org-agenda.el 277 KB

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