org-agenda.el 275 KB

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