org-agenda.el 332 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667
  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 no 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. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5471. x (or pl 0)) pl))
  5472. (add-text-properties
  5473. (or (match-end 1) (match-end 0)) (match-end 0)
  5474. (list 'face (org-get-todo-face (match-string 2 x)))
  5475. x)
  5476. (when (match-end 1)
  5477. (setq x (concat (substring x 0 (match-end 1))
  5478. (format org-agenda-todo-keyword-format
  5479. (match-string 2 x))
  5480. (org-add-props " " (text-properties-at 0 x))
  5481. (substring x (match-end 3)))))))
  5482. x)))
  5483. (defsubst org-cmp-priority (a b)
  5484. "Compare the priorities of string A and B."
  5485. (let ((pa (or (get-text-property 1 'priority a) 0))
  5486. (pb (or (get-text-property 1 'priority b) 0)))
  5487. (cond ((> pa pb) +1)
  5488. ((< pa pb) -1)
  5489. (t nil))))
  5490. (defsubst org-cmp-effort (a b)
  5491. "Compare the effort values of string A and B."
  5492. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5493. (ea (or (get-text-property 1 'effort-minutes a) def))
  5494. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5495. (cond ((> ea eb) +1)
  5496. ((< ea eb) -1)
  5497. (t nil))))
  5498. (defsubst org-cmp-category (a b)
  5499. "Compare the string values of categories of strings A and B."
  5500. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5501. (cb (or (get-text-property 1 'org-category b) "")))
  5502. (cond ((string-lessp ca cb) -1)
  5503. ((string-lessp cb ca) +1)
  5504. (t nil))))
  5505. (defsubst org-cmp-todo-state (a b)
  5506. "Compare the todo states of strings A and B."
  5507. (let* ((ma (or (get-text-property 1 'org-marker a)
  5508. (get-text-property 1 'org-hd-marker a)))
  5509. (mb (or (get-text-property 1 'org-marker b)
  5510. (get-text-property 1 'org-hd-marker b)))
  5511. (fa (and ma (marker-buffer ma)))
  5512. (fb (and mb (marker-buffer mb)))
  5513. (todo-kwds
  5514. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5515. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5516. (ta (or (get-text-property 1 'todo-state a) ""))
  5517. (tb (or (get-text-property 1 'todo-state b) ""))
  5518. (la (- (length (member ta todo-kwds))))
  5519. (lb (- (length (member tb todo-kwds))))
  5520. (donepa (member ta org-done-keywords-for-agenda))
  5521. (donepb (member tb org-done-keywords-for-agenda)))
  5522. (cond ((and donepa (not donepb)) -1)
  5523. ((and (not donepa) donepb) +1)
  5524. ((< la lb) -1)
  5525. ((< lb la) +1)
  5526. (t nil))))
  5527. (defsubst org-cmp-alpha (a b)
  5528. "Compare the headlines, alphabetically."
  5529. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5530. (plb (text-property-any 0 (length b) 'org-heading t b))
  5531. (ta (and pla (substring a pla)))
  5532. (tb (and plb (substring b plb))))
  5533. (when pla
  5534. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5535. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5536. (setq ta (substring ta (match-end 0))))
  5537. (setq ta (downcase ta)))
  5538. (when plb
  5539. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5540. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5541. (setq tb (substring tb (match-end 0))))
  5542. (setq tb (downcase tb)))
  5543. (cond ((not ta) +1)
  5544. ((not tb) -1)
  5545. ((string-lessp ta tb) -1)
  5546. ((string-lessp tb ta) +1)
  5547. (t nil))))
  5548. (defsubst org-cmp-tag (a b)
  5549. "Compare the string values of the first tags of A and B."
  5550. (let ((ta (car (last (get-text-property 1 'tags a))))
  5551. (tb (car (last (get-text-property 1 'tags b)))))
  5552. (cond ((not ta) +1)
  5553. ((not tb) -1)
  5554. ((string-lessp ta tb) -1)
  5555. ((string-lessp tb ta) +1)
  5556. (t nil))))
  5557. (defsubst org-cmp-time (a b)
  5558. "Compare the time-of-day values of strings A and B."
  5559. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5560. (ta (or (get-text-property 1 'time-of-day a) def))
  5561. (tb (or (get-text-property 1 'time-of-day b) def)))
  5562. (cond ((< ta tb) -1)
  5563. ((< tb ta) +1)
  5564. (t nil))))
  5565. (defsubst org-cmp-habit-p (a b)
  5566. "Compare the todo states of strings A and B."
  5567. (let ((ha (get-text-property 1 'org-habit-p a))
  5568. (hb (get-text-property 1 'org-habit-p b)))
  5569. (cond ((and ha (not hb)) -1)
  5570. ((and (not ha) hb) +1)
  5571. (t nil))))
  5572. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5573. (defun org-entries-lessp (a b)
  5574. "Predicate for sorting agenda entries."
  5575. ;; The following variables will be used when the form is evaluated.
  5576. ;; So even though the compiler complains, keep them.
  5577. (let* ((ss org-agenda-sorting-strategy-selected)
  5578. (time-up (and (org-em 'time-up 'time-down ss)
  5579. (org-cmp-time a b)))
  5580. (time-down (if time-up (- time-up) nil))
  5581. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5582. (org-cmp-priority a b)))
  5583. (priority-down (if priority-up (- priority-up) nil))
  5584. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5585. (org-cmp-effort a b)))
  5586. (effort-down (if effort-up (- effort-up) nil))
  5587. (category-up (and (or (org-em 'category-up 'category-down ss)
  5588. (memq 'category-keep ss))
  5589. (org-cmp-category a b)))
  5590. (category-down (if category-up (- category-up) nil))
  5591. (category-keep (if category-up +1 nil))
  5592. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5593. (org-cmp-tag a b)))
  5594. (tag-down (if tag-up (- tag-up) nil))
  5595. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5596. (org-cmp-todo-state a b)))
  5597. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5598. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5599. (org-cmp-habit-p a b)))
  5600. (habit-down (if habit-up (- habit-up) nil))
  5601. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5602. (org-cmp-alpha a b)))
  5603. (alpha-down (if alpha-up (- alpha-up) nil))
  5604. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5605. user-defined-up user-defined-down)
  5606. (if (and need-user-cmp org-agenda-cmp-user-defined
  5607. (functionp org-agenda-cmp-user-defined))
  5608. (setq user-defined-up
  5609. (funcall org-agenda-cmp-user-defined a b)
  5610. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5611. (cdr (assoc
  5612. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5613. '((-1 . t) (1 . nil) (nil . nil))))))
  5614. ;;; Agenda restriction lock
  5615. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5616. "Overlay to mark the headline to which agenda commands are restricted.")
  5617. (overlay-put org-agenda-restriction-lock-overlay
  5618. 'face 'org-agenda-restriction-lock)
  5619. (overlay-put org-agenda-restriction-lock-overlay
  5620. 'help-echo "Agendas are currently limited to this subtree.")
  5621. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5622. (defun org-agenda-set-restriction-lock (&optional type)
  5623. "Set restriction lock for agenda, to current subtree or file.
  5624. Restriction will be the file if TYPE is `file', or if type is the
  5625. universal prefix '(4), or if the cursor is before the first headline
  5626. in the file. Otherwise, restriction will be to the current subtree."
  5627. (interactive "P")
  5628. (and (equal type '(4)) (setq type 'file))
  5629. (setq type (cond
  5630. (type type)
  5631. ((org-at-heading-p) 'subtree)
  5632. ((condition-case nil (org-back-to-heading t) (error nil))
  5633. 'subtree)
  5634. (t 'file)))
  5635. (if (eq type 'subtree)
  5636. (progn
  5637. (setq org-agenda-restrict t)
  5638. (setq org-agenda-overriding-restriction 'subtree)
  5639. (put 'org-agenda-files 'org-restrict
  5640. (list (buffer-file-name (buffer-base-buffer))))
  5641. (org-back-to-heading t)
  5642. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5643. (move-marker org-agenda-restrict-begin (point))
  5644. (move-marker org-agenda-restrict-end
  5645. (save-excursion (org-end-of-subtree t)))
  5646. (message "Locking agenda restriction to subtree"))
  5647. (put 'org-agenda-files 'org-restrict
  5648. (list (buffer-file-name (buffer-base-buffer))))
  5649. (setq org-agenda-restrict nil)
  5650. (setq org-agenda-overriding-restriction 'file)
  5651. (move-marker org-agenda-restrict-begin nil)
  5652. (move-marker org-agenda-restrict-end nil)
  5653. (message "Locking agenda restriction to file"))
  5654. (setq current-prefix-arg nil)
  5655. (org-agenda-maybe-redo))
  5656. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5657. "Remove the agenda restriction lock."
  5658. (interactive "P")
  5659. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5660. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5661. (setq org-agenda-overriding-restriction nil)
  5662. (setq org-agenda-restrict nil)
  5663. (put 'org-agenda-files 'org-restrict nil)
  5664. (move-marker org-agenda-restrict-begin nil)
  5665. (move-marker org-agenda-restrict-end nil)
  5666. (setq current-prefix-arg nil)
  5667. (message "Agenda restriction lock removed")
  5668. (or noupdate (org-agenda-maybe-redo)))
  5669. (defun org-agenda-maybe-redo ()
  5670. "If there is any window showing the agenda view, update it."
  5671. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5672. (w0 (selected-window)))
  5673. (when w
  5674. (select-window w)
  5675. (org-agenda-redo)
  5676. (select-window w0)
  5677. (if org-agenda-overriding-restriction
  5678. (message "Agenda view shifted to new %s restriction"
  5679. org-agenda-overriding-restriction)
  5680. (message "Agenda restriction lock removed")))))
  5681. ;;; Agenda commands
  5682. (defun org-agenda-check-type (error &rest types)
  5683. "Check if agenda buffer is of allowed type.
  5684. If ERROR is non-nil, throw an error, otherwise just return nil."
  5685. (if (memq org-agenda-type types)
  5686. t
  5687. (if error
  5688. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5689. nil)))
  5690. (defun org-agenda-quit ()
  5691. "Exit agenda by removing the window or the buffer."
  5692. (interactive)
  5693. (if org-agenda-columns-active
  5694. (org-columns-quit)
  5695. (let ((buf (current-buffer)))
  5696. (if (eq org-agenda-window-setup 'other-frame)
  5697. (progn
  5698. (kill-buffer buf)
  5699. (org-agenda-reset-markers)
  5700. (org-columns-remove-overlays)
  5701. (setq org-agenda-archives-mode nil)
  5702. (delete-frame))
  5703. (and (not (eq org-agenda-window-setup 'current-window))
  5704. (not (one-window-p))
  5705. (delete-window))
  5706. (kill-buffer buf)
  5707. (org-agenda-reset-markers)
  5708. (org-columns-remove-overlays)
  5709. (setq org-agenda-archives-mode nil)))
  5710. ;; Maybe restore the pre-agenda window configuration.
  5711. (and org-agenda-restore-windows-after-quit
  5712. (not (eq org-agenda-window-setup 'other-frame))
  5713. org-pre-agenda-window-conf
  5714. (set-window-configuration org-pre-agenda-window-conf))))
  5715. (defun org-agenda-exit ()
  5716. "Exit agenda by removing the window or the buffer.
  5717. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5718. Org-mode buffers visited directly by the user will not be touched."
  5719. (interactive)
  5720. (org-release-buffers org-agenda-new-buffers)
  5721. (setq org-agenda-new-buffers nil)
  5722. (org-agenda-quit))
  5723. (defun org-agenda-execute (arg)
  5724. "Execute another agenda command, keeping same window.
  5725. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5726. in the agenda."
  5727. (interactive "P")
  5728. (let ((org-agenda-window-setup 'current-window))
  5729. (org-agenda arg)))
  5730. (defun org-agenda-redo ()
  5731. "Rebuild Agenda.
  5732. When this is the global TODO list, a prefix argument will be interpreted."
  5733. (interactive)
  5734. (let* ((org-agenda-keep-modes t)
  5735. (tag-filter org-agenda-tag-filter)
  5736. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5737. (cat-filter org-agenda-category-filter)
  5738. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5739. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5740. (cols org-agenda-columns-active)
  5741. (line (org-current-line))
  5742. (window-line (- line (org-current-line (window-start))))
  5743. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5744. (put 'org-agenda-tag-filter :preset-filter nil)
  5745. (put 'org-agenda-category-filter :preset-filter nil)
  5746. (and cols (org-columns-quit))
  5747. (message "Rebuilding agenda buffer...")
  5748. (org-let lprops '(eval org-agenda-redo-command))
  5749. (setq org-agenda-undo-list nil
  5750. org-agenda-pending-undo-list nil)
  5751. (message "Rebuilding agenda buffer...done")
  5752. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5753. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5754. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5755. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5756. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5757. (org-goto-line line)
  5758. (recenter window-line)))
  5759. (defvar org-global-tags-completion-table nil)
  5760. (defvar org-agenda-filtered-by-category nil)
  5761. (defvar org-agenda-filter-form nil)
  5762. (defun org-agenda-filter-by-category (strip)
  5763. "Keep only those lines in the agenda buffer that have a specific category.
  5764. The category is that of the current line."
  5765. (interactive "P")
  5766. (if org-agenda-filtered-by-category
  5767. (org-agenda-filter-show-all-cat)
  5768. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  5769. (if cat (org-agenda-filter-apply
  5770. (list (concat (if strip "-" "+") cat)) 'category)
  5771. (error "No category at point")))))
  5772. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5773. "Keep only those lines in the agenda buffer that have a specific tag.
  5774. The tag is selected with its fast selection letter, as configured.
  5775. With prefix argument STRIP, remove all lines that do have the tag.
  5776. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5777. used to narrow the search - the interactive user can also press `-' or `+'
  5778. to switch to narrowing."
  5779. (interactive "P")
  5780. (let* ((alist org-tag-alist-for-agenda)
  5781. (tag-chars (mapconcat
  5782. (lambda (x) (if (and (not (symbolp (car x)))
  5783. (cdr x))
  5784. (char-to-string (cdr x))
  5785. ""))
  5786. alist ""))
  5787. (efforts (org-split-string
  5788. (or (cdr (assoc (concat org-effort-property "_ALL")
  5789. org-global-properties))
  5790. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5791. "")))
  5792. (effort-op org-agenda-filter-effort-default-operator)
  5793. (effort-prompt "")
  5794. (inhibit-read-only t)
  5795. (current org-agenda-tag-filter)
  5796. maybe-refresh a n tag)
  5797. (unless char
  5798. (message
  5799. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5800. (if narrow "Narrow" "Filter") tag-chars
  5801. (if org-agenda-auto-exclude-function "[RET], " ""))
  5802. (setq char (read-char-exclusive)))
  5803. (when (member char '(?+ ?-))
  5804. ;; Narrowing down
  5805. (cond ((equal char ?-) (setq strip t narrow t))
  5806. ((equal char ?+) (setq strip nil narrow t)))
  5807. (message
  5808. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5809. (setq char (read-char-exclusive)))
  5810. (when (member char '(?< ?> ?= ??))
  5811. ;; An effort operator
  5812. (setq effort-op (char-to-string char))
  5813. (setq alist nil) ; to make sure it will be interpreted as effort.
  5814. (unless (equal char ??)
  5815. (loop for i from 0 to 9 do
  5816. (setq effort-prompt
  5817. (concat
  5818. effort-prompt " ["
  5819. (if (= i 9) "0" (int-to-string (1+ i)))
  5820. "]" (nth i efforts))))
  5821. (message "Effort%s: %s " effort-op effort-prompt)
  5822. (setq char (read-char-exclusive))
  5823. (when (or (< char ?0) (> char ?9))
  5824. (error "Need 1-9,0 to select effort" ))))
  5825. (when (equal char ?\t)
  5826. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5827. (org-set-local 'org-global-tags-completion-table
  5828. (org-global-tags-completion-table)))
  5829. (let ((completion-ignore-case t))
  5830. (setq tag (org-icompleting-read
  5831. "Tag: " org-global-tags-completion-table))))
  5832. (cond
  5833. ((equal char ?\r)
  5834. (org-agenda-filter-show-all-tag)
  5835. (when org-agenda-auto-exclude-function
  5836. (setq org-agenda-tag-filter '())
  5837. (dolist (tag (org-agenda-get-represented-tags))
  5838. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5839. (if modifier
  5840. (push modifier org-agenda-tag-filter))))
  5841. (if (not (null org-agenda-tag-filter))
  5842. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  5843. (setq maybe-refresh t))
  5844. ((equal char ?/)
  5845. (org-agenda-filter-show-all-tag)
  5846. (when (get 'org-agenda-tag-filter :preset-filter)
  5847. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  5848. (setq maybe-refresh t))
  5849. ((equal char ?. )
  5850. (setq org-agenda-tag-filter
  5851. (mapcar (lambda(tag) (concat "+" tag))
  5852. (org-get-at-bol 'tags)))
  5853. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5854. (setq maybe-refresh t))
  5855. ((or (equal char ?\ )
  5856. (setq a (rassoc char alist))
  5857. (and (>= char ?0) (<= char ?9)
  5858. (setq n (if (= char ?0) 9 (- char ?0 1))
  5859. tag (concat effort-op (nth n efforts))
  5860. a (cons tag nil)))
  5861. (and (= char ??)
  5862. (setq tag "?eff")
  5863. a (cons tag nil))
  5864. (and tag (setq a (cons tag nil))))
  5865. (org-agenda-filter-show-all-tag)
  5866. (setq tag (car a))
  5867. (setq org-agenda-tag-filter
  5868. (cons (concat (if strip "-" "+") tag)
  5869. (if narrow current nil)))
  5870. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5871. (setq maybe-refresh t))
  5872. (t (error "Invalid tag selection character %c" char)))
  5873. (when (and maybe-refresh
  5874. (eq org-agenda-clockreport-mode 'with-filter))
  5875. (org-agenda-redo))))
  5876. (defun org-agenda-get-represented-tags ()
  5877. "Get a list of all tags currently represented in the agenda."
  5878. (let (p tags)
  5879. (save-excursion
  5880. (goto-char (point-min))
  5881. (while (setq p (next-single-property-change (point) 'tags))
  5882. (goto-char p)
  5883. (mapc (lambda (x) (add-to-list 'tags x))
  5884. (get-text-property (point) 'tags))))
  5885. tags))
  5886. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5887. "Refine the current filter. See `org-agenda-filter-by-tag'."
  5888. (interactive "P")
  5889. (org-agenda-filter-by-tag strip char 'refine))
  5890. (defun org-agenda-filter-make-matcher ()
  5891. "Create the form that tests a line for agenda filter."
  5892. (let (f f1)
  5893. ;; first compute the tag-filter matcher
  5894. (dolist (x (delete-dups
  5895. (append (get 'org-agenda-tag-filter
  5896. :preset-filter) org-agenda-tag-filter)))
  5897. (if (member x '("-" "+"))
  5898. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5899. (if (string-match "[<=>?]" x)
  5900. (setq f1 (org-agenda-filter-effort-form x))
  5901. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5902. (if (equal (string-to-char x) ?-)
  5903. (setq f1 (list 'not f1))))
  5904. (push f1 f))
  5905. ;; then compute the category-filter matcher
  5906. (dolist (x (delete-dups
  5907. (append (get 'org-agenda-category-filter
  5908. :preset-filter) org-agenda-category-filter)))
  5909. (setq f1 (list 'equal (substring x 1) 'cat))
  5910. (push f1 f))
  5911. (cons 'and (nreverse f))))
  5912. (defun org-agenda-filter-effort-form (e)
  5913. "Return the form to compare the effort of the current line with what E says.
  5914. E looks like \"+<2:25\"."
  5915. (let (op)
  5916. (setq e (substring e 1))
  5917. (setq op (string-to-char e) e (substring e 1))
  5918. (setq op (cond ((equal op ?<) '<=)
  5919. ((equal op ?>) '>=)
  5920. ((equal op ??) op)
  5921. (t '=)))
  5922. (list 'org-agenda-compare-effort (list 'quote op)
  5923. (org-duration-string-to-minutes e))))
  5924. (defun org-agenda-compare-effort (op value)
  5925. "Compare the effort of the current line with VALUE, using OP.
  5926. If the line does not have an effort defined, return nil."
  5927. (let ((eff (org-get-at-bol 'effort-minutes)))
  5928. (if (equal op ??)
  5929. (not eff)
  5930. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5931. value))))
  5932. (defun org-agenda-filter-apply (filter type)
  5933. "Set FILTER as the new agenda filter and apply it."
  5934. (let (tags cat)
  5935. (if (eq type 'tag)
  5936. (setq org-agenda-tag-filter filter)
  5937. (setq org-agenda-category-filter filter
  5938. org-agenda-filtered-by-category t))
  5939. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  5940. (org-agenda-set-mode-name)
  5941. (save-excursion
  5942. (goto-char (point-min))
  5943. (while (not (eobp))
  5944. (if (org-get-at-bol 'org-marker)
  5945. (progn
  5946. (setq tags (org-get-at-bol 'tags) ; used in eval
  5947. cat (get-text-property (point) 'org-category))
  5948. (if (not (eval org-agenda-filter-form))
  5949. (org-agenda-filter-hide-line type))
  5950. (beginning-of-line 2))
  5951. (beginning-of-line 2))))
  5952. (if (get-char-property (point) 'invisible)
  5953. (org-agenda-previous-line))))
  5954. (defun org-agenda-filter-hide-line (type)
  5955. (let (ov)
  5956. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5957. (point-at-eol)))
  5958. (overlay-put ov 'invisible t)
  5959. (overlay-put ov 'type type)
  5960. (if (eq type 'tag)
  5961. (push ov org-agenda-tag-filter-overlays)
  5962. (push ov org-agenda-cat-filter-overlays))))
  5963. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5964. (setq pos (or pos (point)))
  5965. (save-excursion
  5966. (dolist (ov (overlays-at pos))
  5967. (when (and (overlay-get ov 'invisible)
  5968. (eq (overlay-get ov 'type) 'tag))
  5969. (goto-char pos)
  5970. (if (< (overlay-start ov) (point-at-eol))
  5971. (move-overlay ov (point-at-eol)
  5972. (overlay-end ov)))))))
  5973. (defun org-agenda-filter-show-all-tag nil
  5974. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  5975. (setq org-agenda-tag-filter-overlays nil
  5976. org-agenda-tag-filter nil
  5977. org-agenda-filter-form nil)
  5978. (org-agenda-set-mode-name))
  5979. (defun org-agenda-filter-show-all-cat nil
  5980. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  5981. (setq org-agenda-cat-filter-overlays nil
  5982. org-agenda-filtered-by-category nil
  5983. org-agenda-category-filter nil
  5984. org-agenda-filter-form nil)
  5985. (org-agenda-set-mode-name))
  5986. (defun org-agenda-manipulate-query-add ()
  5987. "Manipulate the query by adding a search term with positive selection.
  5988. Positive selection means the term must be matched for selection of an entry."
  5989. (interactive)
  5990. (org-agenda-manipulate-query ?\[))
  5991. (defun org-agenda-manipulate-query-subtract ()
  5992. "Manipulate the query by adding a search term with negative selection.
  5993. Negative selection means term must not be matched for selection of an entry."
  5994. (interactive)
  5995. (org-agenda-manipulate-query ?\]))
  5996. (defun org-agenda-manipulate-query-add-re ()
  5997. "Manipulate the query by adding a search regexp with positive selection.
  5998. Positive selection means the regexp must match for selection of an entry."
  5999. (interactive)
  6000. (org-agenda-manipulate-query ?\{))
  6001. (defun org-agenda-manipulate-query-subtract-re ()
  6002. "Manipulate the query by adding a search regexp with negative selection.
  6003. Negative selection means regexp must not match for selection of an entry."
  6004. (interactive)
  6005. (org-agenda-manipulate-query ?\}))
  6006. (defun org-agenda-manipulate-query (char)
  6007. (cond
  6008. ((memq org-agenda-type '(timeline agenda))
  6009. (let ((org-agenda-include-inactive-timestamps t))
  6010. (org-agenda-redo))
  6011. (message "Display now includes inactive timestamps as well"))
  6012. ((eq org-agenda-type 'search)
  6013. (org-add-to-string
  6014. 'org-agenda-query-string
  6015. (if org-agenda-last-search-view-search-was-boolean
  6016. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6017. (?\{ . " +{}") (?\} . " -{}"))))
  6018. " "))
  6019. (setq org-agenda-redo-command
  6020. (list 'org-search-view
  6021. org-todo-only
  6022. org-agenda-query-string
  6023. (+ (length org-agenda-query-string)
  6024. (if (member char '(?\{ ?\})) 0 1))))
  6025. (set-register org-agenda-query-register org-agenda-query-string)
  6026. (org-agenda-redo))
  6027. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6028. org-agenda-type))))
  6029. (defun org-add-to-string (var string)
  6030. (set var (concat (symbol-value var) string)))
  6031. (defun org-agenda-goto-date (date)
  6032. "Jump to DATE in agenda."
  6033. (interactive (list (let ((org-read-date-prefer-future
  6034. (eval org-agenda-jump-prefer-future)))
  6035. (org-read-date))))
  6036. (org-agenda-list nil date))
  6037. (defun org-agenda-goto-today ()
  6038. "Go to today."
  6039. (interactive)
  6040. (org-agenda-check-type t 'timeline 'agenda)
  6041. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6042. (cond
  6043. (tdpos (goto-char tdpos))
  6044. ((eq org-agenda-type 'agenda)
  6045. (let* ((sd (org-agenda-compute-starting-span
  6046. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6047. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6048. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6049. (org-agenda-redo)
  6050. (org-agenda-find-same-or-today-or-agenda)))
  6051. (t (error "Cannot find today")))))
  6052. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6053. (goto-char
  6054. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6055. (text-property-any (point-min) (point-max) 'org-today t)
  6056. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6057. (point-min))))
  6058. (defun org-agenda-later (arg)
  6059. "Go forward in time by thee current span.
  6060. With prefix ARG, go forward that many times the current span."
  6061. (interactive "p")
  6062. (org-agenda-check-type t 'agenda)
  6063. (let* ((span org-agenda-current-span)
  6064. (sd org-starting-day)
  6065. (greg (calendar-gregorian-from-absolute sd))
  6066. (cnt (org-get-at-bol 'org-day-cnt))
  6067. greg2)
  6068. (cond
  6069. ((eq span 'day)
  6070. (setq sd (+ arg sd)))
  6071. ((eq span 'week)
  6072. (setq sd (+ (* 7 arg) sd)))
  6073. ((eq span 'month)
  6074. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6075. sd (calendar-absolute-from-gregorian greg2))
  6076. (setcar greg2 (1+ (car greg2))))
  6077. ((eq span 'year)
  6078. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6079. sd (calendar-absolute-from-gregorian greg2))
  6080. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6081. (t
  6082. (setq sd (+ (* span arg) sd))))
  6083. (let ((org-agenda-overriding-arguments
  6084. (list (car org-agenda-last-arguments) sd span t)))
  6085. (org-agenda-redo)
  6086. (org-agenda-find-same-or-today-or-agenda cnt))))
  6087. (defun org-agenda-earlier (arg)
  6088. "Go backward in time by the current span.
  6089. With prefix ARG, go backward that many times the current span."
  6090. (interactive "p")
  6091. (org-agenda-later (- arg)))
  6092. (defun org-agenda-view-mode-dispatch ()
  6093. "Call one of the view mode commands."
  6094. (interactive)
  6095. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6096. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6097. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6098. [E]ntryText")
  6099. (let ((a (read-char-exclusive)))
  6100. (case a
  6101. (?\ (call-interactively 'org-agenda-reset-view))
  6102. (?d (call-interactively 'org-agenda-day-view))
  6103. (?w (call-interactively 'org-agenda-week-view))
  6104. (?m (call-interactively 'org-agenda-month-view))
  6105. (?y (call-interactively 'org-agenda-year-view))
  6106. (?l (call-interactively 'org-agenda-log-mode))
  6107. (?L (org-agenda-log-mode '(4)))
  6108. (?c (org-agenda-log-mode 'clockcheck))
  6109. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6110. (?a (call-interactively 'org-agenda-archives-mode))
  6111. (?A (org-agenda-archives-mode 'files))
  6112. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6113. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6114. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6115. (?D (call-interactively 'org-agenda-toggle-diary))
  6116. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6117. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6118. (org-agenda-check-type t 'timeline 'agenda)
  6119. (org-agenda-redo))
  6120. (message "Display now includes inactive timestamps as well"))
  6121. (?q (message "Abort"))
  6122. (otherwise (error "Invalid key" )))))
  6123. (defun org-agenda-reset-view ()
  6124. "Switch to default view for agenda."
  6125. (interactive)
  6126. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6127. (defun org-agenda-day-view (&optional day-of-year)
  6128. "Switch to daily view for agenda.
  6129. With argument DAY-OF-YEAR, switch to that day of the year."
  6130. (interactive "P")
  6131. (org-agenda-change-time-span 'day day-of-year))
  6132. (defun org-agenda-week-view (&optional iso-week)
  6133. "Switch to daily view for agenda.
  6134. With argument ISO-WEEK, switch to the corresponding ISO week.
  6135. If ISO-WEEK has more then 2 digits, only the last two encode the
  6136. week. Any digits before this encode a year. So 200712 means
  6137. week 12 of year 2007. Years in the range 1938-2037 can also be
  6138. written as 2-digit years."
  6139. (interactive "P")
  6140. (org-agenda-change-time-span 'week iso-week))
  6141. (defun org-agenda-month-view (&optional month)
  6142. "Switch to monthly view for agenda.
  6143. With argument MONTH, switch to that month."
  6144. (interactive "P")
  6145. (org-agenda-change-time-span 'month month))
  6146. (defun org-agenda-year-view (&optional year)
  6147. "Switch to yearly view for agenda.
  6148. With argument YEAR, switch to that year.
  6149. If MONTH has more then 2 digits, only the last two encode the
  6150. month. Any digits before this encode a year. So 200712 means
  6151. December year 2007. Years in the range 1938-2037 can also be
  6152. written as 2-digit years."
  6153. (interactive "P")
  6154. (when year
  6155. (setq year (org-small-year-to-year year)))
  6156. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6157. (org-agenda-change-time-span 'year year)
  6158. (error "Abort")))
  6159. (defun org-agenda-change-time-span (span &optional n)
  6160. "Change the agenda view to SPAN.
  6161. SPAN may be `day', `week', `month', `year'."
  6162. (org-agenda-check-type t 'agenda)
  6163. (if (and (not n) (equal org-agenda-current-span span))
  6164. (error "Viewing span is already \"%s\"" span))
  6165. (let* ((sd (or (org-get-at-bol 'day)
  6166. org-starting-day))
  6167. (sd (org-agenda-compute-starting-span sd span n))
  6168. (org-agenda-overriding-arguments
  6169. (or org-agenda-overriding-arguments
  6170. (list (car org-agenda-last-arguments) sd span t))))
  6171. (org-agenda-redo)
  6172. (org-agenda-find-same-or-today-or-agenda))
  6173. (org-agenda-set-mode-name)
  6174. (message "Switched to %s view" span))
  6175. (defun org-agenda-compute-starting-span (sd span &optional n)
  6176. "Compute starting date for agenda.
  6177. SPAN may be `day', `week', `month', `year'. The return value
  6178. is a cons cell with the starting date and the number of days,
  6179. so that the date SD will be in that range."
  6180. (let* ((greg (calendar-gregorian-from-absolute sd))
  6181. (dg (nth 1 greg))
  6182. (mg (car greg))
  6183. (yg (nth 2 greg)))
  6184. (cond
  6185. ((eq span 'day)
  6186. (when n
  6187. (setq sd (+ (calendar-absolute-from-gregorian
  6188. (list mg 1 yg))
  6189. n -1))))
  6190. ((eq span 'week)
  6191. (let* ((nt (calendar-day-of-week
  6192. (calendar-gregorian-from-absolute sd)))
  6193. (d (if org-agenda-start-on-weekday
  6194. (- nt org-agenda-start-on-weekday)
  6195. 0))
  6196. y1)
  6197. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6198. (when n
  6199. (require 'cal-iso)
  6200. (when (> n 99)
  6201. (setq y1 (org-small-year-to-year (/ n 100))
  6202. n (mod n 100)))
  6203. (setq sd
  6204. (calendar-absolute-from-iso
  6205. (list n 1
  6206. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6207. ((eq span 'month)
  6208. (let (y1)
  6209. (when (and n (> n 99))
  6210. (setq y1 (org-small-year-to-year (/ n 100))
  6211. n (mod n 100)))
  6212. (setq sd (calendar-absolute-from-gregorian
  6213. (list (or n mg) 1 (or y1 yg))))))
  6214. ((eq span 'year)
  6215. (setq sd (calendar-absolute-from-gregorian
  6216. (list 1 1 (or n yg))))))
  6217. sd))
  6218. (defun org-agenda-next-date-line (&optional arg)
  6219. "Jump to the next line indicating a date in agenda buffer."
  6220. (interactive "p")
  6221. (org-agenda-check-type t 'agenda 'timeline)
  6222. (beginning-of-line 1)
  6223. ;; This does not work if user makes date format that starts with a blank
  6224. (if (looking-at "^\\S-") (forward-char 1))
  6225. (if (not (re-search-forward "^\\S-" nil t arg))
  6226. (progn
  6227. (backward-char 1)
  6228. (error "No next date after this line in this buffer")))
  6229. (goto-char (match-beginning 0)))
  6230. (defun org-agenda-previous-date-line (&optional arg)
  6231. "Jump to the previous line indicating a date in agenda buffer."
  6232. (interactive "p")
  6233. (org-agenda-check-type t 'agenda 'timeline)
  6234. (beginning-of-line 1)
  6235. (if (not (re-search-backward "^\\S-" nil t arg))
  6236. (error "No previous date before this line in this buffer")))
  6237. ;; Initialize the highlight
  6238. (defvar org-hl (make-overlay 1 1))
  6239. (overlay-put org-hl 'face 'highlight)
  6240. (defun org-highlight (begin end &optional buffer)
  6241. "Highlight a region with overlay."
  6242. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6243. (defun org-unhighlight ()
  6244. "Detach overlay INDEX."
  6245. (org-detach-overlay org-hl))
  6246. ;; FIXME this is currently not used.
  6247. (defun org-highlight-until-next-command (beg end &optional buffer)
  6248. "Move the highlight overlay to BEG/END, remove it before the next command."
  6249. (org-highlight beg end buffer)
  6250. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6251. (defun org-unhighlight-once ()
  6252. "Remove the highlight from its position, and this function from the hook."
  6253. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6254. (org-unhighlight))
  6255. (defun org-agenda-follow-mode ()
  6256. "Toggle follow mode in an agenda buffer."
  6257. (interactive)
  6258. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6259. (org-agenda-set-mode-name)
  6260. (org-agenda-do-context-action)
  6261. (message "Follow mode is %s"
  6262. (if org-agenda-follow-mode "on" "off")))
  6263. (defun org-agenda-entry-text-mode (&optional arg)
  6264. "Toggle entry text mode in an agenda buffer."
  6265. (interactive "P")
  6266. (setq org-agenda-entry-text-mode (or (integerp arg)
  6267. (not org-agenda-entry-text-mode)))
  6268. (org-agenda-entry-text-hide)
  6269. (and org-agenda-entry-text-mode
  6270. (let ((org-agenda-entry-text-maxlines
  6271. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6272. (org-agenda-entry-text-show)))
  6273. (org-agenda-set-mode-name)
  6274. (message "Entry text mode is %s. Maximum number of lines is %d"
  6275. (if org-agenda-entry-text-mode "on" "off")
  6276. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6277. (defun org-agenda-clockreport-mode (&optional with-filter)
  6278. "Toggle clocktable mode in an agenda buffer.
  6279. With prefix arg WITH-FILTER, make the clocktable respect the current
  6280. agenda filter."
  6281. (interactive "P")
  6282. (org-agenda-check-type t 'agenda)
  6283. (if with-filter
  6284. (setq org-agenda-clockreport-mode 'with-filter)
  6285. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6286. (org-agenda-set-mode-name)
  6287. (org-agenda-redo)
  6288. (message "Clocktable mode is %s"
  6289. (if org-agenda-clockreport-mode "on" "off")))
  6290. (defun org-agenda-log-mode (&optional special)
  6291. "Toggle log mode in an agenda buffer.
  6292. With argument SPECIAL, show all possible log items, not only the ones
  6293. configured in `org-agenda-log-mode-items'.
  6294. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6295. (interactive "P")
  6296. (org-agenda-check-type t 'agenda 'timeline)
  6297. (setq org-agenda-show-log
  6298. (cond
  6299. ((equal special '(16)) 'only)
  6300. ((eq special 'clockcheck)
  6301. (if (eq org-agenda-show-log 'clockcheck)
  6302. nil 'clockcheck))
  6303. (special '(closed clock state))
  6304. (t (not org-agenda-show-log))))
  6305. (org-agenda-set-mode-name)
  6306. (org-agenda-redo)
  6307. (message "Log mode is %s"
  6308. (if org-agenda-show-log "on" "off")))
  6309. (defun org-agenda-archives-mode (&optional with-files)
  6310. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6311. When called with a prefix argument, include all archive files as well."
  6312. (interactive "P")
  6313. (setq org-agenda-archives-mode
  6314. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6315. (org-agenda-set-mode-name)
  6316. (org-agenda-redo)
  6317. (message
  6318. "%s"
  6319. (cond
  6320. ((eq org-agenda-archives-mode nil)
  6321. "No archives are included")
  6322. ((eq org-agenda-archives-mode 'trees)
  6323. (format "Trees with :%s: tag are included" org-archive-tag))
  6324. ((eq org-agenda-archives-mode t)
  6325. (format "Trees with :%s: tag and all active archive files are included"
  6326. org-archive-tag)))))
  6327. (defun org-agenda-toggle-diary ()
  6328. "Toggle diary inclusion in an agenda buffer."
  6329. (interactive)
  6330. (org-agenda-check-type t 'agenda)
  6331. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6332. (org-agenda-redo)
  6333. (org-agenda-set-mode-name)
  6334. (message "Diary inclusion turned %s"
  6335. (if org-agenda-include-diary "on" "off")))
  6336. (defun org-agenda-toggle-deadlines ()
  6337. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6338. (interactive)
  6339. (org-agenda-check-type t 'agenda)
  6340. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6341. (org-agenda-redo)
  6342. (org-agenda-set-mode-name)
  6343. (message "Deadlines inclusion turned %s"
  6344. (if org-agenda-include-deadlines "on" "off")))
  6345. (defun org-agenda-toggle-time-grid ()
  6346. "Toggle time grid in an agenda buffer."
  6347. (interactive)
  6348. (org-agenda-check-type t 'agenda)
  6349. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6350. (org-agenda-redo)
  6351. (org-agenda-set-mode-name)
  6352. (message "Time-grid turned %s"
  6353. (if org-agenda-use-time-grid "on" "off")))
  6354. (defun org-agenda-set-mode-name ()
  6355. "Set the mode name to indicate all the small mode settings."
  6356. (setq mode-name
  6357. (list "Org-Agenda"
  6358. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6359. " "
  6360. '(:eval (org-agenda-span-name org-agenda-current-span))
  6361. (if org-agenda-follow-mode " Follow" "")
  6362. (if org-agenda-entry-text-mode " ETxt" "")
  6363. (if org-agenda-include-diary " Diary" "")
  6364. (if org-agenda-include-deadlines " Ddl" "")
  6365. (if org-agenda-use-time-grid " Grid" "")
  6366. (if (and (boundp 'org-habit-show-habits)
  6367. org-habit-show-habits) " Habit" "")
  6368. (cond
  6369. ((consp org-agenda-show-log) " LogAll")
  6370. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6371. (org-agenda-show-log " Log")
  6372. (t ""))
  6373. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6374. :preset-filter))
  6375. '(:eval (org-propertize
  6376. (concat " <"
  6377. (mapconcat
  6378. 'identity
  6379. (append
  6380. (get 'org-agenda-category-filter :preset-filter)
  6381. org-agenda-category-filter)
  6382. "")
  6383. ">")
  6384. 'face 'org-agenda-filter-category
  6385. 'help-echo "Category used in filtering"))
  6386. "")
  6387. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6388. :preset-filter))
  6389. '(:eval (org-propertize
  6390. (concat " {"
  6391. (mapconcat
  6392. 'identity
  6393. (append
  6394. (get 'org-agenda-tag-filter :preset-filter)
  6395. org-agenda-tag-filter)
  6396. "")
  6397. "}")
  6398. 'face 'org-agenda-filter-tags
  6399. 'help-echo "Tags used in filtering"))
  6400. "")
  6401. (if org-agenda-archives-mode
  6402. (if (eq org-agenda-archives-mode t)
  6403. " Archives"
  6404. (format " :%s:" org-archive-tag))
  6405. "")
  6406. (if org-agenda-clockreport-mode
  6407. (if (eq org-agenda-clockreport-mode 'with-filter)
  6408. " Clock{}" " Clock")
  6409. "")))
  6410. (force-mode-line-update))
  6411. (defun org-agenda-post-command-hook ()
  6412. (setq org-agenda-type
  6413. (or (get-text-property (point) 'org-agenda-type)
  6414. (get-text-property (max (point-min) (1- (point)))
  6415. 'org-agenda-type))))
  6416. (defun org-agenda-next-line ()
  6417. "Move cursor to the next line, and show if follow mode is active."
  6418. (interactive)
  6419. (call-interactively 'next-line)
  6420. (org-agenda-do-context-action))
  6421. (defun org-agenda-previous-line ()
  6422. "Move cursor to the previous line, and show if follow-mode is active."
  6423. (interactive)
  6424. (call-interactively 'previous-line)
  6425. (org-agenda-do-context-action))
  6426. (defun org-agenda-do-context-action ()
  6427. "Show outline path and, maybe, follow mode window."
  6428. (let ((m (org-get-at-bol 'org-marker)))
  6429. (when (and (markerp m) (marker-buffer m))
  6430. (and org-agenda-follow-mode
  6431. (if org-agenda-follow-indirect
  6432. (org-agenda-tree-to-indirect-buffer)
  6433. (org-agenda-show)))
  6434. (and org-agenda-show-outline-path
  6435. (org-with-point-at m (org-display-outline-path t))))))
  6436. (defun org-agenda-show-priority ()
  6437. "Show the priority of the current item.
  6438. This priority is composed of the main priority given with the [#A] cookies,
  6439. and by additional input from the age of a schedules or deadline entry."
  6440. (interactive)
  6441. (let* ((pri (org-get-at-bol 'priority)))
  6442. (message "Priority is %d" (if pri pri -1000))))
  6443. (defun org-agenda-show-tags ()
  6444. "Show the tags applicable to the current item."
  6445. (interactive)
  6446. (let* ((tags (org-get-at-bol 'tags)))
  6447. (if tags
  6448. (message "Tags are :%s:"
  6449. (org-no-properties (mapconcat 'identity tags ":")))
  6450. (message "No tags associated with this line"))))
  6451. (defun org-agenda-goto (&optional highlight)
  6452. "Go to the Org-mode file which contains the item at point."
  6453. (interactive)
  6454. (let* ((marker (or (org-get-at-bol 'org-marker)
  6455. (org-agenda-error)))
  6456. (buffer (marker-buffer marker))
  6457. (pos (marker-position marker)))
  6458. (switch-to-buffer-other-window buffer)
  6459. (widen)
  6460. (push-mark)
  6461. (goto-char pos)
  6462. (when (eq major-mode 'org-mode)
  6463. (org-show-context 'agenda)
  6464. (save-excursion
  6465. (and (outline-next-heading)
  6466. (org-flag-heading nil)))) ; show the next heading
  6467. (when (outline-invisible-p)
  6468. (show-entry)) ; display invisible text
  6469. (recenter (/ (window-height) 2))
  6470. (run-hooks 'org-agenda-after-show-hook)
  6471. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6472. (defvar org-agenda-after-show-hook nil
  6473. "Normal hook run after an item has been shown from the agenda.
  6474. Point is in the buffer where the item originated.")
  6475. (defun org-agenda-kill ()
  6476. "Kill the entry or subtree belonging to the current agenda entry."
  6477. (interactive)
  6478. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6479. (let* ((marker (or (org-get-at-bol 'org-marker)
  6480. (org-agenda-error)))
  6481. (buffer (marker-buffer marker))
  6482. (pos (marker-position marker))
  6483. (type (org-get-at-bol 'type))
  6484. dbeg dend (n 0) conf)
  6485. (org-with-remote-undo buffer
  6486. (with-current-buffer buffer
  6487. (save-excursion
  6488. (goto-char pos)
  6489. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6490. (setq dbeg (progn (org-back-to-heading t) (point))
  6491. dend (org-end-of-subtree t t))
  6492. (setq dbeg (point-at-bol)
  6493. dend (min (point-max) (1+ (point-at-eol)))))
  6494. (goto-char dbeg)
  6495. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6496. (setq conf (or (eq t org-agenda-confirm-kill)
  6497. (and (numberp org-agenda-confirm-kill)
  6498. (> n org-agenda-confirm-kill))))
  6499. (and conf
  6500. (not (y-or-n-p
  6501. (format "Delete entry with %d lines in buffer \"%s\"? "
  6502. n (buffer-name buffer))))
  6503. (error "Abort"))
  6504. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6505. (with-current-buffer buffer (delete-region dbeg dend))
  6506. (message "Agenda item and source killed"))))
  6507. (defvar org-archive-default-command)
  6508. (defun org-agenda-archive-default ()
  6509. "Archive the entry or subtree belonging to the current agenda entry."
  6510. (interactive)
  6511. (require 'org-archive)
  6512. (org-agenda-archive-with org-archive-default-command))
  6513. (defun org-agenda-archive-default-with-confirmation ()
  6514. "Archive the entry or subtree belonging to the current agenda entry."
  6515. (interactive)
  6516. (require 'org-archive)
  6517. (org-agenda-archive-with org-archive-default-command 'confirm))
  6518. (defun org-agenda-archive ()
  6519. "Archive the entry or subtree belonging to the current agenda entry."
  6520. (interactive)
  6521. (org-agenda-archive-with 'org-archive-subtree))
  6522. (defun org-agenda-archive-to-archive-sibling ()
  6523. "Move the entry to the archive sibling."
  6524. (interactive)
  6525. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6526. (defun org-agenda-archive-with (cmd &optional confirm)
  6527. "Move the entry to the archive sibling."
  6528. (interactive)
  6529. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6530. (let* ((marker (or (org-get-at-bol 'org-marker)
  6531. (org-agenda-error)))
  6532. (buffer (marker-buffer marker))
  6533. (pos (marker-position marker)))
  6534. (org-with-remote-undo buffer
  6535. (with-current-buffer buffer
  6536. (if (eq major-mode 'org-mode)
  6537. (if (and confirm
  6538. (not (y-or-n-p "Archive this subtree or entry? ")))
  6539. (error "Abort")
  6540. (save-excursion
  6541. (goto-char pos)
  6542. (org-remove-subtree-entries-from-agenda)
  6543. (org-back-to-heading t)
  6544. (funcall cmd)))
  6545. (error "Archiving works only in Org-mode files"))))))
  6546. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6547. "Remove all lines in the agenda that correspond to a given subtree.
  6548. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6549. If this information is not given, the function uses the tree at point."
  6550. (let ((buf (or buf (current-buffer))) m p)
  6551. (save-excursion
  6552. (unless (and beg end)
  6553. (org-back-to-heading t)
  6554. (setq beg (point))
  6555. (org-end-of-subtree t)
  6556. (setq end (point)))
  6557. (set-buffer (get-buffer org-agenda-buffer-name))
  6558. (save-excursion
  6559. (goto-char (point-max))
  6560. (beginning-of-line 1)
  6561. (while (not (bobp))
  6562. (when (and (setq m (org-get-at-bol 'org-marker))
  6563. (equal buf (marker-buffer m))
  6564. (setq p (marker-position m))
  6565. (>= p beg)
  6566. (< p end))
  6567. (let ((inhibit-read-only t))
  6568. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6569. (beginning-of-line 0))))))
  6570. (defun org-agenda-refile (&optional goto rfloc no-update)
  6571. "Refile the item at point."
  6572. (interactive "P")
  6573. (if (equal goto '(16))
  6574. (org-refile-goto-last-stored)
  6575. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6576. (org-agenda-error)))
  6577. (buffer (marker-buffer marker))
  6578. (pos (marker-position marker))
  6579. (rfloc (or rfloc
  6580. (org-refile-get-location
  6581. (if goto "Goto" "Refile to") buffer
  6582. org-refile-allow-creating-parent-nodes))))
  6583. (with-current-buffer buffer
  6584. (save-excursion
  6585. (save-restriction
  6586. (widen)
  6587. (goto-char marker)
  6588. (org-remove-subtree-entries-from-agenda)
  6589. (org-refile goto buffer rfloc)))))
  6590. (unless no-update (org-agenda-redo))))
  6591. (defun org-agenda-open-link (&optional arg)
  6592. "Follow the link in the current line, if any.
  6593. This looks for a link in the displayed line in the agenda. It also looks
  6594. at the text of the entry itself."
  6595. (interactive "P")
  6596. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6597. (org-get-at-bol 'org-marker)))
  6598. (buffer (and marker (marker-buffer marker)))
  6599. (prefix (buffer-substring
  6600. (point-at-bol) (point-at-eol))))
  6601. (cond
  6602. (buffer
  6603. (with-current-buffer buffer
  6604. (save-excursion
  6605. (save-restriction
  6606. (widen)
  6607. (goto-char marker)
  6608. (org-offer-links-in-entry arg prefix)))))
  6609. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6610. (save-excursion
  6611. (beginning-of-line 1)
  6612. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6613. (org-open-link-from-string (match-string 1)))
  6614. (t (error "No link to open here")))))
  6615. (defun org-agenda-copy-local-variable (var)
  6616. "Get a variable from a referenced buffer and install it here."
  6617. (let ((m (org-get-at-bol 'org-marker)))
  6618. (when (and m (buffer-live-p (marker-buffer m)))
  6619. (org-set-local var (with-current-buffer (marker-buffer m)
  6620. (symbol-value var))))))
  6621. (defun org-agenda-switch-to (&optional delete-other-windows)
  6622. "Go to the Org-mode file which contains the item at point."
  6623. (interactive)
  6624. (if (and org-return-follows-link
  6625. (not (org-get-at-bol 'org-marker))
  6626. (org-in-regexp org-bracket-link-regexp))
  6627. (org-open-link-from-string (match-string 0))
  6628. (let* ((marker (or (org-get-at-bol 'org-marker)
  6629. (org-agenda-error)))
  6630. (buffer (marker-buffer marker))
  6631. (pos (marker-position marker)))
  6632. (org-pop-to-buffer-same-window buffer)
  6633. (and delete-other-windows (delete-other-windows))
  6634. (widen)
  6635. (goto-char pos)
  6636. (when (eq major-mode 'org-mode)
  6637. (org-show-context 'agenda)
  6638. (save-excursion
  6639. (and (outline-next-heading)
  6640. (org-flag-heading nil))) ; show the next heading
  6641. (when (outline-invisible-p)
  6642. (show-entry)))))) ; display invisible text
  6643. (defun org-agenda-goto-mouse (ev)
  6644. "Go to the Org-mode file which contains the item at the mouse click."
  6645. (interactive "e")
  6646. (mouse-set-point ev)
  6647. (org-agenda-goto))
  6648. (defun org-agenda-show (&optional full-entry)
  6649. "Display the Org-mode file which contains the item at point.
  6650. With prefix argument FULL-ENTRY, make the entire entry visible
  6651. if it was hidden in the outline."
  6652. (interactive "P")
  6653. (let ((win (selected-window)))
  6654. (if full-entry
  6655. (let ((org-show-entry-below t))
  6656. (org-agenda-goto t))
  6657. (org-agenda-goto t))
  6658. (select-window win)))
  6659. (defvar org-agenda-show-window nil)
  6660. (defun org-agenda-show-and-scroll-up (&optional arg)
  6661. "Display the Org-mode file which contains the item at point.
  6662. When called repeatedly, scroll the window that is displaying the buffer.
  6663. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6664. `show-subtree' to display the item, so that drawers and logbooks stay
  6665. folded."
  6666. (interactive "P")
  6667. (let ((win (selected-window)))
  6668. (if (and (window-live-p org-agenda-show-window)
  6669. (eq this-command last-command))
  6670. (progn
  6671. (select-window org-agenda-show-window)
  6672. (ignore-errors (scroll-up)))
  6673. (org-agenda-goto t)
  6674. (if arg (org-show-entry) (show-subtree))
  6675. (setq org-agenda-show-window (selected-window)))
  6676. (select-window win)))
  6677. (defun org-agenda-show-scroll-down ()
  6678. "Scroll down the window showing the agenda."
  6679. (interactive)
  6680. (let ((win (selected-window)))
  6681. (when (window-live-p org-agenda-show-window)
  6682. (select-window org-agenda-show-window)
  6683. (ignore-errors (scroll-down))
  6684. (select-window win))))
  6685. (defun org-agenda-show-1 (&optional more)
  6686. "Display the Org-mode file which contains the item at point.
  6687. The prefix arg selects the amount of information to display:
  6688. 0 hide the subtree
  6689. 1 just show the entry according to defaults.
  6690. 2 show the children view
  6691. 3 show the subtree view
  6692. 4 show the entire subtree and any LOGBOOK drawers
  6693. 5 show the entire subtree and any drawers
  6694. With prefix argument FULL-ENTRY, make the entire entry visible
  6695. if it was hidden in the outline."
  6696. (interactive "p")
  6697. (let ((win (selected-window)))
  6698. (org-agenda-goto t)
  6699. (org-recenter-heading 1)
  6700. (cond
  6701. ((= more 0)
  6702. (hide-subtree)
  6703. (save-excursion
  6704. (org-back-to-heading)
  6705. (run-hook-with-args 'org-cycle-hook 'folded))
  6706. (message "Remote: FOLDED"))
  6707. ((and (org-called-interactively-p 'any) (= more 1))
  6708. (message "Remote: show with default settings"))
  6709. ((= more 2)
  6710. (show-entry)
  6711. (show-children)
  6712. (save-excursion
  6713. (org-back-to-heading)
  6714. (run-hook-with-args 'org-cycle-hook 'children))
  6715. (message "Remote: CHILDREN"))
  6716. ((= more 3)
  6717. (show-subtree)
  6718. (save-excursion
  6719. (org-back-to-heading)
  6720. (run-hook-with-args 'org-cycle-hook 'subtree))
  6721. (message "Remote: SUBTREE"))
  6722. ((= more 4)
  6723. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6724. (org-drawer-regexp
  6725. (concat "^[ \t]*:\\("
  6726. (mapconcat 'regexp-quote org-drawers "\\|")
  6727. "\\):[ \t]*$")))
  6728. (show-subtree)
  6729. (save-excursion
  6730. (org-back-to-heading)
  6731. (org-cycle-hide-drawers 'subtree)))
  6732. (message "Remote: SUBTREE AND LOGBOOK"))
  6733. ((> more 4)
  6734. (show-subtree)
  6735. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6736. (select-window win)))
  6737. (defun org-recenter-heading (n)
  6738. (save-excursion
  6739. (org-back-to-heading)
  6740. (recenter n)))
  6741. (defvar org-agenda-cycle-counter nil)
  6742. (defun org-agenda-cycle-show (&optional n)
  6743. "Show the current entry in another window, with default settings.
  6744. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6745. When use repeatedly in immediate succession, the remote entry will cycle
  6746. through visibility
  6747. children -> subtree -> folded
  6748. When called with a numeric prefix arg, that arg will be passed through to
  6749. `org-agenda-show-1'. For the interpretation of that argument, see the
  6750. docstring of `org-agenda-show-1'."
  6751. (interactive "P")
  6752. (if (integerp n)
  6753. (setq org-agenda-cycle-counter n)
  6754. (if (not (eq last-command this-command))
  6755. (setq org-agenda-cycle-counter 1)
  6756. (if (equal org-agenda-cycle-counter 0)
  6757. (setq org-agenda-cycle-counter 2)
  6758. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6759. (if (> org-agenda-cycle-counter 3)
  6760. (setq org-agenda-cycle-counter 0)))))
  6761. (org-agenda-show-1 org-agenda-cycle-counter))
  6762. (defun org-agenda-recenter (arg)
  6763. "Display the Org-mode file which contains the item at point and recenter."
  6764. (interactive "P")
  6765. (let ((win (selected-window)))
  6766. (org-agenda-goto t)
  6767. (recenter arg)
  6768. (select-window win)))
  6769. (defun org-agenda-show-mouse (ev)
  6770. "Display the Org-mode file which contains the item at the mouse click."
  6771. (interactive "e")
  6772. (mouse-set-point ev)
  6773. (org-agenda-show))
  6774. (defun org-agenda-check-no-diary ()
  6775. "Check if the entry is a diary link and abort if yes."
  6776. (if (org-get-at-bol 'org-agenda-diary-link)
  6777. (org-agenda-error)))
  6778. (defun org-agenda-error ()
  6779. (error "Command not allowed in this line"))
  6780. (defun org-agenda-tree-to-indirect-buffer ()
  6781. "Show the subtree corresponding to the current entry in an indirect buffer.
  6782. This calls the command `org-tree-to-indirect-buffer' from the original
  6783. Org-mode buffer.
  6784. With numerical prefix arg ARG, go up to this level and then take that tree.
  6785. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6786. use the dedicated frame)."
  6787. (interactive)
  6788. (if (and current-prefix-arg (listp current-prefix-arg))
  6789. (org-agenda-do-tree-to-indirect-buffer)
  6790. (let ((agenda-window (selected-window))
  6791. (indirect-window (get-buffer-window org-last-indirect-buffer)))
  6792. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  6793. (unwind-protect
  6794. (progn
  6795. (unless indirect-window
  6796. (setq indirect-window (split-window agenda-window)))
  6797. (select-window indirect-window)
  6798. (switch-to-buffer org-last-indirect-buffer :norecord)
  6799. (fit-window-to-buffer indirect-window))
  6800. (select-window agenda-window)))))
  6801. (defun org-agenda-do-tree-to-indirect-buffer ()
  6802. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  6803. (org-agenda-check-no-diary)
  6804. (let* ((marker (or (org-get-at-bol 'org-marker)
  6805. (org-agenda-error)))
  6806. (buffer (marker-buffer marker))
  6807. (pos (marker-position marker)))
  6808. (with-current-buffer buffer
  6809. (save-excursion
  6810. (goto-char pos)
  6811. (call-interactively 'org-tree-to-indirect-buffer)))))
  6812. (defvar org-last-heading-marker (make-marker)
  6813. "Marker pointing to the headline that last changed its TODO state
  6814. by a remote command from the agenda.")
  6815. (defun org-agenda-todo-nextset ()
  6816. "Switch TODO entry to next sequence."
  6817. (interactive)
  6818. (org-agenda-todo 'nextset))
  6819. (defun org-agenda-todo-previousset ()
  6820. "Switch TODO entry to previous sequence."
  6821. (interactive)
  6822. (org-agenda-todo 'previousset))
  6823. (defun org-agenda-todo (&optional arg)
  6824. "Cycle TODO state of line at point, also in Org-mode file.
  6825. This changes the line at point, all other lines in the agenda referring to
  6826. the same tree node, and the headline of the tree node in the Org-mode file."
  6827. (interactive "P")
  6828. (org-agenda-check-no-diary)
  6829. (let* ((col (current-column))
  6830. (marker (or (org-get-at-bol 'org-marker)
  6831. (org-agenda-error)))
  6832. (buffer (marker-buffer marker))
  6833. (pos (marker-position marker))
  6834. (hdmarker (org-get-at-bol 'org-hd-marker))
  6835. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6836. (inhibit-read-only t)
  6837. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6838. (org-with-remote-undo buffer
  6839. (with-current-buffer buffer
  6840. (widen)
  6841. (goto-char pos)
  6842. (org-show-context 'agenda)
  6843. (save-excursion
  6844. (and (outline-next-heading)
  6845. (org-flag-heading nil))) ; show the next heading
  6846. (let ((current-prefix-arg arg))
  6847. (call-interactively 'org-todo))
  6848. (and (bolp) (forward-char 1))
  6849. (setq newhead (org-get-heading))
  6850. (when (and (org-bound-and-true-p
  6851. org-agenda-headline-snapshot-before-repeat)
  6852. (not (equal org-agenda-headline-snapshot-before-repeat
  6853. newhead))
  6854. todayp)
  6855. (setq newhead org-agenda-headline-snapshot-before-repeat
  6856. just-one t))
  6857. (save-excursion
  6858. (org-back-to-heading)
  6859. (move-marker org-last-heading-marker (point))))
  6860. (beginning-of-line 1)
  6861. (save-excursion
  6862. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6863. (org-move-to-column col))))
  6864. (defun org-agenda-add-note (&optional arg)
  6865. "Add a time-stamped note to the entry at point."
  6866. (interactive "P")
  6867. (org-agenda-check-no-diary)
  6868. (let* ((marker (or (org-get-at-bol 'org-marker)
  6869. (org-agenda-error)))
  6870. (buffer (marker-buffer marker))
  6871. (pos (marker-position marker))
  6872. (hdmarker (org-get-at-bol 'org-hd-marker))
  6873. (inhibit-read-only t))
  6874. (with-current-buffer buffer
  6875. (widen)
  6876. (goto-char pos)
  6877. (org-show-context 'agenda)
  6878. (save-excursion
  6879. (and (outline-next-heading)
  6880. (org-flag-heading nil))) ; show the next heading
  6881. (org-add-note))))
  6882. (defun org-agenda-change-all-lines (newhead hdmarker
  6883. &optional fixface just-this)
  6884. "Change all lines in the agenda buffer which match HDMARKER.
  6885. The new content of the line will be NEWHEAD (as modified by
  6886. `org-agenda-format-item'). HDMARKER is checked with
  6887. `equal' against all `org-hd-marker' text properties in the file.
  6888. If FIXFACE is non-nil, the face of each item is modified according to
  6889. the new TODO state.
  6890. If JUST-THIS is non-nil, change just the current line, not all.
  6891. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6892. (let* ((inhibit-read-only t)
  6893. (line (org-current-line))
  6894. (thetags (with-current-buffer (marker-buffer hdmarker)
  6895. (save-excursion (save-restriction (widen)
  6896. (goto-char hdmarker)
  6897. (org-get-tags-at)))))
  6898. props m pl undone-face done-face finish new dotime cat tags)
  6899. (save-excursion
  6900. (goto-char (point-max))
  6901. (beginning-of-line 1)
  6902. (while (not finish)
  6903. (setq finish (bobp))
  6904. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6905. (or (not just-this) (= (org-current-line) line))
  6906. (equal m hdmarker))
  6907. (setq props (text-properties-at (point))
  6908. dotime (org-get-at-bol 'dotime)
  6909. cat (org-get-at-bol 'org-category)
  6910. tags thetags
  6911. new
  6912. (let ((org-prefix-format-compiled
  6913. (or (get-text-property (point) 'format)
  6914. org-prefix-format-compiled)))
  6915. (with-current-buffer (marker-buffer hdmarker)
  6916. (save-excursion
  6917. (save-restriction
  6918. (widen)
  6919. (org-agenda-format-item (org-get-at-bol 'extra)
  6920. newhead cat tags dotime)))))
  6921. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6922. undone-face (org-get-at-bol 'undone-face)
  6923. done-face (org-get-at-bol 'done-face))
  6924. (beginning-of-line 1)
  6925. (cond
  6926. ((equal new "")
  6927. (and (looking-at ".*\n?") (replace-match "")))
  6928. ((looking-at ".*")
  6929. (replace-match new t t)
  6930. (beginning-of-line 1)
  6931. (add-text-properties (point-at-bol) (point-at-eol) props)
  6932. (when fixface
  6933. (add-text-properties
  6934. (point-at-bol) (point-at-eol)
  6935. (list 'face
  6936. (if org-last-todo-state-is-todo
  6937. undone-face done-face))))
  6938. (org-agenda-highlight-todo 'line)
  6939. (beginning-of-line 1))
  6940. (t (error "Line update did not work"))))
  6941. (beginning-of-line 0)))
  6942. (org-finalize-agenda)))
  6943. (defun org-agenda-align-tags (&optional line)
  6944. "Align all tags in agenda items to `org-agenda-tags-column'."
  6945. (let ((inhibit-read-only t) l c)
  6946. (save-excursion
  6947. (goto-char (if line (point-at-bol) (point-min)))
  6948. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6949. (if line (point-at-eol) nil) t)
  6950. (add-text-properties
  6951. (match-beginning 2) (match-end 2)
  6952. (list 'face (delq nil (let ((prop (get-text-property
  6953. (match-beginning 2) 'face)))
  6954. (or (listp prop) (setq prop (list prop)))
  6955. (if (memq 'org-tag prop)
  6956. prop
  6957. (cons 'org-tag prop))))))
  6958. (setq l (- (match-end 2) (match-beginning 2))
  6959. c (if (< org-agenda-tags-column 0)
  6960. (- (abs org-agenda-tags-column) l)
  6961. org-agenda-tags-column))
  6962. (delete-region (match-beginning 1) (match-end 1))
  6963. (goto-char (match-beginning 1))
  6964. (insert (org-add-props
  6965. (make-string (max 1 (- c (current-column))) ?\ )
  6966. (plist-put (copy-sequence (text-properties-at (point)))
  6967. 'face nil))))
  6968. (goto-char (point-min))
  6969. (org-font-lock-add-tag-faces (point-max)))))
  6970. (defun org-agenda-priority-up ()
  6971. "Increase the priority of line at point, also in Org-mode file."
  6972. (interactive)
  6973. (org-agenda-priority 'up))
  6974. (defun org-agenda-priority-down ()
  6975. "Decrease the priority of line at point, also in Org-mode file."
  6976. (interactive)
  6977. (org-agenda-priority 'down))
  6978. (defun org-agenda-priority (&optional force-direction)
  6979. "Set the priority of line at point, also in Org-mode file.
  6980. This changes the line at point, all other lines in the agenda referring to
  6981. the same tree node, and the headline of the tree node in the Org-mode file."
  6982. (interactive)
  6983. (unless org-enable-priority-commands
  6984. (error "Priority commands are disabled"))
  6985. (org-agenda-check-no-diary)
  6986. (let* ((marker (or (org-get-at-bol 'org-marker)
  6987. (org-agenda-error)))
  6988. (hdmarker (org-get-at-bol 'org-hd-marker))
  6989. (buffer (marker-buffer hdmarker))
  6990. (pos (marker-position hdmarker))
  6991. (inhibit-read-only t)
  6992. newhead)
  6993. (org-with-remote-undo buffer
  6994. (with-current-buffer buffer
  6995. (widen)
  6996. (goto-char pos)
  6997. (org-show-context 'agenda)
  6998. (save-excursion
  6999. (and (outline-next-heading)
  7000. (org-flag-heading nil))) ; show the next heading
  7001. (funcall 'org-priority force-direction)
  7002. (end-of-line 1)
  7003. (setq newhead (org-get-heading)))
  7004. (org-agenda-change-all-lines newhead hdmarker)
  7005. (beginning-of-line 1))))
  7006. ;; FIXME: should fix the tags property of the agenda line.
  7007. (defun org-agenda-set-tags (&optional tag onoff)
  7008. "Set tags for the current headline."
  7009. (interactive)
  7010. (org-agenda-check-no-diary)
  7011. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7012. (call-interactively 'org-change-tag-in-region)
  7013. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7014. (org-agenda-error)))
  7015. (buffer (marker-buffer hdmarker))
  7016. (pos (marker-position hdmarker))
  7017. (inhibit-read-only t)
  7018. newhead)
  7019. (org-with-remote-undo buffer
  7020. (with-current-buffer buffer
  7021. (widen)
  7022. (goto-char pos)
  7023. (save-excursion
  7024. (org-show-context 'agenda))
  7025. (save-excursion
  7026. (and (outline-next-heading)
  7027. (org-flag-heading nil))) ; show the next heading
  7028. (goto-char pos)
  7029. (if tag
  7030. (org-toggle-tag tag onoff)
  7031. (call-interactively 'org-set-tags))
  7032. (end-of-line 1)
  7033. (setq newhead (org-get-heading)))
  7034. (org-agenda-change-all-lines newhead hdmarker)
  7035. (beginning-of-line 1)))))
  7036. (defun org-agenda-set-property ()
  7037. "Set a property for the current headline."
  7038. (interactive)
  7039. (org-agenda-check-no-diary)
  7040. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7041. (org-agenda-error)))
  7042. (buffer (marker-buffer hdmarker))
  7043. (pos (marker-position hdmarker))
  7044. (inhibit-read-only t)
  7045. newhead)
  7046. (org-with-remote-undo buffer
  7047. (with-current-buffer buffer
  7048. (widen)
  7049. (goto-char pos)
  7050. (save-excursion
  7051. (org-show-context 'agenda))
  7052. (save-excursion
  7053. (and (outline-next-heading)
  7054. (org-flag-heading nil))) ; show the next heading
  7055. (goto-char pos)
  7056. (call-interactively 'org-set-property)))))
  7057. (defun org-agenda-set-effort ()
  7058. "Set the effort property for the current headline."
  7059. (interactive)
  7060. (org-agenda-check-no-diary)
  7061. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7062. (org-agenda-error)))
  7063. (buffer (marker-buffer hdmarker))
  7064. (pos (marker-position hdmarker))
  7065. (inhibit-read-only t)
  7066. newhead)
  7067. (org-with-remote-undo buffer
  7068. (with-current-buffer buffer
  7069. (widen)
  7070. (goto-char pos)
  7071. (save-excursion
  7072. (org-show-context 'agenda))
  7073. (save-excursion
  7074. (and (outline-next-heading)
  7075. (org-flag-heading nil))) ; show the next heading
  7076. (goto-char pos)
  7077. (call-interactively 'org-set-effort)
  7078. (end-of-line 1)
  7079. (setq newhead (org-get-heading)))
  7080. (org-agenda-change-all-lines newhead hdmarker))))
  7081. (defun org-agenda-toggle-archive-tag ()
  7082. "Toggle the archive tag for the current entry."
  7083. (interactive)
  7084. (org-agenda-check-no-diary)
  7085. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7086. (org-agenda-error)))
  7087. (buffer (marker-buffer hdmarker))
  7088. (pos (marker-position hdmarker))
  7089. (inhibit-read-only t)
  7090. newhead)
  7091. (org-with-remote-undo buffer
  7092. (with-current-buffer buffer
  7093. (widen)
  7094. (goto-char pos)
  7095. (org-show-context 'agenda)
  7096. (save-excursion
  7097. (and (outline-next-heading)
  7098. (org-flag-heading nil))) ; show the next heading
  7099. (call-interactively 'org-toggle-archive-tag)
  7100. (end-of-line 1)
  7101. (setq newhead (org-get-heading)))
  7102. (org-agenda-change-all-lines newhead hdmarker)
  7103. (beginning-of-line 1))))
  7104. (defun org-agenda-do-date-later (arg)
  7105. (interactive "P")
  7106. (cond
  7107. ((or (equal arg '(16))
  7108. (memq last-command
  7109. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7110. (setq this-command 'org-agenda-date-later-minutes)
  7111. (org-agenda-date-later-minutes 1))
  7112. ((or (equal arg '(4))
  7113. (memq last-command
  7114. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7115. (setq this-command 'org-agenda-date-later-hours)
  7116. (org-agenda-date-later-hours 1))
  7117. (t
  7118. (org-agenda-date-later (prefix-numeric-value arg)))))
  7119. (defun org-agenda-do-date-earlier (arg)
  7120. (interactive "P")
  7121. (cond
  7122. ((or (equal arg '(16))
  7123. (memq last-command
  7124. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7125. (setq this-command 'org-agenda-date-earlier-minutes)
  7126. (org-agenda-date-earlier-minutes 1))
  7127. ((or (equal arg '(4))
  7128. (memq last-command
  7129. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7130. (setq this-command 'org-agenda-date-earlier-hours)
  7131. (org-agenda-date-earlier-hours 1))
  7132. (t
  7133. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7134. (defun org-agenda-date-later (arg &optional what)
  7135. "Change the date of this item to ARG day(s) later."
  7136. (interactive "p")
  7137. (org-agenda-check-type t 'agenda 'timeline)
  7138. (org-agenda-check-no-diary)
  7139. (let* ((marker (or (org-get-at-bol 'org-marker)
  7140. (org-agenda-error)))
  7141. (buffer (marker-buffer marker))
  7142. (pos (marker-position marker))
  7143. cdate today)
  7144. (org-with-remote-undo buffer
  7145. (with-current-buffer buffer
  7146. (widen)
  7147. (goto-char pos)
  7148. (if (not (org-at-timestamp-p))
  7149. (error "Cannot find time stamp"))
  7150. (when (and org-agenda-move-date-from-past-immediately-to-today
  7151. (equal arg 1)
  7152. (or (not what) (eq what 'day))
  7153. (not (save-match-data (org-at-date-range-p))))
  7154. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7155. cdate (calendar-absolute-from-gregorian
  7156. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7157. today (org-today))
  7158. (if (> today cdate)
  7159. ;; immediately shift to today
  7160. (setq arg (- today cdate))))
  7161. (org-timestamp-change arg (or what 'day))
  7162. (when (and (org-at-date-range-p)
  7163. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7164. (let ((end org-last-changed-timestamp))
  7165. (org-timestamp-change arg (or what 'day))
  7166. (setq org-last-changed-timestamp
  7167. (concat org-last-changed-timestamp "--" end)))))
  7168. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7169. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7170. (defun org-agenda-date-earlier (arg &optional what)
  7171. "Change the date of this item to ARG day(s) earlier."
  7172. (interactive "p")
  7173. (org-agenda-date-later (- arg) what))
  7174. (defun org-agenda-date-later-minutes (arg)
  7175. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7176. (interactive "p")
  7177. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7178. (org-agenda-date-later arg 'minute))
  7179. (defun org-agenda-date-earlier-minutes (arg)
  7180. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7181. (interactive "p")
  7182. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7183. (org-agenda-date-earlier arg 'minute))
  7184. (defun org-agenda-date-later-hours (arg)
  7185. "Change the time of this item, in hour steps."
  7186. (interactive "p")
  7187. (org-agenda-date-later arg 'hour))
  7188. (defun org-agenda-date-earlier-hours (arg)
  7189. "Change the time of this item, in hour steps."
  7190. (interactive "p")
  7191. (org-agenda-date-earlier arg 'hour))
  7192. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7193. "Show new date stamp via text properties."
  7194. ;; We use text properties to make this undoable
  7195. (let ((inhibit-read-only t)
  7196. (buffer-invisibility-spec))
  7197. (setq stamp (concat " " prefix " => " stamp))
  7198. (save-excursion
  7199. (goto-char (point-max))
  7200. (while (not (bobp))
  7201. (when (equal marker (org-get-at-bol 'org-marker))
  7202. (org-move-to-column (- (window-width) (length stamp)) t)
  7203. (org-agenda-fix-tags-filter-overlays-at (point))
  7204. (if (featurep 'xemacs)
  7205. ;; Use `duplicable' property to trigger undo recording
  7206. (let ((ex (make-extent nil nil))
  7207. (gl (make-glyph stamp)))
  7208. (set-glyph-face gl 'secondary-selection)
  7209. (set-extent-properties
  7210. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7211. (insert-extent ex (1- (point)) (point-at-eol)))
  7212. (add-text-properties
  7213. (1- (point)) (point-at-eol)
  7214. (list 'display (org-add-props stamp nil
  7215. 'face 'secondary-selection))))
  7216. (beginning-of-line 1))
  7217. (beginning-of-line 0)))))
  7218. (defun org-agenda-date-prompt (arg)
  7219. "Change the date of this item. Date is prompted for, with default today.
  7220. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7221. be used to request time specification in the time stamp."
  7222. (interactive "P")
  7223. (org-agenda-check-type t 'agenda 'timeline)
  7224. (org-agenda-check-no-diary)
  7225. (let* ((marker (or (org-get-at-bol 'org-marker)
  7226. (org-agenda-error)))
  7227. (buffer (marker-buffer marker))
  7228. (pos (marker-position marker)))
  7229. (org-with-remote-undo buffer
  7230. (with-current-buffer buffer
  7231. (widen)
  7232. (goto-char pos)
  7233. (if (not (org-at-timestamp-p t))
  7234. (error "Cannot find time stamp"))
  7235. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7236. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7237. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7238. (defun org-agenda-schedule (arg &optional time)
  7239. "Schedule the item at point.
  7240. ARG is passed through to `org-schedule'."
  7241. (interactive "P")
  7242. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7243. (org-agenda-check-no-diary)
  7244. (let* ((marker (or (org-get-at-bol 'org-marker)
  7245. (org-agenda-error)))
  7246. (type (marker-insertion-type marker))
  7247. (buffer (marker-buffer marker))
  7248. (pos (marker-position marker))
  7249. (org-insert-labeled-timestamps-at-point nil)
  7250. ts)
  7251. (set-marker-insertion-type marker t)
  7252. (org-with-remote-undo buffer
  7253. (with-current-buffer buffer
  7254. (widen)
  7255. (goto-char pos)
  7256. (setq ts (org-schedule arg time)))
  7257. (org-agenda-show-new-time marker ts "S"))
  7258. (message "Item scheduled for %s" ts)))
  7259. (defun org-agenda-deadline (arg &optional time)
  7260. "Schedule the item at point.
  7261. ARG is passed through to `org-deadline'."
  7262. (interactive "P")
  7263. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7264. (org-agenda-check-no-diary)
  7265. (let* ((marker (or (org-get-at-bol 'org-marker)
  7266. (org-agenda-error)))
  7267. (buffer (marker-buffer marker))
  7268. (pos (marker-position marker))
  7269. (org-insert-labeled-timestamps-at-point nil)
  7270. ts)
  7271. (org-with-remote-undo buffer
  7272. (with-current-buffer buffer
  7273. (widen)
  7274. (goto-char pos)
  7275. (setq ts (org-deadline arg time)))
  7276. (org-agenda-show-new-time marker ts "D"))
  7277. (message "Deadline for this item set to %s" ts)))
  7278. (defun org-agenda-action ()
  7279. "Select entry for agenda action, or execute an agenda action.
  7280. This command prompts for another letter. Valid inputs are:
  7281. m Mark the entry at point for an agenda action
  7282. s Schedule the marked entry to the date at the cursor
  7283. d Set the deadline of the marked entry to the date at the cursor
  7284. r Call `org-remember' with cursor date as the default date
  7285. c Call `org-capture' with cursor date as the default date
  7286. SPC Show marked entry in other window
  7287. TAB Visit marked entry in other window
  7288. The cursor may be at a date in the calendar, or in the Org agenda."
  7289. (interactive)
  7290. (let (ans)
  7291. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7292. (setq ans (read-char-exclusive))
  7293. (cond
  7294. ((equal ans ?m)
  7295. ;; Mark this entry
  7296. (if (eq major-mode 'org-agenda-mode)
  7297. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7298. (org-get-at-bol 'org-marker))))
  7299. (if m
  7300. (progn
  7301. (move-marker org-agenda-action-marker
  7302. (marker-position m) (marker-buffer m))
  7303. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7304. (error "Don't know which entry to mark")))
  7305. (error "This command works only in the agenda")))
  7306. ((equal ans ?s)
  7307. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7308. ((equal ans ?d)
  7309. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7310. ((equal ans ?r)
  7311. (org-agenda-do-action '(org-remember) t))
  7312. ((equal ans ?c)
  7313. (org-agenda-do-action '(org-capture) t))
  7314. ((equal ans ?\ )
  7315. (let ((cw (selected-window)))
  7316. (org-switch-to-buffer-other-window
  7317. (marker-buffer org-agenda-action-marker))
  7318. (goto-char org-agenda-action-marker)
  7319. (org-show-context 'agenda)
  7320. (select-window cw)))
  7321. ((equal ans ?\C-i)
  7322. (org-switch-to-buffer-other-window
  7323. (marker-buffer org-agenda-action-marker))
  7324. (goto-char org-agenda-action-marker)
  7325. (org-show-context 'agenda))
  7326. (t (error "Invalid agenda action %c" ans)))))
  7327. (defun org-agenda-do-action (form &optional current-buffer)
  7328. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7329. (let ((org-overriding-default-time (org-get-cursor-date)))
  7330. (if current-buffer
  7331. (eval form)
  7332. (if (not (marker-buffer org-agenda-action-marker))
  7333. (error "No entry has been selected for agenda action")
  7334. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7335. (save-excursion
  7336. (save-restriction
  7337. (widen)
  7338. (goto-char org-agenda-action-marker)
  7339. (eval form))))))))
  7340. (defun org-agenda-clock-in (&optional arg)
  7341. "Start the clock on the currently selected item."
  7342. (interactive "P")
  7343. (org-agenda-check-no-diary)
  7344. (if (equal arg '(4))
  7345. (org-clock-in arg)
  7346. (let* ((marker (or (org-get-at-bol 'org-marker)
  7347. (org-agenda-error)))
  7348. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7349. marker))
  7350. (pos (marker-position marker))
  7351. newhead)
  7352. (org-with-remote-undo (marker-buffer marker)
  7353. (with-current-buffer (marker-buffer marker)
  7354. (widen)
  7355. (goto-char pos)
  7356. (org-show-context 'agenda)
  7357. (org-show-entry)
  7358. (org-cycle-hide-drawers 'children)
  7359. (org-clock-in arg)
  7360. (setq newhead (org-get-heading)))
  7361. (org-agenda-change-all-lines newhead hdmarker)))))
  7362. (defun org-agenda-clock-out ()
  7363. "Stop the currently running clock."
  7364. (interactive)
  7365. (unless (marker-buffer org-clock-marker)
  7366. (error "No running clock"))
  7367. (let ((marker (make-marker)) newhead)
  7368. (org-with-remote-undo (marker-buffer org-clock-marker)
  7369. (with-current-buffer (marker-buffer org-clock-marker)
  7370. (save-excursion
  7371. (save-restriction
  7372. (widen)
  7373. (goto-char org-clock-marker)
  7374. (org-back-to-heading t)
  7375. (move-marker marker (point))
  7376. (org-clock-out)
  7377. (setq newhead (org-get-heading))))))
  7378. (org-agenda-change-all-lines newhead marker)
  7379. (move-marker marker nil)))
  7380. (defun org-agenda-clock-cancel (&optional arg)
  7381. "Cancel the currently running clock."
  7382. (interactive "P")
  7383. (unless (marker-buffer org-clock-marker)
  7384. (error "No running clock"))
  7385. (org-with-remote-undo (marker-buffer org-clock-marker)
  7386. (org-clock-cancel)))
  7387. (defun org-agenda-clock-goto ()
  7388. "Jump to the currently clocked in task within the agenda.
  7389. If the currently clocked in task is not listed in the agenda
  7390. buffer, display it in another window."
  7391. (interactive)
  7392. (let (pos)
  7393. (mapc (lambda (o)
  7394. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7395. (setq pos (overlay-start o))))
  7396. (overlays-in (point-min) (point-max)))
  7397. (cond (pos (goto-char pos))
  7398. ;; If the currently clocked entry is not in the agenda
  7399. ;; buffer, we visit it in another window:
  7400. (org-clock-current-task
  7401. (org-switch-to-buffer-other-window (org-clock-goto)))
  7402. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7403. (defun org-agenda-diary-entry-in-org-file ()
  7404. "Make a diary entry in the file `org-agenda-diary-file'."
  7405. (let (d1 d2 char (text "") dp1 dp2)
  7406. (if (equal (buffer-name) "*Calendar*")
  7407. (setq d1 (calendar-cursor-to-date t)
  7408. d2 (car calendar-mark-ring))
  7409. (setq dp1 (get-text-property (point-at-bol) 'day))
  7410. (unless dp1 (error "No date defined in current line"))
  7411. (setq d1 (calendar-gregorian-from-absolute dp1)
  7412. d2 (and (ignore-errors (mark))
  7413. (save-excursion
  7414. (goto-char (mark))
  7415. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7416. (calendar-gregorian-from-absolute dp2))))
  7417. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7418. (setq char (read-char-exclusive))
  7419. (cond
  7420. ((equal char ?d)
  7421. (setq text (read-string "Day entry: "))
  7422. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7423. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7424. ((equal char ?a)
  7425. (setq d1 (list (car d1) (nth 1 d1)
  7426. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7427. (nth 2 d1))))
  7428. (setq text (read-string "Anniversary (use %d to show years): "))
  7429. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7430. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7431. ((equal char ?b)
  7432. (setq text (read-string "Block entry: "))
  7433. (unless (and d1 d2 (not (equal d1 d2)))
  7434. (error "No block of days selected"))
  7435. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7436. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7437. ((equal char ?j)
  7438. (org-switch-to-buffer-other-window
  7439. (find-file-noselect org-agenda-diary-file))
  7440. (require 'org-datetree)
  7441. (org-datetree-find-date-create d1)
  7442. (org-reveal t))
  7443. (t (error "Invalid selection character `%c'" char)))))
  7444. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7445. "Where in `org-agenda-diary-file' should new entries be added?
  7446. Valid values:
  7447. date-tree in the date tree, as child of the date
  7448. top-level as top-level entries at the end of the file."
  7449. :group 'org-agenda
  7450. :type '(choice
  7451. (const :tag "in a date tree" date-tree)
  7452. (const :tag "as top level at end of file" top-level)))
  7453. (defcustom org-agenda-insert-diary-extract-time nil
  7454. "Non-nil means extract any time specification from the diary entry."
  7455. :group 'org-agenda
  7456. :version "24.1"
  7457. :type 'boolean)
  7458. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7459. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7460. If TEXT is not empty, it will become the headline of the new entry, and
  7461. the resulting entry will not be shown. When TEXT is empty, switch to
  7462. `org-agenda-diary-file' and let the user finish the entry there."
  7463. (let ((cw (current-window-configuration)))
  7464. (org-switch-to-buffer-other-window
  7465. (find-file-noselect org-agenda-diary-file))
  7466. (widen)
  7467. (goto-char (point-min))
  7468. (cond
  7469. ((eq type 'anniversary)
  7470. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7471. (progn
  7472. (or (org-at-heading-p t)
  7473. (progn
  7474. (outline-next-heading)
  7475. (insert "* Anniversaries\n\n")
  7476. (beginning-of-line -1)))))
  7477. (outline-next-heading)
  7478. (org-back-over-empty-lines)
  7479. (backward-char 1)
  7480. (insert "\n")
  7481. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7482. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7483. ((eq type 'day)
  7484. (let ((org-prefix-has-time t)
  7485. (org-agenda-time-leading-zero t)
  7486. fmt time time2)
  7487. (if org-agenda-insert-diary-extract-time
  7488. ;; Use org-agenda-format-item to parse text for a time-range and
  7489. ;; remove it. FIXME: This is a hack, we should refactor
  7490. ;; that function to make time extraction available separately
  7491. (setq fmt (org-agenda-format-item nil text nil nil t)
  7492. time (get-text-property 0 'time fmt)
  7493. time2 (if (> (length time) 0)
  7494. ;; split-string removes trailing ...... if
  7495. ;; no end time given. First space
  7496. ;; separates time from date.
  7497. (concat " " (car (split-string time "\\.")))
  7498. nil)
  7499. text (get-text-property 0 'txt fmt)))
  7500. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7501. (org-agenda-insert-diary-as-top-level text)
  7502. (require 'org-datetree)
  7503. (org-datetree-find-date-create d1)
  7504. (org-agenda-insert-diary-make-new-entry text))
  7505. (org-insert-time-stamp (org-time-from-absolute
  7506. (calendar-absolute-from-gregorian d1))
  7507. nil nil nil nil time2))
  7508. (end-of-line 0))
  7509. ((eq type 'block)
  7510. (if (> (calendar-absolute-from-gregorian d1)
  7511. (calendar-absolute-from-gregorian d2))
  7512. (setq d1 (prog1 d2 (setq d2 d1))))
  7513. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7514. (org-agenda-insert-diary-as-top-level text)
  7515. (require 'org-datetree)
  7516. (org-datetree-find-date-create d1)
  7517. (org-agenda-insert-diary-make-new-entry text))
  7518. (org-insert-time-stamp (org-time-from-absolute
  7519. (calendar-absolute-from-gregorian d1)))
  7520. (insert "--")
  7521. (org-insert-time-stamp (org-time-from-absolute
  7522. (calendar-absolute-from-gregorian d2)))
  7523. (end-of-line 0)))
  7524. (if (string-match "\\S-" text)
  7525. (progn
  7526. (set-window-configuration cw)
  7527. (message "%s entry added to %s"
  7528. (capitalize (symbol-name type))
  7529. (abbreviate-file-name org-agenda-diary-file)))
  7530. (org-reveal t)
  7531. (message "Please finish entry here"))))
  7532. (defun org-agenda-insert-diary-as-top-level (text)
  7533. "Make new entry as a top-level entry at the end of the file.
  7534. Add TEXT as headline, and position the cursor in the second line so that
  7535. a timestamp can be added there."
  7536. (widen)
  7537. (goto-char (point-max))
  7538. (or (bolp) (insert "\n"))
  7539. (insert "* " text "\n")
  7540. (if org-adapt-indentation (org-indent-to-column 2)))
  7541. (defun org-agenda-insert-diary-make-new-entry (text)
  7542. "Make new entry as last child of current entry.
  7543. Add TEXT as headline, and position the cursor in the second line so that
  7544. a timestamp can be added there."
  7545. (let ((org-show-following-heading t)
  7546. (org-show-siblings t)
  7547. (org-show-hierarchy-above t)
  7548. (org-show-entry-below t)
  7549. col)
  7550. (outline-next-heading)
  7551. (org-back-over-empty-lines)
  7552. (or (looking-at "[ \t]*$")
  7553. (progn (insert "\n") (backward-char 1)))
  7554. (org-insert-heading nil t)
  7555. (org-do-demote)
  7556. (setq col (current-column))
  7557. (insert text "\n")
  7558. (if org-adapt-indentation (org-indent-to-column col))
  7559. (let ((org-show-following-heading t)
  7560. (org-show-siblings t)
  7561. (org-show-hierarchy-above t)
  7562. (org-show-entry-below t))
  7563. (org-show-context))))
  7564. (defun org-agenda-diary-entry ()
  7565. "Make a diary entry, like the `i' command from the calendar.
  7566. All the standard commands work: block, weekly etc.
  7567. When `org-agenda-diary-file' points to a file,
  7568. `org-agenda-diary-entry-in-org-file' is called instead to create
  7569. entries in that Org-mode file."
  7570. (interactive)
  7571. (org-agenda-check-type t 'agenda 'timeline)
  7572. (if (not (eq org-agenda-diary-file 'diary-file))
  7573. (org-agenda-diary-entry-in-org-file)
  7574. (require 'diary-lib)
  7575. (let* ((char (progn
  7576. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7577. (read-char-exclusive)))
  7578. (cmd (cdr (assoc char
  7579. '((?d . insert-diary-entry)
  7580. (?w . insert-weekly-diary-entry)
  7581. (?m . insert-monthly-diary-entry)
  7582. (?y . insert-yearly-diary-entry)
  7583. (?a . insert-anniversary-diary-entry)
  7584. (?b . insert-block-diary-entry)
  7585. (?c . insert-cyclic-diary-entry)))))
  7586. (oldf (symbol-function 'calendar-cursor-to-date))
  7587. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7588. (point (point))
  7589. (mark (or (mark t) (point))))
  7590. (unless cmd
  7591. (error "No command associated with <%c>" char))
  7592. (unless (and (get-text-property point 'day)
  7593. (or (not (equal ?b char))
  7594. (get-text-property mark 'day)))
  7595. (error "Don't know which date to use for diary entry"))
  7596. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7597. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7598. (let ((calendar-mark-ring
  7599. (list (calendar-gregorian-from-absolute
  7600. (or (get-text-property mark 'day)
  7601. (get-text-property point 'day))))))
  7602. (unwind-protect
  7603. (progn
  7604. (fset 'calendar-cursor-to-date
  7605. (lambda (&optional error dummy)
  7606. (calendar-gregorian-from-absolute
  7607. (get-text-property point 'day))))
  7608. (call-interactively cmd))
  7609. (fset 'calendar-cursor-to-date oldf))))))
  7610. (defun org-agenda-execute-calendar-command (cmd)
  7611. "Execute a calendar command from the agenda, with the date associated to
  7612. the cursor position."
  7613. (org-agenda-check-type t 'agenda 'timeline)
  7614. (require 'diary-lib)
  7615. (unless (get-text-property (point) 'day)
  7616. (error "Don't know which date to use for calendar command"))
  7617. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7618. (point (point))
  7619. (date (calendar-gregorian-from-absolute
  7620. (get-text-property point 'day)))
  7621. ;; the following 2 vars are needed in the calendar
  7622. (displayed-month (car date))
  7623. (displayed-year (nth 2 date)))
  7624. (unwind-protect
  7625. (progn
  7626. (fset 'calendar-cursor-to-date
  7627. (lambda (&optional error dummy)
  7628. (calendar-gregorian-from-absolute
  7629. (get-text-property point 'day))))
  7630. (call-interactively cmd))
  7631. (fset 'calendar-cursor-to-date oldf))))
  7632. (defun org-agenda-phases-of-moon ()
  7633. "Display the phases of the moon for the 3 months around the cursor date."
  7634. (interactive)
  7635. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7636. (defun org-agenda-holidays ()
  7637. "Display the holidays for the 3 months around the cursor date."
  7638. (interactive)
  7639. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7640. (defvar calendar-longitude)
  7641. (defvar calendar-latitude)
  7642. (defvar calendar-location-name)
  7643. (defun org-agenda-sunrise-sunset (arg)
  7644. "Display sunrise and sunset for the cursor date.
  7645. Latitude and longitude can be specified with the variables
  7646. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7647. argument, latitude and longitude will be prompted for."
  7648. (interactive "P")
  7649. (require 'solar)
  7650. (let ((calendar-longitude (if arg nil calendar-longitude))
  7651. (calendar-latitude (if arg nil calendar-latitude))
  7652. (calendar-location-name
  7653. (if arg "the given coordinates" calendar-location-name)))
  7654. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7655. (defun org-agenda-goto-calendar ()
  7656. "Open the Emacs calendar with the date at the cursor."
  7657. (interactive)
  7658. (org-agenda-check-type t 'agenda 'timeline)
  7659. (let* ((day (or (get-text-property (point) 'day)
  7660. (error "Don't know which date to open in calendar")))
  7661. (date (calendar-gregorian-from-absolute day))
  7662. (calendar-move-hook nil)
  7663. (calendar-view-holidays-initially-flag nil)
  7664. (calendar-view-diary-initially-flag nil))
  7665. (calendar)
  7666. (calendar-goto-date date)))
  7667. ;;;###autoload
  7668. (defun org-calendar-goto-agenda ()
  7669. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7670. This is a command that has to be installed in `calendar-mode-map'."
  7671. (interactive)
  7672. (org-agenda-list nil (calendar-absolute-from-gregorian
  7673. (calendar-cursor-to-date))
  7674. nil))
  7675. (defun org-agenda-convert-date ()
  7676. (interactive)
  7677. (org-agenda-check-type t 'agenda 'timeline)
  7678. (let ((day (get-text-property (point) 'day))
  7679. date s)
  7680. (unless day
  7681. (error "Don't know which date to convert"))
  7682. (setq date (calendar-gregorian-from-absolute day))
  7683. (setq s (concat
  7684. "Gregorian: " (calendar-date-string date) "\n"
  7685. "ISO: " (calendar-iso-date-string date) "\n"
  7686. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7687. "Julian: " (calendar-julian-date-string date) "\n"
  7688. "Astron. JD: " (calendar-astro-date-string date)
  7689. " (Julian date number at noon UTC)\n"
  7690. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7691. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7692. "French: " (calendar-french-date-string date) "\n"
  7693. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7694. "Mayan: " (calendar-mayan-date-string date) "\n"
  7695. "Coptic: " (calendar-coptic-date-string date) "\n"
  7696. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7697. "Persian: " (calendar-persian-date-string date) "\n"
  7698. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7699. (with-output-to-temp-buffer "*Dates*"
  7700. (princ s))
  7701. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7702. ;;; Bulk commands
  7703. (defvar org-agenda-bulk-marked-entries nil
  7704. "List of markers that refer to marked entries in the agenda.")
  7705. (defun org-agenda-bulk-marked-p ()
  7706. (eq (get-char-property (point-at-bol) 'type)
  7707. 'org-marked-entry-overlay))
  7708. (defun org-agenda-bulk-mark (&optional arg)
  7709. "Mark the entry at point for future bulk action."
  7710. (interactive "p")
  7711. (dotimes (i (max arg 1))
  7712. (unless (org-get-at-bol 'org-agenda-diary-link)
  7713. (let* ((m (org-get-at-bol 'org-hd-marker))
  7714. ov)
  7715. (unless (org-agenda-bulk-marked-p)
  7716. (unless m (error "Nothing to mark at point"))
  7717. (push m org-agenda-bulk-marked-entries)
  7718. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7719. (org-overlay-display ov "> "
  7720. (org-get-todo-face "TODO")
  7721. 'evaporate)
  7722. (overlay-put ov 'type 'org-marked-entry-overlay))
  7723. (beginning-of-line 2)
  7724. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7725. (beginning-of-line 2))
  7726. (message "%d entries marked for bulk action"
  7727. (length org-agenda-bulk-marked-entries))))))
  7728. (defun org-agenda-bulk-mark-regexp (regexp)
  7729. "Mark entries match REGEXP."
  7730. (interactive "sMark entries matching regexp: ")
  7731. (let (entries-marked)
  7732. (save-excursion
  7733. (goto-char (point-min))
  7734. (goto-char (next-single-property-change (point) 'txt))
  7735. (while (re-search-forward regexp nil t)
  7736. (when (string-match regexp (get-text-property (point) 'txt))
  7737. (setq entries-marked (+ entries-marked 1))
  7738. (call-interactively 'org-agenda-bulk-mark))))
  7739. (if (not entries-marked)
  7740. (message "No entry matching this regexp."))))
  7741. (defun org-agenda-bulk-unmark ()
  7742. "Unmark the entry at point for future bulk action."
  7743. (interactive)
  7744. (when (org-agenda-bulk-marked-p)
  7745. (org-agenda-bulk-remove-overlays
  7746. (point-at-bol) (+ 2 (point-at-bol)))
  7747. (setq org-agenda-bulk-marked-entries
  7748. (delete (org-get-at-bol 'org-hd-marker)
  7749. org-agenda-bulk-marked-entries)))
  7750. (beginning-of-line 2)
  7751. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7752. (beginning-of-line 2))
  7753. (message "%d entries marked for bulk action"
  7754. (length org-agenda-bulk-marked-entries)))
  7755. (defun org-agenda-bulk-toggle ()
  7756. "Toggle marking the entry at point for bulk action."
  7757. (interactive)
  7758. (if (org-agenda-bulk-marked-p)
  7759. (org-agenda-bulk-unmark)
  7760. (org-agenda-bulk-mark)))
  7761. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7762. "Remove the mark overlays between BEG and END in the agenda buffer.
  7763. BEG and END default to the buffer limits.
  7764. This only removes the overlays, it does not remove the markers
  7765. from the list in `org-agenda-bulk-marked-entries'."
  7766. (interactive)
  7767. (mapc (lambda (ov)
  7768. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7769. (delete-overlay ov)))
  7770. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7771. (defun org-agenda-bulk-remove-all-marks ()
  7772. "Remove all marks in the agenda buffer.
  7773. This will remove the markers, and the overlays."
  7774. (interactive)
  7775. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7776. (setq org-agenda-bulk-marked-entries nil)
  7777. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7778. (defun org-agenda-bulk-action (&optional arg)
  7779. "Execute an remote-editing action on all marked entries.
  7780. The prefix arg is passed through to the command if possible."
  7781. (interactive "P")
  7782. ;; Make sure we have markers, and only valid ones
  7783. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7784. (mapc
  7785. (lambda (m)
  7786. (unless (and (markerp m)
  7787. (marker-buffer m)
  7788. (buffer-live-p (marker-buffer m))
  7789. (marker-position m))
  7790. (error "Marker %s for bulk command is invalid" m)))
  7791. org-agenda-bulk-marked-entries)
  7792. ;; Prompt for the bulk command
  7793. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7794. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7795. (when org-agenda-bulk-custom-functions
  7796. (concat " Custom: ["
  7797. (mapconcat (lambda(f) (char-to-string (car f)))
  7798. org-agenda-bulk-custom-functions "")
  7799. "]"))))
  7800. (let* ((action (read-char-exclusive))
  7801. (org-log-refile (if org-log-refile 'time nil))
  7802. (entries (reverse org-agenda-bulk-marked-entries))
  7803. redo-at-end
  7804. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7805. (cond
  7806. ((equal action ?$)
  7807. (setq cmd '(org-agenda-archive)))
  7808. ((equal action ?A)
  7809. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7810. ((member action '(?r ?w))
  7811. (setq rfloc (org-refile-get-location
  7812. "Refile to"
  7813. (marker-buffer (car org-agenda-bulk-marked-entries))
  7814. org-refile-allow-creating-parent-nodes))
  7815. (if (nth 3 rfloc)
  7816. (setcar (nthcdr 3 rfloc)
  7817. (move-marker (make-marker) (nth 3 rfloc)
  7818. (or (get-file-buffer (nth 1 rfloc))
  7819. (find-buffer-visiting (nth 1 rfloc))
  7820. (error "This should not happen")))))
  7821. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7822. redo-at-end t))
  7823. ((equal action ?t)
  7824. (setq state (org-icompleting-read
  7825. "Todo state: "
  7826. (with-current-buffer (marker-buffer (car entries))
  7827. (mapcar 'list org-todo-keywords-1))))
  7828. (setq cmd `(let ((org-inhibit-blocking t)
  7829. (org-inhibit-logging 'note))
  7830. (org-agenda-todo ,state))))
  7831. ((memq action '(?- ?+))
  7832. (setq tag (org-icompleting-read
  7833. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7834. (with-current-buffer (marker-buffer (car entries))
  7835. (delq nil
  7836. (mapcar (lambda (x)
  7837. (if (stringp (car x)) x)) org-tag-alist)))))
  7838. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7839. ((memq action '(?s ?d))
  7840. (let* ((date (unless arg
  7841. (org-read-date
  7842. nil nil nil
  7843. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7844. (ans (if arg nil org-read-date-final-answer))
  7845. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7846. (setq cmd `(let* ((bound (fboundp 'read-string))
  7847. (old (and bound (symbol-function 'read-string))))
  7848. (unwind-protect
  7849. (progn
  7850. (fset 'read-string (lambda (&rest ignore) ,ans))
  7851. (eval '(,c1 arg)))
  7852. (if bound
  7853. (fset 'read-string old)
  7854. (fmakunbound 'read-string)))))))
  7855. ((equal action ?S)
  7856. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7857. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7858. (let ((days (read-number
  7859. (format "Scatter tasks across how many %sdays: "
  7860. (if arg "week" "")) 7)))
  7861. (setq cmd
  7862. `(let ((distance (1+ (random ,days))))
  7863. (if arg
  7864. (let ((dist distance)
  7865. (day-of-week
  7866. (calendar-day-of-week
  7867. (calendar-gregorian-from-absolute (org-today)))))
  7868. (dotimes (i (1+ dist))
  7869. (while (member day-of-week org-agenda-weekend-days)
  7870. (incf distance)
  7871. (incf day-of-week)
  7872. (if (= day-of-week 7)
  7873. (setq day-of-week 0)))
  7874. (incf day-of-week)
  7875. (if (= day-of-week 7)
  7876. (setq day-of-week 0)))))
  7877. ;; silently fail when try to replan a sexp entry
  7878. (condition-case nil
  7879. (let* ((date (calendar-gregorian-from-absolute
  7880. (+ (org-today) distance)))
  7881. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7882. (nth 2 date))))
  7883. (org-agenda-schedule nil time))
  7884. (error nil)))))))
  7885. ((assoc action org-agenda-bulk-custom-functions)
  7886. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7887. redo-at-end t))
  7888. ((equal action ?f)
  7889. (setq cmd (list (intern
  7890. (org-icompleting-read "Function: "
  7891. obarray 'fboundp t nil nil)))))
  7892. (t (error "Invalid bulk action")))
  7893. ;; Sort the markers, to make sure that parents are handled before children
  7894. (setq entries (sort entries
  7895. (lambda (a b)
  7896. (cond
  7897. ((equal (marker-buffer a) (marker-buffer b))
  7898. (< (marker-position a) (marker-position b)))
  7899. (t
  7900. (string< (buffer-name (marker-buffer a))
  7901. (buffer-name (marker-buffer b))))))))
  7902. ;; Now loop over all markers and apply cmd
  7903. (while (setq e (pop entries))
  7904. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7905. (if (not pos)
  7906. (progn (message "Skipping removed entry at %s" e)
  7907. (setq cntskip (1+ cntskip)))
  7908. (goto-char pos)
  7909. (let (org-loop-over-headlines-in-active-region)
  7910. (eval cmd))
  7911. (setq org-agenda-bulk-marked-entries
  7912. (delete e org-agenda-bulk-marked-entries))
  7913. (setq cnt (1+ cnt))))
  7914. (setq org-agenda-bulk-marked-entries nil)
  7915. (org-agenda-bulk-remove-all-marks)
  7916. (when redo-at-end (org-agenda-redo))
  7917. (message "Acted on %d entries%s"
  7918. cnt
  7919. (if (= cntskip 0)
  7920. ""
  7921. (format ", skipped %d (disappeared before their turn)"
  7922. cntskip)))))
  7923. ;;; Flagging notes
  7924. (defun org-agenda-show-the-flagging-note ()
  7925. "Display the flagging note in the other window.
  7926. When called a second time in direct sequence, offer to remove the FLAGGING
  7927. tag and (if present) the flagging note."
  7928. (interactive)
  7929. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7930. (win (selected-window))
  7931. note heading newhead)
  7932. (unless hdmarker
  7933. (error "No linked entry at point"))
  7934. (if (and (eq this-command last-command)
  7935. (y-or-n-p "Unflag and remove any flagging note? "))
  7936. (progn
  7937. (org-agenda-remove-flag hdmarker)
  7938. (let ((win (get-buffer-window "*Flagging Note*")))
  7939. (and win (delete-window win)))
  7940. (message "Entry unflagged"))
  7941. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7942. (unless note
  7943. (error "No flagging note"))
  7944. (org-kill-new note)
  7945. (org-switch-to-buffer-other-window "*Flagging Note*")
  7946. (erase-buffer)
  7947. (insert note)
  7948. (goto-char (point-min))
  7949. (while (re-search-forward "\\\\n" nil t)
  7950. (replace-match "\n" t t))
  7951. (goto-char (point-min))
  7952. (select-window win)
  7953. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7954. (defun org-agenda-remove-flag (marker)
  7955. "Remove the FLAGGED tag and any flagging note in the entry."
  7956. (let (newhead)
  7957. (org-with-point-at marker
  7958. (org-toggle-tag "FLAGGED" 'off)
  7959. (org-entry-delete nil "THEFLAGGINGNOTE")
  7960. (setq newhead (org-get-heading)))
  7961. (org-agenda-change-all-lines newhead marker)
  7962. (message "Entry unflagged")))
  7963. (defun org-agenda-get-any-marker (&optional pos)
  7964. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7965. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7966. ;;; Appointment reminders
  7967. (defvar appt-time-msg-list)
  7968. ;;;###autoload
  7969. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  7970. "Activate appointments found in `org-agenda-files'.
  7971. With a \\[universal-argument] prefix, refresh the list of
  7972. appointments.
  7973. If FILTER is t, interactively prompt the user for a regular
  7974. expression, and filter out entries that don't match it.
  7975. If FILTER is a string, use this string as a regular expression
  7976. for filtering entries out.
  7977. If FILTER is a function, filter out entries against which
  7978. calling the function returns nil. This function takes one
  7979. argument: an entry from `org-agenda-get-day-entries'.
  7980. FILTER can also be an alist with the car of each cell being
  7981. either 'headline or 'category. For example:
  7982. '((headline \"IMPORTANT\")
  7983. (category \"Work\"))
  7984. will only add headlines containing IMPORTANT or headlines
  7985. belonging to the \"Work\" category.
  7986. ARGS are symbols indicating what kind of entries to consider.
  7987. By default `org-agenda-to-appt' will use :deadline, :scheduled
  7988. and :timestamp entries. See the docstring of `org-diary' for
  7989. details and examples."
  7990. (interactive "P")
  7991. (if refresh (setq appt-time-msg-list nil))
  7992. (if (eq filter t)
  7993. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7994. (let* ((cnt 0) ; count added events
  7995. (scope (or args '(:deadline :scheduled :timestamp)))
  7996. (org-agenda-new-buffers nil)
  7997. (org-deadline-warning-days 0)
  7998. ;; Do not use `org-today' here because appt only takes
  7999. ;; time and without date as argument, so it may pass wrong
  8000. ;; information otherwise
  8001. (today (org-date-to-gregorian
  8002. (time-to-days (current-time))))
  8003. (org-agenda-restrict nil)
  8004. (files (org-agenda-files 'unrestricted)) entries file)
  8005. ;; Get all entries which may contain an appt
  8006. (org-prepare-agenda-buffers files)
  8007. (while (setq file (pop files))
  8008. (setq entries
  8009. (delq nil
  8010. (append entries
  8011. (apply 'org-agenda-get-day-entries
  8012. file today scope)))))
  8013. ;; Map thru entries and find if we should filter them out
  8014. (mapc
  8015. (lambda(x)
  8016. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8017. (cat (get-text-property 1 'org-category x))
  8018. (tod (get-text-property 1 'time-of-day x))
  8019. (ok (or (null filter)
  8020. (and (stringp filter) (string-match filter evt))
  8021. (and (functionp filter) (funcall filter x))
  8022. (and (listp filter)
  8023. (let ((cat-filter (cadr (assoc 'category filter)))
  8024. (evt-filter (cadr (assoc 'headline filter))))
  8025. (or (and (stringp cat-filter)
  8026. (string-match cat-filter cat))
  8027. (and (stringp evt-filter)
  8028. (string-match evt-filter evt))))))))
  8029. ;; FIXME: Shall we remove text-properties for the appt text?
  8030. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8031. (when (and ok tod)
  8032. (setq tod (concat "00" (number-to-string tod))
  8033. tod (when (string-match
  8034. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8035. (concat (match-string 1 tod) ":"
  8036. (match-string 2 tod))))
  8037. (appt-add tod evt)
  8038. (setq cnt (1+ cnt))))) entries)
  8039. (org-release-buffers org-agenda-new-buffers)
  8040. (if (eq cnt 0)
  8041. (message "No event to add")
  8042. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8043. (defun org-agenda-todayp (date)
  8044. "Does DATE mean today, when considering `org-extend-today-until'?"
  8045. (let ((today (org-today))
  8046. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8047. date)))
  8048. (eq date today)))
  8049. (defun org-agenda-todo-yesterday (&optional arg)
  8050. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8051. (interactive "P")
  8052. (let* ((hour (third (decode-time
  8053. (org-current-time))))
  8054. (org-extend-today-until (1+ hour)))
  8055. (org-agenda-todo arg)))
  8056. (provide 'org-agenda)
  8057. ;;; org-agenda.el ends here