org-agenda.el 285 KB

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