org-agenda.el 322 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.7
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (declare-function org-pop-to-buffer-same-window "org-compat"
  57. (&optional buffer-or-name norecord label))
  58. (defvar calendar-mode-map)
  59. (defvar org-clock-current-task) ; defined in org-clock.el
  60. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  61. (defvar org-habit-show-habits)
  62. (defvar org-habit-show-habits-only-for-today)
  63. ;; Defined somewhere in this file, but used before definition.
  64. (defvar org-agenda-buffer-name)
  65. (defvar org-agenda-overriding-header)
  66. (defvar org-agenda-title-append nil)
  67. (defvar entry)
  68. (defvar date)
  69. (defvar org-agenda-undo-list)
  70. (defvar org-agenda-pending-undo-list)
  71. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  72. (defcustom org-agenda-confirm-kill 1
  73. "When set, remote killing from the agenda buffer needs confirmation.
  74. When t, a confirmation is always needed. When a number N, confirmation is
  75. only needed when the text to be killed contains more than N non-white lines."
  76. :group 'org-agenda
  77. :type '(choice
  78. (const :tag "Never" nil)
  79. (const :tag "Always" t)
  80. (integer :tag "When more than N lines")))
  81. (defcustom org-agenda-compact-blocks nil
  82. "Non-nil means make the block agenda more compact.
  83. This is done globally by leaving out lines like the agenda span
  84. name and week number or the separator lines."
  85. :group 'org-agenda
  86. :type 'boolean)
  87. (defcustom org-agenda-block-separator ?=
  88. "The separator between blocks in the agenda.
  89. If this is a string, it will be used as the separator, with a newline added.
  90. If it is a character, it will be repeated to fill the window width.
  91. If nil the separator is disabled. In `org-agenda-custom-commands' this
  92. addresses the separator between the current and the previous block."
  93. :group 'org-agenda
  94. :type '(choice
  95. (const :tag "Disabled" nil)
  96. (character)
  97. (string)))
  98. (defgroup org-agenda-export nil
  99. "Options concerning exporting agenda views in Org-mode."
  100. :tag "Org Agenda Export"
  101. :group 'org-agenda)
  102. (defcustom org-agenda-with-colors t
  103. "Non-nil means use colors in agenda views."
  104. :group 'org-agenda-export
  105. :type 'boolean)
  106. (defcustom org-agenda-exporter-settings nil
  107. "Alist of variable/value pairs that should be active during agenda export.
  108. This is a good place to set options for ps-print and for htmlize.
  109. Note that the way this is implemented, the values will be evaluated
  110. before assigned to the variables. So make sure to quote values you do
  111. *not* want evaluated, for example
  112. (setq org-agenda-exporter-settings
  113. '((ps-print-color-p 'black-white)))"
  114. :group 'org-agenda-export
  115. :type '(repeat
  116. (list
  117. (variable)
  118. (sexp :tag "Value"))))
  119. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  120. "Hook run in temporary buffer before writing it to an export file.
  121. A useful function is `org-agenda-add-entry-text'."
  122. :group 'org-agenda-export
  123. :type 'hook
  124. :options '(org-agenda-add-entry-text))
  125. (defcustom org-agenda-add-entry-text-maxlines 0
  126. "Maximum number of entry text lines to be added to agenda.
  127. This is only relevant when `org-agenda-add-entry-text' is part of
  128. `org-agenda-before-write-hook', which it is by default.
  129. When this is 0, nothing will happen. When it is greater than 0, it
  130. specifies the maximum number of lines that will be added for each entry
  131. that is listed in the agenda view.
  132. Note that this variable is not used during display, only when exporting
  133. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  134. and `org-agenda-entry-text-maxlines'."
  135. :group 'org-agenda
  136. :type 'integer)
  137. (defcustom org-agenda-add-entry-text-descriptive-links t
  138. "Non-nil means export org-links as descriptive links in agenda added text.
  139. This variable applies to the text added to the agenda when
  140. `org-agenda-add-entry-text-maxlines' is larger than 0.
  141. When this variable nil, the URL will (also) be shown."
  142. :group 'org-agenda
  143. :type 'boolean)
  144. (defcustom org-agenda-export-html-style ""
  145. "The style specification for exported HTML Agenda files.
  146. If this variable contains a string, it will replace the default <style>
  147. section as produced by `htmlize'.
  148. Since there are different ways of setting style information, this variable
  149. needs to contain the full HTML structure to provide a style, including the
  150. surrounding HTML tags. The style specifications should include definitions
  151. the fonts used by the agenda, here is an example:
  152. <style type=\"text/css\">
  153. p { font-weight: normal; color: gray; }
  154. .org-agenda-structure {
  155. font-size: 110%;
  156. color: #003399;
  157. font-weight: 600;
  158. }
  159. .org-todo {
  160. color: #cc6666;
  161. font-weight: bold;
  162. }
  163. .org-agenda-done {
  164. color: #339933;
  165. }
  166. .org-done {
  167. color: #339933;
  168. }
  169. .title { text-align: center; }
  170. .todo, .deadline { color: red; }
  171. .done { color: green; }
  172. </style>
  173. or, if you want to keep the style in a file,
  174. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  175. As the value of this option simply gets inserted into the HTML <head> header,
  176. you can \"misuse\" it to also add other text to the header. However,
  177. <style>...</style> is required, if not present the variable will be ignored."
  178. :group 'org-agenda-export
  179. :group 'org-export-html
  180. :type 'string)
  181. (defcustom org-agenda-persistent-filter nil
  182. "When set, keep filters from one agenda view to the next."
  183. :group 'org-agenda
  184. :type 'boolean)
  185. (defgroup org-agenda-custom-commands nil
  186. "Options concerning agenda views in Org-mode."
  187. :tag "Org Agenda Custom Commands"
  188. :group 'org-agenda)
  189. (defconst org-sorting-choice
  190. '(choice
  191. (const time-up) (const time-down)
  192. (const category-keep) (const category-up) (const category-down)
  193. (const tag-down) (const tag-up)
  194. (const priority-up) (const priority-down)
  195. (const todo-state-up) (const todo-state-down)
  196. (const effort-up) (const effort-down)
  197. (const habit-up) (const habit-down)
  198. (const alpha-up) (const alpha-down)
  199. (const user-defined-up) (const user-defined-down))
  200. "Sorting choices.")
  201. (defconst org-agenda-custom-commands-local-options
  202. `(repeat :tag "Local settings for this command. Remember to quote values"
  203. (choice :tag "Setting"
  204. (list :tag "Heading for this block"
  205. (const org-agenda-overriding-header)
  206. (string :tag "Headline"))
  207. (list :tag "Files to be searched"
  208. (const org-agenda-files)
  209. (list
  210. (const :format "" quote)
  211. (repeat (file))))
  212. (list :tag "Sorting strategy"
  213. (const org-agenda-sorting-strategy)
  214. (list
  215. (const :format "" quote)
  216. (repeat
  217. ,org-sorting-choice)))
  218. (list :tag "Prefix format"
  219. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  220. (string))
  221. (list :tag "Number of days in agenda"
  222. (const org-agenda-span)
  223. (choice (const :tag "Day" 'day)
  224. (const :tag "Week" 'week)
  225. (const :tag "Month" 'month)
  226. (const :tag "Year" 'year)
  227. (integer :tag "Custom")))
  228. (list :tag "Fixed starting date"
  229. (const org-agenda-start-day)
  230. (string :value "2007-11-01"))
  231. (list :tag "Start on day of week"
  232. (const org-agenda-start-on-weekday)
  233. (choice :value 1
  234. (const :tag "Today" nil)
  235. (integer :tag "Weekday No.")))
  236. (list :tag "Include data from diary"
  237. (const org-agenda-include-diary)
  238. (boolean))
  239. (list :tag "Deadline Warning days"
  240. (const org-deadline-warning-days)
  241. (integer :value 1))
  242. (list :tag "Tags filter preset"
  243. (const org-agenda-filter-preset)
  244. (list
  245. (const :format "" quote)
  246. (repeat
  247. (string :tag "+tag or -tag"))))
  248. (list :tag "Set daily/weekly entry types"
  249. (const org-agenda-entry-types)
  250. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  251. (const :deadline)
  252. (const :scheduled)
  253. (const :timestamp)
  254. (const :sexp)))
  255. (list :tag "Standard skipping condition"
  256. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  257. (const org-agenda-skip-function)
  258. (list
  259. (const :format "" quote)
  260. (list
  261. (choice
  262. :tag "Skipping range"
  263. (const :tag "Skip entry" org-agenda-skip-entry-if)
  264. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  265. (repeat :inline t :tag "Conditions for skipping"
  266. (choice
  267. :tag "Condition type"
  268. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  269. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  270. (list :tag "TODO state is" :inline t
  271. (const 'todo)
  272. (choice
  273. (const :tag "any not-done state" 'todo)
  274. (const :tag "any done state" 'done)
  275. (const :tag "any state" 'any)
  276. (list :tag "Keyword list"
  277. (const :format "" quote)
  278. (repeat (string :tag "Keyword")))))
  279. (list :tag "TODO state is not" :inline t
  280. (const 'nottodo)
  281. (choice
  282. (const :tag "any not-done state" 'todo)
  283. (const :tag "any done state" 'done)
  284. (const :tag "any state" 'any)
  285. (list :tag "Keyword list"
  286. (const :format "" quote)
  287. (repeat (string :tag "Keyword")))))
  288. (const :tag "scheduled" 'scheduled)
  289. (const :tag "not scheduled" 'notscheduled)
  290. (const :tag "deadline" 'deadline)
  291. (const :tag "no deadline" 'notdeadline)
  292. (const :tag "timestamp" 'timestamp)
  293. (const :tag "no timestamp" 'nottimestamp))))))
  294. (list :tag "Non-standard skipping condition"
  295. :value (org-agenda-skip-function)
  296. (const org-agenda-skip-function)
  297. (sexp :tag "Function or form (quoted!)"))
  298. (list :tag "Any variable"
  299. (variable :tag "Variable")
  300. (sexp :tag "Value (sexp)"))))
  301. "Selection of examples for agenda command settings.
  302. This will be spliced into the custom type of
  303. `org-agenda-custom-commands'.")
  304. (defcustom org-agenda-custom-commands nil
  305. "Custom commands for the agenda.
  306. These commands will be offered on the splash screen displayed by the
  307. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  308. (key desc type match settings files)
  309. key The key (one or more characters as a string) to be associated
  310. with the command.
  311. desc A description of the command, when omitted or nil, a default
  312. description is built using MATCH.
  313. type The command type, any of the following symbols:
  314. agenda The daily/weekly agenda.
  315. todo Entries with a specific TODO keyword, in all agenda files.
  316. search Entries containing search words entry or headline.
  317. tags Tags/Property/TODO match in all agenda files.
  318. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  319. todo-tree Sparse tree of specific TODO keyword in *current* file.
  320. tags-tree Sparse tree with all tags matches in *current* file.
  321. occur-tree Occur sparse tree for *current* file.
  322. ... A user-defined function.
  323. match What to search for:
  324. - a single keyword for TODO keyword searches
  325. - a tags match expression for tags searches
  326. - a word search expression for text searches.
  327. - a regular expression for occur searches
  328. For all other commands, this should be the empty string.
  329. settings A list of option settings, similar to that in a let form, so like
  330. this: ((opt1 val1) (opt2 val2) ...). The values will be
  331. evaluated at the moment of execution, so quote them when needed.
  332. files A list of files file to write the produced agenda buffer to
  333. with the command `org-store-agenda-views'.
  334. If a file name ends in \".html\", an HTML version of the buffer
  335. is written out. If it ends in \".ps\", a postscript version is
  336. produced. Otherwise, only the plain text is written to the file.
  337. You can also define a set of commands, to create a composite agenda buffer.
  338. In this case, an entry looks like this:
  339. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  340. where
  341. desc A description string to be displayed in the dispatcher menu.
  342. cmd An agenda command, similar to the above. However, tree commands
  343. are no allowed, but instead you can get agenda and global todo list.
  344. So valid commands for a set are:
  345. (agenda \"\" settings)
  346. (alltodo \"\" settings)
  347. (stuck \"\" settings)
  348. (todo \"match\" settings files)
  349. (search \"match\" settings files)
  350. (tags \"match\" settings files)
  351. (tags-todo \"match\" settings files)
  352. Each command can carry a list of options, and another set of options can be
  353. given for the whole set of commands. Individual command options take
  354. precedence over the general options.
  355. When using several characters as key to a command, the first characters
  356. are prefix commands. For the dispatcher to display useful information, you
  357. should provide a description for the prefix, like
  358. (setq org-agenda-custom-commands
  359. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  360. (\"hl\" tags \"+HOME+Lisa\")
  361. (\"hp\" tags \"+HOME+Peter\")
  362. (\"hk\" tags \"+HOME+Kim\")))"
  363. :group 'org-agenda-custom-commands
  364. :type `(repeat
  365. (choice :value ("x" "Describe command here" tags "" nil)
  366. (list :tag "Single command"
  367. (string :tag "Access Key(s) ")
  368. (option (string :tag "Description"))
  369. (choice
  370. (const :tag "Agenda" agenda)
  371. (const :tag "TODO list" alltodo)
  372. (const :tag "Search words" search)
  373. (const :tag "Stuck projects" stuck)
  374. (const :tag "Tags/Property match (all agenda files)" tags)
  375. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  376. (const :tag "TODO keyword search (all agenda files)" todo)
  377. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  378. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  379. (const :tag "Occur tree (current buffer)" occur-tree)
  380. (sexp :tag "Other, user-defined function"))
  381. (string :tag "Match (only for some commands)")
  382. ,org-agenda-custom-commands-local-options
  383. (option (repeat :tag "Export" (file :tag "Export to"))))
  384. (list :tag "Command series, all agenda files"
  385. (string :tag "Access Key(s)")
  386. (string :tag "Description ")
  387. (repeat :tag "Component"
  388. (choice
  389. (list :tag "Agenda"
  390. (const :format "" agenda)
  391. (const :tag "" :format "" "")
  392. ,org-agenda-custom-commands-local-options)
  393. (list :tag "TODO list (all keywords)"
  394. (const :format "" alltodo)
  395. (const :tag "" :format "" "")
  396. ,org-agenda-custom-commands-local-options)
  397. (list :tag "Search words"
  398. (const :format "" search)
  399. (string :tag "Match")
  400. ,org-agenda-custom-commands-local-options)
  401. (list :tag "Stuck projects"
  402. (const :format "" stuck)
  403. (const :tag "" :format "" "")
  404. ,org-agenda-custom-commands-local-options)
  405. (list :tag "Tags search"
  406. (const :format "" tags)
  407. (string :tag "Match")
  408. ,org-agenda-custom-commands-local-options)
  409. (list :tag "Tags search, TODO entries only"
  410. (const :format "" tags-todo)
  411. (string :tag "Match")
  412. ,org-agenda-custom-commands-local-options)
  413. (list :tag "TODO keyword search"
  414. (const :format "" todo)
  415. (string :tag "Match")
  416. ,org-agenda-custom-commands-local-options)
  417. (list :tag "Other, user-defined function"
  418. (symbol :tag "function")
  419. (string :tag "Match")
  420. ,org-agenda-custom-commands-local-options)))
  421. (repeat :tag "Settings for entire command set"
  422. (list (variable :tag "Any variable")
  423. (sexp :tag "Value")))
  424. (option (repeat :tag "Export" (file :tag "Export to"))))
  425. (cons :tag "Prefix key documentation"
  426. (string :tag "Access Key(s)")
  427. (string :tag "Description ")))))
  428. (defcustom org-agenda-query-register ?o
  429. "The register holding the current query string.
  430. The purpose of this is that if you construct a query string interactively,
  431. you can then use it to define a custom command."
  432. :group 'org-agenda-custom-commands
  433. :type 'character)
  434. (defcustom org-stuck-projects
  435. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  436. "How to identify stuck projects.
  437. This is a list of four items:
  438. 1. A tags/todo/property matcher string that is used to identify a project.
  439. See the manual for a description of tag and property searches.
  440. The entire tree below a headline matched by this is considered one project.
  441. 2. A list of TODO keywords identifying non-stuck projects.
  442. If the project subtree contains any headline with one of these todo
  443. keywords, the project is considered to be not stuck. If you specify
  444. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  445. 3. A list of tags identifying non-stuck projects.
  446. If the project subtree contains any headline with one of these tags,
  447. the project is considered to be not stuck. If you specify \"*\" as
  448. a tag, any tag will mark the project unstuck. Note that this is about
  449. the explicit presence of a tag somewhere in the subtree, inherited
  450. tags to not count here. If inherited tags make a project not stuck,
  451. use \"-TAG\" in the tags part of the matcher under (1.) above.
  452. 4. An arbitrary regular expression matching non-stuck projects.
  453. If the project turns out to be not stuck, search continues also in the
  454. subtree to see if any of the subtasks have project status.
  455. See also the variable `org-tags-match-list-sublevels' which applies
  456. to projects matched by this search as well.
  457. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  458. or `C-c a #' to produce the list."
  459. :group 'org-agenda-custom-commands
  460. :type '(list
  461. (string :tag "Tags/TODO match to identify a project")
  462. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  463. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  464. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  465. (defcustom org-agenda-filter-effort-default-operator "<"
  466. "The default operator for effort estimate filtering.
  467. If you select an effort estimate limit without first pressing an operator,
  468. this one will be used."
  469. :group 'org-agenda-custom-commands
  470. :type '(choice (const :tag "less or equal" "<")
  471. (const :tag "greater or equal"">")
  472. (const :tag "equal" "=")))
  473. (defgroup org-agenda-skip nil
  474. "Options concerning skipping parts of agenda files."
  475. :tag "Org Agenda Skip"
  476. :group 'org-agenda)
  477. (defcustom org-agenda-skip-function-global nil
  478. "Function to be called at each match during agenda construction.
  479. If this function returns nil, the current match should not be skipped.
  480. If the function decided to skip an agenda match, is must return the
  481. buffer position from which the search should be continued.
  482. This may also be a Lisp form, which will be evaluated.
  483. This variable will be applied to every agenda match, including
  484. tags/property searches and TODO lists. So try to make the test function
  485. do its checking as efficiently as possible. To implement a skipping
  486. condition just for specific agenda commands, use the variable
  487. `org-agenda-skip-function' which can be set in the options section
  488. of custom agenda commands."
  489. :group 'org-agenda-skip
  490. :type 'sexp)
  491. (defgroup org-agenda-daily/weekly nil
  492. "Options concerning the daily/weekly agenda."
  493. :tag "Org Agenda Daily/Weekly"
  494. :group 'org-agenda)
  495. (defgroup org-agenda-todo-list nil
  496. "Options concerning the global todo list agenda view."
  497. :tag "Org Agenda Todo List"
  498. :group 'org-agenda)
  499. (defgroup org-agenda-match-view nil
  500. "Options concerning the general tags/property/todo match agenda view."
  501. :tag "Org Agenda Match View"
  502. :group 'org-agenda)
  503. (defgroup org-agenda-search-view nil
  504. "Options concerning the general tags/property/todo match agenda view."
  505. :tag "Org Agenda Match View"
  506. :group 'org-agenda)
  507. (defvar org-agenda-archives-mode nil
  508. "Non-nil means the agenda will include archived items.
  509. If this is the symbol `trees', trees in the selected agenda scope
  510. that are marked with the ARCHIVE tag will be included anyway. When this is
  511. t, also all archive files associated with the current selection of agenda
  512. files will be included.")
  513. (defcustom org-agenda-skip-comment-trees t
  514. "Non-nil means skip trees that start with the COMMENT keyword.
  515. When nil, these trees are also scanned by agenda commands."
  516. :group 'org-agenda-skip
  517. :type 'boolean)
  518. (defcustom org-agenda-todo-list-sublevels t
  519. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  520. When nil, the sublevels of a TODO entry are not checked, resulting in
  521. potentially much shorter TODO lists."
  522. :group 'org-agenda-skip
  523. :group 'org-agenda-todo-list
  524. :type 'boolean)
  525. (defcustom org-agenda-todo-ignore-with-date nil
  526. "Non-nil means don't show entries with a date in the global todo list.
  527. You can use this if you prefer to mark mere appointments with a TODO keyword,
  528. but don't want them to show up in the TODO list.
  529. When this is set, it also covers deadlines and scheduled items, the settings
  530. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  531. will be ignored.
  532. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  533. :group 'org-agenda-skip
  534. :group 'org-agenda-todo-list
  535. :type 'boolean)
  536. (defcustom org-agenda-todo-ignore-timestamp nil
  537. "Non-nil means don't show entries with a timestamp.
  538. This applies when creating the global todo list.
  539. Valid values are:
  540. past Don't show entries for today or in the past.
  541. future Don't show entries with a timestamp in the future.
  542. The idea behind this is that if it has a future
  543. timestamp, you don't want to think about it until the
  544. date.
  545. all Don't show any entries with a timestamp in the global todo list.
  546. The idea behind this is that by setting a timestamp, you
  547. have already \"taken care\" of this item.
  548. This variable can also have an integer as a value. If positive (N),
  549. todos with a timestamp N or more days in the future will be ignored. If
  550. negative (-N), todos with a timestamp N or more days in the past will be
  551. ignored. If 0, todos with a timestamp either today or in the future will
  552. be ignored. For example, a value of -1 will exclude todos with a
  553. timestamp in the past (yesterday or earlier), while a value of 7 will
  554. exclude todos with a timestamp a week or more in the future.
  555. See also `org-agenda-todo-ignore-with-date'.
  556. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  557. to make his option also apply to the tags-todo list."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type '(choice
  561. (const :tag "Ignore future timestamp todos" future)
  562. (const :tag "Ignore past or present timestamp todos" past)
  563. (const :tag "Ignore all timestamp todos" all)
  564. (const :tag "Show timestamp todos" nil)
  565. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  566. (defcustom org-agenda-todo-ignore-scheduled nil
  567. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  568. This applies when creating the global todo list.
  569. Valid values are:
  570. past Don't show entries scheduled today or in the past.
  571. future Don't show entries scheduled in the future.
  572. The idea behind this is that by scheduling it, you don't want to
  573. think about it until the scheduled date.
  574. all Don't show any scheduled entries in the global todo list.
  575. The idea behind this is that by scheduling it, you have already
  576. \"taken care\" of this item.
  577. t Same as `all', for backward compatibility.
  578. This variable can also have an integer as a value. See
  579. `org-agenda-todo-ignore-timestamp' for more details.
  580. See also `org-agenda-todo-ignore-with-date'.
  581. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  582. to make his option also apply to the tags-todo list."
  583. :group 'org-agenda-skip
  584. :group 'org-agenda-todo-list
  585. :type '(choice
  586. (const :tag "Ignore future-scheduled todos" future)
  587. (const :tag "Ignore past- or present-scheduled todos" past)
  588. (const :tag "Ignore all scheduled todos" all)
  589. (const :tag "Ignore all scheduled todos (compatibility)" t)
  590. (const :tag "Show scheduled todos" nil)
  591. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  592. (defcustom org-agenda-todo-ignore-deadlines nil
  593. "Non-nil means ignore some deadlined TODO items when making TODO list.
  594. There are different motivations for using different values, please think
  595. carefully when configuring this variable.
  596. This applies when creating the global todo list.
  597. Valid values are:
  598. near Don't show near deadline entries. A deadline is near when it is
  599. closer than `org-deadline-warning-days' days. The idea behind this
  600. is that such items will appear in the agenda anyway.
  601. far Don't show TODO entries where a deadline has been defined, but
  602. the deadline is not near. This is useful if you don't want to
  603. use the todo list to figure out what to do now.
  604. past Don't show entries with a deadline timestamp for today or in the past.
  605. future Don't show entries with a deadline timestamp in the future, not even
  606. when they become `near' ones. Use it with caution.
  607. all Ignore all TODO entries that do have a deadline.
  608. t Same as `near', for backward compatibility.
  609. This variable can also have an integer as a value. See
  610. `org-agenda-todo-ignore-timestamp' for more details.
  611. See also `org-agenda-todo-ignore-with-date'.
  612. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  613. to make his option also apply to the tags-todo list."
  614. :group 'org-agenda-skip
  615. :group 'org-agenda-todo-list
  616. :type '(choice
  617. (const :tag "Ignore near deadlines" near)
  618. (const :tag "Ignore near deadlines (compatibility)" t)
  619. (const :tag "Ignore far deadlines" far)
  620. (const :tag "Ignore all TODOs with a deadlines" all)
  621. (const :tag "Show all TODOs, even if they have a deadline" nil)
  622. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  623. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  624. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  625. The variables
  626. `org-agenda-todo-ignore-with-date',
  627. `org-agenda-todo-ignore-timestamp',
  628. `org-agenda-todo-ignore-scheduled',
  629. `org-agenda-todo-ignore-deadlines'
  630. make the global TODO list skip entries that have time stamps of certain
  631. kinds. If this option is set, the same options will also apply for the
  632. tags-todo search, which is the general tags/property matcher
  633. restricted to unfinished TODO entries only."
  634. :group 'org-agenda-skip
  635. :group 'org-agenda-todo-list
  636. :group 'org-agenda-match-view
  637. :type 'boolean)
  638. (defcustom org-agenda-skip-scheduled-if-done nil
  639. "Non-nil means don't show scheduled items in agenda when they are done.
  640. This is relevant for the daily/weekly agenda, not for the TODO list. And
  641. it applies only to the actual date of the scheduling. Warnings about
  642. an item with a past scheduling dates are always turned off when the item
  643. is DONE."
  644. :group 'org-agenda-skip
  645. :group 'org-agenda-daily/weekly
  646. :type 'boolean)
  647. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  648. "Non-nil means skip scheduling line if same entry shows because of deadline.
  649. In the agenda of today, an entry can show up multiple times because
  650. it is both scheduled and has a nearby deadline, and maybe a plain time
  651. stamp as well.
  652. When this variable is t, then only the deadline is shown and the fact that
  653. the entry is scheduled today or was scheduled previously is not shown.
  654. When this variable is nil, the entry will be shown several times. When
  655. the variable is the symbol `not-today', then skip scheduled previously,
  656. but not scheduled today."
  657. :group 'org-agenda-skip
  658. :group 'org-agenda-daily/weekly
  659. :type '(choice
  660. (const :tag "Never" nil)
  661. (const :tag "Always" t)
  662. (const :tag "Not when scheduled today" not-today)))
  663. (defcustom org-agenda-skip-deadline-if-done nil
  664. "Non-nil means don't show deadlines when the corresponding item is done.
  665. When nil, the deadline is still shown and should give you a happy feeling.
  666. This is relevant for the daily/weekly agenda. And it applied only to the
  667. actually date of the deadline. Warnings about approaching and past-due
  668. deadlines are always turned off when the item is DONE."
  669. :group 'org-agenda-skip
  670. :group 'org-agenda-daily/weekly
  671. :type 'boolean)
  672. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  673. "Non-nil means skip deadline prewarning when entry is also scheduled.
  674. This will apply on all days where a prewarning for the deadline would
  675. be shown, but not at the day when the entry is actually due. On that day,
  676. the deadline will be shown anyway.
  677. This variable may be set to nil, t, or a number which will then give
  678. the number of days before the actual deadline when the prewarnings
  679. should resume.
  680. This can be used in a workflow where the first showing of the deadline will
  681. trigger you to schedule it, and then you don't want to be reminded of it
  682. because you will take care of it on the day when scheduled."
  683. :group 'org-agenda-skip
  684. :group 'org-agenda-daily/weekly
  685. :type '(choice
  686. (const :tag "Alwas show prewarning" nil)
  687. (const :tag "Remove prewarning if entry is scheduled" t)
  688. (integer :tag "Restart prewarning N days before deadline")))
  689. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  690. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  691. When non-nil, after the search for timestamps has matched once in an
  692. entry, the rest of the entry will not be searched."
  693. :group 'org-agenda-skip
  694. :type 'boolean)
  695. (defcustom org-agenda-skip-timestamp-if-done nil
  696. "Non-nil means don't select item by timestamp or -range if it is DONE."
  697. :group 'org-agenda-skip
  698. :group 'org-agenda-daily/weekly
  699. :type 'boolean)
  700. (defcustom org-agenda-dim-blocked-tasks t
  701. "Non-nil means dim blocked tasks in the agenda display.
  702. This causes some overhead during agenda construction, but if you
  703. have turned on `org-enforce-todo-dependencies',
  704. `org-enforce-todo-checkbox-dependencies', or any other blocking
  705. mechanism, this will create useful feedback in the agenda.
  706. Instead of t, this variable can also have the value `invisible'.
  707. Then blocked tasks will be invisible and only become visible when
  708. they become unblocked. An exemption to this behavior is when a task is
  709. blocked because of unchecked checkboxes below it. Since checkboxes do
  710. not show up in the agenda views, making this task invisible you remove any
  711. trace from agenda views that there is something to do. Therefore, a task
  712. that is blocked because of checkboxes will never be made invisible, it
  713. will only be dimmed."
  714. :group 'org-agenda-daily/weekly
  715. :group 'org-agenda-todo-list
  716. :type '(choice
  717. (const :tag "Do not dim" nil)
  718. (const :tag "Dim to a grey face" t)
  719. (const :tag "Make invisible" invisible)))
  720. (defcustom org-timeline-show-empty-dates 3
  721. "Non-nil means `org-timeline' also shows dates without an entry.
  722. When nil, only the days which actually have entries are shown.
  723. When t, all days between the first and the last date are shown.
  724. When an integer, show also empty dates, but if there is a gap of more than
  725. N days, just insert a special line indicating the size of the gap."
  726. :group 'org-agenda-skip
  727. :type '(choice
  728. (const :tag "None" nil)
  729. (const :tag "All" t)
  730. (integer :tag "at most")))
  731. (defgroup org-agenda-startup nil
  732. "Options concerning initial settings in the Agenda in Org Mode."
  733. :tag "Org Agenda Startup"
  734. :group 'org-agenda)
  735. (defcustom org-agenda-menu-show-matcher t
  736. "Non-nil means show the match string in the agenda dispatcher menu.
  737. When nil, the matcher string is not shown, but is put into the help-echo
  738. property so than moving the mouse over the command shows it.
  739. Setting it to nil is good if matcher strings are very long and/or if
  740. you want to use two-column display (see `org-agenda-menu-two-column')."
  741. :group 'org-agenda
  742. :type 'boolean)
  743. (defcustom org-agenda-menu-two-column nil
  744. "Non-nil means, use two columns to show custom commands in the dispatcher.
  745. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  746. to nil."
  747. :group 'org-agenda
  748. :type 'boolean)
  749. (defcustom org-finalize-agenda-hook nil
  750. "Hook run just before displaying an agenda buffer."
  751. :group 'org-agenda-startup
  752. :type 'hook)
  753. (defcustom org-agenda-mouse-1-follows-link nil
  754. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  755. A longer mouse click will still set point. Does not work on XEmacs.
  756. Needs to be set before org.el is loaded."
  757. :group 'org-agenda-startup
  758. :type 'boolean)
  759. (defcustom org-agenda-start-with-follow-mode nil
  760. "The initial value of follow mode in a newly created agenda window."
  761. :group 'org-agenda-startup
  762. :type 'boolean)
  763. (defcustom org-agenda-show-outline-path t
  764. "Non-nil means show outline path in echo area after line motion."
  765. :group 'org-agenda-startup
  766. :type 'boolean)
  767. (defcustom org-agenda-start-with-entry-text-mode nil
  768. "The initial value of entry-text-mode in a newly created agenda window."
  769. :group 'org-agenda-startup
  770. :type 'boolean)
  771. (defcustom org-agenda-entry-text-maxlines 5
  772. "Number of text lines to be added when `E' is pressed in the agenda.
  773. Note that this variable only used during agenda display. Add add entry text
  774. when exporting the agenda, configure the variable
  775. `org-agenda-add-entry-ext-maxlines'."
  776. :group 'org-agenda
  777. :type 'integer)
  778. (defcustom org-agenda-entry-text-exclude-regexps nil
  779. "List of regular expressions to clean up entry text.
  780. The complete matches of all regular expressions in this list will be
  781. removed from entry text before it is shown in the agenda."
  782. :group 'org-agenda
  783. :type '(repeat (regexp)))
  784. (defvar org-agenda-entry-text-cleanup-hook nil
  785. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  786. This cleanup is done in a temporary buffer, so the function may inspect and
  787. change the entire buffer.
  788. Some default stuff like drawers and scheduling/deadline dates will already
  789. have been removed when this is called, as will any matches for regular
  790. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  791. (defvar org-agenda-include-inactive-timestamps nil
  792. "Non-nil means include inactive time stamps in agenda and timeline.")
  793. (defgroup org-agenda-windows nil
  794. "Options concerning the windows used by the Agenda in Org Mode."
  795. :tag "Org Agenda Windows"
  796. :group 'org-agenda)
  797. (defcustom org-agenda-window-setup 'reorganize-frame
  798. "How the agenda buffer should be displayed.
  799. Possible values for this option are:
  800. current-window Show agenda in the current window, keeping all other windows.
  801. other-window Use `switch-to-buffer-other-window' to display agenda.
  802. reorganize-frame Show only two windows on the current frame, the current
  803. window and the agenda.
  804. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  805. Also, when exiting the agenda, kill that frame.
  806. See also the variable `org-agenda-restore-windows-after-quit'."
  807. :group 'org-agenda-windows
  808. :type '(choice
  809. (const current-window)
  810. (const other-frame)
  811. (const other-window)
  812. (const reorganize-frame)))
  813. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  814. "The min and max height of the agenda window as a fraction of frame height.
  815. The value of the variable is a cons cell with two numbers between 0 and 1.
  816. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  817. :group 'org-agenda-windows
  818. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  819. (defcustom org-agenda-restore-windows-after-quit nil
  820. "Non-nil means restore window configuration upon exiting agenda.
  821. Before the window configuration is changed for displaying the agenda,
  822. the current status is recorded. When the agenda is exited with
  823. `q' or `x' and this option is set, the old state is restored. If
  824. `org-agenda-window-setup' is `other-frame', the value of this
  825. option will be ignored."
  826. :group 'org-agenda-windows
  827. :type 'boolean)
  828. (defcustom org-agenda-ndays nil
  829. "Number of days to include in overview display.
  830. Should be 1 or 7.
  831. Obsolete, see `org-agenda-span'."
  832. :group 'org-agenda-daily/weekly
  833. :type 'integer)
  834. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  835. (defcustom org-agenda-span 'week
  836. "Number of days to include in overview display.
  837. Can be day, week, month, year, or any number of days.
  838. Custom commands can set this variable in the options section."
  839. :group 'org-agenda-daily/weekly
  840. :type '(choice (const :tag "Day" day)
  841. (const :tag "Week" week)
  842. (const :tag "Month" month)
  843. (const :tag "Year" year)
  844. (integer :tag "Custom")))
  845. (defcustom org-agenda-start-on-weekday 1
  846. "Non-nil means start the overview always on the specified weekday.
  847. 0 denotes Sunday, 1 denotes Monday etc.
  848. When nil, always start on the current day.
  849. Custom commands can set this variable in the options section."
  850. :group 'org-agenda-daily/weekly
  851. :type '(choice (const :tag "Today" nil)
  852. (integer :tag "Weekday No.")))
  853. (defcustom org-agenda-show-all-dates t
  854. "Non-nil means `org-agenda' shows every day in the selected range.
  855. When nil, only the days which actually have entries are shown."
  856. :group 'org-agenda-daily/weekly
  857. :type 'boolean)
  858. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  859. "Format string for displaying dates in the agenda.
  860. Used by the daily/weekly agenda and by the timeline. This should be
  861. a format string understood by `format-time-string', or a function returning
  862. the formatted date as a string. The function must take a single argument,
  863. a calendar-style date list like (month day year)."
  864. :group 'org-agenda-daily/weekly
  865. :type '(choice
  866. (string :tag "Format string")
  867. (function :tag "Function")))
  868. (defun org-agenda-format-date-aligned (date)
  869. "Format a date string for display in the daily/weekly agenda, or timeline.
  870. This function makes sure that dates are aligned for easy reading."
  871. (require 'cal-iso)
  872. (let* ((dayname (calendar-day-name date))
  873. (day (cadr date))
  874. (day-of-week (calendar-day-of-week date))
  875. (month (car date))
  876. (monthname (calendar-month-name month))
  877. (year (nth 2 date))
  878. (iso-week (org-days-to-iso-week
  879. (calendar-absolute-from-gregorian date)))
  880. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  881. (1- year))
  882. ((and (= month 12) (<= iso-week 1))
  883. (1+ year))
  884. (t year)))
  885. (weekstring (if (= day-of-week 1)
  886. (format " W%02d" iso-week)
  887. "")))
  888. (format "%-10s %2d %s %4d%s"
  889. dayname day monthname year weekstring)))
  890. (defcustom org-agenda-time-leading-zero nil
  891. "Non-nil means use leading zero for military times in agenda.
  892. For example, 9:30am would become 09:30 rather than 9:30."
  893. :group 'org-agenda-daily/weekly
  894. :type 'boolean)
  895. (defcustom org-agenda-timegrid-use-ampm nil
  896. "When set, show AM/PM style timestamps on the timegrid."
  897. :group 'org-agenda
  898. :type 'boolean)
  899. (defun org-agenda-time-of-day-to-ampm (time)
  900. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  901. (let* ((hour-number (string-to-number (substring time 0 -3)))
  902. (minute (substring time -2))
  903. (ampm "am"))
  904. (cond
  905. ((equal hour-number 12)
  906. (setq ampm "pm"))
  907. ((> hour-number 12)
  908. (setq ampm "pm")
  909. (setq hour-number (- hour-number 12))))
  910. (concat
  911. (if org-agenda-time-leading-zero
  912. (format "%02d" hour-number)
  913. (format "%02s" (number-to-string hour-number)))
  914. ":" minute ampm)))
  915. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  916. "Conditionally convert TIME to AM/PM format
  917. based on `org-agenda-timegrid-use-ampm'"
  918. (if org-agenda-timegrid-use-ampm
  919. (org-agenda-time-of-day-to-ampm time)
  920. time))
  921. (defcustom org-agenda-weekend-days '(6 0)
  922. "Which days are weekend?
  923. These days get the special face `org-agenda-date-weekend' in the agenda
  924. and timeline buffers."
  925. :group 'org-agenda-daily/weekly
  926. :type '(set :greedy t
  927. (const :tag "Monday" 1)
  928. (const :tag "Tuesday" 2)
  929. (const :tag "Wednesday" 3)
  930. (const :tag "Thursday" 4)
  931. (const :tag "Friday" 5)
  932. (const :tag "Saturday" 6)
  933. (const :tag "Sunday" 0)))
  934. (defcustom org-agenda-include-diary nil
  935. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  936. Custom commands can set this variable in the options section."
  937. :group 'org-agenda-daily/weekly
  938. :type 'boolean)
  939. (defcustom org-agenda-include-deadlines t
  940. "If non-nil, include entries within their deadline warning period.
  941. Custom commands can set this variable in the options section."
  942. :group 'org-agenda-daily/weekly
  943. :type 'boolean)
  944. (defcustom org-agenda-include-all-todo nil
  945. "Set means weekly/daily agenda will always contain all TODO entries.
  946. The TODO entries will be listed at the top of the agenda, before
  947. the entries for specific days.
  948. This option is deprecated, it is better to define a block agenda instead."
  949. :group 'org-agenda-daily/weekly
  950. :type 'boolean)
  951. (defcustom org-agenda-repeating-timestamp-show-all t
  952. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  953. When set to a list of strings, only show occurrences of repeating
  954. stamps for these TODO keywords. When nil, only one occurrence is
  955. shown, either today or the nearest into the future."
  956. :group 'org-agenda-daily/weekly
  957. :type '(choice
  958. (const :tag "Show repeating stamps" t)
  959. (repeat :tag "Show repeating stamps for these TODO keywords"
  960. (string :tag "TODO Keyword"))
  961. (const :tag "Don't show repeating stamps" nil)))
  962. (defcustom org-scheduled-past-days 10000
  963. "No. of days to continue listing scheduled items that are not marked DONE.
  964. When an item is scheduled on a date, it shows up in the agenda on this
  965. day and will be listed until it is marked done for the number of days
  966. given here."
  967. :group 'org-agenda-daily/weekly
  968. :type 'integer)
  969. (defcustom org-agenda-log-mode-items '(closed clock)
  970. "List of items that should be shown in agenda log mode.
  971. This list may contain the following symbols:
  972. closed Show entries that have been closed on that day.
  973. clock Show entries that have received clocked time on that day.
  974. state Show all logged state changes.
  975. Note that instead of changing this variable, you can also press `C-u l' in
  976. the agenda to display all available LOG items temporarily."
  977. :group 'org-agenda-daily/weekly
  978. :type '(set :greedy t (const closed) (const clock) (const state)))
  979. (defcustom org-agenda-clock-consistency-checks
  980. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  981. :gap-ok-around ("4:00")
  982. :default-face ((:background "DarkRed") (:foreground "white"))
  983. :overlap-face nil :gap-face nil :no-end-time-face nil
  984. :long-face nil :short-face nil)
  985. "This is a property list, with the following keys:
  986. :max-duration Mark clocking chunks that are longer than this time.
  987. This is a time string like \"HH:MM\", or the number
  988. of minutes as an integer.
  989. :min-duration Mark clocking chunks that are shorter that this.
  990. This is a time string like \"HH:MM\", or the number
  991. of minutes as an integer.
  992. :max-gap Mark gaps between clocking chunks that are longer than
  993. this duration. A number of minutes, or a string
  994. like \"HH:MM\".
  995. :gap-ok-around List of times during the day which are usually not working
  996. times. When a gap is detected, but the gap contains any
  997. of these times, the gap is *not* reported. For example,
  998. if this is (\"4:00\" \"13:00\") then gaps that contain
  999. 4:00 in the morning (i.e. the night) and 13:00
  1000. (i.e. a typical lunch time) do not cause a warning.
  1001. You should have at least one time during the night in this
  1002. list, or otherwise the first task each morning will trigger
  1003. a warning because it follows a long gap.
  1004. Furthermore, the following properties can be used to define faces for
  1005. issue display.
  1006. :default-face the default face, if the specific face is undefined
  1007. :overlap-face face for overlapping clocks
  1008. :gap-face face for gaps between clocks
  1009. :no-end-time-face face for incomplete clocks
  1010. :long-face face for clock intervals that are too long
  1011. :short-face face for clock intervals that are too short"
  1012. :group 'org-agenda-daily/weekly
  1013. :group 'org-clock
  1014. :type 'plist)
  1015. (defcustom org-agenda-log-mode-add-notes t
  1016. "Non-nil means add first line of notes to log entries in agenda views.
  1017. If a log item like a state change or a clock entry is associated with
  1018. notes, the first line of these notes will be added to the entry in the
  1019. agenda display."
  1020. :group 'org-agenda-daily/weekly
  1021. :type 'boolean)
  1022. (defcustom org-agenda-start-with-log-mode nil
  1023. "The initial value of log-mode in a newly created agenda window."
  1024. :group 'org-agenda-startup
  1025. :group 'org-agenda-daily/weekly
  1026. :type 'boolean)
  1027. (defcustom org-agenda-start-with-clockreport-mode nil
  1028. "The initial value of clockreport-mode in a newly created agenda window."
  1029. :group 'org-agenda-startup
  1030. :group 'org-agenda-daily/weekly
  1031. :type 'boolean)
  1032. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1033. "Property list with parameters for the clocktable in clockreport mode.
  1034. This is the display mode that shows a clock table in the daily/weekly
  1035. agenda, the properties for this dynamic block can be set here.
  1036. The usual clocktable parameters are allowed here, but you cannot set
  1037. the properties :name, :tstart, :tend, :block, and :scope - these will
  1038. be overwritten to make sure the content accurately reflects the
  1039. current display in the agenda."
  1040. :group 'org-agenda-daily/weekly
  1041. :type 'plist)
  1042. (defcustom org-agenda-search-view-always-boolean nil
  1043. "Non-nil means the search string is interpreted as individual parts.
  1044. The search string for search view can either be interpreted as a phrase,
  1045. or as a list of snippets that define a boolean search for a number of
  1046. strings.
  1047. When this is non-nil, the string will be split on whitespace, and each
  1048. snippet will be searched individually, and all must match in order to
  1049. select an entry. A snippet is then a single string of non-white
  1050. characters, or a string in double quotes, or a regexp in {} braces.
  1051. If a snippet is preceded by \"-\", the snippet must *not* match.
  1052. \"+\" is syntactic sugar for positive selection. Each snippet may
  1053. be found as a full word or a partial word, but see the variable
  1054. `org-agenda-search-view-force-full-words'.
  1055. When this is nil, search will look for the entire search phrase as one,
  1056. with each space character matching any amount of whitespace, including
  1057. line breaks.
  1058. Even when this is nil, you can still switch to Boolean search dynamically
  1059. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1060. is a regexp marked with braces like \"{abc}\", this will also switch to
  1061. boolean search."
  1062. :group 'org-agenda-search-view
  1063. :type 'boolean)
  1064. (if (fboundp 'defvaralias)
  1065. (defvaralias 'org-agenda-search-view-search-words-only
  1066. 'org-agenda-search-view-always-boolean))
  1067. (defcustom org-agenda-search-view-force-full-words nil
  1068. "Non-nil means, search words must be matches as complete words.
  1069. When nil, they may also match part of a word."
  1070. :group 'org-agenda-search-view
  1071. :type 'boolean)
  1072. (defgroup org-agenda-time-grid nil
  1073. "Options concerning the time grid in the Org-mode Agenda."
  1074. :tag "Org Agenda Time Grid"
  1075. :group 'org-agenda)
  1076. (defcustom org-agenda-search-headline-for-time t
  1077. "Non-nil means search headline for a time-of-day.
  1078. If the headline contains a time-of-day in one format or another, it will
  1079. be used to sort the entry into the time sequence of items for a day.
  1080. Some people have time stamps in the headline that refer to the creation
  1081. time or so, and then this produces an unwanted side effect. If this is
  1082. the case for your, use this variable to turn off searching the headline
  1083. for a time."
  1084. :group 'org-agenda-time-grid
  1085. :type 'boolean)
  1086. (defcustom org-agenda-use-time-grid t
  1087. "Non-nil means show a time grid in the agenda schedule.
  1088. A time grid is a set of lines for specific times (like every two hours between
  1089. 8:00 and 20:00). The items scheduled for a day at specific times are
  1090. sorted in between these lines.
  1091. For details about when the grid will be shown, and what it will look like, see
  1092. the variable `org-agenda-time-grid'."
  1093. :group 'org-agenda-time-grid
  1094. :type 'boolean)
  1095. (defcustom org-agenda-time-grid
  1096. '((daily today require-timed)
  1097. "----------------"
  1098. (800 1000 1200 1400 1600 1800 2000))
  1099. "The settings for time grid for agenda display.
  1100. This is a list of three items. The first item is again a list. It contains
  1101. symbols specifying conditions when the grid should be displayed:
  1102. daily if the agenda shows a single day
  1103. weekly if the agenda shows an entire week
  1104. today show grid on current date, independent of daily/weekly display
  1105. require-timed show grid only if at least one item has a time specification
  1106. The second item is a string which will be placed behind the grid time.
  1107. The third item is a list of integers, indicating the times that should have
  1108. a grid line."
  1109. :group 'org-agenda-time-grid
  1110. :type
  1111. '(list
  1112. (set :greedy t :tag "Grid Display Options"
  1113. (const :tag "Show grid in single day agenda display" daily)
  1114. (const :tag "Show grid in weekly agenda display" weekly)
  1115. (const :tag "Always show grid for today" today)
  1116. (const :tag "Show grid only if any timed entries are present"
  1117. require-timed)
  1118. (const :tag "Skip grid times already present in an entry"
  1119. remove-match))
  1120. (string :tag "Grid String")
  1121. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1122. (defcustom org-agenda-show-current-time-in-grid t
  1123. "Non-nil means show the current time in the time grid."
  1124. :group 'org-agenda-time-grid
  1125. :type 'boolean)
  1126. (defcustom org-agenda-current-time-string
  1127. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1128. "The string for the current time marker in the agenda."
  1129. :group 'org-agenda-time-grid
  1130. :type 'string)
  1131. (defgroup org-agenda-sorting nil
  1132. "Options concerning sorting in the Org-mode Agenda."
  1133. :tag "Org Agenda Sorting"
  1134. :group 'org-agenda)
  1135. (defcustom org-agenda-sorting-strategy
  1136. '((agenda habit-down time-up priority-down category-keep)
  1137. (todo priority-down category-keep)
  1138. (tags priority-down category-keep)
  1139. (search category-keep))
  1140. "Sorting structure for the agenda items of a single day.
  1141. This is a list of symbols which will be used in sequence to determine
  1142. if an entry should be listed before another entry. The following
  1143. symbols are recognized:
  1144. time-up Put entries with time-of-day indications first, early first
  1145. time-down Put entries with time-of-day indications first, late first
  1146. category-keep Keep the default order of categories, corresponding to the
  1147. sequence in `org-agenda-files'.
  1148. category-up Sort alphabetically by category, A-Z.
  1149. category-down Sort alphabetically by category, Z-A.
  1150. tag-up Sort alphabetically by last tag, A-Z.
  1151. tag-down Sort alphabetically by last tag, Z-A.
  1152. priority-up Sort numerically by priority, high priority last.
  1153. priority-down Sort numerically by priority, high priority first.
  1154. todo-state-up Sort by todo state, tasks that are done last.
  1155. todo-state-down Sort by todo state, tasks that are done first.
  1156. effort-up Sort numerically by estimated effort, high effort last.
  1157. effort-down Sort numerically by estimated effort, high effort first.
  1158. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1159. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1160. habit-up Put entries that are habits first
  1161. habit-down Put entries that are habits last
  1162. alpha-up Sort headlines alphabetically
  1163. alpha-down Sort headlines alphabetically, reversed
  1164. The different possibilities will be tried in sequence, and testing stops
  1165. if one comparison returns a \"not-equal\". For example, the default
  1166. '(time-up category-keep priority-down)
  1167. means: Pull out all entries having a specified time of day and sort them,
  1168. in order to make a time schedule for the current day the first thing in the
  1169. agenda listing for the day. Of the entries without a time indication, keep
  1170. the grouped in categories, don't sort the categories, but keep them in
  1171. the sequence given in `org-agenda-files'. Within each category sort by
  1172. priority.
  1173. Leaving out `category-keep' would mean that items will be sorted across
  1174. categories by priority.
  1175. Instead of a single list, this can also be a set of list for specific
  1176. contents, with a context symbol in the car of the list, any of
  1177. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1178. Custom commands can bind this variable in the options section."
  1179. :group 'org-agenda-sorting
  1180. :type `(choice
  1181. (repeat :tag "General" ,org-sorting-choice)
  1182. (list :tag "Individually"
  1183. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1184. (repeat ,org-sorting-choice))
  1185. (cons (const :tag "Strategy for TODO lists" todo)
  1186. (repeat ,org-sorting-choice))
  1187. (cons (const :tag "Strategy for Tags matches" tags)
  1188. (repeat ,org-sorting-choice))
  1189. (cons (const :tag "Strategy for search matches" search)
  1190. (repeat ,org-sorting-choice)))))
  1191. (defcustom org-agenda-cmp-user-defined nil
  1192. "A function to define the comparison `user-defined'.
  1193. This function must receive two arguments, agenda entry a and b.
  1194. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1195. the user comparison, return nil.
  1196. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1197. part of an agenda sorting strategy."
  1198. :group 'org-agenda-sorting
  1199. :type 'symbol)
  1200. (defcustom org-sort-agenda-notime-is-late t
  1201. "Non-nil means items without time are considered late.
  1202. This is only relevant for sorting. When t, items which have no explicit
  1203. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1204. do have a time. When nil, the default time is before 0:00. You can use this
  1205. option to decide if the schedule for today should come before or after timeless
  1206. agenda entries."
  1207. :group 'org-agenda-sorting
  1208. :type 'boolean)
  1209. (defcustom org-sort-agenda-noeffort-is-high t
  1210. "Non-nil means items without effort estimate are sorted as high effort.
  1211. This also applies when filtering an agenda view with respect to the
  1212. < or > effort operator. Then, tasks with no effort defined will be treated
  1213. as tasks with high effort.
  1214. When nil, such items are sorted as 0 minutes effort."
  1215. :group 'org-agenda-sorting
  1216. :type 'boolean)
  1217. (defgroup org-agenda-line-format nil
  1218. "Options concerning the entry prefix in the Org-mode agenda display."
  1219. :tag "Org Agenda Line Format"
  1220. :group 'org-agenda)
  1221. (defcustom org-agenda-prefix-format
  1222. '((agenda . " %i %-12:c%?-12t% s")
  1223. (timeline . " % s")
  1224. (todo . " %i %-12:c")
  1225. (tags . " %i %-12:c")
  1226. (search . " %i %-12:c"))
  1227. "Format specifications for the prefix of items in the agenda views.
  1228. An alist with five entries, each for the different agenda types. The
  1229. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1230. The values are format strings.
  1231. This format works similar to a printf format, with the following meaning:
  1232. %c the category of the item, \"Diary\" for entries from the diary,
  1233. or as given by the CATEGORY keyword or derived from the file name
  1234. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1235. %T the last tag of the item (ignore inherited tags, which come first)
  1236. %t the HH:MM time-of-day specification if one applies to the entry
  1237. %s Scheduling/Deadline information, a short string
  1238. %(expression) Eval EXPRESSION and replace the control string
  1239. by the result
  1240. All specifiers work basically like the standard `%s' of printf, but may
  1241. contain two additional characters: a question mark just after the `%'
  1242. and a whitespace/punctuation character just before the final letter.
  1243. If the first character after `%' is a question mark, the entire field
  1244. will only be included if the corresponding value applies to the current
  1245. entry. This is useful for fields which should have fixed width when
  1246. present, but zero width when absent. For example, \"%?-12t\" will
  1247. result in a 12 character time field if a time of the day is specified,
  1248. but will completely disappear in entries which do not contain a time.
  1249. If there is punctuation or whitespace character just before the final
  1250. format letter, this character will be appended to the field value if
  1251. the value is not empty. For example, the format \"%-12:c\" leads to
  1252. \"Diary: \" if the category is \"Diary\". If the category were be
  1253. empty, no additional colon would be inserted.
  1254. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1255. which means:
  1256. - Indent the line with two space characters
  1257. - Give the category a 12 chars wide field, padded with whitespace on
  1258. the right (because of `-'). Append a colon if there is a category
  1259. (because of `:').
  1260. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1261. time, don't put in an empty field, just skip it (because of '?').
  1262. - Finally, put the scheduling information.
  1263. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1264. `org-agenda-remove-tags'.
  1265. Custom commands can set this variable in the options section."
  1266. :type '(choice
  1267. (string :tag "General format")
  1268. (list :greedy t :tag "View dependent"
  1269. (cons (const agenda) (string :tag "Format"))
  1270. (cons (const timeline) (string :tag "Format"))
  1271. (cons (const todo) (string :tag "Format"))
  1272. (cons (const tags) (string :tag "Format"))
  1273. (cons (const search) (string :tag "Format"))))
  1274. :group 'org-agenda-line-format)
  1275. (defvar org-prefix-format-compiled nil
  1276. "The compiled version of the most recently used prefix format.
  1277. See the variable `org-agenda-prefix-format'.")
  1278. (defcustom org-agenda-todo-keyword-format "%-1s"
  1279. "Format for the TODO keyword in agenda lines.
  1280. Set this to something like \"%-12s\" if you want all TODO keywords
  1281. to occupy a fixed space in the agenda display."
  1282. :group 'org-agenda-line-format
  1283. :type 'string)
  1284. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1285. "Text preceding timerange entries in the agenda view.
  1286. This is a list with two strings. The first applies when the range
  1287. is entirely on one day. The second applies if the range spans several days.
  1288. The strings may have two \"%d\" format specifiers which will be filled
  1289. with the sequence number of the days, and the total number of days in the
  1290. range, respectively."
  1291. :group 'org-agenda-line-format
  1292. :type '(list
  1293. (string :tag "Deadline today ")
  1294. (choice :tag "Deadline relative"
  1295. (string :tag "Format string")
  1296. (function))))
  1297. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1298. "Text preceding scheduled items in the agenda view.
  1299. This is a list with two strings. The first applies when the item is
  1300. scheduled on the current day. The second applies when it has been scheduled
  1301. previously, it may contain a %d indicating that this is the nth time that
  1302. this item is scheduled, due to automatic rescheduling of unfinished items
  1303. for the following day. So this number is one larger than the number of days
  1304. that passed since this item was scheduled first."
  1305. :group 'org-agenda-line-format
  1306. :type '(list
  1307. (string :tag "Scheduled today ")
  1308. (string :tag "Scheduled previously")))
  1309. (defcustom org-agenda-inactive-leader "["
  1310. "Text preceding item pulled into the agenda by inactive time stamps.
  1311. These entries are added to the agenda when pressing \"[\"."
  1312. :group 'org-agenda-line-format
  1313. :type '(list
  1314. (string :tag "Scheduled today ")
  1315. (string :tag "Scheduled previously")))
  1316. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1317. "Text preceding deadline items in the agenda view.
  1318. This is a list with two strings. The first applies when the item has its
  1319. deadline on the current day. The second applies when it is in the past or
  1320. in the future, it may contain %d to capture how many days away the deadline
  1321. is (was)."
  1322. :group 'org-agenda-line-format
  1323. :type '(list
  1324. (string :tag "Deadline today ")
  1325. (choice :tag "Deadline relative"
  1326. (string :tag "Format string")
  1327. (function))))
  1328. (defcustom org-agenda-remove-times-when-in-prefix t
  1329. "Non-nil means remove duplicate time specifications in agenda items.
  1330. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1331. time-of-day specification in a headline or diary entry is extracted and
  1332. placed into the prefix. If this option is non-nil, the original specification
  1333. \(a timestamp or -range, or just a plain time(range) specification like
  1334. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1335. cluttered.
  1336. The option can be t or nil. It may also be the symbol `beg', indicating
  1337. that the time should only be removed when it is located at the beginning of
  1338. the headline/diary entry."
  1339. :group 'org-agenda-line-format
  1340. :type '(choice
  1341. (const :tag "Always" t)
  1342. (const :tag "Never" nil)
  1343. (const :tag "When at beginning of entry" beg)))
  1344. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1345. "Non-nil means remove time ranges specifications in agenda
  1346. items that span on several days."
  1347. :group 'org-agenda-line-format
  1348. :type 'boolean)
  1349. (defcustom org-agenda-default-appointment-duration nil
  1350. "Default duration for appointments that only have a starting time.
  1351. When nil, no duration is specified in such cases.
  1352. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1353. :group 'org-agenda-line-format
  1354. :type '(choice
  1355. (integer :tag "Minutes")
  1356. (const :tag "No default duration")))
  1357. (defcustom org-agenda-show-inherited-tags t
  1358. "Non-nil means show inherited tags in each agenda line."
  1359. :group 'org-agenda-line-format
  1360. :type 'boolean)
  1361. (defcustom org-agenda-hide-tags-regexp nil
  1362. "Regular expression used to filter away specific tags in agenda views.
  1363. This means that these tags will be present, but not be shown in the agenda
  1364. line. Secondary filtering will still work on the hidden tags.
  1365. Nil means don't hide any tags."
  1366. :group 'org-agenda-line-format
  1367. :type '(choice
  1368. (const :tag "Hide none" nil)
  1369. (string :tag "Regexp ")))
  1370. (defcustom org-agenda-remove-tags nil
  1371. "Non-nil means remove the tags from the headline copy in the agenda.
  1372. When this is the symbol `prefix', only remove tags when
  1373. `org-agenda-prefix-format' contains a `%T' specifier."
  1374. :group 'org-agenda-line-format
  1375. :type '(choice
  1376. (const :tag "Always" t)
  1377. (const :tag "Never" nil)
  1378. (const :tag "When prefix format contains %T" prefix)))
  1379. (if (fboundp 'defvaralias)
  1380. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1381. 'org-agenda-remove-tags))
  1382. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1383. "Shift tags in agenda items to this column.
  1384. If this number is positive, it specifies the column. If it is negative,
  1385. it means that the tags should be flushright to that column. For example,
  1386. -80 works well for a normal 80 character screen."
  1387. :group 'org-agenda-line-format
  1388. :type 'integer)
  1389. (if (fboundp 'defvaralias)
  1390. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1391. (defcustom org-agenda-fontify-priorities 'cookies
  1392. "Non-nil means highlight low and high priorities in agenda.
  1393. When t, the highest priority entries are bold, lowest priority italic.
  1394. However, settings in `org-priority-faces' will overrule these faces.
  1395. When this variable is the symbol `cookies', only fontify the
  1396. cookies, not the entire task.
  1397. This may also be an association list of priority faces, whose
  1398. keys are the character values of `org-highest-priority',
  1399. `org-default-priority', and `org-lowest-priority' (the default values
  1400. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1401. color as a string, or a list like `(:background \"Red\")'.
  1402. If it is a color, the variable `org-faces-easy-properties'
  1403. determines if it is a foreground or a background color."
  1404. :group 'org-agenda-line-format
  1405. :type '(choice
  1406. (const :tag "Never" nil)
  1407. (const :tag "Defaults" t)
  1408. (const :tag "Cookies only" cookies)
  1409. (repeat :tag "Specify"
  1410. (list (character :tag "Priority" :value ?A)
  1411. (choice :tag "Face "
  1412. (string :tag "Color")
  1413. (sexp :tag "Face"))))))
  1414. (defcustom org-agenda-day-face-function nil
  1415. "Function called to determine what face should be used to display a day.
  1416. The only argument passed to that function is the day. It should
  1417. returns a face, or nil if does not want to specify a face and let
  1418. the normal rules apply."
  1419. :group 'org-agenda-line-format
  1420. :type 'function)
  1421. (defcustom org-agenda-category-icon-alist nil
  1422. "Alist of category icon to be displayed in agenda views.
  1423. Each entry should have the following format:
  1424. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1425. Where CATEGORY-REGEXP is a regexp matching the categories where
  1426. the icon should be displayed.
  1427. FILE-OR-DATA either a file path or a string containing image data.
  1428. The other fields can be omited safely if not needed:
  1429. TYPE indicates the image type.
  1430. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1431. image data.
  1432. PROPS are additional image attributes to assign to the image,
  1433. like, e.g. `:ascent center'.
  1434. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1435. If you want to set the display properties yourself, just put a
  1436. list as second element:
  1437. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1438. For example, to display a 16px horizontal space for Emacs
  1439. category, you can use:
  1440. (\"Emacs\" '(space . (:width (16))))"
  1441. :group 'org-agenda-line-format
  1442. :type '(alist :key-type (string :tag "Regexp matching category")
  1443. :value-type (choice (list :tag "Icon"
  1444. (string :tag "File or data")
  1445. (symbol :tag "Type")
  1446. (boolean :tag "Data?")
  1447. (repeat :tag "Extra image properties" :inline t symbol))
  1448. (list :tag "Display properties" sexp))))
  1449. (defgroup org-agenda-column-view nil
  1450. "Options concerning column view in the agenda."
  1451. :tag "Org Agenda Column View"
  1452. :group 'org-agenda)
  1453. (defcustom org-agenda-columns-show-summaries t
  1454. "Non-nil means show summaries for columns displayed in the agenda view."
  1455. :group 'org-agenda-column-view
  1456. :type 'boolean)
  1457. (defcustom org-agenda-columns-compute-summary-properties t
  1458. "Non-nil means recompute all summary properties before column view.
  1459. When column view in the agenda is listing properties that have a summary
  1460. operator, it can go to all relevant buffers and recompute the summaries
  1461. there. This can mean overhead for the agenda column view, but is necessary
  1462. to have thing up to date.
  1463. As a special case, a CLOCKSUM property also makes sure that the clock
  1464. computations are current."
  1465. :group 'org-agenda-column-view
  1466. :type 'boolean)
  1467. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1468. "Non-nil means the duration of an appointment will add to day effort.
  1469. The property to which appointment durations will be added is the one given
  1470. in the option `org-effort-property'. If an appointment does not have
  1471. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1472. is not set, an appointment without end time will not contribute to the time
  1473. estimate."
  1474. :group 'org-agenda-column-view
  1475. :type 'boolean)
  1476. (defcustom org-agenda-auto-exclude-function nil
  1477. "A function called with a tag to decide if it is filtered on '/ RET'.
  1478. The sole argument to the function, which is called once for each
  1479. possible tag, is a string giving the name of the tag. The
  1480. function should return either nil if the tag should be included
  1481. as normal, or \"-<TAG>\" to exclude the tag.
  1482. Note that for the purpose of tag filtering, only the lower-case version of
  1483. all tags will be considered, so that this function will only ever see
  1484. the lower-case version of all tags."
  1485. :group 'org-agenda
  1486. :type 'function)
  1487. (defcustom org-agenda-bulk-custom-functions nil
  1488. "Alist of characters and custom functions for bulk actions.
  1489. For example, this value makes those two functions available:
  1490. '((?R set-category)
  1491. (?C bulk-cut))
  1492. With selected entries in an agenda buffer, `B R' will call
  1493. the custom function `set-category' on the selected entries.
  1494. Note that functions in this alist don't need to be quoted."
  1495. :type 'alist
  1496. :group 'org-agenda)
  1497. (eval-when-compile
  1498. (require 'cl))
  1499. (require 'org)
  1500. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1501. "Execute BODY with point at location given by `org-hd-marker' property.
  1502. If STRING is non-nil, the text property will be fetched from position 0
  1503. in that string. If STRING is nil, it will be fetched from the beginning
  1504. of the current line."
  1505. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1506. 'org-hd-marker string)))
  1507. (with-current-buffer (marker-buffer marker)
  1508. (save-excursion
  1509. (goto-char marker)
  1510. ,@body))))
  1511. (defun org-add-agenda-custom-command (entry)
  1512. "Replace or add a command in `org-agenda-custom-commands'.
  1513. This is mostly for hacking and trying a new command - once the command
  1514. works you probably want to add it to `org-agenda-custom-commands' for good."
  1515. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1516. (if ass
  1517. (setcdr ass (cdr entry))
  1518. (push entry org-agenda-custom-commands))))
  1519. ;;; Define the Org-agenda-mode
  1520. (defvar org-agenda-mode-map (make-sparse-keymap)
  1521. "Keymap for `org-agenda-mode'.")
  1522. (if (fboundp 'defvaralias)
  1523. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1524. (defvar org-agenda-menu) ; defined later in this file.
  1525. (defvar org-agenda-restrict) ; defined later in this file.
  1526. (defvar org-agenda-follow-mode nil)
  1527. (defvar org-agenda-entry-text-mode nil)
  1528. (defvar org-agenda-clockreport-mode nil)
  1529. (defvar org-agenda-show-log nil)
  1530. (defvar org-agenda-redo-command nil)
  1531. (defvar org-agenda-query-string nil)
  1532. (defvar org-agenda-mode-hook nil
  1533. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1534. (defvar org-agenda-type nil)
  1535. (defvar org-agenda-force-single-file nil)
  1536. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1537. (defun org-agenda-mode ()
  1538. "Mode for time-sorted view on action items in Org-mode files.
  1539. The following commands are available:
  1540. \\{org-agenda-mode-map}"
  1541. (interactive)
  1542. (kill-all-local-variables)
  1543. (setq org-agenda-undo-list nil
  1544. org-agenda-pending-undo-list nil
  1545. org-agenda-bulk-marked-entries nil)
  1546. (setq major-mode 'org-agenda-mode)
  1547. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1548. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1549. (setq mode-name "Org-Agenda")
  1550. (use-local-map org-agenda-mode-map)
  1551. (easy-menu-add org-agenda-menu)
  1552. (if org-startup-truncated (setq truncate-lines t))
  1553. (org-set-local 'line-move-visual nil)
  1554. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1555. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1556. ;; Make sure properties are removed when copying text
  1557. (when (boundp 'buffer-substring-filters)
  1558. (org-set-local 'buffer-substring-filters
  1559. (cons (lambda (x)
  1560. (set-text-properties 0 (length x) nil x) x)
  1561. buffer-substring-filters)))
  1562. (unless org-agenda-keep-modes
  1563. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1564. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1565. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1566. org-agenda-show-log org-agenda-start-with-log-mode))
  1567. (easy-menu-change
  1568. '("Agenda") "Agenda Files"
  1569. (append
  1570. (list
  1571. (vector
  1572. (if (get 'org-agenda-files 'org-restrict)
  1573. "Restricted to single file"
  1574. "Edit File List")
  1575. '(org-edit-agenda-file-list)
  1576. (not (get 'org-agenda-files 'org-restrict)))
  1577. "--")
  1578. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1579. (org-agenda-set-mode-name)
  1580. (apply
  1581. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1582. (list 'org-agenda-mode-hook)))
  1583. (substitute-key-definition 'undo 'org-agenda-undo
  1584. org-agenda-mode-map global-map)
  1585. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1586. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1587. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1588. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1589. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1590. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1591. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1592. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1593. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1594. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1595. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1596. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1597. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1598. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1599. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1600. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1601. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1602. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1603. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1604. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1605. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1606. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1607. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1608. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1609. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1610. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1611. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1612. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1613. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1614. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1615. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1616. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1617. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1618. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1619. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1620. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1621. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1622. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1623. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1624. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1625. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1626. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1627. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1628. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1629. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1630. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1631. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1632. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1633. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1634. (while l (org-defkey org-agenda-mode-map
  1635. (int-to-string (pop l)) 'digit-argument)))
  1636. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1637. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1638. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1639. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1640. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1641. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1642. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1643. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1644. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1645. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1646. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1647. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1648. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1649. 'org-clock-modify-effort-estimate)
  1650. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1651. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1652. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1653. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1654. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1655. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1656. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1657. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1658. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1659. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1660. (substitute-key-definition 'next-line 'org-agenda-next-line
  1661. org-agenda-mode-map global-map)
  1662. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1663. org-agenda-mode-map global-map)
  1664. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1666. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1667. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1668. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1669. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1670. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1671. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1672. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1673. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1674. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1675. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1676. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1677. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1678. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1679. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1680. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1681. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1682. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1683. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1684. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1685. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1686. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1687. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1688. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1689. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1690. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1691. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1692. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1693. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1694. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1695. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1696. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1697. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1698. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1699. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1700. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1701. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1702. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1703. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1704. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1705. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1706. (when org-agenda-mouse-1-follows-link
  1707. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1708. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1709. '("Agenda"
  1710. ("Agenda Files")
  1711. "--"
  1712. ("Agenda Dates"
  1713. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1714. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1715. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1716. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1717. "--"
  1718. ("View"
  1719. ["Day View" org-agenda-day-view
  1720. :active (org-agenda-check-type nil 'agenda)
  1721. :style radio :selected (eq org-agenda-current-span 'day)
  1722. :keys "v d (or just d)"]
  1723. ["Week View" org-agenda-week-view
  1724. :active (org-agenda-check-type nil 'agenda)
  1725. :style radio :selected (eq org-agenda-current-span 'week)
  1726. :keys "v w (or just w)"]
  1727. ["Month View" org-agenda-month-view
  1728. :active (org-agenda-check-type nil 'agenda)
  1729. :style radio :selected (eq org-agenda-current-span 'month)
  1730. :keys "v m"]
  1731. ["Year View" org-agenda-year-view
  1732. :active (org-agenda-check-type nil 'agenda)
  1733. :style radio :selected (eq org-agenda-current-span 'year)
  1734. :keys "v y"]
  1735. "--"
  1736. ["Include Diary" org-agenda-toggle-diary
  1737. :style toggle :selected org-agenda-include-diary
  1738. :active (org-agenda-check-type nil 'agenda)]
  1739. ["Include Deadlines" org-agenda-toggle-deadlines
  1740. :style toggle :selected org-agenda-include-deadlines
  1741. :active (org-agenda-check-type nil 'agenda)]
  1742. ["Use Time Grid" org-agenda-toggle-time-grid
  1743. :style toggle :selected org-agenda-use-time-grid
  1744. :active (org-agenda-check-type nil 'agenda)]
  1745. "--"
  1746. ["Show clock report" org-agenda-clockreport-mode
  1747. :style toggle :selected org-agenda-clockreport-mode
  1748. :active (org-agenda-check-type nil 'agenda)]
  1749. ["Show some entry text" org-agenda-entry-text-mode
  1750. :style toggle :selected org-agenda-entry-text-mode
  1751. :active t]
  1752. "--"
  1753. ["Show Logbook entries" org-agenda-log-mode
  1754. :style toggle :selected org-agenda-show-log
  1755. :active (org-agenda-check-type nil 'agenda 'timeline)
  1756. :keys "v l (or just l)"]
  1757. ["Include archived trees" org-agenda-archives-mode
  1758. :style toggle :selected org-agenda-archives-mode :active t
  1759. :keys "v a"]
  1760. ["Include archive files" (org-agenda-archives-mode t)
  1761. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1762. :keys "v A"]
  1763. "--"
  1764. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1765. ["Write view to file" org-write-agenda t]
  1766. ["Rebuild buffer" org-agenda-redo t]
  1767. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1768. "--"
  1769. ["Show original entry" org-agenda-show t]
  1770. ["Go To (other window)" org-agenda-goto t]
  1771. ["Go To (this window)" org-agenda-switch-to t]
  1772. ["Follow Mode" org-agenda-follow-mode
  1773. :style toggle :selected org-agenda-follow-mode :active t]
  1774. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1775. "--"
  1776. ("TODO"
  1777. ["Cycle TODO" org-agenda-todo t]
  1778. ["Next TODO set" org-agenda-todo-nextset t]
  1779. ["Previous TODO set" org-agenda-todo-previousset t]
  1780. ["Add note" org-agenda-add-note t])
  1781. ("Archive/Refile/Delete"
  1782. ["Archive default" org-agenda-archive-default t]
  1783. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1784. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1785. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1786. ["Archive subtree" org-agenda-archive t]
  1787. "--"
  1788. ["Refile" org-agenda-refile t]
  1789. "--"
  1790. ["Delete subtree" org-agenda-kill t])
  1791. ("Bulk action"
  1792. ["Mark entry" org-agenda-bulk-mark t]
  1793. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1794. ["Unmark entry" org-agenda-bulk-unmark t]
  1795. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1796. ["Act on all marked" org-agenda-bulk-action t]
  1797. "--"
  1798. ("Tags and Properties"
  1799. ["Show all Tags" org-agenda-show-tags t]
  1800. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1801. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1802. "--"
  1803. ["Column View" org-columns t])
  1804. ("Deadline/Schedule"
  1805. ["Schedule" org-agenda-schedule t]
  1806. ["Set Deadline" org-agenda-deadline t]
  1807. "--"
  1808. ["Mark item" org-agenda-action :active t :keys "k m"]
  1809. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1810. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1811. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1812. "--"
  1813. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1814. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1815. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1816. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1817. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1818. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1819. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1820. ("Clock and Effort"
  1821. ["Clock in" org-agenda-clock-in t]
  1822. ["Clock out" org-agenda-clock-out t]
  1823. ["Clock cancel" org-agenda-clock-cancel t]
  1824. ["Goto running clock" org-clock-goto t]
  1825. "--"
  1826. ["Set Effort" org-agenda-set-effort t]
  1827. ["Change clocked effort" org-clock-modify-effort-estimate
  1828. (org-clock-is-active)])
  1829. ("Priority"
  1830. ["Set Priority" org-agenda-priority t]
  1831. ["Increase Priority" org-agenda-priority-up t]
  1832. ["Decrease Priority" org-agenda-priority-down t]
  1833. ["Show Priority" org-agenda-show-priority t])
  1834. ("Calendar/Diary"
  1835. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1836. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1837. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1838. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1839. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1840. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1841. "--"
  1842. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1843. "--"
  1844. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1845. "--"
  1846. ("MobileOrg"
  1847. ["Push Files and Views" org-mobile-push t]
  1848. ["Get Captured and Flagged" org-mobile-pull t]
  1849. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1850. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1851. "--"
  1852. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1853. "--"
  1854. ["Quit" org-agenda-quit t]
  1855. ["Exit and Release Buffers" org-agenda-exit t]
  1856. ))
  1857. ;;; Agenda undo
  1858. (defvar org-agenda-allow-remote-undo t
  1859. "Non-nil means allow remote undo from the agenda buffer.")
  1860. (defvar org-agenda-undo-list nil
  1861. "List of undoable operations in the agenda since last refresh.")
  1862. (defvar org-agenda-undo-has-started-in nil
  1863. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1864. (defvar org-agenda-pending-undo-list nil
  1865. "In a series of undo commands, this is the list of remaining undo items.")
  1866. (defun org-agenda-undo ()
  1867. "Undo a remote editing step in the agenda.
  1868. This undoes changes both in the agenda buffer and in the remote buffer
  1869. that have been changed along."
  1870. (interactive)
  1871. (or org-agenda-allow-remote-undo
  1872. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1873. (if (not (eq this-command last-command))
  1874. (setq org-agenda-undo-has-started-in nil
  1875. org-agenda-pending-undo-list org-agenda-undo-list))
  1876. (if (not org-agenda-pending-undo-list)
  1877. (error "No further undo information"))
  1878. (let* ((entry (pop org-agenda-pending-undo-list))
  1879. buf line cmd rembuf)
  1880. (setq cmd (pop entry) line (pop entry))
  1881. (setq rembuf (nth 2 entry))
  1882. (org-with-remote-undo rembuf
  1883. (while (bufferp (setq buf (pop entry)))
  1884. (if (pop entry)
  1885. (with-current-buffer buf
  1886. (let ((last-undo-buffer buf)
  1887. (inhibit-read-only t))
  1888. (unless (memq buf org-agenda-undo-has-started-in)
  1889. (push buf org-agenda-undo-has-started-in)
  1890. (make-local-variable 'pending-undo-list)
  1891. (undo-start))
  1892. (while (and pending-undo-list
  1893. (listp pending-undo-list)
  1894. (not (car pending-undo-list)))
  1895. (pop pending-undo-list))
  1896. (undo-more 1))))))
  1897. (org-goto-line line)
  1898. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1899. (defun org-verify-change-for-undo (l1 l2)
  1900. "Verify that a real change occurred between the undo lists L1 and L2."
  1901. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1902. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1903. (not (eq l1 l2)))
  1904. ;;; Agenda dispatch
  1905. (defvar org-agenda-restrict nil)
  1906. (defvar org-agenda-restrict-begin (make-marker))
  1907. (defvar org-agenda-restrict-end (make-marker))
  1908. (defvar org-agenda-last-dispatch-buffer nil)
  1909. (defvar org-agenda-overriding-restriction nil)
  1910. ;;;###autoload
  1911. (defun org-agenda (&optional arg keys restriction)
  1912. "Dispatch agenda commands to collect entries to the agenda buffer.
  1913. Prompts for a command to execute. Any prefix arg will be passed
  1914. on to the selected command. The default selections are:
  1915. a Call `org-agenda-list' to display the agenda for current day or week.
  1916. t Call `org-todo-list' to display the global todo list.
  1917. T Call `org-todo-list' to display the global todo list, select only
  1918. entries with a specific TODO keyword (the user gets a prompt).
  1919. m Call `org-tags-view' to display headlines with tags matching
  1920. a condition (the user is prompted for the condition).
  1921. M Like `m', but select only TODO entries, no ordinary headlines.
  1922. L Create a timeline for the current buffer.
  1923. e Export views to associated files.
  1924. s Search entries for keywords.
  1925. / Multi occur across all agenda files and also files listed
  1926. in `org-agenda-text-search-extra-files'.
  1927. < Restrict agenda commands to buffer, subtree, or region.
  1928. Press several times to get the desired effect.
  1929. > Remove a previous restriction.
  1930. # List \"stuck\" projects.
  1931. ! Configure what \"stuck\" means.
  1932. C Configure custom agenda commands.
  1933. More commands can be added by configuring the variable
  1934. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1935. searches can be pre-defined in this way.
  1936. If the current buffer is in Org-mode and visiting a file, you can also
  1937. first press `<' once to indicate that the agenda should be temporarily
  1938. \(until the next use of \\[org-agenda]) restricted to the current file.
  1939. Pressing `<' twice means to restrict to the current subtree or region
  1940. \(if active)."
  1941. (interactive "P")
  1942. (catch 'exit
  1943. (let* ((prefix-descriptions nil)
  1944. (org-agenda-window-setup (if (equal (buffer-name)
  1945. org-agenda-buffer-name)
  1946. 'current-window
  1947. org-agenda-window-setup))
  1948. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1949. (org-agenda-custom-commands
  1950. ;; normalize different versions
  1951. (delq nil
  1952. (mapcar
  1953. (lambda (x)
  1954. (cond ((stringp (cdr x))
  1955. (push x prefix-descriptions)
  1956. nil)
  1957. ((stringp (nth 1 x)) x)
  1958. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1959. (t (cons (car x) (cons "" (cdr x))))))
  1960. org-agenda-custom-commands)))
  1961. (buf (current-buffer))
  1962. (bfn (buffer-file-name (buffer-base-buffer)))
  1963. entry key type match lprops ans)
  1964. ;; Turn off restriction unless there is an overriding one,
  1965. (unless org-agenda-overriding-restriction
  1966. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1967. ;; There is a request to keep the file list in place
  1968. (put 'org-agenda-files 'org-restrict nil))
  1969. (setq org-agenda-restrict nil)
  1970. (move-marker org-agenda-restrict-begin nil)
  1971. (move-marker org-agenda-restrict-end nil))
  1972. ;; Delete old local properties
  1973. (put 'org-agenda-redo-command 'org-lprops nil)
  1974. ;; Delete previously set last-arguments
  1975. (put 'org-agenda-redo-command 'last-args nil)
  1976. ;; Remember where this call originated
  1977. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1978. (unless keys
  1979. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1980. keys (car ans)
  1981. restriction (cdr ans)))
  1982. ;; Establish the restriction, if any
  1983. (when (and (not org-agenda-overriding-restriction) restriction)
  1984. (put 'org-agenda-files 'org-restrict (list bfn))
  1985. (cond
  1986. ((eq restriction 'region)
  1987. (setq org-agenda-restrict t)
  1988. (move-marker org-agenda-restrict-begin (region-beginning))
  1989. (move-marker org-agenda-restrict-end (region-end)))
  1990. ((eq restriction 'subtree)
  1991. (save-excursion
  1992. (setq org-agenda-restrict t)
  1993. (org-back-to-heading t)
  1994. (move-marker org-agenda-restrict-begin (point))
  1995. (move-marker org-agenda-restrict-end
  1996. (progn (org-end-of-subtree t)))))))
  1997. ;; For example the todo list should not need it (but does...)
  1998. (cond
  1999. ((setq entry (assoc keys org-agenda-custom-commands))
  2000. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2001. (progn
  2002. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2003. lprops (nth 4 entry))
  2004. (put 'org-agenda-redo-command 'org-lprops lprops)
  2005. (cond
  2006. ((eq type 'agenda)
  2007. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2008. ((eq type 'alltodo)
  2009. (org-let lprops '(org-todo-list current-prefix-arg)))
  2010. ((eq type 'search)
  2011. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2012. ((eq type 'stuck)
  2013. (org-let lprops '(org-agenda-list-stuck-projects
  2014. current-prefix-arg)))
  2015. ((eq type 'tags)
  2016. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2017. ((eq type 'tags-todo)
  2018. (org-let lprops '(org-tags-view '(4) match)))
  2019. ((eq type 'todo)
  2020. (org-let lprops '(org-todo-list match)))
  2021. ((eq type 'tags-tree)
  2022. (org-check-for-org-mode)
  2023. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2024. ((eq type 'todo-tree)
  2025. (org-check-for-org-mode)
  2026. (org-let lprops
  2027. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2028. (regexp-quote match) "\\>"))))
  2029. ((eq type 'occur-tree)
  2030. (org-check-for-org-mode)
  2031. (org-let lprops '(org-occur match)))
  2032. ((functionp type)
  2033. (org-let lprops '(funcall type match)))
  2034. ((fboundp type)
  2035. (org-let lprops '(funcall type match)))
  2036. (t (error "Invalid custom agenda command type %s" type))))
  2037. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2038. ((equal keys "C")
  2039. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2040. (customize-variable 'org-agenda-custom-commands))
  2041. ((equal keys "a") (call-interactively 'org-agenda-list))
  2042. ((equal keys "s") (call-interactively 'org-search-view))
  2043. ((equal keys "t") (call-interactively 'org-todo-list))
  2044. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2045. ((equal keys "m") (call-interactively 'org-tags-view))
  2046. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2047. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2048. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2049. (org-add-hook
  2050. 'post-command-hook
  2051. (lambda ()
  2052. (unless (current-message)
  2053. (let* ((m (org-agenda-get-any-marker))
  2054. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2055. (when note
  2056. (message (concat
  2057. "FLAGGING-NOTE ([?] for more info): "
  2058. (org-add-props
  2059. (replace-regexp-in-string
  2060. "\\\\n" "//"
  2061. (copy-sequence note))
  2062. nil 'face 'org-warning)))))))
  2063. t t))
  2064. ((equal keys "L")
  2065. (unless (org-mode-p)
  2066. (error "This is not an Org-mode file"))
  2067. (unless restriction
  2068. (put 'org-agenda-files 'org-restrict (list bfn))
  2069. (org-call-with-arg 'org-timeline arg)))
  2070. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2071. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2072. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2073. (t (error "Invalid agenda key"))))))
  2074. (defun org-agenda-append-agenda ()
  2075. "Append another agenda view to the current one.
  2076. This function allows interactive building of block agendas.
  2077. Agenda views are separated by `org-agenda-block-separator'."
  2078. (interactive)
  2079. (unless (string= (buffer-name) org-agenda-buffer-name)
  2080. (error "Can only append from within agenda buffer"))
  2081. (let ((org-agenda-multi t))
  2082. (org-agenda)
  2083. (widen)))
  2084. (defun org-agenda-normalize-custom-commands (cmds)
  2085. (delq nil
  2086. (mapcar
  2087. (lambda (x)
  2088. (cond ((stringp (cdr x)) nil)
  2089. ((stringp (nth 1 x)) x)
  2090. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2091. (t (cons (car x) (cons "" (cdr x))))))
  2092. cmds)))
  2093. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2094. "The user interface for selecting an agenda command."
  2095. (catch 'exit
  2096. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2097. (restrict-ok (and bfn (org-mode-p)))
  2098. (region-p (org-region-active-p))
  2099. (custom org-agenda-custom-commands)
  2100. (selstring "")
  2101. restriction second-time
  2102. c entry key type match prefixes rmheader header-end custom1 desc
  2103. line lines left right n n1)
  2104. (save-window-excursion
  2105. (delete-other-windows)
  2106. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2107. (erase-buffer)
  2108. (insert (eval-when-compile
  2109. (let ((header
  2110. "
  2111. Press key for an agenda command: < Buffer, subtree/region restriction
  2112. -------------------------------- > Remove restriction
  2113. a Agenda for current week or day e Export agenda views
  2114. t List of all TODO entries T Entries with special TODO kwd
  2115. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2116. L Timeline for current buffer # List stuck projects (!=configure)
  2117. s Search for keywords C Configure custom agenda commands
  2118. / Multi-occur ? Find :FLAGGED: entries
  2119. ")
  2120. (start 0))
  2121. (while (string-match
  2122. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2123. header start)
  2124. (setq start (match-end 0))
  2125. (add-text-properties (match-beginning 2) (match-end 2)
  2126. '(face bold) header))
  2127. header)))
  2128. (setq header-end (move-marker (make-marker) (point)))
  2129. (while t
  2130. (setq custom1 custom)
  2131. (when (eq rmheader t)
  2132. (org-goto-line 1)
  2133. (re-search-forward ":" nil t)
  2134. (delete-region (match-end 0) (point-at-eol))
  2135. (forward-char 1)
  2136. (looking-at "-+")
  2137. (delete-region (match-end 0) (point-at-eol))
  2138. (move-marker header-end (match-end 0)))
  2139. (goto-char header-end)
  2140. (delete-region (point) (point-max))
  2141. ;; Produce all the lines that describe custom commands and prefixes
  2142. (setq lines nil)
  2143. (while (setq entry (pop custom1))
  2144. (setq key (car entry) desc (nth 1 entry)
  2145. type (nth 2 entry)
  2146. match (nth 3 entry))
  2147. (if (> (length key) 1)
  2148. (add-to-list 'prefixes (string-to-char key))
  2149. (setq line
  2150. (format
  2151. "%-4s%-14s"
  2152. (org-add-props (copy-sequence key)
  2153. '(face bold))
  2154. (cond
  2155. ((string-match "\\S-" desc) desc)
  2156. ((eq type 'agenda) "Agenda for current week or day")
  2157. ((eq type 'alltodo) "List of all TODO entries")
  2158. ((eq type 'search) "Word search")
  2159. ((eq type 'stuck) "List of stuck projects")
  2160. ((eq type 'todo) "TODO keyword")
  2161. ((eq type 'tags) "Tags query")
  2162. ((eq type 'tags-todo) "Tags (TODO)")
  2163. ((eq type 'tags-tree) "Tags tree")
  2164. ((eq type 'todo-tree) "TODO kwd tree")
  2165. ((eq type 'occur-tree) "Occur tree")
  2166. ((functionp type) (if (symbolp type)
  2167. (symbol-name type)
  2168. "Lambda expression"))
  2169. (t "???"))))
  2170. (if org-agenda-menu-show-matcher
  2171. (setq line
  2172. (concat line ": "
  2173. (cond
  2174. ((stringp match)
  2175. (setq match (copy-sequence match))
  2176. (org-add-props match nil 'face 'org-warning))
  2177. (match
  2178. (format "set of %d commands" (length match)))
  2179. (t ""))))
  2180. (if (org-string-nw-p match)
  2181. (add-text-properties
  2182. 0 (length line) (list 'help-echo
  2183. (concat "Matcher: "match)) line)))
  2184. (push line lines)))
  2185. (setq lines (nreverse lines))
  2186. (when prefixes
  2187. (mapc (lambda (x)
  2188. (push
  2189. (format "%s %s"
  2190. (org-add-props (char-to-string x)
  2191. nil 'face 'bold)
  2192. (or (cdr (assoc (concat selstring
  2193. (char-to-string x))
  2194. prefix-descriptions))
  2195. "Prefix key"))
  2196. lines))
  2197. prefixes))
  2198. ;; Check if we should display in two columns
  2199. (if org-agenda-menu-two-column
  2200. (progn
  2201. (setq n (length lines)
  2202. n1 (+ (/ n 2) (mod n 2))
  2203. right (nthcdr n1 lines)
  2204. left (copy-sequence lines))
  2205. (setcdr (nthcdr (1- n1) left) nil))
  2206. (setq left lines right nil))
  2207. (while left
  2208. (insert "\n" (pop left))
  2209. (when right
  2210. (if (< (current-column) 40)
  2211. (move-to-column 40 t)
  2212. (insert " "))
  2213. (insert (pop right))))
  2214. ;; Make the window the right size
  2215. (goto-char (point-min))
  2216. (if second-time
  2217. (if (not (pos-visible-in-window-p (point-max)))
  2218. (org-fit-window-to-buffer))
  2219. (setq second-time t)
  2220. (org-fit-window-to-buffer))
  2221. ;; Ask for selection
  2222. (message "Press key for agenda command%s:"
  2223. (if (or restrict-ok org-agenda-overriding-restriction)
  2224. (if org-agenda-overriding-restriction
  2225. " (restriction lock active)"
  2226. (if restriction
  2227. (format " (restricted to %s)" restriction)
  2228. " (unrestricted)"))
  2229. ""))
  2230. (setq c (read-char-exclusive))
  2231. (message "")
  2232. (cond
  2233. ((assoc (char-to-string c) custom)
  2234. (setq selstring (concat selstring (char-to-string c)))
  2235. (throw 'exit (cons selstring restriction)))
  2236. ((memq c prefixes)
  2237. (setq selstring (concat selstring (char-to-string c))
  2238. prefixes nil
  2239. rmheader (or rmheader t)
  2240. custom (delq nil (mapcar
  2241. (lambda (x)
  2242. (if (or (= (length (car x)) 1)
  2243. (/= (string-to-char (car x)) c))
  2244. nil
  2245. (cons (substring (car x) 1) (cdr x))))
  2246. custom))))
  2247. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2248. (message "Restriction is only possible in Org-mode buffers")
  2249. (ding) (sit-for 1))
  2250. ((eq c ?1)
  2251. (org-agenda-remove-restriction-lock 'noupdate)
  2252. (setq restriction 'buffer))
  2253. ((eq c ?0)
  2254. (org-agenda-remove-restriction-lock 'noupdate)
  2255. (setq restriction (if region-p 'region 'subtree)))
  2256. ((eq c ?<)
  2257. (org-agenda-remove-restriction-lock 'noupdate)
  2258. (setq restriction
  2259. (cond
  2260. ((eq restriction 'buffer)
  2261. (if region-p 'region 'subtree))
  2262. ((memq restriction '(subtree region))
  2263. nil)
  2264. (t 'buffer))))
  2265. ((eq c ?>)
  2266. (org-agenda-remove-restriction-lock 'noupdate)
  2267. (setq restriction nil))
  2268. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2269. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2270. ((and (> (length selstring) 0) (eq c ?\d))
  2271. (delete-window)
  2272. (org-agenda-get-restriction-and-command prefix-descriptions))
  2273. ((equal c ?q) (error "Abort"))
  2274. (t (error "Invalid key %c" c))))))))
  2275. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2276. (defvar org-agenda-last-arguments nil
  2277. "The arguments of the previous call to `org-agenda'.")
  2278. (defun org-agenda-run-series (name series)
  2279. (org-let (nth 1 series) '(org-prepare-agenda name))
  2280. (let* ((org-agenda-multi t)
  2281. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2282. (org-agenda-overriding-arguments
  2283. (or org-agenda-overriding-arguments
  2284. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2285. (get 'org-agenda-redo-command 'last-args))))
  2286. (cmds (car series))
  2287. (gprops (nth 1 series))
  2288. match ;; The byte compiler incorrectly complains about this. Keep it!
  2289. cmd type lprops)
  2290. (while (setq cmd (pop cmds))
  2291. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2292. (cond
  2293. ((eq type 'agenda)
  2294. (org-let2 gprops lprops
  2295. '(call-interactively 'org-agenda-list)))
  2296. ((eq type 'alltodo)
  2297. (org-let2 gprops lprops
  2298. '(call-interactively 'org-todo-list)))
  2299. ((eq type 'search)
  2300. (org-let2 gprops lprops
  2301. '(org-search-view current-prefix-arg match nil)))
  2302. ((eq type 'stuck)
  2303. (org-let2 gprops lprops
  2304. '(call-interactively 'org-agenda-list-stuck-projects)))
  2305. ((eq type 'tags)
  2306. (org-let2 gprops lprops
  2307. '(org-tags-view current-prefix-arg match)))
  2308. ((eq type 'tags-todo)
  2309. (org-let2 gprops lprops
  2310. '(org-tags-view '(4) match)))
  2311. ((eq type 'todo)
  2312. (org-let2 gprops lprops
  2313. '(org-todo-list match)))
  2314. ((fboundp type)
  2315. (org-let2 gprops lprops
  2316. '(funcall type match)))
  2317. (t (error "Invalid type in command series"))))
  2318. (widen)
  2319. (setq org-agenda-redo-command redo)
  2320. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2321. (goto-char (point-min)))
  2322. (org-fit-agenda-window)
  2323. (org-let (nth 1 series) '(org-finalize-agenda)))
  2324. ;;;###autoload
  2325. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2326. "Run an agenda command in batch mode and send the result to STDOUT.
  2327. If CMD-KEY is a string of length 1, it is used as a key in
  2328. `org-agenda-custom-commands' and triggers this command. If it is a
  2329. longer string it is used as a tags/todo match string.
  2330. Parameters are alternating variable names and values that will be bound
  2331. before running the agenda command."
  2332. (let (pars)
  2333. (while parameters
  2334. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2335. (if (> (length cmd-key) 2)
  2336. (eval (list 'let (nreverse pars)
  2337. (list 'org-tags-view nil cmd-key)))
  2338. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2339. (set-buffer org-agenda-buffer-name)
  2340. (princ (org-encode-for-stdout (buffer-string)))))
  2341. ;(defun org-encode-for-stdout (string)
  2342. ; (if (fboundp 'encode-coding-string)
  2343. ; (encode-coding-string string buffer-file-coding-system)
  2344. ; string))
  2345. (defun org-encode-for-stdout (string)
  2346. string)
  2347. (defvar org-agenda-info nil)
  2348. ;;;###autoload
  2349. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2350. "Run an agenda command in batch mode and send the result to STDOUT.
  2351. If CMD-KEY is a string of length 1, it is used as a key in
  2352. `org-agenda-custom-commands' and triggers this command. If it is a
  2353. longer string it is used as a tags/todo match string.
  2354. Parameters are alternating variable names and values that will be bound
  2355. before running the agenda command.
  2356. The output gives a line for each selected agenda item. Each
  2357. item is a list of comma-separated values, like this:
  2358. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2359. category The category of the item
  2360. head The headline, without TODO kwd, TAGS and PRIORITY
  2361. type The type of the agenda entry, can be
  2362. todo selected in TODO match
  2363. tagsmatch selected in tags match
  2364. diary imported from diary
  2365. deadline a deadline on given date
  2366. scheduled scheduled on given date
  2367. timestamp entry has timestamp on given date
  2368. closed entry was closed on given date
  2369. upcoming-deadline warning about deadline
  2370. past-scheduled forwarded scheduled item
  2371. block entry has date block including g. date
  2372. todo The todo keyword, if any
  2373. tags All tags including inherited ones, separated by colons
  2374. date The relevant date, like 2007-2-14
  2375. time The time, like 15:00-16:50
  2376. extra Sting with extra planning info
  2377. priority-l The priority letter if any was given
  2378. priority-n The computed numerical priority
  2379. agenda-day The day in the agenda where this is listed"
  2380. (let (pars)
  2381. (while parameters
  2382. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2383. (push (list 'org-agenda-remove-tags t) pars)
  2384. (if (> (length cmd-key) 2)
  2385. (eval (list 'let (nreverse pars)
  2386. (list 'org-tags-view nil cmd-key)))
  2387. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2388. (set-buffer org-agenda-buffer-name)
  2389. (let* ((lines (org-split-string (buffer-string) "\n"))
  2390. line)
  2391. (while (setq line (pop lines))
  2392. (catch 'next
  2393. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2394. (setq org-agenda-info
  2395. (org-fix-agenda-info (text-properties-at 0 line)))
  2396. (princ
  2397. (org-encode-for-stdout
  2398. (mapconcat 'org-agenda-export-csv-mapper
  2399. '(org-category txt type todo tags date time extra
  2400. priority-letter priority agenda-day)
  2401. ",")))
  2402. (princ "\n"))))))
  2403. (defun org-fix-agenda-info (props)
  2404. "Make sure all properties on an agenda item have a canonical form.
  2405. This ensures the export commands can easily use it."
  2406. (let (tmp re)
  2407. (when (setq tmp (plist-get props 'tags))
  2408. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2409. (when (setq tmp (plist-get props 'date))
  2410. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2411. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2412. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2413. (setq tmp (calendar-date-string tmp)))
  2414. (setq props (plist-put props 'date tmp)))
  2415. (when (setq tmp (plist-get props 'day))
  2416. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2417. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2418. (setq tmp (calendar-date-string tmp)))
  2419. (setq props (plist-put props 'day tmp))
  2420. (setq props (plist-put props 'agenda-day tmp)))
  2421. (when (setq tmp (plist-get props 'txt))
  2422. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2423. (plist-put props 'priority-letter (match-string 1 tmp))
  2424. (setq tmp (replace-match "" t t tmp)))
  2425. (when (and (setq re (plist-get props 'org-todo-regexp))
  2426. (setq re (concat "\\`\\.*" re " ?"))
  2427. (string-match re tmp))
  2428. (plist-put props 'todo (match-string 1 tmp))
  2429. (setq tmp (replace-match "" t t tmp)))
  2430. (plist-put props 'txt tmp)))
  2431. props)
  2432. (defun org-agenda-export-csv-mapper (prop)
  2433. (let ((res (plist-get org-agenda-info prop)))
  2434. (setq res
  2435. (cond
  2436. ((not res) "")
  2437. ((stringp res) res)
  2438. (t (prin1-to-string res))))
  2439. (while (string-match "," res)
  2440. (setq res (replace-match ";" t t res)))
  2441. (org-trim res)))
  2442. ;;;###autoload
  2443. (defun org-store-agenda-views (&rest parameters)
  2444. (interactive)
  2445. (eval (list 'org-batch-store-agenda-views)))
  2446. ;; FIXME, why is this a macro?????
  2447. ;;;###autoload
  2448. (defmacro org-batch-store-agenda-views (&rest parameters)
  2449. "Run all custom agenda commands that have a file argument."
  2450. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2451. (pop-up-frames nil)
  2452. (dir default-directory)
  2453. pars cmd thiscmdkey files opts cmd-or-set)
  2454. (while parameters
  2455. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2456. (setq pars (reverse pars))
  2457. (save-window-excursion
  2458. (while cmds
  2459. (setq cmd (pop cmds)
  2460. thiscmdkey (car cmd)
  2461. cmd-or-set (nth 2 cmd)
  2462. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2463. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2464. (if (stringp files) (setq files (list files)))
  2465. (when files
  2466. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2467. (list 'org-agenda nil thiscmdkey)))
  2468. (set-buffer org-agenda-buffer-name)
  2469. (while files
  2470. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2471. (list 'org-write-agenda
  2472. (expand-file-name (pop files) dir) nil t))))
  2473. (and (get-buffer org-agenda-buffer-name)
  2474. (kill-buffer org-agenda-buffer-name)))))))
  2475. (defun org-agenda-mark-header-line (pos)
  2476. "Mark the line at POS as an agenda structure header."
  2477. (save-excursion
  2478. (goto-char pos)
  2479. (put-text-property (point-at-bol) (point-at-eol)
  2480. 'org-agenda-structural-header t)
  2481. (when org-agenda-title-append
  2482. (put-text-property (point-at-bol) (point-at-eol)
  2483. 'org-agenda-title-append org-agenda-title-append))))
  2484. (defvar org-mobile-creating-agendas)
  2485. (defun org-write-agenda (file &optional open nosettings)
  2486. "Write the current buffer (an agenda view) as a file.
  2487. Depending on the extension of the file name, plain text (.txt),
  2488. HTML (.html or .htm) or Postscript (.ps) is produced.
  2489. If the extension is .ics, run icalendar export over all files used
  2490. to construct the agenda and limit the export to entries listed in the
  2491. agenda now.
  2492. With prefix argument OPEN, open the new file immediately.
  2493. If NOSETTINGS is given, do not scope the settings of
  2494. `org-agenda-exporter-settings' into the export commands. This is used when
  2495. the settings have already been scoped and we do not wish to overrule other,
  2496. higher priority settings."
  2497. (interactive "FWrite agenda to file: \nP")
  2498. (if (not (file-writable-p file))
  2499. (error "Cannot write agenda to file %s" file))
  2500. (org-let (if nosettings nil org-agenda-exporter-settings)
  2501. '(save-excursion
  2502. (save-window-excursion
  2503. (org-agenda-mark-filtered-text)
  2504. (let ((bs (copy-sequence (buffer-string))) beg)
  2505. (org-agenda-unmark-filtered-text)
  2506. (with-temp-buffer
  2507. (rename-buffer "Agenda View" t)
  2508. (set-buffer-modified-p nil)
  2509. (insert bs)
  2510. (org-agenda-remove-marked-text 'org-filtered)
  2511. (while (setq beg (text-property-any (point-min) (point-max)
  2512. 'org-filtered t))
  2513. (delete-region
  2514. beg (or (next-single-property-change beg 'org-filtered)
  2515. (point-max))))
  2516. (run-hooks 'org-agenda-before-write-hook)
  2517. (cond
  2518. ((org-bound-and-true-p org-mobile-creating-agendas)
  2519. (org-mobile-write-agenda-for-mobile file))
  2520. ((string-match "\\.html?\\'" file)
  2521. (require 'htmlize)
  2522. (set-buffer (htmlize-buffer (current-buffer)))
  2523. (when (and org-agenda-export-html-style
  2524. (string-match "<style>" org-agenda-export-html-style))
  2525. ;; replace <style> section with org-agenda-export-html-style
  2526. (goto-char (point-min))
  2527. (kill-region (- (search-forward "<style") 6)
  2528. (search-forward "</style>"))
  2529. (insert org-agenda-export-html-style))
  2530. (write-file file)
  2531. (kill-buffer (current-buffer))
  2532. (message "HTML written to %s" file))
  2533. ((string-match "\\.ps\\'" file)
  2534. (require 'ps-print)
  2535. (ps-print-buffer-with-faces file)
  2536. (message "Postscript written to %s" file))
  2537. ((string-match "\\.pdf\\'" file)
  2538. (require 'ps-print)
  2539. (ps-print-buffer-with-faces
  2540. (concat (file-name-sans-extension file) ".ps"))
  2541. (call-process "ps2pdf" nil nil nil
  2542. (expand-file-name
  2543. (concat (file-name-sans-extension file) ".ps"))
  2544. (expand-file-name file))
  2545. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2546. (message "PDF written to %s" file))
  2547. ((string-match "\\.ics\\'" file)
  2548. (require 'org-icalendar)
  2549. (let ((org-agenda-marker-table
  2550. (org-create-marker-find-array
  2551. (org-agenda-collect-markers)))
  2552. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2553. (org-combined-agenda-icalendar-file file))
  2554. (apply 'org-export-icalendar 'combine
  2555. (org-agenda-files nil 'ifmode))))
  2556. (t
  2557. (let ((bs (buffer-string)))
  2558. (find-file file)
  2559. (erase-buffer)
  2560. (insert bs)
  2561. (save-buffer 0)
  2562. (kill-buffer (current-buffer))
  2563. (message "Plain text written to %s" file))))))))
  2564. (set-buffer org-agenda-buffer-name))
  2565. (when open (org-open-file file)))
  2566. (defvar org-agenda-filter-overlays nil)
  2567. (defun org-agenda-mark-filtered-text ()
  2568. "Mark all text hidden by filtering with a text property."
  2569. (let ((inhibit-read-only t))
  2570. (mapc
  2571. (lambda (o)
  2572. (when (equal (overlay-buffer o) (current-buffer))
  2573. (put-text-property
  2574. (overlay-start o) (overlay-end o)
  2575. 'org-filtered t)))
  2576. org-agenda-filter-overlays)))
  2577. (defun org-agenda-unmark-filtered-text ()
  2578. "Remove the filtering text property."
  2579. (let ((inhibit-read-only t))
  2580. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2581. (defun org-agenda-remove-marked-text (property &optional value)
  2582. "Delete all text marked with VALUE of PROPERTY.
  2583. VALUE defaults to t."
  2584. (let (beg)
  2585. (setq value (or value t))
  2586. (while (setq beg (text-property-any (point-min) (point-max)
  2587. property value))
  2588. (delete-region
  2589. beg (or (next-single-property-change beg 'org-filtered)
  2590. (point-max))))))
  2591. (defun org-agenda-add-entry-text ()
  2592. "Add entry text to agenda lines.
  2593. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2594. entry text following headings shown in the agenda.
  2595. Drawers will be excluded, also the line with scheduling/deadline info."
  2596. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2597. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2598. (let (m txt)
  2599. (goto-char (point-min))
  2600. (while (not (eobp))
  2601. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2602. (beginning-of-line 2)
  2603. (setq txt (org-agenda-get-some-entry-text
  2604. m org-agenda-add-entry-text-maxlines " > "))
  2605. (end-of-line 1)
  2606. (if (string-match "\\S-" txt)
  2607. (insert "\n" txt)
  2608. (or (eobp) (forward-char 1))))))))
  2609. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2610. &rest keep)
  2611. "Extract entry text from MARKER, at most N-LINES lines.
  2612. This will ignore drawers etc, just get the text.
  2613. If INDENT is given, prefix every line with this string. If KEEP is
  2614. given, it is a list of symbols, defining stuff that should not be
  2615. removed from the entry content. Currently only `planning' is allowed here."
  2616. (let (txt drawer-re kwd-time-re ind)
  2617. (save-excursion
  2618. (with-current-buffer (marker-buffer marker)
  2619. (if (not (org-mode-p))
  2620. (setq txt "")
  2621. (save-excursion
  2622. (save-restriction
  2623. (widen)
  2624. (goto-char marker)
  2625. (end-of-line 1)
  2626. (setq txt (buffer-substring
  2627. (min (1+ (point)) (point-max))
  2628. (progn (outline-next-heading) (point)))
  2629. drawer-re org-drawer-regexp
  2630. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2631. ".*\n?"))
  2632. (with-temp-buffer
  2633. (insert txt)
  2634. (when org-agenda-add-entry-text-descriptive-links
  2635. (goto-char (point-min))
  2636. (while (org-activate-bracket-links (point-max))
  2637. (add-text-properties (match-beginning 0) (match-end 0)
  2638. '(face org-link))))
  2639. (goto-char (point-min))
  2640. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2641. (set-text-properties (match-beginning 0) (match-end 0)
  2642. nil))
  2643. (goto-char (point-min))
  2644. (while (re-search-forward drawer-re nil t)
  2645. (delete-region
  2646. (match-beginning 0)
  2647. (progn (re-search-forward
  2648. "^[ \t]*:END:.*\n?" nil 'move)
  2649. (point))))
  2650. (unless (member 'planning keep)
  2651. (goto-char (point-min))
  2652. (while (re-search-forward kwd-time-re nil t)
  2653. (replace-match "")))
  2654. (goto-char (point-min))
  2655. (when org-agenda-entry-text-exclude-regexps
  2656. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2657. (while (setq re (pop re-list))
  2658. (goto-char (point-min))
  2659. (while (re-search-forward re nil t)
  2660. (replace-match "")))))
  2661. (goto-char (point-max))
  2662. (skip-chars-backward " \t\n")
  2663. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2664. ;; find and remove min common indentation
  2665. (goto-char (point-min))
  2666. (untabify (point-min) (point-max))
  2667. (setq ind (org-get-indentation))
  2668. (while (not (eobp))
  2669. (unless (looking-at "[ \t]*$")
  2670. (setq ind (min ind (org-get-indentation))))
  2671. (beginning-of-line 2))
  2672. (goto-char (point-min))
  2673. (while (not (eobp))
  2674. (unless (looking-at "[ \t]*$")
  2675. (move-to-column ind)
  2676. (delete-region (point-at-bol) (point)))
  2677. (beginning-of-line 2))
  2678. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2679. (goto-char (point-min))
  2680. (when indent
  2681. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2682. (replace-match indent t t)))
  2683. (goto-char (point-min))
  2684. (while (looking-at "[ \t]*\n") (replace-match ""))
  2685. (goto-char (point-max))
  2686. (when (> (org-current-line)
  2687. n-lines)
  2688. (org-goto-line (1+ n-lines))
  2689. (backward-char 1))
  2690. (setq txt (buffer-substring (point-min) (point)))))))))
  2691. txt))
  2692. (defun org-agenda-collect-markers ()
  2693. "Collect the markers pointing to entries in the agenda buffer."
  2694. (let (m markers)
  2695. (save-excursion
  2696. (goto-char (point-min))
  2697. (while (not (eobp))
  2698. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2699. (org-get-at-bol 'org-marker)))
  2700. (push m markers))
  2701. (beginning-of-line 2)))
  2702. (nreverse markers)))
  2703. (defun org-create-marker-find-array (marker-list)
  2704. "Create a alist of files names with all marker positions in that file."
  2705. (let (f tbl m a p)
  2706. (while (setq m (pop marker-list))
  2707. (setq p (marker-position m)
  2708. f (buffer-file-name (or (buffer-base-buffer
  2709. (marker-buffer m))
  2710. (marker-buffer m))))
  2711. (if (setq a (assoc f tbl))
  2712. (push (marker-position m) (cdr a))
  2713. (push (list f p) tbl)))
  2714. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2715. tbl)))
  2716. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2717. (defun org-check-agenda-marker-table ()
  2718. "Check of the current entry is on the marker list."
  2719. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2720. a)
  2721. (and (setq a (assoc file org-agenda-marker-table))
  2722. (save-match-data
  2723. (save-excursion
  2724. (org-back-to-heading t)
  2725. (member (point) (cdr a)))))))
  2726. (defun org-check-for-org-mode ()
  2727. "Make sure current buffer is in org-mode. Error if not."
  2728. (or (org-mode-p)
  2729. (error "Cannot execute org-mode agenda command on buffer in %s"
  2730. major-mode)))
  2731. (defun org-fit-agenda-window ()
  2732. "Fit the window to the buffer size."
  2733. (and (memq org-agenda-window-setup '(reorganize-frame))
  2734. (fboundp 'fit-window-to-buffer)
  2735. (org-fit-window-to-buffer
  2736. nil
  2737. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2738. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2739. ;;; Agenda prepare and finalize
  2740. (defvar org-agenda-multi nil) ; dynamically scoped
  2741. (defvar org-agenda-buffer-name "*Org Agenda*")
  2742. (defvar org-pre-agenda-window-conf nil)
  2743. (defvar org-agenda-columns-active nil)
  2744. (defvar org-agenda-name nil)
  2745. (defvar org-agenda-filter nil)
  2746. (defvar org-agenda-filter-while-redo nil)
  2747. (defvar org-agenda-filter-preset nil
  2748. "A preset of the tags filter used for secondary agenda filtering.
  2749. This must be a list of strings, each string must be a single tag preceded
  2750. by \"+\" or \"-\".
  2751. This variable should not be set directly, but agenda custom commands can
  2752. bind it in the options section. The preset filter is a global property of
  2753. the entire agenda view. In a block agenda, it will not work reliably to
  2754. define a filter for one of the individual blocks. You need to set it in
  2755. the global options and expect it to be applied to the entire view.")
  2756. (defun org-prepare-agenda (&optional name)
  2757. (setq org-todo-keywords-for-agenda nil)
  2758. (setq org-done-keywords-for-agenda nil)
  2759. (setq org-drawers-for-agenda nil)
  2760. (unless org-agenda-persistent-filter
  2761. (setq org-agenda-filter nil))
  2762. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2763. (if org-agenda-multi
  2764. (progn
  2765. (setq buffer-read-only nil)
  2766. (goto-char (point-max))
  2767. (unless (or (bobp) org-agenda-compact-blocks
  2768. (not org-agenda-block-separator))
  2769. (insert "\n"
  2770. (if (stringp org-agenda-block-separator)
  2771. org-agenda-block-separator
  2772. (make-string (window-width) org-agenda-block-separator))
  2773. "\n"))
  2774. (narrow-to-region (point) (point-max)))
  2775. (org-agenda-reset-markers)
  2776. (setq org-agenda-contributing-files nil)
  2777. (setq org-agenda-columns-active nil)
  2778. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2779. (setq org-todo-keywords-for-agenda
  2780. (org-uniquify org-todo-keywords-for-agenda))
  2781. (setq org-done-keywords-for-agenda
  2782. (org-uniquify org-done-keywords-for-agenda))
  2783. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2784. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2785. (awin (get-buffer-window abuf)))
  2786. (cond
  2787. ((equal (current-buffer) abuf) nil)
  2788. (awin (select-window awin))
  2789. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2790. ((equal org-agenda-window-setup 'current-window)
  2791. (org-pop-to-buffer-same-window abuf))
  2792. ((equal org-agenda-window-setup 'other-window)
  2793. (org-switch-to-buffer-other-window abuf))
  2794. ((equal org-agenda-window-setup 'other-frame)
  2795. (switch-to-buffer-other-frame abuf))
  2796. ((equal org-agenda-window-setup 'reorganize-frame)
  2797. (delete-other-windows)
  2798. (org-switch-to-buffer-other-window abuf)))
  2799. ;; additional test in case agenda is invoked from within agenda
  2800. ;; buffer via elisp link
  2801. (unless (equal (current-buffer) abuf)
  2802. (org-pop-to-buffer-same-window abuf)))
  2803. (setq buffer-read-only nil)
  2804. (let ((inhibit-read-only t)) (erase-buffer))
  2805. (org-agenda-mode)
  2806. (and name (not org-agenda-name)
  2807. (org-set-local 'org-agenda-name name)))
  2808. (setq buffer-read-only nil))
  2809. (defun org-finalize-agenda ()
  2810. "Finishing touch for the agenda buffer, called just before displaying it."
  2811. (unless org-agenda-multi
  2812. (save-excursion
  2813. (let ((inhibit-read-only t))
  2814. (goto-char (point-min))
  2815. (while (org-activate-bracket-links (point-max))
  2816. (add-text-properties (match-beginning 0) (match-end 0)
  2817. '(face org-link)))
  2818. (org-agenda-align-tags)
  2819. (unless org-agenda-with-colors
  2820. (remove-text-properties (point-min) (point-max) '(face nil))))
  2821. (if (and (boundp 'org-agenda-overriding-columns-format)
  2822. org-agenda-overriding-columns-format)
  2823. (org-set-local 'org-agenda-overriding-columns-format
  2824. org-agenda-overriding-columns-format))
  2825. (if (and (boundp 'org-agenda-view-columns-initially)
  2826. org-agenda-view-columns-initially)
  2827. (org-agenda-columns))
  2828. (when org-agenda-fontify-priorities
  2829. (org-agenda-fontify-priorities))
  2830. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2831. (org-agenda-dim-blocked-tasks))
  2832. (org-agenda-mark-clocking-task)
  2833. (when org-agenda-entry-text-mode
  2834. (org-agenda-entry-text-hide)
  2835. (org-agenda-entry-text-show))
  2836. (if (functionp 'org-habit-insert-consistency-graphs)
  2837. (org-habit-insert-consistency-graphs))
  2838. (run-hooks 'org-finalize-agenda-hook)
  2839. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2840. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2841. (org-agenda-filter-apply org-agenda-filter))
  2842. )))
  2843. (defun org-agenda-mark-clocking-task ()
  2844. "Mark the current clock entry in the agenda if it is present."
  2845. (mapc (lambda (o)
  2846. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2847. (delete-overlay o)))
  2848. (overlays-in (point-min) (point-max)))
  2849. (when (marker-buffer org-clock-hd-marker)
  2850. (save-excursion
  2851. (goto-char (point-min))
  2852. (let (s ov)
  2853. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2854. (goto-char s)
  2855. (when (equal (org-get-at-bol 'org-hd-marker)
  2856. org-clock-hd-marker)
  2857. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2858. (overlay-put ov 'type 'org-agenda-clocking)
  2859. (overlay-put ov 'face 'org-agenda-clocking)
  2860. (overlay-put ov 'help-echo
  2861. "The clock is running in this item")))))))
  2862. (defun org-agenda-fontify-priorities ()
  2863. "Make highest priority lines bold, and lowest italic."
  2864. (interactive)
  2865. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2866. (delete-overlay o)))
  2867. (overlays-in (point-min) (point-max)))
  2868. (save-excursion
  2869. (let ((inhibit-read-only t)
  2870. b e p ov h l)
  2871. (goto-char (point-min))
  2872. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2873. (setq h (or (get-char-property (point) 'org-highest-priority)
  2874. org-highest-priority)
  2875. l (or (get-char-property (point) 'org-lowest-priority)
  2876. org-lowest-priority)
  2877. p (string-to-char (match-string 1))
  2878. b (match-beginning 0)
  2879. e (if (eq org-agenda-fontify-priorities 'cookies)
  2880. (match-end 0)
  2881. (point-at-eol))
  2882. ov (make-overlay b e))
  2883. (overlay-put
  2884. ov 'face
  2885. (cond ((org-face-from-face-or-color
  2886. 'priority nil
  2887. (cdr (assoc p org-priority-faces))))
  2888. ((and (listp org-agenda-fontify-priorities)
  2889. (org-face-from-face-or-color
  2890. 'priority nil
  2891. (cdr (assoc p org-agenda-fontify-priorities)))))
  2892. ((equal p l) 'italic)
  2893. ((equal p h) 'bold)))
  2894. (overlay-put ov 'org-type 'org-priority)))))
  2895. (defun org-agenda-dim-blocked-tasks ()
  2896. "Dim currently blocked TODO's in the agenda display."
  2897. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2898. (delete-overlay o)))
  2899. (overlays-in (point-min) (point-max)))
  2900. (save-excursion
  2901. (let ((inhibit-read-only t)
  2902. (org-depend-tag-blocked nil)
  2903. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2904. org-blocked-by-checkboxes
  2905. invis1 b e p ov h l)
  2906. (goto-char (point-min))
  2907. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2908. (and pos (goto-char (1+ pos))))
  2909. (setq org-blocked-by-checkboxes nil invis1 invis)
  2910. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2911. (when (and marker
  2912. (not (with-current-buffer (marker-buffer marker)
  2913. (save-excursion
  2914. (goto-char marker)
  2915. (if (org-entry-get nil "NOBLOCKING")
  2916. t ;; Never block this entry
  2917. (run-hook-with-args-until-failure
  2918. 'org-blocker-hook
  2919. (list :type 'todo-state-change
  2920. :position marker
  2921. :from 'todo
  2922. :to 'done)))))))
  2923. (if org-blocked-by-checkboxes (setq invis1 nil))
  2924. (setq b (if invis1
  2925. (max (point-min) (1- (point-at-bol)))
  2926. (point-at-bol))
  2927. e (point-at-eol)
  2928. ov (make-overlay b e))
  2929. (if invis1
  2930. (overlay-put ov 'invisible t)
  2931. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2932. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2933. (defvar org-agenda-skip-function nil
  2934. "Function to be called at each match during agenda construction.
  2935. If this function returns nil, the current match should not be skipped.
  2936. Otherwise, the function must return a position from where the search
  2937. should be continued.
  2938. This may also be a Lisp form, it will be evaluated.
  2939. Never set this variable using `setq' or so, because then it will apply
  2940. to all future agenda commands. If you do want a global skipping condition,
  2941. use the option `org-agenda-skip-function-global' instead.
  2942. The correct usage for `org-agenda-skip-function' is to bind it with
  2943. `let' to scope it dynamically into the agenda-constructing command.
  2944. A good way to set it is through options in `org-agenda-custom-commands'.")
  2945. (defun org-agenda-skip ()
  2946. "Throw to `:skip' in places that should be skipped.
  2947. Also moves point to the end of the skipped region, so that search can
  2948. continue from there."
  2949. (let ((p (point-at-bol)) to)
  2950. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2951. (get-text-property p :org-archived)
  2952. (org-end-of-subtree t)
  2953. (throw :skip t))
  2954. (and org-agenda-skip-comment-trees
  2955. (get-text-property p :org-comment)
  2956. (org-end-of-subtree t)
  2957. (throw :skip t))
  2958. (if (equal (char-after p) ?#) (throw :skip t))
  2959. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2960. (org-agenda-skip-eval org-agenda-skip-function)))
  2961. (goto-char to)
  2962. (throw :skip t))))
  2963. (defun org-agenda-skip-eval (form)
  2964. "If FORM is a function or a list, call (or eval) is and return result.
  2965. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2966. and match data are returned to the previous state no matter what these
  2967. functions do."
  2968. (let (fp)
  2969. (and form
  2970. (or (setq fp (functionp form))
  2971. (consp form))
  2972. (save-excursion
  2973. (save-match-data
  2974. (if fp
  2975. (funcall form)
  2976. (eval form)))))))
  2977. (defvar org-agenda-markers nil
  2978. "List of all currently active markers created by `org-agenda'.")
  2979. (defvar org-agenda-last-marker-time (org-float-time)
  2980. "Creation time of the last agenda marker.")
  2981. (defun org-agenda-new-marker (&optional pos)
  2982. "Return a new agenda marker.
  2983. Org-mode keeps a list of these markers and resets them when they are
  2984. no longer in use."
  2985. (let ((m (copy-marker (or pos (point)))))
  2986. (setq org-agenda-last-marker-time (org-float-time))
  2987. (push m org-agenda-markers)
  2988. m))
  2989. (defun org-agenda-reset-markers ()
  2990. "Reset markers created by `org-agenda'."
  2991. (while org-agenda-markers
  2992. (move-marker (pop org-agenda-markers) nil)))
  2993. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2994. "Save relative positions of markers in region."
  2995. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2996. org-agenda-markers))
  2997. ;;; Entry text mode
  2998. (defun org-agenda-entry-text-show-here ()
  2999. "Add some text from the entry as context to the current line."
  3000. (let (m txt o)
  3001. (setq m (org-get-at-bol 'org-hd-marker))
  3002. (unless (marker-buffer m)
  3003. (error "No marker points to an entry here"))
  3004. (setq txt (concat "\n" (org-no-properties
  3005. (org-agenda-get-some-entry-text
  3006. m org-agenda-entry-text-maxlines " > "))))
  3007. (when (string-match "\\S-" txt)
  3008. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3009. (overlay-put o 'evaporate t)
  3010. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3011. (overlay-put o 'after-string txt))))
  3012. (defun org-agenda-entry-text-show ()
  3013. "Add entry context for all agenda lines."
  3014. (interactive)
  3015. (save-excursion
  3016. (goto-char (point-max))
  3017. (beginning-of-line 1)
  3018. (while (not (bobp))
  3019. (when (org-get-at-bol 'org-hd-marker)
  3020. (org-agenda-entry-text-show-here))
  3021. (beginning-of-line 0))))
  3022. (defun org-agenda-entry-text-hide ()
  3023. "Remove any shown entry context."
  3024. (delq nil
  3025. (mapcar (lambda (o)
  3026. (if (eq (overlay-get o 'org-overlay-type)
  3027. 'agenda-entry-content)
  3028. (progn (delete-overlay o) t)))
  3029. (overlays-in (point-min) (point-max)))))
  3030. (defun org-agenda-get-day-face (date)
  3031. "Return the face DATE should be displayed with."
  3032. (or (and (functionp org-agenda-day-face-function)
  3033. (funcall org-agenda-day-face-function date))
  3034. (cond ((org-agenda-todayp date)
  3035. 'org-agenda-date-today)
  3036. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3037. 'org-agenda-date-weekend)
  3038. (t 'org-agenda-date))))
  3039. ;;; Agenda timeline
  3040. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3041. (defun org-timeline (&optional include-all)
  3042. "Show a time-sorted view of the entries in the current org file.
  3043. Only entries with a time stamp of today or later will be listed. With
  3044. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3045. under the current date.
  3046. If the buffer contains an active region, only check the region for
  3047. dates."
  3048. (interactive "P")
  3049. (org-compile-prefix-format 'timeline)
  3050. (org-set-sorting-strategy 'timeline)
  3051. (let* ((dopast t)
  3052. (dotodo include-all)
  3053. (doclosed org-agenda-show-log)
  3054. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3055. (current-buffer))))
  3056. (date (calendar-current-date))
  3057. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3058. (end (if (org-region-active-p) (region-end) (point-max)))
  3059. (day-numbers (org-get-all-dates beg end 'no-ranges
  3060. t doclosed ; always include today
  3061. org-timeline-show-empty-dates))
  3062. (org-deadline-warning-days 0)
  3063. (org-agenda-only-exact-dates t)
  3064. (today (org-today))
  3065. (past t)
  3066. args
  3067. s e rtn d emptyp)
  3068. (setq org-agenda-redo-command
  3069. (list 'progn
  3070. (list 'org-switch-to-buffer-other-window (current-buffer))
  3071. (list 'org-timeline (list 'quote include-all))))
  3072. (if (not dopast)
  3073. ;; Remove past dates from the list of dates.
  3074. (setq day-numbers (delq nil (mapcar (lambda(x)
  3075. (if (>= x today) x nil))
  3076. day-numbers))))
  3077. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3078. (if doclosed (push :closed args))
  3079. (push :timestamp args)
  3080. (push :deadline args)
  3081. (push :scheduled args)
  3082. (push :sexp args)
  3083. (if dotodo (push :todo args))
  3084. (insert "Timeline of file " entry "\n")
  3085. (add-text-properties (point-min) (point)
  3086. (list 'face 'org-agenda-structure))
  3087. (org-agenda-mark-header-line (point-min))
  3088. (while (setq d (pop day-numbers))
  3089. (if (and (listp d) (eq (car d) :omitted))
  3090. (progn
  3091. (setq s (point))
  3092. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3093. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3094. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3095. (if (and (>= d today)
  3096. dopast
  3097. past)
  3098. (progn
  3099. (setq past nil)
  3100. (insert (make-string 79 ?-) "\n")))
  3101. (setq date (calendar-gregorian-from-absolute d))
  3102. (setq s (point))
  3103. (setq rtn (and (not emptyp)
  3104. (apply 'org-agenda-get-day-entries entry
  3105. date args)))
  3106. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3107. (progn
  3108. (insert
  3109. (if (stringp org-agenda-format-date)
  3110. (format-time-string org-agenda-format-date
  3111. (org-time-from-absolute date))
  3112. (funcall org-agenda-format-date date))
  3113. "\n")
  3114. (put-text-property s (1- (point)) 'face
  3115. (org-agenda-get-day-face date))
  3116. (put-text-property s (1- (point)) 'org-date-line t)
  3117. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3118. (if (equal d today)
  3119. (put-text-property s (1- (point)) 'org-today t))
  3120. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3121. (put-text-property s (1- (point)) 'day d)))))
  3122. (goto-char (point-min))
  3123. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3124. (point-min)))
  3125. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3126. (org-finalize-agenda)
  3127. (setq buffer-read-only t)))
  3128. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3129. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3130. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3131. not every single day in the range. If FORCE-TODAY is non-nil, make
  3132. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3133. inactive time stamps (those in square brackets) are included.
  3134. When EMPTY is non-nil, also include days without any entries."
  3135. (let ((re (concat
  3136. (if pre-re pre-re "")
  3137. (if inactive org-ts-regexp-both org-ts-regexp)))
  3138. dates dates1 date day day1 day2 ts1 ts2)
  3139. (if force-today
  3140. (setq dates (list (org-today))))
  3141. (save-excursion
  3142. (goto-char beg)
  3143. (while (re-search-forward re end t)
  3144. (setq day (time-to-days (org-time-string-to-time
  3145. (substring (match-string 1) 0 10))))
  3146. (or (memq day dates) (push day dates)))
  3147. (unless no-ranges
  3148. (goto-char beg)
  3149. (while (re-search-forward org-tr-regexp end t)
  3150. (setq ts1 (substring (match-string 1) 0 10)
  3151. ts2 (substring (match-string 2) 0 10)
  3152. day1 (time-to-days (org-time-string-to-time ts1))
  3153. day2 (time-to-days (org-time-string-to-time ts2)))
  3154. (while (< (setq day1 (1+ day1)) day2)
  3155. (or (memq day1 dates) (push day1 dates)))))
  3156. (setq dates (sort dates '<))
  3157. (when empty
  3158. (while (setq day (pop dates))
  3159. (setq day2 (car dates))
  3160. (push day dates1)
  3161. (when (and day2 empty)
  3162. (if (or (eq empty t)
  3163. (and (numberp empty) (<= (- day2 day) empty)))
  3164. (while (< (setq day (1+ day)) day2)
  3165. (push (list day) dates1))
  3166. (push (cons :omitted (- day2 day)) dates1))))
  3167. (setq dates (nreverse dates1)))
  3168. dates)))
  3169. ;;; Agenda Daily/Weekly
  3170. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3171. "Start day for the agenda view.
  3172. Custom commands can set this variable in the options section.")
  3173. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3174. (defvar org-agenda-current-span nil
  3175. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3176. (defvar org-include-all-loc nil) ; local variable
  3177. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3178. "List of types searched for when creating the daily/weekly agenda.
  3179. This variable is a list of symbols that controls the types of
  3180. items that appear in the daily/weekly agenda. Allowed symbols in this
  3181. list are are
  3182. :timestamp List items containing a date stamp or date range matching
  3183. the selected date. This includes sexp entries in
  3184. angular brackets.
  3185. :sexp List entries resulting from plain diary-like sexps.
  3186. :deadline List deadline due on that date. When the date is today,
  3187. also list any deadlines past due, or due within
  3188. `org-deadline-warning-days'. `:deadline' must appear before
  3189. `:scheduled' if the setting of
  3190. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3191. any effect.
  3192. :scheduled List all items which are scheduled for the given date.
  3193. The diary for *today* also contains items which were
  3194. scheduled earlier and are not yet marked DONE.
  3195. By default, all four types are turned on.
  3196. Never set this variable globally using `setq', because then it
  3197. will apply to all future agenda commands. Instead, bind it with
  3198. `let' to scope it dynamically into the agenda-constructing
  3199. command. A good way to set it is through options in
  3200. `org-agenda-custom-commands'. For a more flexible (though
  3201. somewhat less efficient) way of determining what is included in
  3202. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3203. ;;;###autoload
  3204. (defun org-agenda-list (&optional include-all start-day span)
  3205. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3206. The view will be for the current day or week, but from the overview buffer
  3207. you will be able to go to other days/weeks.
  3208. With a numeric prefix argument in an interactive call, the agenda will
  3209. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3210. the number of days. SPAN defaults to `org-agenda-span'.
  3211. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3212. given in `org-agenda-start-on-weekday'."
  3213. (interactive "P")
  3214. (if (and (integerp include-all) (> include-all 0))
  3215. (setq span include-all include-all nil))
  3216. (setq start-day (or start-day org-agenda-start-day))
  3217. (if org-agenda-overriding-arguments
  3218. (setq include-all (car org-agenda-overriding-arguments)
  3219. start-day (nth 1 org-agenda-overriding-arguments)
  3220. span (nth 2 org-agenda-overriding-arguments)))
  3221. (if (stringp start-day)
  3222. ;; Convert to an absolute day number
  3223. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3224. (setq org-agenda-last-arguments (list include-all start-day span))
  3225. (org-compile-prefix-format 'agenda)
  3226. (org-set-sorting-strategy 'agenda)
  3227. (let* ((span (org-agenda-ndays-to-span
  3228. (or span org-agenda-ndays org-agenda-span)))
  3229. (today (org-today))
  3230. (sd (or start-day today))
  3231. (ndays (org-agenda-span-to-ndays span sd))
  3232. (org-agenda-start-on-weekday
  3233. (if (eq ndays 7)
  3234. org-agenda-start-on-weekday))
  3235. (thefiles (org-agenda-files nil 'ifmode))
  3236. (files thefiles)
  3237. (start (if (or (null org-agenda-start-on-weekday)
  3238. (< ndays 7))
  3239. sd
  3240. (let* ((nt (calendar-day-of-week
  3241. (calendar-gregorian-from-absolute sd)))
  3242. (n1 org-agenda-start-on-weekday)
  3243. (d (- nt n1)))
  3244. (- sd (+ (if (< d 0) 7 0) d)))))
  3245. (day-numbers (list start))
  3246. (day-cnt 0)
  3247. (inhibit-redisplay (not debug-on-error))
  3248. s e rtn rtnall file date d start-pos end-pos todayp
  3249. clocktable-start clocktable-end filter)
  3250. (setq org-agenda-redo-command
  3251. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3252. (dotimes (n (1- ndays))
  3253. (push (1+ (car day-numbers)) day-numbers))
  3254. (setq day-numbers (nreverse day-numbers))
  3255. (setq clocktable-start (car day-numbers)
  3256. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3257. (org-prepare-agenda "Day/Week")
  3258. (org-set-local 'org-starting-day (car day-numbers))
  3259. (org-set-local 'org-include-all-loc include-all)
  3260. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3261. (unless org-agenda-compact-blocks
  3262. (let* ((d1 (car day-numbers))
  3263. (d2 (org-last day-numbers))
  3264. (w1 (org-days-to-iso-week d1))
  3265. (w2 (org-days-to-iso-week d2)))
  3266. (setq s (point))
  3267. (if org-agenda-overriding-header
  3268. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3269. nil 'face 'org-agenda-structure) "\n")
  3270. (insert (org-agenda-span-name span)
  3271. "-agenda"
  3272. (if (< (- d2 d1) 350)
  3273. (if (= w1 w2)
  3274. (format " (W%02d)" w1)
  3275. (format " (W%02d-W%02d)" w1 w2))
  3276. "")
  3277. ":\n")))
  3278. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3279. 'org-date-line t))
  3280. (org-agenda-mark-header-line s))
  3281. (while (setq d (pop day-numbers))
  3282. (setq date (calendar-gregorian-from-absolute d)
  3283. s (point))
  3284. (if (or (setq todayp (= d today))
  3285. (and (not start-pos) (= d sd)))
  3286. (setq start-pos (point))
  3287. (if (and start-pos (not end-pos))
  3288. (setq end-pos (point))))
  3289. (setq files thefiles
  3290. rtnall nil)
  3291. (while (setq file (pop files))
  3292. (catch 'nextfile
  3293. (org-check-agenda-file file)
  3294. (let ((org-agenda-entry-types org-agenda-entry-types))
  3295. (unless org-agenda-include-deadlines
  3296. (setq org-agenda-entry-types
  3297. (delq :deadline org-agenda-entry-types)))
  3298. (cond
  3299. ((memq org-agenda-show-log '(only clockcheck))
  3300. (setq rtn (org-agenda-get-day-entries
  3301. file date :closed)))
  3302. (org-agenda-show-log
  3303. (setq rtn (apply 'org-agenda-get-day-entries
  3304. file date
  3305. (append '(:closed) org-agenda-entry-types))))
  3306. (t
  3307. (setq rtn (apply 'org-agenda-get-day-entries
  3308. file date
  3309. org-agenda-entry-types)))))
  3310. (setq rtnall (append rtnall rtn))))
  3311. (if org-agenda-include-diary
  3312. (let ((org-agenda-search-headline-for-time t))
  3313. (require 'diary-lib)
  3314. (setq rtn (org-get-entries-from-diary date))
  3315. (setq rtnall (append rtnall rtn))))
  3316. (if (or rtnall org-agenda-show-all-dates)
  3317. (progn
  3318. (setq day-cnt (1+ day-cnt))
  3319. (insert
  3320. (if (stringp org-agenda-format-date)
  3321. (format-time-string org-agenda-format-date
  3322. (org-time-from-absolute date))
  3323. (funcall org-agenda-format-date date))
  3324. "\n")
  3325. (put-text-property s (1- (point)) 'face
  3326. (org-agenda-get-day-face date))
  3327. (put-text-property s (1- (point)) 'org-date-line t)
  3328. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3329. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3330. (when todayp
  3331. (put-text-property s (1- (point)) 'org-today t))
  3332. (if rtnall (insert
  3333. (org-finalize-agenda-entries
  3334. (org-agenda-add-time-grid-maybe
  3335. rtnall ndays todayp))
  3336. "\n"))
  3337. (put-text-property s (1- (point)) 'day d)
  3338. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3339. (when (and org-agenda-clockreport-mode clocktable-start)
  3340. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3341. ;; the above line is to ensure the restricted range!
  3342. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3343. tbl)
  3344. (setq p (org-plist-delete p :block))
  3345. (setq p (plist-put p :tstart clocktable-start))
  3346. (setq p (plist-put p :tend clocktable-end))
  3347. (setq p (plist-put p :scope 'agenda))
  3348. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3349. (setq filter (or org-agenda-filter-while-redo
  3350. (get 'org-agenda-filter :preset-filter))))
  3351. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3352. (if (string-match "[<>=]" x)
  3353. ""
  3354. x))
  3355. filter ""))))
  3356. (setq tbl (apply 'org-get-clocktable p))
  3357. (insert tbl)))
  3358. (goto-char (point-min))
  3359. (or org-agenda-multi (org-fit-agenda-window))
  3360. (unless (and (pos-visible-in-window-p (point-min))
  3361. (pos-visible-in-window-p (point-max)))
  3362. (goto-char (1- (point-max)))
  3363. (recenter -1)
  3364. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3365. (progn
  3366. (goto-char (or start-pos 1))
  3367. (recenter 1))))
  3368. (goto-char (or start-pos 1))
  3369. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3370. (if (eq org-agenda-show-log 'clockcheck)
  3371. (org-agenda-show-clocking-issues))
  3372. (org-finalize-agenda)
  3373. (setq buffer-read-only t)
  3374. (message "")))
  3375. (defun org-agenda-ndays-to-span (n)
  3376. "Return a span symbol for a span of N days, or N if none matches."
  3377. (cond ((symbolp n) n)
  3378. ((= n 1) 'day)
  3379. ((= n 7) 'week)
  3380. (t n)))
  3381. (defun org-agenda-span-to-ndays (span start-day)
  3382. "Return ndays from SPAN starting at START-DAY."
  3383. (cond ((numberp span) span)
  3384. ((eq span 'day) 1)
  3385. ((eq span 'week) 7)
  3386. ((eq span 'month)
  3387. (let ((date (calendar-gregorian-from-absolute start-day)))
  3388. (calendar-last-day-of-month (car date) (caddr date))))
  3389. ((eq span 'year)
  3390. (let ((date (calendar-gregorian-from-absolute start-day)))
  3391. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3392. (defun org-agenda-span-name (span)
  3393. "Return a SPAN name."
  3394. (if (null span)
  3395. ""
  3396. (if (symbolp span)
  3397. (capitalize (symbol-name span))
  3398. (format "%d days" span))))
  3399. ;;; Agenda word search
  3400. (defvar org-agenda-search-history nil)
  3401. (defvar org-todo-only nil)
  3402. (defvar org-search-syntax-table nil
  3403. "Special syntax table for org-mode search.
  3404. In this table, we have single quotes not as word constituents, to
  3405. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3406. (defun org-search-syntax-table ()
  3407. (unless org-search-syntax-table
  3408. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3409. (modify-syntax-entry ?' "." org-search-syntax-table)
  3410. (modify-syntax-entry ?` "." org-search-syntax-table))
  3411. org-search-syntax-table)
  3412. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3413. ;;;###autoload
  3414. (defun org-search-view (&optional todo-only string edit-at)
  3415. "Show all entries that contain a phrase or words or regular expressions.
  3416. With optional prefix argument TODO-ONLY, only consider entries that are
  3417. TODO entries. The argument STRING can be used to pass a default search
  3418. string into this function. If EDIT-AT is non-nil, it means that the
  3419. user should get a chance to edit this string, with cursor at position
  3420. EDIT-AT.
  3421. The search string can be viewed either as a phrase that should be found as
  3422. is, or it can be broken into a number of snippets, each of which must match
  3423. in a Boolean way to select an entry. The default depends on the variable
  3424. `org-agenda-search-view-always-boolean'.
  3425. Even if this is turned off (the default) you can always switch to
  3426. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3427. The default is a direct search of the whole phrase, where each space in
  3428. the search string can expand to an arbitrary amount of whitespace,
  3429. including newlines.
  3430. If using a Boolean search, the search string is split on whitespace and
  3431. each snippet is searched separately, with logical AND to select an entry.
  3432. Words prefixed with a minus must *not* occur in the entry. Words without
  3433. a prefix or prefixed with a plus must occur in the entry. Matching is
  3434. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3435. match whole words, not parts of a word) if
  3436. `org-agenda-search-view-force-full-words' is set (default is nil).
  3437. Boolean search snippets enclosed by curly braces are interpreted as
  3438. regular expressions that must or (when preceded with \"-\") must not
  3439. match in the entry. Snippets enclosed into double quotes will be taken
  3440. as a whole, to include whitespace.
  3441. - If the search string starts with an asterisk, search only in headlines.
  3442. - If (possibly after the leading star) the search string starts with an
  3443. exclamation mark, this also means to look at TODO entries only, an effect
  3444. that can also be achieved with a prefix argument.
  3445. - If (possibly after star and exclamation mark) the search string starts
  3446. with a colon, this will mean that the (non-regexp) snippets of the
  3447. Boolean search must match as full words.
  3448. This command searches the agenda files, and in addition the files listed
  3449. in `org-agenda-text-search-extra-files'."
  3450. (interactive "P")
  3451. (org-compile-prefix-format 'search)
  3452. (org-set-sorting-strategy 'search)
  3453. (org-prepare-agenda "SEARCH")
  3454. (let* ((props (list 'face nil
  3455. 'done-face 'org-agenda-done
  3456. 'org-not-done-regexp org-not-done-regexp
  3457. 'org-todo-regexp org-todo-regexp
  3458. 'org-complex-heading-regexp org-complex-heading-regexp
  3459. 'mouse-face 'highlight
  3460. 'help-echo (format "mouse-2 or RET jump to location")))
  3461. (full-words org-agenda-search-view-force-full-words)
  3462. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3463. regexp rtn rtnall files file pos
  3464. marker category tags c neg re boolean
  3465. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3466. (unless (and (not edit-at)
  3467. (stringp string)
  3468. (string-match "\\S-" string))
  3469. (setq string (read-string
  3470. (if org-agenda-search-view-always-boolean
  3471. "[+-]Word/{Regexp} ...: "
  3472. "Phrase, or [+-]Word/{Regexp} ...: ")
  3473. (cond
  3474. ((integerp edit-at) (cons string edit-at))
  3475. (edit-at string))
  3476. 'org-agenda-search-history)))
  3477. (org-set-local 'org-todo-only todo-only)
  3478. (setq org-agenda-redo-command
  3479. (list 'org-search-view (if todo-only t nil) string
  3480. '(if current-prefix-arg 1 nil)))
  3481. (setq org-agenda-query-string string)
  3482. (if (equal (string-to-char string) ?*)
  3483. (setq hdl-only t
  3484. words (substring string 1))
  3485. (setq words string))
  3486. (when (equal (string-to-char words) ?!)
  3487. (setq todo-only t
  3488. words (substring words 1)))
  3489. (when (equal (string-to-char words) ?:)
  3490. (setq full-words t
  3491. words (substring words 1)))
  3492. (if (or org-agenda-search-view-always-boolean
  3493. (member (string-to-char words) '(?- ?+ ?\{)))
  3494. (setq boolean t))
  3495. (setq words (org-split-string words))
  3496. (let (www w)
  3497. (while (setq w (pop words))
  3498. (while (and (string-match "\\\\\\'" w) words)
  3499. (setq w (concat (substring w 0 -1) " " (pop words))))
  3500. (push w www))
  3501. (setq words (nreverse www) www nil)
  3502. (while (setq w (pop words))
  3503. (when (and (string-match "\\`[-+]?{" w)
  3504. (not (string-match "}\\'" w)))
  3505. (while (and words (not (string-match "}\\'" (car words))))
  3506. (setq w (concat w " " (pop words))))
  3507. (setq w (concat w " " (pop words))))
  3508. (push w www))
  3509. (setq words (nreverse www)))
  3510. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3511. (when boolean
  3512. (let (wds w)
  3513. (while (setq w (pop words))
  3514. (if (or (equal (substring w 0 1) "\"")
  3515. (and (> (length w) 1)
  3516. (member (substring w 0 1) '("+" "-"))
  3517. (equal (substring w 1 2) "\"")))
  3518. (while (and words (not (equal (substring w -1) "\"")))
  3519. (setq w (concat w " " (pop words)))))
  3520. (and (string-match "\\`\\([-+]?\\)\"" w)
  3521. (setq w (replace-match "\\1" nil nil w)))
  3522. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3523. (push w wds))
  3524. (setq words (nreverse wds))))
  3525. (if boolean
  3526. (mapc (lambda (w)
  3527. (setq c (string-to-char w))
  3528. (if (equal c ?-)
  3529. (setq neg t w (substring w 1))
  3530. (if (equal c ?+)
  3531. (setq neg nil w (substring w 1))
  3532. (setq neg nil)))
  3533. (if (string-match "\\`{.*}\\'" w)
  3534. (setq re (substring w 1 -1))
  3535. (if full-words
  3536. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3537. (setq re (regexp-quote (downcase w)))))
  3538. (if neg (push re regexps-) (push re regexps+)))
  3539. words)
  3540. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3541. regexps+))
  3542. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3543. (if (not regexps+)
  3544. (setq regexp org-outline-regexp-bol)
  3545. (setq regexp (pop regexps+))
  3546. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3547. regexp))))
  3548. (setq files (org-agenda-files nil 'ifmode))
  3549. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3550. (pop org-agenda-text-search-extra-files)
  3551. (setq files (org-add-archive-files files)))
  3552. (setq files (append files org-agenda-text-search-extra-files)
  3553. rtnall nil)
  3554. (while (setq file (pop files))
  3555. (setq ee nil)
  3556. (catch 'nextfile
  3557. (org-check-agenda-file file)
  3558. (setq buffer (if (file-exists-p file)
  3559. (org-get-agenda-file-buffer file)
  3560. (error "No such file %s" file)))
  3561. (if (not buffer)
  3562. ;; If file does not exist, make sure an error message is sent
  3563. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3564. file))))
  3565. (with-current-buffer buffer
  3566. (with-syntax-table (org-search-syntax-table)
  3567. (unless (org-mode-p)
  3568. (error "Agenda file %s is not in `org-mode'" file))
  3569. (let ((case-fold-search t))
  3570. (save-excursion
  3571. (save-restriction
  3572. (if org-agenda-restrict
  3573. (narrow-to-region org-agenda-restrict-begin
  3574. org-agenda-restrict-end)
  3575. (widen))
  3576. (goto-char (point-min))
  3577. (unless (or (org-on-heading-p)
  3578. (outline-next-heading))
  3579. (throw 'nextfile t))
  3580. (goto-char (max (point-min) (1- (point))))
  3581. (while (re-search-forward regexp nil t)
  3582. (org-back-to-heading t)
  3583. (skip-chars-forward "* ")
  3584. (setq beg (point-at-bol)
  3585. beg1 (point)
  3586. end (progn (outline-next-heading) (point)))
  3587. (catch :skip
  3588. (goto-char beg)
  3589. (org-agenda-skip)
  3590. (setq str (buffer-substring-no-properties
  3591. (point-at-bol)
  3592. (if hdl-only (point-at-eol) end)))
  3593. (mapc (lambda (wr) (when (string-match wr str)
  3594. (goto-char (1- end))
  3595. (throw :skip t)))
  3596. regexps-)
  3597. (mapc (lambda (wr) (unless (string-match wr str)
  3598. (goto-char (1- end))
  3599. (throw :skip t)))
  3600. (if todo-only
  3601. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3602. regexps+)
  3603. regexps+))
  3604. (goto-char beg)
  3605. (setq marker (org-agenda-new-marker (point))
  3606. category (org-get-category)
  3607. tags (org-get-tags-at (point))
  3608. txt (org-format-agenda-item
  3609. ""
  3610. (buffer-substring-no-properties
  3611. beg1 (point-at-eol))
  3612. category tags))
  3613. (org-add-props txt props
  3614. 'org-marker marker 'org-hd-marker marker
  3615. 'org-todo-regexp org-todo-regexp
  3616. 'org-complex-heading-regexp org-complex-heading-regexp
  3617. 'priority 1000 'org-category category
  3618. 'type "search")
  3619. (push txt ee)
  3620. (goto-char (1- end))))))))))
  3621. (setq rtn (nreverse ee))
  3622. (setq rtnall (append rtnall rtn)))
  3623. (if org-agenda-overriding-header
  3624. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3625. nil 'face 'org-agenda-structure) "\n")
  3626. (insert "Search words: ")
  3627. (add-text-properties (point-min) (1- (point))
  3628. (list 'face 'org-agenda-structure))
  3629. (setq pos (point))
  3630. (insert string "\n")
  3631. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3632. (setq pos (point))
  3633. (unless org-agenda-multi
  3634. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3635. (add-text-properties pos (1- (point))
  3636. (list 'face 'org-agenda-structure))))
  3637. (org-agenda-mark-header-line (point-min))
  3638. (when rtnall
  3639. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3640. (goto-char (point-min))
  3641. (or org-agenda-multi (org-fit-agenda-window))
  3642. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3643. (org-finalize-agenda)
  3644. (setq buffer-read-only t)))
  3645. ;;; Agenda TODO list
  3646. (defvar org-select-this-todo-keyword nil)
  3647. (defvar org-last-arg nil)
  3648. ;;;###autoload
  3649. (defun org-todo-list (arg)
  3650. "Show all (not done) TODO entries from all agenda file in a single list.
  3651. The prefix arg can be used to select a specific TODO keyword and limit
  3652. the list to these. When using \\[universal-argument], you will be prompted
  3653. for a keyword. A numeric prefix directly selects the Nth keyword in
  3654. `org-todo-keywords-1'."
  3655. (interactive "P")
  3656. (org-compile-prefix-format 'todo)
  3657. (org-set-sorting-strategy 'todo)
  3658. (org-prepare-agenda "TODO")
  3659. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3660. (let* ((today (org-today))
  3661. (date (calendar-gregorian-from-absolute today))
  3662. (kwds org-todo-keywords-for-agenda)
  3663. (completion-ignore-case t)
  3664. (org-select-this-todo-keyword
  3665. (if (stringp arg) arg
  3666. (and arg (integerp arg) (> arg 0)
  3667. (nth (1- arg) kwds))))
  3668. rtn rtnall files file pos)
  3669. (when (equal arg '(4))
  3670. (setq org-select-this-todo-keyword
  3671. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3672. (mapcar 'list kwds) nil nil)))
  3673. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3674. (org-set-local 'org-last-arg arg)
  3675. (setq org-agenda-redo-command
  3676. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3677. (setq files (org-agenda-files nil 'ifmode)
  3678. rtnall nil)
  3679. (while (setq file (pop files))
  3680. (catch 'nextfile
  3681. (org-check-agenda-file file)
  3682. (setq rtn (org-agenda-get-day-entries file date :todo))
  3683. (setq rtnall (append rtnall rtn))))
  3684. (if org-agenda-overriding-header
  3685. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3686. nil 'face 'org-agenda-structure) "\n")
  3687. (insert "Global list of TODO items of type: ")
  3688. (add-text-properties (point-min) (1- (point))
  3689. (list 'face 'org-agenda-structure
  3690. 'short-heading
  3691. (concat "ToDo: "
  3692. (or org-select-this-todo-keyword "ALL"))))
  3693. (org-agenda-mark-header-line (point-min))
  3694. (setq pos (point))
  3695. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3696. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3697. (setq pos (point))
  3698. (unless org-agenda-multi
  3699. (insert "Available with `N r': (0)ALL")
  3700. (let ((n 0) s)
  3701. (mapc (lambda (x)
  3702. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3703. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3704. (insert "\n "))
  3705. (insert " " s))
  3706. kwds))
  3707. (insert "\n"))
  3708. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3709. (org-agenda-mark-header-line (point-min))
  3710. (when rtnall
  3711. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3712. (goto-char (point-min))
  3713. (or org-agenda-multi (org-fit-agenda-window))
  3714. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3715. (org-finalize-agenda)
  3716. (setq buffer-read-only t)))
  3717. ;;; Agenda tags match
  3718. ;;;###autoload
  3719. (defun org-tags-view (&optional todo-only match)
  3720. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3721. The prefix arg TODO-ONLY limits the search to TODO entries."
  3722. (interactive "P")
  3723. (org-compile-prefix-format 'tags)
  3724. (org-set-sorting-strategy 'tags)
  3725. (let* ((org-tags-match-list-sublevels
  3726. org-tags-match-list-sublevels)
  3727. (completion-ignore-case t)
  3728. rtn rtnall files file pos matcher
  3729. buffer)
  3730. (when (and (stringp match) (not (string-match "\\S-" match)))
  3731. (setq match nil))
  3732. (setq matcher (org-make-tags-matcher match)
  3733. match (car matcher) matcher (cdr matcher))
  3734. (org-prepare-agenda (concat "TAGS " match))
  3735. (setq org-agenda-query-string match)
  3736. (setq org-agenda-redo-command
  3737. (list 'org-tags-view (list 'quote todo-only)
  3738. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3739. (setq files (org-agenda-files nil 'ifmode)
  3740. rtnall nil)
  3741. (while (setq file (pop files))
  3742. (catch 'nextfile
  3743. (org-check-agenda-file file)
  3744. (setq buffer (if (file-exists-p file)
  3745. (org-get-agenda-file-buffer file)
  3746. (error "No such file %s" file)))
  3747. (if (not buffer)
  3748. ;; If file does not exist, error message to agenda
  3749. (setq rtn (list
  3750. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3751. rtnall (append rtnall rtn))
  3752. (with-current-buffer buffer
  3753. (unless (org-mode-p)
  3754. (error "Agenda file %s is not in `org-mode'" file))
  3755. (save-excursion
  3756. (save-restriction
  3757. (if org-agenda-restrict
  3758. (narrow-to-region org-agenda-restrict-begin
  3759. org-agenda-restrict-end)
  3760. (widen))
  3761. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3762. (setq rtnall (append rtnall rtn))))))))
  3763. (if org-agenda-overriding-header
  3764. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3765. nil 'face 'org-agenda-structure) "\n")
  3766. (insert "Headlines with TAGS match: ")
  3767. (add-text-properties (point-min) (1- (point))
  3768. (list 'face 'org-agenda-structure
  3769. 'short-heading
  3770. (concat "Match: " match)))
  3771. (setq pos (point))
  3772. (insert match "\n")
  3773. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3774. (setq pos (point))
  3775. (unless org-agenda-multi
  3776. (insert "Press `C-u r' to search again with new search string\n"))
  3777. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3778. (org-agenda-mark-header-line (point-min))
  3779. (when rtnall
  3780. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3781. (goto-char (point-min))
  3782. (or org-agenda-multi (org-fit-agenda-window))
  3783. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3784. (org-finalize-agenda)
  3785. (setq buffer-read-only t)))
  3786. ;;; Agenda Finding stuck projects
  3787. (defvar org-agenda-skip-regexp nil
  3788. "Regular expression used in skipping subtrees for the agenda.
  3789. This is basically a temporary global variable that can be set and then
  3790. used by user-defined selections using `org-agenda-skip-function'.")
  3791. (defvar org-agenda-overriding-header nil
  3792. "When set during agenda, todo and tags searches it replaces the header.
  3793. This variable should not be set directly, but custom commands can bind it
  3794. in the options section.")
  3795. (defun org-agenda-skip-entry-when-regexp-matches ()
  3796. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3797. If yes, it returns the end position of this entry, causing agenda commands
  3798. to skip the entry but continuing the search in the subtree. This is a
  3799. function that can be put into `org-agenda-skip-function' for the duration
  3800. of a command."
  3801. (let ((end (save-excursion (org-end-of-subtree t)))
  3802. skip)
  3803. (save-excursion
  3804. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3805. (and skip end)))
  3806. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3807. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3808. If yes, it returns the end position of this tree, causing agenda commands
  3809. to skip this subtree. This is a function that can be put into
  3810. `org-agenda-skip-function' for the duration of a command."
  3811. (let ((end (save-excursion (org-end-of-subtree t)))
  3812. skip)
  3813. (save-excursion
  3814. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3815. (and skip end)))
  3816. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3817. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3818. If yes, it returns the end position of the current entry (NOT the tree),
  3819. causing agenda commands to skip the entry but continuing the search in
  3820. the subtree. This is a function that can be put into
  3821. `org-agenda-skip-function' for the duration of a command. An important
  3822. use of this function is for the stuck project list."
  3823. (let ((end (save-excursion (org-end-of-subtree t)))
  3824. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3825. skip)
  3826. (save-excursion
  3827. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3828. (and skip entry-end)))
  3829. (defun org-agenda-skip-entry-if (&rest conditions)
  3830. "Skip entry if any of CONDITIONS is true.
  3831. See `org-agenda-skip-if' for details."
  3832. (org-agenda-skip-if nil conditions))
  3833. (defun org-agenda-skip-subtree-if (&rest conditions)
  3834. "Skip entry if any of CONDITIONS is true.
  3835. See `org-agenda-skip-if' for details."
  3836. (org-agenda-skip-if t conditions))
  3837. (defun org-agenda-skip-if (subtree conditions)
  3838. "Checks current entity for CONDITIONS.
  3839. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3840. the entry, i.e. the text before the next heading is checked.
  3841. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3842. from different tests. Valid conditions are:
  3843. scheduled Check if there is a scheduled cookie
  3844. notscheduled Check if there is no scheduled cookie
  3845. deadline Check if there is a deadline
  3846. notdeadline Check if there is no deadline
  3847. timestamp Check if there is a timestamp (also deadline or scheduled)
  3848. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3849. regexp Check if regexp matches
  3850. notregexp Check if regexp does not match.
  3851. todo Check if TODO keyword matches
  3852. nottodo Check if TODO keyword does not match
  3853. The regexp is taken from the conditions list, it must come right after
  3854. the `regexp' or `notregexp' element.
  3855. `todo' and `nottodo' accept as an argument a list of todo
  3856. keywords, which may include \"*\" to match any todo keyword.
  3857. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3858. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3859. Instead of a list a keyword class may be given
  3860. (org-agenda-skip-entry-if 'nottodo 'done)
  3861. would skip entries that haven't been marked with any of \"DONE\"
  3862. keywords. Possible classes are: `todo', `done', `any'.
  3863. If any of these conditions is met, this function returns the end point of
  3864. the entity, causing the search to continue from there. This is a function
  3865. that can be put into `org-agenda-skip-function' for the duration of a command."
  3866. (let (beg end m)
  3867. (org-back-to-heading t)
  3868. (setq beg (point)
  3869. end (if subtree
  3870. (progn (org-end-of-subtree t) (point))
  3871. (progn (outline-next-heading) (1- (point)))))
  3872. (goto-char beg)
  3873. (and
  3874. (or
  3875. (and (memq 'scheduled conditions)
  3876. (re-search-forward org-scheduled-time-regexp end t))
  3877. (and (memq 'notscheduled conditions)
  3878. (not (re-search-forward org-scheduled-time-regexp end t)))
  3879. (and (memq 'deadline conditions)
  3880. (re-search-forward org-deadline-time-regexp end t))
  3881. (and (memq 'notdeadline conditions)
  3882. (not (re-search-forward org-deadline-time-regexp end t)))
  3883. (and (memq 'timestamp conditions)
  3884. (re-search-forward org-ts-regexp end t))
  3885. (and (memq 'nottimestamp conditions)
  3886. (not (re-search-forward org-ts-regexp end t)))
  3887. (and (setq m (memq 'regexp conditions))
  3888. (stringp (nth 1 m))
  3889. (re-search-forward (nth 1 m) end t))
  3890. (and (setq m (memq 'notregexp conditions))
  3891. (stringp (nth 1 m))
  3892. (not (re-search-forward (nth 1 m) end t)))
  3893. (and (or
  3894. (setq m (memq 'todo conditions))
  3895. (setq m (memq 'nottodo conditions)))
  3896. (org-agenda-skip-if-todo m end)))
  3897. end)))
  3898. (defun org-agenda-skip-if-todo (args end)
  3899. "Helper function for `org-agenda-skip-if', do not use it directly.
  3900. ARGS is a list with first element either `todo' or `nottodo'.
  3901. The remainder is either a list of TODO keywords, or a state symbol
  3902. `todo' or `done' or `any'."
  3903. (let ((kw (car args))
  3904. (arg (cadr args))
  3905. todo-wds todo-re)
  3906. (setq todo-wds
  3907. (org-uniquify
  3908. (cond
  3909. ((listp arg) ;; list of keywords
  3910. (if (member "*" arg)
  3911. (mapcar 'substring-no-properties org-todo-keywords-1)
  3912. arg))
  3913. ((symbolp arg) ;; keyword class name
  3914. (cond
  3915. ((eq arg 'todo)
  3916. (org-delete-all org-done-keywords
  3917. (mapcar 'substring-no-properties
  3918. org-todo-keywords-1)))
  3919. ((eq arg 'done) org-done-keywords)
  3920. ((eq arg 'any)
  3921. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3922. (setq todo-re
  3923. (concat "^\\*+[ \t]+\\<\\("
  3924. (mapconcat 'identity todo-wds "\\|")
  3925. "\\)\\>"))
  3926. (if (eq kw 'todo)
  3927. (re-search-forward todo-re end t)
  3928. (not (re-search-forward todo-re end t)))))
  3929. ;;;###autoload
  3930. (defun org-agenda-list-stuck-projects (&rest ignore)
  3931. "Create agenda view for projects that are stuck.
  3932. Stuck projects are project that have no next actions. For the definitions
  3933. of what a project is and how to check if it stuck, customize the variable
  3934. `org-stuck-projects'."
  3935. (interactive)
  3936. (let* ((org-agenda-skip-function
  3937. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3938. ;; We could have used org-agenda-skip-if here.
  3939. (org-agenda-overriding-header
  3940. (or org-agenda-overriding-header "List of stuck projects: "))
  3941. (matcher (nth 0 org-stuck-projects))
  3942. (todo (nth 1 org-stuck-projects))
  3943. (todo-wds (if (member "*" todo)
  3944. (progn
  3945. (org-prepare-agenda-buffers (org-agenda-files
  3946. nil 'ifmode))
  3947. (org-delete-all
  3948. org-done-keywords-for-agenda
  3949. (copy-sequence org-todo-keywords-for-agenda)))
  3950. todo))
  3951. (todo-re (concat "^\\*+[ \t]+\\("
  3952. (mapconcat 'identity todo-wds "\\|")
  3953. "\\)\\>"))
  3954. (tags (nth 2 org-stuck-projects))
  3955. (tags-re (if (member "*" tags)
  3956. (org-re (concat org-outline-regexp-bol
  3957. ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3958. (if tags
  3959. (concat org-outline-regexp-bol
  3960. ".*:\\("
  3961. (mapconcat 'identity tags "\\|")
  3962. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3963. (gen-re (nth 3 org-stuck-projects))
  3964. (re-list
  3965. (delq nil
  3966. (list
  3967. (if todo todo-re)
  3968. (if tags tags-re)
  3969. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3970. gen-re)))))
  3971. (setq org-agenda-skip-regexp
  3972. (if re-list
  3973. (mapconcat 'identity re-list "\\|")
  3974. (error "No information how to identify unstuck projects")))
  3975. (org-tags-view nil matcher)
  3976. (with-current-buffer org-agenda-buffer-name
  3977. (setq org-agenda-redo-command
  3978. '(org-agenda-list-stuck-projects
  3979. (or current-prefix-arg org-last-arg))))))
  3980. ;;; Diary integration
  3981. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3982. (defvar list-diary-entries-hook)
  3983. (defvar diary-time-regexp)
  3984. (defun org-get-entries-from-diary (date)
  3985. "Get the (Emacs Calendar) diary entries for DATE."
  3986. (require 'diary-lib)
  3987. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3988. (diary-display-hook '(fancy-diary-display))
  3989. (diary-display-function 'fancy-diary-display)
  3990. (pop-up-frames nil)
  3991. (list-diary-entries-hook
  3992. (cons 'org-diary-default-entry list-diary-entries-hook))
  3993. (diary-file-name-prefix-function nil) ; turn this feature off
  3994. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3995. entries
  3996. (org-disable-agenda-to-diary t))
  3997. (save-excursion
  3998. (save-window-excursion
  3999. (funcall (if (fboundp 'diary-list-entries)
  4000. 'diary-list-entries 'list-diary-entries)
  4001. date 1)))
  4002. (if (not (get-buffer diary-fancy-buffer))
  4003. (setq entries nil)
  4004. (with-current-buffer diary-fancy-buffer
  4005. (setq buffer-read-only nil)
  4006. (if (zerop (buffer-size))
  4007. ;; No entries
  4008. (setq entries nil)
  4009. ;; Omit the date and other unnecessary stuff
  4010. (org-agenda-cleanup-fancy-diary)
  4011. ;; Add prefix to each line and extend the text properties
  4012. (if (zerop (buffer-size))
  4013. (setq entries nil)
  4014. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4015. (setq entries
  4016. (with-temp-buffer
  4017. (insert entries) (goto-char (point-min))
  4018. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4019. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4020. (replace-match (concat "; " (match-string 1)))))
  4021. (buffer-string)))))
  4022. (set-buffer-modified-p nil)
  4023. (kill-buffer diary-fancy-buffer)))
  4024. (when entries
  4025. (setq entries (org-split-string entries "\n"))
  4026. (setq entries
  4027. (mapcar
  4028. (lambda (x)
  4029. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4030. ;; Extend the text properties to the beginning of the line
  4031. (org-add-props x (text-properties-at (1- (length x)) x)
  4032. 'type "diary" 'date date 'face 'org-agenda-diary))
  4033. entries)))))
  4034. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4035. "Hook run when the fancy diary buffer is cleaned up.")
  4036. (defun org-agenda-cleanup-fancy-diary ()
  4037. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4038. This gets rid of the date, the underline under the date, and
  4039. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4040. date. It also removes lines that contain only whitespace."
  4041. (goto-char (point-min))
  4042. (if (looking-at ".*?:[ \t]*")
  4043. (progn
  4044. (replace-match "")
  4045. (re-search-forward "\n=+$" nil t)
  4046. (replace-match "")
  4047. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4048. (re-search-forward "\n=+$" nil t)
  4049. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4050. (goto-char (point-min))
  4051. (while (re-search-forward "^ +\n" nil t)
  4052. (replace-match ""))
  4053. (goto-char (point-min))
  4054. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4055. (replace-match ""))
  4056. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4057. ;; Make sure entries from the diary have the right text properties.
  4058. (eval-after-load "diary-lib"
  4059. '(if (boundp 'diary-modify-entry-list-string-function)
  4060. ;; We can rely on the hook, nothing to do
  4061. nil
  4062. ;; Hook not available, must use advice to make this work
  4063. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4064. "Make the position visible."
  4065. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4066. (stringp string)
  4067. buffer-file-name)
  4068. (setq string (org-modify-diary-entry-string string))))))
  4069. (defun org-modify-diary-entry-string (string)
  4070. "Add text properties to string, allowing org-mode to act on it."
  4071. (org-add-props string nil
  4072. 'mouse-face 'highlight
  4073. 'help-echo (if buffer-file-name
  4074. (format "mouse-2 or RET jump to diary file %s"
  4075. (abbreviate-file-name buffer-file-name))
  4076. "")
  4077. 'org-agenda-diary-link t
  4078. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4079. (defun org-diary-default-entry ()
  4080. "Add a dummy entry to the diary.
  4081. Needed to avoid empty dates which mess up holiday display."
  4082. ;; Catch the error if dealing with the new add-to-diary-alist
  4083. (when org-disable-agenda-to-diary
  4084. (condition-case nil
  4085. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4086. (error
  4087. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4088. (defun org-add-to-diary-list (&rest args)
  4089. (if (fboundp 'diary-add-to-list)
  4090. (apply 'diary-add-to-list args)
  4091. (apply 'add-to-diary-list args)))
  4092. (defvar org-diary-last-run-time nil)
  4093. ;;;###autoload
  4094. (defun org-diary (&rest args)
  4095. "Return diary information from org-files.
  4096. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4097. It accesses org files and extracts information from those files to be
  4098. listed in the diary. The function accepts arguments specifying what
  4099. items should be listed. For a list of arguments allowed here, see the
  4100. variable `org-agenda-entry-types'.
  4101. The call in the diary file should look like this:
  4102. &%%(org-diary) ~/path/to/some/orgfile.org
  4103. Use a separate line for each org file to check. Or, if you omit the file name,
  4104. all files listed in `org-agenda-files' will be checked automatically:
  4105. &%%(org-diary)
  4106. If you don't give any arguments (as in the example above), the default
  4107. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4108. So the example above may also be written as
  4109. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4110. The function expects the lisp variables `entry' and `date' to be provided
  4111. by the caller, because this is how the calendar works. Don't use this
  4112. function from a program - use `org-agenda-get-day-entries' instead."
  4113. (when (> (- (org-float-time)
  4114. org-agenda-last-marker-time)
  4115. 5)
  4116. (org-agenda-reset-markers))
  4117. (org-compile-prefix-format 'agenda)
  4118. (org-set-sorting-strategy 'agenda)
  4119. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4120. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4121. (list entry)
  4122. (org-agenda-files t)))
  4123. (time (org-float-time))
  4124. file rtn results)
  4125. (when (or (not org-diary-last-run-time)
  4126. (> (- time
  4127. org-diary-last-run-time)
  4128. 3))
  4129. (org-prepare-agenda-buffers files))
  4130. (setq org-diary-last-run-time time)
  4131. ;; If this is called during org-agenda, don't return any entries to
  4132. ;; the calendar. Org Agenda will list these entries itself.
  4133. (if org-disable-agenda-to-diary (setq files nil))
  4134. (while (setq file (pop files))
  4135. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4136. (setq results (append results rtn)))
  4137. (if results
  4138. (concat (org-finalize-agenda-entries results) "\n"))))
  4139. ;;; Agenda entry finders
  4140. (defun org-agenda-get-day-entries (file date &rest args)
  4141. "Does the work for `org-diary' and `org-agenda'.
  4142. FILE is the path to a file to be checked for entries. DATE is date like
  4143. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4144. which kind of entries should be extracted. For details about these, see
  4145. the documentation of `org-diary'."
  4146. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4147. (let* ((org-startup-folded nil)
  4148. (org-startup-align-all-tables nil)
  4149. (buffer (if (file-exists-p file)
  4150. (org-get-agenda-file-buffer file)
  4151. (error "No such file %s" file)))
  4152. arg results rtn deadline-results)
  4153. (if (not buffer)
  4154. ;; If file does not exist, make sure an error message ends up in diary
  4155. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4156. (with-current-buffer buffer
  4157. (unless (org-mode-p)
  4158. (error "Agenda file %s is not in `org-mode'" file))
  4159. (let ((case-fold-search nil))
  4160. (save-excursion
  4161. (save-restriction
  4162. (if org-agenda-restrict
  4163. (narrow-to-region org-agenda-restrict-begin
  4164. org-agenda-restrict-end)
  4165. (widen))
  4166. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4167. (while (setq arg (pop args))
  4168. (cond
  4169. ((and (eq arg :todo)
  4170. (equal date (calendar-gregorian-from-absolute
  4171. (org-today))))
  4172. (setq rtn (org-agenda-get-todos))
  4173. (setq results (append results rtn)))
  4174. ((eq arg :timestamp)
  4175. (setq rtn (org-agenda-get-blocks))
  4176. (setq results (append results rtn))
  4177. (setq rtn (org-agenda-get-timestamps))
  4178. (setq results (append results rtn)))
  4179. ((eq arg :sexp)
  4180. (setq rtn (org-agenda-get-sexps))
  4181. (setq results (append results rtn)))
  4182. ((eq arg :scheduled)
  4183. (setq rtn (org-agenda-get-scheduled deadline-results))
  4184. (setq results (append results rtn)))
  4185. ((eq arg :closed)
  4186. (setq rtn (org-agenda-get-progress))
  4187. (setq results (append results rtn)))
  4188. ((eq arg :deadline)
  4189. (setq rtn (org-agenda-get-deadlines))
  4190. (setq deadline-results (copy-sequence rtn))
  4191. (setq results (append results rtn))))))))
  4192. results))))
  4193. (defun org-agenda-get-todos ()
  4194. "Return the TODO information for agenda display."
  4195. (let* ((props (list 'face nil
  4196. 'done-face 'org-agenda-done
  4197. 'org-not-done-regexp org-not-done-regexp
  4198. 'org-todo-regexp org-todo-regexp
  4199. 'org-complex-heading-regexp org-complex-heading-regexp
  4200. 'mouse-face 'highlight
  4201. 'help-echo
  4202. (format "mouse-2 or RET jump to org file %s"
  4203. (abbreviate-file-name buffer-file-name))))
  4204. (regexp (concat "^\\*+[ \t]+\\("
  4205. (if org-select-this-todo-keyword
  4206. (if (equal org-select-this-todo-keyword "*")
  4207. org-todo-regexp
  4208. (concat "\\<\\("
  4209. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4210. "\\)\\>"))
  4211. org-not-done-regexp)
  4212. "[^\n\r]*\\)"))
  4213. marker priority category tags todo-state
  4214. ee txt beg end)
  4215. (goto-char (point-min))
  4216. (while (re-search-forward regexp nil t)
  4217. (catch :skip
  4218. (save-match-data
  4219. (beginning-of-line)
  4220. (org-agenda-skip)
  4221. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4222. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4223. (goto-char (1+ beg))
  4224. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4225. (throw :skip nil)))
  4226. (goto-char (match-beginning 1))
  4227. (setq marker (org-agenda-new-marker (match-beginning 0))
  4228. category (org-get-category)
  4229. txt (match-string 1)
  4230. tags (org-get-tags-at (point))
  4231. txt (org-format-agenda-item "" txt category tags)
  4232. priority (1+ (org-get-priority txt))
  4233. todo-state (org-get-todo-state))
  4234. (org-add-props txt props
  4235. 'org-marker marker 'org-hd-marker marker
  4236. 'priority priority 'org-category category
  4237. 'type "todo" 'todo-state todo-state)
  4238. (push txt ee)
  4239. (if org-agenda-todo-list-sublevels
  4240. (goto-char (match-end 1))
  4241. (org-end-of-subtree 'invisible))))
  4242. (nreverse ee)))
  4243. (defun org-agenda-todo-custom-ignore-p (time n)
  4244. "Check whether timestamp is farther away then n number of days.
  4245. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4246. `org-agenda-todo-ignore-scheduled' or
  4247. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4248. (let ((days (org-days-to-time time)))
  4249. (if (>= n 0)
  4250. (>= days n)
  4251. (<= days n))))
  4252. ;;;###autoload
  4253. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4254. (&optional end)
  4255. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4256. (when (or org-agenda-todo-ignore-with-date
  4257. org-agenda-todo-ignore-scheduled
  4258. org-agenda-todo-ignore-deadlines
  4259. org-agenda-todo-ignore-timestamp)
  4260. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4261. (save-excursion
  4262. (or (and org-agenda-todo-ignore-with-date
  4263. (re-search-forward org-ts-regexp end t))
  4264. (and org-agenda-todo-ignore-scheduled
  4265. (re-search-forward org-scheduled-time-regexp end t)
  4266. (cond
  4267. ((eq org-agenda-todo-ignore-scheduled 'future)
  4268. (> (org-days-to-time (match-string 1)) 0))
  4269. ((eq org-agenda-todo-ignore-scheduled 'past)
  4270. (<= (org-days-to-time (match-string 1)) 0))
  4271. ((numberp org-agenda-todo-ignore-scheduled)
  4272. (org-agenda-todo-custom-ignore-p
  4273. (match-string 1) org-agenda-todo-ignore-scheduled))
  4274. (t)))
  4275. (and org-agenda-todo-ignore-deadlines
  4276. (re-search-forward org-deadline-time-regexp end t)
  4277. (cond
  4278. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4279. ((eq org-agenda-todo-ignore-deadlines 'far)
  4280. (not (org-deadline-close (match-string 1))))
  4281. ((eq org-agenda-todo-ignore-deadlines 'future)
  4282. (> (org-days-to-time (match-string 1)) 0))
  4283. ((eq org-agenda-todo-ignore-deadlines 'past)
  4284. (<= (org-days-to-time (match-string 1)) 0))
  4285. ((numberp org-agenda-todo-ignore-deadlines)
  4286. (org-agenda-todo-custom-ignore-p
  4287. (match-string 1) org-agenda-todo-ignore-deadlines))
  4288. (t (org-deadline-close (match-string 1)))))
  4289. (and org-agenda-todo-ignore-timestamp
  4290. (let ((buffer (current-buffer))
  4291. (regexp
  4292. (concat
  4293. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4294. (start (point)))
  4295. ;; Copy current buffer into a temporary one
  4296. (with-temp-buffer
  4297. (insert-buffer-substring buffer start end)
  4298. (goto-char (point-min))
  4299. ;; Delete SCHEDULED and DEADLINE items
  4300. (while (re-search-forward regexp end t)
  4301. (delete-region (match-beginning 0) (match-end 0)))
  4302. (goto-char (point-min))
  4303. ;; No search for timestamp left
  4304. (when (re-search-forward org-ts-regexp nil t)
  4305. (cond
  4306. ((eq org-agenda-todo-ignore-timestamp 'future)
  4307. (> (org-days-to-time (match-string 1)) 0))
  4308. ((eq org-agenda-todo-ignore-timestamp 'past)
  4309. (<= (org-days-to-time (match-string 1)) 0))
  4310. ((numberp org-agenda-todo-ignore-timestamp)
  4311. (org-agenda-todo-custom-ignore-p
  4312. (match-string 1) org-agenda-todo-ignore-timestamp))
  4313. (t))))))))))
  4314. (defconst org-agenda-no-heading-message
  4315. "No heading for this item in buffer or region.")
  4316. (defun org-agenda-get-timestamps ()
  4317. "Return the date stamp information for agenda display."
  4318. (let* ((props (list 'face nil
  4319. 'org-not-done-regexp org-not-done-regexp
  4320. 'org-todo-regexp org-todo-regexp
  4321. 'org-complex-heading-regexp org-complex-heading-regexp
  4322. 'mouse-face 'highlight
  4323. 'help-echo
  4324. (format "mouse-2 or RET jump to org file %s"
  4325. (abbreviate-file-name buffer-file-name))))
  4326. (d1 (calendar-absolute-from-gregorian date))
  4327. (remove-re
  4328. (concat
  4329. (regexp-quote
  4330. (format-time-string
  4331. "<%Y-%m-%d"
  4332. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4333. ".*?>"))
  4334. (regexp
  4335. (concat
  4336. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4337. (regexp-quote
  4338. (substring
  4339. (format-time-string
  4340. (car org-time-stamp-formats)
  4341. (apply 'encode-time ; DATE bound by calendar
  4342. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4343. 1 11))
  4344. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4345. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4346. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4347. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4348. todo-state end-of-match show-all)
  4349. (goto-char (point-min))
  4350. (while (setq end-of-match (re-search-forward regexp nil t))
  4351. (setq b0 (match-beginning 0)
  4352. b3 (match-beginning 3) e3 (match-end 3)
  4353. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4354. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4355. (member todo-state
  4356. org-agenda-repeating-timestamp-show-all)))
  4357. (catch :skip
  4358. (and (org-at-date-range-p) (throw :skip nil))
  4359. (org-agenda-skip)
  4360. (if (and (match-end 1)
  4361. (not (= d1 (org-time-string-to-absolute
  4362. (match-string 1) d1 nil show-all))))
  4363. (throw :skip nil))
  4364. (if (and e3
  4365. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4366. (throw :skip nil))
  4367. (setq tmp (buffer-substring (max (point-min)
  4368. (- b0 org-ds-keyword-length))
  4369. b0)
  4370. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4371. inactivep (= (char-after b0) ?\[)
  4372. deadlinep (string-match org-deadline-regexp tmp)
  4373. scheduledp (string-match org-scheduled-regexp tmp)
  4374. closedp (and org-agenda-include-inactive-timestamps
  4375. (string-match org-closed-string tmp))
  4376. clockp (and org-agenda-include-inactive-timestamps
  4377. (or (string-match org-clock-string tmp)
  4378. (string-match "]-+\\'" tmp)))
  4379. donep (member todo-state org-done-keywords))
  4380. (if (or scheduledp deadlinep closedp clockp
  4381. (and donep org-agenda-skip-timestamp-if-done))
  4382. (throw :skip t))
  4383. (if (string-match ">" timestr)
  4384. ;; substring should only run to end of time stamp
  4385. (setq timestr (substring timestr 0 (match-end 0))))
  4386. (setq marker (org-agenda-new-marker b0)
  4387. category (org-get-category b0))
  4388. (save-excursion
  4389. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4390. (setq txt org-agenda-no-heading-message)
  4391. (goto-char (match-beginning 0))
  4392. (setq hdmarker (org-agenda-new-marker)
  4393. tags (org-get-tags-at))
  4394. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4395. (setq head (or (match-string 1) ""))
  4396. (setq txt (org-format-agenda-item
  4397. (if inactivep org-agenda-inactive-leader nil)
  4398. head category tags timestr
  4399. remove-re)))
  4400. (setq priority (org-get-priority txt))
  4401. (org-add-props txt props
  4402. 'org-marker marker 'org-hd-marker hdmarker)
  4403. (org-add-props txt nil 'priority priority
  4404. 'org-category category 'date date
  4405. 'todo-state todo-state
  4406. 'type "timestamp")
  4407. (push txt ee))
  4408. (if org-agenda-skip-additional-timestamps-same-entry
  4409. (outline-next-heading)
  4410. (goto-char end-of-match))))
  4411. (nreverse ee)))
  4412. (defun org-agenda-get-sexps ()
  4413. "Return the sexp information for agenda display."
  4414. (require 'diary-lib)
  4415. (let* ((props (list 'mouse-face 'highlight
  4416. 'help-echo
  4417. (format "mouse-2 or RET jump to org file %s"
  4418. (abbreviate-file-name buffer-file-name))))
  4419. (regexp "^&?%%(")
  4420. marker category ee txt tags entry result beg b sexp sexp-entry
  4421. todo-state)
  4422. (goto-char (point-min))
  4423. (while (re-search-forward regexp nil t)
  4424. (catch :skip
  4425. (org-agenda-skip)
  4426. (setq beg (match-beginning 0))
  4427. (goto-char (1- (match-end 0)))
  4428. (setq b (point))
  4429. (forward-sexp 1)
  4430. (setq sexp (buffer-substring b (point)))
  4431. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4432. (org-trim (match-string 1))
  4433. ""))
  4434. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4435. (when result
  4436. (setq marker (org-agenda-new-marker beg)
  4437. category (org-get-category beg)
  4438. todo-state (org-get-todo-state))
  4439. (dolist (r (if (stringp result)
  4440. (list result)
  4441. result)) ;; we expect a list here
  4442. (if (string-match "\\S-" r)
  4443. (setq txt r)
  4444. (setq txt "SEXP entry returned empty string"))
  4445. (setq txt (org-format-agenda-item
  4446. "" txt category tags 'time))
  4447. (org-add-props txt props 'org-marker marker)
  4448. (org-add-props txt nil
  4449. 'org-category category 'date date 'todo-state todo-state
  4450. 'type "sexp")
  4451. (push txt ee)))))
  4452. (nreverse ee)))
  4453. ;; Calendar sanity: define some functions that are independent of
  4454. ;; `calendar-date-style'.
  4455. ;; Normally I would like to use ISO format when calling the diary functions,
  4456. ;; but to make sure we still have Emacs 22 compatibility we bind
  4457. ;; also `european-calendar-style' and use european format
  4458. (defun org-anniversary (year month day &optional mark)
  4459. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4460. (org-no-warnings
  4461. (let ((calendar-date-style 'european) (european-calendar-style t))
  4462. (diary-anniversary day month year mark))))
  4463. (defun org-cyclic (N year month day &optional mark)
  4464. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4465. (org-no-warnings
  4466. (let ((calendar-date-style 'european) (european-calendar-style t))
  4467. (diary-cyclic N day month year mark))))
  4468. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4469. "Like `diary-block', but with fixed (ISO) order of arguments."
  4470. (org-no-warnings
  4471. (let ((calendar-date-style 'european) (european-calendar-style t))
  4472. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4473. (defun org-date (year month day &optional mark)
  4474. "Like `diary-date', but with fixed (ISO) order of arguments."
  4475. (org-no-warnings
  4476. (let ((calendar-date-style 'european) (european-calendar-style t))
  4477. (diary-date day month year mark))))
  4478. (defalias 'org-float 'diary-float)
  4479. ;; Define the` org-class' function
  4480. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4481. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4482. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4483. is any number of ISO weeks in the block period for which the item should
  4484. be skipped."
  4485. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4486. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4487. (d (calendar-absolute-from-gregorian date)))
  4488. (and
  4489. (<= date1 d)
  4490. (<= d date2)
  4491. (= (calendar-day-of-week date) dayname)
  4492. (or (not skip-weeks)
  4493. (progn
  4494. (require 'cal-iso)
  4495. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4496. entry)))
  4497. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4498. "Like `org-class', but honor `calendar-date-style'.
  4499. The order of the first 2 times 3 arguments depends on the variable
  4500. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4501. So for American calendars, give this as MONTH DAY YEAR, for European as
  4502. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4503. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4504. is any number of ISO weeks in the block period for which the item should
  4505. be skipped.
  4506. This function is here only for backward compatibility and it is deprecated,
  4507. please use `org-class' instead."
  4508. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4509. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4510. (org-class
  4511. (nth 2 date1) (car date1) (nth 1 date1)
  4512. (nth 2 date2) (car date2) (nth 1 date2)
  4513. dayname skip-weeks)))
  4514. (defalias 'org-get-closed 'org-agenda-get-progress)
  4515. (defun org-agenda-get-progress ()
  4516. "Return the logged TODO entries for agenda display."
  4517. (let* ((props (list 'mouse-face 'highlight
  4518. 'org-not-done-regexp org-not-done-regexp
  4519. 'org-todo-regexp org-todo-regexp
  4520. 'org-complex-heading-regexp org-complex-heading-regexp
  4521. 'help-echo
  4522. (format "mouse-2 or RET jump to org file %s"
  4523. (abbreviate-file-name buffer-file-name))))
  4524. (items (if (consp org-agenda-show-log)
  4525. org-agenda-show-log
  4526. (if (eq org-agenda-show-log 'clockcheck)
  4527. '(clock)
  4528. org-agenda-log-mode-items)))
  4529. (parts
  4530. (delq nil
  4531. (list
  4532. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4533. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4534. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4535. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4536. (error "`org-agenda-log-mode-items' is empty")))
  4537. (regexp (concat
  4538. "\\(" parts-re "\\)"
  4539. " *\\["
  4540. (regexp-quote
  4541. (substring
  4542. (format-time-string
  4543. (car org-time-stamp-formats)
  4544. (apply 'encode-time ; DATE bound by calendar
  4545. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4546. 1 11))))
  4547. (org-agenda-search-headline-for-time nil)
  4548. marker hdmarker priority category tags closedp statep clockp state
  4549. ee txt extra timestr rest clocked)
  4550. (goto-char (point-min))
  4551. (while (re-search-forward regexp nil t)
  4552. (catch :skip
  4553. (org-agenda-skip)
  4554. (setq marker (org-agenda-new-marker (match-beginning 0))
  4555. closedp (equal (match-string 1) org-closed-string)
  4556. statep (equal (string-to-char (match-string 1)) ?-)
  4557. clockp (not (or closedp statep))
  4558. state (and statep (match-string 2))
  4559. category (org-get-category (match-beginning 0))
  4560. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4561. )
  4562. (when (string-match "\\]" timestr)
  4563. ;; substring should only run to end of time stamp
  4564. (setq rest (substring timestr (match-end 0))
  4565. timestr (substring timestr 0 (match-end 0)))
  4566. (if (and (not closedp) (not statep)
  4567. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4568. (progn (setq timestr (concat (substring timestr 0 -1)
  4569. "-" (match-string 1 rest) "]"))
  4570. (setq clocked (match-string 2 rest)))
  4571. (setq clocked "-")))
  4572. (save-excursion
  4573. (setq extra
  4574. (cond
  4575. ((not org-agenda-log-mode-add-notes) nil)
  4576. (statep
  4577. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4578. (match-string 1)))
  4579. (clockp
  4580. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4581. (match-string 1)))))
  4582. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4583. (setq txt org-agenda-no-heading-message)
  4584. (goto-char (match-beginning 0))
  4585. (setq hdmarker (org-agenda-new-marker)
  4586. tags (org-get-tags-at))
  4587. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4588. (setq txt (match-string 1))
  4589. (when extra
  4590. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4591. (setq txt (concat (substring txt 0 (match-beginning 1))
  4592. " - " extra " " (match-string 2 txt)))
  4593. (setq txt (concat txt " - " extra))))
  4594. (setq txt (org-format-agenda-item
  4595. (cond
  4596. (closedp "Closed: ")
  4597. (statep (concat "State: (" state ")"))
  4598. (t (concat "Clocked: (" clocked ")")))
  4599. txt category tags timestr)))
  4600. (setq priority 100000)
  4601. (org-add-props txt props
  4602. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4603. 'priority priority 'org-category category
  4604. 'type "closed" 'date date
  4605. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4606. (push txt ee))
  4607. (goto-char (point-at-eol))))
  4608. (nreverse ee)))
  4609. (defun org-agenda-show-clocking-issues ()
  4610. "Add overlays, showing issues with clocking.
  4611. See also the user option `org-agenda-clock-consistency-checks'."
  4612. (interactive)
  4613. (let* ((pl org-agenda-clock-consistency-checks)
  4614. (re (concat "^[ \t]*"
  4615. org-clock-string
  4616. "[ \t]+"
  4617. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4618. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4619. (tlstart 0.)
  4620. (tlend 0.)
  4621. (maxtime (org-hh:mm-string-to-minutes
  4622. (or (plist-get pl :max-duration) "24:00")))
  4623. (mintime (org-hh:mm-string-to-minutes
  4624. (or (plist-get pl :min-duration) 0)))
  4625. (maxgap (org-hh:mm-string-to-minutes
  4626. ;; default 30:00 means never complain
  4627. (or (plist-get pl :max-gap) "30:00")))
  4628. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4629. (plist-get pl :gap-ok-around)))
  4630. (def-face (or (plist-get pl :default-face)
  4631. '((:background "DarkRed") (:foreground "white"))))
  4632. issue face m te ts dt ov)
  4633. (goto-char (point-min))
  4634. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4635. (setq issue nil face def-face)
  4636. (catch 'next
  4637. (setq m (org-get-at-bol 'org-marker)
  4638. te nil ts nil)
  4639. (unless (and m (markerp m))
  4640. (setq issue "No valid clock line") (throw 'next t))
  4641. (org-with-point-at m
  4642. (save-excursion
  4643. (goto-char (point-at-bol))
  4644. (unless (looking-at re)
  4645. (error "No valid Clock line")
  4646. (throw 'next t))
  4647. (unless (match-end 3)
  4648. (setq issue "No end time"
  4649. face (or (plist-get pl :no-end-time-face) face))
  4650. (throw 'next t))
  4651. (setq ts (match-string 1)
  4652. te (match-string 3)
  4653. ts (org-float-time
  4654. (apply 'encode-time (org-parse-time-string ts)))
  4655. te (org-float-time
  4656. (apply 'encode-time (org-parse-time-string te)))
  4657. dt (- te ts))))
  4658. (cond
  4659. ((> dt (* 60 maxtime))
  4660. ;; a very long clocking chunk
  4661. (setq issue (format "Clocking interval is very long: %s"
  4662. (org-minutes-to-hh:mm-string
  4663. (floor (/ (float dt) 60.))))
  4664. face (or (plist-get pl :long-face) face)))
  4665. ((< dt (* 60 mintime))
  4666. ;; a very short clocking chunk
  4667. (setq issue (format "Clocking interval is very short: %s"
  4668. (org-minutes-to-hh:mm-string
  4669. (floor (/ (float dt) 60.))))
  4670. face (or (plist-get pl :short-face) face)))
  4671. ((and (> tlend 0) (< ts tlend))
  4672. ;; Two clock entries are overlapping
  4673. (setq issue (format "Clocking overlap: %d minutes"
  4674. (/ (- tlend ts) 60))
  4675. face (or (plist-get pl :overlap-face) face)))
  4676. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4677. ;; There is a gap, lets see if we need to report it
  4678. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4679. (setq issue (format "Clocking gap: %d minutes"
  4680. (/ (- ts tlend) 60))
  4681. face (or (plist-get pl :gap-face) face))))
  4682. (t nil)))
  4683. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4684. (when issue
  4685. ;; OK, there was some issue, add an overlay to show the issue
  4686. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4687. (overlay-put ov 'before-string
  4688. (concat
  4689. (org-add-props
  4690. (format "%-43s" (concat " " issue))
  4691. nil
  4692. 'face face)
  4693. "\n"))
  4694. (overlay-put ov 'evaporate t)))))
  4695. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4696. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4697. (catch 'exit
  4698. (unless ok-list
  4699. ;; there are no OK times for gaps...
  4700. (throw 'exit nil))
  4701. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4702. ;; This is more than 24 hours, so it is OK.
  4703. ;; because we have at least one OK time, that must be in the
  4704. ;; 24 hour interval.
  4705. (throw 'exit t))
  4706. ;; We have a shorter gap.
  4707. ;; Now we have to get the minute of the day when these times are
  4708. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4709. (t2dec (decode-time (seconds-to-time t2)))
  4710. ;; compute the minute on the day
  4711. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4712. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4713. (when (< min2 min1)
  4714. ;; if min2 is smaller than min1, this means it is on the next day.
  4715. ;; Wrap it to after midnight.
  4716. (setq min2 (+ min2 1440)))
  4717. ;; Now check if any of the OK times is in the gap
  4718. (mapc (lambda (x)
  4719. ;; Wrap the time to after midnight if necessary
  4720. (if (< x min1) (setq x (+ x 1440)))
  4721. ;; Check if in interval
  4722. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4723. ok-list)
  4724. ;; Nope, this gap is not OK
  4725. nil)))
  4726. (defun org-agenda-get-deadlines ()
  4727. "Return the deadline information for agenda display."
  4728. (let* ((props (list 'mouse-face 'highlight
  4729. 'org-not-done-regexp org-not-done-regexp
  4730. 'org-todo-regexp org-todo-regexp
  4731. 'org-complex-heading-regexp org-complex-heading-regexp
  4732. 'help-echo
  4733. (format "mouse-2 or RET jump to org file %s"
  4734. (abbreviate-file-name buffer-file-name))))
  4735. (regexp org-deadline-time-regexp)
  4736. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4737. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4738. d2 diff dfrac wdays pos pos1 category tags
  4739. suppress-prewarning
  4740. ee txt head face s todo-state show-all upcomingp donep timestr)
  4741. (goto-char (point-min))
  4742. (while (re-search-forward regexp nil t)
  4743. (setq suppress-prewarning nil)
  4744. (catch :skip
  4745. (org-agenda-skip)
  4746. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4747. (save-match-data
  4748. (string-match org-scheduled-time-regexp
  4749. (buffer-substring (point-at-bol)
  4750. (point-at-eol)))))
  4751. (setq suppress-prewarning
  4752. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4753. org-agenda-skip-deadline-prewarning-if-scheduled
  4754. 0)))
  4755. (setq s (match-string 1)
  4756. txt nil
  4757. pos (1- (match-beginning 1))
  4758. todo-state (save-match-data (org-get-todo-state))
  4759. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4760. (member todo-state
  4761. org-agenda-repeating-timestamp-show-all))
  4762. d2 (org-time-string-to-absolute
  4763. (match-string 1) d1 'past show-all)
  4764. diff (- d2 d1)
  4765. wdays (if suppress-prewarning
  4766. (let ((org-deadline-warning-days suppress-prewarning))
  4767. (org-get-wdays s))
  4768. (org-get-wdays s))
  4769. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4770. upcomingp (and todayp (> diff 0)))
  4771. ;; When to show a deadline in the calendar:
  4772. ;; If the expiration is within wdays warning time.
  4773. ;; Past-due deadlines are only shown on the current date
  4774. (if (and (or (and (<= diff wdays)
  4775. (and todayp (not org-agenda-only-exact-dates)))
  4776. (= diff 0)))
  4777. (save-excursion
  4778. ;; (setq todo-state (org-get-todo-state))
  4779. (setq donep (member todo-state org-done-keywords))
  4780. (if (and donep
  4781. (or org-agenda-skip-deadline-if-done
  4782. (not (= diff 0))))
  4783. (setq txt nil)
  4784. (setq category (org-get-category))
  4785. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4786. (setq txt org-agenda-no-heading-message)
  4787. (goto-char (match-end 0))
  4788. (setq pos1 (match-beginning 0))
  4789. (setq tags (org-get-tags-at pos1))
  4790. (setq head (buffer-substring-no-properties
  4791. (point)
  4792. (progn (skip-chars-forward "^\r\n")
  4793. (point))))
  4794. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4795. (setq timestr
  4796. (concat (substring s (match-beginning 1)) " "))
  4797. (setq timestr 'time))
  4798. (setq txt (org-format-agenda-item
  4799. (if (= diff 0)
  4800. (car org-agenda-deadline-leaders)
  4801. (if (functionp
  4802. (nth 1 org-agenda-deadline-leaders))
  4803. (funcall
  4804. (nth 1 org-agenda-deadline-leaders)
  4805. diff date)
  4806. (format (nth 1 org-agenda-deadline-leaders)
  4807. diff)))
  4808. head category tags
  4809. (if (not (= diff 0)) nil timestr)))))
  4810. (when txt
  4811. (setq face (org-agenda-deadline-face dfrac wdays))
  4812. (org-add-props txt props
  4813. 'org-marker (org-agenda-new-marker pos)
  4814. 'org-hd-marker (org-agenda-new-marker pos1)
  4815. 'priority (+ (- diff)
  4816. (org-get-priority txt))
  4817. 'org-category category
  4818. 'todo-state todo-state
  4819. 'type (if upcomingp "upcoming-deadline" "deadline")
  4820. 'date (if upcomingp date d2)
  4821. 'face (if donep 'org-agenda-done face)
  4822. 'undone-face face 'done-face 'org-agenda-done)
  4823. (push txt ee))))))
  4824. (nreverse ee)))
  4825. (defun org-agenda-deadline-face (fraction &optional wdays)
  4826. "Return the face to displaying a deadline item.
  4827. FRACTION is what fraction of the head-warning time has passed."
  4828. (if (equal wdays 0) (setq fraction 1.))
  4829. (let ((faces org-agenda-deadline-faces) f)
  4830. (catch 'exit
  4831. (while (setq f (pop faces))
  4832. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4833. (defun org-agenda-get-scheduled (&optional deadline-results)
  4834. "Return the scheduled information for agenda display."
  4835. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4836. 'org-todo-regexp org-todo-regexp
  4837. 'org-complex-heading-regexp org-complex-heading-regexp
  4838. 'done-face 'org-agenda-done
  4839. 'mouse-face 'highlight
  4840. 'help-echo
  4841. (format "mouse-2 or RET jump to org file %s"
  4842. (abbreviate-file-name buffer-file-name))))
  4843. (regexp org-scheduled-time-regexp)
  4844. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4845. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4846. mm
  4847. (deadline-position-alist
  4848. (mapcar (lambda (a) (and (setq mm (get-text-property
  4849. 0 'org-hd-marker a))
  4850. (cons (marker-position mm) a)))
  4851. deadline-results))
  4852. d2 diff pos pos1 category tags donep
  4853. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4854. (goto-char (point-min))
  4855. (while (re-search-forward regexp nil t)
  4856. (catch :skip
  4857. (org-agenda-skip)
  4858. (setq s (match-string 1)
  4859. txt nil
  4860. pos (1- (match-beginning 1))
  4861. todo-state (save-match-data (org-get-todo-state))
  4862. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4863. (member todo-state
  4864. org-agenda-repeating-timestamp-show-all))
  4865. d2 (org-time-string-to-absolute
  4866. (match-string 1) d1 'past show-all)
  4867. diff (- d2 d1))
  4868. (setq pastschedp (and todayp (< diff 0)))
  4869. ;; When to show a scheduled item in the calendar:
  4870. ;; If it is on or past the date.
  4871. (when (or (and (< diff 0)
  4872. (< (abs diff) org-scheduled-past-days)
  4873. (and todayp (not org-agenda-only-exact-dates)))
  4874. (= diff 0))
  4875. (save-excursion
  4876. (setq donep (member todo-state org-done-keywords))
  4877. (if (and donep
  4878. (or org-agenda-skip-scheduled-if-done
  4879. (not (= diff 0))
  4880. (and (functionp 'org-is-habit-p)
  4881. (org-is-habit-p))))
  4882. (setq txt nil)
  4883. (setq habitp (and (functionp 'org-is-habit-p)
  4884. (org-is-habit-p)))
  4885. (setq category (org-get-category))
  4886. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4887. (setq txt org-agenda-no-heading-message)
  4888. (goto-char (match-end 0))
  4889. (setq pos1 (match-beginning 0))
  4890. (if habitp
  4891. (if (or (not org-habit-show-habits)
  4892. (and (not todayp)
  4893. org-habit-show-habits-only-for-today))
  4894. (throw :skip nil))
  4895. (if (and
  4896. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4897. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4898. pastschedp))
  4899. (setq mm (assoc pos1 deadline-position-alist)))
  4900. (throw :skip nil)))
  4901. (setq tags (org-get-tags-at))
  4902. (setq head (buffer-substring-no-properties
  4903. (point)
  4904. (progn (skip-chars-forward "^\r\n") (point))))
  4905. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4906. (setq timestr
  4907. (concat (substring s (match-beginning 1)) " "))
  4908. (setq timestr 'time))
  4909. (setq txt (org-format-agenda-item
  4910. (if (= diff 0)
  4911. (car org-agenda-scheduled-leaders)
  4912. (format (nth 1 org-agenda-scheduled-leaders)
  4913. (- 1 diff)))
  4914. head category tags
  4915. (if (not (= diff 0)) nil timestr)
  4916. nil habitp))))
  4917. (when txt
  4918. (setq face
  4919. (cond
  4920. ((and (not habitp) pastschedp)
  4921. 'org-scheduled-previously)
  4922. (todayp 'org-scheduled-today)
  4923. (t 'org-scheduled))
  4924. habitp (and habitp (org-habit-parse-todo)))
  4925. (org-add-props txt props
  4926. 'undone-face face
  4927. 'face (if donep 'org-agenda-done face)
  4928. 'org-marker (org-agenda-new-marker pos)
  4929. 'org-hd-marker (org-agenda-new-marker pos1)
  4930. 'type (if pastschedp "past-scheduled" "scheduled")
  4931. 'date (if pastschedp d2 date)
  4932. 'priority (if habitp
  4933. (org-habit-get-priority habitp)
  4934. (+ 94 (- 5 diff) (org-get-priority txt)))
  4935. 'org-category category
  4936. 'org-habit-p habitp
  4937. 'todo-state todo-state)
  4938. (push txt ee))))))
  4939. (nreverse ee)))
  4940. (defun org-agenda-get-blocks ()
  4941. "Return the date-range information for agenda display."
  4942. (let* ((props (list 'face nil
  4943. 'org-not-done-regexp org-not-done-regexp
  4944. 'org-todo-regexp org-todo-regexp
  4945. 'org-complex-heading-regexp org-complex-heading-regexp
  4946. 'mouse-face 'highlight
  4947. 'help-echo
  4948. (format "mouse-2 or RET jump to org file %s"
  4949. (abbreviate-file-name buffer-file-name))))
  4950. (regexp org-tr-regexp)
  4951. (d0 (calendar-absolute-from-gregorian date))
  4952. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4953. head donep)
  4954. (goto-char (point-min))
  4955. (while (re-search-forward regexp nil t)
  4956. (catch :skip
  4957. (org-agenda-skip)
  4958. (setq pos (point))
  4959. (let ((start-time (match-string 1))
  4960. (end-time (match-string 2)))
  4961. (setq s1 (match-string 1)
  4962. s2 (match-string 2)
  4963. d1 (time-to-days (org-time-string-to-time s1))
  4964. d2 (time-to-days (org-time-string-to-time s2)))
  4965. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4966. ;; Only allow days between the limits, because the normal
  4967. ;; date stamps will catch the limits.
  4968. (save-excursion
  4969. (setq todo-state (org-get-todo-state))
  4970. (setq donep (member todo-state org-done-keywords))
  4971. (if (and donep org-agenda-skip-timestamp-if-done)
  4972. (throw :skip t))
  4973. (setq marker (org-agenda-new-marker (point)))
  4974. (setq category (org-get-category))
  4975. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4976. (setq txt org-agenda-no-heading-message)
  4977. (goto-char (match-beginning 0))
  4978. (setq hdmarker (org-agenda-new-marker (point)))
  4979. (setq tags (org-get-tags-at))
  4980. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4981. (setq head (match-string 1))
  4982. (let ((remove-re
  4983. (if org-agenda-remove-timeranges-from-blocks
  4984. (concat
  4985. "<" (regexp-quote s1) ".*?>"
  4986. "--"
  4987. "<" (regexp-quote s2) ".*?>")
  4988. nil)))
  4989. (setq txt (org-format-agenda-item
  4990. (format
  4991. (nth (if (= d1 d2) 0 1)
  4992. org-agenda-timerange-leaders)
  4993. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4994. head category tags
  4995. (cond ((= d1 d0)
  4996. (concat "<" start-time ">"))
  4997. ((= d2 d0)
  4998. (concat "<" end-time ">"))
  4999. (t nil))
  5000. remove-re))))
  5001. (org-add-props txt props
  5002. 'org-marker marker 'org-hd-marker hdmarker
  5003. 'type "block" 'date date
  5004. 'todo-state todo-state
  5005. 'priority (org-get-priority txt) 'org-category category)
  5006. (push txt ee))))
  5007. (goto-char pos)))
  5008. ;; Sort the entries by expiration date.
  5009. (nreverse ee)))
  5010. ;;; Agenda presentation and sorting
  5011. (defvar org-prefix-has-time nil
  5012. "A flag, set by `org-compile-prefix-format'.
  5013. The flag is set if the currently compiled format contains a `%t'.")
  5014. (defvar org-prefix-has-tag nil
  5015. "A flag, set by `org-compile-prefix-format'.
  5016. The flag is set if the currently compiled format contains a `%T'.")
  5017. (defvar org-prefix-has-effort nil
  5018. "A flag, set by `org-compile-prefix-format'.
  5019. The flag is set if the currently compiled format contains a `%e'.")
  5020. (defvar org-prefix-category-length nil
  5021. "Used by `org-compile-prefix-format' to remember the category field width.")
  5022. (defvar org-prefix-category-max-length nil
  5023. "Used by `org-compile-prefix-format' to remember the category field width.")
  5024. (defun org-agenda-get-category-icon (category)
  5025. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5026. (dolist (entry org-agenda-category-icon-alist)
  5027. (when (org-string-match-p (car entry) category)
  5028. (if (listp (cadr entry))
  5029. (return (cadr entry))
  5030. (return (apply 'create-image (cdr entry)))))))
  5031. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5032. remove-re habitp)
  5033. "Format TXT to be inserted into the agenda buffer.
  5034. In particular, it adds the prefix and corresponding text properties. EXTRA
  5035. must be a string and replaces the `%s' specifier in the prefix format.
  5036. CATEGORY (string, symbol or nil) may be used to overrule the default
  5037. category taken from local variable or file name. It will replace the `%c'
  5038. specifier in the format. DOTIME, when non-nil, indicates that a
  5039. time-of-day should be extracted from TXT for sorting of this entry, and for
  5040. the `%t' specifier in the format. When DOTIME is a string, this string is
  5041. searched for a time before TXT is. TAGS can be the tags of the headline.
  5042. Any match of REMOVE-RE will be removed from TXT."
  5043. (save-match-data
  5044. ;; Diary entries sometimes have extra whitespace at the beginning
  5045. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5046. ;; Fix the tags part in txt
  5047. (setq txt (org-agenda-fix-displayed-tags
  5048. txt tags
  5049. org-agenda-show-inherited-tags
  5050. org-agenda-hide-tags-regexp))
  5051. (let* ((category (or category
  5052. (if (stringp org-category)
  5053. org-category
  5054. (and org-category (symbol-name org-category)))
  5055. (if buffer-file-name
  5056. (file-name-sans-extension
  5057. (file-name-nondirectory buffer-file-name))
  5058. "")))
  5059. (category-icon (org-agenda-get-category-icon category))
  5060. (category-icon (if category-icon
  5061. (propertize " " 'display category-icon)
  5062. ""))
  5063. ;; time, tag, effort are needed for the eval of the prefix format
  5064. (tag (if tags (nth (1- (length tags)) tags) ""))
  5065. time effort neffort
  5066. (ts (if dotime (concat
  5067. (if (stringp dotime) dotime "")
  5068. (and org-agenda-search-headline-for-time txt))))
  5069. (time-of-day (and dotime (org-get-time-of-day ts)))
  5070. stamp plain s0 s1 s2 rtn srp l
  5071. duration thecategory)
  5072. (and (org-mode-p) buffer-file-name
  5073. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5074. (when (and dotime time-of-day)
  5075. ;; Extract starting and ending time and move them to prefix
  5076. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5077. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5078. (setq s0 (match-string 0 ts)
  5079. srp (and stamp (match-end 3))
  5080. s1 (match-string (if plain 1 2) ts)
  5081. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5082. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5083. ;; them, we might want to remove them there to avoid duplication.
  5084. ;; The user can turn this off with a variable.
  5085. (if (and org-prefix-has-time
  5086. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5087. (string-match (concat (regexp-quote s0) " *") txt)
  5088. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5089. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5090. (= (match-beginning 0) 0)
  5091. t))
  5092. (setq txt (replace-match "" nil nil txt))))
  5093. ;; Normalize the time(s) to 24 hour
  5094. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5095. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5096. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5097. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5098. (setq s2
  5099. (org-minutes-to-hh:mm-string
  5100. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5101. ;; Compute the duration
  5102. (when s2
  5103. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5104. (org-hh:mm-string-to-minutes s1)))))
  5105. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5106. txt)
  5107. ;; Tags are in the string
  5108. (if (or (eq org-agenda-remove-tags t)
  5109. (and org-agenda-remove-tags
  5110. org-prefix-has-tag))
  5111. (setq txt (replace-match "" t t txt))
  5112. (setq txt (replace-match
  5113. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5114. (match-string 2 txt))
  5115. t t txt))))
  5116. (when (org-mode-p)
  5117. (setq effort
  5118. (condition-case nil
  5119. (org-get-effort
  5120. (or (get-text-property 0 'org-hd-marker txt)
  5121. (get-text-property 0 'org-marker txt)))
  5122. (error nil)))
  5123. (when effort
  5124. (setq neffort (org-duration-string-to-minutes effort)
  5125. effort (setq effort (concat "[" effort "]")))))
  5126. ;; prevent erroring out with %e format when there is no effort
  5127. (or effort (setq effort ""))
  5128. (when remove-re
  5129. (while (string-match remove-re txt)
  5130. (setq txt (replace-match "" t t txt))))
  5131. ;; Set org-heading property on `txt' to mark the start of the
  5132. ;; heading.
  5133. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5134. ;; Prepare the variables needed in the eval of the compiled format
  5135. (setq time (cond (s2 (concat
  5136. (org-agenda-time-of-day-to-ampm-maybe s1)
  5137. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5138. (if org-agenda-timegrid-use-ampm " ")))
  5139. (s1 (concat
  5140. (org-agenda-time-of-day-to-ampm-maybe s1)
  5141. (if org-agenda-timegrid-use-ampm
  5142. "........ "
  5143. "......")))
  5144. (t ""))
  5145. extra (or (and (not habitp) extra) "")
  5146. category (if (symbolp category) (symbol-name category) category)
  5147. thecategory (copy-sequence category))
  5148. (if (string-match org-bracket-link-regexp category)
  5149. (progn
  5150. (setq l (if (match-end 3)
  5151. (- (match-end 3) (match-beginning 3))
  5152. (- (match-end 1) (match-beginning 1))))
  5153. (when (< l (or org-prefix-category-length 0))
  5154. (setq category (copy-sequence category))
  5155. (org-add-props category nil
  5156. 'extra-space (make-string
  5157. (- org-prefix-category-length l 1) ?\ ))))
  5158. (if (and org-prefix-category-max-length
  5159. (>= (length category) org-prefix-category-max-length))
  5160. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5161. ;; Evaluate the compiled format
  5162. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5163. ;; And finally add the text properties
  5164. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5165. (org-add-props rtn nil
  5166. 'org-category (if thecategory (downcase thecategory) category)
  5167. 'tags (mapcar 'org-downcase-keep-props tags)
  5168. 'org-highest-priority org-highest-priority
  5169. 'org-lowest-priority org-lowest-priority
  5170. 'time-of-day time-of-day
  5171. 'duration duration
  5172. 'effort effort
  5173. 'effort-minutes neffort
  5174. 'txt txt
  5175. 'time time
  5176. 'extra extra
  5177. 'format org-prefix-format-compiled
  5178. 'dotime dotime))))
  5179. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5180. "Remove tags string from TXT, and add a modified list of tags.
  5181. The modified list may contain inherited tags, and tags matched by
  5182. `org-agenda-hide-tags-regexp' will be removed."
  5183. (when (or add-inherited hide-re)
  5184. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5185. (setq txt (substring txt 0 (match-beginning 0))))
  5186. (setq tags
  5187. (delq nil
  5188. (mapcar (lambda (tg)
  5189. (if (or (and hide-re (string-match hide-re tg))
  5190. (and (not add-inherited)
  5191. (get-text-property 0 'inherited tg)))
  5192. nil
  5193. tg))
  5194. tags)))
  5195. (when tags
  5196. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5197. i)
  5198. (setq txt (concat txt " :"
  5199. (mapconcat
  5200. (lambda (x)
  5201. (setq i (get-text-property 0 'inherited x))
  5202. (if (and have-i (not i))
  5203. (progn
  5204. (setq have-i nil)
  5205. (concat ":" x))
  5206. x))
  5207. tags ":")
  5208. (if have-i "::" ":"))))))
  5209. txt)
  5210. (defun org-downcase-keep-props (s)
  5211. (let ((props (text-properties-at 0 s)))
  5212. (setq s (downcase s))
  5213. (add-text-properties 0 (length s) props s)
  5214. s))
  5215. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5216. (defvar org-agenda-sorting-strategy-selected nil)
  5217. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5218. (catch 'exit
  5219. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5220. ((and todayp (member 'today (car org-agenda-time-grid))))
  5221. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5222. ((member 'weekly (car org-agenda-time-grid)))
  5223. (t (throw 'exit list)))
  5224. (let* ((have (delq nil (mapcar
  5225. (lambda (x) (get-text-property 1 'time-of-day x))
  5226. list)))
  5227. (string (nth 1 org-agenda-time-grid))
  5228. (gridtimes (nth 2 org-agenda-time-grid))
  5229. (req (car org-agenda-time-grid))
  5230. (remove (member 'remove-match req))
  5231. new time)
  5232. (if (and (member 'require-timed req) (not have))
  5233. ;; don't show empty grid
  5234. (throw 'exit list))
  5235. (while (setq time (pop gridtimes))
  5236. (unless (and remove (member time have))
  5237. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5238. (push (org-format-agenda-item
  5239. nil string "" nil
  5240. (concat (substring time 0 -2) ":" (substring time -2)))
  5241. new)
  5242. (put-text-property
  5243. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5244. (when (and todayp org-agenda-show-current-time-in-grid)
  5245. (push (org-format-agenda-item
  5246. nil
  5247. org-agenda-current-time-string
  5248. "" nil
  5249. (format-time-string "%H:%M "))
  5250. new)
  5251. (put-text-property
  5252. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5253. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5254. (append new list)
  5255. (append list new)))))
  5256. (defun org-compile-prefix-format (key)
  5257. "Compile the prefix format into a Lisp form that can be evaluated.
  5258. The resulting form is returned and stored in the variable
  5259. `org-prefix-format-compiled'."
  5260. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5261. org-prefix-category-length nil org-prefix-has-effort nil)
  5262. (let ((s (cond
  5263. ((stringp org-agenda-prefix-format)
  5264. org-agenda-prefix-format)
  5265. ((assq key org-agenda-prefix-format)
  5266. (cdr (assq key org-agenda-prefix-format)))
  5267. (t " %-12:c%?-12t% s")))
  5268. (start 0)
  5269. varform vars var e c f opt)
  5270. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5271. s start)
  5272. (setq var (or (cdr (assoc (match-string 4 s)
  5273. '(("c" . category) ("t" . time) ("s" . extra)
  5274. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5275. 'eval)
  5276. c (or (match-string 3 s) "")
  5277. opt (match-beginning 1)
  5278. start (1+ (match-beginning 0)))
  5279. (if (equal var 'time) (setq org-prefix-has-time t))
  5280. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5281. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5282. (setq f (concat "%" (match-string 2 s) "s"))
  5283. (when (equal var 'category)
  5284. (setq org-prefix-category-length
  5285. (floor (abs (string-to-number (match-string 2 s)))))
  5286. (setq org-prefix-category-max-length
  5287. (let ((x (match-string 2 s)))
  5288. (save-match-data
  5289. (if (string-match "\\.[0-9]+" x)
  5290. (string-to-number (substring (match-string 0 x) 1)))))))
  5291. (if (eq var 'eval)
  5292. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5293. (if opt
  5294. (setq varform
  5295. `(if (equal "" ,var)
  5296. ""
  5297. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5298. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5299. (setq s (replace-match "%s" t nil s))
  5300. (push varform vars))
  5301. (setq vars (nreverse vars))
  5302. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5303. (defun org-set-sorting-strategy (key)
  5304. (if (symbolp (car org-agenda-sorting-strategy))
  5305. ;; the old format
  5306. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5307. (setq org-agenda-sorting-strategy-selected
  5308. (or (cdr (assq key org-agenda-sorting-strategy))
  5309. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5310. '(time-up category-keep priority-down)))))
  5311. (defun org-get-time-of-day (s &optional string mod24)
  5312. "Check string S for a time of day.
  5313. If found, return it as a military time number between 0 and 2400.
  5314. If not found, return nil.
  5315. The optional STRING argument forces conversion into a 5 character wide string
  5316. HH:MM."
  5317. (save-match-data
  5318. (when
  5319. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5320. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5321. (let* ((h (string-to-number (match-string 1 s)))
  5322. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5323. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5324. (am-p (equal ampm "am"))
  5325. (h1 (cond ((not ampm) h)
  5326. ((= h 12) (if am-p 0 12))
  5327. (t (+ h (if am-p 0 12)))))
  5328. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5329. (mod h1 24) h1))
  5330. (t0 (+ (* 100 h2) m))
  5331. (t1 (concat (if (>= h1 24) "+" " ")
  5332. (if (and org-agenda-time-leading-zero
  5333. (< t0 1000)) "0" "")
  5334. (if (< t0 100) "0" "")
  5335. (if (< t0 10) "0" "")
  5336. (int-to-string t0))))
  5337. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5338. (defvar org-agenda-before-sorting-filter-function nil
  5339. "Function to be applied to agenda items prior to sorting.
  5340. Prior to sorting also means just before they are inserted into the agenda.
  5341. To aid sorting, you may revisit the original entries and add more text
  5342. properties which will later be used by the sorting functions.
  5343. The function should take a string argument, an agenda line.
  5344. It has access to the text properties in that line, which contain among
  5345. other things, the property `org-hd-marker' that points to the entry
  5346. where the line comes from. Note that not all lines going into the agenda
  5347. have this property, only most.
  5348. The function should return the modified string. It is probably best
  5349. to ONLY change text properties.
  5350. You can also use this function as a filter, by returning nil for lines
  5351. you don't want to have in the agenda at all. For this application, you
  5352. could bind the variable in the options section of a custom command.")
  5353. (defun org-finalize-agenda-entries (list &optional nosort)
  5354. "Sort and concatenate the agenda items."
  5355. (setq list (mapcar 'org-agenda-highlight-todo list))
  5356. (if nosort
  5357. list
  5358. (when org-agenda-before-sorting-filter-function
  5359. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5360. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5361. (defun org-agenda-highlight-todo (x)
  5362. (let ((org-done-keywords org-done-keywords-for-agenda)
  5363. (case-fold-search nil)
  5364. re)
  5365. (if (eq x 'line)
  5366. (save-excursion
  5367. (beginning-of-line 1)
  5368. (setq re (org-get-at-bol 'org-todo-regexp))
  5369. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5370. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5371. (add-text-properties (match-beginning 0) (match-end 1)
  5372. (list 'face (org-get-todo-face 1)))
  5373. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5374. (delete-region (match-beginning 1) (1- (match-end 0)))
  5375. (goto-char (match-beginning 1))
  5376. (insert (format org-agenda-todo-keyword-format s)))))
  5377. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5378. (setq re (get-text-property 0 'org-todo-regexp x))
  5379. (when (and re
  5380. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5381. x (or pl 0)) pl))
  5382. (add-text-properties
  5383. (or (match-end 1) (match-end 0)) (match-end 0)
  5384. (list 'face (org-get-todo-face (match-string 2 x)))
  5385. x)
  5386. (when (match-end 1)
  5387. (setq x (concat (substring x 0 (match-end 1))
  5388. (format org-agenda-todo-keyword-format
  5389. (match-string 2 x))
  5390. (org-add-props " " (text-properties-at 0 x))
  5391. (substring x (match-end 3)))))))
  5392. x)))
  5393. (defsubst org-cmp-priority (a b)
  5394. "Compare the priorities of string A and B."
  5395. (let ((pa (or (get-text-property 1 'priority a) 0))
  5396. (pb (or (get-text-property 1 'priority b) 0)))
  5397. (cond ((> pa pb) +1)
  5398. ((< pa pb) -1)
  5399. (t nil))))
  5400. (defsubst org-cmp-effort (a b)
  5401. "Compare the priorities of string A and B."
  5402. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5403. (ea (or (get-text-property 1 'effort-minutes a) def))
  5404. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5405. (cond ((> ea eb) +1)
  5406. ((< ea eb) -1)
  5407. (t nil))))
  5408. (defsubst org-cmp-category (a b)
  5409. "Compare the string values of categories of strings A and B."
  5410. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5411. (cb (or (get-text-property 1 'org-category b) "")))
  5412. (cond ((string-lessp ca cb) -1)
  5413. ((string-lessp cb ca) +1)
  5414. (t nil))))
  5415. (defsubst org-cmp-todo-state (a b)
  5416. "Compare the todo states of strings A and B."
  5417. (let* ((ma (or (get-text-property 1 'org-marker a)
  5418. (get-text-property 1 'org-hd-marker a)))
  5419. (mb (or (get-text-property 1 'org-marker b)
  5420. (get-text-property 1 'org-hd-marker b)))
  5421. (fa (and ma (marker-buffer ma)))
  5422. (fb (and mb (marker-buffer mb)))
  5423. (todo-kwds
  5424. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5425. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5426. (ta (or (get-text-property 1 'todo-state a) ""))
  5427. (tb (or (get-text-property 1 'todo-state b) ""))
  5428. (la (- (length (member ta todo-kwds))))
  5429. (lb (- (length (member tb todo-kwds))))
  5430. (donepa (member ta org-done-keywords-for-agenda))
  5431. (donepb (member tb org-done-keywords-for-agenda)))
  5432. (cond ((and donepa (not donepb)) -1)
  5433. ((and (not donepa) donepb) +1)
  5434. ((< la lb) -1)
  5435. ((< lb la) +1)
  5436. (t nil))))
  5437. (defsubst org-cmp-alpha (a b)
  5438. "Compare the headlines, alphabetically."
  5439. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5440. (plb (text-property-any 0 (length b) 'org-heading t b))
  5441. (ta (and pla (substring a pla)))
  5442. (tb (and plb (substring b plb))))
  5443. (when pla
  5444. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5445. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5446. (setq ta (substring ta (match-end 0))))
  5447. (setq ta (downcase ta)))
  5448. (when plb
  5449. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5450. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5451. (setq tb (substring tb (match-end 0))))
  5452. (setq tb (downcase tb)))
  5453. (cond ((not ta) +1)
  5454. ((not tb) -1)
  5455. ((string-lessp ta tb) -1)
  5456. ((string-lessp tb ta) +1)
  5457. (t nil))))
  5458. (defsubst org-cmp-tag (a b)
  5459. "Compare the string values of the first tags of A and B."
  5460. (let ((ta (car (last (get-text-property 1 'tags a))))
  5461. (tb (car (last (get-text-property 1 'tags b)))))
  5462. (cond ((not ta) +1)
  5463. ((not tb) -1)
  5464. ((string-lessp ta tb) -1)
  5465. ((string-lessp tb ta) +1)
  5466. (t nil))))
  5467. (defsubst org-cmp-time (a b)
  5468. "Compare the time-of-day values of strings A and B."
  5469. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5470. (ta (or (get-text-property 1 'time-of-day a) def))
  5471. (tb (or (get-text-property 1 'time-of-day b) def)))
  5472. (cond ((< ta tb) -1)
  5473. ((< tb ta) +1)
  5474. (t nil))))
  5475. (defsubst org-cmp-habit-p (a b)
  5476. "Compare the todo states of strings A and B."
  5477. (let ((ha (get-text-property 1 'org-habit-p a))
  5478. (hb (get-text-property 1 'org-habit-p b)))
  5479. (cond ((and ha (not hb)) -1)
  5480. ((and (not ha) hb) +1)
  5481. (t nil))))
  5482. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5483. (defun org-entries-lessp (a b)
  5484. "Predicate for sorting agenda entries."
  5485. ;; The following variables will be used when the form is evaluated.
  5486. ;; So even though the compiler complains, keep them.
  5487. (let* ((ss org-agenda-sorting-strategy-selected)
  5488. (time-up (and (org-em 'time-up 'time-down ss)
  5489. (org-cmp-time a b)))
  5490. (time-down (if time-up (- time-up) nil))
  5491. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5492. (org-cmp-priority a b)))
  5493. (priority-down (if priority-up (- priority-up) nil))
  5494. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5495. (org-cmp-effort a b)))
  5496. (effort-down (if effort-up (- effort-up) nil))
  5497. (category-up (and (or (org-em 'category-up 'category-down ss)
  5498. (memq 'category-keep ss))
  5499. (org-cmp-category a b)))
  5500. (category-down (if category-up (- category-up) nil))
  5501. (category-keep (if category-up +1 nil))
  5502. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5503. (org-cmp-tag a b)))
  5504. (tag-down (if tag-up (- tag-up) nil))
  5505. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5506. (org-cmp-todo-state a b)))
  5507. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5508. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5509. (org-cmp-habit-p a b)))
  5510. (habit-down (if habit-up (- habit-up) nil))
  5511. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5512. (org-cmp-alpha a b)))
  5513. (alpha-down (if alpha-up (- alpha-up) nil))
  5514. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5515. user-defined-up user-defined-down)
  5516. (if (and need-user-cmp org-agenda-cmp-user-defined
  5517. (functionp org-agenda-cmp-user-defined))
  5518. (setq user-defined-up
  5519. (funcall org-agenda-cmp-user-defined a b)
  5520. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5521. (cdr (assoc
  5522. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5523. '((-1 . t) (1 . nil) (nil . nil))))))
  5524. ;;; Agenda restriction lock
  5525. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5526. "Overlay to mark the headline to which agenda commands are restricted.")
  5527. (overlay-put org-agenda-restriction-lock-overlay
  5528. 'face 'org-agenda-restriction-lock)
  5529. (overlay-put org-agenda-restriction-lock-overlay
  5530. 'help-echo "Agendas are currently limited to this subtree.")
  5531. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5532. (defun org-agenda-set-restriction-lock (&optional type)
  5533. "Set restriction lock for agenda, to current subtree or file.
  5534. Restriction will be the file if TYPE is `file', or if type is the
  5535. universal prefix '(4), or if the cursor is before the first headline
  5536. in the file. Otherwise, restriction will be to the current subtree."
  5537. (interactive "P")
  5538. (and (equal type '(4)) (setq type 'file))
  5539. (setq type (cond
  5540. (type type)
  5541. ((org-at-heading-p) 'subtree)
  5542. ((condition-case nil (org-back-to-heading t) (error nil))
  5543. 'subtree)
  5544. (t 'file)))
  5545. (if (eq type 'subtree)
  5546. (progn
  5547. (setq org-agenda-restrict t)
  5548. (setq org-agenda-overriding-restriction 'subtree)
  5549. (put 'org-agenda-files 'org-restrict
  5550. (list (buffer-file-name (buffer-base-buffer))))
  5551. (org-back-to-heading t)
  5552. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5553. (move-marker org-agenda-restrict-begin (point))
  5554. (move-marker org-agenda-restrict-end
  5555. (save-excursion (org-end-of-subtree t)))
  5556. (message "Locking agenda restriction to subtree"))
  5557. (put 'org-agenda-files 'org-restrict
  5558. (list (buffer-file-name (buffer-base-buffer))))
  5559. (setq org-agenda-restrict nil)
  5560. (setq org-agenda-overriding-restriction 'file)
  5561. (move-marker org-agenda-restrict-begin nil)
  5562. (move-marker org-agenda-restrict-end nil)
  5563. (message "Locking agenda restriction to file"))
  5564. (setq current-prefix-arg nil)
  5565. (org-agenda-maybe-redo))
  5566. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5567. "Remove the agenda restriction lock."
  5568. (interactive "P")
  5569. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5570. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5571. (setq org-agenda-overriding-restriction nil)
  5572. (setq org-agenda-restrict nil)
  5573. (put 'org-agenda-files 'org-restrict nil)
  5574. (move-marker org-agenda-restrict-begin nil)
  5575. (move-marker org-agenda-restrict-end nil)
  5576. (setq current-prefix-arg nil)
  5577. (message "Agenda restriction lock removed")
  5578. (or noupdate (org-agenda-maybe-redo)))
  5579. (defun org-agenda-maybe-redo ()
  5580. "If there is any window showing the agenda view, update it."
  5581. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5582. (w0 (selected-window)))
  5583. (when w
  5584. (select-window w)
  5585. (org-agenda-redo)
  5586. (select-window w0)
  5587. (if org-agenda-overriding-restriction
  5588. (message "Agenda view shifted to new %s restriction"
  5589. org-agenda-overriding-restriction)
  5590. (message "Agenda restriction lock removed")))))
  5591. ;;; Agenda commands
  5592. (defun org-agenda-check-type (error &rest types)
  5593. "Check if agenda buffer is of allowed type.
  5594. If ERROR is non-nil, throw an error, otherwise just return nil."
  5595. (if (memq org-agenda-type types)
  5596. t
  5597. (if error
  5598. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5599. nil)))
  5600. (defun org-agenda-quit ()
  5601. "Exit agenda by removing the window or the buffer."
  5602. (interactive)
  5603. (if org-agenda-columns-active
  5604. (org-columns-quit)
  5605. (let ((buf (current-buffer)))
  5606. (if (eq org-agenda-window-setup 'other-frame)
  5607. (progn
  5608. (kill-buffer buf)
  5609. (org-agenda-reset-markers)
  5610. (org-columns-remove-overlays)
  5611. (setq org-agenda-archives-mode nil)
  5612. (delete-frame))
  5613. (and (not (eq org-agenda-window-setup 'current-window))
  5614. (not (one-window-p))
  5615. (delete-window))
  5616. (kill-buffer buf)
  5617. (org-agenda-reset-markers)
  5618. (org-columns-remove-overlays)
  5619. (setq org-agenda-archives-mode nil)))
  5620. ;; Maybe restore the pre-agenda window configuration.
  5621. (and org-agenda-restore-windows-after-quit
  5622. (not (eq org-agenda-window-setup 'other-frame))
  5623. org-pre-agenda-window-conf
  5624. (set-window-configuration org-pre-agenda-window-conf))))
  5625. (defun org-agenda-exit ()
  5626. "Exit agenda by removing the window or the buffer.
  5627. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5628. Org-mode buffers visited directly by the user will not be touched."
  5629. (interactive)
  5630. (org-release-buffers org-agenda-new-buffers)
  5631. (setq org-agenda-new-buffers nil)
  5632. (org-agenda-quit))
  5633. (defun org-agenda-execute (arg)
  5634. "Execute another agenda command, keeping same window.
  5635. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5636. in the agenda."
  5637. (interactive "P")
  5638. (let ((org-agenda-window-setup 'current-window))
  5639. (org-agenda arg)))
  5640. (defun org-agenda-redo ()
  5641. "Rebuild Agenda.
  5642. When this is the global TODO list, a prefix argument will be interpreted."
  5643. (interactive)
  5644. (let* ((org-agenda-keep-modes t)
  5645. (filter org-agenda-filter)
  5646. (preset (get 'org-agenda-filter :preset-filter))
  5647. (org-agenda-filter-while-redo (or filter preset))
  5648. (cols org-agenda-columns-active)
  5649. (line (org-current-line))
  5650. (window-line (- line (org-current-line (window-start))))
  5651. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5652. (put 'org-agenda-filter :preset-filter nil)
  5653. (and cols (org-columns-quit))
  5654. (message "Rebuilding agenda buffer...")
  5655. (org-let lprops '(eval org-agenda-redo-command))
  5656. (setq org-agenda-undo-list nil
  5657. org-agenda-pending-undo-list nil)
  5658. (message "Rebuilding agenda buffer...done")
  5659. (put 'org-agenda-filter :preset-filter preset)
  5660. (and (or filter preset) (org-agenda-filter-apply filter))
  5661. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5662. (org-goto-line line)
  5663. (recenter window-line)))
  5664. (defvar org-global-tags-completion-table nil)
  5665. (defvar org-agenda-filter-form nil)
  5666. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5667. "Keep only those lines in the agenda buffer that have a specific tag.
  5668. The tag is selected with its fast selection letter, as configured.
  5669. With prefix argument STRIP, remove all lines that do have the tag.
  5670. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5671. used to narrow the search - the interactive user can also press `-' or `+'
  5672. to switch to narrowing."
  5673. (interactive "P")
  5674. (let* ((alist org-tag-alist-for-agenda)
  5675. (tag-chars (mapconcat
  5676. (lambda (x) (if (and (not (symbolp (car x)))
  5677. (cdr x))
  5678. (char-to-string (cdr x))
  5679. ""))
  5680. alist ""))
  5681. (efforts (org-split-string
  5682. (or (cdr (assoc (concat org-effort-property "_ALL")
  5683. org-global-properties))
  5684. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5685. "")))
  5686. (effort-op org-agenda-filter-effort-default-operator)
  5687. (effort-prompt "")
  5688. (inhibit-read-only t)
  5689. (current org-agenda-filter)
  5690. maybe-refresh a n tag)
  5691. (unless char
  5692. (message
  5693. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5694. (if narrow "Narrow" "Filter") tag-chars
  5695. (if org-agenda-auto-exclude-function "[RET], " ""))
  5696. (setq char (read-char)))
  5697. (when (member char '(?+ ?-))
  5698. ;; Narrowing down
  5699. (cond ((equal char ?-) (setq strip t narrow t))
  5700. ((equal char ?+) (setq strip nil narrow t)))
  5701. (message
  5702. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5703. (setq char (read-char)))
  5704. (when (member char '(?< ?> ?= ??))
  5705. ;; An effort operator
  5706. (setq effort-op (char-to-string char))
  5707. (setq alist nil) ; to make sure it will be interpreted as effort.
  5708. (unless (equal char ??)
  5709. (loop for i from 0 to 9 do
  5710. (setq effort-prompt
  5711. (concat
  5712. effort-prompt " ["
  5713. (if (= i 9) "0" (int-to-string (1+ i)))
  5714. "]" (nth i efforts))))
  5715. (message "Effort%s: %s " effort-op effort-prompt)
  5716. (setq char (read-char))
  5717. (when (or (< char ?0) (> char ?9))
  5718. (error "Need 1-9,0 to select effort" ))))
  5719. (when (equal char ?\t)
  5720. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5721. (org-set-local 'org-global-tags-completion-table
  5722. (org-global-tags-completion-table)))
  5723. (let ((completion-ignore-case t))
  5724. (setq tag (org-icompleting-read
  5725. "Tag: " org-global-tags-completion-table))))
  5726. (cond
  5727. ((equal char ?\r)
  5728. (org-agenda-filter-by-tag-show-all)
  5729. (when org-agenda-auto-exclude-function
  5730. (setq org-agenda-filter '())
  5731. (dolist (tag (org-agenda-get-represented-tags))
  5732. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5733. (if modifier
  5734. (push modifier org-agenda-filter))))
  5735. (if (not (null org-agenda-filter))
  5736. (org-agenda-filter-apply org-agenda-filter)))
  5737. (setq maybe-refresh t))
  5738. ((equal char ?/)
  5739. (org-agenda-filter-by-tag-show-all)
  5740. (when (get 'org-agenda-filter :preset-filter)
  5741. (org-agenda-filter-apply org-agenda-filter))
  5742. (setq maybe-refresh t))
  5743. ((or (equal char ?\ )
  5744. (setq a (rassoc char alist))
  5745. (and (>= char ?0) (<= char ?9)
  5746. (setq n (if (= char ?0) 9 (- char ?0 1))
  5747. tag (concat effort-op (nth n efforts))
  5748. a (cons tag nil)))
  5749. (and (= char ??)
  5750. (setq tag "?eff")
  5751. a (cons tag nil))
  5752. (and tag (setq a (cons tag nil))))
  5753. (org-agenda-filter-by-tag-show-all)
  5754. (setq tag (car a))
  5755. (setq org-agenda-filter
  5756. (cons (concat (if strip "-" "+") tag)
  5757. (if narrow current nil)))
  5758. (org-agenda-filter-apply org-agenda-filter)
  5759. (setq maybe-refresh t))
  5760. (t (error "Invalid tag selection character %c" char)))
  5761. (when (and maybe-refresh
  5762. (eq org-agenda-clockreport-mode 'with-filter))
  5763. (org-agenda-redo))))
  5764. (defun org-agenda-get-represented-tags ()
  5765. "Get a list of all tags currently represented in the agenda."
  5766. (let (p tags)
  5767. (save-excursion
  5768. (goto-char (point-min))
  5769. (while (setq p (next-single-property-change (point) 'tags))
  5770. (goto-char p)
  5771. (mapc (lambda (x) (add-to-list 'tags x))
  5772. (get-text-property (point) 'tags))))
  5773. tags))
  5774. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5775. "Refine the current filter. See `org-agenda-filter-by-tag."
  5776. (interactive "P")
  5777. (org-agenda-filter-by-tag strip char 'refine))
  5778. (defun org-agenda-filter-make-matcher ()
  5779. "Create the form that tests a line for the agenda filter."
  5780. (let (f f1)
  5781. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5782. org-agenda-filter))
  5783. (if (member x '("-" "+"))
  5784. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5785. (if (string-match "[<=>?]" x)
  5786. (setq f1 (org-agenda-filter-effort-form x))
  5787. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5788. (if (equal (string-to-char x) ?-)
  5789. (setq f1 (list 'not f1))))
  5790. (push f1 f))
  5791. (cons 'and (nreverse f))))
  5792. (defun org-agenda-filter-effort-form (e)
  5793. "Return the form to compare the effort of the current line with what E says.
  5794. E looks like \"+<2:25\"."
  5795. (let (op)
  5796. (setq e (substring e 1))
  5797. (setq op (string-to-char e) e (substring e 1))
  5798. (setq op (cond ((equal op ?<) '<=)
  5799. ((equal op ?>) '>=)
  5800. ((equal op ??) op)
  5801. (t '=)))
  5802. (list 'org-agenda-compare-effort (list 'quote op)
  5803. (org-duration-string-to-minutes e))))
  5804. (defun org-agenda-compare-effort (op value)
  5805. "Compare the effort of the current line with VALUE, using OP.
  5806. If the line does not have an effort defined, return nil."
  5807. (let ((eff (org-get-at-bol 'effort-minutes)))
  5808. (if (equal op ??)
  5809. (not eff)
  5810. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5811. value))))
  5812. (defun org-agenda-filter-apply (filter)
  5813. "Set FILTER as the new agenda filter and apply it."
  5814. (let (tags)
  5815. (setq org-agenda-filter filter
  5816. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5817. (org-agenda-set-mode-name)
  5818. (save-excursion
  5819. (goto-char (point-min))
  5820. (while (not (eobp))
  5821. (if (org-get-at-bol 'org-marker)
  5822. (progn
  5823. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5824. (if (not (eval org-agenda-filter-form))
  5825. (org-agenda-filter-by-tag-hide-line))
  5826. (beginning-of-line 2))
  5827. (beginning-of-line 2))))
  5828. (if (get-char-property (point) 'invisible)
  5829. (org-agenda-previous-line))))
  5830. (defun org-agenda-filter-by-tag-hide-line ()
  5831. (let (ov)
  5832. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5833. (point-at-eol)))
  5834. (overlay-put ov 'invisible t)
  5835. (overlay-put ov 'type 'tags-filter)
  5836. (push ov org-agenda-filter-overlays)))
  5837. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5838. (setq pos (or pos (point)))
  5839. (save-excursion
  5840. (dolist (ov (overlays-at pos))
  5841. (when (and (overlay-get ov 'invisible)
  5842. (eq (overlay-get ov 'type) 'tags-filter))
  5843. (goto-char pos)
  5844. (if (< (overlay-start ov) (point-at-eol))
  5845. (move-overlay ov (point-at-eol)
  5846. (overlay-end ov)))))))
  5847. (defun org-agenda-filter-by-tag-show-all ()
  5848. (mapc 'delete-overlay org-agenda-filter-overlays)
  5849. (setq org-agenda-filter-overlays nil)
  5850. (setq org-agenda-filter nil)
  5851. (setq org-agenda-filter-form nil)
  5852. (org-agenda-set-mode-name))
  5853. (defun org-agenda-manipulate-query-add ()
  5854. "Manipulate the query by adding a search term with positive selection.
  5855. Positive selection means the term must be matched for selection of an entry."
  5856. (interactive)
  5857. (org-agenda-manipulate-query ?\[))
  5858. (defun org-agenda-manipulate-query-subtract ()
  5859. "Manipulate the query by adding a search term with negative selection.
  5860. Negative selection means term must not be matched for selection of an entry."
  5861. (interactive)
  5862. (org-agenda-manipulate-query ?\]))
  5863. (defun org-agenda-manipulate-query-add-re ()
  5864. "Manipulate the query by adding a search regexp with positive selection.
  5865. Positive selection means the regexp must match for selection of an entry."
  5866. (interactive)
  5867. (org-agenda-manipulate-query ?\{))
  5868. (defun org-agenda-manipulate-query-subtract-re ()
  5869. "Manipulate the query by adding a search regexp with negative selection.
  5870. Negative selection means regexp must not match for selection of an entry."
  5871. (interactive)
  5872. (org-agenda-manipulate-query ?\}))
  5873. (defun org-agenda-manipulate-query (char)
  5874. (cond
  5875. ((memq org-agenda-type '(timeline agenda))
  5876. (let ((org-agenda-include-inactive-timestamps t))
  5877. (org-agenda-redo))
  5878. (message "Display now includes inactive timestamps as well"))
  5879. ((eq org-agenda-type 'search)
  5880. (org-add-to-string
  5881. 'org-agenda-query-string
  5882. (if org-agenda-last-search-view-search-was-boolean
  5883. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5884. (?\{ . " +{}") (?\} . " -{}"))))
  5885. " "))
  5886. (setq org-agenda-redo-command
  5887. (list 'org-search-view
  5888. org-todo-only
  5889. org-agenda-query-string
  5890. (+ (length org-agenda-query-string)
  5891. (if (member char '(?\{ ?\})) 0 1))))
  5892. (set-register org-agenda-query-register org-agenda-query-string)
  5893. (org-agenda-redo))
  5894. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5895. org-agenda-type))))
  5896. (defun org-add-to-string (var string)
  5897. (set var (concat (symbol-value var) string)))
  5898. (defun org-agenda-goto-date (date)
  5899. "Jump to DATE in agenda."
  5900. (interactive (list (let ((org-read-date-prefer-future
  5901. (eval org-agenda-jump-prefer-future)))
  5902. (org-read-date))))
  5903. (org-agenda-list nil date))
  5904. (defun org-agenda-goto-today ()
  5905. "Go to today."
  5906. (interactive)
  5907. (org-agenda-check-type t 'timeline 'agenda)
  5908. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5909. (cond
  5910. (tdpos (goto-char tdpos))
  5911. ((eq org-agenda-type 'agenda)
  5912. (let* ((sd (org-agenda-compute-starting-span
  5913. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5914. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5915. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5916. (org-agenda-redo)
  5917. (org-agenda-find-same-or-today-or-agenda)))
  5918. (t (error "Cannot find today")))))
  5919. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5920. (goto-char
  5921. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5922. (text-property-any (point-min) (point-max) 'org-today t)
  5923. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5924. (point-min))))
  5925. (defun org-agenda-later (arg)
  5926. "Go forward in time by thee current span.
  5927. With prefix ARG, go forward that many times the current span."
  5928. (interactive "p")
  5929. (org-agenda-check-type t 'agenda)
  5930. (let* ((span org-agenda-current-span)
  5931. (sd org-starting-day)
  5932. (greg (calendar-gregorian-from-absolute sd))
  5933. (cnt (org-get-at-bol 'org-day-cnt))
  5934. greg2)
  5935. (cond
  5936. ((eq span 'day)
  5937. (setq sd (+ arg sd)))
  5938. ((eq span 'week)
  5939. (setq sd (+ (* 7 arg) sd)))
  5940. ((eq span 'month)
  5941. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5942. sd (calendar-absolute-from-gregorian greg2))
  5943. (setcar greg2 (1+ (car greg2))))
  5944. ((eq span 'year)
  5945. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5946. sd (calendar-absolute-from-gregorian greg2))
  5947. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5948. (t
  5949. (setq sd (+ (* span arg) sd))))
  5950. (let ((org-agenda-overriding-arguments
  5951. (list (car org-agenda-last-arguments) sd span t)))
  5952. (org-agenda-redo)
  5953. (org-agenda-find-same-or-today-or-agenda cnt))))
  5954. (defun org-agenda-earlier (arg)
  5955. "Go backward in time by the current span.
  5956. With prefix ARG, go backward that many times the current span."
  5957. (interactive "p")
  5958. (org-agenda-later (- arg)))
  5959. (defun org-agenda-view-mode-dispatch ()
  5960. "Call one of the view mode commands."
  5961. (interactive)
  5962. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5963. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5964. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5965. [E]ntryText")
  5966. (let ((a (read-char-exclusive)))
  5967. (case a
  5968. (?\ (call-interactively 'org-agenda-reset-view))
  5969. (?d (call-interactively 'org-agenda-day-view))
  5970. (?w (call-interactively 'org-agenda-week-view))
  5971. (?m (call-interactively 'org-agenda-month-view))
  5972. (?y (call-interactively 'org-agenda-year-view))
  5973. (?l (call-interactively 'org-agenda-log-mode))
  5974. (?L (org-agenda-log-mode '(4)))
  5975. (?c (org-agenda-log-mode 'clockcheck))
  5976. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5977. (?a (call-interactively 'org-agenda-archives-mode))
  5978. (?A (org-agenda-archives-mode 'files))
  5979. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5980. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5981. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5982. (?D (call-interactively 'org-agenda-toggle-diary))
  5983. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5984. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5985. (org-agenda-check-type t 'timeline 'agenda)
  5986. (org-agenda-redo))
  5987. (message "Display now includes inactive timestamps as well"))
  5988. (?q (message "Abort"))
  5989. (otherwise (error "Invalid key" )))))
  5990. (defun org-agenda-reset-view ()
  5991. "Switch to default view for agenda."
  5992. (interactive)
  5993. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5994. (defun org-agenda-day-view (&optional day-of-year)
  5995. "Switch to daily view for agenda.
  5996. With argument DAY-OF-YEAR, switch to that day of the year."
  5997. (interactive "P")
  5998. (org-agenda-change-time-span 'day day-of-year))
  5999. (defun org-agenda-week-view (&optional iso-week)
  6000. "Switch to daily view for agenda.
  6001. With argument ISO-WEEK, switch to the corresponding ISO week.
  6002. If ISO-WEEK has more then 2 digits, only the last two encode the
  6003. week. Any digits before this encode a year. So 200712 means
  6004. week 12 of year 2007. Years in the range 1938-2037 can also be
  6005. written as 2-digit years."
  6006. (interactive "P")
  6007. (org-agenda-change-time-span 'week iso-week))
  6008. (defun org-agenda-month-view (&optional month)
  6009. "Switch to monthly view for agenda.
  6010. With argument MONTH, switch to that month."
  6011. (interactive "P")
  6012. (org-agenda-change-time-span 'month month))
  6013. (defun org-agenda-year-view (&optional year)
  6014. "Switch to yearly view for agenda.
  6015. With argument YEAR, switch to that year.
  6016. If MONTH has more then 2 digits, only the last two encode the
  6017. month. Any digits before this encode a year. So 200712 means
  6018. December year 2007. Years in the range 1938-2037 can also be
  6019. written as 2-digit years."
  6020. (interactive "P")
  6021. (when year
  6022. (setq year (org-small-year-to-year year)))
  6023. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6024. (org-agenda-change-time-span 'year year)
  6025. (error "Abort")))
  6026. (defun org-agenda-change-time-span (span &optional n)
  6027. "Change the agenda view to SPAN.
  6028. SPAN may be `day', `week', `month', `year'."
  6029. (org-agenda-check-type t 'agenda)
  6030. (if (and (not n) (equal org-agenda-current-span span))
  6031. (error "Viewing span is already \"%s\"" span))
  6032. (let* ((sd (or (org-get-at-bol 'day)
  6033. org-starting-day))
  6034. (sd (org-agenda-compute-starting-span sd span n))
  6035. (org-agenda-overriding-arguments
  6036. (or org-agenda-overriding-arguments
  6037. (list (car org-agenda-last-arguments) sd span t))))
  6038. (org-agenda-redo)
  6039. (org-agenda-find-same-or-today-or-agenda))
  6040. (org-agenda-set-mode-name)
  6041. (message "Switched to %s view" span))
  6042. (defun org-agenda-compute-starting-span (sd span &optional n)
  6043. "Compute starting date for agenda.
  6044. SPAN may be `day', `week', `month', `year'. The return value
  6045. is a cons cell with the starting date and the number of days,
  6046. so that the date SD will be in that range."
  6047. (let* ((greg (calendar-gregorian-from-absolute sd))
  6048. (dg (nth 1 greg))
  6049. (mg (car greg))
  6050. (yg (nth 2 greg)))
  6051. (cond
  6052. ((eq span 'day)
  6053. (when n
  6054. (setq sd (+ (calendar-absolute-from-gregorian
  6055. (list mg 1 yg))
  6056. n -1))))
  6057. ((eq span 'week)
  6058. (let* ((nt (calendar-day-of-week
  6059. (calendar-gregorian-from-absolute sd)))
  6060. (d (if org-agenda-start-on-weekday
  6061. (- nt org-agenda-start-on-weekday)
  6062. 0))
  6063. y1)
  6064. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6065. (when n
  6066. (require 'cal-iso)
  6067. (when (> n 99)
  6068. (setq y1 (org-small-year-to-year (/ n 100))
  6069. n (mod n 100)))
  6070. (setq sd
  6071. (calendar-absolute-from-iso
  6072. (list n 1
  6073. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6074. ((eq span 'month)
  6075. (let (y1)
  6076. (when (and n (> n 99))
  6077. (setq y1 (org-small-year-to-year (/ n 100))
  6078. n (mod n 100)))
  6079. (setq sd (calendar-absolute-from-gregorian
  6080. (list (or n mg) 1 (or y1 yg))))))
  6081. ((eq span 'year)
  6082. (setq sd (calendar-absolute-from-gregorian
  6083. (list 1 1 (or n yg))))))
  6084. sd))
  6085. (defun org-agenda-next-date-line (&optional arg)
  6086. "Jump to the next line indicating a date in agenda buffer."
  6087. (interactive "p")
  6088. (org-agenda-check-type t 'agenda 'timeline)
  6089. (beginning-of-line 1)
  6090. ;; This does not work if user makes date format that starts with a blank
  6091. (if (looking-at "^\\S-") (forward-char 1))
  6092. (if (not (re-search-forward "^\\S-" nil t arg))
  6093. (progn
  6094. (backward-char 1)
  6095. (error "No next date after this line in this buffer")))
  6096. (goto-char (match-beginning 0)))
  6097. (defun org-agenda-previous-date-line (&optional arg)
  6098. "Jump to the previous line indicating a date in agenda buffer."
  6099. (interactive "p")
  6100. (org-agenda-check-type t 'agenda 'timeline)
  6101. (beginning-of-line 1)
  6102. (if (not (re-search-backward "^\\S-" nil t arg))
  6103. (error "No previous date before this line in this buffer")))
  6104. ;; Initialize the highlight
  6105. (defvar org-hl (make-overlay 1 1))
  6106. (overlay-put org-hl 'face 'highlight)
  6107. (defun org-highlight (begin end &optional buffer)
  6108. "Highlight a region with overlay."
  6109. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6110. (defun org-unhighlight ()
  6111. "Detach overlay INDEX."
  6112. (org-detach-overlay org-hl))
  6113. ;; FIXME this is currently not used.
  6114. (defun org-highlight-until-next-command (beg end &optional buffer)
  6115. "Move the highlight overlay to BEG/END, remove it before the next command."
  6116. (org-highlight beg end buffer)
  6117. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6118. (defun org-unhighlight-once ()
  6119. "Remove the highlight from its position, and this function from the hook."
  6120. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6121. (org-unhighlight))
  6122. (defun org-agenda-follow-mode ()
  6123. "Toggle follow mode in an agenda buffer."
  6124. (interactive)
  6125. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6126. (org-agenda-set-mode-name)
  6127. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6128. (org-agenda-show))
  6129. (message "Follow mode is %s"
  6130. (if org-agenda-follow-mode "on" "off")))
  6131. (defun org-agenda-entry-text-mode (&optional arg)
  6132. "Toggle entry text mode in an agenda buffer."
  6133. (interactive "P")
  6134. (setq org-agenda-entry-text-mode (or (integerp arg)
  6135. (not org-agenda-entry-text-mode)))
  6136. (org-agenda-entry-text-hide)
  6137. (and org-agenda-entry-text-mode
  6138. (let ((org-agenda-entry-text-maxlines
  6139. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6140. (org-agenda-entry-text-show)))
  6141. (org-agenda-set-mode-name)
  6142. (message "Entry text mode is %s. Maximum number of lines is %d"
  6143. (if org-agenda-entry-text-mode "on" "off")
  6144. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6145. (defun org-agenda-clockreport-mode (&optional with-filter)
  6146. "Toggle clocktable mode in an agenda buffer.
  6147. With prefix arg WITH-FILTER, make the clocktable respect the current
  6148. agenda filter."
  6149. (interactive "P")
  6150. (org-agenda-check-type t 'agenda)
  6151. (if with-filter
  6152. (setq org-agenda-clockreport-mode 'with-filter)
  6153. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6154. (org-agenda-set-mode-name)
  6155. (org-agenda-redo)
  6156. (message "Clocktable mode is %s"
  6157. (if org-agenda-clockreport-mode "on" "off")))
  6158. (defun org-agenda-log-mode (&optional special)
  6159. "Toggle log mode in an agenda buffer.
  6160. With argument SPECIAL, show all possible log items, not only the ones
  6161. configured in `org-agenda-log-mode-items'.
  6162. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6163. (interactive "P")
  6164. (org-agenda-check-type t 'agenda 'timeline)
  6165. (setq org-agenda-show-log
  6166. (cond
  6167. ((equal special '(16)) 'only)
  6168. ((eq special 'clockcheck)
  6169. (if (eq org-agenda-show-log 'clockcheck)
  6170. nil 'clockcheck))
  6171. (special '(closed clock state))
  6172. (t (not org-agenda-show-log))))
  6173. (org-agenda-set-mode-name)
  6174. (org-agenda-redo)
  6175. (message "Log mode is %s"
  6176. (if org-agenda-show-log "on" "off")))
  6177. (defun org-agenda-archives-mode (&optional with-files)
  6178. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6179. When called with a prefix argument, include all archive files as well."
  6180. (interactive "P")
  6181. (setq org-agenda-archives-mode
  6182. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6183. (org-agenda-set-mode-name)
  6184. (org-agenda-redo)
  6185. (message
  6186. "%s"
  6187. (cond
  6188. ((eq org-agenda-archives-mode nil)
  6189. "No archives are included")
  6190. ((eq org-agenda-archives-mode 'trees)
  6191. (format "Trees with :%s: tag are included" org-archive-tag))
  6192. ((eq org-agenda-archives-mode t)
  6193. (format "Trees with :%s: tag and all active archive files are included"
  6194. org-archive-tag)))))
  6195. (defun org-agenda-toggle-diary ()
  6196. "Toggle diary inclusion in an agenda buffer."
  6197. (interactive)
  6198. (org-agenda-check-type t 'agenda)
  6199. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6200. (org-agenda-redo)
  6201. (org-agenda-set-mode-name)
  6202. (message "Diary inclusion turned %s"
  6203. (if org-agenda-include-diary "on" "off")))
  6204. (defun org-agenda-toggle-deadlines ()
  6205. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6206. (interactive)
  6207. (org-agenda-check-type t 'agenda)
  6208. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6209. (org-agenda-redo)
  6210. (org-agenda-set-mode-name)
  6211. (message "Deadlines inclusion turned %s"
  6212. (if org-agenda-include-deadlines "on" "off")))
  6213. (defun org-agenda-toggle-time-grid ()
  6214. "Toggle time grid in an agenda buffer."
  6215. (interactive)
  6216. (org-agenda-check-type t 'agenda)
  6217. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6218. (org-agenda-redo)
  6219. (org-agenda-set-mode-name)
  6220. (message "Time-grid turned %s"
  6221. (if org-agenda-use-time-grid "on" "off")))
  6222. (defun org-agenda-set-mode-name ()
  6223. "Set the mode name to indicate all the small mode settings."
  6224. (setq mode-name
  6225. (list "Org-Agenda"
  6226. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6227. " "
  6228. '(:eval (org-agenda-span-name org-agenda-current-span))
  6229. (if org-agenda-follow-mode " Follow" "")
  6230. (if org-agenda-entry-text-mode " ETxt" "")
  6231. (if org-agenda-include-diary " Diary" "")
  6232. (if org-agenda-include-deadlines " Ddl" "")
  6233. (if org-agenda-use-time-grid " Grid" "")
  6234. (if (and (boundp 'org-habit-show-habits)
  6235. org-habit-show-habits) " Habit" "")
  6236. (cond
  6237. ((consp org-agenda-show-log) " LogAll")
  6238. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6239. (org-agenda-show-log " Log")
  6240. (t ""))
  6241. (if (or org-agenda-filter (get 'org-agenda-filter
  6242. :preset-filter))
  6243. (concat " {" (mapconcat
  6244. 'identity
  6245. (append (get 'org-agenda-filter
  6246. :preset-filter)
  6247. org-agenda-filter) "") "}")
  6248. "")
  6249. (if org-agenda-archives-mode
  6250. (if (eq org-agenda-archives-mode t)
  6251. " Archives"
  6252. (format " :%s:" org-archive-tag))
  6253. "")
  6254. (if org-agenda-clockreport-mode
  6255. (if (eq org-agenda-clockreport-mode 'with-filter)
  6256. " Clock{}" " Clock")
  6257. "")))
  6258. (force-mode-line-update))
  6259. (defun org-agenda-post-command-hook ()
  6260. (setq org-agenda-type
  6261. (or (get-text-property (point) 'org-agenda-type)
  6262. (get-text-property (max (point-min) (1- (point)))
  6263. 'org-agenda-type))))
  6264. (defun org-agenda-next-line ()
  6265. "Move cursor to the next line, and show if follow mode is active."
  6266. (interactive)
  6267. (call-interactively 'next-line)
  6268. (org-agenda-do-context-action))
  6269. (defun org-agenda-previous-line ()
  6270. "Move cursor to the previous line, and show if follow-mode is active."
  6271. (interactive)
  6272. (call-interactively 'previous-line)
  6273. (org-agenda-do-context-action))
  6274. (defun org-agenda-do-context-action ()
  6275. "Show outline path and, maybe, follow mode window."
  6276. (let ((m (org-get-at-bol 'org-marker)))
  6277. (if (and org-agenda-follow-mode m)
  6278. (org-agenda-show))
  6279. (if (and m org-agenda-show-outline-path)
  6280. (org-with-point-at m
  6281. (org-display-outline-path t)))))
  6282. (defun org-agenda-show-priority ()
  6283. "Show the priority of the current item.
  6284. This priority is composed of the main priority given with the [#A] cookies,
  6285. and by additional input from the age of a schedules or deadline entry."
  6286. (interactive)
  6287. (let* ((pri (org-get-at-bol 'priority)))
  6288. (message "Priority is %d" (if pri pri -1000))))
  6289. (defun org-agenda-show-tags ()
  6290. "Show the tags applicable to the current item."
  6291. (interactive)
  6292. (let* ((tags (org-get-at-bol 'tags)))
  6293. (if tags
  6294. (message "Tags are :%s:"
  6295. (org-no-properties (mapconcat 'identity tags ":")))
  6296. (message "No tags associated with this line"))))
  6297. (defun org-agenda-goto (&optional highlight)
  6298. "Go to the Org-mode file which contains the item at point."
  6299. (interactive)
  6300. (let* ((marker (or (org-get-at-bol 'org-marker)
  6301. (org-agenda-error)))
  6302. (buffer (marker-buffer marker))
  6303. (pos (marker-position marker)))
  6304. (switch-to-buffer-other-window buffer)
  6305. (widen)
  6306. (push-mark)
  6307. (goto-char pos)
  6308. (when (org-mode-p)
  6309. (org-show-context 'agenda)
  6310. (save-excursion
  6311. (and (outline-next-heading)
  6312. (org-flag-heading nil)))) ; show the next heading
  6313. (when (outline-invisible-p)
  6314. (show-entry)) ; display invisible text
  6315. (recenter (/ (window-height) 2))
  6316. (run-hooks 'org-agenda-after-show-hook)
  6317. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6318. (defvar org-agenda-after-show-hook nil
  6319. "Normal hook run after an item has been shown from the agenda.
  6320. Point is in the buffer where the item originated.")
  6321. (defun org-agenda-kill ()
  6322. "Kill the entry or subtree belonging to the current agenda entry."
  6323. (interactive)
  6324. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6325. (let* ((marker (or (org-get-at-bol 'org-marker)
  6326. (org-agenda-error)))
  6327. (buffer (marker-buffer marker))
  6328. (pos (marker-position marker))
  6329. (type (org-get-at-bol 'type))
  6330. dbeg dend (n 0) conf)
  6331. (org-with-remote-undo buffer
  6332. (with-current-buffer buffer
  6333. (save-excursion
  6334. (goto-char pos)
  6335. (if (and (org-mode-p) (not (member type '("sexp"))))
  6336. (setq dbeg (progn (org-back-to-heading t) (point))
  6337. dend (org-end-of-subtree t t))
  6338. (setq dbeg (point-at-bol)
  6339. dend (min (point-max) (1+ (point-at-eol)))))
  6340. (goto-char dbeg)
  6341. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6342. (setq conf (or (eq t org-agenda-confirm-kill)
  6343. (and (numberp org-agenda-confirm-kill)
  6344. (> n org-agenda-confirm-kill))))
  6345. (and conf
  6346. (not (y-or-n-p
  6347. (format "Delete entry with %d lines in buffer \"%s\"? "
  6348. n (buffer-name buffer))))
  6349. (error "Abort"))
  6350. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6351. (with-current-buffer buffer (delete-region dbeg dend))
  6352. (message "Agenda item and source killed"))))
  6353. (defvar org-archive-default-command)
  6354. (defun org-agenda-archive-default ()
  6355. "Archive the entry or subtree belonging to the current agenda entry."
  6356. (interactive)
  6357. (require 'org-archive)
  6358. (org-agenda-archive-with org-archive-default-command))
  6359. (defun org-agenda-archive-default-with-confirmation ()
  6360. "Archive the entry or subtree belonging to the current agenda entry."
  6361. (interactive)
  6362. (require 'org-archive)
  6363. (org-agenda-archive-with org-archive-default-command 'confirm))
  6364. (defun org-agenda-archive ()
  6365. "Archive the entry or subtree belonging to the current agenda entry."
  6366. (interactive)
  6367. (org-agenda-archive-with 'org-archive-subtree))
  6368. (defun org-agenda-archive-to-archive-sibling ()
  6369. "Move the entry to the archive sibling."
  6370. (interactive)
  6371. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6372. (defun org-agenda-archive-with (cmd &optional confirm)
  6373. "Move the entry to the archive sibling."
  6374. (interactive)
  6375. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6376. (let* ((marker (or (org-get-at-bol 'org-marker)
  6377. (org-agenda-error)))
  6378. (buffer (marker-buffer marker))
  6379. (pos (marker-position marker)))
  6380. (org-with-remote-undo buffer
  6381. (with-current-buffer buffer
  6382. (if (org-mode-p)
  6383. (if (and confirm
  6384. (not (y-or-n-p "Archive this subtree or entry? ")))
  6385. (error "Abort")
  6386. (save-excursion
  6387. (goto-char pos)
  6388. (org-remove-subtree-entries-from-agenda)
  6389. (org-back-to-heading t)
  6390. (funcall cmd)))
  6391. (error "Archiving works only in Org-mode files"))))))
  6392. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6393. "Remove all lines in the agenda that correspond to a given subtree.
  6394. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6395. If this information is not given, the function uses the tree at point."
  6396. (let ((buf (or buf (current-buffer))) m p)
  6397. (save-excursion
  6398. (unless (and beg end)
  6399. (org-back-to-heading t)
  6400. (setq beg (point))
  6401. (org-end-of-subtree t)
  6402. (setq end (point)))
  6403. (set-buffer (get-buffer org-agenda-buffer-name))
  6404. (save-excursion
  6405. (goto-char (point-max))
  6406. (beginning-of-line 1)
  6407. (while (not (bobp))
  6408. (when (and (setq m (org-get-at-bol 'org-marker))
  6409. (equal buf (marker-buffer m))
  6410. (setq p (marker-position m))
  6411. (>= p beg)
  6412. (< p end))
  6413. (let ((inhibit-read-only t))
  6414. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6415. (beginning-of-line 0))))))
  6416. (defun org-agenda-refile (&optional goto rfloc no-update)
  6417. "Refile the item at point."
  6418. (interactive "P")
  6419. (if (equal goto '(16))
  6420. (org-refile-goto-last-stored)
  6421. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6422. (org-agenda-error)))
  6423. (buffer (marker-buffer marker))
  6424. (pos (marker-position marker))
  6425. (rfloc (or rfloc
  6426. (org-refile-get-location
  6427. (if goto "Goto" "Refile to") buffer
  6428. org-refile-allow-creating-parent-nodes))))
  6429. (with-current-buffer buffer
  6430. (save-excursion
  6431. (save-restriction
  6432. (widen)
  6433. (goto-char marker)
  6434. (org-remove-subtree-entries-from-agenda)
  6435. (org-refile goto buffer rfloc)))))
  6436. (unless no-update (org-agenda-redo))))
  6437. (defun org-agenda-open-link (&optional arg)
  6438. "Follow the link in the current line, if any.
  6439. This looks for a link in the displayed line in the agenda. It also looks
  6440. at the text of the entry itself."
  6441. (interactive "P")
  6442. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6443. (org-get-at-bol 'org-marker)))
  6444. (buffer (and marker (marker-buffer marker)))
  6445. (prefix (buffer-substring
  6446. (point-at-bol) (point-at-eol))))
  6447. (cond
  6448. (buffer
  6449. (with-current-buffer buffer
  6450. (save-excursion
  6451. (save-restriction
  6452. (widen)
  6453. (goto-char marker)
  6454. (org-offer-links-in-entry arg prefix)))))
  6455. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6456. (save-excursion
  6457. (beginning-of-line 1)
  6458. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6459. (org-open-link-from-string (match-string 1)))
  6460. (t (error "No link to open here")))))
  6461. (defun org-agenda-copy-local-variable (var)
  6462. "Get a variable from a referenced buffer and install it here."
  6463. (let ((m (org-get-at-bol 'org-marker)))
  6464. (when (and m (buffer-live-p (marker-buffer m)))
  6465. (org-set-local var (with-current-buffer (marker-buffer m)
  6466. (symbol-value var))))))
  6467. (defun org-agenda-switch-to (&optional delete-other-windows)
  6468. "Go to the Org-mode file which contains the item at point."
  6469. (interactive)
  6470. (if (and org-return-follows-link
  6471. (not (org-get-at-bol 'org-marker))
  6472. (org-in-regexp org-bracket-link-regexp))
  6473. (org-open-link-from-string (match-string 0))
  6474. (let* ((marker (or (org-get-at-bol 'org-marker)
  6475. (org-agenda-error)))
  6476. (buffer (marker-buffer marker))
  6477. (pos (marker-position marker)))
  6478. (org-pop-to-buffer-same-window buffer)
  6479. (and delete-other-windows (delete-other-windows))
  6480. (widen)
  6481. (goto-char pos)
  6482. (when (org-mode-p)
  6483. (org-show-context 'agenda)
  6484. (save-excursion
  6485. (and (outline-next-heading)
  6486. (org-flag-heading nil))) ; show the next heading
  6487. (when (outline-invisible-p)
  6488. (show-entry)))))) ; display invisible text
  6489. (defun org-agenda-goto-mouse (ev)
  6490. "Go to the Org-mode file which contains the item at the mouse click."
  6491. (interactive "e")
  6492. (mouse-set-point ev)
  6493. (org-agenda-goto))
  6494. (defun org-agenda-show (&optional full-entry)
  6495. "Display the Org-mode file which contains the item at point.
  6496. With prefix argument FULL-ENTRY, make the entire entry visible
  6497. if it was hidden in the outline."
  6498. (interactive "P")
  6499. (let ((win (selected-window)))
  6500. (if full-entry
  6501. (let ((org-show-entry-below t))
  6502. (org-agenda-goto t))
  6503. (org-agenda-goto t))
  6504. (select-window win)))
  6505. (defvar org-agenda-show-window nil)
  6506. (defun org-agenda-show-and-scroll-up ()
  6507. "Display the Org-mode file which contains the item at point.
  6508. When called repeatedly, scroll the window that is displaying the buffer."
  6509. (interactive)
  6510. (let ((win (selected-window)))
  6511. (if (and (window-live-p org-agenda-show-window)
  6512. (eq this-command last-command))
  6513. (progn
  6514. (select-window org-agenda-show-window)
  6515. (ignore-errors (scroll-up)))
  6516. (org-agenda-goto t)
  6517. (show-subtree)
  6518. (setq org-agenda-show-window (selected-window)))
  6519. (select-window win)))
  6520. (defun org-agenda-show-scroll-down ()
  6521. "Scroll down the window showing the agenda."
  6522. (interactive)
  6523. (let ((win (selected-window)))
  6524. (when (window-live-p org-agenda-show-window)
  6525. (select-window org-agenda-show-window)
  6526. (ignore-errors (scroll-down))
  6527. (select-window win))))
  6528. (defun org-agenda-show-1 (&optional more)
  6529. "Display the Org-mode file which contains the item at point.
  6530. The prefix arg selects the amount of information to display:
  6531. 0 hide the subtree
  6532. 1 just show the entry according to defaults.
  6533. 2 show the children view
  6534. 3 show the subtree view
  6535. 4 show the entire subtree and any LOGBOOK drawers
  6536. 5 show the entire subtree and any drawers
  6537. With prefix argument FULL-ENTRY, make the entire entry visible
  6538. if it was hidden in the outline."
  6539. (interactive "p")
  6540. (let ((win (selected-window)))
  6541. (org-agenda-goto t)
  6542. (org-recenter-heading 1)
  6543. (cond
  6544. ((= more 0)
  6545. (hide-subtree)
  6546. (save-excursion
  6547. (org-back-to-heading)
  6548. (run-hook-with-args 'org-cycle-hook 'folded))
  6549. (message "Remote: FOLDED"))
  6550. ((and (org-called-interactively-p 'any) (= more 1))
  6551. (message "Remote: show with default settings"))
  6552. ((= more 2)
  6553. (show-entry)
  6554. (show-children)
  6555. (save-excursion
  6556. (org-back-to-heading)
  6557. (run-hook-with-args 'org-cycle-hook 'children))
  6558. (message "Remote: CHILDREN"))
  6559. ((= more 3)
  6560. (show-subtree)
  6561. (save-excursion
  6562. (org-back-to-heading)
  6563. (run-hook-with-args 'org-cycle-hook 'subtree))
  6564. (message "Remote: SUBTREE"))
  6565. ((= more 4)
  6566. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6567. (org-drawer-regexp
  6568. (concat "^[ \t]*:\\("
  6569. (mapconcat 'regexp-quote org-drawers "\\|")
  6570. "\\):[ \t]*$")))
  6571. (show-subtree)
  6572. (save-excursion
  6573. (org-back-to-heading)
  6574. (org-cycle-hide-drawers 'subtree)))
  6575. (message "Remote: SUBTREE AND LOGBOOK"))
  6576. ((> more 4)
  6577. (show-subtree)
  6578. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6579. (select-window win)))
  6580. (defun org-recenter-heading (n)
  6581. (save-excursion
  6582. (org-back-to-heading)
  6583. (recenter n)))
  6584. (defvar org-agenda-cycle-counter nil)
  6585. (defun org-agenda-cycle-show (&optional n)
  6586. "Show the current entry in another window, with default settings.
  6587. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6588. When use repeatedly in immediate succession, the remote entry will cycle
  6589. through visibility
  6590. children -> subtree -> folded
  6591. When called with a numeric prefix arg, that arg will be passed through to
  6592. `org-agenda-show-1'. For the interpretation of that argument, see the
  6593. docstring of `org-agenda-show-1'."
  6594. (interactive "P")
  6595. (if (integerp n)
  6596. (setq org-agenda-cycle-counter n)
  6597. (if (not (eq last-command this-command))
  6598. (setq org-agenda-cycle-counter 1)
  6599. (if (equal org-agenda-cycle-counter 0)
  6600. (setq org-agenda-cycle-counter 2)
  6601. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6602. (if (> org-agenda-cycle-counter 3)
  6603. (setq org-agenda-cycle-counter 0)))))
  6604. (org-agenda-show-1 org-agenda-cycle-counter))
  6605. (defun org-agenda-recenter (arg)
  6606. "Display the Org-mode file which contains the item at point and recenter."
  6607. (interactive "P")
  6608. (let ((win (selected-window)))
  6609. (org-agenda-goto t)
  6610. (recenter arg)
  6611. (select-window win)))
  6612. (defun org-agenda-show-mouse (ev)
  6613. "Display the Org-mode file which contains the item at the mouse click."
  6614. (interactive "e")
  6615. (mouse-set-point ev)
  6616. (org-agenda-show))
  6617. (defun org-agenda-check-no-diary ()
  6618. "Check if the entry is a diary link and abort if yes."
  6619. (if (org-get-at-bol 'org-agenda-diary-link)
  6620. (org-agenda-error)))
  6621. (defun org-agenda-error ()
  6622. (error "Command not allowed in this line"))
  6623. (defun org-agenda-tree-to-indirect-buffer ()
  6624. "Show the subtree corresponding to the current entry in an indirect buffer.
  6625. This calls the command `org-tree-to-indirect-buffer' from the original
  6626. Org-mode buffer.
  6627. With numerical prefix arg ARG, go up to this level and then take that tree.
  6628. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6629. use the dedicated frame)."
  6630. (interactive)
  6631. (org-agenda-check-no-diary)
  6632. (let* ((marker (or (org-get-at-bol 'org-marker)
  6633. (org-agenda-error)))
  6634. (buffer (marker-buffer marker))
  6635. (pos (marker-position marker)))
  6636. (with-current-buffer buffer
  6637. (save-excursion
  6638. (goto-char pos)
  6639. (call-interactively 'org-tree-to-indirect-buffer)))))
  6640. (defvar org-last-heading-marker (make-marker)
  6641. "Marker pointing to the headline that last changed its TODO state
  6642. by a remote command from the agenda.")
  6643. (defun org-agenda-todo-nextset ()
  6644. "Switch TODO entry to next sequence."
  6645. (interactive)
  6646. (org-agenda-todo 'nextset))
  6647. (defun org-agenda-todo-previousset ()
  6648. "Switch TODO entry to previous sequence."
  6649. (interactive)
  6650. (org-agenda-todo 'previousset))
  6651. (defun org-agenda-todo (&optional arg)
  6652. "Cycle TODO state of line at point, also in Org-mode file.
  6653. This changes the line at point, all other lines in the agenda referring to
  6654. the same tree node, and the headline of the tree node in the Org-mode file."
  6655. (interactive "P")
  6656. (org-agenda-check-no-diary)
  6657. (let* ((col (current-column))
  6658. (marker (or (org-get-at-bol 'org-marker)
  6659. (org-agenda-error)))
  6660. (buffer (marker-buffer marker))
  6661. (pos (marker-position marker))
  6662. (hdmarker (org-get-at-bol 'org-hd-marker))
  6663. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6664. (inhibit-read-only t)
  6665. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6666. (org-with-remote-undo buffer
  6667. (with-current-buffer buffer
  6668. (widen)
  6669. (goto-char pos)
  6670. (org-show-context 'agenda)
  6671. (save-excursion
  6672. (and (outline-next-heading)
  6673. (org-flag-heading nil))) ; show the next heading
  6674. (let ((current-prefix-arg arg))
  6675. (call-interactively 'org-todo))
  6676. (and (bolp) (forward-char 1))
  6677. (setq newhead (org-get-heading))
  6678. (when (and (org-bound-and-true-p
  6679. org-agenda-headline-snapshot-before-repeat)
  6680. (not (equal org-agenda-headline-snapshot-before-repeat
  6681. newhead))
  6682. todayp)
  6683. (setq newhead org-agenda-headline-snapshot-before-repeat
  6684. just-one t))
  6685. (save-excursion
  6686. (org-back-to-heading)
  6687. (move-marker org-last-heading-marker (point))))
  6688. (beginning-of-line 1)
  6689. (save-excursion
  6690. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6691. (org-move-to-column col))))
  6692. (defun org-agenda-add-note (&optional arg)
  6693. "Add a time-stamped note to the entry at point."
  6694. (interactive "P")
  6695. (org-agenda-check-no-diary)
  6696. (let* ((marker (or (org-get-at-bol 'org-marker)
  6697. (org-agenda-error)))
  6698. (buffer (marker-buffer marker))
  6699. (pos (marker-position marker))
  6700. (hdmarker (org-get-at-bol 'org-hd-marker))
  6701. (inhibit-read-only t))
  6702. (with-current-buffer buffer
  6703. (widen)
  6704. (goto-char pos)
  6705. (org-show-context 'agenda)
  6706. (save-excursion
  6707. (and (outline-next-heading)
  6708. (org-flag-heading nil))) ; show the next heading
  6709. (org-add-note))))
  6710. (defun org-agenda-change-all-lines (newhead hdmarker
  6711. &optional fixface just-this)
  6712. "Change all lines in the agenda buffer which match HDMARKER.
  6713. The new content of the line will be NEWHEAD (as modified by
  6714. `org-format-agenda-item'). HDMARKER is checked with
  6715. `equal' against all `org-hd-marker' text properties in the file.
  6716. If FIXFACE is non-nil, the face of each item is modified according to
  6717. the new TODO state.
  6718. If JUST-THIS is non-nil, change just the current line, not all.
  6719. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6720. (let* ((inhibit-read-only t)
  6721. (line (org-current-line))
  6722. (thetags (with-current-buffer (marker-buffer hdmarker)
  6723. (save-excursion (save-restriction (widen)
  6724. (goto-char hdmarker)
  6725. (org-get-tags-at)))))
  6726. props m pl undone-face done-face finish new dotime cat tags)
  6727. (save-excursion
  6728. (goto-char (point-max))
  6729. (beginning-of-line 1)
  6730. (while (not finish)
  6731. (setq finish (bobp))
  6732. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6733. (or (not just-this) (= (org-current-line) line))
  6734. (equal m hdmarker))
  6735. (setq props (text-properties-at (point))
  6736. dotime (org-get-at-bol 'dotime)
  6737. cat (org-get-at-bol 'org-category)
  6738. tags thetags
  6739. new
  6740. (let ((org-prefix-format-compiled
  6741. (or (get-text-property (point) 'format)
  6742. org-prefix-format-compiled)))
  6743. (with-current-buffer (marker-buffer hdmarker)
  6744. (save-excursion
  6745. (save-restriction
  6746. (widen)
  6747. (org-format-agenda-item (org-get-at-bol 'extra)
  6748. newhead cat tags dotime)))))
  6749. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6750. undone-face (org-get-at-bol 'undone-face)
  6751. done-face (org-get-at-bol 'done-face))
  6752. (beginning-of-line 1)
  6753. (cond
  6754. ((equal new "")
  6755. (and (looking-at ".*\n?") (replace-match "")))
  6756. ((looking-at ".*")
  6757. (replace-match new t t)
  6758. (beginning-of-line 1)
  6759. (add-text-properties (point-at-bol) (point-at-eol) props)
  6760. (when fixface
  6761. (add-text-properties
  6762. (point-at-bol) (point-at-eol)
  6763. (list 'face
  6764. (if org-last-todo-state-is-todo
  6765. undone-face done-face))))
  6766. (org-agenda-highlight-todo 'line)
  6767. (beginning-of-line 1))
  6768. (t (error "Line update did not work"))))
  6769. (beginning-of-line 0)))
  6770. (org-finalize-agenda)))
  6771. (defun org-agenda-align-tags (&optional line)
  6772. "Align all tags in agenda items to `org-agenda-tags-column'."
  6773. (let ((inhibit-read-only t) l c)
  6774. (save-excursion
  6775. (goto-char (if line (point-at-bol) (point-min)))
  6776. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6777. (if line (point-at-eol) nil) t)
  6778. (add-text-properties
  6779. (match-beginning 2) (match-end 2)
  6780. (list 'face (delq nil (let ((prop (get-text-property
  6781. (match-beginning 2) 'face)))
  6782. (or (listp prop) (setq prop (list prop)))
  6783. (if (memq 'org-tag prop)
  6784. prop
  6785. (cons 'org-tag prop))))))
  6786. (setq l (- (match-end 2) (match-beginning 2))
  6787. c (if (< org-agenda-tags-column 0)
  6788. (- (abs org-agenda-tags-column) l)
  6789. org-agenda-tags-column))
  6790. (delete-region (match-beginning 1) (match-end 1))
  6791. (goto-char (match-beginning 1))
  6792. (insert (org-add-props
  6793. (make-string (max 1 (- c (current-column))) ?\ )
  6794. (plist-put (copy-sequence (text-properties-at (point)))
  6795. 'face nil))))
  6796. (goto-char (point-min))
  6797. (org-font-lock-add-tag-faces (point-max)))))
  6798. (defun org-agenda-priority-up ()
  6799. "Increase the priority of line at point, also in Org-mode file."
  6800. (interactive)
  6801. (org-agenda-priority 'up))
  6802. (defun org-agenda-priority-down ()
  6803. "Decrease the priority of line at point, also in Org-mode file."
  6804. (interactive)
  6805. (org-agenda-priority 'down))
  6806. (defun org-agenda-priority (&optional force-direction)
  6807. "Set the priority of line at point, also in Org-mode file.
  6808. This changes the line at point, all other lines in the agenda referring to
  6809. the same tree node, and the headline of the tree node in the Org-mode file."
  6810. (interactive)
  6811. (unless org-enable-priority-commands
  6812. (error "Priority commands are disabled"))
  6813. (org-agenda-check-no-diary)
  6814. (let* ((marker (or (org-get-at-bol 'org-marker)
  6815. (org-agenda-error)))
  6816. (hdmarker (org-get-at-bol 'org-hd-marker))
  6817. (buffer (marker-buffer hdmarker))
  6818. (pos (marker-position hdmarker))
  6819. (inhibit-read-only t)
  6820. newhead)
  6821. (org-with-remote-undo buffer
  6822. (with-current-buffer buffer
  6823. (widen)
  6824. (goto-char pos)
  6825. (org-show-context 'agenda)
  6826. (save-excursion
  6827. (and (outline-next-heading)
  6828. (org-flag-heading nil))) ; show the next heading
  6829. (funcall 'org-priority force-direction)
  6830. (end-of-line 1)
  6831. (setq newhead (org-get-heading)))
  6832. (org-agenda-change-all-lines newhead hdmarker)
  6833. (beginning-of-line 1))))
  6834. ;; FIXME: should fix the tags property of the agenda line.
  6835. (defun org-agenda-set-tags (&optional tag onoff)
  6836. "Set tags for the current headline."
  6837. (interactive)
  6838. (org-agenda-check-no-diary)
  6839. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6840. (call-interactively 'org-change-tag-in-region)
  6841. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6842. (org-agenda-error)))
  6843. (buffer (marker-buffer hdmarker))
  6844. (pos (marker-position hdmarker))
  6845. (inhibit-read-only t)
  6846. newhead)
  6847. (org-with-remote-undo buffer
  6848. (with-current-buffer buffer
  6849. (widen)
  6850. (goto-char pos)
  6851. (save-excursion
  6852. (org-show-context 'agenda))
  6853. (save-excursion
  6854. (and (outline-next-heading)
  6855. (org-flag-heading nil))) ; show the next heading
  6856. (goto-char pos)
  6857. (if tag
  6858. (org-toggle-tag tag onoff)
  6859. (call-interactively 'org-set-tags))
  6860. (end-of-line 1)
  6861. (setq newhead (org-get-heading)))
  6862. (org-agenda-change-all-lines newhead hdmarker)
  6863. (beginning-of-line 1)))))
  6864. (defun org-agenda-set-property ()
  6865. "Set a property for the current headline."
  6866. (interactive)
  6867. (org-agenda-check-no-diary)
  6868. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6869. (org-agenda-error)))
  6870. (buffer (marker-buffer hdmarker))
  6871. (pos (marker-position hdmarker))
  6872. (inhibit-read-only t)
  6873. newhead)
  6874. (org-with-remote-undo buffer
  6875. (with-current-buffer buffer
  6876. (widen)
  6877. (goto-char pos)
  6878. (save-excursion
  6879. (org-show-context 'agenda))
  6880. (save-excursion
  6881. (and (outline-next-heading)
  6882. (org-flag-heading nil))) ; show the next heading
  6883. (goto-char pos)
  6884. (call-interactively 'org-set-property)))))
  6885. (defun org-agenda-set-effort ()
  6886. "Set the effort property for the current headline."
  6887. (interactive)
  6888. (org-agenda-check-no-diary)
  6889. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6890. (org-agenda-error)))
  6891. (buffer (marker-buffer hdmarker))
  6892. (pos (marker-position hdmarker))
  6893. (inhibit-read-only t)
  6894. newhead)
  6895. (org-with-remote-undo buffer
  6896. (with-current-buffer buffer
  6897. (widen)
  6898. (goto-char pos)
  6899. (save-excursion
  6900. (org-show-context 'agenda))
  6901. (save-excursion
  6902. (and (outline-next-heading)
  6903. (org-flag-heading nil))) ; show the next heading
  6904. (goto-char pos)
  6905. (call-interactively 'org-set-effort)
  6906. (end-of-line 1)
  6907. (setq newhead (org-get-heading)))
  6908. (org-agenda-change-all-lines newhead hdmarker))))
  6909. (defun org-agenda-toggle-archive-tag ()
  6910. "Toggle the archive tag for the current entry."
  6911. (interactive)
  6912. (org-agenda-check-no-diary)
  6913. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6914. (org-agenda-error)))
  6915. (buffer (marker-buffer hdmarker))
  6916. (pos (marker-position hdmarker))
  6917. (inhibit-read-only t)
  6918. newhead)
  6919. (org-with-remote-undo buffer
  6920. (with-current-buffer buffer
  6921. (widen)
  6922. (goto-char pos)
  6923. (org-show-context 'agenda)
  6924. (save-excursion
  6925. (and (outline-next-heading)
  6926. (org-flag-heading nil))) ; show the next heading
  6927. (call-interactively 'org-toggle-archive-tag)
  6928. (end-of-line 1)
  6929. (setq newhead (org-get-heading)))
  6930. (org-agenda-change-all-lines newhead hdmarker)
  6931. (beginning-of-line 1))))
  6932. (defun org-agenda-do-date-later (arg)
  6933. (interactive "P")
  6934. (cond
  6935. ((or (equal arg '(16))
  6936. (memq last-command
  6937. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6938. (setq this-command 'org-agenda-date-later-minutes)
  6939. (org-agenda-date-later-minutes 1))
  6940. ((or (equal arg '(4))
  6941. (memq last-command
  6942. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6943. (setq this-command 'org-agenda-date-later-hours)
  6944. (org-agenda-date-later-hours 1))
  6945. (t
  6946. (org-agenda-date-later (prefix-numeric-value arg)))))
  6947. (defun org-agenda-do-date-earlier (arg)
  6948. (interactive "P")
  6949. (cond
  6950. ((or (equal arg '(16))
  6951. (memq last-command
  6952. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6953. (setq this-command 'org-agenda-date-earlier-minutes)
  6954. (org-agenda-date-earlier-minutes 1))
  6955. ((or (equal arg '(4))
  6956. (memq last-command
  6957. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6958. (setq this-command 'org-agenda-date-earlier-hours)
  6959. (org-agenda-date-earlier-hours 1))
  6960. (t
  6961. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6962. (defun org-agenda-date-later (arg &optional what)
  6963. "Change the date of this item to ARG day(s) later."
  6964. (interactive "p")
  6965. (org-agenda-check-type t 'agenda 'timeline)
  6966. (org-agenda-check-no-diary)
  6967. (let* ((marker (or (org-get-at-bol 'org-marker)
  6968. (org-agenda-error)))
  6969. (buffer (marker-buffer marker))
  6970. (pos (marker-position marker)))
  6971. (org-with-remote-undo buffer
  6972. (with-current-buffer buffer
  6973. (widen)
  6974. (goto-char pos)
  6975. (if (not (org-at-timestamp-p))
  6976. (error "Cannot find time stamp"))
  6977. (org-timestamp-change arg (or what 'day)))
  6978. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6979. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6980. (defun org-agenda-date-earlier (arg &optional what)
  6981. "Change the date of this item to ARG day(s) earlier."
  6982. (interactive "p")
  6983. (org-agenda-date-later (- arg) what))
  6984. (defun org-agenda-date-later-minutes (arg)
  6985. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6986. (interactive "p")
  6987. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6988. (org-agenda-date-later arg 'minute))
  6989. (defun org-agenda-date-earlier-minutes (arg)
  6990. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6991. (interactive "p")
  6992. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6993. (org-agenda-date-earlier arg 'minute))
  6994. (defun org-agenda-date-later-hours (arg)
  6995. "Change the time of this item, in hour steps."
  6996. (interactive "p")
  6997. (org-agenda-date-later arg 'hour))
  6998. (defun org-agenda-date-earlier-hours (arg)
  6999. "Change the time of this item, in hour steps."
  7000. (interactive "p")
  7001. (org-agenda-date-earlier arg 'hour))
  7002. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7003. "Show new date stamp via text properties."
  7004. ;; We use text properties to make this undoable
  7005. (let ((inhibit-read-only t)
  7006. (buffer-invisibility-spec))
  7007. (setq stamp (concat " " prefix " => " stamp))
  7008. (save-excursion
  7009. (goto-char (point-max))
  7010. (while (not (bobp))
  7011. (when (equal marker (org-get-at-bol 'org-marker))
  7012. (org-move-to-column (- (window-width) (length stamp)) t)
  7013. (org-agenda-fix-tags-filter-overlays-at (point))
  7014. (if (featurep 'xemacs)
  7015. ;; Use `duplicable' property to trigger undo recording
  7016. (let ((ex (make-extent nil nil))
  7017. (gl (make-glyph stamp)))
  7018. (set-glyph-face gl 'secondary-selection)
  7019. (set-extent-properties
  7020. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7021. (insert-extent ex (1- (point)) (point-at-eol)))
  7022. (add-text-properties
  7023. (1- (point)) (point-at-eol)
  7024. (list 'display (org-add-props stamp nil
  7025. 'face 'secondary-selection))))
  7026. (beginning-of-line 1))
  7027. (beginning-of-line 0)))))
  7028. (defun org-agenda-date-prompt (arg)
  7029. "Change the date of this item. Date is prompted for, with default today.
  7030. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7031. be used to request time specification in the time stamp."
  7032. (interactive "P")
  7033. (org-agenda-check-type t 'agenda 'timeline)
  7034. (org-agenda-check-no-diary)
  7035. (let* ((marker (or (org-get-at-bol 'org-marker)
  7036. (org-agenda-error)))
  7037. (buffer (marker-buffer marker))
  7038. (pos (marker-position marker)))
  7039. (org-with-remote-undo buffer
  7040. (with-current-buffer buffer
  7041. (widen)
  7042. (goto-char pos)
  7043. (if (not (org-at-timestamp-p t))
  7044. (error "Cannot find time stamp"))
  7045. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7046. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7047. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7048. (defun org-agenda-schedule (arg &optional time)
  7049. "Schedule the item at point.
  7050. ARG is passed through to `org-schedule'."
  7051. (interactive "P")
  7052. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7053. (org-agenda-check-no-diary)
  7054. (let* ((marker (or (org-get-at-bol 'org-marker)
  7055. (org-agenda-error)))
  7056. (type (marker-insertion-type marker))
  7057. (buffer (marker-buffer marker))
  7058. (pos (marker-position marker))
  7059. (org-insert-labeled-timestamps-at-point nil)
  7060. ts)
  7061. (set-marker-insertion-type marker t)
  7062. (org-with-remote-undo buffer
  7063. (with-current-buffer buffer
  7064. (widen)
  7065. (goto-char pos)
  7066. (setq ts (org-schedule arg time)))
  7067. (org-agenda-show-new-time marker ts "S"))
  7068. (message "Item scheduled for %s" ts)))
  7069. (defun org-agenda-deadline (arg &optional time)
  7070. "Schedule the item at point.
  7071. ARG is passed through to `org-deadline'."
  7072. (interactive "P")
  7073. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7074. (org-agenda-check-no-diary)
  7075. (let* ((marker (or (org-get-at-bol 'org-marker)
  7076. (org-agenda-error)))
  7077. (buffer (marker-buffer marker))
  7078. (pos (marker-position marker))
  7079. (org-insert-labeled-timestamps-at-point nil)
  7080. ts)
  7081. (org-with-remote-undo buffer
  7082. (with-current-buffer buffer
  7083. (widen)
  7084. (goto-char pos)
  7085. (setq ts (org-deadline arg time)))
  7086. (org-agenda-show-new-time marker ts "D"))
  7087. (message "Deadline for this item set to %s" ts)))
  7088. (defun org-agenda-action ()
  7089. "Select entry for agenda action, or execute an agenda action.
  7090. This command prompts for another letter. Valid inputs are:
  7091. m Mark the entry at point for an agenda action
  7092. s Schedule the marked entry to the date at the cursor
  7093. d Set the deadline of the marked entry to the date at the cursor
  7094. r Call `org-remember' with cursor date as the default date
  7095. c Call `org-capture' with cursor date as the default date
  7096. SPC Show marked entry in other window
  7097. TAB Visit marked entry in other window
  7098. The cursor may be at a date in the calendar, or in the Org agenda."
  7099. (interactive)
  7100. (let (ans)
  7101. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7102. (setq ans (read-char-exclusive))
  7103. (cond
  7104. ((equal ans ?m)
  7105. ;; Mark this entry
  7106. (if (eq major-mode 'org-agenda-mode)
  7107. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7108. (org-get-at-bol 'org-marker))))
  7109. (if m
  7110. (progn
  7111. (move-marker org-agenda-action-marker
  7112. (marker-position m) (marker-buffer m))
  7113. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7114. (error "Don't know which entry to mark")))
  7115. (error "This command works only in the agenda")))
  7116. ((equal ans ?s)
  7117. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7118. ((equal ans ?d)
  7119. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7120. ((equal ans ?r)
  7121. (org-agenda-do-action '(org-remember) t))
  7122. ((equal ans ?c)
  7123. (org-agenda-do-action '(org-capture) t))
  7124. ((equal ans ?\ )
  7125. (let ((cw (selected-window)))
  7126. (org-switch-to-buffer-other-window
  7127. (marker-buffer org-agenda-action-marker))
  7128. (goto-char org-agenda-action-marker)
  7129. (org-show-context 'agenda)
  7130. (select-window cw)))
  7131. ((equal ans ?\C-i)
  7132. (org-switch-to-buffer-other-window
  7133. (marker-buffer org-agenda-action-marker))
  7134. (goto-char org-agenda-action-marker)
  7135. (org-show-context 'agenda))
  7136. (t (error "Invalid agenda action %c" ans)))))
  7137. (defun org-agenda-do-action (form &optional current-buffer)
  7138. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7139. (let ((org-overriding-default-time (org-get-cursor-date)))
  7140. (if current-buffer
  7141. (eval form)
  7142. (if (not (marker-buffer org-agenda-action-marker))
  7143. (error "No entry has been selected for agenda action")
  7144. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7145. (save-excursion
  7146. (save-restriction
  7147. (widen)
  7148. (goto-char org-agenda-action-marker)
  7149. (eval form))))))))
  7150. (defun org-agenda-clock-in (&optional arg)
  7151. "Start the clock on the currently selected item."
  7152. (interactive "P")
  7153. (org-agenda-check-no-diary)
  7154. (if (equal arg '(4))
  7155. (org-clock-in arg)
  7156. (let* ((marker (or (org-get-at-bol 'org-marker)
  7157. (org-agenda-error)))
  7158. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7159. marker))
  7160. (pos (marker-position marker))
  7161. newhead)
  7162. (org-with-remote-undo (marker-buffer marker)
  7163. (with-current-buffer (marker-buffer marker)
  7164. (widen)
  7165. (goto-char pos)
  7166. (org-show-context 'agenda)
  7167. (org-show-entry)
  7168. (org-cycle-hide-drawers 'children)
  7169. (org-clock-in arg)
  7170. (setq newhead (org-get-heading)))
  7171. (org-agenda-change-all-lines newhead hdmarker)))))
  7172. (defun org-agenda-clock-out ()
  7173. "Stop the currently running clock."
  7174. (interactive)
  7175. (unless (marker-buffer org-clock-marker)
  7176. (error "No running clock"))
  7177. (let ((marker (make-marker)) newhead)
  7178. (org-with-remote-undo (marker-buffer org-clock-marker)
  7179. (with-current-buffer (marker-buffer org-clock-marker)
  7180. (save-excursion
  7181. (save-restriction
  7182. (widen)
  7183. (goto-char org-clock-marker)
  7184. (org-back-to-heading t)
  7185. (move-marker marker (point))
  7186. (org-clock-out)
  7187. (setq newhead (org-get-heading))))))
  7188. (org-agenda-change-all-lines newhead marker)
  7189. (move-marker marker nil)))
  7190. (defun org-agenda-clock-cancel (&optional arg)
  7191. "Cancel the currently running clock."
  7192. (interactive "P")
  7193. (unless (marker-buffer org-clock-marker)
  7194. (error "No running clock"))
  7195. (org-with-remote-undo (marker-buffer org-clock-marker)
  7196. (org-clock-cancel)))
  7197. (defun org-agenda-clock-goto ()
  7198. "Jump to the currently clocked in task within the agenda.
  7199. If the currently clocked in task is not listed in the agenda
  7200. buffer, display it in another window."
  7201. (interactive)
  7202. (let (pos)
  7203. (mapc (lambda (o)
  7204. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7205. (setq pos (overlay-start o))))
  7206. (overlays-in (point-min) (point-max)))
  7207. (cond (pos (goto-char pos))
  7208. ;; If the currently clocked entry is not in the agenda
  7209. ;; buffer, we visit it in another window:
  7210. (org-clock-current-task
  7211. (org-switch-to-buffer-other-window (org-clock-goto)))
  7212. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7213. (defun org-agenda-diary-entry-in-org-file ()
  7214. "Make a diary entry in the file `org-agenda-diary-file'."
  7215. (let (d1 d2 char (text "") dp1 dp2)
  7216. (if (equal (buffer-name) "*Calendar*")
  7217. (setq d1 (calendar-cursor-to-date t)
  7218. d2 (car calendar-mark-ring))
  7219. (setq dp1 (get-text-property (point-at-bol) 'day))
  7220. (unless dp1 (error "No date defined in current line"))
  7221. (setq d1 (calendar-gregorian-from-absolute dp1)
  7222. d2 (and (ignore-errors (mark))
  7223. (save-excursion
  7224. (goto-char (mark))
  7225. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7226. (calendar-gregorian-from-absolute dp2))))
  7227. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7228. (setq char (read-char-exclusive))
  7229. (cond
  7230. ((equal char ?d)
  7231. (setq text (read-string "Day entry: "))
  7232. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7233. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7234. ((equal char ?a)
  7235. (setq d1 (list (car d1) (nth 1 d1)
  7236. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7237. (nth 2 d1))))
  7238. (setq text (read-string "Anniversary (use %d to show years): "))
  7239. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7240. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7241. ((equal char ?b)
  7242. (setq text (read-string "Block entry: "))
  7243. (unless (and d1 d2 (not (equal d1 d2)))
  7244. (error "No block of days selected"))
  7245. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7246. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7247. ((equal char ?j)
  7248. (org-switch-to-buffer-other-window
  7249. (find-file-noselect org-agenda-diary-file))
  7250. (require 'org-datetree)
  7251. (org-datetree-find-date-create d1)
  7252. (org-reveal t))
  7253. (t (error "Invalid selection character `%c'" char)))))
  7254. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7255. "Where in `org-agenda-diary-file' should new entries be added?
  7256. Valid values:
  7257. date-tree in the date tree, as child of the date
  7258. top-level as top-level entries at the end of the file."
  7259. :group 'org-agenda
  7260. :type '(choice
  7261. (const :tag "in a date tree" date-tree)
  7262. (const :tag "as top level at end of file" top-level)))
  7263. (defcustom org-agenda-insert-diary-extract-time nil
  7264. "Non-nil means extract any time specification from the diary entry."
  7265. :group 'org-agenda
  7266. :type 'boolean)
  7267. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7268. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7269. If TEXT is not empty, it will become the headline of the new entry, and
  7270. the resulting entry will not be shown. When TEXT is empty, switch to
  7271. `org-agenda-diary-file' and let the user finish the entry there."
  7272. (let ((cw (current-window-configuration)))
  7273. (org-switch-to-buffer-other-window
  7274. (find-file-noselect org-agenda-diary-file))
  7275. (widen)
  7276. (goto-char (point-min))
  7277. (cond
  7278. ((eq type 'anniversary)
  7279. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7280. (progn
  7281. (or (org-on-heading-p t)
  7282. (progn
  7283. (outline-next-heading)
  7284. (insert "* Anniversaries\n\n")
  7285. (beginning-of-line -1)))))
  7286. (outline-next-heading)
  7287. (org-back-over-empty-lines)
  7288. (backward-char 1)
  7289. (insert "\n")
  7290. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7291. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7292. ((eq type 'day)
  7293. (let ((org-prefix-has-time t)
  7294. (org-agenda-time-leading-zero t)
  7295. fmt time time2)
  7296. (if org-agenda-insert-diary-extract-time
  7297. ;; Use org-format-agenda-item to parse text for a time-range and
  7298. ;; remove it. FIXME: This is a hack, we should refactor
  7299. ;; that function to make time extraction available separately
  7300. (setq fmt (org-format-agenda-item nil text nil nil t)
  7301. time (get-text-property 0 'time fmt)
  7302. time2 (if (> (length time) 0)
  7303. ;; split-string removes trailing ...... if
  7304. ;; no end time given. First space
  7305. ;; separates time from date.
  7306. (concat " " (car (split-string time "\\.")))
  7307. nil)
  7308. text (get-text-property 0 'txt fmt)))
  7309. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7310. (org-agenda-insert-diary-as-top-level text)
  7311. (require 'org-datetree)
  7312. (org-datetree-find-date-create d1)
  7313. (org-agenda-insert-diary-make-new-entry text))
  7314. (org-insert-time-stamp (org-time-from-absolute
  7315. (calendar-absolute-from-gregorian d1))
  7316. nil nil nil nil time2))
  7317. (end-of-line 0))
  7318. ((eq type 'block)
  7319. (if (> (calendar-absolute-from-gregorian d1)
  7320. (calendar-absolute-from-gregorian d2))
  7321. (setq d1 (prog1 d2 (setq d2 d1))))
  7322. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7323. (org-agenda-insert-diary-as-top-level text)
  7324. (require 'org-datetree)
  7325. (org-datetree-find-date-create d1)
  7326. (org-agenda-insert-diary-make-new-entry text))
  7327. (org-insert-time-stamp (org-time-from-absolute
  7328. (calendar-absolute-from-gregorian d1)))
  7329. (insert "--")
  7330. (org-insert-time-stamp (org-time-from-absolute
  7331. (calendar-absolute-from-gregorian d2)))
  7332. (end-of-line 0)))
  7333. (if (string-match "\\S-" text)
  7334. (progn
  7335. (set-window-configuration cw)
  7336. (message "%s entry added to %s"
  7337. (capitalize (symbol-name type))
  7338. (abbreviate-file-name org-agenda-diary-file)))
  7339. (org-reveal t)
  7340. (message "Please finish entry here"))))
  7341. (defun org-agenda-insert-diary-as-top-level (text)
  7342. "Make new entry as a top-level entry at the end of the file.
  7343. Add TEXT as headline, and position the cursor in the second line so that
  7344. a timestamp can be added there."
  7345. (widen)
  7346. (goto-char (point-max))
  7347. (or (bolp) (insert "\n"))
  7348. (insert "* " text "\n")
  7349. (if org-adapt-indentation (org-indent-to-column 2)))
  7350. (defun org-agenda-insert-diary-make-new-entry (text)
  7351. "Make new entry as last child of current entry.
  7352. Add TEXT as headline, and position the cursor in the second line so that
  7353. a timestamp can be added there."
  7354. (let ((org-show-following-heading t)
  7355. (org-show-siblings t)
  7356. (org-show-hierarchy-above t)
  7357. (org-show-entry-below t)
  7358. col)
  7359. (outline-next-heading)
  7360. (org-back-over-empty-lines)
  7361. (or (looking-at "[ \t]*$")
  7362. (progn (insert "\n") (backward-char 1)))
  7363. (org-insert-heading nil t)
  7364. (org-do-demote)
  7365. (setq col (current-column))
  7366. (insert text "\n")
  7367. (if org-adapt-indentation (org-indent-to-column col))
  7368. (let ((org-show-following-heading t)
  7369. (org-show-siblings t)
  7370. (org-show-hierarchy-above t)
  7371. (org-show-entry-below t))
  7372. (org-show-context))))
  7373. (defun org-agenda-diary-entry ()
  7374. "Make a diary entry, like the `i' command from the calendar.
  7375. All the standard commands work: block, weekly etc.
  7376. When `org-agenda-diary-file' points to a file,
  7377. `org-agenda-diary-entry-in-org-file' is called instead to create
  7378. entries in that Org-mode file."
  7379. (interactive)
  7380. (org-agenda-check-type t 'agenda 'timeline)
  7381. (if (not (eq org-agenda-diary-file 'diary-file))
  7382. (org-agenda-diary-entry-in-org-file)
  7383. (require 'diary-lib)
  7384. (let* ((char (progn
  7385. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7386. (read-char-exclusive)))
  7387. (cmd (cdr (assoc char
  7388. '((?d . insert-diary-entry)
  7389. (?w . insert-weekly-diary-entry)
  7390. (?m . insert-monthly-diary-entry)
  7391. (?y . insert-yearly-diary-entry)
  7392. (?a . insert-anniversary-diary-entry)
  7393. (?b . insert-block-diary-entry)
  7394. (?c . insert-cyclic-diary-entry)))))
  7395. (oldf (symbol-function 'calendar-cursor-to-date))
  7396. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7397. (point (point))
  7398. (mark (or (mark t) (point))))
  7399. (unless cmd
  7400. (error "No command associated with <%c>" char))
  7401. (unless (and (get-text-property point 'day)
  7402. (or (not (equal ?b char))
  7403. (get-text-property mark 'day)))
  7404. (error "Don't know which date to use for diary entry"))
  7405. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7406. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7407. (let ((calendar-mark-ring
  7408. (list (calendar-gregorian-from-absolute
  7409. (or (get-text-property mark 'day)
  7410. (get-text-property point 'day))))))
  7411. (unwind-protect
  7412. (progn
  7413. (fset 'calendar-cursor-to-date
  7414. (lambda (&optional error dummy)
  7415. (calendar-gregorian-from-absolute
  7416. (get-text-property point 'day))))
  7417. (call-interactively cmd))
  7418. (fset 'calendar-cursor-to-date oldf))))))
  7419. (defun org-agenda-execute-calendar-command (cmd)
  7420. "Execute a calendar command from the agenda, with the date associated to
  7421. the cursor position."
  7422. (org-agenda-check-type t 'agenda 'timeline)
  7423. (require 'diary-lib)
  7424. (unless (get-text-property (point) 'day)
  7425. (error "Don't know which date to use for calendar command"))
  7426. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7427. (point (point))
  7428. (date (calendar-gregorian-from-absolute
  7429. (get-text-property point 'day)))
  7430. ;; the following 2 vars are needed in the calendar
  7431. (displayed-month (car date))
  7432. (displayed-year (nth 2 date)))
  7433. (unwind-protect
  7434. (progn
  7435. (fset 'calendar-cursor-to-date
  7436. (lambda (&optional error dummy)
  7437. (calendar-gregorian-from-absolute
  7438. (get-text-property point 'day))))
  7439. (call-interactively cmd))
  7440. (fset 'calendar-cursor-to-date oldf))))
  7441. (defun org-agenda-phases-of-moon ()
  7442. "Display the phases of the moon for the 3 months around the cursor date."
  7443. (interactive)
  7444. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7445. (defun org-agenda-holidays ()
  7446. "Display the holidays for the 3 months around the cursor date."
  7447. (interactive)
  7448. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7449. (defvar calendar-longitude)
  7450. (defvar calendar-latitude)
  7451. (defvar calendar-location-name)
  7452. (defun org-agenda-sunrise-sunset (arg)
  7453. "Display sunrise and sunset for the cursor date.
  7454. Latitude and longitude can be specified with the variables
  7455. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7456. argument, latitude and longitude will be prompted for."
  7457. (interactive "P")
  7458. (require 'solar)
  7459. (let ((calendar-longitude (if arg nil calendar-longitude))
  7460. (calendar-latitude (if arg nil calendar-latitude))
  7461. (calendar-location-name
  7462. (if arg "the given coordinates" calendar-location-name)))
  7463. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7464. (defun org-agenda-goto-calendar ()
  7465. "Open the Emacs calendar with the date at the cursor."
  7466. (interactive)
  7467. (org-agenda-check-type t 'agenda 'timeline)
  7468. (let* ((day (or (get-text-property (point) 'day)
  7469. (error "Don't know which date to open in calendar")))
  7470. (date (calendar-gregorian-from-absolute day))
  7471. (calendar-move-hook nil)
  7472. (calendar-view-holidays-initially-flag nil)
  7473. (calendar-view-diary-initially-flag nil))
  7474. (calendar)
  7475. (calendar-goto-date date)))
  7476. ;;;###autoload
  7477. (defun org-calendar-goto-agenda ()
  7478. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7479. This is a command that has to be installed in `calendar-mode-map'."
  7480. (interactive)
  7481. (org-agenda-list nil (calendar-absolute-from-gregorian
  7482. (calendar-cursor-to-date))
  7483. nil))
  7484. (defun org-agenda-convert-date ()
  7485. (interactive)
  7486. (org-agenda-check-type t 'agenda 'timeline)
  7487. (let ((day (get-text-property (point) 'day))
  7488. date s)
  7489. (unless day
  7490. (error "Don't know which date to convert"))
  7491. (setq date (calendar-gregorian-from-absolute day))
  7492. (setq s (concat
  7493. "Gregorian: " (calendar-date-string date) "\n"
  7494. "ISO: " (calendar-iso-date-string date) "\n"
  7495. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7496. "Julian: " (calendar-julian-date-string date) "\n"
  7497. "Astron. JD: " (calendar-astro-date-string date)
  7498. " (Julian date number at noon UTC)\n"
  7499. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7500. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7501. "French: " (calendar-french-date-string date) "\n"
  7502. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7503. "Mayan: " (calendar-mayan-date-string date) "\n"
  7504. "Coptic: " (calendar-coptic-date-string date) "\n"
  7505. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7506. "Persian: " (calendar-persian-date-string date) "\n"
  7507. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7508. (with-output-to-temp-buffer "*Dates*"
  7509. (princ s))
  7510. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7511. ;;; Bulk commands
  7512. (defvar org-agenda-bulk-marked-entries nil
  7513. "List of markers that refer to marked entries in the agenda.")
  7514. (defun org-agenda-bulk-marked-p ()
  7515. (eq (get-char-property (point-at-bol) 'type)
  7516. 'org-marked-entry-overlay))
  7517. (defun org-agenda-bulk-mark (&optional arg)
  7518. "Mark the entry at point for future bulk action."
  7519. (interactive "p")
  7520. (dotimes (i (max arg 1))
  7521. (unless (org-get-at-bol 'org-agenda-diary-link)
  7522. (let* ((m (org-get-at-bol 'org-hd-marker))
  7523. ov)
  7524. (unless (org-agenda-bulk-marked-p)
  7525. (unless m (error "Nothing to mark at point"))
  7526. (push m org-agenda-bulk-marked-entries)
  7527. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7528. (org-overlay-display ov "> "
  7529. (org-get-todo-face "TODO")
  7530. 'evaporate)
  7531. (overlay-put ov 'type 'org-marked-entry-overlay))
  7532. (beginning-of-line 2)
  7533. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7534. (beginning-of-line 2))
  7535. (message "%d entries marked for bulk action"
  7536. (length org-agenda-bulk-marked-entries))))))
  7537. (defun org-agenda-bulk-mark-regexp (regexp)
  7538. "Mark entries match REGEXP."
  7539. (interactive "sMark entries matching regexp: ")
  7540. (let (entries-marked)
  7541. (save-excursion
  7542. (goto-char (point-min))
  7543. (goto-char (next-single-property-change (point) 'txt))
  7544. (while (re-search-forward regexp nil t)
  7545. (when (string-match regexp (get-text-property (point) 'txt))
  7546. (setq entries-marked (+ entries-marked 1))
  7547. (call-interactively 'org-agenda-bulk-mark))))
  7548. (if (not entries-marked)
  7549. (message "No entry matching this regexp."))))
  7550. (defun org-agenda-bulk-unmark ()
  7551. "Unmark the entry at point for future bulk action."
  7552. (interactive)
  7553. (when (org-agenda-bulk-marked-p)
  7554. (org-agenda-bulk-remove-overlays
  7555. (point-at-bol) (+ 2 (point-at-bol)))
  7556. (setq org-agenda-bulk-marked-entries
  7557. (delete (org-get-at-bol 'org-hd-marker)
  7558. org-agenda-bulk-marked-entries)))
  7559. (beginning-of-line 2)
  7560. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7561. (beginning-of-line 2))
  7562. (message "%d entries marked for bulk action"
  7563. (length org-agenda-bulk-marked-entries)))
  7564. (defun org-agenda-bulk-toggle ()
  7565. "Toggle marking the entry at point for bulk action."
  7566. (interactive)
  7567. (if (org-agenda-bulk-marked-p)
  7568. (org-agenda-bulk-unmark)
  7569. (org-agenda-bulk-mark)))
  7570. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7571. "Remove the mark overlays between BEG and END in the agenda buffer.
  7572. BEG and END default to the buffer limits.
  7573. This only removes the overlays, it does not remove the markers
  7574. from the list in `org-agenda-bulk-marked-entries'."
  7575. (interactive)
  7576. (mapc (lambda (ov)
  7577. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7578. (delete-overlay ov)))
  7579. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7580. (defun org-agenda-bulk-remove-all-marks ()
  7581. "Remove all marks in the agenda buffer.
  7582. This will remove the markers, and the overlays."
  7583. (interactive)
  7584. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7585. (setq org-agenda-bulk-marked-entries nil)
  7586. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7587. (defun org-agenda-bulk-action (&optional arg)
  7588. "Execute an remote-editing action on all marked entries.
  7589. The prefix arg is passed through to the command if possible."
  7590. (interactive "P")
  7591. ;; Make sure we have markers, and only valid ones
  7592. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7593. (mapc
  7594. (lambda (m)
  7595. (unless (and (markerp m)
  7596. (marker-buffer m)
  7597. (buffer-live-p (marker-buffer m))
  7598. (marker-position m))
  7599. (error "Marker %s for bulk command is invalid" m)))
  7600. org-agenda-bulk-marked-entries)
  7601. ;; Prompt for the bulk command
  7602. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7603. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7604. (when org-agenda-bulk-custom-functions
  7605. (concat " Custom: ["
  7606. (mapconcat (lambda(f) (char-to-string (car f)))
  7607. org-agenda-bulk-custom-functions "")
  7608. "]"))))
  7609. (let* ((action (read-char-exclusive))
  7610. (org-log-refile (if org-log-refile 'time nil))
  7611. (entries (reverse org-agenda-bulk-marked-entries))
  7612. redo-at-end
  7613. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7614. (cond
  7615. ((equal action ?$)
  7616. (setq cmd '(org-agenda-archive)))
  7617. ((equal action ?A)
  7618. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7619. ((member action '(?r ?w))
  7620. (setq rfloc (org-refile-get-location
  7621. "Refile to"
  7622. (marker-buffer (car org-agenda-bulk-marked-entries))
  7623. org-refile-allow-creating-parent-nodes))
  7624. (if (nth 3 rfloc)
  7625. (setcar (nthcdr 3 rfloc)
  7626. (move-marker (make-marker) (nth 3 rfloc)
  7627. (or (get-file-buffer (nth 1 rfloc))
  7628. (find-buffer-visiting (nth 1 rfloc))
  7629. (error "This should not happen")))))
  7630. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7631. redo-at-end t))
  7632. ((equal action ?t)
  7633. (setq state (org-icompleting-read
  7634. "Todo state: "
  7635. (with-current-buffer (marker-buffer (car entries))
  7636. (mapcar 'list org-todo-keywords-1))))
  7637. (setq cmd `(let ((org-inhibit-blocking t)
  7638. (org-inhibit-logging 'note))
  7639. (org-agenda-todo ,state))))
  7640. ((memq action '(?- ?+))
  7641. (setq tag (org-icompleting-read
  7642. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7643. (with-current-buffer (marker-buffer (car entries))
  7644. (delq nil
  7645. (mapcar (lambda (x)
  7646. (if (stringp (car x)) x)) org-tag-alist)))))
  7647. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7648. ((memq action '(?s ?d))
  7649. (let* ((date (unless arg
  7650. (org-read-date
  7651. nil nil nil
  7652. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7653. (ans (if arg nil org-read-date-final-answer))
  7654. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7655. (setq cmd `(let* ((bound (fboundp 'read-string))
  7656. (old (and bound (symbol-function 'read-string))))
  7657. (unwind-protect
  7658. (progn
  7659. (fset 'read-string (lambda (&rest ignore) ,ans))
  7660. (eval '(,c1 arg)))
  7661. (if bound
  7662. (fset 'read-string old)
  7663. (fmakunbound 'read-string)))))))
  7664. ((equal action ?S)
  7665. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7666. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7667. (let ((days (read-number
  7668. (format "Scatter tasks across how many %sdays: "
  7669. (if arg "week" "")) 7)))
  7670. (setq cmd
  7671. `(let ((distance (1+ (random ,days))))
  7672. (if arg
  7673. (let ((dist distance)
  7674. (day-of-week
  7675. (calendar-day-of-week
  7676. (calendar-gregorian-from-absolute (org-today)))))
  7677. (dotimes (i (1+ dist))
  7678. (while (member day-of-week org-agenda-weekend-days)
  7679. (incf distance)
  7680. (incf day-of-week)
  7681. (if (= day-of-week 7)
  7682. (setq day-of-week 0)))
  7683. (incf day-of-week)
  7684. (if (= day-of-week 7)
  7685. (setq day-of-week 0)))))
  7686. ;; silently fail when try to replan a sexp entry
  7687. (condition-case nil
  7688. (let* ((date (calendar-gregorian-from-absolute
  7689. (+ (org-today) distance)))
  7690. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7691. (nth 2 date))))
  7692. (org-agenda-schedule nil time))
  7693. (error nil)))))))
  7694. ((assoc action org-agenda-bulk-custom-functions)
  7695. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7696. redo-at-end t))
  7697. ((equal action ?f)
  7698. (setq cmd (list (intern
  7699. (org-icompleting-read "Function: "
  7700. obarray 'fboundp t nil nil)))))
  7701. (t (error "Invalid bulk action")))
  7702. ;; Sort the markers, to make sure that parents are handled before children
  7703. (setq entries (sort entries
  7704. (lambda (a b)
  7705. (cond
  7706. ((equal (marker-buffer a) (marker-buffer b))
  7707. (< (marker-position a) (marker-position b)))
  7708. (t
  7709. (string< (buffer-name (marker-buffer a))
  7710. (buffer-name (marker-buffer b))))))))
  7711. ;; Now loop over all markers and apply cmd
  7712. (while (setq e (pop entries))
  7713. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7714. (if (not pos)
  7715. (progn (message "Skipping removed entry at %s" e)
  7716. (setq cntskip (1+ cntskip)))
  7717. (goto-char pos)
  7718. (eval cmd)
  7719. (setq org-agenda-bulk-marked-entries
  7720. (delete e org-agenda-bulk-marked-entries))
  7721. (setq cnt (1+ cnt))))
  7722. (setq org-agenda-bulk-marked-entries nil)
  7723. (org-agenda-bulk-remove-all-marks)
  7724. (when redo-at-end (org-agenda-redo))
  7725. (message "Acted on %d entries%s"
  7726. cnt
  7727. (if (= cntskip 0)
  7728. ""
  7729. (format ", skipped %d (disappeared before their turn)"
  7730. cntskip)))))
  7731. ;;; Flagging notes
  7732. (defun org-agenda-show-the-flagging-note ()
  7733. "Display the flagging note in the other window.
  7734. When called a second time in direct sequence, offer to remove the FLAGGING
  7735. tag and (if present) the flagging note."
  7736. (interactive)
  7737. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7738. (win (selected-window))
  7739. note heading newhead)
  7740. (unless hdmarker
  7741. (error "No linked entry at point"))
  7742. (if (and (eq this-command last-command)
  7743. (y-or-n-p "Unflag and remove any flagging note? "))
  7744. (progn
  7745. (org-agenda-remove-flag hdmarker)
  7746. (let ((win (get-buffer-window "*Flagging Note*")))
  7747. (and win (delete-window win)))
  7748. (message "Entry unflaged"))
  7749. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7750. (unless note
  7751. (error "No flagging note"))
  7752. (org-kill-new note)
  7753. (org-switch-to-buffer-other-window "*Flagging Note*")
  7754. (erase-buffer)
  7755. (insert note)
  7756. (goto-char (point-min))
  7757. (while (re-search-forward "\\\\n" nil t)
  7758. (replace-match "\n" t t))
  7759. (goto-char (point-min))
  7760. (select-window win)
  7761. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7762. (defun org-agenda-remove-flag (marker)
  7763. "Remove the FLAGGED tag and any flagging note in the entry."
  7764. (let (newhead)
  7765. (org-with-point-at marker
  7766. (org-toggle-tag "FLAGGED" 'off)
  7767. (org-entry-delete nil "THEFLAGGINGNOTE")
  7768. (setq newhead (org-get-heading)))
  7769. (org-agenda-change-all-lines newhead marker)
  7770. (message "Entry unflaged")))
  7771. (defun org-agenda-get-any-marker (&optional pos)
  7772. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7773. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7774. ;;; Appointment reminders
  7775. (defvar appt-time-msg-list)
  7776. ;;;###autoload
  7777. (defun org-agenda-to-appt (&optional refresh filter)
  7778. "Activate appointments found in `org-agenda-files'.
  7779. With a \\[universal-argument] prefix, refresh the list of
  7780. appointments.
  7781. If FILTER is t, interactively prompt the user for a regular
  7782. expression, and filter out entries that don't match it.
  7783. If FILTER is a string, use this string as a regular expression
  7784. for filtering entries out.
  7785. FILTER can also be an alist with the car of each cell being
  7786. either 'headline or 'category. For example:
  7787. '((headline \"IMPORTANT\")
  7788. (category \"Work\"))
  7789. will only add headlines containing IMPORTANT or headlines
  7790. belonging to the \"Work\" category."
  7791. (interactive "P")
  7792. (if refresh (setq appt-time-msg-list nil))
  7793. (if (eq filter t)
  7794. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7795. (let* ((cnt 0) ; count added events
  7796. (org-agenda-new-buffers nil)
  7797. (org-deadline-warning-days 0)
  7798. ;; Do not use `org-today' here because appt only takes
  7799. ;; time and without date as argument, so it may pass wrong
  7800. ;; information otherwise
  7801. (today (org-date-to-gregorian
  7802. (time-to-days (current-time))))
  7803. (org-agenda-restrict nil)
  7804. (files (org-agenda-files 'unrestricted)) entries file)
  7805. ;; Get all entries which may contain an appt
  7806. (org-prepare-agenda-buffers files)
  7807. (while (setq file (pop files))
  7808. (setq entries
  7809. (append entries
  7810. (org-agenda-get-day-entries
  7811. file today :timestamp :scheduled :deadline))))
  7812. (setq entries (delq nil entries))
  7813. ;; Map thru entries and find if we should filter them out
  7814. (mapc
  7815. (lambda(x)
  7816. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7817. (cat (get-text-property 1 'org-category x))
  7818. (tod (get-text-property 1 'time-of-day x))
  7819. (ok (or (null filter)
  7820. (and (stringp filter) (string-match filter evt))
  7821. (and (listp filter)
  7822. (or (string-match
  7823. (cadr (assoc 'category filter)) cat)
  7824. (string-match
  7825. (cadr (assoc 'headline filter)) evt))))))
  7826. ;; FIXME: Shall we remove text-properties for the appt text?
  7827. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7828. (when (and ok tod)
  7829. (setq tod (concat "00" (number-to-string tod))
  7830. tod (when (string-match
  7831. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7832. (concat (match-string 1 tod) ":"
  7833. (match-string 2 tod))))
  7834. (appt-add tod evt)
  7835. (setq cnt (1+ cnt))))) entries)
  7836. (org-release-buffers org-agenda-new-buffers)
  7837. (if (eq cnt 0)
  7838. (message "No event to add")
  7839. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7840. (defun org-agenda-todayp (date)
  7841. "Does DATE mean today, when considering `org-extend-today-until'?"
  7842. (let ((today (org-today))
  7843. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7844. date)))
  7845. (eq date today)))
  7846. (provide 'org-agenda)
  7847. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7848. ;;; org-agenda.el ends here