org-agenda.el 298 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.01trans
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-ndays)
  217. (integer :value 1))
  218. (list :tag "Fixed starting date"
  219. (const org-agenda-start-day)
  220. (string :value "2007-11-01"))
  221. (list :tag "Start on day of week"
  222. (const org-agenda-start-on-weekday)
  223. (choice :value 1
  224. (const :tag "Today" nil)
  225. (integer :tag "Weekday No.")))
  226. (list :tag "Include data from diary"
  227. (const org-agenda-include-diary)
  228. (boolean))
  229. (list :tag "Deadline Warning days"
  230. (const org-deadline-warning-days)
  231. (integer :value 1))
  232. (list :tag "Tags filter preset"
  233. (const org-agenda-filter-preset)
  234. (list
  235. (const :format "" quote)
  236. (repeat
  237. (string :tag "+tag or -tag"))))
  238. (list :tag "Set daily/weekly entry types"
  239. (const org-agenda-entry-types)
  240. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  241. (const :deadline)
  242. (const :scheduled)
  243. (const :timestamp)
  244. (const :sexp)))
  245. (list :tag "Standard skipping condition"
  246. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  247. (const org-agenda-skip-function)
  248. (list
  249. (const :format "" quote)
  250. (list
  251. (choice
  252. :tag "Skipping range"
  253. (const :tag "Skip entry" org-agenda-skip-entry-if)
  254. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  255. (repeat :inline t :tag "Conditions for skipping"
  256. (choice
  257. :tag "Condition type"
  258. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  259. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  260. (list :tag "TODO state is" :inline t
  261. (const 'todo)
  262. (choice
  263. (const :tag "any not-done state" 'todo)
  264. (const :tag "any done state" 'done)
  265. (const :tag "any state" 'any)
  266. (list :tag "Keyword list"
  267. (const :format "" quote)
  268. (repeat (string :tag "Keyword")))))
  269. (list :tag "TODO state is not" :inline t
  270. (const 'nottodo)
  271. (choice
  272. (const :tag "any not-done state" 'todo)
  273. (const :tag "any done state" 'done)
  274. (const :tag "any state" 'any)
  275. (list :tag "Keyword list"
  276. (const :format "" quote)
  277. (repeat (string :tag "Keyword")))))
  278. (const :tag "scheduled" 'scheduled)
  279. (const :tag "not scheduled" 'notscheduled)
  280. (const :tag "deadline" 'deadline)
  281. (const :tag "no deadline" 'notdeadline)
  282. (const :tag "timestamp" 'timestamp)
  283. (const :tag "no timestamp" 'nottimestamp))))))
  284. (list :tag "Non-standard skipping condition"
  285. :value (org-agenda-skip-function)
  286. (const org-agenda-skip-function)
  287. (sexp :tag "Function or form (quoted!)"))
  288. (list :tag "Any variable"
  289. (variable :tag "Variable")
  290. (sexp :tag "Value (sexp)"))))
  291. "Selection of examples for agenda command settings.
  292. This will be spliced into the custom type of
  293. `org-agenda-custom-commands'.")
  294. (defcustom org-agenda-custom-commands nil
  295. "Custom commands for the agenda.
  296. These commands will be offered on the splash screen displayed by the
  297. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  298. (key desc type match settings files)
  299. key The key (one or more characters as a string) to be associated
  300. with the command.
  301. desc A description of the command, when omitted or nil, a default
  302. description is built using MATCH.
  303. type The command type, any of the following symbols:
  304. agenda The daily/weekly agenda.
  305. todo Entries with a specific TODO keyword, in all agenda files.
  306. search Entries containing search words entry or headline.
  307. tags Tags/Property/TODO match in all agenda files.
  308. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  309. todo-tree Sparse tree of specific TODO keyword in *current* file.
  310. tags-tree Sparse tree with all tags matches in *current* file.
  311. occur-tree Occur sparse tree for *current* file.
  312. ... A user-defined function.
  313. match What to search for:
  314. - a single keyword for TODO keyword searches
  315. - a tags match expression for tags searches
  316. - a word search expression for text searches.
  317. - a regular expression for occur searches
  318. For all other commands, this should be the empty string.
  319. settings A list of option settings, similar to that in a let form, so like
  320. this: ((opt1 val1) (opt2 val2) ...). The values will be
  321. evaluated at the moment of execution, so quote them when needed.
  322. files A list of files file to write the produced agenda buffer to
  323. with the command `org-store-agenda-views'.
  324. If a file name ends in \".html\", an HTML version of the buffer
  325. is written out. If it ends in \".ps\", a postscript version is
  326. produced. Otherwise, only the plain text is written to the file.
  327. You can also define a set of commands, to create a composite agenda buffer.
  328. In this case, an entry looks like this:
  329. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  330. where
  331. desc A description string to be displayed in the dispatcher menu.
  332. cmd An agenda command, similar to the above. However, tree commands
  333. are no allowed, but instead you can get agenda and global todo list.
  334. So valid commands for a set are:
  335. (agenda \"\" settings)
  336. (alltodo \"\" settings)
  337. (stuck \"\" settings)
  338. (todo \"match\" settings files)
  339. (search \"match\" settings files)
  340. (tags \"match\" settings files)
  341. (tags-todo \"match\" settings files)
  342. Each command can carry a list of options, and another set of options can be
  343. given for the whole set of commands. Individual command options take
  344. precedence over the general options.
  345. When using several characters as key to a command, the first characters
  346. are prefix commands. For the dispatcher to display useful information, you
  347. should provide a description for the prefix, like
  348. (setq org-agenda-custom-commands
  349. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  350. (\"hl\" tags \"+HOME+Lisa\")
  351. (\"hp\" tags \"+HOME+Peter\")
  352. (\"hk\" tags \"+HOME+Kim\")))"
  353. :group 'org-agenda-custom-commands
  354. :type `(repeat
  355. (choice :value ("x" "Describe command here" tags "" nil)
  356. (list :tag "Single command"
  357. (string :tag "Access Key(s) ")
  358. (option (string :tag "Description"))
  359. (choice
  360. (const :tag "Agenda" agenda)
  361. (const :tag "TODO list" alltodo)
  362. (const :tag "Search words" search)
  363. (const :tag "Stuck projects" stuck)
  364. (const :tag "Tags/Property match (all agenda files)" tags)
  365. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  366. (const :tag "TODO keyword search (all agenda files)" todo)
  367. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  368. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  369. (const :tag "Occur tree (current buffer)" occur-tree)
  370. (sexp :tag "Other, user-defined function"))
  371. (string :tag "Match (only for some commands)")
  372. ,org-agenda-custom-commands-local-options
  373. (option (repeat :tag "Export" (file :tag "Export to"))))
  374. (list :tag "Command series, all agenda files"
  375. (string :tag "Access Key(s)")
  376. (string :tag "Description ")
  377. (repeat :tag "Component"
  378. (choice
  379. (list :tag "Agenda"
  380. (const :format "" agenda)
  381. (const :tag "" :format "" "")
  382. ,org-agenda-custom-commands-local-options)
  383. (list :tag "TODO list (all keywords)"
  384. (const :format "" alltodo)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "Search words"
  388. (const :format "" search)
  389. (string :tag "Match")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Stuck projects"
  392. (const :format "" stuck)
  393. (const :tag "" :format "" "")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Tags search"
  396. (const :format "" tags)
  397. (string :tag "Match")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search, TODO entries only"
  400. (const :format "" tags-todo)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "TODO keyword search"
  404. (const :format "" todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "Other, user-defined function"
  408. (symbol :tag "function")
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)))
  411. (repeat :tag "Settings for entire command set"
  412. (list (variable :tag "Any variable")
  413. (sexp :tag "Value")))
  414. (option (repeat :tag "Export" (file :tag "Export to"))))
  415. (cons :tag "Prefix key documentation"
  416. (string :tag "Access Key(s)")
  417. (string :tag "Description ")))))
  418. (defcustom org-agenda-query-register ?o
  419. "The register holding the current query string.
  420. The purpose of this is that if you construct a query string interactively,
  421. you can then use it to define a custom command."
  422. :group 'org-agenda-custom-commands
  423. :type 'character)
  424. (defcustom org-stuck-projects
  425. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  426. "How to identify stuck projects.
  427. This is a list of four items:
  428. 1. A tags/todo/property matcher string that is used to identify a project.
  429. See the manual for a description of tag and property searches.
  430. The entire tree below a headline matched by this is considered one project.
  431. 2. A list of TODO keywords identifying non-stuck projects.
  432. If the project subtree contains any headline with one of these todo
  433. keywords, the project is considered to be not stuck. If you specify
  434. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  435. 3. A list of tags identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these tags,
  437. the project is considered to be not stuck. If you specify \"*\" as
  438. a tag, any tag will mark the project unstuck. Note that this is about
  439. the explicit presence of a tag somewhere in the subtree, inherited
  440. tags to not count here. If inherited tags make a project not stuck,
  441. use \"-TAG\" in the tags part of the matcher under (1.) above.
  442. 4. An arbitrary regular expression matching non-stuck projects.
  443. If the project turns out to be not stuck, search continues also in the
  444. subtree to see if any of the subtasks have project status.
  445. See also the variable `org-tags-match-list-sublevels' which applies
  446. to projects matched by this search as well.
  447. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  448. or `C-c a #' to produce the list."
  449. :group 'org-agenda-custom-commands
  450. :type '(list
  451. (string :tag "Tags/TODO match to identify a project")
  452. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  453. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  454. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  455. (defcustom org-agenda-filter-effort-default-operator "<"
  456. "The default operator for effort estimate filtering.
  457. If you select an effort estimate limit without first pressing an operator,
  458. this one will be used."
  459. :group 'org-agenda-custom-commands
  460. :type '(choice (const :tag "less or equal" "<")
  461. (const :tag "greater or equal"">")
  462. (const :tag "equal" "=")))
  463. (defgroup org-agenda-skip nil
  464. "Options concerning skipping parts of agenda files."
  465. :tag "Org Agenda Skip"
  466. :group 'org-agenda)
  467. (defgroup org-agenda-daily/weekly nil
  468. "Options concerning the daily/weekly agenda."
  469. :tag "Org Agenda Daily/Weekly"
  470. :group 'org-agenda)
  471. (defgroup org-agenda-todo-list nil
  472. "Options concerning the global todo list agenda view."
  473. :tag "Org Agenda Todo List"
  474. :group 'org-agenda)
  475. (defgroup org-agenda-match-view nil
  476. "Options concerning the general tags/property/todo match agenda view."
  477. :tag "Org Agenda Match View"
  478. :group 'org-agenda)
  479. (defgroup org-agenda-search-view nil
  480. "Options concerning the general tags/property/todo match agenda view."
  481. :tag "Org Agenda Match View"
  482. :group 'org-agenda)
  483. (defvar org-agenda-archives-mode nil
  484. "Non-nil means the agenda will include archived items.
  485. If this is the symbol `trees', trees in the selected agenda scope
  486. that are marked with the ARCHIVE tag will be included anyway. When this is
  487. t, also all archive files associated with the current selection of agenda
  488. files will be included.")
  489. (defcustom org-agenda-skip-comment-trees t
  490. "Non-nil means skip trees that start with the COMMENT keyword.
  491. When nil, these trees are also scanned by agenda commands."
  492. :group 'org-agenda-skip
  493. :type 'boolean)
  494. (defcustom org-agenda-todo-list-sublevels t
  495. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  496. When nil, the sublevels of a TODO entry are not checked, resulting in
  497. potentially much shorter TODO lists."
  498. :group 'org-agenda-skip
  499. :group 'org-agenda-todo-list
  500. :type 'boolean)
  501. (defcustom org-agenda-todo-ignore-with-date nil
  502. "Non-nil means don't show entries with a date in the global todo list.
  503. You can use this if you prefer to mark mere appointments with a TODO keyword,
  504. but don't want them to show up in the TODO list.
  505. When this is set, it also covers deadlines and scheduled items, the settings
  506. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  507. will be ignored.
  508. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-todo-list
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-ignore-scheduled nil
  513. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  514. This applies when creating the global todo list.
  515. Valid values are:
  516. past Don't show entries scheduled today or in the past.
  517. future Don't show entries scheduled in the future.
  518. The idea behind this is that by scheduling it, you don't want to
  519. think about it until the scheduled date.
  520. all Don't show any scheduled entries in the global todo list.
  521. The idea behind this is that by scheduling it, you have already
  522. \"taken care\" of this item.
  523. t Same as `all', for backward compatibility.
  524. See also `org-agenda-todo-ignore-with-date'.
  525. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  526. to make his option also apply to the tags-todo list."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type '(choice
  530. (const :tag "Ignore future-scheduled todos" future)
  531. (const :tag "Ignore past- or present-scheduled todos" past)
  532. (const :tag "Ignore all scheduled todos" all)
  533. (const :tag "Ignore all scheduled todos (compatibility)" t)
  534. (const :tag "Show scheduled todos" nil)))
  535. (defcustom org-agenda-todo-ignore-deadlines nil
  536. "Non-nil means ignore some deadlined TODO items when making TODO list.
  537. There are different motivations for using different values, please think
  538. carefully when configuring this variable.
  539. This applies when creating the global todo list.
  540. Valid values are:
  541. near Don't show near deadline entries. A deadline is near when it is
  542. closer than `org-deadline-warning-days' days. The idea behind this
  543. is that such items will appear in the agenda anyway.
  544. far Don't show TODO entries where a deadline has been defined, but
  545. the deadline is not near. This is useful if you don't want to
  546. use the todo list to figure out what to do now.
  547. past Don't show entries with a deadline timestamp for today or in the past.
  548. future Don't show entries with a deadline timestamp in the future, not even
  549. when they become `near' ones. Use it with caution.
  550. all Ignore all TODO entries that do have a deadline.
  551. t Same as `near', for backward compatibility.
  552. See also `org-agenda-todo-ignore-with-date'.
  553. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  554. to make his option also apply to the tags-todo list."
  555. :group 'org-agenda-skip
  556. :group 'org-agenda-todo-list
  557. :type '(choice
  558. (const :tag "Ignore near deadlines" near)
  559. (const :tag "Ignore near deadlines (compatibility)" t)
  560. (const :tag "Ignore far deadlines" far)
  561. (const :tag "Ignore all TODOs with a deadlines" all)
  562. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  563. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  564. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  565. The variables
  566. `org-agenda-todo-ignore-with-date',
  567. `org-agenda-todo-ignore-scheduled'
  568. `org-agenda-todo-ignore-deadlines'
  569. make the global TODO list skip entries that have time stamps of certain
  570. kinds. If this option is set, the same options will also apply for the
  571. tags-todo search, which is the general tags/property matcher
  572. restricted to unfinished TODO entries only."
  573. :group 'org-agenda-skip
  574. :group 'org-agenda-todo-list
  575. :group 'org-agenda-match-view
  576. :type 'boolean)
  577. (defcustom org-agenda-skip-scheduled-if-done nil
  578. "Non-nil means don't show scheduled items in agenda when they are done.
  579. This is relevant for the daily/weekly agenda, not for the TODO list. And
  580. it applies only to the actual date of the scheduling. Warnings about
  581. an item with a past scheduling dates are always turned off when the item
  582. is DONE."
  583. :group 'org-agenda-skip
  584. :group 'org-agenda-daily/weekly
  585. :type 'boolean)
  586. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  587. "Non-nil means skip scheduling line if same entry shows because of deadline.
  588. In the agenda of today, an entry can show up multiple times because
  589. it is both scheduled and has a nearby deadline, and maybe a plain time
  590. stamp as well.
  591. When this variable is t, then only the deadline is shown and the fact that
  592. the entry is scheduled today or was scheduled previously is not shown.
  593. When this variable is nil, the entry will be shown several times. When
  594. the variable is the symbol `not-today', then skip scheduled previously,
  595. but not scheduled today."
  596. :group 'org-agenda-skip
  597. :group 'org-agenda-daily/weekly
  598. :type '(choice
  599. (const :tag "Never" nil)
  600. (const :tag "Always" t)
  601. (const :tag "Not when scheduled today" not-today)))
  602. (defcustom org-agenda-skip-deadline-if-done nil
  603. "Non-nil means don't show deadlines when the corresponding item is done.
  604. When nil, the deadline is still shown and should give you a happy feeling.
  605. This is relevant for the daily/weekly agenda. And it applied only to the
  606. actually date of the deadline. Warnings about approaching and past-due
  607. deadlines are always turned off when the item is DONE."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-daily/weekly
  610. :type 'boolean)
  611. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  612. "Non-nil means skip deadline prewarning when entry is also scheduled.
  613. This will apply on all days where a prewarning for the deadline would
  614. be shown, but not at the day when the entry is actually due. On that day,
  615. the deadline will be shown anyway.
  616. This variable may be set to nil, t, or a number which will then give
  617. the number of days before the actual deadline when the prewarnings
  618. should resume.
  619. This can be used in a workflow where the first showing of the deadline will
  620. trigger you to schedule it, and then you don't want to be reminded of it
  621. because you will take care of it on the day when scheduled."
  622. :group 'org-agenda-skip
  623. :group 'org-agenda-daily/weekly
  624. :type '(choice
  625. (const :tag "Alwas show prewarning" nil)
  626. (const :tag "Remove prewarning if entry is scheduled" t)
  627. (integer :tag "Restart prewarning N days before deadline")))
  628. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  629. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  630. When non-nil, after the search for timestamps has matched once in an
  631. entry, the rest of the entry will not be searched."
  632. :group 'org-agenda-skip
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-timestamp-if-done nil
  635. "Non-nil means don't select item by timestamp or -range if it is DONE."
  636. :group 'org-agenda-skip
  637. :group 'org-agenda-daily/weekly
  638. :type 'boolean)
  639. (defcustom org-agenda-dim-blocked-tasks t
  640. "Non-nil means dim blocked tasks in the agenda display.
  641. This causes some overhead during agenda construction, but if you
  642. have turned on `org-enforce-todo-dependencies',
  643. `org-enforce-todo-checkbox-dependencies', or any other blocking
  644. mechanism, this will create useful feedback in the agenda.
  645. Instead of t, this variable can also have the value `invisible'.
  646. Then blocked tasks will be invisible and only become visible when
  647. they become unblocked. An exemption to this behavior is when a task is
  648. blocked because of unchecked checkboxes below it. Since checkboxes do
  649. not show up in the agenda views, making this task invisible you remove any
  650. trace from agenda views that there is something to do. Therefore, a task
  651. that is blocked because of checkboxes will never be made invisible, it
  652. will only be dimmed."
  653. :group 'org-agenda-daily/weekly
  654. :group 'org-agenda-todo-list
  655. :type '(choice
  656. (const :tag "Do not dim" nil)
  657. (const :tag "Dim to a grey face" t)
  658. (const :tag "Make invisible" invisible)))
  659. (defcustom org-timeline-show-empty-dates 3
  660. "Non-nil means `org-timeline' also shows dates without an entry.
  661. When nil, only the days which actually have entries are shown.
  662. When t, all days between the first and the last date are shown.
  663. When an integer, show also empty dates, but if there is a gap of more than
  664. N days, just insert a special line indicating the size of the gap."
  665. :group 'org-agenda-skip
  666. :type '(choice
  667. (const :tag "None" nil)
  668. (const :tag "All" t)
  669. (integer :tag "at most")))
  670. (defgroup org-agenda-startup nil
  671. "Options concerning initial settings in the Agenda in Org Mode."
  672. :tag "Org Agenda Startup"
  673. :group 'org-agenda)
  674. (defcustom org-agenda-menu-show-matcher t
  675. "Non-nil menas show the match string in the agenda dispatcher menu.
  676. When nil, the matcher string is not shown, but is put into the help-echo
  677. property so than moving the mouse over the command shows it.
  678. Setting it to nil is good if matcher strings are very long and/or if
  679. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  680. :group 'org-agenda
  681. :type 'boolean)
  682. (defcustom org-agenda-menu-two-column nil
  683. "Non-nil means, use two columns to show custom commands in the dispatcher.
  684. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  685. to nil."
  686. :group 'org-agenda
  687. :type 'boolean)
  688. (defcustom org-finalize-agenda-hook nil
  689. "Hook run just before displaying an agenda buffer."
  690. :group 'org-agenda-startup
  691. :type 'hook)
  692. (defcustom org-agenda-mouse-1-follows-link nil
  693. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  694. A longer mouse click will still set point. Does not work on XEmacs.
  695. Needs to be set before org.el is loaded."
  696. :group 'org-agenda-startup
  697. :type 'boolean)
  698. (defcustom org-agenda-start-with-follow-mode nil
  699. "The initial value of follow mode in a newly created agenda window."
  700. :group 'org-agenda-startup
  701. :type 'boolean)
  702. (defcustom org-agenda-show-outline-path t
  703. "Non-nil means show outline path in echo area after line motion."
  704. :group 'org-agenda-startup
  705. :type 'boolean)
  706. (defcustom org-agenda-start-with-entry-text-mode nil
  707. "The initial value of entry-text-mode in a newly created agenda window."
  708. :group 'org-agenda-startup
  709. :type 'boolean)
  710. (defcustom org-agenda-entry-text-maxlines 5
  711. "Number of text lines to be added when `E' is pressed in the agenda.
  712. Note that this variable only used during agenda display. Add add entry text
  713. when exporting the agenda, configure the variable
  714. `org-agenda-add-entry-ext-maxlines'."
  715. :group 'org-agenda
  716. :type 'integer)
  717. (defcustom org-agenda-entry-text-exclude-regexps nil
  718. "List of regular expressions to clean up entry text.
  719. The complete matches of all regular expressions in this list will be
  720. removed from entry text before it is shown in the agenda."
  721. :group 'org-agenda
  722. :type '(repeat (regexp)))
  723. (defvar org-agenda-entry-text-cleanup-hook nil
  724. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  725. This cleanup is done in a temporary buffer, so the function may inspect and
  726. change the entire buffer.
  727. Some default stuff like drawers and scheduling/deadline dates will already
  728. have been removed when this is called, as will any matches for regular
  729. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  730. (defvar org-agenda-include-inactive-timestamps nil
  731. "Non-nil means include inactive time stamps in agenda and timeline.")
  732. (defgroup org-agenda-windows nil
  733. "Options concerning the windows used by the Agenda in Org Mode."
  734. :tag "Org Agenda Windows"
  735. :group 'org-agenda)
  736. (defcustom org-agenda-window-setup 'reorganize-frame
  737. "How the agenda buffer should be displayed.
  738. Possible values for this option are:
  739. current-window Show agenda in the current window, keeping all other windows.
  740. other-window Use `switch-to-buffer-other-window' to display agenda.
  741. reorganize-frame Show only two windows on the current frame, the current
  742. window and the agenda.
  743. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  744. Also, when exiting the agenda, kill that frame.
  745. See also the variable `org-agenda-restore-windows-after-quit'."
  746. :group 'org-agenda-windows
  747. :type '(choice
  748. (const current-window)
  749. (const other-frame)
  750. (const other-window)
  751. (const reorganize-frame)))
  752. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  753. "The min and max height of the agenda window as a fraction of frame height.
  754. The value of the variable is a cons cell with two numbers between 0 and 1.
  755. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  756. :group 'org-agenda-windows
  757. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  758. (defcustom org-agenda-restore-windows-after-quit nil
  759. "Non-nil means restore window configuration open exiting agenda.
  760. Before the window configuration is changed for displaying the agenda,
  761. the current status is recorded. When the agenda is exited with
  762. `q' or `x' and this option is set, the old state is restored. If
  763. `org-agenda-window-setup' is `other-frame', the value of this
  764. option will be ignored."
  765. :group 'org-agenda-windows
  766. :type 'boolean)
  767. (defcustom org-agenda-ndays 7
  768. "Number of days to include in overview display.
  769. Should be 1 or 7.
  770. Custom commands can set this variable in the options section."
  771. :group 'org-agenda-daily/weekly
  772. :type 'integer)
  773. (defcustom org-agenda-start-on-weekday 1
  774. "Non-nil means start the overview always on the specified weekday.
  775. 0 denotes Sunday, 1 denotes Monday etc.
  776. When nil, always start on the current day.
  777. Custom commands can set this variable in the options section."
  778. :group 'org-agenda-daily/weekly
  779. :type '(choice (const :tag "Today" nil)
  780. (integer :tag "Weekday No.")))
  781. (defcustom org-agenda-show-all-dates t
  782. "Non-nil means `org-agenda' shows every day in the selected range.
  783. When nil, only the days which actually have entries are shown."
  784. :group 'org-agenda-daily/weekly
  785. :type 'boolean)
  786. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  787. "Format string for displaying dates in the agenda.
  788. Used by the daily/weekly agenda and by the timeline. This should be
  789. a format string understood by `format-time-string', or a function returning
  790. the formatted date as a string. The function must take a single argument,
  791. a calendar-style date list like (month day year)."
  792. :group 'org-agenda-daily/weekly
  793. :type '(choice
  794. (string :tag "Format string")
  795. (function :tag "Function")))
  796. (defun org-agenda-format-date-aligned (date)
  797. "Format a date string for display in the daily/weekly agenda, or timeline.
  798. This function makes sure that dates are aligned for easy reading."
  799. (require 'cal-iso)
  800. (let* ((dayname (calendar-day-name date))
  801. (day (cadr date))
  802. (day-of-week (calendar-day-of-week date))
  803. (month (car date))
  804. (monthname (calendar-month-name month))
  805. (year (nth 2 date))
  806. (iso-week (org-days-to-iso-week
  807. (calendar-absolute-from-gregorian date)))
  808. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  809. (1- year))
  810. ((and (= month 12) (<= iso-week 1))
  811. (1+ year))
  812. (t year)))
  813. (weekstring (if (= day-of-week 1)
  814. (format " W%02d" iso-week)
  815. "")))
  816. (format "%-10s %2d %s %4d%s"
  817. dayname day monthname year weekstring)))
  818. (defcustom org-agenda-time-leading-zero nil
  819. "Non-nil means use leading zero for military times in agenda.
  820. For example, 9:30am would become 09:30 rather than 9:30."
  821. :group 'org-agenda-daily/weekly
  822. :type 'boolean)
  823. (defcustom org-agenda-weekend-days '(6 0)
  824. "Which days are weekend?
  825. These days get the special face `org-agenda-date-weekend' in the agenda
  826. and timeline buffers."
  827. :group 'org-agenda-daily/weekly
  828. :type '(set :greedy t
  829. (const :tag "Monday" 1)
  830. (const :tag "Tuesday" 2)
  831. (const :tag "Wednesday" 3)
  832. (const :tag "Thursday" 4)
  833. (const :tag "Friday" 5)
  834. (const :tag "Saturday" 6)
  835. (const :tag "Sunday" 0)))
  836. (defcustom org-agenda-include-diary nil
  837. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  838. Custom commands can set this variable in the options section."
  839. :group 'org-agenda-daily/weekly
  840. :type 'boolean)
  841. (defcustom org-agenda-include-deadlines t
  842. "If non-nil, include entries within their deadline warning period.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type 'boolean)
  846. (defcustom org-agenda-include-all-todo nil
  847. "Set means weekly/daily agenda will always contain all TODO entries.
  848. The TODO entries will be listed at the top of the agenda, before
  849. the entries for specific days.
  850. This option is deprecated, it is better to define a block agenda instead."
  851. :group 'org-agenda-daily/weekly
  852. :type 'boolean)
  853. (defcustom org-agenda-repeating-timestamp-show-all t
  854. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  855. When nil, only one occurrence is shown, either today or the
  856. nearest into the future."
  857. :group 'org-agenda-daily/weekly
  858. :type 'boolean)
  859. (defcustom org-scheduled-past-days 10000
  860. "No. of days to continue listing scheduled items that are not marked DONE.
  861. When an item is scheduled on a date, it shows up in the agenda on this
  862. day and will be listed until it is marked done for the number of days
  863. given here."
  864. :group 'org-agenda-daily/weekly
  865. :type 'integer)
  866. (defcustom org-agenda-log-mode-items '(closed clock)
  867. "List of items that should be shown in agenda log mode.
  868. This list may contain the following symbols:
  869. closed Show entries that have been closed on that day.
  870. clock Show entries that have received clocked time on that day.
  871. state Show all logged state changes.
  872. Note that instead of changing this variable, you can also press `C-u l' in
  873. the agenda to display all available LOG items temporarily."
  874. :group 'org-agenda-daily/weekly
  875. :type '(set :greedy t (const closed) (const clock) (const state)))
  876. (defcustom org-agenda-log-mode-add-notes t
  877. "Non-nil means add first line of notes to log entries in agenda views.
  878. If a log item like a state change or a clock entry is associated with
  879. notes, the first line of these notes will be added to the entry in the
  880. agenda display."
  881. :group 'org-agenda-daily/weekly
  882. :type 'boolean)
  883. (defcustom org-agenda-start-with-log-mode nil
  884. "The initial value of log-mode in a newly created agenda window."
  885. :group 'org-agenda-startup
  886. :group 'org-agenda-daily/weekly
  887. :type 'boolean)
  888. (defcustom org-agenda-start-with-clockreport-mode nil
  889. "The initial value of clockreport-mode in a newly created agenda window."
  890. :group 'org-agenda-startup
  891. :group 'org-agenda-daily/weekly
  892. :type 'boolean)
  893. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  894. "Property list with parameters for the clocktable in clockreport mode.
  895. This is the display mode that shows a clock table in the daily/weekly
  896. agenda, the properties for this dynamic block can be set here.
  897. The usual clocktable parameters are allowed here, but you cannot set
  898. the properties :name, :tstart, :tend, :block, and :scope - these will
  899. be overwritten to make sure the content accurately reflects the
  900. current display in the agenda."
  901. :group 'org-agenda-daily/weekly
  902. :type 'plist)
  903. (defcustom org-agenda-search-view-always-boolean nil
  904. "Non-nil means the search string is interpreted as individual parts.
  905. The search string for search view can either be interpreted as a phrase,
  906. or as a list of snippets that define a boolean search for a number of
  907. strings.
  908. When this is non-nil, the string will be split on whitespace, and each
  909. snippet will be searched individually, and all must match in order to
  910. select an entry. A snippet is then a single string of non-white
  911. characters, or a string in double quotes, or a regexp in {} braces.
  912. If a snippet is preceded by \"-\", the snippet must *not* match.
  913. \"+\" is syntactic sugar for positive selection. Each snippet may
  914. be found as a full word or a partial word, but see the variable
  915. `org-agenda-search-view-force-full-words'.
  916. When this is nil, search will look for the entire search phrase as one,
  917. with each space character matching any amount of whitespace, including
  918. line breaks.
  919. Even when this is nil, you can still switch to Boolean search dynamically
  920. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  921. is a regexp marked with braces like \"{abc}\", this will also switch to
  922. boolean search."
  923. :group 'org-agenda-search-view
  924. :type 'boolean)
  925. (if (fboundp 'defvaralias)
  926. (defvaralias 'org-agenda-search-view-search-words-only
  927. 'org-agenda-search-view-always-boolean))
  928. (defcustom org-agenda-search-view-force-full-words nil
  929. "Non-nil means, search words must be matches as complete words.
  930. When nil, they may also match part of a word."
  931. :group 'org-agenda-search-view
  932. :type 'boolean)
  933. (defgroup org-agenda-time-grid nil
  934. "Options concerning the time grid in the Org-mode Agenda."
  935. :tag "Org Agenda Time Grid"
  936. :group 'org-agenda)
  937. (defcustom org-agenda-search-headline-for-time t
  938. "Non-nil means search headline for a time-of-day.
  939. If the headline contains a time-of-day in one format or another, it will
  940. be used to sort the entry into the time sequence of items for a day.
  941. Some people have time stamps in the headline that refer to the creation
  942. time or so, and then this produces an unwanted side effect. If this is
  943. the case for your, use this variable to turn off searching the headline
  944. for a time."
  945. :group 'org-agenda-time-grid
  946. :type 'boolean)
  947. (defcustom org-agenda-use-time-grid t
  948. "Non-nil means show a time grid in the agenda schedule.
  949. A time grid is a set of lines for specific times (like every two hours between
  950. 8:00 and 20:00). The items scheduled for a day at specific times are
  951. sorted in between these lines.
  952. For details about when the grid will be shown, and what it will look like, see
  953. the variable `org-agenda-time-grid'."
  954. :group 'org-agenda-time-grid
  955. :type 'boolean)
  956. (defcustom org-agenda-time-grid
  957. '((daily today require-timed)
  958. "----------------"
  959. (800 1000 1200 1400 1600 1800 2000))
  960. "The settings for time grid for agenda display.
  961. This is a list of three items. The first item is again a list. It contains
  962. symbols specifying conditions when the grid should be displayed:
  963. daily if the agenda shows a single day
  964. weekly if the agenda shows an entire week
  965. today show grid on current date, independent of daily/weekly display
  966. require-timed show grid only if at least one item has a time specification
  967. The second item is a string which will be placed behind the grid time.
  968. The third item is a list of integers, indicating the times that should have
  969. a grid line."
  970. :group 'org-agenda-time-grid
  971. :type
  972. '(list
  973. (set :greedy t :tag "Grid Display Options"
  974. (const :tag "Show grid in single day agenda display" daily)
  975. (const :tag "Show grid in weekly agenda display" weekly)
  976. (const :tag "Always show grid for today" today)
  977. (const :tag "Show grid only if any timed entries are present"
  978. require-timed)
  979. (const :tag "Skip grid times already present in an entry"
  980. remove-match))
  981. (string :tag "Grid String")
  982. (repeat :tag "Grid Times" (integer :tag "Time"))))
  983. (defgroup org-agenda-sorting nil
  984. "Options concerning sorting in the Org-mode Agenda."
  985. :tag "Org Agenda Sorting"
  986. :group 'org-agenda)
  987. (defcustom org-agenda-sorting-strategy
  988. '((agenda habit-down time-up priority-down category-keep)
  989. (todo priority-down category-keep)
  990. (tags priority-down category-keep)
  991. (search category-keep))
  992. "Sorting structure for the agenda items of a single day.
  993. This is a list of symbols which will be used in sequence to determine
  994. if an entry should be listed before another entry. The following
  995. symbols are recognized:
  996. time-up Put entries with time-of-day indications first, early first
  997. time-down Put entries with time-of-day indications first, late first
  998. category-keep Keep the default order of categories, corresponding to the
  999. sequence in `org-agenda-files'.
  1000. category-up Sort alphabetically by category, A-Z.
  1001. category-down Sort alphabetically by category, Z-A.
  1002. tag-up Sort alphabetically by last tag, A-Z.
  1003. tag-down Sort alphabetically by last tag, Z-A.
  1004. priority-up Sort numerically by priority, high priority last.
  1005. priority-down Sort numerically by priority, high priority first.
  1006. todo-state-up Sort by todo state, tasks that are done last.
  1007. todo-state-down Sort by todo state, tasks that are done first.
  1008. effort-up Sort numerically by estimated effort, high effort last.
  1009. effort-down Sort numerically by estimated effort, high effort first.
  1010. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1011. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1012. habit-up Put entries that are habits first
  1013. habit-down Put entries that are habits last
  1014. alpha-up Sort headlines alphabetically
  1015. alpha-down Sort headlines alphabetically, reversed
  1016. The different possibilities will be tried in sequence, and testing stops
  1017. if one comparison returns a \"not-equal\". For example, the default
  1018. '(time-up category-keep priority-down)
  1019. means: Pull out all entries having a specified time of day and sort them,
  1020. in order to make a time schedule for the current day the first thing in the
  1021. agenda listing for the day. Of the entries without a time indication, keep
  1022. the grouped in categories, don't sort the categories, but keep them in
  1023. the sequence given in `org-agenda-files'. Within each category sort by
  1024. priority.
  1025. Leaving out `category-keep' would mean that items will be sorted across
  1026. categories by priority.
  1027. Instead of a single list, this can also be a set of list for specific
  1028. contents, with a context symbol in the car of the list, any of
  1029. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1030. Custom commands can bind this variable in the options section."
  1031. :group 'org-agenda-sorting
  1032. :type `(choice
  1033. (repeat :tag "General" ,org-sorting-choice)
  1034. (list :tag "Individually"
  1035. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1036. (repeat ,org-sorting-choice))
  1037. (cons (const :tag "Strategy for TODO lists" todo)
  1038. (repeat ,org-sorting-choice))
  1039. (cons (const :tag "Strategy for Tags matches" tags)
  1040. (repeat ,org-sorting-choice))
  1041. (cons (const :tag "Strategy for search matches" search)
  1042. (repeat ,org-sorting-choice)))))
  1043. (defcustom org-agenda-cmp-user-defined nil
  1044. "A function to define the comparison `user-defined'.
  1045. This function must receive two arguments, agenda entry a and b.
  1046. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1047. the user comparison, return nil.
  1048. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1049. part of an agenda sorting strategy."
  1050. :group 'org-agenda-sorting
  1051. :type 'symbol)
  1052. (defcustom org-sort-agenda-notime-is-late t
  1053. "Non-nil means items without time are considered late.
  1054. This is only relevant for sorting. When t, items which have no explicit
  1055. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1056. do have a time. When nil, the default time is before 0:00. You can use this
  1057. option to decide if the schedule for today should come before or after timeless
  1058. agenda entries."
  1059. :group 'org-agenda-sorting
  1060. :type 'boolean)
  1061. (defcustom org-sort-agenda-noeffort-is-high t
  1062. "Non-nil means items without effort estimate are sorted as high effort.
  1063. This also applies when filtering an agenda view with respect to the
  1064. < or > effort operator. Then, tasks with no effort defined will be treated
  1065. as tasks with high effort.
  1066. When nil, such items are sorted as 0 minutes effort."
  1067. :group 'org-agenda-sorting
  1068. :type 'boolean)
  1069. (defgroup org-agenda-line-format nil
  1070. "Options concerning the entry prefix in the Org-mode agenda display."
  1071. :tag "Org Agenda Line Format"
  1072. :group 'org-agenda)
  1073. (defcustom org-agenda-prefix-format
  1074. '((agenda . " %-12:c%?-12t% s")
  1075. (timeline . " % s")
  1076. (todo . " %-12:c")
  1077. (tags . " %-12:c")
  1078. (search . " %-12:c"))
  1079. "Format specifications for the prefix of items in the agenda views.
  1080. An alist with four entries, for the different agenda types. The keys to the
  1081. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1082. are format strings.
  1083. This format works similar to a printf format, with the following meaning:
  1084. %c the category of the item, \"Diary\" for entries from the diary, or
  1085. as given by the CATEGORY keyword or derived from the file name.
  1086. %T the *last* tag of the item. Last because inherited tags come
  1087. first in the list.
  1088. %t the time-of-day specification if one applies to the entry, in the
  1089. format HH:MM
  1090. %s Scheduling/Deadline information, a short string
  1091. All specifiers work basically like the standard `%s' of printf, but may
  1092. contain two additional characters: A question mark just after the `%' and
  1093. a whitespace/punctuation character just before the final letter.
  1094. If the first character after `%' is a question mark, the entire field
  1095. will only be included if the corresponding value applies to the
  1096. current entry. This is useful for fields which should have fixed
  1097. width when present, but zero width when absent. For example,
  1098. \"%?-12t\" will result in a 12 character time field if a time of the
  1099. day is specified, but will completely disappear in entries which do
  1100. not contain a time.
  1101. If there is punctuation or whitespace character just before the final
  1102. format letter, this character will be appended to the field value if
  1103. the value is not empty. For example, the format \"%-12:c\" leads to
  1104. \"Diary: \" if the category is \"Diary\". If the category were be
  1105. empty, no additional colon would be inserted.
  1106. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1107. - Indent the line with two space characters
  1108. - Give the category in a 12 chars wide field, padded with whitespace on
  1109. the right (because of `-'). Append a colon if there is a category
  1110. (because of `:').
  1111. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1112. time, don't put in an empty field, just skip it (because of '?').
  1113. - Finally, put the scheduling information and append a whitespace.
  1114. As another example, if you don't want the time-of-day of entries in
  1115. the prefix, you could use:
  1116. (setq org-agenda-prefix-format \" %-11:c% s\")
  1117. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1118. `org-agenda-remove-tags'.
  1119. Custom commands can set this variable in the options section."
  1120. :type '(choice
  1121. (string :tag "General format")
  1122. (list :greedy t :tag "View dependent"
  1123. (cons (const agenda) (string :tag "Format"))
  1124. (cons (const timeline) (string :tag "Format"))
  1125. (cons (const todo) (string :tag "Format"))
  1126. (cons (const tags) (string :tag "Format"))
  1127. (cons (const search) (string :tag "Format"))))
  1128. :group 'org-agenda-line-format)
  1129. (defvar org-prefix-format-compiled nil
  1130. "The compiled version of the most recently used prefix format.
  1131. See the variable `org-agenda-prefix-format'.")
  1132. (defcustom org-agenda-todo-keyword-format "%-1s"
  1133. "Format for the TODO keyword in agenda lines.
  1134. Set this to something like \"%-12s\" if you want all TODO keywords
  1135. to occupy a fixed space in the agenda display."
  1136. :group 'org-agenda-line-format
  1137. :type 'string)
  1138. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1139. "Text preceding timerange entries in the agenda view.
  1140. This is a list with two strings. The first applies when the range
  1141. is entirely on one day. The second applies if the range spans several days.
  1142. The strings may have two \"%d\" format specifiers which will be filled
  1143. with the sequence number of the days, and the total number of days in the
  1144. range, respectively."
  1145. :group 'org-agenda-line-format
  1146. :type '(list
  1147. (string :tag "Deadline today ")
  1148. (choice :tag "Deadline relative"
  1149. (string :tag "Format string")
  1150. (function))))
  1151. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1152. "Text preceding scheduled items in the agenda view.
  1153. This is a list with two strings. The first applies when the item is
  1154. scheduled on the current day. The second applies when it has been scheduled
  1155. previously, it may contain a %d indicating that this is the nth time that
  1156. this item is scheduled, due to automatic rescheduling of unfinished items
  1157. for the following day. So this number is one larger than the number of days
  1158. that passed since this item was scheduled first."
  1159. :group 'org-agenda-line-format
  1160. :type '(list
  1161. (string :tag "Scheduled today ")
  1162. (string :tag "Scheduled previously")))
  1163. (defcustom org-agenda-inactive-leader "["
  1164. "Text preceding item pulled into the agenda by inactive time stamps.
  1165. These entries are added to the agenda when pressing \"[\"."
  1166. :group 'org-agenda-line-format
  1167. :type '(list
  1168. (string :tag "Scheduled today ")
  1169. (string :tag "Scheduled previously")))
  1170. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1171. "Text preceding deadline items in the agenda view.
  1172. This is a list with two strings. The first applies when the item has its
  1173. deadline on the current day. The second applies when it is in the past or
  1174. in the future, it may contain %d to capture how many days away the deadline
  1175. is (was)."
  1176. :group 'org-agenda-line-format
  1177. :type '(list
  1178. (string :tag "Deadline today ")
  1179. (choice :tag "Deadline relative"
  1180. (string :tag "Format string")
  1181. (function))))
  1182. (defcustom org-agenda-remove-times-when-in-prefix t
  1183. "Non-nil means remove duplicate time specifications in agenda items.
  1184. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1185. time-of-day specification in a headline or diary entry is extracted and
  1186. placed into the prefix. If this option is non-nil, the original specification
  1187. \(a timestamp or -range, or just a plain time(range) specification like
  1188. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1189. cluttered.
  1190. The option can be t or nil. It may also be the symbol `beg', indicating
  1191. that the time should only be removed when it is located at the beginning of
  1192. the headline/diary entry."
  1193. :group 'org-agenda-line-format
  1194. :type '(choice
  1195. (const :tag "Always" t)
  1196. (const :tag "Never" nil)
  1197. (const :tag "When at beginning of entry" beg)))
  1198. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1199. "Non-nil means remove time ranges specifications in agenda
  1200. items that span on several days."
  1201. :group 'org-agenda-line-format
  1202. :type 'boolean)
  1203. (defcustom org-agenda-default-appointment-duration nil
  1204. "Default duration for appointments that only have a starting time.
  1205. When nil, no duration is specified in such cases.
  1206. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1207. :group 'org-agenda-line-format
  1208. :type '(choice
  1209. (integer :tag "Minutes")
  1210. (const :tag "No default duration")))
  1211. (defcustom org-agenda-show-inherited-tags t
  1212. "Non-nil means show inherited tags in each agenda line."
  1213. :group 'org-agenda-line-format
  1214. :type 'boolean)
  1215. (defcustom org-agenda-hide-tags-regexp nil
  1216. "Regular expression used to filter away specific tags in agenda views.
  1217. This means that these tags will be present, but not be shown in the agenda
  1218. line. Secondary filtering will still work on the hidden tags.
  1219. Nil means don't hide any tags."
  1220. :group 'org-agenda-line-format
  1221. :type '(choice
  1222. (const :tag "Hide none" nil)
  1223. (string :tag "Regexp ")))
  1224. (defcustom org-agenda-remove-tags nil
  1225. "Non-nil means remove the tags from the headline copy in the agenda.
  1226. When this is the symbol `prefix', only remove tags when
  1227. `org-agenda-prefix-format' contains a `%T' specifier."
  1228. :group 'org-agenda-line-format
  1229. :type '(choice
  1230. (const :tag "Always" t)
  1231. (const :tag "Never" nil)
  1232. (const :tag "When prefix format contains %T" prefix)))
  1233. (if (fboundp 'defvaralias)
  1234. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1235. 'org-agenda-remove-tags))
  1236. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1237. "Shift tags in agenda items to this column.
  1238. If this number is positive, it specifies the column. If it is negative,
  1239. it means that the tags should be flushright to that column. For example,
  1240. -80 works well for a normal 80 character screen."
  1241. :group 'org-agenda-line-format
  1242. :type 'integer)
  1243. (if (fboundp 'defvaralias)
  1244. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1245. (defcustom org-agenda-fontify-priorities 'cookies
  1246. "Non-nil means highlight low and high priorities in agenda.
  1247. When t, the highest priority entries are bold, lowest priority italic.
  1248. However, settings in `org-priority-faces' will overrule these faces.
  1249. When this variable is the symbol `cookies', only fontify the
  1250. cookies, not the entire task.
  1251. This may also be an association list of priority faces, whose
  1252. keys are the character values of `org-highest-priority',
  1253. `org-default-priority', and `org-lowest-priority' (the default values
  1254. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1255. color as a string, or a list like `(:background \"Red\")'.
  1256. If it is a color, the variable `org-faces-easy-properties'
  1257. determines if it is a foreground or a background color."
  1258. :group 'org-agenda-line-format
  1259. :type '(choice
  1260. (const :tag "Never" nil)
  1261. (const :tag "Defaults" t)
  1262. (const :tag "Cookies only" cookies)
  1263. (repeat :tag "Specify"
  1264. (list (character :tag "Priority" :value ?A)
  1265. (choice :tag "Face "
  1266. (string :tag "Color")
  1267. (sexp :tag "Face"))))))
  1268. (defgroup org-agenda-column-view nil
  1269. "Options concerning column view in the agenda."
  1270. :tag "Org Agenda Column View"
  1271. :group 'org-agenda)
  1272. (defcustom org-agenda-columns-show-summaries t
  1273. "Non-nil means show summaries for columns displayed in the agenda view."
  1274. :group 'org-agenda-column-view
  1275. :type 'boolean)
  1276. (defcustom org-agenda-columns-remove-prefix-from-item t
  1277. "Non-nil means remove the prefix from a headline for agenda column view.
  1278. The special ITEM field in the columns format contains the current line, with
  1279. all information shown in other columns (like the TODO state or a tag).
  1280. When this variable is non-nil, also the agenda prefix will be removed from
  1281. the content of the ITEM field, to make sure as much as possible of the
  1282. headline can be shown in the limited width of the field."
  1283. :group 'org-agenda
  1284. :type 'boolean)
  1285. (defcustom org-agenda-columns-compute-summary-properties t
  1286. "Non-nil means recompute all summary properties before column view.
  1287. When column view in the agenda is listing properties that have a summary
  1288. operator, it can go to all relevant buffers and recompute the summaries
  1289. there. This can mean overhead for the agenda column view, but is necessary
  1290. to have thing up to date.
  1291. As a special case, a CLOCKSUM property also makes sure that the clock
  1292. computations are current."
  1293. :group 'org-agenda-column-view
  1294. :type 'boolean)
  1295. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1296. "Non-nil means the duration of an appointment will add to day effort.
  1297. The property to which appointment durations will be added is the one given
  1298. in the option `org-effort-property'. If an appointment does not have
  1299. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1300. is not set, an appointment without end time will not contribute to the time
  1301. estimate."
  1302. :group 'org-agenda-column-view
  1303. :type 'boolean)
  1304. (defcustom org-agenda-auto-exclude-function nil
  1305. "A function called with a tag to decide if it is filtered on '/ RET'.
  1306. The sole argument to the function, which is called once for each
  1307. possible tag, is a string giving the name of the tag. The
  1308. function should return either nil if the tag should be included
  1309. as normal, or \"-<TAG>\" to exclude the tag.
  1310. Note that for the purpose of tag filtering, only the lower-case version of
  1311. all tags will be considered, so that this function will only ever see
  1312. the lower-case version of all tags."
  1313. :group 'org-agenda
  1314. :type 'function)
  1315. (eval-when-compile
  1316. (require 'cl))
  1317. (require 'org)
  1318. (defun org-add-agenda-custom-command (entry)
  1319. "Replace or add a command in `org-agenda-custom-commands'.
  1320. This is mostly for hacking and trying a new command - once the command
  1321. works you probably want to add it to `org-agenda-custom-commands' for good."
  1322. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1323. (if ass
  1324. (setcdr ass (cdr entry))
  1325. (push entry org-agenda-custom-commands))))
  1326. ;;; Define the Org-agenda-mode
  1327. (defvar org-agenda-mode-map (make-sparse-keymap)
  1328. "Keymap for `org-agenda-mode'.")
  1329. (if (fboundp 'defvaralias)
  1330. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1331. (defvar org-agenda-menu) ; defined later in this file.
  1332. (defvar org-agenda-restrict) ; defined later in this file.
  1333. (defvar org-agenda-follow-mode nil)
  1334. (defvar org-agenda-entry-text-mode nil)
  1335. (defvar org-agenda-clockreport-mode nil)
  1336. (defvar org-agenda-show-log nil)
  1337. (defvar org-agenda-redo-command nil)
  1338. (defvar org-agenda-query-string nil)
  1339. (defvar org-agenda-mode-hook nil
  1340. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1341. (defvar org-agenda-type nil)
  1342. (defvar org-agenda-force-single-file nil)
  1343. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1344. (defun org-agenda-mode ()
  1345. "Mode for time-sorted view on action items in Org-mode files.
  1346. The following commands are available:
  1347. \\{org-agenda-mode-map}"
  1348. (interactive)
  1349. (kill-all-local-variables)
  1350. (setq org-agenda-undo-list nil
  1351. org-agenda-pending-undo-list nil
  1352. org-agenda-bulk-marked-entries nil)
  1353. (setq major-mode 'org-agenda-mode)
  1354. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1355. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1356. (setq mode-name "Org-Agenda")
  1357. (use-local-map org-agenda-mode-map)
  1358. (easy-menu-add org-agenda-menu)
  1359. (if org-startup-truncated (setq truncate-lines t))
  1360. (org-set-local 'line-move-visual nil)
  1361. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1362. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1363. ;; Make sure properties are removed when copying text
  1364. (when (boundp 'buffer-substring-filters)
  1365. (org-set-local 'buffer-substring-filters
  1366. (cons (lambda (x)
  1367. (set-text-properties 0 (length x) nil x) x)
  1368. buffer-substring-filters)))
  1369. (unless org-agenda-keep-modes
  1370. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1371. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1372. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1373. org-agenda-show-log org-agenda-start-with-log-mode))
  1374. (easy-menu-change
  1375. '("Agenda") "Agenda Files"
  1376. (append
  1377. (list
  1378. (vector
  1379. (if (get 'org-agenda-files 'org-restrict)
  1380. "Restricted to single file"
  1381. "Edit File List")
  1382. '(org-edit-agenda-file-list)
  1383. (not (get 'org-agenda-files 'org-restrict)))
  1384. "--")
  1385. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1386. (org-agenda-set-mode-name)
  1387. (apply
  1388. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1389. (list 'org-agenda-mode-hook)))
  1390. (substitute-key-definition 'undo 'org-agenda-undo
  1391. org-agenda-mode-map global-map)
  1392. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1393. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1394. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1395. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1396. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1397. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1398. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1399. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1400. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1401. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1402. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1403. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1404. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1405. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1406. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1407. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1408. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1409. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1410. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1411. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1412. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1413. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1414. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1415. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1416. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1417. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1418. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1419. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1420. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1421. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1422. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1423. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1424. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1425. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1426. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1427. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1428. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1429. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1430. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1431. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1432. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1433. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1434. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1435. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1436. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1437. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1438. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1439. (while l (org-defkey org-agenda-mode-map
  1440. (int-to-string (pop l)) 'digit-argument)))
  1441. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1442. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1443. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1444. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1445. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1446. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1447. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1448. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1449. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1450. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1451. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1452. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1453. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1454. 'org-clock-modify-effort-estimate)
  1455. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1456. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1457. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1458. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1459. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1460. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1461. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1462. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1463. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1464. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1465. (substitute-key-definition 'next-line 'org-agenda-next-line
  1466. org-agenda-mode-map global-map)
  1467. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1468. org-agenda-mode-map global-map)
  1469. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1470. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1471. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1472. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1473. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1474. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1475. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1476. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1477. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1478. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1479. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1480. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1481. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1482. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1483. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1484. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1485. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1486. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1487. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1488. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1489. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1490. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1491. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1492. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1493. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1494. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1495. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1496. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1497. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1498. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1499. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1500. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1501. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1502. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1503. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1504. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1505. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1506. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1507. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1508. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1509. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1510. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1511. (when org-agenda-mouse-1-follows-link
  1512. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1513. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1514. '("Agenda"
  1515. ("Agenda Files")
  1516. "--"
  1517. ("Agenda Dates"
  1518. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1519. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1520. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1521. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1522. "--"
  1523. ("View"
  1524. ["Day View" org-agenda-day-view
  1525. :active (org-agenda-check-type nil 'agenda)
  1526. :style radio :selected (equal org-agenda-ndays 1)
  1527. :keys "v d (or just d)"]
  1528. ["Week View" org-agenda-week-view
  1529. :active (org-agenda-check-type nil 'agenda)
  1530. :style radio :selected (equal org-agenda-ndays 7)
  1531. :keys "v w (or just w)"]
  1532. ["Month View" org-agenda-month-view
  1533. :active (org-agenda-check-type nil 'agenda)
  1534. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1535. :keys "v m"]
  1536. ["Year View" org-agenda-year-view
  1537. :active (org-agenda-check-type nil 'agenda)
  1538. :style radio :selected (member org-agenda-ndays '(365 366))
  1539. :keys "v y"]
  1540. "--"
  1541. ["Include Diary" org-agenda-toggle-diary
  1542. :style toggle :selected org-agenda-include-diary
  1543. :active (org-agenda-check-type nil 'agenda)]
  1544. ["Include Deadlines" org-agenda-toggle-deadlines
  1545. :style toggle :selected org-agenda-include-deadlines
  1546. :active (org-agenda-check-type nil 'agenda)]
  1547. ["Use Time Grid" org-agenda-toggle-time-grid
  1548. :style toggle :selected org-agenda-use-time-grid
  1549. :active (org-agenda-check-type nil 'agenda)]
  1550. "--"
  1551. ["Show clock report" org-agenda-clockreport-mode
  1552. :style toggle :selected org-agenda-clockreport-mode
  1553. :active (org-agenda-check-type nil 'agenda)]
  1554. ["Show some entry text" org-agenda-entry-text-mode
  1555. :style toggle :selected org-agenda-entry-text-mode
  1556. :active t]
  1557. "--"
  1558. ["Show Logbook entries" org-agenda-log-mode
  1559. :style toggle :selected org-agenda-show-log
  1560. :active (org-agenda-check-type nil 'agenda 'timeline)
  1561. :keys "v l (or just l)"]
  1562. ["Include archived trees" org-agenda-archives-mode
  1563. :style toggle :selected org-agenda-archives-mode :active t
  1564. :keys "v a"]
  1565. ["Include archive files" (org-agenda-archives-mode t)
  1566. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1567. :keys "v A"]
  1568. "--"
  1569. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1570. ["Write view to file" org-write-agenda t]
  1571. ["Rebuild buffer" org-agenda-redo t]
  1572. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1573. "--"
  1574. ["Show original entry" org-agenda-show t]
  1575. ["Go To (other window)" org-agenda-goto t]
  1576. ["Go To (this window)" org-agenda-switch-to t]
  1577. ["Follow Mode" org-agenda-follow-mode
  1578. :style toggle :selected org-agenda-follow-mode :active t]
  1579. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1580. "--"
  1581. ("TODO"
  1582. ["Cycle TODO" org-agenda-todo t]
  1583. ["Next TODO set" org-agenda-todo-nextset t]
  1584. ["Previous TODO set" org-agenda-todo-previousset t]
  1585. ["Add note" org-agenda-add-note t])
  1586. ("Archive/Refile/Delete"
  1587. ["Archive default" org-agenda-archive-default t]
  1588. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1589. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1590. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1591. ["Archive subtree" org-agenda-archive t]
  1592. "--"
  1593. ["Refile" org-agenda-refile t]
  1594. "--"
  1595. ["Delete subtree" org-agenda-kill t])
  1596. ("Bulk action"
  1597. ["Mark entry" org-agenda-bulk-mark t]
  1598. ["Unmark entry" org-agenda-bulk-unmark t]
  1599. ["Act on all marked" org-agenda-bulk-action t]
  1600. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1601. "--"
  1602. ("Tags and Properties"
  1603. ["Show all Tags" org-agenda-show-tags t]
  1604. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1605. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1606. "--"
  1607. ["Column View" org-columns t])
  1608. ("Deadline/Schedule"
  1609. ["Schedule" org-agenda-schedule t]
  1610. ["Set Deadline" org-agenda-deadline t]
  1611. "--"
  1612. ["Mark item" org-agenda-action :active t :keys "k m"]
  1613. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1614. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1615. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1616. "--"
  1617. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1618. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1619. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1620. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1621. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1622. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1623. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1624. ("Clock and Effort"
  1625. ["Clock in" org-agenda-clock-in t]
  1626. ["Clock out" org-agenda-clock-out t]
  1627. ["Clock cancel" org-agenda-clock-cancel t]
  1628. ["Goto running clock" org-clock-goto t]
  1629. "--"
  1630. ["Set Effort" org-agenda-set-effort t]
  1631. ["Change clocked effort" org-clock-modify-effort-estimate
  1632. (org-clock-is-active)])
  1633. ("Priority"
  1634. ["Set Priority" org-agenda-priority t]
  1635. ["Increase Priority" org-agenda-priority-up t]
  1636. ["Decrease Priority" org-agenda-priority-down t]
  1637. ["Show Priority" org-agenda-show-priority t])
  1638. ("Calendar/Diary"
  1639. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1640. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1641. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1642. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1643. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1644. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1645. "--"
  1646. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1647. "--"
  1648. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1649. "--"
  1650. ("MobileOrg"
  1651. ["Push Files and Views" org-mobile-push t]
  1652. ["Get Captured and Flagged" org-mobile-pull t]
  1653. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1654. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1655. "--"
  1656. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1657. "--"
  1658. ["Quit" org-agenda-quit t]
  1659. ["Exit and Release Buffers" org-agenda-exit t]
  1660. ))
  1661. ;;; Agenda undo
  1662. (defvar org-agenda-allow-remote-undo t
  1663. "Non-nil means allow remote undo from the agenda buffer.")
  1664. (defvar org-agenda-undo-list nil
  1665. "List of undoable operations in the agenda since last refresh.")
  1666. (defvar org-agenda-undo-has-started-in nil
  1667. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1668. (defvar org-agenda-pending-undo-list nil
  1669. "In a series of undo commands, this is the list of remaining undo items.")
  1670. (defun org-agenda-undo ()
  1671. "Undo a remote editing step in the agenda.
  1672. This undoes changes both in the agenda buffer and in the remote buffer
  1673. that have been changed along."
  1674. (interactive)
  1675. (or org-agenda-allow-remote-undo
  1676. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1677. (if (not (eq this-command last-command))
  1678. (setq org-agenda-undo-has-started-in nil
  1679. org-agenda-pending-undo-list org-agenda-undo-list))
  1680. (if (not org-agenda-pending-undo-list)
  1681. (error "No further undo information"))
  1682. (let* ((entry (pop org-agenda-pending-undo-list))
  1683. buf line cmd rembuf)
  1684. (setq cmd (pop entry) line (pop entry))
  1685. (setq rembuf (nth 2 entry))
  1686. (org-with-remote-undo rembuf
  1687. (while (bufferp (setq buf (pop entry)))
  1688. (if (pop entry)
  1689. (with-current-buffer buf
  1690. (let ((last-undo-buffer buf)
  1691. (inhibit-read-only t))
  1692. (unless (memq buf org-agenda-undo-has-started-in)
  1693. (push buf org-agenda-undo-has-started-in)
  1694. (make-local-variable 'pending-undo-list)
  1695. (undo-start))
  1696. (while (and pending-undo-list
  1697. (listp pending-undo-list)
  1698. (not (car pending-undo-list)))
  1699. (pop pending-undo-list))
  1700. (undo-more 1))))))
  1701. (org-goto-line line)
  1702. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1703. (defun org-verify-change-for-undo (l1 l2)
  1704. "Verify that a real change occurred between the undo lists L1 and L2."
  1705. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1706. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1707. (not (eq l1 l2)))
  1708. ;;; Agenda dispatch
  1709. (defvar org-agenda-restrict nil)
  1710. (defvar org-agenda-restrict-begin (make-marker))
  1711. (defvar org-agenda-restrict-end (make-marker))
  1712. (defvar org-agenda-last-dispatch-buffer nil)
  1713. (defvar org-agenda-overriding-restriction nil)
  1714. ;;;###autoload
  1715. (defun org-agenda (&optional arg keys restriction)
  1716. "Dispatch agenda commands to collect entries to the agenda buffer.
  1717. Prompts for a command to execute. Any prefix arg will be passed
  1718. on to the selected command. The default selections are:
  1719. a Call `org-agenda-list' to display the agenda for current day or week.
  1720. t Call `org-todo-list' to display the global todo list.
  1721. T Call `org-todo-list' to display the global todo list, select only
  1722. entries with a specific TODO keyword (the user gets a prompt).
  1723. m Call `org-tags-view' to display headlines with tags matching
  1724. a condition (the user is prompted for the condition).
  1725. M Like `m', but select only TODO entries, no ordinary headlines.
  1726. L Create a timeline for the current buffer.
  1727. e Export views to associated files.
  1728. s Search entries for keywords.
  1729. / Multi occur across all agenda files and also files listed
  1730. in `org-agenda-text-search-extra-files'.
  1731. < Restrict agenda commands to buffer, subtree, or region.
  1732. Press several times to get the desired effect.
  1733. > Remove a previous restriction.
  1734. # List \"stuck\" projects.
  1735. ! Configure what \"stuck\" means.
  1736. C Configure custom agenda commands.
  1737. More commands can be added by configuring the variable
  1738. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1739. searches can be pre-defined in this way.
  1740. If the current buffer is in Org-mode and visiting a file, you can also
  1741. first press `<' once to indicate that the agenda should be temporarily
  1742. \(until the next use of \\[org-agenda]) restricted to the current file.
  1743. Pressing `<' twice means to restrict to the current subtree or region
  1744. \(if active)."
  1745. (interactive "P")
  1746. (catch 'exit
  1747. (let* ((prefix-descriptions nil)
  1748. (org-agenda-window-setup (if (equal (buffer-name)
  1749. org-agenda-buffer-name)
  1750. 'current-window
  1751. org-agenda-window-setup))
  1752. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1753. (org-agenda-custom-commands
  1754. ;; normalize different versions
  1755. (delq nil
  1756. (mapcar
  1757. (lambda (x)
  1758. (cond ((stringp (cdr x))
  1759. (push x prefix-descriptions)
  1760. nil)
  1761. ((stringp (nth 1 x)) x)
  1762. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1763. (t (cons (car x) (cons "" (cdr x))))))
  1764. org-agenda-custom-commands)))
  1765. (buf (current-buffer))
  1766. (bfn (buffer-file-name (buffer-base-buffer)))
  1767. entry key type match lprops ans)
  1768. ;; Turn off restriction unless there is an overriding one,
  1769. (unless org-agenda-overriding-restriction
  1770. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1771. ;; There is a request to keep the file list in place
  1772. (put 'org-agenda-files 'org-restrict nil))
  1773. (setq org-agenda-restrict nil)
  1774. (move-marker org-agenda-restrict-begin nil)
  1775. (move-marker org-agenda-restrict-end nil))
  1776. ;; Delete old local properties
  1777. (put 'org-agenda-redo-command 'org-lprops nil)
  1778. ;; Remember where this call originated
  1779. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1780. (unless keys
  1781. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1782. keys (car ans)
  1783. restriction (cdr ans)))
  1784. ;; Establish the restriction, if any
  1785. (when (and (not org-agenda-overriding-restriction) restriction)
  1786. (put 'org-agenda-files 'org-restrict (list bfn))
  1787. (cond
  1788. ((eq restriction 'region)
  1789. (setq org-agenda-restrict t)
  1790. (move-marker org-agenda-restrict-begin (region-beginning))
  1791. (move-marker org-agenda-restrict-end (region-end)))
  1792. ((eq restriction 'subtree)
  1793. (save-excursion
  1794. (setq org-agenda-restrict t)
  1795. (org-back-to-heading t)
  1796. (move-marker org-agenda-restrict-begin (point))
  1797. (move-marker org-agenda-restrict-end
  1798. (progn (org-end-of-subtree t)))))))
  1799. ;; For example the todo list should not need it (but does...)
  1800. (cond
  1801. ((setq entry (assoc keys org-agenda-custom-commands))
  1802. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1803. (progn
  1804. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1805. lprops (nth 4 entry))
  1806. (put 'org-agenda-redo-command 'org-lprops lprops)
  1807. (cond
  1808. ((eq type 'agenda)
  1809. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1810. ((eq type 'alltodo)
  1811. (org-let lprops '(org-todo-list current-prefix-arg)))
  1812. ((eq type 'search)
  1813. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1814. ((eq type 'stuck)
  1815. (org-let lprops '(org-agenda-list-stuck-projects
  1816. current-prefix-arg)))
  1817. ((eq type 'tags)
  1818. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1819. ((eq type 'tags-todo)
  1820. (org-let lprops '(org-tags-view '(4) match)))
  1821. ((eq type 'todo)
  1822. (org-let lprops '(org-todo-list match)))
  1823. ((eq type 'tags-tree)
  1824. (org-check-for-org-mode)
  1825. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1826. ((eq type 'todo-tree)
  1827. (org-check-for-org-mode)
  1828. (org-let lprops
  1829. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1830. (regexp-quote match) "\\>"))))
  1831. ((eq type 'occur-tree)
  1832. (org-check-for-org-mode)
  1833. (org-let lprops '(org-occur match)))
  1834. ((functionp type)
  1835. (org-let lprops '(funcall type match)))
  1836. ((fboundp type)
  1837. (org-let lprops '(funcall type match)))
  1838. (t (error "Invalid custom agenda command type %s" type))))
  1839. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1840. ((equal keys "C")
  1841. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1842. (customize-variable 'org-agenda-custom-commands))
  1843. ((equal keys "a") (call-interactively 'org-agenda-list))
  1844. ((equal keys "s") (call-interactively 'org-search-view))
  1845. ((equal keys "t") (call-interactively 'org-todo-list))
  1846. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1847. ((equal keys "m") (call-interactively 'org-tags-view))
  1848. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1849. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1850. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1851. (org-add-hook
  1852. 'post-command-hook
  1853. (lambda ()
  1854. (unless (current-message)
  1855. (let* ((m (org-agenda-get-any-marker))
  1856. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1857. (when note
  1858. (message (concat
  1859. "FLAGGING-NOTE ([?] for more info): "
  1860. (org-add-props
  1861. (replace-regexp-in-string
  1862. "\\\\n" "//"
  1863. (copy-sequence note))
  1864. nil 'face 'org-warning)))))))
  1865. t t))
  1866. ((equal keys "L")
  1867. (unless (org-mode-p)
  1868. (error "This is not an Org-mode file"))
  1869. (unless restriction
  1870. (put 'org-agenda-files 'org-restrict (list bfn))
  1871. (org-call-with-arg 'org-timeline arg)))
  1872. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1873. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1874. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1875. (t (error "Invalid agenda key"))))))
  1876. (defun org-agenda-normalize-custom-commands (cmds)
  1877. (delq nil
  1878. (mapcar
  1879. (lambda (x)
  1880. (cond ((stringp (cdr x)) nil)
  1881. ((stringp (nth 1 x)) x)
  1882. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1883. (t (cons (car x) (cons "" (cdr x))))))
  1884. cmds)))
  1885. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1886. "The user interface for selecting an agenda command."
  1887. (catch 'exit
  1888. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1889. (restrict-ok (and bfn (org-mode-p)))
  1890. (region-p (org-region-active-p))
  1891. (custom org-agenda-custom-commands)
  1892. (selstring "")
  1893. restriction second-time
  1894. c entry key type match prefixes rmheader header-end custom1 desc
  1895. line lines left right n n1)
  1896. (save-window-excursion
  1897. (delete-other-windows)
  1898. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1899. (erase-buffer)
  1900. (insert (eval-when-compile
  1901. (let ((header
  1902. "
  1903. Press key for an agenda command: < Buffer, subtree/region restriction
  1904. -------------------------------- > Remove restriction
  1905. a Agenda for current week or day e Export agenda views
  1906. t List of all TODO entries T Entries with special TODO kwd
  1907. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1908. L Timeline for current buffer # List stuck projects (!=configure)
  1909. s Search for keywords C Configure custom agenda commands
  1910. / Multi-occur ? Find :FLAGGED: entries
  1911. ")
  1912. (start 0))
  1913. (while (string-match
  1914. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1915. header start)
  1916. (setq start (match-end 0))
  1917. (add-text-properties (match-beginning 2) (match-end 2)
  1918. '(face bold) header))
  1919. header)))
  1920. (setq header-end (move-marker (make-marker) (point)))
  1921. (while t
  1922. (setq custom1 custom)
  1923. (when (eq rmheader t)
  1924. (org-goto-line 1)
  1925. (re-search-forward ":" nil t)
  1926. (delete-region (match-end 0) (point-at-eol))
  1927. (forward-char 1)
  1928. (looking-at "-+")
  1929. (delete-region (match-end 0) (point-at-eol))
  1930. (move-marker header-end (match-end 0)))
  1931. (goto-char header-end)
  1932. (delete-region (point) (point-max))
  1933. ;; Produce all the lines that describe custom commands and prefixes
  1934. (setq lines nil)
  1935. (while (setq entry (pop custom1))
  1936. (setq key (car entry) desc (nth 1 entry)
  1937. type (nth 2 entry)
  1938. match (nth 3 entry))
  1939. (if (> (length key) 1)
  1940. (add-to-list 'prefixes (string-to-char key))
  1941. (setq line
  1942. (format
  1943. "%-4s%-14s"
  1944. (org-add-props (copy-sequence key)
  1945. '(face bold))
  1946. (cond
  1947. ((string-match "\\S-" desc) desc)
  1948. ((eq type 'agenda) "Agenda for current week or day")
  1949. ((eq type 'alltodo) "List of all TODO entries")
  1950. ((eq type 'search) "Word search")
  1951. ((eq type 'stuck) "List of stuck projects")
  1952. ((eq type 'todo) "TODO keyword")
  1953. ((eq type 'tags) "Tags query")
  1954. ((eq type 'tags-todo) "Tags (TODO)")
  1955. ((eq type 'tags-tree) "Tags tree")
  1956. ((eq type 'todo-tree) "TODO kwd tree")
  1957. ((eq type 'occur-tree) "Occur tree")
  1958. ((functionp type) (if (symbolp type)
  1959. (symbol-name type)
  1960. "Lambda expression"))
  1961. (t "???"))))
  1962. (if org-agenda-menu-show-matcher
  1963. (setq line
  1964. (concat line ": "
  1965. (cond
  1966. ((stringp match)
  1967. (setq match (copy-sequence match))
  1968. (org-add-props match nil 'face 'org-warning))
  1969. (match
  1970. (format "set of %d commands" (length match)))
  1971. (t ""))))
  1972. (if (org-string-nw-p match)
  1973. (add-text-properties
  1974. 0 (length line) (list 'help-echo
  1975. (concat "Matcher: "match)) line)))
  1976. (push line lines)))
  1977. (setq lines (nreverse lines))
  1978. (when prefixes
  1979. (mapc (lambda (x)
  1980. (push
  1981. (format "%s %s"
  1982. (org-add-props (char-to-string x)
  1983. nil 'face 'bold)
  1984. (or (cdr (assoc (concat selstring
  1985. (char-to-string x))
  1986. prefix-descriptions))
  1987. "Prefix key"))
  1988. lines))
  1989. prefixes))
  1990. ;; Check if we should display in two columns
  1991. (if org-agenda-menu-two-column
  1992. (progn
  1993. (setq n (length lines)
  1994. n1 (+ (/ n 2) (mod n 2))
  1995. right (nthcdr n1 lines)
  1996. left (copy-sequence lines))
  1997. (setcdr (nthcdr (1- n1) left) nil))
  1998. (setq left lines right nil))
  1999. (while left
  2000. (insert "\n" (pop left))
  2001. (when right
  2002. (if (< (current-column) 40)
  2003. (move-to-column 40 t)
  2004. (insert " "))
  2005. (insert (pop right))))
  2006. ;; Make the window the right size
  2007. (goto-char (point-min))
  2008. (if second-time
  2009. (if (not (pos-visible-in-window-p (point-max)))
  2010. (org-fit-window-to-buffer))
  2011. (setq second-time t)
  2012. (org-fit-window-to-buffer))
  2013. ;; Ask for selection
  2014. (message "Press key for agenda command%s:"
  2015. (if (or restrict-ok org-agenda-overriding-restriction)
  2016. (if org-agenda-overriding-restriction
  2017. " (restriction lock active)"
  2018. (if restriction
  2019. (format " (restricted to %s)" restriction)
  2020. " (unrestricted)"))
  2021. ""))
  2022. (setq c (read-char-exclusive))
  2023. (message "")
  2024. (cond
  2025. ((assoc (char-to-string c) custom)
  2026. (setq selstring (concat selstring (char-to-string c)))
  2027. (throw 'exit (cons selstring restriction)))
  2028. ((memq c prefixes)
  2029. (setq selstring (concat selstring (char-to-string c))
  2030. prefixes nil
  2031. rmheader (or rmheader t)
  2032. custom (delq nil (mapcar
  2033. (lambda (x)
  2034. (if (or (= (length (car x)) 1)
  2035. (/= (string-to-char (car x)) c))
  2036. nil
  2037. (cons (substring (car x) 1) (cdr x))))
  2038. custom))))
  2039. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2040. (message "Restriction is only possible in Org-mode buffers")
  2041. (ding) (sit-for 1))
  2042. ((eq c ?1)
  2043. (org-agenda-remove-restriction-lock 'noupdate)
  2044. (setq restriction 'buffer))
  2045. ((eq c ?0)
  2046. (org-agenda-remove-restriction-lock 'noupdate)
  2047. (setq restriction (if region-p 'region 'subtree)))
  2048. ((eq c ?<)
  2049. (org-agenda-remove-restriction-lock 'noupdate)
  2050. (setq restriction
  2051. (cond
  2052. ((eq restriction 'buffer)
  2053. (if region-p 'region 'subtree))
  2054. ((memq restriction '(subtree region))
  2055. nil)
  2056. (t 'buffer))))
  2057. ((eq c ?>)
  2058. (org-agenda-remove-restriction-lock 'noupdate)
  2059. (setq restriction nil))
  2060. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2061. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2062. ((and (> (length selstring) 0) (eq c ?\d))
  2063. (delete-window)
  2064. (org-agenda-get-restriction-and-command prefix-descriptions))
  2065. ((equal c ?q) (error "Abort"))
  2066. (t (error "Invalid key %c" c))))))))
  2067. (defun org-run-agenda-series (name series)
  2068. (org-let (nth 1 series) '(org-prepare-agenda name))
  2069. (let* ((org-agenda-multi t)
  2070. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2071. (cmds (car series))
  2072. (gprops (nth 1 series))
  2073. match ;; The byte compiler incorrectly complains about this. Keep it!
  2074. cmd type lprops)
  2075. (while (setq cmd (pop cmds))
  2076. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2077. (cond
  2078. ((eq type 'agenda)
  2079. (org-let2 gprops lprops
  2080. '(call-interactively 'org-agenda-list)))
  2081. ((eq type 'alltodo)
  2082. (org-let2 gprops lprops
  2083. '(call-interactively 'org-todo-list)))
  2084. ((eq type 'search)
  2085. (org-let2 gprops lprops
  2086. '(org-search-view current-prefix-arg match nil)))
  2087. ((eq type 'stuck)
  2088. (org-let2 gprops lprops
  2089. '(call-interactively 'org-agenda-list-stuck-projects)))
  2090. ((eq type 'tags)
  2091. (org-let2 gprops lprops
  2092. '(org-tags-view current-prefix-arg match)))
  2093. ((eq type 'tags-todo)
  2094. (org-let2 gprops lprops
  2095. '(org-tags-view '(4) match)))
  2096. ((eq type 'todo)
  2097. (org-let2 gprops lprops
  2098. '(org-todo-list match)))
  2099. ((fboundp type)
  2100. (org-let2 gprops lprops
  2101. '(funcall type match)))
  2102. (t (error "Invalid type in command series"))))
  2103. (widen)
  2104. (setq org-agenda-redo-command redo)
  2105. (goto-char (point-min)))
  2106. (org-fit-agenda-window)
  2107. (org-let (nth 1 series) '(org-finalize-agenda)))
  2108. ;;;###autoload
  2109. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2110. "Run an agenda command in batch mode and send the result to STDOUT.
  2111. If CMD-KEY is a string of length 1, it is used as a key in
  2112. `org-agenda-custom-commands' and triggers this command. If it is a
  2113. longer string it is used as a tags/todo match string.
  2114. Parameters are alternating variable names and values that will be bound
  2115. before running the agenda command."
  2116. (let (pars)
  2117. (while parameters
  2118. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2119. (if (> (length cmd-key) 2)
  2120. (eval (list 'let (nreverse pars)
  2121. (list 'org-tags-view nil cmd-key)))
  2122. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2123. (set-buffer org-agenda-buffer-name)
  2124. (princ (org-encode-for-stdout (buffer-string)))))
  2125. ;(defun org-encode-for-stdout (string)
  2126. ; (if (fboundp 'encode-coding-string)
  2127. ; (encode-coding-string string buffer-file-coding-system)
  2128. ; string))
  2129. (defun org-encode-for-stdout (string)
  2130. string)
  2131. (defvar org-agenda-info nil)
  2132. ;;;###autoload
  2133. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2134. "Run an agenda command in batch mode and send the result to STDOUT.
  2135. If CMD-KEY is a string of length 1, it is used as a key in
  2136. `org-agenda-custom-commands' and triggers this command. If it is a
  2137. longer string it is used as a tags/todo match string.
  2138. Parameters are alternating variable names and values that will be bound
  2139. before running the agenda command.
  2140. The output gives a line for each selected agenda item. Each
  2141. item is a list of comma-separated values, like this:
  2142. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2143. category The category of the item
  2144. head The headline, without TODO kwd, TAGS and PRIORITY
  2145. type The type of the agenda entry, can be
  2146. todo selected in TODO match
  2147. tagsmatch selected in tags match
  2148. diary imported from diary
  2149. deadline a deadline on given date
  2150. scheduled scheduled on given date
  2151. timestamp entry has timestamp on given date
  2152. closed entry was closed on given date
  2153. upcoming-deadline warning about deadline
  2154. past-scheduled forwarded scheduled item
  2155. block entry has date block including g. date
  2156. todo The todo keyword, if any
  2157. tags All tags including inherited ones, separated by colons
  2158. date The relevant date, like 2007-2-14
  2159. time The time, like 15:00-16:50
  2160. extra Sting with extra planning info
  2161. priority-l The priority letter if any was given
  2162. priority-n The computed numerical priority
  2163. agenda-day The day in the agenda where this is listed"
  2164. (let (pars)
  2165. (while parameters
  2166. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2167. (push (list 'org-agenda-remove-tags t) pars)
  2168. (if (> (length cmd-key) 2)
  2169. (eval (list 'let (nreverse pars)
  2170. (list 'org-tags-view nil cmd-key)))
  2171. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2172. (set-buffer org-agenda-buffer-name)
  2173. (let* ((lines (org-split-string (buffer-string) "\n"))
  2174. line)
  2175. (while (setq line (pop lines))
  2176. (catch 'next
  2177. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2178. (setq org-agenda-info
  2179. (org-fix-agenda-info (text-properties-at 0 line)))
  2180. (princ
  2181. (org-encode-for-stdout
  2182. (mapconcat 'org-agenda-export-csv-mapper
  2183. '(org-category txt type todo tags date time extra
  2184. priority-letter priority agenda-day)
  2185. ",")))
  2186. (princ "\n"))))))
  2187. (defun org-fix-agenda-info (props)
  2188. "Make sure all properties on an agenda item have a canonical form.
  2189. This ensures the export commands can easily use it."
  2190. (let (tmp re)
  2191. (when (setq tmp (plist-get props 'tags))
  2192. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2193. (when (setq tmp (plist-get props 'date))
  2194. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2195. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2196. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2197. (setq tmp (calendar-date-string tmp)))
  2198. (setq props (plist-put props 'date tmp)))
  2199. (when (setq tmp (plist-get props 'day))
  2200. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2201. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2202. (setq tmp (calendar-date-string tmp)))
  2203. (setq props (plist-put props 'day tmp))
  2204. (setq props (plist-put props 'agenda-day tmp)))
  2205. (when (setq tmp (plist-get props 'txt))
  2206. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2207. (plist-put props 'priority-letter (match-string 1 tmp))
  2208. (setq tmp (replace-match "" t t tmp)))
  2209. (when (and (setq re (plist-get props 'org-todo-regexp))
  2210. (setq re (concat "\\`\\.*" re " ?"))
  2211. (string-match re tmp))
  2212. (plist-put props 'todo (match-string 1 tmp))
  2213. (setq tmp (replace-match "" t t tmp)))
  2214. (plist-put props 'txt tmp)))
  2215. props)
  2216. (defun org-agenda-export-csv-mapper (prop)
  2217. (let ((res (plist-get org-agenda-info prop)))
  2218. (setq res
  2219. (cond
  2220. ((not res) "")
  2221. ((stringp res) res)
  2222. (t (prin1-to-string res))))
  2223. (while (string-match "," res)
  2224. (setq res (replace-match ";" t t res)))
  2225. (org-trim res)))
  2226. ;;;###autoload
  2227. (defun org-store-agenda-views (&rest parameters)
  2228. (interactive)
  2229. (eval (list 'org-batch-store-agenda-views)))
  2230. ;; FIXME, why is this a macro?????
  2231. ;;;###autoload
  2232. (defmacro org-batch-store-agenda-views (&rest parameters)
  2233. "Run all custom agenda commands that have a file argument."
  2234. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2235. (pop-up-frames nil)
  2236. (dir default-directory)
  2237. pars cmd thiscmdkey files opts cmd-or-set)
  2238. (while parameters
  2239. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2240. (setq pars (reverse pars))
  2241. (save-window-excursion
  2242. (while cmds
  2243. (setq cmd (pop cmds)
  2244. thiscmdkey (car cmd)
  2245. cmd-or-set (nth 2 cmd)
  2246. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2247. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2248. (if (stringp files) (setq files (list files)))
  2249. (when files
  2250. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2251. (list 'org-agenda nil thiscmdkey)))
  2252. (set-buffer org-agenda-buffer-name)
  2253. (while files
  2254. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2255. (list 'org-write-agenda
  2256. (expand-file-name (pop files) dir) nil t))))
  2257. (and (get-buffer org-agenda-buffer-name)
  2258. (kill-buffer org-agenda-buffer-name)))))))
  2259. (defun org-agenda-mark-header-line (pos)
  2260. "Mark the line at POS as an agenda structure header."
  2261. (save-excursion
  2262. (goto-char pos)
  2263. (put-text-property (point-at-bol) (point-at-eol)
  2264. 'org-agenda-structural-header t)
  2265. (when org-agenda-title-append
  2266. (put-text-property (point-at-bol) (point-at-eol)
  2267. 'org-agenda-title-append org-agenda-title-append))))
  2268. (defvar org-mobile-creating-agendas)
  2269. (defun org-write-agenda (file &optional open nosettings)
  2270. "Write the current buffer (an agenda view) as a file.
  2271. Depending on the extension of the file name, plain text (.txt),
  2272. HTML (.html or .htm) or Postscript (.ps) is produced.
  2273. If the extension is .ics, run icalendar export over all files used
  2274. to construct the agenda and limit the export to entries listed in the
  2275. agenda now.
  2276. With prefix argument OPEN, open the new file immediately.
  2277. If NOSETTINGS is given, do not scope the settings of
  2278. `org-agenda-exporter-settings' into the export commands. This is used when
  2279. the settings have already been scoped and we do not wish to overrule other,
  2280. higher priority settings."
  2281. (interactive "FWrite agenda to file: \nP")
  2282. (if (not (file-writable-p file))
  2283. (error "Cannot write agenda to file %s" file))
  2284. (cond
  2285. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2286. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2287. (org-let (if nosettings nil org-agenda-exporter-settings)
  2288. `(save-excursion
  2289. (save-window-excursion
  2290. (org-agenda-mark-filtered-text)
  2291. (let ((bs (copy-sequence (buffer-string))) beg)
  2292. (org-agenda-unmark-filtered-text)
  2293. (with-temp-buffer
  2294. (insert bs)
  2295. (org-agenda-remove-marked-text 'org-filtered)
  2296. (while (setq beg (text-property-any (point-min) (point-max)
  2297. 'org-filtered t))
  2298. (delete-region
  2299. beg (or (next-single-property-change beg 'org-filtered)
  2300. (point-max))))
  2301. (run-hooks 'org-agenda-before-write-hook)
  2302. (cond
  2303. ((org-bound-and-true-p org-mobile-creating-agendas)
  2304. (org-mobile-write-agenda-for-mobile file))
  2305. ((string-match "\\.html?\\'" file)
  2306. (set-buffer (htmlize-buffer (current-buffer)))
  2307. (when (and org-agenda-export-html-style
  2308. (string-match "<style>" org-agenda-export-html-style))
  2309. ;; replace <style> section with org-agenda-export-html-style
  2310. (goto-char (point-min))
  2311. (kill-region (- (search-forward "<style") 6)
  2312. (search-forward "</style>"))
  2313. (insert org-agenda-export-html-style))
  2314. (write-file file)
  2315. (kill-buffer (current-buffer))
  2316. (message "HTML written to %s" file))
  2317. ((string-match "\\.ps\\'" file)
  2318. (require 'ps-print)
  2319. ,(flet ((ps-get-buffer-name () "Agenda View"))
  2320. (ps-print-buffer-with-faces file))
  2321. (message "Postscript written to %s" file))
  2322. ((string-match "\\.pdf\\'" file)
  2323. (require 'ps-print)
  2324. ,(flet ((ps-get-buffer-name () "Agenda View"))
  2325. (ps-print-buffer-with-faces
  2326. (concat (file-name-sans-extension file) ".ps")))
  2327. (call-process "ps2pdf" nil nil nil
  2328. (expand-file-name
  2329. (concat (file-name-sans-extension file) ".ps"))
  2330. (expand-file-name file))
  2331. (message "PDF written to %s" file))
  2332. ((string-match "\\.ics\\'" file)
  2333. (require 'org-icalendar)
  2334. (let ((org-agenda-marker-table
  2335. (org-create-marker-find-array
  2336. (org-agenda-collect-markers)))
  2337. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2338. (org-combined-agenda-icalendar-file file))
  2339. (apply 'org-export-icalendar 'combine
  2340. (org-agenda-files nil 'ifmode))))
  2341. (t
  2342. (let ((bs (buffer-string)))
  2343. (find-file file)
  2344. (erase-buffer)
  2345. (insert bs)
  2346. (save-buffer 0)
  2347. (kill-buffer (current-buffer))
  2348. (message "Plain text written to %s" file))))))))
  2349. (set-buffer org-agenda-buffer-name))
  2350. (when open (org-open-file file)))
  2351. (defvar org-agenda-filter-overlays nil)
  2352. (defun org-agenda-mark-filtered-text ()
  2353. "Mark all text hidden by filtering with a text property."
  2354. (let ((inhibit-read-only t))
  2355. (mapc
  2356. (lambda (o)
  2357. (when (equal (overlay-buffer o) (current-buffer))
  2358. (put-text-property
  2359. (overlay-start o) (overlay-end o)
  2360. 'org-filtered t)))
  2361. org-agenda-filter-overlays)))
  2362. (defun org-agenda-unmark-filtered-text ()
  2363. "Remove the filtering text property."
  2364. (let ((inhibit-read-only t))
  2365. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2366. (defun org-agenda-remove-marked-text (property &optional value)
  2367. "Delete all text marked with VALUE of PROPERTY.
  2368. VALUE defaults to t."
  2369. (let (beg)
  2370. (setq value (or value t))
  2371. (while (setq beg (text-property-any (point-min) (point-max)
  2372. property value))
  2373. (delete-region
  2374. beg (or (next-single-property-change beg 'org-filtered)
  2375. (point-max))))))
  2376. (defun org-agenda-add-entry-text ()
  2377. "Add entry text to agenda lines.
  2378. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2379. entry text following headings shown in the agenda.
  2380. Drawers will be excluded, also the line with scheduling/deadline info."
  2381. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2382. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2383. (let (m txt)
  2384. (goto-char (point-min))
  2385. (while (not (eobp))
  2386. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2387. (beginning-of-line 2)
  2388. (setq txt (org-agenda-get-some-entry-text
  2389. m org-agenda-add-entry-text-maxlines " > "))
  2390. (end-of-line 1)
  2391. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2392. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2393. &rest keep)
  2394. "Extract entry text from MARKER, at most N-LINES lines.
  2395. This will ignore drawers etc, just get the text.
  2396. If INDENT is given, prefix every line with this string. If KEEP is
  2397. given, it is a list of symbols, defining stuff that should not be
  2398. removed from the entry content. Currently only `planning' is allowed here."
  2399. (let (txt drawer-re kwd-time-re ind)
  2400. (save-excursion
  2401. (with-current-buffer (marker-buffer marker)
  2402. (if (not (org-mode-p))
  2403. (setq txt "")
  2404. (save-excursion
  2405. (save-restriction
  2406. (widen)
  2407. (goto-char marker)
  2408. (end-of-line 1)
  2409. (setq txt (buffer-substring
  2410. (min (1+ (point)) (point-max))
  2411. (progn (outline-next-heading) (point)))
  2412. drawer-re org-drawer-regexp
  2413. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2414. ".*\n?"))
  2415. (with-temp-buffer
  2416. (insert txt)
  2417. (when org-agenda-add-entry-text-descriptive-links
  2418. (goto-char (point-min))
  2419. (while (org-activate-bracket-links (point-max))
  2420. (add-text-properties (match-beginning 0) (match-end 0)
  2421. '(face org-link))))
  2422. (goto-char (point-min))
  2423. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2424. (set-text-properties (match-beginning 0) (match-end 0)
  2425. nil))
  2426. (goto-char (point-min))
  2427. (while (re-search-forward drawer-re nil t)
  2428. (delete-region
  2429. (match-beginning 0)
  2430. (progn (re-search-forward
  2431. "^[ \t]*:END:.*\n?" nil 'move)
  2432. (point))))
  2433. (unless (member 'planning keep)
  2434. (goto-char (point-min))
  2435. (while (re-search-forward kwd-time-re nil t)
  2436. (replace-match "")))
  2437. (goto-char (point-min))
  2438. (when org-agenda-entry-text-exclude-regexps
  2439. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2440. (while (setq re (pop re-list))
  2441. (goto-char (point-min))
  2442. (while (re-search-forward re nil t)
  2443. (replace-match "")))))
  2444. (goto-char (point-max))
  2445. (skip-chars-backward " \t\n")
  2446. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2447. ;; find and remove min common indentation
  2448. (goto-char (point-min))
  2449. (untabify (point-min) (point-max))
  2450. (setq ind (org-get-indentation))
  2451. (while (not (eobp))
  2452. (unless (looking-at "[ \t]*$")
  2453. (setq ind (min ind (org-get-indentation))))
  2454. (beginning-of-line 2))
  2455. (goto-char (point-min))
  2456. (while (not (eobp))
  2457. (unless (looking-at "[ \t]*$")
  2458. (move-to-column ind)
  2459. (delete-region (point-at-bol) (point)))
  2460. (beginning-of-line 2))
  2461. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2462. (goto-char (point-min))
  2463. (when indent
  2464. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2465. (replace-match indent t t)))
  2466. (goto-char (point-min))
  2467. (while (looking-at "[ \t]*\n") (replace-match ""))
  2468. (goto-char (point-max))
  2469. (when (> (org-current-line)
  2470. n-lines)
  2471. (org-goto-line (1+ n-lines))
  2472. (backward-char 1))
  2473. (setq txt (buffer-substring (point-min) (point)))))))))
  2474. txt))
  2475. (defun org-agenda-collect-markers ()
  2476. "Collect the markers pointing to entries in the agenda buffer."
  2477. (let (m markers)
  2478. (save-excursion
  2479. (goto-char (point-min))
  2480. (while (not (eobp))
  2481. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2482. (org-get-at-bol 'org-marker)))
  2483. (push m markers))
  2484. (beginning-of-line 2)))
  2485. (nreverse markers)))
  2486. (defun org-create-marker-find-array (marker-list)
  2487. "Create a alist of files names with all marker positions in that file."
  2488. (let (f tbl m a p)
  2489. (while (setq m (pop marker-list))
  2490. (setq p (marker-position m)
  2491. f (buffer-file-name (or (buffer-base-buffer
  2492. (marker-buffer m))
  2493. (marker-buffer m))))
  2494. (if (setq a (assoc f tbl))
  2495. (push (marker-position m) (cdr a))
  2496. (push (list f p) tbl)))
  2497. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2498. tbl)))
  2499. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2500. (defun org-check-agenda-marker-table ()
  2501. "Check of the current entry is on the marker list."
  2502. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2503. a)
  2504. (and (setq a (assoc file org-agenda-marker-table))
  2505. (save-match-data
  2506. (save-excursion
  2507. (org-back-to-heading t)
  2508. (member (point) (cdr a)))))))
  2509. (defun org-check-for-org-mode ()
  2510. "Make sure current buffer is in org-mode. Error if not."
  2511. (or (org-mode-p)
  2512. (error "Cannot execute org-mode agenda command on buffer in %s"
  2513. major-mode)))
  2514. (defun org-fit-agenda-window ()
  2515. "Fit the window to the buffer size."
  2516. (and (memq org-agenda-window-setup '(reorganize-frame))
  2517. (fboundp 'fit-window-to-buffer)
  2518. (org-fit-window-to-buffer
  2519. nil
  2520. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2521. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2522. ;;; Agenda prepare and finalize
  2523. (defvar org-agenda-multi nil) ; dynamically scoped
  2524. (defvar org-agenda-buffer-name "*Org Agenda*")
  2525. (defvar org-pre-agenda-window-conf nil)
  2526. (defvar org-agenda-columns-active nil)
  2527. (defvar org-agenda-name nil)
  2528. (defvar org-agenda-filter nil)
  2529. (defvar org-agenda-filter-preset nil
  2530. "A preset of the tags filter used for secondary agenda filtering.
  2531. This must be a list of strings, each string must be a single tag preceded
  2532. by \"+\" or \"-\".
  2533. This variable should not be set directly, but agenda custom commands can
  2534. bind it in the options section. The preset filter is a global property of
  2535. the entire agenda view. In a block agenda, it will not work reliably to
  2536. define a filter for one of the individual blocks. You need to set it in
  2537. the global options and expect it to be applied to the entire view.")
  2538. (defun org-prepare-agenda (&optional name)
  2539. (setq org-todo-keywords-for-agenda nil)
  2540. (setq org-done-keywords-for-agenda nil)
  2541. (setq org-drawers-for-agenda nil)
  2542. (unless org-agenda-persistent-filter
  2543. (setq org-agenda-filter nil))
  2544. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2545. (if org-agenda-multi
  2546. (progn
  2547. (setq buffer-read-only nil)
  2548. (goto-char (point-max))
  2549. (unless (or (bobp) org-agenda-compact-blocks)
  2550. (insert "\n"
  2551. (if (stringp org-agenda-block-separator)
  2552. org-agenda-block-separator
  2553. (make-string (window-width) org-agenda-block-separator))
  2554. "\n"))
  2555. (narrow-to-region (point) (point-max)))
  2556. (org-agenda-reset-markers)
  2557. (setq org-agenda-contributing-files nil)
  2558. (setq org-agenda-columns-active nil)
  2559. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2560. (setq org-todo-keywords-for-agenda
  2561. (org-uniquify org-todo-keywords-for-agenda))
  2562. (setq org-done-keywords-for-agenda
  2563. (org-uniquify org-done-keywords-for-agenda))
  2564. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2565. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2566. (awin (get-buffer-window abuf)))
  2567. (cond
  2568. ((equal (current-buffer) abuf) nil)
  2569. (awin (select-window awin))
  2570. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2571. ((equal org-agenda-window-setup 'current-window)
  2572. (switch-to-buffer abuf))
  2573. ((equal org-agenda-window-setup 'other-window)
  2574. (org-switch-to-buffer-other-window abuf))
  2575. ((equal org-agenda-window-setup 'other-frame)
  2576. (switch-to-buffer-other-frame abuf))
  2577. ((equal org-agenda-window-setup 'reorganize-frame)
  2578. (delete-other-windows)
  2579. (org-switch-to-buffer-other-window abuf))))
  2580. (setq buffer-read-only nil)
  2581. (let ((inhibit-read-only t)) (erase-buffer))
  2582. (org-agenda-mode)
  2583. (and name (not org-agenda-name)
  2584. (org-set-local 'org-agenda-name name)))
  2585. (setq buffer-read-only nil))
  2586. (defun org-finalize-agenda ()
  2587. "Finishing touch for the agenda buffer, called just before displaying it."
  2588. (unless org-agenda-multi
  2589. (save-excursion
  2590. (let ((inhibit-read-only t))
  2591. (goto-char (point-min))
  2592. (while (org-activate-bracket-links (point-max))
  2593. (add-text-properties (match-beginning 0) (match-end 0)
  2594. '(face org-link)))
  2595. (org-agenda-align-tags)
  2596. (unless org-agenda-with-colors
  2597. (remove-text-properties (point-min) (point-max) '(face nil))))
  2598. (if (and (boundp 'org-agenda-overriding-columns-format)
  2599. org-agenda-overriding-columns-format)
  2600. (org-set-local 'org-agenda-overriding-columns-format
  2601. org-agenda-overriding-columns-format))
  2602. (if (and (boundp 'org-agenda-view-columns-initially)
  2603. org-agenda-view-columns-initially)
  2604. (org-agenda-columns))
  2605. (when org-agenda-fontify-priorities
  2606. (org-agenda-fontify-priorities))
  2607. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2608. (org-agenda-dim-blocked-tasks))
  2609. (org-agenda-mark-clocking-task)
  2610. (when org-agenda-entry-text-mode
  2611. (org-agenda-entry-text-hide)
  2612. (org-agenda-entry-text-show))
  2613. (if (functionp 'org-habit-insert-consistency-graphs)
  2614. (org-habit-insert-consistency-graphs))
  2615. (run-hooks 'org-finalize-agenda-hook)
  2616. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2617. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2618. (org-agenda-filter-apply org-agenda-filter))
  2619. )))
  2620. (defun org-agenda-mark-clocking-task ()
  2621. "Mark the current clock entry in the agenda if it is present."
  2622. (mapc (lambda (o)
  2623. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2624. (delete-overlay o)))
  2625. (overlays-in (point-min) (point-max)))
  2626. (when (marker-buffer org-clock-hd-marker)
  2627. (save-excursion
  2628. (goto-char (point-min))
  2629. (let (s ov)
  2630. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2631. (goto-char s)
  2632. (when (equal (org-get-at-bol 'org-hd-marker)
  2633. org-clock-hd-marker)
  2634. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2635. (overlay-put ov 'type 'org-agenda-clocking)
  2636. (overlay-put ov 'face 'org-agenda-clocking)
  2637. (overlay-put ov 'help-echo
  2638. "The clock is running in this item")))))))
  2639. (defun org-agenda-fontify-priorities ()
  2640. "Make highest priority lines bold, and lowest italic."
  2641. (interactive)
  2642. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2643. (delete-overlay o)))
  2644. (overlays-in (point-min) (point-max)))
  2645. (save-excursion
  2646. (let ((inhibit-read-only t)
  2647. b e p ov h l)
  2648. (goto-char (point-min))
  2649. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2650. (setq h (or (get-char-property (point) 'org-highest-priority)
  2651. org-highest-priority)
  2652. l (or (get-char-property (point) 'org-lowest-priority)
  2653. org-lowest-priority)
  2654. p (string-to-char (match-string 1))
  2655. b (match-beginning 0)
  2656. e (if (eq org-agenda-fontify-priorities 'cookies)
  2657. (match-end 0)
  2658. (point-at-eol))
  2659. ov (make-overlay b e))
  2660. (overlay-put
  2661. ov 'face
  2662. (cond ((org-face-from-face-or-color
  2663. 'priority nil
  2664. (cdr (assoc p org-priority-faces))))
  2665. ((and (listp org-agenda-fontify-priorities)
  2666. (org-face-from-face-or-color
  2667. 'priority nil
  2668. (cdr (assoc p org-agenda-fontify-priorities)))))
  2669. ((equal p l) 'italic)
  2670. ((equal p h) 'bold)))
  2671. (overlay-put ov 'org-type 'org-priority)))))
  2672. (defun org-agenda-dim-blocked-tasks ()
  2673. "Dim currently blocked TODO's in the agenda display."
  2674. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2675. (delete-overlay o)))
  2676. (overlays-in (point-min) (point-max)))
  2677. (save-excursion
  2678. (let ((inhibit-read-only t)
  2679. (org-depend-tag-blocked nil)
  2680. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2681. org-blocked-by-checkboxes
  2682. invis1 b e p ov h l)
  2683. (goto-char (point-min))
  2684. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2685. (and pos (goto-char (1+ pos))))
  2686. (setq org-blocked-by-checkboxes nil invis1 invis)
  2687. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2688. (when (and marker
  2689. (not (with-current-buffer (marker-buffer marker)
  2690. (save-excursion
  2691. (goto-char marker)
  2692. (if (org-entry-get nil "NOBLOCKING")
  2693. t ;; Never block this entry
  2694. (run-hook-with-args-until-failure
  2695. 'org-blocker-hook
  2696. (list :type 'todo-state-change
  2697. :position marker
  2698. :from 'todo
  2699. :to 'done)))))))
  2700. (if org-blocked-by-checkboxes (setq invis1 nil))
  2701. (setq b (if invis1
  2702. (max (point-min) (1- (point-at-bol)))
  2703. (point-at-bol))
  2704. e (point-at-eol)
  2705. ov (make-overlay b e))
  2706. (if invis1
  2707. (overlay-put ov 'invisible t)
  2708. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2709. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2710. (defvar org-agenda-skip-function nil
  2711. "Function to be called at each match during agenda construction.
  2712. If this function returns nil, the current match should not be skipped.
  2713. Otherwise, the function must return a position from where the search
  2714. should be continued.
  2715. This may also be a Lisp form, it will be evaluated.
  2716. Never set this variable using `setq' or so, because then it will apply
  2717. to all future agenda commands. Instead, bind it with `let' to scope
  2718. it dynamically into the agenda-constructing command. A good way to set
  2719. it is through options in `org-agenda-custom-commands'.")
  2720. (defun org-agenda-skip ()
  2721. "Throw to `:skip' in places that should be skipped.
  2722. Also moves point to the end of the skipped region, so that search can
  2723. continue from there."
  2724. (let ((p (point-at-bol)) to fp)
  2725. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2726. (get-text-property p :org-archived)
  2727. (org-end-of-subtree t)
  2728. (throw :skip t))
  2729. (and org-agenda-skip-comment-trees
  2730. (get-text-property p :org-comment)
  2731. (org-end-of-subtree t)
  2732. (throw :skip t))
  2733. (if (equal (char-after p) ?#) (throw :skip t))
  2734. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2735. (consp org-agenda-skip-function))
  2736. (setq to (save-excursion
  2737. (save-match-data
  2738. (if fp
  2739. (funcall org-agenda-skip-function)
  2740. (eval org-agenda-skip-function))))))
  2741. (goto-char to)
  2742. (throw :skip t))))
  2743. (defvar org-agenda-markers nil
  2744. "List of all currently active markers created by `org-agenda'.")
  2745. (defvar org-agenda-last-marker-time (org-float-time)
  2746. "Creation time of the last agenda marker.")
  2747. (defun org-agenda-new-marker (&optional pos)
  2748. "Return a new agenda marker.
  2749. Org-mode keeps a list of these markers and resets them when they are
  2750. no longer in use."
  2751. (let ((m (copy-marker (or pos (point)))))
  2752. (setq org-agenda-last-marker-time (org-float-time))
  2753. (push m org-agenda-markers)
  2754. m))
  2755. (defun org-agenda-reset-markers ()
  2756. "Reset markers created by `org-agenda'."
  2757. (while org-agenda-markers
  2758. (move-marker (pop org-agenda-markers) nil)))
  2759. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2760. "Save relative positions of markers in region."
  2761. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2762. org-agenda-markers))
  2763. ;;; Entry text mode
  2764. (defun org-agenda-entry-text-show-here ()
  2765. "Add some text from the entry as context to the current line."
  2766. (let (m txt o)
  2767. (setq m (org-get-at-bol 'org-hd-marker))
  2768. (unless (marker-buffer m)
  2769. (error "No marker points to an entry here"))
  2770. (setq txt (concat "\n" (org-no-properties
  2771. (org-agenda-get-some-entry-text
  2772. m org-agenda-entry-text-maxlines " > "))))
  2773. (when (string-match "\\S-" txt)
  2774. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2775. (overlay-put o 'evaporate t)
  2776. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2777. (overlay-put o 'after-string txt))))
  2778. (defun org-agenda-entry-text-show ()
  2779. "Add entry context for all agenda lines."
  2780. (interactive)
  2781. (save-excursion
  2782. (goto-char (point-max))
  2783. (beginning-of-line 1)
  2784. (while (not (bobp))
  2785. (when (org-get-at-bol 'org-hd-marker)
  2786. (org-agenda-entry-text-show-here))
  2787. (beginning-of-line 0))))
  2788. (defun org-agenda-entry-text-hide ()
  2789. "Remove any shown entry context."
  2790. (delq nil
  2791. (mapcar (lambda (o)
  2792. (if (eq (overlay-get o 'org-overlay-type)
  2793. 'agenda-entry-content)
  2794. (progn (delete-overlay o) t)))
  2795. (overlays-in (point-min) (point-max)))))
  2796. ;;; Agenda timeline
  2797. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2798. (defun org-timeline (&optional include-all)
  2799. "Show a time-sorted view of the entries in the current org file.
  2800. Only entries with a time stamp of today or later will be listed. With
  2801. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2802. under the current date.
  2803. If the buffer contains an active region, only check the region for
  2804. dates."
  2805. (interactive "P")
  2806. (org-compile-prefix-format 'timeline)
  2807. (org-set-sorting-strategy 'timeline)
  2808. (let* ((dopast t)
  2809. (dotodo include-all)
  2810. (doclosed org-agenda-show-log)
  2811. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2812. (current-buffer))))
  2813. (date (calendar-current-date))
  2814. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2815. (end (if (org-region-active-p) (region-end) (point-max)))
  2816. (day-numbers (org-get-all-dates beg end 'no-ranges
  2817. t doclosed ; always include today
  2818. org-timeline-show-empty-dates))
  2819. (org-deadline-warning-days 0)
  2820. (org-agenda-only-exact-dates t)
  2821. (today (time-to-days (current-time)))
  2822. (past t)
  2823. args
  2824. s e rtn d emptyp wd)
  2825. (setq org-agenda-redo-command
  2826. (list 'progn
  2827. (list 'org-switch-to-buffer-other-window (current-buffer))
  2828. (list 'org-timeline (list 'quote include-all))))
  2829. (if (not dopast)
  2830. ;; Remove past dates from the list of dates.
  2831. (setq day-numbers (delq nil (mapcar (lambda(x)
  2832. (if (>= x today) x nil))
  2833. day-numbers))))
  2834. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2835. (if doclosed (push :closed args))
  2836. (push :timestamp args)
  2837. (push :deadline args)
  2838. (push :scheduled args)
  2839. (push :sexp args)
  2840. (if dotodo (push :todo args))
  2841. (insert "Timeline of file " entry "\n")
  2842. (add-text-properties (point-min) (point)
  2843. (list 'face 'org-agenda-structure))
  2844. (org-agenda-mark-header-line (point-min))
  2845. (while (setq d (pop day-numbers))
  2846. (if (and (listp d) (eq (car d) :omitted))
  2847. (progn
  2848. (setq s (point))
  2849. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2850. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2851. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2852. (if (and (>= d today)
  2853. dopast
  2854. past)
  2855. (progn
  2856. (setq past nil)
  2857. (insert (make-string 79 ?-) "\n")))
  2858. (setq date (calendar-gregorian-from-absolute d)
  2859. wd (calendar-day-of-week date))
  2860. (setq s (point))
  2861. (setq rtn (and (not emptyp)
  2862. (apply 'org-agenda-get-day-entries entry
  2863. date args)))
  2864. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2865. (progn
  2866. (insert
  2867. (if (stringp org-agenda-format-date)
  2868. (format-time-string org-agenda-format-date
  2869. (org-time-from-absolute date))
  2870. (funcall org-agenda-format-date date))
  2871. "\n")
  2872. (put-text-property s (1- (point)) 'face
  2873. (if (member wd org-agenda-weekend-days)
  2874. 'org-agenda-date-weekend
  2875. 'org-agenda-date))
  2876. (put-text-property s (1- (point)) 'org-date-line t)
  2877. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2878. (if (equal d today)
  2879. (put-text-property s (1- (point)) 'org-today t))
  2880. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2881. (put-text-property s (1- (point)) 'day d)))))
  2882. (goto-char (point-min))
  2883. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2884. (point-min)))
  2885. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2886. (org-finalize-agenda)
  2887. (setq buffer-read-only t)))
  2888. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2889. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2890. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2891. not every single day in the range. If FORCE-TODAY is non-nil, make
  2892. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2893. inactive time stamps (those in square brackets) are included.
  2894. When EMPTY is non-nil, also include days without any entries."
  2895. (let ((re (concat
  2896. (if pre-re pre-re "")
  2897. (if inactive org-ts-regexp-both org-ts-regexp)))
  2898. dates dates1 date day day1 day2 ts1 ts2)
  2899. (if force-today
  2900. (setq dates (list (time-to-days (current-time)))))
  2901. (save-excursion
  2902. (goto-char beg)
  2903. (while (re-search-forward re end t)
  2904. (setq day (time-to-days (org-time-string-to-time
  2905. (substring (match-string 1) 0 10))))
  2906. (or (memq day dates) (push day dates)))
  2907. (unless no-ranges
  2908. (goto-char beg)
  2909. (while (re-search-forward org-tr-regexp end t)
  2910. (setq ts1 (substring (match-string 1) 0 10)
  2911. ts2 (substring (match-string 2) 0 10)
  2912. day1 (time-to-days (org-time-string-to-time ts1))
  2913. day2 (time-to-days (org-time-string-to-time ts2)))
  2914. (while (< (setq day1 (1+ day1)) day2)
  2915. (or (memq day1 dates) (push day1 dates)))))
  2916. (setq dates (sort dates '<))
  2917. (when empty
  2918. (while (setq day (pop dates))
  2919. (setq day2 (car dates))
  2920. (push day dates1)
  2921. (when (and day2 empty)
  2922. (if (or (eq empty t)
  2923. (and (numberp empty) (<= (- day2 day) empty)))
  2924. (while (< (setq day (1+ day)) day2)
  2925. (push (list day) dates1))
  2926. (push (cons :omitted (- day2 day)) dates1))))
  2927. (setq dates (nreverse dates1)))
  2928. dates)))
  2929. ;;; Agenda Daily/Weekly
  2930. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2931. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2932. "Custom commands can set this variable in the options section.")
  2933. (defvar org-agenda-last-arguments nil
  2934. "The arguments of the previous call to `org-agenda'.")
  2935. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2936. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2937. (defvar org-include-all-loc nil) ; local variable
  2938. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2939. "List of types searched for when creating the daily/weekly agenda.
  2940. This variable is a list of symbols that controls the types of
  2941. items that appear in the daily/weekly agenda. Allowed symbols in this
  2942. list are are
  2943. :timestamp List items containing a date stamp or date range matching
  2944. the selected date. This includes sexp entries in
  2945. angular brackets.
  2946. :sexp List entries resulting from plain diary-like sexps.
  2947. :deadline List deadline due on that date. When the date is today,
  2948. also list any deadlines past due, or due within
  2949. `org-deadline-warning-days'. `:deadline' must appear before
  2950. `:scheduled' if the setting of
  2951. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2952. any effect.
  2953. :scheduled List all items which are scheduled for the given date.
  2954. The diary for *today* also contains items which were
  2955. scheduled earlier and are not yet marked DONE.
  2956. By default, all four types are turned on.
  2957. Never set this variable globally using `setq', because then it
  2958. will apply to all future agenda commands. Instead, bind it with
  2959. `let' to scope it dynamically into the the agenda-constructing
  2960. command. A good way to set it is through options in
  2961. `org-agenda-custom-commands'. For a more flexible (though
  2962. somewhat less efficient) way of determining what is included in
  2963. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2964. ;;;###autoload
  2965. (defun org-agenda-list (&optional include-all start-day ndays)
  2966. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2967. The view will be for the current day or week, but from the overview buffer
  2968. you will be able to go to other days/weeks.
  2969. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2970. all unfinished TODO items will also be shown, before the agenda.
  2971. This feature is considered obsolete, please use the TODO list or a block
  2972. agenda instead.
  2973. With a numeric prefix argument in an interactive call, the agenda will
  2974. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2975. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2976. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2977. given in `org-agenda-start-on-weekday'."
  2978. (interactive "P")
  2979. (if (and (integerp include-all) (> include-all 0))
  2980. (setq ndays include-all include-all nil))
  2981. (setq ndays (or ndays org-agenda-ndays)
  2982. start-day (or start-day org-agenda-start-day))
  2983. (if org-agenda-overriding-arguments
  2984. (setq include-all (car org-agenda-overriding-arguments)
  2985. start-day (nth 1 org-agenda-overriding-arguments)
  2986. ndays (nth 2 org-agenda-overriding-arguments)))
  2987. (if (stringp start-day)
  2988. ;; Convert to an absolute day number
  2989. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2990. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2991. (org-compile-prefix-format 'agenda)
  2992. (org-set-sorting-strategy 'agenda)
  2993. (let* ((org-agenda-start-on-weekday
  2994. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2995. org-agenda-start-on-weekday nil))
  2996. (thefiles (org-agenda-files nil 'ifmode))
  2997. (files thefiles)
  2998. (today (time-to-days
  2999. (time-subtract (current-time)
  3000. (list 0 (* 3600 org-extend-today-until) 0))))
  3001. (sd (or start-day today))
  3002. (start (if (or (null org-agenda-start-on-weekday)
  3003. (< org-agenda-ndays 7))
  3004. sd
  3005. (let* ((nt (calendar-day-of-week
  3006. (calendar-gregorian-from-absolute sd)))
  3007. (n1 org-agenda-start-on-weekday)
  3008. (d (- nt n1)))
  3009. (- sd (+ (if (< d 0) 7 0) d)))))
  3010. (day-numbers (list start))
  3011. (day-cnt 0)
  3012. (inhibit-redisplay (not debug-on-error))
  3013. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  3014. clocktable-start clocktable-end)
  3015. (setq org-agenda-redo-command
  3016. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3017. ;; Make the list of days
  3018. (setq ndays (or ndays org-agenda-ndays)
  3019. nd ndays)
  3020. (while (> ndays 1)
  3021. (push (1+ (car day-numbers)) day-numbers)
  3022. (setq ndays (1- ndays)))
  3023. (setq day-numbers (nreverse day-numbers))
  3024. (setq clocktable-start (car day-numbers)
  3025. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3026. (org-prepare-agenda "Day/Week")
  3027. (org-set-local 'org-starting-day (car day-numbers))
  3028. (org-set-local 'org-include-all-loc include-all)
  3029. (org-set-local 'org-agenda-span
  3030. (org-agenda-ndays-to-span nd))
  3031. (when (and (or include-all org-agenda-include-all-todo)
  3032. (member today day-numbers))
  3033. (setq files thefiles
  3034. rtnall nil)
  3035. (while (setq file (pop files))
  3036. (catch 'nextfile
  3037. (org-check-agenda-file file)
  3038. (setq date (calendar-gregorian-from-absolute today)
  3039. rtn (org-agenda-get-day-entries
  3040. file date :todo))
  3041. (setq rtnall (append rtnall rtn))))
  3042. (when rtnall
  3043. (insert "All currently open TODO items:\n")
  3044. (add-text-properties (point-min) (1- (point))
  3045. (list 'face 'org-agenda-structure
  3046. 'short-heading "All TODO items"))
  3047. (org-agenda-mark-header-line (point-min))
  3048. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3049. (unless org-agenda-compact-blocks
  3050. (let* ((d1 (car day-numbers))
  3051. (d2 (org-last day-numbers))
  3052. (w1 (org-days-to-iso-week d1))
  3053. (w2 (org-days-to-iso-week d2)))
  3054. (setq s (point))
  3055. (if org-agenda-overriding-header
  3056. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3057. nil 'face 'org-agenda-structure) "\n")
  3058. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3059. "-agenda"
  3060. (if (< (- d2 d1) 350)
  3061. (if (= w1 w2)
  3062. (format " (W%02d)" w1)
  3063. (format " (W%02d-W%02d)" w1 w2))
  3064. "")
  3065. ":\n")))
  3066. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3067. 'org-date-line t))
  3068. (org-agenda-mark-header-line s))
  3069. (while (setq d (pop day-numbers))
  3070. (setq date (calendar-gregorian-from-absolute d)
  3071. wd (calendar-day-of-week date)
  3072. s (point))
  3073. (if (or (setq todayp (= d today))
  3074. (and (not start-pos) (= d sd)))
  3075. (setq start-pos (point))
  3076. (if (and start-pos (not end-pos))
  3077. (setq end-pos (point))))
  3078. (setq files thefiles
  3079. rtnall nil)
  3080. (while (setq file (pop files))
  3081. (catch 'nextfile
  3082. (org-check-agenda-file file)
  3083. (let ((org-agenda-entry-types org-agenda-entry-types))
  3084. (unless org-agenda-include-deadlines
  3085. (setq org-agenda-entry-types
  3086. (delq :deadline org-agenda-entry-types)))
  3087. (cond
  3088. ((eq org-agenda-show-log 'only)
  3089. (setq rtn (org-agenda-get-day-entries
  3090. file date :closed)))
  3091. (org-agenda-show-log
  3092. (setq rtn (apply 'org-agenda-get-day-entries
  3093. file date
  3094. (append '(:closed) org-agenda-entry-types))))
  3095. (t
  3096. (setq rtn (apply 'org-agenda-get-day-entries
  3097. file date
  3098. org-agenda-entry-types)))))
  3099. (setq rtnall (append rtnall rtn))))
  3100. (if org-agenda-include-diary
  3101. (let ((org-agenda-search-headline-for-time t))
  3102. (require 'diary-lib)
  3103. (setq rtn (org-get-entries-from-diary date))
  3104. (setq rtnall (append rtnall rtn))))
  3105. (if (or rtnall org-agenda-show-all-dates)
  3106. (progn
  3107. (setq day-cnt (1+ day-cnt))
  3108. (insert
  3109. (if (stringp org-agenda-format-date)
  3110. (format-time-string org-agenda-format-date
  3111. (org-time-from-absolute date))
  3112. (funcall org-agenda-format-date date))
  3113. "\n")
  3114. (put-text-property s (1- (point)) 'face
  3115. (if (member wd org-agenda-weekend-days)
  3116. 'org-agenda-date-weekend
  3117. 'org-agenda-date))
  3118. (put-text-property s (1- (point)) 'org-date-line t)
  3119. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3120. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3121. (when todayp
  3122. (put-text-property s (1- (point)) 'org-today t)
  3123. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3124. (if rtnall (insert
  3125. (org-finalize-agenda-entries
  3126. (org-agenda-add-time-grid-maybe
  3127. rtnall nd todayp))
  3128. "\n"))
  3129. (put-text-property s (1- (point)) 'day d)
  3130. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3131. (when (and org-agenda-clockreport-mode clocktable-start)
  3132. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3133. ;; the above line is to ensure the restricted range!
  3134. (p org-agenda-clockreport-parameter-plist)
  3135. tbl)
  3136. (setq p (org-plist-delete p :block))
  3137. (setq p (plist-put p :tstart clocktable-start))
  3138. (setq p (plist-put p :tend clocktable-end))
  3139. (setq p (plist-put p :scope 'agenda))
  3140. (setq tbl (apply 'org-get-clocktable p))
  3141. (insert tbl)))
  3142. (goto-char (point-min))
  3143. (or org-agenda-multi (org-fit-agenda-window))
  3144. (unless (and (pos-visible-in-window-p (point-min))
  3145. (pos-visible-in-window-p (point-max)))
  3146. (goto-char (1- (point-max)))
  3147. (recenter -1)
  3148. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3149. (progn
  3150. (goto-char (or start-pos 1))
  3151. (recenter 1))))
  3152. (goto-char (or start-pos 1))
  3153. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3154. (org-finalize-agenda)
  3155. (setq buffer-read-only t)
  3156. (message "")))
  3157. (defun org-agenda-ndays-to-span (n)
  3158. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3159. ;;; Agenda word search
  3160. (defvar org-agenda-search-history nil)
  3161. (defvar org-todo-only nil)
  3162. (defvar org-search-syntax-table nil
  3163. "Special syntax table for org-mode search.
  3164. In this table, we have single quotes not as word constituents, to
  3165. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3166. (defun org-search-syntax-table ()
  3167. (unless org-search-syntax-table
  3168. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3169. (modify-syntax-entry ?' "." org-search-syntax-table)
  3170. (modify-syntax-entry ?` "." org-search-syntax-table))
  3171. org-search-syntax-table)
  3172. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3173. ;;;###autoload
  3174. (defun org-search-view (&optional todo-only string edit-at)
  3175. "Show all entries that contain a phrase or words or regular expressions.
  3176. With optional prefix argument TODO-ONLY, only consider entries that are
  3177. TODO entries. The argument STRING can be used to pass a default search
  3178. string into this function. If EDIT-AT is non-nil, it means that the
  3179. user should get a chance to edit this string, with cursor at position
  3180. EDIT-AT.
  3181. The search string can be viewed either as a phrase that should be found as
  3182. is, or it can be broken into a number of snippets, each of which must match
  3183. in a Boolean way to select an entry. The default depends on the variable
  3184. `org-agenda-search-view-always-boolean'.
  3185. Even if this is turned off (the default) you can always switch to
  3186. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3187. The default is a direct search of the whole phrase, where each space in
  3188. the search string can expand to an arbitrary amount of whitespace,
  3189. including newlines.
  3190. If using a Boolean search, the search string is split on whitespace and
  3191. each snippet is searched separately, with logical AND to select an entry.
  3192. Words prefixed with a minus must *not* occur in the entry. Words without
  3193. a prefix or prefixed with a plus must occur in the entry. Matching is
  3194. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3195. match whole words, not parts of a word) if
  3196. `org-agenda-search-view-force-full-words' is set (default is nil).
  3197. Boolean search snippets enclosed by curly braces are interpreted as
  3198. regular expressions that must or (when preceded with \"-\") must not
  3199. match in the entry. Snippets enclosed into double quotes will be taken
  3200. as a whole, to include whitespace.
  3201. - If the search string starts with an asterisk, search only in headlines.
  3202. - If (possibly after the leading star) the search string starts with an
  3203. exclamation mark, this also means to look at TODO entries only, an effect
  3204. that can also be achieved with a prefix argument.
  3205. - If (possibly after star and exclamation mark) the search string starts
  3206. with a colon, this will mean that the (non-regexp) snippets of the
  3207. Boolean search must match as full words.
  3208. This command searches the agenda files, and in addition the files listed
  3209. in `org-agenda-text-search-extra-files'."
  3210. (interactive "P")
  3211. (org-compile-prefix-format 'search)
  3212. (org-set-sorting-strategy 'search)
  3213. (org-prepare-agenda "SEARCH")
  3214. (let* ((props (list 'face nil
  3215. 'done-face 'org-agenda-done
  3216. 'org-not-done-regexp org-not-done-regexp
  3217. 'org-todo-regexp org-todo-regexp
  3218. 'org-complex-heading-regexp org-complex-heading-regexp
  3219. 'mouse-face 'highlight
  3220. 'help-echo (format "mouse-2 or RET jump to location")))
  3221. (full-words org-agenda-search-view-force-full-words)
  3222. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3223. regexp rtn rtnall files file pos
  3224. marker category tags c neg re boolean
  3225. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3226. (unless (and (not edit-at)
  3227. (stringp string)
  3228. (string-match "\\S-" string))
  3229. (setq string (read-string
  3230. (if org-agenda-search-view-always-boolean
  3231. "[+-]Word/{Regexp} ...: "
  3232. "Phrase, or [+-]Word/{Regexp} ...: ")
  3233. (cond
  3234. ((integerp edit-at) (cons string edit-at))
  3235. (edit-at string))
  3236. 'org-agenda-search-history)))
  3237. (org-set-local 'org-todo-only todo-only)
  3238. (setq org-agenda-redo-command
  3239. (list 'org-search-view (if todo-only t nil) string
  3240. '(if current-prefix-arg 1 nil)))
  3241. (setq org-agenda-query-string string)
  3242. (if (equal (string-to-char string) ?*)
  3243. (setq hdl-only t
  3244. words (substring string 1))
  3245. (setq words string))
  3246. (when (equal (string-to-char words) ?!)
  3247. (setq todo-only t
  3248. words (substring words 1)))
  3249. (when (equal (string-to-char words) ?:)
  3250. (setq full-words t
  3251. words (substring words 1)))
  3252. (if (or org-agenda-search-view-always-boolean
  3253. (member (string-to-char words) '(?- ?+ ?\{)))
  3254. (setq boolean t))
  3255. (setq words (org-split-string words))
  3256. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3257. (when boolean
  3258. (let (wds w)
  3259. (while (setq w (pop words))
  3260. (if (or (equal (substring w 0 1) "\"")
  3261. (and (> (length w) 1)
  3262. (member (substring w 0 1) '("+" "-"))
  3263. (equal (substring w 1 2) "\"")))
  3264. (while (and words (not (equal (substring w -1) "\"")))
  3265. (setq w (concat w " " (pop words)))))
  3266. (and (string-match "\\`\\([-+]?\\)\"" w)
  3267. (setq w (replace-match "\\1" nil nil w)))
  3268. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3269. (push w wds))
  3270. (setq words (nreverse wds))))
  3271. (if boolean
  3272. (mapc (lambda (w)
  3273. (setq c (string-to-char w))
  3274. (if (equal c ?-)
  3275. (setq neg t w (substring w 1))
  3276. (if (equal c ?+)
  3277. (setq neg nil w (substring w 1))
  3278. (setq neg nil)))
  3279. (if (string-match "\\`{.*}\\'" w)
  3280. (setq re (substring w 1 -1))
  3281. (if full-words
  3282. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3283. (setq re (regexp-quote (downcase w)))))
  3284. (if neg (push re regexps-) (push re regexps+)))
  3285. words)
  3286. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3287. regexps+))
  3288. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3289. (if (not regexps+)
  3290. (setq regexp (concat "^" org-outline-regexp))
  3291. (setq regexp (pop regexps+))
  3292. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3293. regexp))))
  3294. (setq files (org-agenda-files nil 'ifmode))
  3295. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3296. (pop org-agenda-text-search-extra-files)
  3297. (setq files (org-add-archive-files files)))
  3298. (setq files (append files org-agenda-text-search-extra-files)
  3299. rtnall nil)
  3300. (while (setq file (pop files))
  3301. (setq ee nil)
  3302. (catch 'nextfile
  3303. (org-check-agenda-file file)
  3304. (setq buffer (if (file-exists-p file)
  3305. (org-get-agenda-file-buffer file)
  3306. (error "No such file %s" file)))
  3307. (if (not buffer)
  3308. ;; If file does not exist, make sure an error message is sent
  3309. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3310. file))))
  3311. (with-current-buffer buffer
  3312. (with-syntax-table (org-search-syntax-table)
  3313. (unless (org-mode-p)
  3314. (error "Agenda file %s is not in `org-mode'" file))
  3315. (let ((case-fold-search t))
  3316. (save-excursion
  3317. (save-restriction
  3318. (if org-agenda-restrict
  3319. (narrow-to-region org-agenda-restrict-begin
  3320. org-agenda-restrict-end)
  3321. (widen))
  3322. (goto-char (point-min))
  3323. (unless (or (org-on-heading-p)
  3324. (outline-next-heading))
  3325. (throw 'nextfile t))
  3326. (goto-char (max (point-min) (1- (point))))
  3327. (while (re-search-forward regexp nil t)
  3328. (org-back-to-heading t)
  3329. (skip-chars-forward "* ")
  3330. (setq beg (point-at-bol)
  3331. beg1 (point)
  3332. end (progn (outline-next-heading) (point)))
  3333. (catch :skip
  3334. (goto-char beg)
  3335. (org-agenda-skip)
  3336. (setq str (buffer-substring-no-properties
  3337. (point-at-bol)
  3338. (if hdl-only (point-at-eol) end)))
  3339. (mapc (lambda (wr) (when (string-match wr str)
  3340. (goto-char (1- end))
  3341. (throw :skip t)))
  3342. regexps-)
  3343. (mapc (lambda (wr) (unless (string-match wr str)
  3344. (goto-char (1- end))
  3345. (throw :skip t)))
  3346. (if todo-only
  3347. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3348. regexps+)
  3349. regexps+))
  3350. (goto-char beg)
  3351. (setq marker (org-agenda-new-marker (point))
  3352. category (org-get-category)
  3353. tags (org-get-tags-at (point))
  3354. txt (org-format-agenda-item
  3355. ""
  3356. (buffer-substring-no-properties
  3357. beg1 (point-at-eol))
  3358. category tags))
  3359. (org-add-props txt props
  3360. 'org-marker marker 'org-hd-marker marker
  3361. 'org-todo-regexp org-todo-regexp
  3362. 'org-complex-heading-regexp org-complex-heading-regexp
  3363. 'priority 1000 'org-category category
  3364. 'type "search")
  3365. (push txt ee)
  3366. (goto-char (1- end))))))))))
  3367. (setq rtn (nreverse ee))
  3368. (setq rtnall (append rtnall rtn)))
  3369. (if org-agenda-overriding-header
  3370. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3371. nil 'face 'org-agenda-structure) "\n")
  3372. (insert "Search words: ")
  3373. (add-text-properties (point-min) (1- (point))
  3374. (list 'face 'org-agenda-structure))
  3375. (setq pos (point))
  3376. (insert string "\n")
  3377. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3378. (setq pos (point))
  3379. (unless org-agenda-multi
  3380. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3381. (add-text-properties pos (1- (point))
  3382. (list 'face 'org-agenda-structure))))
  3383. (org-agenda-mark-header-line (point-min))
  3384. (when rtnall
  3385. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3386. (goto-char (point-min))
  3387. (or org-agenda-multi (org-fit-agenda-window))
  3388. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3389. (org-finalize-agenda)
  3390. (setq buffer-read-only t)))
  3391. ;;; Agenda TODO list
  3392. (defvar org-select-this-todo-keyword nil)
  3393. (defvar org-last-arg nil)
  3394. ;;;###autoload
  3395. (defun org-todo-list (arg)
  3396. "Show all (not done) TODO entries from all agenda file in a single list.
  3397. The prefix arg can be used to select a specific TODO keyword and limit
  3398. the list to these. When using \\[universal-argument], you will be prompted
  3399. for a keyword. A numeric prefix directly selects the Nth keyword in
  3400. `org-todo-keywords-1'."
  3401. (interactive "P")
  3402. (org-compile-prefix-format 'todo)
  3403. (org-set-sorting-strategy 'todo)
  3404. (org-prepare-agenda "TODO")
  3405. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3406. (let* ((today (time-to-days (current-time)))
  3407. (date (calendar-gregorian-from-absolute today))
  3408. (kwds org-todo-keywords-for-agenda)
  3409. (completion-ignore-case t)
  3410. (org-select-this-todo-keyword
  3411. (if (stringp arg) arg
  3412. (and arg (integerp arg) (> arg 0)
  3413. (nth (1- arg) kwds))))
  3414. rtn rtnall files file pos)
  3415. (when (equal arg '(4))
  3416. (setq org-select-this-todo-keyword
  3417. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3418. (mapcar 'list kwds) nil nil)))
  3419. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3420. (org-set-local 'org-last-arg arg)
  3421. (setq org-agenda-redo-command
  3422. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3423. (setq files (org-agenda-files nil 'ifmode)
  3424. rtnall nil)
  3425. (while (setq file (pop files))
  3426. (catch 'nextfile
  3427. (org-check-agenda-file file)
  3428. (setq rtn (org-agenda-get-day-entries file date :todo))
  3429. (setq rtnall (append rtnall rtn))))
  3430. (if org-agenda-overriding-header
  3431. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3432. nil 'face 'org-agenda-structure) "\n")
  3433. (insert "Global list of TODO items of type: ")
  3434. (add-text-properties (point-min) (1- (point))
  3435. (list 'face 'org-agenda-structure
  3436. 'short-heading
  3437. (concat "ToDo: "
  3438. (or org-select-this-todo-keyword "ALL"))))
  3439. (org-agenda-mark-header-line (point-min))
  3440. (setq pos (point))
  3441. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3442. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3443. (setq pos (point))
  3444. (unless org-agenda-multi
  3445. (insert "Available with `N r': (0)ALL")
  3446. (let ((n 0) s)
  3447. (mapc (lambda (x)
  3448. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3449. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3450. (insert "\n "))
  3451. (insert " " s))
  3452. kwds))
  3453. (insert "\n"))
  3454. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3455. (org-agenda-mark-header-line (point-min))
  3456. (when rtnall
  3457. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3458. (goto-char (point-min))
  3459. (or org-agenda-multi (org-fit-agenda-window))
  3460. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3461. (org-finalize-agenda)
  3462. (setq buffer-read-only t)))
  3463. ;;; Agenda tags match
  3464. ;;;###autoload
  3465. (defun org-tags-view (&optional todo-only match)
  3466. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3467. The prefix arg TODO-ONLY limits the search to TODO entries."
  3468. (interactive "P")
  3469. (org-compile-prefix-format 'tags)
  3470. (org-set-sorting-strategy 'tags)
  3471. (let* ((org-tags-match-list-sublevels
  3472. org-tags-match-list-sublevels)
  3473. (completion-ignore-case t)
  3474. rtn rtnall files file pos matcher
  3475. buffer)
  3476. (when (and (stringp match) (not (string-match "\\S-" match)))
  3477. (setq match nil))
  3478. (setq matcher (org-make-tags-matcher match)
  3479. match (car matcher) matcher (cdr matcher))
  3480. (org-prepare-agenda (concat "TAGS " match))
  3481. (setq org-agenda-query-string match)
  3482. (setq org-agenda-redo-command
  3483. (list 'org-tags-view (list 'quote todo-only)
  3484. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3485. (setq files (org-agenda-files nil 'ifmode)
  3486. rtnall nil)
  3487. (while (setq file (pop files))
  3488. (catch 'nextfile
  3489. (org-check-agenda-file file)
  3490. (setq buffer (if (file-exists-p file)
  3491. (org-get-agenda-file-buffer file)
  3492. (error "No such file %s" file)))
  3493. (if (not buffer)
  3494. ;; If file does not exist, error message to agenda
  3495. (setq rtn (list
  3496. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3497. rtnall (append rtnall rtn))
  3498. (with-current-buffer buffer
  3499. (unless (org-mode-p)
  3500. (error "Agenda file %s is not in `org-mode'" file))
  3501. (save-excursion
  3502. (save-restriction
  3503. (if org-agenda-restrict
  3504. (narrow-to-region org-agenda-restrict-begin
  3505. org-agenda-restrict-end)
  3506. (widen))
  3507. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3508. (setq rtnall (append rtnall rtn))))))))
  3509. (if org-agenda-overriding-header
  3510. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3511. nil 'face 'org-agenda-structure) "\n")
  3512. (insert "Headlines with TAGS match: ")
  3513. (add-text-properties (point-min) (1- (point))
  3514. (list 'face 'org-agenda-structure
  3515. 'short-heading
  3516. (concat "Match: " match)))
  3517. (setq pos (point))
  3518. (insert match "\n")
  3519. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3520. (setq pos (point))
  3521. (unless org-agenda-multi
  3522. (insert "Press `C-u r' to search again with new search string\n"))
  3523. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3524. (org-agenda-mark-header-line (point-min))
  3525. (when rtnall
  3526. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3527. (goto-char (point-min))
  3528. (or org-agenda-multi (org-fit-agenda-window))
  3529. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3530. (org-finalize-agenda)
  3531. (setq buffer-read-only t)))
  3532. ;;; Agenda Finding stuck projects
  3533. (defvar org-agenda-skip-regexp nil
  3534. "Regular expression used in skipping subtrees for the agenda.
  3535. This is basically a temporary global variable that can be set and then
  3536. used by user-defined selections using `org-agenda-skip-function'.")
  3537. (defvar org-agenda-overriding-header nil
  3538. "When this is set during todo and tags searches, will replace header.
  3539. This variable should not be set directly, but custom commands can bind it
  3540. in the options section.")
  3541. (defun org-agenda-skip-entry-when-regexp-matches ()
  3542. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3543. If yes, it returns the end position of this entry, causing agenda commands
  3544. to skip the entry but continuing the search in the subtree. This is a
  3545. function that can be put into `org-agenda-skip-function' for the duration
  3546. of a command."
  3547. (let ((end (save-excursion (org-end-of-subtree t)))
  3548. skip)
  3549. (save-excursion
  3550. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3551. (and skip end)))
  3552. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3553. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3554. If yes, it returns the end position of this tree, causing agenda commands
  3555. to skip this subtree. This is a function that can be put into
  3556. `org-agenda-skip-function' for the duration of a command."
  3557. (let ((end (save-excursion (org-end-of-subtree t)))
  3558. skip)
  3559. (save-excursion
  3560. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3561. (and skip end)))
  3562. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3563. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3564. If yes, it returns the end position of the current entry (NOT the tree),
  3565. causing agenda commands to skip the entry but continuing the search in
  3566. the subtree. This is a function that can be put into
  3567. `org-agenda-skip-function' for the duration of a command. An important
  3568. use of this function is for the stuck project list."
  3569. (let ((end (save-excursion (org-end-of-subtree t)))
  3570. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3571. skip)
  3572. (save-excursion
  3573. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3574. (and skip entry-end)))
  3575. (defun org-agenda-skip-entry-if (&rest conditions)
  3576. "Skip entry if any of CONDITIONS is true.
  3577. See `org-agenda-skip-if' for details."
  3578. (org-agenda-skip-if nil conditions))
  3579. (defun org-agenda-skip-subtree-if (&rest conditions)
  3580. "Skip entry if any of CONDITIONS is true.
  3581. See `org-agenda-skip-if' for details."
  3582. (org-agenda-skip-if t conditions))
  3583. (defun org-agenda-skip-if (subtree conditions)
  3584. "Checks current entity for CONDITIONS.
  3585. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3586. the entry, i.e. the text before the next heading is checked.
  3587. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3588. from different tests. Valid conditions are:
  3589. scheduled Check if there is a scheduled cookie
  3590. notscheduled Check if there is no scheduled cookie
  3591. deadline Check if there is a deadline
  3592. notdeadline Check if there is no deadline
  3593. timestamp Check if there is a timestamp (also deadline or scheduled)
  3594. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3595. regexp Check if regexp matches
  3596. notregexp Check if regexp does not match.
  3597. todo Check if TODO keyword matches
  3598. nottodo Check if TODO keyword does not match
  3599. The regexp is taken from the conditions list, it must come right after
  3600. the `regexp' or `notregexp' element.
  3601. `todo' and `nottodo' accept as an argument a list of todo
  3602. keywords, which may include \"*\" to match any todo keyword.
  3603. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3604. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3605. Instead of a list a keyword class may be given
  3606. (org-agenda-skip-entry-if 'nottodo 'done)
  3607. would skip entries that haven't been marked with any of \"DONE\"
  3608. keywords. Possible classes are: `todo', `done', `any'.
  3609. If any of these conditions is met, this function returns the end point of
  3610. the entity, causing the search to continue from there. This is a function
  3611. that can be put into `org-agenda-skip-function' for the duration of a command."
  3612. (let (beg end m)
  3613. (org-back-to-heading t)
  3614. (setq beg (point)
  3615. end (if subtree
  3616. (progn (org-end-of-subtree t) (point))
  3617. (progn (outline-next-heading) (1- (point)))))
  3618. (goto-char beg)
  3619. (and
  3620. (or
  3621. (and (memq 'scheduled conditions)
  3622. (re-search-forward org-scheduled-time-regexp end t))
  3623. (and (memq 'notscheduled conditions)
  3624. (not (re-search-forward org-scheduled-time-regexp end t)))
  3625. (and (memq 'deadline conditions)
  3626. (re-search-forward org-deadline-time-regexp end t))
  3627. (and (memq 'notdeadline conditions)
  3628. (not (re-search-forward org-deadline-time-regexp end t)))
  3629. (and (memq 'timestamp conditions)
  3630. (re-search-forward org-ts-regexp end t))
  3631. (and (memq 'nottimestamp conditions)
  3632. (not (re-search-forward org-ts-regexp end t)))
  3633. (and (setq m (memq 'regexp conditions))
  3634. (stringp (nth 1 m))
  3635. (re-search-forward (nth 1 m) end t))
  3636. (and (setq m (memq 'notregexp conditions))
  3637. (stringp (nth 1 m))
  3638. (not (re-search-forward (nth 1 m) end t)))
  3639. (and (or
  3640. (setq m (memq 'todo conditions))
  3641. (setq m (memq 'nottodo conditions)))
  3642. (org-agenda-skip-if-todo m end)))
  3643. end)))
  3644. (defun org-agenda-skip-if-todo (args end)
  3645. "Helper function for `org-agenda-skip-if', do not use it directly.
  3646. ARGS is a list with first element either `todo' or `nottodo'.
  3647. The remainder is either a list of TODO keywords, or a state symbol
  3648. `todo' or `done' or `any'."
  3649. (let ((kw (car args))
  3650. (arg (cadr args))
  3651. todo-wds todo-re)
  3652. (setq todo-wds
  3653. (org-uniquify
  3654. (cond
  3655. ((listp arg) ;; list of keywords
  3656. (if (member "*" arg)
  3657. (mapcar 'substring-no-properties org-todo-keywords-1)
  3658. arg))
  3659. ((symbolp arg) ;; keyword class name
  3660. (cond
  3661. ((eq arg 'todo)
  3662. (org-delete-all org-done-keywords
  3663. (mapcar 'substring-no-properties
  3664. org-todo-keywords-1)))
  3665. ((eq arg 'done) org-done-keywords)
  3666. ((eq arg 'any)
  3667. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3668. (setq todo-re
  3669. (concat "^\\*+[ \t]+\\<\\("
  3670. (mapconcat 'identity todo-wds "\\|")
  3671. "\\)\\>"))
  3672. (if (eq kw 'todo)
  3673. (re-search-forward todo-re end t)
  3674. (not (re-search-forward todo-re end t)))))
  3675. ;;;###autoload
  3676. (defun org-agenda-list-stuck-projects (&rest ignore)
  3677. "Create agenda view for projects that are stuck.
  3678. Stuck projects are project that have no next actions. For the definitions
  3679. of what a project is and how to check if it stuck, customize the variable
  3680. `org-stuck-projects'.
  3681. MATCH is being ignored."
  3682. (interactive)
  3683. (let* ((org-agenda-skip-function
  3684. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3685. ;; We could have used org-agenda-skip-if here.
  3686. (org-agenda-overriding-header
  3687. (or org-agenda-overriding-header "List of stuck projects: "))
  3688. (matcher (nth 0 org-stuck-projects))
  3689. (todo (nth 1 org-stuck-projects))
  3690. (todo-wds (if (member "*" todo)
  3691. (progn
  3692. (org-prepare-agenda-buffers (org-agenda-files
  3693. nil 'ifmode))
  3694. (org-delete-all
  3695. org-done-keywords-for-agenda
  3696. (copy-sequence org-todo-keywords-for-agenda)))
  3697. todo))
  3698. (todo-re (concat "^\\*+[ \t]+\\("
  3699. (mapconcat 'identity todo-wds "\\|")
  3700. "\\)\\>"))
  3701. (tags (nth 2 org-stuck-projects))
  3702. (tags-re (if (member "*" tags)
  3703. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3704. (if tags
  3705. (concat "^\\*+ .*:\\("
  3706. (mapconcat 'identity tags "\\|")
  3707. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3708. (gen-re (nth 3 org-stuck-projects))
  3709. (re-list
  3710. (delq nil
  3711. (list
  3712. (if todo todo-re)
  3713. (if tags tags-re)
  3714. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3715. gen-re)))))
  3716. (setq org-agenda-skip-regexp
  3717. (if re-list
  3718. (mapconcat 'identity re-list "\\|")
  3719. (error "No information how to identify unstuck projects")))
  3720. (org-tags-view nil matcher)
  3721. (with-current-buffer org-agenda-buffer-name
  3722. (setq org-agenda-redo-command
  3723. '(org-agenda-list-stuck-projects
  3724. (or current-prefix-arg org-last-arg))))))
  3725. ;;; Diary integration
  3726. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3727. (defvar list-diary-entries-hook)
  3728. (defun org-get-entries-from-diary (date)
  3729. "Get the (Emacs Calendar) diary entries for DATE."
  3730. (require 'diary-lib)
  3731. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3732. (diary-display-hook '(fancy-diary-display))
  3733. (diary-display-function 'fancy-diary-display)
  3734. (pop-up-frames nil)
  3735. (list-diary-entries-hook
  3736. (cons 'org-diary-default-entry list-diary-entries-hook))
  3737. (diary-file-name-prefix-function nil) ; turn this feature off
  3738. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3739. entries
  3740. (org-disable-agenda-to-diary t))
  3741. (save-excursion
  3742. (save-window-excursion
  3743. (funcall (if (fboundp 'diary-list-entries)
  3744. 'diary-list-entries 'list-diary-entries)
  3745. date 1)))
  3746. (if (not (get-buffer diary-fancy-buffer))
  3747. (setq entries nil)
  3748. (with-current-buffer diary-fancy-buffer
  3749. (setq buffer-read-only nil)
  3750. (if (zerop (buffer-size))
  3751. ;; No entries
  3752. (setq entries nil)
  3753. ;; Omit the date and other unnecessary stuff
  3754. (org-agenda-cleanup-fancy-diary)
  3755. ;; Add prefix to each line and extend the text properties
  3756. (if (zerop (buffer-size))
  3757. (setq entries nil)
  3758. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3759. (set-buffer-modified-p nil)
  3760. (kill-buffer diary-fancy-buffer)))
  3761. (when entries
  3762. (setq entries (org-split-string entries "\n"))
  3763. (setq entries
  3764. (mapcar
  3765. (lambda (x)
  3766. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3767. ;; Extend the text properties to the beginning of the line
  3768. (org-add-props x (text-properties-at (1- (length x)) x)
  3769. 'type "diary" 'date date 'face 'org-agenda-diary))
  3770. entries)))))
  3771. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3772. "Hook run when the fancy diary buffer is cleaned up.")
  3773. (defun org-agenda-cleanup-fancy-diary ()
  3774. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3775. This gets rid of the date, the underline under the date, and
  3776. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3777. date. It also removes lines that contain only whitespace."
  3778. (goto-char (point-min))
  3779. (if (looking-at ".*?:[ \t]*")
  3780. (progn
  3781. (replace-match "")
  3782. (re-search-forward "\n=+$" nil t)
  3783. (replace-match "")
  3784. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3785. (re-search-forward "\n=+$" nil t)
  3786. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3787. (goto-char (point-min))
  3788. (while (re-search-forward "^ +\n" nil t)
  3789. (replace-match ""))
  3790. (goto-char (point-min))
  3791. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3792. (replace-match ""))
  3793. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3794. ;; Make sure entries from the diary have the right text properties.
  3795. (eval-after-load "diary-lib"
  3796. '(if (boundp 'diary-modify-entry-list-string-function)
  3797. ;; We can rely on the hook, nothing to do
  3798. nil
  3799. ;; Hook not available, must use advice to make this work
  3800. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3801. "Make the position visible."
  3802. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3803. (stringp string)
  3804. buffer-file-name)
  3805. (setq string (org-modify-diary-entry-string string))))))
  3806. (defun org-modify-diary-entry-string (string)
  3807. "Add text properties to string, allowing org-mode to act on it."
  3808. (org-add-props string nil
  3809. 'mouse-face 'highlight
  3810. 'help-echo (if buffer-file-name
  3811. (format "mouse-2 or RET jump to diary file %s"
  3812. (abbreviate-file-name buffer-file-name))
  3813. "")
  3814. 'org-agenda-diary-link t
  3815. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3816. (defun org-diary-default-entry ()
  3817. "Add a dummy entry to the diary.
  3818. Needed to avoid empty dates which mess up holiday display."
  3819. ;; Catch the error if dealing with the new add-to-diary-alist
  3820. (when org-disable-agenda-to-diary
  3821. (condition-case nil
  3822. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3823. (error
  3824. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3825. (defun org-add-to-diary-list (&rest args)
  3826. (if (fboundp 'diary-add-to-list)
  3827. (apply 'diary-add-to-list args)
  3828. (apply 'add-to-diary-list args)))
  3829. (defvar org-diary-last-run-time nil)
  3830. ;;;###autoload
  3831. (defun org-diary (&rest args)
  3832. "Return diary information from org-files.
  3833. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3834. It accesses org files and extracts information from those files to be
  3835. listed in the diary. The function accepts arguments specifying what
  3836. items should be listed. For a list of arguments allowed here, see the
  3837. variable `org-agenda-entry-types'.
  3838. The call in the diary file should look like this:
  3839. &%%(org-diary) ~/path/to/some/orgfile.org
  3840. Use a separate line for each org file to check. Or, if you omit the file name,
  3841. all files listed in `org-agenda-files' will be checked automatically:
  3842. &%%(org-diary)
  3843. If you don't give any arguments (as in the example above), the default
  3844. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3845. So the example above may also be written as
  3846. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3847. The function expects the lisp variables `entry' and `date' to be provided
  3848. by the caller, because this is how the calendar works. Don't use this
  3849. function from a program - use `org-agenda-get-day-entries' instead."
  3850. (when (> (- (org-float-time)
  3851. org-agenda-last-marker-time)
  3852. 5)
  3853. (org-agenda-reset-markers))
  3854. (org-compile-prefix-format 'agenda)
  3855. (org-set-sorting-strategy 'agenda)
  3856. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3857. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3858. (list entry)
  3859. (org-agenda-files t)))
  3860. (time (org-float-time))
  3861. file rtn results)
  3862. (when (or (not org-diary-last-run-time)
  3863. (> (- time
  3864. org-diary-last-run-time)
  3865. 3))
  3866. (org-prepare-agenda-buffers files))
  3867. (setq org-diary-last-run-time time)
  3868. ;; If this is called during org-agenda, don't return any entries to
  3869. ;; the calendar. Org Agenda will list these entries itself.
  3870. (if org-disable-agenda-to-diary (setq files nil))
  3871. (while (setq file (pop files))
  3872. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3873. (setq results (append results rtn)))
  3874. (if results
  3875. (concat (org-finalize-agenda-entries results) "\n"))))
  3876. ;;; Agenda entry finders
  3877. (defun org-agenda-get-day-entries (file date &rest args)
  3878. "Does the work for `org-diary' and `org-agenda'.
  3879. FILE is the path to a file to be checked for entries. DATE is date like
  3880. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3881. which kind of entries should be extracted. For details about these, see
  3882. the documentation of `org-diary'."
  3883. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3884. (let* ((org-startup-folded nil)
  3885. (org-startup-align-all-tables nil)
  3886. (buffer (if (file-exists-p file)
  3887. (org-get-agenda-file-buffer file)
  3888. (error "No such file %s" file)))
  3889. arg results rtn deadline-results)
  3890. (if (not buffer)
  3891. ;; If file does not exist, make sure an error message ends up in diary
  3892. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3893. (with-current-buffer buffer
  3894. (unless (org-mode-p)
  3895. (error "Agenda file %s is not in `org-mode'" file))
  3896. (let ((case-fold-search nil))
  3897. (save-excursion
  3898. (save-restriction
  3899. (if org-agenda-restrict
  3900. (narrow-to-region org-agenda-restrict-begin
  3901. org-agenda-restrict-end)
  3902. (widen))
  3903. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3904. (while (setq arg (pop args))
  3905. (cond
  3906. ((and (eq arg :todo)
  3907. (equal date (calendar-current-date)))
  3908. (setq rtn (org-agenda-get-todos))
  3909. (setq results (append results rtn)))
  3910. ((eq arg :timestamp)
  3911. (setq rtn (org-agenda-get-blocks))
  3912. (setq results (append results rtn))
  3913. (setq rtn (org-agenda-get-timestamps))
  3914. (setq results (append results rtn)))
  3915. ((eq arg :sexp)
  3916. (setq rtn (org-agenda-get-sexps))
  3917. (setq results (append results rtn)))
  3918. ((eq arg :scheduled)
  3919. (setq rtn (org-agenda-get-scheduled deadline-results))
  3920. (setq results (append results rtn)))
  3921. ((eq arg :closed)
  3922. (setq rtn (org-agenda-get-progress))
  3923. (setq results (append results rtn)))
  3924. ((eq arg :deadline)
  3925. (setq rtn (org-agenda-get-deadlines))
  3926. (setq deadline-results (copy-sequence rtn))
  3927. (setq results (append results rtn))))))))
  3928. results))))
  3929. (defun org-agenda-get-todos ()
  3930. "Return the TODO information for agenda display."
  3931. (let* ((props (list 'face nil
  3932. 'done-face 'org-agenda-done
  3933. 'org-not-done-regexp org-not-done-regexp
  3934. 'org-todo-regexp org-todo-regexp
  3935. 'org-complex-heading-regexp org-complex-heading-regexp
  3936. 'mouse-face 'highlight
  3937. 'help-echo
  3938. (format "mouse-2 or RET jump to org file %s"
  3939. (abbreviate-file-name buffer-file-name))))
  3940. (regexp (concat "^\\*+[ \t]+\\("
  3941. (if org-select-this-todo-keyword
  3942. (if (equal org-select-this-todo-keyword "*")
  3943. org-todo-regexp
  3944. (concat "\\<\\("
  3945. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3946. "\\)\\>"))
  3947. org-not-done-regexp)
  3948. "[^\n\r]*\\)"))
  3949. marker priority category tags todo-state
  3950. ee txt beg end)
  3951. (goto-char (point-min))
  3952. (while (re-search-forward regexp nil t)
  3953. (catch :skip
  3954. (save-match-data
  3955. (beginning-of-line)
  3956. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3957. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3958. (goto-char (1+ beg))
  3959. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3960. (throw :skip nil)))
  3961. (goto-char beg)
  3962. (org-agenda-skip)
  3963. (goto-char (match-beginning 1))
  3964. (setq marker (org-agenda-new-marker (match-beginning 0))
  3965. category (org-get-category)
  3966. txt (match-string 1)
  3967. tags (org-get-tags-at (point))
  3968. txt (org-format-agenda-item "" txt category tags)
  3969. priority (1+ (org-get-priority txt))
  3970. todo-state (org-get-todo-state))
  3971. (org-add-props txt props
  3972. 'org-marker marker 'org-hd-marker marker
  3973. 'priority priority 'org-category category
  3974. 'type "todo" 'todo-state todo-state)
  3975. (push txt ee)
  3976. (if org-agenda-todo-list-sublevels
  3977. (goto-char (match-end 1))
  3978. (org-end-of-subtree 'invisible))))
  3979. (nreverse ee)))
  3980. ;;;###autoload
  3981. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  3982. (&optional end)
  3983. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  3984. (when (or org-agenda-todo-ignore-with-date
  3985. org-agenda-todo-ignore-scheduled
  3986. org-agenda-todo-ignore-deadlines)
  3987. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3988. (save-excursion
  3989. (or (and org-agenda-todo-ignore-with-date
  3990. (re-search-forward org-ts-regexp end t))
  3991. (and org-agenda-todo-ignore-scheduled
  3992. (re-search-forward org-scheduled-time-regexp end t)
  3993. (cond
  3994. ((eq org-agenda-todo-ignore-scheduled 'future)
  3995. (> (org-days-to-time (match-string 1)) 0))
  3996. ((eq org-agenda-todo-ignore-scheduled 'past)
  3997. (<= (org-days-to-time (match-string 1)) 0))
  3998. (t)))
  3999. (and org-agenda-todo-ignore-deadlines
  4000. (re-search-forward org-deadline-time-regexp end t)
  4001. (cond
  4002. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4003. ((eq org-agenda-todo-ignore-deadlines 'far)
  4004. (not (org-deadline-close (match-string 1))))
  4005. ((eq org-agenda-todo-ignore-deadlines 'future)
  4006. (> (org-days-to-time (match-string 1)) 0))
  4007. ((eq org-agenda-todo-ignore-deadlines 'past)
  4008. (<= (org-days-to-time (match-string 1)) 0))
  4009. (t (org-deadline-close (match-string 1)))))))))
  4010. (defconst org-agenda-no-heading-message
  4011. "No heading for this item in buffer or region.")
  4012. (defun org-agenda-get-timestamps ()
  4013. "Return the date stamp information for agenda display."
  4014. (let* ((props (list 'face nil
  4015. 'org-not-done-regexp org-not-done-regexp
  4016. 'org-todo-regexp org-todo-regexp
  4017. 'org-complex-heading-regexp org-complex-heading-regexp
  4018. 'mouse-face 'highlight
  4019. 'help-echo
  4020. (format "mouse-2 or RET jump to org file %s"
  4021. (abbreviate-file-name buffer-file-name))))
  4022. (d1 (calendar-absolute-from-gregorian date))
  4023. (remove-re
  4024. (concat
  4025. (regexp-quote
  4026. (format-time-string
  4027. "<%Y-%m-%d"
  4028. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4029. ".*?>"))
  4030. (regexp
  4031. (concat
  4032. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4033. (regexp-quote
  4034. (substring
  4035. (format-time-string
  4036. (car org-time-stamp-formats)
  4037. (apply 'encode-time ; DATE bound by calendar
  4038. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4039. 1 11))
  4040. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4041. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4042. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4043. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4044. todo-state end-of-match)
  4045. (goto-char (point-min))
  4046. (while (setq end-of-match (re-search-forward regexp nil t))
  4047. (setq b0 (match-beginning 0)
  4048. b3 (match-beginning 3) e3 (match-end 3))
  4049. (catch :skip
  4050. (and (org-at-date-range-p) (throw :skip nil))
  4051. (org-agenda-skip)
  4052. (if (and (match-end 1)
  4053. (not (= d1 (org-time-string-to-absolute
  4054. (match-string 1) d1 nil
  4055. org-agenda-repeating-timestamp-show-all))))
  4056. (throw :skip nil))
  4057. (if (and e3
  4058. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4059. (throw :skip nil))
  4060. (setq tmp (buffer-substring (max (point-min)
  4061. (- b0 org-ds-keyword-length))
  4062. b0)
  4063. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4064. inactivep (= (char-after b0) ?\[)
  4065. deadlinep (string-match org-deadline-regexp tmp)
  4066. scheduledp (string-match org-scheduled-regexp tmp)
  4067. closedp (and org-agenda-include-inactive-timestamps
  4068. (string-match org-closed-string tmp))
  4069. clockp (and org-agenda-include-inactive-timestamps
  4070. (or (string-match org-clock-string tmp)
  4071. (string-match "]-+\\'" tmp)))
  4072. todo-state (ignore-errors (org-get-todo-state))
  4073. donep (member todo-state org-done-keywords))
  4074. (if (or scheduledp deadlinep closedp clockp
  4075. (and donep org-agenda-skip-timestamp-if-done))
  4076. (throw :skip t))
  4077. (if (string-match ">" timestr)
  4078. ;; substring should only run to end of time stamp
  4079. (setq timestr (substring timestr 0 (match-end 0))))
  4080. (setq marker (org-agenda-new-marker b0)
  4081. category (org-get-category b0))
  4082. (save-excursion
  4083. (if (not (re-search-backward "^\\*+ " nil t))
  4084. (setq txt org-agenda-no-heading-message)
  4085. (goto-char (match-beginning 0))
  4086. (setq hdmarker (org-agenda-new-marker)
  4087. tags (org-get-tags-at))
  4088. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4089. (setq head (match-string 1))
  4090. (setq txt (org-format-agenda-item
  4091. (if inactivep org-agenda-inactive-leader nil)
  4092. head category tags timestr nil
  4093. remove-re)))
  4094. (setq priority (org-get-priority txt))
  4095. (org-add-props txt props
  4096. 'org-marker marker 'org-hd-marker hdmarker)
  4097. (org-add-props txt nil 'priority priority
  4098. 'org-category category 'date date
  4099. 'todo-state todo-state
  4100. 'type "timestamp")
  4101. (push txt ee))
  4102. (if org-agenda-skip-additional-timestamps-same-entry
  4103. (outline-next-heading)
  4104. (goto-char end-of-match))))
  4105. (nreverse ee)))
  4106. (defun org-agenda-get-sexps ()
  4107. "Return the sexp information for agenda display."
  4108. (require 'diary-lib)
  4109. (let* ((props (list 'face nil
  4110. 'mouse-face 'highlight
  4111. 'help-echo
  4112. (format "mouse-2 or RET jump to org file %s"
  4113. (abbreviate-file-name buffer-file-name))))
  4114. (regexp "^&?%%(")
  4115. marker category ee txt tags entry result beg b sexp sexp-entry
  4116. todo-state)
  4117. (goto-char (point-min))
  4118. (while (re-search-forward regexp nil t)
  4119. (catch :skip
  4120. (org-agenda-skip)
  4121. (setq beg (match-beginning 0))
  4122. (goto-char (1- (match-end 0)))
  4123. (setq b (point))
  4124. (forward-sexp 1)
  4125. (setq sexp (buffer-substring b (point)))
  4126. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4127. (org-trim (match-string 1))
  4128. ""))
  4129. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4130. (when result
  4131. (setq marker (org-agenda-new-marker beg)
  4132. category (org-get-category beg)
  4133. todo-state (org-get-todo-state))
  4134. (if (string-match "\\S-" result)
  4135. (setq txt result)
  4136. (setq txt "SEXP entry returned empty string"))
  4137. (setq txt (org-format-agenda-item
  4138. "" txt category tags 'time))
  4139. (org-add-props txt props 'org-marker marker)
  4140. (org-add-props txt nil
  4141. 'org-category category 'date date 'todo-state todo-state
  4142. 'type "sexp")
  4143. (push txt ee))))
  4144. (nreverse ee)))
  4145. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4146. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4147. The order of the first 2 times 3 arguments depends on the variable
  4148. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4149. So for American calendars, give this as MONTH DAY YEAR, for European as
  4150. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4151. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4152. is any number of ISO weeks in the block period for which the item should
  4153. be skipped."
  4154. (let* ((date1 (calendar-absolute-from-gregorian
  4155. (org-order-calendar-date-args m1 d1 y1)))
  4156. (date2 (calendar-absolute-from-gregorian
  4157. (org-order-calendar-date-args m2 d2 y2)))
  4158. (d (calendar-absolute-from-gregorian date)))
  4159. (and
  4160. (<= date1 d)
  4161. (<= d date2)
  4162. (= (calendar-day-of-week date) dayname)
  4163. (or (not skip-weeks)
  4164. (progn
  4165. (require 'cal-iso)
  4166. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4167. entry)))
  4168. (defalias 'org-get-closed 'org-agenda-get-progress)
  4169. (defun org-agenda-get-progress ()
  4170. "Return the logged TODO entries for agenda display."
  4171. (let* ((props (list 'mouse-face 'highlight
  4172. 'org-not-done-regexp org-not-done-regexp
  4173. 'org-todo-regexp org-todo-regexp
  4174. 'org-complex-heading-regexp org-complex-heading-regexp
  4175. 'help-echo
  4176. (format "mouse-2 or RET jump to org file %s"
  4177. (abbreviate-file-name buffer-file-name))))
  4178. (items (if (consp org-agenda-show-log)
  4179. org-agenda-show-log
  4180. org-agenda-log-mode-items))
  4181. (parts
  4182. (delq nil
  4183. (list
  4184. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4185. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4186. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4187. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4188. (error "`org-agenda-log-mode-items' is empty")))
  4189. (regexp (concat
  4190. "\\(" parts-re "\\)"
  4191. " *\\["
  4192. (regexp-quote
  4193. (substring
  4194. (format-time-string
  4195. (car org-time-stamp-formats)
  4196. (apply 'encode-time ; DATE bound by calendar
  4197. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4198. 1 11))))
  4199. (org-agenda-search-headline-for-time nil)
  4200. marker hdmarker priority category tags closedp statep clockp state
  4201. ee txt extra timestr rest clocked)
  4202. (goto-char (point-min))
  4203. (while (re-search-forward regexp nil t)
  4204. (catch :skip
  4205. (org-agenda-skip)
  4206. (setq marker (org-agenda-new-marker (match-beginning 0))
  4207. closedp (equal (match-string 1) org-closed-string)
  4208. statep (equal (string-to-char (match-string 1)) ?-)
  4209. clockp (not (or closedp statep))
  4210. state (and statep (match-string 2))
  4211. category (org-get-category (match-beginning 0))
  4212. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4213. )
  4214. (when (string-match "\\]" timestr)
  4215. ;; substring should only run to end of time stamp
  4216. (setq rest (substring timestr (match-end 0))
  4217. timestr (substring timestr 0 (match-end 0)))
  4218. (if (and (not closedp) (not statep)
  4219. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4220. (progn (setq timestr (concat (substring timestr 0 -1)
  4221. "-" (match-string 1 rest) "]"))
  4222. (setq clocked (match-string 2 rest)))
  4223. (setq clocked "-")))
  4224. (save-excursion
  4225. (setq extra nil)
  4226. (cond
  4227. ((not org-agenda-log-mode-add-notes))
  4228. (statep
  4229. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4230. (setq extra (match-string 1))))
  4231. (clockp
  4232. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4233. (setq extra (match-string 1)))))
  4234. (if (not (re-search-backward "^\\*+ " nil t))
  4235. (setq txt org-agenda-no-heading-message)
  4236. (goto-char (match-beginning 0))
  4237. (setq hdmarker (org-agenda-new-marker)
  4238. tags (org-get-tags-at))
  4239. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4240. (setq txt (match-string 1))
  4241. (when extra
  4242. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4243. (setq txt (concat (substring txt 0 (match-beginning 1))
  4244. " - " extra " " (match-string 2 txt)))
  4245. (setq txt (concat txt " - " extra))))
  4246. (setq txt (org-format-agenda-item
  4247. (cond
  4248. (closedp "Closed: ")
  4249. (statep (concat "State: (" state ")"))
  4250. (t (concat "Clocked: (" clocked ")")))
  4251. txt category tags timestr)))
  4252. (setq priority 100000)
  4253. (org-add-props txt props
  4254. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4255. 'priority priority 'org-category category
  4256. 'type "closed" 'date date
  4257. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4258. (push txt ee))
  4259. (goto-char (point-at-eol))))
  4260. (nreverse ee)))
  4261. (defun org-agenda-get-deadlines ()
  4262. "Return the deadline information for agenda display."
  4263. (let* ((props (list 'mouse-face 'highlight
  4264. 'org-not-done-regexp org-not-done-regexp
  4265. 'org-todo-regexp org-todo-regexp
  4266. 'org-complex-heading-regexp org-complex-heading-regexp
  4267. 'help-echo
  4268. (format "mouse-2 or RET jump to org file %s"
  4269. (abbreviate-file-name buffer-file-name))))
  4270. (regexp org-deadline-time-regexp)
  4271. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4272. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4273. d2 diff dfrac wdays pos pos1 category tags
  4274. suppress-prewarning
  4275. ee txt head face s todo-state upcomingp donep timestr)
  4276. (goto-char (point-min))
  4277. (while (re-search-forward regexp nil t)
  4278. (setq suppress-prewarning nil)
  4279. (catch :skip
  4280. (org-agenda-skip)
  4281. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4282. (save-match-data
  4283. (string-match org-scheduled-time-regexp
  4284. (buffer-substring (point-at-bol)
  4285. (point-at-eol)))))
  4286. (setq suppress-prewarning
  4287. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4288. org-agenda-skip-deadline-prewarning-if-scheduled
  4289. 0)))
  4290. (setq s (match-string 1)
  4291. txt nil
  4292. pos (1- (match-beginning 1))
  4293. d2 (org-time-string-to-absolute
  4294. (match-string 1) d1 'past
  4295. org-agenda-repeating-timestamp-show-all)
  4296. diff (- d2 d1)
  4297. wdays (if suppress-prewarning
  4298. (let ((org-deadline-warning-days suppress-prewarning))
  4299. (org-get-wdays s))
  4300. (org-get-wdays s))
  4301. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4302. upcomingp (and todayp (> diff 0)))
  4303. ;; When to show a deadline in the calendar:
  4304. ;; If the expiration is within wdays warning time.
  4305. ;; Past-due deadlines are only shown on the current date
  4306. (if (and (or (and (<= diff wdays)
  4307. (and todayp (not org-agenda-only-exact-dates)))
  4308. (= diff 0)))
  4309. (save-excursion
  4310. (setq todo-state (org-get-todo-state))
  4311. (setq donep (member todo-state org-done-keywords))
  4312. (if (and donep
  4313. (or org-agenda-skip-deadline-if-done
  4314. (not (= diff 0))))
  4315. (setq txt nil)
  4316. (setq category (org-get-category))
  4317. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4318. (setq txt org-agenda-no-heading-message)
  4319. (goto-char (match-end 0))
  4320. (setq pos1 (match-beginning 0))
  4321. (setq tags (org-get-tags-at pos1))
  4322. (setq head (buffer-substring-no-properties
  4323. (point)
  4324. (progn (skip-chars-forward "^\r\n")
  4325. (point))))
  4326. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4327. (setq timestr
  4328. (concat (substring s (match-beginning 1)) " "))
  4329. (setq timestr 'time))
  4330. (setq txt (org-format-agenda-item
  4331. (if (= diff 0)
  4332. (car org-agenda-deadline-leaders)
  4333. (if (functionp
  4334. (nth 1 org-agenda-deadline-leaders))
  4335. (funcall
  4336. (nth 1 org-agenda-deadline-leaders)
  4337. diff date)
  4338. (format (nth 1 org-agenda-deadline-leaders)
  4339. diff)))
  4340. head category tags
  4341. (if (not (= diff 0)) nil timestr)))))
  4342. (when txt
  4343. (setq face (org-agenda-deadline-face dfrac wdays))
  4344. (org-add-props txt props
  4345. 'org-marker (org-agenda-new-marker pos)
  4346. 'org-hd-marker (org-agenda-new-marker pos1)
  4347. 'priority (+ (- diff)
  4348. (org-get-priority txt))
  4349. 'org-category category
  4350. 'todo-state todo-state
  4351. 'type (if upcomingp "upcoming-deadline" "deadline")
  4352. 'date (if upcomingp date d2)
  4353. 'face (if donep 'org-agenda-done face)
  4354. 'undone-face face 'done-face 'org-agenda-done)
  4355. (push txt ee))))))
  4356. (nreverse ee)))
  4357. (defun org-agenda-deadline-face (fraction &optional wdays)
  4358. "Return the face to displaying a deadline item.
  4359. FRACTION is what fraction of the head-warning time has passed."
  4360. (if (equal wdays 0) (setq fraction 1.))
  4361. (let ((faces org-agenda-deadline-faces) f)
  4362. (catch 'exit
  4363. (while (setq f (pop faces))
  4364. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4365. (defun org-agenda-get-scheduled (&optional deadline-results)
  4366. "Return the scheduled information for agenda display."
  4367. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4368. 'org-todo-regexp org-todo-regexp
  4369. 'org-complex-heading-regexp org-complex-heading-regexp
  4370. 'done-face 'org-agenda-done
  4371. 'mouse-face 'highlight
  4372. 'help-echo
  4373. (format "mouse-2 or RET jump to org file %s"
  4374. (abbreviate-file-name buffer-file-name))))
  4375. (regexp org-scheduled-time-regexp)
  4376. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4377. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4378. mm
  4379. (deadline-position-alist
  4380. (mapcar (lambda (a) (and (setq mm (get-text-property
  4381. 0 'org-hd-marker a))
  4382. (cons (marker-position mm) a)))
  4383. deadline-results))
  4384. d2 diff pos pos1 category tags donep
  4385. ee txt head pastschedp todo-state face timestr s habitp)
  4386. (goto-char (point-min))
  4387. (while (re-search-forward regexp nil t)
  4388. (catch :skip
  4389. (org-agenda-skip)
  4390. (setq s (match-string 1)
  4391. txt nil
  4392. pos (1- (match-beginning 1))
  4393. d2 (org-time-string-to-absolute
  4394. (match-string 1) d1 'past
  4395. org-agenda-repeating-timestamp-show-all)
  4396. diff (- d2 d1))
  4397. (setq pastschedp (and todayp (< diff 0)))
  4398. ;; When to show a scheduled item in the calendar:
  4399. ;; If it is on or past the date.
  4400. (when (or (and (< diff 0)
  4401. (< (abs diff) org-scheduled-past-days)
  4402. (and todayp (not org-agenda-only-exact-dates)))
  4403. (= diff 0))
  4404. (save-excursion
  4405. (setq todo-state (org-get-todo-state))
  4406. (setq donep (member todo-state org-done-keywords))
  4407. (setq habitp (and (functionp 'org-is-habit-p)
  4408. (org-is-habit-p)))
  4409. (if (and donep
  4410. (or habitp org-agenda-skip-scheduled-if-done
  4411. (not (= diff 0))))
  4412. (setq txt nil)
  4413. (setq category (org-get-category))
  4414. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4415. (setq txt org-agenda-no-heading-message)
  4416. (goto-char (match-end 0))
  4417. (setq pos1 (match-beginning 0))
  4418. (if habitp
  4419. (if (or (not org-habit-show-habits)
  4420. (and (not todayp)
  4421. org-habit-show-habits-only-for-today))
  4422. (throw :skip nil))
  4423. (if (and
  4424. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4425. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4426. pastschedp))
  4427. (setq mm (assoc pos1 deadline-position-alist)))
  4428. (throw :skip nil)))
  4429. (setq tags (org-get-tags-at))
  4430. (setq head (buffer-substring-no-properties
  4431. (point)
  4432. (progn (skip-chars-forward "^\r\n") (point))))
  4433. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4434. (setq timestr
  4435. (concat (substring s (match-beginning 1)) " "))
  4436. (setq timestr 'time))
  4437. (setq txt (org-format-agenda-item
  4438. (if (= diff 0)
  4439. (car org-agenda-scheduled-leaders)
  4440. (format (nth 1 org-agenda-scheduled-leaders)
  4441. (- 1 diff)))
  4442. head category tags
  4443. (if (not (= diff 0)) nil timestr)
  4444. nil nil habitp))))
  4445. (when txt
  4446. (setq face
  4447. (cond
  4448. ((and (not habitp) pastschedp)
  4449. 'org-scheduled-previously)
  4450. (todayp 'org-scheduled-today)
  4451. (t 'org-scheduled))
  4452. habitp (and habitp (org-habit-parse-todo)))
  4453. (org-add-props txt props
  4454. 'undone-face face
  4455. 'face (if donep 'org-agenda-done face)
  4456. 'org-marker (org-agenda-new-marker pos)
  4457. 'org-hd-marker (org-agenda-new-marker pos1)
  4458. 'type (if pastschedp "past-scheduled" "scheduled")
  4459. 'date (if pastschedp d2 date)
  4460. 'priority (if habitp
  4461. (org-habit-get-priority habitp)
  4462. (+ 94 (- 5 diff) (org-get-priority txt)))
  4463. 'org-category category
  4464. 'org-habit-p habitp
  4465. 'todo-state todo-state)
  4466. (push txt ee))))))
  4467. (nreverse ee)))
  4468. (defun org-agenda-get-blocks ()
  4469. "Return the date-range information for agenda display."
  4470. (let* ((props (list 'face nil
  4471. 'org-not-done-regexp org-not-done-regexp
  4472. 'org-todo-regexp org-todo-regexp
  4473. 'org-complex-heading-regexp org-complex-heading-regexp
  4474. 'mouse-face 'highlight
  4475. 'help-echo
  4476. (format "mouse-2 or RET jump to org file %s"
  4477. (abbreviate-file-name buffer-file-name))))
  4478. (regexp org-tr-regexp)
  4479. (d0 (calendar-absolute-from-gregorian date))
  4480. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4481. head donep)
  4482. (goto-char (point-min))
  4483. (while (re-search-forward regexp nil t)
  4484. (catch :skip
  4485. (org-agenda-skip)
  4486. (setq pos (point))
  4487. (setq timestr (match-string 0)
  4488. s1 (match-string 1)
  4489. s2 (match-string 2)
  4490. d1 (time-to-days (org-time-string-to-time s1))
  4491. d2 (time-to-days (org-time-string-to-time s2)))
  4492. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4493. ;; Only allow days between the limits, because the normal
  4494. ;; date stamps will catch the limits.
  4495. (save-excursion
  4496. (setq todo-state (org-get-todo-state))
  4497. (setq donep (member todo-state org-done-keywords))
  4498. (if (and donep org-agenda-skip-timestamp-if-done)
  4499. (throw :skip t))
  4500. (setq marker (org-agenda-new-marker (point)))
  4501. (setq category (org-get-category))
  4502. (if (not (re-search-backward "^\\*+ " nil t))
  4503. (setq txt org-agenda-no-heading-message)
  4504. (goto-char (match-beginning 0))
  4505. (setq hdmarker (org-agenda-new-marker (point)))
  4506. (setq tags (org-get-tags-at))
  4507. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4508. (setq head (match-string 1))
  4509. (let ((remove-re
  4510. (if org-agenda-remove-timeranges-from-blocks
  4511. (concat
  4512. "<" (regexp-quote s1) ".*?>"
  4513. "--"
  4514. "<" (regexp-quote s2) ".*?>")
  4515. nil)))
  4516. (setq txt (org-format-agenda-item
  4517. (format
  4518. (nth (if (= d1 d2) 0 1)
  4519. org-agenda-timerange-leaders)
  4520. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4521. head category tags
  4522. timestr nil remove-re))))
  4523. (org-add-props txt props
  4524. 'org-marker marker 'org-hd-marker hdmarker
  4525. 'type "block" 'date date
  4526. 'todo-state todo-state
  4527. 'priority (org-get-priority txt) 'org-category category)
  4528. (push txt ee)))
  4529. (goto-char pos)))
  4530. ;; Sort the entries by expiration date.
  4531. (nreverse ee)))
  4532. ;;; Agenda presentation and sorting
  4533. (defvar org-prefix-has-time nil
  4534. "A flag, set by `org-compile-prefix-format'.
  4535. The flag is set if the currently compiled format contains a `%t'.")
  4536. (defvar org-prefix-has-tag nil
  4537. "A flag, set by `org-compile-prefix-format'.
  4538. The flag is set if the currently compiled format contains a `%T'.")
  4539. (defvar org-prefix-has-effort nil
  4540. "A flag, set by `org-compile-prefix-format'.
  4541. The flag is set if the currently compiled format contains a `%e'.")
  4542. (defvar org-prefix-category-length nil
  4543. "Used by `org-compile-prefix-format' to remember the category field width.")
  4544. (defvar org-prefix-category-max-length nil
  4545. "Used by `org-compile-prefix-format' to remember the category field width.")
  4546. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4547. noprefix remove-re habitp)
  4548. "Format TXT to be inserted into the agenda buffer.
  4549. In particular, it adds the prefix and corresponding text properties. EXTRA
  4550. must be a string and replaces the `%s' specifier in the prefix format.
  4551. CATEGORY (string, symbol or nil) may be used to overrule the default
  4552. category taken from local variable or file name. It will replace the `%c'
  4553. specifier in the format. DOTIME, when non-nil, indicates that a
  4554. time-of-day should be extracted from TXT for sorting of this entry, and for
  4555. the `%t' specifier in the format. When DOTIME is a string, this string is
  4556. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4557. only the correctly processes TXT should be returned - this is used by
  4558. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4559. Any match of REMOVE-RE will be removed from TXT."
  4560. (save-match-data
  4561. ;; Diary entries sometimes have extra whitespace at the beginning
  4562. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4563. ;; Fix the tags part in txt
  4564. (setq txt (org-agenda-fix-displayed-tags
  4565. txt tags
  4566. org-agenda-show-inherited-tags
  4567. org-agenda-hide-tags-regexp))
  4568. (let* ((category (or category
  4569. org-category
  4570. (if buffer-file-name
  4571. (file-name-sans-extension
  4572. (file-name-nondirectory buffer-file-name))
  4573. "")))
  4574. ;; time, tag, effort are needed for the eval of the prefix format
  4575. (tag (if tags (nth (1- (length tags)) tags) ""))
  4576. time effort neffort
  4577. (ts (if dotime (concat
  4578. (if (stringp dotime) dotime "")
  4579. (and org-agenda-search-headline-for-time txt))))
  4580. (time-of-day (and dotime (org-get-time-of-day ts)))
  4581. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4582. duration thecategory)
  4583. (and (org-mode-p) buffer-file-name
  4584. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4585. (when (and dotime time-of-day)
  4586. ;; Extract starting and ending time and move them to prefix
  4587. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4588. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4589. (setq s0 (match-string 0 ts)
  4590. srp (and stamp (match-end 3))
  4591. s1 (match-string (if plain 1 2) ts)
  4592. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4593. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4594. ;; them, we might want to remove them there to avoid duplication.
  4595. ;; The user can turn this off with a variable.
  4596. (if (and org-prefix-has-time
  4597. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4598. (string-match (concat (regexp-quote s0) " *") txt)
  4599. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4600. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4601. (= (match-beginning 0) 0)
  4602. t))
  4603. (setq txt (replace-match "" nil nil txt))))
  4604. ;; Normalize the time(s) to 24 hour
  4605. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4606. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4607. ;; Compute the duration
  4608. (when s1
  4609. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4610. (string-to-number (substring s1 3)))
  4611. t2 (cond
  4612. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4613. (string-to-number (substring s2 3))))
  4614. (org-agenda-default-appointment-duration
  4615. (+ t1 org-agenda-default-appointment-duration))
  4616. (t nil)))
  4617. (setq duration (if t2 (- t2 t1)))))
  4618. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4619. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4620. (let ((m (+ (string-to-number (match-string 2 s1))
  4621. (* 60 (string-to-number (match-string 1 s1)))
  4622. org-agenda-default-appointment-duration))
  4623. h)
  4624. (setq h (/ m 60) m (- m (* h 60)))
  4625. (setq s2 (format "%02d:%02d" h m))))
  4626. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4627. txt)
  4628. ;; Tags are in the string
  4629. (if (or (eq org-agenda-remove-tags t)
  4630. (and org-agenda-remove-tags
  4631. org-prefix-has-tag))
  4632. (setq txt (replace-match "" t t txt))
  4633. (setq txt (replace-match
  4634. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4635. (match-string 2 txt))
  4636. t t txt))))
  4637. (when (org-mode-p)
  4638. (setq effort
  4639. (condition-case nil
  4640. (org-get-effort
  4641. (or (get-text-property 0 'org-hd-marker txt)
  4642. (get-text-property 0 'org-marker txt)))
  4643. (error nil)))
  4644. (when effort
  4645. (setq neffort (org-hh:mm-string-to-minutes effort)
  4646. effort (setq effort (concat "[" effort "]" )))))
  4647. (when remove-re
  4648. (while (string-match remove-re txt)
  4649. (setq txt (replace-match "" t t txt))))
  4650. ;; Create the final string
  4651. (if noprefix
  4652. (setq rtn txt)
  4653. ;; Prepare the variables needed in the eval of the compiled format
  4654. (setq time (cond (s2 (concat s1 "-" s2))
  4655. (s1 (concat s1 "......"))
  4656. (t ""))
  4657. extra (or (and (not habitp) extra) "")
  4658. category (if (symbolp category) (symbol-name category) category)
  4659. thecategory (copy-sequence category))
  4660. (if (string-match org-bracket-link-regexp category)
  4661. (progn
  4662. (setq l (if (match-end 3)
  4663. (- (match-end 3) (match-beginning 3))
  4664. (- (match-end 1) (match-beginning 1))))
  4665. (when (< l (or org-prefix-category-length 0))
  4666. (setq category (copy-sequence category))
  4667. (org-add-props category nil
  4668. 'extra-space (make-string
  4669. (- org-prefix-category-length l 1) ?\ ))))
  4670. (if (and org-prefix-category-max-length
  4671. (>= (length category) org-prefix-category-max-length))
  4672. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4673. ;; Evaluate the compiled format
  4674. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4675. ;; And finally add the text properties
  4676. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4677. (org-add-props rtn nil
  4678. 'org-category (if thecategory (downcase thecategory) category)
  4679. 'tags (mapcar 'org-downcase-keep-props tags)
  4680. 'org-highest-priority org-highest-priority
  4681. 'org-lowest-priority org-lowest-priority
  4682. 'prefix-length (- (length rtn) (length txt))
  4683. 'time-of-day time-of-day
  4684. 'duration duration
  4685. 'effort effort
  4686. 'effort-minutes neffort
  4687. 'txt txt
  4688. 'time time
  4689. 'extra extra
  4690. 'dotime dotime))))
  4691. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4692. "Remove tags string from TXT, and add a modified list of tags.
  4693. The modified list may contain inherited tags, and tags matched by
  4694. `org-agenda-hide-tags-regexp' will be removed."
  4695. (when (or add-inherited hide-re)
  4696. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4697. (setq txt (substring txt 0 (match-beginning 0))))
  4698. (setq tags
  4699. (delq nil
  4700. (mapcar (lambda (tg)
  4701. (if (or (and hide-re (string-match hide-re tg))
  4702. (and (not add-inherited)
  4703. (get-text-property 0 'inherited tg)))
  4704. nil
  4705. tg))
  4706. tags)))
  4707. (when tags
  4708. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4709. i)
  4710. (setq txt (concat txt " :"
  4711. (mapconcat
  4712. (lambda (x)
  4713. (setq i (get-text-property 0 'inherited x))
  4714. (if (and have-i (not i))
  4715. (progn
  4716. (setq have-i nil)
  4717. (concat ":" x))
  4718. x))
  4719. tags ":")
  4720. (if have-i "::" ":"))))))
  4721. txt)
  4722. (defun org-downcase-keep-props (s)
  4723. (let ((props (text-properties-at 0 s)))
  4724. (setq s (downcase s))
  4725. (add-text-properties 0 (length s) props s)
  4726. s))
  4727. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4728. (defvar org-agenda-sorting-strategy-selected nil)
  4729. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4730. (catch 'exit
  4731. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4732. ((and todayp (member 'today (car org-agenda-time-grid))))
  4733. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4734. ((member 'weekly (car org-agenda-time-grid)))
  4735. (t (throw 'exit list)))
  4736. (let* ((have (delq nil (mapcar
  4737. (lambda (x) (get-text-property 1 'time-of-day x))
  4738. list)))
  4739. (string (nth 1 org-agenda-time-grid))
  4740. (gridtimes (nth 2 org-agenda-time-grid))
  4741. (req (car org-agenda-time-grid))
  4742. (remove (member 'remove-match req))
  4743. new time)
  4744. (if (and (member 'require-timed req) (not have))
  4745. ;; don't show empty grid
  4746. (throw 'exit list))
  4747. (while (setq time (pop gridtimes))
  4748. (unless (and remove (member time have))
  4749. (setq time (int-to-string time))
  4750. (push (org-format-agenda-item
  4751. nil string "" nil
  4752. (concat (substring time 0 -2) ":" (substring time -2)))
  4753. new)
  4754. (put-text-property
  4755. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4756. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4757. (append new list)
  4758. (append list new)))))
  4759. (defun org-compile-prefix-format (key)
  4760. "Compile the prefix format into a Lisp form that can be evaluated.
  4761. The resulting form is returned and stored in the variable
  4762. `org-prefix-format-compiled'."
  4763. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4764. org-prefix-category-length nil org-prefix-has-effort nil)
  4765. (let ((s (cond
  4766. ((stringp org-agenda-prefix-format)
  4767. org-agenda-prefix-format)
  4768. ((assq key org-agenda-prefix-format)
  4769. (cdr (assq key org-agenda-prefix-format)))
  4770. (t " %-12:c%?-12t% s")))
  4771. (start 0)
  4772. varform vars var e c f opt)
  4773. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4774. s start)
  4775. (setq var (cdr (assoc (match-string 4 s)
  4776. '(("c" . category) ("t" . time) ("s" . extra)
  4777. ("T" . tag) ("e" . effort))))
  4778. c (or (match-string 3 s) "")
  4779. opt (match-beginning 1)
  4780. start (1+ (match-beginning 0)))
  4781. (if (equal var 'time) (setq org-prefix-has-time t))
  4782. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4783. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4784. (setq f (concat "%" (match-string 2 s) "s"))
  4785. (when (equal var 'category)
  4786. (setq org-prefix-category-length
  4787. (floor (abs (string-to-number (match-string 2 s)))))
  4788. (setq org-prefix-category-max-length
  4789. (let ((x (match-string 2 s)))
  4790. (save-match-data
  4791. (if (string-match "\\.[0-9]+" x)
  4792. (string-to-number (substring (match-string 0 x) 1)))))))
  4793. (if opt
  4794. (setq varform
  4795. `(if (equal "" ,var)
  4796. ""
  4797. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4798. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4799. (setq s (replace-match "%s" t nil s))
  4800. (push varform vars))
  4801. (setq vars (nreverse vars))
  4802. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4803. (defun org-set-sorting-strategy (key)
  4804. (if (symbolp (car org-agenda-sorting-strategy))
  4805. ;; the old format
  4806. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4807. (setq org-agenda-sorting-strategy-selected
  4808. (or (cdr (assq key org-agenda-sorting-strategy))
  4809. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4810. '(time-up category-keep priority-down)))))
  4811. (defun org-get-time-of-day (s &optional string mod24)
  4812. "Check string S for a time of day.
  4813. If found, return it as a military time number between 0 and 2400.
  4814. If not found, return nil.
  4815. The optional STRING argument forces conversion into a 5 character wide string
  4816. HH:MM."
  4817. (save-match-data
  4818. (when
  4819. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4820. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4821. (let* ((h (string-to-number (match-string 1 s)))
  4822. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4823. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4824. (am-p (equal ampm "am"))
  4825. (h1 (cond ((not ampm) h)
  4826. ((= h 12) (if am-p 0 12))
  4827. (t (+ h (if am-p 0 12)))))
  4828. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4829. (mod h1 24) h1))
  4830. (t0 (+ (* 100 h2) m))
  4831. (t1 (concat (if (>= h1 24) "+" " ")
  4832. (if (and org-agenda-time-leading-zero
  4833. (< t0 1000)) "0" "")
  4834. (if (< t0 100) "0" "")
  4835. (if (< t0 10) "0" "")
  4836. (int-to-string t0))))
  4837. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4838. (defvar org-agenda-before-sorting-filter-function nil
  4839. "Function to be applied to agenda items prior to sorting.
  4840. Prior to sorting also means just before they are inserted into the agenda.
  4841. To aid sorting, you may revisit the original entries and add more text
  4842. properties which will later be used by the sorting functions.
  4843. The function should take a string argument, an agenda line.
  4844. It has access to the text properties in that line, which contain among
  4845. other things, the property `org-hd-marker' that points to the entry
  4846. where the line comes from. Note that not all lines going into the agenda
  4847. have this property, only most.
  4848. The function should return the modified string. It is probably best
  4849. to ONLY change text properties.
  4850. You can also use this function as a filter, by returning nil for lines
  4851. you don't want to have in the agenda at all. For this application, you
  4852. could bind the variable in the options section of a custom command.")
  4853. (defun org-finalize-agenda-entries (list &optional nosort)
  4854. "Sort and concatenate the agenda items."
  4855. (setq list (mapcar 'org-agenda-highlight-todo list))
  4856. (if nosort
  4857. list
  4858. (when org-agenda-before-sorting-filter-function
  4859. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  4860. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4861. (defun org-agenda-highlight-todo (x)
  4862. (let ((org-done-keywords org-done-keywords-for-agenda)
  4863. (case-fold-search nil)
  4864. re pl)
  4865. (if (eq x 'line)
  4866. (save-excursion
  4867. (beginning-of-line 1)
  4868. (setq re (org-get-at-bol 'org-todo-regexp))
  4869. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4870. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4871. (add-text-properties (match-beginning 0) (match-end 1)
  4872. (list 'face (org-get-todo-face 1)))
  4873. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4874. (delete-region (match-beginning 1) (1- (match-end 0)))
  4875. (goto-char (match-beginning 1))
  4876. (insert (format org-agenda-todo-keyword-format s)))))
  4877. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4878. pl (get-text-property 0 'prefix-length x))
  4879. (when (and re
  4880. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4881. x (or pl 0)) pl))
  4882. (add-text-properties
  4883. (or (match-end 1) (match-end 0)) (match-end 0)
  4884. (list 'face (org-get-todo-face (match-string 2 x)))
  4885. x)
  4886. (when (match-end 1)
  4887. (setq x (concat (substring x 0 (match-end 1))
  4888. (format org-agenda-todo-keyword-format
  4889. (match-string 2 x))
  4890. (org-add-props " " (text-properties-at 0 x))
  4891. (substring x (match-end 3))))))
  4892. x)))
  4893. (defsubst org-cmp-priority (a b)
  4894. "Compare the priorities of string A and B."
  4895. (let ((pa (or (get-text-property 1 'priority a) 0))
  4896. (pb (or (get-text-property 1 'priority b) 0)))
  4897. (cond ((> pa pb) +1)
  4898. ((< pa pb) -1)
  4899. (t nil))))
  4900. (defsubst org-cmp-effort (a b)
  4901. "Compare the priorities of string A and B."
  4902. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4903. (ea (or (get-text-property 1 'effort-minutes a) def))
  4904. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4905. (cond ((> ea eb) +1)
  4906. ((< ea eb) -1)
  4907. (t nil))))
  4908. (defsubst org-cmp-category (a b)
  4909. "Compare the string values of categories of strings A and B."
  4910. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4911. (cb (or (get-text-property 1 'org-category b) "")))
  4912. (cond ((string-lessp ca cb) -1)
  4913. ((string-lessp cb ca) +1)
  4914. (t nil))))
  4915. (defsubst org-cmp-todo-state (a b)
  4916. "Compare the todo states of strings A and B."
  4917. (let* ((ma (or (get-text-property 1 'org-marker a)
  4918. (get-text-property 1 'org-hd-marker a)))
  4919. (mb (or (get-text-property 1 'org-marker b)
  4920. (get-text-property 1 'org-hd-marker b)))
  4921. (fa (and ma (marker-buffer ma)))
  4922. (fb (and mb (marker-buffer mb)))
  4923. (todo-kwds
  4924. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4925. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4926. (ta (or (get-text-property 1 'todo-state a) ""))
  4927. (tb (or (get-text-property 1 'todo-state b) ""))
  4928. (la (- (length (member ta todo-kwds))))
  4929. (lb (- (length (member tb todo-kwds))))
  4930. (donepa (member ta org-done-keywords-for-agenda))
  4931. (donepb (member tb org-done-keywords-for-agenda)))
  4932. (cond ((and donepa (not donepb)) -1)
  4933. ((and (not donepa) donepb) +1)
  4934. ((< la lb) -1)
  4935. ((< lb la) +1)
  4936. (t nil))))
  4937. (defsubst org-cmp-alpha (a b)
  4938. "Compare the headlines, alphabetically."
  4939. (let* ((pla (get-text-property 0 'prefix-length a))
  4940. (plb (get-text-property 0 'prefix-length b))
  4941. (ta (and pla (substring a pla)))
  4942. (tb (and plb (substring b plb))))
  4943. (when pla
  4944. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  4945. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  4946. (setq ta (substring ta (match-end 0))))
  4947. (setq ta (downcase ta)))
  4948. (when plb
  4949. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  4950. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  4951. (setq tb (substring tb (match-end 0))))
  4952. (setq tb (downcase tb)))
  4953. (cond ((not ta) +1)
  4954. ((not tb) -1)
  4955. ((string-lessp ta tb) -1)
  4956. ((string-lessp tb ta) +1)
  4957. (t nil))))
  4958. (defsubst org-cmp-tag (a b)
  4959. "Compare the string values of the first tags of A and B."
  4960. (let ((ta (car (last (get-text-property 1 'tags a))))
  4961. (tb (car (last (get-text-property 1 'tags b)))))
  4962. (cond ((not ta) +1)
  4963. ((not tb) -1)
  4964. ((string-lessp ta tb) -1)
  4965. ((string-lessp tb ta) +1)
  4966. (t nil))))
  4967. (defsubst org-cmp-time (a b)
  4968. "Compare the time-of-day values of strings A and B."
  4969. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4970. (ta (or (get-text-property 1 'time-of-day a) def))
  4971. (tb (or (get-text-property 1 'time-of-day b) def)))
  4972. (cond ((< ta tb) -1)
  4973. ((< tb ta) +1)
  4974. (t nil))))
  4975. (defsubst org-cmp-habit-p (a b)
  4976. "Compare the todo states of strings A and B."
  4977. (let ((ha (get-text-property 1 'org-habit-p a))
  4978. (hb (get-text-property 1 'org-habit-p b)))
  4979. (cond ((and ha (not hb)) -1)
  4980. ((and (not ha) hb) +1)
  4981. (t nil))))
  4982. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  4983. (defun org-entries-lessp (a b)
  4984. "Predicate for sorting agenda entries."
  4985. ;; The following variables will be used when the form is evaluated.
  4986. ;; So even though the compiler complains, keep them.
  4987. (let* ((ss org-agenda-sorting-strategy-selected)
  4988. (time-up (and (org-em 'time-up 'time-down ss)
  4989. (org-cmp-time a b)))
  4990. (time-down (if time-up (- time-up) nil))
  4991. (priority-up (and (org-em 'priority-up 'priority-down ss)
  4992. (org-cmp-priority a b)))
  4993. (priority-down (if priority-up (- priority-up) nil))
  4994. (effort-up (and (org-em 'effort-up 'effort-down ss)
  4995. (org-cmp-effort a b)))
  4996. (effort-down (if effort-up (- effort-up) nil))
  4997. (category-up (and (or (org-em 'category-up 'category-down ss)
  4998. (memq 'category-keep ss))
  4999. (org-cmp-category a b)))
  5000. (category-down (if category-up (- category-up) nil))
  5001. (category-keep (if category-up +1 nil))
  5002. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5003. (org-cmp-tag a b)))
  5004. (tag-down (if tag-up (- tag-up) nil))
  5005. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5006. (org-cmp-todo-state a b)))
  5007. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5008. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5009. (org-cmp-habit-p a b)))
  5010. (habit-down (if habit-up (- habit-up) nil))
  5011. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5012. (org-cmp-alpha a b)))
  5013. (alpha-down (if alpha-up (- alpha-up) nil))
  5014. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5015. user-defined-up user-defined-down)
  5016. (if (and need-user-cmp org-agenda-cmp-user-defined
  5017. (functionp org-agenda-cmp-user-defined))
  5018. (setq user-defined-up
  5019. (funcall org-agenda-cmp-user-defined a b)
  5020. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5021. (cdr (assoc
  5022. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5023. '((-1 . t) (1 . nil) (nil . nil))))))
  5024. ;;; Agenda restriction lock
  5025. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5026. "Overlay to mark the headline to which agenda commands are restricted.")
  5027. (overlay-put org-agenda-restriction-lock-overlay
  5028. 'face 'org-agenda-restriction-lock)
  5029. (overlay-put org-agenda-restriction-lock-overlay
  5030. 'help-echo "Agendas are currently limited to this subtree.")
  5031. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5032. (defun org-agenda-set-restriction-lock (&optional type)
  5033. "Set restriction lock for agenda, to current subtree or file.
  5034. Restriction will be the file if TYPE is `file', or if type is the
  5035. universal prefix '(4), or if the cursor is before the first headline
  5036. in the file. Otherwise, restriction will be to the current subtree."
  5037. (interactive "P")
  5038. (and (equal type '(4)) (setq type 'file))
  5039. (setq type (cond
  5040. (type type)
  5041. ((org-at-heading-p) 'subtree)
  5042. ((condition-case nil (org-back-to-heading t) (error nil))
  5043. 'subtree)
  5044. (t 'file)))
  5045. (if (eq type 'subtree)
  5046. (progn
  5047. (setq org-agenda-restrict t)
  5048. (setq org-agenda-overriding-restriction 'subtree)
  5049. (put 'org-agenda-files 'org-restrict
  5050. (list (buffer-file-name (buffer-base-buffer))))
  5051. (org-back-to-heading t)
  5052. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5053. (move-marker org-agenda-restrict-begin (point))
  5054. (move-marker org-agenda-restrict-end
  5055. (save-excursion (org-end-of-subtree t)))
  5056. (message "Locking agenda restriction to subtree"))
  5057. (put 'org-agenda-files 'org-restrict
  5058. (list (buffer-file-name (buffer-base-buffer))))
  5059. (setq org-agenda-restrict nil)
  5060. (setq org-agenda-overriding-restriction 'file)
  5061. (move-marker org-agenda-restrict-begin nil)
  5062. (move-marker org-agenda-restrict-end nil)
  5063. (message "Locking agenda restriction to file"))
  5064. (setq current-prefix-arg nil)
  5065. (org-agenda-maybe-redo))
  5066. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5067. "Remove the agenda restriction lock."
  5068. (interactive "P")
  5069. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5070. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5071. (setq org-agenda-overriding-restriction nil)
  5072. (setq org-agenda-restrict nil)
  5073. (put 'org-agenda-files 'org-restrict nil)
  5074. (move-marker org-agenda-restrict-begin nil)
  5075. (move-marker org-agenda-restrict-end nil)
  5076. (setq current-prefix-arg nil)
  5077. (message "Agenda restriction lock removed")
  5078. (or noupdate (org-agenda-maybe-redo)))
  5079. (defun org-agenda-maybe-redo ()
  5080. "If there is any window showing the agenda view, update it."
  5081. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5082. (w0 (selected-window)))
  5083. (when w
  5084. (select-window w)
  5085. (org-agenda-redo)
  5086. (select-window w0)
  5087. (if org-agenda-overriding-restriction
  5088. (message "Agenda view shifted to new %s restriction"
  5089. org-agenda-overriding-restriction)
  5090. (message "Agenda restriction lock removed")))))
  5091. ;;; Agenda commands
  5092. (defun org-agenda-check-type (error &rest types)
  5093. "Check if agenda buffer is of allowed type.
  5094. If ERROR is non-nil, throw an error, otherwise just return nil."
  5095. (if (memq org-agenda-type types)
  5096. t
  5097. (if error
  5098. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5099. nil)))
  5100. (defun org-agenda-quit ()
  5101. "Exit agenda by removing the window or the buffer."
  5102. (interactive)
  5103. (if org-agenda-columns-active
  5104. (org-columns-quit)
  5105. (let ((buf (current-buffer)))
  5106. (if (eq org-agenda-window-setup 'other-frame)
  5107. (progn
  5108. (kill-buffer buf)
  5109. (org-agenda-reset-markers)
  5110. (org-columns-remove-overlays)
  5111. (setq org-agenda-archives-mode nil)
  5112. (delete-frame))
  5113. (and (not (eq org-agenda-window-setup 'current-window))
  5114. (not (one-window-p))
  5115. (delete-window))
  5116. (kill-buffer buf)
  5117. (org-agenda-reset-markers)
  5118. (org-columns-remove-overlays)
  5119. (setq org-agenda-archives-mode nil)))
  5120. ;; Maybe restore the pre-agenda window configuration.
  5121. (and org-agenda-restore-windows-after-quit
  5122. (not (eq org-agenda-window-setup 'other-frame))
  5123. org-pre-agenda-window-conf
  5124. (set-window-configuration org-pre-agenda-window-conf))))
  5125. (defun org-agenda-exit ()
  5126. "Exit agenda by removing the window or the buffer.
  5127. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5128. Org-mode buffers visited directly by the user will not be touched."
  5129. (interactive)
  5130. (org-release-buffers org-agenda-new-buffers)
  5131. (setq org-agenda-new-buffers nil)
  5132. (org-agenda-quit))
  5133. (defun org-agenda-execute (arg)
  5134. "Execute another agenda command, keeping same window.
  5135. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5136. in the agenda."
  5137. (interactive "P")
  5138. (let ((org-agenda-window-setup 'current-window))
  5139. (org-agenda arg)))
  5140. (defun org-agenda-redo ()
  5141. "Rebuild Agenda.
  5142. When this is the global TODO list, a prefix argument will be interpreted."
  5143. (interactive)
  5144. (let* ((org-agenda-keep-modes t)
  5145. (filter org-agenda-filter)
  5146. (preset (get 'org-agenda-filter :preset-filter))
  5147. (cols org-agenda-columns-active)
  5148. (line (org-current-line))
  5149. (window-line (- line (org-current-line (window-start))))
  5150. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5151. (put 'org-agenda-filter :preset-filter nil)
  5152. (and cols (org-columns-quit))
  5153. (message "Rebuilding agenda buffer...")
  5154. (org-let lprops '(eval org-agenda-redo-command))
  5155. (setq org-agenda-undo-list nil
  5156. org-agenda-pending-undo-list nil)
  5157. (message "Rebuilding agenda buffer...done")
  5158. (put 'org-agenda-filter :preset-filter preset)
  5159. (and (or filter preset) (org-agenda-filter-apply filter))
  5160. (and cols (interactive-p) (org-agenda-columns))
  5161. (org-goto-line line)
  5162. (recenter window-line)))
  5163. (defvar org-global-tags-completion-table nil)
  5164. (defvar org-agenda-filter-form nil)
  5165. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5166. "Keep only those lines in the agenda buffer that have a specific tag.
  5167. The tag is selected with its fast selection letter, as configured.
  5168. With prefix argument STRIP, remove all lines that do have the tag.
  5169. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5170. used to narrow the search - the interactive user can also press `-' or `+'
  5171. to switch to narrowing."
  5172. (interactive "P")
  5173. (let* ((alist org-tag-alist-for-agenda)
  5174. (tag-chars (mapconcat
  5175. (lambda (x) (if (and (not (symbolp (car x)))
  5176. (cdr x))
  5177. (char-to-string (cdr x))
  5178. ""))
  5179. alist ""))
  5180. (efforts (org-split-string
  5181. (or (cdr (assoc (concat org-effort-property "_ALL")
  5182. org-global-properties))
  5183. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5184. (effort-op org-agenda-filter-effort-default-operator)
  5185. (effort-prompt "")
  5186. (inhibit-read-only t)
  5187. (current org-agenda-filter)
  5188. a n tag)
  5189. (unless char
  5190. (message
  5191. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5192. (if narrow "Narrow" "Filter") tag-chars
  5193. (if org-agenda-auto-exclude-function "[RET], " ""))
  5194. (setq char (read-char)))
  5195. (when (member char '(?+ ?-))
  5196. ;; Narrowing down
  5197. (cond ((equal char ?-) (setq strip t narrow t))
  5198. ((equal char ?+) (setq strip nil narrow t)))
  5199. (message
  5200. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5201. (setq char (read-char)))
  5202. (when (member char '(?< ?> ?= ??))
  5203. ;; An effort operator
  5204. (setq effort-op (char-to-string char))
  5205. (setq alist nil) ; to make sure it will be interpreted as effort.
  5206. (unless (equal char ??)
  5207. (loop for i from 0 to 9 do
  5208. (setq effort-prompt
  5209. (concat
  5210. effort-prompt " ["
  5211. (if (= i 9) "0" (int-to-string (1+ i)))
  5212. "]" (nth i efforts))))
  5213. (message "Effort%s: %s " effort-op effort-prompt)
  5214. (setq char (read-char))
  5215. (when (or (< char ?0) (> char ?9))
  5216. (error "Need 1-9,0 to select effort" ))))
  5217. (when (equal char ?\t)
  5218. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5219. (org-set-local 'org-global-tags-completion-table
  5220. (org-global-tags-completion-table)))
  5221. (let ((completion-ignore-case t))
  5222. (setq tag (org-icompleting-read
  5223. "Tag: " org-global-tags-completion-table))))
  5224. (cond
  5225. ((equal char ?\r)
  5226. (org-agenda-filter-by-tag-show-all)
  5227. (when org-agenda-auto-exclude-function
  5228. (setq org-agenda-filter '())
  5229. (dolist (tag (org-agenda-get-represented-tags))
  5230. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5231. (if modifier
  5232. (push modifier org-agenda-filter))))
  5233. (if (not (null org-agenda-filter))
  5234. (org-agenda-filter-apply org-agenda-filter))))
  5235. ((equal char ?/)
  5236. (org-agenda-filter-by-tag-show-all)
  5237. (when (get 'org-agenda-filter :preset-filter)
  5238. (org-agenda-filter-apply org-agenda-filter)))
  5239. ((or (equal char ?\ )
  5240. (setq a (rassoc char alist))
  5241. (and (>= char ?0) (<= char ?9)
  5242. (setq n (if (= char ?0) 9 (- char ?0 1))
  5243. tag (concat effort-op (nth n efforts))
  5244. a (cons tag nil)))
  5245. (and (= char ??)
  5246. (setq tag "?eff")
  5247. a (cons tag nil))
  5248. (and tag (setq a (cons tag nil))))
  5249. (org-agenda-filter-by-tag-show-all)
  5250. (setq tag (car a))
  5251. (setq org-agenda-filter
  5252. (cons (concat (if strip "-" "+") tag)
  5253. (if narrow current nil)))
  5254. (org-agenda-filter-apply org-agenda-filter))
  5255. (t (error "Invalid tag selection character %c" char)))))
  5256. (defun org-agenda-get-represented-tags ()
  5257. "Get a list of all tags currently represented in the agenda."
  5258. (let (p tags)
  5259. (save-excursion
  5260. (goto-char (point-min))
  5261. (while (setq p (next-single-property-change (point) 'tags))
  5262. (goto-char p)
  5263. (mapc (lambda (x) (add-to-list 'tags x))
  5264. (get-text-property (point) 'tags))))
  5265. tags))
  5266. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5267. "Refine the current filter. See `org-agenda-filter-by-tag."
  5268. (interactive "P")
  5269. (org-agenda-filter-by-tag strip char 'refine))
  5270. (defun org-agenda-filter-make-matcher ()
  5271. "Create the form that tests a line for the agenda filter."
  5272. (let (f f1)
  5273. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5274. org-agenda-filter))
  5275. (if (member x '("-" "+"))
  5276. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5277. (if (string-match "[<=>?]" x)
  5278. (setq f1 (org-agenda-filter-effort-form x))
  5279. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5280. (if (equal (string-to-char x) ?-)
  5281. (setq f1 (list 'not f1))))
  5282. (push f1 f))
  5283. (cons 'and (nreverse f))))
  5284. (defun org-agenda-filter-effort-form (e)
  5285. "Return the form to compare the effort of the current line with what E says.
  5286. E looks like \"+<2:25\"."
  5287. (let (op)
  5288. (setq e (substring e 1))
  5289. (setq op (string-to-char e) e (substring e 1))
  5290. (setq op (cond ((equal op ?<) '<=)
  5291. ((equal op ?>) '>=)
  5292. ((equal op ??) op)
  5293. (t '=)))
  5294. (list 'org-agenda-compare-effort (list 'quote op)
  5295. (org-hh:mm-string-to-minutes e))))
  5296. (defun org-agenda-compare-effort (op value)
  5297. "Compare the effort of the current line with VALUE, using OP.
  5298. If the line does not have an effort defined, return nil."
  5299. (let ((eff (org-get-at-bol 'effort-minutes)))
  5300. (if (equal op ??)
  5301. (not eff)
  5302. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5303. value))))
  5304. (defun org-agenda-filter-apply (filter)
  5305. "Set FILTER as the new agenda filter and apply it."
  5306. (let (tags)
  5307. (setq org-agenda-filter filter
  5308. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5309. (org-agenda-set-mode-name)
  5310. (save-excursion
  5311. (goto-char (point-min))
  5312. (while (not (eobp))
  5313. (if (org-get-at-bol 'org-marker)
  5314. (progn
  5315. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5316. (if (not (eval org-agenda-filter-form))
  5317. (org-agenda-filter-by-tag-hide-line))
  5318. (beginning-of-line 2))
  5319. (beginning-of-line 2))))))
  5320. (defun org-agenda-filter-by-tag-hide-line ()
  5321. (let (ov)
  5322. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5323. (point-at-eol)))
  5324. (overlay-put ov 'invisible t)
  5325. (overlay-put ov 'type 'tags-filter)
  5326. (push ov org-agenda-filter-overlays)))
  5327. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5328. (setq pos (or pos (point)))
  5329. (save-excursion
  5330. (dolist (ov (overlays-at pos))
  5331. (when (and (overlay-get ov 'invisible)
  5332. (eq (overlay-get ov 'type) 'tags-filter))
  5333. (goto-char pos)
  5334. (if (< (overlay-start ov) (point-at-eol))
  5335. (move-overlay ov (point-at-eol)
  5336. (overlay-end ov)))))))
  5337. (defun org-agenda-filter-by-tag-show-all ()
  5338. (mapc 'delete-overlay org-agenda-filter-overlays)
  5339. (setq org-agenda-filter-overlays nil)
  5340. (setq org-agenda-filter nil)
  5341. (setq org-agenda-filter-form nil)
  5342. (org-agenda-set-mode-name))
  5343. (defun org-agenda-manipulate-query-add ()
  5344. "Manipulate the query by adding a search term with positive selection.
  5345. Positive selection means the term must be matched for selection of an entry."
  5346. (interactive)
  5347. (org-agenda-manipulate-query ?\[))
  5348. (defun org-agenda-manipulate-query-subtract ()
  5349. "Manipulate the query by adding a search term with negative selection.
  5350. Negative selection means term must not be matched for selection of an entry."
  5351. (interactive)
  5352. (org-agenda-manipulate-query ?\]))
  5353. (defun org-agenda-manipulate-query-add-re ()
  5354. "Manipulate the query by adding a search regexp with positive selection.
  5355. Positive selection means the regexp must match for selection of an entry."
  5356. (interactive)
  5357. (org-agenda-manipulate-query ?\{))
  5358. (defun org-agenda-manipulate-query-subtract-re ()
  5359. "Manipulate the query by adding a search regexp with negative selection.
  5360. Negative selection means regexp must not match for selection of an entry."
  5361. (interactive)
  5362. (org-agenda-manipulate-query ?\}))
  5363. (defun org-agenda-manipulate-query (char)
  5364. (cond
  5365. ((memq org-agenda-type '(timeline agenda))
  5366. (let ((org-agenda-include-inactive-timestamps t))
  5367. (org-agenda-redo))
  5368. (message "Display now includes inactive timestamps as well"))
  5369. ((eq org-agenda-type 'search)
  5370. (org-add-to-string
  5371. 'org-agenda-query-string
  5372. (if org-agenda-last-search-view-search-was-boolean
  5373. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5374. (?\{ . " +{}") (?\} . " -{}"))))
  5375. " "))
  5376. (setq org-agenda-redo-command
  5377. (list 'org-search-view
  5378. org-todo-only
  5379. org-agenda-query-string
  5380. (+ (length org-agenda-query-string)
  5381. (if (member char '(?\{ ?\})) 0 1))))
  5382. (set-register org-agenda-query-register org-agenda-query-string)
  5383. (org-agenda-redo))
  5384. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5385. org-agenda-type))))
  5386. (defun org-add-to-string (var string)
  5387. (set var (concat (symbol-value var) string)))
  5388. (defun org-agenda-goto-date (date)
  5389. "Jump to DATE in agenda."
  5390. (interactive (list (org-read-date)))
  5391. (org-agenda-list nil date))
  5392. (defun org-agenda-goto-today ()
  5393. "Go to today."
  5394. (interactive)
  5395. (org-agenda-check-type t 'timeline 'agenda)
  5396. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5397. (cond
  5398. (tdpos (goto-char tdpos))
  5399. ((eq org-agenda-type 'agenda)
  5400. (let* ((sd (time-to-days
  5401. (time-subtract (current-time)
  5402. (list 0 (* 3600 org-extend-today-until) 0))))
  5403. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5404. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5405. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5406. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5407. (org-agenda-redo)
  5408. (org-agenda-find-same-or-today-or-agenda)))
  5409. (t (error "Cannot find today")))))
  5410. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5411. (goto-char
  5412. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5413. (text-property-any (point-min) (point-max) 'org-today t)
  5414. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5415. (point-min))))
  5416. (defun org-agenda-later (arg)
  5417. "Go forward in time by thee current span.
  5418. With prefix ARG, go forward that many times the current span."
  5419. (interactive "p")
  5420. (org-agenda-check-type t 'agenda)
  5421. (let* ((span org-agenda-span)
  5422. (sd org-starting-day)
  5423. (greg (calendar-gregorian-from-absolute sd))
  5424. (cnt (org-get-at-bol 'org-day-cnt))
  5425. greg2 nd)
  5426. (cond
  5427. ((eq span 'day)
  5428. (setq sd (+ arg sd) nd 1))
  5429. ((eq span 'week)
  5430. (setq sd (+ (* 7 arg) sd) nd 7))
  5431. ((eq span 'month)
  5432. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5433. sd (calendar-absolute-from-gregorian greg2))
  5434. (setcar greg2 (1+ (car greg2)))
  5435. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5436. ((eq span 'year)
  5437. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5438. sd (calendar-absolute-from-gregorian greg2))
  5439. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5440. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5441. (let ((org-agenda-overriding-arguments
  5442. (list (car org-agenda-last-arguments) sd nd t)))
  5443. (org-agenda-redo)
  5444. (org-agenda-find-same-or-today-or-agenda cnt))))
  5445. (defun org-agenda-earlier (arg)
  5446. "Go backward in time by the current span.
  5447. With prefix ARG, go backward that many times the current span."
  5448. (interactive "p")
  5449. (org-agenda-later (- arg)))
  5450. (defun org-agenda-view-mode-dispatch ()
  5451. "Call one of the view mode commands."
  5452. (interactive)
  5453. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5454. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5455. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5456. (let ((a (read-char-exclusive)))
  5457. (case a
  5458. (?d (call-interactively 'org-agenda-day-view))
  5459. (?w (call-interactively 'org-agenda-week-view))
  5460. (?m (call-interactively 'org-agenda-month-view))
  5461. (?y (call-interactively 'org-agenda-year-view))
  5462. (?l (call-interactively 'org-agenda-log-mode))
  5463. (?L (org-agenda-log-mode '(4)))
  5464. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5465. (?a (call-interactively 'org-agenda-archives-mode))
  5466. (?A (org-agenda-archives-mode 'files))
  5467. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5468. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5469. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5470. (?D (call-interactively 'org-agenda-toggle-diary))
  5471. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5472. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5473. (org-agenda-check-type t 'timeline 'agenda)
  5474. (org-agenda-redo))
  5475. (message "Display now includes inactive timestamps as well"))
  5476. (?q (message "Abort"))
  5477. (otherwise (error "Invalid key" )))))
  5478. (defun org-agenda-day-view (&optional day-of-year)
  5479. "Switch to daily view for agenda.
  5480. With argument DAY-OF-YEAR, switch to that day of the year."
  5481. (interactive "P")
  5482. (setq org-agenda-ndays 1)
  5483. (org-agenda-change-time-span 'day day-of-year))
  5484. (defun org-agenda-week-view (&optional iso-week)
  5485. "Switch to daily view for agenda.
  5486. With argument ISO-WEEK, switch to the corresponding ISO week.
  5487. If ISO-WEEK has more then 2 digits, only the last two encode the
  5488. week. Any digits before this encode a year. So 200712 means
  5489. week 12 of year 2007. Years in the range 1938-2037 can also be
  5490. written as 2-digit years."
  5491. (interactive "P")
  5492. (setq org-agenda-ndays 7)
  5493. (org-agenda-change-time-span 'week iso-week))
  5494. (defun org-agenda-month-view (&optional month)
  5495. "Switch to monthly view for agenda.
  5496. With argument MONTH, switch to that month."
  5497. (interactive "P")
  5498. (org-agenda-change-time-span 'month month))
  5499. (defun org-agenda-year-view (&optional year)
  5500. "Switch to yearly view for agenda.
  5501. With argument YEAR, switch to that year.
  5502. If MONTH has more then 2 digits, only the last two encode the
  5503. month. Any digits before this encode a year. So 200712 means
  5504. December year 2007. Years in the range 1938-2037 can also be
  5505. written as 2-digit years."
  5506. (interactive "P")
  5507. (when year
  5508. (setq year (org-small-year-to-year year)))
  5509. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5510. (org-agenda-change-time-span 'year year)
  5511. (error "Abort")))
  5512. (defun org-agenda-change-time-span (span &optional n)
  5513. "Change the agenda view to SPAN.
  5514. SPAN may be `day', `week', `month', `year'."
  5515. (org-agenda-check-type t 'agenda)
  5516. (if (and (not n) (equal org-agenda-span span))
  5517. (error "Viewing span is already \"%s\"" span))
  5518. (let* ((sd (or (org-get-at-bol 'day)
  5519. org-starting-day))
  5520. (computed (org-agenda-compute-time-span sd span n))
  5521. (org-agenda-overriding-arguments
  5522. (list (car org-agenda-last-arguments)
  5523. (car computed) (cdr computed) t)))
  5524. (org-agenda-redo)
  5525. (org-agenda-find-same-or-today-or-agenda))
  5526. (org-agenda-set-mode-name)
  5527. (message "Switched to %s view" span))
  5528. (defun org-agenda-compute-time-span (sd span &optional n)
  5529. "Compute starting date and number of days for agenda.
  5530. SPAN may be `day', `week', `month', `year'. The return value
  5531. is a cons cell with the starting date and the number of days,
  5532. so that the date SD will be in that range."
  5533. (let* ((greg (calendar-gregorian-from-absolute sd))
  5534. (dg (nth 1 greg))
  5535. (mg (car greg))
  5536. (yg (nth 2 greg))
  5537. nd w1 y1 m1 thisweek)
  5538. (cond
  5539. ((eq span 'day)
  5540. (when n
  5541. (setq sd (+ (calendar-absolute-from-gregorian
  5542. (list mg 1 yg))
  5543. n -1)))
  5544. (setq nd 1))
  5545. ((eq span 'week)
  5546. (let* ((nt (calendar-day-of-week
  5547. (calendar-gregorian-from-absolute sd)))
  5548. (d (if org-agenda-start-on-weekday
  5549. (- nt org-agenda-start-on-weekday)
  5550. 0)))
  5551. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5552. (when n
  5553. (require 'cal-iso)
  5554. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5555. (when (> n 99)
  5556. (setq y1 (org-small-year-to-year (/ n 100))
  5557. n (mod n 100)))
  5558. (setq sd
  5559. (calendar-absolute-from-iso
  5560. (list n 1
  5561. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5562. (setq nd 7)))
  5563. ((eq span 'month)
  5564. (when (and n (> n 99))
  5565. (setq y1 (org-small-year-to-year (/ n 100))
  5566. n (mod n 100)))
  5567. (setq sd (calendar-absolute-from-gregorian
  5568. (list (or n mg) 1 (or y1 yg)))
  5569. nd (- (calendar-absolute-from-gregorian
  5570. (list (1+ (or n mg)) 1 (or y1 yg)))
  5571. sd)))
  5572. ((eq span 'year)
  5573. (setq sd (calendar-absolute-from-gregorian
  5574. (list 1 1 (or n yg)))
  5575. nd (- (calendar-absolute-from-gregorian
  5576. (list 1 1 (1+ (or n yg))))
  5577. sd))))
  5578. (cons sd nd)))
  5579. (defun org-agenda-next-date-line (&optional arg)
  5580. "Jump to the next line indicating a date in agenda buffer."
  5581. (interactive "p")
  5582. (org-agenda-check-type t 'agenda 'timeline)
  5583. (beginning-of-line 1)
  5584. ;; This does not work if user makes date format that starts with a blank
  5585. (if (looking-at "^\\S-") (forward-char 1))
  5586. (if (not (re-search-forward "^\\S-" nil t arg))
  5587. (progn
  5588. (backward-char 1)
  5589. (error "No next date after this line in this buffer")))
  5590. (goto-char (match-beginning 0)))
  5591. (defun org-agenda-previous-date-line (&optional arg)
  5592. "Jump to the previous line indicating a date in agenda buffer."
  5593. (interactive "p")
  5594. (org-agenda-check-type t 'agenda 'timeline)
  5595. (beginning-of-line 1)
  5596. (if (not (re-search-backward "^\\S-" nil t arg))
  5597. (error "No previous date before this line in this buffer")))
  5598. ;; Initialize the highlight
  5599. (defvar org-hl (make-overlay 1 1))
  5600. (overlay-put org-hl 'face 'highlight)
  5601. (defun org-highlight (begin end &optional buffer)
  5602. "Highlight a region with overlay."
  5603. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5604. (defun org-unhighlight ()
  5605. "Detach overlay INDEX."
  5606. (org-detach-overlay org-hl))
  5607. ;; FIXME this is currently not used.
  5608. (defun org-highlight-until-next-command (beg end &optional buffer)
  5609. "Move the highlight overlay to BEG/END, remove it before the next command."
  5610. (org-highlight beg end buffer)
  5611. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5612. (defun org-unhighlight-once ()
  5613. "Remove the highlight from its position, and this function from the hook."
  5614. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5615. (org-unhighlight))
  5616. (defun org-agenda-follow-mode ()
  5617. "Toggle follow mode in an agenda buffer."
  5618. (interactive)
  5619. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5620. (org-agenda-set-mode-name)
  5621. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5622. (org-agenda-show))
  5623. (message "Follow mode is %s"
  5624. (if org-agenda-follow-mode "on" "off")))
  5625. (defun org-agenda-entry-text-mode (&optional arg)
  5626. "Toggle entry text mode in an agenda buffer."
  5627. (interactive "P")
  5628. (setq org-agenda-entry-text-mode (or (integerp arg)
  5629. (not org-agenda-entry-text-mode)))
  5630. (org-agenda-entry-text-hide)
  5631. (and org-agenda-entry-text-mode
  5632. (let ((org-agenda-entry-text-maxlines
  5633. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5634. (org-agenda-entry-text-show)))
  5635. (org-agenda-set-mode-name)
  5636. (message "Entry text mode is %s. Maximum number of lines is %d"
  5637. (if org-agenda-entry-text-mode "on" "off")
  5638. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5639. (defun org-agenda-clockreport-mode ()
  5640. "Toggle clocktable mode in an agenda buffer."
  5641. (interactive)
  5642. (org-agenda-check-type t 'agenda)
  5643. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5644. (org-agenda-set-mode-name)
  5645. (org-agenda-redo)
  5646. (message "Clocktable mode is %s"
  5647. (if org-agenda-clockreport-mode "on" "off")))
  5648. (defun org-agenda-log-mode (&optional special)
  5649. "Toggle log mode in an agenda buffer.
  5650. With argument SPECIAL, show all possible log items, not only the ones
  5651. configured in `org-agenda-log-mode-items'.
  5652. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5653. (interactive "P")
  5654. (org-agenda-check-type t 'agenda 'timeline)
  5655. (setq org-agenda-show-log
  5656. (if (equal special '(16))
  5657. 'only
  5658. (if special '(closed clock state)
  5659. (not org-agenda-show-log))))
  5660. (org-agenda-set-mode-name)
  5661. (org-agenda-redo)
  5662. (message "Log mode is %s"
  5663. (if org-agenda-show-log "on" "off")))
  5664. (defun org-agenda-archives-mode (&optional with-files)
  5665. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5666. When called with a prefix argument, include all archive files as well."
  5667. (interactive "P")
  5668. (setq org-agenda-archives-mode
  5669. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5670. (org-agenda-set-mode-name)
  5671. (org-agenda-redo)
  5672. (message
  5673. "%s"
  5674. (cond
  5675. ((eq org-agenda-archives-mode nil)
  5676. "No archives are included")
  5677. ((eq org-agenda-archives-mode 'trees)
  5678. (format "Trees with :%s: tag are included" org-archive-tag))
  5679. ((eq org-agenda-archives-mode t)
  5680. (format "Trees with :%s: tag and all active archive files are included"
  5681. org-archive-tag)))))
  5682. (defun org-agenda-toggle-diary ()
  5683. "Toggle diary inclusion in an agenda buffer."
  5684. (interactive)
  5685. (org-agenda-check-type t 'agenda)
  5686. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5687. (org-agenda-redo)
  5688. (org-agenda-set-mode-name)
  5689. (message "Diary inclusion turned %s"
  5690. (if org-agenda-include-diary "on" "off")))
  5691. (defun org-agenda-toggle-deadlines ()
  5692. "Toggle diary inclusion in an agenda buffer."
  5693. (interactive)
  5694. (org-agenda-check-type t 'agenda)
  5695. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5696. (org-agenda-redo)
  5697. (org-agenda-set-mode-name)
  5698. (message "Deadlines inclusion turned %s"
  5699. (if org-agenda-include-deadlines "on" "off")))
  5700. (defun org-agenda-toggle-time-grid ()
  5701. "Toggle time grid in an agenda buffer."
  5702. (interactive)
  5703. (org-agenda-check-type t 'agenda)
  5704. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5705. (org-agenda-redo)
  5706. (org-agenda-set-mode-name)
  5707. (message "Time-grid turned %s"
  5708. (if org-agenda-use-time-grid "on" "off")))
  5709. (defun org-agenda-set-mode-name ()
  5710. "Set the mode name to indicate all the small mode settings."
  5711. (setq mode-name
  5712. (concat "Org-Agenda"
  5713. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5714. (if (equal org-agenda-ndays 1) " Day" "")
  5715. (if (equal org-agenda-ndays 7) " Week" "")
  5716. (if org-agenda-follow-mode " Follow" "")
  5717. (if org-agenda-entry-text-mode " ETxt" "")
  5718. (if org-agenda-include-diary " Diary" "")
  5719. (if org-agenda-include-deadlines " Ddl" "")
  5720. (if org-agenda-use-time-grid " Grid" "")
  5721. (if (and (boundp 'org-habit-show-habits)
  5722. org-habit-show-habits) " Habit" "")
  5723. (if (consp org-agenda-show-log) " LogAll"
  5724. (if org-agenda-show-log " Log" ""))
  5725. (if (or org-agenda-filter (get 'org-agenda-filter
  5726. :preset-filter))
  5727. (concat " {" (mapconcat
  5728. 'identity
  5729. (append (get 'org-agenda-filter
  5730. :preset-filter)
  5731. org-agenda-filter) "") "}")
  5732. "")
  5733. (if org-agenda-archives-mode
  5734. (if (eq org-agenda-archives-mode t)
  5735. " Archives"
  5736. (format " :%s:" org-archive-tag))
  5737. "")
  5738. (if org-agenda-clockreport-mode " Clock" "")))
  5739. (force-mode-line-update))
  5740. (defun org-agenda-post-command-hook ()
  5741. (setq org-agenda-type
  5742. (or (get-text-property (point) 'org-agenda-type)
  5743. (get-text-property (max (point-min) (1- (point)))
  5744. 'org-agenda-type))))
  5745. (defun org-agenda-next-line ()
  5746. "Move cursor to the next line, and show if follow mode is active."
  5747. (interactive)
  5748. (call-interactively 'next-line)
  5749. (org-agenda-do-context-action))
  5750. (defun org-agenda-previous-line ()
  5751. "Move cursor to the previous line, and show if follow-mode is active."
  5752. (interactive)
  5753. (call-interactively 'previous-line)
  5754. (org-agenda-do-context-action))
  5755. (defun org-agenda-do-context-action ()
  5756. "Show outline path and, maybe, follow mode window."
  5757. (let ((m (org-get-at-bol 'org-marker)))
  5758. (if (and org-agenda-follow-mode m)
  5759. (org-agenda-show))
  5760. (if (and m org-agenda-show-outline-path)
  5761. (org-with-point-at m
  5762. (org-display-outline-path t)))))
  5763. (defun org-agenda-show-priority ()
  5764. "Show the priority of the current item.
  5765. This priority is composed of the main priority given with the [#A] cookies,
  5766. and by additional input from the age of a schedules or deadline entry."
  5767. (interactive)
  5768. (let* ((pri (org-get-at-bol 'priority)))
  5769. (message "Priority is %d" (if pri pri -1000))))
  5770. (defun org-agenda-show-tags ()
  5771. "Show the tags applicable to the current item."
  5772. (interactive)
  5773. (let* ((tags (org-get-at-bol 'tags)))
  5774. (if tags
  5775. (message "Tags are :%s:"
  5776. (org-no-properties (mapconcat 'identity tags ":")))
  5777. (message "No tags associated with this line"))))
  5778. (defun org-agenda-goto (&optional highlight)
  5779. "Go to the Org-mode file which contains the item at point."
  5780. (interactive)
  5781. (let* ((marker (or (org-get-at-bol 'org-marker)
  5782. (org-agenda-error)))
  5783. (buffer (marker-buffer marker))
  5784. (pos (marker-position marker)))
  5785. (switch-to-buffer-other-window buffer)
  5786. (widen)
  5787. (push-mark)
  5788. (goto-char pos)
  5789. (when (org-mode-p)
  5790. (org-show-context 'agenda)
  5791. (save-excursion
  5792. (and (outline-next-heading)
  5793. (org-flag-heading nil)))) ; show the next heading
  5794. (recenter (/ (window-height) 2))
  5795. (run-hooks 'org-agenda-after-show-hook)
  5796. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5797. (defvar org-agenda-after-show-hook nil
  5798. "Normal hook run after an item has been shown from the agenda.
  5799. Point is in the buffer where the item originated.")
  5800. (defun org-agenda-kill ()
  5801. "Kill the entry or subtree belonging to the current agenda entry."
  5802. (interactive)
  5803. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5804. (let* ((marker (or (org-get-at-bol 'org-marker)
  5805. (org-agenda-error)))
  5806. (buffer (marker-buffer marker))
  5807. (pos (marker-position marker))
  5808. (type (org-get-at-bol 'type))
  5809. dbeg dend (n 0) conf)
  5810. (org-with-remote-undo buffer
  5811. (with-current-buffer buffer
  5812. (save-excursion
  5813. (goto-char pos)
  5814. (if (and (org-mode-p) (not (member type '("sexp"))))
  5815. (setq dbeg (progn (org-back-to-heading t) (point))
  5816. dend (org-end-of-subtree t t))
  5817. (setq dbeg (point-at-bol)
  5818. dend (min (point-max) (1+ (point-at-eol)))))
  5819. (goto-char dbeg)
  5820. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5821. (setq conf (or (eq t org-agenda-confirm-kill)
  5822. (and (numberp org-agenda-confirm-kill)
  5823. (> n org-agenda-confirm-kill))))
  5824. (and conf
  5825. (not (y-or-n-p
  5826. (format "Delete entry with %d lines in buffer \"%s\"? "
  5827. n (buffer-name buffer))))
  5828. (error "Abort"))
  5829. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5830. (with-current-buffer buffer (delete-region dbeg dend))
  5831. (message "Agenda item and source killed"))))
  5832. (defvar org-archive-default-command)
  5833. (defun org-agenda-archive-default ()
  5834. "Archive the entry or subtree belonging to the current agenda entry."
  5835. (interactive)
  5836. (require 'org-archive)
  5837. (org-agenda-archive-with org-archive-default-command))
  5838. (defun org-agenda-archive-default-with-confirmation ()
  5839. "Archive the entry or subtree belonging to the current agenda entry."
  5840. (interactive)
  5841. (require 'org-archive)
  5842. (org-agenda-archive-with org-archive-default-command 'confirm))
  5843. (defun org-agenda-archive ()
  5844. "Archive the entry or subtree belonging to the current agenda entry."
  5845. (interactive)
  5846. (org-agenda-archive-with 'org-archive-subtree))
  5847. (defun org-agenda-archive-to-archive-sibling ()
  5848. "Move the entry to the archive sibling."
  5849. (interactive)
  5850. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5851. (defun org-agenda-archive-with (cmd &optional confirm)
  5852. "Move the entry to the archive sibling."
  5853. (interactive)
  5854. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5855. (let* ((marker (or (org-get-at-bol 'org-marker)
  5856. (org-agenda-error)))
  5857. (buffer (marker-buffer marker))
  5858. (pos (marker-position marker)))
  5859. (org-with-remote-undo buffer
  5860. (with-current-buffer buffer
  5861. (if (org-mode-p)
  5862. (if (and confirm
  5863. (not (y-or-n-p "Archive this subtree or entry? ")))
  5864. (error "Abort")
  5865. (save-excursion
  5866. (goto-char pos)
  5867. (org-remove-subtree-entries-from-agenda)
  5868. (org-back-to-heading t)
  5869. (funcall cmd)))
  5870. (error "Archiving works only in Org-mode files"))))))
  5871. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5872. "Remove all lines in the agenda that correspond to a given subtree.
  5873. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5874. If this information is not given, the function uses the tree at point."
  5875. (let ((buf (or buf (current-buffer))) m p)
  5876. (save-excursion
  5877. (unless (and beg end)
  5878. (org-back-to-heading t)
  5879. (setq beg (point))
  5880. (org-end-of-subtree t)
  5881. (setq end (point)))
  5882. (set-buffer (get-buffer org-agenda-buffer-name))
  5883. (save-excursion
  5884. (goto-char (point-max))
  5885. (beginning-of-line 1)
  5886. (while (not (bobp))
  5887. (when (and (setq m (org-get-at-bol 'org-marker))
  5888. (equal buf (marker-buffer m))
  5889. (setq p (marker-position m))
  5890. (>= p beg)
  5891. (< p end))
  5892. (let ((inhibit-read-only t))
  5893. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5894. (beginning-of-line 0))))))
  5895. (defun org-agenda-refile (&optional goto rfloc no-update)
  5896. "Refile the item at point."
  5897. (interactive "P")
  5898. (if (equal goto '(16))
  5899. (org-refile-goto-last-stored)
  5900. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5901. (org-agenda-error)))
  5902. (buffer (marker-buffer marker))
  5903. (pos (marker-position marker))
  5904. (rfloc (or rfloc
  5905. (org-refile-get-location
  5906. (if goto "Goto: " "Refile to: ") buffer
  5907. org-refile-allow-creating-parent-nodes))))
  5908. (with-current-buffer buffer
  5909. (save-excursion
  5910. (save-restriction
  5911. (widen)
  5912. (goto-char marker)
  5913. (org-remove-subtree-entries-from-agenda)
  5914. (org-refile goto buffer rfloc)))))
  5915. (unless no-update (org-agenda-redo))))
  5916. (defun org-agenda-open-link (&optional arg)
  5917. "Follow the link in the current line, if any.
  5918. This looks for a link in the displayed line in the agenda. It also looks
  5919. at the text of the entry itself."
  5920. (interactive "P")
  5921. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5922. (org-get-at-bol 'org-marker)))
  5923. (buffer (and marker (marker-buffer marker)))
  5924. (prefix (buffer-substring
  5925. (point-at-bol)
  5926. (+ (point-at-bol)
  5927. (or (org-get-at-bol 'prefix-length) 0)))))
  5928. (cond
  5929. (buffer
  5930. (with-current-buffer buffer
  5931. (save-excursion
  5932. (save-restriction
  5933. (widen)
  5934. (goto-char marker)
  5935. (org-offer-links-in-entry arg prefix)))))
  5936. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5937. (save-excursion
  5938. (beginning-of-line 1)
  5939. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5940. (org-open-link-from-string (match-string 1)))
  5941. (t (error "No link to open here")))))
  5942. (defun org-agenda-copy-local-variable (var)
  5943. "Get a variable from a referenced buffer and install it here."
  5944. (let ((m (org-get-at-bol 'org-marker)))
  5945. (when (and m (buffer-live-p (marker-buffer m)))
  5946. (org-set-local var (with-current-buffer (marker-buffer m)
  5947. (symbol-value var))))))
  5948. (defun org-agenda-switch-to (&optional delete-other-windows)
  5949. "Go to the Org-mode file which contains the item at point."
  5950. (interactive)
  5951. (if (and org-return-follows-link
  5952. (not (org-get-at-bol 'org-marker))
  5953. (org-in-regexp org-bracket-link-regexp))
  5954. (org-open-link-from-string (match-string 0))
  5955. (let* ((marker (or (org-get-at-bol 'org-marker)
  5956. (org-agenda-error)))
  5957. (buffer (marker-buffer marker))
  5958. (pos (marker-position marker)))
  5959. (switch-to-buffer buffer)
  5960. (and delete-other-windows (delete-other-windows))
  5961. (widen)
  5962. (goto-char pos)
  5963. (when (org-mode-p)
  5964. (org-show-context 'agenda)
  5965. (save-excursion
  5966. (and (outline-next-heading)
  5967. (org-flag-heading nil))))))) ; show the next heading
  5968. (defun org-agenda-goto-mouse (ev)
  5969. "Go to the Org-mode file which contains the item at the mouse click."
  5970. (interactive "e")
  5971. (mouse-set-point ev)
  5972. (org-agenda-goto))
  5973. (defun org-agenda-show (&optional full-entry)
  5974. "Display the Org-mode file which contains the item at point.
  5975. With prefix argument FULL-ENTRY, make the entire entry visible
  5976. if it was hidden in the outline."
  5977. (interactive "P")
  5978. (let ((win (selected-window)))
  5979. (if full-entry
  5980. (let ((org-show-entry-below t))
  5981. (org-agenda-goto t))
  5982. (org-agenda-goto t))
  5983. (select-window win)))
  5984. (defvar org-agenda-show-window nil)
  5985. (defun org-agenda-show-and-scroll-up ()
  5986. "Display the Org-mode file which contains the item at point.
  5987. When called repeatedly, scroll the window that is displaying the buffer."
  5988. (interactive)
  5989. (let ((win (selected-window)))
  5990. (if (and (window-live-p org-agenda-show-window)
  5991. (eq this-command last-command))
  5992. (progn
  5993. (select-window org-agenda-show-window)
  5994. (ignore-errors (scroll-up)))
  5995. (org-agenda-goto t)
  5996. (show-subtree)
  5997. (setq org-agenda-show-window (selected-window)))
  5998. (select-window win)))
  5999. (defun org-agenda-show-scroll-down ()
  6000. "Scroll down the window showing the agenda."
  6001. (interactive)
  6002. (let ((win (selected-window)))
  6003. (when (window-live-p org-agenda-show-window)
  6004. (select-window org-agenda-show-window)
  6005. (ignore-errors (scroll-down))
  6006. (select-window win))))
  6007. (defun org-agenda-show-1 (&optional more)
  6008. "Display the Org-mode file which contains the item at point.
  6009. The prefix arg selects the amount of information to display:
  6010. 0 hide the subtree
  6011. 1 just show the entry according to defaults.
  6012. 2 show the children view
  6013. 3 show the subtree view
  6014. 4 show the entire subtree and any LOGBOOK drawers
  6015. 5 show the entire subtree and any drawers
  6016. With prefix argument FULL-ENTRY, make the entire entry visible
  6017. if it was hidden in the outline."
  6018. (interactive "p")
  6019. (let ((win (selected-window)))
  6020. (org-agenda-goto t)
  6021. (org-recenter-heading 1)
  6022. (cond
  6023. ((= more 0)
  6024. (hide-subtree)
  6025. (save-excursion
  6026. (org-back-to-heading)
  6027. (run-hook-with-args 'org-cycle-hook 'folded))
  6028. (message "Remote: FOLDED"))
  6029. ((and (interactive-p) (= more 1))
  6030. (message "Remote: show with default settings"))
  6031. ((= more 2)
  6032. (show-entry)
  6033. (show-children)
  6034. (save-excursion
  6035. (org-back-to-heading)
  6036. (run-hook-with-args 'org-cycle-hook 'children))
  6037. (message "Remote: CHILDREN"))
  6038. ((= more 3)
  6039. (show-subtree)
  6040. (save-excursion
  6041. (org-back-to-heading)
  6042. (run-hook-with-args 'org-cycle-hook 'subtree))
  6043. (message "Remote: SUBTREE"))
  6044. ((= more 4)
  6045. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6046. (org-drawer-regexp
  6047. (concat "^[ \t]*:\\("
  6048. (mapconcat 'regexp-quote org-drawers "\\|")
  6049. "\\):[ \t]*$")))
  6050. (show-subtree)
  6051. (save-excursion
  6052. (org-back-to-heading)
  6053. (org-cycle-hide-drawers 'subtree)))
  6054. (message "Remote: SUBTREE AND LOGBOOK"))
  6055. ((> more 4)
  6056. (show-subtree)
  6057. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6058. (select-window win)))
  6059. (defun org-recenter-heading (n)
  6060. (save-excursion
  6061. (org-back-to-heading)
  6062. (recenter n)))
  6063. (defvar org-agenda-cycle-counter nil)
  6064. (defun org-agenda-cycle-show (&optional n)
  6065. "Show the current entry in another window, with default settings.
  6066. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6067. When use repeatedly in immediate succession, the remote entry will cycle
  6068. through visibility
  6069. children -> subtree -> folded
  6070. When called with a numeric prefix arg, that arg will be passed through to
  6071. `org-agenda-show-1'. For the interpretation of that argument, see the
  6072. docstring of `org-agenda-show-1'."
  6073. (interactive "P")
  6074. (if (integerp n)
  6075. (setq org-agenda-cycle-counter n)
  6076. (if (not (eq last-command this-command))
  6077. (setq org-agenda-cycle-counter 1)
  6078. (if (equal org-agenda-cycle-counter 0)
  6079. (setq org-agenda-cycle-counter 2)
  6080. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6081. (if (> org-agenda-cycle-counter 3)
  6082. (setq org-agenda-cycle-counter 0)))))
  6083. (org-agenda-show-1 org-agenda-cycle-counter))
  6084. (defun org-agenda-recenter (arg)
  6085. "Display the Org-mode file which contains the item at point and recenter."
  6086. (interactive "P")
  6087. (let ((win (selected-window)))
  6088. (org-agenda-goto t)
  6089. (recenter arg)
  6090. (select-window win)))
  6091. (defun org-agenda-show-mouse (ev)
  6092. "Display the Org-mode file which contains the item at the mouse click."
  6093. (interactive "e")
  6094. (mouse-set-point ev)
  6095. (org-agenda-show))
  6096. (defun org-agenda-check-no-diary ()
  6097. "Check if the entry is a diary link and abort if yes."
  6098. (if (org-get-at-bol 'org-agenda-diary-link)
  6099. (org-agenda-error)))
  6100. (defun org-agenda-error ()
  6101. (error "Command not allowed in this line"))
  6102. (defun org-agenda-tree-to-indirect-buffer ()
  6103. "Show the subtree corresponding to the current entry in an indirect buffer.
  6104. This calls the command `org-tree-to-indirect-buffer' from the original
  6105. Org-mode buffer.
  6106. With numerical prefix arg ARG, go up to this level and then take that tree.
  6107. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6108. use the dedicated frame)."
  6109. (interactive)
  6110. (org-agenda-check-no-diary)
  6111. (let* ((marker (or (org-get-at-bol 'org-marker)
  6112. (org-agenda-error)))
  6113. (buffer (marker-buffer marker))
  6114. (pos (marker-position marker)))
  6115. (with-current-buffer buffer
  6116. (save-excursion
  6117. (goto-char pos)
  6118. (call-interactively 'org-tree-to-indirect-buffer)))))
  6119. (defvar org-last-heading-marker (make-marker)
  6120. "Marker pointing to the headline that last changed its TODO state
  6121. by a remote command from the agenda.")
  6122. (defun org-agenda-todo-nextset ()
  6123. "Switch TODO entry to next sequence."
  6124. (interactive)
  6125. (org-agenda-todo 'nextset))
  6126. (defun org-agenda-todo-previousset ()
  6127. "Switch TODO entry to previous sequence."
  6128. (interactive)
  6129. (org-agenda-todo 'previousset))
  6130. (defun org-agenda-todo (&optional arg)
  6131. "Cycle TODO state of line at point, also in Org-mode file.
  6132. This changes the line at point, all other lines in the agenda referring to
  6133. the same tree node, and the headline of the tree node in the Org-mode file."
  6134. (interactive "P")
  6135. (org-agenda-check-no-diary)
  6136. (let* ((col (current-column))
  6137. (marker (or (org-get-at-bol 'org-marker)
  6138. (org-agenda-error)))
  6139. (buffer (marker-buffer marker))
  6140. (pos (marker-position marker))
  6141. (hdmarker (org-get-at-bol 'org-hd-marker))
  6142. (todayp (equal (org-get-at-bol 'day)
  6143. (time-to-days (current-time))))
  6144. (inhibit-read-only t)
  6145. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6146. (org-with-remote-undo buffer
  6147. (with-current-buffer buffer
  6148. (widen)
  6149. (goto-char pos)
  6150. (org-show-context 'agenda)
  6151. (save-excursion
  6152. (and (outline-next-heading)
  6153. (org-flag-heading nil))) ; show the next heading
  6154. (let ((current-prefix-arg arg))
  6155. (call-interactively 'org-todo))
  6156. (and (bolp) (forward-char 1))
  6157. (setq newhead (org-get-heading))
  6158. (when (and (org-bound-and-true-p
  6159. org-agenda-headline-snapshot-before-repeat)
  6160. (not (equal org-agenda-headline-snapshot-before-repeat
  6161. newhead))
  6162. todayp)
  6163. (setq newhead org-agenda-headline-snapshot-before-repeat
  6164. just-one t))
  6165. (save-excursion
  6166. (org-back-to-heading)
  6167. (move-marker org-last-heading-marker (point))))
  6168. (beginning-of-line 1)
  6169. (save-excursion
  6170. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6171. (org-move-to-column col))))
  6172. (defun org-agenda-add-note (&optional arg)
  6173. "Add a time-stamped note to the entry at point."
  6174. (interactive "P")
  6175. (org-agenda-check-no-diary)
  6176. (let* ((marker (or (org-get-at-bol 'org-marker)
  6177. (org-agenda-error)))
  6178. (buffer (marker-buffer marker))
  6179. (pos (marker-position marker))
  6180. (hdmarker (org-get-at-bol 'org-hd-marker))
  6181. (inhibit-read-only t))
  6182. (with-current-buffer buffer
  6183. (widen)
  6184. (goto-char pos)
  6185. (org-show-context 'agenda)
  6186. (save-excursion
  6187. (and (outline-next-heading)
  6188. (org-flag-heading nil))) ; show the next heading
  6189. (org-add-note))))
  6190. (defun org-agenda-change-all-lines (newhead hdmarker
  6191. &optional fixface just-this)
  6192. "Change all lines in the agenda buffer which match HDMARKER.
  6193. The new content of the line will be NEWHEAD (as modified by
  6194. `org-format-agenda-item'). HDMARKER is checked with
  6195. `equal' against all `org-hd-marker' text properties in the file.
  6196. If FIXFACE is non-nil, the face of each item is modified according to
  6197. the new TODO state.
  6198. If JUST-THIS is non-nil, change just the current line, not all.
  6199. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6200. (let* ((inhibit-read-only t)
  6201. (line (org-current-line))
  6202. (thetags (with-current-buffer (marker-buffer hdmarker)
  6203. (save-excursion (save-restriction (widen)
  6204. (goto-char hdmarker)
  6205. (org-get-tags-at)))))
  6206. props m pl undone-face done-face finish new dotime cat tags)
  6207. (save-excursion
  6208. (goto-char (point-max))
  6209. (beginning-of-line 1)
  6210. (while (not finish)
  6211. (setq finish (bobp))
  6212. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6213. (or (not just-this) (= (org-current-line) line))
  6214. (equal m hdmarker))
  6215. (setq props (text-properties-at (point))
  6216. dotime (org-get-at-bol 'dotime)
  6217. cat (org-get-at-bol 'org-category)
  6218. tags thetags
  6219. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6220. pl (org-get-at-bol 'prefix-length)
  6221. undone-face (org-get-at-bol 'undone-face)
  6222. done-face (org-get-at-bol 'done-face))
  6223. (goto-char (+ (point) pl))
  6224. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6225. (cond
  6226. ((equal new "")
  6227. (beginning-of-line 1)
  6228. (and (looking-at ".*\n?") (replace-match "")))
  6229. ((looking-at ".*")
  6230. (replace-match new t t)
  6231. (beginning-of-line 1)
  6232. (add-text-properties (point-at-bol) (point-at-eol) props)
  6233. (when fixface
  6234. (add-text-properties
  6235. (point-at-bol) (point-at-eol)
  6236. (list 'face
  6237. (if org-last-todo-state-is-todo
  6238. undone-face done-face))))
  6239. (org-agenda-highlight-todo 'line)
  6240. (beginning-of-line 1))
  6241. (t (error "Line update did not work"))))
  6242. (beginning-of-line 0)))
  6243. (org-finalize-agenda)))
  6244. (defun org-agenda-align-tags (&optional line)
  6245. "Align all tags in agenda items to `org-agenda-tags-column'."
  6246. (let ((inhibit-read-only t) l c)
  6247. (save-excursion
  6248. (goto-char (if line (point-at-bol) (point-min)))
  6249. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  6250. (if line (point-at-eol) nil) t)
  6251. (add-text-properties
  6252. (match-beginning 2) (match-end 2)
  6253. (list 'face (delq nil (let ((prop (get-text-property
  6254. (match-beginning 2) 'face)))
  6255. (or (listp prop) (setq prop (list prop)))
  6256. (if (memq 'org-tag prop)
  6257. prop
  6258. (cons 'org-tag prop))))))
  6259. (setq l (- (match-end 2) (match-beginning 2))
  6260. c (if (< org-agenda-tags-column 0)
  6261. (- (abs org-agenda-tags-column) l)
  6262. org-agenda-tags-column))
  6263. (delete-region (match-beginning 1) (match-end 1))
  6264. (goto-char (match-beginning 1))
  6265. (insert (org-add-props
  6266. (make-string (max 1 (- c (current-column))) ?\ )
  6267. (plist-put (copy-sequence (text-properties-at (point)))
  6268. 'face nil))))
  6269. (goto-char (point-min))
  6270. (org-font-lock-add-tag-faces (point-max)))))
  6271. (defun org-agenda-priority-up ()
  6272. "Increase the priority of line at point, also in Org-mode file."
  6273. (interactive)
  6274. (org-agenda-priority 'up))
  6275. (defun org-agenda-priority-down ()
  6276. "Decrease the priority of line at point, also in Org-mode file."
  6277. (interactive)
  6278. (org-agenda-priority 'down))
  6279. (defun org-agenda-priority (&optional force-direction)
  6280. "Set the priority of line at point, also in Org-mode file.
  6281. This changes the line at point, all other lines in the agenda referring to
  6282. the same tree node, and the headline of the tree node in the Org-mode file."
  6283. (interactive)
  6284. (unless org-enable-priority-commands
  6285. (error "Priority commands are disabled"))
  6286. (org-agenda-check-no-diary)
  6287. (let* ((marker (or (org-get-at-bol 'org-marker)
  6288. (org-agenda-error)))
  6289. (hdmarker (org-get-at-bol 'org-hd-marker))
  6290. (buffer (marker-buffer hdmarker))
  6291. (pos (marker-position hdmarker))
  6292. (inhibit-read-only t)
  6293. newhead)
  6294. (org-with-remote-undo buffer
  6295. (with-current-buffer buffer
  6296. (widen)
  6297. (goto-char pos)
  6298. (org-show-context 'agenda)
  6299. (save-excursion
  6300. (and (outline-next-heading)
  6301. (org-flag-heading nil))) ; show the next heading
  6302. (funcall 'org-priority force-direction)
  6303. (end-of-line 1)
  6304. (setq newhead (org-get-heading)))
  6305. (org-agenda-change-all-lines newhead hdmarker)
  6306. (beginning-of-line 1))))
  6307. ;; FIXME: should fix the tags property of the agenda line.
  6308. (defun org-agenda-set-tags (&optional tag onoff)
  6309. "Set tags for the current headline."
  6310. (interactive)
  6311. (org-agenda-check-no-diary)
  6312. (if (and (org-region-active-p) (interactive-p))
  6313. (call-interactively 'org-change-tag-in-region)
  6314. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6315. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6316. (org-agenda-error)))
  6317. (buffer (marker-buffer hdmarker))
  6318. (pos (marker-position hdmarker))
  6319. (inhibit-read-only t)
  6320. newhead)
  6321. (org-with-remote-undo buffer
  6322. (with-current-buffer buffer
  6323. (widen)
  6324. (goto-char pos)
  6325. (save-excursion
  6326. (org-show-context 'agenda))
  6327. (save-excursion
  6328. (and (outline-next-heading)
  6329. (org-flag-heading nil))) ; show the next heading
  6330. (goto-char pos)
  6331. (if tag
  6332. (org-toggle-tag tag onoff)
  6333. (call-interactively 'org-set-tags))
  6334. (end-of-line 1)
  6335. (setq newhead (org-get-heading)))
  6336. (org-agenda-change-all-lines newhead hdmarker)
  6337. (beginning-of-line 1)))))
  6338. (defun org-agenda-set-property ()
  6339. "Set a property for the current headline."
  6340. (interactive)
  6341. (org-agenda-check-no-diary)
  6342. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6343. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6344. (org-agenda-error)))
  6345. (buffer (marker-buffer hdmarker))
  6346. (pos (marker-position hdmarker))
  6347. (inhibit-read-only t)
  6348. newhead)
  6349. (org-with-remote-undo buffer
  6350. (with-current-buffer buffer
  6351. (widen)
  6352. (goto-char pos)
  6353. (save-excursion
  6354. (org-show-context 'agenda))
  6355. (save-excursion
  6356. (and (outline-next-heading)
  6357. (org-flag-heading nil))) ; show the next heading
  6358. (goto-char pos)
  6359. (call-interactively 'org-set-property)))))
  6360. (defun org-agenda-set-effort ()
  6361. "Set the effort property for the current headline."
  6362. (interactive)
  6363. (org-agenda-check-no-diary)
  6364. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6365. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6366. (org-agenda-error)))
  6367. (buffer (marker-buffer hdmarker))
  6368. (pos (marker-position hdmarker))
  6369. (inhibit-read-only t)
  6370. newhead)
  6371. (org-with-remote-undo buffer
  6372. (with-current-buffer buffer
  6373. (widen)
  6374. (goto-char pos)
  6375. (save-excursion
  6376. (org-show-context 'agenda))
  6377. (save-excursion
  6378. (and (outline-next-heading)
  6379. (org-flag-heading nil))) ; show the next heading
  6380. (goto-char pos)
  6381. (call-interactively 'org-set-effort)
  6382. (end-of-line 1)))))
  6383. (defun org-agenda-toggle-archive-tag ()
  6384. "Toggle the archive tag for the current entry."
  6385. (interactive)
  6386. (org-agenda-check-no-diary)
  6387. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6388. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6389. (org-agenda-error)))
  6390. (buffer (marker-buffer hdmarker))
  6391. (pos (marker-position hdmarker))
  6392. (inhibit-read-only t)
  6393. newhead)
  6394. (org-with-remote-undo buffer
  6395. (with-current-buffer buffer
  6396. (widen)
  6397. (goto-char pos)
  6398. (org-show-context 'agenda)
  6399. (save-excursion
  6400. (and (outline-next-heading)
  6401. (org-flag-heading nil))) ; show the next heading
  6402. (call-interactively 'org-toggle-archive-tag)
  6403. (end-of-line 1)
  6404. (setq newhead (org-get-heading)))
  6405. (org-agenda-change-all-lines newhead hdmarker)
  6406. (beginning-of-line 1))))
  6407. (defun org-agenda-do-date-later (arg)
  6408. (interactive "P")
  6409. (cond
  6410. ((or (equal arg '(16))
  6411. (memq last-command
  6412. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6413. (setq this-command 'org-agenda-date-later-minutes)
  6414. (org-agenda-date-later-minutes 1))
  6415. ((or (equal arg '(4))
  6416. (memq last-command
  6417. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6418. (setq this-command 'org-agenda-date-later-hours)
  6419. (org-agenda-date-later-hours 1))
  6420. (t
  6421. (org-agenda-date-later (prefix-numeric-value arg)))))
  6422. (defun org-agenda-do-date-earlier (arg)
  6423. (interactive "P")
  6424. (cond
  6425. ((or (equal arg '(16))
  6426. (memq last-command
  6427. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6428. (setq this-command 'org-agenda-date-earlier-minutes)
  6429. (org-agenda-date-earlier-minutes 1))
  6430. ((or (equal arg '(4))
  6431. (memq last-command
  6432. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6433. (setq this-command 'org-agenda-date-earlier-hours)
  6434. (org-agenda-date-earlier-hours 1))
  6435. (t
  6436. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6437. (defun org-agenda-date-later (arg &optional what)
  6438. "Change the date of this item to one day later."
  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))
  6451. (error "Cannot find time stamp"))
  6452. (org-timestamp-change arg (or what 'day)))
  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-date-earlier (arg &optional what)
  6456. "Change the date of this item to one day earlier."
  6457. (interactive "p")
  6458. (org-agenda-date-later (- arg) what))
  6459. (defun org-agenda-date-later-minutes (arg)
  6460. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6461. (interactive "p")
  6462. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6463. (org-agenda-date-later arg 'minute))
  6464. (defun org-agenda-date-earlier-minutes (arg)
  6465. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6466. (interactive "p")
  6467. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6468. (org-agenda-date-earlier arg 'minute))
  6469. (defun org-agenda-date-later-hours (arg)
  6470. "Change the time of this item, in hour steps."
  6471. (interactive "p")
  6472. (org-agenda-date-later arg 'hour))
  6473. (defun org-agenda-date-earlier-hours (arg)
  6474. "Change the time of this item, in hour steps."
  6475. (interactive "p")
  6476. (org-agenda-date-earlier arg 'hour))
  6477. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6478. "Show new date stamp via text properties."
  6479. ;; We use text properties to make this undoable
  6480. (let ((inhibit-read-only t)
  6481. (buffer-invisibility-spec))
  6482. (setq stamp (concat " " prefix " => " stamp))
  6483. (save-excursion
  6484. (goto-char (point-max))
  6485. (while (not (bobp))
  6486. (when (equal marker (org-get-at-bol 'org-marker))
  6487. (org-move-to-column (- (window-width) (length stamp)) t)
  6488. (org-agenda-fix-tags-filter-overlays-at (point))
  6489. (if (featurep 'xemacs)
  6490. ;; Use `duplicable' property to trigger undo recording
  6491. (let ((ex (make-extent nil nil))
  6492. (gl (make-glyph stamp)))
  6493. (set-glyph-face gl 'secondary-selection)
  6494. (set-extent-properties
  6495. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6496. (insert-extent ex (1- (point)) (point-at-eol)))
  6497. (add-text-properties
  6498. (1- (point)) (point-at-eol)
  6499. (list 'display (org-add-props stamp nil
  6500. 'face 'secondary-selection))))
  6501. (beginning-of-line 1))
  6502. (beginning-of-line 0)))))
  6503. (defun org-agenda-date-prompt (arg)
  6504. "Change the date of this item. Date is prompted for, with default today.
  6505. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6506. be used to request time specification in the time stamp."
  6507. (interactive "P")
  6508. (org-agenda-check-type t 'agenda 'timeline)
  6509. (org-agenda-check-no-diary)
  6510. (let* ((marker (or (org-get-at-bol 'org-marker)
  6511. (org-agenda-error)))
  6512. (buffer (marker-buffer marker))
  6513. (pos (marker-position marker)))
  6514. (org-with-remote-undo buffer
  6515. (with-current-buffer buffer
  6516. (widen)
  6517. (goto-char pos)
  6518. (if (not (org-at-timestamp-p t))
  6519. (error "Cannot find time stamp"))
  6520. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6521. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6522. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6523. (defun org-agenda-schedule (arg)
  6524. "Schedule the item at point.
  6525. Arg is passed through to `org-schedule'."
  6526. (interactive "P")
  6527. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6528. (org-agenda-check-no-diary)
  6529. (let* ((marker (or (org-get-at-bol 'org-marker)
  6530. (org-agenda-error)))
  6531. (type (marker-insertion-type marker))
  6532. (buffer (marker-buffer marker))
  6533. (pos (marker-position marker))
  6534. (org-insert-labeled-timestamps-at-point nil)
  6535. ts)
  6536. (set-marker-insertion-type marker t)
  6537. (org-with-remote-undo buffer
  6538. (with-current-buffer buffer
  6539. (widen)
  6540. (goto-char pos)
  6541. (setq ts (org-schedule arg)))
  6542. (org-agenda-show-new-time marker ts "S"))
  6543. (message "Item scheduled for %s" ts)))
  6544. (defun org-agenda-deadline (arg)
  6545. "Schedule the item at point.
  6546. Arg is passed through to `org-deadline'."
  6547. (interactive "P")
  6548. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6549. (org-agenda-check-no-diary)
  6550. (let* ((marker (or (org-get-at-bol 'org-marker)
  6551. (org-agenda-error)))
  6552. (buffer (marker-buffer marker))
  6553. (pos (marker-position marker))
  6554. (org-insert-labeled-timestamps-at-point nil)
  6555. ts)
  6556. (org-with-remote-undo buffer
  6557. (with-current-buffer buffer
  6558. (widen)
  6559. (goto-char pos)
  6560. (setq ts (org-deadline arg)))
  6561. (org-agenda-show-new-time marker ts "D"))
  6562. (message "Deadline for this item set to %s" ts)))
  6563. (defun org-agenda-action ()
  6564. "Select entry for agenda action, or execute an agenda action.
  6565. This command prompts for another letter. Valid inputs are:
  6566. m Mark the entry at point for an agenda action
  6567. s Schedule the marked entry to the date at the cursor
  6568. d Set the deadline of the marked entry to the date at the cursor
  6569. r Call `org-remember' with cursor date as the default date
  6570. c Call `org-capture' with cursor date as the default date
  6571. SPC Show marked entry in other window
  6572. TAB Visit marked entry in other window
  6573. The cursor may be at a date in the calendar, or in the Org agenda."
  6574. (interactive)
  6575. (let (ans)
  6576. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6577. (setq ans (read-char-exclusive))
  6578. (cond
  6579. ((equal ans ?m)
  6580. ;; Mark this entry
  6581. (if (eq major-mode 'org-agenda-mode)
  6582. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6583. (org-get-at-bol 'org-marker))))
  6584. (if m
  6585. (progn
  6586. (move-marker org-agenda-action-marker
  6587. (marker-position m) (marker-buffer m))
  6588. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6589. (error "Don't know which entry to mark")))
  6590. (error "This command works only in the agenda")))
  6591. ((equal ans ?s)
  6592. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6593. ((equal ans ?d)
  6594. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6595. ((equal ans ?r)
  6596. (org-agenda-do-action '(org-remember) t))
  6597. ((equal ans ?c)
  6598. (org-agenda-do-action '(org-capture) t))
  6599. ((equal ans ?\ )
  6600. (let ((cw (selected-window)))
  6601. (org-switch-to-buffer-other-window
  6602. (marker-buffer org-agenda-action-marker))
  6603. (goto-char org-agenda-action-marker)
  6604. (org-show-context 'agenda)
  6605. (select-window cw)))
  6606. ((equal ans ?\C-i)
  6607. (org-switch-to-buffer-other-window
  6608. (marker-buffer org-agenda-action-marker))
  6609. (goto-char org-agenda-action-marker)
  6610. (org-show-context 'agenda))
  6611. (t (error "Invalid agenda action %c" ans)))))
  6612. (defun org-agenda-do-action (form &optional current-buffer)
  6613. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6614. (let ((org-overriding-default-time (org-get-cursor-date)))
  6615. (if current-buffer
  6616. (eval form)
  6617. (if (not (marker-buffer org-agenda-action-marker))
  6618. (error "No entry has been selected for agenda action")
  6619. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6620. (save-excursion
  6621. (save-restriction
  6622. (widen)
  6623. (goto-char org-agenda-action-marker)
  6624. (eval form))))))))
  6625. (defun org-agenda-clock-in (&optional arg)
  6626. "Start the clock on the currently selected item."
  6627. (interactive "P")
  6628. (org-agenda-check-no-diary)
  6629. (if (equal arg '(4))
  6630. (org-clock-in arg)
  6631. (let* ((marker (or (org-get-at-bol 'org-marker)
  6632. (org-agenda-error)))
  6633. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6634. marker))
  6635. (pos (marker-position marker))
  6636. newhead)
  6637. (org-with-remote-undo (marker-buffer marker)
  6638. (with-current-buffer (marker-buffer marker)
  6639. (widen)
  6640. (goto-char pos)
  6641. (org-show-context 'agenda)
  6642. (org-show-entry)
  6643. (org-cycle-hide-drawers 'children)
  6644. (org-clock-in arg)
  6645. (setq newhead (org-get-heading)))
  6646. (org-agenda-change-all-lines newhead hdmarker)))))
  6647. (defun org-agenda-clock-out ()
  6648. "Stop the currently running clock."
  6649. (interactive "P")
  6650. (unless (marker-buffer org-clock-marker)
  6651. (error "No running clock"))
  6652. (let ((marker (make-marker)) newhead)
  6653. (org-with-remote-undo (marker-buffer org-clock-marker)
  6654. (with-current-buffer (marker-buffer org-clock-marker)
  6655. (save-excursion
  6656. (save-restriction
  6657. (widen)
  6658. (goto-char org-clock-marker)
  6659. (org-back-to-heading t)
  6660. (move-marker marker (point))
  6661. (org-clock-out)
  6662. (setq newhead (org-get-heading))))))
  6663. (org-agenda-change-all-lines newhead marker)
  6664. (move-marker marker nil)))
  6665. (defun org-agenda-clock-cancel (&optional arg)
  6666. "Cancel the currently running clock."
  6667. (interactive "P")
  6668. (unless (marker-buffer org-clock-marker)
  6669. (error "No running clock"))
  6670. (org-with-remote-undo (marker-buffer org-clock-marker)
  6671. (org-clock-cancel)))
  6672. (defun org-agenda-clock-goto ()
  6673. "Jump to the currently clocked in task within the agenda.
  6674. If the currently clocked in task is not listed in the agenda
  6675. buffer, display it in another window."
  6676. (interactive)
  6677. (let (pos)
  6678. (mapc (lambda (o)
  6679. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6680. (setq pos (overlay-start o))))
  6681. (overlays-in (point-min) (point-max)))
  6682. (cond (pos (goto-char pos))
  6683. ;; If the currently clocked entry is not in the agenda
  6684. ;; buffer, we visit it in another window:
  6685. (org-clock-current-task
  6686. (org-switch-to-buffer-other-window (org-clock-goto)))
  6687. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6688. (defun org-agenda-diary-entry-in-org-file ()
  6689. "Make a diary entry in the file `org-agenda-diary-file'."
  6690. (let (d1 d2 char (text "") dp1 dp2)
  6691. (if (equal (buffer-name) "*Calendar*")
  6692. (setq d1 (calendar-cursor-to-date t)
  6693. d2 (car calendar-mark-ring))
  6694. (setq dp1 (get-text-property (point-at-bol) 'day))
  6695. (unless dp1 (error "No date defined in current line"))
  6696. (setq d1 (calendar-gregorian-from-absolute dp1)
  6697. d2 (and (ignore-errors (mark))
  6698. (save-excursion
  6699. (goto-char (mark))
  6700. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6701. (calendar-gregorian-from-absolute dp2))))
  6702. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6703. (setq char (read-char-exclusive))
  6704. (cond
  6705. ((equal char ?d)
  6706. (setq text (read-string "Day entry: "))
  6707. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6708. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6709. ((equal char ?a)
  6710. (setq d1 (list (car d1) (nth 1 d1)
  6711. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6712. (nth 2 d1))))
  6713. (setq text (read-string "Anniversary (use %d to show years): "))
  6714. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6715. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6716. ((equal char ?b)
  6717. (setq text (read-string "Block entry: "))
  6718. (unless (and d1 d2 (not (equal d1 d2)))
  6719. (error "No block of days selected"))
  6720. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6721. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6722. ((equal char ?j)
  6723. (org-switch-to-buffer-other-window
  6724. (find-file-noselect org-agenda-diary-file))
  6725. (require 'org-datetree)
  6726. (org-datetree-find-date-create d1)
  6727. (org-reveal t))
  6728. (t (error "Invalid selection character `%c'" char)))))
  6729. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6730. "Where in `org-agenda-diary-file' should new entries be added?
  6731. Valid values:
  6732. date-tree in the date tree, as child of the date
  6733. top-level as top-level entries at the end of the file."
  6734. :group 'org-agenda
  6735. :type '(choice
  6736. (const :tag "in a date tree" date-tree)
  6737. (const :tag "as top level at end of file" top-level)))
  6738. (defcustom org-agenda-insert-diary-extract-time nil
  6739. "Non-nil means extract any time specification from the diary entry."
  6740. :group 'org-agenda
  6741. :type 'boolean)
  6742. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6743. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6744. If TEXT is not empty, it will become the headline of the new entry, and
  6745. the resulting entry will not be shown. When TEXT is empty, switch to
  6746. `org-agenda-diary-file' and let the user finish the entry there."
  6747. (let ((cw (current-window-configuration)))
  6748. (org-switch-to-buffer-other-window
  6749. (find-file-noselect org-agenda-diary-file))
  6750. (widen)
  6751. (goto-char (point-min))
  6752. (cond
  6753. ((eq type 'anniversary)
  6754. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6755. (progn
  6756. (or (org-on-heading-p t)
  6757. (progn
  6758. (outline-next-heading)
  6759. (insert "* Anniversaries\n\n")
  6760. (beginning-of-line -1)))))
  6761. (outline-next-heading)
  6762. (org-back-over-empty-lines)
  6763. (backward-char 1)
  6764. (insert "\n")
  6765. (require 'diary-lib)
  6766. (let ((calendar-date-display-form
  6767. (if (if (boundp 'calendar-date-style)
  6768. (eq calendar-date-style 'european)
  6769. (org-bound-and-true-p european-calendar-style)) ; Emacs 22
  6770. '(day " " month " " year)
  6771. '(month " " day " " year))))
  6772. (insert (format "%%%%(diary-anniversary %s) %s"
  6773. (calendar-date-string d1 nil t) text))))
  6774. ((eq type 'day)
  6775. (let ((org-prefix-has-time t)
  6776. (org-agenda-time-leading-zero t)
  6777. fmt time time2)
  6778. (if org-agenda-insert-diary-extract-time
  6779. ;; Use org-format-agenda-item to parse text for a time-range and
  6780. ;; remove it. FIXME: This is a hack, we should refactor
  6781. ;; that function to make time extraction available separately
  6782. (setq fmt (org-format-agenda-item nil text nil nil t)
  6783. time (get-text-property 0 'time fmt)
  6784. time2 (if (> (length time) 0)
  6785. ;; split-string removes trailing ...... if
  6786. ;; no end time given. First space
  6787. ;; separates time from date.
  6788. (concat " " (car (split-string time "\\.")))
  6789. nil)
  6790. text (get-text-property 0 'txt fmt)))
  6791. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6792. (org-agenda-insert-diary-as-top-level text)
  6793. (require 'org-datetree)
  6794. (org-datetree-find-date-create d1)
  6795. (org-agenda-insert-diary-make-new-entry text))
  6796. (org-insert-time-stamp (org-time-from-absolute
  6797. (calendar-absolute-from-gregorian d1))
  6798. nil nil nil nil time2))
  6799. (end-of-line 0))
  6800. ((eq type 'block)
  6801. (if (> (calendar-absolute-from-gregorian d1)
  6802. (calendar-absolute-from-gregorian d2))
  6803. (setq d1 (prog1 d2 (setq d2 d1))))
  6804. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6805. (org-agenda-insert-diary-as-top-level text)
  6806. (require 'org-datetree)
  6807. (org-datetree-find-date-create d1)
  6808. (org-agenda-insert-diary-make-new-entry text))
  6809. (org-insert-time-stamp (org-time-from-absolute
  6810. (calendar-absolute-from-gregorian d1)))
  6811. (insert "--")
  6812. (org-insert-time-stamp (org-time-from-absolute
  6813. (calendar-absolute-from-gregorian d2)))
  6814. (end-of-line 0)))
  6815. (if (string-match "\\S-" text)
  6816. (progn
  6817. (set-window-configuration cw)
  6818. (message "%s entry added to %s"
  6819. (capitalize (symbol-name type))
  6820. (abbreviate-file-name org-agenda-diary-file)))
  6821. (org-reveal t)
  6822. (message "Please finish entry here"))))
  6823. (defun org-agenda-insert-diary-as-top-level (text)
  6824. "Make new entry as a top-level entry at the end of the file.
  6825. Add TEXT as headline, and position the cursor in the second line so that
  6826. a timestamp can be added there."
  6827. (widen)
  6828. (goto-char (point-max))
  6829. (or (bolp) (insert "\n"))
  6830. (insert "* " text "\n")
  6831. (if org-adapt-indentation (org-indent-to-column 2)))
  6832. (defun org-agenda-insert-diary-make-new-entry (text)
  6833. "Make new entry as last child of current entry.
  6834. Add TEXT as headline, and position the cursor in the second line so that
  6835. a timestamp can be added there."
  6836. (let ((org-show-following-heading t)
  6837. (org-show-siblings t)
  6838. (org-show-hierarchy-above t)
  6839. (org-show-entry-below t)
  6840. col)
  6841. (outline-next-heading)
  6842. (org-back-over-empty-lines)
  6843. (or (looking-at "[ \t]*$")
  6844. (progn (insert "\n") (backward-char 1)))
  6845. (org-insert-heading nil t)
  6846. (org-do-demote)
  6847. (setq col (current-column))
  6848. (insert text "\n")
  6849. (if org-adapt-indentation (org-indent-to-column col))
  6850. (let ((org-show-following-heading t)
  6851. (org-show-siblings t)
  6852. (org-show-hierarchy-above t)
  6853. (org-show-entry-below t))
  6854. (org-show-context))))
  6855. (defun org-agenda-diary-entry ()
  6856. "Make a diary entry, like the `i' command from the calendar.
  6857. All the standard commands work: block, weekly etc.
  6858. When `org-agenda-diary-file' points to a file,
  6859. `org-agenda-diary-entry-in-org-file' is called instead to create
  6860. entries in that Org-mode file."
  6861. (interactive)
  6862. (org-agenda-check-type t 'agenda 'timeline)
  6863. (if (not (eq org-agenda-diary-file 'diary-file))
  6864. (org-agenda-diary-entry-in-org-file)
  6865. (require 'diary-lib)
  6866. (let* ((char (progn
  6867. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6868. (read-char-exclusive)))
  6869. (cmd (cdr (assoc char
  6870. '((?d . insert-diary-entry)
  6871. (?w . insert-weekly-diary-entry)
  6872. (?m . insert-monthly-diary-entry)
  6873. (?y . insert-yearly-diary-entry)
  6874. (?a . insert-anniversary-diary-entry)
  6875. (?b . insert-block-diary-entry)
  6876. (?c . insert-cyclic-diary-entry)))))
  6877. (oldf (symbol-function 'calendar-cursor-to-date))
  6878. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6879. (point (point))
  6880. (mark (or (mark t) (point))))
  6881. (unless cmd
  6882. (error "No command associated with <%c>" char))
  6883. (unless (and (get-text-property point 'day)
  6884. (or (not (equal ?b char))
  6885. (get-text-property mark 'day)))
  6886. (error "Don't know which date to use for diary entry"))
  6887. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6888. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6889. (let ((calendar-mark-ring
  6890. (list (calendar-gregorian-from-absolute
  6891. (or (get-text-property mark 'day)
  6892. (get-text-property point 'day))))))
  6893. (unwind-protect
  6894. (progn
  6895. (fset 'calendar-cursor-to-date
  6896. (lambda (&optional error dummy)
  6897. (calendar-gregorian-from-absolute
  6898. (get-text-property point 'day))))
  6899. (call-interactively cmd))
  6900. (fset 'calendar-cursor-to-date oldf))))))
  6901. (defun org-agenda-execute-calendar-command (cmd)
  6902. "Execute a calendar command from the agenda, with the date associated to
  6903. the cursor position."
  6904. (org-agenda-check-type t 'agenda 'timeline)
  6905. (require 'diary-lib)
  6906. (unless (get-text-property (point) 'day)
  6907. (error "Don't know which date to use for calendar command"))
  6908. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6909. (point (point))
  6910. (date (calendar-gregorian-from-absolute
  6911. (get-text-property point 'day)))
  6912. ;; the following 2 vars are needed in the calendar
  6913. (displayed-month (car date))
  6914. (displayed-year (nth 2 date)))
  6915. (unwind-protect
  6916. (progn
  6917. (fset 'calendar-cursor-to-date
  6918. (lambda (&optional error dummy)
  6919. (calendar-gregorian-from-absolute
  6920. (get-text-property point 'day))))
  6921. (call-interactively cmd))
  6922. (fset 'calendar-cursor-to-date oldf))))
  6923. (defun org-agenda-phases-of-moon ()
  6924. "Display the phases of the moon for the 3 months around the cursor date."
  6925. (interactive)
  6926. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6927. (defun org-agenda-holidays ()
  6928. "Display the holidays for the 3 months around the cursor date."
  6929. (interactive)
  6930. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6931. (defvar calendar-longitude)
  6932. (defvar calendar-latitude)
  6933. (defvar calendar-location-name)
  6934. (defun org-agenda-sunrise-sunset (arg)
  6935. "Display sunrise and sunset for the cursor date.
  6936. Latitude and longitude can be specified with the variables
  6937. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6938. argument, latitude and longitude will be prompted for."
  6939. (interactive "P")
  6940. (require 'solar)
  6941. (let ((calendar-longitude (if arg nil calendar-longitude))
  6942. (calendar-latitude (if arg nil calendar-latitude))
  6943. (calendar-location-name
  6944. (if arg "the given coordinates" calendar-location-name)))
  6945. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6946. (defun org-agenda-goto-calendar ()
  6947. "Open the Emacs calendar with the date at the cursor."
  6948. (interactive)
  6949. (org-agenda-check-type t 'agenda 'timeline)
  6950. (let* ((day (or (get-text-property (point) 'day)
  6951. (error "Don't know which date to open in calendar")))
  6952. (date (calendar-gregorian-from-absolute day))
  6953. (calendar-move-hook nil)
  6954. (calendar-view-holidays-initially-flag nil)
  6955. (calendar-view-diary-initially-flag nil))
  6956. (calendar)
  6957. (calendar-goto-date date)))
  6958. ;;;###autoload
  6959. (defun org-calendar-goto-agenda ()
  6960. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6961. This is a command that has to be installed in `calendar-mode-map'."
  6962. (interactive)
  6963. (org-agenda-list nil (calendar-absolute-from-gregorian
  6964. (calendar-cursor-to-date))
  6965. nil))
  6966. (defun org-agenda-convert-date ()
  6967. (interactive)
  6968. (org-agenda-check-type t 'agenda 'timeline)
  6969. (let ((day (get-text-property (point) 'day))
  6970. date s)
  6971. (unless day
  6972. (error "Don't know which date to convert"))
  6973. (setq date (calendar-gregorian-from-absolute day))
  6974. (setq s (concat
  6975. "Gregorian: " (calendar-date-string date) "\n"
  6976. "ISO: " (calendar-iso-date-string date) "\n"
  6977. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6978. "Julian: " (calendar-julian-date-string date) "\n"
  6979. "Astron. JD: " (calendar-astro-date-string date)
  6980. " (Julian date number at noon UTC)\n"
  6981. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6982. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6983. "French: " (calendar-french-date-string date) "\n"
  6984. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6985. "Mayan: " (calendar-mayan-date-string date) "\n"
  6986. "Coptic: " (calendar-coptic-date-string date) "\n"
  6987. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6988. "Persian: " (calendar-persian-date-string date) "\n"
  6989. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6990. (with-output-to-temp-buffer "*Dates*"
  6991. (princ s))
  6992. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6993. ;;; Bulk commands
  6994. (defvar org-agenda-bulk-marked-entries nil
  6995. "List of markers that refer to marked entries in the agenda.")
  6996. (defun org-agenda-bulk-marked-p ()
  6997. (eq (get-char-property (point-at-bol) 'type)
  6998. 'org-marked-entry-overlay))
  6999. (defun org-agenda-bulk-mark ()
  7000. "Mark the entry at point for future bulk action."
  7001. (interactive)
  7002. (org-agenda-check-no-diary)
  7003. (let* ((m (org-get-at-bol 'org-hd-marker))
  7004. ov)
  7005. (unless (org-agenda-bulk-marked-p)
  7006. (unless m (error "Nothing to mark at point"))
  7007. (push m org-agenda-bulk-marked-entries)
  7008. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7009. (org-overlay-display ov "> "
  7010. (org-get-todo-face "TODO")
  7011. 'evaporate)
  7012. (overlay-put ov 'type 'org-marked-entry-overlay))
  7013. (beginning-of-line 2)
  7014. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7015. (beginning-of-line 2))
  7016. (message "%d entries marked for bulk action"
  7017. (length org-agenda-bulk-marked-entries))))
  7018. (defun org-agenda-bulk-unmark ()
  7019. "Unmark the entry at point for future bulk action."
  7020. (interactive)
  7021. (when (org-agenda-bulk-marked-p)
  7022. (org-agenda-bulk-remove-overlays
  7023. (point-at-bol) (+ 2 (point-at-bol)))
  7024. (setq org-agenda-bulk-marked-entries
  7025. (delete (org-get-at-bol 'org-hd-marker)
  7026. org-agenda-bulk-marked-entries)))
  7027. (beginning-of-line 2)
  7028. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7029. (beginning-of-line 2))
  7030. (message "%d entries marked for bulk action"
  7031. (length org-agenda-bulk-marked-entries)))
  7032. (defun org-agenda-bulk-toggle ()
  7033. "Toggle marking the entry at point for bulk action."
  7034. (interactive)
  7035. (if (org-agenda-bulk-marked-p)
  7036. (org-agenda-bulk-unmark)
  7037. (org-agenda-bulk-mark)))
  7038. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7039. "Remove the mark overlays between BEG and END in the agenda buffer.
  7040. BEG and END default to the buffer limits.
  7041. This only removes the overlays, it does not remove the markers
  7042. from the list in `org-agenda-bulk-marked-entries'."
  7043. (interactive)
  7044. (mapc (lambda (ov)
  7045. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7046. (delete-overlay ov)))
  7047. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7048. (defun org-agenda-bulk-remove-all-marks ()
  7049. "Remove all marks in the agenda buffer.
  7050. This will remove the markers, and the overlays."
  7051. (interactive)
  7052. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7053. (setq org-agenda-bulk-marked-entries nil)
  7054. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7055. (defun org-agenda-bulk-action (&optional arg)
  7056. "Execute an remote-editing action on all marked entries.
  7057. The prefix arg is passed through to the command if possible."
  7058. (interactive "P")
  7059. (unless org-agenda-bulk-marked-entries
  7060. (error "No entries are marked"))
  7061. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7062. (let* ((action (read-char-exclusive))
  7063. (org-log-refile (if org-log-refile 'time nil))
  7064. (entries (reverse org-agenda-bulk-marked-entries))
  7065. redo-at-end
  7066. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7067. (cond
  7068. ((equal action ?$)
  7069. (setq cmd '(org-agenda-archive)))
  7070. ((equal action ?A)
  7071. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7072. ((member action '(?r ?w))
  7073. (setq rfloc (org-refile-get-location
  7074. "Refile to: "
  7075. (marker-buffer (car org-agenda-bulk-marked-entries))
  7076. org-refile-allow-creating-parent-nodes))
  7077. (if (nth 3 rfloc)
  7078. (setcar (nthcdr 3 rfloc)
  7079. (move-marker (make-marker) (nth 3 rfloc)
  7080. (or (get-file-buffer (nth 1 rfloc))
  7081. (find-buffer-visiting (nth 1 rfloc))
  7082. (error "This should not happen")))))
  7083. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7084. redo-at-end t))
  7085. ((equal action ?t)
  7086. (setq state (org-icompleting-read
  7087. "Todo state: "
  7088. (with-current-buffer (marker-buffer (car entries))
  7089. (mapcar 'list org-todo-keywords-1))))
  7090. (setq cmd `(let ((org-inhibit-blocking t)
  7091. (org-inhibit-logging 'note))
  7092. (org-agenda-todo ,state))))
  7093. ((memq action '(?- ?+))
  7094. (setq tag (org-icompleting-read
  7095. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7096. (with-current-buffer (marker-buffer (car entries))
  7097. (delq nil
  7098. (mapcar (lambda (x)
  7099. (if (stringp (car x)) x)) org-tag-alist)))))
  7100. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7101. ((memq action '(?s ?d))
  7102. (let* ((date (unless arg
  7103. (org-read-date
  7104. nil nil nil
  7105. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7106. (ans (if arg nil org-read-date-final-answer))
  7107. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7108. (setq cmd `(let* ((bound (fboundp 'read-string))
  7109. (old (and bound (symbol-function 'read-string))))
  7110. (unwind-protect
  7111. (progn
  7112. (fset 'read-string (lambda (&rest ignore) ,ans))
  7113. (eval '(,c1 arg)))
  7114. (if bound
  7115. (fset 'read-string old)
  7116. (fmakunbound 'read-string)))))))
  7117. (t (error "Invalid bulk action")))
  7118. ;; Sort the markers, to make sure that parents are handled before children
  7119. (setq entries (sort entries
  7120. (lambda (a b)
  7121. (cond
  7122. ((equal (marker-buffer a) (marker-buffer b))
  7123. (< (marker-position a) (marker-position b)))
  7124. (t
  7125. (string< (buffer-name (marker-buffer a))
  7126. (buffer-name (marker-buffer b))))))))
  7127. ;; Now loop over all markers and apply cmd
  7128. (while (setq e (pop entries))
  7129. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7130. (if (not pos)
  7131. (progn (message "Skipping removed entry at %s" e)
  7132. (setq cntskip (1+ cntskip)))
  7133. (goto-char pos)
  7134. (eval cmd)
  7135. (setq org-agenda-bulk-marked-entries
  7136. (delete e org-agenda-bulk-marked-entries))
  7137. (setq cnt (1+ cnt))))
  7138. (setq org-agenda-bulk-marked-entries nil)
  7139. (org-agenda-bulk-remove-all-marks)
  7140. (when redo-at-end (org-agenda-redo))
  7141. (message "Acted on %d entries%s"
  7142. cnt
  7143. (if (= cntskip 0)
  7144. ""
  7145. (format ", skipped %d (disappeared before their turn)"
  7146. cntskip)))))
  7147. ;;; Flagging notes
  7148. (defun org-agenda-show-the-flagging-note ()
  7149. "Display the flagging note in the other window.
  7150. When called a second time in direct sequence, offer to remove the FLAGGING
  7151. tag and (if present) the flagging note."
  7152. (interactive)
  7153. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7154. (win (selected-window))
  7155. note heading newhead)
  7156. (unless hdmarker
  7157. (error "No linked entry at point"))
  7158. (if (and (eq this-command last-command)
  7159. (y-or-n-p "Unflag and remove any flagging note? "))
  7160. (progn
  7161. (org-agenda-remove-flag hdmarker)
  7162. (let ((win (get-buffer-window "*Flagging Note*")))
  7163. (and win (delete-window win)))
  7164. (message "Entry unflaged"))
  7165. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7166. (unless note
  7167. (error "No flagging note"))
  7168. (org-kill-new note)
  7169. (org-switch-to-buffer-other-window "*Flagging Note*")
  7170. (erase-buffer)
  7171. (insert note)
  7172. (goto-char (point-min))
  7173. (while (re-search-forward "\\\\n" nil t)
  7174. (replace-match "\n" t t))
  7175. (goto-char (point-min))
  7176. (select-window win)
  7177. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7178. (defun org-agenda-remove-flag (marker)
  7179. "Remove the FLAGGED tag and any flagging note in the entry."
  7180. (let (newhead)
  7181. (org-with-point-at marker
  7182. (org-toggle-tag "FLAGGED" 'off)
  7183. (org-entry-delete nil "THEFLAGGINGNOTE")
  7184. (setq newhead (org-get-heading)))
  7185. (org-agenda-change-all-lines newhead marker)
  7186. (message "Entry unflaged")))
  7187. (defun org-agenda-get-any-marker (&optional pos)
  7188. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7189. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7190. ;;; Appointment reminders
  7191. (defvar appt-time-msg-list)
  7192. ;;;###autoload
  7193. (defun org-agenda-to-appt (&optional refresh filter)
  7194. "Activate appointments found in `org-agenda-files'.
  7195. With a \\[universal-argument] prefix, refresh the list of
  7196. appointments.
  7197. If FILTER is t, interactively prompt the user for a regular
  7198. expression, and filter out entries that don't match it.
  7199. If FILTER is a string, use this string as a regular expression
  7200. for filtering entries out.
  7201. FILTER can also be an alist with the car of each cell being
  7202. either 'headline or 'category. For example:
  7203. '((headline \"IMPORTANT\")
  7204. (category \"Work\"))
  7205. will only add headlines containing IMPORTANT or headlines
  7206. belonging to the \"Work\" category."
  7207. (interactive "P")
  7208. (if refresh (setq appt-time-msg-list nil))
  7209. (if (eq filter t)
  7210. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7211. (let* ((cnt 0) ; count added events
  7212. (org-agenda-new-buffers nil)
  7213. (org-deadline-warning-days 0)
  7214. (today (org-date-to-gregorian
  7215. (time-to-days (current-time))))
  7216. (org-agenda-restrict nil)
  7217. (files (org-agenda-files 'unrestricted)) entries file)
  7218. ;; Get all entries which may contain an appt
  7219. (org-prepare-agenda-buffers files)
  7220. (while (setq file (pop files))
  7221. (setq entries
  7222. (append entries
  7223. (org-agenda-get-day-entries
  7224. file today :timestamp :scheduled :deadline))))
  7225. (setq entries (delq nil entries))
  7226. ;; Map thru entries and find if we should filter them out
  7227. (mapc
  7228. (lambda(x)
  7229. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7230. (cat (get-text-property 1 'org-category x))
  7231. (tod (get-text-property 1 'time-of-day x))
  7232. (ok (or (null filter)
  7233. (and (stringp filter) (string-match filter evt))
  7234. (and (listp filter)
  7235. (or (string-match
  7236. (cadr (assoc 'category filter)) cat)
  7237. (string-match
  7238. (cadr (assoc 'headline filter)) evt))))))
  7239. ;; FIXME: Shall we remove text-properties for the appt text?
  7240. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7241. (when (and ok tod)
  7242. (setq tod (concat "00" (number-to-string tod))
  7243. tod (when (string-match
  7244. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7245. (concat (match-string 1 tod) ":"
  7246. (match-string 2 tod))))
  7247. (appt-add tod evt)
  7248. (setq cnt (1+ cnt))))) entries)
  7249. (org-release-buffers org-agenda-new-buffers)
  7250. (if (eq cnt 0)
  7251. (message "No event to add")
  7252. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7253. (defun org-agenda-todayp (date)
  7254. "Does DATE mean today, when considering `org-extend-today-until'?"
  7255. (let (today h)
  7256. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7257. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7258. (setq h (nth 2 (decode-time (current-time))))
  7259. (or (and (>= h org-extend-today-until)
  7260. (= date today))
  7261. (and (< h org-extend-today-until)
  7262. (= date (1- today))))))
  7263. (provide 'org-agenda)
  7264. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7265. ;;; org-agenda.el ends here