org-agenda.el 356 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270
  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. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today nil)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in temporary buffer before writing it to an export file.
  144. A useful function is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which it is by default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style ""
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header. However,
  200. <style>...</style> is required, if not present the variable will be ignored."
  201. :group 'org-agenda-export
  202. :group 'org-export-html
  203. :type 'string)
  204. (defcustom org-agenda-persistent-filter nil
  205. "When set, keep filters from one agenda view to the next."
  206. :group 'org-agenda
  207. :type 'boolean)
  208. (defgroup org-agenda-custom-commands nil
  209. "Options concerning agenda views in Org-mode."
  210. :tag "Org Agenda Custom Commands"
  211. :group 'org-agenda)
  212. (defconst org-sorting-choice
  213. '(choice
  214. (const time-up) (const time-down)
  215. (const category-keep) (const category-up) (const category-down)
  216. (const tag-down) (const tag-up)
  217. (const priority-up) (const priority-down)
  218. (const todo-state-up) (const todo-state-down)
  219. (const effort-up) (const effort-down)
  220. (const habit-up) (const habit-down)
  221. (const alpha-up) (const alpha-down)
  222. (const user-defined-up) (const user-defined-down))
  223. "Sorting choices.")
  224. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  225. ;; the new variable `org-agenda-tag-filter-preset'.
  226. (if (fboundp 'defvaralias)
  227. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  228. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  229. (defconst org-agenda-custom-commands-local-options
  230. `(repeat :tag "Local settings for this command. Remember to quote values"
  231. (choice :tag "Setting"
  232. (list :tag "Heading for this block"
  233. (const org-agenda-overriding-header)
  234. (string :tag "Headline"))
  235. (list :tag "Files to be searched"
  236. (const org-agenda-files)
  237. (list
  238. (const :format "" quote)
  239. (repeat (file))))
  240. (list :tag "Sorting strategy"
  241. (const org-agenda-sorting-strategy)
  242. (list
  243. (const :format "" quote)
  244. (repeat
  245. ,org-sorting-choice)))
  246. (list :tag "Prefix format"
  247. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  248. (string))
  249. (list :tag "Number of days in agenda"
  250. (const org-agenda-span)
  251. (choice (const :tag "Day" 'day)
  252. (const :tag "Week" 'week)
  253. (const :tag "Month" 'month)
  254. (const :tag "Year" 'year)
  255. (integer :tag "Custom")))
  256. (list :tag "Fixed starting date"
  257. (const org-agenda-start-day)
  258. (string :value "2007-11-01"))
  259. (list :tag "Start on day of week"
  260. (const org-agenda-start-on-weekday)
  261. (choice :value 1
  262. (const :tag "Today" nil)
  263. (integer :tag "Weekday No.")))
  264. (list :tag "Include data from diary"
  265. (const org-agenda-include-diary)
  266. (boolean))
  267. (list :tag "Deadline Warning days"
  268. (const org-deadline-warning-days)
  269. (integer :value 1))
  270. (list :tag "Category filter preset"
  271. (const org-agenda-category-filter-preset)
  272. (list
  273. (const :format "" quote)
  274. (repeat
  275. (string :tag "+category or -category"))))
  276. (list :tag "Tags filter preset"
  277. (const org-agenda-tag-filter-preset)
  278. (list
  279. (const :format "" quote)
  280. (repeat
  281. (string :tag "+tag or -tag"))))
  282. (list :tag "Set daily/weekly entry types"
  283. (const org-agenda-entry-types)
  284. (list
  285. (const :format "" quote)
  286. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  287. (const :deadline)
  288. (const :scheduled)
  289. (const :timestamp)
  290. (const :sexp))))
  291. (list :tag "Standard skipping condition"
  292. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  293. (const org-agenda-skip-function)
  294. (list
  295. (const :format "" quote)
  296. (list
  297. (choice
  298. :tag "Skipping range"
  299. (const :tag "Skip entry" org-agenda-skip-entry-if)
  300. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  301. (repeat :inline t :tag "Conditions for skipping"
  302. (choice
  303. :tag "Condition type"
  304. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  305. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  306. (list :tag "TODO state is" :inline t
  307. (const 'todo)
  308. (choice
  309. (const :tag "any not-done state" 'todo)
  310. (const :tag "any done state" 'done)
  311. (const :tag "any state" 'any)
  312. (list :tag "Keyword list"
  313. (const :format "" quote)
  314. (repeat (string :tag "Keyword")))))
  315. (list :tag "TODO state is not" :inline t
  316. (const 'nottodo)
  317. (choice
  318. (const :tag "any not-done state" 'todo)
  319. (const :tag "any done state" 'done)
  320. (const :tag "any state" 'any)
  321. (list :tag "Keyword list"
  322. (const :format "" quote)
  323. (repeat (string :tag "Keyword")))))
  324. (const :tag "scheduled" 'scheduled)
  325. (const :tag "not scheduled" 'notscheduled)
  326. (const :tag "deadline" 'deadline)
  327. (const :tag "no deadline" 'notdeadline)
  328. (const :tag "timestamp" 'timestamp)
  329. (const :tag "no timestamp" 'nottimestamp))))))
  330. (list :tag "Non-standard skipping condition"
  331. :value (org-agenda-skip-function)
  332. (const org-agenda-skip-function)
  333. (sexp :tag "Function or form (quoted!)"))
  334. (list :tag "Any variable"
  335. (variable :tag "Variable")
  336. (sexp :tag "Value (sexp)"))))
  337. "Selection of examples for agenda command settings.
  338. This will be spliced into the custom type of
  339. `org-agenda-custom-commands'.")
  340. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  341. ((agenda "") (alltodo))))
  342. "Custom commands for the agenda.
  343. These commands will be offered on the splash screen displayed by the
  344. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  345. (key desc type match settings files)
  346. key The key (one or more characters as a string) to be associated
  347. with the command.
  348. desc A description of the command, when omitted or nil, a default
  349. description is built using MATCH.
  350. type The command type, any of the following symbols:
  351. agenda The daily/weekly agenda.
  352. todo Entries with a specific TODO keyword, in all agenda files.
  353. search Entries containing search words entry or headline.
  354. tags Tags/Property/TODO match in all agenda files.
  355. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  356. todo-tree Sparse tree of specific TODO keyword in *current* file.
  357. tags-tree Sparse tree with all tags matches in *current* file.
  358. occur-tree Occur sparse tree for *current* file.
  359. ... A user-defined function.
  360. match What to search for:
  361. - a single keyword for TODO keyword searches
  362. - a tags match expression for tags searches
  363. - a word search expression for text searches.
  364. - a regular expression for occur searches
  365. For all other commands, this should be the empty string.
  366. settings A list of option settings, similar to that in a let form, so like
  367. this: ((opt1 val1) (opt2 val2) ...). The values will be
  368. evaluated at the moment of execution, so quote them when needed.
  369. files A list of files file to write the produced agenda buffer to
  370. with the command `org-store-agenda-views'.
  371. If a file name ends in \".html\", an HTML version of the buffer
  372. is written out. If it ends in \".ps\", a postscript version is
  373. produced. Otherwise, only the plain text is written to the file.
  374. You can also define a set of commands, to create a composite agenda buffer.
  375. In this case, an entry looks like this:
  376. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  377. where
  378. desc A description string to be displayed in the dispatcher menu.
  379. cmd An agenda command, similar to the above. However, tree commands
  380. are not allowed, but instead you can get agenda and global todo list.
  381. So valid commands for a set are:
  382. (agenda \"\" settings)
  383. (alltodo \"\" settings)
  384. (stuck \"\" settings)
  385. (todo \"match\" settings files)
  386. (search \"match\" settings files)
  387. (tags \"match\" settings files)
  388. (tags-todo \"match\" settings files)
  389. Each command can carry a list of options, and another set of options can be
  390. given for the whole set of commands. Individual command options take
  391. precedence over the general options.
  392. When using several characters as key to a command, the first characters
  393. are prefix commands. For the dispatcher to display useful information, you
  394. should provide a description for the prefix, like
  395. (setq org-agenda-custom-commands
  396. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  397. (\"hl\" tags \"+HOME+Lisa\")
  398. (\"hp\" tags \"+HOME+Peter\")
  399. (\"hk\" tags \"+HOME+Kim\")))"
  400. :group 'org-agenda-custom-commands
  401. :type `(repeat
  402. (choice :value ("x" "Describe command here" tags "" nil)
  403. (list :tag "Single command"
  404. (string :tag "Access Key(s) ")
  405. (option (string :tag "Description"))
  406. (choice
  407. (const :tag "Agenda" agenda)
  408. (const :tag "TODO list" alltodo)
  409. (const :tag "Search words" search)
  410. (const :tag "Stuck projects" stuck)
  411. (const :tag "Tags/Property match (all agenda files)" tags)
  412. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  413. (const :tag "TODO keyword search (all agenda files)" todo)
  414. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  415. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  416. (const :tag "Occur tree (current buffer)" occur-tree)
  417. (sexp :tag "Other, user-defined function"))
  418. (string :tag "Match (only for some commands)")
  419. ,org-agenda-custom-commands-local-options
  420. (option (repeat :tag "Export" (file :tag "Export to"))))
  421. (list :tag "Command series, all agenda files"
  422. (string :tag "Access Key(s)")
  423. (string :tag "Description ")
  424. (repeat :tag "Component"
  425. (choice
  426. (list :tag "Agenda"
  427. (const :format "" agenda)
  428. (const :tag "" :format "" "")
  429. ,org-agenda-custom-commands-local-options)
  430. (list :tag "TODO list (all keywords)"
  431. (const :format "" alltodo)
  432. (const :tag "" :format "" "")
  433. ,org-agenda-custom-commands-local-options)
  434. (list :tag "Search words"
  435. (const :format "" search)
  436. (string :tag "Match")
  437. ,org-agenda-custom-commands-local-options)
  438. (list :tag "Stuck projects"
  439. (const :format "" stuck)
  440. (const :tag "" :format "" "")
  441. ,org-agenda-custom-commands-local-options)
  442. (list :tag "Tags search"
  443. (const :format "" tags)
  444. (string :tag "Match")
  445. ,org-agenda-custom-commands-local-options)
  446. (list :tag "Tags search, TODO entries only"
  447. (const :format "" tags-todo)
  448. (string :tag "Match")
  449. ,org-agenda-custom-commands-local-options)
  450. (list :tag "TODO keyword search"
  451. (const :format "" todo)
  452. (string :tag "Match")
  453. ,org-agenda-custom-commands-local-options)
  454. (list :tag "Other, user-defined function"
  455. (symbol :tag "function")
  456. (string :tag "Match")
  457. ,org-agenda-custom-commands-local-options)))
  458. (repeat :tag "Settings for entire command set"
  459. (list (variable :tag "Any variable")
  460. (sexp :tag "Value")))
  461. (option (repeat :tag "Export" (file :tag "Export to"))))
  462. (cons :tag "Prefix key documentation"
  463. (string :tag "Access Key(s)")
  464. (string :tag "Description ")))))
  465. (defcustom org-agenda-query-register ?o
  466. "The register holding the current query string.
  467. The purpose of this is that if you construct a query string interactively,
  468. you can then use it to define a custom command."
  469. :group 'org-agenda-custom-commands
  470. :type 'character)
  471. (defcustom org-stuck-projects
  472. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  473. "How to identify stuck projects.
  474. This is a list of four items:
  475. 1. A tags/todo/property matcher string that is used to identify a project.
  476. See the manual for a description of tag and property searches.
  477. The entire tree below a headline matched by this is considered one project.
  478. 2. A list of TODO keywords identifying non-stuck projects.
  479. If the project subtree contains any headline with one of these todo
  480. keywords, the project is considered to be not stuck. If you specify
  481. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  482. 3. A list of tags identifying non-stuck projects.
  483. If the project subtree contains any headline with one of these tags,
  484. the project is considered to be not stuck. If you specify \"*\" as
  485. a tag, any tag will mark the project unstuck. Note that this is about
  486. the explicit presence of a tag somewhere in the subtree, inherited
  487. tags to not count here. If inherited tags make a project not stuck,
  488. use \"-TAG\" in the tags part of the matcher under (1.) above.
  489. 4. An arbitrary regular expression matching non-stuck projects.
  490. If the project turns out to be not stuck, search continues also in the
  491. subtree to see if any of the subtasks have project status.
  492. See also the variable `org-tags-match-list-sublevels' which applies
  493. to projects matched by this search as well.
  494. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  495. or `C-c a #' to produce the list."
  496. :group 'org-agenda-custom-commands
  497. :type '(list
  498. (string :tag "Tags/TODO match to identify a project")
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  500. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  501. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  502. (defcustom org-agenda-filter-effort-default-operator "<"
  503. "The default operator for effort estimate filtering.
  504. If you select an effort estimate limit without first pressing an operator,
  505. this one will be used."
  506. :group 'org-agenda-custom-commands
  507. :type '(choice (const :tag "less or equal" "<")
  508. (const :tag "greater or equal"">")
  509. (const :tag "equal" "=")))
  510. (defgroup org-agenda-skip nil
  511. "Options concerning skipping parts of agenda files."
  512. :tag "Org Agenda Skip"
  513. :group 'org-agenda)
  514. (defcustom org-agenda-skip-function-global nil
  515. "Function to be called at each match during agenda construction.
  516. If this function returns nil, the current match should not be skipped.
  517. If the function decided to skip an agenda match, is must return the
  518. buffer position from which the search should be continued.
  519. This may also be a Lisp form, which will be evaluated.
  520. This variable will be applied to every agenda match, including
  521. tags/property searches and TODO lists. So try to make the test function
  522. do its checking as efficiently as possible. To implement a skipping
  523. condition just for specific agenda commands, use the variable
  524. `org-agenda-skip-function' which can be set in the options section
  525. of custom agenda commands."
  526. :group 'org-agenda-skip
  527. :type 'sexp)
  528. (defgroup org-agenda-daily/weekly nil
  529. "Options concerning the daily/weekly agenda."
  530. :tag "Org Agenda Daily/Weekly"
  531. :group 'org-agenda)
  532. (defgroup org-agenda-todo-list nil
  533. "Options concerning the global todo list agenda view."
  534. :tag "Org Agenda Todo List"
  535. :group 'org-agenda)
  536. (defgroup org-agenda-match-view nil
  537. "Options concerning the general tags/property/todo match agenda view."
  538. :tag "Org Agenda Match View"
  539. :group 'org-agenda)
  540. (defgroup org-agenda-search-view nil
  541. "Options concerning the general tags/property/todo match agenda view."
  542. :tag "Org Agenda Match View"
  543. :group 'org-agenda)
  544. (defvar org-agenda-archives-mode nil
  545. "Non-nil means the agenda will include archived items.
  546. If this is the symbol `trees', trees in the selected agenda scope
  547. that are marked with the ARCHIVE tag will be included anyway. When this is
  548. t, also all archive files associated with the current selection of agenda
  549. files will be included.")
  550. (defcustom org-agenda-skip-comment-trees t
  551. "Non-nil means skip trees that start with the COMMENT keyword.
  552. When nil, these trees are also scanned by agenda commands."
  553. :group 'org-agenda-skip
  554. :type 'boolean)
  555. (defcustom org-agenda-todo-list-sublevels t
  556. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  557. When nil, the sublevels of a TODO entry are not checked, resulting in
  558. potentially much shorter TODO lists."
  559. :group 'org-agenda-skip
  560. :group 'org-agenda-todo-list
  561. :type 'boolean)
  562. (defcustom org-agenda-todo-ignore-with-date nil
  563. "Non-nil means don't show entries with a date in the global todo list.
  564. You can use this if you prefer to mark mere appointments with a TODO keyword,
  565. but don't want them to show up in the TODO list.
  566. When this is set, it also covers deadlines and scheduled items, the settings
  567. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  568. will be ignored.
  569. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  570. :group 'org-agenda-skip
  571. :group 'org-agenda-todo-list
  572. :type 'boolean)
  573. (defcustom org-agenda-todo-ignore-timestamp nil
  574. "Non-nil means don't show entries with a timestamp.
  575. This applies when creating the global todo list.
  576. Valid values are:
  577. past Don't show entries for today or in the past.
  578. future Don't show entries with a timestamp in the future.
  579. The idea behind this is that if it has a future
  580. timestamp, you don't want to think about it until the
  581. date.
  582. all Don't show any entries with a timestamp in the global todo list.
  583. The idea behind this is that by setting a timestamp, you
  584. have already \"taken care\" of this item.
  585. This variable can also have an integer as a value. If positive (N),
  586. todos with a timestamp N or more days in the future will be ignored. If
  587. negative (-N), todos with a timestamp N or more days in the past will be
  588. ignored. If 0, todos with a timestamp either today or in the future will
  589. be ignored. For example, a value of -1 will exclude todos with a
  590. timestamp in the past (yesterday or earlier), while a value of 7 will
  591. exclude todos with a timestamp a week or more in the future.
  592. See also `org-agenda-todo-ignore-with-date'.
  593. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  594. to make his option also apply to the tags-todo list."
  595. :group 'org-agenda-skip
  596. :group 'org-agenda-todo-list
  597. :version "24.1"
  598. :type '(choice
  599. (const :tag "Ignore future timestamp todos" future)
  600. (const :tag "Ignore past or present timestamp todos" past)
  601. (const :tag "Ignore all timestamp todos" all)
  602. (const :tag "Show timestamp todos" nil)
  603. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  604. (defcustom org-agenda-todo-ignore-scheduled nil
  605. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  606. This applies when creating the global todo list.
  607. Valid values are:
  608. past Don't show entries scheduled today or in the past.
  609. future Don't show entries scheduled in the future.
  610. The idea behind this is that by scheduling it, you don't want to
  611. think about it until the scheduled date.
  612. all Don't show any scheduled entries in the global todo list.
  613. The idea behind this is that by scheduling it, you have already
  614. \"taken care\" of this item.
  615. t Same as `all', for backward compatibility.
  616. This variable can also have an integer as a value. See
  617. `org-agenda-todo-ignore-timestamp' for more details.
  618. See also `org-agenda-todo-ignore-with-date'.
  619. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  620. to make his option also apply to the tags-todo list."
  621. :group 'org-agenda-skip
  622. :group 'org-agenda-todo-list
  623. :type '(choice
  624. (const :tag "Ignore future-scheduled todos" future)
  625. (const :tag "Ignore past- or present-scheduled todos" past)
  626. (const :tag "Ignore all scheduled todos" all)
  627. (const :tag "Ignore all scheduled todos (compatibility)" t)
  628. (const :tag "Show scheduled todos" nil)
  629. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  630. (defcustom org-agenda-todo-ignore-deadlines nil
  631. "Non-nil means ignore some deadlined TODO items when making TODO list.
  632. There are different motivations for using different values, please think
  633. carefully when configuring this variable.
  634. This applies when creating the global todo list.
  635. Valid values are:
  636. near Don't show near deadline entries. A deadline is near when it is
  637. closer than `org-deadline-warning-days' days. The idea behind this
  638. is that such items will appear in the agenda anyway.
  639. far Don't show TODO entries where a deadline has been defined, but
  640. the deadline is not near. This is useful if you don't want to
  641. use the todo list to figure out what to do now.
  642. past Don't show entries with a deadline timestamp for today or in the past.
  643. future Don't show entries with a deadline timestamp in the future, not even
  644. when they become `near' ones. Use it with caution.
  645. all Ignore all TODO entries that do have a deadline.
  646. t Same as `near', for backward compatibility.
  647. This variable can also have an integer as a value. See
  648. `org-agenda-todo-ignore-timestamp' for more details.
  649. See also `org-agenda-todo-ignore-with-date'.
  650. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  651. to make his option also apply to the tags-todo list."
  652. :group 'org-agenda-skip
  653. :group 'org-agenda-todo-list
  654. :type '(choice
  655. (const :tag "Ignore near deadlines" near)
  656. (const :tag "Ignore near deadlines (compatibility)" t)
  657. (const :tag "Ignore far deadlines" far)
  658. (const :tag "Ignore all TODOs with a deadlines" all)
  659. (const :tag "Show all TODOs, even if they have a deadline" nil)
  660. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  661. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  662. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  663. The variables
  664. `org-agenda-todo-ignore-with-date',
  665. `org-agenda-todo-ignore-timestamp',
  666. `org-agenda-todo-ignore-scheduled',
  667. `org-agenda-todo-ignore-deadlines'
  668. make the global TODO list skip entries that have time stamps of certain
  669. kinds. If this option is set, the same options will also apply for the
  670. tags-todo search, which is the general tags/property matcher
  671. restricted to unfinished TODO entries only."
  672. :group 'org-agenda-skip
  673. :group 'org-agenda-todo-list
  674. :group 'org-agenda-match-view
  675. :type 'boolean)
  676. (defcustom org-agenda-skip-scheduled-if-done nil
  677. "Non-nil means don't show scheduled items in agenda when they are done.
  678. This is relevant for the daily/weekly agenda, not for the TODO list. And
  679. it applies only to the actual date of the scheduling. Warnings about
  680. an item with a past scheduling dates are always turned off when the item
  681. is DONE."
  682. :group 'org-agenda-skip
  683. :group 'org-agenda-daily/weekly
  684. :type 'boolean)
  685. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  686. "Non-nil means skip scheduling line if same entry shows because of deadline.
  687. In the agenda of today, an entry can show up multiple times because
  688. it is both scheduled and has a nearby deadline, and maybe a plain time
  689. stamp as well.
  690. When this variable is t, then only the deadline is shown and the fact that
  691. the entry is scheduled today or was scheduled previously is not shown.
  692. When this variable is nil, the entry will be shown several times. When
  693. the variable is the symbol `not-today', then skip scheduled previously,
  694. but not scheduled today."
  695. :group 'org-agenda-skip
  696. :group 'org-agenda-daily/weekly
  697. :type '(choice
  698. (const :tag "Never" nil)
  699. (const :tag "Always" t)
  700. (const :tag "Not when scheduled today" not-today)))
  701. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  702. "Non-nil means skip timestamp line if same entry shows because of deadline.
  703. In the agenda of today, an entry can show up multiple times
  704. because it has both a plain timestamp and has a nearby deadline.
  705. When this variable is t, then only the deadline is shown and the
  706. fact that the entry has a timestamp for or including today is not
  707. shown. When this variable is nil, the entry will be shown
  708. several times."
  709. :group 'org-agenda-skip
  710. :group 'org-agenda-daily/weekly
  711. :version "24.1"
  712. :type '(choice
  713. (const :tag "Never" nil)
  714. (const :tag "Always" t)))
  715. (defcustom org-agenda-skip-deadline-if-done nil
  716. "Non-nil means don't show deadlines when the corresponding item is done.
  717. When nil, the deadline is still shown and should give you a happy feeling.
  718. This is relevant for the daily/weekly agenda. And it applied only to the
  719. actually date of the deadline. Warnings about approaching and past-due
  720. deadlines are always turned off when the item is DONE."
  721. :group 'org-agenda-skip
  722. :group 'org-agenda-daily/weekly
  723. :type 'boolean)
  724. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  725. "Non-nil means skip deadline prewarning when entry is also scheduled.
  726. This will apply on all days where a prewarning for the deadline would
  727. be shown, but not at the day when the entry is actually due. On that day,
  728. the deadline will be shown anyway.
  729. This variable may be set to nil, t, or a number which will then give
  730. the number of days before the actual deadline when the prewarnings
  731. should resume.
  732. This can be used in a workflow where the first showing of the deadline will
  733. trigger you to schedule it, and then you don't want to be reminded of it
  734. because you will take care of it on the day when scheduled."
  735. :group 'org-agenda-skip
  736. :group 'org-agenda-daily/weekly
  737. :version "24.1"
  738. :type '(choice
  739. (const :tag "Alwas show prewarning" nil)
  740. (const :tag "Remove prewarning if entry is scheduled" t)
  741. (integer :tag "Restart prewarning N days before deadline")))
  742. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  743. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  744. When non-nil, after the search for timestamps has matched once in an
  745. entry, the rest of the entry will not be searched."
  746. :group 'org-agenda-skip
  747. :type 'boolean)
  748. (defcustom org-agenda-skip-timestamp-if-done nil
  749. "Non-nil means don't select item by timestamp or -range if it is DONE."
  750. :group 'org-agenda-skip
  751. :group 'org-agenda-daily/weekly
  752. :type 'boolean)
  753. (defcustom org-agenda-dim-blocked-tasks t
  754. "Non-nil means dim blocked tasks in the agenda display.
  755. This causes some overhead during agenda construction, but if you
  756. have turned on `org-enforce-todo-dependencies',
  757. `org-enforce-todo-checkbox-dependencies', or any other blocking
  758. mechanism, this will create useful feedback in the agenda.
  759. Instead of t, this variable can also have the value `invisible'.
  760. Then blocked tasks will be invisible and only become visible when
  761. they become unblocked. An exemption to this behavior is when a task is
  762. blocked because of unchecked checkboxes below it. Since checkboxes do
  763. not show up in the agenda views, making this task invisible you remove any
  764. trace from agenda views that there is something to do. Therefore, a task
  765. that is blocked because of checkboxes will never be made invisible, it
  766. will only be dimmed."
  767. :group 'org-agenda-daily/weekly
  768. :group 'org-agenda-todo-list
  769. :type '(choice
  770. (const :tag "Do not dim" nil)
  771. (const :tag "Dim to a gray face" t)
  772. (const :tag "Make invisible" invisible)))
  773. (defcustom org-timeline-show-empty-dates 3
  774. "Non-nil means `org-timeline' also shows dates without an entry.
  775. When nil, only the days which actually have entries are shown.
  776. When t, all days between the first and the last date are shown.
  777. When an integer, show also empty dates, but if there is a gap of more than
  778. N days, just insert a special line indicating the size of the gap."
  779. :group 'org-agenda-skip
  780. :type '(choice
  781. (const :tag "None" nil)
  782. (const :tag "All" t)
  783. (integer :tag "at most")))
  784. (defgroup org-agenda-startup nil
  785. "Options concerning initial settings in the Agenda in Org Mode."
  786. :tag "Org Agenda Startup"
  787. :group 'org-agenda)
  788. (defcustom org-agenda-menu-show-matcher t
  789. "Non-nil means show the match string in the agenda dispatcher menu.
  790. When nil, the matcher string is not shown, but is put into the help-echo
  791. property so than moving the mouse over the command shows it.
  792. Setting it to nil is good if matcher strings are very long and/or if
  793. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  794. :group 'org-agenda
  795. :version "24.1"
  796. :type 'boolean)
  797. (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  798. (defcustom org-agenda-menu-two-columns nil
  799. "Non-nil means, use two columns to show custom commands in the dispatcher.
  800. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  801. to nil."
  802. :group 'org-agenda
  803. :version "24.1"
  804. :type 'boolean)
  805. (make-obsolete-variable 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  806. (defcustom org-agenda-finalize-hook nil
  807. "Hook run just before displaying an agenda buffer."
  808. :group 'org-agenda-startup
  809. :type 'hook)
  810. (defcustom org-agenda-mouse-1-follows-link nil
  811. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  812. A longer mouse click will still set point. Does not work on XEmacs.
  813. Needs to be set before org.el is loaded."
  814. :group 'org-agenda-startup
  815. :type 'boolean)
  816. (defcustom org-agenda-start-with-follow-mode nil
  817. "The initial value of follow mode in a newly created agenda window."
  818. :group 'org-agenda-startup
  819. :type 'boolean)
  820. (defcustom org-agenda-follow-indirect nil
  821. "Non-nil means `org-agenda-follow-mode' displays only the
  822. current item's tree, in an indirect buffer."
  823. :group 'org-agenda
  824. :version "24.1"
  825. :type 'boolean)
  826. (defcustom org-agenda-show-outline-path t
  827. "Non-nil means show outline path in echo area after line motion."
  828. :group 'org-agenda-startup
  829. :type 'boolean)
  830. (defcustom org-agenda-start-with-entry-text-mode nil
  831. "The initial value of entry-text-mode in a newly created agenda window."
  832. :group 'org-agenda-startup
  833. :type 'boolean)
  834. (defcustom org-agenda-entry-text-maxlines 5
  835. "Number of text lines to be added when `E' is pressed in the agenda.
  836. Note that this variable only used during agenda display. Add add entry text
  837. when exporting the agenda, configure the variable
  838. `org-agenda-add-entry-ext-maxlines'."
  839. :group 'org-agenda
  840. :type 'integer)
  841. (defcustom org-agenda-entry-text-exclude-regexps nil
  842. "List of regular expressions to clean up entry text.
  843. The complete matches of all regular expressions in this list will be
  844. removed from entry text before it is shown in the agenda."
  845. :group 'org-agenda
  846. :type '(repeat (regexp)))
  847. (defvar org-agenda-entry-text-cleanup-hook nil
  848. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  849. This cleanup is done in a temporary buffer, so the function may inspect and
  850. change the entire buffer.
  851. Some default stuff like drawers and scheduling/deadline dates will already
  852. have been removed when this is called, as will any matches for regular
  853. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  854. (defvar org-agenda-include-inactive-timestamps nil
  855. "Non-nil means include inactive time stamps in agenda and timeline.
  856. Dynamically scoped.")
  857. (defgroup org-agenda-windows nil
  858. "Options concerning the windows used by the Agenda in Org Mode."
  859. :tag "Org Agenda Windows"
  860. :group 'org-agenda)
  861. (defcustom org-agenda-window-setup 'reorganize-frame
  862. "How the agenda buffer should be displayed.
  863. Possible values for this option are:
  864. current-window Show agenda in the current window, keeping all other windows.
  865. other-window Use `switch-to-buffer-other-window' to display agenda.
  866. reorganize-frame Show only two windows on the current frame, the current
  867. window and the agenda.
  868. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  869. Also, when exiting the agenda, kill that frame.
  870. See also the variable `org-agenda-restore-windows-after-quit'."
  871. :group 'org-agenda-windows
  872. :type '(choice
  873. (const current-window)
  874. (const other-frame)
  875. (const other-window)
  876. (const reorganize-frame)))
  877. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  878. "The min and max height of the agenda window as a fraction of frame height.
  879. The value of the variable is a cons cell with two numbers between 0 and 1.
  880. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  881. :group 'org-agenda-windows
  882. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  883. (defcustom org-agenda-restore-windows-after-quit nil
  884. "Non-nil means restore window configuration upon exiting agenda.
  885. Before the window configuration is changed for displaying the agenda,
  886. the current status is recorded. When the agenda is exited with
  887. `q' or `x' and this option is set, the old state is restored. If
  888. `org-agenda-window-setup' is `other-frame', the value of this
  889. option will be ignored."
  890. :group 'org-agenda-windows
  891. :type 'boolean)
  892. (defcustom org-agenda-ndays nil
  893. "Number of days to include in overview display.
  894. Should be 1 or 7.
  895. Obsolete, see `org-agenda-span'."
  896. :group 'org-agenda-daily/weekly
  897. :type 'integer)
  898. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  899. (defcustom org-agenda-span 'week
  900. "Number of days to include in overview display.
  901. Can be day, week, month, year, or any number of days.
  902. Custom commands can set this variable in the options section."
  903. :group 'org-agenda-daily/weekly
  904. :type '(choice (const :tag "Day" day)
  905. (const :tag "Week" week)
  906. (const :tag "Month" month)
  907. (const :tag "Year" year)
  908. (integer :tag "Custom")))
  909. (defcustom org-agenda-start-on-weekday 1
  910. "Non-nil means start the overview always on the specified weekday.
  911. 0 denotes Sunday, 1 denotes Monday etc.
  912. When nil, always start on the current day.
  913. Custom commands can set this variable in the options section."
  914. :group 'org-agenda-daily/weekly
  915. :type '(choice (const :tag "Today" nil)
  916. (integer :tag "Weekday No.")))
  917. (defcustom org-agenda-show-all-dates t
  918. "Non-nil means `org-agenda' shows every day in the selected range.
  919. When nil, only the days which actually have entries are shown."
  920. :group 'org-agenda-daily/weekly
  921. :type 'boolean)
  922. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  923. "Format string for displaying dates in the agenda.
  924. Used by the daily/weekly agenda and by the timeline. This should be
  925. a format string understood by `format-time-string', or a function returning
  926. the formatted date as a string. The function must take a single argument,
  927. a calendar-style date list like (month day year)."
  928. :group 'org-agenda-daily/weekly
  929. :type '(choice
  930. (string :tag "Format string")
  931. (function :tag "Function")))
  932. (defun org-agenda-format-date-aligned (date)
  933. "Format a date string for display in the daily/weekly agenda, or timeline.
  934. This function makes sure that dates are aligned for easy reading."
  935. (require 'cal-iso)
  936. (let* ((dayname (calendar-day-name date))
  937. (day (cadr date))
  938. (day-of-week (calendar-day-of-week date))
  939. (month (car date))
  940. (monthname (calendar-month-name month))
  941. (year (nth 2 date))
  942. (iso-week (org-days-to-iso-week
  943. (calendar-absolute-from-gregorian date)))
  944. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  945. (1- year))
  946. ((and (= month 12) (<= iso-week 1))
  947. (1+ year))
  948. (t year)))
  949. (weekstring (if (= day-of-week 1)
  950. (format " W%02d" iso-week)
  951. "")))
  952. (format "%-10s %2d %s %4d%s"
  953. dayname day monthname year weekstring)))
  954. (defcustom org-agenda-time-leading-zero nil
  955. "Non-nil means use leading zero for military times in agenda.
  956. For example, 9:30am would become 09:30 rather than 9:30."
  957. :group 'org-agenda-daily/weekly
  958. :version "24.1"
  959. :type 'boolean)
  960. (defcustom org-agenda-timegrid-use-ampm nil
  961. "When set, show AM/PM style timestamps on the timegrid."
  962. :group 'org-agenda
  963. :version "24.1"
  964. :type 'boolean)
  965. (defun org-agenda-time-of-day-to-ampm (time)
  966. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  967. (let* ((hour-number (string-to-number (substring time 0 -3)))
  968. (minute (substring time -2))
  969. (ampm "am"))
  970. (cond
  971. ((equal hour-number 12)
  972. (setq ampm "pm"))
  973. ((> hour-number 12)
  974. (setq ampm "pm")
  975. (setq hour-number (- hour-number 12))))
  976. (concat
  977. (if org-agenda-time-leading-zero
  978. (format "%02d" hour-number)
  979. (format "%02s" (number-to-string hour-number)))
  980. ":" minute ampm)))
  981. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  982. "Conditionally convert TIME to AM/PM format
  983. based on `org-agenda-timegrid-use-ampm'"
  984. (if org-agenda-timegrid-use-ampm
  985. (org-agenda-time-of-day-to-ampm time)
  986. time))
  987. (defcustom org-agenda-weekend-days '(6 0)
  988. "Which days are weekend?
  989. These days get the special face `org-agenda-date-weekend' in the agenda
  990. and timeline buffers."
  991. :group 'org-agenda-daily/weekly
  992. :type '(set :greedy t
  993. (const :tag "Monday" 1)
  994. (const :tag "Tuesday" 2)
  995. (const :tag "Wednesday" 3)
  996. (const :tag "Thursday" 4)
  997. (const :tag "Friday" 5)
  998. (const :tag "Saturday" 6)
  999. (const :tag "Sunday" 0)))
  1000. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1001. "Non-nil means jump to today when moving a past date forward in time.
  1002. When using S-right in the agenda to move a a date forward, and the date
  1003. stamp currently points to the past, the first key press will move it
  1004. to today. WHen nil, just move one day forward even if the date stays
  1005. in the past."
  1006. :group 'org-agenda-daily/weekly
  1007. :version "24.1"
  1008. :type 'boolean)
  1009. (defcustom org-agenda-include-diary nil
  1010. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1011. Custom commands can set this variable in the options section."
  1012. :group 'org-agenda-daily/weekly
  1013. :type 'boolean)
  1014. (defcustom org-agenda-include-deadlines t
  1015. "If non-nil, include entries within their deadline warning period.
  1016. Custom commands can set this variable in the options section."
  1017. :group 'org-agenda-daily/weekly
  1018. :version "24.1"
  1019. :type 'boolean)
  1020. (defcustom org-agenda-repeating-timestamp-show-all t
  1021. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1022. When set to a list of strings, only show occurrences of repeating
  1023. stamps for these TODO keywords. When nil, only one occurrence is
  1024. shown, either today or the nearest into the future."
  1025. :group 'org-agenda-daily/weekly
  1026. :type '(choice
  1027. (const :tag "Show repeating stamps" t)
  1028. (repeat :tag "Show repeating stamps for these TODO keywords"
  1029. (string :tag "TODO Keyword"))
  1030. (const :tag "Don't show repeating stamps" nil)))
  1031. (defcustom org-scheduled-past-days 10000
  1032. "No. of days to continue listing scheduled items that are not marked DONE.
  1033. When an item is scheduled on a date, it shows up in the agenda on this
  1034. day and will be listed until it is marked done for the number of days
  1035. given here."
  1036. :group 'org-agenda-daily/weekly
  1037. :type 'integer)
  1038. (defcustom org-agenda-log-mode-items '(closed clock)
  1039. "List of items that should be shown in agenda log mode.
  1040. This list may contain the following symbols:
  1041. closed Show entries that have been closed on that day.
  1042. clock Show entries that have received clocked time on that day.
  1043. state Show all logged state changes.
  1044. Note that instead of changing this variable, you can also press `C-u l' in
  1045. the agenda to display all available LOG items temporarily."
  1046. :group 'org-agenda-daily/weekly
  1047. :type '(set :greedy t (const closed) (const clock) (const state)))
  1048. (defcustom org-agenda-clock-consistency-checks
  1049. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1050. :gap-ok-around ("4:00")
  1051. :default-face ((:background "DarkRed") (:foreground "white"))
  1052. :overlap-face nil :gap-face nil :no-end-time-face nil
  1053. :long-face nil :short-face nil)
  1054. "This is a property list, with the following keys:
  1055. :max-duration Mark clocking chunks that are longer than this time.
  1056. This is a time string like \"HH:MM\", or the number
  1057. of minutes as an integer.
  1058. :min-duration Mark clocking chunks that are shorter that this.
  1059. This is a time string like \"HH:MM\", or the number
  1060. of minutes as an integer.
  1061. :max-gap Mark gaps between clocking chunks that are longer than
  1062. this duration. A number of minutes, or a string
  1063. like \"HH:MM\".
  1064. :gap-ok-around List of times during the day which are usually not working
  1065. times. When a gap is detected, but the gap contains any
  1066. of these times, the gap is *not* reported. For example,
  1067. if this is (\"4:00\" \"13:00\") then gaps that contain
  1068. 4:00 in the morning (i.e. the night) and 13:00
  1069. (i.e. a typical lunch time) do not cause a warning.
  1070. You should have at least one time during the night in this
  1071. list, or otherwise the first task each morning will trigger
  1072. a warning because it follows a long gap.
  1073. Furthermore, the following properties can be used to define faces for
  1074. issue display.
  1075. :default-face the default face, if the specific face is undefined
  1076. :overlap-face face for overlapping clocks
  1077. :gap-face face for gaps between clocks
  1078. :no-end-time-face face for incomplete clocks
  1079. :long-face face for clock intervals that are too long
  1080. :short-face face for clock intervals that are too short"
  1081. :group 'org-agenda-daily/weekly
  1082. :group 'org-clock
  1083. :version "24.1"
  1084. :type 'plist)
  1085. (defcustom org-agenda-log-mode-add-notes t
  1086. "Non-nil means add first line of notes to log entries in agenda views.
  1087. If a log item like a state change or a clock entry is associated with
  1088. notes, the first line of these notes will be added to the entry in the
  1089. agenda display."
  1090. :group 'org-agenda-daily/weekly
  1091. :type 'boolean)
  1092. (defcustom org-agenda-start-with-log-mode nil
  1093. "The initial value of log-mode in a newly created agenda window.
  1094. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1095. explanations on the possible values."
  1096. :group 'org-agenda-startup
  1097. :group 'org-agenda-daily/weekly
  1098. :type '(choice (const :tag "Don't show log items" nil)
  1099. (const :tag "Show only log items" 'only)
  1100. (const :tag "Show all possible log items" 'clockcheck)
  1101. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1102. (choice (const :tag "Show closed log items" 'closed)
  1103. (const :tag "Show clocked log items" 'clock)
  1104. (const :tag "Show all logged state changes" 'state)))))
  1105. (defcustom org-agenda-start-with-clockreport-mode nil
  1106. "The initial value of clockreport-mode in a newly created agenda window."
  1107. :group 'org-agenda-startup
  1108. :group 'org-agenda-daily/weekly
  1109. :type 'boolean)
  1110. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1111. "Property list with parameters for the clocktable in clockreport mode.
  1112. This is the display mode that shows a clock table in the daily/weekly
  1113. agenda, the properties for this dynamic block can be set here.
  1114. The usual clocktable parameters are allowed here, but you cannot set
  1115. the properties :name, :tstart, :tend, :block, and :scope - these will
  1116. be overwritten to make sure the content accurately reflects the
  1117. current display in the agenda."
  1118. :group 'org-agenda-daily/weekly
  1119. :type 'plist)
  1120. (defcustom org-agenda-search-view-always-boolean nil
  1121. "Non-nil means the search string is interpreted as individual parts.
  1122. The search string for search view can either be interpreted as a phrase,
  1123. or as a list of snippets that define a boolean search for a number of
  1124. strings.
  1125. When this is non-nil, the string will be split on whitespace, and each
  1126. snippet will be searched individually, and all must match in order to
  1127. select an entry. A snippet is then a single string of non-white
  1128. characters, or a string in double quotes, or a regexp in {} braces.
  1129. If a snippet is preceded by \"-\", the snippet must *not* match.
  1130. \"+\" is syntactic sugar for positive selection. Each snippet may
  1131. be found as a full word or a partial word, but see the variable
  1132. `org-agenda-search-view-force-full-words'.
  1133. When this is nil, search will look for the entire search phrase as one,
  1134. with each space character matching any amount of whitespace, including
  1135. line breaks.
  1136. Even when this is nil, you can still switch to Boolean search dynamically
  1137. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1138. is a regexp marked with braces like \"{abc}\", this will also switch to
  1139. boolean search."
  1140. :group 'org-agenda-search-view
  1141. :version "24.1"
  1142. :type 'boolean)
  1143. (if (fboundp 'defvaralias)
  1144. (defvaralias 'org-agenda-search-view-search-words-only
  1145. 'org-agenda-search-view-always-boolean))
  1146. (defcustom org-agenda-search-view-force-full-words nil
  1147. "Non-nil means, search words must be matches as complete words.
  1148. When nil, they may also match part of a word."
  1149. :group 'org-agenda-search-view
  1150. :version "24.1"
  1151. :type 'boolean)
  1152. (defgroup org-agenda-time-grid nil
  1153. "Options concerning the time grid in the Org-mode Agenda."
  1154. :tag "Org Agenda Time Grid"
  1155. :group 'org-agenda)
  1156. (defcustom org-agenda-search-headline-for-time t
  1157. "Non-nil means search headline for a time-of-day.
  1158. If the headline contains a time-of-day in one format or another, it will
  1159. be used to sort the entry into the time sequence of items for a day.
  1160. Some people have time stamps in the headline that refer to the creation
  1161. time or so, and then this produces an unwanted side effect. If this is
  1162. the case for your, use this variable to turn off searching the headline
  1163. for a time."
  1164. :group 'org-agenda-time-grid
  1165. :type 'boolean)
  1166. (defcustom org-agenda-use-time-grid t
  1167. "Non-nil means show a time grid in the agenda schedule.
  1168. A time grid is a set of lines for specific times (like every two hours between
  1169. 8:00 and 20:00). The items scheduled for a day at specific times are
  1170. sorted in between these lines.
  1171. For details about when the grid will be shown, and what it will look like, see
  1172. the variable `org-agenda-time-grid'."
  1173. :group 'org-agenda-time-grid
  1174. :type 'boolean)
  1175. (defcustom org-agenda-time-grid
  1176. '((daily today require-timed)
  1177. "----------------"
  1178. (800 1000 1200 1400 1600 1800 2000))
  1179. "The settings for time grid for agenda display.
  1180. This is a list of three items. The first item is again a list. It contains
  1181. symbols specifying conditions when the grid should be displayed:
  1182. daily if the agenda shows a single day
  1183. weekly if the agenda shows an entire week
  1184. today show grid on current date, independent of daily/weekly display
  1185. require-timed show grid only if at least one item has a time specification
  1186. The second item is a string which will be placed behind the grid time.
  1187. The third item is a list of integers, indicating the times that should have
  1188. a grid line."
  1189. :group 'org-agenda-time-grid
  1190. :type
  1191. '(list
  1192. (set :greedy t :tag "Grid Display Options"
  1193. (const :tag "Show grid in single day agenda display" daily)
  1194. (const :tag "Show grid in weekly agenda display" weekly)
  1195. (const :tag "Always show grid for today" today)
  1196. (const :tag "Show grid only if any timed entries are present"
  1197. require-timed)
  1198. (const :tag "Skip grid times already present in an entry"
  1199. remove-match))
  1200. (string :tag "Grid String")
  1201. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1202. (defcustom org-agenda-show-current-time-in-grid t
  1203. "Non-nil means show the current time in the time grid."
  1204. :group 'org-agenda-time-grid
  1205. :version "24.1"
  1206. :type 'boolean)
  1207. (defcustom org-agenda-current-time-string
  1208. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1209. "The string for the current time marker in the agenda."
  1210. :group 'org-agenda-time-grid
  1211. :version "24.1"
  1212. :type 'string)
  1213. (defgroup org-agenda-sorting nil
  1214. "Options concerning sorting in the Org-mode Agenda."
  1215. :tag "Org Agenda Sorting"
  1216. :group 'org-agenda)
  1217. (defcustom org-agenda-sorting-strategy
  1218. '((agenda habit-down time-up priority-down category-keep)
  1219. (todo priority-down category-keep)
  1220. (tags priority-down category-keep)
  1221. (search category-keep))
  1222. "Sorting structure for the agenda items of a single day.
  1223. This is a list of symbols which will be used in sequence to determine
  1224. if an entry should be listed before another entry. The following
  1225. symbols are recognized:
  1226. time-up Put entries with time-of-day indications first, early first
  1227. time-down Put entries with time-of-day indications first, late first
  1228. category-keep Keep the default order of categories, corresponding to the
  1229. sequence in `org-agenda-files'.
  1230. category-up Sort alphabetically by category, A-Z.
  1231. category-down Sort alphabetically by category, Z-A.
  1232. tag-up Sort alphabetically by last tag, A-Z.
  1233. tag-down Sort alphabetically by last tag, Z-A.
  1234. priority-up Sort numerically by priority, high priority last.
  1235. priority-down Sort numerically by priority, high priority first.
  1236. todo-state-up Sort by todo state, tasks that are done last.
  1237. todo-state-down Sort by todo state, tasks that are done first.
  1238. effort-up Sort numerically by estimated effort, high effort last.
  1239. effort-down Sort numerically by estimated effort, high effort first.
  1240. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1241. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1242. habit-up Put entries that are habits first
  1243. habit-down Put entries that are habits last
  1244. alpha-up Sort headlines alphabetically
  1245. alpha-down Sort headlines alphabetically, reversed
  1246. The different possibilities will be tried in sequence, and testing stops
  1247. if one comparison returns a \"not-equal\". For example, the default
  1248. '(time-up category-keep priority-down)
  1249. means: Pull out all entries having a specified time of day and sort them,
  1250. in order to make a time schedule for the current day the first thing in the
  1251. agenda listing for the day. Of the entries without a time indication, keep
  1252. the grouped in categories, don't sort the categories, but keep them in
  1253. the sequence given in `org-agenda-files'. Within each category sort by
  1254. priority.
  1255. Leaving out `category-keep' would mean that items will be sorted across
  1256. categories by priority.
  1257. Instead of a single list, this can also be a set of list for specific
  1258. contents, with a context symbol in the car of the list, any of
  1259. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1260. Custom commands can bind this variable in the options section."
  1261. :group 'org-agenda-sorting
  1262. :type `(choice
  1263. (repeat :tag "General" ,org-sorting-choice)
  1264. (list :tag "Individually"
  1265. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1266. (repeat ,org-sorting-choice))
  1267. (cons (const :tag "Strategy for TODO lists" todo)
  1268. (repeat ,org-sorting-choice))
  1269. (cons (const :tag "Strategy for Tags matches" tags)
  1270. (repeat ,org-sorting-choice))
  1271. (cons (const :tag "Strategy for search matches" search)
  1272. (repeat ,org-sorting-choice)))))
  1273. (defcustom org-agenda-cmp-user-defined nil
  1274. "A function to define the comparison `user-defined'.
  1275. This function must receive two arguments, agenda entry a and b.
  1276. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1277. the user comparison, return nil.
  1278. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1279. part of an agenda sorting strategy."
  1280. :group 'org-agenda-sorting
  1281. :type 'symbol)
  1282. (defcustom org-sort-agenda-notime-is-late t
  1283. "Non-nil means items without time are considered late.
  1284. This is only relevant for sorting. When t, items which have no explicit
  1285. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1286. do have a time. When nil, the default time is before 0:00. You can use this
  1287. option to decide if the schedule for today should come before or after timeless
  1288. agenda entries."
  1289. :group 'org-agenda-sorting
  1290. :type 'boolean)
  1291. (defcustom org-sort-agenda-noeffort-is-high t
  1292. "Non-nil means items without effort estimate are sorted as high effort.
  1293. This also applies when filtering an agenda view with respect to the
  1294. < or > effort operator. Then, tasks with no effort defined will be treated
  1295. as tasks with high effort.
  1296. When nil, such items are sorted as 0 minutes effort."
  1297. :group 'org-agenda-sorting
  1298. :type 'boolean)
  1299. (defgroup org-agenda-line-format nil
  1300. "Options concerning the entry prefix in the Org-mode agenda display."
  1301. :tag "Org Agenda Line Format"
  1302. :group 'org-agenda)
  1303. (defcustom org-agenda-prefix-format
  1304. '((agenda . " %i %-12:c%?-12t% s")
  1305. (timeline . " % s")
  1306. (todo . " %i %-12:c")
  1307. (tags . " %i %-12:c")
  1308. (search . " %i %-12:c"))
  1309. "Format specifications for the prefix of items in the agenda views.
  1310. An alist with five entries, each for the different agenda types. The
  1311. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1312. The values are format strings.
  1313. This format works similar to a printf format, with the following meaning:
  1314. %c the category of the item, \"Diary\" for entries from the diary,
  1315. or as given by the CATEGORY keyword or derived from the file name
  1316. %e the effort required by the item
  1317. %l the level of the item (insert X space(s) if item is of level X)
  1318. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1319. %T the last tag of the item (ignore inherited tags, which come first)
  1320. %t the HH:MM time-of-day specification if one applies to the entry
  1321. %s Scheduling/Deadline information, a short string
  1322. %(expression) Eval EXPRESSION and replace the control string
  1323. by the result
  1324. All specifiers work basically like the standard `%s' of printf, but may
  1325. contain two additional characters: a question mark just after the `%'
  1326. and a whitespace/punctuation character just before the final letter.
  1327. If the first character after `%' is a question mark, the entire field
  1328. will only be included if the corresponding value applies to the current
  1329. entry. This is useful for fields which should have fixed width when
  1330. present, but zero width when absent. For example, \"%?-12t\" will
  1331. result in a 12 character time field if a time of the day is specified,
  1332. but will completely disappear in entries which do not contain a time.
  1333. If there is punctuation or whitespace character just before the final
  1334. format letter, this character will be appended to the field value if
  1335. the value is not empty. For example, the format \"%-12:c\" leads to
  1336. \"Diary: \" if the category is \"Diary\". If the category were be
  1337. empty, no additional colon would be inserted.
  1338. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1339. which means:
  1340. - Indent the line with two space characters
  1341. - Give the category a 12 chars wide field, padded with whitespace on
  1342. the right (because of `-'). Append a colon if there is a category
  1343. (because of `:').
  1344. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1345. time, don't put in an empty field, just skip it (because of '?').
  1346. - Finally, put the scheduling information.
  1347. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1348. `org-agenda-remove-tags'.
  1349. Custom commands can set this variable in the options section."
  1350. :type '(choice
  1351. (string :tag "General format")
  1352. (list :greedy t :tag "View dependent"
  1353. (cons (const agenda) (string :tag "Format"))
  1354. (cons (const timeline) (string :tag "Format"))
  1355. (cons (const todo) (string :tag "Format"))
  1356. (cons (const tags) (string :tag "Format"))
  1357. (cons (const search) (string :tag "Format"))))
  1358. :group 'org-agenda-line-format)
  1359. (defvar org-prefix-format-compiled nil
  1360. "The compiled prefix format and associated variables.
  1361. This is a list where first element is a list of variable bindings, and second
  1362. element is the compiled format expression. See the variable
  1363. `org-agenda-prefix-format'.")
  1364. (defcustom org-agenda-todo-keyword-format "%-1s"
  1365. "Format for the TODO keyword in agenda lines.
  1366. Set this to something like \"%-12s\" if you want all TODO keywords
  1367. to occupy a fixed space in the agenda display."
  1368. :group 'org-agenda-line-format
  1369. :type 'string)
  1370. (defcustom org-agenda-diary-sexp-prefix nil
  1371. "A regexp that matches part of a diary sexp entry
  1372. which should be treated as scheduling/deadline information in
  1373. `org-agenda'.
  1374. For example, you can use this to extract the `diary-remind-message' from
  1375. `diary-remind' entries."
  1376. :group 'org-agenda-line-format
  1377. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1378. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1379. "Text preceding timerange entries in the agenda view.
  1380. This is a list with two strings. The first applies when the range
  1381. is entirely on one day. The second applies if the range spans several days.
  1382. The strings may have two \"%d\" format specifiers which will be filled
  1383. with the sequence number of the days, and the total number of days in the
  1384. range, respectively."
  1385. :group 'org-agenda-line-format
  1386. :type '(list
  1387. (string :tag "Deadline today ")
  1388. (choice :tag "Deadline relative"
  1389. (string :tag "Format string")
  1390. (function))))
  1391. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1392. "Text preceding scheduled items in the agenda view.
  1393. This is a list with two strings. The first applies when the item is
  1394. scheduled on the current day. The second applies when it has been scheduled
  1395. previously, it may contain a %d indicating that this is the nth time that
  1396. this item is scheduled, due to automatic rescheduling of unfinished items
  1397. for the following day. So this number is one larger than the number of days
  1398. that passed since this item was scheduled first."
  1399. :group 'org-agenda-line-format
  1400. :type '(list
  1401. (string :tag "Scheduled today ")
  1402. (string :tag "Scheduled previously")))
  1403. (defcustom org-agenda-inactive-leader "["
  1404. "Text preceding item pulled into the agenda by inactive time stamps.
  1405. These entries are added to the agenda when pressing \"[\"."
  1406. :group 'org-agenda-line-format
  1407. :version "24.1"
  1408. :type '(list
  1409. (string :tag "Scheduled today ")
  1410. (string :tag "Scheduled previously")))
  1411. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1412. "Text preceding deadline items in the agenda view.
  1413. This is a list with two strings. The first applies when the item has its
  1414. deadline on the current day. The second applies when it is in the past or
  1415. in the future, it may contain %d to capture how many days away the deadline
  1416. is (was)."
  1417. :group 'org-agenda-line-format
  1418. :type '(list
  1419. (string :tag "Deadline today ")
  1420. (choice :tag "Deadline relative"
  1421. (string :tag "Format string")
  1422. (function))))
  1423. (defcustom org-agenda-remove-times-when-in-prefix t
  1424. "Non-nil means remove duplicate time specifications in agenda items.
  1425. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1426. time-of-day specification in a headline or diary entry is extracted and
  1427. placed into the prefix. If this option is non-nil, the original specification
  1428. \(a timestamp or -range, or just a plain time(range) specification like
  1429. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1430. cluttered.
  1431. The option can be t or nil. It may also be the symbol `beg', indicating
  1432. that the time should only be removed when it is located at the beginning of
  1433. the headline/diary entry."
  1434. :group 'org-agenda-line-format
  1435. :type '(choice
  1436. (const :tag "Always" t)
  1437. (const :tag "Never" nil)
  1438. (const :tag "When at beginning of entry" beg)))
  1439. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1440. "Non-nil means remove time ranges specifications in agenda
  1441. items that span on several days."
  1442. :group 'org-agenda-line-format
  1443. :version "24.1"
  1444. :type 'boolean)
  1445. (defcustom org-agenda-default-appointment-duration nil
  1446. "Default duration for appointments that only have a starting time.
  1447. When nil, no duration is specified in such cases.
  1448. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1449. :group 'org-agenda-line-format
  1450. :type '(choice
  1451. (integer :tag "Minutes")
  1452. (const :tag "No default duration")))
  1453. (defcustom org-agenda-show-inherited-tags t
  1454. "Non-nil means show inherited tags in each agenda line."
  1455. :group 'org-agenda-line-format
  1456. :type 'boolean)
  1457. (defcustom org-agenda-hide-tags-regexp nil
  1458. "Regular expression used to filter away specific tags in agenda views.
  1459. This means that these tags will be present, but not be shown in the agenda
  1460. line. Secondary filtering will still work on the hidden tags.
  1461. Nil means don't hide any tags."
  1462. :group 'org-agenda-line-format
  1463. :type '(choice
  1464. (const :tag "Hide none" nil)
  1465. (string :tag "Regexp ")))
  1466. (defcustom org-agenda-remove-tags nil
  1467. "Non-nil means remove the tags from the headline copy in the agenda.
  1468. When this is the symbol `prefix', only remove tags when
  1469. `org-agenda-prefix-format' contains a `%T' specifier."
  1470. :group 'org-agenda-line-format
  1471. :type '(choice
  1472. (const :tag "Always" t)
  1473. (const :tag "Never" nil)
  1474. (const :tag "When prefix format contains %T" prefix)))
  1475. (if (fboundp 'defvaralias)
  1476. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1477. 'org-agenda-remove-tags))
  1478. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1479. "Shift tags in agenda items to this column.
  1480. If this number is positive, it specifies the column. If it is negative,
  1481. it means that the tags should be flushright to that column. For example,
  1482. -80 works well for a normal 80 character screen."
  1483. :group 'org-agenda-line-format
  1484. :type 'integer)
  1485. (if (fboundp 'defvaralias)
  1486. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1487. (defcustom org-agenda-fontify-priorities 'cookies
  1488. "Non-nil means highlight low and high priorities in agenda.
  1489. When t, the highest priority entries are bold, lowest priority italic.
  1490. However, settings in `org-priority-faces' will overrule these faces.
  1491. When this variable is the symbol `cookies', only fontify the
  1492. cookies, not the entire task.
  1493. This may also be an association list of priority faces, whose
  1494. keys are the character values of `org-highest-priority',
  1495. `org-default-priority', and `org-lowest-priority' (the default values
  1496. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1497. color as a string, or a list like `(:background \"Red\")'.
  1498. If it is a color, the variable `org-faces-easy-properties'
  1499. determines if it is a foreground or a background color."
  1500. :group 'org-agenda-line-format
  1501. :type '(choice
  1502. (const :tag "Never" nil)
  1503. (const :tag "Defaults" t)
  1504. (const :tag "Cookies only" cookies)
  1505. (repeat :tag "Specify"
  1506. (list (character :tag "Priority" :value ?A)
  1507. (choice :tag "Face "
  1508. (string :tag "Color")
  1509. (sexp :tag "Face"))))))
  1510. (defcustom org-agenda-day-face-function nil
  1511. "Function called to determine what face should be used to display a day.
  1512. The only argument passed to that function is the day. It should
  1513. returns a face, or nil if does not want to specify a face and let
  1514. the normal rules apply."
  1515. :group 'org-agenda-line-format
  1516. :version "24.1"
  1517. :type 'function)
  1518. (defcustom org-agenda-category-icon-alist nil
  1519. "Alist of category icon to be displayed in agenda views.
  1520. Each entry should have the following format:
  1521. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1522. Where CATEGORY-REGEXP is a regexp matching the categories where
  1523. the icon should be displayed.
  1524. FILE-OR-DATA either a file path or a string containing image data.
  1525. The other fields can be omitted safely if not needed:
  1526. TYPE indicates the image type.
  1527. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1528. image data.
  1529. PROPS are additional image attributes to assign to the image,
  1530. like, e.g. `:ascent center'.
  1531. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1532. If you want to set the display properties yourself, just put a
  1533. list as second element:
  1534. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1535. For example, to display a 16px horizontal space for Emacs
  1536. category, you can use:
  1537. (\"Emacs\" '(space . (:width (16))))"
  1538. :group 'org-agenda-line-format
  1539. :version "24.1"
  1540. :type '(alist :key-type (string :tag "Regexp matching category")
  1541. :value-type (choice (list :tag "Icon"
  1542. (string :tag "File or data")
  1543. (symbol :tag "Type")
  1544. (boolean :tag "Data?")
  1545. (repeat :tag "Extra image properties" :inline t symbol))
  1546. (list :tag "Display properties" sexp))))
  1547. (defgroup org-agenda-column-view nil
  1548. "Options concerning column view in the agenda."
  1549. :tag "Org Agenda Column View"
  1550. :group 'org-agenda)
  1551. (defcustom org-agenda-columns-show-summaries t
  1552. "Non-nil means show summaries for columns displayed in the agenda view."
  1553. :group 'org-agenda-column-view
  1554. :type 'boolean)
  1555. (defcustom org-agenda-columns-compute-summary-properties t
  1556. "Non-nil means recompute all summary properties before column view.
  1557. When column view in the agenda is listing properties that have a summary
  1558. operator, it can go to all relevant buffers and recompute the summaries
  1559. there. This can mean overhead for the agenda column view, but is necessary
  1560. to have thing up to date.
  1561. As a special case, a CLOCKSUM property also makes sure that the clock
  1562. computations are current."
  1563. :group 'org-agenda-column-view
  1564. :type 'boolean)
  1565. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1566. "Non-nil means the duration of an appointment will add to day effort.
  1567. The property to which appointment durations will be added is the one given
  1568. in the option `org-effort-property'. If an appointment does not have
  1569. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1570. is not set, an appointment without end time will not contribute to the time
  1571. estimate."
  1572. :group 'org-agenda-column-view
  1573. :type 'boolean)
  1574. (defcustom org-agenda-auto-exclude-function nil
  1575. "A function called with a tag to decide if it is filtered on '/ RET'.
  1576. The sole argument to the function, which is called once for each
  1577. possible tag, is a string giving the name of the tag. The
  1578. function should return either nil if the tag should be included
  1579. as normal, or \"-<TAG>\" to exclude the tag.
  1580. Note that for the purpose of tag filtering, only the lower-case version of
  1581. all tags will be considered, so that this function will only ever see
  1582. the lower-case version of all tags."
  1583. :group 'org-agenda
  1584. :type 'function)
  1585. (defcustom org-agenda-bulk-custom-functions nil
  1586. "Alist of characters and custom functions for bulk actions.
  1587. For example, this value makes those two functions available:
  1588. '((?R set-category)
  1589. (?C bulk-cut))
  1590. With selected entries in an agenda buffer, `B R' will call
  1591. the custom function `set-category' on the selected entries.
  1592. Note that functions in this alist don't need to be quoted."
  1593. :type 'alist
  1594. :version "24.1"
  1595. :group 'org-agenda)
  1596. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1597. "Execute BODY with point at location given by `org-hd-marker' property.
  1598. If STRING is non-nil, the text property will be fetched from position 0
  1599. in that string. If STRING is nil, it will be fetched from the beginning
  1600. of the current line."
  1601. (org-with-gensyms (marker)
  1602. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1603. 'org-hd-marker ,string)))
  1604. (with-current-buffer (marker-buffer ,marker)
  1605. (save-excursion
  1606. (goto-char ,marker)
  1607. ,@body)))))
  1608. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1609. (defun org-add-agenda-custom-command (entry)
  1610. "Replace or add a command in `org-agenda-custom-commands'.
  1611. This is mostly for hacking and trying a new command - once the command
  1612. works you probably want to add it to `org-agenda-custom-commands' for good."
  1613. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1614. (if ass
  1615. (setcdr ass (cdr entry))
  1616. (push entry org-agenda-custom-commands))))
  1617. ;;; Define the org-agenda-mode
  1618. (defvar org-agenda-mode-map (make-sparse-keymap)
  1619. "Keymap for `org-agenda-mode'.")
  1620. (if (fboundp 'defvaralias)
  1621. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1622. (defvar org-agenda-menu) ; defined later in this file.
  1623. (defvar org-agenda-restrict nil) ; defined later in this file.
  1624. (defvar org-agenda-follow-mode nil)
  1625. (defvar org-agenda-entry-text-mode nil)
  1626. (defvar org-agenda-clockreport-mode nil)
  1627. (defvar org-agenda-show-log nil)
  1628. (defvar org-agenda-redo-command nil)
  1629. (defvar org-agenda-query-string nil)
  1630. (defvar org-agenda-mode-hook nil
  1631. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1632. (defvar org-agenda-type nil)
  1633. (defvar org-agenda-force-single-file nil)
  1634. (defvar org-agenda-bulk-marked-entries nil
  1635. "List of markers that refer to marked entries in the agenda.")
  1636. ;;; Multiple agenda buffers support
  1637. (defcustom org-agenda-sticky nil
  1638. "Non-nil means agenda q key will bury agenda buffers.
  1639. Agenda commands will then show existing buffer instead of generating new ones.
  1640. When nil, `q' will kill the single agenda buffer."
  1641. :group 'org-agenda
  1642. :type 'boolean
  1643. :set (lambda (var val)
  1644. (if (boundp var)
  1645. (org-toggle-sticky-agenda (if val 1 0))
  1646. (set var val))))
  1647. ;;;###autoload
  1648. (defun org-toggle-sticky-agenda (&optional arg)
  1649. "Toggle `org-agenda-sticky'."
  1650. (interactive "P")
  1651. (let ((new-value (if arg
  1652. (> (prefix-numeric-value arg) 0)
  1653. (not org-agenda-sticky))))
  1654. (if (equal new-value org-agenda-sticky)
  1655. (and (org-called-interactively-p 'interactive)
  1656. (message "Sticky agenda was already %s"
  1657. (if org-agenda-sticky "enabled" "disabled")))
  1658. (setq org-agenda-sticky new-value)
  1659. (org-agenda-kill-all-agenda-buffers)
  1660. (and (org-called-interactively-p 'interactive)
  1661. (message "Sticky agenda was %s"
  1662. (if org-agenda-sticky "enabled" "disabled"))))))
  1663. (defvar org-agenda-buffer nil
  1664. "Agenda buffer currently being generated.")
  1665. (defvar org-agenda-last-prefix-arg nil)
  1666. (defvar org-agenda-this-buffer-name nil)
  1667. (defvar org-agenda-doing-sticky-redo nil)
  1668. (defvar org-agenda-this-buffer-is-sticky nil)
  1669. (defconst org-agenda-local-vars
  1670. '(org-agenda-this-buffer-name
  1671. org-agenda-undo-list
  1672. org-agenda-pending-undo-list
  1673. org-agenda-follow-mode
  1674. org-agenda-entry-text-mode
  1675. org-agenda-clockreport-mode
  1676. org-agenda-show-log
  1677. org-agenda-redo-command
  1678. org-agenda-query-string
  1679. org-agenda-type
  1680. org-agenda-bulk-marked-entries
  1681. org-agenda-undo-has-started-in
  1682. org-agenda-info
  1683. org-agenda-tag-filter-overlays
  1684. org-agenda-cat-filter-overlays
  1685. org-agenda-pre-window-conf
  1686. org-agenda-columns-active
  1687. org-agenda-tag-filter
  1688. org-agenda-category-filter
  1689. org-agenda-markers
  1690. org-agenda-last-search-view-search-was-boolean
  1691. org-agenda-filtered-by-category
  1692. org-agenda-filter-form
  1693. org-agenda-show-window
  1694. org-agenda-cycle-counter
  1695. org-agenda-last-prefix-arg)
  1696. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1697. (defun org-agenda-mode ()
  1698. "Mode for time-sorted view on action items in Org-mode files.
  1699. The following commands are available:
  1700. \\{org-agenda-mode-map}"
  1701. (interactive)
  1702. (cond (org-agenda-doing-sticky-redo
  1703. ;; Refreshing sticky agenda-buffer
  1704. ;;
  1705. ;; Preserve the value of `org-agenda-local-vars' variables,
  1706. ;; while letting `kill-all-local-variables' kill the rest
  1707. (let ((save (buffer-local-variables)))
  1708. (kill-all-local-variables)
  1709. (mapc 'make-local-variable org-agenda-local-vars)
  1710. (dolist (elem save)
  1711. (let ((var (car elem))
  1712. (val (cdr elem)))
  1713. (when (and val
  1714. (member var org-agenda-local-vars))
  1715. (set var val)))))
  1716. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1717. (org-agenda-sticky
  1718. ;; Creating a sticky Agenda buffer for the first time
  1719. (kill-all-local-variables)
  1720. (mapc 'make-local-variable org-agenda-local-vars)
  1721. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1722. (t
  1723. ;; Creating a non-sticky agenda buffer
  1724. (kill-all-local-variables)
  1725. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1726. (setq org-agenda-undo-list nil
  1727. org-agenda-pending-undo-list nil
  1728. org-agenda-bulk-marked-entries nil)
  1729. (setq major-mode 'org-agenda-mode)
  1730. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1731. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1732. (setq mode-name "Org-Agenda")
  1733. (use-local-map org-agenda-mode-map)
  1734. (easy-menu-add org-agenda-menu)
  1735. (if org-startup-truncated (setq truncate-lines t))
  1736. (org-set-local 'line-move-visual nil)
  1737. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1738. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1739. ;; Make sure properties are removed when copying text
  1740. (make-local-variable 'filter-buffer-substring-functions)
  1741. (add-hook 'filter-buffer-substring-functions
  1742. (lambda (fun start end delete)
  1743. (substring-no-properties (funcall fun start end delete))))
  1744. (unless org-agenda-keep-modes
  1745. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1746. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1747. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1748. org-agenda-show-log org-agenda-start-with-log-mode))
  1749. (easy-menu-change
  1750. '("Agenda") "Agenda Files"
  1751. (append
  1752. (list
  1753. (vector
  1754. (if (get 'org-agenda-files 'org-restrict)
  1755. "Restricted to single file"
  1756. "Edit File List")
  1757. '(org-edit-agenda-file-list)
  1758. (not (get 'org-agenda-files 'org-restrict)))
  1759. "--")
  1760. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1761. (org-agenda-set-mode-name)
  1762. (apply
  1763. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1764. (list 'org-agenda-mode-hook)))
  1765. (substitute-key-definition 'undo 'org-agenda-undo
  1766. org-agenda-mode-map global-map)
  1767. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1768. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1769. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1770. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1771. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1772. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1773. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1774. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1775. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1776. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1777. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1778. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1779. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1780. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1781. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1782. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1783. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1784. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1785. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1786. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1787. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1788. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1789. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1790. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1791. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1792. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1794. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1795. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1796. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1797. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1798. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1799. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1800. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1801. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1802. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1803. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1804. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1805. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1806. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1807. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1808. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1809. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1810. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1811. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1812. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1813. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1814. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1815. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1816. (while l (org-defkey org-agenda-mode-map
  1817. (int-to-string (pop l)) 'digit-argument)))
  1818. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1819. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1820. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1821. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1822. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1823. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1824. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1825. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1826. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1827. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1828. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1829. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1830. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1831. 'org-clock-modify-effort-estimate)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1833. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1834. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1835. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1836. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1837. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1838. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1839. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1840. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1841. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1842. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1843. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1844. (substitute-key-definition 'next-line 'org-agenda-next-line
  1845. org-agenda-mode-map global-map)
  1846. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1847. org-agenda-mode-map global-map)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1849. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1850. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1851. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1852. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
  1853. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1854. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1855. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1856. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1857. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1858. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1859. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1860. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1861. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1862. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1863. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1864. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1865. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1866. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1867. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1868. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1869. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1870. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1871. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1872. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1873. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1874. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1875. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1877. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1878. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1879. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1880. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1881. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1882. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1883. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1884. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1885. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1886. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1887. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1888. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1889. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1890. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1891. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1892. (when org-agenda-mouse-1-follows-link
  1893. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1894. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1895. '("Agenda"
  1896. ("Agenda Files")
  1897. "--"
  1898. ("Agenda Dates"
  1899. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1900. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1901. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1902. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1903. "--"
  1904. ("View"
  1905. ["Day View" org-agenda-day-view
  1906. :active (org-agenda-check-type nil 'agenda)
  1907. :style radio :selected (eq org-agenda-current-span 'day)
  1908. :keys "v d (or just d)"]
  1909. ["Week View" org-agenda-week-view
  1910. :active (org-agenda-check-type nil 'agenda)
  1911. :style radio :selected (eq org-agenda-current-span 'week)
  1912. :keys "v w (or just w)"]
  1913. ["Month View" org-agenda-month-view
  1914. :active (org-agenda-check-type nil 'agenda)
  1915. :style radio :selected (eq org-agenda-current-span 'month)
  1916. :keys "v m"]
  1917. ["Year View" org-agenda-year-view
  1918. :active (org-agenda-check-type nil 'agenda)
  1919. :style radio :selected (eq org-agenda-current-span 'year)
  1920. :keys "v y"]
  1921. "--"
  1922. ["Include Diary" org-agenda-toggle-diary
  1923. :style toggle :selected org-agenda-include-diary
  1924. :active (org-agenda-check-type nil 'agenda)]
  1925. ["Include Deadlines" org-agenda-toggle-deadlines
  1926. :style toggle :selected org-agenda-include-deadlines
  1927. :active (org-agenda-check-type nil 'agenda)]
  1928. ["Use Time Grid" org-agenda-toggle-time-grid
  1929. :style toggle :selected org-agenda-use-time-grid
  1930. :active (org-agenda-check-type nil 'agenda)]
  1931. "--"
  1932. ["Show clock report" org-agenda-clockreport-mode
  1933. :style toggle :selected org-agenda-clockreport-mode
  1934. :active (org-agenda-check-type nil 'agenda)]
  1935. ["Show some entry text" org-agenda-entry-text-mode
  1936. :style toggle :selected org-agenda-entry-text-mode
  1937. :active t]
  1938. "--"
  1939. ["Show Logbook entries" org-agenda-log-mode
  1940. :style toggle :selected org-agenda-show-log
  1941. :active (org-agenda-check-type nil 'agenda 'timeline)
  1942. :keys "v l (or just l)"]
  1943. ["Include archived trees" org-agenda-archives-mode
  1944. :style toggle :selected org-agenda-archives-mode :active t
  1945. :keys "v a"]
  1946. ["Include archive files" (org-agenda-archives-mode t)
  1947. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1948. :keys "v A"]
  1949. "--"
  1950. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1951. ["Write view to file" org-agenda-write t]
  1952. ["Rebuild buffer" org-agenda-redo t]
  1953. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1954. "--"
  1955. ["Show original entry" org-agenda-show t]
  1956. ["Go To (other window)" org-agenda-goto t]
  1957. ["Go To (this window)" org-agenda-switch-to t]
  1958. ["Capture with cursor date" org-agenda-capture t]
  1959. ["Follow Mode" org-agenda-follow-mode
  1960. :style toggle :selected org-agenda-follow-mode :active t]
  1961. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1962. "--"
  1963. ("TODO"
  1964. ["Cycle TODO" org-agenda-todo t]
  1965. ["Next TODO set" org-agenda-todo-nextset t]
  1966. ["Previous TODO set" org-agenda-todo-previousset t]
  1967. ["Add note" org-agenda-add-note t])
  1968. ("Archive/Refile/Delete"
  1969. ["Archive default" org-agenda-archive-default t]
  1970. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1971. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1972. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1973. ["Archive subtree" org-agenda-archive t]
  1974. "--"
  1975. ["Refile" org-agenda-refile t]
  1976. "--"
  1977. ["Delete subtree" org-agenda-kill t])
  1978. ("Bulk action"
  1979. ["Mark entry" org-agenda-bulk-mark t]
  1980. ["Mark all" org-agenda-bulk-mark-all t]
  1981. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1982. ["Unmark entry" org-agenda-bulk-unmark t]
  1983. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  1984. ["Act on all marked" org-agenda-bulk-action t]
  1985. "--"
  1986. ("Tags and Properties"
  1987. ["Show all Tags" org-agenda-show-tags t]
  1988. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1989. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1990. "--"
  1991. ["Column View" org-columns t])
  1992. ("Deadline/Schedule"
  1993. ["Schedule" org-agenda-schedule t]
  1994. ["Set Deadline" org-agenda-deadline t]
  1995. "--"
  1996. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1997. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1998. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1999. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2000. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2001. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2002. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2003. ("Clock and Effort"
  2004. ["Clock in" org-agenda-clock-in t]
  2005. ["Clock out" org-agenda-clock-out t]
  2006. ["Clock cancel" org-agenda-clock-cancel t]
  2007. ["Goto running clock" org-clock-goto t]
  2008. "--"
  2009. ["Set Effort" org-agenda-set-effort t]
  2010. ["Change clocked effort" org-clock-modify-effort-estimate
  2011. (org-clock-is-active)])
  2012. ("Priority"
  2013. ["Set Priority" org-agenda-priority t]
  2014. ["Increase Priority" org-agenda-priority-up t]
  2015. ["Decrease Priority" org-agenda-priority-down t]
  2016. ["Show Priority" org-agenda-show-priority t])
  2017. ("Calendar/Diary"
  2018. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2019. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2020. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2021. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2022. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2023. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2024. "--"
  2025. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2026. "--"
  2027. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2028. "--"
  2029. ("MobileOrg"
  2030. ["Push Files and Views" org-mobile-push t]
  2031. ["Get Captured and Flagged" org-mobile-pull t]
  2032. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2033. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2034. "--"
  2035. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2036. "--"
  2037. ["Quit" org-agenda-quit t]
  2038. ["Exit and Release Buffers" org-agenda-exit t]
  2039. ))
  2040. ;;; Agenda undo
  2041. (defvar org-agenda-allow-remote-undo t
  2042. "Non-nil means allow remote undo from the agenda buffer.")
  2043. (defvar org-agenda-undo-has-started-in nil
  2044. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2045. (defun org-agenda-undo ()
  2046. "Undo a remote editing step in the agenda.
  2047. This undoes changes both in the agenda buffer and in the remote buffer
  2048. that have been changed along."
  2049. (interactive)
  2050. (or org-agenda-allow-remote-undo
  2051. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2052. (if (not (eq this-command last-command))
  2053. (setq org-agenda-undo-has-started-in nil
  2054. org-agenda-pending-undo-list org-agenda-undo-list))
  2055. (if (not org-agenda-pending-undo-list)
  2056. (error "No further undo information"))
  2057. (let* ((entry (pop org-agenda-pending-undo-list))
  2058. buf line cmd rembuf)
  2059. (setq cmd (pop entry) line (pop entry))
  2060. (setq rembuf (nth 2 entry))
  2061. (org-with-remote-undo rembuf
  2062. (while (bufferp (setq buf (pop entry)))
  2063. (if (pop entry)
  2064. (with-current-buffer buf
  2065. (let ((last-undo-buffer buf)
  2066. (inhibit-read-only t))
  2067. (unless (memq buf org-agenda-undo-has-started-in)
  2068. (push buf org-agenda-undo-has-started-in)
  2069. (make-local-variable 'pending-undo-list)
  2070. (undo-start))
  2071. (while (and pending-undo-list
  2072. (listp pending-undo-list)
  2073. (not (car pending-undo-list)))
  2074. (pop pending-undo-list))
  2075. (undo-more 1))))))
  2076. (org-goto-line line)
  2077. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2078. (defun org-verify-change-for-undo (l1 l2)
  2079. "Verify that a real change occurred between the undo lists L1 and L2."
  2080. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2081. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2082. (not (eq l1 l2)))
  2083. ;;; Agenda dispatch
  2084. (defvar org-agenda-restrict-begin (make-marker))
  2085. (defvar org-agenda-restrict-end (make-marker))
  2086. (defvar org-agenda-last-dispatch-buffer nil)
  2087. (defvar org-agenda-overriding-restriction nil)
  2088. (defcustom org-agenda-custom-commands-contexts nil
  2089. "Alist of custom agenda keys and contextual rules.
  2090. For example, if you have a custom agenda command \"p\" and you
  2091. want this command to be accessible only from plain text files,
  2092. use this:
  2093. '((\"p\" (in-file . \"\\.txt\")))
  2094. Here are the available contexts definitions:
  2095. in-file: command displayed only in matching files
  2096. in-mode: command displayed only in matching modes
  2097. not-in-file: command not displayed in matching files
  2098. not-in-mode: command not displayed in matching modes
  2099. [function]: a custom function taking no argument
  2100. If you define several checks, the agenda command will be
  2101. accessible if there is at least one valid check.
  2102. You can also bind a key to another agenda custom command
  2103. depending on contextual rules.
  2104. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2105. Here it means: in .txt files, use \"p\" as the key for the
  2106. agenda command otherwise associated with \"q\". (The command
  2107. originally associated with \"q\" is not displayed to avoid
  2108. duplicates.)"
  2109. ;; :version "24.3"
  2110. :group 'org-agenda-custom-commands
  2111. :type '(repeat (list :tag "Rule"
  2112. (string :tag " Agenda key")
  2113. (string :tag "Replace by command")
  2114. (repeat :tag "Available when"
  2115. (choice
  2116. (cons :tag "Condition"
  2117. (choice
  2118. (const :tag "In file" in-file)
  2119. (const :tag "Not in file" not-in-file)
  2120. (const :tag "In mode" in-mode)
  2121. (const :tag "Not in mode" not-in-mode))
  2122. (regexp))
  2123. (function :tag "Custom function"))))))
  2124. (defvar org-keys nil)
  2125. (defvar org-match nil)
  2126. ;;;###autoload
  2127. (defun org-agenda (&optional arg org-keys restriction)
  2128. "Dispatch agenda commands to collect entries to the agenda buffer.
  2129. Prompts for a command to execute. Any prefix arg will be passed
  2130. on to the selected command. The default selections are:
  2131. a Call `org-agenda-list' to display the agenda for current day or week.
  2132. t Call `org-todo-list' to display the global todo list.
  2133. T Call `org-todo-list' to display the global todo list, select only
  2134. entries with a specific TODO keyword (the user gets a prompt).
  2135. m Call `org-tags-view' to display headlines with tags matching
  2136. a condition (the user is prompted for the condition).
  2137. M Like `m', but select only TODO entries, no ordinary headlines.
  2138. L Create a timeline for the current buffer.
  2139. e Export views to associated files.
  2140. s Search entries for keywords.
  2141. S Search entries for keywords, only with TODO keywords.
  2142. / Multi occur across all agenda files and also files listed
  2143. in `org-agenda-text-search-extra-files'.
  2144. < Restrict agenda commands to buffer, subtree, or region.
  2145. Press several times to get the desired effect.
  2146. > Remove a previous restriction.
  2147. # List \"stuck\" projects.
  2148. ! Configure what \"stuck\" means.
  2149. C Configure custom agenda commands.
  2150. More commands can be added by configuring the variable
  2151. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2152. searches can be pre-defined in this way.
  2153. If the current buffer is in Org-mode and visiting a file, you can also
  2154. first press `<' once to indicate that the agenda should be temporarily
  2155. \(until the next use of \\[org-agenda]) restricted to the current file.
  2156. Pressing `<' twice means to restrict to the current subtree or region
  2157. \(if active)."
  2158. (interactive "P")
  2159. (catch 'exit
  2160. (let* ((prefix-descriptions nil)
  2161. (org-agenda-buffer-name org-agenda-buffer-name)
  2162. (org-agenda-window-setup (if (equal (buffer-name)
  2163. org-agenda-buffer-name)
  2164. 'current-window
  2165. org-agenda-window-setup))
  2166. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2167. (org-agenda-custom-commands
  2168. ;; normalize different versions
  2169. (delq nil
  2170. (mapcar
  2171. (lambda (x)
  2172. (cond ((stringp (cdr x))
  2173. (push x prefix-descriptions)
  2174. nil)
  2175. ((stringp (nth 1 x)) x)
  2176. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2177. (t (cons (car x) (cons "" (cdr x))))))
  2178. org-agenda-custom-commands)))
  2179. (org-agenda-custom-commands
  2180. (org-contextualize-keys
  2181. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2182. (buf (current-buffer))
  2183. (bfn (buffer-file-name (buffer-base-buffer)))
  2184. entry key type org-match lprops ans)
  2185. ;; Turn off restriction unless there is an overriding one,
  2186. (unless org-agenda-overriding-restriction
  2187. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2188. ;; There is a request to keep the file list in place
  2189. (put 'org-agenda-files 'org-restrict nil))
  2190. (setq org-agenda-restrict nil)
  2191. (move-marker org-agenda-restrict-begin nil)
  2192. (move-marker org-agenda-restrict-end nil))
  2193. ;; Delete old local properties
  2194. (put 'org-agenda-redo-command 'org-lprops nil)
  2195. ;; Delete previously set last-arguments
  2196. (put 'org-agenda-redo-command 'last-args nil)
  2197. ;; Remember where this call originated
  2198. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2199. (unless org-keys
  2200. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2201. org-keys (car ans)
  2202. restriction (cdr ans)))
  2203. ;; If we have sticky agenda buffers, set a name for the buffer,
  2204. ;; depending on the invoking keys. The user may still set this
  2205. ;; as a command option, which will overwrite what we do here.
  2206. (if org-agenda-sticky
  2207. (setq org-agenda-buffer-name
  2208. (format "*Org Agenda(%s)*" org-keys)))
  2209. ;; Establish the restriction, if any
  2210. (when (and (not org-agenda-overriding-restriction) restriction)
  2211. (put 'org-agenda-files 'org-restrict (list bfn))
  2212. (cond
  2213. ((eq restriction 'region)
  2214. (setq org-agenda-restrict t)
  2215. (move-marker org-agenda-restrict-begin (region-beginning))
  2216. (move-marker org-agenda-restrict-end (region-end)))
  2217. ((eq restriction 'subtree)
  2218. (save-excursion
  2219. (setq org-agenda-restrict t)
  2220. (org-back-to-heading t)
  2221. (move-marker org-agenda-restrict-begin (point))
  2222. (move-marker org-agenda-restrict-end
  2223. (progn (org-end-of-subtree t)))))))
  2224. ;; For example the todo list should not need it (but does...)
  2225. (cond
  2226. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2227. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2228. (progn
  2229. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2230. lprops (nth 4 entry))
  2231. (if org-agenda-sticky
  2232. (setq org-agenda-buffer-name
  2233. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2234. (format "*Org Agenda(%s)*" org-keys))))
  2235. (put 'org-agenda-redo-command 'org-lprops lprops)
  2236. (cond
  2237. ((eq type 'agenda)
  2238. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2239. ((eq type 'alltodo)
  2240. (org-let lprops '(org-todo-list current-prefix-arg)))
  2241. ((eq type 'search)
  2242. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2243. ((eq type 'stuck)
  2244. (org-let lprops '(org-agenda-list-stuck-projects
  2245. current-prefix-arg)))
  2246. ((eq type 'tags)
  2247. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2248. ((eq type 'tags-todo)
  2249. (org-let lprops '(org-tags-view '(4) org-match)))
  2250. ((eq type 'todo)
  2251. (org-let lprops '(org-todo-list org-match)))
  2252. ((eq type 'tags-tree)
  2253. (org-check-for-org-mode)
  2254. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2255. ((eq type 'todo-tree)
  2256. (org-check-for-org-mode)
  2257. (org-let lprops
  2258. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2259. (regexp-quote org-match) "\\>"))))
  2260. ((eq type 'occur-tree)
  2261. (org-check-for-org-mode)
  2262. (org-let lprops '(org-occur org-match)))
  2263. ((functionp type)
  2264. (org-let lprops '(funcall type org-match)))
  2265. ((fboundp type)
  2266. (org-let lprops '(funcall type org-match)))
  2267. (t (error "Invalid custom agenda command type %s" type))))
  2268. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2269. ((equal org-keys "C")
  2270. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2271. (customize-variable 'org-agenda-custom-commands))
  2272. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2273. ((equal org-keys "s") (call-interactively 'org-search-view))
  2274. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2275. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2276. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2277. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2278. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2279. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2280. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2281. (org-add-hook
  2282. 'post-command-hook
  2283. (lambda ()
  2284. (unless (current-message)
  2285. (let* ((m (org-agenda-get-any-marker))
  2286. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2287. (when note
  2288. (message (concat
  2289. "FLAGGING-NOTE ([?] for more info): "
  2290. (org-add-props
  2291. (replace-regexp-in-string
  2292. "\\\\n" "//"
  2293. (copy-sequence note))
  2294. nil 'face 'org-warning)))))))
  2295. t t))
  2296. ((equal org-keys "L")
  2297. (unless (derived-mode-p 'org-mode)
  2298. (error "This is not an Org-mode file"))
  2299. (unless restriction
  2300. (put 'org-agenda-files 'org-restrict (list bfn))
  2301. (org-call-with-arg 'org-timeline arg)))
  2302. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2303. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2304. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2305. (t (error "Invalid agenda key"))))))
  2306. (defun org-agenda-append-agenda ()
  2307. "Append another agenda view to the current one.
  2308. This function allows interactive building of block agendas.
  2309. Agenda views are separated by `org-agenda-block-separator'."
  2310. (interactive)
  2311. (unless (derived-mode-p 'org-agenda-mode)
  2312. (error "Can only append from within agenda buffer"))
  2313. (let ((org-agenda-multi t))
  2314. (org-agenda)
  2315. (widen)
  2316. (org-agenda-finalize)
  2317. (org-agenda-fit-window-to-buffer)))
  2318. (defun org-agenda-normalize-custom-commands (cmds)
  2319. (delq nil
  2320. (mapcar
  2321. (lambda (x)
  2322. (cond ((stringp (cdr x)) nil)
  2323. ((stringp (nth 1 x)) x)
  2324. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2325. (t (cons (car x) (cons "" (cdr x))))))
  2326. cmds)))
  2327. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2328. "The user interface for selecting an agenda command."
  2329. (catch 'exit
  2330. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2331. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2332. (region-p (org-region-active-p))
  2333. (custom org-agenda-custom-commands)
  2334. (selstring "")
  2335. restriction second-time
  2336. c entry key type match prefixes rmheader header-end custom1 desc
  2337. line lines left right n n1)
  2338. (save-window-excursion
  2339. (delete-other-windows)
  2340. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2341. (erase-buffer)
  2342. (insert (eval-when-compile
  2343. (let ((header
  2344. "Press key for an agenda command: < Buffer, subtree/region restriction
  2345. -------------------------------- > Remove restriction
  2346. a Agenda for current week or day e Export agenda views
  2347. t List of all TODO entries T Entries with special TODO kwd
  2348. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2349. s Search for keywords S Like s, but only TODO entries
  2350. L Timeline for current buffer # List stuck projects (!=configure)
  2351. / Multi-occur C Configure custom agenda commands
  2352. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2353. ")
  2354. (start 0))
  2355. (while (string-match
  2356. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2357. header start)
  2358. (setq start (match-end 0))
  2359. (add-text-properties (match-beginning 2) (match-end 2)
  2360. '(face bold) header))
  2361. header)))
  2362. (setq header-end (move-marker (make-marker) (point)))
  2363. (while t
  2364. (setq custom1 custom)
  2365. (when (eq rmheader t)
  2366. (org-goto-line 1)
  2367. (re-search-forward ":" nil t)
  2368. (delete-region (match-end 0) (point-at-eol))
  2369. (forward-char 1)
  2370. (looking-at "-+")
  2371. (delete-region (match-end 0) (point-at-eol))
  2372. (move-marker header-end (match-end 0)))
  2373. (goto-char header-end)
  2374. (delete-region (point) (point-max))
  2375. ;; Produce all the lines that describe custom commands and prefixes
  2376. (setq lines nil)
  2377. (while (setq entry (pop custom1))
  2378. (setq key (car entry) desc (nth 1 entry)
  2379. type (nth 2 entry)
  2380. match (nth 3 entry))
  2381. (if (> (length key) 1)
  2382. (add-to-list 'prefixes (string-to-char key))
  2383. (setq line
  2384. (format
  2385. "%-4s%-14s"
  2386. (org-add-props (copy-sequence key)
  2387. '(face bold))
  2388. (cond
  2389. ((string-match "\\S-" desc) desc)
  2390. ((eq type 'agenda) "Agenda for current week or day")
  2391. ((eq type 'alltodo) "List of all TODO entries")
  2392. ((eq type 'search) "Word search")
  2393. ((eq type 'stuck) "List of stuck projects")
  2394. ((eq type 'todo) "TODO keyword")
  2395. ((eq type 'tags) "Tags query")
  2396. ((eq type 'tags-todo) "Tags (TODO)")
  2397. ((eq type 'tags-tree) "Tags tree")
  2398. ((eq type 'todo-tree) "TODO kwd tree")
  2399. ((eq type 'occur-tree) "Occur tree")
  2400. ((functionp type) (if (symbolp type)
  2401. (symbol-name type)
  2402. "Lambda expression"))
  2403. (t "???"))))
  2404. (if org-agenda-menu-show-matcher
  2405. (setq line
  2406. (concat line ": "
  2407. (cond
  2408. ((stringp match)
  2409. (setq match (copy-sequence match))
  2410. (org-add-props match nil 'face 'org-warning))
  2411. (match
  2412. (format "set of %d commands" (length match)))
  2413. (t ""))))
  2414. (if (org-string-nw-p match)
  2415. (add-text-properties
  2416. 0 (length line) (list 'help-echo
  2417. (concat "Matcher: "match)) line)))
  2418. (push line lines)))
  2419. (setq lines (nreverse lines))
  2420. (when prefixes
  2421. (mapc (lambda (x)
  2422. (push
  2423. (format "%s %s"
  2424. (org-add-props (char-to-string x)
  2425. nil 'face 'bold)
  2426. (or (cdr (assoc (concat selstring
  2427. (char-to-string x))
  2428. prefix-descriptions))
  2429. "Prefix key"))
  2430. lines))
  2431. prefixes))
  2432. ;; Check if we should display in two columns
  2433. (if org-agenda-menu-two-columns
  2434. (progn
  2435. (setq n (length lines)
  2436. n1 (+ (/ n 2) (mod n 2))
  2437. right (nthcdr n1 lines)
  2438. left (copy-sequence lines))
  2439. (setcdr (nthcdr (1- n1) left) nil))
  2440. (setq left lines right nil))
  2441. (while left
  2442. (insert "\n" (pop left))
  2443. (when right
  2444. (if (< (current-column) 40)
  2445. (move-to-column 40 t)
  2446. (insert " "))
  2447. (insert (pop right))))
  2448. ;; Make the window the right size
  2449. (goto-char (point-min))
  2450. (if second-time
  2451. (if (not (pos-visible-in-window-p (point-max)))
  2452. (org-fit-window-to-buffer))
  2453. (setq second-time t)
  2454. (org-fit-window-to-buffer))
  2455. ;; Ask for selection
  2456. (message "Press key for agenda command%s:"
  2457. (if (or restrict-ok org-agenda-overriding-restriction)
  2458. (if org-agenda-overriding-restriction
  2459. " (restriction lock active)"
  2460. (if restriction
  2461. (format " (restricted to %s)" restriction)
  2462. " (unrestricted)"))
  2463. ""))
  2464. (setq c (read-char-exclusive))
  2465. (message "")
  2466. (cond
  2467. ((assoc (char-to-string c) custom)
  2468. (setq selstring (concat selstring (char-to-string c)))
  2469. (throw 'exit (cons selstring restriction)))
  2470. ((memq c prefixes)
  2471. (setq selstring (concat selstring (char-to-string c))
  2472. prefixes nil
  2473. rmheader (or rmheader t)
  2474. custom (delq nil (mapcar
  2475. (lambda (x)
  2476. (if (or (= (length (car x)) 1)
  2477. (/= (string-to-char (car x)) c))
  2478. nil
  2479. (cons (substring (car x) 1) (cdr x))))
  2480. custom))))
  2481. ((eq c ?*)
  2482. (call-interactively 'org-toggle-sticky-agenda)
  2483. (sit-for 2))
  2484. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2485. (message "Restriction is only possible in Org-mode buffers")
  2486. (ding) (sit-for 1))
  2487. ((eq c ?1)
  2488. (org-agenda-remove-restriction-lock 'noupdate)
  2489. (setq restriction 'buffer))
  2490. ((eq c ?0)
  2491. (org-agenda-remove-restriction-lock 'noupdate)
  2492. (setq restriction (if region-p 'region 'subtree)))
  2493. ((eq c ?<)
  2494. (org-agenda-remove-restriction-lock 'noupdate)
  2495. (setq restriction
  2496. (cond
  2497. ((eq restriction 'buffer)
  2498. (if region-p 'region 'subtree))
  2499. ((memq restriction '(subtree region))
  2500. nil)
  2501. (t 'buffer))))
  2502. ((eq c ?>)
  2503. (org-agenda-remove-restriction-lock 'noupdate)
  2504. (setq restriction nil))
  2505. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2506. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2507. ((and (> (length selstring) 0) (eq c ?\d))
  2508. (delete-window)
  2509. (org-agenda-get-restriction-and-command prefix-descriptions))
  2510. ((equal c ?q) (error "Abort"))
  2511. (t (error "Invalid key %c" c))))))))
  2512. (defun org-agenda-fit-window-to-buffer ()
  2513. "Fit the window to the buffer size."
  2514. (and (memq org-agenda-window-setup '(reorganize-frame))
  2515. (fboundp 'fit-window-to-buffer)
  2516. (org-fit-window-to-buffer
  2517. nil
  2518. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2519. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2520. (defvar org-cmd nil)
  2521. (defvar org-agenda-overriding-cmd nil)
  2522. (defvar org-agenda-overriding-arguments nil)
  2523. (defvar org-agenda-overriding-cmd-arguments nil)
  2524. (defun org-agenda-run-series (name series)
  2525. (org-let (nth 1 series) '(org-agenda-prepare name))
  2526. ;; We need to reset agenda markers here, because when constructing a
  2527. ;; block agenda, the individual blocks do not do that.
  2528. (org-agenda-reset-markers)
  2529. (let* ((org-agenda-multi t)
  2530. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2531. (cmds (car series))
  2532. (gprops (nth 1 series))
  2533. match ;; The byte compiler incorrectly complains about this. Keep it!
  2534. org-cmd type lprops)
  2535. (while (setq org-cmd (pop cmds))
  2536. (setq type (car org-cmd)
  2537. match (eval (nth 1 org-cmd))
  2538. lprops (nth 2 org-cmd))
  2539. (let ((org-agenda-overriding-arguments
  2540. (if (eq org-agenda-overriding-cmd org-cmd)
  2541. (or org-agenda-overriding-arguments
  2542. org-agenda-overriding-cmd-arguments))))
  2543. (cond
  2544. ((eq type 'agenda)
  2545. (org-let2 gprops lprops
  2546. '(call-interactively 'org-agenda-list)))
  2547. ((eq type 'alltodo)
  2548. (org-let2 gprops lprops
  2549. '(call-interactively 'org-todo-list)))
  2550. ((eq type 'search)
  2551. (org-let2 gprops lprops
  2552. '(org-search-view current-prefix-arg match nil)))
  2553. ((eq type 'stuck)
  2554. (org-let2 gprops lprops
  2555. '(call-interactively 'org-agenda-list-stuck-projects)))
  2556. ((eq type 'tags)
  2557. (org-let2 gprops lprops
  2558. '(org-tags-view current-prefix-arg match)))
  2559. ((eq type 'tags-todo)
  2560. (org-let2 gprops lprops
  2561. '(org-tags-view '(4) match)))
  2562. ((eq type 'todo)
  2563. (org-let2 gprops lprops
  2564. '(org-todo-list match)))
  2565. ((fboundp type)
  2566. (org-let2 gprops lprops
  2567. '(funcall type match)))
  2568. (t (error "Invalid type in command series")))))
  2569. (widen)
  2570. (let ((inhibit-read-only t))
  2571. (add-text-properties (point-min) (point-max)
  2572. `(org-serie t org-serie-redo-cmd ,redo)))
  2573. (setq org-agenda-redo-command redo)
  2574. (goto-char (point-min)))
  2575. (org-agenda-fit-window-to-buffer)
  2576. (org-let (nth 1 series) '(org-agenda-finalize)))
  2577. ;;;###autoload
  2578. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2579. "Run an agenda command in batch mode and send the result to STDOUT.
  2580. If CMD-KEY is a string of length 1, it is used as a key in
  2581. `org-agenda-custom-commands' and triggers this command. If it is a
  2582. longer string it is used as a tags/todo match string.
  2583. Parameters are alternating variable names and values that will be bound
  2584. before running the agenda command."
  2585. (org-eval-in-environment (org-make-parameter-alist parameters)
  2586. (if (> (length cmd-key) 2)
  2587. (org-tags-view nil cmd-key)
  2588. (org-agenda nil cmd-key)))
  2589. (set-buffer org-agenda-buffer-name)
  2590. (princ (buffer-string)))
  2591. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2592. (defvar org-agenda-info nil)
  2593. ;;;###autoload
  2594. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2595. "Run an agenda command in batch mode and send the result to STDOUT.
  2596. If CMD-KEY is a string of length 1, it is used as a key in
  2597. `org-agenda-custom-commands' and triggers this command. If it is a
  2598. longer string it is used as a tags/todo match string.
  2599. Parameters are alternating variable names and values that will be bound
  2600. before running the agenda command.
  2601. The output gives a line for each selected agenda item. Each
  2602. item is a list of comma-separated values, like this:
  2603. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2604. category The category of the item
  2605. head The headline, without TODO kwd, TAGS and PRIORITY
  2606. type The type of the agenda entry, can be
  2607. todo selected in TODO match
  2608. tagsmatch selected in tags match
  2609. diary imported from diary
  2610. deadline a deadline on given date
  2611. scheduled scheduled on given date
  2612. timestamp entry has timestamp on given date
  2613. closed entry was closed on given date
  2614. upcoming-deadline warning about deadline
  2615. past-scheduled forwarded scheduled item
  2616. block entry has date block including g. date
  2617. todo The todo keyword, if any
  2618. tags All tags including inherited ones, separated by colons
  2619. date The relevant date, like 2007-2-14
  2620. time The time, like 15:00-16:50
  2621. extra Sting with extra planning info
  2622. priority-l The priority letter if any was given
  2623. priority-n The computed numerical priority
  2624. agenda-day The day in the agenda where this is listed"
  2625. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2626. (org-make-parameter-alist parameters))
  2627. (if (> (length cmd-key) 2)
  2628. (org-tags-view nil cmd-key)
  2629. (org-agenda nil cmd-key)))
  2630. (set-buffer org-agenda-buffer-name)
  2631. (let* ((lines (org-split-string (buffer-string) "\n"))
  2632. line)
  2633. (while (setq line (pop lines))
  2634. (catch 'next
  2635. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2636. (setq org-agenda-info
  2637. (org-fix-agenda-info (text-properties-at 0 line)))
  2638. (princ
  2639. (mapconcat 'org-agenda-export-csv-mapper
  2640. '(org-category txt type todo tags date time extra
  2641. priority-letter priority agenda-day)
  2642. ","))
  2643. (princ "\n")))))
  2644. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2645. (defun org-fix-agenda-info (props)
  2646. "Make sure all properties on an agenda item have a canonical form.
  2647. This ensures the export commands can easily use it."
  2648. (let (tmp re)
  2649. (when (setq tmp (plist-get props 'tags))
  2650. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2651. (when (setq tmp (plist-get props 'date))
  2652. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2653. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2654. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2655. (setq tmp (calendar-date-string tmp)))
  2656. (setq props (plist-put props 'date tmp)))
  2657. (when (setq tmp (plist-get props 'day))
  2658. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2659. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2660. (setq tmp (calendar-date-string tmp)))
  2661. (setq props (plist-put props 'day tmp))
  2662. (setq props (plist-put props 'agenda-day tmp)))
  2663. (when (setq tmp (plist-get props 'txt))
  2664. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2665. (plist-put props 'priority-letter (match-string 1 tmp))
  2666. (setq tmp (replace-match "" t t tmp)))
  2667. (when (and (setq re (plist-get props 'org-todo-regexp))
  2668. (setq re (concat "\\`\\.*" re " ?"))
  2669. (string-match re tmp))
  2670. (plist-put props 'todo (match-string 1 tmp))
  2671. (setq tmp (replace-match "" t t tmp)))
  2672. (plist-put props 'txt tmp)))
  2673. props)
  2674. (defun org-agenda-export-csv-mapper (prop)
  2675. (let ((res (plist-get org-agenda-info prop)))
  2676. (setq res
  2677. (cond
  2678. ((not res) "")
  2679. ((stringp res) res)
  2680. (t (prin1-to-string res))))
  2681. (while (string-match "," res)
  2682. (setq res (replace-match ";" t t res)))
  2683. (org-trim res)))
  2684. ;;;###autoload
  2685. (defun org-store-agenda-views (&rest parameters)
  2686. (interactive)
  2687. (eval (list 'org-batch-store-agenda-views)))
  2688. ;;;###autoload
  2689. (defmacro org-batch-store-agenda-views (&rest parameters)
  2690. "Run all custom agenda commands that have a file argument."
  2691. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2692. (pop-up-frames nil)
  2693. (dir default-directory)
  2694. (pars (org-make-parameter-alist parameters))
  2695. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2696. (save-window-excursion
  2697. (while cmds
  2698. (setq cmd (pop cmds)
  2699. thiscmdkey (car cmd)
  2700. thiscmdcmd (cdr cmd)
  2701. match (nth 2 thiscmdcmd)
  2702. bufname (if org-agenda-sticky
  2703. (or (and (stringp match)
  2704. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2705. (format "*Org Agenda(%s)*" thiscmdkey))
  2706. org-agenda-buffer-name)
  2707. cmd-or-set (nth 2 cmd)
  2708. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2709. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2710. (if (stringp files) (setq files (list files)))
  2711. (when files
  2712. (org-eval-in-environment (append org-agenda-exporter-settings
  2713. opts pars)
  2714. (org-agenda nil thiscmdkey))
  2715. (set-buffer bufname)
  2716. (while files
  2717. (org-eval-in-environment (append org-agenda-exporter-settings
  2718. opts pars)
  2719. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2720. (and (get-buffer bufname)
  2721. (kill-buffer bufname)))))))
  2722. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2723. (defvar org-agenda-current-span nil
  2724. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2725. (defun org-agenda-mark-header-line (pos)
  2726. "Mark the line at POS as an agenda structure header."
  2727. (save-excursion
  2728. (goto-char pos)
  2729. (put-text-property (point-at-bol) (point-at-eol)
  2730. 'org-agenda-structural-header t)
  2731. (when org-agenda-title-append
  2732. (put-text-property (point-at-bol) (point-at-eol)
  2733. 'org-agenda-title-append org-agenda-title-append))))
  2734. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2735. (defvar org-agenda-write-buffer-name "Agenda View")
  2736. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2737. "Write the current buffer (an agenda view) as a file.
  2738. Depending on the extension of the file name, plain text (.txt),
  2739. HTML (.html or .htm) or Postscript (.ps) is produced.
  2740. If the extension is .ics, run icalendar export over all files used
  2741. to construct the agenda and limit the export to entries listed in the
  2742. agenda now.
  2743. With prefix argument OPEN, open the new file immediately.
  2744. If NOSETTINGS is given, do not scope the settings of
  2745. `org-agenda-exporter-settings' into the export commands. This is used when
  2746. the settings have already been scoped and we do not wish to overrule other,
  2747. higher priority settings.
  2748. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2749. (interactive "FWrite agenda to file: \nP")
  2750. (if (not (file-writable-p file))
  2751. (error "Cannot write agenda to file %s" file))
  2752. (org-let (if nosettings nil org-agenda-exporter-settings)
  2753. '(save-excursion
  2754. (save-window-excursion
  2755. (org-agenda-mark-filtered-text)
  2756. (let ((bs (copy-sequence (buffer-string))) beg)
  2757. (org-agenda-unmark-filtered-text)
  2758. (with-temp-buffer
  2759. (rename-buffer org-agenda-write-buffer-name t)
  2760. (set-buffer-modified-p nil)
  2761. (insert bs)
  2762. (org-agenda-remove-marked-text 'org-filtered)
  2763. (while (setq beg (text-property-any (point-min) (point-max)
  2764. 'org-filtered t))
  2765. (delete-region
  2766. beg (or (next-single-property-change beg 'org-filtered)
  2767. (point-max))))
  2768. (run-hooks 'org-agenda-before-write-hook)
  2769. (cond
  2770. ((org-bound-and-true-p org-mobile-creating-agendas)
  2771. (org-mobile-write-agenda-for-mobile file))
  2772. ((string-match "\\.html?\\'" file)
  2773. (require 'htmlize)
  2774. (set-buffer (htmlize-buffer (current-buffer)))
  2775. (when (and org-agenda-export-html-style
  2776. (string-match "<style>" org-agenda-export-html-style))
  2777. ;; replace <style> section with org-agenda-export-html-style
  2778. (goto-char (point-min))
  2779. (kill-region (- (search-forward "<style") 6)
  2780. (search-forward "</style>"))
  2781. (insert org-agenda-export-html-style))
  2782. (write-file file)
  2783. (kill-buffer (current-buffer))
  2784. (message "HTML written to %s" file))
  2785. ((string-match "\\.ps\\'" file)
  2786. (require 'ps-print)
  2787. (ps-print-buffer-with-faces file)
  2788. (message "Postscript written to %s" file))
  2789. ((string-match "\\.pdf\\'" file)
  2790. (require 'ps-print)
  2791. (ps-print-buffer-with-faces
  2792. (concat (file-name-sans-extension file) ".ps"))
  2793. (call-process "ps2pdf" nil nil nil
  2794. (expand-file-name
  2795. (concat (file-name-sans-extension file) ".ps"))
  2796. (expand-file-name file))
  2797. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2798. (message "PDF written to %s" file))
  2799. ((string-match "\\.ics\\'" file)
  2800. (require 'org-icalendar)
  2801. (let ((org-agenda-marker-table
  2802. (org-create-marker-find-array
  2803. (org-agenda-collect-markers)))
  2804. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2805. (org-combined-agenda-icalendar-file file))
  2806. (apply 'org-export-icalendar 'combine
  2807. (org-agenda-files nil 'ifmode))))
  2808. (t
  2809. (let ((bs (buffer-string)))
  2810. (find-file file)
  2811. (erase-buffer)
  2812. (insert bs)
  2813. (save-buffer 0)
  2814. (kill-buffer (current-buffer))
  2815. (message "Plain text written to %s" file))))))))
  2816. (set-buffer (or agenda-bufname
  2817. (and (called-interactively-p 'any) (buffer-name))
  2818. org-agenda-buffer-name)))
  2819. (when open (org-open-file file)))
  2820. (defvar org-agenda-tag-filter-overlays nil)
  2821. (defvar org-agenda-cat-filter-overlays nil)
  2822. (defun org-agenda-mark-filtered-text ()
  2823. "Mark all text hidden by filtering with a text property."
  2824. (let ((inhibit-read-only t))
  2825. (mapc
  2826. (lambda (o)
  2827. (when (equal (overlay-buffer o) (current-buffer))
  2828. (put-text-property
  2829. (overlay-start o) (overlay-end o)
  2830. 'org-filtered t)))
  2831. (append org-agenda-tag-filter-overlays
  2832. org-agenda-cat-filter-overlays))))
  2833. (defun org-agenda-unmark-filtered-text ()
  2834. "Remove the filtering text property."
  2835. (let ((inhibit-read-only t))
  2836. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2837. (defun org-agenda-remove-marked-text (property &optional value)
  2838. "Delete all text marked with VALUE of PROPERTY.
  2839. VALUE defaults to t."
  2840. (let (beg)
  2841. (setq value (or value t))
  2842. (while (setq beg (text-property-any (point-min) (point-max)
  2843. property value))
  2844. (delete-region
  2845. beg (or (next-single-property-change beg 'org-filtered)
  2846. (point-max))))))
  2847. (defun org-agenda-add-entry-text ()
  2848. "Add entry text to agenda lines.
  2849. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2850. entry text following headings shown in the agenda.
  2851. Drawers will be excluded, also the line with scheduling/deadline info."
  2852. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2853. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2854. (let (m txt)
  2855. (goto-char (point-min))
  2856. (while (not (eobp))
  2857. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2858. (beginning-of-line 2)
  2859. (setq txt (org-agenda-get-some-entry-text
  2860. m org-agenda-add-entry-text-maxlines " > "))
  2861. (end-of-line 1)
  2862. (if (string-match "\\S-" txt)
  2863. (insert "\n" txt)
  2864. (or (eobp) (forward-char 1))))))))
  2865. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2866. &rest keep)
  2867. "Extract entry text from MARKER, at most N-LINES lines.
  2868. This will ignore drawers etc, just get the text.
  2869. If INDENT is given, prefix every line with this string. If KEEP is
  2870. given, it is a list of symbols, defining stuff that should not be
  2871. removed from the entry content. Currently only `planning' is allowed here."
  2872. (let (txt drawer-re kwd-time-re ind)
  2873. (save-excursion
  2874. (with-current-buffer (marker-buffer marker)
  2875. (if (not (derived-mode-p 'org-mode))
  2876. (setq txt "")
  2877. (save-excursion
  2878. (save-restriction
  2879. (widen)
  2880. (goto-char marker)
  2881. (end-of-line 1)
  2882. (setq txt (buffer-substring
  2883. (min (1+ (point)) (point-max))
  2884. (progn (outline-next-heading) (point)))
  2885. drawer-re org-drawer-regexp
  2886. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2887. ".*\n?"))
  2888. (with-temp-buffer
  2889. (insert txt)
  2890. (when org-agenda-add-entry-text-descriptive-links
  2891. (goto-char (point-min))
  2892. (while (org-activate-bracket-links (point-max))
  2893. (add-text-properties (match-beginning 0) (match-end 0)
  2894. '(face org-link))))
  2895. (goto-char (point-min))
  2896. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2897. (set-text-properties (match-beginning 0) (match-end 0)
  2898. nil))
  2899. (goto-char (point-min))
  2900. (while (re-search-forward drawer-re nil t)
  2901. (delete-region
  2902. (match-beginning 0)
  2903. (progn (re-search-forward
  2904. "^[ \t]*:END:.*\n?" nil 'move)
  2905. (point))))
  2906. (unless (member 'planning keep)
  2907. (goto-char (point-min))
  2908. (while (re-search-forward kwd-time-re nil t)
  2909. (replace-match "")))
  2910. (goto-char (point-min))
  2911. (when org-agenda-entry-text-exclude-regexps
  2912. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2913. (while (setq re (pop re-list))
  2914. (goto-char (point-min))
  2915. (while (re-search-forward re nil t)
  2916. (replace-match "")))))
  2917. (goto-char (point-max))
  2918. (skip-chars-backward " \t\n")
  2919. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2920. ;; find and remove min common indentation
  2921. (goto-char (point-min))
  2922. (untabify (point-min) (point-max))
  2923. (setq ind (org-get-indentation))
  2924. (while (not (eobp))
  2925. (unless (looking-at "[ \t]*$")
  2926. (setq ind (min ind (org-get-indentation))))
  2927. (beginning-of-line 2))
  2928. (goto-char (point-min))
  2929. (while (not (eobp))
  2930. (unless (looking-at "[ \t]*$")
  2931. (move-to-column ind)
  2932. (delete-region (point-at-bol) (point)))
  2933. (beginning-of-line 2))
  2934. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2935. (goto-char (point-min))
  2936. (when indent
  2937. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2938. (replace-match indent t t)))
  2939. (goto-char (point-min))
  2940. (while (looking-at "[ \t]*\n") (replace-match ""))
  2941. (goto-char (point-max))
  2942. (when (> (org-current-line)
  2943. n-lines)
  2944. (org-goto-line (1+ n-lines))
  2945. (backward-char 1))
  2946. (setq txt (buffer-substring (point-min) (point)))))))))
  2947. txt))
  2948. (defun org-agenda-collect-markers ()
  2949. "Collect the markers pointing to entries in the agenda buffer."
  2950. (let (m markers)
  2951. (save-excursion
  2952. (goto-char (point-min))
  2953. (while (not (eobp))
  2954. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2955. (org-get-at-bol 'org-marker)))
  2956. (push m markers))
  2957. (beginning-of-line 2)))
  2958. (nreverse markers)))
  2959. (defun org-create-marker-find-array (marker-list)
  2960. "Create a alist of files names with all marker positions in that file."
  2961. (let (f tbl m a p)
  2962. (while (setq m (pop marker-list))
  2963. (setq p (marker-position m)
  2964. f (buffer-file-name (or (buffer-base-buffer
  2965. (marker-buffer m))
  2966. (marker-buffer m))))
  2967. (if (setq a (assoc f tbl))
  2968. (push (marker-position m) (cdr a))
  2969. (push (list f p) tbl)))
  2970. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2971. tbl)))
  2972. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2973. (defun org-check-agenda-marker-table ()
  2974. "Check of the current entry is on the marker list."
  2975. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2976. a)
  2977. (and (setq a (assoc file org-agenda-marker-table))
  2978. (save-match-data
  2979. (save-excursion
  2980. (org-back-to-heading t)
  2981. (member (point) (cdr a)))))))
  2982. (defun org-check-for-org-mode ()
  2983. "Make sure current buffer is in org-mode. Error if not."
  2984. (or (derived-mode-p 'org-mode)
  2985. (error "Cannot execute org-mode agenda command on buffer in %s"
  2986. major-mode)))
  2987. ;;; Agenda prepare and finalize
  2988. (defvar org-agenda-multi nil) ; dynamically scoped
  2989. (defvar org-agenda-pre-window-conf nil)
  2990. (defvar org-agenda-columns-active nil)
  2991. (defvar org-agenda-name nil)
  2992. (defvar org-agenda-tag-filter nil)
  2993. (defvar org-agenda-category-filter nil)
  2994. (defvar org-agenda-top-category-filter nil)
  2995. (defvar org-agenda-tag-filter-while-redo nil)
  2996. (defvar org-agenda-tag-filter-preset nil
  2997. "A preset of the tags filter used for secondary agenda filtering.
  2998. This must be a list of strings, each string must be a single tag preceded
  2999. by \"+\" or \"-\".
  3000. This variable should not be set directly, but agenda custom commands can
  3001. bind it in the options section. The preset filter is a global property of
  3002. the entire agenda view. In a block agenda, it will not work reliably to
  3003. define a filter for one of the individual blocks. You need to set it in
  3004. the global options and expect it to be applied to the entire view.")
  3005. (defvar org-agenda-category-filter-preset nil
  3006. "A preset of the category filter used for secondary agenda filtering.
  3007. This must be a list of strings, each string must be a single category
  3008. preceded by \"+\" or \"-\".
  3009. This variable should not be set directly, but agenda custom commands can
  3010. bind it in the options section. The preset filter is a global property of
  3011. the entire agenda view. In a block agenda, it will not work reliably to
  3012. define a filter for one of the individual blocks. You need to set it in
  3013. the global options and expect it to be applied to the entire view.")
  3014. (defun org-agenda-use-sticky-p ()
  3015. "Return non-nil if an agenda buffer named
  3016. `org-agenda-buffer-name' exists and should be shown instead of
  3017. generating a new one."
  3018. (and
  3019. ;; turned off by user
  3020. org-agenda-sticky
  3021. ;; For multi-agenda buffer already exists
  3022. (not org-agenda-multi)
  3023. ;; buffer found
  3024. (get-buffer org-agenda-buffer-name)
  3025. ;; C-u parameter is same as last call
  3026. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3027. (and
  3028. (equal current-prefix-arg
  3029. org-agenda-last-prefix-arg)
  3030. ;; In case user turned stickiness on, while having existing
  3031. ;; Agenda buffer active, don't reuse that buffer, because it
  3032. ;; does not have org variables local
  3033. org-agenda-this-buffer-is-sticky))))
  3034. (defun org-agenda-prepare-window (abuf)
  3035. "Setup agenda buffer in the window."
  3036. (let* ((awin (get-buffer-window abuf))
  3037. wconf)
  3038. (cond
  3039. ((equal (current-buffer) abuf) nil)
  3040. (awin (select-window awin))
  3041. ((not (setq wconf (current-window-configuration))))
  3042. ((equal org-agenda-window-setup 'current-window)
  3043. (org-pop-to-buffer-same-window abuf))
  3044. ((equal org-agenda-window-setup 'other-window)
  3045. (org-switch-to-buffer-other-window abuf))
  3046. ((equal org-agenda-window-setup 'other-frame)
  3047. (switch-to-buffer-other-frame abuf))
  3048. ((equal org-agenda-window-setup 'reorganize-frame)
  3049. (delete-other-windows)
  3050. (org-switch-to-buffer-other-window abuf)))
  3051. ;; additional test in case agenda is invoked from within agenda
  3052. ;; buffer via elisp link
  3053. (unless (equal (current-buffer) abuf)
  3054. (org-pop-to-buffer-same-window abuf))
  3055. (setq org-agenda-pre-window-conf
  3056. (or org-agenda-pre-window-conf wconf))))
  3057. (defun org-agenda-prepare (&optional name)
  3058. (if (org-agenda-use-sticky-p)
  3059. (progn
  3060. ;; Popup existing buffer
  3061. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3062. (message "Sticky Agenda buffer, use `r' to refresh")
  3063. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3064. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3065. (setq org-todo-keywords-for-agenda nil)
  3066. (setq org-drawers-for-agenda nil)
  3067. (unless org-agenda-persistent-filter
  3068. (setq org-agenda-tag-filter nil
  3069. org-agenda-category-filter nil))
  3070. (put 'org-agenda-tag-filter :preset-filter
  3071. org-agenda-tag-filter-preset)
  3072. (put 'org-agenda-category-filter :preset-filter
  3073. org-agenda-category-filter-preset)
  3074. (if org-agenda-multi
  3075. (progn
  3076. (setq buffer-read-only nil)
  3077. (goto-char (point-max))
  3078. (unless (or (bobp) org-agenda-compact-blocks
  3079. (not org-agenda-block-separator))
  3080. (insert "\n"
  3081. (if (stringp org-agenda-block-separator)
  3082. org-agenda-block-separator
  3083. (make-string (window-width) org-agenda-block-separator))
  3084. "\n"))
  3085. (narrow-to-region (point) (point-max)))
  3086. (setq org-done-keywords-for-agenda nil)
  3087. ;; Setting any org variables that are in org-agenda-local-vars
  3088. ;; list need to be done after the prepare call
  3089. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3090. (setq buffer-read-only nil)
  3091. (org-agenda-reset-markers)
  3092. (let ((inhibit-read-only t)) (erase-buffer))
  3093. (org-agenda-mode)
  3094. (setq org-agenda-buffer (current-buffer))
  3095. (setq org-agenda-contributing-files nil)
  3096. (setq org-agenda-columns-active nil)
  3097. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3098. (setq org-todo-keywords-for-agenda
  3099. (org-uniquify org-todo-keywords-for-agenda))
  3100. (setq org-done-keywords-for-agenda
  3101. (org-uniquify org-done-keywords-for-agenda))
  3102. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3103. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3104. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3105. (and name (not org-agenda-name)
  3106. (org-set-local 'org-agenda-name name)))
  3107. (setq buffer-read-only nil)))
  3108. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3109. (defun org-agenda-finalize ()
  3110. "Finishing touch for the agenda buffer, called just before displaying it."
  3111. (unless org-agenda-multi
  3112. (save-excursion
  3113. (let ((inhibit-read-only t))
  3114. (goto-char (point-min))
  3115. (while (org-activate-bracket-links (point-max))
  3116. (add-text-properties (match-beginning 0) (match-end 0)
  3117. '(face org-link)))
  3118. (org-agenda-align-tags)
  3119. (unless org-agenda-with-colors
  3120. (remove-text-properties (point-min) (point-max) '(face nil))))
  3121. (if (and (boundp 'org-agenda-overriding-columns-format)
  3122. org-agenda-overriding-columns-format)
  3123. (org-set-local 'org-agenda-overriding-columns-format
  3124. org-agenda-overriding-columns-format))
  3125. (if (and (boundp 'org-agenda-view-columns-initially)
  3126. org-agenda-view-columns-initially)
  3127. (org-agenda-columns))
  3128. (when org-agenda-fontify-priorities
  3129. (org-agenda-fontify-priorities))
  3130. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3131. (org-agenda-dim-blocked-tasks))
  3132. (org-agenda-mark-clocking-task)
  3133. (when org-agenda-entry-text-mode
  3134. (org-agenda-entry-text-hide)
  3135. (org-agenda-entry-text-show))
  3136. (if (functionp 'org-habit-insert-consistency-graphs)
  3137. (org-habit-insert-consistency-graphs))
  3138. (run-hooks 'org-agenda-finalize-hook)
  3139. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3140. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3141. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3142. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3143. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3144. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3145. )))
  3146. (defun org-agenda-mark-clocking-task ()
  3147. "Mark the current clock entry in the agenda if it is present."
  3148. (mapc (lambda (o)
  3149. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3150. (delete-overlay o)))
  3151. (overlays-in (point-min) (point-max)))
  3152. (when (marker-buffer org-clock-hd-marker)
  3153. (save-excursion
  3154. (goto-char (point-min))
  3155. (let (s ov)
  3156. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3157. (goto-char s)
  3158. (when (equal (org-get-at-bol 'org-hd-marker)
  3159. org-clock-hd-marker)
  3160. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3161. (overlay-put ov 'type 'org-agenda-clocking)
  3162. (overlay-put ov 'face 'org-agenda-clocking)
  3163. (overlay-put ov 'help-echo
  3164. "The clock is running in this item")))))))
  3165. (defun org-agenda-fontify-priorities ()
  3166. "Make highest priority lines bold, and lowest italic."
  3167. (interactive)
  3168. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3169. (delete-overlay o)))
  3170. (overlays-in (point-min) (point-max)))
  3171. (save-excursion
  3172. (let ((inhibit-read-only t)
  3173. b e p ov h l)
  3174. (goto-char (point-min))
  3175. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3176. (setq h (or (get-char-property (point) 'org-highest-priority)
  3177. org-highest-priority)
  3178. l (or (get-char-property (point) 'org-lowest-priority)
  3179. org-lowest-priority)
  3180. p (string-to-char (match-string 1))
  3181. b (match-beginning 0)
  3182. e (if (eq org-agenda-fontify-priorities 'cookies)
  3183. (match-end 0)
  3184. (point-at-eol))
  3185. ov (make-overlay b e))
  3186. (overlay-put
  3187. ov 'face
  3188. (cond ((org-face-from-face-or-color
  3189. 'priority nil
  3190. (cdr (assoc p org-priority-faces))))
  3191. ((and (listp org-agenda-fontify-priorities)
  3192. (org-face-from-face-or-color
  3193. 'priority nil
  3194. (cdr (assoc p org-agenda-fontify-priorities)))))
  3195. ((equal p l) 'italic)
  3196. ((equal p h) 'bold)))
  3197. (overlay-put ov 'org-type 'org-priority)))))
  3198. (defun org-agenda-dim-blocked-tasks ()
  3199. "Dim currently blocked TODO's in the agenda display."
  3200. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3201. (delete-overlay o)))
  3202. (overlays-in (point-min) (point-max)))
  3203. (save-excursion
  3204. (let ((inhibit-read-only t)
  3205. (org-depend-tag-blocked nil)
  3206. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3207. org-blocked-by-checkboxes
  3208. invis1 b e p ov h l)
  3209. (goto-char (point-min))
  3210. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3211. (and pos (goto-char (1+ pos))))
  3212. (setq org-blocked-by-checkboxes nil invis1 invis)
  3213. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3214. (when (and marker
  3215. (with-current-buffer (marker-buffer marker)
  3216. (save-excursion (goto-char marker)
  3217. (org-entry-blocked-p))))
  3218. (if org-blocked-by-checkboxes (setq invis1 nil))
  3219. (setq b (if invis1
  3220. (max (point-min) (1- (point-at-bol)))
  3221. (point-at-bol))
  3222. e (point-at-eol)
  3223. ov (make-overlay b e))
  3224. (if invis1
  3225. (overlay-put ov 'invisible t)
  3226. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3227. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3228. (defvar org-agenda-skip-function nil
  3229. "Function to be called at each match during agenda construction.
  3230. If this function returns nil, the current match should not be skipped.
  3231. Otherwise, the function must return a position from where the search
  3232. should be continued.
  3233. This may also be a Lisp form, it will be evaluated.
  3234. Never set this variable using `setq' or so, because then it will apply
  3235. to all future agenda commands. If you do want a global skipping condition,
  3236. use the option `org-agenda-skip-function-global' instead.
  3237. The correct usage for `org-agenda-skip-function' is to bind it with
  3238. `let' to scope it dynamically into the agenda-constructing command.
  3239. A good way to set it is through options in `org-agenda-custom-commands'.")
  3240. (defun org-agenda-skip ()
  3241. "Throw to `:skip' in places that should be skipped.
  3242. Also moves point to the end of the skipped region, so that search can
  3243. continue from there."
  3244. (let ((p (point-at-bol)) to)
  3245. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3246. (get-text-property p :org-archived)
  3247. (org-end-of-subtree t)
  3248. (throw :skip t))
  3249. (and org-agenda-skip-comment-trees
  3250. (get-text-property p :org-comment)
  3251. (org-end-of-subtree t)
  3252. (throw :skip t))
  3253. (if (equal (char-after p) ?#) (throw :skip t))
  3254. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3255. (org-agenda-skip-eval org-agenda-skip-function)))
  3256. (goto-char to)
  3257. (throw :skip t))))
  3258. (defun org-agenda-skip-eval (form)
  3259. "If FORM is a function or a list, call (or eval) is and return result.
  3260. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3261. and match data are returned to the previous state no matter what these
  3262. functions do."
  3263. (let (fp)
  3264. (and form
  3265. (or (setq fp (functionp form))
  3266. (consp form))
  3267. (save-excursion
  3268. (save-match-data
  3269. (if fp
  3270. (funcall form)
  3271. (eval form)))))))
  3272. (defvar org-agenda-markers nil
  3273. "List of all currently active markers created by `org-agenda'.")
  3274. (defvar org-agenda-last-marker-time (org-float-time)
  3275. "Creation time of the last agenda marker.")
  3276. (defun org-agenda-new-marker (&optional pos)
  3277. "Return a new agenda marker.
  3278. Org-mode keeps a list of these markers and resets them when they are
  3279. no longer in use."
  3280. (let ((m (copy-marker (or pos (point)))))
  3281. (setq org-agenda-last-marker-time (org-float-time))
  3282. (if org-agenda-buffer
  3283. (with-current-buffer org-agenda-buffer
  3284. (push m org-agenda-markers))
  3285. (push m org-agenda-markers))
  3286. m))
  3287. (defun org-agenda-reset-markers ()
  3288. "Reset markers created by `org-agenda'."
  3289. (while org-agenda-markers
  3290. (move-marker (pop org-agenda-markers) nil)))
  3291. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3292. "Save relative positions of markers in region.
  3293. This check for agenda markers in all agenda buffers currently active."
  3294. (dolist (buf (buffer-list))
  3295. (with-current-buffer buf
  3296. (when (eq major-mode 'org-agenda-mode)
  3297. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3298. org-agenda-markers)))))
  3299. ;;; Entry text mode
  3300. (defun org-agenda-entry-text-show-here ()
  3301. "Add some text from the entry as context to the current line."
  3302. (let (m txt o)
  3303. (setq m (org-get-at-bol 'org-hd-marker))
  3304. (unless (marker-buffer m)
  3305. (error "No marker points to an entry here"))
  3306. (setq txt (concat "\n" (org-no-properties
  3307. (org-agenda-get-some-entry-text
  3308. m org-agenda-entry-text-maxlines " > "))))
  3309. (when (string-match "\\S-" txt)
  3310. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3311. (overlay-put o 'evaporate t)
  3312. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3313. (overlay-put o 'after-string txt))))
  3314. (defun org-agenda-entry-text-show ()
  3315. "Add entry context for all agenda lines."
  3316. (interactive)
  3317. (save-excursion
  3318. (goto-char (point-max))
  3319. (beginning-of-line 1)
  3320. (while (not (bobp))
  3321. (when (org-get-at-bol 'org-hd-marker)
  3322. (org-agenda-entry-text-show-here))
  3323. (beginning-of-line 0))))
  3324. (defun org-agenda-entry-text-hide ()
  3325. "Remove any shown entry context."
  3326. (delq nil
  3327. (mapcar (lambda (o)
  3328. (if (eq (overlay-get o 'org-overlay-type)
  3329. 'agenda-entry-content)
  3330. (progn (delete-overlay o) t)))
  3331. (overlays-in (point-min) (point-max)))))
  3332. (defun org-agenda-get-day-face (date)
  3333. "Return the face DATE should be displayed with."
  3334. (or (and (functionp org-agenda-day-face-function)
  3335. (funcall org-agenda-day-face-function date))
  3336. (cond ((org-agenda-todayp date)
  3337. 'org-agenda-date-today)
  3338. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3339. 'org-agenda-date-weekend)
  3340. (t 'org-agenda-date))))
  3341. ;;; Agenda timeline
  3342. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3343. (defun org-timeline (&optional dotodo)
  3344. "Show a time-sorted view of the entries in the current org file.
  3345. Only entries with a time stamp of today or later will be listed. With
  3346. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3347. under the current date.
  3348. If the buffer contains an active region, only check the region for
  3349. dates."
  3350. (interactive "P")
  3351. (let* ((dopast t)
  3352. (org-agenda-show-log-scoped org-agenda-show-log)
  3353. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3354. (current-buffer))))
  3355. (date (calendar-current-date))
  3356. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3357. (end (if (org-region-active-p) (region-end) (point-max)))
  3358. (day-numbers (org-get-all-dates
  3359. beg end 'no-ranges
  3360. t org-agenda-show-log-scoped ; always include today
  3361. org-timeline-show-empty-dates))
  3362. (org-deadline-warning-days 0)
  3363. (org-agenda-only-exact-dates t)
  3364. (today (org-today))
  3365. (past t)
  3366. args
  3367. s e rtn d emptyp)
  3368. (setq org-agenda-redo-command
  3369. (list 'progn
  3370. (list 'org-switch-to-buffer-other-window (current-buffer))
  3371. (list 'org-timeline (list 'quote dotodo))))
  3372. (if (not dopast)
  3373. ;; Remove past dates from the list of dates.
  3374. (setq day-numbers (delq nil (mapcar (lambda(x)
  3375. (if (>= x today) x nil))
  3376. day-numbers))))
  3377. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3378. (org-compile-prefix-format 'timeline)
  3379. (org-set-sorting-strategy 'timeline)
  3380. (if org-agenda-show-log-scoped (push :closed args))
  3381. (push :timestamp args)
  3382. (push :deadline args)
  3383. (push :scheduled args)
  3384. (push :sexp args)
  3385. (if dotodo (push :todo args))
  3386. (insert "Timeline of file " entry "\n")
  3387. (add-text-properties (point-min) (point)
  3388. (list 'face 'org-agenda-structure))
  3389. (org-agenda-mark-header-line (point-min))
  3390. (while (setq d (pop day-numbers))
  3391. (if (and (listp d) (eq (car d) :omitted))
  3392. (progn
  3393. (setq s (point))
  3394. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3395. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3396. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3397. (if (and (>= d today)
  3398. dopast
  3399. past)
  3400. (progn
  3401. (setq past nil)
  3402. (insert (make-string 79 ?-) "\n")))
  3403. (setq date (calendar-gregorian-from-absolute d))
  3404. (setq s (point))
  3405. (setq rtn (and (not emptyp)
  3406. (apply 'org-agenda-get-day-entries entry
  3407. date args)))
  3408. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3409. (progn
  3410. (insert
  3411. (if (stringp org-agenda-format-date)
  3412. (format-time-string org-agenda-format-date
  3413. (org-time-from-absolute date))
  3414. (funcall org-agenda-format-date date))
  3415. "\n")
  3416. (put-text-property s (1- (point)) 'face
  3417. (org-agenda-get-day-face date))
  3418. (put-text-property s (1- (point)) 'org-date-line t)
  3419. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3420. (if (equal d today)
  3421. (put-text-property s (1- (point)) 'org-today t))
  3422. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3423. (put-text-property s (1- (point)) 'day d)))))
  3424. (goto-char (point-min))
  3425. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3426. (point-min)))
  3427. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3428. (org-agenda-finalize)
  3429. (setq buffer-read-only t)))
  3430. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3431. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3432. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3433. not every single day in the range. If FORCE-TODAY is non-nil, make
  3434. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3435. inactive time stamps (those in square brackets) are included.
  3436. When EMPTY is non-nil, also include days without any entries."
  3437. (let ((re (concat
  3438. (if pre-re pre-re "")
  3439. (if inactive org-ts-regexp-both org-ts-regexp)))
  3440. dates dates1 date day day1 day2 ts1 ts2 pos)
  3441. (if force-today
  3442. (setq dates (list (org-today))))
  3443. (save-excursion
  3444. (goto-char beg)
  3445. (while (re-search-forward re end t)
  3446. (setq day (time-to-days (org-time-string-to-time
  3447. (substring (match-string 1) 0 10)
  3448. (current-buffer) (match-beginning 0))))
  3449. (or (memq day dates) (push day dates)))
  3450. (unless no-ranges
  3451. (goto-char beg)
  3452. (while (re-search-forward org-tr-regexp end t)
  3453. (setq pos (match-beginning 0))
  3454. (setq ts1 (substring (match-string 1) 0 10)
  3455. ts2 (substring (match-string 2) 0 10)
  3456. day1 (time-to-days (org-time-string-to-time
  3457. ts1 (current-buffer) pos))
  3458. day2 (time-to-days (org-time-string-to-time
  3459. ts2 (current-buffer) pos)))
  3460. (while (< (setq day1 (1+ day1)) day2)
  3461. (or (memq day1 dates) (push day1 dates)))))
  3462. (setq dates (sort dates '<))
  3463. (when empty
  3464. (while (setq day (pop dates))
  3465. (setq day2 (car dates))
  3466. (push day dates1)
  3467. (when (and day2 empty)
  3468. (if (or (eq empty t)
  3469. (and (numberp empty) (<= (- day2 day) empty)))
  3470. (while (< (setq day (1+ day)) day2)
  3471. (push (list day) dates1))
  3472. (push (cons :omitted (- day2 day)) dates1))))
  3473. (setq dates (nreverse dates1)))
  3474. dates)))
  3475. ;;; Agenda Daily/Weekly
  3476. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3477. "Start day for the agenda view.
  3478. Custom commands can set this variable in the options section.")
  3479. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3480. (defvar org-arg-loc nil) ; local variable
  3481. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3482. "List of types searched for when creating the daily/weekly agenda.
  3483. This variable is a list of symbols that controls the types of
  3484. items that appear in the daily/weekly agenda. Allowed symbols in this
  3485. list are are
  3486. :timestamp List items containing a date stamp or date range matching
  3487. the selected date. This includes sexp entries in
  3488. angular brackets.
  3489. :sexp List entries resulting from plain diary-like sexps.
  3490. :deadline List deadline due on that date. When the date is today,
  3491. also list any deadlines past due, or due within
  3492. `org-deadline-warning-days'. `:deadline' must appear before
  3493. `:scheduled' if the setting of
  3494. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3495. any effect.
  3496. :scheduled List all items which are scheduled for the given date.
  3497. The diary for *today* also contains items which were
  3498. scheduled earlier and are not yet marked DONE.
  3499. By default, all four types are turned on.
  3500. Never set this variable globally using `setq', because then it
  3501. will apply to all future agenda commands. Instead, bind it with
  3502. `let' to scope it dynamically into the agenda-constructing
  3503. command. A good way to set it is through options in
  3504. `org-agenda-custom-commands'. For a more flexible (though
  3505. somewhat less efficient) way of determining what is included in
  3506. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3507. (defvar org-agenda-buffer-tmp-name nil)
  3508. ;;;###autoload
  3509. (defun org-agenda-list (&optional arg start-day span)
  3510. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3511. The view will be for the current day or week, but from the overview buffer
  3512. you will be able to go to other days/weeks.
  3513. With a numeric prefix argument in an interactive call, the agenda will
  3514. span ARG days. Lisp programs should instead specify SPAN to change
  3515. the number of days. SPAN defaults to `org-agenda-span'.
  3516. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3517. given in `org-agenda-start-on-weekday'."
  3518. (interactive "P")
  3519. (if org-agenda-overriding-arguments
  3520. (setq arg (car org-agenda-overriding-arguments)
  3521. start-day (nth 1 org-agenda-overriding-arguments)
  3522. span (nth 2 org-agenda-overriding-arguments)))
  3523. (if (and (integerp arg) (> arg 0))
  3524. (setq span arg arg nil))
  3525. (catch 'exit
  3526. (setq org-agenda-buffer-name
  3527. (or org-agenda-buffer-tmp-name
  3528. (if org-agenda-sticky
  3529. (cond ((and org-keys (stringp org-match))
  3530. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3531. (org-keys
  3532. (format "*Org Agenda(%s)*" org-keys))
  3533. (t "*Org Agenda(a)*")))
  3534. org-agenda-buffer-name))
  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 &optional start-day)
  3701. "Return ndays from SPAN, possibly 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 level 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. level
  3937. (make-string
  3938. (1- (string-to-number
  3939. (substring (symbol-name (get-text-property
  3940. (match-beginning 0) 'face)) 10))) ? )
  3941. category-pos (get-text-property (point) 'org-category-position)
  3942. tags (org-get-tags-at (point))
  3943. txt (org-agenda-format-item
  3944. ""
  3945. (buffer-substring-no-properties
  3946. beg1 (point-at-eol))
  3947. level category tags))
  3948. (org-add-props txt props
  3949. 'org-marker marker 'org-hd-marker marker
  3950. 'org-todo-regexp org-todo-regexp
  3951. 'level level
  3952. 'org-complex-heading-regexp org-complex-heading-regexp
  3953. 'priority 1000 'org-category category
  3954. 'org-category-position category-pos
  3955. 'type "search")
  3956. (push txt ee)
  3957. (goto-char (1- end))))))))))
  3958. (setq rtn (nreverse ee))
  3959. (setq rtnall (append rtnall rtn)))
  3960. (if org-agenda-overriding-header
  3961. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3962. nil 'face 'org-agenda-structure) "\n")
  3963. (insert "Search words: ")
  3964. (add-text-properties (point-min) (1- (point))
  3965. (list 'face 'org-agenda-structure))
  3966. (setq pos (point))
  3967. (insert string "\n")
  3968. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3969. (setq pos (point))
  3970. (unless org-agenda-multi
  3971. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3972. (add-text-properties pos (1- (point))
  3973. (list 'face 'org-agenda-structure))))
  3974. (org-agenda-mark-header-line (point-min))
  3975. (when rtnall
  3976. (insert (org-agenda-finalize-entries rtnall) "\n"))
  3977. (goto-char (point-min))
  3978. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3979. (add-text-properties (point-min) (point-max)
  3980. `(org-agenda-type search
  3981. org-last-args (,todo-only ,string ,edit-at)
  3982. org-redo-cmd ,org-agenda-redo-command
  3983. org-serie-cmd ,org-cmd))
  3984. (org-agenda-finalize)
  3985. (setq buffer-read-only t))))
  3986. ;;; Agenda TODO list
  3987. (defvar org-select-this-todo-keyword nil)
  3988. (defvar org-last-arg nil)
  3989. ;;;###autoload
  3990. (defun org-todo-list (&optional arg)
  3991. "Show all (not done) TODO entries from all agenda file in a single list.
  3992. The prefix arg can be used to select a specific TODO keyword and limit
  3993. the list to these. When using \\[universal-argument], you will be prompted
  3994. for a keyword. A numeric prefix directly selects the Nth keyword in
  3995. `org-todo-keywords-1'."
  3996. (interactive "P")
  3997. (if org-agenda-overriding-arguments
  3998. (setq arg org-agenda-overriding-arguments))
  3999. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4000. (let* ((today (org-today))
  4001. (date (calendar-gregorian-from-absolute today))
  4002. (kwds org-todo-keywords-for-agenda)
  4003. (completion-ignore-case t)
  4004. (org-select-this-todo-keyword
  4005. (if (stringp arg) arg
  4006. (and arg (integerp arg) (> arg 0)
  4007. (nth (1- arg) kwds))))
  4008. rtn rtnall files file pos)
  4009. (when (equal arg '(4))
  4010. (setq org-select-this-todo-keyword
  4011. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4012. (mapcar 'list kwds) nil nil)))
  4013. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4014. (catch 'exit
  4015. (if org-agenda-sticky
  4016. (setq org-agenda-buffer-name
  4017. (if (stringp org-select-this-todo-keyword)
  4018. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4019. org-select-this-todo-keyword)
  4020. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4021. (org-agenda-prepare "TODO")
  4022. (org-compile-prefix-format 'todo)
  4023. (org-set-sorting-strategy 'todo)
  4024. (setq org-agenda-redo-command
  4025. `(org-todo-list (or current-prefix-arg (quote ,arg))))
  4026. (setq files (org-agenda-files nil 'ifmode)
  4027. rtnall nil)
  4028. (while (setq file (pop files))
  4029. (catch 'nextfile
  4030. (org-check-agenda-file file)
  4031. (setq rtn (org-agenda-get-day-entries file date :todo))
  4032. (setq rtnall (append rtnall rtn))))
  4033. (if org-agenda-overriding-header
  4034. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4035. nil 'face 'org-agenda-structure) "\n")
  4036. (insert "Global list of TODO items of type: ")
  4037. (add-text-properties (point-min) (1- (point))
  4038. (list 'face 'org-agenda-structure
  4039. 'short-heading
  4040. (concat "ToDo: "
  4041. (or org-select-this-todo-keyword "ALL"))))
  4042. (org-agenda-mark-header-line (point-min))
  4043. (setq pos (point))
  4044. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4045. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4046. (setq pos (point))
  4047. (unless org-agenda-multi
  4048. (insert "Available with `N r': (0)[ALL]")
  4049. (let ((n 0) s)
  4050. (mapc (lambda (x)
  4051. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4052. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4053. (insert "\n "))
  4054. (insert " " s))
  4055. kwds))
  4056. (insert "\n"))
  4057. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4058. (org-agenda-mark-header-line (point-min))
  4059. (when rtnall
  4060. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4061. (goto-char (point-min))
  4062. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4063. (add-text-properties (point-min) (point-max)
  4064. `(org-agenda-type todo
  4065. org-last-args ,arg
  4066. org-redo-cmd ,org-agenda-redo-command
  4067. org-serie-cmd ,org-cmd))
  4068. (org-agenda-finalize)
  4069. (setq buffer-read-only t))))
  4070. ;;; Agenda tags match
  4071. ;;;###autoload
  4072. (defun org-tags-view (&optional todo-only match)
  4073. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4074. The prefix arg TODO-ONLY limits the search to TODO entries."
  4075. (interactive "P")
  4076. (if org-agenda-overriding-arguments
  4077. (setq todo-only (car org-agenda-overriding-arguments)
  4078. match (nth 1 org-agenda-overriding-arguments)))
  4079. (let* ((org-tags-match-list-sublevels
  4080. org-tags-match-list-sublevels)
  4081. (completion-ignore-case t)
  4082. rtn rtnall files file pos matcher
  4083. buffer)
  4084. (when (and (stringp match) (not (string-match "\\S-" match)))
  4085. (setq match nil))
  4086. (setq matcher (org-make-tags-matcher match)
  4087. match (car matcher) matcher (cdr matcher))
  4088. (catch 'exit
  4089. (if org-agenda-sticky
  4090. (setq org-agenda-buffer-name
  4091. (if (stringp match)
  4092. (format "*Org Agenda(%s:%s)*"
  4093. (or org-keys (or (and todo-only "M") "m")) match)
  4094. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4095. (org-agenda-prepare (concat "TAGS " match))
  4096. (org-compile-prefix-format 'tags)
  4097. (org-set-sorting-strategy 'tags)
  4098. (setq org-agenda-query-string match)
  4099. (setq org-agenda-redo-command
  4100. (list 'org-tags-view `(quote ,todo-only)
  4101. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4102. (setq files (org-agenda-files nil 'ifmode)
  4103. rtnall nil)
  4104. (while (setq file (pop files))
  4105. (catch 'nextfile
  4106. (org-check-agenda-file file)
  4107. (setq buffer (if (file-exists-p file)
  4108. (org-get-agenda-file-buffer file)
  4109. (error "No such file %s" file)))
  4110. (if (not buffer)
  4111. ;; If file does not exist, error message to agenda
  4112. (setq rtn (list
  4113. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4114. rtnall (append rtnall rtn))
  4115. (with-current-buffer buffer
  4116. (unless (derived-mode-p 'org-mode)
  4117. (error "Agenda file %s is not in `org-mode'" file))
  4118. (save-excursion
  4119. (save-restriction
  4120. (if org-agenda-restrict
  4121. (narrow-to-region org-agenda-restrict-begin
  4122. org-agenda-restrict-end)
  4123. (widen))
  4124. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4125. (setq rtnall (append rtnall rtn))))))))
  4126. (if org-agenda-overriding-header
  4127. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4128. nil 'face 'org-agenda-structure) "\n")
  4129. (insert "Headlines with TAGS match: ")
  4130. (add-text-properties (point-min) (1- (point))
  4131. (list 'face 'org-agenda-structure
  4132. 'short-heading
  4133. (concat "Match: " match)))
  4134. (setq pos (point))
  4135. (insert match "\n")
  4136. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4137. (setq pos (point))
  4138. (unless org-agenda-multi
  4139. (insert "Press `C-u r' to search again with new search string\n"))
  4140. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4141. (org-agenda-mark-header-line (point-min))
  4142. (when rtnall
  4143. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4144. (goto-char (point-min))
  4145. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4146. (add-text-properties (point-min) (point-max)
  4147. `(org-agenda-type tags
  4148. org-last-args (,todo-only ,match)
  4149. org-redo-cmd ,org-agenda-redo-command
  4150. org-serie-cmd ,org-cmd))
  4151. (org-agenda-finalize)
  4152. (setq buffer-read-only t))))
  4153. ;;; Agenda Finding stuck projects
  4154. (defvar org-agenda-skip-regexp nil
  4155. "Regular expression used in skipping subtrees for the agenda.
  4156. This is basically a temporary global variable that can be set and then
  4157. used by user-defined selections using `org-agenda-skip-function'.")
  4158. (defvar org-agenda-overriding-header nil
  4159. "When set during agenda, todo and tags searches it replaces the header.
  4160. This variable should not be set directly, but custom commands can bind it
  4161. in the options section.")
  4162. (defun org-agenda-skip-entry-when-regexp-matches ()
  4163. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4164. If yes, it returns the end position of this entry, causing agenda commands
  4165. to skip the entry but continuing the search in the subtree. This is a
  4166. function that can be put into `org-agenda-skip-function' for the duration
  4167. of a command."
  4168. (let ((end (save-excursion (org-end-of-subtree t)))
  4169. skip)
  4170. (save-excursion
  4171. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4172. (and skip end)))
  4173. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4174. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4175. If yes, it returns the end position of this tree, causing agenda commands
  4176. to skip this subtree. This is a function that can be put into
  4177. `org-agenda-skip-function' for the duration of a command."
  4178. (let ((end (save-excursion (org-end-of-subtree t)))
  4179. skip)
  4180. (save-excursion
  4181. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4182. (and skip end)))
  4183. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4184. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4185. If yes, it returns the end position of the current entry (NOT the tree),
  4186. causing agenda commands to skip the entry but continuing the search in
  4187. the subtree. This is a function that can be put into
  4188. `org-agenda-skip-function' for the duration of a command. An important
  4189. use of this function is for the stuck project list."
  4190. (let ((end (save-excursion (org-end-of-subtree t)))
  4191. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4192. skip)
  4193. (save-excursion
  4194. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4195. (and skip entry-end)))
  4196. (defun org-agenda-skip-entry-if (&rest conditions)
  4197. "Skip entry if any of CONDITIONS is true.
  4198. See `org-agenda-skip-if' for details."
  4199. (org-agenda-skip-if nil conditions))
  4200. (defun org-agenda-skip-subtree-if (&rest conditions)
  4201. "Skip entry if any of CONDITIONS is true.
  4202. See `org-agenda-skip-if' for details."
  4203. (org-agenda-skip-if t conditions))
  4204. (defun org-agenda-skip-if (subtree conditions)
  4205. "Checks current entity for CONDITIONS.
  4206. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4207. the entry (i.e. the text before the next heading) is checked.
  4208. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4209. from different tests. Valid conditions are:
  4210. scheduled Check if there is a scheduled cookie
  4211. notscheduled Check if there is no scheduled cookie
  4212. deadline Check if there is a deadline
  4213. notdeadline Check if there is no deadline
  4214. timestamp Check if there is a timestamp (also deadline or scheduled)
  4215. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4216. regexp Check if regexp matches
  4217. notregexp Check if regexp does not match.
  4218. todo Check if TODO keyword matches
  4219. nottodo Check if TODO keyword does not match
  4220. The regexp is taken from the conditions list, it must come right after
  4221. the `regexp' or `notregexp' element.
  4222. `todo' and `nottodo' accept as an argument a list of todo
  4223. keywords, which may include \"*\" to match any todo keyword.
  4224. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4225. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4226. Instead of a list, a keyword class may be given. For example:
  4227. (org-agenda-skip-entry-if 'nottodo 'done)
  4228. would skip entries that haven't been marked with any of \"DONE\"
  4229. keywords. Possible classes are: `todo', `done', `any'.
  4230. If any of these conditions is met, this function returns the end point of
  4231. the entity, causing the search to continue from there. This is a function
  4232. that can be put into `org-agenda-skip-function' for the duration of a command."
  4233. (let (beg end m)
  4234. (org-back-to-heading t)
  4235. (setq beg (point)
  4236. end (if subtree
  4237. (progn (org-end-of-subtree t) (point))
  4238. (progn (outline-next-heading) (1- (point)))))
  4239. (goto-char beg)
  4240. (and
  4241. (or
  4242. (and (memq 'scheduled conditions)
  4243. (re-search-forward org-scheduled-time-regexp end t))
  4244. (and (memq 'notscheduled conditions)
  4245. (not (re-search-forward org-scheduled-time-regexp end t)))
  4246. (and (memq 'deadline conditions)
  4247. (re-search-forward org-deadline-time-regexp end t))
  4248. (and (memq 'notdeadline conditions)
  4249. (not (re-search-forward org-deadline-time-regexp end t)))
  4250. (and (memq 'timestamp conditions)
  4251. (re-search-forward org-ts-regexp end t))
  4252. (and (memq 'nottimestamp conditions)
  4253. (not (re-search-forward org-ts-regexp end t)))
  4254. (and (setq m (memq 'regexp conditions))
  4255. (stringp (nth 1 m))
  4256. (re-search-forward (nth 1 m) end t))
  4257. (and (setq m (memq 'notregexp conditions))
  4258. (stringp (nth 1 m))
  4259. (not (re-search-forward (nth 1 m) end t)))
  4260. (and (or
  4261. (setq m (memq 'nottodo conditions))
  4262. (setq m (memq 'todo-unblocked conditions))
  4263. (setq m (memq 'nottodo-unblocked conditions))
  4264. (setq m (memq 'todo conditions)))
  4265. (org-agenda-skip-if-todo m end)))
  4266. end)))
  4267. (defun org-agenda-skip-if-todo (args end)
  4268. "Helper function for `org-agenda-skip-if', do not use it directly.
  4269. ARGS is a list with first element either `todo', `nottodo',
  4270. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4271. a list of TODO keywords, or a state symbol `todo' or `done' or
  4272. `any'."
  4273. (let ((kw (car args))
  4274. (arg (cadr args))
  4275. todo-wds todo-re)
  4276. (setq todo-wds
  4277. (org-uniquify
  4278. (cond
  4279. ((listp arg) ;; list of keywords
  4280. (if (member "*" arg)
  4281. (mapcar 'substring-no-properties org-todo-keywords-1)
  4282. arg))
  4283. ((symbolp arg) ;; keyword class name
  4284. (cond
  4285. ((eq arg 'todo)
  4286. (org-delete-all org-done-keywords
  4287. (mapcar 'substring-no-properties
  4288. org-todo-keywords-1)))
  4289. ((eq arg 'done) org-done-keywords)
  4290. ((eq arg 'any)
  4291. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4292. (setq todo-re
  4293. (concat "^\\*+[ \t]+\\<\\("
  4294. (mapconcat 'identity todo-wds "\\|")
  4295. "\\)\\>"))
  4296. (cond
  4297. ((eq kw 'todo) (re-search-forward todo-re end t))
  4298. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4299. ((eq kw 'todo-unblocked)
  4300. (catch 'unblocked
  4301. (while (re-search-forward todo-re end t)
  4302. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4303. nil))
  4304. ((eq kw 'nottodo-unblocked)
  4305. (catch 'unblocked
  4306. (while (re-search-forward todo-re end t)
  4307. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4308. t))
  4309. )))
  4310. ;;;###autoload
  4311. (defun org-agenda-list-stuck-projects (&rest ignore)
  4312. "Create agenda view for projects that are stuck.
  4313. Stuck projects are project that have no next actions. For the definitions
  4314. of what a project is and how to check if it stuck, customize the variable
  4315. `org-stuck-projects'."
  4316. (interactive)
  4317. (let* ((org-agenda-skip-function
  4318. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4319. ;; We could have used org-agenda-skip-if here.
  4320. (org-agenda-overriding-header
  4321. (or org-agenda-overriding-header "List of stuck projects: "))
  4322. (matcher (nth 0 org-stuck-projects))
  4323. (todo (nth 1 org-stuck-projects))
  4324. (todo-wds (if (member "*" todo)
  4325. (progn
  4326. (org-agenda-prepare-buffers (org-agenda-files
  4327. nil 'ifmode))
  4328. (org-delete-all
  4329. org-done-keywords-for-agenda
  4330. (copy-sequence org-todo-keywords-for-agenda)))
  4331. todo))
  4332. (todo-re (concat "^\\*+[ \t]+\\("
  4333. (mapconcat 'identity todo-wds "\\|")
  4334. "\\)\\>"))
  4335. (tags (nth 2 org-stuck-projects))
  4336. (tags-re (if (member "*" tags)
  4337. (concat org-outline-regexp-bol
  4338. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4339. (if tags
  4340. (concat org-outline-regexp-bol
  4341. ".*:\\("
  4342. (mapconcat 'identity tags "\\|")
  4343. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4344. (gen-re (nth 3 org-stuck-projects))
  4345. (re-list
  4346. (delq nil
  4347. (list
  4348. (if todo todo-re)
  4349. (if tags tags-re)
  4350. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4351. gen-re)))))
  4352. (setq org-agenda-skip-regexp
  4353. (if re-list
  4354. (mapconcat 'identity re-list "\\|")
  4355. (error "No information how to identify unstuck projects")))
  4356. (org-tags-view nil matcher)
  4357. (with-current-buffer org-agenda-buffer-name
  4358. (setq org-agenda-redo-command
  4359. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4360. ;;; Diary integration
  4361. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4362. (defvar diary-list-entries-hook)
  4363. (defvar diary-time-regexp)
  4364. (defun org-get-entries-from-diary (date)
  4365. "Get the (Emacs Calendar) diary entries for DATE."
  4366. (require 'diary-lib)
  4367. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4368. (diary-display-hook '(fancy-diary-display))
  4369. (diary-display-function 'fancy-diary-display)
  4370. (pop-up-frames nil)
  4371. (diary-list-entries-hook
  4372. (cons 'org-diary-default-entry diary-list-entries-hook))
  4373. (diary-file-name-prefix-function nil) ; turn this feature off
  4374. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4375. entries
  4376. (org-disable-agenda-to-diary t))
  4377. (save-excursion
  4378. (save-window-excursion
  4379. (funcall (if (fboundp 'diary-list-entries)
  4380. 'diary-list-entries 'list-diary-entries)
  4381. date 1)))
  4382. (if (not (get-buffer diary-fancy-buffer))
  4383. (setq entries nil)
  4384. (with-current-buffer diary-fancy-buffer
  4385. (setq buffer-read-only nil)
  4386. (if (zerop (buffer-size))
  4387. ;; No entries
  4388. (setq entries nil)
  4389. ;; Omit the date and other unnecessary stuff
  4390. (org-agenda-cleanup-fancy-diary)
  4391. ;; Add prefix to each line and extend the text properties
  4392. (if (zerop (buffer-size))
  4393. (setq entries nil)
  4394. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4395. (setq entries
  4396. (with-temp-buffer
  4397. (insert entries) (goto-char (point-min))
  4398. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4399. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4400. (replace-match (concat "; " (match-string 1)))))
  4401. (buffer-string)))))
  4402. (set-buffer-modified-p nil)
  4403. (kill-buffer diary-fancy-buffer)))
  4404. (when entries
  4405. (setq entries (org-split-string entries "\n"))
  4406. (setq entries
  4407. (mapcar
  4408. (lambda (x)
  4409. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4410. ;; Extend the text properties to the beginning of the line
  4411. (org-add-props x (text-properties-at (1- (length x)) x)
  4412. 'type "diary" 'date date 'face 'org-agenda-diary))
  4413. entries)))))
  4414. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4415. "Hook run when the fancy diary buffer is cleaned up.")
  4416. (defun org-agenda-cleanup-fancy-diary ()
  4417. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4418. This gets rid of the date, the underline under the date, and
  4419. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4420. date. It also removes lines that contain only whitespace."
  4421. (goto-char (point-min))
  4422. (if (looking-at ".*?:[ \t]*")
  4423. (progn
  4424. (replace-match "")
  4425. (re-search-forward "\n=+$" nil t)
  4426. (replace-match "")
  4427. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4428. (re-search-forward "\n=+$" nil t)
  4429. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4430. (goto-char (point-min))
  4431. (while (re-search-forward "^ +\n" nil t)
  4432. (replace-match ""))
  4433. (goto-char (point-min))
  4434. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4435. (replace-match ""))
  4436. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4437. ;; Make sure entries from the diary have the right text properties.
  4438. (eval-after-load "diary-lib"
  4439. '(if (boundp 'diary-modify-entry-list-string-function)
  4440. ;; We can rely on the hook, nothing to do
  4441. nil
  4442. ;; Hook not available, must use advice to make this work
  4443. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4444. "Make the position visible."
  4445. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4446. (stringp string)
  4447. buffer-file-name)
  4448. (setq string (org-modify-diary-entry-string string))))))
  4449. (defun org-modify-diary-entry-string (string)
  4450. "Add text properties to string, allowing org-mode to act on it."
  4451. (org-add-props string nil
  4452. 'mouse-face 'highlight
  4453. 'help-echo (if buffer-file-name
  4454. (format "mouse-2 or RET jump to diary file %s"
  4455. (abbreviate-file-name buffer-file-name))
  4456. "")
  4457. 'org-agenda-diary-link t
  4458. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4459. (defun org-diary-default-entry ()
  4460. "Add a dummy entry to the diary.
  4461. Needed to avoid empty dates which mess up holiday display."
  4462. ;; Catch the error if dealing with the new add-to-diary-alist
  4463. (when org-disable-agenda-to-diary
  4464. (condition-case nil
  4465. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4466. (error
  4467. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4468. (defun org-add-to-diary-list (&rest args)
  4469. (if (fboundp 'diary-add-to-list)
  4470. (apply 'diary-add-to-list args)
  4471. (apply 'add-to-diary-list args)))
  4472. (defvar org-diary-last-run-time nil)
  4473. ;;;###autoload
  4474. (defun org-diary (&rest args)
  4475. "Return diary information from org files.
  4476. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4477. It accesses org files and extracts information from those files to be
  4478. listed in the diary. The function accepts arguments specifying what
  4479. items should be listed. For a list of arguments allowed here, see the
  4480. variable `org-agenda-entry-types'.
  4481. The call in the diary file should look like this:
  4482. &%%(org-diary) ~/path/to/some/orgfile.org
  4483. Use a separate line for each org file to check. Or, if you omit the file name,
  4484. all files listed in `org-agenda-files' will be checked automatically:
  4485. &%%(org-diary)
  4486. If you don't give any arguments (as in the example above), the default
  4487. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4488. So the example above may also be written as
  4489. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4490. The function expects the lisp variables `entry' and `date' to be provided
  4491. by the caller, because this is how the calendar works. Don't use this
  4492. function from a program - use `org-agenda-get-day-entries' instead."
  4493. (when (> (- (org-float-time)
  4494. org-agenda-last-marker-time)
  4495. 5)
  4496. ;; I am not sure if this works with sticky agendas, because the marker
  4497. ;; list is then no longer a global variable.
  4498. (org-agenda-reset-markers))
  4499. (org-compile-prefix-format 'agenda)
  4500. (org-set-sorting-strategy 'agenda)
  4501. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4502. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4503. (list entry)
  4504. (org-agenda-files t)))
  4505. (time (org-float-time))
  4506. file rtn results)
  4507. (when (or (not org-diary-last-run-time)
  4508. (> (- time
  4509. org-diary-last-run-time)
  4510. 3))
  4511. (org-agenda-prepare-buffers files))
  4512. (setq org-diary-last-run-time time)
  4513. ;; If this is called during org-agenda, don't return any entries to
  4514. ;; the calendar. Org Agenda will list these entries itself.
  4515. (if org-disable-agenda-to-diary (setq files nil))
  4516. (while (setq file (pop files))
  4517. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4518. (setq results (append results rtn)))
  4519. (if results
  4520. (concat (org-agenda-finalize-entries results) "\n"))))
  4521. ;;; Agenda entry finders
  4522. (defun org-agenda-get-day-entries (file date &rest args)
  4523. "Does the work for `org-diary' and `org-agenda'.
  4524. FILE is the path to a file to be checked for entries. DATE is date like
  4525. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4526. which kind of entries should be extracted. For details about these, see
  4527. the documentation of `org-diary'."
  4528. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4529. (let* ((org-startup-folded nil)
  4530. (org-startup-align-all-tables nil)
  4531. (buffer (if (file-exists-p file)
  4532. (org-get-agenda-file-buffer file)
  4533. (error "No such file %s" file)))
  4534. arg results rtn deadline-results)
  4535. (if (not buffer)
  4536. ;; If file does not exist, make sure an error message ends up in diary
  4537. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4538. (with-current-buffer buffer
  4539. (unless (derived-mode-p 'org-mode)
  4540. (error "Agenda file %s is not in `org-mode'" file))
  4541. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4542. (let ((case-fold-search nil))
  4543. (save-excursion
  4544. (save-restriction
  4545. (if org-agenda-restrict
  4546. (narrow-to-region org-agenda-restrict-begin
  4547. org-agenda-restrict-end)
  4548. (widen))
  4549. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4550. (while (setq arg (pop args))
  4551. (cond
  4552. ((and (eq arg :todo)
  4553. (equal date (calendar-gregorian-from-absolute
  4554. (org-today))))
  4555. (setq rtn (org-agenda-get-todos))
  4556. (setq results (append results rtn)))
  4557. ((eq arg :timestamp)
  4558. (setq rtn (org-agenda-get-blocks))
  4559. (setq results (append results rtn))
  4560. (setq rtn (org-agenda-get-timestamps deadline-results))
  4561. (setq results (append results rtn)))
  4562. ((eq arg :sexp)
  4563. (setq rtn (org-agenda-get-sexps))
  4564. (setq results (append results rtn)))
  4565. ((eq arg :scheduled)
  4566. (setq rtn (org-agenda-get-scheduled deadline-results))
  4567. (setq results (append results rtn)))
  4568. ((eq arg :closed)
  4569. (setq rtn (org-agenda-get-progress))
  4570. (setq results (append results rtn)))
  4571. ((eq arg :deadline)
  4572. (setq rtn (org-agenda-get-deadlines))
  4573. (setq deadline-results (copy-sequence rtn))
  4574. (setq results (append results rtn))))))))
  4575. results))))
  4576. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4577. (defun org-agenda-get-todos ()
  4578. "Return the TODO information for agenda display."
  4579. (let* ((props (list 'face nil
  4580. 'done-face 'org-agenda-done
  4581. 'org-not-done-regexp org-not-done-regexp
  4582. 'org-todo-regexp org-todo-regexp
  4583. 'org-complex-heading-regexp org-complex-heading-regexp
  4584. 'mouse-face 'highlight
  4585. 'help-echo
  4586. (format "mouse-2 or RET jump to org file %s"
  4587. (abbreviate-file-name buffer-file-name))))
  4588. (regexp (format org-heading-keyword-regexp-format
  4589. (cond
  4590. ((and org-select-this-todo-keyword
  4591. (equal org-select-this-todo-keyword "*"))
  4592. org-todo-regexp)
  4593. (org-select-this-todo-keyword
  4594. (concat "\\("
  4595. (mapconcat 'identity
  4596. (org-split-string
  4597. org-select-this-todo-keyword
  4598. "|")
  4599. "\\|") "\\)"))
  4600. (t org-not-done-regexp))))
  4601. marker priority category category-pos level tags todo-state
  4602. ee txt beg end)
  4603. (goto-char (point-min))
  4604. (while (re-search-forward regexp nil t)
  4605. (catch :skip
  4606. (save-match-data
  4607. (beginning-of-line)
  4608. (org-agenda-skip)
  4609. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4610. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4611. (goto-char (1+ beg))
  4612. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4613. (throw :skip nil)))
  4614. (goto-char (match-beginning 2))
  4615. (setq marker (org-agenda-new-marker (match-beginning 0))
  4616. category (org-get-category)
  4617. category-pos (get-text-property (point) 'org-category-position)
  4618. txt (org-trim
  4619. (buffer-substring (match-beginning 2) (match-end 0)))
  4620. tags (org-get-tags-at (point))
  4621. level (make-string
  4622. (1- (string-to-number
  4623. (substring (symbol-name (get-text-property
  4624. (match-beginning 0) 'face)) 10))) ? )
  4625. txt (org-agenda-format-item "" txt level category tags)
  4626. priority (1+ (org-get-priority txt))
  4627. todo-state (org-get-todo-state))
  4628. (org-add-props txt props
  4629. 'org-marker marker 'org-hd-marker marker
  4630. 'priority priority 'org-category category
  4631. 'level level
  4632. 'org-category-position category-pos
  4633. 'type "todo" 'todo-state todo-state)
  4634. (push txt ee)
  4635. (if org-agenda-todo-list-sublevels
  4636. (goto-char (match-end 2))
  4637. (org-end-of-subtree 'invisible))))
  4638. (nreverse ee)))
  4639. (defun org-agenda-todo-custom-ignore-p (time n)
  4640. "Check whether timestamp is farther away then n number of days.
  4641. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4642. `org-agenda-todo-ignore-scheduled' or
  4643. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4644. (let ((days (org-days-to-time time)))
  4645. (if (>= n 0)
  4646. (>= days n)
  4647. (<= days n))))
  4648. ;;;###autoload
  4649. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4650. (&optional end)
  4651. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4652. (when (or org-agenda-todo-ignore-with-date
  4653. org-agenda-todo-ignore-scheduled
  4654. org-agenda-todo-ignore-deadlines
  4655. org-agenda-todo-ignore-timestamp)
  4656. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4657. (save-excursion
  4658. (or (and org-agenda-todo-ignore-with-date
  4659. (re-search-forward org-ts-regexp end t))
  4660. (and org-agenda-todo-ignore-scheduled
  4661. (re-search-forward org-scheduled-time-regexp end t)
  4662. (cond
  4663. ((eq org-agenda-todo-ignore-scheduled 'future)
  4664. (> (org-days-to-time (match-string 1)) 0))
  4665. ((eq org-agenda-todo-ignore-scheduled 'past)
  4666. (<= (org-days-to-time (match-string 1)) 0))
  4667. ((numberp org-agenda-todo-ignore-scheduled)
  4668. (org-agenda-todo-custom-ignore-p
  4669. (match-string 1) org-agenda-todo-ignore-scheduled))
  4670. (t)))
  4671. (and org-agenda-todo-ignore-deadlines
  4672. (re-search-forward org-deadline-time-regexp end t)
  4673. (cond
  4674. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4675. ((eq org-agenda-todo-ignore-deadlines 'far)
  4676. (not (org-deadline-close (match-string 1))))
  4677. ((eq org-agenda-todo-ignore-deadlines 'future)
  4678. (> (org-days-to-time (match-string 1)) 0))
  4679. ((eq org-agenda-todo-ignore-deadlines 'past)
  4680. (<= (org-days-to-time (match-string 1)) 0))
  4681. ((numberp org-agenda-todo-ignore-deadlines)
  4682. (org-agenda-todo-custom-ignore-p
  4683. (match-string 1) org-agenda-todo-ignore-deadlines))
  4684. (t (org-deadline-close (match-string 1)))))
  4685. (and org-agenda-todo-ignore-timestamp
  4686. (let ((buffer (current-buffer))
  4687. (regexp
  4688. (concat
  4689. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4690. (start (point)))
  4691. ;; Copy current buffer into a temporary one
  4692. (with-temp-buffer
  4693. (insert-buffer-substring buffer start end)
  4694. (goto-char (point-min))
  4695. ;; Delete SCHEDULED and DEADLINE items
  4696. (while (re-search-forward regexp end t)
  4697. (delete-region (match-beginning 0) (match-end 0)))
  4698. (goto-char (point-min))
  4699. ;; No search for timestamp left
  4700. (when (re-search-forward org-ts-regexp nil t)
  4701. (cond
  4702. ((eq org-agenda-todo-ignore-timestamp 'future)
  4703. (> (org-days-to-time (match-string 1)) 0))
  4704. ((eq org-agenda-todo-ignore-timestamp 'past)
  4705. (<= (org-days-to-time (match-string 1)) 0))
  4706. ((numberp org-agenda-todo-ignore-timestamp)
  4707. (org-agenda-todo-custom-ignore-p
  4708. (match-string 1) org-agenda-todo-ignore-timestamp))
  4709. (t))))))))))
  4710. (defconst org-agenda-no-heading-message
  4711. "No heading for this item in buffer or region.")
  4712. (defun org-agenda-get-timestamps (&optional deadline-results)
  4713. "Return the date stamp information for agenda display."
  4714. (let* ((props (list 'face 'org-agenda-calendar-event
  4715. 'org-not-done-regexp org-not-done-regexp
  4716. 'org-todo-regexp org-todo-regexp
  4717. 'org-complex-heading-regexp org-complex-heading-regexp
  4718. 'mouse-face 'highlight
  4719. 'help-echo
  4720. (format "mouse-2 or RET jump to org file %s"
  4721. (abbreviate-file-name buffer-file-name))))
  4722. (d1 (calendar-absolute-from-gregorian date))
  4723. mm
  4724. (deadline-position-alist
  4725. (mapcar (lambda (a) (and (setq mm (get-text-property
  4726. 0 'org-hd-marker a))
  4727. (cons (marker-position mm) a)))
  4728. deadline-results))
  4729. (remove-re org-ts-regexp)
  4730. (regexp
  4731. (concat
  4732. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4733. (regexp-quote
  4734. (substring
  4735. (format-time-string
  4736. (car org-time-stamp-formats)
  4737. (apply 'encode-time ; DATE bound by calendar
  4738. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4739. 1 11))
  4740. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4741. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4742. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4743. donep tmp priority category category-pos level ee txt timestr tags
  4744. b0 b3 e3 head todo-state end-of-match show-all warntime)
  4745. (goto-char (point-min))
  4746. (while (setq end-of-match (re-search-forward regexp nil t))
  4747. (setq b0 (match-beginning 0)
  4748. b3 (match-beginning 3) e3 (match-end 3)
  4749. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4750. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4751. (member todo-state
  4752. org-agenda-repeating-timestamp-show-all)))
  4753. (catch :skip
  4754. (and (org-at-date-range-p) (throw :skip nil))
  4755. (org-agenda-skip)
  4756. (if (and (match-end 1)
  4757. (not (= d1 (org-time-string-to-absolute
  4758. (match-string 1) d1 nil show-all
  4759. (current-buffer) b0))))
  4760. (throw :skip nil))
  4761. (if (and e3
  4762. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4763. (throw :skip nil))
  4764. (setq tmp (buffer-substring (max (point-min)
  4765. (- b0 org-ds-keyword-length))
  4766. b0)
  4767. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4768. inactivep (= (char-after b0) ?\[)
  4769. deadlinep (string-match org-deadline-regexp tmp)
  4770. scheduledp (string-match org-scheduled-regexp tmp)
  4771. closedp (and org-agenda-include-inactive-timestamps
  4772. (string-match org-closed-string tmp))
  4773. clockp (and org-agenda-include-inactive-timestamps
  4774. (or (string-match org-clock-string tmp)
  4775. (string-match "]-+\\'" tmp)))
  4776. warntime (org-entry-get (point) "APPT_WARNTIME")
  4777. donep (member todo-state org-done-keywords))
  4778. (if (or scheduledp deadlinep closedp clockp
  4779. (and donep org-agenda-skip-timestamp-if-done))
  4780. (throw :skip t))
  4781. (if (string-match ">" timestr)
  4782. ;; substring should only run to end of time stamp
  4783. (setq timestr (substring timestr 0 (match-end 0))))
  4784. (setq marker (org-agenda-new-marker b0)
  4785. category (org-get-category b0)
  4786. category-pos (get-text-property b0 'org-category-position))
  4787. (save-excursion
  4788. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4789. (setq txt org-agenda-no-heading-message)
  4790. (goto-char (match-beginning 0))
  4791. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4792. (assoc (point) deadline-position-alist))
  4793. (throw :skip nil))
  4794. (setq hdmarker (org-agenda-new-marker)
  4795. tags (org-get-tags-at)
  4796. level
  4797. (make-string
  4798. (1- (string-to-number
  4799. (substring (symbol-name (get-text-property (point) 'face)) 10))) ? ))
  4800. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4801. (setq head (or (match-string 1) ""))
  4802. (setq txt (org-agenda-format-item
  4803. (if inactivep org-agenda-inactive-leader nil)
  4804. head level category tags timestr
  4805. remove-re)))
  4806. (setq priority (org-get-priority txt))
  4807. (org-add-props txt props 'priority priority
  4808. 'org-marker marker 'org-hd-marker hdmarker
  4809. 'org-category category 'date date
  4810. 'level level
  4811. 'org-category-position category-pos
  4812. 'todo-state todo-state
  4813. 'warntime warntime
  4814. 'type "timestamp")
  4815. (push txt ee))
  4816. (if org-agenda-skip-additional-timestamps-same-entry
  4817. (outline-next-heading)
  4818. (goto-char end-of-match))))
  4819. (nreverse ee)))
  4820. (defun org-agenda-get-sexps ()
  4821. "Return the sexp information for agenda display."
  4822. (require 'diary-lib)
  4823. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4824. 'mouse-face 'highlight
  4825. 'help-echo
  4826. (format "mouse-2 or RET jump to org file %s"
  4827. (abbreviate-file-name buffer-file-name))))
  4828. (regexp "^&?%%(")
  4829. marker category extra category-pos level ee txt tags entry
  4830. result beg b sexp sexp-entry todo-state warntime)
  4831. (goto-char (point-min))
  4832. (while (re-search-forward regexp nil t)
  4833. (catch :skip
  4834. (org-agenda-skip)
  4835. (setq beg (match-beginning 0))
  4836. (goto-char (1- (match-end 0)))
  4837. (setq b (point))
  4838. (forward-sexp 1)
  4839. (setq sexp (buffer-substring b (point)))
  4840. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4841. (org-trim (match-string 1))
  4842. ""))
  4843. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4844. (when result
  4845. (setq marker (org-agenda-new-marker beg)
  4846. level (make-string
  4847. (1- (string-to-number
  4848. (substring (symbol-name (get-text-property beg 'face)) 10))) ? )
  4849. category (org-get-category beg)
  4850. category-pos (get-text-property beg 'org-category-position)
  4851. tags (save-excursion (org-backward-heading-same-level 0)
  4852. (org-get-tags-at))
  4853. todo-state (org-get-todo-state)
  4854. warntime (org-entry-get (point) "APPT_WARNTIME"))
  4855. (dolist (r (if (stringp result)
  4856. (list result)
  4857. result)) ;; we expect a list here
  4858. (when (and org-agenda-diary-sexp-prefix
  4859. (string-match org-agenda-diary-sexp-prefix r))
  4860. (setq extra (match-string 0 r)
  4861. r (replace-match "" nil nil r)))
  4862. (if (string-match "\\S-" r)
  4863. (setq txt r)
  4864. (setq txt "SEXP entry returned empty string"))
  4865. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  4866. (org-add-props txt props 'org-marker marker
  4867. 'org-category category 'date date 'todo-state todo-state
  4868. 'org-category-position category-pos 'tags tags
  4869. 'level level
  4870. 'type "sexp" 'warntime warntime)
  4871. (push txt ee)))))
  4872. (nreverse ee)))
  4873. ;; Calendar sanity: define some functions that are independent of
  4874. ;; `calendar-date-style'.
  4875. ;; Normally I would like to use ISO format when calling the diary functions,
  4876. ;; but to make sure we still have Emacs 22 compatibility we bind
  4877. ;; also `european-calendar-style' and use european format
  4878. (defun org-anniversary (year month day &optional mark)
  4879. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4880. (org-no-warnings
  4881. (let ((calendar-date-style 'european) (european-calendar-style t))
  4882. (diary-anniversary day month year mark))))
  4883. (defun org-cyclic (N year month day &optional mark)
  4884. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4885. (org-no-warnings
  4886. (let ((calendar-date-style 'european) (european-calendar-style t))
  4887. (diary-cyclic N day month year mark))))
  4888. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4889. "Like `diary-block', but with fixed (ISO) order of arguments."
  4890. (org-no-warnings
  4891. (let ((calendar-date-style 'european) (european-calendar-style t))
  4892. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4893. (defun org-date (year month day &optional mark)
  4894. "Like `diary-date', but with fixed (ISO) order of arguments."
  4895. (org-no-warnings
  4896. (let ((calendar-date-style 'european) (european-calendar-style t))
  4897. (diary-date day month year mark))))
  4898. (defalias 'org-float 'diary-float)
  4899. ;; Define the` org-class' function
  4900. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4901. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4902. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4903. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4904. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4905. `holidays', then any date that is known by the Emacs calendar to be a
  4906. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  4907. then those holidays will be skipped."
  4908. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4909. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4910. (d (calendar-absolute-from-gregorian date))
  4911. (h (when skip-weeks (calendar-check-holidays date))))
  4912. (and
  4913. (<= date1 d)
  4914. (<= d date2)
  4915. (= (calendar-day-of-week date) dayname)
  4916. (or (not skip-weeks)
  4917. (progn
  4918. (require 'cal-iso)
  4919. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4920. (not (or (and h (memq 'holidays skip-weeks))
  4921. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  4922. entry)))
  4923. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4924. "Like `org-class', but honor `calendar-date-style'.
  4925. The order of the first 2 times 3 arguments depends on the variable
  4926. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4927. So for American calendars, give this as MONTH DAY YEAR, for European as
  4928. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4929. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4930. is any number of ISO weeks in the block period for which the item should
  4931. be skipped.
  4932. This function is here only for backward compatibility and it is deprecated,
  4933. please use `org-class' instead."
  4934. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4935. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4936. (org-class
  4937. (nth 2 date1) (car date1) (nth 1 date1)
  4938. (nth 2 date2) (car date2) (nth 1 date2)
  4939. dayname skip-weeks)))
  4940. (make-obsolete 'org-diary-class 'org-class "")
  4941. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  4942. (defalias 'org-get-closed 'org-agenda-get-progress)
  4943. (defun org-agenda-get-progress ()
  4944. "Return the logged TODO entries for agenda display."
  4945. (let* ((props (list 'mouse-face 'highlight
  4946. 'org-not-done-regexp org-not-done-regexp
  4947. 'org-todo-regexp org-todo-regexp
  4948. 'org-complex-heading-regexp org-complex-heading-regexp
  4949. 'help-echo
  4950. (format "mouse-2 or RET jump to org file %s"
  4951. (abbreviate-file-name buffer-file-name))))
  4952. (items (if (consp org-agenda-show-log-scoped)
  4953. org-agenda-show-log-scoped
  4954. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4955. '(clock)
  4956. org-agenda-log-mode-items)))
  4957. (parts
  4958. (delq nil
  4959. (list
  4960. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4961. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4962. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4963. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4964. (error "`org-agenda-log-mode-items' is empty")))
  4965. (regexp (concat
  4966. "\\(" parts-re "\\)"
  4967. " *\\["
  4968. (regexp-quote
  4969. (substring
  4970. (format-time-string
  4971. (car org-time-stamp-formats)
  4972. (apply 'encode-time ; DATE bound by calendar
  4973. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4974. 1 11))))
  4975. (org-agenda-search-headline-for-time nil)
  4976. marker hdmarker priority category category-pos level tags closedp
  4977. statep clockp state ee txt extra timestr rest clocked)
  4978. (goto-char (point-min))
  4979. (while (re-search-forward regexp nil t)
  4980. (catch :skip
  4981. (org-agenda-skip)
  4982. (setq marker (org-agenda-new-marker (match-beginning 0))
  4983. closedp (equal (match-string 1) org-closed-string)
  4984. statep (equal (string-to-char (match-string 1)) ?-)
  4985. clockp (not (or closedp statep))
  4986. state (and statep (match-string 2))
  4987. category (org-get-category (match-beginning 0))
  4988. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4989. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4990. (when (string-match "\\]" timestr)
  4991. ;; substring should only run to end of time stamp
  4992. (setq rest (substring timestr (match-end 0))
  4993. timestr (substring timestr 0 (match-end 0)))
  4994. (if (and (not closedp) (not statep)
  4995. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4996. rest))
  4997. (progn (setq timestr (concat (substring timestr 0 -1)
  4998. "-" (match-string 1 rest) "]"))
  4999. (setq clocked (match-string 2 rest)))
  5000. (setq clocked "-")))
  5001. (save-excursion
  5002. (setq extra
  5003. (cond
  5004. ((not org-agenda-log-mode-add-notes) nil)
  5005. (statep
  5006. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5007. (match-string 1)))
  5008. (clockp
  5009. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5010. (match-string 1)))))
  5011. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5012. (setq txt org-agenda-no-heading-message)
  5013. (goto-char (match-beginning 0))
  5014. (setq hdmarker (org-agenda-new-marker)
  5015. tags (org-get-tags-at)
  5016. level
  5017. (make-string
  5018. (1- (string-to-number
  5019. (substring (symbol-name (get-text-property (point) 'face)) 10))) ? ))
  5020. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5021. (setq txt (match-string 1))
  5022. (when extra
  5023. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5024. (setq txt (concat (substring txt 0 (match-beginning 1))
  5025. " - " extra " " (match-string 2 txt)))
  5026. (setq txt (concat txt " - " extra))))
  5027. (setq txt (org-agenda-format-item
  5028. (cond
  5029. (closedp "Closed: ")
  5030. (statep (concat "State: (" state ")"))
  5031. (t (concat "Clocked: (" clocked ")")))
  5032. txt level category tags timestr)))
  5033. (setq priority 100000)
  5034. (org-add-props txt props
  5035. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5036. 'priority priority 'org-category category
  5037. 'org-category-position category-pos
  5038. 'level level
  5039. 'type "closed" 'date date
  5040. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5041. (push txt ee))
  5042. (goto-char (point-at-eol))))
  5043. (nreverse ee)))
  5044. (defun org-agenda-show-clocking-issues ()
  5045. "Add overlays, showing issues with clocking.
  5046. See also the user option `org-agenda-clock-consistency-checks'."
  5047. (interactive)
  5048. (let* ((pl org-agenda-clock-consistency-checks)
  5049. (re (concat "^[ \t]*"
  5050. org-clock-string
  5051. "[ \t]+"
  5052. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5053. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5054. (tlstart 0.)
  5055. (tlend 0.)
  5056. (maxtime (org-hh:mm-string-to-minutes
  5057. (or (plist-get pl :max-duration) "24:00")))
  5058. (mintime (org-hh:mm-string-to-minutes
  5059. (or (plist-get pl :min-duration) 0)))
  5060. (maxgap (org-hh:mm-string-to-minutes
  5061. ;; default 30:00 means never complain
  5062. (or (plist-get pl :max-gap) "30:00")))
  5063. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5064. (plist-get pl :gap-ok-around)))
  5065. (def-face (or (plist-get pl :default-face)
  5066. '((:background "DarkRed") (:foreground "white"))))
  5067. issue face m te ts dt ov)
  5068. (goto-char (point-min))
  5069. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5070. (setq issue nil face def-face)
  5071. (catch 'next
  5072. (setq m (org-get-at-bol 'org-marker)
  5073. te nil ts nil)
  5074. (unless (and m (markerp m))
  5075. (setq issue "No valid clock line") (throw 'next t))
  5076. (org-with-point-at m
  5077. (save-excursion
  5078. (goto-char (point-at-bol))
  5079. (unless (looking-at re)
  5080. (error "No valid Clock line")
  5081. (throw 'next t))
  5082. (unless (match-end 3)
  5083. (setq issue "No end time"
  5084. face (or (plist-get pl :no-end-time-face) face))
  5085. (throw 'next t))
  5086. (setq ts (match-string 1)
  5087. te (match-string 3)
  5088. ts (org-float-time
  5089. (apply 'encode-time (org-parse-time-string ts)))
  5090. te (org-float-time
  5091. (apply 'encode-time (org-parse-time-string te)))
  5092. dt (- te ts))))
  5093. (cond
  5094. ((> dt (* 60 maxtime))
  5095. ;; a very long clocking chunk
  5096. (setq issue (format "Clocking interval is very long: %s"
  5097. (org-minutes-to-hh:mm-string
  5098. (floor (/ (float dt) 60.))))
  5099. face (or (plist-get pl :long-face) face)))
  5100. ((< dt (* 60 mintime))
  5101. ;; a very short clocking chunk
  5102. (setq issue (format "Clocking interval is very short: %s"
  5103. (org-minutes-to-hh:mm-string
  5104. (floor (/ (float dt) 60.))))
  5105. face (or (plist-get pl :short-face) face)))
  5106. ((and (> tlend 0) (< ts tlend))
  5107. ;; Two clock entries are overlapping
  5108. (setq issue (format "Clocking overlap: %d minutes"
  5109. (/ (- tlend ts) 60))
  5110. face (or (plist-get pl :overlap-face) face)))
  5111. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5112. ;; There is a gap, lets see if we need to report it
  5113. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5114. (setq issue (format "Clocking gap: %d minutes"
  5115. (/ (- ts tlend) 60))
  5116. face (or (plist-get pl :gap-face) face))))
  5117. (t nil)))
  5118. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5119. (when issue
  5120. ;; OK, there was some issue, add an overlay to show the issue
  5121. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5122. (overlay-put ov 'before-string
  5123. (concat
  5124. (org-add-props
  5125. (format "%-43s" (concat " " issue))
  5126. nil
  5127. 'face face)
  5128. "\n"))
  5129. (overlay-put ov 'evaporate t)))))
  5130. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5131. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5132. (catch 'exit
  5133. (unless ok-list
  5134. ;; there are no OK times for gaps...
  5135. (throw 'exit nil))
  5136. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5137. ;; This is more than 24 hours, so it is OK.
  5138. ;; because we have at least one OK time, that must be in the
  5139. ;; 24 hour interval.
  5140. (throw 'exit t))
  5141. ;; We have a shorter gap.
  5142. ;; Now we have to get the minute of the day when these times are
  5143. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5144. (t2dec (decode-time (seconds-to-time t2)))
  5145. ;; compute the minute on the day
  5146. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5147. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5148. (when (< min2 min1)
  5149. ;; if min2 is smaller than min1, this means it is on the next day.
  5150. ;; Wrap it to after midnight.
  5151. (setq min2 (+ min2 1440)))
  5152. ;; Now check if any of the OK times is in the gap
  5153. (mapc (lambda (x)
  5154. ;; Wrap the time to after midnight if necessary
  5155. (if (< x min1) (setq x (+ x 1440)))
  5156. ;; Check if in interval
  5157. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5158. ok-list)
  5159. ;; Nope, this gap is not OK
  5160. nil)))
  5161. (defun org-agenda-get-deadlines ()
  5162. "Return the deadline information for agenda display."
  5163. (let* ((props (list 'mouse-face 'highlight
  5164. 'org-not-done-regexp org-not-done-regexp
  5165. 'org-todo-regexp org-todo-regexp
  5166. 'org-complex-heading-regexp org-complex-heading-regexp
  5167. 'help-echo
  5168. (format "mouse-2 or RET jump to org file %s"
  5169. (abbreviate-file-name buffer-file-name))))
  5170. (regexp org-deadline-time-regexp)
  5171. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5172. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5173. d2 diff dfrac wdays pos pos1 category category-pos level
  5174. tags suppress-prewarning ee txt head face s todo-state
  5175. show-all upcomingp donep timestr warntime)
  5176. (goto-char (point-min))
  5177. (while (re-search-forward regexp nil t)
  5178. (setq suppress-prewarning nil)
  5179. (catch :skip
  5180. (org-agenda-skip)
  5181. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5182. (save-match-data
  5183. (string-match org-scheduled-time-regexp
  5184. (buffer-substring (point-at-bol)
  5185. (point-at-eol)))))
  5186. (setq suppress-prewarning
  5187. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5188. org-agenda-skip-deadline-prewarning-if-scheduled
  5189. 0)))
  5190. (setq s (match-string 1)
  5191. txt nil
  5192. pos (1- (match-beginning 1))
  5193. todo-state (save-match-data (org-get-todo-state))
  5194. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5195. (member todo-state
  5196. org-agenda-repeating-timestamp-show-all))
  5197. d2 (org-time-string-to-absolute
  5198. (match-string 1) d1 'past show-all
  5199. (current-buffer) pos)
  5200. diff (- d2 d1)
  5201. wdays (if suppress-prewarning
  5202. (let ((org-deadline-warning-days suppress-prewarning))
  5203. (org-get-wdays s))
  5204. (org-get-wdays s))
  5205. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5206. upcomingp (and todayp (> diff 0)))
  5207. ;; When to show a deadline in the calendar:
  5208. ;; If the expiration is within wdays warning time.
  5209. ;; Past-due deadlines are only shown on the current date
  5210. (if (and (or (and (<= diff wdays)
  5211. (and todayp (not org-agenda-only-exact-dates)))
  5212. (= diff 0)))
  5213. (save-excursion
  5214. ;; (setq todo-state (org-get-todo-state))
  5215. (setq donep (member todo-state org-done-keywords))
  5216. (if (and donep
  5217. (or org-agenda-skip-deadline-if-done
  5218. (not (= diff 0))))
  5219. (setq txt nil)
  5220. (setq category (org-get-category)
  5221. warntime (org-entry-get (point) "APPT_WARNTIME")
  5222. category-pos (get-text-property (point) 'org-category-position))
  5223. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5224. (setq txt org-agenda-no-heading-message)
  5225. (goto-char (match-end 0))
  5226. (setq pos1 (match-beginning 0))
  5227. (setq level
  5228. (make-string
  5229. (1- (string-to-number
  5230. (substring (symbol-name (get-text-property pos1 'face)) 10))) ? ))
  5231. (setq tags (org-get-tags-at pos1))
  5232. (setq head (buffer-substring-no-properties
  5233. (point)
  5234. (progn (skip-chars-forward "^\r\n")
  5235. (point))))
  5236. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5237. (setq timestr
  5238. (concat (substring s (match-beginning 1)) " "))
  5239. (setq timestr 'time))
  5240. (setq txt (org-agenda-format-item
  5241. (if (= diff 0)
  5242. (car org-agenda-deadline-leaders)
  5243. (if (functionp
  5244. (nth 1 org-agenda-deadline-leaders))
  5245. (funcall
  5246. (nth 1 org-agenda-deadline-leaders)
  5247. diff date)
  5248. (format (nth 1 org-agenda-deadline-leaders)
  5249. diff)))
  5250. head level category tags
  5251. (if (not (= diff 0)) nil timestr)))))
  5252. (when txt
  5253. (setq face (org-agenda-deadline-face dfrac))
  5254. (org-add-props txt props
  5255. 'org-marker (org-agenda-new-marker pos)
  5256. 'warntime warntime
  5257. 'level level
  5258. 'org-hd-marker (org-agenda-new-marker pos1)
  5259. 'priority (+ (- diff)
  5260. (org-get-priority txt))
  5261. 'org-category category
  5262. 'org-category-position category-pos
  5263. 'todo-state todo-state
  5264. 'type (if upcomingp "upcoming-deadline" "deadline")
  5265. 'date (if upcomingp date d2)
  5266. 'face (if donep 'org-agenda-done face)
  5267. 'undone-face face 'done-face 'org-agenda-done)
  5268. (push txt ee))))))
  5269. (nreverse ee)))
  5270. (defun org-agenda-deadline-face (fraction)
  5271. "Return the face to displaying a deadline item.
  5272. FRACTION is what fraction of the head-warning time has passed."
  5273. (let ((faces org-agenda-deadline-faces) f)
  5274. (catch 'exit
  5275. (while (setq f (pop faces))
  5276. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5277. (defun org-agenda-get-scheduled (&optional deadline-results)
  5278. "Return the scheduled information for agenda display."
  5279. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5280. 'org-todo-regexp org-todo-regexp
  5281. 'org-complex-heading-regexp org-complex-heading-regexp
  5282. 'done-face 'org-agenda-done
  5283. 'mouse-face 'highlight
  5284. 'help-echo
  5285. (format "mouse-2 or RET jump to org file %s"
  5286. (abbreviate-file-name buffer-file-name))))
  5287. (regexp org-scheduled-time-regexp)
  5288. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5289. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5290. mm
  5291. (deadline-position-alist
  5292. (mapcar (lambda (a) (and (setq mm (get-text-property
  5293. 0 'org-hd-marker a))
  5294. (cons (marker-position mm) a)))
  5295. deadline-results))
  5296. d2 diff pos pos1 category category-pos level tags donep
  5297. ee txt head pastschedp todo-state face timestr s habitp show-all
  5298. did-habit-check-p warntime)
  5299. (goto-char (point-min))
  5300. (while (re-search-forward regexp nil t)
  5301. (catch :skip
  5302. (org-agenda-skip)
  5303. (setq s (match-string 1)
  5304. txt nil
  5305. pos (1- (match-beginning 1))
  5306. todo-state (save-match-data (org-get-todo-state))
  5307. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5308. (member todo-state
  5309. org-agenda-repeating-timestamp-show-all))
  5310. d2 (org-time-string-to-absolute
  5311. (match-string 1) d1 'past show-all
  5312. (current-buffer) pos)
  5313. diff (- d2 d1)
  5314. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5315. (setq pastschedp (and todayp (< diff 0)))
  5316. (setq did-habit-check-p nil)
  5317. ;; When to show a scheduled item in the calendar:
  5318. ;; If it is on or past the date.
  5319. (when (or (and (< diff 0)
  5320. (< (abs diff) org-scheduled-past-days)
  5321. (and todayp (not org-agenda-only-exact-dates)))
  5322. (= diff 0)
  5323. ;; org-is-habit-p uses org-entry-get, which is expansive
  5324. ;; so we go extra mile to only call it once
  5325. (and todayp
  5326. org-habit-show-all-today
  5327. (setq did-habit-check-p t)
  5328. (setq habitp (and (functionp 'org-is-habit-p)
  5329. (org-is-habit-p)))))
  5330. (save-excursion
  5331. (setq donep (member todo-state org-done-keywords))
  5332. (if (and donep
  5333. (or org-agenda-skip-scheduled-if-done
  5334. (not (= diff 0))
  5335. (and (functionp 'org-is-habit-p)
  5336. (org-is-habit-p))))
  5337. (setq txt nil)
  5338. (setq habitp (if did-habit-check-p habitp
  5339. (and (functionp 'org-is-habit-p)
  5340. (org-is-habit-p))))
  5341. (setq category (org-get-category)
  5342. category-pos (get-text-property (point) 'org-category-position))
  5343. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5344. (setq txt org-agenda-no-heading-message)
  5345. (goto-char (match-end 0))
  5346. (setq pos1 (match-beginning 0))
  5347. (if habitp
  5348. (if (or (not org-habit-show-habits)
  5349. (and (not todayp)
  5350. org-habit-show-habits-only-for-today))
  5351. (throw :skip nil))
  5352. (if (and
  5353. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5354. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5355. pastschedp))
  5356. (setq mm (assoc pos1 deadline-position-alist)))
  5357. (throw :skip nil)))
  5358. (setq tags (org-get-tags-at))
  5359. (setq level
  5360. (make-string
  5361. (1- (string-to-number
  5362. (substring (symbol-name (get-text-property
  5363. (match-beginning 0) 'face)) 10))) ? ))
  5364. (setq head (buffer-substring-no-properties
  5365. (point)
  5366. (progn (skip-chars-forward "^\r\n") (point))))
  5367. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5368. (setq timestr
  5369. (concat (substring s (match-beginning 1)) " "))
  5370. (setq timestr 'time))
  5371. (setq txt (org-agenda-format-item
  5372. (if (= diff 0)
  5373. (car org-agenda-scheduled-leaders)
  5374. (format (nth 1 org-agenda-scheduled-leaders)
  5375. (- 1 diff)))
  5376. head level category tags
  5377. (if (not (= diff 0)) nil timestr)
  5378. nil habitp))))
  5379. (when txt
  5380. (setq face
  5381. (cond
  5382. ((and (not habitp) pastschedp)
  5383. 'org-scheduled-previously)
  5384. (todayp 'org-scheduled-today)
  5385. (t 'org-scheduled))
  5386. habitp (and habitp (org-habit-parse-todo)))
  5387. (org-add-props txt props
  5388. 'undone-face face
  5389. 'face (if donep 'org-agenda-done face)
  5390. 'org-marker (org-agenda-new-marker pos)
  5391. 'org-hd-marker (org-agenda-new-marker pos1)
  5392. 'type (if pastschedp "past-scheduled" "scheduled")
  5393. 'date (if pastschedp d2 date)
  5394. 'warntime warntime
  5395. 'level level
  5396. 'priority (if habitp
  5397. (org-habit-get-priority habitp)
  5398. (+ 94 (- 5 diff) (org-get-priority txt)))
  5399. 'org-category category
  5400. 'category-position category-pos
  5401. 'org-habit-p habitp
  5402. 'todo-state todo-state)
  5403. (push txt ee))))))
  5404. (nreverse ee)))
  5405. (defun org-agenda-get-blocks ()
  5406. "Return the date-range information for agenda display."
  5407. (let* ((props (list 'face nil
  5408. 'org-not-done-regexp org-not-done-regexp
  5409. 'org-todo-regexp org-todo-regexp
  5410. 'org-complex-heading-regexp org-complex-heading-regexp
  5411. 'mouse-face 'highlight
  5412. 'help-echo
  5413. (format "mouse-2 or RET jump to org file %s"
  5414. (abbreviate-file-name buffer-file-name))))
  5415. (regexp org-tr-regexp)
  5416. (d0 (calendar-absolute-from-gregorian date))
  5417. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5418. level todo-state tags pos head donep)
  5419. (goto-char (point-min))
  5420. (while (re-search-forward regexp nil t)
  5421. (catch :skip
  5422. (org-agenda-skip)
  5423. (setq pos (point))
  5424. (let ((start-time (match-string 1))
  5425. (end-time (match-string 2)))
  5426. (setq s1 (match-string 1)
  5427. s2 (match-string 2)
  5428. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5429. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5430. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5431. ;; Only allow days between the limits, because the normal
  5432. ;; date stamps will catch the limits.
  5433. (save-excursion
  5434. (setq todo-state (org-get-todo-state))
  5435. (setq donep (member todo-state org-done-keywords))
  5436. (if (and donep org-agenda-skip-timestamp-if-done)
  5437. (throw :skip t))
  5438. (setq marker (org-agenda-new-marker (point)))
  5439. (setq category (org-get-category)
  5440. category-pos (get-text-property (point) 'org-category-position))
  5441. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5442. (setq txt org-agenda-no-heading-message)
  5443. (goto-char (match-beginning 0))
  5444. (setq hdmarker (org-agenda-new-marker (point)))
  5445. (setq tags (org-get-tags-at))
  5446. (setq level
  5447. (make-string
  5448. (1- (string-to-number
  5449. (substring (symbol-name (get-text-property
  5450. (match-beginning 0) 'face)) 10))) ? ))
  5451. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5452. (setq head (match-string 1))
  5453. (let ((remove-re
  5454. (if org-agenda-remove-timeranges-from-blocks
  5455. (concat
  5456. "<" (regexp-quote s1) ".*?>"
  5457. "--"
  5458. "<" (regexp-quote s2) ".*?>")
  5459. nil)))
  5460. (setq txt (org-agenda-format-item
  5461. (format
  5462. (nth (if (= d1 d2) 0 1)
  5463. org-agenda-timerange-leaders)
  5464. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5465. head level category tags
  5466. (cond ((and (= d1 d0) (= d2 d0))
  5467. (concat "<" start-time ">--<" end-time ">"))
  5468. ((= d1 d0)
  5469. (concat "<" start-time ">"))
  5470. ((= d2 d0)
  5471. (concat "<" end-time ">")))
  5472. remove-re))))
  5473. (org-add-props txt props
  5474. 'org-marker marker 'org-hd-marker hdmarker
  5475. 'type "block" 'date date
  5476. 'level level
  5477. 'todo-state todo-state
  5478. 'priority (org-get-priority txt) 'org-category category
  5479. 'org-category-position category-pos)
  5480. (push txt ee))))
  5481. (goto-char pos)))
  5482. ;; Sort the entries by expiration date.
  5483. (nreverse ee)))
  5484. ;;; Agenda presentation and sorting
  5485. (defvar org-prefix-has-time nil
  5486. "A flag, set by `org-compile-prefix-format'.
  5487. The flag is set if the currently compiled format contains a `%t'.")
  5488. (defvar org-prefix-has-tag nil
  5489. "A flag, set by `org-compile-prefix-format'.
  5490. The flag is set if the currently compiled format contains a `%T'.")
  5491. (defvar org-prefix-has-effort nil
  5492. "A flag, set by `org-compile-prefix-format'.
  5493. The flag is set if the currently compiled format contains a `%e'.")
  5494. (defvar org-prefix-category-length nil
  5495. "Used by `org-compile-prefix-format' to remember the category field width.")
  5496. (defvar org-prefix-category-max-length nil
  5497. "Used by `org-compile-prefix-format' to remember the category field width.")
  5498. (defun org-agenda-get-category-icon (category)
  5499. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5500. (dolist (entry org-agenda-category-icon-alist)
  5501. (when (org-string-match-p (car entry) category)
  5502. (if (listp (cadr entry))
  5503. (return (cadr entry))
  5504. (return (apply 'create-image (cdr entry)))))))
  5505. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5506. remove-re habitp)
  5507. "Format TXT to be inserted into the agenda buffer.
  5508. In particular, add the prefix and corresponding text properties.
  5509. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5510. LEVEL may be a string to replace the `%l' specifier.
  5511. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5512. category taken from local variable or file name. It will replace the `%c'
  5513. specifier in the format.
  5514. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5515. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5516. When DOTIME is a string, this string is searched for a time before TXT is.
  5517. TAGS can be the tags of the headline.
  5518. Any match of REMOVE-RE will be removed from TXT."
  5519. ;; We keep the org-prefix-* variable values along with a compiled
  5520. ;; formatter, so that multiple agendas existing at the same time do
  5521. ;; not step on each other toes.
  5522. ;;
  5523. ;; It was inconvenient to make these variables buffer local in
  5524. ;; Agenda buffers, because this function expects to be called with
  5525. ;; the buffer where item comes from being current, and not agenda
  5526. ;; buffer
  5527. (let* ((bindings (car org-prefix-format-compiled))
  5528. (formatter (cadr org-prefix-format-compiled)))
  5529. (loop for (var value) in bindings
  5530. do (set var value))
  5531. (save-match-data
  5532. ;; Diary entries sometimes have extra whitespace at the beginning
  5533. (setq txt (org-trim txt))
  5534. ;; Fix the tags part in txt
  5535. (setq txt (org-agenda-fix-displayed-tags
  5536. txt tags
  5537. org-agenda-show-inherited-tags
  5538. org-agenda-hide-tags-regexp))
  5539. (let* ((category (or category
  5540. (if (stringp org-category)
  5541. org-category
  5542. (and org-category (symbol-name org-category)))
  5543. (if buffer-file-name
  5544. (file-name-sans-extension
  5545. (file-name-nondirectory buffer-file-name))
  5546. "")))
  5547. (category-icon (org-agenda-get-category-icon category))
  5548. (category-icon (if category-icon
  5549. (propertize " " 'display category-icon)
  5550. ""))
  5551. ;; time, tag, effort are needed for the eval of the prefix format
  5552. (tag (if tags (nth (1- (length tags)) tags) ""))
  5553. time effort neffort
  5554. (ts (if dotime (concat
  5555. (if (stringp dotime) dotime "")
  5556. (and org-agenda-search-headline-for-time txt))))
  5557. (time-of-day (and dotime (org-get-time-of-day ts)))
  5558. stamp plain s0 s1 s2 rtn srp l
  5559. duration thecategory)
  5560. (and (derived-mode-p 'org-mode) buffer-file-name
  5561. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5562. (when (and dotime time-of-day)
  5563. ;; Extract starting and ending time and move them to prefix
  5564. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5565. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5566. (setq s0 (match-string 0 ts)
  5567. srp (and stamp (match-end 3))
  5568. s1 (match-string (if plain 1 2) ts)
  5569. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5570. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5571. ;; them, we might want to remove them there to avoid duplication.
  5572. ;; The user can turn this off with a variable.
  5573. (if (and org-prefix-has-time
  5574. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5575. (string-match (concat (regexp-quote s0) " *") txt)
  5576. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5577. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5578. (= (match-beginning 0) 0)
  5579. t))
  5580. (setq txt (replace-match "" nil nil txt))))
  5581. ;; Normalize the time(s) to 24 hour
  5582. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5583. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5584. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5585. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5586. (setq s2
  5587. (org-minutes-to-hh:mm-string
  5588. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5589. ;; Compute the duration
  5590. (when s2
  5591. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5592. (org-hh:mm-string-to-minutes s1)))))
  5593. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5594. txt)
  5595. ;; Tags are in the string
  5596. (if (or (eq org-agenda-remove-tags t)
  5597. (and org-agenda-remove-tags
  5598. org-prefix-has-tag))
  5599. (setq txt (replace-match "" t t txt))
  5600. (setq txt (replace-match
  5601. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5602. (match-string 2 txt))
  5603. t t txt))))
  5604. (when (derived-mode-p 'org-mode)
  5605. (setq effort
  5606. (condition-case nil
  5607. (org-get-effort
  5608. (or (get-text-property 0 'org-hd-marker txt)
  5609. (get-text-property 0 'org-marker txt)))
  5610. (error nil)))
  5611. (when effort
  5612. (setq neffort (org-duration-string-to-minutes effort)
  5613. effort (setq effort (concat "[" effort "]")))))
  5614. ;; prevent erroring out with %e format when there is no effort
  5615. (or effort (setq effort ""))
  5616. (when remove-re
  5617. (while (string-match remove-re txt)
  5618. (setq txt (replace-match "" t t txt))))
  5619. ;; Set org-heading property on `txt' to mark the start of the
  5620. ;; heading.
  5621. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5622. ;; Prepare the variables needed in the eval of the compiled format
  5623. (setq time (cond (s2 (concat
  5624. (org-agenda-time-of-day-to-ampm-maybe s1)
  5625. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5626. (if org-agenda-timegrid-use-ampm " ")))
  5627. (s1 (concat
  5628. (org-agenda-time-of-day-to-ampm-maybe s1)
  5629. (if org-agenda-timegrid-use-ampm
  5630. "........ "
  5631. "......")))
  5632. (t ""))
  5633. extra (or (and (not habitp) extra) "")
  5634. category (if (symbolp category) (symbol-name category) category)
  5635. thecategory (copy-sequence category))
  5636. (if (string-match org-bracket-link-regexp category)
  5637. (progn
  5638. (setq l (if (match-end 3)
  5639. (- (match-end 3) (match-beginning 3))
  5640. (- (match-end 1) (match-beginning 1))))
  5641. (when (< l (or org-prefix-category-length 0))
  5642. (setq category (copy-sequence category))
  5643. (org-add-props category nil
  5644. 'extra-space (make-string
  5645. (- org-prefix-category-length l 1) ?\ ))))
  5646. (if (and org-prefix-category-max-length
  5647. (>= (length category) org-prefix-category-max-length))
  5648. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5649. ;; Evaluate the compiled format
  5650. (setq rtn (concat (eval formatter) txt))
  5651. ;; And finally add the text properties
  5652. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5653. (org-add-props rtn nil
  5654. 'org-category (if thecategory (downcase thecategory) category)
  5655. 'tags (mapcar 'org-downcase-keep-props tags)
  5656. 'org-highest-priority org-highest-priority
  5657. 'org-lowest-priority org-lowest-priority
  5658. 'time-of-day time-of-day
  5659. 'duration duration
  5660. 'effort effort
  5661. 'effort-minutes neffort
  5662. 'txt txt
  5663. 'time time
  5664. 'extra extra
  5665. 'format org-prefix-format-compiled
  5666. 'dotime dotime)))))
  5667. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5668. "Remove tags string from TXT, and add a modified list of tags.
  5669. The modified list may contain inherited tags, and tags matched by
  5670. `org-agenda-hide-tags-regexp' will be removed."
  5671. (when (or add-inherited hide-re)
  5672. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5673. (setq txt (substring txt 0 (match-beginning 0))))
  5674. (setq tags
  5675. (delq nil
  5676. (mapcar (lambda (tg)
  5677. (if (or (and hide-re (string-match hide-re tg))
  5678. (and (not add-inherited)
  5679. (get-text-property 0 'inherited tg)))
  5680. nil
  5681. tg))
  5682. tags)))
  5683. (when tags
  5684. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5685. i)
  5686. (setq txt (concat txt " :"
  5687. (mapconcat
  5688. (lambda (x)
  5689. (setq i (get-text-property 0 'inherited x))
  5690. (if (and have-i (not i))
  5691. (progn
  5692. (setq have-i nil)
  5693. (concat ":" x))
  5694. x))
  5695. tags ":")
  5696. (if have-i "::" ":"))))))
  5697. txt)
  5698. (defun org-downcase-keep-props (s)
  5699. (let ((props (text-properties-at 0 s)))
  5700. (setq s (downcase s))
  5701. (add-text-properties 0 (length s) props s)
  5702. s))
  5703. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5704. (defvar org-agenda-sorting-strategy-selected nil)
  5705. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5706. (catch 'exit
  5707. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5708. ((and todayp (member 'today (car org-agenda-time-grid))))
  5709. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5710. ((member 'weekly (car org-agenda-time-grid)))
  5711. (t (throw 'exit list)))
  5712. (let* ((have (delq nil (mapcar
  5713. (lambda (x) (get-text-property 1 'time-of-day x))
  5714. list)))
  5715. (string (nth 1 org-agenda-time-grid))
  5716. (gridtimes (nth 2 org-agenda-time-grid))
  5717. (req (car org-agenda-time-grid))
  5718. (remove (member 'remove-match req))
  5719. new time)
  5720. (if (and (member 'require-timed req) (not have))
  5721. ;; don't show empty grid
  5722. (throw 'exit list))
  5723. (while (setq time (pop gridtimes))
  5724. (unless (and remove (member time have))
  5725. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5726. (push (org-agenda-format-item
  5727. nil string "" nil
  5728. (concat (substring time 0 -2) ":" (substring time -2)))
  5729. new)
  5730. (put-text-property
  5731. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5732. (when (and todayp org-agenda-show-current-time-in-grid)
  5733. (push (org-agenda-format-item
  5734. nil
  5735. org-agenda-current-time-string
  5736. "" nil
  5737. (format-time-string "%H:%M "))
  5738. new)
  5739. (put-text-property
  5740. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5741. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5742. (append new list)
  5743. (append list new)))))
  5744. (defun org-compile-prefix-format (key)
  5745. "Compile the prefix format into a Lisp form that can be evaluated.
  5746. The resulting form and associated variable bindings is returned
  5747. and stored in the variable `org-prefix-format-compiled'."
  5748. (setq org-prefix-has-time nil
  5749. org-prefix-has-tag nil
  5750. org-prefix-category-length nil
  5751. org-prefix-has-effort nil)
  5752. (let ((s (cond
  5753. ((stringp org-agenda-prefix-format)
  5754. org-agenda-prefix-format)
  5755. ((assq key org-agenda-prefix-format)
  5756. (cdr (assq key org-agenda-prefix-format)))
  5757. (t " %-12:c%?-12t% s")))
  5758. (start 0)
  5759. varform vars var e c f opt)
  5760. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
  5761. s start)
  5762. (setq var (or (cdr (assoc (match-string 4 s)
  5763. '(("c" . category) ("t" . time) ("s" . extra)
  5764. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5765. 'eval)
  5766. c (or (match-string 3 s) "")
  5767. opt (match-beginning 1)
  5768. start (1+ (match-beginning 0)))
  5769. (if (equal var 'time) (setq org-prefix-has-time t))
  5770. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5771. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5772. (setq f (concat "%" (match-string 2 s) "s"))
  5773. (when (equal var 'category)
  5774. (setq org-prefix-category-length
  5775. (floor (abs (string-to-number (match-string 2 s)))))
  5776. (setq org-prefix-category-max-length
  5777. (let ((x (match-string 2 s)))
  5778. (save-match-data
  5779. (if (string-match "\\.[0-9]+" x)
  5780. (string-to-number (substring (match-string 0 x) 1)))))))
  5781. (if (eq var 'eval)
  5782. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5783. (if opt
  5784. (setq varform
  5785. `(if (equal "" ,var)
  5786. ""
  5787. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5788. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5789. (setq s (replace-match "%s" t nil s))
  5790. (push varform vars))
  5791. (setq vars (nreverse vars))
  5792. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5793. (setq org-prefix-format-compiled
  5794. (list
  5795. `((org-prefix-has-time ,org-prefix-has-time)
  5796. (org-prefix-has-tag ,org-prefix-has-tag)
  5797. (org-prefix-category-length ,org-prefix-category-length)
  5798. (org-prefix-has-effort ,org-prefix-has-effort))
  5799. `(format ,s ,@vars))))))
  5800. (defun org-set-sorting-strategy (key)
  5801. (if (symbolp (car org-agenda-sorting-strategy))
  5802. ;; the old format
  5803. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5804. (setq org-agenda-sorting-strategy-selected
  5805. (or (cdr (assq key org-agenda-sorting-strategy))
  5806. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5807. '(time-up category-keep priority-down)))))
  5808. (defun org-get-time-of-day (s &optional string mod24)
  5809. "Check string S for a time of day.
  5810. If found, return it as a military time number between 0 and 2400.
  5811. If not found, return nil.
  5812. The optional STRING argument forces conversion into a 5 character wide string
  5813. HH:MM."
  5814. (save-match-data
  5815. (when
  5816. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5817. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5818. (let* ((h (string-to-number (match-string 1 s)))
  5819. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5820. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5821. (am-p (equal ampm "am"))
  5822. (h1 (cond ((not ampm) h)
  5823. ((= h 12) (if am-p 0 12))
  5824. (t (+ h (if am-p 0 12)))))
  5825. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5826. (mod h1 24) h1))
  5827. (t0 (+ (* 100 h2) m))
  5828. (t1 (concat (if (>= h1 24) "+" " ")
  5829. (if (and org-agenda-time-leading-zero
  5830. (< t0 1000)) "0" "")
  5831. (if (< t0 100) "0" "")
  5832. (if (< t0 10) "0" "")
  5833. (int-to-string t0))))
  5834. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5835. (defvar org-agenda-before-sorting-filter-function nil
  5836. "Function to be applied to agenda items prior to sorting.
  5837. Prior to sorting also means just before they are inserted into the agenda.
  5838. To aid sorting, you may revisit the original entries and add more text
  5839. properties which will later be used by the sorting functions.
  5840. The function should take a string argument, an agenda line.
  5841. It has access to the text properties in that line, which contain among
  5842. other things, the property `org-hd-marker' that points to the entry
  5843. where the line comes from. Note that not all lines going into the agenda
  5844. have this property, only most.
  5845. The function should return the modified string. It is probably best
  5846. to ONLY change text properties.
  5847. You can also use this function as a filter, by returning nil for lines
  5848. you don't want to have in the agenda at all. For this application, you
  5849. could bind the variable in the options section of a custom command.")
  5850. (defun org-agenda-finalize-entries (list &optional nosort)
  5851. "Sort and concatenate the agenda items."
  5852. (setq list (mapcar 'org-agenda-highlight-todo list))
  5853. (if nosort
  5854. list
  5855. (when org-agenda-before-sorting-filter-function
  5856. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5857. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5858. (defun org-agenda-highlight-todo (x)
  5859. (let ((org-done-keywords org-done-keywords-for-agenda)
  5860. (case-fold-search nil)
  5861. re)
  5862. (if (eq x 'line)
  5863. (save-excursion
  5864. (beginning-of-line 1)
  5865. (setq re (org-get-at-bol 'org-todo-regexp))
  5866. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5867. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5868. (add-text-properties (match-beginning 0) (match-end 1)
  5869. (list 'face (org-get-todo-face 1)))
  5870. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5871. (delete-region (match-beginning 1) (1- (match-end 0)))
  5872. (goto-char (match-beginning 1))
  5873. (insert (format org-agenda-todo-keyword-format s)))))
  5874. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5875. (setq re (get-text-property 0 'org-todo-regexp x))
  5876. (when (and re
  5877. ;; Test `pl' because if there's no heading content,
  5878. ;; there's no point matching to highlight. Note
  5879. ;; that if we didn't test `pl' first, and there
  5880. ;; happened to be no keyword from `org-todo-regexp'
  5881. ;; on this heading line, then the `equal' comparison
  5882. ;; afterwards would spuriously succeed in the case
  5883. ;; where `pl' is nil -- causing an args-out-of-range
  5884. ;; error when we try to add text properties to text
  5885. ;; that isn't there.
  5886. pl
  5887. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5888. x pl) pl))
  5889. (add-text-properties
  5890. (or (match-end 1) (match-end 0)) (match-end 0)
  5891. (list 'face (org-get-todo-face (match-string 2 x)))
  5892. x)
  5893. (when (match-end 1)
  5894. (setq x (concat (substring x 0 (match-end 1))
  5895. (format org-agenda-todo-keyword-format
  5896. (match-string 2 x))
  5897. (org-add-props " " (text-properties-at 0 x))
  5898. (substring x (match-end 3)))))))
  5899. x)))
  5900. (defsubst org-cmp-priority (a b)
  5901. "Compare the priorities of string A and B."
  5902. (let ((pa (or (get-text-property 1 'priority a) 0))
  5903. (pb (or (get-text-property 1 'priority b) 0)))
  5904. (cond ((> pa pb) +1)
  5905. ((< pa pb) -1))))
  5906. (defsubst org-cmp-effort (a b)
  5907. "Compare the effort values of string A and B."
  5908. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5909. (ea (or (get-text-property 1 'effort-minutes a) def))
  5910. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5911. (cond ((> ea eb) +1)
  5912. ((< ea eb) -1))))
  5913. (defsubst org-cmp-category (a b)
  5914. "Compare the string values of categories of strings A and B."
  5915. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5916. (cb (or (get-text-property 1 'org-category b) "")))
  5917. (cond ((string-lessp ca cb) -1)
  5918. ((string-lessp cb ca) +1))))
  5919. (defsubst org-cmp-todo-state (a b)
  5920. "Compare the todo states of strings A and B."
  5921. (let* ((ma (or (get-text-property 1 'org-marker a)
  5922. (get-text-property 1 'org-hd-marker a)))
  5923. (mb (or (get-text-property 1 'org-marker b)
  5924. (get-text-property 1 'org-hd-marker b)))
  5925. (fa (and ma (marker-buffer ma)))
  5926. (fb (and mb (marker-buffer mb)))
  5927. (todo-kwds
  5928. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5929. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5930. (ta (or (get-text-property 1 'todo-state a) ""))
  5931. (tb (or (get-text-property 1 'todo-state b) ""))
  5932. (la (- (length (member ta todo-kwds))))
  5933. (lb (- (length (member tb todo-kwds))))
  5934. (donepa (member ta org-done-keywords-for-agenda))
  5935. (donepb (member tb org-done-keywords-for-agenda)))
  5936. (cond ((and donepa (not donepb)) -1)
  5937. ((and (not donepa) donepb) +1)
  5938. ((< la lb) -1)
  5939. ((< lb la) +1))))
  5940. (defsubst org-cmp-alpha (a b)
  5941. "Compare the headlines, alphabetically."
  5942. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5943. (plb (text-property-any 0 (length b) 'org-heading t b))
  5944. (ta (and pla (substring a pla)))
  5945. (tb (and plb (substring b plb))))
  5946. (when pla
  5947. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5948. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5949. (setq ta (substring ta (match-end 0))))
  5950. (setq ta (downcase ta)))
  5951. (when plb
  5952. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5953. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5954. (setq tb (substring tb (match-end 0))))
  5955. (setq tb (downcase tb)))
  5956. (cond ((not ta) +1)
  5957. ((not tb) -1)
  5958. ((string-lessp ta tb) -1)
  5959. ((string-lessp tb ta) +1))))
  5960. (defsubst org-cmp-tag (a b)
  5961. "Compare the string values of the first tags of A and B."
  5962. (let ((ta (car (last (get-text-property 1 'tags a))))
  5963. (tb (car (last (get-text-property 1 'tags b)))))
  5964. (cond ((not ta) +1)
  5965. ((not tb) -1)
  5966. ((string-lessp ta tb) -1)
  5967. ((string-lessp tb ta) +1))))
  5968. (defsubst org-cmp-time (a b)
  5969. "Compare the time-of-day values of strings A and B."
  5970. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5971. (ta (or (get-text-property 1 'time-of-day a) def))
  5972. (tb (or (get-text-property 1 'time-of-day b) def)))
  5973. (cond ((< ta tb) -1)
  5974. ((< tb ta) +1))))
  5975. (defsubst org-cmp-habit-p (a b)
  5976. "Compare the todo states of strings A and B."
  5977. (let ((ha (get-text-property 1 'org-habit-p a))
  5978. (hb (get-text-property 1 'org-habit-p b)))
  5979. (cond ((and ha (not hb)) -1)
  5980. ((and (not ha) hb) +1))))
  5981. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5982. (defun org-entries-lessp (a b)
  5983. "Predicate for sorting agenda entries."
  5984. ;; The following variables will be used when the form is evaluated.
  5985. ;; So even though the compiler complains, keep them.
  5986. (let* ((ss org-agenda-sorting-strategy-selected)
  5987. (time-up (and (org-em 'time-up 'time-down ss)
  5988. (org-cmp-time a b)))
  5989. (time-down (if time-up (- time-up) nil))
  5990. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5991. (org-cmp-priority a b)))
  5992. (priority-down (if priority-up (- priority-up) nil))
  5993. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5994. (org-cmp-effort a b)))
  5995. (effort-down (if effort-up (- effort-up) nil))
  5996. (category-up (and (or (org-em 'category-up 'category-down ss)
  5997. (memq 'category-keep ss))
  5998. (org-cmp-category a b)))
  5999. (category-down (if category-up (- category-up) nil))
  6000. (category-keep (if category-up +1 nil))
  6001. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6002. (org-cmp-tag a b)))
  6003. (tag-down (if tag-up (- tag-up) nil))
  6004. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6005. (org-cmp-todo-state a b)))
  6006. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6007. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6008. (org-cmp-habit-p a b)))
  6009. (habit-down (if habit-up (- habit-up) nil))
  6010. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6011. (org-cmp-alpha a b)))
  6012. (alpha-down (if alpha-up (- alpha-up) nil))
  6013. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6014. user-defined-up user-defined-down)
  6015. (if (and need-user-cmp org-agenda-cmp-user-defined
  6016. (functionp org-agenda-cmp-user-defined))
  6017. (setq user-defined-up
  6018. (funcall org-agenda-cmp-user-defined a b)
  6019. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6020. (cdr (assoc
  6021. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6022. '((-1 . t) (1 . nil) (nil . nil))))))
  6023. ;;; Agenda restriction lock
  6024. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6025. "Overlay to mark the headline to which agenda commands are restricted.")
  6026. (overlay-put org-agenda-restriction-lock-overlay
  6027. 'face 'org-agenda-restriction-lock)
  6028. (overlay-put org-agenda-restriction-lock-overlay
  6029. 'help-echo "Agendas are currently limited to this subtree.")
  6030. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6031. (defun org-agenda-set-restriction-lock (&optional type)
  6032. "Set restriction lock for agenda, to current subtree or file.
  6033. Restriction will be the file if TYPE is `file', or if type is the
  6034. universal prefix '(4), or if the cursor is before the first headline
  6035. in the file. Otherwise, restriction will be to the current subtree."
  6036. (interactive "P")
  6037. (and (equal type '(4)) (setq type 'file))
  6038. (setq type (cond
  6039. (type type)
  6040. ((org-at-heading-p) 'subtree)
  6041. ((condition-case nil (org-back-to-heading t) (error nil))
  6042. 'subtree)
  6043. (t 'file)))
  6044. (if (eq type 'subtree)
  6045. (progn
  6046. (setq org-agenda-restrict t)
  6047. (setq org-agenda-overriding-restriction 'subtree)
  6048. (put 'org-agenda-files 'org-restrict
  6049. (list (buffer-file-name (buffer-base-buffer))))
  6050. (org-back-to-heading t)
  6051. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6052. (move-marker org-agenda-restrict-begin (point))
  6053. (move-marker org-agenda-restrict-end
  6054. (save-excursion (org-end-of-subtree t)))
  6055. (message "Locking agenda restriction to subtree"))
  6056. (put 'org-agenda-files 'org-restrict
  6057. (list (buffer-file-name (buffer-base-buffer))))
  6058. (setq org-agenda-restrict nil)
  6059. (setq org-agenda-overriding-restriction 'file)
  6060. (move-marker org-agenda-restrict-begin nil)
  6061. (move-marker org-agenda-restrict-end nil)
  6062. (message "Locking agenda restriction to file"))
  6063. (setq current-prefix-arg nil)
  6064. (org-agenda-maybe-redo))
  6065. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6066. "Remove the agenda restriction lock."
  6067. (interactive "P")
  6068. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6069. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6070. (setq org-agenda-overriding-restriction nil)
  6071. (setq org-agenda-restrict nil)
  6072. (put 'org-agenda-files 'org-restrict nil)
  6073. (move-marker org-agenda-restrict-begin nil)
  6074. (move-marker org-agenda-restrict-end nil)
  6075. (setq current-prefix-arg nil)
  6076. (message "Agenda restriction lock removed")
  6077. (or noupdate (org-agenda-maybe-redo)))
  6078. (defun org-agenda-maybe-redo ()
  6079. "If there is any window showing the agenda view, update it."
  6080. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6081. (w0 (selected-window)))
  6082. (when w
  6083. (select-window w)
  6084. (org-agenda-redo)
  6085. (select-window w0)
  6086. (if org-agenda-overriding-restriction
  6087. (message "Agenda view shifted to new %s restriction"
  6088. org-agenda-overriding-restriction)
  6089. (message "Agenda restriction lock removed")))))
  6090. ;;; Agenda commands
  6091. (defun org-agenda-check-type (error &rest types)
  6092. "Check if agenda buffer is of allowed type.
  6093. If ERROR is non-nil, throw an error, otherwise just return nil."
  6094. (if (not org-agenda-type)
  6095. (error "No Org agenda currently displayed")
  6096. (if (memq org-agenda-type types)
  6097. t
  6098. (if error
  6099. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6100. nil))))
  6101. (defun org-agenda-Quit (&optional arg)
  6102. "Exit agenda by removing the window or the buffer."
  6103. (interactive)
  6104. (if org-agenda-columns-active
  6105. (org-columns-quit)
  6106. (let ((buf (current-buffer)))
  6107. (if (eq org-agenda-window-setup 'other-frame)
  6108. (progn
  6109. (org-agenda-reset-markers)
  6110. (kill-buffer buf)
  6111. (org-columns-remove-overlays)
  6112. (setq org-agenda-archives-mode nil)
  6113. (delete-frame))
  6114. (and (not (eq org-agenda-window-setup 'current-window))
  6115. (not (one-window-p))
  6116. (delete-window))
  6117. (org-agenda-reset-markers)
  6118. (kill-buffer buf)
  6119. (org-columns-remove-overlays)
  6120. (setq org-agenda-archives-mode nil)))
  6121. ;; Maybe restore the pre-agenda window configuration.
  6122. (and org-agenda-restore-windows-after-quit
  6123. (not (eq org-agenda-window-setup 'other-frame))
  6124. org-agenda-pre-window-conf
  6125. (set-window-configuration org-agenda-pre-window-conf)
  6126. (setq org-agenda-pre-window-conf nil))))
  6127. (defun org-agenda-quit ()
  6128. "Exit agenda by killing agenda buffer or burying it when
  6129. `org-agenda-sticky' is non-NIL"
  6130. (interactive)
  6131. (if org-agenda-columns-active
  6132. (org-columns-quit)
  6133. (if org-agenda-sticky
  6134. (let ((buf (current-buffer)))
  6135. (if (eq org-agenda-window-setup 'other-frame)
  6136. (progn
  6137. (delete-frame))
  6138. (and (not (eq org-agenda-window-setup 'current-window))
  6139. (not (one-window-p))
  6140. (delete-window)))
  6141. (with-current-buffer buf
  6142. (bury-buffer)
  6143. ;; Maybe restore the pre-agenda window configuration.
  6144. (and org-agenda-restore-windows-after-quit
  6145. (not (eq org-agenda-window-setup 'other-frame))
  6146. org-agenda-pre-window-conf
  6147. (set-window-configuration org-agenda-pre-window-conf)
  6148. (setq org-agenda-pre-window-conf nil))))
  6149. (org-agenda-Quit))))
  6150. (defun org-agenda-exit ()
  6151. "Exit agenda by removing the window or the buffer.
  6152. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6153. Org-mode buffers visited directly by the user will not be touched."
  6154. (interactive)
  6155. (org-release-buffers org-agenda-new-buffers)
  6156. (setq org-agenda-new-buffers nil)
  6157. (org-agenda-Quit))
  6158. (defun org-agenda-kill-all-agenda-buffers ()
  6159. "Kill all buffers in `org-agena-mode'.
  6160. This is used when toggling sticky agendas. You can also explicitly invoke it
  6161. with `C-c a C-k'."
  6162. (interactive)
  6163. (let (blist)
  6164. (dolist (buf (buffer-list))
  6165. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6166. (push buf blist)))
  6167. (mapc 'kill-buffer blist)))
  6168. (defun org-agenda-execute (arg)
  6169. "Execute another agenda command, keeping same window.
  6170. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6171. in the agenda."
  6172. (interactive "P")
  6173. (let ((org-agenda-window-setup 'current-window))
  6174. (org-agenda arg)))
  6175. (defun org-agenda-redo (&optional all)
  6176. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6177. (interactive "P")
  6178. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6179. (cpa (unless (eq all t) current-prefix-arg))
  6180. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6181. (org-agenda-sticky nil)
  6182. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6183. org-agenda-buffer-name))
  6184. (org-agenda-keep-modes t)
  6185. (tag-filter org-agenda-tag-filter)
  6186. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6187. (top-cat-filter org-agenda-top-category-filter)
  6188. (cat-filter org-agenda-category-filter)
  6189. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6190. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6191. (cols org-agenda-columns-active)
  6192. (line (org-current-line))
  6193. (window-line (- line (org-current-line (window-start))))
  6194. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6195. (redo-cmd (get-text-property p 'org-redo-cmd))
  6196. (last-args (get-text-property p 'org-last-args))
  6197. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6198. (org-agenda-overriding-cmd-arguments
  6199. (unless (eq all t)
  6200. (cond ((listp last-args)
  6201. (cons (or cpa (car last-args)) (cdr last-args)))
  6202. ((stringp last-args)
  6203. last-args))))
  6204. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6205. (put 'org-agenda-tag-filter :preset-filter nil)
  6206. (put 'org-agenda-category-filter :preset-filter nil)
  6207. (and cols (org-columns-quit))
  6208. (message "Rebuilding agenda buffer...")
  6209. (if serie-redo-cmd
  6210. (eval serie-redo-cmd)
  6211. (org-let lprops '(eval redo-cmd)))
  6212. (setq org-agenda-undo-list nil
  6213. org-agenda-pending-undo-list nil)
  6214. (message "Rebuilding agenda buffer...done")
  6215. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6216. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6217. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6218. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6219. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6220. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6221. (org-goto-line line)
  6222. (recenter window-line)))
  6223. (defvar org-global-tags-completion-table nil)
  6224. (defvar org-agenda-filter-form nil)
  6225. (defvar org-agenda-filtered-by-category nil)
  6226. (defun org-agenda-filter-by-category (strip)
  6227. "Keep only those lines in the agenda buffer that have a specific category.
  6228. The category is that of the current line."
  6229. (interactive "P")
  6230. (if (and org-agenda-filtered-by-category
  6231. org-agenda-category-filter)
  6232. (org-agenda-filter-show-all-cat)
  6233. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6234. (if cat (org-agenda-filter-apply
  6235. (list (concat (if strip "-" "+") cat)) 'category)
  6236. (error "No category at point")))))
  6237. (defun org-find-top-category (&optional pos)
  6238. (save-excursion
  6239. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6240. (if pos (goto-char pos))
  6241. ;; Skip up to the topmost parent
  6242. (while (ignore-errors (outline-up-heading 1) t))
  6243. (ignore-errors
  6244. (nth 4 (org-heading-components))))))
  6245. (defvar org-agenda-filtered-by-top-category nil)
  6246. (defun org-agenda-filter-by-top-category (strip)
  6247. "Keep only those lines in the agenda buffer that have a specific category.
  6248. The category is that of the current line."
  6249. (interactive "P")
  6250. (if org-agenda-filtered-by-top-category
  6251. (progn
  6252. (setq org-agenda-filtered-by-top-category nil
  6253. org-agenda-top-category-filter nil)
  6254. (org-agenda-filter-show-all-cat))
  6255. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6256. (if cat (org-agenda-filter-top-category-apply cat strip)
  6257. (error "No top-level category at point")))))
  6258. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6259. "Keep only those lines in the agenda buffer that have a specific tag.
  6260. The tag is selected with its fast selection letter, as configured.
  6261. With prefix argument STRIP, remove all lines that do have the tag.
  6262. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6263. used to narrow the search - the interactive user can also press `-' or `+'
  6264. to switch to narrowing."
  6265. (interactive "P")
  6266. (let* ((alist org-tag-alist-for-agenda)
  6267. (tag-chars (mapconcat
  6268. (lambda (x) (if (and (not (symbolp (car x)))
  6269. (cdr x))
  6270. (char-to-string (cdr x))
  6271. ""))
  6272. alist ""))
  6273. (efforts (org-split-string
  6274. (or (cdr (assoc (concat org-effort-property "_ALL")
  6275. org-global-properties))
  6276. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6277. "")))
  6278. (effort-op org-agenda-filter-effort-default-operator)
  6279. (effort-prompt "")
  6280. (inhibit-read-only t)
  6281. (current org-agenda-tag-filter)
  6282. maybe-refresh a n tag)
  6283. (unless char
  6284. (message
  6285. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6286. (if narrow "Narrow" "Filter") tag-chars
  6287. (if org-agenda-auto-exclude-function "[RET], " ""))
  6288. (setq char (read-char-exclusive)))
  6289. (when (member char '(?+ ?-))
  6290. ;; Narrowing down
  6291. (cond ((equal char ?-) (setq strip t narrow t))
  6292. ((equal char ?+) (setq strip nil narrow t)))
  6293. (message
  6294. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6295. (setq char (read-char-exclusive)))
  6296. (when (member char '(?< ?> ?= ??))
  6297. ;; An effort operator
  6298. (setq effort-op (char-to-string char))
  6299. (setq alist nil) ; to make sure it will be interpreted as effort.
  6300. (unless (equal char ??)
  6301. (loop for i from 0 to 9 do
  6302. (setq effort-prompt
  6303. (concat
  6304. effort-prompt " ["
  6305. (if (= i 9) "0" (int-to-string (1+ i)))
  6306. "]" (nth i efforts))))
  6307. (message "Effort%s: %s " effort-op effort-prompt)
  6308. (setq char (read-char-exclusive))
  6309. (when (or (< char ?0) (> char ?9))
  6310. (error "Need 1-9,0 to select effort"))))
  6311. (when (equal char ?\t)
  6312. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6313. (org-set-local 'org-global-tags-completion-table
  6314. (org-global-tags-completion-table)))
  6315. (let ((completion-ignore-case t))
  6316. (setq tag (org-icompleting-read
  6317. "Tag: " org-global-tags-completion-table))))
  6318. (cond
  6319. ((equal char ?\r)
  6320. (org-agenda-filter-show-all-tag)
  6321. (when org-agenda-auto-exclude-function
  6322. (setq org-agenda-tag-filter '())
  6323. (dolist (tag (org-agenda-get-represented-tags))
  6324. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6325. (if modifier
  6326. (push modifier org-agenda-tag-filter))))
  6327. (if (not (null org-agenda-tag-filter))
  6328. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6329. (setq maybe-refresh t))
  6330. ((equal char ?/)
  6331. (org-agenda-filter-show-all-tag)
  6332. (when (get 'org-agenda-tag-filter :preset-filter)
  6333. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6334. (setq maybe-refresh t))
  6335. ((equal char ?. )
  6336. (setq org-agenda-tag-filter
  6337. (mapcar (lambda(tag) (concat "+" tag))
  6338. (org-get-at-bol 'tags)))
  6339. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6340. (setq maybe-refresh t))
  6341. ((or (equal char ?\ )
  6342. (setq a (rassoc char alist))
  6343. (and (>= char ?0) (<= char ?9)
  6344. (setq n (if (= char ?0) 9 (- char ?0 1))
  6345. tag (concat effort-op (nth n efforts))
  6346. a (cons tag nil)))
  6347. (and (= char ??)
  6348. (setq tag "?eff")
  6349. a (cons tag nil))
  6350. (and tag (setq a (cons tag nil))))
  6351. (org-agenda-filter-show-all-tag)
  6352. (setq tag (car a))
  6353. (setq org-agenda-tag-filter
  6354. (cons (concat (if strip "-" "+") tag)
  6355. (if narrow current nil)))
  6356. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6357. (setq maybe-refresh t))
  6358. (t (error "Invalid tag selection character %c" char)))
  6359. (when (and maybe-refresh
  6360. (eq org-agenda-clockreport-mode 'with-filter))
  6361. (org-agenda-redo))))
  6362. (defun org-agenda-get-represented-tags ()
  6363. "Get a list of all tags currently represented in the agenda."
  6364. (let (p tags)
  6365. (save-excursion
  6366. (goto-char (point-min))
  6367. (while (setq p (next-single-property-change (point) 'tags))
  6368. (goto-char p)
  6369. (mapc (lambda (x) (add-to-list 'tags x))
  6370. (get-text-property (point) 'tags))))
  6371. tags))
  6372. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6373. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6374. (interactive "P")
  6375. (org-agenda-filter-by-tag strip char 'refine))
  6376. (defun org-agenda-filter-make-matcher ()
  6377. "Create the form that tests a line for agenda filter."
  6378. (let (f f1)
  6379. ;; first compute the tag-filter matcher
  6380. (dolist (x (delete-dups
  6381. (append (get 'org-agenda-tag-filter
  6382. :preset-filter) org-agenda-tag-filter)))
  6383. (if (member x '("-" "+"))
  6384. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6385. (if (string-match "[<=>?]" x)
  6386. (setq f1 (org-agenda-filter-effort-form x))
  6387. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6388. (if (equal (string-to-char x) ?-)
  6389. (setq f1 (list 'not f1))))
  6390. (push f1 f))
  6391. ;; then compute the category-filter matcher
  6392. (dolist (x (delete-dups
  6393. (append (get 'org-agenda-category-filter
  6394. :preset-filter) org-agenda-category-filter)))
  6395. (if (equal "-" (substring x 0 1))
  6396. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6397. (setq f1 (list 'equal (substring x 1) 'cat)))
  6398. (push f1 f))
  6399. (cons 'and (nreverse f))))
  6400. (defun org-agenda-filter-effort-form (e)
  6401. "Return the form to compare the effort of the current line with what E says.
  6402. E looks like \"+<2:25\"."
  6403. (let (op)
  6404. (setq e (substring e 1))
  6405. (setq op (string-to-char e) e (substring e 1))
  6406. (setq op (cond ((equal op ?<) '<=)
  6407. ((equal op ?>) '>=)
  6408. ((equal op ??) op)
  6409. (t '=)))
  6410. (list 'org-agenda-compare-effort (list 'quote op)
  6411. (org-duration-string-to-minutes e))))
  6412. (defun org-agenda-compare-effort (op value)
  6413. "Compare the effort of the current line with VALUE, using OP.
  6414. If the line does not have an effort defined, return nil."
  6415. (let ((eff (org-get-at-bol 'effort-minutes)))
  6416. (if (equal op ??)
  6417. (not eff)
  6418. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6419. value))))
  6420. (defun org-agenda-filter-apply (filter type)
  6421. "Set FILTER as the new agenda filter and apply it."
  6422. (let (tags cat)
  6423. (if (eq type 'tag)
  6424. (setq org-agenda-tag-filter filter)
  6425. (setq org-agenda-category-filter filter))
  6426. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6427. (if (and (eq type 'category)
  6428. (not (equal (substring (car filter) 0 1) "-")))
  6429. ;; Only set `org-agenda-filtered-by-category' to t
  6430. ;; when a unique category is used as the filter
  6431. (setq org-agenda-filtered-by-category t))
  6432. (org-agenda-set-mode-name)
  6433. (save-excursion
  6434. (goto-char (point-min))
  6435. (while (not (eobp))
  6436. (if (org-get-at-bol 'org-marker)
  6437. (progn
  6438. (setq tags (org-get-at-bol 'tags) ; used in eval
  6439. cat (get-text-property (point) 'org-category))
  6440. (if (not (eval org-agenda-filter-form))
  6441. (org-agenda-filter-hide-line type))
  6442. (beginning-of-line 2))
  6443. (beginning-of-line 2))))
  6444. (if (get-char-property (point) 'invisible)
  6445. (ignore-errors (org-agenda-previous-line)))))
  6446. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6447. "Set FILTER as the new agenda filter and apply it."
  6448. (org-agenda-set-mode-name)
  6449. (save-excursion
  6450. (goto-char (point-min))
  6451. (while (not (eobp))
  6452. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6453. (topcat (and pos (org-find-top-category pos))))
  6454. (if (and topcat (funcall (if negative 'identity 'not)
  6455. (string= category topcat)))
  6456. (org-agenda-filter-hide-line 'category)))
  6457. (beginning-of-line 2)))
  6458. (if (get-char-property (point) 'invisible)
  6459. (org-agenda-previous-line))
  6460. (setq org-agenda-top-category-filter category
  6461. org-agenda-filtered-by-top-category t))
  6462. (defun org-agenda-filter-hide-line (type)
  6463. (let (ov)
  6464. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6465. (point-at-eol)))
  6466. (overlay-put ov 'invisible t)
  6467. (overlay-put ov 'type type)
  6468. (if (eq type 'tag)
  6469. (push ov org-agenda-tag-filter-overlays)
  6470. (push ov org-agenda-cat-filter-overlays))))
  6471. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6472. (setq pos (or pos (point)))
  6473. (save-excursion
  6474. (dolist (ov (overlays-at pos))
  6475. (when (and (overlay-get ov 'invisible)
  6476. (eq (overlay-get ov 'type) 'tag))
  6477. (goto-char pos)
  6478. (if (< (overlay-start ov) (point-at-eol))
  6479. (move-overlay ov (point-at-eol)
  6480. (overlay-end ov)))))))
  6481. (defun org-agenda-filter-show-all-tag nil
  6482. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6483. (setq org-agenda-tag-filter-overlays nil
  6484. org-agenda-tag-filter nil
  6485. org-agenda-filter-form nil)
  6486. (org-agenda-set-mode-name))
  6487. (defun org-agenda-filter-show-all-cat nil
  6488. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6489. (setq org-agenda-cat-filter-overlays nil
  6490. org-agenda-filtered-by-category nil
  6491. org-agenda-category-filter nil
  6492. org-agenda-filter-form nil)
  6493. (org-agenda-set-mode-name))
  6494. (defun org-agenda-manipulate-query-add ()
  6495. "Manipulate the query by adding a search term with positive selection.
  6496. Positive selection means the term must be matched for selection of an entry."
  6497. (interactive)
  6498. (org-agenda-manipulate-query ?\[))
  6499. (defun org-agenda-manipulate-query-subtract ()
  6500. "Manipulate the query by adding a search term with negative selection.
  6501. Negative selection means term must not be matched for selection of an entry."
  6502. (interactive)
  6503. (org-agenda-manipulate-query ?\]))
  6504. (defun org-agenda-manipulate-query-add-re ()
  6505. "Manipulate the query by adding a search regexp with positive selection.
  6506. Positive selection means the regexp must match for selection of an entry."
  6507. (interactive)
  6508. (org-agenda-manipulate-query ?\{))
  6509. (defun org-agenda-manipulate-query-subtract-re ()
  6510. "Manipulate the query by adding a search regexp with negative selection.
  6511. Negative selection means regexp must not match for selection of an entry."
  6512. (interactive)
  6513. (org-agenda-manipulate-query ?\}))
  6514. (defun org-agenda-manipulate-query (char)
  6515. (cond
  6516. ((memq org-agenda-type '(timeline agenda))
  6517. (let ((org-agenda-include-inactive-timestamps t))
  6518. (org-agenda-redo))
  6519. (message "Display now includes inactive timestamps as well"))
  6520. ((eq org-agenda-type 'search)
  6521. (org-add-to-string
  6522. 'org-agenda-query-string
  6523. (if org-agenda-last-search-view-search-was-boolean
  6524. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6525. (?\{ . " +{}") (?\} . " -{}"))))
  6526. " "))
  6527. (setq org-agenda-redo-command
  6528. (list 'org-search-view
  6529. (car (get-text-property (point) 'org-last-args))
  6530. org-agenda-query-string
  6531. (+ (length org-agenda-query-string)
  6532. (if (member char '(?\{ ?\})) 0 1))))
  6533. (set-register org-agenda-query-register org-agenda-query-string)
  6534. (let ((org-agenda-overriding-arguments
  6535. (cdr org-agenda-redo-command)))
  6536. (org-agenda-redo)))
  6537. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6538. org-agenda-type))))
  6539. (defun org-add-to-string (var string)
  6540. (set var (concat (symbol-value var) string)))
  6541. (defun org-agenda-goto-date (span)
  6542. "Jump to DATE in agenda."
  6543. (interactive "P")
  6544. (let* ((org-read-date-prefer-future
  6545. (eval org-agenda-jump-prefer-future))
  6546. (date (org-read-date))
  6547. (org-agenda-sticky-orig org-agenda-sticky)
  6548. (org-agenda-buffer-tmp-name (buffer-name))
  6549. (args (get-text-property (point) 'org-last-args))
  6550. (0-arg (or current-prefix-arg (car args)))
  6551. (2-arg (nth 2 args))
  6552. (newcmd (list 'org-agenda-list 0-arg date
  6553. (org-agenda-span-to-ndays 2-arg)))
  6554. (newargs (cdr newcmd))
  6555. (inhibit-read-only t)
  6556. org-agenda-sticky)
  6557. (if (not (org-agenda-check-type t 'agenda))
  6558. (error "Not available in non-agenda blocks")
  6559. (add-text-properties (point-min) (point-max)
  6560. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6561. (org-agenda-redo)
  6562. (setq org-agenda-sticky org-agenda-sticky-orig
  6563. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6564. (defun org-agenda-goto-today ()
  6565. "Go to today."
  6566. (interactive)
  6567. (org-agenda-check-type t 'timeline 'agenda)
  6568. (let* ((args (get-text-property (point) 'org-last-args))
  6569. (curspan (nth 2 args))
  6570. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6571. (cond
  6572. (tdpos (goto-char tdpos))
  6573. ((eq org-agenda-type 'agenda)
  6574. (let* ((sd (org-agenda-compute-starting-span
  6575. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6576. (org-agenda-overriding-arguments args))
  6577. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6578. (org-agenda-redo)
  6579. (org-agenda-find-same-or-today-or-agenda)))
  6580. (t (error "Cannot find today")))))
  6581. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6582. (goto-char
  6583. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6584. (text-property-any (point-min) (point-max) 'org-today t)
  6585. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6586. (and (get-text-property (point) 'org-serie)
  6587. (org-agenda-goto-block-beginning))
  6588. (point-min))))
  6589. (defun org-agenda-goto-block-beginning ()
  6590. "Go the agenda block beginning."
  6591. (interactive)
  6592. (if (not (derived-mode-p 'org-agenda-mode))
  6593. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6594. (let (dest)
  6595. (save-excursion
  6596. (unless (looking-at "\\'")
  6597. (forward-char))
  6598. (let* ((prop 'org-agenda-structural-header)
  6599. (p (previous-single-property-change (point) prop))
  6600. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6601. (1- (point))) prop)))
  6602. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6603. (if (not dest)
  6604. (error "Cannot find the beginning of the blog")
  6605. (goto-char dest)
  6606. (move-beginning-of-line 1)))))
  6607. (defun org-agenda-later (arg)
  6608. "Go forward in time by thee current span.
  6609. With prefix ARG, go forward that many times the current span."
  6610. (interactive "p")
  6611. (org-agenda-check-type t 'agenda)
  6612. (let* ((args (get-text-property (point) 'org-last-args))
  6613. (span (or (nth 2 args) org-agenda-current-span))
  6614. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6615. (greg (calendar-gregorian-from-absolute sd))
  6616. (cnt (org-get-at-bol 'org-day-cnt))
  6617. greg2)
  6618. (cond
  6619. ((numberp span)
  6620. (setq sd (+ span sd)))
  6621. ((eq span 'day)
  6622. (setq sd (+ arg sd)))
  6623. ((eq span 'week)
  6624. (setq sd (+ (* 7 arg) sd)))
  6625. ((eq span 'month)
  6626. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6627. sd (calendar-absolute-from-gregorian greg2))
  6628. (setcar greg2 (1+ (car greg2))))
  6629. ((eq span 'year)
  6630. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6631. sd (calendar-absolute-from-gregorian greg2))
  6632. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6633. (t
  6634. (setq sd (+ (* span arg) sd))))
  6635. (let ((org-agenda-overriding-cmd
  6636. ;; `cmd' may have been set by `org-agenda-run-series' which
  6637. ;; uses `org-agenda-overriding-cmd' to decide whether
  6638. ;; overriding is allowed for `cmd'
  6639. (get-text-property (point) 'org-serie-cmd))
  6640. (org-agenda-overriding-arguments
  6641. (list (car args) sd span)))
  6642. (org-agenda-redo)
  6643. (org-agenda-find-same-or-today-or-agenda cnt))))
  6644. (defun org-agenda-earlier (arg)
  6645. "Go backward in time by the current span.
  6646. With prefix ARG, go backward that many times the current span."
  6647. (interactive "p")
  6648. (org-agenda-later (- arg)))
  6649. (defun org-agenda-view-mode-dispatch ()
  6650. "Call one of the view mode commands."
  6651. (interactive)
  6652. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6653. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6654. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6655. (let ((a (read-char-exclusive)))
  6656. (case a
  6657. (?\ (call-interactively 'org-agenda-reset-view))
  6658. (?d (call-interactively 'org-agenda-day-view))
  6659. (?w (call-interactively 'org-agenda-week-view))
  6660. (?m (call-interactively 'org-agenda-month-view))
  6661. (?y (call-interactively 'org-agenda-year-view))
  6662. (?l (call-interactively 'org-agenda-log-mode))
  6663. (?L (org-agenda-log-mode '(4)))
  6664. (?c (org-agenda-log-mode 'clockcheck))
  6665. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6666. (?a (call-interactively 'org-agenda-archives-mode))
  6667. (?A (org-agenda-archives-mode 'files))
  6668. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6669. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6670. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6671. (?D (call-interactively 'org-agenda-toggle-diary))
  6672. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6673. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6674. (org-agenda-check-type t 'timeline 'agenda)
  6675. (org-agenda-redo))
  6676. (message "Display now includes inactive timestamps as well"))
  6677. (?q (message "Abort"))
  6678. (otherwise (error "Invalid key" )))))
  6679. (defun org-agenda-reset-view ()
  6680. "Switch to default view for agenda."
  6681. (interactive)
  6682. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6683. (defun org-agenda-day-view (&optional day-of-year)
  6684. "Switch to daily view for agenda.
  6685. With argument DAY-OF-YEAR, switch to that day of the year."
  6686. (interactive "P")
  6687. (org-agenda-change-time-span 'day day-of-year))
  6688. (defun org-agenda-week-view (&optional iso-week)
  6689. "Switch to daily view for agenda.
  6690. With argument ISO-WEEK, switch to the corresponding ISO week.
  6691. If ISO-WEEK has more then 2 digits, only the last two encode the
  6692. week. Any digits before this encode a year. So 200712 means
  6693. week 12 of year 2007. Years in the range 1938-2037 can also be
  6694. written as 2-digit years."
  6695. (interactive "P")
  6696. (org-agenda-change-time-span 'week iso-week))
  6697. (defun org-agenda-month-view (&optional month)
  6698. "Switch to monthly view for agenda.
  6699. With argument MONTH, switch to that month."
  6700. (interactive "P")
  6701. (org-agenda-change-time-span 'month month))
  6702. (defun org-agenda-year-view (&optional year)
  6703. "Switch to yearly view for agenda.
  6704. With argument YEAR, switch to that year.
  6705. If MONTH has more then 2 digits, only the last two encode the
  6706. month. Any digits before this encode a year. So 200712 means
  6707. December year 2007. Years in the range 1938-2037 can also be
  6708. written as 2-digit years."
  6709. (interactive "P")
  6710. (when year
  6711. (setq year (org-small-year-to-year year)))
  6712. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6713. (org-agenda-change-time-span 'year year)
  6714. (error "Abort")))
  6715. (defun org-agenda-change-time-span (span &optional n)
  6716. "Change the agenda view to SPAN.
  6717. SPAN may be `day', `week', `month', `year'."
  6718. (org-agenda-check-type t 'agenda)
  6719. (let* ((args (get-text-property (point) 'org-last-args))
  6720. (curspan (nth 2 args)))
  6721. (if (and (not n) (equal curspan span))
  6722. (error "Viewing span is already \"%s\"" span))
  6723. (let* ((sd (or (org-get-at-bol 'day)
  6724. (nth 1 args)
  6725. org-starting-day))
  6726. (sd (org-agenda-compute-starting-span sd span n))
  6727. (org-agenda-overriding-cmd
  6728. (get-text-property (point) 'org-serie-cmd))
  6729. (org-agenda-overriding-arguments
  6730. (list (car args) sd span)))
  6731. (org-agenda-redo)
  6732. (org-agenda-find-same-or-today-or-agenda))
  6733. (org-agenda-set-mode-name)
  6734. (message "Switched to %s view" span)))
  6735. (defun org-agenda-compute-starting-span (sd span &optional n)
  6736. "Compute starting date for agenda.
  6737. SPAN may be `day', `week', `month', `year'. The return value
  6738. is a cons cell with the starting date and the number of days,
  6739. so that the date SD will be in that range."
  6740. (let* ((greg (calendar-gregorian-from-absolute sd))
  6741. (dg (nth 1 greg))
  6742. (mg (car greg))
  6743. (yg (nth 2 greg)))
  6744. (cond
  6745. ((eq span 'day)
  6746. (when n
  6747. (setq sd (+ (calendar-absolute-from-gregorian
  6748. (list mg 1 yg))
  6749. n -1))))
  6750. ((eq span 'week)
  6751. (let* ((nt (calendar-day-of-week
  6752. (calendar-gregorian-from-absolute sd)))
  6753. (d (if org-agenda-start-on-weekday
  6754. (- nt org-agenda-start-on-weekday)
  6755. 0))
  6756. y1)
  6757. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6758. (when n
  6759. (require 'cal-iso)
  6760. (when (> n 99)
  6761. (setq y1 (org-small-year-to-year (/ n 100))
  6762. n (mod n 100)))
  6763. (setq sd
  6764. (calendar-absolute-from-iso
  6765. (list n 1
  6766. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6767. ((eq span 'month)
  6768. (let (y1)
  6769. (when (and n (> n 99))
  6770. (setq y1 (org-small-year-to-year (/ n 100))
  6771. n (mod n 100)))
  6772. (setq sd (calendar-absolute-from-gregorian
  6773. (list (or n mg) 1 (or y1 yg))))))
  6774. ((eq span 'year)
  6775. (setq sd (calendar-absolute-from-gregorian
  6776. (list 1 1 (or n yg))))))
  6777. sd))
  6778. (defun org-agenda-next-date-line (&optional arg)
  6779. "Jump to the next line indicating a date in agenda buffer."
  6780. (interactive "p")
  6781. (org-agenda-check-type t 'agenda 'timeline)
  6782. (beginning-of-line 1)
  6783. ;; This does not work if user makes date format that starts with a blank
  6784. (if (looking-at "^\\S-") (forward-char 1))
  6785. (if (not (re-search-forward "^\\S-" nil t arg))
  6786. (progn
  6787. (backward-char 1)
  6788. (error "No next date after this line in this buffer")))
  6789. (goto-char (match-beginning 0)))
  6790. (defun org-agenda-previous-date-line (&optional arg)
  6791. "Jump to the previous line indicating a date in agenda buffer."
  6792. (interactive "p")
  6793. (org-agenda-check-type t 'agenda 'timeline)
  6794. (beginning-of-line 1)
  6795. (if (not (re-search-backward "^\\S-" nil t arg))
  6796. (error "No previous date before this line in this buffer")))
  6797. ;; Initialize the highlight
  6798. (defvar org-hl (make-overlay 1 1))
  6799. (overlay-put org-hl 'face 'highlight)
  6800. (defun org-highlight (begin end &optional buffer)
  6801. "Highlight a region with overlay."
  6802. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6803. (defun org-unhighlight ()
  6804. "Detach overlay INDEX."
  6805. (org-detach-overlay org-hl))
  6806. (defun org-unhighlight-once ()
  6807. "Remove the highlight from its position, and this function from the hook."
  6808. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6809. (org-unhighlight))
  6810. (defun org-agenda-follow-mode ()
  6811. "Toggle follow mode in an agenda buffer."
  6812. (interactive)
  6813. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6814. (org-agenda-set-mode-name)
  6815. (org-agenda-do-context-action)
  6816. (message "Follow mode is %s"
  6817. (if org-agenda-follow-mode "on" "off")))
  6818. (defun org-agenda-entry-text-mode (&optional arg)
  6819. "Toggle entry text mode in an agenda buffer."
  6820. (interactive "P")
  6821. (setq org-agenda-entry-text-mode (or (integerp arg)
  6822. (not org-agenda-entry-text-mode)))
  6823. (org-agenda-entry-text-hide)
  6824. (and org-agenda-entry-text-mode
  6825. (let ((org-agenda-entry-text-maxlines
  6826. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6827. (org-agenda-entry-text-show)))
  6828. (org-agenda-set-mode-name)
  6829. (message "Entry text mode is %s. Maximum number of lines is %d"
  6830. (if org-agenda-entry-text-mode "on" "off")
  6831. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6832. (defun org-agenda-clockreport-mode (&optional with-filter)
  6833. "Toggle clocktable mode in an agenda buffer.
  6834. With prefix arg WITH-FILTER, make the clocktable respect the current
  6835. agenda filter."
  6836. (interactive "P")
  6837. (org-agenda-check-type t 'agenda)
  6838. (if with-filter
  6839. (setq org-agenda-clockreport-mode 'with-filter)
  6840. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6841. (org-agenda-set-mode-name)
  6842. (org-agenda-redo)
  6843. (message "Clocktable mode is %s"
  6844. (if org-agenda-clockreport-mode "on" "off")))
  6845. (defun org-agenda-log-mode (&optional special)
  6846. "Toggle log mode in an agenda buffer.
  6847. With argument SPECIAL, show all possible log items, not only the ones
  6848. configured in `org-agenda-log-mode-items'.
  6849. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6850. (interactive "P")
  6851. (org-agenda-check-type t 'agenda 'timeline)
  6852. (setq org-agenda-show-log
  6853. (cond
  6854. ((equal special '(16)) 'only)
  6855. ((eq special 'clockcheck)
  6856. (if (eq org-agenda-show-log 'clockcheck)
  6857. nil 'clockcheck))
  6858. (special '(closed clock state))
  6859. (t (not org-agenda-show-log))))
  6860. (org-agenda-set-mode-name)
  6861. (org-agenda-redo)
  6862. (message "Log mode is %s"
  6863. (if org-agenda-show-log "on" "off")))
  6864. (defun org-agenda-archives-mode (&optional with-files)
  6865. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6866. When called with a prefix argument, include all archive files as well."
  6867. (interactive "P")
  6868. (setq org-agenda-archives-mode
  6869. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6870. (org-agenda-set-mode-name)
  6871. (org-agenda-redo)
  6872. (message
  6873. "%s"
  6874. (cond
  6875. ((eq org-agenda-archives-mode nil)
  6876. "No archives are included")
  6877. ((eq org-agenda-archives-mode 'trees)
  6878. (format "Trees with :%s: tag are included" org-archive-tag))
  6879. ((eq org-agenda-archives-mode t)
  6880. (format "Trees with :%s: tag and all active archive files are included"
  6881. org-archive-tag)))))
  6882. (defun org-agenda-toggle-diary ()
  6883. "Toggle diary inclusion in an agenda buffer."
  6884. (interactive)
  6885. (org-agenda-check-type t 'agenda)
  6886. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6887. (org-agenda-redo)
  6888. (org-agenda-set-mode-name)
  6889. (message "Diary inclusion turned %s"
  6890. (if org-agenda-include-diary "on" "off")))
  6891. (defun org-agenda-toggle-deadlines ()
  6892. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6893. (interactive)
  6894. (org-agenda-check-type t 'agenda)
  6895. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6896. (org-agenda-redo)
  6897. (org-agenda-set-mode-name)
  6898. (message "Deadlines inclusion turned %s"
  6899. (if org-agenda-include-deadlines "on" "off")))
  6900. (defun org-agenda-toggle-time-grid ()
  6901. "Toggle time grid in an agenda buffer."
  6902. (interactive)
  6903. (org-agenda-check-type t 'agenda)
  6904. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6905. (org-agenda-redo)
  6906. (org-agenda-set-mode-name)
  6907. (message "Time-grid turned %s"
  6908. (if org-agenda-use-time-grid "on" "off")))
  6909. (defun org-agenda-set-mode-name ()
  6910. "Set the mode name to indicate all the small mode settings."
  6911. (setq mode-name
  6912. (list "Org-Agenda"
  6913. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6914. " "
  6915. '(:eval (org-agenda-span-name org-agenda-current-span))
  6916. (if org-agenda-follow-mode " Follow" "")
  6917. (if org-agenda-entry-text-mode " ETxt" "")
  6918. (if org-agenda-include-diary " Diary" "")
  6919. (if org-agenda-include-deadlines " Ddl" "")
  6920. (if org-agenda-use-time-grid " Grid" "")
  6921. (if (and (boundp 'org-habit-show-habits)
  6922. org-habit-show-habits) " Habit" "")
  6923. (cond
  6924. ((consp org-agenda-show-log) " LogAll")
  6925. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6926. (org-agenda-show-log " Log")
  6927. (t ""))
  6928. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6929. :preset-filter))
  6930. '(:eval (org-propertize
  6931. (concat " <"
  6932. (mapconcat
  6933. 'identity
  6934. (append
  6935. (get 'org-agenda-category-filter :preset-filter)
  6936. org-agenda-category-filter)
  6937. "")
  6938. ">")
  6939. 'face 'org-agenda-filter-category
  6940. 'help-echo "Category used in filtering"))
  6941. "")
  6942. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6943. :preset-filter))
  6944. '(:eval (org-propertize
  6945. (concat " {"
  6946. (mapconcat
  6947. 'identity
  6948. (append
  6949. (get 'org-agenda-tag-filter :preset-filter)
  6950. org-agenda-tag-filter)
  6951. "")
  6952. "}")
  6953. 'face 'org-agenda-filter-tags
  6954. 'help-echo "Tags used in filtering"))
  6955. "")
  6956. (if org-agenda-archives-mode
  6957. (if (eq org-agenda-archives-mode t)
  6958. " Archives"
  6959. (format " :%s:" org-archive-tag))
  6960. "")
  6961. (if org-agenda-clockreport-mode
  6962. (if (eq org-agenda-clockreport-mode 'with-filter)
  6963. " Clock{}" " Clock")
  6964. "")))
  6965. (force-mode-line-update))
  6966. (defun org-agenda-post-command-hook ()
  6967. (setq org-agenda-type
  6968. (or (get-text-property (point) 'org-agenda-type)
  6969. (get-text-property (max (point-min) (1- (point)))
  6970. 'org-agenda-type))))
  6971. (defun org-agenda-next-line ()
  6972. "Move cursor to the next line, and show if follow mode is active."
  6973. (interactive)
  6974. (call-interactively 'next-line)
  6975. (org-agenda-do-context-action))
  6976. (defun org-agenda-previous-line ()
  6977. "Move cursor to the previous line, and show if follow-mode is active."
  6978. (interactive)
  6979. (call-interactively 'previous-line)
  6980. (org-agenda-do-context-action))
  6981. (defun org-agenda-next-item (n)
  6982. "Move cursor to next agenda item."
  6983. (interactive "p")
  6984. (let ((col (current-column)))
  6985. (dotimes (c n)
  6986. (when (next-single-property-change (point-at-eol) 'org-marker)
  6987. (move-end-of-line 1)
  6988. (goto-char (next-single-property-change (point) 'org-marker))))
  6989. (org-move-to-column col))
  6990. (org-agenda-do-context-action))
  6991. (defun org-agenda-previous-item (n)
  6992. "Move cursor to next agenda item."
  6993. (interactive "p")
  6994. (dotimes (c n)
  6995. (let ((col (current-column))
  6996. (goto (save-excursion
  6997. (move-end-of-line 0)
  6998. (previous-single-property-change (point) 'org-marker))))
  6999. (if goto (goto-char goto))
  7000. (org-move-to-column col)))
  7001. (org-agenda-do-context-action))
  7002. (defun org-agenda-do-context-action ()
  7003. "Show outline path and, maybe, follow mode window."
  7004. (let ((m (org-get-at-bol 'org-marker)))
  7005. (when (and (markerp m) (marker-buffer m))
  7006. (and org-agenda-follow-mode
  7007. (if org-agenda-follow-indirect
  7008. (org-agenda-tree-to-indirect-buffer)
  7009. (org-agenda-show)))
  7010. (and org-agenda-show-outline-path
  7011. (org-with-point-at m (org-display-outline-path t))))))
  7012. (defun org-agenda-show-priority ()
  7013. "Show the priority of the current item.
  7014. This priority is composed of the main priority given with the [#A] cookies,
  7015. and by additional input from the age of a schedules or deadline entry."
  7016. (interactive)
  7017. (let* ((pri (org-get-at-bol 'priority)))
  7018. (message "Priority is %d" (if pri pri -1000))))
  7019. (defun org-agenda-show-tags ()
  7020. "Show the tags applicable to the current item."
  7021. (interactive)
  7022. (let* ((tags (org-get-at-bol 'tags)))
  7023. (if tags
  7024. (message "Tags are :%s:"
  7025. (org-no-properties (mapconcat 'identity tags ":")))
  7026. (message "No tags associated with this line"))))
  7027. (defun org-agenda-goto (&optional highlight)
  7028. "Go to the Org-mode file which contains the item at point."
  7029. (interactive)
  7030. (let* ((marker (or (org-get-at-bol 'org-marker)
  7031. (org-agenda-error)))
  7032. (buffer (marker-buffer marker))
  7033. (pos (marker-position marker)))
  7034. (switch-to-buffer-other-window buffer)
  7035. (widen)
  7036. (push-mark)
  7037. (goto-char pos)
  7038. (when (derived-mode-p 'org-mode)
  7039. (org-show-context 'agenda)
  7040. (save-excursion
  7041. (and (outline-next-heading)
  7042. (org-flag-heading nil)))) ; show the next heading
  7043. (when (outline-invisible-p)
  7044. (show-entry)) ; display invisible text
  7045. (recenter (/ (window-height) 2))
  7046. (run-hooks 'org-agenda-after-show-hook)
  7047. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7048. (defvar org-agenda-after-show-hook nil
  7049. "Normal hook run after an item has been shown from the agenda.
  7050. Point is in the buffer where the item originated.")
  7051. (defun org-agenda-kill ()
  7052. "Kill the entry or subtree belonging to the current agenda entry."
  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. (type (org-get-at-bol 'type))
  7061. dbeg dend (n 0) conf)
  7062. (org-with-remote-undo buffer
  7063. (with-current-buffer buffer
  7064. (save-excursion
  7065. (goto-char pos)
  7066. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7067. (setq dbeg (progn (org-back-to-heading t) (point))
  7068. dend (org-end-of-subtree t t))
  7069. (setq dbeg (point-at-bol)
  7070. dend (min (point-max) (1+ (point-at-eol)))))
  7071. (goto-char dbeg)
  7072. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7073. (setq conf (or (eq t org-agenda-confirm-kill)
  7074. (and (numberp org-agenda-confirm-kill)
  7075. (> n org-agenda-confirm-kill))))
  7076. (and conf
  7077. (not (y-or-n-p
  7078. (format "Delete entry with %d lines in buffer \"%s\"? "
  7079. n (buffer-name buffer))))
  7080. (error "Abort"))
  7081. (let ((org-agenda-buffer-name bufname-orig))
  7082. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7083. (with-current-buffer buffer (delete-region dbeg dend))
  7084. (message "Agenda item and source killed"))))
  7085. (defvar org-archive-default-command) ; defined in org-archive.el
  7086. (defun org-agenda-archive-default ()
  7087. "Archive the entry or subtree belonging to the current agenda entry."
  7088. (interactive)
  7089. (require 'org-archive)
  7090. (org-agenda-archive-with org-archive-default-command))
  7091. (defun org-agenda-archive-default-with-confirmation ()
  7092. "Archive the entry or subtree belonging to the current agenda entry."
  7093. (interactive)
  7094. (require 'org-archive)
  7095. (org-agenda-archive-with org-archive-default-command 'confirm))
  7096. (defun org-agenda-archive ()
  7097. "Archive the entry or subtree belonging to the current agenda entry."
  7098. (interactive)
  7099. (org-agenda-archive-with 'org-archive-subtree))
  7100. (defun org-agenda-archive-to-archive-sibling ()
  7101. "Move the entry to the archive sibling."
  7102. (interactive)
  7103. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7104. (defun org-agenda-archive-with (cmd &optional confirm)
  7105. "Move the entry to the archive sibling."
  7106. (interactive)
  7107. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7108. (let* ((bufname-orig (buffer-name))
  7109. (marker (or (org-get-at-bol 'org-marker)
  7110. (org-agenda-error)))
  7111. (buffer (marker-buffer marker))
  7112. (pos (marker-position marker)))
  7113. (org-with-remote-undo buffer
  7114. (with-current-buffer buffer
  7115. (if (derived-mode-p 'org-mode)
  7116. (if (and confirm
  7117. (not (y-or-n-p "Archive this subtree or entry? ")))
  7118. (error "Abort")
  7119. (save-excursion
  7120. (goto-char pos)
  7121. (let ((org-agenda-buffer-name bufname-orig))
  7122. (org-remove-subtree-entries-from-agenda))
  7123. (org-back-to-heading t)
  7124. (funcall cmd)))
  7125. (error "Archiving works only in Org-mode files"))))))
  7126. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7127. "Remove all lines in the agenda that correspond to a given subtree.
  7128. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7129. If this information is not given, the function uses the tree at point."
  7130. (let ((buf (or buf (current-buffer))) m p)
  7131. (save-excursion
  7132. (unless (and beg end)
  7133. (org-back-to-heading t)
  7134. (setq beg (point))
  7135. (org-end-of-subtree t)
  7136. (setq end (point)))
  7137. (set-buffer (get-buffer org-agenda-buffer-name))
  7138. (save-excursion
  7139. (goto-char (point-max))
  7140. (beginning-of-line 1)
  7141. (while (not (bobp))
  7142. (when (and (setq m (org-get-at-bol 'org-marker))
  7143. (equal buf (marker-buffer m))
  7144. (setq p (marker-position m))
  7145. (>= p beg)
  7146. (< p end))
  7147. (let ((inhibit-read-only t))
  7148. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7149. (beginning-of-line 0))))))
  7150. (defun org-agenda-refile (&optional goto rfloc no-update)
  7151. "Refile the item at point."
  7152. (interactive "P")
  7153. (if (equal goto '(16))
  7154. (org-refile-goto-last-stored)
  7155. (let* ((buffer-orig (buffer-name))
  7156. (marker (or (org-get-at-bol 'org-hd-marker)
  7157. (org-agenda-error)))
  7158. (buffer (marker-buffer marker))
  7159. (pos (marker-position marker))
  7160. (rfloc (or rfloc
  7161. (org-refile-get-location
  7162. (if goto "Goto" "Refile to") buffer
  7163. org-refile-allow-creating-parent-nodes))))
  7164. (with-current-buffer buffer
  7165. (save-excursion
  7166. (save-restriction
  7167. (widen)
  7168. (goto-char marker)
  7169. (let ((org-agenda-buffer-name buffer-orig))
  7170. (org-remove-subtree-entries-from-agenda))
  7171. (org-refile goto buffer rfloc)))))
  7172. (unless no-update (org-agenda-redo))))
  7173. (defun org-agenda-open-link (&optional arg)
  7174. "Follow the link in the current line, if any.
  7175. This looks for a link in the displayed line in the agenda. It also looks
  7176. at the text of the entry itself."
  7177. (interactive "P")
  7178. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7179. (org-get-at-bol 'org-marker)))
  7180. (buffer (and marker (marker-buffer marker)))
  7181. (prefix (buffer-substring
  7182. (point-at-bol) (point-at-eol))))
  7183. (cond
  7184. (buffer
  7185. (with-current-buffer buffer
  7186. (save-excursion
  7187. (save-restriction
  7188. (widen)
  7189. (goto-char marker)
  7190. (org-offer-links-in-entry arg prefix)))))
  7191. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7192. (save-excursion
  7193. (beginning-of-line 1)
  7194. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7195. (org-open-link-from-string (match-string 1)))
  7196. (t (error "No link to open here")))))
  7197. (defun org-agenda-copy-local-variable (var)
  7198. "Get a variable from a referenced buffer and install it here."
  7199. (let ((m (org-get-at-bol 'org-marker)))
  7200. (when (and m (buffer-live-p (marker-buffer m)))
  7201. (org-set-local var (with-current-buffer (marker-buffer m)
  7202. (symbol-value var))))))
  7203. (defun org-agenda-switch-to (&optional delete-other-windows)
  7204. "Go to the Org-mode file which contains the item at point."
  7205. (interactive)
  7206. (if (and org-return-follows-link
  7207. (not (org-get-at-bol 'org-marker))
  7208. (org-in-regexp org-bracket-link-regexp))
  7209. (org-open-link-from-string (match-string 0))
  7210. (let* ((marker (or (org-get-at-bol 'org-marker)
  7211. (org-agenda-error)))
  7212. (buffer (marker-buffer marker))
  7213. (pos (marker-position marker)))
  7214. (org-pop-to-buffer-same-window buffer)
  7215. (and delete-other-windows (delete-other-windows))
  7216. (widen)
  7217. (goto-char pos)
  7218. (when (derived-mode-p 'org-mode)
  7219. (org-show-context 'agenda)
  7220. (save-excursion
  7221. (and (outline-next-heading)
  7222. (org-flag-heading nil))) ; show the next heading
  7223. (when (outline-invisible-p)
  7224. (show-entry)) ; display invisible text
  7225. (run-hooks 'org-agenda-after-show-hook)))))
  7226. (defun org-agenda-goto-mouse (ev)
  7227. "Go to the Org-mode file which contains the item at the mouse click."
  7228. (interactive "e")
  7229. (mouse-set-point ev)
  7230. (org-agenda-goto))
  7231. (defun org-agenda-show (&optional full-entry)
  7232. "Display the Org-mode file which contains the item at point.
  7233. With prefix argument FULL-ENTRY, make the entire entry visible
  7234. if it was hidden in the outline."
  7235. (interactive "P")
  7236. (let ((win (selected-window)))
  7237. (if full-entry
  7238. (let ((org-show-entry-below t))
  7239. (org-agenda-goto t))
  7240. (org-agenda-goto t))
  7241. (select-window win)))
  7242. (defvar org-agenda-show-window nil)
  7243. (defun org-agenda-show-and-scroll-up (&optional arg)
  7244. "Display the Org-mode file which contains the item at point.
  7245. When called repeatedly, scroll the window that is displaying the buffer.
  7246. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7247. `show-subtree' to display the item, so that drawers and logbooks stay
  7248. folded."
  7249. (interactive "P")
  7250. (let ((win (selected-window)))
  7251. (if (and (window-live-p org-agenda-show-window)
  7252. (eq this-command last-command))
  7253. (progn
  7254. (select-window org-agenda-show-window)
  7255. (ignore-errors (scroll-up)))
  7256. (org-agenda-goto t)
  7257. (if arg (org-show-entry) (show-subtree))
  7258. (setq org-agenda-show-window (selected-window)))
  7259. (select-window win)))
  7260. (defun org-agenda-show-scroll-down ()
  7261. "Scroll down the window showing the agenda."
  7262. (interactive)
  7263. (let ((win (selected-window)))
  7264. (when (window-live-p org-agenda-show-window)
  7265. (select-window org-agenda-show-window)
  7266. (ignore-errors (scroll-down))
  7267. (select-window win))))
  7268. (defun org-agenda-show-1 (&optional more)
  7269. "Display the Org-mode file which contains the item at point.
  7270. The prefix arg selects the amount of information to display:
  7271. 0 hide the subtree
  7272. 1 just show the entry according to defaults.
  7273. 2 show the children view
  7274. 3 show the subtree view
  7275. 4 show the entire subtree and any LOGBOOK drawers
  7276. 5 show the entire subtree and any drawers
  7277. With prefix argument FULL-ENTRY, make the entire entry visible
  7278. if it was hidden in the outline."
  7279. (interactive "p")
  7280. (let ((win (selected-window)))
  7281. (org-agenda-goto t)
  7282. (org-recenter-heading 1)
  7283. (cond
  7284. ((= more 0)
  7285. (hide-subtree)
  7286. (save-excursion
  7287. (org-back-to-heading)
  7288. (run-hook-with-args 'org-cycle-hook 'folded))
  7289. (message "Remote: FOLDED"))
  7290. ((and (org-called-interactively-p 'any) (= more 1))
  7291. (message "Remote: show with default settings"))
  7292. ((= more 2)
  7293. (show-entry)
  7294. (show-children)
  7295. (save-excursion
  7296. (org-back-to-heading)
  7297. (run-hook-with-args 'org-cycle-hook 'children))
  7298. (message "Remote: CHILDREN"))
  7299. ((= more 3)
  7300. (show-subtree)
  7301. (save-excursion
  7302. (org-back-to-heading)
  7303. (run-hook-with-args 'org-cycle-hook 'subtree))
  7304. (message "Remote: SUBTREE"))
  7305. ((= more 4)
  7306. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7307. (org-drawer-regexp
  7308. (concat "^[ \t]*:\\("
  7309. (mapconcat 'regexp-quote org-drawers "\\|")
  7310. "\\):[ \t]*$")))
  7311. (show-subtree)
  7312. (save-excursion
  7313. (org-back-to-heading)
  7314. (org-cycle-hide-drawers 'subtree)))
  7315. (message "Remote: SUBTREE AND LOGBOOK"))
  7316. ((> more 4)
  7317. (show-subtree)
  7318. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7319. (select-window win)))
  7320. (defun org-recenter-heading (n)
  7321. (save-excursion
  7322. (org-back-to-heading)
  7323. (recenter n)))
  7324. (defvar org-agenda-cycle-counter nil)
  7325. (defun org-agenda-cycle-show (&optional n)
  7326. "Show the current entry in another window, with default settings.
  7327. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7328. When use repeatedly in immediate succession, the remote entry will cycle
  7329. through visibility
  7330. children -> subtree -> folded
  7331. When called with a numeric prefix arg, that arg will be passed through to
  7332. `org-agenda-show-1'. For the interpretation of that argument, see the
  7333. docstring of `org-agenda-show-1'."
  7334. (interactive "P")
  7335. (if (integerp n)
  7336. (setq org-agenda-cycle-counter n)
  7337. (if (not (eq last-command this-command))
  7338. (setq org-agenda-cycle-counter 1)
  7339. (if (equal org-agenda-cycle-counter 0)
  7340. (setq org-agenda-cycle-counter 2)
  7341. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7342. (if (> org-agenda-cycle-counter 3)
  7343. (setq org-agenda-cycle-counter 0)))))
  7344. (org-agenda-show-1 org-agenda-cycle-counter))
  7345. (defun org-agenda-recenter (arg)
  7346. "Display the Org-mode file which contains the item at point and recenter."
  7347. (interactive "P")
  7348. (let ((win (selected-window)))
  7349. (org-agenda-goto t)
  7350. (recenter arg)
  7351. (select-window win)))
  7352. (defun org-agenda-show-mouse (ev)
  7353. "Display the Org-mode file which contains the item at the mouse click."
  7354. (interactive "e")
  7355. (mouse-set-point ev)
  7356. (org-agenda-show))
  7357. (defun org-agenda-check-no-diary ()
  7358. "Check if the entry is a diary link and abort if yes."
  7359. (if (org-get-at-bol 'org-agenda-diary-link)
  7360. (org-agenda-error)))
  7361. (defun org-agenda-error ()
  7362. (error "Command not allowed in this line"))
  7363. (defun org-agenda-tree-to-indirect-buffer ()
  7364. "Show the subtree corresponding to the current entry in an indirect buffer.
  7365. This calls the command `org-tree-to-indirect-buffer' from the original
  7366. Org-mode buffer.
  7367. With numerical prefix arg ARG, go up to this level and then take that tree.
  7368. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7369. use the dedicated frame)."
  7370. (interactive)
  7371. (if (and current-prefix-arg (listp current-prefix-arg))
  7372. (org-agenda-do-tree-to-indirect-buffer)
  7373. (let ((agenda-window (selected-window))
  7374. (indirect-window
  7375. (and org-last-indirect-buffer
  7376. (get-buffer-window org-last-indirect-buffer))))
  7377. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7378. (unwind-protect
  7379. (progn
  7380. (unless (and indirect-window (window-live-p indirect-window))
  7381. (setq indirect-window (split-window agenda-window)))
  7382. (select-window indirect-window)
  7383. (switch-to-buffer org-last-indirect-buffer :norecord)
  7384. (fit-window-to-buffer indirect-window))
  7385. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7386. (defun org-agenda-do-tree-to-indirect-buffer ()
  7387. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7388. (org-agenda-check-no-diary)
  7389. (let* ((marker (or (org-get-at-bol 'org-marker)
  7390. (org-agenda-error)))
  7391. (buffer (marker-buffer marker))
  7392. (pos (marker-position marker)))
  7393. (with-current-buffer buffer
  7394. (save-excursion
  7395. (goto-char pos)
  7396. (call-interactively 'org-tree-to-indirect-buffer)))))
  7397. (defvar org-last-heading-marker (make-marker)
  7398. "Marker pointing to the headline that last changed its TODO state
  7399. by a remote command from the agenda.")
  7400. (defun org-agenda-todo-nextset ()
  7401. "Switch TODO entry to next sequence."
  7402. (interactive)
  7403. (org-agenda-todo 'nextset))
  7404. (defun org-agenda-todo-previousset ()
  7405. "Switch TODO entry to previous sequence."
  7406. (interactive)
  7407. (org-agenda-todo 'previousset))
  7408. (defun org-agenda-todo (&optional arg)
  7409. "Cycle TODO state of line at point, also in Org-mode file.
  7410. This changes the line at point, all other lines in the agenda referring to
  7411. the same tree node, and the headline of the tree node in the Org-mode file."
  7412. (interactive "P")
  7413. (org-agenda-check-no-diary)
  7414. (let* ((col (current-column))
  7415. (marker (or (org-get-at-bol 'org-marker)
  7416. (org-agenda-error)))
  7417. (buffer (marker-buffer marker))
  7418. (pos (marker-position marker))
  7419. (hdmarker (org-get-at-bol 'org-hd-marker))
  7420. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7421. (inhibit-read-only t)
  7422. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7423. (org-with-remote-undo buffer
  7424. (with-current-buffer buffer
  7425. (widen)
  7426. (goto-char pos)
  7427. (org-show-context 'agenda)
  7428. (save-excursion
  7429. (and (outline-next-heading)
  7430. (org-flag-heading nil))) ; show the next heading
  7431. (let ((current-prefix-arg arg))
  7432. (call-interactively 'org-todo))
  7433. (and (bolp) (forward-char 1))
  7434. (setq newhead (org-get-heading))
  7435. (when (and (org-bound-and-true-p
  7436. org-agenda-headline-snapshot-before-repeat)
  7437. (not (equal org-agenda-headline-snapshot-before-repeat
  7438. newhead))
  7439. todayp)
  7440. (setq newhead org-agenda-headline-snapshot-before-repeat
  7441. just-one t))
  7442. (save-excursion
  7443. (org-back-to-heading)
  7444. (move-marker org-last-heading-marker (point))))
  7445. (beginning-of-line 1)
  7446. (save-excursion
  7447. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7448. (org-move-to-column col))))
  7449. (defun org-agenda-add-note (&optional arg)
  7450. "Add a time-stamped note to the entry at point."
  7451. (interactive "P")
  7452. (org-agenda-check-no-diary)
  7453. (let* ((marker (or (org-get-at-bol 'org-marker)
  7454. (org-agenda-error)))
  7455. (buffer (marker-buffer marker))
  7456. (pos (marker-position marker))
  7457. (hdmarker (org-get-at-bol 'org-hd-marker))
  7458. (inhibit-read-only t))
  7459. (with-current-buffer buffer
  7460. (widen)
  7461. (goto-char pos)
  7462. (org-show-context 'agenda)
  7463. (save-excursion
  7464. (and (outline-next-heading)
  7465. (org-flag-heading nil))) ; show the next heading
  7466. (org-add-note))))
  7467. (defun org-agenda-change-all-lines (newhead hdmarker
  7468. &optional fixface just-this)
  7469. "Change all lines in the agenda buffer which match HDMARKER.
  7470. The new content of the line will be NEWHEAD (as modified by
  7471. `org-agenda-format-item'). HDMARKER is checked with
  7472. `equal' against all `org-hd-marker' text properties in the file.
  7473. If FIXFACE is non-nil, the face of each item is modified according to
  7474. the new TODO state.
  7475. If JUST-THIS is non-nil, change just the current line, not all.
  7476. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7477. (let* ((inhibit-read-only t)
  7478. (line (org-current-line))
  7479. (org-agenda-buffer (current-buffer))
  7480. (thetags (with-current-buffer (marker-buffer hdmarker)
  7481. (save-excursion (save-restriction (widen)
  7482. (goto-char hdmarker)
  7483. (org-get-tags-at)))))
  7484. props m pl undone-face done-face finish new dotime level cat tags)
  7485. (save-excursion
  7486. (goto-char (point-max))
  7487. (beginning-of-line 1)
  7488. (while (not finish)
  7489. (setq finish (bobp))
  7490. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7491. (or (not just-this) (= (org-current-line) line))
  7492. (equal m hdmarker))
  7493. (setq props (text-properties-at (point))
  7494. dotime (org-get-at-bol 'dotime)
  7495. cat (org-get-at-bol 'org-category)
  7496. level (org-get-at-bol 'level)
  7497. tags thetags
  7498. new
  7499. (let ((org-prefix-format-compiled
  7500. (or (get-text-property (point) 'format)
  7501. org-prefix-format-compiled))
  7502. (extra (org-get-at-bol 'extra)))
  7503. (with-current-buffer (marker-buffer hdmarker)
  7504. (save-excursion
  7505. (save-restriction
  7506. (widen)
  7507. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7508. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7509. undone-face (org-get-at-bol 'undone-face)
  7510. done-face (org-get-at-bol 'done-face))
  7511. (beginning-of-line 1)
  7512. (cond
  7513. ((equal new "")
  7514. (and (looking-at ".*\n?") (replace-match "")))
  7515. ((looking-at ".*")
  7516. (replace-match new t t)
  7517. (beginning-of-line 1)
  7518. (add-text-properties (point-at-bol) (point-at-eol) props)
  7519. (when fixface
  7520. (add-text-properties
  7521. (point-at-bol) (point-at-eol)
  7522. (list 'face
  7523. (if org-last-todo-state-is-todo
  7524. undone-face done-face))))
  7525. (org-agenda-highlight-todo 'line)
  7526. (beginning-of-line 1))
  7527. (t (error "Line update did not work"))))
  7528. (beginning-of-line 0)))
  7529. (org-agenda-finalize)))
  7530. (defun org-agenda-align-tags (&optional line)
  7531. "Align all tags in agenda items to `org-agenda-tags-column'."
  7532. (let ((inhibit-read-only t) l c)
  7533. (save-excursion
  7534. (goto-char (if line (point-at-bol) (point-min)))
  7535. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7536. (if line (point-at-eol) nil) t)
  7537. (add-text-properties
  7538. (match-beginning 2) (match-end 2)
  7539. (list 'face (delq nil (let ((prop (get-text-property
  7540. (match-beginning 2) 'face)))
  7541. (or (listp prop) (setq prop (list prop)))
  7542. (if (memq 'org-tag prop)
  7543. prop
  7544. (cons 'org-tag prop))))))
  7545. (setq l (- (match-end 2) (match-beginning 2))
  7546. c (if (< org-agenda-tags-column 0)
  7547. (- (abs org-agenda-tags-column) l)
  7548. org-agenda-tags-column))
  7549. (delete-region (match-beginning 1) (match-end 1))
  7550. (goto-char (match-beginning 1))
  7551. (insert (org-add-props
  7552. (make-string (max 1 (- c (current-column))) ?\ )
  7553. (plist-put (copy-sequence (text-properties-at (point)))
  7554. 'face nil))))
  7555. (goto-char (point-min))
  7556. (org-font-lock-add-tag-faces (point-max)))))
  7557. (defun org-agenda-priority-up ()
  7558. "Increase the priority of line at point, also in Org-mode file."
  7559. (interactive)
  7560. (org-agenda-priority 'up))
  7561. (defun org-agenda-priority-down ()
  7562. "Decrease the priority of line at point, also in Org-mode file."
  7563. (interactive)
  7564. (org-agenda-priority 'down))
  7565. (defun org-agenda-priority (&optional force-direction)
  7566. "Set the priority of line at point, also in Org-mode file.
  7567. This changes the line at point, all other lines in the agenda referring to
  7568. the same tree node, and the headline of the tree node in the Org-mode file."
  7569. (interactive)
  7570. (unless org-enable-priority-commands
  7571. (error "Priority commands are disabled"))
  7572. (org-agenda-check-no-diary)
  7573. (let* ((marker (or (org-get-at-bol 'org-marker)
  7574. (org-agenda-error)))
  7575. (hdmarker (org-get-at-bol 'org-hd-marker))
  7576. (buffer (marker-buffer hdmarker))
  7577. (pos (marker-position hdmarker))
  7578. (inhibit-read-only t)
  7579. newhead)
  7580. (org-with-remote-undo buffer
  7581. (with-current-buffer buffer
  7582. (widen)
  7583. (goto-char pos)
  7584. (org-show-context 'agenda)
  7585. (save-excursion
  7586. (and (outline-next-heading)
  7587. (org-flag-heading nil))) ; show the next heading
  7588. (funcall 'org-priority force-direction)
  7589. (end-of-line 1)
  7590. (setq newhead (org-get-heading)))
  7591. (org-agenda-change-all-lines newhead hdmarker)
  7592. (beginning-of-line 1))))
  7593. ;; FIXME: should fix the tags property of the agenda line.
  7594. (defun org-agenda-set-tags (&optional tag onoff)
  7595. "Set tags for the current headline."
  7596. (interactive)
  7597. (org-agenda-check-no-diary)
  7598. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7599. (call-interactively 'org-change-tag-in-region)
  7600. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7601. (org-agenda-error)))
  7602. (buffer (marker-buffer hdmarker))
  7603. (pos (marker-position hdmarker))
  7604. (inhibit-read-only t)
  7605. newhead)
  7606. (org-with-remote-undo buffer
  7607. (with-current-buffer buffer
  7608. (widen)
  7609. (goto-char pos)
  7610. (save-excursion
  7611. (org-show-context 'agenda))
  7612. (save-excursion
  7613. (and (outline-next-heading)
  7614. (org-flag-heading nil))) ; show the next heading
  7615. (goto-char pos)
  7616. (if tag
  7617. (org-toggle-tag tag onoff)
  7618. (call-interactively 'org-set-tags))
  7619. (end-of-line 1)
  7620. (setq newhead (org-get-heading)))
  7621. (org-agenda-change-all-lines newhead hdmarker)
  7622. (beginning-of-line 1)))))
  7623. (defun org-agenda-set-property ()
  7624. "Set a property for the current headline."
  7625. (interactive)
  7626. (org-agenda-check-no-diary)
  7627. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7628. (org-agenda-error)))
  7629. (buffer (marker-buffer hdmarker))
  7630. (pos (marker-position hdmarker))
  7631. (inhibit-read-only t)
  7632. newhead)
  7633. (org-with-remote-undo buffer
  7634. (with-current-buffer buffer
  7635. (widen)
  7636. (goto-char pos)
  7637. (save-excursion
  7638. (org-show-context 'agenda))
  7639. (save-excursion
  7640. (and (outline-next-heading)
  7641. (org-flag-heading nil))) ; show the next heading
  7642. (goto-char pos)
  7643. (call-interactively 'org-set-property)))))
  7644. (defun org-agenda-set-effort ()
  7645. "Set the effort property for the current headline."
  7646. (interactive)
  7647. (org-agenda-check-no-diary)
  7648. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7649. (org-agenda-error)))
  7650. (buffer (marker-buffer hdmarker))
  7651. (pos (marker-position hdmarker))
  7652. (inhibit-read-only t)
  7653. newhead)
  7654. (org-with-remote-undo buffer
  7655. (with-current-buffer buffer
  7656. (widen)
  7657. (goto-char pos)
  7658. (save-excursion
  7659. (org-show-context 'agenda))
  7660. (save-excursion
  7661. (and (outline-next-heading)
  7662. (org-flag-heading nil))) ; show the next heading
  7663. (goto-char pos)
  7664. (call-interactively 'org-set-effort)
  7665. (end-of-line 1)
  7666. (setq newhead (org-get-heading)))
  7667. (org-agenda-change-all-lines newhead hdmarker))))
  7668. (defun org-agenda-toggle-archive-tag ()
  7669. "Toggle the archive tag for the current entry."
  7670. (interactive)
  7671. (org-agenda-check-no-diary)
  7672. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7673. (org-agenda-error)))
  7674. (buffer (marker-buffer hdmarker))
  7675. (pos (marker-position hdmarker))
  7676. (inhibit-read-only t)
  7677. newhead)
  7678. (org-with-remote-undo buffer
  7679. (with-current-buffer buffer
  7680. (widen)
  7681. (goto-char pos)
  7682. (org-show-context 'agenda)
  7683. (save-excursion
  7684. (and (outline-next-heading)
  7685. (org-flag-heading nil))) ; show the next heading
  7686. (call-interactively 'org-toggle-archive-tag)
  7687. (end-of-line 1)
  7688. (setq newhead (org-get-heading)))
  7689. (org-agenda-change-all-lines newhead hdmarker)
  7690. (beginning-of-line 1))))
  7691. (defun org-agenda-do-date-later (arg)
  7692. (interactive "P")
  7693. (cond
  7694. ((or (equal arg '(16))
  7695. (memq last-command
  7696. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7697. (setq this-command 'org-agenda-date-later-minutes)
  7698. (org-agenda-date-later-minutes 1))
  7699. ((or (equal arg '(4))
  7700. (memq last-command
  7701. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7702. (setq this-command 'org-agenda-date-later-hours)
  7703. (org-agenda-date-later-hours 1))
  7704. (t
  7705. (org-agenda-date-later (prefix-numeric-value arg)))))
  7706. (defun org-agenda-do-date-earlier (arg)
  7707. (interactive "P")
  7708. (cond
  7709. ((or (equal arg '(16))
  7710. (memq last-command
  7711. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7712. (setq this-command 'org-agenda-date-earlier-minutes)
  7713. (org-agenda-date-earlier-minutes 1))
  7714. ((or (equal arg '(4))
  7715. (memq last-command
  7716. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7717. (setq this-command 'org-agenda-date-earlier-hours)
  7718. (org-agenda-date-earlier-hours 1))
  7719. (t
  7720. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7721. (defun org-agenda-date-later (arg &optional what)
  7722. "Change the date of this item to ARG day(s) later."
  7723. (interactive "p")
  7724. (org-agenda-check-type t 'agenda 'timeline)
  7725. (org-agenda-check-no-diary)
  7726. (let* ((marker (or (org-get-at-bol 'org-marker)
  7727. (org-agenda-error)))
  7728. (buffer (marker-buffer marker))
  7729. (pos (marker-position marker))
  7730. cdate today)
  7731. (org-with-remote-undo buffer
  7732. (with-current-buffer buffer
  7733. (widen)
  7734. (goto-char pos)
  7735. (if (not (org-at-timestamp-p))
  7736. (error "Cannot find time stamp"))
  7737. (when (and org-agenda-move-date-from-past-immediately-to-today
  7738. (equal arg 1)
  7739. (or (not what) (eq what 'day))
  7740. (not (save-match-data (org-at-date-range-p))))
  7741. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7742. cdate (calendar-absolute-from-gregorian
  7743. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7744. today (org-today))
  7745. (if (> today cdate)
  7746. ;; immediately shift to today
  7747. (setq arg (- today cdate))))
  7748. (org-timestamp-change arg (or what 'day))
  7749. (when (and (org-at-date-range-p)
  7750. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7751. (let ((end org-last-changed-timestamp))
  7752. (org-timestamp-change arg (or what 'day))
  7753. (setq org-last-changed-timestamp
  7754. (concat org-last-changed-timestamp "--" end)))))
  7755. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7756. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7757. (defun org-agenda-date-earlier (arg &optional what)
  7758. "Change the date of this item to ARG day(s) earlier."
  7759. (interactive "p")
  7760. (org-agenda-date-later (- arg) what))
  7761. (defun org-agenda-date-later-minutes (arg)
  7762. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7763. (interactive "p")
  7764. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7765. (org-agenda-date-later arg 'minute))
  7766. (defun org-agenda-date-earlier-minutes (arg)
  7767. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7768. (interactive "p")
  7769. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7770. (org-agenda-date-earlier arg 'minute))
  7771. (defun org-agenda-date-later-hours (arg)
  7772. "Change the time of this item, in hour steps."
  7773. (interactive "p")
  7774. (org-agenda-date-later arg 'hour))
  7775. (defun org-agenda-date-earlier-hours (arg)
  7776. "Change the time of this item, in hour steps."
  7777. (interactive "p")
  7778. (org-agenda-date-earlier arg 'hour))
  7779. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7780. "Show new date stamp via text properties."
  7781. ;; We use text properties to make this undoable
  7782. (let ((inhibit-read-only t)
  7783. (buffer-invisibility-spec))
  7784. (setq stamp (concat " " prefix " => " stamp))
  7785. (save-excursion
  7786. (goto-char (point-max))
  7787. (while (not (bobp))
  7788. (when (equal marker (org-get-at-bol 'org-marker))
  7789. (org-move-to-column (- (window-width) (length stamp)) t)
  7790. (org-agenda-fix-tags-filter-overlays-at (point))
  7791. (if (featurep 'xemacs)
  7792. ;; Use `duplicable' property to trigger undo recording
  7793. (let ((ex (make-extent nil nil))
  7794. (gl (make-glyph stamp)))
  7795. (set-glyph-face gl 'secondary-selection)
  7796. (set-extent-properties
  7797. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7798. (insert-extent ex (1- (point)) (point-at-eol)))
  7799. (add-text-properties
  7800. (1- (point)) (point-at-eol)
  7801. (list 'display (org-add-props stamp nil
  7802. 'face 'secondary-selection))))
  7803. (beginning-of-line 1))
  7804. (beginning-of-line 0)))))
  7805. (defun org-agenda-date-prompt (arg)
  7806. "Change the date of this item. Date is prompted for, with default today.
  7807. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7808. be used to request time specification in the time stamp."
  7809. (interactive "P")
  7810. (org-agenda-check-type t 'agenda 'timeline)
  7811. (org-agenda-check-no-diary)
  7812. (let* ((marker (or (org-get-at-bol 'org-marker)
  7813. (org-agenda-error)))
  7814. (buffer (marker-buffer marker))
  7815. (pos (marker-position marker)))
  7816. (org-with-remote-undo buffer
  7817. (with-current-buffer buffer
  7818. (widen)
  7819. (goto-char pos)
  7820. (if (not (org-at-timestamp-p t))
  7821. (error "Cannot find time stamp"))
  7822. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7823. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7824. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7825. (defun org-agenda-schedule (arg &optional time)
  7826. "Schedule the item at point.
  7827. ARG is passed through to `org-schedule'."
  7828. (interactive "P")
  7829. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7830. (org-agenda-check-no-diary)
  7831. (let* ((marker (or (org-get-at-bol 'org-marker)
  7832. (org-agenda-error)))
  7833. (type (marker-insertion-type marker))
  7834. (buffer (marker-buffer marker))
  7835. (pos (marker-position marker))
  7836. (org-insert-labeled-timestamps-at-point nil)
  7837. ts)
  7838. (set-marker-insertion-type marker t)
  7839. (org-with-remote-undo buffer
  7840. (with-current-buffer buffer
  7841. (widen)
  7842. (goto-char pos)
  7843. (setq ts (org-schedule arg time)))
  7844. (org-agenda-show-new-time marker ts "S"))
  7845. (message "Item scheduled for %s" ts)))
  7846. (defun org-agenda-deadline (arg &optional time)
  7847. "Schedule the item at point.
  7848. ARG is passed through to `org-deadline'."
  7849. (interactive "P")
  7850. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7851. (org-agenda-check-no-diary)
  7852. (let* ((marker (or (org-get-at-bol 'org-marker)
  7853. (org-agenda-error)))
  7854. (buffer (marker-buffer marker))
  7855. (pos (marker-position marker))
  7856. (org-insert-labeled-timestamps-at-point nil)
  7857. ts)
  7858. (org-with-remote-undo buffer
  7859. (with-current-buffer buffer
  7860. (widen)
  7861. (goto-char pos)
  7862. (setq ts (org-deadline arg time)))
  7863. (org-agenda-show-new-time marker ts "D"))
  7864. (message "Deadline for this item set to %s" ts)))
  7865. (defun org-agenda-clock-in (&optional arg)
  7866. "Start the clock on the currently selected item."
  7867. (interactive "P")
  7868. (org-agenda-check-no-diary)
  7869. (if (equal arg '(4))
  7870. (org-clock-in arg)
  7871. (let* ((marker (or (org-get-at-bol 'org-marker)
  7872. (org-agenda-error)))
  7873. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7874. marker))
  7875. (pos (marker-position marker))
  7876. newhead)
  7877. (org-with-remote-undo (marker-buffer marker)
  7878. (with-current-buffer (marker-buffer marker)
  7879. (widen)
  7880. (goto-char pos)
  7881. (org-show-context 'agenda)
  7882. (org-show-entry)
  7883. (org-cycle-hide-drawers 'children)
  7884. (org-clock-in arg)
  7885. (setq newhead (org-get-heading)))
  7886. (org-agenda-change-all-lines newhead hdmarker)))))
  7887. (defun org-agenda-clock-out ()
  7888. "Stop the currently running clock."
  7889. (interactive)
  7890. (unless (marker-buffer org-clock-marker)
  7891. (error "No running clock"))
  7892. (let ((marker (make-marker)) newhead)
  7893. (org-with-remote-undo (marker-buffer org-clock-marker)
  7894. (with-current-buffer (marker-buffer org-clock-marker)
  7895. (save-excursion
  7896. (save-restriction
  7897. (widen)
  7898. (goto-char org-clock-marker)
  7899. (org-back-to-heading t)
  7900. (move-marker marker (point))
  7901. (org-clock-out)
  7902. (setq newhead (org-get-heading))))))
  7903. (org-agenda-change-all-lines newhead marker)
  7904. (move-marker marker nil)))
  7905. (defun org-agenda-clock-cancel (&optional arg)
  7906. "Cancel the currently running clock."
  7907. (interactive "P")
  7908. (unless (marker-buffer org-clock-marker)
  7909. (error "No running clock"))
  7910. (org-with-remote-undo (marker-buffer org-clock-marker)
  7911. (org-clock-cancel)))
  7912. (defun org-agenda-clock-goto ()
  7913. "Jump to the currently clocked in task within the agenda.
  7914. If the currently clocked in task is not listed in the agenda
  7915. buffer, display it in another window."
  7916. (interactive)
  7917. (let (pos)
  7918. (mapc (lambda (o)
  7919. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7920. (setq pos (overlay-start o))))
  7921. (overlays-in (point-min) (point-max)))
  7922. (cond (pos (goto-char pos))
  7923. ;; If the currently clocked entry is not in the agenda
  7924. ;; buffer, we visit it in another window:
  7925. (org-clock-current-task
  7926. (org-switch-to-buffer-other-window (org-clock-goto)))
  7927. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7928. (defun org-agenda-diary-entry-in-org-file ()
  7929. "Make a diary entry in the file `org-agenda-diary-file'."
  7930. (let (d1 d2 char (text "") dp1 dp2)
  7931. (if (equal (buffer-name) "*Calendar*")
  7932. (setq d1 (calendar-cursor-to-date t)
  7933. d2 (car calendar-mark-ring))
  7934. (setq dp1 (get-text-property (point-at-bol) 'day))
  7935. (unless dp1 (error "No date defined in current line"))
  7936. (setq d1 (calendar-gregorian-from-absolute dp1)
  7937. d2 (and (ignore-errors (mark))
  7938. (save-excursion
  7939. (goto-char (mark))
  7940. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7941. (calendar-gregorian-from-absolute dp2))))
  7942. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7943. (setq char (read-char-exclusive))
  7944. (cond
  7945. ((equal char ?d)
  7946. (setq text (read-string "Day entry: "))
  7947. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7948. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7949. ((equal char ?a)
  7950. (setq d1 (list (car d1) (nth 1 d1)
  7951. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7952. (nth 2 d1))))
  7953. (setq text (read-string "Anniversary (use %d to show years): "))
  7954. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7955. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7956. ((equal char ?b)
  7957. (setq text (read-string "Block entry: "))
  7958. (unless (and d1 d2 (not (equal d1 d2)))
  7959. (error "No block of days selected"))
  7960. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7961. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7962. ((equal char ?j)
  7963. (org-switch-to-buffer-other-window
  7964. (find-file-noselect org-agenda-diary-file))
  7965. (require 'org-datetree)
  7966. (org-datetree-find-date-create d1)
  7967. (org-reveal t))
  7968. (t (error "Invalid selection character `%c'" char)))))
  7969. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7970. "Where in `org-agenda-diary-file' should new entries be added?
  7971. Valid values:
  7972. date-tree in the date tree, as child of the date
  7973. top-level as top-level entries at the end of the file."
  7974. :group 'org-agenda
  7975. :type '(choice
  7976. (const :tag "in a date tree" date-tree)
  7977. (const :tag "as top level at end of file" top-level)))
  7978. (defcustom org-agenda-insert-diary-extract-time nil
  7979. "Non-nil means extract any time specification from the diary entry."
  7980. :group 'org-agenda
  7981. :version "24.1"
  7982. :type 'boolean)
  7983. (defcustom org-agenda-bulk-mark-char ">"
  7984. "A single-character string to be used as the bulk mark."
  7985. :group 'org-agenda
  7986. :version "24.1"
  7987. :type 'string)
  7988. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7989. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7990. If TEXT is not empty, it will become the headline of the new entry, and
  7991. the resulting entry will not be shown. When TEXT is empty, switch to
  7992. `org-agenda-diary-file' and let the user finish the entry there."
  7993. (let ((cw (current-window-configuration)))
  7994. (org-switch-to-buffer-other-window
  7995. (find-file-noselect org-agenda-diary-file))
  7996. (widen)
  7997. (goto-char (point-min))
  7998. (cond
  7999. ((eq type 'anniversary)
  8000. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8001. (progn
  8002. (or (org-at-heading-p t)
  8003. (progn
  8004. (outline-next-heading)
  8005. (insert "* Anniversaries\n\n")
  8006. (beginning-of-line -1)))))
  8007. (outline-next-heading)
  8008. (org-back-over-empty-lines)
  8009. (backward-char 1)
  8010. (insert "\n")
  8011. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8012. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8013. ((eq type 'day)
  8014. (let ((org-prefix-has-time t)
  8015. (org-agenda-time-leading-zero t)
  8016. fmt time time2)
  8017. (if org-agenda-insert-diary-extract-time
  8018. ;; Use org-agenda-format-item to parse text for a time-range and
  8019. ;; remove it. FIXME: This is a hack, we should refactor
  8020. ;; that function to make time extraction available separately
  8021. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8022. time (get-text-property 0 'time fmt)
  8023. time2 (if (> (length time) 0)
  8024. ;; split-string removes trailing ...... if
  8025. ;; no end time given. First space
  8026. ;; separates time from date.
  8027. (concat " " (car (split-string time "\\.")))
  8028. nil)
  8029. text (get-text-property 0 'txt fmt)))
  8030. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8031. (org-agenda-insert-diary-as-top-level text)
  8032. (require 'org-datetree)
  8033. (org-datetree-find-date-create d1)
  8034. (org-agenda-insert-diary-make-new-entry text))
  8035. (org-insert-time-stamp (org-time-from-absolute
  8036. (calendar-absolute-from-gregorian d1))
  8037. nil nil nil nil time2))
  8038. (end-of-line 0))
  8039. ((eq type 'block)
  8040. (if (> (calendar-absolute-from-gregorian d1)
  8041. (calendar-absolute-from-gregorian d2))
  8042. (setq d1 (prog1 d2 (setq d2 d1))))
  8043. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8044. (org-agenda-insert-diary-as-top-level text)
  8045. (require 'org-datetree)
  8046. (org-datetree-find-date-create d1)
  8047. (org-agenda-insert-diary-make-new-entry text))
  8048. (org-insert-time-stamp (org-time-from-absolute
  8049. (calendar-absolute-from-gregorian d1)))
  8050. (insert "--")
  8051. (org-insert-time-stamp (org-time-from-absolute
  8052. (calendar-absolute-from-gregorian d2)))
  8053. (end-of-line 0)))
  8054. (if (string-match "\\S-" text)
  8055. (progn
  8056. (set-window-configuration cw)
  8057. (message "%s entry added to %s"
  8058. (capitalize (symbol-name type))
  8059. (abbreviate-file-name org-agenda-diary-file)))
  8060. (org-reveal t)
  8061. (message "Please finish entry here"))))
  8062. (defun org-agenda-insert-diary-as-top-level (text)
  8063. "Make new entry as a top-level entry at the end of the file.
  8064. Add TEXT as headline, and position the cursor in the second line so that
  8065. a timestamp can be added there."
  8066. (widen)
  8067. (goto-char (point-max))
  8068. (or (bolp) (insert "\n"))
  8069. (insert "* " text "\n")
  8070. (if org-adapt-indentation (org-indent-to-column 2)))
  8071. (defun org-agenda-insert-diary-make-new-entry (text)
  8072. "Make new entry as last child of current entry.
  8073. Add TEXT as headline, and position the cursor in the second line so that
  8074. a timestamp can be added there."
  8075. (let ((org-show-following-heading t)
  8076. (org-show-siblings t)
  8077. (org-show-hierarchy-above t)
  8078. (org-show-entry-below t)
  8079. col)
  8080. (outline-next-heading)
  8081. (org-back-over-empty-lines)
  8082. (or (looking-at "[ \t]*$")
  8083. (progn (insert "\n") (backward-char 1)))
  8084. (org-insert-heading nil t)
  8085. (org-do-demote)
  8086. (setq col (current-column))
  8087. (insert text "\n")
  8088. (if org-adapt-indentation (org-indent-to-column col))
  8089. (let ((org-show-following-heading t)
  8090. (org-show-siblings t)
  8091. (org-show-hierarchy-above t)
  8092. (org-show-entry-below t))
  8093. (org-show-context))))
  8094. (defun org-agenda-diary-entry ()
  8095. "Make a diary entry, like the `i' command from the calendar.
  8096. All the standard commands work: block, weekly etc.
  8097. When `org-agenda-diary-file' points to a file,
  8098. `org-agenda-diary-entry-in-org-file' is called instead to create
  8099. entries in that Org-mode file."
  8100. (interactive)
  8101. (org-agenda-check-type t 'agenda 'timeline)
  8102. (if (not (eq org-agenda-diary-file 'diary-file))
  8103. (org-agenda-diary-entry-in-org-file)
  8104. (require 'diary-lib)
  8105. (let* ((char (progn
  8106. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8107. (read-char-exclusive)))
  8108. (cmd (cdr (assoc char
  8109. '((?d . insert-diary-entry)
  8110. (?w . insert-weekly-diary-entry)
  8111. (?m . insert-monthly-diary-entry)
  8112. (?y . insert-yearly-diary-entry)
  8113. (?a . insert-anniversary-diary-entry)
  8114. (?b . insert-block-diary-entry)
  8115. (?c . insert-cyclic-diary-entry)))))
  8116. (oldf (symbol-function 'calendar-cursor-to-date))
  8117. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8118. (point (point))
  8119. (mark (or (mark t) (point))))
  8120. (unless cmd
  8121. (error "No command associated with <%c>" char))
  8122. (unless (and (get-text-property point 'day)
  8123. (or (not (equal ?b char))
  8124. (get-text-property mark 'day)))
  8125. (error "Don't know which date to use for diary entry"))
  8126. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8127. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8128. (let ((calendar-mark-ring
  8129. (list (calendar-gregorian-from-absolute
  8130. (or (get-text-property mark 'day)
  8131. (get-text-property point 'day))))))
  8132. (unwind-protect
  8133. (progn
  8134. (fset 'calendar-cursor-to-date
  8135. (lambda (&optional error dummy)
  8136. (calendar-gregorian-from-absolute
  8137. (get-text-property point 'day))))
  8138. (call-interactively cmd))
  8139. (fset 'calendar-cursor-to-date oldf))))))
  8140. (defun org-agenda-execute-calendar-command (cmd)
  8141. "Execute a calendar command from the agenda, with the date associated to
  8142. the cursor position."
  8143. (org-agenda-check-type t 'agenda 'timeline)
  8144. (require 'diary-lib)
  8145. (unless (get-text-property (point) 'day)
  8146. (error "Don't know which date to use for calendar command"))
  8147. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8148. (point (point))
  8149. (date (calendar-gregorian-from-absolute
  8150. (get-text-property point 'day)))
  8151. ;; the following 2 vars are needed in the calendar
  8152. (displayed-month (car date))
  8153. (displayed-year (nth 2 date)))
  8154. (unwind-protect
  8155. (progn
  8156. (fset 'calendar-cursor-to-date
  8157. (lambda (&optional error dummy)
  8158. (calendar-gregorian-from-absolute
  8159. (get-text-property point 'day))))
  8160. (call-interactively cmd))
  8161. (fset 'calendar-cursor-to-date oldf))))
  8162. (defun org-agenda-phases-of-moon ()
  8163. "Display the phases of the moon for the 3 months around the cursor date."
  8164. (interactive)
  8165. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8166. (defun org-agenda-holidays ()
  8167. "Display the holidays for the 3 months around the cursor date."
  8168. (interactive)
  8169. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8170. (defvar calendar-longitude) ; defined in calendar.el
  8171. (defvar calendar-latitude) ; defined in calendar.el
  8172. (defvar calendar-location-name) ; defined in calendar.el
  8173. (defun org-agenda-sunrise-sunset (arg)
  8174. "Display sunrise and sunset for the cursor date.
  8175. Latitude and longitude can be specified with the variables
  8176. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8177. argument, latitude and longitude will be prompted for."
  8178. (interactive "P")
  8179. (require 'solar)
  8180. (let ((calendar-longitude (if arg nil calendar-longitude))
  8181. (calendar-latitude (if arg nil calendar-latitude))
  8182. (calendar-location-name
  8183. (if arg "the given coordinates" calendar-location-name)))
  8184. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8185. (defun org-agenda-goto-calendar ()
  8186. "Open the Emacs calendar with the date at the cursor."
  8187. (interactive)
  8188. (org-agenda-check-type t 'agenda 'timeline)
  8189. (let* ((day (or (get-text-property (point) 'day)
  8190. (error "Don't know which date to open in calendar")))
  8191. (date (calendar-gregorian-from-absolute day))
  8192. (calendar-move-hook nil)
  8193. (calendar-view-holidays-initially-flag nil)
  8194. (calendar-view-diary-initially-flag nil))
  8195. (calendar)
  8196. (calendar-goto-date date)))
  8197. ;;;###autoload
  8198. (defun org-calendar-goto-agenda ()
  8199. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8200. This is a command that has to be installed in `calendar-mode-map'."
  8201. (interactive)
  8202. (org-agenda-list nil (calendar-absolute-from-gregorian
  8203. (calendar-cursor-to-date))
  8204. nil))
  8205. (defun org-agenda-convert-date ()
  8206. (interactive)
  8207. (org-agenda-check-type t 'agenda 'timeline)
  8208. (let ((day (get-text-property (point) 'day))
  8209. date s)
  8210. (unless day
  8211. (error "Don't know which date to convert"))
  8212. (setq date (calendar-gregorian-from-absolute day))
  8213. (setq s (concat
  8214. "Gregorian: " (calendar-date-string date) "\n"
  8215. "ISO: " (calendar-iso-date-string date) "\n"
  8216. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8217. "Julian: " (calendar-julian-date-string date) "\n"
  8218. "Astron. JD: " (calendar-astro-date-string date)
  8219. " (Julian date number at noon UTC)\n"
  8220. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8221. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8222. "French: " (calendar-french-date-string date) "\n"
  8223. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8224. "Mayan: " (calendar-mayan-date-string date) "\n"
  8225. "Coptic: " (calendar-coptic-date-string date) "\n"
  8226. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8227. "Persian: " (calendar-persian-date-string date) "\n"
  8228. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8229. (with-output-to-temp-buffer "*Dates*"
  8230. (princ s))
  8231. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8232. ;;; Bulk commands
  8233. (defun org-agenda-bulk-marked-p ()
  8234. (eq (get-char-property (point-at-bol) 'type)
  8235. 'org-marked-entry-overlay))
  8236. (defun org-agenda-bulk-mark (&optional arg)
  8237. "Mark the entry at point for future bulk action."
  8238. (interactive "p")
  8239. (dotimes (i (or arg 1))
  8240. (unless (org-get-at-bol 'org-agenda-diary-link)
  8241. (let* ((m (org-get-at-bol 'org-hd-marker))
  8242. ov)
  8243. (unless (org-agenda-bulk-marked-p)
  8244. (unless m (error "Nothing to mark at point"))
  8245. (push m org-agenda-bulk-marked-entries)
  8246. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8247. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8248. (org-get-todo-face "TODO")
  8249. 'evaporate)
  8250. (overlay-put ov 'type 'org-marked-entry-overlay))
  8251. (beginning-of-line 2)
  8252. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8253. (beginning-of-line 2))
  8254. (message "%d entries marked for bulk action"
  8255. (length org-agenda-bulk-marked-entries))))))
  8256. (defun org-agenda-bulk-mark-all ()
  8257. "Mark all entries for future agenda bulk action."
  8258. (interactive)
  8259. (org-agenda-bulk-mark-regexp "."))
  8260. (defun org-agenda-bulk-mark-regexp (regexp)
  8261. "Mark entries matching REGEXP for future agenda bulk action."
  8262. (interactive "sMark entries matching regexp: ")
  8263. (let ((entries-marked 0))
  8264. (save-excursion
  8265. (goto-char (point-min))
  8266. (goto-char (next-single-property-change (point) 'txt))
  8267. (while (re-search-forward regexp nil t)
  8268. (when (string-match regexp (get-text-property (point) 'txt))
  8269. (setq entries-marked (1+ entries-marked))
  8270. (call-interactively 'org-agenda-bulk-mark))))
  8271. (if (not entries-marked)
  8272. (message "No entry matching this regexp."))))
  8273. (defun org-agenda-bulk-unmark (&optional arg)
  8274. "Unmark the entry at point for future bulk action."
  8275. (interactive "P")
  8276. (if arg
  8277. (org-agenda-bulk-unmark-all)
  8278. (cond ((org-agenda-bulk-marked-p)
  8279. (org-agenda-bulk-remove-overlays
  8280. (point-at-bol) (+ 2 (point-at-bol)))
  8281. (setq org-agenda-bulk-marked-entries
  8282. (delete (org-get-at-bol 'org-hd-marker)
  8283. org-agenda-bulk-marked-entries))
  8284. (beginning-of-line 2)
  8285. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8286. (beginning-of-line 2))
  8287. (message "%d entries left marked for bulk action"
  8288. (length org-agenda-bulk-marked-entries)))
  8289. (t (message "No entry to unmark here")))))
  8290. (defun org-agenda-bulk-toggle ()
  8291. "Toggle marking the entry at point for bulk action."
  8292. (interactive)
  8293. (if (org-agenda-bulk-marked-p)
  8294. (org-agenda-bulk-unmark)
  8295. (org-agenda-bulk-mark)))
  8296. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8297. "Remove the mark overlays between BEG and END in the agenda buffer.
  8298. BEG and END default to the buffer limits.
  8299. This only removes the overlays, it does not remove the markers
  8300. from the list in `org-agenda-bulk-marked-entries'."
  8301. (interactive)
  8302. (mapc (lambda (ov)
  8303. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8304. (delete-overlay ov)))
  8305. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8306. (defun org-agenda-bulk-unmark-all ()
  8307. "Remove all marks in the agenda buffer.
  8308. This will remove the markers and the overlays."
  8309. (interactive)
  8310. (if (null org-agenda-bulk-marked-entries)
  8311. (message "No entry to unmark")
  8312. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8313. (setq org-agenda-bulk-marked-entries nil)
  8314. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8315. (defcustom org-agenda-persistent-marks nil
  8316. "Non-nil means marked items will stay marked after a bulk action.
  8317. You can toggle this interactively by typing `p' when prompted for a
  8318. bulk action."
  8319. :group 'org-agenda
  8320. :version "24.1"
  8321. :type 'boolean)
  8322. (defun org-agenda-bulk-action (&optional arg)
  8323. "Execute an remote-editing action on all marked entries.
  8324. The prefix arg is passed through to the command if possible."
  8325. (interactive "P")
  8326. ;; Make sure we have markers, and only valid ones
  8327. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8328. (mapc
  8329. (lambda (m)
  8330. (unless (and (markerp m)
  8331. (marker-buffer m)
  8332. (buffer-live-p (marker-buffer m))
  8333. (marker-position m))
  8334. (error "Marker %s for bulk command is invalid" m)))
  8335. org-agenda-bulk-marked-entries)
  8336. ;; Prompt for the bulk command
  8337. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8338. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8339. "[S]catter [f]unction "
  8340. (when org-agenda-bulk-custom-functions
  8341. (concat " Custom: ["
  8342. (mapconcat (lambda(f) (char-to-string (car f)))
  8343. org-agenda-bulk-custom-functions "")
  8344. "]"))))
  8345. (catch 'exit
  8346. (let* ((action (read-char-exclusive))
  8347. (org-log-refile (if org-log-refile 'time nil))
  8348. (entries (reverse org-agenda-bulk-marked-entries))
  8349. (org-overriding-default-time
  8350. (if (get-text-property (point) 'org-agenda-date-header)
  8351. (org-get-cursor-date)))
  8352. redo-at-end
  8353. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8354. (cond
  8355. ((equal action ?p)
  8356. (let ((org-agenda-persistent-marks
  8357. (not org-agenda-persistent-marks)))
  8358. (org-agenda-bulk-action)
  8359. (throw 'exit nil)))
  8360. ((equal action ?$)
  8361. (setq cmd '(org-agenda-archive)))
  8362. ((equal action ?A)
  8363. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8364. ((member action '(?r ?w))
  8365. (setq rfloc (org-refile-get-location
  8366. "Refile to"
  8367. (marker-buffer (car entries))
  8368. org-refile-allow-creating-parent-nodes))
  8369. (if (nth 3 rfloc)
  8370. (setcar (nthcdr 3 rfloc)
  8371. (move-marker (make-marker) (nth 3 rfloc)
  8372. (or (get-file-buffer (nth 1 rfloc))
  8373. (find-buffer-visiting (nth 1 rfloc))
  8374. (error "This should not happen")))))
  8375. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8376. redo-at-end t))
  8377. ((equal action ?t)
  8378. (setq state (org-icompleting-read
  8379. "Todo state: "
  8380. (with-current-buffer (marker-buffer (car entries))
  8381. (mapcar 'list org-todo-keywords-1))))
  8382. (setq cmd `(let ((org-inhibit-blocking t)
  8383. (org-inhibit-logging 'note))
  8384. (org-agenda-todo ,state))))
  8385. ((memq action '(?- ?+))
  8386. (setq tag (org-icompleting-read
  8387. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8388. (with-current-buffer (marker-buffer (car entries))
  8389. (delq nil
  8390. (mapcar (lambda (x)
  8391. (if (stringp (car x)) x)) org-tag-alist)))))
  8392. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8393. ((memq action '(?s ?d))
  8394. (let* ((date
  8395. (unless arg
  8396. (or org-overriding-default-time
  8397. (and (org-read-date
  8398. nil nil nil
  8399. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to"))
  8400. (or (ignore-errors
  8401. (org-time-string-to-time org-read-date-final-answer))
  8402. (current-time))))))
  8403. (date (format-time-string (car org-time-stamp-formats) date))
  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) ,date))
  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. (setq cnt (1+ cnt))))
  8471. (when redo-at-end (org-agenda-redo))
  8472. (unless org-agenda-persistent-marks
  8473. (org-agenda-bulk-unmark-all))
  8474. (message "Acted on %d entries%s%s"
  8475. cnt
  8476. (if (= cntskip 0)
  8477. ""
  8478. (format ", skipped %d (disappeared before their turn)"
  8479. cntskip))
  8480. (if (not org-agenda-persistent-marks)
  8481. "" " (kept marked)"))))))
  8482. (defun org-agenda-capture ()
  8483. "Call `org-capture' with the date at point."
  8484. (interactive)
  8485. (if (not (eq major-mode 'org-agenda-mode))
  8486. (error "You cannot do this outside of agenda buffers")
  8487. (let ((org-overriding-default-time
  8488. (org-get-cursor-date)))
  8489. (call-interactively 'org-capture))))
  8490. ;;; Flagging notes
  8491. (defun org-agenda-show-the-flagging-note ()
  8492. "Display the flagging note in the other window.
  8493. When called a second time in direct sequence, offer to remove the FLAGGING
  8494. tag and (if present) the flagging note."
  8495. (interactive)
  8496. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8497. (win (selected-window))
  8498. note heading newhead)
  8499. (unless hdmarker
  8500. (error "No linked entry at point"))
  8501. (if (and (eq this-command last-command)
  8502. (y-or-n-p "Unflag and remove any flagging note? "))
  8503. (progn
  8504. (org-agenda-remove-flag hdmarker)
  8505. (let ((win (get-buffer-window "*Flagging Note*")))
  8506. (and win (delete-window win)))
  8507. (message "Entry unflagged"))
  8508. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8509. (unless note
  8510. (error "No flagging note"))
  8511. (org-kill-new note)
  8512. (org-switch-to-buffer-other-window "*Flagging Note*")
  8513. (erase-buffer)
  8514. (insert note)
  8515. (goto-char (point-min))
  8516. (while (re-search-forward "\\\\n" nil t)
  8517. (replace-match "\n" t t))
  8518. (goto-char (point-min))
  8519. (select-window win)
  8520. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8521. (defun org-agenda-remove-flag (marker)
  8522. "Remove the FLAGGED tag and any flagging note in the entry."
  8523. (let (newhead)
  8524. (org-with-point-at marker
  8525. (org-toggle-tag "FLAGGED" 'off)
  8526. (org-entry-delete nil "THEFLAGGINGNOTE")
  8527. (setq newhead (org-get-heading)))
  8528. (org-agenda-change-all-lines newhead marker)
  8529. (message "Entry unflagged")))
  8530. (defun org-agenda-get-any-marker (&optional pos)
  8531. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8532. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8533. ;;; Appointment reminders
  8534. (defvar appt-time-msg-list) ; defined in appt.el
  8535. ;;;###autoload
  8536. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8537. "Activate appointments found in `org-agenda-files'.
  8538. With a \\[universal-argument] prefix, refresh the list of
  8539. appointments.
  8540. If FILTER is t, interactively prompt the user for a regular
  8541. expression, and filter out entries that don't match it.
  8542. If FILTER is a string, use this string as a regular expression
  8543. for filtering entries out.
  8544. If FILTER is a function, filter out entries against which
  8545. calling the function returns nil. This function takes one
  8546. argument: an entry from `org-agenda-get-day-entries'.
  8547. FILTER can also be an alist with the car of each cell being
  8548. either 'headline or 'category. For example:
  8549. '((headline \"IMPORTANT\")
  8550. (category \"Work\"))
  8551. will only add headlines containing IMPORTANT or headlines
  8552. belonging to the \"Work\" category.
  8553. ARGS are symbols indicating what kind of entries to consider.
  8554. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8555. and :timestamp entries. See the docstring of `org-diary' for
  8556. details and examples.
  8557. If an entry as a APPT_WARNTIME property, its value will be used
  8558. to override `appt-message-warning-time'."
  8559. (interactive "P")
  8560. (if refresh (setq appt-time-msg-list nil))
  8561. (if (eq filter t)
  8562. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8563. (let* ((cnt 0) ; count added events
  8564. (scope (or args '(:deadline :scheduled :timestamp)))
  8565. (org-agenda-new-buffers nil)
  8566. (org-deadline-warning-days 0)
  8567. ;; Do not use `org-today' here because appt only takes
  8568. ;; time and without date as argument, so it may pass wrong
  8569. ;; information otherwise
  8570. (today (org-date-to-gregorian
  8571. (time-to-days (current-time))))
  8572. (org-agenda-restrict nil)
  8573. (files (org-agenda-files 'unrestricted)) entries file
  8574. (org-agenda-buffer nil))
  8575. ;; Get all entries which may contain an appt
  8576. (org-agenda-prepare-buffers files)
  8577. (while (setq file (pop files))
  8578. (setq entries
  8579. (delq nil
  8580. (append entries
  8581. (apply 'org-agenda-get-day-entries
  8582. file today scope)))))
  8583. ;; Map thru entries and find if we should filter them out
  8584. (mapc
  8585. (lambda(x)
  8586. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8587. (cat (get-text-property 1 'org-category x))
  8588. (tod (get-text-property 1 'time-of-day x))
  8589. (ok (or (null filter)
  8590. (and (stringp filter) (string-match filter evt))
  8591. (and (functionp filter) (funcall filter x))
  8592. (and (listp filter)
  8593. (let ((cat-filter (cadr (assoc 'category filter)))
  8594. (evt-filter (cadr (assoc 'headline filter))))
  8595. (or (and (stringp cat-filter)
  8596. (string-match cat-filter cat))
  8597. (and (stringp evt-filter)
  8598. (string-match evt-filter evt)))))))
  8599. (wrn (get-text-property 1 'warntime x)))
  8600. ;; FIXME: Shall we remove text-properties for the appt text?
  8601. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8602. (when (and ok tod)
  8603. (setq tod (concat "00" (number-to-string tod))
  8604. tod (when (string-match
  8605. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8606. (concat (match-string 1 tod) ":"
  8607. (match-string 2 tod))))
  8608. (if (version< emacs-version "23.3")
  8609. (appt-add tod evt)
  8610. (appt-add tod evt wrn))
  8611. (setq cnt (1+ cnt))))) entries)
  8612. (org-release-buffers org-agenda-new-buffers)
  8613. (if (eq cnt 0)
  8614. (message "No event to add")
  8615. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8616. (defun org-agenda-todayp (date)
  8617. "Does DATE mean today, when considering `org-extend-today-until'?"
  8618. (let ((today (org-today))
  8619. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8620. date)))
  8621. (eq date today)))
  8622. (defun org-agenda-todo-yesterday (&optional arg)
  8623. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8624. (interactive "P")
  8625. (let* ((hour (third (decode-time
  8626. (org-current-time))))
  8627. (org-extend-today-until (1+ hour)))
  8628. (org-agenda-todo arg)))
  8629. (provide 'org-agenda)
  8630. ;;; org-agenda.el ends here