org-agenda.el 248 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  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: 6.28trans
  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. (require 'calendar))
  30. (declare-function diary-add-to-list "diary-lib"
  31. (date string specifier &optional marker globcolor literal))
  32. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  33. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  34. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  35. (declare-function calendar-check-holidays "holidays" (date))
  36. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  37. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  38. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  39. (declare-function calendar-french-date-string "cal-french" (&optional date))
  40. (declare-function calendar-goto-date "cal-move" (date))
  41. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  42. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  43. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  44. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  45. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  46. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  47. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (defvar calendar-mode-map)
  50. ;; Defined somewhere in this file, but used before definition.
  51. (defvar org-agenda-buffer-name)
  52. (defvar org-agenda-overriding-header)
  53. (defvar entry)
  54. (defvar date)
  55. (defvar org-agenda-undo-list)
  56. (defvar org-agenda-pending-undo-list)
  57. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  58. (defcustom org-agenda-confirm-kill 1
  59. "When set, remote killing from the agenda buffer needs confirmation.
  60. When t, a confirmation is always needed. When a number N, confirmation is
  61. only needed when the text to be killed contains more than N non-white lines."
  62. :group 'org-agenda
  63. :type '(choice
  64. (const :tag "Never" nil)
  65. (const :tag "Always" t)
  66. (integer :tag "When more than N lines")))
  67. (defcustom org-agenda-compact-blocks nil
  68. "Non-nil means, make the block agenda more compact.
  69. This is done by leaving out unnecessary lines."
  70. :group 'org-agenda
  71. :type 'boolean)
  72. (defcustom org-agenda-block-separator ?=
  73. "The separator between blocks in the agenda.
  74. If this is a string, it will be used as the separator, with a newline added.
  75. If it is a character, it will be repeated to fill the window width."
  76. :group 'org-agenda
  77. :type '(choice
  78. (character)
  79. (string)))
  80. (defgroup org-agenda-export nil
  81. "Options concerning exporting agenda views in Org-mode."
  82. :tag "Org Agenda Export"
  83. :group 'org-agenda)
  84. (defcustom org-agenda-with-colors t
  85. "Non-nil means, use colors in agenda views."
  86. :group 'org-agenda-export
  87. :type 'boolean)
  88. (defcustom org-agenda-exporter-settings nil
  89. "Alist of variable/value pairs that should be active during agenda export.
  90. This is a good place to set options for ps-print and for htmlize.
  91. Note that the way this is implemented, the values will be evaluated
  92. before assigned to the variables. So make sure to quote values you do
  93. *not* want evaluated, for example
  94. (setq org-agenda-exporter-settings
  95. '((ps-print-color-p 'black-white)))"
  96. :group 'org-agenda-export
  97. :type '(repeat
  98. (list
  99. (variable)
  100. (sexp :tag "Value"))))
  101. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  102. "Hook run in temporary buffer before writing it to an export file.
  103. A useful function is `org-agenda-add-entry-text'."
  104. :group 'org-agenda-export
  105. :type 'hook
  106. :options '(org-agenda-add-entry-text))
  107. (defcustom org-agenda-add-entry-text-maxlines 0
  108. "Maximum number of entry text lines to be added to agenda.
  109. This is only relevant when `org-agenda-add-entry-text' is part of
  110. `org-agenda-before-write-hook', which it is by default.
  111. When this is 0, nothing will happen. When it is greater than 0, it
  112. specifies the maximum number of lines that will be added for each entry
  113. that is listed in the agenda view."
  114. :group 'org-agenda
  115. :type 'integer)
  116. (defcustom org-agenda-add-entry-text-descriptive-links t
  117. "Non-nil means, export org-links as descriptive links in agenda added text.
  118. This variable applies to the text added to the agenda when
  119. `org-agenda-add-entry-text-maxlines' is larger than 0.
  120. When this variable nil, the URL will (also) be shown."
  121. :group 'org-agenda
  122. :type 'boolean)
  123. (defcustom org-agenda-export-html-style ""
  124. "The style specification for exported HTML Agenda files.
  125. If this variable contains a string, it will replace the default <style>
  126. section as produced by `htmlize'.
  127. Since there are different ways of setting style information, this variable
  128. needs to contain the full HTML structure to provide a style, including the
  129. surrounding HTML tags. The style specifications should include definitions
  130. the fonts used by the agenda, here is an example:
  131. <style type=\"text/css\">
  132. p { font-weight: normal; color: gray; }
  133. .org-agenda-structure {
  134. font-size: 110%;
  135. color: #003399;
  136. font-weight: 600;
  137. }
  138. .org-todo {
  139. color: #cc6666;
  140. font-weight: bold;
  141. }
  142. .org-agenda-done {
  143. color: #339933;
  144. }
  145. .org-done {
  146. color: #339933;
  147. }
  148. .title { text-align: center; }
  149. .todo, .deadline { color: red; }
  150. .done { color: green; }
  151. </style>
  152. or, if you want to keep the style in a file,
  153. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  154. As the value of this option simply gets inserted into the HTML <head> header,
  155. you can \"misuse\" it to also add other text to the header. However,
  156. <style>...</style> is required, if not present the variable will be ignored."
  157. :group 'org-agenda-export
  158. :group 'org-export-html
  159. :type 'string)
  160. (defgroup org-agenda-custom-commands nil
  161. "Options concerning agenda views in Org-mode."
  162. :tag "Org Agenda Custom Commands"
  163. :group 'org-agenda)
  164. (defconst org-sorting-choice
  165. '(choice
  166. (const time-up) (const time-down)
  167. (const category-keep) (const category-up) (const category-down)
  168. (const tag-down) (const tag-up)
  169. (const priority-up) (const priority-down)
  170. (const todo-state-up) (const todo-state-down)
  171. (const effort-up) (const effort-down)
  172. (const user-defined-up) (const user-defined-down))
  173. "Sorting choices.")
  174. (defconst org-agenda-custom-commands-local-options
  175. `(repeat :tag "Local settings for this command. Remember to quote values"
  176. (choice :tag "Setting"
  177. (list :tag "Heading for this block"
  178. (const org-agenda-overriding-header)
  179. (string :tag "Headline"))
  180. (list :tag "Files to be searched"
  181. (const org-agenda-files)
  182. (list
  183. (const :format "" quote)
  184. (repeat (file))))
  185. (list :tag "Sorting strategy"
  186. (const org-agenda-sorting-strategy)
  187. (list
  188. (const :format "" quote)
  189. (repeat
  190. ,org-sorting-choice)))
  191. (list :tag "Prefix format"
  192. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  193. (string))
  194. (list :tag "Number of days in agenda"
  195. (const org-agenda-ndays)
  196. (integer :value 1))
  197. (list :tag "Fixed starting date"
  198. (const org-agenda-start-day)
  199. (string :value "2007-11-01"))
  200. (list :tag "Start on day of week"
  201. (const org-agenda-start-on-weekday)
  202. (choice :value 1
  203. (const :tag "Today" nil)
  204. (integer :tag "Weekday No.")))
  205. (list :tag "Include data from diary"
  206. (const org-agenda-include-diary)
  207. (boolean))
  208. (list :tag "Deadline Warning days"
  209. (const org-deadline-warning-days)
  210. (integer :value 1))
  211. (list :tag "Tags filter preset"
  212. (const org-agenda-filter-preset)
  213. (list
  214. (const :format "" quote)
  215. (repeat
  216. (string :tag "+tag or -tag"))))
  217. (list :tag "Standard skipping condition"
  218. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  219. (const org-agenda-skip-function)
  220. (list
  221. (const :format "" quote)
  222. (list
  223. (choice
  224. :tag "Skipping range"
  225. (const :tag "Skip entry" org-agenda-skip-entry-if)
  226. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  227. (repeat :inline t :tag "Conditions for skipping"
  228. (choice
  229. :tag "Condition type"
  230. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  231. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  232. (const :tag "scheduled" 'scheduled)
  233. (const :tag "not scheduled" 'notscheduled)
  234. (const :tag "deadline" 'deadline)
  235. (const :tag "no deadline" 'notdeadline)
  236. (const :tag "timestamp" 'timestamp)
  237. (const :tag "no timestamp" 'nottimestamp))))))
  238. (list :tag "Non-standard skipping condition"
  239. :value (org-agenda-skip-function)
  240. (const org-agenda-skip-function)
  241. (sexp :tag "Function or form (quoted!)"))
  242. (list :tag "Any variable"
  243. (variable :tag "Variable")
  244. (sexp :tag "Value (sexp)"))))
  245. "Selection of examples for agenda command settings.
  246. This will be spliced into the custom type of
  247. `org-agenda-custom-commands'.")
  248. (defcustom org-agenda-custom-commands nil
  249. "Custom commands for the agenda.
  250. These commands will be offered on the splash screen displayed by the
  251. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  252. (key desc type match settings files)
  253. key The key (one or more characters as a string) to be associated
  254. with the command.
  255. desc A description of the command, when omitted or nil, a default
  256. description is built using MATCH.
  257. type The command type, any of the following symbols:
  258. agenda The daily/weekly agenda.
  259. todo Entries with a specific TODO keyword, in all agenda files.
  260. search Entries containing search words entry or headline.
  261. tags Tags/Property/TODO match in all agenda files.
  262. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  263. todo-tree Sparse tree of specific TODO keyword in *current* file.
  264. tags-tree Sparse tree with all tags matches in *current* file.
  265. occur-tree Occur sparse tree for *current* file.
  266. ... A user-defined function.
  267. match What to search for:
  268. - a single keyword for TODO keyword searches
  269. - a tags match expression for tags searches
  270. - a word search expression for text searches.
  271. - a regular expression for occur searches
  272. For all other commands, this should be the empty string.
  273. settings A list of option settings, similar to that in a let form, so like
  274. this: ((opt1 val1) (opt2 val2) ...). The values will be
  275. evaluated at the moment of execution, so quote them when needed.
  276. files A list of files file to write the produced agenda buffer to
  277. with the command `org-store-agenda-views'.
  278. If a file name ends in \".html\", an HTML version of the buffer
  279. is written out. If it ends in \".ps\", a postscript version is
  280. produced. Otherwise, only the plain text is written to the file.
  281. You can also define a set of commands, to create a composite agenda buffer.
  282. In this case, an entry looks like this:
  283. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  284. where
  285. desc A description string to be displayed in the dispatcher menu.
  286. cmd An agenda command, similar to the above. However, tree commands
  287. are no allowed, but instead you can get agenda and global todo list.
  288. So valid commands for a set are:
  289. (agenda \"\" settings)
  290. (alltodo \"\" settings)
  291. (stuck \"\" settings)
  292. (todo \"match\" settings files)
  293. (search \"match\" settings files)
  294. (tags \"match\" settings files)
  295. (tags-todo \"match\" settings files)
  296. Each command can carry a list of options, and another set of options can be
  297. given for the whole set of commands. Individual command options take
  298. precedence over the general options.
  299. When using several characters as key to a command, the first characters
  300. are prefix commands. For the dispatcher to display useful information, you
  301. should provide a description for the prefix, like
  302. (setq org-agenda-custom-commands
  303. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  304. (\"hl\" tags \"+HOME+Lisa\")
  305. (\"hp\" tags \"+HOME+Peter\")
  306. (\"hk\" tags \"+HOME+Kim\")))"
  307. :group 'org-agenda-custom-commands
  308. :type `(repeat
  309. (choice :value ("x" "Describe command here" tags "" nil)
  310. (list :tag "Single command"
  311. (string :tag "Access Key(s) ")
  312. (option (string :tag "Description"))
  313. (choice
  314. (const :tag "Agenda" agenda)
  315. (const :tag "TODO list" alltodo)
  316. (const :tag "Search words" search)
  317. (const :tag "Stuck projects" stuck)
  318. (const :tag "Tags/Property match (all agenda files)" tags)
  319. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  320. (const :tag "TODO keyword search (all agenda files)" todo)
  321. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  322. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  323. (const :tag "Occur tree (current buffer)" occur-tree)
  324. (sexp :tag "Other, user-defined function"))
  325. (string :tag "Match (only for some commands)")
  326. ,org-agenda-custom-commands-local-options
  327. (option (repeat :tag "Export" (file :tag "Export to"))))
  328. (list :tag "Command series, all agenda files"
  329. (string :tag "Access Key(s)")
  330. (string :tag "Description ")
  331. (repeat :tag "Component"
  332. (choice
  333. (list :tag "Agenda"
  334. (const :format "" agenda)
  335. (const :tag "" :format "" "")
  336. ,org-agenda-custom-commands-local-options)
  337. (list :tag "TODO list (all keywords)"
  338. (const :format "" alltodo)
  339. (const :tag "" :format "" "")
  340. ,org-agenda-custom-commands-local-options)
  341. (list :tag "Search words"
  342. (const :format "" search)
  343. (string :tag "Match")
  344. ,org-agenda-custom-commands-local-options)
  345. (list :tag "Stuck projects"
  346. (const :format "" stuck)
  347. (const :tag "" :format "" "")
  348. ,org-agenda-custom-commands-local-options)
  349. (list :tag "Tags search"
  350. (const :format "" tags)
  351. (string :tag "Match")
  352. ,org-agenda-custom-commands-local-options)
  353. (list :tag "Tags search, TODO entries only"
  354. (const :format "" tags-todo)
  355. (string :tag "Match")
  356. ,org-agenda-custom-commands-local-options)
  357. (list :tag "TODO keyword search"
  358. (const :format "" todo)
  359. (string :tag "Match")
  360. ,org-agenda-custom-commands-local-options)
  361. (list :tag "Other, user-defined function"
  362. (symbol :tag "function")
  363. (string :tag "Match")
  364. ,org-agenda-custom-commands-local-options)))
  365. (repeat :tag "Settings for entire command set"
  366. (list (variable :tag "Any variable")
  367. (sexp :tag "Value")))
  368. (option (repeat :tag "Export" (file :tag "Export to"))))
  369. (cons :tag "Prefix key documentation"
  370. (string :tag "Access Key(s)")
  371. (string :tag "Description ")))))
  372. (defcustom org-agenda-query-register ?o
  373. "The register holding the current query string.
  374. The purpose of this is that if you construct a query string interactively,
  375. you can then use it to define a custom command."
  376. :group 'org-agenda-custom-commands
  377. :type 'character)
  378. (defcustom org-stuck-projects
  379. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  380. "How to identify stuck projects.
  381. This is a list of four items:
  382. 1. A tags/todo/property matcher string that is used to identify a project.
  383. See the manual for a description of tag and property searches.
  384. The entire tree below a headline matched by this is considered one project.
  385. 2. A list of TODO keywords identifying non-stuck projects.
  386. If the project subtree contains any headline with one of these todo
  387. keywords, the project is considered to be not stuck. If you specify
  388. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  389. 3. A list of tags identifying non-stuck projects.
  390. If the project subtree contains any headline with one of these tags,
  391. the project is considered to be not stuck. If you specify \"*\" as
  392. a tag, any tag will mark the project unstuck. Note that this is about
  393. the explicit presence of a tag somewhere in the subtree, inherited
  394. tags to not count here. If inherited tags make a project not stuck,
  395. use \"-TAG\" in the tags part of the matcher under (1.) above.
  396. 4. An arbitrary regular expression matching non-stuck projects.
  397. If the project turns out to be not stuck, search continues also in the
  398. subtree to see if any of the subtasks have project status.
  399. See also the variable `org-tags-match-list-sublevels' which applies
  400. to projects matched by this search as well.
  401. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  402. or `C-c a #' to produce the list."
  403. :group 'org-agenda-custom-commands
  404. :type '(list
  405. (string :tag "Tags/TODO match to identify a project")
  406. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  407. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  408. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  409. (defcustom org-agenda-filter-effort-default-operator "<"
  410. "The default operator for effort estimate filtering.
  411. If you select an effort estimate limit without first pressing an operator,
  412. this one will be used."
  413. :group 'org-agenda-custom-commands
  414. :type '(choice (const :tag "less or equal" "<")
  415. (const :tag "greater or equal"">")
  416. (const :tag "equal" "=")))
  417. (defgroup org-agenda-skip nil
  418. "Options concerning skipping parts of agenda files."
  419. :tag "Org Agenda Skip"
  420. :group 'org-agenda)
  421. (defgroup org-agenda-daily/weekly nil
  422. "Options concerning the daily/weekly agenda."
  423. :tag "Org Agenda Daily/Weekly"
  424. :group 'org-agenda)
  425. (defgroup org-agenda-todo-list nil
  426. "Options concerning the global todo list agenda view."
  427. :tag "Org Agenda Todo List"
  428. :group 'org-agenda)
  429. (defgroup org-agenda-match-view nil
  430. "Options concerning the general tags/property/todo match agenda view."
  431. :tag "Org Agenda Match View"
  432. :group 'org-agenda)
  433. (defvar org-agenda-archives-mode nil
  434. "Non-nil means, the agenda will include archived items.
  435. If this is the symbol `trees', trees in the selected agenda scope
  436. that are marked with the ARCHIVE tag will be included anyway. When this is
  437. t, also all archive files associated with the current selection of agenda
  438. files will be included.")
  439. (defcustom org-agenda-skip-comment-trees t
  440. "Non-nil means, skip trees that start with the COMMENT keyword.
  441. When nil, these trees are also scanned by agenda commands."
  442. :group 'org-agenda-skip
  443. :type 'boolean)
  444. (defcustom org-agenda-todo-list-sublevels t
  445. "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
  446. When nil, the sublevels of a TODO entry are not checked, resulting in
  447. potentially much shorter TODO lists."
  448. :group 'org-agenda-skip
  449. :group 'org-agenda-todo-list
  450. :type 'boolean)
  451. (defcustom org-agenda-todo-ignore-with-date nil
  452. "Non-nil means, don't show entries with a date in the global todo list.
  453. You can use this if you prefer to mark mere appointments with a TODO keyword,
  454. but don't want them to show up in the TODO list.
  455. When this is set, it also covers deadlines and scheduled items, the settings
  456. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  457. will be ignored.
  458. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  459. :group 'org-agenda-skip
  460. :group 'org-agenda-todo-list
  461. :type 'boolean)
  462. (defcustom org-agenda-todo-ignore-scheduled nil
  463. "Non-nil means, don't show scheduled entries in the global todo list.
  464. The idea behind this is that by scheduling it, you have already taken care
  465. of this item.
  466. See also `org-agenda-todo-ignore-with-date'.
  467. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  468. :group 'org-agenda-skip
  469. :group 'org-agenda-todo-list
  470. :type 'boolean)
  471. (defcustom org-agenda-todo-ignore-deadlines nil
  472. "Non-nil means, don't show near deadline entries in the global todo list.
  473. Near means closer than `org-deadline-warning-days' days.
  474. The idea behind this is that such items will appear in the agenda anyway.
  475. See also `org-agenda-todo-ignore-with-date'.
  476. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  477. :group 'org-agenda-skip
  478. :group 'org-agenda-todo-list
  479. :type 'boolean)
  480. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  481. "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
  482. The variables
  483. `org-agenda-todo-ignore-with-date',
  484. `org-agenda-todo-ignore-scheduled'
  485. `org-agenda-todo-ignore-deadlines'
  486. make the global TODO list skip entries that have time stamps of certain
  487. kinds. If this option is set, the same options will also apply for the
  488. tags-todo search, which is the general tags/property matcher
  489. restricted to unfinished TODO entries only."
  490. :group 'org-agenda-skip
  491. :group 'org-agenda-todo-list
  492. :group 'org-agenda-match-view
  493. :type 'boolean)
  494. (defcustom org-agenda-skip-scheduled-if-done nil
  495. "Non-nil means don't show scheduled items in agenda when they are done.
  496. This is relevant for the daily/weekly agenda, not for the TODO list. And
  497. it applies only to the actual date of the scheduling. Warnings about
  498. an item with a past scheduling dates are always turned off when the item
  499. is DONE."
  500. :group 'org-agenda-skip
  501. :group 'org-agenda-daily/weekly
  502. :type 'boolean)
  503. (defcustom org-agenda-skip-deadline-if-done nil
  504. "Non-nil means don't show deadlines when the corresponding item is done.
  505. When nil, the deadline is still shown and should give you a happy feeling.
  506. This is relevant for the daily/weekly agenda. And it applied only to the
  507. actually date of the deadline. Warnings about approaching and past-due
  508. deadlines are always turned off when the item is DONE."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-daily/weekly
  511. :type 'boolean)
  512. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  513. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  514. When non-nil, after the search for timestamps has matched once in an
  515. entry, the rest of the entry will not be searched."
  516. :group 'org-agenda-skip
  517. :type 'boolean)
  518. (defcustom org-agenda-skip-timestamp-if-done nil
  519. "Non-nil means don't select item by timestamp or -range if it is DONE."
  520. :group 'org-agenda-skip
  521. :group 'org-agenda-daily/weekly
  522. :type 'boolean)
  523. (defcustom org-agenda-dim-blocked-tasks t
  524. "Non-nil means, dim blocked tasks in the agenda display.
  525. This causes some overhead during agenda construction, but if you
  526. have turned on `org-enforce-todo-dependencies',
  527. `org-enforce-todo-checkbox-dependencies', or any other blocking
  528. mechanism, this will create useful feedback in the agenda.
  529. Instead ot t, this variable can also have the value `invisible'.
  530. Then blocked tasks will be invisible and only become visible when
  531. they become unblocked. An exemption to this behavior is when a task is
  532. blocked because of unchecked checkboxes below it. Since checkboxes do
  533. not show up in the agenda views, making this task invisible you remove any
  534. trace from agenda views that there is something to do. Therefore, a task
  535. that is blocked because of checkboxes will never be made invisible, it
  536. will only be dimmed."
  537. :group 'org-agenda-daily/weekly
  538. :group 'org-agenda-todo-list
  539. :type '(choice
  540. (const :tag "Do not dim" nil)
  541. (const :tag "Dim to a grey face" t)
  542. (const :tag "Make invisibe" invisible)))
  543. (defcustom org-timeline-show-empty-dates 3
  544. "Non-nil means, `org-timeline' also shows dates without an entry.
  545. When nil, only the days which actually have entries are shown.
  546. When t, all days between the first and the last date are shown.
  547. When an integer, show also empty dates, but if there is a gap of more than
  548. N days, just insert a special line indicating the size of the gap."
  549. :group 'org-agenda-skip
  550. :type '(choice
  551. (const :tag "None" nil)
  552. (const :tag "All" t)
  553. (integer :tag "at most")))
  554. (defgroup org-agenda-startup nil
  555. "Options concerning initial settings in the Agenda in Org Mode."
  556. :tag "Org Agenda Startup"
  557. :group 'org-agenda)
  558. (defcustom org-finalize-agenda-hook nil
  559. "Hook run just before displaying an agenda buffer."
  560. :group 'org-agenda-startup
  561. :type 'hook)
  562. (defcustom org-agenda-mouse-1-follows-link nil
  563. "Non-nil means, mouse-1 on a link will follow the link in the agenda.
  564. A longer mouse click will still set point. Does not work on XEmacs.
  565. Needs to be set before org.el is loaded."
  566. :group 'org-agenda-startup
  567. :type 'boolean)
  568. (defcustom org-agenda-start-with-follow-mode nil
  569. "The initial value of follow-mode in a newly created agenda window."
  570. :group 'org-agenda-startup
  571. :type 'boolean)
  572. (defvar org-agenda-include-inactive-timestamps nil
  573. "Non-nil means, include inactive time stamps in agenda and timeline.")
  574. (defgroup org-agenda-windows nil
  575. "Options concerning the windows used by the Agenda in Org Mode."
  576. :tag "Org Agenda Windows"
  577. :group 'org-agenda)
  578. (defcustom org-agenda-window-setup 'reorganize-frame
  579. "How the agenda buffer should be displayed.
  580. Possible values for this option are:
  581. current-window Show agenda in the current window, keeping all other windows.
  582. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  583. other-window Use `switch-to-buffer-other-window' to display agenda.
  584. reorganize-frame Show only two windows on the current frame, the current
  585. window and the agenda.
  586. See also the variable `org-agenda-restore-windows-after-quit'."
  587. :group 'org-agenda-windows
  588. :type '(choice
  589. (const current-window)
  590. (const other-frame)
  591. (const other-window)
  592. (const reorganize-frame)))
  593. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  594. "The min and max height of the agenda window as a fraction of frame height.
  595. The value of the variable is a cons cell with two numbers between 0 and 1.
  596. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  597. :group 'org-agenda-windows
  598. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  599. (defcustom org-agenda-restore-windows-after-quit nil
  600. "Non-nil means, restore window configuration open exiting agenda.
  601. Before the window configuration is changed for displaying the agenda,
  602. the current status is recorded. When the agenda is exited with
  603. `q' or `x' and this option is set, the old state is restored. If
  604. `org-agenda-window-setup' is `other-frame', the value of this
  605. option will be ignored.."
  606. :group 'org-agenda-windows
  607. :type 'boolean)
  608. (defcustom org-agenda-ndays 7
  609. "Number of days to include in overview display.
  610. Should be 1 or 7.
  611. Custom commands can set this variable in the options section."
  612. :group 'org-agenda-daily/weekly
  613. :type 'integer)
  614. (defcustom org-agenda-start-on-weekday 1
  615. "Non-nil means, start the overview always on the specified weekday.
  616. 0 denotes Sunday, 1 denotes Monday etc.
  617. When nil, always start on the current day.
  618. Custom commands can set this variable in the options section."
  619. :group 'org-agenda-daily/weekly
  620. :type '(choice (const :tag "Today" nil)
  621. (integer :tag "Weekday No.")))
  622. (defcustom org-agenda-show-all-dates t
  623. "Non-nil means, `org-agenda' shows every day in the selected range.
  624. When nil, only the days which actually have entries are shown."
  625. :group 'org-agenda-daily/weekly
  626. :type 'boolean)
  627. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  628. "Format string for displaying dates in the agenda.
  629. Used by the daily/weekly agenda and by the timeline. This should be
  630. a format string understood by `format-time-string', or a function returning
  631. the formatted date as a string. The function must take a single argument,
  632. a calendar-style date list like (month day year)."
  633. :group 'org-agenda-daily/weekly
  634. :type '(choice
  635. (string :tag "Format string")
  636. (function :tag "Function")))
  637. (defun org-agenda-format-date-aligned (date)
  638. "Format a date string for display in the daily/weekly agenda, or timeline.
  639. This function makes sure that dates are aligned for easy reading."
  640. (require 'cal-iso)
  641. (let* ((dayname (calendar-day-name date))
  642. (day (cadr date))
  643. (day-of-week (calendar-day-of-week date))
  644. (month (car date))
  645. (monthname (calendar-month-name month))
  646. (year (nth 2 date))
  647. (iso-week (org-days-to-iso-week
  648. (calendar-absolute-from-gregorian date)))
  649. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  650. (1- year))
  651. ((and (= month 12) (<= iso-week 1))
  652. (1+ year))
  653. (t year)))
  654. (weekstring (if (= day-of-week 1)
  655. (format " W%02d" iso-week)
  656. "")))
  657. (format "%-10s %2d %s %4d%s"
  658. dayname day monthname year weekstring)))
  659. (defcustom org-agenda-weekend-days '(6 0)
  660. "Which days are weekend?
  661. These days get the special face `org-agenda-date-weekend' in the agenda
  662. and timeline buffers."
  663. :group 'org-agenda-daily/weekly
  664. :type '(set :greedy t
  665. (const :tag "Monday" 1)
  666. (const :tag "Tuesday" 2)
  667. (const :tag "Wednesday" 3)
  668. (const :tag "Thursday" 4)
  669. (const :tag "Friday" 5)
  670. (const :tag "Saturday" 6)
  671. (const :tag "Sunday" 0)))
  672. (defcustom org-agenda-include-diary nil
  673. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  674. Custom commands can set this variable in the options section."
  675. :group 'org-agenda-daily/weekly
  676. :type 'boolean)
  677. (defcustom org-agenda-include-all-todo nil
  678. "Set means weekly/daily agenda will always contain all TODO entries.
  679. The TODO entries will be listed at the top of the agenda, before
  680. the entries for specific days.
  681. This option is deprecated, it is better to define a block agenda instead."
  682. :group 'org-agenda-daily/weekly
  683. :type 'boolean)
  684. (defcustom org-agenda-repeating-timestamp-show-all t
  685. "Non-nil means, show all occurrences of a repeating stamp in the agenda.
  686. When nil, only one occurrence is shown, either today or the
  687. nearest into the future."
  688. :group 'org-agenda-daily/weekly
  689. :type 'boolean)
  690. (defcustom org-scheduled-past-days 10000
  691. "No. of days to continue listing scheduled items that are not marked DONE.
  692. When an item is scheduled on a date, it shows up in the agenda on this
  693. day and will be listed until it is marked done for the number of days
  694. given here."
  695. :group 'org-agenda-daily/weekly
  696. :type 'integer)
  697. (defcustom org-agenda-log-mode-items '(closed clock)
  698. "List of items that should be shown in agenda log mode.
  699. This list may contain the following symbols:
  700. closed Show entries that have been closed on that day.
  701. clock Show entries that have received clocked time on that day.
  702. state Show all logged state changes.
  703. Note that instead of changing this variable, you can also press `C-u l' in
  704. the agenda to display all available LOG items temporarily."
  705. :group 'org-agenda-daily/weekly
  706. :type '(set :greedy t (const closed) (const clock) (const state)))
  707. (defcustom org-agenda-log-mode-add-notes t
  708. "Non-nil means, add first line of notes to log entries in agenda views.
  709. If a log item like a state change or a clock entry is associated with
  710. notes, the first line of these notes will be added to the entry in the
  711. agenda display."
  712. :group 'org-agenda-daily/weekly
  713. :type 'boolean)
  714. (defcustom org-agenda-start-with-log-mode nil
  715. "The initial value of log-mode in a newly created agenda window."
  716. :group 'org-agenda-startup
  717. :group 'org-agenda-daily/weekly
  718. :type 'boolean)
  719. (defcustom org-agenda-start-with-clockreport-mode nil
  720. "The initial value of clockreport-mode in a newly created agenda window."
  721. :group 'org-agenda-startup
  722. :group 'org-agenda-daily/weekly
  723. :type 'boolean)
  724. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  725. "Property list with parameters for the clocktable in clockreport mode.
  726. This is the display mode that shows a clock table in the daily/weekly
  727. agenda, the properties for this dynamic block can be set here.
  728. The usual clocktable parameters are allowed here, but you cannot set
  729. the properties :name, :tstart, :tend, :block, and :scope - these will
  730. be overwritten to make sure the content accurately reflects the
  731. current display in the agenda."
  732. :group 'org-agenda-daily/weekly
  733. :type 'plist)
  734. (defgroup org-agenda-time-grid nil
  735. "Options concerning the time grid in the Org-mode Agenda."
  736. :tag "Org Agenda Time Grid"
  737. :group 'org-agenda)
  738. (defcustom org-agenda-search-headline-for-time t
  739. "Non-nil means, search headline for a time-of-day.
  740. If the headline contains a time-of-day in one format or another, it will
  741. be used to sort the entry into the time sequence of items for a day.
  742. Some people have time stamps in the headline that refer to the creation
  743. time or so, and then this produces an unwanted side effect. If this is
  744. the case for your, use this variable to turn off searching the headline
  745. for a time."
  746. :group 'org-agenda-time-grid
  747. :type 'boolean)
  748. (defcustom org-agenda-use-time-grid t
  749. "Non-nil means, show a time grid in the agenda schedule.
  750. A time grid is a set of lines for specific times (like every two hours between
  751. 8:00 and 20:00). The items scheduled for a day at specific times are
  752. sorted in between these lines.
  753. For details about when the grid will be shown, and what it will look like, see
  754. the variable `org-agenda-time-grid'."
  755. :group 'org-agenda-time-grid
  756. :type 'boolean)
  757. (defcustom org-agenda-time-grid
  758. '((daily today require-timed)
  759. "----------------"
  760. (800 1000 1200 1400 1600 1800 2000))
  761. "The settings for time grid for agenda display.
  762. This is a list of three items. The first item is again a list. It contains
  763. symbols specifying conditions when the grid should be displayed:
  764. daily if the agenda shows a single day
  765. weekly if the agenda shows an entire week
  766. today show grid on current date, independent of daily/weekly display
  767. require-timed show grid only if at least one item has a time specification
  768. The second item is a string which will be placed behind the grid time.
  769. The third item is a list of integers, indicating the times that should have
  770. a grid line."
  771. :group 'org-agenda-time-grid
  772. :type
  773. '(list
  774. (set :greedy t :tag "Grid Display Options"
  775. (const :tag "Show grid in single day agenda display" daily)
  776. (const :tag "Show grid in weekly agenda display" weekly)
  777. (const :tag "Always show grid for today" today)
  778. (const :tag "Show grid only if any timed entries are present"
  779. require-timed)
  780. (const :tag "Skip grid times already present in an entry"
  781. remove-match))
  782. (string :tag "Grid String")
  783. (repeat :tag "Grid Times" (integer :tag "Time"))))
  784. (defgroup org-agenda-sorting nil
  785. "Options concerning sorting in the Org-mode Agenda."
  786. :tag "Org Agenda Sorting"
  787. :group 'org-agenda)
  788. (defcustom org-agenda-sorting-strategy
  789. '((agenda time-up priority-down category-keep)
  790. (todo priority-down category-keep)
  791. (tags priority-down category-keep)
  792. (search category-keep))
  793. "Sorting structure for the agenda items of a single day.
  794. This is a list of symbols which will be used in sequence to determine
  795. if an entry should be listed before another entry. The following
  796. symbols are recognized:
  797. time-up Put entries with time-of-day indications first, early first
  798. time-down Put entries with time-of-day indications first, late first
  799. category-keep Keep the default order of categories, corresponding to the
  800. sequence in `org-agenda-files'.
  801. category-up Sort alphabetically by category, A-Z.
  802. category-down Sort alphabetically by category, Z-A.
  803. tag-up Sort alphabetically by last tag, A-Z.
  804. tag-down Sort alphabetically by last tag, Z-A.
  805. priority-up Sort numerically by priority, high priority last.
  806. priority-down Sort numerically by priority, high priority first.
  807. todo-state-up Sort by todo state, tasks that are done last.
  808. todo-state-down Sort by todo state, tasks that are done first.
  809. effort-up Sort numerically by estimated effort, high effort last.
  810. effort-down Sort numerically by estimated effort, high effort first.
  811. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  812. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  813. The different possibilities will be tried in sequence, and testing stops
  814. if one comparison returns a \"not-equal\". For example, the default
  815. '(time-up category-keep priority-down)
  816. means: Pull out all entries having a specified time of day and sort them,
  817. in order to make a time schedule for the current day the first thing in the
  818. agenda listing for the day. Of the entries without a time indication, keep
  819. the grouped in categories, don't sort the categories, but keep them in
  820. the sequence given in `org-agenda-files'. Within each category sort by
  821. priority.
  822. Leaving out `category-keep' would mean that items will be sorted across
  823. categories by priority.
  824. Instead of a single list, this can also be a set of list for specific
  825. contents, with a context symbol in the car of the list, any of
  826. `agenda', `todo', `tags' for the corresponding agenda views.
  827. Custom commands can bind this variable in the options section."
  828. :group 'org-agenda-sorting
  829. :type `(choice
  830. (repeat :tag "General" ,org-sorting-choice)
  831. (list :tag "Individually"
  832. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  833. (repeat ,org-sorting-choice))
  834. (cons (const :tag "Strategy for TODO lists" todo)
  835. (repeat ,org-sorting-choice))
  836. (cons (const :tag "Strategy for Tags matches" tags)
  837. (repeat ,org-sorting-choice)))))
  838. (defcustom org-agenda-cmp-user-defined nil
  839. "A function to define the comparison `user-defined'.
  840. This function must receive two arguments, agenda entry a and b.
  841. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  842. the user comparison, return nil.
  843. When this is defined, you can make `user-defined-up' and `user-defined-down'
  844. part of an agenda sorting strategy."
  845. :group 'org-agenda-sorting
  846. :type 'symbol)
  847. (defcustom org-sort-agenda-notime-is-late t
  848. "Non-nil means, items without time are considered late.
  849. This is only relevant for sorting. When t, items which have no explicit
  850. time like 15:30 will be considered as 99:01, i.e. later than any items which
  851. do have a time. When nil, the default time is before 0:00. You can use this
  852. option to decide if the schedule for today should come before or after timeless
  853. agenda entries."
  854. :group 'org-agenda-sorting
  855. :type 'boolean)
  856. (defcustom org-sort-agenda-noeffort-is-high t
  857. "Non-nil means, items without effort estimate are sorted as high effort.
  858. This also applies when filtering an agenda view with respect to the
  859. < or > effort operator. Then, tasks with no effort defined will be treated
  860. as tasks with high effort.
  861. When nil, such items are sorted as 0 minutes effort."
  862. :group 'org-agenda-sorting
  863. :type 'boolean)
  864. (defgroup org-agenda-line-format nil
  865. "Options concerning the entry prefix in the Org-mode agenda display."
  866. :tag "Org Agenda Line Format"
  867. :group 'org-agenda)
  868. (defcustom org-agenda-prefix-format
  869. '((agenda . " %-12:c%?-12t% s")
  870. (timeline . " % s")
  871. (todo . " %-12:c")
  872. (tags . " %-12:c")
  873. (search . " %-12:c"))
  874. "Format specifications for the prefix of items in the agenda views.
  875. An alist with four entries, for the different agenda types. The keys to the
  876. sublists are `agenda', `timeline', `todo', and `tags'. The values
  877. are format strings.
  878. This format works similar to a printf format, with the following meaning:
  879. %c the category of the item, \"Diary\" for entries from the diary, or
  880. as given by the CATEGORY keyword or derived from the file name.
  881. %T the *last* tag of the item. Last because inherited tags come
  882. first in the list.
  883. %t the time-of-day specification if one applies to the entry, in the
  884. format HH:MM
  885. %s Scheduling/Deadline information, a short string
  886. All specifiers work basically like the standard `%s' of printf, but may
  887. contain two additional characters: A question mark just after the `%' and
  888. a whitespace/punctuation character just before the final letter.
  889. If the first character after `%' is a question mark, the entire field
  890. will only be included if the corresponding value applies to the
  891. current entry. This is useful for fields which should have fixed
  892. width when present, but zero width when absent. For example,
  893. \"%?-12t\" will result in a 12 character time field if a time of the
  894. day is specified, but will completely disappear in entries which do
  895. not contain a time.
  896. If there is punctuation or whitespace character just before the final
  897. format letter, this character will be appended to the field value if
  898. the value is not empty. For example, the format \"%-12:c\" leads to
  899. \"Diary: \" if the category is \"Diary\". If the category were be
  900. empty, no additional colon would be interted.
  901. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  902. - Indent the line with two space characters
  903. - Give the category in a 12 chars wide field, padded with whitespace on
  904. the right (because of `-'). Append a colon if there is a category
  905. (because of `:').
  906. - If there is a time-of-day, put it into a 12 chars wide field. If no
  907. time, don't put in an empty field, just skip it (because of '?').
  908. - Finally, put the scheduling information and append a whitespace.
  909. As another example, if you don't want the time-of-day of entries in
  910. the prefix, you could use:
  911. (setq org-agenda-prefix-format \" %-11:c% s\")
  912. See also the variables `org-agenda-remove-times-when-in-prefix' and
  913. `org-agenda-remove-tags'.
  914. Custom commands can set this variable in the options section."
  915. :type '(choice
  916. (string :tag "General format")
  917. (list :greedy t :tag "View dependent"
  918. (cons (const agenda) (string :tag "Format"))
  919. (cons (const timeline) (string :tag "Format"))
  920. (cons (const todo) (string :tag "Format"))
  921. (cons (const tags) (string :tag "Format"))
  922. (cons (const search) (string :tag "Format"))))
  923. :group 'org-agenda-line-format)
  924. (defvar org-prefix-format-compiled nil
  925. "The compiled version of the most recently used prefix format.
  926. See the variable `org-agenda-prefix-format'.")
  927. (defcustom org-agenda-todo-keyword-format "%-1s"
  928. "Format for the TODO keyword in agenda lines.
  929. Set this to something like \"%-12s\" if you want all TODO keywords
  930. to occupy a fixed space in the agenda display."
  931. :group 'org-agenda-line-format
  932. :type 'string)
  933. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  934. "Text preceding timerange entries in the agenda view.
  935. This is a list with two strings. The first applies when the range
  936. is entirely on one day. The second applies if the range spans several days.
  937. The strings may have two \"%d\" format specifiers which will be filled
  938. with the sequence number of the days, and the total number of days in the
  939. range, respectively."
  940. :group 'org-agenda-line-format
  941. :type '(list
  942. (string :tag "Deadline today ")
  943. (choice :tag "Deadline relative"
  944. (string :tag "Format string")
  945. (function))))
  946. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  947. "Text preceeding scheduled items in the agenda view.
  948. This is a list with two strings. The first applies when the item is
  949. scheduled on the current day. The second applies when it has been scheduled
  950. previously, it may contain a %d indicating that this is the nth time that
  951. this item is scheduled, due to automatic rescheduling of unfinished items
  952. for the following day. So this number is one larger than the number of days
  953. that passed since this item was scheduled first."
  954. :group 'org-agenda-line-format
  955. :type '(list
  956. (string :tag "Scheduled today ")
  957. (string :tag "Scheduled previously")))
  958. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  959. "Text preceeding deadline items in the agenda view.
  960. This is a list with two strings. The first applies when the item has its
  961. deadline on the current day. The second applies when it is in the past or
  962. in the future, it may contain %d to capture how many days away the deadline
  963. is (was)."
  964. :group 'org-agenda-line-format
  965. :type '(list
  966. (string :tag "Deadline today ")
  967. (choice :tag "Deadline relative"
  968. (string :tag "Format string")
  969. (function))))
  970. (defcustom org-agenda-remove-times-when-in-prefix t
  971. "Non-nil means, remove duplicate time specifications in agenda items.
  972. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  973. time-of-day specification in a headline or diary entry is extracted and
  974. placed into the prefix. If this option is non-nil, the original specification
  975. \(a timestamp or -range, or just a plain time(range) specification like
  976. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  977. cluttered.
  978. The option can be t or nil. It may also be the symbol `beg', indicating
  979. that the time should only be removed what it is located at the beginning of
  980. the headline/diary entry."
  981. :group 'org-agenda-line-format
  982. :type '(choice
  983. (const :tag "Always" t)
  984. (const :tag "Never" nil)
  985. (const :tag "When at beginning of entry" beg)))
  986. (defcustom org-agenda-default-appointment-duration nil
  987. "Default duration for appointments that only have a starting time.
  988. When nil, no duration is specified in such cases.
  989. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  990. :group 'org-agenda-line-format
  991. :type '(choice
  992. (integer :tag "Minutes")
  993. (const :tag "No default duration")))
  994. (defcustom org-agenda-show-inherited-tags t
  995. "Non-nil means, show inherited tags in each agenda line."
  996. :group 'org-agenda-line-format
  997. :type 'boolean)
  998. (defcustom org-agenda-remove-tags nil
  999. "Non-nil means, remove the tags from the headline copy in the agenda.
  1000. When this is the symbol `prefix', only remove tags when
  1001. `org-agenda-prefix-format' contains a `%T' specifier."
  1002. :group 'org-agenda-line-format
  1003. :type '(choice
  1004. (const :tag "Always" t)
  1005. (const :tag "Never" nil)
  1006. (const :tag "When prefix format contains %T" prefix)))
  1007. (if (fboundp 'defvaralias)
  1008. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1009. 'org-agenda-remove-tags))
  1010. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1011. "Shift tags in agenda items to this column.
  1012. If this number is positive, it specifies the column. If it is negative,
  1013. it means that the tags should be flushright to that column. For example,
  1014. -80 works well for a normal 80 character screen."
  1015. :group 'org-agenda-line-format
  1016. :type 'integer)
  1017. (if (fboundp 'defvaralias)
  1018. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1019. (defcustom org-agenda-fontify-priorities 'cookies
  1020. "Non-nil means, highlight low and high priorities in agenda.
  1021. When t, the highest priority entries are bold, lowest priority italic.
  1022. However, settings in org-priority-faces will overrule these faces.
  1023. When this variable is the symbol `cookies', only fontify the
  1024. cookies, not the entire task.
  1025. This may also be an association list of priority faces, whose
  1026. keys are the character values of `org-highest-priority',
  1027. `org-default-priority', and `org-lowest-priority' (the default values
  1028. are ?A, ?B, and ?C, respectively). The face may be a named face,
  1029. or a list like `(:background \"Red\")'."
  1030. :group 'org-agenda-line-format
  1031. :type '(choice
  1032. (const :tag "Never" nil)
  1033. (const :tag "Defaults" t)
  1034. (const :tag "Cookies only" cookies)
  1035. (repeat :tag "Specify"
  1036. (list (character :tag "Priority" :value ?A)
  1037. (sexp :tag "face")))))
  1038. (defgroup org-agenda-column-view nil
  1039. "Options concerning column view in the agenda."
  1040. :tag "Org Agenda Column View"
  1041. :group 'org-agenda)
  1042. (defcustom org-agenda-columns-show-summaries t
  1043. "Non-nil means, show summaries for columns displayed in the agenda view."
  1044. :group 'org-agenda-column-view
  1045. :type 'boolean)
  1046. (defcustom org-agenda-columns-remove-prefix-from-item t
  1047. "Non-nil means, remove the prefix from a headline for agenda column view.
  1048. The special ITEM field in the columns format contains the current line, with
  1049. all information shown in other columns (like the TODO state or a tag).
  1050. When this variable is non-nil, also the agenda prefix will be removed from
  1051. the content of the ITEM field, to make sure as much as possible of the
  1052. headline can be shown in the limited width of the field."
  1053. :group 'org-agenda
  1054. :type 'boolean)
  1055. (defcustom org-agenda-columns-compute-summary-properties t
  1056. "Non-nil means, recompute all summary properties before column view.
  1057. When column view in the agenda is listing properties that have a summary
  1058. operator, it can go to all relevant buffers and recompute the summaries
  1059. there. This can mean overhead for the agenda column view, but is necessary
  1060. to have thing up to date.
  1061. As a special case, a CLOCKSUM property also makes sure that the clock
  1062. computations are current."
  1063. :group 'org-agenda-column-view
  1064. :type 'boolean)
  1065. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1066. "Non-nil means, the duration of an appointment will add to day effort.
  1067. The property to which appointment durations will be added is the one given
  1068. in the option `org-effort-property'. If an appointment does not have
  1069. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1070. is not set, an appointment without end time will not contribute to the time
  1071. estimate."
  1072. :group 'org-agenda-column-view
  1073. :type 'boolean)
  1074. (eval-when-compile
  1075. (require 'cl))
  1076. (require 'org)
  1077. (defun org-add-agenda-custom-command (entry)
  1078. "Replace or add a command in `org-agenda-custom-commands'.
  1079. This is mostly for hacking and trying a new command - once the command
  1080. works you probably want to add it to `org-agenda-custom-commands' for good."
  1081. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1082. (if ass
  1083. (setcdr ass (cdr entry))
  1084. (push entry org-agenda-custom-commands))))
  1085. ;;; Define the Org-agenda-mode
  1086. (defvar org-agenda-mode-map (make-sparse-keymap)
  1087. "Keymap for `org-agenda-mode'.")
  1088. (defvar org-agenda-menu) ; defined later in this file.
  1089. (defvar org-agenda-restrict) ; defined later in this file.
  1090. (defvar org-agenda-follow-mode nil)
  1091. (defvar org-agenda-clockreport-mode nil)
  1092. (defvar org-agenda-show-log nil)
  1093. (defvar org-agenda-redo-command nil)
  1094. (defvar org-agenda-query-string nil)
  1095. (defvar org-agenda-mode-hook nil
  1096. "Hook for org-agenda-mode, run after the mode is turned on.")
  1097. (defvar org-agenda-type nil)
  1098. (defvar org-agenda-force-single-file nil)
  1099. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1100. (defun org-agenda-mode ()
  1101. "Mode for time-sorted view on action items in Org-mode files.
  1102. The following commands are available:
  1103. \\{org-agenda-mode-map}"
  1104. (interactive)
  1105. (kill-all-local-variables)
  1106. (setq org-agenda-undo-list nil
  1107. org-agenda-pending-undo-list nil
  1108. org-agenda-bulk-marked-entries nil)
  1109. (setq major-mode 'org-agenda-mode)
  1110. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1111. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1112. (setq mode-name "Org-Agenda")
  1113. (use-local-map org-agenda-mode-map)
  1114. (easy-menu-add org-agenda-menu)
  1115. (if org-startup-truncated (setq truncate-lines t))
  1116. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1117. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1118. ;; Make sure properties are removed when copying text
  1119. (when (boundp 'buffer-substring-filters)
  1120. (org-set-local 'buffer-substring-filters
  1121. (cons (lambda (x)
  1122. (set-text-properties 0 (length x) nil x) x)
  1123. buffer-substring-filters)))
  1124. (unless org-agenda-keep-modes
  1125. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1126. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1127. org-agenda-show-log org-agenda-start-with-log-mode))
  1128. (easy-menu-change
  1129. '("Agenda") "Agenda Files"
  1130. (append
  1131. (list
  1132. (vector
  1133. (if (get 'org-agenda-files 'org-restrict)
  1134. "Restricted to single file"
  1135. "Edit File List")
  1136. '(org-edit-agenda-file-list)
  1137. (not (get 'org-agenda-files 'org-restrict)))
  1138. "--")
  1139. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1140. (org-agenda-set-mode-name)
  1141. (apply
  1142. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1143. (list 'org-agenda-mode-hook)))
  1144. (substitute-key-definition 'undo 'org-agenda-undo
  1145. org-agenda-mode-map global-map)
  1146. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1147. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1148. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1149. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1150. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1151. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1152. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1153. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1154. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1155. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1156. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1157. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1158. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1159. (org-defkey org-agenda-mode-map "A" 'org-agenda-archive-to-archive-sibling)
  1160. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1161. (org-defkey org-agenda-mode-map " " 'org-agenda-show)
  1162. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1163. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1164. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1165. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1166. (org-defkey org-agenda-mode-map "b" 'org-agenda-tree-to-indirect-buffer)
  1167. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1168. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1169. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1170. (org-defkey org-agenda-mode-map "a" 'org-agenda-toggle-archive-tag)
  1171. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1172. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1173. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1174. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1175. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1176. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1177. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1178. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1179. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1180. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1181. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1182. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1183. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1184. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1185. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1186. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1187. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1188. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1189. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1190. (while l (org-defkey org-agenda-mode-map
  1191. (int-to-string (pop l)) 'digit-argument)))
  1192. (org-defkey org-agenda-mode-map "f" 'org-agenda-follow-mode)
  1193. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1194. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1195. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1196. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1197. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1198. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1199. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1200. (org-defkey org-agenda-mode-map "e" 'org-agenda-execute)
  1201. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1202. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1203. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1204. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1205. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1206. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1207. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1208. (org-defkey org-agenda-mode-map "n" 'next-line)
  1209. (org-defkey org-agenda-mode-map "p" 'previous-line)
  1210. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1211. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1212. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1213. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1214. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1215. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1216. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1217. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1218. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1219. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1220. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1221. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1222. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1223. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1224. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1225. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1226. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1227. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1228. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1229. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1230. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1231. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1232. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1233. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1234. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1235. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1236. (org-defkey org-agenda-mode-map [(right)] 'org-agenda-later)
  1237. (org-defkey org-agenda-mode-map [(left)] 'org-agenda-earlier)
  1238. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1239. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1240. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1241. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1242. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1243. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1244. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1245. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1246. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1247. (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
  1248. "Local keymap for agenda entries from Org-mode.")
  1249. (org-defkey org-agenda-keymap
  1250. (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
  1251. (org-defkey org-agenda-keymap
  1252. (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
  1253. (when org-agenda-mouse-1-follows-link
  1254. (org-defkey org-agenda-keymap [follow-link] 'mouse-face))
  1255. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1256. '("Agenda"
  1257. ("Agenda Files")
  1258. "--"
  1259. ["Show" org-agenda-show t]
  1260. ["Go To (other window)" org-agenda-goto t]
  1261. ["Go To (this window)" org-agenda-switch-to t]
  1262. ["Follow Mode" org-agenda-follow-mode
  1263. :style toggle :selected org-agenda-follow-mode :active t]
  1264. ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1265. "--"
  1266. ["Cycle TODO" org-agenda-todo t]
  1267. ("Archive and Refile"
  1268. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1269. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1270. ["Archive subtree" org-agenda-archive t]
  1271. ["Refile" org-agenda-refile t])
  1272. ["Delete subtree" org-agenda-kill t]
  1273. ("Bulk action"
  1274. ["Toggle mark entry" org-agenda-bulk-mark t]
  1275. ["Act on all marked" org-agenda-bulk-action t]
  1276. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1277. "--"
  1278. ["Add note" org-agenda-add-note t]
  1279. "--"
  1280. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1281. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1282. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1283. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)]
  1284. "--"
  1285. ("Tags and Properties"
  1286. ["Show all Tags" org-agenda-show-tags t]
  1287. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1288. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1289. "--"
  1290. ["Column View" org-columns t])
  1291. ("Date/Schedule"
  1292. ["Schedule" org-agenda-schedule t]
  1293. ["Set Deadline" org-agenda-deadline t]
  1294. "--"
  1295. ["Mark item" org-agenda-action :active t :keys "k m"]
  1296. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1297. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1298. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1299. "--"
  1300. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1301. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1302. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1303. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1304. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1305. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1306. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1307. ("Clock"
  1308. ["Clock in" org-agenda-clock-in t]
  1309. ["Clock out" org-agenda-clock-out t]
  1310. ["Clock cancel" org-agenda-clock-cancel t]
  1311. ["Goto running clock" org-clock-goto t])
  1312. ("Priority"
  1313. ["Set Priority" org-agenda-priority t]
  1314. ["Increase Priority" org-agenda-priority-up t]
  1315. ["Decrease Priority" org-agenda-priority-down t]
  1316. ["Show Priority" org-agenda-show-priority t])
  1317. ("Calendar/Diary"
  1318. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1319. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1320. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1321. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1322. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1323. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1324. "--"
  1325. ["Create iCalendar file" org-export-icalendar-combine-agenda-files t])
  1326. "--"
  1327. ("View"
  1328. ["Day View" org-agenda-day-view
  1329. :active (org-agenda-check-type nil 'agenda)
  1330. :style radio :selected (equal org-agenda-ndays 1)
  1331. :keys "v d (or just d)"]
  1332. ["Week View" org-agenda-week-view
  1333. :active (org-agenda-check-type nil 'agenda)
  1334. :style radio :selected (equal org-agenda-ndays 7)
  1335. :keys "v w (or just w)"]
  1336. ["Month View" org-agenda-month-view
  1337. :active (org-agenda-check-type nil 'agenda)
  1338. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1339. :keys "v m"]
  1340. ["Year View" org-agenda-year-view
  1341. :active (org-agenda-check-type nil 'agenda)
  1342. :style radio :selected (member org-agenda-ndays '(365 366))
  1343. :keys "v y"]
  1344. "--"
  1345. ["Include Diary" org-agenda-toggle-diary
  1346. :style toggle :selected org-agenda-include-diary
  1347. :active (org-agenda-check-type nil 'agenda)]
  1348. ["Use Time Grid" org-agenda-toggle-time-grid
  1349. :style toggle :selected org-agenda-use-time-grid
  1350. :active (org-agenda-check-type nil 'agenda)]
  1351. "--"
  1352. ["Show clock report" org-agenda-clockreport-mode
  1353. :style toggle :selected org-agenda-clockreport-mode
  1354. :active (org-agenda-check-type nil 'agenda)]
  1355. "--"
  1356. ["Show Logbook entries" org-agenda-log-mode
  1357. :style toggle :selected org-agenda-show-log
  1358. :active (org-agenda-check-type nil 'agenda 'timeline)
  1359. :keys "v l (or just l)"]
  1360. ["Include archived trees" org-agenda-archives-mode
  1361. :style toggle :selected org-agenda-archives-mode :active t
  1362. :keys "v a"]
  1363. ["Include archive files" (org-agenda-archives-mode t)
  1364. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1365. :keys "v A"]
  1366. "--"
  1367. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1368. ["Write view to file" org-write-agenda t]
  1369. ["Rebuild buffer" org-agenda-redo t]
  1370. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1371. "--"
  1372. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1373. "--"
  1374. ["Quit" org-agenda-quit t]
  1375. ["Exit and Release Buffers" org-agenda-exit t]
  1376. ))
  1377. ;;; Agenda undo
  1378. (defvar org-agenda-allow-remote-undo t
  1379. "Non-nil means, allow remote undo from the agenda buffer.")
  1380. (defvar org-agenda-undo-list nil
  1381. "List of undoable operations in the agenda since last refresh.")
  1382. (defvar org-agenda-undo-has-started-in nil
  1383. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1384. (defvar org-agenda-pending-undo-list nil
  1385. "In a series of undo commands, this is the list of remaining undo items.")
  1386. (defun org-agenda-undo ()
  1387. "Undo a remote editing step in the agenda.
  1388. This undoes changes both in the agenda buffer and in the remote buffer
  1389. that have been changed along."
  1390. (interactive)
  1391. (or org-agenda-allow-remote-undo
  1392. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
  1393. (if (not (eq this-command last-command))
  1394. (setq org-agenda-undo-has-started-in nil
  1395. org-agenda-pending-undo-list org-agenda-undo-list))
  1396. (if (not org-agenda-pending-undo-list)
  1397. (error "No further undo information"))
  1398. (let* ((entry (pop org-agenda-pending-undo-list))
  1399. buf line cmd rembuf)
  1400. (setq cmd (pop entry) line (pop entry))
  1401. (setq rembuf (nth 2 entry))
  1402. (org-with-remote-undo rembuf
  1403. (while (bufferp (setq buf (pop entry)))
  1404. (if (pop entry)
  1405. (with-current-buffer buf
  1406. (let ((last-undo-buffer buf)
  1407. (inhibit-read-only t))
  1408. (unless (memq buf org-agenda-undo-has-started-in)
  1409. (push buf org-agenda-undo-has-started-in)
  1410. (make-local-variable 'pending-undo-list)
  1411. (undo-start))
  1412. (while (and pending-undo-list
  1413. (listp pending-undo-list)
  1414. (not (car pending-undo-list)))
  1415. (pop pending-undo-list))
  1416. (undo-more 1))))))
  1417. (goto-line line)
  1418. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1419. (defun org-verify-change-for-undo (l1 l2)
  1420. "Verify that a real change occurred between the undo lists L1 and L2."
  1421. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1422. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1423. (not (eq l1 l2)))
  1424. ;;; Agenda dispatch
  1425. (defvar org-agenda-restrict nil)
  1426. (defvar org-agenda-restrict-begin (make-marker))
  1427. (defvar org-agenda-restrict-end (make-marker))
  1428. (defvar org-agenda-last-dispatch-buffer nil)
  1429. (defvar org-agenda-overriding-restriction nil)
  1430. ;;;###autoload
  1431. (defun org-agenda (&optional arg keys restriction)
  1432. "Dispatch agenda commands to collect entries to the agenda buffer.
  1433. Prompts for a command to execute. Any prefix arg will be passed
  1434. on to the selected command. The default selections are:
  1435. a Call `org-agenda-list' to display the agenda for current day or week.
  1436. t Call `org-todo-list' to display the global todo list.
  1437. T Call `org-todo-list' to display the global todo list, select only
  1438. entries with a specific TODO keyword (the user gets a prompt).
  1439. m Call `org-tags-view' to display headlines with tags matching
  1440. a condition (the user is prompted for the condition).
  1441. M Like `m', but select only TODO entries, no ordinary headlines.
  1442. L Create a timeline for the current buffer.
  1443. e Export views to associated files.
  1444. s Search entries for keywords.
  1445. / Multi occur accros all agenda files and also files listed
  1446. in `org-agenda-text-search-extra-files'.
  1447. < Restrict agenda commands to buffer, subtree, or region.
  1448. Press several times to get the desired effect.
  1449. > Remove a previous restriction.
  1450. # List \"stuck\" projects.
  1451. ! Configure what \"stuck\" means.
  1452. C Configure custom agenda commands.
  1453. More commands can be added by configuring the variable
  1454. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1455. searches can be pre-defined in this way.
  1456. If the current buffer is in Org-mode and visiting a file, you can also
  1457. first press `<' once to indicate that the agenda should be temporarily
  1458. \(until the next use of \\[org-agenda]) restricted to the current file.
  1459. Pressing `<' twice means to restrict to the current subtree or region
  1460. \(if active)."
  1461. (interactive "P")
  1462. (catch 'exit
  1463. (let* ((prefix-descriptions nil)
  1464. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1465. (org-agenda-custom-commands
  1466. ;; normalize different versions
  1467. (delq nil
  1468. (mapcar
  1469. (lambda (x)
  1470. (cond ((stringp (cdr x))
  1471. (push x prefix-descriptions)
  1472. nil)
  1473. ((stringp (nth 1 x)) x)
  1474. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1475. (t (cons (car x) (cons "" (cdr x))))))
  1476. org-agenda-custom-commands)))
  1477. (buf (current-buffer))
  1478. (bfn (buffer-file-name (buffer-base-buffer)))
  1479. entry key type match lprops ans)
  1480. ;; Turn off restriction unless there is an overriding one
  1481. (unless org-agenda-overriding-restriction
  1482. (put 'org-agenda-files 'org-restrict nil)
  1483. (setq org-agenda-restrict nil)
  1484. (move-marker org-agenda-restrict-begin nil)
  1485. (move-marker org-agenda-restrict-end nil))
  1486. ;; Delete old local properties
  1487. (put 'org-agenda-redo-command 'org-lprops nil)
  1488. ;; Remember where this call originated
  1489. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1490. (unless keys
  1491. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1492. keys (car ans)
  1493. restriction (cdr ans)))
  1494. ;; Estabish the restriction, if any
  1495. (when (and (not org-agenda-overriding-restriction) restriction)
  1496. (put 'org-agenda-files 'org-restrict (list bfn))
  1497. (cond
  1498. ((eq restriction 'region)
  1499. (setq org-agenda-restrict t)
  1500. (move-marker org-agenda-restrict-begin (region-beginning))
  1501. (move-marker org-agenda-restrict-end (region-end)))
  1502. ((eq restriction 'subtree)
  1503. (save-excursion
  1504. (setq org-agenda-restrict t)
  1505. (org-back-to-heading t)
  1506. (move-marker org-agenda-restrict-begin (point))
  1507. (move-marker org-agenda-restrict-end
  1508. (progn (org-end-of-subtree t)))))))
  1509. (require 'calendar) ; FIXME: can we avoid this for some commands?
  1510. ;; For example the todo list should not need it (but does...)
  1511. (cond
  1512. ((setq entry (assoc keys org-agenda-custom-commands))
  1513. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1514. (progn
  1515. (setq type (nth 2 entry) match (nth 3 entry) lprops (nth 4 entry))
  1516. (put 'org-agenda-redo-command 'org-lprops lprops)
  1517. (cond
  1518. ((eq type 'agenda)
  1519. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1520. ((eq type 'alltodo)
  1521. (org-let lprops '(org-todo-list current-prefix-arg)))
  1522. ((eq type 'search)
  1523. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1524. ((eq type 'stuck)
  1525. (org-let lprops '(org-agenda-list-stuck-projects
  1526. current-prefix-arg)))
  1527. ((eq type 'tags)
  1528. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1529. ((eq type 'tags-todo)
  1530. (org-let lprops '(org-tags-view '(4) match)))
  1531. ((eq type 'todo)
  1532. (org-let lprops '(org-todo-list match)))
  1533. ((eq type 'tags-tree)
  1534. (org-check-for-org-mode)
  1535. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1536. ((eq type 'todo-tree)
  1537. (org-check-for-org-mode)
  1538. (org-let lprops
  1539. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1540. (regexp-quote match) "\\>"))))
  1541. ((eq type 'occur-tree)
  1542. (org-check-for-org-mode)
  1543. (org-let lprops '(org-occur match)))
  1544. ((functionp type)
  1545. (org-let lprops '(funcall type match)))
  1546. ((fboundp type)
  1547. (org-let lprops '(funcall type match)))
  1548. (t (error "Invalid custom agenda command type %s" type))))
  1549. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1550. ((equal keys "C")
  1551. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1552. (customize-variable 'org-agenda-custom-commands))
  1553. ((equal keys "a") (call-interactively 'org-agenda-list))
  1554. ((equal keys "s") (call-interactively 'org-search-view))
  1555. ((equal keys "t") (call-interactively 'org-todo-list))
  1556. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1557. ((equal keys "m") (call-interactively 'org-tags-view))
  1558. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1559. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1560. ((equal keys "L")
  1561. (unless (org-mode-p)
  1562. (error "This is not an Org-mode file"))
  1563. (unless restriction
  1564. (put 'org-agenda-files 'org-restrict (list bfn))
  1565. (org-call-with-arg 'org-timeline arg)))
  1566. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1567. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1568. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1569. (t (error "Invalid agenda key"))))))
  1570. (defun org-agenda-normalize-custom-commands (cmds)
  1571. (delq nil
  1572. (mapcar
  1573. (lambda (x)
  1574. (cond ((stringp (cdr x)) nil)
  1575. ((stringp (nth 1 x)) x)
  1576. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1577. (t (cons (car x) (cons "" (cdr x))))))
  1578. cmds)))
  1579. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1580. "The user interface for selecting an agenda command."
  1581. (catch 'exit
  1582. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1583. (restrict-ok (and bfn (org-mode-p)))
  1584. (region-p (org-region-active-p))
  1585. (custom org-agenda-custom-commands)
  1586. (selstring "")
  1587. restriction second-time
  1588. c entry key type match prefixes rmheader header-end custom1 desc)
  1589. (save-window-excursion
  1590. (delete-other-windows)
  1591. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1592. (erase-buffer)
  1593. (insert (eval-when-compile
  1594. (let ((header
  1595. "
  1596. Press key for an agenda command: < Buffer, subtree/region restriction
  1597. -------------------------------- > Remove restriction
  1598. a Agenda for current week or day e Export agenda views
  1599. t List of all TODO entries T Entries with special TODO kwd
  1600. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1601. L Timeline for current buffer # List stuck projects (!=configure)
  1602. s Search for keywords C Configure custom agenda commands
  1603. / Multi-occur
  1604. ")
  1605. (start 0))
  1606. (while (string-match
  1607. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1608. header start)
  1609. (setq start (match-end 0))
  1610. (add-text-properties (match-beginning 2) (match-end 2)
  1611. '(face bold) header))
  1612. header)))
  1613. (setq header-end (move-marker (make-marker) (point)))
  1614. (while t
  1615. (setq custom1 custom)
  1616. (when (eq rmheader t)
  1617. (goto-line 1)
  1618. (re-search-forward ":" nil t)
  1619. (delete-region (match-end 0) (point-at-eol))
  1620. (forward-char 1)
  1621. (looking-at "-+")
  1622. (delete-region (match-end 0) (point-at-eol))
  1623. (move-marker header-end (match-end 0)))
  1624. (goto-char header-end)
  1625. (delete-region (point) (point-max))
  1626. (while (setq entry (pop custom1))
  1627. (setq key (car entry) desc (nth 1 entry)
  1628. type (nth 2 entry) match (nth 3 entry))
  1629. (if (> (length key) 1)
  1630. (add-to-list 'prefixes (string-to-char key))
  1631. (insert
  1632. (format
  1633. "\n%-4s%-14s: %s"
  1634. (org-add-props (copy-sequence key)
  1635. '(face bold))
  1636. (cond
  1637. ((string-match "\\S-" desc) desc)
  1638. ((eq type 'agenda) "Agenda for current week or day")
  1639. ((eq type 'alltodo) "List of all TODO entries")
  1640. ((eq type 'search) "Word search")
  1641. ((eq type 'stuck) "List of stuck projects")
  1642. ((eq type 'todo) "TODO keyword")
  1643. ((eq type 'tags) "Tags query")
  1644. ((eq type 'tags-todo) "Tags (TODO)")
  1645. ((eq type 'tags-tree) "Tags tree")
  1646. ((eq type 'todo-tree) "TODO kwd tree")
  1647. ((eq type 'occur-tree) "Occur tree")
  1648. ((functionp type) (if (symbolp type)
  1649. (symbol-name type)
  1650. "Lambda expression"))
  1651. (t "???"))
  1652. (cond
  1653. ((stringp match)
  1654. (org-add-props match nil 'face 'org-warning))
  1655. (match
  1656. (format "set of %d commands" (length match)))
  1657. (t ""))))))
  1658. (when prefixes
  1659. (mapc (lambda (x)
  1660. (insert
  1661. (format "\n%s %s"
  1662. (org-add-props (char-to-string x)
  1663. nil 'face 'bold)
  1664. (or (cdr (assoc (concat selstring (char-to-string x))
  1665. prefix-descriptions))
  1666. "Prefix key"))))
  1667. prefixes))
  1668. (goto-char (point-min))
  1669. (if second-time
  1670. (if (not (pos-visible-in-window-p (point-max)))
  1671. (org-fit-window-to-buffer))
  1672. (setq second-time t)
  1673. (org-fit-window-to-buffer))
  1674. (message "Press key for agenda command%s:"
  1675. (if (or restrict-ok org-agenda-overriding-restriction)
  1676. (if org-agenda-overriding-restriction
  1677. " (restriction lock active)"
  1678. (if restriction
  1679. (format " (restricted to %s)" restriction)
  1680. " (unrestricted)"))
  1681. ""))
  1682. (setq c (read-char-exclusive))
  1683. (message "")
  1684. (cond
  1685. ((assoc (char-to-string c) custom)
  1686. (setq selstring (concat selstring (char-to-string c)))
  1687. (throw 'exit (cons selstring restriction)))
  1688. ((memq c prefixes)
  1689. (setq selstring (concat selstring (char-to-string c))
  1690. prefixes nil
  1691. rmheader (or rmheader t)
  1692. custom (delq nil (mapcar
  1693. (lambda (x)
  1694. (if (or (= (length (car x)) 1)
  1695. (/= (string-to-char (car x)) c))
  1696. nil
  1697. (cons (substring (car x) 1) (cdr x))))
  1698. custom))))
  1699. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1700. (message "Restriction is only possible in Org-mode buffers")
  1701. (ding) (sit-for 1))
  1702. ((eq c ?1)
  1703. (org-agenda-remove-restriction-lock 'noupdate)
  1704. (setq restriction 'buffer))
  1705. ((eq c ?0)
  1706. (org-agenda-remove-restriction-lock 'noupdate)
  1707. (setq restriction (if region-p 'region 'subtree)))
  1708. ((eq c ?<)
  1709. (org-agenda-remove-restriction-lock 'noupdate)
  1710. (setq restriction
  1711. (cond
  1712. ((eq restriction 'buffer)
  1713. (if region-p 'region 'subtree))
  1714. ((memq restriction '(subtree region))
  1715. nil)
  1716. (t 'buffer))))
  1717. ((eq c ?>)
  1718. (org-agenda-remove-restriction-lock 'noupdate)
  1719. (setq restriction nil))
  1720. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/)))
  1721. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  1722. ((and (> (length selstring) 0) (eq c ?\d))
  1723. (delete-window)
  1724. (org-agenda-get-restriction-and-command prefix-descriptions))
  1725. ((equal c ?q) (error "Abort"))
  1726. (t (error "Invalid key %c" c))))))))
  1727. (defun org-run-agenda-series (name series)
  1728. (org-let (nth 1 series) '(org-prepare-agenda name))
  1729. (let* ((org-agenda-multi t)
  1730. (redo (list 'org-run-agenda-series name (list 'quote series)))
  1731. (cmds (car series))
  1732. (gprops (nth 1 series))
  1733. match ;; The byte compiler incorrectly complains about this. Keep it!
  1734. cmd type lprops)
  1735. (while (setq cmd (pop cmds))
  1736. (setq type (car cmd) match (nth 1 cmd) lprops (nth 2 cmd))
  1737. (cond
  1738. ((eq type 'agenda)
  1739. (org-let2 gprops lprops
  1740. '(call-interactively 'org-agenda-list)))
  1741. ((eq type 'alltodo)
  1742. (org-let2 gprops lprops
  1743. '(call-interactively 'org-todo-list)))
  1744. ((eq type 'search)
  1745. (org-let2 gprops lprops
  1746. '(org-search-view current-prefix-arg match nil)))
  1747. ((eq type 'stuck)
  1748. (org-let2 gprops lprops
  1749. '(call-interactively 'org-agenda-list-stuck-projects)))
  1750. ((eq type 'tags)
  1751. (org-let2 gprops lprops
  1752. '(org-tags-view current-prefix-arg match)))
  1753. ((eq type 'tags-todo)
  1754. (org-let2 gprops lprops
  1755. '(org-tags-view '(4) match)))
  1756. ((eq type 'todo)
  1757. (org-let2 gprops lprops
  1758. '(org-todo-list match)))
  1759. ((fboundp type)
  1760. (org-let2 gprops lprops
  1761. '(funcall type match)))
  1762. (t (error "Invalid type in command series"))))
  1763. (widen)
  1764. (setq org-agenda-redo-command redo)
  1765. (goto-char (point-min)))
  1766. (org-fit-agenda-window)
  1767. (org-let (nth 1 series) '(org-finalize-agenda)))
  1768. ;;;###autoload
  1769. (defmacro org-batch-agenda (cmd-key &rest parameters)
  1770. "Run an agenda command in batch mode and send the result to STDOUT.
  1771. If CMD-KEY is a string of length 1, it is used as a key in
  1772. `org-agenda-custom-commands' and triggers this command. If it is a
  1773. longer string it is used as a tags/todo match string.
  1774. Paramters are alternating variable names and values that will be bound
  1775. before running the agenda command."
  1776. (let (pars)
  1777. (while parameters
  1778. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1779. (if (> (length cmd-key) 2)
  1780. (eval (list 'let (nreverse pars)
  1781. (list 'org-tags-view nil cmd-key)))
  1782. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1783. (set-buffer org-agenda-buffer-name)
  1784. (princ (org-encode-for-stdout (buffer-string)))))
  1785. (defun org-encode-for-stdout (string)
  1786. (if (fboundp 'encode-coding-string)
  1787. (encode-coding-string string buffer-file-coding-system)
  1788. string))
  1789. (defvar org-agenda-info nil)
  1790. ;;;###autoload
  1791. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  1792. "Run an agenda command in batch mode and send the result to STDOUT.
  1793. If CMD-KEY is a string of length 1, it is used as a key in
  1794. `org-agenda-custom-commands' and triggers this command. If it is a
  1795. longer string it is used as a tags/todo match string.
  1796. Paramters are alternating variable names and values that will be bound
  1797. before running the agenda command.
  1798. The output gives a line for each selected agenda item. Each
  1799. item is a list of comma-separated values, like this:
  1800. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  1801. category The category of the item
  1802. head The headline, without TODO kwd, TAGS and PRIORITY
  1803. type The type of the agenda entry, can be
  1804. todo selected in TODO match
  1805. tagsmatch selected in tags match
  1806. diary imported from diary
  1807. deadline a deadline on given date
  1808. scheduled scheduled on given date
  1809. timestamp entry has timestamp on given date
  1810. closed entry was closed on given date
  1811. upcoming-deadline warning about deadline
  1812. past-scheduled forwarded scheduled item
  1813. block entry has date block including g. date
  1814. todo The todo keyword, if any
  1815. tags All tags including inherited ones, separated by colons
  1816. date The relevant date, like 2007-2-14
  1817. time The time, like 15:00-16:50
  1818. extra Sting with extra planning info
  1819. priority-l The priority letter if any was given
  1820. priority-n The computed numerical priority
  1821. agenda-day The day in the agenda where this is listed"
  1822. (let (pars)
  1823. (while parameters
  1824. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1825. (push (list 'org-agenda-remove-tags t) pars)
  1826. (if (> (length cmd-key) 2)
  1827. (eval (list 'let (nreverse pars)
  1828. (list 'org-tags-view nil cmd-key)))
  1829. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1830. (set-buffer org-agenda-buffer-name)
  1831. (let* ((lines (org-split-string (buffer-string) "\n"))
  1832. line)
  1833. (while (setq line (pop lines))
  1834. (catch 'next
  1835. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  1836. (setq org-agenda-info
  1837. (org-fix-agenda-info (text-properties-at 0 line)))
  1838. (princ
  1839. (org-encode-for-stdout
  1840. (mapconcat 'org-agenda-export-csv-mapper
  1841. '(org-category txt type todo tags date time-of-day extra
  1842. priority-letter priority agenda-day)
  1843. ",")))
  1844. (princ "\n"))))))
  1845. (defun org-fix-agenda-info (props)
  1846. "Make sure all properties on an agenda item have a canonical form,
  1847. so the export commands can easily use it."
  1848. (let (tmp re)
  1849. (when (setq tmp (plist-get props 'tags))
  1850. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  1851. (when (setq tmp (plist-get props 'date))
  1852. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  1853. (let ((calendar-date-display-form '(year "-" month "-" day)))
  1854. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  1855. (setq tmp (calendar-date-string tmp)))
  1856. (setq props (plist-put props 'date tmp)))
  1857. (when (setq tmp (plist-get props 'day))
  1858. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  1859. (let ((calendar-date-display-form '(year "-" month "-" day)))
  1860. (setq tmp (calendar-date-string tmp)))
  1861. (setq props (plist-put props 'day tmp))
  1862. (setq props (plist-put props 'agenda-day tmp)))
  1863. (when (setq tmp (plist-get props 'txt))
  1864. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  1865. (plist-put props 'priority-letter (match-string 1 tmp))
  1866. (setq tmp (replace-match "" t t tmp)))
  1867. (when (and (setq re (plist-get props 'org-todo-regexp))
  1868. (setq re (concat "\\`\\.*" re " ?"))
  1869. (string-match re tmp))
  1870. (plist-put props 'todo (match-string 1 tmp))
  1871. (setq tmp (replace-match "" t t tmp)))
  1872. (plist-put props 'txt tmp)))
  1873. props)
  1874. (defun org-agenda-export-csv-mapper (prop)
  1875. (let ((res (plist-get org-agenda-info prop)))
  1876. (setq res
  1877. (cond
  1878. ((not res) "")
  1879. ((stringp res) res)
  1880. (t (prin1-to-string res))))
  1881. (while (string-match "," res)
  1882. (setq res (replace-match ";" t t res)))
  1883. (org-trim res)))
  1884. ;;;###autoload
  1885. (defun org-store-agenda-views (&rest parameters)
  1886. (interactive)
  1887. (eval (list 'org-batch-store-agenda-views)))
  1888. ;; FIXME, why is this a macro?????
  1889. ;;;###autoload
  1890. (defmacro org-batch-store-agenda-views (&rest parameters)
  1891. "Run all custom agenda commands that have a file argument."
  1892. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  1893. (pop-up-frames nil)
  1894. (dir default-directory)
  1895. pars cmd thiscmdkey files opts cmd-or-set)
  1896. (while parameters
  1897. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1898. (setq pars (reverse pars))
  1899. (save-window-excursion
  1900. (while cmds
  1901. (setq cmd (pop cmds)
  1902. thiscmdkey (car cmd)
  1903. cmd-or-set (nth 2 cmd)
  1904. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  1905. files (nth (if (listp cmd-or-set) 4 5) cmd))
  1906. (if (stringp files) (setq files (list files)))
  1907. (when files
  1908. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  1909. (list 'org-agenda nil thiscmdkey)))
  1910. (set-buffer org-agenda-buffer-name)
  1911. (while files
  1912. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  1913. (list 'org-write-agenda
  1914. (expand-file-name (pop files) dir) nil t))))
  1915. (and (get-buffer org-agenda-buffer-name)
  1916. (kill-buffer org-agenda-buffer-name)))))))
  1917. (defun org-write-agenda (file &optional open nosettings)
  1918. "Write the current buffer (an agenda view) as a file.
  1919. Depending on the extension of the file name, plain text (.txt),
  1920. HTML (.html or .htm) or Postscript (.ps) is produced.
  1921. If the extension is .ics, run icalendar export over all files used
  1922. to construct the agenda and limit the export to entries listed in the
  1923. agenda now.
  1924. With prefic argument OPEN, open the new file immediately.
  1925. If NOSETTINGS is given, do not scope the settings of
  1926. `org-agenda-exporter-settings' into the export commands. This is used when
  1927. the settings have already been scoped and we do not wish to overrule other,
  1928. higher priority settings."
  1929. (interactive "FWrite agenda to file: \nP")
  1930. (if (not (file-writable-p file))
  1931. (error "Cannot write agenda to file %s" file))
  1932. (cond
  1933. ((string-match "\\.html?\\'" file) (require 'htmlize))
  1934. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  1935. (org-let (if nosettings nil org-agenda-exporter-settings)
  1936. '(save-excursion
  1937. (save-window-excursion
  1938. (org-agenda-mark-filtered-text)
  1939. (let ((bs (copy-sequence (buffer-string))) beg)
  1940. (org-agenda-unmark-filtered-text)
  1941. (with-temp-buffer
  1942. (insert bs)
  1943. (org-agenda-remove-marked-text 'org-filtered)
  1944. (while (setq beg (text-property-any (point-min) (point-max)
  1945. 'org-filtered t))
  1946. (delete-region
  1947. beg (or (next-single-property-change beg 'org-filtered)
  1948. (point-max))))
  1949. (run-hooks 'org-agenda-before-write-hook)
  1950. (cond
  1951. ((string-match "\\.html?\\'" file)
  1952. (set-buffer (htmlize-buffer (current-buffer)))
  1953. (when (and org-agenda-export-html-style
  1954. (string-match "<style>" org-agenda-export-html-style))
  1955. ;; replace <style> section with org-agenda-export-html-style
  1956. (goto-char (point-min))
  1957. (kill-region (- (search-forward "<style") 6)
  1958. (search-forward "</style>"))
  1959. (insert org-agenda-export-html-style))
  1960. (write-file file)
  1961. (kill-buffer (current-buffer))
  1962. (message "HTML written to %s" file))
  1963. ((string-match "\\.ps\\'" file)
  1964. (require 'ps-print)
  1965. (flet ((ps-get-buffer-name () "Agenda View"))
  1966. (ps-print-buffer-with-faces file))
  1967. (message "Postscript written to %s" file))
  1968. ((string-match "\\.pdf\\'" file)
  1969. (require 'ps-print)
  1970. (flet ((ps-get-buffer-name () "Agenda View"))
  1971. (ps-print-buffer-with-faces
  1972. (concat (file-name-sans-extension file) ".ps")))
  1973. (call-process "ps2pdf" nil nil nil
  1974. (expand-file-name
  1975. (concat (file-name-sans-extension file) ".ps"))
  1976. (expand-file-name file))
  1977. (message "PDF written to %s" file))
  1978. ((string-match "\\.ics\\'" file)
  1979. (require 'org-icalendar)
  1980. (let ((org-agenda-marker-table
  1981. (org-create-marker-find-array
  1982. (org-agenda-collect-markers)))
  1983. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  1984. (org-combined-agenda-icalendar-file file))
  1985. (apply 'org-export-icalendar 'combine
  1986. (org-agenda-files nil 'ifmode))))
  1987. (t
  1988. (let ((bs (buffer-string)))
  1989. (find-file file)
  1990. (erase-buffer)
  1991. (insert bs)
  1992. (save-buffer 0)
  1993. (kill-buffer (current-buffer))
  1994. (message "Plain text written to %s" file))))))))
  1995. (set-buffer org-agenda-buffer-name))
  1996. (when open (org-open-file file)))
  1997. (defvar org-agenda-filter-overlays nil)
  1998. (defun org-agenda-mark-filtered-text ()
  1999. "Mark all text hidden by filtering with a text property."
  2000. (let ((inhibit-read-only t))
  2001. (mapc
  2002. (lambda (o)
  2003. (when (equal (org-overlay-buffer o) (current-buffer))
  2004. (put-text-property
  2005. (org-overlay-start o) (org-overlay-end o)
  2006. 'org-filtered t)))
  2007. org-agenda-filter-overlays)))
  2008. (defun org-agenda-unmark-filtered-text ()
  2009. "Remove the filtering text property."
  2010. (let ((inhibit-read-only t))
  2011. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2012. (defun org-agenda-remove-marked-text (property &optional value)
  2013. "Delete all text marked with VALUE of PROPERTY.
  2014. VALUE defaults to t."
  2015. (let (beg)
  2016. (setq value (or value t))
  2017. (while (setq beg (text-property-any (point-min) (point-max)
  2018. property value))
  2019. (delete-region
  2020. beg (or (next-single-property-change beg 'org-filtered)
  2021. (point-max))))))
  2022. (defun org-agenda-add-entry-text ()
  2023. "Add entry text to agenda lines.
  2024. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2025. entry text following headings shown in the agenda.
  2026. Drawers will be excluded, also the line with scheduling/deadline info."
  2027. (when (> org-agenda-add-entry-text-maxlines 0)
  2028. (let (m txt drawer-re kwd-time-re ind)
  2029. (goto-char (point-min))
  2030. (while (not (eobp))
  2031. (if (not (setq m (get-text-property (point) 'org-hd-marker)))
  2032. (beginning-of-line 2)
  2033. (save-excursion
  2034. (with-current-buffer (marker-buffer m)
  2035. (if (not (org-mode-p))
  2036. (setq txt "")
  2037. (save-excursion
  2038. (save-restriction
  2039. (widen)
  2040. (goto-char m)
  2041. (beginning-of-line 2)
  2042. (setq txt (buffer-substring
  2043. (point)
  2044. (progn (outline-next-heading) (point)))
  2045. drawer-re org-drawer-regexp
  2046. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2047. ".*\n?"))
  2048. (with-temp-buffer
  2049. (insert txt)
  2050. (when org-agenda-add-entry-text-descriptive-links
  2051. (goto-char (point-min))
  2052. (while (org-activate-bracket-links (point-max))
  2053. (add-text-properties (match-beginning 0) (match-end 0)
  2054. '(face org-link))))
  2055. (goto-char (point-min))
  2056. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2057. (set-text-properties (match-beginning 0) (match-end 0)
  2058. nil))
  2059. (goto-char (point-min))
  2060. (while (re-search-forward drawer-re nil t)
  2061. (delete-region
  2062. (match-beginning 0)
  2063. (progn (re-search-forward
  2064. "^[ \t]*:END:.*\n?" nil 'move)
  2065. (point))))
  2066. (goto-char (point-min))
  2067. (while (re-search-forward kwd-time-re nil t)
  2068. (replace-match ""))
  2069. (if (re-search-forward "[ \t\n]+\\'" nil t)
  2070. (replace-match ""))
  2071. (goto-char (point-min))
  2072. ;; find min indentation
  2073. (goto-char (point-min))
  2074. (untabify (point-min) (point-max))
  2075. (setq ind (org-get-indentation))
  2076. (while (not (eobp))
  2077. (unless (looking-at "[ \t]*$")
  2078. (setq ind (min ind (org-get-indentation))))
  2079. (beginning-of-line 2))
  2080. (goto-char (point-min))
  2081. (while (not (eobp))
  2082. (unless (looking-at "[ \t]*$")
  2083. (move-to-column ind)
  2084. (delete-region (point-at-bol) (point)))
  2085. (beginning-of-line 2))
  2086. (goto-char (point-min))
  2087. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2088. (replace-match " > "))
  2089. (goto-char (point-min))
  2090. (while (looking-at "[ \t]*\n") (replace-match ""))
  2091. (goto-char (point-max))
  2092. (when (> (org-current-line)
  2093. (1+ org-agenda-add-entry-text-maxlines))
  2094. (goto-line (1+ org-agenda-add-entry-text-maxlines))
  2095. (backward-char 1))
  2096. (setq txt (buffer-substring (point-min) (point)))))))))
  2097. (end-of-line 1)
  2098. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2099. (defun org-agenda-collect-markers ()
  2100. "Collect the markers pointing to entries in the agenda buffer."
  2101. (let (m markers)
  2102. (save-excursion
  2103. (goto-char (point-min))
  2104. (while (not (eobp))
  2105. (when (setq m (or (get-text-property (point) 'org-hd-marker)
  2106. (get-text-property (point) 'org-marker)))
  2107. (push m markers))
  2108. (beginning-of-line 2)))
  2109. (nreverse markers)))
  2110. (defun org-create-marker-find-array (marker-list)
  2111. "Create a alist of files names with all marker positions in that file."
  2112. (let (f tbl m a p)
  2113. (while (setq m (pop marker-list))
  2114. (setq p (marker-position m)
  2115. f (buffer-file-name (or (buffer-base-buffer
  2116. (marker-buffer m))
  2117. (marker-buffer m))))
  2118. (if (setq a (assoc f tbl))
  2119. (push (marker-position m) (cdr a))
  2120. (push (list f p) tbl)))
  2121. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2122. tbl)))
  2123. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2124. (defun org-check-agenda-marker-table ()
  2125. "Check of the current entry is on the marker list."
  2126. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2127. a)
  2128. (and (setq a (assoc file org-agenda-marker-table))
  2129. (save-match-data
  2130. (save-excursion
  2131. (org-back-to-heading t)
  2132. (member (point) (cdr a)))))))
  2133. (defun org-check-for-org-mode ()
  2134. "Make sure current buffer is in org-mode. Error if not."
  2135. (or (org-mode-p)
  2136. (error "Cannot execute org-mode agenda command on buffer in %s."
  2137. major-mode)))
  2138. (defun org-fit-agenda-window ()
  2139. "Fit the window to the buffer size."
  2140. (and (memq org-agenda-window-setup '(reorganize-frame))
  2141. (fboundp 'fit-window-to-buffer)
  2142. (org-fit-window-to-buffer
  2143. nil
  2144. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2145. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2146. ;;; Agenda prepare and finalize
  2147. (defvar org-agenda-multi nil) ; dynamically scoped
  2148. (defvar org-agenda-buffer-name "*Org Agenda*")
  2149. (defvar org-pre-agenda-window-conf nil)
  2150. (defvar org-agenda-columns-active nil)
  2151. (defvar org-agenda-name nil)
  2152. (defvar org-agenda-filter nil)
  2153. (defvar org-agenda-filter-preset nil
  2154. "A preset of the tags filter used for secondary agenda filtering.
  2155. This must be a list of strings, each string must be a single tag preceeded
  2156. by \"+\" or \"-\".
  2157. This variable should not be set directly, but agenda custom commands can
  2158. bind it in the options section.")
  2159. (defun org-prepare-agenda (&optional name)
  2160. (setq org-todo-keywords-for-agenda nil)
  2161. (setq org-done-keywords-for-agenda nil)
  2162. (setq org-agenda-filter nil)
  2163. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2164. (if org-agenda-multi
  2165. (progn
  2166. (setq buffer-read-only nil)
  2167. (goto-char (point-max))
  2168. (unless (or (bobp) org-agenda-compact-blocks)
  2169. (insert "\n"
  2170. (if (stringp org-agenda-block-separator)
  2171. org-agenda-block-separator
  2172. (make-string (window-width) org-agenda-block-separator))
  2173. "\n"))
  2174. (narrow-to-region (point) (point-max)))
  2175. (org-agenda-reset-markers)
  2176. (setq org-agenda-contributing-files nil)
  2177. (setq org-agenda-columns-active nil)
  2178. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2179. (setq org-todo-keywords-for-agenda
  2180. (org-uniquify org-todo-keywords-for-agenda))
  2181. (setq org-done-keywords-for-agenda
  2182. (org-uniquify org-done-keywords-for-agenda))
  2183. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2184. (awin (get-buffer-window abuf)))
  2185. (cond
  2186. ((equal (current-buffer) abuf) nil)
  2187. (awin (select-window awin))
  2188. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2189. ((equal org-agenda-window-setup 'current-window)
  2190. (switch-to-buffer abuf))
  2191. ((equal org-agenda-window-setup 'other-window)
  2192. (org-switch-to-buffer-other-window abuf))
  2193. ((equal org-agenda-window-setup 'other-frame)
  2194. (switch-to-buffer-other-frame abuf))
  2195. ((equal org-agenda-window-setup 'reorganize-frame)
  2196. (delete-other-windows)
  2197. (org-switch-to-buffer-other-window abuf))))
  2198. (setq buffer-read-only nil)
  2199. (let ((inhibit-read-only t)) (erase-buffer))
  2200. (org-agenda-mode)
  2201. (and name (not org-agenda-name)
  2202. (org-set-local 'org-agenda-name name)))
  2203. (setq buffer-read-only nil))
  2204. (defun org-finalize-agenda ()
  2205. "Finishing touch for the agenda buffer, called just before displaying it."
  2206. (unless org-agenda-multi
  2207. (save-excursion
  2208. (let ((inhibit-read-only t))
  2209. (goto-char (point-min))
  2210. (while (org-activate-bracket-links (point-max))
  2211. (add-text-properties (match-beginning 0) (match-end 0)
  2212. '(face org-link)))
  2213. (org-agenda-align-tags)
  2214. (unless org-agenda-with-colors
  2215. (remove-text-properties (point-min) (point-max) '(face nil))))
  2216. (if (and (boundp 'org-agenda-overriding-columns-format)
  2217. org-agenda-overriding-columns-format)
  2218. (org-set-local 'org-agenda-overriding-columns-format
  2219. org-agenda-overriding-columns-format))
  2220. (if (and (boundp 'org-agenda-view-columns-initially)
  2221. org-agenda-view-columns-initially)
  2222. (org-agenda-columns))
  2223. (when org-agenda-fontify-priorities
  2224. (org-agenda-fontify-priorities))
  2225. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2226. (org-agenda-dim-blocked-tasks))
  2227. (run-hooks 'org-finalize-agenda-hook)
  2228. (setq org-agenda-type (get-text-property (point) 'org-agenda-type))
  2229. (when (get 'org-agenda-filter :preset-filter)
  2230. (org-agenda-filter-apply org-agenda-filter))
  2231. )))
  2232. (defun org-agenda-fontify-priorities ()
  2233. "Make highest priority lines bold, and lowest italic."
  2234. (interactive)
  2235. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
  2236. (org-delete-overlay o)))
  2237. (org-overlays-in (point-min) (point-max)))
  2238. (save-excursion
  2239. (let ((inhibit-read-only t)
  2240. b e p ov h l)
  2241. (goto-char (point-min))
  2242. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2243. (setq h (or (get-char-property (point) 'org-highest-priority)
  2244. org-highest-priority)
  2245. l (or (get-char-property (point) 'org-lowest-priority)
  2246. org-lowest-priority)
  2247. p (string-to-char (match-string 1))
  2248. b (match-beginning 0)
  2249. e (if (eq org-agenda-fontify-priorities 'cookies)
  2250. (match-end 0)
  2251. (point-at-eol))
  2252. ov (org-make-overlay b e))
  2253. (org-overlay-put
  2254. ov 'face
  2255. (cond ((cdr (assoc p org-priority-faces)))
  2256. ((and (listp org-agenda-fontify-priorities)
  2257. (cdr (assoc p org-agenda-fontify-priorities))))
  2258. ((equal p l) 'italic)
  2259. ((equal p h) 'bold)))
  2260. (org-overlay-put ov 'org-type 'org-priority)))))
  2261. (defun org-agenda-dim-blocked-tasks ()
  2262. "Dim currently blocked TODO's in the agenda display."
  2263. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
  2264. (org-delete-overlay o)))
  2265. (org-overlays-in (point-min) (point-max)))
  2266. (save-excursion
  2267. (let ((inhibit-read-only t)
  2268. (org-depend-tag-blocked nil)
  2269. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2270. org-blocked-by-checkboxes
  2271. invis1 b e p ov h l)
  2272. (goto-char (point-min))
  2273. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2274. (and pos (goto-char (1+ pos))))
  2275. (setq org-blocked-by-checkboxes nil invis1 invis)
  2276. (let ((marker (get-text-property (point) 'org-hd-marker)))
  2277. (when (and marker
  2278. (not (with-current-buffer (marker-buffer marker)
  2279. (save-excursion
  2280. (goto-char marker)
  2281. (if (org-entry-get nil "NOBLOCKING")
  2282. t ;; Never block this entry
  2283. (run-hook-with-args-until-failure
  2284. 'org-blocker-hook
  2285. (list :type 'todo-state-change
  2286. :position marker
  2287. :from 'todo
  2288. :to 'done)))))))
  2289. (if org-blocked-by-checkboxes (setq invis1 nil))
  2290. (setq b (if invis1 (max (point-min) (1- (point))) (point))
  2291. e (point-at-eol)
  2292. ov (org-make-overlay b e))
  2293. (if invis1
  2294. (org-overlay-put ov 'invisible t)
  2295. (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2296. (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
  2297. (defvar org-agenda-skip-function nil
  2298. "Function to be called at each match during agenda construction.
  2299. If this function returns nil, the current match should not be skipped.
  2300. Otherwise, the function must return a position from where the search
  2301. should be continued.
  2302. This may also be a Lisp form, it will be evaluated.
  2303. Never set this variable using `setq' or so, because then it will apply
  2304. to all future agenda commands. Instead, bind it with `let' to scope
  2305. it dynamically into the agenda-constructing command. A good way to set
  2306. it is through options in org-agenda-custom-commands.")
  2307. (defun org-agenda-skip ()
  2308. "Throw to `:skip' in places that should be skipped.
  2309. Also moves point to the end of the skipped region, so that search can
  2310. continue from there."
  2311. (let ((p (point-at-bol)) to fp)
  2312. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2313. (get-text-property p :org-archived)
  2314. (org-end-of-subtree t)
  2315. (throw :skip t))
  2316. (and org-agenda-skip-comment-trees
  2317. (get-text-property p :org-comment)
  2318. (org-end-of-subtree t)
  2319. (throw :skip t))
  2320. (if (equal (char-after p) ?#) (throw :skip t))
  2321. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2322. (consp org-agenda-skip-function))
  2323. (setq to (save-excursion
  2324. (save-match-data
  2325. (if fp
  2326. (funcall org-agenda-skip-function)
  2327. (eval org-agenda-skip-function))))))
  2328. (goto-char to)
  2329. (throw :skip t))))
  2330. (defvar org-agenda-markers nil
  2331. "List of all currently active markers created by `org-agenda'.")
  2332. (defvar org-agenda-last-marker-time (time-to-seconds (current-time))
  2333. "Creation time of the last agenda marker.")
  2334. (defun org-agenda-new-marker (&optional pos)
  2335. "Return a new agenda marker.
  2336. Org-mode keeps a list of these markers and resets them when they are
  2337. no longer in use."
  2338. (let ((m (copy-marker (or pos (point)))))
  2339. (setq org-agenda-last-marker-time (time-to-seconds (current-time)))
  2340. (push m org-agenda-markers)
  2341. m))
  2342. (defun org-agenda-reset-markers ()
  2343. "Reset markers created by `org-agenda'."
  2344. (while org-agenda-markers
  2345. (move-marker (pop org-agenda-markers) nil)))
  2346. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2347. "Save relative positions of markers in region."
  2348. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2349. org-agenda-markers))
  2350. ;;; Agenda timeline
  2351. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2352. (defun org-timeline (&optional include-all)
  2353. "Show a time-sorted view of the entries in the current org file.
  2354. Only entries with a time stamp of today or later will be listed. With
  2355. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2356. under the current date.
  2357. If the buffer contains an active region, only check the region for
  2358. dates."
  2359. (interactive "P")
  2360. (require 'calendar)
  2361. (org-compile-prefix-format 'timeline)
  2362. (org-set-sorting-strategy 'timeline)
  2363. (let* ((dopast t)
  2364. (dotodo include-all)
  2365. (doclosed org-agenda-show-log)
  2366. (entry buffer-file-name)
  2367. (date (calendar-current-date))
  2368. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2369. (end (if (org-region-active-p) (region-end) (point-max)))
  2370. (day-numbers (org-get-all-dates beg end 'no-ranges
  2371. t doclosed ; always include today
  2372. org-timeline-show-empty-dates))
  2373. (org-deadline-warning-days 0)
  2374. (org-agenda-only-exact-dates t)
  2375. (today (time-to-days (current-time)))
  2376. (past t)
  2377. args
  2378. s e rtn d emptyp wd)
  2379. (setq org-agenda-redo-command
  2380. (list 'progn
  2381. (list 'org-switch-to-buffer-other-window (current-buffer))
  2382. (list 'org-timeline (list 'quote include-all))))
  2383. (if (not dopast)
  2384. ;; Remove past dates from the list of dates.
  2385. (setq day-numbers (delq nil (mapcar (lambda(x)
  2386. (if (>= x today) x nil))
  2387. day-numbers))))
  2388. (org-prepare-agenda (concat "Timeline "
  2389. (file-name-nondirectory buffer-file-name)))
  2390. (if doclosed (push :closed args))
  2391. (push :timestamp args)
  2392. (push :deadline args)
  2393. (push :scheduled args)
  2394. (push :sexp args)
  2395. (if dotodo (push :todo args))
  2396. (while (setq d (pop day-numbers))
  2397. (if (and (listp d) (eq (car d) :omitted))
  2398. (progn
  2399. (setq s (point))
  2400. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2401. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2402. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2403. (if (and (>= d today)
  2404. dopast
  2405. past)
  2406. (progn
  2407. (setq past nil)
  2408. (insert (make-string 79 ?-) "\n")))
  2409. (setq date (calendar-gregorian-from-absolute d)
  2410. wd (calendar-day-of-week date))
  2411. (setq s (point))
  2412. (setq rtn (and (not emptyp)
  2413. (apply 'org-agenda-get-day-entries entry
  2414. date args)))
  2415. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2416. (progn
  2417. (insert
  2418. (if (stringp org-agenda-format-date)
  2419. (format-time-string org-agenda-format-date
  2420. (org-time-from-absolute date))
  2421. (funcall org-agenda-format-date date))
  2422. "\n")
  2423. (put-text-property s (1- (point)) 'face
  2424. (if (member wd org-agenda-weekend-days)
  2425. 'org-agenda-date-weekend
  2426. 'org-agenda-date))
  2427. (put-text-property s (1- (point)) 'org-date-line t)
  2428. (if (equal d today)
  2429. (put-text-property s (1- (point)) 'org-today t))
  2430. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2431. (put-text-property s (1- (point)) 'day d)))))
  2432. (goto-char (point-min))
  2433. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2434. (point-min)))
  2435. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2436. (org-finalize-agenda)
  2437. (setq buffer-read-only t)))
  2438. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2439. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2440. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2441. not every single day in the range. If FORCE-TODAY is non-nil, make
  2442. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2443. inactive time stamps (those in square brackets) are included.
  2444. When EMPTY is non-nil, also include days without any entries."
  2445. (let ((re (concat
  2446. (if pre-re pre-re "")
  2447. (if inactive org-ts-regexp-both org-ts-regexp)))
  2448. dates dates1 date day day1 day2 ts1 ts2)
  2449. (if force-today
  2450. (setq dates (list (time-to-days (current-time)))))
  2451. (save-excursion
  2452. (goto-char beg)
  2453. (while (re-search-forward re end t)
  2454. (setq day (time-to-days (org-time-string-to-time
  2455. (substring (match-string 1) 0 10))))
  2456. (or (memq day dates) (push day dates)))
  2457. (unless no-ranges
  2458. (goto-char beg)
  2459. (while (re-search-forward org-tr-regexp end t)
  2460. (setq ts1 (substring (match-string 1) 0 10)
  2461. ts2 (substring (match-string 2) 0 10)
  2462. day1 (time-to-days (org-time-string-to-time ts1))
  2463. day2 (time-to-days (org-time-string-to-time ts2)))
  2464. (while (< (setq day1 (1+ day1)) day2)
  2465. (or (memq day1 dates) (push day1 dates)))))
  2466. (setq dates (sort dates '<))
  2467. (when empty
  2468. (while (setq day (pop dates))
  2469. (setq day2 (car dates))
  2470. (push day dates1)
  2471. (when (and day2 empty)
  2472. (if (or (eq empty t)
  2473. (and (numberp empty) (<= (- day2 day) empty)))
  2474. (while (< (setq day (1+ day)) day2)
  2475. (push (list day) dates1))
  2476. (push (cons :omitted (- day2 day)) dates1))))
  2477. (setq dates (nreverse dates1)))
  2478. dates)))
  2479. ;;; Agenda Daily/Weekly
  2480. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2481. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2482. "Custom commands can set this variable in the options section.")
  2483. (defvar org-agenda-last-arguments nil
  2484. "The arguments of the previous call to org-agenda")
  2485. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2486. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2487. (defvar org-include-all-loc nil) ; local variable
  2488. (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
  2489. ;;;###autoload
  2490. (defun org-agenda-list (&optional include-all start-day ndays)
  2491. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2492. The view will be for the current day or week, but from the overview buffer
  2493. you will be able to go to other days/weeks.
  2494. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2495. all unfinished TODO items will also be shown, before the agenda.
  2496. This feature is considered obsolete, please use the TODO list or a block
  2497. agenda instead.
  2498. With a numeric prefix argument in an interactive call, the agenda will
  2499. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2500. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2501. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2502. given in `org-agenda-start-on-weekday'."
  2503. (interactive "P")
  2504. (if (and (integerp include-all) (> include-all 0))
  2505. (setq ndays include-all include-all nil))
  2506. (setq ndays (or ndays org-agenda-ndays)
  2507. start-day (or start-day org-agenda-start-day))
  2508. (if org-agenda-overriding-arguments
  2509. (setq include-all (car org-agenda-overriding-arguments)
  2510. start-day (nth 1 org-agenda-overriding-arguments)
  2511. ndays (nth 2 org-agenda-overriding-arguments)))
  2512. (if (stringp start-day)
  2513. ;; Convert to an absolute day number
  2514. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2515. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2516. (org-compile-prefix-format 'agenda)
  2517. (org-set-sorting-strategy 'agenda)
  2518. (require 'calendar)
  2519. (let* ((org-agenda-start-on-weekday
  2520. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2521. org-agenda-start-on-weekday nil))
  2522. (thefiles (org-agenda-files nil 'ifmode))
  2523. (files thefiles)
  2524. (today (time-to-days
  2525. (time-subtract (current-time)
  2526. (list 0 (* 3600 org-extend-today-until) 0))))
  2527. (sd (or start-day today))
  2528. (start (if (or (null org-agenda-start-on-weekday)
  2529. (< org-agenda-ndays 7))
  2530. sd
  2531. (let* ((nt (calendar-day-of-week
  2532. (calendar-gregorian-from-absolute sd)))
  2533. (n1 org-agenda-start-on-weekday)
  2534. (d (- nt n1)))
  2535. (- sd (+ (if (< d 0) 7 0) d)))))
  2536. (day-numbers (list start))
  2537. (day-cnt 0)
  2538. (inhibit-redisplay (not debug-on-error))
  2539. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2540. clocktable-start clocktable-end)
  2541. (setq org-agenda-redo-command
  2542. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2543. ;; Make the list of days
  2544. (setq ndays (or ndays org-agenda-ndays)
  2545. nd ndays)
  2546. (while (> ndays 1)
  2547. (push (1+ (car day-numbers)) day-numbers)
  2548. (setq ndays (1- ndays)))
  2549. (setq day-numbers (nreverse day-numbers))
  2550. (setq clocktable-start (car day-numbers)
  2551. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2552. (org-prepare-agenda "Day/Week")
  2553. (org-set-local 'org-starting-day (car day-numbers))
  2554. (org-set-local 'org-include-all-loc include-all)
  2555. (org-set-local 'org-agenda-span
  2556. (org-agenda-ndays-to-span nd))
  2557. (when (and (or include-all org-agenda-include-all-todo)
  2558. (member today day-numbers))
  2559. (setq files thefiles
  2560. rtnall nil)
  2561. (while (setq file (pop files))
  2562. (catch 'nextfile
  2563. (org-check-agenda-file file)
  2564. (setq date (calendar-gregorian-from-absolute today)
  2565. rtn (org-agenda-get-day-entries
  2566. file date :todo))
  2567. (setq rtnall (append rtnall rtn))))
  2568. (when rtnall
  2569. (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
  2570. (add-text-properties (point-min) (1- (point))
  2571. (list 'face 'org-agenda-structure))
  2572. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2573. (unless org-agenda-compact-blocks
  2574. (let* ((d1 (car day-numbers))
  2575. (d2 (org-last day-numbers))
  2576. (w1 (org-days-to-iso-week d1))
  2577. (w2 (org-days-to-iso-week d2)))
  2578. (setq s (point))
  2579. (if org-agenda-overriding-header
  2580. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2581. nil 'face 'org-agenda-structure) "\n")
  2582. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  2583. "-agenda"
  2584. (if (< (- d2 d1) 350)
  2585. (if (= w1 w2)
  2586. (format " (W%02d)" w1)
  2587. (format " (W%02d-W%02d)" w1 w2))
  2588. "")
  2589. ":\n")))
  2590. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  2591. 'org-date-line t)))
  2592. (while (setq d (pop day-numbers))
  2593. (setq date (calendar-gregorian-from-absolute d)
  2594. wd (calendar-day-of-week date)
  2595. s (point))
  2596. (if (or (setq todayp (= d today))
  2597. (and (not start-pos) (= d sd)))
  2598. (setq start-pos (point))
  2599. (if (and start-pos (not end-pos))
  2600. (setq end-pos (point))))
  2601. (setq files thefiles
  2602. rtnall nil)
  2603. (while (setq file (pop files))
  2604. (catch 'nextfile
  2605. (org-check-agenda-file file)
  2606. (cond
  2607. ((eq org-agenda-show-log 'only)
  2608. (setq rtn (org-agenda-get-day-entries
  2609. file date :closed)))
  2610. (org-agenda-show-log
  2611. (setq rtn (org-agenda-get-day-entries
  2612. file date
  2613. :deadline :scheduled :timestamp :sexp :closed)))
  2614. (t
  2615. (setq rtn (org-agenda-get-day-entries
  2616. file date
  2617. :deadline :scheduled :sexp :timestamp))))
  2618. (setq rtnall (append rtnall rtn))))
  2619. (if org-agenda-include-diary
  2620. (let ((org-agenda-search-headline-for-time t))
  2621. (require 'diary-lib)
  2622. (setq rtn (org-get-entries-from-diary date))
  2623. (setq rtnall (append rtnall rtn))))
  2624. (if (or rtnall org-agenda-show-all-dates)
  2625. (progn
  2626. (setq day-cnt (1+ day-cnt))
  2627. (insert
  2628. (if (stringp org-agenda-format-date)
  2629. (format-time-string org-agenda-format-date
  2630. (org-time-from-absolute date))
  2631. (funcall org-agenda-format-date date))
  2632. "\n")
  2633. (put-text-property s (1- (point)) 'face
  2634. (if (member wd org-agenda-weekend-days)
  2635. 'org-agenda-date-weekend
  2636. 'org-agenda-date))
  2637. (put-text-property s (1- (point)) 'org-date-line t)
  2638. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  2639. (when todayp
  2640. (put-text-property s (1- (point)) 'org-today t)
  2641. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  2642. (if rtnall (insert
  2643. (org-finalize-agenda-entries
  2644. (org-agenda-add-time-grid-maybe
  2645. rtnall nd todayp))
  2646. "\n"))
  2647. (put-text-property s (1- (point)) 'day d)
  2648. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  2649. (when (and org-agenda-clockreport-mode clocktable-start)
  2650. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  2651. ;; the above line is to ensure the restricted range!
  2652. (p org-agenda-clockreport-parameter-plist)
  2653. tbl)
  2654. (setq p (org-plist-delete p :block))
  2655. (setq p (plist-put p :tstart clocktable-start))
  2656. (setq p (plist-put p :tend clocktable-end))
  2657. (setq p (plist-put p :scope 'agenda))
  2658. (setq tbl (apply 'org-get-clocktable p))
  2659. (insert tbl)))
  2660. (goto-char (point-min))
  2661. (or org-agenda-multi (org-fit-agenda-window))
  2662. (unless (and (pos-visible-in-window-p (point-min))
  2663. (pos-visible-in-window-p (point-max)))
  2664. (goto-char (1- (point-max)))
  2665. (recenter -1)
  2666. (if (not (pos-visible-in-window-p (or start-pos 1)))
  2667. (progn
  2668. (goto-char (or start-pos 1))
  2669. (recenter 1))))
  2670. (goto-char (or start-pos 1))
  2671. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  2672. (org-finalize-agenda)
  2673. (setq buffer-read-only t)
  2674. (message "")))
  2675. (defun org-agenda-ndays-to-span (n)
  2676. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  2677. ;;; Agenda word search
  2678. (defvar org-agenda-search-history nil)
  2679. (defvar org-todo-only nil)
  2680. (defvar org-search-syntax-table nil
  2681. "Special syntax table for org-mode search.
  2682. In this table, we have single quotes not as word constituents, to
  2683. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  2684. (defun org-search-syntax-table ()
  2685. (unless org-search-syntax-table
  2686. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  2687. (modify-syntax-entry ?' "." org-search-syntax-table)
  2688. (modify-syntax-entry ?` "." org-search-syntax-table))
  2689. org-search-syntax-table)
  2690. ;;;###autoload
  2691. (defun org-search-view (&optional todo-only string edit-at)
  2692. "Show all entries that contain words or regular expressions.
  2693. If the first character of the search string is an asterisks,
  2694. search only the headlines.
  2695. With optional prefix argument TODO-ONLY, only consider entries that are
  2696. TODO entries. The argument STRING can be used to pass a default search
  2697. string into this function. If EDIT-AT is non-nil, it means that the
  2698. user should get a chance to edit this string, with cursor at position
  2699. EDIT-AT.
  2700. The search string is broken into \"words\" by splitting at whitespace.
  2701. The individual words are then interpreted as a boolean expression with
  2702. logical AND. Words prefixed with a minus must not occur in the entry.
  2703. Words without a prefix or prefixed with a plus must occur in the entry.
  2704. Matching is case-insensitive and the words are enclosed by word delimiters.
  2705. Words enclosed by curly braces are interpreted as regular expressions
  2706. that must or must not match in the entry.
  2707. If the search string starts with an asterisk, search only in headlines.
  2708. If (possibly after the leading star) the search string starts with an
  2709. exclamation mark, this also means to look at TODO entries only, an effect
  2710. that can also be achieved with a prefix argument.
  2711. This command searches the agenda files, and in addition the files listed
  2712. in `org-agenda-text-search-extra-files'."
  2713. (interactive "P")
  2714. (org-compile-prefix-format 'search)
  2715. (org-set-sorting-strategy 'search)
  2716. (org-prepare-agenda "SEARCH")
  2717. (let* ((props (list 'face nil
  2718. 'done-face 'org-agenda-done
  2719. 'org-not-done-regexp org-not-done-regexp
  2720. 'org-todo-regexp org-todo-regexp
  2721. 'org-complex-heading-regexp org-complex-heading-regexp
  2722. 'mouse-face 'highlight
  2723. 'keymap org-agenda-keymap
  2724. 'help-echo (format "mouse-2 or RET jump to location")))
  2725. regexp rtn rtnall files file pos
  2726. marker category tags c neg re
  2727. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  2728. (unless (and (not edit-at)
  2729. (stringp string)
  2730. (string-match "\\S-" string))
  2731. (setq string (read-string "[+-]Word/{Regexp} ...: "
  2732. (cond
  2733. ((integerp edit-at) (cons string edit-at))
  2734. (edit-at string))
  2735. 'org-agenda-search-history)))
  2736. (org-set-local 'org-todo-only todo-only)
  2737. (setq org-agenda-redo-command
  2738. (list 'org-search-view (if todo-only t nil) string
  2739. '(if current-prefix-arg 1 nil)))
  2740. (setq org-agenda-query-string string)
  2741. (if (equal (string-to-char string) ?*)
  2742. (setq hdl-only t
  2743. words (substring string 1))
  2744. (setq words string))
  2745. (when (equal (string-to-char words) ?!)
  2746. (setq todo-only t
  2747. words (substring words 1)))
  2748. (setq words (org-split-string words))
  2749. (mapc (lambda (w)
  2750. (setq c (string-to-char w))
  2751. (if (equal c ?-)
  2752. (setq neg t w (substring w 1))
  2753. (if (equal c ?+)
  2754. (setq neg nil w (substring w 1))
  2755. (setq neg nil)))
  2756. (if (string-match "\\`{.*}\\'" w)
  2757. (setq re (substring w 1 -1))
  2758. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
  2759. (if neg (push re regexps-) (push re regexps+)))
  2760. words)
  2761. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  2762. (if (not regexps+)
  2763. (setq regexp (concat "^" org-outline-regexp))
  2764. (setq regexp (pop regexps+))
  2765. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  2766. regexp))))
  2767. (setq files (org-agenda-files nil 'ifmode))
  2768. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  2769. (pop org-agenda-text-search-extra-files)
  2770. (setq files (org-add-archive-files files)))
  2771. (setq files (append files org-agenda-text-search-extra-files)
  2772. rtnall nil)
  2773. (while (setq file (pop files))
  2774. (setq ee nil)
  2775. (catch 'nextfile
  2776. (org-check-agenda-file file)
  2777. (setq buffer (if (file-exists-p file)
  2778. (org-get-agenda-file-buffer file)
  2779. (error "No such file %s" file)))
  2780. (if (not buffer)
  2781. ;; If file does not exist, make sure an error message is sent
  2782. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  2783. file))))
  2784. (with-current-buffer buffer
  2785. (with-syntax-table (org-search-syntax-table)
  2786. (unless (org-mode-p)
  2787. (error "Agenda file %s is not in `org-mode'" file))
  2788. (let ((case-fold-search t))
  2789. (save-excursion
  2790. (save-restriction
  2791. (if org-agenda-restrict
  2792. (narrow-to-region org-agenda-restrict-begin
  2793. org-agenda-restrict-end)
  2794. (widen))
  2795. (goto-char (point-min))
  2796. (unless (or (org-on-heading-p)
  2797. (outline-next-heading))
  2798. (throw 'nextfile t))
  2799. (goto-char (max (point-min) (1- (point))))
  2800. (while (re-search-forward regexp nil t)
  2801. (org-back-to-heading t)
  2802. (skip-chars-forward "* ")
  2803. (setq beg (point-at-bol)
  2804. beg1 (point)
  2805. end (progn (outline-next-heading) (point)))
  2806. (catch :skip
  2807. (goto-char beg)
  2808. (org-agenda-skip)
  2809. (setq str (buffer-substring-no-properties
  2810. (point-at-bol)
  2811. (if hdl-only (point-at-eol) end)))
  2812. (mapc (lambda (wr) (when (string-match wr str)
  2813. (goto-char (1- end))
  2814. (throw :skip t)))
  2815. regexps-)
  2816. (mapc (lambda (wr) (unless (string-match wr str)
  2817. (goto-char (1- end))
  2818. (throw :skip t)))
  2819. (if todo-only
  2820. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  2821. regexps+)
  2822. regexps+))
  2823. (goto-char beg)
  2824. (setq marker (org-agenda-new-marker (point))
  2825. category (org-get-category)
  2826. tags (org-get-tags-at (point))
  2827. txt (org-format-agenda-item
  2828. ""
  2829. (buffer-substring-no-properties
  2830. beg1 (point-at-eol))
  2831. category tags))
  2832. (org-add-props txt props
  2833. 'org-marker marker 'org-hd-marker marker
  2834. 'org-todo-regexp org-todo-regexp
  2835. 'org-complex-heading-regexp org-complex-heading-regexp
  2836. 'priority 1000 'org-category category
  2837. 'type "search")
  2838. (push txt ee)
  2839. (goto-char (1- end))))))))))
  2840. (setq rtn (nreverse ee))
  2841. (setq rtnall (append rtnall rtn)))
  2842. (if org-agenda-overriding-header
  2843. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2844. nil 'face 'org-agenda-structure) "\n")
  2845. (insert "Search words: ")
  2846. (add-text-properties (point-min) (1- (point))
  2847. (list 'face 'org-agenda-structure))
  2848. (setq pos (point))
  2849. (insert string "\n")
  2850. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  2851. (setq pos (point))
  2852. (unless org-agenda-multi
  2853. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  2854. (add-text-properties pos (1- (point))
  2855. (list 'face 'org-agenda-structure))))
  2856. (when rtnall
  2857. (insert (org-finalize-agenda-entries rtnall) "\n"))
  2858. (goto-char (point-min))
  2859. (or org-agenda-multi (org-fit-agenda-window))
  2860. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  2861. (org-finalize-agenda)
  2862. (setq buffer-read-only t)))
  2863. ;;; Agenda TODO list
  2864. (defvar org-select-this-todo-keyword nil)
  2865. (defvar org-last-arg nil)
  2866. ;;;###autoload
  2867. (defun org-todo-list (arg)
  2868. "Show all TODO entries from all agenda file in a single list.
  2869. The prefix arg can be used to select a specific TODO keyword and limit
  2870. the list to these. When using \\[universal-argument], you will be prompted
  2871. for a keyword. A numeric prefix directly selects the Nth keyword in
  2872. `org-todo-keywords-1'."
  2873. (interactive "P")
  2874. (require 'calendar)
  2875. (org-compile-prefix-format 'todo)
  2876. (org-set-sorting-strategy 'todo)
  2877. (org-prepare-agenda "TODO")
  2878. (let* ((today (time-to-days (current-time)))
  2879. (date (calendar-gregorian-from-absolute today))
  2880. (kwds org-todo-keywords-for-agenda)
  2881. (completion-ignore-case t)
  2882. (org-select-this-todo-keyword
  2883. (if (stringp arg) arg
  2884. (and arg (integerp arg) (> arg 0)
  2885. (nth (1- arg) kwds))))
  2886. rtn rtnall files file pos)
  2887. (when (equal arg '(4))
  2888. (setq org-select-this-todo-keyword
  2889. (org-ido-completing-read "Keyword (or KWD1|K2D2|...): "
  2890. (mapcar 'list kwds) nil nil)))
  2891. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  2892. (org-set-local 'org-last-arg arg)
  2893. (setq org-agenda-redo-command
  2894. '(org-todo-list (or current-prefix-arg org-last-arg)))
  2895. (setq files (org-agenda-files nil 'ifmode)
  2896. rtnall nil)
  2897. (while (setq file (pop files))
  2898. (catch 'nextfile
  2899. (org-check-agenda-file file)
  2900. (setq rtn (org-agenda-get-day-entries file date :todo))
  2901. (setq rtnall (append rtnall rtn))))
  2902. (if org-agenda-overriding-header
  2903. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2904. nil 'face 'org-agenda-structure) "\n")
  2905. (insert "Global list of TODO items of type: ")
  2906. (add-text-properties (point-min) (1- (point))
  2907. (list 'face 'org-agenda-structure))
  2908. (setq pos (point))
  2909. (insert (or org-select-this-todo-keyword "ALL") "\n")
  2910. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  2911. (setq pos (point))
  2912. (unless org-agenda-multi
  2913. (insert "Available with `N r': (0)ALL")
  2914. (let ((n 0) s)
  2915. (mapc (lambda (x)
  2916. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  2917. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  2918. (insert "\n "))
  2919. (insert " " s))
  2920. kwds))
  2921. (insert "\n"))
  2922. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  2923. (when rtnall
  2924. (insert (org-finalize-agenda-entries rtnall) "\n"))
  2925. (goto-char (point-min))
  2926. (or org-agenda-multi (org-fit-agenda-window))
  2927. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  2928. (org-finalize-agenda)
  2929. (setq buffer-read-only t)))
  2930. ;;; Agenda tags match
  2931. ;;;###autoload
  2932. (defun org-tags-view (&optional todo-only match)
  2933. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  2934. The prefix arg TODO-ONLY limits the search to TODO entries."
  2935. (interactive "P")
  2936. (org-compile-prefix-format 'tags)
  2937. (org-set-sorting-strategy 'tags)
  2938. (let* ((org-tags-match-list-sublevels
  2939. ;?????? (if todo-only t org-tags-match-list-sublevels))
  2940. org-tags-match-list-sublevels)
  2941. (completion-ignore-case t)
  2942. rtn rtnall files file pos matcher
  2943. buffer)
  2944. (setq matcher (org-make-tags-matcher match)
  2945. match (car matcher) matcher (cdr matcher))
  2946. (org-prepare-agenda (concat "TAGS " match))
  2947. (setq org-agenda-query-string match)
  2948. (setq org-agenda-redo-command
  2949. (list 'org-tags-view (list 'quote todo-only)
  2950. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  2951. (setq files (org-agenda-files nil 'ifmode)
  2952. rtnall nil)
  2953. (while (setq file (pop files))
  2954. (catch 'nextfile
  2955. (org-check-agenda-file file)
  2956. (setq buffer (if (file-exists-p file)
  2957. (org-get-agenda-file-buffer file)
  2958. (error "No such file %s" file)))
  2959. (if (not buffer)
  2960. ;; If file does not exist, error message to agenda
  2961. (setq rtn (list
  2962. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  2963. rtnall (append rtnall rtn))
  2964. (with-current-buffer buffer
  2965. (unless (org-mode-p)
  2966. (error "Agenda file %s is not in `org-mode'" file))
  2967. (save-excursion
  2968. (save-restriction
  2969. (if org-agenda-restrict
  2970. (narrow-to-region org-agenda-restrict-begin
  2971. org-agenda-restrict-end)
  2972. (widen))
  2973. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  2974. (setq rtnall (append rtnall rtn))))))))
  2975. (if org-agenda-overriding-header
  2976. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2977. nil 'face 'org-agenda-structure) "\n")
  2978. (insert "Headlines with TAGS match: ")
  2979. (add-text-properties (point-min) (1- (point))
  2980. (list 'face 'org-agenda-structure))
  2981. (setq pos (point))
  2982. (insert match "\n")
  2983. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  2984. (setq pos (point))
  2985. (unless org-agenda-multi
  2986. (insert "Press `C-u r' to search again with new search string\n"))
  2987. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  2988. (when rtnall
  2989. (insert (org-finalize-agenda-entries rtnall) "\n"))
  2990. (goto-char (point-min))
  2991. (or org-agenda-multi (org-fit-agenda-window))
  2992. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  2993. (org-finalize-agenda)
  2994. (setq buffer-read-only t)))
  2995. ;;; Agenda Finding stuck projects
  2996. (defvar org-agenda-skip-regexp nil
  2997. "Regular expression used in skipping subtrees for the agenda.
  2998. This is basically a temporary global variable that can be set and then
  2999. used by user-defined selections using `org-agenda-skip-function'.")
  3000. (defvar org-agenda-overriding-header nil
  3001. "When this is set during todo and tags searches, will replace header.
  3002. This variable should not be set directly, but custom commands can bind it
  3003. in the options section.")
  3004. (defun org-agenda-skip-entry-when-regexp-matches ()
  3005. "Checks if the current entry contains match for `org-agenda-skip-regexp'.
  3006. If yes, it returns the end position of this entry, causing agenda commands
  3007. to skip the entry but continuing the search in the subtree. This is a
  3008. function that can be put into `org-agenda-skip-function' for the duration
  3009. of a command."
  3010. (let ((end (save-excursion (org-end-of-subtree t)))
  3011. skip)
  3012. (save-excursion
  3013. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3014. (and skip end)))
  3015. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3016. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3017. If yes, it returns the end position of this tree, causing agenda commands
  3018. to skip this subtree. This is a function that can be put into
  3019. `org-agenda-skip-function' for the duration of a command."
  3020. (let ((end (save-excursion (org-end-of-subtree t)))
  3021. skip)
  3022. (save-excursion
  3023. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3024. (and skip end)))
  3025. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3026. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3027. If yes, it returns the end position of the current entry (NOT the tree),
  3028. causing agenda commands to skip the entry but continuing the search in
  3029. the subtree. This is a function that can be put into
  3030. `org-agenda-skip-function' for the duration of a command. An important
  3031. use of this function is for the stuck project list."
  3032. (let ((end (save-excursion (org-end-of-subtree t)))
  3033. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3034. skip)
  3035. (save-excursion
  3036. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3037. (and skip entry-end)))
  3038. (defun org-agenda-skip-entry-if (&rest conditions)
  3039. "Skip entry if any of CONDITIONS is true.
  3040. See `org-agenda-skip-if' for details."
  3041. (org-agenda-skip-if nil conditions))
  3042. (defun org-agenda-skip-subtree-if (&rest conditions)
  3043. "Skip entry if any of CONDITIONS is true.
  3044. See `org-agenda-skip-if' for details."
  3045. (org-agenda-skip-if t conditions))
  3046. (defun org-agenda-skip-if (subtree conditions)
  3047. "Checks current entity for CONDITIONS.
  3048. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3049. the entry, i.e. the text before the next heading is checked.
  3050. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3051. from different tests. Valid conditions are:
  3052. scheduled Check if there is a scheduled cookie
  3053. notscheduled Check if there is no scheduled cookie
  3054. deadline Check if there is a deadline
  3055. notdeadline Check if there is no deadline
  3056. timestamp Check if there is a timestamp (also deadline or scheduled)
  3057. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3058. regexp Check if regexp matches
  3059. notregexp Check if regexp does not match.
  3060. The regexp is taken from the conditions list, it must come right after
  3061. the `regexp' or `notregexp' element.
  3062. If any of these conditions is met, this function returns the end point of
  3063. the entity, causing the search to continue from there. This is a function
  3064. that can be put into `org-agenda-skip-function' for the duration of a command."
  3065. (let (beg end m)
  3066. (org-back-to-heading t)
  3067. (setq beg (point)
  3068. end (if subtree
  3069. (progn (org-end-of-subtree t) (point))
  3070. (progn (outline-next-heading) (1- (point)))))
  3071. (goto-char beg)
  3072. (and
  3073. (or
  3074. (and (memq 'scheduled conditions)
  3075. (re-search-forward org-scheduled-time-regexp end t))
  3076. (and (memq 'notscheduled conditions)
  3077. (not (re-search-forward org-scheduled-time-regexp end t)))
  3078. (and (memq 'deadline conditions)
  3079. (re-search-forward org-deadline-time-regexp end t))
  3080. (and (memq 'notdeadline conditions)
  3081. (not (re-search-forward org-deadline-time-regexp end t)))
  3082. (and (memq 'timestamp conditions)
  3083. (re-search-forward org-ts-regexp end t))
  3084. (and (memq 'nottimestamp conditions)
  3085. (not (re-search-forward org-ts-regexp end t)))
  3086. (and (setq m (memq 'regexp conditions))
  3087. (stringp (nth 1 m))
  3088. (re-search-forward (nth 1 m) end t))
  3089. (and (setq m (memq 'notregexp conditions))
  3090. (stringp (nth 1 m))
  3091. (not (re-search-forward (nth 1 m) end t))))
  3092. end)))
  3093. ;;;###autoload
  3094. (defun org-agenda-list-stuck-projects (&rest ignore)
  3095. "Create agenda view for projects that are stuck.
  3096. Stuck projects are project that have no next actions. For the definitions
  3097. of what a project is and how to check if it stuck, customize the variable
  3098. `org-stuck-projects'.
  3099. MATCH is being ignored."
  3100. (interactive)
  3101. (let* ((org-agenda-skip-function
  3102. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3103. ;; We could have used org-agenda-skip-if here.
  3104. (org-agenda-overriding-header
  3105. (or org-agenda-overriding-header "List of stuck projects: "))
  3106. (matcher (nth 0 org-stuck-projects))
  3107. (todo (nth 1 org-stuck-projects))
  3108. (todo-wds (if (member "*" todo)
  3109. (progn
  3110. (org-prepare-agenda-buffers (org-agenda-files
  3111. nil 'ifmode))
  3112. (org-delete-all
  3113. org-done-keywords-for-agenda
  3114. (copy-sequence org-todo-keywords-for-agenda)))
  3115. todo))
  3116. (todo-re (concat "^\\*+[ \t]+\\("
  3117. (mapconcat 'identity todo-wds "\\|")
  3118. "\\)\\>"))
  3119. (tags (nth 2 org-stuck-projects))
  3120. (tags-re (if (member "*" tags)
  3121. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3122. (if tags
  3123. (concat "^\\*+ .*:\\("
  3124. (mapconcat 'identity tags "\\|")
  3125. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3126. (gen-re (nth 3 org-stuck-projects))
  3127. (re-list
  3128. (delq nil
  3129. (list
  3130. (if todo todo-re)
  3131. (if tags tags-re)
  3132. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3133. gen-re)))))
  3134. (setq org-agenda-skip-regexp
  3135. (if re-list
  3136. (mapconcat 'identity re-list "\\|")
  3137. (error "No information how to identify unstuck projects")))
  3138. (org-tags-view nil matcher)
  3139. (with-current-buffer org-agenda-buffer-name
  3140. (setq org-agenda-redo-command
  3141. '(org-agenda-list-stuck-projects
  3142. (or current-prefix-arg org-last-arg))))))
  3143. ;;; Diary integration
  3144. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3145. (defvar list-diary-entries-hook)
  3146. (defun org-get-entries-from-diary (date)
  3147. "Get the (Emacs Calendar) diary entries for DATE."
  3148. (require 'diary-lib)
  3149. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3150. (fancy-diary-buffer diary-fancy-buffer)
  3151. (diary-display-hook '(fancy-diary-display))
  3152. (diary-display-function 'fancy-diary-display)
  3153. (pop-up-frames nil)
  3154. (list-diary-entries-hook
  3155. (cons 'org-diary-default-entry list-diary-entries-hook))
  3156. (diary-file-name-prefix-function nil) ; turn this feature off
  3157. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3158. entries
  3159. (org-disable-agenda-to-diary t))
  3160. (save-excursion
  3161. (save-window-excursion
  3162. (funcall (if (fboundp 'diary-list-entries)
  3163. 'diary-list-entries 'list-diary-entries)
  3164. date 1)))
  3165. (if (not (get-buffer diary-fancy-buffer))
  3166. (setq entries nil)
  3167. (with-current-buffer diary-fancy-buffer
  3168. (setq buffer-read-only nil)
  3169. (if (zerop (buffer-size))
  3170. ;; No entries
  3171. (setq entries nil)
  3172. ;; Omit the date and other unnecessary stuff
  3173. (org-agenda-cleanup-fancy-diary)
  3174. ;; Add prefix to each line and extend the text properties
  3175. (if (zerop (buffer-size))
  3176. (setq entries nil)
  3177. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3178. (set-buffer-modified-p nil)
  3179. (kill-buffer diary-fancy-buffer)))
  3180. (when entries
  3181. (setq entries (org-split-string entries "\n"))
  3182. (setq entries
  3183. (mapcar
  3184. (lambda (x)
  3185. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3186. ;; Extend the text properties to the beginning of the line
  3187. (org-add-props x (text-properties-at (1- (length x)) x)
  3188. 'type "diary" 'date date))
  3189. entries)))))
  3190. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3191. "Hook run when the fancy diary buffer is cleaned up.")
  3192. (defun org-agenda-cleanup-fancy-diary ()
  3193. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3194. This gets rid of the date, the underline under the date, and
  3195. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3196. date. It also removes lines that contain only whitespace."
  3197. (goto-char (point-min))
  3198. (if (looking-at ".*?:[ \t]*")
  3199. (progn
  3200. (replace-match "")
  3201. (re-search-forward "\n=+$" nil t)
  3202. (replace-match "")
  3203. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3204. (re-search-forward "\n=+$" nil t)
  3205. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3206. (goto-char (point-min))
  3207. (while (re-search-forward "^ +\n" nil t)
  3208. (replace-match ""))
  3209. (goto-char (point-min))
  3210. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3211. (replace-match ""))
  3212. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3213. ;; Make sure entries from the diary have the right text properties.
  3214. (eval-after-load "diary-lib"
  3215. '(if (boundp 'diary-modify-entry-list-string-function)
  3216. ;; We can rely on the hook, nothing to do
  3217. nil
  3218. ;; Hook not available, must use advice to make this work
  3219. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3220. "Make the position visible."
  3221. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3222. (stringp string)
  3223. buffer-file-name)
  3224. (setq string (org-modify-diary-entry-string string))))))
  3225. (defun org-modify-diary-entry-string (string)
  3226. "Add text properties to string, allowing org-mode to act on it."
  3227. (org-add-props string nil
  3228. 'mouse-face 'highlight
  3229. 'keymap org-agenda-keymap
  3230. 'help-echo (if buffer-file-name
  3231. (format "mouse-2 or RET jump to diary file %s"
  3232. (abbreviate-file-name buffer-file-name))
  3233. "")
  3234. 'org-agenda-diary-link t
  3235. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3236. (defun org-diary-default-entry ()
  3237. "Add a dummy entry to the diary.
  3238. Needed to avoid empty dates which mess up holiday display."
  3239. ;; Catch the error if dealing with the new add-to-diary-alist
  3240. (when org-disable-agenda-to-diary
  3241. (condition-case nil
  3242. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3243. (error
  3244. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3245. (defun org-add-to-diary-list (&rest args)
  3246. (if (fboundp 'diary-add-to-list)
  3247. (apply 'diary-add-to-list args)
  3248. (apply 'add-to-diary-list args)))
  3249. ;;;###autoload
  3250. (defun org-diary (&rest args)
  3251. "Return diary information from org-files.
  3252. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3253. It accesses org files and extracts information from those files to be
  3254. listed in the diary. The function accepts arguments specifying what
  3255. items should be listed. The following arguments are allowed:
  3256. :timestamp List the headlines of items containing a date stamp or
  3257. date range matching the selected date. Deadlines will
  3258. also be listed, on the expiration day.
  3259. :sexp List entries resulting from diary-like sexps.
  3260. :deadline List any deadlines past due, or due within
  3261. `org-deadline-warning-days'. The listing occurs only
  3262. in the diary for *today*, not at any other date. If
  3263. an entry is marked DONE, it is no longer listed.
  3264. :scheduled List all items which are scheduled for the given date.
  3265. The diary for *today* also contains items which were
  3266. scheduled earlier and are not yet marked DONE.
  3267. :todo List all TODO items from the org-file. This may be a
  3268. long list - so this is not turned on by default.
  3269. Like deadlines, these entries only show up in the
  3270. diary for *today*, not at any other date.
  3271. The call in the diary file should look like this:
  3272. &%%(org-diary) ~/path/to/some/orgfile.org
  3273. Use a separate line for each org file to check. Or, if you omit the file name,
  3274. all files listed in `org-agenda-files' will be checked automatically:
  3275. &%%(org-diary)
  3276. If you don't give any arguments (as in the example above), the default
  3277. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3278. So the example above may also be written as
  3279. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3280. The function expects the lisp variables `entry' and `date' to be provided
  3281. by the caller, because this is how the calendar works. Don't use this
  3282. function from a program - use `org-agenda-get-day-entries' instead."
  3283. (when (> (- (time-to-seconds (current-time))
  3284. org-agenda-last-marker-time)
  3285. 5)
  3286. (org-agenda-reset-markers))
  3287. (org-compile-prefix-format 'agenda)
  3288. (org-set-sorting-strategy 'agenda)
  3289. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3290. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3291. (list entry)
  3292. (org-agenda-files t)))
  3293. file rtn results)
  3294. (org-prepare-agenda-buffers files)
  3295. ;; If this is called during org-agenda, don't return any entries to
  3296. ;; the calendar. Org Agenda will list these entries itself.
  3297. (if org-disable-agenda-to-diary (setq files nil))
  3298. (while (setq file (pop files))
  3299. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3300. (setq results (append results rtn)))
  3301. (if results
  3302. (concat (org-finalize-agenda-entries results) "\n"))))
  3303. ;;; Agenda entry finders
  3304. (defun org-agenda-get-day-entries (file date &rest args)
  3305. "Does the work for `org-diary' and `org-agenda'.
  3306. FILE is the path to a file to be checked for entries. DATE is date like
  3307. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3308. which kind of entries should be extracted. For details about these, see
  3309. the documentation of `org-diary'."
  3310. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3311. (let* ((org-startup-folded nil)
  3312. (org-startup-align-all-tables nil)
  3313. (buffer (if (file-exists-p file)
  3314. (org-get-agenda-file-buffer file)
  3315. (error "No such file %s" file)))
  3316. arg results rtn)
  3317. (if (not buffer)
  3318. ;; If file does not exist, make sure an error message ends up in diary
  3319. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3320. (with-current-buffer buffer
  3321. (unless (org-mode-p)
  3322. (error "Agenda file %s is not in `org-mode'" file))
  3323. (let ((case-fold-search nil))
  3324. (save-excursion
  3325. (save-restriction
  3326. (if org-agenda-restrict
  3327. (narrow-to-region org-agenda-restrict-begin
  3328. org-agenda-restrict-end)
  3329. (widen))
  3330. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3331. (while (setq arg (pop args))
  3332. (cond
  3333. ((and (eq arg :todo)
  3334. (equal date (calendar-current-date)))
  3335. (setq rtn (org-agenda-get-todos))
  3336. (setq results (append results rtn)))
  3337. ((eq arg :timestamp)
  3338. (setq rtn (org-agenda-get-blocks))
  3339. (setq results (append results rtn))
  3340. (setq rtn (org-agenda-get-timestamps))
  3341. (setq results (append results rtn)))
  3342. ((eq arg :sexp)
  3343. (setq rtn (org-agenda-get-sexps))
  3344. (setq results (append results rtn)))
  3345. ((eq arg :scheduled)
  3346. (setq rtn (org-agenda-get-scheduled))
  3347. (setq results (append results rtn)))
  3348. ((eq arg :closed)
  3349. (setq rtn (org-agenda-get-progress))
  3350. (setq results (append results rtn)))
  3351. ((eq arg :deadline)
  3352. (setq rtn (org-agenda-get-deadlines))
  3353. (setq results (append results rtn))))))))
  3354. results))))
  3355. (defun org-agenda-get-todos ()
  3356. "Return the TODO information for agenda display."
  3357. (let* ((props (list 'face nil
  3358. 'done-face 'org-agenda-done
  3359. 'org-not-done-regexp org-not-done-regexp
  3360. 'org-todo-regexp org-todo-regexp
  3361. 'org-complex-heading-regexp org-complex-heading-regexp
  3362. 'mouse-face 'highlight
  3363. 'keymap org-agenda-keymap
  3364. 'help-echo
  3365. (format "mouse-2 or RET jump to org file %s"
  3366. (abbreviate-file-name buffer-file-name))))
  3367. (regexp (concat "^\\*+[ \t]+\\("
  3368. (if org-select-this-todo-keyword
  3369. (if (equal org-select-this-todo-keyword "*")
  3370. org-todo-regexp
  3371. (concat "\\<\\("
  3372. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3373. "\\)\\>"))
  3374. org-not-done-regexp)
  3375. "[^\n\r]*\\)"))
  3376. marker priority category tags todo-state
  3377. ee txt beg end)
  3378. (goto-char (point-min))
  3379. (while (re-search-forward regexp nil t)
  3380. (catch :skip
  3381. (save-match-data
  3382. (beginning-of-line)
  3383. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3384. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3385. (goto-char (1+ beg))
  3386. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3387. (throw :skip nil)))
  3388. (goto-char beg)
  3389. (org-agenda-skip)
  3390. (goto-char (match-beginning 1))
  3391. (setq marker (org-agenda-new-marker (match-beginning 0))
  3392. category (org-get-category)
  3393. txt (match-string 1)
  3394. tags (org-get-tags-at (point))
  3395. txt (org-format-agenda-item "" txt category tags)
  3396. priority (1+ (org-get-priority txt))
  3397. todo-state (org-get-todo-state))
  3398. (org-add-props txt props
  3399. 'org-marker marker 'org-hd-marker marker
  3400. 'priority priority 'org-category category
  3401. 'type "todo" 'todo-state todo-state)
  3402. (push txt ee)
  3403. (if org-agenda-todo-list-sublevels
  3404. (goto-char (match-end 1))
  3405. (org-end-of-subtree 'invisible))))
  3406. (nreverse ee)))
  3407. ;;;###autoload
  3408. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
  3409. "Do we have a reason to ignore this todo entry because it has a time stamp?"
  3410. (when (or org-agenda-todo-ignore-with-date
  3411. org-agenda-todo-ignore-scheduled
  3412. org-agenda-todo-ignore-deadlines)
  3413. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3414. (save-excursion
  3415. (or (and org-agenda-todo-ignore-with-date
  3416. (re-search-forward org-ts-regexp end t))
  3417. (and org-agenda-todo-ignore-scheduled
  3418. (re-search-forward org-scheduled-time-regexp end t))
  3419. (and org-agenda-todo-ignore-deadlines
  3420. (re-search-forward org-deadline-time-regexp end t)
  3421. (org-deadline-close (match-string 1)))))))
  3422. (defconst org-agenda-no-heading-message
  3423. "No heading for this item in buffer or region.")
  3424. (defun org-agenda-get-timestamps ()
  3425. "Return the date stamp information for agenda display."
  3426. (let* ((props (list 'face nil
  3427. 'org-not-done-regexp org-not-done-regexp
  3428. 'org-todo-regexp org-todo-regexp
  3429. 'org-complex-heading-regexp org-complex-heading-regexp
  3430. 'mouse-face 'highlight
  3431. 'keymap org-agenda-keymap
  3432. 'help-echo
  3433. (format "mouse-2 or RET jump to org file %s"
  3434. (abbreviate-file-name buffer-file-name))))
  3435. (d1 (calendar-absolute-from-gregorian date))
  3436. (remove-re
  3437. (concat
  3438. (regexp-quote
  3439. (format-time-string
  3440. "<%Y-%m-%d"
  3441. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  3442. ".*?>"))
  3443. (regexp
  3444. (concat
  3445. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  3446. (regexp-quote
  3447. (substring
  3448. (format-time-string
  3449. (car org-time-stamp-formats)
  3450. (apply 'encode-time ; DATE bound by calendar
  3451. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3452. 1 11))
  3453. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  3454. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  3455. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  3456. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  3457. todo-state end-of-match)
  3458. (goto-char (point-min))
  3459. (while (setq end-of-match (re-search-forward regexp nil t))
  3460. (setq b0 (match-beginning 0)
  3461. b3 (match-beginning 3) e3 (match-end 3))
  3462. (catch :skip
  3463. (and (org-at-date-range-p) (throw :skip nil))
  3464. (org-agenda-skip)
  3465. (if (and (match-end 1)
  3466. (not (= d1 (org-time-string-to-absolute
  3467. (match-string 1) d1 nil
  3468. org-agenda-repeating-timestamp-show-all))))
  3469. (throw :skip nil))
  3470. (if (and e3
  3471. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  3472. (throw :skip nil))
  3473. (setq tmp (buffer-substring (max (point-min)
  3474. (- b0 org-ds-keyword-length))
  3475. b0)
  3476. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  3477. inactivep (= (char-after b0) ?\[)
  3478. deadlinep (string-match org-deadline-regexp tmp)
  3479. scheduledp (string-match org-scheduled-regexp tmp)
  3480. closedp (and org-agenda-include-inactive-timestamps
  3481. (string-match org-closed-string tmp))
  3482. clockp (and org-agenda-include-inactive-timestamps
  3483. (or (string-match org-clock-string tmp)
  3484. (string-match "]-+\\'" tmp)))
  3485. todo-state (org-get-todo-state)
  3486. donep (member todo-state org-done-keywords))
  3487. (if (or scheduledp deadlinep closedp clockp
  3488. (and donep org-agenda-skip-timestamp-if-done))
  3489. (throw :skip t))
  3490. (if (string-match ">" timestr)
  3491. ;; substring should only run to end of time stamp
  3492. (setq timestr (substring timestr 0 (match-end 0))))
  3493. (setq marker (org-agenda-new-marker b0)
  3494. category (org-get-category b0))
  3495. (save-excursion
  3496. (if (not (re-search-backward "^\\*+ " nil t))
  3497. (setq txt org-agenda-no-heading-message)
  3498. (goto-char (match-beginning 0))
  3499. (setq hdmarker (org-agenda-new-marker)
  3500. tags (org-get-tags-at))
  3501. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3502. (setq head (match-string 1))
  3503. (setq txt (org-format-agenda-item
  3504. (if inactivep "[" nil)
  3505. head category tags timestr nil
  3506. remove-re)))
  3507. (setq priority (org-get-priority txt))
  3508. (org-add-props txt props
  3509. 'org-marker marker 'org-hd-marker hdmarker)
  3510. (org-add-props txt nil 'priority priority
  3511. 'org-category category 'date date
  3512. 'todo-state todo-state
  3513. 'type "timestamp")
  3514. (push txt ee))
  3515. (if org-agenda-skip-additional-timestamps-same-entry
  3516. (outline-next-heading)
  3517. (goto-char end-of-match))))
  3518. (nreverse ee)))
  3519. (defun org-agenda-get-sexps ()
  3520. "Return the sexp information for agenda display."
  3521. (require 'diary-lib)
  3522. (let* ((props (list 'face nil
  3523. 'mouse-face 'highlight
  3524. 'keymap org-agenda-keymap
  3525. 'help-echo
  3526. (format "mouse-2 or RET jump to org file %s"
  3527. (abbreviate-file-name buffer-file-name))))
  3528. (regexp "^&?%%(")
  3529. marker category ee txt tags entry result beg b sexp sexp-entry
  3530. todo-state)
  3531. (goto-char (point-min))
  3532. (while (re-search-forward regexp nil t)
  3533. (catch :skip
  3534. (org-agenda-skip)
  3535. (setq beg (match-beginning 0))
  3536. (goto-char (1- (match-end 0)))
  3537. (setq b (point))
  3538. (forward-sexp 1)
  3539. (setq sexp (buffer-substring b (point)))
  3540. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  3541. (org-trim (match-string 1))
  3542. ""))
  3543. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  3544. (when result
  3545. (setq marker (org-agenda-new-marker beg)
  3546. category (org-get-category beg)
  3547. todo-state (org-get-todo-state))
  3548. (if (string-match "\\S-" result)
  3549. (setq txt result)
  3550. (setq txt "SEXP entry returned empty string"))
  3551. (setq txt (org-format-agenda-item
  3552. "" txt category tags 'time))
  3553. (org-add-props txt props 'org-marker marker)
  3554. (org-add-props txt nil
  3555. 'org-category category 'date date 'todo-state todo-state
  3556. 'type "sexp")
  3557. (push txt ee))))
  3558. (nreverse ee)))
  3559. (defalias 'org-get-closed 'org-agenda-get-progress)
  3560. (defun org-agenda-get-progress ()
  3561. "Return the logged TODO entries for agenda display."
  3562. (let* ((props (list 'mouse-face 'highlight
  3563. 'org-not-done-regexp org-not-done-regexp
  3564. 'org-todo-regexp org-todo-regexp
  3565. 'org-complex-heading-regexp org-complex-heading-regexp
  3566. 'keymap org-agenda-keymap
  3567. 'help-echo
  3568. (format "mouse-2 or RET jump to org file %s"
  3569. (abbreviate-file-name buffer-file-name))))
  3570. (items (if (consp org-agenda-show-log)
  3571. org-agenda-show-log
  3572. org-agenda-log-mode-items))
  3573. (parts
  3574. (delq nil
  3575. (list
  3576. (if (memq 'closed items) (concat "\\<" org-closed-string))
  3577. (if (memq 'clock items) (concat "\\<" org-clock-string))
  3578. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  3579. (parts-re (if parts (mapconcat 'identity parts "\\|")
  3580. (error "`org-agenda-log-mode-items' is empty")))
  3581. (regexp (concat
  3582. "\\(" parts-re "\\)"
  3583. " *\\["
  3584. (regexp-quote
  3585. (substring
  3586. (format-time-string
  3587. (car org-time-stamp-formats)
  3588. (apply 'encode-time ; DATE bound by calendar
  3589. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3590. 1 11))))
  3591. (org-agenda-search-headline-for-time nil)
  3592. marker hdmarker priority category tags closedp statep clockp state
  3593. ee txt extra timestr rest clocked)
  3594. (goto-char (point-min))
  3595. (while (re-search-forward regexp nil t)
  3596. (catch :skip
  3597. (org-agenda-skip)
  3598. (setq marker (org-agenda-new-marker (match-beginning 0))
  3599. closedp (equal (match-string 1) org-closed-string)
  3600. statep (equal (string-to-char (match-string 1)) ?-)
  3601. clockp (not (or closedp statep))
  3602. state (and statep (match-string 2))
  3603. category (org-get-category (match-beginning 0))
  3604. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  3605. )
  3606. (when (string-match "\\]" timestr)
  3607. ;; substring should only run to end of time stamp
  3608. (setq rest (substring timestr (match-end 0))
  3609. timestr (substring timestr 0 (match-end 0)))
  3610. (if (and (not closedp) (not statep)
  3611. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  3612. (progn (setq timestr (concat (substring timestr 0 -1)
  3613. "-" (match-string 1 rest) "]"))
  3614. (setq clocked (match-string 2 rest)))
  3615. (setq clocked "-")))
  3616. (save-excursion
  3617. (cond
  3618. ((not org-agenda-log-mode-add-notes) (setq extra nil))
  3619. (statep
  3620. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  3621. (setq extra (match-string 1))))
  3622. (clockp
  3623. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  3624. (setq extra (match-string 1))))
  3625. (t (setq extra nil)))
  3626. (if (not (re-search-backward "^\\*+ " nil t))
  3627. (setq txt org-agenda-no-heading-message)
  3628. (goto-char (match-beginning 0))
  3629. (setq hdmarker (org-agenda-new-marker)
  3630. tags (org-get-tags-at))
  3631. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3632. (setq txt (match-string 1))
  3633. (when extra
  3634. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  3635. (setq txt (concat (substring txt 0 (match-beginning 1))
  3636. " - " extra " " (match-string 2 txt)))
  3637. (setq txt (concat txt " - " extra))))
  3638. (setq txt (org-format-agenda-item
  3639. (cond
  3640. (closedp "Closed: ")
  3641. (statep (concat "State: (" state ")"))
  3642. (t (concat "Clocked: (" clocked ")")))
  3643. txt category tags timestr)))
  3644. (setq priority 100000)
  3645. (org-add-props txt props
  3646. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  3647. 'priority priority 'org-category category
  3648. 'type "closed" 'date date
  3649. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  3650. (push txt ee))
  3651. (goto-char (point-at-eol))))
  3652. (nreverse ee)))
  3653. (defun org-agenda-get-deadlines ()
  3654. "Return the deadline information for agenda display."
  3655. (let* ((props (list 'mouse-face 'highlight
  3656. 'org-not-done-regexp org-not-done-regexp
  3657. 'org-todo-regexp org-todo-regexp
  3658. 'org-complex-heading-regexp org-complex-heading-regexp
  3659. 'keymap org-agenda-keymap
  3660. 'help-echo
  3661. (format "mouse-2 or RET jump to org file %s"
  3662. (abbreviate-file-name buffer-file-name))))
  3663. (regexp org-deadline-time-regexp)
  3664. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  3665. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  3666. d2 diff dfrac wdays pos pos1 category tags
  3667. ee txt head face s todo-state upcomingp donep timestr)
  3668. (goto-char (point-min))
  3669. (while (re-search-forward regexp nil t)
  3670. (catch :skip
  3671. (org-agenda-skip)
  3672. (setq s (match-string 1)
  3673. txt nil
  3674. pos (1- (match-beginning 1))
  3675. d2 (org-time-string-to-absolute
  3676. (match-string 1) d1 'past
  3677. org-agenda-repeating-timestamp-show-all)
  3678. diff (- d2 d1)
  3679. wdays (org-get-wdays s)
  3680. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  3681. upcomingp (and todayp (> diff 0)))
  3682. ;; When to show a deadline in the calendar:
  3683. ;; If the expiration is within wdays warning time.
  3684. ;; Past-due deadlines are only shown on the current date
  3685. (if (or (and (<= diff wdays)
  3686. (and todayp (not org-agenda-only-exact-dates)))
  3687. (= diff 0))
  3688. (save-excursion
  3689. (setq todo-state (org-get-todo-state))
  3690. (setq donep (member todo-state org-done-keywords))
  3691. (if (and donep
  3692. (or org-agenda-skip-deadline-if-done
  3693. (not (= diff 0))))
  3694. (setq txt nil)
  3695. (setq category (org-get-category))
  3696. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  3697. (setq txt org-agenda-no-heading-message)
  3698. (goto-char (match-end 0))
  3699. (setq pos1 (match-beginning 0))
  3700. (setq tags (org-get-tags-at pos1))
  3701. (setq head (buffer-substring-no-properties
  3702. (point)
  3703. (progn (skip-chars-forward "^\r\n")
  3704. (point))))
  3705. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  3706. (setq timestr
  3707. (concat (substring s (match-beginning 1)) " "))
  3708. (setq timestr 'time))
  3709. (setq txt (org-format-agenda-item
  3710. (if (= diff 0)
  3711. (car org-agenda-deadline-leaders)
  3712. (if (functionp
  3713. (nth 1 org-agenda-deadline-leaders))
  3714. (funcall
  3715. (nth 1 org-agenda-deadline-leaders)
  3716. diff date)
  3717. (format (nth 1 org-agenda-deadline-leaders)
  3718. diff)))
  3719. head category tags
  3720. (if (not (= diff 0)) nil timestr)))))
  3721. (when txt
  3722. (setq face (org-agenda-deadline-face dfrac wdays))
  3723. (org-add-props txt props
  3724. 'org-marker (org-agenda-new-marker pos)
  3725. 'org-hd-marker (org-agenda-new-marker pos1)
  3726. 'priority (+ (- diff)
  3727. (org-get-priority txt))
  3728. 'org-category category
  3729. 'todo-state todo-state
  3730. 'type (if upcomingp "upcoming-deadline" "deadline")
  3731. 'date (if upcomingp date d2)
  3732. 'face (if donep 'org-agenda-done face)
  3733. 'undone-face face 'done-face 'org-agenda-done)
  3734. (push txt ee))))))
  3735. (nreverse ee)))
  3736. (defun org-agenda-deadline-face (fraction &optional wdays)
  3737. "Return the face to displaying a deadline item.
  3738. FRACTION is what fraction of the head-warning time has passed."
  3739. (if (equal wdays 0) (setq fraction 1.))
  3740. (let ((faces org-agenda-deadline-faces) f)
  3741. (catch 'exit
  3742. (while (setq f (pop faces))
  3743. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  3744. (defun org-agenda-get-scheduled ()
  3745. "Return the scheduled information for agenda display."
  3746. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  3747. 'org-todo-regexp org-todo-regexp
  3748. 'org-complex-heading-regexp org-complex-heading-regexp
  3749. 'done-face 'org-agenda-done
  3750. 'mouse-face 'highlight
  3751. 'keymap org-agenda-keymap
  3752. 'help-echo
  3753. (format "mouse-2 or RET jump to org file %s"
  3754. (abbreviate-file-name buffer-file-name))))
  3755. (regexp org-scheduled-time-regexp)
  3756. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  3757. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  3758. d2 diff pos pos1 category tags donep
  3759. ee txt head pastschedp todo-state face timestr s)
  3760. (goto-char (point-min))
  3761. (while (re-search-forward regexp nil t)
  3762. (catch :skip
  3763. (org-agenda-skip)
  3764. (setq s (match-string 1)
  3765. txt nil
  3766. pos (1- (match-beginning 1))
  3767. d2 (org-time-string-to-absolute
  3768. (match-string 1) d1 'past
  3769. org-agenda-repeating-timestamp-show-all)
  3770. diff (- d2 d1))
  3771. (setq pastschedp (and todayp (< diff 0)))
  3772. ;; When to show a scheduled item in the calendar:
  3773. ;; If it is on or past the date.
  3774. (if (or (and (< diff 0)
  3775. (< (abs diff) org-scheduled-past-days)
  3776. (and todayp (not org-agenda-only-exact-dates)))
  3777. (= diff 0))
  3778. (save-excursion
  3779. (setq todo-state (org-get-todo-state))
  3780. (setq donep (member todo-state org-done-keywords))
  3781. (if (and donep
  3782. (or org-agenda-skip-scheduled-if-done
  3783. (not (= diff 0))))
  3784. (setq txt nil)
  3785. (setq category (org-get-category))
  3786. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  3787. (setq txt org-agenda-no-heading-message)
  3788. (goto-char (match-end 0))
  3789. (setq pos1 (match-beginning 0))
  3790. (setq tags (org-get-tags-at))
  3791. (setq head (buffer-substring-no-properties
  3792. (point)
  3793. (progn (skip-chars-forward "^\r\n") (point))))
  3794. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  3795. (setq timestr
  3796. (concat (substring s (match-beginning 1)) " "))
  3797. (setq timestr 'time))
  3798. (setq txt (org-format-agenda-item
  3799. (if (= diff 0)
  3800. (car org-agenda-scheduled-leaders)
  3801. (format (nth 1 org-agenda-scheduled-leaders)
  3802. (- 1 diff)))
  3803. head category tags
  3804. (if (not (= diff 0)) nil timestr)))))
  3805. (when txt
  3806. (setq face
  3807. (cond
  3808. (pastschedp 'org-scheduled-previously)
  3809. (todayp 'org-scheduled-today)
  3810. (t 'org-scheduled)))
  3811. (org-add-props txt props
  3812. 'undone-face face
  3813. 'face (if donep 'org-agenda-done face)
  3814. 'org-marker (org-agenda-new-marker pos)
  3815. 'org-hd-marker (org-agenda-new-marker pos1)
  3816. 'type (if pastschedp "past-scheduled" "scheduled")
  3817. 'date (if pastschedp d2 date)
  3818. 'priority (+ 94 (- 5 diff) (org-get-priority txt))
  3819. 'org-category category
  3820. 'todo-state todo-state)
  3821. (push txt ee))))))
  3822. (nreverse ee)))
  3823. (defun org-agenda-get-blocks ()
  3824. "Return the date-range information for agenda display."
  3825. (let* ((props (list 'face nil
  3826. 'org-not-done-regexp org-not-done-regexp
  3827. 'org-todo-regexp org-todo-regexp
  3828. 'org-complex-heading-regexp org-complex-heading-regexp
  3829. 'mouse-face 'highlight
  3830. 'keymap org-agenda-keymap
  3831. 'help-echo
  3832. (format "mouse-2 or RET jump to org file %s"
  3833. (abbreviate-file-name buffer-file-name))))
  3834. (regexp org-tr-regexp)
  3835. (d0 (calendar-absolute-from-gregorian date))
  3836. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  3837. head donep)
  3838. (goto-char (point-min))
  3839. (while (re-search-forward regexp nil t)
  3840. (catch :skip
  3841. (org-agenda-skip)
  3842. (setq pos (point))
  3843. (setq timestr (match-string 0)
  3844. s1 (match-string 1)
  3845. s2 (match-string 2)
  3846. d1 (time-to-days (org-time-string-to-time s1))
  3847. d2 (time-to-days (org-time-string-to-time s2)))
  3848. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  3849. ;; Only allow days between the limits, because the normal
  3850. ;; date stamps will catch the limits.
  3851. (save-excursion
  3852. (setq todo-state (org-get-todo-state))
  3853. (setq donep (member todo-state org-done-keywords))
  3854. (if (and donep org-agenda-skip-timestamp-if-done)
  3855. (throw :skip t))
  3856. (setq marker (org-agenda-new-marker (point)))
  3857. (setq category (org-get-category))
  3858. (if (not (re-search-backward "^\\*+ " nil t))
  3859. (setq txt org-agenda-no-heading-message)
  3860. (goto-char (match-beginning 0))
  3861. (setq hdmarker (org-agenda-new-marker (point)))
  3862. (setq tags (org-get-tags-at))
  3863. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3864. (setq head (match-string 1))
  3865. (setq txt (org-format-agenda-item
  3866. (format
  3867. (nth (if (= d1 d2) 0 1)
  3868. org-agenda-timerange-leaders)
  3869. (1+ (- d0 d1)) (1+ (- d2 d1)))
  3870. head category tags
  3871. (if (= d0 d1) timestr))))
  3872. (org-add-props txt props
  3873. 'org-marker marker 'org-hd-marker hdmarker
  3874. 'type "block" 'date date
  3875. 'todo-state todo-state
  3876. 'priority (org-get-priority txt) 'org-category category)
  3877. (push txt ee)))
  3878. (goto-char pos)))
  3879. ;; Sort the entries by expiration date.
  3880. (nreverse ee)))
  3881. ;;; Agenda presentation and sorting
  3882. (defvar org-prefix-has-time nil
  3883. "A flag, set by `org-compile-prefix-format'.
  3884. The flag is set if the currently compiled format contains a `%t'.")
  3885. (defvar org-prefix-has-tag nil
  3886. "A flag, set by `org-compile-prefix-format'.
  3887. The flag is set if the currently compiled format contains a `%T'.")
  3888. (defvar org-prefix-has-effort nil
  3889. "A flag, set by `org-compile-prefix-format'.
  3890. The flag is set if the currently compiled format contains a `%e'.")
  3891. (defun org-format-agenda-item (extra txt &optional category tags dotime
  3892. noprefix remove-re)
  3893. "Format TXT to be inserted into the agenda buffer.
  3894. In particular, it adds the prefix and corresponding text properties. EXTRA
  3895. must be a string and replaces the `%s' specifier in the prefix format.
  3896. CATEGORY (string, symbol or nil) may be used to overrule the default
  3897. category taken from local variable or file name. It will replace the `%c'
  3898. specifier in the format. DOTIME, when non-nil, indicates that a
  3899. time-of-day should be extracted from TXT for sorting of this entry, and for
  3900. the `%t' specifier in the format. When DOTIME is a string, this string is
  3901. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  3902. only the correctly processes TXT should be returned - this is used by
  3903. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  3904. Any match of REMOVE-RE will be removed from TXT."
  3905. (save-match-data
  3906. ;; Diary entries sometimes have extra whitespace at the beginning
  3907. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  3908. (when org-agenda-show-inherited-tags
  3909. ;; Fix the tags part in txt
  3910. (setq txt (org-agenda-add-inherited-tags txt tags)))
  3911. (let* ((category (or category
  3912. org-category
  3913. (if buffer-file-name
  3914. (file-name-sans-extension
  3915. (file-name-nondirectory buffer-file-name))
  3916. "")))
  3917. ;; time, tag, effort are needed for the eval of the prefix format
  3918. (tag (if tags (nth (1- (length tags)) tags) ""))
  3919. time effort neffort
  3920. (ts (if dotime (concat
  3921. (if (stringp dotime) dotime "")
  3922. (and org-agenda-search-headline-for-time txt))))
  3923. (time-of-day (and dotime (org-get-time-of-day ts)))
  3924. stamp plain s0 s1 s2 t1 t2 rtn srp
  3925. duration)
  3926. (and (org-mode-p) buffer-file-name
  3927. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  3928. (when (and dotime time-of-day)
  3929. ;; Extract starting and ending time and move them to prefix
  3930. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  3931. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  3932. (setq s0 (match-string 0 ts)
  3933. srp (and stamp (match-end 3))
  3934. s1 (match-string (if plain 1 2) ts)
  3935. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  3936. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  3937. ;; them, we might want to remove them there to avoid duplication.
  3938. ;; The user can turn this off with a variable.
  3939. (if (and org-prefix-has-time
  3940. org-agenda-remove-times-when-in-prefix (or stamp plain)
  3941. (string-match (concat (regexp-quote s0) " *") txt)
  3942. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  3943. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  3944. (= (match-beginning 0) 0)
  3945. t))
  3946. (setq txt (replace-match "" nil nil txt))))
  3947. ;; Normalize the time(s) to 24 hour
  3948. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  3949. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  3950. ;; Compute the duration
  3951. (when s1
  3952. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  3953. (string-to-number (substring s1 3)))
  3954. t2 (cond
  3955. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  3956. (string-to-number (substring s2 3))))
  3957. (org-agenda-default-appointment-duration
  3958. (+ t1 org-agenda-default-appointment-duration))
  3959. (t nil)))
  3960. (setq duration (if t2 (- t2 t1)))))
  3961. (when (and s1 (not s2) org-agenda-default-appointment-duration
  3962. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  3963. (let ((m (+ (string-to-number (match-string 2 s1))
  3964. (* 60 (string-to-number (match-string 1 s1)))
  3965. org-agenda-default-appointment-duration))
  3966. h)
  3967. (setq h (/ m 60) m (- m (* h 60)))
  3968. (setq s2 (format "%02d:%02d" h m))))
  3969. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  3970. txt)
  3971. ;; Tags are in the string
  3972. (if (or (eq org-agenda-remove-tags t)
  3973. (and org-agenda-remove-tags
  3974. org-prefix-has-tag))
  3975. (setq txt (replace-match "" t t txt))
  3976. (setq txt (replace-match
  3977. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  3978. (match-string 2 txt))
  3979. t t txt))))
  3980. (when (org-mode-p)
  3981. (setq effort
  3982. (condition-case nil
  3983. (org-get-effort
  3984. (or (get-text-property 0 'org-hd-marker txt)
  3985. (get-text-property 0 'org-marker txt)))
  3986. (error nil)))
  3987. (when effort
  3988. (setq neffort (org-hh:mm-string-to-minutes effort)
  3989. effort (setq effort (concat "[" effort"]" )))))
  3990. (when remove-re
  3991. (while (string-match remove-re txt)
  3992. (setq txt (replace-match "" t t txt))))
  3993. ;; Create the final string
  3994. (if noprefix
  3995. (setq rtn txt)
  3996. ;; Prepare the variables needed in the eval of the compiled format
  3997. (setq time (cond (s2 (concat s1 "-" s2))
  3998. (s1 (concat s1 "......"))
  3999. (t ""))
  4000. extra (or extra "")
  4001. category (if (symbolp category) (symbol-name category) category))
  4002. ;; Evaluate the compiled format
  4003. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4004. ;; And finally add the text properties
  4005. (org-add-props rtn nil
  4006. 'org-category (downcase category)
  4007. 'tags (mapcar 'org-downcase-keep-props tags)
  4008. 'org-highest-priority org-highest-priority
  4009. 'org-lowest-priority org-lowest-priority
  4010. 'prefix-length (- (length rtn) (length txt))
  4011. 'time-of-day time-of-day
  4012. 'duration duration
  4013. 'effort effort
  4014. 'effort-minutes neffort
  4015. 'txt txt
  4016. 'time time
  4017. 'extra extra
  4018. 'dotime dotime))))
  4019. (defun org-agenda-add-inherited-tags (txt tags)
  4020. "Remove tags string from TXT, and add complete list of tags.
  4021. The new list includes inherited tags. If any inherited tags are present,
  4022. a double colon separates inherited tags from local tags."
  4023. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4024. (setq txt (substring txt 0 (match-beginning 0))))
  4025. (when tags
  4026. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4027. i)
  4028. (setq txt (concat txt " :"
  4029. (mapconcat
  4030. (lambda (x)
  4031. (setq i (get-text-property 0 'inherited x))
  4032. (if (and have-i (not i))
  4033. (progn
  4034. (setq have-i nil)
  4035. (concat ":" x))
  4036. x))
  4037. tags ":")
  4038. (if have-i "::" ":")))))
  4039. txt)
  4040. (defun org-downcase-keep-props (s)
  4041. (let ((props (text-properties-at 0 s)))
  4042. (setq s (downcase s))
  4043. (add-text-properties 0 (length s) props s)
  4044. s))
  4045. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4046. (defvar org-agenda-sorting-strategy-selected nil)
  4047. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4048. (catch 'exit
  4049. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4050. ((and todayp (member 'today (car org-agenda-time-grid))))
  4051. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4052. ((member 'weekly (car org-agenda-time-grid)))
  4053. (t (throw 'exit list)))
  4054. (let* ((have (delq nil (mapcar
  4055. (lambda (x) (get-text-property 1 'time-of-day x))
  4056. list)))
  4057. (string (nth 1 org-agenda-time-grid))
  4058. (gridtimes (nth 2 org-agenda-time-grid))
  4059. (req (car org-agenda-time-grid))
  4060. (remove (member 'remove-match req))
  4061. new time)
  4062. (if (and (member 'require-timed req) (not have))
  4063. ;; don't show empty grid
  4064. (throw 'exit list))
  4065. (while (setq time (pop gridtimes))
  4066. (unless (and remove (member time have))
  4067. (setq time (int-to-string time))
  4068. (push (org-format-agenda-item
  4069. nil string "" nil
  4070. (concat (substring time 0 -2) ":" (substring time -2)))
  4071. new)
  4072. (put-text-property
  4073. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4074. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4075. (append new list)
  4076. (append list new)))))
  4077. (defun org-compile-prefix-format (key)
  4078. "Compile the prefix format into a Lisp form that can be evaluated.
  4079. The resulting form is returned and stored in the variable
  4080. `org-prefix-format-compiled'."
  4081. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4082. org-prefix-has-effort nil)
  4083. (let ((s (cond
  4084. ((stringp org-agenda-prefix-format)
  4085. org-agenda-prefix-format)
  4086. ((assq key org-agenda-prefix-format)
  4087. (cdr (assq key org-agenda-prefix-format)))
  4088. (t " %-12:c%?-12t% s")))
  4089. (start 0)
  4090. varform vars var e c f opt)
  4091. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4092. s start)
  4093. (setq var (cdr (assoc (match-string 4 s)
  4094. '(("c" . category) ("t" . time) ("s" . extra)
  4095. ("T" . tag) ("e" . effort))))
  4096. c (or (match-string 3 s) "")
  4097. opt (match-beginning 1)
  4098. start (1+ (match-beginning 0)))
  4099. (if (equal var 'time) (setq org-prefix-has-time t))
  4100. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4101. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4102. (setq f (concat "%" (match-string 2 s) "s"))
  4103. (if opt
  4104. (setq varform
  4105. `(if (equal "" ,var)
  4106. ""
  4107. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4108. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c)))))
  4109. (setq s (replace-match "%s" t nil s))
  4110. (push varform vars))
  4111. (setq vars (nreverse vars))
  4112. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4113. (defun org-set-sorting-strategy (key)
  4114. (if (symbolp (car org-agenda-sorting-strategy))
  4115. ;; the old format
  4116. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4117. (setq org-agenda-sorting-strategy-selected
  4118. (or (cdr (assq key org-agenda-sorting-strategy))
  4119. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4120. '(time-up category-keep priority-down)))))
  4121. (defun org-get-time-of-day (s &optional string mod24)
  4122. "Check string S for a time of day.
  4123. If found, return it as a military time number between 0 and 2400.
  4124. If not found, return nil.
  4125. The optional STRING argument forces conversion into a 5 character wide string
  4126. HH:MM."
  4127. (save-match-data
  4128. (when
  4129. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4130. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4131. (let* ((h (string-to-number (match-string 1 s)))
  4132. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4133. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4134. (am-p (equal ampm "am"))
  4135. (h1 (cond ((not ampm) h)
  4136. ((= h 12) (if am-p 0 12))
  4137. (t (+ h (if am-p 0 12)))))
  4138. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4139. (mod h1 24) h1))
  4140. (t0 (+ (* 100 h2) m))
  4141. (t1 (concat (if (>= h1 24) "+" " ")
  4142. (if (< t0 100) "0" "")
  4143. (if (< t0 10) "0" "")
  4144. (int-to-string t0))))
  4145. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4146. (defun org-finalize-agenda-entries (list &optional nosort)
  4147. "Sort and concatenate the agenda items."
  4148. (setq list (mapcar 'org-agenda-highlight-todo list))
  4149. (if nosort
  4150. list
  4151. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4152. (defun org-agenda-highlight-todo (x)
  4153. (let ((org-done-keywords org-done-keywords-for-agenda)
  4154. re pl)
  4155. (if (eq x 'line)
  4156. (save-excursion
  4157. (beginning-of-line 1)
  4158. (setq re (get-text-property (point) 'org-todo-regexp))
  4159. (goto-char (+ (point) (or (get-text-property (point) 'prefix-length) 0)))
  4160. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4161. (add-text-properties (match-beginning 0) (match-end 1)
  4162. (list 'face (org-get-todo-face 1)))
  4163. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4164. (delete-region (match-beginning 1) (1- (match-end 0)))
  4165. (goto-char (match-beginning 1))
  4166. (insert (format org-agenda-todo-keyword-format s)))))
  4167. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4168. pl (get-text-property 0 'prefix-length x))
  4169. (when (and re
  4170. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4171. x (or pl 0)) pl))
  4172. (add-text-properties
  4173. (or (match-end 1) (match-end 0)) (match-end 0)
  4174. (list 'face (org-get-todo-face (match-string 2 x)))
  4175. x)
  4176. (setq x (concat (substring x 0 (match-end 1))
  4177. (format org-agenda-todo-keyword-format
  4178. (match-string 2 x))
  4179. " "
  4180. (substring x (match-end 3)))))
  4181. x)))
  4182. (defsubst org-cmp-priority (a b)
  4183. "Compare the priorities of string A and B."
  4184. (let ((pa (or (get-text-property 1 'priority a) 0))
  4185. (pb (or (get-text-property 1 'priority b) 0)))
  4186. (cond ((> pa pb) +1)
  4187. ((< pa pb) -1)
  4188. (t nil))))
  4189. (defsubst org-cmp-effort (a b)
  4190. "Compare the priorities of string A and B."
  4191. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4192. (ea (or (get-text-property 1 'effort-minutes a) def))
  4193. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4194. (cond ((> ea eb) +1)
  4195. ((< ea eb) -1)
  4196. (t nil))))
  4197. (defsubst org-cmp-category (a b)
  4198. "Compare the string values of categories of strings A and B."
  4199. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4200. (cb (or (get-text-property 1 'org-category b) "")))
  4201. (cond ((string-lessp ca cb) -1)
  4202. ((string-lessp cb ca) +1)
  4203. (t nil))))
  4204. (defsubst org-cmp-todo-state (a b)
  4205. "Compare the todo states of strings A and B."
  4206. (let* ((ma (or (get-text-property 1 'org-marker a)
  4207. (get-text-property 1 'org-hd-marker a)))
  4208. (mb (or (get-text-property 1 'org-marker b)
  4209. (get-text-property 1 'org-hd-marker b)))
  4210. (fa (and ma (marker-buffer ma)))
  4211. (fb (and mb (marker-buffer mb)))
  4212. (todo-kwds
  4213. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4214. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4215. (ta (or (get-text-property 1 'todo-state a) ""))
  4216. (tb (or (get-text-property 1 'todo-state b) ""))
  4217. (la (- (length (member ta todo-kwds))))
  4218. (lb (- (length (member tb todo-kwds))))
  4219. (donepa (member ta org-done-keywords-for-agenda))
  4220. (donepb (member tb org-done-keywords-for-agenda)))
  4221. (cond ((and donepa (not donepb)) -1)
  4222. ((and (not donepa) donepb) +1)
  4223. ((< la lb) -1)
  4224. ((< lb la) +1)
  4225. (t nil))))
  4226. (defsubst org-cmp-tag (a b)
  4227. "Compare the string values of the first tags of A and B."
  4228. (let ((ta (car (last (get-text-property 1 'tags a))))
  4229. (tb (car (last (get-text-property 1 'tags b)))))
  4230. (cond ((not ta) +1)
  4231. ((not tb) -1)
  4232. ((string-lessp ta tb) -1)
  4233. ((string-lessp tb ta) +1)
  4234. (t nil))))
  4235. (defsubst org-cmp-time (a b)
  4236. "Compare the time-of-day values of strings A and B."
  4237. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4238. (ta (or (get-text-property 1 'time-of-day a) def))
  4239. (tb (or (get-text-property 1 'time-of-day b) def)))
  4240. (cond ((< ta tb) -1)
  4241. ((< tb ta) +1)
  4242. (t nil))))
  4243. (defun org-entries-lessp (a b)
  4244. "Predicate for sorting agenda entries."
  4245. ;; The following variables will be used when the form is evaluated.
  4246. ;; So even though the compiler complains, keep them.
  4247. (let* ((time-up (org-cmp-time a b))
  4248. (time-down (if time-up (- time-up) nil))
  4249. (priority-up (org-cmp-priority a b))
  4250. (priority-down (if priority-up (- priority-up) nil))
  4251. (effort-up (org-cmp-effort a b))
  4252. (effort-down (if effort-up (- effort-up) nil))
  4253. (category-up (org-cmp-category a b))
  4254. (category-down (if category-up (- category-up) nil))
  4255. (category-keep (if category-up +1 nil))
  4256. (tag-up (org-cmp-tag a b))
  4257. (tag-down (if tag-up (- tag-up) nil))
  4258. (todo-state-up (org-cmp-todo-state a b))
  4259. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4260. user-defined-up user-defined-down)
  4261. (if (and org-agenda-cmp-user-defined
  4262. (functionp org-agenda-cmp-user-defined))
  4263. (setq user-defined-up
  4264. (funcall org-agenda-cmp-user-defined a b)
  4265. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  4266. (cdr (assoc
  4267. (eval (cons 'or org-agenda-sorting-strategy-selected))
  4268. '((-1 . t) (1 . nil) (nil . nil))))))
  4269. ;;; Agenda restriction lock
  4270. (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
  4271. "Overlay to mark the headline to which arenda commands are restricted.")
  4272. (org-overlay-put org-agenda-restriction-lock-overlay
  4273. 'face 'org-agenda-restriction-lock)
  4274. (org-overlay-put org-agenda-restriction-lock-overlay
  4275. 'help-echo "Agendas are currently limited to this subtree.")
  4276. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4277. (defun org-agenda-set-restriction-lock (&optional type)
  4278. "Set restriction lock for agenda, to current subtree or file.
  4279. Restriction will be the file if TYPE is `file', or if type is the
  4280. universal prefix '(4), or if the cursor is before the first headline
  4281. in the file. Otherwise, restriction will be to the current subtree."
  4282. (interactive "P")
  4283. (and (equal type '(4)) (setq type 'file))
  4284. (setq type (cond
  4285. (type type)
  4286. ((org-at-heading-p) 'subtree)
  4287. ((condition-case nil (org-back-to-heading t) (error nil))
  4288. 'subtree)
  4289. (t 'file)))
  4290. (if (eq type 'subtree)
  4291. (progn
  4292. (setq org-agenda-restrict t)
  4293. (setq org-agenda-overriding-restriction 'subtree)
  4294. (put 'org-agenda-files 'org-restrict
  4295. (list (buffer-file-name (buffer-base-buffer))))
  4296. (org-back-to-heading t)
  4297. (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  4298. (move-marker org-agenda-restrict-begin (point))
  4299. (move-marker org-agenda-restrict-end
  4300. (save-excursion (org-end-of-subtree t)))
  4301. (message "Locking agenda restriction to subtree"))
  4302. (put 'org-agenda-files 'org-restrict
  4303. (list (buffer-file-name (buffer-base-buffer))))
  4304. (setq org-agenda-restrict nil)
  4305. (setq org-agenda-overriding-restriction 'file)
  4306. (move-marker org-agenda-restrict-begin nil)
  4307. (move-marker org-agenda-restrict-end nil)
  4308. (message "Locking agenda restriction to file"))
  4309. (setq current-prefix-arg nil)
  4310. (org-agenda-maybe-redo))
  4311. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  4312. "Remove the agenda restriction lock."
  4313. (interactive "P")
  4314. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4315. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  4316. (setq org-agenda-overriding-restriction nil)
  4317. (setq org-agenda-restrict nil)
  4318. (put 'org-agenda-files 'org-restrict nil)
  4319. (move-marker org-agenda-restrict-begin nil)
  4320. (move-marker org-agenda-restrict-end nil)
  4321. (setq current-prefix-arg nil)
  4322. (message "Agenda restriction lock removed")
  4323. (or noupdate (org-agenda-maybe-redo)))
  4324. (defun org-agenda-maybe-redo ()
  4325. "If there is any window showing the agenda view, update it."
  4326. (let ((w (get-buffer-window org-agenda-buffer-name t))
  4327. (w0 (selected-window)))
  4328. (when w
  4329. (select-window w)
  4330. (org-agenda-redo)
  4331. (select-window w0)
  4332. (if org-agenda-overriding-restriction
  4333. (message "Agenda view shifted to new %s restriction"
  4334. org-agenda-overriding-restriction)
  4335. (message "Agenda restriction lock removed")))))
  4336. ;;; Agenda commands
  4337. (defun org-agenda-check-type (error &rest types)
  4338. "Check if agenda buffer is of allowed type.
  4339. If ERROR is non-nil, throw an error, otherwise just return nil."
  4340. (if (memq org-agenda-type types)
  4341. t
  4342. (if error
  4343. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  4344. nil)))
  4345. (defun org-agenda-quit ()
  4346. "Exit agenda by removing the window or the buffer."
  4347. (interactive)
  4348. (if org-agenda-columns-active
  4349. (org-columns-quit)
  4350. (let ((buf (current-buffer)))
  4351. (and (not (eq org-agenda-window-setup 'current-window))
  4352. (not (one-window-p))
  4353. (delete-window))
  4354. (kill-buffer buf)
  4355. (org-agenda-reset-markers)
  4356. (org-columns-remove-overlays)
  4357. (setq org-agenda-archives-mode nil))
  4358. ;; Maybe restore the pre-agenda window configuration.
  4359. (and org-agenda-restore-windows-after-quit
  4360. (not (eq org-agenda-window-setup 'other-frame))
  4361. org-pre-agenda-window-conf
  4362. (set-window-configuration org-pre-agenda-window-conf))))
  4363. (defun org-agenda-exit ()
  4364. "Exit agenda by removing the window or the buffer.
  4365. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  4366. Org-mode buffers visited directly by the user will not be touched."
  4367. (interactive)
  4368. (org-release-buffers org-agenda-new-buffers)
  4369. (setq org-agenda-new-buffers nil)
  4370. (org-agenda-quit))
  4371. (defun org-agenda-execute (arg)
  4372. "Execute another agenda command, keeping same window.\\<global-map>
  4373. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  4374. (interactive "P")
  4375. (let ((org-agenda-window-setup 'current-window))
  4376. (org-agenda arg)))
  4377. (defun org-agenda-redo ()
  4378. "Rebuild Agenda.
  4379. When this is the global TODO list, a prefix argument will be interpreted."
  4380. (interactive)
  4381. (let* ((org-agenda-keep-modes t)
  4382. (filter org-agenda-filter)
  4383. (preset (get 'org-agenda-filter :preset-filter))
  4384. (cols org-agenda-columns-active)
  4385. (line (org-current-line))
  4386. (window-line (- line (org-current-line (window-start))))
  4387. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  4388. (put 'org-agenda-filter :preset-filter nil)
  4389. (and cols (org-columns-quit))
  4390. (message "Rebuilding agenda buffer...")
  4391. (org-let lprops '(eval org-agenda-redo-command))
  4392. (setq org-agenda-undo-list nil
  4393. org-agenda-pending-undo-list nil)
  4394. (message "Rebuilding agenda buffer...done")
  4395. (put 'org-agenda-filter :preset-filter preset)
  4396. (and (or filter preset) (org-agenda-filter-apply filter))
  4397. (and cols (interactive-p) (org-agenda-columns))
  4398. (goto-line line)
  4399. (recenter window-line)))
  4400. (defvar org-global-tags-completion-table nil)
  4401. (defvar org-agenda-filter-form nil)
  4402. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  4403. "Keep only those lines in the agenda buffer that have a specific tag.
  4404. The tag is selected with its fast selection letter, as configured.
  4405. With prefix argument STRIP, remove all lines that do have the tag.
  4406. A lisp caller can specify CHAR. NARROW means that the new tag should be
  4407. used to narrow the search - the interactive user can also press `-' or `+'
  4408. to switch to narrowing."
  4409. (interactive "P")
  4410. (let* ((alist org-tag-alist-for-agenda)
  4411. (tag-chars (mapconcat
  4412. (lambda (x) (if (cdr x) (char-to-string (cdr x)) ""))
  4413. alist ""))
  4414. (efforts (org-split-string
  4415. (or (cdr (assoc (concat org-effort-property "_ALL")
  4416. org-global-properties))
  4417. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  4418. (effort-op org-agenda-filter-effort-default-operator)
  4419. (effort-prompt "")
  4420. (inhibit-read-only t)
  4421. (current org-agenda-filter)
  4422. char a n tag)
  4423. (unless char
  4424. (message
  4425. "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
  4426. (if narrow "Narrow" "Filter") tag-chars)
  4427. (setq char (read-char)))
  4428. (when (member char '(?+ ?-))
  4429. ;; Narrowing down
  4430. (cond ((equal char ?-) (setq strip t narrow t))
  4431. ((equal char ?+) (setq strip nil narrow t)))
  4432. (message
  4433. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  4434. (setq char (read-char)))
  4435. (when (member char '(?< ?> ?= ??))
  4436. ;; An effort operator
  4437. (setq effort-op (char-to-string char))
  4438. (setq alist nil) ; to make sure it will be interpreted as effort.
  4439. (unless (equal char ??)
  4440. (loop for i from 0 to 9 do
  4441. (setq effort-prompt
  4442. (concat
  4443. effort-prompt " ["
  4444. (if (= i 9) "0" (int-to-string (1+ i)))
  4445. "]" (nth i efforts))))
  4446. (message "Effort%s: %s " effort-op effort-prompt)
  4447. (setq char (read-char))
  4448. (when (or (< char ?0) (> char ?9))
  4449. (error "Need 1-9,0 to select effort" ))))
  4450. (when (equal char ?\t)
  4451. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  4452. (org-set-local 'org-global-tags-completion-table
  4453. (org-global-tags-completion-table)))
  4454. (let ((completion-ignore-case t))
  4455. (setq tag (org-ido-completing-read
  4456. "Tag: " org-global-tags-completion-table))))
  4457. (cond
  4458. ((equal char ?/)
  4459. (org-agenda-filter-by-tag-show-all)
  4460. (when (get 'org-agenda-filter :preset-filter)
  4461. (org-agenda-filter-apply org-agenda-filter)))
  4462. ((or (equal char ?\ )
  4463. (setq a (rassoc char alist))
  4464. (and (>= char ?0) (<= char ?9)
  4465. (setq n (if (= char ?0) 9 (- char ?0 1))
  4466. tag (concat effort-op (nth n efforts))
  4467. a (cons tag nil)))
  4468. (and (= char ??)
  4469. (setq tag "?eff")
  4470. a (cons tag nil))
  4471. (and tag (setq a (cons tag nil))))
  4472. (org-agenda-filter-by-tag-show-all)
  4473. (setq tag (car a))
  4474. (setq org-agenda-filter
  4475. (cons (concat (if strip "-" "+") tag)
  4476. (if narrow current nil)))
  4477. (org-agenda-filter-apply org-agenda-filter))
  4478. (t (error "Invalid tag selection character %c" char)))))
  4479. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  4480. "Refine the current filter. See `org-agenda-filter-by-tag."
  4481. (interactive "P")
  4482. (org-agenda-filter-by-tag strip char 'refine))
  4483. (defun org-agenda-filter-make-matcher ()
  4484. "Create the form that tests a line for the agenda filter."
  4485. (let (f f1)
  4486. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  4487. org-agenda-filter))
  4488. (if (member x '("-" "+"))
  4489. (setq f1 '(not tags))
  4490. (if (string-match "[<=>?]" x)
  4491. (setq f1 (org-agenda-filter-effort-form x))
  4492. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  4493. (if (equal (string-to-char x) ?-)
  4494. (setq f1 (list 'not f1))))
  4495. (push f1 f))
  4496. (cons 'and (nreverse f))))
  4497. (defun org-agenda-filter-effort-form (e)
  4498. "Return the form to compare the effort of the current line with what E says.
  4499. E looks line \"+<2:25\"."
  4500. (let (op)
  4501. (setq e (substring e 1))
  4502. (setq op (string-to-char e) e (substring e 1))
  4503. (setq op (cond ((equal op ?<) '<=)
  4504. ((equal op ?>) '>=)
  4505. ((equal op ??) op)
  4506. (t '=)))
  4507. (list 'org-agenda-compare-effort (list 'quote op)
  4508. (org-hh:mm-string-to-minutes e))))
  4509. (defun org-agenda-compare-effort (op value)
  4510. "Compare the effort of the current line with VALUE, using OP.
  4511. If the line does not have an effort defined, return nil."
  4512. (let ((eff (get-text-property (point) 'effort-minutes)))
  4513. (if (equal op ??)
  4514. (not eff)
  4515. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  4516. value))))
  4517. (defun org-agenda-filter-apply (filter)
  4518. "Set FILTER as the new agenda filter and apply it."
  4519. (let (tags)
  4520. (setq org-agenda-filter filter
  4521. org-agenda-filter-form (org-agenda-filter-make-matcher))
  4522. (org-agenda-set-mode-name)
  4523. (save-excursion
  4524. (goto-char (point-min))
  4525. (while (not (eobp))
  4526. (if (get-text-property (point) 'org-marker)
  4527. (progn
  4528. (setq tags (get-text-property (point) 'tags)) ; used in eval
  4529. (if (not (eval org-agenda-filter-form))
  4530. (org-agenda-filter-by-tag-hide-line))
  4531. (beginning-of-line 2))
  4532. (beginning-of-line 2))))))
  4533. (defun org-agenda-filter-by-tag-hide-line ()
  4534. (let (ov)
  4535. (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
  4536. (point-at-eol)))
  4537. (org-overlay-put ov 'invisible t)
  4538. (org-overlay-put ov 'type 'tags-filter)
  4539. (push ov org-agenda-filter-overlays)))
  4540. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  4541. (setq pos (or pos (point)))
  4542. (save-excursion
  4543. (dolist (ov (org-overlays-at pos))
  4544. (when (and (org-overlay-get ov 'invisible)
  4545. (eq (org-overlay-get ov 'type) 'tags-filter))
  4546. (goto-char pos)
  4547. (if (< (org-overlay-start ov) (point-at-eol))
  4548. (org-move-overlay ov (point-at-eol)
  4549. (org-overlay-end ov)))))))
  4550. (defun org-agenda-filter-by-tag-show-all ()
  4551. (mapc 'org-delete-overlay org-agenda-filter-overlays)
  4552. (setq org-agenda-filter-overlays nil)
  4553. (setq org-agenda-filter nil)
  4554. (setq org-agenda-filter-form nil)
  4555. (org-agenda-set-mode-name))
  4556. (defun org-agenda-manipulate-query-add ()
  4557. "Manipulate the query by adding a search term with positive selection.
  4558. Positive selection means, the term must be matched for selection of an entry."
  4559. (interactive)
  4560. (org-agenda-manipulate-query ?\[))
  4561. (defun org-agenda-manipulate-query-subtract ()
  4562. "Manipulate the query by adding a search term with negative selection.
  4563. Negative selection means, term must not be matched for selection of an entry."
  4564. (interactive)
  4565. (org-agenda-manipulate-query ?\]))
  4566. (defun org-agenda-manipulate-query-add-re ()
  4567. "Manipulate the query by adding a search regexp with positive selection.
  4568. Positive selection means, the regexp must match for selection of an entry."
  4569. (interactive)
  4570. (org-agenda-manipulate-query ?\{))
  4571. (defun org-agenda-manipulate-query-subtract-re ()
  4572. "Manipulate the query by adding a search regexp with negative selection.
  4573. Negative selection means, regexp must not match for selection of an entry."
  4574. (interactive)
  4575. (org-agenda-manipulate-query ?\}))
  4576. (defun org-agenda-manipulate-query (char)
  4577. (cond
  4578. ((memq org-agenda-type '(timeline agenda))
  4579. (if (y-or-n-p "Re-display with inactive time stamps included? ")
  4580. (let ((org-agenda-include-inactive-timestamps t))
  4581. (org-agenda-redo))
  4582. (error "Abort")))
  4583. ((eq org-agenda-type 'search)
  4584. (org-add-to-string
  4585. 'org-agenda-query-string
  4586. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  4587. (?\{ . " +{}") (?\} . " -{}")))))
  4588. (setq org-agenda-redo-command
  4589. (list 'org-search-view
  4590. org-todo-only
  4591. org-agenda-query-string
  4592. (+ (length org-agenda-query-string)
  4593. (if (member char '(?\{ ?\})) 0 1))))
  4594. (set-register org-agenda-query-register org-agenda-query-string)
  4595. (org-agenda-redo))
  4596. (t (error "Cannot manipulate query for %s-type agenda buffers"
  4597. org-agenda-type))))
  4598. (defun org-add-to-string (var string)
  4599. (set var (concat (symbol-value var) string)))
  4600. (defun org-agenda-goto-date (date)
  4601. "Jump to DATE in agenda."
  4602. (interactive (list (org-read-date)))
  4603. (org-agenda-list nil date))
  4604. (defun org-agenda-goto-today ()
  4605. "Go to today."
  4606. (interactive)
  4607. (org-agenda-check-type t 'timeline 'agenda)
  4608. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  4609. (cond
  4610. (tdpos (goto-char tdpos))
  4611. ((eq org-agenda-type 'agenda)
  4612. (let* ((sd (time-to-days
  4613. (time-subtract (current-time)
  4614. (list 0 (* 3600 org-extend-today-until) 0))))
  4615. (comp (org-agenda-compute-time-span sd org-agenda-span))
  4616. (org-agenda-overriding-arguments org-agenda-last-arguments))
  4617. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  4618. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  4619. (org-agenda-redo)
  4620. (org-agenda-find-same-or-today-or-agenda)))
  4621. (t (error "Cannot find today")))))
  4622. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  4623. (goto-char
  4624. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  4625. (text-property-any (point-min) (point-max) 'org-today t)
  4626. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  4627. (point-min))))
  4628. (defun org-agenda-later (arg)
  4629. "Go forward in time by thee current span.
  4630. With prefix ARG, go forward that many times the current span."
  4631. (interactive "p")
  4632. (org-agenda-check-type t 'agenda)
  4633. (let* ((span org-agenda-span)
  4634. (sd org-starting-day)
  4635. (greg (calendar-gregorian-from-absolute sd))
  4636. (cnt (get-text-property (point) 'org-day-cnt))
  4637. greg2 nd)
  4638. (cond
  4639. ((eq span 'day)
  4640. (setq sd (+ arg sd) nd 1))
  4641. ((eq span 'week)
  4642. (setq sd (+ (* 7 arg) sd) nd 7))
  4643. ((eq span 'month)
  4644. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  4645. sd (calendar-absolute-from-gregorian greg2))
  4646. (setcar greg2 (1+ (car greg2)))
  4647. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  4648. ((eq span 'year)
  4649. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  4650. sd (calendar-absolute-from-gregorian greg2))
  4651. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  4652. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  4653. (let ((org-agenda-overriding-arguments
  4654. (list (car org-agenda-last-arguments) sd nd t)))
  4655. (org-agenda-redo)
  4656. (org-agenda-find-same-or-today-or-agenda cnt))))
  4657. (defun org-agenda-earlier (arg)
  4658. "Go backward in time by the current span.
  4659. With prefix ARG, go backward that many times the current span."
  4660. (interactive "p")
  4661. (org-agenda-later (- arg)))
  4662. (defun org-agenda-view-mode-dispatch ()
  4663. "Call one of the view mode commands."
  4664. (interactive)
  4665. (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
  4666. clock[R]eport time[G]rid include[D]iary")
  4667. (let ((a (read-char-exclusive)))
  4668. (case a
  4669. (?d (call-interactively 'org-agenda-day-view))
  4670. (?w (call-interactively 'org-agenda-week-view))
  4671. (?m (call-interactively 'org-agenda-month-view))
  4672. (?y (call-interactively 'org-agenda-year-view))
  4673. (?l (call-interactively 'org-agenda-log-mode))
  4674. (?a (call-interactively 'org-agenda-archives-mode))
  4675. (?A (org-agenda-archives-mode 'files))
  4676. (?R (call-interactively 'org-agenda-clockreport-mode))
  4677. (?G (call-interactively 'org-agenda-toggle-time-grid))
  4678. (?D (call-interactively 'org-agenda-toggle-diary))
  4679. (?q (message "Abort"))
  4680. (otherwise (error "Invalid key" )))))
  4681. (defun org-agenda-day-view (&optional day-of-year)
  4682. "Switch to daily view for agenda.
  4683. With argument DAY-OF-YEAR, switch to that day of the year."
  4684. (interactive "P")
  4685. (setq org-agenda-ndays 1)
  4686. (org-agenda-change-time-span 'day day-of-year))
  4687. (defun org-agenda-week-view (&optional iso-week)
  4688. "Switch to daily view for agenda.
  4689. With argument ISO-WEEK, switch to the corresponding ISO week.
  4690. If ISO-WEEK has more then 2 digits, only the last two encode the
  4691. week. Any digits before this encode a year. So 200712 means
  4692. week 12 of year 2007. Years in the range 1938-2037 can also be
  4693. written as 2-digit years."
  4694. (interactive "P")
  4695. (setq org-agenda-ndays 7)
  4696. (org-agenda-change-time-span 'week iso-week))
  4697. (defun org-agenda-month-view (&optional month)
  4698. "Switch to monthly view for agenda.
  4699. With argument MONTH, switch to that month."
  4700. (interactive "P")
  4701. (org-agenda-change-time-span 'month month))
  4702. (defun org-agenda-year-view (&optional year)
  4703. "Switch to yearly view for agenda.
  4704. With argument YEAR, switch to that year.
  4705. If MONTH has more then 2 digits, only the last two encode the
  4706. month. Any digits before this encode a year. So 200712 means
  4707. December year 2007. Years in the range 1938-2037 can also be
  4708. written as 2-digit years."
  4709. (interactive "P")
  4710. (when year
  4711. (setq year (org-small-year-to-year year)))
  4712. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  4713. (org-agenda-change-time-span 'year year)
  4714. (error "Abort")))
  4715. (defun org-agenda-change-time-span (span &optional n)
  4716. "Change the agenda view to SPAN.
  4717. SPAN may be `day', `week', `month', `year'."
  4718. (org-agenda-check-type t 'agenda)
  4719. (if (and (not n) (equal org-agenda-span span))
  4720. (error "Viewing span is already \"%s\"" span))
  4721. (let* ((sd (or (get-text-property (point) 'day)
  4722. org-starting-day))
  4723. (computed (org-agenda-compute-time-span sd span n))
  4724. (org-agenda-overriding-arguments
  4725. (list (car org-agenda-last-arguments)
  4726. (car computed) (cdr computed) t)))
  4727. (org-agenda-redo)
  4728. (org-agenda-find-same-or-today-or-agenda))
  4729. (org-agenda-set-mode-name)
  4730. (message "Switched to %s view" span))
  4731. (defun org-agenda-compute-time-span (sd span &optional n)
  4732. "Compute starting date and number of days for agenda.
  4733. SPAN may be `day', `week', `month', `year'. The return value
  4734. is a cons cell with the starting date and the number of days,
  4735. so that the date SD will be in that range."
  4736. (let* ((greg (calendar-gregorian-from-absolute sd))
  4737. (dg (nth 1 greg))
  4738. (mg (car greg))
  4739. (yg (nth 2 greg))
  4740. nd w1 y1 m1 thisweek)
  4741. (cond
  4742. ((eq span 'day)
  4743. (when n
  4744. (setq sd (+ (calendar-absolute-from-gregorian
  4745. (list mg 1 yg))
  4746. n -1)))
  4747. (setq nd 1))
  4748. ((eq span 'week)
  4749. (let* ((nt (calendar-day-of-week
  4750. (calendar-gregorian-from-absolute sd)))
  4751. (d (if org-agenda-start-on-weekday
  4752. (- nt org-agenda-start-on-weekday)
  4753. 0)))
  4754. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  4755. (when n
  4756. (require 'cal-iso)
  4757. (setq thisweek (car (calendar-iso-from-absolute sd)))
  4758. (when (> n 99)
  4759. (setq y1 (org-small-year-to-year (/ n 100))
  4760. n (mod n 100)))
  4761. (setq sd
  4762. (calendar-absolute-from-iso
  4763. (list n 1
  4764. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  4765. (setq nd 7)))
  4766. ((eq span 'month)
  4767. (when (and n (> n 99))
  4768. (setq y1 (org-small-year-to-year (/ n 100))
  4769. n (mod n 100)))
  4770. (setq sd (calendar-absolute-from-gregorian
  4771. (list (or n mg) 1 (or y1 yg)))
  4772. nd (- (calendar-absolute-from-gregorian
  4773. (list (1+ (or n mg)) 1 (or y1 yg)))
  4774. sd)))
  4775. ((eq span 'year)
  4776. (setq sd (calendar-absolute-from-gregorian
  4777. (list 1 1 (or n yg)))
  4778. nd (- (calendar-absolute-from-gregorian
  4779. (list 1 1 (1+ (or n yg))))
  4780. sd))))
  4781. (cons sd nd)))
  4782. (defun org-agenda-next-date-line (&optional arg)
  4783. "Jump to the next line indicating a date in agenda buffer."
  4784. (interactive "p")
  4785. (org-agenda-check-type t 'agenda 'timeline)
  4786. (beginning-of-line 1)
  4787. ;; This does not work if user makes date format that starts with a blank
  4788. (if (looking-at "^\\S-") (forward-char 1))
  4789. (if (not (re-search-forward "^\\S-" nil t arg))
  4790. (progn
  4791. (backward-char 1)
  4792. (error "No next date after this line in this buffer")))
  4793. (goto-char (match-beginning 0)))
  4794. (defun org-agenda-previous-date-line (&optional arg)
  4795. "Jump to the previous line indicating a date in agenda buffer."
  4796. (interactive "p")
  4797. (org-agenda-check-type t 'agenda 'timeline)
  4798. (beginning-of-line 1)
  4799. (if (not (re-search-backward "^\\S-" nil t arg))
  4800. (error "No previous date before this line in this buffer")))
  4801. ;; Initialize the highlight
  4802. (defvar org-hl (org-make-overlay 1 1))
  4803. (org-overlay-put org-hl 'face 'highlight)
  4804. (defun org-highlight (begin end &optional buffer)
  4805. "Highlight a region with overlay."
  4806. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  4807. org-hl begin end (or buffer (current-buffer))))
  4808. (defun org-unhighlight ()
  4809. "Detach overlay INDEX."
  4810. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  4811. ;; FIXME this is currently not used.
  4812. (defun org-highlight-until-next-command (beg end &optional buffer)
  4813. "Move the highlight overlay to BEG/END, remove it before the next command."
  4814. (org-highlight beg end buffer)
  4815. (add-hook 'pre-command-hook 'org-unhighlight-once))
  4816. (defun org-unhighlight-once ()
  4817. "Remove the highlight from its position, and this function from the hook."
  4818. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  4819. (org-unhighlight))
  4820. (defun org-agenda-follow-mode ()
  4821. "Toggle follow mode in an agenda buffer."
  4822. (interactive)
  4823. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  4824. (org-agenda-set-mode-name)
  4825. (message "Follow mode is %s"
  4826. (if org-agenda-follow-mode "on" "off")))
  4827. (defun org-agenda-clockreport-mode ()
  4828. "Toggle clocktable mode in an agenda buffer."
  4829. (interactive)
  4830. (org-agenda-check-type t 'agenda)
  4831. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  4832. (org-agenda-set-mode-name)
  4833. (org-agenda-redo)
  4834. (message "Clocktable mode is %s"
  4835. (if org-agenda-clockreport-mode "on" "off")))
  4836. (defun org-agenda-log-mode (&optional special)
  4837. "Toggle log mode in an agenda buffer.
  4838. With argument SPECIAL, show all possible log items, not only the ones
  4839. configured in `org-agenda-log-mode-items'.
  4840. With a double `C-u' prefix arg, show *only* log items, nothing else."
  4841. (interactive "P")
  4842. (org-agenda-check-type t 'agenda 'timeline)
  4843. (setq org-agenda-show-log
  4844. (if (equal special '(16))
  4845. 'only
  4846. (if special '(closed clock state)
  4847. (not org-agenda-show-log))))
  4848. (org-agenda-set-mode-name)
  4849. (org-agenda-redo)
  4850. (message "Log mode is %s"
  4851. (if org-agenda-show-log "on" "off")))
  4852. (defun org-agenda-archives-mode (&optional with-files)
  4853. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  4854. When called with a prefix argument, include all archive files as well."
  4855. (interactive "P")
  4856. (setq org-agenda-archives-mode
  4857. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  4858. (org-agenda-set-mode-name)
  4859. (org-agenda-redo)
  4860. (message
  4861. "%s"
  4862. (cond
  4863. ((eq org-agenda-archives-mode nil)
  4864. "No archives are included")
  4865. ((eq org-agenda-archives-mode 'trees)
  4866. (format "Trees with :%s: tag are included" org-archive-tag))
  4867. ((eq org-agenda-archives-mode t)
  4868. (format "Trees with :%s: tag and all active archive files are included"
  4869. org-archive-tag)))))
  4870. (defun org-agenda-toggle-diary ()
  4871. "Toggle diary inclusion in an agenda buffer."
  4872. (interactive)
  4873. (org-agenda-check-type t 'agenda)
  4874. (setq org-agenda-include-diary (not org-agenda-include-diary))
  4875. (org-agenda-redo)
  4876. (org-agenda-set-mode-name)
  4877. (message "Diary inclusion turned %s"
  4878. (if org-agenda-include-diary "on" "off")))
  4879. (defun org-agenda-toggle-time-grid ()
  4880. "Toggle time grid in an agenda buffer."
  4881. (interactive)
  4882. (org-agenda-check-type t 'agenda)
  4883. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  4884. (org-agenda-redo)
  4885. (org-agenda-set-mode-name)
  4886. (message "Time-grid turned %s"
  4887. (if org-agenda-use-time-grid "on" "off")))
  4888. (defun org-agenda-set-mode-name ()
  4889. "Set the mode name to indicate all the small mode settings."
  4890. (setq mode-name
  4891. (concat "Org-Agenda"
  4892. (if (equal org-agenda-ndays 1) " Day" "")
  4893. (if (equal org-agenda-ndays 7) " Week" "")
  4894. (if org-agenda-follow-mode " Follow" "")
  4895. (if org-agenda-include-diary " Diary" "")
  4896. (if org-agenda-use-time-grid " Grid" "")
  4897. (if (consp org-agenda-show-log) " LogAll"
  4898. (if org-agenda-show-log " Log" ""))
  4899. (if (or org-agenda-filter (get 'org-agenda-filter
  4900. :preset-filter))
  4901. (concat " {" (mapconcat
  4902. 'identity
  4903. (append (get 'org-agenda-filter
  4904. :preset-filter)
  4905. org-agenda-filter) "") "}")
  4906. "")
  4907. (if org-agenda-archives-mode
  4908. (if (eq org-agenda-archives-mode t)
  4909. " Archives"
  4910. (format " :%s:" org-archive-tag))
  4911. "")
  4912. (if org-agenda-clockreport-mode " Clock" "")))
  4913. (force-mode-line-update))
  4914. (defun org-agenda-post-command-hook ()
  4915. (and (eolp) (not (bolp)) (backward-char 1))
  4916. (setq org-agenda-type
  4917. (or (get-text-property (point) 'org-agenda-type)
  4918. (get-text-property (max (point-min) (1- (point)))
  4919. 'org-agenda-type)))
  4920. (if (and org-agenda-follow-mode
  4921. (get-text-property (point) 'org-marker))
  4922. (org-agenda-show)))
  4923. (defun org-agenda-show-priority ()
  4924. "Show the priority of the current item.
  4925. This priority is composed of the main priority given with the [#A] cookies,
  4926. and by additional input from the age of a schedules or deadline entry."
  4927. (interactive)
  4928. (let* ((pri (get-text-property (point-at-bol) 'priority)))
  4929. (message "Priority is %d" (if pri pri -1000))))
  4930. (defun org-agenda-show-tags ()
  4931. "Show the tags applicable to the current item."
  4932. (interactive)
  4933. (let* ((tags (get-text-property (point-at-bol) 'tags)))
  4934. (if tags
  4935. (message "Tags are :%s:"
  4936. (org-no-properties (mapconcat 'identity tags ":")))
  4937. (message "No tags associated with this line"))))
  4938. (defun org-agenda-goto (&optional highlight)
  4939. "Go to the Org-mode file which contains the item at point."
  4940. (interactive)
  4941. (let* ((marker (or (get-text-property (point) 'org-marker)
  4942. (org-agenda-error)))
  4943. (buffer (marker-buffer marker))
  4944. (pos (marker-position marker)))
  4945. (switch-to-buffer-other-window buffer)
  4946. (widen)
  4947. (goto-char pos)
  4948. (when (org-mode-p)
  4949. (org-show-context 'agenda)
  4950. (save-excursion
  4951. (and (outline-next-heading)
  4952. (org-flag-heading nil)))) ; show the next heading
  4953. (recenter (/ (window-height) 2))
  4954. (run-hooks 'org-agenda-after-show-hook)
  4955. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  4956. (defvar org-agenda-after-show-hook nil
  4957. "Normal hook run after an item has been shown from the agenda.
  4958. Point is in the buffer where the item originated.")
  4959. (defun org-agenda-kill ()
  4960. "Kill the entry or subtree belonging to the current agenda entry."
  4961. (interactive)
  4962. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  4963. (let* ((marker (or (get-text-property (point) 'org-marker)
  4964. (org-agenda-error)))
  4965. (buffer (marker-buffer marker))
  4966. (pos (marker-position marker))
  4967. (type (get-text-property (point) 'type))
  4968. dbeg dend (n 0) conf)
  4969. (org-with-remote-undo buffer
  4970. (with-current-buffer buffer
  4971. (save-excursion
  4972. (goto-char pos)
  4973. (if (and (org-mode-p) (not (member type '("sexp"))))
  4974. (setq dbeg (progn (org-back-to-heading t) (point))
  4975. dend (org-end-of-subtree t t))
  4976. (setq dbeg (point-at-bol)
  4977. dend (min (point-max) (1+ (point-at-eol)))))
  4978. (goto-char dbeg)
  4979. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  4980. (setq conf (or (eq t org-agenda-confirm-kill)
  4981. (and (numberp org-agenda-confirm-kill)
  4982. (> n org-agenda-confirm-kill))))
  4983. (and conf
  4984. (not (y-or-n-p
  4985. (format "Delete entry with %d lines in buffer \"%s\"? "
  4986. n (buffer-name buffer))))
  4987. (error "Abort"))
  4988. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  4989. (with-current-buffer buffer (delete-region dbeg dend))
  4990. (message "Agenda item and source killed"))))
  4991. (defun org-agenda-archive ()
  4992. "Archive the entry or subtree belonging to the current agenda entry."
  4993. (interactive)
  4994. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  4995. (let* ((marker (or (get-text-property (point) 'org-marker)
  4996. (org-agenda-error)))
  4997. (buffer (marker-buffer marker))
  4998. (pos (marker-position marker)))
  4999. (org-with-remote-undo buffer
  5000. (with-current-buffer buffer
  5001. (if (org-mode-p)
  5002. (save-excursion
  5003. (goto-char pos)
  5004. (org-remove-subtree-entries-from-agenda)
  5005. (org-back-to-heading t)
  5006. (org-archive-subtree))
  5007. (error "Archiving works only in Org-mode files"))))))
  5008. (defun org-agenda-archive-to-archive-sibling ()
  5009. "Move the entry to the archive sibling."
  5010. (interactive)
  5011. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5012. (let* ((marker (or (get-text-property (point) 'org-marker)
  5013. (org-agenda-error)))
  5014. (buffer (marker-buffer marker))
  5015. (pos (marker-position marker)))
  5016. (org-with-remote-undo buffer
  5017. (with-current-buffer buffer
  5018. (if (org-mode-p)
  5019. (save-excursion
  5020. (goto-char pos)
  5021. (org-remove-subtree-entries-from-agenda)
  5022. (org-back-to-heading t)
  5023. (org-archive-to-archive-sibling))
  5024. (error "Archiving works only in Org-mode files"))))))
  5025. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5026. "Remove all lines in the agenda that correspond to a given subtree.
  5027. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5028. If this information is not given, the function uses the tree at point."
  5029. (let ((buf (or buf (current-buffer))) m p)
  5030. (save-excursion
  5031. (unless (and beg end)
  5032. (org-back-to-heading t)
  5033. (setq beg (point))
  5034. (org-end-of-subtree t)
  5035. (setq end (point)))
  5036. (set-buffer (get-buffer org-agenda-buffer-name))
  5037. (save-excursion
  5038. (goto-char (point-max))
  5039. (beginning-of-line 1)
  5040. (while (not (bobp))
  5041. (when (and (setq m (get-text-property (point) 'org-marker))
  5042. (equal buf (marker-buffer m))
  5043. (setq p (marker-position m))
  5044. (>= p beg)
  5045. (< p end))
  5046. (let ((inhibit-read-only t))
  5047. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5048. (beginning-of-line 0))))))
  5049. (defun org-agenda-refile (&optional goto rfloc)
  5050. "Refile the item at point."
  5051. (interactive "P")
  5052. (let* ((marker (or (get-text-property (point) 'org-hd-marker)
  5053. (org-agenda-error)))
  5054. (buffer (marker-buffer marker))
  5055. (pos (marker-position marker))
  5056. (rfloc (or rfloc
  5057. (org-refile-get-location
  5058. (if goto "Goto: " "Refile to: ") buffer
  5059. org-refile-allow-creating-parent-nodes))))
  5060. (with-current-buffer buffer
  5061. (save-excursion
  5062. (save-restriction
  5063. (widen)
  5064. (goto-char marker)
  5065. (org-remove-subtree-entries-from-agenda)
  5066. (org-refile goto buffer rfloc))))))
  5067. (defun org-agenda-open-link ()
  5068. "Follow the link in the current line, if any."
  5069. (interactive)
  5070. (org-agenda-copy-local-variable 'org-link-abbrev-alist-local)
  5071. (save-excursion
  5072. (save-restriction
  5073. (narrow-to-region (point-at-bol) (point-at-eol))
  5074. (org-open-at-point))))
  5075. (defun org-agenda-copy-local-variable (var)
  5076. "Get a variable from a referenced buffer and install it here."
  5077. (let ((m (get-text-property (point) 'org-marker)))
  5078. (when (and m (buffer-live-p (marker-buffer m)))
  5079. (org-set-local var (with-current-buffer (marker-buffer m)
  5080. (symbol-value var))))))
  5081. (defun org-agenda-switch-to (&optional delete-other-windows)
  5082. "Go to the Org-mode file which contains the item at point."
  5083. (interactive)
  5084. (let* ((marker (or (get-text-property (point) 'org-marker)
  5085. (org-agenda-error)))
  5086. (buffer (marker-buffer marker))
  5087. (pos (marker-position marker)))
  5088. (switch-to-buffer buffer)
  5089. (and delete-other-windows (delete-other-windows))
  5090. (widen)
  5091. (goto-char pos)
  5092. (when (org-mode-p)
  5093. (org-show-context 'agenda)
  5094. (save-excursion
  5095. (and (outline-next-heading)
  5096. (org-flag-heading nil)))))) ; show the next heading
  5097. (defun org-agenda-goto-mouse (ev)
  5098. "Go to the Org-mode file which contains the item at the mouse click."
  5099. (interactive "e")
  5100. (mouse-set-point ev)
  5101. (org-agenda-goto))
  5102. (defun org-agenda-show (&optional full-entry)
  5103. "Display the Org-mode file which contains the item at point.
  5104. With prefix argument FULL-ENTRY, make the entire entry visible
  5105. if it was hidden in the outline."
  5106. (interactive "P")
  5107. (let ((win (selected-window)))
  5108. (if full-entry
  5109. (let ((org-show-entry-below t))
  5110. (org-agenda-goto t))
  5111. (org-agenda-goto t))
  5112. (select-window win)))
  5113. (defun org-agenda-show-1 (&optional more)
  5114. "Display the Org-mode file which contains the item at point.
  5115. The prefix arg causes further revieling:
  5116. 0 hide the subtree
  5117. 1 just show the entry according to defaults.
  5118. 2 show the text below the heading
  5119. 3 show the entire subtree
  5120. 4 show the entire subtree and any LOGBOOK drawers
  5121. 5 show the entire subtree and any drawers
  5122. With prefix argument FULL-ENTRY, make the entire entry visible
  5123. if it was hidden in the outline."
  5124. (interactive "p")
  5125. (let ((win (selected-window)))
  5126. (org-agenda-goto t)
  5127. (org-recenter-heading 1)
  5128. (cond
  5129. ((= more 0)
  5130. (hide-subtree)
  5131. (message "Remote: hide subtree"))
  5132. ((and (interactive-p) (= more 1))
  5133. (message "Remote: show with default settings"))
  5134. ((= more 2)
  5135. (show-entry)
  5136. (save-excursion
  5137. (org-back-to-heading)
  5138. (org-cycle-hide-drawers 'children))
  5139. (message "Remote: show entry"))
  5140. ((= more 3)
  5141. (show-subtree)
  5142. (save-excursion
  5143. (org-back-to-heading)
  5144. (org-cycle-hide-drawers 'subtree))
  5145. (message "Remote: show subtree"))
  5146. ((= more 4)
  5147. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  5148. (org-drawer-regexp
  5149. (concat "^[ \t]*:\\("
  5150. (mapconcat 'regexp-quote org-drawers "\\|")
  5151. "\\):[ \t]*$")))
  5152. (show-subtree)
  5153. (save-excursion
  5154. (org-back-to-heading)
  5155. (org-cycle-hide-drawers 'subtree)))
  5156. (message "Remote: show subtree and LOGBOOK"))
  5157. ((> more 4)
  5158. (show-subtree)
  5159. (message "Remote: show subtree and LOGBOOK")))
  5160. (select-window win)))
  5161. (defun org-recenter-heading (n)
  5162. (save-excursion
  5163. (org-back-to-heading)
  5164. (recenter n)))
  5165. (defvar org-agenda-cycle-counter nil)
  5166. (defun org-agenda-cycle-show (n)
  5167. "Show the current entry in another window, with default settings.
  5168. Default settings are taken from `org-show-hierarchy-above' and siblings.
  5169. When use repeadedly in immediate succession, the remote entry will cycle
  5170. through visibility
  5171. entry -> subtree -> subtree with logbook"
  5172. (interactive "p")
  5173. (when (and (= n 1)
  5174. (not (eq last-command this-command)))
  5175. (setq org-agenda-cycle-counter 0))
  5176. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  5177. (if (> org-agenda-cycle-counter 4)
  5178. (setq org-agenda-cycle-counter 0))
  5179. (org-agenda-show-1 org-agenda-cycle-counter))
  5180. (defun org-agenda-recenter (arg)
  5181. "Display the Org-mode file which contains the item at point and recenter."
  5182. (interactive "P")
  5183. (let ((win (selected-window)))
  5184. (org-agenda-goto t)
  5185. (recenter arg)
  5186. (select-window win)))
  5187. (defun org-agenda-show-mouse (ev)
  5188. "Display the Org-mode file which contains the item at the mouse click."
  5189. (interactive "e")
  5190. (mouse-set-point ev)
  5191. (org-agenda-show))
  5192. (defun org-agenda-check-no-diary ()
  5193. "Check if the entry is a diary link and abort if yes."
  5194. (if (get-text-property (point) 'org-agenda-diary-link)
  5195. (org-agenda-error)))
  5196. (defun org-agenda-error ()
  5197. (error "Command not allowed in this line"))
  5198. (defun org-agenda-tree-to-indirect-buffer ()
  5199. "Show the subtree corresponding to the current entry in an indirect buffer.
  5200. This calls the command `org-tree-to-indirect-buffer' from the original
  5201. Org-mode buffer.
  5202. With numerical prefix arg ARG, go up to this level and then take that tree.
  5203. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  5204. dedicated frame)."
  5205. (interactive)
  5206. (org-agenda-check-no-diary)
  5207. (let* ((marker (or (get-text-property (point) 'org-marker)
  5208. (org-agenda-error)))
  5209. (buffer (marker-buffer marker))
  5210. (pos (marker-position marker)))
  5211. (with-current-buffer buffer
  5212. (save-excursion
  5213. (goto-char pos)
  5214. (call-interactively 'org-tree-to-indirect-buffer)))))
  5215. (defvar org-last-heading-marker (make-marker)
  5216. "Marker pointing to the headline that last changed its TODO state
  5217. by a remote command from the agenda.")
  5218. (defun org-agenda-todo-nextset ()
  5219. "Switch TODO entry to next sequence."
  5220. (interactive)
  5221. (org-agenda-todo 'nextset))
  5222. (defun org-agenda-todo-previousset ()
  5223. "Switch TODO entry to previous sequence."
  5224. (interactive)
  5225. (org-agenda-todo 'previousset))
  5226. (defun org-agenda-todo (&optional arg)
  5227. "Cycle TODO state of line at point, also in Org-mode file.
  5228. This changes the line at point, all other lines in the agenda referring to
  5229. the same tree node, and the headline of the tree node in the Org-mode file."
  5230. (interactive "P")
  5231. (org-agenda-check-no-diary)
  5232. (let* ((col (current-column))
  5233. (marker (or (get-text-property (point) 'org-marker)
  5234. (org-agenda-error)))
  5235. (buffer (marker-buffer marker))
  5236. (pos (marker-position marker))
  5237. (hdmarker (get-text-property (point) 'org-hd-marker))
  5238. (todayp (equal (get-text-property (point) 'day)
  5239. (time-to-days (current-time))))
  5240. (inhibit-read-only t)
  5241. org-agenda-headline-snapshot-before-repeat newhead just-one)
  5242. (org-with-remote-undo buffer
  5243. (with-current-buffer buffer
  5244. (widen)
  5245. (goto-char pos)
  5246. (org-show-context 'agenda)
  5247. (save-excursion
  5248. (and (outline-next-heading)
  5249. (org-flag-heading nil))) ; show the next heading
  5250. (let ((current-prefix-arg arg))
  5251. (call-interactively 'org-todo))
  5252. (and (bolp) (forward-char 1))
  5253. (setq newhead (org-get-heading))
  5254. (when (and (org-bound-and-true-p
  5255. org-agenda-headline-snapshot-before-repeat)
  5256. (not (equal org-agenda-headline-snapshot-before-repeat
  5257. newhead))
  5258. todayp)
  5259. (setq newhead org-agenda-headline-snapshot-before-repeat
  5260. just-one t))
  5261. (save-excursion
  5262. (org-back-to-heading)
  5263. (move-marker org-last-heading-marker (point))))
  5264. (beginning-of-line 1)
  5265. (save-excursion
  5266. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  5267. (org-move-to-column col))))
  5268. (defun org-agenda-add-note (&optional arg)
  5269. "Add a time-stamped note to the entry at point."
  5270. (interactive "P")
  5271. (org-agenda-check-no-diary)
  5272. (let* ((marker (or (get-text-property (point) 'org-marker)
  5273. (org-agenda-error)))
  5274. (buffer (marker-buffer marker))
  5275. (pos (marker-position marker))
  5276. (hdmarker (get-text-property (point) 'org-hd-marker))
  5277. (inhibit-read-only t))
  5278. (with-current-buffer buffer
  5279. (widen)
  5280. (goto-char pos)
  5281. (org-show-context 'agenda)
  5282. (save-excursion
  5283. (and (outline-next-heading)
  5284. (org-flag-heading nil))) ; show the next heading
  5285. (org-add-note))))
  5286. (defun org-agenda-change-all-lines (newhead hdmarker
  5287. &optional fixface just-this)
  5288. "Change all lines in the agenda buffer which match HDMARKER.
  5289. The new content of the line will be NEWHEAD (as modified by
  5290. `org-format-agenda-item'). HDMARKER is checked with
  5291. `equal' against all `org-hd-marker' text properties in the file.
  5292. If FIXFACE is non-nil, the face of each item is modified according to
  5293. the new TODO state.
  5294. If JUST-THIS is non-nil, change just the current line, not all.
  5295. If FORCE-TAGS is non nil, the car of it returns the new tags."
  5296. (let* ((inhibit-read-only t)
  5297. (line (org-current-line))
  5298. (thetags (with-current-buffer (marker-buffer hdmarker)
  5299. (save-excursion (save-restriction (widen)
  5300. (goto-char hdmarker)
  5301. (org-get-tags-at)))))
  5302. props m pl undone-face done-face finish new dotime cat tags)
  5303. (save-excursion
  5304. (goto-char (point-max))
  5305. (beginning-of-line 1)
  5306. (while (not finish)
  5307. (setq finish (bobp))
  5308. (when (and (setq m (get-text-property (point) 'org-hd-marker))
  5309. (or (not just-this) (= (org-current-line) line))
  5310. (equal m hdmarker))
  5311. (setq props (text-properties-at (point))
  5312. dotime (get-text-property (point) 'dotime)
  5313. cat (get-text-property (point) 'org-category)
  5314. tags thetags
  5315. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  5316. pl (get-text-property (point) 'prefix-length)
  5317. undone-face (get-text-property (point) 'undone-face)
  5318. done-face (get-text-property (point) 'done-face))
  5319. (org-move-to-column pl)
  5320. (cond
  5321. ((equal new "")
  5322. (beginning-of-line 1)
  5323. (and (looking-at ".*\n?") (replace-match "")))
  5324. ((looking-at ".*")
  5325. (replace-match new t t)
  5326. (beginning-of-line 1)
  5327. (add-text-properties (point-at-bol) (point-at-eol) props)
  5328. (when fixface
  5329. (add-text-properties
  5330. (point-at-bol) (point-at-eol)
  5331. (list 'face
  5332. (if org-last-todo-state-is-todo
  5333. undone-face done-face))))
  5334. (org-agenda-highlight-todo 'line)
  5335. (beginning-of-line 1))
  5336. (t (error "Line update did not work"))))
  5337. (beginning-of-line 0)))
  5338. (org-finalize-agenda)))
  5339. (defun org-agenda-align-tags (&optional line)
  5340. "Align all tags in agenda items to `org-agenda-tags-column'."
  5341. (let ((inhibit-read-only t) l c)
  5342. (save-excursion
  5343. (goto-char (if line (point-at-bol) (point-min)))
  5344. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  5345. (if line (point-at-eol) nil) t)
  5346. (add-text-properties
  5347. (match-beginning 2) (match-end 2)
  5348. (list 'face (delq nil (let ((prop (get-text-property
  5349. (match-beginning 2) 'face)))
  5350. (or (listp prop) (setq prop (list prop)))
  5351. (if (memq 'org-tag prop)
  5352. prop
  5353. (cons 'org-tag prop))))))
  5354. (setq l (- (match-end 2) (match-beginning 2))
  5355. c (if (< org-agenda-tags-column 0)
  5356. (- (abs org-agenda-tags-column) l)
  5357. org-agenda-tags-column))
  5358. (delete-region (match-beginning 1) (match-end 1))
  5359. (goto-char (match-beginning 1))
  5360. (insert (org-add-props
  5361. (make-string (max 1 (- c (current-column))) ?\ )
  5362. (text-properties-at (point)))))
  5363. (goto-char (point-min))
  5364. (org-font-lock-add-tag-faces (point-max)))))
  5365. (defun org-agenda-priority-up ()
  5366. "Increase the priority of line at point, also in Org-mode file."
  5367. (interactive)
  5368. (org-agenda-priority 'up))
  5369. (defun org-agenda-priority-down ()
  5370. "Decrease the priority of line at point, also in Org-mode file."
  5371. (interactive)
  5372. (org-agenda-priority 'down))
  5373. (defun org-agenda-priority (&optional force-direction)
  5374. "Set the priority of line at point, also in Org-mode file.
  5375. This changes the line at point, all other lines in the agenda referring to
  5376. the same tree node, and the headline of the tree node in the Org-mode file."
  5377. (interactive)
  5378. (unless org-enable-priority-commands
  5379. (error "Priority commands are disabled"))
  5380. (org-agenda-check-no-diary)
  5381. (let* ((marker (or (get-text-property (point) 'org-marker)
  5382. (org-agenda-error)))
  5383. (hdmarker (get-text-property (point) 'org-hd-marker))
  5384. (buffer (marker-buffer hdmarker))
  5385. (pos (marker-position hdmarker))
  5386. (inhibit-read-only t)
  5387. newhead)
  5388. (org-with-remote-undo buffer
  5389. (with-current-buffer buffer
  5390. (widen)
  5391. (goto-char pos)
  5392. (org-show-context 'agenda)
  5393. (save-excursion
  5394. (and (outline-next-heading)
  5395. (org-flag-heading nil))) ; show the next heading
  5396. (funcall 'org-priority force-direction)
  5397. (end-of-line 1)
  5398. (setq newhead (org-get-heading)))
  5399. (org-agenda-change-all-lines newhead hdmarker)
  5400. (beginning-of-line 1))))
  5401. ;; FIXME: should fix the tags property of the agenda line.
  5402. (defun org-agenda-set-tags (&optional tag onoff)
  5403. "Set tags for the current headline."
  5404. (interactive)
  5405. (org-agenda-check-no-diary)
  5406. (if (and (org-region-active-p) (interactive-p))
  5407. (call-interactively 'org-change-tag-in-region)
  5408. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5409. (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
  5410. (org-agenda-error)))
  5411. (buffer (marker-buffer hdmarker))
  5412. (pos (marker-position hdmarker))
  5413. (inhibit-read-only t)
  5414. newhead)
  5415. (org-with-remote-undo buffer
  5416. (with-current-buffer buffer
  5417. (widen)
  5418. (goto-char pos)
  5419. (save-excursion
  5420. (org-show-context 'agenda))
  5421. (save-excursion
  5422. (and (outline-next-heading)
  5423. (org-flag-heading nil))) ; show the next heading
  5424. (goto-char pos)
  5425. (if tag
  5426. (org-toggle-tag tag onoff)
  5427. (call-interactively 'org-set-tags))
  5428. (end-of-line 1)
  5429. (setq newhead (org-get-heading)))
  5430. (org-agenda-change-all-lines newhead hdmarker)
  5431. (beginning-of-line 1)))))
  5432. (defun org-agenda-toggle-archive-tag ()
  5433. "Toggle the archive tag for the current entry."
  5434. (interactive)
  5435. (org-agenda-check-no-diary)
  5436. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5437. (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
  5438. (org-agenda-error)))
  5439. (buffer (marker-buffer hdmarker))
  5440. (pos (marker-position hdmarker))
  5441. (inhibit-read-only t)
  5442. newhead)
  5443. (org-with-remote-undo buffer
  5444. (with-current-buffer buffer
  5445. (widen)
  5446. (goto-char pos)
  5447. (org-show-context 'agenda)
  5448. (save-excursion
  5449. (and (outline-next-heading)
  5450. (org-flag-heading nil))) ; show the next heading
  5451. (call-interactively 'org-toggle-archive-tag)
  5452. (end-of-line 1)
  5453. (setq newhead (org-get-heading)))
  5454. (org-agenda-change-all-lines newhead hdmarker)
  5455. (beginning-of-line 1))))
  5456. (defun org-agenda-do-date-later (arg)
  5457. (interactive "P")
  5458. (cond
  5459. ((or (equal arg '(16))
  5460. (memq last-command
  5461. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  5462. (setq this-command 'org-agenda-date-later-minutes)
  5463. (org-agenda-date-later-minutes 1))
  5464. ((or (equal arg '(4))
  5465. (memq last-command
  5466. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  5467. (setq this-command 'org-agenda-date-later-hours)
  5468. (org-agenda-date-later-hours 1))
  5469. (t
  5470. (org-agenda-date-later (prefix-numeric-value arg)))))
  5471. (defun org-agenda-do-date-earlier (arg)
  5472. (interactive "P")
  5473. (cond
  5474. ((or (equal arg '(16))
  5475. (memq last-command
  5476. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  5477. (setq this-command 'org-agenda-date-earlier-minutes)
  5478. (org-agenda-date-earlier-minutes 1))
  5479. ((or (equal arg '(4))
  5480. (memq last-command
  5481. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  5482. (setq this-command 'org-agenda-date-earlier-hours)
  5483. (org-agenda-date-earlier-hours 1))
  5484. (t
  5485. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  5486. (defun org-agenda-date-later (arg &optional what)
  5487. "Change the date of this item to one day later."
  5488. (interactive "p")
  5489. (org-agenda-check-type t 'agenda 'timeline)
  5490. (org-agenda-check-no-diary)
  5491. (let* ((marker (or (get-text-property (point) 'org-marker)
  5492. (org-agenda-error)))
  5493. (buffer (marker-buffer marker))
  5494. (pos (marker-position marker)))
  5495. (org-with-remote-undo buffer
  5496. (with-current-buffer buffer
  5497. (widen)
  5498. (goto-char pos)
  5499. (if (not (org-at-timestamp-p))
  5500. (error "Cannot find time stamp"))
  5501. (org-timestamp-change arg (or what 'day)))
  5502. (org-agenda-show-new-time marker org-last-changed-timestamp))
  5503. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  5504. (defun org-agenda-date-earlier (arg &optional what)
  5505. "Change the date of this item to one day earlier."
  5506. (interactive "p")
  5507. (org-agenda-date-later (- arg) what))
  5508. (defun org-agenda-date-later-minutes (arg)
  5509. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  5510. (interactive "p")
  5511. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  5512. (org-agenda-date-later arg 'minute))
  5513. (defun org-agenda-date-earlier-minutes (arg)
  5514. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  5515. (interactive "p")
  5516. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  5517. (org-agenda-date-earlier arg 'minute))
  5518. (defun org-agenda-date-later-hours (arg)
  5519. "Change the time of this item, in hour steps."
  5520. (interactive "p")
  5521. (org-agenda-date-later arg 'hour))
  5522. (defun org-agenda-date-earlier-hours (arg)
  5523. "Change the time of this item, in hour steps."
  5524. (interactive "p")
  5525. (org-agenda-date-earlier arg 'hour))
  5526. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  5527. "Show new date stamp via text properties."
  5528. ;; We use text properties to make this undoable
  5529. (let ((inhibit-read-only t)
  5530. (buffer-invisibility-spec))
  5531. (setq stamp (concat " " prefix " => " stamp))
  5532. (save-excursion
  5533. (goto-char (point-max))
  5534. (while (not (bobp))
  5535. (when (equal marker (get-text-property (point) 'org-marker))
  5536. (org-move-to-column (- (window-width) (length stamp)) t)
  5537. (org-agenda-fix-tags-filter-overlays-at (point))
  5538. (if (featurep 'xemacs)
  5539. ;; Use `duplicable' property to trigger undo recording
  5540. (let ((ex (make-extent nil nil))
  5541. (gl (make-glyph stamp)))
  5542. (set-glyph-face gl 'secondary-selection)
  5543. (set-extent-properties
  5544. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  5545. (insert-extent ex (1- (point)) (point-at-eol)))
  5546. (add-text-properties
  5547. (1- (point)) (point-at-eol)
  5548. (list 'display (org-add-props stamp nil
  5549. 'face 'secondary-selection))))
  5550. (beginning-of-line 1))
  5551. (beginning-of-line 0)))))
  5552. (defun org-agenda-date-prompt (arg)
  5553. "Change the date of this item. Date is prompted for, with default today.
  5554. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  5555. be used to request time specification in the time stamp."
  5556. (interactive "P")
  5557. (org-agenda-check-type t 'agenda 'timeline)
  5558. (org-agenda-check-no-diary)
  5559. (let* ((marker (or (get-text-property (point) 'org-marker)
  5560. (org-agenda-error)))
  5561. (buffer (marker-buffer marker))
  5562. (pos (marker-position marker)))
  5563. (org-with-remote-undo buffer
  5564. (with-current-buffer buffer
  5565. (widen)
  5566. (goto-char pos)
  5567. (if (not (org-at-timestamp-p))
  5568. (error "Cannot find time stamp"))
  5569. (org-time-stamp arg)
  5570. (message "Time stamp changed to %s" org-last-changed-timestamp)))))
  5571. (defun org-agenda-schedule (arg)
  5572. "Schedule the item at point."
  5573. (interactive "P")
  5574. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  5575. (org-agenda-check-no-diary)
  5576. (let* ((marker (or (get-text-property (point) 'org-marker)
  5577. (org-agenda-error)))
  5578. (type (marker-insertion-type marker))
  5579. (buffer (marker-buffer marker))
  5580. (pos (marker-position marker))
  5581. (org-insert-labeled-timestamps-at-point nil)
  5582. ts)
  5583. (set-marker-insertion-type marker t)
  5584. (org-with-remote-undo buffer
  5585. (with-current-buffer buffer
  5586. (widen)
  5587. (goto-char pos)
  5588. (setq ts (org-schedule arg)))
  5589. (org-agenda-show-new-time marker ts "S"))
  5590. (message "Item scheduled for %s" ts)))
  5591. (defun org-agenda-deadline (arg)
  5592. "Schedule the item at point."
  5593. (interactive "P")
  5594. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  5595. (org-agenda-check-no-diary)
  5596. (let* ((marker (or (get-text-property (point) 'org-marker)
  5597. (org-agenda-error)))
  5598. (buffer (marker-buffer marker))
  5599. (pos (marker-position marker))
  5600. (org-insert-labeled-timestamps-at-point nil)
  5601. ts)
  5602. (org-with-remote-undo buffer
  5603. (with-current-buffer buffer
  5604. (widen)
  5605. (goto-char pos)
  5606. (setq ts (org-deadline arg)))
  5607. (org-agenda-show-new-time marker ts "S"))
  5608. (message "Deadline for this item set to %s" ts)))
  5609. (defun org-agenda-action ()
  5610. "Select entry for agenda action, or execute an agenda action.
  5611. This command prompts for another letter. Valid inputs are:
  5612. m Mark the entry at point for an agenda action
  5613. s Schedule the marked entry to the date at the cursor
  5614. d Set the deadline of the marked entry to the date at the cursor
  5615. r Call `org-remember' with cursor date as the default date
  5616. SPC Show marked entry in other window
  5617. TAB Visit marked entry in other window
  5618. The cursor may be at a date in the calendar, or in the Org agenda."
  5619. (interactive)
  5620. (let (ans)
  5621. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  5622. (setq ans (read-char-exclusive))
  5623. (cond
  5624. ((equal ans ?m)
  5625. ;; Mark this entry
  5626. (if (eq major-mode 'org-agenda-mode)
  5627. (let ((m (or (get-text-property (point) 'org-hd-marker)
  5628. (get-text-property (point) 'org-marker))))
  5629. (if m
  5630. (progn
  5631. (move-marker org-agenda-action-marker
  5632. (marker-position m) (marker-buffer m))
  5633. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  5634. (error "Don't know which entry to mark")))
  5635. (error "This command works only in the agenda")))
  5636. ((equal ans ?s)
  5637. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  5638. ((equal ans ?d)
  5639. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  5640. ((equal ans ?r)
  5641. (org-agenda-do-action '(org-remember) t))
  5642. ((equal ans ?\ )
  5643. (let ((cw (selected-window)))
  5644. (org-switch-to-buffer-other-window
  5645. (marker-buffer org-agenda-action-marker))
  5646. (goto-char org-agenda-action-marker)
  5647. (org-show-context 'agenda)
  5648. (select-window cw)))
  5649. ((equal ans ?\C-i)
  5650. (org-switch-to-buffer-other-window
  5651. (marker-buffer org-agenda-action-marker))
  5652. (goto-char org-agenda-action-marker)
  5653. (org-show-context 'agenda))
  5654. (t (error "Invalid agenda action %c" ans)))))
  5655. (defun org-agenda-do-action (form &optional current-buffer)
  5656. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  5657. (let ((org-overriding-default-time (org-get-cursor-date)))
  5658. (if current-buffer
  5659. (eval form)
  5660. (if (not (marker-buffer org-agenda-action-marker))
  5661. (error "No entry has bee selected for agenda action")
  5662. (with-current-buffer (marker-buffer org-agenda-action-marker)
  5663. (save-excursion
  5664. (save-restriction
  5665. (widen)
  5666. (goto-char org-agenda-action-marker)
  5667. (eval form))))))))
  5668. (defun org-agenda-clock-in (&optional arg)
  5669. "Start the clock on the currently selected item."
  5670. (interactive "P")
  5671. (org-agenda-check-no-diary)
  5672. (if (equal arg '(4))
  5673. (org-clock-in arg)
  5674. (let* ((marker (or (get-text-property (point) 'org-marker)
  5675. (org-agenda-error)))
  5676. (hdmarker (or (get-text-property (point) 'org-hd-marker)
  5677. marker))
  5678. (pos (marker-position marker))
  5679. newhead)
  5680. (org-with-remote-undo (marker-buffer marker)
  5681. (with-current-buffer (marker-buffer marker)
  5682. (widen)
  5683. (goto-char pos)
  5684. (org-show-context 'agenda)
  5685. (org-show-entry)
  5686. (org-cycle-hide-drawers 'children)
  5687. (org-clock-in arg)
  5688. (setq newhead (org-get-heading)))
  5689. (org-agenda-change-all-lines newhead hdmarker)))))
  5690. (defun org-agenda-clock-out (&optional arg)
  5691. "Stop the currently running clock."
  5692. (interactive "P")
  5693. (unless (marker-buffer org-clock-marker)
  5694. (error "No running clock"))
  5695. (let ((marker (make-marker)) newhead)
  5696. (org-with-remote-undo (marker-buffer org-clock-marker)
  5697. (with-current-buffer (marker-buffer org-clock-marker)
  5698. (save-excursion
  5699. (save-restriction
  5700. (widen)
  5701. (goto-char org-clock-marker)
  5702. (org-back-to-heading t)
  5703. (move-marker marker (point))
  5704. (org-clock-out)
  5705. (setq newhead (org-get-heading))))))
  5706. (org-agenda-change-all-lines newhead marker)
  5707. (move-marker marker nil)))
  5708. (defun org-agenda-clock-cancel (&optional arg)
  5709. "Cancel the currently running clock."
  5710. (interactive "P")
  5711. (unless (marker-buffer org-clock-marker)
  5712. (error "No running clock"))
  5713. (org-with-remote-undo (marker-buffer org-clock-marker)
  5714. (org-clock-cancel)))
  5715. (defun org-agenda-diary-entry ()
  5716. "Make a diary entry, like the `i' command from the calendar.
  5717. All the standard commands work: block, weekly etc."
  5718. (interactive)
  5719. (org-agenda-check-type t 'agenda 'timeline)
  5720. (require 'diary-lib)
  5721. (let* ((char (progn
  5722. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  5723. (read-char-exclusive)))
  5724. (cmd (cdr (assoc char
  5725. '((?d . insert-diary-entry)
  5726. (?w . insert-weekly-diary-entry)
  5727. (?m . insert-monthly-diary-entry)
  5728. (?y . insert-yearly-diary-entry)
  5729. (?a . insert-anniversary-diary-entry)
  5730. (?b . insert-block-diary-entry)
  5731. (?c . insert-cyclic-diary-entry)))))
  5732. (oldf (symbol-function 'calendar-cursor-to-date))
  5733. ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  5734. (point (point))
  5735. (mark (or (mark t) (point))))
  5736. (unless cmd
  5737. (error "No command associated with <%c>" char))
  5738. (unless (and (get-text-property point 'day)
  5739. (or (not (equal ?b char))
  5740. (get-text-property mark 'day)))
  5741. (error "Don't know which date to use for diary entry"))
  5742. ;; We implement this by hacking the `calendar-cursor-to-date' function
  5743. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  5744. (let ((calendar-mark-ring
  5745. (list (calendar-gregorian-from-absolute
  5746. (or (get-text-property mark 'day)
  5747. (get-text-property point 'day))))))
  5748. (unwind-protect
  5749. (progn
  5750. (fset 'calendar-cursor-to-date
  5751. (lambda (&optional error dummy)
  5752. (calendar-gregorian-from-absolute
  5753. (get-text-property point 'day))))
  5754. (call-interactively cmd))
  5755. (fset 'calendar-cursor-to-date oldf)))))
  5756. (defun org-agenda-execute-calendar-command (cmd)
  5757. "Execute a calendar command from the agenda, with the date associated to
  5758. the cursor position."
  5759. (org-agenda-check-type t 'agenda 'timeline)
  5760. (require 'diary-lib)
  5761. (unless (get-text-property (point) 'day)
  5762. (error "Don't know which date to use for calendar command"))
  5763. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  5764. (point (point))
  5765. (date (calendar-gregorian-from-absolute
  5766. (get-text-property point 'day)))
  5767. ;; the following 2 vars are needed in the calendar
  5768. (displayed-month (car date))
  5769. (displayed-year (nth 2 date)))
  5770. (unwind-protect
  5771. (progn
  5772. (fset 'calendar-cursor-to-date
  5773. (lambda (&optional error dummy)
  5774. (calendar-gregorian-from-absolute
  5775. (get-text-property point 'day))))
  5776. (call-interactively cmd))
  5777. (fset 'calendar-cursor-to-date oldf))))
  5778. (defun org-agenda-phases-of-moon ()
  5779. "Display the phases of the moon for the 3 months around the cursor date."
  5780. (interactive)
  5781. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  5782. (defun org-agenda-holidays ()
  5783. "Display the holidays for the 3 months around the cursor date."
  5784. (interactive)
  5785. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  5786. (defvar calendar-longitude)
  5787. (defvar calendar-latitude)
  5788. (defvar calendar-location-name)
  5789. (defun org-agenda-sunrise-sunset (arg)
  5790. "Display sunrise and sunset for the cursor date.
  5791. Latitude and longitude can be specified with the variables
  5792. `calendar-latitude' and `calendar-longitude'. When called with prefix
  5793. argument, latitude and longitude will be prompted for."
  5794. (interactive "P")
  5795. (require 'solar)
  5796. (let ((calendar-longitude (if arg nil calendar-longitude))
  5797. (calendar-latitude (if arg nil calendar-latitude))
  5798. (calendar-location-name
  5799. (if arg "the given coordinates" calendar-location-name)))
  5800. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  5801. (defun org-agenda-goto-calendar ()
  5802. "Open the Emacs calendar with the date at the cursor."
  5803. (interactive)
  5804. (org-agenda-check-type t 'agenda 'timeline)
  5805. (let* ((day (or (get-text-property (point) 'day)
  5806. (error "Don't know which date to open in calendar")))
  5807. (date (calendar-gregorian-from-absolute day))
  5808. (calendar-move-hook nil)
  5809. (calendar-view-holidays-initially-flag nil)
  5810. (calendar-view-diary-initially-flag nil)
  5811. (view-calendar-holidays-initially nil)
  5812. (view-diary-entries-initially nil))
  5813. (calendar)
  5814. (calendar-goto-date date)))
  5815. ;;;###autoload
  5816. (defun org-calendar-goto-agenda ()
  5817. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  5818. This is a command that has to be installed in `calendar-mode-map'."
  5819. (interactive)
  5820. (org-agenda-list nil (calendar-absolute-from-gregorian
  5821. (calendar-cursor-to-date))
  5822. nil))
  5823. (defun org-agenda-convert-date ()
  5824. (interactive)
  5825. (org-agenda-check-type t 'agenda 'timeline)
  5826. (let ((day (get-text-property (point) 'day))
  5827. date s)
  5828. (unless day
  5829. (error "Don't know which date to convert"))
  5830. (setq date (calendar-gregorian-from-absolute day))
  5831. (setq s (concat
  5832. "Gregorian: " (calendar-date-string date) "\n"
  5833. "ISO: " (calendar-iso-date-string date) "\n"
  5834. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  5835. "Julian: " (calendar-julian-date-string date) "\n"
  5836. "Astron. JD: " (calendar-astro-date-string date)
  5837. " (Julian date number at noon UTC)\n"
  5838. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  5839. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  5840. "French: " (calendar-french-date-string date) "\n"
  5841. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  5842. "Mayan: " (calendar-mayan-date-string date) "\n"
  5843. "Coptic: " (calendar-coptic-date-string date) "\n"
  5844. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  5845. "Persian: " (calendar-persian-date-string date) "\n"
  5846. "Chinese: " (calendar-chinese-date-string date) "\n"))
  5847. (with-output-to-temp-buffer "*Dates*"
  5848. (princ s))
  5849. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  5850. ;;; Bulk commands
  5851. (defvar org-agenda-bulk-marked-entries nil
  5852. "List of markers that refer to marked entries in the agenda.")
  5853. (defun org-agenda-bulk-mark ()
  5854. "Mark the entry at point for future bulk action."
  5855. (interactive)
  5856. (org-agenda-check-no-diary)
  5857. (let* ((m (get-text-property (point) 'org-hd-marker))
  5858. ov)
  5859. (unless (eq (get-char-property (point-at-bol) 'type)
  5860. 'org-marked-entry-overlay)
  5861. (unless m (error "Nothing to mark at point"))
  5862. (push m org-agenda-bulk-marked-entries)
  5863. (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  5864. (org-overlay-display ov ">>"
  5865. (org-get-todo-face "TODO")
  5866. 'evaporate)
  5867. (org-overlay-put ov 'type 'org-marked-entry-overlay))
  5868. (beginning-of-line 2)
  5869. (message "%d entries marked for bulk action"
  5870. (length org-agenda-bulk-marked-entries))))
  5871. (defun org-agenda-bulk-unmark ()
  5872. "Unmark the entry at point for future bulk action."
  5873. (interactive)
  5874. (when (eq (get-char-property (point-at-bol) 'type)
  5875. 'org-marked-entry-overlay)
  5876. (org-agenda-bulk-remove-overlays
  5877. (point-at-bol) (+ 2 (point-at-bol)))
  5878. (setq org-agenda-bulk-marked-entries
  5879. (delete (get-text-property (point-at-bol) 'org-hd-marker)
  5880. org-agenda-bulk-marked-entries)))
  5881. (beginning-of-line 2)
  5882. (message "%d entries marked for bulk action"
  5883. (length org-agenda-bulk-marked-entries)))
  5884. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  5885. "Remove the mark overlays between BEG and END in the agenda buffer.
  5886. BEG and END default to the buffer limits.
  5887. This only removes the overlays, it does not remove the markers
  5888. from the list in `org-agenda-bulk-marked-entries'."
  5889. (interactive)
  5890. (mapc (lambda (ov)
  5891. (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
  5892. (org-delete-overlay ov)))
  5893. (org-overlays-in (or beg (point-min)) (or end (point-max)))))
  5894. (defun org-agenda-bulk-remove-all-marks ()
  5895. "Remove all marks in the agenda buffer.
  5896. This will remove the markers, and the overlays."
  5897. (interactive)
  5898. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  5899. (setq org-agenda-bulk-marked-entries nil)
  5900. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  5901. (defun org-agenda-bulk-action ()
  5902. "Execute an remote-editing action on all marked entries."
  5903. (interactive)
  5904. (unless org-agenda-bulk-marked-entries
  5905. (error "No entries are marked"))
  5906. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  5907. (let* ((action (read-char-exclusive))
  5908. (entries (reverse org-agenda-bulk-marked-entries))
  5909. cmd rfloc state e tag (cnt 0))
  5910. (cond
  5911. ((equal action ?$)
  5912. (setq cmd '(org-agenda-archive)))
  5913. ((equal action ?A)
  5914. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  5915. ((member action '(?r ?w))
  5916. (setq rfloc (org-refile-get-location
  5917. "Refile to: "
  5918. (marker-buffer (car org-agenda-bulk-marked-entries))
  5919. org-refile-allow-creating-parent-nodes))
  5920. (setcar (nthcdr 3 rfloc)
  5921. (move-marker (make-marker) (nth 3 rfloc)
  5922. (or (get-file-buffer (nth 1 rfloc))
  5923. (find-buffer-visiting (nth 1 rfloc))
  5924. (error "This should not happen"))))
  5925. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
  5926. ((equal action ?t)
  5927. (setq state (org-ido-completing-read
  5928. "Todo state: "
  5929. (with-current-buffer (marker-buffer (car entries))
  5930. (mapcar 'list org-todo-keywords-1))))
  5931. (setq cmd `(let ((org-inhibit-blocking t)
  5932. (org-inhibit-logging 'note))
  5933. (org-agenda-todo ,state))))
  5934. ((memq action '(?- ?+))
  5935. (setq tag (org-ido-completing-read
  5936. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  5937. (with-current-buffer (marker-buffer (car entries))
  5938. (delq nil
  5939. (mapcar (lambda (x)
  5940. (if (stringp (car x)) x)) org-tag-alist)))))
  5941. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  5942. ((memq action '(?s ?d))
  5943. (let* ((date (org-read-date
  5944. nil nil nil
  5945. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
  5946. (ans org-read-date-final-answer)
  5947. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  5948. (setq cmd `(let* ((bound (fboundp 'read-string))
  5949. (old (and bound (symbol-function 'read-string))))
  5950. (unwind-protect
  5951. (progn
  5952. (fset 'read-string (lambda (&rest ignore) ,ans))
  5953. (call-interactively ',c1))
  5954. (if bound
  5955. (fset 'read-string old)
  5956. (fmakunbound 'read-string)))))))
  5957. (t (error "Invalid bulk action")))
  5958. ;; Now loop over all markers and apply cmd
  5959. (while (setq e (pop entries))
  5960. (goto-char
  5961. (or (text-property-any (point-min) (point-max) 'org-hd-marker e)
  5962. (error "Cannot find entry for marker %s" e)))
  5963. (eval cmd)
  5964. (setq org-agenda-bulk-marked-entries (delete e org-agenda-bulk-marked-entries))
  5965. (setq cnt (1+ cnt)))
  5966. (setq org-agenda-bulk-marked-entries nil)
  5967. (org-agenda-bulk-remove-all-marks)
  5968. (message "Acted on %d entries" cnt)))
  5969. ;;; Appointment reminders
  5970. (defvar appt-time-msg-list)
  5971. ;;;###autoload
  5972. (defun org-agenda-to-appt (&optional refresh filter)
  5973. "Activate appointments found in `org-agenda-files'.
  5974. With a \\[universal-argument] prefix, refresh the list of
  5975. appointments.
  5976. If FILTER is t, interactively prompt the user for a regular
  5977. expression, and filter out entries that don't match it.
  5978. If FILTER is a string, use this string as a regular expression
  5979. for filtering entries out.
  5980. FILTER can also be an alist with the car of each cell being
  5981. either 'headline or 'category. For example:
  5982. '((headline \"IMPORTANT\")
  5983. (category \"Work\"))
  5984. will only add headlines containing IMPORTANT or headlines
  5985. belonging to the \"Work\" category."
  5986. (interactive "P")
  5987. (require 'calendar)
  5988. (if refresh (setq appt-time-msg-list nil))
  5989. (if (eq filter t)
  5990. (setq filter (read-from-minibuffer "Regexp filter: ")))
  5991. (let* ((cnt 0) ; count added events
  5992. (org-agenda-new-buffers nil)
  5993. (org-deadline-warning-days 0)
  5994. (today (org-date-to-gregorian
  5995. (time-to-days (current-time))))
  5996. (org-agenda-restrict nil)
  5997. (files (org-agenda-files 'unrestricted)) entries file)
  5998. ;; Get all entries which may contain an appt
  5999. (org-prepare-agenda-buffers files)
  6000. (while (setq file (pop files))
  6001. (setq entries
  6002. (append entries
  6003. (org-agenda-get-day-entries
  6004. file today :timestamp :scheduled :deadline))))
  6005. (setq entries (delq nil entries))
  6006. ;; Map thru entries and find if we should filter them out
  6007. (mapc
  6008. (lambda(x)
  6009. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  6010. (cat (get-text-property 1 'org-category x))
  6011. (tod (get-text-property 1 'time-of-day x))
  6012. (ok (or (null filter)
  6013. (and (stringp filter) (string-match filter evt))
  6014. (and (listp filter)
  6015. (or (string-match
  6016. (cadr (assoc 'category filter)) cat)
  6017. (string-match
  6018. (cadr (assoc 'headline filter)) evt))))))
  6019. ;; FIXME: Shall we remove text-properties for the appt text?
  6020. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  6021. (when (and ok tod)
  6022. (setq tod (concat "00" (number-to-string tod))
  6023. tod (when (string-match
  6024. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  6025. (concat (match-string 1 tod) ":"
  6026. (match-string 2 tod))))
  6027. (appt-add tod evt)
  6028. (setq cnt (1+ cnt))))) entries)
  6029. (org-release-buffers org-agenda-new-buffers)
  6030. (if (eq cnt 0)
  6031. (message "No event to add")
  6032. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  6033. (defun org-agenda-todayp (date)
  6034. "Does DATE mean today, when considering `org-extend-today-until'?"
  6035. (let (today h)
  6036. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  6037. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  6038. (setq h (nth 2 (decode-time (current-time))))
  6039. (or (and (>= h org-extend-today-until)
  6040. (= date today))
  6041. (and (< h org-extend-today-until)
  6042. (= date (1- today))))))
  6043. (provide 'org-agenda)
  6044. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  6045. ;;; org-agenda.el ends here