org-agenda.el 342 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. ;; Defined somewhere in this file, but used before definition.
  80. (defvar org-agenda-buffer-name)
  81. (defvar org-agenda-overriding-header)
  82. (defvar org-agenda-title-append nil)
  83. (defvar entry)
  84. (defvar date)
  85. (defvar org-agenda-undo-list)
  86. (defvar org-agenda-pending-undo-list)
  87. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  88. (defcustom org-agenda-confirm-kill 1
  89. "When set, remote killing from the agenda buffer needs confirmation.
  90. When t, a confirmation is always needed. When a number N, confirmation is
  91. only needed when the text to be killed contains more than N non-white lines."
  92. :group 'org-agenda
  93. :type '(choice
  94. (const :tag "Never" nil)
  95. (const :tag "Always" t)
  96. (integer :tag "When more than N lines")))
  97. (defcustom org-agenda-compact-blocks nil
  98. "Non-nil means make the block agenda more compact.
  99. This is done globally by leaving out lines like the agenda span
  100. name and week number or the separator lines."
  101. :group 'org-agenda
  102. :type 'boolean)
  103. (defcustom org-agenda-block-separator ?=
  104. "The separator between blocks in the agenda.
  105. If this is a string, it will be used as the separator, with a newline added.
  106. If it is a character, it will be repeated to fill the window width.
  107. If nil the separator is disabled. In `org-agenda-custom-commands' this
  108. addresses the separator between the current and the previous block."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Disabled" nil)
  112. (character)
  113. (string)))
  114. (defgroup org-agenda-export nil
  115. "Options concerning exporting agenda views in Org-mode."
  116. :tag "Org Agenda Export"
  117. :group 'org-agenda)
  118. (defcustom org-agenda-with-colors t
  119. "Non-nil means use colors in agenda views."
  120. :group 'org-agenda-export
  121. :type 'boolean)
  122. (defcustom org-agenda-exporter-settings nil
  123. "Alist of variable/value pairs that should be active during agenda export.
  124. This is a good place to set options for ps-print and for htmlize.
  125. Note that the way this is implemented, the values will be evaluated
  126. before assigned to the variables. So make sure to quote values you do
  127. *not* want evaluated, for example
  128. (setq org-agenda-exporter-settings
  129. '((ps-print-color-p 'black-white)))"
  130. :group 'org-agenda-export
  131. :type '(repeat
  132. (list
  133. (variable)
  134. (sexp :tag "Value"))))
  135. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  136. "Hook run in temporary buffer before writing it to an export file.
  137. A useful function is `org-agenda-add-entry-text'."
  138. :group 'org-agenda-export
  139. :type 'hook
  140. :options '(org-agenda-add-entry-text))
  141. (defcustom org-agenda-add-entry-text-maxlines 0
  142. "Maximum number of entry text lines to be added to agenda.
  143. This is only relevant when `org-agenda-add-entry-text' is part of
  144. `org-agenda-before-write-hook', which it is by default.
  145. When this is 0, nothing will happen. When it is greater than 0, it
  146. specifies the maximum number of lines that will be added for each entry
  147. that is listed in the agenda view.
  148. Note that this variable is not used during display, only when exporting
  149. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  150. and `org-agenda-entry-text-maxlines'."
  151. :group 'org-agenda
  152. :type 'integer)
  153. (defcustom org-agenda-add-entry-text-descriptive-links t
  154. "Non-nil means export org-links as descriptive links in agenda added text.
  155. This variable applies to the text added to the agenda when
  156. `org-agenda-add-entry-text-maxlines' is larger than 0.
  157. When this variable nil, the URL will (also) be shown."
  158. :group 'org-agenda
  159. :type 'boolean)
  160. (defcustom org-agenda-export-html-style ""
  161. "The style specification for exported HTML Agenda files.
  162. If this variable contains a string, it will replace the default <style>
  163. section as produced by `htmlize'.
  164. Since there are different ways of setting style information, this variable
  165. needs to contain the full HTML structure to provide a style, including the
  166. surrounding HTML tags. The style specifications should include definitions
  167. the fonts used by the agenda, here is an example:
  168. <style type=\"text/css\">
  169. p { font-weight: normal; color: gray; }
  170. .org-agenda-structure {
  171. font-size: 110%;
  172. color: #003399;
  173. font-weight: 600;
  174. }
  175. .org-todo {
  176. color: #cc6666;
  177. font-weight: bold;
  178. }
  179. .org-agenda-done {
  180. color: #339933;
  181. }
  182. .org-done {
  183. color: #339933;
  184. }
  185. .title { text-align: center; }
  186. .todo, .deadline { color: red; }
  187. .done { color: green; }
  188. </style>
  189. or, if you want to keep the style in a file,
  190. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  191. As the value of this option simply gets inserted into the HTML <head> header,
  192. you can \"misuse\" it to also add other text to the header. However,
  193. <style>...</style> is required, if not present the variable will be ignored."
  194. :group 'org-agenda-export
  195. :group 'org-export-html
  196. :type 'string)
  197. (defcustom org-agenda-persistent-filter nil
  198. "When set, keep filters from one agenda view to the next."
  199. :group 'org-agenda
  200. :type 'boolean)
  201. (defgroup org-agenda-custom-commands nil
  202. "Options concerning agenda views in Org-mode."
  203. :tag "Org Agenda Custom Commands"
  204. :group 'org-agenda)
  205. (defconst org-sorting-choice
  206. '(choice
  207. (const time-up) (const time-down)
  208. (const category-keep) (const category-up) (const category-down)
  209. (const tag-down) (const tag-up)
  210. (const priority-up) (const priority-down)
  211. (const todo-state-up) (const todo-state-down)
  212. (const effort-up) (const effort-down)
  213. (const habit-up) (const habit-down)
  214. (const alpha-up) (const alpha-down)
  215. (const user-defined-up) (const user-defined-down))
  216. "Sorting choices.")
  217. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  218. ;; the new variable `org-agenda-tag-filter-preset'.
  219. (if (fboundp 'defvaralias)
  220. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  221. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  222. (defconst org-agenda-custom-commands-local-options
  223. `(repeat :tag "Local settings for this command. Remember to quote values"
  224. (choice :tag "Setting"
  225. (list :tag "Heading for this block"
  226. (const org-agenda-overriding-header)
  227. (string :tag "Headline"))
  228. (list :tag "Files to be searched"
  229. (const org-agenda-files)
  230. (list
  231. (const :format "" quote)
  232. (repeat (file))))
  233. (list :tag "Sorting strategy"
  234. (const org-agenda-sorting-strategy)
  235. (list
  236. (const :format "" quote)
  237. (repeat
  238. ,org-sorting-choice)))
  239. (list :tag "Prefix format"
  240. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  241. (string))
  242. (list :tag "Number of days in agenda"
  243. (const org-agenda-span)
  244. (choice (const :tag "Day" 'day)
  245. (const :tag "Week" 'week)
  246. (const :tag "Month" 'month)
  247. (const :tag "Year" 'year)
  248. (integer :tag "Custom")))
  249. (list :tag "Fixed starting date"
  250. (const org-agenda-start-day)
  251. (string :value "2007-11-01"))
  252. (list :tag "Start on day of week"
  253. (const org-agenda-start-on-weekday)
  254. (choice :value 1
  255. (const :tag "Today" nil)
  256. (integer :tag "Weekday No.")))
  257. (list :tag "Include data from diary"
  258. (const org-agenda-include-diary)
  259. (boolean))
  260. (list :tag "Deadline Warning days"
  261. (const org-deadline-warning-days)
  262. (integer :value 1))
  263. (list :tag "Category filter preset"
  264. (const org-agenda-category-filter-preset)
  265. (list
  266. (const :format "" quote)
  267. (repeat
  268. (string :tag "+category or -category"))))
  269. (list :tag "Tags filter preset"
  270. (const org-agenda-tag-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+tag or -tag"))))
  275. (list :tag "Set daily/weekly entry types"
  276. (const org-agenda-entry-types)
  277. (list
  278. (const :format "" quote)
  279. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  280. (const :deadline)
  281. (const :scheduled)
  282. (const :timestamp)
  283. (const :sexp))))
  284. (list :tag "Standard skipping condition"
  285. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  286. (const org-agenda-skip-function)
  287. (list
  288. (const :format "" quote)
  289. (list
  290. (choice
  291. :tag "Skipping range"
  292. (const :tag "Skip entry" org-agenda-skip-entry-if)
  293. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  294. (repeat :inline t :tag "Conditions for skipping"
  295. (choice
  296. :tag "Condition type"
  297. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  298. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  299. (list :tag "TODO state is" :inline t
  300. (const 'todo)
  301. (choice
  302. (const :tag "any not-done state" 'todo)
  303. (const :tag "any done state" 'done)
  304. (const :tag "any state" 'any)
  305. (list :tag "Keyword list"
  306. (const :format "" quote)
  307. (repeat (string :tag "Keyword")))))
  308. (list :tag "TODO state is not" :inline t
  309. (const 'nottodo)
  310. (choice
  311. (const :tag "any not-done state" 'todo)
  312. (const :tag "any done state" 'done)
  313. (const :tag "any state" 'any)
  314. (list :tag "Keyword list"
  315. (const :format "" quote)
  316. (repeat (string :tag "Keyword")))))
  317. (const :tag "scheduled" 'scheduled)
  318. (const :tag "not scheduled" 'notscheduled)
  319. (const :tag "deadline" 'deadline)
  320. (const :tag "no deadline" 'notdeadline)
  321. (const :tag "timestamp" 'timestamp)
  322. (const :tag "no timestamp" 'nottimestamp))))))
  323. (list :tag "Non-standard skipping condition"
  324. :value (org-agenda-skip-function)
  325. (const org-agenda-skip-function)
  326. (sexp :tag "Function or form (quoted!)"))
  327. (list :tag "Any variable"
  328. (variable :tag "Variable")
  329. (sexp :tag "Value (sexp)"))))
  330. "Selection of examples for agenda command settings.
  331. This will be spliced into the custom type of
  332. `org-agenda-custom-commands'.")
  333. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  334. ((agenda "") (alltodo))))
  335. "Custom commands for the agenda.
  336. These commands will be offered on the splash screen displayed by the
  337. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  338. (key desc type match settings files)
  339. key The key (one or more characters as a string) to be associated
  340. with the command.
  341. desc A description of the command, when omitted or nil, a default
  342. description is built using MATCH.
  343. type The command type, any of the following symbols:
  344. agenda The daily/weekly agenda.
  345. todo Entries with a specific TODO keyword, in all agenda files.
  346. search Entries containing search words entry or headline.
  347. tags Tags/Property/TODO match in all agenda files.
  348. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  349. todo-tree Sparse tree of specific TODO keyword in *current* file.
  350. tags-tree Sparse tree with all tags matches in *current* file.
  351. occur-tree Occur sparse tree for *current* file.
  352. ... A user-defined function.
  353. match What to search for:
  354. - a single keyword for TODO keyword searches
  355. - a tags match expression for tags searches
  356. - a word search expression for text searches.
  357. - a regular expression for occur searches
  358. For all other commands, this should be the empty string.
  359. settings A list of option settings, similar to that in a let form, so like
  360. this: ((opt1 val1) (opt2 val2) ...). The values will be
  361. evaluated at the moment of execution, so quote them when needed.
  362. files A list of files file to write the produced agenda buffer to
  363. with the command `org-store-agenda-views'.
  364. If a file name ends in \".html\", an HTML version of the buffer
  365. is written out. If it ends in \".ps\", a postscript version is
  366. produced. Otherwise, only the plain text is written to the file.
  367. You can also define a set of commands, to create a composite agenda buffer.
  368. In this case, an entry looks like this:
  369. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  370. where
  371. desc A description string to be displayed in the dispatcher menu.
  372. cmd An agenda command, similar to the above. However, tree commands
  373. are not allowed, but instead you can get agenda and global todo list.
  374. So valid commands for a set are:
  375. (agenda \"\" settings)
  376. (alltodo \"\" settings)
  377. (stuck \"\" settings)
  378. (todo \"match\" settings files)
  379. (search \"match\" settings files)
  380. (tags \"match\" settings files)
  381. (tags-todo \"match\" settings files)
  382. Each command can carry a list of options, and another set of options can be
  383. given for the whole set of commands. Individual command options take
  384. precedence over the general options.
  385. When using several characters as key to a command, the first characters
  386. are prefix commands. For the dispatcher to display useful information, you
  387. should provide a description for the prefix, like
  388. (setq org-agenda-custom-commands
  389. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  390. (\"hl\" tags \"+HOME+Lisa\")
  391. (\"hp\" tags \"+HOME+Peter\")
  392. (\"hk\" tags \"+HOME+Kim\")))"
  393. :group 'org-agenda-custom-commands
  394. :type `(repeat
  395. (choice :value ("x" "Describe command here" tags "" nil)
  396. (list :tag "Single command"
  397. (string :tag "Access Key(s) ")
  398. (option (string :tag "Description"))
  399. (choice
  400. (const :tag "Agenda" agenda)
  401. (const :tag "TODO list" alltodo)
  402. (const :tag "Search words" search)
  403. (const :tag "Stuck projects" stuck)
  404. (const :tag "Tags/Property match (all agenda files)" tags)
  405. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  406. (const :tag "TODO keyword search (all agenda files)" todo)
  407. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  408. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  409. (const :tag "Occur tree (current buffer)" occur-tree)
  410. (sexp :tag "Other, user-defined function"))
  411. (string :tag "Match (only for some commands)")
  412. ,org-agenda-custom-commands-local-options
  413. (option (repeat :tag "Export" (file :tag "Export to"))))
  414. (list :tag "Command series, all agenda files"
  415. (string :tag "Access Key(s)")
  416. (string :tag "Description ")
  417. (repeat :tag "Component"
  418. (choice
  419. (list :tag "Agenda"
  420. (const :format "" agenda)
  421. (const :tag "" :format "" "")
  422. ,org-agenda-custom-commands-local-options)
  423. (list :tag "TODO list (all keywords)"
  424. (const :format "" alltodo)
  425. (const :tag "" :format "" "")
  426. ,org-agenda-custom-commands-local-options)
  427. (list :tag "Search words"
  428. (const :format "" search)
  429. (string :tag "Match")
  430. ,org-agenda-custom-commands-local-options)
  431. (list :tag "Stuck projects"
  432. (const :format "" stuck)
  433. (const :tag "" :format "" "")
  434. ,org-agenda-custom-commands-local-options)
  435. (list :tag "Tags search"
  436. (const :format "" tags)
  437. (string :tag "Match")
  438. ,org-agenda-custom-commands-local-options)
  439. (list :tag "Tags search, TODO entries only"
  440. (const :format "" tags-todo)
  441. (string :tag "Match")
  442. ,org-agenda-custom-commands-local-options)
  443. (list :tag "TODO keyword search"
  444. (const :format "" todo)
  445. (string :tag "Match")
  446. ,org-agenda-custom-commands-local-options)
  447. (list :tag "Other, user-defined function"
  448. (symbol :tag "function")
  449. (string :tag "Match")
  450. ,org-agenda-custom-commands-local-options)))
  451. (repeat :tag "Settings for entire command set"
  452. (list (variable :tag "Any variable")
  453. (sexp :tag "Value")))
  454. (option (repeat :tag "Export" (file :tag "Export to"))))
  455. (cons :tag "Prefix key documentation"
  456. (string :tag "Access Key(s)")
  457. (string :tag "Description ")))))
  458. (defcustom org-agenda-query-register ?o
  459. "The register holding the current query string.
  460. The purpose of this is that if you construct a query string interactively,
  461. you can then use it to define a custom command."
  462. :group 'org-agenda-custom-commands
  463. :type 'character)
  464. (defcustom org-stuck-projects
  465. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  466. "How to identify stuck projects.
  467. This is a list of four items:
  468. 1. A tags/todo/property matcher string that is used to identify a project.
  469. See the manual for a description of tag and property searches.
  470. The entire tree below a headline matched by this is considered one project.
  471. 2. A list of TODO keywords identifying non-stuck projects.
  472. If the project subtree contains any headline with one of these todo
  473. keywords, the project is considered to be not stuck. If you specify
  474. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  475. 3. A list of tags identifying non-stuck projects.
  476. If the project subtree contains any headline with one of these tags,
  477. the project is considered to be not stuck. If you specify \"*\" as
  478. a tag, any tag will mark the project unstuck. Note that this is about
  479. the explicit presence of a tag somewhere in the subtree, inherited
  480. tags to not count here. If inherited tags make a project not stuck,
  481. use \"-TAG\" in the tags part of the matcher under (1.) above.
  482. 4. An arbitrary regular expression matching non-stuck projects.
  483. If the project turns out to be not stuck, search continues also in the
  484. subtree to see if any of the subtasks have project status.
  485. See also the variable `org-tags-match-list-sublevels' which applies
  486. to projects matched by this search as well.
  487. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  488. or `C-c a #' to produce the list."
  489. :group 'org-agenda-custom-commands
  490. :type '(list
  491. (string :tag "Tags/TODO match to identify a project")
  492. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  493. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  494. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  495. (defcustom org-agenda-filter-effort-default-operator "<"
  496. "The default operator for effort estimate filtering.
  497. If you select an effort estimate limit without first pressing an operator,
  498. this one will be used."
  499. :group 'org-agenda-custom-commands
  500. :type '(choice (const :tag "less or equal" "<")
  501. (const :tag "greater or equal"">")
  502. (const :tag "equal" "=")))
  503. (defgroup org-agenda-skip nil
  504. "Options concerning skipping parts of agenda files."
  505. :tag "Org Agenda Skip"
  506. :group 'org-agenda)
  507. (defcustom org-agenda-skip-function-global nil
  508. "Function to be called at each match during agenda construction.
  509. If this function returns nil, the current match should not be skipped.
  510. If the function decided to skip an agenda match, is must return the
  511. buffer position from which the search should be continued.
  512. This may also be a Lisp form, which will be evaluated.
  513. This variable will be applied to every agenda match, including
  514. tags/property searches and TODO lists. So try to make the test function
  515. do its checking as efficiently as possible. To implement a skipping
  516. condition just for specific agenda commands, use the variable
  517. `org-agenda-skip-function' which can be set in the options section
  518. of custom agenda commands."
  519. :group 'org-agenda-skip
  520. :type 'sexp)
  521. (defgroup org-agenda-daily/weekly nil
  522. "Options concerning the daily/weekly agenda."
  523. :tag "Org Agenda Daily/Weekly"
  524. :group 'org-agenda)
  525. (defgroup org-agenda-todo-list nil
  526. "Options concerning the global todo list agenda view."
  527. :tag "Org Agenda Todo List"
  528. :group 'org-agenda)
  529. (defgroup org-agenda-match-view nil
  530. "Options concerning the general tags/property/todo match agenda view."
  531. :tag "Org Agenda Match View"
  532. :group 'org-agenda)
  533. (defgroup org-agenda-search-view nil
  534. "Options concerning the general tags/property/todo match agenda view."
  535. :tag "Org Agenda Match View"
  536. :group 'org-agenda)
  537. (defvar org-agenda-archives-mode nil
  538. "Non-nil means the agenda will include archived items.
  539. If this is the symbol `trees', trees in the selected agenda scope
  540. that are marked with the ARCHIVE tag will be included anyway. When this is
  541. t, also all archive files associated with the current selection of agenda
  542. files will be included.")
  543. (defcustom org-agenda-skip-comment-trees t
  544. "Non-nil means skip trees that start with the COMMENT keyword.
  545. When nil, these trees are also scanned by agenda commands."
  546. :group 'org-agenda-skip
  547. :type 'boolean)
  548. (defcustom org-agenda-todo-list-sublevels t
  549. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  550. When nil, the sublevels of a TODO entry are not checked, resulting in
  551. potentially much shorter TODO lists."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type 'boolean)
  555. (defcustom org-agenda-todo-ignore-with-date nil
  556. "Non-nil means don't show entries with a date in the global todo list.
  557. You can use this if you prefer to mark mere appointments with a TODO keyword,
  558. but don't want them to show up in the TODO list.
  559. When this is set, it also covers deadlines and scheduled items, the settings
  560. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  561. will be ignored.
  562. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  563. :group 'org-agenda-skip
  564. :group 'org-agenda-todo-list
  565. :type 'boolean)
  566. (defcustom org-agenda-todo-ignore-timestamp nil
  567. "Non-nil means don't show entries with a timestamp.
  568. This applies when creating the global todo list.
  569. Valid values are:
  570. past Don't show entries for today or in the past.
  571. future Don't show entries with a timestamp in the future.
  572. The idea behind this is that if it has a future
  573. timestamp, you don't want to think about it until the
  574. date.
  575. all Don't show any entries with a timestamp in the global todo list.
  576. The idea behind this is that by setting a timestamp, you
  577. have already \"taken care\" of this item.
  578. This variable can also have an integer as a value. If positive (N),
  579. todos with a timestamp N or more days in the future will be ignored. If
  580. negative (-N), todos with a timestamp N or more days in the past will be
  581. ignored. If 0, todos with a timestamp either today or in the future will
  582. be ignored. For example, a value of -1 will exclude todos with a
  583. timestamp in the past (yesterday or earlier), while a value of 7 will
  584. exclude todos with a timestamp a week or more in the future.
  585. See also `org-agenda-todo-ignore-with-date'.
  586. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  587. to make his option also apply to the tags-todo list."
  588. :group 'org-agenda-skip
  589. :group 'org-agenda-todo-list
  590. :version "24.1"
  591. :type '(choice
  592. (const :tag "Ignore future timestamp todos" future)
  593. (const :tag "Ignore past or present timestamp todos" past)
  594. (const :tag "Ignore all timestamp todos" all)
  595. (const :tag "Show timestamp todos" nil)
  596. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  597. (defcustom org-agenda-todo-ignore-scheduled nil
  598. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  599. This applies when creating the global todo list.
  600. Valid values are:
  601. past Don't show entries scheduled today or in the past.
  602. future Don't show entries scheduled in the future.
  603. The idea behind this is that by scheduling it, you don't want to
  604. think about it until the scheduled date.
  605. all Don't show any scheduled entries in the global todo list.
  606. The idea behind this is that by scheduling it, you have already
  607. \"taken care\" of this item.
  608. t Same as `all', for backward compatibility.
  609. This variable can also have an integer as a value. See
  610. `org-agenda-todo-ignore-timestamp' for more details.
  611. See also `org-agenda-todo-ignore-with-date'.
  612. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  613. to make his option also apply to the tags-todo list."
  614. :group 'org-agenda-skip
  615. :group 'org-agenda-todo-list
  616. :type '(choice
  617. (const :tag "Ignore future-scheduled todos" future)
  618. (const :tag "Ignore past- or present-scheduled todos" past)
  619. (const :tag "Ignore all scheduled todos" all)
  620. (const :tag "Ignore all scheduled todos (compatibility)" t)
  621. (const :tag "Show scheduled todos" nil)
  622. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  623. (defcustom org-agenda-todo-ignore-deadlines nil
  624. "Non-nil means ignore some deadlined TODO items when making TODO list.
  625. There are different motivations for using different values, please think
  626. carefully when configuring this variable.
  627. This applies when creating the global todo list.
  628. Valid values are:
  629. near Don't show near deadline entries. A deadline is near when it is
  630. closer than `org-deadline-warning-days' days. The idea behind this
  631. is that such items will appear in the agenda anyway.
  632. far Don't show TODO entries where a deadline has been defined, but
  633. the deadline is not near. This is useful if you don't want to
  634. use the todo list to figure out what to do now.
  635. past Don't show entries with a deadline timestamp for today or in the past.
  636. future Don't show entries with a deadline timestamp in the future, not even
  637. when they become `near' ones. Use it with caution.
  638. all Ignore all TODO entries that do have a deadline.
  639. t Same as `near', for backward compatibility.
  640. This variable can also have an integer as a value. See
  641. `org-agenda-todo-ignore-timestamp' for more details.
  642. See also `org-agenda-todo-ignore-with-date'.
  643. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  644. to make his option also apply to the tags-todo list."
  645. :group 'org-agenda-skip
  646. :group 'org-agenda-todo-list
  647. :type '(choice
  648. (const :tag "Ignore near deadlines" near)
  649. (const :tag "Ignore near deadlines (compatibility)" t)
  650. (const :tag "Ignore far deadlines" far)
  651. (const :tag "Ignore all TODOs with a deadlines" all)
  652. (const :tag "Show all TODOs, even if they have a deadline" nil)
  653. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  654. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  655. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  656. The variables
  657. `org-agenda-todo-ignore-with-date',
  658. `org-agenda-todo-ignore-timestamp',
  659. `org-agenda-todo-ignore-scheduled',
  660. `org-agenda-todo-ignore-deadlines'
  661. make the global TODO list skip entries that have time stamps of certain
  662. kinds. If this option is set, the same options will also apply for the
  663. tags-todo search, which is the general tags/property matcher
  664. restricted to unfinished TODO entries only."
  665. :group 'org-agenda-skip
  666. :group 'org-agenda-todo-list
  667. :group 'org-agenda-match-view
  668. :type 'boolean)
  669. (defcustom org-agenda-skip-scheduled-if-done nil
  670. "Non-nil means don't show scheduled items in agenda when they are done.
  671. This is relevant for the daily/weekly agenda, not for the TODO list. And
  672. it applies only to the actual date of the scheduling. Warnings about
  673. an item with a past scheduling dates are always turned off when the item
  674. is DONE."
  675. :group 'org-agenda-skip
  676. :group 'org-agenda-daily/weekly
  677. :type 'boolean)
  678. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  679. "Non-nil means skip scheduling line if same entry shows because of deadline.
  680. In the agenda of today, an entry can show up multiple times because
  681. it is both scheduled and has a nearby deadline, and maybe a plain time
  682. stamp as well.
  683. When this variable is t, then only the deadline is shown and the fact that
  684. the entry is scheduled today or was scheduled previously is not shown.
  685. When this variable is nil, the entry will be shown several times. When
  686. the variable is the symbol `not-today', then skip scheduled previously,
  687. but not scheduled today."
  688. :group 'org-agenda-skip
  689. :group 'org-agenda-daily/weekly
  690. :type '(choice
  691. (const :tag "Never" nil)
  692. (const :tag "Always" t)
  693. (const :tag "Not when scheduled today" not-today)))
  694. (defcustom org-agenda-skip-deadline-if-done nil
  695. "Non-nil means don't show deadlines when the corresponding item is done.
  696. When nil, the deadline is still shown and should give you a happy feeling.
  697. This is relevant for the daily/weekly agenda. And it applied only to the
  698. actually date of the deadline. Warnings about approaching and past-due
  699. deadlines are always turned off when the item is DONE."
  700. :group 'org-agenda-skip
  701. :group 'org-agenda-daily/weekly
  702. :type 'boolean)
  703. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  704. "Non-nil means skip deadline prewarning when entry is also scheduled.
  705. This will apply on all days where a prewarning for the deadline would
  706. be shown, but not at the day when the entry is actually due. On that day,
  707. the deadline will be shown anyway.
  708. This variable may be set to nil, t, or a number which will then give
  709. the number of days before the actual deadline when the prewarnings
  710. should resume.
  711. This can be used in a workflow where the first showing of the deadline will
  712. trigger you to schedule it, and then you don't want to be reminded of it
  713. because you will take care of it on the day when scheduled."
  714. :group 'org-agenda-skip
  715. :group 'org-agenda-daily/weekly
  716. :version "24.1"
  717. :type '(choice
  718. (const :tag "Alwas show prewarning" nil)
  719. (const :tag "Remove prewarning if entry is scheduled" t)
  720. (integer :tag "Restart prewarning N days before deadline")))
  721. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  722. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  723. When non-nil, after the search for timestamps has matched once in an
  724. entry, the rest of the entry will not be searched."
  725. :group 'org-agenda-skip
  726. :type 'boolean)
  727. (defcustom org-agenda-skip-timestamp-if-done nil
  728. "Non-nil means don't select item by timestamp or -range if it is DONE."
  729. :group 'org-agenda-skip
  730. :group 'org-agenda-daily/weekly
  731. :type 'boolean)
  732. (defcustom org-agenda-dim-blocked-tasks t
  733. "Non-nil means dim blocked tasks in the agenda display.
  734. This causes some overhead during agenda construction, but if you
  735. have turned on `org-enforce-todo-dependencies',
  736. `org-enforce-todo-checkbox-dependencies', or any other blocking
  737. mechanism, this will create useful feedback in the agenda.
  738. Instead of t, this variable can also have the value `invisible'.
  739. Then blocked tasks will be invisible and only become visible when
  740. they become unblocked. An exemption to this behavior is when a task is
  741. blocked because of unchecked checkboxes below it. Since checkboxes do
  742. not show up in the agenda views, making this task invisible you remove any
  743. trace from agenda views that there is something to do. Therefore, a task
  744. that is blocked because of checkboxes will never be made invisible, it
  745. will only be dimmed."
  746. :group 'org-agenda-daily/weekly
  747. :group 'org-agenda-todo-list
  748. :type '(choice
  749. (const :tag "Do not dim" nil)
  750. (const :tag "Dim to a gray face" t)
  751. (const :tag "Make invisible" invisible)))
  752. (defcustom org-timeline-show-empty-dates 3
  753. "Non-nil means `org-timeline' also shows dates without an entry.
  754. When nil, only the days which actually have entries are shown.
  755. When t, all days between the first and the last date are shown.
  756. When an integer, show also empty dates, but if there is a gap of more than
  757. N days, just insert a special line indicating the size of the gap."
  758. :group 'org-agenda-skip
  759. :type '(choice
  760. (const :tag "None" nil)
  761. (const :tag "All" t)
  762. (integer :tag "at most")))
  763. (defgroup org-agenda-startup nil
  764. "Options concerning initial settings in the Agenda in Org Mode."
  765. :tag "Org Agenda Startup"
  766. :group 'org-agenda)
  767. (defcustom org-agenda-menu-show-matcher t
  768. "Non-nil means show the match string in the agenda dispatcher menu.
  769. When nil, the matcher string is not shown, but is put into the help-echo
  770. property so than moving the mouse over the command shows it.
  771. Setting it to nil is good if matcher strings are very long and/or if
  772. you want to use two-column display (see `org-agenda-menu-two-column')."
  773. :group 'org-agenda
  774. :version "24.1"
  775. :type 'boolean)
  776. (defcustom org-agenda-menu-two-column nil
  777. "Non-nil means, use two columns to show custom commands in the dispatcher.
  778. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  779. to nil."
  780. :group 'org-agenda
  781. :version "24.1"
  782. :type 'boolean)
  783. (defcustom org-finalize-agenda-hook nil
  784. "Hook run just before displaying an agenda buffer."
  785. :group 'org-agenda-startup
  786. :type 'hook)
  787. (defcustom org-agenda-mouse-1-follows-link nil
  788. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  789. A longer mouse click will still set point. Does not work on XEmacs.
  790. Needs to be set before org.el is loaded."
  791. :group 'org-agenda-startup
  792. :type 'boolean)
  793. (defcustom org-agenda-start-with-follow-mode nil
  794. "The initial value of follow mode in a newly created agenda window."
  795. :group 'org-agenda-startup
  796. :type 'boolean)
  797. (defcustom org-agenda-follow-indirect nil
  798. "Non-nil means `org-agenda-follow-mode' displays only the
  799. current item's tree, in an indirect buffer."
  800. :group 'org-agenda
  801. :version "24.1"
  802. :type 'boolean)
  803. (defcustom org-agenda-show-outline-path t
  804. "Non-nil means show outline path in echo area after line motion."
  805. :group 'org-agenda-startup
  806. :type 'boolean)
  807. (defcustom org-agenda-start-with-entry-text-mode nil
  808. "The initial value of entry-text-mode in a newly created agenda window."
  809. :group 'org-agenda-startup
  810. :type 'boolean)
  811. (defcustom org-agenda-entry-text-maxlines 5
  812. "Number of text lines to be added when `E' is pressed in the agenda.
  813. Note that this variable only used during agenda display. Add add entry text
  814. when exporting the agenda, configure the variable
  815. `org-agenda-add-entry-ext-maxlines'."
  816. :group 'org-agenda
  817. :type 'integer)
  818. (defcustom org-agenda-entry-text-exclude-regexps nil
  819. "List of regular expressions to clean up entry text.
  820. The complete matches of all regular expressions in this list will be
  821. removed from entry text before it is shown in the agenda."
  822. :group 'org-agenda
  823. :type '(repeat (regexp)))
  824. (defvar org-agenda-entry-text-cleanup-hook nil
  825. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  826. This cleanup is done in a temporary buffer, so the function may inspect and
  827. change the entire buffer.
  828. Some default stuff like drawers and scheduling/deadline dates will already
  829. have been removed when this is called, as will any matches for regular
  830. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  831. (defvar org-agenda-include-inactive-timestamps nil
  832. "Non-nil means include inactive time stamps in agenda and timeline.
  833. Dynamically scoped.")
  834. (defgroup org-agenda-windows nil
  835. "Options concerning the windows used by the Agenda in Org Mode."
  836. :tag "Org Agenda Windows"
  837. :group 'org-agenda)
  838. (defcustom org-agenda-window-setup 'reorganize-frame
  839. "How the agenda buffer should be displayed.
  840. Possible values for this option are:
  841. current-window Show agenda in the current window, keeping all other windows.
  842. other-window Use `switch-to-buffer-other-window' to display agenda.
  843. reorganize-frame Show only two windows on the current frame, the current
  844. window and the agenda.
  845. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  846. Also, when exiting the agenda, kill that frame.
  847. See also the variable `org-agenda-restore-windows-after-quit'."
  848. :group 'org-agenda-windows
  849. :type '(choice
  850. (const current-window)
  851. (const other-frame)
  852. (const other-window)
  853. (const reorganize-frame)))
  854. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  855. "The min and max height of the agenda window as a fraction of frame height.
  856. The value of the variable is a cons cell with two numbers between 0 and 1.
  857. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  858. :group 'org-agenda-windows
  859. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  860. (defcustom org-agenda-restore-windows-after-quit nil
  861. "Non-nil means restore window configuration upon exiting agenda.
  862. Before the window configuration is changed for displaying the agenda,
  863. the current status is recorded. When the agenda is exited with
  864. `q' or `x' and this option is set, the old state is restored. If
  865. `org-agenda-window-setup' is `other-frame', the value of this
  866. option will be ignored."
  867. :group 'org-agenda-windows
  868. :type 'boolean)
  869. (defcustom org-agenda-ndays nil
  870. "Number of days to include in overview display.
  871. Should be 1 or 7.
  872. Obsolete, see `org-agenda-span'."
  873. :group 'org-agenda-daily/weekly
  874. :type 'integer)
  875. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  876. (defcustom org-agenda-span 'week
  877. "Number of days to include in overview display.
  878. Can be day, week, month, year, or any number of days.
  879. Custom commands can set this variable in the options section."
  880. :group 'org-agenda-daily/weekly
  881. :type '(choice (const :tag "Day" day)
  882. (const :tag "Week" week)
  883. (const :tag "Month" month)
  884. (const :tag "Year" year)
  885. (integer :tag "Custom")))
  886. (defcustom org-agenda-start-on-weekday 1
  887. "Non-nil means start the overview always on the specified weekday.
  888. 0 denotes Sunday, 1 denotes Monday etc.
  889. When nil, always start on the current day.
  890. Custom commands can set this variable in the options section."
  891. :group 'org-agenda-daily/weekly
  892. :type '(choice (const :tag "Today" nil)
  893. (integer :tag "Weekday No.")))
  894. (defcustom org-agenda-show-all-dates t
  895. "Non-nil means `org-agenda' shows every day in the selected range.
  896. When nil, only the days which actually have entries are shown."
  897. :group 'org-agenda-daily/weekly
  898. :type 'boolean)
  899. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  900. "Format string for displaying dates in the agenda.
  901. Used by the daily/weekly agenda and by the timeline. This should be
  902. a format string understood by `format-time-string', or a function returning
  903. the formatted date as a string. The function must take a single argument,
  904. a calendar-style date list like (month day year)."
  905. :group 'org-agenda-daily/weekly
  906. :type '(choice
  907. (string :tag "Format string")
  908. (function :tag "Function")))
  909. (defun org-agenda-format-date-aligned (date)
  910. "Format a date string for display in the daily/weekly agenda, or timeline.
  911. This function makes sure that dates are aligned for easy reading."
  912. (require 'cal-iso)
  913. (let* ((dayname (calendar-day-name date))
  914. (day (cadr date))
  915. (day-of-week (calendar-day-of-week date))
  916. (month (car date))
  917. (monthname (calendar-month-name month))
  918. (year (nth 2 date))
  919. (iso-week (org-days-to-iso-week
  920. (calendar-absolute-from-gregorian date)))
  921. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  922. (1- year))
  923. ((and (= month 12) (<= iso-week 1))
  924. (1+ year))
  925. (t year)))
  926. (weekstring (if (= day-of-week 1)
  927. (format " W%02d" iso-week)
  928. "")))
  929. (format "%-10s %2d %s %4d%s"
  930. dayname day monthname year weekstring)))
  931. (defcustom org-agenda-time-leading-zero nil
  932. "Non-nil means use leading zero for military times in agenda.
  933. For example, 9:30am would become 09:30 rather than 9:30."
  934. :group 'org-agenda-daily/weekly
  935. :version "24.1"
  936. :type 'boolean)
  937. (defcustom org-agenda-timegrid-use-ampm nil
  938. "When set, show AM/PM style timestamps on the timegrid."
  939. :group 'org-agenda
  940. :version "24.1"
  941. :type 'boolean)
  942. (defun org-agenda-time-of-day-to-ampm (time)
  943. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  944. (let* ((hour-number (string-to-number (substring time 0 -3)))
  945. (minute (substring time -2))
  946. (ampm "am"))
  947. (cond
  948. ((equal hour-number 12)
  949. (setq ampm "pm"))
  950. ((> hour-number 12)
  951. (setq ampm "pm")
  952. (setq hour-number (- hour-number 12))))
  953. (concat
  954. (if org-agenda-time-leading-zero
  955. (format "%02d" hour-number)
  956. (format "%02s" (number-to-string hour-number)))
  957. ":" minute ampm)))
  958. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  959. "Conditionally convert TIME to AM/PM format
  960. based on `org-agenda-timegrid-use-ampm'"
  961. (if org-agenda-timegrid-use-ampm
  962. (org-agenda-time-of-day-to-ampm time)
  963. time))
  964. (defcustom org-agenda-weekend-days '(6 0)
  965. "Which days are weekend?
  966. These days get the special face `org-agenda-date-weekend' in the agenda
  967. and timeline buffers."
  968. :group 'org-agenda-daily/weekly
  969. :type '(set :greedy t
  970. (const :tag "Monday" 1)
  971. (const :tag "Tuesday" 2)
  972. (const :tag "Wednesday" 3)
  973. (const :tag "Thursday" 4)
  974. (const :tag "Friday" 5)
  975. (const :tag "Saturday" 6)
  976. (const :tag "Sunday" 0)))
  977. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  978. "Non-nil means jump to today when moving a past date forward in time.
  979. When using S-right in the agenda to move a a date forward, and the date
  980. stamp currently points to the past, the first key press will move it
  981. to today. WHen nil, just move one day forward even if the date stays
  982. in the past."
  983. :group 'org-agenda-daily/weekly
  984. :version "24.1"
  985. :type 'boolean)
  986. (defcustom org-agenda-include-diary nil
  987. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  988. Custom commands can set this variable in the options section."
  989. :group 'org-agenda-daily/weekly
  990. :type 'boolean)
  991. (defcustom org-agenda-include-deadlines t
  992. "If non-nil, include entries within their deadline warning period.
  993. Custom commands can set this variable in the options section."
  994. :group 'org-agenda-daily/weekly
  995. :version "24.1"
  996. :type 'boolean)
  997. (defcustom org-agenda-repeating-timestamp-show-all t
  998. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  999. When set to a list of strings, only show occurrences of repeating
  1000. stamps for these TODO keywords. When nil, only one occurrence is
  1001. shown, either today or the nearest into the future."
  1002. :group 'org-agenda-daily/weekly
  1003. :type '(choice
  1004. (const :tag "Show repeating stamps" t)
  1005. (repeat :tag "Show repeating stamps for these TODO keywords"
  1006. (string :tag "TODO Keyword"))
  1007. (const :tag "Don't show repeating stamps" nil)))
  1008. (defcustom org-scheduled-past-days 10000
  1009. "No. of days to continue listing scheduled items that are not marked DONE.
  1010. When an item is scheduled on a date, it shows up in the agenda on this
  1011. day and will be listed until it is marked done for the number of days
  1012. given here."
  1013. :group 'org-agenda-daily/weekly
  1014. :type 'integer)
  1015. (defcustom org-agenda-log-mode-items '(closed clock)
  1016. "List of items that should be shown in agenda log mode.
  1017. This list may contain the following symbols:
  1018. closed Show entries that have been closed on that day.
  1019. clock Show entries that have received clocked time on that day.
  1020. state Show all logged state changes.
  1021. Note that instead of changing this variable, you can also press `C-u l' in
  1022. the agenda to display all available LOG items temporarily."
  1023. :group 'org-agenda-daily/weekly
  1024. :type '(set :greedy t (const closed) (const clock) (const state)))
  1025. (defcustom org-agenda-clock-consistency-checks
  1026. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1027. :gap-ok-around ("4:00")
  1028. :default-face ((:background "DarkRed") (:foreground "white"))
  1029. :overlap-face nil :gap-face nil :no-end-time-face nil
  1030. :long-face nil :short-face nil)
  1031. "This is a property list, with the following keys:
  1032. :max-duration Mark clocking chunks that are longer than this time.
  1033. This is a time string like \"HH:MM\", or the number
  1034. of minutes as an integer.
  1035. :min-duration Mark clocking chunks that are shorter that this.
  1036. This is a time string like \"HH:MM\", or the number
  1037. of minutes as an integer.
  1038. :max-gap Mark gaps between clocking chunks that are longer than
  1039. this duration. A number of minutes, or a string
  1040. like \"HH:MM\".
  1041. :gap-ok-around List of times during the day which are usually not working
  1042. times. When a gap is detected, but the gap contains any
  1043. of these times, the gap is *not* reported. For example,
  1044. if this is (\"4:00\" \"13:00\") then gaps that contain
  1045. 4:00 in the morning (i.e. the night) and 13:00
  1046. (i.e. a typical lunch time) do not cause a warning.
  1047. You should have at least one time during the night in this
  1048. list, or otherwise the first task each morning will trigger
  1049. a warning because it follows a long gap.
  1050. Furthermore, the following properties can be used to define faces for
  1051. issue display.
  1052. :default-face the default face, if the specific face is undefined
  1053. :overlap-face face for overlapping clocks
  1054. :gap-face face for gaps between clocks
  1055. :no-end-time-face face for incomplete clocks
  1056. :long-face face for clock intervals that are too long
  1057. :short-face face for clock intervals that are too short"
  1058. :group 'org-agenda-daily/weekly
  1059. :group 'org-clock
  1060. :version "24.1"
  1061. :type 'plist)
  1062. (defcustom org-agenda-log-mode-add-notes t
  1063. "Non-nil means add first line of notes to log entries in agenda views.
  1064. If a log item like a state change or a clock entry is associated with
  1065. notes, the first line of these notes will be added to the entry in the
  1066. agenda display."
  1067. :group 'org-agenda-daily/weekly
  1068. :type 'boolean)
  1069. (defcustom org-agenda-start-with-log-mode nil
  1070. "The initial value of log-mode in a newly created agenda window."
  1071. :group 'org-agenda-startup
  1072. :group 'org-agenda-daily/weekly
  1073. :type 'boolean)
  1074. (defcustom org-agenda-start-with-clockreport-mode nil
  1075. "The initial value of clockreport-mode in a newly created agenda window."
  1076. :group 'org-agenda-startup
  1077. :group 'org-agenda-daily/weekly
  1078. :type 'boolean)
  1079. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1080. "Property list with parameters for the clocktable in clockreport mode.
  1081. This is the display mode that shows a clock table in the daily/weekly
  1082. agenda, the properties for this dynamic block can be set here.
  1083. The usual clocktable parameters are allowed here, but you cannot set
  1084. the properties :name, :tstart, :tend, :block, and :scope - these will
  1085. be overwritten to make sure the content accurately reflects the
  1086. current display in the agenda."
  1087. :group 'org-agenda-daily/weekly
  1088. :type 'plist)
  1089. (defcustom org-agenda-search-view-always-boolean nil
  1090. "Non-nil means the search string is interpreted as individual parts.
  1091. The search string for search view can either be interpreted as a phrase,
  1092. or as a list of snippets that define a boolean search for a number of
  1093. strings.
  1094. When this is non-nil, the string will be split on whitespace, and each
  1095. snippet will be searched individually, and all must match in order to
  1096. select an entry. A snippet is then a single string of non-white
  1097. characters, or a string in double quotes, or a regexp in {} braces.
  1098. If a snippet is preceded by \"-\", the snippet must *not* match.
  1099. \"+\" is syntactic sugar for positive selection. Each snippet may
  1100. be found as a full word or a partial word, but see the variable
  1101. `org-agenda-search-view-force-full-words'.
  1102. When this is nil, search will look for the entire search phrase as one,
  1103. with each space character matching any amount of whitespace, including
  1104. line breaks.
  1105. Even when this is nil, you can still switch to Boolean search dynamically
  1106. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1107. is a regexp marked with braces like \"{abc}\", this will also switch to
  1108. boolean search."
  1109. :group 'org-agenda-search-view
  1110. :version "24.1"
  1111. :type 'boolean)
  1112. (if (fboundp 'defvaralias)
  1113. (defvaralias 'org-agenda-search-view-search-words-only
  1114. 'org-agenda-search-view-always-boolean))
  1115. (defcustom org-agenda-search-view-force-full-words nil
  1116. "Non-nil means, search words must be matches as complete words.
  1117. When nil, they may also match part of a word."
  1118. :group 'org-agenda-search-view
  1119. :version "24.1"
  1120. :type 'boolean)
  1121. (defgroup org-agenda-time-grid nil
  1122. "Options concerning the time grid in the Org-mode Agenda."
  1123. :tag "Org Agenda Time Grid"
  1124. :group 'org-agenda)
  1125. (defcustom org-agenda-search-headline-for-time t
  1126. "Non-nil means search headline for a time-of-day.
  1127. If the headline contains a time-of-day in one format or another, it will
  1128. be used to sort the entry into the time sequence of items for a day.
  1129. Some people have time stamps in the headline that refer to the creation
  1130. time or so, and then this produces an unwanted side effect. If this is
  1131. the case for your, use this variable to turn off searching the headline
  1132. for a time."
  1133. :group 'org-agenda-time-grid
  1134. :type 'boolean)
  1135. (defcustom org-agenda-use-time-grid t
  1136. "Non-nil means show a time grid in the agenda schedule.
  1137. A time grid is a set of lines for specific times (like every two hours between
  1138. 8:00 and 20:00). The items scheduled for a day at specific times are
  1139. sorted in between these lines.
  1140. For details about when the grid will be shown, and what it will look like, see
  1141. the variable `org-agenda-time-grid'."
  1142. :group 'org-agenda-time-grid
  1143. :type 'boolean)
  1144. (defcustom org-agenda-time-grid
  1145. '((daily today require-timed)
  1146. "----------------"
  1147. (800 1000 1200 1400 1600 1800 2000))
  1148. "The settings for time grid for agenda display.
  1149. This is a list of three items. The first item is again a list. It contains
  1150. symbols specifying conditions when the grid should be displayed:
  1151. daily if the agenda shows a single day
  1152. weekly if the agenda shows an entire week
  1153. today show grid on current date, independent of daily/weekly display
  1154. require-timed show grid only if at least one item has a time specification
  1155. The second item is a string which will be placed behind the grid time.
  1156. The third item is a list of integers, indicating the times that should have
  1157. a grid line."
  1158. :group 'org-agenda-time-grid
  1159. :type
  1160. '(list
  1161. (set :greedy t :tag "Grid Display Options"
  1162. (const :tag "Show grid in single day agenda display" daily)
  1163. (const :tag "Show grid in weekly agenda display" weekly)
  1164. (const :tag "Always show grid for today" today)
  1165. (const :tag "Show grid only if any timed entries are present"
  1166. require-timed)
  1167. (const :tag "Skip grid times already present in an entry"
  1168. remove-match))
  1169. (string :tag "Grid String")
  1170. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1171. (defcustom org-agenda-show-current-time-in-grid t
  1172. "Non-nil means show the current time in the time grid."
  1173. :group 'org-agenda-time-grid
  1174. :version "24.1"
  1175. :type 'boolean)
  1176. (defcustom org-agenda-current-time-string
  1177. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1178. "The string for the current time marker in the agenda."
  1179. :group 'org-agenda-time-grid
  1180. :version "24.1"
  1181. :type 'string)
  1182. (defgroup org-agenda-sorting nil
  1183. "Options concerning sorting in the Org-mode Agenda."
  1184. :tag "Org Agenda Sorting"
  1185. :group 'org-agenda)
  1186. (defcustom org-agenda-sorting-strategy
  1187. '((agenda habit-down time-up priority-down category-keep)
  1188. (todo priority-down category-keep)
  1189. (tags priority-down category-keep)
  1190. (search category-keep))
  1191. "Sorting structure for the agenda items of a single day.
  1192. This is a list of symbols which will be used in sequence to determine
  1193. if an entry should be listed before another entry. The following
  1194. symbols are recognized:
  1195. time-up Put entries with time-of-day indications first, early first
  1196. time-down Put entries with time-of-day indications first, late first
  1197. category-keep Keep the default order of categories, corresponding to the
  1198. sequence in `org-agenda-files'.
  1199. category-up Sort alphabetically by category, A-Z.
  1200. category-down Sort alphabetically by category, Z-A.
  1201. tag-up Sort alphabetically by last tag, A-Z.
  1202. tag-down Sort alphabetically by last tag, Z-A.
  1203. priority-up Sort numerically by priority, high priority last.
  1204. priority-down Sort numerically by priority, high priority first.
  1205. todo-state-up Sort by todo state, tasks that are done last.
  1206. todo-state-down Sort by todo state, tasks that are done first.
  1207. effort-up Sort numerically by estimated effort, high effort last.
  1208. effort-down Sort numerically by estimated effort, high effort first.
  1209. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1210. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1211. habit-up Put entries that are habits first
  1212. habit-down Put entries that are habits last
  1213. alpha-up Sort headlines alphabetically
  1214. alpha-down Sort headlines alphabetically, reversed
  1215. The different possibilities will be tried in sequence, and testing stops
  1216. if one comparison returns a \"not-equal\". For example, the default
  1217. '(time-up category-keep priority-down)
  1218. means: Pull out all entries having a specified time of day and sort them,
  1219. in order to make a time schedule for the current day the first thing in the
  1220. agenda listing for the day. Of the entries without a time indication, keep
  1221. the grouped in categories, don't sort the categories, but keep them in
  1222. the sequence given in `org-agenda-files'. Within each category sort by
  1223. priority.
  1224. Leaving out `category-keep' would mean that items will be sorted across
  1225. categories by priority.
  1226. Instead of a single list, this can also be a set of list for specific
  1227. contents, with a context symbol in the car of the list, any of
  1228. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1229. Custom commands can bind this variable in the options section."
  1230. :group 'org-agenda-sorting
  1231. :type `(choice
  1232. (repeat :tag "General" ,org-sorting-choice)
  1233. (list :tag "Individually"
  1234. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1235. (repeat ,org-sorting-choice))
  1236. (cons (const :tag "Strategy for TODO lists" todo)
  1237. (repeat ,org-sorting-choice))
  1238. (cons (const :tag "Strategy for Tags matches" tags)
  1239. (repeat ,org-sorting-choice))
  1240. (cons (const :tag "Strategy for search matches" search)
  1241. (repeat ,org-sorting-choice)))))
  1242. (defcustom org-agenda-cmp-user-defined nil
  1243. "A function to define the comparison `user-defined'.
  1244. This function must receive two arguments, agenda entry a and b.
  1245. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1246. the user comparison, return nil.
  1247. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1248. part of an agenda sorting strategy."
  1249. :group 'org-agenda-sorting
  1250. :type 'symbol)
  1251. (defcustom org-sort-agenda-notime-is-late t
  1252. "Non-nil means items without time are considered late.
  1253. This is only relevant for sorting. When t, items which have no explicit
  1254. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1255. do have a time. When nil, the default time is before 0:00. You can use this
  1256. option to decide if the schedule for today should come before or after timeless
  1257. agenda entries."
  1258. :group 'org-agenda-sorting
  1259. :type 'boolean)
  1260. (defcustom org-sort-agenda-noeffort-is-high t
  1261. "Non-nil means items without effort estimate are sorted as high effort.
  1262. This also applies when filtering an agenda view with respect to the
  1263. < or > effort operator. Then, tasks with no effort defined will be treated
  1264. as tasks with high effort.
  1265. When nil, such items are sorted as 0 minutes effort."
  1266. :group 'org-agenda-sorting
  1267. :type 'boolean)
  1268. (defgroup org-agenda-line-format nil
  1269. "Options concerning the entry prefix in the Org-mode agenda display."
  1270. :tag "Org Agenda Line Format"
  1271. :group 'org-agenda)
  1272. (defcustom org-agenda-prefix-format
  1273. '((agenda . " %i %-12:c%?-12t% s")
  1274. (timeline . " % s")
  1275. (todo . " %i %-12:c")
  1276. (tags . " %i %-12:c")
  1277. (search . " %i %-12:c"))
  1278. "Format specifications for the prefix of items in the agenda views.
  1279. An alist with five entries, each for the different agenda types. The
  1280. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1281. The values are format strings.
  1282. This format works similar to a printf format, with the following meaning:
  1283. %c the category of the item, \"Diary\" for entries from the diary,
  1284. or as given by the CATEGORY keyword or derived from the file name
  1285. %e the effort required by the item
  1286. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1287. %T the last tag of the item (ignore inherited tags, which come first)
  1288. %t the HH:MM time-of-day specification if one applies to the entry
  1289. %s Scheduling/Deadline information, a short string
  1290. %(expression) Eval EXPRESSION and replace the control string
  1291. by the result
  1292. All specifiers work basically like the standard `%s' of printf, but may
  1293. contain two additional characters: a question mark just after the `%'
  1294. and a whitespace/punctuation character just before the final letter.
  1295. If the first character after `%' is a question mark, the entire field
  1296. will only be included if the corresponding value applies to the current
  1297. entry. This is useful for fields which should have fixed width when
  1298. present, but zero width when absent. For example, \"%?-12t\" will
  1299. result in a 12 character time field if a time of the day is specified,
  1300. but will completely disappear in entries which do not contain a time.
  1301. If there is punctuation or whitespace character just before the final
  1302. format letter, this character will be appended to the field value if
  1303. the value is not empty. For example, the format \"%-12:c\" leads to
  1304. \"Diary: \" if the category is \"Diary\". If the category were be
  1305. empty, no additional colon would be inserted.
  1306. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1307. which means:
  1308. - Indent the line with two space characters
  1309. - Give the category a 12 chars wide field, padded with whitespace on
  1310. the right (because of `-'). Append a colon if there is a category
  1311. (because of `:').
  1312. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1313. time, don't put in an empty field, just skip it (because of '?').
  1314. - Finally, put the scheduling information.
  1315. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1316. `org-agenda-remove-tags'.
  1317. Custom commands can set this variable in the options section."
  1318. :type '(choice
  1319. (string :tag "General format")
  1320. (list :greedy t :tag "View dependent"
  1321. (cons (const agenda) (string :tag "Format"))
  1322. (cons (const timeline) (string :tag "Format"))
  1323. (cons (const todo) (string :tag "Format"))
  1324. (cons (const tags) (string :tag "Format"))
  1325. (cons (const search) (string :tag "Format"))))
  1326. :group 'org-agenda-line-format)
  1327. (defvar org-prefix-format-compiled nil
  1328. "The compiled prefix format and associated variables.
  1329. This is a list where first element is a list of variable bindings, and second
  1330. element is the compiled format expression. See the variable
  1331. `org-agenda-prefix-format'.")
  1332. (defcustom org-agenda-todo-keyword-format "%-1s"
  1333. "Format for the TODO keyword in agenda lines.
  1334. Set this to something like \"%-12s\" if you want all TODO keywords
  1335. to occupy a fixed space in the agenda display."
  1336. :group 'org-agenda-line-format
  1337. :type 'string)
  1338. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1339. "Text preceding timerange entries in the agenda view.
  1340. This is a list with two strings. The first applies when the range
  1341. is entirely on one day. The second applies if the range spans several days.
  1342. The strings may have two \"%d\" format specifiers which will be filled
  1343. with the sequence number of the days, and the total number of days in the
  1344. range, respectively."
  1345. :group 'org-agenda-line-format
  1346. :type '(list
  1347. (string :tag "Deadline today ")
  1348. (choice :tag "Deadline relative"
  1349. (string :tag "Format string")
  1350. (function))))
  1351. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1352. "Text preceding scheduled items in the agenda view.
  1353. This is a list with two strings. The first applies when the item is
  1354. scheduled on the current day. The second applies when it has been scheduled
  1355. previously, it may contain a %d indicating that this is the nth time that
  1356. this item is scheduled, due to automatic rescheduling of unfinished items
  1357. for the following day. So this number is one larger than the number of days
  1358. that passed since this item was scheduled first."
  1359. :group 'org-agenda-line-format
  1360. :type '(list
  1361. (string :tag "Scheduled today ")
  1362. (string :tag "Scheduled previously")))
  1363. (defcustom org-agenda-inactive-leader "["
  1364. "Text preceding item pulled into the agenda by inactive time stamps.
  1365. These entries are added to the agenda when pressing \"[\"."
  1366. :group 'org-agenda-line-format
  1367. :version "24.1"
  1368. :type '(list
  1369. (string :tag "Scheduled today ")
  1370. (string :tag "Scheduled previously")))
  1371. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1372. "Text preceding deadline items in the agenda view.
  1373. This is a list with two strings. The first applies when the item has its
  1374. deadline on the current day. The second applies when it is in the past or
  1375. in the future, it may contain %d to capture how many days away the deadline
  1376. is (was)."
  1377. :group 'org-agenda-line-format
  1378. :type '(list
  1379. (string :tag "Deadline today ")
  1380. (choice :tag "Deadline relative"
  1381. (string :tag "Format string")
  1382. (function))))
  1383. (defcustom org-agenda-remove-times-when-in-prefix t
  1384. "Non-nil means remove duplicate time specifications in agenda items.
  1385. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1386. time-of-day specification in a headline or diary entry is extracted and
  1387. placed into the prefix. If this option is non-nil, the original specification
  1388. \(a timestamp or -range, or just a plain time(range) specification like
  1389. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1390. cluttered.
  1391. The option can be t or nil. It may also be the symbol `beg', indicating
  1392. that the time should only be removed when it is located at the beginning of
  1393. the headline/diary entry."
  1394. :group 'org-agenda-line-format
  1395. :type '(choice
  1396. (const :tag "Always" t)
  1397. (const :tag "Never" nil)
  1398. (const :tag "When at beginning of entry" beg)))
  1399. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1400. "Non-nil means remove time ranges specifications in agenda
  1401. items that span on several days."
  1402. :group 'org-agenda-line-format
  1403. :version "24.1"
  1404. :type 'boolean)
  1405. (defcustom org-agenda-default-appointment-duration nil
  1406. "Default duration for appointments that only have a starting time.
  1407. When nil, no duration is specified in such cases.
  1408. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1409. :group 'org-agenda-line-format
  1410. :type '(choice
  1411. (integer :tag "Minutes")
  1412. (const :tag "No default duration")))
  1413. (defcustom org-agenda-show-inherited-tags t
  1414. "Non-nil means show inherited tags in each agenda line."
  1415. :group 'org-agenda-line-format
  1416. :type 'boolean)
  1417. (defcustom org-agenda-hide-tags-regexp nil
  1418. "Regular expression used to filter away specific tags in agenda views.
  1419. This means that these tags will be present, but not be shown in the agenda
  1420. line. Secondary filtering will still work on the hidden tags.
  1421. Nil means don't hide any tags."
  1422. :group 'org-agenda-line-format
  1423. :type '(choice
  1424. (const :tag "Hide none" nil)
  1425. (string :tag "Regexp ")))
  1426. (defcustom org-agenda-remove-tags nil
  1427. "Non-nil means remove the tags from the headline copy in the agenda.
  1428. When this is the symbol `prefix', only remove tags when
  1429. `org-agenda-prefix-format' contains a `%T' specifier."
  1430. :group 'org-agenda-line-format
  1431. :type '(choice
  1432. (const :tag "Always" t)
  1433. (const :tag "Never" nil)
  1434. (const :tag "When prefix format contains %T" prefix)))
  1435. (if (fboundp 'defvaralias)
  1436. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1437. 'org-agenda-remove-tags))
  1438. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1439. "Shift tags in agenda items to this column.
  1440. If this number is positive, it specifies the column. If it is negative,
  1441. it means that the tags should be flushright to that column. For example,
  1442. -80 works well for a normal 80 character screen."
  1443. :group 'org-agenda-line-format
  1444. :type 'integer)
  1445. (if (fboundp 'defvaralias)
  1446. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1447. (defcustom org-agenda-fontify-priorities 'cookies
  1448. "Non-nil means highlight low and high priorities in agenda.
  1449. When t, the highest priority entries are bold, lowest priority italic.
  1450. However, settings in `org-priority-faces' will overrule these faces.
  1451. When this variable is the symbol `cookies', only fontify the
  1452. cookies, not the entire task.
  1453. This may also be an association list of priority faces, whose
  1454. keys are the character values of `org-highest-priority',
  1455. `org-default-priority', and `org-lowest-priority' (the default values
  1456. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1457. color as a string, or a list like `(:background \"Red\")'.
  1458. If it is a color, the variable `org-faces-easy-properties'
  1459. determines if it is a foreground or a background color."
  1460. :group 'org-agenda-line-format
  1461. :type '(choice
  1462. (const :tag "Never" nil)
  1463. (const :tag "Defaults" t)
  1464. (const :tag "Cookies only" cookies)
  1465. (repeat :tag "Specify"
  1466. (list (character :tag "Priority" :value ?A)
  1467. (choice :tag "Face "
  1468. (string :tag "Color")
  1469. (sexp :tag "Face"))))))
  1470. (defcustom org-agenda-day-face-function nil
  1471. "Function called to determine what face should be used to display a day.
  1472. The only argument passed to that function is the day. It should
  1473. returns a face, or nil if does not want to specify a face and let
  1474. the normal rules apply."
  1475. :group 'org-agenda-line-format
  1476. :version "24.1"
  1477. :type 'function)
  1478. (defcustom org-agenda-category-icon-alist nil
  1479. "Alist of category icon to be displayed in agenda views.
  1480. Each entry should have the following format:
  1481. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1482. Where CATEGORY-REGEXP is a regexp matching the categories where
  1483. the icon should be displayed.
  1484. FILE-OR-DATA either a file path or a string containing image data.
  1485. The other fields can be omitted safely if not needed:
  1486. TYPE indicates the image type.
  1487. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1488. image data.
  1489. PROPS are additional image attributes to assign to the image,
  1490. like, e.g. `:ascent center'.
  1491. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1492. If you want to set the display properties yourself, just put a
  1493. list as second element:
  1494. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1495. For example, to display a 16px horizontal space for Emacs
  1496. category, you can use:
  1497. (\"Emacs\" '(space . (:width (16))))"
  1498. :group 'org-agenda-line-format
  1499. :version "24.1"
  1500. :type '(alist :key-type (string :tag "Regexp matching category")
  1501. :value-type (choice (list :tag "Icon"
  1502. (string :tag "File or data")
  1503. (symbol :tag "Type")
  1504. (boolean :tag "Data?")
  1505. (repeat :tag "Extra image properties" :inline t symbol))
  1506. (list :tag "Display properties" sexp))))
  1507. (defgroup org-agenda-column-view nil
  1508. "Options concerning column view in the agenda."
  1509. :tag "Org Agenda Column View"
  1510. :group 'org-agenda)
  1511. (defcustom org-agenda-columns-show-summaries t
  1512. "Non-nil means show summaries for columns displayed in the agenda view."
  1513. :group 'org-agenda-column-view
  1514. :type 'boolean)
  1515. (defcustom org-agenda-columns-compute-summary-properties t
  1516. "Non-nil means recompute all summary properties before column view.
  1517. When column view in the agenda is listing properties that have a summary
  1518. operator, it can go to all relevant buffers and recompute the summaries
  1519. there. This can mean overhead for the agenda column view, but is necessary
  1520. to have thing up to date.
  1521. As a special case, a CLOCKSUM property also makes sure that the clock
  1522. computations are current."
  1523. :group 'org-agenda-column-view
  1524. :type 'boolean)
  1525. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1526. "Non-nil means the duration of an appointment will add to day effort.
  1527. The property to which appointment durations will be added is the one given
  1528. in the option `org-effort-property'. If an appointment does not have
  1529. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1530. is not set, an appointment without end time will not contribute to the time
  1531. estimate."
  1532. :group 'org-agenda-column-view
  1533. :type 'boolean)
  1534. (defcustom org-agenda-auto-exclude-function nil
  1535. "A function called with a tag to decide if it is filtered on '/ RET'.
  1536. The sole argument to the function, which is called once for each
  1537. possible tag, is a string giving the name of the tag. The
  1538. function should return either nil if the tag should be included
  1539. as normal, or \"-<TAG>\" to exclude the tag.
  1540. Note that for the purpose of tag filtering, only the lower-case version of
  1541. all tags will be considered, so that this function will only ever see
  1542. the lower-case version of all tags."
  1543. :group 'org-agenda
  1544. :type 'function)
  1545. (defcustom org-agenda-bulk-custom-functions nil
  1546. "Alist of characters and custom functions for bulk actions.
  1547. For example, this value makes those two functions available:
  1548. '((?R set-category)
  1549. (?C bulk-cut))
  1550. With selected entries in an agenda buffer, `B R' will call
  1551. the custom function `set-category' on the selected entries.
  1552. Note that functions in this alist don't need to be quoted."
  1553. :type 'alist
  1554. :version "24.1"
  1555. :group 'org-agenda)
  1556. (eval-when-compile
  1557. (require 'cl))
  1558. (require 'org)
  1559. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1560. "Execute BODY with point at location given by `org-hd-marker' property.
  1561. If STRING is non-nil, the text property will be fetched from position 0
  1562. in that string. If STRING is nil, it will be fetched from the beginning
  1563. of the current line."
  1564. (org-with-gensyms (marker)
  1565. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1566. 'org-hd-marker ,string)))
  1567. (with-current-buffer (marker-buffer ,marker)
  1568. (save-excursion
  1569. (goto-char ,marker)
  1570. ,@body)))))
  1571. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1572. (defun org-add-agenda-custom-command (entry)
  1573. "Replace or add a command in `org-agenda-custom-commands'.
  1574. This is mostly for hacking and trying a new command - once the command
  1575. works you probably want to add it to `org-agenda-custom-commands' for good."
  1576. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1577. (if ass
  1578. (setcdr ass (cdr entry))
  1579. (push entry org-agenda-custom-commands))))
  1580. ;;; Define the org-agenda-mode
  1581. (defvar org-agenda-mode-map (make-sparse-keymap)
  1582. "Keymap for `org-agenda-mode'.")
  1583. (if (fboundp 'defvaralias)
  1584. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1585. (defvar org-agenda-menu) ; defined later in this file.
  1586. (defvar org-agenda-restrict) ; defined later in this file.
  1587. (defvar org-agenda-follow-mode nil)
  1588. (defvar org-agenda-entry-text-mode nil)
  1589. (defvar org-agenda-clockreport-mode nil)
  1590. (defvar org-agenda-show-log nil)
  1591. (defvar org-agenda-redo-command nil)
  1592. (defvar org-agenda-query-string nil)
  1593. (defvar org-agenda-mode-hook nil
  1594. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1595. (defvar org-agenda-type nil)
  1596. (defvar org-agenda-force-single-file nil)
  1597. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1598. ;;; Multiple agenda buffers support
  1599. (defcustom org-agenda-sticky nil
  1600. "Non-nil means agenda q key will bury agenda buffers.
  1601. Agenda commands will then show existing buffer instead of generating new ones.
  1602. When nil, `q' will kill the single agenda buffer."
  1603. :group 'org-agenda
  1604. :type 'boolean
  1605. :set (lambda (var val)
  1606. (if (boundp var)
  1607. (org-toggle-sticky-agenda (if val 1 0))
  1608. (set var val))))
  1609. (defun org-toggle-sticky-agenda (&optional arg)
  1610. "Toggle `org-agenda-sticky'."
  1611. (interactive "P")
  1612. (let ((new-value (if arg
  1613. (> (prefix-numeric-value arg) 0)
  1614. (not org-agenda-sticky))))
  1615. (if (equal new-value org-agenda-sticky)
  1616. (message "Sticky agenda was already %s"
  1617. (if org-agenda-sticky "enabled" "disabled"))
  1618. (setq org-agenda-sticky new-value)
  1619. (org-agenda-kill-all-agenda-buffers)
  1620. (message "Sticky agenda was %s"
  1621. (if org-agenda-sticky "enabled" "disabled")))))
  1622. (defvar org-agenda-buffer nil
  1623. "Agenda buffer currently being generated.")
  1624. (defvar org-agenda-last-prefix-arg nil)
  1625. (defvar org-agenda-this-buffer-name nil)
  1626. (defvar org-agenda-doing-sticky-redo nil)
  1627. (defvar org-agenda-this-buffer-is-sticky nil)
  1628. (defconst org-agenda-local-vars
  1629. '(org-agenda-this-buffer-name
  1630. org-agenda-undo-list
  1631. org-agenda-pending-undo-list
  1632. org-agenda-follow-mode
  1633. org-agenda-entry-text-mode
  1634. org-agenda-clockreport-mode
  1635. org-agenda-show-log
  1636. org-agenda-redo-command
  1637. org-agenda-query-string
  1638. org-agenda-type
  1639. org-agenda-bulk-marked-entries
  1640. org-agenda-undo-has-started-in
  1641. org-agenda-last-arguments
  1642. org-agenda-info
  1643. org-agenda-tag-filter-overlays
  1644. org-agenda-cat-filter-overlays
  1645. org-pre-agenda-window-conf
  1646. org-agenda-columns-active
  1647. org-agenda-tag-filter
  1648. org-agenda-category-filter
  1649. org-agenda-markers
  1650. org-agenda-last-search-view-search-was-boolean
  1651. org-agenda-filtered-by-category
  1652. org-agenda-filter-form
  1653. org-agenda-show-window
  1654. org-agenda-cycle-counter
  1655. org-agenda-last-prefix-arg)
  1656. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1657. (defun org-agenda-mode ()
  1658. "Mode for time-sorted view on action items in Org-mode files.
  1659. The following commands are available:
  1660. \\{org-agenda-mode-map}"
  1661. (interactive)
  1662. (cond (org-agenda-doing-sticky-redo
  1663. ;; Refreshing sticky agenda-buffer
  1664. ;;
  1665. ;; Preserve the value of `org-agenda-local-vars' variables,
  1666. ;; while letting `kill-all-local-variables' kill the rest
  1667. (let ((save (buffer-local-variables)))
  1668. (kill-all-local-variables)
  1669. (mapc 'make-local-variable org-agenda-local-vars)
  1670. (dolist (elem save)
  1671. (let ((var (car elem))
  1672. (val (cdr elem)))
  1673. (when (and val
  1674. (member var org-agenda-local-vars))
  1675. (set var val)))))
  1676. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1677. (org-agenda-sticky
  1678. ;; Creating a sticky Agenda buffer for the first time
  1679. (kill-all-local-variables)
  1680. (mapc 'make-local-variable org-agenda-local-vars)
  1681. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1682. (t
  1683. ;; Creating a non-sticky agenda buffer
  1684. (kill-all-local-variables)
  1685. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1686. (setq org-agenda-undo-list nil
  1687. org-agenda-pending-undo-list nil
  1688. org-agenda-bulk-marked-entries nil)
  1689. (setq major-mode 'org-agenda-mode)
  1690. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1691. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1692. (setq mode-name "Org-Agenda")
  1693. (use-local-map org-agenda-mode-map)
  1694. (easy-menu-add org-agenda-menu)
  1695. (if org-startup-truncated (setq truncate-lines t))
  1696. (org-set-local 'line-move-visual nil)
  1697. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1698. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1699. ;; Make sure properties are removed when copying text
  1700. (when (boundp 'buffer-substring-filters)
  1701. (org-set-local 'buffer-substring-filters
  1702. (cons (lambda (x)
  1703. (set-text-properties 0 (length x) nil x) x)
  1704. buffer-substring-filters)))
  1705. (unless org-agenda-keep-modes
  1706. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1707. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1708. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1709. org-agenda-show-log org-agenda-start-with-log-mode))
  1710. (easy-menu-change
  1711. '("Agenda") "Agenda Files"
  1712. (append
  1713. (list
  1714. (vector
  1715. (if (get 'org-agenda-files 'org-restrict)
  1716. "Restricted to single file"
  1717. "Edit File List")
  1718. '(org-edit-agenda-file-list)
  1719. (not (get 'org-agenda-files 'org-restrict)))
  1720. "--")
  1721. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1722. (org-agenda-set-mode-name)
  1723. (apply
  1724. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1725. (list 'org-agenda-mode-hook)))
  1726. (substitute-key-definition 'undo 'org-agenda-undo
  1727. org-agenda-mode-map global-map)
  1728. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1729. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1730. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1731. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1732. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1733. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1734. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1735. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1736. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1737. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1738. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1739. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1740. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1741. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1742. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1743. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1744. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1745. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1746. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1747. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1748. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1749. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1750. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1751. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1752. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1753. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1754. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1755. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1756. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1757. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1758. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1759. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1760. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1761. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1762. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1763. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1764. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1765. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1766. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1767. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1768. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1769. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1770. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1771. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1772. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1773. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1774. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1775. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1776. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1777. (while l (org-defkey org-agenda-mode-map
  1778. (int-to-string (pop l)) 'digit-argument)))
  1779. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1780. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1781. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1782. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1783. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1784. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1785. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1786. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1787. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1788. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1789. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1791. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1792. 'org-clock-modify-effort-estimate)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1794. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1795. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1796. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1797. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1798. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1799. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1800. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1801. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1802. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1803. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1804. (substitute-key-definition 'next-line 'org-agenda-next-line
  1805. org-agenda-mode-map global-map)
  1806. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1807. org-agenda-mode-map global-map)
  1808. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1809. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1810. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1811. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1812. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1813. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1814. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1815. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1816. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1817. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1818. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1819. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1820. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1821. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1822. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1823. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1824. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1825. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1826. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1827. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1828. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1829. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1830. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1831. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1832. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1833. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1834. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1835. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1836. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1837. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1838. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1839. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1840. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1841. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1842. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1843. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1844. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1845. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1846. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1847. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1849. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1850. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1851. (when org-agenda-mouse-1-follows-link
  1852. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1853. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1854. '("Agenda"
  1855. ("Agenda Files")
  1856. "--"
  1857. ("Agenda Dates"
  1858. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1859. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1860. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1861. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1862. "--"
  1863. ("View"
  1864. ["Day View" org-agenda-day-view
  1865. :active (org-agenda-check-type nil 'agenda)
  1866. :style radio :selected (eq org-agenda-current-span 'day)
  1867. :keys "v d (or just d)"]
  1868. ["Week View" org-agenda-week-view
  1869. :active (org-agenda-check-type nil 'agenda)
  1870. :style radio :selected (eq org-agenda-current-span 'week)
  1871. :keys "v w (or just w)"]
  1872. ["Month View" org-agenda-month-view
  1873. :active (org-agenda-check-type nil 'agenda)
  1874. :style radio :selected (eq org-agenda-current-span 'month)
  1875. :keys "v m"]
  1876. ["Year View" org-agenda-year-view
  1877. :active (org-agenda-check-type nil 'agenda)
  1878. :style radio :selected (eq org-agenda-current-span 'year)
  1879. :keys "v y"]
  1880. "--"
  1881. ["Include Diary" org-agenda-toggle-diary
  1882. :style toggle :selected org-agenda-include-diary
  1883. :active (org-agenda-check-type nil 'agenda)]
  1884. ["Include Deadlines" org-agenda-toggle-deadlines
  1885. :style toggle :selected org-agenda-include-deadlines
  1886. :active (org-agenda-check-type nil 'agenda)]
  1887. ["Use Time Grid" org-agenda-toggle-time-grid
  1888. :style toggle :selected org-agenda-use-time-grid
  1889. :active (org-agenda-check-type nil 'agenda)]
  1890. "--"
  1891. ["Show clock report" org-agenda-clockreport-mode
  1892. :style toggle :selected org-agenda-clockreport-mode
  1893. :active (org-agenda-check-type nil 'agenda)]
  1894. ["Show some entry text" org-agenda-entry-text-mode
  1895. :style toggle :selected org-agenda-entry-text-mode
  1896. :active t]
  1897. "--"
  1898. ["Show Logbook entries" org-agenda-log-mode
  1899. :style toggle :selected org-agenda-show-log
  1900. :active (org-agenda-check-type nil 'agenda 'timeline)
  1901. :keys "v l (or just l)"]
  1902. ["Include archived trees" org-agenda-archives-mode
  1903. :style toggle :selected org-agenda-archives-mode :active t
  1904. :keys "v a"]
  1905. ["Include archive files" (org-agenda-archives-mode t)
  1906. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1907. :keys "v A"]
  1908. "--"
  1909. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1910. ["Write view to file" org-agenda-write t]
  1911. ["Rebuild buffer" org-agenda-redo t]
  1912. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1913. "--"
  1914. ["Show original entry" org-agenda-show t]
  1915. ["Go To (other window)" org-agenda-goto t]
  1916. ["Go To (this window)" org-agenda-switch-to t]
  1917. ["Follow Mode" org-agenda-follow-mode
  1918. :style toggle :selected org-agenda-follow-mode :active t]
  1919. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1920. "--"
  1921. ("TODO"
  1922. ["Cycle TODO" org-agenda-todo t]
  1923. ["Next TODO set" org-agenda-todo-nextset t]
  1924. ["Previous TODO set" org-agenda-todo-previousset t]
  1925. ["Add note" org-agenda-add-note t])
  1926. ("Archive/Refile/Delete"
  1927. ["Archive default" org-agenda-archive-default t]
  1928. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1929. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1930. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1931. ["Archive subtree" org-agenda-archive t]
  1932. "--"
  1933. ["Refile" org-agenda-refile t]
  1934. "--"
  1935. ["Delete subtree" org-agenda-kill t])
  1936. ("Bulk action"
  1937. ["Mark entry" org-agenda-bulk-mark t]
  1938. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1939. ["Unmark entry" org-agenda-bulk-unmark t]
  1940. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1941. ["Act on all marked" org-agenda-bulk-action t]
  1942. "--"
  1943. ("Tags and Properties"
  1944. ["Show all Tags" org-agenda-show-tags t]
  1945. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1946. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1947. "--"
  1948. ["Column View" org-columns t])
  1949. ("Deadline/Schedule"
  1950. ["Schedule" org-agenda-schedule t]
  1951. ["Set Deadline" org-agenda-deadline t]
  1952. "--"
  1953. ["Mark item" org-agenda-action :active t :keys "k m"]
  1954. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1955. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1956. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1957. "--"
  1958. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1959. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1960. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1961. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1962. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1963. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1964. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1965. ("Clock and Effort"
  1966. ["Clock in" org-agenda-clock-in t]
  1967. ["Clock out" org-agenda-clock-out t]
  1968. ["Clock cancel" org-agenda-clock-cancel t]
  1969. ["Goto running clock" org-clock-goto t]
  1970. "--"
  1971. ["Set Effort" org-agenda-set-effort t]
  1972. ["Change clocked effort" org-clock-modify-effort-estimate
  1973. (org-clock-is-active)])
  1974. ("Priority"
  1975. ["Set Priority" org-agenda-priority t]
  1976. ["Increase Priority" org-agenda-priority-up t]
  1977. ["Decrease Priority" org-agenda-priority-down t]
  1978. ["Show Priority" org-agenda-show-priority t])
  1979. ("Calendar/Diary"
  1980. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1981. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1982. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1983. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1984. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1985. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1986. "--"
  1987. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1988. "--"
  1989. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1990. "--"
  1991. ("MobileOrg"
  1992. ["Push Files and Views" org-mobile-push t]
  1993. ["Get Captured and Flagged" org-mobile-pull t]
  1994. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1995. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1996. "--"
  1997. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1998. "--"
  1999. ["Quit" org-agenda-quit t]
  2000. ["Exit and Release Buffers" org-agenda-exit t]
  2001. ))
  2002. ;;; Agenda undo
  2003. (defvar org-agenda-allow-remote-undo t
  2004. "Non-nil means allow remote undo from the agenda buffer.")
  2005. (defvar org-agenda-undo-list nil
  2006. "List of undoable operations in the agenda since last refresh.")
  2007. (defvar org-agenda-undo-has-started-in nil
  2008. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2009. (defvar org-agenda-pending-undo-list nil
  2010. "In a series of undo commands, this is the list of remaining undo items.")
  2011. (defun org-agenda-undo ()
  2012. "Undo a remote editing step in the agenda.
  2013. This undoes changes both in the agenda buffer and in the remote buffer
  2014. that have been changed along."
  2015. (interactive)
  2016. (or org-agenda-allow-remote-undo
  2017. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2018. (if (not (eq this-command last-command))
  2019. (setq org-agenda-undo-has-started-in nil
  2020. org-agenda-pending-undo-list org-agenda-undo-list))
  2021. (if (not org-agenda-pending-undo-list)
  2022. (error "No further undo information"))
  2023. (let* ((entry (pop org-agenda-pending-undo-list))
  2024. buf line cmd rembuf)
  2025. (setq cmd (pop entry) line (pop entry))
  2026. (setq rembuf (nth 2 entry))
  2027. (org-with-remote-undo rembuf
  2028. (while (bufferp (setq buf (pop entry)))
  2029. (if (pop entry)
  2030. (with-current-buffer buf
  2031. (let ((last-undo-buffer buf)
  2032. (inhibit-read-only t))
  2033. (unless (memq buf org-agenda-undo-has-started-in)
  2034. (push buf org-agenda-undo-has-started-in)
  2035. (make-local-variable 'pending-undo-list)
  2036. (undo-start))
  2037. (while (and pending-undo-list
  2038. (listp pending-undo-list)
  2039. (not (car pending-undo-list)))
  2040. (pop pending-undo-list))
  2041. (undo-more 1))))))
  2042. (org-goto-line line)
  2043. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2044. (defun org-verify-change-for-undo (l1 l2)
  2045. "Verify that a real change occurred between the undo lists L1 and L2."
  2046. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2047. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2048. (not (eq l1 l2)))
  2049. ;;; Agenda dispatch
  2050. (defvar org-agenda-restrict nil)
  2051. (defvar org-agenda-restrict-begin (make-marker))
  2052. (defvar org-agenda-restrict-end (make-marker))
  2053. (defvar org-agenda-last-dispatch-buffer nil)
  2054. (defvar org-agenda-overriding-restriction nil)
  2055. ;;;###autoload
  2056. (defun org-agenda (&optional arg keys restriction)
  2057. "Dispatch agenda commands to collect entries to the agenda buffer.
  2058. Prompts for a command to execute. Any prefix arg will be passed
  2059. on to the selected command. The default selections are:
  2060. a Call `org-agenda-list' to display the agenda for current day or week.
  2061. t Call `org-todo-list' to display the global todo list.
  2062. T Call `org-todo-list' to display the global todo list, select only
  2063. entries with a specific TODO keyword (the user gets a prompt).
  2064. m Call `org-tags-view' to display headlines with tags matching
  2065. a condition (the user is prompted for the condition).
  2066. M Like `m', but select only TODO entries, no ordinary headlines.
  2067. L Create a timeline for the current buffer.
  2068. e Export views to associated files.
  2069. s Search entries for keywords.
  2070. / Multi occur across all agenda files and also files listed
  2071. in `org-agenda-text-search-extra-files'.
  2072. < Restrict agenda commands to buffer, subtree, or region.
  2073. Press several times to get the desired effect.
  2074. > Remove a previous restriction.
  2075. # List \"stuck\" projects.
  2076. ! Configure what \"stuck\" means.
  2077. C Configure custom agenda commands.
  2078. More commands can be added by configuring the variable
  2079. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2080. searches can be pre-defined in this way.
  2081. If the current buffer is in Org-mode and visiting a file, you can also
  2082. first press `<' once to indicate that the agenda should be temporarily
  2083. \(until the next use of \\[org-agenda]) restricted to the current file.
  2084. Pressing `<' twice means to restrict to the current subtree or region
  2085. \(if active)."
  2086. (interactive "P")
  2087. (catch 'exit
  2088. (let* ((prefix-descriptions nil)
  2089. (org-agenda-buffer-name org-agenda-buffer-name)
  2090. (org-agenda-window-setup (if (equal (buffer-name)
  2091. org-agenda-buffer-name)
  2092. 'current-window
  2093. org-agenda-window-setup))
  2094. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2095. (org-agenda-custom-commands
  2096. ;; normalize different versions
  2097. (delq nil
  2098. (mapcar
  2099. (lambda (x)
  2100. (cond ((stringp (cdr x))
  2101. (push x prefix-descriptions)
  2102. nil)
  2103. ((stringp (nth 1 x)) x)
  2104. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2105. (t (cons (car x) (cons "" (cdr x))))))
  2106. org-agenda-custom-commands)))
  2107. (buf (current-buffer))
  2108. (bfn (buffer-file-name (buffer-base-buffer)))
  2109. entry key type match lprops ans)
  2110. ;; Turn off restriction unless there is an overriding one,
  2111. (unless org-agenda-overriding-restriction
  2112. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2113. ;; There is a request to keep the file list in place
  2114. (put 'org-agenda-files 'org-restrict nil))
  2115. (setq org-agenda-restrict nil)
  2116. (move-marker org-agenda-restrict-begin nil)
  2117. (move-marker org-agenda-restrict-end nil))
  2118. ;; Delete old local properties
  2119. (put 'org-agenda-redo-command 'org-lprops nil)
  2120. ;; Delete previously set last-arguments
  2121. (put 'org-agenda-redo-command 'last-args nil)
  2122. ;; Remember where this call originated
  2123. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2124. (unless keys
  2125. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2126. keys (car ans)
  2127. restriction (cdr ans)))
  2128. ;; If we have sticky agenda buffers, set a name for the buffer,
  2129. ;; depending on the invoking keys. The user may still set this
  2130. ;; as a command option, which will overwrite what we do here.
  2131. (if org-agenda-sticky
  2132. (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
  2133. ;; Establish the restriction, if any
  2134. (when (and (not org-agenda-overriding-restriction) restriction)
  2135. (put 'org-agenda-files 'org-restrict (list bfn))
  2136. (cond
  2137. ((eq restriction 'region)
  2138. (setq org-agenda-restrict t)
  2139. (move-marker org-agenda-restrict-begin (region-beginning))
  2140. (move-marker org-agenda-restrict-end (region-end)))
  2141. ((eq restriction 'subtree)
  2142. (save-excursion
  2143. (setq org-agenda-restrict t)
  2144. (org-back-to-heading t)
  2145. (move-marker org-agenda-restrict-begin (point))
  2146. (move-marker org-agenda-restrict-end
  2147. (progn (org-end-of-subtree t)))))))
  2148. ;; For example the todo list should not need it (but does...)
  2149. (cond
  2150. ((setq entry (assoc keys org-agenda-custom-commands))
  2151. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2152. (progn
  2153. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2154. lprops (nth 4 entry))
  2155. (put 'org-agenda-redo-command 'org-lprops lprops)
  2156. (cond
  2157. ((eq type 'agenda)
  2158. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2159. ((eq type 'alltodo)
  2160. (org-let lprops '(org-todo-list current-prefix-arg)))
  2161. ((eq type 'search)
  2162. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2163. ((eq type 'stuck)
  2164. (org-let lprops '(org-agenda-list-stuck-projects
  2165. current-prefix-arg)))
  2166. ((eq type 'tags)
  2167. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2168. ((eq type 'tags-todo)
  2169. (org-let lprops '(org-tags-view '(4) match)))
  2170. ((eq type 'todo)
  2171. (org-let lprops '(org-todo-list match)))
  2172. ((eq type 'tags-tree)
  2173. (org-check-for-org-mode)
  2174. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2175. ((eq type 'todo-tree)
  2176. (org-check-for-org-mode)
  2177. (org-let lprops
  2178. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2179. (regexp-quote match) "\\>"))))
  2180. ((eq type 'occur-tree)
  2181. (org-check-for-org-mode)
  2182. (org-let lprops '(org-occur match)))
  2183. ((functionp type)
  2184. (org-let lprops '(funcall type match)))
  2185. ((fboundp type)
  2186. (org-let lprops '(funcall type match)))
  2187. (t (error "Invalid custom agenda command type %s" type))))
  2188. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2189. ((equal keys "C")
  2190. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2191. (customize-variable 'org-agenda-custom-commands))
  2192. ((equal keys "a") (call-interactively 'org-agenda-list))
  2193. ((equal keys "s") (call-interactively 'org-search-view))
  2194. ((equal keys "t") (call-interactively 'org-todo-list))
  2195. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2196. ((equal keys "m") (call-interactively 'org-tags-view))
  2197. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2198. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2199. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2200. (org-add-hook
  2201. 'post-command-hook
  2202. (lambda ()
  2203. (unless (current-message)
  2204. (let* ((m (org-agenda-get-any-marker))
  2205. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2206. (when note
  2207. (message (concat
  2208. "FLAGGING-NOTE ([?] for more info): "
  2209. (org-add-props
  2210. (replace-regexp-in-string
  2211. "\\\\n" "//"
  2212. (copy-sequence note))
  2213. nil 'face 'org-warning)))))))
  2214. t t))
  2215. ((equal keys "L")
  2216. (unless (eq major-mode 'org-mode)
  2217. (error "This is not an Org-mode file"))
  2218. (unless restriction
  2219. (put 'org-agenda-files 'org-restrict (list bfn))
  2220. (org-call-with-arg 'org-timeline arg)))
  2221. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2222. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2223. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2224. (t (error "Invalid agenda key"))))))
  2225. (defun org-agenda-append-agenda ()
  2226. "Append another agenda view to the current one.
  2227. This function allows interactive building of block agendas.
  2228. Agenda views are separated by `org-agenda-block-separator'."
  2229. (interactive)
  2230. (unless (string= (buffer-name) org-agenda-buffer-name)
  2231. (error "Can only append from within agenda buffer"))
  2232. (let ((org-agenda-multi t))
  2233. (org-agenda)
  2234. (widen)))
  2235. (defun org-agenda-normalize-custom-commands (cmds)
  2236. (delq nil
  2237. (mapcar
  2238. (lambda (x)
  2239. (cond ((stringp (cdr x)) nil)
  2240. ((stringp (nth 1 x)) x)
  2241. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2242. (t (cons (car x) (cons "" (cdr x))))))
  2243. cmds)))
  2244. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2245. "The user interface for selecting an agenda command."
  2246. (catch 'exit
  2247. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2248. (restrict-ok (and bfn (eq major-mode 'org-mode)))
  2249. (region-p (org-region-active-p))
  2250. (custom org-agenda-custom-commands)
  2251. (selstring "")
  2252. restriction second-time
  2253. c entry key type match prefixes rmheader header-end custom1 desc
  2254. line lines left right n n1)
  2255. (save-window-excursion
  2256. (delete-other-windows)
  2257. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2258. (erase-buffer)
  2259. (insert (eval-when-compile
  2260. (let ((header
  2261. "Press key for an agenda command: < Buffer, subtree/region restriction
  2262. -------------------------------- > Remove restriction
  2263. a Agenda for current week or day e Export agenda views
  2264. t List of all TODO entries T Entries with special TODO kwd
  2265. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2266. L Timeline for current buffer # List stuck projects (!=configure)
  2267. s Search for keywords * Toggle sticky agenda views
  2268. / Multi-occur ? Find :FLAGGED: entries
  2269. C Configure custom agenda commands
  2270. ")
  2271. (start 0))
  2272. (while (string-match
  2273. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2274. header start)
  2275. (setq start (match-end 0))
  2276. (add-text-properties (match-beginning 2) (match-end 2)
  2277. '(face bold) header))
  2278. header)))
  2279. (setq header-end (move-marker (make-marker) (point)))
  2280. (while t
  2281. (setq custom1 custom)
  2282. (when (eq rmheader t)
  2283. (org-goto-line 1)
  2284. (re-search-forward ":" nil t)
  2285. (delete-region (match-end 0) (point-at-eol))
  2286. (forward-char 1)
  2287. (looking-at "-+")
  2288. (delete-region (match-end 0) (point-at-eol))
  2289. (move-marker header-end (match-end 0)))
  2290. (goto-char header-end)
  2291. (delete-region (point) (point-max))
  2292. ;; Produce all the lines that describe custom commands and prefixes
  2293. (setq lines nil)
  2294. (while (setq entry (pop custom1))
  2295. (setq key (car entry) desc (nth 1 entry)
  2296. type (nth 2 entry)
  2297. match (nth 3 entry))
  2298. (if (> (length key) 1)
  2299. (add-to-list 'prefixes (string-to-char key))
  2300. (setq line
  2301. (format
  2302. "%-4s%-14s"
  2303. (org-add-props (copy-sequence key)
  2304. '(face bold))
  2305. (cond
  2306. ((string-match "\\S-" desc) desc)
  2307. ((eq type 'agenda) "Agenda for current week or day")
  2308. ((eq type 'alltodo) "List of all TODO entries")
  2309. ((eq type 'search) "Word search")
  2310. ((eq type 'stuck) "List of stuck projects")
  2311. ((eq type 'todo) "TODO keyword")
  2312. ((eq type 'tags) "Tags query")
  2313. ((eq type 'tags-todo) "Tags (TODO)")
  2314. ((eq type 'tags-tree) "Tags tree")
  2315. ((eq type 'todo-tree) "TODO kwd tree")
  2316. ((eq type 'occur-tree) "Occur tree")
  2317. ((functionp type) (if (symbolp type)
  2318. (symbol-name type)
  2319. "Lambda expression"))
  2320. (t "???"))))
  2321. (if org-agenda-menu-show-matcher
  2322. (setq line
  2323. (concat line ": "
  2324. (cond
  2325. ((stringp match)
  2326. (setq match (copy-sequence match))
  2327. (org-add-props match nil 'face 'org-warning))
  2328. (match
  2329. (format "set of %d commands" (length match)))
  2330. (t ""))))
  2331. (if (org-string-nw-p match)
  2332. (add-text-properties
  2333. 0 (length line) (list 'help-echo
  2334. (concat "Matcher: "match)) line)))
  2335. (push line lines)))
  2336. (setq lines (nreverse lines))
  2337. (when prefixes
  2338. (mapc (lambda (x)
  2339. (push
  2340. (format "%s %s"
  2341. (org-add-props (char-to-string x)
  2342. nil 'face 'bold)
  2343. (or (cdr (assoc (concat selstring
  2344. (char-to-string x))
  2345. prefix-descriptions))
  2346. "Prefix key"))
  2347. lines))
  2348. prefixes))
  2349. ;; Check if we should display in two columns
  2350. (if org-agenda-menu-two-column
  2351. (progn
  2352. (setq n (length lines)
  2353. n1 (+ (/ n 2) (mod n 2))
  2354. right (nthcdr n1 lines)
  2355. left (copy-sequence lines))
  2356. (setcdr (nthcdr (1- n1) left) nil))
  2357. (setq left lines right nil))
  2358. (while left
  2359. (insert "\n" (pop left))
  2360. (when right
  2361. (if (< (current-column) 40)
  2362. (move-to-column 40 t)
  2363. (insert " "))
  2364. (insert (pop right))))
  2365. ;; Make the window the right size
  2366. (goto-char (point-min))
  2367. (if second-time
  2368. (if (not (pos-visible-in-window-p (point-max)))
  2369. (org-fit-window-to-buffer))
  2370. (setq second-time t)
  2371. (org-fit-window-to-buffer))
  2372. ;; Ask for selection
  2373. (message "Press key for agenda command%s:"
  2374. (if (or restrict-ok org-agenda-overriding-restriction)
  2375. (if org-agenda-overriding-restriction
  2376. " (restriction lock active)"
  2377. (if restriction
  2378. (format " (restricted to %s)" restriction)
  2379. " (unrestricted)"))
  2380. ""))
  2381. (setq c (read-char-exclusive))
  2382. (message "")
  2383. (cond
  2384. ((assoc (char-to-string c) custom)
  2385. (setq selstring (concat selstring (char-to-string c)))
  2386. (throw 'exit (cons selstring restriction)))
  2387. ((memq c prefixes)
  2388. (setq selstring (concat selstring (char-to-string c))
  2389. prefixes nil
  2390. rmheader (or rmheader t)
  2391. custom (delq nil (mapcar
  2392. (lambda (x)
  2393. (if (or (= (length (car x)) 1)
  2394. (/= (string-to-char (car x)) c))
  2395. nil
  2396. (cons (substring (car x) 1) (cdr x))))
  2397. custom))))
  2398. ((eq c ?*)
  2399. (org-toggle-sticky-agenda)
  2400. (sit-for 2))
  2401. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2402. (message "Restriction is only possible in Org-mode buffers")
  2403. (ding) (sit-for 1))
  2404. ((eq c ?1)
  2405. (org-agenda-remove-restriction-lock 'noupdate)
  2406. (setq restriction 'buffer))
  2407. ((eq c ?0)
  2408. (org-agenda-remove-restriction-lock 'noupdate)
  2409. (setq restriction (if region-p 'region 'subtree)))
  2410. ((eq c ?<)
  2411. (org-agenda-remove-restriction-lock 'noupdate)
  2412. (setq restriction
  2413. (cond
  2414. ((eq restriction 'buffer)
  2415. (if region-p 'region 'subtree))
  2416. ((memq restriction '(subtree region))
  2417. nil)
  2418. (t 'buffer))))
  2419. ((eq c ?>)
  2420. (org-agenda-remove-restriction-lock 'noupdate)
  2421. (setq restriction nil))
  2422. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2423. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2424. ((and (> (length selstring) 0) (eq c ?\d))
  2425. (delete-window)
  2426. (org-agenda-get-restriction-and-command prefix-descriptions))
  2427. ((equal c ?q) (error "Abort"))
  2428. (t (error "Invalid key %c" c))))))))
  2429. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2430. (defvar org-agenda-last-arguments nil
  2431. "The arguments of the previous call to `org-agenda'.")
  2432. (defun org-agenda-run-series (name series)
  2433. (org-let (nth 1 series) '(org-prepare-agenda name))
  2434. ;; We need to reset agenda markers here, because when constructing a
  2435. ;; block agenda, the individual blocks do not do that.
  2436. (org-agenda-reset-markers)
  2437. (let* ((org-agenda-multi t)
  2438. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2439. (org-agenda-overriding-arguments
  2440. (or org-agenda-overriding-arguments
  2441. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2442. (get 'org-agenda-redo-command 'last-args))))
  2443. (cmds (car series))
  2444. (gprops (nth 1 series))
  2445. match ;; The byte compiler incorrectly complains about this. Keep it!
  2446. cmd type lprops)
  2447. (while (setq cmd (pop cmds))
  2448. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2449. (cond
  2450. ((eq type 'agenda)
  2451. (org-let2 gprops lprops
  2452. '(call-interactively 'org-agenda-list)))
  2453. ((eq type 'alltodo)
  2454. (org-let2 gprops lprops
  2455. '(call-interactively 'org-todo-list)))
  2456. ((eq type 'search)
  2457. (org-let2 gprops lprops
  2458. '(org-search-view current-prefix-arg match nil)))
  2459. ((eq type 'stuck)
  2460. (org-let2 gprops lprops
  2461. '(call-interactively 'org-agenda-list-stuck-projects)))
  2462. ((eq type 'tags)
  2463. (org-let2 gprops lprops
  2464. '(org-tags-view current-prefix-arg match)))
  2465. ((eq type 'tags-todo)
  2466. (org-let2 gprops lprops
  2467. '(org-tags-view '(4) match)))
  2468. ((eq type 'todo)
  2469. (org-let2 gprops lprops
  2470. '(org-todo-list match)))
  2471. ((fboundp type)
  2472. (org-let2 gprops lprops
  2473. '(funcall type match)))
  2474. (t (error "Invalid type in command series"))))
  2475. (widen)
  2476. (setq org-agenda-redo-command redo)
  2477. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2478. (goto-char (point-min)))
  2479. (org-fit-agenda-window)
  2480. (org-let (nth 1 series) '(org-finalize-agenda)))
  2481. ;;;###autoload
  2482. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2483. "Run an agenda command in batch mode and send the result to STDOUT.
  2484. If CMD-KEY is a string of length 1, it is used as a key in
  2485. `org-agenda-custom-commands' and triggers this command. If it is a
  2486. longer string it is used as a tags/todo match string.
  2487. Parameters are alternating variable names and values that will be bound
  2488. before running the agenda command."
  2489. (org-eval-in-environment (org-make-parameter-alist parameters)
  2490. (if (> (length cmd-key) 2)
  2491. (org-tags-view nil cmd-key)
  2492. (org-agenda nil cmd-key)))
  2493. (set-buffer org-agenda-buffer-name)
  2494. (princ (buffer-string)))
  2495. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2496. (defvar org-agenda-info nil)
  2497. ;;;###autoload
  2498. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2499. "Run an agenda command in batch mode and send the result to STDOUT.
  2500. If CMD-KEY is a string of length 1, it is used as a key in
  2501. `org-agenda-custom-commands' and triggers this command. If it is a
  2502. longer string it is used as a tags/todo match string.
  2503. Parameters are alternating variable names and values that will be bound
  2504. before running the agenda command.
  2505. The output gives a line for each selected agenda item. Each
  2506. item is a list of comma-separated values, like this:
  2507. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2508. category The category of the item
  2509. head The headline, without TODO kwd, TAGS and PRIORITY
  2510. type The type of the agenda entry, can be
  2511. todo selected in TODO match
  2512. tagsmatch selected in tags match
  2513. diary imported from diary
  2514. deadline a deadline on given date
  2515. scheduled scheduled on given date
  2516. timestamp entry has timestamp on given date
  2517. closed entry was closed on given date
  2518. upcoming-deadline warning about deadline
  2519. past-scheduled forwarded scheduled item
  2520. block entry has date block including g. date
  2521. todo The todo keyword, if any
  2522. tags All tags including inherited ones, separated by colons
  2523. date The relevant date, like 2007-2-14
  2524. time The time, like 15:00-16:50
  2525. extra Sting with extra planning info
  2526. priority-l The priority letter if any was given
  2527. priority-n The computed numerical priority
  2528. agenda-day The day in the agenda where this is listed"
  2529. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2530. (org-make-parameter-alist parameters))
  2531. (if (> (length cmd-key) 2)
  2532. (org-tags-view nil cmd-key)
  2533. (org-agenda nil cmd-key)))
  2534. (set-buffer org-agenda-buffer-name)
  2535. (let* ((lines (org-split-string (buffer-string) "\n"))
  2536. line)
  2537. (while (setq line (pop lines))
  2538. (catch 'next
  2539. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2540. (setq org-agenda-info
  2541. (org-fix-agenda-info (text-properties-at 0 line)))
  2542. (princ
  2543. (mapconcat 'org-agenda-export-csv-mapper
  2544. '(org-category txt type todo tags date time extra
  2545. priority-letter priority agenda-day)
  2546. ","))
  2547. (princ "\n")))))
  2548. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2549. (defun org-fix-agenda-info (props)
  2550. "Make sure all properties on an agenda item have a canonical form.
  2551. This ensures the export commands can easily use it."
  2552. (let (tmp re)
  2553. (when (setq tmp (plist-get props 'tags))
  2554. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2555. (when (setq tmp (plist-get props 'date))
  2556. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2557. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2558. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2559. (setq tmp (calendar-date-string tmp)))
  2560. (setq props (plist-put props 'date tmp)))
  2561. (when (setq tmp (plist-get props 'day))
  2562. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2563. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2564. (setq tmp (calendar-date-string tmp)))
  2565. (setq props (plist-put props 'day tmp))
  2566. (setq props (plist-put props 'agenda-day tmp)))
  2567. (when (setq tmp (plist-get props 'txt))
  2568. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2569. (plist-put props 'priority-letter (match-string 1 tmp))
  2570. (setq tmp (replace-match "" t t tmp)))
  2571. (when (and (setq re (plist-get props 'org-todo-regexp))
  2572. (setq re (concat "\\`\\.*" re " ?"))
  2573. (string-match re tmp))
  2574. (plist-put props 'todo (match-string 1 tmp))
  2575. (setq tmp (replace-match "" t t tmp)))
  2576. (plist-put props 'txt tmp)))
  2577. props)
  2578. (defun org-agenda-export-csv-mapper (prop)
  2579. (let ((res (plist-get org-agenda-info prop)))
  2580. (setq res
  2581. (cond
  2582. ((not res) "")
  2583. ((stringp res) res)
  2584. (t (prin1-to-string res))))
  2585. (while (string-match "," res)
  2586. (setq res (replace-match ";" t t res)))
  2587. (org-trim res)))
  2588. ;;;###autoload
  2589. (defun org-store-agenda-views (&rest parameters)
  2590. (interactive)
  2591. (eval (list 'org-batch-store-agenda-views)))
  2592. ;;;###autoload
  2593. (defmacro org-batch-store-agenda-views (&rest parameters)
  2594. "Run all custom agenda commands that have a file argument."
  2595. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2596. (pop-up-frames nil)
  2597. (dir default-directory)
  2598. (pars (org-make-parameter-alist parameters))
  2599. cmd thiscmdkey files opts cmd-or-set)
  2600. (save-window-excursion
  2601. (while cmds
  2602. (setq cmd (pop cmds)
  2603. thiscmdkey (car cmd)
  2604. cmd-or-set (nth 2 cmd)
  2605. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2606. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2607. (if (stringp files) (setq files (list files)))
  2608. (when files
  2609. (org-eval-in-environment (append org-agenda-exporter-settings
  2610. opts pars)
  2611. (org-agenda nil thiscmdkey))
  2612. (set-buffer org-agenda-buffer-name)
  2613. (while files
  2614. (org-eval-in-environment (append org-agenda-exporter-settings
  2615. opts pars)
  2616. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2617. (and (get-buffer org-agenda-buffer-name)
  2618. (kill-buffer org-agenda-buffer-name)))))))
  2619. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2620. (defun org-agenda-mark-header-line (pos)
  2621. "Mark the line at POS as an agenda structure header."
  2622. (save-excursion
  2623. (goto-char pos)
  2624. (put-text-property (point-at-bol) (point-at-eol)
  2625. 'org-agenda-structural-header t)
  2626. (when org-agenda-title-append
  2627. (put-text-property (point-at-bol) (point-at-eol)
  2628. 'org-agenda-title-append org-agenda-title-append))))
  2629. (defvar org-mobile-creating-agendas)
  2630. (defvar org-agenda-write-buffer-name "Agenda View")
  2631. (defun org-agenda-write (file &optional open nosettings)
  2632. "Write the current buffer (an agenda view) as a file.
  2633. Depending on the extension of the file name, plain text (.txt),
  2634. HTML (.html or .htm) or Postscript (.ps) is produced.
  2635. If the extension is .ics, run icalendar export over all files used
  2636. to construct the agenda and limit the export to entries listed in the
  2637. agenda now.
  2638. With prefix argument OPEN, open the new file immediately.
  2639. If NOSETTINGS is given, do not scope the settings of
  2640. `org-agenda-exporter-settings' into the export commands. This is used when
  2641. the settings have already been scoped and we do not wish to overrule other,
  2642. higher priority settings."
  2643. (interactive "FWrite agenda to file: \nP")
  2644. (if (not (file-writable-p file))
  2645. (error "Cannot write agenda to file %s" file))
  2646. (org-let (if nosettings nil org-agenda-exporter-settings)
  2647. '(save-excursion
  2648. (save-window-excursion
  2649. (org-agenda-mark-filtered-text)
  2650. (let ((bs (copy-sequence (buffer-string))) beg)
  2651. (org-agenda-unmark-filtered-text)
  2652. (with-temp-buffer
  2653. (rename-buffer org-agenda-write-buffer-name t)
  2654. (set-buffer-modified-p nil)
  2655. (insert bs)
  2656. (org-agenda-remove-marked-text 'org-filtered)
  2657. (while (setq beg (text-property-any (point-min) (point-max)
  2658. 'org-filtered t))
  2659. (delete-region
  2660. beg (or (next-single-property-change beg 'org-filtered)
  2661. (point-max))))
  2662. (run-hooks 'org-agenda-before-write-hook)
  2663. (cond
  2664. ((org-bound-and-true-p org-mobile-creating-agendas)
  2665. (org-mobile-write-agenda-for-mobile file))
  2666. ((string-match "\\.html?\\'" file)
  2667. (require 'htmlize)
  2668. (set-buffer (htmlize-buffer (current-buffer)))
  2669. (when (and org-agenda-export-html-style
  2670. (string-match "<style>" org-agenda-export-html-style))
  2671. ;; replace <style> section with org-agenda-export-html-style
  2672. (goto-char (point-min))
  2673. (kill-region (- (search-forward "<style") 6)
  2674. (search-forward "</style>"))
  2675. (insert org-agenda-export-html-style))
  2676. (write-file file)
  2677. (kill-buffer (current-buffer))
  2678. (message "HTML written to %s" file))
  2679. ((string-match "\\.ps\\'" file)
  2680. (require 'ps-print)
  2681. (ps-print-buffer-with-faces file)
  2682. (message "Postscript written to %s" file))
  2683. ((string-match "\\.pdf\\'" file)
  2684. (require 'ps-print)
  2685. (ps-print-buffer-with-faces
  2686. (concat (file-name-sans-extension file) ".ps"))
  2687. (call-process "ps2pdf" nil nil nil
  2688. (expand-file-name
  2689. (concat (file-name-sans-extension file) ".ps"))
  2690. (expand-file-name file))
  2691. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2692. (message "PDF written to %s" file))
  2693. ((string-match "\\.ics\\'" file)
  2694. (require 'org-icalendar)
  2695. (let ((org-agenda-marker-table
  2696. (org-create-marker-find-array
  2697. (org-agenda-collect-markers)))
  2698. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2699. (org-combined-agenda-icalendar-file file))
  2700. (apply 'org-export-icalendar 'combine
  2701. (org-agenda-files nil 'ifmode))))
  2702. (t
  2703. (let ((bs (buffer-string)))
  2704. (find-file file)
  2705. (erase-buffer)
  2706. (insert bs)
  2707. (save-buffer 0)
  2708. (kill-buffer (current-buffer))
  2709. (message "Plain text written to %s" file))))))))
  2710. (set-buffer org-agenda-buffer-name))
  2711. (when open (org-open-file file)))
  2712. (defvar org-agenda-tag-filter-overlays nil)
  2713. (defvar org-agenda-cat-filter-overlays nil)
  2714. (defun org-agenda-mark-filtered-text ()
  2715. "Mark all text hidden by filtering with a text property."
  2716. (let ((inhibit-read-only t))
  2717. (mapc
  2718. (lambda (o)
  2719. (when (equal (overlay-buffer o) (current-buffer))
  2720. (put-text-property
  2721. (overlay-start o) (overlay-end o)
  2722. 'org-filtered t)))
  2723. (append org-agenda-tag-filter-overlays
  2724. org-agenda-cat-filter-overlays))))
  2725. (defun org-agenda-unmark-filtered-text ()
  2726. "Remove the filtering text property."
  2727. (let ((inhibit-read-only t))
  2728. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2729. (defun org-agenda-remove-marked-text (property &optional value)
  2730. "Delete all text marked with VALUE of PROPERTY.
  2731. VALUE defaults to t."
  2732. (let (beg)
  2733. (setq value (or value t))
  2734. (while (setq beg (text-property-any (point-min) (point-max)
  2735. property value))
  2736. (delete-region
  2737. beg (or (next-single-property-change beg 'org-filtered)
  2738. (point-max))))))
  2739. (defun org-agenda-add-entry-text ()
  2740. "Add entry text to agenda lines.
  2741. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2742. entry text following headings shown in the agenda.
  2743. Drawers will be excluded, also the line with scheduling/deadline info."
  2744. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2745. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2746. (let (m txt)
  2747. (goto-char (point-min))
  2748. (while (not (eobp))
  2749. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2750. (beginning-of-line 2)
  2751. (setq txt (org-agenda-get-some-entry-text
  2752. m org-agenda-add-entry-text-maxlines " > "))
  2753. (end-of-line 1)
  2754. (if (string-match "\\S-" txt)
  2755. (insert "\n" txt)
  2756. (or (eobp) (forward-char 1))))))))
  2757. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2758. &rest keep)
  2759. "Extract entry text from MARKER, at most N-LINES lines.
  2760. This will ignore drawers etc, just get the text.
  2761. If INDENT is given, prefix every line with this string. If KEEP is
  2762. given, it is a list of symbols, defining stuff that should not be
  2763. removed from the entry content. Currently only `planning' is allowed here."
  2764. (let (txt drawer-re kwd-time-re ind)
  2765. (save-excursion
  2766. (with-current-buffer (marker-buffer marker)
  2767. (if (not (eq major-mode 'org-mode))
  2768. (setq txt "")
  2769. (save-excursion
  2770. (save-restriction
  2771. (widen)
  2772. (goto-char marker)
  2773. (end-of-line 1)
  2774. (setq txt (buffer-substring
  2775. (min (1+ (point)) (point-max))
  2776. (progn (outline-next-heading) (point)))
  2777. drawer-re org-drawer-regexp
  2778. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2779. ".*\n?"))
  2780. (with-temp-buffer
  2781. (insert txt)
  2782. (when org-agenda-add-entry-text-descriptive-links
  2783. (goto-char (point-min))
  2784. (while (org-activate-bracket-links (point-max))
  2785. (add-text-properties (match-beginning 0) (match-end 0)
  2786. '(face org-link))))
  2787. (goto-char (point-min))
  2788. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2789. (set-text-properties (match-beginning 0) (match-end 0)
  2790. nil))
  2791. (goto-char (point-min))
  2792. (while (re-search-forward drawer-re nil t)
  2793. (delete-region
  2794. (match-beginning 0)
  2795. (progn (re-search-forward
  2796. "^[ \t]*:END:.*\n?" nil 'move)
  2797. (point))))
  2798. (unless (member 'planning keep)
  2799. (goto-char (point-min))
  2800. (while (re-search-forward kwd-time-re nil t)
  2801. (replace-match "")))
  2802. (goto-char (point-min))
  2803. (when org-agenda-entry-text-exclude-regexps
  2804. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2805. (while (setq re (pop re-list))
  2806. (goto-char (point-min))
  2807. (while (re-search-forward re nil t)
  2808. (replace-match "")))))
  2809. (goto-char (point-max))
  2810. (skip-chars-backward " \t\n")
  2811. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2812. ;; find and remove min common indentation
  2813. (goto-char (point-min))
  2814. (untabify (point-min) (point-max))
  2815. (setq ind (org-get-indentation))
  2816. (while (not (eobp))
  2817. (unless (looking-at "[ \t]*$")
  2818. (setq ind (min ind (org-get-indentation))))
  2819. (beginning-of-line 2))
  2820. (goto-char (point-min))
  2821. (while (not (eobp))
  2822. (unless (looking-at "[ \t]*$")
  2823. (move-to-column ind)
  2824. (delete-region (point-at-bol) (point)))
  2825. (beginning-of-line 2))
  2826. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2827. (goto-char (point-min))
  2828. (when indent
  2829. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2830. (replace-match indent t t)))
  2831. (goto-char (point-min))
  2832. (while (looking-at "[ \t]*\n") (replace-match ""))
  2833. (goto-char (point-max))
  2834. (when (> (org-current-line)
  2835. n-lines)
  2836. (org-goto-line (1+ n-lines))
  2837. (backward-char 1))
  2838. (setq txt (buffer-substring (point-min) (point)))))))))
  2839. txt))
  2840. (defun org-agenda-collect-markers ()
  2841. "Collect the markers pointing to entries in the agenda buffer."
  2842. (let (m markers)
  2843. (save-excursion
  2844. (goto-char (point-min))
  2845. (while (not (eobp))
  2846. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2847. (org-get-at-bol 'org-marker)))
  2848. (push m markers))
  2849. (beginning-of-line 2)))
  2850. (nreverse markers)))
  2851. (defun org-create-marker-find-array (marker-list)
  2852. "Create a alist of files names with all marker positions in that file."
  2853. (let (f tbl m a p)
  2854. (while (setq m (pop marker-list))
  2855. (setq p (marker-position m)
  2856. f (buffer-file-name (or (buffer-base-buffer
  2857. (marker-buffer m))
  2858. (marker-buffer m))))
  2859. (if (setq a (assoc f tbl))
  2860. (push (marker-position m) (cdr a))
  2861. (push (list f p) tbl)))
  2862. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2863. tbl)))
  2864. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2865. (defun org-check-agenda-marker-table ()
  2866. "Check of the current entry is on the marker list."
  2867. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2868. a)
  2869. (and (setq a (assoc file org-agenda-marker-table))
  2870. (save-match-data
  2871. (save-excursion
  2872. (org-back-to-heading t)
  2873. (member (point) (cdr a)))))))
  2874. (defun org-check-for-org-mode ()
  2875. "Make sure current buffer is in org-mode. Error if not."
  2876. (or (eq major-mode 'org-mode)
  2877. (error "Cannot execute org-mode agenda command on buffer in %s"
  2878. major-mode)))
  2879. (defun org-fit-agenda-window ()
  2880. "Fit the window to the buffer size."
  2881. (and (memq org-agenda-window-setup '(reorganize-frame))
  2882. (fboundp 'fit-window-to-buffer)
  2883. (org-fit-window-to-buffer
  2884. nil
  2885. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2886. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2887. ;;; Agenda prepare and finalize
  2888. (defvar org-agenda-multi nil) ; dynamically scoped
  2889. (defvar org-agenda-buffer-name "*Org Agenda*")
  2890. (defvar org-pre-agenda-window-conf nil)
  2891. (defvar org-agenda-columns-active nil)
  2892. (defvar org-agenda-name nil)
  2893. (defvar org-agenda-tag-filter nil)
  2894. (defvar org-agenda-category-filter nil)
  2895. (defvar org-agenda-tag-filter-while-redo nil)
  2896. (defvar org-agenda-tag-filter-preset nil
  2897. "A preset of the tags filter used for secondary agenda filtering.
  2898. This must be a list of strings, each string must be a single tag preceded
  2899. by \"+\" or \"-\".
  2900. This variable should not be set directly, but agenda custom commands can
  2901. bind it in the options section. The preset filter is a global property of
  2902. the entire agenda view. In a block agenda, it will not work reliably to
  2903. define a filter for one of the individual blocks. You need to set it in
  2904. the global options and expect it to be applied to the entire view.")
  2905. (defvar org-agenda-category-filter-preset nil
  2906. "A preset of the category filter used for secondary agenda filtering.
  2907. This must be a list of strings, each string must be a single category
  2908. preceded by \"+\" or \"-\".
  2909. This variable should not be set directly, but agenda custom commands can
  2910. bind it in the options section. The preset filter is a global property of
  2911. the entire agenda view. In a block agenda, it will not work reliably to
  2912. define a filter for one of the individual blocks. You need to set it in
  2913. the global options and expect it to be applied to the entire view.")
  2914. (defun org-agenda-use-sticky-p ()
  2915. "Return non-NIL if existing agenda buffer named
  2916. `org-agenda-buffer-name' exists, and should be shown instead of
  2917. generating a new one"
  2918. (and
  2919. ;; turned off by user
  2920. org-agenda-sticky
  2921. ;; For multi-agenda buffer already exists
  2922. (not org-agenda-multi)
  2923. ;; buffer found
  2924. (get-buffer org-agenda-buffer-name)
  2925. ;; C-u parameter is same as last call
  2926. (with-current-buffer (get-buffer org-agenda-buffer-name)
  2927. (and
  2928. (equal current-prefix-arg
  2929. org-agenda-last-prefix-arg)
  2930. ;; In case user turned stickiness on, while having existing
  2931. ;; Agenda buffer active, don't reuse that buffer, because it
  2932. ;; does not have org variables local
  2933. org-agenda-this-buffer-is-sticky))))
  2934. (defun org-prepare-agenda-window (abuf)
  2935. "Setup agenda buffer in the window"
  2936. (let* ((awin (get-buffer-window abuf))
  2937. wconf)
  2938. (cond
  2939. ((equal (current-buffer) abuf) nil)
  2940. (awin (select-window awin))
  2941. ((not (setq wconf (current-window-configuration))))
  2942. ((equal org-agenda-window-setup 'current-window)
  2943. (org-pop-to-buffer-same-window abuf))
  2944. ((equal org-agenda-window-setup 'other-window)
  2945. (org-switch-to-buffer-other-window abuf))
  2946. ((equal org-agenda-window-setup 'other-frame)
  2947. (switch-to-buffer-other-frame abuf))
  2948. ((equal org-agenda-window-setup 'reorganize-frame)
  2949. (delete-other-windows)
  2950. (org-switch-to-buffer-other-window abuf)))
  2951. ;; additional test in case agenda is invoked from within agenda
  2952. ;; buffer via elisp link
  2953. (unless (equal (current-buffer) abuf)
  2954. (org-pop-to-buffer-same-window abuf))
  2955. (setq org-pre-agenda-window-conf wconf)))
  2956. (defun org-prepare-agenda (&optional name)
  2957. (if (org-agenda-use-sticky-p)
  2958. (progn
  2959. ;; Popup existing buffer
  2960. (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
  2961. (message "Sticky Agenda buffer, use `r' to refresh")
  2962. (throw 'exit nil))
  2963. (setq org-todo-keywords-for-agenda nil)
  2964. (setq org-drawers-for-agenda nil)
  2965. (unless org-agenda-persistent-filter
  2966. (setq org-agenda-tag-filter nil
  2967. org-agenda-category-filter nil))
  2968. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2969. (put 'org-agenda-category-filter :preset-filter
  2970. org-agenda-category-filter-preset)
  2971. (if org-agenda-multi
  2972. (progn
  2973. (setq buffer-read-only nil)
  2974. (goto-char (point-max))
  2975. (unless (or (bobp) org-agenda-compact-blocks
  2976. (not org-agenda-block-separator))
  2977. (insert "\n"
  2978. (if (stringp org-agenda-block-separator)
  2979. org-agenda-block-separator
  2980. (make-string (window-width) org-agenda-block-separator))
  2981. "\n"))
  2982. (narrow-to-region (point) (point-max)))
  2983. (setq org-done-keywords-for-agenda nil)
  2984. ;; Setting any org variables that are in org-agenda-local-vars
  2985. ;; list need to be done after the prepare call
  2986. (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
  2987. (setq buffer-read-only nil)
  2988. (org-agenda-reset-markers)
  2989. (let ((inhibit-read-only t)) (erase-buffer))
  2990. (org-agenda-mode)
  2991. (setq org-agenda-buffer (current-buffer))
  2992. (setq org-agenda-contributing-files nil)
  2993. (setq org-agenda-columns-active nil)
  2994. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2995. (setq org-todo-keywords-for-agenda
  2996. (org-uniquify org-todo-keywords-for-agenda))
  2997. (setq org-done-keywords-for-agenda
  2998. (org-uniquify org-done-keywords-for-agenda))
  2999. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3000. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3001. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3002. (and name (not org-agenda-name)
  3003. (org-set-local 'org-agenda-name name)))
  3004. (setq buffer-read-only nil)))
  3005. (defun org-finalize-agenda ()
  3006. "Finishing touch for the agenda buffer, called just before displaying it."
  3007. (unless org-agenda-multi
  3008. (save-excursion
  3009. (let ((inhibit-read-only t))
  3010. (goto-char (point-min))
  3011. (while (org-activate-bracket-links (point-max))
  3012. (add-text-properties (match-beginning 0) (match-end 0)
  3013. '(face org-link)))
  3014. (org-agenda-align-tags)
  3015. (unless org-agenda-with-colors
  3016. (remove-text-properties (point-min) (point-max) '(face nil))))
  3017. (if (and (boundp 'org-agenda-overriding-columns-format)
  3018. org-agenda-overriding-columns-format)
  3019. (org-set-local 'org-agenda-overriding-columns-format
  3020. org-agenda-overriding-columns-format))
  3021. (if (and (boundp 'org-agenda-view-columns-initially)
  3022. org-agenda-view-columns-initially)
  3023. (org-agenda-columns))
  3024. (when org-agenda-fontify-priorities
  3025. (org-agenda-fontify-priorities))
  3026. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3027. (org-agenda-dim-blocked-tasks))
  3028. (org-agenda-mark-clocking-task)
  3029. (when org-agenda-entry-text-mode
  3030. (org-agenda-entry-text-hide)
  3031. (org-agenda-entry-text-show))
  3032. (if (functionp 'org-habit-insert-consistency-graphs)
  3033. (org-habit-insert-consistency-graphs))
  3034. (run-hooks 'org-finalize-agenda-hook)
  3035. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3036. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3037. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3038. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3039. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3040. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3041. )))
  3042. (defun org-agenda-mark-clocking-task ()
  3043. "Mark the current clock entry in the agenda if it is present."
  3044. (mapc (lambda (o)
  3045. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3046. (delete-overlay o)))
  3047. (overlays-in (point-min) (point-max)))
  3048. (when (marker-buffer org-clock-hd-marker)
  3049. (save-excursion
  3050. (goto-char (point-min))
  3051. (let (s ov)
  3052. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3053. (goto-char s)
  3054. (when (equal (org-get-at-bol 'org-hd-marker)
  3055. org-clock-hd-marker)
  3056. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3057. (overlay-put ov 'type 'org-agenda-clocking)
  3058. (overlay-put ov 'face 'org-agenda-clocking)
  3059. (overlay-put ov 'help-echo
  3060. "The clock is running in this item")))))))
  3061. (defun org-agenda-fontify-priorities ()
  3062. "Make highest priority lines bold, and lowest italic."
  3063. (interactive)
  3064. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3065. (delete-overlay o)))
  3066. (overlays-in (point-min) (point-max)))
  3067. (save-excursion
  3068. (let ((inhibit-read-only t)
  3069. b e p ov h l)
  3070. (goto-char (point-min))
  3071. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3072. (setq h (or (get-char-property (point) 'org-highest-priority)
  3073. org-highest-priority)
  3074. l (or (get-char-property (point) 'org-lowest-priority)
  3075. org-lowest-priority)
  3076. p (string-to-char (match-string 1))
  3077. b (match-beginning 0)
  3078. e (if (eq org-agenda-fontify-priorities 'cookies)
  3079. (match-end 0)
  3080. (point-at-eol))
  3081. ov (make-overlay b e))
  3082. (overlay-put
  3083. ov 'face
  3084. (cond ((org-face-from-face-or-color
  3085. 'priority nil
  3086. (cdr (assoc p org-priority-faces))))
  3087. ((and (listp org-agenda-fontify-priorities)
  3088. (org-face-from-face-or-color
  3089. 'priority nil
  3090. (cdr (assoc p org-agenda-fontify-priorities)))))
  3091. ((equal p l) 'italic)
  3092. ((equal p h) 'bold)))
  3093. (overlay-put ov 'org-type 'org-priority)))))
  3094. (defun org-agenda-dim-blocked-tasks ()
  3095. "Dim currently blocked TODO's in the agenda display."
  3096. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3097. (delete-overlay o)))
  3098. (overlays-in (point-min) (point-max)))
  3099. (save-excursion
  3100. (let ((inhibit-read-only t)
  3101. (org-depend-tag-blocked nil)
  3102. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3103. org-blocked-by-checkboxes
  3104. invis1 b e p ov h l)
  3105. (goto-char (point-min))
  3106. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3107. (and pos (goto-char (1+ pos))))
  3108. (setq org-blocked-by-checkboxes nil invis1 invis)
  3109. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3110. (when (and marker
  3111. (with-current-buffer (marker-buffer marker)
  3112. (save-excursion (goto-char marker)
  3113. (org-entry-blocked-p))))
  3114. (if org-blocked-by-checkboxes (setq invis1 nil))
  3115. (setq b (if invis1
  3116. (max (point-min) (1- (point-at-bol)))
  3117. (point-at-bol))
  3118. e (point-at-eol)
  3119. ov (make-overlay b e))
  3120. (if invis1
  3121. (overlay-put ov 'invisible t)
  3122. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3123. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3124. (defvar org-agenda-skip-function nil
  3125. "Function to be called at each match during agenda construction.
  3126. If this function returns nil, the current match should not be skipped.
  3127. Otherwise, the function must return a position from where the search
  3128. should be continued.
  3129. This may also be a Lisp form, it will be evaluated.
  3130. Never set this variable using `setq' or so, because then it will apply
  3131. to all future agenda commands. If you do want a global skipping condition,
  3132. use the option `org-agenda-skip-function-global' instead.
  3133. The correct usage for `org-agenda-skip-function' is to bind it with
  3134. `let' to scope it dynamically into the agenda-constructing command.
  3135. A good way to set it is through options in `org-agenda-custom-commands'.")
  3136. (defun org-agenda-skip ()
  3137. "Throw to `:skip' in places that should be skipped.
  3138. Also moves point to the end of the skipped region, so that search can
  3139. continue from there."
  3140. (let ((p (point-at-bol)) to)
  3141. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3142. (get-text-property p :org-archived)
  3143. (org-end-of-subtree t)
  3144. (throw :skip t))
  3145. (and org-agenda-skip-comment-trees
  3146. (get-text-property p :org-comment)
  3147. (org-end-of-subtree t)
  3148. (throw :skip t))
  3149. (if (equal (char-after p) ?#) (throw :skip t))
  3150. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3151. (org-agenda-skip-eval org-agenda-skip-function)))
  3152. (goto-char to)
  3153. (throw :skip t))))
  3154. (defun org-agenda-skip-eval (form)
  3155. "If FORM is a function or a list, call (or eval) is and return result.
  3156. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3157. and match data are returned to the previous state no matter what these
  3158. functions do."
  3159. (let (fp)
  3160. (and form
  3161. (or (setq fp (functionp form))
  3162. (consp form))
  3163. (save-excursion
  3164. (save-match-data
  3165. (if fp
  3166. (funcall form)
  3167. (eval form)))))))
  3168. (defvar org-agenda-markers nil
  3169. "List of all currently active markers created by `org-agenda'.")
  3170. (defvar org-agenda-last-marker-time (org-float-time)
  3171. "Creation time of the last agenda marker.")
  3172. (defun org-agenda-new-marker (&optional pos)
  3173. "Return a new agenda marker.
  3174. Org-mode keeps a list of these markers and resets them when they are
  3175. no longer in use."
  3176. (let ((m (copy-marker (or pos (point)))))
  3177. (setq org-agenda-last-marker-time (org-float-time))
  3178. (if org-agenda-buffer
  3179. (with-current-buffer org-agenda-buffer
  3180. (push m org-agenda-markers))
  3181. (push m org-agenda-markers))
  3182. m))
  3183. (defun org-agenda-reset-markers ()
  3184. "Reset markers created by `org-agenda'."
  3185. (while org-agenda-markers
  3186. (move-marker (pop org-agenda-markers) nil)))
  3187. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3188. "Save relative positions of markers in region.
  3189. This check for agenda markers in all agenda buffers currently active."
  3190. (dolist (buf (buffer-list))
  3191. (with-current-buffer buf
  3192. (when (eq major-mode 'org-agenda-mode)
  3193. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3194. org-agenda-markers)))))
  3195. ;;; Entry text mode
  3196. (defun org-agenda-entry-text-show-here ()
  3197. "Add some text from the entry as context to the current line."
  3198. (let (m txt o)
  3199. (setq m (org-get-at-bol 'org-hd-marker))
  3200. (unless (marker-buffer m)
  3201. (error "No marker points to an entry here"))
  3202. (setq txt (concat "\n" (org-no-properties
  3203. (org-agenda-get-some-entry-text
  3204. m org-agenda-entry-text-maxlines " > "))))
  3205. (when (string-match "\\S-" txt)
  3206. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3207. (overlay-put o 'evaporate t)
  3208. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3209. (overlay-put o 'after-string txt))))
  3210. (defun org-agenda-entry-text-show ()
  3211. "Add entry context for all agenda lines."
  3212. (interactive)
  3213. (save-excursion
  3214. (goto-char (point-max))
  3215. (beginning-of-line 1)
  3216. (while (not (bobp))
  3217. (when (org-get-at-bol 'org-hd-marker)
  3218. (org-agenda-entry-text-show-here))
  3219. (beginning-of-line 0))))
  3220. (defun org-agenda-entry-text-hide ()
  3221. "Remove any shown entry context."
  3222. (delq nil
  3223. (mapcar (lambda (o)
  3224. (if (eq (overlay-get o 'org-overlay-type)
  3225. 'agenda-entry-content)
  3226. (progn (delete-overlay o) t)))
  3227. (overlays-in (point-min) (point-max)))))
  3228. (defun org-agenda-get-day-face (date)
  3229. "Return the face DATE should be displayed with."
  3230. (or (and (functionp org-agenda-day-face-function)
  3231. (funcall org-agenda-day-face-function date))
  3232. (cond ((org-agenda-todayp date)
  3233. 'org-agenda-date-today)
  3234. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3235. 'org-agenda-date-weekend)
  3236. (t 'org-agenda-date))))
  3237. ;;; Agenda timeline
  3238. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3239. (defun org-timeline (&optional dotodo)
  3240. "Show a time-sorted view of the entries in the current org file.
  3241. Only entries with a time stamp of today or later will be listed. With
  3242. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3243. under the current date.
  3244. If the buffer contains an active region, only check the region for
  3245. dates."
  3246. (interactive "P")
  3247. (let* ((dopast t)
  3248. (org-agenda-show-log-scoped org-agenda-show-log)
  3249. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3250. (current-buffer))))
  3251. (date (calendar-current-date))
  3252. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3253. (end (if (org-region-active-p) (region-end) (point-max)))
  3254. (day-numbers (org-get-all-dates
  3255. beg end 'no-ranges
  3256. t org-agenda-show-log-scoped ; always include today
  3257. org-timeline-show-empty-dates))
  3258. (org-deadline-warning-days 0)
  3259. (org-agenda-only-exact-dates t)
  3260. (today (org-today))
  3261. (past t)
  3262. args
  3263. s e rtn d emptyp)
  3264. (setq org-agenda-redo-command
  3265. (list 'progn
  3266. (list 'org-switch-to-buffer-other-window (current-buffer))
  3267. (list 'org-timeline (list 'quote dotodo))))
  3268. (if (not dopast)
  3269. ;; Remove past dates from the list of dates.
  3270. (setq day-numbers (delq nil (mapcar (lambda(x)
  3271. (if (>= x today) x nil))
  3272. day-numbers))))
  3273. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3274. (org-compile-prefix-format 'timeline)
  3275. (org-set-sorting-strategy 'timeline)
  3276. (if org-agenda-show-log-scoped (push :closed args))
  3277. (push :timestamp args)
  3278. (push :deadline args)
  3279. (push :scheduled args)
  3280. (push :sexp args)
  3281. (if dotodo (push :todo args))
  3282. (insert "Timeline of file " entry "\n")
  3283. (add-text-properties (point-min) (point)
  3284. (list 'face 'org-agenda-structure))
  3285. (org-agenda-mark-header-line (point-min))
  3286. (while (setq d (pop day-numbers))
  3287. (if (and (listp d) (eq (car d) :omitted))
  3288. (progn
  3289. (setq s (point))
  3290. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3291. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3292. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3293. (if (and (>= d today)
  3294. dopast
  3295. past)
  3296. (progn
  3297. (setq past nil)
  3298. (insert (make-string 79 ?-) "\n")))
  3299. (setq date (calendar-gregorian-from-absolute d))
  3300. (setq s (point))
  3301. (setq rtn (and (not emptyp)
  3302. (apply 'org-agenda-get-day-entries entry
  3303. date args)))
  3304. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3305. (progn
  3306. (insert
  3307. (if (stringp org-agenda-format-date)
  3308. (format-time-string org-agenda-format-date
  3309. (org-time-from-absolute date))
  3310. (funcall org-agenda-format-date date))
  3311. "\n")
  3312. (put-text-property s (1- (point)) 'face
  3313. (org-agenda-get-day-face date))
  3314. (put-text-property s (1- (point)) 'org-date-line t)
  3315. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3316. (if (equal d today)
  3317. (put-text-property s (1- (point)) 'org-today t))
  3318. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3319. (put-text-property s (1- (point)) 'day d)))))
  3320. (goto-char (point-min))
  3321. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3322. (point-min)))
  3323. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3324. (org-finalize-agenda)
  3325. (setq buffer-read-only t)))
  3326. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3327. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3328. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3329. not every single day in the range. If FORCE-TODAY is non-nil, make
  3330. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3331. inactive time stamps (those in square brackets) are included.
  3332. When EMPTY is non-nil, also include days without any entries."
  3333. (let ((re (concat
  3334. (if pre-re pre-re "")
  3335. (if inactive org-ts-regexp-both org-ts-regexp)))
  3336. dates dates1 date day day1 day2 ts1 ts2 pos)
  3337. (if force-today
  3338. (setq dates (list (org-today))))
  3339. (save-excursion
  3340. (goto-char beg)
  3341. (while (re-search-forward re end t)
  3342. (setq day (time-to-days (org-time-string-to-time
  3343. (substring (match-string 1) 0 10)
  3344. (current-buffer) (match-beginning 0))))
  3345. (or (memq day dates) (push day dates)))
  3346. (unless no-ranges
  3347. (goto-char beg)
  3348. (while (re-search-forward org-tr-regexp end t)
  3349. (setq pos (match-beginning 0))
  3350. (setq ts1 (substring (match-string 1) 0 10)
  3351. ts2 (substring (match-string 2) 0 10)
  3352. day1 (time-to-days (org-time-string-to-time
  3353. ts1 (current-buffer) pos))
  3354. day2 (time-to-days (org-time-string-to-time
  3355. ts2 (current-buffer) pos)))
  3356. (while (< (setq day1 (1+ day1)) day2)
  3357. (or (memq day1 dates) (push day1 dates)))))
  3358. (setq dates (sort dates '<))
  3359. (when empty
  3360. (while (setq day (pop dates))
  3361. (setq day2 (car dates))
  3362. (push day dates1)
  3363. (when (and day2 empty)
  3364. (if (or (eq empty t)
  3365. (and (numberp empty) (<= (- day2 day) empty)))
  3366. (while (< (setq day (1+ day)) day2)
  3367. (push (list day) dates1))
  3368. (push (cons :omitted (- day2 day)) dates1))))
  3369. (setq dates (nreverse dates1)))
  3370. dates)))
  3371. ;;; Agenda Daily/Weekly
  3372. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3373. "Start day for the agenda view.
  3374. Custom commands can set this variable in the options section.")
  3375. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3376. (defvar org-agenda-current-span nil
  3377. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3378. (defvar org-arg-loc nil) ; local variable
  3379. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3380. "List of types searched for when creating the daily/weekly agenda.
  3381. This variable is a list of symbols that controls the types of
  3382. items that appear in the daily/weekly agenda. Allowed symbols in this
  3383. list are are
  3384. :timestamp List items containing a date stamp or date range matching
  3385. the selected date. This includes sexp entries in
  3386. angular brackets.
  3387. :sexp List entries resulting from plain diary-like sexps.
  3388. :deadline List deadline due on that date. When the date is today,
  3389. also list any deadlines past due, or due within
  3390. `org-deadline-warning-days'. `:deadline' must appear before
  3391. `:scheduled' if the setting of
  3392. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3393. any effect.
  3394. :scheduled List all items which are scheduled for the given date.
  3395. The diary for *today* also contains items which were
  3396. scheduled earlier and are not yet marked DONE.
  3397. By default, all four types are turned on.
  3398. Never set this variable globally using `setq', because then it
  3399. will apply to all future agenda commands. Instead, bind it with
  3400. `let' to scope it dynamically into the agenda-constructing
  3401. command. A good way to set it is through options in
  3402. `org-agenda-custom-commands'. For a more flexible (though
  3403. somewhat less efficient) way of determining what is included in
  3404. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3405. ;;;###autoload
  3406. (defun org-agenda-list (&optional arg start-day span)
  3407. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3408. The view will be for the current day or week, but from the overview buffer
  3409. you will be able to go to other days/weeks.
  3410. With a numeric prefix argument in an interactive call, the agenda will
  3411. span ARG days. Lisp programs should instead specify SPAN to change
  3412. the number of days. SPAN defaults to `org-agenda-span'.
  3413. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3414. given in `org-agenda-start-on-weekday'."
  3415. (interactive "P")
  3416. (if (and (integerp arg) (> arg 0))
  3417. (setq span arg arg nil))
  3418. (org-prepare-agenda "Day/Week")
  3419. (setq start-day (or start-day org-agenda-start-day))
  3420. (if org-agenda-overriding-arguments
  3421. (setq arg (car org-agenda-overriding-arguments)
  3422. start-day (nth 1 org-agenda-overriding-arguments)
  3423. span (nth 2 org-agenda-overriding-arguments)))
  3424. (if (stringp start-day)
  3425. ;; Convert to an absolute day number
  3426. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3427. (setq org-agenda-last-arguments (list arg start-day span))
  3428. (org-compile-prefix-format 'agenda)
  3429. (org-set-sorting-strategy 'agenda)
  3430. (let* ((span (org-agenda-ndays-to-span
  3431. (or span org-agenda-ndays org-agenda-span)))
  3432. (today (org-today))
  3433. (sd (or start-day today))
  3434. (ndays (org-agenda-span-to-ndays span sd))
  3435. (org-agenda-start-on-weekday
  3436. (if (eq ndays 7)
  3437. org-agenda-start-on-weekday))
  3438. (thefiles (org-agenda-files nil 'ifmode))
  3439. (files thefiles)
  3440. (start (if (or (null org-agenda-start-on-weekday)
  3441. (< ndays 7))
  3442. sd
  3443. (let* ((nt (calendar-day-of-week
  3444. (calendar-gregorian-from-absolute sd)))
  3445. (n1 org-agenda-start-on-weekday)
  3446. (d (- nt n1)))
  3447. (- sd (+ (if (< d 0) 7 0) d)))))
  3448. (day-numbers (list start))
  3449. (day-cnt 0)
  3450. (inhibit-redisplay (not debug-on-error))
  3451. (org-agenda-show-log-scoped org-agenda-show-log)
  3452. s e rtn rtnall file date d start-pos end-pos todayp
  3453. clocktable-start clocktable-end filter)
  3454. (setq org-agenda-redo-command
  3455. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3456. (dotimes (n (1- ndays))
  3457. (push (1+ (car day-numbers)) day-numbers))
  3458. (setq day-numbers (nreverse day-numbers))
  3459. (setq clocktable-start (car day-numbers)
  3460. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3461. (org-set-local 'org-starting-day (car day-numbers))
  3462. (org-set-local 'org-arg-loc arg)
  3463. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3464. (unless org-agenda-compact-blocks
  3465. (let* ((d1 (car day-numbers))
  3466. (d2 (org-last day-numbers))
  3467. (w1 (org-days-to-iso-week d1))
  3468. (w2 (org-days-to-iso-week d2)))
  3469. (setq s (point))
  3470. (if org-agenda-overriding-header
  3471. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3472. nil 'face 'org-agenda-structure) "\n")
  3473. (insert (org-agenda-span-name span)
  3474. "-agenda"
  3475. (if (< (- d2 d1) 350)
  3476. (if (= w1 w2)
  3477. (format " (W%02d)" w1)
  3478. (format " (W%02d-W%02d)" w1 w2))
  3479. "")
  3480. ":\n")))
  3481. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3482. 'org-date-line t))
  3483. (org-agenda-mark-header-line s))
  3484. (while (setq d (pop day-numbers))
  3485. (setq date (calendar-gregorian-from-absolute d)
  3486. s (point))
  3487. (if (or (setq todayp (= d today))
  3488. (and (not start-pos) (= d sd)))
  3489. (setq start-pos (point))
  3490. (if (and start-pos (not end-pos))
  3491. (setq end-pos (point))))
  3492. (setq files thefiles
  3493. rtnall nil)
  3494. (while (setq file (pop files))
  3495. (catch 'nextfile
  3496. (org-check-agenda-file file)
  3497. (let ((org-agenda-entry-types org-agenda-entry-types))
  3498. (unless org-agenda-include-deadlines
  3499. (setq org-agenda-entry-types
  3500. (delq :deadline org-agenda-entry-types)))
  3501. (cond
  3502. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3503. (setq rtn (org-agenda-get-day-entries
  3504. file date :closed)))
  3505. (org-agenda-show-log-scoped
  3506. (setq rtn (apply 'org-agenda-get-day-entries
  3507. file date
  3508. (append '(:closed) org-agenda-entry-types))))
  3509. (t
  3510. (setq rtn (apply 'org-agenda-get-day-entries
  3511. file date
  3512. org-agenda-entry-types)))))
  3513. (setq rtnall (append rtnall rtn)))) ;; all entries
  3514. (if org-agenda-include-diary
  3515. (let ((org-agenda-search-headline-for-time t))
  3516. (require 'diary-lib)
  3517. (setq rtn (org-get-entries-from-diary date))
  3518. (setq rtnall (append rtnall rtn))))
  3519. (if (or rtnall org-agenda-show-all-dates)
  3520. (progn
  3521. (setq day-cnt (1+ day-cnt))
  3522. (insert
  3523. (if (stringp org-agenda-format-date)
  3524. (format-time-string org-agenda-format-date
  3525. (org-time-from-absolute date))
  3526. (funcall org-agenda-format-date date))
  3527. "\n")
  3528. (put-text-property s (1- (point)) 'face
  3529. (org-agenda-get-day-face date))
  3530. (put-text-property s (1- (point)) 'org-date-line t)
  3531. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3532. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3533. (when todayp
  3534. (put-text-property s (1- (point)) 'org-today t))
  3535. (if rtnall (insert ;; all entries
  3536. (org-finalize-agenda-entries
  3537. (org-agenda-add-time-grid-maybe
  3538. rtnall ndays todayp))
  3539. "\n"))
  3540. (put-text-property s (1- (point)) 'day d)
  3541. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3542. (when (and org-agenda-clockreport-mode clocktable-start)
  3543. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3544. ;; the above line is to ensure the restricted range!
  3545. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3546. tbl)
  3547. (setq p (org-plist-delete p :block))
  3548. (setq p (plist-put p :tstart clocktable-start))
  3549. (setq p (plist-put p :tend clocktable-end))
  3550. (setq p (plist-put p :scope 'agenda))
  3551. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3552. (setq filter (or org-agenda-tag-filter-while-redo
  3553. (get 'org-agenda-tag-filter :preset-filter))))
  3554. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3555. (if (string-match "[<>=]" x)
  3556. ""
  3557. x))
  3558. filter ""))))
  3559. (setq tbl (apply 'org-get-clocktable p))
  3560. (insert tbl)))
  3561. (goto-char (point-min))
  3562. (or org-agenda-multi (org-fit-agenda-window))
  3563. (unless (and (pos-visible-in-window-p (point-min))
  3564. (pos-visible-in-window-p (point-max)))
  3565. (goto-char (1- (point-max)))
  3566. (recenter -1)
  3567. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3568. (progn
  3569. (goto-char (or start-pos 1))
  3570. (recenter 1))))
  3571. (goto-char (or start-pos 1))
  3572. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3573. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3574. (org-agenda-show-clocking-issues))
  3575. (org-finalize-agenda)
  3576. (setq buffer-read-only t)
  3577. (message "")))
  3578. (defun org-agenda-ndays-to-span (n)
  3579. "Return a span symbol for a span of N days, or N if none matches."
  3580. (cond ((symbolp n) n)
  3581. ((= n 1) 'day)
  3582. ((= n 7) 'week)
  3583. (t n)))
  3584. (defun org-agenda-span-to-ndays (span start-day)
  3585. "Return ndays from SPAN starting at START-DAY."
  3586. (cond ((numberp span) span)
  3587. ((eq span 'day) 1)
  3588. ((eq span 'week) 7)
  3589. ((eq span 'month)
  3590. (let ((date (calendar-gregorian-from-absolute start-day)))
  3591. (calendar-last-day-of-month (car date) (caddr date))))
  3592. ((eq span 'year)
  3593. (let ((date (calendar-gregorian-from-absolute start-day)))
  3594. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3595. (defun org-agenda-span-name (span)
  3596. "Return a SPAN name."
  3597. (if (null span)
  3598. ""
  3599. (if (symbolp span)
  3600. (capitalize (symbol-name span))
  3601. (format "%d days" span))))
  3602. ;;; Agenda word search
  3603. (defvar org-agenda-search-history nil)
  3604. (defvar org-todo-only nil)
  3605. (defvar org-search-syntax-table nil
  3606. "Special syntax table for org-mode search.
  3607. In this table, we have single quotes not as word constituents, to
  3608. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3609. (defun org-search-syntax-table ()
  3610. (unless org-search-syntax-table
  3611. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3612. (modify-syntax-entry ?' "." org-search-syntax-table)
  3613. (modify-syntax-entry ?` "." org-search-syntax-table))
  3614. org-search-syntax-table)
  3615. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3616. ;;;###autoload
  3617. (defun org-search-view (&optional todo-only string edit-at)
  3618. "Show all entries that contain a phrase or words or regular expressions.
  3619. With optional prefix argument TODO-ONLY, only consider entries that are
  3620. TODO entries. The argument STRING can be used to pass a default search
  3621. string into this function. If EDIT-AT is non-nil, it means that the
  3622. user should get a chance to edit this string, with cursor at position
  3623. EDIT-AT.
  3624. The search string can be viewed either as a phrase that should be found as
  3625. is, or it can be broken into a number of snippets, each of which must match
  3626. in a Boolean way to select an entry. The default depends on the variable
  3627. `org-agenda-search-view-always-boolean'.
  3628. Even if this is turned off (the default) you can always switch to
  3629. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3630. The default is a direct search of the whole phrase, where each space in
  3631. the search string can expand to an arbitrary amount of whitespace,
  3632. including newlines.
  3633. If using a Boolean search, the search string is split on whitespace and
  3634. each snippet is searched separately, with logical AND to select an entry.
  3635. Words prefixed with a minus must *not* occur in the entry. Words without
  3636. a prefix or prefixed with a plus must occur in the entry. Matching is
  3637. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3638. match whole words, not parts of a word) if
  3639. `org-agenda-search-view-force-full-words' is set (default is nil).
  3640. Boolean search snippets enclosed by curly braces are interpreted as
  3641. regular expressions that must or (when preceded with \"-\") must not
  3642. match in the entry. Snippets enclosed into double quotes will be taken
  3643. as a whole, to include whitespace.
  3644. - If the search string starts with an asterisk, search only in headlines.
  3645. - If (possibly after the leading star) the search string starts with an
  3646. exclamation mark, this also means to look at TODO entries only, an effect
  3647. that can also be achieved with a prefix argument.
  3648. - If (possibly after star and exclamation mark) the search string starts
  3649. with a colon, this will mean that the (non-regexp) snippets of the
  3650. Boolean search must match as full words.
  3651. This command searches the agenda files, and in addition the files listed
  3652. in `org-agenda-text-search-extra-files'."
  3653. (interactive "P")
  3654. (org-prepare-agenda "SEARCH")
  3655. (org-compile-prefix-format 'search)
  3656. (org-set-sorting-strategy 'search)
  3657. (let* ((props (list 'face nil
  3658. 'done-face 'org-agenda-done
  3659. 'org-not-done-regexp org-not-done-regexp
  3660. 'org-todo-regexp org-todo-regexp
  3661. 'org-complex-heading-regexp org-complex-heading-regexp
  3662. 'mouse-face 'highlight
  3663. 'help-echo (format "mouse-2 or RET jump to location")))
  3664. (full-words org-agenda-search-view-force-full-words)
  3665. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3666. regexp rtn rtnall files file pos
  3667. marker category org-category-pos tags c neg re boolean
  3668. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3669. (unless (and (not edit-at)
  3670. (stringp string)
  3671. (string-match "\\S-" string))
  3672. (setq string (read-string
  3673. (if org-agenda-search-view-always-boolean
  3674. "[+-]Word/{Regexp} ...: "
  3675. "Phrase, or [+-]Word/{Regexp} ...: ")
  3676. (cond
  3677. ((integerp edit-at) (cons string edit-at))
  3678. (edit-at string))
  3679. 'org-agenda-search-history)))
  3680. (org-set-local 'org-todo-only todo-only)
  3681. (setq org-agenda-redo-command
  3682. (list 'org-search-view (if todo-only t nil) string
  3683. '(if current-prefix-arg 1 nil)))
  3684. (setq org-agenda-query-string string)
  3685. (if (equal (string-to-char string) ?*)
  3686. (setq hdl-only t
  3687. words (substring string 1))
  3688. (setq words string))
  3689. (when (equal (string-to-char words) ?!)
  3690. (setq todo-only t
  3691. words (substring words 1)))
  3692. (when (equal (string-to-char words) ?:)
  3693. (setq full-words t
  3694. words (substring words 1)))
  3695. (if (or org-agenda-search-view-always-boolean
  3696. (member (string-to-char words) '(?- ?+ ?\{)))
  3697. (setq boolean t))
  3698. (setq words (org-split-string words))
  3699. (let (www w)
  3700. (while (setq w (pop words))
  3701. (while (and (string-match "\\\\\\'" w) words)
  3702. (setq w (concat (substring w 0 -1) " " (pop words))))
  3703. (push w www))
  3704. (setq words (nreverse www) www nil)
  3705. (while (setq w (pop words))
  3706. (when (and (string-match "\\`[-+]?{" w)
  3707. (not (string-match "}\\'" w)))
  3708. (while (and words (not (string-match "}\\'" (car words))))
  3709. (setq w (concat w " " (pop words))))
  3710. (setq w (concat w " " (pop words))))
  3711. (push w www))
  3712. (setq words (nreverse www)))
  3713. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3714. (when boolean
  3715. (let (wds w)
  3716. (while (setq w (pop words))
  3717. (if (or (equal (substring w 0 1) "\"")
  3718. (and (> (length w) 1)
  3719. (member (substring w 0 1) '("+" "-"))
  3720. (equal (substring w 1 2) "\"")))
  3721. (while (and words (not (equal (substring w -1) "\"")))
  3722. (setq w (concat w " " (pop words)))))
  3723. (and (string-match "\\`\\([-+]?\\)\"" w)
  3724. (setq w (replace-match "\\1" nil nil w)))
  3725. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3726. (push w wds))
  3727. (setq words (nreverse wds))))
  3728. (if boolean
  3729. (mapc (lambda (w)
  3730. (setq c (string-to-char w))
  3731. (if (equal c ?-)
  3732. (setq neg t w (substring w 1))
  3733. (if (equal c ?+)
  3734. (setq neg nil w (substring w 1))
  3735. (setq neg nil)))
  3736. (if (string-match "\\`{.*}\\'" w)
  3737. (setq re (substring w 1 -1))
  3738. (if full-words
  3739. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3740. (setq re (regexp-quote (downcase w)))))
  3741. (if neg (push re regexps-) (push re regexps+)))
  3742. words)
  3743. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3744. regexps+))
  3745. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3746. (if (not regexps+)
  3747. (setq regexp org-outline-regexp-bol)
  3748. (setq regexp (pop regexps+))
  3749. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3750. regexp))))
  3751. (setq files (org-agenda-files nil 'ifmode))
  3752. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3753. (pop org-agenda-text-search-extra-files)
  3754. (setq files (org-add-archive-files files)))
  3755. (setq files (append files org-agenda-text-search-extra-files)
  3756. rtnall nil)
  3757. (while (setq file (pop files))
  3758. (setq ee nil)
  3759. (catch 'nextfile
  3760. (org-check-agenda-file file)
  3761. (setq buffer (if (file-exists-p file)
  3762. (org-get-agenda-file-buffer file)
  3763. (error "No such file %s" file)))
  3764. (if (not buffer)
  3765. ;; If file does not exist, make sure an error message is sent
  3766. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3767. file))))
  3768. (with-current-buffer buffer
  3769. (with-syntax-table (org-search-syntax-table)
  3770. (unless (eq major-mode 'org-mode)
  3771. (error "Agenda file %s is not in `org-mode'" file))
  3772. (let ((case-fold-search t))
  3773. (save-excursion
  3774. (save-restriction
  3775. (if org-agenda-restrict
  3776. (narrow-to-region org-agenda-restrict-begin
  3777. org-agenda-restrict-end)
  3778. (widen))
  3779. (goto-char (point-min))
  3780. (unless (or (org-at-heading-p)
  3781. (outline-next-heading))
  3782. (throw 'nextfile t))
  3783. (goto-char (max (point-min) (1- (point))))
  3784. (while (re-search-forward regexp nil t)
  3785. (org-back-to-heading t)
  3786. (skip-chars-forward "* ")
  3787. (setq beg (point-at-bol)
  3788. beg1 (point)
  3789. end (progn (outline-next-heading) (point)))
  3790. (catch :skip
  3791. (goto-char beg)
  3792. (org-agenda-skip)
  3793. (setq str (buffer-substring-no-properties
  3794. (point-at-bol)
  3795. (if hdl-only (point-at-eol) end)))
  3796. (mapc (lambda (wr) (when (string-match wr str)
  3797. (goto-char (1- end))
  3798. (throw :skip t)))
  3799. regexps-)
  3800. (mapc (lambda (wr) (unless (string-match wr str)
  3801. (goto-char (1- end))
  3802. (throw :skip t)))
  3803. (if todo-only
  3804. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3805. regexps+)
  3806. regexps+))
  3807. (goto-char beg)
  3808. (setq marker (org-agenda-new-marker (point))
  3809. category (org-get-category)
  3810. org-category-pos (get-text-property (point) 'org-category-position)
  3811. tags (org-get-tags-at (point))
  3812. txt (org-agenda-format-item
  3813. ""
  3814. (buffer-substring-no-properties
  3815. beg1 (point-at-eol))
  3816. category tags))
  3817. (org-add-props txt props
  3818. 'org-marker marker 'org-hd-marker marker
  3819. 'org-todo-regexp org-todo-regexp
  3820. 'org-complex-heading-regexp org-complex-heading-regexp
  3821. 'priority 1000 'org-category category
  3822. 'org-category-position org-category-pos
  3823. 'type "search")
  3824. (push txt ee)
  3825. (goto-char (1- end))))))))))
  3826. (setq rtn (nreverse ee))
  3827. (setq rtnall (append rtnall rtn)))
  3828. (if org-agenda-overriding-header
  3829. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3830. nil 'face 'org-agenda-structure) "\n")
  3831. (insert "Search words: ")
  3832. (add-text-properties (point-min) (1- (point))
  3833. (list 'face 'org-agenda-structure))
  3834. (setq pos (point))
  3835. (insert string "\n")
  3836. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3837. (setq pos (point))
  3838. (unless org-agenda-multi
  3839. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3840. (add-text-properties pos (1- (point))
  3841. (list 'face 'org-agenda-structure))))
  3842. (org-agenda-mark-header-line (point-min))
  3843. (when rtnall
  3844. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3845. (goto-char (point-min))
  3846. (or org-agenda-multi (org-fit-agenda-window))
  3847. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3848. (org-finalize-agenda)
  3849. (setq buffer-read-only t)))
  3850. ;;; Agenda TODO list
  3851. (defvar org-select-this-todo-keyword nil)
  3852. (defvar org-last-arg nil)
  3853. ;;;###autoload
  3854. (defun org-todo-list (arg)
  3855. "Show all (not done) TODO entries from all agenda file in a single list.
  3856. The prefix arg can be used to select a specific TODO keyword and limit
  3857. the list to these. When using \\[universal-argument], you will be prompted
  3858. for a keyword. A numeric prefix directly selects the Nth keyword in
  3859. `org-todo-keywords-1'."
  3860. (interactive "P")
  3861. (org-prepare-agenda "TODO")
  3862. (org-compile-prefix-format 'todo)
  3863. (org-set-sorting-strategy 'todo)
  3864. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3865. (let* ((today (org-today))
  3866. (date (calendar-gregorian-from-absolute today))
  3867. (kwds org-todo-keywords-for-agenda)
  3868. (completion-ignore-case t)
  3869. (org-select-this-todo-keyword
  3870. (if (stringp arg) arg
  3871. (and arg (integerp arg) (> arg 0)
  3872. (nth (1- arg) kwds))))
  3873. rtn rtnall files file pos)
  3874. (when (equal arg '(4))
  3875. (setq org-select-this-todo-keyword
  3876. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3877. (mapcar 'list kwds) nil nil)))
  3878. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3879. (org-set-local 'org-last-arg arg)
  3880. (setq org-agenda-redo-command
  3881. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3882. (setq files (org-agenda-files nil 'ifmode)
  3883. rtnall nil)
  3884. (while (setq file (pop files))
  3885. (catch 'nextfile
  3886. (org-check-agenda-file file)
  3887. (setq rtn (org-agenda-get-day-entries file date :todo))
  3888. (setq rtnall (append rtnall rtn))))
  3889. (if org-agenda-overriding-header
  3890. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3891. nil 'face 'org-agenda-structure) "\n")
  3892. (insert "Global list of TODO items of type: ")
  3893. (add-text-properties (point-min) (1- (point))
  3894. (list 'face 'org-agenda-structure
  3895. 'short-heading
  3896. (concat "ToDo: "
  3897. (or org-select-this-todo-keyword "ALL"))))
  3898. (org-agenda-mark-header-line (point-min))
  3899. (setq pos (point))
  3900. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3901. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3902. (setq pos (point))
  3903. (unless org-agenda-multi
  3904. (insert "Available with `N r': (0)ALL")
  3905. (let ((n 0) s)
  3906. (mapc (lambda (x)
  3907. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3908. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3909. (insert "\n "))
  3910. (insert " " s))
  3911. kwds))
  3912. (insert "\n"))
  3913. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3914. (org-agenda-mark-header-line (point-min))
  3915. (when rtnall
  3916. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3917. (goto-char (point-min))
  3918. (or org-agenda-multi (org-fit-agenda-window))
  3919. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3920. (org-finalize-agenda)
  3921. (setq buffer-read-only t)))
  3922. ;;; Agenda tags match
  3923. ;;;###autoload
  3924. (defun org-tags-view (&optional todo-only match)
  3925. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3926. The prefix arg TODO-ONLY limits the search to TODO entries."
  3927. (interactive "P")
  3928. (let* ((org-tags-match-list-sublevels
  3929. org-tags-match-list-sublevels)
  3930. (completion-ignore-case t)
  3931. rtn rtnall files file pos matcher
  3932. buffer)
  3933. (when (and (stringp match) (not (string-match "\\S-" match)))
  3934. (setq match nil))
  3935. (setq matcher (org-make-tags-matcher match)
  3936. match (car matcher) matcher (cdr matcher))
  3937. (org-prepare-agenda (concat "TAGS " match))
  3938. (org-compile-prefix-format 'tags)
  3939. (org-set-sorting-strategy 'tags)
  3940. (setq org-agenda-query-string match)
  3941. (setq org-agenda-redo-command
  3942. (list 'org-tags-view (list 'quote todo-only)
  3943. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3944. (setq files (org-agenda-files nil 'ifmode)
  3945. rtnall nil)
  3946. (while (setq file (pop files))
  3947. (catch 'nextfile
  3948. (org-check-agenda-file file)
  3949. (setq buffer (if (file-exists-p file)
  3950. (org-get-agenda-file-buffer file)
  3951. (error "No such file %s" file)))
  3952. (if (not buffer)
  3953. ;; If file does not exist, error message to agenda
  3954. (setq rtn (list
  3955. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3956. rtnall (append rtnall rtn))
  3957. (with-current-buffer buffer
  3958. (unless (eq major-mode 'org-mode)
  3959. (error "Agenda file %s is not in `org-mode'" file))
  3960. (save-excursion
  3961. (save-restriction
  3962. (if org-agenda-restrict
  3963. (narrow-to-region org-agenda-restrict-begin
  3964. org-agenda-restrict-end)
  3965. (widen))
  3966. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3967. (setq rtnall (append rtnall rtn))))))))
  3968. (if org-agenda-overriding-header
  3969. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3970. nil 'face 'org-agenda-structure) "\n")
  3971. (insert "Headlines with TAGS match: ")
  3972. (add-text-properties (point-min) (1- (point))
  3973. (list 'face 'org-agenda-structure
  3974. 'short-heading
  3975. (concat "Match: " match)))
  3976. (setq pos (point))
  3977. (insert match "\n")
  3978. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3979. (setq pos (point))
  3980. (unless org-agenda-multi
  3981. (insert "Press `C-u r' to search again with new search string\n"))
  3982. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3983. (org-agenda-mark-header-line (point-min))
  3984. (when rtnall
  3985. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3986. (goto-char (point-min))
  3987. (or org-agenda-multi (org-fit-agenda-window))
  3988. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3989. (org-finalize-agenda)
  3990. (setq buffer-read-only t)))
  3991. ;;; Agenda Finding stuck projects
  3992. (defvar org-agenda-skip-regexp nil
  3993. "Regular expression used in skipping subtrees for the agenda.
  3994. This is basically a temporary global variable that can be set and then
  3995. used by user-defined selections using `org-agenda-skip-function'.")
  3996. (defvar org-agenda-overriding-header nil
  3997. "When set during agenda, todo and tags searches it replaces the header.
  3998. This variable should not be set directly, but custom commands can bind it
  3999. in the options section.")
  4000. (defun org-agenda-skip-entry-when-regexp-matches ()
  4001. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4002. If yes, it returns the end position of this entry, causing agenda commands
  4003. to skip the entry but continuing the search in the subtree. This is a
  4004. function that can be put into `org-agenda-skip-function' for the duration
  4005. of a command."
  4006. (let ((end (save-excursion (org-end-of-subtree t)))
  4007. skip)
  4008. (save-excursion
  4009. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4010. (and skip end)))
  4011. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4012. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4013. If yes, it returns the end position of this tree, causing agenda commands
  4014. to skip this subtree. This is a function that can be put into
  4015. `org-agenda-skip-function' for the duration of a command."
  4016. (let ((end (save-excursion (org-end-of-subtree t)))
  4017. skip)
  4018. (save-excursion
  4019. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4020. (and skip end)))
  4021. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4022. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4023. If yes, it returns the end position of the current entry (NOT the tree),
  4024. causing agenda commands to skip the entry but continuing the search in
  4025. the subtree. This is a function that can be put into
  4026. `org-agenda-skip-function' for the duration of a command. An important
  4027. use of this function is for the stuck project list."
  4028. (let ((end (save-excursion (org-end-of-subtree t)))
  4029. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4030. skip)
  4031. (save-excursion
  4032. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4033. (and skip entry-end)))
  4034. (defun org-agenda-skip-entry-if (&rest conditions)
  4035. "Skip entry if any of CONDITIONS is true.
  4036. See `org-agenda-skip-if' for details."
  4037. (org-agenda-skip-if nil conditions))
  4038. (defun org-agenda-skip-subtree-if (&rest conditions)
  4039. "Skip entry if any of CONDITIONS is true.
  4040. See `org-agenda-skip-if' for details."
  4041. (org-agenda-skip-if t conditions))
  4042. (defun org-agenda-skip-if (subtree conditions)
  4043. "Checks current entity for CONDITIONS.
  4044. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4045. the entry (i.e. the text before the next heading) is checked.
  4046. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4047. from different tests. Valid conditions are:
  4048. scheduled Check if there is a scheduled cookie
  4049. notscheduled Check if there is no scheduled cookie
  4050. deadline Check if there is a deadline
  4051. notdeadline Check if there is no deadline
  4052. timestamp Check if there is a timestamp (also deadline or scheduled)
  4053. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4054. regexp Check if regexp matches
  4055. notregexp Check if regexp does not match.
  4056. todo Check if TODO keyword matches
  4057. nottodo Check if TODO keyword does not match
  4058. The regexp is taken from the conditions list, it must come right after
  4059. the `regexp' or `notregexp' element.
  4060. `todo' and `nottodo' accept as an argument a list of todo
  4061. keywords, which may include \"*\" to match any todo keyword.
  4062. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4063. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4064. Instead of a list, a keyword class may be given. For example:
  4065. (org-agenda-skip-entry-if 'nottodo 'done)
  4066. would skip entries that haven't been marked with any of \"DONE\"
  4067. keywords. Possible classes are: `todo', `done', `any'.
  4068. If any of these conditions is met, this function returns the end point of
  4069. the entity, causing the search to continue from there. This is a function
  4070. that can be put into `org-agenda-skip-function' for the duration of a command."
  4071. (let (beg end m)
  4072. (org-back-to-heading t)
  4073. (setq beg (point)
  4074. end (if subtree
  4075. (progn (org-end-of-subtree t) (point))
  4076. (progn (outline-next-heading) (1- (point)))))
  4077. (goto-char beg)
  4078. (and
  4079. (or
  4080. (and (memq 'scheduled conditions)
  4081. (re-search-forward org-scheduled-time-regexp end t))
  4082. (and (memq 'notscheduled conditions)
  4083. (not (re-search-forward org-scheduled-time-regexp end t)))
  4084. (and (memq 'deadline conditions)
  4085. (re-search-forward org-deadline-time-regexp end t))
  4086. (and (memq 'notdeadline conditions)
  4087. (not (re-search-forward org-deadline-time-regexp end t)))
  4088. (and (memq 'timestamp conditions)
  4089. (re-search-forward org-ts-regexp end t))
  4090. (and (memq 'nottimestamp conditions)
  4091. (not (re-search-forward org-ts-regexp end t)))
  4092. (and (setq m (memq 'regexp conditions))
  4093. (stringp (nth 1 m))
  4094. (re-search-forward (nth 1 m) end t))
  4095. (and (setq m (memq 'notregexp conditions))
  4096. (stringp (nth 1 m))
  4097. (not (re-search-forward (nth 1 m) end t)))
  4098. (and (or
  4099. (setq m (memq 'nottodo conditions))
  4100. (setq m (memq 'todo conditions)))
  4101. (org-agenda-skip-if-todo m end)))
  4102. end)))
  4103. (defun org-agenda-skip-if-todo (args end)
  4104. "Helper function for `org-agenda-skip-if', do not use it directly.
  4105. ARGS is a list with first element either `todo' or `nottodo'.
  4106. The remainder is either a list of TODO keywords, or a state symbol
  4107. `todo' or `done' or `any'."
  4108. (let ((kw (car args))
  4109. (arg (cadr args))
  4110. todo-wds todo-re)
  4111. (setq todo-wds
  4112. (org-uniquify
  4113. (cond
  4114. ((listp arg) ;; list of keywords
  4115. (if (member "*" arg)
  4116. (mapcar 'substring-no-properties org-todo-keywords-1)
  4117. arg))
  4118. ((symbolp arg) ;; keyword class name
  4119. (cond
  4120. ((eq arg 'todo)
  4121. (org-delete-all org-done-keywords
  4122. (mapcar 'substring-no-properties
  4123. org-todo-keywords-1)))
  4124. ((eq arg 'done) org-done-keywords)
  4125. ((eq arg 'any)
  4126. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4127. (setq todo-re
  4128. (concat "^\\*+[ \t]+\\<\\("
  4129. (mapconcat 'identity todo-wds "\\|")
  4130. "\\)\\>"))
  4131. (if (eq kw 'todo)
  4132. (re-search-forward todo-re end t)
  4133. (not (re-search-forward todo-re end t)))))
  4134. ;;;###autoload
  4135. (defun org-agenda-list-stuck-projects (&rest ignore)
  4136. "Create agenda view for projects that are stuck.
  4137. Stuck projects are project that have no next actions. For the definitions
  4138. of what a project is and how to check if it stuck, customize the variable
  4139. `org-stuck-projects'."
  4140. (interactive)
  4141. (let* ((org-agenda-skip-function
  4142. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4143. ;; We could have used org-agenda-skip-if here.
  4144. (org-agenda-overriding-header
  4145. (or org-agenda-overriding-header "List of stuck projects: "))
  4146. (matcher (nth 0 org-stuck-projects))
  4147. (todo (nth 1 org-stuck-projects))
  4148. (todo-wds (if (member "*" todo)
  4149. (progn
  4150. (org-prepare-agenda-buffers (org-agenda-files
  4151. nil 'ifmode))
  4152. (org-delete-all
  4153. org-done-keywords-for-agenda
  4154. (copy-sequence org-todo-keywords-for-agenda)))
  4155. todo))
  4156. (todo-re (concat "^\\*+[ \t]+\\("
  4157. (mapconcat 'identity todo-wds "\\|")
  4158. "\\)\\>"))
  4159. (tags (nth 2 org-stuck-projects))
  4160. (tags-re (if (member "*" tags)
  4161. (concat org-outline-regexp-bol
  4162. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4163. (if tags
  4164. (concat org-outline-regexp-bol
  4165. ".*:\\("
  4166. (mapconcat 'identity tags "\\|")
  4167. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4168. (gen-re (nth 3 org-stuck-projects))
  4169. (re-list
  4170. (delq nil
  4171. (list
  4172. (if todo todo-re)
  4173. (if tags tags-re)
  4174. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4175. gen-re)))))
  4176. (setq org-agenda-skip-regexp
  4177. (if re-list
  4178. (mapconcat 'identity re-list "\\|")
  4179. (error "No information how to identify unstuck projects")))
  4180. (org-tags-view nil matcher)
  4181. (with-current-buffer org-agenda-buffer-name
  4182. (setq org-agenda-redo-command
  4183. '(org-agenda-list-stuck-projects
  4184. (or current-prefix-arg org-last-arg))))))
  4185. ;;; Diary integration
  4186. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4187. (defvar diary-list-entries-hook)
  4188. (defvar diary-time-regexp)
  4189. (defun org-get-entries-from-diary (date)
  4190. "Get the (Emacs Calendar) diary entries for DATE."
  4191. (require 'diary-lib)
  4192. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4193. (diary-display-hook '(fancy-diary-display))
  4194. (diary-display-function 'fancy-diary-display)
  4195. (pop-up-frames nil)
  4196. (diary-list-entries-hook
  4197. (cons 'org-diary-default-entry diary-list-entries-hook))
  4198. (diary-file-name-prefix-function nil) ; turn this feature off
  4199. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4200. entries
  4201. (org-disable-agenda-to-diary t))
  4202. (save-excursion
  4203. (save-window-excursion
  4204. (funcall (if (fboundp 'diary-list-entries)
  4205. 'diary-list-entries 'list-diary-entries)
  4206. date 1)))
  4207. (if (not (get-buffer diary-fancy-buffer))
  4208. (setq entries nil)
  4209. (with-current-buffer diary-fancy-buffer
  4210. (setq buffer-read-only nil)
  4211. (if (zerop (buffer-size))
  4212. ;; No entries
  4213. (setq entries nil)
  4214. ;; Omit the date and other unnecessary stuff
  4215. (org-agenda-cleanup-fancy-diary)
  4216. ;; Add prefix to each line and extend the text properties
  4217. (if (zerop (buffer-size))
  4218. (setq entries nil)
  4219. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4220. (setq entries
  4221. (with-temp-buffer
  4222. (insert entries) (goto-char (point-min))
  4223. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4224. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4225. (replace-match (concat "; " (match-string 1)))))
  4226. (buffer-string)))))
  4227. (set-buffer-modified-p nil)
  4228. (kill-buffer diary-fancy-buffer)))
  4229. (when entries
  4230. (setq entries (org-split-string entries "\n"))
  4231. (setq entries
  4232. (mapcar
  4233. (lambda (x)
  4234. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4235. ;; Extend the text properties to the beginning of the line
  4236. (org-add-props x (text-properties-at (1- (length x)) x)
  4237. 'type "diary" 'date date 'face 'org-agenda-diary))
  4238. entries)))))
  4239. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4240. "Hook run when the fancy diary buffer is cleaned up.")
  4241. (defun org-agenda-cleanup-fancy-diary ()
  4242. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4243. This gets rid of the date, the underline under the date, and
  4244. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4245. date. It also removes lines that contain only whitespace."
  4246. (goto-char (point-min))
  4247. (if (looking-at ".*?:[ \t]*")
  4248. (progn
  4249. (replace-match "")
  4250. (re-search-forward "\n=+$" nil t)
  4251. (replace-match "")
  4252. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4253. (re-search-forward "\n=+$" nil t)
  4254. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4255. (goto-char (point-min))
  4256. (while (re-search-forward "^ +\n" nil t)
  4257. (replace-match ""))
  4258. (goto-char (point-min))
  4259. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4260. (replace-match ""))
  4261. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4262. ;; Make sure entries from the diary have the right text properties.
  4263. (eval-after-load "diary-lib"
  4264. '(if (boundp 'diary-modify-entry-list-string-function)
  4265. ;; We can rely on the hook, nothing to do
  4266. nil
  4267. ;; Hook not available, must use advice to make this work
  4268. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4269. "Make the position visible."
  4270. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4271. (stringp string)
  4272. buffer-file-name)
  4273. (setq string (org-modify-diary-entry-string string))))))
  4274. (defun org-modify-diary-entry-string (string)
  4275. "Add text properties to string, allowing org-mode to act on it."
  4276. (org-add-props string nil
  4277. 'mouse-face 'highlight
  4278. 'help-echo (if buffer-file-name
  4279. (format "mouse-2 or RET jump to diary file %s"
  4280. (abbreviate-file-name buffer-file-name))
  4281. "")
  4282. 'org-agenda-diary-link t
  4283. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4284. (defun org-diary-default-entry ()
  4285. "Add a dummy entry to the diary.
  4286. Needed to avoid empty dates which mess up holiday display."
  4287. ;; Catch the error if dealing with the new add-to-diary-alist
  4288. (when org-disable-agenda-to-diary
  4289. (condition-case nil
  4290. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4291. (error
  4292. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4293. (defun org-add-to-diary-list (&rest args)
  4294. (if (fboundp 'diary-add-to-list)
  4295. (apply 'diary-add-to-list args)
  4296. (apply 'add-to-diary-list args)))
  4297. (defvar org-diary-last-run-time nil)
  4298. ;;;###autoload
  4299. (defun org-diary (&rest args)
  4300. "Return diary information from org-files.
  4301. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4302. It accesses org files and extracts information from those files to be
  4303. listed in the diary. The function accepts arguments specifying what
  4304. items should be listed. For a list of arguments allowed here, see the
  4305. variable `org-agenda-entry-types'.
  4306. The call in the diary file should look like this:
  4307. &%%(org-diary) ~/path/to/some/orgfile.org
  4308. Use a separate line for each org file to check. Or, if you omit the file name,
  4309. all files listed in `org-agenda-files' will be checked automatically:
  4310. &%%(org-diary)
  4311. If you don't give any arguments (as in the example above), the default
  4312. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4313. So the example above may also be written as
  4314. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4315. The function expects the lisp variables `entry' and `date' to be provided
  4316. by the caller, because this is how the calendar works. Don't use this
  4317. function from a program - use `org-agenda-get-day-entries' instead."
  4318. (when (> (- (org-float-time)
  4319. org-agenda-last-marker-time)
  4320. 5)
  4321. ;; I am not sure if this works with sticky agendas, because the marker
  4322. ;; list is then no longer a global variable.
  4323. (org-agenda-reset-markers))
  4324. (org-compile-prefix-format 'agenda)
  4325. (org-set-sorting-strategy 'agenda)
  4326. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4327. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4328. (list entry)
  4329. (org-agenda-files t)))
  4330. (time (org-float-time))
  4331. file rtn results)
  4332. (when (or (not org-diary-last-run-time)
  4333. (> (- time
  4334. org-diary-last-run-time)
  4335. 3))
  4336. (org-prepare-agenda-buffers files))
  4337. (setq org-diary-last-run-time time)
  4338. ;; If this is called during org-agenda, don't return any entries to
  4339. ;; the calendar. Org Agenda will list these entries itself.
  4340. (if org-disable-agenda-to-diary (setq files nil))
  4341. (while (setq file (pop files))
  4342. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4343. (setq results (append results rtn)))
  4344. (if results
  4345. (concat (org-finalize-agenda-entries results) "\n"))))
  4346. ;;; Agenda entry finders
  4347. (defun org-agenda-get-day-entries (file date &rest args)
  4348. "Does the work for `org-diary' and `org-agenda'.
  4349. FILE is the path to a file to be checked for entries. DATE is date like
  4350. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4351. which kind of entries should be extracted. For details about these, see
  4352. the documentation of `org-diary'."
  4353. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4354. (let* ((org-startup-folded nil)
  4355. (org-startup-align-all-tables nil)
  4356. (buffer (if (file-exists-p file)
  4357. (org-get-agenda-file-buffer file)
  4358. (error "No such file %s" file)))
  4359. arg results rtn deadline-results)
  4360. (if (not buffer)
  4361. ;; If file does not exist, make sure an error message ends up in diary
  4362. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4363. (with-current-buffer buffer
  4364. (unless (eq major-mode 'org-mode)
  4365. (error "Agenda file %s is not in `org-mode'" file))
  4366. (let ((case-fold-search nil))
  4367. (save-excursion
  4368. (save-restriction
  4369. (if org-agenda-restrict
  4370. (narrow-to-region org-agenda-restrict-begin
  4371. org-agenda-restrict-end)
  4372. (widen))
  4373. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4374. (while (setq arg (pop args))
  4375. (cond
  4376. ((and (eq arg :todo)
  4377. (equal date (calendar-gregorian-from-absolute
  4378. (org-today))))
  4379. (setq rtn (org-agenda-get-todos))
  4380. (setq results (append results rtn)))
  4381. ((eq arg :timestamp)
  4382. (setq rtn (org-agenda-get-blocks))
  4383. (setq results (append results rtn))
  4384. (setq rtn (org-agenda-get-timestamps))
  4385. (setq results (append results rtn)))
  4386. ((eq arg :sexp)
  4387. (setq rtn (org-agenda-get-sexps))
  4388. (setq results (append results rtn)))
  4389. ((eq arg :scheduled)
  4390. (setq rtn (org-agenda-get-scheduled deadline-results))
  4391. (setq results (append results rtn)))
  4392. ((eq arg :closed)
  4393. (setq rtn (org-agenda-get-progress))
  4394. (setq results (append results rtn)))
  4395. ((eq arg :deadline)
  4396. (setq rtn (org-agenda-get-deadlines))
  4397. (setq deadline-results (copy-sequence rtn))
  4398. (setq results (append results rtn))))))))
  4399. results))))
  4400. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4401. (defun org-agenda-get-todos ()
  4402. "Return the TODO information for agenda display."
  4403. (let* ((props (list 'face nil
  4404. 'done-face 'org-agenda-done
  4405. 'org-not-done-regexp org-not-done-regexp
  4406. 'org-todo-regexp org-todo-regexp
  4407. 'org-complex-heading-regexp org-complex-heading-regexp
  4408. 'mouse-face 'highlight
  4409. 'help-echo
  4410. (format "mouse-2 or RET jump to org file %s"
  4411. (abbreviate-file-name buffer-file-name))))
  4412. (regexp (format org-heading-keyword-regexp-format
  4413. (cond
  4414. ((and org-select-this-todo-keyword
  4415. (equal org-select-this-todo-keyword "*"))
  4416. org-todo-regexp)
  4417. (org-select-this-todo-keyword
  4418. (concat "\\("
  4419. (mapconcat 'identity
  4420. (org-split-string
  4421. org-select-this-todo-keyword
  4422. "|")
  4423. "\\|") "\\)"))
  4424. (t org-not-done-regexp))))
  4425. marker priority category org-category-pos tags todo-state
  4426. ee txt beg end)
  4427. (goto-char (point-min))
  4428. (while (re-search-forward regexp nil t)
  4429. (catch :skip
  4430. (save-match-data
  4431. (beginning-of-line)
  4432. (org-agenda-skip)
  4433. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4434. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4435. (goto-char (1+ beg))
  4436. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4437. (throw :skip nil)))
  4438. (goto-char (match-beginning 2))
  4439. (setq marker (org-agenda-new-marker (match-beginning 0))
  4440. category (org-get-category)
  4441. org-category-pos (get-text-property (point) 'org-category-position)
  4442. txt (org-trim
  4443. (buffer-substring (match-beginning 2) (match-end 0)))
  4444. tags (org-get-tags-at (point))
  4445. txt (org-agenda-format-item "" txt category tags)
  4446. priority (1+ (org-get-priority txt))
  4447. todo-state (org-get-todo-state))
  4448. (org-add-props txt props
  4449. 'org-marker marker 'org-hd-marker marker
  4450. 'priority priority 'org-category category
  4451. 'org-category-position org-category-pos
  4452. 'type "todo" 'todo-state todo-state)
  4453. (push txt ee)
  4454. (if org-agenda-todo-list-sublevels
  4455. (goto-char (match-end 2))
  4456. (org-end-of-subtree 'invisible))))
  4457. (nreverse ee)))
  4458. (defun org-agenda-todo-custom-ignore-p (time n)
  4459. "Check whether timestamp is farther away then n number of days.
  4460. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4461. `org-agenda-todo-ignore-scheduled' or
  4462. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4463. (let ((days (org-days-to-time time)))
  4464. (if (>= n 0)
  4465. (>= days n)
  4466. (<= days n))))
  4467. ;;;###autoload
  4468. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4469. (&optional end)
  4470. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4471. (when (or org-agenda-todo-ignore-with-date
  4472. org-agenda-todo-ignore-scheduled
  4473. org-agenda-todo-ignore-deadlines
  4474. org-agenda-todo-ignore-timestamp)
  4475. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4476. (save-excursion
  4477. (or (and org-agenda-todo-ignore-with-date
  4478. (re-search-forward org-ts-regexp end t))
  4479. (and org-agenda-todo-ignore-scheduled
  4480. (re-search-forward org-scheduled-time-regexp end t)
  4481. (cond
  4482. ((eq org-agenda-todo-ignore-scheduled 'future)
  4483. (> (org-days-to-time (match-string 1)) 0))
  4484. ((eq org-agenda-todo-ignore-scheduled 'past)
  4485. (<= (org-days-to-time (match-string 1)) 0))
  4486. ((numberp org-agenda-todo-ignore-scheduled)
  4487. (org-agenda-todo-custom-ignore-p
  4488. (match-string 1) org-agenda-todo-ignore-scheduled))
  4489. (t)))
  4490. (and org-agenda-todo-ignore-deadlines
  4491. (re-search-forward org-deadline-time-regexp end t)
  4492. (cond
  4493. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4494. ((eq org-agenda-todo-ignore-deadlines 'far)
  4495. (not (org-deadline-close (match-string 1))))
  4496. ((eq org-agenda-todo-ignore-deadlines 'future)
  4497. (> (org-days-to-time (match-string 1)) 0))
  4498. ((eq org-agenda-todo-ignore-deadlines 'past)
  4499. (<= (org-days-to-time (match-string 1)) 0))
  4500. ((numberp org-agenda-todo-ignore-deadlines)
  4501. (org-agenda-todo-custom-ignore-p
  4502. (match-string 1) org-agenda-todo-ignore-deadlines))
  4503. (t (org-deadline-close (match-string 1)))))
  4504. (and org-agenda-todo-ignore-timestamp
  4505. (let ((buffer (current-buffer))
  4506. (regexp
  4507. (concat
  4508. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4509. (start (point)))
  4510. ;; Copy current buffer into a temporary one
  4511. (with-temp-buffer
  4512. (insert-buffer-substring buffer start end)
  4513. (goto-char (point-min))
  4514. ;; Delete SCHEDULED and DEADLINE items
  4515. (while (re-search-forward regexp end t)
  4516. (delete-region (match-beginning 0) (match-end 0)))
  4517. (goto-char (point-min))
  4518. ;; No search for timestamp left
  4519. (when (re-search-forward org-ts-regexp nil t)
  4520. (cond
  4521. ((eq org-agenda-todo-ignore-timestamp 'future)
  4522. (> (org-days-to-time (match-string 1)) 0))
  4523. ((eq org-agenda-todo-ignore-timestamp 'past)
  4524. (<= (org-days-to-time (match-string 1)) 0))
  4525. ((numberp org-agenda-todo-ignore-timestamp)
  4526. (org-agenda-todo-custom-ignore-p
  4527. (match-string 1) org-agenda-todo-ignore-timestamp))
  4528. (t))))))))))
  4529. (defconst org-agenda-no-heading-message
  4530. "No heading for this item in buffer or region.")
  4531. (defun org-agenda-get-timestamps ()
  4532. "Return the date stamp information for agenda display."
  4533. (let* ((props (list 'face 'org-agenda-calendar-event
  4534. 'org-not-done-regexp org-not-done-regexp
  4535. 'org-todo-regexp org-todo-regexp
  4536. 'org-complex-heading-regexp org-complex-heading-regexp
  4537. 'mouse-face 'highlight
  4538. 'help-echo
  4539. (format "mouse-2 or RET jump to org file %s"
  4540. (abbreviate-file-name buffer-file-name))))
  4541. (d1 (calendar-absolute-from-gregorian date))
  4542. (remove-re
  4543. (concat
  4544. (regexp-quote
  4545. (format-time-string
  4546. "<%Y-%m-%d"
  4547. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4548. ".*?>"))
  4549. (regexp
  4550. (concat
  4551. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4552. (regexp-quote
  4553. (substring
  4554. (format-time-string
  4555. (car org-time-stamp-formats)
  4556. (apply 'encode-time ; DATE bound by calendar
  4557. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4558. 1 11))
  4559. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4560. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4561. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4562. donep tmp priority category org-category-pos ee txt timestr tags
  4563. b0 b3 e3 head todo-state end-of-match show-all)
  4564. (goto-char (point-min))
  4565. (while (setq end-of-match (re-search-forward regexp nil t))
  4566. (setq b0 (match-beginning 0)
  4567. b3 (match-beginning 3) e3 (match-end 3)
  4568. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4569. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4570. (member todo-state
  4571. org-agenda-repeating-timestamp-show-all)))
  4572. (catch :skip
  4573. (and (org-at-date-range-p) (throw :skip nil))
  4574. (org-agenda-skip)
  4575. (if (and (match-end 1)
  4576. (not (= d1 (org-time-string-to-absolute
  4577. (match-string 1) d1 nil show-all
  4578. (current-buffer) b0))))
  4579. (throw :skip nil))
  4580. (if (and e3
  4581. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4582. (throw :skip nil))
  4583. (setq tmp (buffer-substring (max (point-min)
  4584. (- b0 org-ds-keyword-length))
  4585. b0)
  4586. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4587. inactivep (= (char-after b0) ?\[)
  4588. deadlinep (string-match org-deadline-regexp tmp)
  4589. scheduledp (string-match org-scheduled-regexp tmp)
  4590. closedp (and org-agenda-include-inactive-timestamps
  4591. (string-match org-closed-string tmp))
  4592. clockp (and org-agenda-include-inactive-timestamps
  4593. (or (string-match org-clock-string tmp)
  4594. (string-match "]-+\\'" tmp)))
  4595. donep (member todo-state org-done-keywords))
  4596. (if (or scheduledp deadlinep closedp clockp
  4597. (and donep org-agenda-skip-timestamp-if-done))
  4598. (throw :skip t))
  4599. (if (string-match ">" timestr)
  4600. ;; substring should only run to end of time stamp
  4601. (setq timestr (substring timestr 0 (match-end 0))))
  4602. (setq marker (org-agenda-new-marker b0)
  4603. category (org-get-category b0)
  4604. org-category-pos (get-text-property b0 'org-category-position))
  4605. (save-excursion
  4606. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4607. (setq txt org-agenda-no-heading-message)
  4608. (goto-char (match-beginning 0))
  4609. (setq hdmarker (org-agenda-new-marker)
  4610. tags (org-get-tags-at))
  4611. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4612. (setq head (or (match-string 1) ""))
  4613. (setq txt (org-agenda-format-item
  4614. (if inactivep org-agenda-inactive-leader nil)
  4615. head category tags timestr
  4616. remove-re)))
  4617. (setq priority (org-get-priority txt))
  4618. (org-add-props txt props
  4619. 'org-marker marker 'org-hd-marker hdmarker)
  4620. (org-add-props txt nil 'priority priority
  4621. 'org-category category 'date date
  4622. 'org-category-position org-category-pos
  4623. 'todo-state todo-state
  4624. 'type "timestamp")
  4625. (push txt ee))
  4626. (if org-agenda-skip-additional-timestamps-same-entry
  4627. (outline-next-heading)
  4628. (goto-char end-of-match))))
  4629. (nreverse ee)))
  4630. (defun org-agenda-get-sexps ()
  4631. "Return the sexp information for agenda display."
  4632. (require 'diary-lib)
  4633. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4634. 'mouse-face 'highlight
  4635. 'help-echo
  4636. (format "mouse-2 or RET jump to org file %s"
  4637. (abbreviate-file-name buffer-file-name))))
  4638. (regexp "^&?%%(")
  4639. marker category org-category-pos ee txt tags entry
  4640. result beg b sexp sexp-entry todo-state)
  4641. (goto-char (point-min))
  4642. (while (re-search-forward regexp nil t)
  4643. (catch :skip
  4644. (org-agenda-skip)
  4645. (setq beg (match-beginning 0))
  4646. (goto-char (1- (match-end 0)))
  4647. (setq b (point))
  4648. (forward-sexp 1)
  4649. (setq sexp (buffer-substring b (point)))
  4650. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4651. (org-trim (match-string 1))
  4652. ""))
  4653. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4654. (when result
  4655. (setq marker (org-agenda-new-marker beg)
  4656. category (org-get-category beg)
  4657. org-category-pos (get-text-property beg 'org-category-position)
  4658. todo-state (org-get-todo-state))
  4659. (dolist (r (if (stringp result)
  4660. (list result)
  4661. result)) ;; we expect a list here
  4662. (if (string-match "\\S-" r)
  4663. (setq txt r)
  4664. (setq txt "SEXP entry returned empty string"))
  4665. (setq txt (org-agenda-format-item
  4666. "" txt category tags 'time))
  4667. (org-add-props txt props 'org-marker marker)
  4668. (org-add-props txt nil
  4669. 'org-category category 'date date 'todo-state todo-state
  4670. 'org-category-position org-category-pos
  4671. 'type "sexp")
  4672. (push txt ee)))))
  4673. (nreverse ee)))
  4674. ;; Calendar sanity: define some functions that are independent of
  4675. ;; `calendar-date-style'.
  4676. ;; Normally I would like to use ISO format when calling the diary functions,
  4677. ;; but to make sure we still have Emacs 22 compatibility we bind
  4678. ;; also `european-calendar-style' and use european format
  4679. (defun org-anniversary (year month day &optional mark)
  4680. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4681. (org-no-warnings
  4682. (let ((calendar-date-style 'european) (european-calendar-style t))
  4683. (diary-anniversary day month year mark))))
  4684. (defun org-cyclic (N year month day &optional mark)
  4685. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4686. (org-no-warnings
  4687. (let ((calendar-date-style 'european) (european-calendar-style t))
  4688. (diary-cyclic N day month year mark))))
  4689. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4690. "Like `diary-block', but with fixed (ISO) order of arguments."
  4691. (org-no-warnings
  4692. (let ((calendar-date-style 'european) (european-calendar-style t))
  4693. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4694. (defun org-date (year month day &optional mark)
  4695. "Like `diary-date', but with fixed (ISO) order of arguments."
  4696. (org-no-warnings
  4697. (let ((calendar-date-style 'european) (european-calendar-style t))
  4698. (diary-date day month year mark))))
  4699. (defalias 'org-float 'diary-float)
  4700. ;; Define the` org-class' function
  4701. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4702. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4703. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4704. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4705. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4706. `holidays', then any date that is known by the Emacs calendar to be a
  4707. holiday will also be skipped."
  4708. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4709. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4710. (d (calendar-absolute-from-gregorian date)))
  4711. (and
  4712. (<= date1 d)
  4713. (<= d date2)
  4714. (= (calendar-day-of-week date) dayname)
  4715. (or (not skip-weeks)
  4716. (progn
  4717. (require 'cal-iso)
  4718. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4719. (not (and (memq 'holidays skip-weeks)
  4720. (calendar-check-holidays date)))
  4721. entry)))
  4722. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4723. "Like `org-class', but honor `calendar-date-style'.
  4724. The order of the first 2 times 3 arguments depends on the variable
  4725. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4726. So for American calendars, give this as MONTH DAY YEAR, for European as
  4727. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4728. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4729. is any number of ISO weeks in the block period for which the item should
  4730. be skipped.
  4731. This function is here only for backward compatibility and it is deprecated,
  4732. please use `org-class' instead."
  4733. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4734. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4735. (org-class
  4736. (nth 2 date1) (car date1) (nth 1 date1)
  4737. (nth 2 date2) (car date2) (nth 1 date2)
  4738. dayname skip-weeks)))
  4739. (make-obsolete 'org-diary-class 'org-class "")
  4740. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4741. (defalias 'org-get-closed 'org-agenda-get-progress)
  4742. (defun org-agenda-get-progress ()
  4743. "Return the logged TODO entries for agenda display."
  4744. (let* ((props (list 'mouse-face 'highlight
  4745. 'org-not-done-regexp org-not-done-regexp
  4746. 'org-todo-regexp org-todo-regexp
  4747. 'org-complex-heading-regexp org-complex-heading-regexp
  4748. 'help-echo
  4749. (format "mouse-2 or RET jump to org file %s"
  4750. (abbreviate-file-name buffer-file-name))))
  4751. (items (if (consp org-agenda-show-log-scoped)
  4752. org-agenda-show-log-scoped
  4753. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4754. '(clock)
  4755. org-agenda-log-mode-items)))
  4756. (parts
  4757. (delq nil
  4758. (list
  4759. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4760. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4761. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4762. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4763. (error "`org-agenda-log-mode-items' is empty")))
  4764. (regexp (concat
  4765. "\\(" parts-re "\\)"
  4766. " *\\["
  4767. (regexp-quote
  4768. (substring
  4769. (format-time-string
  4770. (car org-time-stamp-formats)
  4771. (apply 'encode-time ; DATE bound by calendar
  4772. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4773. 1 11))))
  4774. (org-agenda-search-headline-for-time nil)
  4775. marker hdmarker priority category org-category-pos tags closedp
  4776. statep clockp state ee txt extra timestr rest clocked)
  4777. (goto-char (point-min))
  4778. (while (re-search-forward regexp nil t)
  4779. (catch :skip
  4780. (org-agenda-skip)
  4781. (setq marker (org-agenda-new-marker (match-beginning 0))
  4782. closedp (equal (match-string 1) org-closed-string)
  4783. statep (equal (string-to-char (match-string 1)) ?-)
  4784. clockp (not (or closedp statep))
  4785. state (and statep (match-string 2))
  4786. category (org-get-category (match-beginning 0))
  4787. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4788. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4789. (when (string-match "\\]" timestr)
  4790. ;; substring should only run to end of time stamp
  4791. (setq rest (substring timestr (match-end 0))
  4792. timestr (substring timestr 0 (match-end 0)))
  4793. (if (and (not closedp) (not statep)
  4794. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4795. rest))
  4796. (progn (setq timestr (concat (substring timestr 0 -1)
  4797. "-" (match-string 1 rest) "]"))
  4798. (setq clocked (match-string 2 rest)))
  4799. (setq clocked "-")))
  4800. (save-excursion
  4801. (setq extra
  4802. (cond
  4803. ((not org-agenda-log-mode-add-notes) nil)
  4804. (statep
  4805. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4806. (match-string 1)))
  4807. (clockp
  4808. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4809. (match-string 1)))))
  4810. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4811. (setq txt org-agenda-no-heading-message)
  4812. (goto-char (match-beginning 0))
  4813. (setq hdmarker (org-agenda-new-marker)
  4814. tags (org-get-tags-at))
  4815. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4816. (setq txt (match-string 1))
  4817. (when extra
  4818. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4819. (setq txt (concat (substring txt 0 (match-beginning 1))
  4820. " - " extra " " (match-string 2 txt)))
  4821. (setq txt (concat txt " - " extra))))
  4822. (setq txt (org-agenda-format-item
  4823. (cond
  4824. (closedp "Closed: ")
  4825. (statep (concat "State: (" state ")"))
  4826. (t (concat "Clocked: (" clocked ")")))
  4827. txt category tags timestr)))
  4828. (setq priority 100000)
  4829. (org-add-props txt props
  4830. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4831. 'priority priority 'org-category category
  4832. 'org-category-position org-category-pos
  4833. 'type "closed" 'date date
  4834. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4835. (push txt ee))
  4836. (goto-char (point-at-eol))))
  4837. (nreverse ee)))
  4838. (defun org-agenda-show-clocking-issues ()
  4839. "Add overlays, showing issues with clocking.
  4840. See also the user option `org-agenda-clock-consistency-checks'."
  4841. (interactive)
  4842. (let* ((pl org-agenda-clock-consistency-checks)
  4843. (re (concat "^[ \t]*"
  4844. org-clock-string
  4845. "[ \t]+"
  4846. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4847. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4848. (tlstart 0.)
  4849. (tlend 0.)
  4850. (maxtime (org-hh:mm-string-to-minutes
  4851. (or (plist-get pl :max-duration) "24:00")))
  4852. (mintime (org-hh:mm-string-to-minutes
  4853. (or (plist-get pl :min-duration) 0)))
  4854. (maxgap (org-hh:mm-string-to-minutes
  4855. ;; default 30:00 means never complain
  4856. (or (plist-get pl :max-gap) "30:00")))
  4857. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4858. (plist-get pl :gap-ok-around)))
  4859. (def-face (or (plist-get pl :default-face)
  4860. '((:background "DarkRed") (:foreground "white"))))
  4861. issue face m te ts dt ov)
  4862. (goto-char (point-min))
  4863. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4864. (setq issue nil face def-face)
  4865. (catch 'next
  4866. (setq m (org-get-at-bol 'org-marker)
  4867. te nil ts nil)
  4868. (unless (and m (markerp m))
  4869. (setq issue "No valid clock line") (throw 'next t))
  4870. (org-with-point-at m
  4871. (save-excursion
  4872. (goto-char (point-at-bol))
  4873. (unless (looking-at re)
  4874. (error "No valid Clock line")
  4875. (throw 'next t))
  4876. (unless (match-end 3)
  4877. (setq issue "No end time"
  4878. face (or (plist-get pl :no-end-time-face) face))
  4879. (throw 'next t))
  4880. (setq ts (match-string 1)
  4881. te (match-string 3)
  4882. ts (org-float-time
  4883. (apply 'encode-time (org-parse-time-string ts)))
  4884. te (org-float-time
  4885. (apply 'encode-time (org-parse-time-string te)))
  4886. dt (- te ts))))
  4887. (cond
  4888. ((> dt (* 60 maxtime))
  4889. ;; a very long clocking chunk
  4890. (setq issue (format "Clocking interval is very long: %s"
  4891. (org-minutes-to-hh:mm-string
  4892. (floor (/ (float dt) 60.))))
  4893. face (or (plist-get pl :long-face) face)))
  4894. ((< dt (* 60 mintime))
  4895. ;; a very short clocking chunk
  4896. (setq issue (format "Clocking interval is very short: %s"
  4897. (org-minutes-to-hh:mm-string
  4898. (floor (/ (float dt) 60.))))
  4899. face (or (plist-get pl :short-face) face)))
  4900. ((and (> tlend 0) (< ts tlend))
  4901. ;; Two clock entries are overlapping
  4902. (setq issue (format "Clocking overlap: %d minutes"
  4903. (/ (- tlend ts) 60))
  4904. face (or (plist-get pl :overlap-face) face)))
  4905. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4906. ;; There is a gap, lets see if we need to report it
  4907. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4908. (setq issue (format "Clocking gap: %d minutes"
  4909. (/ (- ts tlend) 60))
  4910. face (or (plist-get pl :gap-face) face))))
  4911. (t nil)))
  4912. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4913. (when issue
  4914. ;; OK, there was some issue, add an overlay to show the issue
  4915. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4916. (overlay-put ov 'before-string
  4917. (concat
  4918. (org-add-props
  4919. (format "%-43s" (concat " " issue))
  4920. nil
  4921. 'face face)
  4922. "\n"))
  4923. (overlay-put ov 'evaporate t)))))
  4924. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4925. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4926. (catch 'exit
  4927. (unless ok-list
  4928. ;; there are no OK times for gaps...
  4929. (throw 'exit nil))
  4930. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4931. ;; This is more than 24 hours, so it is OK.
  4932. ;; because we have at least one OK time, that must be in the
  4933. ;; 24 hour interval.
  4934. (throw 'exit t))
  4935. ;; We have a shorter gap.
  4936. ;; Now we have to get the minute of the day when these times are
  4937. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4938. (t2dec (decode-time (seconds-to-time t2)))
  4939. ;; compute the minute on the day
  4940. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4941. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4942. (when (< min2 min1)
  4943. ;; if min2 is smaller than min1, this means it is on the next day.
  4944. ;; Wrap it to after midnight.
  4945. (setq min2 (+ min2 1440)))
  4946. ;; Now check if any of the OK times is in the gap
  4947. (mapc (lambda (x)
  4948. ;; Wrap the time to after midnight if necessary
  4949. (if (< x min1) (setq x (+ x 1440)))
  4950. ;; Check if in interval
  4951. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4952. ok-list)
  4953. ;; Nope, this gap is not OK
  4954. nil)))
  4955. (defun org-agenda-get-deadlines ()
  4956. "Return the deadline information for agenda display."
  4957. (let* ((props (list 'mouse-face 'highlight
  4958. 'org-not-done-regexp org-not-done-regexp
  4959. 'org-todo-regexp org-todo-regexp
  4960. 'org-complex-heading-regexp org-complex-heading-regexp
  4961. 'help-echo
  4962. (format "mouse-2 or RET jump to org file %s"
  4963. (abbreviate-file-name buffer-file-name))))
  4964. (regexp org-deadline-time-regexp)
  4965. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4966. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4967. d2 diff dfrac wdays pos pos1 category org-category-pos
  4968. tags suppress-prewarning ee txt head face s todo-state
  4969. show-all upcomingp donep timestr)
  4970. (goto-char (point-min))
  4971. (while (re-search-forward regexp nil t)
  4972. (setq suppress-prewarning nil)
  4973. (catch :skip
  4974. (org-agenda-skip)
  4975. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4976. (save-match-data
  4977. (string-match org-scheduled-time-regexp
  4978. (buffer-substring (point-at-bol)
  4979. (point-at-eol)))))
  4980. (setq suppress-prewarning
  4981. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4982. org-agenda-skip-deadline-prewarning-if-scheduled
  4983. 0)))
  4984. (setq s (match-string 1)
  4985. txt nil
  4986. pos (1- (match-beginning 1))
  4987. todo-state (save-match-data (org-get-todo-state))
  4988. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4989. (member todo-state
  4990. org-agenda-repeating-timestamp-show-all))
  4991. d2 (org-time-string-to-absolute
  4992. (match-string 1) d1 'past show-all
  4993. (current-buffer) pos)
  4994. diff (- d2 d1)
  4995. wdays (if suppress-prewarning
  4996. (let ((org-deadline-warning-days suppress-prewarning))
  4997. (org-get-wdays s))
  4998. (org-get-wdays s))
  4999. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5000. upcomingp (and todayp (> diff 0)))
  5001. ;; When to show a deadline in the calendar:
  5002. ;; If the expiration is within wdays warning time.
  5003. ;; Past-due deadlines are only shown on the current date
  5004. (if (and (or (and (<= diff wdays)
  5005. (and todayp (not org-agenda-only-exact-dates)))
  5006. (= diff 0)))
  5007. (save-excursion
  5008. ;; (setq todo-state (org-get-todo-state))
  5009. (setq donep (member todo-state org-done-keywords))
  5010. (if (and donep
  5011. (or org-agenda-skip-deadline-if-done
  5012. (not (= diff 0))))
  5013. (setq txt nil)
  5014. (setq category (org-get-category)
  5015. org-category-pos (get-text-property (point) 'org-category-position))
  5016. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5017. (setq txt org-agenda-no-heading-message)
  5018. (goto-char (match-end 0))
  5019. (setq pos1 (match-beginning 0))
  5020. (setq tags (org-get-tags-at pos1))
  5021. (setq head (buffer-substring-no-properties
  5022. (point)
  5023. (progn (skip-chars-forward "^\r\n")
  5024. (point))))
  5025. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5026. (setq timestr
  5027. (concat (substring s (match-beginning 1)) " "))
  5028. (setq timestr 'time))
  5029. (setq txt (org-agenda-format-item
  5030. (if (= diff 0)
  5031. (car org-agenda-deadline-leaders)
  5032. (if (functionp
  5033. (nth 1 org-agenda-deadline-leaders))
  5034. (funcall
  5035. (nth 1 org-agenda-deadline-leaders)
  5036. diff date)
  5037. (format (nth 1 org-agenda-deadline-leaders)
  5038. diff)))
  5039. head category tags
  5040. (if (not (= diff 0)) nil timestr)))))
  5041. (when txt
  5042. (setq face (org-agenda-deadline-face dfrac))
  5043. (org-add-props txt props
  5044. 'org-marker (org-agenda-new-marker pos)
  5045. 'org-hd-marker (org-agenda-new-marker pos1)
  5046. 'priority (+ (- diff)
  5047. (org-get-priority txt))
  5048. 'org-category category
  5049. 'org-category-position org-category-pos
  5050. 'todo-state todo-state
  5051. 'type (if upcomingp "upcoming-deadline" "deadline")
  5052. 'date (if upcomingp date d2)
  5053. 'face (if donep 'org-agenda-done face)
  5054. 'undone-face face 'done-face 'org-agenda-done)
  5055. (push txt ee))))))
  5056. (nreverse ee)))
  5057. (defun org-agenda-deadline-face (fraction)
  5058. "Return the face to displaying a deadline item.
  5059. FRACTION is what fraction of the head-warning time has passed."
  5060. (let ((faces org-agenda-deadline-faces) f)
  5061. (catch 'exit
  5062. (while (setq f (pop faces))
  5063. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5064. (defun org-agenda-get-scheduled (&optional deadline-results)
  5065. "Return the scheduled information for agenda display."
  5066. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5067. 'org-todo-regexp org-todo-regexp
  5068. 'org-complex-heading-regexp org-complex-heading-regexp
  5069. 'done-face 'org-agenda-done
  5070. 'mouse-face 'highlight
  5071. 'help-echo
  5072. (format "mouse-2 or RET jump to org file %s"
  5073. (abbreviate-file-name buffer-file-name))))
  5074. (regexp org-scheduled-time-regexp)
  5075. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5076. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5077. mm
  5078. (deadline-position-alist
  5079. (mapcar (lambda (a) (and (setq mm (get-text-property
  5080. 0 'org-hd-marker a))
  5081. (cons (marker-position mm) a)))
  5082. deadline-results))
  5083. d2 diff pos pos1 category org-category-pos tags donep
  5084. ee txt head pastschedp todo-state face timestr s habitp show-all)
  5085. (goto-char (point-min))
  5086. (while (re-search-forward regexp nil t)
  5087. (catch :skip
  5088. (org-agenda-skip)
  5089. (setq s (match-string 1)
  5090. txt nil
  5091. pos (1- (match-beginning 1))
  5092. todo-state (save-match-data (org-get-todo-state))
  5093. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5094. (member todo-state
  5095. org-agenda-repeating-timestamp-show-all))
  5096. d2 (org-time-string-to-absolute
  5097. (match-string 1) d1 'past show-all
  5098. (current-buffer) pos)
  5099. diff (- d2 d1))
  5100. (setq pastschedp (and todayp (< diff 0)))
  5101. ;; When to show a scheduled item in the calendar:
  5102. ;; If it is on or past the date.
  5103. (when (or (and (< diff 0)
  5104. (< (abs diff) org-scheduled-past-days)
  5105. (and todayp (not org-agenda-only-exact-dates)))
  5106. (= diff 0))
  5107. (save-excursion
  5108. (setq donep (member todo-state org-done-keywords))
  5109. (if (and donep
  5110. (or org-agenda-skip-scheduled-if-done
  5111. (not (= diff 0))
  5112. (and (functionp 'org-is-habit-p)
  5113. (org-is-habit-p))))
  5114. (setq txt nil)
  5115. (setq habitp (and (functionp 'org-is-habit-p)
  5116. (org-is-habit-p)))
  5117. (setq category (org-get-category)
  5118. org-category-pos (get-text-property (point) 'org-category-position))
  5119. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5120. (setq txt org-agenda-no-heading-message)
  5121. (goto-char (match-end 0))
  5122. (setq pos1 (match-beginning 0))
  5123. (if habitp
  5124. (if (or (not org-habit-show-habits)
  5125. (and (not todayp)
  5126. org-habit-show-habits-only-for-today))
  5127. (throw :skip nil))
  5128. (if (and
  5129. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5130. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5131. pastschedp))
  5132. (setq mm (assoc pos1 deadline-position-alist)))
  5133. (throw :skip nil)))
  5134. (setq tags (org-get-tags-at))
  5135. (setq head (buffer-substring-no-properties
  5136. (point)
  5137. (progn (skip-chars-forward "^\r\n") (point))))
  5138. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5139. (setq timestr
  5140. (concat (substring s (match-beginning 1)) " "))
  5141. (setq timestr 'time))
  5142. (setq txt (org-agenda-format-item
  5143. (if (= diff 0)
  5144. (car org-agenda-scheduled-leaders)
  5145. (format (nth 1 org-agenda-scheduled-leaders)
  5146. (- 1 diff)))
  5147. head category tags
  5148. (if (not (= diff 0)) nil timestr)
  5149. nil habitp))))
  5150. (when txt
  5151. (setq face
  5152. (cond
  5153. ((and (not habitp) pastschedp)
  5154. 'org-scheduled-previously)
  5155. (todayp 'org-scheduled-today)
  5156. (t 'org-scheduled))
  5157. habitp (and habitp (org-habit-parse-todo)))
  5158. (org-add-props txt props
  5159. 'undone-face face
  5160. 'face (if donep 'org-agenda-done face)
  5161. 'org-marker (org-agenda-new-marker pos)
  5162. 'org-hd-marker (org-agenda-new-marker pos1)
  5163. 'type (if pastschedp "past-scheduled" "scheduled")
  5164. 'date (if pastschedp d2 date)
  5165. 'priority (if habitp
  5166. (org-habit-get-priority habitp)
  5167. (+ 94 (- 5 diff) (org-get-priority txt)))
  5168. 'org-category category
  5169. 'org-category-position org-category-pos
  5170. 'org-habit-p habitp
  5171. 'todo-state todo-state)
  5172. (push txt ee))))))
  5173. (nreverse ee)))
  5174. (defun org-agenda-get-blocks ()
  5175. "Return the date-range information for agenda display."
  5176. (let* ((props (list 'face nil
  5177. 'org-not-done-regexp org-not-done-regexp
  5178. 'org-todo-regexp org-todo-regexp
  5179. 'org-complex-heading-regexp org-complex-heading-regexp
  5180. 'mouse-face 'highlight
  5181. 'help-echo
  5182. (format "mouse-2 or RET jump to org file %s"
  5183. (abbreviate-file-name buffer-file-name))))
  5184. (regexp org-tr-regexp)
  5185. (d0 (calendar-absolute-from-gregorian date))
  5186. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5187. todo-state tags pos head donep)
  5188. (goto-char (point-min))
  5189. (while (re-search-forward regexp nil t)
  5190. (catch :skip
  5191. (org-agenda-skip)
  5192. (setq pos (point))
  5193. (let ((start-time (match-string 1))
  5194. (end-time (match-string 2)))
  5195. (setq s1 (match-string 1)
  5196. s2 (match-string 2)
  5197. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5198. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5199. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5200. ;; Only allow days between the limits, because the normal
  5201. ;; date stamps will catch the limits.
  5202. (save-excursion
  5203. (setq todo-state (org-get-todo-state))
  5204. (setq donep (member todo-state org-done-keywords))
  5205. (if (and donep org-agenda-skip-timestamp-if-done)
  5206. (throw :skip t))
  5207. (setq marker (org-agenda-new-marker (point)))
  5208. (setq category (org-get-category)
  5209. org-category-pos (get-text-property (point) 'org-category-position))
  5210. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5211. (setq txt org-agenda-no-heading-message)
  5212. (goto-char (match-beginning 0))
  5213. (setq hdmarker (org-agenda-new-marker (point)))
  5214. (setq tags (org-get-tags-at))
  5215. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5216. (setq head (match-string 1))
  5217. (let ((remove-re
  5218. (if org-agenda-remove-timeranges-from-blocks
  5219. (concat
  5220. "<" (regexp-quote s1) ".*?>"
  5221. "--"
  5222. "<" (regexp-quote s2) ".*?>")
  5223. nil)))
  5224. (setq txt (org-agenda-format-item
  5225. (format
  5226. (nth (if (= d1 d2) 0 1)
  5227. org-agenda-timerange-leaders)
  5228. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5229. head category tags
  5230. (cond ((and (= d1 d0) (= d2 d0))
  5231. (concat "<" start-time ">--<" end-time ">"))
  5232. ((= d1 d0)
  5233. (concat "<" start-time ">"))
  5234. ((= d2 d0)
  5235. (concat "<" end-time ">"))
  5236. (t nil))
  5237. remove-re))))
  5238. (org-add-props txt props
  5239. 'org-marker marker 'org-hd-marker hdmarker
  5240. 'type "block" 'date date
  5241. 'todo-state todo-state
  5242. 'priority (org-get-priority txt) 'org-category category
  5243. 'org-category-position org-category-pos)
  5244. (push txt ee))))
  5245. (goto-char pos)))
  5246. ;; Sort the entries by expiration date.
  5247. (nreverse ee)))
  5248. ;;; Agenda presentation and sorting
  5249. (defvar org-prefix-has-time nil
  5250. "A flag, set by `org-compile-prefix-format'.
  5251. The flag is set if the currently compiled format contains a `%t'.")
  5252. (defvar org-prefix-has-tag nil
  5253. "A flag, set by `org-compile-prefix-format'.
  5254. The flag is set if the currently compiled format contains a `%T'.")
  5255. (defvar org-prefix-has-effort nil
  5256. "A flag, set by `org-compile-prefix-format'.
  5257. The flag is set if the currently compiled format contains a `%e'.")
  5258. (defvar org-prefix-category-length nil
  5259. "Used by `org-compile-prefix-format' to remember the category field width.")
  5260. (defvar org-prefix-category-max-length nil
  5261. "Used by `org-compile-prefix-format' to remember the category field width.")
  5262. (defun org-agenda-get-category-icon (category)
  5263. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5264. (dolist (entry org-agenda-category-icon-alist)
  5265. (when (org-string-match-p (car entry) category)
  5266. (if (listp (cadr entry))
  5267. (return (cadr entry))
  5268. (return (apply 'create-image (cdr entry)))))))
  5269. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5270. remove-re habitp)
  5271. "Format TXT to be inserted into the agenda buffer.
  5272. In particular, it adds the prefix and corresponding text properties. EXTRA
  5273. must be a string and replaces the `%s' specifier in the prefix format.
  5274. CATEGORY (string, symbol or nil) may be used to overrule the default
  5275. category taken from local variable or file name. It will replace the `%c'
  5276. specifier in the format. DOTIME, when non-nil, indicates that a
  5277. time-of-day should be extracted from TXT for sorting of this entry, and for
  5278. the `%t' specifier in the format. When DOTIME is a string, this string is
  5279. searched for a time before TXT is. TAGS can be the tags of the headline.
  5280. Any match of REMOVE-RE will be removed from TXT."
  5281. ;; We keep the org-prefix-* variable values along with a compiled
  5282. ;; formatter, so that multiple agendas existing at the same time, do
  5283. ;; not step on each other toes.
  5284. ;;
  5285. ;; It was inconvenient to make these variables buffer local in
  5286. ;; Agenda buffers, because this function expects to be called with
  5287. ;; the buffer where item comes from being current, and not agenda
  5288. ;; buffer
  5289. (let* ((bindings (car org-prefix-format-compiled))
  5290. (formatter (cadr org-prefix-format-compiled)))
  5291. (loop for (var value) in bindings
  5292. do (set var value))
  5293. (save-match-data
  5294. ;; Diary entries sometimes have extra whitespace at the beginning
  5295. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5296. ;; Fix the tags part in txt
  5297. (setq txt (org-agenda-fix-displayed-tags
  5298. txt tags
  5299. org-agenda-show-inherited-tags
  5300. org-agenda-hide-tags-regexp))
  5301. (let* ((category (or category
  5302. (if (stringp org-category)
  5303. org-category
  5304. (and org-category (symbol-name org-category)))
  5305. (if buffer-file-name
  5306. (file-name-sans-extension
  5307. (file-name-nondirectory buffer-file-name))
  5308. "")))
  5309. (category-icon (org-agenda-get-category-icon category))
  5310. (category-icon (if category-icon
  5311. (propertize " " 'display category-icon)
  5312. ""))
  5313. ;; time, tag, effort are needed for the eval of the prefix format
  5314. (tag (if tags (nth (1- (length tags)) tags) ""))
  5315. time effort neffort
  5316. (ts (if dotime (concat
  5317. (if (stringp dotime) dotime "")
  5318. (and org-agenda-search-headline-for-time txt))))
  5319. (time-of-day (and dotime (org-get-time-of-day ts)))
  5320. stamp plain s0 s1 s2 rtn srp l
  5321. duration thecategory)
  5322. (and (eq major-mode 'org-mode) buffer-file-name
  5323. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5324. (when (and dotime time-of-day)
  5325. ;; Extract starting and ending time and move them to prefix
  5326. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5327. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5328. (setq s0 (match-string 0 ts)
  5329. srp (and stamp (match-end 3))
  5330. s1 (match-string (if plain 1 2) ts)
  5331. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5332. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5333. ;; them, we might want to remove them there to avoid duplication.
  5334. ;; The user can turn this off with a variable.
  5335. (if (and org-prefix-has-time
  5336. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5337. (string-match (concat (regexp-quote s0) " *") txt)
  5338. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5339. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5340. (= (match-beginning 0) 0)
  5341. t))
  5342. (setq txt (replace-match "" nil nil txt))))
  5343. ;; Normalize the time(s) to 24 hour
  5344. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5345. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5346. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5347. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5348. (setq s2
  5349. (org-minutes-to-hh:mm-string
  5350. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5351. ;; Compute the duration
  5352. (when s2
  5353. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5354. (org-hh:mm-string-to-minutes s1)))))
  5355. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5356. txt)
  5357. ;; Tags are in the string
  5358. (if (or (eq org-agenda-remove-tags t)
  5359. (and org-agenda-remove-tags
  5360. org-prefix-has-tag))
  5361. (setq txt (replace-match "" t t txt))
  5362. (setq txt (replace-match
  5363. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5364. (match-string 2 txt))
  5365. t t txt))))
  5366. (when (eq major-mode 'org-mode)
  5367. (setq effort
  5368. (condition-case nil
  5369. (org-get-effort
  5370. (or (get-text-property 0 'org-hd-marker txt)
  5371. (get-text-property 0 'org-marker txt)))
  5372. (error nil)))
  5373. (when effort
  5374. (setq neffort (org-duration-string-to-minutes effort)
  5375. effort (setq effort (concat "[" effort "]")))))
  5376. ;; prevent erroring out with %e format when there is no effort
  5377. (or effort (setq effort ""))
  5378. (when remove-re
  5379. (while (string-match remove-re txt)
  5380. (setq txt (replace-match "" t t txt))))
  5381. ;; Set org-heading property on `txt' to mark the start of the
  5382. ;; heading.
  5383. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5384. ;; Prepare the variables needed in the eval of the compiled format
  5385. (setq time (cond (s2 (concat
  5386. (org-agenda-time-of-day-to-ampm-maybe s1)
  5387. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5388. (if org-agenda-timegrid-use-ampm " ")))
  5389. (s1 (concat
  5390. (org-agenda-time-of-day-to-ampm-maybe s1)
  5391. (if org-agenda-timegrid-use-ampm
  5392. "........ "
  5393. "......")))
  5394. (t ""))
  5395. extra (or (and (not habitp) extra) "")
  5396. category (if (symbolp category) (symbol-name category) category)
  5397. thecategory (copy-sequence category))
  5398. (if (string-match org-bracket-link-regexp category)
  5399. (progn
  5400. (setq l (if (match-end 3)
  5401. (- (match-end 3) (match-beginning 3))
  5402. (- (match-end 1) (match-beginning 1))))
  5403. (when (< l (or org-prefix-category-length 0))
  5404. (setq category (copy-sequence category))
  5405. (org-add-props category nil
  5406. 'extra-space (make-string
  5407. (- org-prefix-category-length l 1) ?\ ))))
  5408. (if (and org-prefix-category-max-length
  5409. (>= (length category) org-prefix-category-max-length))
  5410. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5411. ;; Evaluate the compiled format
  5412. (setq rtn (concat (eval formatter) txt))
  5413. ;; And finally add the text properties
  5414. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5415. (org-add-props rtn nil
  5416. 'org-category (if thecategory (downcase thecategory) category)
  5417. 'tags (mapcar 'org-downcase-keep-props tags)
  5418. 'org-highest-priority org-highest-priority
  5419. 'org-lowest-priority org-lowest-priority
  5420. 'time-of-day time-of-day
  5421. 'duration duration
  5422. 'effort effort
  5423. 'effort-minutes neffort
  5424. 'txt txt
  5425. 'time time
  5426. 'extra extra
  5427. 'format org-prefix-format-compiled
  5428. 'dotime dotime)))))
  5429. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5430. "Remove tags string from TXT, and add a modified list of tags.
  5431. The modified list may contain inherited tags, and tags matched by
  5432. `org-agenda-hide-tags-regexp' will be removed."
  5433. (when (or add-inherited hide-re)
  5434. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5435. (setq txt (substring txt 0 (match-beginning 0))))
  5436. (setq tags
  5437. (delq nil
  5438. (mapcar (lambda (tg)
  5439. (if (or (and hide-re (string-match hide-re tg))
  5440. (and (not add-inherited)
  5441. (get-text-property 0 'inherited tg)))
  5442. nil
  5443. tg))
  5444. tags)))
  5445. (when tags
  5446. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5447. i)
  5448. (setq txt (concat txt " :"
  5449. (mapconcat
  5450. (lambda (x)
  5451. (setq i (get-text-property 0 'inherited x))
  5452. (if (and have-i (not i))
  5453. (progn
  5454. (setq have-i nil)
  5455. (concat ":" x))
  5456. x))
  5457. tags ":")
  5458. (if have-i "::" ":"))))))
  5459. txt)
  5460. (defun org-downcase-keep-props (s)
  5461. (let ((props (text-properties-at 0 s)))
  5462. (setq s (downcase s))
  5463. (add-text-properties 0 (length s) props s)
  5464. s))
  5465. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5466. (defvar org-agenda-sorting-strategy-selected nil)
  5467. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5468. (catch 'exit
  5469. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5470. ((and todayp (member 'today (car org-agenda-time-grid))))
  5471. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5472. ((member 'weekly (car org-agenda-time-grid)))
  5473. (t (throw 'exit list)))
  5474. (let* ((have (delq nil (mapcar
  5475. (lambda (x) (get-text-property 1 'time-of-day x))
  5476. list)))
  5477. (string (nth 1 org-agenda-time-grid))
  5478. (gridtimes (nth 2 org-agenda-time-grid))
  5479. (req (car org-agenda-time-grid))
  5480. (remove (member 'remove-match req))
  5481. new time)
  5482. (if (and (member 'require-timed req) (not have))
  5483. ;; don't show empty grid
  5484. (throw 'exit list))
  5485. (while (setq time (pop gridtimes))
  5486. (unless (and remove (member time have))
  5487. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5488. (push (org-agenda-format-item
  5489. nil string "" nil
  5490. (concat (substring time 0 -2) ":" (substring time -2)))
  5491. new)
  5492. (put-text-property
  5493. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5494. (when (and todayp org-agenda-show-current-time-in-grid)
  5495. (push (org-agenda-format-item
  5496. nil
  5497. org-agenda-current-time-string
  5498. "" nil
  5499. (format-time-string "%H:%M "))
  5500. new)
  5501. (put-text-property
  5502. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5503. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5504. (append new list)
  5505. (append list new)))))
  5506. (defun org-compile-prefix-format (key)
  5507. "Compile the prefix format into a Lisp form that can be evaluated.
  5508. The resulting form and associated variable bindings is returned
  5509. and stored in the variable `org-prefix-format-compiled'."
  5510. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5511. org-prefix-category-length nil
  5512. org-prefix-has-effort nil)
  5513. (let ((s (cond
  5514. ((stringp org-agenda-prefix-format)
  5515. org-agenda-prefix-format)
  5516. ((assq key org-agenda-prefix-format)
  5517. (cdr (assq key org-agenda-prefix-format)))
  5518. (t " %-12:c%?-12t% s")))
  5519. (start 0)
  5520. varform vars var e c f opt)
  5521. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5522. s start)
  5523. (setq var (or (cdr (assoc (match-string 4 s)
  5524. '(("c" . category) ("t" . time) ("s" . extra)
  5525. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5526. 'eval)
  5527. c (or (match-string 3 s) "")
  5528. opt (match-beginning 1)
  5529. start (1+ (match-beginning 0)))
  5530. (if (equal var 'time) (setq org-prefix-has-time t))
  5531. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5532. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5533. (setq f (concat "%" (match-string 2 s) "s"))
  5534. (when (equal var 'category)
  5535. (setq org-prefix-category-length
  5536. (floor (abs (string-to-number (match-string 2 s)))))
  5537. (setq org-prefix-category-max-length
  5538. (let ((x (match-string 2 s)))
  5539. (save-match-data
  5540. (if (string-match "\\.[0-9]+" x)
  5541. (string-to-number (substring (match-string 0 x) 1)))))))
  5542. (if (eq var 'eval)
  5543. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5544. (if opt
  5545. (setq varform
  5546. `(if (equal "" ,var)
  5547. ""
  5548. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5549. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5550. (setq s (replace-match "%s" t nil s))
  5551. (push varform vars))
  5552. (setq vars (nreverse vars))
  5553. (with-current-buffer org-agenda-buffer
  5554. (setq org-prefix-format-compiled
  5555. (list
  5556. `((org-prefix-has-time ,org-prefix-has-time)
  5557. (org-prefix-has-tag ,org-prefix-has-tag)
  5558. (org-prefix-category-length ,org-prefix-category-length)
  5559. (org-prefix-has-effort ,org-prefix-has-effort))
  5560. `(format ,s ,@vars))))))
  5561. (defun org-set-sorting-strategy (key)
  5562. (if (symbolp (car org-agenda-sorting-strategy))
  5563. ;; the old format
  5564. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5565. (setq org-agenda-sorting-strategy-selected
  5566. (or (cdr (assq key org-agenda-sorting-strategy))
  5567. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5568. '(time-up category-keep priority-down)))))
  5569. (defun org-get-time-of-day (s &optional string mod24)
  5570. "Check string S for a time of day.
  5571. If found, return it as a military time number between 0 and 2400.
  5572. If not found, return nil.
  5573. The optional STRING argument forces conversion into a 5 character wide string
  5574. HH:MM."
  5575. (save-match-data
  5576. (when
  5577. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5578. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5579. (let* ((h (string-to-number (match-string 1 s)))
  5580. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5581. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5582. (am-p (equal ampm "am"))
  5583. (h1 (cond ((not ampm) h)
  5584. ((= h 12) (if am-p 0 12))
  5585. (t (+ h (if am-p 0 12)))))
  5586. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5587. (mod h1 24) h1))
  5588. (t0 (+ (* 100 h2) m))
  5589. (t1 (concat (if (>= h1 24) "+" " ")
  5590. (if (and org-agenda-time-leading-zero
  5591. (< t0 1000)) "0" "")
  5592. (if (< t0 100) "0" "")
  5593. (if (< t0 10) "0" "")
  5594. (int-to-string t0))))
  5595. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5596. (defvar org-agenda-before-sorting-filter-function nil
  5597. "Function to be applied to agenda items prior to sorting.
  5598. Prior to sorting also means just before they are inserted into the agenda.
  5599. To aid sorting, you may revisit the original entries and add more text
  5600. properties which will later be used by the sorting functions.
  5601. The function should take a string argument, an agenda line.
  5602. It has access to the text properties in that line, which contain among
  5603. other things, the property `org-hd-marker' that points to the entry
  5604. where the line comes from. Note that not all lines going into the agenda
  5605. have this property, only most.
  5606. The function should return the modified string. It is probably best
  5607. to ONLY change text properties.
  5608. You can also use this function as a filter, by returning nil for lines
  5609. you don't want to have in the agenda at all. For this application, you
  5610. could bind the variable in the options section of a custom command.")
  5611. (defun org-finalize-agenda-entries (list &optional nosort)
  5612. "Sort and concatenate the agenda items."
  5613. (setq list (mapcar 'org-agenda-highlight-todo list))
  5614. (if nosort
  5615. list
  5616. (when org-agenda-before-sorting-filter-function
  5617. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5618. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5619. (defun org-agenda-highlight-todo (x)
  5620. (let ((org-done-keywords org-done-keywords-for-agenda)
  5621. (case-fold-search nil)
  5622. re)
  5623. (if (eq x 'line)
  5624. (save-excursion
  5625. (beginning-of-line 1)
  5626. (setq re (org-get-at-bol 'org-todo-regexp))
  5627. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5628. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5629. (add-text-properties (match-beginning 0) (match-end 1)
  5630. (list 'face (org-get-todo-face 1)))
  5631. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5632. (delete-region (match-beginning 1) (1- (match-end 0)))
  5633. (goto-char (match-beginning 1))
  5634. (insert (format org-agenda-todo-keyword-format s)))))
  5635. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5636. (setq re (get-text-property 0 'org-todo-regexp x))
  5637. (when (and re
  5638. ;; Test `pl' because if there's no heading content,
  5639. ;; there's no point matching to highlight. Note
  5640. ;; that if we didn't test `pl' first, and there
  5641. ;; happened to be no keyword from `org-todo-regexp'
  5642. ;; on this heading line, then the `equal' comparison
  5643. ;; afterwards would spuriously succeed in the case
  5644. ;; where `pl' is nil -- causing an args-out-of-range
  5645. ;; error when we try to add text properties to text
  5646. ;; that isn't there.
  5647. pl
  5648. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5649. x pl) pl))
  5650. (add-text-properties
  5651. (or (match-end 1) (match-end 0)) (match-end 0)
  5652. (list 'face (org-get-todo-face (match-string 2 x)))
  5653. x)
  5654. (when (match-end 1)
  5655. (setq x (concat (substring x 0 (match-end 1))
  5656. (format org-agenda-todo-keyword-format
  5657. (match-string 2 x))
  5658. (org-add-props " " (text-properties-at 0 x))
  5659. (substring x (match-end 3)))))))
  5660. x)))
  5661. (defsubst org-cmp-priority (a b)
  5662. "Compare the priorities of string A and B."
  5663. (let ((pa (or (get-text-property 1 'priority a) 0))
  5664. (pb (or (get-text-property 1 'priority b) 0)))
  5665. (cond ((> pa pb) +1)
  5666. ((< pa pb) -1)
  5667. (t nil))))
  5668. (defsubst org-cmp-effort (a b)
  5669. "Compare the effort values of string A and B."
  5670. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5671. (ea (or (get-text-property 1 'effort-minutes a) def))
  5672. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5673. (cond ((> ea eb) +1)
  5674. ((< ea eb) -1)
  5675. (t nil))))
  5676. (defsubst org-cmp-category (a b)
  5677. "Compare the string values of categories of strings A and B."
  5678. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5679. (cb (or (get-text-property 1 'org-category b) "")))
  5680. (cond ((string-lessp ca cb) -1)
  5681. ((string-lessp cb ca) +1)
  5682. (t nil))))
  5683. (defsubst org-cmp-todo-state (a b)
  5684. "Compare the todo states of strings A and B."
  5685. (let* ((ma (or (get-text-property 1 'org-marker a)
  5686. (get-text-property 1 'org-hd-marker a)))
  5687. (mb (or (get-text-property 1 'org-marker b)
  5688. (get-text-property 1 'org-hd-marker b)))
  5689. (fa (and ma (marker-buffer ma)))
  5690. (fb (and mb (marker-buffer mb)))
  5691. (todo-kwds
  5692. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5693. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5694. (ta (or (get-text-property 1 'todo-state a) ""))
  5695. (tb (or (get-text-property 1 'todo-state b) ""))
  5696. (la (- (length (member ta todo-kwds))))
  5697. (lb (- (length (member tb todo-kwds))))
  5698. (donepa (member ta org-done-keywords-for-agenda))
  5699. (donepb (member tb org-done-keywords-for-agenda)))
  5700. (cond ((and donepa (not donepb)) -1)
  5701. ((and (not donepa) donepb) +1)
  5702. ((< la lb) -1)
  5703. ((< lb la) +1)
  5704. (t nil))))
  5705. (defsubst org-cmp-alpha (a b)
  5706. "Compare the headlines, alphabetically."
  5707. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5708. (plb (text-property-any 0 (length b) 'org-heading t b))
  5709. (ta (and pla (substring a pla)))
  5710. (tb (and plb (substring b plb))))
  5711. (when pla
  5712. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5713. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5714. (setq ta (substring ta (match-end 0))))
  5715. (setq ta (downcase ta)))
  5716. (when plb
  5717. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5718. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5719. (setq tb (substring tb (match-end 0))))
  5720. (setq tb (downcase tb)))
  5721. (cond ((not ta) +1)
  5722. ((not tb) -1)
  5723. ((string-lessp ta tb) -1)
  5724. ((string-lessp tb ta) +1)
  5725. (t nil))))
  5726. (defsubst org-cmp-tag (a b)
  5727. "Compare the string values of the first tags of A and B."
  5728. (let ((ta (car (last (get-text-property 1 'tags a))))
  5729. (tb (car (last (get-text-property 1 'tags b)))))
  5730. (cond ((not ta) +1)
  5731. ((not tb) -1)
  5732. ((string-lessp ta tb) -1)
  5733. ((string-lessp tb ta) +1)
  5734. (t nil))))
  5735. (defsubst org-cmp-time (a b)
  5736. "Compare the time-of-day values of strings A and B."
  5737. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5738. (ta (or (get-text-property 1 'time-of-day a) def))
  5739. (tb (or (get-text-property 1 'time-of-day b) def)))
  5740. (cond ((< ta tb) -1)
  5741. ((< tb ta) +1)
  5742. (t nil))))
  5743. (defsubst org-cmp-habit-p (a b)
  5744. "Compare the todo states of strings A and B."
  5745. (let ((ha (get-text-property 1 'org-habit-p a))
  5746. (hb (get-text-property 1 'org-habit-p b)))
  5747. (cond ((and ha (not hb)) -1)
  5748. ((and (not ha) hb) +1)
  5749. (t nil))))
  5750. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5751. (defun org-entries-lessp (a b)
  5752. "Predicate for sorting agenda entries."
  5753. ;; The following variables will be used when the form is evaluated.
  5754. ;; So even though the compiler complains, keep them.
  5755. (let* ((ss org-agenda-sorting-strategy-selected)
  5756. (time-up (and (org-em 'time-up 'time-down ss)
  5757. (org-cmp-time a b)))
  5758. (time-down (if time-up (- time-up) nil))
  5759. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5760. (org-cmp-priority a b)))
  5761. (priority-down (if priority-up (- priority-up) nil))
  5762. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5763. (org-cmp-effort a b)))
  5764. (effort-down (if effort-up (- effort-up) nil))
  5765. (category-up (and (or (org-em 'category-up 'category-down ss)
  5766. (memq 'category-keep ss))
  5767. (org-cmp-category a b)))
  5768. (category-down (if category-up (- category-up) nil))
  5769. (category-keep (if category-up +1 nil))
  5770. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5771. (org-cmp-tag a b)))
  5772. (tag-down (if tag-up (- tag-up) nil))
  5773. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5774. (org-cmp-todo-state a b)))
  5775. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5776. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5777. (org-cmp-habit-p a b)))
  5778. (habit-down (if habit-up (- habit-up) nil))
  5779. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5780. (org-cmp-alpha a b)))
  5781. (alpha-down (if alpha-up (- alpha-up) nil))
  5782. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5783. user-defined-up user-defined-down)
  5784. (if (and need-user-cmp org-agenda-cmp-user-defined
  5785. (functionp org-agenda-cmp-user-defined))
  5786. (setq user-defined-up
  5787. (funcall org-agenda-cmp-user-defined a b)
  5788. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5789. (cdr (assoc
  5790. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5791. '((-1 . t) (1 . nil) (nil . nil))))))
  5792. ;;; Agenda restriction lock
  5793. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5794. "Overlay to mark the headline to which agenda commands are restricted.")
  5795. (overlay-put org-agenda-restriction-lock-overlay
  5796. 'face 'org-agenda-restriction-lock)
  5797. (overlay-put org-agenda-restriction-lock-overlay
  5798. 'help-echo "Agendas are currently limited to this subtree.")
  5799. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5800. (defun org-agenda-set-restriction-lock (&optional type)
  5801. "Set restriction lock for agenda, to current subtree or file.
  5802. Restriction will be the file if TYPE is `file', or if type is the
  5803. universal prefix '(4), or if the cursor is before the first headline
  5804. in the file. Otherwise, restriction will be to the current subtree."
  5805. (interactive "P")
  5806. (and (equal type '(4)) (setq type 'file))
  5807. (setq type (cond
  5808. (type type)
  5809. ((org-at-heading-p) 'subtree)
  5810. ((condition-case nil (org-back-to-heading t) (error nil))
  5811. 'subtree)
  5812. (t 'file)))
  5813. (if (eq type 'subtree)
  5814. (progn
  5815. (setq org-agenda-restrict t)
  5816. (setq org-agenda-overriding-restriction 'subtree)
  5817. (put 'org-agenda-files 'org-restrict
  5818. (list (buffer-file-name (buffer-base-buffer))))
  5819. (org-back-to-heading t)
  5820. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5821. (move-marker org-agenda-restrict-begin (point))
  5822. (move-marker org-agenda-restrict-end
  5823. (save-excursion (org-end-of-subtree t)))
  5824. (message "Locking agenda restriction to subtree"))
  5825. (put 'org-agenda-files 'org-restrict
  5826. (list (buffer-file-name (buffer-base-buffer))))
  5827. (setq org-agenda-restrict nil)
  5828. (setq org-agenda-overriding-restriction 'file)
  5829. (move-marker org-agenda-restrict-begin nil)
  5830. (move-marker org-agenda-restrict-end nil)
  5831. (message "Locking agenda restriction to file"))
  5832. (setq current-prefix-arg nil)
  5833. (org-agenda-maybe-redo))
  5834. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5835. "Remove the agenda restriction lock."
  5836. (interactive "P")
  5837. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5838. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5839. (setq org-agenda-overriding-restriction nil)
  5840. (setq org-agenda-restrict nil)
  5841. (put 'org-agenda-files 'org-restrict nil)
  5842. (move-marker org-agenda-restrict-begin nil)
  5843. (move-marker org-agenda-restrict-end nil)
  5844. (setq current-prefix-arg nil)
  5845. (message "Agenda restriction lock removed")
  5846. (or noupdate (org-agenda-maybe-redo)))
  5847. (defun org-agenda-maybe-redo ()
  5848. "If there is any window showing the agenda view, update it."
  5849. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5850. (w0 (selected-window)))
  5851. (when w
  5852. (select-window w)
  5853. (org-agenda-redo)
  5854. (select-window w0)
  5855. (if org-agenda-overriding-restriction
  5856. (message "Agenda view shifted to new %s restriction"
  5857. org-agenda-overriding-restriction)
  5858. (message "Agenda restriction lock removed")))))
  5859. ;;; Agenda commands
  5860. (defun org-agenda-check-type (error &rest types)
  5861. "Check if agenda buffer is of allowed type.
  5862. If ERROR is non-nil, throw an error, otherwise just return nil."
  5863. (if (memq org-agenda-type types)
  5864. t
  5865. (if error
  5866. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5867. nil)))
  5868. (defun org-agenda-Quit (&optional arg)
  5869. "Exit agenda by removing the window or the buffer"
  5870. (interactive)
  5871. (if org-agenda-columns-active
  5872. (org-columns-quit)
  5873. (let ((buf (current-buffer)))
  5874. (if (eq org-agenda-window-setup 'other-frame)
  5875. (progn
  5876. (org-agenda-reset-markers)
  5877. (kill-buffer buf)
  5878. (org-columns-remove-overlays)
  5879. (setq org-agenda-archives-mode nil)
  5880. (delete-frame))
  5881. (and (not (eq org-agenda-window-setup 'current-window))
  5882. (not (one-window-p))
  5883. (delete-window))
  5884. (org-agenda-reset-markers)
  5885. (kill-buffer buf)
  5886. (org-columns-remove-overlays)
  5887. (setq org-agenda-archives-mode nil)))
  5888. ;; Maybe restore the pre-agenda window configuration.
  5889. (and org-agenda-restore-windows-after-quit
  5890. (not (eq org-agenda-window-setup 'other-frame))
  5891. org-pre-agenda-window-conf
  5892. (set-window-configuration org-pre-agenda-window-conf))))
  5893. (defun org-agenda-quit ()
  5894. "Exit agenda by killing agenda buffer or burying it when
  5895. `org-agenda-sticky' is non-NIL"
  5896. (interactive)
  5897. (if org-agenda-columns-active
  5898. (org-columns-quit)
  5899. (if org-agenda-sticky
  5900. (let ((buf (current-buffer)))
  5901. (if (eq org-agenda-window-setup 'other-frame)
  5902. (progn
  5903. (delete-frame))
  5904. (and (not (eq org-agenda-window-setup 'current-window))
  5905. (not (one-window-p))
  5906. (delete-window)))
  5907. (with-current-buffer buf
  5908. (bury-buffer)))
  5909. (org-agenda-Quit))))
  5910. (defun org-agenda-exit ()
  5911. "Exit agenda by removing the window or the buffer.
  5912. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5913. Org-mode buffers visited directly by the user will not be touched."
  5914. (interactive)
  5915. (org-release-buffers org-agenda-new-buffers)
  5916. (setq org-agenda-new-buffers nil)
  5917. (org-agenda-Quit))
  5918. (defun org-agenda-kill-all-agenda-buffers ()
  5919. "Kill all buffers in `org-agena-mode'.
  5920. This is used when toggling sticky agendas. You can also explicitly invoke it
  5921. with `C-c a C-k'."
  5922. (interactive)
  5923. (let (blist)
  5924. (dolist (buf (buffer-list))
  5925. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5926. (push buf blist)))
  5927. (mapc 'kill-buffer blist)))
  5928. (defun org-agenda-execute (arg)
  5929. "Execute another agenda command, keeping same window.
  5930. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5931. in the agenda."
  5932. (interactive "P")
  5933. (let ((org-agenda-window-setup 'current-window))
  5934. (org-agenda arg)))
  5935. (defun org-agenda-redo ()
  5936. "Rebuild Agenda.
  5937. When this is the global TODO list, a prefix argument will be interpreted."
  5938. (interactive)
  5939. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  5940. (org-agenda-sticky nil)
  5941. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  5942. org-agenda-buffer-name))
  5943. (org-agenda-keep-modes t)
  5944. (tag-filter org-agenda-tag-filter)
  5945. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5946. (cat-filter org-agenda-category-filter)
  5947. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5948. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5949. (cols org-agenda-columns-active)
  5950. (line (org-current-line))
  5951. (window-line (- line (org-current-line (window-start))))
  5952. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5953. (put 'org-agenda-tag-filter :preset-filter nil)
  5954. (put 'org-agenda-category-filter :preset-filter nil)
  5955. (and cols (org-columns-quit))
  5956. (message "Rebuilding agenda buffer...")
  5957. (org-let lprops '(eval org-agenda-redo-command))
  5958. (setq org-agenda-undo-list nil
  5959. org-agenda-pending-undo-list nil)
  5960. (message "Rebuilding agenda buffer...done")
  5961. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5962. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5963. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5964. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5965. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5966. (org-goto-line line)
  5967. (recenter window-line)))
  5968. (defvar org-global-tags-completion-table nil)
  5969. (defvar org-agenda-filter-form nil)
  5970. (defvar org-agenda-filtered-by-category nil)
  5971. (defun org-agenda-filter-by-category (strip)
  5972. "Keep only those lines in the agenda buffer that have a specific category.
  5973. The category is that of the current line."
  5974. (interactive "P")
  5975. (if org-agenda-filtered-by-category
  5976. (org-agenda-filter-show-all-cat)
  5977. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  5978. (if cat (org-agenda-filter-apply
  5979. (list (concat (if strip "-" "+") cat)) 'category)
  5980. (error "No category at point")))))
  5981. (defun org-find-top-category (&optional pos)
  5982. (save-excursion
  5983. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  5984. (if pos (goto-char pos))
  5985. ;; Skip up to the topmost parent
  5986. (while (ignore-errors (outline-up-heading 1) t))
  5987. (ignore-errors
  5988. (nth 4 (org-heading-components))))))
  5989. (defvar org-agenda-filtered-by-top-category nil)
  5990. (defun org-agenda-filter-by-top-category (strip)
  5991. "Keep only those lines in the agenda buffer that have a specific category.
  5992. The category is that of the current line."
  5993. (interactive "P")
  5994. (if org-agenda-filtered-by-top-category
  5995. (progn
  5996. (setq org-agenda-filtered-by-top-category nil)
  5997. (org-agenda-filter-show-all-cat))
  5998. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  5999. (if cat (org-agenda-filter-top-category-apply cat strip)
  6000. (error "No top-level category at point")))))
  6001. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6002. "Keep only those lines in the agenda buffer that have a specific tag.
  6003. The tag is selected with its fast selection letter, as configured.
  6004. With prefix argument STRIP, remove all lines that do have the tag.
  6005. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6006. used to narrow the search - the interactive user can also press `-' or `+'
  6007. to switch to narrowing."
  6008. (interactive "P")
  6009. (let* ((alist org-tag-alist-for-agenda)
  6010. (tag-chars (mapconcat
  6011. (lambda (x) (if (and (not (symbolp (car x)))
  6012. (cdr x))
  6013. (char-to-string (cdr x))
  6014. ""))
  6015. alist ""))
  6016. (efforts (org-split-string
  6017. (or (cdr (assoc (concat org-effort-property "_ALL")
  6018. org-global-properties))
  6019. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6020. "")))
  6021. (effort-op org-agenda-filter-effort-default-operator)
  6022. (effort-prompt "")
  6023. (inhibit-read-only t)
  6024. (current org-agenda-tag-filter)
  6025. maybe-refresh a n tag)
  6026. (unless char
  6027. (message
  6028. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6029. (if narrow "Narrow" "Filter") tag-chars
  6030. (if org-agenda-auto-exclude-function "[RET], " ""))
  6031. (setq char (read-char-exclusive)))
  6032. (when (member char '(?+ ?-))
  6033. ;; Narrowing down
  6034. (cond ((equal char ?-) (setq strip t narrow t))
  6035. ((equal char ?+) (setq strip nil narrow t)))
  6036. (message
  6037. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6038. (setq char (read-char-exclusive)))
  6039. (when (member char '(?< ?> ?= ??))
  6040. ;; An effort operator
  6041. (setq effort-op (char-to-string char))
  6042. (setq alist nil) ; to make sure it will be interpreted as effort.
  6043. (unless (equal char ??)
  6044. (loop for i from 0 to 9 do
  6045. (setq effort-prompt
  6046. (concat
  6047. effort-prompt " ["
  6048. (if (= i 9) "0" (int-to-string (1+ i)))
  6049. "]" (nth i efforts))))
  6050. (message "Effort%s: %s " effort-op effort-prompt)
  6051. (setq char (read-char-exclusive))
  6052. (when (or (< char ?0) (> char ?9))
  6053. (error "Need 1-9,0 to select effort"))))
  6054. (when (equal char ?\t)
  6055. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6056. (org-set-local 'org-global-tags-completion-table
  6057. (org-global-tags-completion-table)))
  6058. (let ((completion-ignore-case t))
  6059. (setq tag (org-icompleting-read
  6060. "Tag: " org-global-tags-completion-table))))
  6061. (cond
  6062. ((equal char ?\r)
  6063. (org-agenda-filter-show-all-tag)
  6064. (when org-agenda-auto-exclude-function
  6065. (setq org-agenda-tag-filter '())
  6066. (dolist (tag (org-agenda-get-represented-tags))
  6067. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6068. (if modifier
  6069. (push modifier org-agenda-tag-filter))))
  6070. (if (not (null org-agenda-tag-filter))
  6071. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6072. (setq maybe-refresh t))
  6073. ((equal char ?/)
  6074. (org-agenda-filter-show-all-tag)
  6075. (when (get 'org-agenda-tag-filter :preset-filter)
  6076. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6077. (setq maybe-refresh t))
  6078. ((equal char ?. )
  6079. (setq org-agenda-tag-filter
  6080. (mapcar (lambda(tag) (concat "+" tag))
  6081. (org-get-at-bol 'tags)))
  6082. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6083. (setq maybe-refresh t))
  6084. ((or (equal char ?\ )
  6085. (setq a (rassoc char alist))
  6086. (and (>= char ?0) (<= char ?9)
  6087. (setq n (if (= char ?0) 9 (- char ?0 1))
  6088. tag (concat effort-op (nth n efforts))
  6089. a (cons tag nil)))
  6090. (and (= char ??)
  6091. (setq tag "?eff")
  6092. a (cons tag nil))
  6093. (and tag (setq a (cons tag nil))))
  6094. (org-agenda-filter-show-all-tag)
  6095. (setq tag (car a))
  6096. (setq org-agenda-tag-filter
  6097. (cons (concat (if strip "-" "+") tag)
  6098. (if narrow current nil)))
  6099. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6100. (setq maybe-refresh t))
  6101. (t (error "Invalid tag selection character %c" char)))
  6102. (when (and maybe-refresh
  6103. (eq org-agenda-clockreport-mode 'with-filter))
  6104. (org-agenda-redo))))
  6105. (defun org-agenda-get-represented-tags ()
  6106. "Get a list of all tags currently represented in the agenda."
  6107. (let (p tags)
  6108. (save-excursion
  6109. (goto-char (point-min))
  6110. (while (setq p (next-single-property-change (point) 'tags))
  6111. (goto-char p)
  6112. (mapc (lambda (x) (add-to-list 'tags x))
  6113. (get-text-property (point) 'tags))))
  6114. tags))
  6115. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6116. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6117. (interactive "P")
  6118. (org-agenda-filter-by-tag strip char 'refine))
  6119. (defun org-agenda-filter-make-matcher ()
  6120. "Create the form that tests a line for agenda filter."
  6121. (let (f f1)
  6122. ;; first compute the tag-filter matcher
  6123. (dolist (x (delete-dups
  6124. (append (get 'org-agenda-tag-filter
  6125. :preset-filter) org-agenda-tag-filter)))
  6126. (if (member x '("-" "+"))
  6127. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6128. (if (string-match "[<=>?]" x)
  6129. (setq f1 (org-agenda-filter-effort-form x))
  6130. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6131. (if (equal (string-to-char x) ?-)
  6132. (setq f1 (list 'not f1))))
  6133. (push f1 f))
  6134. ;; then compute the category-filter matcher
  6135. (dolist (x (delete-dups
  6136. (append (get 'org-agenda-category-filter
  6137. :preset-filter) org-agenda-category-filter)))
  6138. (if (equal "-" (substring x 0 1))
  6139. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6140. (setq f1 (list 'equal (substring x 1) 'cat)))
  6141. (push f1 f))
  6142. (cons 'and (nreverse f))))
  6143. (defun org-agenda-filter-effort-form (e)
  6144. "Return the form to compare the effort of the current line with what E says.
  6145. E looks like \"+<2:25\"."
  6146. (let (op)
  6147. (setq e (substring e 1))
  6148. (setq op (string-to-char e) e (substring e 1))
  6149. (setq op (cond ((equal op ?<) '<=)
  6150. ((equal op ?>) '>=)
  6151. ((equal op ??) op)
  6152. (t '=)))
  6153. (list 'org-agenda-compare-effort (list 'quote op)
  6154. (org-duration-string-to-minutes e))))
  6155. (defun org-agenda-compare-effort (op value)
  6156. "Compare the effort of the current line with VALUE, using OP.
  6157. If the line does not have an effort defined, return nil."
  6158. (let ((eff (org-get-at-bol 'effort-minutes)))
  6159. (if (equal op ??)
  6160. (not eff)
  6161. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6162. value))))
  6163. (defun org-agenda-filter-apply (filter type)
  6164. "Set FILTER as the new agenda filter and apply it."
  6165. (let (tags cat)
  6166. (if (eq type 'tag)
  6167. (setq org-agenda-tag-filter filter)
  6168. (setq org-agenda-category-filter filter))
  6169. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6170. (if (and (eq type 'category)
  6171. (not (equal (substring (car filter) 0 1) "-")))
  6172. ;; Only set `org-agenda-filtered-by-category' to t
  6173. ;; when a unique category is used as the filter
  6174. (setq org-agenda-filtered-by-category t))
  6175. (org-agenda-set-mode-name)
  6176. (save-excursion
  6177. (goto-char (point-min))
  6178. (while (not (eobp))
  6179. (if (org-get-at-bol 'org-marker)
  6180. (progn
  6181. (setq tags (org-get-at-bol 'tags) ; used in eval
  6182. cat (get-text-property (point) 'org-category))
  6183. (if (not (eval org-agenda-filter-form))
  6184. (org-agenda-filter-hide-line type))
  6185. (beginning-of-line 2))
  6186. (beginning-of-line 2))))
  6187. (if (get-char-property (point) 'invisible)
  6188. (ignore-errors (org-agenda-previous-line)))))
  6189. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6190. "Set FILTER as the new agenda filter and apply it."
  6191. (org-agenda-set-mode-name)
  6192. (save-excursion
  6193. (goto-char (point-min))
  6194. (while (not (eobp))
  6195. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6196. (topcat (and pos (org-find-top-category pos))))
  6197. (if (and topcat (funcall (if negative 'identity 'not)
  6198. (string= category topcat)))
  6199. (org-agenda-filter-hide-line 'category)))
  6200. (beginning-of-line 2)))
  6201. (if (get-char-property (point) 'invisible)
  6202. (org-agenda-previous-line))
  6203. (setq org-agenda-filtered-by-top-category t))
  6204. (defun org-agenda-filter-hide-line (type)
  6205. (let (ov)
  6206. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6207. (point-at-eol)))
  6208. (overlay-put ov 'invisible t)
  6209. (overlay-put ov 'type type)
  6210. (if (eq type 'tag)
  6211. (push ov org-agenda-tag-filter-overlays)
  6212. (push ov org-agenda-cat-filter-overlays))))
  6213. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6214. (setq pos (or pos (point)))
  6215. (save-excursion
  6216. (dolist (ov (overlays-at pos))
  6217. (when (and (overlay-get ov 'invisible)
  6218. (eq (overlay-get ov 'type) 'tag))
  6219. (goto-char pos)
  6220. (if (< (overlay-start ov) (point-at-eol))
  6221. (move-overlay ov (point-at-eol)
  6222. (overlay-end ov)))))))
  6223. (defun org-agenda-filter-show-all-tag nil
  6224. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6225. (setq org-agenda-tag-filter-overlays nil
  6226. org-agenda-tag-filter nil
  6227. org-agenda-filter-form nil)
  6228. (org-agenda-set-mode-name))
  6229. (defun org-agenda-filter-show-all-cat nil
  6230. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6231. (setq org-agenda-cat-filter-overlays nil
  6232. org-agenda-filtered-by-category nil
  6233. org-agenda-category-filter nil
  6234. org-agenda-filter-form nil)
  6235. (org-agenda-set-mode-name))
  6236. (defun org-agenda-manipulate-query-add ()
  6237. "Manipulate the query by adding a search term with positive selection.
  6238. Positive selection means the term must be matched for selection of an entry."
  6239. (interactive)
  6240. (org-agenda-manipulate-query ?\[))
  6241. (defun org-agenda-manipulate-query-subtract ()
  6242. "Manipulate the query by adding a search term with negative selection.
  6243. Negative selection means term must not be matched for selection of an entry."
  6244. (interactive)
  6245. (org-agenda-manipulate-query ?\]))
  6246. (defun org-agenda-manipulate-query-add-re ()
  6247. "Manipulate the query by adding a search regexp with positive selection.
  6248. Positive selection means the regexp must match for selection of an entry."
  6249. (interactive)
  6250. (org-agenda-manipulate-query ?\{))
  6251. (defun org-agenda-manipulate-query-subtract-re ()
  6252. "Manipulate the query by adding a search regexp with negative selection.
  6253. Negative selection means regexp must not match for selection of an entry."
  6254. (interactive)
  6255. (org-agenda-manipulate-query ?\}))
  6256. (defun org-agenda-manipulate-query (char)
  6257. (cond
  6258. ((memq org-agenda-type '(timeline agenda))
  6259. (let ((org-agenda-include-inactive-timestamps t))
  6260. (org-agenda-redo))
  6261. (message "Display now includes inactive timestamps as well"))
  6262. ((eq org-agenda-type 'search)
  6263. (org-add-to-string
  6264. 'org-agenda-query-string
  6265. (if org-agenda-last-search-view-search-was-boolean
  6266. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6267. (?\{ . " +{}") (?\} . " -{}"))))
  6268. " "))
  6269. (setq org-agenda-redo-command
  6270. (list 'org-search-view
  6271. org-todo-only
  6272. org-agenda-query-string
  6273. (+ (length org-agenda-query-string)
  6274. (if (member char '(?\{ ?\})) 0 1))))
  6275. (set-register org-agenda-query-register org-agenda-query-string)
  6276. (org-agenda-redo))
  6277. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6278. org-agenda-type))))
  6279. (defun org-add-to-string (var string)
  6280. (set var (concat (symbol-value var) string)))
  6281. (defun org-agenda-goto-date (date)
  6282. "Jump to DATE in agenda."
  6283. (interactive (list (let ((org-read-date-prefer-future
  6284. (eval org-agenda-jump-prefer-future)))
  6285. (org-read-date))))
  6286. (org-agenda-list nil date))
  6287. (defun org-agenda-goto-today ()
  6288. "Go to today."
  6289. (interactive)
  6290. (org-agenda-check-type t 'timeline 'agenda)
  6291. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6292. (cond
  6293. (tdpos (goto-char tdpos))
  6294. ((eq org-agenda-type 'agenda)
  6295. (let* ((sd (org-agenda-compute-starting-span
  6296. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6297. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6298. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6299. (org-agenda-redo)
  6300. (org-agenda-find-same-or-today-or-agenda)))
  6301. (t (error "Cannot find today")))))
  6302. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6303. (goto-char
  6304. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6305. (text-property-any (point-min) (point-max) 'org-today t)
  6306. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6307. (point-min))))
  6308. (defun org-agenda-later (arg)
  6309. "Go forward in time by thee current span.
  6310. With prefix ARG, go forward that many times the current span."
  6311. (interactive "p")
  6312. (org-agenda-check-type t 'agenda)
  6313. (let* ((span org-agenda-current-span)
  6314. (sd org-starting-day)
  6315. (greg (calendar-gregorian-from-absolute sd))
  6316. (cnt (org-get-at-bol 'org-day-cnt))
  6317. greg2)
  6318. (cond
  6319. ((eq span 'day)
  6320. (setq sd (+ arg sd)))
  6321. ((eq span 'week)
  6322. (setq sd (+ (* 7 arg) sd)))
  6323. ((eq span 'month)
  6324. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6325. sd (calendar-absolute-from-gregorian greg2))
  6326. (setcar greg2 (1+ (car greg2))))
  6327. ((eq span 'year)
  6328. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6329. sd (calendar-absolute-from-gregorian greg2))
  6330. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6331. (t
  6332. (setq sd (+ (* span arg) sd))))
  6333. (let ((org-agenda-overriding-arguments
  6334. (list (car org-agenda-last-arguments) sd span t)))
  6335. (org-agenda-redo)
  6336. (org-agenda-find-same-or-today-or-agenda cnt))))
  6337. (defun org-agenda-earlier (arg)
  6338. "Go backward in time by the current span.
  6339. With prefix ARG, go backward that many times the current span."
  6340. (interactive "p")
  6341. (org-agenda-later (- arg)))
  6342. (defun org-agenda-view-mode-dispatch ()
  6343. "Call one of the view mode commands."
  6344. (interactive)
  6345. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6346. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6347. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6348. [E]ntryText")
  6349. (let ((a (read-char-exclusive)))
  6350. (case a
  6351. (?\ (call-interactively 'org-agenda-reset-view))
  6352. (?d (call-interactively 'org-agenda-day-view))
  6353. (?w (call-interactively 'org-agenda-week-view))
  6354. (?m (call-interactively 'org-agenda-month-view))
  6355. (?y (call-interactively 'org-agenda-year-view))
  6356. (?l (call-interactively 'org-agenda-log-mode))
  6357. (?L (org-agenda-log-mode '(4)))
  6358. (?c (org-agenda-log-mode 'clockcheck))
  6359. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6360. (?a (call-interactively 'org-agenda-archives-mode))
  6361. (?A (org-agenda-archives-mode 'files))
  6362. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6363. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6364. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6365. (?D (call-interactively 'org-agenda-toggle-diary))
  6366. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6367. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6368. (org-agenda-check-type t 'timeline 'agenda)
  6369. (org-agenda-redo))
  6370. (message "Display now includes inactive timestamps as well"))
  6371. (?q (message "Abort"))
  6372. (otherwise (error "Invalid key" )))))
  6373. (defun org-agenda-reset-view ()
  6374. "Switch to default view for agenda."
  6375. (interactive)
  6376. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6377. (defun org-agenda-day-view (&optional day-of-year)
  6378. "Switch to daily view for agenda.
  6379. With argument DAY-OF-YEAR, switch to that day of the year."
  6380. (interactive "P")
  6381. (org-agenda-change-time-span 'day day-of-year))
  6382. (defun org-agenda-week-view (&optional iso-week)
  6383. "Switch to daily view for agenda.
  6384. With argument ISO-WEEK, switch to the corresponding ISO week.
  6385. If ISO-WEEK has more then 2 digits, only the last two encode the
  6386. week. Any digits before this encode a year. So 200712 means
  6387. week 12 of year 2007. Years in the range 1938-2037 can also be
  6388. written as 2-digit years."
  6389. (interactive "P")
  6390. (org-agenda-change-time-span 'week iso-week))
  6391. (defun org-agenda-month-view (&optional month)
  6392. "Switch to monthly view for agenda.
  6393. With argument MONTH, switch to that month."
  6394. (interactive "P")
  6395. (org-agenda-change-time-span 'month month))
  6396. (defun org-agenda-year-view (&optional year)
  6397. "Switch to yearly view for agenda.
  6398. With argument YEAR, switch to that year.
  6399. If MONTH has more then 2 digits, only the last two encode the
  6400. month. Any digits before this encode a year. So 200712 means
  6401. December year 2007. Years in the range 1938-2037 can also be
  6402. written as 2-digit years."
  6403. (interactive "P")
  6404. (when year
  6405. (setq year (org-small-year-to-year year)))
  6406. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6407. (org-agenda-change-time-span 'year year)
  6408. (error "Abort")))
  6409. (defun org-agenda-change-time-span (span &optional n)
  6410. "Change the agenda view to SPAN.
  6411. SPAN may be `day', `week', `month', `year'."
  6412. (org-agenda-check-type t 'agenda)
  6413. (if (and (not n) (equal org-agenda-current-span span))
  6414. (error "Viewing span is already \"%s\"" span))
  6415. (let* ((sd (or (org-get-at-bol 'day)
  6416. org-starting-day))
  6417. (sd (org-agenda-compute-starting-span sd span n))
  6418. (org-agenda-overriding-arguments
  6419. (or org-agenda-overriding-arguments
  6420. (list (car org-agenda-last-arguments) sd span t))))
  6421. (org-agenda-redo)
  6422. (org-agenda-find-same-or-today-or-agenda))
  6423. (org-agenda-set-mode-name)
  6424. (message "Switched to %s view" span))
  6425. (defun org-agenda-compute-starting-span (sd span &optional n)
  6426. "Compute starting date for agenda.
  6427. SPAN may be `day', `week', `month', `year'. The return value
  6428. is a cons cell with the starting date and the number of days,
  6429. so that the date SD will be in that range."
  6430. (let* ((greg (calendar-gregorian-from-absolute sd))
  6431. (dg (nth 1 greg))
  6432. (mg (car greg))
  6433. (yg (nth 2 greg)))
  6434. (cond
  6435. ((eq span 'day)
  6436. (when n
  6437. (setq sd (+ (calendar-absolute-from-gregorian
  6438. (list mg 1 yg))
  6439. n -1))))
  6440. ((eq span 'week)
  6441. (let* ((nt (calendar-day-of-week
  6442. (calendar-gregorian-from-absolute sd)))
  6443. (d (if org-agenda-start-on-weekday
  6444. (- nt org-agenda-start-on-weekday)
  6445. 0))
  6446. y1)
  6447. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6448. (when n
  6449. (require 'cal-iso)
  6450. (when (> n 99)
  6451. (setq y1 (org-small-year-to-year (/ n 100))
  6452. n (mod n 100)))
  6453. (setq sd
  6454. (calendar-absolute-from-iso
  6455. (list n 1
  6456. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6457. ((eq span 'month)
  6458. (let (y1)
  6459. (when (and n (> n 99))
  6460. (setq y1 (org-small-year-to-year (/ n 100))
  6461. n (mod n 100)))
  6462. (setq sd (calendar-absolute-from-gregorian
  6463. (list (or n mg) 1 (or y1 yg))))))
  6464. ((eq span 'year)
  6465. (setq sd (calendar-absolute-from-gregorian
  6466. (list 1 1 (or n yg))))))
  6467. sd))
  6468. (defun org-agenda-next-date-line (&optional arg)
  6469. "Jump to the next line indicating a date in agenda buffer."
  6470. (interactive "p")
  6471. (org-agenda-check-type t 'agenda 'timeline)
  6472. (beginning-of-line 1)
  6473. ;; This does not work if user makes date format that starts with a blank
  6474. (if (looking-at "^\\S-") (forward-char 1))
  6475. (if (not (re-search-forward "^\\S-" nil t arg))
  6476. (progn
  6477. (backward-char 1)
  6478. (error "No next date after this line in this buffer")))
  6479. (goto-char (match-beginning 0)))
  6480. (defun org-agenda-previous-date-line (&optional arg)
  6481. "Jump to the previous line indicating a date in agenda buffer."
  6482. (interactive "p")
  6483. (org-agenda-check-type t 'agenda 'timeline)
  6484. (beginning-of-line 1)
  6485. (if (not (re-search-backward "^\\S-" nil t arg))
  6486. (error "No previous date before this line in this buffer")))
  6487. ;; Initialize the highlight
  6488. (defvar org-hl (make-overlay 1 1))
  6489. (overlay-put org-hl 'face 'highlight)
  6490. (defun org-highlight (begin end &optional buffer)
  6491. "Highlight a region with overlay."
  6492. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6493. (defun org-unhighlight ()
  6494. "Detach overlay INDEX."
  6495. (org-detach-overlay org-hl))
  6496. ;; FIXME this is currently not used.
  6497. (defun org-highlight-until-next-command (beg end &optional buffer)
  6498. "Move the highlight overlay to BEG/END, remove it before the next command."
  6499. (org-highlight beg end buffer)
  6500. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6501. (defun org-unhighlight-once ()
  6502. "Remove the highlight from its position, and this function from the hook."
  6503. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6504. (org-unhighlight))
  6505. (defun org-agenda-follow-mode ()
  6506. "Toggle follow mode in an agenda buffer."
  6507. (interactive)
  6508. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6509. (org-agenda-set-mode-name)
  6510. (org-agenda-do-context-action)
  6511. (message "Follow mode is %s"
  6512. (if org-agenda-follow-mode "on" "off")))
  6513. (defun org-agenda-entry-text-mode (&optional arg)
  6514. "Toggle entry text mode in an agenda buffer."
  6515. (interactive "P")
  6516. (setq org-agenda-entry-text-mode (or (integerp arg)
  6517. (not org-agenda-entry-text-mode)))
  6518. (org-agenda-entry-text-hide)
  6519. (and org-agenda-entry-text-mode
  6520. (let ((org-agenda-entry-text-maxlines
  6521. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6522. (org-agenda-entry-text-show)))
  6523. (org-agenda-set-mode-name)
  6524. (message "Entry text mode is %s. Maximum number of lines is %d"
  6525. (if org-agenda-entry-text-mode "on" "off")
  6526. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6527. (defun org-agenda-clockreport-mode (&optional with-filter)
  6528. "Toggle clocktable mode in an agenda buffer.
  6529. With prefix arg WITH-FILTER, make the clocktable respect the current
  6530. agenda filter."
  6531. (interactive "P")
  6532. (org-agenda-check-type t 'agenda)
  6533. (if with-filter
  6534. (setq org-agenda-clockreport-mode 'with-filter)
  6535. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6536. (org-agenda-set-mode-name)
  6537. (org-agenda-redo)
  6538. (message "Clocktable mode is %s"
  6539. (if org-agenda-clockreport-mode "on" "off")))
  6540. (defun org-agenda-log-mode (&optional special)
  6541. "Toggle log mode in an agenda buffer.
  6542. With argument SPECIAL, show all possible log items, not only the ones
  6543. configured in `org-agenda-log-mode-items'.
  6544. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6545. (interactive "P")
  6546. (org-agenda-check-type t 'agenda 'timeline)
  6547. (setq org-agenda-show-log
  6548. (cond
  6549. ((equal special '(16)) 'only)
  6550. ((eq special 'clockcheck)
  6551. (if (eq org-agenda-show-log 'clockcheck)
  6552. nil 'clockcheck))
  6553. (special '(closed clock state))
  6554. (t (not org-agenda-show-log))))
  6555. (org-agenda-set-mode-name)
  6556. (org-agenda-redo)
  6557. (message "Log mode is %s"
  6558. (if org-agenda-show-log "on" "off")))
  6559. (defun org-agenda-archives-mode (&optional with-files)
  6560. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6561. When called with a prefix argument, include all archive files as well."
  6562. (interactive "P")
  6563. (setq org-agenda-archives-mode
  6564. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6565. (org-agenda-set-mode-name)
  6566. (org-agenda-redo)
  6567. (message
  6568. "%s"
  6569. (cond
  6570. ((eq org-agenda-archives-mode nil)
  6571. "No archives are included")
  6572. ((eq org-agenda-archives-mode 'trees)
  6573. (format "Trees with :%s: tag are included" org-archive-tag))
  6574. ((eq org-agenda-archives-mode t)
  6575. (format "Trees with :%s: tag and all active archive files are included"
  6576. org-archive-tag)))))
  6577. (defun org-agenda-toggle-diary ()
  6578. "Toggle diary inclusion in an agenda buffer."
  6579. (interactive)
  6580. (org-agenda-check-type t 'agenda)
  6581. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6582. (org-agenda-redo)
  6583. (org-agenda-set-mode-name)
  6584. (message "Diary inclusion turned %s"
  6585. (if org-agenda-include-diary "on" "off")))
  6586. (defun org-agenda-toggle-deadlines ()
  6587. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6588. (interactive)
  6589. (org-agenda-check-type t 'agenda)
  6590. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6591. (org-agenda-redo)
  6592. (org-agenda-set-mode-name)
  6593. (message "Deadlines inclusion turned %s"
  6594. (if org-agenda-include-deadlines "on" "off")))
  6595. (defun org-agenda-toggle-time-grid ()
  6596. "Toggle time grid in an agenda buffer."
  6597. (interactive)
  6598. (org-agenda-check-type t 'agenda)
  6599. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6600. (org-agenda-redo)
  6601. (org-agenda-set-mode-name)
  6602. (message "Time-grid turned %s"
  6603. (if org-agenda-use-time-grid "on" "off")))
  6604. (defun org-agenda-set-mode-name ()
  6605. "Set the mode name to indicate all the small mode settings."
  6606. (setq mode-name
  6607. (list "Org-Agenda"
  6608. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6609. " "
  6610. '(:eval (org-agenda-span-name org-agenda-current-span))
  6611. (if org-agenda-follow-mode " Follow" "")
  6612. (if org-agenda-entry-text-mode " ETxt" "")
  6613. (if org-agenda-include-diary " Diary" "")
  6614. (if org-agenda-include-deadlines " Ddl" "")
  6615. (if org-agenda-use-time-grid " Grid" "")
  6616. (if (and (boundp 'org-habit-show-habits)
  6617. org-habit-show-habits) " Habit" "")
  6618. (cond
  6619. ((consp org-agenda-show-log) " LogAll")
  6620. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6621. (org-agenda-show-log " Log")
  6622. (t ""))
  6623. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6624. :preset-filter))
  6625. '(:eval (org-propertize
  6626. (concat " <"
  6627. (mapconcat
  6628. 'identity
  6629. (append
  6630. (get 'org-agenda-category-filter :preset-filter)
  6631. org-agenda-category-filter)
  6632. "")
  6633. ">")
  6634. 'face 'org-agenda-filter-category
  6635. 'help-echo "Category used in filtering"))
  6636. "")
  6637. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6638. :preset-filter))
  6639. '(:eval (org-propertize
  6640. (concat " {"
  6641. (mapconcat
  6642. 'identity
  6643. (append
  6644. (get 'org-agenda-tag-filter :preset-filter)
  6645. org-agenda-tag-filter)
  6646. "")
  6647. "}")
  6648. 'face 'org-agenda-filter-tags
  6649. 'help-echo "Tags used in filtering"))
  6650. "")
  6651. (if org-agenda-archives-mode
  6652. (if (eq org-agenda-archives-mode t)
  6653. " Archives"
  6654. (format " :%s:" org-archive-tag))
  6655. "")
  6656. (if org-agenda-clockreport-mode
  6657. (if (eq org-agenda-clockreport-mode 'with-filter)
  6658. " Clock{}" " Clock")
  6659. "")))
  6660. (force-mode-line-update))
  6661. (defun org-agenda-post-command-hook ()
  6662. (setq org-agenda-type
  6663. (or (get-text-property (point) 'org-agenda-type)
  6664. (get-text-property (max (point-min) (1- (point)))
  6665. 'org-agenda-type))))
  6666. (defun org-agenda-next-line ()
  6667. "Move cursor to the next line, and show if follow mode is active."
  6668. (interactive)
  6669. (call-interactively 'next-line)
  6670. (org-agenda-do-context-action))
  6671. (defun org-agenda-previous-line ()
  6672. "Move cursor to the previous line, and show if follow-mode is active."
  6673. (interactive)
  6674. (call-interactively 'previous-line)
  6675. (org-agenda-do-context-action))
  6676. (defun org-agenda-do-context-action ()
  6677. "Show outline path and, maybe, follow mode window."
  6678. (let ((m (org-get-at-bol 'org-marker)))
  6679. (when (and (markerp m) (marker-buffer m))
  6680. (and org-agenda-follow-mode
  6681. (if org-agenda-follow-indirect
  6682. (org-agenda-tree-to-indirect-buffer)
  6683. (org-agenda-show)))
  6684. (and org-agenda-show-outline-path
  6685. (org-with-point-at m (org-display-outline-path t))))))
  6686. (defun org-agenda-show-priority ()
  6687. "Show the priority of the current item.
  6688. This priority is composed of the main priority given with the [#A] cookies,
  6689. and by additional input from the age of a schedules or deadline entry."
  6690. (interactive)
  6691. (let* ((pri (org-get-at-bol 'priority)))
  6692. (message "Priority is %d" (if pri pri -1000))))
  6693. (defun org-agenda-show-tags ()
  6694. "Show the tags applicable to the current item."
  6695. (interactive)
  6696. (let* ((tags (org-get-at-bol 'tags)))
  6697. (if tags
  6698. (message "Tags are :%s:"
  6699. (org-no-properties (mapconcat 'identity tags ":")))
  6700. (message "No tags associated with this line"))))
  6701. (defun org-agenda-goto (&optional highlight)
  6702. "Go to the Org-mode file which contains the item at point."
  6703. (interactive)
  6704. (let* ((marker (or (org-get-at-bol 'org-marker)
  6705. (org-agenda-error)))
  6706. (buffer (marker-buffer marker))
  6707. (pos (marker-position marker)))
  6708. (switch-to-buffer-other-window buffer)
  6709. (widen)
  6710. (push-mark)
  6711. (goto-char pos)
  6712. (when (eq major-mode 'org-mode)
  6713. (org-show-context 'agenda)
  6714. (save-excursion
  6715. (and (outline-next-heading)
  6716. (org-flag-heading nil)))) ; show the next heading
  6717. (when (outline-invisible-p)
  6718. (show-entry)) ; display invisible text
  6719. (recenter (/ (window-height) 2))
  6720. (run-hooks 'org-agenda-after-show-hook)
  6721. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6722. (defvar org-agenda-after-show-hook nil
  6723. "Normal hook run after an item has been shown from the agenda.
  6724. Point is in the buffer where the item originated.")
  6725. (defun org-agenda-kill ()
  6726. "Kill the entry or subtree belonging to the current agenda entry."
  6727. (interactive)
  6728. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6729. (let* ((marker (or (org-get-at-bol 'org-marker)
  6730. (org-agenda-error)))
  6731. (buffer (marker-buffer marker))
  6732. (pos (marker-position marker))
  6733. (type (org-get-at-bol 'type))
  6734. dbeg dend (n 0) conf)
  6735. (org-with-remote-undo buffer
  6736. (with-current-buffer buffer
  6737. (save-excursion
  6738. (goto-char pos)
  6739. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6740. (setq dbeg (progn (org-back-to-heading t) (point))
  6741. dend (org-end-of-subtree t t))
  6742. (setq dbeg (point-at-bol)
  6743. dend (min (point-max) (1+ (point-at-eol)))))
  6744. (goto-char dbeg)
  6745. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6746. (setq conf (or (eq t org-agenda-confirm-kill)
  6747. (and (numberp org-agenda-confirm-kill)
  6748. (> n org-agenda-confirm-kill))))
  6749. (and conf
  6750. (not (y-or-n-p
  6751. (format "Delete entry with %d lines in buffer \"%s\"? "
  6752. n (buffer-name buffer))))
  6753. (error "Abort"))
  6754. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6755. (with-current-buffer buffer (delete-region dbeg dend))
  6756. (message "Agenda item and source killed"))))
  6757. (defvar org-archive-default-command)
  6758. (defun org-agenda-archive-default ()
  6759. "Archive the entry or subtree belonging to the current agenda entry."
  6760. (interactive)
  6761. (require 'org-archive)
  6762. (org-agenda-archive-with org-archive-default-command))
  6763. (defun org-agenda-archive-default-with-confirmation ()
  6764. "Archive the entry or subtree belonging to the current agenda entry."
  6765. (interactive)
  6766. (require 'org-archive)
  6767. (org-agenda-archive-with org-archive-default-command 'confirm))
  6768. (defun org-agenda-archive ()
  6769. "Archive the entry or subtree belonging to the current agenda entry."
  6770. (interactive)
  6771. (org-agenda-archive-with 'org-archive-subtree))
  6772. (defun org-agenda-archive-to-archive-sibling ()
  6773. "Move the entry to the archive sibling."
  6774. (interactive)
  6775. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6776. (defun org-agenda-archive-with (cmd &optional confirm)
  6777. "Move the entry to the archive sibling."
  6778. (interactive)
  6779. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6780. (let* ((marker (or (org-get-at-bol 'org-marker)
  6781. (org-agenda-error)))
  6782. (buffer (marker-buffer marker))
  6783. (pos (marker-position marker)))
  6784. (org-with-remote-undo buffer
  6785. (with-current-buffer buffer
  6786. (if (eq major-mode 'org-mode)
  6787. (if (and confirm
  6788. (not (y-or-n-p "Archive this subtree or entry? ")))
  6789. (error "Abort")
  6790. (save-excursion
  6791. (goto-char pos)
  6792. (org-remove-subtree-entries-from-agenda)
  6793. (org-back-to-heading t)
  6794. (funcall cmd)))
  6795. (error "Archiving works only in Org-mode files"))))))
  6796. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6797. "Remove all lines in the agenda that correspond to a given subtree.
  6798. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6799. If this information is not given, the function uses the tree at point."
  6800. (let ((buf (or buf (current-buffer))) m p)
  6801. (save-excursion
  6802. (unless (and beg end)
  6803. (org-back-to-heading t)
  6804. (setq beg (point))
  6805. (org-end-of-subtree t)
  6806. (setq end (point)))
  6807. (set-buffer (get-buffer org-agenda-buffer-name))
  6808. (save-excursion
  6809. (goto-char (point-max))
  6810. (beginning-of-line 1)
  6811. (while (not (bobp))
  6812. (when (and (setq m (org-get-at-bol 'org-marker))
  6813. (equal buf (marker-buffer m))
  6814. (setq p (marker-position m))
  6815. (>= p beg)
  6816. (< p end))
  6817. (let ((inhibit-read-only t))
  6818. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6819. (beginning-of-line 0))))))
  6820. (defun org-agenda-refile (&optional goto rfloc no-update)
  6821. "Refile the item at point."
  6822. (interactive "P")
  6823. (if (equal goto '(16))
  6824. (org-refile-goto-last-stored)
  6825. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6826. (org-agenda-error)))
  6827. (buffer (marker-buffer marker))
  6828. (pos (marker-position marker))
  6829. (rfloc (or rfloc
  6830. (org-refile-get-location
  6831. (if goto "Goto" "Refile to") buffer
  6832. org-refile-allow-creating-parent-nodes))))
  6833. (with-current-buffer buffer
  6834. (save-excursion
  6835. (save-restriction
  6836. (widen)
  6837. (goto-char marker)
  6838. (org-remove-subtree-entries-from-agenda)
  6839. (org-refile goto buffer rfloc)))))
  6840. (unless no-update (org-agenda-redo))))
  6841. (defun org-agenda-open-link (&optional arg)
  6842. "Follow the link in the current line, if any.
  6843. This looks for a link in the displayed line in the agenda. It also looks
  6844. at the text of the entry itself."
  6845. (interactive "P")
  6846. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6847. (org-get-at-bol 'org-marker)))
  6848. (buffer (and marker (marker-buffer marker)))
  6849. (prefix (buffer-substring
  6850. (point-at-bol) (point-at-eol))))
  6851. (cond
  6852. (buffer
  6853. (with-current-buffer buffer
  6854. (save-excursion
  6855. (save-restriction
  6856. (widen)
  6857. (goto-char marker)
  6858. (org-offer-links-in-entry arg prefix)))))
  6859. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6860. (save-excursion
  6861. (beginning-of-line 1)
  6862. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6863. (org-open-link-from-string (match-string 1)))
  6864. (t (error "No link to open here")))))
  6865. (defun org-agenda-copy-local-variable (var)
  6866. "Get a variable from a referenced buffer and install it here."
  6867. (let ((m (org-get-at-bol 'org-marker)))
  6868. (when (and m (buffer-live-p (marker-buffer m)))
  6869. (org-set-local var (with-current-buffer (marker-buffer m)
  6870. (symbol-value var))))))
  6871. (defun org-agenda-switch-to (&optional delete-other-windows)
  6872. "Go to the Org-mode file which contains the item at point."
  6873. (interactive)
  6874. (if (and org-return-follows-link
  6875. (not (org-get-at-bol 'org-marker))
  6876. (org-in-regexp org-bracket-link-regexp))
  6877. (org-open-link-from-string (match-string 0))
  6878. (let* ((marker (or (org-get-at-bol 'org-marker)
  6879. (org-agenda-error)))
  6880. (buffer (marker-buffer marker))
  6881. (pos (marker-position marker)))
  6882. (org-pop-to-buffer-same-window buffer)
  6883. (and delete-other-windows (delete-other-windows))
  6884. (widen)
  6885. (goto-char pos)
  6886. (when (eq major-mode 'org-mode)
  6887. (org-show-context 'agenda)
  6888. (save-excursion
  6889. (and (outline-next-heading)
  6890. (org-flag-heading nil))) ; show the next heading
  6891. (when (outline-invisible-p)
  6892. (show-entry)))))) ; display invisible text
  6893. (defun org-agenda-goto-mouse (ev)
  6894. "Go to the Org-mode file which contains the item at the mouse click."
  6895. (interactive "e")
  6896. (mouse-set-point ev)
  6897. (org-agenda-goto))
  6898. (defun org-agenda-show (&optional full-entry)
  6899. "Display the Org-mode file which contains the item at point.
  6900. With prefix argument FULL-ENTRY, make the entire entry visible
  6901. if it was hidden in the outline."
  6902. (interactive "P")
  6903. (let ((win (selected-window)))
  6904. (if full-entry
  6905. (let ((org-show-entry-below t))
  6906. (org-agenda-goto t))
  6907. (org-agenda-goto t))
  6908. (select-window win)))
  6909. (defvar org-agenda-show-window nil)
  6910. (defun org-agenda-show-and-scroll-up (&optional arg)
  6911. "Display the Org-mode file which contains the item at point.
  6912. When called repeatedly, scroll the window that is displaying the buffer.
  6913. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6914. `show-subtree' to display the item, so that drawers and logbooks stay
  6915. folded."
  6916. (interactive "P")
  6917. (let ((win (selected-window)))
  6918. (if (and (window-live-p org-agenda-show-window)
  6919. (eq this-command last-command))
  6920. (progn
  6921. (select-window org-agenda-show-window)
  6922. (ignore-errors (scroll-up)))
  6923. (org-agenda-goto t)
  6924. (if arg (org-show-entry) (show-subtree))
  6925. (setq org-agenda-show-window (selected-window)))
  6926. (select-window win)))
  6927. (defun org-agenda-show-scroll-down ()
  6928. "Scroll down the window showing the agenda."
  6929. (interactive)
  6930. (let ((win (selected-window)))
  6931. (when (window-live-p org-agenda-show-window)
  6932. (select-window org-agenda-show-window)
  6933. (ignore-errors (scroll-down))
  6934. (select-window win))))
  6935. (defun org-agenda-show-1 (&optional more)
  6936. "Display the Org-mode file which contains the item at point.
  6937. The prefix arg selects the amount of information to display:
  6938. 0 hide the subtree
  6939. 1 just show the entry according to defaults.
  6940. 2 show the children view
  6941. 3 show the subtree view
  6942. 4 show the entire subtree and any LOGBOOK drawers
  6943. 5 show the entire subtree and any drawers
  6944. With prefix argument FULL-ENTRY, make the entire entry visible
  6945. if it was hidden in the outline."
  6946. (interactive "p")
  6947. (let ((win (selected-window)))
  6948. (org-agenda-goto t)
  6949. (org-recenter-heading 1)
  6950. (cond
  6951. ((= more 0)
  6952. (hide-subtree)
  6953. (save-excursion
  6954. (org-back-to-heading)
  6955. (run-hook-with-args 'org-cycle-hook 'folded))
  6956. (message "Remote: FOLDED"))
  6957. ((and (org-called-interactively-p 'any) (= more 1))
  6958. (message "Remote: show with default settings"))
  6959. ((= more 2)
  6960. (show-entry)
  6961. (show-children)
  6962. (save-excursion
  6963. (org-back-to-heading)
  6964. (run-hook-with-args 'org-cycle-hook 'children))
  6965. (message "Remote: CHILDREN"))
  6966. ((= more 3)
  6967. (show-subtree)
  6968. (save-excursion
  6969. (org-back-to-heading)
  6970. (run-hook-with-args 'org-cycle-hook 'subtree))
  6971. (message "Remote: SUBTREE"))
  6972. ((= more 4)
  6973. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6974. (org-drawer-regexp
  6975. (concat "^[ \t]*:\\("
  6976. (mapconcat 'regexp-quote org-drawers "\\|")
  6977. "\\):[ \t]*$")))
  6978. (show-subtree)
  6979. (save-excursion
  6980. (org-back-to-heading)
  6981. (org-cycle-hide-drawers 'subtree)))
  6982. (message "Remote: SUBTREE AND LOGBOOK"))
  6983. ((> more 4)
  6984. (show-subtree)
  6985. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6986. (select-window win)))
  6987. (defun org-recenter-heading (n)
  6988. (save-excursion
  6989. (org-back-to-heading)
  6990. (recenter n)))
  6991. (defvar org-agenda-cycle-counter nil)
  6992. (defun org-agenda-cycle-show (&optional n)
  6993. "Show the current entry in another window, with default settings.
  6994. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6995. When use repeatedly in immediate succession, the remote entry will cycle
  6996. through visibility
  6997. children -> subtree -> folded
  6998. When called with a numeric prefix arg, that arg will be passed through to
  6999. `org-agenda-show-1'. For the interpretation of that argument, see the
  7000. docstring of `org-agenda-show-1'."
  7001. (interactive "P")
  7002. (if (integerp n)
  7003. (setq org-agenda-cycle-counter n)
  7004. (if (not (eq last-command this-command))
  7005. (setq org-agenda-cycle-counter 1)
  7006. (if (equal org-agenda-cycle-counter 0)
  7007. (setq org-agenda-cycle-counter 2)
  7008. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7009. (if (> org-agenda-cycle-counter 3)
  7010. (setq org-agenda-cycle-counter 0)))))
  7011. (org-agenda-show-1 org-agenda-cycle-counter))
  7012. (defun org-agenda-recenter (arg)
  7013. "Display the Org-mode file which contains the item at point and recenter."
  7014. (interactive "P")
  7015. (let ((win (selected-window)))
  7016. (org-agenda-goto t)
  7017. (recenter arg)
  7018. (select-window win)))
  7019. (defun org-agenda-show-mouse (ev)
  7020. "Display the Org-mode file which contains the item at the mouse click."
  7021. (interactive "e")
  7022. (mouse-set-point ev)
  7023. (org-agenda-show))
  7024. (defun org-agenda-check-no-diary ()
  7025. "Check if the entry is a diary link and abort if yes."
  7026. (if (org-get-at-bol 'org-agenda-diary-link)
  7027. (org-agenda-error)))
  7028. (defun org-agenda-error ()
  7029. (error "Command not allowed in this line"))
  7030. (defun org-agenda-tree-to-indirect-buffer ()
  7031. "Show the subtree corresponding to the current entry in an indirect buffer.
  7032. This calls the command `org-tree-to-indirect-buffer' from the original
  7033. Org-mode buffer.
  7034. With numerical prefix arg ARG, go up to this level and then take that tree.
  7035. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7036. use the dedicated frame)."
  7037. (interactive)
  7038. (if (and current-prefix-arg (listp current-prefix-arg))
  7039. (org-agenda-do-tree-to-indirect-buffer)
  7040. (let ((agenda-window (selected-window))
  7041. (indirect-window
  7042. (and org-last-indirect-buffer
  7043. (get-buffer-window org-last-indirect-buffer))))
  7044. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7045. (unwind-protect
  7046. (progn
  7047. (unless (and indirect-window (window-live-p indirect-window))
  7048. (setq indirect-window (split-window agenda-window)))
  7049. (select-window indirect-window)
  7050. (switch-to-buffer org-last-indirect-buffer :norecord)
  7051. (fit-window-to-buffer indirect-window))
  7052. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7053. (defun org-agenda-do-tree-to-indirect-buffer ()
  7054. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7055. (org-agenda-check-no-diary)
  7056. (let* ((marker (or (org-get-at-bol 'org-marker)
  7057. (org-agenda-error)))
  7058. (buffer (marker-buffer marker))
  7059. (pos (marker-position marker)))
  7060. (with-current-buffer buffer
  7061. (save-excursion
  7062. (goto-char pos)
  7063. (call-interactively 'org-tree-to-indirect-buffer)))))
  7064. (defvar org-last-heading-marker (make-marker)
  7065. "Marker pointing to the headline that last changed its TODO state
  7066. by a remote command from the agenda.")
  7067. (defun org-agenda-todo-nextset ()
  7068. "Switch TODO entry to next sequence."
  7069. (interactive)
  7070. (org-agenda-todo 'nextset))
  7071. (defun org-agenda-todo-previousset ()
  7072. "Switch TODO entry to previous sequence."
  7073. (interactive)
  7074. (org-agenda-todo 'previousset))
  7075. (defun org-agenda-todo (&optional arg)
  7076. "Cycle TODO state of line at point, also in Org-mode file.
  7077. This changes the line at point, all other lines in the agenda referring to
  7078. the same tree node, and the headline of the tree node in the Org-mode file."
  7079. (interactive "P")
  7080. (org-agenda-check-no-diary)
  7081. (let* ((col (current-column))
  7082. (marker (or (org-get-at-bol 'org-marker)
  7083. (org-agenda-error)))
  7084. (buffer (marker-buffer marker))
  7085. (pos (marker-position marker))
  7086. (hdmarker (org-get-at-bol 'org-hd-marker))
  7087. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7088. (inhibit-read-only t)
  7089. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7090. (org-with-remote-undo buffer
  7091. (with-current-buffer buffer
  7092. (widen)
  7093. (goto-char pos)
  7094. (org-show-context 'agenda)
  7095. (save-excursion
  7096. (and (outline-next-heading)
  7097. (org-flag-heading nil))) ; show the next heading
  7098. (let ((current-prefix-arg arg))
  7099. (call-interactively 'org-todo))
  7100. (and (bolp) (forward-char 1))
  7101. (setq newhead (org-get-heading))
  7102. (when (and (org-bound-and-true-p
  7103. org-agenda-headline-snapshot-before-repeat)
  7104. (not (equal org-agenda-headline-snapshot-before-repeat
  7105. newhead))
  7106. todayp)
  7107. (setq newhead org-agenda-headline-snapshot-before-repeat
  7108. just-one t))
  7109. (save-excursion
  7110. (org-back-to-heading)
  7111. (move-marker org-last-heading-marker (point))))
  7112. (beginning-of-line 1)
  7113. (save-excursion
  7114. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7115. (org-move-to-column col))))
  7116. (defun org-agenda-add-note (&optional arg)
  7117. "Add a time-stamped note to the entry at point."
  7118. (interactive "P")
  7119. (org-agenda-check-no-diary)
  7120. (let* ((marker (or (org-get-at-bol 'org-marker)
  7121. (org-agenda-error)))
  7122. (buffer (marker-buffer marker))
  7123. (pos (marker-position marker))
  7124. (hdmarker (org-get-at-bol 'org-hd-marker))
  7125. (inhibit-read-only t))
  7126. (with-current-buffer buffer
  7127. (widen)
  7128. (goto-char pos)
  7129. (org-show-context 'agenda)
  7130. (save-excursion
  7131. (and (outline-next-heading)
  7132. (org-flag-heading nil))) ; show the next heading
  7133. (org-add-note))))
  7134. (defun org-agenda-change-all-lines (newhead hdmarker
  7135. &optional fixface just-this)
  7136. "Change all lines in the agenda buffer which match HDMARKER.
  7137. The new content of the line will be NEWHEAD (as modified by
  7138. `org-agenda-format-item'). HDMARKER is checked with
  7139. `equal' against all `org-hd-marker' text properties in the file.
  7140. If FIXFACE is non-nil, the face of each item is modified according to
  7141. the new TODO state.
  7142. If JUST-THIS is non-nil, change just the current line, not all.
  7143. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7144. (let* ((inhibit-read-only t)
  7145. (line (org-current-line))
  7146. (org-agenda-buffer (current-buffer))
  7147. (thetags (with-current-buffer (marker-buffer hdmarker)
  7148. (save-excursion (save-restriction (widen)
  7149. (goto-char hdmarker)
  7150. (org-get-tags-at)))))
  7151. props m pl undone-face done-face finish new dotime cat tags)
  7152. (save-excursion
  7153. (goto-char (point-max))
  7154. (beginning-of-line 1)
  7155. (while (not finish)
  7156. (setq finish (bobp))
  7157. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7158. (or (not just-this) (= (org-current-line) line))
  7159. (equal m hdmarker))
  7160. (setq props (text-properties-at (point))
  7161. dotime (org-get-at-bol 'dotime)
  7162. cat (org-get-at-bol 'org-category)
  7163. tags thetags
  7164. new
  7165. (let ((org-prefix-format-compiled
  7166. (or (get-text-property (point) 'format)
  7167. org-prefix-format-compiled))
  7168. (extra (org-get-at-bol 'extra)))
  7169. (with-current-buffer (marker-buffer hdmarker)
  7170. (save-excursion
  7171. (save-restriction
  7172. (widen)
  7173. (org-agenda-format-item extra newhead cat tags dotime)))))
  7174. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7175. undone-face (org-get-at-bol 'undone-face)
  7176. done-face (org-get-at-bol 'done-face))
  7177. (beginning-of-line 1)
  7178. (cond
  7179. ((equal new "")
  7180. (and (looking-at ".*\n?") (replace-match "")))
  7181. ((looking-at ".*")
  7182. (replace-match new t t)
  7183. (beginning-of-line 1)
  7184. (add-text-properties (point-at-bol) (point-at-eol) props)
  7185. (when fixface
  7186. (add-text-properties
  7187. (point-at-bol) (point-at-eol)
  7188. (list 'face
  7189. (if org-last-todo-state-is-todo
  7190. undone-face done-face))))
  7191. (org-agenda-highlight-todo 'line)
  7192. (beginning-of-line 1))
  7193. (t (error "Line update did not work"))))
  7194. (beginning-of-line 0)))
  7195. (org-finalize-agenda)))
  7196. (defun org-agenda-align-tags (&optional line)
  7197. "Align all tags in agenda items to `org-agenda-tags-column'."
  7198. (let ((inhibit-read-only t) l c)
  7199. (save-excursion
  7200. (goto-char (if line (point-at-bol) (point-min)))
  7201. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7202. (if line (point-at-eol) nil) t)
  7203. (add-text-properties
  7204. (match-beginning 2) (match-end 2)
  7205. (list 'face (delq nil (let ((prop (get-text-property
  7206. (match-beginning 2) 'face)))
  7207. (or (listp prop) (setq prop (list prop)))
  7208. (if (memq 'org-tag prop)
  7209. prop
  7210. (cons 'org-tag prop))))))
  7211. (setq l (- (match-end 2) (match-beginning 2))
  7212. c (if (< org-agenda-tags-column 0)
  7213. (- (abs org-agenda-tags-column) l)
  7214. org-agenda-tags-column))
  7215. (delete-region (match-beginning 1) (match-end 1))
  7216. (goto-char (match-beginning 1))
  7217. (insert (org-add-props
  7218. (make-string (max 1 (- c (current-column))) ?\ )
  7219. (plist-put (copy-sequence (text-properties-at (point)))
  7220. 'face nil))))
  7221. (goto-char (point-min))
  7222. (org-font-lock-add-tag-faces (point-max)))))
  7223. (defun org-agenda-priority-up ()
  7224. "Increase the priority of line at point, also in Org-mode file."
  7225. (interactive)
  7226. (org-agenda-priority 'up))
  7227. (defun org-agenda-priority-down ()
  7228. "Decrease the priority of line at point, also in Org-mode file."
  7229. (interactive)
  7230. (org-agenda-priority 'down))
  7231. (defun org-agenda-priority (&optional force-direction)
  7232. "Set the priority of line at point, also in Org-mode file.
  7233. This changes the line at point, all other lines in the agenda referring to
  7234. the same tree node, and the headline of the tree node in the Org-mode file."
  7235. (interactive)
  7236. (unless org-enable-priority-commands
  7237. (error "Priority commands are disabled"))
  7238. (org-agenda-check-no-diary)
  7239. (let* ((marker (or (org-get-at-bol 'org-marker)
  7240. (org-agenda-error)))
  7241. (hdmarker (org-get-at-bol 'org-hd-marker))
  7242. (buffer (marker-buffer hdmarker))
  7243. (pos (marker-position hdmarker))
  7244. (inhibit-read-only t)
  7245. newhead)
  7246. (org-with-remote-undo buffer
  7247. (with-current-buffer buffer
  7248. (widen)
  7249. (goto-char pos)
  7250. (org-show-context 'agenda)
  7251. (save-excursion
  7252. (and (outline-next-heading)
  7253. (org-flag-heading nil))) ; show the next heading
  7254. (funcall 'org-priority force-direction)
  7255. (end-of-line 1)
  7256. (setq newhead (org-get-heading)))
  7257. (org-agenda-change-all-lines newhead hdmarker)
  7258. (beginning-of-line 1))))
  7259. ;; FIXME: should fix the tags property of the agenda line.
  7260. (defun org-agenda-set-tags (&optional tag onoff)
  7261. "Set tags for the current headline."
  7262. (interactive)
  7263. (org-agenda-check-no-diary)
  7264. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7265. (call-interactively 'org-change-tag-in-region)
  7266. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7267. (org-agenda-error)))
  7268. (buffer (marker-buffer hdmarker))
  7269. (pos (marker-position hdmarker))
  7270. (inhibit-read-only t)
  7271. newhead)
  7272. (org-with-remote-undo buffer
  7273. (with-current-buffer buffer
  7274. (widen)
  7275. (goto-char pos)
  7276. (save-excursion
  7277. (org-show-context 'agenda))
  7278. (save-excursion
  7279. (and (outline-next-heading)
  7280. (org-flag-heading nil))) ; show the next heading
  7281. (goto-char pos)
  7282. (if tag
  7283. (org-toggle-tag tag onoff)
  7284. (call-interactively 'org-set-tags))
  7285. (end-of-line 1)
  7286. (setq newhead (org-get-heading)))
  7287. (org-agenda-change-all-lines newhead hdmarker)
  7288. (beginning-of-line 1)))))
  7289. (defun org-agenda-set-property ()
  7290. "Set a property for the current headline."
  7291. (interactive)
  7292. (org-agenda-check-no-diary)
  7293. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7294. (org-agenda-error)))
  7295. (buffer (marker-buffer hdmarker))
  7296. (pos (marker-position hdmarker))
  7297. (inhibit-read-only t)
  7298. newhead)
  7299. (org-with-remote-undo buffer
  7300. (with-current-buffer buffer
  7301. (widen)
  7302. (goto-char pos)
  7303. (save-excursion
  7304. (org-show-context 'agenda))
  7305. (save-excursion
  7306. (and (outline-next-heading)
  7307. (org-flag-heading nil))) ; show the next heading
  7308. (goto-char pos)
  7309. (call-interactively 'org-set-property)))))
  7310. (defun org-agenda-set-effort ()
  7311. "Set the effort property for the current headline."
  7312. (interactive)
  7313. (org-agenda-check-no-diary)
  7314. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7315. (org-agenda-error)))
  7316. (buffer (marker-buffer hdmarker))
  7317. (pos (marker-position hdmarker))
  7318. (inhibit-read-only t)
  7319. newhead)
  7320. (org-with-remote-undo buffer
  7321. (with-current-buffer buffer
  7322. (widen)
  7323. (goto-char pos)
  7324. (save-excursion
  7325. (org-show-context 'agenda))
  7326. (save-excursion
  7327. (and (outline-next-heading)
  7328. (org-flag-heading nil))) ; show the next heading
  7329. (goto-char pos)
  7330. (call-interactively 'org-set-effort)
  7331. (end-of-line 1)
  7332. (setq newhead (org-get-heading)))
  7333. (org-agenda-change-all-lines newhead hdmarker))))
  7334. (defun org-agenda-toggle-archive-tag ()
  7335. "Toggle the archive tag for the current entry."
  7336. (interactive)
  7337. (org-agenda-check-no-diary)
  7338. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7339. (org-agenda-error)))
  7340. (buffer (marker-buffer hdmarker))
  7341. (pos (marker-position hdmarker))
  7342. (inhibit-read-only t)
  7343. newhead)
  7344. (org-with-remote-undo buffer
  7345. (with-current-buffer buffer
  7346. (widen)
  7347. (goto-char pos)
  7348. (org-show-context 'agenda)
  7349. (save-excursion
  7350. (and (outline-next-heading)
  7351. (org-flag-heading nil))) ; show the next heading
  7352. (call-interactively 'org-toggle-archive-tag)
  7353. (end-of-line 1)
  7354. (setq newhead (org-get-heading)))
  7355. (org-agenda-change-all-lines newhead hdmarker)
  7356. (beginning-of-line 1))))
  7357. (defun org-agenda-do-date-later (arg)
  7358. (interactive "P")
  7359. (cond
  7360. ((or (equal arg '(16))
  7361. (memq last-command
  7362. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7363. (setq this-command 'org-agenda-date-later-minutes)
  7364. (org-agenda-date-later-minutes 1))
  7365. ((or (equal arg '(4))
  7366. (memq last-command
  7367. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7368. (setq this-command 'org-agenda-date-later-hours)
  7369. (org-agenda-date-later-hours 1))
  7370. (t
  7371. (org-agenda-date-later (prefix-numeric-value arg)))))
  7372. (defun org-agenda-do-date-earlier (arg)
  7373. (interactive "P")
  7374. (cond
  7375. ((or (equal arg '(16))
  7376. (memq last-command
  7377. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7378. (setq this-command 'org-agenda-date-earlier-minutes)
  7379. (org-agenda-date-earlier-minutes 1))
  7380. ((or (equal arg '(4))
  7381. (memq last-command
  7382. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7383. (setq this-command 'org-agenda-date-earlier-hours)
  7384. (org-agenda-date-earlier-hours 1))
  7385. (t
  7386. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7387. (defun org-agenda-date-later (arg &optional what)
  7388. "Change the date of this item to ARG day(s) later."
  7389. (interactive "p")
  7390. (org-agenda-check-type t 'agenda 'timeline)
  7391. (org-agenda-check-no-diary)
  7392. (let* ((marker (or (org-get-at-bol 'org-marker)
  7393. (org-agenda-error)))
  7394. (buffer (marker-buffer marker))
  7395. (pos (marker-position marker))
  7396. cdate today)
  7397. (org-with-remote-undo buffer
  7398. (with-current-buffer buffer
  7399. (widen)
  7400. (goto-char pos)
  7401. (if (not (org-at-timestamp-p))
  7402. (error "Cannot find time stamp"))
  7403. (when (and org-agenda-move-date-from-past-immediately-to-today
  7404. (equal arg 1)
  7405. (or (not what) (eq what 'day))
  7406. (not (save-match-data (org-at-date-range-p))))
  7407. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7408. cdate (calendar-absolute-from-gregorian
  7409. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7410. today (org-today))
  7411. (if (> today cdate)
  7412. ;; immediately shift to today
  7413. (setq arg (- today cdate))))
  7414. (org-timestamp-change arg (or what 'day))
  7415. (when (and (org-at-date-range-p)
  7416. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7417. (let ((end org-last-changed-timestamp))
  7418. (org-timestamp-change arg (or what 'day))
  7419. (setq org-last-changed-timestamp
  7420. (concat org-last-changed-timestamp "--" end)))))
  7421. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7422. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7423. (defun org-agenda-date-earlier (arg &optional what)
  7424. "Change the date of this item to ARG day(s) earlier."
  7425. (interactive "p")
  7426. (org-agenda-date-later (- arg) what))
  7427. (defun org-agenda-date-later-minutes (arg)
  7428. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7429. (interactive "p")
  7430. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7431. (org-agenda-date-later arg 'minute))
  7432. (defun org-agenda-date-earlier-minutes (arg)
  7433. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7434. (interactive "p")
  7435. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7436. (org-agenda-date-earlier arg 'minute))
  7437. (defun org-agenda-date-later-hours (arg)
  7438. "Change the time of this item, in hour steps."
  7439. (interactive "p")
  7440. (org-agenda-date-later arg 'hour))
  7441. (defun org-agenda-date-earlier-hours (arg)
  7442. "Change the time of this item, in hour steps."
  7443. (interactive "p")
  7444. (org-agenda-date-earlier arg 'hour))
  7445. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7446. "Show new date stamp via text properties."
  7447. ;; We use text properties to make this undoable
  7448. (let ((inhibit-read-only t)
  7449. (buffer-invisibility-spec))
  7450. (setq stamp (concat " " prefix " => " stamp))
  7451. (save-excursion
  7452. (goto-char (point-max))
  7453. (while (not (bobp))
  7454. (when (equal marker (org-get-at-bol 'org-marker))
  7455. (org-move-to-column (- (window-width) (length stamp)) t)
  7456. (org-agenda-fix-tags-filter-overlays-at (point))
  7457. (if (featurep 'xemacs)
  7458. ;; Use `duplicable' property to trigger undo recording
  7459. (let ((ex (make-extent nil nil))
  7460. (gl (make-glyph stamp)))
  7461. (set-glyph-face gl 'secondary-selection)
  7462. (set-extent-properties
  7463. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7464. (insert-extent ex (1- (point)) (point-at-eol)))
  7465. (add-text-properties
  7466. (1- (point)) (point-at-eol)
  7467. (list 'display (org-add-props stamp nil
  7468. 'face 'secondary-selection))))
  7469. (beginning-of-line 1))
  7470. (beginning-of-line 0)))))
  7471. (defun org-agenda-date-prompt (arg)
  7472. "Change the date of this item. Date is prompted for, with default today.
  7473. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7474. be used to request time specification in the time stamp."
  7475. (interactive "P")
  7476. (org-agenda-check-type t 'agenda 'timeline)
  7477. (org-agenda-check-no-diary)
  7478. (let* ((marker (or (org-get-at-bol 'org-marker)
  7479. (org-agenda-error)))
  7480. (buffer (marker-buffer marker))
  7481. (pos (marker-position marker)))
  7482. (org-with-remote-undo buffer
  7483. (with-current-buffer buffer
  7484. (widen)
  7485. (goto-char pos)
  7486. (if (not (org-at-timestamp-p t))
  7487. (error "Cannot find time stamp"))
  7488. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7489. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7490. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7491. (defun org-agenda-schedule (arg &optional time)
  7492. "Schedule the item at point.
  7493. ARG is passed through to `org-schedule'."
  7494. (interactive "P")
  7495. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7496. (org-agenda-check-no-diary)
  7497. (let* ((marker (or (org-get-at-bol 'org-marker)
  7498. (org-agenda-error)))
  7499. (type (marker-insertion-type marker))
  7500. (buffer (marker-buffer marker))
  7501. (pos (marker-position marker))
  7502. (org-insert-labeled-timestamps-at-point nil)
  7503. ts)
  7504. (set-marker-insertion-type marker t)
  7505. (org-with-remote-undo buffer
  7506. (with-current-buffer buffer
  7507. (widen)
  7508. (goto-char pos)
  7509. (setq ts (org-schedule arg time)))
  7510. (org-agenda-show-new-time marker ts "S"))
  7511. (message "Item scheduled for %s" ts)))
  7512. (defun org-agenda-deadline (arg &optional time)
  7513. "Schedule the item at point.
  7514. ARG is passed through to `org-deadline'."
  7515. (interactive "P")
  7516. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7517. (org-agenda-check-no-diary)
  7518. (let* ((marker (or (org-get-at-bol 'org-marker)
  7519. (org-agenda-error)))
  7520. (buffer (marker-buffer marker))
  7521. (pos (marker-position marker))
  7522. (org-insert-labeled-timestamps-at-point nil)
  7523. ts)
  7524. (org-with-remote-undo buffer
  7525. (with-current-buffer buffer
  7526. (widen)
  7527. (goto-char pos)
  7528. (setq ts (org-deadline arg time)))
  7529. (org-agenda-show-new-time marker ts "D"))
  7530. (message "Deadline for this item set to %s" ts)))
  7531. (defun org-agenda-action ()
  7532. "Select entry for agenda action, or execute an agenda action.
  7533. This command prompts for another letter. Valid inputs are:
  7534. m Mark the entry at point for an agenda action
  7535. s Schedule the marked entry to the date at the cursor
  7536. d Set the deadline of the marked entry to the date at the cursor
  7537. r Call `org-remember' with cursor date as the default date
  7538. c Call `org-capture' with cursor date as the default date
  7539. SPC Show marked entry in other window
  7540. TAB Visit marked entry in other window
  7541. The cursor may be at a date in the calendar, or in the Org agenda."
  7542. (interactive)
  7543. (let (ans)
  7544. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7545. (setq ans (read-char-exclusive))
  7546. (cond
  7547. ((equal ans ?m)
  7548. ;; Mark this entry
  7549. (if (eq major-mode 'org-agenda-mode)
  7550. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7551. (org-get-at-bol 'org-marker))))
  7552. (if m
  7553. (progn
  7554. (move-marker org-agenda-action-marker
  7555. (marker-position m) (marker-buffer m))
  7556. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7557. (error "Don't know which entry to mark")))
  7558. (error "This command works only in the agenda")))
  7559. ((equal ans ?s)
  7560. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7561. ((equal ans ?d)
  7562. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7563. ((equal ans ?r)
  7564. (org-agenda-do-action '(org-remember) t))
  7565. ((equal ans ?c)
  7566. (org-agenda-do-action '(org-capture) t))
  7567. ((equal ans ?\ )
  7568. (let ((cw (selected-window)))
  7569. (org-switch-to-buffer-other-window
  7570. (marker-buffer org-agenda-action-marker))
  7571. (goto-char org-agenda-action-marker)
  7572. (org-show-context 'agenda)
  7573. (select-window cw)))
  7574. ((equal ans ?\C-i)
  7575. (org-switch-to-buffer-other-window
  7576. (marker-buffer org-agenda-action-marker))
  7577. (goto-char org-agenda-action-marker)
  7578. (org-show-context 'agenda))
  7579. (t (error "Invalid agenda action %c" ans)))))
  7580. (defun org-agenda-do-action (form &optional current-buffer)
  7581. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7582. (let ((org-overriding-default-time (org-get-cursor-date)))
  7583. (if current-buffer
  7584. (eval form)
  7585. (if (not (marker-buffer org-agenda-action-marker))
  7586. (error "No entry has been selected for agenda action")
  7587. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7588. (save-excursion
  7589. (save-restriction
  7590. (widen)
  7591. (goto-char org-agenda-action-marker)
  7592. (eval form))))))))
  7593. (defun org-agenda-clock-in (&optional arg)
  7594. "Start the clock on the currently selected item."
  7595. (interactive "P")
  7596. (org-agenda-check-no-diary)
  7597. (if (equal arg '(4))
  7598. (org-clock-in arg)
  7599. (let* ((marker (or (org-get-at-bol 'org-marker)
  7600. (org-agenda-error)))
  7601. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7602. marker))
  7603. (pos (marker-position marker))
  7604. newhead)
  7605. (org-with-remote-undo (marker-buffer marker)
  7606. (with-current-buffer (marker-buffer marker)
  7607. (widen)
  7608. (goto-char pos)
  7609. (org-show-context 'agenda)
  7610. (org-show-entry)
  7611. (org-cycle-hide-drawers 'children)
  7612. (org-clock-in arg)
  7613. (setq newhead (org-get-heading)))
  7614. (org-agenda-change-all-lines newhead hdmarker)))))
  7615. (defun org-agenda-clock-out ()
  7616. "Stop the currently running clock."
  7617. (interactive)
  7618. (unless (marker-buffer org-clock-marker)
  7619. (error "No running clock"))
  7620. (let ((marker (make-marker)) newhead)
  7621. (org-with-remote-undo (marker-buffer org-clock-marker)
  7622. (with-current-buffer (marker-buffer org-clock-marker)
  7623. (save-excursion
  7624. (save-restriction
  7625. (widen)
  7626. (goto-char org-clock-marker)
  7627. (org-back-to-heading t)
  7628. (move-marker marker (point))
  7629. (org-clock-out)
  7630. (setq newhead (org-get-heading))))))
  7631. (org-agenda-change-all-lines newhead marker)
  7632. (move-marker marker nil)))
  7633. (defun org-agenda-clock-cancel (&optional arg)
  7634. "Cancel the currently running clock."
  7635. (interactive "P")
  7636. (unless (marker-buffer org-clock-marker)
  7637. (error "No running clock"))
  7638. (org-with-remote-undo (marker-buffer org-clock-marker)
  7639. (org-clock-cancel)))
  7640. (defun org-agenda-clock-goto ()
  7641. "Jump to the currently clocked in task within the agenda.
  7642. If the currently clocked in task is not listed in the agenda
  7643. buffer, display it in another window."
  7644. (interactive)
  7645. (let (pos)
  7646. (mapc (lambda (o)
  7647. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7648. (setq pos (overlay-start o))))
  7649. (overlays-in (point-min) (point-max)))
  7650. (cond (pos (goto-char pos))
  7651. ;; If the currently clocked entry is not in the agenda
  7652. ;; buffer, we visit it in another window:
  7653. (org-clock-current-task
  7654. (org-switch-to-buffer-other-window (org-clock-goto)))
  7655. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7656. (defun org-agenda-diary-entry-in-org-file ()
  7657. "Make a diary entry in the file `org-agenda-diary-file'."
  7658. (let (d1 d2 char (text "") dp1 dp2)
  7659. (if (equal (buffer-name) "*Calendar*")
  7660. (setq d1 (calendar-cursor-to-date t)
  7661. d2 (car calendar-mark-ring))
  7662. (setq dp1 (get-text-property (point-at-bol) 'day))
  7663. (unless dp1 (error "No date defined in current line"))
  7664. (setq d1 (calendar-gregorian-from-absolute dp1)
  7665. d2 (and (ignore-errors (mark))
  7666. (save-excursion
  7667. (goto-char (mark))
  7668. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7669. (calendar-gregorian-from-absolute dp2))))
  7670. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7671. (setq char (read-char-exclusive))
  7672. (cond
  7673. ((equal char ?d)
  7674. (setq text (read-string "Day entry: "))
  7675. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7676. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7677. ((equal char ?a)
  7678. (setq d1 (list (car d1) (nth 1 d1)
  7679. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7680. (nth 2 d1))))
  7681. (setq text (read-string "Anniversary (use %d to show years): "))
  7682. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7683. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7684. ((equal char ?b)
  7685. (setq text (read-string "Block entry: "))
  7686. (unless (and d1 d2 (not (equal d1 d2)))
  7687. (error "No block of days selected"))
  7688. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7689. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7690. ((equal char ?j)
  7691. (org-switch-to-buffer-other-window
  7692. (find-file-noselect org-agenda-diary-file))
  7693. (require 'org-datetree)
  7694. (org-datetree-find-date-create d1)
  7695. (org-reveal t))
  7696. (t (error "Invalid selection character `%c'" char)))))
  7697. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7698. "Where in `org-agenda-diary-file' should new entries be added?
  7699. Valid values:
  7700. date-tree in the date tree, as child of the date
  7701. top-level as top-level entries at the end of the file."
  7702. :group 'org-agenda
  7703. :type '(choice
  7704. (const :tag "in a date tree" date-tree)
  7705. (const :tag "as top level at end of file" top-level)))
  7706. (defcustom org-agenda-insert-diary-extract-time nil
  7707. "Non-nil means extract any time specification from the diary entry."
  7708. :group 'org-agenda
  7709. :version "24.1"
  7710. :type 'boolean)
  7711. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7712. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7713. If TEXT is not empty, it will become the headline of the new entry, and
  7714. the resulting entry will not be shown. When TEXT is empty, switch to
  7715. `org-agenda-diary-file' and let the user finish the entry there."
  7716. (let ((cw (current-window-configuration)))
  7717. (org-switch-to-buffer-other-window
  7718. (find-file-noselect org-agenda-diary-file))
  7719. (widen)
  7720. (goto-char (point-min))
  7721. (cond
  7722. ((eq type 'anniversary)
  7723. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7724. (progn
  7725. (or (org-at-heading-p t)
  7726. (progn
  7727. (outline-next-heading)
  7728. (insert "* Anniversaries\n\n")
  7729. (beginning-of-line -1)))))
  7730. (outline-next-heading)
  7731. (org-back-over-empty-lines)
  7732. (backward-char 1)
  7733. (insert "\n")
  7734. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7735. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7736. ((eq type 'day)
  7737. (let ((org-prefix-has-time t)
  7738. (org-agenda-time-leading-zero t)
  7739. fmt time time2)
  7740. (if org-agenda-insert-diary-extract-time
  7741. ;; Use org-agenda-format-item to parse text for a time-range and
  7742. ;; remove it. FIXME: This is a hack, we should refactor
  7743. ;; that function to make time extraction available separately
  7744. (setq fmt (org-agenda-format-item nil text nil nil t)
  7745. time (get-text-property 0 'time fmt)
  7746. time2 (if (> (length time) 0)
  7747. ;; split-string removes trailing ...... if
  7748. ;; no end time given. First space
  7749. ;; separates time from date.
  7750. (concat " " (car (split-string time "\\.")))
  7751. nil)
  7752. text (get-text-property 0 'txt fmt)))
  7753. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7754. (org-agenda-insert-diary-as-top-level text)
  7755. (require 'org-datetree)
  7756. (org-datetree-find-date-create d1)
  7757. (org-agenda-insert-diary-make-new-entry text))
  7758. (org-insert-time-stamp (org-time-from-absolute
  7759. (calendar-absolute-from-gregorian d1))
  7760. nil nil nil nil time2))
  7761. (end-of-line 0))
  7762. ((eq type 'block)
  7763. (if (> (calendar-absolute-from-gregorian d1)
  7764. (calendar-absolute-from-gregorian d2))
  7765. (setq d1 (prog1 d2 (setq d2 d1))))
  7766. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7767. (org-agenda-insert-diary-as-top-level text)
  7768. (require 'org-datetree)
  7769. (org-datetree-find-date-create d1)
  7770. (org-agenda-insert-diary-make-new-entry text))
  7771. (org-insert-time-stamp (org-time-from-absolute
  7772. (calendar-absolute-from-gregorian d1)))
  7773. (insert "--")
  7774. (org-insert-time-stamp (org-time-from-absolute
  7775. (calendar-absolute-from-gregorian d2)))
  7776. (end-of-line 0)))
  7777. (if (string-match "\\S-" text)
  7778. (progn
  7779. (set-window-configuration cw)
  7780. (message "%s entry added to %s"
  7781. (capitalize (symbol-name type))
  7782. (abbreviate-file-name org-agenda-diary-file)))
  7783. (org-reveal t)
  7784. (message "Please finish entry here"))))
  7785. (defun org-agenda-insert-diary-as-top-level (text)
  7786. "Make new entry as a top-level entry at the end of the file.
  7787. Add TEXT as headline, and position the cursor in the second line so that
  7788. a timestamp can be added there."
  7789. (widen)
  7790. (goto-char (point-max))
  7791. (or (bolp) (insert "\n"))
  7792. (insert "* " text "\n")
  7793. (if org-adapt-indentation (org-indent-to-column 2)))
  7794. (defun org-agenda-insert-diary-make-new-entry (text)
  7795. "Make new entry as last child of current entry.
  7796. Add TEXT as headline, and position the cursor in the second line so that
  7797. a timestamp can be added there."
  7798. (let ((org-show-following-heading t)
  7799. (org-show-siblings t)
  7800. (org-show-hierarchy-above t)
  7801. (org-show-entry-below t)
  7802. col)
  7803. (outline-next-heading)
  7804. (org-back-over-empty-lines)
  7805. (or (looking-at "[ \t]*$")
  7806. (progn (insert "\n") (backward-char 1)))
  7807. (org-insert-heading nil t)
  7808. (org-do-demote)
  7809. (setq col (current-column))
  7810. (insert text "\n")
  7811. (if org-adapt-indentation (org-indent-to-column col))
  7812. (let ((org-show-following-heading t)
  7813. (org-show-siblings t)
  7814. (org-show-hierarchy-above t)
  7815. (org-show-entry-below t))
  7816. (org-show-context))))
  7817. (defun org-agenda-diary-entry ()
  7818. "Make a diary entry, like the `i' command from the calendar.
  7819. All the standard commands work: block, weekly etc.
  7820. When `org-agenda-diary-file' points to a file,
  7821. `org-agenda-diary-entry-in-org-file' is called instead to create
  7822. entries in that Org-mode file."
  7823. (interactive)
  7824. (org-agenda-check-type t 'agenda 'timeline)
  7825. (if (not (eq org-agenda-diary-file 'diary-file))
  7826. (org-agenda-diary-entry-in-org-file)
  7827. (require 'diary-lib)
  7828. (let* ((char (progn
  7829. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7830. (read-char-exclusive)))
  7831. (cmd (cdr (assoc char
  7832. '((?d . insert-diary-entry)
  7833. (?w . insert-weekly-diary-entry)
  7834. (?m . insert-monthly-diary-entry)
  7835. (?y . insert-yearly-diary-entry)
  7836. (?a . insert-anniversary-diary-entry)
  7837. (?b . insert-block-diary-entry)
  7838. (?c . insert-cyclic-diary-entry)))))
  7839. (oldf (symbol-function 'calendar-cursor-to-date))
  7840. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7841. (point (point))
  7842. (mark (or (mark t) (point))))
  7843. (unless cmd
  7844. (error "No command associated with <%c>" char))
  7845. (unless (and (get-text-property point 'day)
  7846. (or (not (equal ?b char))
  7847. (get-text-property mark 'day)))
  7848. (error "Don't know which date to use for diary entry"))
  7849. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7850. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7851. (let ((calendar-mark-ring
  7852. (list (calendar-gregorian-from-absolute
  7853. (or (get-text-property mark 'day)
  7854. (get-text-property point 'day))))))
  7855. (unwind-protect
  7856. (progn
  7857. (fset 'calendar-cursor-to-date
  7858. (lambda (&optional error dummy)
  7859. (calendar-gregorian-from-absolute
  7860. (get-text-property point 'day))))
  7861. (call-interactively cmd))
  7862. (fset 'calendar-cursor-to-date oldf))))))
  7863. (defun org-agenda-execute-calendar-command (cmd)
  7864. "Execute a calendar command from the agenda, with the date associated to
  7865. the cursor position."
  7866. (org-agenda-check-type t 'agenda 'timeline)
  7867. (require 'diary-lib)
  7868. (unless (get-text-property (point) 'day)
  7869. (error "Don't know which date to use for calendar command"))
  7870. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7871. (point (point))
  7872. (date (calendar-gregorian-from-absolute
  7873. (get-text-property point 'day)))
  7874. ;; the following 2 vars are needed in the calendar
  7875. (displayed-month (car date))
  7876. (displayed-year (nth 2 date)))
  7877. (unwind-protect
  7878. (progn
  7879. (fset 'calendar-cursor-to-date
  7880. (lambda (&optional error dummy)
  7881. (calendar-gregorian-from-absolute
  7882. (get-text-property point 'day))))
  7883. (call-interactively cmd))
  7884. (fset 'calendar-cursor-to-date oldf))))
  7885. (defun org-agenda-phases-of-moon ()
  7886. "Display the phases of the moon for the 3 months around the cursor date."
  7887. (interactive)
  7888. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7889. (defun org-agenda-holidays ()
  7890. "Display the holidays for the 3 months around the cursor date."
  7891. (interactive)
  7892. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7893. (defvar calendar-longitude)
  7894. (defvar calendar-latitude)
  7895. (defvar calendar-location-name)
  7896. (defun org-agenda-sunrise-sunset (arg)
  7897. "Display sunrise and sunset for the cursor date.
  7898. Latitude and longitude can be specified with the variables
  7899. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7900. argument, latitude and longitude will be prompted for."
  7901. (interactive "P")
  7902. (require 'solar)
  7903. (let ((calendar-longitude (if arg nil calendar-longitude))
  7904. (calendar-latitude (if arg nil calendar-latitude))
  7905. (calendar-location-name
  7906. (if arg "the given coordinates" calendar-location-name)))
  7907. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7908. (defun org-agenda-goto-calendar ()
  7909. "Open the Emacs calendar with the date at the cursor."
  7910. (interactive)
  7911. (org-agenda-check-type t 'agenda 'timeline)
  7912. (let* ((day (or (get-text-property (point) 'day)
  7913. (error "Don't know which date to open in calendar")))
  7914. (date (calendar-gregorian-from-absolute day))
  7915. (calendar-move-hook nil)
  7916. (calendar-view-holidays-initially-flag nil)
  7917. (calendar-view-diary-initially-flag nil))
  7918. (calendar)
  7919. (calendar-goto-date date)))
  7920. ;;;###autoload
  7921. (defun org-calendar-goto-agenda ()
  7922. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7923. This is a command that has to be installed in `calendar-mode-map'."
  7924. (interactive)
  7925. (org-agenda-list nil (calendar-absolute-from-gregorian
  7926. (calendar-cursor-to-date))
  7927. nil))
  7928. (defun org-agenda-convert-date ()
  7929. (interactive)
  7930. (org-agenda-check-type t 'agenda 'timeline)
  7931. (let ((day (get-text-property (point) 'day))
  7932. date s)
  7933. (unless day
  7934. (error "Don't know which date to convert"))
  7935. (setq date (calendar-gregorian-from-absolute day))
  7936. (setq s (concat
  7937. "Gregorian: " (calendar-date-string date) "\n"
  7938. "ISO: " (calendar-iso-date-string date) "\n"
  7939. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7940. "Julian: " (calendar-julian-date-string date) "\n"
  7941. "Astron. JD: " (calendar-astro-date-string date)
  7942. " (Julian date number at noon UTC)\n"
  7943. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7944. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7945. "French: " (calendar-french-date-string date) "\n"
  7946. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7947. "Mayan: " (calendar-mayan-date-string date) "\n"
  7948. "Coptic: " (calendar-coptic-date-string date) "\n"
  7949. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7950. "Persian: " (calendar-persian-date-string date) "\n"
  7951. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7952. (with-output-to-temp-buffer "*Dates*"
  7953. (princ s))
  7954. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7955. ;;; Bulk commands
  7956. (defvar org-agenda-bulk-marked-entries nil
  7957. "List of markers that refer to marked entries in the agenda.")
  7958. (defun org-agenda-bulk-marked-p ()
  7959. (eq (get-char-property (point-at-bol) 'type)
  7960. 'org-marked-entry-overlay))
  7961. (defun org-agenda-bulk-mark (&optional arg)
  7962. "Mark the entry at point for future bulk action."
  7963. (interactive "p")
  7964. (dotimes (i (max arg 1))
  7965. (unless (org-get-at-bol 'org-agenda-diary-link)
  7966. (let* ((m (org-get-at-bol 'org-hd-marker))
  7967. ov)
  7968. (unless (org-agenda-bulk-marked-p)
  7969. (unless m (error "Nothing to mark at point"))
  7970. (push m org-agenda-bulk-marked-entries)
  7971. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7972. (org-overlay-display ov "> "
  7973. (org-get-todo-face "TODO")
  7974. 'evaporate)
  7975. (overlay-put ov 'type 'org-marked-entry-overlay))
  7976. (beginning-of-line 2)
  7977. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7978. (beginning-of-line 2))
  7979. (message "%d entries marked for bulk action"
  7980. (length org-agenda-bulk-marked-entries))))))
  7981. (defun org-agenda-bulk-mark-regexp (regexp)
  7982. "Mark entries match REGEXP."
  7983. (interactive "sMark entries matching regexp: ")
  7984. (let (entries-marked)
  7985. (save-excursion
  7986. (goto-char (point-min))
  7987. (goto-char (next-single-property-change (point) 'txt))
  7988. (while (re-search-forward regexp nil t)
  7989. (when (string-match regexp (get-text-property (point) 'txt))
  7990. (setq entries-marked (+ entries-marked 1))
  7991. (call-interactively 'org-agenda-bulk-mark))))
  7992. (if (not entries-marked)
  7993. (message "No entry matching this regexp."))))
  7994. (defun org-agenda-bulk-unmark ()
  7995. "Unmark the entry at point for future bulk action."
  7996. (interactive)
  7997. (when (org-agenda-bulk-marked-p)
  7998. (org-agenda-bulk-remove-overlays
  7999. (point-at-bol) (+ 2 (point-at-bol)))
  8000. (setq org-agenda-bulk-marked-entries
  8001. (delete (org-get-at-bol 'org-hd-marker)
  8002. org-agenda-bulk-marked-entries)))
  8003. (beginning-of-line 2)
  8004. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8005. (beginning-of-line 2))
  8006. (message "%d entries marked for bulk action"
  8007. (length org-agenda-bulk-marked-entries)))
  8008. (defun org-agenda-bulk-toggle ()
  8009. "Toggle marking the entry at point for bulk action."
  8010. (interactive)
  8011. (if (org-agenda-bulk-marked-p)
  8012. (org-agenda-bulk-unmark)
  8013. (org-agenda-bulk-mark)))
  8014. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8015. "Remove the mark overlays between BEG and END in the agenda buffer.
  8016. BEG and END default to the buffer limits.
  8017. This only removes the overlays, it does not remove the markers
  8018. from the list in `org-agenda-bulk-marked-entries'."
  8019. (interactive)
  8020. (mapc (lambda (ov)
  8021. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8022. (delete-overlay ov)))
  8023. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8024. (defun org-agenda-bulk-remove-all-marks ()
  8025. "Remove all marks in the agenda buffer.
  8026. This will remove the markers, and the overlays."
  8027. (interactive)
  8028. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8029. (setq org-agenda-bulk-marked-entries nil)
  8030. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  8031. (defun org-agenda-bulk-action (&optional arg)
  8032. "Execute an remote-editing action on all marked entries.
  8033. The prefix arg is passed through to the command if possible."
  8034. (interactive "P")
  8035. ;; Make sure we have markers, and only valid ones
  8036. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8037. (mapc
  8038. (lambda (m)
  8039. (unless (and (markerp m)
  8040. (marker-buffer m)
  8041. (buffer-live-p (marker-buffer m))
  8042. (marker-position m))
  8043. (error "Marker %s for bulk command is invalid" m)))
  8044. org-agenda-bulk-marked-entries)
  8045. ;; Prompt for the bulk command
  8046. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  8047. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  8048. (when org-agenda-bulk-custom-functions
  8049. (concat " Custom: ["
  8050. (mapconcat (lambda(f) (char-to-string (car f)))
  8051. org-agenda-bulk-custom-functions "")
  8052. "]"))))
  8053. (let* ((action (read-char-exclusive))
  8054. (org-log-refile (if org-log-refile 'time nil))
  8055. (entries (reverse org-agenda-bulk-marked-entries))
  8056. redo-at-end
  8057. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8058. (cond
  8059. ((equal action ?$)
  8060. (setq cmd '(org-agenda-archive)))
  8061. ((equal action ?A)
  8062. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8063. ((member action '(?r ?w))
  8064. (setq rfloc (org-refile-get-location
  8065. "Refile to"
  8066. (marker-buffer (car org-agenda-bulk-marked-entries))
  8067. org-refile-allow-creating-parent-nodes))
  8068. (if (nth 3 rfloc)
  8069. (setcar (nthcdr 3 rfloc)
  8070. (move-marker (make-marker) (nth 3 rfloc)
  8071. (or (get-file-buffer (nth 1 rfloc))
  8072. (find-buffer-visiting (nth 1 rfloc))
  8073. (error "This should not happen")))))
  8074. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8075. redo-at-end t))
  8076. ((equal action ?t)
  8077. (setq state (org-icompleting-read
  8078. "Todo state: "
  8079. (with-current-buffer (marker-buffer (car entries))
  8080. (mapcar 'list org-todo-keywords-1))))
  8081. (setq cmd `(let ((org-inhibit-blocking t)
  8082. (org-inhibit-logging 'note))
  8083. (org-agenda-todo ,state))))
  8084. ((memq action '(?- ?+))
  8085. (setq tag (org-icompleting-read
  8086. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8087. (with-current-buffer (marker-buffer (car entries))
  8088. (delq nil
  8089. (mapcar (lambda (x)
  8090. (if (stringp (car x)) x)) org-tag-alist)))))
  8091. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8092. ((memq action '(?s ?d))
  8093. (let* ((date (unless arg
  8094. (org-read-date
  8095. nil nil nil
  8096. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8097. (ans (if arg nil org-read-date-final-answer))
  8098. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8099. (setq cmd `(let* ((bound (fboundp 'read-string))
  8100. (old (and bound (symbol-function 'read-string))))
  8101. (unwind-protect
  8102. (progn
  8103. (fset 'read-string (lambda (&rest ignore) ,ans))
  8104. (eval '(,c1 arg)))
  8105. (if bound
  8106. (fset 'read-string old)
  8107. (fmakunbound 'read-string)))))))
  8108. ((equal action ?S)
  8109. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8110. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8111. (let ((days (read-number
  8112. (format "Scatter tasks across how many %sdays: "
  8113. (if arg "week" "")) 7)))
  8114. (setq cmd
  8115. `(let ((distance (1+ (random ,days))))
  8116. (if arg
  8117. (let ((dist distance)
  8118. (day-of-week
  8119. (calendar-day-of-week
  8120. (calendar-gregorian-from-absolute (org-today)))))
  8121. (dotimes (i (1+ dist))
  8122. (while (member day-of-week org-agenda-weekend-days)
  8123. (incf distance)
  8124. (incf day-of-week)
  8125. (if (= day-of-week 7)
  8126. (setq day-of-week 0)))
  8127. (incf day-of-week)
  8128. (if (= day-of-week 7)
  8129. (setq day-of-week 0)))))
  8130. ;; silently fail when try to replan a sexp entry
  8131. (condition-case nil
  8132. (let* ((date (calendar-gregorian-from-absolute
  8133. (+ (org-today) distance)))
  8134. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8135. (nth 2 date))))
  8136. (org-agenda-schedule nil time))
  8137. (error nil)))))))
  8138. ((assoc action org-agenda-bulk-custom-functions)
  8139. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8140. redo-at-end t))
  8141. ((equal action ?f)
  8142. (setq cmd (list (intern
  8143. (org-icompleting-read "Function: "
  8144. obarray 'fboundp t nil nil)))))
  8145. (t (error "Invalid bulk action")))
  8146. ;; Sort the markers, to make sure that parents are handled before children
  8147. (setq entries (sort entries
  8148. (lambda (a b)
  8149. (cond
  8150. ((equal (marker-buffer a) (marker-buffer b))
  8151. (< (marker-position a) (marker-position b)))
  8152. (t
  8153. (string< (buffer-name (marker-buffer a))
  8154. (buffer-name (marker-buffer b))))))))
  8155. ;; Now loop over all markers and apply cmd
  8156. (while (setq e (pop entries))
  8157. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8158. (if (not pos)
  8159. (progn (message "Skipping removed entry at %s" e)
  8160. (setq cntskip (1+ cntskip)))
  8161. (goto-char pos)
  8162. (let (org-loop-over-headlines-in-active-region)
  8163. (eval cmd))
  8164. (setq org-agenda-bulk-marked-entries
  8165. (delete e org-agenda-bulk-marked-entries))
  8166. (setq cnt (1+ cnt))))
  8167. (setq org-agenda-bulk-marked-entries nil)
  8168. (org-agenda-bulk-remove-all-marks)
  8169. (when redo-at-end (org-agenda-redo))
  8170. (message "Acted on %d entries%s"
  8171. cnt
  8172. (if (= cntskip 0)
  8173. ""
  8174. (format ", skipped %d (disappeared before their turn)"
  8175. cntskip)))))
  8176. ;;; Flagging notes
  8177. (defun org-agenda-show-the-flagging-note ()
  8178. "Display the flagging note in the other window.
  8179. When called a second time in direct sequence, offer to remove the FLAGGING
  8180. tag and (if present) the flagging note."
  8181. (interactive)
  8182. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8183. (win (selected-window))
  8184. note heading newhead)
  8185. (unless hdmarker
  8186. (error "No linked entry at point"))
  8187. (if (and (eq this-command last-command)
  8188. (y-or-n-p "Unflag and remove any flagging note? "))
  8189. (progn
  8190. (org-agenda-remove-flag hdmarker)
  8191. (let ((win (get-buffer-window "*Flagging Note*")))
  8192. (and win (delete-window win)))
  8193. (message "Entry unflagged"))
  8194. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8195. (unless note
  8196. (error "No flagging note"))
  8197. (org-kill-new note)
  8198. (org-switch-to-buffer-other-window "*Flagging Note*")
  8199. (erase-buffer)
  8200. (insert note)
  8201. (goto-char (point-min))
  8202. (while (re-search-forward "\\\\n" nil t)
  8203. (replace-match "\n" t t))
  8204. (goto-char (point-min))
  8205. (select-window win)
  8206. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8207. (defun org-agenda-remove-flag (marker)
  8208. "Remove the FLAGGED tag and any flagging note in the entry."
  8209. (let (newhead)
  8210. (org-with-point-at marker
  8211. (org-toggle-tag "FLAGGED" 'off)
  8212. (org-entry-delete nil "THEFLAGGINGNOTE")
  8213. (setq newhead (org-get-heading)))
  8214. (org-agenda-change-all-lines newhead marker)
  8215. (message "Entry unflagged")))
  8216. (defun org-agenda-get-any-marker (&optional pos)
  8217. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8218. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8219. ;;; Appointment reminders
  8220. (defvar appt-time-msg-list)
  8221. ;;;###autoload
  8222. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8223. "Activate appointments found in `org-agenda-files'.
  8224. With a \\[universal-argument] prefix, refresh the list of
  8225. appointments.
  8226. If FILTER is t, interactively prompt the user for a regular
  8227. expression, and filter out entries that don't match it.
  8228. If FILTER is a string, use this string as a regular expression
  8229. for filtering entries out.
  8230. If FILTER is a function, filter out entries against which
  8231. calling the function returns nil. This function takes one
  8232. argument: an entry from `org-agenda-get-day-entries'.
  8233. FILTER can also be an alist with the car of each cell being
  8234. either 'headline or 'category. For example:
  8235. '((headline \"IMPORTANT\")
  8236. (category \"Work\"))
  8237. will only add headlines containing IMPORTANT or headlines
  8238. belonging to the \"Work\" category.
  8239. ARGS are symbols indicating what kind of entries to consider.
  8240. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8241. and :timestamp entries. See the docstring of `org-diary' for
  8242. details and examples."
  8243. (interactive "P")
  8244. (if refresh (setq appt-time-msg-list nil))
  8245. (if (eq filter t)
  8246. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8247. (let* ((cnt 0) ; count added events
  8248. (scope (or args '(:deadline :scheduled :timestamp)))
  8249. (org-agenda-new-buffers nil)
  8250. (org-deadline-warning-days 0)
  8251. ;; Do not use `org-today' here because appt only takes
  8252. ;; time and without date as argument, so it may pass wrong
  8253. ;; information otherwise
  8254. (today (org-date-to-gregorian
  8255. (time-to-days (current-time))))
  8256. (org-agenda-restrict nil)
  8257. (files (org-agenda-files 'unrestricted)) entries file
  8258. (org-agenda-buffer nil))
  8259. ;; Get all entries which may contain an appt
  8260. (org-prepare-agenda-buffers files)
  8261. (while (setq file (pop files))
  8262. (setq entries
  8263. (delq nil
  8264. (append entries
  8265. (apply 'org-agenda-get-day-entries
  8266. file today scope)))))
  8267. ;; Map thru entries and find if we should filter them out
  8268. (mapc
  8269. (lambda(x)
  8270. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8271. (cat (get-text-property 1 'org-category x))
  8272. (tod (get-text-property 1 'time-of-day x))
  8273. (ok (or (null filter)
  8274. (and (stringp filter) (string-match filter evt))
  8275. (and (functionp filter) (funcall filter x))
  8276. (and (listp filter)
  8277. (let ((cat-filter (cadr (assoc 'category filter)))
  8278. (evt-filter (cadr (assoc 'headline filter))))
  8279. (or (and (stringp cat-filter)
  8280. (string-match cat-filter cat))
  8281. (and (stringp evt-filter)
  8282. (string-match evt-filter evt))))))))
  8283. ;; FIXME: Shall we remove text-properties for the appt text?
  8284. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8285. (when (and ok tod)
  8286. (setq tod (concat "00" (number-to-string tod))
  8287. tod (when (string-match
  8288. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8289. (concat (match-string 1 tod) ":"
  8290. (match-string 2 tod))))
  8291. (appt-add tod evt)
  8292. (setq cnt (1+ cnt))))) entries)
  8293. (org-release-buffers org-agenda-new-buffers)
  8294. (if (eq cnt 0)
  8295. (message "No event to add")
  8296. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8297. (defun org-agenda-todayp (date)
  8298. "Does DATE mean today, when considering `org-extend-today-until'?"
  8299. (let ((today (org-today))
  8300. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8301. date)))
  8302. (eq date today)))
  8303. (defun org-agenda-todo-yesterday (&optional arg)
  8304. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8305. (interactive "P")
  8306. (let* ((hour (third (decode-time
  8307. (org-current-time))))
  8308. (org-extend-today-until (1+ hour)))
  8309. (org-agenda-todo arg)))
  8310. (provide 'org-agenda)
  8311. ;;; org-agenda.el ends here