org-agenda.el 356 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (defvar calendar-mode-map) ; defined in calendar.el
  78. (defvar org-clock-current-task) ; defined in org-clock.el
  79. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  80. (defvar org-habit-show-habits) ; defined in org-habit.el
  81. (defvar org-habit-show-habits-only-for-today)
  82. (defvar org-habit-show-all-today nil)
  83. ;; Defined somewhere in this file, but used before definition.
  84. (defvar org-agenda-buffer-name "*Org Agenda*")
  85. (defvar org-agenda-overriding-header nil)
  86. (defvar org-agenda-title-append nil)
  87. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  88. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defvar org-agenda-undo-list nil
  91. "List of undoable operations in the agenda since last refresh.")
  92. (defvar org-agenda-pending-undo-list nil
  93. "In a series of undo commands, this is the list of remaining undo items.")
  94. (defcustom org-agenda-confirm-kill 1
  95. "When set, remote killing from the agenda buffer needs confirmation.
  96. When t, a confirmation is always needed. When a number N, confirmation is
  97. only needed when the text to be killed contains more than N non-white lines."
  98. :group 'org-agenda
  99. :type '(choice
  100. (const :tag "Never" nil)
  101. (const :tag "Always" t)
  102. (integer :tag "When more than N lines")))
  103. (defcustom org-agenda-compact-blocks nil
  104. "Non-nil means make the block agenda more compact.
  105. This is done globally by leaving out lines like the agenda span
  106. name and week number or the separator lines."
  107. :group 'org-agenda
  108. :type 'boolean)
  109. (defcustom org-agenda-block-separator ?=
  110. "The separator between blocks in the agenda.
  111. If this is a string, it will be used as the separator, with a newline added.
  112. If it is a character, it will be repeated to fill the window width.
  113. If nil the separator is disabled. In `org-agenda-custom-commands' this
  114. addresses the separator between the current and the previous block."
  115. :group 'org-agenda
  116. :type '(choice
  117. (const :tag "Disabled" nil)
  118. (character)
  119. (string)))
  120. (defgroup org-agenda-export nil
  121. "Options concerning exporting agenda views in Org-mode."
  122. :tag "Org Agenda Export"
  123. :group 'org-agenda)
  124. (defcustom org-agenda-with-colors t
  125. "Non-nil means use colors in agenda views."
  126. :group 'org-agenda-export
  127. :type 'boolean)
  128. (defcustom org-agenda-exporter-settings nil
  129. "Alist of variable/value pairs that should be active during agenda export.
  130. This is a good place to set options for ps-print and for htmlize.
  131. Note that the way this is implemented, the values will be evaluated
  132. before assigned to the variables. So make sure to quote values you do
  133. *not* want evaluated, for example
  134. (setq org-agenda-exporter-settings
  135. '((ps-print-color-p 'black-white)))"
  136. :group 'org-agenda-export
  137. :type '(repeat
  138. (list
  139. (variable)
  140. (sexp :tag "Value"))))
  141. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  142. "Hook run in temporary buffer before writing it to an export file.
  143. A useful function is `org-agenda-add-entry-text'."
  144. :group 'org-agenda-export
  145. :type 'hook
  146. :options '(org-agenda-add-entry-text))
  147. (defcustom org-agenda-add-entry-text-maxlines 0
  148. "Maximum number of entry text lines to be added to agenda.
  149. This is only relevant when `org-agenda-add-entry-text' is part of
  150. `org-agenda-before-write-hook', which it is by default.
  151. When this is 0, nothing will happen. When it is greater than 0, it
  152. specifies the maximum number of lines that will be added for each entry
  153. that is listed in the agenda view.
  154. Note that this variable is not used during display, only when exporting
  155. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  156. and `org-agenda-entry-text-maxlines'."
  157. :group 'org-agenda
  158. :type 'integer)
  159. (defcustom org-agenda-add-entry-text-descriptive-links t
  160. "Non-nil means export org-links as descriptive links in agenda added text.
  161. This variable applies to the text added to the agenda when
  162. `org-agenda-add-entry-text-maxlines' is larger than 0.
  163. When this variable nil, the URL will (also) be shown."
  164. :group 'org-agenda
  165. :type 'boolean)
  166. (defcustom org-agenda-export-html-style ""
  167. "The style specification for exported HTML Agenda files.
  168. If this variable contains a string, it will replace the default <style>
  169. section as produced by `htmlize'.
  170. Since there are different ways of setting style information, this variable
  171. needs to contain the full HTML structure to provide a style, including the
  172. surrounding HTML tags. The style specifications should include definitions
  173. the fonts used by the agenda, here is an example:
  174. <style type=\"text/css\">
  175. p { font-weight: normal; color: gray; }
  176. .org-agenda-structure {
  177. font-size: 110%;
  178. color: #003399;
  179. font-weight: 600;
  180. }
  181. .org-todo {
  182. color: #cc6666;
  183. font-weight: bold;
  184. }
  185. .org-agenda-done {
  186. color: #339933;
  187. }
  188. .org-done {
  189. color: #339933;
  190. }
  191. .title { text-align: center; }
  192. .todo, .deadline { color: red; }
  193. .done { color: green; }
  194. </style>
  195. or, if you want to keep the style in a file,
  196. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  197. As the value of this option simply gets inserted into the HTML <head> header,
  198. you can \"misuse\" it to also add other text to the header. However,
  199. <style>...</style> is required, if not present the variable will be ignored."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags to not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  661. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  662. The variables
  663. `org-agenda-todo-ignore-with-date',
  664. `org-agenda-todo-ignore-timestamp',
  665. `org-agenda-todo-ignore-scheduled',
  666. `org-agenda-todo-ignore-deadlines'
  667. make the global TODO list skip entries that have time stamps of certain
  668. kinds. If this option is set, the same options will also apply for the
  669. tags-todo search, which is the general tags/property matcher
  670. restricted to unfinished TODO entries only."
  671. :group 'org-agenda-skip
  672. :group 'org-agenda-todo-list
  673. :group 'org-agenda-match-view
  674. :type 'boolean)
  675. (defcustom org-agenda-skip-scheduled-if-done nil
  676. "Non-nil means don't show scheduled items in agenda when they are done.
  677. This is relevant for the daily/weekly agenda, not for the TODO list. And
  678. it applies only to the actual date of the scheduling. Warnings about
  679. an item with a past scheduling dates are always turned off when the item
  680. is DONE."
  681. :group 'org-agenda-skip
  682. :group 'org-agenda-daily/weekly
  683. :type 'boolean)
  684. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  685. "Non-nil means skip scheduling line if same entry shows because of deadline.
  686. In the agenda of today, an entry can show up multiple times because
  687. it is both scheduled and has a nearby deadline, and maybe a plain time
  688. stamp as well.
  689. When this variable is t, then only the deadline is shown and the fact that
  690. the entry is scheduled today or was scheduled previously is not shown.
  691. When this variable is nil, the entry will be shown several times. When
  692. the variable is the symbol `not-today', then skip scheduled previously,
  693. but not scheduled today."
  694. :group 'org-agenda-skip
  695. :group 'org-agenda-daily/weekly
  696. :type '(choice
  697. (const :tag "Never" nil)
  698. (const :tag "Always" t)
  699. (const :tag "Not when scheduled today" not-today)))
  700. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  701. "Non-nil means skip timestamp line if same entry shows because of deadline.
  702. In the agenda of today, an entry can show up multiple times
  703. because it has both a plain timestamp and has a nearby deadline.
  704. When this variable is t, then only the deadline is shown and the
  705. fact that the entry has a timestamp for or including today is not
  706. shown. When this variable is nil, the entry will be shown
  707. several times."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-daily/weekly
  710. :version "24.1"
  711. :type '(choice
  712. (const :tag "Never" nil)
  713. (const :tag "Always" t)))
  714. (defcustom org-agenda-skip-deadline-if-done nil
  715. "Non-nil means don't show deadlines when the corresponding item is done.
  716. When nil, the deadline is still shown and should give you a happy feeling.
  717. This is relevant for the daily/weekly agenda. And it applied only to the
  718. actually date of the deadline. Warnings about approaching and past-due
  719. deadlines are always turned off when the item is DONE."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :type 'boolean)
  723. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  724. "Non-nil means skip deadline prewarning when entry is also scheduled.
  725. This will apply on all days where a prewarning for the deadline would
  726. be shown, but not at the day when the entry is actually due. On that day,
  727. the deadline will be shown anyway.
  728. This variable may be set to nil, t, or a number which will then give
  729. the number of days before the actual deadline when the prewarnings
  730. should resume.
  731. This can be used in a workflow where the first showing of the deadline will
  732. trigger you to schedule it, and then you don't want to be reminded of it
  733. because you will take care of it on the day when scheduled."
  734. :group 'org-agenda-skip
  735. :group 'org-agenda-daily/weekly
  736. :version "24.1"
  737. :type '(choice
  738. (const :tag "Alwas show prewarning" nil)
  739. (const :tag "Remove prewarning if entry is scheduled" t)
  740. (integer :tag "Restart prewarning N days before deadline")))
  741. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  742. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  743. When non-nil, after the search for timestamps has matched once in an
  744. entry, the rest of the entry will not be searched."
  745. :group 'org-agenda-skip
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-timestamp-if-done nil
  748. "Non-nil means don't select item by timestamp or -range if it is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-dim-blocked-tasks t
  753. "Non-nil means dim blocked tasks in the agenda display.
  754. This causes some overhead during agenda construction, but if you
  755. have turned on `org-enforce-todo-dependencies',
  756. `org-enforce-todo-checkbox-dependencies', or any other blocking
  757. mechanism, this will create useful feedback in the agenda.
  758. Instead of t, this variable can also have the value `invisible'.
  759. Then blocked tasks will be invisible and only become visible when
  760. they become unblocked. An exemption to this behavior is when a task is
  761. blocked because of unchecked checkboxes below it. Since checkboxes do
  762. not show up in the agenda views, making this task invisible you remove any
  763. trace from agenda views that there is something to do. Therefore, a task
  764. that is blocked because of checkboxes will never be made invisible, it
  765. will only be dimmed."
  766. :group 'org-agenda-daily/weekly
  767. :group 'org-agenda-todo-list
  768. :type '(choice
  769. (const :tag "Do not dim" nil)
  770. (const :tag "Dim to a gray face" t)
  771. (const :tag "Make invisible" invisible)))
  772. (defcustom org-timeline-show-empty-dates 3
  773. "Non-nil means `org-timeline' also shows dates without an entry.
  774. When nil, only the days which actually have entries are shown.
  775. When t, all days between the first and the last date are shown.
  776. When an integer, show also empty dates, but if there is a gap of more than
  777. N days, just insert a special line indicating the size of the gap."
  778. :group 'org-agenda-skip
  779. :type '(choice
  780. (const :tag "None" nil)
  781. (const :tag "All" t)
  782. (integer :tag "at most")))
  783. (defgroup org-agenda-startup nil
  784. "Options concerning initial settings in the Agenda in Org Mode."
  785. :tag "Org Agenda Startup"
  786. :group 'org-agenda)
  787. (defcustom org-agenda-menu-show-matcher t
  788. "Non-nil means show the match string in the agenda dispatcher menu.
  789. When nil, the matcher string is not shown, but is put into the help-echo
  790. property so than moving the mouse over the command shows it.
  791. Setting it to nil is good if matcher strings are very long and/or if
  792. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  793. :group 'org-agenda
  794. :version "24.1"
  795. :type 'boolean)
  796. (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  797. (defcustom org-agenda-menu-two-columns nil
  798. "Non-nil means, use two columns to show custom commands in the dispatcher.
  799. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  800. to nil."
  801. :group 'org-agenda
  802. :version "24.1"
  803. :type 'boolean)
  804. (make-obsolete-variable 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  805. (defcustom org-agenda-finalize-hook nil
  806. "Hook run just before displaying an agenda buffer."
  807. :group 'org-agenda-startup
  808. :type 'hook)
  809. (defcustom org-agenda-mouse-1-follows-link nil
  810. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  811. A longer mouse click will still set point. Does not work on XEmacs.
  812. Needs to be set before org.el is loaded."
  813. :group 'org-agenda-startup
  814. :type 'boolean)
  815. (defcustom org-agenda-start-with-follow-mode nil
  816. "The initial value of follow mode in a newly created agenda window."
  817. :group 'org-agenda-startup
  818. :type 'boolean)
  819. (defcustom org-agenda-follow-indirect nil
  820. "Non-nil means `org-agenda-follow-mode' displays only the
  821. current item's tree, in an indirect buffer."
  822. :group 'org-agenda
  823. :version "24.1"
  824. :type 'boolean)
  825. (defcustom org-agenda-show-outline-path t
  826. "Non-nil means show outline path in echo area after line motion."
  827. :group 'org-agenda-startup
  828. :type 'boolean)
  829. (defcustom org-agenda-start-with-entry-text-mode nil
  830. "The initial value of entry-text-mode in a newly created agenda window."
  831. :group 'org-agenda-startup
  832. :type 'boolean)
  833. (defcustom org-agenda-entry-text-maxlines 5
  834. "Number of text lines to be added when `E' is pressed in the agenda.
  835. Note that this variable only used during agenda display. Add add entry text
  836. when exporting the agenda, configure the variable
  837. `org-agenda-add-entry-ext-maxlines'."
  838. :group 'org-agenda
  839. :type 'integer)
  840. (defcustom org-agenda-entry-text-exclude-regexps nil
  841. "List of regular expressions to clean up entry text.
  842. The complete matches of all regular expressions in this list will be
  843. removed from entry text before it is shown in the agenda."
  844. :group 'org-agenda
  845. :type '(repeat (regexp)))
  846. (defvar org-agenda-entry-text-cleanup-hook nil
  847. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  848. This cleanup is done in a temporary buffer, so the function may inspect and
  849. change the entire buffer.
  850. Some default stuff like drawers and scheduling/deadline dates will already
  851. have been removed when this is called, as will any matches for regular
  852. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  853. (defvar org-agenda-include-inactive-timestamps nil
  854. "Non-nil means include inactive time stamps in agenda and timeline.
  855. Dynamically scoped.")
  856. (defgroup org-agenda-windows nil
  857. "Options concerning the windows used by the Agenda in Org Mode."
  858. :tag "Org Agenda Windows"
  859. :group 'org-agenda)
  860. (defcustom org-agenda-window-setup 'reorganize-frame
  861. "How the agenda buffer should be displayed.
  862. Possible values for this option are:
  863. current-window Show agenda in the current window, keeping all other windows.
  864. other-window Use `switch-to-buffer-other-window' to display agenda.
  865. reorganize-frame Show only two windows on the current frame, the current
  866. window and the agenda.
  867. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  868. Also, when exiting the agenda, kill that frame.
  869. See also the variable `org-agenda-restore-windows-after-quit'."
  870. :group 'org-agenda-windows
  871. :type '(choice
  872. (const current-window)
  873. (const other-frame)
  874. (const other-window)
  875. (const reorganize-frame)))
  876. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  877. "The min and max height of the agenda window as a fraction of frame height.
  878. The value of the variable is a cons cell with two numbers between 0 and 1.
  879. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  880. :group 'org-agenda-windows
  881. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  882. (defcustom org-agenda-restore-windows-after-quit nil
  883. "Non-nil means restore window configuration upon exiting agenda.
  884. Before the window configuration is changed for displaying the agenda,
  885. the current status is recorded. When the agenda is exited with
  886. `q' or `x' and this option is set, the old state is restored. If
  887. `org-agenda-window-setup' is `other-frame', the value of this
  888. option will be ignored."
  889. :group 'org-agenda-windows
  890. :type 'boolean)
  891. (defcustom org-agenda-ndays nil
  892. "Number of days to include in overview display.
  893. Should be 1 or 7.
  894. Obsolete, see `org-agenda-span'."
  895. :group 'org-agenda-daily/weekly
  896. :type 'integer)
  897. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  898. (defcustom org-agenda-span 'week
  899. "Number of days to include in overview display.
  900. Can be day, week, month, year, or any number of days.
  901. Custom commands can set this variable in the options section."
  902. :group 'org-agenda-daily/weekly
  903. :type '(choice (const :tag "Day" day)
  904. (const :tag "Week" week)
  905. (const :tag "Month" month)
  906. (const :tag "Year" year)
  907. (integer :tag "Custom")))
  908. (defcustom org-agenda-start-on-weekday 1
  909. "Non-nil means start the overview always on the specified weekday.
  910. 0 denotes Sunday, 1 denotes Monday etc.
  911. When nil, always start on the current day.
  912. Custom commands can set this variable in the options section."
  913. :group 'org-agenda-daily/weekly
  914. :type '(choice (const :tag "Today" nil)
  915. (integer :tag "Weekday No.")))
  916. (defcustom org-agenda-show-all-dates t
  917. "Non-nil means `org-agenda' shows every day in the selected range.
  918. When nil, only the days which actually have entries are shown."
  919. :group 'org-agenda-daily/weekly
  920. :type 'boolean)
  921. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  922. "Format string for displaying dates in the agenda.
  923. Used by the daily/weekly agenda and by the timeline. This should be
  924. a format string understood by `format-time-string', or a function returning
  925. the formatted date as a string. The function must take a single argument,
  926. a calendar-style date list like (month day year)."
  927. :group 'org-agenda-daily/weekly
  928. :type '(choice
  929. (string :tag "Format string")
  930. (function :tag "Function")))
  931. (defun org-agenda-format-date-aligned (date)
  932. "Format a date string for display in the daily/weekly agenda, or timeline.
  933. This function makes sure that dates are aligned for easy reading."
  934. (require 'cal-iso)
  935. (let* ((dayname (calendar-day-name date))
  936. (day (cadr date))
  937. (day-of-week (calendar-day-of-week date))
  938. (month (car date))
  939. (monthname (calendar-month-name month))
  940. (year (nth 2 date))
  941. (iso-week (org-days-to-iso-week
  942. (calendar-absolute-from-gregorian date)))
  943. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  944. (1- year))
  945. ((and (= month 12) (<= iso-week 1))
  946. (1+ year))
  947. (t year)))
  948. (weekstring (if (= day-of-week 1)
  949. (format " W%02d" iso-week)
  950. "")))
  951. (format "%-10s %2d %s %4d%s"
  952. dayname day monthname year weekstring)))
  953. (defcustom org-agenda-time-leading-zero nil
  954. "Non-nil means use leading zero for military times in agenda.
  955. For example, 9:30am would become 09:30 rather than 9:30."
  956. :group 'org-agenda-daily/weekly
  957. :version "24.1"
  958. :type 'boolean)
  959. (defcustom org-agenda-timegrid-use-ampm nil
  960. "When set, show AM/PM style timestamps on the timegrid."
  961. :group 'org-agenda
  962. :version "24.1"
  963. :type 'boolean)
  964. (defun org-agenda-time-of-day-to-ampm (time)
  965. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  966. (let* ((hour-number (string-to-number (substring time 0 -3)))
  967. (minute (substring time -2))
  968. (ampm "am"))
  969. (cond
  970. ((equal hour-number 12)
  971. (setq ampm "pm"))
  972. ((> hour-number 12)
  973. (setq ampm "pm")
  974. (setq hour-number (- hour-number 12))))
  975. (concat
  976. (if org-agenda-time-leading-zero
  977. (format "%02d" hour-number)
  978. (format "%02s" (number-to-string hour-number)))
  979. ":" minute ampm)))
  980. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  981. "Conditionally convert TIME to AM/PM format
  982. based on `org-agenda-timegrid-use-ampm'"
  983. (if org-agenda-timegrid-use-ampm
  984. (org-agenda-time-of-day-to-ampm time)
  985. time))
  986. (defcustom org-agenda-weekend-days '(6 0)
  987. "Which days are weekend?
  988. These days get the special face `org-agenda-date-weekend' in the agenda
  989. and timeline buffers."
  990. :group 'org-agenda-daily/weekly
  991. :type '(set :greedy t
  992. (const :tag "Monday" 1)
  993. (const :tag "Tuesday" 2)
  994. (const :tag "Wednesday" 3)
  995. (const :tag "Thursday" 4)
  996. (const :tag "Friday" 5)
  997. (const :tag "Saturday" 6)
  998. (const :tag "Sunday" 0)))
  999. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1000. "Non-nil means jump to today when moving a past date forward in time.
  1001. When using S-right in the agenda to move a a date forward, and the date
  1002. stamp currently points to the past, the first key press will move it
  1003. to today. WHen nil, just move one day forward even if the date stays
  1004. in the past."
  1005. :group 'org-agenda-daily/weekly
  1006. :version "24.1"
  1007. :type 'boolean)
  1008. (defcustom org-agenda-include-diary nil
  1009. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1010. Custom commands can set this variable in the options section."
  1011. :group 'org-agenda-daily/weekly
  1012. :type 'boolean)
  1013. (defcustom org-agenda-include-deadlines t
  1014. "If non-nil, include entries within their deadline warning period.
  1015. Custom commands can set this variable in the options section."
  1016. :group 'org-agenda-daily/weekly
  1017. :version "24.1"
  1018. :type 'boolean)
  1019. (defcustom org-agenda-repeating-timestamp-show-all t
  1020. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1021. When set to a list of strings, only show occurrences of repeating
  1022. stamps for these TODO keywords. When nil, only one occurrence is
  1023. shown, either today or the nearest into the future."
  1024. :group 'org-agenda-daily/weekly
  1025. :type '(choice
  1026. (const :tag "Show repeating stamps" t)
  1027. (repeat :tag "Show repeating stamps for these TODO keywords"
  1028. (string :tag "TODO Keyword"))
  1029. (const :tag "Don't show repeating stamps" nil)))
  1030. (defcustom org-scheduled-past-days 10000
  1031. "No. of days to continue listing scheduled items that are not marked DONE.
  1032. When an item is scheduled on a date, it shows up in the agenda on this
  1033. day and will be listed until it is marked done for the number of days
  1034. given here."
  1035. :group 'org-agenda-daily/weekly
  1036. :type 'integer)
  1037. (defcustom org-agenda-log-mode-items '(closed clock)
  1038. "List of items that should be shown in agenda log mode.
  1039. This list may contain the following symbols:
  1040. closed Show entries that have been closed on that day.
  1041. clock Show entries that have received clocked time on that day.
  1042. state Show all logged state changes.
  1043. Note that instead of changing this variable, you can also press `C-u l' in
  1044. the agenda to display all available LOG items temporarily."
  1045. :group 'org-agenda-daily/weekly
  1046. :type '(set :greedy t (const closed) (const clock) (const state)))
  1047. (defcustom org-agenda-clock-consistency-checks
  1048. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1049. :gap-ok-around ("4:00")
  1050. :default-face ((:background "DarkRed") (:foreground "white"))
  1051. :overlap-face nil :gap-face nil :no-end-time-face nil
  1052. :long-face nil :short-face nil)
  1053. "This is a property list, with the following keys:
  1054. :max-duration Mark clocking chunks that are longer than this time.
  1055. This is a time string like \"HH:MM\", or the number
  1056. of minutes as an integer.
  1057. :min-duration Mark clocking chunks that are shorter that this.
  1058. This is a time string like \"HH:MM\", or the number
  1059. of minutes as an integer.
  1060. :max-gap Mark gaps between clocking chunks that are longer than
  1061. this duration. A number of minutes, or a string
  1062. like \"HH:MM\".
  1063. :gap-ok-around List of times during the day which are usually not working
  1064. times. When a gap is detected, but the gap contains any
  1065. of these times, the gap is *not* reported. For example,
  1066. if this is (\"4:00\" \"13:00\") then gaps that contain
  1067. 4:00 in the morning (i.e. the night) and 13:00
  1068. (i.e. a typical lunch time) do not cause a warning.
  1069. You should have at least one time during the night in this
  1070. list, or otherwise the first task each morning will trigger
  1071. a warning because it follows a long gap.
  1072. Furthermore, the following properties can be used to define faces for
  1073. issue display.
  1074. :default-face the default face, if the specific face is undefined
  1075. :overlap-face face for overlapping clocks
  1076. :gap-face face for gaps between clocks
  1077. :no-end-time-face face for incomplete clocks
  1078. :long-face face for clock intervals that are too long
  1079. :short-face face for clock intervals that are too short"
  1080. :group 'org-agenda-daily/weekly
  1081. :group 'org-clock
  1082. :version "24.1"
  1083. :type 'plist)
  1084. (defcustom org-agenda-log-mode-add-notes t
  1085. "Non-nil means add first line of notes to log entries in agenda views.
  1086. If a log item like a state change or a clock entry is associated with
  1087. notes, the first line of these notes will be added to the entry in the
  1088. agenda display."
  1089. :group 'org-agenda-daily/weekly
  1090. :type 'boolean)
  1091. (defcustom org-agenda-start-with-log-mode nil
  1092. "The initial value of log-mode in a newly created agenda window.
  1093. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1094. explanations on the possible values."
  1095. :group 'org-agenda-startup
  1096. :group 'org-agenda-daily/weekly
  1097. :type '(choice (const :tag "Don't show log items" nil)
  1098. (const :tag "Show only log items" 'only)
  1099. (const :tag "Show all possible log items" 'clockcheck)
  1100. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1101. (choice (const :tag "Show closed log items" 'closed)
  1102. (const :tag "Show clocked log items" 'clock)
  1103. (const :tag "Show all logged state changes" 'state)))))
  1104. (defcustom org-agenda-start-with-clockreport-mode nil
  1105. "The initial value of clockreport-mode in a newly created agenda window."
  1106. :group 'org-agenda-startup
  1107. :group 'org-agenda-daily/weekly
  1108. :type 'boolean)
  1109. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1110. "Property list with parameters for the clocktable in clockreport mode.
  1111. This is the display mode that shows a clock table in the daily/weekly
  1112. agenda, the properties for this dynamic block can be set here.
  1113. The usual clocktable parameters are allowed here, but you cannot set
  1114. the properties :name, :tstart, :tend, :block, and :scope - these will
  1115. be overwritten to make sure the content accurately reflects the
  1116. current display in the agenda."
  1117. :group 'org-agenda-daily/weekly
  1118. :type 'plist)
  1119. (defcustom org-agenda-search-view-always-boolean nil
  1120. "Non-nil means the search string is interpreted as individual parts.
  1121. The search string for search view can either be interpreted as a phrase,
  1122. or as a list of snippets that define a boolean search for a number of
  1123. strings.
  1124. When this is non-nil, the string will be split on whitespace, and each
  1125. snippet will be searched individually, and all must match in order to
  1126. select an entry. A snippet is then a single string of non-white
  1127. characters, or a string in double quotes, or a regexp in {} braces.
  1128. If a snippet is preceded by \"-\", the snippet must *not* match.
  1129. \"+\" is syntactic sugar for positive selection. Each snippet may
  1130. be found as a full word or a partial word, but see the variable
  1131. `org-agenda-search-view-force-full-words'.
  1132. When this is nil, search will look for the entire search phrase as one,
  1133. with each space character matching any amount of whitespace, including
  1134. line breaks.
  1135. Even when this is nil, you can still switch to Boolean search dynamically
  1136. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1137. is a regexp marked with braces like \"{abc}\", this will also switch to
  1138. boolean search."
  1139. :group 'org-agenda-search-view
  1140. :version "24.1"
  1141. :type 'boolean)
  1142. (if (fboundp 'defvaralias)
  1143. (defvaralias 'org-agenda-search-view-search-words-only
  1144. 'org-agenda-search-view-always-boolean))
  1145. (defcustom org-agenda-search-view-force-full-words nil
  1146. "Non-nil means, search words must be matches as complete words.
  1147. When nil, they may also match part of a word."
  1148. :group 'org-agenda-search-view
  1149. :version "24.1"
  1150. :type 'boolean)
  1151. (defgroup org-agenda-time-grid nil
  1152. "Options concerning the time grid in the Org-mode Agenda."
  1153. :tag "Org Agenda Time Grid"
  1154. :group 'org-agenda)
  1155. (defcustom org-agenda-search-headline-for-time t
  1156. "Non-nil means search headline for a time-of-day.
  1157. If the headline contains a time-of-day in one format or another, it will
  1158. be used to sort the entry into the time sequence of items for a day.
  1159. Some people have time stamps in the headline that refer to the creation
  1160. time or so, and then this produces an unwanted side effect. If this is
  1161. the case for your, use this variable to turn off searching the headline
  1162. for a time."
  1163. :group 'org-agenda-time-grid
  1164. :type 'boolean)
  1165. (defcustom org-agenda-use-time-grid t
  1166. "Non-nil means show a time grid in the agenda schedule.
  1167. A time grid is a set of lines for specific times (like every two hours between
  1168. 8:00 and 20:00). The items scheduled for a day at specific times are
  1169. sorted in between these lines.
  1170. For details about when the grid will be shown, and what it will look like, see
  1171. the variable `org-agenda-time-grid'."
  1172. :group 'org-agenda-time-grid
  1173. :type 'boolean)
  1174. (defcustom org-agenda-time-grid
  1175. '((daily today require-timed)
  1176. "----------------"
  1177. (800 1000 1200 1400 1600 1800 2000))
  1178. "The settings for time grid for agenda display.
  1179. This is a list of three items. The first item is again a list. It contains
  1180. symbols specifying conditions when the grid should be displayed:
  1181. daily if the agenda shows a single day
  1182. weekly if the agenda shows an entire week
  1183. today show grid on current date, independent of daily/weekly display
  1184. require-timed show grid only if at least one item has a time specification
  1185. The second item is a string which will be placed behind the grid time.
  1186. The third item is a list of integers, indicating the times that should have
  1187. a grid line."
  1188. :group 'org-agenda-time-grid
  1189. :type
  1190. '(list
  1191. (set :greedy t :tag "Grid Display Options"
  1192. (const :tag "Show grid in single day agenda display" daily)
  1193. (const :tag "Show grid in weekly agenda display" weekly)
  1194. (const :tag "Always show grid for today" today)
  1195. (const :tag "Show grid only if any timed entries are present"
  1196. require-timed)
  1197. (const :tag "Skip grid times already present in an entry"
  1198. remove-match))
  1199. (string :tag "Grid String")
  1200. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1201. (defcustom org-agenda-show-current-time-in-grid t
  1202. "Non-nil means show the current time in the time grid."
  1203. :group 'org-agenda-time-grid
  1204. :version "24.1"
  1205. :type 'boolean)
  1206. (defcustom org-agenda-current-time-string
  1207. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1208. "The string for the current time marker in the agenda."
  1209. :group 'org-agenda-time-grid
  1210. :version "24.1"
  1211. :type 'string)
  1212. (defgroup org-agenda-sorting nil
  1213. "Options concerning sorting in the Org-mode Agenda."
  1214. :tag "Org Agenda Sorting"
  1215. :group 'org-agenda)
  1216. (defcustom org-agenda-sorting-strategy
  1217. '((agenda habit-down time-up priority-down category-keep)
  1218. (todo priority-down category-keep)
  1219. (tags priority-down category-keep)
  1220. (search category-keep))
  1221. "Sorting structure for the agenda items of a single day.
  1222. This is a list of symbols which will be used in sequence to determine
  1223. if an entry should be listed before another entry. The following
  1224. symbols are recognized:
  1225. time-up Put entries with time-of-day indications first, early first
  1226. time-down Put entries with time-of-day indications first, late first
  1227. category-keep Keep the default order of categories, corresponding to the
  1228. sequence in `org-agenda-files'.
  1229. category-up Sort alphabetically by category, A-Z.
  1230. category-down Sort alphabetically by category, Z-A.
  1231. tag-up Sort alphabetically by last tag, A-Z.
  1232. tag-down Sort alphabetically by last tag, Z-A.
  1233. priority-up Sort numerically by priority, high priority last.
  1234. priority-down Sort numerically by priority, high priority first.
  1235. todo-state-up Sort by todo state, tasks that are done last.
  1236. todo-state-down Sort by todo state, tasks that are done first.
  1237. effort-up Sort numerically by estimated effort, high effort last.
  1238. effort-down Sort numerically by estimated effort, high effort first.
  1239. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1240. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1241. habit-up Put entries that are habits first
  1242. habit-down Put entries that are habits last
  1243. alpha-up Sort headlines alphabetically
  1244. alpha-down Sort headlines alphabetically, reversed
  1245. The different possibilities will be tried in sequence, and testing stops
  1246. if one comparison returns a \"not-equal\". For example, the default
  1247. '(time-up category-keep priority-down)
  1248. means: Pull out all entries having a specified time of day and sort them,
  1249. in order to make a time schedule for the current day the first thing in the
  1250. agenda listing for the day. Of the entries without a time indication, keep
  1251. the grouped in categories, don't sort the categories, but keep them in
  1252. the sequence given in `org-agenda-files'. Within each category sort by
  1253. priority.
  1254. Leaving out `category-keep' would mean that items will be sorted across
  1255. categories by priority.
  1256. Instead of a single list, this can also be a set of list for specific
  1257. contents, with a context symbol in the car of the list, any of
  1258. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1259. Custom commands can bind this variable in the options section."
  1260. :group 'org-agenda-sorting
  1261. :type `(choice
  1262. (repeat :tag "General" ,org-sorting-choice)
  1263. (list :tag "Individually"
  1264. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1265. (repeat ,org-sorting-choice))
  1266. (cons (const :tag "Strategy for TODO lists" todo)
  1267. (repeat ,org-sorting-choice))
  1268. (cons (const :tag "Strategy for Tags matches" tags)
  1269. (repeat ,org-sorting-choice))
  1270. (cons (const :tag "Strategy for search matches" search)
  1271. (repeat ,org-sorting-choice)))))
  1272. (defcustom org-agenda-cmp-user-defined nil
  1273. "A function to define the comparison `user-defined'.
  1274. This function must receive two arguments, agenda entry a and b.
  1275. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1276. the user comparison, return nil.
  1277. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1278. part of an agenda sorting strategy."
  1279. :group 'org-agenda-sorting
  1280. :type 'symbol)
  1281. (defcustom org-sort-agenda-notime-is-late t
  1282. "Non-nil means items without time are considered late.
  1283. This is only relevant for sorting. When t, items which have no explicit
  1284. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1285. do have a time. When nil, the default time is before 0:00. You can use this
  1286. option to decide if the schedule for today should come before or after timeless
  1287. agenda entries."
  1288. :group 'org-agenda-sorting
  1289. :type 'boolean)
  1290. (defcustom org-sort-agenda-noeffort-is-high t
  1291. "Non-nil means items without effort estimate are sorted as high effort.
  1292. This also applies when filtering an agenda view with respect to the
  1293. < or > effort operator. Then, tasks with no effort defined will be treated
  1294. as tasks with high effort.
  1295. When nil, such items are sorted as 0 minutes effort."
  1296. :group 'org-agenda-sorting
  1297. :type 'boolean)
  1298. (defgroup org-agenda-line-format nil
  1299. "Options concerning the entry prefix in the Org-mode agenda display."
  1300. :tag "Org Agenda Line Format"
  1301. :group 'org-agenda)
  1302. (defcustom org-agenda-prefix-format
  1303. '((agenda . " %i %-12:c%?-12t% s")
  1304. (timeline . " % s")
  1305. (todo . " %i %-12:c")
  1306. (tags . " %i %-12:c")
  1307. (search . " %i %-12:c"))
  1308. "Format specifications for the prefix of items in the agenda views.
  1309. An alist with five entries, each for the different agenda types. The
  1310. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1311. The values are format strings.
  1312. This format works similar to a printf format, with the following meaning:
  1313. %c the category of the item, \"Diary\" for entries from the diary,
  1314. or as given by the CATEGORY keyword or derived from the file name
  1315. %e the effort required by the item
  1316. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1317. %T the last tag of the item (ignore inherited tags, which come first)
  1318. %t the HH:MM time-of-day specification if one applies to the entry
  1319. %s Scheduling/Deadline information, a short string
  1320. %(expression) Eval EXPRESSION and replace the control string
  1321. by the result
  1322. All specifiers work basically like the standard `%s' of printf, but may
  1323. contain two additional characters: a question mark just after the `%'
  1324. and a whitespace/punctuation character just before the final letter.
  1325. If the first character after `%' is a question mark, the entire field
  1326. will only be included if the corresponding value applies to the current
  1327. entry. This is useful for fields which should have fixed width when
  1328. present, but zero width when absent. For example, \"%?-12t\" will
  1329. result in a 12 character time field if a time of the day is specified,
  1330. but will completely disappear in entries which do not contain a time.
  1331. If there is punctuation or whitespace character just before the final
  1332. format letter, this character will be appended to the field value if
  1333. the value is not empty. For example, the format \"%-12:c\" leads to
  1334. \"Diary: \" if the category is \"Diary\". If the category were be
  1335. empty, no additional colon would be inserted.
  1336. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1337. which means:
  1338. - Indent the line with two space characters
  1339. - Give the category a 12 chars wide field, padded with whitespace on
  1340. the right (because of `-'). Append a colon if there is a category
  1341. (because of `:').
  1342. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1343. time, don't put in an empty field, just skip it (because of '?').
  1344. - Finally, put the scheduling information.
  1345. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1346. `org-agenda-remove-tags'.
  1347. Custom commands can set this variable in the options section."
  1348. :type '(choice
  1349. (string :tag "General format")
  1350. (list :greedy t :tag "View dependent"
  1351. (cons (const agenda) (string :tag "Format"))
  1352. (cons (const timeline) (string :tag "Format"))
  1353. (cons (const todo) (string :tag "Format"))
  1354. (cons (const tags) (string :tag "Format"))
  1355. (cons (const search) (string :tag "Format"))))
  1356. :group 'org-agenda-line-format)
  1357. (defvar org-prefix-format-compiled nil
  1358. "The compiled prefix format and associated variables.
  1359. This is a list where first element is a list of variable bindings, and second
  1360. element is the compiled format expression. See the variable
  1361. `org-agenda-prefix-format'.")
  1362. (defcustom org-agenda-todo-keyword-format "%-1s"
  1363. "Format for the TODO keyword in agenda lines.
  1364. Set this to something like \"%-12s\" if you want all TODO keywords
  1365. to occupy a fixed space in the agenda display."
  1366. :group 'org-agenda-line-format
  1367. :type 'string)
  1368. (defcustom org-agenda-diary-sexp-prefix nil
  1369. "A regexp that matches part of a diary sexp entry
  1370. which should be treated as scheduling/deadline information in
  1371. `org-agenda'.
  1372. For example, you can use this to extract the `diary-remind-message' from
  1373. `diary-remind' entries."
  1374. :group 'org-agenda-line-format
  1375. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1376. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1377. "Text preceding timerange entries in the agenda view.
  1378. This is a list with two strings. The first applies when the range
  1379. is entirely on one day. The second applies if the range spans several days.
  1380. The strings may have two \"%d\" format specifiers which will be filled
  1381. with the sequence number of the days, and the total number of days in the
  1382. range, respectively."
  1383. :group 'org-agenda-line-format
  1384. :type '(list
  1385. (string :tag "Deadline today ")
  1386. (choice :tag "Deadline relative"
  1387. (string :tag "Format string")
  1388. (function))))
  1389. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1390. "Text preceding scheduled items in the agenda view.
  1391. This is a list with two strings. The first applies when the item is
  1392. scheduled on the current day. The second applies when it has been scheduled
  1393. previously, it may contain a %d indicating that this is the nth time that
  1394. this item is scheduled, due to automatic rescheduling of unfinished items
  1395. for the following day. So this number is one larger than the number of days
  1396. that passed since this item was scheduled first."
  1397. :group 'org-agenda-line-format
  1398. :type '(list
  1399. (string :tag "Scheduled today ")
  1400. (string :tag "Scheduled previously")))
  1401. (defcustom org-agenda-inactive-leader "["
  1402. "Text preceding item pulled into the agenda by inactive time stamps.
  1403. These entries are added to the agenda when pressing \"[\"."
  1404. :group 'org-agenda-line-format
  1405. :version "24.1"
  1406. :type '(list
  1407. (string :tag "Scheduled today ")
  1408. (string :tag "Scheduled previously")))
  1409. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1410. "Text preceding deadline items in the agenda view.
  1411. This is a list with two strings. The first applies when the item has its
  1412. deadline on the current day. The second applies when it is in the past or
  1413. in the future, it may contain %d to capture how many days away the deadline
  1414. is (was)."
  1415. :group 'org-agenda-line-format
  1416. :type '(list
  1417. (string :tag "Deadline today ")
  1418. (choice :tag "Deadline relative"
  1419. (string :tag "Format string")
  1420. (function))))
  1421. (defcustom org-agenda-remove-times-when-in-prefix t
  1422. "Non-nil means remove duplicate time specifications in agenda items.
  1423. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1424. time-of-day specification in a headline or diary entry is extracted and
  1425. placed into the prefix. If this option is non-nil, the original specification
  1426. \(a timestamp or -range, or just a plain time(range) specification like
  1427. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1428. cluttered.
  1429. The option can be t or nil. It may also be the symbol `beg', indicating
  1430. that the time should only be removed when it is located at the beginning of
  1431. the headline/diary entry."
  1432. :group 'org-agenda-line-format
  1433. :type '(choice
  1434. (const :tag "Always" t)
  1435. (const :tag "Never" nil)
  1436. (const :tag "When at beginning of entry" beg)))
  1437. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1438. "Non-nil means remove time ranges specifications in agenda
  1439. items that span on several days."
  1440. :group 'org-agenda-line-format
  1441. :version "24.1"
  1442. :type 'boolean)
  1443. (defcustom org-agenda-default-appointment-duration nil
  1444. "Default duration for appointments that only have a starting time.
  1445. When nil, no duration is specified in such cases.
  1446. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1447. :group 'org-agenda-line-format
  1448. :type '(choice
  1449. (integer :tag "Minutes")
  1450. (const :tag "No default duration")))
  1451. (defcustom org-agenda-show-inherited-tags t
  1452. "Non-nil means show inherited tags in each agenda line."
  1453. :group 'org-agenda-line-format
  1454. :type 'boolean)
  1455. (defcustom org-agenda-hide-tags-regexp nil
  1456. "Regular expression used to filter away specific tags in agenda views.
  1457. This means that these tags will be present, but not be shown in the agenda
  1458. line. Secondary filtering will still work on the hidden tags.
  1459. Nil means don't hide any tags."
  1460. :group 'org-agenda-line-format
  1461. :type '(choice
  1462. (const :tag "Hide none" nil)
  1463. (string :tag "Regexp ")))
  1464. (defcustom org-agenda-remove-tags nil
  1465. "Non-nil means remove the tags from the headline copy in the agenda.
  1466. When this is the symbol `prefix', only remove tags when
  1467. `org-agenda-prefix-format' contains a `%T' specifier."
  1468. :group 'org-agenda-line-format
  1469. :type '(choice
  1470. (const :tag "Always" t)
  1471. (const :tag "Never" nil)
  1472. (const :tag "When prefix format contains %T" prefix)))
  1473. (if (fboundp 'defvaralias)
  1474. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1475. 'org-agenda-remove-tags))
  1476. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1477. "Shift tags in agenda items to this column.
  1478. If this number is positive, it specifies the column. If it is negative,
  1479. it means that the tags should be flushright to that column. For example,
  1480. -80 works well for a normal 80 character screen."
  1481. :group 'org-agenda-line-format
  1482. :type 'integer)
  1483. (if (fboundp 'defvaralias)
  1484. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1485. (defcustom org-agenda-fontify-priorities 'cookies
  1486. "Non-nil means highlight low and high priorities in agenda.
  1487. When t, the highest priority entries are bold, lowest priority italic.
  1488. However, settings in `org-priority-faces' will overrule these faces.
  1489. When this variable is the symbol `cookies', only fontify the
  1490. cookies, not the entire task.
  1491. This may also be an association list of priority faces, whose
  1492. keys are the character values of `org-highest-priority',
  1493. `org-default-priority', and `org-lowest-priority' (the default values
  1494. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1495. color as a string, or a list like `(:background \"Red\")'.
  1496. If it is a color, the variable `org-faces-easy-properties'
  1497. determines if it is a foreground or a background color."
  1498. :group 'org-agenda-line-format
  1499. :type '(choice
  1500. (const :tag "Never" nil)
  1501. (const :tag "Defaults" t)
  1502. (const :tag "Cookies only" cookies)
  1503. (repeat :tag "Specify"
  1504. (list (character :tag "Priority" :value ?A)
  1505. (choice :tag "Face "
  1506. (string :tag "Color")
  1507. (sexp :tag "Face"))))))
  1508. (defcustom org-agenda-day-face-function nil
  1509. "Function called to determine what face should be used to display a day.
  1510. The only argument passed to that function is the day. It should
  1511. returns a face, or nil if does not want to specify a face and let
  1512. the normal rules apply."
  1513. :group 'org-agenda-line-format
  1514. :version "24.1"
  1515. :type 'function)
  1516. (defcustom org-agenda-category-icon-alist nil
  1517. "Alist of category icon to be displayed in agenda views.
  1518. Each entry should have the following format:
  1519. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1520. Where CATEGORY-REGEXP is a regexp matching the categories where
  1521. the icon should be displayed.
  1522. FILE-OR-DATA either a file path or a string containing image data.
  1523. The other fields can be omitted safely if not needed:
  1524. TYPE indicates the image type.
  1525. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1526. image data.
  1527. PROPS are additional image attributes to assign to the image,
  1528. like, e.g. `:ascent center'.
  1529. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1530. If you want to set the display properties yourself, just put a
  1531. list as second element:
  1532. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1533. For example, to display a 16px horizontal space for Emacs
  1534. category, you can use:
  1535. (\"Emacs\" '(space . (:width (16))))"
  1536. :group 'org-agenda-line-format
  1537. :version "24.1"
  1538. :type '(alist :key-type (string :tag "Regexp matching category")
  1539. :value-type (choice (list :tag "Icon"
  1540. (string :tag "File or data")
  1541. (symbol :tag "Type")
  1542. (boolean :tag "Data?")
  1543. (repeat :tag "Extra image properties" :inline t symbol))
  1544. (list :tag "Display properties" sexp))))
  1545. (defgroup org-agenda-column-view nil
  1546. "Options concerning column view in the agenda."
  1547. :tag "Org Agenda Column View"
  1548. :group 'org-agenda)
  1549. (defcustom org-agenda-columns-show-summaries t
  1550. "Non-nil means show summaries for columns displayed in the agenda view."
  1551. :group 'org-agenda-column-view
  1552. :type 'boolean)
  1553. (defcustom org-agenda-columns-compute-summary-properties t
  1554. "Non-nil means recompute all summary properties before column view.
  1555. When column view in the agenda is listing properties that have a summary
  1556. operator, it can go to all relevant buffers and recompute the summaries
  1557. there. This can mean overhead for the agenda column view, but is necessary
  1558. to have thing up to date.
  1559. As a special case, a CLOCKSUM property also makes sure that the clock
  1560. computations are current."
  1561. :group 'org-agenda-column-view
  1562. :type 'boolean)
  1563. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1564. "Non-nil means the duration of an appointment will add to day effort.
  1565. The property to which appointment durations will be added is the one given
  1566. in the option `org-effort-property'. If an appointment does not have
  1567. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1568. is not set, an appointment without end time will not contribute to the time
  1569. estimate."
  1570. :group 'org-agenda-column-view
  1571. :type 'boolean)
  1572. (defcustom org-agenda-auto-exclude-function nil
  1573. "A function called with a tag to decide if it is filtered on '/ RET'.
  1574. The sole argument to the function, which is called once for each
  1575. possible tag, is a string giving the name of the tag. The
  1576. function should return either nil if the tag should be included
  1577. as normal, or \"-<TAG>\" to exclude the tag.
  1578. Note that for the purpose of tag filtering, only the lower-case version of
  1579. all tags will be considered, so that this function will only ever see
  1580. the lower-case version of all tags."
  1581. :group 'org-agenda
  1582. :type 'function)
  1583. (defcustom org-agenda-bulk-custom-functions nil
  1584. "Alist of characters and custom functions for bulk actions.
  1585. For example, this value makes those two functions available:
  1586. '((?R set-category)
  1587. (?C bulk-cut))
  1588. With selected entries in an agenda buffer, `B R' will call
  1589. the custom function `set-category' on the selected entries.
  1590. Note that functions in this alist don't need to be quoted."
  1591. :type 'alist
  1592. :version "24.1"
  1593. :group 'org-agenda)
  1594. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1595. "Execute BODY with point at location given by `org-hd-marker' property.
  1596. If STRING is non-nil, the text property will be fetched from position 0
  1597. in that string. If STRING is nil, it will be fetched from the beginning
  1598. of the current line."
  1599. (org-with-gensyms (marker)
  1600. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1601. 'org-hd-marker ,string)))
  1602. (with-current-buffer (marker-buffer ,marker)
  1603. (save-excursion
  1604. (goto-char ,marker)
  1605. ,@body)))))
  1606. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1607. (defun org-add-agenda-custom-command (entry)
  1608. "Replace or add a command in `org-agenda-custom-commands'.
  1609. This is mostly for hacking and trying a new command - once the command
  1610. works you probably want to add it to `org-agenda-custom-commands' for good."
  1611. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1612. (if ass
  1613. (setcdr ass (cdr entry))
  1614. (push entry org-agenda-custom-commands))))
  1615. ;;; Define the org-agenda-mode
  1616. (defvar org-agenda-mode-map (make-sparse-keymap)
  1617. "Keymap for `org-agenda-mode'.")
  1618. (if (fboundp 'defvaralias)
  1619. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1620. (defvar org-agenda-menu) ; defined later in this file.
  1621. (defvar org-agenda-restrict nil) ; defined later in this file.
  1622. (defvar org-agenda-follow-mode nil)
  1623. (defvar org-agenda-entry-text-mode nil)
  1624. (defvar org-agenda-clockreport-mode nil)
  1625. (defvar org-agenda-show-log nil)
  1626. (defvar org-agenda-redo-command nil)
  1627. (defvar org-agenda-query-string nil)
  1628. (defvar org-agenda-mode-hook nil
  1629. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1630. (defvar org-agenda-type nil)
  1631. (defvar org-agenda-force-single-file nil)
  1632. (defvar org-agenda-bulk-marked-entries nil
  1633. "List of markers that refer to marked entries in the agenda.")
  1634. ;;; Multiple agenda buffers support
  1635. (defcustom org-agenda-sticky nil
  1636. "Non-nil means agenda q key will bury agenda buffers.
  1637. Agenda commands will then show existing buffer instead of generating new ones.
  1638. When nil, `q' will kill the single agenda buffer."
  1639. :group 'org-agenda
  1640. :type 'boolean
  1641. :set (lambda (var val)
  1642. (if (boundp var)
  1643. (org-toggle-sticky-agenda (if val 1 0))
  1644. (set var val))))
  1645. ;;;###autoload
  1646. (defun org-toggle-sticky-agenda (&optional arg)
  1647. "Toggle `org-agenda-sticky'."
  1648. (interactive "P")
  1649. (let ((new-value (if arg
  1650. (> (prefix-numeric-value arg) 0)
  1651. (not org-agenda-sticky))))
  1652. (if (equal new-value org-agenda-sticky)
  1653. (and (org-called-interactively-p 'interactive)
  1654. (message "Sticky agenda was already %s"
  1655. (if org-agenda-sticky "enabled" "disabled")))
  1656. (setq org-agenda-sticky new-value)
  1657. (org-agenda-kill-all-agenda-buffers)
  1658. (and (org-called-interactively-p 'interactive)
  1659. (message "Sticky agenda was %s"
  1660. (if org-agenda-sticky "enabled" "disabled"))))))
  1661. (defvar org-agenda-buffer nil
  1662. "Agenda buffer currently being generated.")
  1663. (defvar org-agenda-last-prefix-arg nil)
  1664. (defvar org-agenda-this-buffer-name nil)
  1665. (defvar org-agenda-doing-sticky-redo nil)
  1666. (defvar org-agenda-this-buffer-is-sticky nil)
  1667. (defconst org-agenda-local-vars
  1668. '(org-agenda-this-buffer-name
  1669. org-agenda-undo-list
  1670. org-agenda-pending-undo-list
  1671. org-agenda-follow-mode
  1672. org-agenda-entry-text-mode
  1673. org-agenda-clockreport-mode
  1674. org-agenda-show-log
  1675. org-agenda-redo-command
  1676. org-agenda-query-string
  1677. org-agenda-type
  1678. org-agenda-bulk-marked-entries
  1679. org-agenda-undo-has-started-in
  1680. org-agenda-info
  1681. org-agenda-tag-filter-overlays
  1682. org-agenda-cat-filter-overlays
  1683. org-agenda-pre-window-conf
  1684. org-agenda-columns-active
  1685. org-agenda-tag-filter
  1686. org-agenda-category-filter
  1687. org-agenda-markers
  1688. org-agenda-last-search-view-search-was-boolean
  1689. org-agenda-filtered-by-category
  1690. org-agenda-filter-form
  1691. org-agenda-show-window
  1692. org-agenda-cycle-counter
  1693. org-agenda-last-prefix-arg)
  1694. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1695. (defun org-agenda-mode ()
  1696. "Mode for time-sorted view on action items in Org-mode files.
  1697. The following commands are available:
  1698. \\{org-agenda-mode-map}"
  1699. (interactive)
  1700. (cond (org-agenda-doing-sticky-redo
  1701. ;; Refreshing sticky agenda-buffer
  1702. ;;
  1703. ;; Preserve the value of `org-agenda-local-vars' variables,
  1704. ;; while letting `kill-all-local-variables' kill the rest
  1705. (let ((save (buffer-local-variables)))
  1706. (kill-all-local-variables)
  1707. (mapc 'make-local-variable org-agenda-local-vars)
  1708. (dolist (elem save)
  1709. (let ((var (car elem))
  1710. (val (cdr elem)))
  1711. (when (and val
  1712. (member var org-agenda-local-vars))
  1713. (set var val)))))
  1714. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1715. (org-agenda-sticky
  1716. ;; Creating a sticky Agenda buffer for the first time
  1717. (kill-all-local-variables)
  1718. (mapc 'make-local-variable org-agenda-local-vars)
  1719. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1720. (t
  1721. ;; Creating a non-sticky agenda buffer
  1722. (kill-all-local-variables)
  1723. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1724. (setq org-agenda-undo-list nil
  1725. org-agenda-pending-undo-list nil
  1726. org-agenda-bulk-marked-entries nil)
  1727. (setq major-mode 'org-agenda-mode)
  1728. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1729. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1730. (setq mode-name "Org-Agenda")
  1731. (use-local-map org-agenda-mode-map)
  1732. (easy-menu-add org-agenda-menu)
  1733. (if org-startup-truncated (setq truncate-lines t))
  1734. (org-set-local 'line-move-visual nil)
  1735. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1736. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1737. ;; Make sure properties are removed when copying text
  1738. (make-local-variable 'filter-buffer-substring-functions)
  1739. (add-hook 'filter-buffer-substring-functions
  1740. (lambda (fun start end delete)
  1741. (substring-no-properties (funcall fun start end delete))))
  1742. (unless org-agenda-keep-modes
  1743. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1744. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1745. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1746. org-agenda-show-log org-agenda-start-with-log-mode))
  1747. (easy-menu-change
  1748. '("Agenda") "Agenda Files"
  1749. (append
  1750. (list
  1751. (vector
  1752. (if (get 'org-agenda-files 'org-restrict)
  1753. "Restricted to single file"
  1754. "Edit File List")
  1755. '(org-edit-agenda-file-list)
  1756. (not (get 'org-agenda-files 'org-restrict)))
  1757. "--")
  1758. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1759. (org-agenda-set-mode-name)
  1760. (apply
  1761. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1762. (list 'org-agenda-mode-hook)))
  1763. (substitute-key-definition 'undo 'org-agenda-undo
  1764. org-agenda-mode-map global-map)
  1765. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1766. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1767. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1768. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1769. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1770. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1771. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1772. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1773. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1774. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1775. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1776. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1777. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1778. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1779. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1780. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1781. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1782. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1783. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1784. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1785. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1786. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1787. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1788. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1789. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1791. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1792. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1794. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1795. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1796. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1797. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1798. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1799. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1800. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1801. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1802. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1803. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1804. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1805. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1806. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1807. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1808. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1809. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1810. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1811. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1812. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1813. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1814. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1815. (while l (org-defkey org-agenda-mode-map
  1816. (int-to-string (pop l)) 'digit-argument)))
  1817. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1818. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1819. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1820. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1821. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1822. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1823. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1824. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1825. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1826. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1827. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1828. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1829. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1830. 'org-clock-modify-effort-estimate)
  1831. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1832. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1833. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1834. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1835. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1836. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1837. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1838. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1839. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1840. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1841. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1842. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1843. (substitute-key-definition 'next-line 'org-agenda-next-line
  1844. org-agenda-mode-map global-map)
  1845. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1846. org-agenda-mode-map global-map)
  1847. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1849. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1850. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1851. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
  1852. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1853. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1854. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1855. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1856. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1857. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1858. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1859. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1860. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1861. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1862. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1863. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1864. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1865. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1866. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1867. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1868. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1869. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1870. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1871. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1872. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1873. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1874. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1875. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1877. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1878. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1879. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1880. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1881. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1882. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1883. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1884. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1885. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1886. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1887. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1888. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1889. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1890. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1891. (when org-agenda-mouse-1-follows-link
  1892. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1893. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1894. '("Agenda"
  1895. ("Agenda Files")
  1896. "--"
  1897. ("Agenda Dates"
  1898. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1899. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1900. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1901. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1902. "--"
  1903. ("View"
  1904. ["Day View" org-agenda-day-view
  1905. :active (org-agenda-check-type nil 'agenda)
  1906. :style radio :selected (eq org-agenda-current-span 'day)
  1907. :keys "v d (or just d)"]
  1908. ["Week View" org-agenda-week-view
  1909. :active (org-agenda-check-type nil 'agenda)
  1910. :style radio :selected (eq org-agenda-current-span 'week)
  1911. :keys "v w (or just w)"]
  1912. ["Month View" org-agenda-month-view
  1913. :active (org-agenda-check-type nil 'agenda)
  1914. :style radio :selected (eq org-agenda-current-span 'month)
  1915. :keys "v m"]
  1916. ["Year View" org-agenda-year-view
  1917. :active (org-agenda-check-type nil 'agenda)
  1918. :style radio :selected (eq org-agenda-current-span 'year)
  1919. :keys "v y"]
  1920. "--"
  1921. ["Include Diary" org-agenda-toggle-diary
  1922. :style toggle :selected org-agenda-include-diary
  1923. :active (org-agenda-check-type nil 'agenda)]
  1924. ["Include Deadlines" org-agenda-toggle-deadlines
  1925. :style toggle :selected org-agenda-include-deadlines
  1926. :active (org-agenda-check-type nil 'agenda)]
  1927. ["Use Time Grid" org-agenda-toggle-time-grid
  1928. :style toggle :selected org-agenda-use-time-grid
  1929. :active (org-agenda-check-type nil 'agenda)]
  1930. "--"
  1931. ["Show clock report" org-agenda-clockreport-mode
  1932. :style toggle :selected org-agenda-clockreport-mode
  1933. :active (org-agenda-check-type nil 'agenda)]
  1934. ["Show some entry text" org-agenda-entry-text-mode
  1935. :style toggle :selected org-agenda-entry-text-mode
  1936. :active t]
  1937. "--"
  1938. ["Show Logbook entries" org-agenda-log-mode
  1939. :style toggle :selected org-agenda-show-log
  1940. :active (org-agenda-check-type nil 'agenda 'timeline)
  1941. :keys "v l (or just l)"]
  1942. ["Include archived trees" org-agenda-archives-mode
  1943. :style toggle :selected org-agenda-archives-mode :active t
  1944. :keys "v a"]
  1945. ["Include archive files" (org-agenda-archives-mode t)
  1946. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1947. :keys "v A"]
  1948. "--"
  1949. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1950. ["Write view to file" org-agenda-write t]
  1951. ["Rebuild buffer" org-agenda-redo t]
  1952. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1953. "--"
  1954. ["Show original entry" org-agenda-show t]
  1955. ["Go To (other window)" org-agenda-goto t]
  1956. ["Go To (this window)" org-agenda-switch-to t]
  1957. ["Follow Mode" org-agenda-follow-mode
  1958. :style toggle :selected org-agenda-follow-mode :active t]
  1959. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1960. "--"
  1961. ("TODO"
  1962. ["Cycle TODO" org-agenda-todo t]
  1963. ["Next TODO set" org-agenda-todo-nextset t]
  1964. ["Previous TODO set" org-agenda-todo-previousset t]
  1965. ["Add note" org-agenda-add-note t])
  1966. ("Archive/Refile/Delete"
  1967. ["Archive default" org-agenda-archive-default t]
  1968. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1969. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1970. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1971. ["Archive subtree" org-agenda-archive t]
  1972. "--"
  1973. ["Refile" org-agenda-refile t]
  1974. "--"
  1975. ["Delete subtree" org-agenda-kill t])
  1976. ("Bulk action"
  1977. ["Mark entry" org-agenda-bulk-mark t]
  1978. ["Mark all" org-agenda-bulk-mark-all t]
  1979. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1980. ["Unmark entry" org-agenda-bulk-unmark t]
  1981. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
  1982. ["Act on all marked" org-agenda-bulk-action t]
  1983. "--"
  1984. ("Tags and Properties"
  1985. ["Show all Tags" org-agenda-show-tags t]
  1986. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1987. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1988. "--"
  1989. ["Column View" org-columns t])
  1990. ("Deadline/Schedule"
  1991. ["Schedule" org-agenda-schedule t]
  1992. ["Set Deadline" org-agenda-deadline t]
  1993. "--"
  1994. ["Mark item" org-agenda-action :active t :keys "k m"]
  1995. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1996. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1997. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1998. "--"
  1999. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2000. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2001. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2002. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2003. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2004. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2005. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2006. ("Clock and Effort"
  2007. ["Clock in" org-agenda-clock-in t]
  2008. ["Clock out" org-agenda-clock-out t]
  2009. ["Clock cancel" org-agenda-clock-cancel t]
  2010. ["Goto running clock" org-clock-goto t]
  2011. "--"
  2012. ["Set Effort" org-agenda-set-effort t]
  2013. ["Change clocked effort" org-clock-modify-effort-estimate
  2014. (org-clock-is-active)])
  2015. ("Priority"
  2016. ["Set Priority" org-agenda-priority t]
  2017. ["Increase Priority" org-agenda-priority-up t]
  2018. ["Decrease Priority" org-agenda-priority-down t]
  2019. ["Show Priority" org-agenda-show-priority t])
  2020. ("Calendar/Diary"
  2021. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2022. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2023. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2024. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2025. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2026. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2027. "--"
  2028. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2029. "--"
  2030. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2031. "--"
  2032. ("MobileOrg"
  2033. ["Push Files and Views" org-mobile-push t]
  2034. ["Get Captured and Flagged" org-mobile-pull t]
  2035. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2036. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2037. "--"
  2038. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2039. "--"
  2040. ["Quit" org-agenda-quit t]
  2041. ["Exit and Release Buffers" org-agenda-exit t]
  2042. ))
  2043. ;;; Agenda undo
  2044. (defvar org-agenda-allow-remote-undo t
  2045. "Non-nil means allow remote undo from the agenda buffer.")
  2046. (defvar org-agenda-undo-has-started-in nil
  2047. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2048. (defun org-agenda-undo ()
  2049. "Undo a remote editing step in the agenda.
  2050. This undoes changes both in the agenda buffer and in the remote buffer
  2051. that have been changed along."
  2052. (interactive)
  2053. (or org-agenda-allow-remote-undo
  2054. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2055. (if (not (eq this-command last-command))
  2056. (setq org-agenda-undo-has-started-in nil
  2057. org-agenda-pending-undo-list org-agenda-undo-list))
  2058. (if (not org-agenda-pending-undo-list)
  2059. (error "No further undo information"))
  2060. (let* ((entry (pop org-agenda-pending-undo-list))
  2061. buf line cmd rembuf)
  2062. (setq cmd (pop entry) line (pop entry))
  2063. (setq rembuf (nth 2 entry))
  2064. (org-with-remote-undo rembuf
  2065. (while (bufferp (setq buf (pop entry)))
  2066. (if (pop entry)
  2067. (with-current-buffer buf
  2068. (let ((last-undo-buffer buf)
  2069. (inhibit-read-only t))
  2070. (unless (memq buf org-agenda-undo-has-started-in)
  2071. (push buf org-agenda-undo-has-started-in)
  2072. (make-local-variable 'pending-undo-list)
  2073. (undo-start))
  2074. (while (and pending-undo-list
  2075. (listp pending-undo-list)
  2076. (not (car pending-undo-list)))
  2077. (pop pending-undo-list))
  2078. (undo-more 1))))))
  2079. (org-goto-line line)
  2080. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2081. (defun org-verify-change-for-undo (l1 l2)
  2082. "Verify that a real change occurred between the undo lists L1 and L2."
  2083. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2084. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2085. (not (eq l1 l2)))
  2086. ;;; Agenda dispatch
  2087. (defvar org-agenda-restrict-begin (make-marker))
  2088. (defvar org-agenda-restrict-end (make-marker))
  2089. (defvar org-agenda-last-dispatch-buffer nil)
  2090. (defvar org-agenda-overriding-restriction nil)
  2091. (defcustom org-agenda-custom-commands-contexts nil
  2092. "Alist of custom agenda keys and contextual rules.
  2093. For example, if you have a custom agenda command \"p\" and you
  2094. want this command to be accessible only from plain text files,
  2095. use this:
  2096. '((\"p\" (in-file . \"\\.txt\")))
  2097. Here are the available contexts definitions:
  2098. in-file: command displayed only in matching files
  2099. in-mode: command displayed only in matching modes
  2100. not-in-file: command not displayed in matching files
  2101. not-in-mode: command not displayed in matching modes
  2102. [function]: a custom function taking no argument
  2103. If you define several checks, the agenda command will be
  2104. accessible if there is at least one valid check.
  2105. You can also bind a key to another agenda custom command
  2106. depending on contextual rules.
  2107. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2108. Here it means: in .txt files, use \"p\" as the key for the
  2109. agenda command otherwise associated with \"q\". (The command
  2110. originally associated with \"q\" is not displayed to avoid
  2111. duplicates.)"
  2112. ;; :version "24.3"
  2113. :group 'org-agenda-custom-commands
  2114. :type '(repeat (list :tag "Rule"
  2115. (string :tag " Agenda key")
  2116. (string :tag "Replace by command")
  2117. (repeat :tag "Available when"
  2118. (choice
  2119. (cons :tag "Condition"
  2120. (choice
  2121. (const :tag "In file" in-file)
  2122. (const :tag "Not in file" not-in-file)
  2123. (const :tag "In mode" in-mode)
  2124. (const :tag "Not in mode" not-in-mode))
  2125. (regexp))
  2126. (function :tag "Custom function"))))))
  2127. (defvar org-keys nil)
  2128. (defvar org-match nil)
  2129. ;;;###autoload
  2130. (defun org-agenda (&optional arg org-keys restriction)
  2131. "Dispatch agenda commands to collect entries to the agenda buffer.
  2132. Prompts for a command to execute. Any prefix arg will be passed
  2133. on to the selected command. The default selections are:
  2134. a Call `org-agenda-list' to display the agenda for current day or week.
  2135. t Call `org-todo-list' to display the global todo list.
  2136. T Call `org-todo-list' to display the global todo list, select only
  2137. entries with a specific TODO keyword (the user gets a prompt).
  2138. m Call `org-tags-view' to display headlines with tags matching
  2139. a condition (the user is prompted for the condition).
  2140. M Like `m', but select only TODO entries, no ordinary headlines.
  2141. L Create a timeline for the current buffer.
  2142. e Export views to associated files.
  2143. s Search entries for keywords.
  2144. S Search entries for keywords, only with TODO keywords.
  2145. / Multi occur across all agenda files and also files listed
  2146. in `org-agenda-text-search-extra-files'.
  2147. < Restrict agenda commands to buffer, subtree, or region.
  2148. Press several times to get the desired effect.
  2149. > Remove a previous restriction.
  2150. # List \"stuck\" projects.
  2151. ! Configure what \"stuck\" means.
  2152. C Configure custom agenda commands.
  2153. More commands can be added by configuring the variable
  2154. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2155. searches can be pre-defined in this way.
  2156. If the current buffer is in Org-mode and visiting a file, you can also
  2157. first press `<' once to indicate that the agenda should be temporarily
  2158. \(until the next use of \\[org-agenda]) restricted to the current file.
  2159. Pressing `<' twice means to restrict to the current subtree or region
  2160. \(if active)."
  2161. (interactive "P")
  2162. (catch 'exit
  2163. (let* ((prefix-descriptions nil)
  2164. (org-agenda-buffer-name org-agenda-buffer-name)
  2165. (org-agenda-window-setup (if (equal (buffer-name)
  2166. org-agenda-buffer-name)
  2167. 'current-window
  2168. org-agenda-window-setup))
  2169. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2170. (org-agenda-custom-commands
  2171. ;; normalize different versions
  2172. (delq nil
  2173. (mapcar
  2174. (lambda (x)
  2175. (cond ((stringp (cdr x))
  2176. (push x prefix-descriptions)
  2177. nil)
  2178. ((stringp (nth 1 x)) x)
  2179. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2180. (t (cons (car x) (cons "" (cdr x))))))
  2181. org-agenda-custom-commands)))
  2182. (org-agenda-custom-commands
  2183. (org-contextualize-keys
  2184. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2185. (buf (current-buffer))
  2186. (bfn (buffer-file-name (buffer-base-buffer)))
  2187. entry key type org-match lprops ans)
  2188. ;; Turn off restriction unless there is an overriding one,
  2189. (unless org-agenda-overriding-restriction
  2190. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2191. ;; There is a request to keep the file list in place
  2192. (put 'org-agenda-files 'org-restrict nil))
  2193. (setq org-agenda-restrict nil)
  2194. (move-marker org-agenda-restrict-begin nil)
  2195. (move-marker org-agenda-restrict-end nil))
  2196. ;; Delete old local properties
  2197. (put 'org-agenda-redo-command 'org-lprops nil)
  2198. ;; Delete previously set last-arguments
  2199. (put 'org-agenda-redo-command 'last-args nil)
  2200. ;; Remember where this call originated
  2201. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2202. (unless org-keys
  2203. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2204. org-keys (car ans)
  2205. restriction (cdr ans)))
  2206. ;; If we have sticky agenda buffers, set a name for the buffer,
  2207. ;; depending on the invoking keys. The user may still set this
  2208. ;; as a command option, which will overwrite what we do here.
  2209. (if org-agenda-sticky
  2210. (setq org-agenda-buffer-name
  2211. (format "*Org Agenda(%s)*" org-keys)))
  2212. ;; Establish the restriction, if any
  2213. (when (and (not org-agenda-overriding-restriction) restriction)
  2214. (put 'org-agenda-files 'org-restrict (list bfn))
  2215. (cond
  2216. ((eq restriction 'region)
  2217. (setq org-agenda-restrict t)
  2218. (move-marker org-agenda-restrict-begin (region-beginning))
  2219. (move-marker org-agenda-restrict-end (region-end)))
  2220. ((eq restriction 'subtree)
  2221. (save-excursion
  2222. (setq org-agenda-restrict t)
  2223. (org-back-to-heading t)
  2224. (move-marker org-agenda-restrict-begin (point))
  2225. (move-marker org-agenda-restrict-end
  2226. (progn (org-end-of-subtree t)))))))
  2227. ;; For example the todo list should not need it (but does...)
  2228. (cond
  2229. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2230. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2231. (progn
  2232. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2233. lprops (nth 4 entry))
  2234. (if org-agenda-sticky
  2235. (setq org-agenda-buffer-name
  2236. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2237. (format "*Org Agenda(%s)*" org-keys))))
  2238. (put 'org-agenda-redo-command 'org-lprops lprops)
  2239. (cond
  2240. ((eq type 'agenda)
  2241. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2242. ((eq type 'alltodo)
  2243. (org-let lprops '(org-todo-list current-prefix-arg)))
  2244. ((eq type 'search)
  2245. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2246. ((eq type 'stuck)
  2247. (org-let lprops '(org-agenda-list-stuck-projects
  2248. current-prefix-arg)))
  2249. ((eq type 'tags)
  2250. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2251. ((eq type 'tags-todo)
  2252. (org-let lprops '(org-tags-view '(4) org-match)))
  2253. ((eq type 'todo)
  2254. (org-let lprops '(org-todo-list org-match)))
  2255. ((eq type 'tags-tree)
  2256. (org-check-for-org-mode)
  2257. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2258. ((eq type 'todo-tree)
  2259. (org-check-for-org-mode)
  2260. (org-let lprops
  2261. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2262. (regexp-quote org-match) "\\>"))))
  2263. ((eq type 'occur-tree)
  2264. (org-check-for-org-mode)
  2265. (org-let lprops '(org-occur org-match)))
  2266. ((functionp type)
  2267. (org-let lprops '(funcall type org-match)))
  2268. ((fboundp type)
  2269. (org-let lprops '(funcall type org-match)))
  2270. (t (error "Invalid custom agenda command type %s" type))))
  2271. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2272. ((equal org-keys "C")
  2273. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2274. (customize-variable 'org-agenda-custom-commands))
  2275. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2276. ((equal org-keys "s") (call-interactively 'org-search-view))
  2277. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2278. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2279. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2280. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2281. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2282. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2283. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2284. (org-add-hook
  2285. 'post-command-hook
  2286. (lambda ()
  2287. (unless (current-message)
  2288. (let* ((m (org-agenda-get-any-marker))
  2289. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2290. (when note
  2291. (message (concat
  2292. "FLAGGING-NOTE ([?] for more info): "
  2293. (org-add-props
  2294. (replace-regexp-in-string
  2295. "\\\\n" "//"
  2296. (copy-sequence note))
  2297. nil 'face 'org-warning)))))))
  2298. t t))
  2299. ((equal org-keys "L")
  2300. (unless (derived-mode-p 'org-mode)
  2301. (error "This is not an Org-mode file"))
  2302. (unless restriction
  2303. (put 'org-agenda-files 'org-restrict (list bfn))
  2304. (org-call-with-arg 'org-timeline arg)))
  2305. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2306. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2307. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2308. (t (error "Invalid agenda key"))))))
  2309. (defun org-agenda-append-agenda ()
  2310. "Append another agenda view to the current one.
  2311. This function allows interactive building of block agendas.
  2312. Agenda views are separated by `org-agenda-block-separator'."
  2313. (interactive)
  2314. (unless (derived-mode-p 'org-agenda-mode)
  2315. (error "Can only append from within agenda buffer"))
  2316. (let ((org-agenda-multi t))
  2317. (org-agenda)
  2318. (widen)
  2319. (org-agenda-finalize)
  2320. (org-agenda-fit-window-to-buffer)))
  2321. (defun org-agenda-normalize-custom-commands (cmds)
  2322. (delq nil
  2323. (mapcar
  2324. (lambda (x)
  2325. (cond ((stringp (cdr x)) nil)
  2326. ((stringp (nth 1 x)) x)
  2327. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2328. (t (cons (car x) (cons "" (cdr x))))))
  2329. cmds)))
  2330. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2331. "The user interface for selecting an agenda command."
  2332. (catch 'exit
  2333. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2334. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2335. (region-p (org-region-active-p))
  2336. (custom org-agenda-custom-commands)
  2337. (selstring "")
  2338. restriction second-time
  2339. c entry key type match prefixes rmheader header-end custom1 desc
  2340. line lines left right n n1)
  2341. (save-window-excursion
  2342. (delete-other-windows)
  2343. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2344. (erase-buffer)
  2345. (insert (eval-when-compile
  2346. (let ((header
  2347. "Press key for an agenda command: < Buffer, subtree/region restriction
  2348. -------------------------------- > Remove restriction
  2349. a Agenda for current week or day e Export agenda views
  2350. t List of all TODO entries T Entries with special TODO kwd
  2351. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2352. s Search for keywords S Like s, but only TODO entries
  2353. L Timeline for current buffer # List stuck projects (!=configure)
  2354. / Multi-occur C Configure custom agenda commands
  2355. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2356. ")
  2357. (start 0))
  2358. (while (string-match
  2359. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2360. header start)
  2361. (setq start (match-end 0))
  2362. (add-text-properties (match-beginning 2) (match-end 2)
  2363. '(face bold) header))
  2364. header)))
  2365. (setq header-end (move-marker (make-marker) (point)))
  2366. (while t
  2367. (setq custom1 custom)
  2368. (when (eq rmheader t)
  2369. (org-goto-line 1)
  2370. (re-search-forward ":" nil t)
  2371. (delete-region (match-end 0) (point-at-eol))
  2372. (forward-char 1)
  2373. (looking-at "-+")
  2374. (delete-region (match-end 0) (point-at-eol))
  2375. (move-marker header-end (match-end 0)))
  2376. (goto-char header-end)
  2377. (delete-region (point) (point-max))
  2378. ;; Produce all the lines that describe custom commands and prefixes
  2379. (setq lines nil)
  2380. (while (setq entry (pop custom1))
  2381. (setq key (car entry) desc (nth 1 entry)
  2382. type (nth 2 entry)
  2383. match (nth 3 entry))
  2384. (if (> (length key) 1)
  2385. (add-to-list 'prefixes (string-to-char key))
  2386. (setq line
  2387. (format
  2388. "%-4s%-14s"
  2389. (org-add-props (copy-sequence key)
  2390. '(face bold))
  2391. (cond
  2392. ((string-match "\\S-" desc) desc)
  2393. ((eq type 'agenda) "Agenda for current week or day")
  2394. ((eq type 'alltodo) "List of all TODO entries")
  2395. ((eq type 'search) "Word search")
  2396. ((eq type 'stuck) "List of stuck projects")
  2397. ((eq type 'todo) "TODO keyword")
  2398. ((eq type 'tags) "Tags query")
  2399. ((eq type 'tags-todo) "Tags (TODO)")
  2400. ((eq type 'tags-tree) "Tags tree")
  2401. ((eq type 'todo-tree) "TODO kwd tree")
  2402. ((eq type 'occur-tree) "Occur tree")
  2403. ((functionp type) (if (symbolp type)
  2404. (symbol-name type)
  2405. "Lambda expression"))
  2406. (t "???"))))
  2407. (if org-agenda-menu-show-matcher
  2408. (setq line
  2409. (concat line ": "
  2410. (cond
  2411. ((stringp match)
  2412. (setq match (copy-sequence match))
  2413. (org-add-props match nil 'face 'org-warning))
  2414. (match
  2415. (format "set of %d commands" (length match)))
  2416. (t ""))))
  2417. (if (org-string-nw-p match)
  2418. (add-text-properties
  2419. 0 (length line) (list 'help-echo
  2420. (concat "Matcher: "match)) line)))
  2421. (push line lines)))
  2422. (setq lines (nreverse lines))
  2423. (when prefixes
  2424. (mapc (lambda (x)
  2425. (push
  2426. (format "%s %s"
  2427. (org-add-props (char-to-string x)
  2428. nil 'face 'bold)
  2429. (or (cdr (assoc (concat selstring
  2430. (char-to-string x))
  2431. prefix-descriptions))
  2432. "Prefix key"))
  2433. lines))
  2434. prefixes))
  2435. ;; Check if we should display in two columns
  2436. (if org-agenda-menu-two-columns
  2437. (progn
  2438. (setq n (length lines)
  2439. n1 (+ (/ n 2) (mod n 2))
  2440. right (nthcdr n1 lines)
  2441. left (copy-sequence lines))
  2442. (setcdr (nthcdr (1- n1) left) nil))
  2443. (setq left lines right nil))
  2444. (while left
  2445. (insert "\n" (pop left))
  2446. (when right
  2447. (if (< (current-column) 40)
  2448. (move-to-column 40 t)
  2449. (insert " "))
  2450. (insert (pop right))))
  2451. ;; Make the window the right size
  2452. (goto-char (point-min))
  2453. (if second-time
  2454. (if (not (pos-visible-in-window-p (point-max)))
  2455. (org-fit-window-to-buffer))
  2456. (setq second-time t)
  2457. (org-fit-window-to-buffer))
  2458. ;; Ask for selection
  2459. (message "Press key for agenda command%s:"
  2460. (if (or restrict-ok org-agenda-overriding-restriction)
  2461. (if org-agenda-overriding-restriction
  2462. " (restriction lock active)"
  2463. (if restriction
  2464. (format " (restricted to %s)" restriction)
  2465. " (unrestricted)"))
  2466. ""))
  2467. (setq c (read-char-exclusive))
  2468. (message "")
  2469. (cond
  2470. ((assoc (char-to-string c) custom)
  2471. (setq selstring (concat selstring (char-to-string c)))
  2472. (throw 'exit (cons selstring restriction)))
  2473. ((memq c prefixes)
  2474. (setq selstring (concat selstring (char-to-string c))
  2475. prefixes nil
  2476. rmheader (or rmheader t)
  2477. custom (delq nil (mapcar
  2478. (lambda (x)
  2479. (if (or (= (length (car x)) 1)
  2480. (/= (string-to-char (car x)) c))
  2481. nil
  2482. (cons (substring (car x) 1) (cdr x))))
  2483. custom))))
  2484. ((eq c ?*)
  2485. (call-interactively 'org-toggle-sticky-agenda)
  2486. (sit-for 2))
  2487. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2488. (message "Restriction is only possible in Org-mode buffers")
  2489. (ding) (sit-for 1))
  2490. ((eq c ?1)
  2491. (org-agenda-remove-restriction-lock 'noupdate)
  2492. (setq restriction 'buffer))
  2493. ((eq c ?0)
  2494. (org-agenda-remove-restriction-lock 'noupdate)
  2495. (setq restriction (if region-p 'region 'subtree)))
  2496. ((eq c ?<)
  2497. (org-agenda-remove-restriction-lock 'noupdate)
  2498. (setq restriction
  2499. (cond
  2500. ((eq restriction 'buffer)
  2501. (if region-p 'region 'subtree))
  2502. ((memq restriction '(subtree region))
  2503. nil)
  2504. (t 'buffer))))
  2505. ((eq c ?>)
  2506. (org-agenda-remove-restriction-lock 'noupdate)
  2507. (setq restriction nil))
  2508. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2509. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2510. ((and (> (length selstring) 0) (eq c ?\d))
  2511. (delete-window)
  2512. (org-agenda-get-restriction-and-command prefix-descriptions))
  2513. ((equal c ?q) (error "Abort"))
  2514. (t (error "Invalid key %c" c))))))))
  2515. (defun org-agenda-fit-window-to-buffer ()
  2516. "Fit the window to the buffer size."
  2517. (and (memq org-agenda-window-setup '(reorganize-frame))
  2518. (fboundp 'fit-window-to-buffer)
  2519. (org-fit-window-to-buffer
  2520. nil
  2521. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2522. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2523. (defvar org-cmd nil)
  2524. (defvar org-agenda-overriding-cmd nil)
  2525. (defvar org-agenda-overriding-arguments nil)
  2526. (defvar org-agenda-overriding-cmd-arguments nil)
  2527. (defun org-agenda-run-series (name series)
  2528. (org-let (nth 1 series) '(org-agenda-prepare name))
  2529. ;; We need to reset agenda markers here, because when constructing a
  2530. ;; block agenda, the individual blocks do not do that.
  2531. (org-agenda-reset-markers)
  2532. (let* ((org-agenda-multi t)
  2533. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2534. (cmds (car series))
  2535. (gprops (nth 1 series))
  2536. match ;; The byte compiler incorrectly complains about this. Keep it!
  2537. org-cmd type lprops)
  2538. (while (setq org-cmd (pop cmds))
  2539. (setq type (car org-cmd)
  2540. match (eval (nth 1 org-cmd))
  2541. lprops (nth 2 org-cmd))
  2542. (let ((org-agenda-overriding-arguments
  2543. (if (eq org-agenda-overriding-cmd org-cmd)
  2544. (or org-agenda-overriding-arguments
  2545. org-agenda-overriding-cmd-arguments))))
  2546. (cond
  2547. ((eq type 'agenda)
  2548. (org-let2 gprops lprops
  2549. '(call-interactively 'org-agenda-list)))
  2550. ((eq type 'alltodo)
  2551. (org-let2 gprops lprops
  2552. '(call-interactively 'org-todo-list)))
  2553. ((eq type 'search)
  2554. (org-let2 gprops lprops
  2555. '(org-search-view current-prefix-arg match nil)))
  2556. ((eq type 'stuck)
  2557. (org-let2 gprops lprops
  2558. '(call-interactively 'org-agenda-list-stuck-projects)))
  2559. ((eq type 'tags)
  2560. (org-let2 gprops lprops
  2561. '(org-tags-view current-prefix-arg match)))
  2562. ((eq type 'tags-todo)
  2563. (org-let2 gprops lprops
  2564. '(org-tags-view '(4) match)))
  2565. ((eq type 'todo)
  2566. (org-let2 gprops lprops
  2567. '(org-todo-list match)))
  2568. ((fboundp type)
  2569. (org-let2 gprops lprops
  2570. '(funcall type match)))
  2571. (t (error "Invalid type in command series")))))
  2572. (widen)
  2573. (let ((inhibit-read-only t))
  2574. (add-text-properties (point-min) (point-max)
  2575. `(org-serie t org-serie-redo-cmd ,redo)))
  2576. (setq org-agenda-redo-command redo)
  2577. (goto-char (point-min)))
  2578. (org-agenda-fit-window-to-buffer)
  2579. (org-let (nth 1 series) '(org-agenda-finalize)))
  2580. ;;;###autoload
  2581. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2582. "Run an agenda command in batch mode and send the result to STDOUT.
  2583. If CMD-KEY is a string of length 1, it is used as a key in
  2584. `org-agenda-custom-commands' and triggers this command. If it is a
  2585. longer string it is used as a tags/todo match string.
  2586. Parameters are alternating variable names and values that will be bound
  2587. before running the agenda command."
  2588. (org-eval-in-environment (org-make-parameter-alist parameters)
  2589. (if (> (length cmd-key) 2)
  2590. (org-tags-view nil cmd-key)
  2591. (org-agenda nil cmd-key)))
  2592. (set-buffer org-agenda-buffer-name)
  2593. (princ (buffer-string)))
  2594. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2595. (defvar org-agenda-info nil)
  2596. ;;;###autoload
  2597. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2598. "Run an agenda command in batch mode and send the result to STDOUT.
  2599. If CMD-KEY is a string of length 1, it is used as a key in
  2600. `org-agenda-custom-commands' and triggers this command. If it is a
  2601. longer string it is used as a tags/todo match string.
  2602. Parameters are alternating variable names and values that will be bound
  2603. before running the agenda command.
  2604. The output gives a line for each selected agenda item. Each
  2605. item is a list of comma-separated values, like this:
  2606. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2607. category The category of the item
  2608. head The headline, without TODO kwd, TAGS and PRIORITY
  2609. type The type of the agenda entry, can be
  2610. todo selected in TODO match
  2611. tagsmatch selected in tags match
  2612. diary imported from diary
  2613. deadline a deadline on given date
  2614. scheduled scheduled on given date
  2615. timestamp entry has timestamp on given date
  2616. closed entry was closed on given date
  2617. upcoming-deadline warning about deadline
  2618. past-scheduled forwarded scheduled item
  2619. block entry has date block including g. date
  2620. todo The todo keyword, if any
  2621. tags All tags including inherited ones, separated by colons
  2622. date The relevant date, like 2007-2-14
  2623. time The time, like 15:00-16:50
  2624. extra Sting with extra planning info
  2625. priority-l The priority letter if any was given
  2626. priority-n The computed numerical priority
  2627. agenda-day The day in the agenda where this is listed"
  2628. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2629. (org-make-parameter-alist parameters))
  2630. (if (> (length cmd-key) 2)
  2631. (org-tags-view nil cmd-key)
  2632. (org-agenda nil cmd-key)))
  2633. (set-buffer org-agenda-buffer-name)
  2634. (let* ((lines (org-split-string (buffer-string) "\n"))
  2635. line)
  2636. (while (setq line (pop lines))
  2637. (catch 'next
  2638. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2639. (setq org-agenda-info
  2640. (org-fix-agenda-info (text-properties-at 0 line)))
  2641. (princ
  2642. (mapconcat 'org-agenda-export-csv-mapper
  2643. '(org-category txt type todo tags date time extra
  2644. priority-letter priority agenda-day)
  2645. ","))
  2646. (princ "\n")))))
  2647. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2648. (defun org-fix-agenda-info (props)
  2649. "Make sure all properties on an agenda item have a canonical form.
  2650. This ensures the export commands can easily use it."
  2651. (let (tmp re)
  2652. (when (setq tmp (plist-get props 'tags))
  2653. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2654. (when (setq tmp (plist-get props 'date))
  2655. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2656. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2657. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2658. (setq tmp (calendar-date-string tmp)))
  2659. (setq props (plist-put props 'date tmp)))
  2660. (when (setq tmp (plist-get props 'day))
  2661. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2662. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2663. (setq tmp (calendar-date-string tmp)))
  2664. (setq props (plist-put props 'day tmp))
  2665. (setq props (plist-put props 'agenda-day tmp)))
  2666. (when (setq tmp (plist-get props 'txt))
  2667. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2668. (plist-put props 'priority-letter (match-string 1 tmp))
  2669. (setq tmp (replace-match "" t t tmp)))
  2670. (when (and (setq re (plist-get props 'org-todo-regexp))
  2671. (setq re (concat "\\`\\.*" re " ?"))
  2672. (string-match re tmp))
  2673. (plist-put props 'todo (match-string 1 tmp))
  2674. (setq tmp (replace-match "" t t tmp)))
  2675. (plist-put props 'txt tmp)))
  2676. props)
  2677. (defun org-agenda-export-csv-mapper (prop)
  2678. (let ((res (plist-get org-agenda-info prop)))
  2679. (setq res
  2680. (cond
  2681. ((not res) "")
  2682. ((stringp res) res)
  2683. (t (prin1-to-string res))))
  2684. (while (string-match "," res)
  2685. (setq res (replace-match ";" t t res)))
  2686. (org-trim res)))
  2687. ;;;###autoload
  2688. (defun org-store-agenda-views (&rest parameters)
  2689. (interactive)
  2690. (eval (list 'org-batch-store-agenda-views)))
  2691. ;;;###autoload
  2692. (defmacro org-batch-store-agenda-views (&rest parameters)
  2693. "Run all custom agenda commands that have a file argument."
  2694. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2695. (pop-up-frames nil)
  2696. (dir default-directory)
  2697. (pars (org-make-parameter-alist parameters))
  2698. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2699. (save-window-excursion
  2700. (while cmds
  2701. (setq cmd (pop cmds)
  2702. thiscmdkey (car cmd)
  2703. thiscmdcmd (cdr cmd)
  2704. match (nth 2 thiscmdcmd)
  2705. bufname (if org-agenda-sticky
  2706. (or (and (stringp match)
  2707. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2708. (format "*Org Agenda(%s)*" thiscmdkey))
  2709. org-agenda-buffer-name)
  2710. cmd-or-set (nth 2 cmd)
  2711. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2712. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2713. (if (stringp files) (setq files (list files)))
  2714. (when files
  2715. (org-eval-in-environment (append org-agenda-exporter-settings
  2716. opts pars)
  2717. (org-agenda nil thiscmdkey))
  2718. (set-buffer bufname)
  2719. (while files
  2720. (org-eval-in-environment (append org-agenda-exporter-settings
  2721. opts pars)
  2722. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2723. (and (get-buffer bufname)
  2724. (kill-buffer bufname)))))))
  2725. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2726. (defvar org-agenda-current-span nil
  2727. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2728. (defun org-agenda-mark-header-line (pos)
  2729. "Mark the line at POS as an agenda structure header."
  2730. (save-excursion
  2731. (goto-char pos)
  2732. (put-text-property (point-at-bol) (point-at-eol)
  2733. 'org-agenda-structural-header t)
  2734. (when org-agenda-title-append
  2735. (put-text-property (point-at-bol) (point-at-eol)
  2736. 'org-agenda-title-append org-agenda-title-append))))
  2737. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2738. (defvar org-agenda-write-buffer-name "Agenda View")
  2739. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2740. "Write the current buffer (an agenda view) as a file.
  2741. Depending on the extension of the file name, plain text (.txt),
  2742. HTML (.html or .htm) or Postscript (.ps) is produced.
  2743. If the extension is .ics, run icalendar export over all files used
  2744. to construct the agenda and limit the export to entries listed in the
  2745. agenda now.
  2746. With prefix argument OPEN, open the new file immediately.
  2747. If NOSETTINGS is given, do not scope the settings of
  2748. `org-agenda-exporter-settings' into the export commands. This is used when
  2749. the settings have already been scoped and we do not wish to overrule other,
  2750. higher priority settings.
  2751. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2752. (interactive "FWrite agenda to file: \nP")
  2753. (if (not (file-writable-p file))
  2754. (error "Cannot write agenda to file %s" file))
  2755. (org-let (if nosettings nil org-agenda-exporter-settings)
  2756. '(save-excursion
  2757. (save-window-excursion
  2758. (org-agenda-mark-filtered-text)
  2759. (let ((bs (copy-sequence (buffer-string))) beg)
  2760. (org-agenda-unmark-filtered-text)
  2761. (with-temp-buffer
  2762. (rename-buffer org-agenda-write-buffer-name t)
  2763. (set-buffer-modified-p nil)
  2764. (insert bs)
  2765. (org-agenda-remove-marked-text 'org-filtered)
  2766. (while (setq beg (text-property-any (point-min) (point-max)
  2767. 'org-filtered t))
  2768. (delete-region
  2769. beg (or (next-single-property-change beg 'org-filtered)
  2770. (point-max))))
  2771. (run-hooks 'org-agenda-before-write-hook)
  2772. (cond
  2773. ((org-bound-and-true-p org-mobile-creating-agendas)
  2774. (org-mobile-write-agenda-for-mobile file))
  2775. ((string-match "\\.html?\\'" file)
  2776. (require 'htmlize)
  2777. (set-buffer (htmlize-buffer (current-buffer)))
  2778. (when (and org-agenda-export-html-style
  2779. (string-match "<style>" org-agenda-export-html-style))
  2780. ;; replace <style> section with org-agenda-export-html-style
  2781. (goto-char (point-min))
  2782. (kill-region (- (search-forward "<style") 6)
  2783. (search-forward "</style>"))
  2784. (insert org-agenda-export-html-style))
  2785. (write-file file)
  2786. (kill-buffer (current-buffer))
  2787. (message "HTML written to %s" file))
  2788. ((string-match "\\.ps\\'" file)
  2789. (require 'ps-print)
  2790. (ps-print-buffer-with-faces file)
  2791. (message "Postscript written to %s" file))
  2792. ((string-match "\\.pdf\\'" file)
  2793. (require 'ps-print)
  2794. (ps-print-buffer-with-faces
  2795. (concat (file-name-sans-extension file) ".ps"))
  2796. (call-process "ps2pdf" nil nil nil
  2797. (expand-file-name
  2798. (concat (file-name-sans-extension file) ".ps"))
  2799. (expand-file-name file))
  2800. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2801. (message "PDF written to %s" file))
  2802. ((string-match "\\.ics\\'" file)
  2803. (require 'org-icalendar)
  2804. (let ((org-agenda-marker-table
  2805. (org-create-marker-find-array
  2806. (org-agenda-collect-markers)))
  2807. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2808. (org-combined-agenda-icalendar-file file))
  2809. (apply 'org-export-icalendar 'combine
  2810. (org-agenda-files nil 'ifmode))))
  2811. (t
  2812. (let ((bs (buffer-string)))
  2813. (find-file file)
  2814. (erase-buffer)
  2815. (insert bs)
  2816. (save-buffer 0)
  2817. (kill-buffer (current-buffer))
  2818. (message "Plain text written to %s" file))))))))
  2819. (set-buffer (or agenda-bufname
  2820. (and (called-interactively-p 'any) (buffer-name))
  2821. org-agenda-buffer-name)))
  2822. (when open (org-open-file file)))
  2823. (defvar org-agenda-tag-filter-overlays nil)
  2824. (defvar org-agenda-cat-filter-overlays nil)
  2825. (defun org-agenda-mark-filtered-text ()
  2826. "Mark all text hidden by filtering with a text property."
  2827. (let ((inhibit-read-only t))
  2828. (mapc
  2829. (lambda (o)
  2830. (when (equal (overlay-buffer o) (current-buffer))
  2831. (put-text-property
  2832. (overlay-start o) (overlay-end o)
  2833. 'org-filtered t)))
  2834. (append org-agenda-tag-filter-overlays
  2835. org-agenda-cat-filter-overlays))))
  2836. (defun org-agenda-unmark-filtered-text ()
  2837. "Remove the filtering text property."
  2838. (let ((inhibit-read-only t))
  2839. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2840. (defun org-agenda-remove-marked-text (property &optional value)
  2841. "Delete all text marked with VALUE of PROPERTY.
  2842. VALUE defaults to t."
  2843. (let (beg)
  2844. (setq value (or value t))
  2845. (while (setq beg (text-property-any (point-min) (point-max)
  2846. property value))
  2847. (delete-region
  2848. beg (or (next-single-property-change beg 'org-filtered)
  2849. (point-max))))))
  2850. (defun org-agenda-add-entry-text ()
  2851. "Add entry text to agenda lines.
  2852. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2853. entry text following headings shown in the agenda.
  2854. Drawers will be excluded, also the line with scheduling/deadline info."
  2855. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2856. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2857. (let (m txt)
  2858. (goto-char (point-min))
  2859. (while (not (eobp))
  2860. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2861. (beginning-of-line 2)
  2862. (setq txt (org-agenda-get-some-entry-text
  2863. m org-agenda-add-entry-text-maxlines " > "))
  2864. (end-of-line 1)
  2865. (if (string-match "\\S-" txt)
  2866. (insert "\n" txt)
  2867. (or (eobp) (forward-char 1))))))))
  2868. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2869. &rest keep)
  2870. "Extract entry text from MARKER, at most N-LINES lines.
  2871. This will ignore drawers etc, just get the text.
  2872. If INDENT is given, prefix every line with this string. If KEEP is
  2873. given, it is a list of symbols, defining stuff that should not be
  2874. removed from the entry content. Currently only `planning' is allowed here."
  2875. (let (txt drawer-re kwd-time-re ind)
  2876. (save-excursion
  2877. (with-current-buffer (marker-buffer marker)
  2878. (if (not (derived-mode-p 'org-mode))
  2879. (setq txt "")
  2880. (save-excursion
  2881. (save-restriction
  2882. (widen)
  2883. (goto-char marker)
  2884. (end-of-line 1)
  2885. (setq txt (buffer-substring
  2886. (min (1+ (point)) (point-max))
  2887. (progn (outline-next-heading) (point)))
  2888. drawer-re org-drawer-regexp
  2889. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2890. ".*\n?"))
  2891. (with-temp-buffer
  2892. (insert txt)
  2893. (when org-agenda-add-entry-text-descriptive-links
  2894. (goto-char (point-min))
  2895. (while (org-activate-bracket-links (point-max))
  2896. (add-text-properties (match-beginning 0) (match-end 0)
  2897. '(face org-link))))
  2898. (goto-char (point-min))
  2899. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2900. (set-text-properties (match-beginning 0) (match-end 0)
  2901. nil))
  2902. (goto-char (point-min))
  2903. (while (re-search-forward drawer-re nil t)
  2904. (delete-region
  2905. (match-beginning 0)
  2906. (progn (re-search-forward
  2907. "^[ \t]*:END:.*\n?" nil 'move)
  2908. (point))))
  2909. (unless (member 'planning keep)
  2910. (goto-char (point-min))
  2911. (while (re-search-forward kwd-time-re nil t)
  2912. (replace-match "")))
  2913. (goto-char (point-min))
  2914. (when org-agenda-entry-text-exclude-regexps
  2915. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2916. (while (setq re (pop re-list))
  2917. (goto-char (point-min))
  2918. (while (re-search-forward re nil t)
  2919. (replace-match "")))))
  2920. (goto-char (point-max))
  2921. (skip-chars-backward " \t\n")
  2922. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2923. ;; find and remove min common indentation
  2924. (goto-char (point-min))
  2925. (untabify (point-min) (point-max))
  2926. (setq ind (org-get-indentation))
  2927. (while (not (eobp))
  2928. (unless (looking-at "[ \t]*$")
  2929. (setq ind (min ind (org-get-indentation))))
  2930. (beginning-of-line 2))
  2931. (goto-char (point-min))
  2932. (while (not (eobp))
  2933. (unless (looking-at "[ \t]*$")
  2934. (move-to-column ind)
  2935. (delete-region (point-at-bol) (point)))
  2936. (beginning-of-line 2))
  2937. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2938. (goto-char (point-min))
  2939. (when indent
  2940. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2941. (replace-match indent t t)))
  2942. (goto-char (point-min))
  2943. (while (looking-at "[ \t]*\n") (replace-match ""))
  2944. (goto-char (point-max))
  2945. (when (> (org-current-line)
  2946. n-lines)
  2947. (org-goto-line (1+ n-lines))
  2948. (backward-char 1))
  2949. (setq txt (buffer-substring (point-min) (point)))))))))
  2950. txt))
  2951. (defun org-agenda-collect-markers ()
  2952. "Collect the markers pointing to entries in the agenda buffer."
  2953. (let (m markers)
  2954. (save-excursion
  2955. (goto-char (point-min))
  2956. (while (not (eobp))
  2957. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2958. (org-get-at-bol 'org-marker)))
  2959. (push m markers))
  2960. (beginning-of-line 2)))
  2961. (nreverse markers)))
  2962. (defun org-create-marker-find-array (marker-list)
  2963. "Create a alist of files names with all marker positions in that file."
  2964. (let (f tbl m a p)
  2965. (while (setq m (pop marker-list))
  2966. (setq p (marker-position m)
  2967. f (buffer-file-name (or (buffer-base-buffer
  2968. (marker-buffer m))
  2969. (marker-buffer m))))
  2970. (if (setq a (assoc f tbl))
  2971. (push (marker-position m) (cdr a))
  2972. (push (list f p) tbl)))
  2973. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2974. tbl)))
  2975. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2976. (defun org-check-agenda-marker-table ()
  2977. "Check of the current entry is on the marker list."
  2978. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2979. a)
  2980. (and (setq a (assoc file org-agenda-marker-table))
  2981. (save-match-data
  2982. (save-excursion
  2983. (org-back-to-heading t)
  2984. (member (point) (cdr a)))))))
  2985. (defun org-check-for-org-mode ()
  2986. "Make sure current buffer is in org-mode. Error if not."
  2987. (or (derived-mode-p 'org-mode)
  2988. (error "Cannot execute org-mode agenda command on buffer in %s"
  2989. major-mode)))
  2990. ;;; Agenda prepare and finalize
  2991. (defvar org-agenda-multi nil) ; dynamically scoped
  2992. (defvar org-agenda-pre-window-conf nil)
  2993. (defvar org-agenda-columns-active nil)
  2994. (defvar org-agenda-name nil)
  2995. (defvar org-agenda-tag-filter nil)
  2996. (defvar org-agenda-category-filter nil)
  2997. (defvar org-agenda-top-category-filter nil)
  2998. (defvar org-agenda-tag-filter-while-redo nil)
  2999. (defvar org-agenda-tag-filter-preset nil
  3000. "A preset of the tags filter used for secondary agenda filtering.
  3001. This must be a list of strings, each string must be a single tag preceded
  3002. by \"+\" or \"-\".
  3003. This variable should not be set directly, but agenda custom commands can
  3004. bind it in the options section. The preset filter is a global property of
  3005. the entire agenda view. In a block agenda, it will not work reliably to
  3006. define a filter for one of the individual blocks. You need to set it in
  3007. the global options and expect it to be applied to the entire view.")
  3008. (defvar org-agenda-category-filter-preset nil
  3009. "A preset of the category filter used for secondary agenda filtering.
  3010. This must be a list of strings, each string must be a single category
  3011. preceded by \"+\" or \"-\".
  3012. This variable should not be set directly, but agenda custom commands can
  3013. bind it in the options section. The preset filter is a global property of
  3014. the entire agenda view. In a block agenda, it will not work reliably to
  3015. define a filter for one of the individual blocks. You need to set it in
  3016. the global options and expect it to be applied to the entire view.")
  3017. (defun org-agenda-use-sticky-p ()
  3018. "Return non-nil if an agenda buffer named
  3019. `org-agenda-buffer-name' exists and should be shown instead of
  3020. generating a new one."
  3021. (and
  3022. ;; turned off by user
  3023. org-agenda-sticky
  3024. ;; For multi-agenda buffer already exists
  3025. (not org-agenda-multi)
  3026. ;; buffer found
  3027. (get-buffer org-agenda-buffer-name)
  3028. ;; C-u parameter is same as last call
  3029. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3030. (and
  3031. (equal current-prefix-arg
  3032. org-agenda-last-prefix-arg)
  3033. ;; In case user turned stickiness on, while having existing
  3034. ;; Agenda buffer active, don't reuse that buffer, because it
  3035. ;; does not have org variables local
  3036. org-agenda-this-buffer-is-sticky))))
  3037. (defun org-agenda-prepare-window (abuf)
  3038. "Setup agenda buffer in the window."
  3039. (let* ((awin (get-buffer-window abuf))
  3040. wconf)
  3041. (cond
  3042. ((equal (current-buffer) abuf) nil)
  3043. (awin (select-window awin))
  3044. ((not (setq wconf (current-window-configuration))))
  3045. ((equal org-agenda-window-setup 'current-window)
  3046. (org-pop-to-buffer-same-window abuf))
  3047. ((equal org-agenda-window-setup 'other-window)
  3048. (org-switch-to-buffer-other-window abuf))
  3049. ((equal org-agenda-window-setup 'other-frame)
  3050. (switch-to-buffer-other-frame abuf))
  3051. ((equal org-agenda-window-setup 'reorganize-frame)
  3052. (delete-other-windows)
  3053. (org-switch-to-buffer-other-window abuf)))
  3054. ;; additional test in case agenda is invoked from within agenda
  3055. ;; buffer via elisp link
  3056. (unless (equal (current-buffer) abuf)
  3057. (org-pop-to-buffer-same-window abuf))
  3058. (setq org-agenda-pre-window-conf
  3059. (or org-agenda-pre-window-conf wconf))))
  3060. (defun org-agenda-prepare (&optional name)
  3061. (if (org-agenda-use-sticky-p)
  3062. (progn
  3063. ;; Popup existing buffer
  3064. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3065. (message "Sticky Agenda buffer, use `r' to refresh")
  3066. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3067. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3068. (setq org-todo-keywords-for-agenda nil)
  3069. (setq org-drawers-for-agenda nil)
  3070. (unless org-agenda-persistent-filter
  3071. (setq org-agenda-tag-filter nil
  3072. org-agenda-category-filter nil))
  3073. (put 'org-agenda-tag-filter :preset-filter
  3074. org-agenda-tag-filter-preset)
  3075. (put 'org-agenda-category-filter :preset-filter
  3076. org-agenda-category-filter-preset)
  3077. (if org-agenda-multi
  3078. (progn
  3079. (setq buffer-read-only nil)
  3080. (goto-char (point-max))
  3081. (unless (or (bobp) org-agenda-compact-blocks
  3082. (not org-agenda-block-separator))
  3083. (insert "\n"
  3084. (if (stringp org-agenda-block-separator)
  3085. org-agenda-block-separator
  3086. (make-string (window-width) org-agenda-block-separator))
  3087. "\n"))
  3088. (narrow-to-region (point) (point-max)))
  3089. (setq org-done-keywords-for-agenda nil)
  3090. ;; Setting any org variables that are in org-agenda-local-vars
  3091. ;; list need to be done after the prepare call
  3092. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3093. (setq buffer-read-only nil)
  3094. (org-agenda-reset-markers)
  3095. (let ((inhibit-read-only t)) (erase-buffer))
  3096. (org-agenda-mode)
  3097. (setq org-agenda-buffer (current-buffer))
  3098. (setq org-agenda-contributing-files nil)
  3099. (setq org-agenda-columns-active nil)
  3100. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3101. (setq org-todo-keywords-for-agenda
  3102. (org-uniquify org-todo-keywords-for-agenda))
  3103. (setq org-done-keywords-for-agenda
  3104. (org-uniquify org-done-keywords-for-agenda))
  3105. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3106. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3107. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3108. (and name (not org-agenda-name)
  3109. (org-set-local 'org-agenda-name name)))
  3110. (setq buffer-read-only nil)))
  3111. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3112. (defun org-agenda-finalize ()
  3113. "Finishing touch for the agenda buffer, called just before displaying it."
  3114. (unless org-agenda-multi
  3115. (save-excursion
  3116. (let ((inhibit-read-only t))
  3117. (goto-char (point-min))
  3118. (while (org-activate-bracket-links (point-max))
  3119. (add-text-properties (match-beginning 0) (match-end 0)
  3120. '(face org-link)))
  3121. (org-agenda-align-tags)
  3122. (unless org-agenda-with-colors
  3123. (remove-text-properties (point-min) (point-max) '(face nil))))
  3124. (if (and (boundp 'org-agenda-overriding-columns-format)
  3125. org-agenda-overriding-columns-format)
  3126. (org-set-local 'org-agenda-overriding-columns-format
  3127. org-agenda-overriding-columns-format))
  3128. (if (and (boundp 'org-agenda-view-columns-initially)
  3129. org-agenda-view-columns-initially)
  3130. (org-agenda-columns))
  3131. (when org-agenda-fontify-priorities
  3132. (org-agenda-fontify-priorities))
  3133. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3134. (org-agenda-dim-blocked-tasks))
  3135. (org-agenda-mark-clocking-task)
  3136. (when org-agenda-entry-text-mode
  3137. (org-agenda-entry-text-hide)
  3138. (org-agenda-entry-text-show))
  3139. (if (functionp 'org-habit-insert-consistency-graphs)
  3140. (org-habit-insert-consistency-graphs))
  3141. (run-hooks 'org-agenda-finalize-hook)
  3142. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3143. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3144. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3145. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3146. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3147. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3148. )))
  3149. (defun org-agenda-mark-clocking-task ()
  3150. "Mark the current clock entry in the agenda if it is present."
  3151. (mapc (lambda (o)
  3152. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3153. (delete-overlay o)))
  3154. (overlays-in (point-min) (point-max)))
  3155. (when (marker-buffer org-clock-hd-marker)
  3156. (save-excursion
  3157. (goto-char (point-min))
  3158. (let (s ov)
  3159. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3160. (goto-char s)
  3161. (when (equal (org-get-at-bol 'org-hd-marker)
  3162. org-clock-hd-marker)
  3163. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3164. (overlay-put ov 'type 'org-agenda-clocking)
  3165. (overlay-put ov 'face 'org-agenda-clocking)
  3166. (overlay-put ov 'help-echo
  3167. "The clock is running in this item")))))))
  3168. (defun org-agenda-fontify-priorities ()
  3169. "Make highest priority lines bold, and lowest italic."
  3170. (interactive)
  3171. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3172. (delete-overlay o)))
  3173. (overlays-in (point-min) (point-max)))
  3174. (save-excursion
  3175. (let ((inhibit-read-only t)
  3176. b e p ov h l)
  3177. (goto-char (point-min))
  3178. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3179. (setq h (or (get-char-property (point) 'org-highest-priority)
  3180. org-highest-priority)
  3181. l (or (get-char-property (point) 'org-lowest-priority)
  3182. org-lowest-priority)
  3183. p (string-to-char (match-string 1))
  3184. b (match-beginning 0)
  3185. e (if (eq org-agenda-fontify-priorities 'cookies)
  3186. (match-end 0)
  3187. (point-at-eol))
  3188. ov (make-overlay b e))
  3189. (overlay-put
  3190. ov 'face
  3191. (cond ((org-face-from-face-or-color
  3192. 'priority nil
  3193. (cdr (assoc p org-priority-faces))))
  3194. ((and (listp org-agenda-fontify-priorities)
  3195. (org-face-from-face-or-color
  3196. 'priority nil
  3197. (cdr (assoc p org-agenda-fontify-priorities)))))
  3198. ((equal p l) 'italic)
  3199. ((equal p h) 'bold)))
  3200. (overlay-put ov 'org-type 'org-priority)))))
  3201. (defun org-agenda-dim-blocked-tasks ()
  3202. "Dim currently blocked TODO's in the agenda display."
  3203. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3204. (delete-overlay o)))
  3205. (overlays-in (point-min) (point-max)))
  3206. (save-excursion
  3207. (let ((inhibit-read-only t)
  3208. (org-depend-tag-blocked nil)
  3209. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3210. org-blocked-by-checkboxes
  3211. invis1 b e p ov h l)
  3212. (goto-char (point-min))
  3213. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3214. (and pos (goto-char (1+ pos))))
  3215. (setq org-blocked-by-checkboxes nil invis1 invis)
  3216. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3217. (when (and marker
  3218. (with-current-buffer (marker-buffer marker)
  3219. (save-excursion (goto-char marker)
  3220. (org-entry-blocked-p))))
  3221. (if org-blocked-by-checkboxes (setq invis1 nil))
  3222. (setq b (if invis1
  3223. (max (point-min) (1- (point-at-bol)))
  3224. (point-at-bol))
  3225. e (point-at-eol)
  3226. ov (make-overlay b e))
  3227. (if invis1
  3228. (overlay-put ov 'invisible t)
  3229. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3230. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3231. (defvar org-agenda-skip-function nil
  3232. "Function to be called at each match during agenda construction.
  3233. If this function returns nil, the current match should not be skipped.
  3234. Otherwise, the function must return a position from where the search
  3235. should be continued.
  3236. This may also be a Lisp form, it will be evaluated.
  3237. Never set this variable using `setq' or so, because then it will apply
  3238. to all future agenda commands. If you do want a global skipping condition,
  3239. use the option `org-agenda-skip-function-global' instead.
  3240. The correct usage for `org-agenda-skip-function' is to bind it with
  3241. `let' to scope it dynamically into the agenda-constructing command.
  3242. A good way to set it is through options in `org-agenda-custom-commands'.")
  3243. (defun org-agenda-skip ()
  3244. "Throw to `:skip' in places that should be skipped.
  3245. Also moves point to the end of the skipped region, so that search can
  3246. continue from there."
  3247. (let ((p (point-at-bol)) to)
  3248. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3249. (get-text-property p :org-archived)
  3250. (org-end-of-subtree t)
  3251. (throw :skip t))
  3252. (and org-agenda-skip-comment-trees
  3253. (get-text-property p :org-comment)
  3254. (org-end-of-subtree t)
  3255. (throw :skip t))
  3256. (if (equal (char-after p) ?#) (throw :skip t))
  3257. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3258. (org-agenda-skip-eval org-agenda-skip-function)))
  3259. (goto-char to)
  3260. (throw :skip t))))
  3261. (defun org-agenda-skip-eval (form)
  3262. "If FORM is a function or a list, call (or eval) is and return result.
  3263. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3264. and match data are returned to the previous state no matter what these
  3265. functions do."
  3266. (let (fp)
  3267. (and form
  3268. (or (setq fp (functionp form))
  3269. (consp form))
  3270. (save-excursion
  3271. (save-match-data
  3272. (if fp
  3273. (funcall form)
  3274. (eval form)))))))
  3275. (defvar org-agenda-markers nil
  3276. "List of all currently active markers created by `org-agenda'.")
  3277. (defvar org-agenda-last-marker-time (org-float-time)
  3278. "Creation time of the last agenda marker.")
  3279. (defun org-agenda-new-marker (&optional pos)
  3280. "Return a new agenda marker.
  3281. Org-mode keeps a list of these markers and resets them when they are
  3282. no longer in use."
  3283. (let ((m (copy-marker (or pos (point)))))
  3284. (setq org-agenda-last-marker-time (org-float-time))
  3285. (if org-agenda-buffer
  3286. (with-current-buffer org-agenda-buffer
  3287. (push m org-agenda-markers))
  3288. (push m org-agenda-markers))
  3289. m))
  3290. (defun org-agenda-reset-markers ()
  3291. "Reset markers created by `org-agenda'."
  3292. (while org-agenda-markers
  3293. (move-marker (pop org-agenda-markers) nil)))
  3294. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3295. "Save relative positions of markers in region.
  3296. This check for agenda markers in all agenda buffers currently active."
  3297. (dolist (buf (buffer-list))
  3298. (with-current-buffer buf
  3299. (when (eq major-mode 'org-agenda-mode)
  3300. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3301. org-agenda-markers)))))
  3302. ;;; Entry text mode
  3303. (defun org-agenda-entry-text-show-here ()
  3304. "Add some text from the entry as context to the current line."
  3305. (let (m txt o)
  3306. (setq m (org-get-at-bol 'org-hd-marker))
  3307. (unless (marker-buffer m)
  3308. (error "No marker points to an entry here"))
  3309. (setq txt (concat "\n" (org-no-properties
  3310. (org-agenda-get-some-entry-text
  3311. m org-agenda-entry-text-maxlines " > "))))
  3312. (when (string-match "\\S-" txt)
  3313. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3314. (overlay-put o 'evaporate t)
  3315. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3316. (overlay-put o 'after-string txt))))
  3317. (defun org-agenda-entry-text-show ()
  3318. "Add entry context for all agenda lines."
  3319. (interactive)
  3320. (save-excursion
  3321. (goto-char (point-max))
  3322. (beginning-of-line 1)
  3323. (while (not (bobp))
  3324. (when (org-get-at-bol 'org-hd-marker)
  3325. (org-agenda-entry-text-show-here))
  3326. (beginning-of-line 0))))
  3327. (defun org-agenda-entry-text-hide ()
  3328. "Remove any shown entry context."
  3329. (delq nil
  3330. (mapcar (lambda (o)
  3331. (if (eq (overlay-get o 'org-overlay-type)
  3332. 'agenda-entry-content)
  3333. (progn (delete-overlay o) t)))
  3334. (overlays-in (point-min) (point-max)))))
  3335. (defun org-agenda-get-day-face (date)
  3336. "Return the face DATE should be displayed with."
  3337. (or (and (functionp org-agenda-day-face-function)
  3338. (funcall org-agenda-day-face-function date))
  3339. (cond ((org-agenda-todayp date)
  3340. 'org-agenda-date-today)
  3341. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3342. 'org-agenda-date-weekend)
  3343. (t 'org-agenda-date))))
  3344. ;;; Agenda timeline
  3345. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3346. (defun org-timeline (&optional dotodo)
  3347. "Show a time-sorted view of the entries in the current org file.
  3348. Only entries with a time stamp of today or later will be listed. With
  3349. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3350. under the current date.
  3351. If the buffer contains an active region, only check the region for
  3352. dates."
  3353. (interactive "P")
  3354. (let* ((dopast t)
  3355. (org-agenda-show-log-scoped org-agenda-show-log)
  3356. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3357. (current-buffer))))
  3358. (date (calendar-current-date))
  3359. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3360. (end (if (org-region-active-p) (region-end) (point-max)))
  3361. (day-numbers (org-get-all-dates
  3362. beg end 'no-ranges
  3363. t org-agenda-show-log-scoped ; always include today
  3364. org-timeline-show-empty-dates))
  3365. (org-deadline-warning-days 0)
  3366. (org-agenda-only-exact-dates t)
  3367. (today (org-today))
  3368. (past t)
  3369. args
  3370. s e rtn d emptyp)
  3371. (setq org-agenda-redo-command
  3372. (list 'progn
  3373. (list 'org-switch-to-buffer-other-window (current-buffer))
  3374. (list 'org-timeline (list 'quote dotodo))))
  3375. (if (not dopast)
  3376. ;; Remove past dates from the list of dates.
  3377. (setq day-numbers (delq nil (mapcar (lambda(x)
  3378. (if (>= x today) x nil))
  3379. day-numbers))))
  3380. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3381. (org-compile-prefix-format 'timeline)
  3382. (org-set-sorting-strategy 'timeline)
  3383. (if org-agenda-show-log-scoped (push :closed args))
  3384. (push :timestamp args)
  3385. (push :deadline args)
  3386. (push :scheduled args)
  3387. (push :sexp args)
  3388. (if dotodo (push :todo args))
  3389. (insert "Timeline of file " entry "\n")
  3390. (add-text-properties (point-min) (point)
  3391. (list 'face 'org-agenda-structure))
  3392. (org-agenda-mark-header-line (point-min))
  3393. (while (setq d (pop day-numbers))
  3394. (if (and (listp d) (eq (car d) :omitted))
  3395. (progn
  3396. (setq s (point))
  3397. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3398. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3399. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3400. (if (and (>= d today)
  3401. dopast
  3402. past)
  3403. (progn
  3404. (setq past nil)
  3405. (insert (make-string 79 ?-) "\n")))
  3406. (setq date (calendar-gregorian-from-absolute d))
  3407. (setq s (point))
  3408. (setq rtn (and (not emptyp)
  3409. (apply 'org-agenda-get-day-entries entry
  3410. date args)))
  3411. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3412. (progn
  3413. (insert
  3414. (if (stringp org-agenda-format-date)
  3415. (format-time-string org-agenda-format-date
  3416. (org-time-from-absolute date))
  3417. (funcall org-agenda-format-date date))
  3418. "\n")
  3419. (put-text-property s (1- (point)) 'face
  3420. (org-agenda-get-day-face date))
  3421. (put-text-property s (1- (point)) 'org-date-line t)
  3422. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3423. (if (equal d today)
  3424. (put-text-property s (1- (point)) 'org-today t))
  3425. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3426. (put-text-property s (1- (point)) 'day d)))))
  3427. (goto-char (point-min))
  3428. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3429. (point-min)))
  3430. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3431. (org-agenda-finalize)
  3432. (setq buffer-read-only t)))
  3433. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3434. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3435. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3436. not every single day in the range. If FORCE-TODAY is non-nil, make
  3437. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3438. inactive time stamps (those in square brackets) are included.
  3439. When EMPTY is non-nil, also include days without any entries."
  3440. (let ((re (concat
  3441. (if pre-re pre-re "")
  3442. (if inactive org-ts-regexp-both org-ts-regexp)))
  3443. dates dates1 date day day1 day2 ts1 ts2 pos)
  3444. (if force-today
  3445. (setq dates (list (org-today))))
  3446. (save-excursion
  3447. (goto-char beg)
  3448. (while (re-search-forward re end t)
  3449. (setq day (time-to-days (org-time-string-to-time
  3450. (substring (match-string 1) 0 10)
  3451. (current-buffer) (match-beginning 0))))
  3452. (or (memq day dates) (push day dates)))
  3453. (unless no-ranges
  3454. (goto-char beg)
  3455. (while (re-search-forward org-tr-regexp end t)
  3456. (setq pos (match-beginning 0))
  3457. (setq ts1 (substring (match-string 1) 0 10)
  3458. ts2 (substring (match-string 2) 0 10)
  3459. day1 (time-to-days (org-time-string-to-time
  3460. ts1 (current-buffer) pos))
  3461. day2 (time-to-days (org-time-string-to-time
  3462. ts2 (current-buffer) pos)))
  3463. (while (< (setq day1 (1+ day1)) day2)
  3464. (or (memq day1 dates) (push day1 dates)))))
  3465. (setq dates (sort dates '<))
  3466. (when empty
  3467. (while (setq day (pop dates))
  3468. (setq day2 (car dates))
  3469. (push day dates1)
  3470. (when (and day2 empty)
  3471. (if (or (eq empty t)
  3472. (and (numberp empty) (<= (- day2 day) empty)))
  3473. (while (< (setq day (1+ day)) day2)
  3474. (push (list day) dates1))
  3475. (push (cons :omitted (- day2 day)) dates1))))
  3476. (setq dates (nreverse dates1)))
  3477. dates)))
  3478. ;;; Agenda Daily/Weekly
  3479. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3480. "Start day for the agenda view.
  3481. Custom commands can set this variable in the options section.")
  3482. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3483. (defvar org-arg-loc nil) ; local variable
  3484. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3485. "List of types searched for when creating the daily/weekly agenda.
  3486. This variable is a list of symbols that controls the types of
  3487. items that appear in the daily/weekly agenda. Allowed symbols in this
  3488. list are are
  3489. :timestamp List items containing a date stamp or date range matching
  3490. the selected date. This includes sexp entries in
  3491. angular brackets.
  3492. :sexp List entries resulting from plain diary-like sexps.
  3493. :deadline List deadline due on that date. When the date is today,
  3494. also list any deadlines past due, or due within
  3495. `org-deadline-warning-days'. `:deadline' must appear before
  3496. `:scheduled' if the setting of
  3497. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3498. any effect.
  3499. :scheduled List all items which are scheduled for the given date.
  3500. The diary for *today* also contains items which were
  3501. scheduled earlier and are not yet marked DONE.
  3502. By default, all four types are turned on.
  3503. Never set this variable globally using `setq', because then it
  3504. will apply to all future agenda commands. Instead, bind it with
  3505. `let' to scope it dynamically into the agenda-constructing
  3506. command. A good way to set it is through options in
  3507. `org-agenda-custom-commands'. For a more flexible (though
  3508. somewhat less efficient) way of determining what is included in
  3509. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3510. ;;;###autoload
  3511. (defun org-agenda-list (&optional arg start-day span)
  3512. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3513. The view will be for the current day or week, but from the overview buffer
  3514. you will be able to go to other days/weeks.
  3515. With a numeric prefix argument in an interactive call, the agenda will
  3516. span ARG days. Lisp programs should instead specify SPAN to change
  3517. the number of days. SPAN defaults to `org-agenda-span'.
  3518. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3519. given in `org-agenda-start-on-weekday'."
  3520. (interactive "P")
  3521. (if org-agenda-overriding-arguments
  3522. (setq arg (car org-agenda-overriding-arguments)
  3523. start-day (nth 1 org-agenda-overriding-arguments)
  3524. span (nth 2 org-agenda-overriding-arguments)))
  3525. (if (and (integerp arg) (> arg 0))
  3526. (setq span arg arg nil))
  3527. (catch 'exit
  3528. (if org-agenda-sticky
  3529. (setq org-agenda-buffer-name
  3530. (cond ((and org-keys (stringp org-match))
  3531. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3532. (org-keys
  3533. (format "*Org Agenda(%s)*" org-keys))
  3534. (t "*Org Agenda(a)*"))))
  3535. (org-agenda-prepare "Day/Week")
  3536. (setq start-day (or start-day org-agenda-start-day))
  3537. (if (stringp start-day)
  3538. ;; Convert to an absolute day number
  3539. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3540. (org-compile-prefix-format 'agenda)
  3541. (org-set-sorting-strategy 'agenda)
  3542. (let* ((span (org-agenda-ndays-to-span
  3543. (or span org-agenda-ndays org-agenda-span)))
  3544. (today (org-today))
  3545. (sd (or start-day today))
  3546. (ndays (org-agenda-span-to-ndays span sd))
  3547. (org-agenda-start-on-weekday
  3548. (if (eq ndays 7)
  3549. org-agenda-start-on-weekday))
  3550. (thefiles (org-agenda-files nil 'ifmode))
  3551. (files thefiles)
  3552. (start (if (or (null org-agenda-start-on-weekday)
  3553. (< ndays 7))
  3554. sd
  3555. (let* ((nt (calendar-day-of-week
  3556. (calendar-gregorian-from-absolute sd)))
  3557. (n1 org-agenda-start-on-weekday)
  3558. (d (- nt n1)))
  3559. (- sd (+ (if (< d 0) 7 0) d)))))
  3560. (day-numbers (list start))
  3561. (day-cnt 0)
  3562. (inhibit-redisplay (not debug-on-error))
  3563. (org-agenda-show-log-scoped org-agenda-show-log)
  3564. s e rtn rtnall file date d start-pos end-pos todayp
  3565. clocktable-start clocktable-end filter)
  3566. (setq org-agenda-redo-command
  3567. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3568. (dotimes (n (1- ndays))
  3569. (push (1+ (car day-numbers)) day-numbers))
  3570. (setq day-numbers (nreverse day-numbers))
  3571. (setq clocktable-start (car day-numbers)
  3572. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3573. (org-set-local 'org-starting-day (car day-numbers))
  3574. (org-set-local 'org-arg-loc arg)
  3575. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3576. (unless org-agenda-compact-blocks
  3577. (let* ((d1 (car day-numbers))
  3578. (d2 (org-last day-numbers))
  3579. (w1 (org-days-to-iso-week d1))
  3580. (w2 (org-days-to-iso-week d2)))
  3581. (setq s (point))
  3582. (if org-agenda-overriding-header
  3583. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3584. nil 'face 'org-agenda-structure) "\n")
  3585. (insert (org-agenda-span-name span)
  3586. "-agenda"
  3587. (if (< (- d2 d1) 350)
  3588. (if (= w1 w2)
  3589. (format " (W%02d)" w1)
  3590. (format " (W%02d-W%02d)" w1 w2))
  3591. "")
  3592. ":\n")))
  3593. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3594. 'org-date-line t))
  3595. (org-agenda-mark-header-line s))
  3596. (while (setq d (pop day-numbers))
  3597. (setq date (calendar-gregorian-from-absolute d)
  3598. s (point))
  3599. (if (or (setq todayp (= d today))
  3600. (and (not start-pos) (= d sd)))
  3601. (setq start-pos (point))
  3602. (if (and start-pos (not end-pos))
  3603. (setq end-pos (point))))
  3604. (setq files thefiles
  3605. rtnall nil)
  3606. (while (setq file (pop files))
  3607. (catch 'nextfile
  3608. (org-check-agenda-file file)
  3609. (let ((org-agenda-entry-types org-agenda-entry-types))
  3610. (unless org-agenda-include-deadlines
  3611. (setq org-agenda-entry-types
  3612. (delq :deadline org-agenda-entry-types)))
  3613. (cond
  3614. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3615. (setq rtn (org-agenda-get-day-entries
  3616. file date :closed)))
  3617. (org-agenda-show-log-scoped
  3618. (setq rtn (apply 'org-agenda-get-day-entries
  3619. file date
  3620. (append '(:closed) org-agenda-entry-types))))
  3621. (t
  3622. (setq rtn (apply 'org-agenda-get-day-entries
  3623. file date
  3624. org-agenda-entry-types)))))
  3625. (setq rtnall (append rtnall rtn)))) ;; all entries
  3626. (if org-agenda-include-diary
  3627. (let ((org-agenda-search-headline-for-time t))
  3628. (require 'diary-lib)
  3629. (setq rtn (org-get-entries-from-diary date))
  3630. (setq rtnall (append rtnall rtn))))
  3631. (if (or rtnall org-agenda-show-all-dates)
  3632. (progn
  3633. (setq day-cnt (1+ day-cnt))
  3634. (insert
  3635. (if (stringp org-agenda-format-date)
  3636. (format-time-string org-agenda-format-date
  3637. (org-time-from-absolute date))
  3638. (funcall org-agenda-format-date date))
  3639. "\n")
  3640. (put-text-property s (1- (point)) 'face
  3641. (org-agenda-get-day-face date))
  3642. (put-text-property s (1- (point)) 'org-date-line t)
  3643. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3644. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3645. (when todayp
  3646. (put-text-property s (1- (point)) 'org-today t))
  3647. (setq rtnall
  3648. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3649. (if rtnall (insert ;; all entries
  3650. (org-agenda-finalize-entries rtnall)
  3651. "\n"))
  3652. (put-text-property s (1- (point)) 'day d)
  3653. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3654. (when (and org-agenda-clockreport-mode clocktable-start)
  3655. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3656. ;; the above line is to ensure the restricted range!
  3657. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3658. tbl)
  3659. (setq p (org-plist-delete p :block))
  3660. (setq p (plist-put p :tstart clocktable-start))
  3661. (setq p (plist-put p :tend clocktable-end))
  3662. (setq p (plist-put p :scope 'agenda))
  3663. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3664. (setq filter (or org-agenda-tag-filter-while-redo
  3665. (get 'org-agenda-tag-filter :preset-filter))))
  3666. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3667. (if (string-match "[<>=]" x)
  3668. ""
  3669. x))
  3670. filter ""))))
  3671. (setq tbl (apply 'org-get-clocktable p))
  3672. (insert tbl)))
  3673. (goto-char (point-min))
  3674. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3675. (unless (and (pos-visible-in-window-p (point-min))
  3676. (pos-visible-in-window-p (point-max)))
  3677. (goto-char (1- (point-max)))
  3678. (recenter -1)
  3679. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3680. (progn
  3681. (goto-char (or start-pos 1))
  3682. (recenter 1))))
  3683. (goto-char (or start-pos 1))
  3684. (add-text-properties (point-min) (point-max)
  3685. `(org-agenda-type agenda
  3686. org-last-args (,arg ,start-day ,span)
  3687. org-redo-cmd ,org-agenda-redo-command
  3688. org-serie-cmd ,org-cmd))
  3689. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3690. (org-agenda-show-clocking-issues))
  3691. (org-agenda-finalize)
  3692. (setq buffer-read-only t)
  3693. (message ""))))
  3694. (defun org-agenda-ndays-to-span (n)
  3695. "Return a span symbol for a span of N days, or N if none matches."
  3696. (cond ((symbolp n) n)
  3697. ((= n 1) 'day)
  3698. ((= n 7) 'week)
  3699. (t n)))
  3700. (defun org-agenda-span-to-ndays (span start-day)
  3701. "Return ndays from SPAN starting at START-DAY."
  3702. (cond ((numberp span) span)
  3703. ((eq span 'day) 1)
  3704. ((eq span 'week) 7)
  3705. ((eq span 'month)
  3706. (let ((date (calendar-gregorian-from-absolute start-day)))
  3707. (calendar-last-day-of-month (car date) (caddr date))))
  3708. ((eq span 'year)
  3709. (let ((date (calendar-gregorian-from-absolute start-day)))
  3710. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3711. (defun org-agenda-span-name (span)
  3712. "Return a SPAN name."
  3713. (if (null span)
  3714. ""
  3715. (if (symbolp span)
  3716. (capitalize (symbol-name span))
  3717. (format "%d days" span))))
  3718. ;;; Agenda word search
  3719. (defvar org-agenda-search-history nil)
  3720. (defvar org-search-syntax-table nil
  3721. "Special syntax table for org-mode search.
  3722. In this table, we have single quotes not as word constituents, to
  3723. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3724. (defvar org-mode-syntax-table) ; From org.el
  3725. (defun org-search-syntax-table ()
  3726. (unless org-search-syntax-table
  3727. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3728. (modify-syntax-entry ?' "." org-search-syntax-table)
  3729. (modify-syntax-entry ?` "." org-search-syntax-table))
  3730. org-search-syntax-table)
  3731. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3732. ;;;###autoload
  3733. (defun org-search-view (&optional todo-only string edit-at)
  3734. "Show all entries that contain a phrase or words or regular expressions.
  3735. With optional prefix argument TODO-ONLY, only consider entries that are
  3736. TODO entries. The argument STRING can be used to pass a default search
  3737. string into this function. If EDIT-AT is non-nil, it means that the
  3738. user should get a chance to edit this string, with cursor at position
  3739. EDIT-AT.
  3740. The search string can be viewed either as a phrase that should be found as
  3741. is, or it can be broken into a number of snippets, each of which must match
  3742. in a Boolean way to select an entry. The default depends on the variable
  3743. `org-agenda-search-view-always-boolean'.
  3744. Even if this is turned off (the default) you can always switch to
  3745. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3746. The default is a direct search of the whole phrase, where each space in
  3747. the search string can expand to an arbitrary amount of whitespace,
  3748. including newlines.
  3749. If using a Boolean search, the search string is split on whitespace and
  3750. each snippet is searched separately, with logical AND to select an entry.
  3751. Words prefixed with a minus must *not* occur in the entry. Words without
  3752. a prefix or prefixed with a plus must occur in the entry. Matching is
  3753. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3754. match whole words, not parts of a word) if
  3755. `org-agenda-search-view-force-full-words' is set (default is nil).
  3756. Boolean search snippets enclosed by curly braces are interpreted as
  3757. regular expressions that must or (when preceded with \"-\") must not
  3758. match in the entry. Snippets enclosed into double quotes will be taken
  3759. as a whole, to include whitespace.
  3760. - If the search string starts with an asterisk, search only in headlines.
  3761. - If (possibly after the leading star) the search string starts with an
  3762. exclamation mark, this also means to look at TODO entries only, an effect
  3763. that can also be achieved with a prefix argument.
  3764. - If (possibly after star and exclamation mark) the search string starts
  3765. with a colon, this will mean that the (non-regexp) snippets of the
  3766. Boolean search must match as full words.
  3767. This command searches the agenda files, and in addition the files listed
  3768. in `org-agenda-text-search-extra-files'."
  3769. (interactive "P")
  3770. (if org-agenda-overriding-arguments
  3771. (setq todo-only (car org-agenda-overriding-arguments)
  3772. string (nth 1 org-agenda-overriding-arguments)
  3773. edit-at (nth 2 org-agenda-overriding-arguments)))
  3774. (let* ((props (list 'face nil
  3775. 'done-face 'org-agenda-done
  3776. 'org-not-done-regexp org-not-done-regexp
  3777. 'org-todo-regexp org-todo-regexp
  3778. 'org-complex-heading-regexp org-complex-heading-regexp
  3779. 'mouse-face 'highlight
  3780. 'help-echo (format "mouse-2 or RET jump to location")))
  3781. (full-words org-agenda-search-view-force-full-words)
  3782. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3783. regexp rtn rtnall files file pos
  3784. marker category category-pos tags c neg re boolean
  3785. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3786. (unless (and (not edit-at)
  3787. (stringp string)
  3788. (string-match "\\S-" string))
  3789. (setq string (read-string
  3790. (if org-agenda-search-view-always-boolean
  3791. "[+-]Word/{Regexp} ...: "
  3792. "Phrase or [+-]Word/{Regexp} ...: ")
  3793. (cond
  3794. ((integerp edit-at) (cons string edit-at))
  3795. (edit-at string))
  3796. 'org-agenda-search-history)))
  3797. (catch 'exit
  3798. (if org-agenda-sticky
  3799. (setq org-agenda-buffer-name
  3800. (if (stringp string)
  3801. (format "*Org Agenda(%s:%s)*"
  3802. (or org-keys (or (and todo-only "S") "s")) string)
  3803. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3804. (org-agenda-prepare "SEARCH")
  3805. (org-compile-prefix-format 'search)
  3806. (org-set-sorting-strategy 'search)
  3807. (setq org-agenda-redo-command
  3808. (list 'org-search-view (if todo-only t nil)
  3809. (list 'if 'current-prefix-arg nil string)))
  3810. (setq org-agenda-query-string string)
  3811. (if (equal (string-to-char string) ?*)
  3812. (setq hdl-only t
  3813. words (substring string 1))
  3814. (setq words string))
  3815. (when (equal (string-to-char words) ?!)
  3816. (setq todo-only t
  3817. words (substring words 1)))
  3818. (when (equal (string-to-char words) ?:)
  3819. (setq full-words t
  3820. words (substring words 1)))
  3821. (if (or org-agenda-search-view-always-boolean
  3822. (member (string-to-char words) '(?- ?+ ?\{)))
  3823. (setq boolean t))
  3824. (setq words (org-split-string words))
  3825. (let (www w)
  3826. (while (setq w (pop words))
  3827. (while (and (string-match "\\\\\\'" w) words)
  3828. (setq w (concat (substring w 0 -1) " " (pop words))))
  3829. (push w www))
  3830. (setq words (nreverse www) www nil)
  3831. (while (setq w (pop words))
  3832. (when (and (string-match "\\`[-+]?{" w)
  3833. (not (string-match "}\\'" w)))
  3834. (while (and words (not (string-match "}\\'" (car words))))
  3835. (setq w (concat w " " (pop words))))
  3836. (setq w (concat w " " (pop words))))
  3837. (push w www))
  3838. (setq words (nreverse www)))
  3839. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3840. (when boolean
  3841. (let (wds w)
  3842. (while (setq w (pop words))
  3843. (if (or (equal (substring w 0 1) "\"")
  3844. (and (> (length w) 1)
  3845. (member (substring w 0 1) '("+" "-"))
  3846. (equal (substring w 1 2) "\"")))
  3847. (while (and words (not (equal (substring w -1) "\"")))
  3848. (setq w (concat w " " (pop words)))))
  3849. (and (string-match "\\`\\([-+]?\\)\"" w)
  3850. (setq w (replace-match "\\1" nil nil w)))
  3851. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3852. (push w wds))
  3853. (setq words (nreverse wds))))
  3854. (if boolean
  3855. (mapc (lambda (w)
  3856. (setq c (string-to-char w))
  3857. (if (equal c ?-)
  3858. (setq neg t w (substring w 1))
  3859. (if (equal c ?+)
  3860. (setq neg nil w (substring w 1))
  3861. (setq neg nil)))
  3862. (if (string-match "\\`{.*}\\'" w)
  3863. (setq re (substring w 1 -1))
  3864. (if full-words
  3865. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3866. (setq re (regexp-quote (downcase w)))))
  3867. (if neg (push re regexps-) (push re regexps+)))
  3868. words)
  3869. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3870. regexps+))
  3871. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3872. (if (not regexps+)
  3873. (setq regexp org-outline-regexp-bol)
  3874. (setq regexp (pop regexps+))
  3875. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3876. regexp))))
  3877. (setq files (org-agenda-files nil 'ifmode))
  3878. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3879. (pop org-agenda-text-search-extra-files)
  3880. (setq files (org-add-archive-files files)))
  3881. (setq files (append files org-agenda-text-search-extra-files)
  3882. rtnall nil)
  3883. (while (setq file (pop files))
  3884. (setq ee nil)
  3885. (catch 'nextfile
  3886. (org-check-agenda-file file)
  3887. (setq buffer (if (file-exists-p file)
  3888. (org-get-agenda-file-buffer file)
  3889. (error "No such file %s" file)))
  3890. (if (not buffer)
  3891. ;; If file does not exist, make sure an error message is sent
  3892. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3893. file))))
  3894. (with-current-buffer buffer
  3895. (with-syntax-table (org-search-syntax-table)
  3896. (unless (derived-mode-p 'org-mode)
  3897. (error "Agenda file %s is not in `org-mode'" file))
  3898. (let ((case-fold-search t))
  3899. (save-excursion
  3900. (save-restriction
  3901. (if org-agenda-restrict
  3902. (narrow-to-region org-agenda-restrict-begin
  3903. org-agenda-restrict-end)
  3904. (widen))
  3905. (goto-char (point-min))
  3906. (unless (or (org-at-heading-p)
  3907. (outline-next-heading))
  3908. (throw 'nextfile t))
  3909. (goto-char (max (point-min) (1- (point))))
  3910. (while (re-search-forward regexp nil t)
  3911. (org-back-to-heading t)
  3912. (skip-chars-forward "* ")
  3913. (setq beg (point-at-bol)
  3914. beg1 (point)
  3915. end (progn (outline-next-heading) (point)))
  3916. (catch :skip
  3917. (goto-char beg)
  3918. (org-agenda-skip)
  3919. (setq str (buffer-substring-no-properties
  3920. (point-at-bol)
  3921. (if hdl-only (point-at-eol) end)))
  3922. (mapc (lambda (wr) (when (string-match wr str)
  3923. (goto-char (1- end))
  3924. (throw :skip t)))
  3925. regexps-)
  3926. (mapc (lambda (wr) (unless (string-match wr str)
  3927. (goto-char (1- end))
  3928. (throw :skip t)))
  3929. (if todo-only
  3930. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3931. regexps+)
  3932. regexps+))
  3933. (goto-char beg)
  3934. (setq marker (org-agenda-new-marker (point))
  3935. category (org-get-category)
  3936. category-pos (get-text-property (point) 'org-category-position)
  3937. tags (org-get-tags-at (point))
  3938. txt (org-agenda-format-item
  3939. ""
  3940. (buffer-substring-no-properties
  3941. beg1 (point-at-eol))
  3942. category tags))
  3943. (org-add-props txt props
  3944. 'org-marker marker 'org-hd-marker marker
  3945. 'org-todo-regexp org-todo-regexp
  3946. 'org-complex-heading-regexp org-complex-heading-regexp
  3947. 'priority 1000 'org-category category
  3948. 'org-category-position category-pos
  3949. 'type "search")
  3950. (push txt ee)
  3951. (goto-char (1- end))))))))))
  3952. (setq rtn (nreverse ee))
  3953. (setq rtnall (append rtnall rtn)))
  3954. (if org-agenda-overriding-header
  3955. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3956. nil 'face 'org-agenda-structure) "\n")
  3957. (insert "Search words: ")
  3958. (add-text-properties (point-min) (1- (point))
  3959. (list 'face 'org-agenda-structure))
  3960. (setq pos (point))
  3961. (insert string "\n")
  3962. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3963. (setq pos (point))
  3964. (unless org-agenda-multi
  3965. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3966. (add-text-properties pos (1- (point))
  3967. (list 'face 'org-agenda-structure))))
  3968. (org-agenda-mark-header-line (point-min))
  3969. (when rtnall
  3970. (insert (org-agenda-finalize-entries rtnall) "\n"))
  3971. (goto-char (point-min))
  3972. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3973. (add-text-properties (point-min) (point-max)
  3974. `(org-agenda-type search
  3975. org-last-args (,todo-only ,string ,edit-at)
  3976. org-redo-cmd ,org-agenda-redo-command
  3977. org-serie-cmd ,org-cmd))
  3978. (org-agenda-finalize)
  3979. (setq buffer-read-only t))))
  3980. ;;; Agenda TODO list
  3981. (defvar org-select-this-todo-keyword nil)
  3982. (defvar org-last-arg nil)
  3983. ;;;###autoload
  3984. (defun org-todo-list (&optional arg)
  3985. "Show all (not done) TODO entries from all agenda file in a single list.
  3986. The prefix arg can be used to select a specific TODO keyword and limit
  3987. the list to these. When using \\[universal-argument], you will be prompted
  3988. for a keyword. A numeric prefix directly selects the Nth keyword in
  3989. `org-todo-keywords-1'."
  3990. (interactive "P")
  3991. (if org-agenda-overriding-arguments
  3992. (setq arg org-agenda-overriding-arguments))
  3993. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3994. (let* ((today (org-today))
  3995. (date (calendar-gregorian-from-absolute today))
  3996. (kwds org-todo-keywords-for-agenda)
  3997. (completion-ignore-case t)
  3998. (org-select-this-todo-keyword
  3999. (if (stringp arg) arg
  4000. (and arg (integerp arg) (> arg 0)
  4001. (nth (1- arg) kwds))))
  4002. rtn rtnall files file pos)
  4003. (when (equal arg '(4))
  4004. (setq org-select-this-todo-keyword
  4005. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4006. (mapcar 'list kwds) nil nil)))
  4007. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4008. (catch 'exit
  4009. (if org-agenda-sticky
  4010. (setq org-agenda-buffer-name
  4011. (if (stringp org-select-this-todo-keyword)
  4012. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4013. org-select-this-todo-keyword)
  4014. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4015. (org-agenda-prepare "TODO")
  4016. (org-compile-prefix-format 'todo)
  4017. (org-set-sorting-strategy 'todo)
  4018. (setq org-agenda-redo-command
  4019. `(org-todo-list (or current-prefix-arg (quote ,arg))))
  4020. (setq files (org-agenda-files nil 'ifmode)
  4021. rtnall nil)
  4022. (while (setq file (pop files))
  4023. (catch 'nextfile
  4024. (org-check-agenda-file file)
  4025. (setq rtn (org-agenda-get-day-entries file date :todo))
  4026. (setq rtnall (append rtnall rtn))))
  4027. (if org-agenda-overriding-header
  4028. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4029. nil 'face 'org-agenda-structure) "\n")
  4030. (insert "Global list of TODO items of type: ")
  4031. (add-text-properties (point-min) (1- (point))
  4032. (list 'face 'org-agenda-structure
  4033. 'short-heading
  4034. (concat "ToDo: "
  4035. (or org-select-this-todo-keyword "ALL"))))
  4036. (org-agenda-mark-header-line (point-min))
  4037. (setq pos (point))
  4038. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4039. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4040. (setq pos (point))
  4041. (unless org-agenda-multi
  4042. (insert "Available with `N r': (0)[ALL]")
  4043. (let ((n 0) s)
  4044. (mapc (lambda (x)
  4045. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4046. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4047. (insert "\n "))
  4048. (insert " " s))
  4049. kwds))
  4050. (insert "\n"))
  4051. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4052. (org-agenda-mark-header-line (point-min))
  4053. (when rtnall
  4054. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4055. (goto-char (point-min))
  4056. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4057. (add-text-properties (point-min) (point-max)
  4058. `(org-agenda-type todo
  4059. org-last-args ,arg
  4060. org-redo-cmd ,org-agenda-redo-command
  4061. org-serie-cmd ,org-cmd))
  4062. (org-agenda-finalize)
  4063. (setq buffer-read-only t))))
  4064. ;;; Agenda tags match
  4065. ;;;###autoload
  4066. (defun org-tags-view (&optional todo-only match)
  4067. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4068. The prefix arg TODO-ONLY limits the search to TODO entries."
  4069. (interactive "P")
  4070. (if org-agenda-overriding-arguments
  4071. (setq todo-only (car org-agenda-overriding-arguments)
  4072. match (nth 1 org-agenda-overriding-arguments)))
  4073. (let* ((org-tags-match-list-sublevels
  4074. org-tags-match-list-sublevels)
  4075. (completion-ignore-case t)
  4076. rtn rtnall files file pos matcher
  4077. buffer)
  4078. (when (and (stringp match) (not (string-match "\\S-" match)))
  4079. (setq match nil))
  4080. (setq matcher (org-make-tags-matcher match)
  4081. match (car matcher) matcher (cdr matcher))
  4082. (catch 'exit
  4083. (if org-agenda-sticky
  4084. (setq org-agenda-buffer-name
  4085. (if (stringp match)
  4086. (format "*Org Agenda(%s:%s)*"
  4087. (or org-keys (or (and todo-only "M") "m")) match)
  4088. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4089. (org-agenda-prepare (concat "TAGS " match))
  4090. (org-compile-prefix-format 'tags)
  4091. (org-set-sorting-strategy 'tags)
  4092. (setq org-agenda-query-string match)
  4093. (setq org-agenda-redo-command
  4094. (list 'org-tags-view `(quote ,todo-only)
  4095. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4096. (setq files (org-agenda-files nil 'ifmode)
  4097. rtnall nil)
  4098. (while (setq file (pop files))
  4099. (catch 'nextfile
  4100. (org-check-agenda-file file)
  4101. (setq buffer (if (file-exists-p file)
  4102. (org-get-agenda-file-buffer file)
  4103. (error "No such file %s" file)))
  4104. (if (not buffer)
  4105. ;; If file does not exist, error message to agenda
  4106. (setq rtn (list
  4107. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4108. rtnall (append rtnall rtn))
  4109. (with-current-buffer buffer
  4110. (unless (derived-mode-p 'org-mode)
  4111. (error "Agenda file %s is not in `org-mode'" file))
  4112. (save-excursion
  4113. (save-restriction
  4114. (if org-agenda-restrict
  4115. (narrow-to-region org-agenda-restrict-begin
  4116. org-agenda-restrict-end)
  4117. (widen))
  4118. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4119. (setq rtnall (append rtnall rtn))))))))
  4120. (if org-agenda-overriding-header
  4121. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4122. nil 'face 'org-agenda-structure) "\n")
  4123. (insert "Headlines with TAGS match: ")
  4124. (add-text-properties (point-min) (1- (point))
  4125. (list 'face 'org-agenda-structure
  4126. 'short-heading
  4127. (concat "Match: " match)))
  4128. (setq pos (point))
  4129. (insert match "\n")
  4130. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4131. (setq pos (point))
  4132. (unless org-agenda-multi
  4133. (insert "Press `C-u r' to search again with new search string\n"))
  4134. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4135. (org-agenda-mark-header-line (point-min))
  4136. (when rtnall
  4137. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4138. (goto-char (point-min))
  4139. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4140. (add-text-properties (point-min) (point-max)
  4141. `(org-agenda-type tags
  4142. org-last-args (,todo-only ,match)
  4143. org-redo-cmd ,org-agenda-redo-command
  4144. org-serie-cmd ,org-cmd))
  4145. (org-agenda-finalize)
  4146. (setq buffer-read-only t))))
  4147. ;;; Agenda Finding stuck projects
  4148. (defvar org-agenda-skip-regexp nil
  4149. "Regular expression used in skipping subtrees for the agenda.
  4150. This is basically a temporary global variable that can be set and then
  4151. used by user-defined selections using `org-agenda-skip-function'.")
  4152. (defvar org-agenda-overriding-header nil
  4153. "When set during agenda, todo and tags searches it replaces the header.
  4154. This variable should not be set directly, but custom commands can bind it
  4155. in the options section.")
  4156. (defun org-agenda-skip-entry-when-regexp-matches ()
  4157. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4158. If yes, it returns the end position of this entry, causing agenda commands
  4159. to skip the entry but continuing the search in the subtree. This is a
  4160. function that can be put into `org-agenda-skip-function' for the duration
  4161. of a command."
  4162. (let ((end (save-excursion (org-end-of-subtree t)))
  4163. skip)
  4164. (save-excursion
  4165. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4166. (and skip end)))
  4167. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4168. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4169. If yes, it returns the end position of this tree, causing agenda commands
  4170. to skip this subtree. This is a function that can be put into
  4171. `org-agenda-skip-function' for the duration of a command."
  4172. (let ((end (save-excursion (org-end-of-subtree t)))
  4173. skip)
  4174. (save-excursion
  4175. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4176. (and skip end)))
  4177. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4178. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4179. If yes, it returns the end position of the current entry (NOT the tree),
  4180. causing agenda commands to skip the entry but continuing the search in
  4181. the subtree. This is a function that can be put into
  4182. `org-agenda-skip-function' for the duration of a command. An important
  4183. use of this function is for the stuck project list."
  4184. (let ((end (save-excursion (org-end-of-subtree t)))
  4185. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4186. skip)
  4187. (save-excursion
  4188. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4189. (and skip entry-end)))
  4190. (defun org-agenda-skip-entry-if (&rest conditions)
  4191. "Skip entry if any of CONDITIONS is true.
  4192. See `org-agenda-skip-if' for details."
  4193. (org-agenda-skip-if nil conditions))
  4194. (defun org-agenda-skip-subtree-if (&rest conditions)
  4195. "Skip entry if any of CONDITIONS is true.
  4196. See `org-agenda-skip-if' for details."
  4197. (org-agenda-skip-if t conditions))
  4198. (defun org-agenda-skip-if (subtree conditions)
  4199. "Checks current entity for CONDITIONS.
  4200. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4201. the entry (i.e. the text before the next heading) is checked.
  4202. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4203. from different tests. Valid conditions are:
  4204. scheduled Check if there is a scheduled cookie
  4205. notscheduled Check if there is no scheduled cookie
  4206. deadline Check if there is a deadline
  4207. notdeadline Check if there is no deadline
  4208. timestamp Check if there is a timestamp (also deadline or scheduled)
  4209. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4210. regexp Check if regexp matches
  4211. notregexp Check if regexp does not match.
  4212. todo Check if TODO keyword matches
  4213. nottodo Check if TODO keyword does not match
  4214. The regexp is taken from the conditions list, it must come right after
  4215. the `regexp' or `notregexp' element.
  4216. `todo' and `nottodo' accept as an argument a list of todo
  4217. keywords, which may include \"*\" to match any todo keyword.
  4218. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4219. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4220. Instead of a list, a keyword class may be given. For example:
  4221. (org-agenda-skip-entry-if 'nottodo 'done)
  4222. would skip entries that haven't been marked with any of \"DONE\"
  4223. keywords. Possible classes are: `todo', `done', `any'.
  4224. If any of these conditions is met, this function returns the end point of
  4225. the entity, causing the search to continue from there. This is a function
  4226. that can be put into `org-agenda-skip-function' for the duration of a command."
  4227. (let (beg end m)
  4228. (org-back-to-heading t)
  4229. (setq beg (point)
  4230. end (if subtree
  4231. (progn (org-end-of-subtree t) (point))
  4232. (progn (outline-next-heading) (1- (point)))))
  4233. (goto-char beg)
  4234. (and
  4235. (or
  4236. (and (memq 'scheduled conditions)
  4237. (re-search-forward org-scheduled-time-regexp end t))
  4238. (and (memq 'notscheduled conditions)
  4239. (not (re-search-forward org-scheduled-time-regexp end t)))
  4240. (and (memq 'deadline conditions)
  4241. (re-search-forward org-deadline-time-regexp end t))
  4242. (and (memq 'notdeadline conditions)
  4243. (not (re-search-forward org-deadline-time-regexp end t)))
  4244. (and (memq 'timestamp conditions)
  4245. (re-search-forward org-ts-regexp end t))
  4246. (and (memq 'nottimestamp conditions)
  4247. (not (re-search-forward org-ts-regexp end t)))
  4248. (and (setq m (memq 'regexp conditions))
  4249. (stringp (nth 1 m))
  4250. (re-search-forward (nth 1 m) end t))
  4251. (and (setq m (memq 'notregexp conditions))
  4252. (stringp (nth 1 m))
  4253. (not (re-search-forward (nth 1 m) end t)))
  4254. (and (or
  4255. (setq m (memq 'nottodo conditions))
  4256. (setq m (memq 'todo-unblocked conditions))
  4257. (setq m (memq 'nottodo-unblocked conditions))
  4258. (setq m (memq 'todo conditions)))
  4259. (org-agenda-skip-if-todo m end)))
  4260. end)))
  4261. (defun org-agenda-skip-if-todo (args end)
  4262. "Helper function for `org-agenda-skip-if', do not use it directly.
  4263. ARGS is a list with first element either `todo', `nottodo',
  4264. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4265. a list of TODO keywords, or a state symbol `todo' or `done' or
  4266. `any'."
  4267. (let ((kw (car args))
  4268. (arg (cadr args))
  4269. todo-wds todo-re)
  4270. (setq todo-wds
  4271. (org-uniquify
  4272. (cond
  4273. ((listp arg) ;; list of keywords
  4274. (if (member "*" arg)
  4275. (mapcar 'substring-no-properties org-todo-keywords-1)
  4276. arg))
  4277. ((symbolp arg) ;; keyword class name
  4278. (cond
  4279. ((eq arg 'todo)
  4280. (org-delete-all org-done-keywords
  4281. (mapcar 'substring-no-properties
  4282. org-todo-keywords-1)))
  4283. ((eq arg 'done) org-done-keywords)
  4284. ((eq arg 'any)
  4285. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4286. (setq todo-re
  4287. (concat "^\\*+[ \t]+\\<\\("
  4288. (mapconcat 'identity todo-wds "\\|")
  4289. "\\)\\>"))
  4290. (cond
  4291. ((eq kw 'todo) (re-search-forward todo-re end t))
  4292. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4293. ((eq kw 'todo-unblocked)
  4294. (catch 'unblocked
  4295. (while (re-search-forward todo-re end t)
  4296. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4297. nil))
  4298. ((eq kw 'nottodo-unblocked)
  4299. (catch 'unblocked
  4300. (while (re-search-forward todo-re end t)
  4301. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4302. t))
  4303. )))
  4304. ;;;###autoload
  4305. (defun org-agenda-list-stuck-projects (&rest ignore)
  4306. "Create agenda view for projects that are stuck.
  4307. Stuck projects are project that have no next actions. For the definitions
  4308. of what a project is and how to check if it stuck, customize the variable
  4309. `org-stuck-projects'."
  4310. (interactive)
  4311. (let* ((org-agenda-skip-function
  4312. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4313. ;; We could have used org-agenda-skip-if here.
  4314. (org-agenda-overriding-header
  4315. (or org-agenda-overriding-header "List of stuck projects: "))
  4316. (matcher (nth 0 org-stuck-projects))
  4317. (todo (nth 1 org-stuck-projects))
  4318. (todo-wds (if (member "*" todo)
  4319. (progn
  4320. (org-agenda-prepare-buffers (org-agenda-files
  4321. nil 'ifmode))
  4322. (org-delete-all
  4323. org-done-keywords-for-agenda
  4324. (copy-sequence org-todo-keywords-for-agenda)))
  4325. todo))
  4326. (todo-re (concat "^\\*+[ \t]+\\("
  4327. (mapconcat 'identity todo-wds "\\|")
  4328. "\\)\\>"))
  4329. (tags (nth 2 org-stuck-projects))
  4330. (tags-re (if (member "*" tags)
  4331. (concat org-outline-regexp-bol
  4332. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4333. (if tags
  4334. (concat org-outline-regexp-bol
  4335. ".*:\\("
  4336. (mapconcat 'identity tags "\\|")
  4337. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4338. (gen-re (nth 3 org-stuck-projects))
  4339. (re-list
  4340. (delq nil
  4341. (list
  4342. (if todo todo-re)
  4343. (if tags tags-re)
  4344. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4345. gen-re)))))
  4346. (setq org-agenda-skip-regexp
  4347. (if re-list
  4348. (mapconcat 'identity re-list "\\|")
  4349. (error "No information how to identify unstuck projects")))
  4350. (org-tags-view nil matcher)
  4351. (with-current-buffer org-agenda-buffer-name
  4352. (setq org-agenda-redo-command
  4353. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4354. ;;; Diary integration
  4355. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4356. (defvar diary-list-entries-hook)
  4357. (defvar diary-time-regexp)
  4358. (defun org-get-entries-from-diary (date)
  4359. "Get the (Emacs Calendar) diary entries for DATE."
  4360. (require 'diary-lib)
  4361. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4362. (diary-display-hook '(fancy-diary-display))
  4363. (diary-display-function 'fancy-diary-display)
  4364. (pop-up-frames nil)
  4365. (diary-list-entries-hook
  4366. (cons 'org-diary-default-entry diary-list-entries-hook))
  4367. (diary-file-name-prefix-function nil) ; turn this feature off
  4368. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4369. entries
  4370. (org-disable-agenda-to-diary t))
  4371. (save-excursion
  4372. (save-window-excursion
  4373. (funcall (if (fboundp 'diary-list-entries)
  4374. 'diary-list-entries 'list-diary-entries)
  4375. date 1)))
  4376. (if (not (get-buffer diary-fancy-buffer))
  4377. (setq entries nil)
  4378. (with-current-buffer diary-fancy-buffer
  4379. (setq buffer-read-only nil)
  4380. (if (zerop (buffer-size))
  4381. ;; No entries
  4382. (setq entries nil)
  4383. ;; Omit the date and other unnecessary stuff
  4384. (org-agenda-cleanup-fancy-diary)
  4385. ;; Add prefix to each line and extend the text properties
  4386. (if (zerop (buffer-size))
  4387. (setq entries nil)
  4388. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4389. (setq entries
  4390. (with-temp-buffer
  4391. (insert entries) (goto-char (point-min))
  4392. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4393. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4394. (replace-match (concat "; " (match-string 1)))))
  4395. (buffer-string)))))
  4396. (set-buffer-modified-p nil)
  4397. (kill-buffer diary-fancy-buffer)))
  4398. (when entries
  4399. (setq entries (org-split-string entries "\n"))
  4400. (setq entries
  4401. (mapcar
  4402. (lambda (x)
  4403. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4404. ;; Extend the text properties to the beginning of the line
  4405. (org-add-props x (text-properties-at (1- (length x)) x)
  4406. 'type "diary" 'date date 'face 'org-agenda-diary))
  4407. entries)))))
  4408. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4409. "Hook run when the fancy diary buffer is cleaned up.")
  4410. (defun org-agenda-cleanup-fancy-diary ()
  4411. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4412. This gets rid of the date, the underline under the date, and
  4413. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4414. date. It also removes lines that contain only whitespace."
  4415. (goto-char (point-min))
  4416. (if (looking-at ".*?:[ \t]*")
  4417. (progn
  4418. (replace-match "")
  4419. (re-search-forward "\n=+$" nil t)
  4420. (replace-match "")
  4421. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4422. (re-search-forward "\n=+$" nil t)
  4423. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4424. (goto-char (point-min))
  4425. (while (re-search-forward "^ +\n" nil t)
  4426. (replace-match ""))
  4427. (goto-char (point-min))
  4428. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4429. (replace-match ""))
  4430. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4431. ;; Make sure entries from the diary have the right text properties.
  4432. (eval-after-load "diary-lib"
  4433. '(if (boundp 'diary-modify-entry-list-string-function)
  4434. ;; We can rely on the hook, nothing to do
  4435. nil
  4436. ;; Hook not available, must use advice to make this work
  4437. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4438. "Make the position visible."
  4439. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4440. (stringp string)
  4441. buffer-file-name)
  4442. (setq string (org-modify-diary-entry-string string))))))
  4443. (defun org-modify-diary-entry-string (string)
  4444. "Add text properties to string, allowing org-mode to act on it."
  4445. (org-add-props string nil
  4446. 'mouse-face 'highlight
  4447. 'help-echo (if buffer-file-name
  4448. (format "mouse-2 or RET jump to diary file %s"
  4449. (abbreviate-file-name buffer-file-name))
  4450. "")
  4451. 'org-agenda-diary-link t
  4452. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4453. (defun org-diary-default-entry ()
  4454. "Add a dummy entry to the diary.
  4455. Needed to avoid empty dates which mess up holiday display."
  4456. ;; Catch the error if dealing with the new add-to-diary-alist
  4457. (when org-disable-agenda-to-diary
  4458. (condition-case nil
  4459. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4460. (error
  4461. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4462. (defun org-add-to-diary-list (&rest args)
  4463. (if (fboundp 'diary-add-to-list)
  4464. (apply 'diary-add-to-list args)
  4465. (apply 'add-to-diary-list args)))
  4466. (defvar org-diary-last-run-time nil)
  4467. ;;;###autoload
  4468. (defun org-diary (&rest args)
  4469. "Return diary information from org files.
  4470. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4471. It accesses org files and extracts information from those files to be
  4472. listed in the diary. The function accepts arguments specifying what
  4473. items should be listed. For a list of arguments allowed here, see the
  4474. variable `org-agenda-entry-types'.
  4475. The call in the diary file should look like this:
  4476. &%%(org-diary) ~/path/to/some/orgfile.org
  4477. Use a separate line for each org file to check. Or, if you omit the file name,
  4478. all files listed in `org-agenda-files' will be checked automatically:
  4479. &%%(org-diary)
  4480. If you don't give any arguments (as in the example above), the default
  4481. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4482. So the example above may also be written as
  4483. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4484. The function expects the lisp variables `entry' and `date' to be provided
  4485. by the caller, because this is how the calendar works. Don't use this
  4486. function from a program - use `org-agenda-get-day-entries' instead."
  4487. (when (> (- (org-float-time)
  4488. org-agenda-last-marker-time)
  4489. 5)
  4490. ;; I am not sure if this works with sticky agendas, because the marker
  4491. ;; list is then no longer a global variable.
  4492. (org-agenda-reset-markers))
  4493. (org-compile-prefix-format 'agenda)
  4494. (org-set-sorting-strategy 'agenda)
  4495. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4496. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4497. (list entry)
  4498. (org-agenda-files t)))
  4499. (time (org-float-time))
  4500. file rtn results)
  4501. (when (or (not org-diary-last-run-time)
  4502. (> (- time
  4503. org-diary-last-run-time)
  4504. 3))
  4505. (org-agenda-prepare-buffers files))
  4506. (setq org-diary-last-run-time time)
  4507. ;; If this is called during org-agenda, don't return any entries to
  4508. ;; the calendar. Org Agenda will list these entries itself.
  4509. (if org-disable-agenda-to-diary (setq files nil))
  4510. (while (setq file (pop files))
  4511. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4512. (setq results (append results rtn)))
  4513. (if results
  4514. (concat (org-agenda-finalize-entries results) "\n"))))
  4515. ;;; Agenda entry finders
  4516. (defun org-agenda-get-day-entries (file date &rest args)
  4517. "Does the work for `org-diary' and `org-agenda'.
  4518. FILE is the path to a file to be checked for entries. DATE is date like
  4519. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4520. which kind of entries should be extracted. For details about these, see
  4521. the documentation of `org-diary'."
  4522. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4523. (let* ((org-startup-folded nil)
  4524. (org-startup-align-all-tables nil)
  4525. (buffer (if (file-exists-p file)
  4526. (org-get-agenda-file-buffer file)
  4527. (error "No such file %s" file)))
  4528. arg results rtn deadline-results)
  4529. (if (not buffer)
  4530. ;; If file does not exist, make sure an error message ends up in diary
  4531. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4532. (with-current-buffer buffer
  4533. (unless (derived-mode-p 'org-mode)
  4534. (error "Agenda file %s is not in `org-mode'" file))
  4535. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4536. (let ((case-fold-search nil))
  4537. (save-excursion
  4538. (save-restriction
  4539. (if org-agenda-restrict
  4540. (narrow-to-region org-agenda-restrict-begin
  4541. org-agenda-restrict-end)
  4542. (widen))
  4543. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4544. (while (setq arg (pop args))
  4545. (cond
  4546. ((and (eq arg :todo)
  4547. (equal date (calendar-gregorian-from-absolute
  4548. (org-today))))
  4549. (setq rtn (org-agenda-get-todos))
  4550. (setq results (append results rtn)))
  4551. ((eq arg :timestamp)
  4552. (setq rtn (org-agenda-get-blocks))
  4553. (setq results (append results rtn))
  4554. (setq rtn (org-agenda-get-timestamps deadline-results))
  4555. (setq results (append results rtn)))
  4556. ((eq arg :sexp)
  4557. (setq rtn (org-agenda-get-sexps))
  4558. (setq results (append results rtn)))
  4559. ((eq arg :scheduled)
  4560. (setq rtn (org-agenda-get-scheduled deadline-results))
  4561. (setq results (append results rtn)))
  4562. ((eq arg :closed)
  4563. (setq rtn (org-agenda-get-progress))
  4564. (setq results (append results rtn)))
  4565. ((eq arg :deadline)
  4566. (setq rtn (org-agenda-get-deadlines))
  4567. (setq deadline-results (copy-sequence rtn))
  4568. (setq results (append results rtn))))))))
  4569. results))))
  4570. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4571. (defun org-agenda-get-todos ()
  4572. "Return the TODO information for agenda display."
  4573. (let* ((props (list 'face nil
  4574. 'done-face 'org-agenda-done
  4575. 'org-not-done-regexp org-not-done-regexp
  4576. 'org-todo-regexp org-todo-regexp
  4577. 'org-complex-heading-regexp org-complex-heading-regexp
  4578. 'mouse-face 'highlight
  4579. 'help-echo
  4580. (format "mouse-2 or RET jump to org file %s"
  4581. (abbreviate-file-name buffer-file-name))))
  4582. (regexp (format org-heading-keyword-regexp-format
  4583. (cond
  4584. ((and org-select-this-todo-keyword
  4585. (equal org-select-this-todo-keyword "*"))
  4586. org-todo-regexp)
  4587. (org-select-this-todo-keyword
  4588. (concat "\\("
  4589. (mapconcat 'identity
  4590. (org-split-string
  4591. org-select-this-todo-keyword
  4592. "|")
  4593. "\\|") "\\)"))
  4594. (t org-not-done-regexp))))
  4595. marker priority category category-pos tags todo-state
  4596. ee txt beg end)
  4597. (goto-char (point-min))
  4598. (while (re-search-forward regexp nil t)
  4599. (catch :skip
  4600. (save-match-data
  4601. (beginning-of-line)
  4602. (org-agenda-skip)
  4603. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4604. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4605. (goto-char (1+ beg))
  4606. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4607. (throw :skip nil)))
  4608. (goto-char (match-beginning 2))
  4609. (setq marker (org-agenda-new-marker (match-beginning 0))
  4610. category (org-get-category)
  4611. category-pos (get-text-property (point) 'org-category-position)
  4612. txt (org-trim
  4613. (buffer-substring (match-beginning 2) (match-end 0)))
  4614. tags (org-get-tags-at (point))
  4615. txt (org-agenda-format-item "" txt category tags)
  4616. priority (1+ (org-get-priority txt))
  4617. todo-state (org-get-todo-state))
  4618. (org-add-props txt props
  4619. 'org-marker marker 'org-hd-marker marker
  4620. 'priority priority 'org-category category
  4621. 'org-category-position category-pos
  4622. 'type "todo" 'todo-state todo-state)
  4623. (push txt ee)
  4624. (if org-agenda-todo-list-sublevels
  4625. (goto-char (match-end 2))
  4626. (org-end-of-subtree 'invisible))))
  4627. (nreverse ee)))
  4628. (defun org-agenda-todo-custom-ignore-p (time n)
  4629. "Check whether timestamp is farther away then n number of days.
  4630. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4631. `org-agenda-todo-ignore-scheduled' or
  4632. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4633. (let ((days (org-days-to-time time)))
  4634. (if (>= n 0)
  4635. (>= days n)
  4636. (<= days n))))
  4637. ;;;###autoload
  4638. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4639. (&optional end)
  4640. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4641. (when (or org-agenda-todo-ignore-with-date
  4642. org-agenda-todo-ignore-scheduled
  4643. org-agenda-todo-ignore-deadlines
  4644. org-agenda-todo-ignore-timestamp)
  4645. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4646. (save-excursion
  4647. (or (and org-agenda-todo-ignore-with-date
  4648. (re-search-forward org-ts-regexp end t))
  4649. (and org-agenda-todo-ignore-scheduled
  4650. (re-search-forward org-scheduled-time-regexp end t)
  4651. (cond
  4652. ((eq org-agenda-todo-ignore-scheduled 'future)
  4653. (> (org-days-to-time (match-string 1)) 0))
  4654. ((eq org-agenda-todo-ignore-scheduled 'past)
  4655. (<= (org-days-to-time (match-string 1)) 0))
  4656. ((numberp org-agenda-todo-ignore-scheduled)
  4657. (org-agenda-todo-custom-ignore-p
  4658. (match-string 1) org-agenda-todo-ignore-scheduled))
  4659. (t)))
  4660. (and org-agenda-todo-ignore-deadlines
  4661. (re-search-forward org-deadline-time-regexp end t)
  4662. (cond
  4663. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4664. ((eq org-agenda-todo-ignore-deadlines 'far)
  4665. (not (org-deadline-close (match-string 1))))
  4666. ((eq org-agenda-todo-ignore-deadlines 'future)
  4667. (> (org-days-to-time (match-string 1)) 0))
  4668. ((eq org-agenda-todo-ignore-deadlines 'past)
  4669. (<= (org-days-to-time (match-string 1)) 0))
  4670. ((numberp org-agenda-todo-ignore-deadlines)
  4671. (org-agenda-todo-custom-ignore-p
  4672. (match-string 1) org-agenda-todo-ignore-deadlines))
  4673. (t (org-deadline-close (match-string 1)))))
  4674. (and org-agenda-todo-ignore-timestamp
  4675. (let ((buffer (current-buffer))
  4676. (regexp
  4677. (concat
  4678. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4679. (start (point)))
  4680. ;; Copy current buffer into a temporary one
  4681. (with-temp-buffer
  4682. (insert-buffer-substring buffer start end)
  4683. (goto-char (point-min))
  4684. ;; Delete SCHEDULED and DEADLINE items
  4685. (while (re-search-forward regexp end t)
  4686. (delete-region (match-beginning 0) (match-end 0)))
  4687. (goto-char (point-min))
  4688. ;; No search for timestamp left
  4689. (when (re-search-forward org-ts-regexp nil t)
  4690. (cond
  4691. ((eq org-agenda-todo-ignore-timestamp 'future)
  4692. (> (org-days-to-time (match-string 1)) 0))
  4693. ((eq org-agenda-todo-ignore-timestamp 'past)
  4694. (<= (org-days-to-time (match-string 1)) 0))
  4695. ((numberp org-agenda-todo-ignore-timestamp)
  4696. (org-agenda-todo-custom-ignore-p
  4697. (match-string 1) org-agenda-todo-ignore-timestamp))
  4698. (t))))))))))
  4699. (defconst org-agenda-no-heading-message
  4700. "No heading for this item in buffer or region.")
  4701. (defun org-agenda-get-timestamps (&optional deadline-results)
  4702. "Return the date stamp information for agenda display."
  4703. (let* ((props (list 'face 'org-agenda-calendar-event
  4704. 'org-not-done-regexp org-not-done-regexp
  4705. 'org-todo-regexp org-todo-regexp
  4706. 'org-complex-heading-regexp org-complex-heading-regexp
  4707. 'mouse-face 'highlight
  4708. 'help-echo
  4709. (format "mouse-2 or RET jump to org file %s"
  4710. (abbreviate-file-name buffer-file-name))))
  4711. (d1 (calendar-absolute-from-gregorian date))
  4712. mm
  4713. (deadline-position-alist
  4714. (mapcar (lambda (a) (and (setq mm (get-text-property
  4715. 0 'org-hd-marker a))
  4716. (cons (marker-position mm) a)))
  4717. deadline-results))
  4718. (remove-re org-ts-regexp)
  4719. (regexp
  4720. (concat
  4721. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4722. (regexp-quote
  4723. (substring
  4724. (format-time-string
  4725. (car org-time-stamp-formats)
  4726. (apply 'encode-time ; DATE bound by calendar
  4727. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4728. 1 11))
  4729. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4730. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4731. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4732. donep tmp priority category category-pos ee txt timestr tags
  4733. b0 b3 e3 head todo-state end-of-match show-all warntime)
  4734. (goto-char (point-min))
  4735. (while (setq end-of-match (re-search-forward regexp nil t))
  4736. (setq b0 (match-beginning 0)
  4737. b3 (match-beginning 3) e3 (match-end 3)
  4738. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4739. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4740. (member todo-state
  4741. org-agenda-repeating-timestamp-show-all)))
  4742. (catch :skip
  4743. (and (org-at-date-range-p) (throw :skip nil))
  4744. (org-agenda-skip)
  4745. (if (and (match-end 1)
  4746. (not (= d1 (org-time-string-to-absolute
  4747. (match-string 1) d1 nil show-all
  4748. (current-buffer) b0))))
  4749. (throw :skip nil))
  4750. (if (and e3
  4751. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4752. (throw :skip nil))
  4753. (setq tmp (buffer-substring (max (point-min)
  4754. (- b0 org-ds-keyword-length))
  4755. b0)
  4756. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4757. inactivep (= (char-after b0) ?\[)
  4758. deadlinep (string-match org-deadline-regexp tmp)
  4759. scheduledp (string-match org-scheduled-regexp tmp)
  4760. closedp (and org-agenda-include-inactive-timestamps
  4761. (string-match org-closed-string tmp))
  4762. clockp (and org-agenda-include-inactive-timestamps
  4763. (or (string-match org-clock-string tmp)
  4764. (string-match "]-+\\'" tmp)))
  4765. warntime (org-entry-get (point) "APPT_WARNTIME")
  4766. donep (member todo-state org-done-keywords))
  4767. (if (or scheduledp deadlinep closedp clockp
  4768. (and donep org-agenda-skip-timestamp-if-done))
  4769. (throw :skip t))
  4770. (if (string-match ">" timestr)
  4771. ;; substring should only run to end of time stamp
  4772. (setq timestr (substring timestr 0 (match-end 0))))
  4773. (setq marker (org-agenda-new-marker b0)
  4774. category (org-get-category b0)
  4775. category-pos (get-text-property b0 'org-category-position))
  4776. (save-excursion
  4777. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4778. (setq txt org-agenda-no-heading-message)
  4779. (goto-char (match-beginning 0))
  4780. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4781. (assoc (point) deadline-position-alist))
  4782. (throw :skip nil))
  4783. (setq hdmarker (org-agenda-new-marker)
  4784. tags (org-get-tags-at))
  4785. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4786. (setq head (or (match-string 1) ""))
  4787. (setq txt (org-agenda-format-item
  4788. (if inactivep org-agenda-inactive-leader nil)
  4789. head category tags timestr
  4790. remove-re)))
  4791. (setq priority (org-get-priority txt))
  4792. (org-add-props txt props
  4793. 'org-marker marker 'org-hd-marker hdmarker)
  4794. (org-add-props txt nil 'priority priority
  4795. 'org-category category 'date date
  4796. 'org-category-position category-pos
  4797. 'todo-state todo-state
  4798. 'warntime warntime
  4799. 'type "timestamp")
  4800. (push txt ee))
  4801. (if org-agenda-skip-additional-timestamps-same-entry
  4802. (outline-next-heading)
  4803. (goto-char end-of-match))))
  4804. (nreverse ee)))
  4805. (defun org-agenda-get-sexps ()
  4806. "Return the sexp information for agenda display."
  4807. (require 'diary-lib)
  4808. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4809. 'mouse-face 'highlight
  4810. 'help-echo
  4811. (format "mouse-2 or RET jump to org file %s"
  4812. (abbreviate-file-name buffer-file-name))))
  4813. (regexp "^&?%%(")
  4814. marker category extra category-pos ee txt tags entry
  4815. result beg b sexp sexp-entry todo-state warntime)
  4816. (goto-char (point-min))
  4817. (while (re-search-forward regexp nil t)
  4818. (catch :skip
  4819. (org-agenda-skip)
  4820. (setq beg (match-beginning 0))
  4821. (goto-char (1- (match-end 0)))
  4822. (setq b (point))
  4823. (forward-sexp 1)
  4824. (setq sexp (buffer-substring b (point)))
  4825. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4826. (org-trim (match-string 1))
  4827. ""))
  4828. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4829. (when result
  4830. (setq marker (org-agenda-new-marker beg)
  4831. category (org-get-category beg)
  4832. category-pos (get-text-property beg 'org-category-position)
  4833. tags (save-excursion (org-backward-heading-same-level 0)
  4834. (org-get-tags-at))
  4835. todo-state (org-get-todo-state)
  4836. warntime (org-entry-get (point) "APPT_WARNTIME"))
  4837. (dolist (r (if (stringp result)
  4838. (list result)
  4839. result)) ;; we expect a list here
  4840. (when (and org-agenda-diary-sexp-prefix
  4841. (string-match org-agenda-diary-sexp-prefix r))
  4842. (setq extra (match-string 0 r)
  4843. r (replace-match "" nil nil r)))
  4844. (if (string-match "\\S-" r)
  4845. (setq txt r)
  4846. (setq txt "SEXP entry returned empty string"))
  4847. (setq txt (org-agenda-format-item
  4848. extra txt category tags 'time))
  4849. (org-add-props txt props 'org-marker marker)
  4850. (org-add-props txt nil
  4851. 'org-category category 'date date 'todo-state todo-state
  4852. 'org-category-position category-pos 'tags tags
  4853. 'type "sexp" 'warntime warntime)
  4854. (push txt ee)))))
  4855. (nreverse ee)))
  4856. ;; Calendar sanity: define some functions that are independent of
  4857. ;; `calendar-date-style'.
  4858. ;; Normally I would like to use ISO format when calling the diary functions,
  4859. ;; but to make sure we still have Emacs 22 compatibility we bind
  4860. ;; also `european-calendar-style' and use european format
  4861. (defun org-anniversary (year month day &optional mark)
  4862. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4863. (org-no-warnings
  4864. (let ((calendar-date-style 'european) (european-calendar-style t))
  4865. (diary-anniversary day month year mark))))
  4866. (defun org-cyclic (N year month day &optional mark)
  4867. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4868. (org-no-warnings
  4869. (let ((calendar-date-style 'european) (european-calendar-style t))
  4870. (diary-cyclic N day month year mark))))
  4871. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4872. "Like `diary-block', but with fixed (ISO) order of arguments."
  4873. (org-no-warnings
  4874. (let ((calendar-date-style 'european) (european-calendar-style t))
  4875. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4876. (defun org-date (year month day &optional mark)
  4877. "Like `diary-date', but with fixed (ISO) order of arguments."
  4878. (org-no-warnings
  4879. (let ((calendar-date-style 'european) (european-calendar-style t))
  4880. (diary-date day month year mark))))
  4881. (defalias 'org-float 'diary-float)
  4882. ;; Define the` org-class' function
  4883. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4884. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4885. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4886. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4887. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4888. `holidays', then any date that is known by the Emacs calendar to be a
  4889. holiday will also be skipped."
  4890. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4891. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4892. (d (calendar-absolute-from-gregorian date)))
  4893. (and
  4894. (<= date1 d)
  4895. (<= d date2)
  4896. (= (calendar-day-of-week date) dayname)
  4897. (or (not skip-weeks)
  4898. (progn
  4899. (require 'cal-iso)
  4900. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4901. (not (and (memq 'holidays skip-weeks)
  4902. (calendar-check-holidays date)))
  4903. entry)))
  4904. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4905. "Like `org-class', but honor `calendar-date-style'.
  4906. The order of the first 2 times 3 arguments depends on the variable
  4907. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4908. So for American calendars, give this as MONTH DAY YEAR, for European as
  4909. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4910. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4911. is any number of ISO weeks in the block period for which the item should
  4912. be skipped.
  4913. This function is here only for backward compatibility and it is deprecated,
  4914. please use `org-class' instead."
  4915. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4916. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4917. (org-class
  4918. (nth 2 date1) (car date1) (nth 1 date1)
  4919. (nth 2 date2) (car date2) (nth 1 date2)
  4920. dayname skip-weeks)))
  4921. (make-obsolete 'org-diary-class 'org-class "")
  4922. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  4923. (defalias 'org-get-closed 'org-agenda-get-progress)
  4924. (defun org-agenda-get-progress ()
  4925. "Return the logged TODO entries for agenda display."
  4926. (let* ((props (list 'mouse-face 'highlight
  4927. 'org-not-done-regexp org-not-done-regexp
  4928. 'org-todo-regexp org-todo-regexp
  4929. 'org-complex-heading-regexp org-complex-heading-regexp
  4930. 'help-echo
  4931. (format "mouse-2 or RET jump to org file %s"
  4932. (abbreviate-file-name buffer-file-name))))
  4933. (items (if (consp org-agenda-show-log-scoped)
  4934. org-agenda-show-log-scoped
  4935. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4936. '(clock)
  4937. org-agenda-log-mode-items)))
  4938. (parts
  4939. (delq nil
  4940. (list
  4941. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4942. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4943. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4944. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4945. (error "`org-agenda-log-mode-items' is empty")))
  4946. (regexp (concat
  4947. "\\(" parts-re "\\)"
  4948. " *\\["
  4949. (regexp-quote
  4950. (substring
  4951. (format-time-string
  4952. (car org-time-stamp-formats)
  4953. (apply 'encode-time ; DATE bound by calendar
  4954. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4955. 1 11))))
  4956. (org-agenda-search-headline-for-time nil)
  4957. marker hdmarker priority category category-pos tags closedp
  4958. statep clockp state ee txt extra timestr rest clocked)
  4959. (goto-char (point-min))
  4960. (while (re-search-forward regexp nil t)
  4961. (catch :skip
  4962. (org-agenda-skip)
  4963. (setq marker (org-agenda-new-marker (match-beginning 0))
  4964. closedp (equal (match-string 1) org-closed-string)
  4965. statep (equal (string-to-char (match-string 1)) ?-)
  4966. clockp (not (or closedp statep))
  4967. state (and statep (match-string 2))
  4968. category (org-get-category (match-beginning 0))
  4969. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4970. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4971. (when (string-match "\\]" timestr)
  4972. ;; substring should only run to end of time stamp
  4973. (setq rest (substring timestr (match-end 0))
  4974. timestr (substring timestr 0 (match-end 0)))
  4975. (if (and (not closedp) (not statep)
  4976. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4977. rest))
  4978. (progn (setq timestr (concat (substring timestr 0 -1)
  4979. "-" (match-string 1 rest) "]"))
  4980. (setq clocked (match-string 2 rest)))
  4981. (setq clocked "-")))
  4982. (save-excursion
  4983. (setq extra
  4984. (cond
  4985. ((not org-agenda-log-mode-add-notes) nil)
  4986. (statep
  4987. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4988. (match-string 1)))
  4989. (clockp
  4990. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4991. (match-string 1)))))
  4992. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4993. (setq txt org-agenda-no-heading-message)
  4994. (goto-char (match-beginning 0))
  4995. (setq hdmarker (org-agenda-new-marker)
  4996. tags (org-get-tags-at))
  4997. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4998. (setq txt (match-string 1))
  4999. (when extra
  5000. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5001. (setq txt (concat (substring txt 0 (match-beginning 1))
  5002. " - " extra " " (match-string 2 txt)))
  5003. (setq txt (concat txt " - " extra))))
  5004. (setq txt (org-agenda-format-item
  5005. (cond
  5006. (closedp "Closed: ")
  5007. (statep (concat "State: (" state ")"))
  5008. (t (concat "Clocked: (" clocked ")")))
  5009. txt category tags timestr)))
  5010. (setq priority 100000)
  5011. (org-add-props txt props
  5012. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5013. 'priority priority 'org-category category
  5014. 'org-category-position category-pos
  5015. 'type "closed" 'date date
  5016. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5017. (push txt ee))
  5018. (goto-char (point-at-eol))))
  5019. (nreverse ee)))
  5020. (defun org-agenda-show-clocking-issues ()
  5021. "Add overlays, showing issues with clocking.
  5022. See also the user option `org-agenda-clock-consistency-checks'."
  5023. (interactive)
  5024. (let* ((pl org-agenda-clock-consistency-checks)
  5025. (re (concat "^[ \t]*"
  5026. org-clock-string
  5027. "[ \t]+"
  5028. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5029. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5030. (tlstart 0.)
  5031. (tlend 0.)
  5032. (maxtime (org-hh:mm-string-to-minutes
  5033. (or (plist-get pl :max-duration) "24:00")))
  5034. (mintime (org-hh:mm-string-to-minutes
  5035. (or (plist-get pl :min-duration) 0)))
  5036. (maxgap (org-hh:mm-string-to-minutes
  5037. ;; default 30:00 means never complain
  5038. (or (plist-get pl :max-gap) "30:00")))
  5039. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5040. (plist-get pl :gap-ok-around)))
  5041. (def-face (or (plist-get pl :default-face)
  5042. '((:background "DarkRed") (:foreground "white"))))
  5043. issue face m te ts dt ov)
  5044. (goto-char (point-min))
  5045. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5046. (setq issue nil face def-face)
  5047. (catch 'next
  5048. (setq m (org-get-at-bol 'org-marker)
  5049. te nil ts nil)
  5050. (unless (and m (markerp m))
  5051. (setq issue "No valid clock line") (throw 'next t))
  5052. (org-with-point-at m
  5053. (save-excursion
  5054. (goto-char (point-at-bol))
  5055. (unless (looking-at re)
  5056. (error "No valid Clock line")
  5057. (throw 'next t))
  5058. (unless (match-end 3)
  5059. (setq issue "No end time"
  5060. face (or (plist-get pl :no-end-time-face) face))
  5061. (throw 'next t))
  5062. (setq ts (match-string 1)
  5063. te (match-string 3)
  5064. ts (org-float-time
  5065. (apply 'encode-time (org-parse-time-string ts)))
  5066. te (org-float-time
  5067. (apply 'encode-time (org-parse-time-string te)))
  5068. dt (- te ts))))
  5069. (cond
  5070. ((> dt (* 60 maxtime))
  5071. ;; a very long clocking chunk
  5072. (setq issue (format "Clocking interval is very long: %s"
  5073. (org-minutes-to-hh:mm-string
  5074. (floor (/ (float dt) 60.))))
  5075. face (or (plist-get pl :long-face) face)))
  5076. ((< dt (* 60 mintime))
  5077. ;; a very short clocking chunk
  5078. (setq issue (format "Clocking interval is very short: %s"
  5079. (org-minutes-to-hh:mm-string
  5080. (floor (/ (float dt) 60.))))
  5081. face (or (plist-get pl :short-face) face)))
  5082. ((and (> tlend 0) (< ts tlend))
  5083. ;; Two clock entries are overlapping
  5084. (setq issue (format "Clocking overlap: %d minutes"
  5085. (/ (- tlend ts) 60))
  5086. face (or (plist-get pl :overlap-face) face)))
  5087. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5088. ;; There is a gap, lets see if we need to report it
  5089. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5090. (setq issue (format "Clocking gap: %d minutes"
  5091. (/ (- ts tlend) 60))
  5092. face (or (plist-get pl :gap-face) face))))
  5093. (t nil)))
  5094. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5095. (when issue
  5096. ;; OK, there was some issue, add an overlay to show the issue
  5097. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5098. (overlay-put ov 'before-string
  5099. (concat
  5100. (org-add-props
  5101. (format "%-43s" (concat " " issue))
  5102. nil
  5103. 'face face)
  5104. "\n"))
  5105. (overlay-put ov 'evaporate t)))))
  5106. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5107. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5108. (catch 'exit
  5109. (unless ok-list
  5110. ;; there are no OK times for gaps...
  5111. (throw 'exit nil))
  5112. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5113. ;; This is more than 24 hours, so it is OK.
  5114. ;; because we have at least one OK time, that must be in the
  5115. ;; 24 hour interval.
  5116. (throw 'exit t))
  5117. ;; We have a shorter gap.
  5118. ;; Now we have to get the minute of the day when these times are
  5119. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5120. (t2dec (decode-time (seconds-to-time t2)))
  5121. ;; compute the minute on the day
  5122. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5123. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5124. (when (< min2 min1)
  5125. ;; if min2 is smaller than min1, this means it is on the next day.
  5126. ;; Wrap it to after midnight.
  5127. (setq min2 (+ min2 1440)))
  5128. ;; Now check if any of the OK times is in the gap
  5129. (mapc (lambda (x)
  5130. ;; Wrap the time to after midnight if necessary
  5131. (if (< x min1) (setq x (+ x 1440)))
  5132. ;; Check if in interval
  5133. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5134. ok-list)
  5135. ;; Nope, this gap is not OK
  5136. nil)))
  5137. (defun org-agenda-get-deadlines ()
  5138. "Return the deadline information for agenda display."
  5139. (let* ((props (list 'mouse-face 'highlight
  5140. 'org-not-done-regexp org-not-done-regexp
  5141. 'org-todo-regexp org-todo-regexp
  5142. 'org-complex-heading-regexp org-complex-heading-regexp
  5143. 'help-echo
  5144. (format "mouse-2 or RET jump to org file %s"
  5145. (abbreviate-file-name buffer-file-name))))
  5146. (regexp org-deadline-time-regexp)
  5147. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5148. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5149. d2 diff dfrac wdays pos pos1 category category-pos
  5150. tags suppress-prewarning ee txt head face s todo-state
  5151. show-all upcomingp donep timestr warntime)
  5152. (goto-char (point-min))
  5153. (while (re-search-forward regexp nil t)
  5154. (setq suppress-prewarning nil)
  5155. (catch :skip
  5156. (org-agenda-skip)
  5157. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5158. (save-match-data
  5159. (string-match org-scheduled-time-regexp
  5160. (buffer-substring (point-at-bol)
  5161. (point-at-eol)))))
  5162. (setq suppress-prewarning
  5163. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5164. org-agenda-skip-deadline-prewarning-if-scheduled
  5165. 0)))
  5166. (setq s (match-string 1)
  5167. txt nil
  5168. pos (1- (match-beginning 1))
  5169. todo-state (save-match-data (org-get-todo-state))
  5170. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5171. (member todo-state
  5172. org-agenda-repeating-timestamp-show-all))
  5173. d2 (org-time-string-to-absolute
  5174. (match-string 1) d1 'past show-all
  5175. (current-buffer) pos)
  5176. diff (- d2 d1)
  5177. wdays (if suppress-prewarning
  5178. (let ((org-deadline-warning-days suppress-prewarning))
  5179. (org-get-wdays s))
  5180. (org-get-wdays s))
  5181. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5182. upcomingp (and todayp (> diff 0)))
  5183. ;; When to show a deadline in the calendar:
  5184. ;; If the expiration is within wdays warning time.
  5185. ;; Past-due deadlines are only shown on the current date
  5186. (if (and (or (and (<= diff wdays)
  5187. (and todayp (not org-agenda-only-exact-dates)))
  5188. (= diff 0)))
  5189. (save-excursion
  5190. ;; (setq todo-state (org-get-todo-state))
  5191. (setq donep (member todo-state org-done-keywords))
  5192. (if (and donep
  5193. (or org-agenda-skip-deadline-if-done
  5194. (not (= diff 0))))
  5195. (setq txt nil)
  5196. (setq category (org-get-category)
  5197. warntime (org-entry-get (point) "APPT_WARNTIME")
  5198. category-pos (get-text-property (point) 'org-category-position))
  5199. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5200. (setq txt org-agenda-no-heading-message)
  5201. (goto-char (match-end 0))
  5202. (setq pos1 (match-beginning 0))
  5203. (setq tags (org-get-tags-at pos1))
  5204. (setq head (buffer-substring-no-properties
  5205. (point)
  5206. (progn (skip-chars-forward "^\r\n")
  5207. (point))))
  5208. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5209. (setq timestr
  5210. (concat (substring s (match-beginning 1)) " "))
  5211. (setq timestr 'time))
  5212. (setq txt (org-agenda-format-item
  5213. (if (= diff 0)
  5214. (car org-agenda-deadline-leaders)
  5215. (if (functionp
  5216. (nth 1 org-agenda-deadline-leaders))
  5217. (funcall
  5218. (nth 1 org-agenda-deadline-leaders)
  5219. diff date)
  5220. (format (nth 1 org-agenda-deadline-leaders)
  5221. diff)))
  5222. head category tags
  5223. (if (not (= diff 0)) nil timestr)))))
  5224. (when txt
  5225. (setq face (org-agenda-deadline-face dfrac))
  5226. (org-add-props txt props
  5227. 'org-marker (org-agenda-new-marker pos)
  5228. 'warntime warntime
  5229. 'org-hd-marker (org-agenda-new-marker pos1)
  5230. 'priority (+ (- diff)
  5231. (org-get-priority txt))
  5232. 'org-category category
  5233. 'org-category-position category-pos
  5234. 'todo-state todo-state
  5235. 'type (if upcomingp "upcoming-deadline" "deadline")
  5236. 'date (if upcomingp date d2)
  5237. 'face (if donep 'org-agenda-done face)
  5238. 'undone-face face 'done-face 'org-agenda-done)
  5239. (push txt ee))))))
  5240. (nreverse ee)))
  5241. (defun org-agenda-deadline-face (fraction)
  5242. "Return the face to displaying a deadline item.
  5243. FRACTION is what fraction of the head-warning time has passed."
  5244. (let ((faces org-agenda-deadline-faces) f)
  5245. (catch 'exit
  5246. (while (setq f (pop faces))
  5247. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5248. (defun org-agenda-get-scheduled (&optional deadline-results)
  5249. "Return the scheduled information for agenda display."
  5250. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5251. 'org-todo-regexp org-todo-regexp
  5252. 'org-complex-heading-regexp org-complex-heading-regexp
  5253. 'done-face 'org-agenda-done
  5254. 'mouse-face 'highlight
  5255. 'help-echo
  5256. (format "mouse-2 or RET jump to org file %s"
  5257. (abbreviate-file-name buffer-file-name))))
  5258. (regexp org-scheduled-time-regexp)
  5259. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5260. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5261. mm
  5262. (deadline-position-alist
  5263. (mapcar (lambda (a) (and (setq mm (get-text-property
  5264. 0 'org-hd-marker a))
  5265. (cons (marker-position mm) a)))
  5266. deadline-results))
  5267. d2 diff pos pos1 category category-pos tags donep
  5268. ee txt head pastschedp todo-state face timestr s habitp show-all
  5269. did-habit-check-p warntime)
  5270. (goto-char (point-min))
  5271. (while (re-search-forward regexp nil t)
  5272. (catch :skip
  5273. (org-agenda-skip)
  5274. (setq s (match-string 1)
  5275. txt nil
  5276. pos (1- (match-beginning 1))
  5277. todo-state (save-match-data (org-get-todo-state))
  5278. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5279. (member todo-state
  5280. org-agenda-repeating-timestamp-show-all))
  5281. d2 (org-time-string-to-absolute
  5282. (match-string 1) d1 'past show-all
  5283. (current-buffer) pos)
  5284. diff (- d2 d1)
  5285. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5286. (setq pastschedp (and todayp (< diff 0)))
  5287. (setq did-habit-check-p nil)
  5288. ;; When to show a scheduled item in the calendar:
  5289. ;; If it is on or past the date.
  5290. (when (or (and (< diff 0)
  5291. (< (abs diff) org-scheduled-past-days)
  5292. (and todayp (not org-agenda-only-exact-dates)))
  5293. (= diff 0)
  5294. ;; org-is-habit-p uses org-entry-get, which is expansive
  5295. ;; so we go extra mile to only call it once
  5296. (and todayp
  5297. org-habit-show-all-today
  5298. (setq did-habit-check-p t)
  5299. (setq habitp (and (functionp 'org-is-habit-p)
  5300. (org-is-habit-p)))))
  5301. (save-excursion
  5302. (setq donep (member todo-state org-done-keywords))
  5303. (if (and donep
  5304. (or org-agenda-skip-scheduled-if-done
  5305. (not (= diff 0))
  5306. (and (functionp 'org-is-habit-p)
  5307. (org-is-habit-p))))
  5308. (setq txt nil)
  5309. (setq habitp (if did-habit-check-p habitp
  5310. (and (functionp 'org-is-habit-p)
  5311. (org-is-habit-p))))
  5312. (setq category (org-get-category)
  5313. category-pos (get-text-property (point) 'org-category-position))
  5314. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5315. (setq txt org-agenda-no-heading-message)
  5316. (goto-char (match-end 0))
  5317. (setq pos1 (match-beginning 0))
  5318. (if habitp
  5319. (if (or (not org-habit-show-habits)
  5320. (and (not todayp)
  5321. org-habit-show-habits-only-for-today))
  5322. (throw :skip nil))
  5323. (if (and
  5324. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5325. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5326. pastschedp))
  5327. (setq mm (assoc pos1 deadline-position-alist)))
  5328. (throw :skip nil)))
  5329. (setq tags (org-get-tags-at))
  5330. (setq head (buffer-substring-no-properties
  5331. (point)
  5332. (progn (skip-chars-forward "^\r\n") (point))))
  5333. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5334. (setq timestr
  5335. (concat (substring s (match-beginning 1)) " "))
  5336. (setq timestr 'time))
  5337. (setq txt (org-agenda-format-item
  5338. (if (= diff 0)
  5339. (car org-agenda-scheduled-leaders)
  5340. (format (nth 1 org-agenda-scheduled-leaders)
  5341. (- 1 diff)))
  5342. head category tags
  5343. (if (not (= diff 0)) nil timestr)
  5344. nil habitp))))
  5345. (when txt
  5346. (setq face
  5347. (cond
  5348. ((and (not habitp) pastschedp)
  5349. 'org-scheduled-previously)
  5350. (todayp 'org-scheduled-today)
  5351. (t 'org-scheduled))
  5352. habitp (and habitp (org-habit-parse-todo)))
  5353. (org-add-props txt props
  5354. 'undone-face face
  5355. 'face (if donep 'org-agenda-done face)
  5356. 'org-marker (org-agenda-new-marker pos)
  5357. 'org-hd-marker (org-agenda-new-marker pos1)
  5358. 'type (if pastschedp "past-scheduled" "scheduled")
  5359. 'date (if pastschedp d2 date)
  5360. 'warntime warntime
  5361. 'priority (if habitp
  5362. (org-habit-get-priority habitp)
  5363. (+ 94 (- 5 diff) (org-get-priority txt)))
  5364. 'org-category category
  5365. 'category-position category-pos
  5366. 'org-habit-p habitp
  5367. 'todo-state todo-state)
  5368. (push txt ee))))))
  5369. (nreverse ee)))
  5370. (defun org-agenda-get-blocks ()
  5371. "Return the date-range information for agenda display."
  5372. (let* ((props (list 'face nil
  5373. 'org-not-done-regexp org-not-done-regexp
  5374. 'org-todo-regexp org-todo-regexp
  5375. 'org-complex-heading-regexp org-complex-heading-regexp
  5376. 'mouse-face 'highlight
  5377. 'help-echo
  5378. (format "mouse-2 or RET jump to org file %s"
  5379. (abbreviate-file-name buffer-file-name))))
  5380. (regexp org-tr-regexp)
  5381. (d0 (calendar-absolute-from-gregorian date))
  5382. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5383. todo-state tags pos head donep)
  5384. (goto-char (point-min))
  5385. (while (re-search-forward regexp nil t)
  5386. (catch :skip
  5387. (org-agenda-skip)
  5388. (setq pos (point))
  5389. (let ((start-time (match-string 1))
  5390. (end-time (match-string 2)))
  5391. (setq s1 (match-string 1)
  5392. s2 (match-string 2)
  5393. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5394. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5395. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5396. ;; Only allow days between the limits, because the normal
  5397. ;; date stamps will catch the limits.
  5398. (save-excursion
  5399. (setq todo-state (org-get-todo-state))
  5400. (setq donep (member todo-state org-done-keywords))
  5401. (if (and donep org-agenda-skip-timestamp-if-done)
  5402. (throw :skip t))
  5403. (setq marker (org-agenda-new-marker (point)))
  5404. (setq category (org-get-category)
  5405. category-pos (get-text-property (point) 'org-category-position))
  5406. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5407. (setq txt org-agenda-no-heading-message)
  5408. (goto-char (match-beginning 0))
  5409. (setq hdmarker (org-agenda-new-marker (point)))
  5410. (setq tags (org-get-tags-at))
  5411. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5412. (setq head (match-string 1))
  5413. (let ((remove-re
  5414. (if org-agenda-remove-timeranges-from-blocks
  5415. (concat
  5416. "<" (regexp-quote s1) ".*?>"
  5417. "--"
  5418. "<" (regexp-quote s2) ".*?>")
  5419. nil)))
  5420. (setq txt (org-agenda-format-item
  5421. (format
  5422. (nth (if (= d1 d2) 0 1)
  5423. org-agenda-timerange-leaders)
  5424. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5425. head category tags
  5426. (cond ((and (= d1 d0) (= d2 d0))
  5427. (concat "<" start-time ">--<" end-time ">"))
  5428. ((= d1 d0)
  5429. (concat "<" start-time ">"))
  5430. ((= d2 d0)
  5431. (concat "<" end-time ">")))
  5432. remove-re))))
  5433. (org-add-props txt props
  5434. 'org-marker marker 'org-hd-marker hdmarker
  5435. 'type "block" 'date date
  5436. 'todo-state todo-state
  5437. 'priority (org-get-priority txt) 'org-category category
  5438. 'org-category-position category-pos)
  5439. (push txt ee))))
  5440. (goto-char pos)))
  5441. ;; Sort the entries by expiration date.
  5442. (nreverse ee)))
  5443. ;;; Agenda presentation and sorting
  5444. (defvar org-prefix-has-time nil
  5445. "A flag, set by `org-compile-prefix-format'.
  5446. The flag is set if the currently compiled format contains a `%t'.")
  5447. (defvar org-prefix-has-tag nil
  5448. "A flag, set by `org-compile-prefix-format'.
  5449. The flag is set if the currently compiled format contains a `%T'.")
  5450. (defvar org-prefix-has-effort nil
  5451. "A flag, set by `org-compile-prefix-format'.
  5452. The flag is set if the currently compiled format contains a `%e'.")
  5453. (defvar org-prefix-category-length nil
  5454. "Used by `org-compile-prefix-format' to remember the category field width.")
  5455. (defvar org-prefix-category-max-length nil
  5456. "Used by `org-compile-prefix-format' to remember the category field width.")
  5457. (defun org-agenda-get-category-icon (category)
  5458. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5459. (dolist (entry org-agenda-category-icon-alist)
  5460. (when (org-string-match-p (car entry) category)
  5461. (if (listp (cadr entry))
  5462. (return (cadr entry))
  5463. (return (apply 'create-image (cdr entry)))))))
  5464. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5465. remove-re habitp)
  5466. "Format TXT to be inserted into the agenda buffer.
  5467. In particular, it adds the prefix and corresponding text properties. EXTRA
  5468. must be a string and replaces the `%s' specifier in the prefix format.
  5469. CATEGORY (string, symbol or nil) may be used to overrule the default
  5470. category taken from local variable or file name. It will replace the `%c'
  5471. specifier in the format. DOTIME, when non-nil, indicates that a
  5472. time-of-day should be extracted from TXT for sorting of this entry, and for
  5473. the `%t' specifier in the format. When DOTIME is a string, this string is
  5474. searched for a time before TXT is. TAGS can be the tags of the headline.
  5475. Any match of REMOVE-RE will be removed from TXT."
  5476. ;; We keep the org-prefix-* variable values along with a compiled
  5477. ;; formatter, so that multiple agendas existing at the same time, do
  5478. ;; not step on each other toes.
  5479. ;;
  5480. ;; It was inconvenient to make these variables buffer local in
  5481. ;; Agenda buffers, because this function expects to be called with
  5482. ;; the buffer where item comes from being current, and not agenda
  5483. ;; buffer
  5484. (let* ((bindings (car org-prefix-format-compiled))
  5485. (formatter (cadr org-prefix-format-compiled)))
  5486. (loop for (var value) in bindings
  5487. do (set var value))
  5488. (save-match-data
  5489. ;; Diary entries sometimes have extra whitespace at the beginning
  5490. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5491. ;; Fix the tags part in txt
  5492. (setq txt (org-agenda-fix-displayed-tags
  5493. txt tags
  5494. org-agenda-show-inherited-tags
  5495. org-agenda-hide-tags-regexp))
  5496. (let* ((category (or category
  5497. (if (stringp org-category)
  5498. org-category
  5499. (and org-category (symbol-name org-category)))
  5500. (if buffer-file-name
  5501. (file-name-sans-extension
  5502. (file-name-nondirectory buffer-file-name))
  5503. "")))
  5504. (category-icon (org-agenda-get-category-icon category))
  5505. (category-icon (if category-icon
  5506. (propertize " " 'display category-icon)
  5507. ""))
  5508. ;; time, tag, effort are needed for the eval of the prefix format
  5509. (tag (if tags (nth (1- (length tags)) tags) ""))
  5510. time effort neffort
  5511. (ts (if dotime (concat
  5512. (if (stringp dotime) dotime "")
  5513. (and org-agenda-search-headline-for-time txt))))
  5514. (time-of-day (and dotime (org-get-time-of-day ts)))
  5515. stamp plain s0 s1 s2 rtn srp l
  5516. duration thecategory)
  5517. (and (derived-mode-p 'org-mode) buffer-file-name
  5518. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5519. (when (and dotime time-of-day)
  5520. ;; Extract starting and ending time and move them to prefix
  5521. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5522. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5523. (setq s0 (match-string 0 ts)
  5524. srp (and stamp (match-end 3))
  5525. s1 (match-string (if plain 1 2) ts)
  5526. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5527. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5528. ;; them, we might want to remove them there to avoid duplication.
  5529. ;; The user can turn this off with a variable.
  5530. (if (and org-prefix-has-time
  5531. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5532. (string-match (concat (regexp-quote s0) " *") txt)
  5533. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5534. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5535. (= (match-beginning 0) 0)
  5536. t))
  5537. (setq txt (replace-match "" nil nil txt))))
  5538. ;; Normalize the time(s) to 24 hour
  5539. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5540. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5541. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5542. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5543. (setq s2
  5544. (org-minutes-to-hh:mm-string
  5545. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5546. ;; Compute the duration
  5547. (when s2
  5548. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5549. (org-hh:mm-string-to-minutes s1)))))
  5550. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5551. txt)
  5552. ;; Tags are in the string
  5553. (if (or (eq org-agenda-remove-tags t)
  5554. (and org-agenda-remove-tags
  5555. org-prefix-has-tag))
  5556. (setq txt (replace-match "" t t txt))
  5557. (setq txt (replace-match
  5558. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5559. (match-string 2 txt))
  5560. t t txt))))
  5561. (when (derived-mode-p 'org-mode)
  5562. (setq effort
  5563. (condition-case nil
  5564. (org-get-effort
  5565. (or (get-text-property 0 'org-hd-marker txt)
  5566. (get-text-property 0 'org-marker txt)))
  5567. (error nil)))
  5568. (when effort
  5569. (setq neffort (org-duration-string-to-minutes effort)
  5570. effort (setq effort (concat "[" effort "]")))))
  5571. ;; prevent erroring out with %e format when there is no effort
  5572. (or effort (setq effort ""))
  5573. (when remove-re
  5574. (while (string-match remove-re txt)
  5575. (setq txt (replace-match "" t t txt))))
  5576. ;; Set org-heading property on `txt' to mark the start of the
  5577. ;; heading.
  5578. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5579. ;; Prepare the variables needed in the eval of the compiled format
  5580. (setq time (cond (s2 (concat
  5581. (org-agenda-time-of-day-to-ampm-maybe s1)
  5582. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5583. (if org-agenda-timegrid-use-ampm " ")))
  5584. (s1 (concat
  5585. (org-agenda-time-of-day-to-ampm-maybe s1)
  5586. (if org-agenda-timegrid-use-ampm
  5587. "........ "
  5588. "......")))
  5589. (t ""))
  5590. extra (or (and (not habitp) extra) "")
  5591. category (if (symbolp category) (symbol-name category) category)
  5592. thecategory (copy-sequence category))
  5593. (if (string-match org-bracket-link-regexp category)
  5594. (progn
  5595. (setq l (if (match-end 3)
  5596. (- (match-end 3) (match-beginning 3))
  5597. (- (match-end 1) (match-beginning 1))))
  5598. (when (< l (or org-prefix-category-length 0))
  5599. (setq category (copy-sequence category))
  5600. (org-add-props category nil
  5601. 'extra-space (make-string
  5602. (- org-prefix-category-length l 1) ?\ ))))
  5603. (if (and org-prefix-category-max-length
  5604. (>= (length category) org-prefix-category-max-length))
  5605. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5606. ;; Evaluate the compiled format
  5607. (setq rtn (concat (eval formatter) txt))
  5608. ;; And finally add the text properties
  5609. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5610. (org-add-props rtn nil
  5611. 'org-category (if thecategory (downcase thecategory) category)
  5612. 'tags (mapcar 'org-downcase-keep-props tags)
  5613. 'org-highest-priority org-highest-priority
  5614. 'org-lowest-priority org-lowest-priority
  5615. 'time-of-day time-of-day
  5616. 'duration duration
  5617. 'effort effort
  5618. 'effort-minutes neffort
  5619. 'txt txt
  5620. 'time time
  5621. 'extra extra
  5622. 'format org-prefix-format-compiled
  5623. 'dotime dotime)))))
  5624. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5625. "Remove tags string from TXT, and add a modified list of tags.
  5626. The modified list may contain inherited tags, and tags matched by
  5627. `org-agenda-hide-tags-regexp' will be removed."
  5628. (when (or add-inherited hide-re)
  5629. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5630. (setq txt (substring txt 0 (match-beginning 0))))
  5631. (setq tags
  5632. (delq nil
  5633. (mapcar (lambda (tg)
  5634. (if (or (and hide-re (string-match hide-re tg))
  5635. (and (not add-inherited)
  5636. (get-text-property 0 'inherited tg)))
  5637. nil
  5638. tg))
  5639. tags)))
  5640. (when tags
  5641. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5642. i)
  5643. (setq txt (concat txt " :"
  5644. (mapconcat
  5645. (lambda (x)
  5646. (setq i (get-text-property 0 'inherited x))
  5647. (if (and have-i (not i))
  5648. (progn
  5649. (setq have-i nil)
  5650. (concat ":" x))
  5651. x))
  5652. tags ":")
  5653. (if have-i "::" ":"))))))
  5654. txt)
  5655. (defun org-downcase-keep-props (s)
  5656. (let ((props (text-properties-at 0 s)))
  5657. (setq s (downcase s))
  5658. (add-text-properties 0 (length s) props s)
  5659. s))
  5660. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5661. (defvar org-agenda-sorting-strategy-selected nil)
  5662. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5663. (catch 'exit
  5664. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5665. ((and todayp (member 'today (car org-agenda-time-grid))))
  5666. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5667. ((member 'weekly (car org-agenda-time-grid)))
  5668. (t (throw 'exit list)))
  5669. (let* ((have (delq nil (mapcar
  5670. (lambda (x) (get-text-property 1 'time-of-day x))
  5671. list)))
  5672. (string (nth 1 org-agenda-time-grid))
  5673. (gridtimes (nth 2 org-agenda-time-grid))
  5674. (req (car org-agenda-time-grid))
  5675. (remove (member 'remove-match req))
  5676. new time)
  5677. (if (and (member 'require-timed req) (not have))
  5678. ;; don't show empty grid
  5679. (throw 'exit list))
  5680. (while (setq time (pop gridtimes))
  5681. (unless (and remove (member time have))
  5682. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5683. (push (org-agenda-format-item
  5684. nil string "" nil
  5685. (concat (substring time 0 -2) ":" (substring time -2)))
  5686. new)
  5687. (put-text-property
  5688. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5689. (when (and todayp org-agenda-show-current-time-in-grid)
  5690. (push (org-agenda-format-item
  5691. nil
  5692. org-agenda-current-time-string
  5693. "" nil
  5694. (format-time-string "%H:%M "))
  5695. new)
  5696. (put-text-property
  5697. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5698. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5699. (append new list)
  5700. (append list new)))))
  5701. (defun org-compile-prefix-format (key)
  5702. "Compile the prefix format into a Lisp form that can be evaluated.
  5703. The resulting form and associated variable bindings is returned
  5704. and stored in the variable `org-prefix-format-compiled'."
  5705. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5706. org-prefix-category-length nil
  5707. org-prefix-has-effort nil)
  5708. (let ((s (cond
  5709. ((stringp org-agenda-prefix-format)
  5710. org-agenda-prefix-format)
  5711. ((assq key org-agenda-prefix-format)
  5712. (cdr (assq key org-agenda-prefix-format)))
  5713. (t " %-12:c%?-12t% s")))
  5714. (start 0)
  5715. varform vars var e c f opt)
  5716. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5717. s start)
  5718. (setq var (or (cdr (assoc (match-string 4 s)
  5719. '(("c" . category) ("t" . time) ("s" . extra)
  5720. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5721. 'eval)
  5722. c (or (match-string 3 s) "")
  5723. opt (match-beginning 1)
  5724. start (1+ (match-beginning 0)))
  5725. (if (equal var 'time) (setq org-prefix-has-time t))
  5726. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5727. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5728. (setq f (concat "%" (match-string 2 s) "s"))
  5729. (when (equal var 'category)
  5730. (setq org-prefix-category-length
  5731. (floor (abs (string-to-number (match-string 2 s)))))
  5732. (setq org-prefix-category-max-length
  5733. (let ((x (match-string 2 s)))
  5734. (save-match-data
  5735. (if (string-match "\\.[0-9]+" x)
  5736. (string-to-number (substring (match-string 0 x) 1)))))))
  5737. (if (eq var 'eval)
  5738. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5739. (if opt
  5740. (setq varform
  5741. `(if (equal "" ,var)
  5742. ""
  5743. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5744. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5745. (setq s (replace-match "%s" t nil s))
  5746. (push varform vars))
  5747. (setq vars (nreverse vars))
  5748. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5749. (setq org-prefix-format-compiled
  5750. (list
  5751. `((org-prefix-has-time ,org-prefix-has-time)
  5752. (org-prefix-has-tag ,org-prefix-has-tag)
  5753. (org-prefix-category-length ,org-prefix-category-length)
  5754. (org-prefix-has-effort ,org-prefix-has-effort))
  5755. `(format ,s ,@vars))))))
  5756. (defun org-set-sorting-strategy (key)
  5757. (if (symbolp (car org-agenda-sorting-strategy))
  5758. ;; the old format
  5759. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5760. (setq org-agenda-sorting-strategy-selected
  5761. (or (cdr (assq key org-agenda-sorting-strategy))
  5762. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5763. '(time-up category-keep priority-down)))))
  5764. (defun org-get-time-of-day (s &optional string mod24)
  5765. "Check string S for a time of day.
  5766. If found, return it as a military time number between 0 and 2400.
  5767. If not found, return nil.
  5768. The optional STRING argument forces conversion into a 5 character wide string
  5769. HH:MM."
  5770. (save-match-data
  5771. (when
  5772. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5773. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5774. (let* ((h (string-to-number (match-string 1 s)))
  5775. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5776. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5777. (am-p (equal ampm "am"))
  5778. (h1 (cond ((not ampm) h)
  5779. ((= h 12) (if am-p 0 12))
  5780. (t (+ h (if am-p 0 12)))))
  5781. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5782. (mod h1 24) h1))
  5783. (t0 (+ (* 100 h2) m))
  5784. (t1 (concat (if (>= h1 24) "+" " ")
  5785. (if (and org-agenda-time-leading-zero
  5786. (< t0 1000)) "0" "")
  5787. (if (< t0 100) "0" "")
  5788. (if (< t0 10) "0" "")
  5789. (int-to-string t0))))
  5790. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5791. (defvar org-agenda-before-sorting-filter-function nil
  5792. "Function to be applied to agenda items prior to sorting.
  5793. Prior to sorting also means just before they are inserted into the agenda.
  5794. To aid sorting, you may revisit the original entries and add more text
  5795. properties which will later be used by the sorting functions.
  5796. The function should take a string argument, an agenda line.
  5797. It has access to the text properties in that line, which contain among
  5798. other things, the property `org-hd-marker' that points to the entry
  5799. where the line comes from. Note that not all lines going into the agenda
  5800. have this property, only most.
  5801. The function should return the modified string. It is probably best
  5802. to ONLY change text properties.
  5803. You can also use this function as a filter, by returning nil for lines
  5804. you don't want to have in the agenda at all. For this application, you
  5805. could bind the variable in the options section of a custom command.")
  5806. (defun org-agenda-finalize-entries (list &optional nosort)
  5807. "Sort and concatenate the agenda items."
  5808. (setq list (mapcar 'org-agenda-highlight-todo list))
  5809. (if nosort
  5810. list
  5811. (when org-agenda-before-sorting-filter-function
  5812. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5813. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5814. (defun org-agenda-highlight-todo (x)
  5815. (let ((org-done-keywords org-done-keywords-for-agenda)
  5816. (case-fold-search nil)
  5817. re)
  5818. (if (eq x 'line)
  5819. (save-excursion
  5820. (beginning-of-line 1)
  5821. (setq re (org-get-at-bol 'org-todo-regexp))
  5822. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5823. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5824. (add-text-properties (match-beginning 0) (match-end 1)
  5825. (list 'face (org-get-todo-face 1)))
  5826. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5827. (delete-region (match-beginning 1) (1- (match-end 0)))
  5828. (goto-char (match-beginning 1))
  5829. (insert (format org-agenda-todo-keyword-format s)))))
  5830. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5831. (setq re (get-text-property 0 'org-todo-regexp x))
  5832. (when (and re
  5833. ;; Test `pl' because if there's no heading content,
  5834. ;; there's no point matching to highlight. Note
  5835. ;; that if we didn't test `pl' first, and there
  5836. ;; happened to be no keyword from `org-todo-regexp'
  5837. ;; on this heading line, then the `equal' comparison
  5838. ;; afterwards would spuriously succeed in the case
  5839. ;; where `pl' is nil -- causing an args-out-of-range
  5840. ;; error when we try to add text properties to text
  5841. ;; that isn't there.
  5842. pl
  5843. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5844. x pl) pl))
  5845. (add-text-properties
  5846. (or (match-end 1) (match-end 0)) (match-end 0)
  5847. (list 'face (org-get-todo-face (match-string 2 x)))
  5848. x)
  5849. (when (match-end 1)
  5850. (setq x (concat (substring x 0 (match-end 1))
  5851. (format org-agenda-todo-keyword-format
  5852. (match-string 2 x))
  5853. (org-add-props " " (text-properties-at 0 x))
  5854. (substring x (match-end 3)))))))
  5855. x)))
  5856. (defsubst org-cmp-priority (a b)
  5857. "Compare the priorities of string A and B."
  5858. (let ((pa (or (get-text-property 1 'priority a) 0))
  5859. (pb (or (get-text-property 1 'priority b) 0)))
  5860. (cond ((> pa pb) +1)
  5861. ((< pa pb) -1))))
  5862. (defsubst org-cmp-effort (a b)
  5863. "Compare the effort values of string A and B."
  5864. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5865. (ea (or (get-text-property 1 'effort-minutes a) def))
  5866. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5867. (cond ((> ea eb) +1)
  5868. ((< ea eb) -1))))
  5869. (defsubst org-cmp-category (a b)
  5870. "Compare the string values of categories of strings A and B."
  5871. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5872. (cb (or (get-text-property 1 'org-category b) "")))
  5873. (cond ((string-lessp ca cb) -1)
  5874. ((string-lessp cb ca) +1))))
  5875. (defsubst org-cmp-todo-state (a b)
  5876. "Compare the todo states of strings A and B."
  5877. (let* ((ma (or (get-text-property 1 'org-marker a)
  5878. (get-text-property 1 'org-hd-marker a)))
  5879. (mb (or (get-text-property 1 'org-marker b)
  5880. (get-text-property 1 'org-hd-marker b)))
  5881. (fa (and ma (marker-buffer ma)))
  5882. (fb (and mb (marker-buffer mb)))
  5883. (todo-kwds
  5884. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5885. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5886. (ta (or (get-text-property 1 'todo-state a) ""))
  5887. (tb (or (get-text-property 1 'todo-state b) ""))
  5888. (la (- (length (member ta todo-kwds))))
  5889. (lb (- (length (member tb todo-kwds))))
  5890. (donepa (member ta org-done-keywords-for-agenda))
  5891. (donepb (member tb org-done-keywords-for-agenda)))
  5892. (cond ((and donepa (not donepb)) -1)
  5893. ((and (not donepa) donepb) +1)
  5894. ((< la lb) -1)
  5895. ((< lb la) +1))))
  5896. (defsubst org-cmp-alpha (a b)
  5897. "Compare the headlines, alphabetically."
  5898. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5899. (plb (text-property-any 0 (length b) 'org-heading t b))
  5900. (ta (and pla (substring a pla)))
  5901. (tb (and plb (substring b plb))))
  5902. (when pla
  5903. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5904. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5905. (setq ta (substring ta (match-end 0))))
  5906. (setq ta (downcase ta)))
  5907. (when plb
  5908. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5909. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5910. (setq tb (substring tb (match-end 0))))
  5911. (setq tb (downcase tb)))
  5912. (cond ((not ta) +1)
  5913. ((not tb) -1)
  5914. ((string-lessp ta tb) -1)
  5915. ((string-lessp tb ta) +1))))
  5916. (defsubst org-cmp-tag (a b)
  5917. "Compare the string values of the first tags of A and B."
  5918. (let ((ta (car (last (get-text-property 1 'tags a))))
  5919. (tb (car (last (get-text-property 1 'tags b)))))
  5920. (cond ((not ta) +1)
  5921. ((not tb) -1)
  5922. ((string-lessp ta tb) -1)
  5923. ((string-lessp tb ta) +1))))
  5924. (defsubst org-cmp-time (a b)
  5925. "Compare the time-of-day values of strings A and B."
  5926. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5927. (ta (or (get-text-property 1 'time-of-day a) def))
  5928. (tb (or (get-text-property 1 'time-of-day b) def)))
  5929. (cond ((< ta tb) -1)
  5930. ((< tb ta) +1))))
  5931. (defsubst org-cmp-habit-p (a b)
  5932. "Compare the todo states of strings A and B."
  5933. (let ((ha (get-text-property 1 'org-habit-p a))
  5934. (hb (get-text-property 1 'org-habit-p b)))
  5935. (cond ((and ha (not hb)) -1)
  5936. ((and (not ha) hb) +1))))
  5937. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5938. (defun org-entries-lessp (a b)
  5939. "Predicate for sorting agenda entries."
  5940. ;; The following variables will be used when the form is evaluated.
  5941. ;; So even though the compiler complains, keep them.
  5942. (let* ((ss org-agenda-sorting-strategy-selected)
  5943. (time-up (and (org-em 'time-up 'time-down ss)
  5944. (org-cmp-time a b)))
  5945. (time-down (if time-up (- time-up) nil))
  5946. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5947. (org-cmp-priority a b)))
  5948. (priority-down (if priority-up (- priority-up) nil))
  5949. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5950. (org-cmp-effort a b)))
  5951. (effort-down (if effort-up (- effort-up) nil))
  5952. (category-up (and (or (org-em 'category-up 'category-down ss)
  5953. (memq 'category-keep ss))
  5954. (org-cmp-category a b)))
  5955. (category-down (if category-up (- category-up) nil))
  5956. (category-keep (if category-up +1 nil))
  5957. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5958. (org-cmp-tag a b)))
  5959. (tag-down (if tag-up (- tag-up) nil))
  5960. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5961. (org-cmp-todo-state a b)))
  5962. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5963. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5964. (org-cmp-habit-p a b)))
  5965. (habit-down (if habit-up (- habit-up) nil))
  5966. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5967. (org-cmp-alpha a b)))
  5968. (alpha-down (if alpha-up (- alpha-up) nil))
  5969. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5970. user-defined-up user-defined-down)
  5971. (if (and need-user-cmp org-agenda-cmp-user-defined
  5972. (functionp org-agenda-cmp-user-defined))
  5973. (setq user-defined-up
  5974. (funcall org-agenda-cmp-user-defined a b)
  5975. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5976. (cdr (assoc
  5977. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5978. '((-1 . t) (1 . nil) (nil . nil))))))
  5979. ;;; Agenda restriction lock
  5980. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5981. "Overlay to mark the headline to which agenda commands are restricted.")
  5982. (overlay-put org-agenda-restriction-lock-overlay
  5983. 'face 'org-agenda-restriction-lock)
  5984. (overlay-put org-agenda-restriction-lock-overlay
  5985. 'help-echo "Agendas are currently limited to this subtree.")
  5986. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5987. (defun org-agenda-set-restriction-lock (&optional type)
  5988. "Set restriction lock for agenda, to current subtree or file.
  5989. Restriction will be the file if TYPE is `file', or if type is the
  5990. universal prefix '(4), or if the cursor is before the first headline
  5991. in the file. Otherwise, restriction will be to the current subtree."
  5992. (interactive "P")
  5993. (and (equal type '(4)) (setq type 'file))
  5994. (setq type (cond
  5995. (type type)
  5996. ((org-at-heading-p) 'subtree)
  5997. ((condition-case nil (org-back-to-heading t) (error nil))
  5998. 'subtree)
  5999. (t 'file)))
  6000. (if (eq type 'subtree)
  6001. (progn
  6002. (setq org-agenda-restrict t)
  6003. (setq org-agenda-overriding-restriction 'subtree)
  6004. (put 'org-agenda-files 'org-restrict
  6005. (list (buffer-file-name (buffer-base-buffer))))
  6006. (org-back-to-heading t)
  6007. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6008. (move-marker org-agenda-restrict-begin (point))
  6009. (move-marker org-agenda-restrict-end
  6010. (save-excursion (org-end-of-subtree t)))
  6011. (message "Locking agenda restriction to subtree"))
  6012. (put 'org-agenda-files 'org-restrict
  6013. (list (buffer-file-name (buffer-base-buffer))))
  6014. (setq org-agenda-restrict nil)
  6015. (setq org-agenda-overriding-restriction 'file)
  6016. (move-marker org-agenda-restrict-begin nil)
  6017. (move-marker org-agenda-restrict-end nil)
  6018. (message "Locking agenda restriction to file"))
  6019. (setq current-prefix-arg nil)
  6020. (org-agenda-maybe-redo))
  6021. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6022. "Remove the agenda restriction lock."
  6023. (interactive "P")
  6024. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6025. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6026. (setq org-agenda-overriding-restriction nil)
  6027. (setq org-agenda-restrict nil)
  6028. (put 'org-agenda-files 'org-restrict nil)
  6029. (move-marker org-agenda-restrict-begin nil)
  6030. (move-marker org-agenda-restrict-end nil)
  6031. (setq current-prefix-arg nil)
  6032. (message "Agenda restriction lock removed")
  6033. (or noupdate (org-agenda-maybe-redo)))
  6034. (defun org-agenda-maybe-redo ()
  6035. "If there is any window showing the agenda view, update it."
  6036. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6037. (w0 (selected-window)))
  6038. (when w
  6039. (select-window w)
  6040. (org-agenda-redo)
  6041. (select-window w0)
  6042. (if org-agenda-overriding-restriction
  6043. (message "Agenda view shifted to new %s restriction"
  6044. org-agenda-overriding-restriction)
  6045. (message "Agenda restriction lock removed")))))
  6046. ;;; Agenda commands
  6047. (defun org-agenda-check-type (error &rest types)
  6048. "Check if agenda buffer is of allowed type.
  6049. If ERROR is non-nil, throw an error, otherwise just return nil."
  6050. (if (not org-agenda-type)
  6051. (error "No Org agenda currently displayed")
  6052. (if (memq org-agenda-type types)
  6053. t
  6054. (if error
  6055. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6056. nil))))
  6057. (defun org-agenda-Quit (&optional arg)
  6058. "Exit agenda by removing the window or the buffer."
  6059. (interactive)
  6060. (if org-agenda-columns-active
  6061. (org-columns-quit)
  6062. (let ((buf (current-buffer)))
  6063. (if (eq org-agenda-window-setup 'other-frame)
  6064. (progn
  6065. (org-agenda-reset-markers)
  6066. (kill-buffer buf)
  6067. (org-columns-remove-overlays)
  6068. (setq org-agenda-archives-mode nil)
  6069. (delete-frame))
  6070. (and (not (eq org-agenda-window-setup 'current-window))
  6071. (not (one-window-p))
  6072. (delete-window))
  6073. (org-agenda-reset-markers)
  6074. (kill-buffer buf)
  6075. (org-columns-remove-overlays)
  6076. (setq org-agenda-archives-mode nil)))
  6077. ;; Maybe restore the pre-agenda window configuration.
  6078. (and org-agenda-restore-windows-after-quit
  6079. (not (eq org-agenda-window-setup 'other-frame))
  6080. org-agenda-pre-window-conf
  6081. (set-window-configuration org-agenda-pre-window-conf)
  6082. (setq org-agenda-pre-window-conf nil))))
  6083. (defun org-agenda-quit ()
  6084. "Exit agenda by killing agenda buffer or burying it when
  6085. `org-agenda-sticky' is non-NIL"
  6086. (interactive)
  6087. (if org-agenda-columns-active
  6088. (org-columns-quit)
  6089. (if org-agenda-sticky
  6090. (let ((buf (current-buffer)))
  6091. (if (eq org-agenda-window-setup 'other-frame)
  6092. (progn
  6093. (delete-frame))
  6094. (and (not (eq org-agenda-window-setup 'current-window))
  6095. (not (one-window-p))
  6096. (delete-window)))
  6097. (with-current-buffer buf
  6098. (bury-buffer)
  6099. ;; Maybe restore the pre-agenda window configuration.
  6100. (and org-agenda-restore-windows-after-quit
  6101. (not (eq org-agenda-window-setup 'other-frame))
  6102. org-agenda-pre-window-conf
  6103. (set-window-configuration org-agenda-pre-window-conf)
  6104. (setq org-agenda-pre-window-conf nil))))
  6105. (org-agenda-Quit))))
  6106. (defun org-agenda-exit ()
  6107. "Exit agenda by removing the window or the buffer.
  6108. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6109. Org-mode buffers visited directly by the user will not be touched."
  6110. (interactive)
  6111. (org-release-buffers org-agenda-new-buffers)
  6112. (setq org-agenda-new-buffers nil)
  6113. (org-agenda-Quit))
  6114. (defun org-agenda-kill-all-agenda-buffers ()
  6115. "Kill all buffers in `org-agena-mode'.
  6116. This is used when toggling sticky agendas. You can also explicitly invoke it
  6117. with `C-c a C-k'."
  6118. (interactive)
  6119. (let (blist)
  6120. (dolist (buf (buffer-list))
  6121. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6122. (push buf blist)))
  6123. (mapc 'kill-buffer blist)))
  6124. (defun org-agenda-execute (arg)
  6125. "Execute another agenda command, keeping same window.
  6126. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6127. in the agenda."
  6128. (interactive "P")
  6129. (let ((org-agenda-window-setup 'current-window))
  6130. (org-agenda arg)))
  6131. (defun org-agenda-redo (&optional all)
  6132. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6133. (interactive "P")
  6134. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6135. (cpa (unless (eq all t) current-prefix-arg))
  6136. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6137. (org-agenda-sticky nil)
  6138. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6139. org-agenda-buffer-name))
  6140. (org-agenda-keep-modes t)
  6141. (tag-filter org-agenda-tag-filter)
  6142. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6143. (top-cat-filter org-agenda-top-category-filter)
  6144. (cat-filter org-agenda-category-filter)
  6145. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6146. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6147. (cols org-agenda-columns-active)
  6148. (line (org-current-line))
  6149. (window-line (- line (org-current-line (window-start))))
  6150. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6151. (redo-cmd (get-text-property p 'org-redo-cmd))
  6152. (last-args (get-text-property p 'org-last-args))
  6153. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6154. (org-agenda-overriding-cmd-arguments
  6155. (unless (eq all t)
  6156. (cond ((listp last-args)
  6157. (cons (or cpa (car last-args)) (cdr last-args)))
  6158. ((stringp last-args)
  6159. last-args))))
  6160. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6161. (put 'org-agenda-tag-filter :preset-filter nil)
  6162. (put 'org-agenda-category-filter :preset-filter nil)
  6163. (and cols (org-columns-quit))
  6164. (message "Rebuilding agenda buffer...")
  6165. (if serie-redo-cmd
  6166. (eval serie-redo-cmd)
  6167. (org-let lprops '(eval redo-cmd)))
  6168. (setq org-agenda-undo-list nil
  6169. org-agenda-pending-undo-list nil)
  6170. (message "Rebuilding agenda buffer...done")
  6171. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6172. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6173. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6174. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6175. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6176. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6177. (org-goto-line line)
  6178. (recenter window-line)))
  6179. (defvar org-global-tags-completion-table nil)
  6180. (defvar org-agenda-filter-form nil)
  6181. (defvar org-agenda-filtered-by-category nil)
  6182. (defun org-agenda-filter-by-category (strip)
  6183. "Keep only those lines in the agenda buffer that have a specific category.
  6184. The category is that of the current line."
  6185. (interactive "P")
  6186. (if (and org-agenda-filtered-by-category
  6187. org-agenda-category-filter)
  6188. (org-agenda-filter-show-all-cat)
  6189. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6190. (if cat (org-agenda-filter-apply
  6191. (list (concat (if strip "-" "+") cat)) 'category)
  6192. (error "No category at point")))))
  6193. (defun org-find-top-category (&optional pos)
  6194. (save-excursion
  6195. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6196. (if pos (goto-char pos))
  6197. ;; Skip up to the topmost parent
  6198. (while (ignore-errors (outline-up-heading 1) t))
  6199. (ignore-errors
  6200. (nth 4 (org-heading-components))))))
  6201. (defvar org-agenda-filtered-by-top-category nil)
  6202. (defun org-agenda-filter-by-top-category (strip)
  6203. "Keep only those lines in the agenda buffer that have a specific category.
  6204. The category is that of the current line."
  6205. (interactive "P")
  6206. (if org-agenda-filtered-by-top-category
  6207. (progn
  6208. (setq org-agenda-filtered-by-top-category nil
  6209. org-agenda-top-category-filter nil)
  6210. (org-agenda-filter-show-all-cat))
  6211. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6212. (if cat (org-agenda-filter-top-category-apply cat strip)
  6213. (error "No top-level category at point")))))
  6214. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6215. "Keep only those lines in the agenda buffer that have a specific tag.
  6216. The tag is selected with its fast selection letter, as configured.
  6217. With prefix argument STRIP, remove all lines that do have the tag.
  6218. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6219. used to narrow the search - the interactive user can also press `-' or `+'
  6220. to switch to narrowing."
  6221. (interactive "P")
  6222. (let* ((alist org-tag-alist-for-agenda)
  6223. (tag-chars (mapconcat
  6224. (lambda (x) (if (and (not (symbolp (car x)))
  6225. (cdr x))
  6226. (char-to-string (cdr x))
  6227. ""))
  6228. alist ""))
  6229. (efforts (org-split-string
  6230. (or (cdr (assoc (concat org-effort-property "_ALL")
  6231. org-global-properties))
  6232. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6233. "")))
  6234. (effort-op org-agenda-filter-effort-default-operator)
  6235. (effort-prompt "")
  6236. (inhibit-read-only t)
  6237. (current org-agenda-tag-filter)
  6238. maybe-refresh a n tag)
  6239. (unless char
  6240. (message
  6241. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6242. (if narrow "Narrow" "Filter") tag-chars
  6243. (if org-agenda-auto-exclude-function "[RET], " ""))
  6244. (setq char (read-char-exclusive)))
  6245. (when (member char '(?+ ?-))
  6246. ;; Narrowing down
  6247. (cond ((equal char ?-) (setq strip t narrow t))
  6248. ((equal char ?+) (setq strip nil narrow t)))
  6249. (message
  6250. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6251. (setq char (read-char-exclusive)))
  6252. (when (member char '(?< ?> ?= ??))
  6253. ;; An effort operator
  6254. (setq effort-op (char-to-string char))
  6255. (setq alist nil) ; to make sure it will be interpreted as effort.
  6256. (unless (equal char ??)
  6257. (loop for i from 0 to 9 do
  6258. (setq effort-prompt
  6259. (concat
  6260. effort-prompt " ["
  6261. (if (= i 9) "0" (int-to-string (1+ i)))
  6262. "]" (nth i efforts))))
  6263. (message "Effort%s: %s " effort-op effort-prompt)
  6264. (setq char (read-char-exclusive))
  6265. (when (or (< char ?0) (> char ?9))
  6266. (error "Need 1-9,0 to select effort"))))
  6267. (when (equal char ?\t)
  6268. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6269. (org-set-local 'org-global-tags-completion-table
  6270. (org-global-tags-completion-table)))
  6271. (let ((completion-ignore-case t))
  6272. (setq tag (org-icompleting-read
  6273. "Tag: " org-global-tags-completion-table))))
  6274. (cond
  6275. ((equal char ?\r)
  6276. (org-agenda-filter-show-all-tag)
  6277. (when org-agenda-auto-exclude-function
  6278. (setq org-agenda-tag-filter '())
  6279. (dolist (tag (org-agenda-get-represented-tags))
  6280. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6281. (if modifier
  6282. (push modifier org-agenda-tag-filter))))
  6283. (if (not (null org-agenda-tag-filter))
  6284. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6285. (setq maybe-refresh t))
  6286. ((equal char ?/)
  6287. (org-agenda-filter-show-all-tag)
  6288. (when (get 'org-agenda-tag-filter :preset-filter)
  6289. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6290. (setq maybe-refresh t))
  6291. ((equal char ?. )
  6292. (setq org-agenda-tag-filter
  6293. (mapcar (lambda(tag) (concat "+" tag))
  6294. (org-get-at-bol 'tags)))
  6295. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6296. (setq maybe-refresh t))
  6297. ((or (equal char ?\ )
  6298. (setq a (rassoc char alist))
  6299. (and (>= char ?0) (<= char ?9)
  6300. (setq n (if (= char ?0) 9 (- char ?0 1))
  6301. tag (concat effort-op (nth n efforts))
  6302. a (cons tag nil)))
  6303. (and (= char ??)
  6304. (setq tag "?eff")
  6305. a (cons tag nil))
  6306. (and tag (setq a (cons tag nil))))
  6307. (org-agenda-filter-show-all-tag)
  6308. (setq tag (car a))
  6309. (setq org-agenda-tag-filter
  6310. (cons (concat (if strip "-" "+") tag)
  6311. (if narrow current nil)))
  6312. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6313. (setq maybe-refresh t))
  6314. (t (error "Invalid tag selection character %c" char)))
  6315. (when (and maybe-refresh
  6316. (eq org-agenda-clockreport-mode 'with-filter))
  6317. (org-agenda-redo))))
  6318. (defun org-agenda-get-represented-tags ()
  6319. "Get a list of all tags currently represented in the agenda."
  6320. (let (p tags)
  6321. (save-excursion
  6322. (goto-char (point-min))
  6323. (while (setq p (next-single-property-change (point) 'tags))
  6324. (goto-char p)
  6325. (mapc (lambda (x) (add-to-list 'tags x))
  6326. (get-text-property (point) 'tags))))
  6327. tags))
  6328. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6329. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6330. (interactive "P")
  6331. (org-agenda-filter-by-tag strip char 'refine))
  6332. (defun org-agenda-filter-make-matcher ()
  6333. "Create the form that tests a line for agenda filter."
  6334. (let (f f1)
  6335. ;; first compute the tag-filter matcher
  6336. (dolist (x (delete-dups
  6337. (append (get 'org-agenda-tag-filter
  6338. :preset-filter) org-agenda-tag-filter)))
  6339. (if (member x '("-" "+"))
  6340. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6341. (if (string-match "[<=>?]" x)
  6342. (setq f1 (org-agenda-filter-effort-form x))
  6343. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6344. (if (equal (string-to-char x) ?-)
  6345. (setq f1 (list 'not f1))))
  6346. (push f1 f))
  6347. ;; then compute the category-filter matcher
  6348. (dolist (x (delete-dups
  6349. (append (get 'org-agenda-category-filter
  6350. :preset-filter) org-agenda-category-filter)))
  6351. (if (equal "-" (substring x 0 1))
  6352. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6353. (setq f1 (list 'equal (substring x 1) 'cat)))
  6354. (push f1 f))
  6355. (cons 'and (nreverse f))))
  6356. (defun org-agenda-filter-effort-form (e)
  6357. "Return the form to compare the effort of the current line with what E says.
  6358. E looks like \"+<2:25\"."
  6359. (let (op)
  6360. (setq e (substring e 1))
  6361. (setq op (string-to-char e) e (substring e 1))
  6362. (setq op (cond ((equal op ?<) '<=)
  6363. ((equal op ?>) '>=)
  6364. ((equal op ??) op)
  6365. (t '=)))
  6366. (list 'org-agenda-compare-effort (list 'quote op)
  6367. (org-duration-string-to-minutes e))))
  6368. (defun org-agenda-compare-effort (op value)
  6369. "Compare the effort of the current line with VALUE, using OP.
  6370. If the line does not have an effort defined, return nil."
  6371. (let ((eff (org-get-at-bol 'effort-minutes)))
  6372. (if (equal op ??)
  6373. (not eff)
  6374. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6375. value))))
  6376. (defun org-agenda-filter-apply (filter type)
  6377. "Set FILTER as the new agenda filter and apply it."
  6378. (let (tags cat)
  6379. (if (eq type 'tag)
  6380. (setq org-agenda-tag-filter filter)
  6381. (setq org-agenda-category-filter filter))
  6382. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6383. (if (and (eq type 'category)
  6384. (not (equal (substring (car filter) 0 1) "-")))
  6385. ;; Only set `org-agenda-filtered-by-category' to t
  6386. ;; when a unique category is used as the filter
  6387. (setq org-agenda-filtered-by-category t))
  6388. (org-agenda-set-mode-name)
  6389. (save-excursion
  6390. (goto-char (point-min))
  6391. (while (not (eobp))
  6392. (if (org-get-at-bol 'org-marker)
  6393. (progn
  6394. (setq tags (org-get-at-bol 'tags) ; used in eval
  6395. cat (get-text-property (point) 'org-category))
  6396. (if (not (eval org-agenda-filter-form))
  6397. (org-agenda-filter-hide-line type))
  6398. (beginning-of-line 2))
  6399. (beginning-of-line 2))))
  6400. (if (get-char-property (point) 'invisible)
  6401. (ignore-errors (org-agenda-previous-line)))))
  6402. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6403. "Set FILTER as the new agenda filter and apply it."
  6404. (org-agenda-set-mode-name)
  6405. (save-excursion
  6406. (goto-char (point-min))
  6407. (while (not (eobp))
  6408. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6409. (topcat (and pos (org-find-top-category pos))))
  6410. (if (and topcat (funcall (if negative 'identity 'not)
  6411. (string= category topcat)))
  6412. (org-agenda-filter-hide-line 'category)))
  6413. (beginning-of-line 2)))
  6414. (if (get-char-property (point) 'invisible)
  6415. (org-agenda-previous-line))
  6416. (setq org-agenda-top-category-filter category
  6417. org-agenda-filtered-by-top-category t))
  6418. (defun org-agenda-filter-hide-line (type)
  6419. (let (ov)
  6420. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6421. (point-at-eol)))
  6422. (overlay-put ov 'invisible t)
  6423. (overlay-put ov 'type type)
  6424. (if (eq type 'tag)
  6425. (push ov org-agenda-tag-filter-overlays)
  6426. (push ov org-agenda-cat-filter-overlays))))
  6427. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6428. (setq pos (or pos (point)))
  6429. (save-excursion
  6430. (dolist (ov (overlays-at pos))
  6431. (when (and (overlay-get ov 'invisible)
  6432. (eq (overlay-get ov 'type) 'tag))
  6433. (goto-char pos)
  6434. (if (< (overlay-start ov) (point-at-eol))
  6435. (move-overlay ov (point-at-eol)
  6436. (overlay-end ov)))))))
  6437. (defun org-agenda-filter-show-all-tag nil
  6438. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6439. (setq org-agenda-tag-filter-overlays nil
  6440. org-agenda-tag-filter nil
  6441. org-agenda-filter-form nil)
  6442. (org-agenda-set-mode-name))
  6443. (defun org-agenda-filter-show-all-cat nil
  6444. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6445. (setq org-agenda-cat-filter-overlays nil
  6446. org-agenda-filtered-by-category nil
  6447. org-agenda-category-filter nil
  6448. org-agenda-filter-form nil)
  6449. (org-agenda-set-mode-name))
  6450. (defun org-agenda-manipulate-query-add ()
  6451. "Manipulate the query by adding a search term with positive selection.
  6452. Positive selection means the term must be matched for selection of an entry."
  6453. (interactive)
  6454. (org-agenda-manipulate-query ?\[))
  6455. (defun org-agenda-manipulate-query-subtract ()
  6456. "Manipulate the query by adding a search term with negative selection.
  6457. Negative selection means term must not be matched for selection of an entry."
  6458. (interactive)
  6459. (org-agenda-manipulate-query ?\]))
  6460. (defun org-agenda-manipulate-query-add-re ()
  6461. "Manipulate the query by adding a search regexp with positive selection.
  6462. Positive selection means the regexp must match for selection of an entry."
  6463. (interactive)
  6464. (org-agenda-manipulate-query ?\{))
  6465. (defun org-agenda-manipulate-query-subtract-re ()
  6466. "Manipulate the query by adding a search regexp with negative selection.
  6467. Negative selection means regexp must not match for selection of an entry."
  6468. (interactive)
  6469. (org-agenda-manipulate-query ?\}))
  6470. (defun org-agenda-manipulate-query (char)
  6471. (cond
  6472. ((memq org-agenda-type '(timeline agenda))
  6473. (let ((org-agenda-include-inactive-timestamps t))
  6474. (org-agenda-redo))
  6475. (message "Display now includes inactive timestamps as well"))
  6476. ((eq org-agenda-type 'search)
  6477. (org-add-to-string
  6478. 'org-agenda-query-string
  6479. (if org-agenda-last-search-view-search-was-boolean
  6480. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6481. (?\{ . " +{}") (?\} . " -{}"))))
  6482. " "))
  6483. (setq org-agenda-redo-command
  6484. (list 'org-search-view
  6485. (car (get-text-property (point) 'org-last-args))
  6486. org-agenda-query-string
  6487. (+ (length org-agenda-query-string)
  6488. (if (member char '(?\{ ?\})) 0 1))))
  6489. (set-register org-agenda-query-register org-agenda-query-string)
  6490. (let ((org-agenda-overriding-arguments
  6491. (cdr org-agenda-redo-command)))
  6492. (org-agenda-redo)))
  6493. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6494. org-agenda-type))))
  6495. (defun org-add-to-string (var string)
  6496. (set var (concat (symbol-value var) string)))
  6497. (defun org-agenda-goto-date (date)
  6498. "Jump to DATE in agenda."
  6499. (interactive (list (let ((org-read-date-prefer-future
  6500. (eval org-agenda-jump-prefer-future)))
  6501. (org-read-date))))
  6502. (let ((org-agenda-sticky-orig org-agenda-sticky)
  6503. org-agenda-sticky)
  6504. (org-agenda-list nil date)
  6505. (setq org-agenda-sticky org-agenda-sticky-orig
  6506. org-agenda-this-buffer-is-sticky org-agenda-sticky))
  6507. (let ((inhibit-read-only t))
  6508. (add-text-properties (point-min) (point-max)
  6509. `(org-last-cmd
  6510. (org-agenda-list nil ,date)))))
  6511. (defun org-agenda-goto-today ()
  6512. "Go to today."
  6513. (interactive)
  6514. (org-agenda-check-type t 'timeline 'agenda)
  6515. (let* ((args (get-text-property (point) 'org-last-args))
  6516. (curspan (nth 2 args))
  6517. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6518. (cond
  6519. (tdpos (goto-char tdpos))
  6520. ((eq org-agenda-type 'agenda)
  6521. (let* ((sd (org-agenda-compute-starting-span
  6522. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6523. (org-agenda-overriding-arguments args))
  6524. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6525. (org-agenda-redo)
  6526. (org-agenda-find-same-or-today-or-agenda)))
  6527. (t (error "Cannot find today")))))
  6528. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6529. (goto-char
  6530. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6531. (text-property-any (point-min) (point-max) 'org-today t)
  6532. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6533. (and (get-text-property (point) 'org-serie)
  6534. (org-agenda-goto-block-beginning))
  6535. (point-min))))
  6536. (defun org-agenda-goto-block-beginning ()
  6537. "Go the agenda block beginning."
  6538. (interactive)
  6539. (if (not (derived-mode-p 'org-agenda-mode))
  6540. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6541. (let (dest)
  6542. (save-excursion
  6543. (unless (looking-at "\\'")
  6544. (forward-char))
  6545. (let* ((prop 'org-agenda-structural-header)
  6546. (p (previous-single-property-change (point) prop))
  6547. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6548. (1- (point))) prop)))
  6549. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6550. (if (not dest)
  6551. (error "Cannot find the beginning of the blog")
  6552. (goto-char dest)
  6553. (move-beginning-of-line 1)))))
  6554. (defun org-agenda-later (arg)
  6555. "Go forward in time by thee current span.
  6556. With prefix ARG, go forward that many times the current span."
  6557. (interactive "p")
  6558. (org-agenda-check-type t 'agenda)
  6559. (let* ((args (get-text-property (point) 'org-last-args))
  6560. (span (or (nth 2 args) org-agenda-current-span))
  6561. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6562. (greg (calendar-gregorian-from-absolute sd))
  6563. (cnt (org-get-at-bol 'org-day-cnt))
  6564. greg2)
  6565. (cond
  6566. ((numberp span)
  6567. (setq sd (+ span sd)))
  6568. ((eq span 'day)
  6569. (setq sd (+ arg sd)))
  6570. ((eq span 'week)
  6571. (setq sd (+ (* 7 arg) sd)))
  6572. ((eq span 'month)
  6573. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6574. sd (calendar-absolute-from-gregorian greg2))
  6575. (setcar greg2 (1+ (car greg2))))
  6576. ((eq span 'year)
  6577. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6578. sd (calendar-absolute-from-gregorian greg2))
  6579. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6580. (t
  6581. (setq sd (+ (* span arg) sd))))
  6582. (let ((org-agenda-overriding-cmd
  6583. ;; `cmd' may have been set by `org-agenda-run-series' which
  6584. ;; uses `org-agenda-overriding-cmd' to decide whether
  6585. ;; overriding is allowed for `cmd'
  6586. (get-text-property (point) 'org-serie-cmd))
  6587. (org-agenda-overriding-arguments
  6588. (list (car args) sd span)))
  6589. (org-agenda-redo)
  6590. (org-agenda-find-same-or-today-or-agenda cnt))))
  6591. (defun org-agenda-earlier (arg)
  6592. "Go backward in time by the current span.
  6593. With prefix ARG, go backward that many times the current span."
  6594. (interactive "p")
  6595. (org-agenda-later (- arg)))
  6596. (defun org-agenda-view-mode-dispatch ()
  6597. "Call one of the view mode commands."
  6598. (interactive)
  6599. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6600. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6601. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6602. (let ((a (read-char-exclusive)))
  6603. (case a
  6604. (?\ (call-interactively 'org-agenda-reset-view))
  6605. (?d (call-interactively 'org-agenda-day-view))
  6606. (?w (call-interactively 'org-agenda-week-view))
  6607. (?m (call-interactively 'org-agenda-month-view))
  6608. (?y (call-interactively 'org-agenda-year-view))
  6609. (?l (call-interactively 'org-agenda-log-mode))
  6610. (?L (org-agenda-log-mode '(4)))
  6611. (?c (org-agenda-log-mode 'clockcheck))
  6612. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6613. (?a (call-interactively 'org-agenda-archives-mode))
  6614. (?A (org-agenda-archives-mode 'files))
  6615. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6616. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6617. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6618. (?D (call-interactively 'org-agenda-toggle-diary))
  6619. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6620. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6621. (org-agenda-check-type t 'timeline 'agenda)
  6622. (org-agenda-redo))
  6623. (message "Display now includes inactive timestamps as well"))
  6624. (?q (message "Abort"))
  6625. (otherwise (error "Invalid key" )))))
  6626. (defun org-agenda-reset-view ()
  6627. "Switch to default view for agenda."
  6628. (interactive)
  6629. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6630. (defun org-agenda-day-view (&optional day-of-year)
  6631. "Switch to daily view for agenda.
  6632. With argument DAY-OF-YEAR, switch to that day of the year."
  6633. (interactive "P")
  6634. (org-agenda-change-time-span 'day day-of-year))
  6635. (defun org-agenda-week-view (&optional iso-week)
  6636. "Switch to daily view for agenda.
  6637. With argument ISO-WEEK, switch to the corresponding ISO week.
  6638. If ISO-WEEK has more then 2 digits, only the last two encode the
  6639. week. Any digits before this encode a year. So 200712 means
  6640. week 12 of year 2007. Years in the range 1938-2037 can also be
  6641. written as 2-digit years."
  6642. (interactive "P")
  6643. (org-agenda-change-time-span 'week iso-week))
  6644. (defun org-agenda-month-view (&optional month)
  6645. "Switch to monthly view for agenda.
  6646. With argument MONTH, switch to that month."
  6647. (interactive "P")
  6648. (org-agenda-change-time-span 'month month))
  6649. (defun org-agenda-year-view (&optional year)
  6650. "Switch to yearly view for agenda.
  6651. With argument YEAR, switch to that year.
  6652. If MONTH has more then 2 digits, only the last two encode the
  6653. month. Any digits before this encode a year. So 200712 means
  6654. December year 2007. Years in the range 1938-2037 can also be
  6655. written as 2-digit years."
  6656. (interactive "P")
  6657. (when year
  6658. (setq year (org-small-year-to-year year)))
  6659. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6660. (org-agenda-change-time-span 'year year)
  6661. (error "Abort")))
  6662. (defun org-agenda-change-time-span (span &optional n)
  6663. "Change the agenda view to SPAN.
  6664. SPAN may be `day', `week', `month', `year'."
  6665. (org-agenda-check-type t 'agenda)
  6666. (let* ((args (get-text-property (point) 'org-last-args))
  6667. (curspan (nth 2 args)))
  6668. (if (and (not n) (equal curspan span))
  6669. (error "Viewing span is already \"%s\"" span))
  6670. (let* ((sd (or (org-get-at-bol 'day)
  6671. (nth 1 args)
  6672. org-starting-day))
  6673. (sd (org-agenda-compute-starting-span sd span n))
  6674. (org-agenda-overriding-cmd
  6675. (get-text-property (point) 'org-serie-cmd))
  6676. (org-agenda-overriding-arguments
  6677. (list (car args) sd span)))
  6678. (org-agenda-redo)
  6679. (org-agenda-find-same-or-today-or-agenda))
  6680. (org-agenda-set-mode-name)
  6681. (message "Switched to %s view" span)))
  6682. (defun org-agenda-compute-starting-span (sd span &optional n)
  6683. "Compute starting date for agenda.
  6684. SPAN may be `day', `week', `month', `year'. The return value
  6685. is a cons cell with the starting date and the number of days,
  6686. so that the date SD will be in that range."
  6687. (let* ((greg (calendar-gregorian-from-absolute sd))
  6688. (dg (nth 1 greg))
  6689. (mg (car greg))
  6690. (yg (nth 2 greg)))
  6691. (cond
  6692. ((eq span 'day)
  6693. (when n
  6694. (setq sd (+ (calendar-absolute-from-gregorian
  6695. (list mg 1 yg))
  6696. n -1))))
  6697. ((eq span 'week)
  6698. (let* ((nt (calendar-day-of-week
  6699. (calendar-gregorian-from-absolute sd)))
  6700. (d (if org-agenda-start-on-weekday
  6701. (- nt org-agenda-start-on-weekday)
  6702. 0))
  6703. y1)
  6704. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6705. (when n
  6706. (require 'cal-iso)
  6707. (when (> n 99)
  6708. (setq y1 (org-small-year-to-year (/ n 100))
  6709. n (mod n 100)))
  6710. (setq sd
  6711. (calendar-absolute-from-iso
  6712. (list n 1
  6713. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6714. ((eq span 'month)
  6715. (let (y1)
  6716. (when (and n (> n 99))
  6717. (setq y1 (org-small-year-to-year (/ n 100))
  6718. n (mod n 100)))
  6719. (setq sd (calendar-absolute-from-gregorian
  6720. (list (or n mg) 1 (or y1 yg))))))
  6721. ((eq span 'year)
  6722. (setq sd (calendar-absolute-from-gregorian
  6723. (list 1 1 (or n yg))))))
  6724. sd))
  6725. (defun org-agenda-next-date-line (&optional arg)
  6726. "Jump to the next line indicating a date in agenda buffer."
  6727. (interactive "p")
  6728. (org-agenda-check-type t 'agenda 'timeline)
  6729. (beginning-of-line 1)
  6730. ;; This does not work if user makes date format that starts with a blank
  6731. (if (looking-at "^\\S-") (forward-char 1))
  6732. (if (not (re-search-forward "^\\S-" nil t arg))
  6733. (progn
  6734. (backward-char 1)
  6735. (error "No next date after this line in this buffer")))
  6736. (goto-char (match-beginning 0)))
  6737. (defun org-agenda-previous-date-line (&optional arg)
  6738. "Jump to the previous line indicating a date in agenda buffer."
  6739. (interactive "p")
  6740. (org-agenda-check-type t 'agenda 'timeline)
  6741. (beginning-of-line 1)
  6742. (if (not (re-search-backward "^\\S-" nil t arg))
  6743. (error "No previous date before this line in this buffer")))
  6744. ;; Initialize the highlight
  6745. (defvar org-hl (make-overlay 1 1))
  6746. (overlay-put org-hl 'face 'highlight)
  6747. (defun org-highlight (begin end &optional buffer)
  6748. "Highlight a region with overlay."
  6749. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6750. (defun org-unhighlight ()
  6751. "Detach overlay INDEX."
  6752. (org-detach-overlay org-hl))
  6753. (defun org-unhighlight-once ()
  6754. "Remove the highlight from its position, and this function from the hook."
  6755. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6756. (org-unhighlight))
  6757. (defun org-agenda-follow-mode ()
  6758. "Toggle follow mode in an agenda buffer."
  6759. (interactive)
  6760. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6761. (org-agenda-set-mode-name)
  6762. (org-agenda-do-context-action)
  6763. (message "Follow mode is %s"
  6764. (if org-agenda-follow-mode "on" "off")))
  6765. (defun org-agenda-entry-text-mode (&optional arg)
  6766. "Toggle entry text mode in an agenda buffer."
  6767. (interactive "P")
  6768. (setq org-agenda-entry-text-mode (or (integerp arg)
  6769. (not org-agenda-entry-text-mode)))
  6770. (org-agenda-entry-text-hide)
  6771. (and org-agenda-entry-text-mode
  6772. (let ((org-agenda-entry-text-maxlines
  6773. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6774. (org-agenda-entry-text-show)))
  6775. (org-agenda-set-mode-name)
  6776. (message "Entry text mode is %s. Maximum number of lines is %d"
  6777. (if org-agenda-entry-text-mode "on" "off")
  6778. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6779. (defun org-agenda-clockreport-mode (&optional with-filter)
  6780. "Toggle clocktable mode in an agenda buffer.
  6781. With prefix arg WITH-FILTER, make the clocktable respect the current
  6782. agenda filter."
  6783. (interactive "P")
  6784. (org-agenda-check-type t 'agenda)
  6785. (if with-filter
  6786. (setq org-agenda-clockreport-mode 'with-filter)
  6787. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6788. (org-agenda-set-mode-name)
  6789. (org-agenda-redo)
  6790. (message "Clocktable mode is %s"
  6791. (if org-agenda-clockreport-mode "on" "off")))
  6792. (defun org-agenda-log-mode (&optional special)
  6793. "Toggle log mode in an agenda buffer.
  6794. With argument SPECIAL, show all possible log items, not only the ones
  6795. configured in `org-agenda-log-mode-items'.
  6796. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6797. (interactive "P")
  6798. (org-agenda-check-type t 'agenda 'timeline)
  6799. (setq org-agenda-show-log
  6800. (cond
  6801. ((equal special '(16)) 'only)
  6802. ((eq special 'clockcheck)
  6803. (if (eq org-agenda-show-log 'clockcheck)
  6804. nil 'clockcheck))
  6805. (special '(closed clock state))
  6806. (t (not org-agenda-show-log))))
  6807. (org-agenda-set-mode-name)
  6808. (org-agenda-redo)
  6809. (message "Log mode is %s"
  6810. (if org-agenda-show-log "on" "off")))
  6811. (defun org-agenda-archives-mode (&optional with-files)
  6812. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6813. When called with a prefix argument, include all archive files as well."
  6814. (interactive "P")
  6815. (setq org-agenda-archives-mode
  6816. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6817. (org-agenda-set-mode-name)
  6818. (org-agenda-redo)
  6819. (message
  6820. "%s"
  6821. (cond
  6822. ((eq org-agenda-archives-mode nil)
  6823. "No archives are included")
  6824. ((eq org-agenda-archives-mode 'trees)
  6825. (format "Trees with :%s: tag are included" org-archive-tag))
  6826. ((eq org-agenda-archives-mode t)
  6827. (format "Trees with :%s: tag and all active archive files are included"
  6828. org-archive-tag)))))
  6829. (defun org-agenda-toggle-diary ()
  6830. "Toggle diary inclusion in an agenda buffer."
  6831. (interactive)
  6832. (org-agenda-check-type t 'agenda)
  6833. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6834. (org-agenda-redo)
  6835. (org-agenda-set-mode-name)
  6836. (message "Diary inclusion turned %s"
  6837. (if org-agenda-include-diary "on" "off")))
  6838. (defun org-agenda-toggle-deadlines ()
  6839. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6840. (interactive)
  6841. (org-agenda-check-type t 'agenda)
  6842. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6843. (org-agenda-redo)
  6844. (org-agenda-set-mode-name)
  6845. (message "Deadlines inclusion turned %s"
  6846. (if org-agenda-include-deadlines "on" "off")))
  6847. (defun org-agenda-toggle-time-grid ()
  6848. "Toggle time grid in an agenda buffer."
  6849. (interactive)
  6850. (org-agenda-check-type t 'agenda)
  6851. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6852. (org-agenda-redo)
  6853. (org-agenda-set-mode-name)
  6854. (message "Time-grid turned %s"
  6855. (if org-agenda-use-time-grid "on" "off")))
  6856. (defun org-agenda-set-mode-name ()
  6857. "Set the mode name to indicate all the small mode settings."
  6858. (setq mode-name
  6859. (list "Org-Agenda"
  6860. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6861. " "
  6862. '(:eval (org-agenda-span-name org-agenda-current-span))
  6863. (if org-agenda-follow-mode " Follow" "")
  6864. (if org-agenda-entry-text-mode " ETxt" "")
  6865. (if org-agenda-include-diary " Diary" "")
  6866. (if org-agenda-include-deadlines " Ddl" "")
  6867. (if org-agenda-use-time-grid " Grid" "")
  6868. (if (and (boundp 'org-habit-show-habits)
  6869. org-habit-show-habits) " Habit" "")
  6870. (cond
  6871. ((consp org-agenda-show-log) " LogAll")
  6872. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6873. (org-agenda-show-log " Log")
  6874. (t ""))
  6875. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6876. :preset-filter))
  6877. '(:eval (org-propertize
  6878. (concat " <"
  6879. (mapconcat
  6880. 'identity
  6881. (append
  6882. (get 'org-agenda-category-filter :preset-filter)
  6883. org-agenda-category-filter)
  6884. "")
  6885. ">")
  6886. 'face 'org-agenda-filter-category
  6887. 'help-echo "Category used in filtering"))
  6888. "")
  6889. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6890. :preset-filter))
  6891. '(:eval (org-propertize
  6892. (concat " {"
  6893. (mapconcat
  6894. 'identity
  6895. (append
  6896. (get 'org-agenda-tag-filter :preset-filter)
  6897. org-agenda-tag-filter)
  6898. "")
  6899. "}")
  6900. 'face 'org-agenda-filter-tags
  6901. 'help-echo "Tags used in filtering"))
  6902. "")
  6903. (if org-agenda-archives-mode
  6904. (if (eq org-agenda-archives-mode t)
  6905. " Archives"
  6906. (format " :%s:" org-archive-tag))
  6907. "")
  6908. (if org-agenda-clockreport-mode
  6909. (if (eq org-agenda-clockreport-mode 'with-filter)
  6910. " Clock{}" " Clock")
  6911. "")))
  6912. (force-mode-line-update))
  6913. (defun org-agenda-post-command-hook ()
  6914. (setq org-agenda-type
  6915. (or (get-text-property (point) 'org-agenda-type)
  6916. (get-text-property (max (point-min) (1- (point)))
  6917. 'org-agenda-type))))
  6918. (defun org-agenda-next-line ()
  6919. "Move cursor to the next line, and show if follow mode is active."
  6920. (interactive)
  6921. (call-interactively 'next-line)
  6922. (org-agenda-do-context-action))
  6923. (defun org-agenda-previous-line ()
  6924. "Move cursor to the previous line, and show if follow-mode is active."
  6925. (interactive)
  6926. (call-interactively 'previous-line)
  6927. (org-agenda-do-context-action))
  6928. (defun org-agenda-next-item (n)
  6929. "Move cursor to next agenda item."
  6930. (interactive "p")
  6931. (let ((col (current-column)))
  6932. (dotimes (c n)
  6933. (when (next-single-property-change (point-at-eol) 'org-marker)
  6934. (move-end-of-line 1)
  6935. (goto-char (next-single-property-change (point) 'org-marker))))
  6936. (org-move-to-column col))
  6937. (org-agenda-do-context-action))
  6938. (defun org-agenda-previous-item (n)
  6939. "Move cursor to next agenda item."
  6940. (interactive "p")
  6941. (dotimes (c n)
  6942. (let ((col (current-column))
  6943. (goto (save-excursion
  6944. (move-end-of-line 0)
  6945. (previous-single-property-change (point) 'org-marker))))
  6946. (if goto (goto-char goto))
  6947. (org-move-to-column col)))
  6948. (org-agenda-do-context-action))
  6949. (defun org-agenda-do-context-action ()
  6950. "Show outline path and, maybe, follow mode window."
  6951. (let ((m (org-get-at-bol 'org-marker)))
  6952. (when (and (markerp m) (marker-buffer m))
  6953. (and org-agenda-follow-mode
  6954. (if org-agenda-follow-indirect
  6955. (org-agenda-tree-to-indirect-buffer)
  6956. (org-agenda-show)))
  6957. (and org-agenda-show-outline-path
  6958. (org-with-point-at m (org-display-outline-path t))))))
  6959. (defun org-agenda-show-priority ()
  6960. "Show the priority of the current item.
  6961. This priority is composed of the main priority given with the [#A] cookies,
  6962. and by additional input from the age of a schedules or deadline entry."
  6963. (interactive)
  6964. (let* ((pri (org-get-at-bol 'priority)))
  6965. (message "Priority is %d" (if pri pri -1000))))
  6966. (defun org-agenda-show-tags ()
  6967. "Show the tags applicable to the current item."
  6968. (interactive)
  6969. (let* ((tags (org-get-at-bol 'tags)))
  6970. (if tags
  6971. (message "Tags are :%s:"
  6972. (org-no-properties (mapconcat 'identity tags ":")))
  6973. (message "No tags associated with this line"))))
  6974. (defun org-agenda-goto (&optional highlight)
  6975. "Go to the Org-mode file which contains the item at point."
  6976. (interactive)
  6977. (let* ((marker (or (org-get-at-bol 'org-marker)
  6978. (org-agenda-error)))
  6979. (buffer (marker-buffer marker))
  6980. (pos (marker-position marker)))
  6981. (switch-to-buffer-other-window buffer)
  6982. (widen)
  6983. (push-mark)
  6984. (goto-char pos)
  6985. (when (derived-mode-p 'org-mode)
  6986. (org-show-context 'agenda)
  6987. (save-excursion
  6988. (and (outline-next-heading)
  6989. (org-flag-heading nil)))) ; show the next heading
  6990. (when (outline-invisible-p)
  6991. (show-entry)) ; display invisible text
  6992. (recenter (/ (window-height) 2))
  6993. (run-hooks 'org-agenda-after-show-hook)
  6994. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6995. (defvar org-agenda-after-show-hook nil
  6996. "Normal hook run after an item has been shown from the agenda.
  6997. Point is in the buffer where the item originated.")
  6998. (defun org-agenda-kill ()
  6999. "Kill the entry or subtree belonging to the current agenda entry."
  7000. (interactive)
  7001. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7002. (let* ((bufname-orig (buffer-name))
  7003. (marker (or (org-get-at-bol 'org-marker)
  7004. (org-agenda-error)))
  7005. (buffer (marker-buffer marker))
  7006. (pos (marker-position marker))
  7007. (type (org-get-at-bol 'type))
  7008. dbeg dend (n 0) conf)
  7009. (org-with-remote-undo buffer
  7010. (with-current-buffer buffer
  7011. (save-excursion
  7012. (goto-char pos)
  7013. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7014. (setq dbeg (progn (org-back-to-heading t) (point))
  7015. dend (org-end-of-subtree t t))
  7016. (setq dbeg (point-at-bol)
  7017. dend (min (point-max) (1+ (point-at-eol)))))
  7018. (goto-char dbeg)
  7019. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7020. (setq conf (or (eq t org-agenda-confirm-kill)
  7021. (and (numberp org-agenda-confirm-kill)
  7022. (> n org-agenda-confirm-kill))))
  7023. (and conf
  7024. (not (y-or-n-p
  7025. (format "Delete entry with %d lines in buffer \"%s\"? "
  7026. n (buffer-name buffer))))
  7027. (error "Abort"))
  7028. (let ((org-agenda-buffer-name bufname-orig))
  7029. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7030. (with-current-buffer buffer (delete-region dbeg dend))
  7031. (message "Agenda item and source killed"))))
  7032. (defvar org-archive-default-command) ; defined in org-archive.el
  7033. (defun org-agenda-archive-default ()
  7034. "Archive the entry or subtree belonging to the current agenda entry."
  7035. (interactive)
  7036. (require 'org-archive)
  7037. (org-agenda-archive-with org-archive-default-command))
  7038. (defun org-agenda-archive-default-with-confirmation ()
  7039. "Archive the entry or subtree belonging to the current agenda entry."
  7040. (interactive)
  7041. (require 'org-archive)
  7042. (org-agenda-archive-with org-archive-default-command 'confirm))
  7043. (defun org-agenda-archive ()
  7044. "Archive the entry or subtree belonging to the current agenda entry."
  7045. (interactive)
  7046. (org-agenda-archive-with 'org-archive-subtree))
  7047. (defun org-agenda-archive-to-archive-sibling ()
  7048. "Move the entry to the archive sibling."
  7049. (interactive)
  7050. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7051. (defun org-agenda-archive-with (cmd &optional confirm)
  7052. "Move the entry to the archive sibling."
  7053. (interactive)
  7054. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7055. (let* ((bufname-orig (buffer-name))
  7056. (marker (or (org-get-at-bol 'org-marker)
  7057. (org-agenda-error)))
  7058. (buffer (marker-buffer marker))
  7059. (pos (marker-position marker)))
  7060. (org-with-remote-undo buffer
  7061. (with-current-buffer buffer
  7062. (if (derived-mode-p 'org-mode)
  7063. (if (and confirm
  7064. (not (y-or-n-p "Archive this subtree or entry? ")))
  7065. (error "Abort")
  7066. (save-excursion
  7067. (goto-char pos)
  7068. (let ((org-agenda-buffer-name bufname-orig))
  7069. (org-remove-subtree-entries-from-agenda))
  7070. (org-back-to-heading t)
  7071. (funcall cmd)))
  7072. (error "Archiving works only in Org-mode files"))))))
  7073. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7074. "Remove all lines in the agenda that correspond to a given subtree.
  7075. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7076. If this information is not given, the function uses the tree at point."
  7077. (let ((buf (or buf (current-buffer))) m p)
  7078. (save-excursion
  7079. (unless (and beg end)
  7080. (org-back-to-heading t)
  7081. (setq beg (point))
  7082. (org-end-of-subtree t)
  7083. (setq end (point)))
  7084. (set-buffer (get-buffer org-agenda-buffer-name))
  7085. (save-excursion
  7086. (goto-char (point-max))
  7087. (beginning-of-line 1)
  7088. (while (not (bobp))
  7089. (when (and (setq m (org-get-at-bol 'org-marker))
  7090. (equal buf (marker-buffer m))
  7091. (setq p (marker-position m))
  7092. (>= p beg)
  7093. (< p end))
  7094. (let ((inhibit-read-only t))
  7095. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7096. (beginning-of-line 0))))))
  7097. (defun org-agenda-refile (&optional goto rfloc no-update)
  7098. "Refile the item at point."
  7099. (interactive "P")
  7100. (if (equal goto '(16))
  7101. (org-refile-goto-last-stored)
  7102. (let* ((buffer-orig (buffer-name))
  7103. (marker (or (org-get-at-bol 'org-hd-marker)
  7104. (org-agenda-error)))
  7105. (buffer (marker-buffer marker))
  7106. (pos (marker-position marker))
  7107. (rfloc (or rfloc
  7108. (org-refile-get-location
  7109. (if goto "Goto" "Refile to") buffer
  7110. org-refile-allow-creating-parent-nodes))))
  7111. (with-current-buffer buffer
  7112. (save-excursion
  7113. (save-restriction
  7114. (widen)
  7115. (goto-char marker)
  7116. (let ((org-agenda-buffer-name buffer-orig))
  7117. (org-remove-subtree-entries-from-agenda))
  7118. (org-refile goto buffer rfloc)))))
  7119. (unless no-update (org-agenda-redo))))
  7120. (defun org-agenda-open-link (&optional arg)
  7121. "Follow the link in the current line, if any.
  7122. This looks for a link in the displayed line in the agenda. It also looks
  7123. at the text of the entry itself."
  7124. (interactive "P")
  7125. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7126. (org-get-at-bol 'org-marker)))
  7127. (buffer (and marker (marker-buffer marker)))
  7128. (prefix (buffer-substring
  7129. (point-at-bol) (point-at-eol))))
  7130. (cond
  7131. (buffer
  7132. (with-current-buffer buffer
  7133. (save-excursion
  7134. (save-restriction
  7135. (widen)
  7136. (goto-char marker)
  7137. (org-offer-links-in-entry arg prefix)))))
  7138. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7139. (save-excursion
  7140. (beginning-of-line 1)
  7141. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7142. (org-open-link-from-string (match-string 1)))
  7143. (t (error "No link to open here")))))
  7144. (defun org-agenda-copy-local-variable (var)
  7145. "Get a variable from a referenced buffer and install it here."
  7146. (let ((m (org-get-at-bol 'org-marker)))
  7147. (when (and m (buffer-live-p (marker-buffer m)))
  7148. (org-set-local var (with-current-buffer (marker-buffer m)
  7149. (symbol-value var))))))
  7150. (defun org-agenda-switch-to (&optional delete-other-windows)
  7151. "Go to the Org-mode file which contains the item at point."
  7152. (interactive)
  7153. (if (and org-return-follows-link
  7154. (not (org-get-at-bol 'org-marker))
  7155. (org-in-regexp org-bracket-link-regexp))
  7156. (org-open-link-from-string (match-string 0))
  7157. (let* ((marker (or (org-get-at-bol 'org-marker)
  7158. (org-agenda-error)))
  7159. (buffer (marker-buffer marker))
  7160. (pos (marker-position marker)))
  7161. (org-pop-to-buffer-same-window buffer)
  7162. (and delete-other-windows (delete-other-windows))
  7163. (widen)
  7164. (goto-char pos)
  7165. (when (derived-mode-p 'org-mode)
  7166. (org-show-context 'agenda)
  7167. (save-excursion
  7168. (and (outline-next-heading)
  7169. (org-flag-heading nil))) ; show the next heading
  7170. (when (outline-invisible-p)
  7171. (show-entry)) ; display invisible text
  7172. (run-hooks 'org-agenda-after-show-hook)))))
  7173. (defun org-agenda-goto-mouse (ev)
  7174. "Go to the Org-mode file which contains the item at the mouse click."
  7175. (interactive "e")
  7176. (mouse-set-point ev)
  7177. (org-agenda-goto))
  7178. (defun org-agenda-show (&optional full-entry)
  7179. "Display the Org-mode file which contains the item at point.
  7180. With prefix argument FULL-ENTRY, make the entire entry visible
  7181. if it was hidden in the outline."
  7182. (interactive "P")
  7183. (let ((win (selected-window)))
  7184. (if full-entry
  7185. (let ((org-show-entry-below t))
  7186. (org-agenda-goto t))
  7187. (org-agenda-goto t))
  7188. (select-window win)))
  7189. (defvar org-agenda-show-window nil)
  7190. (defun org-agenda-show-and-scroll-up (&optional arg)
  7191. "Display the Org-mode file which contains the item at point.
  7192. When called repeatedly, scroll the window that is displaying the buffer.
  7193. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7194. `show-subtree' to display the item, so that drawers and logbooks stay
  7195. folded."
  7196. (interactive "P")
  7197. (let ((win (selected-window)))
  7198. (if (and (window-live-p org-agenda-show-window)
  7199. (eq this-command last-command))
  7200. (progn
  7201. (select-window org-agenda-show-window)
  7202. (ignore-errors (scroll-up)))
  7203. (org-agenda-goto t)
  7204. (if arg (org-show-entry) (show-subtree))
  7205. (setq org-agenda-show-window (selected-window)))
  7206. (select-window win)))
  7207. (defun org-agenda-show-scroll-down ()
  7208. "Scroll down the window showing the agenda."
  7209. (interactive)
  7210. (let ((win (selected-window)))
  7211. (when (window-live-p org-agenda-show-window)
  7212. (select-window org-agenda-show-window)
  7213. (ignore-errors (scroll-down))
  7214. (select-window win))))
  7215. (defun org-agenda-show-1 (&optional more)
  7216. "Display the Org-mode file which contains the item at point.
  7217. The prefix arg selects the amount of information to display:
  7218. 0 hide the subtree
  7219. 1 just show the entry according to defaults.
  7220. 2 show the children view
  7221. 3 show the subtree view
  7222. 4 show the entire subtree and any LOGBOOK drawers
  7223. 5 show the entire subtree and any drawers
  7224. With prefix argument FULL-ENTRY, make the entire entry visible
  7225. if it was hidden in the outline."
  7226. (interactive "p")
  7227. (let ((win (selected-window)))
  7228. (org-agenda-goto t)
  7229. (org-recenter-heading 1)
  7230. (cond
  7231. ((= more 0)
  7232. (hide-subtree)
  7233. (save-excursion
  7234. (org-back-to-heading)
  7235. (run-hook-with-args 'org-cycle-hook 'folded))
  7236. (message "Remote: FOLDED"))
  7237. ((and (org-called-interactively-p 'any) (= more 1))
  7238. (message "Remote: show with default settings"))
  7239. ((= more 2)
  7240. (show-entry)
  7241. (show-children)
  7242. (save-excursion
  7243. (org-back-to-heading)
  7244. (run-hook-with-args 'org-cycle-hook 'children))
  7245. (message "Remote: CHILDREN"))
  7246. ((= more 3)
  7247. (show-subtree)
  7248. (save-excursion
  7249. (org-back-to-heading)
  7250. (run-hook-with-args 'org-cycle-hook 'subtree))
  7251. (message "Remote: SUBTREE"))
  7252. ((= more 4)
  7253. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7254. (org-drawer-regexp
  7255. (concat "^[ \t]*:\\("
  7256. (mapconcat 'regexp-quote org-drawers "\\|")
  7257. "\\):[ \t]*$")))
  7258. (show-subtree)
  7259. (save-excursion
  7260. (org-back-to-heading)
  7261. (org-cycle-hide-drawers 'subtree)))
  7262. (message "Remote: SUBTREE AND LOGBOOK"))
  7263. ((> more 4)
  7264. (show-subtree)
  7265. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7266. (select-window win)))
  7267. (defun org-recenter-heading (n)
  7268. (save-excursion
  7269. (org-back-to-heading)
  7270. (recenter n)))
  7271. (defvar org-agenda-cycle-counter nil)
  7272. (defun org-agenda-cycle-show (&optional n)
  7273. "Show the current entry in another window, with default settings.
  7274. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7275. When use repeatedly in immediate succession, the remote entry will cycle
  7276. through visibility
  7277. children -> subtree -> folded
  7278. When called with a numeric prefix arg, that arg will be passed through to
  7279. `org-agenda-show-1'. For the interpretation of that argument, see the
  7280. docstring of `org-agenda-show-1'."
  7281. (interactive "P")
  7282. (if (integerp n)
  7283. (setq org-agenda-cycle-counter n)
  7284. (if (not (eq last-command this-command))
  7285. (setq org-agenda-cycle-counter 1)
  7286. (if (equal org-agenda-cycle-counter 0)
  7287. (setq org-agenda-cycle-counter 2)
  7288. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7289. (if (> org-agenda-cycle-counter 3)
  7290. (setq org-agenda-cycle-counter 0)))))
  7291. (org-agenda-show-1 org-agenda-cycle-counter))
  7292. (defun org-agenda-recenter (arg)
  7293. "Display the Org-mode file which contains the item at point and recenter."
  7294. (interactive "P")
  7295. (let ((win (selected-window)))
  7296. (org-agenda-goto t)
  7297. (recenter arg)
  7298. (select-window win)))
  7299. (defun org-agenda-show-mouse (ev)
  7300. "Display the Org-mode file which contains the item at the mouse click."
  7301. (interactive "e")
  7302. (mouse-set-point ev)
  7303. (org-agenda-show))
  7304. (defun org-agenda-check-no-diary ()
  7305. "Check if the entry is a diary link and abort if yes."
  7306. (if (org-get-at-bol 'org-agenda-diary-link)
  7307. (org-agenda-error)))
  7308. (defun org-agenda-error ()
  7309. (error "Command not allowed in this line"))
  7310. (defun org-agenda-tree-to-indirect-buffer ()
  7311. "Show the subtree corresponding to the current entry in an indirect buffer.
  7312. This calls the command `org-tree-to-indirect-buffer' from the original
  7313. Org-mode buffer.
  7314. With numerical prefix arg ARG, go up to this level and then take that tree.
  7315. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7316. use the dedicated frame)."
  7317. (interactive)
  7318. (if (and current-prefix-arg (listp current-prefix-arg))
  7319. (org-agenda-do-tree-to-indirect-buffer)
  7320. (let ((agenda-window (selected-window))
  7321. (indirect-window
  7322. (and org-last-indirect-buffer
  7323. (get-buffer-window org-last-indirect-buffer))))
  7324. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7325. (unwind-protect
  7326. (progn
  7327. (unless (and indirect-window (window-live-p indirect-window))
  7328. (setq indirect-window (split-window agenda-window)))
  7329. (select-window indirect-window)
  7330. (switch-to-buffer org-last-indirect-buffer :norecord)
  7331. (fit-window-to-buffer indirect-window))
  7332. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7333. (defun org-agenda-do-tree-to-indirect-buffer ()
  7334. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7335. (org-agenda-check-no-diary)
  7336. (let* ((marker (or (org-get-at-bol 'org-marker)
  7337. (org-agenda-error)))
  7338. (buffer (marker-buffer marker))
  7339. (pos (marker-position marker)))
  7340. (with-current-buffer buffer
  7341. (save-excursion
  7342. (goto-char pos)
  7343. (call-interactively 'org-tree-to-indirect-buffer)))))
  7344. (defvar org-last-heading-marker (make-marker)
  7345. "Marker pointing to the headline that last changed its TODO state
  7346. by a remote command from the agenda.")
  7347. (defun org-agenda-todo-nextset ()
  7348. "Switch TODO entry to next sequence."
  7349. (interactive)
  7350. (org-agenda-todo 'nextset))
  7351. (defun org-agenda-todo-previousset ()
  7352. "Switch TODO entry to previous sequence."
  7353. (interactive)
  7354. (org-agenda-todo 'previousset))
  7355. (defun org-agenda-todo (&optional arg)
  7356. "Cycle TODO state of line at point, also in Org-mode file.
  7357. This changes the line at point, all other lines in the agenda referring to
  7358. the same tree node, and the headline of the tree node in the Org-mode file."
  7359. (interactive "P")
  7360. (org-agenda-check-no-diary)
  7361. (let* ((col (current-column))
  7362. (marker (or (org-get-at-bol 'org-marker)
  7363. (org-agenda-error)))
  7364. (buffer (marker-buffer marker))
  7365. (pos (marker-position marker))
  7366. (hdmarker (org-get-at-bol 'org-hd-marker))
  7367. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7368. (inhibit-read-only t)
  7369. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7370. (org-with-remote-undo buffer
  7371. (with-current-buffer buffer
  7372. (widen)
  7373. (goto-char pos)
  7374. (org-show-context 'agenda)
  7375. (save-excursion
  7376. (and (outline-next-heading)
  7377. (org-flag-heading nil))) ; show the next heading
  7378. (let ((current-prefix-arg arg))
  7379. (call-interactively 'org-todo))
  7380. (and (bolp) (forward-char 1))
  7381. (setq newhead (org-get-heading))
  7382. (when (and (org-bound-and-true-p
  7383. org-agenda-headline-snapshot-before-repeat)
  7384. (not (equal org-agenda-headline-snapshot-before-repeat
  7385. newhead))
  7386. todayp)
  7387. (setq newhead org-agenda-headline-snapshot-before-repeat
  7388. just-one t))
  7389. (save-excursion
  7390. (org-back-to-heading)
  7391. (move-marker org-last-heading-marker (point))))
  7392. (beginning-of-line 1)
  7393. (save-excursion
  7394. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7395. (org-move-to-column col))))
  7396. (defun org-agenda-add-note (&optional arg)
  7397. "Add a time-stamped note to the entry at point."
  7398. (interactive "P")
  7399. (org-agenda-check-no-diary)
  7400. (let* ((marker (or (org-get-at-bol 'org-marker)
  7401. (org-agenda-error)))
  7402. (buffer (marker-buffer marker))
  7403. (pos (marker-position marker))
  7404. (hdmarker (org-get-at-bol 'org-hd-marker))
  7405. (inhibit-read-only t))
  7406. (with-current-buffer buffer
  7407. (widen)
  7408. (goto-char pos)
  7409. (org-show-context 'agenda)
  7410. (save-excursion
  7411. (and (outline-next-heading)
  7412. (org-flag-heading nil))) ; show the next heading
  7413. (org-add-note))))
  7414. (defun org-agenda-change-all-lines (newhead hdmarker
  7415. &optional fixface just-this)
  7416. "Change all lines in the agenda buffer which match HDMARKER.
  7417. The new content of the line will be NEWHEAD (as modified by
  7418. `org-agenda-format-item'). HDMARKER is checked with
  7419. `equal' against all `org-hd-marker' text properties in the file.
  7420. If FIXFACE is non-nil, the face of each item is modified according to
  7421. the new TODO state.
  7422. If JUST-THIS is non-nil, change just the current line, not all.
  7423. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7424. (let* ((inhibit-read-only t)
  7425. (line (org-current-line))
  7426. (org-agenda-buffer (current-buffer))
  7427. (thetags (with-current-buffer (marker-buffer hdmarker)
  7428. (save-excursion (save-restriction (widen)
  7429. (goto-char hdmarker)
  7430. (org-get-tags-at)))))
  7431. props m pl undone-face done-face finish new dotime cat tags)
  7432. (save-excursion
  7433. (goto-char (point-max))
  7434. (beginning-of-line 1)
  7435. (while (not finish)
  7436. (setq finish (bobp))
  7437. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7438. (or (not just-this) (= (org-current-line) line))
  7439. (equal m hdmarker))
  7440. (setq props (text-properties-at (point))
  7441. dotime (org-get-at-bol 'dotime)
  7442. cat (org-get-at-bol 'org-category)
  7443. tags thetags
  7444. new
  7445. (let ((org-prefix-format-compiled
  7446. (or (get-text-property (point) 'format)
  7447. org-prefix-format-compiled))
  7448. (extra (org-get-at-bol 'extra)))
  7449. (with-current-buffer (marker-buffer hdmarker)
  7450. (save-excursion
  7451. (save-restriction
  7452. (widen)
  7453. (org-agenda-format-item extra newhead cat tags dotime)))))
  7454. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7455. undone-face (org-get-at-bol 'undone-face)
  7456. done-face (org-get-at-bol 'done-face))
  7457. (beginning-of-line 1)
  7458. (cond
  7459. ((equal new "")
  7460. (and (looking-at ".*\n?") (replace-match "")))
  7461. ((looking-at ".*")
  7462. (replace-match new t t)
  7463. (beginning-of-line 1)
  7464. (add-text-properties (point-at-bol) (point-at-eol) props)
  7465. (when fixface
  7466. (add-text-properties
  7467. (point-at-bol) (point-at-eol)
  7468. (list 'face
  7469. (if org-last-todo-state-is-todo
  7470. undone-face done-face))))
  7471. (org-agenda-highlight-todo 'line)
  7472. (beginning-of-line 1))
  7473. (t (error "Line update did not work"))))
  7474. (beginning-of-line 0)))
  7475. (org-agenda-finalize)))
  7476. (defun org-agenda-align-tags (&optional line)
  7477. "Align all tags in agenda items to `org-agenda-tags-column'."
  7478. (let ((inhibit-read-only t) l c)
  7479. (save-excursion
  7480. (goto-char (if line (point-at-bol) (point-min)))
  7481. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7482. (if line (point-at-eol) nil) t)
  7483. (add-text-properties
  7484. (match-beginning 2) (match-end 2)
  7485. (list 'face (delq nil (let ((prop (get-text-property
  7486. (match-beginning 2) 'face)))
  7487. (or (listp prop) (setq prop (list prop)))
  7488. (if (memq 'org-tag prop)
  7489. prop
  7490. (cons 'org-tag prop))))))
  7491. (setq l (- (match-end 2) (match-beginning 2))
  7492. c (if (< org-agenda-tags-column 0)
  7493. (- (abs org-agenda-tags-column) l)
  7494. org-agenda-tags-column))
  7495. (delete-region (match-beginning 1) (match-end 1))
  7496. (goto-char (match-beginning 1))
  7497. (insert (org-add-props
  7498. (make-string (max 1 (- c (current-column))) ?\ )
  7499. (plist-put (copy-sequence (text-properties-at (point)))
  7500. 'face nil))))
  7501. (goto-char (point-min))
  7502. (org-font-lock-add-tag-faces (point-max)))))
  7503. (defun org-agenda-priority-up ()
  7504. "Increase the priority of line at point, also in Org-mode file."
  7505. (interactive)
  7506. (org-agenda-priority 'up))
  7507. (defun org-agenda-priority-down ()
  7508. "Decrease the priority of line at point, also in Org-mode file."
  7509. (interactive)
  7510. (org-agenda-priority 'down))
  7511. (defun org-agenda-priority (&optional force-direction)
  7512. "Set the priority of line at point, also in Org-mode file.
  7513. This changes the line at point, all other lines in the agenda referring to
  7514. the same tree node, and the headline of the tree node in the Org-mode file."
  7515. (interactive)
  7516. (unless org-enable-priority-commands
  7517. (error "Priority commands are disabled"))
  7518. (org-agenda-check-no-diary)
  7519. (let* ((marker (or (org-get-at-bol 'org-marker)
  7520. (org-agenda-error)))
  7521. (hdmarker (org-get-at-bol 'org-hd-marker))
  7522. (buffer (marker-buffer hdmarker))
  7523. (pos (marker-position hdmarker))
  7524. (inhibit-read-only t)
  7525. newhead)
  7526. (org-with-remote-undo buffer
  7527. (with-current-buffer buffer
  7528. (widen)
  7529. (goto-char pos)
  7530. (org-show-context 'agenda)
  7531. (save-excursion
  7532. (and (outline-next-heading)
  7533. (org-flag-heading nil))) ; show the next heading
  7534. (funcall 'org-priority force-direction)
  7535. (end-of-line 1)
  7536. (setq newhead (org-get-heading)))
  7537. (org-agenda-change-all-lines newhead hdmarker)
  7538. (beginning-of-line 1))))
  7539. ;; FIXME: should fix the tags property of the agenda line.
  7540. (defun org-agenda-set-tags (&optional tag onoff)
  7541. "Set tags for the current headline."
  7542. (interactive)
  7543. (org-agenda-check-no-diary)
  7544. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7545. (call-interactively 'org-change-tag-in-region)
  7546. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7547. (org-agenda-error)))
  7548. (buffer (marker-buffer hdmarker))
  7549. (pos (marker-position hdmarker))
  7550. (inhibit-read-only t)
  7551. newhead)
  7552. (org-with-remote-undo buffer
  7553. (with-current-buffer buffer
  7554. (widen)
  7555. (goto-char pos)
  7556. (save-excursion
  7557. (org-show-context 'agenda))
  7558. (save-excursion
  7559. (and (outline-next-heading)
  7560. (org-flag-heading nil))) ; show the next heading
  7561. (goto-char pos)
  7562. (if tag
  7563. (org-toggle-tag tag onoff)
  7564. (call-interactively 'org-set-tags))
  7565. (end-of-line 1)
  7566. (setq newhead (org-get-heading)))
  7567. (org-agenda-change-all-lines newhead hdmarker)
  7568. (beginning-of-line 1)))))
  7569. (defun org-agenda-set-property ()
  7570. "Set a property for the current headline."
  7571. (interactive)
  7572. (org-agenda-check-no-diary)
  7573. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7574. (org-agenda-error)))
  7575. (buffer (marker-buffer hdmarker))
  7576. (pos (marker-position hdmarker))
  7577. (inhibit-read-only t)
  7578. newhead)
  7579. (org-with-remote-undo buffer
  7580. (with-current-buffer buffer
  7581. (widen)
  7582. (goto-char pos)
  7583. (save-excursion
  7584. (org-show-context 'agenda))
  7585. (save-excursion
  7586. (and (outline-next-heading)
  7587. (org-flag-heading nil))) ; show the next heading
  7588. (goto-char pos)
  7589. (call-interactively 'org-set-property)))))
  7590. (defun org-agenda-set-effort ()
  7591. "Set the effort property for the current headline."
  7592. (interactive)
  7593. (org-agenda-check-no-diary)
  7594. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7595. (org-agenda-error)))
  7596. (buffer (marker-buffer hdmarker))
  7597. (pos (marker-position hdmarker))
  7598. (inhibit-read-only t)
  7599. newhead)
  7600. (org-with-remote-undo buffer
  7601. (with-current-buffer buffer
  7602. (widen)
  7603. (goto-char pos)
  7604. (save-excursion
  7605. (org-show-context 'agenda))
  7606. (save-excursion
  7607. (and (outline-next-heading)
  7608. (org-flag-heading nil))) ; show the next heading
  7609. (goto-char pos)
  7610. (call-interactively 'org-set-effort)
  7611. (end-of-line 1)
  7612. (setq newhead (org-get-heading)))
  7613. (org-agenda-change-all-lines newhead hdmarker))))
  7614. (defun org-agenda-toggle-archive-tag ()
  7615. "Toggle the archive tag for the current entry."
  7616. (interactive)
  7617. (org-agenda-check-no-diary)
  7618. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7619. (org-agenda-error)))
  7620. (buffer (marker-buffer hdmarker))
  7621. (pos (marker-position hdmarker))
  7622. (inhibit-read-only t)
  7623. newhead)
  7624. (org-with-remote-undo buffer
  7625. (with-current-buffer buffer
  7626. (widen)
  7627. (goto-char pos)
  7628. (org-show-context 'agenda)
  7629. (save-excursion
  7630. (and (outline-next-heading)
  7631. (org-flag-heading nil))) ; show the next heading
  7632. (call-interactively 'org-toggle-archive-tag)
  7633. (end-of-line 1)
  7634. (setq newhead (org-get-heading)))
  7635. (org-agenda-change-all-lines newhead hdmarker)
  7636. (beginning-of-line 1))))
  7637. (defun org-agenda-do-date-later (arg)
  7638. (interactive "P")
  7639. (cond
  7640. ((or (equal arg '(16))
  7641. (memq last-command
  7642. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7643. (setq this-command 'org-agenda-date-later-minutes)
  7644. (org-agenda-date-later-minutes 1))
  7645. ((or (equal arg '(4))
  7646. (memq last-command
  7647. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7648. (setq this-command 'org-agenda-date-later-hours)
  7649. (org-agenda-date-later-hours 1))
  7650. (t
  7651. (org-agenda-date-later (prefix-numeric-value arg)))))
  7652. (defun org-agenda-do-date-earlier (arg)
  7653. (interactive "P")
  7654. (cond
  7655. ((or (equal arg '(16))
  7656. (memq last-command
  7657. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7658. (setq this-command 'org-agenda-date-earlier-minutes)
  7659. (org-agenda-date-earlier-minutes 1))
  7660. ((or (equal arg '(4))
  7661. (memq last-command
  7662. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7663. (setq this-command 'org-agenda-date-earlier-hours)
  7664. (org-agenda-date-earlier-hours 1))
  7665. (t
  7666. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7667. (defun org-agenda-date-later (arg &optional what)
  7668. "Change the date of this item to ARG day(s) later."
  7669. (interactive "p")
  7670. (org-agenda-check-type t 'agenda 'timeline)
  7671. (org-agenda-check-no-diary)
  7672. (let* ((marker (or (org-get-at-bol 'org-marker)
  7673. (org-agenda-error)))
  7674. (buffer (marker-buffer marker))
  7675. (pos (marker-position marker))
  7676. cdate today)
  7677. (org-with-remote-undo buffer
  7678. (with-current-buffer buffer
  7679. (widen)
  7680. (goto-char pos)
  7681. (if (not (org-at-timestamp-p))
  7682. (error "Cannot find time stamp"))
  7683. (when (and org-agenda-move-date-from-past-immediately-to-today
  7684. (equal arg 1)
  7685. (or (not what) (eq what 'day))
  7686. (not (save-match-data (org-at-date-range-p))))
  7687. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7688. cdate (calendar-absolute-from-gregorian
  7689. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7690. today (org-today))
  7691. (if (> today cdate)
  7692. ;; immediately shift to today
  7693. (setq arg (- today cdate))))
  7694. (org-timestamp-change arg (or what 'day))
  7695. (when (and (org-at-date-range-p)
  7696. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7697. (let ((end org-last-changed-timestamp))
  7698. (org-timestamp-change arg (or what 'day))
  7699. (setq org-last-changed-timestamp
  7700. (concat org-last-changed-timestamp "--" end)))))
  7701. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7702. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7703. (defun org-agenda-date-earlier (arg &optional what)
  7704. "Change the date of this item to ARG day(s) earlier."
  7705. (interactive "p")
  7706. (org-agenda-date-later (- arg) what))
  7707. (defun org-agenda-date-later-minutes (arg)
  7708. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7709. (interactive "p")
  7710. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7711. (org-agenda-date-later arg 'minute))
  7712. (defun org-agenda-date-earlier-minutes (arg)
  7713. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7714. (interactive "p")
  7715. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7716. (org-agenda-date-earlier arg 'minute))
  7717. (defun org-agenda-date-later-hours (arg)
  7718. "Change the time of this item, in hour steps."
  7719. (interactive "p")
  7720. (org-agenda-date-later arg 'hour))
  7721. (defun org-agenda-date-earlier-hours (arg)
  7722. "Change the time of this item, in hour steps."
  7723. (interactive "p")
  7724. (org-agenda-date-earlier arg 'hour))
  7725. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7726. "Show new date stamp via text properties."
  7727. ;; We use text properties to make this undoable
  7728. (let ((inhibit-read-only t)
  7729. (buffer-invisibility-spec))
  7730. (setq stamp (concat " " prefix " => " stamp))
  7731. (save-excursion
  7732. (goto-char (point-max))
  7733. (while (not (bobp))
  7734. (when (equal marker (org-get-at-bol 'org-marker))
  7735. (org-move-to-column (- (window-width) (length stamp)) t)
  7736. (org-agenda-fix-tags-filter-overlays-at (point))
  7737. (if (featurep 'xemacs)
  7738. ;; Use `duplicable' property to trigger undo recording
  7739. (let ((ex (make-extent nil nil))
  7740. (gl (make-glyph stamp)))
  7741. (set-glyph-face gl 'secondary-selection)
  7742. (set-extent-properties
  7743. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7744. (insert-extent ex (1- (point)) (point-at-eol)))
  7745. (add-text-properties
  7746. (1- (point)) (point-at-eol)
  7747. (list 'display (org-add-props stamp nil
  7748. 'face 'secondary-selection))))
  7749. (beginning-of-line 1))
  7750. (beginning-of-line 0)))))
  7751. (defun org-agenda-date-prompt (arg)
  7752. "Change the date of this item. Date is prompted for, with default today.
  7753. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7754. be used to request time specification in the time stamp."
  7755. (interactive "P")
  7756. (org-agenda-check-type t 'agenda 'timeline)
  7757. (org-agenda-check-no-diary)
  7758. (let* ((marker (or (org-get-at-bol 'org-marker)
  7759. (org-agenda-error)))
  7760. (buffer (marker-buffer marker))
  7761. (pos (marker-position marker)))
  7762. (org-with-remote-undo buffer
  7763. (with-current-buffer buffer
  7764. (widen)
  7765. (goto-char pos)
  7766. (if (not (org-at-timestamp-p t))
  7767. (error "Cannot find time stamp"))
  7768. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7769. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7770. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7771. (defun org-agenda-schedule (arg &optional time)
  7772. "Schedule the item at point.
  7773. ARG is passed through to `org-schedule'."
  7774. (interactive "P")
  7775. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7776. (org-agenda-check-no-diary)
  7777. (let* ((marker (or (org-get-at-bol 'org-marker)
  7778. (org-agenda-error)))
  7779. (type (marker-insertion-type marker))
  7780. (buffer (marker-buffer marker))
  7781. (pos (marker-position marker))
  7782. (org-insert-labeled-timestamps-at-point nil)
  7783. ts)
  7784. (set-marker-insertion-type marker t)
  7785. (org-with-remote-undo buffer
  7786. (with-current-buffer buffer
  7787. (widen)
  7788. (goto-char pos)
  7789. (setq ts (org-schedule arg time)))
  7790. (org-agenda-show-new-time marker ts "S"))
  7791. (message "Item scheduled for %s" ts)))
  7792. (defun org-agenda-deadline (arg &optional time)
  7793. "Schedule the item at point.
  7794. ARG is passed through to `org-deadline'."
  7795. (interactive "P")
  7796. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7797. (org-agenda-check-no-diary)
  7798. (let* ((marker (or (org-get-at-bol 'org-marker)
  7799. (org-agenda-error)))
  7800. (buffer (marker-buffer marker))
  7801. (pos (marker-position marker))
  7802. (org-insert-labeled-timestamps-at-point nil)
  7803. ts)
  7804. (org-with-remote-undo buffer
  7805. (with-current-buffer buffer
  7806. (widen)
  7807. (goto-char pos)
  7808. (setq ts (org-deadline arg time)))
  7809. (org-agenda-show-new-time marker ts "D"))
  7810. (message "Deadline for this item set to %s" ts)))
  7811. (defun org-agenda-action ()
  7812. "Select entry for agenda action, or execute an agenda action.
  7813. This command prompts for another letter. Valid inputs are:
  7814. m Mark the entry at point for an agenda action
  7815. s Schedule the marked entry to the date at the cursor
  7816. d Set the deadline of the marked entry to the date at the cursor
  7817. r Call `org-remember' with cursor date as the default date
  7818. c Call `org-capture' with cursor date as the default date
  7819. SPC Show marked entry in other window
  7820. TAB Visit marked entry in other window
  7821. The cursor may be at a date in the calendar, or in the Org agenda."
  7822. (interactive)
  7823. (let (ans)
  7824. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7825. (setq ans (read-char-exclusive))
  7826. (cond
  7827. ((equal ans ?m)
  7828. ;; Mark this entry
  7829. (if (eq major-mode 'org-agenda-mode)
  7830. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7831. (org-get-at-bol 'org-marker))))
  7832. (if m
  7833. (progn
  7834. (move-marker org-agenda-action-marker
  7835. (marker-position m) (marker-buffer m))
  7836. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7837. (error "Don't know which entry to mark")))
  7838. (error "This command works only in the agenda")))
  7839. ((equal ans ?s)
  7840. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7841. ((equal ans ?d)
  7842. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7843. ((equal ans ?r)
  7844. (org-agenda-do-action '(org-remember) t))
  7845. ((equal ans ?c)
  7846. (org-agenda-do-action '(org-capture) t))
  7847. ((equal ans ?\ )
  7848. (let ((cw (selected-window)))
  7849. (org-switch-to-buffer-other-window
  7850. (marker-buffer org-agenda-action-marker))
  7851. (goto-char org-agenda-action-marker)
  7852. (org-show-context 'agenda)
  7853. (select-window cw)))
  7854. ((equal ans ?\C-i)
  7855. (org-switch-to-buffer-other-window
  7856. (marker-buffer org-agenda-action-marker))
  7857. (goto-char org-agenda-action-marker)
  7858. (org-show-context 'agenda))
  7859. (t (error "Invalid agenda action %c" ans)))))
  7860. (defun org-agenda-do-action (form &optional current-buffer)
  7861. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7862. (let ((org-overriding-default-time (org-get-cursor-date)))
  7863. (if current-buffer
  7864. (eval form)
  7865. (if (not (marker-buffer org-agenda-action-marker))
  7866. (error "No entry has been selected for agenda action")
  7867. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7868. (save-excursion
  7869. (save-restriction
  7870. (widen)
  7871. (goto-char org-agenda-action-marker)
  7872. (eval form))))))))
  7873. (defun org-agenda-clock-in (&optional arg)
  7874. "Start the clock on the currently selected item."
  7875. (interactive "P")
  7876. (org-agenda-check-no-diary)
  7877. (if (equal arg '(4))
  7878. (org-clock-in arg)
  7879. (let* ((marker (or (org-get-at-bol 'org-marker)
  7880. (org-agenda-error)))
  7881. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7882. marker))
  7883. (pos (marker-position marker))
  7884. newhead)
  7885. (org-with-remote-undo (marker-buffer marker)
  7886. (with-current-buffer (marker-buffer marker)
  7887. (widen)
  7888. (goto-char pos)
  7889. (org-show-context 'agenda)
  7890. (org-show-entry)
  7891. (org-cycle-hide-drawers 'children)
  7892. (org-clock-in arg)
  7893. (setq newhead (org-get-heading)))
  7894. (org-agenda-change-all-lines newhead hdmarker)))))
  7895. (defun org-agenda-clock-out ()
  7896. "Stop the currently running clock."
  7897. (interactive)
  7898. (unless (marker-buffer org-clock-marker)
  7899. (error "No running clock"))
  7900. (let ((marker (make-marker)) newhead)
  7901. (org-with-remote-undo (marker-buffer org-clock-marker)
  7902. (with-current-buffer (marker-buffer org-clock-marker)
  7903. (save-excursion
  7904. (save-restriction
  7905. (widen)
  7906. (goto-char org-clock-marker)
  7907. (org-back-to-heading t)
  7908. (move-marker marker (point))
  7909. (org-clock-out)
  7910. (setq newhead (org-get-heading))))))
  7911. (org-agenda-change-all-lines newhead marker)
  7912. (move-marker marker nil)))
  7913. (defun org-agenda-clock-cancel (&optional arg)
  7914. "Cancel the currently running clock."
  7915. (interactive "P")
  7916. (unless (marker-buffer org-clock-marker)
  7917. (error "No running clock"))
  7918. (org-with-remote-undo (marker-buffer org-clock-marker)
  7919. (org-clock-cancel)))
  7920. (defun org-agenda-clock-goto ()
  7921. "Jump to the currently clocked in task within the agenda.
  7922. If the currently clocked in task is not listed in the agenda
  7923. buffer, display it in another window."
  7924. (interactive)
  7925. (let (pos)
  7926. (mapc (lambda (o)
  7927. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7928. (setq pos (overlay-start o))))
  7929. (overlays-in (point-min) (point-max)))
  7930. (cond (pos (goto-char pos))
  7931. ;; If the currently clocked entry is not in the agenda
  7932. ;; buffer, we visit it in another window:
  7933. (org-clock-current-task
  7934. (org-switch-to-buffer-other-window (org-clock-goto)))
  7935. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7936. (defun org-agenda-diary-entry-in-org-file ()
  7937. "Make a diary entry in the file `org-agenda-diary-file'."
  7938. (let (d1 d2 char (text "") dp1 dp2)
  7939. (if (equal (buffer-name) "*Calendar*")
  7940. (setq d1 (calendar-cursor-to-date t)
  7941. d2 (car calendar-mark-ring))
  7942. (setq dp1 (get-text-property (point-at-bol) 'day))
  7943. (unless dp1 (error "No date defined in current line"))
  7944. (setq d1 (calendar-gregorian-from-absolute dp1)
  7945. d2 (and (ignore-errors (mark))
  7946. (save-excursion
  7947. (goto-char (mark))
  7948. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7949. (calendar-gregorian-from-absolute dp2))))
  7950. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7951. (setq char (read-char-exclusive))
  7952. (cond
  7953. ((equal char ?d)
  7954. (setq text (read-string "Day entry: "))
  7955. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7956. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7957. ((equal char ?a)
  7958. (setq d1 (list (car d1) (nth 1 d1)
  7959. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7960. (nth 2 d1))))
  7961. (setq text (read-string "Anniversary (use %d to show years): "))
  7962. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7963. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7964. ((equal char ?b)
  7965. (setq text (read-string "Block entry: "))
  7966. (unless (and d1 d2 (not (equal d1 d2)))
  7967. (error "No block of days selected"))
  7968. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7969. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7970. ((equal char ?j)
  7971. (org-switch-to-buffer-other-window
  7972. (find-file-noselect org-agenda-diary-file))
  7973. (require 'org-datetree)
  7974. (org-datetree-find-date-create d1)
  7975. (org-reveal t))
  7976. (t (error "Invalid selection character `%c'" char)))))
  7977. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7978. "Where in `org-agenda-diary-file' should new entries be added?
  7979. Valid values:
  7980. date-tree in the date tree, as child of the date
  7981. top-level as top-level entries at the end of the file."
  7982. :group 'org-agenda
  7983. :type '(choice
  7984. (const :tag "in a date tree" date-tree)
  7985. (const :tag "as top level at end of file" top-level)))
  7986. (defcustom org-agenda-insert-diary-extract-time nil
  7987. "Non-nil means extract any time specification from the diary entry."
  7988. :group 'org-agenda
  7989. :version "24.1"
  7990. :type 'boolean)
  7991. (defcustom org-agenda-bulk-mark-char ">"
  7992. "A single-character string to be used as the bulk mark."
  7993. :group 'org-agenda
  7994. :version "24.1"
  7995. :type 'string)
  7996. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7997. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7998. If TEXT is not empty, it will become the headline of the new entry, and
  7999. the resulting entry will not be shown. When TEXT is empty, switch to
  8000. `org-agenda-diary-file' and let the user finish the entry there."
  8001. (let ((cw (current-window-configuration)))
  8002. (org-switch-to-buffer-other-window
  8003. (find-file-noselect org-agenda-diary-file))
  8004. (widen)
  8005. (goto-char (point-min))
  8006. (cond
  8007. ((eq type 'anniversary)
  8008. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8009. (progn
  8010. (or (org-at-heading-p t)
  8011. (progn
  8012. (outline-next-heading)
  8013. (insert "* Anniversaries\n\n")
  8014. (beginning-of-line -1)))))
  8015. (outline-next-heading)
  8016. (org-back-over-empty-lines)
  8017. (backward-char 1)
  8018. (insert "\n")
  8019. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8020. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8021. ((eq type 'day)
  8022. (let ((org-prefix-has-time t)
  8023. (org-agenda-time-leading-zero t)
  8024. fmt time time2)
  8025. (if org-agenda-insert-diary-extract-time
  8026. ;; Use org-agenda-format-item to parse text for a time-range and
  8027. ;; remove it. FIXME: This is a hack, we should refactor
  8028. ;; that function to make time extraction available separately
  8029. (setq fmt (org-agenda-format-item nil text nil nil t)
  8030. time (get-text-property 0 'time fmt)
  8031. time2 (if (> (length time) 0)
  8032. ;; split-string removes trailing ...... if
  8033. ;; no end time given. First space
  8034. ;; separates time from date.
  8035. (concat " " (car (split-string time "\\.")))
  8036. nil)
  8037. text (get-text-property 0 'txt fmt)))
  8038. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8039. (org-agenda-insert-diary-as-top-level text)
  8040. (require 'org-datetree)
  8041. (org-datetree-find-date-create d1)
  8042. (org-agenda-insert-diary-make-new-entry text))
  8043. (org-insert-time-stamp (org-time-from-absolute
  8044. (calendar-absolute-from-gregorian d1))
  8045. nil nil nil nil time2))
  8046. (end-of-line 0))
  8047. ((eq type 'block)
  8048. (if (> (calendar-absolute-from-gregorian d1)
  8049. (calendar-absolute-from-gregorian d2))
  8050. (setq d1 (prog1 d2 (setq d2 d1))))
  8051. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8052. (org-agenda-insert-diary-as-top-level text)
  8053. (require 'org-datetree)
  8054. (org-datetree-find-date-create d1)
  8055. (org-agenda-insert-diary-make-new-entry text))
  8056. (org-insert-time-stamp (org-time-from-absolute
  8057. (calendar-absolute-from-gregorian d1)))
  8058. (insert "--")
  8059. (org-insert-time-stamp (org-time-from-absolute
  8060. (calendar-absolute-from-gregorian d2)))
  8061. (end-of-line 0)))
  8062. (if (string-match "\\S-" text)
  8063. (progn
  8064. (set-window-configuration cw)
  8065. (message "%s entry added to %s"
  8066. (capitalize (symbol-name type))
  8067. (abbreviate-file-name org-agenda-diary-file)))
  8068. (org-reveal t)
  8069. (message "Please finish entry here"))))
  8070. (defun org-agenda-insert-diary-as-top-level (text)
  8071. "Make new entry as a top-level entry at the end of the file.
  8072. Add TEXT as headline, and position the cursor in the second line so that
  8073. a timestamp can be added there."
  8074. (widen)
  8075. (goto-char (point-max))
  8076. (or (bolp) (insert "\n"))
  8077. (insert "* " text "\n")
  8078. (if org-adapt-indentation (org-indent-to-column 2)))
  8079. (defun org-agenda-insert-diary-make-new-entry (text)
  8080. "Make new entry as last child of current entry.
  8081. Add TEXT as headline, and position the cursor in the second line so that
  8082. a timestamp can be added there."
  8083. (let ((org-show-following-heading t)
  8084. (org-show-siblings t)
  8085. (org-show-hierarchy-above t)
  8086. (org-show-entry-below t)
  8087. col)
  8088. (outline-next-heading)
  8089. (org-back-over-empty-lines)
  8090. (or (looking-at "[ \t]*$")
  8091. (progn (insert "\n") (backward-char 1)))
  8092. (org-insert-heading nil t)
  8093. (org-do-demote)
  8094. (setq col (current-column))
  8095. (insert text "\n")
  8096. (if org-adapt-indentation (org-indent-to-column col))
  8097. (let ((org-show-following-heading t)
  8098. (org-show-siblings t)
  8099. (org-show-hierarchy-above t)
  8100. (org-show-entry-below t))
  8101. (org-show-context))))
  8102. (defun org-agenda-diary-entry ()
  8103. "Make a diary entry, like the `i' command from the calendar.
  8104. All the standard commands work: block, weekly etc.
  8105. When `org-agenda-diary-file' points to a file,
  8106. `org-agenda-diary-entry-in-org-file' is called instead to create
  8107. entries in that Org-mode file."
  8108. (interactive)
  8109. (org-agenda-check-type t 'agenda 'timeline)
  8110. (if (not (eq org-agenda-diary-file 'diary-file))
  8111. (org-agenda-diary-entry-in-org-file)
  8112. (require 'diary-lib)
  8113. (let* ((char (progn
  8114. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8115. (read-char-exclusive)))
  8116. (cmd (cdr (assoc char
  8117. '((?d . insert-diary-entry)
  8118. (?w . insert-weekly-diary-entry)
  8119. (?m . insert-monthly-diary-entry)
  8120. (?y . insert-yearly-diary-entry)
  8121. (?a . insert-anniversary-diary-entry)
  8122. (?b . insert-block-diary-entry)
  8123. (?c . insert-cyclic-diary-entry)))))
  8124. (oldf (symbol-function 'calendar-cursor-to-date))
  8125. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8126. (point (point))
  8127. (mark (or (mark t) (point))))
  8128. (unless cmd
  8129. (error "No command associated with <%c>" char))
  8130. (unless (and (get-text-property point 'day)
  8131. (or (not (equal ?b char))
  8132. (get-text-property mark 'day)))
  8133. (error "Don't know which date to use for diary entry"))
  8134. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8135. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8136. (let ((calendar-mark-ring
  8137. (list (calendar-gregorian-from-absolute
  8138. (or (get-text-property mark 'day)
  8139. (get-text-property point 'day))))))
  8140. (unwind-protect
  8141. (progn
  8142. (fset 'calendar-cursor-to-date
  8143. (lambda (&optional error dummy)
  8144. (calendar-gregorian-from-absolute
  8145. (get-text-property point 'day))))
  8146. (call-interactively cmd))
  8147. (fset 'calendar-cursor-to-date oldf))))))
  8148. (defun org-agenda-execute-calendar-command (cmd)
  8149. "Execute a calendar command from the agenda, with the date associated to
  8150. the cursor position."
  8151. (org-agenda-check-type t 'agenda 'timeline)
  8152. (require 'diary-lib)
  8153. (unless (get-text-property (point) 'day)
  8154. (error "Don't know which date to use for calendar command"))
  8155. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8156. (point (point))
  8157. (date (calendar-gregorian-from-absolute
  8158. (get-text-property point 'day)))
  8159. ;; the following 2 vars are needed in the calendar
  8160. (displayed-month (car date))
  8161. (displayed-year (nth 2 date)))
  8162. (unwind-protect
  8163. (progn
  8164. (fset 'calendar-cursor-to-date
  8165. (lambda (&optional error dummy)
  8166. (calendar-gregorian-from-absolute
  8167. (get-text-property point 'day))))
  8168. (call-interactively cmd))
  8169. (fset 'calendar-cursor-to-date oldf))))
  8170. (defun org-agenda-phases-of-moon ()
  8171. "Display the phases of the moon for the 3 months around the cursor date."
  8172. (interactive)
  8173. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8174. (defun org-agenda-holidays ()
  8175. "Display the holidays for the 3 months around the cursor date."
  8176. (interactive)
  8177. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8178. (defvar calendar-longitude) ; defined in calendar.el
  8179. (defvar calendar-latitude) ; defined in calendar.el
  8180. (defvar calendar-location-name) ; defined in calendar.el
  8181. (defun org-agenda-sunrise-sunset (arg)
  8182. "Display sunrise and sunset for the cursor date.
  8183. Latitude and longitude can be specified with the variables
  8184. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8185. argument, latitude and longitude will be prompted for."
  8186. (interactive "P")
  8187. (require 'solar)
  8188. (let ((calendar-longitude (if arg nil calendar-longitude))
  8189. (calendar-latitude (if arg nil calendar-latitude))
  8190. (calendar-location-name
  8191. (if arg "the given coordinates" calendar-location-name)))
  8192. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8193. (defun org-agenda-goto-calendar ()
  8194. "Open the Emacs calendar with the date at the cursor."
  8195. (interactive)
  8196. (org-agenda-check-type t 'agenda 'timeline)
  8197. (let* ((day (or (get-text-property (point) 'day)
  8198. (error "Don't know which date to open in calendar")))
  8199. (date (calendar-gregorian-from-absolute day))
  8200. (calendar-move-hook nil)
  8201. (calendar-view-holidays-initially-flag nil)
  8202. (calendar-view-diary-initially-flag nil))
  8203. (calendar)
  8204. (calendar-goto-date date)))
  8205. ;;;###autoload
  8206. (defun org-calendar-goto-agenda ()
  8207. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8208. This is a command that has to be installed in `calendar-mode-map'."
  8209. (interactive)
  8210. (org-agenda-list nil (calendar-absolute-from-gregorian
  8211. (calendar-cursor-to-date))
  8212. nil))
  8213. (defun org-agenda-convert-date ()
  8214. (interactive)
  8215. (org-agenda-check-type t 'agenda 'timeline)
  8216. (let ((day (get-text-property (point) 'day))
  8217. date s)
  8218. (unless day
  8219. (error "Don't know which date to convert"))
  8220. (setq date (calendar-gregorian-from-absolute day))
  8221. (setq s (concat
  8222. "Gregorian: " (calendar-date-string date) "\n"
  8223. "ISO: " (calendar-iso-date-string date) "\n"
  8224. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8225. "Julian: " (calendar-julian-date-string date) "\n"
  8226. "Astron. JD: " (calendar-astro-date-string date)
  8227. " (Julian date number at noon UTC)\n"
  8228. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8229. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8230. "French: " (calendar-french-date-string date) "\n"
  8231. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8232. "Mayan: " (calendar-mayan-date-string date) "\n"
  8233. "Coptic: " (calendar-coptic-date-string date) "\n"
  8234. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8235. "Persian: " (calendar-persian-date-string date) "\n"
  8236. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8237. (with-output-to-temp-buffer "*Dates*"
  8238. (princ s))
  8239. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8240. ;;; Bulk commands
  8241. (defun org-agenda-bulk-marked-p ()
  8242. (eq (get-char-property (point-at-bol) 'type)
  8243. 'org-marked-entry-overlay))
  8244. (defun org-agenda-bulk-mark (&optional arg)
  8245. "Mark the entry at point for future bulk action."
  8246. (interactive "p")
  8247. (dotimes (i (or arg 1))
  8248. (unless (org-get-at-bol 'org-agenda-diary-link)
  8249. (let* ((m (org-get-at-bol 'org-hd-marker))
  8250. ov)
  8251. (unless (org-agenda-bulk-marked-p)
  8252. (unless m (error "Nothing to mark at point"))
  8253. (push m org-agenda-bulk-marked-entries)
  8254. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8255. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8256. (org-get-todo-face "TODO")
  8257. 'evaporate)
  8258. (overlay-put ov 'type 'org-marked-entry-overlay))
  8259. (beginning-of-line 2)
  8260. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8261. (beginning-of-line 2))
  8262. (message "%d entries marked for bulk action"
  8263. (length org-agenda-bulk-marked-entries))))))
  8264. (defun org-agenda-bulk-mark-all ()
  8265. "Mark all entries for future agenda bulk action."
  8266. (interactive)
  8267. (org-agenda-bulk-mark-regexp "."))
  8268. (defun org-agenda-bulk-mark-regexp (regexp)
  8269. "Mark entries matching REGEXP for future agenda bulk action."
  8270. (interactive "sMark entries matching regexp: ")
  8271. (let ((entries-marked 0))
  8272. (save-excursion
  8273. (goto-char (point-min))
  8274. (goto-char (next-single-property-change (point) 'txt))
  8275. (while (re-search-forward regexp nil t)
  8276. (when (string-match regexp (get-text-property (point) 'txt))
  8277. (setq entries-marked (1+ entries-marked))
  8278. (call-interactively 'org-agenda-bulk-mark))))
  8279. (if (not entries-marked)
  8280. (message "No entry matching this regexp."))))
  8281. (defun org-agenda-bulk-unmark (&optional arg)
  8282. "Unmark the entry at point for future bulk action."
  8283. (interactive "P")
  8284. (if arg
  8285. (org-agenda-bulk-unmark-all)
  8286. (cond ((org-agenda-bulk-marked-p)
  8287. (org-agenda-bulk-remove-overlays
  8288. (point-at-bol) (+ 2 (point-at-bol)))
  8289. (setq org-agenda-bulk-marked-entries
  8290. (delete (org-get-at-bol 'org-hd-marker)
  8291. org-agenda-bulk-marked-entries))
  8292. (beginning-of-line 2)
  8293. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8294. (beginning-of-line 2))
  8295. (message "%d entries left marked for bulk action"
  8296. (length org-agenda-bulk-marked-entries)))
  8297. (t (message "No entry to unmark here")))))
  8298. (defun org-agenda-bulk-toggle ()
  8299. "Toggle marking the entry at point for bulk action."
  8300. (interactive)
  8301. (if (org-agenda-bulk-marked-p)
  8302. (org-agenda-bulk-unmark)
  8303. (org-agenda-bulk-mark)))
  8304. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8305. "Remove the mark overlays between BEG and END in the agenda buffer.
  8306. BEG and END default to the buffer limits.
  8307. This only removes the overlays, it does not remove the markers
  8308. from the list in `org-agenda-bulk-marked-entries'."
  8309. (interactive)
  8310. (mapc (lambda (ov)
  8311. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8312. (delete-overlay ov)))
  8313. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8314. (defun org-agenda-bulk-unmark-all ()
  8315. "Remove all marks in the agenda buffer.
  8316. This will remove the markers and the overlays."
  8317. (interactive)
  8318. (if (null org-agenda-bulk-marked-entries)
  8319. (message "No entry to unmark")
  8320. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8321. (setq org-agenda-bulk-marked-entries nil)
  8322. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8323. (defcustom org-agenda-persistent-marks nil
  8324. "Non-nil means marked items will stay marked after a bulk action.
  8325. You can toggle this interactively by typing `p' when prompted for a
  8326. bulk action."
  8327. :group 'org-agenda
  8328. :version "24.1"
  8329. :type 'boolean)
  8330. (defun org-agenda-bulk-action (&optional arg)
  8331. "Execute an remote-editing action on all marked entries.
  8332. The prefix arg is passed through to the command if possible."
  8333. (interactive "P")
  8334. ;; Make sure we have markers, and only valid ones
  8335. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8336. (mapc
  8337. (lambda (m)
  8338. (unless (and (markerp m)
  8339. (marker-buffer m)
  8340. (buffer-live-p (marker-buffer m))
  8341. (marker-position m))
  8342. (error "Marker %s for bulk command is invalid" m)))
  8343. org-agenda-bulk-marked-entries)
  8344. ;; Prompt for the bulk command
  8345. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8346. (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
  8347. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
  8348. (when org-agenda-bulk-custom-functions
  8349. (concat " Custom: ["
  8350. (mapconcat (lambda(f) (char-to-string (car f)))
  8351. org-agenda-bulk-custom-functions "")
  8352. "]"))))
  8353. (catch 'exit
  8354. (let* ((action (read-char-exclusive))
  8355. (org-log-refile (if org-log-refile 'time nil))
  8356. (entries (reverse org-agenda-bulk-marked-entries))
  8357. redo-at-end
  8358. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8359. (cond
  8360. ((equal action ?p)
  8361. (let ((org-agenda-persistent-marks
  8362. (not org-agenda-persistent-marks)))
  8363. (org-agenda-bulk-action)
  8364. (throw 'exit nil)))
  8365. ((equal action ?$)
  8366. (setq cmd '(org-agenda-archive)))
  8367. ((equal action ?A)
  8368. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8369. ((member action '(?r ?w))
  8370. (setq rfloc (org-refile-get-location
  8371. "Refile to"
  8372. (marker-buffer (car org-agenda-bulk-marked-entries))
  8373. org-refile-allow-creating-parent-nodes))
  8374. (if (nth 3 rfloc)
  8375. (setcar (nthcdr 3 rfloc)
  8376. (move-marker (make-marker) (nth 3 rfloc)
  8377. (or (get-file-buffer (nth 1 rfloc))
  8378. (find-buffer-visiting (nth 1 rfloc))
  8379. (error "This should not happen")))))
  8380. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8381. redo-at-end t))
  8382. ((equal action ?t)
  8383. (setq state (org-icompleting-read
  8384. "Todo state: "
  8385. (with-current-buffer (marker-buffer (car entries))
  8386. (mapcar 'list org-todo-keywords-1))))
  8387. (setq cmd `(let ((org-inhibit-blocking t)
  8388. (org-inhibit-logging 'note))
  8389. (org-agenda-todo ,state))))
  8390. ((memq action '(?- ?+))
  8391. (setq tag (org-icompleting-read
  8392. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8393. (with-current-buffer (marker-buffer (car entries))
  8394. (delq nil
  8395. (mapcar (lambda (x)
  8396. (if (stringp (car x)) x)) org-tag-alist)))))
  8397. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8398. ((memq action '(?s ?d))
  8399. (let* ((date (unless arg
  8400. (org-read-date
  8401. nil nil nil
  8402. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8403. (ans (if arg nil org-read-date-final-answer))
  8404. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8405. (setq cmd `(let* ((bound (fboundp 'read-string))
  8406. (old (and bound (symbol-function 'read-string))))
  8407. (unwind-protect
  8408. (progn
  8409. (fset 'read-string (lambda (&rest ignore) ,ans))
  8410. (eval '(,c1 arg)))
  8411. (if bound
  8412. (fset 'read-string old)
  8413. (fmakunbound 'read-string)))))))
  8414. ((equal action ?S)
  8415. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8416. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8417. (let ((days (read-number
  8418. (format "Scatter tasks across how many %sdays: "
  8419. (if arg "week" "")) 7)))
  8420. (setq cmd
  8421. `(let ((distance (1+ (random ,days))))
  8422. (if arg
  8423. (let ((dist distance)
  8424. (day-of-week
  8425. (calendar-day-of-week
  8426. (calendar-gregorian-from-absolute (org-today)))))
  8427. (dotimes (i (1+ dist))
  8428. (while (member day-of-week org-agenda-weekend-days)
  8429. (incf distance)
  8430. (incf day-of-week)
  8431. (if (= day-of-week 7)
  8432. (setq day-of-week 0)))
  8433. (incf day-of-week)
  8434. (if (= day-of-week 7)
  8435. (setq day-of-week 0)))))
  8436. ;; silently fail when try to replan a sexp entry
  8437. (condition-case nil
  8438. (let* ((date (calendar-gregorian-from-absolute
  8439. (+ (org-today) distance)))
  8440. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8441. (nth 2 date))))
  8442. (org-agenda-schedule nil time))
  8443. (error nil)))))))
  8444. ((assoc action org-agenda-bulk-custom-functions)
  8445. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8446. redo-at-end t))
  8447. ((equal action ?f)
  8448. (setq cmd (list (intern
  8449. (org-icompleting-read "Function: "
  8450. obarray 'fboundp t nil nil)))))
  8451. (t (error "Invalid bulk action")))
  8452. ;; Sort the markers, to make sure that parents are handled before children
  8453. (setq entries (sort entries
  8454. (lambda (a b)
  8455. (cond
  8456. ((equal (marker-buffer a) (marker-buffer b))
  8457. (< (marker-position a) (marker-position b)))
  8458. (t
  8459. (string< (buffer-name (marker-buffer a))
  8460. (buffer-name (marker-buffer b))))))))
  8461. ;; Now loop over all markers and apply cmd
  8462. (while (setq e (pop entries))
  8463. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8464. (if (not pos)
  8465. (progn (message "Skipping removed entry at %s" e)
  8466. (setq cntskip (1+ cntskip)))
  8467. (goto-char pos)
  8468. (let (org-loop-over-headlines-in-active-region)
  8469. (eval cmd))
  8470. (when (not org-agenda-persistent-marks)
  8471. (setq org-agenda-bulk-marked-entries
  8472. (delete e org-agenda-bulk-marked-entries)))
  8473. (setq cnt (1+ cnt))))
  8474. (when (not org-agenda-persistent-marks)
  8475. (org-agenda-bulk-unmark-all))
  8476. (when redo-at-end (org-agenda-redo))
  8477. (message "Acted on %d entries%s%s"
  8478. cnt
  8479. (if (= cntskip 0)
  8480. ""
  8481. (format ", skipped %d (disappeared before their turn)"
  8482. cntskip))
  8483. (if (not org-agenda-persistent-marks)
  8484. "" " (kept marked)"))))))
  8485. ;;; Flagging notes
  8486. (defun org-agenda-show-the-flagging-note ()
  8487. "Display the flagging note in the other window.
  8488. When called a second time in direct sequence, offer to remove the FLAGGING
  8489. tag and (if present) the flagging note."
  8490. (interactive)
  8491. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8492. (win (selected-window))
  8493. note heading newhead)
  8494. (unless hdmarker
  8495. (error "No linked entry at point"))
  8496. (if (and (eq this-command last-command)
  8497. (y-or-n-p "Unflag and remove any flagging note? "))
  8498. (progn
  8499. (org-agenda-remove-flag hdmarker)
  8500. (let ((win (get-buffer-window "*Flagging Note*")))
  8501. (and win (delete-window win)))
  8502. (message "Entry unflagged"))
  8503. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8504. (unless note
  8505. (error "No flagging note"))
  8506. (org-kill-new note)
  8507. (org-switch-to-buffer-other-window "*Flagging Note*")
  8508. (erase-buffer)
  8509. (insert note)
  8510. (goto-char (point-min))
  8511. (while (re-search-forward "\\\\n" nil t)
  8512. (replace-match "\n" t t))
  8513. (goto-char (point-min))
  8514. (select-window win)
  8515. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8516. (defun org-agenda-remove-flag (marker)
  8517. "Remove the FLAGGED tag and any flagging note in the entry."
  8518. (let (newhead)
  8519. (org-with-point-at marker
  8520. (org-toggle-tag "FLAGGED" 'off)
  8521. (org-entry-delete nil "THEFLAGGINGNOTE")
  8522. (setq newhead (org-get-heading)))
  8523. (org-agenda-change-all-lines newhead marker)
  8524. (message "Entry unflagged")))
  8525. (defun org-agenda-get-any-marker (&optional pos)
  8526. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8527. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8528. ;;; Appointment reminders
  8529. (defvar appt-time-msg-list) ; defined in appt.el
  8530. ;;;###autoload
  8531. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8532. "Activate appointments found in `org-agenda-files'.
  8533. With a \\[universal-argument] prefix, refresh the list of
  8534. appointments.
  8535. If FILTER is t, interactively prompt the user for a regular
  8536. expression, and filter out entries that don't match it.
  8537. If FILTER is a string, use this string as a regular expression
  8538. for filtering entries out.
  8539. If FILTER is a function, filter out entries against which
  8540. calling the function returns nil. This function takes one
  8541. argument: an entry from `org-agenda-get-day-entries'.
  8542. FILTER can also be an alist with the car of each cell being
  8543. either 'headline or 'category. For example:
  8544. '((headline \"IMPORTANT\")
  8545. (category \"Work\"))
  8546. will only add headlines containing IMPORTANT or headlines
  8547. belonging to the \"Work\" category.
  8548. ARGS are symbols indicating what kind of entries to consider.
  8549. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8550. and :timestamp entries. See the docstring of `org-diary' for
  8551. details and examples.
  8552. If an entry as a APPT_WARNTIME property, its value will be used
  8553. to override `appt-message-warning-time'."
  8554. (interactive "P")
  8555. (if refresh (setq appt-time-msg-list nil))
  8556. (if (eq filter t)
  8557. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8558. (let* ((cnt 0) ; count added events
  8559. (scope (or args '(:deadline :scheduled :timestamp)))
  8560. (org-agenda-new-buffers nil)
  8561. (org-deadline-warning-days 0)
  8562. ;; Do not use `org-today' here because appt only takes
  8563. ;; time and without date as argument, so it may pass wrong
  8564. ;; information otherwise
  8565. (today (org-date-to-gregorian
  8566. (time-to-days (current-time))))
  8567. (org-agenda-restrict nil)
  8568. (files (org-agenda-files 'unrestricted)) entries file
  8569. (org-agenda-buffer nil))
  8570. ;; Get all entries which may contain an appt
  8571. (org-agenda-prepare-buffers files)
  8572. (while (setq file (pop files))
  8573. (setq entries
  8574. (delq nil
  8575. (append entries
  8576. (apply 'org-agenda-get-day-entries
  8577. file today scope)))))
  8578. ;; Map thru entries and find if we should filter them out
  8579. (mapc
  8580. (lambda(x)
  8581. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8582. (cat (get-text-property 1 'org-category x))
  8583. (tod (get-text-property 1 'time-of-day x))
  8584. (ok (or (null filter)
  8585. (and (stringp filter) (string-match filter evt))
  8586. (and (functionp filter) (funcall filter x))
  8587. (and (listp filter)
  8588. (let ((cat-filter (cadr (assoc 'category filter)))
  8589. (evt-filter (cadr (assoc 'headline filter))))
  8590. (or (and (stringp cat-filter)
  8591. (string-match cat-filter cat))
  8592. (and (stringp evt-filter)
  8593. (string-match evt-filter evt)))))))
  8594. (wrn (get-text-property 1 'warntime x)))
  8595. ;; FIXME: Shall we remove text-properties for the appt text?
  8596. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8597. (when (and ok tod)
  8598. (setq tod (concat "00" (number-to-string tod))
  8599. tod (when (string-match
  8600. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8601. (concat (match-string 1 tod) ":"
  8602. (match-string 2 tod))))
  8603. (if (version< emacs-version "23.3")
  8604. (appt-add tod evt)
  8605. (appt-add tod evt wrn))
  8606. (setq cnt (1+ cnt))))) entries)
  8607. (org-release-buffers org-agenda-new-buffers)
  8608. (if (eq cnt 0)
  8609. (message "No event to add")
  8610. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8611. (defun org-agenda-todayp (date)
  8612. "Does DATE mean today, when considering `org-extend-today-until'?"
  8613. (let ((today (org-today))
  8614. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8615. date)))
  8616. (eq date today)))
  8617. (defun org-agenda-todo-yesterday (&optional arg)
  8618. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8619. (interactive "P")
  8620. (let* ((hour (third (decode-time
  8621. (org-current-time))))
  8622. (org-extend-today-until (1+ hour)))
  8623. (org-agenda-todo arg)))
  8624. (provide 'org-agenda)
  8625. ;;; org-agenda.el ends here