org-agenda.el 332 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. ;; Defined somewhere in this file, but used before definition.
  80. (defvar org-agenda-buffer-name)
  81. (defvar org-agenda-overriding-header)
  82. (defvar org-agenda-title-append nil)
  83. (defvar entry)
  84. (defvar date)
  85. (defvar org-agenda-undo-list)
  86. (defvar org-agenda-pending-undo-list)
  87. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  88. (defcustom org-agenda-confirm-kill 1
  89. "When set, remote killing from the agenda buffer needs confirmation.
  90. When t, a confirmation is always needed. When a number N, confirmation is
  91. only needed when the text to be killed contains more than N non-white lines."
  92. :group 'org-agenda
  93. :type '(choice
  94. (const :tag "Never" nil)
  95. (const :tag "Always" t)
  96. (integer :tag "When more than N lines")))
  97. (defcustom org-agenda-compact-blocks nil
  98. "Non-nil means make the block agenda more compact.
  99. This is done globally by leaving out lines like the agenda span
  100. name and week number or the separator lines."
  101. :group 'org-agenda
  102. :type 'boolean)
  103. (defcustom org-agenda-block-separator ?=
  104. "The separator between blocks in the agenda.
  105. If this is a string, it will be used as the separator, with a newline added.
  106. If it is a character, it will be repeated to fill the window width.
  107. If nil the separator is disabled. In `org-agenda-custom-commands' this
  108. addresses the separator between the current and the previous block."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Disabled" nil)
  112. (character)
  113. (string)))
  114. (defgroup org-agenda-export nil
  115. "Options concerning exporting agenda views in Org-mode."
  116. :tag "Org Agenda Export"
  117. :group 'org-agenda)
  118. (defcustom org-agenda-with-colors t
  119. "Non-nil means use colors in agenda views."
  120. :group 'org-agenda-export
  121. :type 'boolean)
  122. (defcustom org-agenda-exporter-settings nil
  123. "Alist of variable/value pairs that should be active during agenda export.
  124. This is a good place to set options for ps-print and for htmlize.
  125. Note that the way this is implemented, the values will be evaluated
  126. before assigned to the variables. So make sure to quote values you do
  127. *not* want evaluated, for example
  128. (setq org-agenda-exporter-settings
  129. '((ps-print-color-p 'black-white)))"
  130. :group 'org-agenda-export
  131. :type '(repeat
  132. (list
  133. (variable)
  134. (sexp :tag "Value"))))
  135. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  136. "Hook run in temporary buffer before writing it to an export file.
  137. A useful function is `org-agenda-add-entry-text'."
  138. :group 'org-agenda-export
  139. :type 'hook
  140. :options '(org-agenda-add-entry-text))
  141. (defcustom org-agenda-add-entry-text-maxlines 0
  142. "Maximum number of entry text lines to be added to agenda.
  143. This is only relevant when `org-agenda-add-entry-text' is part of
  144. `org-agenda-before-write-hook', which it is by default.
  145. When this is 0, nothing will happen. When it is greater than 0, it
  146. specifies the maximum number of lines that will be added for each entry
  147. that is listed in the agenda view.
  148. Note that this variable is not used during display, only when exporting
  149. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  150. and `org-agenda-entry-text-maxlines'."
  151. :group 'org-agenda
  152. :type 'integer)
  153. (defcustom org-agenda-add-entry-text-descriptive-links t
  154. "Non-nil means export org-links as descriptive links in agenda added text.
  155. This variable applies to the text added to the agenda when
  156. `org-agenda-add-entry-text-maxlines' is larger than 0.
  157. When this variable nil, the URL will (also) be shown."
  158. :group 'org-agenda
  159. :type 'boolean)
  160. (defcustom org-agenda-export-html-style ""
  161. "The style specification for exported HTML Agenda files.
  162. If this variable contains a string, it will replace the default <style>
  163. section as produced by `htmlize'.
  164. Since there are different ways of setting style information, this variable
  165. needs to contain the full HTML structure to provide a style, including the
  166. surrounding HTML tags. The style specifications should include definitions
  167. the fonts used by the agenda, here is an example:
  168. <style type=\"text/css\">
  169. p { font-weight: normal; color: gray; }
  170. .org-agenda-structure {
  171. font-size: 110%;
  172. color: #003399;
  173. font-weight: 600;
  174. }
  175. .org-todo {
  176. color: #cc6666;
  177. font-weight: bold;
  178. }
  179. .org-agenda-done {
  180. color: #339933;
  181. }
  182. .org-done {
  183. color: #339933;
  184. }
  185. .title { text-align: center; }
  186. .todo, .deadline { color: red; }
  187. .done { color: green; }
  188. </style>
  189. or, if you want to keep the style in a file,
  190. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  191. As the value of this option simply gets inserted into the HTML <head> header,
  192. you can \"misuse\" it to also add other text to the header. However,
  193. <style>...</style> is required, if not present the variable will be ignored."
  194. :group 'org-agenda-export
  195. :group 'org-export-html
  196. :type 'string)
  197. (defcustom org-agenda-persistent-filter nil
  198. "When set, keep filters from one agenda view to the next."
  199. :group 'org-agenda
  200. :type 'boolean)
  201. (defgroup org-agenda-custom-commands nil
  202. "Options concerning agenda views in Org-mode."
  203. :tag "Org Agenda Custom Commands"
  204. :group 'org-agenda)
  205. (defconst org-sorting-choice
  206. '(choice
  207. (const time-up) (const time-down)
  208. (const category-keep) (const category-up) (const category-down)
  209. (const tag-down) (const tag-up)
  210. (const priority-up) (const priority-down)
  211. (const todo-state-up) (const todo-state-down)
  212. (const effort-up) (const effort-down)
  213. (const habit-up) (const habit-down)
  214. (const alpha-up) (const alpha-down)
  215. (const user-defined-up) (const user-defined-down))
  216. "Sorting choices.")
  217. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  218. ;; the new variable `org-agenda-tag-filter-preset'.
  219. (if (fboundp 'defvaralias)
  220. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  221. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  222. (defconst org-agenda-custom-commands-local-options
  223. `(repeat :tag "Local settings for this command. Remember to quote values"
  224. (choice :tag "Setting"
  225. (list :tag "Heading for this block"
  226. (const org-agenda-overriding-header)
  227. (string :tag "Headline"))
  228. (list :tag "Files to be searched"
  229. (const org-agenda-files)
  230. (list
  231. (const :format "" quote)
  232. (repeat (file))))
  233. (list :tag "Sorting strategy"
  234. (const org-agenda-sorting-strategy)
  235. (list
  236. (const :format "" quote)
  237. (repeat
  238. ,org-sorting-choice)))
  239. (list :tag "Prefix format"
  240. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  241. (string))
  242. (list :tag "Number of days in agenda"
  243. (const org-agenda-span)
  244. (choice (const :tag "Day" 'day)
  245. (const :tag "Week" 'week)
  246. (const :tag "Month" 'month)
  247. (const :tag "Year" 'year)
  248. (integer :tag "Custom")))
  249. (list :tag "Fixed starting date"
  250. (const org-agenda-start-day)
  251. (string :value "2007-11-01"))
  252. (list :tag "Start on day of week"
  253. (const org-agenda-start-on-weekday)
  254. (choice :value 1
  255. (const :tag "Today" nil)
  256. (integer :tag "Weekday No.")))
  257. (list :tag "Include data from diary"
  258. (const org-agenda-include-diary)
  259. (boolean))
  260. (list :tag "Deadline Warning days"
  261. (const org-deadline-warning-days)
  262. (integer :value 1))
  263. (list :tag "Category filter preset"
  264. (const org-agenda-category-filter-preset)
  265. (list
  266. (const :format "" quote)
  267. (repeat
  268. (string :tag "+category or -category"))))
  269. (list :tag "Tags filter preset"
  270. (const org-agenda-tag-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+tag or -tag"))))
  275. (list :tag "Set daily/weekly entry types"
  276. (const org-agenda-entry-types)
  277. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  278. (const :deadline)
  279. (const :scheduled)
  280. (const :timestamp)
  281. (const :sexp)))
  282. (list :tag "Standard skipping condition"
  283. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  284. (const org-agenda-skip-function)
  285. (list
  286. (const :format "" quote)
  287. (list
  288. (choice
  289. :tag "Skipping range"
  290. (const :tag "Skip entry" org-agenda-skip-entry-if)
  291. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  292. (repeat :inline t :tag "Conditions for skipping"
  293. (choice
  294. :tag "Condition type"
  295. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  296. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  297. (list :tag "TODO state is" :inline t
  298. (const 'todo)
  299. (choice
  300. (const :tag "any not-done state" 'todo)
  301. (const :tag "any done state" 'done)
  302. (const :tag "any state" 'any)
  303. (list :tag "Keyword list"
  304. (const :format "" quote)
  305. (repeat (string :tag "Keyword")))))
  306. (list :tag "TODO state is not" :inline t
  307. (const 'nottodo)
  308. (choice
  309. (const :tag "any not-done state" 'todo)
  310. (const :tag "any done state" 'done)
  311. (const :tag "any state" 'any)
  312. (list :tag "Keyword list"
  313. (const :format "" quote)
  314. (repeat (string :tag "Keyword")))))
  315. (const :tag "scheduled" 'scheduled)
  316. (const :tag "not scheduled" 'notscheduled)
  317. (const :tag "deadline" 'deadline)
  318. (const :tag "no deadline" 'notdeadline)
  319. (const :tag "timestamp" 'timestamp)
  320. (const :tag "no timestamp" 'nottimestamp))))))
  321. (list :tag "Non-standard skipping condition"
  322. :value (org-agenda-skip-function)
  323. (const org-agenda-skip-function)
  324. (sexp :tag "Function or form (quoted!)"))
  325. (list :tag "Any variable"
  326. (variable :tag "Variable")
  327. (sexp :tag "Value (sexp)"))))
  328. "Selection of examples for agenda command settings.
  329. This will be spliced into the custom type of
  330. `org-agenda-custom-commands'.")
  331. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  332. ((agenda "") (alltodo))))
  333. "Custom commands for the agenda.
  334. These commands will be offered on the splash screen displayed by the
  335. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  336. (key desc type match settings files)
  337. key The key (one or more characters as a string) to be associated
  338. with the command.
  339. desc A description of the command, when omitted or nil, a default
  340. description is built using MATCH.
  341. type The command type, any of the following symbols:
  342. agenda The daily/weekly agenda.
  343. todo Entries with a specific TODO keyword, in all agenda files.
  344. search Entries containing search words entry or headline.
  345. tags Tags/Property/TODO match in all agenda files.
  346. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  347. todo-tree Sparse tree of specific TODO keyword in *current* file.
  348. tags-tree Sparse tree with all tags matches in *current* file.
  349. occur-tree Occur sparse tree for *current* file.
  350. ... A user-defined function.
  351. match What to search for:
  352. - a single keyword for TODO keyword searches
  353. - a tags match expression for tags searches
  354. - a word search expression for text searches.
  355. - a regular expression for occur searches
  356. For all other commands, this should be the empty string.
  357. settings A list of option settings, similar to that in a let form, so like
  358. this: ((opt1 val1) (opt2 val2) ...). The values will be
  359. evaluated at the moment of execution, so quote them when needed.
  360. files A list of files file to write the produced agenda buffer to
  361. with the command `org-store-agenda-views'.
  362. If a file name ends in \".html\", an HTML version of the buffer
  363. is written out. If it ends in \".ps\", a postscript version is
  364. produced. Otherwise, only the plain text is written to the file.
  365. You can also define a set of commands, to create a composite agenda buffer.
  366. In this case, an entry looks like this:
  367. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  368. where
  369. desc A description string to be displayed in the dispatcher menu.
  370. cmd An agenda command, similar to the above. However, tree commands
  371. are not allowed, but instead you can get agenda and global todo list.
  372. So valid commands for a set are:
  373. (agenda \"\" settings)
  374. (alltodo \"\" settings)
  375. (stuck \"\" settings)
  376. (todo \"match\" settings files)
  377. (search \"match\" settings files)
  378. (tags \"match\" settings files)
  379. (tags-todo \"match\" settings files)
  380. Each command can carry a list of options, and another set of options can be
  381. given for the whole set of commands. Individual command options take
  382. precedence over the general options.
  383. When using several characters as key to a command, the first characters
  384. are prefix commands. For the dispatcher to display useful information, you
  385. should provide a description for the prefix, like
  386. (setq org-agenda-custom-commands
  387. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  388. (\"hl\" tags \"+HOME+Lisa\")
  389. (\"hp\" tags \"+HOME+Peter\")
  390. (\"hk\" tags \"+HOME+Kim\")))"
  391. :group 'org-agenda-custom-commands
  392. :type `(repeat
  393. (choice :value ("x" "Describe command here" tags "" nil)
  394. (list :tag "Single command"
  395. (string :tag "Access Key(s) ")
  396. (option (string :tag "Description"))
  397. (choice
  398. (const :tag "Agenda" agenda)
  399. (const :tag "TODO list" alltodo)
  400. (const :tag "Search words" search)
  401. (const :tag "Stuck projects" stuck)
  402. (const :tag "Tags/Property match (all agenda files)" tags)
  403. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  404. (const :tag "TODO keyword search (all agenda files)" todo)
  405. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  406. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  407. (const :tag "Occur tree (current buffer)" occur-tree)
  408. (sexp :tag "Other, user-defined function"))
  409. (string :tag "Match (only for some commands)")
  410. ,org-agenda-custom-commands-local-options
  411. (option (repeat :tag "Export" (file :tag "Export to"))))
  412. (list :tag "Command series, all agenda files"
  413. (string :tag "Access Key(s)")
  414. (string :tag "Description ")
  415. (repeat :tag "Component"
  416. (choice
  417. (list :tag "Agenda"
  418. (const :format "" agenda)
  419. (const :tag "" :format "" "")
  420. ,org-agenda-custom-commands-local-options)
  421. (list :tag "TODO list (all keywords)"
  422. (const :format "" alltodo)
  423. (const :tag "" :format "" "")
  424. ,org-agenda-custom-commands-local-options)
  425. (list :tag "Search words"
  426. (const :format "" search)
  427. (string :tag "Match")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "Stuck projects"
  430. (const :format "" stuck)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Tags search"
  434. (const :format "" tags)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Tags search, TODO entries only"
  438. (const :format "" tags-todo)
  439. (string :tag "Match")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "TODO keyword search"
  442. (const :format "" todo)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Other, user-defined function"
  446. (symbol :tag "function")
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)))
  449. (repeat :tag "Settings for entire command set"
  450. (list (variable :tag "Any variable")
  451. (sexp :tag "Value")))
  452. (option (repeat :tag "Export" (file :tag "Export to"))))
  453. (cons :tag "Prefix key documentation"
  454. (string :tag "Access Key(s)")
  455. (string :tag "Description ")))))
  456. (defcustom org-agenda-query-register ?o
  457. "The register holding the current query string.
  458. The purpose of this is that if you construct a query string interactively,
  459. you can then use it to define a custom command."
  460. :group 'org-agenda-custom-commands
  461. :type 'character)
  462. (defcustom org-stuck-projects
  463. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  464. "How to identify stuck projects.
  465. This is a list of four items:
  466. 1. A tags/todo/property matcher string that is used to identify a project.
  467. See the manual for a description of tag and property searches.
  468. The entire tree below a headline matched by this is considered one project.
  469. 2. A list of TODO keywords identifying non-stuck projects.
  470. If the project subtree contains any headline with one of these todo
  471. keywords, the project is considered to be not stuck. If you specify
  472. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  473. 3. A list of tags identifying non-stuck projects.
  474. If the project subtree contains any headline with one of these tags,
  475. the project is considered to be not stuck. If you specify \"*\" as
  476. a tag, any tag will mark the project unstuck. Note that this is about
  477. the explicit presence of a tag somewhere in the subtree, inherited
  478. tags to not count here. If inherited tags make a project not stuck,
  479. use \"-TAG\" in the tags part of the matcher under (1.) above.
  480. 4. An arbitrary regular expression matching non-stuck projects.
  481. If the project turns out to be not stuck, search continues also in the
  482. subtree to see if any of the subtasks have project status.
  483. See also the variable `org-tags-match-list-sublevels' which applies
  484. to projects matched by this search as well.
  485. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  486. or `C-c a #' to produce the list."
  487. :group 'org-agenda-custom-commands
  488. :type '(list
  489. (string :tag "Tags/TODO match to identify a project")
  490. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  491. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  492. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  493. (defcustom org-agenda-filter-effort-default-operator "<"
  494. "The default operator for effort estimate filtering.
  495. If you select an effort estimate limit without first pressing an operator,
  496. this one will be used."
  497. :group 'org-agenda-custom-commands
  498. :type '(choice (const :tag "less or equal" "<")
  499. (const :tag "greater or equal"">")
  500. (const :tag "equal" "=")))
  501. (defgroup org-agenda-skip nil
  502. "Options concerning skipping parts of agenda files."
  503. :tag "Org Agenda Skip"
  504. :group 'org-agenda)
  505. (defcustom org-agenda-skip-function-global nil
  506. "Function to be called at each match during agenda construction.
  507. If this function returns nil, the current match should not be skipped.
  508. If the function decided to skip an agenda match, is must return the
  509. buffer position from which the search should be continued.
  510. This may also be a Lisp form, which will be evaluated.
  511. This variable will be applied to every agenda match, including
  512. tags/property searches and TODO lists. So try to make the test function
  513. do its checking as efficiently as possible. To implement a skipping
  514. condition just for specific agenda commands, use the variable
  515. `org-agenda-skip-function' which can be set in the options section
  516. of custom agenda commands."
  517. :group 'org-agenda-skip
  518. :type 'sexp)
  519. (defgroup org-agenda-daily/weekly nil
  520. "Options concerning the daily/weekly agenda."
  521. :tag "Org Agenda Daily/Weekly"
  522. :group 'org-agenda)
  523. (defgroup org-agenda-todo-list nil
  524. "Options concerning the global todo list agenda view."
  525. :tag "Org Agenda Todo List"
  526. :group 'org-agenda)
  527. (defgroup org-agenda-match-view nil
  528. "Options concerning the general tags/property/todo match agenda view."
  529. :tag "Org Agenda Match View"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-search-view nil
  532. "Options concerning the general tags/property/todo match agenda view."
  533. :tag "Org Agenda Match View"
  534. :group 'org-agenda)
  535. (defvar org-agenda-archives-mode nil
  536. "Non-nil means the agenda will include archived items.
  537. If this is the symbol `trees', trees in the selected agenda scope
  538. that are marked with the ARCHIVE tag will be included anyway. When this is
  539. t, also all archive files associated with the current selection of agenda
  540. files will be included.")
  541. (defcustom org-agenda-skip-comment-trees t
  542. "Non-nil means skip trees that start with the COMMENT keyword.
  543. When nil, these trees are also scanned by agenda commands."
  544. :group 'org-agenda-skip
  545. :type 'boolean)
  546. (defcustom org-agenda-todo-list-sublevels t
  547. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  548. When nil, the sublevels of a TODO entry are not checked, resulting in
  549. potentially much shorter TODO lists."
  550. :group 'org-agenda-skip
  551. :group 'org-agenda-todo-list
  552. :type 'boolean)
  553. (defcustom org-agenda-todo-ignore-with-date nil
  554. "Non-nil means don't show entries with a date in the global todo list.
  555. You can use this if you prefer to mark mere appointments with a TODO keyword,
  556. but don't want them to show up in the TODO list.
  557. When this is set, it also covers deadlines and scheduled items, the settings
  558. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  559. will be ignored.
  560. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  561. :group 'org-agenda-skip
  562. :group 'org-agenda-todo-list
  563. :type 'boolean)
  564. (defcustom org-agenda-todo-ignore-timestamp nil
  565. "Non-nil means don't show entries with a timestamp.
  566. This applies when creating the global todo list.
  567. Valid values are:
  568. past Don't show entries for today or in the past.
  569. future Don't show entries with a timestamp in the future.
  570. The idea behind this is that if it has a future
  571. timestamp, you don't want to think about it until the
  572. date.
  573. all Don't show any entries with a timestamp in the global todo list.
  574. The idea behind this is that by setting a timestamp, you
  575. have already \"taken care\" of this item.
  576. This variable can also have an integer as a value. If positive (N),
  577. todos with a timestamp N or more days in the future will be ignored. If
  578. negative (-N), todos with a timestamp N or more days in the past will be
  579. ignored. If 0, todos with a timestamp either today or in the future will
  580. be ignored. For example, a value of -1 will exclude todos with a
  581. timestamp in the past (yesterday or earlier), while a value of 7 will
  582. exclude todos with a timestamp a week or more in the future.
  583. See also `org-agenda-todo-ignore-with-date'.
  584. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  585. to make his option also apply to the tags-todo list."
  586. :group 'org-agenda-skip
  587. :group 'org-agenda-todo-list
  588. :version "24.1"
  589. :type '(choice
  590. (const :tag "Ignore future timestamp todos" future)
  591. (const :tag "Ignore past or present timestamp todos" past)
  592. (const :tag "Ignore all timestamp todos" all)
  593. (const :tag "Show timestamp todos" nil)
  594. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  595. (defcustom org-agenda-todo-ignore-scheduled nil
  596. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  597. This applies when creating the global todo list.
  598. Valid values are:
  599. past Don't show entries scheduled today or in the past.
  600. future Don't show entries scheduled in the future.
  601. The idea behind this is that by scheduling it, you don't want to
  602. think about it until the scheduled date.
  603. all Don't show any scheduled entries in the global todo list.
  604. The idea behind this is that by scheduling it, you have already
  605. \"taken care\" of this item.
  606. t Same as `all', for backward compatibility.
  607. This variable can also have an integer as a value. See
  608. `org-agenda-todo-ignore-timestamp' for more details.
  609. See also `org-agenda-todo-ignore-with-date'.
  610. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  611. to make his option also apply to the tags-todo list."
  612. :group 'org-agenda-skip
  613. :group 'org-agenda-todo-list
  614. :type '(choice
  615. (const :tag "Ignore future-scheduled todos" future)
  616. (const :tag "Ignore past- or present-scheduled todos" past)
  617. (const :tag "Ignore all scheduled todos" all)
  618. (const :tag "Ignore all scheduled todos (compatibility)" t)
  619. (const :tag "Show scheduled todos" nil)
  620. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  621. (defcustom org-agenda-todo-ignore-deadlines nil
  622. "Non-nil means ignore some deadlined TODO items when making TODO list.
  623. There are different motivations for using different values, please think
  624. carefully when configuring this variable.
  625. This applies when creating the global todo list.
  626. Valid values are:
  627. near Don't show near deadline entries. A deadline is near when it is
  628. closer than `org-deadline-warning-days' days. The idea behind this
  629. is that such items will appear in the agenda anyway.
  630. far Don't show TODO entries where a deadline has been defined, but
  631. the deadline is not near. This is useful if you don't want to
  632. use the todo list to figure out what to do now.
  633. past Don't show entries with a deadline timestamp for today or in the past.
  634. future Don't show entries with a deadline timestamp in the future, not even
  635. when they become `near' ones. Use it with caution.
  636. all Ignore all TODO entries that do have a deadline.
  637. t Same as `near', for backward compatibility.
  638. This variable can also have an integer as a value. See
  639. `org-agenda-todo-ignore-timestamp' for more details.
  640. See also `org-agenda-todo-ignore-with-date'.
  641. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  642. to make his option also apply to the tags-todo list."
  643. :group 'org-agenda-skip
  644. :group 'org-agenda-todo-list
  645. :type '(choice
  646. (const :tag "Ignore near deadlines" near)
  647. (const :tag "Ignore near deadlines (compatibility)" t)
  648. (const :tag "Ignore far deadlines" far)
  649. (const :tag "Ignore all TODOs with a deadlines" all)
  650. (const :tag "Show all TODOs, even if they have a deadline" nil)
  651. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  652. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  653. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  654. The variables
  655. `org-agenda-todo-ignore-with-date',
  656. `org-agenda-todo-ignore-timestamp',
  657. `org-agenda-todo-ignore-scheduled',
  658. `org-agenda-todo-ignore-deadlines'
  659. make the global TODO list skip entries that have time stamps of certain
  660. kinds. If this option is set, the same options will also apply for the
  661. tags-todo search, which is the general tags/property matcher
  662. restricted to unfinished TODO entries only."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-todo-list
  665. :group 'org-agenda-match-view
  666. :type 'boolean)
  667. (defcustom org-agenda-skip-scheduled-if-done nil
  668. "Non-nil means don't show scheduled items in agenda when they are done.
  669. This is relevant for the daily/weekly agenda, not for the TODO list. And
  670. it applies only to the actual date of the scheduling. Warnings about
  671. an item with a past scheduling dates are always turned off when the item
  672. is DONE."
  673. :group 'org-agenda-skip
  674. :group 'org-agenda-daily/weekly
  675. :type 'boolean)
  676. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  677. "Non-nil means skip scheduling line if same entry shows because of deadline.
  678. In the agenda of today, an entry can show up multiple times because
  679. it is both scheduled and has a nearby deadline, and maybe a plain time
  680. stamp as well.
  681. When this variable is t, then only the deadline is shown and the fact that
  682. the entry is scheduled today or was scheduled previously is not shown.
  683. When this variable is nil, the entry will be shown several times. When
  684. the variable is the symbol `not-today', then skip scheduled previously,
  685. but not scheduled today."
  686. :group 'org-agenda-skip
  687. :group 'org-agenda-daily/weekly
  688. :type '(choice
  689. (const :tag "Never" nil)
  690. (const :tag "Always" t)
  691. (const :tag "Not when scheduled today" not-today)))
  692. (defcustom org-agenda-skip-deadline-if-done nil
  693. "Non-nil means don't show deadlines when the corresponding item is done.
  694. When nil, the deadline is still shown and should give you a happy feeling.
  695. This is relevant for the daily/weekly agenda. And it applied only to the
  696. actually date of the deadline. Warnings about approaching and past-due
  697. deadlines are always turned off when the item is DONE."
  698. :group 'org-agenda-skip
  699. :group 'org-agenda-daily/weekly
  700. :type 'boolean)
  701. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  702. "Non-nil means skip deadline prewarning when entry is also scheduled.
  703. This will apply on all days where a prewarning for the deadline would
  704. be shown, but not at the day when the entry is actually due. On that day,
  705. the deadline will be shown anyway.
  706. This variable may be set to nil, t, or a number which will then give
  707. the number of days before the actual deadline when the prewarnings
  708. should resume.
  709. This can be used in a workflow where the first showing of the deadline will
  710. trigger you to schedule it, and then you don't want to be reminded of it
  711. because you will take care of it on the day when scheduled."
  712. :group 'org-agenda-skip
  713. :group 'org-agenda-daily/weekly
  714. :version "24.1"
  715. :type '(choice
  716. (const :tag "Alwas show prewarning" nil)
  717. (const :tag "Remove prewarning if entry is scheduled" t)
  718. (integer :tag "Restart prewarning N days before deadline")))
  719. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  720. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  721. When non-nil, after the search for timestamps has matched once in an
  722. entry, the rest of the entry will not be searched."
  723. :group 'org-agenda-skip
  724. :type 'boolean)
  725. (defcustom org-agenda-skip-timestamp-if-done nil
  726. "Non-nil means don't select item by timestamp or -range if it is DONE."
  727. :group 'org-agenda-skip
  728. :group 'org-agenda-daily/weekly
  729. :type 'boolean)
  730. (defcustom org-agenda-dim-blocked-tasks t
  731. "Non-nil means dim blocked tasks in the agenda display.
  732. This causes some overhead during agenda construction, but if you
  733. have turned on `org-enforce-todo-dependencies',
  734. `org-enforce-todo-checkbox-dependencies', or any other blocking
  735. mechanism, this will create useful feedback in the agenda.
  736. Instead of t, this variable can also have the value `invisible'.
  737. Then blocked tasks will be invisible and only become visible when
  738. they become unblocked. An exemption to this behavior is when a task is
  739. blocked because of unchecked checkboxes below it. Since checkboxes do
  740. not show up in the agenda views, making this task invisible you remove any
  741. trace from agenda views that there is something to do. Therefore, a task
  742. that is blocked because of checkboxes will never be made invisible, it
  743. will only be dimmed."
  744. :group 'org-agenda-daily/weekly
  745. :group 'org-agenda-todo-list
  746. :type '(choice
  747. (const :tag "Do not dim" nil)
  748. (const :tag "Dim to a gray face" t)
  749. (const :tag "Make invisible" invisible)))
  750. (defcustom org-timeline-show-empty-dates 3
  751. "Non-nil means `org-timeline' also shows dates without an entry.
  752. When nil, only the days which actually have entries are shown.
  753. When t, all days between the first and the last date are shown.
  754. When an integer, show also empty dates, but if there is a gap of more than
  755. N days, just insert a special line indicating the size of the gap."
  756. :group 'org-agenda-skip
  757. :type '(choice
  758. (const :tag "None" nil)
  759. (const :tag "All" t)
  760. (integer :tag "at most")))
  761. (defgroup org-agenda-startup nil
  762. "Options concerning initial settings in the Agenda in Org Mode."
  763. :tag "Org Agenda Startup"
  764. :group 'org-agenda)
  765. (defcustom org-agenda-menu-show-matcher t
  766. "Non-nil means show the match string in the agenda dispatcher menu.
  767. When nil, the matcher string is not shown, but is put into the help-echo
  768. property so than moving the mouse over the command shows it.
  769. Setting it to nil is good if matcher strings are very long and/or if
  770. you want to use two-column display (see `org-agenda-menu-two-column')."
  771. :group 'org-agenda
  772. :version "24.1"
  773. :type 'boolean)
  774. (defcustom org-agenda-menu-two-column nil
  775. "Non-nil means, use two columns to show custom commands in the dispatcher.
  776. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  777. to nil."
  778. :group 'org-agenda
  779. :version "24.1"
  780. :type 'boolean)
  781. (defcustom org-finalize-agenda-hook nil
  782. "Hook run just before displaying an agenda buffer."
  783. :group 'org-agenda-startup
  784. :type 'hook)
  785. (defcustom org-agenda-mouse-1-follows-link nil
  786. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  787. A longer mouse click will still set point. Does not work on XEmacs.
  788. Needs to be set before org.el is loaded."
  789. :group 'org-agenda-startup
  790. :type 'boolean)
  791. (defcustom org-agenda-start-with-follow-mode nil
  792. "The initial value of follow mode in a newly created agenda window."
  793. :group 'org-agenda-startup
  794. :type 'boolean)
  795. (defcustom org-agenda-follow-indirect nil
  796. "Non-nil means `org-agenda-follow-mode' displays only the
  797. current item's tree, in an indirect buffer."
  798. :group 'org-agenda
  799. :version "24.1"
  800. :type 'boolean)
  801. (defcustom org-agenda-show-outline-path t
  802. "Non-nil means show outline path in echo area after line motion."
  803. :group 'org-agenda-startup
  804. :type 'boolean)
  805. (defcustom org-agenda-start-with-entry-text-mode nil
  806. "The initial value of entry-text-mode in a newly created agenda window."
  807. :group 'org-agenda-startup
  808. :type 'boolean)
  809. (defcustom org-agenda-entry-text-maxlines 5
  810. "Number of text lines to be added when `E' is pressed in the agenda.
  811. Note that this variable only used during agenda display. Add add entry text
  812. when exporting the agenda, configure the variable
  813. `org-agenda-add-entry-ext-maxlines'."
  814. :group 'org-agenda
  815. :type 'integer)
  816. (defcustom org-agenda-entry-text-exclude-regexps nil
  817. "List of regular expressions to clean up entry text.
  818. The complete matches of all regular expressions in this list will be
  819. removed from entry text before it is shown in the agenda."
  820. :group 'org-agenda
  821. :type '(repeat (regexp)))
  822. (defvar org-agenda-entry-text-cleanup-hook nil
  823. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  824. This cleanup is done in a temporary buffer, so the function may inspect and
  825. change the entire buffer.
  826. Some default stuff like drawers and scheduling/deadline dates will already
  827. have been removed when this is called, as will any matches for regular
  828. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  829. (defvar org-agenda-include-inactive-timestamps nil
  830. "Non-nil means include inactive time stamps in agenda and timeline.")
  831. (defgroup org-agenda-windows nil
  832. "Options concerning the windows used by the Agenda in Org Mode."
  833. :tag "Org Agenda Windows"
  834. :group 'org-agenda)
  835. (defcustom org-agenda-window-setup 'reorganize-frame
  836. "How the agenda buffer should be displayed.
  837. Possible values for this option are:
  838. current-window Show agenda in the current window, keeping all other windows.
  839. other-window Use `switch-to-buffer-other-window' to display agenda.
  840. reorganize-frame Show only two windows on the current frame, the current
  841. window and the agenda.
  842. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  843. Also, when exiting the agenda, kill that frame.
  844. See also the variable `org-agenda-restore-windows-after-quit'."
  845. :group 'org-agenda-windows
  846. :type '(choice
  847. (const current-window)
  848. (const other-frame)
  849. (const other-window)
  850. (const reorganize-frame)))
  851. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  852. "The min and max height of the agenda window as a fraction of frame height.
  853. The value of the variable is a cons cell with two numbers between 0 and 1.
  854. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  855. :group 'org-agenda-windows
  856. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  857. (defcustom org-agenda-restore-windows-after-quit nil
  858. "Non-nil means restore window configuration upon exiting agenda.
  859. Before the window configuration is changed for displaying the agenda,
  860. the current status is recorded. When the agenda is exited with
  861. `q' or `x' and this option is set, the old state is restored. If
  862. `org-agenda-window-setup' is `other-frame', the value of this
  863. option will be ignored."
  864. :group 'org-agenda-windows
  865. :type 'boolean)
  866. (defcustom org-agenda-ndays nil
  867. "Number of days to include in overview display.
  868. Should be 1 or 7.
  869. Obsolete, see `org-agenda-span'."
  870. :group 'org-agenda-daily/weekly
  871. :type 'integer)
  872. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  873. (defcustom org-agenda-span 'week
  874. "Number of days to include in overview display.
  875. Can be day, week, month, year, or any number of days.
  876. Custom commands can set this variable in the options section."
  877. :group 'org-agenda-daily/weekly
  878. :type '(choice (const :tag "Day" day)
  879. (const :tag "Week" week)
  880. (const :tag "Month" month)
  881. (const :tag "Year" year)
  882. (integer :tag "Custom")))
  883. (defcustom org-agenda-start-on-weekday 1
  884. "Non-nil means start the overview always on the specified weekday.
  885. 0 denotes Sunday, 1 denotes Monday etc.
  886. When nil, always start on the current day.
  887. Custom commands can set this variable in the options section."
  888. :group 'org-agenda-daily/weekly
  889. :type '(choice (const :tag "Today" nil)
  890. (integer :tag "Weekday No.")))
  891. (defcustom org-agenda-show-all-dates t
  892. "Non-nil means `org-agenda' shows every day in the selected range.
  893. When nil, only the days which actually have entries are shown."
  894. :group 'org-agenda-daily/weekly
  895. :type 'boolean)
  896. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  897. "Format string for displaying dates in the agenda.
  898. Used by the daily/weekly agenda and by the timeline. This should be
  899. a format string understood by `format-time-string', or a function returning
  900. the formatted date as a string. The function must take a single argument,
  901. a calendar-style date list like (month day year)."
  902. :group 'org-agenda-daily/weekly
  903. :type '(choice
  904. (string :tag "Format string")
  905. (function :tag "Function")))
  906. (defun org-agenda-format-date-aligned (date)
  907. "Format a date string for display in the daily/weekly agenda, or timeline.
  908. This function makes sure that dates are aligned for easy reading."
  909. (require 'cal-iso)
  910. (let* ((dayname (calendar-day-name date))
  911. (day (cadr date))
  912. (day-of-week (calendar-day-of-week date))
  913. (month (car date))
  914. (monthname (calendar-month-name month))
  915. (year (nth 2 date))
  916. (iso-week (org-days-to-iso-week
  917. (calendar-absolute-from-gregorian date)))
  918. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  919. (1- year))
  920. ((and (= month 12) (<= iso-week 1))
  921. (1+ year))
  922. (t year)))
  923. (weekstring (if (= day-of-week 1)
  924. (format " W%02d" iso-week)
  925. "")))
  926. (format "%-10s %2d %s %4d%s"
  927. dayname day monthname year weekstring)))
  928. (defcustom org-agenda-time-leading-zero nil
  929. "Non-nil means use leading zero for military times in agenda.
  930. For example, 9:30am would become 09:30 rather than 9:30."
  931. :group 'org-agenda-daily/weekly
  932. :version "24.1"
  933. :type 'boolean)
  934. (defcustom org-agenda-timegrid-use-ampm nil
  935. "When set, show AM/PM style timestamps on the timegrid."
  936. :group 'org-agenda
  937. :version "24.1"
  938. :type 'boolean)
  939. (defun org-agenda-time-of-day-to-ampm (time)
  940. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  941. (let* ((hour-number (string-to-number (substring time 0 -3)))
  942. (minute (substring time -2))
  943. (ampm "am"))
  944. (cond
  945. ((equal hour-number 12)
  946. (setq ampm "pm"))
  947. ((> hour-number 12)
  948. (setq ampm "pm")
  949. (setq hour-number (- hour-number 12))))
  950. (concat
  951. (if org-agenda-time-leading-zero
  952. (format "%02d" hour-number)
  953. (format "%02s" (number-to-string hour-number)))
  954. ":" minute ampm)))
  955. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  956. "Conditionally convert TIME to AM/PM format
  957. based on `org-agenda-timegrid-use-ampm'"
  958. (if org-agenda-timegrid-use-ampm
  959. (org-agenda-time-of-day-to-ampm time)
  960. time))
  961. (defcustom org-agenda-weekend-days '(6 0)
  962. "Which days are weekend?
  963. These days get the special face `org-agenda-date-weekend' in the agenda
  964. and timeline buffers."
  965. :group 'org-agenda-daily/weekly
  966. :type '(set :greedy t
  967. (const :tag "Monday" 1)
  968. (const :tag "Tuesday" 2)
  969. (const :tag "Wednesday" 3)
  970. (const :tag "Thursday" 4)
  971. (const :tag "Friday" 5)
  972. (const :tag "Saturday" 6)
  973. (const :tag "Sunday" 0)))
  974. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  975. "Non-nil means jump to today when moving a past date forward in time.
  976. When using S-right in the agenda to move a a date forward, and the date
  977. stamp currently points to the past, the first key press will move it
  978. to today. WHen nil, just move one day forward even if the date stays
  979. in the past."
  980. :group 'org-agenda-daily/weekly
  981. :version "24.1"
  982. :type 'boolean)
  983. (defcustom org-agenda-include-diary nil
  984. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  985. Custom commands can set this variable in the options section."
  986. :group 'org-agenda-daily/weekly
  987. :type 'boolean)
  988. (defcustom org-agenda-include-deadlines t
  989. "If non-nil, include entries within their deadline warning period.
  990. Custom commands can set this variable in the options section."
  991. :group 'org-agenda-daily/weekly
  992. :version "24.1"
  993. :type 'boolean)
  994. (defcustom org-agenda-repeating-timestamp-show-all t
  995. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  996. When set to a list of strings, only show occurrences of repeating
  997. stamps for these TODO keywords. When nil, only one occurrence is
  998. shown, either today or the nearest into the future."
  999. :group 'org-agenda-daily/weekly
  1000. :type '(choice
  1001. (const :tag "Show repeating stamps" t)
  1002. (repeat :tag "Show repeating stamps for these TODO keywords"
  1003. (string :tag "TODO Keyword"))
  1004. (const :tag "Don't show repeating stamps" nil)))
  1005. (defcustom org-scheduled-past-days 10000
  1006. "No. of days to continue listing scheduled items that are not marked DONE.
  1007. When an item is scheduled on a date, it shows up in the agenda on this
  1008. day and will be listed until it is marked done for the number of days
  1009. given here."
  1010. :group 'org-agenda-daily/weekly
  1011. :type 'integer)
  1012. (defcustom org-agenda-log-mode-items '(closed clock)
  1013. "List of items that should be shown in agenda log mode.
  1014. This list may contain the following symbols:
  1015. closed Show entries that have been closed on that day.
  1016. clock Show entries that have received clocked time on that day.
  1017. state Show all logged state changes.
  1018. Note that instead of changing this variable, you can also press `C-u l' in
  1019. the agenda to display all available LOG items temporarily."
  1020. :group 'org-agenda-daily/weekly
  1021. :type '(set :greedy t (const closed) (const clock) (const state)))
  1022. (defcustom org-agenda-clock-consistency-checks
  1023. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1024. :gap-ok-around ("4:00")
  1025. :default-face ((:background "DarkRed") (:foreground "white"))
  1026. :overlap-face nil :gap-face nil :no-end-time-face nil
  1027. :long-face nil :short-face nil)
  1028. "This is a property list, with the following keys:
  1029. :max-duration Mark clocking chunks that are longer than this time.
  1030. This is a time string like \"HH:MM\", or the number
  1031. of minutes as an integer.
  1032. :min-duration Mark clocking chunks that are shorter that this.
  1033. This is a time string like \"HH:MM\", or the number
  1034. of minutes as an integer.
  1035. :max-gap Mark gaps between clocking chunks that are longer than
  1036. this duration. A number of minutes, or a string
  1037. like \"HH:MM\".
  1038. :gap-ok-around List of times during the day which are usually not working
  1039. times. When a gap is detected, but the gap contains any
  1040. of these times, the gap is *not* reported. For example,
  1041. if this is (\"4:00\" \"13:00\") then gaps that contain
  1042. 4:00 in the morning (i.e. the night) and 13:00
  1043. (i.e. a typical lunch time) do not cause a warning.
  1044. You should have at least one time during the night in this
  1045. list, or otherwise the first task each morning will trigger
  1046. a warning because it follows a long gap.
  1047. Furthermore, the following properties can be used to define faces for
  1048. issue display.
  1049. :default-face the default face, if the specific face is undefined
  1050. :overlap-face face for overlapping clocks
  1051. :gap-face face for gaps between clocks
  1052. :no-end-time-face face for incomplete clocks
  1053. :long-face face for clock intervals that are too long
  1054. :short-face face for clock intervals that are too short"
  1055. :group 'org-agenda-daily/weekly
  1056. :group 'org-clock
  1057. :version "24.1"
  1058. :type 'plist)
  1059. (defcustom org-agenda-log-mode-add-notes t
  1060. "Non-nil means add first line of notes to log entries in agenda views.
  1061. If a log item like a state change or a clock entry is associated with
  1062. notes, the first line of these notes will be added to the entry in the
  1063. agenda display."
  1064. :group 'org-agenda-daily/weekly
  1065. :type 'boolean)
  1066. (defcustom org-agenda-start-with-log-mode nil
  1067. "The initial value of log-mode in a newly created agenda window."
  1068. :group 'org-agenda-startup
  1069. :group 'org-agenda-daily/weekly
  1070. :type 'boolean)
  1071. (defcustom org-agenda-start-with-clockreport-mode nil
  1072. "The initial value of clockreport-mode in a newly created agenda window."
  1073. :group 'org-agenda-startup
  1074. :group 'org-agenda-daily/weekly
  1075. :type 'boolean)
  1076. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1077. "Property list with parameters for the clocktable in clockreport mode.
  1078. This is the display mode that shows a clock table in the daily/weekly
  1079. agenda, the properties for this dynamic block can be set here.
  1080. The usual clocktable parameters are allowed here, but you cannot set
  1081. the properties :name, :tstart, :tend, :block, and :scope - these will
  1082. be overwritten to make sure the content accurately reflects the
  1083. current display in the agenda."
  1084. :group 'org-agenda-daily/weekly
  1085. :type 'plist)
  1086. (defcustom org-agenda-search-view-always-boolean nil
  1087. "Non-nil means the search string is interpreted as individual parts.
  1088. The search string for search view can either be interpreted as a phrase,
  1089. or as a list of snippets that define a boolean search for a number of
  1090. strings.
  1091. When this is non-nil, the string will be split on whitespace, and each
  1092. snippet will be searched individually, and all must match in order to
  1093. select an entry. A snippet is then a single string of non-white
  1094. characters, or a string in double quotes, or a regexp in {} braces.
  1095. If a snippet is preceded by \"-\", the snippet must *not* match.
  1096. \"+\" is syntactic sugar for positive selection. Each snippet may
  1097. be found as a full word or a partial word, but see the variable
  1098. `org-agenda-search-view-force-full-words'.
  1099. When this is nil, search will look for the entire search phrase as one,
  1100. with each space character matching any amount of whitespace, including
  1101. line breaks.
  1102. Even when this is nil, you can still switch to Boolean search dynamically
  1103. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1104. is a regexp marked with braces like \"{abc}\", this will also switch to
  1105. boolean search."
  1106. :group 'org-agenda-search-view
  1107. :version "24.1"
  1108. :type 'boolean)
  1109. (if (fboundp 'defvaralias)
  1110. (defvaralias 'org-agenda-search-view-search-words-only
  1111. 'org-agenda-search-view-always-boolean))
  1112. (defcustom org-agenda-search-view-force-full-words nil
  1113. "Non-nil means, search words must be matches as complete words.
  1114. When nil, they may also match part of a word."
  1115. :group 'org-agenda-search-view
  1116. :version "24.1"
  1117. :type 'boolean)
  1118. (defgroup org-agenda-time-grid nil
  1119. "Options concerning the time grid in the Org-mode Agenda."
  1120. :tag "Org Agenda Time Grid"
  1121. :group 'org-agenda)
  1122. (defcustom org-agenda-search-headline-for-time t
  1123. "Non-nil means search headline for a time-of-day.
  1124. If the headline contains a time-of-day in one format or another, it will
  1125. be used to sort the entry into the time sequence of items for a day.
  1126. Some people have time stamps in the headline that refer to the creation
  1127. time or so, and then this produces an unwanted side effect. If this is
  1128. the case for your, use this variable to turn off searching the headline
  1129. for a time."
  1130. :group 'org-agenda-time-grid
  1131. :type 'boolean)
  1132. (defcustom org-agenda-use-time-grid t
  1133. "Non-nil means show a time grid in the agenda schedule.
  1134. A time grid is a set of lines for specific times (like every two hours between
  1135. 8:00 and 20:00). The items scheduled for a day at specific times are
  1136. sorted in between these lines.
  1137. For details about when the grid will be shown, and what it will look like, see
  1138. the variable `org-agenda-time-grid'."
  1139. :group 'org-agenda-time-grid
  1140. :type 'boolean)
  1141. (defcustom org-agenda-time-grid
  1142. '((daily today require-timed)
  1143. "----------------"
  1144. (800 1000 1200 1400 1600 1800 2000))
  1145. "The settings for time grid for agenda display.
  1146. This is a list of three items. The first item is again a list. It contains
  1147. symbols specifying conditions when the grid should be displayed:
  1148. daily if the agenda shows a single day
  1149. weekly if the agenda shows an entire week
  1150. today show grid on current date, independent of daily/weekly display
  1151. require-timed show grid only if at least one item has a time specification
  1152. The second item is a string which will be placed behind the grid time.
  1153. The third item is a list of integers, indicating the times that should have
  1154. a grid line."
  1155. :group 'org-agenda-time-grid
  1156. :type
  1157. '(list
  1158. (set :greedy t :tag "Grid Display Options"
  1159. (const :tag "Show grid in single day agenda display" daily)
  1160. (const :tag "Show grid in weekly agenda display" weekly)
  1161. (const :tag "Always show grid for today" today)
  1162. (const :tag "Show grid only if any timed entries are present"
  1163. require-timed)
  1164. (const :tag "Skip grid times already present in an entry"
  1165. remove-match))
  1166. (string :tag "Grid String")
  1167. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1168. (defcustom org-agenda-show-current-time-in-grid t
  1169. "Non-nil means show the current time in the time grid."
  1170. :group 'org-agenda-time-grid
  1171. :version "24.1"
  1172. :type 'boolean)
  1173. (defcustom org-agenda-current-time-string
  1174. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1175. "The string for the current time marker in the agenda."
  1176. :group 'org-agenda-time-grid
  1177. :version "24.1"
  1178. :type 'string)
  1179. (defgroup org-agenda-sorting nil
  1180. "Options concerning sorting in the Org-mode Agenda."
  1181. :tag "Org Agenda Sorting"
  1182. :group 'org-agenda)
  1183. (defcustom org-agenda-sorting-strategy
  1184. '((agenda habit-down time-up priority-down category-keep)
  1185. (todo priority-down category-keep)
  1186. (tags priority-down category-keep)
  1187. (search category-keep))
  1188. "Sorting structure for the agenda items of a single day.
  1189. This is a list of symbols which will be used in sequence to determine
  1190. if an entry should be listed before another entry. The following
  1191. symbols are recognized:
  1192. time-up Put entries with time-of-day indications first, early first
  1193. time-down Put entries with time-of-day indications first, late first
  1194. category-keep Keep the default order of categories, corresponding to the
  1195. sequence in `org-agenda-files'.
  1196. category-up Sort alphabetically by category, A-Z.
  1197. category-down Sort alphabetically by category, Z-A.
  1198. tag-up Sort alphabetically by last tag, A-Z.
  1199. tag-down Sort alphabetically by last tag, Z-A.
  1200. priority-up Sort numerically by priority, high priority last.
  1201. priority-down Sort numerically by priority, high priority first.
  1202. todo-state-up Sort by todo state, tasks that are done last.
  1203. todo-state-down Sort by todo state, tasks that are done first.
  1204. effort-up Sort numerically by estimated effort, high effort last.
  1205. effort-down Sort numerically by estimated effort, high effort first.
  1206. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1207. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1208. habit-up Put entries that are habits first
  1209. habit-down Put entries that are habits last
  1210. alpha-up Sort headlines alphabetically
  1211. alpha-down Sort headlines alphabetically, reversed
  1212. The different possibilities will be tried in sequence, and testing stops
  1213. if one comparison returns a \"not-equal\". For example, the default
  1214. '(time-up category-keep priority-down)
  1215. means: Pull out all entries having a specified time of day and sort them,
  1216. in order to make a time schedule for the current day the first thing in the
  1217. agenda listing for the day. Of the entries without a time indication, keep
  1218. the grouped in categories, don't sort the categories, but keep them in
  1219. the sequence given in `org-agenda-files'. Within each category sort by
  1220. priority.
  1221. Leaving out `category-keep' would mean that items will be sorted across
  1222. categories by priority.
  1223. Instead of a single list, this can also be a set of list for specific
  1224. contents, with a context symbol in the car of the list, any of
  1225. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1226. Custom commands can bind this variable in the options section."
  1227. :group 'org-agenda-sorting
  1228. :type `(choice
  1229. (repeat :tag "General" ,org-sorting-choice)
  1230. (list :tag "Individually"
  1231. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1232. (repeat ,org-sorting-choice))
  1233. (cons (const :tag "Strategy for TODO lists" todo)
  1234. (repeat ,org-sorting-choice))
  1235. (cons (const :tag "Strategy for Tags matches" tags)
  1236. (repeat ,org-sorting-choice))
  1237. (cons (const :tag "Strategy for search matches" search)
  1238. (repeat ,org-sorting-choice)))))
  1239. (defcustom org-agenda-cmp-user-defined nil
  1240. "A function to define the comparison `user-defined'.
  1241. This function must receive two arguments, agenda entry a and b.
  1242. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1243. the user comparison, return nil.
  1244. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1245. part of an agenda sorting strategy."
  1246. :group 'org-agenda-sorting
  1247. :type 'symbol)
  1248. (defcustom org-sort-agenda-notime-is-late t
  1249. "Non-nil means items without time are considered late.
  1250. This is only relevant for sorting. When t, items which have no explicit
  1251. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1252. do have a time. When nil, the default time is before 0:00. You can use this
  1253. option to decide if the schedule for today should come before or after timeless
  1254. agenda entries."
  1255. :group 'org-agenda-sorting
  1256. :type 'boolean)
  1257. (defcustom org-sort-agenda-noeffort-is-high t
  1258. "Non-nil means items without effort estimate are sorted as high effort.
  1259. This also applies when filtering an agenda view with respect to the
  1260. < or > effort operator. Then, tasks with no effort defined will be treated
  1261. as tasks with high effort.
  1262. When nil, such items are sorted as 0 minutes effort."
  1263. :group 'org-agenda-sorting
  1264. :type 'boolean)
  1265. (defgroup org-agenda-line-format nil
  1266. "Options concerning the entry prefix in the Org-mode agenda display."
  1267. :tag "Org Agenda Line Format"
  1268. :group 'org-agenda)
  1269. (defcustom org-agenda-prefix-format
  1270. '((agenda . " %i %-12:c%?-12t% s")
  1271. (timeline . " % s")
  1272. (todo . " %i %-12:c")
  1273. (tags . " %i %-12:c")
  1274. (search . " %i %-12:c"))
  1275. "Format specifications for the prefix of items in the agenda views.
  1276. An alist with five entries, each for the different agenda types. The
  1277. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1278. The values are format strings.
  1279. This format works similar to a printf format, with the following meaning:
  1280. %c the category of the item, \"Diary\" for entries from the diary,
  1281. or as given by the CATEGORY keyword or derived from the file name
  1282. %e the effort required by the item
  1283. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1284. %T the last tag of the item (ignore inherited tags, which come first)
  1285. %t the HH:MM time-of-day specification if one applies to the entry
  1286. %s Scheduling/Deadline information, a short string
  1287. %(expression) Eval EXPRESSION and replace the control string
  1288. by the result
  1289. All specifiers work basically like the standard `%s' of printf, but may
  1290. contain two additional characters: a question mark just after the `%'
  1291. and a whitespace/punctuation character just before the final letter.
  1292. If the first character after `%' is a question mark, the entire field
  1293. will only be included if the corresponding value applies to the current
  1294. entry. This is useful for fields which should have fixed width when
  1295. present, but zero width when absent. For example, \"%?-12t\" will
  1296. result in a 12 character time field if a time of the day is specified,
  1297. but will completely disappear in entries which do not contain a time.
  1298. If there is punctuation or whitespace character just before the final
  1299. format letter, this character will be appended to the field value if
  1300. the value is not empty. For example, the format \"%-12:c\" leads to
  1301. \"Diary: \" if the category is \"Diary\". If the category were be
  1302. empty, no additional colon would be inserted.
  1303. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1304. which means:
  1305. - Indent the line with two space characters
  1306. - Give the category a 12 chars wide field, padded with whitespace on
  1307. the right (because of `-'). Append a colon if there is a category
  1308. (because of `:').
  1309. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1310. time, don't put in an empty field, just skip it (because of '?').
  1311. - Finally, put the scheduling information.
  1312. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1313. `org-agenda-remove-tags'.
  1314. Custom commands can set this variable in the options section."
  1315. :type '(choice
  1316. (string :tag "General format")
  1317. (list :greedy t :tag "View dependent"
  1318. (cons (const agenda) (string :tag "Format"))
  1319. (cons (const timeline) (string :tag "Format"))
  1320. (cons (const todo) (string :tag "Format"))
  1321. (cons (const tags) (string :tag "Format"))
  1322. (cons (const search) (string :tag "Format"))))
  1323. :group 'org-agenda-line-format)
  1324. (defvar org-prefix-format-compiled nil
  1325. "The compiled version of the most recently used prefix format.
  1326. See the variable `org-agenda-prefix-format'.")
  1327. (defcustom org-agenda-todo-keyword-format "%-1s"
  1328. "Format for the TODO keyword in agenda lines.
  1329. Set this to something like \"%-12s\" if you want all TODO keywords
  1330. to occupy a fixed space in the agenda display."
  1331. :group 'org-agenda-line-format
  1332. :type 'string)
  1333. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1334. "Text preceding timerange entries in the agenda view.
  1335. This is a list with two strings. The first applies when the range
  1336. is entirely on one day. The second applies if the range spans several days.
  1337. The strings may have two \"%d\" format specifiers which will be filled
  1338. with the sequence number of the days, and the total number of days in the
  1339. range, respectively."
  1340. :group 'org-agenda-line-format
  1341. :type '(list
  1342. (string :tag "Deadline today ")
  1343. (choice :tag "Deadline relative"
  1344. (string :tag "Format string")
  1345. (function))))
  1346. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1347. "Text preceding scheduled items in the agenda view.
  1348. This is a list with two strings. The first applies when the item is
  1349. scheduled on the current day. The second applies when it has been scheduled
  1350. previously, it may contain a %d indicating that this is the nth time that
  1351. this item is scheduled, due to automatic rescheduling of unfinished items
  1352. for the following day. So this number is one larger than the number of days
  1353. that passed since this item was scheduled first."
  1354. :group 'org-agenda-line-format
  1355. :type '(list
  1356. (string :tag "Scheduled today ")
  1357. (string :tag "Scheduled previously")))
  1358. (defcustom org-agenda-inactive-leader "["
  1359. "Text preceding item pulled into the agenda by inactive time stamps.
  1360. These entries are added to the agenda when pressing \"[\"."
  1361. :group 'org-agenda-line-format
  1362. :version "24.1"
  1363. :type '(list
  1364. (string :tag "Scheduled today ")
  1365. (string :tag "Scheduled previously")))
  1366. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1367. "Text preceding deadline items in the agenda view.
  1368. This is a list with two strings. The first applies when the item has its
  1369. deadline on the current day. The second applies when it is in the past or
  1370. in the future, it may contain %d to capture how many days away the deadline
  1371. is (was)."
  1372. :group 'org-agenda-line-format
  1373. :type '(list
  1374. (string :tag "Deadline today ")
  1375. (choice :tag "Deadline relative"
  1376. (string :tag "Format string")
  1377. (function))))
  1378. (defcustom org-agenda-remove-times-when-in-prefix t
  1379. "Non-nil means remove duplicate time specifications in agenda items.
  1380. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1381. time-of-day specification in a headline or diary entry is extracted and
  1382. placed into the prefix. If this option is non-nil, the original specification
  1383. \(a timestamp or -range, or just a plain time(range) specification like
  1384. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1385. cluttered.
  1386. The option can be t or nil. It may also be the symbol `beg', indicating
  1387. that the time should only be removed when it is located at the beginning of
  1388. the headline/diary entry."
  1389. :group 'org-agenda-line-format
  1390. :type '(choice
  1391. (const :tag "Always" t)
  1392. (const :tag "Never" nil)
  1393. (const :tag "When at beginning of entry" beg)))
  1394. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1395. "Non-nil means remove time ranges specifications in agenda
  1396. items that span on several days."
  1397. :group 'org-agenda-line-format
  1398. :version "24.1"
  1399. :type 'boolean)
  1400. (defcustom org-agenda-default-appointment-duration nil
  1401. "Default duration for appointments that only have a starting time.
  1402. When nil, no duration is specified in such cases.
  1403. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1404. :group 'org-agenda-line-format
  1405. :type '(choice
  1406. (integer :tag "Minutes")
  1407. (const :tag "No default duration")))
  1408. (defcustom org-agenda-show-inherited-tags t
  1409. "Non-nil means show inherited tags in each agenda line."
  1410. :group 'org-agenda-line-format
  1411. :type 'boolean)
  1412. (defcustom org-agenda-hide-tags-regexp nil
  1413. "Regular expression used to filter away specific tags in agenda views.
  1414. This means that these tags will be present, but not be shown in the agenda
  1415. line. Secondary filtering will still work on the hidden tags.
  1416. Nil means don't hide any tags."
  1417. :group 'org-agenda-line-format
  1418. :type '(choice
  1419. (const :tag "Hide none" nil)
  1420. (string :tag "Regexp ")))
  1421. (defcustom org-agenda-remove-tags nil
  1422. "Non-nil means remove the tags from the headline copy in the agenda.
  1423. When this is the symbol `prefix', only remove tags when
  1424. `org-agenda-prefix-format' contains a `%T' specifier."
  1425. :group 'org-agenda-line-format
  1426. :type '(choice
  1427. (const :tag "Always" t)
  1428. (const :tag "Never" nil)
  1429. (const :tag "When prefix format contains %T" prefix)))
  1430. (if (fboundp 'defvaralias)
  1431. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1432. 'org-agenda-remove-tags))
  1433. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1434. "Shift tags in agenda items to this column.
  1435. If this number is positive, it specifies the column. If it is negative,
  1436. it means that the tags should be flushright to that column. For example,
  1437. -80 works well for a normal 80 character screen."
  1438. :group 'org-agenda-line-format
  1439. :type 'integer)
  1440. (if (fboundp 'defvaralias)
  1441. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1442. (defcustom org-agenda-fontify-priorities 'cookies
  1443. "Non-nil means highlight low and high priorities in agenda.
  1444. When t, the highest priority entries are bold, lowest priority italic.
  1445. However, settings in `org-priority-faces' will overrule these faces.
  1446. When this variable is the symbol `cookies', only fontify the
  1447. cookies, not the entire task.
  1448. This may also be an association list of priority faces, whose
  1449. keys are the character values of `org-highest-priority',
  1450. `org-default-priority', and `org-lowest-priority' (the default values
  1451. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1452. color as a string, or a list like `(:background \"Red\")'.
  1453. If it is a color, the variable `org-faces-easy-properties'
  1454. determines if it is a foreground or a background color."
  1455. :group 'org-agenda-line-format
  1456. :type '(choice
  1457. (const :tag "Never" nil)
  1458. (const :tag "Defaults" t)
  1459. (const :tag "Cookies only" cookies)
  1460. (repeat :tag "Specify"
  1461. (list (character :tag "Priority" :value ?A)
  1462. (choice :tag "Face "
  1463. (string :tag "Color")
  1464. (sexp :tag "Face"))))))
  1465. (defcustom org-agenda-day-face-function nil
  1466. "Function called to determine what face should be used to display a day.
  1467. The only argument passed to that function is the day. It should
  1468. returns a face, or nil if does not want to specify a face and let
  1469. the normal rules apply."
  1470. :group 'org-agenda-line-format
  1471. :version "24.1"
  1472. :type 'function)
  1473. (defcustom org-agenda-category-icon-alist nil
  1474. "Alist of category icon to be displayed in agenda views.
  1475. Each entry should have the following format:
  1476. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1477. Where CATEGORY-REGEXP is a regexp matching the categories where
  1478. the icon should be displayed.
  1479. FILE-OR-DATA either a file path or a string containing image data.
  1480. The other fields can be omitted safely if not needed:
  1481. TYPE indicates the image type.
  1482. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1483. image data.
  1484. PROPS are additional image attributes to assign to the image,
  1485. like, e.g. `:ascent center'.
  1486. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1487. If you want to set the display properties yourself, just put a
  1488. list as second element:
  1489. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1490. For example, to display a 16px horizontal space for Emacs
  1491. category, you can use:
  1492. (\"Emacs\" '(space . (:width (16))))"
  1493. :group 'org-agenda-line-format
  1494. :version "24.1"
  1495. :type '(alist :key-type (string :tag "Regexp matching category")
  1496. :value-type (choice (list :tag "Icon"
  1497. (string :tag "File or data")
  1498. (symbol :tag "Type")
  1499. (boolean :tag "Data?")
  1500. (repeat :tag "Extra image properties" :inline t symbol))
  1501. (list :tag "Display properties" sexp))))
  1502. (defgroup org-agenda-column-view nil
  1503. "Options concerning column view in the agenda."
  1504. :tag "Org Agenda Column View"
  1505. :group 'org-agenda)
  1506. (defcustom org-agenda-columns-show-summaries t
  1507. "Non-nil means show summaries for columns displayed in the agenda view."
  1508. :group 'org-agenda-column-view
  1509. :type 'boolean)
  1510. (defcustom org-agenda-columns-compute-summary-properties t
  1511. "Non-nil means recompute all summary properties before column view.
  1512. When column view in the agenda is listing properties that have a summary
  1513. operator, it can go to all relevant buffers and recompute the summaries
  1514. there. This can mean overhead for the agenda column view, but is necessary
  1515. to have thing up to date.
  1516. As a special case, a CLOCKSUM property also makes sure that the clock
  1517. computations are current."
  1518. :group 'org-agenda-column-view
  1519. :type 'boolean)
  1520. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1521. "Non-nil means the duration of an appointment will add to day effort.
  1522. The property to which appointment durations will be added is the one given
  1523. in the option `org-effort-property'. If an appointment does not have
  1524. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1525. is not set, an appointment without end time will not contribute to the time
  1526. estimate."
  1527. :group 'org-agenda-column-view
  1528. :type 'boolean)
  1529. (defcustom org-agenda-auto-exclude-function nil
  1530. "A function called with a tag to decide if it is filtered on '/ RET'.
  1531. The sole argument to the function, which is called once for each
  1532. possible tag, is a string giving the name of the tag. The
  1533. function should return either nil if the tag should be included
  1534. as normal, or \"-<TAG>\" to exclude the tag.
  1535. Note that for the purpose of tag filtering, only the lower-case version of
  1536. all tags will be considered, so that this function will only ever see
  1537. the lower-case version of all tags."
  1538. :group 'org-agenda
  1539. :type 'function)
  1540. (defcustom org-agenda-bulk-custom-functions nil
  1541. "Alist of characters and custom functions for bulk actions.
  1542. For example, this value makes those two functions available:
  1543. '((?R set-category)
  1544. (?C bulk-cut))
  1545. With selected entries in an agenda buffer, `B R' will call
  1546. the custom function `set-category' on the selected entries.
  1547. Note that functions in this alist don't need to be quoted."
  1548. :type 'alist
  1549. :version "24.1"
  1550. :group 'org-agenda)
  1551. (eval-when-compile
  1552. (require 'cl))
  1553. (require 'org)
  1554. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1555. "Execute BODY with point at location given by `org-hd-marker' property.
  1556. If STRING is non-nil, the text property will be fetched from position 0
  1557. in that string. If STRING is nil, it will be fetched from the beginning
  1558. of the current line."
  1559. (org-with-gensyms (marker)
  1560. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1561. 'org-hd-marker ,string)))
  1562. (with-current-buffer (marker-buffer ,marker)
  1563. (save-excursion
  1564. (goto-char ,marker)
  1565. ,@body)))))
  1566. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1567. (defun org-add-agenda-custom-command (entry)
  1568. "Replace or add a command in `org-agenda-custom-commands'.
  1569. This is mostly for hacking and trying a new command - once the command
  1570. works you probably want to add it to `org-agenda-custom-commands' for good."
  1571. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1572. (if ass
  1573. (setcdr ass (cdr entry))
  1574. (push entry org-agenda-custom-commands))))
  1575. ;;; Define the org-agenda-mode
  1576. (defvar org-agenda-mode-map (make-sparse-keymap)
  1577. "Keymap for `org-agenda-mode'.")
  1578. (if (fboundp 'defvaralias)
  1579. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1580. (defvar org-agenda-menu) ; defined later in this file.
  1581. (defvar org-agenda-restrict) ; defined later in this file.
  1582. (defvar org-agenda-follow-mode nil)
  1583. (defvar org-agenda-entry-text-mode nil)
  1584. (defvar org-agenda-clockreport-mode nil)
  1585. (defvar org-agenda-show-log nil)
  1586. (defvar org-agenda-redo-command nil)
  1587. (defvar org-agenda-query-string nil)
  1588. (defvar org-agenda-mode-hook nil
  1589. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1590. (defvar org-agenda-type nil)
  1591. (defvar org-agenda-force-single-file nil)
  1592. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1593. (defun org-agenda-mode ()
  1594. "Mode for time-sorted view on action items in Org-mode files.
  1595. The following commands are available:
  1596. \\{org-agenda-mode-map}"
  1597. (interactive)
  1598. (kill-all-local-variables)
  1599. (setq org-agenda-undo-list nil
  1600. org-agenda-pending-undo-list nil
  1601. org-agenda-bulk-marked-entries nil)
  1602. (setq major-mode 'org-agenda-mode)
  1603. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1604. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1605. (setq mode-name "Org-Agenda")
  1606. (use-local-map org-agenda-mode-map)
  1607. (easy-menu-add org-agenda-menu)
  1608. (if org-startup-truncated (setq truncate-lines t))
  1609. (org-set-local 'line-move-visual nil)
  1610. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1611. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1612. ;; Make sure properties are removed when copying text
  1613. (when (boundp 'buffer-substring-filters)
  1614. (org-set-local 'buffer-substring-filters
  1615. (cons (lambda (x)
  1616. (set-text-properties 0 (length x) nil x) x)
  1617. buffer-substring-filters)))
  1618. (unless org-agenda-keep-modes
  1619. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1620. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1621. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1622. org-agenda-show-log org-agenda-start-with-log-mode))
  1623. (easy-menu-change
  1624. '("Agenda") "Agenda Files"
  1625. (append
  1626. (list
  1627. (vector
  1628. (if (get 'org-agenda-files 'org-restrict)
  1629. "Restricted to single file"
  1630. "Edit File List")
  1631. '(org-edit-agenda-file-list)
  1632. (not (get 'org-agenda-files 'org-restrict)))
  1633. "--")
  1634. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1635. (org-agenda-set-mode-name)
  1636. (apply
  1637. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1638. (list 'org-agenda-mode-hook)))
  1639. (substitute-key-definition 'undo 'org-agenda-undo
  1640. org-agenda-mode-map global-map)
  1641. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1642. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1643. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1644. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1645. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1646. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1647. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1648. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1649. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1650. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1651. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1652. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1653. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1654. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1655. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1656. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1657. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1658. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1659. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1660. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1661. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1662. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1663. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1664. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1666. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1667. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1668. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1669. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1670. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1671. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1672. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1673. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1674. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1675. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1676. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1677. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1678. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1679. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1680. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1681. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1682. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1683. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1684. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1685. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1686. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1687. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1688. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1689. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1690. (while l (org-defkey org-agenda-mode-map
  1691. (int-to-string (pop l)) 'digit-argument)))
  1692. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1693. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1694. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1695. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1696. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1697. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1698. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1699. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1700. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1701. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1702. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1703. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1704. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1705. 'org-clock-modify-effort-estimate)
  1706. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1707. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1708. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1709. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1710. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1711. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1712. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1713. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1714. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1715. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1716. (substitute-key-definition 'next-line 'org-agenda-next-line
  1717. org-agenda-mode-map global-map)
  1718. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1719. org-agenda-mode-map global-map)
  1720. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1721. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1722. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1723. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1724. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1725. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1726. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1727. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1728. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1729. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1730. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1731. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1732. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1733. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1734. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1735. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1736. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1737. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1738. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1739. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1740. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1741. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1742. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1743. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1744. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1745. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1746. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1747. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1748. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1749. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1750. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1751. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1752. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1753. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1754. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1755. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1756. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1757. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1758. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1759. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1760. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1761. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1762. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1763. (when org-agenda-mouse-1-follows-link
  1764. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1765. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1766. '("Agenda"
  1767. ("Agenda Files")
  1768. "--"
  1769. ("Agenda Dates"
  1770. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1771. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1772. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1773. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1774. "--"
  1775. ("View"
  1776. ["Day View" org-agenda-day-view
  1777. :active (org-agenda-check-type nil 'agenda)
  1778. :style radio :selected (eq org-agenda-current-span 'day)
  1779. :keys "v d (or just d)"]
  1780. ["Week View" org-agenda-week-view
  1781. :active (org-agenda-check-type nil 'agenda)
  1782. :style radio :selected (eq org-agenda-current-span 'week)
  1783. :keys "v w (or just w)"]
  1784. ["Month View" org-agenda-month-view
  1785. :active (org-agenda-check-type nil 'agenda)
  1786. :style radio :selected (eq org-agenda-current-span 'month)
  1787. :keys "v m"]
  1788. ["Year View" org-agenda-year-view
  1789. :active (org-agenda-check-type nil 'agenda)
  1790. :style radio :selected (eq org-agenda-current-span 'year)
  1791. :keys "v y"]
  1792. "--"
  1793. ["Include Diary" org-agenda-toggle-diary
  1794. :style toggle :selected org-agenda-include-diary
  1795. :active (org-agenda-check-type nil 'agenda)]
  1796. ["Include Deadlines" org-agenda-toggle-deadlines
  1797. :style toggle :selected org-agenda-include-deadlines
  1798. :active (org-agenda-check-type nil 'agenda)]
  1799. ["Use Time Grid" org-agenda-toggle-time-grid
  1800. :style toggle :selected org-agenda-use-time-grid
  1801. :active (org-agenda-check-type nil 'agenda)]
  1802. "--"
  1803. ["Show clock report" org-agenda-clockreport-mode
  1804. :style toggle :selected org-agenda-clockreport-mode
  1805. :active (org-agenda-check-type nil 'agenda)]
  1806. ["Show some entry text" org-agenda-entry-text-mode
  1807. :style toggle :selected org-agenda-entry-text-mode
  1808. :active t]
  1809. "--"
  1810. ["Show Logbook entries" org-agenda-log-mode
  1811. :style toggle :selected org-agenda-show-log
  1812. :active (org-agenda-check-type nil 'agenda 'timeline)
  1813. :keys "v l (or just l)"]
  1814. ["Include archived trees" org-agenda-archives-mode
  1815. :style toggle :selected org-agenda-archives-mode :active t
  1816. :keys "v a"]
  1817. ["Include archive files" (org-agenda-archives-mode t)
  1818. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1819. :keys "v A"]
  1820. "--"
  1821. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1822. ["Write view to file" org-agenda-write t]
  1823. ["Rebuild buffer" org-agenda-redo t]
  1824. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1825. "--"
  1826. ["Show original entry" org-agenda-show t]
  1827. ["Go To (other window)" org-agenda-goto t]
  1828. ["Go To (this window)" org-agenda-switch-to t]
  1829. ["Follow Mode" org-agenda-follow-mode
  1830. :style toggle :selected org-agenda-follow-mode :active t]
  1831. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1832. "--"
  1833. ("TODO"
  1834. ["Cycle TODO" org-agenda-todo t]
  1835. ["Next TODO set" org-agenda-todo-nextset t]
  1836. ["Previous TODO set" org-agenda-todo-previousset t]
  1837. ["Add note" org-agenda-add-note t])
  1838. ("Archive/Refile/Delete"
  1839. ["Archive default" org-agenda-archive-default t]
  1840. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1841. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1842. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1843. ["Archive subtree" org-agenda-archive t]
  1844. "--"
  1845. ["Refile" org-agenda-refile t]
  1846. "--"
  1847. ["Delete subtree" org-agenda-kill t])
  1848. ("Bulk action"
  1849. ["Mark entry" org-agenda-bulk-mark t]
  1850. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1851. ["Unmark entry" org-agenda-bulk-unmark t]
  1852. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1853. ["Act on all marked" org-agenda-bulk-action t]
  1854. "--"
  1855. ("Tags and Properties"
  1856. ["Show all Tags" org-agenda-show-tags t]
  1857. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1858. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1859. "--"
  1860. ["Column View" org-columns t])
  1861. ("Deadline/Schedule"
  1862. ["Schedule" org-agenda-schedule t]
  1863. ["Set Deadline" org-agenda-deadline t]
  1864. "--"
  1865. ["Mark item" org-agenda-action :active t :keys "k m"]
  1866. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1867. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1868. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1869. "--"
  1870. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1871. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1872. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1873. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1874. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1875. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1876. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1877. ("Clock and Effort"
  1878. ["Clock in" org-agenda-clock-in t]
  1879. ["Clock out" org-agenda-clock-out t]
  1880. ["Clock cancel" org-agenda-clock-cancel t]
  1881. ["Goto running clock" org-clock-goto t]
  1882. "--"
  1883. ["Set Effort" org-agenda-set-effort t]
  1884. ["Change clocked effort" org-clock-modify-effort-estimate
  1885. (org-clock-is-active)])
  1886. ("Priority"
  1887. ["Set Priority" org-agenda-priority t]
  1888. ["Increase Priority" org-agenda-priority-up t]
  1889. ["Decrease Priority" org-agenda-priority-down t]
  1890. ["Show Priority" org-agenda-show-priority t])
  1891. ("Calendar/Diary"
  1892. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1893. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1894. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1895. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1896. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1897. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1898. "--"
  1899. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1900. "--"
  1901. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1902. "--"
  1903. ("MobileOrg"
  1904. ["Push Files and Views" org-mobile-push t]
  1905. ["Get Captured and Flagged" org-mobile-pull t]
  1906. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1907. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1908. "--"
  1909. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1910. "--"
  1911. ["Quit" org-agenda-quit t]
  1912. ["Exit and Release Buffers" org-agenda-exit t]
  1913. ))
  1914. ;;; Agenda undo
  1915. (defvar org-agenda-allow-remote-undo t
  1916. "Non-nil means allow remote undo from the agenda buffer.")
  1917. (defvar org-agenda-undo-list nil
  1918. "List of undoable operations in the agenda since last refresh.")
  1919. (defvar org-agenda-undo-has-started-in nil
  1920. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1921. (defvar org-agenda-pending-undo-list nil
  1922. "In a series of undo commands, this is the list of remaining undo items.")
  1923. (defun org-agenda-undo ()
  1924. "Undo a remote editing step in the agenda.
  1925. This undoes changes both in the agenda buffer and in the remote buffer
  1926. that have been changed along."
  1927. (interactive)
  1928. (or org-agenda-allow-remote-undo
  1929. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1930. (if (not (eq this-command last-command))
  1931. (setq org-agenda-undo-has-started-in nil
  1932. org-agenda-pending-undo-list org-agenda-undo-list))
  1933. (if (not org-agenda-pending-undo-list)
  1934. (error "No further undo information"))
  1935. (let* ((entry (pop org-agenda-pending-undo-list))
  1936. buf line cmd rembuf)
  1937. (setq cmd (pop entry) line (pop entry))
  1938. (setq rembuf (nth 2 entry))
  1939. (org-with-remote-undo rembuf
  1940. (while (bufferp (setq buf (pop entry)))
  1941. (if (pop entry)
  1942. (with-current-buffer buf
  1943. (let ((last-undo-buffer buf)
  1944. (inhibit-read-only t))
  1945. (unless (memq buf org-agenda-undo-has-started-in)
  1946. (push buf org-agenda-undo-has-started-in)
  1947. (make-local-variable 'pending-undo-list)
  1948. (undo-start))
  1949. (while (and pending-undo-list
  1950. (listp pending-undo-list)
  1951. (not (car pending-undo-list)))
  1952. (pop pending-undo-list))
  1953. (undo-more 1))))))
  1954. (org-goto-line line)
  1955. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1956. (defun org-verify-change-for-undo (l1 l2)
  1957. "Verify that a real change occurred between the undo lists L1 and L2."
  1958. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1959. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1960. (not (eq l1 l2)))
  1961. ;;; Agenda dispatch
  1962. (defvar org-agenda-restrict nil)
  1963. (defvar org-agenda-restrict-begin (make-marker))
  1964. (defvar org-agenda-restrict-end (make-marker))
  1965. (defvar org-agenda-last-dispatch-buffer nil)
  1966. (defvar org-agenda-overriding-restriction nil)
  1967. ;;;###autoload
  1968. (defun org-agenda (&optional arg keys restriction)
  1969. "Dispatch agenda commands to collect entries to the agenda buffer.
  1970. Prompts for a command to execute. Any prefix arg will be passed
  1971. on to the selected command. The default selections are:
  1972. a Call `org-agenda-list' to display the agenda for current day or week.
  1973. t Call `org-todo-list' to display the global todo list.
  1974. T Call `org-todo-list' to display the global todo list, select only
  1975. entries with a specific TODO keyword (the user gets a prompt).
  1976. m Call `org-tags-view' to display headlines with tags matching
  1977. a condition (the user is prompted for the condition).
  1978. M Like `m', but select only TODO entries, no ordinary headlines.
  1979. L Create a timeline for the current buffer.
  1980. e Export views to associated files.
  1981. s Search entries for keywords.
  1982. / Multi occur across all agenda files and also files listed
  1983. in `org-agenda-text-search-extra-files'.
  1984. < Restrict agenda commands to buffer, subtree, or region.
  1985. Press several times to get the desired effect.
  1986. > Remove a previous restriction.
  1987. # List \"stuck\" projects.
  1988. ! Configure what \"stuck\" means.
  1989. C Configure custom agenda commands.
  1990. More commands can be added by configuring the variable
  1991. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1992. searches can be pre-defined in this way.
  1993. If the current buffer is in Org-mode and visiting a file, you can also
  1994. first press `<' once to indicate that the agenda should be temporarily
  1995. \(until the next use of \\[org-agenda]) restricted to the current file.
  1996. Pressing `<' twice means to restrict to the current subtree or region
  1997. \(if active)."
  1998. (interactive "P")
  1999. (catch 'exit
  2000. (let* ((prefix-descriptions nil)
  2001. (org-agenda-window-setup (if (equal (buffer-name)
  2002. org-agenda-buffer-name)
  2003. 'current-window
  2004. org-agenda-window-setup))
  2005. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2006. (org-agenda-custom-commands
  2007. ;; normalize different versions
  2008. (delq nil
  2009. (mapcar
  2010. (lambda (x)
  2011. (cond ((stringp (cdr x))
  2012. (push x prefix-descriptions)
  2013. nil)
  2014. ((stringp (nth 1 x)) x)
  2015. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2016. (t (cons (car x) (cons "" (cdr x))))))
  2017. org-agenda-custom-commands)))
  2018. (buf (current-buffer))
  2019. (bfn (buffer-file-name (buffer-base-buffer)))
  2020. entry key type match lprops ans)
  2021. ;; Turn off restriction unless there is an overriding one,
  2022. (unless org-agenda-overriding-restriction
  2023. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2024. ;; There is a request to keep the file list in place
  2025. (put 'org-agenda-files 'org-restrict nil))
  2026. (setq org-agenda-restrict nil)
  2027. (move-marker org-agenda-restrict-begin nil)
  2028. (move-marker org-agenda-restrict-end nil))
  2029. ;; Delete old local properties
  2030. (put 'org-agenda-redo-command 'org-lprops nil)
  2031. ;; Delete previously set last-arguments
  2032. (put 'org-agenda-redo-command 'last-args nil)
  2033. ;; Remember where this call originated
  2034. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2035. (unless keys
  2036. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2037. keys (car ans)
  2038. restriction (cdr ans)))
  2039. ;; Establish the restriction, if any
  2040. (when (and (not org-agenda-overriding-restriction) restriction)
  2041. (put 'org-agenda-files 'org-restrict (list bfn))
  2042. (cond
  2043. ((eq restriction 'region)
  2044. (setq org-agenda-restrict t)
  2045. (move-marker org-agenda-restrict-begin (region-beginning))
  2046. (move-marker org-agenda-restrict-end (region-end)))
  2047. ((eq restriction 'subtree)
  2048. (save-excursion
  2049. (setq org-agenda-restrict t)
  2050. (org-back-to-heading t)
  2051. (move-marker org-agenda-restrict-begin (point))
  2052. (move-marker org-agenda-restrict-end
  2053. (progn (org-end-of-subtree t)))))))
  2054. ;; For example the todo list should not need it (but does...)
  2055. (cond
  2056. ((setq entry (assoc keys org-agenda-custom-commands))
  2057. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2058. (progn
  2059. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2060. lprops (nth 4 entry))
  2061. (put 'org-agenda-redo-command 'org-lprops lprops)
  2062. (cond
  2063. ((eq type 'agenda)
  2064. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2065. ((eq type 'alltodo)
  2066. (org-let lprops '(org-todo-list current-prefix-arg)))
  2067. ((eq type 'search)
  2068. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2069. ((eq type 'stuck)
  2070. (org-let lprops '(org-agenda-list-stuck-projects
  2071. current-prefix-arg)))
  2072. ((eq type 'tags)
  2073. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2074. ((eq type 'tags-todo)
  2075. (org-let lprops '(org-tags-view '(4) match)))
  2076. ((eq type 'todo)
  2077. (org-let lprops '(org-todo-list match)))
  2078. ((eq type 'tags-tree)
  2079. (org-check-for-org-mode)
  2080. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2081. ((eq type 'todo-tree)
  2082. (org-check-for-org-mode)
  2083. (org-let lprops
  2084. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2085. (regexp-quote match) "\\>"))))
  2086. ((eq type 'occur-tree)
  2087. (org-check-for-org-mode)
  2088. (org-let lprops '(org-occur match)))
  2089. ((functionp type)
  2090. (org-let lprops '(funcall type match)))
  2091. ((fboundp type)
  2092. (org-let lprops '(funcall type match)))
  2093. (t (error "Invalid custom agenda command type %s" type))))
  2094. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2095. ((equal keys "C")
  2096. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2097. (customize-variable 'org-agenda-custom-commands))
  2098. ((equal keys "a") (call-interactively 'org-agenda-list))
  2099. ((equal keys "s") (call-interactively 'org-search-view))
  2100. ((equal keys "t") (call-interactively 'org-todo-list))
  2101. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2102. ((equal keys "m") (call-interactively 'org-tags-view))
  2103. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2104. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2105. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2106. (org-add-hook
  2107. 'post-command-hook
  2108. (lambda ()
  2109. (unless (current-message)
  2110. (let* ((m (org-agenda-get-any-marker))
  2111. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2112. (when note
  2113. (message (concat
  2114. "FLAGGING-NOTE ([?] for more info): "
  2115. (org-add-props
  2116. (replace-regexp-in-string
  2117. "\\\\n" "//"
  2118. (copy-sequence note))
  2119. nil 'face 'org-warning)))))))
  2120. t t))
  2121. ((equal keys "L")
  2122. (unless (eq major-mode 'org-mode)
  2123. (error "This is not an Org-mode file"))
  2124. (unless restriction
  2125. (put 'org-agenda-files 'org-restrict (list bfn))
  2126. (org-call-with-arg 'org-timeline arg)))
  2127. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2128. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2129. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2130. (t (error "Invalid agenda key"))))))
  2131. (defun org-agenda-append-agenda ()
  2132. "Append another agenda view to the current one.
  2133. This function allows interactive building of block agendas.
  2134. Agenda views are separated by `org-agenda-block-separator'."
  2135. (interactive)
  2136. (unless (string= (buffer-name) org-agenda-buffer-name)
  2137. (error "Can only append from within agenda buffer"))
  2138. (let ((org-agenda-multi t))
  2139. (org-agenda)
  2140. (widen)))
  2141. (defun org-agenda-normalize-custom-commands (cmds)
  2142. (delq nil
  2143. (mapcar
  2144. (lambda (x)
  2145. (cond ((stringp (cdr x)) nil)
  2146. ((stringp (nth 1 x)) x)
  2147. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2148. (t (cons (car x) (cons "" (cdr x))))))
  2149. cmds)))
  2150. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2151. "The user interface for selecting an agenda command."
  2152. (catch 'exit
  2153. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2154. (restrict-ok (and bfn (eq major-mode 'org-mode)))
  2155. (region-p (org-region-active-p))
  2156. (custom org-agenda-custom-commands)
  2157. (selstring "")
  2158. restriction second-time
  2159. c entry key type match prefixes rmheader header-end custom1 desc
  2160. line lines left right n n1)
  2161. (save-window-excursion
  2162. (delete-other-windows)
  2163. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2164. (erase-buffer)
  2165. (insert (eval-when-compile
  2166. (let ((header
  2167. "
  2168. Press key for an agenda command: < Buffer, subtree/region restriction
  2169. -------------------------------- > Remove restriction
  2170. a Agenda for current week or day e Export agenda views
  2171. t List of all TODO entries T Entries with special TODO kwd
  2172. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2173. L Timeline for current buffer # List stuck projects (!=configure)
  2174. s Search for keywords C Configure custom agenda commands
  2175. / Multi-occur ? Find :FLAGGED: entries
  2176. ")
  2177. (start 0))
  2178. (while (string-match
  2179. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2180. header start)
  2181. (setq start (match-end 0))
  2182. (add-text-properties (match-beginning 2) (match-end 2)
  2183. '(face bold) header))
  2184. header)))
  2185. (setq header-end (move-marker (make-marker) (point)))
  2186. (while t
  2187. (setq custom1 custom)
  2188. (when (eq rmheader t)
  2189. (org-goto-line 1)
  2190. (re-search-forward ":" nil t)
  2191. (delete-region (match-end 0) (point-at-eol))
  2192. (forward-char 1)
  2193. (looking-at "-+")
  2194. (delete-region (match-end 0) (point-at-eol))
  2195. (move-marker header-end (match-end 0)))
  2196. (goto-char header-end)
  2197. (delete-region (point) (point-max))
  2198. ;; Produce all the lines that describe custom commands and prefixes
  2199. (setq lines nil)
  2200. (while (setq entry (pop custom1))
  2201. (setq key (car entry) desc (nth 1 entry)
  2202. type (nth 2 entry)
  2203. match (nth 3 entry))
  2204. (if (> (length key) 1)
  2205. (add-to-list 'prefixes (string-to-char key))
  2206. (setq line
  2207. (format
  2208. "%-4s%-14s"
  2209. (org-add-props (copy-sequence key)
  2210. '(face bold))
  2211. (cond
  2212. ((string-match "\\S-" desc) desc)
  2213. ((eq type 'agenda) "Agenda for current week or day")
  2214. ((eq type 'alltodo) "List of all TODO entries")
  2215. ((eq type 'search) "Word search")
  2216. ((eq type 'stuck) "List of stuck projects")
  2217. ((eq type 'todo) "TODO keyword")
  2218. ((eq type 'tags) "Tags query")
  2219. ((eq type 'tags-todo) "Tags (TODO)")
  2220. ((eq type 'tags-tree) "Tags tree")
  2221. ((eq type 'todo-tree) "TODO kwd tree")
  2222. ((eq type 'occur-tree) "Occur tree")
  2223. ((functionp type) (if (symbolp type)
  2224. (symbol-name type)
  2225. "Lambda expression"))
  2226. (t "???"))))
  2227. (if org-agenda-menu-show-matcher
  2228. (setq line
  2229. (concat line ": "
  2230. (cond
  2231. ((stringp match)
  2232. (setq match (copy-sequence match))
  2233. (org-add-props match nil 'face 'org-warning))
  2234. (match
  2235. (format "set of %d commands" (length match)))
  2236. (t ""))))
  2237. (if (org-string-nw-p match)
  2238. (add-text-properties
  2239. 0 (length line) (list 'help-echo
  2240. (concat "Matcher: "match)) line)))
  2241. (push line lines)))
  2242. (setq lines (nreverse lines))
  2243. (when prefixes
  2244. (mapc (lambda (x)
  2245. (push
  2246. (format "%s %s"
  2247. (org-add-props (char-to-string x)
  2248. nil 'face 'bold)
  2249. (or (cdr (assoc (concat selstring
  2250. (char-to-string x))
  2251. prefix-descriptions))
  2252. "Prefix key"))
  2253. lines))
  2254. prefixes))
  2255. ;; Check if we should display in two columns
  2256. (if org-agenda-menu-two-column
  2257. (progn
  2258. (setq n (length lines)
  2259. n1 (+ (/ n 2) (mod n 2))
  2260. right (nthcdr n1 lines)
  2261. left (copy-sequence lines))
  2262. (setcdr (nthcdr (1- n1) left) nil))
  2263. (setq left lines right nil))
  2264. (while left
  2265. (insert "\n" (pop left))
  2266. (when right
  2267. (if (< (current-column) 40)
  2268. (move-to-column 40 t)
  2269. (insert " "))
  2270. (insert (pop right))))
  2271. ;; Make the window the right size
  2272. (goto-char (point-min))
  2273. (if second-time
  2274. (if (not (pos-visible-in-window-p (point-max)))
  2275. (org-fit-window-to-buffer))
  2276. (setq second-time t)
  2277. (org-fit-window-to-buffer))
  2278. ;; Ask for selection
  2279. (message "Press key for agenda command%s:"
  2280. (if (or restrict-ok org-agenda-overriding-restriction)
  2281. (if org-agenda-overriding-restriction
  2282. " (restriction lock active)"
  2283. (if restriction
  2284. (format " (restricted to %s)" restriction)
  2285. " (unrestricted)"))
  2286. ""))
  2287. (setq c (read-char-exclusive))
  2288. (message "")
  2289. (cond
  2290. ((assoc (char-to-string c) custom)
  2291. (setq selstring (concat selstring (char-to-string c)))
  2292. (throw 'exit (cons selstring restriction)))
  2293. ((memq c prefixes)
  2294. (setq selstring (concat selstring (char-to-string c))
  2295. prefixes nil
  2296. rmheader (or rmheader t)
  2297. custom (delq nil (mapcar
  2298. (lambda (x)
  2299. (if (or (= (length (car x)) 1)
  2300. (/= (string-to-char (car x)) c))
  2301. nil
  2302. (cons (substring (car x) 1) (cdr x))))
  2303. custom))))
  2304. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2305. (message "Restriction is only possible in Org-mode buffers")
  2306. (ding) (sit-for 1))
  2307. ((eq c ?1)
  2308. (org-agenda-remove-restriction-lock 'noupdate)
  2309. (setq restriction 'buffer))
  2310. ((eq c ?0)
  2311. (org-agenda-remove-restriction-lock 'noupdate)
  2312. (setq restriction (if region-p 'region 'subtree)))
  2313. ((eq c ?<)
  2314. (org-agenda-remove-restriction-lock 'noupdate)
  2315. (setq restriction
  2316. (cond
  2317. ((eq restriction 'buffer)
  2318. (if region-p 'region 'subtree))
  2319. ((memq restriction '(subtree region))
  2320. nil)
  2321. (t 'buffer))))
  2322. ((eq c ?>)
  2323. (org-agenda-remove-restriction-lock 'noupdate)
  2324. (setq restriction nil))
  2325. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2326. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2327. ((and (> (length selstring) 0) (eq c ?\d))
  2328. (delete-window)
  2329. (org-agenda-get-restriction-and-command prefix-descriptions))
  2330. ((equal c ?q) (error "Abort"))
  2331. (t (error "Invalid key %c" c))))))))
  2332. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2333. (defvar org-agenda-last-arguments nil
  2334. "The arguments of the previous call to `org-agenda'.")
  2335. (defun org-agenda-run-series (name series)
  2336. (org-let (nth 1 series) '(org-prepare-agenda name))
  2337. (let* ((org-agenda-multi t)
  2338. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2339. (org-agenda-overriding-arguments
  2340. (or org-agenda-overriding-arguments
  2341. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2342. (get 'org-agenda-redo-command 'last-args))))
  2343. (cmds (car series))
  2344. (gprops (nth 1 series))
  2345. match ;; The byte compiler incorrectly complains about this. Keep it!
  2346. cmd type lprops)
  2347. (while (setq cmd (pop cmds))
  2348. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2349. (cond
  2350. ((eq type 'agenda)
  2351. (org-let2 gprops lprops
  2352. '(call-interactively 'org-agenda-list)))
  2353. ((eq type 'alltodo)
  2354. (org-let2 gprops lprops
  2355. '(call-interactively 'org-todo-list)))
  2356. ((eq type 'search)
  2357. (org-let2 gprops lprops
  2358. '(org-search-view current-prefix-arg match nil)))
  2359. ((eq type 'stuck)
  2360. (org-let2 gprops lprops
  2361. '(call-interactively 'org-agenda-list-stuck-projects)))
  2362. ((eq type 'tags)
  2363. (org-let2 gprops lprops
  2364. '(org-tags-view current-prefix-arg match)))
  2365. ((eq type 'tags-todo)
  2366. (org-let2 gprops lprops
  2367. '(org-tags-view '(4) match)))
  2368. ((eq type 'todo)
  2369. (org-let2 gprops lprops
  2370. '(org-todo-list match)))
  2371. ((fboundp type)
  2372. (org-let2 gprops lprops
  2373. '(funcall type match)))
  2374. (t (error "Invalid type in command series"))))
  2375. (widen)
  2376. (setq org-agenda-redo-command redo)
  2377. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2378. (goto-char (point-min)))
  2379. (org-fit-agenda-window)
  2380. (org-let (nth 1 series) '(org-finalize-agenda)))
  2381. ;;;###autoload
  2382. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2383. "Run an agenda command in batch mode and send the result to STDOUT.
  2384. If CMD-KEY is a string of length 1, it is used as a key in
  2385. `org-agenda-custom-commands' and triggers this command. If it is a
  2386. longer string it is used as a tags/todo match string.
  2387. Parameters are alternating variable names and values that will be bound
  2388. before running the agenda command."
  2389. (org-eval-in-environment (org-make-parameter-alist parameters)
  2390. (if (> (length cmd-key) 2)
  2391. (org-tags-view nil cmd-key)
  2392. (org-agenda nil cmd-key)))
  2393. (set-buffer org-agenda-buffer-name)
  2394. (princ (buffer-string)))
  2395. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2396. (defvar org-agenda-info nil)
  2397. ;;;###autoload
  2398. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2399. "Run an agenda command in batch mode and send the result to STDOUT.
  2400. If CMD-KEY is a string of length 1, it is used as a key in
  2401. `org-agenda-custom-commands' and triggers this command. If it is a
  2402. longer string it is used as a tags/todo match string.
  2403. Parameters are alternating variable names and values that will be bound
  2404. before running the agenda command.
  2405. The output gives a line for each selected agenda item. Each
  2406. item is a list of comma-separated values, like this:
  2407. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2408. category The category of the item
  2409. head The headline, without TODO kwd, TAGS and PRIORITY
  2410. type The type of the agenda entry, can be
  2411. todo selected in TODO match
  2412. tagsmatch selected in tags match
  2413. diary imported from diary
  2414. deadline a deadline on given date
  2415. scheduled scheduled on given date
  2416. timestamp entry has timestamp on given date
  2417. closed entry was closed on given date
  2418. upcoming-deadline warning about deadline
  2419. past-scheduled forwarded scheduled item
  2420. block entry has date block including g. date
  2421. todo The todo keyword, if any
  2422. tags All tags including inherited ones, separated by colons
  2423. date The relevant date, like 2007-2-14
  2424. time The time, like 15:00-16:50
  2425. extra Sting with extra planning info
  2426. priority-l The priority letter if any was given
  2427. priority-n The computed numerical priority
  2428. agenda-day The day in the agenda where this is listed"
  2429. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2430. (org-make-parameter-alist parameters))
  2431. (if (> (length cmd-key) 2)
  2432. (org-tags-view nil cmd-key)
  2433. (org-agenda nil cmd-key)))
  2434. (set-buffer org-agenda-buffer-name)
  2435. (let* ((lines (org-split-string (buffer-string) "\n"))
  2436. line)
  2437. (while (setq line (pop lines))
  2438. (catch 'next
  2439. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2440. (setq org-agenda-info
  2441. (org-fix-agenda-info (text-properties-at 0 line)))
  2442. (princ
  2443. (mapconcat 'org-agenda-export-csv-mapper
  2444. '(org-category txt type todo tags date time extra
  2445. priority-letter priority agenda-day)
  2446. ","))
  2447. (princ "\n")))))
  2448. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2449. (defun org-fix-agenda-info (props)
  2450. "Make sure all properties on an agenda item have a canonical form.
  2451. This ensures the export commands can easily use it."
  2452. (let (tmp re)
  2453. (when (setq tmp (plist-get props 'tags))
  2454. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2455. (when (setq tmp (plist-get props 'date))
  2456. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2457. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2458. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2459. (setq tmp (calendar-date-string tmp)))
  2460. (setq props (plist-put props 'date tmp)))
  2461. (when (setq tmp (plist-get props 'day))
  2462. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2463. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2464. (setq tmp (calendar-date-string tmp)))
  2465. (setq props (plist-put props 'day tmp))
  2466. (setq props (plist-put props 'agenda-day tmp)))
  2467. (when (setq tmp (plist-get props 'txt))
  2468. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2469. (plist-put props 'priority-letter (match-string 1 tmp))
  2470. (setq tmp (replace-match "" t t tmp)))
  2471. (when (and (setq re (plist-get props 'org-todo-regexp))
  2472. (setq re (concat "\\`\\.*" re " ?"))
  2473. (string-match re tmp))
  2474. (plist-put props 'todo (match-string 1 tmp))
  2475. (setq tmp (replace-match "" t t tmp)))
  2476. (plist-put props 'txt tmp)))
  2477. props)
  2478. (defun org-agenda-export-csv-mapper (prop)
  2479. (let ((res (plist-get org-agenda-info prop)))
  2480. (setq res
  2481. (cond
  2482. ((not res) "")
  2483. ((stringp res) res)
  2484. (t (prin1-to-string res))))
  2485. (while (string-match "," res)
  2486. (setq res (replace-match ";" t t res)))
  2487. (org-trim res)))
  2488. ;;;###autoload
  2489. (defun org-store-agenda-views (&rest parameters)
  2490. (interactive)
  2491. (eval (list 'org-batch-store-agenda-views)))
  2492. ;;;###autoload
  2493. (defmacro org-batch-store-agenda-views (&rest parameters)
  2494. "Run all custom agenda commands that have a file argument."
  2495. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2496. (pop-up-frames nil)
  2497. (dir default-directory)
  2498. (pars (org-make-parameter-alist parameters))
  2499. cmd thiscmdkey files opts cmd-or-set)
  2500. (save-window-excursion
  2501. (while cmds
  2502. (setq cmd (pop cmds)
  2503. thiscmdkey (car cmd)
  2504. cmd-or-set (nth 2 cmd)
  2505. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2506. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2507. (if (stringp files) (setq files (list files)))
  2508. (when files
  2509. (org-eval-in-environment (append org-agenda-exporter-settings
  2510. opts pars)
  2511. (org-agenda nil thiscmdkey))
  2512. (set-buffer org-agenda-buffer-name)
  2513. (while files
  2514. (org-eval-in-environment (append org-agenda-exporter-settings
  2515. opts pars)
  2516. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2517. (and (get-buffer org-agenda-buffer-name)
  2518. (kill-buffer org-agenda-buffer-name)))))))
  2519. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2520. (defun org-agenda-mark-header-line (pos)
  2521. "Mark the line at POS as an agenda structure header."
  2522. (save-excursion
  2523. (goto-char pos)
  2524. (put-text-property (point-at-bol) (point-at-eol)
  2525. 'org-agenda-structural-header t)
  2526. (when org-agenda-title-append
  2527. (put-text-property (point-at-bol) (point-at-eol)
  2528. 'org-agenda-title-append org-agenda-title-append))))
  2529. (defvar org-mobile-creating-agendas)
  2530. (defvar org-agenda-write-buffer-name "Agenda View")
  2531. (defun org-agenda-write (file &optional open nosettings)
  2532. "Write the current buffer (an agenda view) as a file.
  2533. Depending on the extension of the file name, plain text (.txt),
  2534. HTML (.html or .htm) or Postscript (.ps) is produced.
  2535. If the extension is .ics, run icalendar export over all files used
  2536. to construct the agenda and limit the export to entries listed in the
  2537. agenda now.
  2538. With prefix argument OPEN, open the new file immediately.
  2539. If NOSETTINGS is given, do not scope the settings of
  2540. `org-agenda-exporter-settings' into the export commands. This is used when
  2541. the settings have already been scoped and we do not wish to overrule other,
  2542. higher priority settings."
  2543. (interactive "FWrite agenda to file: \nP")
  2544. (if (not (file-writable-p file))
  2545. (error "Cannot write agenda to file %s" file))
  2546. (org-let (if nosettings nil org-agenda-exporter-settings)
  2547. '(save-excursion
  2548. (save-window-excursion
  2549. (org-agenda-mark-filtered-text)
  2550. (let ((bs (copy-sequence (buffer-string))) beg)
  2551. (org-agenda-unmark-filtered-text)
  2552. (with-temp-buffer
  2553. (rename-buffer org-agenda-write-buffer-name t)
  2554. (set-buffer-modified-p nil)
  2555. (insert bs)
  2556. (org-agenda-remove-marked-text 'org-filtered)
  2557. (while (setq beg (text-property-any (point-min) (point-max)
  2558. 'org-filtered t))
  2559. (delete-region
  2560. beg (or (next-single-property-change beg 'org-filtered)
  2561. (point-max))))
  2562. (run-hooks 'org-agenda-before-write-hook)
  2563. (cond
  2564. ((org-bound-and-true-p org-mobile-creating-agendas)
  2565. (org-mobile-write-agenda-for-mobile file))
  2566. ((string-match "\\.html?\\'" file)
  2567. (require 'htmlize)
  2568. (set-buffer (htmlize-buffer (current-buffer)))
  2569. (when (and org-agenda-export-html-style
  2570. (string-match "<style>" org-agenda-export-html-style))
  2571. ;; replace <style> section with org-agenda-export-html-style
  2572. (goto-char (point-min))
  2573. (kill-region (- (search-forward "<style") 6)
  2574. (search-forward "</style>"))
  2575. (insert org-agenda-export-html-style))
  2576. (write-file file)
  2577. (kill-buffer (current-buffer))
  2578. (message "HTML written to %s" file))
  2579. ((string-match "\\.ps\\'" file)
  2580. (require 'ps-print)
  2581. (ps-print-buffer-with-faces file)
  2582. (message "Postscript written to %s" file))
  2583. ((string-match "\\.pdf\\'" file)
  2584. (require 'ps-print)
  2585. (ps-print-buffer-with-faces
  2586. (concat (file-name-sans-extension file) ".ps"))
  2587. (call-process "ps2pdf" nil nil nil
  2588. (expand-file-name
  2589. (concat (file-name-sans-extension file) ".ps"))
  2590. (expand-file-name file))
  2591. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2592. (message "PDF written to %s" file))
  2593. ((string-match "\\.ics\\'" file)
  2594. (require 'org-icalendar)
  2595. (let ((org-agenda-marker-table
  2596. (org-create-marker-find-array
  2597. (org-agenda-collect-markers)))
  2598. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2599. (org-combined-agenda-icalendar-file file))
  2600. (apply 'org-export-icalendar 'combine
  2601. (org-agenda-files nil 'ifmode))))
  2602. (t
  2603. (let ((bs (buffer-string)))
  2604. (find-file file)
  2605. (erase-buffer)
  2606. (insert bs)
  2607. (save-buffer 0)
  2608. (kill-buffer (current-buffer))
  2609. (message "Plain text written to %s" file))))))))
  2610. (set-buffer org-agenda-buffer-name))
  2611. (when open (org-open-file file)))
  2612. (defvar org-agenda-tag-filter-overlays nil)
  2613. (defvar org-agenda-cat-filter-overlays nil)
  2614. (defun org-agenda-mark-filtered-text ()
  2615. "Mark all text hidden by filtering with a text property."
  2616. (let ((inhibit-read-only t))
  2617. (mapc
  2618. (lambda (o)
  2619. (when (equal (overlay-buffer o) (current-buffer))
  2620. (put-text-property
  2621. (overlay-start o) (overlay-end o)
  2622. 'org-filtered t)))
  2623. (append org-agenda-tag-filter-overlays
  2624. org-agenda-cat-filter-overlays))))
  2625. (defun org-agenda-unmark-filtered-text ()
  2626. "Remove the filtering text property."
  2627. (let ((inhibit-read-only t))
  2628. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2629. (defun org-agenda-remove-marked-text (property &optional value)
  2630. "Delete all text marked with VALUE of PROPERTY.
  2631. VALUE defaults to t."
  2632. (let (beg)
  2633. (setq value (or value t))
  2634. (while (setq beg (text-property-any (point-min) (point-max)
  2635. property value))
  2636. (delete-region
  2637. beg (or (next-single-property-change beg 'org-filtered)
  2638. (point-max))))))
  2639. (defun org-agenda-add-entry-text ()
  2640. "Add entry text to agenda lines.
  2641. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2642. entry text following headings shown in the agenda.
  2643. Drawers will be excluded, also the line with scheduling/deadline info."
  2644. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2645. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2646. (let (m txt)
  2647. (goto-char (point-min))
  2648. (while (not (eobp))
  2649. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2650. (beginning-of-line 2)
  2651. (setq txt (org-agenda-get-some-entry-text
  2652. m org-agenda-add-entry-text-maxlines " > "))
  2653. (end-of-line 1)
  2654. (if (string-match "\\S-" txt)
  2655. (insert "\n" txt)
  2656. (or (eobp) (forward-char 1))))))))
  2657. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2658. &rest keep)
  2659. "Extract entry text from MARKER, at most N-LINES lines.
  2660. This will ignore drawers etc, just get the text.
  2661. If INDENT is given, prefix every line with this string. If KEEP is
  2662. given, it is a list of symbols, defining stuff that should not be
  2663. removed from the entry content. Currently only `planning' is allowed here."
  2664. (let (txt drawer-re kwd-time-re ind)
  2665. (save-excursion
  2666. (with-current-buffer (marker-buffer marker)
  2667. (if (not (eq major-mode 'org-mode))
  2668. (setq txt "")
  2669. (save-excursion
  2670. (save-restriction
  2671. (widen)
  2672. (goto-char marker)
  2673. (end-of-line 1)
  2674. (setq txt (buffer-substring
  2675. (min (1+ (point)) (point-max))
  2676. (progn (outline-next-heading) (point)))
  2677. drawer-re org-drawer-regexp
  2678. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2679. ".*\n?"))
  2680. (with-temp-buffer
  2681. (insert txt)
  2682. (when org-agenda-add-entry-text-descriptive-links
  2683. (goto-char (point-min))
  2684. (while (org-activate-bracket-links (point-max))
  2685. (add-text-properties (match-beginning 0) (match-end 0)
  2686. '(face org-link))))
  2687. (goto-char (point-min))
  2688. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2689. (set-text-properties (match-beginning 0) (match-end 0)
  2690. nil))
  2691. (goto-char (point-min))
  2692. (while (re-search-forward drawer-re nil t)
  2693. (delete-region
  2694. (match-beginning 0)
  2695. (progn (re-search-forward
  2696. "^[ \t]*:END:.*\n?" nil 'move)
  2697. (point))))
  2698. (unless (member 'planning keep)
  2699. (goto-char (point-min))
  2700. (while (re-search-forward kwd-time-re nil t)
  2701. (replace-match "")))
  2702. (goto-char (point-min))
  2703. (when org-agenda-entry-text-exclude-regexps
  2704. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2705. (while (setq re (pop re-list))
  2706. (goto-char (point-min))
  2707. (while (re-search-forward re nil t)
  2708. (replace-match "")))))
  2709. (goto-char (point-max))
  2710. (skip-chars-backward " \t\n")
  2711. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2712. ;; find and remove min common indentation
  2713. (goto-char (point-min))
  2714. (untabify (point-min) (point-max))
  2715. (setq ind (org-get-indentation))
  2716. (while (not (eobp))
  2717. (unless (looking-at "[ \t]*$")
  2718. (setq ind (min ind (org-get-indentation))))
  2719. (beginning-of-line 2))
  2720. (goto-char (point-min))
  2721. (while (not (eobp))
  2722. (unless (looking-at "[ \t]*$")
  2723. (move-to-column ind)
  2724. (delete-region (point-at-bol) (point)))
  2725. (beginning-of-line 2))
  2726. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2727. (goto-char (point-min))
  2728. (when indent
  2729. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2730. (replace-match indent t t)))
  2731. (goto-char (point-min))
  2732. (while (looking-at "[ \t]*\n") (replace-match ""))
  2733. (goto-char (point-max))
  2734. (when (> (org-current-line)
  2735. n-lines)
  2736. (org-goto-line (1+ n-lines))
  2737. (backward-char 1))
  2738. (setq txt (buffer-substring (point-min) (point)))))))))
  2739. txt))
  2740. (defun org-agenda-collect-markers ()
  2741. "Collect the markers pointing to entries in the agenda buffer."
  2742. (let (m markers)
  2743. (save-excursion
  2744. (goto-char (point-min))
  2745. (while (not (eobp))
  2746. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2747. (org-get-at-bol 'org-marker)))
  2748. (push m markers))
  2749. (beginning-of-line 2)))
  2750. (nreverse markers)))
  2751. (defun org-create-marker-find-array (marker-list)
  2752. "Create a alist of files names with all marker positions in that file."
  2753. (let (f tbl m a p)
  2754. (while (setq m (pop marker-list))
  2755. (setq p (marker-position m)
  2756. f (buffer-file-name (or (buffer-base-buffer
  2757. (marker-buffer m))
  2758. (marker-buffer m))))
  2759. (if (setq a (assoc f tbl))
  2760. (push (marker-position m) (cdr a))
  2761. (push (list f p) tbl)))
  2762. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2763. tbl)))
  2764. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2765. (defun org-check-agenda-marker-table ()
  2766. "Check of the current entry is on the marker list."
  2767. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2768. a)
  2769. (and (setq a (assoc file org-agenda-marker-table))
  2770. (save-match-data
  2771. (save-excursion
  2772. (org-back-to-heading t)
  2773. (member (point) (cdr a)))))))
  2774. (defun org-check-for-org-mode ()
  2775. "Make sure current buffer is in org-mode. Error if not."
  2776. (or (eq major-mode 'org-mode)
  2777. (error "Cannot execute org-mode agenda command on buffer in %s"
  2778. major-mode)))
  2779. (defun org-fit-agenda-window ()
  2780. "Fit the window to the buffer size."
  2781. (and (memq org-agenda-window-setup '(reorganize-frame))
  2782. (fboundp 'fit-window-to-buffer)
  2783. (org-fit-window-to-buffer
  2784. nil
  2785. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2786. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2787. ;;; Agenda prepare and finalize
  2788. (defvar org-agenda-multi nil) ; dynamically scoped
  2789. (defvar org-agenda-buffer-name "*Org Agenda*")
  2790. (defvar org-pre-agenda-window-conf nil)
  2791. (defvar org-agenda-columns-active nil)
  2792. (defvar org-agenda-name nil)
  2793. (defvar org-agenda-tag-filter nil)
  2794. (defvar org-agenda-category-filter nil)
  2795. (defvar org-agenda-tag-filter-while-redo nil)
  2796. (defvar org-agenda-tag-filter-preset nil
  2797. "A preset of the tags filter used for secondary agenda filtering.
  2798. This must be a list of strings, each string must be a single tag preceded
  2799. by \"+\" or \"-\".
  2800. This variable should not be set directly, but agenda custom commands can
  2801. bind it in the options section. The preset filter is a global property of
  2802. the entire agenda view. In a block agenda, it will not work reliably to
  2803. define a filter for one of the individual blocks. You need to set it in
  2804. the global options and expect it to be applied to the entire view.")
  2805. (defvar org-agenda-category-filter-preset nil
  2806. "A preset of the category filter used for secondary agenda filtering.
  2807. This must be a list of strings, each string must be a single category
  2808. preceded by \"+\" or \"-\".
  2809. This variable should not be set directly, but agenda custom commands can
  2810. bind it in the options section. The preset filter is a global property of
  2811. the entire agenda view. In a block agenda, it will not work reliably to
  2812. define a filter for one of the individual blocks. You need to set it in
  2813. the global options and expect it to be applied to the entire view.")
  2814. (defun org-prepare-agenda (&optional name)
  2815. (setq org-todo-keywords-for-agenda nil)
  2816. (setq org-done-keywords-for-agenda nil)
  2817. (setq org-drawers-for-agenda nil)
  2818. (unless org-agenda-persistent-filter
  2819. (setq org-agenda-tag-filter nil
  2820. org-agenda-category-filter nil))
  2821. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2822. (put 'org-agenda-category-filter :preset-filter org-agenda-category-filter-preset)
  2823. (if org-agenda-multi
  2824. (progn
  2825. (setq buffer-read-only nil)
  2826. (goto-char (point-max))
  2827. (unless (or (bobp) org-agenda-compact-blocks
  2828. (not org-agenda-block-separator))
  2829. (insert "\n"
  2830. (if (stringp org-agenda-block-separator)
  2831. org-agenda-block-separator
  2832. (make-string (window-width) org-agenda-block-separator))
  2833. "\n"))
  2834. (narrow-to-region (point) (point-max)))
  2835. (org-agenda-reset-markers)
  2836. (setq org-agenda-contributing-files nil)
  2837. (setq org-agenda-columns-active nil)
  2838. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2839. (setq org-todo-keywords-for-agenda
  2840. (org-uniquify org-todo-keywords-for-agenda))
  2841. (setq org-done-keywords-for-agenda
  2842. (org-uniquify org-done-keywords-for-agenda))
  2843. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2844. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2845. (awin (get-buffer-window abuf)))
  2846. (cond
  2847. ((equal (current-buffer) abuf) nil)
  2848. (awin (select-window awin))
  2849. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2850. ((equal org-agenda-window-setup 'current-window)
  2851. (org-pop-to-buffer-same-window abuf))
  2852. ((equal org-agenda-window-setup 'other-window)
  2853. (org-switch-to-buffer-other-window abuf))
  2854. ((equal org-agenda-window-setup 'other-frame)
  2855. (switch-to-buffer-other-frame abuf))
  2856. ((equal org-agenda-window-setup 'reorganize-frame)
  2857. (delete-other-windows)
  2858. (org-switch-to-buffer-other-window abuf)))
  2859. ;; additional test in case agenda is invoked from within agenda
  2860. ;; buffer via elisp link
  2861. (unless (equal (current-buffer) abuf)
  2862. (org-pop-to-buffer-same-window abuf)))
  2863. (setq buffer-read-only nil)
  2864. (let ((inhibit-read-only t)) (erase-buffer))
  2865. (org-agenda-mode)
  2866. (and name (not org-agenda-name)
  2867. (org-set-local 'org-agenda-name name)))
  2868. (setq buffer-read-only nil))
  2869. (defun org-finalize-agenda ()
  2870. "Finishing touch for the agenda buffer, called just before displaying it."
  2871. (unless org-agenda-multi
  2872. (save-excursion
  2873. (let ((inhibit-read-only t))
  2874. (goto-char (point-min))
  2875. (while (org-activate-bracket-links (point-max))
  2876. (add-text-properties (match-beginning 0) (match-end 0)
  2877. '(face org-link)))
  2878. (org-agenda-align-tags)
  2879. (unless org-agenda-with-colors
  2880. (remove-text-properties (point-min) (point-max) '(face nil))))
  2881. (if (and (boundp 'org-agenda-overriding-columns-format)
  2882. org-agenda-overriding-columns-format)
  2883. (org-set-local 'org-agenda-overriding-columns-format
  2884. org-agenda-overriding-columns-format))
  2885. (if (and (boundp 'org-agenda-view-columns-initially)
  2886. org-agenda-view-columns-initially)
  2887. (org-agenda-columns))
  2888. (when org-agenda-fontify-priorities
  2889. (org-agenda-fontify-priorities))
  2890. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2891. (org-agenda-dim-blocked-tasks))
  2892. (org-agenda-mark-clocking-task)
  2893. (when org-agenda-entry-text-mode
  2894. (org-agenda-entry-text-hide)
  2895. (org-agenda-entry-text-show))
  2896. (if (functionp 'org-habit-insert-consistency-graphs)
  2897. (org-habit-insert-consistency-graphs))
  2898. (run-hooks 'org-finalize-agenda-hook)
  2899. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2900. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  2901. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  2902. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  2903. (org-agenda-filter-apply org-agenda-category-filter 'category))
  2904. )))
  2905. (defun org-agenda-mark-clocking-task ()
  2906. "Mark the current clock entry in the agenda if it is present."
  2907. (mapc (lambda (o)
  2908. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2909. (delete-overlay o)))
  2910. (overlays-in (point-min) (point-max)))
  2911. (when (marker-buffer org-clock-hd-marker)
  2912. (save-excursion
  2913. (goto-char (point-min))
  2914. (let (s ov)
  2915. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2916. (goto-char s)
  2917. (when (equal (org-get-at-bol 'org-hd-marker)
  2918. org-clock-hd-marker)
  2919. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2920. (overlay-put ov 'type 'org-agenda-clocking)
  2921. (overlay-put ov 'face 'org-agenda-clocking)
  2922. (overlay-put ov 'help-echo
  2923. "The clock is running in this item")))))))
  2924. (defun org-agenda-fontify-priorities ()
  2925. "Make highest priority lines bold, and lowest italic."
  2926. (interactive)
  2927. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2928. (delete-overlay o)))
  2929. (overlays-in (point-min) (point-max)))
  2930. (save-excursion
  2931. (let ((inhibit-read-only t)
  2932. b e p ov h l)
  2933. (goto-char (point-min))
  2934. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2935. (setq h (or (get-char-property (point) 'org-highest-priority)
  2936. org-highest-priority)
  2937. l (or (get-char-property (point) 'org-lowest-priority)
  2938. org-lowest-priority)
  2939. p (string-to-char (match-string 1))
  2940. b (match-beginning 0)
  2941. e (if (eq org-agenda-fontify-priorities 'cookies)
  2942. (match-end 0)
  2943. (point-at-eol))
  2944. ov (make-overlay b e))
  2945. (overlay-put
  2946. ov 'face
  2947. (cond ((org-face-from-face-or-color
  2948. 'priority nil
  2949. (cdr (assoc p org-priority-faces))))
  2950. ((and (listp org-agenda-fontify-priorities)
  2951. (org-face-from-face-or-color
  2952. 'priority nil
  2953. (cdr (assoc p org-agenda-fontify-priorities)))))
  2954. ((equal p l) 'italic)
  2955. ((equal p h) 'bold)))
  2956. (overlay-put ov 'org-type 'org-priority)))))
  2957. (defun org-agenda-dim-blocked-tasks ()
  2958. "Dim currently blocked TODO's in the agenda display."
  2959. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2960. (delete-overlay o)))
  2961. (overlays-in (point-min) (point-max)))
  2962. (save-excursion
  2963. (let ((inhibit-read-only t)
  2964. (org-depend-tag-blocked nil)
  2965. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2966. org-blocked-by-checkboxes
  2967. invis1 b e p ov h l)
  2968. (goto-char (point-min))
  2969. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2970. (and pos (goto-char (1+ pos))))
  2971. (setq org-blocked-by-checkboxes nil invis1 invis)
  2972. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2973. (when (and marker
  2974. (with-current-buffer (marker-buffer marker)
  2975. (save-excursion (goto-char marker)
  2976. (org-entry-blocked-p))))
  2977. (if org-blocked-by-checkboxes (setq invis1 nil))
  2978. (setq b (if invis1
  2979. (max (point-min) (1- (point-at-bol)))
  2980. (point-at-bol))
  2981. e (point-at-eol)
  2982. ov (make-overlay b e))
  2983. (if invis1
  2984. (overlay-put ov 'invisible t)
  2985. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2986. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2987. (defvar org-agenda-skip-function nil
  2988. "Function to be called at each match during agenda construction.
  2989. If this function returns nil, the current match should not be skipped.
  2990. Otherwise, the function must return a position from where the search
  2991. should be continued.
  2992. This may also be a Lisp form, it will be evaluated.
  2993. Never set this variable using `setq' or so, because then it will apply
  2994. to all future agenda commands. If you do want a global skipping condition,
  2995. use the option `org-agenda-skip-function-global' instead.
  2996. The correct usage for `org-agenda-skip-function' is to bind it with
  2997. `let' to scope it dynamically into the agenda-constructing command.
  2998. A good way to set it is through options in `org-agenda-custom-commands'.")
  2999. (defun org-agenda-skip ()
  3000. "Throw to `:skip' in places that should be skipped.
  3001. Also moves point to the end of the skipped region, so that search can
  3002. continue from there."
  3003. (let ((p (point-at-bol)) to)
  3004. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3005. (get-text-property p :org-archived)
  3006. (org-end-of-subtree t)
  3007. (throw :skip t))
  3008. (and org-agenda-skip-comment-trees
  3009. (get-text-property p :org-comment)
  3010. (org-end-of-subtree t)
  3011. (throw :skip t))
  3012. (if (equal (char-after p) ?#) (throw :skip t))
  3013. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3014. (org-agenda-skip-eval org-agenda-skip-function)))
  3015. (goto-char to)
  3016. (throw :skip t))))
  3017. (defun org-agenda-skip-eval (form)
  3018. "If FORM is a function or a list, call (or eval) is and return result.
  3019. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3020. and match data are returned to the previous state no matter what these
  3021. functions do."
  3022. (let (fp)
  3023. (and form
  3024. (or (setq fp (functionp form))
  3025. (consp form))
  3026. (save-excursion
  3027. (save-match-data
  3028. (if fp
  3029. (funcall form)
  3030. (eval form)))))))
  3031. (defvar org-agenda-markers nil
  3032. "List of all currently active markers created by `org-agenda'.")
  3033. (defvar org-agenda-last-marker-time (org-float-time)
  3034. "Creation time of the last agenda marker.")
  3035. (defun org-agenda-new-marker (&optional pos)
  3036. "Return a new agenda marker.
  3037. Org-mode keeps a list of these markers and resets them when they are
  3038. no longer in use."
  3039. (let ((m (copy-marker (or pos (point)))))
  3040. (setq org-agenda-last-marker-time (org-float-time))
  3041. (push m org-agenda-markers)
  3042. m))
  3043. (defun org-agenda-reset-markers ()
  3044. "Reset markers created by `org-agenda'."
  3045. (while org-agenda-markers
  3046. (move-marker (pop org-agenda-markers) nil)))
  3047. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3048. "Save relative positions of markers in region."
  3049. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3050. org-agenda-markers))
  3051. ;;; Entry text mode
  3052. (defun org-agenda-entry-text-show-here ()
  3053. "Add some text from the entry as context to the current line."
  3054. (let (m txt o)
  3055. (setq m (org-get-at-bol 'org-hd-marker))
  3056. (unless (marker-buffer m)
  3057. (error "No marker points to an entry here"))
  3058. (setq txt (concat "\n" (org-no-properties
  3059. (org-agenda-get-some-entry-text
  3060. m org-agenda-entry-text-maxlines " > "))))
  3061. (when (string-match "\\S-" txt)
  3062. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3063. (overlay-put o 'evaporate t)
  3064. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3065. (overlay-put o 'after-string txt))))
  3066. (defun org-agenda-entry-text-show ()
  3067. "Add entry context for all agenda lines."
  3068. (interactive)
  3069. (save-excursion
  3070. (goto-char (point-max))
  3071. (beginning-of-line 1)
  3072. (while (not (bobp))
  3073. (when (org-get-at-bol 'org-hd-marker)
  3074. (org-agenda-entry-text-show-here))
  3075. (beginning-of-line 0))))
  3076. (defun org-agenda-entry-text-hide ()
  3077. "Remove any shown entry context."
  3078. (delq nil
  3079. (mapcar (lambda (o)
  3080. (if (eq (overlay-get o 'org-overlay-type)
  3081. 'agenda-entry-content)
  3082. (progn (delete-overlay o) t)))
  3083. (overlays-in (point-min) (point-max)))))
  3084. (defun org-agenda-get-day-face (date)
  3085. "Return the face DATE should be displayed with."
  3086. (or (and (functionp org-agenda-day-face-function)
  3087. (funcall org-agenda-day-face-function date))
  3088. (cond ((org-agenda-todayp date)
  3089. 'org-agenda-date-today)
  3090. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3091. 'org-agenda-date-weekend)
  3092. (t 'org-agenda-date))))
  3093. ;;; Agenda timeline
  3094. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3095. (defun org-timeline (&optional dotodo)
  3096. "Show a time-sorted view of the entries in the current org file.
  3097. Only entries with a time stamp of today or later will be listed. With
  3098. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3099. under the current date.
  3100. If the buffer contains an active region, only check the region for
  3101. dates."
  3102. (interactive "P")
  3103. (org-compile-prefix-format 'timeline)
  3104. (org-set-sorting-strategy 'timeline)
  3105. (let* ((dopast t)
  3106. (doclosed org-agenda-show-log)
  3107. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3108. (current-buffer))))
  3109. (date (calendar-current-date))
  3110. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3111. (end (if (org-region-active-p) (region-end) (point-max)))
  3112. (day-numbers (org-get-all-dates beg end 'no-ranges
  3113. t doclosed ; always include today
  3114. org-timeline-show-empty-dates))
  3115. (org-deadline-warning-days 0)
  3116. (org-agenda-only-exact-dates t)
  3117. (today (org-today))
  3118. (past t)
  3119. args
  3120. s e rtn d emptyp)
  3121. (setq org-agenda-redo-command
  3122. (list 'progn
  3123. (list 'org-switch-to-buffer-other-window (current-buffer))
  3124. (list 'org-timeline (list 'quote dotodo))))
  3125. (if (not dopast)
  3126. ;; Remove past dates from the list of dates.
  3127. (setq day-numbers (delq nil (mapcar (lambda(x)
  3128. (if (>= x today) x nil))
  3129. day-numbers))))
  3130. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3131. (if doclosed (push :closed args))
  3132. (push :timestamp args)
  3133. (push :deadline args)
  3134. (push :scheduled args)
  3135. (push :sexp args)
  3136. (if dotodo (push :todo args))
  3137. (insert "Timeline of file " entry "\n")
  3138. (add-text-properties (point-min) (point)
  3139. (list 'face 'org-agenda-structure))
  3140. (org-agenda-mark-header-line (point-min))
  3141. (while (setq d (pop day-numbers))
  3142. (if (and (listp d) (eq (car d) :omitted))
  3143. (progn
  3144. (setq s (point))
  3145. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3146. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3147. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3148. (if (and (>= d today)
  3149. dopast
  3150. past)
  3151. (progn
  3152. (setq past nil)
  3153. (insert (make-string 79 ?-) "\n")))
  3154. (setq date (calendar-gregorian-from-absolute d))
  3155. (setq s (point))
  3156. (setq rtn (and (not emptyp)
  3157. (apply 'org-agenda-get-day-entries entry
  3158. date args)))
  3159. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3160. (progn
  3161. (insert
  3162. (if (stringp org-agenda-format-date)
  3163. (format-time-string org-agenda-format-date
  3164. (org-time-from-absolute date))
  3165. (funcall org-agenda-format-date date))
  3166. "\n")
  3167. (put-text-property s (1- (point)) 'face
  3168. (org-agenda-get-day-face date))
  3169. (put-text-property s (1- (point)) 'org-date-line t)
  3170. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3171. (if (equal d today)
  3172. (put-text-property s (1- (point)) 'org-today t))
  3173. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3174. (put-text-property s (1- (point)) 'day d)))))
  3175. (goto-char (point-min))
  3176. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3177. (point-min)))
  3178. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3179. (org-finalize-agenda)
  3180. (setq buffer-read-only t)))
  3181. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3182. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3183. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3184. not every single day in the range. If FORCE-TODAY is non-nil, make
  3185. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3186. inactive time stamps (those in square brackets) are included.
  3187. When EMPTY is non-nil, also include days without any entries."
  3188. (let ((re (concat
  3189. (if pre-re pre-re "")
  3190. (if inactive org-ts-regexp-both org-ts-regexp)))
  3191. dates dates1 date day day1 day2 ts1 ts2 pos)
  3192. (if force-today
  3193. (setq dates (list (org-today))))
  3194. (save-excursion
  3195. (goto-char beg)
  3196. (while (re-search-forward re end t)
  3197. (setq day (time-to-days (org-time-string-to-time
  3198. (substring (match-string 1) 0 10)
  3199. (current-buffer) (match-beginning 0))))
  3200. (or (memq day dates) (push day dates)))
  3201. (unless no-ranges
  3202. (goto-char beg)
  3203. (while (re-search-forward org-tr-regexp end t)
  3204. (setq pos (match-beginning 0))
  3205. (setq ts1 (substring (match-string 1) 0 10)
  3206. ts2 (substring (match-string 2) 0 10)
  3207. day1 (time-to-days (org-time-string-to-time
  3208. ts1 (current-buffer) pos))
  3209. day2 (time-to-days (org-time-string-to-time
  3210. ts2 (current-buffer) pos)))
  3211. (while (< (setq day1 (1+ day1)) day2)
  3212. (or (memq day1 dates) (push day1 dates)))))
  3213. (setq dates (sort dates '<))
  3214. (when empty
  3215. (while (setq day (pop dates))
  3216. (setq day2 (car dates))
  3217. (push day dates1)
  3218. (when (and day2 empty)
  3219. (if (or (eq empty t)
  3220. (and (numberp empty) (<= (- day2 day) empty)))
  3221. (while (< (setq day (1+ day)) day2)
  3222. (push (list day) dates1))
  3223. (push (cons :omitted (- day2 day)) dates1))))
  3224. (setq dates (nreverse dates1)))
  3225. dates)))
  3226. ;;; Agenda Daily/Weekly
  3227. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3228. "Start day for the agenda view.
  3229. Custom commands can set this variable in the options section.")
  3230. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3231. (defvar org-agenda-current-span nil
  3232. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3233. (defvar org-arg-loc nil) ; local variable
  3234. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3235. "List of types searched for when creating the daily/weekly agenda.
  3236. This variable is a list of symbols that controls the types of
  3237. items that appear in the daily/weekly agenda. Allowed symbols in this
  3238. list are are
  3239. :timestamp List items containing a date stamp or date range matching
  3240. the selected date. This includes sexp entries in
  3241. angular brackets.
  3242. :sexp List entries resulting from plain diary-like sexps.
  3243. :deadline List deadline due on that date. When the date is today,
  3244. also list any deadlines past due, or due within
  3245. `org-deadline-warning-days'. `:deadline' must appear before
  3246. `:scheduled' if the setting of
  3247. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3248. any effect.
  3249. :scheduled List all items which are scheduled for the given date.
  3250. The diary for *today* also contains items which were
  3251. scheduled earlier and are not yet marked DONE.
  3252. By default, all four types are turned on.
  3253. Never set this variable globally using `setq', because then it
  3254. will apply to all future agenda commands. Instead, bind it with
  3255. `let' to scope it dynamically into the agenda-constructing
  3256. command. A good way to set it is through options in
  3257. `org-agenda-custom-commands'. For a more flexible (though
  3258. somewhat less efficient) way of determining what is included in
  3259. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3260. ;;;###autoload
  3261. (defun org-agenda-list (&optional arg start-day span)
  3262. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3263. The view will be for the current day or week, but from the overview buffer
  3264. you will be able to go to other days/weeks.
  3265. With a numeric prefix argument in an interactive call, the agenda will
  3266. span ARG days. Lisp programs should instead specify SPAN to change
  3267. the number of days. SPAN defaults to `org-agenda-span'.
  3268. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3269. given in `org-agenda-start-on-weekday'."
  3270. (interactive "P")
  3271. (if (and (integerp arg) (> arg 0))
  3272. (setq span arg arg nil))
  3273. (setq start-day (or start-day org-agenda-start-day))
  3274. (if org-agenda-overriding-arguments
  3275. (setq arg (car org-agenda-overriding-arguments)
  3276. start-day (nth 1 org-agenda-overriding-arguments)
  3277. span (nth 2 org-agenda-overriding-arguments)))
  3278. (if (stringp start-day)
  3279. ;; Convert to an absolute day number
  3280. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3281. (setq org-agenda-last-arguments (list arg start-day span))
  3282. (org-compile-prefix-format 'agenda)
  3283. (org-set-sorting-strategy 'agenda)
  3284. (let* ((span (org-agenda-ndays-to-span
  3285. (or span org-agenda-ndays org-agenda-span)))
  3286. (today (org-today))
  3287. (sd (or start-day today))
  3288. (ndays (org-agenda-span-to-ndays span sd))
  3289. (org-agenda-start-on-weekday
  3290. (if (eq ndays 7)
  3291. org-agenda-start-on-weekday))
  3292. (thefiles (org-agenda-files nil 'ifmode))
  3293. (files thefiles)
  3294. (start (if (or (null org-agenda-start-on-weekday)
  3295. (< ndays 7))
  3296. sd
  3297. (let* ((nt (calendar-day-of-week
  3298. (calendar-gregorian-from-absolute sd)))
  3299. (n1 org-agenda-start-on-weekday)
  3300. (d (- nt n1)))
  3301. (- sd (+ (if (< d 0) 7 0) d)))))
  3302. (day-numbers (list start))
  3303. (day-cnt 0)
  3304. (inhibit-redisplay (not debug-on-error))
  3305. s e rtn rtnall file date d start-pos end-pos todayp
  3306. clocktable-start clocktable-end filter)
  3307. (setq org-agenda-redo-command
  3308. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3309. (dotimes (n (1- ndays))
  3310. (push (1+ (car day-numbers)) day-numbers))
  3311. (setq day-numbers (nreverse day-numbers))
  3312. (setq clocktable-start (car day-numbers)
  3313. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3314. (org-prepare-agenda "Day/Week")
  3315. (org-set-local 'org-starting-day (car day-numbers))
  3316. (org-set-local 'org-arg-loc arg)
  3317. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3318. (unless org-agenda-compact-blocks
  3319. (let* ((d1 (car day-numbers))
  3320. (d2 (org-last day-numbers))
  3321. (w1 (org-days-to-iso-week d1))
  3322. (w2 (org-days-to-iso-week d2)))
  3323. (setq s (point))
  3324. (if org-agenda-overriding-header
  3325. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3326. nil 'face 'org-agenda-structure) "\n")
  3327. (insert (org-agenda-span-name span)
  3328. "-agenda"
  3329. (if (< (- d2 d1) 350)
  3330. (if (= w1 w2)
  3331. (format " (W%02d)" w1)
  3332. (format " (W%02d-W%02d)" w1 w2))
  3333. "")
  3334. ":\n")))
  3335. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3336. 'org-date-line t))
  3337. (org-agenda-mark-header-line s))
  3338. (while (setq d (pop day-numbers))
  3339. (setq date (calendar-gregorian-from-absolute d)
  3340. s (point))
  3341. (if (or (setq todayp (= d today))
  3342. (and (not start-pos) (= d sd)))
  3343. (setq start-pos (point))
  3344. (if (and start-pos (not end-pos))
  3345. (setq end-pos (point))))
  3346. (setq files thefiles
  3347. rtnall nil)
  3348. (while (setq file (pop files))
  3349. (catch 'nextfile
  3350. (org-check-agenda-file file)
  3351. (let ((org-agenda-entry-types org-agenda-entry-types))
  3352. (unless org-agenda-include-deadlines
  3353. (setq org-agenda-entry-types
  3354. (delq :deadline org-agenda-entry-types)))
  3355. (cond
  3356. ((memq org-agenda-show-log '(only clockcheck))
  3357. (setq rtn (org-agenda-get-day-entries
  3358. file date :closed)))
  3359. (org-agenda-show-log
  3360. (setq rtn (apply 'org-agenda-get-day-entries
  3361. file date
  3362. (append '(:closed) org-agenda-entry-types))))
  3363. (t
  3364. (setq rtn (apply 'org-agenda-get-day-entries
  3365. file date
  3366. org-agenda-entry-types)))))
  3367. (setq rtnall (append rtnall rtn)))) ;; all entries
  3368. (if org-agenda-include-diary
  3369. (let ((org-agenda-search-headline-for-time t))
  3370. (require 'diary-lib)
  3371. (setq rtn (org-get-entries-from-diary date))
  3372. (setq rtnall (append rtnall rtn))))
  3373. (if (or rtnall org-agenda-show-all-dates)
  3374. (progn
  3375. (setq day-cnt (1+ day-cnt))
  3376. (insert
  3377. (if (stringp org-agenda-format-date)
  3378. (format-time-string org-agenda-format-date
  3379. (org-time-from-absolute date))
  3380. (funcall org-agenda-format-date date))
  3381. "\n")
  3382. (put-text-property s (1- (point)) 'face
  3383. (org-agenda-get-day-face date))
  3384. (put-text-property s (1- (point)) 'org-date-line t)
  3385. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3386. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3387. (when todayp
  3388. (put-text-property s (1- (point)) 'org-today t))
  3389. (if rtnall (insert ;; all entries
  3390. (org-finalize-agenda-entries
  3391. (org-agenda-add-time-grid-maybe
  3392. rtnall ndays todayp))
  3393. "\n"))
  3394. (put-text-property s (1- (point)) 'day d)
  3395. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3396. (when (and org-agenda-clockreport-mode clocktable-start)
  3397. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3398. ;; the above line is to ensure the restricted range!
  3399. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3400. tbl)
  3401. (setq p (org-plist-delete p :block))
  3402. (setq p (plist-put p :tstart clocktable-start))
  3403. (setq p (plist-put p :tend clocktable-end))
  3404. (setq p (plist-put p :scope 'agenda))
  3405. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3406. (setq filter (or org-agenda-tag-filter-while-redo
  3407. (get 'org-agenda-tag-filter :preset-filter))))
  3408. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3409. (if (string-match "[<>=]" x)
  3410. ""
  3411. x))
  3412. filter ""))))
  3413. (setq tbl (apply 'org-get-clocktable p))
  3414. (insert tbl)))
  3415. (goto-char (point-min))
  3416. (or org-agenda-multi (org-fit-agenda-window))
  3417. (unless (and (pos-visible-in-window-p (point-min))
  3418. (pos-visible-in-window-p (point-max)))
  3419. (goto-char (1- (point-max)))
  3420. (recenter -1)
  3421. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3422. (progn
  3423. (goto-char (or start-pos 1))
  3424. (recenter 1))))
  3425. (goto-char (or start-pos 1))
  3426. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3427. (if (eq org-agenda-show-log 'clockcheck)
  3428. (org-agenda-show-clocking-issues))
  3429. (org-finalize-agenda)
  3430. (setq buffer-read-only t)
  3431. (message "")))
  3432. (defun org-agenda-ndays-to-span (n)
  3433. "Return a span symbol for a span of N days, or N if none matches."
  3434. (cond ((symbolp n) n)
  3435. ((= n 1) 'day)
  3436. ((= n 7) 'week)
  3437. (t n)))
  3438. (defun org-agenda-span-to-ndays (span start-day)
  3439. "Return ndays from SPAN starting at START-DAY."
  3440. (cond ((numberp span) span)
  3441. ((eq span 'day) 1)
  3442. ((eq span 'week) 7)
  3443. ((eq span 'month)
  3444. (let ((date (calendar-gregorian-from-absolute start-day)))
  3445. (calendar-last-day-of-month (car date) (caddr date))))
  3446. ((eq span 'year)
  3447. (let ((date (calendar-gregorian-from-absolute start-day)))
  3448. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3449. (defun org-agenda-span-name (span)
  3450. "Return a SPAN name."
  3451. (if (null span)
  3452. ""
  3453. (if (symbolp span)
  3454. (capitalize (symbol-name span))
  3455. (format "%d days" span))))
  3456. ;;; Agenda word search
  3457. (defvar org-agenda-search-history nil)
  3458. (defvar org-todo-only nil)
  3459. (defvar org-search-syntax-table nil
  3460. "Special syntax table for org-mode search.
  3461. In this table, we have single quotes not as word constituents, to
  3462. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3463. (defun org-search-syntax-table ()
  3464. (unless org-search-syntax-table
  3465. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3466. (modify-syntax-entry ?' "." org-search-syntax-table)
  3467. (modify-syntax-entry ?` "." org-search-syntax-table))
  3468. org-search-syntax-table)
  3469. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3470. ;;;###autoload
  3471. (defun org-search-view (&optional todo-only string edit-at)
  3472. "Show all entries that contain a phrase or words or regular expressions.
  3473. With optional prefix argument TODO-ONLY, only consider entries that are
  3474. TODO entries. The argument STRING can be used to pass a default search
  3475. string into this function. If EDIT-AT is non-nil, it means that the
  3476. user should get a chance to edit this string, with cursor at position
  3477. EDIT-AT.
  3478. The search string can be viewed either as a phrase that should be found as
  3479. is, or it can be broken into a number of snippets, each of which must match
  3480. in a Boolean way to select an entry. The default depends on the variable
  3481. `org-agenda-search-view-always-boolean'.
  3482. Even if this is turned off (the default) you can always switch to
  3483. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3484. The default is a direct search of the whole phrase, where each space in
  3485. the search string can expand to an arbitrary amount of whitespace,
  3486. including newlines.
  3487. If using a Boolean search, the search string is split on whitespace and
  3488. each snippet is searched separately, with logical AND to select an entry.
  3489. Words prefixed with a minus must *not* occur in the entry. Words without
  3490. a prefix or prefixed with a plus must occur in the entry. Matching is
  3491. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3492. match whole words, not parts of a word) if
  3493. `org-agenda-search-view-force-full-words' is set (default is nil).
  3494. Boolean search snippets enclosed by curly braces are interpreted as
  3495. regular expressions that must or (when preceded with \"-\") must not
  3496. match in the entry. Snippets enclosed into double quotes will be taken
  3497. as a whole, to include whitespace.
  3498. - If the search string starts with an asterisk, search only in headlines.
  3499. - If (possibly after the leading star) the search string starts with an
  3500. exclamation mark, this also means to look at TODO entries only, an effect
  3501. that can also be achieved with a prefix argument.
  3502. - If (possibly after star and exclamation mark) the search string starts
  3503. with a colon, this will mean that the (non-regexp) snippets of the
  3504. Boolean search must match as full words.
  3505. This command searches the agenda files, and in addition the files listed
  3506. in `org-agenda-text-search-extra-files'."
  3507. (interactive "P")
  3508. (org-compile-prefix-format 'search)
  3509. (org-set-sorting-strategy 'search)
  3510. (org-prepare-agenda "SEARCH")
  3511. (let* ((props (list 'face nil
  3512. 'done-face 'org-agenda-done
  3513. 'org-not-done-regexp org-not-done-regexp
  3514. 'org-todo-regexp org-todo-regexp
  3515. 'org-complex-heading-regexp org-complex-heading-regexp
  3516. 'mouse-face 'highlight
  3517. 'help-echo (format "mouse-2 or RET jump to location")))
  3518. (full-words org-agenda-search-view-force-full-words)
  3519. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3520. regexp rtn rtnall files file pos
  3521. marker category org-category-pos tags c neg re boolean
  3522. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3523. (unless (and (not edit-at)
  3524. (stringp string)
  3525. (string-match "\\S-" string))
  3526. (setq string (read-string
  3527. (if org-agenda-search-view-always-boolean
  3528. "[+-]Word/{Regexp} ...: "
  3529. "Phrase, or [+-]Word/{Regexp} ...: ")
  3530. (cond
  3531. ((integerp edit-at) (cons string edit-at))
  3532. (edit-at string))
  3533. 'org-agenda-search-history)))
  3534. (org-set-local 'org-todo-only todo-only)
  3535. (setq org-agenda-redo-command
  3536. (list 'org-search-view (if todo-only t nil) string
  3537. '(if current-prefix-arg 1 nil)))
  3538. (setq org-agenda-query-string string)
  3539. (if (equal (string-to-char string) ?*)
  3540. (setq hdl-only t
  3541. words (substring string 1))
  3542. (setq words string))
  3543. (when (equal (string-to-char words) ?!)
  3544. (setq todo-only t
  3545. words (substring words 1)))
  3546. (when (equal (string-to-char words) ?:)
  3547. (setq full-words t
  3548. words (substring words 1)))
  3549. (if (or org-agenda-search-view-always-boolean
  3550. (member (string-to-char words) '(?- ?+ ?\{)))
  3551. (setq boolean t))
  3552. (setq words (org-split-string words))
  3553. (let (www w)
  3554. (while (setq w (pop words))
  3555. (while (and (string-match "\\\\\\'" w) words)
  3556. (setq w (concat (substring w 0 -1) " " (pop words))))
  3557. (push w www))
  3558. (setq words (nreverse www) www nil)
  3559. (while (setq w (pop words))
  3560. (when (and (string-match "\\`[-+]?{" w)
  3561. (not (string-match "}\\'" w)))
  3562. (while (and words (not (string-match "}\\'" (car words))))
  3563. (setq w (concat w " " (pop words))))
  3564. (setq w (concat w " " (pop words))))
  3565. (push w www))
  3566. (setq words (nreverse www)))
  3567. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3568. (when boolean
  3569. (let (wds w)
  3570. (while (setq w (pop words))
  3571. (if (or (equal (substring w 0 1) "\"")
  3572. (and (> (length w) 1)
  3573. (member (substring w 0 1) '("+" "-"))
  3574. (equal (substring w 1 2) "\"")))
  3575. (while (and words (not (equal (substring w -1) "\"")))
  3576. (setq w (concat w " " (pop words)))))
  3577. (and (string-match "\\`\\([-+]?\\)\"" w)
  3578. (setq w (replace-match "\\1" nil nil w)))
  3579. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3580. (push w wds))
  3581. (setq words (nreverse wds))))
  3582. (if boolean
  3583. (mapc (lambda (w)
  3584. (setq c (string-to-char w))
  3585. (if (equal c ?-)
  3586. (setq neg t w (substring w 1))
  3587. (if (equal c ?+)
  3588. (setq neg nil w (substring w 1))
  3589. (setq neg nil)))
  3590. (if (string-match "\\`{.*}\\'" w)
  3591. (setq re (substring w 1 -1))
  3592. (if full-words
  3593. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3594. (setq re (regexp-quote (downcase w)))))
  3595. (if neg (push re regexps-) (push re regexps+)))
  3596. words)
  3597. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3598. regexps+))
  3599. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3600. (if (not regexps+)
  3601. (setq regexp org-outline-regexp-bol)
  3602. (setq regexp (pop regexps+))
  3603. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3604. regexp))))
  3605. (setq files (org-agenda-files nil 'ifmode))
  3606. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3607. (pop org-agenda-text-search-extra-files)
  3608. (setq files (org-add-archive-files files)))
  3609. (setq files (append files org-agenda-text-search-extra-files)
  3610. rtnall nil)
  3611. (while (setq file (pop files))
  3612. (setq ee nil)
  3613. (catch 'nextfile
  3614. (org-check-agenda-file file)
  3615. (setq buffer (if (file-exists-p file)
  3616. (org-get-agenda-file-buffer file)
  3617. (error "No such file %s" file)))
  3618. (if (not buffer)
  3619. ;; If file does not exist, make sure an error message is sent
  3620. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3621. file))))
  3622. (with-current-buffer buffer
  3623. (with-syntax-table (org-search-syntax-table)
  3624. (unless (eq major-mode 'org-mode)
  3625. (error "Agenda file %s is not in `org-mode'" file))
  3626. (let ((case-fold-search t))
  3627. (save-excursion
  3628. (save-restriction
  3629. (if org-agenda-restrict
  3630. (narrow-to-region org-agenda-restrict-begin
  3631. org-agenda-restrict-end)
  3632. (widen))
  3633. (goto-char (point-min))
  3634. (unless (or (org-at-heading-p)
  3635. (outline-next-heading))
  3636. (throw 'nextfile t))
  3637. (goto-char (max (point-min) (1- (point))))
  3638. (while (re-search-forward regexp nil t)
  3639. (org-back-to-heading t)
  3640. (skip-chars-forward "* ")
  3641. (setq beg (point-at-bol)
  3642. beg1 (point)
  3643. end (progn (outline-next-heading) (point)))
  3644. (catch :skip
  3645. (goto-char beg)
  3646. (org-agenda-skip)
  3647. (setq str (buffer-substring-no-properties
  3648. (point-at-bol)
  3649. (if hdl-only (point-at-eol) end)))
  3650. (mapc (lambda (wr) (when (string-match wr str)
  3651. (goto-char (1- end))
  3652. (throw :skip t)))
  3653. regexps-)
  3654. (mapc (lambda (wr) (unless (string-match wr str)
  3655. (goto-char (1- end))
  3656. (throw :skip t)))
  3657. (if todo-only
  3658. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3659. regexps+)
  3660. regexps+))
  3661. (goto-char beg)
  3662. (setq marker (org-agenda-new-marker (point))
  3663. category (org-get-category)
  3664. org-category-pos (get-text-property (point) 'org-category-position)
  3665. tags (org-get-tags-at (point))
  3666. txt (org-agenda-format-item
  3667. ""
  3668. (buffer-substring-no-properties
  3669. beg1 (point-at-eol))
  3670. category tags))
  3671. (org-add-props txt props
  3672. 'org-marker marker 'org-hd-marker marker
  3673. 'org-todo-regexp org-todo-regexp
  3674. 'org-complex-heading-regexp org-complex-heading-regexp
  3675. 'priority 1000 'org-category category
  3676. 'org-category-position org-category-pos
  3677. 'type "search")
  3678. (push txt ee)
  3679. (goto-char (1- end))))))))))
  3680. (setq rtn (nreverse ee))
  3681. (setq rtnall (append rtnall rtn)))
  3682. (if org-agenda-overriding-header
  3683. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3684. nil 'face 'org-agenda-structure) "\n")
  3685. (insert "Search words: ")
  3686. (add-text-properties (point-min) (1- (point))
  3687. (list 'face 'org-agenda-structure))
  3688. (setq pos (point))
  3689. (insert string "\n")
  3690. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3691. (setq pos (point))
  3692. (unless org-agenda-multi
  3693. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3694. (add-text-properties pos (1- (point))
  3695. (list 'face 'org-agenda-structure))))
  3696. (org-agenda-mark-header-line (point-min))
  3697. (when rtnall
  3698. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3699. (goto-char (point-min))
  3700. (or org-agenda-multi (org-fit-agenda-window))
  3701. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3702. (org-finalize-agenda)
  3703. (setq buffer-read-only t)))
  3704. ;;; Agenda TODO list
  3705. (defvar org-select-this-todo-keyword nil)
  3706. (defvar org-last-arg nil)
  3707. ;;;###autoload
  3708. (defun org-todo-list (arg)
  3709. "Show all (not done) TODO entries from all agenda file in a single list.
  3710. The prefix arg can be used to select a specific TODO keyword and limit
  3711. the list to these. When using \\[universal-argument], you will be prompted
  3712. for a keyword. A numeric prefix directly selects the Nth keyword in
  3713. `org-todo-keywords-1'."
  3714. (interactive "P")
  3715. (org-compile-prefix-format 'todo)
  3716. (org-set-sorting-strategy 'todo)
  3717. (org-prepare-agenda "TODO")
  3718. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3719. (let* ((today (org-today))
  3720. (date (calendar-gregorian-from-absolute today))
  3721. (kwds org-todo-keywords-for-agenda)
  3722. (completion-ignore-case t)
  3723. (org-select-this-todo-keyword
  3724. (if (stringp arg) arg
  3725. (and arg (integerp arg) (> arg 0)
  3726. (nth (1- arg) kwds))))
  3727. rtn rtnall files file pos)
  3728. (when (equal arg '(4))
  3729. (setq org-select-this-todo-keyword
  3730. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3731. (mapcar 'list kwds) nil nil)))
  3732. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3733. (org-set-local 'org-last-arg arg)
  3734. (setq org-agenda-redo-command
  3735. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3736. (setq files (org-agenda-files nil 'ifmode)
  3737. rtnall nil)
  3738. (while (setq file (pop files))
  3739. (catch 'nextfile
  3740. (org-check-agenda-file file)
  3741. (setq rtn (org-agenda-get-day-entries file date :todo))
  3742. (setq rtnall (append rtnall rtn))))
  3743. (if org-agenda-overriding-header
  3744. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3745. nil 'face 'org-agenda-structure) "\n")
  3746. (insert "Global list of TODO items of type: ")
  3747. (add-text-properties (point-min) (1- (point))
  3748. (list 'face 'org-agenda-structure
  3749. 'short-heading
  3750. (concat "ToDo: "
  3751. (or org-select-this-todo-keyword "ALL"))))
  3752. (org-agenda-mark-header-line (point-min))
  3753. (setq pos (point))
  3754. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3755. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3756. (setq pos (point))
  3757. (unless org-agenda-multi
  3758. (insert "Available with `N r': (0)ALL")
  3759. (let ((n 0) s)
  3760. (mapc (lambda (x)
  3761. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3762. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3763. (insert "\n "))
  3764. (insert " " s))
  3765. kwds))
  3766. (insert "\n"))
  3767. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3768. (org-agenda-mark-header-line (point-min))
  3769. (when rtnall
  3770. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3771. (goto-char (point-min))
  3772. (or org-agenda-multi (org-fit-agenda-window))
  3773. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3774. (org-finalize-agenda)
  3775. (setq buffer-read-only t)))
  3776. ;;; Agenda tags match
  3777. ;;;###autoload
  3778. (defun org-tags-view (&optional todo-only match)
  3779. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3780. The prefix arg TODO-ONLY limits the search to TODO entries."
  3781. (interactive "P")
  3782. (org-compile-prefix-format 'tags)
  3783. (org-set-sorting-strategy 'tags)
  3784. (let* ((org-tags-match-list-sublevels
  3785. org-tags-match-list-sublevels)
  3786. (completion-ignore-case t)
  3787. rtn rtnall files file pos matcher
  3788. buffer)
  3789. (when (and (stringp match) (not (string-match "\\S-" match)))
  3790. (setq match nil))
  3791. (setq matcher (org-make-tags-matcher match)
  3792. match (car matcher) matcher (cdr matcher))
  3793. (org-prepare-agenda (concat "TAGS " match))
  3794. (setq org-agenda-query-string match)
  3795. (setq org-agenda-redo-command
  3796. (list 'org-tags-view (list 'quote todo-only)
  3797. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3798. (setq files (org-agenda-files nil 'ifmode)
  3799. rtnall nil)
  3800. (while (setq file (pop files))
  3801. (catch 'nextfile
  3802. (org-check-agenda-file file)
  3803. (setq buffer (if (file-exists-p file)
  3804. (org-get-agenda-file-buffer file)
  3805. (error "No such file %s" file)))
  3806. (if (not buffer)
  3807. ;; If file does not exist, error message to agenda
  3808. (setq rtn (list
  3809. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3810. rtnall (append rtnall rtn))
  3811. (with-current-buffer buffer
  3812. (unless (eq major-mode 'org-mode)
  3813. (error "Agenda file %s is not in `org-mode'" file))
  3814. (save-excursion
  3815. (save-restriction
  3816. (if org-agenda-restrict
  3817. (narrow-to-region org-agenda-restrict-begin
  3818. org-agenda-restrict-end)
  3819. (widen))
  3820. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3821. (setq rtnall (append rtnall rtn))))))))
  3822. (if org-agenda-overriding-header
  3823. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3824. nil 'face 'org-agenda-structure) "\n")
  3825. (insert "Headlines with TAGS match: ")
  3826. (add-text-properties (point-min) (1- (point))
  3827. (list 'face 'org-agenda-structure
  3828. 'short-heading
  3829. (concat "Match: " match)))
  3830. (setq pos (point))
  3831. (insert match "\n")
  3832. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3833. (setq pos (point))
  3834. (unless org-agenda-multi
  3835. (insert "Press `C-u r' to search again with new search string\n"))
  3836. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3837. (org-agenda-mark-header-line (point-min))
  3838. (when rtnall
  3839. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3840. (goto-char (point-min))
  3841. (or org-agenda-multi (org-fit-agenda-window))
  3842. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3843. (org-finalize-agenda)
  3844. (setq buffer-read-only t)))
  3845. ;;; Agenda Finding stuck projects
  3846. (defvar org-agenda-skip-regexp nil
  3847. "Regular expression used in skipping subtrees for the agenda.
  3848. This is basically a temporary global variable that can be set and then
  3849. used by user-defined selections using `org-agenda-skip-function'.")
  3850. (defvar org-agenda-overriding-header nil
  3851. "When set during agenda, todo and tags searches it replaces the header.
  3852. This variable should not be set directly, but custom commands can bind it
  3853. in the options section.")
  3854. (defun org-agenda-skip-entry-when-regexp-matches ()
  3855. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3856. If yes, it returns the end position of this entry, causing agenda commands
  3857. to skip the entry but continuing the search in the subtree. This is a
  3858. function that can be put into `org-agenda-skip-function' for the duration
  3859. of a command."
  3860. (let ((end (save-excursion (org-end-of-subtree t)))
  3861. skip)
  3862. (save-excursion
  3863. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3864. (and skip end)))
  3865. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3866. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3867. If yes, it returns the end position of this tree, causing agenda commands
  3868. to skip this subtree. This is a function that can be put into
  3869. `org-agenda-skip-function' for the duration of a command."
  3870. (let ((end (save-excursion (org-end-of-subtree t)))
  3871. skip)
  3872. (save-excursion
  3873. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3874. (and skip end)))
  3875. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3876. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3877. If yes, it returns the end position of the current entry (NOT the tree),
  3878. causing agenda commands to skip the entry but continuing the search in
  3879. the subtree. This is a function that can be put into
  3880. `org-agenda-skip-function' for the duration of a command. An important
  3881. use of this function is for the stuck project list."
  3882. (let ((end (save-excursion (org-end-of-subtree t)))
  3883. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3884. skip)
  3885. (save-excursion
  3886. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3887. (and skip entry-end)))
  3888. (defun org-agenda-skip-entry-if (&rest conditions)
  3889. "Skip entry if any of CONDITIONS is true.
  3890. See `org-agenda-skip-if' for details."
  3891. (org-agenda-skip-if nil conditions))
  3892. (defun org-agenda-skip-subtree-if (&rest conditions)
  3893. "Skip entry if any of CONDITIONS is true.
  3894. See `org-agenda-skip-if' for details."
  3895. (org-agenda-skip-if t conditions))
  3896. (defun org-agenda-skip-if (subtree conditions)
  3897. "Checks current entity for CONDITIONS.
  3898. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3899. the entry, i.e. the text before the next heading is checked.
  3900. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3901. from different tests. Valid conditions are:
  3902. scheduled Check if there is a scheduled cookie
  3903. notscheduled Check if there is no scheduled cookie
  3904. deadline Check if there is a deadline
  3905. notdeadline Check if there is no deadline
  3906. timestamp Check if there is a timestamp (also deadline or scheduled)
  3907. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3908. regexp Check if regexp matches
  3909. notregexp Check if regexp does not match.
  3910. todo Check if TODO keyword matches
  3911. nottodo Check if TODO keyword does not match
  3912. The regexp is taken from the conditions list, it must come right after
  3913. the `regexp' or `notregexp' element.
  3914. `todo' and `nottodo' accept as an argument a list of todo
  3915. keywords, which may include \"*\" to match any todo keyword.
  3916. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3917. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3918. Instead of a list a keyword class may be given
  3919. (org-agenda-skip-entry-if 'nottodo 'done)
  3920. would skip entries that haven't been marked with any of \"DONE\"
  3921. keywords. Possible classes are: `todo', `done', `any'.
  3922. If any of these conditions is met, this function returns the end point of
  3923. the entity, causing the search to continue from there. This is a function
  3924. that can be put into `org-agenda-skip-function' for the duration of a command."
  3925. (let (beg end m)
  3926. (org-back-to-heading t)
  3927. (setq beg (point)
  3928. end (if subtree
  3929. (progn (org-end-of-subtree t) (point))
  3930. (progn (outline-next-heading) (1- (point)))))
  3931. (goto-char beg)
  3932. (and
  3933. (or
  3934. (and (memq 'scheduled conditions)
  3935. (re-search-forward org-scheduled-time-regexp end t))
  3936. (and (memq 'notscheduled conditions)
  3937. (not (re-search-forward org-scheduled-time-regexp end t)))
  3938. (and (memq 'deadline conditions)
  3939. (re-search-forward org-deadline-time-regexp end t))
  3940. (and (memq 'notdeadline conditions)
  3941. (not (re-search-forward org-deadline-time-regexp end t)))
  3942. (and (memq 'timestamp conditions)
  3943. (re-search-forward org-ts-regexp end t))
  3944. (and (memq 'nottimestamp conditions)
  3945. (not (re-search-forward org-ts-regexp end t)))
  3946. (and (setq m (memq 'regexp conditions))
  3947. (stringp (nth 1 m))
  3948. (re-search-forward (nth 1 m) end t))
  3949. (and (setq m (memq 'notregexp conditions))
  3950. (stringp (nth 1 m))
  3951. (not (re-search-forward (nth 1 m) end t)))
  3952. (and (or
  3953. (setq m (memq 'todo conditions))
  3954. (setq m (memq 'nottodo conditions)))
  3955. (org-agenda-skip-if-todo m end)))
  3956. end)))
  3957. (defun org-agenda-skip-if-todo (args end)
  3958. "Helper function for `org-agenda-skip-if', do not use it directly.
  3959. ARGS is a list with first element either `todo' or `nottodo'.
  3960. The remainder is either a list of TODO keywords, or a state symbol
  3961. `todo' or `done' or `any'."
  3962. (let ((kw (car args))
  3963. (arg (cadr args))
  3964. todo-wds todo-re)
  3965. (setq todo-wds
  3966. (org-uniquify
  3967. (cond
  3968. ((listp arg) ;; list of keywords
  3969. (if (member "*" arg)
  3970. (mapcar 'substring-no-properties org-todo-keywords-1)
  3971. arg))
  3972. ((symbolp arg) ;; keyword class name
  3973. (cond
  3974. ((eq arg 'todo)
  3975. (org-delete-all org-done-keywords
  3976. (mapcar 'substring-no-properties
  3977. org-todo-keywords-1)))
  3978. ((eq arg 'done) org-done-keywords)
  3979. ((eq arg 'any)
  3980. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3981. (setq todo-re
  3982. (concat "^\\*+[ \t]+\\<\\("
  3983. (mapconcat 'identity todo-wds "\\|")
  3984. "\\)\\>"))
  3985. (if (eq kw 'todo)
  3986. (re-search-forward todo-re end t)
  3987. (not (re-search-forward todo-re end t)))))
  3988. ;;;###autoload
  3989. (defun org-agenda-list-stuck-projects (&rest ignore)
  3990. "Create agenda view for projects that are stuck.
  3991. Stuck projects are project that have no next actions. For the definitions
  3992. of what a project is and how to check if it stuck, customize the variable
  3993. `org-stuck-projects'."
  3994. (interactive)
  3995. (let* ((org-agenda-skip-function
  3996. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3997. ;; We could have used org-agenda-skip-if here.
  3998. (org-agenda-overriding-header
  3999. (or org-agenda-overriding-header "List of stuck projects: "))
  4000. (matcher (nth 0 org-stuck-projects))
  4001. (todo (nth 1 org-stuck-projects))
  4002. (todo-wds (if (member "*" todo)
  4003. (progn
  4004. (org-prepare-agenda-buffers (org-agenda-files
  4005. nil 'ifmode))
  4006. (org-delete-all
  4007. org-done-keywords-for-agenda
  4008. (copy-sequence org-todo-keywords-for-agenda)))
  4009. todo))
  4010. (todo-re (concat "^\\*+[ \t]+\\("
  4011. (mapconcat 'identity todo-wds "\\|")
  4012. "\\)\\>"))
  4013. (tags (nth 2 org-stuck-projects))
  4014. (tags-re (if (member "*" tags)
  4015. (concat org-outline-regexp-bol
  4016. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4017. (if tags
  4018. (concat org-outline-regexp-bol
  4019. ".*:\\("
  4020. (mapconcat 'identity tags "\\|")
  4021. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4022. (gen-re (nth 3 org-stuck-projects))
  4023. (re-list
  4024. (delq nil
  4025. (list
  4026. (if todo todo-re)
  4027. (if tags tags-re)
  4028. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4029. gen-re)))))
  4030. (setq org-agenda-skip-regexp
  4031. (if re-list
  4032. (mapconcat 'identity re-list "\\|")
  4033. (error "No information how to identify unstuck projects")))
  4034. (org-tags-view nil matcher)
  4035. (with-current-buffer org-agenda-buffer-name
  4036. (setq org-agenda-redo-command
  4037. '(org-agenda-list-stuck-projects
  4038. (or current-prefix-arg org-last-arg))))))
  4039. ;;; Diary integration
  4040. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4041. (defvar diary-list-entries-hook)
  4042. (defvar diary-time-regexp)
  4043. (defun org-get-entries-from-diary (date)
  4044. "Get the (Emacs Calendar) diary entries for DATE."
  4045. (require 'diary-lib)
  4046. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4047. (diary-display-hook '(fancy-diary-display))
  4048. (diary-display-function 'fancy-diary-display)
  4049. (pop-up-frames nil)
  4050. (diary-list-entries-hook
  4051. (cons 'org-diary-default-entry diary-list-entries-hook))
  4052. (diary-file-name-prefix-function nil) ; turn this feature off
  4053. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4054. entries
  4055. (org-disable-agenda-to-diary t))
  4056. (save-excursion
  4057. (save-window-excursion
  4058. (funcall (if (fboundp 'diary-list-entries)
  4059. 'diary-list-entries 'list-diary-entries)
  4060. date 1)))
  4061. (if (not (get-buffer diary-fancy-buffer))
  4062. (setq entries nil)
  4063. (with-current-buffer diary-fancy-buffer
  4064. (setq buffer-read-only nil)
  4065. (if (zerop (buffer-size))
  4066. ;; No entries
  4067. (setq entries nil)
  4068. ;; Omit the date and other unnecessary stuff
  4069. (org-agenda-cleanup-fancy-diary)
  4070. ;; Add prefix to each line and extend the text properties
  4071. (if (zerop (buffer-size))
  4072. (setq entries nil)
  4073. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4074. (setq entries
  4075. (with-temp-buffer
  4076. (insert entries) (goto-char (point-min))
  4077. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4078. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4079. (replace-match (concat "; " (match-string 1)))))
  4080. (buffer-string)))))
  4081. (set-buffer-modified-p nil)
  4082. (kill-buffer diary-fancy-buffer)))
  4083. (when entries
  4084. (setq entries (org-split-string entries "\n"))
  4085. (setq entries
  4086. (mapcar
  4087. (lambda (x)
  4088. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4089. ;; Extend the text properties to the beginning of the line
  4090. (org-add-props x (text-properties-at (1- (length x)) x)
  4091. 'type "diary" 'date date 'face 'org-agenda-diary))
  4092. entries)))))
  4093. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4094. "Hook run when the fancy diary buffer is cleaned up.")
  4095. (defun org-agenda-cleanup-fancy-diary ()
  4096. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4097. This gets rid of the date, the underline under the date, and
  4098. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4099. date. It also removes lines that contain only whitespace."
  4100. (goto-char (point-min))
  4101. (if (looking-at ".*?:[ \t]*")
  4102. (progn
  4103. (replace-match "")
  4104. (re-search-forward "\n=+$" nil t)
  4105. (replace-match "")
  4106. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4107. (re-search-forward "\n=+$" nil t)
  4108. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4109. (goto-char (point-min))
  4110. (while (re-search-forward "^ +\n" nil t)
  4111. (replace-match ""))
  4112. (goto-char (point-min))
  4113. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4114. (replace-match ""))
  4115. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4116. ;; Make sure entries from the diary have the right text properties.
  4117. (eval-after-load "diary-lib"
  4118. '(if (boundp 'diary-modify-entry-list-string-function)
  4119. ;; We can rely on the hook, nothing to do
  4120. nil
  4121. ;; Hook not available, must use advice to make this work
  4122. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4123. "Make the position visible."
  4124. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4125. (stringp string)
  4126. buffer-file-name)
  4127. (setq string (org-modify-diary-entry-string string))))))
  4128. (defun org-modify-diary-entry-string (string)
  4129. "Add text properties to string, allowing org-mode to act on it."
  4130. (org-add-props string nil
  4131. 'mouse-face 'highlight
  4132. 'help-echo (if buffer-file-name
  4133. (format "mouse-2 or RET jump to diary file %s"
  4134. (abbreviate-file-name buffer-file-name))
  4135. "")
  4136. 'org-agenda-diary-link t
  4137. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4138. (defun org-diary-default-entry ()
  4139. "Add a dummy entry to the diary.
  4140. Needed to avoid empty dates which mess up holiday display."
  4141. ;; Catch the error if dealing with the new add-to-diary-alist
  4142. (when org-disable-agenda-to-diary
  4143. (condition-case nil
  4144. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4145. (error
  4146. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4147. (defun org-add-to-diary-list (&rest args)
  4148. (if (fboundp 'diary-add-to-list)
  4149. (apply 'diary-add-to-list args)
  4150. (apply 'add-to-diary-list args)))
  4151. (defvar org-diary-last-run-time nil)
  4152. ;;;###autoload
  4153. (defun org-diary (&rest args)
  4154. "Return diary information from org-files.
  4155. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4156. It accesses org files and extracts information from those files to be
  4157. listed in the diary. The function accepts arguments specifying what
  4158. items should be listed. For a list of arguments allowed here, see the
  4159. variable `org-agenda-entry-types'.
  4160. The call in the diary file should look like this:
  4161. &%%(org-diary) ~/path/to/some/orgfile.org
  4162. Use a separate line for each org file to check. Or, if you omit the file name,
  4163. all files listed in `org-agenda-files' will be checked automatically:
  4164. &%%(org-diary)
  4165. If you don't give any arguments (as in the example above), the default
  4166. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4167. So the example above may also be written as
  4168. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4169. The function expects the lisp variables `entry' and `date' to be provided
  4170. by the caller, because this is how the calendar works. Don't use this
  4171. function from a program - use `org-agenda-get-day-entries' instead."
  4172. (when (> (- (org-float-time)
  4173. org-agenda-last-marker-time)
  4174. 5)
  4175. (org-agenda-reset-markers))
  4176. (org-compile-prefix-format 'agenda)
  4177. (org-set-sorting-strategy 'agenda)
  4178. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4179. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4180. (list entry)
  4181. (org-agenda-files t)))
  4182. (time (org-float-time))
  4183. file rtn results)
  4184. (when (or (not org-diary-last-run-time)
  4185. (> (- time
  4186. org-diary-last-run-time)
  4187. 3))
  4188. (org-prepare-agenda-buffers files))
  4189. (setq org-diary-last-run-time time)
  4190. ;; If this is called during org-agenda, don't return any entries to
  4191. ;; the calendar. Org Agenda will list these entries itself.
  4192. (if org-disable-agenda-to-diary (setq files nil))
  4193. (while (setq file (pop files))
  4194. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4195. (setq results (append results rtn)))
  4196. (if results
  4197. (concat (org-finalize-agenda-entries results) "\n"))))
  4198. ;;; Agenda entry finders
  4199. (defun org-agenda-get-day-entries (file date &rest args)
  4200. "Does the work for `org-diary' and `org-agenda'.
  4201. FILE is the path to a file to be checked for entries. DATE is date like
  4202. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4203. which kind of entries should be extracted. For details about these, see
  4204. the documentation of `org-diary'."
  4205. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4206. (let* ((org-startup-folded nil)
  4207. (org-startup-align-all-tables nil)
  4208. (buffer (if (file-exists-p file)
  4209. (org-get-agenda-file-buffer file)
  4210. (error "No such file %s" file)))
  4211. arg results rtn deadline-results)
  4212. (if (not buffer)
  4213. ;; If file does not exist, make sure an error message ends up in diary
  4214. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4215. (with-current-buffer buffer
  4216. (unless (eq major-mode 'org-mode)
  4217. (error "Agenda file %s is not in `org-mode'" file))
  4218. (let ((case-fold-search nil))
  4219. (save-excursion
  4220. (save-restriction
  4221. (if org-agenda-restrict
  4222. (narrow-to-region org-agenda-restrict-begin
  4223. org-agenda-restrict-end)
  4224. (widen))
  4225. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4226. (while (setq arg (pop args))
  4227. (cond
  4228. ((and (eq arg :todo)
  4229. (equal date (calendar-gregorian-from-absolute
  4230. (org-today))))
  4231. (setq rtn (org-agenda-get-todos))
  4232. (setq results (append results rtn)))
  4233. ((eq arg :timestamp)
  4234. (setq rtn (org-agenda-get-blocks))
  4235. (setq results (append results rtn))
  4236. (setq rtn (org-agenda-get-timestamps))
  4237. (setq results (append results rtn)))
  4238. ((eq arg :sexp)
  4239. (setq rtn (org-agenda-get-sexps))
  4240. (setq results (append results rtn)))
  4241. ((eq arg :scheduled)
  4242. (setq rtn (org-agenda-get-scheduled deadline-results))
  4243. (setq results (append results rtn)))
  4244. ((eq arg :closed)
  4245. (setq rtn (org-agenda-get-progress))
  4246. (setq results (append results rtn)))
  4247. ((eq arg :deadline)
  4248. (setq rtn (org-agenda-get-deadlines))
  4249. (setq deadline-results (copy-sequence rtn))
  4250. (setq results (append results rtn))))))))
  4251. results))))
  4252. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4253. (defun org-agenda-get-todos ()
  4254. "Return the TODO information for agenda display."
  4255. (let* ((props (list 'face nil
  4256. 'done-face 'org-agenda-done
  4257. 'org-not-done-regexp org-not-done-regexp
  4258. 'org-todo-regexp org-todo-regexp
  4259. 'org-complex-heading-regexp org-complex-heading-regexp
  4260. 'mouse-face 'highlight
  4261. 'help-echo
  4262. (format "mouse-2 or RET jump to org file %s"
  4263. (abbreviate-file-name buffer-file-name))))
  4264. (regexp (format org-heading-keyword-regexp-format
  4265. (cond
  4266. ((and org-select-this-todo-keyword
  4267. (equal org-select-this-todo-keyword "*"))
  4268. org-todo-regexp)
  4269. (org-select-this-todo-keyword
  4270. (concat "\\("
  4271. (mapconcat 'identity
  4272. (org-split-string
  4273. org-select-this-todo-keyword
  4274. "|")
  4275. "\\|") "\\)"))
  4276. (t org-not-done-regexp))))
  4277. marker priority category org-category-pos tags todo-state
  4278. ee txt beg end)
  4279. (goto-char (point-min))
  4280. (while (re-search-forward regexp nil t)
  4281. (catch :skip
  4282. (save-match-data
  4283. (beginning-of-line)
  4284. (org-agenda-skip)
  4285. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4286. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4287. (goto-char (1+ beg))
  4288. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4289. (throw :skip nil)))
  4290. (goto-char (match-beginning 2))
  4291. (setq marker (org-agenda-new-marker (match-beginning 0))
  4292. category (org-get-category)
  4293. org-category-pos (get-text-property (point) 'org-category-position)
  4294. txt (org-trim
  4295. (buffer-substring (match-beginning 2) (match-end 0)))
  4296. tags (org-get-tags-at (point))
  4297. txt (org-agenda-format-item "" txt category tags)
  4298. priority (1+ (org-get-priority txt))
  4299. todo-state (org-get-todo-state))
  4300. (org-add-props txt props
  4301. 'org-marker marker 'org-hd-marker marker
  4302. 'priority priority 'org-category category
  4303. 'org-category-position org-category-pos
  4304. 'type "todo" 'todo-state todo-state)
  4305. (push txt ee)
  4306. (if org-agenda-todo-list-sublevels
  4307. (goto-char (match-end 2))
  4308. (org-end-of-subtree 'invisible))))
  4309. (nreverse ee)))
  4310. (defun org-agenda-todo-custom-ignore-p (time n)
  4311. "Check whether timestamp is farther away then n number of days.
  4312. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4313. `org-agenda-todo-ignore-scheduled' or
  4314. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4315. (let ((days (org-days-to-time time)))
  4316. (if (>= n 0)
  4317. (>= days n)
  4318. (<= days n))))
  4319. ;;;###autoload
  4320. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4321. (&optional end)
  4322. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4323. (when (or org-agenda-todo-ignore-with-date
  4324. org-agenda-todo-ignore-scheduled
  4325. org-agenda-todo-ignore-deadlines
  4326. org-agenda-todo-ignore-timestamp)
  4327. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4328. (save-excursion
  4329. (or (and org-agenda-todo-ignore-with-date
  4330. (re-search-forward org-ts-regexp end t))
  4331. (and org-agenda-todo-ignore-scheduled
  4332. (re-search-forward org-scheduled-time-regexp end t)
  4333. (cond
  4334. ((eq org-agenda-todo-ignore-scheduled 'future)
  4335. (> (org-days-to-time (match-string 1)) 0))
  4336. ((eq org-agenda-todo-ignore-scheduled 'past)
  4337. (<= (org-days-to-time (match-string 1)) 0))
  4338. ((numberp org-agenda-todo-ignore-scheduled)
  4339. (org-agenda-todo-custom-ignore-p
  4340. (match-string 1) org-agenda-todo-ignore-scheduled))
  4341. (t)))
  4342. (and org-agenda-todo-ignore-deadlines
  4343. (re-search-forward org-deadline-time-regexp end t)
  4344. (cond
  4345. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4346. ((eq org-agenda-todo-ignore-deadlines 'far)
  4347. (not (org-deadline-close (match-string 1))))
  4348. ((eq org-agenda-todo-ignore-deadlines 'future)
  4349. (> (org-days-to-time (match-string 1)) 0))
  4350. ((eq org-agenda-todo-ignore-deadlines 'past)
  4351. (<= (org-days-to-time (match-string 1)) 0))
  4352. ((numberp org-agenda-todo-ignore-deadlines)
  4353. (org-agenda-todo-custom-ignore-p
  4354. (match-string 1) org-agenda-todo-ignore-deadlines))
  4355. (t (org-deadline-close (match-string 1)))))
  4356. (and org-agenda-todo-ignore-timestamp
  4357. (let ((buffer (current-buffer))
  4358. (regexp
  4359. (concat
  4360. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4361. (start (point)))
  4362. ;; Copy current buffer into a temporary one
  4363. (with-temp-buffer
  4364. (insert-buffer-substring buffer start end)
  4365. (goto-char (point-min))
  4366. ;; Delete SCHEDULED and DEADLINE items
  4367. (while (re-search-forward regexp end t)
  4368. (delete-region (match-beginning 0) (match-end 0)))
  4369. (goto-char (point-min))
  4370. ;; No search for timestamp left
  4371. (when (re-search-forward org-ts-regexp nil t)
  4372. (cond
  4373. ((eq org-agenda-todo-ignore-timestamp 'future)
  4374. (> (org-days-to-time (match-string 1)) 0))
  4375. ((eq org-agenda-todo-ignore-timestamp 'past)
  4376. (<= (org-days-to-time (match-string 1)) 0))
  4377. ((numberp org-agenda-todo-ignore-timestamp)
  4378. (org-agenda-todo-custom-ignore-p
  4379. (match-string 1) org-agenda-todo-ignore-timestamp))
  4380. (t))))))))))
  4381. (defconst org-agenda-no-heading-message
  4382. "No heading for this item in buffer or region.")
  4383. (defun org-agenda-get-timestamps ()
  4384. "Return the date stamp information for agenda display."
  4385. (let* ((props (list 'face 'org-agenda-calendar-event
  4386. 'org-not-done-regexp org-not-done-regexp
  4387. 'org-todo-regexp org-todo-regexp
  4388. 'org-complex-heading-regexp org-complex-heading-regexp
  4389. 'mouse-face 'highlight
  4390. 'help-echo
  4391. (format "mouse-2 or RET jump to org file %s"
  4392. (abbreviate-file-name buffer-file-name))))
  4393. (d1 (calendar-absolute-from-gregorian date))
  4394. (remove-re
  4395. (concat
  4396. (regexp-quote
  4397. (format-time-string
  4398. "<%Y-%m-%d"
  4399. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4400. ".*?>"))
  4401. (regexp
  4402. (concat
  4403. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4404. (regexp-quote
  4405. (substring
  4406. (format-time-string
  4407. (car org-time-stamp-formats)
  4408. (apply 'encode-time ; DATE bound by calendar
  4409. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4410. 1 11))
  4411. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4412. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4413. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4414. donep tmp priority category org-category-pos ee txt timestr tags
  4415. b0 b3 e3 head todo-state end-of-match show-all)
  4416. (goto-char (point-min))
  4417. (while (setq end-of-match (re-search-forward regexp nil t))
  4418. (setq b0 (match-beginning 0)
  4419. b3 (match-beginning 3) e3 (match-end 3)
  4420. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4421. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4422. (member todo-state
  4423. org-agenda-repeating-timestamp-show-all)))
  4424. (catch :skip
  4425. (and (org-at-date-range-p) (throw :skip nil))
  4426. (org-agenda-skip)
  4427. (if (and (match-end 1)
  4428. (not (= d1 (org-time-string-to-absolute
  4429. (match-string 1) d1 nil show-all
  4430. (current-buffer) b0))))
  4431. (throw :skip nil))
  4432. (if (and e3
  4433. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4434. (throw :skip nil))
  4435. (setq tmp (buffer-substring (max (point-min)
  4436. (- b0 org-ds-keyword-length))
  4437. b0)
  4438. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4439. inactivep (= (char-after b0) ?\[)
  4440. deadlinep (string-match org-deadline-regexp tmp)
  4441. scheduledp (string-match org-scheduled-regexp tmp)
  4442. closedp (and org-agenda-include-inactive-timestamps
  4443. (string-match org-closed-string tmp))
  4444. clockp (and org-agenda-include-inactive-timestamps
  4445. (or (string-match org-clock-string tmp)
  4446. (string-match "]-+\\'" tmp)))
  4447. donep (member todo-state org-done-keywords))
  4448. (if (or scheduledp deadlinep closedp clockp
  4449. (and donep org-agenda-skip-timestamp-if-done))
  4450. (throw :skip t))
  4451. (if (string-match ">" timestr)
  4452. ;; substring should only run to end of time stamp
  4453. (setq timestr (substring timestr 0 (match-end 0))))
  4454. (setq marker (org-agenda-new-marker b0)
  4455. category (org-get-category b0)
  4456. org-category-pos (get-text-property b0 'org-category-position))
  4457. (save-excursion
  4458. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4459. (setq txt org-agenda-no-heading-message)
  4460. (goto-char (match-beginning 0))
  4461. (setq hdmarker (org-agenda-new-marker)
  4462. tags (org-get-tags-at))
  4463. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4464. (setq head (or (match-string 1) ""))
  4465. (setq txt (org-agenda-format-item
  4466. (if inactivep org-agenda-inactive-leader nil)
  4467. head category tags timestr
  4468. remove-re)))
  4469. (setq priority (org-get-priority txt))
  4470. (org-add-props txt props
  4471. 'org-marker marker 'org-hd-marker hdmarker)
  4472. (org-add-props txt nil 'priority priority
  4473. 'org-category category 'date date
  4474. 'org-category-position org-category-pos
  4475. 'todo-state todo-state
  4476. 'type "timestamp")
  4477. (push txt ee))
  4478. (if org-agenda-skip-additional-timestamps-same-entry
  4479. (outline-next-heading)
  4480. (goto-char end-of-match))))
  4481. (nreverse ee)))
  4482. (defun org-agenda-get-sexps ()
  4483. "Return the sexp information for agenda display."
  4484. (require 'diary-lib)
  4485. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4486. 'mouse-face 'highlight
  4487. 'help-echo
  4488. (format "mouse-2 or RET jump to org file %s"
  4489. (abbreviate-file-name buffer-file-name))))
  4490. (regexp "^&?%%(")
  4491. marker category org-category-pos ee txt tags entry
  4492. result beg b sexp sexp-entry todo-state)
  4493. (goto-char (point-min))
  4494. (while (re-search-forward regexp nil t)
  4495. (catch :skip
  4496. (org-agenda-skip)
  4497. (setq beg (match-beginning 0))
  4498. (goto-char (1- (match-end 0)))
  4499. (setq b (point))
  4500. (forward-sexp 1)
  4501. (setq sexp (buffer-substring b (point)))
  4502. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4503. (org-trim (match-string 1))
  4504. ""))
  4505. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4506. (when result
  4507. (setq marker (org-agenda-new-marker beg)
  4508. category (org-get-category beg)
  4509. org-category-pos (get-text-property beg 'org-category-position)
  4510. todo-state (org-get-todo-state))
  4511. (dolist (r (if (stringp result)
  4512. (list result)
  4513. result)) ;; we expect a list here
  4514. (if (string-match "\\S-" r)
  4515. (setq txt r)
  4516. (setq txt "SEXP entry returned empty string"))
  4517. (setq txt (org-agenda-format-item
  4518. "" txt category tags 'time))
  4519. (org-add-props txt props 'org-marker marker)
  4520. (org-add-props txt nil
  4521. 'org-category category 'date date 'todo-state todo-state
  4522. 'org-category-position org-category-pos
  4523. 'type "sexp")
  4524. (push txt ee)))))
  4525. (nreverse ee)))
  4526. ;; Calendar sanity: define some functions that are independent of
  4527. ;; `calendar-date-style'.
  4528. ;; Normally I would like to use ISO format when calling the diary functions,
  4529. ;; but to make sure we still have Emacs 22 compatibility we bind
  4530. ;; also `european-calendar-style' and use european format
  4531. (defun org-anniversary (year month day &optional mark)
  4532. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4533. (org-no-warnings
  4534. (let ((calendar-date-style 'european) (european-calendar-style t))
  4535. (diary-anniversary day month year mark))))
  4536. (defun org-cyclic (N year month day &optional mark)
  4537. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4538. (org-no-warnings
  4539. (let ((calendar-date-style 'european) (european-calendar-style t))
  4540. (diary-cyclic N day month year mark))))
  4541. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4542. "Like `diary-block', but with fixed (ISO) order of arguments."
  4543. (org-no-warnings
  4544. (let ((calendar-date-style 'european) (european-calendar-style t))
  4545. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4546. (defun org-date (year month day &optional mark)
  4547. "Like `diary-date', but with fixed (ISO) order of arguments."
  4548. (org-no-warnings
  4549. (let ((calendar-date-style 'european) (european-calendar-style t))
  4550. (diary-date day month year mark))))
  4551. (defalias 'org-float 'diary-float)
  4552. ;; Define the` org-class' function
  4553. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4554. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4555. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4556. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4557. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4558. `holidays', then any date that is known by the Emacs calendar to be a
  4559. holiday will also be skipped."
  4560. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4561. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4562. (d (calendar-absolute-from-gregorian date)))
  4563. (and
  4564. (<= date1 d)
  4565. (<= d date2)
  4566. (= (calendar-day-of-week date) dayname)
  4567. (or (not skip-weeks)
  4568. (progn
  4569. (require 'cal-iso)
  4570. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4571. (not (and (memq 'holidays skip-weeks)
  4572. (calendar-check-holidays date)))
  4573. entry)))
  4574. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4575. "Like `org-class', but honor `calendar-date-style'.
  4576. The order of the first 2 times 3 arguments depends on the variable
  4577. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4578. So for American calendars, give this as MONTH DAY YEAR, for European as
  4579. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4580. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4581. is any number of ISO weeks in the block period for which the item should
  4582. be skipped.
  4583. This function is here only for backward compatibility and it is deprecated,
  4584. please use `org-class' instead."
  4585. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4586. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4587. (org-class
  4588. (nth 2 date1) (car date1) (nth 1 date1)
  4589. (nth 2 date2) (car date2) (nth 1 date2)
  4590. dayname skip-weeks)))
  4591. (make-obsolete 'org-diary-class 'org-class "")
  4592. (defalias 'org-get-closed 'org-agenda-get-progress)
  4593. (defun org-agenda-get-progress ()
  4594. "Return the logged TODO entries for agenda display."
  4595. (let* ((props (list 'mouse-face 'highlight
  4596. 'org-not-done-regexp org-not-done-regexp
  4597. 'org-todo-regexp org-todo-regexp
  4598. 'org-complex-heading-regexp org-complex-heading-regexp
  4599. 'help-echo
  4600. (format "mouse-2 or RET jump to org file %s"
  4601. (abbreviate-file-name buffer-file-name))))
  4602. (items (if (consp org-agenda-show-log)
  4603. org-agenda-show-log
  4604. (if (eq org-agenda-show-log 'clockcheck)
  4605. '(clock)
  4606. org-agenda-log-mode-items)))
  4607. (parts
  4608. (delq nil
  4609. (list
  4610. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4611. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4612. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4613. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4614. (error "`org-agenda-log-mode-items' is empty")))
  4615. (regexp (concat
  4616. "\\(" parts-re "\\)"
  4617. " *\\["
  4618. (regexp-quote
  4619. (substring
  4620. (format-time-string
  4621. (car org-time-stamp-formats)
  4622. (apply 'encode-time ; DATE bound by calendar
  4623. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4624. 1 11))))
  4625. (org-agenda-search-headline-for-time nil)
  4626. marker hdmarker priority category org-category-pos tags closedp
  4627. statep clockp state ee txt extra timestr rest clocked)
  4628. (goto-char (point-min))
  4629. (while (re-search-forward regexp nil t)
  4630. (catch :skip
  4631. (org-agenda-skip)
  4632. (setq marker (org-agenda-new-marker (match-beginning 0))
  4633. closedp (equal (match-string 1) org-closed-string)
  4634. statep (equal (string-to-char (match-string 1)) ?-)
  4635. clockp (not (or closedp statep))
  4636. state (and statep (match-string 2))
  4637. category (org-get-category (match-beginning 0))
  4638. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4639. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4640. (when (string-match "\\]" timestr)
  4641. ;; substring should only run to end of time stamp
  4642. (setq rest (substring timestr (match-end 0))
  4643. timestr (substring timestr 0 (match-end 0)))
  4644. (if (and (not closedp) (not statep)
  4645. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4646. rest))
  4647. (progn (setq timestr (concat (substring timestr 0 -1)
  4648. "-" (match-string 1 rest) "]"))
  4649. (setq clocked (match-string 2 rest)))
  4650. (setq clocked "-")))
  4651. (save-excursion
  4652. (setq extra
  4653. (cond
  4654. ((not org-agenda-log-mode-add-notes) nil)
  4655. (statep
  4656. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4657. (match-string 1)))
  4658. (clockp
  4659. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4660. (match-string 1)))))
  4661. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4662. (setq txt org-agenda-no-heading-message)
  4663. (goto-char (match-beginning 0))
  4664. (setq hdmarker (org-agenda-new-marker)
  4665. tags (org-get-tags-at))
  4666. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4667. (setq txt (match-string 1))
  4668. (when extra
  4669. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4670. (setq txt (concat (substring txt 0 (match-beginning 1))
  4671. " - " extra " " (match-string 2 txt)))
  4672. (setq txt (concat txt " - " extra))))
  4673. (setq txt (org-agenda-format-item
  4674. (cond
  4675. (closedp "Closed: ")
  4676. (statep (concat "State: (" state ")"))
  4677. (t (concat "Clocked: (" clocked ")")))
  4678. txt category tags timestr)))
  4679. (setq priority 100000)
  4680. (org-add-props txt props
  4681. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4682. 'priority priority 'org-category category
  4683. 'org-category-position org-category-pos
  4684. 'type "closed" 'date date
  4685. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4686. (push txt ee))
  4687. (goto-char (point-at-eol))))
  4688. (nreverse ee)))
  4689. (defun org-agenda-show-clocking-issues ()
  4690. "Add overlays, showing issues with clocking.
  4691. See also the user option `org-agenda-clock-consistency-checks'."
  4692. (interactive)
  4693. (let* ((pl org-agenda-clock-consistency-checks)
  4694. (re (concat "^[ \t]*"
  4695. org-clock-string
  4696. "[ \t]+"
  4697. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4698. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4699. (tlstart 0.)
  4700. (tlend 0.)
  4701. (maxtime (org-hh:mm-string-to-minutes
  4702. (or (plist-get pl :max-duration) "24:00")))
  4703. (mintime (org-hh:mm-string-to-minutes
  4704. (or (plist-get pl :min-duration) 0)))
  4705. (maxgap (org-hh:mm-string-to-minutes
  4706. ;; default 30:00 means never complain
  4707. (or (plist-get pl :max-gap) "30:00")))
  4708. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4709. (plist-get pl :gap-ok-around)))
  4710. (def-face (or (plist-get pl :default-face)
  4711. '((:background "DarkRed") (:foreground "white"))))
  4712. issue face m te ts dt ov)
  4713. (goto-char (point-min))
  4714. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4715. (setq issue nil face def-face)
  4716. (catch 'next
  4717. (setq m (org-get-at-bol 'org-marker)
  4718. te nil ts nil)
  4719. (unless (and m (markerp m))
  4720. (setq issue "No valid clock line") (throw 'next t))
  4721. (org-with-point-at m
  4722. (save-excursion
  4723. (goto-char (point-at-bol))
  4724. (unless (looking-at re)
  4725. (error "No valid Clock line")
  4726. (throw 'next t))
  4727. (unless (match-end 3)
  4728. (setq issue "No end time"
  4729. face (or (plist-get pl :no-end-time-face) face))
  4730. (throw 'next t))
  4731. (setq ts (match-string 1)
  4732. te (match-string 3)
  4733. ts (org-float-time
  4734. (apply 'encode-time (org-parse-time-string ts)))
  4735. te (org-float-time
  4736. (apply 'encode-time (org-parse-time-string te)))
  4737. dt (- te ts))))
  4738. (cond
  4739. ((> dt (* 60 maxtime))
  4740. ;; a very long clocking chunk
  4741. (setq issue (format "Clocking interval is very long: %s"
  4742. (org-minutes-to-hh:mm-string
  4743. (floor (/ (float dt) 60.))))
  4744. face (or (plist-get pl :long-face) face)))
  4745. ((< dt (* 60 mintime))
  4746. ;; a very short clocking chunk
  4747. (setq issue (format "Clocking interval is very short: %s"
  4748. (org-minutes-to-hh:mm-string
  4749. (floor (/ (float dt) 60.))))
  4750. face (or (plist-get pl :short-face) face)))
  4751. ((and (> tlend 0) (< ts tlend))
  4752. ;; Two clock entries are overlapping
  4753. (setq issue (format "Clocking overlap: %d minutes"
  4754. (/ (- tlend ts) 60))
  4755. face (or (plist-get pl :overlap-face) face)))
  4756. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4757. ;; There is a gap, lets see if we need to report it
  4758. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4759. (setq issue (format "Clocking gap: %d minutes"
  4760. (/ (- ts tlend) 60))
  4761. face (or (plist-get pl :gap-face) face))))
  4762. (t nil)))
  4763. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4764. (when issue
  4765. ;; OK, there was some issue, add an overlay to show the issue
  4766. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4767. (overlay-put ov 'before-string
  4768. (concat
  4769. (org-add-props
  4770. (format "%-43s" (concat " " issue))
  4771. nil
  4772. 'face face)
  4773. "\n"))
  4774. (overlay-put ov 'evaporate t)))))
  4775. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4776. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4777. (catch 'exit
  4778. (unless ok-list
  4779. ;; there are no OK times for gaps...
  4780. (throw 'exit nil))
  4781. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4782. ;; This is more than 24 hours, so it is OK.
  4783. ;; because we have at least one OK time, that must be in the
  4784. ;; 24 hour interval.
  4785. (throw 'exit t))
  4786. ;; We have a shorter gap.
  4787. ;; Now we have to get the minute of the day when these times are
  4788. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4789. (t2dec (decode-time (seconds-to-time t2)))
  4790. ;; compute the minute on the day
  4791. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4792. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4793. (when (< min2 min1)
  4794. ;; if min2 is smaller than min1, this means it is on the next day.
  4795. ;; Wrap it to after midnight.
  4796. (setq min2 (+ min2 1440)))
  4797. ;; Now check if any of the OK times is in the gap
  4798. (mapc (lambda (x)
  4799. ;; Wrap the time to after midnight if necessary
  4800. (if (< x min1) (setq x (+ x 1440)))
  4801. ;; Check if in interval
  4802. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4803. ok-list)
  4804. ;; Nope, this gap is not OK
  4805. nil)))
  4806. (defun org-agenda-get-deadlines ()
  4807. "Return the deadline information for agenda display."
  4808. (let* ((props (list 'mouse-face 'highlight
  4809. 'org-not-done-regexp org-not-done-regexp
  4810. 'org-todo-regexp org-todo-regexp
  4811. 'org-complex-heading-regexp org-complex-heading-regexp
  4812. 'help-echo
  4813. (format "mouse-2 or RET jump to org file %s"
  4814. (abbreviate-file-name buffer-file-name))))
  4815. (regexp org-deadline-time-regexp)
  4816. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4817. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4818. d2 diff dfrac wdays pos pos1 category org-category-pos
  4819. tags suppress-prewarning ee txt head face s todo-state
  4820. show-all upcomingp donep timestr)
  4821. (goto-char (point-min))
  4822. (while (re-search-forward regexp nil t)
  4823. (setq suppress-prewarning nil)
  4824. (catch :skip
  4825. (org-agenda-skip)
  4826. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4827. (save-match-data
  4828. (string-match org-scheduled-time-regexp
  4829. (buffer-substring (point-at-bol)
  4830. (point-at-eol)))))
  4831. (setq suppress-prewarning
  4832. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4833. org-agenda-skip-deadline-prewarning-if-scheduled
  4834. 0)))
  4835. (setq s (match-string 1)
  4836. txt nil
  4837. pos (1- (match-beginning 1))
  4838. todo-state (save-match-data (org-get-todo-state))
  4839. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4840. (member todo-state
  4841. org-agenda-repeating-timestamp-show-all))
  4842. d2 (org-time-string-to-absolute
  4843. (match-string 1) d1 'past show-all
  4844. (current-buffer) pos)
  4845. diff (- d2 d1)
  4846. wdays (if suppress-prewarning
  4847. (let ((org-deadline-warning-days suppress-prewarning))
  4848. (org-get-wdays s))
  4849. (org-get-wdays s))
  4850. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4851. upcomingp (and todayp (> diff 0)))
  4852. ;; When to show a deadline in the calendar:
  4853. ;; If the expiration is within wdays warning time.
  4854. ;; Past-due deadlines are only shown on the current date
  4855. (if (and (or (and (<= diff wdays)
  4856. (and todayp (not org-agenda-only-exact-dates)))
  4857. (= diff 0)))
  4858. (save-excursion
  4859. ;; (setq todo-state (org-get-todo-state))
  4860. (setq donep (member todo-state org-done-keywords))
  4861. (if (and donep
  4862. (or org-agenda-skip-deadline-if-done
  4863. (not (= diff 0))))
  4864. (setq txt nil)
  4865. (setq category (org-get-category)
  4866. org-category-pos (get-text-property (point) 'org-category-position))
  4867. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4868. (setq txt org-agenda-no-heading-message)
  4869. (goto-char (match-end 0))
  4870. (setq pos1 (match-beginning 0))
  4871. (setq tags (org-get-tags-at pos1))
  4872. (setq head (buffer-substring-no-properties
  4873. (point)
  4874. (progn (skip-chars-forward "^\r\n")
  4875. (point))))
  4876. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4877. (setq timestr
  4878. (concat (substring s (match-beginning 1)) " "))
  4879. (setq timestr 'time))
  4880. (setq txt (org-agenda-format-item
  4881. (if (= diff 0)
  4882. (car org-agenda-deadline-leaders)
  4883. (if (functionp
  4884. (nth 1 org-agenda-deadline-leaders))
  4885. (funcall
  4886. (nth 1 org-agenda-deadline-leaders)
  4887. diff date)
  4888. (format (nth 1 org-agenda-deadline-leaders)
  4889. diff)))
  4890. head category tags
  4891. (if (not (= diff 0)) nil timestr)))))
  4892. (when txt
  4893. (setq face (org-agenda-deadline-face dfrac))
  4894. (org-add-props txt props
  4895. 'org-marker (org-agenda-new-marker pos)
  4896. 'org-hd-marker (org-agenda-new-marker pos1)
  4897. 'priority (+ (- diff)
  4898. (org-get-priority txt))
  4899. 'org-category category
  4900. 'org-category-position org-category-pos
  4901. 'todo-state todo-state
  4902. 'type (if upcomingp "upcoming-deadline" "deadline")
  4903. 'date (if upcomingp date d2)
  4904. 'face (if donep 'org-agenda-done face)
  4905. 'undone-face face 'done-face 'org-agenda-done)
  4906. (push txt ee))))))
  4907. (nreverse ee)))
  4908. (defun org-agenda-deadline-face (fraction)
  4909. "Return the face to displaying a deadline item.
  4910. FRACTION is what fraction of the head-warning time has passed."
  4911. (let ((faces org-agenda-deadline-faces) f)
  4912. (catch 'exit
  4913. (while (setq f (pop faces))
  4914. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4915. (defun org-agenda-get-scheduled (&optional deadline-results)
  4916. "Return the scheduled information for agenda display."
  4917. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4918. 'org-todo-regexp org-todo-regexp
  4919. 'org-complex-heading-regexp org-complex-heading-regexp
  4920. 'done-face 'org-agenda-done
  4921. 'mouse-face 'highlight
  4922. 'help-echo
  4923. (format "mouse-2 or RET jump to org file %s"
  4924. (abbreviate-file-name buffer-file-name))))
  4925. (regexp org-scheduled-time-regexp)
  4926. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4927. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4928. mm
  4929. (deadline-position-alist
  4930. (mapcar (lambda (a) (and (setq mm (get-text-property
  4931. 0 'org-hd-marker a))
  4932. (cons (marker-position mm) a)))
  4933. deadline-results))
  4934. d2 diff pos pos1 category org-category-pos tags donep
  4935. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4936. (goto-char (point-min))
  4937. (while (re-search-forward regexp nil t)
  4938. (catch :skip
  4939. (org-agenda-skip)
  4940. (setq s (match-string 1)
  4941. txt nil
  4942. pos (1- (match-beginning 1))
  4943. todo-state (save-match-data (org-get-todo-state))
  4944. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4945. (member todo-state
  4946. org-agenda-repeating-timestamp-show-all))
  4947. d2 (org-time-string-to-absolute
  4948. (match-string 1) d1 'past show-all
  4949. (current-buffer) pos)
  4950. diff (- d2 d1))
  4951. (setq pastschedp (and todayp (< diff 0)))
  4952. ;; When to show a scheduled item in the calendar:
  4953. ;; If it is on or past the date.
  4954. (when (or (and (< diff 0)
  4955. (< (abs diff) org-scheduled-past-days)
  4956. (and todayp (not org-agenda-only-exact-dates)))
  4957. (= diff 0))
  4958. (save-excursion
  4959. (setq donep (member todo-state org-done-keywords))
  4960. (if (and donep
  4961. (or org-agenda-skip-scheduled-if-done
  4962. (not (= diff 0))
  4963. (and (functionp 'org-is-habit-p)
  4964. (org-is-habit-p))))
  4965. (setq txt nil)
  4966. (setq habitp (and (functionp 'org-is-habit-p)
  4967. (org-is-habit-p)))
  4968. (setq category (org-get-category)
  4969. org-category-pos (get-text-property (point) 'org-category-position))
  4970. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4971. (setq txt org-agenda-no-heading-message)
  4972. (goto-char (match-end 0))
  4973. (setq pos1 (match-beginning 0))
  4974. (if habitp
  4975. (if (or (not org-habit-show-habits)
  4976. (and (not todayp)
  4977. org-habit-show-habits-only-for-today))
  4978. (throw :skip nil))
  4979. (if (and
  4980. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4981. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4982. pastschedp))
  4983. (setq mm (assoc pos1 deadline-position-alist)))
  4984. (throw :skip nil)))
  4985. (setq tags (org-get-tags-at))
  4986. (setq head (buffer-substring-no-properties
  4987. (point)
  4988. (progn (skip-chars-forward "^\r\n") (point))))
  4989. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4990. (setq timestr
  4991. (concat (substring s (match-beginning 1)) " "))
  4992. (setq timestr 'time))
  4993. (setq txt (org-agenda-format-item
  4994. (if (= diff 0)
  4995. (car org-agenda-scheduled-leaders)
  4996. (format (nth 1 org-agenda-scheduled-leaders)
  4997. (- 1 diff)))
  4998. head category tags
  4999. (if (not (= diff 0)) nil timestr)
  5000. nil habitp))))
  5001. (when txt
  5002. (setq face
  5003. (cond
  5004. ((and (not habitp) pastschedp)
  5005. 'org-scheduled-previously)
  5006. (todayp 'org-scheduled-today)
  5007. (t 'org-scheduled))
  5008. habitp (and habitp (org-habit-parse-todo)))
  5009. (org-add-props txt props
  5010. 'undone-face face
  5011. 'face (if donep 'org-agenda-done face)
  5012. 'org-marker (org-agenda-new-marker pos)
  5013. 'org-hd-marker (org-agenda-new-marker pos1)
  5014. 'type (if pastschedp "past-scheduled" "scheduled")
  5015. 'date (if pastschedp d2 date)
  5016. 'priority (if habitp
  5017. (org-habit-get-priority habitp)
  5018. (+ 94 (- 5 diff) (org-get-priority txt)))
  5019. 'org-category category
  5020. 'org-category-position org-category-pos
  5021. 'org-habit-p habitp
  5022. 'todo-state todo-state)
  5023. (push txt ee))))))
  5024. (nreverse ee)))
  5025. (defun org-agenda-get-blocks ()
  5026. "Return the date-range information for agenda display."
  5027. (let* ((props (list 'face nil
  5028. 'org-not-done-regexp org-not-done-regexp
  5029. 'org-todo-regexp org-todo-regexp
  5030. 'org-complex-heading-regexp org-complex-heading-regexp
  5031. 'mouse-face 'highlight
  5032. 'help-echo
  5033. (format "mouse-2 or RET jump to org file %s"
  5034. (abbreviate-file-name buffer-file-name))))
  5035. (regexp org-tr-regexp)
  5036. (d0 (calendar-absolute-from-gregorian date))
  5037. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5038. todo-state tags pos head donep)
  5039. (goto-char (point-min))
  5040. (while (re-search-forward regexp nil t)
  5041. (catch :skip
  5042. (org-agenda-skip)
  5043. (setq pos (point))
  5044. (let ((start-time (match-string 1))
  5045. (end-time (match-string 2)))
  5046. (setq s1 (match-string 1)
  5047. s2 (match-string 2)
  5048. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5049. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5050. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5051. ;; Only allow days between the limits, because the normal
  5052. ;; date stamps will catch the limits.
  5053. (save-excursion
  5054. (setq todo-state (org-get-todo-state))
  5055. (setq donep (member todo-state org-done-keywords))
  5056. (if (and donep org-agenda-skip-timestamp-if-done)
  5057. (throw :skip t))
  5058. (setq marker (org-agenda-new-marker (point)))
  5059. (setq category (org-get-category)
  5060. org-category-pos (get-text-property (point) 'org-category-position))
  5061. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5062. (setq txt org-agenda-no-heading-message)
  5063. (goto-char (match-beginning 0))
  5064. (setq hdmarker (org-agenda-new-marker (point)))
  5065. (setq tags (org-get-tags-at))
  5066. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5067. (setq head (match-string 1))
  5068. (let ((remove-re
  5069. (if org-agenda-remove-timeranges-from-blocks
  5070. (concat
  5071. "<" (regexp-quote s1) ".*?>"
  5072. "--"
  5073. "<" (regexp-quote s2) ".*?>")
  5074. nil)))
  5075. (setq txt (org-agenda-format-item
  5076. (format
  5077. (nth (if (= d1 d2) 0 1)
  5078. org-agenda-timerange-leaders)
  5079. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5080. head category tags
  5081. (cond ((and (= d1 d0) (= d2 d0))
  5082. (concat "<" start-time ">--<" end-time ">"))
  5083. ((= d1 d0)
  5084. (concat "<" start-time ">"))
  5085. ((= d2 d0)
  5086. (concat "<" end-time ">"))
  5087. (t nil))
  5088. remove-re))))
  5089. (org-add-props txt props
  5090. 'org-marker marker 'org-hd-marker hdmarker
  5091. 'type "block" 'date date
  5092. 'todo-state todo-state
  5093. 'priority (org-get-priority txt) 'org-category category
  5094. 'org-category-position org-category-pos)
  5095. (push txt ee))))
  5096. (goto-char pos)))
  5097. ;; Sort the entries by expiration date.
  5098. (nreverse ee)))
  5099. ;;; Agenda presentation and sorting
  5100. (defvar org-prefix-has-time nil
  5101. "A flag, set by `org-compile-prefix-format'.
  5102. The flag is set if the currently compiled format contains a `%t'.")
  5103. (defvar org-prefix-has-tag nil
  5104. "A flag, set by `org-compile-prefix-format'.
  5105. The flag is set if the currently compiled format contains a `%T'.")
  5106. (defvar org-prefix-has-effort nil
  5107. "A flag, set by `org-compile-prefix-format'.
  5108. The flag is set if the currently compiled format contains a `%e'.")
  5109. (defvar org-prefix-category-length nil
  5110. "Used by `org-compile-prefix-format' to remember the category field width.")
  5111. (defvar org-prefix-category-max-length nil
  5112. "Used by `org-compile-prefix-format' to remember the category field width.")
  5113. (defun org-agenda-get-category-icon (category)
  5114. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5115. (dolist (entry org-agenda-category-icon-alist)
  5116. (when (org-string-match-p (car entry) category)
  5117. (if (listp (cadr entry))
  5118. (return (cadr entry))
  5119. (return (apply 'create-image (cdr entry)))))))
  5120. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5121. remove-re habitp)
  5122. "Format TXT to be inserted into the agenda buffer.
  5123. In particular, it adds the prefix and corresponding text properties. EXTRA
  5124. must be a string and replaces the `%s' specifier in the prefix format.
  5125. CATEGORY (string, symbol or nil) may be used to overrule the default
  5126. category taken from local variable or file name. It will replace the `%c'
  5127. specifier in the format. DOTIME, when non-nil, indicates that a
  5128. time-of-day should be extracted from TXT for sorting of this entry, and for
  5129. the `%t' specifier in the format. When DOTIME is a string, this string is
  5130. searched for a time before TXT is. TAGS can be the tags of the headline.
  5131. Any match of REMOVE-RE will be removed from TXT."
  5132. (save-match-data
  5133. ;; Diary entries sometimes have extra whitespace at the beginning
  5134. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5135. ;; Fix the tags part in txt
  5136. (setq txt (org-agenda-fix-displayed-tags
  5137. txt tags
  5138. org-agenda-show-inherited-tags
  5139. org-agenda-hide-tags-regexp))
  5140. (let* ((category (or category
  5141. (if (stringp org-category)
  5142. org-category
  5143. (and org-category (symbol-name org-category)))
  5144. (if buffer-file-name
  5145. (file-name-sans-extension
  5146. (file-name-nondirectory buffer-file-name))
  5147. "")))
  5148. (category-icon (org-agenda-get-category-icon category))
  5149. (category-icon (if category-icon
  5150. (propertize " " 'display category-icon)
  5151. ""))
  5152. ;; time, tag, effort are needed for the eval of the prefix format
  5153. (tag (if tags (nth (1- (length tags)) tags) ""))
  5154. time effort neffort
  5155. (ts (if dotime (concat
  5156. (if (stringp dotime) dotime "")
  5157. (and org-agenda-search-headline-for-time txt))))
  5158. (time-of-day (and dotime (org-get-time-of-day ts)))
  5159. stamp plain s0 s1 s2 rtn srp l
  5160. duration thecategory)
  5161. (and (eq major-mode 'org-mode) buffer-file-name
  5162. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5163. (when (and dotime time-of-day)
  5164. ;; Extract starting and ending time and move them to prefix
  5165. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5166. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5167. (setq s0 (match-string 0 ts)
  5168. srp (and stamp (match-end 3))
  5169. s1 (match-string (if plain 1 2) ts)
  5170. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5171. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5172. ;; them, we might want to remove them there to avoid duplication.
  5173. ;; The user can turn this off with a variable.
  5174. (if (and org-prefix-has-time
  5175. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5176. (string-match (concat (regexp-quote s0) " *") txt)
  5177. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5178. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5179. (= (match-beginning 0) 0)
  5180. t))
  5181. (setq txt (replace-match "" nil nil txt))))
  5182. ;; Normalize the time(s) to 24 hour
  5183. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5184. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5185. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5186. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5187. (setq s2
  5188. (org-minutes-to-hh:mm-string
  5189. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5190. ;; Compute the duration
  5191. (when s2
  5192. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5193. (org-hh:mm-string-to-minutes s1)))))
  5194. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5195. txt)
  5196. ;; Tags are in the string
  5197. (if (or (eq org-agenda-remove-tags t)
  5198. (and org-agenda-remove-tags
  5199. org-prefix-has-tag))
  5200. (setq txt (replace-match "" t t txt))
  5201. (setq txt (replace-match
  5202. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5203. (match-string 2 txt))
  5204. t t txt))))
  5205. (when (eq major-mode 'org-mode)
  5206. (setq effort
  5207. (condition-case nil
  5208. (org-get-effort
  5209. (or (get-text-property 0 'org-hd-marker txt)
  5210. (get-text-property 0 'org-marker txt)))
  5211. (error nil)))
  5212. (when effort
  5213. (setq neffort (org-duration-string-to-minutes effort)
  5214. effort (setq effort (concat "[" effort "]")))))
  5215. ;; prevent erroring out with %e format when there is no effort
  5216. (or effort (setq effort ""))
  5217. (when remove-re
  5218. (while (string-match remove-re txt)
  5219. (setq txt (replace-match "" t t txt))))
  5220. ;; Set org-heading property on `txt' to mark the start of the
  5221. ;; heading.
  5222. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5223. ;; Prepare the variables needed in the eval of the compiled format
  5224. (setq time (cond (s2 (concat
  5225. (org-agenda-time-of-day-to-ampm-maybe s1)
  5226. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5227. (if org-agenda-timegrid-use-ampm " ")))
  5228. (s1 (concat
  5229. (org-agenda-time-of-day-to-ampm-maybe s1)
  5230. (if org-agenda-timegrid-use-ampm
  5231. "........ "
  5232. "......")))
  5233. (t ""))
  5234. extra (or (and (not habitp) extra) "")
  5235. category (if (symbolp category) (symbol-name category) category)
  5236. thecategory (copy-sequence category))
  5237. (if (string-match org-bracket-link-regexp category)
  5238. (progn
  5239. (setq l (if (match-end 3)
  5240. (- (match-end 3) (match-beginning 3))
  5241. (- (match-end 1) (match-beginning 1))))
  5242. (when (< l (or org-prefix-category-length 0))
  5243. (setq category (copy-sequence category))
  5244. (org-add-props category nil
  5245. 'extra-space (make-string
  5246. (- org-prefix-category-length l 1) ?\ ))))
  5247. (if (and org-prefix-category-max-length
  5248. (>= (length category) org-prefix-category-max-length))
  5249. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5250. ;; Evaluate the compiled format
  5251. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5252. ;; And finally add the text properties
  5253. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5254. (org-add-props rtn nil
  5255. 'org-category (if thecategory (downcase thecategory) category)
  5256. 'tags (mapcar 'org-downcase-keep-props tags)
  5257. 'org-highest-priority org-highest-priority
  5258. 'org-lowest-priority org-lowest-priority
  5259. 'time-of-day time-of-day
  5260. 'duration duration
  5261. 'effort effort
  5262. 'effort-minutes neffort
  5263. 'txt txt
  5264. 'time time
  5265. 'extra extra
  5266. 'format org-prefix-format-compiled
  5267. 'dotime dotime))))
  5268. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5269. "Remove tags string from TXT, and add a modified list of tags.
  5270. The modified list may contain inherited tags, and tags matched by
  5271. `org-agenda-hide-tags-regexp' will be removed."
  5272. (when (or add-inherited hide-re)
  5273. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5274. (setq txt (substring txt 0 (match-beginning 0))))
  5275. (setq tags
  5276. (delq nil
  5277. (mapcar (lambda (tg)
  5278. (if (or (and hide-re (string-match hide-re tg))
  5279. (and (not add-inherited)
  5280. (get-text-property 0 'inherited tg)))
  5281. nil
  5282. tg))
  5283. tags)))
  5284. (when tags
  5285. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5286. i)
  5287. (setq txt (concat txt " :"
  5288. (mapconcat
  5289. (lambda (x)
  5290. (setq i (get-text-property 0 'inherited x))
  5291. (if (and have-i (not i))
  5292. (progn
  5293. (setq have-i nil)
  5294. (concat ":" x))
  5295. x))
  5296. tags ":")
  5297. (if have-i "::" ":"))))))
  5298. txt)
  5299. (defun org-downcase-keep-props (s)
  5300. (let ((props (text-properties-at 0 s)))
  5301. (setq s (downcase s))
  5302. (add-text-properties 0 (length s) props s)
  5303. s))
  5304. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5305. (defvar org-agenda-sorting-strategy-selected nil)
  5306. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5307. (catch 'exit
  5308. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5309. ((and todayp (member 'today (car org-agenda-time-grid))))
  5310. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5311. ((member 'weekly (car org-agenda-time-grid)))
  5312. (t (throw 'exit list)))
  5313. (let* ((have (delq nil (mapcar
  5314. (lambda (x) (get-text-property 1 'time-of-day x))
  5315. list)))
  5316. (string (nth 1 org-agenda-time-grid))
  5317. (gridtimes (nth 2 org-agenda-time-grid))
  5318. (req (car org-agenda-time-grid))
  5319. (remove (member 'remove-match req))
  5320. new time)
  5321. (if (and (member 'require-timed req) (not have))
  5322. ;; don't show empty grid
  5323. (throw 'exit list))
  5324. (while (setq time (pop gridtimes))
  5325. (unless (and remove (member time have))
  5326. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5327. (push (org-agenda-format-item
  5328. nil string "" nil
  5329. (concat (substring time 0 -2) ":" (substring time -2)))
  5330. new)
  5331. (put-text-property
  5332. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5333. (when (and todayp org-agenda-show-current-time-in-grid)
  5334. (push (org-agenda-format-item
  5335. nil
  5336. org-agenda-current-time-string
  5337. "" nil
  5338. (format-time-string "%H:%M "))
  5339. new)
  5340. (put-text-property
  5341. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5342. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5343. (append new list)
  5344. (append list new)))))
  5345. (defun org-compile-prefix-format (key)
  5346. "Compile the prefix format into a Lisp form that can be evaluated.
  5347. The resulting form is returned and stored in the variable
  5348. `org-prefix-format-compiled'."
  5349. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5350. org-prefix-category-length nil
  5351. org-prefix-has-effort nil)
  5352. (let ((s (cond
  5353. ((stringp org-agenda-prefix-format)
  5354. org-agenda-prefix-format)
  5355. ((assq key org-agenda-prefix-format)
  5356. (cdr (assq key org-agenda-prefix-format)))
  5357. (t " %-12:c%?-12t% s")))
  5358. (start 0)
  5359. varform vars var e c f opt)
  5360. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5361. s start)
  5362. (setq var (or (cdr (assoc (match-string 4 s)
  5363. '(("c" . category) ("t" . time) ("s" . extra)
  5364. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5365. 'eval)
  5366. c (or (match-string 3 s) "")
  5367. opt (match-beginning 1)
  5368. start (1+ (match-beginning 0)))
  5369. (if (equal var 'time) (setq org-prefix-has-time t))
  5370. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5371. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5372. (setq f (concat "%" (match-string 2 s) "s"))
  5373. (when (equal var 'category)
  5374. (setq org-prefix-category-length
  5375. (floor (abs (string-to-number (match-string 2 s)))))
  5376. (setq org-prefix-category-max-length
  5377. (let ((x (match-string 2 s)))
  5378. (save-match-data
  5379. (if (string-match "\\.[0-9]+" x)
  5380. (string-to-number (substring (match-string 0 x) 1)))))))
  5381. (if (eq var 'eval)
  5382. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5383. (if opt
  5384. (setq varform
  5385. `(if (equal "" ,var)
  5386. ""
  5387. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5388. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5389. (setq s (replace-match "%s" t nil s))
  5390. (push varform vars))
  5391. (setq vars (nreverse vars))
  5392. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5393. (defun org-set-sorting-strategy (key)
  5394. (if (symbolp (car org-agenda-sorting-strategy))
  5395. ;; the old format
  5396. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5397. (setq org-agenda-sorting-strategy-selected
  5398. (or (cdr (assq key org-agenda-sorting-strategy))
  5399. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5400. '(time-up category-keep priority-down)))))
  5401. (defun org-get-time-of-day (s &optional string mod24)
  5402. "Check string S for a time of day.
  5403. If found, return it as a military time number between 0 and 2400.
  5404. If not found, return nil.
  5405. The optional STRING argument forces conversion into a 5 character wide string
  5406. HH:MM."
  5407. (save-match-data
  5408. (when
  5409. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5410. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5411. (let* ((h (string-to-number (match-string 1 s)))
  5412. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5413. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5414. (am-p (equal ampm "am"))
  5415. (h1 (cond ((not ampm) h)
  5416. ((= h 12) (if am-p 0 12))
  5417. (t (+ h (if am-p 0 12)))))
  5418. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5419. (mod h1 24) h1))
  5420. (t0 (+ (* 100 h2) m))
  5421. (t1 (concat (if (>= h1 24) "+" " ")
  5422. (if (and org-agenda-time-leading-zero
  5423. (< t0 1000)) "0" "")
  5424. (if (< t0 100) "0" "")
  5425. (if (< t0 10) "0" "")
  5426. (int-to-string t0))))
  5427. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5428. (defvar org-agenda-before-sorting-filter-function nil
  5429. "Function to be applied to agenda items prior to sorting.
  5430. Prior to sorting also means just before they are inserted into the agenda.
  5431. To aid sorting, you may revisit the original entries and add more text
  5432. properties which will later be used by the sorting functions.
  5433. The function should take a string argument, an agenda line.
  5434. It has access to the text properties in that line, which contain among
  5435. other things, the property `org-hd-marker' that points to the entry
  5436. where the line comes from. Note that not all lines going into the agenda
  5437. have this property, only most.
  5438. The function should return the modified string. It is probably best
  5439. to ONLY change text properties.
  5440. You can also use this function as a filter, by returning nil for lines
  5441. you don't want to have in the agenda at all. For this application, you
  5442. could bind the variable in the options section of a custom command.")
  5443. (defun org-finalize-agenda-entries (list &optional nosort)
  5444. "Sort and concatenate the agenda items."
  5445. (setq list (mapcar 'org-agenda-highlight-todo list))
  5446. (if nosort
  5447. list
  5448. (when org-agenda-before-sorting-filter-function
  5449. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5450. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5451. (defun org-agenda-highlight-todo (x)
  5452. (let ((org-done-keywords org-done-keywords-for-agenda)
  5453. (case-fold-search nil)
  5454. re)
  5455. (if (eq x 'line)
  5456. (save-excursion
  5457. (beginning-of-line 1)
  5458. (setq re (org-get-at-bol 'org-todo-regexp))
  5459. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5460. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5461. (add-text-properties (match-beginning 0) (match-end 1)
  5462. (list 'face (org-get-todo-face 1)))
  5463. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5464. (delete-region (match-beginning 1) (1- (match-end 0)))
  5465. (goto-char (match-beginning 1))
  5466. (insert (format org-agenda-todo-keyword-format s)))))
  5467. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5468. (setq re (get-text-property 0 'org-todo-regexp x))
  5469. (when (and re
  5470. ;; Test `pl' because if there's no heading content,
  5471. ;; there's no point matching to highlight. Note
  5472. ;; that if we didn't test `pl' first, and there
  5473. ;; happened to be no keyword from `org-todo-regexp'
  5474. ;; on this heading line, then the `equal' comparison
  5475. ;; afterwards would spuriously succeed in the case
  5476. ;; where `pl' is nil -- causing an args-out-of-range
  5477. ;; error when we try to add text properties to text
  5478. ;; that isn't there.
  5479. pl
  5480. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5481. x pl) pl))
  5482. (add-text-properties
  5483. (or (match-end 1) (match-end 0)) (match-end 0)
  5484. (list 'face (org-get-todo-face (match-string 2 x)))
  5485. x)
  5486. (when (match-end 1)
  5487. (setq x (concat (substring x 0 (match-end 1))
  5488. (format org-agenda-todo-keyword-format
  5489. (match-string 2 x))
  5490. (org-add-props " " (text-properties-at 0 x))
  5491. (substring x (match-end 3)))))))
  5492. x)))
  5493. (defsubst org-cmp-priority (a b)
  5494. "Compare the priorities of string A and B."
  5495. (let ((pa (or (get-text-property 1 'priority a) 0))
  5496. (pb (or (get-text-property 1 'priority b) 0)))
  5497. (cond ((> pa pb) +1)
  5498. ((< pa pb) -1)
  5499. (t nil))))
  5500. (defsubst org-cmp-effort (a b)
  5501. "Compare the effort values of string A and B."
  5502. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5503. (ea (or (get-text-property 1 'effort-minutes a) def))
  5504. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5505. (cond ((> ea eb) +1)
  5506. ((< ea eb) -1)
  5507. (t nil))))
  5508. (defsubst org-cmp-category (a b)
  5509. "Compare the string values of categories of strings A and B."
  5510. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5511. (cb (or (get-text-property 1 'org-category b) "")))
  5512. (cond ((string-lessp ca cb) -1)
  5513. ((string-lessp cb ca) +1)
  5514. (t nil))))
  5515. (defsubst org-cmp-todo-state (a b)
  5516. "Compare the todo states of strings A and B."
  5517. (let* ((ma (or (get-text-property 1 'org-marker a)
  5518. (get-text-property 1 'org-hd-marker a)))
  5519. (mb (or (get-text-property 1 'org-marker b)
  5520. (get-text-property 1 'org-hd-marker b)))
  5521. (fa (and ma (marker-buffer ma)))
  5522. (fb (and mb (marker-buffer mb)))
  5523. (todo-kwds
  5524. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5525. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5526. (ta (or (get-text-property 1 'todo-state a) ""))
  5527. (tb (or (get-text-property 1 'todo-state b) ""))
  5528. (la (- (length (member ta todo-kwds))))
  5529. (lb (- (length (member tb todo-kwds))))
  5530. (donepa (member ta org-done-keywords-for-agenda))
  5531. (donepb (member tb org-done-keywords-for-agenda)))
  5532. (cond ((and donepa (not donepb)) -1)
  5533. ((and (not donepa) donepb) +1)
  5534. ((< la lb) -1)
  5535. ((< lb la) +1)
  5536. (t nil))))
  5537. (defsubst org-cmp-alpha (a b)
  5538. "Compare the headlines, alphabetically."
  5539. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5540. (plb (text-property-any 0 (length b) 'org-heading t b))
  5541. (ta (and pla (substring a pla)))
  5542. (tb (and plb (substring b plb))))
  5543. (when pla
  5544. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5545. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5546. (setq ta (substring ta (match-end 0))))
  5547. (setq ta (downcase ta)))
  5548. (when plb
  5549. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5550. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5551. (setq tb (substring tb (match-end 0))))
  5552. (setq tb (downcase tb)))
  5553. (cond ((not ta) +1)
  5554. ((not tb) -1)
  5555. ((string-lessp ta tb) -1)
  5556. ((string-lessp tb ta) +1)
  5557. (t nil))))
  5558. (defsubst org-cmp-tag (a b)
  5559. "Compare the string values of the first tags of A and B."
  5560. (let ((ta (car (last (get-text-property 1 'tags a))))
  5561. (tb (car (last (get-text-property 1 'tags b)))))
  5562. (cond ((not ta) +1)
  5563. ((not tb) -1)
  5564. ((string-lessp ta tb) -1)
  5565. ((string-lessp tb ta) +1)
  5566. (t nil))))
  5567. (defsubst org-cmp-time (a b)
  5568. "Compare the time-of-day values of strings A and B."
  5569. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5570. (ta (or (get-text-property 1 'time-of-day a) def))
  5571. (tb (or (get-text-property 1 'time-of-day b) def)))
  5572. (cond ((< ta tb) -1)
  5573. ((< tb ta) +1)
  5574. (t nil))))
  5575. (defsubst org-cmp-habit-p (a b)
  5576. "Compare the todo states of strings A and B."
  5577. (let ((ha (get-text-property 1 'org-habit-p a))
  5578. (hb (get-text-property 1 'org-habit-p b)))
  5579. (cond ((and ha (not hb)) -1)
  5580. ((and (not ha) hb) +1)
  5581. (t nil))))
  5582. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5583. (defun org-entries-lessp (a b)
  5584. "Predicate for sorting agenda entries."
  5585. ;; The following variables will be used when the form is evaluated.
  5586. ;; So even though the compiler complains, keep them.
  5587. (let* ((ss org-agenda-sorting-strategy-selected)
  5588. (time-up (and (org-em 'time-up 'time-down ss)
  5589. (org-cmp-time a b)))
  5590. (time-down (if time-up (- time-up) nil))
  5591. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5592. (org-cmp-priority a b)))
  5593. (priority-down (if priority-up (- priority-up) nil))
  5594. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5595. (org-cmp-effort a b)))
  5596. (effort-down (if effort-up (- effort-up) nil))
  5597. (category-up (and (or (org-em 'category-up 'category-down ss)
  5598. (memq 'category-keep ss))
  5599. (org-cmp-category a b)))
  5600. (category-down (if category-up (- category-up) nil))
  5601. (category-keep (if category-up +1 nil))
  5602. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5603. (org-cmp-tag a b)))
  5604. (tag-down (if tag-up (- tag-up) nil))
  5605. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5606. (org-cmp-todo-state a b)))
  5607. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5608. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5609. (org-cmp-habit-p a b)))
  5610. (habit-down (if habit-up (- habit-up) nil))
  5611. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5612. (org-cmp-alpha a b)))
  5613. (alpha-down (if alpha-up (- alpha-up) nil))
  5614. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5615. user-defined-up user-defined-down)
  5616. (if (and need-user-cmp org-agenda-cmp-user-defined
  5617. (functionp org-agenda-cmp-user-defined))
  5618. (setq user-defined-up
  5619. (funcall org-agenda-cmp-user-defined a b)
  5620. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5621. (cdr (assoc
  5622. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5623. '((-1 . t) (1 . nil) (nil . nil))))))
  5624. ;;; Agenda restriction lock
  5625. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5626. "Overlay to mark the headline to which agenda commands are restricted.")
  5627. (overlay-put org-agenda-restriction-lock-overlay
  5628. 'face 'org-agenda-restriction-lock)
  5629. (overlay-put org-agenda-restriction-lock-overlay
  5630. 'help-echo "Agendas are currently limited to this subtree.")
  5631. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5632. (defun org-agenda-set-restriction-lock (&optional type)
  5633. "Set restriction lock for agenda, to current subtree or file.
  5634. Restriction will be the file if TYPE is `file', or if type is the
  5635. universal prefix '(4), or if the cursor is before the first headline
  5636. in the file. Otherwise, restriction will be to the current subtree."
  5637. (interactive "P")
  5638. (and (equal type '(4)) (setq type 'file))
  5639. (setq type (cond
  5640. (type type)
  5641. ((org-at-heading-p) 'subtree)
  5642. ((condition-case nil (org-back-to-heading t) (error nil))
  5643. 'subtree)
  5644. (t 'file)))
  5645. (if (eq type 'subtree)
  5646. (progn
  5647. (setq org-agenda-restrict t)
  5648. (setq org-agenda-overriding-restriction 'subtree)
  5649. (put 'org-agenda-files 'org-restrict
  5650. (list (buffer-file-name (buffer-base-buffer))))
  5651. (org-back-to-heading t)
  5652. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5653. (move-marker org-agenda-restrict-begin (point))
  5654. (move-marker org-agenda-restrict-end
  5655. (save-excursion (org-end-of-subtree t)))
  5656. (message "Locking agenda restriction to subtree"))
  5657. (put 'org-agenda-files 'org-restrict
  5658. (list (buffer-file-name (buffer-base-buffer))))
  5659. (setq org-agenda-restrict nil)
  5660. (setq org-agenda-overriding-restriction 'file)
  5661. (move-marker org-agenda-restrict-begin nil)
  5662. (move-marker org-agenda-restrict-end nil)
  5663. (message "Locking agenda restriction to file"))
  5664. (setq current-prefix-arg nil)
  5665. (org-agenda-maybe-redo))
  5666. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5667. "Remove the agenda restriction lock."
  5668. (interactive "P")
  5669. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5670. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5671. (setq org-agenda-overriding-restriction nil)
  5672. (setq org-agenda-restrict nil)
  5673. (put 'org-agenda-files 'org-restrict nil)
  5674. (move-marker org-agenda-restrict-begin nil)
  5675. (move-marker org-agenda-restrict-end nil)
  5676. (setq current-prefix-arg nil)
  5677. (message "Agenda restriction lock removed")
  5678. (or noupdate (org-agenda-maybe-redo)))
  5679. (defun org-agenda-maybe-redo ()
  5680. "If there is any window showing the agenda view, update it."
  5681. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5682. (w0 (selected-window)))
  5683. (when w
  5684. (select-window w)
  5685. (org-agenda-redo)
  5686. (select-window w0)
  5687. (if org-agenda-overriding-restriction
  5688. (message "Agenda view shifted to new %s restriction"
  5689. org-agenda-overriding-restriction)
  5690. (message "Agenda restriction lock removed")))))
  5691. ;;; Agenda commands
  5692. (defun org-agenda-check-type (error &rest types)
  5693. "Check if agenda buffer is of allowed type.
  5694. If ERROR is non-nil, throw an error, otherwise just return nil."
  5695. (if (memq org-agenda-type types)
  5696. t
  5697. (if error
  5698. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5699. nil)))
  5700. (defun org-agenda-quit ()
  5701. "Exit agenda by removing the window or the buffer."
  5702. (interactive)
  5703. (if org-agenda-columns-active
  5704. (org-columns-quit)
  5705. (let ((buf (current-buffer)))
  5706. (if (eq org-agenda-window-setup 'other-frame)
  5707. (progn
  5708. (kill-buffer buf)
  5709. (org-agenda-reset-markers)
  5710. (org-columns-remove-overlays)
  5711. (setq org-agenda-archives-mode nil)
  5712. (delete-frame))
  5713. (and (not (eq org-agenda-window-setup 'current-window))
  5714. (not (one-window-p))
  5715. (delete-window))
  5716. (kill-buffer buf)
  5717. (org-agenda-reset-markers)
  5718. (org-columns-remove-overlays)
  5719. (setq org-agenda-archives-mode nil)))
  5720. ;; Maybe restore the pre-agenda window configuration.
  5721. (and org-agenda-restore-windows-after-quit
  5722. (not (eq org-agenda-window-setup 'other-frame))
  5723. org-pre-agenda-window-conf
  5724. (set-window-configuration org-pre-agenda-window-conf))))
  5725. (defun org-agenda-exit ()
  5726. "Exit agenda by removing the window or the buffer.
  5727. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5728. Org-mode buffers visited directly by the user will not be touched."
  5729. (interactive)
  5730. (org-release-buffers org-agenda-new-buffers)
  5731. (setq org-agenda-new-buffers nil)
  5732. (org-agenda-quit))
  5733. (defun org-agenda-execute (arg)
  5734. "Execute another agenda command, keeping same window.
  5735. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5736. in the agenda."
  5737. (interactive "P")
  5738. (let ((org-agenda-window-setup 'current-window))
  5739. (org-agenda arg)))
  5740. (defun org-agenda-redo ()
  5741. "Rebuild Agenda.
  5742. When this is the global TODO list, a prefix argument will be interpreted."
  5743. (interactive)
  5744. (let* ((org-agenda-keep-modes t)
  5745. (tag-filter org-agenda-tag-filter)
  5746. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5747. (cat-filter org-agenda-category-filter)
  5748. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5749. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5750. (cols org-agenda-columns-active)
  5751. (line (org-current-line))
  5752. (window-line (- line (org-current-line (window-start))))
  5753. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5754. (put 'org-agenda-tag-filter :preset-filter nil)
  5755. (put 'org-agenda-category-filter :preset-filter nil)
  5756. (and cols (org-columns-quit))
  5757. (message "Rebuilding agenda buffer...")
  5758. (org-let lprops '(eval org-agenda-redo-command))
  5759. (setq org-agenda-undo-list nil
  5760. org-agenda-pending-undo-list nil)
  5761. (message "Rebuilding agenda buffer...done")
  5762. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5763. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5764. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5765. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5766. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5767. (org-goto-line line)
  5768. (recenter window-line)))
  5769. (defvar org-global-tags-completion-table nil)
  5770. (defvar org-agenda-filtered-by-category nil)
  5771. (defvar org-agenda-filter-form nil)
  5772. (defun org-agenda-filter-by-category (strip)
  5773. "Keep only those lines in the agenda buffer that have a specific category.
  5774. The category is that of the current line."
  5775. (interactive "P")
  5776. (if org-agenda-filtered-by-category
  5777. (org-agenda-filter-show-all-cat)
  5778. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  5779. (if cat (org-agenda-filter-apply
  5780. (list (concat (if strip "-" "+") cat)) 'category)
  5781. (error "No category at point")))))
  5782. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5783. "Keep only those lines in the agenda buffer that have a specific tag.
  5784. The tag is selected with its fast selection letter, as configured.
  5785. With prefix argument STRIP, remove all lines that do have the tag.
  5786. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5787. used to narrow the search - the interactive user can also press `-' or `+'
  5788. to switch to narrowing."
  5789. (interactive "P")
  5790. (let* ((alist org-tag-alist-for-agenda)
  5791. (tag-chars (mapconcat
  5792. (lambda (x) (if (and (not (symbolp (car x)))
  5793. (cdr x))
  5794. (char-to-string (cdr x))
  5795. ""))
  5796. alist ""))
  5797. (efforts (org-split-string
  5798. (or (cdr (assoc (concat org-effort-property "_ALL")
  5799. org-global-properties))
  5800. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5801. "")))
  5802. (effort-op org-agenda-filter-effort-default-operator)
  5803. (effort-prompt "")
  5804. (inhibit-read-only t)
  5805. (current org-agenda-tag-filter)
  5806. maybe-refresh a n tag)
  5807. (unless char
  5808. (message
  5809. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5810. (if narrow "Narrow" "Filter") tag-chars
  5811. (if org-agenda-auto-exclude-function "[RET], " ""))
  5812. (setq char (read-char-exclusive)))
  5813. (when (member char '(?+ ?-))
  5814. ;; Narrowing down
  5815. (cond ((equal char ?-) (setq strip t narrow t))
  5816. ((equal char ?+) (setq strip nil narrow t)))
  5817. (message
  5818. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5819. (setq char (read-char-exclusive)))
  5820. (when (member char '(?< ?> ?= ??))
  5821. ;; An effort operator
  5822. (setq effort-op (char-to-string char))
  5823. (setq alist nil) ; to make sure it will be interpreted as effort.
  5824. (unless (equal char ??)
  5825. (loop for i from 0 to 9 do
  5826. (setq effort-prompt
  5827. (concat
  5828. effort-prompt " ["
  5829. (if (= i 9) "0" (int-to-string (1+ i)))
  5830. "]" (nth i efforts))))
  5831. (message "Effort%s: %s " effort-op effort-prompt)
  5832. (setq char (read-char-exclusive))
  5833. (when (or (< char ?0) (> char ?9))
  5834. (error "Need 1-9,0 to select effort" ))))
  5835. (when (equal char ?\t)
  5836. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5837. (org-set-local 'org-global-tags-completion-table
  5838. (org-global-tags-completion-table)))
  5839. (let ((completion-ignore-case t))
  5840. (setq tag (org-icompleting-read
  5841. "Tag: " org-global-tags-completion-table))))
  5842. (cond
  5843. ((equal char ?\r)
  5844. (org-agenda-filter-show-all-tag)
  5845. (when org-agenda-auto-exclude-function
  5846. (setq org-agenda-tag-filter '())
  5847. (dolist (tag (org-agenda-get-represented-tags))
  5848. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5849. (if modifier
  5850. (push modifier org-agenda-tag-filter))))
  5851. (if (not (null org-agenda-tag-filter))
  5852. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  5853. (setq maybe-refresh t))
  5854. ((equal char ?/)
  5855. (org-agenda-filter-show-all-tag)
  5856. (when (get 'org-agenda-tag-filter :preset-filter)
  5857. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  5858. (setq maybe-refresh t))
  5859. ((equal char ?. )
  5860. (setq org-agenda-tag-filter
  5861. (mapcar (lambda(tag) (concat "+" tag))
  5862. (org-get-at-bol 'tags)))
  5863. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5864. (setq maybe-refresh t))
  5865. ((or (equal char ?\ )
  5866. (setq a (rassoc char alist))
  5867. (and (>= char ?0) (<= char ?9)
  5868. (setq n (if (= char ?0) 9 (- char ?0 1))
  5869. tag (concat effort-op (nth n efforts))
  5870. a (cons tag nil)))
  5871. (and (= char ??)
  5872. (setq tag "?eff")
  5873. a (cons tag nil))
  5874. (and tag (setq a (cons tag nil))))
  5875. (org-agenda-filter-show-all-tag)
  5876. (setq tag (car a))
  5877. (setq org-agenda-tag-filter
  5878. (cons (concat (if strip "-" "+") tag)
  5879. (if narrow current nil)))
  5880. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5881. (setq maybe-refresh t))
  5882. (t (error "Invalid tag selection character %c" char)))
  5883. (when (and maybe-refresh
  5884. (eq org-agenda-clockreport-mode 'with-filter))
  5885. (org-agenda-redo))))
  5886. (defun org-agenda-get-represented-tags ()
  5887. "Get a list of all tags currently represented in the agenda."
  5888. (let (p tags)
  5889. (save-excursion
  5890. (goto-char (point-min))
  5891. (while (setq p (next-single-property-change (point) 'tags))
  5892. (goto-char p)
  5893. (mapc (lambda (x) (add-to-list 'tags x))
  5894. (get-text-property (point) 'tags))))
  5895. tags))
  5896. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5897. "Refine the current filter. See `org-agenda-filter-by-tag'."
  5898. (interactive "P")
  5899. (org-agenda-filter-by-tag strip char 'refine))
  5900. (defun org-agenda-filter-make-matcher ()
  5901. "Create the form that tests a line for agenda filter."
  5902. (let (f f1)
  5903. ;; first compute the tag-filter matcher
  5904. (dolist (x (delete-dups
  5905. (append (get 'org-agenda-tag-filter
  5906. :preset-filter) org-agenda-tag-filter)))
  5907. (if (member x '("-" "+"))
  5908. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5909. (if (string-match "[<=>?]" x)
  5910. (setq f1 (org-agenda-filter-effort-form x))
  5911. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5912. (if (equal (string-to-char x) ?-)
  5913. (setq f1 (list 'not f1))))
  5914. (push f1 f))
  5915. ;; then compute the category-filter matcher
  5916. (dolist (x (delete-dups
  5917. (append (get 'org-agenda-category-filter
  5918. :preset-filter) org-agenda-category-filter)))
  5919. (setq f1 (list 'equal (substring x 1) 'cat))
  5920. (push f1 f))
  5921. (cons 'and (nreverse f))))
  5922. (defun org-agenda-filter-effort-form (e)
  5923. "Return the form to compare the effort of the current line with what E says.
  5924. E looks like \"+<2:25\"."
  5925. (let (op)
  5926. (setq e (substring e 1))
  5927. (setq op (string-to-char e) e (substring e 1))
  5928. (setq op (cond ((equal op ?<) '<=)
  5929. ((equal op ?>) '>=)
  5930. ((equal op ??) op)
  5931. (t '=)))
  5932. (list 'org-agenda-compare-effort (list 'quote op)
  5933. (org-duration-string-to-minutes e))))
  5934. (defun org-agenda-compare-effort (op value)
  5935. "Compare the effort of the current line with VALUE, using OP.
  5936. If the line does not have an effort defined, return nil."
  5937. (let ((eff (org-get-at-bol 'effort-minutes)))
  5938. (if (equal op ??)
  5939. (not eff)
  5940. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5941. value))))
  5942. (defun org-agenda-filter-apply (filter type)
  5943. "Set FILTER as the new agenda filter and apply it."
  5944. (let (tags cat)
  5945. (if (eq type 'tag)
  5946. (setq org-agenda-tag-filter filter)
  5947. (setq org-agenda-category-filter filter
  5948. org-agenda-filtered-by-category t))
  5949. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  5950. (org-agenda-set-mode-name)
  5951. (save-excursion
  5952. (goto-char (point-min))
  5953. (while (not (eobp))
  5954. (if (org-get-at-bol 'org-marker)
  5955. (progn
  5956. (setq tags (org-get-at-bol 'tags) ; used in eval
  5957. cat (get-text-property (point) 'org-category))
  5958. (if (not (eval org-agenda-filter-form))
  5959. (org-agenda-filter-hide-line type))
  5960. (beginning-of-line 2))
  5961. (beginning-of-line 2))))
  5962. (if (get-char-property (point) 'invisible)
  5963. (org-agenda-previous-line))))
  5964. (defun org-agenda-filter-hide-line (type)
  5965. (let (ov)
  5966. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5967. (point-at-eol)))
  5968. (overlay-put ov 'invisible t)
  5969. (overlay-put ov 'type type)
  5970. (if (eq type 'tag)
  5971. (push ov org-agenda-tag-filter-overlays)
  5972. (push ov org-agenda-cat-filter-overlays))))
  5973. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5974. (setq pos (or pos (point)))
  5975. (save-excursion
  5976. (dolist (ov (overlays-at pos))
  5977. (when (and (overlay-get ov 'invisible)
  5978. (eq (overlay-get ov 'type) 'tag))
  5979. (goto-char pos)
  5980. (if (< (overlay-start ov) (point-at-eol))
  5981. (move-overlay ov (point-at-eol)
  5982. (overlay-end ov)))))))
  5983. (defun org-agenda-filter-show-all-tag nil
  5984. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  5985. (setq org-agenda-tag-filter-overlays nil
  5986. org-agenda-tag-filter nil
  5987. org-agenda-filter-form nil)
  5988. (org-agenda-set-mode-name))
  5989. (defun org-agenda-filter-show-all-cat nil
  5990. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  5991. (setq org-agenda-cat-filter-overlays nil
  5992. org-agenda-filtered-by-category nil
  5993. org-agenda-category-filter nil
  5994. org-agenda-filter-form nil)
  5995. (org-agenda-set-mode-name))
  5996. (defun org-agenda-manipulate-query-add ()
  5997. "Manipulate the query by adding a search term with positive selection.
  5998. Positive selection means the term must be matched for selection of an entry."
  5999. (interactive)
  6000. (org-agenda-manipulate-query ?\[))
  6001. (defun org-agenda-manipulate-query-subtract ()
  6002. "Manipulate the query by adding a search term with negative selection.
  6003. Negative selection means term must not be matched for selection of an entry."
  6004. (interactive)
  6005. (org-agenda-manipulate-query ?\]))
  6006. (defun org-agenda-manipulate-query-add-re ()
  6007. "Manipulate the query by adding a search regexp with positive selection.
  6008. Positive selection means the regexp must match for selection of an entry."
  6009. (interactive)
  6010. (org-agenda-manipulate-query ?\{))
  6011. (defun org-agenda-manipulate-query-subtract-re ()
  6012. "Manipulate the query by adding a search regexp with negative selection.
  6013. Negative selection means regexp must not match for selection of an entry."
  6014. (interactive)
  6015. (org-agenda-manipulate-query ?\}))
  6016. (defun org-agenda-manipulate-query (char)
  6017. (cond
  6018. ((memq org-agenda-type '(timeline agenda))
  6019. (let ((org-agenda-include-inactive-timestamps t))
  6020. (org-agenda-redo))
  6021. (message "Display now includes inactive timestamps as well"))
  6022. ((eq org-agenda-type 'search)
  6023. (org-add-to-string
  6024. 'org-agenda-query-string
  6025. (if org-agenda-last-search-view-search-was-boolean
  6026. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6027. (?\{ . " +{}") (?\} . " -{}"))))
  6028. " "))
  6029. (setq org-agenda-redo-command
  6030. (list 'org-search-view
  6031. org-todo-only
  6032. org-agenda-query-string
  6033. (+ (length org-agenda-query-string)
  6034. (if (member char '(?\{ ?\})) 0 1))))
  6035. (set-register org-agenda-query-register org-agenda-query-string)
  6036. (org-agenda-redo))
  6037. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6038. org-agenda-type))))
  6039. (defun org-add-to-string (var string)
  6040. (set var (concat (symbol-value var) string)))
  6041. (defun org-agenda-goto-date (date)
  6042. "Jump to DATE in agenda."
  6043. (interactive (list (let ((org-read-date-prefer-future
  6044. (eval org-agenda-jump-prefer-future)))
  6045. (org-read-date))))
  6046. (org-agenda-list nil date))
  6047. (defun org-agenda-goto-today ()
  6048. "Go to today."
  6049. (interactive)
  6050. (org-agenda-check-type t 'timeline 'agenda)
  6051. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6052. (cond
  6053. (tdpos (goto-char tdpos))
  6054. ((eq org-agenda-type 'agenda)
  6055. (let* ((sd (org-agenda-compute-starting-span
  6056. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6057. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6058. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6059. (org-agenda-redo)
  6060. (org-agenda-find-same-or-today-or-agenda)))
  6061. (t (error "Cannot find today")))))
  6062. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6063. (goto-char
  6064. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6065. (text-property-any (point-min) (point-max) 'org-today t)
  6066. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6067. (point-min))))
  6068. (defun org-agenda-later (arg)
  6069. "Go forward in time by thee current span.
  6070. With prefix ARG, go forward that many times the current span."
  6071. (interactive "p")
  6072. (org-agenda-check-type t 'agenda)
  6073. (let* ((span org-agenda-current-span)
  6074. (sd org-starting-day)
  6075. (greg (calendar-gregorian-from-absolute sd))
  6076. (cnt (org-get-at-bol 'org-day-cnt))
  6077. greg2)
  6078. (cond
  6079. ((eq span 'day)
  6080. (setq sd (+ arg sd)))
  6081. ((eq span 'week)
  6082. (setq sd (+ (* 7 arg) sd)))
  6083. ((eq span 'month)
  6084. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6085. sd (calendar-absolute-from-gregorian greg2))
  6086. (setcar greg2 (1+ (car greg2))))
  6087. ((eq span 'year)
  6088. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6089. sd (calendar-absolute-from-gregorian greg2))
  6090. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6091. (t
  6092. (setq sd (+ (* span arg) sd))))
  6093. (let ((org-agenda-overriding-arguments
  6094. (list (car org-agenda-last-arguments) sd span t)))
  6095. (org-agenda-redo)
  6096. (org-agenda-find-same-or-today-or-agenda cnt))))
  6097. (defun org-agenda-earlier (arg)
  6098. "Go backward in time by the current span.
  6099. With prefix ARG, go backward that many times the current span."
  6100. (interactive "p")
  6101. (org-agenda-later (- arg)))
  6102. (defun org-agenda-view-mode-dispatch ()
  6103. "Call one of the view mode commands."
  6104. (interactive)
  6105. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6106. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6107. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6108. [E]ntryText")
  6109. (let ((a (read-char-exclusive)))
  6110. (case a
  6111. (?\ (call-interactively 'org-agenda-reset-view))
  6112. (?d (call-interactively 'org-agenda-day-view))
  6113. (?w (call-interactively 'org-agenda-week-view))
  6114. (?m (call-interactively 'org-agenda-month-view))
  6115. (?y (call-interactively 'org-agenda-year-view))
  6116. (?l (call-interactively 'org-agenda-log-mode))
  6117. (?L (org-agenda-log-mode '(4)))
  6118. (?c (org-agenda-log-mode 'clockcheck))
  6119. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6120. (?a (call-interactively 'org-agenda-archives-mode))
  6121. (?A (org-agenda-archives-mode 'files))
  6122. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6123. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6124. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6125. (?D (call-interactively 'org-agenda-toggle-diary))
  6126. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6127. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6128. (org-agenda-check-type t 'timeline 'agenda)
  6129. (org-agenda-redo))
  6130. (message "Display now includes inactive timestamps as well"))
  6131. (?q (message "Abort"))
  6132. (otherwise (error "Invalid key" )))))
  6133. (defun org-agenda-reset-view ()
  6134. "Switch to default view for agenda."
  6135. (interactive)
  6136. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6137. (defun org-agenda-day-view (&optional day-of-year)
  6138. "Switch to daily view for agenda.
  6139. With argument DAY-OF-YEAR, switch to that day of the year."
  6140. (interactive "P")
  6141. (org-agenda-change-time-span 'day day-of-year))
  6142. (defun org-agenda-week-view (&optional iso-week)
  6143. "Switch to daily view for agenda.
  6144. With argument ISO-WEEK, switch to the corresponding ISO week.
  6145. If ISO-WEEK has more then 2 digits, only the last two encode the
  6146. week. Any digits before this encode a year. So 200712 means
  6147. week 12 of year 2007. Years in the range 1938-2037 can also be
  6148. written as 2-digit years."
  6149. (interactive "P")
  6150. (org-agenda-change-time-span 'week iso-week))
  6151. (defun org-agenda-month-view (&optional month)
  6152. "Switch to monthly view for agenda.
  6153. With argument MONTH, switch to that month."
  6154. (interactive "P")
  6155. (org-agenda-change-time-span 'month month))
  6156. (defun org-agenda-year-view (&optional year)
  6157. "Switch to yearly view for agenda.
  6158. With argument YEAR, switch to that year.
  6159. If MONTH has more then 2 digits, only the last two encode the
  6160. month. Any digits before this encode a year. So 200712 means
  6161. December year 2007. Years in the range 1938-2037 can also be
  6162. written as 2-digit years."
  6163. (interactive "P")
  6164. (when year
  6165. (setq year (org-small-year-to-year year)))
  6166. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6167. (org-agenda-change-time-span 'year year)
  6168. (error "Abort")))
  6169. (defun org-agenda-change-time-span (span &optional n)
  6170. "Change the agenda view to SPAN.
  6171. SPAN may be `day', `week', `month', `year'."
  6172. (org-agenda-check-type t 'agenda)
  6173. (if (and (not n) (equal org-agenda-current-span span))
  6174. (error "Viewing span is already \"%s\"" span))
  6175. (let* ((sd (or (org-get-at-bol 'day)
  6176. org-starting-day))
  6177. (sd (org-agenda-compute-starting-span sd span n))
  6178. (org-agenda-overriding-arguments
  6179. (or org-agenda-overriding-arguments
  6180. (list (car org-agenda-last-arguments) sd span t))))
  6181. (org-agenda-redo)
  6182. (org-agenda-find-same-or-today-or-agenda))
  6183. (org-agenda-set-mode-name)
  6184. (message "Switched to %s view" span))
  6185. (defun org-agenda-compute-starting-span (sd span &optional n)
  6186. "Compute starting date for agenda.
  6187. SPAN may be `day', `week', `month', `year'. The return value
  6188. is a cons cell with the starting date and the number of days,
  6189. so that the date SD will be in that range."
  6190. (let* ((greg (calendar-gregorian-from-absolute sd))
  6191. (dg (nth 1 greg))
  6192. (mg (car greg))
  6193. (yg (nth 2 greg)))
  6194. (cond
  6195. ((eq span 'day)
  6196. (when n
  6197. (setq sd (+ (calendar-absolute-from-gregorian
  6198. (list mg 1 yg))
  6199. n -1))))
  6200. ((eq span 'week)
  6201. (let* ((nt (calendar-day-of-week
  6202. (calendar-gregorian-from-absolute sd)))
  6203. (d (if org-agenda-start-on-weekday
  6204. (- nt org-agenda-start-on-weekday)
  6205. 0))
  6206. y1)
  6207. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6208. (when n
  6209. (require 'cal-iso)
  6210. (when (> n 99)
  6211. (setq y1 (org-small-year-to-year (/ n 100))
  6212. n (mod n 100)))
  6213. (setq sd
  6214. (calendar-absolute-from-iso
  6215. (list n 1
  6216. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6217. ((eq span 'month)
  6218. (let (y1)
  6219. (when (and n (> n 99))
  6220. (setq y1 (org-small-year-to-year (/ n 100))
  6221. n (mod n 100)))
  6222. (setq sd (calendar-absolute-from-gregorian
  6223. (list (or n mg) 1 (or y1 yg))))))
  6224. ((eq span 'year)
  6225. (setq sd (calendar-absolute-from-gregorian
  6226. (list 1 1 (or n yg))))))
  6227. sd))
  6228. (defun org-agenda-next-date-line (&optional arg)
  6229. "Jump to the next line indicating a date in agenda buffer."
  6230. (interactive "p")
  6231. (org-agenda-check-type t 'agenda 'timeline)
  6232. (beginning-of-line 1)
  6233. ;; This does not work if user makes date format that starts with a blank
  6234. (if (looking-at "^\\S-") (forward-char 1))
  6235. (if (not (re-search-forward "^\\S-" nil t arg))
  6236. (progn
  6237. (backward-char 1)
  6238. (error "No next date after this line in this buffer")))
  6239. (goto-char (match-beginning 0)))
  6240. (defun org-agenda-previous-date-line (&optional arg)
  6241. "Jump to the previous line indicating a date in agenda buffer."
  6242. (interactive "p")
  6243. (org-agenda-check-type t 'agenda 'timeline)
  6244. (beginning-of-line 1)
  6245. (if (not (re-search-backward "^\\S-" nil t arg))
  6246. (error "No previous date before this line in this buffer")))
  6247. ;; Initialize the highlight
  6248. (defvar org-hl (make-overlay 1 1))
  6249. (overlay-put org-hl 'face 'highlight)
  6250. (defun org-highlight (begin end &optional buffer)
  6251. "Highlight a region with overlay."
  6252. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6253. (defun org-unhighlight ()
  6254. "Detach overlay INDEX."
  6255. (org-detach-overlay org-hl))
  6256. ;; FIXME this is currently not used.
  6257. (defun org-highlight-until-next-command (beg end &optional buffer)
  6258. "Move the highlight overlay to BEG/END, remove it before the next command."
  6259. (org-highlight beg end buffer)
  6260. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6261. (defun org-unhighlight-once ()
  6262. "Remove the highlight from its position, and this function from the hook."
  6263. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6264. (org-unhighlight))
  6265. (defun org-agenda-follow-mode ()
  6266. "Toggle follow mode in an agenda buffer."
  6267. (interactive)
  6268. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6269. (org-agenda-set-mode-name)
  6270. (org-agenda-do-context-action)
  6271. (message "Follow mode is %s"
  6272. (if org-agenda-follow-mode "on" "off")))
  6273. (defun org-agenda-entry-text-mode (&optional arg)
  6274. "Toggle entry text mode in an agenda buffer."
  6275. (interactive "P")
  6276. (setq org-agenda-entry-text-mode (or (integerp arg)
  6277. (not org-agenda-entry-text-mode)))
  6278. (org-agenda-entry-text-hide)
  6279. (and org-agenda-entry-text-mode
  6280. (let ((org-agenda-entry-text-maxlines
  6281. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6282. (org-agenda-entry-text-show)))
  6283. (org-agenda-set-mode-name)
  6284. (message "Entry text mode is %s. Maximum number of lines is %d"
  6285. (if org-agenda-entry-text-mode "on" "off")
  6286. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6287. (defun org-agenda-clockreport-mode (&optional with-filter)
  6288. "Toggle clocktable mode in an agenda buffer.
  6289. With prefix arg WITH-FILTER, make the clocktable respect the current
  6290. agenda filter."
  6291. (interactive "P")
  6292. (org-agenda-check-type t 'agenda)
  6293. (if with-filter
  6294. (setq org-agenda-clockreport-mode 'with-filter)
  6295. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6296. (org-agenda-set-mode-name)
  6297. (org-agenda-redo)
  6298. (message "Clocktable mode is %s"
  6299. (if org-agenda-clockreport-mode "on" "off")))
  6300. (defun org-agenda-log-mode (&optional special)
  6301. "Toggle log mode in an agenda buffer.
  6302. With argument SPECIAL, show all possible log items, not only the ones
  6303. configured in `org-agenda-log-mode-items'.
  6304. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6305. (interactive "P")
  6306. (org-agenda-check-type t 'agenda 'timeline)
  6307. (setq org-agenda-show-log
  6308. (cond
  6309. ((equal special '(16)) 'only)
  6310. ((eq special 'clockcheck)
  6311. (if (eq org-agenda-show-log 'clockcheck)
  6312. nil 'clockcheck))
  6313. (special '(closed clock state))
  6314. (t (not org-agenda-show-log))))
  6315. (org-agenda-set-mode-name)
  6316. (org-agenda-redo)
  6317. (message "Log mode is %s"
  6318. (if org-agenda-show-log "on" "off")))
  6319. (defun org-agenda-archives-mode (&optional with-files)
  6320. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6321. When called with a prefix argument, include all archive files as well."
  6322. (interactive "P")
  6323. (setq org-agenda-archives-mode
  6324. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6325. (org-agenda-set-mode-name)
  6326. (org-agenda-redo)
  6327. (message
  6328. "%s"
  6329. (cond
  6330. ((eq org-agenda-archives-mode nil)
  6331. "No archives are included")
  6332. ((eq org-agenda-archives-mode 'trees)
  6333. (format "Trees with :%s: tag are included" org-archive-tag))
  6334. ((eq org-agenda-archives-mode t)
  6335. (format "Trees with :%s: tag and all active archive files are included"
  6336. org-archive-tag)))))
  6337. (defun org-agenda-toggle-diary ()
  6338. "Toggle diary inclusion in an agenda buffer."
  6339. (interactive)
  6340. (org-agenda-check-type t 'agenda)
  6341. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6342. (org-agenda-redo)
  6343. (org-agenda-set-mode-name)
  6344. (message "Diary inclusion turned %s"
  6345. (if org-agenda-include-diary "on" "off")))
  6346. (defun org-agenda-toggle-deadlines ()
  6347. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6348. (interactive)
  6349. (org-agenda-check-type t 'agenda)
  6350. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6351. (org-agenda-redo)
  6352. (org-agenda-set-mode-name)
  6353. (message "Deadlines inclusion turned %s"
  6354. (if org-agenda-include-deadlines "on" "off")))
  6355. (defun org-agenda-toggle-time-grid ()
  6356. "Toggle time grid in an agenda buffer."
  6357. (interactive)
  6358. (org-agenda-check-type t 'agenda)
  6359. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6360. (org-agenda-redo)
  6361. (org-agenda-set-mode-name)
  6362. (message "Time-grid turned %s"
  6363. (if org-agenda-use-time-grid "on" "off")))
  6364. (defun org-agenda-set-mode-name ()
  6365. "Set the mode name to indicate all the small mode settings."
  6366. (setq mode-name
  6367. (list "Org-Agenda"
  6368. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6369. " "
  6370. '(:eval (org-agenda-span-name org-agenda-current-span))
  6371. (if org-agenda-follow-mode " Follow" "")
  6372. (if org-agenda-entry-text-mode " ETxt" "")
  6373. (if org-agenda-include-diary " Diary" "")
  6374. (if org-agenda-include-deadlines " Ddl" "")
  6375. (if org-agenda-use-time-grid " Grid" "")
  6376. (if (and (boundp 'org-habit-show-habits)
  6377. org-habit-show-habits) " Habit" "")
  6378. (cond
  6379. ((consp org-agenda-show-log) " LogAll")
  6380. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6381. (org-agenda-show-log " Log")
  6382. (t ""))
  6383. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6384. :preset-filter))
  6385. '(:eval (org-propertize
  6386. (concat " <"
  6387. (mapconcat
  6388. 'identity
  6389. (append
  6390. (get 'org-agenda-category-filter :preset-filter)
  6391. org-agenda-category-filter)
  6392. "")
  6393. ">")
  6394. 'face 'org-agenda-filter-category
  6395. 'help-echo "Category used in filtering"))
  6396. "")
  6397. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6398. :preset-filter))
  6399. '(:eval (org-propertize
  6400. (concat " {"
  6401. (mapconcat
  6402. 'identity
  6403. (append
  6404. (get 'org-agenda-tag-filter :preset-filter)
  6405. org-agenda-tag-filter)
  6406. "")
  6407. "}")
  6408. 'face 'org-agenda-filter-tags
  6409. 'help-echo "Tags used in filtering"))
  6410. "")
  6411. (if org-agenda-archives-mode
  6412. (if (eq org-agenda-archives-mode t)
  6413. " Archives"
  6414. (format " :%s:" org-archive-tag))
  6415. "")
  6416. (if org-agenda-clockreport-mode
  6417. (if (eq org-agenda-clockreport-mode 'with-filter)
  6418. " Clock{}" " Clock")
  6419. "")))
  6420. (force-mode-line-update))
  6421. (defun org-agenda-post-command-hook ()
  6422. (setq org-agenda-type
  6423. (or (get-text-property (point) 'org-agenda-type)
  6424. (get-text-property (max (point-min) (1- (point)))
  6425. 'org-agenda-type))))
  6426. (defun org-agenda-next-line ()
  6427. "Move cursor to the next line, and show if follow mode is active."
  6428. (interactive)
  6429. (call-interactively 'next-line)
  6430. (org-agenda-do-context-action))
  6431. (defun org-agenda-previous-line ()
  6432. "Move cursor to the previous line, and show if follow-mode is active."
  6433. (interactive)
  6434. (call-interactively 'previous-line)
  6435. (org-agenda-do-context-action))
  6436. (defun org-agenda-do-context-action ()
  6437. "Show outline path and, maybe, follow mode window."
  6438. (let ((m (org-get-at-bol 'org-marker)))
  6439. (when (and (markerp m) (marker-buffer m))
  6440. (and org-agenda-follow-mode
  6441. (if org-agenda-follow-indirect
  6442. (org-agenda-tree-to-indirect-buffer)
  6443. (org-agenda-show)))
  6444. (and org-agenda-show-outline-path
  6445. (org-with-point-at m (org-display-outline-path t))))))
  6446. (defun org-agenda-show-priority ()
  6447. "Show the priority of the current item.
  6448. This priority is composed of the main priority given with the [#A] cookies,
  6449. and by additional input from the age of a schedules or deadline entry."
  6450. (interactive)
  6451. (let* ((pri (org-get-at-bol 'priority)))
  6452. (message "Priority is %d" (if pri pri -1000))))
  6453. (defun org-agenda-show-tags ()
  6454. "Show the tags applicable to the current item."
  6455. (interactive)
  6456. (let* ((tags (org-get-at-bol 'tags)))
  6457. (if tags
  6458. (message "Tags are :%s:"
  6459. (org-no-properties (mapconcat 'identity tags ":")))
  6460. (message "No tags associated with this line"))))
  6461. (defun org-agenda-goto (&optional highlight)
  6462. "Go to the Org-mode file which contains the item at point."
  6463. (interactive)
  6464. (let* ((marker (or (org-get-at-bol 'org-marker)
  6465. (org-agenda-error)))
  6466. (buffer (marker-buffer marker))
  6467. (pos (marker-position marker)))
  6468. (switch-to-buffer-other-window buffer)
  6469. (widen)
  6470. (push-mark)
  6471. (goto-char pos)
  6472. (when (eq major-mode 'org-mode)
  6473. (org-show-context 'agenda)
  6474. (save-excursion
  6475. (and (outline-next-heading)
  6476. (org-flag-heading nil)))) ; show the next heading
  6477. (when (outline-invisible-p)
  6478. (show-entry)) ; display invisible text
  6479. (recenter (/ (window-height) 2))
  6480. (run-hooks 'org-agenda-after-show-hook)
  6481. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6482. (defvar org-agenda-after-show-hook nil
  6483. "Normal hook run after an item has been shown from the agenda.
  6484. Point is in the buffer where the item originated.")
  6485. (defun org-agenda-kill ()
  6486. "Kill the entry or subtree belonging to the current agenda entry."
  6487. (interactive)
  6488. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6489. (let* ((marker (or (org-get-at-bol 'org-marker)
  6490. (org-agenda-error)))
  6491. (buffer (marker-buffer marker))
  6492. (pos (marker-position marker))
  6493. (type (org-get-at-bol 'type))
  6494. dbeg dend (n 0) conf)
  6495. (org-with-remote-undo buffer
  6496. (with-current-buffer buffer
  6497. (save-excursion
  6498. (goto-char pos)
  6499. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6500. (setq dbeg (progn (org-back-to-heading t) (point))
  6501. dend (org-end-of-subtree t t))
  6502. (setq dbeg (point-at-bol)
  6503. dend (min (point-max) (1+ (point-at-eol)))))
  6504. (goto-char dbeg)
  6505. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6506. (setq conf (or (eq t org-agenda-confirm-kill)
  6507. (and (numberp org-agenda-confirm-kill)
  6508. (> n org-agenda-confirm-kill))))
  6509. (and conf
  6510. (not (y-or-n-p
  6511. (format "Delete entry with %d lines in buffer \"%s\"? "
  6512. n (buffer-name buffer))))
  6513. (error "Abort"))
  6514. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6515. (with-current-buffer buffer (delete-region dbeg dend))
  6516. (message "Agenda item and source killed"))))
  6517. (defvar org-archive-default-command)
  6518. (defun org-agenda-archive-default ()
  6519. "Archive the entry or subtree belonging to the current agenda entry."
  6520. (interactive)
  6521. (require 'org-archive)
  6522. (org-agenda-archive-with org-archive-default-command))
  6523. (defun org-agenda-archive-default-with-confirmation ()
  6524. "Archive the entry or subtree belonging to the current agenda entry."
  6525. (interactive)
  6526. (require 'org-archive)
  6527. (org-agenda-archive-with org-archive-default-command 'confirm))
  6528. (defun org-agenda-archive ()
  6529. "Archive the entry or subtree belonging to the current agenda entry."
  6530. (interactive)
  6531. (org-agenda-archive-with 'org-archive-subtree))
  6532. (defun org-agenda-archive-to-archive-sibling ()
  6533. "Move the entry to the archive sibling."
  6534. (interactive)
  6535. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6536. (defun org-agenda-archive-with (cmd &optional confirm)
  6537. "Move the entry to the archive sibling."
  6538. (interactive)
  6539. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6540. (let* ((marker (or (org-get-at-bol 'org-marker)
  6541. (org-agenda-error)))
  6542. (buffer (marker-buffer marker))
  6543. (pos (marker-position marker)))
  6544. (org-with-remote-undo buffer
  6545. (with-current-buffer buffer
  6546. (if (eq major-mode 'org-mode)
  6547. (if (and confirm
  6548. (not (y-or-n-p "Archive this subtree or entry? ")))
  6549. (error "Abort")
  6550. (save-excursion
  6551. (goto-char pos)
  6552. (org-remove-subtree-entries-from-agenda)
  6553. (org-back-to-heading t)
  6554. (funcall cmd)))
  6555. (error "Archiving works only in Org-mode files"))))))
  6556. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6557. "Remove all lines in the agenda that correspond to a given subtree.
  6558. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6559. If this information is not given, the function uses the tree at point."
  6560. (let ((buf (or buf (current-buffer))) m p)
  6561. (save-excursion
  6562. (unless (and beg end)
  6563. (org-back-to-heading t)
  6564. (setq beg (point))
  6565. (org-end-of-subtree t)
  6566. (setq end (point)))
  6567. (set-buffer (get-buffer org-agenda-buffer-name))
  6568. (save-excursion
  6569. (goto-char (point-max))
  6570. (beginning-of-line 1)
  6571. (while (not (bobp))
  6572. (when (and (setq m (org-get-at-bol 'org-marker))
  6573. (equal buf (marker-buffer m))
  6574. (setq p (marker-position m))
  6575. (>= p beg)
  6576. (< p end))
  6577. (let ((inhibit-read-only t))
  6578. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6579. (beginning-of-line 0))))))
  6580. (defun org-agenda-refile (&optional goto rfloc no-update)
  6581. "Refile the item at point."
  6582. (interactive "P")
  6583. (if (equal goto '(16))
  6584. (org-refile-goto-last-stored)
  6585. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6586. (org-agenda-error)))
  6587. (buffer (marker-buffer marker))
  6588. (pos (marker-position marker))
  6589. (rfloc (or rfloc
  6590. (org-refile-get-location
  6591. (if goto "Goto" "Refile to") buffer
  6592. org-refile-allow-creating-parent-nodes))))
  6593. (with-current-buffer buffer
  6594. (save-excursion
  6595. (save-restriction
  6596. (widen)
  6597. (goto-char marker)
  6598. (org-remove-subtree-entries-from-agenda)
  6599. (org-refile goto buffer rfloc)))))
  6600. (unless no-update (org-agenda-redo))))
  6601. (defun org-agenda-open-link (&optional arg)
  6602. "Follow the link in the current line, if any.
  6603. This looks for a link in the displayed line in the agenda. It also looks
  6604. at the text of the entry itself."
  6605. (interactive "P")
  6606. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6607. (org-get-at-bol 'org-marker)))
  6608. (buffer (and marker (marker-buffer marker)))
  6609. (prefix (buffer-substring
  6610. (point-at-bol) (point-at-eol))))
  6611. (cond
  6612. (buffer
  6613. (with-current-buffer buffer
  6614. (save-excursion
  6615. (save-restriction
  6616. (widen)
  6617. (goto-char marker)
  6618. (org-offer-links-in-entry arg prefix)))))
  6619. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6620. (save-excursion
  6621. (beginning-of-line 1)
  6622. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6623. (org-open-link-from-string (match-string 1)))
  6624. (t (error "No link to open here")))))
  6625. (defun org-agenda-copy-local-variable (var)
  6626. "Get a variable from a referenced buffer and install it here."
  6627. (let ((m (org-get-at-bol 'org-marker)))
  6628. (when (and m (buffer-live-p (marker-buffer m)))
  6629. (org-set-local var (with-current-buffer (marker-buffer m)
  6630. (symbol-value var))))))
  6631. (defun org-agenda-switch-to (&optional delete-other-windows)
  6632. "Go to the Org-mode file which contains the item at point."
  6633. (interactive)
  6634. (if (and org-return-follows-link
  6635. (not (org-get-at-bol 'org-marker))
  6636. (org-in-regexp org-bracket-link-regexp))
  6637. (org-open-link-from-string (match-string 0))
  6638. (let* ((marker (or (org-get-at-bol 'org-marker)
  6639. (org-agenda-error)))
  6640. (buffer (marker-buffer marker))
  6641. (pos (marker-position marker)))
  6642. (org-pop-to-buffer-same-window buffer)
  6643. (and delete-other-windows (delete-other-windows))
  6644. (widen)
  6645. (goto-char pos)
  6646. (when (eq major-mode 'org-mode)
  6647. (org-show-context 'agenda)
  6648. (save-excursion
  6649. (and (outline-next-heading)
  6650. (org-flag-heading nil))) ; show the next heading
  6651. (when (outline-invisible-p)
  6652. (show-entry)))))) ; display invisible text
  6653. (defun org-agenda-goto-mouse (ev)
  6654. "Go to the Org-mode file which contains the item at the mouse click."
  6655. (interactive "e")
  6656. (mouse-set-point ev)
  6657. (org-agenda-goto))
  6658. (defun org-agenda-show (&optional full-entry)
  6659. "Display the Org-mode file which contains the item at point.
  6660. With prefix argument FULL-ENTRY, make the entire entry visible
  6661. if it was hidden in the outline."
  6662. (interactive "P")
  6663. (let ((win (selected-window)))
  6664. (if full-entry
  6665. (let ((org-show-entry-below t))
  6666. (org-agenda-goto t))
  6667. (org-agenda-goto t))
  6668. (select-window win)))
  6669. (defvar org-agenda-show-window nil)
  6670. (defun org-agenda-show-and-scroll-up (&optional arg)
  6671. "Display the Org-mode file which contains the item at point.
  6672. When called repeatedly, scroll the window that is displaying the buffer.
  6673. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6674. `show-subtree' to display the item, so that drawers and logbooks stay
  6675. folded."
  6676. (interactive "P")
  6677. (let ((win (selected-window)))
  6678. (if (and (window-live-p org-agenda-show-window)
  6679. (eq this-command last-command))
  6680. (progn
  6681. (select-window org-agenda-show-window)
  6682. (ignore-errors (scroll-up)))
  6683. (org-agenda-goto t)
  6684. (if arg (org-show-entry) (show-subtree))
  6685. (setq org-agenda-show-window (selected-window)))
  6686. (select-window win)))
  6687. (defun org-agenda-show-scroll-down ()
  6688. "Scroll down the window showing the agenda."
  6689. (interactive)
  6690. (let ((win (selected-window)))
  6691. (when (window-live-p org-agenda-show-window)
  6692. (select-window org-agenda-show-window)
  6693. (ignore-errors (scroll-down))
  6694. (select-window win))))
  6695. (defun org-agenda-show-1 (&optional more)
  6696. "Display the Org-mode file which contains the item at point.
  6697. The prefix arg selects the amount of information to display:
  6698. 0 hide the subtree
  6699. 1 just show the entry according to defaults.
  6700. 2 show the children view
  6701. 3 show the subtree view
  6702. 4 show the entire subtree and any LOGBOOK drawers
  6703. 5 show the entire subtree and any drawers
  6704. With prefix argument FULL-ENTRY, make the entire entry visible
  6705. if it was hidden in the outline."
  6706. (interactive "p")
  6707. (let ((win (selected-window)))
  6708. (org-agenda-goto t)
  6709. (org-recenter-heading 1)
  6710. (cond
  6711. ((= more 0)
  6712. (hide-subtree)
  6713. (save-excursion
  6714. (org-back-to-heading)
  6715. (run-hook-with-args 'org-cycle-hook 'folded))
  6716. (message "Remote: FOLDED"))
  6717. ((and (org-called-interactively-p 'any) (= more 1))
  6718. (message "Remote: show with default settings"))
  6719. ((= more 2)
  6720. (show-entry)
  6721. (show-children)
  6722. (save-excursion
  6723. (org-back-to-heading)
  6724. (run-hook-with-args 'org-cycle-hook 'children))
  6725. (message "Remote: CHILDREN"))
  6726. ((= more 3)
  6727. (show-subtree)
  6728. (save-excursion
  6729. (org-back-to-heading)
  6730. (run-hook-with-args 'org-cycle-hook 'subtree))
  6731. (message "Remote: SUBTREE"))
  6732. ((= more 4)
  6733. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6734. (org-drawer-regexp
  6735. (concat "^[ \t]*:\\("
  6736. (mapconcat 'regexp-quote org-drawers "\\|")
  6737. "\\):[ \t]*$")))
  6738. (show-subtree)
  6739. (save-excursion
  6740. (org-back-to-heading)
  6741. (org-cycle-hide-drawers 'subtree)))
  6742. (message "Remote: SUBTREE AND LOGBOOK"))
  6743. ((> more 4)
  6744. (show-subtree)
  6745. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6746. (select-window win)))
  6747. (defun org-recenter-heading (n)
  6748. (save-excursion
  6749. (org-back-to-heading)
  6750. (recenter n)))
  6751. (defvar org-agenda-cycle-counter nil)
  6752. (defun org-agenda-cycle-show (&optional n)
  6753. "Show the current entry in another window, with default settings.
  6754. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6755. When use repeatedly in immediate succession, the remote entry will cycle
  6756. through visibility
  6757. children -> subtree -> folded
  6758. When called with a numeric prefix arg, that arg will be passed through to
  6759. `org-agenda-show-1'. For the interpretation of that argument, see the
  6760. docstring of `org-agenda-show-1'."
  6761. (interactive "P")
  6762. (if (integerp n)
  6763. (setq org-agenda-cycle-counter n)
  6764. (if (not (eq last-command this-command))
  6765. (setq org-agenda-cycle-counter 1)
  6766. (if (equal org-agenda-cycle-counter 0)
  6767. (setq org-agenda-cycle-counter 2)
  6768. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6769. (if (> org-agenda-cycle-counter 3)
  6770. (setq org-agenda-cycle-counter 0)))))
  6771. (org-agenda-show-1 org-agenda-cycle-counter))
  6772. (defun org-agenda-recenter (arg)
  6773. "Display the Org-mode file which contains the item at point and recenter."
  6774. (interactive "P")
  6775. (let ((win (selected-window)))
  6776. (org-agenda-goto t)
  6777. (recenter arg)
  6778. (select-window win)))
  6779. (defun org-agenda-show-mouse (ev)
  6780. "Display the Org-mode file which contains the item at the mouse click."
  6781. (interactive "e")
  6782. (mouse-set-point ev)
  6783. (org-agenda-show))
  6784. (defun org-agenda-check-no-diary ()
  6785. "Check if the entry is a diary link and abort if yes."
  6786. (if (org-get-at-bol 'org-agenda-diary-link)
  6787. (org-agenda-error)))
  6788. (defun org-agenda-error ()
  6789. (error "Command not allowed in this line"))
  6790. (defun org-agenda-tree-to-indirect-buffer ()
  6791. "Show the subtree corresponding to the current entry in an indirect buffer.
  6792. This calls the command `org-tree-to-indirect-buffer' from the original
  6793. Org-mode buffer.
  6794. With numerical prefix arg ARG, go up to this level and then take that tree.
  6795. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6796. use the dedicated frame)."
  6797. (interactive)
  6798. (if (and current-prefix-arg (listp current-prefix-arg))
  6799. (org-agenda-do-tree-to-indirect-buffer)
  6800. (let ((agenda-window (selected-window))
  6801. (indirect-window (and org-last-indirect-buffer (get-buffer-window org-last-indirect-buffer))))
  6802. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  6803. (unwind-protect
  6804. (progn
  6805. (unless (and indirect-window (window-live-p indirect-window))
  6806. (setq indirect-window (split-window agenda-window)))
  6807. (select-window indirect-window)
  6808. (switch-to-buffer org-last-indirect-buffer :norecord)
  6809. (fit-window-to-buffer indirect-window))
  6810. (select-window agenda-window)))))
  6811. (defun org-agenda-do-tree-to-indirect-buffer ()
  6812. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  6813. (org-agenda-check-no-diary)
  6814. (let* ((marker (or (org-get-at-bol 'org-marker)
  6815. (org-agenda-error)))
  6816. (buffer (marker-buffer marker))
  6817. (pos (marker-position marker)))
  6818. (with-current-buffer buffer
  6819. (save-excursion
  6820. (goto-char pos)
  6821. (call-interactively 'org-tree-to-indirect-buffer)))))
  6822. (defvar org-last-heading-marker (make-marker)
  6823. "Marker pointing to the headline that last changed its TODO state
  6824. by a remote command from the agenda.")
  6825. (defun org-agenda-todo-nextset ()
  6826. "Switch TODO entry to next sequence."
  6827. (interactive)
  6828. (org-agenda-todo 'nextset))
  6829. (defun org-agenda-todo-previousset ()
  6830. "Switch TODO entry to previous sequence."
  6831. (interactive)
  6832. (org-agenda-todo 'previousset))
  6833. (defun org-agenda-todo (&optional arg)
  6834. "Cycle TODO state of line at point, also in Org-mode file.
  6835. This changes the line at point, all other lines in the agenda referring to
  6836. the same tree node, and the headline of the tree node in the Org-mode file."
  6837. (interactive "P")
  6838. (org-agenda-check-no-diary)
  6839. (let* ((col (current-column))
  6840. (marker (or (org-get-at-bol 'org-marker)
  6841. (org-agenda-error)))
  6842. (buffer (marker-buffer marker))
  6843. (pos (marker-position marker))
  6844. (hdmarker (org-get-at-bol 'org-hd-marker))
  6845. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6846. (inhibit-read-only t)
  6847. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6848. (org-with-remote-undo buffer
  6849. (with-current-buffer buffer
  6850. (widen)
  6851. (goto-char pos)
  6852. (org-show-context 'agenda)
  6853. (save-excursion
  6854. (and (outline-next-heading)
  6855. (org-flag-heading nil))) ; show the next heading
  6856. (let ((current-prefix-arg arg))
  6857. (call-interactively 'org-todo))
  6858. (and (bolp) (forward-char 1))
  6859. (setq newhead (org-get-heading))
  6860. (when (and (org-bound-and-true-p
  6861. org-agenda-headline-snapshot-before-repeat)
  6862. (not (equal org-agenda-headline-snapshot-before-repeat
  6863. newhead))
  6864. todayp)
  6865. (setq newhead org-agenda-headline-snapshot-before-repeat
  6866. just-one t))
  6867. (save-excursion
  6868. (org-back-to-heading)
  6869. (move-marker org-last-heading-marker (point))))
  6870. (beginning-of-line 1)
  6871. (save-excursion
  6872. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6873. (org-move-to-column col))))
  6874. (defun org-agenda-add-note (&optional arg)
  6875. "Add a time-stamped note to the entry at point."
  6876. (interactive "P")
  6877. (org-agenda-check-no-diary)
  6878. (let* ((marker (or (org-get-at-bol 'org-marker)
  6879. (org-agenda-error)))
  6880. (buffer (marker-buffer marker))
  6881. (pos (marker-position marker))
  6882. (hdmarker (org-get-at-bol 'org-hd-marker))
  6883. (inhibit-read-only t))
  6884. (with-current-buffer buffer
  6885. (widen)
  6886. (goto-char pos)
  6887. (org-show-context 'agenda)
  6888. (save-excursion
  6889. (and (outline-next-heading)
  6890. (org-flag-heading nil))) ; show the next heading
  6891. (org-add-note))))
  6892. (defun org-agenda-change-all-lines (newhead hdmarker
  6893. &optional fixface just-this)
  6894. "Change all lines in the agenda buffer which match HDMARKER.
  6895. The new content of the line will be NEWHEAD (as modified by
  6896. `org-agenda-format-item'). HDMARKER is checked with
  6897. `equal' against all `org-hd-marker' text properties in the file.
  6898. If FIXFACE is non-nil, the face of each item is modified according to
  6899. the new TODO state.
  6900. If JUST-THIS is non-nil, change just the current line, not all.
  6901. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6902. (let* ((inhibit-read-only t)
  6903. (line (org-current-line))
  6904. (thetags (with-current-buffer (marker-buffer hdmarker)
  6905. (save-excursion (save-restriction (widen)
  6906. (goto-char hdmarker)
  6907. (org-get-tags-at)))))
  6908. props m pl undone-face done-face finish new dotime cat tags)
  6909. (save-excursion
  6910. (goto-char (point-max))
  6911. (beginning-of-line 1)
  6912. (while (not finish)
  6913. (setq finish (bobp))
  6914. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6915. (or (not just-this) (= (org-current-line) line))
  6916. (equal m hdmarker))
  6917. (setq props (text-properties-at (point))
  6918. dotime (org-get-at-bol 'dotime)
  6919. cat (org-get-at-bol 'org-category)
  6920. tags thetags
  6921. new
  6922. (let ((org-prefix-format-compiled
  6923. (or (get-text-property (point) 'format)
  6924. org-prefix-format-compiled)))
  6925. (with-current-buffer (marker-buffer hdmarker)
  6926. (save-excursion
  6927. (save-restriction
  6928. (widen)
  6929. (org-agenda-format-item (org-get-at-bol 'extra)
  6930. newhead cat tags dotime)))))
  6931. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6932. undone-face (org-get-at-bol 'undone-face)
  6933. done-face (org-get-at-bol 'done-face))
  6934. (beginning-of-line 1)
  6935. (cond
  6936. ((equal new "")
  6937. (and (looking-at ".*\n?") (replace-match "")))
  6938. ((looking-at ".*")
  6939. (replace-match new t t)
  6940. (beginning-of-line 1)
  6941. (add-text-properties (point-at-bol) (point-at-eol) props)
  6942. (when fixface
  6943. (add-text-properties
  6944. (point-at-bol) (point-at-eol)
  6945. (list 'face
  6946. (if org-last-todo-state-is-todo
  6947. undone-face done-face))))
  6948. (org-agenda-highlight-todo 'line)
  6949. (beginning-of-line 1))
  6950. (t (error "Line update did not work"))))
  6951. (beginning-of-line 0)))
  6952. (org-finalize-agenda)))
  6953. (defun org-agenda-align-tags (&optional line)
  6954. "Align all tags in agenda items to `org-agenda-tags-column'."
  6955. (let ((inhibit-read-only t) l c)
  6956. (save-excursion
  6957. (goto-char (if line (point-at-bol) (point-min)))
  6958. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6959. (if line (point-at-eol) nil) t)
  6960. (add-text-properties
  6961. (match-beginning 2) (match-end 2)
  6962. (list 'face (delq nil (let ((prop (get-text-property
  6963. (match-beginning 2) 'face)))
  6964. (or (listp prop) (setq prop (list prop)))
  6965. (if (memq 'org-tag prop)
  6966. prop
  6967. (cons 'org-tag prop))))))
  6968. (setq l (- (match-end 2) (match-beginning 2))
  6969. c (if (< org-agenda-tags-column 0)
  6970. (- (abs org-agenda-tags-column) l)
  6971. org-agenda-tags-column))
  6972. (delete-region (match-beginning 1) (match-end 1))
  6973. (goto-char (match-beginning 1))
  6974. (insert (org-add-props
  6975. (make-string (max 1 (- c (current-column))) ?\ )
  6976. (plist-put (copy-sequence (text-properties-at (point)))
  6977. 'face nil))))
  6978. (goto-char (point-min))
  6979. (org-font-lock-add-tag-faces (point-max)))))
  6980. (defun org-agenda-priority-up ()
  6981. "Increase the priority of line at point, also in Org-mode file."
  6982. (interactive)
  6983. (org-agenda-priority 'up))
  6984. (defun org-agenda-priority-down ()
  6985. "Decrease the priority of line at point, also in Org-mode file."
  6986. (interactive)
  6987. (org-agenda-priority 'down))
  6988. (defun org-agenda-priority (&optional force-direction)
  6989. "Set the priority of line at point, also in Org-mode file.
  6990. This changes the line at point, all other lines in the agenda referring to
  6991. the same tree node, and the headline of the tree node in the Org-mode file."
  6992. (interactive)
  6993. (unless org-enable-priority-commands
  6994. (error "Priority commands are disabled"))
  6995. (org-agenda-check-no-diary)
  6996. (let* ((marker (or (org-get-at-bol 'org-marker)
  6997. (org-agenda-error)))
  6998. (hdmarker (org-get-at-bol 'org-hd-marker))
  6999. (buffer (marker-buffer hdmarker))
  7000. (pos (marker-position hdmarker))
  7001. (inhibit-read-only t)
  7002. newhead)
  7003. (org-with-remote-undo buffer
  7004. (with-current-buffer buffer
  7005. (widen)
  7006. (goto-char pos)
  7007. (org-show-context 'agenda)
  7008. (save-excursion
  7009. (and (outline-next-heading)
  7010. (org-flag-heading nil))) ; show the next heading
  7011. (funcall 'org-priority force-direction)
  7012. (end-of-line 1)
  7013. (setq newhead (org-get-heading)))
  7014. (org-agenda-change-all-lines newhead hdmarker)
  7015. (beginning-of-line 1))))
  7016. ;; FIXME: should fix the tags property of the agenda line.
  7017. (defun org-agenda-set-tags (&optional tag onoff)
  7018. "Set tags for the current headline."
  7019. (interactive)
  7020. (org-agenda-check-no-diary)
  7021. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7022. (call-interactively 'org-change-tag-in-region)
  7023. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7024. (org-agenda-error)))
  7025. (buffer (marker-buffer hdmarker))
  7026. (pos (marker-position hdmarker))
  7027. (inhibit-read-only t)
  7028. newhead)
  7029. (org-with-remote-undo buffer
  7030. (with-current-buffer buffer
  7031. (widen)
  7032. (goto-char pos)
  7033. (save-excursion
  7034. (org-show-context 'agenda))
  7035. (save-excursion
  7036. (and (outline-next-heading)
  7037. (org-flag-heading nil))) ; show the next heading
  7038. (goto-char pos)
  7039. (if tag
  7040. (org-toggle-tag tag onoff)
  7041. (call-interactively 'org-set-tags))
  7042. (end-of-line 1)
  7043. (setq newhead (org-get-heading)))
  7044. (org-agenda-change-all-lines newhead hdmarker)
  7045. (beginning-of-line 1)))))
  7046. (defun org-agenda-set-property ()
  7047. "Set a property for the current headline."
  7048. (interactive)
  7049. (org-agenda-check-no-diary)
  7050. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7051. (org-agenda-error)))
  7052. (buffer (marker-buffer hdmarker))
  7053. (pos (marker-position hdmarker))
  7054. (inhibit-read-only t)
  7055. newhead)
  7056. (org-with-remote-undo buffer
  7057. (with-current-buffer buffer
  7058. (widen)
  7059. (goto-char pos)
  7060. (save-excursion
  7061. (org-show-context 'agenda))
  7062. (save-excursion
  7063. (and (outline-next-heading)
  7064. (org-flag-heading nil))) ; show the next heading
  7065. (goto-char pos)
  7066. (call-interactively 'org-set-property)))))
  7067. (defun org-agenda-set-effort ()
  7068. "Set the effort property for the current headline."
  7069. (interactive)
  7070. (org-agenda-check-no-diary)
  7071. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7072. (org-agenda-error)))
  7073. (buffer (marker-buffer hdmarker))
  7074. (pos (marker-position hdmarker))
  7075. (inhibit-read-only t)
  7076. newhead)
  7077. (org-with-remote-undo buffer
  7078. (with-current-buffer buffer
  7079. (widen)
  7080. (goto-char pos)
  7081. (save-excursion
  7082. (org-show-context 'agenda))
  7083. (save-excursion
  7084. (and (outline-next-heading)
  7085. (org-flag-heading nil))) ; show the next heading
  7086. (goto-char pos)
  7087. (call-interactively 'org-set-effort)
  7088. (end-of-line 1)
  7089. (setq newhead (org-get-heading)))
  7090. (org-agenda-change-all-lines newhead hdmarker))))
  7091. (defun org-agenda-toggle-archive-tag ()
  7092. "Toggle the archive tag for the current entry."
  7093. (interactive)
  7094. (org-agenda-check-no-diary)
  7095. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7096. (org-agenda-error)))
  7097. (buffer (marker-buffer hdmarker))
  7098. (pos (marker-position hdmarker))
  7099. (inhibit-read-only t)
  7100. newhead)
  7101. (org-with-remote-undo buffer
  7102. (with-current-buffer buffer
  7103. (widen)
  7104. (goto-char pos)
  7105. (org-show-context 'agenda)
  7106. (save-excursion
  7107. (and (outline-next-heading)
  7108. (org-flag-heading nil))) ; show the next heading
  7109. (call-interactively 'org-toggle-archive-tag)
  7110. (end-of-line 1)
  7111. (setq newhead (org-get-heading)))
  7112. (org-agenda-change-all-lines newhead hdmarker)
  7113. (beginning-of-line 1))))
  7114. (defun org-agenda-do-date-later (arg)
  7115. (interactive "P")
  7116. (cond
  7117. ((or (equal arg '(16))
  7118. (memq last-command
  7119. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7120. (setq this-command 'org-agenda-date-later-minutes)
  7121. (org-agenda-date-later-minutes 1))
  7122. ((or (equal arg '(4))
  7123. (memq last-command
  7124. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7125. (setq this-command 'org-agenda-date-later-hours)
  7126. (org-agenda-date-later-hours 1))
  7127. (t
  7128. (org-agenda-date-later (prefix-numeric-value arg)))))
  7129. (defun org-agenda-do-date-earlier (arg)
  7130. (interactive "P")
  7131. (cond
  7132. ((or (equal arg '(16))
  7133. (memq last-command
  7134. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7135. (setq this-command 'org-agenda-date-earlier-minutes)
  7136. (org-agenda-date-earlier-minutes 1))
  7137. ((or (equal arg '(4))
  7138. (memq last-command
  7139. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7140. (setq this-command 'org-agenda-date-earlier-hours)
  7141. (org-agenda-date-earlier-hours 1))
  7142. (t
  7143. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7144. (defun org-agenda-date-later (arg &optional what)
  7145. "Change the date of this item to ARG day(s) later."
  7146. (interactive "p")
  7147. (org-agenda-check-type t 'agenda 'timeline)
  7148. (org-agenda-check-no-diary)
  7149. (let* ((marker (or (org-get-at-bol 'org-marker)
  7150. (org-agenda-error)))
  7151. (buffer (marker-buffer marker))
  7152. (pos (marker-position marker))
  7153. cdate today)
  7154. (org-with-remote-undo buffer
  7155. (with-current-buffer buffer
  7156. (widen)
  7157. (goto-char pos)
  7158. (if (not (org-at-timestamp-p))
  7159. (error "Cannot find time stamp"))
  7160. (when (and org-agenda-move-date-from-past-immediately-to-today
  7161. (equal arg 1)
  7162. (or (not what) (eq what 'day))
  7163. (not (save-match-data (org-at-date-range-p))))
  7164. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7165. cdate (calendar-absolute-from-gregorian
  7166. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7167. today (org-today))
  7168. (if (> today cdate)
  7169. ;; immediately shift to today
  7170. (setq arg (- today cdate))))
  7171. (org-timestamp-change arg (or what 'day))
  7172. (when (and (org-at-date-range-p)
  7173. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7174. (let ((end org-last-changed-timestamp))
  7175. (org-timestamp-change arg (or what 'day))
  7176. (setq org-last-changed-timestamp
  7177. (concat org-last-changed-timestamp "--" end)))))
  7178. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7179. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7180. (defun org-agenda-date-earlier (arg &optional what)
  7181. "Change the date of this item to ARG day(s) earlier."
  7182. (interactive "p")
  7183. (org-agenda-date-later (- arg) what))
  7184. (defun org-agenda-date-later-minutes (arg)
  7185. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7186. (interactive "p")
  7187. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7188. (org-agenda-date-later arg 'minute))
  7189. (defun org-agenda-date-earlier-minutes (arg)
  7190. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7191. (interactive "p")
  7192. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7193. (org-agenda-date-earlier arg 'minute))
  7194. (defun org-agenda-date-later-hours (arg)
  7195. "Change the time of this item, in hour steps."
  7196. (interactive "p")
  7197. (org-agenda-date-later arg 'hour))
  7198. (defun org-agenda-date-earlier-hours (arg)
  7199. "Change the time of this item, in hour steps."
  7200. (interactive "p")
  7201. (org-agenda-date-earlier arg 'hour))
  7202. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7203. "Show new date stamp via text properties."
  7204. ;; We use text properties to make this undoable
  7205. (let ((inhibit-read-only t)
  7206. (buffer-invisibility-spec))
  7207. (setq stamp (concat " " prefix " => " stamp))
  7208. (save-excursion
  7209. (goto-char (point-max))
  7210. (while (not (bobp))
  7211. (when (equal marker (org-get-at-bol 'org-marker))
  7212. (org-move-to-column (- (window-width) (length stamp)) t)
  7213. (org-agenda-fix-tags-filter-overlays-at (point))
  7214. (if (featurep 'xemacs)
  7215. ;; Use `duplicable' property to trigger undo recording
  7216. (let ((ex (make-extent nil nil))
  7217. (gl (make-glyph stamp)))
  7218. (set-glyph-face gl 'secondary-selection)
  7219. (set-extent-properties
  7220. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7221. (insert-extent ex (1- (point)) (point-at-eol)))
  7222. (add-text-properties
  7223. (1- (point)) (point-at-eol)
  7224. (list 'display (org-add-props stamp nil
  7225. 'face 'secondary-selection))))
  7226. (beginning-of-line 1))
  7227. (beginning-of-line 0)))))
  7228. (defun org-agenda-date-prompt (arg)
  7229. "Change the date of this item. Date is prompted for, with default today.
  7230. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7231. be used to request time specification in the time stamp."
  7232. (interactive "P")
  7233. (org-agenda-check-type t 'agenda 'timeline)
  7234. (org-agenda-check-no-diary)
  7235. (let* ((marker (or (org-get-at-bol 'org-marker)
  7236. (org-agenda-error)))
  7237. (buffer (marker-buffer marker))
  7238. (pos (marker-position marker)))
  7239. (org-with-remote-undo buffer
  7240. (with-current-buffer buffer
  7241. (widen)
  7242. (goto-char pos)
  7243. (if (not (org-at-timestamp-p t))
  7244. (error "Cannot find time stamp"))
  7245. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7246. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7247. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7248. (defun org-agenda-schedule (arg &optional time)
  7249. "Schedule the item at point.
  7250. ARG is passed through to `org-schedule'."
  7251. (interactive "P")
  7252. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7253. (org-agenda-check-no-diary)
  7254. (let* ((marker (or (org-get-at-bol 'org-marker)
  7255. (org-agenda-error)))
  7256. (type (marker-insertion-type marker))
  7257. (buffer (marker-buffer marker))
  7258. (pos (marker-position marker))
  7259. (org-insert-labeled-timestamps-at-point nil)
  7260. ts)
  7261. (set-marker-insertion-type marker t)
  7262. (org-with-remote-undo buffer
  7263. (with-current-buffer buffer
  7264. (widen)
  7265. (goto-char pos)
  7266. (setq ts (org-schedule arg time)))
  7267. (org-agenda-show-new-time marker ts "S"))
  7268. (message "Item scheduled for %s" ts)))
  7269. (defun org-agenda-deadline (arg &optional time)
  7270. "Schedule the item at point.
  7271. ARG is passed through to `org-deadline'."
  7272. (interactive "P")
  7273. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7274. (org-agenda-check-no-diary)
  7275. (let* ((marker (or (org-get-at-bol 'org-marker)
  7276. (org-agenda-error)))
  7277. (buffer (marker-buffer marker))
  7278. (pos (marker-position marker))
  7279. (org-insert-labeled-timestamps-at-point nil)
  7280. ts)
  7281. (org-with-remote-undo buffer
  7282. (with-current-buffer buffer
  7283. (widen)
  7284. (goto-char pos)
  7285. (setq ts (org-deadline arg time)))
  7286. (org-agenda-show-new-time marker ts "D"))
  7287. (message "Deadline for this item set to %s" ts)))
  7288. (defun org-agenda-action ()
  7289. "Select entry for agenda action, or execute an agenda action.
  7290. This command prompts for another letter. Valid inputs are:
  7291. m Mark the entry at point for an agenda action
  7292. s Schedule the marked entry to the date at the cursor
  7293. d Set the deadline of the marked entry to the date at the cursor
  7294. r Call `org-remember' with cursor date as the default date
  7295. c Call `org-capture' with cursor date as the default date
  7296. SPC Show marked entry in other window
  7297. TAB Visit marked entry in other window
  7298. The cursor may be at a date in the calendar, or in the Org agenda."
  7299. (interactive)
  7300. (let (ans)
  7301. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7302. (setq ans (read-char-exclusive))
  7303. (cond
  7304. ((equal ans ?m)
  7305. ;; Mark this entry
  7306. (if (eq major-mode 'org-agenda-mode)
  7307. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7308. (org-get-at-bol 'org-marker))))
  7309. (if m
  7310. (progn
  7311. (move-marker org-agenda-action-marker
  7312. (marker-position m) (marker-buffer m))
  7313. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7314. (error "Don't know which entry to mark")))
  7315. (error "This command works only in the agenda")))
  7316. ((equal ans ?s)
  7317. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7318. ((equal ans ?d)
  7319. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7320. ((equal ans ?r)
  7321. (org-agenda-do-action '(org-remember) t))
  7322. ((equal ans ?c)
  7323. (org-agenda-do-action '(org-capture) t))
  7324. ((equal ans ?\ )
  7325. (let ((cw (selected-window)))
  7326. (org-switch-to-buffer-other-window
  7327. (marker-buffer org-agenda-action-marker))
  7328. (goto-char org-agenda-action-marker)
  7329. (org-show-context 'agenda)
  7330. (select-window cw)))
  7331. ((equal ans ?\C-i)
  7332. (org-switch-to-buffer-other-window
  7333. (marker-buffer org-agenda-action-marker))
  7334. (goto-char org-agenda-action-marker)
  7335. (org-show-context 'agenda))
  7336. (t (error "Invalid agenda action %c" ans)))))
  7337. (defun org-agenda-do-action (form &optional current-buffer)
  7338. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7339. (let ((org-overriding-default-time (org-get-cursor-date)))
  7340. (if current-buffer
  7341. (eval form)
  7342. (if (not (marker-buffer org-agenda-action-marker))
  7343. (error "No entry has been selected for agenda action")
  7344. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7345. (save-excursion
  7346. (save-restriction
  7347. (widen)
  7348. (goto-char org-agenda-action-marker)
  7349. (eval form))))))))
  7350. (defun org-agenda-clock-in (&optional arg)
  7351. "Start the clock on the currently selected item."
  7352. (interactive "P")
  7353. (org-agenda-check-no-diary)
  7354. (if (equal arg '(4))
  7355. (org-clock-in arg)
  7356. (let* ((marker (or (org-get-at-bol 'org-marker)
  7357. (org-agenda-error)))
  7358. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7359. marker))
  7360. (pos (marker-position marker))
  7361. newhead)
  7362. (org-with-remote-undo (marker-buffer marker)
  7363. (with-current-buffer (marker-buffer marker)
  7364. (widen)
  7365. (goto-char pos)
  7366. (org-show-context 'agenda)
  7367. (org-show-entry)
  7368. (org-cycle-hide-drawers 'children)
  7369. (org-clock-in arg)
  7370. (setq newhead (org-get-heading)))
  7371. (org-agenda-change-all-lines newhead hdmarker)))))
  7372. (defun org-agenda-clock-out ()
  7373. "Stop the currently running clock."
  7374. (interactive)
  7375. (unless (marker-buffer org-clock-marker)
  7376. (error "No running clock"))
  7377. (let ((marker (make-marker)) newhead)
  7378. (org-with-remote-undo (marker-buffer org-clock-marker)
  7379. (with-current-buffer (marker-buffer org-clock-marker)
  7380. (save-excursion
  7381. (save-restriction
  7382. (widen)
  7383. (goto-char org-clock-marker)
  7384. (org-back-to-heading t)
  7385. (move-marker marker (point))
  7386. (org-clock-out)
  7387. (setq newhead (org-get-heading))))))
  7388. (org-agenda-change-all-lines newhead marker)
  7389. (move-marker marker nil)))
  7390. (defun org-agenda-clock-cancel (&optional arg)
  7391. "Cancel the currently running clock."
  7392. (interactive "P")
  7393. (unless (marker-buffer org-clock-marker)
  7394. (error "No running clock"))
  7395. (org-with-remote-undo (marker-buffer org-clock-marker)
  7396. (org-clock-cancel)))
  7397. (defun org-agenda-clock-goto ()
  7398. "Jump to the currently clocked in task within the agenda.
  7399. If the currently clocked in task is not listed in the agenda
  7400. buffer, display it in another window."
  7401. (interactive)
  7402. (let (pos)
  7403. (mapc (lambda (o)
  7404. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7405. (setq pos (overlay-start o))))
  7406. (overlays-in (point-min) (point-max)))
  7407. (cond (pos (goto-char pos))
  7408. ;; If the currently clocked entry is not in the agenda
  7409. ;; buffer, we visit it in another window:
  7410. (org-clock-current-task
  7411. (org-switch-to-buffer-other-window (org-clock-goto)))
  7412. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7413. (defun org-agenda-diary-entry-in-org-file ()
  7414. "Make a diary entry in the file `org-agenda-diary-file'."
  7415. (let (d1 d2 char (text "") dp1 dp2)
  7416. (if (equal (buffer-name) "*Calendar*")
  7417. (setq d1 (calendar-cursor-to-date t)
  7418. d2 (car calendar-mark-ring))
  7419. (setq dp1 (get-text-property (point-at-bol) 'day))
  7420. (unless dp1 (error "No date defined in current line"))
  7421. (setq d1 (calendar-gregorian-from-absolute dp1)
  7422. d2 (and (ignore-errors (mark))
  7423. (save-excursion
  7424. (goto-char (mark))
  7425. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7426. (calendar-gregorian-from-absolute dp2))))
  7427. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7428. (setq char (read-char-exclusive))
  7429. (cond
  7430. ((equal char ?d)
  7431. (setq text (read-string "Day entry: "))
  7432. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7433. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7434. ((equal char ?a)
  7435. (setq d1 (list (car d1) (nth 1 d1)
  7436. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7437. (nth 2 d1))))
  7438. (setq text (read-string "Anniversary (use %d to show years): "))
  7439. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7440. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7441. ((equal char ?b)
  7442. (setq text (read-string "Block entry: "))
  7443. (unless (and d1 d2 (not (equal d1 d2)))
  7444. (error "No block of days selected"))
  7445. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7446. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7447. ((equal char ?j)
  7448. (org-switch-to-buffer-other-window
  7449. (find-file-noselect org-agenda-diary-file))
  7450. (require 'org-datetree)
  7451. (org-datetree-find-date-create d1)
  7452. (org-reveal t))
  7453. (t (error "Invalid selection character `%c'" char)))))
  7454. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7455. "Where in `org-agenda-diary-file' should new entries be added?
  7456. Valid values:
  7457. date-tree in the date tree, as child of the date
  7458. top-level as top-level entries at the end of the file."
  7459. :group 'org-agenda
  7460. :type '(choice
  7461. (const :tag "in a date tree" date-tree)
  7462. (const :tag "as top level at end of file" top-level)))
  7463. (defcustom org-agenda-insert-diary-extract-time nil
  7464. "Non-nil means extract any time specification from the diary entry."
  7465. :group 'org-agenda
  7466. :version "24.1"
  7467. :type 'boolean)
  7468. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7469. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7470. If TEXT is not empty, it will become the headline of the new entry, and
  7471. the resulting entry will not be shown. When TEXT is empty, switch to
  7472. `org-agenda-diary-file' and let the user finish the entry there."
  7473. (let ((cw (current-window-configuration)))
  7474. (org-switch-to-buffer-other-window
  7475. (find-file-noselect org-agenda-diary-file))
  7476. (widen)
  7477. (goto-char (point-min))
  7478. (cond
  7479. ((eq type 'anniversary)
  7480. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7481. (progn
  7482. (or (org-at-heading-p t)
  7483. (progn
  7484. (outline-next-heading)
  7485. (insert "* Anniversaries\n\n")
  7486. (beginning-of-line -1)))))
  7487. (outline-next-heading)
  7488. (org-back-over-empty-lines)
  7489. (backward-char 1)
  7490. (insert "\n")
  7491. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7492. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7493. ((eq type 'day)
  7494. (let ((org-prefix-has-time t)
  7495. (org-agenda-time-leading-zero t)
  7496. fmt time time2)
  7497. (if org-agenda-insert-diary-extract-time
  7498. ;; Use org-agenda-format-item to parse text for a time-range and
  7499. ;; remove it. FIXME: This is a hack, we should refactor
  7500. ;; that function to make time extraction available separately
  7501. (setq fmt (org-agenda-format-item nil text nil nil t)
  7502. time (get-text-property 0 'time fmt)
  7503. time2 (if (> (length time) 0)
  7504. ;; split-string removes trailing ...... if
  7505. ;; no end time given. First space
  7506. ;; separates time from date.
  7507. (concat " " (car (split-string time "\\.")))
  7508. nil)
  7509. text (get-text-property 0 'txt fmt)))
  7510. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7511. (org-agenda-insert-diary-as-top-level text)
  7512. (require 'org-datetree)
  7513. (org-datetree-find-date-create d1)
  7514. (org-agenda-insert-diary-make-new-entry text))
  7515. (org-insert-time-stamp (org-time-from-absolute
  7516. (calendar-absolute-from-gregorian d1))
  7517. nil nil nil nil time2))
  7518. (end-of-line 0))
  7519. ((eq type 'block)
  7520. (if (> (calendar-absolute-from-gregorian d1)
  7521. (calendar-absolute-from-gregorian d2))
  7522. (setq d1 (prog1 d2 (setq d2 d1))))
  7523. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7524. (org-agenda-insert-diary-as-top-level text)
  7525. (require 'org-datetree)
  7526. (org-datetree-find-date-create d1)
  7527. (org-agenda-insert-diary-make-new-entry text))
  7528. (org-insert-time-stamp (org-time-from-absolute
  7529. (calendar-absolute-from-gregorian d1)))
  7530. (insert "--")
  7531. (org-insert-time-stamp (org-time-from-absolute
  7532. (calendar-absolute-from-gregorian d2)))
  7533. (end-of-line 0)))
  7534. (if (string-match "\\S-" text)
  7535. (progn
  7536. (set-window-configuration cw)
  7537. (message "%s entry added to %s"
  7538. (capitalize (symbol-name type))
  7539. (abbreviate-file-name org-agenda-diary-file)))
  7540. (org-reveal t)
  7541. (message "Please finish entry here"))))
  7542. (defun org-agenda-insert-diary-as-top-level (text)
  7543. "Make new entry as a top-level entry at the end of the file.
  7544. Add TEXT as headline, and position the cursor in the second line so that
  7545. a timestamp can be added there."
  7546. (widen)
  7547. (goto-char (point-max))
  7548. (or (bolp) (insert "\n"))
  7549. (insert "* " text "\n")
  7550. (if org-adapt-indentation (org-indent-to-column 2)))
  7551. (defun org-agenda-insert-diary-make-new-entry (text)
  7552. "Make new entry as last child of current entry.
  7553. Add TEXT as headline, and position the cursor in the second line so that
  7554. a timestamp can be added there."
  7555. (let ((org-show-following-heading t)
  7556. (org-show-siblings t)
  7557. (org-show-hierarchy-above t)
  7558. (org-show-entry-below t)
  7559. col)
  7560. (outline-next-heading)
  7561. (org-back-over-empty-lines)
  7562. (or (looking-at "[ \t]*$")
  7563. (progn (insert "\n") (backward-char 1)))
  7564. (org-insert-heading nil t)
  7565. (org-do-demote)
  7566. (setq col (current-column))
  7567. (insert text "\n")
  7568. (if org-adapt-indentation (org-indent-to-column col))
  7569. (let ((org-show-following-heading t)
  7570. (org-show-siblings t)
  7571. (org-show-hierarchy-above t)
  7572. (org-show-entry-below t))
  7573. (org-show-context))))
  7574. (defun org-agenda-diary-entry ()
  7575. "Make a diary entry, like the `i' command from the calendar.
  7576. All the standard commands work: block, weekly etc.
  7577. When `org-agenda-diary-file' points to a file,
  7578. `org-agenda-diary-entry-in-org-file' is called instead to create
  7579. entries in that Org-mode file."
  7580. (interactive)
  7581. (org-agenda-check-type t 'agenda 'timeline)
  7582. (if (not (eq org-agenda-diary-file 'diary-file))
  7583. (org-agenda-diary-entry-in-org-file)
  7584. (require 'diary-lib)
  7585. (let* ((char (progn
  7586. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7587. (read-char-exclusive)))
  7588. (cmd (cdr (assoc char
  7589. '((?d . insert-diary-entry)
  7590. (?w . insert-weekly-diary-entry)
  7591. (?m . insert-monthly-diary-entry)
  7592. (?y . insert-yearly-diary-entry)
  7593. (?a . insert-anniversary-diary-entry)
  7594. (?b . insert-block-diary-entry)
  7595. (?c . insert-cyclic-diary-entry)))))
  7596. (oldf (symbol-function 'calendar-cursor-to-date))
  7597. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7598. (point (point))
  7599. (mark (or (mark t) (point))))
  7600. (unless cmd
  7601. (error "No command associated with <%c>" char))
  7602. (unless (and (get-text-property point 'day)
  7603. (or (not (equal ?b char))
  7604. (get-text-property mark 'day)))
  7605. (error "Don't know which date to use for diary entry"))
  7606. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7607. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7608. (let ((calendar-mark-ring
  7609. (list (calendar-gregorian-from-absolute
  7610. (or (get-text-property mark 'day)
  7611. (get-text-property point 'day))))))
  7612. (unwind-protect
  7613. (progn
  7614. (fset 'calendar-cursor-to-date
  7615. (lambda (&optional error dummy)
  7616. (calendar-gregorian-from-absolute
  7617. (get-text-property point 'day))))
  7618. (call-interactively cmd))
  7619. (fset 'calendar-cursor-to-date oldf))))))
  7620. (defun org-agenda-execute-calendar-command (cmd)
  7621. "Execute a calendar command from the agenda, with the date associated to
  7622. the cursor position."
  7623. (org-agenda-check-type t 'agenda 'timeline)
  7624. (require 'diary-lib)
  7625. (unless (get-text-property (point) 'day)
  7626. (error "Don't know which date to use for calendar command"))
  7627. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7628. (point (point))
  7629. (date (calendar-gregorian-from-absolute
  7630. (get-text-property point 'day)))
  7631. ;; the following 2 vars are needed in the calendar
  7632. (displayed-month (car date))
  7633. (displayed-year (nth 2 date)))
  7634. (unwind-protect
  7635. (progn
  7636. (fset 'calendar-cursor-to-date
  7637. (lambda (&optional error dummy)
  7638. (calendar-gregorian-from-absolute
  7639. (get-text-property point 'day))))
  7640. (call-interactively cmd))
  7641. (fset 'calendar-cursor-to-date oldf))))
  7642. (defun org-agenda-phases-of-moon ()
  7643. "Display the phases of the moon for the 3 months around the cursor date."
  7644. (interactive)
  7645. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7646. (defun org-agenda-holidays ()
  7647. "Display the holidays for the 3 months around the cursor date."
  7648. (interactive)
  7649. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7650. (defvar calendar-longitude)
  7651. (defvar calendar-latitude)
  7652. (defvar calendar-location-name)
  7653. (defun org-agenda-sunrise-sunset (arg)
  7654. "Display sunrise and sunset for the cursor date.
  7655. Latitude and longitude can be specified with the variables
  7656. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7657. argument, latitude and longitude will be prompted for."
  7658. (interactive "P")
  7659. (require 'solar)
  7660. (let ((calendar-longitude (if arg nil calendar-longitude))
  7661. (calendar-latitude (if arg nil calendar-latitude))
  7662. (calendar-location-name
  7663. (if arg "the given coordinates" calendar-location-name)))
  7664. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7665. (defun org-agenda-goto-calendar ()
  7666. "Open the Emacs calendar with the date at the cursor."
  7667. (interactive)
  7668. (org-agenda-check-type t 'agenda 'timeline)
  7669. (let* ((day (or (get-text-property (point) 'day)
  7670. (error "Don't know which date to open in calendar")))
  7671. (date (calendar-gregorian-from-absolute day))
  7672. (calendar-move-hook nil)
  7673. (calendar-view-holidays-initially-flag nil)
  7674. (calendar-view-diary-initially-flag nil))
  7675. (calendar)
  7676. (calendar-goto-date date)))
  7677. ;;;###autoload
  7678. (defun org-calendar-goto-agenda ()
  7679. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7680. This is a command that has to be installed in `calendar-mode-map'."
  7681. (interactive)
  7682. (org-agenda-list nil (calendar-absolute-from-gregorian
  7683. (calendar-cursor-to-date))
  7684. nil))
  7685. (defun org-agenda-convert-date ()
  7686. (interactive)
  7687. (org-agenda-check-type t 'agenda 'timeline)
  7688. (let ((day (get-text-property (point) 'day))
  7689. date s)
  7690. (unless day
  7691. (error "Don't know which date to convert"))
  7692. (setq date (calendar-gregorian-from-absolute day))
  7693. (setq s (concat
  7694. "Gregorian: " (calendar-date-string date) "\n"
  7695. "ISO: " (calendar-iso-date-string date) "\n"
  7696. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7697. "Julian: " (calendar-julian-date-string date) "\n"
  7698. "Astron. JD: " (calendar-astro-date-string date)
  7699. " (Julian date number at noon UTC)\n"
  7700. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7701. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7702. "French: " (calendar-french-date-string date) "\n"
  7703. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7704. "Mayan: " (calendar-mayan-date-string date) "\n"
  7705. "Coptic: " (calendar-coptic-date-string date) "\n"
  7706. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7707. "Persian: " (calendar-persian-date-string date) "\n"
  7708. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7709. (with-output-to-temp-buffer "*Dates*"
  7710. (princ s))
  7711. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7712. ;;; Bulk commands
  7713. (defvar org-agenda-bulk-marked-entries nil
  7714. "List of markers that refer to marked entries in the agenda.")
  7715. (defun org-agenda-bulk-marked-p ()
  7716. (eq (get-char-property (point-at-bol) 'type)
  7717. 'org-marked-entry-overlay))
  7718. (defun org-agenda-bulk-mark (&optional arg)
  7719. "Mark the entry at point for future bulk action."
  7720. (interactive "p")
  7721. (dotimes (i (max arg 1))
  7722. (unless (org-get-at-bol 'org-agenda-diary-link)
  7723. (let* ((m (org-get-at-bol 'org-hd-marker))
  7724. ov)
  7725. (unless (org-agenda-bulk-marked-p)
  7726. (unless m (error "Nothing to mark at point"))
  7727. (push m org-agenda-bulk-marked-entries)
  7728. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7729. (org-overlay-display ov "> "
  7730. (org-get-todo-face "TODO")
  7731. 'evaporate)
  7732. (overlay-put ov 'type 'org-marked-entry-overlay))
  7733. (beginning-of-line 2)
  7734. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7735. (beginning-of-line 2))
  7736. (message "%d entries marked for bulk action"
  7737. (length org-agenda-bulk-marked-entries))))))
  7738. (defun org-agenda-bulk-mark-regexp (regexp)
  7739. "Mark entries match REGEXP."
  7740. (interactive "sMark entries matching regexp: ")
  7741. (let (entries-marked)
  7742. (save-excursion
  7743. (goto-char (point-min))
  7744. (goto-char (next-single-property-change (point) 'txt))
  7745. (while (re-search-forward regexp nil t)
  7746. (when (string-match regexp (get-text-property (point) 'txt))
  7747. (setq entries-marked (+ entries-marked 1))
  7748. (call-interactively 'org-agenda-bulk-mark))))
  7749. (if (not entries-marked)
  7750. (message "No entry matching this regexp."))))
  7751. (defun org-agenda-bulk-unmark ()
  7752. "Unmark the entry at point for future bulk action."
  7753. (interactive)
  7754. (when (org-agenda-bulk-marked-p)
  7755. (org-agenda-bulk-remove-overlays
  7756. (point-at-bol) (+ 2 (point-at-bol)))
  7757. (setq org-agenda-bulk-marked-entries
  7758. (delete (org-get-at-bol 'org-hd-marker)
  7759. org-agenda-bulk-marked-entries)))
  7760. (beginning-of-line 2)
  7761. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7762. (beginning-of-line 2))
  7763. (message "%d entries marked for bulk action"
  7764. (length org-agenda-bulk-marked-entries)))
  7765. (defun org-agenda-bulk-toggle ()
  7766. "Toggle marking the entry at point for bulk action."
  7767. (interactive)
  7768. (if (org-agenda-bulk-marked-p)
  7769. (org-agenda-bulk-unmark)
  7770. (org-agenda-bulk-mark)))
  7771. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7772. "Remove the mark overlays between BEG and END in the agenda buffer.
  7773. BEG and END default to the buffer limits.
  7774. This only removes the overlays, it does not remove the markers
  7775. from the list in `org-agenda-bulk-marked-entries'."
  7776. (interactive)
  7777. (mapc (lambda (ov)
  7778. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7779. (delete-overlay ov)))
  7780. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7781. (defun org-agenda-bulk-remove-all-marks ()
  7782. "Remove all marks in the agenda buffer.
  7783. This will remove the markers, and the overlays."
  7784. (interactive)
  7785. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7786. (setq org-agenda-bulk-marked-entries nil)
  7787. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7788. (defun org-agenda-bulk-action (&optional arg)
  7789. "Execute an remote-editing action on all marked entries.
  7790. The prefix arg is passed through to the command if possible."
  7791. (interactive "P")
  7792. ;; Make sure we have markers, and only valid ones
  7793. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7794. (mapc
  7795. (lambda (m)
  7796. (unless (and (markerp m)
  7797. (marker-buffer m)
  7798. (buffer-live-p (marker-buffer m))
  7799. (marker-position m))
  7800. (error "Marker %s for bulk command is invalid" m)))
  7801. org-agenda-bulk-marked-entries)
  7802. ;; Prompt for the bulk command
  7803. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7804. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7805. (when org-agenda-bulk-custom-functions
  7806. (concat " Custom: ["
  7807. (mapconcat (lambda(f) (char-to-string (car f)))
  7808. org-agenda-bulk-custom-functions "")
  7809. "]"))))
  7810. (let* ((action (read-char-exclusive))
  7811. (org-log-refile (if org-log-refile 'time nil))
  7812. (entries (reverse org-agenda-bulk-marked-entries))
  7813. redo-at-end
  7814. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7815. (cond
  7816. ((equal action ?$)
  7817. (setq cmd '(org-agenda-archive)))
  7818. ((equal action ?A)
  7819. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7820. ((member action '(?r ?w))
  7821. (setq rfloc (org-refile-get-location
  7822. "Refile to"
  7823. (marker-buffer (car org-agenda-bulk-marked-entries))
  7824. org-refile-allow-creating-parent-nodes))
  7825. (if (nth 3 rfloc)
  7826. (setcar (nthcdr 3 rfloc)
  7827. (move-marker (make-marker) (nth 3 rfloc)
  7828. (or (get-file-buffer (nth 1 rfloc))
  7829. (find-buffer-visiting (nth 1 rfloc))
  7830. (error "This should not happen")))))
  7831. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7832. redo-at-end t))
  7833. ((equal action ?t)
  7834. (setq state (org-icompleting-read
  7835. "Todo state: "
  7836. (with-current-buffer (marker-buffer (car entries))
  7837. (mapcar 'list org-todo-keywords-1))))
  7838. (setq cmd `(let ((org-inhibit-blocking t)
  7839. (org-inhibit-logging 'note))
  7840. (org-agenda-todo ,state))))
  7841. ((memq action '(?- ?+))
  7842. (setq tag (org-icompleting-read
  7843. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7844. (with-current-buffer (marker-buffer (car entries))
  7845. (delq nil
  7846. (mapcar (lambda (x)
  7847. (if (stringp (car x)) x)) org-tag-alist)))))
  7848. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7849. ((memq action '(?s ?d))
  7850. (let* ((date (unless arg
  7851. (org-read-date
  7852. nil nil nil
  7853. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7854. (ans (if arg nil org-read-date-final-answer))
  7855. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7856. (setq cmd `(let* ((bound (fboundp 'read-string))
  7857. (old (and bound (symbol-function 'read-string))))
  7858. (unwind-protect
  7859. (progn
  7860. (fset 'read-string (lambda (&rest ignore) ,ans))
  7861. (eval '(,c1 arg)))
  7862. (if bound
  7863. (fset 'read-string old)
  7864. (fmakunbound 'read-string)))))))
  7865. ((equal action ?S)
  7866. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7867. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7868. (let ((days (read-number
  7869. (format "Scatter tasks across how many %sdays: "
  7870. (if arg "week" "")) 7)))
  7871. (setq cmd
  7872. `(let ((distance (1+ (random ,days))))
  7873. (if arg
  7874. (let ((dist distance)
  7875. (day-of-week
  7876. (calendar-day-of-week
  7877. (calendar-gregorian-from-absolute (org-today)))))
  7878. (dotimes (i (1+ dist))
  7879. (while (member day-of-week org-agenda-weekend-days)
  7880. (incf distance)
  7881. (incf day-of-week)
  7882. (if (= day-of-week 7)
  7883. (setq day-of-week 0)))
  7884. (incf day-of-week)
  7885. (if (= day-of-week 7)
  7886. (setq day-of-week 0)))))
  7887. ;; silently fail when try to replan a sexp entry
  7888. (condition-case nil
  7889. (let* ((date (calendar-gregorian-from-absolute
  7890. (+ (org-today) distance)))
  7891. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7892. (nth 2 date))))
  7893. (org-agenda-schedule nil time))
  7894. (error nil)))))))
  7895. ((assoc action org-agenda-bulk-custom-functions)
  7896. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7897. redo-at-end t))
  7898. ((equal action ?f)
  7899. (setq cmd (list (intern
  7900. (org-icompleting-read "Function: "
  7901. obarray 'fboundp t nil nil)))))
  7902. (t (error "Invalid bulk action")))
  7903. ;; Sort the markers, to make sure that parents are handled before children
  7904. (setq entries (sort entries
  7905. (lambda (a b)
  7906. (cond
  7907. ((equal (marker-buffer a) (marker-buffer b))
  7908. (< (marker-position a) (marker-position b)))
  7909. (t
  7910. (string< (buffer-name (marker-buffer a))
  7911. (buffer-name (marker-buffer b))))))))
  7912. ;; Now loop over all markers and apply cmd
  7913. (while (setq e (pop entries))
  7914. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7915. (if (not pos)
  7916. (progn (message "Skipping removed entry at %s" e)
  7917. (setq cntskip (1+ cntskip)))
  7918. (goto-char pos)
  7919. (let (org-loop-over-headlines-in-active-region)
  7920. (eval cmd))
  7921. (setq org-agenda-bulk-marked-entries
  7922. (delete e org-agenda-bulk-marked-entries))
  7923. (setq cnt (1+ cnt))))
  7924. (setq org-agenda-bulk-marked-entries nil)
  7925. (org-agenda-bulk-remove-all-marks)
  7926. (when redo-at-end (org-agenda-redo))
  7927. (message "Acted on %d entries%s"
  7928. cnt
  7929. (if (= cntskip 0)
  7930. ""
  7931. (format ", skipped %d (disappeared before their turn)"
  7932. cntskip)))))
  7933. ;;; Flagging notes
  7934. (defun org-agenda-show-the-flagging-note ()
  7935. "Display the flagging note in the other window.
  7936. When called a second time in direct sequence, offer to remove the FLAGGING
  7937. tag and (if present) the flagging note."
  7938. (interactive)
  7939. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7940. (win (selected-window))
  7941. note heading newhead)
  7942. (unless hdmarker
  7943. (error "No linked entry at point"))
  7944. (if (and (eq this-command last-command)
  7945. (y-or-n-p "Unflag and remove any flagging note? "))
  7946. (progn
  7947. (org-agenda-remove-flag hdmarker)
  7948. (let ((win (get-buffer-window "*Flagging Note*")))
  7949. (and win (delete-window win)))
  7950. (message "Entry unflagged"))
  7951. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7952. (unless note
  7953. (error "No flagging note"))
  7954. (org-kill-new note)
  7955. (org-switch-to-buffer-other-window "*Flagging Note*")
  7956. (erase-buffer)
  7957. (insert note)
  7958. (goto-char (point-min))
  7959. (while (re-search-forward "\\\\n" nil t)
  7960. (replace-match "\n" t t))
  7961. (goto-char (point-min))
  7962. (select-window win)
  7963. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7964. (defun org-agenda-remove-flag (marker)
  7965. "Remove the FLAGGED tag and any flagging note in the entry."
  7966. (let (newhead)
  7967. (org-with-point-at marker
  7968. (org-toggle-tag "FLAGGED" 'off)
  7969. (org-entry-delete nil "THEFLAGGINGNOTE")
  7970. (setq newhead (org-get-heading)))
  7971. (org-agenda-change-all-lines newhead marker)
  7972. (message "Entry unflagged")))
  7973. (defun org-agenda-get-any-marker (&optional pos)
  7974. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7975. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7976. ;;; Appointment reminders
  7977. (defvar appt-time-msg-list)
  7978. ;;;###autoload
  7979. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  7980. "Activate appointments found in `org-agenda-files'.
  7981. With a \\[universal-argument] prefix, refresh the list of
  7982. appointments.
  7983. If FILTER is t, interactively prompt the user for a regular
  7984. expression, and filter out entries that don't match it.
  7985. If FILTER is a string, use this string as a regular expression
  7986. for filtering entries out.
  7987. If FILTER is a function, filter out entries against which
  7988. calling the function returns nil. This function takes one
  7989. argument: an entry from `org-agenda-get-day-entries'.
  7990. FILTER can also be an alist with the car of each cell being
  7991. either 'headline or 'category. For example:
  7992. '((headline \"IMPORTANT\")
  7993. (category \"Work\"))
  7994. will only add headlines containing IMPORTANT or headlines
  7995. belonging to the \"Work\" category.
  7996. ARGS are symbols indicating what kind of entries to consider.
  7997. By default `org-agenda-to-appt' will use :deadline, :scheduled
  7998. and :timestamp entries. See the docstring of `org-diary' for
  7999. details and examples."
  8000. (interactive "P")
  8001. (if refresh (setq appt-time-msg-list nil))
  8002. (if (eq filter t)
  8003. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8004. (let* ((cnt 0) ; count added events
  8005. (scope (or args '(:deadline :scheduled :timestamp)))
  8006. (org-agenda-new-buffers nil)
  8007. (org-deadline-warning-days 0)
  8008. ;; Do not use `org-today' here because appt only takes
  8009. ;; time and without date as argument, so it may pass wrong
  8010. ;; information otherwise
  8011. (today (org-date-to-gregorian
  8012. (time-to-days (current-time))))
  8013. (org-agenda-restrict nil)
  8014. (files (org-agenda-files 'unrestricted)) entries file)
  8015. ;; Get all entries which may contain an appt
  8016. (org-prepare-agenda-buffers files)
  8017. (while (setq file (pop files))
  8018. (setq entries
  8019. (delq nil
  8020. (append entries
  8021. (apply 'org-agenda-get-day-entries
  8022. file today scope)))))
  8023. ;; Map thru entries and find if we should filter them out
  8024. (mapc
  8025. (lambda(x)
  8026. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8027. (cat (get-text-property 1 'org-category x))
  8028. (tod (get-text-property 1 'time-of-day x))
  8029. (ok (or (null filter)
  8030. (and (stringp filter) (string-match filter evt))
  8031. (and (functionp filter) (funcall filter x))
  8032. (and (listp filter)
  8033. (let ((cat-filter (cadr (assoc 'category filter)))
  8034. (evt-filter (cadr (assoc 'headline filter))))
  8035. (or (and (stringp cat-filter)
  8036. (string-match cat-filter cat))
  8037. (and (stringp evt-filter)
  8038. (string-match evt-filter evt))))))))
  8039. ;; FIXME: Shall we remove text-properties for the appt text?
  8040. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8041. (when (and ok tod)
  8042. (setq tod (concat "00" (number-to-string tod))
  8043. tod (when (string-match
  8044. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8045. (concat (match-string 1 tod) ":"
  8046. (match-string 2 tod))))
  8047. (appt-add tod evt)
  8048. (setq cnt (1+ cnt))))) entries)
  8049. (org-release-buffers org-agenda-new-buffers)
  8050. (if (eq cnt 0)
  8051. (message "No event to add")
  8052. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8053. (defun org-agenda-todayp (date)
  8054. "Does DATE mean today, when considering `org-extend-today-until'?"
  8055. (let ((today (org-today))
  8056. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8057. date)))
  8058. (eq date today)))
  8059. (defun org-agenda-todo-yesterday (&optional arg)
  8060. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8061. (interactive "P")
  8062. (let* ((hour (third (decode-time
  8063. (org-current-time))))
  8064. (org-extend-today-until (1+ hour)))
  8065. (org-agenda-todo arg)))
  8066. (provide 'org-agenda)
  8067. ;;; org-agenda.el ends here