org-agenda.el 306 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.3
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-ndays)
  217. (integer :value 1))
  218. (list :tag "Fixed starting date"
  219. (const org-agenda-start-day)
  220. (string :value "2007-11-01"))
  221. (list :tag "Start on day of week"
  222. (const org-agenda-start-on-weekday)
  223. (choice :value 1
  224. (const :tag "Today" nil)
  225. (integer :tag "Weekday No.")))
  226. (list :tag "Include data from diary"
  227. (const org-agenda-include-diary)
  228. (boolean))
  229. (list :tag "Deadline Warning days"
  230. (const org-deadline-warning-days)
  231. (integer :value 1))
  232. (list :tag "Tags filter preset"
  233. (const org-agenda-filter-preset)
  234. (list
  235. (const :format "" quote)
  236. (repeat
  237. (string :tag "+tag or -tag"))))
  238. (list :tag "Set daily/weekly entry types"
  239. (const org-agenda-entry-types)
  240. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  241. (const :deadline)
  242. (const :scheduled)
  243. (const :timestamp)
  244. (const :sexp)))
  245. (list :tag "Standard skipping condition"
  246. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  247. (const org-agenda-skip-function)
  248. (list
  249. (const :format "" quote)
  250. (list
  251. (choice
  252. :tag "Skipping range"
  253. (const :tag "Skip entry" org-agenda-skip-entry-if)
  254. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  255. (repeat :inline t :tag "Conditions for skipping"
  256. (choice
  257. :tag "Condition type"
  258. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  259. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  260. (list :tag "TODO state is" :inline t
  261. (const 'todo)
  262. (choice
  263. (const :tag "any not-done state" 'todo)
  264. (const :tag "any done state" 'done)
  265. (const :tag "any state" 'any)
  266. (list :tag "Keyword list"
  267. (const :format "" quote)
  268. (repeat (string :tag "Keyword")))))
  269. (list :tag "TODO state is not" :inline t
  270. (const 'nottodo)
  271. (choice
  272. (const :tag "any not-done state" 'todo)
  273. (const :tag "any done state" 'done)
  274. (const :tag "any state" 'any)
  275. (list :tag "Keyword list"
  276. (const :format "" quote)
  277. (repeat (string :tag "Keyword")))))
  278. (const :tag "scheduled" 'scheduled)
  279. (const :tag "not scheduled" 'notscheduled)
  280. (const :tag "deadline" 'deadline)
  281. (const :tag "no deadline" 'notdeadline)
  282. (const :tag "timestamp" 'timestamp)
  283. (const :tag "no timestamp" 'nottimestamp))))))
  284. (list :tag "Non-standard skipping condition"
  285. :value (org-agenda-skip-function)
  286. (const org-agenda-skip-function)
  287. (sexp :tag "Function or form (quoted!)"))
  288. (list :tag "Any variable"
  289. (variable :tag "Variable")
  290. (sexp :tag "Value (sexp)"))))
  291. "Selection of examples for agenda command settings.
  292. This will be spliced into the custom type of
  293. `org-agenda-custom-commands'.")
  294. (defcustom org-agenda-custom-commands nil
  295. "Custom commands for the agenda.
  296. These commands will be offered on the splash screen displayed by the
  297. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  298. (key desc type match settings files)
  299. key The key (one or more characters as a string) to be associated
  300. with the command.
  301. desc A description of the command, when omitted or nil, a default
  302. description is built using MATCH.
  303. type The command type, any of the following symbols:
  304. agenda The daily/weekly agenda.
  305. todo Entries with a specific TODO keyword, in all agenda files.
  306. search Entries containing search words entry or headline.
  307. tags Tags/Property/TODO match in all agenda files.
  308. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  309. todo-tree Sparse tree of specific TODO keyword in *current* file.
  310. tags-tree Sparse tree with all tags matches in *current* file.
  311. occur-tree Occur sparse tree for *current* file.
  312. ... A user-defined function.
  313. match What to search for:
  314. - a single keyword for TODO keyword searches
  315. - a tags match expression for tags searches
  316. - a word search expression for text searches.
  317. - a regular expression for occur searches
  318. For all other commands, this should be the empty string.
  319. settings A list of option settings, similar to that in a let form, so like
  320. this: ((opt1 val1) (opt2 val2) ...). The values will be
  321. evaluated at the moment of execution, so quote them when needed.
  322. files A list of files file to write the produced agenda buffer to
  323. with the command `org-store-agenda-views'.
  324. If a file name ends in \".html\", an HTML version of the buffer
  325. is written out. If it ends in \".ps\", a postscript version is
  326. produced. Otherwise, only the plain text is written to the file.
  327. You can also define a set of commands, to create a composite agenda buffer.
  328. In this case, an entry looks like this:
  329. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  330. where
  331. desc A description string to be displayed in the dispatcher menu.
  332. cmd An agenda command, similar to the above. However, tree commands
  333. are no allowed, but instead you can get agenda and global todo list.
  334. So valid commands for a set are:
  335. (agenda \"\" settings)
  336. (alltodo \"\" settings)
  337. (stuck \"\" settings)
  338. (todo \"match\" settings files)
  339. (search \"match\" settings files)
  340. (tags \"match\" settings files)
  341. (tags-todo \"match\" settings files)
  342. Each command can carry a list of options, and another set of options can be
  343. given for the whole set of commands. Individual command options take
  344. precedence over the general options.
  345. When using several characters as key to a command, the first characters
  346. are prefix commands. For the dispatcher to display useful information, you
  347. should provide a description for the prefix, like
  348. (setq org-agenda-custom-commands
  349. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  350. (\"hl\" tags \"+HOME+Lisa\")
  351. (\"hp\" tags \"+HOME+Peter\")
  352. (\"hk\" tags \"+HOME+Kim\")))"
  353. :group 'org-agenda-custom-commands
  354. :type `(repeat
  355. (choice :value ("x" "Describe command here" tags "" nil)
  356. (list :tag "Single command"
  357. (string :tag "Access Key(s) ")
  358. (option (string :tag "Description"))
  359. (choice
  360. (const :tag "Agenda" agenda)
  361. (const :tag "TODO list" alltodo)
  362. (const :tag "Search words" search)
  363. (const :tag "Stuck projects" stuck)
  364. (const :tag "Tags/Property match (all agenda files)" tags)
  365. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  366. (const :tag "TODO keyword search (all agenda files)" todo)
  367. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  368. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  369. (const :tag "Occur tree (current buffer)" occur-tree)
  370. (sexp :tag "Other, user-defined function"))
  371. (string :tag "Match (only for some commands)")
  372. ,org-agenda-custom-commands-local-options
  373. (option (repeat :tag "Export" (file :tag "Export to"))))
  374. (list :tag "Command series, all agenda files"
  375. (string :tag "Access Key(s)")
  376. (string :tag "Description ")
  377. (repeat :tag "Component"
  378. (choice
  379. (list :tag "Agenda"
  380. (const :format "" agenda)
  381. (const :tag "" :format "" "")
  382. ,org-agenda-custom-commands-local-options)
  383. (list :tag "TODO list (all keywords)"
  384. (const :format "" alltodo)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "Search words"
  388. (const :format "" search)
  389. (string :tag "Match")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Stuck projects"
  392. (const :format "" stuck)
  393. (const :tag "" :format "" "")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Tags search"
  396. (const :format "" tags)
  397. (string :tag "Match")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search, TODO entries only"
  400. (const :format "" tags-todo)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "TODO keyword search"
  404. (const :format "" todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "Other, user-defined function"
  408. (symbol :tag "function")
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)))
  411. (repeat :tag "Settings for entire command set"
  412. (list (variable :tag "Any variable")
  413. (sexp :tag "Value")))
  414. (option (repeat :tag "Export" (file :tag "Export to"))))
  415. (cons :tag "Prefix key documentation"
  416. (string :tag "Access Key(s)")
  417. (string :tag "Description ")))))
  418. (defcustom org-agenda-query-register ?o
  419. "The register holding the current query string.
  420. The purpose of this is that if you construct a query string interactively,
  421. you can then use it to define a custom command."
  422. :group 'org-agenda-custom-commands
  423. :type 'character)
  424. (defcustom org-stuck-projects
  425. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  426. "How to identify stuck projects.
  427. This is a list of four items:
  428. 1. A tags/todo/property matcher string that is used to identify a project.
  429. See the manual for a description of tag and property searches.
  430. The entire tree below a headline matched by this is considered one project.
  431. 2. A list of TODO keywords identifying non-stuck projects.
  432. If the project subtree contains any headline with one of these todo
  433. keywords, the project is considered to be not stuck. If you specify
  434. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  435. 3. A list of tags identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these tags,
  437. the project is considered to be not stuck. If you specify \"*\" as
  438. a tag, any tag will mark the project unstuck. Note that this is about
  439. the explicit presence of a tag somewhere in the subtree, inherited
  440. tags to not count here. If inherited tags make a project not stuck,
  441. use \"-TAG\" in the tags part of the matcher under (1.) above.
  442. 4. An arbitrary regular expression matching non-stuck projects.
  443. If the project turns out to be not stuck, search continues also in the
  444. subtree to see if any of the subtasks have project status.
  445. See also the variable `org-tags-match-list-sublevels' which applies
  446. to projects matched by this search as well.
  447. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  448. or `C-c a #' to produce the list."
  449. :group 'org-agenda-custom-commands
  450. :type '(list
  451. (string :tag "Tags/TODO match to identify a project")
  452. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  453. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  454. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  455. (defcustom org-agenda-filter-effort-default-operator "<"
  456. "The default operator for effort estimate filtering.
  457. If you select an effort estimate limit without first pressing an operator,
  458. this one will be used."
  459. :group 'org-agenda-custom-commands
  460. :type '(choice (const :tag "less or equal" "<")
  461. (const :tag "greater or equal"">")
  462. (const :tag "equal" "=")))
  463. (defgroup org-agenda-skip nil
  464. "Options concerning skipping parts of agenda files."
  465. :tag "Org Agenda Skip"
  466. :group 'org-agenda)
  467. (defgroup org-agenda-daily/weekly nil
  468. "Options concerning the daily/weekly agenda."
  469. :tag "Org Agenda Daily/Weekly"
  470. :group 'org-agenda)
  471. (defgroup org-agenda-todo-list nil
  472. "Options concerning the global todo list agenda view."
  473. :tag "Org Agenda Todo List"
  474. :group 'org-agenda)
  475. (defgroup org-agenda-match-view nil
  476. "Options concerning the general tags/property/todo match agenda view."
  477. :tag "Org Agenda Match View"
  478. :group 'org-agenda)
  479. (defgroup org-agenda-search-view nil
  480. "Options concerning the general tags/property/todo match agenda view."
  481. :tag "Org Agenda Match View"
  482. :group 'org-agenda)
  483. (defvar org-agenda-archives-mode nil
  484. "Non-nil means the agenda will include archived items.
  485. If this is the symbol `trees', trees in the selected agenda scope
  486. that are marked with the ARCHIVE tag will be included anyway. When this is
  487. t, also all archive files associated with the current selection of agenda
  488. files will be included.")
  489. (defcustom org-agenda-skip-comment-trees t
  490. "Non-nil means skip trees that start with the COMMENT keyword.
  491. When nil, these trees are also scanned by agenda commands."
  492. :group 'org-agenda-skip
  493. :type 'boolean)
  494. (defcustom org-agenda-todo-list-sublevels t
  495. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  496. When nil, the sublevels of a TODO entry are not checked, resulting in
  497. potentially much shorter TODO lists."
  498. :group 'org-agenda-skip
  499. :group 'org-agenda-todo-list
  500. :type 'boolean)
  501. (defcustom org-agenda-todo-ignore-with-date nil
  502. "Non-nil means don't show entries with a date in the global todo list.
  503. You can use this if you prefer to mark mere appointments with a TODO keyword,
  504. but don't want them to show up in the TODO list.
  505. When this is set, it also covers deadlines and scheduled items, the settings
  506. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  507. will be ignored.
  508. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-todo-list
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-ignore-timestamp nil
  513. "Non-nil means don't show entries with a timestamp.
  514. This applies when creating the global todo list.
  515. Valid values are:
  516. past Don't show entries for today or in the past.
  517. future Don't show entries with a timestamp in the future.
  518. The idea behind this is that if it has a future
  519. timestamp, you don't want to think about it until the
  520. date.
  521. all Don't show any entries with a timestamp in the global todo list.
  522. The idea behind this is that by setting a timestamp, you
  523. have already \"taken care\" of this item.
  524. See also `org-agenda-todo-ignore-with-date'.
  525. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  526. to make his option also apply to the tags-todo list."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type '(choice
  530. (const :tag "Ignore future timestamp todos" future)
  531. (const :tag "Ignore past or present timestamp todos" past)
  532. (const :tag "Ignore all timestamp todos" all)
  533. (const :tag "Show timestamp todos" nil)))
  534. (defcustom org-agenda-todo-ignore-scheduled nil
  535. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  536. This applies when creating the global todo list.
  537. Valid values are:
  538. past Don't show entries scheduled today or in the past.
  539. future Don't show entries scheduled in the future.
  540. The idea behind this is that by scheduling it, you don't want to
  541. think about it until the scheduled date.
  542. all Don't show any scheduled entries in the global todo list.
  543. The idea behind this is that by scheduling it, you have already
  544. \"taken care\" of this item.
  545. t Same as `all', for backward compatibility.
  546. See also `org-agenda-todo-ignore-with-date'.
  547. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  548. to make his option also apply to the tags-todo list."
  549. :group 'org-agenda-skip
  550. :group 'org-agenda-todo-list
  551. :type '(choice
  552. (const :tag "Ignore future-scheduled todos" future)
  553. (const :tag "Ignore past- or present-scheduled todos" past)
  554. (const :tag "Ignore all scheduled todos" all)
  555. (const :tag "Ignore all scheduled todos (compatibility)" t)
  556. (const :tag "Show scheduled todos" nil)))
  557. (defcustom org-agenda-todo-ignore-deadlines nil
  558. "Non-nil means ignore some deadlined TODO items when making TODO list.
  559. There are different motivations for using different values, please think
  560. carefully when configuring this variable.
  561. This applies when creating the global todo list.
  562. Valid values are:
  563. near Don't show near deadline entries. A deadline is near when it is
  564. closer than `org-deadline-warning-days' days. The idea behind this
  565. is that such items will appear in the agenda anyway.
  566. far Don't show TODO entries where a deadline has been defined, but
  567. the deadline is not near. This is useful if you don't want to
  568. use the todo list to figure out what to do now.
  569. past Don't show entries with a deadline timestamp for today or in the past.
  570. future Don't show entries with a deadline timestamp in the future, not even
  571. when they become `near' ones. Use it with caution.
  572. all Ignore all TODO entries that do have a deadline.
  573. t Same as `near', for backward compatibility.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore near deadlines" near)
  581. (const :tag "Ignore near deadlines (compatibility)" t)
  582. (const :tag "Ignore far deadlines" far)
  583. (const :tag "Ignore all TODOs with a deadlines" all)
  584. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  585. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  586. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  587. The variables
  588. `org-agenda-todo-ignore-with-date',
  589. `org-agenda-todo-ignore-timestamp',
  590. `org-agenda-todo-ignore-scheduled',
  591. `org-agenda-todo-ignore-deadlines'
  592. make the global TODO list skip entries that have time stamps of certain
  593. kinds. If this option is set, the same options will also apply for the
  594. tags-todo search, which is the general tags/property matcher
  595. restricted to unfinished TODO entries only."
  596. :group 'org-agenda-skip
  597. :group 'org-agenda-todo-list
  598. :group 'org-agenda-match-view
  599. :type 'boolean)
  600. (defcustom org-agenda-skip-scheduled-if-done nil
  601. "Non-nil means don't show scheduled items in agenda when they are done.
  602. This is relevant for the daily/weekly agenda, not for the TODO list. And
  603. it applies only to the actual date of the scheduling. Warnings about
  604. an item with a past scheduling dates are always turned off when the item
  605. is DONE."
  606. :group 'org-agenda-skip
  607. :group 'org-agenda-daily/weekly
  608. :type 'boolean)
  609. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  610. "Non-nil means skip scheduling line if same entry shows because of deadline.
  611. In the agenda of today, an entry can show up multiple times because
  612. it is both scheduled and has a nearby deadline, and maybe a plain time
  613. stamp as well.
  614. When this variable is t, then only the deadline is shown and the fact that
  615. the entry is scheduled today or was scheduled previously is not shown.
  616. When this variable is nil, the entry will be shown several times. When
  617. the variable is the symbol `not-today', then skip scheduled previously,
  618. but not scheduled today."
  619. :group 'org-agenda-skip
  620. :group 'org-agenda-daily/weekly
  621. :type '(choice
  622. (const :tag "Never" nil)
  623. (const :tag "Always" t)
  624. (const :tag "Not when scheduled today" not-today)))
  625. (defcustom org-agenda-skip-deadline-if-done nil
  626. "Non-nil means don't show deadlines when the corresponding item is done.
  627. When nil, the deadline is still shown and should give you a happy feeling.
  628. This is relevant for the daily/weekly agenda. And it applied only to the
  629. actually date of the deadline. Warnings about approaching and past-due
  630. deadlines are always turned off when the item is DONE."
  631. :group 'org-agenda-skip
  632. :group 'org-agenda-daily/weekly
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  635. "Non-nil means skip deadline prewarning when entry is also scheduled.
  636. This will apply on all days where a prewarning for the deadline would
  637. be shown, but not at the day when the entry is actually due. On that day,
  638. the deadline will be shown anyway.
  639. This variable may be set to nil, t, or a number which will then give
  640. the number of days before the actual deadline when the prewarnings
  641. should resume.
  642. This can be used in a workflow where the first showing of the deadline will
  643. trigger you to schedule it, and then you don't want to be reminded of it
  644. because you will take care of it on the day when scheduled."
  645. :group 'org-agenda-skip
  646. :group 'org-agenda-daily/weekly
  647. :type '(choice
  648. (const :tag "Alwas show prewarning" nil)
  649. (const :tag "Remove prewarning if entry is scheduled" t)
  650. (integer :tag "Restart prewarning N days before deadline")))
  651. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  652. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  653. When non-nil, after the search for timestamps has matched once in an
  654. entry, the rest of the entry will not be searched."
  655. :group 'org-agenda-skip
  656. :type 'boolean)
  657. (defcustom org-agenda-skip-timestamp-if-done nil
  658. "Non-nil means don't select item by timestamp or -range if it is DONE."
  659. :group 'org-agenda-skip
  660. :group 'org-agenda-daily/weekly
  661. :type 'boolean)
  662. (defcustom org-agenda-dim-blocked-tasks t
  663. "Non-nil means dim blocked tasks in the agenda display.
  664. This causes some overhead during agenda construction, but if you
  665. have turned on `org-enforce-todo-dependencies',
  666. `org-enforce-todo-checkbox-dependencies', or any other blocking
  667. mechanism, this will create useful feedback in the agenda.
  668. Instead of t, this variable can also have the value `invisible'.
  669. Then blocked tasks will be invisible and only become visible when
  670. they become unblocked. An exemption to this behavior is when a task is
  671. blocked because of unchecked checkboxes below it. Since checkboxes do
  672. not show up in the agenda views, making this task invisible you remove any
  673. trace from agenda views that there is something to do. Therefore, a task
  674. that is blocked because of checkboxes will never be made invisible, it
  675. will only be dimmed."
  676. :group 'org-agenda-daily/weekly
  677. :group 'org-agenda-todo-list
  678. :type '(choice
  679. (const :tag "Do not dim" nil)
  680. (const :tag "Dim to a grey face" t)
  681. (const :tag "Make invisible" invisible)))
  682. (defcustom org-timeline-show-empty-dates 3
  683. "Non-nil means `org-timeline' also shows dates without an entry.
  684. When nil, only the days which actually have entries are shown.
  685. When t, all days between the first and the last date are shown.
  686. When an integer, show also empty dates, but if there is a gap of more than
  687. N days, just insert a special line indicating the size of the gap."
  688. :group 'org-agenda-skip
  689. :type '(choice
  690. (const :tag "None" nil)
  691. (const :tag "All" t)
  692. (integer :tag "at most")))
  693. (defgroup org-agenda-startup nil
  694. "Options concerning initial settings in the Agenda in Org Mode."
  695. :tag "Org Agenda Startup"
  696. :group 'org-agenda)
  697. (defcustom org-agenda-menu-show-matcher t
  698. "Non-nil menas show the match string in the agenda dispatcher menu.
  699. When nil, the matcher string is not shown, but is put into the help-echo
  700. property so than moving the mouse over the command shows it.
  701. Setting it to nil is good if matcher strings are very long and/or if
  702. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  703. :group 'org-agenda
  704. :type 'boolean)
  705. (defcustom org-agenda-menu-two-column nil
  706. "Non-nil means, use two columns to show custom commands in the dispatcher.
  707. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  708. to nil."
  709. :group 'org-agenda
  710. :type 'boolean)
  711. (defcustom org-finalize-agenda-hook nil
  712. "Hook run just before displaying an agenda buffer."
  713. :group 'org-agenda-startup
  714. :type 'hook)
  715. (defcustom org-agenda-mouse-1-follows-link nil
  716. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  717. A longer mouse click will still set point. Does not work on XEmacs.
  718. Needs to be set before org.el is loaded."
  719. :group 'org-agenda-startup
  720. :type 'boolean)
  721. (defcustom org-agenda-start-with-follow-mode nil
  722. "The initial value of follow mode in a newly created agenda window."
  723. :group 'org-agenda-startup
  724. :type 'boolean)
  725. (defcustom org-agenda-show-outline-path t
  726. "Non-nil means show outline path in echo area after line motion."
  727. :group 'org-agenda-startup
  728. :type 'boolean)
  729. (defcustom org-agenda-start-with-entry-text-mode nil
  730. "The initial value of entry-text-mode in a newly created agenda window."
  731. :group 'org-agenda-startup
  732. :type 'boolean)
  733. (defcustom org-agenda-entry-text-maxlines 5
  734. "Number of text lines to be added when `E' is pressed in the agenda.
  735. Note that this variable only used during agenda display. Add add entry text
  736. when exporting the agenda, configure the variable
  737. `org-agenda-add-entry-ext-maxlines'."
  738. :group 'org-agenda
  739. :type 'integer)
  740. (defcustom org-agenda-entry-text-exclude-regexps nil
  741. "List of regular expressions to clean up entry text.
  742. The complete matches of all regular expressions in this list will be
  743. removed from entry text before it is shown in the agenda."
  744. :group 'org-agenda
  745. :type '(repeat (regexp)))
  746. (defvar org-agenda-entry-text-cleanup-hook nil
  747. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  748. This cleanup is done in a temporary buffer, so the function may inspect and
  749. change the entire buffer.
  750. Some default stuff like drawers and scheduling/deadline dates will already
  751. have been removed when this is called, as will any matches for regular
  752. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  753. (defvar org-agenda-include-inactive-timestamps nil
  754. "Non-nil means include inactive time stamps in agenda and timeline.")
  755. (defgroup org-agenda-windows nil
  756. "Options concerning the windows used by the Agenda in Org Mode."
  757. :tag "Org Agenda Windows"
  758. :group 'org-agenda)
  759. (defcustom org-agenda-window-setup 'reorganize-frame
  760. "How the agenda buffer should be displayed.
  761. Possible values for this option are:
  762. current-window Show agenda in the current window, keeping all other windows.
  763. other-window Use `switch-to-buffer-other-window' to display agenda.
  764. reorganize-frame Show only two windows on the current frame, the current
  765. window and the agenda.
  766. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  767. Also, when exiting the agenda, kill that frame.
  768. See also the variable `org-agenda-restore-windows-after-quit'."
  769. :group 'org-agenda-windows
  770. :type '(choice
  771. (const current-window)
  772. (const other-frame)
  773. (const other-window)
  774. (const reorganize-frame)))
  775. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  776. "The min and max height of the agenda window as a fraction of frame height.
  777. The value of the variable is a cons cell with two numbers between 0 and 1.
  778. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  779. :group 'org-agenda-windows
  780. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  781. (defcustom org-agenda-restore-windows-after-quit nil
  782. "Non-nil means restore window configuration open exiting agenda.
  783. Before the window configuration is changed for displaying the agenda,
  784. the current status is recorded. When the agenda is exited with
  785. `q' or `x' and this option is set, the old state is restored. If
  786. `org-agenda-window-setup' is `other-frame', the value of this
  787. option will be ignored."
  788. :group 'org-agenda-windows
  789. :type 'boolean)
  790. (defcustom org-agenda-ndays 7
  791. "Number of days to include in overview display.
  792. Should be 1 or 7.
  793. Custom commands can set this variable in the options section."
  794. :group 'org-agenda-daily/weekly
  795. :type 'integer)
  796. (defcustom org-agenda-start-on-weekday 1
  797. "Non-nil means start the overview always on the specified weekday.
  798. 0 denotes Sunday, 1 denotes Monday etc.
  799. When nil, always start on the current day.
  800. Custom commands can set this variable in the options section."
  801. :group 'org-agenda-daily/weekly
  802. :type '(choice (const :tag "Today" nil)
  803. (integer :tag "Weekday No.")))
  804. (defcustom org-agenda-show-all-dates t
  805. "Non-nil means `org-agenda' shows every day in the selected range.
  806. When nil, only the days which actually have entries are shown."
  807. :group 'org-agenda-daily/weekly
  808. :type 'boolean)
  809. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  810. "Format string for displaying dates in the agenda.
  811. Used by the daily/weekly agenda and by the timeline. This should be
  812. a format string understood by `format-time-string', or a function returning
  813. the formatted date as a string. The function must take a single argument,
  814. a calendar-style date list like (month day year)."
  815. :group 'org-agenda-daily/weekly
  816. :type '(choice
  817. (string :tag "Format string")
  818. (function :tag "Function")))
  819. (defun org-agenda-format-date-aligned (date)
  820. "Format a date string for display in the daily/weekly agenda, or timeline.
  821. This function makes sure that dates are aligned for easy reading."
  822. (require 'cal-iso)
  823. (let* ((dayname (calendar-day-name date))
  824. (day (cadr date))
  825. (day-of-week (calendar-day-of-week date))
  826. (month (car date))
  827. (monthname (calendar-month-name month))
  828. (year (nth 2 date))
  829. (iso-week (org-days-to-iso-week
  830. (calendar-absolute-from-gregorian date)))
  831. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  832. (1- year))
  833. ((and (= month 12) (<= iso-week 1))
  834. (1+ year))
  835. (t year)))
  836. (weekstring (if (= day-of-week 1)
  837. (format " W%02d" iso-week)
  838. "")))
  839. (format "%-10s %2d %s %4d%s"
  840. dayname day monthname year weekstring)))
  841. (defcustom org-agenda-time-leading-zero nil
  842. "Non-nil means use leading zero for military times in agenda.
  843. For example, 9:30am would become 09:30 rather than 9:30."
  844. :group 'org-agenda-daily/weekly
  845. :type 'boolean)
  846. (defcustom org-agenda-timegrid-use-ampm nil
  847. "When set, show AM/PM style timestamps on the timegrid."
  848. :group 'org-agenda
  849. :type 'boolean)
  850. (defun org-agenda-time-of-day-to-ampm (time)
  851. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  852. (let* ((hour-number (string-to-number (substring time 0 -3)))
  853. (minute (substring time -2))
  854. (ampm "am"))
  855. (cond
  856. ((equal hour-number 12)
  857. (setq ampm "pm"))
  858. ((> hour-number 12)
  859. (setq ampm "pm")
  860. (setq hour-number (- hour-number 12))))
  861. (concat
  862. (if org-agenda-time-leading-zero
  863. (format "%02d" hour-number)
  864. (format "%02s" (number-to-string hour-number)))
  865. ":" minute ampm)))
  866. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  867. "Conditionally convert TIME to AM/PM format
  868. based on `org-agenda-timegrid-use-ampm'"
  869. (if org-agenda-timegrid-use-ampm
  870. (org-agenda-time-of-day-to-ampm time)
  871. time))
  872. (defcustom org-agenda-weekend-days '(6 0)
  873. "Which days are weekend?
  874. These days get the special face `org-agenda-date-weekend' in the agenda
  875. and timeline buffers."
  876. :group 'org-agenda-daily/weekly
  877. :type '(set :greedy t
  878. (const :tag "Monday" 1)
  879. (const :tag "Tuesday" 2)
  880. (const :tag "Wednesday" 3)
  881. (const :tag "Thursday" 4)
  882. (const :tag "Friday" 5)
  883. (const :tag "Saturday" 6)
  884. (const :tag "Sunday" 0)))
  885. (defcustom org-agenda-include-diary nil
  886. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  887. Custom commands can set this variable in the options section."
  888. :group 'org-agenda-daily/weekly
  889. :type 'boolean)
  890. (defcustom org-agenda-include-deadlines t
  891. "If non-nil, include entries within their deadline warning period.
  892. Custom commands can set this variable in the options section."
  893. :group 'org-agenda-daily/weekly
  894. :type 'boolean)
  895. (defcustom org-agenda-include-all-todo nil
  896. "Set means weekly/daily agenda will always contain all TODO entries.
  897. The TODO entries will be listed at the top of the agenda, before
  898. the entries for specific days.
  899. This option is deprecated, it is better to define a block agenda instead."
  900. :group 'org-agenda-daily/weekly
  901. :type 'boolean)
  902. (defcustom org-agenda-repeating-timestamp-show-all t
  903. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  904. When nil, only one occurrence is shown, either today or the
  905. nearest into the future."
  906. :group 'org-agenda-daily/weekly
  907. :type 'boolean)
  908. (defcustom org-scheduled-past-days 10000
  909. "No. of days to continue listing scheduled items that are not marked DONE.
  910. When an item is scheduled on a date, it shows up in the agenda on this
  911. day and will be listed until it is marked done for the number of days
  912. given here."
  913. :group 'org-agenda-daily/weekly
  914. :type 'integer)
  915. (defcustom org-agenda-log-mode-items '(closed clock)
  916. "List of items that should be shown in agenda log mode.
  917. This list may contain the following symbols:
  918. closed Show entries that have been closed on that day.
  919. clock Show entries that have received clocked time on that day.
  920. state Show all logged state changes.
  921. Note that instead of changing this variable, you can also press `C-u l' in
  922. the agenda to display all available LOG items temporarily."
  923. :group 'org-agenda-daily/weekly
  924. :type '(set :greedy t (const closed) (const clock) (const state)))
  925. (defcustom org-agenda-log-mode-add-notes t
  926. "Non-nil means add first line of notes to log entries in agenda views.
  927. If a log item like a state change or a clock entry is associated with
  928. notes, the first line of these notes will be added to the entry in the
  929. agenda display."
  930. :group 'org-agenda-daily/weekly
  931. :type 'boolean)
  932. (defcustom org-agenda-start-with-log-mode nil
  933. "The initial value of log-mode in a newly created agenda window."
  934. :group 'org-agenda-startup
  935. :group 'org-agenda-daily/weekly
  936. :type 'boolean)
  937. (defcustom org-agenda-start-with-clockreport-mode nil
  938. "The initial value of clockreport-mode in a newly created agenda window."
  939. :group 'org-agenda-startup
  940. :group 'org-agenda-daily/weekly
  941. :type 'boolean)
  942. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  943. "Property list with parameters for the clocktable in clockreport mode.
  944. This is the display mode that shows a clock table in the daily/weekly
  945. agenda, the properties for this dynamic block can be set here.
  946. The usual clocktable parameters are allowed here, but you cannot set
  947. the properties :name, :tstart, :tend, :block, and :scope - these will
  948. be overwritten to make sure the content accurately reflects the
  949. current display in the agenda."
  950. :group 'org-agenda-daily/weekly
  951. :type 'plist)
  952. (defcustom org-agenda-search-view-always-boolean nil
  953. "Non-nil means the search string is interpreted as individual parts.
  954. The search string for search view can either be interpreted as a phrase,
  955. or as a list of snippets that define a boolean search for a number of
  956. strings.
  957. When this is non-nil, the string will be split on whitespace, and each
  958. snippet will be searched individually, and all must match in order to
  959. select an entry. A snippet is then a single string of non-white
  960. characters, or a string in double quotes, or a regexp in {} braces.
  961. If a snippet is preceded by \"-\", the snippet must *not* match.
  962. \"+\" is syntactic sugar for positive selection. Each snippet may
  963. be found as a full word or a partial word, but see the variable
  964. `org-agenda-search-view-force-full-words'.
  965. When this is nil, search will look for the entire search phrase as one,
  966. with each space character matching any amount of whitespace, including
  967. line breaks.
  968. Even when this is nil, you can still switch to Boolean search dynamically
  969. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  970. is a regexp marked with braces like \"{abc}\", this will also switch to
  971. boolean search."
  972. :group 'org-agenda-search-view
  973. :type 'boolean)
  974. (if (fboundp 'defvaralias)
  975. (defvaralias 'org-agenda-search-view-search-words-only
  976. 'org-agenda-search-view-always-boolean))
  977. (defcustom org-agenda-search-view-force-full-words nil
  978. "Non-nil means, search words must be matches as complete words.
  979. When nil, they may also match part of a word."
  980. :group 'org-agenda-search-view
  981. :type 'boolean)
  982. (defgroup org-agenda-time-grid nil
  983. "Options concerning the time grid in the Org-mode Agenda."
  984. :tag "Org Agenda Time Grid"
  985. :group 'org-agenda)
  986. (defcustom org-agenda-search-headline-for-time t
  987. "Non-nil means search headline for a time-of-day.
  988. If the headline contains a time-of-day in one format or another, it will
  989. be used to sort the entry into the time sequence of items for a day.
  990. Some people have time stamps in the headline that refer to the creation
  991. time or so, and then this produces an unwanted side effect. If this is
  992. the case for your, use this variable to turn off searching the headline
  993. for a time."
  994. :group 'org-agenda-time-grid
  995. :type 'boolean)
  996. (defcustom org-agenda-use-time-grid t
  997. "Non-nil means show a time grid in the agenda schedule.
  998. A time grid is a set of lines for specific times (like every two hours between
  999. 8:00 and 20:00). The items scheduled for a day at specific times are
  1000. sorted in between these lines.
  1001. For details about when the grid will be shown, and what it will look like, see
  1002. the variable `org-agenda-time-grid'."
  1003. :group 'org-agenda-time-grid
  1004. :type 'boolean)
  1005. (defcustom org-agenda-time-grid
  1006. '((daily today require-timed)
  1007. "----------------"
  1008. (800 1000 1200 1400 1600 1800 2000))
  1009. "The settings for time grid for agenda display.
  1010. This is a list of three items. The first item is again a list. It contains
  1011. symbols specifying conditions when the grid should be displayed:
  1012. daily if the agenda shows a single day
  1013. weekly if the agenda shows an entire week
  1014. today show grid on current date, independent of daily/weekly display
  1015. require-timed show grid only if at least one item has a time specification
  1016. The second item is a string which will be placed behind the grid time.
  1017. The third item is a list of integers, indicating the times that should have
  1018. a grid line."
  1019. :group 'org-agenda-time-grid
  1020. :type
  1021. '(list
  1022. (set :greedy t :tag "Grid Display Options"
  1023. (const :tag "Show grid in single day agenda display" daily)
  1024. (const :tag "Show grid in weekly agenda display" weekly)
  1025. (const :tag "Always show grid for today" today)
  1026. (const :tag "Show grid only if any timed entries are present"
  1027. require-timed)
  1028. (const :tag "Skip grid times already present in an entry"
  1029. remove-match))
  1030. (string :tag "Grid String")
  1031. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1032. (defgroup org-agenda-sorting nil
  1033. "Options concerning sorting in the Org-mode Agenda."
  1034. :tag "Org Agenda Sorting"
  1035. :group 'org-agenda)
  1036. (defcustom org-agenda-sorting-strategy
  1037. '((agenda habit-down time-up priority-down category-keep)
  1038. (todo priority-down category-keep)
  1039. (tags priority-down category-keep)
  1040. (search category-keep))
  1041. "Sorting structure for the agenda items of a single day.
  1042. This is a list of symbols which will be used in sequence to determine
  1043. if an entry should be listed before another entry. The following
  1044. symbols are recognized:
  1045. time-up Put entries with time-of-day indications first, early first
  1046. time-down Put entries with time-of-day indications first, late first
  1047. category-keep Keep the default order of categories, corresponding to the
  1048. sequence in `org-agenda-files'.
  1049. category-up Sort alphabetically by category, A-Z.
  1050. category-down Sort alphabetically by category, Z-A.
  1051. tag-up Sort alphabetically by last tag, A-Z.
  1052. tag-down Sort alphabetically by last tag, Z-A.
  1053. priority-up Sort numerically by priority, high priority last.
  1054. priority-down Sort numerically by priority, high priority first.
  1055. todo-state-up Sort by todo state, tasks that are done last.
  1056. todo-state-down Sort by todo state, tasks that are done first.
  1057. effort-up Sort numerically by estimated effort, high effort last.
  1058. effort-down Sort numerically by estimated effort, high effort first.
  1059. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1060. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1061. habit-up Put entries that are habits first
  1062. habit-down Put entries that are habits last
  1063. alpha-up Sort headlines alphabetically
  1064. alpha-down Sort headlines alphabetically, reversed
  1065. The different possibilities will be tried in sequence, and testing stops
  1066. if one comparison returns a \"not-equal\". For example, the default
  1067. '(time-up category-keep priority-down)
  1068. means: Pull out all entries having a specified time of day and sort them,
  1069. in order to make a time schedule for the current day the first thing in the
  1070. agenda listing for the day. Of the entries without a time indication, keep
  1071. the grouped in categories, don't sort the categories, but keep them in
  1072. the sequence given in `org-agenda-files'. Within each category sort by
  1073. priority.
  1074. Leaving out `category-keep' would mean that items will be sorted across
  1075. categories by priority.
  1076. Instead of a single list, this can also be a set of list for specific
  1077. contents, with a context symbol in the car of the list, any of
  1078. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1079. Custom commands can bind this variable in the options section."
  1080. :group 'org-agenda-sorting
  1081. :type `(choice
  1082. (repeat :tag "General" ,org-sorting-choice)
  1083. (list :tag "Individually"
  1084. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1085. (repeat ,org-sorting-choice))
  1086. (cons (const :tag "Strategy for TODO lists" todo)
  1087. (repeat ,org-sorting-choice))
  1088. (cons (const :tag "Strategy for Tags matches" tags)
  1089. (repeat ,org-sorting-choice))
  1090. (cons (const :tag "Strategy for search matches" search)
  1091. (repeat ,org-sorting-choice)))))
  1092. (defcustom org-agenda-cmp-user-defined nil
  1093. "A function to define the comparison `user-defined'.
  1094. This function must receive two arguments, agenda entry a and b.
  1095. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1096. the user comparison, return nil.
  1097. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1098. part of an agenda sorting strategy."
  1099. :group 'org-agenda-sorting
  1100. :type 'symbol)
  1101. (defcustom org-sort-agenda-notime-is-late t
  1102. "Non-nil means items without time are considered late.
  1103. This is only relevant for sorting. When t, items which have no explicit
  1104. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1105. do have a time. When nil, the default time is before 0:00. You can use this
  1106. option to decide if the schedule for today should come before or after timeless
  1107. agenda entries."
  1108. :group 'org-agenda-sorting
  1109. :type 'boolean)
  1110. (defcustom org-sort-agenda-noeffort-is-high t
  1111. "Non-nil means items without effort estimate are sorted as high effort.
  1112. This also applies when filtering an agenda view with respect to the
  1113. < or > effort operator. Then, tasks with no effort defined will be treated
  1114. as tasks with high effort.
  1115. When nil, such items are sorted as 0 minutes effort."
  1116. :group 'org-agenda-sorting
  1117. :type 'boolean)
  1118. (defgroup org-agenda-line-format nil
  1119. "Options concerning the entry prefix in the Org-mode agenda display."
  1120. :tag "Org Agenda Line Format"
  1121. :group 'org-agenda)
  1122. (defcustom org-agenda-prefix-format
  1123. '((agenda . " %i %-12:c%?-12t% s")
  1124. (timeline . " % s")
  1125. (todo . " %i %-12:c")
  1126. (tags . " %i %-12:c")
  1127. (search . " %i %-12:c"))
  1128. "Format specifications for the prefix of items in the agenda views.
  1129. An alist with four entries, for the different agenda types. The keys to the
  1130. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1131. are format strings.
  1132. This format works similar to a printf format, with the following meaning:
  1133. %c the category of the item, \"Diary\" for entries from the diary, or
  1134. as given by the CATEGORY keyword or derived from the file name.
  1135. %i the icon category of the item, as give in
  1136. `org-agenda-category-icon-alist'.
  1137. %T the *last* tag of the item. Last because inherited tags come
  1138. first in the list.
  1139. %t the time-of-day specification if one applies to the entry, in the
  1140. format HH:MM
  1141. %s Scheduling/Deadline information, a short string
  1142. All specifiers work basically like the standard `%s' of printf, but may
  1143. contain two additional characters: A question mark just after the `%' and
  1144. a whitespace/punctuation character just before the final letter.
  1145. If the first character after `%' is a question mark, the entire field
  1146. will only be included if the corresponding value applies to the
  1147. current entry. This is useful for fields which should have fixed
  1148. width when present, but zero width when absent. For example,
  1149. \"%?-12t\" will result in a 12 character time field if a time of the
  1150. day is specified, but will completely disappear in entries which do
  1151. not contain a time.
  1152. If there is punctuation or whitespace character just before the final
  1153. format letter, this character will be appended to the field value if
  1154. the value is not empty. For example, the format \"%-12:c\" leads to
  1155. \"Diary: \" if the category is \"Diary\". If the category were be
  1156. empty, no additional colon would be inserted.
  1157. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1158. - Indent the line with two space characters
  1159. - Give the category in a 12 chars wide field, padded with whitespace on
  1160. the right (because of `-'). Append a colon if there is a category
  1161. (because of `:').
  1162. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1163. time, don't put in an empty field, just skip it (because of '?').
  1164. - Finally, put the scheduling information and append a whitespace.
  1165. As another example, if you don't want the time-of-day of entries in
  1166. the prefix, you could use:
  1167. (setq org-agenda-prefix-format \" %-11:c% s\")
  1168. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1169. `org-agenda-remove-tags'.
  1170. Custom commands can set this variable in the options section."
  1171. :type '(choice
  1172. (string :tag "General format")
  1173. (list :greedy t :tag "View dependent"
  1174. (cons (const agenda) (string :tag "Format"))
  1175. (cons (const timeline) (string :tag "Format"))
  1176. (cons (const todo) (string :tag "Format"))
  1177. (cons (const tags) (string :tag "Format"))
  1178. (cons (const search) (string :tag "Format"))))
  1179. :group 'org-agenda-line-format)
  1180. (defvar org-prefix-format-compiled nil
  1181. "The compiled version of the most recently used prefix format.
  1182. See the variable `org-agenda-prefix-format'.")
  1183. (defcustom org-agenda-todo-keyword-format "%-1s"
  1184. "Format for the TODO keyword in agenda lines.
  1185. Set this to something like \"%-12s\" if you want all TODO keywords
  1186. to occupy a fixed space in the agenda display."
  1187. :group 'org-agenda-line-format
  1188. :type 'string)
  1189. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1190. "Text preceding timerange entries in the agenda view.
  1191. This is a list with two strings. The first applies when the range
  1192. is entirely on one day. The second applies if the range spans several days.
  1193. The strings may have two \"%d\" format specifiers which will be filled
  1194. with the sequence number of the days, and the total number of days in the
  1195. range, respectively."
  1196. :group 'org-agenda-line-format
  1197. :type '(list
  1198. (string :tag "Deadline today ")
  1199. (choice :tag "Deadline relative"
  1200. (string :tag "Format string")
  1201. (function))))
  1202. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1203. "Text preceding scheduled items in the agenda view.
  1204. This is a list with two strings. The first applies when the item is
  1205. scheduled on the current day. The second applies when it has been scheduled
  1206. previously, it may contain a %d indicating that this is the nth time that
  1207. this item is scheduled, due to automatic rescheduling of unfinished items
  1208. for the following day. So this number is one larger than the number of days
  1209. that passed since this item was scheduled first."
  1210. :group 'org-agenda-line-format
  1211. :type '(list
  1212. (string :tag "Scheduled today ")
  1213. (string :tag "Scheduled previously")))
  1214. (defcustom org-agenda-inactive-leader "["
  1215. "Text preceding item pulled into the agenda by inactive time stamps.
  1216. These entries are added to the agenda when pressing \"[\"."
  1217. :group 'org-agenda-line-format
  1218. :type '(list
  1219. (string :tag "Scheduled today ")
  1220. (string :tag "Scheduled previously")))
  1221. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1222. "Text preceding deadline items in the agenda view.
  1223. This is a list with two strings. The first applies when the item has its
  1224. deadline on the current day. The second applies when it is in the past or
  1225. in the future, it may contain %d to capture how many days away the deadline
  1226. is (was)."
  1227. :group 'org-agenda-line-format
  1228. :type '(list
  1229. (string :tag "Deadline today ")
  1230. (choice :tag "Deadline relative"
  1231. (string :tag "Format string")
  1232. (function))))
  1233. (defcustom org-agenda-remove-times-when-in-prefix t
  1234. "Non-nil means remove duplicate time specifications in agenda items.
  1235. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1236. time-of-day specification in a headline or diary entry is extracted and
  1237. placed into the prefix. If this option is non-nil, the original specification
  1238. \(a timestamp or -range, or just a plain time(range) specification like
  1239. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1240. cluttered.
  1241. The option can be t or nil. It may also be the symbol `beg', indicating
  1242. that the time should only be removed when it is located at the beginning of
  1243. the headline/diary entry."
  1244. :group 'org-agenda-line-format
  1245. :type '(choice
  1246. (const :tag "Always" t)
  1247. (const :tag "Never" nil)
  1248. (const :tag "When at beginning of entry" beg)))
  1249. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1250. "Non-nil means remove time ranges specifications in agenda
  1251. items that span on several days."
  1252. :group 'org-agenda-line-format
  1253. :type 'boolean)
  1254. (defcustom org-agenda-default-appointment-duration nil
  1255. "Default duration for appointments that only have a starting time.
  1256. When nil, no duration is specified in such cases.
  1257. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1258. :group 'org-agenda-line-format
  1259. :type '(choice
  1260. (integer :tag "Minutes")
  1261. (const :tag "No default duration")))
  1262. (defcustom org-agenda-show-inherited-tags t
  1263. "Non-nil means show inherited tags in each agenda line."
  1264. :group 'org-agenda-line-format
  1265. :type 'boolean)
  1266. (defcustom org-agenda-hide-tags-regexp nil
  1267. "Regular expression used to filter away specific tags in agenda views.
  1268. This means that these tags will be present, but not be shown in the agenda
  1269. line. Secondary filtering will still work on the hidden tags.
  1270. Nil means don't hide any tags."
  1271. :group 'org-agenda-line-format
  1272. :type '(choice
  1273. (const :tag "Hide none" nil)
  1274. (string :tag "Regexp ")))
  1275. (defcustom org-agenda-remove-tags nil
  1276. "Non-nil means remove the tags from the headline copy in the agenda.
  1277. When this is the symbol `prefix', only remove tags when
  1278. `org-agenda-prefix-format' contains a `%T' specifier."
  1279. :group 'org-agenda-line-format
  1280. :type '(choice
  1281. (const :tag "Always" t)
  1282. (const :tag "Never" nil)
  1283. (const :tag "When prefix format contains %T" prefix)))
  1284. (if (fboundp 'defvaralias)
  1285. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1286. 'org-agenda-remove-tags))
  1287. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1288. "Shift tags in agenda items to this column.
  1289. If this number is positive, it specifies the column. If it is negative,
  1290. it means that the tags should be flushright to that column. For example,
  1291. -80 works well for a normal 80 character screen."
  1292. :group 'org-agenda-line-format
  1293. :type 'integer)
  1294. (if (fboundp 'defvaralias)
  1295. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1296. (defcustom org-agenda-fontify-priorities 'cookies
  1297. "Non-nil means highlight low and high priorities in agenda.
  1298. When t, the highest priority entries are bold, lowest priority italic.
  1299. However, settings in `org-priority-faces' will overrule these faces.
  1300. When this variable is the symbol `cookies', only fontify the
  1301. cookies, not the entire task.
  1302. This may also be an association list of priority faces, whose
  1303. keys are the character values of `org-highest-priority',
  1304. `org-default-priority', and `org-lowest-priority' (the default values
  1305. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1306. color as a string, or a list like `(:background \"Red\")'.
  1307. If it is a color, the variable `org-faces-easy-properties'
  1308. determines if it is a foreground or a background color."
  1309. :group 'org-agenda-line-format
  1310. :type '(choice
  1311. (const :tag "Never" nil)
  1312. (const :tag "Defaults" t)
  1313. (const :tag "Cookies only" cookies)
  1314. (repeat :tag "Specify"
  1315. (list (character :tag "Priority" :value ?A)
  1316. (choice :tag "Face "
  1317. (string :tag "Color")
  1318. (sexp :tag "Face"))))))
  1319. (defcustom org-agenda-day-face-function nil
  1320. "Function called to determine what face should be used to display a day.
  1321. The only argument passed to that function is the day. It should
  1322. returns a face, or nil if does not want to specify a face and let
  1323. the normal rules apply."
  1324. :group 'org-agenda-line-format
  1325. :type 'function)
  1326. (defcustom org-agenda-category-icon-alist nil
  1327. "Alist of category icon to be displayed in agenda views.
  1328. Each entry should have the following format:
  1329. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1330. Where CATEGORY-REGEXP is a regexp matching the categories where
  1331. the icon should be displayed.
  1332. FILE-OR-DATA either a file path or a string containing image data.
  1333. The other fields can be ommited safely if not needed:
  1334. TYPE indicates the image type.
  1335. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1336. image data.
  1337. PROPS are additional image attributes to assign to the image,
  1338. like, e.g. `:ascent center'.
  1339. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1340. If you want to set the display properties yourself, just put a
  1341. list as second element:
  1342. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1343. For example, to display a 16px horizontal space for Emacs
  1344. category, you can use:
  1345. (\"Emacs\" '(space . (:width (16))))"
  1346. :group 'org-agenda-line-format
  1347. :type '(alist :key-type (string :tag "Regexp matching category")
  1348. :value-type (choice (list :tag "Icon"
  1349. (string :tag "File or data")
  1350. (symbol :tag "Type")
  1351. (boolean :tag "Data?")
  1352. (repeat :tag "Extra image properties" :inline t symbol))
  1353. (list :tag "Display properties" sexp))))
  1354. (defgroup org-agenda-column-view nil
  1355. "Options concerning column view in the agenda."
  1356. :tag "Org Agenda Column View"
  1357. :group 'org-agenda)
  1358. (defcustom org-agenda-columns-show-summaries t
  1359. "Non-nil means show summaries for columns displayed in the agenda view."
  1360. :group 'org-agenda-column-view
  1361. :type 'boolean)
  1362. (defcustom org-agenda-columns-remove-prefix-from-item t
  1363. "Non-nil means remove the prefix from a headline for agenda column view.
  1364. The special ITEM field in the columns format contains the current line, with
  1365. all information shown in other columns (like the TODO state or a tag).
  1366. When this variable is non-nil, also the agenda prefix will be removed from
  1367. the content of the ITEM field, to make sure as much as possible of the
  1368. headline can be shown in the limited width of the field."
  1369. :group 'org-agenda
  1370. :type 'boolean)
  1371. (defcustom org-agenda-columns-compute-summary-properties t
  1372. "Non-nil means recompute all summary properties before column view.
  1373. When column view in the agenda is listing properties that have a summary
  1374. operator, it can go to all relevant buffers and recompute the summaries
  1375. there. This can mean overhead for the agenda column view, but is necessary
  1376. to have thing up to date.
  1377. As a special case, a CLOCKSUM property also makes sure that the clock
  1378. computations are current."
  1379. :group 'org-agenda-column-view
  1380. :type 'boolean)
  1381. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1382. "Non-nil means the duration of an appointment will add to day effort.
  1383. The property to which appointment durations will be added is the one given
  1384. in the option `org-effort-property'. If an appointment does not have
  1385. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1386. is not set, an appointment without end time will not contribute to the time
  1387. estimate."
  1388. :group 'org-agenda-column-view
  1389. :type 'boolean)
  1390. (defcustom org-agenda-auto-exclude-function nil
  1391. "A function called with a tag to decide if it is filtered on '/ RET'.
  1392. The sole argument to the function, which is called once for each
  1393. possible tag, is a string giving the name of the tag. The
  1394. function should return either nil if the tag should be included
  1395. as normal, or \"-<TAG>\" to exclude the tag.
  1396. Note that for the purpose of tag filtering, only the lower-case version of
  1397. all tags will be considered, so that this function will only ever see
  1398. the lower-case version of all tags."
  1399. :group 'org-agenda
  1400. :type 'function)
  1401. (eval-when-compile
  1402. (require 'cl))
  1403. (require 'org)
  1404. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1405. "Execute BODY with point at location given by `org-hd-marker' property.
  1406. If STRING is non-nil, the text property will be fetched from position 0
  1407. in that string. If STRING is nil, it will be fetched from the beginning
  1408. of the current line."
  1409. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1410. 'org-hd-marker string)))
  1411. (with-current-buffer (marker-buffer marker)
  1412. (save-excursion
  1413. (goto-char marker)
  1414. ,@body))))
  1415. (defun org-add-agenda-custom-command (entry)
  1416. "Replace or add a command in `org-agenda-custom-commands'.
  1417. This is mostly for hacking and trying a new command - once the command
  1418. works you probably want to add it to `org-agenda-custom-commands' for good."
  1419. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1420. (if ass
  1421. (setcdr ass (cdr entry))
  1422. (push entry org-agenda-custom-commands))))
  1423. ;;; Define the Org-agenda-mode
  1424. (defvar org-agenda-mode-map (make-sparse-keymap)
  1425. "Keymap for `org-agenda-mode'.")
  1426. (if (fboundp 'defvaralias)
  1427. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1428. (defvar org-agenda-menu) ; defined later in this file.
  1429. (defvar org-agenda-restrict) ; defined later in this file.
  1430. (defvar org-agenda-follow-mode nil)
  1431. (defvar org-agenda-entry-text-mode nil)
  1432. (defvar org-agenda-clockreport-mode nil)
  1433. (defvar org-agenda-show-log nil)
  1434. (defvar org-agenda-redo-command nil)
  1435. (defvar org-agenda-query-string nil)
  1436. (defvar org-agenda-mode-hook nil
  1437. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1438. (defvar org-agenda-type nil)
  1439. (defvar org-agenda-force-single-file nil)
  1440. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1441. (defun org-agenda-mode ()
  1442. "Mode for time-sorted view on action items in Org-mode files.
  1443. The following commands are available:
  1444. \\{org-agenda-mode-map}"
  1445. (interactive)
  1446. (kill-all-local-variables)
  1447. (setq org-agenda-undo-list nil
  1448. org-agenda-pending-undo-list nil
  1449. org-agenda-bulk-marked-entries nil)
  1450. (setq major-mode 'org-agenda-mode)
  1451. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1452. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1453. (setq mode-name "Org-Agenda")
  1454. (use-local-map org-agenda-mode-map)
  1455. (easy-menu-add org-agenda-menu)
  1456. (if org-startup-truncated (setq truncate-lines t))
  1457. (org-set-local 'line-move-visual nil)
  1458. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1459. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1460. ;; Make sure properties are removed when copying text
  1461. (when (boundp 'buffer-substring-filters)
  1462. (org-set-local 'buffer-substring-filters
  1463. (cons (lambda (x)
  1464. (set-text-properties 0 (length x) nil x) x)
  1465. buffer-substring-filters)))
  1466. (unless org-agenda-keep-modes
  1467. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1468. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1469. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1470. org-agenda-show-log org-agenda-start-with-log-mode))
  1471. (easy-menu-change
  1472. '("Agenda") "Agenda Files"
  1473. (append
  1474. (list
  1475. (vector
  1476. (if (get 'org-agenda-files 'org-restrict)
  1477. "Restricted to single file"
  1478. "Edit File List")
  1479. '(org-edit-agenda-file-list)
  1480. (not (get 'org-agenda-files 'org-restrict)))
  1481. "--")
  1482. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1483. (org-agenda-set-mode-name)
  1484. (apply
  1485. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1486. (list 'org-agenda-mode-hook)))
  1487. (substitute-key-definition 'undo 'org-agenda-undo
  1488. org-agenda-mode-map global-map)
  1489. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1490. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1491. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1492. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1493. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1494. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1495. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1496. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1497. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1498. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1499. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1500. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1501. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1502. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1503. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1504. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1505. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1506. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1507. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1508. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1509. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1510. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1511. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1512. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1513. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1514. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1515. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1516. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1517. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1518. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1519. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1520. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1521. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1522. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1523. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1524. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1525. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1526. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1527. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1528. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1529. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1530. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1531. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1532. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1533. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1534. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1535. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1536. (while l (org-defkey org-agenda-mode-map
  1537. (int-to-string (pop l)) 'digit-argument)))
  1538. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1539. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1540. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1541. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1542. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1543. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1544. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1545. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1546. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1547. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1548. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1549. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1550. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1551. 'org-clock-modify-effort-estimate)
  1552. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1553. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1554. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1555. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1556. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1557. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1558. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1559. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1560. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1561. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1562. (substitute-key-definition 'next-line 'org-agenda-next-line
  1563. org-agenda-mode-map global-map)
  1564. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1565. org-agenda-mode-map global-map)
  1566. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1567. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1568. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1569. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1570. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1571. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1572. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1573. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1574. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1575. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1576. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1577. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1578. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1579. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1580. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1581. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1582. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1583. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1584. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1585. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1586. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1587. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1588. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1589. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1590. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1591. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1592. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1593. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1594. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1595. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1596. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1597. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1598. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1599. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1600. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1601. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1602. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1603. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1604. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1605. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1606. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1607. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1608. (when org-agenda-mouse-1-follows-link
  1609. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1610. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1611. '("Agenda"
  1612. ("Agenda Files")
  1613. "--"
  1614. ("Agenda Dates"
  1615. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1616. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1617. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1618. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1619. "--"
  1620. ("View"
  1621. ["Day View" org-agenda-day-view
  1622. :active (org-agenda-check-type nil 'agenda)
  1623. :style radio :selected (equal org-agenda-ndays 1)
  1624. :keys "v d (or just d)"]
  1625. ["Week View" org-agenda-week-view
  1626. :active (org-agenda-check-type nil 'agenda)
  1627. :style radio :selected (equal org-agenda-ndays 7)
  1628. :keys "v w (or just w)"]
  1629. ["Month View" org-agenda-month-view
  1630. :active (org-agenda-check-type nil 'agenda)
  1631. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1632. :keys "v m"]
  1633. ["Year View" org-agenda-year-view
  1634. :active (org-agenda-check-type nil 'agenda)
  1635. :style radio :selected (member org-agenda-ndays '(365 366))
  1636. :keys "v y"]
  1637. "--"
  1638. ["Include Diary" org-agenda-toggle-diary
  1639. :style toggle :selected org-agenda-include-diary
  1640. :active (org-agenda-check-type nil 'agenda)]
  1641. ["Include Deadlines" org-agenda-toggle-deadlines
  1642. :style toggle :selected org-agenda-include-deadlines
  1643. :active (org-agenda-check-type nil 'agenda)]
  1644. ["Use Time Grid" org-agenda-toggle-time-grid
  1645. :style toggle :selected org-agenda-use-time-grid
  1646. :active (org-agenda-check-type nil 'agenda)]
  1647. "--"
  1648. ["Show clock report" org-agenda-clockreport-mode
  1649. :style toggle :selected org-agenda-clockreport-mode
  1650. :active (org-agenda-check-type nil 'agenda)]
  1651. ["Show some entry text" org-agenda-entry-text-mode
  1652. :style toggle :selected org-agenda-entry-text-mode
  1653. :active t]
  1654. "--"
  1655. ["Show Logbook entries" org-agenda-log-mode
  1656. :style toggle :selected org-agenda-show-log
  1657. :active (org-agenda-check-type nil 'agenda 'timeline)
  1658. :keys "v l (or just l)"]
  1659. ["Include archived trees" org-agenda-archives-mode
  1660. :style toggle :selected org-agenda-archives-mode :active t
  1661. :keys "v a"]
  1662. ["Include archive files" (org-agenda-archives-mode t)
  1663. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1664. :keys "v A"]
  1665. "--"
  1666. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1667. ["Write view to file" org-write-agenda t]
  1668. ["Rebuild buffer" org-agenda-redo t]
  1669. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1670. "--"
  1671. ["Show original entry" org-agenda-show t]
  1672. ["Go To (other window)" org-agenda-goto t]
  1673. ["Go To (this window)" org-agenda-switch-to t]
  1674. ["Follow Mode" org-agenda-follow-mode
  1675. :style toggle :selected org-agenda-follow-mode :active t]
  1676. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1677. "--"
  1678. ("TODO"
  1679. ["Cycle TODO" org-agenda-todo t]
  1680. ["Next TODO set" org-agenda-todo-nextset t]
  1681. ["Previous TODO set" org-agenda-todo-previousset t]
  1682. ["Add note" org-agenda-add-note t])
  1683. ("Archive/Refile/Delete"
  1684. ["Archive default" org-agenda-archive-default t]
  1685. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1686. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1687. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1688. ["Archive subtree" org-agenda-archive t]
  1689. "--"
  1690. ["Refile" org-agenda-refile t]
  1691. "--"
  1692. ["Delete subtree" org-agenda-kill t])
  1693. ("Bulk action"
  1694. ["Mark entry" org-agenda-bulk-mark t]
  1695. ["Unmark entry" org-agenda-bulk-unmark t]
  1696. ["Act on all marked" org-agenda-bulk-action t]
  1697. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1698. "--"
  1699. ("Tags and Properties"
  1700. ["Show all Tags" org-agenda-show-tags t]
  1701. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1702. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1703. "--"
  1704. ["Column View" org-columns t])
  1705. ("Deadline/Schedule"
  1706. ["Schedule" org-agenda-schedule t]
  1707. ["Set Deadline" org-agenda-deadline t]
  1708. "--"
  1709. ["Mark item" org-agenda-action :active t :keys "k m"]
  1710. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1711. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1712. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1713. "--"
  1714. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1715. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1716. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1717. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1718. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1719. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1720. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1721. ("Clock and Effort"
  1722. ["Clock in" org-agenda-clock-in t]
  1723. ["Clock out" org-agenda-clock-out t]
  1724. ["Clock cancel" org-agenda-clock-cancel t]
  1725. ["Goto running clock" org-clock-goto t]
  1726. "--"
  1727. ["Set Effort" org-agenda-set-effort t]
  1728. ["Change clocked effort" org-clock-modify-effort-estimate
  1729. (org-clock-is-active)])
  1730. ("Priority"
  1731. ["Set Priority" org-agenda-priority t]
  1732. ["Increase Priority" org-agenda-priority-up t]
  1733. ["Decrease Priority" org-agenda-priority-down t]
  1734. ["Show Priority" org-agenda-show-priority t])
  1735. ("Calendar/Diary"
  1736. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1737. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1738. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1739. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1740. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1741. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1742. "--"
  1743. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1744. "--"
  1745. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1746. "--"
  1747. ("MobileOrg"
  1748. ["Push Files and Views" org-mobile-push t]
  1749. ["Get Captured and Flagged" org-mobile-pull t]
  1750. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1751. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1752. "--"
  1753. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1754. "--"
  1755. ["Quit" org-agenda-quit t]
  1756. ["Exit and Release Buffers" org-agenda-exit t]
  1757. ))
  1758. ;;; Agenda undo
  1759. (defvar org-agenda-allow-remote-undo t
  1760. "Non-nil means allow remote undo from the agenda buffer.")
  1761. (defvar org-agenda-undo-list nil
  1762. "List of undoable operations in the agenda since last refresh.")
  1763. (defvar org-agenda-undo-has-started-in nil
  1764. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1765. (defvar org-agenda-pending-undo-list nil
  1766. "In a series of undo commands, this is the list of remaining undo items.")
  1767. (defun org-agenda-undo ()
  1768. "Undo a remote editing step in the agenda.
  1769. This undoes changes both in the agenda buffer and in the remote buffer
  1770. that have been changed along."
  1771. (interactive)
  1772. (or org-agenda-allow-remote-undo
  1773. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1774. (if (not (eq this-command last-command))
  1775. (setq org-agenda-undo-has-started-in nil
  1776. org-agenda-pending-undo-list org-agenda-undo-list))
  1777. (if (not org-agenda-pending-undo-list)
  1778. (error "No further undo information"))
  1779. (let* ((entry (pop org-agenda-pending-undo-list))
  1780. buf line cmd rembuf)
  1781. (setq cmd (pop entry) line (pop entry))
  1782. (setq rembuf (nth 2 entry))
  1783. (org-with-remote-undo rembuf
  1784. (while (bufferp (setq buf (pop entry)))
  1785. (if (pop entry)
  1786. (with-current-buffer buf
  1787. (let ((last-undo-buffer buf)
  1788. (inhibit-read-only t))
  1789. (unless (memq buf org-agenda-undo-has-started-in)
  1790. (push buf org-agenda-undo-has-started-in)
  1791. (make-local-variable 'pending-undo-list)
  1792. (undo-start))
  1793. (while (and pending-undo-list
  1794. (listp pending-undo-list)
  1795. (not (car pending-undo-list)))
  1796. (pop pending-undo-list))
  1797. (undo-more 1))))))
  1798. (org-goto-line line)
  1799. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1800. (defun org-verify-change-for-undo (l1 l2)
  1801. "Verify that a real change occurred between the undo lists L1 and L2."
  1802. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1803. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1804. (not (eq l1 l2)))
  1805. ;;; Agenda dispatch
  1806. (defvar org-agenda-restrict nil)
  1807. (defvar org-agenda-restrict-begin (make-marker))
  1808. (defvar org-agenda-restrict-end (make-marker))
  1809. (defvar org-agenda-last-dispatch-buffer nil)
  1810. (defvar org-agenda-overriding-restriction nil)
  1811. ;;;###autoload
  1812. (defun org-agenda (&optional arg keys restriction)
  1813. "Dispatch agenda commands to collect entries to the agenda buffer.
  1814. Prompts for a command to execute. Any prefix arg will be passed
  1815. on to the selected command. The default selections are:
  1816. a Call `org-agenda-list' to display the agenda for current day or week.
  1817. t Call `org-todo-list' to display the global todo list.
  1818. T Call `org-todo-list' to display the global todo list, select only
  1819. entries with a specific TODO keyword (the user gets a prompt).
  1820. m Call `org-tags-view' to display headlines with tags matching
  1821. a condition (the user is prompted for the condition).
  1822. M Like `m', but select only TODO entries, no ordinary headlines.
  1823. L Create a timeline for the current buffer.
  1824. e Export views to associated files.
  1825. s Search entries for keywords.
  1826. / Multi occur across all agenda files and also files listed
  1827. in `org-agenda-text-search-extra-files'.
  1828. < Restrict agenda commands to buffer, subtree, or region.
  1829. Press several times to get the desired effect.
  1830. > Remove a previous restriction.
  1831. # List \"stuck\" projects.
  1832. ! Configure what \"stuck\" means.
  1833. C Configure custom agenda commands.
  1834. More commands can be added by configuring the variable
  1835. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1836. searches can be pre-defined in this way.
  1837. If the current buffer is in Org-mode and visiting a file, you can also
  1838. first press `<' once to indicate that the agenda should be temporarily
  1839. \(until the next use of \\[org-agenda]) restricted to the current file.
  1840. Pressing `<' twice means to restrict to the current subtree or region
  1841. \(if active)."
  1842. (interactive "P")
  1843. (catch 'exit
  1844. (let* ((prefix-descriptions nil)
  1845. (org-agenda-window-setup (if (equal (buffer-name)
  1846. org-agenda-buffer-name)
  1847. 'current-window
  1848. org-agenda-window-setup))
  1849. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1850. (org-agenda-custom-commands
  1851. ;; normalize different versions
  1852. (delq nil
  1853. (mapcar
  1854. (lambda (x)
  1855. (cond ((stringp (cdr x))
  1856. (push x prefix-descriptions)
  1857. nil)
  1858. ((stringp (nth 1 x)) x)
  1859. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1860. (t (cons (car x) (cons "" (cdr x))))))
  1861. org-agenda-custom-commands)))
  1862. (buf (current-buffer))
  1863. (bfn (buffer-file-name (buffer-base-buffer)))
  1864. entry key type match lprops ans)
  1865. ;; Turn off restriction unless there is an overriding one,
  1866. (unless org-agenda-overriding-restriction
  1867. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1868. ;; There is a request to keep the file list in place
  1869. (put 'org-agenda-files 'org-restrict nil))
  1870. (setq org-agenda-restrict nil)
  1871. (move-marker org-agenda-restrict-begin nil)
  1872. (move-marker org-agenda-restrict-end nil))
  1873. ;; Delete old local properties
  1874. (put 'org-agenda-redo-command 'org-lprops nil)
  1875. ;; Remember where this call originated
  1876. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1877. (unless keys
  1878. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1879. keys (car ans)
  1880. restriction (cdr ans)))
  1881. ;; Establish the restriction, if any
  1882. (when (and (not org-agenda-overriding-restriction) restriction)
  1883. (put 'org-agenda-files 'org-restrict (list bfn))
  1884. (cond
  1885. ((eq restriction 'region)
  1886. (setq org-agenda-restrict t)
  1887. (move-marker org-agenda-restrict-begin (region-beginning))
  1888. (move-marker org-agenda-restrict-end (region-end)))
  1889. ((eq restriction 'subtree)
  1890. (save-excursion
  1891. (setq org-agenda-restrict t)
  1892. (org-back-to-heading t)
  1893. (move-marker org-agenda-restrict-begin (point))
  1894. (move-marker org-agenda-restrict-end
  1895. (progn (org-end-of-subtree t)))))))
  1896. ;; For example the todo list should not need it (but does...)
  1897. (cond
  1898. ((setq entry (assoc keys org-agenda-custom-commands))
  1899. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1900. (progn
  1901. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1902. lprops (nth 4 entry))
  1903. (put 'org-agenda-redo-command 'org-lprops lprops)
  1904. (cond
  1905. ((eq type 'agenda)
  1906. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1907. ((eq type 'alltodo)
  1908. (org-let lprops '(org-todo-list current-prefix-arg)))
  1909. ((eq type 'search)
  1910. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1911. ((eq type 'stuck)
  1912. (org-let lprops '(org-agenda-list-stuck-projects
  1913. current-prefix-arg)))
  1914. ((eq type 'tags)
  1915. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1916. ((eq type 'tags-todo)
  1917. (org-let lprops '(org-tags-view '(4) match)))
  1918. ((eq type 'todo)
  1919. (org-let lprops '(org-todo-list match)))
  1920. ((eq type 'tags-tree)
  1921. (org-check-for-org-mode)
  1922. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1923. ((eq type 'todo-tree)
  1924. (org-check-for-org-mode)
  1925. (org-let lprops
  1926. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1927. (regexp-quote match) "\\>"))))
  1928. ((eq type 'occur-tree)
  1929. (org-check-for-org-mode)
  1930. (org-let lprops '(org-occur match)))
  1931. ((functionp type)
  1932. (org-let lprops '(funcall type match)))
  1933. ((fboundp type)
  1934. (org-let lprops '(funcall type match)))
  1935. (t (error "Invalid custom agenda command type %s" type))))
  1936. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1937. ((equal keys "C")
  1938. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1939. (customize-variable 'org-agenda-custom-commands))
  1940. ((equal keys "a") (call-interactively 'org-agenda-list))
  1941. ((equal keys "s") (call-interactively 'org-search-view))
  1942. ((equal keys "t") (call-interactively 'org-todo-list))
  1943. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1944. ((equal keys "m") (call-interactively 'org-tags-view))
  1945. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1946. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1947. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1948. (org-add-hook
  1949. 'post-command-hook
  1950. (lambda ()
  1951. (unless (current-message)
  1952. (let* ((m (org-agenda-get-any-marker))
  1953. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1954. (when note
  1955. (message (concat
  1956. "FLAGGING-NOTE ([?] for more info): "
  1957. (org-add-props
  1958. (replace-regexp-in-string
  1959. "\\\\n" "//"
  1960. (copy-sequence note))
  1961. nil 'face 'org-warning)))))))
  1962. t t))
  1963. ((equal keys "L")
  1964. (unless (org-mode-p)
  1965. (error "This is not an Org-mode file"))
  1966. (unless restriction
  1967. (put 'org-agenda-files 'org-restrict (list bfn))
  1968. (org-call-with-arg 'org-timeline arg)))
  1969. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1970. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1971. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1972. (t (error "Invalid agenda key"))))))
  1973. (defun org-agenda-normalize-custom-commands (cmds)
  1974. (delq nil
  1975. (mapcar
  1976. (lambda (x)
  1977. (cond ((stringp (cdr x)) nil)
  1978. ((stringp (nth 1 x)) x)
  1979. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1980. (t (cons (car x) (cons "" (cdr x))))))
  1981. cmds)))
  1982. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1983. "The user interface for selecting an agenda command."
  1984. (catch 'exit
  1985. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1986. (restrict-ok (and bfn (org-mode-p)))
  1987. (region-p (org-region-active-p))
  1988. (custom org-agenda-custom-commands)
  1989. (selstring "")
  1990. restriction second-time
  1991. c entry key type match prefixes rmheader header-end custom1 desc
  1992. line lines left right n n1)
  1993. (save-window-excursion
  1994. (delete-other-windows)
  1995. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1996. (erase-buffer)
  1997. (insert (eval-when-compile
  1998. (let ((header
  1999. "
  2000. Press key for an agenda command: < Buffer, subtree/region restriction
  2001. -------------------------------- > Remove restriction
  2002. a Agenda for current week or day e Export agenda views
  2003. t List of all TODO entries T Entries with special TODO kwd
  2004. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2005. L Timeline for current buffer # List stuck projects (!=configure)
  2006. s Search for keywords C Configure custom agenda commands
  2007. / Multi-occur ? Find :FLAGGED: entries
  2008. ")
  2009. (start 0))
  2010. (while (string-match
  2011. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2012. header start)
  2013. (setq start (match-end 0))
  2014. (add-text-properties (match-beginning 2) (match-end 2)
  2015. '(face bold) header))
  2016. header)))
  2017. (setq header-end (move-marker (make-marker) (point)))
  2018. (while t
  2019. (setq custom1 custom)
  2020. (when (eq rmheader t)
  2021. (org-goto-line 1)
  2022. (re-search-forward ":" nil t)
  2023. (delete-region (match-end 0) (point-at-eol))
  2024. (forward-char 1)
  2025. (looking-at "-+")
  2026. (delete-region (match-end 0) (point-at-eol))
  2027. (move-marker header-end (match-end 0)))
  2028. (goto-char header-end)
  2029. (delete-region (point) (point-max))
  2030. ;; Produce all the lines that describe custom commands and prefixes
  2031. (setq lines nil)
  2032. (while (setq entry (pop custom1))
  2033. (setq key (car entry) desc (nth 1 entry)
  2034. type (nth 2 entry)
  2035. match (nth 3 entry))
  2036. (if (> (length key) 1)
  2037. (add-to-list 'prefixes (string-to-char key))
  2038. (setq line
  2039. (format
  2040. "%-4s%-14s"
  2041. (org-add-props (copy-sequence key)
  2042. '(face bold))
  2043. (cond
  2044. ((string-match "\\S-" desc) desc)
  2045. ((eq type 'agenda) "Agenda for current week or day")
  2046. ((eq type 'alltodo) "List of all TODO entries")
  2047. ((eq type 'search) "Word search")
  2048. ((eq type 'stuck) "List of stuck projects")
  2049. ((eq type 'todo) "TODO keyword")
  2050. ((eq type 'tags) "Tags query")
  2051. ((eq type 'tags-todo) "Tags (TODO)")
  2052. ((eq type 'tags-tree) "Tags tree")
  2053. ((eq type 'todo-tree) "TODO kwd tree")
  2054. ((eq type 'occur-tree) "Occur tree")
  2055. ((functionp type) (if (symbolp type)
  2056. (symbol-name type)
  2057. "Lambda expression"))
  2058. (t "???"))))
  2059. (if org-agenda-menu-show-matcher
  2060. (setq line
  2061. (concat line ": "
  2062. (cond
  2063. ((stringp match)
  2064. (setq match (copy-sequence match))
  2065. (org-add-props match nil 'face 'org-warning))
  2066. (match
  2067. (format "set of %d commands" (length match)))
  2068. (t ""))))
  2069. (if (org-string-nw-p match)
  2070. (add-text-properties
  2071. 0 (length line) (list 'help-echo
  2072. (concat "Matcher: "match)) line)))
  2073. (push line lines)))
  2074. (setq lines (nreverse lines))
  2075. (when prefixes
  2076. (mapc (lambda (x)
  2077. (push
  2078. (format "%s %s"
  2079. (org-add-props (char-to-string x)
  2080. nil 'face 'bold)
  2081. (or (cdr (assoc (concat selstring
  2082. (char-to-string x))
  2083. prefix-descriptions))
  2084. "Prefix key"))
  2085. lines))
  2086. prefixes))
  2087. ;; Check if we should display in two columns
  2088. (if org-agenda-menu-two-column
  2089. (progn
  2090. (setq n (length lines)
  2091. n1 (+ (/ n 2) (mod n 2))
  2092. right (nthcdr n1 lines)
  2093. left (copy-sequence lines))
  2094. (setcdr (nthcdr (1- n1) left) nil))
  2095. (setq left lines right nil))
  2096. (while left
  2097. (insert "\n" (pop left))
  2098. (when right
  2099. (if (< (current-column) 40)
  2100. (move-to-column 40 t)
  2101. (insert " "))
  2102. (insert (pop right))))
  2103. ;; Make the window the right size
  2104. (goto-char (point-min))
  2105. (if second-time
  2106. (if (not (pos-visible-in-window-p (point-max)))
  2107. (org-fit-window-to-buffer))
  2108. (setq second-time t)
  2109. (org-fit-window-to-buffer))
  2110. ;; Ask for selection
  2111. (message "Press key for agenda command%s:"
  2112. (if (or restrict-ok org-agenda-overriding-restriction)
  2113. (if org-agenda-overriding-restriction
  2114. " (restriction lock active)"
  2115. (if restriction
  2116. (format " (restricted to %s)" restriction)
  2117. " (unrestricted)"))
  2118. ""))
  2119. (setq c (read-char-exclusive))
  2120. (message "")
  2121. (cond
  2122. ((assoc (char-to-string c) custom)
  2123. (setq selstring (concat selstring (char-to-string c)))
  2124. (throw 'exit (cons selstring restriction)))
  2125. ((memq c prefixes)
  2126. (setq selstring (concat selstring (char-to-string c))
  2127. prefixes nil
  2128. rmheader (or rmheader t)
  2129. custom (delq nil (mapcar
  2130. (lambda (x)
  2131. (if (or (= (length (car x)) 1)
  2132. (/= (string-to-char (car x)) c))
  2133. nil
  2134. (cons (substring (car x) 1) (cdr x))))
  2135. custom))))
  2136. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2137. (message "Restriction is only possible in Org-mode buffers")
  2138. (ding) (sit-for 1))
  2139. ((eq c ?1)
  2140. (org-agenda-remove-restriction-lock 'noupdate)
  2141. (setq restriction 'buffer))
  2142. ((eq c ?0)
  2143. (org-agenda-remove-restriction-lock 'noupdate)
  2144. (setq restriction (if region-p 'region 'subtree)))
  2145. ((eq c ?<)
  2146. (org-agenda-remove-restriction-lock 'noupdate)
  2147. (setq restriction
  2148. (cond
  2149. ((eq restriction 'buffer)
  2150. (if region-p 'region 'subtree))
  2151. ((memq restriction '(subtree region))
  2152. nil)
  2153. (t 'buffer))))
  2154. ((eq c ?>)
  2155. (org-agenda-remove-restriction-lock 'noupdate)
  2156. (setq restriction nil))
  2157. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2158. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2159. ((and (> (length selstring) 0) (eq c ?\d))
  2160. (delete-window)
  2161. (org-agenda-get-restriction-and-command prefix-descriptions))
  2162. ((equal c ?q) (error "Abort"))
  2163. (t (error "Invalid key %c" c))))))))
  2164. (defun org-run-agenda-series (name series)
  2165. (org-let (nth 1 series) '(org-prepare-agenda name))
  2166. (let* ((org-agenda-multi t)
  2167. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2168. (cmds (car series))
  2169. (gprops (nth 1 series))
  2170. match ;; The byte compiler incorrectly complains about this. Keep it!
  2171. cmd type lprops)
  2172. (while (setq cmd (pop cmds))
  2173. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2174. (cond
  2175. ((eq type 'agenda)
  2176. (org-let2 gprops lprops
  2177. '(call-interactively 'org-agenda-list)))
  2178. ((eq type 'alltodo)
  2179. (org-let2 gprops lprops
  2180. '(call-interactively 'org-todo-list)))
  2181. ((eq type 'search)
  2182. (org-let2 gprops lprops
  2183. '(org-search-view current-prefix-arg match nil)))
  2184. ((eq type 'stuck)
  2185. (org-let2 gprops lprops
  2186. '(call-interactively 'org-agenda-list-stuck-projects)))
  2187. ((eq type 'tags)
  2188. (org-let2 gprops lprops
  2189. '(org-tags-view current-prefix-arg match)))
  2190. ((eq type 'tags-todo)
  2191. (org-let2 gprops lprops
  2192. '(org-tags-view '(4) match)))
  2193. ((eq type 'todo)
  2194. (org-let2 gprops lprops
  2195. '(org-todo-list match)))
  2196. ((fboundp type)
  2197. (org-let2 gprops lprops
  2198. '(funcall type match)))
  2199. (t (error "Invalid type in command series"))))
  2200. (widen)
  2201. (setq org-agenda-redo-command redo)
  2202. (goto-char (point-min)))
  2203. (org-fit-agenda-window)
  2204. (org-let (nth 1 series) '(org-finalize-agenda)))
  2205. ;;;###autoload
  2206. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2207. "Run an agenda command in batch mode and send the result to STDOUT.
  2208. If CMD-KEY is a string of length 1, it is used as a key in
  2209. `org-agenda-custom-commands' and triggers this command. If it is a
  2210. longer string it is used as a tags/todo match string.
  2211. Parameters are alternating variable names and values that will be bound
  2212. before running the agenda command."
  2213. (let (pars)
  2214. (while parameters
  2215. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2216. (if (> (length cmd-key) 2)
  2217. (eval (list 'let (nreverse pars)
  2218. (list 'org-tags-view nil cmd-key)))
  2219. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2220. (set-buffer org-agenda-buffer-name)
  2221. (princ (org-encode-for-stdout (buffer-string)))))
  2222. ;(defun org-encode-for-stdout (string)
  2223. ; (if (fboundp 'encode-coding-string)
  2224. ; (encode-coding-string string buffer-file-coding-system)
  2225. ; string))
  2226. (defun org-encode-for-stdout (string)
  2227. string)
  2228. (defvar org-agenda-info nil)
  2229. ;;;###autoload
  2230. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2231. "Run an agenda command in batch mode and send the result to STDOUT.
  2232. If CMD-KEY is a string of length 1, it is used as a key in
  2233. `org-agenda-custom-commands' and triggers this command. If it is a
  2234. longer string it is used as a tags/todo match string.
  2235. Parameters are alternating variable names and values that will be bound
  2236. before running the agenda command.
  2237. The output gives a line for each selected agenda item. Each
  2238. item is a list of comma-separated values, like this:
  2239. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2240. category The category of the item
  2241. head The headline, without TODO kwd, TAGS and PRIORITY
  2242. type The type of the agenda entry, can be
  2243. todo selected in TODO match
  2244. tagsmatch selected in tags match
  2245. diary imported from diary
  2246. deadline a deadline on given date
  2247. scheduled scheduled on given date
  2248. timestamp entry has timestamp on given date
  2249. closed entry was closed on given date
  2250. upcoming-deadline warning about deadline
  2251. past-scheduled forwarded scheduled item
  2252. block entry has date block including g. date
  2253. todo The todo keyword, if any
  2254. tags All tags including inherited ones, separated by colons
  2255. date The relevant date, like 2007-2-14
  2256. time The time, like 15:00-16:50
  2257. extra Sting with extra planning info
  2258. priority-l The priority letter if any was given
  2259. priority-n The computed numerical priority
  2260. agenda-day The day in the agenda where this is listed"
  2261. (let (pars)
  2262. (while parameters
  2263. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2264. (push (list 'org-agenda-remove-tags t) pars)
  2265. (if (> (length cmd-key) 2)
  2266. (eval (list 'let (nreverse pars)
  2267. (list 'org-tags-view nil cmd-key)))
  2268. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2269. (set-buffer org-agenda-buffer-name)
  2270. (let* ((lines (org-split-string (buffer-string) "\n"))
  2271. line)
  2272. (while (setq line (pop lines))
  2273. (catch 'next
  2274. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2275. (setq org-agenda-info
  2276. (org-fix-agenda-info (text-properties-at 0 line)))
  2277. (princ
  2278. (org-encode-for-stdout
  2279. (mapconcat 'org-agenda-export-csv-mapper
  2280. '(org-category txt type todo tags date time extra
  2281. priority-letter priority agenda-day)
  2282. ",")))
  2283. (princ "\n"))))))
  2284. (defun org-fix-agenda-info (props)
  2285. "Make sure all properties on an agenda item have a canonical form.
  2286. This ensures the export commands can easily use it."
  2287. (let (tmp re)
  2288. (when (setq tmp (plist-get props 'tags))
  2289. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2290. (when (setq tmp (plist-get props 'date))
  2291. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2292. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2293. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2294. (setq tmp (calendar-date-string tmp)))
  2295. (setq props (plist-put props 'date tmp)))
  2296. (when (setq tmp (plist-get props 'day))
  2297. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2298. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2299. (setq tmp (calendar-date-string tmp)))
  2300. (setq props (plist-put props 'day tmp))
  2301. (setq props (plist-put props 'agenda-day tmp)))
  2302. (when (setq tmp (plist-get props 'txt))
  2303. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2304. (plist-put props 'priority-letter (match-string 1 tmp))
  2305. (setq tmp (replace-match "" t t tmp)))
  2306. (when (and (setq re (plist-get props 'org-todo-regexp))
  2307. (setq re (concat "\\`\\.*" re " ?"))
  2308. (string-match re tmp))
  2309. (plist-put props 'todo (match-string 1 tmp))
  2310. (setq tmp (replace-match "" t t tmp)))
  2311. (plist-put props 'txt tmp)))
  2312. props)
  2313. (defun org-agenda-export-csv-mapper (prop)
  2314. (let ((res (plist-get org-agenda-info prop)))
  2315. (setq res
  2316. (cond
  2317. ((not res) "")
  2318. ((stringp res) res)
  2319. (t (prin1-to-string res))))
  2320. (while (string-match "," res)
  2321. (setq res (replace-match ";" t t res)))
  2322. (org-trim res)))
  2323. ;;;###autoload
  2324. (defun org-store-agenda-views (&rest parameters)
  2325. (interactive)
  2326. (eval (list 'org-batch-store-agenda-views)))
  2327. ;; FIXME, why is this a macro?????
  2328. ;;;###autoload
  2329. (defmacro org-batch-store-agenda-views (&rest parameters)
  2330. "Run all custom agenda commands that have a file argument."
  2331. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2332. (pop-up-frames nil)
  2333. (dir default-directory)
  2334. pars cmd thiscmdkey files opts cmd-or-set)
  2335. (while parameters
  2336. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2337. (setq pars (reverse pars))
  2338. (save-window-excursion
  2339. (while cmds
  2340. (setq cmd (pop cmds)
  2341. thiscmdkey (car cmd)
  2342. cmd-or-set (nth 2 cmd)
  2343. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2344. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2345. (if (stringp files) (setq files (list files)))
  2346. (when files
  2347. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2348. (list 'org-agenda nil thiscmdkey)))
  2349. (set-buffer org-agenda-buffer-name)
  2350. (while files
  2351. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2352. (list 'org-write-agenda
  2353. (expand-file-name (pop files) dir) nil t))))
  2354. (and (get-buffer org-agenda-buffer-name)
  2355. (kill-buffer org-agenda-buffer-name)))))))
  2356. (defun org-agenda-mark-header-line (pos)
  2357. "Mark the line at POS as an agenda structure header."
  2358. (save-excursion
  2359. (goto-char pos)
  2360. (put-text-property (point-at-bol) (point-at-eol)
  2361. 'org-agenda-structural-header t)
  2362. (when org-agenda-title-append
  2363. (put-text-property (point-at-bol) (point-at-eol)
  2364. 'org-agenda-title-append org-agenda-title-append))))
  2365. (defvar org-mobile-creating-agendas)
  2366. (defun org-write-agenda (file &optional open nosettings)
  2367. "Write the current buffer (an agenda view) as a file.
  2368. Depending on the extension of the file name, plain text (.txt),
  2369. HTML (.html or .htm) or Postscript (.ps) is produced.
  2370. If the extension is .ics, run icalendar export over all files used
  2371. to construct the agenda and limit the export to entries listed in the
  2372. agenda now.
  2373. With prefix argument OPEN, open the new file immediately.
  2374. If NOSETTINGS is given, do not scope the settings of
  2375. `org-agenda-exporter-settings' into the export commands. This is used when
  2376. the settings have already been scoped and we do not wish to overrule other,
  2377. higher priority settings."
  2378. (interactive "FWrite agenda to file: \nP")
  2379. (if (not (file-writable-p file))
  2380. (error "Cannot write agenda to file %s" file))
  2381. (org-let (if nosettings nil org-agenda-exporter-settings)
  2382. '(save-excursion
  2383. (save-window-excursion
  2384. (org-agenda-mark-filtered-text)
  2385. (let ((bs (copy-sequence (buffer-string))) beg)
  2386. (org-agenda-unmark-filtered-text)
  2387. (with-temp-buffer
  2388. (rename-buffer "Agenda View" t)
  2389. (set-buffer-modified-p nil)
  2390. (insert bs)
  2391. (org-agenda-remove-marked-text 'org-filtered)
  2392. (while (setq beg (text-property-any (point-min) (point-max)
  2393. 'org-filtered t))
  2394. (delete-region
  2395. beg (or (next-single-property-change beg 'org-filtered)
  2396. (point-max))))
  2397. (run-hooks 'org-agenda-before-write-hook)
  2398. (cond
  2399. ((org-bound-and-true-p org-mobile-creating-agendas)
  2400. (org-mobile-write-agenda-for-mobile file))
  2401. ((string-match "\\.html?\\'" file)
  2402. (require 'htmlize)
  2403. (set-buffer (htmlize-buffer (current-buffer)))
  2404. (when (and org-agenda-export-html-style
  2405. (string-match "<style>" org-agenda-export-html-style))
  2406. ;; replace <style> section with org-agenda-export-html-style
  2407. (goto-char (point-min))
  2408. (kill-region (- (search-forward "<style") 6)
  2409. (search-forward "</style>"))
  2410. (insert org-agenda-export-html-style))
  2411. (write-file file)
  2412. (kill-buffer (current-buffer))
  2413. (message "HTML written to %s" file))
  2414. ((string-match "\\.ps\\'" file)
  2415. (require 'ps-print)
  2416. (ps-print-buffer-with-faces file)
  2417. (message "Postscript written to %s" file))
  2418. ((string-match "\\.pdf\\'" file)
  2419. (require 'ps-print)
  2420. (ps-print-buffer-with-faces
  2421. (concat (file-name-sans-extension file) ".ps"))
  2422. (call-process "ps2pdf" nil nil nil
  2423. (expand-file-name
  2424. (concat (file-name-sans-extension file) ".ps"))
  2425. (expand-file-name file))
  2426. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2427. (message "PDF written to %s" file))
  2428. ((string-match "\\.ics\\'" file)
  2429. (require 'org-icalendar)
  2430. (let ((org-agenda-marker-table
  2431. (org-create-marker-find-array
  2432. (org-agenda-collect-markers)))
  2433. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2434. (org-combined-agenda-icalendar-file file))
  2435. (apply 'org-export-icalendar 'combine
  2436. (org-agenda-files nil 'ifmode))))
  2437. (t
  2438. (let ((bs (buffer-string)))
  2439. (find-file file)
  2440. (erase-buffer)
  2441. (insert bs)
  2442. (save-buffer 0)
  2443. (kill-buffer (current-buffer))
  2444. (message "Plain text written to %s" file))))))))
  2445. (set-buffer org-agenda-buffer-name))
  2446. (when open (org-open-file file)))
  2447. (defvar org-agenda-filter-overlays nil)
  2448. (defun org-agenda-mark-filtered-text ()
  2449. "Mark all text hidden by filtering with a text property."
  2450. (let ((inhibit-read-only t))
  2451. (mapc
  2452. (lambda (o)
  2453. (when (equal (overlay-buffer o) (current-buffer))
  2454. (put-text-property
  2455. (overlay-start o) (overlay-end o)
  2456. 'org-filtered t)))
  2457. org-agenda-filter-overlays)))
  2458. (defun org-agenda-unmark-filtered-text ()
  2459. "Remove the filtering text property."
  2460. (let ((inhibit-read-only t))
  2461. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2462. (defun org-agenda-remove-marked-text (property &optional value)
  2463. "Delete all text marked with VALUE of PROPERTY.
  2464. VALUE defaults to t."
  2465. (let (beg)
  2466. (setq value (or value t))
  2467. (while (setq beg (text-property-any (point-min) (point-max)
  2468. property value))
  2469. (delete-region
  2470. beg (or (next-single-property-change beg 'org-filtered)
  2471. (point-max))))))
  2472. (defun org-agenda-add-entry-text ()
  2473. "Add entry text to agenda lines.
  2474. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2475. entry text following headings shown in the agenda.
  2476. Drawers will be excluded, also the line with scheduling/deadline info."
  2477. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2478. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2479. (let (m txt)
  2480. (goto-char (point-min))
  2481. (while (not (eobp))
  2482. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2483. (beginning-of-line 2)
  2484. (setq txt (org-agenda-get-some-entry-text
  2485. m org-agenda-add-entry-text-maxlines " > "))
  2486. (end-of-line 1)
  2487. (if (string-match "\\S-" txt)
  2488. (insert "\n" txt)
  2489. (or (eobp) (forward-char 1))))))))
  2490. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2491. &rest keep)
  2492. "Extract entry text from MARKER, at most N-LINES lines.
  2493. This will ignore drawers etc, just get the text.
  2494. If INDENT is given, prefix every line with this string. If KEEP is
  2495. given, it is a list of symbols, defining stuff that should not be
  2496. removed from the entry content. Currently only `planning' is allowed here."
  2497. (let (txt drawer-re kwd-time-re ind)
  2498. (save-excursion
  2499. (with-current-buffer (marker-buffer marker)
  2500. (if (not (org-mode-p))
  2501. (setq txt "")
  2502. (save-excursion
  2503. (save-restriction
  2504. (widen)
  2505. (goto-char marker)
  2506. (end-of-line 1)
  2507. (setq txt (buffer-substring
  2508. (min (1+ (point)) (point-max))
  2509. (progn (outline-next-heading) (point)))
  2510. drawer-re org-drawer-regexp
  2511. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2512. ".*\n?"))
  2513. (with-temp-buffer
  2514. (insert txt)
  2515. (when org-agenda-add-entry-text-descriptive-links
  2516. (goto-char (point-min))
  2517. (while (org-activate-bracket-links (point-max))
  2518. (add-text-properties (match-beginning 0) (match-end 0)
  2519. '(face org-link))))
  2520. (goto-char (point-min))
  2521. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2522. (set-text-properties (match-beginning 0) (match-end 0)
  2523. nil))
  2524. (goto-char (point-min))
  2525. (while (re-search-forward drawer-re nil t)
  2526. (delete-region
  2527. (match-beginning 0)
  2528. (progn (re-search-forward
  2529. "^[ \t]*:END:.*\n?" nil 'move)
  2530. (point))))
  2531. (unless (member 'planning keep)
  2532. (goto-char (point-min))
  2533. (while (re-search-forward kwd-time-re nil t)
  2534. (replace-match "")))
  2535. (goto-char (point-min))
  2536. (when org-agenda-entry-text-exclude-regexps
  2537. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2538. (while (setq re (pop re-list))
  2539. (goto-char (point-min))
  2540. (while (re-search-forward re nil t)
  2541. (replace-match "")))))
  2542. (goto-char (point-max))
  2543. (skip-chars-backward " \t\n")
  2544. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2545. ;; find and remove min common indentation
  2546. (goto-char (point-min))
  2547. (untabify (point-min) (point-max))
  2548. (setq ind (org-get-indentation))
  2549. (while (not (eobp))
  2550. (unless (looking-at "[ \t]*$")
  2551. (setq ind (min ind (org-get-indentation))))
  2552. (beginning-of-line 2))
  2553. (goto-char (point-min))
  2554. (while (not (eobp))
  2555. (unless (looking-at "[ \t]*$")
  2556. (move-to-column ind)
  2557. (delete-region (point-at-bol) (point)))
  2558. (beginning-of-line 2))
  2559. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2560. (goto-char (point-min))
  2561. (when indent
  2562. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2563. (replace-match indent t t)))
  2564. (goto-char (point-min))
  2565. (while (looking-at "[ \t]*\n") (replace-match ""))
  2566. (goto-char (point-max))
  2567. (when (> (org-current-line)
  2568. n-lines)
  2569. (org-goto-line (1+ n-lines))
  2570. (backward-char 1))
  2571. (setq txt (buffer-substring (point-min) (point)))))))))
  2572. txt))
  2573. (defun org-agenda-collect-markers ()
  2574. "Collect the markers pointing to entries in the agenda buffer."
  2575. (let (m markers)
  2576. (save-excursion
  2577. (goto-char (point-min))
  2578. (while (not (eobp))
  2579. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2580. (org-get-at-bol 'org-marker)))
  2581. (push m markers))
  2582. (beginning-of-line 2)))
  2583. (nreverse markers)))
  2584. (defun org-create-marker-find-array (marker-list)
  2585. "Create a alist of files names with all marker positions in that file."
  2586. (let (f tbl m a p)
  2587. (while (setq m (pop marker-list))
  2588. (setq p (marker-position m)
  2589. f (buffer-file-name (or (buffer-base-buffer
  2590. (marker-buffer m))
  2591. (marker-buffer m))))
  2592. (if (setq a (assoc f tbl))
  2593. (push (marker-position m) (cdr a))
  2594. (push (list f p) tbl)))
  2595. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2596. tbl)))
  2597. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2598. (defun org-check-agenda-marker-table ()
  2599. "Check of the current entry is on the marker list."
  2600. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2601. a)
  2602. (and (setq a (assoc file org-agenda-marker-table))
  2603. (save-match-data
  2604. (save-excursion
  2605. (org-back-to-heading t)
  2606. (member (point) (cdr a)))))))
  2607. (defun org-check-for-org-mode ()
  2608. "Make sure current buffer is in org-mode. Error if not."
  2609. (or (org-mode-p)
  2610. (error "Cannot execute org-mode agenda command on buffer in %s"
  2611. major-mode)))
  2612. (defun org-fit-agenda-window ()
  2613. "Fit the window to the buffer size."
  2614. (and (memq org-agenda-window-setup '(reorganize-frame))
  2615. (fboundp 'fit-window-to-buffer)
  2616. (org-fit-window-to-buffer
  2617. nil
  2618. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2619. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2620. ;;; Agenda prepare and finalize
  2621. (defvar org-agenda-multi nil) ; dynamically scoped
  2622. (defvar org-agenda-buffer-name "*Org Agenda*")
  2623. (defvar org-pre-agenda-window-conf nil)
  2624. (defvar org-agenda-columns-active nil)
  2625. (defvar org-agenda-name nil)
  2626. (defvar org-agenda-filter nil)
  2627. (defvar org-agenda-filter-while-redo nil)
  2628. (defvar org-agenda-filter-preset nil
  2629. "A preset of the tags filter used for secondary agenda filtering.
  2630. This must be a list of strings, each string must be a single tag preceded
  2631. by \"+\" or \"-\".
  2632. This variable should not be set directly, but agenda custom commands can
  2633. bind it in the options section. The preset filter is a global property of
  2634. the entire agenda view. In a block agenda, it will not work reliably to
  2635. define a filter for one of the individual blocks. You need to set it in
  2636. the global options and expect it to be applied to the entire view.")
  2637. (defun org-prepare-agenda (&optional name)
  2638. (setq org-todo-keywords-for-agenda nil)
  2639. (setq org-done-keywords-for-agenda nil)
  2640. (setq org-drawers-for-agenda nil)
  2641. (unless org-agenda-persistent-filter
  2642. (setq org-agenda-filter nil))
  2643. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2644. (if org-agenda-multi
  2645. (progn
  2646. (setq buffer-read-only nil)
  2647. (goto-char (point-max))
  2648. (unless (or (bobp) org-agenda-compact-blocks)
  2649. (insert "\n"
  2650. (if (stringp org-agenda-block-separator)
  2651. org-agenda-block-separator
  2652. (make-string (window-width) org-agenda-block-separator))
  2653. "\n"))
  2654. (narrow-to-region (point) (point-max)))
  2655. (org-agenda-reset-markers)
  2656. (setq org-agenda-contributing-files nil)
  2657. (setq org-agenda-columns-active nil)
  2658. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2659. (setq org-todo-keywords-for-agenda
  2660. (org-uniquify org-todo-keywords-for-agenda))
  2661. (setq org-done-keywords-for-agenda
  2662. (org-uniquify org-done-keywords-for-agenda))
  2663. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2664. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2665. (awin (get-buffer-window abuf)))
  2666. (cond
  2667. ((equal (current-buffer) abuf) nil)
  2668. (awin (select-window awin))
  2669. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2670. ((equal org-agenda-window-setup 'current-window)
  2671. (switch-to-buffer abuf))
  2672. ((equal org-agenda-window-setup 'other-window)
  2673. (org-switch-to-buffer-other-window abuf))
  2674. ((equal org-agenda-window-setup 'other-frame)
  2675. (switch-to-buffer-other-frame abuf))
  2676. ((equal org-agenda-window-setup 'reorganize-frame)
  2677. (delete-other-windows)
  2678. (org-switch-to-buffer-other-window abuf)))
  2679. ;; additional test in case agenda is invoked from within agenda
  2680. ;; buffer via elisp link
  2681. (unless (equal (current-buffer) abuf)
  2682. (switch-to-buffer abuf)))
  2683. (setq buffer-read-only nil)
  2684. (let ((inhibit-read-only t)) (erase-buffer))
  2685. (org-agenda-mode)
  2686. (and name (not org-agenda-name)
  2687. (org-set-local 'org-agenda-name name)))
  2688. (setq buffer-read-only nil))
  2689. (defun org-finalize-agenda ()
  2690. "Finishing touch for the agenda buffer, called just before displaying it."
  2691. (unless org-agenda-multi
  2692. (save-excursion
  2693. (let ((inhibit-read-only t))
  2694. (goto-char (point-min))
  2695. (while (org-activate-bracket-links (point-max))
  2696. (add-text-properties (match-beginning 0) (match-end 0)
  2697. '(face org-link)))
  2698. (org-agenda-align-tags)
  2699. (unless org-agenda-with-colors
  2700. (remove-text-properties (point-min) (point-max) '(face nil))))
  2701. (if (and (boundp 'org-agenda-overriding-columns-format)
  2702. org-agenda-overriding-columns-format)
  2703. (org-set-local 'org-agenda-overriding-columns-format
  2704. org-agenda-overriding-columns-format))
  2705. (if (and (boundp 'org-agenda-view-columns-initially)
  2706. org-agenda-view-columns-initially)
  2707. (org-agenda-columns))
  2708. (when org-agenda-fontify-priorities
  2709. (org-agenda-fontify-priorities))
  2710. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2711. (org-agenda-dim-blocked-tasks))
  2712. (org-agenda-mark-clocking-task)
  2713. (when org-agenda-entry-text-mode
  2714. (org-agenda-entry-text-hide)
  2715. (org-agenda-entry-text-show))
  2716. (if (functionp 'org-habit-insert-consistency-graphs)
  2717. (org-habit-insert-consistency-graphs))
  2718. (run-hooks 'org-finalize-agenda-hook)
  2719. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2720. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2721. (org-agenda-filter-apply org-agenda-filter))
  2722. )))
  2723. (defun org-agenda-mark-clocking-task ()
  2724. "Mark the current clock entry in the agenda if it is present."
  2725. (mapc (lambda (o)
  2726. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2727. (delete-overlay o)))
  2728. (overlays-in (point-min) (point-max)))
  2729. (when (marker-buffer org-clock-hd-marker)
  2730. (save-excursion
  2731. (goto-char (point-min))
  2732. (let (s ov)
  2733. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2734. (goto-char s)
  2735. (when (equal (org-get-at-bol 'org-hd-marker)
  2736. org-clock-hd-marker)
  2737. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2738. (overlay-put ov 'type 'org-agenda-clocking)
  2739. (overlay-put ov 'face 'org-agenda-clocking)
  2740. (overlay-put ov 'help-echo
  2741. "The clock is running in this item")))))))
  2742. (defun org-agenda-fontify-priorities ()
  2743. "Make highest priority lines bold, and lowest italic."
  2744. (interactive)
  2745. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2746. (delete-overlay o)))
  2747. (overlays-in (point-min) (point-max)))
  2748. (save-excursion
  2749. (let ((inhibit-read-only t)
  2750. b e p ov h l)
  2751. (goto-char (point-min))
  2752. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2753. (setq h (or (get-char-property (point) 'org-highest-priority)
  2754. org-highest-priority)
  2755. l (or (get-char-property (point) 'org-lowest-priority)
  2756. org-lowest-priority)
  2757. p (string-to-char (match-string 1))
  2758. b (match-beginning 0)
  2759. e (if (eq org-agenda-fontify-priorities 'cookies)
  2760. (match-end 0)
  2761. (point-at-eol))
  2762. ov (make-overlay b e))
  2763. (overlay-put
  2764. ov 'face
  2765. (cond ((org-face-from-face-or-color
  2766. 'priority nil
  2767. (cdr (assoc p org-priority-faces))))
  2768. ((and (listp org-agenda-fontify-priorities)
  2769. (org-face-from-face-or-color
  2770. 'priority nil
  2771. (cdr (assoc p org-agenda-fontify-priorities)))))
  2772. ((equal p l) 'italic)
  2773. ((equal p h) 'bold)))
  2774. (overlay-put ov 'org-type 'org-priority)))))
  2775. (defun org-agenda-dim-blocked-tasks ()
  2776. "Dim currently blocked TODO's in the agenda display."
  2777. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2778. (delete-overlay o)))
  2779. (overlays-in (point-min) (point-max)))
  2780. (save-excursion
  2781. (let ((inhibit-read-only t)
  2782. (org-depend-tag-blocked nil)
  2783. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2784. org-blocked-by-checkboxes
  2785. invis1 b e p ov h l)
  2786. (goto-char (point-min))
  2787. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2788. (and pos (goto-char (1+ pos))))
  2789. (setq org-blocked-by-checkboxes nil invis1 invis)
  2790. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2791. (when (and marker
  2792. (not (with-current-buffer (marker-buffer marker)
  2793. (save-excursion
  2794. (goto-char marker)
  2795. (if (org-entry-get nil "NOBLOCKING")
  2796. t ;; Never block this entry
  2797. (run-hook-with-args-until-failure
  2798. 'org-blocker-hook
  2799. (list :type 'todo-state-change
  2800. :position marker
  2801. :from 'todo
  2802. :to 'done)))))))
  2803. (if org-blocked-by-checkboxes (setq invis1 nil))
  2804. (setq b (if invis1
  2805. (max (point-min) (1- (point-at-bol)))
  2806. (point-at-bol))
  2807. e (point-at-eol)
  2808. ov (make-overlay b e))
  2809. (if invis1
  2810. (overlay-put ov 'invisible t)
  2811. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2812. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2813. (defvar org-agenda-skip-function nil
  2814. "Function to be called at each match during agenda construction.
  2815. If this function returns nil, the current match should not be skipped.
  2816. Otherwise, the function must return a position from where the search
  2817. should be continued.
  2818. This may also be a Lisp form, it will be evaluated.
  2819. Never set this variable using `setq' or so, because then it will apply
  2820. to all future agenda commands. Instead, bind it with `let' to scope
  2821. it dynamically into the agenda-constructing command. A good way to set
  2822. it is through options in `org-agenda-custom-commands'.")
  2823. (defun org-agenda-skip ()
  2824. "Throw to `:skip' in places that should be skipped.
  2825. Also moves point to the end of the skipped region, so that search can
  2826. continue from there."
  2827. (let ((p (point-at-bol)) to fp)
  2828. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2829. (get-text-property p :org-archived)
  2830. (org-end-of-subtree t)
  2831. (throw :skip t))
  2832. (and org-agenda-skip-comment-trees
  2833. (get-text-property p :org-comment)
  2834. (org-end-of-subtree t)
  2835. (throw :skip t))
  2836. (if (equal (char-after p) ?#) (throw :skip t))
  2837. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2838. (consp org-agenda-skip-function))
  2839. (setq to (save-excursion
  2840. (save-match-data
  2841. (if fp
  2842. (funcall org-agenda-skip-function)
  2843. (eval org-agenda-skip-function))))))
  2844. (goto-char to)
  2845. (throw :skip t))))
  2846. (defvar org-agenda-markers nil
  2847. "List of all currently active markers created by `org-agenda'.")
  2848. (defvar org-agenda-last-marker-time (org-float-time)
  2849. "Creation time of the last agenda marker.")
  2850. (defun org-agenda-new-marker (&optional pos)
  2851. "Return a new agenda marker.
  2852. Org-mode keeps a list of these markers and resets them when they are
  2853. no longer in use."
  2854. (let ((m (copy-marker (or pos (point)))))
  2855. (setq org-agenda-last-marker-time (org-float-time))
  2856. (push m org-agenda-markers)
  2857. m))
  2858. (defun org-agenda-reset-markers ()
  2859. "Reset markers created by `org-agenda'."
  2860. (while org-agenda-markers
  2861. (move-marker (pop org-agenda-markers) nil)))
  2862. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2863. "Save relative positions of markers in region."
  2864. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2865. org-agenda-markers))
  2866. ;;; Entry text mode
  2867. (defun org-agenda-entry-text-show-here ()
  2868. "Add some text from the entry as context to the current line."
  2869. (let (m txt o)
  2870. (setq m (org-get-at-bol 'org-hd-marker))
  2871. (unless (marker-buffer m)
  2872. (error "No marker points to an entry here"))
  2873. (setq txt (concat "\n" (org-no-properties
  2874. (org-agenda-get-some-entry-text
  2875. m org-agenda-entry-text-maxlines " > "))))
  2876. (when (string-match "\\S-" txt)
  2877. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2878. (overlay-put o 'evaporate t)
  2879. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2880. (overlay-put o 'after-string txt))))
  2881. (defun org-agenda-entry-text-show ()
  2882. "Add entry context for all agenda lines."
  2883. (interactive)
  2884. (save-excursion
  2885. (goto-char (point-max))
  2886. (beginning-of-line 1)
  2887. (while (not (bobp))
  2888. (when (org-get-at-bol 'org-hd-marker)
  2889. (org-agenda-entry-text-show-here))
  2890. (beginning-of-line 0))))
  2891. (defun org-agenda-entry-text-hide ()
  2892. "Remove any shown entry context."
  2893. (delq nil
  2894. (mapcar (lambda (o)
  2895. (if (eq (overlay-get o 'org-overlay-type)
  2896. 'agenda-entry-content)
  2897. (progn (delete-overlay o) t)))
  2898. (overlays-in (point-min) (point-max)))))
  2899. (defun org-agenda-get-day-face (date)
  2900. "Return the face DATE should be displayed with."
  2901. (or (and (functionp org-agenda-day-face-function)
  2902. (funcall org-agenda-day-face-function date))
  2903. (cond ((org-agenda-todayp date)
  2904. 'org-agenda-date-today)
  2905. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  2906. 'org-agenda-date-weekend)
  2907. (t 'org-agenda-date))))
  2908. ;;; Agenda timeline
  2909. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2910. (defun org-timeline (&optional include-all)
  2911. "Show a time-sorted view of the entries in the current org file.
  2912. Only entries with a time stamp of today or later will be listed. With
  2913. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2914. under the current date.
  2915. If the buffer contains an active region, only check the region for
  2916. dates."
  2917. (interactive "P")
  2918. (org-compile-prefix-format 'timeline)
  2919. (org-set-sorting-strategy 'timeline)
  2920. (let* ((dopast t)
  2921. (dotodo include-all)
  2922. (doclosed org-agenda-show-log)
  2923. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2924. (current-buffer))))
  2925. (date (calendar-current-date))
  2926. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2927. (end (if (org-region-active-p) (region-end) (point-max)))
  2928. (day-numbers (org-get-all-dates beg end 'no-ranges
  2929. t doclosed ; always include today
  2930. org-timeline-show-empty-dates))
  2931. (org-deadline-warning-days 0)
  2932. (org-agenda-only-exact-dates t)
  2933. (today (org-agenda-today))
  2934. (past t)
  2935. args
  2936. s e rtn d emptyp)
  2937. (setq org-agenda-redo-command
  2938. (list 'progn
  2939. (list 'org-switch-to-buffer-other-window (current-buffer))
  2940. (list 'org-timeline (list 'quote include-all))))
  2941. (if (not dopast)
  2942. ;; Remove past dates from the list of dates.
  2943. (setq day-numbers (delq nil (mapcar (lambda(x)
  2944. (if (>= x today) x nil))
  2945. day-numbers))))
  2946. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2947. (if doclosed (push :closed args))
  2948. (push :timestamp args)
  2949. (push :deadline args)
  2950. (push :scheduled args)
  2951. (push :sexp args)
  2952. (if dotodo (push :todo args))
  2953. (insert "Timeline of file " entry "\n")
  2954. (add-text-properties (point-min) (point)
  2955. (list 'face 'org-agenda-structure))
  2956. (org-agenda-mark-header-line (point-min))
  2957. (while (setq d (pop day-numbers))
  2958. (if (and (listp d) (eq (car d) :omitted))
  2959. (progn
  2960. (setq s (point))
  2961. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2962. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2963. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2964. (if (and (>= d today)
  2965. dopast
  2966. past)
  2967. (progn
  2968. (setq past nil)
  2969. (insert (make-string 79 ?-) "\n")))
  2970. (setq date (calendar-gregorian-from-absolute d))
  2971. (setq s (point))
  2972. (setq rtn (and (not emptyp)
  2973. (apply 'org-agenda-get-day-entries entry
  2974. date args)))
  2975. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2976. (progn
  2977. (insert
  2978. (if (stringp org-agenda-format-date)
  2979. (format-time-string org-agenda-format-date
  2980. (org-time-from-absolute date))
  2981. (funcall org-agenda-format-date date))
  2982. "\n")
  2983. (put-text-property s (1- (point)) 'face
  2984. (org-agenda-get-day-face date))
  2985. (put-text-property s (1- (point)) 'org-date-line t)
  2986. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2987. (if (equal d today)
  2988. (put-text-property s (1- (point)) 'org-today t))
  2989. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2990. (put-text-property s (1- (point)) 'day d)))))
  2991. (goto-char (point-min))
  2992. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2993. (point-min)))
  2994. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2995. (org-finalize-agenda)
  2996. (setq buffer-read-only t)))
  2997. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2998. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2999. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3000. not every single day in the range. If FORCE-TODAY is non-nil, make
  3001. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3002. inactive time stamps (those in square brackets) are included.
  3003. When EMPTY is non-nil, also include days without any entries."
  3004. (let ((re (concat
  3005. (if pre-re pre-re "")
  3006. (if inactive org-ts-regexp-both org-ts-regexp)))
  3007. dates dates1 date day day1 day2 ts1 ts2)
  3008. (if force-today
  3009. (setq dates (list (org-agenda-today))))
  3010. (save-excursion
  3011. (goto-char beg)
  3012. (while (re-search-forward re end t)
  3013. (setq day (time-to-days (org-time-string-to-time
  3014. (substring (match-string 1) 0 10))))
  3015. (or (memq day dates) (push day dates)))
  3016. (unless no-ranges
  3017. (goto-char beg)
  3018. (while (re-search-forward org-tr-regexp end t)
  3019. (setq ts1 (substring (match-string 1) 0 10)
  3020. ts2 (substring (match-string 2) 0 10)
  3021. day1 (time-to-days (org-time-string-to-time ts1))
  3022. day2 (time-to-days (org-time-string-to-time ts2)))
  3023. (while (< (setq day1 (1+ day1)) day2)
  3024. (or (memq day1 dates) (push day1 dates)))))
  3025. (setq dates (sort dates '<))
  3026. (when empty
  3027. (while (setq day (pop dates))
  3028. (setq day2 (car dates))
  3029. (push day dates1)
  3030. (when (and day2 empty)
  3031. (if (or (eq empty t)
  3032. (and (numberp empty) (<= (- day2 day) empty)))
  3033. (while (< (setq day (1+ day)) day2)
  3034. (push (list day) dates1))
  3035. (push (cons :omitted (- day2 day)) dates1))))
  3036. (setq dates (nreverse dates1)))
  3037. dates)))
  3038. ;;; Agenda Daily/Weekly
  3039. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  3040. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3041. "Custom commands can set this variable in the options section.")
  3042. (defvar org-agenda-last-arguments nil
  3043. "The arguments of the previous call to `org-agenda'.")
  3044. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3045. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  3046. (defvar org-include-all-loc nil) ; local variable
  3047. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3048. "List of types searched for when creating the daily/weekly agenda.
  3049. This variable is a list of symbols that controls the types of
  3050. items that appear in the daily/weekly agenda. Allowed symbols in this
  3051. list are are
  3052. :timestamp List items containing a date stamp or date range matching
  3053. the selected date. This includes sexp entries in
  3054. angular brackets.
  3055. :sexp List entries resulting from plain diary-like sexps.
  3056. :deadline List deadline due on that date. When the date is today,
  3057. also list any deadlines past due, or due within
  3058. `org-deadline-warning-days'. `:deadline' must appear before
  3059. `:scheduled' if the setting of
  3060. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3061. any effect.
  3062. :scheduled List all items which are scheduled for the given date.
  3063. The diary for *today* also contains items which were
  3064. scheduled earlier and are not yet marked DONE.
  3065. By default, all four types are turned on.
  3066. Never set this variable globally using `setq', because then it
  3067. will apply to all future agenda commands. Instead, bind it with
  3068. `let' to scope it dynamically into the the agenda-constructing
  3069. command. A good way to set it is through options in
  3070. `org-agenda-custom-commands'. For a more flexible (though
  3071. somewhat less efficient) way of determining what is included in
  3072. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3073. ;;;###autoload
  3074. (defun org-agenda-list (&optional include-all start-day ndays)
  3075. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3076. The view will be for the current day or week, but from the overview buffer
  3077. you will be able to go to other days/weeks.
  3078. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3079. all unfinished TODO items will also be shown, before the agenda.
  3080. This feature is considered obsolete, please use the TODO list or a block
  3081. agenda instead.
  3082. With a numeric prefix argument in an interactive call, the agenda will
  3083. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  3084. the number of days. NDAYS defaults to `org-agenda-ndays'.
  3085. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3086. given in `org-agenda-start-on-weekday'."
  3087. (interactive "P")
  3088. (if (and (integerp include-all) (> include-all 0))
  3089. (setq ndays include-all include-all nil))
  3090. (setq ndays (or ndays org-agenda-ndays)
  3091. start-day (or start-day org-agenda-start-day))
  3092. (if org-agenda-overriding-arguments
  3093. (setq include-all (car org-agenda-overriding-arguments)
  3094. start-day (nth 1 org-agenda-overriding-arguments)
  3095. ndays (nth 2 org-agenda-overriding-arguments)))
  3096. (if (stringp start-day)
  3097. ;; Convert to an absolute day number
  3098. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3099. (setq org-agenda-last-arguments (list include-all start-day ndays))
  3100. (org-compile-prefix-format 'agenda)
  3101. (org-set-sorting-strategy 'agenda)
  3102. (let* ((org-agenda-start-on-weekday
  3103. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  3104. org-agenda-start-on-weekday nil))
  3105. (thefiles (org-agenda-files nil 'ifmode))
  3106. (files thefiles)
  3107. (today (org-agenda-today))
  3108. (sd (or start-day today))
  3109. (start (if (or (null org-agenda-start-on-weekday)
  3110. (< org-agenda-ndays 7))
  3111. sd
  3112. (let* ((nt (calendar-day-of-week
  3113. (calendar-gregorian-from-absolute sd)))
  3114. (n1 org-agenda-start-on-weekday)
  3115. (d (- nt n1)))
  3116. (- sd (+ (if (< d 0) 7 0) d)))))
  3117. (day-numbers (list start))
  3118. (day-cnt 0)
  3119. (inhibit-redisplay (not debug-on-error))
  3120. s e rtn rtnall file date d start-pos end-pos todayp nd
  3121. clocktable-start clocktable-end filter)
  3122. (setq org-agenda-redo-command
  3123. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3124. ;; Make the list of days
  3125. (setq ndays (or ndays org-agenda-ndays)
  3126. nd ndays)
  3127. (while (> ndays 1)
  3128. (push (1+ (car day-numbers)) day-numbers)
  3129. (setq ndays (1- ndays)))
  3130. (setq day-numbers (nreverse day-numbers))
  3131. (setq clocktable-start (car day-numbers)
  3132. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3133. (org-prepare-agenda "Day/Week")
  3134. (org-set-local 'org-starting-day (car day-numbers))
  3135. (org-set-local 'org-include-all-loc include-all)
  3136. (org-set-local 'org-agenda-span
  3137. (org-agenda-ndays-to-span nd))
  3138. (when (and (or include-all org-agenda-include-all-todo)
  3139. (member today day-numbers))
  3140. (setq files thefiles
  3141. rtnall nil)
  3142. (while (setq file (pop files))
  3143. (catch 'nextfile
  3144. (org-check-agenda-file file)
  3145. (setq date (calendar-gregorian-from-absolute today)
  3146. rtn (org-agenda-get-day-entries
  3147. file date :todo))
  3148. (setq rtnall (append rtnall rtn))))
  3149. (when rtnall
  3150. (insert "All currently open TODO items:\n")
  3151. (add-text-properties (point-min) (1- (point))
  3152. (list 'face 'org-agenda-structure
  3153. 'short-heading "All TODO items"))
  3154. (org-agenda-mark-header-line (point-min))
  3155. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3156. (unless org-agenda-compact-blocks
  3157. (let* ((d1 (car day-numbers))
  3158. (d2 (org-last day-numbers))
  3159. (w1 (org-days-to-iso-week d1))
  3160. (w2 (org-days-to-iso-week d2)))
  3161. (setq s (point))
  3162. (if org-agenda-overriding-header
  3163. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3164. nil 'face 'org-agenda-structure) "\n")
  3165. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3166. "-agenda"
  3167. (if (< (- d2 d1) 350)
  3168. (if (= w1 w2)
  3169. (format " (W%02d)" w1)
  3170. (format " (W%02d-W%02d)" w1 w2))
  3171. "")
  3172. ":\n")))
  3173. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3174. 'org-date-line t))
  3175. (org-agenda-mark-header-line s))
  3176. (while (setq d (pop day-numbers))
  3177. (setq date (calendar-gregorian-from-absolute d)
  3178. s (point))
  3179. (if (or (setq todayp (= d today))
  3180. (and (not start-pos) (= d sd)))
  3181. (setq start-pos (point))
  3182. (if (and start-pos (not end-pos))
  3183. (setq end-pos (point))))
  3184. (setq files thefiles
  3185. rtnall nil)
  3186. (while (setq file (pop files))
  3187. (catch 'nextfile
  3188. (org-check-agenda-file file)
  3189. (let ((org-agenda-entry-types org-agenda-entry-types))
  3190. (unless org-agenda-include-deadlines
  3191. (setq org-agenda-entry-types
  3192. (delq :deadline org-agenda-entry-types)))
  3193. (cond
  3194. ((eq org-agenda-show-log 'only)
  3195. (setq rtn (org-agenda-get-day-entries
  3196. file date :closed)))
  3197. (org-agenda-show-log
  3198. (setq rtn (apply 'org-agenda-get-day-entries
  3199. file date
  3200. (append '(:closed) org-agenda-entry-types))))
  3201. (t
  3202. (setq rtn (apply 'org-agenda-get-day-entries
  3203. file date
  3204. org-agenda-entry-types)))))
  3205. (setq rtnall (append rtnall rtn))))
  3206. (if org-agenda-include-diary
  3207. (let ((org-agenda-search-headline-for-time t))
  3208. (require 'diary-lib)
  3209. (setq rtn (org-get-entries-from-diary date))
  3210. (setq rtnall (append rtnall rtn))))
  3211. (if (or rtnall org-agenda-show-all-dates)
  3212. (progn
  3213. (setq day-cnt (1+ day-cnt))
  3214. (insert
  3215. (if (stringp org-agenda-format-date)
  3216. (format-time-string org-agenda-format-date
  3217. (org-time-from-absolute date))
  3218. (funcall org-agenda-format-date date))
  3219. "\n")
  3220. (put-text-property s (1- (point)) 'face
  3221. (org-agenda-get-day-face date))
  3222. (put-text-property s (1- (point)) 'org-date-line t)
  3223. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3224. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3225. (when todayp
  3226. (put-text-property s (1- (point)) 'org-today t))
  3227. (if rtnall (insert
  3228. (org-finalize-agenda-entries
  3229. (org-agenda-add-time-grid-maybe
  3230. rtnall nd todayp))
  3231. "\n"))
  3232. (put-text-property s (1- (point)) 'day d)
  3233. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3234. (when (and org-agenda-clockreport-mode clocktable-start)
  3235. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3236. ;; the above line is to ensure the restricted range!
  3237. (p org-agenda-clockreport-parameter-plist)
  3238. tbl)
  3239. (setq p (org-plist-delete p :block))
  3240. (setq p (plist-put p :tstart clocktable-start))
  3241. (setq p (plist-put p :tend clocktable-end))
  3242. (setq p (plist-put p :scope 'agenda))
  3243. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3244. (setq filter (or org-agenda-filter-while-redo
  3245. (get 'org-agenda-filter :preset-filter))))
  3246. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3247. (if (string-match "[<>=]" x)
  3248. ""
  3249. x))
  3250. filter ""))))
  3251. (message "%s" (plist-get p :tags)) (sit-for 2)
  3252. (setq tbl (apply 'org-get-clocktable p))
  3253. (insert tbl)))
  3254. (goto-char (point-min))
  3255. (or org-agenda-multi (org-fit-agenda-window))
  3256. (unless (and (pos-visible-in-window-p (point-min))
  3257. (pos-visible-in-window-p (point-max)))
  3258. (goto-char (1- (point-max)))
  3259. (recenter -1)
  3260. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3261. (progn
  3262. (goto-char (or start-pos 1))
  3263. (recenter 1))))
  3264. (goto-char (or start-pos 1))
  3265. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3266. (org-finalize-agenda)
  3267. (setq buffer-read-only t)
  3268. (message "")))
  3269. (defun org-agenda-ndays-to-span (n)
  3270. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3271. ;;; Agenda word search
  3272. (defvar org-agenda-search-history nil)
  3273. (defvar org-todo-only nil)
  3274. (defvar org-search-syntax-table nil
  3275. "Special syntax table for org-mode search.
  3276. In this table, we have single quotes not as word constituents, to
  3277. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3278. (defun org-search-syntax-table ()
  3279. (unless org-search-syntax-table
  3280. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3281. (modify-syntax-entry ?' "." org-search-syntax-table)
  3282. (modify-syntax-entry ?` "." org-search-syntax-table))
  3283. org-search-syntax-table)
  3284. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3285. ;;;###autoload
  3286. (defun org-search-view (&optional todo-only string edit-at)
  3287. "Show all entries that contain a phrase or words or regular expressions.
  3288. With optional prefix argument TODO-ONLY, only consider entries that are
  3289. TODO entries. The argument STRING can be used to pass a default search
  3290. string into this function. If EDIT-AT is non-nil, it means that the
  3291. user should get a chance to edit this string, with cursor at position
  3292. EDIT-AT.
  3293. The search string can be viewed either as a phrase that should be found as
  3294. is, or it can be broken into a number of snippets, each of which must match
  3295. in a Boolean way to select an entry. The default depends on the variable
  3296. `org-agenda-search-view-always-boolean'.
  3297. Even if this is turned off (the default) you can always switch to
  3298. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3299. The default is a direct search of the whole phrase, where each space in
  3300. the search string can expand to an arbitrary amount of whitespace,
  3301. including newlines.
  3302. If using a Boolean search, the search string is split on whitespace and
  3303. each snippet is searched separately, with logical AND to select an entry.
  3304. Words prefixed with a minus must *not* occur in the entry. Words without
  3305. a prefix or prefixed with a plus must occur in the entry. Matching is
  3306. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3307. match whole words, not parts of a word) if
  3308. `org-agenda-search-view-force-full-words' is set (default is nil).
  3309. Boolean search snippets enclosed by curly braces are interpreted as
  3310. regular expressions that must or (when preceded with \"-\") must not
  3311. match in the entry. Snippets enclosed into double quotes will be taken
  3312. as a whole, to include whitespace.
  3313. - If the search string starts with an asterisk, search only in headlines.
  3314. - If (possibly after the leading star) the search string starts with an
  3315. exclamation mark, this also means to look at TODO entries only, an effect
  3316. that can also be achieved with a prefix argument.
  3317. - If (possibly after star and exclamation mark) the search string starts
  3318. with a colon, this will mean that the (non-regexp) snippets of the
  3319. Boolean search must match as full words.
  3320. This command searches the agenda files, and in addition the files listed
  3321. in `org-agenda-text-search-extra-files'."
  3322. (interactive "P")
  3323. (org-compile-prefix-format 'search)
  3324. (org-set-sorting-strategy 'search)
  3325. (org-prepare-agenda "SEARCH")
  3326. (let* ((props (list 'face nil
  3327. 'done-face 'org-agenda-done
  3328. 'org-not-done-regexp org-not-done-regexp
  3329. 'org-todo-regexp org-todo-regexp
  3330. 'org-complex-heading-regexp org-complex-heading-regexp
  3331. 'mouse-face 'highlight
  3332. 'help-echo (format "mouse-2 or RET jump to location")))
  3333. (full-words org-agenda-search-view-force-full-words)
  3334. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3335. regexp rtn rtnall files file pos
  3336. marker category tags c neg re boolean
  3337. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3338. (unless (and (not edit-at)
  3339. (stringp string)
  3340. (string-match "\\S-" string))
  3341. (setq string (read-string
  3342. (if org-agenda-search-view-always-boolean
  3343. "[+-]Word/{Regexp} ...: "
  3344. "Phrase, or [+-]Word/{Regexp} ...: ")
  3345. (cond
  3346. ((integerp edit-at) (cons string edit-at))
  3347. (edit-at string))
  3348. 'org-agenda-search-history)))
  3349. (org-set-local 'org-todo-only todo-only)
  3350. (setq org-agenda-redo-command
  3351. (list 'org-search-view (if todo-only t nil) string
  3352. '(if current-prefix-arg 1 nil)))
  3353. (setq org-agenda-query-string string)
  3354. (if (equal (string-to-char string) ?*)
  3355. (setq hdl-only t
  3356. words (substring string 1))
  3357. (setq words string))
  3358. (when (equal (string-to-char words) ?!)
  3359. (setq todo-only t
  3360. words (substring words 1)))
  3361. (when (equal (string-to-char words) ?:)
  3362. (setq full-words t
  3363. words (substring words 1)))
  3364. (if (or org-agenda-search-view-always-boolean
  3365. (member (string-to-char words) '(?- ?+ ?\{)))
  3366. (setq boolean t))
  3367. (setq words (org-split-string words))
  3368. (let (www w)
  3369. (while (setq w (pop words))
  3370. (while (and (string-match "\\\\\\'" w) words)
  3371. (setq w (concat (substring w 0 -1) " " (pop words))))
  3372. (push w www))
  3373. (setq words (nreverse www) www nil)
  3374. (while (setq w (pop words))
  3375. (when (and (string-match "\\`[-+]?{" w)
  3376. (not (string-match "}\\'" w)))
  3377. (while (and words (not (string-match "}\\'" (car words))))
  3378. (setq w (concat w " " (pop words))))
  3379. (setq w (concat w " " (pop words))))
  3380. (push w www))
  3381. (setq words (nreverse www)))
  3382. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3383. (when boolean
  3384. (let (wds w)
  3385. (while (setq w (pop words))
  3386. (if (or (equal (substring w 0 1) "\"")
  3387. (and (> (length w) 1)
  3388. (member (substring w 0 1) '("+" "-"))
  3389. (equal (substring w 1 2) "\"")))
  3390. (while (and words (not (equal (substring w -1) "\"")))
  3391. (setq w (concat w " " (pop words)))))
  3392. (and (string-match "\\`\\([-+]?\\)\"" w)
  3393. (setq w (replace-match "\\1" nil nil w)))
  3394. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3395. (push w wds))
  3396. (setq words (nreverse wds))))
  3397. (if boolean
  3398. (mapc (lambda (w)
  3399. (setq c (string-to-char w))
  3400. (if (equal c ?-)
  3401. (setq neg t w (substring w 1))
  3402. (if (equal c ?+)
  3403. (setq neg nil w (substring w 1))
  3404. (setq neg nil)))
  3405. (if (string-match "\\`{.*}\\'" w)
  3406. (setq re (substring w 1 -1))
  3407. (if full-words
  3408. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3409. (setq re (regexp-quote (downcase w)))))
  3410. (if neg (push re regexps-) (push re regexps+)))
  3411. words)
  3412. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3413. regexps+))
  3414. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3415. (if (not regexps+)
  3416. (setq regexp (concat "^" org-outline-regexp))
  3417. (setq regexp (pop regexps+))
  3418. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3419. regexp))))
  3420. (setq files (org-agenda-files nil 'ifmode))
  3421. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3422. (pop org-agenda-text-search-extra-files)
  3423. (setq files (org-add-archive-files files)))
  3424. (setq files (append files org-agenda-text-search-extra-files)
  3425. rtnall nil)
  3426. (while (setq file (pop files))
  3427. (setq ee nil)
  3428. (catch 'nextfile
  3429. (org-check-agenda-file file)
  3430. (setq buffer (if (file-exists-p file)
  3431. (org-get-agenda-file-buffer file)
  3432. (error "No such file %s" file)))
  3433. (if (not buffer)
  3434. ;; If file does not exist, make sure an error message is sent
  3435. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3436. file))))
  3437. (with-current-buffer buffer
  3438. (with-syntax-table (org-search-syntax-table)
  3439. (unless (org-mode-p)
  3440. (error "Agenda file %s is not in `org-mode'" file))
  3441. (let ((case-fold-search t))
  3442. (save-excursion
  3443. (save-restriction
  3444. (if org-agenda-restrict
  3445. (narrow-to-region org-agenda-restrict-begin
  3446. org-agenda-restrict-end)
  3447. (widen))
  3448. (goto-char (point-min))
  3449. (unless (or (org-on-heading-p)
  3450. (outline-next-heading))
  3451. (throw 'nextfile t))
  3452. (goto-char (max (point-min) (1- (point))))
  3453. (while (re-search-forward regexp nil t)
  3454. (org-back-to-heading t)
  3455. (skip-chars-forward "* ")
  3456. (setq beg (point-at-bol)
  3457. beg1 (point)
  3458. end (progn (outline-next-heading) (point)))
  3459. (catch :skip
  3460. (goto-char beg)
  3461. (org-agenda-skip)
  3462. (setq str (buffer-substring-no-properties
  3463. (point-at-bol)
  3464. (if hdl-only (point-at-eol) end)))
  3465. (mapc (lambda (wr) (when (string-match wr str)
  3466. (goto-char (1- end))
  3467. (throw :skip t)))
  3468. regexps-)
  3469. (mapc (lambda (wr) (unless (string-match wr str)
  3470. (goto-char (1- end))
  3471. (throw :skip t)))
  3472. (if todo-only
  3473. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3474. regexps+)
  3475. regexps+))
  3476. (goto-char beg)
  3477. (setq marker (org-agenda-new-marker (point))
  3478. category (org-get-category)
  3479. tags (org-get-tags-at (point))
  3480. txt (org-format-agenda-item
  3481. ""
  3482. (buffer-substring-no-properties
  3483. beg1 (point-at-eol))
  3484. category tags))
  3485. (org-add-props txt props
  3486. 'org-marker marker 'org-hd-marker marker
  3487. 'org-todo-regexp org-todo-regexp
  3488. 'org-complex-heading-regexp org-complex-heading-regexp
  3489. 'priority 1000 'org-category category
  3490. 'type "search")
  3491. (push txt ee)
  3492. (goto-char (1- end))))))))))
  3493. (setq rtn (nreverse ee))
  3494. (setq rtnall (append rtnall rtn)))
  3495. (if org-agenda-overriding-header
  3496. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3497. nil 'face 'org-agenda-structure) "\n")
  3498. (insert "Search words: ")
  3499. (add-text-properties (point-min) (1- (point))
  3500. (list 'face 'org-agenda-structure))
  3501. (setq pos (point))
  3502. (insert string "\n")
  3503. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3504. (setq pos (point))
  3505. (unless org-agenda-multi
  3506. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3507. (add-text-properties pos (1- (point))
  3508. (list 'face 'org-agenda-structure))))
  3509. (org-agenda-mark-header-line (point-min))
  3510. (when rtnall
  3511. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3512. (goto-char (point-min))
  3513. (or org-agenda-multi (org-fit-agenda-window))
  3514. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3515. (org-finalize-agenda)
  3516. (setq buffer-read-only t)))
  3517. ;;; Agenda TODO list
  3518. (defvar org-select-this-todo-keyword nil)
  3519. (defvar org-last-arg nil)
  3520. ;;;###autoload
  3521. (defun org-todo-list (arg)
  3522. "Show all (not done) TODO entries from all agenda file in a single list.
  3523. The prefix arg can be used to select a specific TODO keyword and limit
  3524. the list to these. When using \\[universal-argument], you will be prompted
  3525. for a keyword. A numeric prefix directly selects the Nth keyword in
  3526. `org-todo-keywords-1'."
  3527. (interactive "P")
  3528. (org-compile-prefix-format 'todo)
  3529. (org-set-sorting-strategy 'todo)
  3530. (org-prepare-agenda "TODO")
  3531. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3532. (let* ((today (org-agenda-today))
  3533. (date (calendar-gregorian-from-absolute today))
  3534. (kwds org-todo-keywords-for-agenda)
  3535. (completion-ignore-case t)
  3536. (org-select-this-todo-keyword
  3537. (if (stringp arg) arg
  3538. (and arg (integerp arg) (> arg 0)
  3539. (nth (1- arg) kwds))))
  3540. rtn rtnall files file pos)
  3541. (when (equal arg '(4))
  3542. (setq org-select-this-todo-keyword
  3543. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3544. (mapcar 'list kwds) nil nil)))
  3545. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3546. (org-set-local 'org-last-arg arg)
  3547. (setq org-agenda-redo-command
  3548. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3549. (setq files (org-agenda-files nil 'ifmode)
  3550. rtnall nil)
  3551. (while (setq file (pop files))
  3552. (catch 'nextfile
  3553. (org-check-agenda-file file)
  3554. (setq rtn (org-agenda-get-day-entries file date :todo))
  3555. (setq rtnall (append rtnall rtn))))
  3556. (if org-agenda-overriding-header
  3557. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3558. nil 'face 'org-agenda-structure) "\n")
  3559. (insert "Global list of TODO items of type: ")
  3560. (add-text-properties (point-min) (1- (point))
  3561. (list 'face 'org-agenda-structure
  3562. 'short-heading
  3563. (concat "ToDo: "
  3564. (or org-select-this-todo-keyword "ALL"))))
  3565. (org-agenda-mark-header-line (point-min))
  3566. (setq pos (point))
  3567. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3568. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3569. (setq pos (point))
  3570. (unless org-agenda-multi
  3571. (insert "Available with `N r': (0)ALL")
  3572. (let ((n 0) s)
  3573. (mapc (lambda (x)
  3574. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3575. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3576. (insert "\n "))
  3577. (insert " " s))
  3578. kwds))
  3579. (insert "\n"))
  3580. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3581. (org-agenda-mark-header-line (point-min))
  3582. (when rtnall
  3583. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3584. (goto-char (point-min))
  3585. (or org-agenda-multi (org-fit-agenda-window))
  3586. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3587. (org-finalize-agenda)
  3588. (setq buffer-read-only t)))
  3589. ;;; Agenda tags match
  3590. ;;;###autoload
  3591. (defun org-tags-view (&optional todo-only match)
  3592. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3593. The prefix arg TODO-ONLY limits the search to TODO entries."
  3594. (interactive "P")
  3595. (org-compile-prefix-format 'tags)
  3596. (org-set-sorting-strategy 'tags)
  3597. (let* ((org-tags-match-list-sublevels
  3598. org-tags-match-list-sublevels)
  3599. (completion-ignore-case t)
  3600. rtn rtnall files file pos matcher
  3601. buffer)
  3602. (when (and (stringp match) (not (string-match "\\S-" match)))
  3603. (setq match nil))
  3604. (setq matcher (org-make-tags-matcher match)
  3605. match (car matcher) matcher (cdr matcher))
  3606. (org-prepare-agenda (concat "TAGS " match))
  3607. (setq org-agenda-query-string match)
  3608. (setq org-agenda-redo-command
  3609. (list 'org-tags-view (list 'quote todo-only)
  3610. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3611. (setq files (org-agenda-files nil 'ifmode)
  3612. rtnall nil)
  3613. (while (setq file (pop files))
  3614. (catch 'nextfile
  3615. (org-check-agenda-file file)
  3616. (setq buffer (if (file-exists-p file)
  3617. (org-get-agenda-file-buffer file)
  3618. (error "No such file %s" file)))
  3619. (if (not buffer)
  3620. ;; If file does not exist, error message to agenda
  3621. (setq rtn (list
  3622. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3623. rtnall (append rtnall rtn))
  3624. (with-current-buffer buffer
  3625. (unless (org-mode-p)
  3626. (error "Agenda file %s is not in `org-mode'" file))
  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. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3634. (setq rtnall (append rtnall rtn))))))))
  3635. (if org-agenda-overriding-header
  3636. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3637. nil 'face 'org-agenda-structure) "\n")
  3638. (insert "Headlines with TAGS match: ")
  3639. (add-text-properties (point-min) (1- (point))
  3640. (list 'face 'org-agenda-structure
  3641. 'short-heading
  3642. (concat "Match: " match)))
  3643. (setq pos (point))
  3644. (insert match "\n")
  3645. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3646. (setq pos (point))
  3647. (unless org-agenda-multi
  3648. (insert "Press `C-u r' to search again with new search string\n"))
  3649. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3650. (org-agenda-mark-header-line (point-min))
  3651. (when rtnall
  3652. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3653. (goto-char (point-min))
  3654. (or org-agenda-multi (org-fit-agenda-window))
  3655. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3656. (org-finalize-agenda)
  3657. (setq buffer-read-only t)))
  3658. ;;; Agenda Finding stuck projects
  3659. (defvar org-agenda-skip-regexp nil
  3660. "Regular expression used in skipping subtrees for the agenda.
  3661. This is basically a temporary global variable that can be set and then
  3662. used by user-defined selections using `org-agenda-skip-function'.")
  3663. (defvar org-agenda-overriding-header nil
  3664. "When this is set during todo and tags searches, will replace header.
  3665. This variable should not be set directly, but custom commands can bind it
  3666. in the options section.")
  3667. (defun org-agenda-skip-entry-when-regexp-matches ()
  3668. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3669. If yes, it returns the end position of this entry, causing agenda commands
  3670. to skip the entry but continuing the search in the subtree. This is a
  3671. function that can be put into `org-agenda-skip-function' for the duration
  3672. of a command."
  3673. (let ((end (save-excursion (org-end-of-subtree t)))
  3674. skip)
  3675. (save-excursion
  3676. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3677. (and skip end)))
  3678. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3679. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3680. If yes, it returns the end position of this tree, causing agenda commands
  3681. to skip this subtree. This is a function that can be put into
  3682. `org-agenda-skip-function' for the duration of a command."
  3683. (let ((end (save-excursion (org-end-of-subtree t)))
  3684. skip)
  3685. (save-excursion
  3686. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3687. (and skip end)))
  3688. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3689. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3690. If yes, it returns the end position of the current entry (NOT the tree),
  3691. causing agenda commands to skip the entry but continuing the search in
  3692. the subtree. This is a function that can be put into
  3693. `org-agenda-skip-function' for the duration of a command. An important
  3694. use of this function is for the stuck project list."
  3695. (let ((end (save-excursion (org-end-of-subtree t)))
  3696. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3697. skip)
  3698. (save-excursion
  3699. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3700. (and skip entry-end)))
  3701. (defun org-agenda-skip-entry-if (&rest conditions)
  3702. "Skip entry if any of CONDITIONS is true.
  3703. See `org-agenda-skip-if' for details."
  3704. (org-agenda-skip-if nil conditions))
  3705. (defun org-agenda-skip-subtree-if (&rest conditions)
  3706. "Skip entry if any of CONDITIONS is true.
  3707. See `org-agenda-skip-if' for details."
  3708. (org-agenda-skip-if t conditions))
  3709. (defun org-agenda-skip-if (subtree conditions)
  3710. "Checks current entity for CONDITIONS.
  3711. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3712. the entry, i.e. the text before the next heading is checked.
  3713. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3714. from different tests. Valid conditions are:
  3715. scheduled Check if there is a scheduled cookie
  3716. notscheduled Check if there is no scheduled cookie
  3717. deadline Check if there is a deadline
  3718. notdeadline Check if there is no deadline
  3719. timestamp Check if there is a timestamp (also deadline or scheduled)
  3720. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3721. regexp Check if regexp matches
  3722. notregexp Check if regexp does not match.
  3723. todo Check if TODO keyword matches
  3724. nottodo Check if TODO keyword does not match
  3725. The regexp is taken from the conditions list, it must come right after
  3726. the `regexp' or `notregexp' element.
  3727. `todo' and `nottodo' accept as an argument a list of todo
  3728. keywords, which may include \"*\" to match any todo keyword.
  3729. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3730. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3731. Instead of a list a keyword class may be given
  3732. (org-agenda-skip-entry-if 'nottodo 'done)
  3733. would skip entries that haven't been marked with any of \"DONE\"
  3734. keywords. Possible classes are: `todo', `done', `any'.
  3735. If any of these conditions is met, this function returns the end point of
  3736. the entity, causing the search to continue from there. This is a function
  3737. that can be put into `org-agenda-skip-function' for the duration of a command."
  3738. (let (beg end m)
  3739. (org-back-to-heading t)
  3740. (setq beg (point)
  3741. end (if subtree
  3742. (progn (org-end-of-subtree t) (point))
  3743. (progn (outline-next-heading) (1- (point)))))
  3744. (goto-char beg)
  3745. (and
  3746. (or
  3747. (and (memq 'scheduled conditions)
  3748. (re-search-forward org-scheduled-time-regexp end t))
  3749. (and (memq 'notscheduled conditions)
  3750. (not (re-search-forward org-scheduled-time-regexp end t)))
  3751. (and (memq 'deadline conditions)
  3752. (re-search-forward org-deadline-time-regexp end t))
  3753. (and (memq 'notdeadline conditions)
  3754. (not (re-search-forward org-deadline-time-regexp end t)))
  3755. (and (memq 'timestamp conditions)
  3756. (re-search-forward org-ts-regexp end t))
  3757. (and (memq 'nottimestamp conditions)
  3758. (not (re-search-forward org-ts-regexp end t)))
  3759. (and (setq m (memq 'regexp conditions))
  3760. (stringp (nth 1 m))
  3761. (re-search-forward (nth 1 m) end t))
  3762. (and (setq m (memq 'notregexp conditions))
  3763. (stringp (nth 1 m))
  3764. (not (re-search-forward (nth 1 m) end t)))
  3765. (and (or
  3766. (setq m (memq 'todo conditions))
  3767. (setq m (memq 'nottodo conditions)))
  3768. (org-agenda-skip-if-todo m end)))
  3769. end)))
  3770. (defun org-agenda-skip-if-todo (args end)
  3771. "Helper function for `org-agenda-skip-if', do not use it directly.
  3772. ARGS is a list with first element either `todo' or `nottodo'.
  3773. The remainder is either a list of TODO keywords, or a state symbol
  3774. `todo' or `done' or `any'."
  3775. (let ((kw (car args))
  3776. (arg (cadr args))
  3777. todo-wds todo-re)
  3778. (setq todo-wds
  3779. (org-uniquify
  3780. (cond
  3781. ((listp arg) ;; list of keywords
  3782. (if (member "*" arg)
  3783. (mapcar 'substring-no-properties org-todo-keywords-1)
  3784. arg))
  3785. ((symbolp arg) ;; keyword class name
  3786. (cond
  3787. ((eq arg 'todo)
  3788. (org-delete-all org-done-keywords
  3789. (mapcar 'substring-no-properties
  3790. org-todo-keywords-1)))
  3791. ((eq arg 'done) org-done-keywords)
  3792. ((eq arg 'any)
  3793. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3794. (setq todo-re
  3795. (concat "^\\*+[ \t]+\\<\\("
  3796. (mapconcat 'identity todo-wds "\\|")
  3797. "\\)\\>"))
  3798. (if (eq kw 'todo)
  3799. (re-search-forward todo-re end t)
  3800. (not (re-search-forward todo-re end t)))))
  3801. ;;;###autoload
  3802. (defun org-agenda-list-stuck-projects (&rest ignore)
  3803. "Create agenda view for projects that are stuck.
  3804. Stuck projects are project that have no next actions. For the definitions
  3805. of what a project is and how to check if it stuck, customize the variable
  3806. `org-stuck-projects'."
  3807. (interactive)
  3808. (let* ((org-agenda-skip-function
  3809. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3810. ;; We could have used org-agenda-skip-if here.
  3811. (org-agenda-overriding-header
  3812. (or org-agenda-overriding-header "List of stuck projects: "))
  3813. (matcher (nth 0 org-stuck-projects))
  3814. (todo (nth 1 org-stuck-projects))
  3815. (todo-wds (if (member "*" todo)
  3816. (progn
  3817. (org-prepare-agenda-buffers (org-agenda-files
  3818. nil 'ifmode))
  3819. (org-delete-all
  3820. org-done-keywords-for-agenda
  3821. (copy-sequence org-todo-keywords-for-agenda)))
  3822. todo))
  3823. (todo-re (concat "^\\*+[ \t]+\\("
  3824. (mapconcat 'identity todo-wds "\\|")
  3825. "\\)\\>"))
  3826. (tags (nth 2 org-stuck-projects))
  3827. (tags-re (if (member "*" tags)
  3828. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3829. (if tags
  3830. (concat "^\\*+ .*:\\("
  3831. (mapconcat 'identity tags "\\|")
  3832. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3833. (gen-re (nth 3 org-stuck-projects))
  3834. (re-list
  3835. (delq nil
  3836. (list
  3837. (if todo todo-re)
  3838. (if tags tags-re)
  3839. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3840. gen-re)))))
  3841. (setq org-agenda-skip-regexp
  3842. (if re-list
  3843. (mapconcat 'identity re-list "\\|")
  3844. (error "No information how to identify unstuck projects")))
  3845. (org-tags-view nil matcher)
  3846. (with-current-buffer org-agenda-buffer-name
  3847. (setq org-agenda-redo-command
  3848. '(org-agenda-list-stuck-projects
  3849. (or current-prefix-arg org-last-arg))))))
  3850. ;;; Diary integration
  3851. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3852. (defvar list-diary-entries-hook)
  3853. (defun org-get-entries-from-diary (date)
  3854. "Get the (Emacs Calendar) diary entries for DATE."
  3855. (require 'diary-lib)
  3856. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3857. (diary-display-hook '(fancy-diary-display))
  3858. (diary-display-function 'fancy-diary-display)
  3859. (pop-up-frames nil)
  3860. (list-diary-entries-hook
  3861. (cons 'org-diary-default-entry list-diary-entries-hook))
  3862. (diary-file-name-prefix-function nil) ; turn this feature off
  3863. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3864. entries
  3865. (org-disable-agenda-to-diary t))
  3866. (save-excursion
  3867. (save-window-excursion
  3868. (funcall (if (fboundp 'diary-list-entries)
  3869. 'diary-list-entries 'list-diary-entries)
  3870. date 1)))
  3871. (if (not (get-buffer diary-fancy-buffer))
  3872. (setq entries nil)
  3873. (with-current-buffer diary-fancy-buffer
  3874. (setq buffer-read-only nil)
  3875. (if (zerop (buffer-size))
  3876. ;; No entries
  3877. (setq entries nil)
  3878. ;; Omit the date and other unnecessary stuff
  3879. (org-agenda-cleanup-fancy-diary)
  3880. ;; Add prefix to each line and extend the text properties
  3881. (if (zerop (buffer-size))
  3882. (setq entries nil)
  3883. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3884. (set-buffer-modified-p nil)
  3885. (kill-buffer diary-fancy-buffer)))
  3886. (when entries
  3887. (setq entries (org-split-string entries "\n"))
  3888. (setq entries
  3889. (mapcar
  3890. (lambda (x)
  3891. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3892. ;; Extend the text properties to the beginning of the line
  3893. (org-add-props x (text-properties-at (1- (length x)) x)
  3894. 'type "diary" 'date date 'face 'org-agenda-diary))
  3895. entries)))))
  3896. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3897. "Hook run when the fancy diary buffer is cleaned up.")
  3898. (defun org-agenda-cleanup-fancy-diary ()
  3899. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3900. This gets rid of the date, the underline under the date, and
  3901. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3902. date. It also removes lines that contain only whitespace."
  3903. (goto-char (point-min))
  3904. (if (looking-at ".*?:[ \t]*")
  3905. (progn
  3906. (replace-match "")
  3907. (re-search-forward "\n=+$" nil t)
  3908. (replace-match "")
  3909. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3910. (re-search-forward "\n=+$" nil t)
  3911. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3912. (goto-char (point-min))
  3913. (while (re-search-forward "^ +\n" nil t)
  3914. (replace-match ""))
  3915. (goto-char (point-min))
  3916. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3917. (replace-match ""))
  3918. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3919. ;; Make sure entries from the diary have the right text properties.
  3920. (eval-after-load "diary-lib"
  3921. '(if (boundp 'diary-modify-entry-list-string-function)
  3922. ;; We can rely on the hook, nothing to do
  3923. nil
  3924. ;; Hook not available, must use advice to make this work
  3925. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3926. "Make the position visible."
  3927. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3928. (stringp string)
  3929. buffer-file-name)
  3930. (setq string (org-modify-diary-entry-string string))))))
  3931. (defun org-modify-diary-entry-string (string)
  3932. "Add text properties to string, allowing org-mode to act on it."
  3933. (org-add-props string nil
  3934. 'mouse-face 'highlight
  3935. 'help-echo (if buffer-file-name
  3936. (format "mouse-2 or RET jump to diary file %s"
  3937. (abbreviate-file-name buffer-file-name))
  3938. "")
  3939. 'org-agenda-diary-link t
  3940. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3941. (defun org-diary-default-entry ()
  3942. "Add a dummy entry to the diary.
  3943. Needed to avoid empty dates which mess up holiday display."
  3944. ;; Catch the error if dealing with the new add-to-diary-alist
  3945. (when org-disable-agenda-to-diary
  3946. (condition-case nil
  3947. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3948. (error
  3949. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3950. (defun org-add-to-diary-list (&rest args)
  3951. (if (fboundp 'diary-add-to-list)
  3952. (apply 'diary-add-to-list args)
  3953. (apply 'add-to-diary-list args)))
  3954. (defvar org-diary-last-run-time nil)
  3955. ;;;###autoload
  3956. (defun org-diary (&rest args)
  3957. "Return diary information from org-files.
  3958. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3959. It accesses org files and extracts information from those files to be
  3960. listed in the diary. The function accepts arguments specifying what
  3961. items should be listed. For a list of arguments allowed here, see the
  3962. variable `org-agenda-entry-types'.
  3963. The call in the diary file should look like this:
  3964. &%%(org-diary) ~/path/to/some/orgfile.org
  3965. Use a separate line for each org file to check. Or, if you omit the file name,
  3966. all files listed in `org-agenda-files' will be checked automatically:
  3967. &%%(org-diary)
  3968. If you don't give any arguments (as in the example above), the default
  3969. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3970. So the example above may also be written as
  3971. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3972. The function expects the lisp variables `entry' and `date' to be provided
  3973. by the caller, because this is how the calendar works. Don't use this
  3974. function from a program - use `org-agenda-get-day-entries' instead."
  3975. (when (> (- (org-float-time)
  3976. org-agenda-last-marker-time)
  3977. 5)
  3978. (org-agenda-reset-markers))
  3979. (org-compile-prefix-format 'agenda)
  3980. (org-set-sorting-strategy 'agenda)
  3981. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3982. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3983. (list entry)
  3984. (org-agenda-files t)))
  3985. (time (org-float-time))
  3986. file rtn results)
  3987. (when (or (not org-diary-last-run-time)
  3988. (> (- time
  3989. org-diary-last-run-time)
  3990. 3))
  3991. (org-prepare-agenda-buffers files))
  3992. (setq org-diary-last-run-time time)
  3993. ;; If this is called during org-agenda, don't return any entries to
  3994. ;; the calendar. Org Agenda will list these entries itself.
  3995. (if org-disable-agenda-to-diary (setq files nil))
  3996. (while (setq file (pop files))
  3997. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3998. (setq results (append results rtn)))
  3999. (if results
  4000. (concat (org-finalize-agenda-entries results) "\n"))))
  4001. ;;; Agenda entry finders
  4002. (defun org-agenda-get-day-entries (file date &rest args)
  4003. "Does the work for `org-diary' and `org-agenda'.
  4004. FILE is the path to a file to be checked for entries. DATE is date like
  4005. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4006. which kind of entries should be extracted. For details about these, see
  4007. the documentation of `org-diary'."
  4008. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4009. (let* ((org-startup-folded nil)
  4010. (org-startup-align-all-tables nil)
  4011. (buffer (if (file-exists-p file)
  4012. (org-get-agenda-file-buffer file)
  4013. (error "No such file %s" file)))
  4014. arg results rtn deadline-results)
  4015. (if (not buffer)
  4016. ;; If file does not exist, make sure an error message ends up in diary
  4017. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4018. (with-current-buffer buffer
  4019. (unless (org-mode-p)
  4020. (error "Agenda file %s is not in `org-mode'" file))
  4021. (let ((case-fold-search nil))
  4022. (save-excursion
  4023. (save-restriction
  4024. (if org-agenda-restrict
  4025. (narrow-to-region org-agenda-restrict-begin
  4026. org-agenda-restrict-end)
  4027. (widen))
  4028. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4029. (while (setq arg (pop args))
  4030. (cond
  4031. ((and (eq arg :todo)
  4032. (equal date (calendar-current-date)))
  4033. (setq rtn (org-agenda-get-todos))
  4034. (setq results (append results rtn)))
  4035. ((eq arg :timestamp)
  4036. (setq rtn (org-agenda-get-blocks))
  4037. (setq results (append results rtn))
  4038. (setq rtn (org-agenda-get-timestamps))
  4039. (setq results (append results rtn)))
  4040. ((eq arg :sexp)
  4041. (setq rtn (org-agenda-get-sexps))
  4042. (setq results (append results rtn)))
  4043. ((eq arg :scheduled)
  4044. (setq rtn (org-agenda-get-scheduled deadline-results))
  4045. (setq results (append results rtn)))
  4046. ((eq arg :closed)
  4047. (setq rtn (org-agenda-get-progress))
  4048. (setq results (append results rtn)))
  4049. ((eq arg :deadline)
  4050. (setq rtn (org-agenda-get-deadlines))
  4051. (setq deadline-results (copy-sequence rtn))
  4052. (setq results (append results rtn))))))))
  4053. results))))
  4054. (defun org-agenda-get-todos ()
  4055. "Return the TODO information for agenda display."
  4056. (let* ((props (list 'face nil
  4057. 'done-face 'org-agenda-done
  4058. 'org-not-done-regexp org-not-done-regexp
  4059. 'org-todo-regexp org-todo-regexp
  4060. 'org-complex-heading-regexp org-complex-heading-regexp
  4061. 'mouse-face 'highlight
  4062. 'help-echo
  4063. (format "mouse-2 or RET jump to org file %s"
  4064. (abbreviate-file-name buffer-file-name))))
  4065. (regexp (concat "^\\*+[ \t]+\\("
  4066. (if org-select-this-todo-keyword
  4067. (if (equal org-select-this-todo-keyword "*")
  4068. org-todo-regexp
  4069. (concat "\\<\\("
  4070. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4071. "\\)\\>"))
  4072. org-not-done-regexp)
  4073. "[^\n\r]*\\)"))
  4074. marker priority category tags todo-state
  4075. ee txt beg end)
  4076. (goto-char (point-min))
  4077. (while (re-search-forward regexp nil t)
  4078. (catch :skip
  4079. (save-match-data
  4080. (beginning-of-line)
  4081. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4082. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4083. (goto-char (1+ beg))
  4084. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4085. (throw :skip nil)))
  4086. (goto-char beg)
  4087. (org-agenda-skip)
  4088. (goto-char (match-beginning 1))
  4089. (setq marker (org-agenda-new-marker (match-beginning 0))
  4090. category (org-get-category)
  4091. txt (match-string 1)
  4092. tags (org-get-tags-at (point))
  4093. txt (org-format-agenda-item "" txt category tags)
  4094. priority (1+ (org-get-priority txt))
  4095. todo-state (org-get-todo-state))
  4096. (org-add-props txt props
  4097. 'org-marker marker 'org-hd-marker marker
  4098. 'priority priority 'org-category category
  4099. 'type "todo" 'todo-state todo-state)
  4100. (push txt ee)
  4101. (if org-agenda-todo-list-sublevels
  4102. (goto-char (match-end 1))
  4103. (org-end-of-subtree 'invisible))))
  4104. (nreverse ee)))
  4105. ;;;###autoload
  4106. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4107. (&optional end)
  4108. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4109. (when (or org-agenda-todo-ignore-with-date
  4110. org-agenda-todo-ignore-scheduled
  4111. org-agenda-todo-ignore-deadlines
  4112. org-agenda-todo-ignore-timestamp)
  4113. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4114. (save-excursion
  4115. (or (and org-agenda-todo-ignore-with-date
  4116. (re-search-forward org-ts-regexp end t))
  4117. (and org-agenda-todo-ignore-scheduled
  4118. (re-search-forward org-scheduled-time-regexp end t)
  4119. (cond
  4120. ((eq org-agenda-todo-ignore-scheduled 'future)
  4121. (> (org-days-to-time (match-string 1)) 0))
  4122. ((eq org-agenda-todo-ignore-scheduled 'past)
  4123. (<= (org-days-to-time (match-string 1)) 0))
  4124. (t)))
  4125. (and org-agenda-todo-ignore-deadlines
  4126. (re-search-forward org-deadline-time-regexp end t)
  4127. (cond
  4128. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4129. ((eq org-agenda-todo-ignore-deadlines 'far)
  4130. (not (org-deadline-close (match-string 1))))
  4131. ((eq org-agenda-todo-ignore-deadlines 'future)
  4132. (> (org-days-to-time (match-string 1)) 0))
  4133. ((eq org-agenda-todo-ignore-deadlines 'past)
  4134. (<= (org-days-to-time (match-string 1)) 0))
  4135. (t (org-deadline-close (match-string 1)))))
  4136. (and org-agenda-todo-ignore-timestamp
  4137. (let ((buffer (current-buffer))
  4138. (regexp
  4139. (concat
  4140. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4141. (start (point)))
  4142. ;; Copy current buffer into a temporary one
  4143. (with-temp-buffer
  4144. (insert-buffer-substring buffer start end)
  4145. (goto-char (point-min))
  4146. ;; Delete SCHEDULED and DEADLINE items
  4147. (while (re-search-forward regexp end t)
  4148. (delete-region (match-beginning 0) (match-end 0)))
  4149. (goto-char (point-min))
  4150. ;; No search for timestamp left
  4151. (when (re-search-forward org-ts-regexp nil t)
  4152. (cond
  4153. ((eq org-agenda-todo-ignore-timestamp 'future)
  4154. (> (org-days-to-time (match-string 1)) 0))
  4155. ((eq org-agenda-todo-ignore-timestamp 'past)
  4156. (<= (org-days-to-time (match-string 1)) 0))
  4157. (t))))))))))
  4158. (defconst org-agenda-no-heading-message
  4159. "No heading for this item in buffer or region.")
  4160. (defun org-agenda-get-timestamps ()
  4161. "Return the date stamp information for agenda display."
  4162. (let* ((props (list 'face nil
  4163. 'org-not-done-regexp org-not-done-regexp
  4164. 'org-todo-regexp org-todo-regexp
  4165. 'org-complex-heading-regexp org-complex-heading-regexp
  4166. 'mouse-face 'highlight
  4167. 'help-echo
  4168. (format "mouse-2 or RET jump to org file %s"
  4169. (abbreviate-file-name buffer-file-name))))
  4170. (d1 (calendar-absolute-from-gregorian date))
  4171. (remove-re
  4172. (concat
  4173. (regexp-quote
  4174. (format-time-string
  4175. "<%Y-%m-%d"
  4176. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4177. ".*?>"))
  4178. (regexp
  4179. (concat
  4180. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4181. (regexp-quote
  4182. (substring
  4183. (format-time-string
  4184. (car org-time-stamp-formats)
  4185. (apply 'encode-time ; DATE bound by calendar
  4186. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4187. 1 11))
  4188. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4189. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4190. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4191. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4192. todo-state end-of-match)
  4193. (goto-char (point-min))
  4194. (while (setq end-of-match (re-search-forward regexp nil t))
  4195. (setq b0 (match-beginning 0)
  4196. b3 (match-beginning 3) e3 (match-end 3))
  4197. (catch :skip
  4198. (and (org-at-date-range-p) (throw :skip nil))
  4199. (org-agenda-skip)
  4200. (if (and (match-end 1)
  4201. (not (= d1 (org-time-string-to-absolute
  4202. (match-string 1) d1 nil
  4203. org-agenda-repeating-timestamp-show-all))))
  4204. (throw :skip nil))
  4205. (if (and e3
  4206. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4207. (throw :skip nil))
  4208. (setq tmp (buffer-substring (max (point-min)
  4209. (- b0 org-ds-keyword-length))
  4210. b0)
  4211. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4212. inactivep (= (char-after b0) ?\[)
  4213. deadlinep (string-match org-deadline-regexp tmp)
  4214. scheduledp (string-match org-scheduled-regexp tmp)
  4215. closedp (and org-agenda-include-inactive-timestamps
  4216. (string-match org-closed-string tmp))
  4217. clockp (and org-agenda-include-inactive-timestamps
  4218. (or (string-match org-clock-string tmp)
  4219. (string-match "]-+\\'" tmp)))
  4220. todo-state (ignore-errors (org-get-todo-state))
  4221. donep (member todo-state org-done-keywords))
  4222. (if (or scheduledp deadlinep closedp clockp
  4223. (and donep org-agenda-skip-timestamp-if-done))
  4224. (throw :skip t))
  4225. (if (string-match ">" timestr)
  4226. ;; substring should only run to end of time stamp
  4227. (setq timestr (substring timestr 0 (match-end 0))))
  4228. (setq marker (org-agenda-new-marker b0)
  4229. category (org-get-category b0))
  4230. (save-excursion
  4231. (if (not (re-search-backward "^\\*+ " nil t))
  4232. (setq txt org-agenda-no-heading-message)
  4233. (goto-char (match-beginning 0))
  4234. (setq hdmarker (org-agenda-new-marker)
  4235. tags (org-get-tags-at))
  4236. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4237. (setq head (match-string 1))
  4238. (setq txt (org-format-agenda-item
  4239. (if inactivep org-agenda-inactive-leader nil)
  4240. head category tags timestr nil
  4241. remove-re)))
  4242. (setq priority (org-get-priority txt))
  4243. (org-add-props txt props
  4244. 'org-marker marker 'org-hd-marker hdmarker)
  4245. (org-add-props txt nil 'priority priority
  4246. 'org-category category 'date date
  4247. 'todo-state todo-state
  4248. 'type "timestamp")
  4249. (push txt ee))
  4250. (if org-agenda-skip-additional-timestamps-same-entry
  4251. (outline-next-heading)
  4252. (goto-char end-of-match))))
  4253. (nreverse ee)))
  4254. (defun org-agenda-get-sexps ()
  4255. "Return the sexp information for agenda display."
  4256. (require 'diary-lib)
  4257. (let* ((props (list 'face nil
  4258. 'mouse-face 'highlight
  4259. 'help-echo
  4260. (format "mouse-2 or RET jump to org file %s"
  4261. (abbreviate-file-name buffer-file-name))))
  4262. (regexp "^&?%%(")
  4263. marker category ee txt tags entry result beg b sexp sexp-entry
  4264. todo-state)
  4265. (goto-char (point-min))
  4266. (while (re-search-forward regexp nil t)
  4267. (catch :skip
  4268. (org-agenda-skip)
  4269. (setq beg (match-beginning 0))
  4270. (goto-char (1- (match-end 0)))
  4271. (setq b (point))
  4272. (forward-sexp 1)
  4273. (setq sexp (buffer-substring b (point)))
  4274. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4275. (org-trim (match-string 1))
  4276. ""))
  4277. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4278. (when result
  4279. (setq marker (org-agenda-new-marker beg)
  4280. category (org-get-category beg)
  4281. todo-state (org-get-todo-state))
  4282. (dolist (r (if (stringp result)
  4283. (list result)
  4284. result)) ;; we expect a list here
  4285. (if (string-match "\\S-" r)
  4286. (setq txt r)
  4287. (setq txt "SEXP entry returned empty string"))
  4288. (setq txt (org-format-agenda-item
  4289. "" txt category tags 'time))
  4290. (org-add-props txt props 'org-marker marker)
  4291. (org-add-props txt nil
  4292. 'org-category category 'date date 'todo-state todo-state
  4293. 'type "sexp")
  4294. (push txt ee)))))
  4295. (nreverse ee)))
  4296. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4297. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4298. The order of the first 2 times 3 arguments depends on the variable
  4299. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4300. So for American calendars, give this as MONTH DAY YEAR, for European as
  4301. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4302. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4303. is any number of ISO weeks in the block period for which the item should
  4304. be skipped."
  4305. (let* ((date1 (calendar-absolute-from-gregorian
  4306. (org-order-calendar-date-args m1 d1 y1)))
  4307. (date2 (calendar-absolute-from-gregorian
  4308. (org-order-calendar-date-args m2 d2 y2)))
  4309. (d (calendar-absolute-from-gregorian date)))
  4310. (and
  4311. (<= date1 d)
  4312. (<= d date2)
  4313. (= (calendar-day-of-week date) dayname)
  4314. (or (not skip-weeks)
  4315. (progn
  4316. (require 'cal-iso)
  4317. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4318. entry)))
  4319. (defalias 'org-get-closed 'org-agenda-get-progress)
  4320. (defun org-agenda-get-progress ()
  4321. "Return the logged TODO entries for agenda display."
  4322. (let* ((props (list 'mouse-face 'highlight
  4323. 'org-not-done-regexp org-not-done-regexp
  4324. 'org-todo-regexp org-todo-regexp
  4325. 'org-complex-heading-regexp org-complex-heading-regexp
  4326. 'help-echo
  4327. (format "mouse-2 or RET jump to org file %s"
  4328. (abbreviate-file-name buffer-file-name))))
  4329. (items (if (consp org-agenda-show-log)
  4330. org-agenda-show-log
  4331. org-agenda-log-mode-items))
  4332. (parts
  4333. (delq nil
  4334. (list
  4335. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4336. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4337. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4338. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4339. (error "`org-agenda-log-mode-items' is empty")))
  4340. (regexp (concat
  4341. "\\(" parts-re "\\)"
  4342. " *\\["
  4343. (regexp-quote
  4344. (substring
  4345. (format-time-string
  4346. (car org-time-stamp-formats)
  4347. (apply 'encode-time ; DATE bound by calendar
  4348. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4349. 1 11))))
  4350. (org-agenda-search-headline-for-time nil)
  4351. marker hdmarker priority category tags closedp statep clockp state
  4352. ee txt extra timestr rest clocked)
  4353. (goto-char (point-min))
  4354. (while (re-search-forward regexp nil t)
  4355. (catch :skip
  4356. (org-agenda-skip)
  4357. (setq marker (org-agenda-new-marker (match-beginning 0))
  4358. closedp (equal (match-string 1) org-closed-string)
  4359. statep (equal (string-to-char (match-string 1)) ?-)
  4360. clockp (not (or closedp statep))
  4361. state (and statep (match-string 2))
  4362. category (org-get-category (match-beginning 0))
  4363. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4364. )
  4365. (when (string-match "\\]" timestr)
  4366. ;; substring should only run to end of time stamp
  4367. (setq rest (substring timestr (match-end 0))
  4368. timestr (substring timestr 0 (match-end 0)))
  4369. (if (and (not closedp) (not statep)
  4370. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4371. (progn (setq timestr (concat (substring timestr 0 -1)
  4372. "-" (match-string 1 rest) "]"))
  4373. (setq clocked (match-string 2 rest)))
  4374. (setq clocked "-")))
  4375. (save-excursion
  4376. (setq extra nil)
  4377. (cond
  4378. ((not org-agenda-log-mode-add-notes))
  4379. (statep
  4380. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4381. (setq extra (match-string 1))))
  4382. (clockp
  4383. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4384. (setq extra (match-string 1)))))
  4385. (if (not (re-search-backward "^\\*+ " nil t))
  4386. (setq txt org-agenda-no-heading-message)
  4387. (goto-char (match-beginning 0))
  4388. (setq hdmarker (org-agenda-new-marker)
  4389. tags (org-get-tags-at))
  4390. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4391. (setq txt (match-string 1))
  4392. (when extra
  4393. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4394. (setq txt (concat (substring txt 0 (match-beginning 1))
  4395. " - " extra " " (match-string 2 txt)))
  4396. (setq txt (concat txt " - " extra))))
  4397. (setq txt (org-format-agenda-item
  4398. (cond
  4399. (closedp "Closed: ")
  4400. (statep (concat "State: (" state ")"))
  4401. (t (concat "Clocked: (" clocked ")")))
  4402. txt category tags timestr)))
  4403. (setq priority 100000)
  4404. (org-add-props txt props
  4405. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4406. 'priority priority 'org-category category
  4407. 'type "closed" 'date date
  4408. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4409. (push txt ee))
  4410. (goto-char (point-at-eol))))
  4411. (nreverse ee)))
  4412. (defun org-agenda-get-deadlines ()
  4413. "Return the deadline information for agenda display."
  4414. (let* ((props (list 'mouse-face 'highlight
  4415. 'org-not-done-regexp org-not-done-regexp
  4416. 'org-todo-regexp org-todo-regexp
  4417. 'org-complex-heading-regexp org-complex-heading-regexp
  4418. 'help-echo
  4419. (format "mouse-2 or RET jump to org file %s"
  4420. (abbreviate-file-name buffer-file-name))))
  4421. (regexp org-deadline-time-regexp)
  4422. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4423. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4424. d2 diff dfrac wdays pos pos1 category tags
  4425. suppress-prewarning
  4426. ee txt head face s todo-state upcomingp donep timestr)
  4427. (goto-char (point-min))
  4428. (while (re-search-forward regexp nil t)
  4429. (setq suppress-prewarning nil)
  4430. (catch :skip
  4431. (org-agenda-skip)
  4432. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4433. (save-match-data
  4434. (string-match org-scheduled-time-regexp
  4435. (buffer-substring (point-at-bol)
  4436. (point-at-eol)))))
  4437. (setq suppress-prewarning
  4438. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4439. org-agenda-skip-deadline-prewarning-if-scheduled
  4440. 0)))
  4441. (setq s (match-string 1)
  4442. txt nil
  4443. pos (1- (match-beginning 1))
  4444. d2 (org-time-string-to-absolute
  4445. (match-string 1) d1 'past
  4446. org-agenda-repeating-timestamp-show-all)
  4447. diff (- d2 d1)
  4448. wdays (if suppress-prewarning
  4449. (let ((org-deadline-warning-days suppress-prewarning))
  4450. (org-get-wdays s))
  4451. (org-get-wdays s))
  4452. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4453. upcomingp (and todayp (> diff 0)))
  4454. ;; When to show a deadline in the calendar:
  4455. ;; If the expiration is within wdays warning time.
  4456. ;; Past-due deadlines are only shown on the current date
  4457. (if (and (or (and (<= diff wdays)
  4458. (and todayp (not org-agenda-only-exact-dates)))
  4459. (= diff 0)))
  4460. (save-excursion
  4461. (setq todo-state (org-get-todo-state))
  4462. (setq donep (member todo-state org-done-keywords))
  4463. (if (and donep
  4464. (or org-agenda-skip-deadline-if-done
  4465. (not (= diff 0))))
  4466. (setq txt nil)
  4467. (setq category (org-get-category))
  4468. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4469. (setq txt org-agenda-no-heading-message)
  4470. (goto-char (match-end 0))
  4471. (setq pos1 (match-beginning 0))
  4472. (setq tags (org-get-tags-at pos1))
  4473. (setq head (buffer-substring-no-properties
  4474. (point)
  4475. (progn (skip-chars-forward "^\r\n")
  4476. (point))))
  4477. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4478. (setq timestr
  4479. (concat (substring s (match-beginning 1)) " "))
  4480. (setq timestr 'time))
  4481. (setq txt (org-format-agenda-item
  4482. (if (= diff 0)
  4483. (car org-agenda-deadline-leaders)
  4484. (if (functionp
  4485. (nth 1 org-agenda-deadline-leaders))
  4486. (funcall
  4487. (nth 1 org-agenda-deadline-leaders)
  4488. diff date)
  4489. (format (nth 1 org-agenda-deadline-leaders)
  4490. diff)))
  4491. head category tags
  4492. (if (not (= diff 0)) nil timestr)))))
  4493. (when txt
  4494. (setq face (org-agenda-deadline-face dfrac wdays))
  4495. (org-add-props txt props
  4496. 'org-marker (org-agenda-new-marker pos)
  4497. 'org-hd-marker (org-agenda-new-marker pos1)
  4498. 'priority (+ (- diff)
  4499. (org-get-priority txt))
  4500. 'org-category category
  4501. 'todo-state todo-state
  4502. 'type (if upcomingp "upcoming-deadline" "deadline")
  4503. 'date (if upcomingp date d2)
  4504. 'face (if donep 'org-agenda-done face)
  4505. 'undone-face face 'done-face 'org-agenda-done)
  4506. (push txt ee))))))
  4507. (nreverse ee)))
  4508. (defun org-agenda-deadline-face (fraction &optional wdays)
  4509. "Return the face to displaying a deadline item.
  4510. FRACTION is what fraction of the head-warning time has passed."
  4511. (if (equal wdays 0) (setq fraction 1.))
  4512. (let ((faces org-agenda-deadline-faces) f)
  4513. (catch 'exit
  4514. (while (setq f (pop faces))
  4515. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4516. (defun org-agenda-get-scheduled (&optional deadline-results)
  4517. "Return the scheduled information for agenda display."
  4518. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4519. 'org-todo-regexp org-todo-regexp
  4520. 'org-complex-heading-regexp org-complex-heading-regexp
  4521. 'done-face 'org-agenda-done
  4522. 'mouse-face 'highlight
  4523. 'help-echo
  4524. (format "mouse-2 or RET jump to org file %s"
  4525. (abbreviate-file-name buffer-file-name))))
  4526. (regexp org-scheduled-time-regexp)
  4527. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4528. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4529. mm
  4530. (deadline-position-alist
  4531. (mapcar (lambda (a) (and (setq mm (get-text-property
  4532. 0 'org-hd-marker a))
  4533. (cons (marker-position mm) a)))
  4534. deadline-results))
  4535. d2 diff pos pos1 category tags donep
  4536. ee txt head pastschedp todo-state face timestr s habitp)
  4537. (goto-char (point-min))
  4538. (while (re-search-forward regexp nil t)
  4539. (catch :skip
  4540. (org-agenda-skip)
  4541. (setq s (match-string 1)
  4542. txt nil
  4543. pos (1- (match-beginning 1))
  4544. d2 (org-time-string-to-absolute
  4545. (match-string 1) d1 'past
  4546. org-agenda-repeating-timestamp-show-all)
  4547. diff (- d2 d1))
  4548. (setq pastschedp (and todayp (< diff 0)))
  4549. ;; When to show a scheduled item in the calendar:
  4550. ;; If it is on or past the date.
  4551. (when (or (and (< diff 0)
  4552. (< (abs diff) org-scheduled-past-days)
  4553. (and todayp (not org-agenda-only-exact-dates)))
  4554. (= diff 0))
  4555. (save-excursion
  4556. (setq todo-state (org-get-todo-state))
  4557. (setq donep (member todo-state org-done-keywords))
  4558. (setq habitp (and (functionp 'org-is-habit-p)
  4559. (org-is-habit-p)))
  4560. (if (and donep
  4561. (or habitp org-agenda-skip-scheduled-if-done
  4562. (not (= diff 0))))
  4563. (setq txt nil)
  4564. (setq category (org-get-category))
  4565. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4566. (setq txt org-agenda-no-heading-message)
  4567. (goto-char (match-end 0))
  4568. (setq pos1 (match-beginning 0))
  4569. (if habitp
  4570. (if (or (not org-habit-show-habits)
  4571. (and (not todayp)
  4572. org-habit-show-habits-only-for-today))
  4573. (throw :skip nil))
  4574. (if (and
  4575. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4576. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4577. pastschedp))
  4578. (setq mm (assoc pos1 deadline-position-alist)))
  4579. (throw :skip nil)))
  4580. (setq tags (org-get-tags-at))
  4581. (setq head (buffer-substring-no-properties
  4582. (point)
  4583. (progn (skip-chars-forward "^\r\n") (point))))
  4584. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4585. (setq timestr
  4586. (concat (substring s (match-beginning 1)) " "))
  4587. (setq timestr 'time))
  4588. (setq txt (org-format-agenda-item
  4589. (if (= diff 0)
  4590. (car org-agenda-scheduled-leaders)
  4591. (format (nth 1 org-agenda-scheduled-leaders)
  4592. (- 1 diff)))
  4593. head category tags
  4594. (if (not (= diff 0)) nil timestr)
  4595. nil nil habitp))))
  4596. (when txt
  4597. (setq face
  4598. (cond
  4599. ((and (not habitp) pastschedp)
  4600. 'org-scheduled-previously)
  4601. (todayp 'org-scheduled-today)
  4602. (t 'org-scheduled))
  4603. habitp (and habitp (org-habit-parse-todo)))
  4604. (org-add-props txt props
  4605. 'undone-face face
  4606. 'face (if donep 'org-agenda-done face)
  4607. 'org-marker (org-agenda-new-marker pos)
  4608. 'org-hd-marker (org-agenda-new-marker pos1)
  4609. 'type (if pastschedp "past-scheduled" "scheduled")
  4610. 'date (if pastschedp d2 date)
  4611. 'priority (if habitp
  4612. (org-habit-get-priority habitp)
  4613. (+ 94 (- 5 diff) (org-get-priority txt)))
  4614. 'org-category category
  4615. 'org-habit-p habitp
  4616. 'todo-state todo-state)
  4617. (push txt ee))))))
  4618. (nreverse ee)))
  4619. (defun org-agenda-get-blocks ()
  4620. "Return the date-range information for agenda display."
  4621. (let* ((props (list 'face nil
  4622. 'org-not-done-regexp org-not-done-regexp
  4623. 'org-todo-regexp org-todo-regexp
  4624. 'org-complex-heading-regexp org-complex-heading-regexp
  4625. 'mouse-face 'highlight
  4626. 'help-echo
  4627. (format "mouse-2 or RET jump to org file %s"
  4628. (abbreviate-file-name buffer-file-name))))
  4629. (regexp org-tr-regexp)
  4630. (d0 (calendar-absolute-from-gregorian date))
  4631. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4632. head donep)
  4633. (goto-char (point-min))
  4634. (while (re-search-forward regexp nil t)
  4635. (catch :skip
  4636. (org-agenda-skip)
  4637. (setq pos (point))
  4638. (setq timestr (match-string 0)
  4639. s1 (match-string 1)
  4640. s2 (match-string 2)
  4641. d1 (time-to-days (org-time-string-to-time s1))
  4642. d2 (time-to-days (org-time-string-to-time s2)))
  4643. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4644. ;; Only allow days between the limits, because the normal
  4645. ;; date stamps will catch the limits.
  4646. (save-excursion
  4647. (setq todo-state (org-get-todo-state))
  4648. (setq donep (member todo-state org-done-keywords))
  4649. (if (and donep org-agenda-skip-timestamp-if-done)
  4650. (throw :skip t))
  4651. (setq marker (org-agenda-new-marker (point)))
  4652. (setq category (org-get-category))
  4653. (if (not (re-search-backward "^\\*+ " nil t))
  4654. (setq txt org-agenda-no-heading-message)
  4655. (goto-char (match-beginning 0))
  4656. (setq hdmarker (org-agenda-new-marker (point)))
  4657. (setq tags (org-get-tags-at))
  4658. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4659. (setq head (match-string 1))
  4660. (let ((remove-re
  4661. (if org-agenda-remove-timeranges-from-blocks
  4662. (concat
  4663. "<" (regexp-quote s1) ".*?>"
  4664. "--"
  4665. "<" (regexp-quote s2) ".*?>")
  4666. nil)))
  4667. (setq txt (org-format-agenda-item
  4668. (format
  4669. (nth (if (= d1 d2) 0 1)
  4670. org-agenda-timerange-leaders)
  4671. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4672. head category tags
  4673. timestr nil remove-re))))
  4674. (org-add-props txt props
  4675. 'org-marker marker 'org-hd-marker hdmarker
  4676. 'type "block" 'date date
  4677. 'todo-state todo-state
  4678. 'priority (org-get-priority txt) 'org-category category)
  4679. (push txt ee)))
  4680. (goto-char pos)))
  4681. ;; Sort the entries by expiration date.
  4682. (nreverse ee)))
  4683. ;;; Agenda presentation and sorting
  4684. (defvar org-prefix-has-time nil
  4685. "A flag, set by `org-compile-prefix-format'.
  4686. The flag is set if the currently compiled format contains a `%t'.")
  4687. (defvar org-prefix-has-tag nil
  4688. "A flag, set by `org-compile-prefix-format'.
  4689. The flag is set if the currently compiled format contains a `%T'.")
  4690. (defvar org-prefix-has-effort nil
  4691. "A flag, set by `org-compile-prefix-format'.
  4692. The flag is set if the currently compiled format contains a `%e'.")
  4693. (defvar org-prefix-category-length nil
  4694. "Used by `org-compile-prefix-format' to remember the category field width.")
  4695. (defvar org-prefix-category-max-length nil
  4696. "Used by `org-compile-prefix-format' to remember the category field width.")
  4697. (defun org-agenda-get-category-icon (category)
  4698. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4699. (dolist (entry org-agenda-category-icon-alist)
  4700. (when (org-string-match-p (car entry) category)
  4701. (if (listp (cadr entry))
  4702. (return (cadr entry))
  4703. (return (apply 'create-image (cdr entry)))))))
  4704. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4705. noprefix remove-re habitp)
  4706. "Format TXT to be inserted into the agenda buffer.
  4707. In particular, it adds the prefix and corresponding text properties. EXTRA
  4708. must be a string and replaces the `%s' specifier in the prefix format.
  4709. CATEGORY (string, symbol or nil) may be used to overrule the default
  4710. category taken from local variable or file name. It will replace the `%c'
  4711. specifier in the format. DOTIME, when non-nil, indicates that a
  4712. time-of-day should be extracted from TXT for sorting of this entry, and for
  4713. the `%t' specifier in the format. When DOTIME is a string, this string is
  4714. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4715. only the correctly processes TXT should be returned - this is used by
  4716. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4717. Any match of REMOVE-RE will be removed from TXT."
  4718. (save-match-data
  4719. ;; Diary entries sometimes have extra whitespace at the beginning
  4720. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4721. ;; Fix the tags part in txt
  4722. (setq txt (org-agenda-fix-displayed-tags
  4723. txt tags
  4724. org-agenda-show-inherited-tags
  4725. org-agenda-hide-tags-regexp))
  4726. (let* ((category (or category
  4727. (if (stringp org-category)
  4728. org-category
  4729. (symbol-name org-category))
  4730. (if buffer-file-name
  4731. (file-name-sans-extension
  4732. (file-name-nondirectory buffer-file-name))
  4733. "")))
  4734. (category-icon (org-agenda-get-category-icon category))
  4735. (category-icon (if category-icon
  4736. (propertize " " 'display category-icon)
  4737. ""))
  4738. ;; time, tag, effort are needed for the eval of the prefix format
  4739. (tag (if tags (nth (1- (length tags)) tags) ""))
  4740. time effort neffort
  4741. (ts (if dotime (concat
  4742. (if (stringp dotime) dotime "")
  4743. (and org-agenda-search-headline-for-time txt))))
  4744. (time-of-day (and dotime (org-get-time-of-day ts)))
  4745. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4746. duration thecategory)
  4747. (and (org-mode-p) buffer-file-name
  4748. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4749. (when (and dotime time-of-day)
  4750. ;; Extract starting and ending time and move them to prefix
  4751. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4752. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4753. (setq s0 (match-string 0 ts)
  4754. srp (and stamp (match-end 3))
  4755. s1 (match-string (if plain 1 2) ts)
  4756. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4757. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4758. ;; them, we might want to remove them there to avoid duplication.
  4759. ;; The user can turn this off with a variable.
  4760. (if (and org-prefix-has-time
  4761. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4762. (string-match (concat (regexp-quote s0) " *") txt)
  4763. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4764. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4765. (= (match-beginning 0) 0)
  4766. t))
  4767. (setq txt (replace-match "" nil nil txt))))
  4768. ;; Normalize the time(s) to 24 hour
  4769. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4770. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4771. ;; Compute the duration
  4772. (when s1
  4773. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4774. (string-to-number (substring s1 3)))
  4775. t2 (cond
  4776. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4777. (string-to-number (substring s2 3))))
  4778. (org-agenda-default-appointment-duration
  4779. (+ t1 org-agenda-default-appointment-duration))
  4780. (t nil)))
  4781. (setq duration (if t2 (- t2 t1)))))
  4782. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4783. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4784. (let ((m (+ (string-to-number (match-string 2 s1))
  4785. (* 60 (string-to-number (match-string 1 s1)))
  4786. org-agenda-default-appointment-duration))
  4787. h)
  4788. (setq h (/ m 60) m (- m (* h 60)))
  4789. (setq s2 (format "%02d:%02d" h m))))
  4790. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4791. txt)
  4792. ;; Tags are in the string
  4793. (if (or (eq org-agenda-remove-tags t)
  4794. (and org-agenda-remove-tags
  4795. org-prefix-has-tag))
  4796. (setq txt (replace-match "" t t txt))
  4797. (setq txt (replace-match
  4798. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4799. (match-string 2 txt))
  4800. t t txt))))
  4801. (when (org-mode-p)
  4802. (setq effort
  4803. (condition-case nil
  4804. (org-get-effort
  4805. (or (get-text-property 0 'org-hd-marker txt)
  4806. (get-text-property 0 'org-marker txt)))
  4807. (error nil)))
  4808. (when effort
  4809. (setq neffort (org-hh:mm-string-to-minutes effort)
  4810. effort (setq effort (concat "[" effort "]" )))))
  4811. (when remove-re
  4812. (while (string-match remove-re txt)
  4813. (setq txt (replace-match "" t t txt))))
  4814. ;; Create the final string
  4815. (if noprefix
  4816. (setq rtn txt)
  4817. ;; Prepare the variables needed in the eval of the compiled format
  4818. (setq time (cond (s2 (concat
  4819. (org-agenda-time-of-day-to-ampm-maybe s1)
  4820. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  4821. (if org-agenda-timegrid-use-ampm " ")))
  4822. (s1 (concat
  4823. (org-agenda-time-of-day-to-ampm-maybe s1)
  4824. (if org-agenda-timegrid-use-ampm
  4825. "........ "
  4826. "......")))
  4827. (t ""))
  4828. extra (or (and (not habitp) extra) "")
  4829. category (if (symbolp category) (symbol-name category) category)
  4830. thecategory (copy-sequence category))
  4831. (if (string-match org-bracket-link-regexp category)
  4832. (progn
  4833. (setq l (if (match-end 3)
  4834. (- (match-end 3) (match-beginning 3))
  4835. (- (match-end 1) (match-beginning 1))))
  4836. (when (< l (or org-prefix-category-length 0))
  4837. (setq category (copy-sequence category))
  4838. (org-add-props category nil
  4839. 'extra-space (make-string
  4840. (- org-prefix-category-length l 1) ?\ ))))
  4841. (if (and org-prefix-category-max-length
  4842. (>= (length category) org-prefix-category-max-length))
  4843. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4844. ;; Evaluate the compiled format
  4845. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4846. ;; And finally add the text properties
  4847. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4848. (org-add-props rtn nil
  4849. 'org-category (if thecategory (downcase thecategory) category)
  4850. 'tags (mapcar 'org-downcase-keep-props tags)
  4851. 'org-highest-priority org-highest-priority
  4852. 'org-lowest-priority org-lowest-priority
  4853. 'prefix-length (- (length rtn) (length txt))
  4854. 'time-of-day time-of-day
  4855. 'duration duration
  4856. 'effort effort
  4857. 'effort-minutes neffort
  4858. 'txt txt
  4859. 'time time
  4860. 'extra extra
  4861. 'dotime dotime))))
  4862. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4863. "Remove tags string from TXT, and add a modified list of tags.
  4864. The modified list may contain inherited tags, and tags matched by
  4865. `org-agenda-hide-tags-regexp' will be removed."
  4866. (when (or add-inherited hide-re)
  4867. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4868. (setq txt (substring txt 0 (match-beginning 0))))
  4869. (setq tags
  4870. (delq nil
  4871. (mapcar (lambda (tg)
  4872. (if (or (and hide-re (string-match hide-re tg))
  4873. (and (not add-inherited)
  4874. (get-text-property 0 'inherited tg)))
  4875. nil
  4876. tg))
  4877. tags)))
  4878. (when tags
  4879. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4880. i)
  4881. (setq txt (concat txt " :"
  4882. (mapconcat
  4883. (lambda (x)
  4884. (setq i (get-text-property 0 'inherited x))
  4885. (if (and have-i (not i))
  4886. (progn
  4887. (setq have-i nil)
  4888. (concat ":" x))
  4889. x))
  4890. tags ":")
  4891. (if have-i "::" ":"))))))
  4892. txt)
  4893. (defun org-downcase-keep-props (s)
  4894. (let ((props (text-properties-at 0 s)))
  4895. (setq s (downcase s))
  4896. (add-text-properties 0 (length s) props s)
  4897. s))
  4898. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4899. (defvar org-agenda-sorting-strategy-selected nil)
  4900. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4901. (catch 'exit
  4902. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4903. ((and todayp (member 'today (car org-agenda-time-grid))))
  4904. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4905. ((member 'weekly (car org-agenda-time-grid)))
  4906. (t (throw 'exit list)))
  4907. (let* ((have (delq nil (mapcar
  4908. (lambda (x) (get-text-property 1 'time-of-day x))
  4909. list)))
  4910. (string (nth 1 org-agenda-time-grid))
  4911. (gridtimes (nth 2 org-agenda-time-grid))
  4912. (req (car org-agenda-time-grid))
  4913. (remove (member 'remove-match req))
  4914. new time)
  4915. (if (and (member 'require-timed req) (not have))
  4916. ;; don't show empty grid
  4917. (throw 'exit list))
  4918. (while (setq time (pop gridtimes))
  4919. (unless (and remove (member time have))
  4920. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  4921. (push (org-format-agenda-item
  4922. nil string "" nil
  4923. (concat (substring time 0 -2) ":" (substring time -2)))
  4924. new)
  4925. (put-text-property
  4926. 2 (length (car new)) 'face 'org-time-grid (car new))))
  4927. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4928. (append new list)
  4929. (append list new)))))
  4930. (defun org-compile-prefix-format (key)
  4931. "Compile the prefix format into a Lisp form that can be evaluated.
  4932. The resulting form is returned and stored in the variable
  4933. `org-prefix-format-compiled'."
  4934. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4935. org-prefix-category-length nil org-prefix-has-effort nil)
  4936. (let ((s (cond
  4937. ((stringp org-agenda-prefix-format)
  4938. org-agenda-prefix-format)
  4939. ((assq key org-agenda-prefix-format)
  4940. (cdr (assq key org-agenda-prefix-format)))
  4941. (t " %-12:c%?-12t% s")))
  4942. (start 0)
  4943. varform vars var e c f opt)
  4944. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\)"
  4945. s start)
  4946. (setq var (cdr (assoc (match-string 4 s)
  4947. '(("c" . category) ("t" . time) ("s" . extra)
  4948. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  4949. c (or (match-string 3 s) "")
  4950. opt (match-beginning 1)
  4951. start (1+ (match-beginning 0)))
  4952. (if (equal var 'time) (setq org-prefix-has-time t))
  4953. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4954. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4955. (setq f (concat "%" (match-string 2 s) "s"))
  4956. (when (equal var 'category)
  4957. (setq org-prefix-category-length
  4958. (floor (abs (string-to-number (match-string 2 s)))))
  4959. (setq org-prefix-category-max-length
  4960. (let ((x (match-string 2 s)))
  4961. (save-match-data
  4962. (if (string-match "\\.[0-9]+" x)
  4963. (string-to-number (substring (match-string 0 x) 1)))))))
  4964. (if opt
  4965. (setq varform
  4966. `(if (equal "" ,var)
  4967. ""
  4968. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4969. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4970. (setq s (replace-match "%s" t nil s))
  4971. (push varform vars))
  4972. (setq vars (nreverse vars))
  4973. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4974. (defun org-set-sorting-strategy (key)
  4975. (if (symbolp (car org-agenda-sorting-strategy))
  4976. ;; the old format
  4977. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4978. (setq org-agenda-sorting-strategy-selected
  4979. (or (cdr (assq key org-agenda-sorting-strategy))
  4980. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4981. '(time-up category-keep priority-down)))))
  4982. (defun org-get-time-of-day (s &optional string mod24)
  4983. "Check string S for a time of day.
  4984. If found, return it as a military time number between 0 and 2400.
  4985. If not found, return nil.
  4986. The optional STRING argument forces conversion into a 5 character wide string
  4987. HH:MM."
  4988. (save-match-data
  4989. (when
  4990. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4991. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4992. (let* ((h (string-to-number (match-string 1 s)))
  4993. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4994. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4995. (am-p (equal ampm "am"))
  4996. (h1 (cond ((not ampm) h)
  4997. ((= h 12) (if am-p 0 12))
  4998. (t (+ h (if am-p 0 12)))))
  4999. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5000. (mod h1 24) h1))
  5001. (t0 (+ (* 100 h2) m))
  5002. (t1 (concat (if (>= h1 24) "+" " ")
  5003. (if (and org-agenda-time-leading-zero
  5004. (< t0 1000)) "0" "")
  5005. (if (< t0 100) "0" "")
  5006. (if (< t0 10) "0" "")
  5007. (int-to-string t0))))
  5008. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5009. (defvar org-agenda-before-sorting-filter-function nil
  5010. "Function to be applied to agenda items prior to sorting.
  5011. Prior to sorting also means just before they are inserted into the agenda.
  5012. To aid sorting, you may revisit the original entries and add more text
  5013. properties which will later be used by the sorting functions.
  5014. The function should take a string argument, an agenda line.
  5015. It has access to the text properties in that line, which contain among
  5016. other things, the property `org-hd-marker' that points to the entry
  5017. where the line comes from. Note that not all lines going into the agenda
  5018. have this property, only most.
  5019. The function should return the modified string. It is probably best
  5020. to ONLY change text properties.
  5021. You can also use this function as a filter, by returning nil for lines
  5022. you don't want to have in the agenda at all. For this application, you
  5023. could bind the variable in the options section of a custom command.")
  5024. (defun org-finalize-agenda-entries (list &optional nosort)
  5025. "Sort and concatenate the agenda items."
  5026. (setq list (mapcar 'org-agenda-highlight-todo list))
  5027. (if nosort
  5028. list
  5029. (when org-agenda-before-sorting-filter-function
  5030. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5031. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5032. (defun org-agenda-highlight-todo (x)
  5033. (let ((org-done-keywords org-done-keywords-for-agenda)
  5034. (case-fold-search nil)
  5035. re pl)
  5036. (if (eq x 'line)
  5037. (save-excursion
  5038. (beginning-of-line 1)
  5039. (setq re (org-get-at-bol 'org-todo-regexp))
  5040. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  5041. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5042. (add-text-properties (match-beginning 0) (match-end 1)
  5043. (list 'face (org-get-todo-face 1)))
  5044. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5045. (delete-region (match-beginning 1) (1- (match-end 0)))
  5046. (goto-char (match-beginning 1))
  5047. (insert (format org-agenda-todo-keyword-format s)))))
  5048. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  5049. pl (get-text-property 0 'prefix-length x))
  5050. (when (and re
  5051. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5052. x (or pl 0)) pl))
  5053. (add-text-properties
  5054. (or (match-end 1) (match-end 0)) (match-end 0)
  5055. (list 'face (org-get-todo-face (match-string 2 x)))
  5056. x)
  5057. (when (match-end 1)
  5058. (setq x (concat (substring x 0 (match-end 1))
  5059. (format org-agenda-todo-keyword-format
  5060. (match-string 2 x))
  5061. (org-add-props " " (text-properties-at 0 x))
  5062. (substring x (match-end 3))))))
  5063. x)))
  5064. (defsubst org-cmp-priority (a b)
  5065. "Compare the priorities of string A and B."
  5066. (let ((pa (or (get-text-property 1 'priority a) 0))
  5067. (pb (or (get-text-property 1 'priority b) 0)))
  5068. (cond ((> pa pb) +1)
  5069. ((< pa pb) -1)
  5070. (t nil))))
  5071. (defsubst org-cmp-effort (a b)
  5072. "Compare the priorities of string A and B."
  5073. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5074. (ea (or (get-text-property 1 'effort-minutes a) def))
  5075. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5076. (cond ((> ea eb) +1)
  5077. ((< ea eb) -1)
  5078. (t nil))))
  5079. (defsubst org-cmp-category (a b)
  5080. "Compare the string values of categories of strings A and B."
  5081. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5082. (cb (or (get-text-property 1 'org-category b) "")))
  5083. (cond ((string-lessp ca cb) -1)
  5084. ((string-lessp cb ca) +1)
  5085. (t nil))))
  5086. (defsubst org-cmp-todo-state (a b)
  5087. "Compare the todo states of strings A and B."
  5088. (let* ((ma (or (get-text-property 1 'org-marker a)
  5089. (get-text-property 1 'org-hd-marker a)))
  5090. (mb (or (get-text-property 1 'org-marker b)
  5091. (get-text-property 1 'org-hd-marker b)))
  5092. (fa (and ma (marker-buffer ma)))
  5093. (fb (and mb (marker-buffer mb)))
  5094. (todo-kwds
  5095. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5096. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5097. (ta (or (get-text-property 1 'todo-state a) ""))
  5098. (tb (or (get-text-property 1 'todo-state b) ""))
  5099. (la (- (length (member ta todo-kwds))))
  5100. (lb (- (length (member tb todo-kwds))))
  5101. (donepa (member ta org-done-keywords-for-agenda))
  5102. (donepb (member tb org-done-keywords-for-agenda)))
  5103. (cond ((and donepa (not donepb)) -1)
  5104. ((and (not donepa) donepb) +1)
  5105. ((< la lb) -1)
  5106. ((< lb la) +1)
  5107. (t nil))))
  5108. (defsubst org-cmp-alpha (a b)
  5109. "Compare the headlines, alphabetically."
  5110. (let* ((pla (get-text-property 0 'prefix-length a))
  5111. (plb (get-text-property 0 'prefix-length b))
  5112. (ta (and pla (substring a pla)))
  5113. (tb (and plb (substring b plb))))
  5114. (when pla
  5115. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5116. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5117. (setq ta (substring ta (match-end 0))))
  5118. (setq ta (downcase ta)))
  5119. (when plb
  5120. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5121. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5122. (setq tb (substring tb (match-end 0))))
  5123. (setq tb (downcase tb)))
  5124. (cond ((not ta) +1)
  5125. ((not tb) -1)
  5126. ((string-lessp ta tb) -1)
  5127. ((string-lessp tb ta) +1)
  5128. (t nil))))
  5129. (defsubst org-cmp-tag (a b)
  5130. "Compare the string values of the first tags of A and B."
  5131. (let ((ta (car (last (get-text-property 1 'tags a))))
  5132. (tb (car (last (get-text-property 1 'tags b)))))
  5133. (cond ((not ta) +1)
  5134. ((not tb) -1)
  5135. ((string-lessp ta tb) -1)
  5136. ((string-lessp tb ta) +1)
  5137. (t nil))))
  5138. (defsubst org-cmp-time (a b)
  5139. "Compare the time-of-day values of strings A and B."
  5140. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5141. (ta (or (get-text-property 1 'time-of-day a) def))
  5142. (tb (or (get-text-property 1 'time-of-day b) def)))
  5143. (cond ((< ta tb) -1)
  5144. ((< tb ta) +1)
  5145. (t nil))))
  5146. (defsubst org-cmp-habit-p (a b)
  5147. "Compare the todo states of strings A and B."
  5148. (let ((ha (get-text-property 1 'org-habit-p a))
  5149. (hb (get-text-property 1 'org-habit-p b)))
  5150. (cond ((and ha (not hb)) -1)
  5151. ((and (not ha) hb) +1)
  5152. (t nil))))
  5153. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5154. (defun org-entries-lessp (a b)
  5155. "Predicate for sorting agenda entries."
  5156. ;; The following variables will be used when the form is evaluated.
  5157. ;; So even though the compiler complains, keep them.
  5158. (let* ((ss org-agenda-sorting-strategy-selected)
  5159. (time-up (and (org-em 'time-up 'time-down ss)
  5160. (org-cmp-time a b)))
  5161. (time-down (if time-up (- time-up) nil))
  5162. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5163. (org-cmp-priority a b)))
  5164. (priority-down (if priority-up (- priority-up) nil))
  5165. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5166. (org-cmp-effort a b)))
  5167. (effort-down (if effort-up (- effort-up) nil))
  5168. (category-up (and (or (org-em 'category-up 'category-down ss)
  5169. (memq 'category-keep ss))
  5170. (org-cmp-category a b)))
  5171. (category-down (if category-up (- category-up) nil))
  5172. (category-keep (if category-up +1 nil))
  5173. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5174. (org-cmp-tag a b)))
  5175. (tag-down (if tag-up (- tag-up) nil))
  5176. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5177. (org-cmp-todo-state a b)))
  5178. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5179. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5180. (org-cmp-habit-p a b)))
  5181. (habit-down (if habit-up (- habit-up) nil))
  5182. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5183. (org-cmp-alpha a b)))
  5184. (alpha-down (if alpha-up (- alpha-up) nil))
  5185. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5186. user-defined-up user-defined-down)
  5187. (if (and need-user-cmp org-agenda-cmp-user-defined
  5188. (functionp org-agenda-cmp-user-defined))
  5189. (setq user-defined-up
  5190. (funcall org-agenda-cmp-user-defined a b)
  5191. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5192. (cdr (assoc
  5193. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5194. '((-1 . t) (1 . nil) (nil . nil))))))
  5195. ;;; Agenda restriction lock
  5196. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5197. "Overlay to mark the headline to which agenda commands are restricted.")
  5198. (overlay-put org-agenda-restriction-lock-overlay
  5199. 'face 'org-agenda-restriction-lock)
  5200. (overlay-put org-agenda-restriction-lock-overlay
  5201. 'help-echo "Agendas are currently limited to this subtree.")
  5202. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5203. (defun org-agenda-set-restriction-lock (&optional type)
  5204. "Set restriction lock for agenda, to current subtree or file.
  5205. Restriction will be the file if TYPE is `file', or if type is the
  5206. universal prefix '(4), or if the cursor is before the first headline
  5207. in the file. Otherwise, restriction will be to the current subtree."
  5208. (interactive "P")
  5209. (and (equal type '(4)) (setq type 'file))
  5210. (setq type (cond
  5211. (type type)
  5212. ((org-at-heading-p) 'subtree)
  5213. ((condition-case nil (org-back-to-heading t) (error nil))
  5214. 'subtree)
  5215. (t 'file)))
  5216. (if (eq type 'subtree)
  5217. (progn
  5218. (setq org-agenda-restrict t)
  5219. (setq org-agenda-overriding-restriction 'subtree)
  5220. (put 'org-agenda-files 'org-restrict
  5221. (list (buffer-file-name (buffer-base-buffer))))
  5222. (org-back-to-heading t)
  5223. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5224. (move-marker org-agenda-restrict-begin (point))
  5225. (move-marker org-agenda-restrict-end
  5226. (save-excursion (org-end-of-subtree t)))
  5227. (message "Locking agenda restriction to subtree"))
  5228. (put 'org-agenda-files 'org-restrict
  5229. (list (buffer-file-name (buffer-base-buffer))))
  5230. (setq org-agenda-restrict nil)
  5231. (setq org-agenda-overriding-restriction 'file)
  5232. (move-marker org-agenda-restrict-begin nil)
  5233. (move-marker org-agenda-restrict-end nil)
  5234. (message "Locking agenda restriction to file"))
  5235. (setq current-prefix-arg nil)
  5236. (org-agenda-maybe-redo))
  5237. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5238. "Remove the agenda restriction lock."
  5239. (interactive "P")
  5240. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5241. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5242. (setq org-agenda-overriding-restriction nil)
  5243. (setq org-agenda-restrict nil)
  5244. (put 'org-agenda-files 'org-restrict nil)
  5245. (move-marker org-agenda-restrict-begin nil)
  5246. (move-marker org-agenda-restrict-end nil)
  5247. (setq current-prefix-arg nil)
  5248. (message "Agenda restriction lock removed")
  5249. (or noupdate (org-agenda-maybe-redo)))
  5250. (defun org-agenda-maybe-redo ()
  5251. "If there is any window showing the agenda view, update it."
  5252. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5253. (w0 (selected-window)))
  5254. (when w
  5255. (select-window w)
  5256. (org-agenda-redo)
  5257. (select-window w0)
  5258. (if org-agenda-overriding-restriction
  5259. (message "Agenda view shifted to new %s restriction"
  5260. org-agenda-overriding-restriction)
  5261. (message "Agenda restriction lock removed")))))
  5262. ;;; Agenda commands
  5263. (defun org-agenda-check-type (error &rest types)
  5264. "Check if agenda buffer is of allowed type.
  5265. If ERROR is non-nil, throw an error, otherwise just return nil."
  5266. (if (memq org-agenda-type types)
  5267. t
  5268. (if error
  5269. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5270. nil)))
  5271. (defun org-agenda-quit ()
  5272. "Exit agenda by removing the window or the buffer."
  5273. (interactive)
  5274. (if org-agenda-columns-active
  5275. (org-columns-quit)
  5276. (let ((buf (current-buffer)))
  5277. (if (eq org-agenda-window-setup 'other-frame)
  5278. (progn
  5279. (kill-buffer buf)
  5280. (org-agenda-reset-markers)
  5281. (org-columns-remove-overlays)
  5282. (setq org-agenda-archives-mode nil)
  5283. (delete-frame))
  5284. (and (not (eq org-agenda-window-setup 'current-window))
  5285. (not (one-window-p))
  5286. (delete-window))
  5287. (kill-buffer buf)
  5288. (org-agenda-reset-markers)
  5289. (org-columns-remove-overlays)
  5290. (setq org-agenda-archives-mode nil)))
  5291. ;; Maybe restore the pre-agenda window configuration.
  5292. (and org-agenda-restore-windows-after-quit
  5293. (not (eq org-agenda-window-setup 'other-frame))
  5294. org-pre-agenda-window-conf
  5295. (set-window-configuration org-pre-agenda-window-conf))))
  5296. (defun org-agenda-exit ()
  5297. "Exit agenda by removing the window or the buffer.
  5298. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5299. Org-mode buffers visited directly by the user will not be touched."
  5300. (interactive)
  5301. (org-release-buffers org-agenda-new-buffers)
  5302. (setq org-agenda-new-buffers nil)
  5303. (org-agenda-quit))
  5304. (defun org-agenda-execute (arg)
  5305. "Execute another agenda command, keeping same window.
  5306. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5307. in the agenda."
  5308. (interactive "P")
  5309. (let ((org-agenda-window-setup 'current-window))
  5310. (org-agenda arg)))
  5311. (defun org-agenda-redo ()
  5312. "Rebuild Agenda.
  5313. When this is the global TODO list, a prefix argument will be interpreted."
  5314. (interactive)
  5315. (let* ((org-agenda-keep-modes t)
  5316. (filter org-agenda-filter)
  5317. (preset (get 'org-agenda-filter :preset-filter))
  5318. (org-agenda-filter-while-redo (or filter preset))
  5319. (cols org-agenda-columns-active)
  5320. (line (org-current-line))
  5321. (window-line (- line (org-current-line (window-start))))
  5322. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5323. (put 'org-agenda-filter :preset-filter nil)
  5324. (and cols (org-columns-quit))
  5325. (message "Rebuilding agenda buffer...")
  5326. (org-let lprops '(eval org-agenda-redo-command))
  5327. (setq org-agenda-undo-list nil
  5328. org-agenda-pending-undo-list nil)
  5329. (message "Rebuilding agenda buffer...done")
  5330. (put 'org-agenda-filter :preset-filter preset)
  5331. (and (or filter preset) (org-agenda-filter-apply filter))
  5332. (and cols (interactive-p) (org-agenda-columns))
  5333. (org-goto-line line)
  5334. (recenter window-line)))
  5335. (defvar org-global-tags-completion-table nil)
  5336. (defvar org-agenda-filter-form nil)
  5337. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5338. "Keep only those lines in the agenda buffer that have a specific tag.
  5339. The tag is selected with its fast selection letter, as configured.
  5340. With prefix argument STRIP, remove all lines that do have the tag.
  5341. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5342. used to narrow the search - the interactive user can also press `-' or `+'
  5343. to switch to narrowing."
  5344. (interactive "P")
  5345. (let* ((alist org-tag-alist-for-agenda)
  5346. (tag-chars (mapconcat
  5347. (lambda (x) (if (and (not (symbolp (car x)))
  5348. (cdr x))
  5349. (char-to-string (cdr x))
  5350. ""))
  5351. alist ""))
  5352. (efforts (org-split-string
  5353. (or (cdr (assoc (concat org-effort-property "_ALL")
  5354. org-global-properties))
  5355. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5356. (effort-op org-agenda-filter-effort-default-operator)
  5357. (effort-prompt "")
  5358. (inhibit-read-only t)
  5359. (current org-agenda-filter)
  5360. a n tag)
  5361. (unless char
  5362. (message
  5363. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5364. (if narrow "Narrow" "Filter") tag-chars
  5365. (if org-agenda-auto-exclude-function "[RET], " ""))
  5366. (setq char (read-char)))
  5367. (when (member char '(?+ ?-))
  5368. ;; Narrowing down
  5369. (cond ((equal char ?-) (setq strip t narrow t))
  5370. ((equal char ?+) (setq strip nil narrow t)))
  5371. (message
  5372. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5373. (setq char (read-char)))
  5374. (when (member char '(?< ?> ?= ??))
  5375. ;; An effort operator
  5376. (setq effort-op (char-to-string char))
  5377. (setq alist nil) ; to make sure it will be interpreted as effort.
  5378. (unless (equal char ??)
  5379. (loop for i from 0 to 9 do
  5380. (setq effort-prompt
  5381. (concat
  5382. effort-prompt " ["
  5383. (if (= i 9) "0" (int-to-string (1+ i)))
  5384. "]" (nth i efforts))))
  5385. (message "Effort%s: %s " effort-op effort-prompt)
  5386. (setq char (read-char))
  5387. (when (or (< char ?0) (> char ?9))
  5388. (error "Need 1-9,0 to select effort" ))))
  5389. (when (equal char ?\t)
  5390. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5391. (org-set-local 'org-global-tags-completion-table
  5392. (org-global-tags-completion-table)))
  5393. (let ((completion-ignore-case t))
  5394. (setq tag (org-icompleting-read
  5395. "Tag: " org-global-tags-completion-table))))
  5396. (cond
  5397. ((equal char ?\r)
  5398. (org-agenda-filter-by-tag-show-all)
  5399. (when org-agenda-auto-exclude-function
  5400. (setq org-agenda-filter '())
  5401. (dolist (tag (org-agenda-get-represented-tags))
  5402. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5403. (if modifier
  5404. (push modifier org-agenda-filter))))
  5405. (if (not (null org-agenda-filter))
  5406. (org-agenda-filter-apply org-agenda-filter))))
  5407. ((equal char ?/)
  5408. (org-agenda-filter-by-tag-show-all)
  5409. (when (get 'org-agenda-filter :preset-filter)
  5410. (org-agenda-filter-apply org-agenda-filter)))
  5411. ((or (equal char ?\ )
  5412. (setq a (rassoc char alist))
  5413. (and (>= char ?0) (<= char ?9)
  5414. (setq n (if (= char ?0) 9 (- char ?0 1))
  5415. tag (concat effort-op (nth n efforts))
  5416. a (cons tag nil)))
  5417. (and (= char ??)
  5418. (setq tag "?eff")
  5419. a (cons tag nil))
  5420. (and tag (setq a (cons tag nil))))
  5421. (org-agenda-filter-by-tag-show-all)
  5422. (setq tag (car a))
  5423. (setq org-agenda-filter
  5424. (cons (concat (if strip "-" "+") tag)
  5425. (if narrow current nil)))
  5426. (org-agenda-filter-apply org-agenda-filter))
  5427. (t (error "Invalid tag selection character %c" char)))))
  5428. (defun org-agenda-get-represented-tags ()
  5429. "Get a list of all tags currently represented in the agenda."
  5430. (let (p tags)
  5431. (save-excursion
  5432. (goto-char (point-min))
  5433. (while (setq p (next-single-property-change (point) 'tags))
  5434. (goto-char p)
  5435. (mapc (lambda (x) (add-to-list 'tags x))
  5436. (get-text-property (point) 'tags))))
  5437. tags))
  5438. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5439. "Refine the current filter. See `org-agenda-filter-by-tag."
  5440. (interactive "P")
  5441. (org-agenda-filter-by-tag strip char 'refine))
  5442. (defun org-agenda-filter-make-matcher ()
  5443. "Create the form that tests a line for the agenda filter."
  5444. (let (f f1)
  5445. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5446. org-agenda-filter))
  5447. (if (member x '("-" "+"))
  5448. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5449. (if (string-match "[<=>?]" x)
  5450. (setq f1 (org-agenda-filter-effort-form x))
  5451. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5452. (if (equal (string-to-char x) ?-)
  5453. (setq f1 (list 'not f1))))
  5454. (push f1 f))
  5455. (cons 'and (nreverse f))))
  5456. (defun org-agenda-filter-effort-form (e)
  5457. "Return the form to compare the effort of the current line with what E says.
  5458. E looks like \"+<2:25\"."
  5459. (let (op)
  5460. (setq e (substring e 1))
  5461. (setq op (string-to-char e) e (substring e 1))
  5462. (setq op (cond ((equal op ?<) '<=)
  5463. ((equal op ?>) '>=)
  5464. ((equal op ??) op)
  5465. (t '=)))
  5466. (list 'org-agenda-compare-effort (list 'quote op)
  5467. (org-hh:mm-string-to-minutes e))))
  5468. (defun org-agenda-compare-effort (op value)
  5469. "Compare the effort of the current line with VALUE, using OP.
  5470. If the line does not have an effort defined, return nil."
  5471. (let ((eff (org-get-at-bol 'effort-minutes)))
  5472. (if (equal op ??)
  5473. (not eff)
  5474. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5475. value))))
  5476. (defun org-agenda-filter-apply (filter)
  5477. "Set FILTER as the new agenda filter and apply it."
  5478. (let (tags)
  5479. (setq org-agenda-filter filter
  5480. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5481. (org-agenda-set-mode-name)
  5482. (save-excursion
  5483. (goto-char (point-min))
  5484. (while (not (eobp))
  5485. (if (org-get-at-bol 'org-marker)
  5486. (progn
  5487. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5488. (if (not (eval org-agenda-filter-form))
  5489. (org-agenda-filter-by-tag-hide-line))
  5490. (beginning-of-line 2))
  5491. (beginning-of-line 2))))
  5492. (if (get-char-property (point) 'invisible)
  5493. (org-agenda-previous-line))))
  5494. (defun org-agenda-filter-by-tag-hide-line ()
  5495. (let (ov)
  5496. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5497. (point-at-eol)))
  5498. (overlay-put ov 'invisible t)
  5499. (overlay-put ov 'type 'tags-filter)
  5500. (push ov org-agenda-filter-overlays)))
  5501. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5502. (setq pos (or pos (point)))
  5503. (save-excursion
  5504. (dolist (ov (overlays-at pos))
  5505. (when (and (overlay-get ov 'invisible)
  5506. (eq (overlay-get ov 'type) 'tags-filter))
  5507. (goto-char pos)
  5508. (if (< (overlay-start ov) (point-at-eol))
  5509. (move-overlay ov (point-at-eol)
  5510. (overlay-end ov)))))))
  5511. (defun org-agenda-filter-by-tag-show-all ()
  5512. (mapc 'delete-overlay org-agenda-filter-overlays)
  5513. (setq org-agenda-filter-overlays nil)
  5514. (setq org-agenda-filter nil)
  5515. (setq org-agenda-filter-form nil)
  5516. (org-agenda-set-mode-name))
  5517. (defun org-agenda-manipulate-query-add ()
  5518. "Manipulate the query by adding a search term with positive selection.
  5519. Positive selection means the term must be matched for selection of an entry."
  5520. (interactive)
  5521. (org-agenda-manipulate-query ?\[))
  5522. (defun org-agenda-manipulate-query-subtract ()
  5523. "Manipulate the query by adding a search term with negative selection.
  5524. Negative selection means term must not be matched for selection of an entry."
  5525. (interactive)
  5526. (org-agenda-manipulate-query ?\]))
  5527. (defun org-agenda-manipulate-query-add-re ()
  5528. "Manipulate the query by adding a search regexp with positive selection.
  5529. Positive selection means the regexp must match for selection of an entry."
  5530. (interactive)
  5531. (org-agenda-manipulate-query ?\{))
  5532. (defun org-agenda-manipulate-query-subtract-re ()
  5533. "Manipulate the query by adding a search regexp with negative selection.
  5534. Negative selection means regexp must not match for selection of an entry."
  5535. (interactive)
  5536. (org-agenda-manipulate-query ?\}))
  5537. (defun org-agenda-manipulate-query (char)
  5538. (cond
  5539. ((memq org-agenda-type '(timeline agenda))
  5540. (let ((org-agenda-include-inactive-timestamps t))
  5541. (org-agenda-redo))
  5542. (message "Display now includes inactive timestamps as well"))
  5543. ((eq org-agenda-type 'search)
  5544. (org-add-to-string
  5545. 'org-agenda-query-string
  5546. (if org-agenda-last-search-view-search-was-boolean
  5547. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5548. (?\{ . " +{}") (?\} . " -{}"))))
  5549. " "))
  5550. (setq org-agenda-redo-command
  5551. (list 'org-search-view
  5552. org-todo-only
  5553. org-agenda-query-string
  5554. (+ (length org-agenda-query-string)
  5555. (if (member char '(?\{ ?\})) 0 1))))
  5556. (set-register org-agenda-query-register org-agenda-query-string)
  5557. (org-agenda-redo))
  5558. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5559. org-agenda-type))))
  5560. (defun org-add-to-string (var string)
  5561. (set var (concat (symbol-value var) string)))
  5562. (defun org-agenda-goto-date (date)
  5563. "Jump to DATE in agenda."
  5564. (interactive (list (let ((org-read-date-prefer-future
  5565. (eval org-agenda-jump-prefer-future)))
  5566. (org-read-date))))
  5567. (org-agenda-list nil date))
  5568. (defun org-agenda-goto-today ()
  5569. "Go to today."
  5570. (interactive)
  5571. (org-agenda-check-type t 'timeline 'agenda)
  5572. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5573. (cond
  5574. (tdpos (goto-char tdpos))
  5575. ((eq org-agenda-type 'agenda)
  5576. (let* ((sd (org-agenda-today))
  5577. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5578. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5579. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5580. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5581. (org-agenda-redo)
  5582. (org-agenda-find-same-or-today-or-agenda)))
  5583. (t (error "Cannot find today")))))
  5584. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5585. (goto-char
  5586. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5587. (text-property-any (point-min) (point-max) 'org-today t)
  5588. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5589. (point-min))))
  5590. (defun org-agenda-later (arg)
  5591. "Go forward in time by thee current span.
  5592. With prefix ARG, go forward that many times the current span."
  5593. (interactive "p")
  5594. (org-agenda-check-type t 'agenda)
  5595. (let* ((span org-agenda-span)
  5596. (sd org-starting-day)
  5597. (greg (calendar-gregorian-from-absolute sd))
  5598. (cnt (org-get-at-bol 'org-day-cnt))
  5599. greg2 nd)
  5600. (cond
  5601. ((eq span 'day)
  5602. (setq sd (+ arg sd) nd 1))
  5603. ((eq span 'week)
  5604. (setq sd (+ (* 7 arg) sd) nd 7))
  5605. ((eq span 'month)
  5606. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5607. sd (calendar-absolute-from-gregorian greg2))
  5608. (setcar greg2 (1+ (car greg2)))
  5609. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5610. ((eq span 'year)
  5611. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5612. sd (calendar-absolute-from-gregorian greg2))
  5613. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5614. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5615. (let ((org-agenda-overriding-arguments
  5616. (list (car org-agenda-last-arguments) sd nd t)))
  5617. (org-agenda-redo)
  5618. (org-agenda-find-same-or-today-or-agenda cnt))))
  5619. (defun org-agenda-earlier (arg)
  5620. "Go backward in time by the current span.
  5621. With prefix ARG, go backward that many times the current span."
  5622. (interactive "p")
  5623. (org-agenda-later (- arg)))
  5624. (defun org-agenda-view-mode-dispatch ()
  5625. "Call one of the view mode commands."
  5626. (interactive)
  5627. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5628. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5629. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5630. (let ((a (read-char-exclusive)))
  5631. (case a
  5632. (?d (call-interactively 'org-agenda-day-view))
  5633. (?w (call-interactively 'org-agenda-week-view))
  5634. (?m (call-interactively 'org-agenda-month-view))
  5635. (?y (call-interactively 'org-agenda-year-view))
  5636. (?l (call-interactively 'org-agenda-log-mode))
  5637. (?L (org-agenda-log-mode '(4)))
  5638. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5639. (?a (call-interactively 'org-agenda-archives-mode))
  5640. (?A (org-agenda-archives-mode 'files))
  5641. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5642. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5643. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5644. (?D (call-interactively 'org-agenda-toggle-diary))
  5645. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5646. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5647. (org-agenda-check-type t 'timeline 'agenda)
  5648. (org-agenda-redo))
  5649. (message "Display now includes inactive timestamps as well"))
  5650. (?q (message "Abort"))
  5651. (otherwise (error "Invalid key" )))))
  5652. (defun org-agenda-day-view (&optional day-of-year)
  5653. "Switch to daily view for agenda.
  5654. With argument DAY-OF-YEAR, switch to that day of the year."
  5655. (interactive "P")
  5656. (setq org-agenda-ndays 1)
  5657. (org-agenda-change-time-span 'day day-of-year))
  5658. (defun org-agenda-week-view (&optional iso-week)
  5659. "Switch to daily view for agenda.
  5660. With argument ISO-WEEK, switch to the corresponding ISO week.
  5661. If ISO-WEEK has more then 2 digits, only the last two encode the
  5662. week. Any digits before this encode a year. So 200712 means
  5663. week 12 of year 2007. Years in the range 1938-2037 can also be
  5664. written as 2-digit years."
  5665. (interactive "P")
  5666. (setq org-agenda-ndays 7)
  5667. (org-agenda-change-time-span 'week iso-week))
  5668. (defun org-agenda-month-view (&optional month)
  5669. "Switch to monthly view for agenda.
  5670. With argument MONTH, switch to that month."
  5671. (interactive "P")
  5672. (org-agenda-change-time-span 'month month))
  5673. (defun org-agenda-year-view (&optional year)
  5674. "Switch to yearly view for agenda.
  5675. With argument YEAR, switch to that year.
  5676. If MONTH has more then 2 digits, only the last two encode the
  5677. month. Any digits before this encode a year. So 200712 means
  5678. December year 2007. Years in the range 1938-2037 can also be
  5679. written as 2-digit years."
  5680. (interactive "P")
  5681. (when year
  5682. (setq year (org-small-year-to-year year)))
  5683. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5684. (org-agenda-change-time-span 'year year)
  5685. (error "Abort")))
  5686. (defun org-agenda-change-time-span (span &optional n)
  5687. "Change the agenda view to SPAN.
  5688. SPAN may be `day', `week', `month', `year'."
  5689. (org-agenda-check-type t 'agenda)
  5690. (if (and (not n) (equal org-agenda-span span))
  5691. (error "Viewing span is already \"%s\"" span))
  5692. (let* ((sd (or (org-get-at-bol 'day)
  5693. org-starting-day))
  5694. (computed (org-agenda-compute-time-span sd span n))
  5695. (org-agenda-overriding-arguments
  5696. (list (car org-agenda-last-arguments)
  5697. (car computed) (cdr computed) t)))
  5698. (org-agenda-redo)
  5699. (org-agenda-find-same-or-today-or-agenda))
  5700. (org-agenda-set-mode-name)
  5701. (message "Switched to %s view" span))
  5702. (defun org-agenda-compute-time-span (sd span &optional n)
  5703. "Compute starting date and number of days for agenda.
  5704. SPAN may be `day', `week', `month', `year'. The return value
  5705. is a cons cell with the starting date and the number of days,
  5706. so that the date SD will be in that range."
  5707. (let* ((greg (calendar-gregorian-from-absolute sd))
  5708. (dg (nth 1 greg))
  5709. (mg (car greg))
  5710. (yg (nth 2 greg))
  5711. nd w1 y1 m1 thisweek)
  5712. (cond
  5713. ((eq span 'day)
  5714. (when n
  5715. (setq sd (+ (calendar-absolute-from-gregorian
  5716. (list mg 1 yg))
  5717. n -1)))
  5718. (setq nd 1))
  5719. ((eq span 'week)
  5720. (let* ((nt (calendar-day-of-week
  5721. (calendar-gregorian-from-absolute sd)))
  5722. (d (if org-agenda-start-on-weekday
  5723. (- nt org-agenda-start-on-weekday)
  5724. 0)))
  5725. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5726. (when n
  5727. (require 'cal-iso)
  5728. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5729. (when (> n 99)
  5730. (setq y1 (org-small-year-to-year (/ n 100))
  5731. n (mod n 100)))
  5732. (setq sd
  5733. (calendar-absolute-from-iso
  5734. (list n 1
  5735. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5736. (setq nd 7)))
  5737. ((eq span 'month)
  5738. (when (and n (> n 99))
  5739. (setq y1 (org-small-year-to-year (/ n 100))
  5740. n (mod n 100)))
  5741. (setq sd (calendar-absolute-from-gregorian
  5742. (list (or n mg) 1 (or y1 yg)))
  5743. nd (- (calendar-absolute-from-gregorian
  5744. (list (1+ (or n mg)) 1 (or y1 yg)))
  5745. sd)))
  5746. ((eq span 'year)
  5747. (setq sd (calendar-absolute-from-gregorian
  5748. (list 1 1 (or n yg)))
  5749. nd (- (calendar-absolute-from-gregorian
  5750. (list 1 1 (1+ (or n yg))))
  5751. sd))))
  5752. (cons sd nd)))
  5753. (defun org-agenda-next-date-line (&optional arg)
  5754. "Jump to the next line indicating a date in agenda buffer."
  5755. (interactive "p")
  5756. (org-agenda-check-type t 'agenda 'timeline)
  5757. (beginning-of-line 1)
  5758. ;; This does not work if user makes date format that starts with a blank
  5759. (if (looking-at "^\\S-") (forward-char 1))
  5760. (if (not (re-search-forward "^\\S-" nil t arg))
  5761. (progn
  5762. (backward-char 1)
  5763. (error "No next date after this line in this buffer")))
  5764. (goto-char (match-beginning 0)))
  5765. (defun org-agenda-previous-date-line (&optional arg)
  5766. "Jump to the previous line indicating a date in agenda buffer."
  5767. (interactive "p")
  5768. (org-agenda-check-type t 'agenda 'timeline)
  5769. (beginning-of-line 1)
  5770. (if (not (re-search-backward "^\\S-" nil t arg))
  5771. (error "No previous date before this line in this buffer")))
  5772. ;; Initialize the highlight
  5773. (defvar org-hl (make-overlay 1 1))
  5774. (overlay-put org-hl 'face 'highlight)
  5775. (defun org-highlight (begin end &optional buffer)
  5776. "Highlight a region with overlay."
  5777. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5778. (defun org-unhighlight ()
  5779. "Detach overlay INDEX."
  5780. (org-detach-overlay org-hl))
  5781. ;; FIXME this is currently not used.
  5782. (defun org-highlight-until-next-command (beg end &optional buffer)
  5783. "Move the highlight overlay to BEG/END, remove it before the next command."
  5784. (org-highlight beg end buffer)
  5785. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5786. (defun org-unhighlight-once ()
  5787. "Remove the highlight from its position, and this function from the hook."
  5788. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5789. (org-unhighlight))
  5790. (defun org-agenda-follow-mode ()
  5791. "Toggle follow mode in an agenda buffer."
  5792. (interactive)
  5793. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5794. (org-agenda-set-mode-name)
  5795. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5796. (org-agenda-show))
  5797. (message "Follow mode is %s"
  5798. (if org-agenda-follow-mode "on" "off")))
  5799. (defun org-agenda-entry-text-mode (&optional arg)
  5800. "Toggle entry text mode in an agenda buffer."
  5801. (interactive "P")
  5802. (setq org-agenda-entry-text-mode (or (integerp arg)
  5803. (not org-agenda-entry-text-mode)))
  5804. (org-agenda-entry-text-hide)
  5805. (and org-agenda-entry-text-mode
  5806. (let ((org-agenda-entry-text-maxlines
  5807. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5808. (org-agenda-entry-text-show)))
  5809. (org-agenda-set-mode-name)
  5810. (message "Entry text mode is %s. Maximum number of lines is %d"
  5811. (if org-agenda-entry-text-mode "on" "off")
  5812. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5813. (defun org-agenda-clockreport-mode (&optional with-filter)
  5814. "Toggle clocktable mode in an agenda buffer.
  5815. With prefix arg WITH-FILTER, make the clocktable respect the current
  5816. agenda filter."
  5817. (interactive "P")
  5818. (org-agenda-check-type t 'agenda)
  5819. (if with-filter
  5820. (setq org-agenda-clockreport-mode 'with-filter)
  5821. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5822. (org-agenda-set-mode-name)
  5823. (org-agenda-redo)
  5824. (message "Clocktable mode is %s"
  5825. (if org-agenda-clockreport-mode "on" "off")))
  5826. (defun org-agenda-log-mode (&optional special)
  5827. "Toggle log mode in an agenda buffer.
  5828. With argument SPECIAL, show all possible log items, not only the ones
  5829. configured in `org-agenda-log-mode-items'.
  5830. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5831. (interactive "P")
  5832. (org-agenda-check-type t 'agenda 'timeline)
  5833. (setq org-agenda-show-log
  5834. (if (equal special '(16))
  5835. 'only
  5836. (if special '(closed clock state)
  5837. (not org-agenda-show-log))))
  5838. (org-agenda-set-mode-name)
  5839. (org-agenda-redo)
  5840. (message "Log mode is %s"
  5841. (if org-agenda-show-log "on" "off")))
  5842. (defun org-agenda-archives-mode (&optional with-files)
  5843. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5844. When called with a prefix argument, include all archive files as well."
  5845. (interactive "P")
  5846. (setq org-agenda-archives-mode
  5847. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5848. (org-agenda-set-mode-name)
  5849. (org-agenda-redo)
  5850. (message
  5851. "%s"
  5852. (cond
  5853. ((eq org-agenda-archives-mode nil)
  5854. "No archives are included")
  5855. ((eq org-agenda-archives-mode 'trees)
  5856. (format "Trees with :%s: tag are included" org-archive-tag))
  5857. ((eq org-agenda-archives-mode t)
  5858. (format "Trees with :%s: tag and all active archive files are included"
  5859. org-archive-tag)))))
  5860. (defun org-agenda-toggle-diary ()
  5861. "Toggle diary inclusion in an agenda buffer."
  5862. (interactive)
  5863. (org-agenda-check-type t 'agenda)
  5864. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5865. (org-agenda-redo)
  5866. (org-agenda-set-mode-name)
  5867. (message "Diary inclusion turned %s"
  5868. (if org-agenda-include-diary "on" "off")))
  5869. (defun org-agenda-toggle-deadlines ()
  5870. "Toggle diary inclusion in an agenda buffer."
  5871. (interactive)
  5872. (org-agenda-check-type t 'agenda)
  5873. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5874. (org-agenda-redo)
  5875. (org-agenda-set-mode-name)
  5876. (message "Deadlines inclusion turned %s"
  5877. (if org-agenda-include-deadlines "on" "off")))
  5878. (defun org-agenda-toggle-time-grid ()
  5879. "Toggle time grid in an agenda buffer."
  5880. (interactive)
  5881. (org-agenda-check-type t 'agenda)
  5882. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5883. (org-agenda-redo)
  5884. (org-agenda-set-mode-name)
  5885. (message "Time-grid turned %s"
  5886. (if org-agenda-use-time-grid "on" "off")))
  5887. (defun org-agenda-set-mode-name ()
  5888. "Set the mode name to indicate all the small mode settings."
  5889. (setq mode-name
  5890. (concat "Org-Agenda"
  5891. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5892. (if (equal org-agenda-ndays 1) " Day" "")
  5893. (if (equal org-agenda-ndays 7) " Week" "")
  5894. (if org-agenda-follow-mode " Follow" "")
  5895. (if org-agenda-entry-text-mode " ETxt" "")
  5896. (if org-agenda-include-diary " Diary" "")
  5897. (if org-agenda-include-deadlines " Ddl" "")
  5898. (if org-agenda-use-time-grid " Grid" "")
  5899. (if (and (boundp 'org-habit-show-habits)
  5900. org-habit-show-habits) " Habit" "")
  5901. (if (consp org-agenda-show-log) " LogAll"
  5902. (if org-agenda-show-log " Log" ""))
  5903. (if (or org-agenda-filter (get 'org-agenda-filter
  5904. :preset-filter))
  5905. (concat " {" (mapconcat
  5906. 'identity
  5907. (append (get 'org-agenda-filter
  5908. :preset-filter)
  5909. org-agenda-filter) "") "}")
  5910. "")
  5911. (if org-agenda-archives-mode
  5912. (if (eq org-agenda-archives-mode t)
  5913. " Archives"
  5914. (format " :%s:" org-archive-tag))
  5915. "")
  5916. (if org-agenda-clockreport-mode
  5917. (if (eq org-agenda-clockreport-mode 'with-filter)
  5918. " Clock{}" " Clock")
  5919. "")))
  5920. (force-mode-line-update))
  5921. (defun org-agenda-post-command-hook ()
  5922. (setq org-agenda-type
  5923. (or (get-text-property (point) 'org-agenda-type)
  5924. (get-text-property (max (point-min) (1- (point)))
  5925. 'org-agenda-type))))
  5926. (defun org-agenda-next-line ()
  5927. "Move cursor to the next line, and show if follow mode is active."
  5928. (interactive)
  5929. (call-interactively 'next-line)
  5930. (org-agenda-do-context-action))
  5931. (defun org-agenda-previous-line ()
  5932. "Move cursor to the previous line, and show if follow-mode is active."
  5933. (interactive)
  5934. (call-interactively 'previous-line)
  5935. (org-agenda-do-context-action))
  5936. (defun org-agenda-do-context-action ()
  5937. "Show outline path and, maybe, follow mode window."
  5938. (let ((m (org-get-at-bol 'org-marker)))
  5939. (if (and org-agenda-follow-mode m)
  5940. (org-agenda-show))
  5941. (if (and m org-agenda-show-outline-path)
  5942. (org-with-point-at m
  5943. (org-display-outline-path t)))))
  5944. (defun org-agenda-show-priority ()
  5945. "Show the priority of the current item.
  5946. This priority is composed of the main priority given with the [#A] cookies,
  5947. and by additional input from the age of a schedules or deadline entry."
  5948. (interactive)
  5949. (let* ((pri (org-get-at-bol 'priority)))
  5950. (message "Priority is %d" (if pri pri -1000))))
  5951. (defun org-agenda-show-tags ()
  5952. "Show the tags applicable to the current item."
  5953. (interactive)
  5954. (let* ((tags (org-get-at-bol 'tags)))
  5955. (if tags
  5956. (message "Tags are :%s:"
  5957. (org-no-properties (mapconcat 'identity tags ":")))
  5958. (message "No tags associated with this line"))))
  5959. (defun org-agenda-goto (&optional highlight)
  5960. "Go to the Org-mode file which contains the item at point."
  5961. (interactive)
  5962. (let* ((marker (or (org-get-at-bol 'org-marker)
  5963. (org-agenda-error)))
  5964. (buffer (marker-buffer marker))
  5965. (pos (marker-position marker)))
  5966. (switch-to-buffer-other-window buffer)
  5967. (widen)
  5968. (push-mark)
  5969. (goto-char pos)
  5970. (when (org-mode-p)
  5971. (org-show-context 'agenda)
  5972. (save-excursion
  5973. (and (outline-next-heading)
  5974. (org-flag-heading nil)))) ; show the next heading
  5975. (recenter (/ (window-height) 2))
  5976. (run-hooks 'org-agenda-after-show-hook)
  5977. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5978. (defvar org-agenda-after-show-hook nil
  5979. "Normal hook run after an item has been shown from the agenda.
  5980. Point is in the buffer where the item originated.")
  5981. (defun org-agenda-kill ()
  5982. "Kill the entry or subtree belonging to the current agenda entry."
  5983. (interactive)
  5984. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5985. (let* ((marker (or (org-get-at-bol 'org-marker)
  5986. (org-agenda-error)))
  5987. (buffer (marker-buffer marker))
  5988. (pos (marker-position marker))
  5989. (type (org-get-at-bol 'type))
  5990. dbeg dend (n 0) conf)
  5991. (org-with-remote-undo buffer
  5992. (with-current-buffer buffer
  5993. (save-excursion
  5994. (goto-char pos)
  5995. (if (and (org-mode-p) (not (member type '("sexp"))))
  5996. (setq dbeg (progn (org-back-to-heading t) (point))
  5997. dend (org-end-of-subtree t t))
  5998. (setq dbeg (point-at-bol)
  5999. dend (min (point-max) (1+ (point-at-eol)))))
  6000. (goto-char dbeg)
  6001. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6002. (setq conf (or (eq t org-agenda-confirm-kill)
  6003. (and (numberp org-agenda-confirm-kill)
  6004. (> n org-agenda-confirm-kill))))
  6005. (and conf
  6006. (not (y-or-n-p
  6007. (format "Delete entry with %d lines in buffer \"%s\"? "
  6008. n (buffer-name buffer))))
  6009. (error "Abort"))
  6010. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6011. (with-current-buffer buffer (delete-region dbeg dend))
  6012. (message "Agenda item and source killed"))))
  6013. (defvar org-archive-default-command)
  6014. (defun org-agenda-archive-default ()
  6015. "Archive the entry or subtree belonging to the current agenda entry."
  6016. (interactive)
  6017. (require 'org-archive)
  6018. (org-agenda-archive-with org-archive-default-command))
  6019. (defun org-agenda-archive-default-with-confirmation ()
  6020. "Archive the entry or subtree belonging to the current agenda entry."
  6021. (interactive)
  6022. (require 'org-archive)
  6023. (org-agenda-archive-with org-archive-default-command 'confirm))
  6024. (defun org-agenda-archive ()
  6025. "Archive the entry or subtree belonging to the current agenda entry."
  6026. (interactive)
  6027. (org-agenda-archive-with 'org-archive-subtree))
  6028. (defun org-agenda-archive-to-archive-sibling ()
  6029. "Move the entry to the archive sibling."
  6030. (interactive)
  6031. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6032. (defun org-agenda-archive-with (cmd &optional confirm)
  6033. "Move the entry to the archive sibling."
  6034. (interactive)
  6035. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6036. (let* ((marker (or (org-get-at-bol 'org-marker)
  6037. (org-agenda-error)))
  6038. (buffer (marker-buffer marker))
  6039. (pos (marker-position marker)))
  6040. (org-with-remote-undo buffer
  6041. (with-current-buffer buffer
  6042. (if (org-mode-p)
  6043. (if (and confirm
  6044. (not (y-or-n-p "Archive this subtree or entry? ")))
  6045. (error "Abort")
  6046. (save-excursion
  6047. (goto-char pos)
  6048. (org-remove-subtree-entries-from-agenda)
  6049. (org-back-to-heading t)
  6050. (funcall cmd)))
  6051. (error "Archiving works only in Org-mode files"))))))
  6052. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6053. "Remove all lines in the agenda that correspond to a given subtree.
  6054. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6055. If this information is not given, the function uses the tree at point."
  6056. (let ((buf (or buf (current-buffer))) m p)
  6057. (save-excursion
  6058. (unless (and beg end)
  6059. (org-back-to-heading t)
  6060. (setq beg (point))
  6061. (org-end-of-subtree t)
  6062. (setq end (point)))
  6063. (set-buffer (get-buffer org-agenda-buffer-name))
  6064. (save-excursion
  6065. (goto-char (point-max))
  6066. (beginning-of-line 1)
  6067. (while (not (bobp))
  6068. (when (and (setq m (org-get-at-bol 'org-marker))
  6069. (equal buf (marker-buffer m))
  6070. (setq p (marker-position m))
  6071. (>= p beg)
  6072. (< p end))
  6073. (let ((inhibit-read-only t))
  6074. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6075. (beginning-of-line 0))))))
  6076. (defun org-agenda-refile (&optional goto rfloc no-update)
  6077. "Refile the item at point."
  6078. (interactive "P")
  6079. (if (equal goto '(16))
  6080. (org-refile-goto-last-stored)
  6081. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6082. (org-agenda-error)))
  6083. (buffer (marker-buffer marker))
  6084. (pos (marker-position marker))
  6085. (rfloc (or rfloc
  6086. (org-refile-get-location
  6087. (if goto "Goto: " "Refile to: ") buffer
  6088. org-refile-allow-creating-parent-nodes))))
  6089. (with-current-buffer buffer
  6090. (save-excursion
  6091. (save-restriction
  6092. (widen)
  6093. (goto-char marker)
  6094. (org-remove-subtree-entries-from-agenda)
  6095. (org-refile goto buffer rfloc)))))
  6096. (unless no-update (org-agenda-redo))))
  6097. (defun org-agenda-open-link (&optional arg)
  6098. "Follow the link in the current line, if any.
  6099. This looks for a link in the displayed line in the agenda. It also looks
  6100. at the text of the entry itself."
  6101. (interactive "P")
  6102. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6103. (org-get-at-bol 'org-marker)))
  6104. (buffer (and marker (marker-buffer marker)))
  6105. (prefix (buffer-substring
  6106. (point-at-bol)
  6107. (+ (point-at-bol)
  6108. (or (org-get-at-bol 'prefix-length) 0)))))
  6109. (cond
  6110. (buffer
  6111. (with-current-buffer buffer
  6112. (save-excursion
  6113. (save-restriction
  6114. (widen)
  6115. (goto-char marker)
  6116. (org-offer-links-in-entry arg prefix)))))
  6117. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6118. (save-excursion
  6119. (beginning-of-line 1)
  6120. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6121. (org-open-link-from-string (match-string 1)))
  6122. (t (error "No link to open here")))))
  6123. (defun org-agenda-copy-local-variable (var)
  6124. "Get a variable from a referenced buffer and install it here."
  6125. (let ((m (org-get-at-bol 'org-marker)))
  6126. (when (and m (buffer-live-p (marker-buffer m)))
  6127. (org-set-local var (with-current-buffer (marker-buffer m)
  6128. (symbol-value var))))))
  6129. (defun org-agenda-switch-to (&optional delete-other-windows)
  6130. "Go to the Org-mode file which contains the item at point."
  6131. (interactive)
  6132. (if (and org-return-follows-link
  6133. (not (org-get-at-bol 'org-marker))
  6134. (org-in-regexp org-bracket-link-regexp))
  6135. (org-open-link-from-string (match-string 0))
  6136. (let* ((marker (or (org-get-at-bol 'org-marker)
  6137. (org-agenda-error)))
  6138. (buffer (marker-buffer marker))
  6139. (pos (marker-position marker)))
  6140. (switch-to-buffer buffer)
  6141. (and delete-other-windows (delete-other-windows))
  6142. (widen)
  6143. (goto-char pos)
  6144. (when (org-mode-p)
  6145. (org-show-context 'agenda)
  6146. (save-excursion
  6147. (and (outline-next-heading)
  6148. (org-flag-heading nil))))))) ; show the next heading
  6149. (defun org-agenda-goto-mouse (ev)
  6150. "Go to the Org-mode file which contains the item at the mouse click."
  6151. (interactive "e")
  6152. (mouse-set-point ev)
  6153. (org-agenda-goto))
  6154. (defun org-agenda-show (&optional full-entry)
  6155. "Display the Org-mode file which contains the item at point.
  6156. With prefix argument FULL-ENTRY, make the entire entry visible
  6157. if it was hidden in the outline."
  6158. (interactive "P")
  6159. (let ((win (selected-window)))
  6160. (if full-entry
  6161. (let ((org-show-entry-below t))
  6162. (org-agenda-goto t))
  6163. (org-agenda-goto t))
  6164. (select-window win)))
  6165. (defvar org-agenda-show-window nil)
  6166. (defun org-agenda-show-and-scroll-up ()
  6167. "Display the Org-mode file which contains the item at point.
  6168. When called repeatedly, scroll the window that is displaying the buffer."
  6169. (interactive)
  6170. (let ((win (selected-window)))
  6171. (if (and (window-live-p org-agenda-show-window)
  6172. (eq this-command last-command))
  6173. (progn
  6174. (select-window org-agenda-show-window)
  6175. (ignore-errors (scroll-up)))
  6176. (org-agenda-goto t)
  6177. (show-subtree)
  6178. (setq org-agenda-show-window (selected-window)))
  6179. (select-window win)))
  6180. (defun org-agenda-show-scroll-down ()
  6181. "Scroll down the window showing the agenda."
  6182. (interactive)
  6183. (let ((win (selected-window)))
  6184. (when (window-live-p org-agenda-show-window)
  6185. (select-window org-agenda-show-window)
  6186. (ignore-errors (scroll-down))
  6187. (select-window win))))
  6188. (defun org-agenda-show-1 (&optional more)
  6189. "Display the Org-mode file which contains the item at point.
  6190. The prefix arg selects the amount of information to display:
  6191. 0 hide the subtree
  6192. 1 just show the entry according to defaults.
  6193. 2 show the children view
  6194. 3 show the subtree view
  6195. 4 show the entire subtree and any LOGBOOK drawers
  6196. 5 show the entire subtree and any drawers
  6197. With prefix argument FULL-ENTRY, make the entire entry visible
  6198. if it was hidden in the outline."
  6199. (interactive "p")
  6200. (let ((win (selected-window)))
  6201. (org-agenda-goto t)
  6202. (org-recenter-heading 1)
  6203. (cond
  6204. ((= more 0)
  6205. (hide-subtree)
  6206. (save-excursion
  6207. (org-back-to-heading)
  6208. (run-hook-with-args 'org-cycle-hook 'folded))
  6209. (message "Remote: FOLDED"))
  6210. ((and (interactive-p) (= more 1))
  6211. (message "Remote: show with default settings"))
  6212. ((= more 2)
  6213. (show-entry)
  6214. (show-children)
  6215. (save-excursion
  6216. (org-back-to-heading)
  6217. (run-hook-with-args 'org-cycle-hook 'children))
  6218. (message "Remote: CHILDREN"))
  6219. ((= more 3)
  6220. (show-subtree)
  6221. (save-excursion
  6222. (org-back-to-heading)
  6223. (run-hook-with-args 'org-cycle-hook 'subtree))
  6224. (message "Remote: SUBTREE"))
  6225. ((= more 4)
  6226. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6227. (org-drawer-regexp
  6228. (concat "^[ \t]*:\\("
  6229. (mapconcat 'regexp-quote org-drawers "\\|")
  6230. "\\):[ \t]*$")))
  6231. (show-subtree)
  6232. (save-excursion
  6233. (org-back-to-heading)
  6234. (org-cycle-hide-drawers 'subtree)))
  6235. (message "Remote: SUBTREE AND LOGBOOK"))
  6236. ((> more 4)
  6237. (show-subtree)
  6238. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6239. (select-window win)))
  6240. (defun org-recenter-heading (n)
  6241. (save-excursion
  6242. (org-back-to-heading)
  6243. (recenter n)))
  6244. (defvar org-agenda-cycle-counter nil)
  6245. (defun org-agenda-cycle-show (&optional n)
  6246. "Show the current entry in another window, with default settings.
  6247. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6248. When use repeatedly in immediate succession, the remote entry will cycle
  6249. through visibility
  6250. children -> subtree -> folded
  6251. When called with a numeric prefix arg, that arg will be passed through to
  6252. `org-agenda-show-1'. For the interpretation of that argument, see the
  6253. docstring of `org-agenda-show-1'."
  6254. (interactive "P")
  6255. (if (integerp n)
  6256. (setq org-agenda-cycle-counter n)
  6257. (if (not (eq last-command this-command))
  6258. (setq org-agenda-cycle-counter 1)
  6259. (if (equal org-agenda-cycle-counter 0)
  6260. (setq org-agenda-cycle-counter 2)
  6261. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6262. (if (> org-agenda-cycle-counter 3)
  6263. (setq org-agenda-cycle-counter 0)))))
  6264. (org-agenda-show-1 org-agenda-cycle-counter))
  6265. (defun org-agenda-recenter (arg)
  6266. "Display the Org-mode file which contains the item at point and recenter."
  6267. (interactive "P")
  6268. (let ((win (selected-window)))
  6269. (org-agenda-goto t)
  6270. (recenter arg)
  6271. (select-window win)))
  6272. (defun org-agenda-show-mouse (ev)
  6273. "Display the Org-mode file which contains the item at the mouse click."
  6274. (interactive "e")
  6275. (mouse-set-point ev)
  6276. (org-agenda-show))
  6277. (defun org-agenda-check-no-diary ()
  6278. "Check if the entry is a diary link and abort if yes."
  6279. (if (org-get-at-bol 'org-agenda-diary-link)
  6280. (org-agenda-error)))
  6281. (defun org-agenda-error ()
  6282. (error "Command not allowed in this line"))
  6283. (defun org-agenda-tree-to-indirect-buffer ()
  6284. "Show the subtree corresponding to the current entry in an indirect buffer.
  6285. This calls the command `org-tree-to-indirect-buffer' from the original
  6286. Org-mode buffer.
  6287. With numerical prefix arg ARG, go up to this level and then take that tree.
  6288. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6289. use the dedicated frame)."
  6290. (interactive)
  6291. (org-agenda-check-no-diary)
  6292. (let* ((marker (or (org-get-at-bol 'org-marker)
  6293. (org-agenda-error)))
  6294. (buffer (marker-buffer marker))
  6295. (pos (marker-position marker)))
  6296. (with-current-buffer buffer
  6297. (save-excursion
  6298. (goto-char pos)
  6299. (call-interactively 'org-tree-to-indirect-buffer)))))
  6300. (defvar org-last-heading-marker (make-marker)
  6301. "Marker pointing to the headline that last changed its TODO state
  6302. by a remote command from the agenda.")
  6303. (defun org-agenda-todo-nextset ()
  6304. "Switch TODO entry to next sequence."
  6305. (interactive)
  6306. (org-agenda-todo 'nextset))
  6307. (defun org-agenda-todo-previousset ()
  6308. "Switch TODO entry to previous sequence."
  6309. (interactive)
  6310. (org-agenda-todo 'previousset))
  6311. (defun org-agenda-todo (&optional arg)
  6312. "Cycle TODO state of line at point, also in Org-mode file.
  6313. This changes the line at point, all other lines in the agenda referring to
  6314. the same tree node, and the headline of the tree node in the Org-mode file."
  6315. (interactive "P")
  6316. (org-agenda-check-no-diary)
  6317. (let* ((col (current-column))
  6318. (marker (or (org-get-at-bol 'org-marker)
  6319. (org-agenda-error)))
  6320. (buffer (marker-buffer marker))
  6321. (pos (marker-position marker))
  6322. (hdmarker (org-get-at-bol 'org-hd-marker))
  6323. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6324. (inhibit-read-only t)
  6325. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6326. (org-with-remote-undo buffer
  6327. (with-current-buffer buffer
  6328. (widen)
  6329. (goto-char pos)
  6330. (org-show-context 'agenda)
  6331. (save-excursion
  6332. (and (outline-next-heading)
  6333. (org-flag-heading nil))) ; show the next heading
  6334. (let ((current-prefix-arg arg))
  6335. (call-interactively 'org-todo))
  6336. (and (bolp) (forward-char 1))
  6337. (setq newhead (org-get-heading))
  6338. (when (and (org-bound-and-true-p
  6339. org-agenda-headline-snapshot-before-repeat)
  6340. (not (equal org-agenda-headline-snapshot-before-repeat
  6341. newhead))
  6342. todayp)
  6343. (setq newhead org-agenda-headline-snapshot-before-repeat
  6344. just-one t))
  6345. (save-excursion
  6346. (org-back-to-heading)
  6347. (move-marker org-last-heading-marker (point))))
  6348. (beginning-of-line 1)
  6349. (save-excursion
  6350. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6351. (org-move-to-column col))))
  6352. (defun org-agenda-add-note (&optional arg)
  6353. "Add a time-stamped note to the entry at point."
  6354. (interactive "P")
  6355. (org-agenda-check-no-diary)
  6356. (let* ((marker (or (org-get-at-bol 'org-marker)
  6357. (org-agenda-error)))
  6358. (buffer (marker-buffer marker))
  6359. (pos (marker-position marker))
  6360. (hdmarker (org-get-at-bol 'org-hd-marker))
  6361. (inhibit-read-only t))
  6362. (with-current-buffer buffer
  6363. (widen)
  6364. (goto-char pos)
  6365. (org-show-context 'agenda)
  6366. (save-excursion
  6367. (and (outline-next-heading)
  6368. (org-flag-heading nil))) ; show the next heading
  6369. (org-add-note))))
  6370. (defun org-agenda-change-all-lines (newhead hdmarker
  6371. &optional fixface just-this)
  6372. "Change all lines in the agenda buffer which match HDMARKER.
  6373. The new content of the line will be NEWHEAD (as modified by
  6374. `org-format-agenda-item'). HDMARKER is checked with
  6375. `equal' against all `org-hd-marker' text properties in the file.
  6376. If FIXFACE is non-nil, the face of each item is modified according to
  6377. the new TODO state.
  6378. If JUST-THIS is non-nil, change just the current line, not all.
  6379. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6380. (let* ((inhibit-read-only t)
  6381. (line (org-current-line))
  6382. (thetags (with-current-buffer (marker-buffer hdmarker)
  6383. (save-excursion (save-restriction (widen)
  6384. (goto-char hdmarker)
  6385. (org-get-tags-at)))))
  6386. props m pl undone-face done-face finish new dotime cat tags)
  6387. (save-excursion
  6388. (goto-char (point-max))
  6389. (beginning-of-line 1)
  6390. (while (not finish)
  6391. (setq finish (bobp))
  6392. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6393. (or (not just-this) (= (org-current-line) line))
  6394. (equal m hdmarker))
  6395. (setq props (text-properties-at (point))
  6396. dotime (org-get-at-bol 'dotime)
  6397. cat (org-get-at-bol 'org-category)
  6398. tags thetags
  6399. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6400. pl (org-get-at-bol 'prefix-length)
  6401. undone-face (org-get-at-bol 'undone-face)
  6402. done-face (org-get-at-bol 'done-face))
  6403. (goto-char (+ (point) pl))
  6404. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6405. (cond
  6406. ((equal new "")
  6407. (beginning-of-line 1)
  6408. (and (looking-at ".*\n?") (replace-match "")))
  6409. ((looking-at ".*")
  6410. (replace-match new t t)
  6411. (beginning-of-line 1)
  6412. (add-text-properties (point-at-bol) (point-at-eol) props)
  6413. (when fixface
  6414. (add-text-properties
  6415. (point-at-bol) (point-at-eol)
  6416. (list 'face
  6417. (if org-last-todo-state-is-todo
  6418. undone-face done-face))))
  6419. (org-agenda-highlight-todo 'line)
  6420. (beginning-of-line 1))
  6421. (t (error "Line update did not work"))))
  6422. (beginning-of-line 0)))
  6423. (org-finalize-agenda)))
  6424. (defun org-agenda-align-tags (&optional line)
  6425. "Align all tags in agenda items to `org-agenda-tags-column'."
  6426. (let ((inhibit-read-only t) l c)
  6427. (save-excursion
  6428. (goto-char (if line (point-at-bol) (point-min)))
  6429. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6430. (if line (point-at-eol) nil) t)
  6431. (add-text-properties
  6432. (match-beginning 2) (match-end 2)
  6433. (list 'face (delq nil (let ((prop (get-text-property
  6434. (match-beginning 2) 'face)))
  6435. (or (listp prop) (setq prop (list prop)))
  6436. (if (memq 'org-tag prop)
  6437. prop
  6438. (cons 'org-tag prop))))))
  6439. (setq l (- (match-end 2) (match-beginning 2))
  6440. c (if (< org-agenda-tags-column 0)
  6441. (- (abs org-agenda-tags-column) l)
  6442. org-agenda-tags-column))
  6443. (delete-region (match-beginning 1) (match-end 1))
  6444. (goto-char (match-beginning 1))
  6445. (insert (org-add-props
  6446. (make-string (max 1 (- c (current-column))) ?\ )
  6447. (plist-put (copy-sequence (text-properties-at (point)))
  6448. 'face nil))))
  6449. (goto-char (point-min))
  6450. (org-font-lock-add-tag-faces (point-max)))))
  6451. (defun org-agenda-priority-up ()
  6452. "Increase the priority of line at point, also in Org-mode file."
  6453. (interactive)
  6454. (org-agenda-priority 'up))
  6455. (defun org-agenda-priority-down ()
  6456. "Decrease the priority of line at point, also in Org-mode file."
  6457. (interactive)
  6458. (org-agenda-priority 'down))
  6459. (defun org-agenda-priority (&optional force-direction)
  6460. "Set the priority of line at point, also in Org-mode file.
  6461. This changes the line at point, all other lines in the agenda referring to
  6462. the same tree node, and the headline of the tree node in the Org-mode file."
  6463. (interactive)
  6464. (unless org-enable-priority-commands
  6465. (error "Priority commands are disabled"))
  6466. (org-agenda-check-no-diary)
  6467. (let* ((marker (or (org-get-at-bol 'org-marker)
  6468. (org-agenda-error)))
  6469. (hdmarker (org-get-at-bol 'org-hd-marker))
  6470. (buffer (marker-buffer hdmarker))
  6471. (pos (marker-position hdmarker))
  6472. (inhibit-read-only t)
  6473. newhead)
  6474. (org-with-remote-undo buffer
  6475. (with-current-buffer buffer
  6476. (widen)
  6477. (goto-char pos)
  6478. (org-show-context 'agenda)
  6479. (save-excursion
  6480. (and (outline-next-heading)
  6481. (org-flag-heading nil))) ; show the next heading
  6482. (funcall 'org-priority force-direction)
  6483. (end-of-line 1)
  6484. (setq newhead (org-get-heading)))
  6485. (org-agenda-change-all-lines newhead hdmarker)
  6486. (beginning-of-line 1))))
  6487. ;; FIXME: should fix the tags property of the agenda line.
  6488. (defun org-agenda-set-tags (&optional tag onoff)
  6489. "Set tags for the current headline."
  6490. (interactive)
  6491. (org-agenda-check-no-diary)
  6492. (if (and (org-region-active-p) (interactive-p))
  6493. (call-interactively 'org-change-tag-in-region)
  6494. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6495. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6496. (org-agenda-error)))
  6497. (buffer (marker-buffer hdmarker))
  6498. (pos (marker-position hdmarker))
  6499. (inhibit-read-only t)
  6500. newhead)
  6501. (org-with-remote-undo buffer
  6502. (with-current-buffer buffer
  6503. (widen)
  6504. (goto-char pos)
  6505. (save-excursion
  6506. (org-show-context 'agenda))
  6507. (save-excursion
  6508. (and (outline-next-heading)
  6509. (org-flag-heading nil))) ; show the next heading
  6510. (goto-char pos)
  6511. (if tag
  6512. (org-toggle-tag tag onoff)
  6513. (call-interactively 'org-set-tags))
  6514. (end-of-line 1)
  6515. (setq newhead (org-get-heading)))
  6516. (org-agenda-change-all-lines newhead hdmarker)
  6517. (beginning-of-line 1)))))
  6518. (defun org-agenda-set-property ()
  6519. "Set a property for the current headline."
  6520. (interactive)
  6521. (org-agenda-check-no-diary)
  6522. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6523. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6524. (org-agenda-error)))
  6525. (buffer (marker-buffer hdmarker))
  6526. (pos (marker-position hdmarker))
  6527. (inhibit-read-only t)
  6528. newhead)
  6529. (org-with-remote-undo buffer
  6530. (with-current-buffer buffer
  6531. (widen)
  6532. (goto-char pos)
  6533. (save-excursion
  6534. (org-show-context 'agenda))
  6535. (save-excursion
  6536. (and (outline-next-heading)
  6537. (org-flag-heading nil))) ; show the next heading
  6538. (goto-char pos)
  6539. (call-interactively 'org-set-property)))))
  6540. (defun org-agenda-set-effort ()
  6541. "Set the effort property for the current headline."
  6542. (interactive)
  6543. (org-agenda-check-no-diary)
  6544. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6545. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6546. (org-agenda-error)))
  6547. (buffer (marker-buffer hdmarker))
  6548. (pos (marker-position hdmarker))
  6549. (inhibit-read-only t)
  6550. newhead)
  6551. (org-with-remote-undo buffer
  6552. (with-current-buffer buffer
  6553. (widen)
  6554. (goto-char pos)
  6555. (save-excursion
  6556. (org-show-context 'agenda))
  6557. (save-excursion
  6558. (and (outline-next-heading)
  6559. (org-flag-heading nil))) ; show the next heading
  6560. (goto-char pos)
  6561. (call-interactively 'org-set-effort)
  6562. (end-of-line 1)))))
  6563. (defun org-agenda-toggle-archive-tag ()
  6564. "Toggle the archive tag for the current entry."
  6565. (interactive)
  6566. (org-agenda-check-no-diary)
  6567. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6568. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6569. (org-agenda-error)))
  6570. (buffer (marker-buffer hdmarker))
  6571. (pos (marker-position hdmarker))
  6572. (inhibit-read-only t)
  6573. newhead)
  6574. (org-with-remote-undo buffer
  6575. (with-current-buffer buffer
  6576. (widen)
  6577. (goto-char pos)
  6578. (org-show-context 'agenda)
  6579. (save-excursion
  6580. (and (outline-next-heading)
  6581. (org-flag-heading nil))) ; show the next heading
  6582. (call-interactively 'org-toggle-archive-tag)
  6583. (end-of-line 1)
  6584. (setq newhead (org-get-heading)))
  6585. (org-agenda-change-all-lines newhead hdmarker)
  6586. (beginning-of-line 1))))
  6587. (defun org-agenda-do-date-later (arg)
  6588. (interactive "P")
  6589. (cond
  6590. ((or (equal arg '(16))
  6591. (memq last-command
  6592. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6593. (setq this-command 'org-agenda-date-later-minutes)
  6594. (org-agenda-date-later-minutes 1))
  6595. ((or (equal arg '(4))
  6596. (memq last-command
  6597. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6598. (setq this-command 'org-agenda-date-later-hours)
  6599. (org-agenda-date-later-hours 1))
  6600. (t
  6601. (org-agenda-date-later (prefix-numeric-value arg)))))
  6602. (defun org-agenda-do-date-earlier (arg)
  6603. (interactive "P")
  6604. (cond
  6605. ((or (equal arg '(16))
  6606. (memq last-command
  6607. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6608. (setq this-command 'org-agenda-date-earlier-minutes)
  6609. (org-agenda-date-earlier-minutes 1))
  6610. ((or (equal arg '(4))
  6611. (memq last-command
  6612. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6613. (setq this-command 'org-agenda-date-earlier-hours)
  6614. (org-agenda-date-earlier-hours 1))
  6615. (t
  6616. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6617. (defun org-agenda-date-later (arg &optional what)
  6618. "Change the date of this item to one day later."
  6619. (interactive "p")
  6620. (org-agenda-check-type t 'agenda 'timeline)
  6621. (org-agenda-check-no-diary)
  6622. (let* ((marker (or (org-get-at-bol 'org-marker)
  6623. (org-agenda-error)))
  6624. (buffer (marker-buffer marker))
  6625. (pos (marker-position marker)))
  6626. (org-with-remote-undo buffer
  6627. (with-current-buffer buffer
  6628. (widen)
  6629. (goto-char pos)
  6630. (if (not (org-at-timestamp-p))
  6631. (error "Cannot find time stamp"))
  6632. (org-timestamp-change arg (or what 'day)))
  6633. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6634. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6635. (defun org-agenda-date-earlier (arg &optional what)
  6636. "Change the date of this item to one day earlier."
  6637. (interactive "p")
  6638. (org-agenda-date-later (- arg) what))
  6639. (defun org-agenda-date-later-minutes (arg)
  6640. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6641. (interactive "p")
  6642. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6643. (org-agenda-date-later arg 'minute))
  6644. (defun org-agenda-date-earlier-minutes (arg)
  6645. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6646. (interactive "p")
  6647. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6648. (org-agenda-date-earlier arg 'minute))
  6649. (defun org-agenda-date-later-hours (arg)
  6650. "Change the time of this item, in hour steps."
  6651. (interactive "p")
  6652. (org-agenda-date-later arg 'hour))
  6653. (defun org-agenda-date-earlier-hours (arg)
  6654. "Change the time of this item, in hour steps."
  6655. (interactive "p")
  6656. (org-agenda-date-earlier arg 'hour))
  6657. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6658. "Show new date stamp via text properties."
  6659. ;; We use text properties to make this undoable
  6660. (let ((inhibit-read-only t)
  6661. (buffer-invisibility-spec))
  6662. (setq stamp (concat " " prefix " => " stamp))
  6663. (save-excursion
  6664. (goto-char (point-max))
  6665. (while (not (bobp))
  6666. (when (equal marker (org-get-at-bol 'org-marker))
  6667. (org-move-to-column (- (window-width) (length stamp)) t)
  6668. (org-agenda-fix-tags-filter-overlays-at (point))
  6669. (if (featurep 'xemacs)
  6670. ;; Use `duplicable' property to trigger undo recording
  6671. (let ((ex (make-extent nil nil))
  6672. (gl (make-glyph stamp)))
  6673. (set-glyph-face gl 'secondary-selection)
  6674. (set-extent-properties
  6675. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6676. (insert-extent ex (1- (point)) (point-at-eol)))
  6677. (add-text-properties
  6678. (1- (point)) (point-at-eol)
  6679. (list 'display (org-add-props stamp nil
  6680. 'face 'secondary-selection))))
  6681. (beginning-of-line 1))
  6682. (beginning-of-line 0)))))
  6683. (defun org-agenda-date-prompt (arg)
  6684. "Change the date of this item. Date is prompted for, with default today.
  6685. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6686. be used to request time specification in the time stamp."
  6687. (interactive "P")
  6688. (org-agenda-check-type t 'agenda 'timeline)
  6689. (org-agenda-check-no-diary)
  6690. (let* ((marker (or (org-get-at-bol 'org-marker)
  6691. (org-agenda-error)))
  6692. (buffer (marker-buffer marker))
  6693. (pos (marker-position marker)))
  6694. (org-with-remote-undo buffer
  6695. (with-current-buffer buffer
  6696. (widen)
  6697. (goto-char pos)
  6698. (if (not (org-at-timestamp-p t))
  6699. (error "Cannot find time stamp"))
  6700. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6701. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6702. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6703. (defun org-agenda-schedule (arg)
  6704. "Schedule the item at point.
  6705. Arg is passed through to `org-schedule'."
  6706. (interactive "P")
  6707. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6708. (org-agenda-check-no-diary)
  6709. (let* ((marker (or (org-get-at-bol 'org-marker)
  6710. (org-agenda-error)))
  6711. (type (marker-insertion-type marker))
  6712. (buffer (marker-buffer marker))
  6713. (pos (marker-position marker))
  6714. (org-insert-labeled-timestamps-at-point nil)
  6715. ts)
  6716. (set-marker-insertion-type marker t)
  6717. (org-with-remote-undo buffer
  6718. (with-current-buffer buffer
  6719. (widen)
  6720. (goto-char pos)
  6721. (setq ts (org-schedule arg)))
  6722. (org-agenda-show-new-time marker ts "S"))
  6723. (message "Item scheduled for %s" ts)))
  6724. (defun org-agenda-deadline (arg)
  6725. "Schedule the item at point.
  6726. Arg is passed through to `org-deadline'."
  6727. (interactive "P")
  6728. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6729. (org-agenda-check-no-diary)
  6730. (let* ((marker (or (org-get-at-bol 'org-marker)
  6731. (org-agenda-error)))
  6732. (buffer (marker-buffer marker))
  6733. (pos (marker-position marker))
  6734. (org-insert-labeled-timestamps-at-point nil)
  6735. ts)
  6736. (org-with-remote-undo buffer
  6737. (with-current-buffer buffer
  6738. (widen)
  6739. (goto-char pos)
  6740. (setq ts (org-deadline arg)))
  6741. (org-agenda-show-new-time marker ts "D"))
  6742. (message "Deadline for this item set to %s" ts)))
  6743. (defun org-agenda-action ()
  6744. "Select entry for agenda action, or execute an agenda action.
  6745. This command prompts for another letter. Valid inputs are:
  6746. m Mark the entry at point for an agenda action
  6747. s Schedule the marked entry to the date at the cursor
  6748. d Set the deadline of the marked entry to the date at the cursor
  6749. r Call `org-remember' with cursor date as the default date
  6750. c Call `org-capture' with cursor date as the default date
  6751. SPC Show marked entry in other window
  6752. TAB Visit marked entry in other window
  6753. The cursor may be at a date in the calendar, or in the Org agenda."
  6754. (interactive)
  6755. (let (ans)
  6756. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6757. (setq ans (read-char-exclusive))
  6758. (cond
  6759. ((equal ans ?m)
  6760. ;; Mark this entry
  6761. (if (eq major-mode 'org-agenda-mode)
  6762. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6763. (org-get-at-bol 'org-marker))))
  6764. (if m
  6765. (progn
  6766. (move-marker org-agenda-action-marker
  6767. (marker-position m) (marker-buffer m))
  6768. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6769. (error "Don't know which entry to mark")))
  6770. (error "This command works only in the agenda")))
  6771. ((equal ans ?s)
  6772. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6773. ((equal ans ?d)
  6774. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6775. ((equal ans ?r)
  6776. (org-agenda-do-action '(org-remember) t))
  6777. ((equal ans ?c)
  6778. (org-agenda-do-action '(org-capture) t))
  6779. ((equal ans ?\ )
  6780. (let ((cw (selected-window)))
  6781. (org-switch-to-buffer-other-window
  6782. (marker-buffer org-agenda-action-marker))
  6783. (goto-char org-agenda-action-marker)
  6784. (org-show-context 'agenda)
  6785. (select-window cw)))
  6786. ((equal ans ?\C-i)
  6787. (org-switch-to-buffer-other-window
  6788. (marker-buffer org-agenda-action-marker))
  6789. (goto-char org-agenda-action-marker)
  6790. (org-show-context 'agenda))
  6791. (t (error "Invalid agenda action %c" ans)))))
  6792. (defun org-agenda-do-action (form &optional current-buffer)
  6793. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6794. (let ((org-overriding-default-time (org-get-cursor-date)))
  6795. (if current-buffer
  6796. (eval form)
  6797. (if (not (marker-buffer org-agenda-action-marker))
  6798. (error "No entry has been selected for agenda action")
  6799. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6800. (save-excursion
  6801. (save-restriction
  6802. (widen)
  6803. (goto-char org-agenda-action-marker)
  6804. (eval form))))))))
  6805. (defun org-agenda-clock-in (&optional arg)
  6806. "Start the clock on the currently selected item."
  6807. (interactive "P")
  6808. (org-agenda-check-no-diary)
  6809. (if (equal arg '(4))
  6810. (org-clock-in arg)
  6811. (let* ((marker (or (org-get-at-bol 'org-marker)
  6812. (org-agenda-error)))
  6813. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6814. marker))
  6815. (pos (marker-position marker))
  6816. newhead)
  6817. (org-with-remote-undo (marker-buffer marker)
  6818. (with-current-buffer (marker-buffer marker)
  6819. (widen)
  6820. (goto-char pos)
  6821. (org-show-context 'agenda)
  6822. (org-show-entry)
  6823. (org-cycle-hide-drawers 'children)
  6824. (org-clock-in arg)
  6825. (setq newhead (org-get-heading)))
  6826. (org-agenda-change-all-lines newhead hdmarker)))))
  6827. (defun org-agenda-clock-out ()
  6828. "Stop the currently running clock."
  6829. (interactive)
  6830. (unless (marker-buffer org-clock-marker)
  6831. (error "No running clock"))
  6832. (let ((marker (make-marker)) newhead)
  6833. (org-with-remote-undo (marker-buffer org-clock-marker)
  6834. (with-current-buffer (marker-buffer org-clock-marker)
  6835. (save-excursion
  6836. (save-restriction
  6837. (widen)
  6838. (goto-char org-clock-marker)
  6839. (org-back-to-heading t)
  6840. (move-marker marker (point))
  6841. (org-clock-out)
  6842. (setq newhead (org-get-heading))))))
  6843. (org-agenda-change-all-lines newhead marker)
  6844. (move-marker marker nil)))
  6845. (defun org-agenda-clock-cancel (&optional arg)
  6846. "Cancel the currently running clock."
  6847. (interactive "P")
  6848. (unless (marker-buffer org-clock-marker)
  6849. (error "No running clock"))
  6850. (org-with-remote-undo (marker-buffer org-clock-marker)
  6851. (org-clock-cancel)))
  6852. (defun org-agenda-clock-goto ()
  6853. "Jump to the currently clocked in task within the agenda.
  6854. If the currently clocked in task is not listed in the agenda
  6855. buffer, display it in another window."
  6856. (interactive)
  6857. (let (pos)
  6858. (mapc (lambda (o)
  6859. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6860. (setq pos (overlay-start o))))
  6861. (overlays-in (point-min) (point-max)))
  6862. (cond (pos (goto-char pos))
  6863. ;; If the currently clocked entry is not in the agenda
  6864. ;; buffer, we visit it in another window:
  6865. (org-clock-current-task
  6866. (org-switch-to-buffer-other-window (org-clock-goto)))
  6867. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6868. (defun org-agenda-diary-entry-in-org-file ()
  6869. "Make a diary entry in the file `org-agenda-diary-file'."
  6870. (let (d1 d2 char (text "") dp1 dp2)
  6871. (if (equal (buffer-name) "*Calendar*")
  6872. (setq d1 (calendar-cursor-to-date t)
  6873. d2 (car calendar-mark-ring))
  6874. (setq dp1 (get-text-property (point-at-bol) 'day))
  6875. (unless dp1 (error "No date defined in current line"))
  6876. (setq d1 (calendar-gregorian-from-absolute dp1)
  6877. d2 (and (ignore-errors (mark))
  6878. (save-excursion
  6879. (goto-char (mark))
  6880. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6881. (calendar-gregorian-from-absolute dp2))))
  6882. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6883. (setq char (read-char-exclusive))
  6884. (cond
  6885. ((equal char ?d)
  6886. (setq text (read-string "Day entry: "))
  6887. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6888. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6889. ((equal char ?a)
  6890. (setq d1 (list (car d1) (nth 1 d1)
  6891. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6892. (nth 2 d1))))
  6893. (setq text (read-string "Anniversary (use %d to show years): "))
  6894. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6895. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6896. ((equal char ?b)
  6897. (setq text (read-string "Block entry: "))
  6898. (unless (and d1 d2 (not (equal d1 d2)))
  6899. (error "No block of days selected"))
  6900. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6901. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6902. ((equal char ?j)
  6903. (org-switch-to-buffer-other-window
  6904. (find-file-noselect org-agenda-diary-file))
  6905. (require 'org-datetree)
  6906. (org-datetree-find-date-create d1)
  6907. (org-reveal t))
  6908. (t (error "Invalid selection character `%c'" char)))))
  6909. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6910. "Where in `org-agenda-diary-file' should new entries be added?
  6911. Valid values:
  6912. date-tree in the date tree, as child of the date
  6913. top-level as top-level entries at the end of the file."
  6914. :group 'org-agenda
  6915. :type '(choice
  6916. (const :tag "in a date tree" date-tree)
  6917. (const :tag "as top level at end of file" top-level)))
  6918. (defcustom org-agenda-insert-diary-extract-time nil
  6919. "Non-nil means extract any time specification from the diary entry."
  6920. :group 'org-agenda
  6921. :type 'boolean)
  6922. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6923. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6924. If TEXT is not empty, it will become the headline of the new entry, and
  6925. the resulting entry will not be shown. When TEXT is empty, switch to
  6926. `org-agenda-diary-file' and let the user finish the entry there."
  6927. (let ((cw (current-window-configuration)))
  6928. (org-switch-to-buffer-other-window
  6929. (find-file-noselect org-agenda-diary-file))
  6930. (widen)
  6931. (goto-char (point-min))
  6932. (cond
  6933. ((eq type 'anniversary)
  6934. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6935. (progn
  6936. (or (org-on-heading-p t)
  6937. (progn
  6938. (outline-next-heading)
  6939. (insert "* Anniversaries\n\n")
  6940. (beginning-of-line -1)))))
  6941. (outline-next-heading)
  6942. (org-back-over-empty-lines)
  6943. (backward-char 1)
  6944. (insert "\n")
  6945. (require 'diary-lib)
  6946. (let ((calendar-date-display-form
  6947. (if (if (boundp 'calendar-date-style)
  6948. (eq calendar-date-style 'european)
  6949. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  6950. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  6951. '(day " " month " " year)
  6952. '(month " " day " " year))))
  6953. (insert (format "%%%%(diary-anniversary %s) %s"
  6954. (calendar-date-string d1 nil t) text))))
  6955. ((eq type 'day)
  6956. (let ((org-prefix-has-time t)
  6957. (org-agenda-time-leading-zero t)
  6958. fmt time time2)
  6959. (if org-agenda-insert-diary-extract-time
  6960. ;; Use org-format-agenda-item to parse text for a time-range and
  6961. ;; remove it. FIXME: This is a hack, we should refactor
  6962. ;; that function to make time extraction available separately
  6963. (setq fmt (org-format-agenda-item nil text nil nil t)
  6964. time (get-text-property 0 'time fmt)
  6965. time2 (if (> (length time) 0)
  6966. ;; split-string removes trailing ...... if
  6967. ;; no end time given. First space
  6968. ;; separates time from date.
  6969. (concat " " (car (split-string time "\\.")))
  6970. nil)
  6971. text (get-text-property 0 'txt fmt)))
  6972. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6973. (org-agenda-insert-diary-as-top-level text)
  6974. (require 'org-datetree)
  6975. (org-datetree-find-date-create d1)
  6976. (org-agenda-insert-diary-make-new-entry text))
  6977. (org-insert-time-stamp (org-time-from-absolute
  6978. (calendar-absolute-from-gregorian d1))
  6979. nil nil nil nil time2))
  6980. (end-of-line 0))
  6981. ((eq type 'block)
  6982. (if (> (calendar-absolute-from-gregorian d1)
  6983. (calendar-absolute-from-gregorian d2))
  6984. (setq d1 (prog1 d2 (setq d2 d1))))
  6985. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6986. (org-agenda-insert-diary-as-top-level text)
  6987. (require 'org-datetree)
  6988. (org-datetree-find-date-create d1)
  6989. (org-agenda-insert-diary-make-new-entry text))
  6990. (org-insert-time-stamp (org-time-from-absolute
  6991. (calendar-absolute-from-gregorian d1)))
  6992. (insert "--")
  6993. (org-insert-time-stamp (org-time-from-absolute
  6994. (calendar-absolute-from-gregorian d2)))
  6995. (end-of-line 0)))
  6996. (if (string-match "\\S-" text)
  6997. (progn
  6998. (set-window-configuration cw)
  6999. (message "%s entry added to %s"
  7000. (capitalize (symbol-name type))
  7001. (abbreviate-file-name org-agenda-diary-file)))
  7002. (org-reveal t)
  7003. (message "Please finish entry here"))))
  7004. (defun org-agenda-insert-diary-as-top-level (text)
  7005. "Make new entry as a top-level entry at the end of the file.
  7006. Add TEXT as headline, and position the cursor in the second line so that
  7007. a timestamp can be added there."
  7008. (widen)
  7009. (goto-char (point-max))
  7010. (or (bolp) (insert "\n"))
  7011. (insert "* " text "\n")
  7012. (if org-adapt-indentation (org-indent-to-column 2)))
  7013. (defun org-agenda-insert-diary-make-new-entry (text)
  7014. "Make new entry as last child of current entry.
  7015. Add TEXT as headline, and position the cursor in the second line so that
  7016. a timestamp can be added there."
  7017. (let ((org-show-following-heading t)
  7018. (org-show-siblings t)
  7019. (org-show-hierarchy-above t)
  7020. (org-show-entry-below t)
  7021. col)
  7022. (outline-next-heading)
  7023. (org-back-over-empty-lines)
  7024. (or (looking-at "[ \t]*$")
  7025. (progn (insert "\n") (backward-char 1)))
  7026. (org-insert-heading nil t)
  7027. (org-do-demote)
  7028. (setq col (current-column))
  7029. (insert text "\n")
  7030. (if org-adapt-indentation (org-indent-to-column col))
  7031. (let ((org-show-following-heading t)
  7032. (org-show-siblings t)
  7033. (org-show-hierarchy-above t)
  7034. (org-show-entry-below t))
  7035. (org-show-context))))
  7036. (defun org-agenda-diary-entry ()
  7037. "Make a diary entry, like the `i' command from the calendar.
  7038. All the standard commands work: block, weekly etc.
  7039. When `org-agenda-diary-file' points to a file,
  7040. `org-agenda-diary-entry-in-org-file' is called instead to create
  7041. entries in that Org-mode file."
  7042. (interactive)
  7043. (org-agenda-check-type t 'agenda 'timeline)
  7044. (if (not (eq org-agenda-diary-file 'diary-file))
  7045. (org-agenda-diary-entry-in-org-file)
  7046. (require 'diary-lib)
  7047. (let* ((char (progn
  7048. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7049. (read-char-exclusive)))
  7050. (cmd (cdr (assoc char
  7051. '((?d . insert-diary-entry)
  7052. (?w . insert-weekly-diary-entry)
  7053. (?m . insert-monthly-diary-entry)
  7054. (?y . insert-yearly-diary-entry)
  7055. (?a . insert-anniversary-diary-entry)
  7056. (?b . insert-block-diary-entry)
  7057. (?c . insert-cyclic-diary-entry)))))
  7058. (oldf (symbol-function 'calendar-cursor-to-date))
  7059. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7060. (point (point))
  7061. (mark (or (mark t) (point))))
  7062. (unless cmd
  7063. (error "No command associated with <%c>" char))
  7064. (unless (and (get-text-property point 'day)
  7065. (or (not (equal ?b char))
  7066. (get-text-property mark 'day)))
  7067. (error "Don't know which date to use for diary entry"))
  7068. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7069. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7070. (let ((calendar-mark-ring
  7071. (list (calendar-gregorian-from-absolute
  7072. (or (get-text-property mark 'day)
  7073. (get-text-property point 'day))))))
  7074. (unwind-protect
  7075. (progn
  7076. (fset 'calendar-cursor-to-date
  7077. (lambda (&optional error dummy)
  7078. (calendar-gregorian-from-absolute
  7079. (get-text-property point 'day))))
  7080. (call-interactively cmd))
  7081. (fset 'calendar-cursor-to-date oldf))))))
  7082. (defun org-agenda-execute-calendar-command (cmd)
  7083. "Execute a calendar command from the agenda, with the date associated to
  7084. the cursor position."
  7085. (org-agenda-check-type t 'agenda 'timeline)
  7086. (require 'diary-lib)
  7087. (unless (get-text-property (point) 'day)
  7088. (error "Don't know which date to use for calendar command"))
  7089. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7090. (point (point))
  7091. (date (calendar-gregorian-from-absolute
  7092. (get-text-property point 'day)))
  7093. ;; the following 2 vars are needed in the calendar
  7094. (displayed-month (car date))
  7095. (displayed-year (nth 2 date)))
  7096. (unwind-protect
  7097. (progn
  7098. (fset 'calendar-cursor-to-date
  7099. (lambda (&optional error dummy)
  7100. (calendar-gregorian-from-absolute
  7101. (get-text-property point 'day))))
  7102. (call-interactively cmd))
  7103. (fset 'calendar-cursor-to-date oldf))))
  7104. (defun org-agenda-phases-of-moon ()
  7105. "Display the phases of the moon for the 3 months around the cursor date."
  7106. (interactive)
  7107. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7108. (defun org-agenda-holidays ()
  7109. "Display the holidays for the 3 months around the cursor date."
  7110. (interactive)
  7111. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7112. (defvar calendar-longitude)
  7113. (defvar calendar-latitude)
  7114. (defvar calendar-location-name)
  7115. (defun org-agenda-sunrise-sunset (arg)
  7116. "Display sunrise and sunset for the cursor date.
  7117. Latitude and longitude can be specified with the variables
  7118. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7119. argument, latitude and longitude will be prompted for."
  7120. (interactive "P")
  7121. (require 'solar)
  7122. (let ((calendar-longitude (if arg nil calendar-longitude))
  7123. (calendar-latitude (if arg nil calendar-latitude))
  7124. (calendar-location-name
  7125. (if arg "the given coordinates" calendar-location-name)))
  7126. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7127. (defun org-agenda-goto-calendar ()
  7128. "Open the Emacs calendar with the date at the cursor."
  7129. (interactive)
  7130. (org-agenda-check-type t 'agenda 'timeline)
  7131. (let* ((day (or (get-text-property (point) 'day)
  7132. (error "Don't know which date to open in calendar")))
  7133. (date (calendar-gregorian-from-absolute day))
  7134. (calendar-move-hook nil)
  7135. (calendar-view-holidays-initially-flag nil)
  7136. (calendar-view-diary-initially-flag nil))
  7137. (calendar)
  7138. (calendar-goto-date date)))
  7139. ;;;###autoload
  7140. (defun org-calendar-goto-agenda ()
  7141. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7142. This is a command that has to be installed in `calendar-mode-map'."
  7143. (interactive)
  7144. (org-agenda-list nil (calendar-absolute-from-gregorian
  7145. (calendar-cursor-to-date))
  7146. nil))
  7147. (defun org-agenda-convert-date ()
  7148. (interactive)
  7149. (org-agenda-check-type t 'agenda 'timeline)
  7150. (let ((day (get-text-property (point) 'day))
  7151. date s)
  7152. (unless day
  7153. (error "Don't know which date to convert"))
  7154. (setq date (calendar-gregorian-from-absolute day))
  7155. (setq s (concat
  7156. "Gregorian: " (calendar-date-string date) "\n"
  7157. "ISO: " (calendar-iso-date-string date) "\n"
  7158. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7159. "Julian: " (calendar-julian-date-string date) "\n"
  7160. "Astron. JD: " (calendar-astro-date-string date)
  7161. " (Julian date number at noon UTC)\n"
  7162. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7163. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7164. "French: " (calendar-french-date-string date) "\n"
  7165. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7166. "Mayan: " (calendar-mayan-date-string date) "\n"
  7167. "Coptic: " (calendar-coptic-date-string date) "\n"
  7168. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7169. "Persian: " (calendar-persian-date-string date) "\n"
  7170. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7171. (with-output-to-temp-buffer "*Dates*"
  7172. (princ s))
  7173. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7174. ;;; Bulk commands
  7175. (defvar org-agenda-bulk-marked-entries nil
  7176. "List of markers that refer to marked entries in the agenda.")
  7177. (defun org-agenda-bulk-marked-p ()
  7178. (eq (get-char-property (point-at-bol) 'type)
  7179. 'org-marked-entry-overlay))
  7180. (defun org-agenda-bulk-mark ()
  7181. "Mark the entry at point for future bulk action."
  7182. (interactive)
  7183. (org-agenda-check-no-diary)
  7184. (let* ((m (org-get-at-bol 'org-hd-marker))
  7185. ov)
  7186. (unless (org-agenda-bulk-marked-p)
  7187. (unless m (error "Nothing to mark at point"))
  7188. (push m org-agenda-bulk-marked-entries)
  7189. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7190. (org-overlay-display ov "> "
  7191. (org-get-todo-face "TODO")
  7192. 'evaporate)
  7193. (overlay-put ov 'type 'org-marked-entry-overlay))
  7194. (beginning-of-line 2)
  7195. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7196. (beginning-of-line 2))
  7197. (message "%d entries marked for bulk action"
  7198. (length org-agenda-bulk-marked-entries))))
  7199. (defun org-agenda-bulk-unmark ()
  7200. "Unmark the entry at point for future bulk action."
  7201. (interactive)
  7202. (when (org-agenda-bulk-marked-p)
  7203. (org-agenda-bulk-remove-overlays
  7204. (point-at-bol) (+ 2 (point-at-bol)))
  7205. (setq org-agenda-bulk-marked-entries
  7206. (delete (org-get-at-bol 'org-hd-marker)
  7207. org-agenda-bulk-marked-entries)))
  7208. (beginning-of-line 2)
  7209. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7210. (beginning-of-line 2))
  7211. (message "%d entries marked for bulk action"
  7212. (length org-agenda-bulk-marked-entries)))
  7213. (defun org-agenda-bulk-toggle ()
  7214. "Toggle marking the entry at point for bulk action."
  7215. (interactive)
  7216. (if (org-agenda-bulk-marked-p)
  7217. (org-agenda-bulk-unmark)
  7218. (org-agenda-bulk-mark)))
  7219. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7220. "Remove the mark overlays between BEG and END in the agenda buffer.
  7221. BEG and END default to the buffer limits.
  7222. This only removes the overlays, it does not remove the markers
  7223. from the list in `org-agenda-bulk-marked-entries'."
  7224. (interactive)
  7225. (mapc (lambda (ov)
  7226. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7227. (delete-overlay ov)))
  7228. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7229. (defun org-agenda-bulk-remove-all-marks ()
  7230. "Remove all marks in the agenda buffer.
  7231. This will remove the markers, and the overlays."
  7232. (interactive)
  7233. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7234. (setq org-agenda-bulk-marked-entries nil)
  7235. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7236. (defun org-agenda-bulk-action (&optional arg)
  7237. "Execute an remote-editing action on all marked entries.
  7238. The prefix arg is passed through to the command if possible."
  7239. (interactive "P")
  7240. (unless org-agenda-bulk-marked-entries
  7241. (error "No entries are marked"))
  7242. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7243. (let* ((action (read-char-exclusive))
  7244. (org-log-refile (if org-log-refile 'time nil))
  7245. (entries (reverse org-agenda-bulk-marked-entries))
  7246. redo-at-end
  7247. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7248. (cond
  7249. ((equal action ?$)
  7250. (setq cmd '(org-agenda-archive)))
  7251. ((equal action ?A)
  7252. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7253. ((member action '(?r ?w))
  7254. (setq rfloc (org-refile-get-location
  7255. "Refile to: "
  7256. (marker-buffer (car org-agenda-bulk-marked-entries))
  7257. org-refile-allow-creating-parent-nodes))
  7258. (if (nth 3 rfloc)
  7259. (setcar (nthcdr 3 rfloc)
  7260. (move-marker (make-marker) (nth 3 rfloc)
  7261. (or (get-file-buffer (nth 1 rfloc))
  7262. (find-buffer-visiting (nth 1 rfloc))
  7263. (error "This should not happen")))))
  7264. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7265. redo-at-end t))
  7266. ((equal action ?t)
  7267. (setq state (org-icompleting-read
  7268. "Todo state: "
  7269. (with-current-buffer (marker-buffer (car entries))
  7270. (mapcar 'list org-todo-keywords-1))))
  7271. (setq cmd `(let ((org-inhibit-blocking t)
  7272. (org-inhibit-logging 'note))
  7273. (org-agenda-todo ,state))))
  7274. ((memq action '(?- ?+))
  7275. (setq tag (org-icompleting-read
  7276. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7277. (with-current-buffer (marker-buffer (car entries))
  7278. (delq nil
  7279. (mapcar (lambda (x)
  7280. (if (stringp (car x)) x)) org-tag-alist)))))
  7281. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7282. ((memq action '(?s ?d))
  7283. (let* ((date (unless arg
  7284. (org-read-date
  7285. nil nil nil
  7286. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7287. (ans (if arg nil org-read-date-final-answer))
  7288. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7289. (setq cmd `(let* ((bound (fboundp 'read-string))
  7290. (old (and bound (symbol-function 'read-string))))
  7291. (unwind-protect
  7292. (progn
  7293. (fset 'read-string (lambda (&rest ignore) ,ans))
  7294. (eval '(,c1 arg)))
  7295. (if bound
  7296. (fset 'read-string old)
  7297. (fmakunbound 'read-string)))))))
  7298. (t (error "Invalid bulk action")))
  7299. ;; Sort the markers, to make sure that parents are handled before children
  7300. (setq entries (sort entries
  7301. (lambda (a b)
  7302. (cond
  7303. ((equal (marker-buffer a) (marker-buffer b))
  7304. (< (marker-position a) (marker-position b)))
  7305. (t
  7306. (string< (buffer-name (marker-buffer a))
  7307. (buffer-name (marker-buffer b))))))))
  7308. ;; Now loop over all markers and apply cmd
  7309. (while (setq e (pop entries))
  7310. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7311. (if (not pos)
  7312. (progn (message "Skipping removed entry at %s" e)
  7313. (setq cntskip (1+ cntskip)))
  7314. (goto-char pos)
  7315. (eval cmd)
  7316. (setq org-agenda-bulk-marked-entries
  7317. (delete e org-agenda-bulk-marked-entries))
  7318. (setq cnt (1+ cnt))))
  7319. (setq org-agenda-bulk-marked-entries nil)
  7320. (org-agenda-bulk-remove-all-marks)
  7321. (when redo-at-end (org-agenda-redo))
  7322. (message "Acted on %d entries%s"
  7323. cnt
  7324. (if (= cntskip 0)
  7325. ""
  7326. (format ", skipped %d (disappeared before their turn)"
  7327. cntskip)))))
  7328. ;;; Flagging notes
  7329. (defun org-agenda-show-the-flagging-note ()
  7330. "Display the flagging note in the other window.
  7331. When called a second time in direct sequence, offer to remove the FLAGGING
  7332. tag and (if present) the flagging note."
  7333. (interactive)
  7334. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7335. (win (selected-window))
  7336. note heading newhead)
  7337. (unless hdmarker
  7338. (error "No linked entry at point"))
  7339. (if (and (eq this-command last-command)
  7340. (y-or-n-p "Unflag and remove any flagging note? "))
  7341. (progn
  7342. (org-agenda-remove-flag hdmarker)
  7343. (let ((win (get-buffer-window "*Flagging Note*")))
  7344. (and win (delete-window win)))
  7345. (message "Entry unflaged"))
  7346. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7347. (unless note
  7348. (error "No flagging note"))
  7349. (org-kill-new note)
  7350. (org-switch-to-buffer-other-window "*Flagging Note*")
  7351. (erase-buffer)
  7352. (insert note)
  7353. (goto-char (point-min))
  7354. (while (re-search-forward "\\\\n" nil t)
  7355. (replace-match "\n" t t))
  7356. (goto-char (point-min))
  7357. (select-window win)
  7358. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7359. (defun org-agenda-remove-flag (marker)
  7360. "Remove the FLAGGED tag and any flagging note in the entry."
  7361. (let (newhead)
  7362. (org-with-point-at marker
  7363. (org-toggle-tag "FLAGGED" 'off)
  7364. (org-entry-delete nil "THEFLAGGINGNOTE")
  7365. (setq newhead (org-get-heading)))
  7366. (org-agenda-change-all-lines newhead marker)
  7367. (message "Entry unflaged")))
  7368. (defun org-agenda-get-any-marker (&optional pos)
  7369. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7370. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7371. ;;; Appointment reminders
  7372. (defvar appt-time-msg-list)
  7373. ;;;###autoload
  7374. (defun org-agenda-to-appt (&optional refresh filter)
  7375. "Activate appointments found in `org-agenda-files'.
  7376. With a \\[universal-argument] prefix, refresh the list of
  7377. appointments.
  7378. If FILTER is t, interactively prompt the user for a regular
  7379. expression, and filter out entries that don't match it.
  7380. If FILTER is a string, use this string as a regular expression
  7381. for filtering entries out.
  7382. FILTER can also be an alist with the car of each cell being
  7383. either 'headline or 'category. For example:
  7384. '((headline \"IMPORTANT\")
  7385. (category \"Work\"))
  7386. will only add headlines containing IMPORTANT or headlines
  7387. belonging to the \"Work\" category."
  7388. (interactive "P")
  7389. (if refresh (setq appt-time-msg-list nil))
  7390. (if (eq filter t)
  7391. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7392. (let* ((cnt 0) ; count added events
  7393. (org-agenda-new-buffers nil)
  7394. (org-deadline-warning-days 0)
  7395. ;; Do not use `org-agenda-today' here because appt only takes
  7396. ;; time and without date as argument, so it may pass wrong
  7397. ;; information otherwise
  7398. (today (org-date-to-gregorian
  7399. (time-to-days (current-time))))
  7400. (org-agenda-restrict nil)
  7401. (files (org-agenda-files 'unrestricted)) entries file)
  7402. ;; Get all entries which may contain an appt
  7403. (org-prepare-agenda-buffers files)
  7404. (while (setq file (pop files))
  7405. (setq entries
  7406. (append entries
  7407. (org-agenda-get-day-entries
  7408. file today :timestamp :scheduled :deadline))))
  7409. (setq entries (delq nil entries))
  7410. ;; Map thru entries and find if we should filter them out
  7411. (mapc
  7412. (lambda(x)
  7413. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7414. (cat (get-text-property 1 'org-category x))
  7415. (tod (get-text-property 1 'time-of-day x))
  7416. (ok (or (null filter)
  7417. (and (stringp filter) (string-match filter evt))
  7418. (and (listp filter)
  7419. (or (string-match
  7420. (cadr (assoc 'category filter)) cat)
  7421. (string-match
  7422. (cadr (assoc 'headline filter)) evt))))))
  7423. ;; FIXME: Shall we remove text-properties for the appt text?
  7424. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7425. (when (and ok tod)
  7426. (setq tod (concat "00" (number-to-string tod))
  7427. tod (when (string-match
  7428. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7429. (concat (match-string 1 tod) ":"
  7430. (match-string 2 tod))))
  7431. (appt-add tod evt)
  7432. (setq cnt (1+ cnt))))) entries)
  7433. (org-release-buffers org-agenda-new-buffers)
  7434. (if (eq cnt 0)
  7435. (message "No event to add")
  7436. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7437. (defun org-agenda-today ()
  7438. "Return today date, considering `org-extend-today-until'."
  7439. (time-to-days
  7440. (time-subtract (current-time)
  7441. (list 0 (* 3600 org-extend-today-until) 0))))
  7442. (defun org-agenda-todayp (date)
  7443. "Does DATE mean today, when considering `org-extend-today-until'?"
  7444. (let ((today (org-agenda-today))
  7445. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7446. date)))
  7447. (eq date today)))
  7448. (provide 'org-agenda)
  7449. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7450. ;;; org-agenda.el ends here