org-agenda.el 302 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920
  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-scheduled nil
  513. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  514. This applies when creating the global todo list.
  515. Valid values are:
  516. past Don't show entries scheduled today or in the past.
  517. future Don't show entries scheduled in the future.
  518. The idea behind this is that by scheduling it, you don't want to
  519. think about it until the scheduled date.
  520. all Don't show any scheduled entries in the global todo list.
  521. The idea behind this is that by scheduling it, you have already
  522. \"taken care\" of this item.
  523. t Same as `all', for backward compatibility.
  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-scheduled todos" future)
  531. (const :tag "Ignore past- or present-scheduled todos" past)
  532. (const :tag "Ignore all scheduled todos" all)
  533. (const :tag "Ignore all scheduled todos (compatibility)" t)
  534. (const :tag "Show scheduled todos" nil)))
  535. (defcustom org-agenda-todo-ignore-deadlines nil
  536. "Non-nil means ignore some deadlined TODO items when making TODO list.
  537. There are different motivations for using different values, please think
  538. carefully when configuring this variable.
  539. This applies when creating the global todo list.
  540. Valid values are:
  541. near Don't show near deadline entries. A deadline is near when it is
  542. closer than `org-deadline-warning-days' days. The idea behind this
  543. is that such items will appear in the agenda anyway.
  544. far Don't show TODO entries where a deadline has been defined, but
  545. the deadline is not near. This is useful if you don't want to
  546. use the todo list to figure out what to do now.
  547. past Don't show entries with a deadline timestamp for today or in the past.
  548. future Don't show entries with a deadline timestamp in the future, not even
  549. when they become `near' ones. Use it with caution.
  550. all Ignore all TODO entries that do have a deadline.
  551. t Same as `near', for backward compatibility.
  552. See also `org-agenda-todo-ignore-with-date'.
  553. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  554. to make his option also apply to the tags-todo list."
  555. :group 'org-agenda-skip
  556. :group 'org-agenda-todo-list
  557. :type '(choice
  558. (const :tag "Ignore near deadlines" near)
  559. (const :tag "Ignore near deadlines (compatibility)" t)
  560. (const :tag "Ignore far deadlines" far)
  561. (const :tag "Ignore all TODOs with a deadlines" all)
  562. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  563. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  564. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  565. The variables
  566. `org-agenda-todo-ignore-with-date',
  567. `org-agenda-todo-ignore-scheduled'
  568. `org-agenda-todo-ignore-deadlines'
  569. make the global TODO list skip entries that have time stamps of certain
  570. kinds. If this option is set, the same options will also apply for the
  571. tags-todo search, which is the general tags/property matcher
  572. restricted to unfinished TODO entries only."
  573. :group 'org-agenda-skip
  574. :group 'org-agenda-todo-list
  575. :group 'org-agenda-match-view
  576. :type 'boolean)
  577. (defcustom org-agenda-skip-scheduled-if-done nil
  578. "Non-nil means don't show scheduled items in agenda when they are done.
  579. This is relevant for the daily/weekly agenda, not for the TODO list. And
  580. it applies only to the actual date of the scheduling. Warnings about
  581. an item with a past scheduling dates are always turned off when the item
  582. is DONE."
  583. :group 'org-agenda-skip
  584. :group 'org-agenda-daily/weekly
  585. :type 'boolean)
  586. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  587. "Non-nil means skip scheduling line if same entry shows because of deadline.
  588. In the agenda of today, an entry can show up multiple times because
  589. it is both scheduled and has a nearby deadline, and maybe a plain time
  590. stamp as well.
  591. When this variable is t, then only the deadline is shown and the fact that
  592. the entry is scheduled today or was scheduled previously is not shown.
  593. When this variable is nil, the entry will be shown several times. When
  594. the variable is the symbol `not-today', then skip scheduled previously,
  595. but not scheduled today."
  596. :group 'org-agenda-skip
  597. :group 'org-agenda-daily/weekly
  598. :type '(choice
  599. (const :tag "Never" nil)
  600. (const :tag "Always" t)
  601. (const :tag "Not when scheduled today" not-today)))
  602. (defcustom org-agenda-skip-deadline-if-done nil
  603. "Non-nil means don't show deadlines when the corresponding item is done.
  604. When nil, the deadline is still shown and should give you a happy feeling.
  605. This is relevant for the daily/weekly agenda. And it applied only to the
  606. actually date of the deadline. Warnings about approaching and past-due
  607. deadlines are always turned off when the item is DONE."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-daily/weekly
  610. :type 'boolean)
  611. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  612. "Non-nil means skip deadline prewarning when entry is also scheduled.
  613. This will apply on all days where a prewarning for the deadline would
  614. be shown, but not at the day when the entry is actually due. On that day,
  615. the deadline will be shown anyway.
  616. This variable may be set to nil, t, or a number which will then give
  617. the number of days before the actual deadline when the prewarnings
  618. should resume.
  619. This can be used in a workflow where the first showing of the deadline will
  620. trigger you to schedule it, and then you don't want to be reminded of it
  621. because you will take care of it on the day when scheduled."
  622. :group 'org-agenda-skip
  623. :group 'org-agenda-daily/weekly
  624. :type '(choice
  625. (const :tag "Alwas show prewarning" nil)
  626. (const :tag "Remove prewarning if entry is scheduled" t)
  627. (integer :tag "Restart prewarning N days before deadline")))
  628. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  629. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  630. When non-nil, after the search for timestamps has matched once in an
  631. entry, the rest of the entry will not be searched."
  632. :group 'org-agenda-skip
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-timestamp-if-done nil
  635. "Non-nil means don't select item by timestamp or -range if it is DONE."
  636. :group 'org-agenda-skip
  637. :group 'org-agenda-daily/weekly
  638. :type 'boolean)
  639. (defcustom org-agenda-dim-blocked-tasks t
  640. "Non-nil means dim blocked tasks in the agenda display.
  641. This causes some overhead during agenda construction, but if you
  642. have turned on `org-enforce-todo-dependencies',
  643. `org-enforce-todo-checkbox-dependencies', or any other blocking
  644. mechanism, this will create useful feedback in the agenda.
  645. Instead of t, this variable can also have the value `invisible'.
  646. Then blocked tasks will be invisible and only become visible when
  647. they become unblocked. An exemption to this behavior is when a task is
  648. blocked because of unchecked checkboxes below it. Since checkboxes do
  649. not show up in the agenda views, making this task invisible you remove any
  650. trace from agenda views that there is something to do. Therefore, a task
  651. that is blocked because of checkboxes will never be made invisible, it
  652. will only be dimmed."
  653. :group 'org-agenda-daily/weekly
  654. :group 'org-agenda-todo-list
  655. :type '(choice
  656. (const :tag "Do not dim" nil)
  657. (const :tag "Dim to a grey face" t)
  658. (const :tag "Make invisible" invisible)))
  659. (defcustom org-timeline-show-empty-dates 3
  660. "Non-nil means `org-timeline' also shows dates without an entry.
  661. When nil, only the days which actually have entries are shown.
  662. When t, all days between the first and the last date are shown.
  663. When an integer, show also empty dates, but if there is a gap of more than
  664. N days, just insert a special line indicating the size of the gap."
  665. :group 'org-agenda-skip
  666. :type '(choice
  667. (const :tag "None" nil)
  668. (const :tag "All" t)
  669. (integer :tag "at most")))
  670. (defgroup org-agenda-startup nil
  671. "Options concerning initial settings in the Agenda in Org Mode."
  672. :tag "Org Agenda Startup"
  673. :group 'org-agenda)
  674. (defcustom org-agenda-menu-show-matcher t
  675. "Non-nil menas show the match string in the agenda dispatcher menu.
  676. When nil, the matcher string is not shown, but is put into the help-echo
  677. property so than moving the mouse over the command shows it.
  678. Setting it to nil is good if matcher strings are very long and/or if
  679. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  680. :group 'org-agenda
  681. :type 'boolean)
  682. (defcustom org-agenda-menu-two-column nil
  683. "Non-nil means, use two columns to show custom commands in the dispatcher.
  684. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  685. to nil."
  686. :group 'org-agenda
  687. :type 'boolean)
  688. (defcustom org-finalize-agenda-hook nil
  689. "Hook run just before displaying an agenda buffer."
  690. :group 'org-agenda-startup
  691. :type 'hook)
  692. (defcustom org-agenda-mouse-1-follows-link nil
  693. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  694. A longer mouse click will still set point. Does not work on XEmacs.
  695. Needs to be set before org.el is loaded."
  696. :group 'org-agenda-startup
  697. :type 'boolean)
  698. (defcustom org-agenda-start-with-follow-mode nil
  699. "The initial value of follow mode in a newly created agenda window."
  700. :group 'org-agenda-startup
  701. :type 'boolean)
  702. (defcustom org-agenda-show-outline-path t
  703. "Non-nil means show outline path in echo area after line motion."
  704. :group 'org-agenda-startup
  705. :type 'boolean)
  706. (defcustom org-agenda-start-with-entry-text-mode nil
  707. "The initial value of entry-text-mode in a newly created agenda window."
  708. :group 'org-agenda-startup
  709. :type 'boolean)
  710. (defcustom org-agenda-entry-text-maxlines 5
  711. "Number of text lines to be added when `E' is pressed in the agenda.
  712. Note that this variable only used during agenda display. Add add entry text
  713. when exporting the agenda, configure the variable
  714. `org-agenda-add-entry-ext-maxlines'."
  715. :group 'org-agenda
  716. :type 'integer)
  717. (defcustom org-agenda-entry-text-exclude-regexps nil
  718. "List of regular expressions to clean up entry text.
  719. The complete matches of all regular expressions in this list will be
  720. removed from entry text before it is shown in the agenda."
  721. :group 'org-agenda
  722. :type '(repeat (regexp)))
  723. (defvar org-agenda-entry-text-cleanup-hook nil
  724. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  725. This cleanup is done in a temporary buffer, so the function may inspect and
  726. change the entire buffer.
  727. Some default stuff like drawers and scheduling/deadline dates will already
  728. have been removed when this is called, as will any matches for regular
  729. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  730. (defvar org-agenda-include-inactive-timestamps nil
  731. "Non-nil means include inactive time stamps in agenda and timeline.")
  732. (defgroup org-agenda-windows nil
  733. "Options concerning the windows used by the Agenda in Org Mode."
  734. :tag "Org Agenda Windows"
  735. :group 'org-agenda)
  736. (defcustom org-agenda-window-setup 'reorganize-frame
  737. "How the agenda buffer should be displayed.
  738. Possible values for this option are:
  739. current-window Show agenda in the current window, keeping all other windows.
  740. other-window Use `switch-to-buffer-other-window' to display agenda.
  741. reorganize-frame Show only two windows on the current frame, the current
  742. window and the agenda.
  743. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  744. Also, when exiting the agenda, kill that frame.
  745. See also the variable `org-agenda-restore-windows-after-quit'."
  746. :group 'org-agenda-windows
  747. :type '(choice
  748. (const current-window)
  749. (const other-frame)
  750. (const other-window)
  751. (const reorganize-frame)))
  752. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  753. "The min and max height of the agenda window as a fraction of frame height.
  754. The value of the variable is a cons cell with two numbers between 0 and 1.
  755. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  756. :group 'org-agenda-windows
  757. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  758. (defcustom org-agenda-restore-windows-after-quit nil
  759. "Non-nil means restore window configuration open exiting agenda.
  760. Before the window configuration is changed for displaying the agenda,
  761. the current status is recorded. When the agenda is exited with
  762. `q' or `x' and this option is set, the old state is restored. If
  763. `org-agenda-window-setup' is `other-frame', the value of this
  764. option will be ignored."
  765. :group 'org-agenda-windows
  766. :type 'boolean)
  767. (defcustom org-agenda-ndays 7
  768. "Number of days to include in overview display.
  769. Should be 1 or 7.
  770. Custom commands can set this variable in the options section."
  771. :group 'org-agenda-daily/weekly
  772. :type 'integer)
  773. (defcustom org-agenda-start-on-weekday 1
  774. "Non-nil means start the overview always on the specified weekday.
  775. 0 denotes Sunday, 1 denotes Monday etc.
  776. When nil, always start on the current day.
  777. Custom commands can set this variable in the options section."
  778. :group 'org-agenda-daily/weekly
  779. :type '(choice (const :tag "Today" nil)
  780. (integer :tag "Weekday No.")))
  781. (defcustom org-agenda-show-all-dates t
  782. "Non-nil means `org-agenda' shows every day in the selected range.
  783. When nil, only the days which actually have entries are shown."
  784. :group 'org-agenda-daily/weekly
  785. :type 'boolean)
  786. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  787. "Format string for displaying dates in the agenda.
  788. Used by the daily/weekly agenda and by the timeline. This should be
  789. a format string understood by `format-time-string', or a function returning
  790. the formatted date as a string. The function must take a single argument,
  791. a calendar-style date list like (month day year)."
  792. :group 'org-agenda-daily/weekly
  793. :type '(choice
  794. (string :tag "Format string")
  795. (function :tag "Function")))
  796. (defun org-agenda-format-date-aligned (date)
  797. "Format a date string for display in the daily/weekly agenda, or timeline.
  798. This function makes sure that dates are aligned for easy reading."
  799. (require 'cal-iso)
  800. (let* ((dayname (calendar-day-name date))
  801. (day (cadr date))
  802. (day-of-week (calendar-day-of-week date))
  803. (month (car date))
  804. (monthname (calendar-month-name month))
  805. (year (nth 2 date))
  806. (iso-week (org-days-to-iso-week
  807. (calendar-absolute-from-gregorian date)))
  808. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  809. (1- year))
  810. ((and (= month 12) (<= iso-week 1))
  811. (1+ year))
  812. (t year)))
  813. (weekstring (if (= day-of-week 1)
  814. (format " W%02d" iso-week)
  815. "")))
  816. (format "%-10s %2d %s %4d%s"
  817. dayname day monthname year weekstring)))
  818. (defcustom org-agenda-time-leading-zero nil
  819. "Non-nil means use leading zero for military times in agenda.
  820. For example, 9:30am would become 09:30 rather than 9:30."
  821. :group 'org-agenda-daily/weekly
  822. :type 'boolean)
  823. (defcustom org-agenda-weekend-days '(6 0)
  824. "Which days are weekend?
  825. These days get the special face `org-agenda-date-weekend' in the agenda
  826. and timeline buffers."
  827. :group 'org-agenda-daily/weekly
  828. :type '(set :greedy t
  829. (const :tag "Monday" 1)
  830. (const :tag "Tuesday" 2)
  831. (const :tag "Wednesday" 3)
  832. (const :tag "Thursday" 4)
  833. (const :tag "Friday" 5)
  834. (const :tag "Saturday" 6)
  835. (const :tag "Sunday" 0)))
  836. (defcustom org-agenda-include-diary nil
  837. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  838. Custom commands can set this variable in the options section."
  839. :group 'org-agenda-daily/weekly
  840. :type 'boolean)
  841. (defcustom org-agenda-include-deadlines t
  842. "If non-nil, include entries within their deadline warning period.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type 'boolean)
  846. (defcustom org-agenda-include-all-todo nil
  847. "Set means weekly/daily agenda will always contain all TODO entries.
  848. The TODO entries will be listed at the top of the agenda, before
  849. the entries for specific days.
  850. This option is deprecated, it is better to define a block agenda instead."
  851. :group 'org-agenda-daily/weekly
  852. :type 'boolean)
  853. (defcustom org-agenda-repeating-timestamp-show-all t
  854. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  855. When nil, only one occurrence is shown, either today or the
  856. nearest into the future."
  857. :group 'org-agenda-daily/weekly
  858. :type 'boolean)
  859. (defcustom org-scheduled-past-days 10000
  860. "No. of days to continue listing scheduled items that are not marked DONE.
  861. When an item is scheduled on a date, it shows up in the agenda on this
  862. day and will be listed until it is marked done for the number of days
  863. given here."
  864. :group 'org-agenda-daily/weekly
  865. :type 'integer)
  866. (defcustom org-agenda-log-mode-items '(closed clock)
  867. "List of items that should be shown in agenda log mode.
  868. This list may contain the following symbols:
  869. closed Show entries that have been closed on that day.
  870. clock Show entries that have received clocked time on that day.
  871. state Show all logged state changes.
  872. Note that instead of changing this variable, you can also press `C-u l' in
  873. the agenda to display all available LOG items temporarily."
  874. :group 'org-agenda-daily/weekly
  875. :type '(set :greedy t (const closed) (const clock) (const state)))
  876. (defcustom org-agenda-log-mode-add-notes t
  877. "Non-nil means add first line of notes to log entries in agenda views.
  878. If a log item like a state change or a clock entry is associated with
  879. notes, the first line of these notes will be added to the entry in the
  880. agenda display."
  881. :group 'org-agenda-daily/weekly
  882. :type 'boolean)
  883. (defcustom org-agenda-start-with-log-mode nil
  884. "The initial value of log-mode in a newly created agenda window."
  885. :group 'org-agenda-startup
  886. :group 'org-agenda-daily/weekly
  887. :type 'boolean)
  888. (defcustom org-agenda-start-with-clockreport-mode nil
  889. "The initial value of clockreport-mode in a newly created agenda window."
  890. :group 'org-agenda-startup
  891. :group 'org-agenda-daily/weekly
  892. :type 'boolean)
  893. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  894. "Property list with parameters for the clocktable in clockreport mode.
  895. This is the display mode that shows a clock table in the daily/weekly
  896. agenda, the properties for this dynamic block can be set here.
  897. The usual clocktable parameters are allowed here, but you cannot set
  898. the properties :name, :tstart, :tend, :block, and :scope - these will
  899. be overwritten to make sure the content accurately reflects the
  900. current display in the agenda."
  901. :group 'org-agenda-daily/weekly
  902. :type 'plist)
  903. (defcustom org-agenda-search-view-always-boolean nil
  904. "Non-nil means the search string is interpreted as individual parts.
  905. The search string for search view can either be interpreted as a phrase,
  906. or as a list of snippets that define a boolean search for a number of
  907. strings.
  908. When this is non-nil, the string will be split on whitespace, and each
  909. snippet will be searched individually, and all must match in order to
  910. select an entry. A snippet is then a single string of non-white
  911. characters, or a string in double quotes, or a regexp in {} braces.
  912. If a snippet is preceded by \"-\", the snippet must *not* match.
  913. \"+\" is syntactic sugar for positive selection. Each snippet may
  914. be found as a full word or a partial word, but see the variable
  915. `org-agenda-search-view-force-full-words'.
  916. When this is nil, search will look for the entire search phrase as one,
  917. with each space character matching any amount of whitespace, including
  918. line breaks.
  919. Even when this is nil, you can still switch to Boolean search dynamically
  920. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  921. is a regexp marked with braces like \"{abc}\", this will also switch to
  922. boolean search."
  923. :group 'org-agenda-search-view
  924. :type 'boolean)
  925. (if (fboundp 'defvaralias)
  926. (defvaralias 'org-agenda-search-view-search-words-only
  927. 'org-agenda-search-view-always-boolean))
  928. (defcustom org-agenda-search-view-force-full-words nil
  929. "Non-nil means, search words must be matches as complete words.
  930. When nil, they may also match part of a word."
  931. :group 'org-agenda-search-view
  932. :type 'boolean)
  933. (defgroup org-agenda-time-grid nil
  934. "Options concerning the time grid in the Org-mode Agenda."
  935. :tag "Org Agenda Time Grid"
  936. :group 'org-agenda)
  937. (defcustom org-agenda-search-headline-for-time t
  938. "Non-nil means search headline for a time-of-day.
  939. If the headline contains a time-of-day in one format or another, it will
  940. be used to sort the entry into the time sequence of items for a day.
  941. Some people have time stamps in the headline that refer to the creation
  942. time or so, and then this produces an unwanted side effect. If this is
  943. the case for your, use this variable to turn off searching the headline
  944. for a time."
  945. :group 'org-agenda-time-grid
  946. :type 'boolean)
  947. (defcustom org-agenda-use-time-grid t
  948. "Non-nil means show a time grid in the agenda schedule.
  949. A time grid is a set of lines for specific times (like every two hours between
  950. 8:00 and 20:00). The items scheduled for a day at specific times are
  951. sorted in between these lines.
  952. For details about when the grid will be shown, and what it will look like, see
  953. the variable `org-agenda-time-grid'."
  954. :group 'org-agenda-time-grid
  955. :type 'boolean)
  956. (defcustom org-agenda-time-grid
  957. '((daily today require-timed)
  958. "----------------"
  959. (800 1000 1200 1400 1600 1800 2000))
  960. "The settings for time grid for agenda display.
  961. This is a list of three items. The first item is again a list. It contains
  962. symbols specifying conditions when the grid should be displayed:
  963. daily if the agenda shows a single day
  964. weekly if the agenda shows an entire week
  965. today show grid on current date, independent of daily/weekly display
  966. require-timed show grid only if at least one item has a time specification
  967. The second item is a string which will be placed behind the grid time.
  968. The third item is a list of integers, indicating the times that should have
  969. a grid line."
  970. :group 'org-agenda-time-grid
  971. :type
  972. '(list
  973. (set :greedy t :tag "Grid Display Options"
  974. (const :tag "Show grid in single day agenda display" daily)
  975. (const :tag "Show grid in weekly agenda display" weekly)
  976. (const :tag "Always show grid for today" today)
  977. (const :tag "Show grid only if any timed entries are present"
  978. require-timed)
  979. (const :tag "Skip grid times already present in an entry"
  980. remove-match))
  981. (string :tag "Grid String")
  982. (repeat :tag "Grid Times" (integer :tag "Time"))))
  983. (defgroup org-agenda-sorting nil
  984. "Options concerning sorting in the Org-mode Agenda."
  985. :tag "Org Agenda Sorting"
  986. :group 'org-agenda)
  987. (defcustom org-agenda-sorting-strategy
  988. '((agenda habit-down time-up priority-down category-keep)
  989. (todo priority-down category-keep)
  990. (tags priority-down category-keep)
  991. (search category-keep))
  992. "Sorting structure for the agenda items of a single day.
  993. This is a list of symbols which will be used in sequence to determine
  994. if an entry should be listed before another entry. The following
  995. symbols are recognized:
  996. time-up Put entries with time-of-day indications first, early first
  997. time-down Put entries with time-of-day indications first, late first
  998. category-keep Keep the default order of categories, corresponding to the
  999. sequence in `org-agenda-files'.
  1000. category-up Sort alphabetically by category, A-Z.
  1001. category-down Sort alphabetically by category, Z-A.
  1002. tag-up Sort alphabetically by last tag, A-Z.
  1003. tag-down Sort alphabetically by last tag, Z-A.
  1004. priority-up Sort numerically by priority, high priority last.
  1005. priority-down Sort numerically by priority, high priority first.
  1006. todo-state-up Sort by todo state, tasks that are done last.
  1007. todo-state-down Sort by todo state, tasks that are done first.
  1008. effort-up Sort numerically by estimated effort, high effort last.
  1009. effort-down Sort numerically by estimated effort, high effort first.
  1010. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1011. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1012. habit-up Put entries that are habits first
  1013. habit-down Put entries that are habits last
  1014. alpha-up Sort headlines alphabetically
  1015. alpha-down Sort headlines alphabetically, reversed
  1016. The different possibilities will be tried in sequence, and testing stops
  1017. if one comparison returns a \"not-equal\". For example, the default
  1018. '(time-up category-keep priority-down)
  1019. means: Pull out all entries having a specified time of day and sort them,
  1020. in order to make a time schedule for the current day the first thing in the
  1021. agenda listing for the day. Of the entries without a time indication, keep
  1022. the grouped in categories, don't sort the categories, but keep them in
  1023. the sequence given in `org-agenda-files'. Within each category sort by
  1024. priority.
  1025. Leaving out `category-keep' would mean that items will be sorted across
  1026. categories by priority.
  1027. Instead of a single list, this can also be a set of list for specific
  1028. contents, with a context symbol in the car of the list, any of
  1029. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1030. Custom commands can bind this variable in the options section."
  1031. :group 'org-agenda-sorting
  1032. :type `(choice
  1033. (repeat :tag "General" ,org-sorting-choice)
  1034. (list :tag "Individually"
  1035. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1036. (repeat ,org-sorting-choice))
  1037. (cons (const :tag "Strategy for TODO lists" todo)
  1038. (repeat ,org-sorting-choice))
  1039. (cons (const :tag "Strategy for Tags matches" tags)
  1040. (repeat ,org-sorting-choice))
  1041. (cons (const :tag "Strategy for search matches" search)
  1042. (repeat ,org-sorting-choice)))))
  1043. (defcustom org-agenda-cmp-user-defined nil
  1044. "A function to define the comparison `user-defined'.
  1045. This function must receive two arguments, agenda entry a and b.
  1046. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1047. the user comparison, return nil.
  1048. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1049. part of an agenda sorting strategy."
  1050. :group 'org-agenda-sorting
  1051. :type 'symbol)
  1052. (defcustom org-sort-agenda-notime-is-late t
  1053. "Non-nil means items without time are considered late.
  1054. This is only relevant for sorting. When t, items which have no explicit
  1055. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1056. do have a time. When nil, the default time is before 0:00. You can use this
  1057. option to decide if the schedule for today should come before or after timeless
  1058. agenda entries."
  1059. :group 'org-agenda-sorting
  1060. :type 'boolean)
  1061. (defcustom org-sort-agenda-noeffort-is-high t
  1062. "Non-nil means items without effort estimate are sorted as high effort.
  1063. This also applies when filtering an agenda view with respect to the
  1064. < or > effort operator. Then, tasks with no effort defined will be treated
  1065. as tasks with high effort.
  1066. When nil, such items are sorted as 0 minutes effort."
  1067. :group 'org-agenda-sorting
  1068. :type 'boolean)
  1069. (defgroup org-agenda-line-format nil
  1070. "Options concerning the entry prefix in the Org-mode agenda display."
  1071. :tag "Org Agenda Line Format"
  1072. :group 'org-agenda)
  1073. (defcustom org-agenda-prefix-format
  1074. '((agenda . " %i %-12:c%?-12t% s")
  1075. (timeline . " % s")
  1076. (todo . " %i %-12:c")
  1077. (tags . " %i %-12:c")
  1078. (search . " %i %-12:c"))
  1079. "Format specifications for the prefix of items in the agenda views.
  1080. An alist with four entries, for the different agenda types. The keys to the
  1081. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1082. are format strings.
  1083. This format works similar to a printf format, with the following meaning:
  1084. %c the category of the item, \"Diary\" for entries from the diary, or
  1085. as given by the CATEGORY keyword or derived from the file name.
  1086. %i the icon category of the item, as give in
  1087. `org-agenda-category-icon-alist'.
  1088. %T the *last* tag of the item. Last because inherited tags come
  1089. first in the list.
  1090. %t the time-of-day specification if one applies to the entry, in the
  1091. format HH:MM
  1092. %s Scheduling/Deadline information, a short string
  1093. All specifiers work basically like the standard `%s' of printf, but may
  1094. contain two additional characters: A question mark just after the `%' and
  1095. a whitespace/punctuation character just before the final letter.
  1096. If the first character after `%' is a question mark, the entire field
  1097. will only be included if the corresponding value applies to the
  1098. current entry. This is useful for fields which should have fixed
  1099. width when present, but zero width when absent. For example,
  1100. \"%?-12t\" will result in a 12 character time field if a time of the
  1101. day is specified, but will completely disappear in entries which do
  1102. not contain a time.
  1103. If there is punctuation or whitespace character just before the final
  1104. format letter, this character will be appended to the field value if
  1105. the value is not empty. For example, the format \"%-12:c\" leads to
  1106. \"Diary: \" if the category is \"Diary\". If the category were be
  1107. empty, no additional colon would be inserted.
  1108. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1109. - Indent the line with two space characters
  1110. - Give the category in a 12 chars wide field, padded with whitespace on
  1111. the right (because of `-'). Append a colon if there is a category
  1112. (because of `:').
  1113. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1114. time, don't put in an empty field, just skip it (because of '?').
  1115. - Finally, put the scheduling information and append a whitespace.
  1116. As another example, if you don't want the time-of-day of entries in
  1117. the prefix, you could use:
  1118. (setq org-agenda-prefix-format \" %-11:c% s\")
  1119. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1120. `org-agenda-remove-tags'.
  1121. Custom commands can set this variable in the options section."
  1122. :type '(choice
  1123. (string :tag "General format")
  1124. (list :greedy t :tag "View dependent"
  1125. (cons (const agenda) (string :tag "Format"))
  1126. (cons (const timeline) (string :tag "Format"))
  1127. (cons (const todo) (string :tag "Format"))
  1128. (cons (const tags) (string :tag "Format"))
  1129. (cons (const search) (string :tag "Format"))))
  1130. :group 'org-agenda-line-format)
  1131. (defvar org-prefix-format-compiled nil
  1132. "The compiled version of the most recently used prefix format.
  1133. See the variable `org-agenda-prefix-format'.")
  1134. (defcustom org-agenda-todo-keyword-format "%-1s"
  1135. "Format for the TODO keyword in agenda lines.
  1136. Set this to something like \"%-12s\" if you want all TODO keywords
  1137. to occupy a fixed space in the agenda display."
  1138. :group 'org-agenda-line-format
  1139. :type 'string)
  1140. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1141. "Text preceding timerange entries in the agenda view.
  1142. This is a list with two strings. The first applies when the range
  1143. is entirely on one day. The second applies if the range spans several days.
  1144. The strings may have two \"%d\" format specifiers which will be filled
  1145. with the sequence number of the days, and the total number of days in the
  1146. range, respectively."
  1147. :group 'org-agenda-line-format
  1148. :type '(list
  1149. (string :tag "Deadline today ")
  1150. (choice :tag "Deadline relative"
  1151. (string :tag "Format string")
  1152. (function))))
  1153. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1154. "Text preceding scheduled items in the agenda view.
  1155. This is a list with two strings. The first applies when the item is
  1156. scheduled on the current day. The second applies when it has been scheduled
  1157. previously, it may contain a %d indicating that this is the nth time that
  1158. this item is scheduled, due to automatic rescheduling of unfinished items
  1159. for the following day. So this number is one larger than the number of days
  1160. that passed since this item was scheduled first."
  1161. :group 'org-agenda-line-format
  1162. :type '(list
  1163. (string :tag "Scheduled today ")
  1164. (string :tag "Scheduled previously")))
  1165. (defcustom org-agenda-inactive-leader "["
  1166. "Text preceding item pulled into the agenda by inactive time stamps.
  1167. These entries are added to the agenda when pressing \"[\"."
  1168. :group 'org-agenda-line-format
  1169. :type '(list
  1170. (string :tag "Scheduled today ")
  1171. (string :tag "Scheduled previously")))
  1172. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1173. "Text preceding deadline items in the agenda view.
  1174. This is a list with two strings. The first applies when the item has its
  1175. deadline on the current day. The second applies when it is in the past or
  1176. in the future, it may contain %d to capture how many days away the deadline
  1177. is (was)."
  1178. :group 'org-agenda-line-format
  1179. :type '(list
  1180. (string :tag "Deadline today ")
  1181. (choice :tag "Deadline relative"
  1182. (string :tag "Format string")
  1183. (function))))
  1184. (defcustom org-agenda-remove-times-when-in-prefix t
  1185. "Non-nil means remove duplicate time specifications in agenda items.
  1186. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1187. time-of-day specification in a headline or diary entry is extracted and
  1188. placed into the prefix. If this option is non-nil, the original specification
  1189. \(a timestamp or -range, or just a plain time(range) specification like
  1190. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1191. cluttered.
  1192. The option can be t or nil. It may also be the symbol `beg', indicating
  1193. that the time should only be removed when it is located at the beginning of
  1194. the headline/diary entry."
  1195. :group 'org-agenda-line-format
  1196. :type '(choice
  1197. (const :tag "Always" t)
  1198. (const :tag "Never" nil)
  1199. (const :tag "When at beginning of entry" beg)))
  1200. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1201. "Non-nil means remove time ranges specifications in agenda
  1202. items that span on several days."
  1203. :group 'org-agenda-line-format
  1204. :type 'boolean)
  1205. (defcustom org-agenda-default-appointment-duration nil
  1206. "Default duration for appointments that only have a starting time.
  1207. When nil, no duration is specified in such cases.
  1208. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1209. :group 'org-agenda-line-format
  1210. :type '(choice
  1211. (integer :tag "Minutes")
  1212. (const :tag "No default duration")))
  1213. (defcustom org-agenda-show-inherited-tags t
  1214. "Non-nil means show inherited tags in each agenda line."
  1215. :group 'org-agenda-line-format
  1216. :type 'boolean)
  1217. (defcustom org-agenda-hide-tags-regexp nil
  1218. "Regular expression used to filter away specific tags in agenda views.
  1219. This means that these tags will be present, but not be shown in the agenda
  1220. line. Secondary filtering will still work on the hidden tags.
  1221. Nil means don't hide any tags."
  1222. :group 'org-agenda-line-format
  1223. :type '(choice
  1224. (const :tag "Hide none" nil)
  1225. (string :tag "Regexp ")))
  1226. (defcustom org-agenda-remove-tags nil
  1227. "Non-nil means remove the tags from the headline copy in the agenda.
  1228. When this is the symbol `prefix', only remove tags when
  1229. `org-agenda-prefix-format' contains a `%T' specifier."
  1230. :group 'org-agenda-line-format
  1231. :type '(choice
  1232. (const :tag "Always" t)
  1233. (const :tag "Never" nil)
  1234. (const :tag "When prefix format contains %T" prefix)))
  1235. (if (fboundp 'defvaralias)
  1236. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1237. 'org-agenda-remove-tags))
  1238. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1239. "Shift tags in agenda items to this column.
  1240. If this number is positive, it specifies the column. If it is negative,
  1241. it means that the tags should be flushright to that column. For example,
  1242. -80 works well for a normal 80 character screen."
  1243. :group 'org-agenda-line-format
  1244. :type 'integer)
  1245. (if (fboundp 'defvaralias)
  1246. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1247. (defcustom org-agenda-fontify-priorities 'cookies
  1248. "Non-nil means highlight low and high priorities in agenda.
  1249. When t, the highest priority entries are bold, lowest priority italic.
  1250. However, settings in `org-priority-faces' will overrule these faces.
  1251. When this variable is the symbol `cookies', only fontify the
  1252. cookies, not the entire task.
  1253. This may also be an association list of priority faces, whose
  1254. keys are the character values of `org-highest-priority',
  1255. `org-default-priority', and `org-lowest-priority' (the default values
  1256. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1257. color as a string, or a list like `(:background \"Red\")'.
  1258. If it is a color, the variable `org-faces-easy-properties'
  1259. determines if it is a foreground or a background color."
  1260. :group 'org-agenda-line-format
  1261. :type '(choice
  1262. (const :tag "Never" nil)
  1263. (const :tag "Defaults" t)
  1264. (const :tag "Cookies only" cookies)
  1265. (repeat :tag "Specify"
  1266. (list (character :tag "Priority" :value ?A)
  1267. (choice :tag "Face "
  1268. (string :tag "Color")
  1269. (sexp :tag "Face"))))))
  1270. (defcustom org-agenda-category-icon-alist nil
  1271. "Alist of category icon to be displayed in agenda views.
  1272. Each entry should have the following format:
  1273. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1274. Where CATEGORY-REGEXP is a regexp matching the categories where
  1275. the icon should be displayed.
  1276. FILE-OR-DATA either a file path or a string containing image data.
  1277. The other fields can be ommited safely if not needed:
  1278. TYPE indicates the image type.
  1279. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1280. image data.
  1281. PROPS are additional image attributes to assign to the image,
  1282. like, e.g. `:ascent center'.
  1283. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1284. If you want to set the display properties yourself, just put a
  1285. list as second element:
  1286. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1287. For example, to display a 16px horizontal space for Emacs
  1288. category, you can use:
  1289. (\"Emacs\" '(space . (:width (16))))"
  1290. :group 'org-agenda-line-format
  1291. :type '(alist :key-type (string :tag "Regexp matching category")
  1292. :value-type (choice (list :tag "Icon"
  1293. (string :tag "File or data")
  1294. (symbol :tag "Type")
  1295. (boolean :tag "Data?")
  1296. (repeat :tag "Extra image properties" :inline t symbol))
  1297. (list :tag "Display properties" sexp))))
  1298. (defgroup org-agenda-column-view nil
  1299. "Options concerning column view in the agenda."
  1300. :tag "Org Agenda Column View"
  1301. :group 'org-agenda)
  1302. (defcustom org-agenda-columns-show-summaries t
  1303. "Non-nil means show summaries for columns displayed in the agenda view."
  1304. :group 'org-agenda-column-view
  1305. :type 'boolean)
  1306. (defcustom org-agenda-columns-remove-prefix-from-item t
  1307. "Non-nil means remove the prefix from a headline for agenda column view.
  1308. The special ITEM field in the columns format contains the current line, with
  1309. all information shown in other columns (like the TODO state or a tag).
  1310. When this variable is non-nil, also the agenda prefix will be removed from
  1311. the content of the ITEM field, to make sure as much as possible of the
  1312. headline can be shown in the limited width of the field."
  1313. :group 'org-agenda
  1314. :type 'boolean)
  1315. (defcustom org-agenda-columns-compute-summary-properties t
  1316. "Non-nil means recompute all summary properties before column view.
  1317. When column view in the agenda is listing properties that have a summary
  1318. operator, it can go to all relevant buffers and recompute the summaries
  1319. there. This can mean overhead for the agenda column view, but is necessary
  1320. to have thing up to date.
  1321. As a special case, a CLOCKSUM property also makes sure that the clock
  1322. computations are current."
  1323. :group 'org-agenda-column-view
  1324. :type 'boolean)
  1325. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1326. "Non-nil means the duration of an appointment will add to day effort.
  1327. The property to which appointment durations will be added is the one given
  1328. in the option `org-effort-property'. If an appointment does not have
  1329. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1330. is not set, an appointment without end time will not contribute to the time
  1331. estimate."
  1332. :group 'org-agenda-column-view
  1333. :type 'boolean)
  1334. (defcustom org-agenda-auto-exclude-function nil
  1335. "A function called with a tag to decide if it is filtered on '/ RET'.
  1336. The sole argument to the function, which is called once for each
  1337. possible tag, is a string giving the name of the tag. The
  1338. function should return either nil if the tag should be included
  1339. as normal, or \"-<TAG>\" to exclude the tag.
  1340. Note that for the purpose of tag filtering, only the lower-case version of
  1341. all tags will be considered, so that this function will only ever see
  1342. the lower-case version of all tags."
  1343. :group 'org-agenda
  1344. :type 'function)
  1345. (eval-when-compile
  1346. (require 'cl))
  1347. (require 'org)
  1348. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1349. "Execute BODY with point at location given by `org-hd-marker' property.
  1350. If STRING is non-nil, the text property will be fetched from position 0
  1351. in that string. If STRING is nil, it will be fetched from the beginning
  1352. of the current line."
  1353. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1354. 'org-hd-marker string)))
  1355. (with-current-buffer (marker-buffer marker)
  1356. (save-excursion
  1357. (goto-char marker)
  1358. ,@body))))
  1359. (defun org-add-agenda-custom-command (entry)
  1360. "Replace or add a command in `org-agenda-custom-commands'.
  1361. This is mostly for hacking and trying a new command - once the command
  1362. works you probably want to add it to `org-agenda-custom-commands' for good."
  1363. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1364. (if ass
  1365. (setcdr ass (cdr entry))
  1366. (push entry org-agenda-custom-commands))))
  1367. ;;; Define the Org-agenda-mode
  1368. (defvar org-agenda-mode-map (make-sparse-keymap)
  1369. "Keymap for `org-agenda-mode'.")
  1370. (if (fboundp 'defvaralias)
  1371. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1372. (defvar org-agenda-menu) ; defined later in this file.
  1373. (defvar org-agenda-restrict) ; defined later in this file.
  1374. (defvar org-agenda-follow-mode nil)
  1375. (defvar org-agenda-entry-text-mode nil)
  1376. (defvar org-agenda-clockreport-mode nil)
  1377. (defvar org-agenda-show-log nil)
  1378. (defvar org-agenda-redo-command nil)
  1379. (defvar org-agenda-query-string nil)
  1380. (defvar org-agenda-mode-hook nil
  1381. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1382. (defvar org-agenda-type nil)
  1383. (defvar org-agenda-force-single-file nil)
  1384. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1385. (defun org-agenda-mode ()
  1386. "Mode for time-sorted view on action items in Org-mode files.
  1387. The following commands are available:
  1388. \\{org-agenda-mode-map}"
  1389. (interactive)
  1390. (kill-all-local-variables)
  1391. (setq org-agenda-undo-list nil
  1392. org-agenda-pending-undo-list nil
  1393. org-agenda-bulk-marked-entries nil)
  1394. (setq major-mode 'org-agenda-mode)
  1395. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1396. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1397. (setq mode-name "Org-Agenda")
  1398. (use-local-map org-agenda-mode-map)
  1399. (easy-menu-add org-agenda-menu)
  1400. (if org-startup-truncated (setq truncate-lines t))
  1401. (org-set-local 'line-move-visual nil)
  1402. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1403. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1404. ;; Make sure properties are removed when copying text
  1405. (when (boundp 'buffer-substring-filters)
  1406. (org-set-local 'buffer-substring-filters
  1407. (cons (lambda (x)
  1408. (set-text-properties 0 (length x) nil x) x)
  1409. buffer-substring-filters)))
  1410. (unless org-agenda-keep-modes
  1411. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1412. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1413. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1414. org-agenda-show-log org-agenda-start-with-log-mode))
  1415. (easy-menu-change
  1416. '("Agenda") "Agenda Files"
  1417. (append
  1418. (list
  1419. (vector
  1420. (if (get 'org-agenda-files 'org-restrict)
  1421. "Restricted to single file"
  1422. "Edit File List")
  1423. '(org-edit-agenda-file-list)
  1424. (not (get 'org-agenda-files 'org-restrict)))
  1425. "--")
  1426. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1427. (org-agenda-set-mode-name)
  1428. (apply
  1429. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1430. (list 'org-agenda-mode-hook)))
  1431. (substitute-key-definition 'undo 'org-agenda-undo
  1432. org-agenda-mode-map global-map)
  1433. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1434. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1435. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1436. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1437. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1438. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1439. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1440. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1441. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1442. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1443. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1444. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1445. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1446. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1447. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1448. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1449. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1450. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1451. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1452. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1453. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1454. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1455. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1456. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1457. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1458. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1459. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1460. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1461. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1462. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1463. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1464. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1465. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1466. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1467. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1468. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1469. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1470. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1471. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1472. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1473. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1474. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1475. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1476. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1477. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1478. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1479. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1480. (while l (org-defkey org-agenda-mode-map
  1481. (int-to-string (pop l)) 'digit-argument)))
  1482. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1483. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1484. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1485. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1486. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1487. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1488. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1489. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1490. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1491. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1492. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1493. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1494. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1495. 'org-clock-modify-effort-estimate)
  1496. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1497. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1498. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1499. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1500. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1501. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1502. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1503. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1504. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1505. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1506. (substitute-key-definition 'next-line 'org-agenda-next-line
  1507. org-agenda-mode-map global-map)
  1508. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1509. org-agenda-mode-map global-map)
  1510. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1511. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1512. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1513. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1514. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1515. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1516. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1517. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1518. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1519. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1520. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1521. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1522. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1523. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1524. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1525. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1526. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1527. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1528. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1529. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1530. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1531. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1532. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1533. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1534. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1535. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1536. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1537. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1538. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1539. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1540. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1541. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1542. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1543. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1544. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1545. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1546. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1547. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1548. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1549. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1550. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1551. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1552. (when org-agenda-mouse-1-follows-link
  1553. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1554. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1555. '("Agenda"
  1556. ("Agenda Files")
  1557. "--"
  1558. ("Agenda Dates"
  1559. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1560. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1561. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1562. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1563. "--"
  1564. ("View"
  1565. ["Day View" org-agenda-day-view
  1566. :active (org-agenda-check-type nil 'agenda)
  1567. :style radio :selected (equal org-agenda-ndays 1)
  1568. :keys "v d (or just d)"]
  1569. ["Week View" org-agenda-week-view
  1570. :active (org-agenda-check-type nil 'agenda)
  1571. :style radio :selected (equal org-agenda-ndays 7)
  1572. :keys "v w (or just w)"]
  1573. ["Month View" org-agenda-month-view
  1574. :active (org-agenda-check-type nil 'agenda)
  1575. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1576. :keys "v m"]
  1577. ["Year View" org-agenda-year-view
  1578. :active (org-agenda-check-type nil 'agenda)
  1579. :style radio :selected (member org-agenda-ndays '(365 366))
  1580. :keys "v y"]
  1581. "--"
  1582. ["Include Diary" org-agenda-toggle-diary
  1583. :style toggle :selected org-agenda-include-diary
  1584. :active (org-agenda-check-type nil 'agenda)]
  1585. ["Include Deadlines" org-agenda-toggle-deadlines
  1586. :style toggle :selected org-agenda-include-deadlines
  1587. :active (org-agenda-check-type nil 'agenda)]
  1588. ["Use Time Grid" org-agenda-toggle-time-grid
  1589. :style toggle :selected org-agenda-use-time-grid
  1590. :active (org-agenda-check-type nil 'agenda)]
  1591. "--"
  1592. ["Show clock report" org-agenda-clockreport-mode
  1593. :style toggle :selected org-agenda-clockreport-mode
  1594. :active (org-agenda-check-type nil 'agenda)]
  1595. ["Show some entry text" org-agenda-entry-text-mode
  1596. :style toggle :selected org-agenda-entry-text-mode
  1597. :active t]
  1598. "--"
  1599. ["Show Logbook entries" org-agenda-log-mode
  1600. :style toggle :selected org-agenda-show-log
  1601. :active (org-agenda-check-type nil 'agenda 'timeline)
  1602. :keys "v l (or just l)"]
  1603. ["Include archived trees" org-agenda-archives-mode
  1604. :style toggle :selected org-agenda-archives-mode :active t
  1605. :keys "v a"]
  1606. ["Include archive files" (org-agenda-archives-mode t)
  1607. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1608. :keys "v A"]
  1609. "--"
  1610. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1611. ["Write view to file" org-write-agenda t]
  1612. ["Rebuild buffer" org-agenda-redo t]
  1613. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1614. "--"
  1615. ["Show original entry" org-agenda-show t]
  1616. ["Go To (other window)" org-agenda-goto t]
  1617. ["Go To (this window)" org-agenda-switch-to t]
  1618. ["Follow Mode" org-agenda-follow-mode
  1619. :style toggle :selected org-agenda-follow-mode :active t]
  1620. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1621. "--"
  1622. ("TODO"
  1623. ["Cycle TODO" org-agenda-todo t]
  1624. ["Next TODO set" org-agenda-todo-nextset t]
  1625. ["Previous TODO set" org-agenda-todo-previousset t]
  1626. ["Add note" org-agenda-add-note t])
  1627. ("Archive/Refile/Delete"
  1628. ["Archive default" org-agenda-archive-default t]
  1629. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1630. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1631. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1632. ["Archive subtree" org-agenda-archive t]
  1633. "--"
  1634. ["Refile" org-agenda-refile t]
  1635. "--"
  1636. ["Delete subtree" org-agenda-kill t])
  1637. ("Bulk action"
  1638. ["Mark entry" org-agenda-bulk-mark t]
  1639. ["Unmark entry" org-agenda-bulk-unmark t]
  1640. ["Act on all marked" org-agenda-bulk-action t]
  1641. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1642. "--"
  1643. ("Tags and Properties"
  1644. ["Show all Tags" org-agenda-show-tags t]
  1645. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1646. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1647. "--"
  1648. ["Column View" org-columns t])
  1649. ("Deadline/Schedule"
  1650. ["Schedule" org-agenda-schedule t]
  1651. ["Set Deadline" org-agenda-deadline t]
  1652. "--"
  1653. ["Mark item" org-agenda-action :active t :keys "k m"]
  1654. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1655. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1656. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1657. "--"
  1658. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1659. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1660. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1661. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1662. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1663. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1664. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1665. ("Clock and Effort"
  1666. ["Clock in" org-agenda-clock-in t]
  1667. ["Clock out" org-agenda-clock-out t]
  1668. ["Clock cancel" org-agenda-clock-cancel t]
  1669. ["Goto running clock" org-clock-goto t]
  1670. "--"
  1671. ["Set Effort" org-agenda-set-effort t]
  1672. ["Change clocked effort" org-clock-modify-effort-estimate
  1673. (org-clock-is-active)])
  1674. ("Priority"
  1675. ["Set Priority" org-agenda-priority t]
  1676. ["Increase Priority" org-agenda-priority-up t]
  1677. ["Decrease Priority" org-agenda-priority-down t]
  1678. ["Show Priority" org-agenda-show-priority t])
  1679. ("Calendar/Diary"
  1680. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1681. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1682. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1683. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1684. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1685. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1686. "--"
  1687. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1688. "--"
  1689. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1690. "--"
  1691. ("MobileOrg"
  1692. ["Push Files and Views" org-mobile-push t]
  1693. ["Get Captured and Flagged" org-mobile-pull t]
  1694. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1695. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1696. "--"
  1697. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1698. "--"
  1699. ["Quit" org-agenda-quit t]
  1700. ["Exit and Release Buffers" org-agenda-exit t]
  1701. ))
  1702. ;;; Agenda undo
  1703. (defvar org-agenda-allow-remote-undo t
  1704. "Non-nil means allow remote undo from the agenda buffer.")
  1705. (defvar org-agenda-undo-list nil
  1706. "List of undoable operations in the agenda since last refresh.")
  1707. (defvar org-agenda-undo-has-started-in nil
  1708. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1709. (defvar org-agenda-pending-undo-list nil
  1710. "In a series of undo commands, this is the list of remaining undo items.")
  1711. (defun org-agenda-undo ()
  1712. "Undo a remote editing step in the agenda.
  1713. This undoes changes both in the agenda buffer and in the remote buffer
  1714. that have been changed along."
  1715. (interactive)
  1716. (or org-agenda-allow-remote-undo
  1717. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1718. (if (not (eq this-command last-command))
  1719. (setq org-agenda-undo-has-started-in nil
  1720. org-agenda-pending-undo-list org-agenda-undo-list))
  1721. (if (not org-agenda-pending-undo-list)
  1722. (error "No further undo information"))
  1723. (let* ((entry (pop org-agenda-pending-undo-list))
  1724. buf line cmd rembuf)
  1725. (setq cmd (pop entry) line (pop entry))
  1726. (setq rembuf (nth 2 entry))
  1727. (org-with-remote-undo rembuf
  1728. (while (bufferp (setq buf (pop entry)))
  1729. (if (pop entry)
  1730. (with-current-buffer buf
  1731. (let ((last-undo-buffer buf)
  1732. (inhibit-read-only t))
  1733. (unless (memq buf org-agenda-undo-has-started-in)
  1734. (push buf org-agenda-undo-has-started-in)
  1735. (make-local-variable 'pending-undo-list)
  1736. (undo-start))
  1737. (while (and pending-undo-list
  1738. (listp pending-undo-list)
  1739. (not (car pending-undo-list)))
  1740. (pop pending-undo-list))
  1741. (undo-more 1))))))
  1742. (org-goto-line line)
  1743. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1744. (defun org-verify-change-for-undo (l1 l2)
  1745. "Verify that a real change occurred between the undo lists L1 and L2."
  1746. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1747. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1748. (not (eq l1 l2)))
  1749. ;;; Agenda dispatch
  1750. (defvar org-agenda-restrict nil)
  1751. (defvar org-agenda-restrict-begin (make-marker))
  1752. (defvar org-agenda-restrict-end (make-marker))
  1753. (defvar org-agenda-last-dispatch-buffer nil)
  1754. (defvar org-agenda-overriding-restriction nil)
  1755. ;;;###autoload
  1756. (defun org-agenda (&optional arg keys restriction)
  1757. "Dispatch agenda commands to collect entries to the agenda buffer.
  1758. Prompts for a command to execute. Any prefix arg will be passed
  1759. on to the selected command. The default selections are:
  1760. a Call `org-agenda-list' to display the agenda for current day or week.
  1761. t Call `org-todo-list' to display the global todo list.
  1762. T Call `org-todo-list' to display the global todo list, select only
  1763. entries with a specific TODO keyword (the user gets a prompt).
  1764. m Call `org-tags-view' to display headlines with tags matching
  1765. a condition (the user is prompted for the condition).
  1766. M Like `m', but select only TODO entries, no ordinary headlines.
  1767. L Create a timeline for the current buffer.
  1768. e Export views to associated files.
  1769. s Search entries for keywords.
  1770. / Multi occur across all agenda files and also files listed
  1771. in `org-agenda-text-search-extra-files'.
  1772. < Restrict agenda commands to buffer, subtree, or region.
  1773. Press several times to get the desired effect.
  1774. > Remove a previous restriction.
  1775. # List \"stuck\" projects.
  1776. ! Configure what \"stuck\" means.
  1777. C Configure custom agenda commands.
  1778. More commands can be added by configuring the variable
  1779. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1780. searches can be pre-defined in this way.
  1781. If the current buffer is in Org-mode and visiting a file, you can also
  1782. first press `<' once to indicate that the agenda should be temporarily
  1783. \(until the next use of \\[org-agenda]) restricted to the current file.
  1784. Pressing `<' twice means to restrict to the current subtree or region
  1785. \(if active)."
  1786. (interactive "P")
  1787. (catch 'exit
  1788. (let* ((prefix-descriptions nil)
  1789. (org-agenda-window-setup (if (equal (buffer-name)
  1790. org-agenda-buffer-name)
  1791. 'current-window
  1792. org-agenda-window-setup))
  1793. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1794. (org-agenda-custom-commands
  1795. ;; normalize different versions
  1796. (delq nil
  1797. (mapcar
  1798. (lambda (x)
  1799. (cond ((stringp (cdr x))
  1800. (push x prefix-descriptions)
  1801. nil)
  1802. ((stringp (nth 1 x)) x)
  1803. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1804. (t (cons (car x) (cons "" (cdr x))))))
  1805. org-agenda-custom-commands)))
  1806. (buf (current-buffer))
  1807. (bfn (buffer-file-name (buffer-base-buffer)))
  1808. entry key type match lprops ans)
  1809. ;; Turn off restriction unless there is an overriding one,
  1810. (unless org-agenda-overriding-restriction
  1811. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1812. ;; There is a request to keep the file list in place
  1813. (put 'org-agenda-files 'org-restrict nil))
  1814. (setq org-agenda-restrict nil)
  1815. (move-marker org-agenda-restrict-begin nil)
  1816. (move-marker org-agenda-restrict-end nil))
  1817. ;; Delete old local properties
  1818. (put 'org-agenda-redo-command 'org-lprops nil)
  1819. ;; Remember where this call originated
  1820. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1821. (unless keys
  1822. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1823. keys (car ans)
  1824. restriction (cdr ans)))
  1825. ;; Establish the restriction, if any
  1826. (when (and (not org-agenda-overriding-restriction) restriction)
  1827. (put 'org-agenda-files 'org-restrict (list bfn))
  1828. (cond
  1829. ((eq restriction 'region)
  1830. (setq org-agenda-restrict t)
  1831. (move-marker org-agenda-restrict-begin (region-beginning))
  1832. (move-marker org-agenda-restrict-end (region-end)))
  1833. ((eq restriction 'subtree)
  1834. (save-excursion
  1835. (setq org-agenda-restrict t)
  1836. (org-back-to-heading t)
  1837. (move-marker org-agenda-restrict-begin (point))
  1838. (move-marker org-agenda-restrict-end
  1839. (progn (org-end-of-subtree t)))))))
  1840. ;; For example the todo list should not need it (but does...)
  1841. (cond
  1842. ((setq entry (assoc keys org-agenda-custom-commands))
  1843. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1844. (progn
  1845. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1846. lprops (nth 4 entry))
  1847. (put 'org-agenda-redo-command 'org-lprops lprops)
  1848. (cond
  1849. ((eq type 'agenda)
  1850. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1851. ((eq type 'alltodo)
  1852. (org-let lprops '(org-todo-list current-prefix-arg)))
  1853. ((eq type 'search)
  1854. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1855. ((eq type 'stuck)
  1856. (org-let lprops '(org-agenda-list-stuck-projects
  1857. current-prefix-arg)))
  1858. ((eq type 'tags)
  1859. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1860. ((eq type 'tags-todo)
  1861. (org-let lprops '(org-tags-view '(4) match)))
  1862. ((eq type 'todo)
  1863. (org-let lprops '(org-todo-list match)))
  1864. ((eq type 'tags-tree)
  1865. (org-check-for-org-mode)
  1866. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1867. ((eq type 'todo-tree)
  1868. (org-check-for-org-mode)
  1869. (org-let lprops
  1870. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1871. (regexp-quote match) "\\>"))))
  1872. ((eq type 'occur-tree)
  1873. (org-check-for-org-mode)
  1874. (org-let lprops '(org-occur match)))
  1875. ((functionp type)
  1876. (org-let lprops '(funcall type match)))
  1877. ((fboundp type)
  1878. (org-let lprops '(funcall type match)))
  1879. (t (error "Invalid custom agenda command type %s" type))))
  1880. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1881. ((equal keys "C")
  1882. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1883. (customize-variable 'org-agenda-custom-commands))
  1884. ((equal keys "a") (call-interactively 'org-agenda-list))
  1885. ((equal keys "s") (call-interactively 'org-search-view))
  1886. ((equal keys "t") (call-interactively 'org-todo-list))
  1887. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1888. ((equal keys "m") (call-interactively 'org-tags-view))
  1889. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1890. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1891. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1892. (org-add-hook
  1893. 'post-command-hook
  1894. (lambda ()
  1895. (unless (current-message)
  1896. (let* ((m (org-agenda-get-any-marker))
  1897. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1898. (when note
  1899. (message (concat
  1900. "FLAGGING-NOTE ([?] for more info): "
  1901. (org-add-props
  1902. (replace-regexp-in-string
  1903. "\\\\n" "//"
  1904. (copy-sequence note))
  1905. nil 'face 'org-warning)))))))
  1906. t t))
  1907. ((equal keys "L")
  1908. (unless (org-mode-p)
  1909. (error "This is not an Org-mode file"))
  1910. (unless restriction
  1911. (put 'org-agenda-files 'org-restrict (list bfn))
  1912. (org-call-with-arg 'org-timeline arg)))
  1913. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1914. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1915. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1916. (t (error "Invalid agenda key"))))))
  1917. (defun org-agenda-normalize-custom-commands (cmds)
  1918. (delq nil
  1919. (mapcar
  1920. (lambda (x)
  1921. (cond ((stringp (cdr x)) nil)
  1922. ((stringp (nth 1 x)) x)
  1923. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1924. (t (cons (car x) (cons "" (cdr x))))))
  1925. cmds)))
  1926. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1927. "The user interface for selecting an agenda command."
  1928. (catch 'exit
  1929. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1930. (restrict-ok (and bfn (org-mode-p)))
  1931. (region-p (org-region-active-p))
  1932. (custom org-agenda-custom-commands)
  1933. (selstring "")
  1934. restriction second-time
  1935. c entry key type match prefixes rmheader header-end custom1 desc
  1936. line lines left right n n1)
  1937. (save-window-excursion
  1938. (delete-other-windows)
  1939. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1940. (erase-buffer)
  1941. (insert (eval-when-compile
  1942. (let ((header
  1943. "
  1944. Press key for an agenda command: < Buffer, subtree/region restriction
  1945. -------------------------------- > Remove restriction
  1946. a Agenda for current week or day e Export agenda views
  1947. t List of all TODO entries T Entries with special TODO kwd
  1948. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1949. L Timeline for current buffer # List stuck projects (!=configure)
  1950. s Search for keywords C Configure custom agenda commands
  1951. / Multi-occur ? Find :FLAGGED: entries
  1952. ")
  1953. (start 0))
  1954. (while (string-match
  1955. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1956. header start)
  1957. (setq start (match-end 0))
  1958. (add-text-properties (match-beginning 2) (match-end 2)
  1959. '(face bold) header))
  1960. header)))
  1961. (setq header-end (move-marker (make-marker) (point)))
  1962. (while t
  1963. (setq custom1 custom)
  1964. (when (eq rmheader t)
  1965. (org-goto-line 1)
  1966. (re-search-forward ":" nil t)
  1967. (delete-region (match-end 0) (point-at-eol))
  1968. (forward-char 1)
  1969. (looking-at "-+")
  1970. (delete-region (match-end 0) (point-at-eol))
  1971. (move-marker header-end (match-end 0)))
  1972. (goto-char header-end)
  1973. (delete-region (point) (point-max))
  1974. ;; Produce all the lines that describe custom commands and prefixes
  1975. (setq lines nil)
  1976. (while (setq entry (pop custom1))
  1977. (setq key (car entry) desc (nth 1 entry)
  1978. type (nth 2 entry)
  1979. match (nth 3 entry))
  1980. (if (> (length key) 1)
  1981. (add-to-list 'prefixes (string-to-char key))
  1982. (setq line
  1983. (format
  1984. "%-4s%-14s"
  1985. (org-add-props (copy-sequence key)
  1986. '(face bold))
  1987. (cond
  1988. ((string-match "\\S-" desc) desc)
  1989. ((eq type 'agenda) "Agenda for current week or day")
  1990. ((eq type 'alltodo) "List of all TODO entries")
  1991. ((eq type 'search) "Word search")
  1992. ((eq type 'stuck) "List of stuck projects")
  1993. ((eq type 'todo) "TODO keyword")
  1994. ((eq type 'tags) "Tags query")
  1995. ((eq type 'tags-todo) "Tags (TODO)")
  1996. ((eq type 'tags-tree) "Tags tree")
  1997. ((eq type 'todo-tree) "TODO kwd tree")
  1998. ((eq type 'occur-tree) "Occur tree")
  1999. ((functionp type) (if (symbolp type)
  2000. (symbol-name type)
  2001. "Lambda expression"))
  2002. (t "???"))))
  2003. (if org-agenda-menu-show-matcher
  2004. (setq line
  2005. (concat line ": "
  2006. (cond
  2007. ((stringp match)
  2008. (setq match (copy-sequence match))
  2009. (org-add-props match nil 'face 'org-warning))
  2010. (match
  2011. (format "set of %d commands" (length match)))
  2012. (t ""))))
  2013. (if (org-string-nw-p match)
  2014. (add-text-properties
  2015. 0 (length line) (list 'help-echo
  2016. (concat "Matcher: "match)) line)))
  2017. (push line lines)))
  2018. (setq lines (nreverse lines))
  2019. (when prefixes
  2020. (mapc (lambda (x)
  2021. (push
  2022. (format "%s %s"
  2023. (org-add-props (char-to-string x)
  2024. nil 'face 'bold)
  2025. (or (cdr (assoc (concat selstring
  2026. (char-to-string x))
  2027. prefix-descriptions))
  2028. "Prefix key"))
  2029. lines))
  2030. prefixes))
  2031. ;; Check if we should display in two columns
  2032. (if org-agenda-menu-two-column
  2033. (progn
  2034. (setq n (length lines)
  2035. n1 (+ (/ n 2) (mod n 2))
  2036. right (nthcdr n1 lines)
  2037. left (copy-sequence lines))
  2038. (setcdr (nthcdr (1- n1) left) nil))
  2039. (setq left lines right nil))
  2040. (while left
  2041. (insert "\n" (pop left))
  2042. (when right
  2043. (if (< (current-column) 40)
  2044. (move-to-column 40 t)
  2045. (insert " "))
  2046. (insert (pop right))))
  2047. ;; Make the window the right size
  2048. (goto-char (point-min))
  2049. (if second-time
  2050. (if (not (pos-visible-in-window-p (point-max)))
  2051. (org-fit-window-to-buffer))
  2052. (setq second-time t)
  2053. (org-fit-window-to-buffer))
  2054. ;; Ask for selection
  2055. (message "Press key for agenda command%s:"
  2056. (if (or restrict-ok org-agenda-overriding-restriction)
  2057. (if org-agenda-overriding-restriction
  2058. " (restriction lock active)"
  2059. (if restriction
  2060. (format " (restricted to %s)" restriction)
  2061. " (unrestricted)"))
  2062. ""))
  2063. (setq c (read-char-exclusive))
  2064. (message "")
  2065. (cond
  2066. ((assoc (char-to-string c) custom)
  2067. (setq selstring (concat selstring (char-to-string c)))
  2068. (throw 'exit (cons selstring restriction)))
  2069. ((memq c prefixes)
  2070. (setq selstring (concat selstring (char-to-string c))
  2071. prefixes nil
  2072. rmheader (or rmheader t)
  2073. custom (delq nil (mapcar
  2074. (lambda (x)
  2075. (if (or (= (length (car x)) 1)
  2076. (/= (string-to-char (car x)) c))
  2077. nil
  2078. (cons (substring (car x) 1) (cdr x))))
  2079. custom))))
  2080. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2081. (message "Restriction is only possible in Org-mode buffers")
  2082. (ding) (sit-for 1))
  2083. ((eq c ?1)
  2084. (org-agenda-remove-restriction-lock 'noupdate)
  2085. (setq restriction 'buffer))
  2086. ((eq c ?0)
  2087. (org-agenda-remove-restriction-lock 'noupdate)
  2088. (setq restriction (if region-p 'region 'subtree)))
  2089. ((eq c ?<)
  2090. (org-agenda-remove-restriction-lock 'noupdate)
  2091. (setq restriction
  2092. (cond
  2093. ((eq restriction 'buffer)
  2094. (if region-p 'region 'subtree))
  2095. ((memq restriction '(subtree region))
  2096. nil)
  2097. (t 'buffer))))
  2098. ((eq c ?>)
  2099. (org-agenda-remove-restriction-lock 'noupdate)
  2100. (setq restriction nil))
  2101. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2102. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2103. ((and (> (length selstring) 0) (eq c ?\d))
  2104. (delete-window)
  2105. (org-agenda-get-restriction-and-command prefix-descriptions))
  2106. ((equal c ?q) (error "Abort"))
  2107. (t (error "Invalid key %c" c))))))))
  2108. (defun org-run-agenda-series (name series)
  2109. (org-let (nth 1 series) '(org-prepare-agenda name))
  2110. (let* ((org-agenda-multi t)
  2111. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2112. (cmds (car series))
  2113. (gprops (nth 1 series))
  2114. match ;; The byte compiler incorrectly complains about this. Keep it!
  2115. cmd type lprops)
  2116. (while (setq cmd (pop cmds))
  2117. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2118. (cond
  2119. ((eq type 'agenda)
  2120. (org-let2 gprops lprops
  2121. '(call-interactively 'org-agenda-list)))
  2122. ((eq type 'alltodo)
  2123. (org-let2 gprops lprops
  2124. '(call-interactively 'org-todo-list)))
  2125. ((eq type 'search)
  2126. (org-let2 gprops lprops
  2127. '(org-search-view current-prefix-arg match nil)))
  2128. ((eq type 'stuck)
  2129. (org-let2 gprops lprops
  2130. '(call-interactively 'org-agenda-list-stuck-projects)))
  2131. ((eq type 'tags)
  2132. (org-let2 gprops lprops
  2133. '(org-tags-view current-prefix-arg match)))
  2134. ((eq type 'tags-todo)
  2135. (org-let2 gprops lprops
  2136. '(org-tags-view '(4) match)))
  2137. ((eq type 'todo)
  2138. (org-let2 gprops lprops
  2139. '(org-todo-list match)))
  2140. ((fboundp type)
  2141. (org-let2 gprops lprops
  2142. '(funcall type match)))
  2143. (t (error "Invalid type in command series"))))
  2144. (widen)
  2145. (setq org-agenda-redo-command redo)
  2146. (goto-char (point-min)))
  2147. (org-fit-agenda-window)
  2148. (org-let (nth 1 series) '(org-finalize-agenda)))
  2149. ;;;###autoload
  2150. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2151. "Run an agenda command in batch mode and send the result to STDOUT.
  2152. If CMD-KEY is a string of length 1, it is used as a key in
  2153. `org-agenda-custom-commands' and triggers this command. If it is a
  2154. longer string it is used as a tags/todo match string.
  2155. Parameters are alternating variable names and values that will be bound
  2156. before running the agenda command."
  2157. (let (pars)
  2158. (while parameters
  2159. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2160. (if (> (length cmd-key) 2)
  2161. (eval (list 'let (nreverse pars)
  2162. (list 'org-tags-view nil cmd-key)))
  2163. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2164. (set-buffer org-agenda-buffer-name)
  2165. (princ (org-encode-for-stdout (buffer-string)))))
  2166. ;(defun org-encode-for-stdout (string)
  2167. ; (if (fboundp 'encode-coding-string)
  2168. ; (encode-coding-string string buffer-file-coding-system)
  2169. ; string))
  2170. (defun org-encode-for-stdout (string)
  2171. string)
  2172. (defvar org-agenda-info nil)
  2173. ;;;###autoload
  2174. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2175. "Run an agenda command in batch mode and send the result to STDOUT.
  2176. If CMD-KEY is a string of length 1, it is used as a key in
  2177. `org-agenda-custom-commands' and triggers this command. If it is a
  2178. longer string it is used as a tags/todo match string.
  2179. Parameters are alternating variable names and values that will be bound
  2180. before running the agenda command.
  2181. The output gives a line for each selected agenda item. Each
  2182. item is a list of comma-separated values, like this:
  2183. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2184. category The category of the item
  2185. head The headline, without TODO kwd, TAGS and PRIORITY
  2186. type The type of the agenda entry, can be
  2187. todo selected in TODO match
  2188. tagsmatch selected in tags match
  2189. diary imported from diary
  2190. deadline a deadline on given date
  2191. scheduled scheduled on given date
  2192. timestamp entry has timestamp on given date
  2193. closed entry was closed on given date
  2194. upcoming-deadline warning about deadline
  2195. past-scheduled forwarded scheduled item
  2196. block entry has date block including g. date
  2197. todo The todo keyword, if any
  2198. tags All tags including inherited ones, separated by colons
  2199. date The relevant date, like 2007-2-14
  2200. time The time, like 15:00-16:50
  2201. extra Sting with extra planning info
  2202. priority-l The priority letter if any was given
  2203. priority-n The computed numerical priority
  2204. agenda-day The day in the agenda where this is listed"
  2205. (let (pars)
  2206. (while parameters
  2207. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2208. (push (list 'org-agenda-remove-tags t) pars)
  2209. (if (> (length cmd-key) 2)
  2210. (eval (list 'let (nreverse pars)
  2211. (list 'org-tags-view nil cmd-key)))
  2212. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2213. (set-buffer org-agenda-buffer-name)
  2214. (let* ((lines (org-split-string (buffer-string) "\n"))
  2215. line)
  2216. (while (setq line (pop lines))
  2217. (catch 'next
  2218. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2219. (setq org-agenda-info
  2220. (org-fix-agenda-info (text-properties-at 0 line)))
  2221. (princ
  2222. (org-encode-for-stdout
  2223. (mapconcat 'org-agenda-export-csv-mapper
  2224. '(org-category txt type todo tags date time extra
  2225. priority-letter priority agenda-day)
  2226. ",")))
  2227. (princ "\n"))))))
  2228. (defun org-fix-agenda-info (props)
  2229. "Make sure all properties on an agenda item have a canonical form.
  2230. This ensures the export commands can easily use it."
  2231. (let (tmp re)
  2232. (when (setq tmp (plist-get props 'tags))
  2233. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2234. (when (setq tmp (plist-get props 'date))
  2235. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2236. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2237. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2238. (setq tmp (calendar-date-string tmp)))
  2239. (setq props (plist-put props 'date tmp)))
  2240. (when (setq tmp (plist-get props 'day))
  2241. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2242. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2243. (setq tmp (calendar-date-string tmp)))
  2244. (setq props (plist-put props 'day tmp))
  2245. (setq props (plist-put props 'agenda-day tmp)))
  2246. (when (setq tmp (plist-get props 'txt))
  2247. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2248. (plist-put props 'priority-letter (match-string 1 tmp))
  2249. (setq tmp (replace-match "" t t tmp)))
  2250. (when (and (setq re (plist-get props 'org-todo-regexp))
  2251. (setq re (concat "\\`\\.*" re " ?"))
  2252. (string-match re tmp))
  2253. (plist-put props 'todo (match-string 1 tmp))
  2254. (setq tmp (replace-match "" t t tmp)))
  2255. (plist-put props 'txt tmp)))
  2256. props)
  2257. (defun org-agenda-export-csv-mapper (prop)
  2258. (let ((res (plist-get org-agenda-info prop)))
  2259. (setq res
  2260. (cond
  2261. ((not res) "")
  2262. ((stringp res) res)
  2263. (t (prin1-to-string res))))
  2264. (while (string-match "," res)
  2265. (setq res (replace-match ";" t t res)))
  2266. (org-trim res)))
  2267. ;;;###autoload
  2268. (defun org-store-agenda-views (&rest parameters)
  2269. (interactive)
  2270. (eval (list 'org-batch-store-agenda-views)))
  2271. ;; FIXME, why is this a macro?????
  2272. ;;;###autoload
  2273. (defmacro org-batch-store-agenda-views (&rest parameters)
  2274. "Run all custom agenda commands that have a file argument."
  2275. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2276. (pop-up-frames nil)
  2277. (dir default-directory)
  2278. pars cmd thiscmdkey files opts cmd-or-set)
  2279. (while parameters
  2280. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2281. (setq pars (reverse pars))
  2282. (save-window-excursion
  2283. (while cmds
  2284. (setq cmd (pop cmds)
  2285. thiscmdkey (car cmd)
  2286. cmd-or-set (nth 2 cmd)
  2287. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2288. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2289. (if (stringp files) (setq files (list files)))
  2290. (when files
  2291. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2292. (list 'org-agenda nil thiscmdkey)))
  2293. (set-buffer org-agenda-buffer-name)
  2294. (while files
  2295. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2296. (list 'org-write-agenda
  2297. (expand-file-name (pop files) dir) nil t))))
  2298. (and (get-buffer org-agenda-buffer-name)
  2299. (kill-buffer org-agenda-buffer-name)))))))
  2300. (defun org-agenda-mark-header-line (pos)
  2301. "Mark the line at POS as an agenda structure header."
  2302. (save-excursion
  2303. (goto-char pos)
  2304. (put-text-property (point-at-bol) (point-at-eol)
  2305. 'org-agenda-structural-header t)
  2306. (when org-agenda-title-append
  2307. (put-text-property (point-at-bol) (point-at-eol)
  2308. 'org-agenda-title-append org-agenda-title-append))))
  2309. (defvar org-mobile-creating-agendas)
  2310. (defun org-write-agenda (file &optional open nosettings)
  2311. "Write the current buffer (an agenda view) as a file.
  2312. Depending on the extension of the file name, plain text (.txt),
  2313. HTML (.html or .htm) or Postscript (.ps) is produced.
  2314. If the extension is .ics, run icalendar export over all files used
  2315. to construct the agenda and limit the export to entries listed in the
  2316. agenda now.
  2317. With prefix argument OPEN, open the new file immediately.
  2318. If NOSETTINGS is given, do not scope the settings of
  2319. `org-agenda-exporter-settings' into the export commands. This is used when
  2320. the settings have already been scoped and we do not wish to overrule other,
  2321. higher priority settings."
  2322. (interactive "FWrite agenda to file: \nP")
  2323. (if (not (file-writable-p file))
  2324. (error "Cannot write agenda to file %s" file))
  2325. (org-let (if nosettings nil org-agenda-exporter-settings)
  2326. '(save-excursion
  2327. (save-window-excursion
  2328. (org-agenda-mark-filtered-text)
  2329. (let ((bs (copy-sequence (buffer-string))) beg)
  2330. (org-agenda-unmark-filtered-text)
  2331. (with-temp-buffer
  2332. (rename-buffer "Agenda View" t)
  2333. (set-buffer-modified-p nil)
  2334. (insert bs)
  2335. (org-agenda-remove-marked-text 'org-filtered)
  2336. (while (setq beg (text-property-any (point-min) (point-max)
  2337. 'org-filtered t))
  2338. (delete-region
  2339. beg (or (next-single-property-change beg 'org-filtered)
  2340. (point-max))))
  2341. (run-hooks 'org-agenda-before-write-hook)
  2342. (cond
  2343. ((org-bound-and-true-p org-mobile-creating-agendas)
  2344. (org-mobile-write-agenda-for-mobile file))
  2345. ((string-match "\\.html?\\'" file)
  2346. (require 'htmlize)
  2347. (set-buffer (htmlize-buffer (current-buffer)))
  2348. (when (and org-agenda-export-html-style
  2349. (string-match "<style>" org-agenda-export-html-style))
  2350. ;; replace <style> section with org-agenda-export-html-style
  2351. (goto-char (point-min))
  2352. (kill-region (- (search-forward "<style") 6)
  2353. (search-forward "</style>"))
  2354. (insert org-agenda-export-html-style))
  2355. (write-file file)
  2356. (kill-buffer (current-buffer))
  2357. (message "HTML written to %s" file))
  2358. ((string-match "\\.ps\\'" file)
  2359. (require 'ps-print)
  2360. (ps-print-buffer-with-faces file)
  2361. (message "Postscript written to %s" file))
  2362. ((string-match "\\.pdf\\'" file)
  2363. (require 'ps-print)
  2364. (ps-print-buffer-with-faces
  2365. (concat (file-name-sans-extension file) ".ps"))
  2366. (call-process "ps2pdf" nil nil nil
  2367. (expand-file-name
  2368. (concat (file-name-sans-extension file) ".ps"))
  2369. (expand-file-name file))
  2370. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2371. (message "PDF written to %s" file))
  2372. ((string-match "\\.ics\\'" file)
  2373. (require 'org-icalendar)
  2374. (let ((org-agenda-marker-table
  2375. (org-create-marker-find-array
  2376. (org-agenda-collect-markers)))
  2377. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2378. (org-combined-agenda-icalendar-file file))
  2379. (apply 'org-export-icalendar 'combine
  2380. (org-agenda-files nil 'ifmode))))
  2381. (t
  2382. (let ((bs (buffer-string)))
  2383. (find-file file)
  2384. (erase-buffer)
  2385. (insert bs)
  2386. (save-buffer 0)
  2387. (kill-buffer (current-buffer))
  2388. (message "Plain text written to %s" file))))))))
  2389. (set-buffer org-agenda-buffer-name))
  2390. (when open (org-open-file file)))
  2391. (defvar org-agenda-filter-overlays nil)
  2392. (defun org-agenda-mark-filtered-text ()
  2393. "Mark all text hidden by filtering with a text property."
  2394. (let ((inhibit-read-only t))
  2395. (mapc
  2396. (lambda (o)
  2397. (when (equal (overlay-buffer o) (current-buffer))
  2398. (put-text-property
  2399. (overlay-start o) (overlay-end o)
  2400. 'org-filtered t)))
  2401. org-agenda-filter-overlays)))
  2402. (defun org-agenda-unmark-filtered-text ()
  2403. "Remove the filtering text property."
  2404. (let ((inhibit-read-only t))
  2405. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2406. (defun org-agenda-remove-marked-text (property &optional value)
  2407. "Delete all text marked with VALUE of PROPERTY.
  2408. VALUE defaults to t."
  2409. (let (beg)
  2410. (setq value (or value t))
  2411. (while (setq beg (text-property-any (point-min) (point-max)
  2412. property value))
  2413. (delete-region
  2414. beg (or (next-single-property-change beg 'org-filtered)
  2415. (point-max))))))
  2416. (defun org-agenda-add-entry-text ()
  2417. "Add entry text to agenda lines.
  2418. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2419. entry text following headings shown in the agenda.
  2420. Drawers will be excluded, also the line with scheduling/deadline info."
  2421. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2422. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2423. (let (m txt)
  2424. (goto-char (point-min))
  2425. (while (not (eobp))
  2426. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2427. (beginning-of-line 2)
  2428. (setq txt (org-agenda-get-some-entry-text
  2429. m org-agenda-add-entry-text-maxlines " > "))
  2430. (end-of-line 1)
  2431. (if (string-match "\\S-" txt)
  2432. (insert "\n" txt)
  2433. (or (eobp) (forward-char 1))))))))
  2434. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2435. &rest keep)
  2436. "Extract entry text from MARKER, at most N-LINES lines.
  2437. This will ignore drawers etc, just get the text.
  2438. If INDENT is given, prefix every line with this string. If KEEP is
  2439. given, it is a list of symbols, defining stuff that should not be
  2440. removed from the entry content. Currently only `planning' is allowed here."
  2441. (let (txt drawer-re kwd-time-re ind)
  2442. (save-excursion
  2443. (with-current-buffer (marker-buffer marker)
  2444. (if (not (org-mode-p))
  2445. (setq txt "")
  2446. (save-excursion
  2447. (save-restriction
  2448. (widen)
  2449. (goto-char marker)
  2450. (end-of-line 1)
  2451. (setq txt (buffer-substring
  2452. (min (1+ (point)) (point-max))
  2453. (progn (outline-next-heading) (point)))
  2454. drawer-re org-drawer-regexp
  2455. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2456. ".*\n?"))
  2457. (with-temp-buffer
  2458. (insert txt)
  2459. (when org-agenda-add-entry-text-descriptive-links
  2460. (goto-char (point-min))
  2461. (while (org-activate-bracket-links (point-max))
  2462. (add-text-properties (match-beginning 0) (match-end 0)
  2463. '(face org-link))))
  2464. (goto-char (point-min))
  2465. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2466. (set-text-properties (match-beginning 0) (match-end 0)
  2467. nil))
  2468. (goto-char (point-min))
  2469. (while (re-search-forward drawer-re nil t)
  2470. (delete-region
  2471. (match-beginning 0)
  2472. (progn (re-search-forward
  2473. "^[ \t]*:END:.*\n?" nil 'move)
  2474. (point))))
  2475. (unless (member 'planning keep)
  2476. (goto-char (point-min))
  2477. (while (re-search-forward kwd-time-re nil t)
  2478. (replace-match "")))
  2479. (goto-char (point-min))
  2480. (when org-agenda-entry-text-exclude-regexps
  2481. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2482. (while (setq re (pop re-list))
  2483. (goto-char (point-min))
  2484. (while (re-search-forward re nil t)
  2485. (replace-match "")))))
  2486. (goto-char (point-max))
  2487. (skip-chars-backward " \t\n")
  2488. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2489. ;; find and remove min common indentation
  2490. (goto-char (point-min))
  2491. (untabify (point-min) (point-max))
  2492. (setq ind (org-get-indentation))
  2493. (while (not (eobp))
  2494. (unless (looking-at "[ \t]*$")
  2495. (setq ind (min ind (org-get-indentation))))
  2496. (beginning-of-line 2))
  2497. (goto-char (point-min))
  2498. (while (not (eobp))
  2499. (unless (looking-at "[ \t]*$")
  2500. (move-to-column ind)
  2501. (delete-region (point-at-bol) (point)))
  2502. (beginning-of-line 2))
  2503. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2504. (goto-char (point-min))
  2505. (when indent
  2506. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2507. (replace-match indent t t)))
  2508. (goto-char (point-min))
  2509. (while (looking-at "[ \t]*\n") (replace-match ""))
  2510. (goto-char (point-max))
  2511. (when (> (org-current-line)
  2512. n-lines)
  2513. (org-goto-line (1+ n-lines))
  2514. (backward-char 1))
  2515. (setq txt (buffer-substring (point-min) (point)))))))))
  2516. txt))
  2517. (defun org-agenda-collect-markers ()
  2518. "Collect the markers pointing to entries in the agenda buffer."
  2519. (let (m markers)
  2520. (save-excursion
  2521. (goto-char (point-min))
  2522. (while (not (eobp))
  2523. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2524. (org-get-at-bol 'org-marker)))
  2525. (push m markers))
  2526. (beginning-of-line 2)))
  2527. (nreverse markers)))
  2528. (defun org-create-marker-find-array (marker-list)
  2529. "Create a alist of files names with all marker positions in that file."
  2530. (let (f tbl m a p)
  2531. (while (setq m (pop marker-list))
  2532. (setq p (marker-position m)
  2533. f (buffer-file-name (or (buffer-base-buffer
  2534. (marker-buffer m))
  2535. (marker-buffer m))))
  2536. (if (setq a (assoc f tbl))
  2537. (push (marker-position m) (cdr a))
  2538. (push (list f p) tbl)))
  2539. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2540. tbl)))
  2541. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2542. (defun org-check-agenda-marker-table ()
  2543. "Check of the current entry is on the marker list."
  2544. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2545. a)
  2546. (and (setq a (assoc file org-agenda-marker-table))
  2547. (save-match-data
  2548. (save-excursion
  2549. (org-back-to-heading t)
  2550. (member (point) (cdr a)))))))
  2551. (defun org-check-for-org-mode ()
  2552. "Make sure current buffer is in org-mode. Error if not."
  2553. (or (org-mode-p)
  2554. (error "Cannot execute org-mode agenda command on buffer in %s"
  2555. major-mode)))
  2556. (defun org-fit-agenda-window ()
  2557. "Fit the window to the buffer size."
  2558. (and (memq org-agenda-window-setup '(reorganize-frame))
  2559. (fboundp 'fit-window-to-buffer)
  2560. (org-fit-window-to-buffer
  2561. nil
  2562. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2563. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2564. ;;; Agenda prepare and finalize
  2565. (defvar org-agenda-multi nil) ; dynamically scoped
  2566. (defvar org-agenda-buffer-name "*Org Agenda*")
  2567. (defvar org-pre-agenda-window-conf nil)
  2568. (defvar org-agenda-columns-active nil)
  2569. (defvar org-agenda-name nil)
  2570. (defvar org-agenda-filter nil)
  2571. (defvar org-agenda-filter-while-redo nil)
  2572. (defvar org-agenda-filter-preset nil
  2573. "A preset of the tags filter used for secondary agenda filtering.
  2574. This must be a list of strings, each string must be a single tag preceded
  2575. by \"+\" or \"-\".
  2576. This variable should not be set directly, but agenda custom commands can
  2577. bind it in the options section. The preset filter is a global property of
  2578. the entire agenda view. In a block agenda, it will not work reliably to
  2579. define a filter for one of the individual blocks. You need to set it in
  2580. the global options and expect it to be applied to the entire view.")
  2581. (defun org-prepare-agenda (&optional name)
  2582. (setq org-todo-keywords-for-agenda nil)
  2583. (setq org-done-keywords-for-agenda nil)
  2584. (setq org-drawers-for-agenda nil)
  2585. (unless org-agenda-persistent-filter
  2586. (setq org-agenda-filter nil))
  2587. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2588. (if org-agenda-multi
  2589. (progn
  2590. (setq buffer-read-only nil)
  2591. (goto-char (point-max))
  2592. (unless (or (bobp) org-agenda-compact-blocks)
  2593. (insert "\n"
  2594. (if (stringp org-agenda-block-separator)
  2595. org-agenda-block-separator
  2596. (make-string (window-width) org-agenda-block-separator))
  2597. "\n"))
  2598. (narrow-to-region (point) (point-max)))
  2599. (org-agenda-reset-markers)
  2600. (setq org-agenda-contributing-files nil)
  2601. (setq org-agenda-columns-active nil)
  2602. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2603. (setq org-todo-keywords-for-agenda
  2604. (org-uniquify org-todo-keywords-for-agenda))
  2605. (setq org-done-keywords-for-agenda
  2606. (org-uniquify org-done-keywords-for-agenda))
  2607. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2608. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2609. (awin (get-buffer-window abuf)))
  2610. (cond
  2611. ((equal (current-buffer) abuf) nil)
  2612. (awin (select-window awin))
  2613. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2614. ((equal org-agenda-window-setup 'current-window)
  2615. (switch-to-buffer abuf))
  2616. ((equal org-agenda-window-setup 'other-window)
  2617. (org-switch-to-buffer-other-window abuf))
  2618. ((equal org-agenda-window-setup 'other-frame)
  2619. (switch-to-buffer-other-frame abuf))
  2620. ((equal org-agenda-window-setup 'reorganize-frame)
  2621. (delete-other-windows)
  2622. (org-switch-to-buffer-other-window abuf)))
  2623. ;; additional test in case agenda is invoked from within agenda
  2624. ;; buffer via elisp link
  2625. (unless (equal (current-buffer) abuf)
  2626. (switch-to-buffer abuf)))
  2627. (setq buffer-read-only nil)
  2628. (let ((inhibit-read-only t)) (erase-buffer))
  2629. (org-agenda-mode)
  2630. (and name (not org-agenda-name)
  2631. (org-set-local 'org-agenda-name name)))
  2632. (setq buffer-read-only nil))
  2633. (defun org-finalize-agenda ()
  2634. "Finishing touch for the agenda buffer, called just before displaying it."
  2635. (unless org-agenda-multi
  2636. (save-excursion
  2637. (let ((inhibit-read-only t))
  2638. (goto-char (point-min))
  2639. (while (org-activate-bracket-links (point-max))
  2640. (add-text-properties (match-beginning 0) (match-end 0)
  2641. '(face org-link)))
  2642. (org-agenda-align-tags)
  2643. (unless org-agenda-with-colors
  2644. (remove-text-properties (point-min) (point-max) '(face nil))))
  2645. (if (and (boundp 'org-agenda-overriding-columns-format)
  2646. org-agenda-overriding-columns-format)
  2647. (org-set-local 'org-agenda-overriding-columns-format
  2648. org-agenda-overriding-columns-format))
  2649. (if (and (boundp 'org-agenda-view-columns-initially)
  2650. org-agenda-view-columns-initially)
  2651. (org-agenda-columns))
  2652. (when org-agenda-fontify-priorities
  2653. (org-agenda-fontify-priorities))
  2654. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2655. (org-agenda-dim-blocked-tasks))
  2656. (org-agenda-mark-clocking-task)
  2657. (when org-agenda-entry-text-mode
  2658. (org-agenda-entry-text-hide)
  2659. (org-agenda-entry-text-show))
  2660. (if (functionp 'org-habit-insert-consistency-graphs)
  2661. (org-habit-insert-consistency-graphs))
  2662. (run-hooks 'org-finalize-agenda-hook)
  2663. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2664. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2665. (org-agenda-filter-apply org-agenda-filter))
  2666. )))
  2667. (defun org-agenda-mark-clocking-task ()
  2668. "Mark the current clock entry in the agenda if it is present."
  2669. (mapc (lambda (o)
  2670. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2671. (delete-overlay o)))
  2672. (overlays-in (point-min) (point-max)))
  2673. (when (marker-buffer org-clock-hd-marker)
  2674. (save-excursion
  2675. (goto-char (point-min))
  2676. (let (s ov)
  2677. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2678. (goto-char s)
  2679. (when (equal (org-get-at-bol 'org-hd-marker)
  2680. org-clock-hd-marker)
  2681. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2682. (overlay-put ov 'type 'org-agenda-clocking)
  2683. (overlay-put ov 'face 'org-agenda-clocking)
  2684. (overlay-put ov 'help-echo
  2685. "The clock is running in this item")))))))
  2686. (defun org-agenda-fontify-priorities ()
  2687. "Make highest priority lines bold, and lowest italic."
  2688. (interactive)
  2689. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2690. (delete-overlay o)))
  2691. (overlays-in (point-min) (point-max)))
  2692. (save-excursion
  2693. (let ((inhibit-read-only t)
  2694. b e p ov h l)
  2695. (goto-char (point-min))
  2696. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2697. (setq h (or (get-char-property (point) 'org-highest-priority)
  2698. org-highest-priority)
  2699. l (or (get-char-property (point) 'org-lowest-priority)
  2700. org-lowest-priority)
  2701. p (string-to-char (match-string 1))
  2702. b (match-beginning 0)
  2703. e (if (eq org-agenda-fontify-priorities 'cookies)
  2704. (match-end 0)
  2705. (point-at-eol))
  2706. ov (make-overlay b e))
  2707. (overlay-put
  2708. ov 'face
  2709. (cond ((org-face-from-face-or-color
  2710. 'priority nil
  2711. (cdr (assoc p org-priority-faces))))
  2712. ((and (listp org-agenda-fontify-priorities)
  2713. (org-face-from-face-or-color
  2714. 'priority nil
  2715. (cdr (assoc p org-agenda-fontify-priorities)))))
  2716. ((equal p l) 'italic)
  2717. ((equal p h) 'bold)))
  2718. (overlay-put ov 'org-type 'org-priority)))))
  2719. (defun org-agenda-dim-blocked-tasks ()
  2720. "Dim currently blocked TODO's in the agenda display."
  2721. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2722. (delete-overlay o)))
  2723. (overlays-in (point-min) (point-max)))
  2724. (save-excursion
  2725. (let ((inhibit-read-only t)
  2726. (org-depend-tag-blocked nil)
  2727. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2728. org-blocked-by-checkboxes
  2729. invis1 b e p ov h l)
  2730. (goto-char (point-min))
  2731. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2732. (and pos (goto-char (1+ pos))))
  2733. (setq org-blocked-by-checkboxes nil invis1 invis)
  2734. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2735. (when (and marker
  2736. (not (with-current-buffer (marker-buffer marker)
  2737. (save-excursion
  2738. (goto-char marker)
  2739. (if (org-entry-get nil "NOBLOCKING")
  2740. t ;; Never block this entry
  2741. (run-hook-with-args-until-failure
  2742. 'org-blocker-hook
  2743. (list :type 'todo-state-change
  2744. :position marker
  2745. :from 'todo
  2746. :to 'done)))))))
  2747. (if org-blocked-by-checkboxes (setq invis1 nil))
  2748. (setq b (if invis1
  2749. (max (point-min) (1- (point-at-bol)))
  2750. (point-at-bol))
  2751. e (point-at-eol)
  2752. ov (make-overlay b e))
  2753. (if invis1
  2754. (overlay-put ov 'invisible t)
  2755. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2756. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2757. (defvar org-agenda-skip-function nil
  2758. "Function to be called at each match during agenda construction.
  2759. If this function returns nil, the current match should not be skipped.
  2760. Otherwise, the function must return a position from where the search
  2761. should be continued.
  2762. This may also be a Lisp form, it will be evaluated.
  2763. Never set this variable using `setq' or so, because then it will apply
  2764. to all future agenda commands. Instead, bind it with `let' to scope
  2765. it dynamically into the agenda-constructing command. A good way to set
  2766. it is through options in `org-agenda-custom-commands'.")
  2767. (defun org-agenda-skip ()
  2768. "Throw to `:skip' in places that should be skipped.
  2769. Also moves point to the end of the skipped region, so that search can
  2770. continue from there."
  2771. (let ((p (point-at-bol)) to fp)
  2772. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2773. (get-text-property p :org-archived)
  2774. (org-end-of-subtree t)
  2775. (throw :skip t))
  2776. (and org-agenda-skip-comment-trees
  2777. (get-text-property p :org-comment)
  2778. (org-end-of-subtree t)
  2779. (throw :skip t))
  2780. (if (equal (char-after p) ?#) (throw :skip t))
  2781. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2782. (consp org-agenda-skip-function))
  2783. (setq to (save-excursion
  2784. (save-match-data
  2785. (if fp
  2786. (funcall org-agenda-skip-function)
  2787. (eval org-agenda-skip-function))))))
  2788. (goto-char to)
  2789. (throw :skip t))))
  2790. (defvar org-agenda-markers nil
  2791. "List of all currently active markers created by `org-agenda'.")
  2792. (defvar org-agenda-last-marker-time (org-float-time)
  2793. "Creation time of the last agenda marker.")
  2794. (defun org-agenda-new-marker (&optional pos)
  2795. "Return a new agenda marker.
  2796. Org-mode keeps a list of these markers and resets them when they are
  2797. no longer in use."
  2798. (let ((m (copy-marker (or pos (point)))))
  2799. (setq org-agenda-last-marker-time (org-float-time))
  2800. (push m org-agenda-markers)
  2801. m))
  2802. (defun org-agenda-reset-markers ()
  2803. "Reset markers created by `org-agenda'."
  2804. (while org-agenda-markers
  2805. (move-marker (pop org-agenda-markers) nil)))
  2806. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2807. "Save relative positions of markers in region."
  2808. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2809. org-agenda-markers))
  2810. ;;; Entry text mode
  2811. (defun org-agenda-entry-text-show-here ()
  2812. "Add some text from the entry as context to the current line."
  2813. (let (m txt o)
  2814. (setq m (org-get-at-bol 'org-hd-marker))
  2815. (unless (marker-buffer m)
  2816. (error "No marker points to an entry here"))
  2817. (setq txt (concat "\n" (org-no-properties
  2818. (org-agenda-get-some-entry-text
  2819. m org-agenda-entry-text-maxlines " > "))))
  2820. (when (string-match "\\S-" txt)
  2821. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2822. (overlay-put o 'evaporate t)
  2823. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2824. (overlay-put o 'after-string txt))))
  2825. (defun org-agenda-entry-text-show ()
  2826. "Add entry context for all agenda lines."
  2827. (interactive)
  2828. (save-excursion
  2829. (goto-char (point-max))
  2830. (beginning-of-line 1)
  2831. (while (not (bobp))
  2832. (when (org-get-at-bol 'org-hd-marker)
  2833. (org-agenda-entry-text-show-here))
  2834. (beginning-of-line 0))))
  2835. (defun org-agenda-entry-text-hide ()
  2836. "Remove any shown entry context."
  2837. (delq nil
  2838. (mapcar (lambda (o)
  2839. (if (eq (overlay-get o 'org-overlay-type)
  2840. 'agenda-entry-content)
  2841. (progn (delete-overlay o) t)))
  2842. (overlays-in (point-min) (point-max)))))
  2843. ;;; Agenda timeline
  2844. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2845. (defun org-timeline (&optional include-all)
  2846. "Show a time-sorted view of the entries in the current org file.
  2847. Only entries with a time stamp of today or later will be listed. With
  2848. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2849. under the current date.
  2850. If the buffer contains an active region, only check the region for
  2851. dates."
  2852. (interactive "P")
  2853. (org-compile-prefix-format 'timeline)
  2854. (org-set-sorting-strategy 'timeline)
  2855. (let* ((dopast t)
  2856. (dotodo include-all)
  2857. (doclosed org-agenda-show-log)
  2858. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2859. (current-buffer))))
  2860. (date (calendar-current-date))
  2861. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2862. (end (if (org-region-active-p) (region-end) (point-max)))
  2863. (day-numbers (org-get-all-dates beg end 'no-ranges
  2864. t doclosed ; always include today
  2865. org-timeline-show-empty-dates))
  2866. (org-deadline-warning-days 0)
  2867. (org-agenda-only-exact-dates t)
  2868. (today (time-to-days (current-time)))
  2869. (past t)
  2870. args
  2871. s e rtn d emptyp wd)
  2872. (setq org-agenda-redo-command
  2873. (list 'progn
  2874. (list 'org-switch-to-buffer-other-window (current-buffer))
  2875. (list 'org-timeline (list 'quote include-all))))
  2876. (if (not dopast)
  2877. ;; Remove past dates from the list of dates.
  2878. (setq day-numbers (delq nil (mapcar (lambda(x)
  2879. (if (>= x today) x nil))
  2880. day-numbers))))
  2881. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2882. (if doclosed (push :closed args))
  2883. (push :timestamp args)
  2884. (push :deadline args)
  2885. (push :scheduled args)
  2886. (push :sexp args)
  2887. (if dotodo (push :todo args))
  2888. (insert "Timeline of file " entry "\n")
  2889. (add-text-properties (point-min) (point)
  2890. (list 'face 'org-agenda-structure))
  2891. (org-agenda-mark-header-line (point-min))
  2892. (while (setq d (pop day-numbers))
  2893. (if (and (listp d) (eq (car d) :omitted))
  2894. (progn
  2895. (setq s (point))
  2896. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2897. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2898. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2899. (if (and (>= d today)
  2900. dopast
  2901. past)
  2902. (progn
  2903. (setq past nil)
  2904. (insert (make-string 79 ?-) "\n")))
  2905. (setq date (calendar-gregorian-from-absolute d)
  2906. wd (calendar-day-of-week date))
  2907. (setq s (point))
  2908. (setq rtn (and (not emptyp)
  2909. (apply 'org-agenda-get-day-entries entry
  2910. date args)))
  2911. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2912. (progn
  2913. (insert
  2914. (if (stringp org-agenda-format-date)
  2915. (format-time-string org-agenda-format-date
  2916. (org-time-from-absolute date))
  2917. (funcall org-agenda-format-date date))
  2918. "\n")
  2919. (put-text-property s (1- (point)) 'face
  2920. (if (member wd org-agenda-weekend-days)
  2921. 'org-agenda-date-weekend
  2922. 'org-agenda-date))
  2923. (put-text-property s (1- (point)) 'org-date-line t)
  2924. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2925. (if (equal d today)
  2926. (put-text-property s (1- (point)) 'org-today t))
  2927. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2928. (put-text-property s (1- (point)) 'day d)))))
  2929. (goto-char (point-min))
  2930. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2931. (point-min)))
  2932. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2933. (org-finalize-agenda)
  2934. (setq buffer-read-only t)))
  2935. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2936. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2937. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2938. not every single day in the range. If FORCE-TODAY is non-nil, make
  2939. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2940. inactive time stamps (those in square brackets) are included.
  2941. When EMPTY is non-nil, also include days without any entries."
  2942. (let ((re (concat
  2943. (if pre-re pre-re "")
  2944. (if inactive org-ts-regexp-both org-ts-regexp)))
  2945. dates dates1 date day day1 day2 ts1 ts2)
  2946. (if force-today
  2947. (setq dates (list (time-to-days (current-time)))))
  2948. (save-excursion
  2949. (goto-char beg)
  2950. (while (re-search-forward re end t)
  2951. (setq day (time-to-days (org-time-string-to-time
  2952. (substring (match-string 1) 0 10))))
  2953. (or (memq day dates) (push day dates)))
  2954. (unless no-ranges
  2955. (goto-char beg)
  2956. (while (re-search-forward org-tr-regexp end t)
  2957. (setq ts1 (substring (match-string 1) 0 10)
  2958. ts2 (substring (match-string 2) 0 10)
  2959. day1 (time-to-days (org-time-string-to-time ts1))
  2960. day2 (time-to-days (org-time-string-to-time ts2)))
  2961. (while (< (setq day1 (1+ day1)) day2)
  2962. (or (memq day1 dates) (push day1 dates)))))
  2963. (setq dates (sort dates '<))
  2964. (when empty
  2965. (while (setq day (pop dates))
  2966. (setq day2 (car dates))
  2967. (push day dates1)
  2968. (when (and day2 empty)
  2969. (if (or (eq empty t)
  2970. (and (numberp empty) (<= (- day2 day) empty)))
  2971. (while (< (setq day (1+ day)) day2)
  2972. (push (list day) dates1))
  2973. (push (cons :omitted (- day2 day)) dates1))))
  2974. (setq dates (nreverse dates1)))
  2975. dates)))
  2976. ;;; Agenda Daily/Weekly
  2977. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2978. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2979. "Custom commands can set this variable in the options section.")
  2980. (defvar org-agenda-last-arguments nil
  2981. "The arguments of the previous call to `org-agenda'.")
  2982. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2983. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2984. (defvar org-include-all-loc nil) ; local variable
  2985. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2986. "List of types searched for when creating the daily/weekly agenda.
  2987. This variable is a list of symbols that controls the types of
  2988. items that appear in the daily/weekly agenda. Allowed symbols in this
  2989. list are are
  2990. :timestamp List items containing a date stamp or date range matching
  2991. the selected date. This includes sexp entries in
  2992. angular brackets.
  2993. :sexp List entries resulting from plain diary-like sexps.
  2994. :deadline List deadline due on that date. When the date is today,
  2995. also list any deadlines past due, or due within
  2996. `org-deadline-warning-days'. `:deadline' must appear before
  2997. `:scheduled' if the setting of
  2998. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2999. any effect.
  3000. :scheduled List all items which are scheduled for the given date.
  3001. The diary for *today* also contains items which were
  3002. scheduled earlier and are not yet marked DONE.
  3003. By default, all four types are turned on.
  3004. Never set this variable globally using `setq', because then it
  3005. will apply to all future agenda commands. Instead, bind it with
  3006. `let' to scope it dynamically into the the agenda-constructing
  3007. command. A good way to set it is through options in
  3008. `org-agenda-custom-commands'. For a more flexible (though
  3009. somewhat less efficient) way of determining what is included in
  3010. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3011. ;;;###autoload
  3012. (defun org-agenda-list (&optional include-all start-day ndays)
  3013. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3014. The view will be for the current day or week, but from the overview buffer
  3015. you will be able to go to other days/weeks.
  3016. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3017. all unfinished TODO items will also be shown, before the agenda.
  3018. This feature is considered obsolete, please use the TODO list or a block
  3019. agenda instead.
  3020. With a numeric prefix argument in an interactive call, the agenda will
  3021. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  3022. the number of days. NDAYS defaults to `org-agenda-ndays'.
  3023. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3024. given in `org-agenda-start-on-weekday'."
  3025. (interactive "P")
  3026. (if (and (integerp include-all) (> include-all 0))
  3027. (setq ndays include-all include-all nil))
  3028. (setq ndays (or ndays org-agenda-ndays)
  3029. start-day (or start-day org-agenda-start-day))
  3030. (if org-agenda-overriding-arguments
  3031. (setq include-all (car org-agenda-overriding-arguments)
  3032. start-day (nth 1 org-agenda-overriding-arguments)
  3033. ndays (nth 2 org-agenda-overriding-arguments)))
  3034. (if (stringp start-day)
  3035. ;; Convert to an absolute day number
  3036. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3037. (setq org-agenda-last-arguments (list include-all start-day ndays))
  3038. (org-compile-prefix-format 'agenda)
  3039. (org-set-sorting-strategy 'agenda)
  3040. (let* ((org-agenda-start-on-weekday
  3041. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  3042. org-agenda-start-on-weekday nil))
  3043. (thefiles (org-agenda-files nil 'ifmode))
  3044. (files thefiles)
  3045. (today (time-to-days
  3046. (time-subtract (current-time)
  3047. (list 0 (* 3600 org-extend-today-until) 0))))
  3048. (sd (or start-day today))
  3049. (start (if (or (null org-agenda-start-on-weekday)
  3050. (< org-agenda-ndays 7))
  3051. sd
  3052. (let* ((nt (calendar-day-of-week
  3053. (calendar-gregorian-from-absolute sd)))
  3054. (n1 org-agenda-start-on-weekday)
  3055. (d (- nt n1)))
  3056. (- sd (+ (if (< d 0) 7 0) d)))))
  3057. (day-numbers (list start))
  3058. (day-cnt 0)
  3059. (inhibit-redisplay (not debug-on-error))
  3060. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  3061. clocktable-start clocktable-end filter)
  3062. (setq org-agenda-redo-command
  3063. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3064. ;; Make the list of days
  3065. (setq ndays (or ndays org-agenda-ndays)
  3066. nd ndays)
  3067. (while (> ndays 1)
  3068. (push (1+ (car day-numbers)) day-numbers)
  3069. (setq ndays (1- ndays)))
  3070. (setq day-numbers (nreverse day-numbers))
  3071. (setq clocktable-start (car day-numbers)
  3072. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3073. (org-prepare-agenda "Day/Week")
  3074. (org-set-local 'org-starting-day (car day-numbers))
  3075. (org-set-local 'org-include-all-loc include-all)
  3076. (org-set-local 'org-agenda-span
  3077. (org-agenda-ndays-to-span nd))
  3078. (when (and (or include-all org-agenda-include-all-todo)
  3079. (member today day-numbers))
  3080. (setq files thefiles
  3081. rtnall nil)
  3082. (while (setq file (pop files))
  3083. (catch 'nextfile
  3084. (org-check-agenda-file file)
  3085. (setq date (calendar-gregorian-from-absolute today)
  3086. rtn (org-agenda-get-day-entries
  3087. file date :todo))
  3088. (setq rtnall (append rtnall rtn))))
  3089. (when rtnall
  3090. (insert "All currently open TODO items:\n")
  3091. (add-text-properties (point-min) (1- (point))
  3092. (list 'face 'org-agenda-structure
  3093. 'short-heading "All TODO items"))
  3094. (org-agenda-mark-header-line (point-min))
  3095. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3096. (unless org-agenda-compact-blocks
  3097. (let* ((d1 (car day-numbers))
  3098. (d2 (org-last day-numbers))
  3099. (w1 (org-days-to-iso-week d1))
  3100. (w2 (org-days-to-iso-week d2)))
  3101. (setq s (point))
  3102. (if org-agenda-overriding-header
  3103. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3104. nil 'face 'org-agenda-structure) "\n")
  3105. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3106. "-agenda"
  3107. (if (< (- d2 d1) 350)
  3108. (if (= w1 w2)
  3109. (format " (W%02d)" w1)
  3110. (format " (W%02d-W%02d)" w1 w2))
  3111. "")
  3112. ":\n")))
  3113. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3114. 'org-date-line t))
  3115. (org-agenda-mark-header-line s))
  3116. (while (setq d (pop day-numbers))
  3117. (setq date (calendar-gregorian-from-absolute d)
  3118. wd (calendar-day-of-week date)
  3119. s (point))
  3120. (if (or (setq todayp (= d today))
  3121. (and (not start-pos) (= d sd)))
  3122. (setq start-pos (point))
  3123. (if (and start-pos (not end-pos))
  3124. (setq end-pos (point))))
  3125. (setq files thefiles
  3126. rtnall nil)
  3127. (while (setq file (pop files))
  3128. (catch 'nextfile
  3129. (org-check-agenda-file file)
  3130. (let ((org-agenda-entry-types org-agenda-entry-types))
  3131. (unless org-agenda-include-deadlines
  3132. (setq org-agenda-entry-types
  3133. (delq :deadline org-agenda-entry-types)))
  3134. (cond
  3135. ((eq org-agenda-show-log 'only)
  3136. (setq rtn (org-agenda-get-day-entries
  3137. file date :closed)))
  3138. (org-agenda-show-log
  3139. (setq rtn (apply 'org-agenda-get-day-entries
  3140. file date
  3141. (append '(:closed) org-agenda-entry-types))))
  3142. (t
  3143. (setq rtn (apply 'org-agenda-get-day-entries
  3144. file date
  3145. org-agenda-entry-types)))))
  3146. (setq rtnall (append rtnall rtn))))
  3147. (if org-agenda-include-diary
  3148. (let ((org-agenda-search-headline-for-time t))
  3149. (require 'diary-lib)
  3150. (setq rtn (org-get-entries-from-diary date))
  3151. (setq rtnall (append rtnall rtn))))
  3152. (if (or rtnall org-agenda-show-all-dates)
  3153. (progn
  3154. (setq day-cnt (1+ day-cnt))
  3155. (insert
  3156. (if (stringp org-agenda-format-date)
  3157. (format-time-string org-agenda-format-date
  3158. (org-time-from-absolute date))
  3159. (funcall org-agenda-format-date date))
  3160. "\n")
  3161. (put-text-property s (1- (point)) 'face
  3162. (if (member wd org-agenda-weekend-days)
  3163. 'org-agenda-date-weekend
  3164. 'org-agenda-date))
  3165. (put-text-property s (1- (point)) 'org-date-line t)
  3166. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3167. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3168. (when todayp
  3169. (put-text-property s (1- (point)) 'org-today t)
  3170. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3171. (if rtnall (insert
  3172. (org-finalize-agenda-entries
  3173. (org-agenda-add-time-grid-maybe
  3174. rtnall nd todayp))
  3175. "\n"))
  3176. (put-text-property s (1- (point)) 'day d)
  3177. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3178. (when (and org-agenda-clockreport-mode clocktable-start)
  3179. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3180. ;; the above line is to ensure the restricted range!
  3181. (p org-agenda-clockreport-parameter-plist)
  3182. tbl)
  3183. (setq p (org-plist-delete p :block))
  3184. (setq p (plist-put p :tstart clocktable-start))
  3185. (setq p (plist-put p :tend clocktable-end))
  3186. (setq p (plist-put p :scope 'agenda))
  3187. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3188. (setq filter (or org-agenda-filter-while-redo
  3189. (get 'org-agenda-filter :preset-filter))))
  3190. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3191. (if (string-match "[<>=]" x)
  3192. ""
  3193. x))
  3194. filter ""))))
  3195. (message "%s" (plist-get p :tags)) (sit-for 2)
  3196. (setq tbl (apply 'org-get-clocktable p))
  3197. (insert tbl)))
  3198. (goto-char (point-min))
  3199. (or org-agenda-multi (org-fit-agenda-window))
  3200. (unless (and (pos-visible-in-window-p (point-min))
  3201. (pos-visible-in-window-p (point-max)))
  3202. (goto-char (1- (point-max)))
  3203. (recenter -1)
  3204. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3205. (progn
  3206. (goto-char (or start-pos 1))
  3207. (recenter 1))))
  3208. (goto-char (or start-pos 1))
  3209. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3210. (org-finalize-agenda)
  3211. (setq buffer-read-only t)
  3212. (message "")))
  3213. (defun org-agenda-ndays-to-span (n)
  3214. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3215. ;;; Agenda word search
  3216. (defvar org-agenda-search-history nil)
  3217. (defvar org-todo-only nil)
  3218. (defvar org-search-syntax-table nil
  3219. "Special syntax table for org-mode search.
  3220. In this table, we have single quotes not as word constituents, to
  3221. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3222. (defun org-search-syntax-table ()
  3223. (unless org-search-syntax-table
  3224. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3225. (modify-syntax-entry ?' "." org-search-syntax-table)
  3226. (modify-syntax-entry ?` "." org-search-syntax-table))
  3227. org-search-syntax-table)
  3228. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3229. ;;;###autoload
  3230. (defun org-search-view (&optional todo-only string edit-at)
  3231. "Show all entries that contain a phrase or words or regular expressions.
  3232. With optional prefix argument TODO-ONLY, only consider entries that are
  3233. TODO entries. The argument STRING can be used to pass a default search
  3234. string into this function. If EDIT-AT is non-nil, it means that the
  3235. user should get a chance to edit this string, with cursor at position
  3236. EDIT-AT.
  3237. The search string can be viewed either as a phrase that should be found as
  3238. is, or it can be broken into a number of snippets, each of which must match
  3239. in a Boolean way to select an entry. The default depends on the variable
  3240. `org-agenda-search-view-always-boolean'.
  3241. Even if this is turned off (the default) you can always switch to
  3242. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3243. The default is a direct search of the whole phrase, where each space in
  3244. the search string can expand to an arbitrary amount of whitespace,
  3245. including newlines.
  3246. If using a Boolean search, the search string is split on whitespace and
  3247. each snippet is searched separately, with logical AND to select an entry.
  3248. Words prefixed with a minus must *not* occur in the entry. Words without
  3249. a prefix or prefixed with a plus must occur in the entry. Matching is
  3250. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3251. match whole words, not parts of a word) if
  3252. `org-agenda-search-view-force-full-words' is set (default is nil).
  3253. Boolean search snippets enclosed by curly braces are interpreted as
  3254. regular expressions that must or (when preceded with \"-\") must not
  3255. match in the entry. Snippets enclosed into double quotes will be taken
  3256. as a whole, to include whitespace.
  3257. - If the search string starts with an asterisk, search only in headlines.
  3258. - If (possibly after the leading star) the search string starts with an
  3259. exclamation mark, this also means to look at TODO entries only, an effect
  3260. that can also be achieved with a prefix argument.
  3261. - If (possibly after star and exclamation mark) the search string starts
  3262. with a colon, this will mean that the (non-regexp) snippets of the
  3263. Boolean search must match as full words.
  3264. This command searches the agenda files, and in addition the files listed
  3265. in `org-agenda-text-search-extra-files'."
  3266. (interactive "P")
  3267. (org-compile-prefix-format 'search)
  3268. (org-set-sorting-strategy 'search)
  3269. (org-prepare-agenda "SEARCH")
  3270. (let* ((props (list 'face nil
  3271. 'done-face 'org-agenda-done
  3272. 'org-not-done-regexp org-not-done-regexp
  3273. 'org-todo-regexp org-todo-regexp
  3274. 'org-complex-heading-regexp org-complex-heading-regexp
  3275. 'mouse-face 'highlight
  3276. 'help-echo (format "mouse-2 or RET jump to location")))
  3277. (full-words org-agenda-search-view-force-full-words)
  3278. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3279. regexp rtn rtnall files file pos
  3280. marker category tags c neg re boolean
  3281. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3282. (unless (and (not edit-at)
  3283. (stringp string)
  3284. (string-match "\\S-" string))
  3285. (setq string (read-string
  3286. (if org-agenda-search-view-always-boolean
  3287. "[+-]Word/{Regexp} ...: "
  3288. "Phrase, or [+-]Word/{Regexp} ...: ")
  3289. (cond
  3290. ((integerp edit-at) (cons string edit-at))
  3291. (edit-at string))
  3292. 'org-agenda-search-history)))
  3293. (org-set-local 'org-todo-only todo-only)
  3294. (setq org-agenda-redo-command
  3295. (list 'org-search-view (if todo-only t nil) string
  3296. '(if current-prefix-arg 1 nil)))
  3297. (setq org-agenda-query-string string)
  3298. (if (equal (string-to-char string) ?*)
  3299. (setq hdl-only t
  3300. words (substring string 1))
  3301. (setq words string))
  3302. (when (equal (string-to-char words) ?!)
  3303. (setq todo-only t
  3304. words (substring words 1)))
  3305. (when (equal (string-to-char words) ?:)
  3306. (setq full-words t
  3307. words (substring words 1)))
  3308. (if (or org-agenda-search-view-always-boolean
  3309. (member (string-to-char words) '(?- ?+ ?\{)))
  3310. (setq boolean t))
  3311. (setq words (org-split-string words))
  3312. (let (www w)
  3313. (while (setq w (pop words))
  3314. (while (and (string-match "\\\\\\'" w) words)
  3315. (setq w (concat (substring w 0 -1) " " (pop words))))
  3316. (push w www))
  3317. (setq words (nreverse www) www nil)
  3318. (while (setq w (pop words))
  3319. (when (and (string-match "\\`[-+]?{" w)
  3320. (not (string-match "}\\'" w)))
  3321. (while (and words (not (string-match "}\\'" (car words))))
  3322. (setq w (concat w " " (pop words))))
  3323. (setq w (concat w " " (pop words))))
  3324. (push w www))
  3325. (setq words (nreverse www)))
  3326. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3327. (when boolean
  3328. (let (wds w)
  3329. (while (setq w (pop words))
  3330. (if (or (equal (substring w 0 1) "\"")
  3331. (and (> (length w) 1)
  3332. (member (substring w 0 1) '("+" "-"))
  3333. (equal (substring w 1 2) "\"")))
  3334. (while (and words (not (equal (substring w -1) "\"")))
  3335. (setq w (concat w " " (pop words)))))
  3336. (and (string-match "\\`\\([-+]?\\)\"" w)
  3337. (setq w (replace-match "\\1" nil nil w)))
  3338. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3339. (push w wds))
  3340. (setq words (nreverse wds))))
  3341. (if boolean
  3342. (mapc (lambda (w)
  3343. (setq c (string-to-char w))
  3344. (if (equal c ?-)
  3345. (setq neg t w (substring w 1))
  3346. (if (equal c ?+)
  3347. (setq neg nil w (substring w 1))
  3348. (setq neg nil)))
  3349. (if (string-match "\\`{.*}\\'" w)
  3350. (setq re (substring w 1 -1))
  3351. (if full-words
  3352. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3353. (setq re (regexp-quote (downcase w)))))
  3354. (if neg (push re regexps-) (push re regexps+)))
  3355. words)
  3356. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3357. regexps+))
  3358. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3359. (if (not regexps+)
  3360. (setq regexp (concat "^" org-outline-regexp))
  3361. (setq regexp (pop regexps+))
  3362. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3363. regexp))))
  3364. (setq files (org-agenda-files nil 'ifmode))
  3365. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3366. (pop org-agenda-text-search-extra-files)
  3367. (setq files (org-add-archive-files files)))
  3368. (setq files (append files org-agenda-text-search-extra-files)
  3369. rtnall nil)
  3370. (while (setq file (pop files))
  3371. (setq ee nil)
  3372. (catch 'nextfile
  3373. (org-check-agenda-file file)
  3374. (setq buffer (if (file-exists-p file)
  3375. (org-get-agenda-file-buffer file)
  3376. (error "No such file %s" file)))
  3377. (if (not buffer)
  3378. ;; If file does not exist, make sure an error message is sent
  3379. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3380. file))))
  3381. (with-current-buffer buffer
  3382. (with-syntax-table (org-search-syntax-table)
  3383. (unless (org-mode-p)
  3384. (error "Agenda file %s is not in `org-mode'" file))
  3385. (let ((case-fold-search t))
  3386. (save-excursion
  3387. (save-restriction
  3388. (if org-agenda-restrict
  3389. (narrow-to-region org-agenda-restrict-begin
  3390. org-agenda-restrict-end)
  3391. (widen))
  3392. (goto-char (point-min))
  3393. (unless (or (org-on-heading-p)
  3394. (outline-next-heading))
  3395. (throw 'nextfile t))
  3396. (goto-char (max (point-min) (1- (point))))
  3397. (while (re-search-forward regexp nil t)
  3398. (org-back-to-heading t)
  3399. (skip-chars-forward "* ")
  3400. (setq beg (point-at-bol)
  3401. beg1 (point)
  3402. end (progn (outline-next-heading) (point)))
  3403. (catch :skip
  3404. (goto-char beg)
  3405. (org-agenda-skip)
  3406. (setq str (buffer-substring-no-properties
  3407. (point-at-bol)
  3408. (if hdl-only (point-at-eol) end)))
  3409. (mapc (lambda (wr) (when (string-match wr str)
  3410. (goto-char (1- end))
  3411. (throw :skip t)))
  3412. regexps-)
  3413. (mapc (lambda (wr) (unless (string-match wr str)
  3414. (goto-char (1- end))
  3415. (throw :skip t)))
  3416. (if todo-only
  3417. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3418. regexps+)
  3419. regexps+))
  3420. (goto-char beg)
  3421. (setq marker (org-agenda-new-marker (point))
  3422. category (org-get-category)
  3423. tags (org-get-tags-at (point))
  3424. txt (org-format-agenda-item
  3425. ""
  3426. (buffer-substring-no-properties
  3427. beg1 (point-at-eol))
  3428. category tags))
  3429. (org-add-props txt props
  3430. 'org-marker marker 'org-hd-marker marker
  3431. 'org-todo-regexp org-todo-regexp
  3432. 'org-complex-heading-regexp org-complex-heading-regexp
  3433. 'priority 1000 'org-category category
  3434. 'type "search")
  3435. (push txt ee)
  3436. (goto-char (1- end))))))))))
  3437. (setq rtn (nreverse ee))
  3438. (setq rtnall (append rtnall rtn)))
  3439. (if org-agenda-overriding-header
  3440. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3441. nil 'face 'org-agenda-structure) "\n")
  3442. (insert "Search words: ")
  3443. (add-text-properties (point-min) (1- (point))
  3444. (list 'face 'org-agenda-structure))
  3445. (setq pos (point))
  3446. (insert string "\n")
  3447. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3448. (setq pos (point))
  3449. (unless org-agenda-multi
  3450. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3451. (add-text-properties pos (1- (point))
  3452. (list 'face 'org-agenda-structure))))
  3453. (org-agenda-mark-header-line (point-min))
  3454. (when rtnall
  3455. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3456. (goto-char (point-min))
  3457. (or org-agenda-multi (org-fit-agenda-window))
  3458. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3459. (org-finalize-agenda)
  3460. (setq buffer-read-only t)))
  3461. ;;; Agenda TODO list
  3462. (defvar org-select-this-todo-keyword nil)
  3463. (defvar org-last-arg nil)
  3464. ;;;###autoload
  3465. (defun org-todo-list (arg)
  3466. "Show all (not done) TODO entries from all agenda file in a single list.
  3467. The prefix arg can be used to select a specific TODO keyword and limit
  3468. the list to these. When using \\[universal-argument], you will be prompted
  3469. for a keyword. A numeric prefix directly selects the Nth keyword in
  3470. `org-todo-keywords-1'."
  3471. (interactive "P")
  3472. (org-compile-prefix-format 'todo)
  3473. (org-set-sorting-strategy 'todo)
  3474. (org-prepare-agenda "TODO")
  3475. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3476. (let* ((today (time-to-days (current-time)))
  3477. (date (calendar-gregorian-from-absolute today))
  3478. (kwds org-todo-keywords-for-agenda)
  3479. (completion-ignore-case t)
  3480. (org-select-this-todo-keyword
  3481. (if (stringp arg) arg
  3482. (and arg (integerp arg) (> arg 0)
  3483. (nth (1- arg) kwds))))
  3484. rtn rtnall files file pos)
  3485. (when (equal arg '(4))
  3486. (setq org-select-this-todo-keyword
  3487. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3488. (mapcar 'list kwds) nil nil)))
  3489. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3490. (org-set-local 'org-last-arg arg)
  3491. (setq org-agenda-redo-command
  3492. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3493. (setq files (org-agenda-files nil 'ifmode)
  3494. rtnall nil)
  3495. (while (setq file (pop files))
  3496. (catch 'nextfile
  3497. (org-check-agenda-file file)
  3498. (setq rtn (org-agenda-get-day-entries file date :todo))
  3499. (setq rtnall (append rtnall rtn))))
  3500. (if org-agenda-overriding-header
  3501. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3502. nil 'face 'org-agenda-structure) "\n")
  3503. (insert "Global list of TODO items of type: ")
  3504. (add-text-properties (point-min) (1- (point))
  3505. (list 'face 'org-agenda-structure
  3506. 'short-heading
  3507. (concat "ToDo: "
  3508. (or org-select-this-todo-keyword "ALL"))))
  3509. (org-agenda-mark-header-line (point-min))
  3510. (setq pos (point))
  3511. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3512. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3513. (setq pos (point))
  3514. (unless org-agenda-multi
  3515. (insert "Available with `N r': (0)ALL")
  3516. (let ((n 0) s)
  3517. (mapc (lambda (x)
  3518. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3519. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3520. (insert "\n "))
  3521. (insert " " s))
  3522. kwds))
  3523. (insert "\n"))
  3524. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3525. (org-agenda-mark-header-line (point-min))
  3526. (when rtnall
  3527. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3528. (goto-char (point-min))
  3529. (or org-agenda-multi (org-fit-agenda-window))
  3530. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3531. (org-finalize-agenda)
  3532. (setq buffer-read-only t)))
  3533. ;;; Agenda tags match
  3534. ;;;###autoload
  3535. (defun org-tags-view (&optional todo-only match)
  3536. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3537. The prefix arg TODO-ONLY limits the search to TODO entries."
  3538. (interactive "P")
  3539. (org-compile-prefix-format 'tags)
  3540. (org-set-sorting-strategy 'tags)
  3541. (let* ((org-tags-match-list-sublevels
  3542. org-tags-match-list-sublevels)
  3543. (completion-ignore-case t)
  3544. rtn rtnall files file pos matcher
  3545. buffer)
  3546. (when (and (stringp match) (not (string-match "\\S-" match)))
  3547. (setq match nil))
  3548. (setq matcher (org-make-tags-matcher match)
  3549. match (car matcher) matcher (cdr matcher))
  3550. (org-prepare-agenda (concat "TAGS " match))
  3551. (setq org-agenda-query-string match)
  3552. (setq org-agenda-redo-command
  3553. (list 'org-tags-view (list 'quote todo-only)
  3554. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3555. (setq files (org-agenda-files nil 'ifmode)
  3556. rtnall nil)
  3557. (while (setq file (pop files))
  3558. (catch 'nextfile
  3559. (org-check-agenda-file file)
  3560. (setq buffer (if (file-exists-p file)
  3561. (org-get-agenda-file-buffer file)
  3562. (error "No such file %s" file)))
  3563. (if (not buffer)
  3564. ;; If file does not exist, error message to agenda
  3565. (setq rtn (list
  3566. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3567. rtnall (append rtnall rtn))
  3568. (with-current-buffer buffer
  3569. (unless (org-mode-p)
  3570. (error "Agenda file %s is not in `org-mode'" file))
  3571. (save-excursion
  3572. (save-restriction
  3573. (if org-agenda-restrict
  3574. (narrow-to-region org-agenda-restrict-begin
  3575. org-agenda-restrict-end)
  3576. (widen))
  3577. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3578. (setq rtnall (append rtnall rtn))))))))
  3579. (if org-agenda-overriding-header
  3580. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3581. nil 'face 'org-agenda-structure) "\n")
  3582. (insert "Headlines with TAGS match: ")
  3583. (add-text-properties (point-min) (1- (point))
  3584. (list 'face 'org-agenda-structure
  3585. 'short-heading
  3586. (concat "Match: " match)))
  3587. (setq pos (point))
  3588. (insert match "\n")
  3589. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3590. (setq pos (point))
  3591. (unless org-agenda-multi
  3592. (insert "Press `C-u r' to search again with new search string\n"))
  3593. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3594. (org-agenda-mark-header-line (point-min))
  3595. (when rtnall
  3596. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3597. (goto-char (point-min))
  3598. (or org-agenda-multi (org-fit-agenda-window))
  3599. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3600. (org-finalize-agenda)
  3601. (setq buffer-read-only t)))
  3602. ;;; Agenda Finding stuck projects
  3603. (defvar org-agenda-skip-regexp nil
  3604. "Regular expression used in skipping subtrees for the agenda.
  3605. This is basically a temporary global variable that can be set and then
  3606. used by user-defined selections using `org-agenda-skip-function'.")
  3607. (defvar org-agenda-overriding-header nil
  3608. "When this is set during todo and tags searches, will replace header.
  3609. This variable should not be set directly, but custom commands can bind it
  3610. in the options section.")
  3611. (defun org-agenda-skip-entry-when-regexp-matches ()
  3612. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3613. If yes, it returns the end position of this entry, causing agenda commands
  3614. to skip the entry but continuing the search in the subtree. This is a
  3615. function that can be put into `org-agenda-skip-function' for the duration
  3616. of a command."
  3617. (let ((end (save-excursion (org-end-of-subtree t)))
  3618. skip)
  3619. (save-excursion
  3620. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3621. (and skip end)))
  3622. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3623. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3624. If yes, it returns the end position of this tree, causing agenda commands
  3625. to skip this subtree. This is a function that can be put into
  3626. `org-agenda-skip-function' for the duration of a command."
  3627. (let ((end (save-excursion (org-end-of-subtree t)))
  3628. skip)
  3629. (save-excursion
  3630. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3631. (and skip end)))
  3632. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3633. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3634. If yes, it returns the end position of the current entry (NOT the tree),
  3635. causing agenda commands to skip the entry but continuing the search in
  3636. the subtree. This is a function that can be put into
  3637. `org-agenda-skip-function' for the duration of a command. An important
  3638. use of this function is for the stuck project list."
  3639. (let ((end (save-excursion (org-end-of-subtree t)))
  3640. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3641. skip)
  3642. (save-excursion
  3643. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3644. (and skip entry-end)))
  3645. (defun org-agenda-skip-entry-if (&rest conditions)
  3646. "Skip entry if any of CONDITIONS is true.
  3647. See `org-agenda-skip-if' for details."
  3648. (org-agenda-skip-if nil conditions))
  3649. (defun org-agenda-skip-subtree-if (&rest conditions)
  3650. "Skip entry if any of CONDITIONS is true.
  3651. See `org-agenda-skip-if' for details."
  3652. (org-agenda-skip-if t conditions))
  3653. (defun org-agenda-skip-if (subtree conditions)
  3654. "Checks current entity for CONDITIONS.
  3655. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3656. the entry, i.e. the text before the next heading is checked.
  3657. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3658. from different tests. Valid conditions are:
  3659. scheduled Check if there is a scheduled cookie
  3660. notscheduled Check if there is no scheduled cookie
  3661. deadline Check if there is a deadline
  3662. notdeadline Check if there is no deadline
  3663. timestamp Check if there is a timestamp (also deadline or scheduled)
  3664. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3665. regexp Check if regexp matches
  3666. notregexp Check if regexp does not match.
  3667. todo Check if TODO keyword matches
  3668. nottodo Check if TODO keyword does not match
  3669. The regexp is taken from the conditions list, it must come right after
  3670. the `regexp' or `notregexp' element.
  3671. `todo' and `nottodo' accept as an argument a list of todo
  3672. keywords, which may include \"*\" to match any todo keyword.
  3673. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3674. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3675. Instead of a list a keyword class may be given
  3676. (org-agenda-skip-entry-if 'nottodo 'done)
  3677. would skip entries that haven't been marked with any of \"DONE\"
  3678. keywords. Possible classes are: `todo', `done', `any'.
  3679. If any of these conditions is met, this function returns the end point of
  3680. the entity, causing the search to continue from there. This is a function
  3681. that can be put into `org-agenda-skip-function' for the duration of a command."
  3682. (let (beg end m)
  3683. (org-back-to-heading t)
  3684. (setq beg (point)
  3685. end (if subtree
  3686. (progn (org-end-of-subtree t) (point))
  3687. (progn (outline-next-heading) (1- (point)))))
  3688. (goto-char beg)
  3689. (and
  3690. (or
  3691. (and (memq 'scheduled conditions)
  3692. (re-search-forward org-scheduled-time-regexp end t))
  3693. (and (memq 'notscheduled conditions)
  3694. (not (re-search-forward org-scheduled-time-regexp end t)))
  3695. (and (memq 'deadline conditions)
  3696. (re-search-forward org-deadline-time-regexp end t))
  3697. (and (memq 'notdeadline conditions)
  3698. (not (re-search-forward org-deadline-time-regexp end t)))
  3699. (and (memq 'timestamp conditions)
  3700. (re-search-forward org-ts-regexp end t))
  3701. (and (memq 'nottimestamp conditions)
  3702. (not (re-search-forward org-ts-regexp end t)))
  3703. (and (setq m (memq 'regexp conditions))
  3704. (stringp (nth 1 m))
  3705. (re-search-forward (nth 1 m) end t))
  3706. (and (setq m (memq 'notregexp conditions))
  3707. (stringp (nth 1 m))
  3708. (not (re-search-forward (nth 1 m) end t)))
  3709. (and (or
  3710. (setq m (memq 'todo conditions))
  3711. (setq m (memq 'nottodo conditions)))
  3712. (org-agenda-skip-if-todo m end)))
  3713. end)))
  3714. (defun org-agenda-skip-if-todo (args end)
  3715. "Helper function for `org-agenda-skip-if', do not use it directly.
  3716. ARGS is a list with first element either `todo' or `nottodo'.
  3717. The remainder is either a list of TODO keywords, or a state symbol
  3718. `todo' or `done' or `any'."
  3719. (let ((kw (car args))
  3720. (arg (cadr args))
  3721. todo-wds todo-re)
  3722. (setq todo-wds
  3723. (org-uniquify
  3724. (cond
  3725. ((listp arg) ;; list of keywords
  3726. (if (member "*" arg)
  3727. (mapcar 'substring-no-properties org-todo-keywords-1)
  3728. arg))
  3729. ((symbolp arg) ;; keyword class name
  3730. (cond
  3731. ((eq arg 'todo)
  3732. (org-delete-all org-done-keywords
  3733. (mapcar 'substring-no-properties
  3734. org-todo-keywords-1)))
  3735. ((eq arg 'done) org-done-keywords)
  3736. ((eq arg 'any)
  3737. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3738. (setq todo-re
  3739. (concat "^\\*+[ \t]+\\<\\("
  3740. (mapconcat 'identity todo-wds "\\|")
  3741. "\\)\\>"))
  3742. (if (eq kw 'todo)
  3743. (re-search-forward todo-re end t)
  3744. (not (re-search-forward todo-re end t)))))
  3745. ;;;###autoload
  3746. (defun org-agenda-list-stuck-projects (&rest ignore)
  3747. "Create agenda view for projects that are stuck.
  3748. Stuck projects are project that have no next actions. For the definitions
  3749. of what a project is and how to check if it stuck, customize the variable
  3750. `org-stuck-projects'."
  3751. (interactive)
  3752. (let* ((org-agenda-skip-function
  3753. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3754. ;; We could have used org-agenda-skip-if here.
  3755. (org-agenda-overriding-header
  3756. (or org-agenda-overriding-header "List of stuck projects: "))
  3757. (matcher (nth 0 org-stuck-projects))
  3758. (todo (nth 1 org-stuck-projects))
  3759. (todo-wds (if (member "*" todo)
  3760. (progn
  3761. (org-prepare-agenda-buffers (org-agenda-files
  3762. nil 'ifmode))
  3763. (org-delete-all
  3764. org-done-keywords-for-agenda
  3765. (copy-sequence org-todo-keywords-for-agenda)))
  3766. todo))
  3767. (todo-re (concat "^\\*+[ \t]+\\("
  3768. (mapconcat 'identity todo-wds "\\|")
  3769. "\\)\\>"))
  3770. (tags (nth 2 org-stuck-projects))
  3771. (tags-re (if (member "*" tags)
  3772. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3773. (if tags
  3774. (concat "^\\*+ .*:\\("
  3775. (mapconcat 'identity tags "\\|")
  3776. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3777. (gen-re (nth 3 org-stuck-projects))
  3778. (re-list
  3779. (delq nil
  3780. (list
  3781. (if todo todo-re)
  3782. (if tags tags-re)
  3783. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3784. gen-re)))))
  3785. (setq org-agenda-skip-regexp
  3786. (if re-list
  3787. (mapconcat 'identity re-list "\\|")
  3788. (error "No information how to identify unstuck projects")))
  3789. (org-tags-view nil matcher)
  3790. (with-current-buffer org-agenda-buffer-name
  3791. (setq org-agenda-redo-command
  3792. '(org-agenda-list-stuck-projects
  3793. (or current-prefix-arg org-last-arg))))))
  3794. ;;; Diary integration
  3795. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3796. (defvar list-diary-entries-hook)
  3797. (defun org-get-entries-from-diary (date)
  3798. "Get the (Emacs Calendar) diary entries for DATE."
  3799. (require 'diary-lib)
  3800. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3801. (diary-display-hook '(fancy-diary-display))
  3802. (diary-display-function 'fancy-diary-display)
  3803. (pop-up-frames nil)
  3804. (list-diary-entries-hook
  3805. (cons 'org-diary-default-entry list-diary-entries-hook))
  3806. (diary-file-name-prefix-function nil) ; turn this feature off
  3807. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3808. entries
  3809. (org-disable-agenda-to-diary t))
  3810. (save-excursion
  3811. (save-window-excursion
  3812. (funcall (if (fboundp 'diary-list-entries)
  3813. 'diary-list-entries 'list-diary-entries)
  3814. date 1)))
  3815. (if (not (get-buffer diary-fancy-buffer))
  3816. (setq entries nil)
  3817. (with-current-buffer diary-fancy-buffer
  3818. (setq buffer-read-only nil)
  3819. (if (zerop (buffer-size))
  3820. ;; No entries
  3821. (setq entries nil)
  3822. ;; Omit the date and other unnecessary stuff
  3823. (org-agenda-cleanup-fancy-diary)
  3824. ;; Add prefix to each line and extend the text properties
  3825. (if (zerop (buffer-size))
  3826. (setq entries nil)
  3827. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3828. (set-buffer-modified-p nil)
  3829. (kill-buffer diary-fancy-buffer)))
  3830. (when entries
  3831. (setq entries (org-split-string entries "\n"))
  3832. (setq entries
  3833. (mapcar
  3834. (lambda (x)
  3835. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3836. ;; Extend the text properties to the beginning of the line
  3837. (org-add-props x (text-properties-at (1- (length x)) x)
  3838. 'type "diary" 'date date 'face 'org-agenda-diary))
  3839. entries)))))
  3840. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3841. "Hook run when the fancy diary buffer is cleaned up.")
  3842. (defun org-agenda-cleanup-fancy-diary ()
  3843. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3844. This gets rid of the date, the underline under the date, and
  3845. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3846. date. It also removes lines that contain only whitespace."
  3847. (goto-char (point-min))
  3848. (if (looking-at ".*?:[ \t]*")
  3849. (progn
  3850. (replace-match "")
  3851. (re-search-forward "\n=+$" nil t)
  3852. (replace-match "")
  3853. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3854. (re-search-forward "\n=+$" nil t)
  3855. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3856. (goto-char (point-min))
  3857. (while (re-search-forward "^ +\n" nil t)
  3858. (replace-match ""))
  3859. (goto-char (point-min))
  3860. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3861. (replace-match ""))
  3862. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3863. ;; Make sure entries from the diary have the right text properties.
  3864. (eval-after-load "diary-lib"
  3865. '(if (boundp 'diary-modify-entry-list-string-function)
  3866. ;; We can rely on the hook, nothing to do
  3867. nil
  3868. ;; Hook not available, must use advice to make this work
  3869. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3870. "Make the position visible."
  3871. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3872. (stringp string)
  3873. buffer-file-name)
  3874. (setq string (org-modify-diary-entry-string string))))))
  3875. (defun org-modify-diary-entry-string (string)
  3876. "Add text properties to string, allowing org-mode to act on it."
  3877. (org-add-props string nil
  3878. 'mouse-face 'highlight
  3879. 'help-echo (if buffer-file-name
  3880. (format "mouse-2 or RET jump to diary file %s"
  3881. (abbreviate-file-name buffer-file-name))
  3882. "")
  3883. 'org-agenda-diary-link t
  3884. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3885. (defun org-diary-default-entry ()
  3886. "Add a dummy entry to the diary.
  3887. Needed to avoid empty dates which mess up holiday display."
  3888. ;; Catch the error if dealing with the new add-to-diary-alist
  3889. (when org-disable-agenda-to-diary
  3890. (condition-case nil
  3891. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3892. (error
  3893. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3894. (defun org-add-to-diary-list (&rest args)
  3895. (if (fboundp 'diary-add-to-list)
  3896. (apply 'diary-add-to-list args)
  3897. (apply 'add-to-diary-list args)))
  3898. (defvar org-diary-last-run-time nil)
  3899. ;;;###autoload
  3900. (defun org-diary (&rest args)
  3901. "Return diary information from org-files.
  3902. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3903. It accesses org files and extracts information from those files to be
  3904. listed in the diary. The function accepts arguments specifying what
  3905. items should be listed. For a list of arguments allowed here, see the
  3906. variable `org-agenda-entry-types'.
  3907. The call in the diary file should look like this:
  3908. &%%(org-diary) ~/path/to/some/orgfile.org
  3909. Use a separate line for each org file to check. Or, if you omit the file name,
  3910. all files listed in `org-agenda-files' will be checked automatically:
  3911. &%%(org-diary)
  3912. If you don't give any arguments (as in the example above), the default
  3913. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3914. So the example above may also be written as
  3915. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3916. The function expects the lisp variables `entry' and `date' to be provided
  3917. by the caller, because this is how the calendar works. Don't use this
  3918. function from a program - use `org-agenda-get-day-entries' instead."
  3919. (when (> (- (org-float-time)
  3920. org-agenda-last-marker-time)
  3921. 5)
  3922. (org-agenda-reset-markers))
  3923. (org-compile-prefix-format 'agenda)
  3924. (org-set-sorting-strategy 'agenda)
  3925. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3926. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3927. (list entry)
  3928. (org-agenda-files t)))
  3929. (time (org-float-time))
  3930. file rtn results)
  3931. (when (or (not org-diary-last-run-time)
  3932. (> (- time
  3933. org-diary-last-run-time)
  3934. 3))
  3935. (org-prepare-agenda-buffers files))
  3936. (setq org-diary-last-run-time time)
  3937. ;; If this is called during org-agenda, don't return any entries to
  3938. ;; the calendar. Org Agenda will list these entries itself.
  3939. (if org-disable-agenda-to-diary (setq files nil))
  3940. (while (setq file (pop files))
  3941. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3942. (setq results (append results rtn)))
  3943. (if results
  3944. (concat (org-finalize-agenda-entries results) "\n"))))
  3945. ;;; Agenda entry finders
  3946. (defun org-agenda-get-day-entries (file date &rest args)
  3947. "Does the work for `org-diary' and `org-agenda'.
  3948. FILE is the path to a file to be checked for entries. DATE is date like
  3949. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3950. which kind of entries should be extracted. For details about these, see
  3951. the documentation of `org-diary'."
  3952. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3953. (let* ((org-startup-folded nil)
  3954. (org-startup-align-all-tables nil)
  3955. (buffer (if (file-exists-p file)
  3956. (org-get-agenda-file-buffer file)
  3957. (error "No such file %s" file)))
  3958. arg results rtn deadline-results)
  3959. (if (not buffer)
  3960. ;; If file does not exist, make sure an error message ends up in diary
  3961. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3962. (with-current-buffer buffer
  3963. (unless (org-mode-p)
  3964. (error "Agenda file %s is not in `org-mode'" file))
  3965. (let ((case-fold-search nil))
  3966. (save-excursion
  3967. (save-restriction
  3968. (if org-agenda-restrict
  3969. (narrow-to-region org-agenda-restrict-begin
  3970. org-agenda-restrict-end)
  3971. (widen))
  3972. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3973. (while (setq arg (pop args))
  3974. (cond
  3975. ((and (eq arg :todo)
  3976. (equal date (calendar-current-date)))
  3977. (setq rtn (org-agenda-get-todos))
  3978. (setq results (append results rtn)))
  3979. ((eq arg :timestamp)
  3980. (setq rtn (org-agenda-get-blocks))
  3981. (setq results (append results rtn))
  3982. (setq rtn (org-agenda-get-timestamps))
  3983. (setq results (append results rtn)))
  3984. ((eq arg :sexp)
  3985. (setq rtn (org-agenda-get-sexps))
  3986. (setq results (append results rtn)))
  3987. ((eq arg :scheduled)
  3988. (setq rtn (org-agenda-get-scheduled deadline-results))
  3989. (setq results (append results rtn)))
  3990. ((eq arg :closed)
  3991. (setq rtn (org-agenda-get-progress))
  3992. (setq results (append results rtn)))
  3993. ((eq arg :deadline)
  3994. (setq rtn (org-agenda-get-deadlines))
  3995. (setq deadline-results (copy-sequence rtn))
  3996. (setq results (append results rtn))))))))
  3997. results))))
  3998. (defun org-agenda-get-todos ()
  3999. "Return the TODO information for agenda display."
  4000. (let* ((props (list 'face nil
  4001. 'done-face 'org-agenda-done
  4002. 'org-not-done-regexp org-not-done-regexp
  4003. 'org-todo-regexp org-todo-regexp
  4004. 'org-complex-heading-regexp org-complex-heading-regexp
  4005. 'mouse-face 'highlight
  4006. 'help-echo
  4007. (format "mouse-2 or RET jump to org file %s"
  4008. (abbreviate-file-name buffer-file-name))))
  4009. (regexp (concat "^\\*+[ \t]+\\("
  4010. (if org-select-this-todo-keyword
  4011. (if (equal org-select-this-todo-keyword "*")
  4012. org-todo-regexp
  4013. (concat "\\<\\("
  4014. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4015. "\\)\\>"))
  4016. org-not-done-regexp)
  4017. "[^\n\r]*\\)"))
  4018. marker priority category tags todo-state
  4019. ee txt beg end)
  4020. (goto-char (point-min))
  4021. (while (re-search-forward regexp nil t)
  4022. (catch :skip
  4023. (save-match-data
  4024. (beginning-of-line)
  4025. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4026. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4027. (goto-char (1+ beg))
  4028. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4029. (throw :skip nil)))
  4030. (goto-char beg)
  4031. (org-agenda-skip)
  4032. (goto-char (match-beginning 1))
  4033. (setq marker (org-agenda-new-marker (match-beginning 0))
  4034. category (org-get-category)
  4035. txt (match-string 1)
  4036. tags (org-get-tags-at (point))
  4037. txt (org-format-agenda-item "" txt category tags)
  4038. priority (1+ (org-get-priority txt))
  4039. todo-state (org-get-todo-state))
  4040. (org-add-props txt props
  4041. 'org-marker marker 'org-hd-marker marker
  4042. 'priority priority 'org-category category
  4043. 'type "todo" 'todo-state todo-state)
  4044. (push txt ee)
  4045. (if org-agenda-todo-list-sublevels
  4046. (goto-char (match-end 1))
  4047. (org-end-of-subtree 'invisible))))
  4048. (nreverse ee)))
  4049. ;;;###autoload
  4050. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4051. (&optional end)
  4052. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4053. (when (or org-agenda-todo-ignore-with-date
  4054. org-agenda-todo-ignore-scheduled
  4055. org-agenda-todo-ignore-deadlines)
  4056. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4057. (save-excursion
  4058. (or (and org-agenda-todo-ignore-with-date
  4059. (re-search-forward org-ts-regexp end t))
  4060. (and org-agenda-todo-ignore-scheduled
  4061. (re-search-forward org-scheduled-time-regexp end t)
  4062. (cond
  4063. ((eq org-agenda-todo-ignore-scheduled 'future)
  4064. (> (org-days-to-time (match-string 1)) 0))
  4065. ((eq org-agenda-todo-ignore-scheduled 'past)
  4066. (<= (org-days-to-time (match-string 1)) 0))
  4067. (t)))
  4068. (and org-agenda-todo-ignore-deadlines
  4069. (re-search-forward org-deadline-time-regexp end t)
  4070. (cond
  4071. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4072. ((eq org-agenda-todo-ignore-deadlines 'far)
  4073. (not (org-deadline-close (match-string 1))))
  4074. ((eq org-agenda-todo-ignore-deadlines 'future)
  4075. (> (org-days-to-time (match-string 1)) 0))
  4076. ((eq org-agenda-todo-ignore-deadlines 'past)
  4077. (<= (org-days-to-time (match-string 1)) 0))
  4078. (t (org-deadline-close (match-string 1)))))))))
  4079. (defconst org-agenda-no-heading-message
  4080. "No heading for this item in buffer or region.")
  4081. (defun org-agenda-get-timestamps ()
  4082. "Return the date stamp information for agenda display."
  4083. (let* ((props (list 'face nil
  4084. 'org-not-done-regexp org-not-done-regexp
  4085. 'org-todo-regexp org-todo-regexp
  4086. 'org-complex-heading-regexp org-complex-heading-regexp
  4087. 'mouse-face 'highlight
  4088. 'help-echo
  4089. (format "mouse-2 or RET jump to org file %s"
  4090. (abbreviate-file-name buffer-file-name))))
  4091. (d1 (calendar-absolute-from-gregorian date))
  4092. (remove-re
  4093. (concat
  4094. (regexp-quote
  4095. (format-time-string
  4096. "<%Y-%m-%d"
  4097. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4098. ".*?>"))
  4099. (regexp
  4100. (concat
  4101. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4102. (regexp-quote
  4103. (substring
  4104. (format-time-string
  4105. (car org-time-stamp-formats)
  4106. (apply 'encode-time ; DATE bound by calendar
  4107. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4108. 1 11))
  4109. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4110. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4111. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4112. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4113. todo-state end-of-match)
  4114. (goto-char (point-min))
  4115. (while (setq end-of-match (re-search-forward regexp nil t))
  4116. (setq b0 (match-beginning 0)
  4117. b3 (match-beginning 3) e3 (match-end 3))
  4118. (catch :skip
  4119. (and (org-at-date-range-p) (throw :skip nil))
  4120. (org-agenda-skip)
  4121. (if (and (match-end 1)
  4122. (not (= d1 (org-time-string-to-absolute
  4123. (match-string 1) d1 nil
  4124. org-agenda-repeating-timestamp-show-all))))
  4125. (throw :skip nil))
  4126. (if (and e3
  4127. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4128. (throw :skip nil))
  4129. (setq tmp (buffer-substring (max (point-min)
  4130. (- b0 org-ds-keyword-length))
  4131. b0)
  4132. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4133. inactivep (= (char-after b0) ?\[)
  4134. deadlinep (string-match org-deadline-regexp tmp)
  4135. scheduledp (string-match org-scheduled-regexp tmp)
  4136. closedp (and org-agenda-include-inactive-timestamps
  4137. (string-match org-closed-string tmp))
  4138. clockp (and org-agenda-include-inactive-timestamps
  4139. (or (string-match org-clock-string tmp)
  4140. (string-match "]-+\\'" tmp)))
  4141. todo-state (ignore-errors (org-get-todo-state))
  4142. donep (member todo-state org-done-keywords))
  4143. (if (or scheduledp deadlinep closedp clockp
  4144. (and donep org-agenda-skip-timestamp-if-done))
  4145. (throw :skip t))
  4146. (if (string-match ">" timestr)
  4147. ;; substring should only run to end of time stamp
  4148. (setq timestr (substring timestr 0 (match-end 0))))
  4149. (setq marker (org-agenda-new-marker b0)
  4150. category (org-get-category b0))
  4151. (save-excursion
  4152. (if (not (re-search-backward "^\\*+ " nil t))
  4153. (setq txt org-agenda-no-heading-message)
  4154. (goto-char (match-beginning 0))
  4155. (setq hdmarker (org-agenda-new-marker)
  4156. tags (org-get-tags-at))
  4157. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4158. (setq head (match-string 1))
  4159. (setq txt (org-format-agenda-item
  4160. (if inactivep org-agenda-inactive-leader nil)
  4161. head category tags timestr nil
  4162. remove-re)))
  4163. (setq priority (org-get-priority txt))
  4164. (org-add-props txt props
  4165. 'org-marker marker 'org-hd-marker hdmarker)
  4166. (org-add-props txt nil 'priority priority
  4167. 'org-category category 'date date
  4168. 'todo-state todo-state
  4169. 'type "timestamp")
  4170. (push txt ee))
  4171. (if org-agenda-skip-additional-timestamps-same-entry
  4172. (outline-next-heading)
  4173. (goto-char end-of-match))))
  4174. (nreverse ee)))
  4175. (defun org-agenda-get-sexps ()
  4176. "Return the sexp information for agenda display."
  4177. (require 'diary-lib)
  4178. (let* ((props (list 'face nil
  4179. 'mouse-face 'highlight
  4180. 'help-echo
  4181. (format "mouse-2 or RET jump to org file %s"
  4182. (abbreviate-file-name buffer-file-name))))
  4183. (regexp "^&?%%(")
  4184. marker category ee txt tags entry result beg b sexp sexp-entry
  4185. todo-state)
  4186. (goto-char (point-min))
  4187. (while (re-search-forward regexp nil t)
  4188. (catch :skip
  4189. (org-agenda-skip)
  4190. (setq beg (match-beginning 0))
  4191. (goto-char (1- (match-end 0)))
  4192. (setq b (point))
  4193. (forward-sexp 1)
  4194. (setq sexp (buffer-substring b (point)))
  4195. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4196. (org-trim (match-string 1))
  4197. ""))
  4198. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4199. (when result
  4200. (setq marker (org-agenda-new-marker beg)
  4201. category (org-get-category beg)
  4202. todo-state (org-get-todo-state))
  4203. (dolist (r (if (stringp result)
  4204. (list result)
  4205. result)) ;; we expect a list here
  4206. (if (string-match "\\S-" r)
  4207. (setq txt r)
  4208. (setq txt "SEXP entry returned empty string"))
  4209. (setq txt (org-format-agenda-item
  4210. "" txt category tags 'time))
  4211. (org-add-props txt props 'org-marker marker)
  4212. (org-add-props txt nil
  4213. 'org-category category 'date date 'todo-state todo-state
  4214. 'type "sexp")
  4215. (push txt ee)))))
  4216. (nreverse ee)))
  4217. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4218. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4219. The order of the first 2 times 3 arguments depends on the variable
  4220. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4221. So for American calendars, give this as MONTH DAY YEAR, for European as
  4222. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4223. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4224. is any number of ISO weeks in the block period for which the item should
  4225. be skipped."
  4226. (let* ((date1 (calendar-absolute-from-gregorian
  4227. (org-order-calendar-date-args m1 d1 y1)))
  4228. (date2 (calendar-absolute-from-gregorian
  4229. (org-order-calendar-date-args m2 d2 y2)))
  4230. (d (calendar-absolute-from-gregorian date)))
  4231. (and
  4232. (<= date1 d)
  4233. (<= d date2)
  4234. (= (calendar-day-of-week date) dayname)
  4235. (or (not skip-weeks)
  4236. (progn
  4237. (require 'cal-iso)
  4238. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4239. entry)))
  4240. (defalias 'org-get-closed 'org-agenda-get-progress)
  4241. (defun org-agenda-get-progress ()
  4242. "Return the logged TODO entries for agenda display."
  4243. (let* ((props (list 'mouse-face 'highlight
  4244. 'org-not-done-regexp org-not-done-regexp
  4245. 'org-todo-regexp org-todo-regexp
  4246. 'org-complex-heading-regexp org-complex-heading-regexp
  4247. 'help-echo
  4248. (format "mouse-2 or RET jump to org file %s"
  4249. (abbreviate-file-name buffer-file-name))))
  4250. (items (if (consp org-agenda-show-log)
  4251. org-agenda-show-log
  4252. org-agenda-log-mode-items))
  4253. (parts
  4254. (delq nil
  4255. (list
  4256. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4257. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4258. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4259. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4260. (error "`org-agenda-log-mode-items' is empty")))
  4261. (regexp (concat
  4262. "\\(" parts-re "\\)"
  4263. " *\\["
  4264. (regexp-quote
  4265. (substring
  4266. (format-time-string
  4267. (car org-time-stamp-formats)
  4268. (apply 'encode-time ; DATE bound by calendar
  4269. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4270. 1 11))))
  4271. (org-agenda-search-headline-for-time nil)
  4272. marker hdmarker priority category tags closedp statep clockp state
  4273. ee txt extra timestr rest clocked)
  4274. (goto-char (point-min))
  4275. (while (re-search-forward regexp nil t)
  4276. (catch :skip
  4277. (org-agenda-skip)
  4278. (setq marker (org-agenda-new-marker (match-beginning 0))
  4279. closedp (equal (match-string 1) org-closed-string)
  4280. statep (equal (string-to-char (match-string 1)) ?-)
  4281. clockp (not (or closedp statep))
  4282. state (and statep (match-string 2))
  4283. category (org-get-category (match-beginning 0))
  4284. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4285. )
  4286. (when (string-match "\\]" timestr)
  4287. ;; substring should only run to end of time stamp
  4288. (setq rest (substring timestr (match-end 0))
  4289. timestr (substring timestr 0 (match-end 0)))
  4290. (if (and (not closedp) (not statep)
  4291. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4292. (progn (setq timestr (concat (substring timestr 0 -1)
  4293. "-" (match-string 1 rest) "]"))
  4294. (setq clocked (match-string 2 rest)))
  4295. (setq clocked "-")))
  4296. (save-excursion
  4297. (setq extra nil)
  4298. (cond
  4299. ((not org-agenda-log-mode-add-notes))
  4300. (statep
  4301. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4302. (setq extra (match-string 1))))
  4303. (clockp
  4304. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4305. (setq extra (match-string 1)))))
  4306. (if (not (re-search-backward "^\\*+ " nil t))
  4307. (setq txt org-agenda-no-heading-message)
  4308. (goto-char (match-beginning 0))
  4309. (setq hdmarker (org-agenda-new-marker)
  4310. tags (org-get-tags-at))
  4311. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4312. (setq txt (match-string 1))
  4313. (when extra
  4314. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4315. (setq txt (concat (substring txt 0 (match-beginning 1))
  4316. " - " extra " " (match-string 2 txt)))
  4317. (setq txt (concat txt " - " extra))))
  4318. (setq txt (org-format-agenda-item
  4319. (cond
  4320. (closedp "Closed: ")
  4321. (statep (concat "State: (" state ")"))
  4322. (t (concat "Clocked: (" clocked ")")))
  4323. txt category tags timestr)))
  4324. (setq priority 100000)
  4325. (org-add-props txt props
  4326. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4327. 'priority priority 'org-category category
  4328. 'type "closed" 'date date
  4329. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4330. (push txt ee))
  4331. (goto-char (point-at-eol))))
  4332. (nreverse ee)))
  4333. (defun org-agenda-get-deadlines ()
  4334. "Return the deadline information for agenda display."
  4335. (let* ((props (list 'mouse-face 'highlight
  4336. 'org-not-done-regexp org-not-done-regexp
  4337. 'org-todo-regexp org-todo-regexp
  4338. 'org-complex-heading-regexp org-complex-heading-regexp
  4339. 'help-echo
  4340. (format "mouse-2 or RET jump to org file %s"
  4341. (abbreviate-file-name buffer-file-name))))
  4342. (regexp org-deadline-time-regexp)
  4343. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4344. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4345. d2 diff dfrac wdays pos pos1 category tags
  4346. suppress-prewarning
  4347. ee txt head face s todo-state upcomingp donep timestr)
  4348. (goto-char (point-min))
  4349. (while (re-search-forward regexp nil t)
  4350. (setq suppress-prewarning nil)
  4351. (catch :skip
  4352. (org-agenda-skip)
  4353. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4354. (save-match-data
  4355. (string-match org-scheduled-time-regexp
  4356. (buffer-substring (point-at-bol)
  4357. (point-at-eol)))))
  4358. (setq suppress-prewarning
  4359. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4360. org-agenda-skip-deadline-prewarning-if-scheduled
  4361. 0)))
  4362. (setq s (match-string 1)
  4363. txt nil
  4364. pos (1- (match-beginning 1))
  4365. d2 (org-time-string-to-absolute
  4366. (match-string 1) d1 'past
  4367. org-agenda-repeating-timestamp-show-all)
  4368. diff (- d2 d1)
  4369. wdays (if suppress-prewarning
  4370. (let ((org-deadline-warning-days suppress-prewarning))
  4371. (org-get-wdays s))
  4372. (org-get-wdays s))
  4373. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4374. upcomingp (and todayp (> diff 0)))
  4375. ;; When to show a deadline in the calendar:
  4376. ;; If the expiration is within wdays warning time.
  4377. ;; Past-due deadlines are only shown on the current date
  4378. (if (and (or (and (<= diff wdays)
  4379. (and todayp (not org-agenda-only-exact-dates)))
  4380. (= diff 0)))
  4381. (save-excursion
  4382. (setq todo-state (org-get-todo-state))
  4383. (setq donep (member todo-state org-done-keywords))
  4384. (if (and donep
  4385. (or org-agenda-skip-deadline-if-done
  4386. (not (= diff 0))))
  4387. (setq txt nil)
  4388. (setq category (org-get-category))
  4389. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4390. (setq txt org-agenda-no-heading-message)
  4391. (goto-char (match-end 0))
  4392. (setq pos1 (match-beginning 0))
  4393. (setq tags (org-get-tags-at pos1))
  4394. (setq head (buffer-substring-no-properties
  4395. (point)
  4396. (progn (skip-chars-forward "^\r\n")
  4397. (point))))
  4398. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4399. (setq timestr
  4400. (concat (substring s (match-beginning 1)) " "))
  4401. (setq timestr 'time))
  4402. (setq txt (org-format-agenda-item
  4403. (if (= diff 0)
  4404. (car org-agenda-deadline-leaders)
  4405. (if (functionp
  4406. (nth 1 org-agenda-deadline-leaders))
  4407. (funcall
  4408. (nth 1 org-agenda-deadline-leaders)
  4409. diff date)
  4410. (format (nth 1 org-agenda-deadline-leaders)
  4411. diff)))
  4412. head category tags
  4413. (if (not (= diff 0)) nil timestr)))))
  4414. (when txt
  4415. (setq face (org-agenda-deadline-face dfrac wdays))
  4416. (org-add-props txt props
  4417. 'org-marker (org-agenda-new-marker pos)
  4418. 'org-hd-marker (org-agenda-new-marker pos1)
  4419. 'priority (+ (- diff)
  4420. (org-get-priority txt))
  4421. 'org-category category
  4422. 'todo-state todo-state
  4423. 'type (if upcomingp "upcoming-deadline" "deadline")
  4424. 'date (if upcomingp date d2)
  4425. 'face (if donep 'org-agenda-done face)
  4426. 'undone-face face 'done-face 'org-agenda-done)
  4427. (push txt ee))))))
  4428. (nreverse ee)))
  4429. (defun org-agenda-deadline-face (fraction &optional wdays)
  4430. "Return the face to displaying a deadline item.
  4431. FRACTION is what fraction of the head-warning time has passed."
  4432. (if (equal wdays 0) (setq fraction 1.))
  4433. (let ((faces org-agenda-deadline-faces) f)
  4434. (catch 'exit
  4435. (while (setq f (pop faces))
  4436. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4437. (defun org-agenda-get-scheduled (&optional deadline-results)
  4438. "Return the scheduled information for agenda display."
  4439. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4440. 'org-todo-regexp org-todo-regexp
  4441. 'org-complex-heading-regexp org-complex-heading-regexp
  4442. 'done-face 'org-agenda-done
  4443. 'mouse-face 'highlight
  4444. 'help-echo
  4445. (format "mouse-2 or RET jump to org file %s"
  4446. (abbreviate-file-name buffer-file-name))))
  4447. (regexp org-scheduled-time-regexp)
  4448. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4449. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4450. mm
  4451. (deadline-position-alist
  4452. (mapcar (lambda (a) (and (setq mm (get-text-property
  4453. 0 'org-hd-marker a))
  4454. (cons (marker-position mm) a)))
  4455. deadline-results))
  4456. d2 diff pos pos1 category tags donep
  4457. ee txt head pastschedp todo-state face timestr s habitp)
  4458. (goto-char (point-min))
  4459. (while (re-search-forward regexp nil t)
  4460. (catch :skip
  4461. (org-agenda-skip)
  4462. (setq s (match-string 1)
  4463. txt nil
  4464. pos (1- (match-beginning 1))
  4465. d2 (org-time-string-to-absolute
  4466. (match-string 1) d1 'past
  4467. org-agenda-repeating-timestamp-show-all)
  4468. diff (- d2 d1))
  4469. (setq pastschedp (and todayp (< diff 0)))
  4470. ;; When to show a scheduled item in the calendar:
  4471. ;; If it is on or past the date.
  4472. (when (or (and (< diff 0)
  4473. (< (abs diff) org-scheduled-past-days)
  4474. (and todayp (not org-agenda-only-exact-dates)))
  4475. (= diff 0))
  4476. (save-excursion
  4477. (setq todo-state (org-get-todo-state))
  4478. (setq donep (member todo-state org-done-keywords))
  4479. (setq habitp (and (functionp 'org-is-habit-p)
  4480. (org-is-habit-p)))
  4481. (if (and donep
  4482. (or habitp org-agenda-skip-scheduled-if-done
  4483. (not (= diff 0))))
  4484. (setq txt nil)
  4485. (setq category (org-get-category))
  4486. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4487. (setq txt org-agenda-no-heading-message)
  4488. (goto-char (match-end 0))
  4489. (setq pos1 (match-beginning 0))
  4490. (if habitp
  4491. (if (or (not org-habit-show-habits)
  4492. (and (not todayp)
  4493. org-habit-show-habits-only-for-today))
  4494. (throw :skip nil))
  4495. (if (and
  4496. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4497. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4498. pastschedp))
  4499. (setq mm (assoc pos1 deadline-position-alist)))
  4500. (throw :skip nil)))
  4501. (setq tags (org-get-tags-at))
  4502. (setq head (buffer-substring-no-properties
  4503. (point)
  4504. (progn (skip-chars-forward "^\r\n") (point))))
  4505. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4506. (setq timestr
  4507. (concat (substring s (match-beginning 1)) " "))
  4508. (setq timestr 'time))
  4509. (setq txt (org-format-agenda-item
  4510. (if (= diff 0)
  4511. (car org-agenda-scheduled-leaders)
  4512. (format (nth 1 org-agenda-scheduled-leaders)
  4513. (- 1 diff)))
  4514. head category tags
  4515. (if (not (= diff 0)) nil timestr)
  4516. nil nil habitp))))
  4517. (when txt
  4518. (setq face
  4519. (cond
  4520. ((and (not habitp) pastschedp)
  4521. 'org-scheduled-previously)
  4522. (todayp 'org-scheduled-today)
  4523. (t 'org-scheduled))
  4524. habitp (and habitp (org-habit-parse-todo)))
  4525. (org-add-props txt props
  4526. 'undone-face face
  4527. 'face (if donep 'org-agenda-done face)
  4528. 'org-marker (org-agenda-new-marker pos)
  4529. 'org-hd-marker (org-agenda-new-marker pos1)
  4530. 'type (if pastschedp "past-scheduled" "scheduled")
  4531. 'date (if pastschedp d2 date)
  4532. 'priority (if habitp
  4533. (org-habit-get-priority habitp)
  4534. (+ 94 (- 5 diff) (org-get-priority txt)))
  4535. 'org-category category
  4536. 'org-habit-p habitp
  4537. 'todo-state todo-state)
  4538. (push txt ee))))))
  4539. (nreverse ee)))
  4540. (defun org-agenda-get-blocks ()
  4541. "Return the date-range information for agenda display."
  4542. (let* ((props (list 'face nil
  4543. 'org-not-done-regexp org-not-done-regexp
  4544. 'org-todo-regexp org-todo-regexp
  4545. 'org-complex-heading-regexp org-complex-heading-regexp
  4546. 'mouse-face 'highlight
  4547. 'help-echo
  4548. (format "mouse-2 or RET jump to org file %s"
  4549. (abbreviate-file-name buffer-file-name))))
  4550. (regexp org-tr-regexp)
  4551. (d0 (calendar-absolute-from-gregorian date))
  4552. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4553. head donep)
  4554. (goto-char (point-min))
  4555. (while (re-search-forward regexp nil t)
  4556. (catch :skip
  4557. (org-agenda-skip)
  4558. (setq pos (point))
  4559. (setq timestr (match-string 0)
  4560. s1 (match-string 1)
  4561. s2 (match-string 2)
  4562. d1 (time-to-days (org-time-string-to-time s1))
  4563. d2 (time-to-days (org-time-string-to-time s2)))
  4564. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4565. ;; Only allow days between the limits, because the normal
  4566. ;; date stamps will catch the limits.
  4567. (save-excursion
  4568. (setq todo-state (org-get-todo-state))
  4569. (setq donep (member todo-state org-done-keywords))
  4570. (if (and donep org-agenda-skip-timestamp-if-done)
  4571. (throw :skip t))
  4572. (setq marker (org-agenda-new-marker (point)))
  4573. (setq category (org-get-category))
  4574. (if (not (re-search-backward "^\\*+ " nil t))
  4575. (setq txt org-agenda-no-heading-message)
  4576. (goto-char (match-beginning 0))
  4577. (setq hdmarker (org-agenda-new-marker (point)))
  4578. (setq tags (org-get-tags-at))
  4579. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4580. (setq head (match-string 1))
  4581. (let ((remove-re
  4582. (if org-agenda-remove-timeranges-from-blocks
  4583. (concat
  4584. "<" (regexp-quote s1) ".*?>"
  4585. "--"
  4586. "<" (regexp-quote s2) ".*?>")
  4587. nil)))
  4588. (setq txt (org-format-agenda-item
  4589. (format
  4590. (nth (if (= d1 d2) 0 1)
  4591. org-agenda-timerange-leaders)
  4592. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4593. head category tags
  4594. timestr nil remove-re))))
  4595. (org-add-props txt props
  4596. 'org-marker marker 'org-hd-marker hdmarker
  4597. 'type "block" 'date date
  4598. 'todo-state todo-state
  4599. 'priority (org-get-priority txt) 'org-category category)
  4600. (push txt ee)))
  4601. (goto-char pos)))
  4602. ;; Sort the entries by expiration date.
  4603. (nreverse ee)))
  4604. ;;; Agenda presentation and sorting
  4605. (defvar org-prefix-has-time nil
  4606. "A flag, set by `org-compile-prefix-format'.
  4607. The flag is set if the currently compiled format contains a `%t'.")
  4608. (defvar org-prefix-has-tag nil
  4609. "A flag, set by `org-compile-prefix-format'.
  4610. The flag is set if the currently compiled format contains a `%T'.")
  4611. (defvar org-prefix-has-effort nil
  4612. "A flag, set by `org-compile-prefix-format'.
  4613. The flag is set if the currently compiled format contains a `%e'.")
  4614. (defvar org-prefix-category-length nil
  4615. "Used by `org-compile-prefix-format' to remember the category field width.")
  4616. (defvar org-prefix-category-max-length nil
  4617. "Used by `org-compile-prefix-format' to remember the category field width.")
  4618. (defun org-agenda-get-category-icon (category)
  4619. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4620. (dolist (entry org-agenda-category-icon-alist)
  4621. (when (org-string-match-p (car entry) category)
  4622. (if (listp (cadr entry))
  4623. (return (cadr entry))
  4624. (return (apply 'create-image (cdr entry)))))))
  4625. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4626. noprefix remove-re habitp)
  4627. "Format TXT to be inserted into the agenda buffer.
  4628. In particular, it adds the prefix and corresponding text properties. EXTRA
  4629. must be a string and replaces the `%s' specifier in the prefix format.
  4630. CATEGORY (string, symbol or nil) may be used to overrule the default
  4631. category taken from local variable or file name. It will replace the `%c'
  4632. specifier in the format. DOTIME, when non-nil, indicates that a
  4633. time-of-day should be extracted from TXT for sorting of this entry, and for
  4634. the `%t' specifier in the format. When DOTIME is a string, this string is
  4635. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4636. only the correctly processes TXT should be returned - this is used by
  4637. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4638. Any match of REMOVE-RE will be removed from TXT."
  4639. (save-match-data
  4640. ;; Diary entries sometimes have extra whitespace at the beginning
  4641. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4642. ;; Fix the tags part in txt
  4643. (setq txt (org-agenda-fix-displayed-tags
  4644. txt tags
  4645. org-agenda-show-inherited-tags
  4646. org-agenda-hide-tags-regexp))
  4647. (let* ((category (or category
  4648. org-category
  4649. (if buffer-file-name
  4650. (file-name-sans-extension
  4651. (file-name-nondirectory buffer-file-name))
  4652. "")))
  4653. (category-icon (org-agenda-get-category-icon category))
  4654. (category-icon (if category-icon
  4655. (propertize " " 'display category-icon)
  4656. ""))
  4657. ;; time, tag, effort are needed for the eval of the prefix format
  4658. (tag (if tags (nth (1- (length tags)) tags) ""))
  4659. time effort neffort
  4660. (ts (if dotime (concat
  4661. (if (stringp dotime) dotime "")
  4662. (and org-agenda-search-headline-for-time txt))))
  4663. (time-of-day (and dotime (org-get-time-of-day ts)))
  4664. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4665. duration thecategory)
  4666. (and (org-mode-p) buffer-file-name
  4667. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4668. (when (and dotime time-of-day)
  4669. ;; Extract starting and ending time and move them to prefix
  4670. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4671. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4672. (setq s0 (match-string 0 ts)
  4673. srp (and stamp (match-end 3))
  4674. s1 (match-string (if plain 1 2) ts)
  4675. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4676. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4677. ;; them, we might want to remove them there to avoid duplication.
  4678. ;; The user can turn this off with a variable.
  4679. (if (and org-prefix-has-time
  4680. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4681. (string-match (concat (regexp-quote s0) " *") txt)
  4682. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4683. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4684. (= (match-beginning 0) 0)
  4685. t))
  4686. (setq txt (replace-match "" nil nil txt))))
  4687. ;; Normalize the time(s) to 24 hour
  4688. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4689. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4690. ;; Compute the duration
  4691. (when s1
  4692. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4693. (string-to-number (substring s1 3)))
  4694. t2 (cond
  4695. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4696. (string-to-number (substring s2 3))))
  4697. (org-agenda-default-appointment-duration
  4698. (+ t1 org-agenda-default-appointment-duration))
  4699. (t nil)))
  4700. (setq duration (if t2 (- t2 t1)))))
  4701. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4702. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4703. (let ((m (+ (string-to-number (match-string 2 s1))
  4704. (* 60 (string-to-number (match-string 1 s1)))
  4705. org-agenda-default-appointment-duration))
  4706. h)
  4707. (setq h (/ m 60) m (- m (* h 60)))
  4708. (setq s2 (format "%02d:%02d" h m))))
  4709. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4710. txt)
  4711. ;; Tags are in the string
  4712. (if (or (eq org-agenda-remove-tags t)
  4713. (and org-agenda-remove-tags
  4714. org-prefix-has-tag))
  4715. (setq txt (replace-match "" t t txt))
  4716. (setq txt (replace-match
  4717. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4718. (match-string 2 txt))
  4719. t t txt))))
  4720. (when (org-mode-p)
  4721. (setq effort
  4722. (condition-case nil
  4723. (org-get-effort
  4724. (or (get-text-property 0 'org-hd-marker txt)
  4725. (get-text-property 0 'org-marker txt)))
  4726. (error nil)))
  4727. (when effort
  4728. (setq neffort (org-hh:mm-string-to-minutes effort)
  4729. effort (setq effort (concat "[" effort "]" )))))
  4730. (when remove-re
  4731. (while (string-match remove-re txt)
  4732. (setq txt (replace-match "" t t txt))))
  4733. ;; Create the final string
  4734. (if noprefix
  4735. (setq rtn txt)
  4736. ;; Prepare the variables needed in the eval of the compiled format
  4737. (setq time (cond (s2 (concat s1 "-" s2))
  4738. (s1 (concat s1 "......"))
  4739. (t ""))
  4740. extra (or (and (not habitp) extra) "")
  4741. category (if (symbolp category) (symbol-name category) category)
  4742. thecategory (copy-sequence category))
  4743. (if (string-match org-bracket-link-regexp category)
  4744. (progn
  4745. (setq l (if (match-end 3)
  4746. (- (match-end 3) (match-beginning 3))
  4747. (- (match-end 1) (match-beginning 1))))
  4748. (when (< l (or org-prefix-category-length 0))
  4749. (setq category (copy-sequence category))
  4750. (org-add-props category nil
  4751. 'extra-space (make-string
  4752. (- org-prefix-category-length l 1) ?\ ))))
  4753. (if (and org-prefix-category-max-length
  4754. (>= (length category) org-prefix-category-max-length))
  4755. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4756. ;; Evaluate the compiled format
  4757. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4758. ;; And finally add the text properties
  4759. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4760. (org-add-props rtn nil
  4761. 'org-category (if thecategory (downcase thecategory) category)
  4762. 'tags (mapcar 'org-downcase-keep-props tags)
  4763. 'org-highest-priority org-highest-priority
  4764. 'org-lowest-priority org-lowest-priority
  4765. 'prefix-length (- (length rtn) (length txt))
  4766. 'time-of-day time-of-day
  4767. 'duration duration
  4768. 'effort effort
  4769. 'effort-minutes neffort
  4770. 'txt txt
  4771. 'time time
  4772. 'extra extra
  4773. 'dotime dotime))))
  4774. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4775. "Remove tags string from TXT, and add a modified list of tags.
  4776. The modified list may contain inherited tags, and tags matched by
  4777. `org-agenda-hide-tags-regexp' will be removed."
  4778. (when (or add-inherited hide-re)
  4779. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4780. (setq txt (substring txt 0 (match-beginning 0))))
  4781. (setq tags
  4782. (delq nil
  4783. (mapcar (lambda (tg)
  4784. (if (or (and hide-re (string-match hide-re tg))
  4785. (and (not add-inherited)
  4786. (get-text-property 0 'inherited tg)))
  4787. nil
  4788. tg))
  4789. tags)))
  4790. (when tags
  4791. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4792. i)
  4793. (setq txt (concat txt " :"
  4794. (mapconcat
  4795. (lambda (x)
  4796. (setq i (get-text-property 0 'inherited x))
  4797. (if (and have-i (not i))
  4798. (progn
  4799. (setq have-i nil)
  4800. (concat ":" x))
  4801. x))
  4802. tags ":")
  4803. (if have-i "::" ":"))))))
  4804. txt)
  4805. (defun org-downcase-keep-props (s)
  4806. (let ((props (text-properties-at 0 s)))
  4807. (setq s (downcase s))
  4808. (add-text-properties 0 (length s) props s)
  4809. s))
  4810. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4811. (defvar org-agenda-sorting-strategy-selected nil)
  4812. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4813. (catch 'exit
  4814. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4815. ((and todayp (member 'today (car org-agenda-time-grid))))
  4816. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4817. ((member 'weekly (car org-agenda-time-grid)))
  4818. (t (throw 'exit list)))
  4819. (let* ((have (delq nil (mapcar
  4820. (lambda (x) (get-text-property 1 'time-of-day x))
  4821. list)))
  4822. (string (nth 1 org-agenda-time-grid))
  4823. (gridtimes (nth 2 org-agenda-time-grid))
  4824. (req (car org-agenda-time-grid))
  4825. (remove (member 'remove-match req))
  4826. new time)
  4827. (if (and (member 'require-timed req) (not have))
  4828. ;; don't show empty grid
  4829. (throw 'exit list))
  4830. (while (setq time (pop gridtimes))
  4831. (unless (and remove (member time have))
  4832. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  4833. (push (org-format-agenda-item
  4834. nil string "" nil
  4835. (concat (substring time 0 -2) ":" (substring time -2)))
  4836. new)
  4837. (put-text-property
  4838. 2 (length (car new)) 'face 'org-time-grid (car new))))
  4839. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4840. (append new list)
  4841. (append list new)))))
  4842. (defun org-compile-prefix-format (key)
  4843. "Compile the prefix format into a Lisp form that can be evaluated.
  4844. The resulting form is returned and stored in the variable
  4845. `org-prefix-format-compiled'."
  4846. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4847. org-prefix-category-length nil org-prefix-has-effort nil)
  4848. (let ((s (cond
  4849. ((stringp org-agenda-prefix-format)
  4850. org-agenda-prefix-format)
  4851. ((assq key org-agenda-prefix-format)
  4852. (cdr (assq key org-agenda-prefix-format)))
  4853. (t " %-12:c%?-12t% s")))
  4854. (start 0)
  4855. varform vars var e c f opt)
  4856. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\)"
  4857. s start)
  4858. (setq var (cdr (assoc (match-string 4 s)
  4859. '(("c" . category) ("t" . time) ("s" . extra)
  4860. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  4861. c (or (match-string 3 s) "")
  4862. opt (match-beginning 1)
  4863. start (1+ (match-beginning 0)))
  4864. (if (equal var 'time) (setq org-prefix-has-time t))
  4865. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4866. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4867. (setq f (concat "%" (match-string 2 s) "s"))
  4868. (when (equal var 'category)
  4869. (setq org-prefix-category-length
  4870. (floor (abs (string-to-number (match-string 2 s)))))
  4871. (setq org-prefix-category-max-length
  4872. (let ((x (match-string 2 s)))
  4873. (save-match-data
  4874. (if (string-match "\\.[0-9]+" x)
  4875. (string-to-number (substring (match-string 0 x) 1)))))))
  4876. (if opt
  4877. (setq varform
  4878. `(if (equal "" ,var)
  4879. ""
  4880. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4881. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4882. (setq s (replace-match "%s" t nil s))
  4883. (push varform vars))
  4884. (setq vars (nreverse vars))
  4885. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4886. (defun org-set-sorting-strategy (key)
  4887. (if (symbolp (car org-agenda-sorting-strategy))
  4888. ;; the old format
  4889. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4890. (setq org-agenda-sorting-strategy-selected
  4891. (or (cdr (assq key org-agenda-sorting-strategy))
  4892. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4893. '(time-up category-keep priority-down)))))
  4894. (defun org-get-time-of-day (s &optional string mod24)
  4895. "Check string S for a time of day.
  4896. If found, return it as a military time number between 0 and 2400.
  4897. If not found, return nil.
  4898. The optional STRING argument forces conversion into a 5 character wide string
  4899. HH:MM."
  4900. (save-match-data
  4901. (when
  4902. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4903. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4904. (let* ((h (string-to-number (match-string 1 s)))
  4905. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4906. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4907. (am-p (equal ampm "am"))
  4908. (h1 (cond ((not ampm) h)
  4909. ((= h 12) (if am-p 0 12))
  4910. (t (+ h (if am-p 0 12)))))
  4911. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4912. (mod h1 24) h1))
  4913. (t0 (+ (* 100 h2) m))
  4914. (t1 (concat (if (>= h1 24) "+" " ")
  4915. (if (and org-agenda-time-leading-zero
  4916. (< t0 1000)) "0" "")
  4917. (if (< t0 100) "0" "")
  4918. (if (< t0 10) "0" "")
  4919. (int-to-string t0))))
  4920. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4921. (defvar org-agenda-before-sorting-filter-function nil
  4922. "Function to be applied to agenda items prior to sorting.
  4923. Prior to sorting also means just before they are inserted into the agenda.
  4924. To aid sorting, you may revisit the original entries and add more text
  4925. properties which will later be used by the sorting functions.
  4926. The function should take a string argument, an agenda line.
  4927. It has access to the text properties in that line, which contain among
  4928. other things, the property `org-hd-marker' that points to the entry
  4929. where the line comes from. Note that not all lines going into the agenda
  4930. have this property, only most.
  4931. The function should return the modified string. It is probably best
  4932. to ONLY change text properties.
  4933. You can also use this function as a filter, by returning nil for lines
  4934. you don't want to have in the agenda at all. For this application, you
  4935. could bind the variable in the options section of a custom command.")
  4936. (defun org-finalize-agenda-entries (list &optional nosort)
  4937. "Sort and concatenate the agenda items."
  4938. (setq list (mapcar 'org-agenda-highlight-todo list))
  4939. (if nosort
  4940. list
  4941. (when org-agenda-before-sorting-filter-function
  4942. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  4943. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4944. (defun org-agenda-highlight-todo (x)
  4945. (let ((org-done-keywords org-done-keywords-for-agenda)
  4946. (case-fold-search nil)
  4947. re pl)
  4948. (if (eq x 'line)
  4949. (save-excursion
  4950. (beginning-of-line 1)
  4951. (setq re (org-get-at-bol 'org-todo-regexp))
  4952. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4953. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4954. (add-text-properties (match-beginning 0) (match-end 1)
  4955. (list 'face (org-get-todo-face 1)))
  4956. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4957. (delete-region (match-beginning 1) (1- (match-end 0)))
  4958. (goto-char (match-beginning 1))
  4959. (insert (format org-agenda-todo-keyword-format s)))))
  4960. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4961. pl (get-text-property 0 'prefix-length x))
  4962. (when (and re
  4963. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4964. x (or pl 0)) pl))
  4965. (add-text-properties
  4966. (or (match-end 1) (match-end 0)) (match-end 0)
  4967. (list 'face (org-get-todo-face (match-string 2 x)))
  4968. x)
  4969. (when (match-end 1)
  4970. (setq x (concat (substring x 0 (match-end 1))
  4971. (format org-agenda-todo-keyword-format
  4972. (match-string 2 x))
  4973. (org-add-props " " (text-properties-at 0 x))
  4974. (substring x (match-end 3))))))
  4975. x)))
  4976. (defsubst org-cmp-priority (a b)
  4977. "Compare the priorities of string A and B."
  4978. (let ((pa (or (get-text-property 1 'priority a) 0))
  4979. (pb (or (get-text-property 1 'priority b) 0)))
  4980. (cond ((> pa pb) +1)
  4981. ((< pa pb) -1)
  4982. (t nil))))
  4983. (defsubst org-cmp-effort (a b)
  4984. "Compare the priorities of string A and B."
  4985. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4986. (ea (or (get-text-property 1 'effort-minutes a) def))
  4987. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4988. (cond ((> ea eb) +1)
  4989. ((< ea eb) -1)
  4990. (t nil))))
  4991. (defsubst org-cmp-category (a b)
  4992. "Compare the string values of categories of strings A and B."
  4993. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4994. (cb (or (get-text-property 1 'org-category b) "")))
  4995. (cond ((string-lessp ca cb) -1)
  4996. ((string-lessp cb ca) +1)
  4997. (t nil))))
  4998. (defsubst org-cmp-todo-state (a b)
  4999. "Compare the todo states of strings A and B."
  5000. (let* ((ma (or (get-text-property 1 'org-marker a)
  5001. (get-text-property 1 'org-hd-marker a)))
  5002. (mb (or (get-text-property 1 'org-marker b)
  5003. (get-text-property 1 'org-hd-marker b)))
  5004. (fa (and ma (marker-buffer ma)))
  5005. (fb (and mb (marker-buffer mb)))
  5006. (todo-kwds
  5007. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5008. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5009. (ta (or (get-text-property 1 'todo-state a) ""))
  5010. (tb (or (get-text-property 1 'todo-state b) ""))
  5011. (la (- (length (member ta todo-kwds))))
  5012. (lb (- (length (member tb todo-kwds))))
  5013. (donepa (member ta org-done-keywords-for-agenda))
  5014. (donepb (member tb org-done-keywords-for-agenda)))
  5015. (cond ((and donepa (not donepb)) -1)
  5016. ((and (not donepa) donepb) +1)
  5017. ((< la lb) -1)
  5018. ((< lb la) +1)
  5019. (t nil))))
  5020. (defsubst org-cmp-alpha (a b)
  5021. "Compare the headlines, alphabetically."
  5022. (let* ((pla (get-text-property 0 'prefix-length a))
  5023. (plb (get-text-property 0 'prefix-length b))
  5024. (ta (and pla (substring a pla)))
  5025. (tb (and plb (substring b plb))))
  5026. (when pla
  5027. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5028. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5029. (setq ta (substring ta (match-end 0))))
  5030. (setq ta (downcase ta)))
  5031. (when plb
  5032. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5033. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5034. (setq tb (substring tb (match-end 0))))
  5035. (setq tb (downcase tb)))
  5036. (cond ((not ta) +1)
  5037. ((not tb) -1)
  5038. ((string-lessp ta tb) -1)
  5039. ((string-lessp tb ta) +1)
  5040. (t nil))))
  5041. (defsubst org-cmp-tag (a b)
  5042. "Compare the string values of the first tags of A and B."
  5043. (let ((ta (car (last (get-text-property 1 'tags a))))
  5044. (tb (car (last (get-text-property 1 'tags b)))))
  5045. (cond ((not ta) +1)
  5046. ((not tb) -1)
  5047. ((string-lessp ta tb) -1)
  5048. ((string-lessp tb ta) +1)
  5049. (t nil))))
  5050. (defsubst org-cmp-time (a b)
  5051. "Compare the time-of-day values of strings A and B."
  5052. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5053. (ta (or (get-text-property 1 'time-of-day a) def))
  5054. (tb (or (get-text-property 1 'time-of-day b) def)))
  5055. (cond ((< ta tb) -1)
  5056. ((< tb ta) +1)
  5057. (t nil))))
  5058. (defsubst org-cmp-habit-p (a b)
  5059. "Compare the todo states of strings A and B."
  5060. (let ((ha (get-text-property 1 'org-habit-p a))
  5061. (hb (get-text-property 1 'org-habit-p b)))
  5062. (cond ((and ha (not hb)) -1)
  5063. ((and (not ha) hb) +1)
  5064. (t nil))))
  5065. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5066. (defun org-entries-lessp (a b)
  5067. "Predicate for sorting agenda entries."
  5068. ;; The following variables will be used when the form is evaluated.
  5069. ;; So even though the compiler complains, keep them.
  5070. (let* ((ss org-agenda-sorting-strategy-selected)
  5071. (time-up (and (org-em 'time-up 'time-down ss)
  5072. (org-cmp-time a b)))
  5073. (time-down (if time-up (- time-up) nil))
  5074. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5075. (org-cmp-priority a b)))
  5076. (priority-down (if priority-up (- priority-up) nil))
  5077. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5078. (org-cmp-effort a b)))
  5079. (effort-down (if effort-up (- effort-up) nil))
  5080. (category-up (and (or (org-em 'category-up 'category-down ss)
  5081. (memq 'category-keep ss))
  5082. (org-cmp-category a b)))
  5083. (category-down (if category-up (- category-up) nil))
  5084. (category-keep (if category-up +1 nil))
  5085. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5086. (org-cmp-tag a b)))
  5087. (tag-down (if tag-up (- tag-up) nil))
  5088. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5089. (org-cmp-todo-state a b)))
  5090. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5091. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5092. (org-cmp-habit-p a b)))
  5093. (habit-down (if habit-up (- habit-up) nil))
  5094. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5095. (org-cmp-alpha a b)))
  5096. (alpha-down (if alpha-up (- alpha-up) nil))
  5097. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5098. user-defined-up user-defined-down)
  5099. (if (and need-user-cmp org-agenda-cmp-user-defined
  5100. (functionp org-agenda-cmp-user-defined))
  5101. (setq user-defined-up
  5102. (funcall org-agenda-cmp-user-defined a b)
  5103. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5104. (cdr (assoc
  5105. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5106. '((-1 . t) (1 . nil) (nil . nil))))))
  5107. ;;; Agenda restriction lock
  5108. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5109. "Overlay to mark the headline to which agenda commands are restricted.")
  5110. (overlay-put org-agenda-restriction-lock-overlay
  5111. 'face 'org-agenda-restriction-lock)
  5112. (overlay-put org-agenda-restriction-lock-overlay
  5113. 'help-echo "Agendas are currently limited to this subtree.")
  5114. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5115. (defun org-agenda-set-restriction-lock (&optional type)
  5116. "Set restriction lock for agenda, to current subtree or file.
  5117. Restriction will be the file if TYPE is `file', or if type is the
  5118. universal prefix '(4), or if the cursor is before the first headline
  5119. in the file. Otherwise, restriction will be to the current subtree."
  5120. (interactive "P")
  5121. (and (equal type '(4)) (setq type 'file))
  5122. (setq type (cond
  5123. (type type)
  5124. ((org-at-heading-p) 'subtree)
  5125. ((condition-case nil (org-back-to-heading t) (error nil))
  5126. 'subtree)
  5127. (t 'file)))
  5128. (if (eq type 'subtree)
  5129. (progn
  5130. (setq org-agenda-restrict t)
  5131. (setq org-agenda-overriding-restriction 'subtree)
  5132. (put 'org-agenda-files 'org-restrict
  5133. (list (buffer-file-name (buffer-base-buffer))))
  5134. (org-back-to-heading t)
  5135. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5136. (move-marker org-agenda-restrict-begin (point))
  5137. (move-marker org-agenda-restrict-end
  5138. (save-excursion (org-end-of-subtree t)))
  5139. (message "Locking agenda restriction to subtree"))
  5140. (put 'org-agenda-files 'org-restrict
  5141. (list (buffer-file-name (buffer-base-buffer))))
  5142. (setq org-agenda-restrict nil)
  5143. (setq org-agenda-overriding-restriction 'file)
  5144. (move-marker org-agenda-restrict-begin nil)
  5145. (move-marker org-agenda-restrict-end nil)
  5146. (message "Locking agenda restriction to file"))
  5147. (setq current-prefix-arg nil)
  5148. (org-agenda-maybe-redo))
  5149. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5150. "Remove the agenda restriction lock."
  5151. (interactive "P")
  5152. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5153. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5154. (setq org-agenda-overriding-restriction nil)
  5155. (setq org-agenda-restrict nil)
  5156. (put 'org-agenda-files 'org-restrict nil)
  5157. (move-marker org-agenda-restrict-begin nil)
  5158. (move-marker org-agenda-restrict-end nil)
  5159. (setq current-prefix-arg nil)
  5160. (message "Agenda restriction lock removed")
  5161. (or noupdate (org-agenda-maybe-redo)))
  5162. (defun org-agenda-maybe-redo ()
  5163. "If there is any window showing the agenda view, update it."
  5164. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5165. (w0 (selected-window)))
  5166. (when w
  5167. (select-window w)
  5168. (org-agenda-redo)
  5169. (select-window w0)
  5170. (if org-agenda-overriding-restriction
  5171. (message "Agenda view shifted to new %s restriction"
  5172. org-agenda-overriding-restriction)
  5173. (message "Agenda restriction lock removed")))))
  5174. ;;; Agenda commands
  5175. (defun org-agenda-check-type (error &rest types)
  5176. "Check if agenda buffer is of allowed type.
  5177. If ERROR is non-nil, throw an error, otherwise just return nil."
  5178. (if (memq org-agenda-type types)
  5179. t
  5180. (if error
  5181. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5182. nil)))
  5183. (defun org-agenda-quit ()
  5184. "Exit agenda by removing the window or the buffer."
  5185. (interactive)
  5186. (if org-agenda-columns-active
  5187. (org-columns-quit)
  5188. (let ((buf (current-buffer)))
  5189. (if (eq org-agenda-window-setup 'other-frame)
  5190. (progn
  5191. (kill-buffer buf)
  5192. (org-agenda-reset-markers)
  5193. (org-columns-remove-overlays)
  5194. (setq org-agenda-archives-mode nil)
  5195. (delete-frame))
  5196. (and (not (eq org-agenda-window-setup 'current-window))
  5197. (not (one-window-p))
  5198. (delete-window))
  5199. (kill-buffer buf)
  5200. (org-agenda-reset-markers)
  5201. (org-columns-remove-overlays)
  5202. (setq org-agenda-archives-mode nil)))
  5203. ;; Maybe restore the pre-agenda window configuration.
  5204. (and org-agenda-restore-windows-after-quit
  5205. (not (eq org-agenda-window-setup 'other-frame))
  5206. org-pre-agenda-window-conf
  5207. (set-window-configuration org-pre-agenda-window-conf))))
  5208. (defun org-agenda-exit ()
  5209. "Exit agenda by removing the window or the buffer.
  5210. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5211. Org-mode buffers visited directly by the user will not be touched."
  5212. (interactive)
  5213. (org-release-buffers org-agenda-new-buffers)
  5214. (setq org-agenda-new-buffers nil)
  5215. (org-agenda-quit))
  5216. (defun org-agenda-execute (arg)
  5217. "Execute another agenda command, keeping same window.
  5218. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5219. in the agenda."
  5220. (interactive "P")
  5221. (let ((org-agenda-window-setup 'current-window))
  5222. (org-agenda arg)))
  5223. (defun org-agenda-redo ()
  5224. "Rebuild Agenda.
  5225. When this is the global TODO list, a prefix argument will be interpreted."
  5226. (interactive)
  5227. (let* ((org-agenda-keep-modes t)
  5228. (filter org-agenda-filter)
  5229. (preset (get 'org-agenda-filter :preset-filter))
  5230. (org-agenda-filter-while-redo (or filter preset))
  5231. (cols org-agenda-columns-active)
  5232. (line (org-current-line))
  5233. (window-line (- line (org-current-line (window-start))))
  5234. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5235. (put 'org-agenda-filter :preset-filter nil)
  5236. (and cols (org-columns-quit))
  5237. (message "Rebuilding agenda buffer...")
  5238. (org-let lprops '(eval org-agenda-redo-command))
  5239. (setq org-agenda-undo-list nil
  5240. org-agenda-pending-undo-list nil)
  5241. (message "Rebuilding agenda buffer...done")
  5242. (put 'org-agenda-filter :preset-filter preset)
  5243. (and (or filter preset) (org-agenda-filter-apply filter))
  5244. (and cols (interactive-p) (org-agenda-columns))
  5245. (org-goto-line line)
  5246. (recenter window-line)))
  5247. (defvar org-global-tags-completion-table nil)
  5248. (defvar org-agenda-filter-form nil)
  5249. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5250. "Keep only those lines in the agenda buffer that have a specific tag.
  5251. The tag is selected with its fast selection letter, as configured.
  5252. With prefix argument STRIP, remove all lines that do have the tag.
  5253. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5254. used to narrow the search - the interactive user can also press `-' or `+'
  5255. to switch to narrowing."
  5256. (interactive "P")
  5257. (let* ((alist org-tag-alist-for-agenda)
  5258. (tag-chars (mapconcat
  5259. (lambda (x) (if (and (not (symbolp (car x)))
  5260. (cdr x))
  5261. (char-to-string (cdr x))
  5262. ""))
  5263. alist ""))
  5264. (efforts (org-split-string
  5265. (or (cdr (assoc (concat org-effort-property "_ALL")
  5266. org-global-properties))
  5267. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5268. (effort-op org-agenda-filter-effort-default-operator)
  5269. (effort-prompt "")
  5270. (inhibit-read-only t)
  5271. (current org-agenda-filter)
  5272. a n tag)
  5273. (unless char
  5274. (message
  5275. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5276. (if narrow "Narrow" "Filter") tag-chars
  5277. (if org-agenda-auto-exclude-function "[RET], " ""))
  5278. (setq char (read-char)))
  5279. (when (member char '(?+ ?-))
  5280. ;; Narrowing down
  5281. (cond ((equal char ?-) (setq strip t narrow t))
  5282. ((equal char ?+) (setq strip nil narrow t)))
  5283. (message
  5284. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5285. (setq char (read-char)))
  5286. (when (member char '(?< ?> ?= ??))
  5287. ;; An effort operator
  5288. (setq effort-op (char-to-string char))
  5289. (setq alist nil) ; to make sure it will be interpreted as effort.
  5290. (unless (equal char ??)
  5291. (loop for i from 0 to 9 do
  5292. (setq effort-prompt
  5293. (concat
  5294. effort-prompt " ["
  5295. (if (= i 9) "0" (int-to-string (1+ i)))
  5296. "]" (nth i efforts))))
  5297. (message "Effort%s: %s " effort-op effort-prompt)
  5298. (setq char (read-char))
  5299. (when (or (< char ?0) (> char ?9))
  5300. (error "Need 1-9,0 to select effort" ))))
  5301. (when (equal char ?\t)
  5302. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5303. (org-set-local 'org-global-tags-completion-table
  5304. (org-global-tags-completion-table)))
  5305. (let ((completion-ignore-case t))
  5306. (setq tag (org-icompleting-read
  5307. "Tag: " org-global-tags-completion-table))))
  5308. (cond
  5309. ((equal char ?\r)
  5310. (org-agenda-filter-by-tag-show-all)
  5311. (when org-agenda-auto-exclude-function
  5312. (setq org-agenda-filter '())
  5313. (dolist (tag (org-agenda-get-represented-tags))
  5314. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5315. (if modifier
  5316. (push modifier org-agenda-filter))))
  5317. (if (not (null org-agenda-filter))
  5318. (org-agenda-filter-apply org-agenda-filter))))
  5319. ((equal char ?/)
  5320. (org-agenda-filter-by-tag-show-all)
  5321. (when (get 'org-agenda-filter :preset-filter)
  5322. (org-agenda-filter-apply org-agenda-filter)))
  5323. ((or (equal char ?\ )
  5324. (setq a (rassoc char alist))
  5325. (and (>= char ?0) (<= char ?9)
  5326. (setq n (if (= char ?0) 9 (- char ?0 1))
  5327. tag (concat effort-op (nth n efforts))
  5328. a (cons tag nil)))
  5329. (and (= char ??)
  5330. (setq tag "?eff")
  5331. a (cons tag nil))
  5332. (and tag (setq a (cons tag nil))))
  5333. (org-agenda-filter-by-tag-show-all)
  5334. (setq tag (car a))
  5335. (setq org-agenda-filter
  5336. (cons (concat (if strip "-" "+") tag)
  5337. (if narrow current nil)))
  5338. (org-agenda-filter-apply org-agenda-filter))
  5339. (t (error "Invalid tag selection character %c" char)))))
  5340. (defun org-agenda-get-represented-tags ()
  5341. "Get a list of all tags currently represented in the agenda."
  5342. (let (p tags)
  5343. (save-excursion
  5344. (goto-char (point-min))
  5345. (while (setq p (next-single-property-change (point) 'tags))
  5346. (goto-char p)
  5347. (mapc (lambda (x) (add-to-list 'tags x))
  5348. (get-text-property (point) 'tags))))
  5349. tags))
  5350. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5351. "Refine the current filter. See `org-agenda-filter-by-tag."
  5352. (interactive "P")
  5353. (org-agenda-filter-by-tag strip char 'refine))
  5354. (defun org-agenda-filter-make-matcher ()
  5355. "Create the form that tests a line for the agenda filter."
  5356. (let (f f1)
  5357. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5358. org-agenda-filter))
  5359. (if (member x '("-" "+"))
  5360. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5361. (if (string-match "[<=>?]" x)
  5362. (setq f1 (org-agenda-filter-effort-form x))
  5363. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5364. (if (equal (string-to-char x) ?-)
  5365. (setq f1 (list 'not f1))))
  5366. (push f1 f))
  5367. (cons 'and (nreverse f))))
  5368. (defun org-agenda-filter-effort-form (e)
  5369. "Return the form to compare the effort of the current line with what E says.
  5370. E looks like \"+<2:25\"."
  5371. (let (op)
  5372. (setq e (substring e 1))
  5373. (setq op (string-to-char e) e (substring e 1))
  5374. (setq op (cond ((equal op ?<) '<=)
  5375. ((equal op ?>) '>=)
  5376. ((equal op ??) op)
  5377. (t '=)))
  5378. (list 'org-agenda-compare-effort (list 'quote op)
  5379. (org-hh:mm-string-to-minutes e))))
  5380. (defun org-agenda-compare-effort (op value)
  5381. "Compare the effort of the current line with VALUE, using OP.
  5382. If the line does not have an effort defined, return nil."
  5383. (let ((eff (org-get-at-bol 'effort-minutes)))
  5384. (if (equal op ??)
  5385. (not eff)
  5386. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5387. value))))
  5388. (defun org-agenda-filter-apply (filter)
  5389. "Set FILTER as the new agenda filter and apply it."
  5390. (let (tags)
  5391. (setq org-agenda-filter filter
  5392. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5393. (org-agenda-set-mode-name)
  5394. (save-excursion
  5395. (goto-char (point-min))
  5396. (while (not (eobp))
  5397. (if (org-get-at-bol 'org-marker)
  5398. (progn
  5399. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5400. (if (not (eval org-agenda-filter-form))
  5401. (org-agenda-filter-by-tag-hide-line))
  5402. (beginning-of-line 2))
  5403. (beginning-of-line 2))))
  5404. (if (get-char-property (point) 'invisible)
  5405. (org-agenda-previous-line))))
  5406. (defun org-agenda-filter-by-tag-hide-line ()
  5407. (let (ov)
  5408. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5409. (point-at-eol)))
  5410. (overlay-put ov 'invisible t)
  5411. (overlay-put ov 'type 'tags-filter)
  5412. (push ov org-agenda-filter-overlays)))
  5413. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5414. (setq pos (or pos (point)))
  5415. (save-excursion
  5416. (dolist (ov (overlays-at pos))
  5417. (when (and (overlay-get ov 'invisible)
  5418. (eq (overlay-get ov 'type) 'tags-filter))
  5419. (goto-char pos)
  5420. (if (< (overlay-start ov) (point-at-eol))
  5421. (move-overlay ov (point-at-eol)
  5422. (overlay-end ov)))))))
  5423. (defun org-agenda-filter-by-tag-show-all ()
  5424. (mapc 'delete-overlay org-agenda-filter-overlays)
  5425. (setq org-agenda-filter-overlays nil)
  5426. (setq org-agenda-filter nil)
  5427. (setq org-agenda-filter-form nil)
  5428. (org-agenda-set-mode-name))
  5429. (defun org-agenda-manipulate-query-add ()
  5430. "Manipulate the query by adding a search term with positive selection.
  5431. Positive selection means the term must be matched for selection of an entry."
  5432. (interactive)
  5433. (org-agenda-manipulate-query ?\[))
  5434. (defun org-agenda-manipulate-query-subtract ()
  5435. "Manipulate the query by adding a search term with negative selection.
  5436. Negative selection means term must not be matched for selection of an entry."
  5437. (interactive)
  5438. (org-agenda-manipulate-query ?\]))
  5439. (defun org-agenda-manipulate-query-add-re ()
  5440. "Manipulate the query by adding a search regexp with positive selection.
  5441. Positive selection means the regexp must match for selection of an entry."
  5442. (interactive)
  5443. (org-agenda-manipulate-query ?\{))
  5444. (defun org-agenda-manipulate-query-subtract-re ()
  5445. "Manipulate the query by adding a search regexp with negative selection.
  5446. Negative selection means regexp must not match for selection of an entry."
  5447. (interactive)
  5448. (org-agenda-manipulate-query ?\}))
  5449. (defun org-agenda-manipulate-query (char)
  5450. (cond
  5451. ((memq org-agenda-type '(timeline agenda))
  5452. (let ((org-agenda-include-inactive-timestamps t))
  5453. (org-agenda-redo))
  5454. (message "Display now includes inactive timestamps as well"))
  5455. ((eq org-agenda-type 'search)
  5456. (org-add-to-string
  5457. 'org-agenda-query-string
  5458. (if org-agenda-last-search-view-search-was-boolean
  5459. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5460. (?\{ . " +{}") (?\} . " -{}"))))
  5461. " "))
  5462. (setq org-agenda-redo-command
  5463. (list 'org-search-view
  5464. org-todo-only
  5465. org-agenda-query-string
  5466. (+ (length org-agenda-query-string)
  5467. (if (member char '(?\{ ?\})) 0 1))))
  5468. (set-register org-agenda-query-register org-agenda-query-string)
  5469. (org-agenda-redo))
  5470. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5471. org-agenda-type))))
  5472. (defun org-add-to-string (var string)
  5473. (set var (concat (symbol-value var) string)))
  5474. (defun org-agenda-goto-date (date)
  5475. "Jump to DATE in agenda."
  5476. (interactive (list (let ((org-read-date-prefer-future
  5477. (eval org-agenda-jump-prefer-future)))
  5478. (org-read-date))))
  5479. (org-agenda-list nil date))
  5480. (defun org-agenda-goto-today ()
  5481. "Go to today."
  5482. (interactive)
  5483. (org-agenda-check-type t 'timeline 'agenda)
  5484. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5485. (cond
  5486. (tdpos (goto-char tdpos))
  5487. ((eq org-agenda-type 'agenda)
  5488. (let* ((sd (time-to-days
  5489. (time-subtract (current-time)
  5490. (list 0 (* 3600 org-extend-today-until) 0))))
  5491. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5492. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5493. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5494. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5495. (org-agenda-redo)
  5496. (org-agenda-find-same-or-today-or-agenda)))
  5497. (t (error "Cannot find today")))))
  5498. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5499. (goto-char
  5500. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5501. (text-property-any (point-min) (point-max) 'org-today t)
  5502. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5503. (point-min))))
  5504. (defun org-agenda-later (arg)
  5505. "Go forward in time by thee current span.
  5506. With prefix ARG, go forward that many times the current span."
  5507. (interactive "p")
  5508. (org-agenda-check-type t 'agenda)
  5509. (let* ((span org-agenda-span)
  5510. (sd org-starting-day)
  5511. (greg (calendar-gregorian-from-absolute sd))
  5512. (cnt (org-get-at-bol 'org-day-cnt))
  5513. greg2 nd)
  5514. (cond
  5515. ((eq span 'day)
  5516. (setq sd (+ arg sd) nd 1))
  5517. ((eq span 'week)
  5518. (setq sd (+ (* 7 arg) sd) nd 7))
  5519. ((eq span 'month)
  5520. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5521. sd (calendar-absolute-from-gregorian greg2))
  5522. (setcar greg2 (1+ (car greg2)))
  5523. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5524. ((eq span 'year)
  5525. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5526. sd (calendar-absolute-from-gregorian greg2))
  5527. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5528. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5529. (let ((org-agenda-overriding-arguments
  5530. (list (car org-agenda-last-arguments) sd nd t)))
  5531. (org-agenda-redo)
  5532. (org-agenda-find-same-or-today-or-agenda cnt))))
  5533. (defun org-agenda-earlier (arg)
  5534. "Go backward in time by the current span.
  5535. With prefix ARG, go backward that many times the current span."
  5536. (interactive "p")
  5537. (org-agenda-later (- arg)))
  5538. (defun org-agenda-view-mode-dispatch ()
  5539. "Call one of the view mode commands."
  5540. (interactive)
  5541. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5542. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5543. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5544. (let ((a (read-char-exclusive)))
  5545. (case a
  5546. (?d (call-interactively 'org-agenda-day-view))
  5547. (?w (call-interactively 'org-agenda-week-view))
  5548. (?m (call-interactively 'org-agenda-month-view))
  5549. (?y (call-interactively 'org-agenda-year-view))
  5550. (?l (call-interactively 'org-agenda-log-mode))
  5551. (?L (org-agenda-log-mode '(4)))
  5552. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5553. (?a (call-interactively 'org-agenda-archives-mode))
  5554. (?A (org-agenda-archives-mode 'files))
  5555. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5556. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5557. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5558. (?D (call-interactively 'org-agenda-toggle-diary))
  5559. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5560. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5561. (org-agenda-check-type t 'timeline 'agenda)
  5562. (org-agenda-redo))
  5563. (message "Display now includes inactive timestamps as well"))
  5564. (?q (message "Abort"))
  5565. (otherwise (error "Invalid key" )))))
  5566. (defun org-agenda-day-view (&optional day-of-year)
  5567. "Switch to daily view for agenda.
  5568. With argument DAY-OF-YEAR, switch to that day of the year."
  5569. (interactive "P")
  5570. (setq org-agenda-ndays 1)
  5571. (org-agenda-change-time-span 'day day-of-year))
  5572. (defun org-agenda-week-view (&optional iso-week)
  5573. "Switch to daily view for agenda.
  5574. With argument ISO-WEEK, switch to the corresponding ISO week.
  5575. If ISO-WEEK has more then 2 digits, only the last two encode the
  5576. week. Any digits before this encode a year. So 200712 means
  5577. week 12 of year 2007. Years in the range 1938-2037 can also be
  5578. written as 2-digit years."
  5579. (interactive "P")
  5580. (setq org-agenda-ndays 7)
  5581. (org-agenda-change-time-span 'week iso-week))
  5582. (defun org-agenda-month-view (&optional month)
  5583. "Switch to monthly view for agenda.
  5584. With argument MONTH, switch to that month."
  5585. (interactive "P")
  5586. (org-agenda-change-time-span 'month month))
  5587. (defun org-agenda-year-view (&optional year)
  5588. "Switch to yearly view for agenda.
  5589. With argument YEAR, switch to that year.
  5590. If MONTH has more then 2 digits, only the last two encode the
  5591. month. Any digits before this encode a year. So 200712 means
  5592. December year 2007. Years in the range 1938-2037 can also be
  5593. written as 2-digit years."
  5594. (interactive "P")
  5595. (when year
  5596. (setq year (org-small-year-to-year year)))
  5597. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5598. (org-agenda-change-time-span 'year year)
  5599. (error "Abort")))
  5600. (defun org-agenda-change-time-span (span &optional n)
  5601. "Change the agenda view to SPAN.
  5602. SPAN may be `day', `week', `month', `year'."
  5603. (org-agenda-check-type t 'agenda)
  5604. (if (and (not n) (equal org-agenda-span span))
  5605. (error "Viewing span is already \"%s\"" span))
  5606. (let* ((sd (or (org-get-at-bol 'day)
  5607. org-starting-day))
  5608. (computed (org-agenda-compute-time-span sd span n))
  5609. (org-agenda-overriding-arguments
  5610. (list (car org-agenda-last-arguments)
  5611. (car computed) (cdr computed) t)))
  5612. (org-agenda-redo)
  5613. (org-agenda-find-same-or-today-or-agenda))
  5614. (org-agenda-set-mode-name)
  5615. (message "Switched to %s view" span))
  5616. (defun org-agenda-compute-time-span (sd span &optional n)
  5617. "Compute starting date and number of days for agenda.
  5618. SPAN may be `day', `week', `month', `year'. The return value
  5619. is a cons cell with the starting date and the number of days,
  5620. so that the date SD will be in that range."
  5621. (let* ((greg (calendar-gregorian-from-absolute sd))
  5622. (dg (nth 1 greg))
  5623. (mg (car greg))
  5624. (yg (nth 2 greg))
  5625. nd w1 y1 m1 thisweek)
  5626. (cond
  5627. ((eq span 'day)
  5628. (when n
  5629. (setq sd (+ (calendar-absolute-from-gregorian
  5630. (list mg 1 yg))
  5631. n -1)))
  5632. (setq nd 1))
  5633. ((eq span 'week)
  5634. (let* ((nt (calendar-day-of-week
  5635. (calendar-gregorian-from-absolute sd)))
  5636. (d (if org-agenda-start-on-weekday
  5637. (- nt org-agenda-start-on-weekday)
  5638. 0)))
  5639. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5640. (when n
  5641. (require 'cal-iso)
  5642. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5643. (when (> n 99)
  5644. (setq y1 (org-small-year-to-year (/ n 100))
  5645. n (mod n 100)))
  5646. (setq sd
  5647. (calendar-absolute-from-iso
  5648. (list n 1
  5649. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5650. (setq nd 7)))
  5651. ((eq span 'month)
  5652. (when (and n (> n 99))
  5653. (setq y1 (org-small-year-to-year (/ n 100))
  5654. n (mod n 100)))
  5655. (setq sd (calendar-absolute-from-gregorian
  5656. (list (or n mg) 1 (or y1 yg)))
  5657. nd (- (calendar-absolute-from-gregorian
  5658. (list (1+ (or n mg)) 1 (or y1 yg)))
  5659. sd)))
  5660. ((eq span 'year)
  5661. (setq sd (calendar-absolute-from-gregorian
  5662. (list 1 1 (or n yg)))
  5663. nd (- (calendar-absolute-from-gregorian
  5664. (list 1 1 (1+ (or n yg))))
  5665. sd))))
  5666. (cons sd nd)))
  5667. (defun org-agenda-next-date-line (&optional arg)
  5668. "Jump to the next line indicating a date in agenda buffer."
  5669. (interactive "p")
  5670. (org-agenda-check-type t 'agenda 'timeline)
  5671. (beginning-of-line 1)
  5672. ;; This does not work if user makes date format that starts with a blank
  5673. (if (looking-at "^\\S-") (forward-char 1))
  5674. (if (not (re-search-forward "^\\S-" nil t arg))
  5675. (progn
  5676. (backward-char 1)
  5677. (error "No next date after this line in this buffer")))
  5678. (goto-char (match-beginning 0)))
  5679. (defun org-agenda-previous-date-line (&optional arg)
  5680. "Jump to the previous line indicating a date in agenda buffer."
  5681. (interactive "p")
  5682. (org-agenda-check-type t 'agenda 'timeline)
  5683. (beginning-of-line 1)
  5684. (if (not (re-search-backward "^\\S-" nil t arg))
  5685. (error "No previous date before this line in this buffer")))
  5686. ;; Initialize the highlight
  5687. (defvar org-hl (make-overlay 1 1))
  5688. (overlay-put org-hl 'face 'highlight)
  5689. (defun org-highlight (begin end &optional buffer)
  5690. "Highlight a region with overlay."
  5691. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5692. (defun org-unhighlight ()
  5693. "Detach overlay INDEX."
  5694. (org-detach-overlay org-hl))
  5695. ;; FIXME this is currently not used.
  5696. (defun org-highlight-until-next-command (beg end &optional buffer)
  5697. "Move the highlight overlay to BEG/END, remove it before the next command."
  5698. (org-highlight beg end buffer)
  5699. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5700. (defun org-unhighlight-once ()
  5701. "Remove the highlight from its position, and this function from the hook."
  5702. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5703. (org-unhighlight))
  5704. (defun org-agenda-follow-mode ()
  5705. "Toggle follow mode in an agenda buffer."
  5706. (interactive)
  5707. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5708. (org-agenda-set-mode-name)
  5709. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5710. (org-agenda-show))
  5711. (message "Follow mode is %s"
  5712. (if org-agenda-follow-mode "on" "off")))
  5713. (defun org-agenda-entry-text-mode (&optional arg)
  5714. "Toggle entry text mode in an agenda buffer."
  5715. (interactive "P")
  5716. (setq org-agenda-entry-text-mode (or (integerp arg)
  5717. (not org-agenda-entry-text-mode)))
  5718. (org-agenda-entry-text-hide)
  5719. (and org-agenda-entry-text-mode
  5720. (let ((org-agenda-entry-text-maxlines
  5721. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5722. (org-agenda-entry-text-show)))
  5723. (org-agenda-set-mode-name)
  5724. (message "Entry text mode is %s. Maximum number of lines is %d"
  5725. (if org-agenda-entry-text-mode "on" "off")
  5726. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5727. (defun org-agenda-clockreport-mode (&optional with-filter)
  5728. "Toggle clocktable mode in an agenda buffer.
  5729. With prefix arg WITH-FILTER, make the clocktable respect the current
  5730. agenda filter."
  5731. (interactive "P")
  5732. (org-agenda-check-type t 'agenda)
  5733. (if with-filter
  5734. (setq org-agenda-clockreport-mode 'with-filter)
  5735. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5736. (org-agenda-set-mode-name)
  5737. (org-agenda-redo)
  5738. (message "Clocktable mode is %s"
  5739. (if org-agenda-clockreport-mode "on" "off")))
  5740. (defun org-agenda-log-mode (&optional special)
  5741. "Toggle log mode in an agenda buffer.
  5742. With argument SPECIAL, show all possible log items, not only the ones
  5743. configured in `org-agenda-log-mode-items'.
  5744. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5745. (interactive "P")
  5746. (org-agenda-check-type t 'agenda 'timeline)
  5747. (setq org-agenda-show-log
  5748. (if (equal special '(16))
  5749. 'only
  5750. (if special '(closed clock state)
  5751. (not org-agenda-show-log))))
  5752. (org-agenda-set-mode-name)
  5753. (org-agenda-redo)
  5754. (message "Log mode is %s"
  5755. (if org-agenda-show-log "on" "off")))
  5756. (defun org-agenda-archives-mode (&optional with-files)
  5757. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5758. When called with a prefix argument, include all archive files as well."
  5759. (interactive "P")
  5760. (setq org-agenda-archives-mode
  5761. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5762. (org-agenda-set-mode-name)
  5763. (org-agenda-redo)
  5764. (message
  5765. "%s"
  5766. (cond
  5767. ((eq org-agenda-archives-mode nil)
  5768. "No archives are included")
  5769. ((eq org-agenda-archives-mode 'trees)
  5770. (format "Trees with :%s: tag are included" org-archive-tag))
  5771. ((eq org-agenda-archives-mode t)
  5772. (format "Trees with :%s: tag and all active archive files are included"
  5773. org-archive-tag)))))
  5774. (defun org-agenda-toggle-diary ()
  5775. "Toggle diary inclusion in an agenda buffer."
  5776. (interactive)
  5777. (org-agenda-check-type t 'agenda)
  5778. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5779. (org-agenda-redo)
  5780. (org-agenda-set-mode-name)
  5781. (message "Diary inclusion turned %s"
  5782. (if org-agenda-include-diary "on" "off")))
  5783. (defun org-agenda-toggle-deadlines ()
  5784. "Toggle diary inclusion in an agenda buffer."
  5785. (interactive)
  5786. (org-agenda-check-type t 'agenda)
  5787. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5788. (org-agenda-redo)
  5789. (org-agenda-set-mode-name)
  5790. (message "Deadlines inclusion turned %s"
  5791. (if org-agenda-include-deadlines "on" "off")))
  5792. (defun org-agenda-toggle-time-grid ()
  5793. "Toggle time grid in an agenda buffer."
  5794. (interactive)
  5795. (org-agenda-check-type t 'agenda)
  5796. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5797. (org-agenda-redo)
  5798. (org-agenda-set-mode-name)
  5799. (message "Time-grid turned %s"
  5800. (if org-agenda-use-time-grid "on" "off")))
  5801. (defun org-agenda-set-mode-name ()
  5802. "Set the mode name to indicate all the small mode settings."
  5803. (setq mode-name
  5804. (concat "Org-Agenda"
  5805. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5806. (if (equal org-agenda-ndays 1) " Day" "")
  5807. (if (equal org-agenda-ndays 7) " Week" "")
  5808. (if org-agenda-follow-mode " Follow" "")
  5809. (if org-agenda-entry-text-mode " ETxt" "")
  5810. (if org-agenda-include-diary " Diary" "")
  5811. (if org-agenda-include-deadlines " Ddl" "")
  5812. (if org-agenda-use-time-grid " Grid" "")
  5813. (if (and (boundp 'org-habit-show-habits)
  5814. org-habit-show-habits) " Habit" "")
  5815. (if (consp org-agenda-show-log) " LogAll"
  5816. (if org-agenda-show-log " Log" ""))
  5817. (if (or org-agenda-filter (get 'org-agenda-filter
  5818. :preset-filter))
  5819. (concat " {" (mapconcat
  5820. 'identity
  5821. (append (get 'org-agenda-filter
  5822. :preset-filter)
  5823. org-agenda-filter) "") "}")
  5824. "")
  5825. (if org-agenda-archives-mode
  5826. (if (eq org-agenda-archives-mode t)
  5827. " Archives"
  5828. (format " :%s:" org-archive-tag))
  5829. "")
  5830. (if org-agenda-clockreport-mode
  5831. (if (eq org-agenda-clockreport-mode 'with-filter)
  5832. " Clock{}" " Clock")
  5833. "")))
  5834. (force-mode-line-update))
  5835. (defun org-agenda-post-command-hook ()
  5836. (setq org-agenda-type
  5837. (or (get-text-property (point) 'org-agenda-type)
  5838. (get-text-property (max (point-min) (1- (point)))
  5839. 'org-agenda-type))))
  5840. (defun org-agenda-next-line ()
  5841. "Move cursor to the next line, and show if follow mode is active."
  5842. (interactive)
  5843. (call-interactively 'next-line)
  5844. (org-agenda-do-context-action))
  5845. (defun org-agenda-previous-line ()
  5846. "Move cursor to the previous line, and show if follow-mode is active."
  5847. (interactive)
  5848. (call-interactively 'previous-line)
  5849. (org-agenda-do-context-action))
  5850. (defun org-agenda-do-context-action ()
  5851. "Show outline path and, maybe, follow mode window."
  5852. (let ((m (org-get-at-bol 'org-marker)))
  5853. (if (and org-agenda-follow-mode m)
  5854. (org-agenda-show))
  5855. (if (and m org-agenda-show-outline-path)
  5856. (org-with-point-at m
  5857. (org-display-outline-path t)))))
  5858. (defun org-agenda-show-priority ()
  5859. "Show the priority of the current item.
  5860. This priority is composed of the main priority given with the [#A] cookies,
  5861. and by additional input from the age of a schedules or deadline entry."
  5862. (interactive)
  5863. (let* ((pri (org-get-at-bol 'priority)))
  5864. (message "Priority is %d" (if pri pri -1000))))
  5865. (defun org-agenda-show-tags ()
  5866. "Show the tags applicable to the current item."
  5867. (interactive)
  5868. (let* ((tags (org-get-at-bol 'tags)))
  5869. (if tags
  5870. (message "Tags are :%s:"
  5871. (org-no-properties (mapconcat 'identity tags ":")))
  5872. (message "No tags associated with this line"))))
  5873. (defun org-agenda-goto (&optional highlight)
  5874. "Go to the Org-mode file which contains the item at point."
  5875. (interactive)
  5876. (let* ((marker (or (org-get-at-bol 'org-marker)
  5877. (org-agenda-error)))
  5878. (buffer (marker-buffer marker))
  5879. (pos (marker-position marker)))
  5880. (switch-to-buffer-other-window buffer)
  5881. (widen)
  5882. (push-mark)
  5883. (goto-char pos)
  5884. (when (org-mode-p)
  5885. (org-show-context 'agenda)
  5886. (save-excursion
  5887. (and (outline-next-heading)
  5888. (org-flag-heading nil)))) ; show the next heading
  5889. (recenter (/ (window-height) 2))
  5890. (run-hooks 'org-agenda-after-show-hook)
  5891. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5892. (defvar org-agenda-after-show-hook nil
  5893. "Normal hook run after an item has been shown from the agenda.
  5894. Point is in the buffer where the item originated.")
  5895. (defun org-agenda-kill ()
  5896. "Kill the entry or subtree belonging to the current agenda entry."
  5897. (interactive)
  5898. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5899. (let* ((marker (or (org-get-at-bol 'org-marker)
  5900. (org-agenda-error)))
  5901. (buffer (marker-buffer marker))
  5902. (pos (marker-position marker))
  5903. (type (org-get-at-bol 'type))
  5904. dbeg dend (n 0) conf)
  5905. (org-with-remote-undo buffer
  5906. (with-current-buffer buffer
  5907. (save-excursion
  5908. (goto-char pos)
  5909. (if (and (org-mode-p) (not (member type '("sexp"))))
  5910. (setq dbeg (progn (org-back-to-heading t) (point))
  5911. dend (org-end-of-subtree t t))
  5912. (setq dbeg (point-at-bol)
  5913. dend (min (point-max) (1+ (point-at-eol)))))
  5914. (goto-char dbeg)
  5915. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5916. (setq conf (or (eq t org-agenda-confirm-kill)
  5917. (and (numberp org-agenda-confirm-kill)
  5918. (> n org-agenda-confirm-kill))))
  5919. (and conf
  5920. (not (y-or-n-p
  5921. (format "Delete entry with %d lines in buffer \"%s\"? "
  5922. n (buffer-name buffer))))
  5923. (error "Abort"))
  5924. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5925. (with-current-buffer buffer (delete-region dbeg dend))
  5926. (message "Agenda item and source killed"))))
  5927. (defvar org-archive-default-command)
  5928. (defun org-agenda-archive-default ()
  5929. "Archive the entry or subtree belonging to the current agenda entry."
  5930. (interactive)
  5931. (require 'org-archive)
  5932. (org-agenda-archive-with org-archive-default-command))
  5933. (defun org-agenda-archive-default-with-confirmation ()
  5934. "Archive the entry or subtree belonging to the current agenda entry."
  5935. (interactive)
  5936. (require 'org-archive)
  5937. (org-agenda-archive-with org-archive-default-command 'confirm))
  5938. (defun org-agenda-archive ()
  5939. "Archive the entry or subtree belonging to the current agenda entry."
  5940. (interactive)
  5941. (org-agenda-archive-with 'org-archive-subtree))
  5942. (defun org-agenda-archive-to-archive-sibling ()
  5943. "Move the entry to the archive sibling."
  5944. (interactive)
  5945. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5946. (defun org-agenda-archive-with (cmd &optional confirm)
  5947. "Move the entry to the archive sibling."
  5948. (interactive)
  5949. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5950. (let* ((marker (or (org-get-at-bol 'org-marker)
  5951. (org-agenda-error)))
  5952. (buffer (marker-buffer marker))
  5953. (pos (marker-position marker)))
  5954. (org-with-remote-undo buffer
  5955. (with-current-buffer buffer
  5956. (if (org-mode-p)
  5957. (if (and confirm
  5958. (not (y-or-n-p "Archive this subtree or entry? ")))
  5959. (error "Abort")
  5960. (save-excursion
  5961. (goto-char pos)
  5962. (org-remove-subtree-entries-from-agenda)
  5963. (org-back-to-heading t)
  5964. (funcall cmd)))
  5965. (error "Archiving works only in Org-mode files"))))))
  5966. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5967. "Remove all lines in the agenda that correspond to a given subtree.
  5968. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5969. If this information is not given, the function uses the tree at point."
  5970. (let ((buf (or buf (current-buffer))) m p)
  5971. (save-excursion
  5972. (unless (and beg end)
  5973. (org-back-to-heading t)
  5974. (setq beg (point))
  5975. (org-end-of-subtree t)
  5976. (setq end (point)))
  5977. (set-buffer (get-buffer org-agenda-buffer-name))
  5978. (save-excursion
  5979. (goto-char (point-max))
  5980. (beginning-of-line 1)
  5981. (while (not (bobp))
  5982. (when (and (setq m (org-get-at-bol 'org-marker))
  5983. (equal buf (marker-buffer m))
  5984. (setq p (marker-position m))
  5985. (>= p beg)
  5986. (< p end))
  5987. (let ((inhibit-read-only t))
  5988. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5989. (beginning-of-line 0))))))
  5990. (defun org-agenda-refile (&optional goto rfloc no-update)
  5991. "Refile the item at point."
  5992. (interactive "P")
  5993. (if (equal goto '(16))
  5994. (org-refile-goto-last-stored)
  5995. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5996. (org-agenda-error)))
  5997. (buffer (marker-buffer marker))
  5998. (pos (marker-position marker))
  5999. (rfloc (or rfloc
  6000. (org-refile-get-location
  6001. (if goto "Goto: " "Refile to: ") buffer
  6002. org-refile-allow-creating-parent-nodes))))
  6003. (with-current-buffer buffer
  6004. (save-excursion
  6005. (save-restriction
  6006. (widen)
  6007. (goto-char marker)
  6008. (org-remove-subtree-entries-from-agenda)
  6009. (org-refile goto buffer rfloc)))))
  6010. (unless no-update (org-agenda-redo))))
  6011. (defun org-agenda-open-link (&optional arg)
  6012. "Follow the link in the current line, if any.
  6013. This looks for a link in the displayed line in the agenda. It also looks
  6014. at the text of the entry itself."
  6015. (interactive "P")
  6016. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6017. (org-get-at-bol 'org-marker)))
  6018. (buffer (and marker (marker-buffer marker)))
  6019. (prefix (buffer-substring
  6020. (point-at-bol)
  6021. (+ (point-at-bol)
  6022. (or (org-get-at-bol 'prefix-length) 0)))))
  6023. (cond
  6024. (buffer
  6025. (with-current-buffer buffer
  6026. (save-excursion
  6027. (save-restriction
  6028. (widen)
  6029. (goto-char marker)
  6030. (org-offer-links-in-entry arg prefix)))))
  6031. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6032. (save-excursion
  6033. (beginning-of-line 1)
  6034. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6035. (org-open-link-from-string (match-string 1)))
  6036. (t (error "No link to open here")))))
  6037. (defun org-agenda-copy-local-variable (var)
  6038. "Get a variable from a referenced buffer and install it here."
  6039. (let ((m (org-get-at-bol 'org-marker)))
  6040. (when (and m (buffer-live-p (marker-buffer m)))
  6041. (org-set-local var (with-current-buffer (marker-buffer m)
  6042. (symbol-value var))))))
  6043. (defun org-agenda-switch-to (&optional delete-other-windows)
  6044. "Go to the Org-mode file which contains the item at point."
  6045. (interactive)
  6046. (if (and org-return-follows-link
  6047. (not (org-get-at-bol 'org-marker))
  6048. (org-in-regexp org-bracket-link-regexp))
  6049. (org-open-link-from-string (match-string 0))
  6050. (let* ((marker (or (org-get-at-bol 'org-marker)
  6051. (org-agenda-error)))
  6052. (buffer (marker-buffer marker))
  6053. (pos (marker-position marker)))
  6054. (switch-to-buffer buffer)
  6055. (and delete-other-windows (delete-other-windows))
  6056. (widen)
  6057. (goto-char pos)
  6058. (when (org-mode-p)
  6059. (org-show-context 'agenda)
  6060. (save-excursion
  6061. (and (outline-next-heading)
  6062. (org-flag-heading nil))))))) ; show the next heading
  6063. (defun org-agenda-goto-mouse (ev)
  6064. "Go to the Org-mode file which contains the item at the mouse click."
  6065. (interactive "e")
  6066. (mouse-set-point ev)
  6067. (org-agenda-goto))
  6068. (defun org-agenda-show (&optional full-entry)
  6069. "Display the Org-mode file which contains the item at point.
  6070. With prefix argument FULL-ENTRY, make the entire entry visible
  6071. if it was hidden in the outline."
  6072. (interactive "P")
  6073. (let ((win (selected-window)))
  6074. (if full-entry
  6075. (let ((org-show-entry-below t))
  6076. (org-agenda-goto t))
  6077. (org-agenda-goto t))
  6078. (select-window win)))
  6079. (defvar org-agenda-show-window nil)
  6080. (defun org-agenda-show-and-scroll-up ()
  6081. "Display the Org-mode file which contains the item at point.
  6082. When called repeatedly, scroll the window that is displaying the buffer."
  6083. (interactive)
  6084. (let ((win (selected-window)))
  6085. (if (and (window-live-p org-agenda-show-window)
  6086. (eq this-command last-command))
  6087. (progn
  6088. (select-window org-agenda-show-window)
  6089. (ignore-errors (scroll-up)))
  6090. (org-agenda-goto t)
  6091. (show-subtree)
  6092. (setq org-agenda-show-window (selected-window)))
  6093. (select-window win)))
  6094. (defun org-agenda-show-scroll-down ()
  6095. "Scroll down the window showing the agenda."
  6096. (interactive)
  6097. (let ((win (selected-window)))
  6098. (when (window-live-p org-agenda-show-window)
  6099. (select-window org-agenda-show-window)
  6100. (ignore-errors (scroll-down))
  6101. (select-window win))))
  6102. (defun org-agenda-show-1 (&optional more)
  6103. "Display the Org-mode file which contains the item at point.
  6104. The prefix arg selects the amount of information to display:
  6105. 0 hide the subtree
  6106. 1 just show the entry according to defaults.
  6107. 2 show the children view
  6108. 3 show the subtree view
  6109. 4 show the entire subtree and any LOGBOOK drawers
  6110. 5 show the entire subtree and any drawers
  6111. With prefix argument FULL-ENTRY, make the entire entry visible
  6112. if it was hidden in the outline."
  6113. (interactive "p")
  6114. (let ((win (selected-window)))
  6115. (org-agenda-goto t)
  6116. (org-recenter-heading 1)
  6117. (cond
  6118. ((= more 0)
  6119. (hide-subtree)
  6120. (save-excursion
  6121. (org-back-to-heading)
  6122. (run-hook-with-args 'org-cycle-hook 'folded))
  6123. (message "Remote: FOLDED"))
  6124. ((and (interactive-p) (= more 1))
  6125. (message "Remote: show with default settings"))
  6126. ((= more 2)
  6127. (show-entry)
  6128. (show-children)
  6129. (save-excursion
  6130. (org-back-to-heading)
  6131. (run-hook-with-args 'org-cycle-hook 'children))
  6132. (message "Remote: CHILDREN"))
  6133. ((= more 3)
  6134. (show-subtree)
  6135. (save-excursion
  6136. (org-back-to-heading)
  6137. (run-hook-with-args 'org-cycle-hook 'subtree))
  6138. (message "Remote: SUBTREE"))
  6139. ((= more 4)
  6140. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6141. (org-drawer-regexp
  6142. (concat "^[ \t]*:\\("
  6143. (mapconcat 'regexp-quote org-drawers "\\|")
  6144. "\\):[ \t]*$")))
  6145. (show-subtree)
  6146. (save-excursion
  6147. (org-back-to-heading)
  6148. (org-cycle-hide-drawers 'subtree)))
  6149. (message "Remote: SUBTREE AND LOGBOOK"))
  6150. ((> more 4)
  6151. (show-subtree)
  6152. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6153. (select-window win)))
  6154. (defun org-recenter-heading (n)
  6155. (save-excursion
  6156. (org-back-to-heading)
  6157. (recenter n)))
  6158. (defvar org-agenda-cycle-counter nil)
  6159. (defun org-agenda-cycle-show (&optional n)
  6160. "Show the current entry in another window, with default settings.
  6161. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6162. When use repeatedly in immediate succession, the remote entry will cycle
  6163. through visibility
  6164. children -> subtree -> folded
  6165. When called with a numeric prefix arg, that arg will be passed through to
  6166. `org-agenda-show-1'. For the interpretation of that argument, see the
  6167. docstring of `org-agenda-show-1'."
  6168. (interactive "P")
  6169. (if (integerp n)
  6170. (setq org-agenda-cycle-counter n)
  6171. (if (not (eq last-command this-command))
  6172. (setq org-agenda-cycle-counter 1)
  6173. (if (equal org-agenda-cycle-counter 0)
  6174. (setq org-agenda-cycle-counter 2)
  6175. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6176. (if (> org-agenda-cycle-counter 3)
  6177. (setq org-agenda-cycle-counter 0)))))
  6178. (org-agenda-show-1 org-agenda-cycle-counter))
  6179. (defun org-agenda-recenter (arg)
  6180. "Display the Org-mode file which contains the item at point and recenter."
  6181. (interactive "P")
  6182. (let ((win (selected-window)))
  6183. (org-agenda-goto t)
  6184. (recenter arg)
  6185. (select-window win)))
  6186. (defun org-agenda-show-mouse (ev)
  6187. "Display the Org-mode file which contains the item at the mouse click."
  6188. (interactive "e")
  6189. (mouse-set-point ev)
  6190. (org-agenda-show))
  6191. (defun org-agenda-check-no-diary ()
  6192. "Check if the entry is a diary link and abort if yes."
  6193. (if (org-get-at-bol 'org-agenda-diary-link)
  6194. (org-agenda-error)))
  6195. (defun org-agenda-error ()
  6196. (error "Command not allowed in this line"))
  6197. (defun org-agenda-tree-to-indirect-buffer ()
  6198. "Show the subtree corresponding to the current entry in an indirect buffer.
  6199. This calls the command `org-tree-to-indirect-buffer' from the original
  6200. Org-mode buffer.
  6201. With numerical prefix arg ARG, go up to this level and then take that tree.
  6202. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6203. use the dedicated frame)."
  6204. (interactive)
  6205. (org-agenda-check-no-diary)
  6206. (let* ((marker (or (org-get-at-bol 'org-marker)
  6207. (org-agenda-error)))
  6208. (buffer (marker-buffer marker))
  6209. (pos (marker-position marker)))
  6210. (with-current-buffer buffer
  6211. (save-excursion
  6212. (goto-char pos)
  6213. (call-interactively 'org-tree-to-indirect-buffer)))))
  6214. (defvar org-last-heading-marker (make-marker)
  6215. "Marker pointing to the headline that last changed its TODO state
  6216. by a remote command from the agenda.")
  6217. (defun org-agenda-todo-nextset ()
  6218. "Switch TODO entry to next sequence."
  6219. (interactive)
  6220. (org-agenda-todo 'nextset))
  6221. (defun org-agenda-todo-previousset ()
  6222. "Switch TODO entry to previous sequence."
  6223. (interactive)
  6224. (org-agenda-todo 'previousset))
  6225. (defun org-agenda-todo (&optional arg)
  6226. "Cycle TODO state of line at point, also in Org-mode file.
  6227. This changes the line at point, all other lines in the agenda referring to
  6228. the same tree node, and the headline of the tree node in the Org-mode file."
  6229. (interactive "P")
  6230. (org-agenda-check-no-diary)
  6231. (let* ((col (current-column))
  6232. (marker (or (org-get-at-bol 'org-marker)
  6233. (org-agenda-error)))
  6234. (buffer (marker-buffer marker))
  6235. (pos (marker-position marker))
  6236. (hdmarker (org-get-at-bol 'org-hd-marker))
  6237. (todayp (equal (org-get-at-bol 'day)
  6238. (time-to-days (current-time))))
  6239. (inhibit-read-only t)
  6240. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6241. (org-with-remote-undo buffer
  6242. (with-current-buffer buffer
  6243. (widen)
  6244. (goto-char pos)
  6245. (org-show-context 'agenda)
  6246. (save-excursion
  6247. (and (outline-next-heading)
  6248. (org-flag-heading nil))) ; show the next heading
  6249. (let ((current-prefix-arg arg))
  6250. (call-interactively 'org-todo))
  6251. (and (bolp) (forward-char 1))
  6252. (setq newhead (org-get-heading))
  6253. (when (and (org-bound-and-true-p
  6254. org-agenda-headline-snapshot-before-repeat)
  6255. (not (equal org-agenda-headline-snapshot-before-repeat
  6256. newhead))
  6257. todayp)
  6258. (setq newhead org-agenda-headline-snapshot-before-repeat
  6259. just-one t))
  6260. (save-excursion
  6261. (org-back-to-heading)
  6262. (move-marker org-last-heading-marker (point))))
  6263. (beginning-of-line 1)
  6264. (save-excursion
  6265. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6266. (org-move-to-column col))))
  6267. (defun org-agenda-add-note (&optional arg)
  6268. "Add a time-stamped note to the entry at point."
  6269. (interactive "P")
  6270. (org-agenda-check-no-diary)
  6271. (let* ((marker (or (org-get-at-bol 'org-marker)
  6272. (org-agenda-error)))
  6273. (buffer (marker-buffer marker))
  6274. (pos (marker-position marker))
  6275. (hdmarker (org-get-at-bol 'org-hd-marker))
  6276. (inhibit-read-only t))
  6277. (with-current-buffer buffer
  6278. (widen)
  6279. (goto-char pos)
  6280. (org-show-context 'agenda)
  6281. (save-excursion
  6282. (and (outline-next-heading)
  6283. (org-flag-heading nil))) ; show the next heading
  6284. (org-add-note))))
  6285. (defun org-agenda-change-all-lines (newhead hdmarker
  6286. &optional fixface just-this)
  6287. "Change all lines in the agenda buffer which match HDMARKER.
  6288. The new content of the line will be NEWHEAD (as modified by
  6289. `org-format-agenda-item'). HDMARKER is checked with
  6290. `equal' against all `org-hd-marker' text properties in the file.
  6291. If FIXFACE is non-nil, the face of each item is modified according to
  6292. the new TODO state.
  6293. If JUST-THIS is non-nil, change just the current line, not all.
  6294. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6295. (let* ((inhibit-read-only t)
  6296. (line (org-current-line))
  6297. (thetags (with-current-buffer (marker-buffer hdmarker)
  6298. (save-excursion (save-restriction (widen)
  6299. (goto-char hdmarker)
  6300. (org-get-tags-at)))))
  6301. props m pl undone-face done-face finish new dotime cat tags)
  6302. (save-excursion
  6303. (goto-char (point-max))
  6304. (beginning-of-line 1)
  6305. (while (not finish)
  6306. (setq finish (bobp))
  6307. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6308. (or (not just-this) (= (org-current-line) line))
  6309. (equal m hdmarker))
  6310. (setq props (text-properties-at (point))
  6311. dotime (org-get-at-bol 'dotime)
  6312. cat (org-get-at-bol 'org-category)
  6313. tags thetags
  6314. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6315. pl (org-get-at-bol 'prefix-length)
  6316. undone-face (org-get-at-bol 'undone-face)
  6317. done-face (org-get-at-bol 'done-face))
  6318. (goto-char (+ (point) pl))
  6319. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6320. (cond
  6321. ((equal new "")
  6322. (beginning-of-line 1)
  6323. (and (looking-at ".*\n?") (replace-match "")))
  6324. ((looking-at ".*")
  6325. (replace-match new t t)
  6326. (beginning-of-line 1)
  6327. (add-text-properties (point-at-bol) (point-at-eol) props)
  6328. (when fixface
  6329. (add-text-properties
  6330. (point-at-bol) (point-at-eol)
  6331. (list 'face
  6332. (if org-last-todo-state-is-todo
  6333. undone-face done-face))))
  6334. (org-agenda-highlight-todo 'line)
  6335. (beginning-of-line 1))
  6336. (t (error "Line update did not work"))))
  6337. (beginning-of-line 0)))
  6338. (org-finalize-agenda)))
  6339. (defun org-agenda-align-tags (&optional line)
  6340. "Align all tags in agenda items to `org-agenda-tags-column'."
  6341. (let ((inhibit-read-only t) l c)
  6342. (save-excursion
  6343. (goto-char (if line (point-at-bol) (point-min)))
  6344. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6345. (if line (point-at-eol) nil) t)
  6346. (add-text-properties
  6347. (match-beginning 2) (match-end 2)
  6348. (list 'face (delq nil (let ((prop (get-text-property
  6349. (match-beginning 2) 'face)))
  6350. (or (listp prop) (setq prop (list prop)))
  6351. (if (memq 'org-tag prop)
  6352. prop
  6353. (cons 'org-tag prop))))))
  6354. (setq l (- (match-end 2) (match-beginning 2))
  6355. c (if (< org-agenda-tags-column 0)
  6356. (- (abs org-agenda-tags-column) l)
  6357. org-agenda-tags-column))
  6358. (delete-region (match-beginning 1) (match-end 1))
  6359. (goto-char (match-beginning 1))
  6360. (insert (org-add-props
  6361. (make-string (max 1 (- c (current-column))) ?\ )
  6362. (plist-put (copy-sequence (text-properties-at (point)))
  6363. 'face nil))))
  6364. (goto-char (point-min))
  6365. (org-font-lock-add-tag-faces (point-max)))))
  6366. (defun org-agenda-priority-up ()
  6367. "Increase the priority of line at point, also in Org-mode file."
  6368. (interactive)
  6369. (org-agenda-priority 'up))
  6370. (defun org-agenda-priority-down ()
  6371. "Decrease the priority of line at point, also in Org-mode file."
  6372. (interactive)
  6373. (org-agenda-priority 'down))
  6374. (defun org-agenda-priority (&optional force-direction)
  6375. "Set the priority of line at point, also in Org-mode file.
  6376. This changes the line at point, all other lines in the agenda referring to
  6377. the same tree node, and the headline of the tree node in the Org-mode file."
  6378. (interactive)
  6379. (unless org-enable-priority-commands
  6380. (error "Priority commands are disabled"))
  6381. (org-agenda-check-no-diary)
  6382. (let* ((marker (or (org-get-at-bol 'org-marker)
  6383. (org-agenda-error)))
  6384. (hdmarker (org-get-at-bol 'org-hd-marker))
  6385. (buffer (marker-buffer hdmarker))
  6386. (pos (marker-position hdmarker))
  6387. (inhibit-read-only t)
  6388. newhead)
  6389. (org-with-remote-undo buffer
  6390. (with-current-buffer buffer
  6391. (widen)
  6392. (goto-char pos)
  6393. (org-show-context 'agenda)
  6394. (save-excursion
  6395. (and (outline-next-heading)
  6396. (org-flag-heading nil))) ; show the next heading
  6397. (funcall 'org-priority force-direction)
  6398. (end-of-line 1)
  6399. (setq newhead (org-get-heading)))
  6400. (org-agenda-change-all-lines newhead hdmarker)
  6401. (beginning-of-line 1))))
  6402. ;; FIXME: should fix the tags property of the agenda line.
  6403. (defun org-agenda-set-tags (&optional tag onoff)
  6404. "Set tags for the current headline."
  6405. (interactive)
  6406. (org-agenda-check-no-diary)
  6407. (if (and (org-region-active-p) (interactive-p))
  6408. (call-interactively 'org-change-tag-in-region)
  6409. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6410. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6411. (org-agenda-error)))
  6412. (buffer (marker-buffer hdmarker))
  6413. (pos (marker-position hdmarker))
  6414. (inhibit-read-only t)
  6415. newhead)
  6416. (org-with-remote-undo buffer
  6417. (with-current-buffer buffer
  6418. (widen)
  6419. (goto-char pos)
  6420. (save-excursion
  6421. (org-show-context 'agenda))
  6422. (save-excursion
  6423. (and (outline-next-heading)
  6424. (org-flag-heading nil))) ; show the next heading
  6425. (goto-char pos)
  6426. (if tag
  6427. (org-toggle-tag tag onoff)
  6428. (call-interactively 'org-set-tags))
  6429. (end-of-line 1)
  6430. (setq newhead (org-get-heading)))
  6431. (org-agenda-change-all-lines newhead hdmarker)
  6432. (beginning-of-line 1)))))
  6433. (defun org-agenda-set-property ()
  6434. "Set a property for the current headline."
  6435. (interactive)
  6436. (org-agenda-check-no-diary)
  6437. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6438. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6439. (org-agenda-error)))
  6440. (buffer (marker-buffer hdmarker))
  6441. (pos (marker-position hdmarker))
  6442. (inhibit-read-only t)
  6443. newhead)
  6444. (org-with-remote-undo buffer
  6445. (with-current-buffer buffer
  6446. (widen)
  6447. (goto-char pos)
  6448. (save-excursion
  6449. (org-show-context 'agenda))
  6450. (save-excursion
  6451. (and (outline-next-heading)
  6452. (org-flag-heading nil))) ; show the next heading
  6453. (goto-char pos)
  6454. (call-interactively 'org-set-property)))))
  6455. (defun org-agenda-set-effort ()
  6456. "Set the effort property for the current headline."
  6457. (interactive)
  6458. (org-agenda-check-no-diary)
  6459. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6460. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6461. (org-agenda-error)))
  6462. (buffer (marker-buffer hdmarker))
  6463. (pos (marker-position hdmarker))
  6464. (inhibit-read-only t)
  6465. newhead)
  6466. (org-with-remote-undo buffer
  6467. (with-current-buffer buffer
  6468. (widen)
  6469. (goto-char pos)
  6470. (save-excursion
  6471. (org-show-context 'agenda))
  6472. (save-excursion
  6473. (and (outline-next-heading)
  6474. (org-flag-heading nil))) ; show the next heading
  6475. (goto-char pos)
  6476. (call-interactively 'org-set-effort)
  6477. (end-of-line 1)))))
  6478. (defun org-agenda-toggle-archive-tag ()
  6479. "Toggle the archive tag for the current entry."
  6480. (interactive)
  6481. (org-agenda-check-no-diary)
  6482. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6483. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6484. (org-agenda-error)))
  6485. (buffer (marker-buffer hdmarker))
  6486. (pos (marker-position hdmarker))
  6487. (inhibit-read-only t)
  6488. newhead)
  6489. (org-with-remote-undo buffer
  6490. (with-current-buffer buffer
  6491. (widen)
  6492. (goto-char pos)
  6493. (org-show-context 'agenda)
  6494. (save-excursion
  6495. (and (outline-next-heading)
  6496. (org-flag-heading nil))) ; show the next heading
  6497. (call-interactively 'org-toggle-archive-tag)
  6498. (end-of-line 1)
  6499. (setq newhead (org-get-heading)))
  6500. (org-agenda-change-all-lines newhead hdmarker)
  6501. (beginning-of-line 1))))
  6502. (defun org-agenda-do-date-later (arg)
  6503. (interactive "P")
  6504. (cond
  6505. ((or (equal arg '(16))
  6506. (memq last-command
  6507. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6508. (setq this-command 'org-agenda-date-later-minutes)
  6509. (org-agenda-date-later-minutes 1))
  6510. ((or (equal arg '(4))
  6511. (memq last-command
  6512. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6513. (setq this-command 'org-agenda-date-later-hours)
  6514. (org-agenda-date-later-hours 1))
  6515. (t
  6516. (org-agenda-date-later (prefix-numeric-value arg)))))
  6517. (defun org-agenda-do-date-earlier (arg)
  6518. (interactive "P")
  6519. (cond
  6520. ((or (equal arg '(16))
  6521. (memq last-command
  6522. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6523. (setq this-command 'org-agenda-date-earlier-minutes)
  6524. (org-agenda-date-earlier-minutes 1))
  6525. ((or (equal arg '(4))
  6526. (memq last-command
  6527. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6528. (setq this-command 'org-agenda-date-earlier-hours)
  6529. (org-agenda-date-earlier-hours 1))
  6530. (t
  6531. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6532. (defun org-agenda-date-later (arg &optional what)
  6533. "Change the date of this item to one day later."
  6534. (interactive "p")
  6535. (org-agenda-check-type t 'agenda 'timeline)
  6536. (org-agenda-check-no-diary)
  6537. (let* ((marker (or (org-get-at-bol 'org-marker)
  6538. (org-agenda-error)))
  6539. (buffer (marker-buffer marker))
  6540. (pos (marker-position marker)))
  6541. (org-with-remote-undo buffer
  6542. (with-current-buffer buffer
  6543. (widen)
  6544. (goto-char pos)
  6545. (if (not (org-at-timestamp-p))
  6546. (error "Cannot find time stamp"))
  6547. (org-timestamp-change arg (or what 'day)))
  6548. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6549. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6550. (defun org-agenda-date-earlier (arg &optional what)
  6551. "Change the date of this item to one day earlier."
  6552. (interactive "p")
  6553. (org-agenda-date-later (- arg) what))
  6554. (defun org-agenda-date-later-minutes (arg)
  6555. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6556. (interactive "p")
  6557. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6558. (org-agenda-date-later arg 'minute))
  6559. (defun org-agenda-date-earlier-minutes (arg)
  6560. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6561. (interactive "p")
  6562. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6563. (org-agenda-date-earlier arg 'minute))
  6564. (defun org-agenda-date-later-hours (arg)
  6565. "Change the time of this item, in hour steps."
  6566. (interactive "p")
  6567. (org-agenda-date-later arg 'hour))
  6568. (defun org-agenda-date-earlier-hours (arg)
  6569. "Change the time of this item, in hour steps."
  6570. (interactive "p")
  6571. (org-agenda-date-earlier arg 'hour))
  6572. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6573. "Show new date stamp via text properties."
  6574. ;; We use text properties to make this undoable
  6575. (let ((inhibit-read-only t)
  6576. (buffer-invisibility-spec))
  6577. (setq stamp (concat " " prefix " => " stamp))
  6578. (save-excursion
  6579. (goto-char (point-max))
  6580. (while (not (bobp))
  6581. (when (equal marker (org-get-at-bol 'org-marker))
  6582. (org-move-to-column (- (window-width) (length stamp)) t)
  6583. (org-agenda-fix-tags-filter-overlays-at (point))
  6584. (if (featurep 'xemacs)
  6585. ;; Use `duplicable' property to trigger undo recording
  6586. (let ((ex (make-extent nil nil))
  6587. (gl (make-glyph stamp)))
  6588. (set-glyph-face gl 'secondary-selection)
  6589. (set-extent-properties
  6590. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6591. (insert-extent ex (1- (point)) (point-at-eol)))
  6592. (add-text-properties
  6593. (1- (point)) (point-at-eol)
  6594. (list 'display (org-add-props stamp nil
  6595. 'face 'secondary-selection))))
  6596. (beginning-of-line 1))
  6597. (beginning-of-line 0)))))
  6598. (defun org-agenda-date-prompt (arg)
  6599. "Change the date of this item. Date is prompted for, with default today.
  6600. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6601. be used to request time specification in the time stamp."
  6602. (interactive "P")
  6603. (org-agenda-check-type t 'agenda 'timeline)
  6604. (org-agenda-check-no-diary)
  6605. (let* ((marker (or (org-get-at-bol 'org-marker)
  6606. (org-agenda-error)))
  6607. (buffer (marker-buffer marker))
  6608. (pos (marker-position marker)))
  6609. (org-with-remote-undo buffer
  6610. (with-current-buffer buffer
  6611. (widen)
  6612. (goto-char pos)
  6613. (if (not (org-at-timestamp-p t))
  6614. (error "Cannot find time stamp"))
  6615. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6616. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6617. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6618. (defun org-agenda-schedule (arg)
  6619. "Schedule the item at point.
  6620. Arg is passed through to `org-schedule'."
  6621. (interactive "P")
  6622. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6623. (org-agenda-check-no-diary)
  6624. (let* ((marker (or (org-get-at-bol 'org-marker)
  6625. (org-agenda-error)))
  6626. (type (marker-insertion-type marker))
  6627. (buffer (marker-buffer marker))
  6628. (pos (marker-position marker))
  6629. (org-insert-labeled-timestamps-at-point nil)
  6630. ts)
  6631. (set-marker-insertion-type marker t)
  6632. (org-with-remote-undo buffer
  6633. (with-current-buffer buffer
  6634. (widen)
  6635. (goto-char pos)
  6636. (setq ts (org-schedule arg)))
  6637. (org-agenda-show-new-time marker ts "S"))
  6638. (message "Item scheduled for %s" ts)))
  6639. (defun org-agenda-deadline (arg)
  6640. "Schedule the item at point.
  6641. Arg is passed through to `org-deadline'."
  6642. (interactive "P")
  6643. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6644. (org-agenda-check-no-diary)
  6645. (let* ((marker (or (org-get-at-bol 'org-marker)
  6646. (org-agenda-error)))
  6647. (buffer (marker-buffer marker))
  6648. (pos (marker-position marker))
  6649. (org-insert-labeled-timestamps-at-point nil)
  6650. ts)
  6651. (org-with-remote-undo buffer
  6652. (with-current-buffer buffer
  6653. (widen)
  6654. (goto-char pos)
  6655. (setq ts (org-deadline arg)))
  6656. (org-agenda-show-new-time marker ts "D"))
  6657. (message "Deadline for this item set to %s" ts)))
  6658. (defun org-agenda-action ()
  6659. "Select entry for agenda action, or execute an agenda action.
  6660. This command prompts for another letter. Valid inputs are:
  6661. m Mark the entry at point for an agenda action
  6662. s Schedule the marked entry to the date at the cursor
  6663. d Set the deadline of the marked entry to the date at the cursor
  6664. r Call `org-remember' with cursor date as the default date
  6665. c Call `org-capture' with cursor date as the default date
  6666. SPC Show marked entry in other window
  6667. TAB Visit marked entry in other window
  6668. The cursor may be at a date in the calendar, or in the Org agenda."
  6669. (interactive)
  6670. (let (ans)
  6671. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6672. (setq ans (read-char-exclusive))
  6673. (cond
  6674. ((equal ans ?m)
  6675. ;; Mark this entry
  6676. (if (eq major-mode 'org-agenda-mode)
  6677. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6678. (org-get-at-bol 'org-marker))))
  6679. (if m
  6680. (progn
  6681. (move-marker org-agenda-action-marker
  6682. (marker-position m) (marker-buffer m))
  6683. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6684. (error "Don't know which entry to mark")))
  6685. (error "This command works only in the agenda")))
  6686. ((equal ans ?s)
  6687. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6688. ((equal ans ?d)
  6689. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6690. ((equal ans ?r)
  6691. (org-agenda-do-action '(org-remember) t))
  6692. ((equal ans ?c)
  6693. (org-agenda-do-action '(org-capture) t))
  6694. ((equal ans ?\ )
  6695. (let ((cw (selected-window)))
  6696. (org-switch-to-buffer-other-window
  6697. (marker-buffer org-agenda-action-marker))
  6698. (goto-char org-agenda-action-marker)
  6699. (org-show-context 'agenda)
  6700. (select-window cw)))
  6701. ((equal ans ?\C-i)
  6702. (org-switch-to-buffer-other-window
  6703. (marker-buffer org-agenda-action-marker))
  6704. (goto-char org-agenda-action-marker)
  6705. (org-show-context 'agenda))
  6706. (t (error "Invalid agenda action %c" ans)))))
  6707. (defun org-agenda-do-action (form &optional current-buffer)
  6708. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6709. (let ((org-overriding-default-time (org-get-cursor-date)))
  6710. (if current-buffer
  6711. (eval form)
  6712. (if (not (marker-buffer org-agenda-action-marker))
  6713. (error "No entry has been selected for agenda action")
  6714. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6715. (save-excursion
  6716. (save-restriction
  6717. (widen)
  6718. (goto-char org-agenda-action-marker)
  6719. (eval form))))))))
  6720. (defun org-agenda-clock-in (&optional arg)
  6721. "Start the clock on the currently selected item."
  6722. (interactive "P")
  6723. (org-agenda-check-no-diary)
  6724. (if (equal arg '(4))
  6725. (org-clock-in arg)
  6726. (let* ((marker (or (org-get-at-bol 'org-marker)
  6727. (org-agenda-error)))
  6728. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6729. marker))
  6730. (pos (marker-position marker))
  6731. newhead)
  6732. (org-with-remote-undo (marker-buffer marker)
  6733. (with-current-buffer (marker-buffer marker)
  6734. (widen)
  6735. (goto-char pos)
  6736. (org-show-context 'agenda)
  6737. (org-show-entry)
  6738. (org-cycle-hide-drawers 'children)
  6739. (org-clock-in arg)
  6740. (setq newhead (org-get-heading)))
  6741. (org-agenda-change-all-lines newhead hdmarker)))))
  6742. (defun org-agenda-clock-out ()
  6743. "Stop the currently running clock."
  6744. (interactive)
  6745. (unless (marker-buffer org-clock-marker)
  6746. (error "No running clock"))
  6747. (let ((marker (make-marker)) newhead)
  6748. (org-with-remote-undo (marker-buffer org-clock-marker)
  6749. (with-current-buffer (marker-buffer org-clock-marker)
  6750. (save-excursion
  6751. (save-restriction
  6752. (widen)
  6753. (goto-char org-clock-marker)
  6754. (org-back-to-heading t)
  6755. (move-marker marker (point))
  6756. (org-clock-out)
  6757. (setq newhead (org-get-heading))))))
  6758. (org-agenda-change-all-lines newhead marker)
  6759. (move-marker marker nil)))
  6760. (defun org-agenda-clock-cancel (&optional arg)
  6761. "Cancel the currently running clock."
  6762. (interactive "P")
  6763. (unless (marker-buffer org-clock-marker)
  6764. (error "No running clock"))
  6765. (org-with-remote-undo (marker-buffer org-clock-marker)
  6766. (org-clock-cancel)))
  6767. (defun org-agenda-clock-goto ()
  6768. "Jump to the currently clocked in task within the agenda.
  6769. If the currently clocked in task is not listed in the agenda
  6770. buffer, display it in another window."
  6771. (interactive)
  6772. (let (pos)
  6773. (mapc (lambda (o)
  6774. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6775. (setq pos (overlay-start o))))
  6776. (overlays-in (point-min) (point-max)))
  6777. (cond (pos (goto-char pos))
  6778. ;; If the currently clocked entry is not in the agenda
  6779. ;; buffer, we visit it in another window:
  6780. (org-clock-current-task
  6781. (org-switch-to-buffer-other-window (org-clock-goto)))
  6782. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6783. (defun org-agenda-diary-entry-in-org-file ()
  6784. "Make a diary entry in the file `org-agenda-diary-file'."
  6785. (let (d1 d2 char (text "") dp1 dp2)
  6786. (if (equal (buffer-name) "*Calendar*")
  6787. (setq d1 (calendar-cursor-to-date t)
  6788. d2 (car calendar-mark-ring))
  6789. (setq dp1 (get-text-property (point-at-bol) 'day))
  6790. (unless dp1 (error "No date defined in current line"))
  6791. (setq d1 (calendar-gregorian-from-absolute dp1)
  6792. d2 (and (ignore-errors (mark))
  6793. (save-excursion
  6794. (goto-char (mark))
  6795. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6796. (calendar-gregorian-from-absolute dp2))))
  6797. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6798. (setq char (read-char-exclusive))
  6799. (cond
  6800. ((equal char ?d)
  6801. (setq text (read-string "Day entry: "))
  6802. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6803. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6804. ((equal char ?a)
  6805. (setq d1 (list (car d1) (nth 1 d1)
  6806. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6807. (nth 2 d1))))
  6808. (setq text (read-string "Anniversary (use %d to show years): "))
  6809. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6810. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6811. ((equal char ?b)
  6812. (setq text (read-string "Block entry: "))
  6813. (unless (and d1 d2 (not (equal d1 d2)))
  6814. (error "No block of days selected"))
  6815. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6816. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6817. ((equal char ?j)
  6818. (org-switch-to-buffer-other-window
  6819. (find-file-noselect org-agenda-diary-file))
  6820. (require 'org-datetree)
  6821. (org-datetree-find-date-create d1)
  6822. (org-reveal t))
  6823. (t (error "Invalid selection character `%c'" char)))))
  6824. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6825. "Where in `org-agenda-diary-file' should new entries be added?
  6826. Valid values:
  6827. date-tree in the date tree, as child of the date
  6828. top-level as top-level entries at the end of the file."
  6829. :group 'org-agenda
  6830. :type '(choice
  6831. (const :tag "in a date tree" date-tree)
  6832. (const :tag "as top level at end of file" top-level)))
  6833. (defcustom org-agenda-insert-diary-extract-time nil
  6834. "Non-nil means extract any time specification from the diary entry."
  6835. :group 'org-agenda
  6836. :type 'boolean)
  6837. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6838. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6839. If TEXT is not empty, it will become the headline of the new entry, and
  6840. the resulting entry will not be shown. When TEXT is empty, switch to
  6841. `org-agenda-diary-file' and let the user finish the entry there."
  6842. (let ((cw (current-window-configuration)))
  6843. (org-switch-to-buffer-other-window
  6844. (find-file-noselect org-agenda-diary-file))
  6845. (widen)
  6846. (goto-char (point-min))
  6847. (cond
  6848. ((eq type 'anniversary)
  6849. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6850. (progn
  6851. (or (org-on-heading-p t)
  6852. (progn
  6853. (outline-next-heading)
  6854. (insert "* Anniversaries\n\n")
  6855. (beginning-of-line -1)))))
  6856. (outline-next-heading)
  6857. (org-back-over-empty-lines)
  6858. (backward-char 1)
  6859. (insert "\n")
  6860. (require 'diary-lib)
  6861. (let ((calendar-date-display-form
  6862. (if (if (boundp 'calendar-date-style)
  6863. (eq calendar-date-style 'european)
  6864. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  6865. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  6866. '(day " " month " " year)
  6867. '(month " " day " " year))))
  6868. (insert (format "%%%%(diary-anniversary %s) %s"
  6869. (calendar-date-string d1 nil t) text))))
  6870. ((eq type 'day)
  6871. (let ((org-prefix-has-time t)
  6872. (org-agenda-time-leading-zero t)
  6873. fmt time time2)
  6874. (if org-agenda-insert-diary-extract-time
  6875. ;; Use org-format-agenda-item to parse text for a time-range and
  6876. ;; remove it. FIXME: This is a hack, we should refactor
  6877. ;; that function to make time extraction available separately
  6878. (setq fmt (org-format-agenda-item nil text nil nil t)
  6879. time (get-text-property 0 'time fmt)
  6880. time2 (if (> (length time) 0)
  6881. ;; split-string removes trailing ...... if
  6882. ;; no end time given. First space
  6883. ;; separates time from date.
  6884. (concat " " (car (split-string time "\\.")))
  6885. nil)
  6886. text (get-text-property 0 'txt fmt)))
  6887. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6888. (org-agenda-insert-diary-as-top-level text)
  6889. (require 'org-datetree)
  6890. (org-datetree-find-date-create d1)
  6891. (org-agenda-insert-diary-make-new-entry text))
  6892. (org-insert-time-stamp (org-time-from-absolute
  6893. (calendar-absolute-from-gregorian d1))
  6894. nil nil nil nil time2))
  6895. (end-of-line 0))
  6896. ((eq type 'block)
  6897. (if (> (calendar-absolute-from-gregorian d1)
  6898. (calendar-absolute-from-gregorian d2))
  6899. (setq d1 (prog1 d2 (setq d2 d1))))
  6900. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6901. (org-agenda-insert-diary-as-top-level text)
  6902. (require 'org-datetree)
  6903. (org-datetree-find-date-create d1)
  6904. (org-agenda-insert-diary-make-new-entry text))
  6905. (org-insert-time-stamp (org-time-from-absolute
  6906. (calendar-absolute-from-gregorian d1)))
  6907. (insert "--")
  6908. (org-insert-time-stamp (org-time-from-absolute
  6909. (calendar-absolute-from-gregorian d2)))
  6910. (end-of-line 0)))
  6911. (if (string-match "\\S-" text)
  6912. (progn
  6913. (set-window-configuration cw)
  6914. (message "%s entry added to %s"
  6915. (capitalize (symbol-name type))
  6916. (abbreviate-file-name org-agenda-diary-file)))
  6917. (org-reveal t)
  6918. (message "Please finish entry here"))))
  6919. (defun org-agenda-insert-diary-as-top-level (text)
  6920. "Make new entry as a top-level entry at the end of the file.
  6921. Add TEXT as headline, and position the cursor in the second line so that
  6922. a timestamp can be added there."
  6923. (widen)
  6924. (goto-char (point-max))
  6925. (or (bolp) (insert "\n"))
  6926. (insert "* " text "\n")
  6927. (if org-adapt-indentation (org-indent-to-column 2)))
  6928. (defun org-agenda-insert-diary-make-new-entry (text)
  6929. "Make new entry as last child of current entry.
  6930. Add TEXT as headline, and position the cursor in the second line so that
  6931. a timestamp can be added there."
  6932. (let ((org-show-following-heading t)
  6933. (org-show-siblings t)
  6934. (org-show-hierarchy-above t)
  6935. (org-show-entry-below t)
  6936. col)
  6937. (outline-next-heading)
  6938. (org-back-over-empty-lines)
  6939. (or (looking-at "[ \t]*$")
  6940. (progn (insert "\n") (backward-char 1)))
  6941. (org-insert-heading nil t)
  6942. (org-do-demote)
  6943. (setq col (current-column))
  6944. (insert text "\n")
  6945. (if org-adapt-indentation (org-indent-to-column col))
  6946. (let ((org-show-following-heading t)
  6947. (org-show-siblings t)
  6948. (org-show-hierarchy-above t)
  6949. (org-show-entry-below t))
  6950. (org-show-context))))
  6951. (defun org-agenda-diary-entry ()
  6952. "Make a diary entry, like the `i' command from the calendar.
  6953. All the standard commands work: block, weekly etc.
  6954. When `org-agenda-diary-file' points to a file,
  6955. `org-agenda-diary-entry-in-org-file' is called instead to create
  6956. entries in that Org-mode file."
  6957. (interactive)
  6958. (org-agenda-check-type t 'agenda 'timeline)
  6959. (if (not (eq org-agenda-diary-file 'diary-file))
  6960. (org-agenda-diary-entry-in-org-file)
  6961. (require 'diary-lib)
  6962. (let* ((char (progn
  6963. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6964. (read-char-exclusive)))
  6965. (cmd (cdr (assoc char
  6966. '((?d . insert-diary-entry)
  6967. (?w . insert-weekly-diary-entry)
  6968. (?m . insert-monthly-diary-entry)
  6969. (?y . insert-yearly-diary-entry)
  6970. (?a . insert-anniversary-diary-entry)
  6971. (?b . insert-block-diary-entry)
  6972. (?c . insert-cyclic-diary-entry)))))
  6973. (oldf (symbol-function 'calendar-cursor-to-date))
  6974. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6975. (point (point))
  6976. (mark (or (mark t) (point))))
  6977. (unless cmd
  6978. (error "No command associated with <%c>" char))
  6979. (unless (and (get-text-property point 'day)
  6980. (or (not (equal ?b char))
  6981. (get-text-property mark 'day)))
  6982. (error "Don't know which date to use for diary entry"))
  6983. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6984. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6985. (let ((calendar-mark-ring
  6986. (list (calendar-gregorian-from-absolute
  6987. (or (get-text-property mark 'day)
  6988. (get-text-property point 'day))))))
  6989. (unwind-protect
  6990. (progn
  6991. (fset 'calendar-cursor-to-date
  6992. (lambda (&optional error dummy)
  6993. (calendar-gregorian-from-absolute
  6994. (get-text-property point 'day))))
  6995. (call-interactively cmd))
  6996. (fset 'calendar-cursor-to-date oldf))))))
  6997. (defun org-agenda-execute-calendar-command (cmd)
  6998. "Execute a calendar command from the agenda, with the date associated to
  6999. the cursor position."
  7000. (org-agenda-check-type t 'agenda 'timeline)
  7001. (require 'diary-lib)
  7002. (unless (get-text-property (point) 'day)
  7003. (error "Don't know which date to use for calendar command"))
  7004. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7005. (point (point))
  7006. (date (calendar-gregorian-from-absolute
  7007. (get-text-property point 'day)))
  7008. ;; the following 2 vars are needed in the calendar
  7009. (displayed-month (car date))
  7010. (displayed-year (nth 2 date)))
  7011. (unwind-protect
  7012. (progn
  7013. (fset 'calendar-cursor-to-date
  7014. (lambda (&optional error dummy)
  7015. (calendar-gregorian-from-absolute
  7016. (get-text-property point 'day))))
  7017. (call-interactively cmd))
  7018. (fset 'calendar-cursor-to-date oldf))))
  7019. (defun org-agenda-phases-of-moon ()
  7020. "Display the phases of the moon for the 3 months around the cursor date."
  7021. (interactive)
  7022. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7023. (defun org-agenda-holidays ()
  7024. "Display the holidays for the 3 months around the cursor date."
  7025. (interactive)
  7026. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7027. (defvar calendar-longitude)
  7028. (defvar calendar-latitude)
  7029. (defvar calendar-location-name)
  7030. (defun org-agenda-sunrise-sunset (arg)
  7031. "Display sunrise and sunset for the cursor date.
  7032. Latitude and longitude can be specified with the variables
  7033. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7034. argument, latitude and longitude will be prompted for."
  7035. (interactive "P")
  7036. (require 'solar)
  7037. (let ((calendar-longitude (if arg nil calendar-longitude))
  7038. (calendar-latitude (if arg nil calendar-latitude))
  7039. (calendar-location-name
  7040. (if arg "the given coordinates" calendar-location-name)))
  7041. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7042. (defun org-agenda-goto-calendar ()
  7043. "Open the Emacs calendar with the date at the cursor."
  7044. (interactive)
  7045. (org-agenda-check-type t 'agenda 'timeline)
  7046. (let* ((day (or (get-text-property (point) 'day)
  7047. (error "Don't know which date to open in calendar")))
  7048. (date (calendar-gregorian-from-absolute day))
  7049. (calendar-move-hook nil)
  7050. (calendar-view-holidays-initially-flag nil)
  7051. (calendar-view-diary-initially-flag nil))
  7052. (calendar)
  7053. (calendar-goto-date date)))
  7054. ;;;###autoload
  7055. (defun org-calendar-goto-agenda ()
  7056. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7057. This is a command that has to be installed in `calendar-mode-map'."
  7058. (interactive)
  7059. (org-agenda-list nil (calendar-absolute-from-gregorian
  7060. (calendar-cursor-to-date))
  7061. nil))
  7062. (defun org-agenda-convert-date ()
  7063. (interactive)
  7064. (org-agenda-check-type t 'agenda 'timeline)
  7065. (let ((day (get-text-property (point) 'day))
  7066. date s)
  7067. (unless day
  7068. (error "Don't know which date to convert"))
  7069. (setq date (calendar-gregorian-from-absolute day))
  7070. (setq s (concat
  7071. "Gregorian: " (calendar-date-string date) "\n"
  7072. "ISO: " (calendar-iso-date-string date) "\n"
  7073. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7074. "Julian: " (calendar-julian-date-string date) "\n"
  7075. "Astron. JD: " (calendar-astro-date-string date)
  7076. " (Julian date number at noon UTC)\n"
  7077. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7078. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7079. "French: " (calendar-french-date-string date) "\n"
  7080. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7081. "Mayan: " (calendar-mayan-date-string date) "\n"
  7082. "Coptic: " (calendar-coptic-date-string date) "\n"
  7083. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7084. "Persian: " (calendar-persian-date-string date) "\n"
  7085. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7086. (with-output-to-temp-buffer "*Dates*"
  7087. (princ s))
  7088. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7089. ;;; Bulk commands
  7090. (defvar org-agenda-bulk-marked-entries nil
  7091. "List of markers that refer to marked entries in the agenda.")
  7092. (defun org-agenda-bulk-marked-p ()
  7093. (eq (get-char-property (point-at-bol) 'type)
  7094. 'org-marked-entry-overlay))
  7095. (defun org-agenda-bulk-mark ()
  7096. "Mark the entry at point for future bulk action."
  7097. (interactive)
  7098. (org-agenda-check-no-diary)
  7099. (let* ((m (org-get-at-bol 'org-hd-marker))
  7100. ov)
  7101. (unless (org-agenda-bulk-marked-p)
  7102. (unless m (error "Nothing to mark at point"))
  7103. (push m org-agenda-bulk-marked-entries)
  7104. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7105. (org-overlay-display ov "> "
  7106. (org-get-todo-face "TODO")
  7107. 'evaporate)
  7108. (overlay-put ov 'type 'org-marked-entry-overlay))
  7109. (beginning-of-line 2)
  7110. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7111. (beginning-of-line 2))
  7112. (message "%d entries marked for bulk action"
  7113. (length org-agenda-bulk-marked-entries))))
  7114. (defun org-agenda-bulk-unmark ()
  7115. "Unmark the entry at point for future bulk action."
  7116. (interactive)
  7117. (when (org-agenda-bulk-marked-p)
  7118. (org-agenda-bulk-remove-overlays
  7119. (point-at-bol) (+ 2 (point-at-bol)))
  7120. (setq org-agenda-bulk-marked-entries
  7121. (delete (org-get-at-bol 'org-hd-marker)
  7122. org-agenda-bulk-marked-entries)))
  7123. (beginning-of-line 2)
  7124. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7125. (beginning-of-line 2))
  7126. (message "%d entries marked for bulk action"
  7127. (length org-agenda-bulk-marked-entries)))
  7128. (defun org-agenda-bulk-toggle ()
  7129. "Toggle marking the entry at point for bulk action."
  7130. (interactive)
  7131. (if (org-agenda-bulk-marked-p)
  7132. (org-agenda-bulk-unmark)
  7133. (org-agenda-bulk-mark)))
  7134. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7135. "Remove the mark overlays between BEG and END in the agenda buffer.
  7136. BEG and END default to the buffer limits.
  7137. This only removes the overlays, it does not remove the markers
  7138. from the list in `org-agenda-bulk-marked-entries'."
  7139. (interactive)
  7140. (mapc (lambda (ov)
  7141. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7142. (delete-overlay ov)))
  7143. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7144. (defun org-agenda-bulk-remove-all-marks ()
  7145. "Remove all marks in the agenda buffer.
  7146. This will remove the markers, and the overlays."
  7147. (interactive)
  7148. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7149. (setq org-agenda-bulk-marked-entries nil)
  7150. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7151. (defun org-agenda-bulk-action (&optional arg)
  7152. "Execute an remote-editing action on all marked entries.
  7153. The prefix arg is passed through to the command if possible."
  7154. (interactive "P")
  7155. (unless org-agenda-bulk-marked-entries
  7156. (error "No entries are marked"))
  7157. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7158. (let* ((action (read-char-exclusive))
  7159. (org-log-refile (if org-log-refile 'time nil))
  7160. (entries (reverse org-agenda-bulk-marked-entries))
  7161. redo-at-end
  7162. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7163. (cond
  7164. ((equal action ?$)
  7165. (setq cmd '(org-agenda-archive)))
  7166. ((equal action ?A)
  7167. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7168. ((member action '(?r ?w))
  7169. (setq rfloc (org-refile-get-location
  7170. "Refile to: "
  7171. (marker-buffer (car org-agenda-bulk-marked-entries))
  7172. org-refile-allow-creating-parent-nodes))
  7173. (if (nth 3 rfloc)
  7174. (setcar (nthcdr 3 rfloc)
  7175. (move-marker (make-marker) (nth 3 rfloc)
  7176. (or (get-file-buffer (nth 1 rfloc))
  7177. (find-buffer-visiting (nth 1 rfloc))
  7178. (error "This should not happen")))))
  7179. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7180. redo-at-end t))
  7181. ((equal action ?t)
  7182. (setq state (org-icompleting-read
  7183. "Todo state: "
  7184. (with-current-buffer (marker-buffer (car entries))
  7185. (mapcar 'list org-todo-keywords-1))))
  7186. (setq cmd `(let ((org-inhibit-blocking t)
  7187. (org-inhibit-logging 'note))
  7188. (org-agenda-todo ,state))))
  7189. ((memq action '(?- ?+))
  7190. (setq tag (org-icompleting-read
  7191. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7192. (with-current-buffer (marker-buffer (car entries))
  7193. (delq nil
  7194. (mapcar (lambda (x)
  7195. (if (stringp (car x)) x)) org-tag-alist)))))
  7196. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7197. ((memq action '(?s ?d))
  7198. (let* ((date (unless arg
  7199. (org-read-date
  7200. nil nil nil
  7201. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7202. (ans (if arg nil org-read-date-final-answer))
  7203. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7204. (setq cmd `(let* ((bound (fboundp 'read-string))
  7205. (old (and bound (symbol-function 'read-string))))
  7206. (unwind-protect
  7207. (progn
  7208. (fset 'read-string (lambda (&rest ignore) ,ans))
  7209. (eval '(,c1 arg)))
  7210. (if bound
  7211. (fset 'read-string old)
  7212. (fmakunbound 'read-string)))))))
  7213. (t (error "Invalid bulk action")))
  7214. ;; Sort the markers, to make sure that parents are handled before children
  7215. (setq entries (sort entries
  7216. (lambda (a b)
  7217. (cond
  7218. ((equal (marker-buffer a) (marker-buffer b))
  7219. (< (marker-position a) (marker-position b)))
  7220. (t
  7221. (string< (buffer-name (marker-buffer a))
  7222. (buffer-name (marker-buffer b))))))))
  7223. ;; Now loop over all markers and apply cmd
  7224. (while (setq e (pop entries))
  7225. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7226. (if (not pos)
  7227. (progn (message "Skipping removed entry at %s" e)
  7228. (setq cntskip (1+ cntskip)))
  7229. (goto-char pos)
  7230. (eval cmd)
  7231. (setq org-agenda-bulk-marked-entries
  7232. (delete e org-agenda-bulk-marked-entries))
  7233. (setq cnt (1+ cnt))))
  7234. (setq org-agenda-bulk-marked-entries nil)
  7235. (org-agenda-bulk-remove-all-marks)
  7236. (when redo-at-end (org-agenda-redo))
  7237. (message "Acted on %d entries%s"
  7238. cnt
  7239. (if (= cntskip 0)
  7240. ""
  7241. (format ", skipped %d (disappeared before their turn)"
  7242. cntskip)))))
  7243. ;;; Flagging notes
  7244. (defun org-agenda-show-the-flagging-note ()
  7245. "Display the flagging note in the other window.
  7246. When called a second time in direct sequence, offer to remove the FLAGGING
  7247. tag and (if present) the flagging note."
  7248. (interactive)
  7249. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7250. (win (selected-window))
  7251. note heading newhead)
  7252. (unless hdmarker
  7253. (error "No linked entry at point"))
  7254. (if (and (eq this-command last-command)
  7255. (y-or-n-p "Unflag and remove any flagging note? "))
  7256. (progn
  7257. (org-agenda-remove-flag hdmarker)
  7258. (let ((win (get-buffer-window "*Flagging Note*")))
  7259. (and win (delete-window win)))
  7260. (message "Entry unflaged"))
  7261. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7262. (unless note
  7263. (error "No flagging note"))
  7264. (org-kill-new note)
  7265. (org-switch-to-buffer-other-window "*Flagging Note*")
  7266. (erase-buffer)
  7267. (insert note)
  7268. (goto-char (point-min))
  7269. (while (re-search-forward "\\\\n" nil t)
  7270. (replace-match "\n" t t))
  7271. (goto-char (point-min))
  7272. (select-window win)
  7273. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7274. (defun org-agenda-remove-flag (marker)
  7275. "Remove the FLAGGED tag and any flagging note in the entry."
  7276. (let (newhead)
  7277. (org-with-point-at marker
  7278. (org-toggle-tag "FLAGGED" 'off)
  7279. (org-entry-delete nil "THEFLAGGINGNOTE")
  7280. (setq newhead (org-get-heading)))
  7281. (org-agenda-change-all-lines newhead marker)
  7282. (message "Entry unflaged")))
  7283. (defun org-agenda-get-any-marker (&optional pos)
  7284. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7285. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7286. ;;; Appointment reminders
  7287. (defvar appt-time-msg-list)
  7288. ;;;###autoload
  7289. (defun org-agenda-to-appt (&optional refresh filter)
  7290. "Activate appointments found in `org-agenda-files'.
  7291. With a \\[universal-argument] prefix, refresh the list of
  7292. appointments.
  7293. If FILTER is t, interactively prompt the user for a regular
  7294. expression, and filter out entries that don't match it.
  7295. If FILTER is a string, use this string as a regular expression
  7296. for filtering entries out.
  7297. FILTER can also be an alist with the car of each cell being
  7298. either 'headline or 'category. For example:
  7299. '((headline \"IMPORTANT\")
  7300. (category \"Work\"))
  7301. will only add headlines containing IMPORTANT or headlines
  7302. belonging to the \"Work\" category."
  7303. (interactive "P")
  7304. (if refresh (setq appt-time-msg-list nil))
  7305. (if (eq filter t)
  7306. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7307. (let* ((cnt 0) ; count added events
  7308. (org-agenda-new-buffers nil)
  7309. (org-deadline-warning-days 0)
  7310. (today (org-date-to-gregorian
  7311. (time-to-days (current-time))))
  7312. (org-agenda-restrict nil)
  7313. (files (org-agenda-files 'unrestricted)) entries file)
  7314. ;; Get all entries which may contain an appt
  7315. (org-prepare-agenda-buffers files)
  7316. (while (setq file (pop files))
  7317. (setq entries
  7318. (append entries
  7319. (org-agenda-get-day-entries
  7320. file today :timestamp :scheduled :deadline))))
  7321. (setq entries (delq nil entries))
  7322. ;; Map thru entries and find if we should filter them out
  7323. (mapc
  7324. (lambda(x)
  7325. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7326. (cat (get-text-property 1 'org-category x))
  7327. (tod (get-text-property 1 'time-of-day x))
  7328. (ok (or (null filter)
  7329. (and (stringp filter) (string-match filter evt))
  7330. (and (listp filter)
  7331. (or (string-match
  7332. (cadr (assoc 'category filter)) cat)
  7333. (string-match
  7334. (cadr (assoc 'headline filter)) evt))))))
  7335. ;; FIXME: Shall we remove text-properties for the appt text?
  7336. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7337. (when (and ok tod)
  7338. (setq tod (concat "00" (number-to-string tod))
  7339. tod (when (string-match
  7340. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7341. (concat (match-string 1 tod) ":"
  7342. (match-string 2 tod))))
  7343. (appt-add tod evt)
  7344. (setq cnt (1+ cnt))))) entries)
  7345. (org-release-buffers org-agenda-new-buffers)
  7346. (if (eq cnt 0)
  7347. (message "No event to add")
  7348. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7349. (defun org-agenda-todayp (date)
  7350. "Does DATE mean today, when considering `org-extend-today-until'?"
  7351. (let (today h)
  7352. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7353. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7354. (setq h (nth 2 (decode-time (current-time))))
  7355. (or (and (>= h org-extend-today-until)
  7356. (= date today))
  7357. (and (< h org-extend-today-until)
  7358. (= date (1- today))))))
  7359. (provide 'org-agenda)
  7360. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7361. ;;; org-agenda.el ends here