org-agenda.el 343 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964
  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. (and (called-interactively-p 'interactive)
  1617. (message "Sticky agenda was already %s"
  1618. (if org-agenda-sticky "enabled" "disabled")))
  1619. (setq org-agenda-sticky new-value)
  1620. (org-agenda-kill-all-agenda-buffers)
  1621. (and (called-interactively-p 'interactive)
  1622. (message "Sticky agenda was %s"
  1623. (if org-agenda-sticky "enabled" "disabled"))))))
  1624. (defvar org-agenda-buffer nil
  1625. "Agenda buffer currently being generated.")
  1626. (defvar org-agenda-last-prefix-arg nil)
  1627. (defvar org-agenda-this-buffer-name nil)
  1628. (defvar org-agenda-doing-sticky-redo nil)
  1629. (defvar org-agenda-this-buffer-is-sticky nil)
  1630. (defconst org-agenda-local-vars
  1631. '(org-agenda-this-buffer-name
  1632. org-agenda-undo-list
  1633. org-agenda-pending-undo-list
  1634. org-agenda-follow-mode
  1635. org-agenda-entry-text-mode
  1636. org-agenda-clockreport-mode
  1637. org-agenda-show-log
  1638. org-agenda-redo-command
  1639. org-agenda-query-string
  1640. org-agenda-type
  1641. org-agenda-bulk-marked-entries
  1642. org-agenda-undo-has-started-in
  1643. org-agenda-last-arguments
  1644. org-agenda-info
  1645. org-agenda-tag-filter-overlays
  1646. org-agenda-cat-filter-overlays
  1647. org-pre-agenda-window-conf
  1648. org-agenda-columns-active
  1649. org-agenda-tag-filter
  1650. org-agenda-category-filter
  1651. org-agenda-markers
  1652. org-agenda-last-search-view-search-was-boolean
  1653. org-agenda-filtered-by-category
  1654. org-agenda-filter-form
  1655. org-agenda-show-window
  1656. org-agenda-cycle-counter
  1657. org-agenda-last-prefix-arg)
  1658. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1659. (defun org-agenda-mode ()
  1660. "Mode for time-sorted view on action items in Org-mode files.
  1661. The following commands are available:
  1662. \\{org-agenda-mode-map}"
  1663. (interactive)
  1664. (cond (org-agenda-doing-sticky-redo
  1665. ;; Refreshing sticky agenda-buffer
  1666. ;;
  1667. ;; Preserve the value of `org-agenda-local-vars' variables,
  1668. ;; while letting `kill-all-local-variables' kill the rest
  1669. (let ((save (buffer-local-variables)))
  1670. (kill-all-local-variables)
  1671. (mapc 'make-local-variable org-agenda-local-vars)
  1672. (dolist (elem save)
  1673. (let ((var (car elem))
  1674. (val (cdr elem)))
  1675. (when (and val
  1676. (member var org-agenda-local-vars))
  1677. (set var val)))))
  1678. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1679. (org-agenda-sticky
  1680. ;; Creating a sticky Agenda buffer for the first time
  1681. (kill-all-local-variables)
  1682. (mapc 'make-local-variable org-agenda-local-vars)
  1683. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1684. (t
  1685. ;; Creating a non-sticky agenda buffer
  1686. (kill-all-local-variables)
  1687. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1688. (setq org-agenda-undo-list nil
  1689. org-agenda-pending-undo-list nil
  1690. org-agenda-bulk-marked-entries nil)
  1691. (setq major-mode 'org-agenda-mode)
  1692. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1693. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1694. (setq mode-name "Org-Agenda")
  1695. (use-local-map org-agenda-mode-map)
  1696. (easy-menu-add org-agenda-menu)
  1697. (if org-startup-truncated (setq truncate-lines t))
  1698. (org-set-local 'line-move-visual nil)
  1699. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1700. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1701. ;; Make sure properties are removed when copying text
  1702. (when (boundp 'buffer-substring-filters)
  1703. (org-set-local 'buffer-substring-filters
  1704. (cons (lambda (x)
  1705. (set-text-properties 0 (length x) nil x) x)
  1706. buffer-substring-filters)))
  1707. (unless org-agenda-keep-modes
  1708. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1709. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1710. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1711. org-agenda-show-log org-agenda-start-with-log-mode))
  1712. (easy-menu-change
  1713. '("Agenda") "Agenda Files"
  1714. (append
  1715. (list
  1716. (vector
  1717. (if (get 'org-agenda-files 'org-restrict)
  1718. "Restricted to single file"
  1719. "Edit File List")
  1720. '(org-edit-agenda-file-list)
  1721. (not (get 'org-agenda-files 'org-restrict)))
  1722. "--")
  1723. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1724. (org-agenda-set-mode-name)
  1725. (apply
  1726. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1727. (list 'org-agenda-mode-hook)))
  1728. (substitute-key-definition 'undo 'org-agenda-undo
  1729. org-agenda-mode-map global-map)
  1730. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1731. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1732. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1733. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1734. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1735. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1736. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1737. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1738. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1739. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1740. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1741. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1742. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1743. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1744. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1745. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1746. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1747. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1748. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1749. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1750. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1751. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1752. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1753. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1754. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1755. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1756. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1757. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1758. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1759. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1760. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1761. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1762. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1763. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1764. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1765. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1766. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1767. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1768. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1769. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1770. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1771. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1772. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1773. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1774. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1775. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1776. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1777. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1778. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1779. (while l (org-defkey org-agenda-mode-map
  1780. (int-to-string (pop l)) 'digit-argument)))
  1781. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1782. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1783. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1784. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1785. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1786. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1787. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1788. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1789. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1790. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1791. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1792. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1794. 'org-clock-modify-effort-estimate)
  1795. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1796. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1797. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1798. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1799. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1800. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1801. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1802. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1803. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1804. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1805. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1806. (substitute-key-definition 'next-line 'org-agenda-next-line
  1807. org-agenda-mode-map global-map)
  1808. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1809. org-agenda-mode-map global-map)
  1810. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1811. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1812. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1813. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1814. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1815. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1816. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1817. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1818. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1819. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1820. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1821. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1822. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1823. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1824. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1825. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1826. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1827. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1828. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1829. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1830. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1831. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1832. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1833. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1834. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1835. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1836. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1837. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1838. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1839. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1840. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1841. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1842. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1843. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1844. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1845. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1846. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1847. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1848. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1849. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1850. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1851. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1852. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1853. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1854. (when org-agenda-mouse-1-follows-link
  1855. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1856. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1857. '("Agenda"
  1858. ("Agenda Files")
  1859. "--"
  1860. ("Agenda Dates"
  1861. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1862. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1863. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1864. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1865. "--"
  1866. ("View"
  1867. ["Day View" org-agenda-day-view
  1868. :active (org-agenda-check-type nil 'agenda)
  1869. :style radio :selected (eq org-agenda-current-span 'day)
  1870. :keys "v d (or just d)"]
  1871. ["Week View" org-agenda-week-view
  1872. :active (org-agenda-check-type nil 'agenda)
  1873. :style radio :selected (eq org-agenda-current-span 'week)
  1874. :keys "v w (or just w)"]
  1875. ["Month View" org-agenda-month-view
  1876. :active (org-agenda-check-type nil 'agenda)
  1877. :style radio :selected (eq org-agenda-current-span 'month)
  1878. :keys "v m"]
  1879. ["Year View" org-agenda-year-view
  1880. :active (org-agenda-check-type nil 'agenda)
  1881. :style radio :selected (eq org-agenda-current-span 'year)
  1882. :keys "v y"]
  1883. "--"
  1884. ["Include Diary" org-agenda-toggle-diary
  1885. :style toggle :selected org-agenda-include-diary
  1886. :active (org-agenda-check-type nil 'agenda)]
  1887. ["Include Deadlines" org-agenda-toggle-deadlines
  1888. :style toggle :selected org-agenda-include-deadlines
  1889. :active (org-agenda-check-type nil 'agenda)]
  1890. ["Use Time Grid" org-agenda-toggle-time-grid
  1891. :style toggle :selected org-agenda-use-time-grid
  1892. :active (org-agenda-check-type nil 'agenda)]
  1893. "--"
  1894. ["Show clock report" org-agenda-clockreport-mode
  1895. :style toggle :selected org-agenda-clockreport-mode
  1896. :active (org-agenda-check-type nil 'agenda)]
  1897. ["Show some entry text" org-agenda-entry-text-mode
  1898. :style toggle :selected org-agenda-entry-text-mode
  1899. :active t]
  1900. "--"
  1901. ["Show Logbook entries" org-agenda-log-mode
  1902. :style toggle :selected org-agenda-show-log
  1903. :active (org-agenda-check-type nil 'agenda 'timeline)
  1904. :keys "v l (or just l)"]
  1905. ["Include archived trees" org-agenda-archives-mode
  1906. :style toggle :selected org-agenda-archives-mode :active t
  1907. :keys "v a"]
  1908. ["Include archive files" (org-agenda-archives-mode t)
  1909. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1910. :keys "v A"]
  1911. "--"
  1912. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1913. ["Write view to file" org-agenda-write t]
  1914. ["Rebuild buffer" org-agenda-redo t]
  1915. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1916. "--"
  1917. ["Show original entry" org-agenda-show t]
  1918. ["Go To (other window)" org-agenda-goto t]
  1919. ["Go To (this window)" org-agenda-switch-to t]
  1920. ["Follow Mode" org-agenda-follow-mode
  1921. :style toggle :selected org-agenda-follow-mode :active t]
  1922. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1923. "--"
  1924. ("TODO"
  1925. ["Cycle TODO" org-agenda-todo t]
  1926. ["Next TODO set" org-agenda-todo-nextset t]
  1927. ["Previous TODO set" org-agenda-todo-previousset t]
  1928. ["Add note" org-agenda-add-note t])
  1929. ("Archive/Refile/Delete"
  1930. ["Archive default" org-agenda-archive-default t]
  1931. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1932. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1933. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1934. ["Archive subtree" org-agenda-archive t]
  1935. "--"
  1936. ["Refile" org-agenda-refile t]
  1937. "--"
  1938. ["Delete subtree" org-agenda-kill t])
  1939. ("Bulk action"
  1940. ["Mark entry" org-agenda-bulk-mark t]
  1941. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1942. ["Unmark entry" org-agenda-bulk-unmark t]
  1943. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1944. ["Act on all marked" org-agenda-bulk-action t]
  1945. "--"
  1946. ("Tags and Properties"
  1947. ["Show all Tags" org-agenda-show-tags t]
  1948. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1949. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1950. "--"
  1951. ["Column View" org-columns t])
  1952. ("Deadline/Schedule"
  1953. ["Schedule" org-agenda-schedule t]
  1954. ["Set Deadline" org-agenda-deadline t]
  1955. "--"
  1956. ["Mark item" org-agenda-action :active t :keys "k m"]
  1957. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1958. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1959. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1960. "--"
  1961. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1962. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1963. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1964. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1965. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1966. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1967. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1968. ("Clock and Effort"
  1969. ["Clock in" org-agenda-clock-in t]
  1970. ["Clock out" org-agenda-clock-out t]
  1971. ["Clock cancel" org-agenda-clock-cancel t]
  1972. ["Goto running clock" org-clock-goto t]
  1973. "--"
  1974. ["Set Effort" org-agenda-set-effort t]
  1975. ["Change clocked effort" org-clock-modify-effort-estimate
  1976. (org-clock-is-active)])
  1977. ("Priority"
  1978. ["Set Priority" org-agenda-priority t]
  1979. ["Increase Priority" org-agenda-priority-up t]
  1980. ["Decrease Priority" org-agenda-priority-down t]
  1981. ["Show Priority" org-agenda-show-priority t])
  1982. ("Calendar/Diary"
  1983. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1984. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1985. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1986. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1987. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1988. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1989. "--"
  1990. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1991. "--"
  1992. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1993. "--"
  1994. ("MobileOrg"
  1995. ["Push Files and Views" org-mobile-push t]
  1996. ["Get Captured and Flagged" org-mobile-pull t]
  1997. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1998. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1999. "--"
  2000. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2001. "--"
  2002. ["Quit" org-agenda-quit t]
  2003. ["Exit and Release Buffers" org-agenda-exit t]
  2004. ))
  2005. ;;; Agenda undo
  2006. (defvar org-agenda-allow-remote-undo t
  2007. "Non-nil means allow remote undo from the agenda buffer.")
  2008. (defvar org-agenda-undo-list nil
  2009. "List of undoable operations in the agenda since last refresh.")
  2010. (defvar org-agenda-undo-has-started-in nil
  2011. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2012. (defvar org-agenda-pending-undo-list nil
  2013. "In a series of undo commands, this is the list of remaining undo items.")
  2014. (defun org-agenda-undo ()
  2015. "Undo a remote editing step in the agenda.
  2016. This undoes changes both in the agenda buffer and in the remote buffer
  2017. that have been changed along."
  2018. (interactive)
  2019. (or org-agenda-allow-remote-undo
  2020. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2021. (if (not (eq this-command last-command))
  2022. (setq org-agenda-undo-has-started-in nil
  2023. org-agenda-pending-undo-list org-agenda-undo-list))
  2024. (if (not org-agenda-pending-undo-list)
  2025. (error "No further undo information"))
  2026. (let* ((entry (pop org-agenda-pending-undo-list))
  2027. buf line cmd rembuf)
  2028. (setq cmd (pop entry) line (pop entry))
  2029. (setq rembuf (nth 2 entry))
  2030. (org-with-remote-undo rembuf
  2031. (while (bufferp (setq buf (pop entry)))
  2032. (if (pop entry)
  2033. (with-current-buffer buf
  2034. (let ((last-undo-buffer buf)
  2035. (inhibit-read-only t))
  2036. (unless (memq buf org-agenda-undo-has-started-in)
  2037. (push buf org-agenda-undo-has-started-in)
  2038. (make-local-variable 'pending-undo-list)
  2039. (undo-start))
  2040. (while (and pending-undo-list
  2041. (listp pending-undo-list)
  2042. (not (car pending-undo-list)))
  2043. (pop pending-undo-list))
  2044. (undo-more 1))))))
  2045. (org-goto-line line)
  2046. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2047. (defun org-verify-change-for-undo (l1 l2)
  2048. "Verify that a real change occurred between the undo lists L1 and L2."
  2049. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2050. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2051. (not (eq l1 l2)))
  2052. ;;; Agenda dispatch
  2053. (defvar org-agenda-restrict nil)
  2054. (defvar org-agenda-restrict-begin (make-marker))
  2055. (defvar org-agenda-restrict-end (make-marker))
  2056. (defvar org-agenda-last-dispatch-buffer nil)
  2057. (defvar org-agenda-overriding-restriction nil)
  2058. ;;;###autoload
  2059. (defun org-agenda (&optional arg keys restriction)
  2060. "Dispatch agenda commands to collect entries to the agenda buffer.
  2061. Prompts for a command to execute. Any prefix arg will be passed
  2062. on to the selected command. The default selections are:
  2063. a Call `org-agenda-list' to display the agenda for current day or week.
  2064. t Call `org-todo-list' to display the global todo list.
  2065. T Call `org-todo-list' to display the global todo list, select only
  2066. entries with a specific TODO keyword (the user gets a prompt).
  2067. m Call `org-tags-view' to display headlines with tags matching
  2068. a condition (the user is prompted for the condition).
  2069. M Like `m', but select only TODO entries, no ordinary headlines.
  2070. L Create a timeline for the current buffer.
  2071. e Export views to associated files.
  2072. s Search entries for keywords.
  2073. / Multi occur across all agenda files and also files listed
  2074. in `org-agenda-text-search-extra-files'.
  2075. < Restrict agenda commands to buffer, subtree, or region.
  2076. Press several times to get the desired effect.
  2077. > Remove a previous restriction.
  2078. # List \"stuck\" projects.
  2079. ! Configure what \"stuck\" means.
  2080. C Configure custom agenda commands.
  2081. More commands can be added by configuring the variable
  2082. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2083. searches can be pre-defined in this way.
  2084. If the current buffer is in Org-mode and visiting a file, you can also
  2085. first press `<' once to indicate that the agenda should be temporarily
  2086. \(until the next use of \\[org-agenda]) restricted to the current file.
  2087. Pressing `<' twice means to restrict to the current subtree or region
  2088. \(if active)."
  2089. (interactive "P")
  2090. (catch 'exit
  2091. (let* ((prefix-descriptions nil)
  2092. (org-agenda-buffer-name org-agenda-buffer-name)
  2093. (org-agenda-window-setup (if (equal (buffer-name)
  2094. org-agenda-buffer-name)
  2095. 'current-window
  2096. org-agenda-window-setup))
  2097. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2098. (org-agenda-custom-commands
  2099. ;; normalize different versions
  2100. (delq nil
  2101. (mapcar
  2102. (lambda (x)
  2103. (cond ((stringp (cdr x))
  2104. (push x prefix-descriptions)
  2105. nil)
  2106. ((stringp (nth 1 x)) x)
  2107. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2108. (t (cons (car x) (cons "" (cdr x))))))
  2109. org-agenda-custom-commands)))
  2110. (buf (current-buffer))
  2111. (bfn (buffer-file-name (buffer-base-buffer)))
  2112. entry key type match lprops ans)
  2113. ;; Turn off restriction unless there is an overriding one,
  2114. (unless org-agenda-overriding-restriction
  2115. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2116. ;; There is a request to keep the file list in place
  2117. (put 'org-agenda-files 'org-restrict nil))
  2118. (setq org-agenda-restrict nil)
  2119. (move-marker org-agenda-restrict-begin nil)
  2120. (move-marker org-agenda-restrict-end nil))
  2121. ;; Delete old local properties
  2122. (put 'org-agenda-redo-command 'org-lprops nil)
  2123. ;; Delete previously set last-arguments
  2124. (put 'org-agenda-redo-command 'last-args nil)
  2125. ;; Remember where this call originated
  2126. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2127. (unless keys
  2128. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2129. keys (car ans)
  2130. restriction (cdr ans)))
  2131. ;; If we have sticky agenda buffers, set a name for the buffer,
  2132. ;; depending on the invoking keys. The user may still set this
  2133. ;; as a command option, which will overwrite what we do here.
  2134. (if org-agenda-sticky
  2135. (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
  2136. ;; Establish the restriction, if any
  2137. (when (and (not org-agenda-overriding-restriction) restriction)
  2138. (put 'org-agenda-files 'org-restrict (list bfn))
  2139. (cond
  2140. ((eq restriction 'region)
  2141. (setq org-agenda-restrict t)
  2142. (move-marker org-agenda-restrict-begin (region-beginning))
  2143. (move-marker org-agenda-restrict-end (region-end)))
  2144. ((eq restriction 'subtree)
  2145. (save-excursion
  2146. (setq org-agenda-restrict t)
  2147. (org-back-to-heading t)
  2148. (move-marker org-agenda-restrict-begin (point))
  2149. (move-marker org-agenda-restrict-end
  2150. (progn (org-end-of-subtree t)))))))
  2151. ;; For example the todo list should not need it (but does...)
  2152. (cond
  2153. ((setq entry (assoc keys org-agenda-custom-commands))
  2154. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2155. (progn
  2156. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2157. lprops (nth 4 entry))
  2158. (put 'org-agenda-redo-command 'org-lprops lprops)
  2159. (cond
  2160. ((eq type 'agenda)
  2161. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2162. ((eq type 'alltodo)
  2163. (org-let lprops '(org-todo-list current-prefix-arg)))
  2164. ((eq type 'search)
  2165. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2166. ((eq type 'stuck)
  2167. (org-let lprops '(org-agenda-list-stuck-projects
  2168. current-prefix-arg)))
  2169. ((eq type 'tags)
  2170. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2171. ((eq type 'tags-todo)
  2172. (org-let lprops '(org-tags-view '(4) match)))
  2173. ((eq type 'todo)
  2174. (org-let lprops '(org-todo-list match)))
  2175. ((eq type 'tags-tree)
  2176. (org-check-for-org-mode)
  2177. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2178. ((eq type 'todo-tree)
  2179. (org-check-for-org-mode)
  2180. (org-let lprops
  2181. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2182. (regexp-quote match) "\\>"))))
  2183. ((eq type 'occur-tree)
  2184. (org-check-for-org-mode)
  2185. (org-let lprops '(org-occur match)))
  2186. ((functionp type)
  2187. (org-let lprops '(funcall type match)))
  2188. ((fboundp type)
  2189. (org-let lprops '(funcall type match)))
  2190. (t (error "Invalid custom agenda command type %s" type))))
  2191. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2192. ((equal keys "C")
  2193. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2194. (customize-variable 'org-agenda-custom-commands))
  2195. ((equal keys "a") (call-interactively 'org-agenda-list))
  2196. ((equal keys "s") (call-interactively 'org-search-view))
  2197. ((equal keys "t") (call-interactively 'org-todo-list))
  2198. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2199. ((equal keys "m") (call-interactively 'org-tags-view))
  2200. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2201. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2202. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2203. (org-add-hook
  2204. 'post-command-hook
  2205. (lambda ()
  2206. (unless (current-message)
  2207. (let* ((m (org-agenda-get-any-marker))
  2208. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2209. (when note
  2210. (message (concat
  2211. "FLAGGING-NOTE ([?] for more info): "
  2212. (org-add-props
  2213. (replace-regexp-in-string
  2214. "\\\\n" "//"
  2215. (copy-sequence note))
  2216. nil 'face 'org-warning)))))))
  2217. t t))
  2218. ((equal keys "L")
  2219. (unless (derived-mode-p 'org-mode)
  2220. (error "This is not an Org-mode file"))
  2221. (unless restriction
  2222. (put 'org-agenda-files 'org-restrict (list bfn))
  2223. (org-call-with-arg 'org-timeline arg)))
  2224. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2225. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2226. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2227. (t (error "Invalid agenda key"))))))
  2228. (defun org-agenda-append-agenda ()
  2229. "Append another agenda view to the current one.
  2230. This function allows interactive building of block agendas.
  2231. Agenda views are separated by `org-agenda-block-separator'."
  2232. (interactive)
  2233. (unless (string= (buffer-name) org-agenda-buffer-name)
  2234. (error "Can only append from within agenda buffer"))
  2235. (let ((org-agenda-multi t))
  2236. (org-agenda)
  2237. (widen)))
  2238. (defun org-agenda-normalize-custom-commands (cmds)
  2239. (delq nil
  2240. (mapcar
  2241. (lambda (x)
  2242. (cond ((stringp (cdr x)) nil)
  2243. ((stringp (nth 1 x)) x)
  2244. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2245. (t (cons (car x) (cons "" (cdr x))))))
  2246. cmds)))
  2247. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2248. "The user interface for selecting an agenda command."
  2249. (catch 'exit
  2250. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2251. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2252. (region-p (org-region-active-p))
  2253. (custom org-agenda-custom-commands)
  2254. (selstring "")
  2255. restriction second-time
  2256. c entry key type match prefixes rmheader header-end custom1 desc
  2257. line lines left right n n1)
  2258. (save-window-excursion
  2259. (delete-other-windows)
  2260. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2261. (erase-buffer)
  2262. (insert (eval-when-compile
  2263. (let ((header
  2264. "Press key for an agenda command: < Buffer, subtree/region restriction
  2265. -------------------------------- > Remove restriction
  2266. a Agenda for current week or day e Export agenda views
  2267. t List of all TODO entries T Entries with special TODO kwd
  2268. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2269. L Timeline for current buffer # List stuck projects (!=configure)
  2270. s Search for keywords * Toggle sticky agenda views
  2271. / Multi-occur ? Find :FLAGGED: entries
  2272. C Configure custom agenda commands
  2273. ")
  2274. (start 0))
  2275. (while (string-match
  2276. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2277. header start)
  2278. (setq start (match-end 0))
  2279. (add-text-properties (match-beginning 2) (match-end 2)
  2280. '(face bold) header))
  2281. header)))
  2282. (setq header-end (move-marker (make-marker) (point)))
  2283. (while t
  2284. (setq custom1 custom)
  2285. (when (eq rmheader t)
  2286. (org-goto-line 1)
  2287. (re-search-forward ":" nil t)
  2288. (delete-region (match-end 0) (point-at-eol))
  2289. (forward-char 1)
  2290. (looking-at "-+")
  2291. (delete-region (match-end 0) (point-at-eol))
  2292. (move-marker header-end (match-end 0)))
  2293. (goto-char header-end)
  2294. (delete-region (point) (point-max))
  2295. ;; Produce all the lines that describe custom commands and prefixes
  2296. (setq lines nil)
  2297. (while (setq entry (pop custom1))
  2298. (setq key (car entry) desc (nth 1 entry)
  2299. type (nth 2 entry)
  2300. match (nth 3 entry))
  2301. (if (> (length key) 1)
  2302. (add-to-list 'prefixes (string-to-char key))
  2303. (setq line
  2304. (format
  2305. "%-4s%-14s"
  2306. (org-add-props (copy-sequence key)
  2307. '(face bold))
  2308. (cond
  2309. ((string-match "\\S-" desc) desc)
  2310. ((eq type 'agenda) "Agenda for current week or day")
  2311. ((eq type 'alltodo) "List of all TODO entries")
  2312. ((eq type 'search) "Word search")
  2313. ((eq type 'stuck) "List of stuck projects")
  2314. ((eq type 'todo) "TODO keyword")
  2315. ((eq type 'tags) "Tags query")
  2316. ((eq type 'tags-todo) "Tags (TODO)")
  2317. ((eq type 'tags-tree) "Tags tree")
  2318. ((eq type 'todo-tree) "TODO kwd tree")
  2319. ((eq type 'occur-tree) "Occur tree")
  2320. ((functionp type) (if (symbolp type)
  2321. (symbol-name type)
  2322. "Lambda expression"))
  2323. (t "???"))))
  2324. (if org-agenda-menu-show-matcher
  2325. (setq line
  2326. (concat line ": "
  2327. (cond
  2328. ((stringp match)
  2329. (setq match (copy-sequence match))
  2330. (org-add-props match nil 'face 'org-warning))
  2331. (match
  2332. (format "set of %d commands" (length match)))
  2333. (t ""))))
  2334. (if (org-string-nw-p match)
  2335. (add-text-properties
  2336. 0 (length line) (list 'help-echo
  2337. (concat "Matcher: "match)) line)))
  2338. (push line lines)))
  2339. (setq lines (nreverse lines))
  2340. (when prefixes
  2341. (mapc (lambda (x)
  2342. (push
  2343. (format "%s %s"
  2344. (org-add-props (char-to-string x)
  2345. nil 'face 'bold)
  2346. (or (cdr (assoc (concat selstring
  2347. (char-to-string x))
  2348. prefix-descriptions))
  2349. "Prefix key"))
  2350. lines))
  2351. prefixes))
  2352. ;; Check if we should display in two columns
  2353. (if org-agenda-menu-two-column
  2354. (progn
  2355. (setq n (length lines)
  2356. n1 (+ (/ n 2) (mod n 2))
  2357. right (nthcdr n1 lines)
  2358. left (copy-sequence lines))
  2359. (setcdr (nthcdr (1- n1) left) nil))
  2360. (setq left lines right nil))
  2361. (while left
  2362. (insert "\n" (pop left))
  2363. (when right
  2364. (if (< (current-column) 40)
  2365. (move-to-column 40 t)
  2366. (insert " "))
  2367. (insert (pop right))))
  2368. ;; Make the window the right size
  2369. (goto-char (point-min))
  2370. (if second-time
  2371. (if (not (pos-visible-in-window-p (point-max)))
  2372. (org-fit-window-to-buffer))
  2373. (setq second-time t)
  2374. (org-fit-window-to-buffer))
  2375. ;; Ask for selection
  2376. (message "Press key for agenda command%s:"
  2377. (if (or restrict-ok org-agenda-overriding-restriction)
  2378. (if org-agenda-overriding-restriction
  2379. " (restriction lock active)"
  2380. (if restriction
  2381. (format " (restricted to %s)" restriction)
  2382. " (unrestricted)"))
  2383. ""))
  2384. (setq c (read-char-exclusive))
  2385. (message "")
  2386. (cond
  2387. ((assoc (char-to-string c) custom)
  2388. (setq selstring (concat selstring (char-to-string c)))
  2389. (throw 'exit (cons selstring restriction)))
  2390. ((memq c prefixes)
  2391. (setq selstring (concat selstring (char-to-string c))
  2392. prefixes nil
  2393. rmheader (or rmheader t)
  2394. custom (delq nil (mapcar
  2395. (lambda (x)
  2396. (if (or (= (length (car x)) 1)
  2397. (/= (string-to-char (car x)) c))
  2398. nil
  2399. (cons (substring (car x) 1) (cdr x))))
  2400. custom))))
  2401. ((eq c ?*)
  2402. (call-interactively 'org-toggle-sticky-agenda)
  2403. (sit-for 2))
  2404. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2405. (message "Restriction is only possible in Org-mode buffers")
  2406. (ding) (sit-for 1))
  2407. ((eq c ?1)
  2408. (org-agenda-remove-restriction-lock 'noupdate)
  2409. (setq restriction 'buffer))
  2410. ((eq c ?0)
  2411. (org-agenda-remove-restriction-lock 'noupdate)
  2412. (setq restriction (if region-p 'region 'subtree)))
  2413. ((eq c ?<)
  2414. (org-agenda-remove-restriction-lock 'noupdate)
  2415. (setq restriction
  2416. (cond
  2417. ((eq restriction 'buffer)
  2418. (if region-p 'region 'subtree))
  2419. ((memq restriction '(subtree region))
  2420. nil)
  2421. (t 'buffer))))
  2422. ((eq c ?>)
  2423. (org-agenda-remove-restriction-lock 'noupdate)
  2424. (setq restriction nil))
  2425. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2426. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2427. ((and (> (length selstring) 0) (eq c ?\d))
  2428. (delete-window)
  2429. (org-agenda-get-restriction-and-command prefix-descriptions))
  2430. ((equal c ?q) (error "Abort"))
  2431. (t (error "Invalid key %c" c))))))))
  2432. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2433. (defvar org-agenda-last-arguments nil
  2434. "The arguments of the previous call to `org-agenda'.")
  2435. (defun org-agenda-run-series (name series)
  2436. (org-let (nth 1 series) '(org-prepare-agenda name))
  2437. ;; We need to reset agenda markers here, because when constructing a
  2438. ;; block agenda, the individual blocks do not do that.
  2439. (org-agenda-reset-markers)
  2440. (let* ((org-agenda-multi t)
  2441. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2442. (org-agenda-overriding-arguments
  2443. (or org-agenda-overriding-arguments
  2444. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2445. (get 'org-agenda-redo-command 'last-args))))
  2446. (cmds (car series))
  2447. (gprops (nth 1 series))
  2448. match ;; The byte compiler incorrectly complains about this. Keep it!
  2449. cmd type lprops)
  2450. (while (setq cmd (pop cmds))
  2451. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2452. (cond
  2453. ((eq type 'agenda)
  2454. (org-let2 gprops lprops
  2455. '(call-interactively 'org-agenda-list)))
  2456. ((eq type 'alltodo)
  2457. (org-let2 gprops lprops
  2458. '(call-interactively 'org-todo-list)))
  2459. ((eq type 'search)
  2460. (org-let2 gprops lprops
  2461. '(org-search-view current-prefix-arg match nil)))
  2462. ((eq type 'stuck)
  2463. (org-let2 gprops lprops
  2464. '(call-interactively 'org-agenda-list-stuck-projects)))
  2465. ((eq type 'tags)
  2466. (org-let2 gprops lprops
  2467. '(org-tags-view current-prefix-arg match)))
  2468. ((eq type 'tags-todo)
  2469. (org-let2 gprops lprops
  2470. '(org-tags-view '(4) match)))
  2471. ((eq type 'todo)
  2472. (org-let2 gprops lprops
  2473. '(org-todo-list match)))
  2474. ((fboundp type)
  2475. (org-let2 gprops lprops
  2476. '(funcall type match)))
  2477. (t (error "Invalid type in command series"))))
  2478. (widen)
  2479. (setq org-agenda-redo-command redo)
  2480. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2481. (goto-char (point-min)))
  2482. (org-fit-agenda-window)
  2483. (org-let (nth 1 series) '(org-finalize-agenda)))
  2484. ;;;###autoload
  2485. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2486. "Run an agenda command in batch mode and send the result to STDOUT.
  2487. If CMD-KEY is a string of length 1, it is used as a key in
  2488. `org-agenda-custom-commands' and triggers this command. If it is a
  2489. longer string it is used as a tags/todo match string.
  2490. Parameters are alternating variable names and values that will be bound
  2491. before running the agenda command."
  2492. (org-eval-in-environment (org-make-parameter-alist parameters)
  2493. (if (> (length cmd-key) 2)
  2494. (org-tags-view nil cmd-key)
  2495. (org-agenda nil cmd-key)))
  2496. (set-buffer org-agenda-buffer-name)
  2497. (princ (buffer-string)))
  2498. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2499. (defvar org-agenda-info nil)
  2500. ;;;###autoload
  2501. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2502. "Run an agenda command in batch mode and send the result to STDOUT.
  2503. If CMD-KEY is a string of length 1, it is used as a key in
  2504. `org-agenda-custom-commands' and triggers this command. If it is a
  2505. longer string it is used as a tags/todo match string.
  2506. Parameters are alternating variable names and values that will be bound
  2507. before running the agenda command.
  2508. The output gives a line for each selected agenda item. Each
  2509. item is a list of comma-separated values, like this:
  2510. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2511. category The category of the item
  2512. head The headline, without TODO kwd, TAGS and PRIORITY
  2513. type The type of the agenda entry, can be
  2514. todo selected in TODO match
  2515. tagsmatch selected in tags match
  2516. diary imported from diary
  2517. deadline a deadline on given date
  2518. scheduled scheduled on given date
  2519. timestamp entry has timestamp on given date
  2520. closed entry was closed on given date
  2521. upcoming-deadline warning about deadline
  2522. past-scheduled forwarded scheduled item
  2523. block entry has date block including g. date
  2524. todo The todo keyword, if any
  2525. tags All tags including inherited ones, separated by colons
  2526. date The relevant date, like 2007-2-14
  2527. time The time, like 15:00-16:50
  2528. extra Sting with extra planning info
  2529. priority-l The priority letter if any was given
  2530. priority-n The computed numerical priority
  2531. agenda-day The day in the agenda where this is listed"
  2532. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2533. (org-make-parameter-alist parameters))
  2534. (if (> (length cmd-key) 2)
  2535. (org-tags-view nil cmd-key)
  2536. (org-agenda nil cmd-key)))
  2537. (set-buffer org-agenda-buffer-name)
  2538. (let* ((lines (org-split-string (buffer-string) "\n"))
  2539. line)
  2540. (while (setq line (pop lines))
  2541. (catch 'next
  2542. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2543. (setq org-agenda-info
  2544. (org-fix-agenda-info (text-properties-at 0 line)))
  2545. (princ
  2546. (mapconcat 'org-agenda-export-csv-mapper
  2547. '(org-category txt type todo tags date time extra
  2548. priority-letter priority agenda-day)
  2549. ","))
  2550. (princ "\n")))))
  2551. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2552. (defun org-fix-agenda-info (props)
  2553. "Make sure all properties on an agenda item have a canonical form.
  2554. This ensures the export commands can easily use it."
  2555. (let (tmp re)
  2556. (when (setq tmp (plist-get props 'tags))
  2557. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2558. (when (setq tmp (plist-get props 'date))
  2559. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2560. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2561. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2562. (setq tmp (calendar-date-string tmp)))
  2563. (setq props (plist-put props 'date tmp)))
  2564. (when (setq tmp (plist-get props 'day))
  2565. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2566. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2567. (setq tmp (calendar-date-string tmp)))
  2568. (setq props (plist-put props 'day tmp))
  2569. (setq props (plist-put props 'agenda-day tmp)))
  2570. (when (setq tmp (plist-get props 'txt))
  2571. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2572. (plist-put props 'priority-letter (match-string 1 tmp))
  2573. (setq tmp (replace-match "" t t tmp)))
  2574. (when (and (setq re (plist-get props 'org-todo-regexp))
  2575. (setq re (concat "\\`\\.*" re " ?"))
  2576. (string-match re tmp))
  2577. (plist-put props 'todo (match-string 1 tmp))
  2578. (setq tmp (replace-match "" t t tmp)))
  2579. (plist-put props 'txt tmp)))
  2580. props)
  2581. (defun org-agenda-export-csv-mapper (prop)
  2582. (let ((res (plist-get org-agenda-info prop)))
  2583. (setq res
  2584. (cond
  2585. ((not res) "")
  2586. ((stringp res) res)
  2587. (t (prin1-to-string res))))
  2588. (while (string-match "," res)
  2589. (setq res (replace-match ";" t t res)))
  2590. (org-trim res)))
  2591. ;;;###autoload
  2592. (defun org-store-agenda-views (&rest parameters)
  2593. (interactive)
  2594. (eval (list 'org-batch-store-agenda-views)))
  2595. ;;;###autoload
  2596. (defmacro org-batch-store-agenda-views (&rest parameters)
  2597. "Run all custom agenda commands that have a file argument."
  2598. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2599. (pop-up-frames nil)
  2600. (dir default-directory)
  2601. (pars (org-make-parameter-alist parameters))
  2602. cmd thiscmdkey files opts cmd-or-set)
  2603. (save-window-excursion
  2604. (while cmds
  2605. (setq cmd (pop cmds)
  2606. thiscmdkey (car cmd)
  2607. cmd-or-set (nth 2 cmd)
  2608. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2609. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2610. (if (stringp files) (setq files (list files)))
  2611. (when files
  2612. (org-eval-in-environment (append org-agenda-exporter-settings
  2613. opts pars)
  2614. (org-agenda nil thiscmdkey))
  2615. (set-buffer org-agenda-buffer-name)
  2616. (while files
  2617. (org-eval-in-environment (append org-agenda-exporter-settings
  2618. opts pars)
  2619. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2620. (and (get-buffer org-agenda-buffer-name)
  2621. (kill-buffer org-agenda-buffer-name)))))))
  2622. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2623. (defun org-agenda-mark-header-line (pos)
  2624. "Mark the line at POS as an agenda structure header."
  2625. (save-excursion
  2626. (goto-char pos)
  2627. (put-text-property (point-at-bol) (point-at-eol)
  2628. 'org-agenda-structural-header t)
  2629. (when org-agenda-title-append
  2630. (put-text-property (point-at-bol) (point-at-eol)
  2631. 'org-agenda-title-append org-agenda-title-append))))
  2632. (defvar org-mobile-creating-agendas)
  2633. (defvar org-agenda-write-buffer-name "Agenda View")
  2634. (defun org-agenda-write (file &optional open nosettings)
  2635. "Write the current buffer (an agenda view) as a file.
  2636. Depending on the extension of the file name, plain text (.txt),
  2637. HTML (.html or .htm) or Postscript (.ps) is produced.
  2638. If the extension is .ics, run icalendar export over all files used
  2639. to construct the agenda and limit the export to entries listed in the
  2640. agenda now.
  2641. With prefix argument OPEN, open the new file immediately.
  2642. If NOSETTINGS is given, do not scope the settings of
  2643. `org-agenda-exporter-settings' into the export commands. This is used when
  2644. the settings have already been scoped and we do not wish to overrule other,
  2645. higher priority settings."
  2646. (interactive "FWrite agenda to file: \nP")
  2647. (if (not (file-writable-p file))
  2648. (error "Cannot write agenda to file %s" file))
  2649. (org-let (if nosettings nil org-agenda-exporter-settings)
  2650. '(save-excursion
  2651. (save-window-excursion
  2652. (org-agenda-mark-filtered-text)
  2653. (let ((bs (copy-sequence (buffer-string))) beg)
  2654. (org-agenda-unmark-filtered-text)
  2655. (with-temp-buffer
  2656. (rename-buffer org-agenda-write-buffer-name t)
  2657. (set-buffer-modified-p nil)
  2658. (insert bs)
  2659. (org-agenda-remove-marked-text 'org-filtered)
  2660. (while (setq beg (text-property-any (point-min) (point-max)
  2661. 'org-filtered t))
  2662. (delete-region
  2663. beg (or (next-single-property-change beg 'org-filtered)
  2664. (point-max))))
  2665. (run-hooks 'org-agenda-before-write-hook)
  2666. (cond
  2667. ((org-bound-and-true-p org-mobile-creating-agendas)
  2668. (org-mobile-write-agenda-for-mobile file))
  2669. ((string-match "\\.html?\\'" file)
  2670. (require 'htmlize)
  2671. (set-buffer (htmlize-buffer (current-buffer)))
  2672. (when (and org-agenda-export-html-style
  2673. (string-match "<style>" org-agenda-export-html-style))
  2674. ;; replace <style> section with org-agenda-export-html-style
  2675. (goto-char (point-min))
  2676. (kill-region (- (search-forward "<style") 6)
  2677. (search-forward "</style>"))
  2678. (insert org-agenda-export-html-style))
  2679. (write-file file)
  2680. (kill-buffer (current-buffer))
  2681. (message "HTML written to %s" file))
  2682. ((string-match "\\.ps\\'" file)
  2683. (require 'ps-print)
  2684. (ps-print-buffer-with-faces file)
  2685. (message "Postscript written to %s" file))
  2686. ((string-match "\\.pdf\\'" file)
  2687. (require 'ps-print)
  2688. (ps-print-buffer-with-faces
  2689. (concat (file-name-sans-extension file) ".ps"))
  2690. (call-process "ps2pdf" nil nil nil
  2691. (expand-file-name
  2692. (concat (file-name-sans-extension file) ".ps"))
  2693. (expand-file-name file))
  2694. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2695. (message "PDF written to %s" file))
  2696. ((string-match "\\.ics\\'" file)
  2697. (require 'org-icalendar)
  2698. (let ((org-agenda-marker-table
  2699. (org-create-marker-find-array
  2700. (org-agenda-collect-markers)))
  2701. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2702. (org-combined-agenda-icalendar-file file))
  2703. (apply 'org-export-icalendar 'combine
  2704. (org-agenda-files nil 'ifmode))))
  2705. (t
  2706. (let ((bs (buffer-string)))
  2707. (find-file file)
  2708. (erase-buffer)
  2709. (insert bs)
  2710. (save-buffer 0)
  2711. (kill-buffer (current-buffer))
  2712. (message "Plain text written to %s" file))))))))
  2713. (set-buffer org-agenda-buffer-name))
  2714. (when open (org-open-file file)))
  2715. (defvar org-agenda-tag-filter-overlays nil)
  2716. (defvar org-agenda-cat-filter-overlays nil)
  2717. (defun org-agenda-mark-filtered-text ()
  2718. "Mark all text hidden by filtering with a text property."
  2719. (let ((inhibit-read-only t))
  2720. (mapc
  2721. (lambda (o)
  2722. (when (equal (overlay-buffer o) (current-buffer))
  2723. (put-text-property
  2724. (overlay-start o) (overlay-end o)
  2725. 'org-filtered t)))
  2726. (append org-agenda-tag-filter-overlays
  2727. org-agenda-cat-filter-overlays))))
  2728. (defun org-agenda-unmark-filtered-text ()
  2729. "Remove the filtering text property."
  2730. (let ((inhibit-read-only t))
  2731. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2732. (defun org-agenda-remove-marked-text (property &optional value)
  2733. "Delete all text marked with VALUE of PROPERTY.
  2734. VALUE defaults to t."
  2735. (let (beg)
  2736. (setq value (or value t))
  2737. (while (setq beg (text-property-any (point-min) (point-max)
  2738. property value))
  2739. (delete-region
  2740. beg (or (next-single-property-change beg 'org-filtered)
  2741. (point-max))))))
  2742. (defun org-agenda-add-entry-text ()
  2743. "Add entry text to agenda lines.
  2744. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2745. entry text following headings shown in the agenda.
  2746. Drawers will be excluded, also the line with scheduling/deadline info."
  2747. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2748. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2749. (let (m txt)
  2750. (goto-char (point-min))
  2751. (while (not (eobp))
  2752. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2753. (beginning-of-line 2)
  2754. (setq txt (org-agenda-get-some-entry-text
  2755. m org-agenda-add-entry-text-maxlines " > "))
  2756. (end-of-line 1)
  2757. (if (string-match "\\S-" txt)
  2758. (insert "\n" txt)
  2759. (or (eobp) (forward-char 1))))))))
  2760. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2761. &rest keep)
  2762. "Extract entry text from MARKER, at most N-LINES lines.
  2763. This will ignore drawers etc, just get the text.
  2764. If INDENT is given, prefix every line with this string. If KEEP is
  2765. given, it is a list of symbols, defining stuff that should not be
  2766. removed from the entry content. Currently only `planning' is allowed here."
  2767. (let (txt drawer-re kwd-time-re ind)
  2768. (save-excursion
  2769. (with-current-buffer (marker-buffer marker)
  2770. (if (not (derived-mode-p 'org-mode))
  2771. (setq txt "")
  2772. (save-excursion
  2773. (save-restriction
  2774. (widen)
  2775. (goto-char marker)
  2776. (end-of-line 1)
  2777. (setq txt (buffer-substring
  2778. (min (1+ (point)) (point-max))
  2779. (progn (outline-next-heading) (point)))
  2780. drawer-re org-drawer-regexp
  2781. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2782. ".*\n?"))
  2783. (with-temp-buffer
  2784. (insert txt)
  2785. (when org-agenda-add-entry-text-descriptive-links
  2786. (goto-char (point-min))
  2787. (while (org-activate-bracket-links (point-max))
  2788. (add-text-properties (match-beginning 0) (match-end 0)
  2789. '(face org-link))))
  2790. (goto-char (point-min))
  2791. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2792. (set-text-properties (match-beginning 0) (match-end 0)
  2793. nil))
  2794. (goto-char (point-min))
  2795. (while (re-search-forward drawer-re nil t)
  2796. (delete-region
  2797. (match-beginning 0)
  2798. (progn (re-search-forward
  2799. "^[ \t]*:END:.*\n?" nil 'move)
  2800. (point))))
  2801. (unless (member 'planning keep)
  2802. (goto-char (point-min))
  2803. (while (re-search-forward kwd-time-re nil t)
  2804. (replace-match "")))
  2805. (goto-char (point-min))
  2806. (when org-agenda-entry-text-exclude-regexps
  2807. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2808. (while (setq re (pop re-list))
  2809. (goto-char (point-min))
  2810. (while (re-search-forward re nil t)
  2811. (replace-match "")))))
  2812. (goto-char (point-max))
  2813. (skip-chars-backward " \t\n")
  2814. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2815. ;; find and remove min common indentation
  2816. (goto-char (point-min))
  2817. (untabify (point-min) (point-max))
  2818. (setq ind (org-get-indentation))
  2819. (while (not (eobp))
  2820. (unless (looking-at "[ \t]*$")
  2821. (setq ind (min ind (org-get-indentation))))
  2822. (beginning-of-line 2))
  2823. (goto-char (point-min))
  2824. (while (not (eobp))
  2825. (unless (looking-at "[ \t]*$")
  2826. (move-to-column ind)
  2827. (delete-region (point-at-bol) (point)))
  2828. (beginning-of-line 2))
  2829. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2830. (goto-char (point-min))
  2831. (when indent
  2832. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2833. (replace-match indent t t)))
  2834. (goto-char (point-min))
  2835. (while (looking-at "[ \t]*\n") (replace-match ""))
  2836. (goto-char (point-max))
  2837. (when (> (org-current-line)
  2838. n-lines)
  2839. (org-goto-line (1+ n-lines))
  2840. (backward-char 1))
  2841. (setq txt (buffer-substring (point-min) (point)))))))))
  2842. txt))
  2843. (defun org-agenda-collect-markers ()
  2844. "Collect the markers pointing to entries in the agenda buffer."
  2845. (let (m markers)
  2846. (save-excursion
  2847. (goto-char (point-min))
  2848. (while (not (eobp))
  2849. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2850. (org-get-at-bol 'org-marker)))
  2851. (push m markers))
  2852. (beginning-of-line 2)))
  2853. (nreverse markers)))
  2854. (defun org-create-marker-find-array (marker-list)
  2855. "Create a alist of files names with all marker positions in that file."
  2856. (let (f tbl m a p)
  2857. (while (setq m (pop marker-list))
  2858. (setq p (marker-position m)
  2859. f (buffer-file-name (or (buffer-base-buffer
  2860. (marker-buffer m))
  2861. (marker-buffer m))))
  2862. (if (setq a (assoc f tbl))
  2863. (push (marker-position m) (cdr a))
  2864. (push (list f p) tbl)))
  2865. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2866. tbl)))
  2867. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2868. (defun org-check-agenda-marker-table ()
  2869. "Check of the current entry is on the marker list."
  2870. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2871. a)
  2872. (and (setq a (assoc file org-agenda-marker-table))
  2873. (save-match-data
  2874. (save-excursion
  2875. (org-back-to-heading t)
  2876. (member (point) (cdr a)))))))
  2877. (defun org-check-for-org-mode ()
  2878. "Make sure current buffer is in org-mode. Error if not."
  2879. (or (derived-mode-p 'org-mode)
  2880. (error "Cannot execute org-mode agenda command on buffer in %s"
  2881. major-mode)))
  2882. (defun org-fit-agenda-window ()
  2883. "Fit the window to the buffer size."
  2884. (and (memq org-agenda-window-setup '(reorganize-frame))
  2885. (fboundp 'fit-window-to-buffer)
  2886. (org-fit-window-to-buffer
  2887. nil
  2888. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2889. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2890. ;;; Agenda prepare and finalize
  2891. (defvar org-agenda-multi nil) ; dynamically scoped
  2892. (defvar org-agenda-buffer-name "*Org Agenda*")
  2893. (defvar org-pre-agenda-window-conf nil)
  2894. (defvar org-agenda-columns-active nil)
  2895. (defvar org-agenda-name nil)
  2896. (defvar org-agenda-tag-filter nil)
  2897. (defvar org-agenda-category-filter nil)
  2898. (defvar org-agenda-top-category-filter nil)
  2899. (defvar org-agenda-tag-filter-while-redo nil)
  2900. (defvar org-agenda-tag-filter-preset nil
  2901. "A preset of the tags filter used for secondary agenda filtering.
  2902. This must be a list of strings, each string must be a single tag preceded
  2903. by \"+\" or \"-\".
  2904. This variable should not be set directly, but agenda custom commands can
  2905. bind it in the options section. The preset filter is a global property of
  2906. the entire agenda view. In a block agenda, it will not work reliably to
  2907. define a filter for one of the individual blocks. You need to set it in
  2908. the global options and expect it to be applied to the entire view.")
  2909. (defvar org-agenda-category-filter-preset nil
  2910. "A preset of the category filter used for secondary agenda filtering.
  2911. This must be a list of strings, each string must be a single category
  2912. preceded by \"+\" or \"-\".
  2913. This variable should not be set directly, but agenda custom commands can
  2914. bind it in the options section. The preset filter is a global property of
  2915. the entire agenda view. In a block agenda, it will not work reliably to
  2916. define a filter for one of the individual blocks. You need to set it in
  2917. the global options and expect it to be applied to the entire view.")
  2918. (defun org-agenda-use-sticky-p ()
  2919. "Return non-NIL if existing agenda buffer named
  2920. `org-agenda-buffer-name' exists, and should be shown instead of
  2921. generating a new one"
  2922. (and
  2923. ;; turned off by user
  2924. org-agenda-sticky
  2925. ;; For multi-agenda buffer already exists
  2926. (not org-agenda-multi)
  2927. ;; buffer found
  2928. (get-buffer org-agenda-buffer-name)
  2929. ;; C-u parameter is same as last call
  2930. (with-current-buffer (get-buffer org-agenda-buffer-name)
  2931. (and
  2932. (equal current-prefix-arg
  2933. org-agenda-last-prefix-arg)
  2934. ;; In case user turned stickiness on, while having existing
  2935. ;; Agenda buffer active, don't reuse that buffer, because it
  2936. ;; does not have org variables local
  2937. org-agenda-this-buffer-is-sticky))))
  2938. (defun org-prepare-agenda-window (abuf)
  2939. "Setup agenda buffer in the window"
  2940. (let* ((awin (get-buffer-window abuf))
  2941. wconf)
  2942. (cond
  2943. ((equal (current-buffer) abuf) nil)
  2944. (awin (select-window awin))
  2945. ((not (setq wconf (current-window-configuration))))
  2946. ((equal org-agenda-window-setup 'current-window)
  2947. (org-pop-to-buffer-same-window abuf))
  2948. ((equal org-agenda-window-setup 'other-window)
  2949. (org-switch-to-buffer-other-window abuf))
  2950. ((equal org-agenda-window-setup 'other-frame)
  2951. (switch-to-buffer-other-frame abuf))
  2952. ((equal org-agenda-window-setup 'reorganize-frame)
  2953. (delete-other-windows)
  2954. (org-switch-to-buffer-other-window abuf)))
  2955. ;; additional test in case agenda is invoked from within agenda
  2956. ;; buffer via elisp link
  2957. (unless (equal (current-buffer) abuf)
  2958. (org-pop-to-buffer-same-window abuf))
  2959. (setq org-pre-agenda-window-conf wconf)))
  2960. (defun org-prepare-agenda (&optional name)
  2961. (if (org-agenda-use-sticky-p)
  2962. (progn
  2963. ;; Popup existing buffer
  2964. (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
  2965. (message "Sticky Agenda buffer, use `r' to refresh")
  2966. (throw 'exit nil))
  2967. (setq org-todo-keywords-for-agenda nil)
  2968. (setq org-drawers-for-agenda nil)
  2969. (unless org-agenda-persistent-filter
  2970. (setq org-agenda-tag-filter nil
  2971. org-agenda-category-filter nil))
  2972. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2973. (put 'org-agenda-category-filter :preset-filter
  2974. org-agenda-category-filter-preset)
  2975. (if org-agenda-multi
  2976. (progn
  2977. (setq buffer-read-only nil)
  2978. (goto-char (point-max))
  2979. (unless (or (bobp) org-agenda-compact-blocks
  2980. (not org-agenda-block-separator))
  2981. (insert "\n"
  2982. (if (stringp org-agenda-block-separator)
  2983. org-agenda-block-separator
  2984. (make-string (window-width) org-agenda-block-separator))
  2985. "\n"))
  2986. (narrow-to-region (point) (point-max)))
  2987. (setq org-done-keywords-for-agenda nil)
  2988. ;; Setting any org variables that are in org-agenda-local-vars
  2989. ;; list need to be done after the prepare call
  2990. (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
  2991. (setq buffer-read-only nil)
  2992. (org-agenda-reset-markers)
  2993. (let ((inhibit-read-only t)) (erase-buffer))
  2994. (org-agenda-mode)
  2995. (setq org-agenda-buffer (current-buffer))
  2996. (setq org-agenda-contributing-files nil)
  2997. (setq org-agenda-columns-active nil)
  2998. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2999. (setq org-todo-keywords-for-agenda
  3000. (org-uniquify org-todo-keywords-for-agenda))
  3001. (setq org-done-keywords-for-agenda
  3002. (org-uniquify org-done-keywords-for-agenda))
  3003. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3004. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3005. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3006. (and name (not org-agenda-name)
  3007. (org-set-local 'org-agenda-name name)))
  3008. (setq buffer-read-only nil)))
  3009. (defun org-finalize-agenda ()
  3010. "Finishing touch for the agenda buffer, called just before displaying it."
  3011. (unless org-agenda-multi
  3012. (save-excursion
  3013. (let ((inhibit-read-only t))
  3014. (goto-char (point-min))
  3015. (while (org-activate-bracket-links (point-max))
  3016. (add-text-properties (match-beginning 0) (match-end 0)
  3017. '(face org-link)))
  3018. (org-agenda-align-tags)
  3019. (unless org-agenda-with-colors
  3020. (remove-text-properties (point-min) (point-max) '(face nil))))
  3021. (if (and (boundp 'org-agenda-overriding-columns-format)
  3022. org-agenda-overriding-columns-format)
  3023. (org-set-local 'org-agenda-overriding-columns-format
  3024. org-agenda-overriding-columns-format))
  3025. (if (and (boundp 'org-agenda-view-columns-initially)
  3026. org-agenda-view-columns-initially)
  3027. (org-agenda-columns))
  3028. (when org-agenda-fontify-priorities
  3029. (org-agenda-fontify-priorities))
  3030. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3031. (org-agenda-dim-blocked-tasks))
  3032. (org-agenda-mark-clocking-task)
  3033. (when org-agenda-entry-text-mode
  3034. (org-agenda-entry-text-hide)
  3035. (org-agenda-entry-text-show))
  3036. (if (functionp 'org-habit-insert-consistency-graphs)
  3037. (org-habit-insert-consistency-graphs))
  3038. (run-hooks 'org-finalize-agenda-hook)
  3039. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3040. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3041. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3042. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3043. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3044. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3045. )))
  3046. (defun org-agenda-mark-clocking-task ()
  3047. "Mark the current clock entry in the agenda if it is present."
  3048. (mapc (lambda (o)
  3049. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3050. (delete-overlay o)))
  3051. (overlays-in (point-min) (point-max)))
  3052. (when (marker-buffer org-clock-hd-marker)
  3053. (save-excursion
  3054. (goto-char (point-min))
  3055. (let (s ov)
  3056. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3057. (goto-char s)
  3058. (when (equal (org-get-at-bol 'org-hd-marker)
  3059. org-clock-hd-marker)
  3060. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3061. (overlay-put ov 'type 'org-agenda-clocking)
  3062. (overlay-put ov 'face 'org-agenda-clocking)
  3063. (overlay-put ov 'help-echo
  3064. "The clock is running in this item")))))))
  3065. (defun org-agenda-fontify-priorities ()
  3066. "Make highest priority lines bold, and lowest italic."
  3067. (interactive)
  3068. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3069. (delete-overlay o)))
  3070. (overlays-in (point-min) (point-max)))
  3071. (save-excursion
  3072. (let ((inhibit-read-only t)
  3073. b e p ov h l)
  3074. (goto-char (point-min))
  3075. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3076. (setq h (or (get-char-property (point) 'org-highest-priority)
  3077. org-highest-priority)
  3078. l (or (get-char-property (point) 'org-lowest-priority)
  3079. org-lowest-priority)
  3080. p (string-to-char (match-string 1))
  3081. b (match-beginning 0)
  3082. e (if (eq org-agenda-fontify-priorities 'cookies)
  3083. (match-end 0)
  3084. (point-at-eol))
  3085. ov (make-overlay b e))
  3086. (overlay-put
  3087. ov 'face
  3088. (cond ((org-face-from-face-or-color
  3089. 'priority nil
  3090. (cdr (assoc p org-priority-faces))))
  3091. ((and (listp org-agenda-fontify-priorities)
  3092. (org-face-from-face-or-color
  3093. 'priority nil
  3094. (cdr (assoc p org-agenda-fontify-priorities)))))
  3095. ((equal p l) 'italic)
  3096. ((equal p h) 'bold)))
  3097. (overlay-put ov 'org-type 'org-priority)))))
  3098. (defun org-agenda-dim-blocked-tasks ()
  3099. "Dim currently blocked TODO's in the agenda display."
  3100. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3101. (delete-overlay o)))
  3102. (overlays-in (point-min) (point-max)))
  3103. (save-excursion
  3104. (let ((inhibit-read-only t)
  3105. (org-depend-tag-blocked nil)
  3106. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3107. org-blocked-by-checkboxes
  3108. invis1 b e p ov h l)
  3109. (goto-char (point-min))
  3110. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3111. (and pos (goto-char (1+ pos))))
  3112. (setq org-blocked-by-checkboxes nil invis1 invis)
  3113. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3114. (when (and marker
  3115. (with-current-buffer (marker-buffer marker)
  3116. (save-excursion (goto-char marker)
  3117. (org-entry-blocked-p))))
  3118. (if org-blocked-by-checkboxes (setq invis1 nil))
  3119. (setq b (if invis1
  3120. (max (point-min) (1- (point-at-bol)))
  3121. (point-at-bol))
  3122. e (point-at-eol)
  3123. ov (make-overlay b e))
  3124. (if invis1
  3125. (overlay-put ov 'invisible t)
  3126. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3127. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3128. (defvar org-agenda-skip-function nil
  3129. "Function to be called at each match during agenda construction.
  3130. If this function returns nil, the current match should not be skipped.
  3131. Otherwise, the function must return a position from where the search
  3132. should be continued.
  3133. This may also be a Lisp form, it will be evaluated.
  3134. Never set this variable using `setq' or so, because then it will apply
  3135. to all future agenda commands. If you do want a global skipping condition,
  3136. use the option `org-agenda-skip-function-global' instead.
  3137. The correct usage for `org-agenda-skip-function' is to bind it with
  3138. `let' to scope it dynamically into the agenda-constructing command.
  3139. A good way to set it is through options in `org-agenda-custom-commands'.")
  3140. (defun org-agenda-skip ()
  3141. "Throw to `:skip' in places that should be skipped.
  3142. Also moves point to the end of the skipped region, so that search can
  3143. continue from there."
  3144. (let ((p (point-at-bol)) to)
  3145. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3146. (get-text-property p :org-archived)
  3147. (org-end-of-subtree t)
  3148. (throw :skip t))
  3149. (and org-agenda-skip-comment-trees
  3150. (get-text-property p :org-comment)
  3151. (org-end-of-subtree t)
  3152. (throw :skip t))
  3153. (if (equal (char-after p) ?#) (throw :skip t))
  3154. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3155. (org-agenda-skip-eval org-agenda-skip-function)))
  3156. (goto-char to)
  3157. (throw :skip t))))
  3158. (defun org-agenda-skip-eval (form)
  3159. "If FORM is a function or a list, call (or eval) is and return result.
  3160. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3161. and match data are returned to the previous state no matter what these
  3162. functions do."
  3163. (let (fp)
  3164. (and form
  3165. (or (setq fp (functionp form))
  3166. (consp form))
  3167. (save-excursion
  3168. (save-match-data
  3169. (if fp
  3170. (funcall form)
  3171. (eval form)))))))
  3172. (defvar org-agenda-markers nil
  3173. "List of all currently active markers created by `org-agenda'.")
  3174. (defvar org-agenda-last-marker-time (org-float-time)
  3175. "Creation time of the last agenda marker.")
  3176. (defun org-agenda-new-marker (&optional pos)
  3177. "Return a new agenda marker.
  3178. Org-mode keeps a list of these markers and resets them when they are
  3179. no longer in use."
  3180. (let ((m (copy-marker (or pos (point)))))
  3181. (setq org-agenda-last-marker-time (org-float-time))
  3182. (if org-agenda-buffer
  3183. (with-current-buffer org-agenda-buffer
  3184. (push m org-agenda-markers))
  3185. (push m org-agenda-markers))
  3186. m))
  3187. (defun org-agenda-reset-markers ()
  3188. "Reset markers created by `org-agenda'."
  3189. (while org-agenda-markers
  3190. (move-marker (pop org-agenda-markers) nil)))
  3191. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3192. "Save relative positions of markers in region.
  3193. This check for agenda markers in all agenda buffers currently active."
  3194. (dolist (buf (buffer-list))
  3195. (with-current-buffer buf
  3196. (when (eq major-mode 'org-agenda-mode)
  3197. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3198. org-agenda-markers)))))
  3199. ;;; Entry text mode
  3200. (defun org-agenda-entry-text-show-here ()
  3201. "Add some text from the entry as context to the current line."
  3202. (let (m txt o)
  3203. (setq m (org-get-at-bol 'org-hd-marker))
  3204. (unless (marker-buffer m)
  3205. (error "No marker points to an entry here"))
  3206. (setq txt (concat "\n" (org-no-properties
  3207. (org-agenda-get-some-entry-text
  3208. m org-agenda-entry-text-maxlines " > "))))
  3209. (when (string-match "\\S-" txt)
  3210. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3211. (overlay-put o 'evaporate t)
  3212. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3213. (overlay-put o 'after-string txt))))
  3214. (defun org-agenda-entry-text-show ()
  3215. "Add entry context for all agenda lines."
  3216. (interactive)
  3217. (save-excursion
  3218. (goto-char (point-max))
  3219. (beginning-of-line 1)
  3220. (while (not (bobp))
  3221. (when (org-get-at-bol 'org-hd-marker)
  3222. (org-agenda-entry-text-show-here))
  3223. (beginning-of-line 0))))
  3224. (defun org-agenda-entry-text-hide ()
  3225. "Remove any shown entry context."
  3226. (delq nil
  3227. (mapcar (lambda (o)
  3228. (if (eq (overlay-get o 'org-overlay-type)
  3229. 'agenda-entry-content)
  3230. (progn (delete-overlay o) t)))
  3231. (overlays-in (point-min) (point-max)))))
  3232. (defun org-agenda-get-day-face (date)
  3233. "Return the face DATE should be displayed with."
  3234. (or (and (functionp org-agenda-day-face-function)
  3235. (funcall org-agenda-day-face-function date))
  3236. (cond ((org-agenda-todayp date)
  3237. 'org-agenda-date-today)
  3238. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3239. 'org-agenda-date-weekend)
  3240. (t 'org-agenda-date))))
  3241. ;;; Agenda timeline
  3242. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3243. (defun org-timeline (&optional dotodo)
  3244. "Show a time-sorted view of the entries in the current org file.
  3245. Only entries with a time stamp of today or later will be listed. With
  3246. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3247. under the current date.
  3248. If the buffer contains an active region, only check the region for
  3249. dates."
  3250. (interactive "P")
  3251. (let* ((dopast t)
  3252. (org-agenda-show-log-scoped org-agenda-show-log)
  3253. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3254. (current-buffer))))
  3255. (date (calendar-current-date))
  3256. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3257. (end (if (org-region-active-p) (region-end) (point-max)))
  3258. (day-numbers (org-get-all-dates
  3259. beg end 'no-ranges
  3260. t org-agenda-show-log-scoped ; always include today
  3261. org-timeline-show-empty-dates))
  3262. (org-deadline-warning-days 0)
  3263. (org-agenda-only-exact-dates t)
  3264. (today (org-today))
  3265. (past t)
  3266. args
  3267. s e rtn d emptyp)
  3268. (setq org-agenda-redo-command
  3269. (list 'progn
  3270. (list 'org-switch-to-buffer-other-window (current-buffer))
  3271. (list 'org-timeline (list 'quote dotodo))))
  3272. (if (not dopast)
  3273. ;; Remove past dates from the list of dates.
  3274. (setq day-numbers (delq nil (mapcar (lambda(x)
  3275. (if (>= x today) x nil))
  3276. day-numbers))))
  3277. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3278. (org-compile-prefix-format 'timeline)
  3279. (org-set-sorting-strategy 'timeline)
  3280. (if org-agenda-show-log-scoped (push :closed args))
  3281. (push :timestamp args)
  3282. (push :deadline args)
  3283. (push :scheduled args)
  3284. (push :sexp args)
  3285. (if dotodo (push :todo args))
  3286. (insert "Timeline of file " entry "\n")
  3287. (add-text-properties (point-min) (point)
  3288. (list 'face 'org-agenda-structure))
  3289. (org-agenda-mark-header-line (point-min))
  3290. (while (setq d (pop day-numbers))
  3291. (if (and (listp d) (eq (car d) :omitted))
  3292. (progn
  3293. (setq s (point))
  3294. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3295. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3296. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3297. (if (and (>= d today)
  3298. dopast
  3299. past)
  3300. (progn
  3301. (setq past nil)
  3302. (insert (make-string 79 ?-) "\n")))
  3303. (setq date (calendar-gregorian-from-absolute d))
  3304. (setq s (point))
  3305. (setq rtn (and (not emptyp)
  3306. (apply 'org-agenda-get-day-entries entry
  3307. date args)))
  3308. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3309. (progn
  3310. (insert
  3311. (if (stringp org-agenda-format-date)
  3312. (format-time-string org-agenda-format-date
  3313. (org-time-from-absolute date))
  3314. (funcall org-agenda-format-date date))
  3315. "\n")
  3316. (put-text-property s (1- (point)) 'face
  3317. (org-agenda-get-day-face date))
  3318. (put-text-property s (1- (point)) 'org-date-line t)
  3319. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3320. (if (equal d today)
  3321. (put-text-property s (1- (point)) 'org-today t))
  3322. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3323. (put-text-property s (1- (point)) 'day d)))))
  3324. (goto-char (point-min))
  3325. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3326. (point-min)))
  3327. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3328. (org-finalize-agenda)
  3329. (setq buffer-read-only t)))
  3330. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3331. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3332. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3333. not every single day in the range. If FORCE-TODAY is non-nil, make
  3334. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3335. inactive time stamps (those in square brackets) are included.
  3336. When EMPTY is non-nil, also include days without any entries."
  3337. (let ((re (concat
  3338. (if pre-re pre-re "")
  3339. (if inactive org-ts-regexp-both org-ts-regexp)))
  3340. dates dates1 date day day1 day2 ts1 ts2 pos)
  3341. (if force-today
  3342. (setq dates (list (org-today))))
  3343. (save-excursion
  3344. (goto-char beg)
  3345. (while (re-search-forward re end t)
  3346. (setq day (time-to-days (org-time-string-to-time
  3347. (substring (match-string 1) 0 10)
  3348. (current-buffer) (match-beginning 0))))
  3349. (or (memq day dates) (push day dates)))
  3350. (unless no-ranges
  3351. (goto-char beg)
  3352. (while (re-search-forward org-tr-regexp end t)
  3353. (setq pos (match-beginning 0))
  3354. (setq ts1 (substring (match-string 1) 0 10)
  3355. ts2 (substring (match-string 2) 0 10)
  3356. day1 (time-to-days (org-time-string-to-time
  3357. ts1 (current-buffer) pos))
  3358. day2 (time-to-days (org-time-string-to-time
  3359. ts2 (current-buffer) pos)))
  3360. (while (< (setq day1 (1+ day1)) day2)
  3361. (or (memq day1 dates) (push day1 dates)))))
  3362. (setq dates (sort dates '<))
  3363. (when empty
  3364. (while (setq day (pop dates))
  3365. (setq day2 (car dates))
  3366. (push day dates1)
  3367. (when (and day2 empty)
  3368. (if (or (eq empty t)
  3369. (and (numberp empty) (<= (- day2 day) empty)))
  3370. (while (< (setq day (1+ day)) day2)
  3371. (push (list day) dates1))
  3372. (push (cons :omitted (- day2 day)) dates1))))
  3373. (setq dates (nreverse dates1)))
  3374. dates)))
  3375. ;;; Agenda Daily/Weekly
  3376. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3377. "Start day for the agenda view.
  3378. Custom commands can set this variable in the options section.")
  3379. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3380. (defvar org-agenda-current-span nil
  3381. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3382. (defvar org-arg-loc nil) ; local variable
  3383. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3384. "List of types searched for when creating the daily/weekly agenda.
  3385. This variable is a list of symbols that controls the types of
  3386. items that appear in the daily/weekly agenda. Allowed symbols in this
  3387. list are are
  3388. :timestamp List items containing a date stamp or date range matching
  3389. the selected date. This includes sexp entries in
  3390. angular brackets.
  3391. :sexp List entries resulting from plain diary-like sexps.
  3392. :deadline List deadline due on that date. When the date is today,
  3393. also list any deadlines past due, or due within
  3394. `org-deadline-warning-days'. `:deadline' must appear before
  3395. `:scheduled' if the setting of
  3396. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3397. any effect.
  3398. :scheduled List all items which are scheduled for the given date.
  3399. The diary for *today* also contains items which were
  3400. scheduled earlier and are not yet marked DONE.
  3401. By default, all four types are turned on.
  3402. Never set this variable globally using `setq', because then it
  3403. will apply to all future agenda commands. Instead, bind it with
  3404. `let' to scope it dynamically into the agenda-constructing
  3405. command. A good way to set it is through options in
  3406. `org-agenda-custom-commands'. For a more flexible (though
  3407. somewhat less efficient) way of determining what is included in
  3408. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3409. ;;;###autoload
  3410. (defun org-agenda-list (&optional arg start-day span)
  3411. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3412. The view will be for the current day or week, but from the overview buffer
  3413. you will be able to go to other days/weeks.
  3414. With a numeric prefix argument in an interactive call, the agenda will
  3415. span ARG days. Lisp programs should instead specify SPAN to change
  3416. the number of days. SPAN defaults to `org-agenda-span'.
  3417. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3418. given in `org-agenda-start-on-weekday'."
  3419. (interactive "P")
  3420. (if (and (integerp arg) (> arg 0))
  3421. (setq span arg arg nil))
  3422. (org-prepare-agenda "Day/Week")
  3423. (setq start-day (or start-day org-agenda-start-day))
  3424. (if org-agenda-overriding-arguments
  3425. (setq arg (car org-agenda-overriding-arguments)
  3426. start-day (nth 1 org-agenda-overriding-arguments)
  3427. span (nth 2 org-agenda-overriding-arguments)))
  3428. (if (stringp start-day)
  3429. ;; Convert to an absolute day number
  3430. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3431. (setq org-agenda-last-arguments (list arg start-day span))
  3432. (org-compile-prefix-format 'agenda)
  3433. (org-set-sorting-strategy 'agenda)
  3434. (let* ((span (org-agenda-ndays-to-span
  3435. (or span org-agenda-ndays org-agenda-span)))
  3436. (today (org-today))
  3437. (sd (or start-day today))
  3438. (ndays (org-agenda-span-to-ndays span sd))
  3439. (org-agenda-start-on-weekday
  3440. (if (eq ndays 7)
  3441. org-agenda-start-on-weekday))
  3442. (thefiles (org-agenda-files nil 'ifmode))
  3443. (files thefiles)
  3444. (start (if (or (null org-agenda-start-on-weekday)
  3445. (< ndays 7))
  3446. sd
  3447. (let* ((nt (calendar-day-of-week
  3448. (calendar-gregorian-from-absolute sd)))
  3449. (n1 org-agenda-start-on-weekday)
  3450. (d (- nt n1)))
  3451. (- sd (+ (if (< d 0) 7 0) d)))))
  3452. (day-numbers (list start))
  3453. (day-cnt 0)
  3454. (inhibit-redisplay (not debug-on-error))
  3455. (org-agenda-show-log-scoped org-agenda-show-log)
  3456. s e rtn rtnall file date d start-pos end-pos todayp
  3457. clocktable-start clocktable-end filter)
  3458. (setq org-agenda-redo-command
  3459. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3460. (dotimes (n (1- ndays))
  3461. (push (1+ (car day-numbers)) day-numbers))
  3462. (setq day-numbers (nreverse day-numbers))
  3463. (setq clocktable-start (car day-numbers)
  3464. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3465. (org-set-local 'org-starting-day (car day-numbers))
  3466. (org-set-local 'org-arg-loc arg)
  3467. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3468. (unless org-agenda-compact-blocks
  3469. (let* ((d1 (car day-numbers))
  3470. (d2 (org-last day-numbers))
  3471. (w1 (org-days-to-iso-week d1))
  3472. (w2 (org-days-to-iso-week d2)))
  3473. (setq s (point))
  3474. (if org-agenda-overriding-header
  3475. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3476. nil 'face 'org-agenda-structure) "\n")
  3477. (insert (org-agenda-span-name span)
  3478. "-agenda"
  3479. (if (< (- d2 d1) 350)
  3480. (if (= w1 w2)
  3481. (format " (W%02d)" w1)
  3482. (format " (W%02d-W%02d)" w1 w2))
  3483. "")
  3484. ":\n")))
  3485. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3486. 'org-date-line t))
  3487. (org-agenda-mark-header-line s))
  3488. (while (setq d (pop day-numbers))
  3489. (setq date (calendar-gregorian-from-absolute d)
  3490. s (point))
  3491. (if (or (setq todayp (= d today))
  3492. (and (not start-pos) (= d sd)))
  3493. (setq start-pos (point))
  3494. (if (and start-pos (not end-pos))
  3495. (setq end-pos (point))))
  3496. (setq files thefiles
  3497. rtnall nil)
  3498. (while (setq file (pop files))
  3499. (catch 'nextfile
  3500. (org-check-agenda-file file)
  3501. (let ((org-agenda-entry-types org-agenda-entry-types))
  3502. (unless org-agenda-include-deadlines
  3503. (setq org-agenda-entry-types
  3504. (delq :deadline org-agenda-entry-types)))
  3505. (cond
  3506. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3507. (setq rtn (org-agenda-get-day-entries
  3508. file date :closed)))
  3509. (org-agenda-show-log-scoped
  3510. (setq rtn (apply 'org-agenda-get-day-entries
  3511. file date
  3512. (append '(:closed) org-agenda-entry-types))))
  3513. (t
  3514. (setq rtn (apply 'org-agenda-get-day-entries
  3515. file date
  3516. org-agenda-entry-types)))))
  3517. (setq rtnall (append rtnall rtn)))) ;; all entries
  3518. (if org-agenda-include-diary
  3519. (let ((org-agenda-search-headline-for-time t))
  3520. (require 'diary-lib)
  3521. (setq rtn (org-get-entries-from-diary date))
  3522. (setq rtnall (append rtnall rtn))))
  3523. (if (or rtnall org-agenda-show-all-dates)
  3524. (progn
  3525. (setq day-cnt (1+ day-cnt))
  3526. (insert
  3527. (if (stringp org-agenda-format-date)
  3528. (format-time-string org-agenda-format-date
  3529. (org-time-from-absolute date))
  3530. (funcall org-agenda-format-date date))
  3531. "\n")
  3532. (put-text-property s (1- (point)) 'face
  3533. (org-agenda-get-day-face date))
  3534. (put-text-property s (1- (point)) 'org-date-line t)
  3535. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3536. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3537. (when todayp
  3538. (put-text-property s (1- (point)) 'org-today t))
  3539. (if rtnall (insert ;; all entries
  3540. (org-finalize-agenda-entries
  3541. (org-agenda-add-time-grid-maybe
  3542. rtnall ndays todayp))
  3543. "\n"))
  3544. (put-text-property s (1- (point)) 'day d)
  3545. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3546. (when (and org-agenda-clockreport-mode clocktable-start)
  3547. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3548. ;; the above line is to ensure the restricted range!
  3549. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3550. tbl)
  3551. (setq p (org-plist-delete p :block))
  3552. (setq p (plist-put p :tstart clocktable-start))
  3553. (setq p (plist-put p :tend clocktable-end))
  3554. (setq p (plist-put p :scope 'agenda))
  3555. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3556. (setq filter (or org-agenda-tag-filter-while-redo
  3557. (get 'org-agenda-tag-filter :preset-filter))))
  3558. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3559. (if (string-match "[<>=]" x)
  3560. ""
  3561. x))
  3562. filter ""))))
  3563. (setq tbl (apply 'org-get-clocktable p))
  3564. (insert tbl)))
  3565. (goto-char (point-min))
  3566. (or org-agenda-multi (org-fit-agenda-window))
  3567. (unless (and (pos-visible-in-window-p (point-min))
  3568. (pos-visible-in-window-p (point-max)))
  3569. (goto-char (1- (point-max)))
  3570. (recenter -1)
  3571. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3572. (progn
  3573. (goto-char (or start-pos 1))
  3574. (recenter 1))))
  3575. (goto-char (or start-pos 1))
  3576. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3577. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3578. (org-agenda-show-clocking-issues))
  3579. (org-finalize-agenda)
  3580. (setq buffer-read-only t)
  3581. (message "")))
  3582. (defun org-agenda-ndays-to-span (n)
  3583. "Return a span symbol for a span of N days, or N if none matches."
  3584. (cond ((symbolp n) n)
  3585. ((= n 1) 'day)
  3586. ((= n 7) 'week)
  3587. (t n)))
  3588. (defun org-agenda-span-to-ndays (span start-day)
  3589. "Return ndays from SPAN starting at START-DAY."
  3590. (cond ((numberp span) span)
  3591. ((eq span 'day) 1)
  3592. ((eq span 'week) 7)
  3593. ((eq span 'month)
  3594. (let ((date (calendar-gregorian-from-absolute start-day)))
  3595. (calendar-last-day-of-month (car date) (caddr date))))
  3596. ((eq span 'year)
  3597. (let ((date (calendar-gregorian-from-absolute start-day)))
  3598. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3599. (defun org-agenda-span-name (span)
  3600. "Return a SPAN name."
  3601. (if (null span)
  3602. ""
  3603. (if (symbolp span)
  3604. (capitalize (symbol-name span))
  3605. (format "%d days" span))))
  3606. ;;; Agenda word search
  3607. (defvar org-agenda-search-history nil)
  3608. (defvar org-todo-only nil)
  3609. (defvar org-search-syntax-table nil
  3610. "Special syntax table for org-mode search.
  3611. In this table, we have single quotes not as word constituents, to
  3612. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3613. (defun org-search-syntax-table ()
  3614. (unless org-search-syntax-table
  3615. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3616. (modify-syntax-entry ?' "." org-search-syntax-table)
  3617. (modify-syntax-entry ?` "." org-search-syntax-table))
  3618. org-search-syntax-table)
  3619. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3620. ;;;###autoload
  3621. (defun org-search-view (&optional todo-only string edit-at)
  3622. "Show all entries that contain a phrase or words or regular expressions.
  3623. With optional prefix argument TODO-ONLY, only consider entries that are
  3624. TODO entries. The argument STRING can be used to pass a default search
  3625. string into this function. If EDIT-AT is non-nil, it means that the
  3626. user should get a chance to edit this string, with cursor at position
  3627. EDIT-AT.
  3628. The search string can be viewed either as a phrase that should be found as
  3629. is, or it can be broken into a number of snippets, each of which must match
  3630. in a Boolean way to select an entry. The default depends on the variable
  3631. `org-agenda-search-view-always-boolean'.
  3632. Even if this is turned off (the default) you can always switch to
  3633. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3634. The default is a direct search of the whole phrase, where each space in
  3635. the search string can expand to an arbitrary amount of whitespace,
  3636. including newlines.
  3637. If using a Boolean search, the search string is split on whitespace and
  3638. each snippet is searched separately, with logical AND to select an entry.
  3639. Words prefixed with a minus must *not* occur in the entry. Words without
  3640. a prefix or prefixed with a plus must occur in the entry. Matching is
  3641. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3642. match whole words, not parts of a word) if
  3643. `org-agenda-search-view-force-full-words' is set (default is nil).
  3644. Boolean search snippets enclosed by curly braces are interpreted as
  3645. regular expressions that must or (when preceded with \"-\") must not
  3646. match in the entry. Snippets enclosed into double quotes will be taken
  3647. as a whole, to include whitespace.
  3648. - If the search string starts with an asterisk, search only in headlines.
  3649. - If (possibly after the leading star) the search string starts with an
  3650. exclamation mark, this also means to look at TODO entries only, an effect
  3651. that can also be achieved with a prefix argument.
  3652. - If (possibly after star and exclamation mark) the search string starts
  3653. with a colon, this will mean that the (non-regexp) snippets of the
  3654. Boolean search must match as full words.
  3655. This command searches the agenda files, and in addition the files listed
  3656. in `org-agenda-text-search-extra-files'."
  3657. (interactive "P")
  3658. (org-prepare-agenda "SEARCH")
  3659. (org-compile-prefix-format 'search)
  3660. (org-set-sorting-strategy 'search)
  3661. (let* ((props (list 'face nil
  3662. 'done-face 'org-agenda-done
  3663. 'org-not-done-regexp org-not-done-regexp
  3664. 'org-todo-regexp org-todo-regexp
  3665. 'org-complex-heading-regexp org-complex-heading-regexp
  3666. 'mouse-face 'highlight
  3667. 'help-echo (format "mouse-2 or RET jump to location")))
  3668. (full-words org-agenda-search-view-force-full-words)
  3669. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3670. regexp rtn rtnall files file pos
  3671. marker category org-category-pos tags c neg re boolean
  3672. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3673. (unless (and (not edit-at)
  3674. (stringp string)
  3675. (string-match "\\S-" string))
  3676. (setq string (read-string
  3677. (if org-agenda-search-view-always-boolean
  3678. "[+-]Word/{Regexp} ...: "
  3679. "Phrase, or [+-]Word/{Regexp} ...: ")
  3680. (cond
  3681. ((integerp edit-at) (cons string edit-at))
  3682. (edit-at string))
  3683. 'org-agenda-search-history)))
  3684. (org-set-local 'org-todo-only todo-only)
  3685. (setq org-agenda-redo-command
  3686. (list 'org-search-view (if todo-only t nil) string
  3687. '(if current-prefix-arg 1 nil)))
  3688. (setq org-agenda-query-string string)
  3689. (if (equal (string-to-char string) ?*)
  3690. (setq hdl-only t
  3691. words (substring string 1))
  3692. (setq words string))
  3693. (when (equal (string-to-char words) ?!)
  3694. (setq todo-only t
  3695. words (substring words 1)))
  3696. (when (equal (string-to-char words) ?:)
  3697. (setq full-words t
  3698. words (substring words 1)))
  3699. (if (or org-agenda-search-view-always-boolean
  3700. (member (string-to-char words) '(?- ?+ ?\{)))
  3701. (setq boolean t))
  3702. (setq words (org-split-string words))
  3703. (let (www w)
  3704. (while (setq w (pop words))
  3705. (while (and (string-match "\\\\\\'" w) words)
  3706. (setq w (concat (substring w 0 -1) " " (pop words))))
  3707. (push w www))
  3708. (setq words (nreverse www) www nil)
  3709. (while (setq w (pop words))
  3710. (when (and (string-match "\\`[-+]?{" w)
  3711. (not (string-match "}\\'" w)))
  3712. (while (and words (not (string-match "}\\'" (car words))))
  3713. (setq w (concat w " " (pop words))))
  3714. (setq w (concat w " " (pop words))))
  3715. (push w www))
  3716. (setq words (nreverse www)))
  3717. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3718. (when boolean
  3719. (let (wds w)
  3720. (while (setq w (pop words))
  3721. (if (or (equal (substring w 0 1) "\"")
  3722. (and (> (length w) 1)
  3723. (member (substring w 0 1) '("+" "-"))
  3724. (equal (substring w 1 2) "\"")))
  3725. (while (and words (not (equal (substring w -1) "\"")))
  3726. (setq w (concat w " " (pop words)))))
  3727. (and (string-match "\\`\\([-+]?\\)\"" w)
  3728. (setq w (replace-match "\\1" nil nil w)))
  3729. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3730. (push w wds))
  3731. (setq words (nreverse wds))))
  3732. (if boolean
  3733. (mapc (lambda (w)
  3734. (setq c (string-to-char w))
  3735. (if (equal c ?-)
  3736. (setq neg t w (substring w 1))
  3737. (if (equal c ?+)
  3738. (setq neg nil w (substring w 1))
  3739. (setq neg nil)))
  3740. (if (string-match "\\`{.*}\\'" w)
  3741. (setq re (substring w 1 -1))
  3742. (if full-words
  3743. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3744. (setq re (regexp-quote (downcase w)))))
  3745. (if neg (push re regexps-) (push re regexps+)))
  3746. words)
  3747. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3748. regexps+))
  3749. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3750. (if (not regexps+)
  3751. (setq regexp org-outline-regexp-bol)
  3752. (setq regexp (pop regexps+))
  3753. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3754. regexp))))
  3755. (setq files (org-agenda-files nil 'ifmode))
  3756. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3757. (pop org-agenda-text-search-extra-files)
  3758. (setq files (org-add-archive-files files)))
  3759. (setq files (append files org-agenda-text-search-extra-files)
  3760. rtnall nil)
  3761. (while (setq file (pop files))
  3762. (setq ee nil)
  3763. (catch 'nextfile
  3764. (org-check-agenda-file file)
  3765. (setq buffer (if (file-exists-p file)
  3766. (org-get-agenda-file-buffer file)
  3767. (error "No such file %s" file)))
  3768. (if (not buffer)
  3769. ;; If file does not exist, make sure an error message is sent
  3770. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3771. file))))
  3772. (with-current-buffer buffer
  3773. (with-syntax-table (org-search-syntax-table)
  3774. (unless (derived-mode-p 'org-mode)
  3775. (error "Agenda file %s is not in `org-mode'" file))
  3776. (let ((case-fold-search t))
  3777. (save-excursion
  3778. (save-restriction
  3779. (if org-agenda-restrict
  3780. (narrow-to-region org-agenda-restrict-begin
  3781. org-agenda-restrict-end)
  3782. (widen))
  3783. (goto-char (point-min))
  3784. (unless (or (org-at-heading-p)
  3785. (outline-next-heading))
  3786. (throw 'nextfile t))
  3787. (goto-char (max (point-min) (1- (point))))
  3788. (while (re-search-forward regexp nil t)
  3789. (org-back-to-heading t)
  3790. (skip-chars-forward "* ")
  3791. (setq beg (point-at-bol)
  3792. beg1 (point)
  3793. end (progn (outline-next-heading) (point)))
  3794. (catch :skip
  3795. (goto-char beg)
  3796. (org-agenda-skip)
  3797. (setq str (buffer-substring-no-properties
  3798. (point-at-bol)
  3799. (if hdl-only (point-at-eol) end)))
  3800. (mapc (lambda (wr) (when (string-match wr str)
  3801. (goto-char (1- end))
  3802. (throw :skip t)))
  3803. regexps-)
  3804. (mapc (lambda (wr) (unless (string-match wr str)
  3805. (goto-char (1- end))
  3806. (throw :skip t)))
  3807. (if todo-only
  3808. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3809. regexps+)
  3810. regexps+))
  3811. (goto-char beg)
  3812. (setq marker (org-agenda-new-marker (point))
  3813. category (org-get-category)
  3814. org-category-pos (get-text-property (point) 'org-category-position)
  3815. tags (org-get-tags-at (point))
  3816. txt (org-agenda-format-item
  3817. ""
  3818. (buffer-substring-no-properties
  3819. beg1 (point-at-eol))
  3820. category tags))
  3821. (org-add-props txt props
  3822. 'org-marker marker 'org-hd-marker marker
  3823. 'org-todo-regexp org-todo-regexp
  3824. 'org-complex-heading-regexp org-complex-heading-regexp
  3825. 'priority 1000 'org-category category
  3826. 'org-category-position org-category-pos
  3827. 'type "search")
  3828. (push txt ee)
  3829. (goto-char (1- end))))))))))
  3830. (setq rtn (nreverse ee))
  3831. (setq rtnall (append rtnall rtn)))
  3832. (if org-agenda-overriding-header
  3833. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3834. nil 'face 'org-agenda-structure) "\n")
  3835. (insert "Search words: ")
  3836. (add-text-properties (point-min) (1- (point))
  3837. (list 'face 'org-agenda-structure))
  3838. (setq pos (point))
  3839. (insert string "\n")
  3840. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3841. (setq pos (point))
  3842. (unless org-agenda-multi
  3843. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3844. (add-text-properties pos (1- (point))
  3845. (list 'face 'org-agenda-structure))))
  3846. (org-agenda-mark-header-line (point-min))
  3847. (when rtnall
  3848. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3849. (goto-char (point-min))
  3850. (or org-agenda-multi (org-fit-agenda-window))
  3851. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3852. (org-finalize-agenda)
  3853. (setq buffer-read-only t)))
  3854. ;;; Agenda TODO list
  3855. (defvar org-select-this-todo-keyword nil)
  3856. (defvar org-last-arg nil)
  3857. ;;;###autoload
  3858. (defun org-todo-list (arg)
  3859. "Show all (not done) TODO entries from all agenda file in a single list.
  3860. The prefix arg can be used to select a specific TODO keyword and limit
  3861. the list to these. When using \\[universal-argument], you will be prompted
  3862. for a keyword. A numeric prefix directly selects the Nth keyword in
  3863. `org-todo-keywords-1'."
  3864. (interactive "P")
  3865. (org-prepare-agenda "TODO")
  3866. (org-compile-prefix-format 'todo)
  3867. (org-set-sorting-strategy 'todo)
  3868. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3869. (let* ((today (org-today))
  3870. (date (calendar-gregorian-from-absolute today))
  3871. (kwds org-todo-keywords-for-agenda)
  3872. (completion-ignore-case t)
  3873. (org-select-this-todo-keyword
  3874. (if (stringp arg) arg
  3875. (and arg (integerp arg) (> arg 0)
  3876. (nth (1- arg) kwds))))
  3877. rtn rtnall files file pos)
  3878. (when (equal arg '(4))
  3879. (setq org-select-this-todo-keyword
  3880. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3881. (mapcar 'list kwds) nil nil)))
  3882. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3883. (org-set-local 'org-last-arg arg)
  3884. (setq org-agenda-redo-command
  3885. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3886. (setq files (org-agenda-files nil 'ifmode)
  3887. rtnall nil)
  3888. (while (setq file (pop files))
  3889. (catch 'nextfile
  3890. (org-check-agenda-file file)
  3891. (setq rtn (org-agenda-get-day-entries file date :todo))
  3892. (setq rtnall (append rtnall rtn))))
  3893. (if org-agenda-overriding-header
  3894. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3895. nil 'face 'org-agenda-structure) "\n")
  3896. (insert "Global list of TODO items of type: ")
  3897. (add-text-properties (point-min) (1- (point))
  3898. (list 'face 'org-agenda-structure
  3899. 'short-heading
  3900. (concat "ToDo: "
  3901. (or org-select-this-todo-keyword "ALL"))))
  3902. (org-agenda-mark-header-line (point-min))
  3903. (setq pos (point))
  3904. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3905. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3906. (setq pos (point))
  3907. (unless org-agenda-multi
  3908. (insert "Available with `N r': (0)ALL")
  3909. (let ((n 0) s)
  3910. (mapc (lambda (x)
  3911. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3912. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3913. (insert "\n "))
  3914. (insert " " s))
  3915. kwds))
  3916. (insert "\n"))
  3917. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3918. (org-agenda-mark-header-line (point-min))
  3919. (when rtnall
  3920. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3921. (goto-char (point-min))
  3922. (or org-agenda-multi (org-fit-agenda-window))
  3923. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3924. (org-finalize-agenda)
  3925. (setq buffer-read-only t)))
  3926. ;;; Agenda tags match
  3927. ;;;###autoload
  3928. (defun org-tags-view (&optional todo-only match)
  3929. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3930. The prefix arg TODO-ONLY limits the search to TODO entries."
  3931. (interactive "P")
  3932. (let* ((org-tags-match-list-sublevels
  3933. org-tags-match-list-sublevels)
  3934. (completion-ignore-case t)
  3935. rtn rtnall files file pos matcher
  3936. buffer)
  3937. (when (and (stringp match) (not (string-match "\\S-" match)))
  3938. (setq match nil))
  3939. (setq matcher (org-make-tags-matcher match)
  3940. match (car matcher) matcher (cdr matcher))
  3941. (org-prepare-agenda (concat "TAGS " match))
  3942. (org-compile-prefix-format 'tags)
  3943. (org-set-sorting-strategy 'tags)
  3944. (setq org-agenda-query-string match)
  3945. (setq org-agenda-redo-command
  3946. (list 'org-tags-view (list 'quote todo-only)
  3947. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3948. (setq files (org-agenda-files nil 'ifmode)
  3949. rtnall nil)
  3950. (while (setq file (pop files))
  3951. (catch 'nextfile
  3952. (org-check-agenda-file file)
  3953. (setq buffer (if (file-exists-p file)
  3954. (org-get-agenda-file-buffer file)
  3955. (error "No such file %s" file)))
  3956. (if (not buffer)
  3957. ;; If file does not exist, error message to agenda
  3958. (setq rtn (list
  3959. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3960. rtnall (append rtnall rtn))
  3961. (with-current-buffer buffer
  3962. (unless (derived-mode-p 'org-mode)
  3963. (error "Agenda file %s is not in `org-mode'" file))
  3964. (save-excursion
  3965. (save-restriction
  3966. (if org-agenda-restrict
  3967. (narrow-to-region org-agenda-restrict-begin
  3968. org-agenda-restrict-end)
  3969. (widen))
  3970. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3971. (setq rtnall (append rtnall rtn))))))))
  3972. (if org-agenda-overriding-header
  3973. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3974. nil 'face 'org-agenda-structure) "\n")
  3975. (insert "Headlines with TAGS match: ")
  3976. (add-text-properties (point-min) (1- (point))
  3977. (list 'face 'org-agenda-structure
  3978. 'short-heading
  3979. (concat "Match: " match)))
  3980. (setq pos (point))
  3981. (insert match "\n")
  3982. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3983. (setq pos (point))
  3984. (unless org-agenda-multi
  3985. (insert "Press `C-u r' to search again with new search string\n"))
  3986. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3987. (org-agenda-mark-header-line (point-min))
  3988. (when rtnall
  3989. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3990. (goto-char (point-min))
  3991. (or org-agenda-multi (org-fit-agenda-window))
  3992. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3993. (org-finalize-agenda)
  3994. (setq buffer-read-only t)))
  3995. ;;; Agenda Finding stuck projects
  3996. (defvar org-agenda-skip-regexp nil
  3997. "Regular expression used in skipping subtrees for the agenda.
  3998. This is basically a temporary global variable that can be set and then
  3999. used by user-defined selections using `org-agenda-skip-function'.")
  4000. (defvar org-agenda-overriding-header nil
  4001. "When set during agenda, todo and tags searches it replaces the header.
  4002. This variable should not be set directly, but custom commands can bind it
  4003. in the options section.")
  4004. (defun org-agenda-skip-entry-when-regexp-matches ()
  4005. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4006. If yes, it returns the end position of this entry, causing agenda commands
  4007. to skip the entry but continuing the search in the subtree. This is a
  4008. function that can be put into `org-agenda-skip-function' for the duration
  4009. of a command."
  4010. (let ((end (save-excursion (org-end-of-subtree t)))
  4011. skip)
  4012. (save-excursion
  4013. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4014. (and skip end)))
  4015. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4016. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4017. If yes, it returns the end position of this tree, causing agenda commands
  4018. to skip this subtree. This is a function that can be put into
  4019. `org-agenda-skip-function' for the duration of a command."
  4020. (let ((end (save-excursion (org-end-of-subtree t)))
  4021. skip)
  4022. (save-excursion
  4023. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4024. (and skip end)))
  4025. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4026. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4027. If yes, it returns the end position of the current entry (NOT the tree),
  4028. causing agenda commands to skip the entry but continuing the search in
  4029. the subtree. This is a function that can be put into
  4030. `org-agenda-skip-function' for the duration of a command. An important
  4031. use of this function is for the stuck project list."
  4032. (let ((end (save-excursion (org-end-of-subtree t)))
  4033. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4034. skip)
  4035. (save-excursion
  4036. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4037. (and skip entry-end)))
  4038. (defun org-agenda-skip-entry-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 nil conditions))
  4042. (defun org-agenda-skip-subtree-if (&rest conditions)
  4043. "Skip entry if any of CONDITIONS is true.
  4044. See `org-agenda-skip-if' for details."
  4045. (org-agenda-skip-if t conditions))
  4046. (defun org-agenda-skip-if (subtree conditions)
  4047. "Checks current entity for CONDITIONS.
  4048. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4049. the entry (i.e. the text before the next heading) is checked.
  4050. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4051. from different tests. Valid conditions are:
  4052. scheduled Check if there is a scheduled cookie
  4053. notscheduled Check if there is no scheduled cookie
  4054. deadline Check if there is a deadline
  4055. notdeadline Check if there is no deadline
  4056. timestamp Check if there is a timestamp (also deadline or scheduled)
  4057. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4058. regexp Check if regexp matches
  4059. notregexp Check if regexp does not match.
  4060. todo Check if TODO keyword matches
  4061. nottodo Check if TODO keyword does not match
  4062. The regexp is taken from the conditions list, it must come right after
  4063. the `regexp' or `notregexp' element.
  4064. `todo' and `nottodo' accept as an argument a list of todo
  4065. keywords, which may include \"*\" to match any todo keyword.
  4066. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4067. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4068. Instead of a list, a keyword class may be given. For example:
  4069. (org-agenda-skip-entry-if 'nottodo 'done)
  4070. would skip entries that haven't been marked with any of \"DONE\"
  4071. keywords. Possible classes are: `todo', `done', `any'.
  4072. If any of these conditions is met, this function returns the end point of
  4073. the entity, causing the search to continue from there. This is a function
  4074. that can be put into `org-agenda-skip-function' for the duration of a command."
  4075. (let (beg end m)
  4076. (org-back-to-heading t)
  4077. (setq beg (point)
  4078. end (if subtree
  4079. (progn (org-end-of-subtree t) (point))
  4080. (progn (outline-next-heading) (1- (point)))))
  4081. (goto-char beg)
  4082. (and
  4083. (or
  4084. (and (memq 'scheduled conditions)
  4085. (re-search-forward org-scheduled-time-regexp end t))
  4086. (and (memq 'notscheduled conditions)
  4087. (not (re-search-forward org-scheduled-time-regexp end t)))
  4088. (and (memq 'deadline conditions)
  4089. (re-search-forward org-deadline-time-regexp end t))
  4090. (and (memq 'notdeadline conditions)
  4091. (not (re-search-forward org-deadline-time-regexp end t)))
  4092. (and (memq 'timestamp conditions)
  4093. (re-search-forward org-ts-regexp end t))
  4094. (and (memq 'nottimestamp conditions)
  4095. (not (re-search-forward org-ts-regexp end t)))
  4096. (and (setq m (memq 'regexp conditions))
  4097. (stringp (nth 1 m))
  4098. (re-search-forward (nth 1 m) end t))
  4099. (and (setq m (memq 'notregexp conditions))
  4100. (stringp (nth 1 m))
  4101. (not (re-search-forward (nth 1 m) end t)))
  4102. (and (or
  4103. (setq m (memq 'nottodo conditions))
  4104. (setq m (memq 'todo-unblocked conditions))
  4105. (setq m (memq 'nottodo-unblocked conditions))
  4106. (setq m (memq 'todo conditions)))
  4107. (org-agenda-skip-if-todo m end)))
  4108. end)))
  4109. (defun org-agenda-skip-if-todo (args end)
  4110. "Helper function for `org-agenda-skip-if', do not use it directly.
  4111. ARGS is a list with first element either `todo', `nottodo',
  4112. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4113. a list of TODO keywords, or a state symbol `todo' or `done' or
  4114. `any'."
  4115. (let ((kw (car args))
  4116. (arg (cadr args))
  4117. todo-wds todo-re)
  4118. (setq todo-wds
  4119. (org-uniquify
  4120. (cond
  4121. ((listp arg) ;; list of keywords
  4122. (if (member "*" arg)
  4123. (mapcar 'substring-no-properties org-todo-keywords-1)
  4124. arg))
  4125. ((symbolp arg) ;; keyword class name
  4126. (cond
  4127. ((eq arg 'todo)
  4128. (org-delete-all org-done-keywords
  4129. (mapcar 'substring-no-properties
  4130. org-todo-keywords-1)))
  4131. ((eq arg 'done) org-done-keywords)
  4132. ((eq arg 'any)
  4133. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4134. (setq todo-re
  4135. (concat "^\\*+[ \t]+\\<\\("
  4136. (mapconcat 'identity todo-wds "\\|")
  4137. "\\)\\>"))
  4138. (cond
  4139. ((eq kw 'todo) (re-search-forward todo-re end t))
  4140. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4141. ((eq kw 'todo-unblocked)
  4142. (catch 'unblocked
  4143. (while (re-search-forward todo-re end t)
  4144. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4145. nil))
  4146. ((eq kw 'nottodo-unblocked)
  4147. (catch 'unblocked
  4148. (while (re-search-forward todo-re end t)
  4149. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4150. t))
  4151. )))
  4152. ;;;###autoload
  4153. (defun org-agenda-list-stuck-projects (&rest ignore)
  4154. "Create agenda view for projects that are stuck.
  4155. Stuck projects are project that have no next actions. For the definitions
  4156. of what a project is and how to check if it stuck, customize the variable
  4157. `org-stuck-projects'."
  4158. (interactive)
  4159. (let* ((org-agenda-skip-function
  4160. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4161. ;; We could have used org-agenda-skip-if here.
  4162. (org-agenda-overriding-header
  4163. (or org-agenda-overriding-header "List of stuck projects: "))
  4164. (matcher (nth 0 org-stuck-projects))
  4165. (todo (nth 1 org-stuck-projects))
  4166. (todo-wds (if (member "*" todo)
  4167. (progn
  4168. (org-prepare-agenda-buffers (org-agenda-files
  4169. nil 'ifmode))
  4170. (org-delete-all
  4171. org-done-keywords-for-agenda
  4172. (copy-sequence org-todo-keywords-for-agenda)))
  4173. todo))
  4174. (todo-re (concat "^\\*+[ \t]+\\("
  4175. (mapconcat 'identity todo-wds "\\|")
  4176. "\\)\\>"))
  4177. (tags (nth 2 org-stuck-projects))
  4178. (tags-re (if (member "*" tags)
  4179. (concat org-outline-regexp-bol
  4180. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4181. (if tags
  4182. (concat org-outline-regexp-bol
  4183. ".*:\\("
  4184. (mapconcat 'identity tags "\\|")
  4185. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4186. (gen-re (nth 3 org-stuck-projects))
  4187. (re-list
  4188. (delq nil
  4189. (list
  4190. (if todo todo-re)
  4191. (if tags tags-re)
  4192. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4193. gen-re)))))
  4194. (setq org-agenda-skip-regexp
  4195. (if re-list
  4196. (mapconcat 'identity re-list "\\|")
  4197. (error "No information how to identify unstuck projects")))
  4198. (org-tags-view nil matcher)
  4199. (with-current-buffer org-agenda-buffer-name
  4200. (setq org-agenda-redo-command
  4201. '(org-agenda-list-stuck-projects
  4202. (or current-prefix-arg org-last-arg))))))
  4203. ;;; Diary integration
  4204. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4205. (defvar diary-list-entries-hook)
  4206. (defvar diary-time-regexp)
  4207. (defun org-get-entries-from-diary (date)
  4208. "Get the (Emacs Calendar) diary entries for DATE."
  4209. (require 'diary-lib)
  4210. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4211. (diary-display-hook '(fancy-diary-display))
  4212. (diary-display-function 'fancy-diary-display)
  4213. (pop-up-frames nil)
  4214. (diary-list-entries-hook
  4215. (cons 'org-diary-default-entry diary-list-entries-hook))
  4216. (diary-file-name-prefix-function nil) ; turn this feature off
  4217. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4218. entries
  4219. (org-disable-agenda-to-diary t))
  4220. (save-excursion
  4221. (save-window-excursion
  4222. (funcall (if (fboundp 'diary-list-entries)
  4223. 'diary-list-entries 'list-diary-entries)
  4224. date 1)))
  4225. (if (not (get-buffer diary-fancy-buffer))
  4226. (setq entries nil)
  4227. (with-current-buffer diary-fancy-buffer
  4228. (setq buffer-read-only nil)
  4229. (if (zerop (buffer-size))
  4230. ;; No entries
  4231. (setq entries nil)
  4232. ;; Omit the date and other unnecessary stuff
  4233. (org-agenda-cleanup-fancy-diary)
  4234. ;; Add prefix to each line and extend the text properties
  4235. (if (zerop (buffer-size))
  4236. (setq entries nil)
  4237. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4238. (setq entries
  4239. (with-temp-buffer
  4240. (insert entries) (goto-char (point-min))
  4241. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4242. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4243. (replace-match (concat "; " (match-string 1)))))
  4244. (buffer-string)))))
  4245. (set-buffer-modified-p nil)
  4246. (kill-buffer diary-fancy-buffer)))
  4247. (when entries
  4248. (setq entries (org-split-string entries "\n"))
  4249. (setq entries
  4250. (mapcar
  4251. (lambda (x)
  4252. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4253. ;; Extend the text properties to the beginning of the line
  4254. (org-add-props x (text-properties-at (1- (length x)) x)
  4255. 'type "diary" 'date date 'face 'org-agenda-diary))
  4256. entries)))))
  4257. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4258. "Hook run when the fancy diary buffer is cleaned up.")
  4259. (defun org-agenda-cleanup-fancy-diary ()
  4260. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4261. This gets rid of the date, the underline under the date, and
  4262. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4263. date. It also removes lines that contain only whitespace."
  4264. (goto-char (point-min))
  4265. (if (looking-at ".*?:[ \t]*")
  4266. (progn
  4267. (replace-match "")
  4268. (re-search-forward "\n=+$" nil t)
  4269. (replace-match "")
  4270. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4271. (re-search-forward "\n=+$" nil t)
  4272. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4273. (goto-char (point-min))
  4274. (while (re-search-forward "^ +\n" nil t)
  4275. (replace-match ""))
  4276. (goto-char (point-min))
  4277. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4278. (replace-match ""))
  4279. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4280. ;; Make sure entries from the diary have the right text properties.
  4281. (eval-after-load "diary-lib"
  4282. '(if (boundp 'diary-modify-entry-list-string-function)
  4283. ;; We can rely on the hook, nothing to do
  4284. nil
  4285. ;; Hook not available, must use advice to make this work
  4286. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4287. "Make the position visible."
  4288. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4289. (stringp string)
  4290. buffer-file-name)
  4291. (setq string (org-modify-diary-entry-string string))))))
  4292. (defun org-modify-diary-entry-string (string)
  4293. "Add text properties to string, allowing org-mode to act on it."
  4294. (org-add-props string nil
  4295. 'mouse-face 'highlight
  4296. 'help-echo (if buffer-file-name
  4297. (format "mouse-2 or RET jump to diary file %s"
  4298. (abbreviate-file-name buffer-file-name))
  4299. "")
  4300. 'org-agenda-diary-link t
  4301. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4302. (defun org-diary-default-entry ()
  4303. "Add a dummy entry to the diary.
  4304. Needed to avoid empty dates which mess up holiday display."
  4305. ;; Catch the error if dealing with the new add-to-diary-alist
  4306. (when org-disable-agenda-to-diary
  4307. (condition-case nil
  4308. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4309. (error
  4310. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4311. (defun org-add-to-diary-list (&rest args)
  4312. (if (fboundp 'diary-add-to-list)
  4313. (apply 'diary-add-to-list args)
  4314. (apply 'add-to-diary-list args)))
  4315. (defvar org-diary-last-run-time nil)
  4316. ;;;###autoload
  4317. (defun org-diary (&rest args)
  4318. "Return diary information from org-files.
  4319. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4320. It accesses org files and extracts information from those files to be
  4321. listed in the diary. The function accepts arguments specifying what
  4322. items should be listed. For a list of arguments allowed here, see the
  4323. variable `org-agenda-entry-types'.
  4324. The call in the diary file should look like this:
  4325. &%%(org-diary) ~/path/to/some/orgfile.org
  4326. Use a separate line for each org file to check. Or, if you omit the file name,
  4327. all files listed in `org-agenda-files' will be checked automatically:
  4328. &%%(org-diary)
  4329. If you don't give any arguments (as in the example above), the default
  4330. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4331. So the example above may also be written as
  4332. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4333. The function expects the lisp variables `entry' and `date' to be provided
  4334. by the caller, because this is how the calendar works. Don't use this
  4335. function from a program - use `org-agenda-get-day-entries' instead."
  4336. (when (> (- (org-float-time)
  4337. org-agenda-last-marker-time)
  4338. 5)
  4339. ;; I am not sure if this works with sticky agendas, because the marker
  4340. ;; list is then no longer a global variable.
  4341. (org-agenda-reset-markers))
  4342. (org-compile-prefix-format 'agenda)
  4343. (org-set-sorting-strategy 'agenda)
  4344. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4345. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4346. (list entry)
  4347. (org-agenda-files t)))
  4348. (time (org-float-time))
  4349. file rtn results)
  4350. (when (or (not org-diary-last-run-time)
  4351. (> (- time
  4352. org-diary-last-run-time)
  4353. 3))
  4354. (org-prepare-agenda-buffers files))
  4355. (setq org-diary-last-run-time time)
  4356. ;; If this is called during org-agenda, don't return any entries to
  4357. ;; the calendar. Org Agenda will list these entries itself.
  4358. (if org-disable-agenda-to-diary (setq files nil))
  4359. (while (setq file (pop files))
  4360. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4361. (setq results (append results rtn)))
  4362. (if results
  4363. (concat (org-finalize-agenda-entries results) "\n"))))
  4364. ;;; Agenda entry finders
  4365. (defun org-agenda-get-day-entries (file date &rest args)
  4366. "Does the work for `org-diary' and `org-agenda'.
  4367. FILE is the path to a file to be checked for entries. DATE is date like
  4368. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4369. which kind of entries should be extracted. For details about these, see
  4370. the documentation of `org-diary'."
  4371. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4372. (let* ((org-startup-folded nil)
  4373. (org-startup-align-all-tables nil)
  4374. (buffer (if (file-exists-p file)
  4375. (org-get-agenda-file-buffer file)
  4376. (error "No such file %s" file)))
  4377. arg results rtn deadline-results)
  4378. (if (not buffer)
  4379. ;; If file does not exist, make sure an error message ends up in diary
  4380. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4381. (with-current-buffer buffer
  4382. (unless (derived-mode-p 'org-mode)
  4383. (error "Agenda file %s is not in `org-mode'" file))
  4384. (let ((case-fold-search nil))
  4385. (save-excursion
  4386. (save-restriction
  4387. (if org-agenda-restrict
  4388. (narrow-to-region org-agenda-restrict-begin
  4389. org-agenda-restrict-end)
  4390. (widen))
  4391. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4392. (while (setq arg (pop args))
  4393. (cond
  4394. ((and (eq arg :todo)
  4395. (equal date (calendar-gregorian-from-absolute
  4396. (org-today))))
  4397. (setq rtn (org-agenda-get-todos))
  4398. (setq results (append results rtn)))
  4399. ((eq arg :timestamp)
  4400. (setq rtn (org-agenda-get-blocks))
  4401. (setq results (append results rtn))
  4402. (setq rtn (org-agenda-get-timestamps))
  4403. (setq results (append results rtn)))
  4404. ((eq arg :sexp)
  4405. (setq rtn (org-agenda-get-sexps))
  4406. (setq results (append results rtn)))
  4407. ((eq arg :scheduled)
  4408. (setq rtn (org-agenda-get-scheduled deadline-results))
  4409. (setq results (append results rtn)))
  4410. ((eq arg :closed)
  4411. (setq rtn (org-agenda-get-progress))
  4412. (setq results (append results rtn)))
  4413. ((eq arg :deadline)
  4414. (setq rtn (org-agenda-get-deadlines))
  4415. (setq deadline-results (copy-sequence rtn))
  4416. (setq results (append results rtn))))))))
  4417. results))))
  4418. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4419. (defun org-agenda-get-todos ()
  4420. "Return the TODO information for agenda display."
  4421. (let* ((props (list 'face nil
  4422. 'done-face 'org-agenda-done
  4423. 'org-not-done-regexp org-not-done-regexp
  4424. 'org-todo-regexp org-todo-regexp
  4425. 'org-complex-heading-regexp org-complex-heading-regexp
  4426. 'mouse-face 'highlight
  4427. 'help-echo
  4428. (format "mouse-2 or RET jump to org file %s"
  4429. (abbreviate-file-name buffer-file-name))))
  4430. (regexp (format org-heading-keyword-regexp-format
  4431. (cond
  4432. ((and org-select-this-todo-keyword
  4433. (equal org-select-this-todo-keyword "*"))
  4434. org-todo-regexp)
  4435. (org-select-this-todo-keyword
  4436. (concat "\\("
  4437. (mapconcat 'identity
  4438. (org-split-string
  4439. org-select-this-todo-keyword
  4440. "|")
  4441. "\\|") "\\)"))
  4442. (t org-not-done-regexp))))
  4443. marker priority category org-category-pos tags todo-state
  4444. ee txt beg end)
  4445. (goto-char (point-min))
  4446. (while (re-search-forward regexp nil t)
  4447. (catch :skip
  4448. (save-match-data
  4449. (beginning-of-line)
  4450. (org-agenda-skip)
  4451. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4452. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4453. (goto-char (1+ beg))
  4454. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4455. (throw :skip nil)))
  4456. (goto-char (match-beginning 2))
  4457. (setq marker (org-agenda-new-marker (match-beginning 0))
  4458. category (org-get-category)
  4459. org-category-pos (get-text-property (point) 'org-category-position)
  4460. txt (org-trim
  4461. (buffer-substring (match-beginning 2) (match-end 0)))
  4462. tags (org-get-tags-at (point))
  4463. txt (org-agenda-format-item "" txt category tags)
  4464. priority (1+ (org-get-priority txt))
  4465. todo-state (org-get-todo-state))
  4466. (org-add-props txt props
  4467. 'org-marker marker 'org-hd-marker marker
  4468. 'priority priority 'org-category category
  4469. 'org-category-position org-category-pos
  4470. 'type "todo" 'todo-state todo-state)
  4471. (push txt ee)
  4472. (if org-agenda-todo-list-sublevels
  4473. (goto-char (match-end 2))
  4474. (org-end-of-subtree 'invisible))))
  4475. (nreverse ee)))
  4476. (defun org-agenda-todo-custom-ignore-p (time n)
  4477. "Check whether timestamp is farther away then n number of days.
  4478. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4479. `org-agenda-todo-ignore-scheduled' or
  4480. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4481. (let ((days (org-days-to-time time)))
  4482. (if (>= n 0)
  4483. (>= days n)
  4484. (<= days n))))
  4485. ;;;###autoload
  4486. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4487. (&optional end)
  4488. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4489. (when (or org-agenda-todo-ignore-with-date
  4490. org-agenda-todo-ignore-scheduled
  4491. org-agenda-todo-ignore-deadlines
  4492. org-agenda-todo-ignore-timestamp)
  4493. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4494. (save-excursion
  4495. (or (and org-agenda-todo-ignore-with-date
  4496. (re-search-forward org-ts-regexp end t))
  4497. (and org-agenda-todo-ignore-scheduled
  4498. (re-search-forward org-scheduled-time-regexp end t)
  4499. (cond
  4500. ((eq org-agenda-todo-ignore-scheduled 'future)
  4501. (> (org-days-to-time (match-string 1)) 0))
  4502. ((eq org-agenda-todo-ignore-scheduled 'past)
  4503. (<= (org-days-to-time (match-string 1)) 0))
  4504. ((numberp org-agenda-todo-ignore-scheduled)
  4505. (org-agenda-todo-custom-ignore-p
  4506. (match-string 1) org-agenda-todo-ignore-scheduled))
  4507. (t)))
  4508. (and org-agenda-todo-ignore-deadlines
  4509. (re-search-forward org-deadline-time-regexp end t)
  4510. (cond
  4511. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4512. ((eq org-agenda-todo-ignore-deadlines 'far)
  4513. (not (org-deadline-close (match-string 1))))
  4514. ((eq org-agenda-todo-ignore-deadlines 'future)
  4515. (> (org-days-to-time (match-string 1)) 0))
  4516. ((eq org-agenda-todo-ignore-deadlines 'past)
  4517. (<= (org-days-to-time (match-string 1)) 0))
  4518. ((numberp org-agenda-todo-ignore-deadlines)
  4519. (org-agenda-todo-custom-ignore-p
  4520. (match-string 1) org-agenda-todo-ignore-deadlines))
  4521. (t (org-deadline-close (match-string 1)))))
  4522. (and org-agenda-todo-ignore-timestamp
  4523. (let ((buffer (current-buffer))
  4524. (regexp
  4525. (concat
  4526. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4527. (start (point)))
  4528. ;; Copy current buffer into a temporary one
  4529. (with-temp-buffer
  4530. (insert-buffer-substring buffer start end)
  4531. (goto-char (point-min))
  4532. ;; Delete SCHEDULED and DEADLINE items
  4533. (while (re-search-forward regexp end t)
  4534. (delete-region (match-beginning 0) (match-end 0)))
  4535. (goto-char (point-min))
  4536. ;; No search for timestamp left
  4537. (when (re-search-forward org-ts-regexp nil t)
  4538. (cond
  4539. ((eq org-agenda-todo-ignore-timestamp 'future)
  4540. (> (org-days-to-time (match-string 1)) 0))
  4541. ((eq org-agenda-todo-ignore-timestamp 'past)
  4542. (<= (org-days-to-time (match-string 1)) 0))
  4543. ((numberp org-agenda-todo-ignore-timestamp)
  4544. (org-agenda-todo-custom-ignore-p
  4545. (match-string 1) org-agenda-todo-ignore-timestamp))
  4546. (t))))))))))
  4547. (defconst org-agenda-no-heading-message
  4548. "No heading for this item in buffer or region.")
  4549. (defun org-agenda-get-timestamps ()
  4550. "Return the date stamp information for agenda display."
  4551. (let* ((props (list 'face 'org-agenda-calendar-event
  4552. 'org-not-done-regexp org-not-done-regexp
  4553. 'org-todo-regexp org-todo-regexp
  4554. 'org-complex-heading-regexp org-complex-heading-regexp
  4555. 'mouse-face 'highlight
  4556. 'help-echo
  4557. (format "mouse-2 or RET jump to org file %s"
  4558. (abbreviate-file-name buffer-file-name))))
  4559. (d1 (calendar-absolute-from-gregorian date))
  4560. (remove-re
  4561. (concat
  4562. (regexp-quote
  4563. (format-time-string
  4564. "<%Y-%m-%d"
  4565. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4566. ".*?>"))
  4567. (regexp
  4568. (concat
  4569. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4570. (regexp-quote
  4571. (substring
  4572. (format-time-string
  4573. (car org-time-stamp-formats)
  4574. (apply 'encode-time ; DATE bound by calendar
  4575. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4576. 1 11))
  4577. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4578. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4579. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4580. donep tmp priority category org-category-pos ee txt timestr tags
  4581. b0 b3 e3 head todo-state end-of-match show-all)
  4582. (goto-char (point-min))
  4583. (while (setq end-of-match (re-search-forward regexp nil t))
  4584. (setq b0 (match-beginning 0)
  4585. b3 (match-beginning 3) e3 (match-end 3)
  4586. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4587. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4588. (member todo-state
  4589. org-agenda-repeating-timestamp-show-all)))
  4590. (catch :skip
  4591. (and (org-at-date-range-p) (throw :skip nil))
  4592. (org-agenda-skip)
  4593. (if (and (match-end 1)
  4594. (not (= d1 (org-time-string-to-absolute
  4595. (match-string 1) d1 nil show-all
  4596. (current-buffer) b0))))
  4597. (throw :skip nil))
  4598. (if (and e3
  4599. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4600. (throw :skip nil))
  4601. (setq tmp (buffer-substring (max (point-min)
  4602. (- b0 org-ds-keyword-length))
  4603. b0)
  4604. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4605. inactivep (= (char-after b0) ?\[)
  4606. deadlinep (string-match org-deadline-regexp tmp)
  4607. scheduledp (string-match org-scheduled-regexp tmp)
  4608. closedp (and org-agenda-include-inactive-timestamps
  4609. (string-match org-closed-string tmp))
  4610. clockp (and org-agenda-include-inactive-timestamps
  4611. (or (string-match org-clock-string tmp)
  4612. (string-match "]-+\\'" tmp)))
  4613. donep (member todo-state org-done-keywords))
  4614. (if (or scheduledp deadlinep closedp clockp
  4615. (and donep org-agenda-skip-timestamp-if-done))
  4616. (throw :skip t))
  4617. (if (string-match ">" timestr)
  4618. ;; substring should only run to end of time stamp
  4619. (setq timestr (substring timestr 0 (match-end 0))))
  4620. (setq marker (org-agenda-new-marker b0)
  4621. category (org-get-category b0)
  4622. org-category-pos (get-text-property b0 'org-category-position))
  4623. (save-excursion
  4624. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4625. (setq txt org-agenda-no-heading-message)
  4626. (goto-char (match-beginning 0))
  4627. (setq hdmarker (org-agenda-new-marker)
  4628. tags (org-get-tags-at))
  4629. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4630. (setq head (or (match-string 1) ""))
  4631. (setq txt (org-agenda-format-item
  4632. (if inactivep org-agenda-inactive-leader nil)
  4633. head category tags timestr
  4634. remove-re)))
  4635. (setq priority (org-get-priority txt))
  4636. (org-add-props txt props
  4637. 'org-marker marker 'org-hd-marker hdmarker)
  4638. (org-add-props txt nil 'priority priority
  4639. 'org-category category 'date date
  4640. 'org-category-position org-category-pos
  4641. 'todo-state todo-state
  4642. 'type "timestamp")
  4643. (push txt ee))
  4644. (if org-agenda-skip-additional-timestamps-same-entry
  4645. (outline-next-heading)
  4646. (goto-char end-of-match))))
  4647. (nreverse ee)))
  4648. (defun org-agenda-get-sexps ()
  4649. "Return the sexp information for agenda display."
  4650. (require 'diary-lib)
  4651. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4652. 'mouse-face 'highlight
  4653. 'help-echo
  4654. (format "mouse-2 or RET jump to org file %s"
  4655. (abbreviate-file-name buffer-file-name))))
  4656. (regexp "^&?%%(")
  4657. marker category org-category-pos ee txt tags entry
  4658. result beg b sexp sexp-entry todo-state)
  4659. (goto-char (point-min))
  4660. (while (re-search-forward regexp nil t)
  4661. (catch :skip
  4662. (org-agenda-skip)
  4663. (setq beg (match-beginning 0))
  4664. (goto-char (1- (match-end 0)))
  4665. (setq b (point))
  4666. (forward-sexp 1)
  4667. (setq sexp (buffer-substring b (point)))
  4668. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4669. (org-trim (match-string 1))
  4670. ""))
  4671. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4672. (when result
  4673. (setq marker (org-agenda-new-marker beg)
  4674. category (org-get-category beg)
  4675. org-category-pos (get-text-property beg 'org-category-position)
  4676. todo-state (org-get-todo-state))
  4677. (dolist (r (if (stringp result)
  4678. (list result)
  4679. result)) ;; we expect a list here
  4680. (if (string-match "\\S-" r)
  4681. (setq txt r)
  4682. (setq txt "SEXP entry returned empty string"))
  4683. (setq txt (org-agenda-format-item
  4684. "" txt category tags 'time))
  4685. (org-add-props txt props 'org-marker marker)
  4686. (org-add-props txt nil
  4687. 'org-category category 'date date 'todo-state todo-state
  4688. 'org-category-position org-category-pos
  4689. 'type "sexp")
  4690. (push txt ee)))))
  4691. (nreverse ee)))
  4692. ;; Calendar sanity: define some functions that are independent of
  4693. ;; `calendar-date-style'.
  4694. ;; Normally I would like to use ISO format when calling the diary functions,
  4695. ;; but to make sure we still have Emacs 22 compatibility we bind
  4696. ;; also `european-calendar-style' and use european format
  4697. (defun org-anniversary (year month day &optional mark)
  4698. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4699. (org-no-warnings
  4700. (let ((calendar-date-style 'european) (european-calendar-style t))
  4701. (diary-anniversary day month year mark))))
  4702. (defun org-cyclic (N year month day &optional mark)
  4703. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4704. (org-no-warnings
  4705. (let ((calendar-date-style 'european) (european-calendar-style t))
  4706. (diary-cyclic N day month year mark))))
  4707. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4708. "Like `diary-block', but with fixed (ISO) order of arguments."
  4709. (org-no-warnings
  4710. (let ((calendar-date-style 'european) (european-calendar-style t))
  4711. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4712. (defun org-date (year month day &optional mark)
  4713. "Like `diary-date', but with fixed (ISO) order of arguments."
  4714. (org-no-warnings
  4715. (let ((calendar-date-style 'european) (european-calendar-style t))
  4716. (diary-date day month year mark))))
  4717. (defalias 'org-float 'diary-float)
  4718. ;; Define the` org-class' function
  4719. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4720. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4721. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4722. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4723. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4724. `holidays', then any date that is known by the Emacs calendar to be a
  4725. holiday will also be skipped."
  4726. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4727. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4728. (d (calendar-absolute-from-gregorian date)))
  4729. (and
  4730. (<= date1 d)
  4731. (<= d date2)
  4732. (= (calendar-day-of-week date) dayname)
  4733. (or (not skip-weeks)
  4734. (progn
  4735. (require 'cal-iso)
  4736. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4737. (not (and (memq 'holidays skip-weeks)
  4738. (calendar-check-holidays date)))
  4739. entry)))
  4740. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4741. "Like `org-class', but honor `calendar-date-style'.
  4742. The order of the first 2 times 3 arguments depends on the variable
  4743. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4744. So for American calendars, give this as MONTH DAY YEAR, for European as
  4745. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4746. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4747. is any number of ISO weeks in the block period for which the item should
  4748. be skipped.
  4749. This function is here only for backward compatibility and it is deprecated,
  4750. please use `org-class' instead."
  4751. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4752. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4753. (org-class
  4754. (nth 2 date1) (car date1) (nth 1 date1)
  4755. (nth 2 date2) (car date2) (nth 1 date2)
  4756. dayname skip-weeks)))
  4757. (make-obsolete 'org-diary-class 'org-class "")
  4758. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4759. (defalias 'org-get-closed 'org-agenda-get-progress)
  4760. (defun org-agenda-get-progress ()
  4761. "Return the logged TODO entries for agenda display."
  4762. (let* ((props (list 'mouse-face 'highlight
  4763. 'org-not-done-regexp org-not-done-regexp
  4764. 'org-todo-regexp org-todo-regexp
  4765. 'org-complex-heading-regexp org-complex-heading-regexp
  4766. 'help-echo
  4767. (format "mouse-2 or RET jump to org file %s"
  4768. (abbreviate-file-name buffer-file-name))))
  4769. (items (if (consp org-agenda-show-log-scoped)
  4770. org-agenda-show-log-scoped
  4771. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4772. '(clock)
  4773. org-agenda-log-mode-items)))
  4774. (parts
  4775. (delq nil
  4776. (list
  4777. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4778. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4779. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4780. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4781. (error "`org-agenda-log-mode-items' is empty")))
  4782. (regexp (concat
  4783. "\\(" parts-re "\\)"
  4784. " *\\["
  4785. (regexp-quote
  4786. (substring
  4787. (format-time-string
  4788. (car org-time-stamp-formats)
  4789. (apply 'encode-time ; DATE bound by calendar
  4790. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4791. 1 11))))
  4792. (org-agenda-search-headline-for-time nil)
  4793. marker hdmarker priority category org-category-pos tags closedp
  4794. statep clockp state ee txt extra timestr rest clocked)
  4795. (goto-char (point-min))
  4796. (while (re-search-forward regexp nil t)
  4797. (catch :skip
  4798. (org-agenda-skip)
  4799. (setq marker (org-agenda-new-marker (match-beginning 0))
  4800. closedp (equal (match-string 1) org-closed-string)
  4801. statep (equal (string-to-char (match-string 1)) ?-)
  4802. clockp (not (or closedp statep))
  4803. state (and statep (match-string 2))
  4804. category (org-get-category (match-beginning 0))
  4805. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4806. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4807. (when (string-match "\\]" timestr)
  4808. ;; substring should only run to end of time stamp
  4809. (setq rest (substring timestr (match-end 0))
  4810. timestr (substring timestr 0 (match-end 0)))
  4811. (if (and (not closedp) (not statep)
  4812. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4813. rest))
  4814. (progn (setq timestr (concat (substring timestr 0 -1)
  4815. "-" (match-string 1 rest) "]"))
  4816. (setq clocked (match-string 2 rest)))
  4817. (setq clocked "-")))
  4818. (save-excursion
  4819. (setq extra
  4820. (cond
  4821. ((not org-agenda-log-mode-add-notes) nil)
  4822. (statep
  4823. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4824. (match-string 1)))
  4825. (clockp
  4826. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4827. (match-string 1)))))
  4828. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4829. (setq txt org-agenda-no-heading-message)
  4830. (goto-char (match-beginning 0))
  4831. (setq hdmarker (org-agenda-new-marker)
  4832. tags (org-get-tags-at))
  4833. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4834. (setq txt (match-string 1))
  4835. (when extra
  4836. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4837. (setq txt (concat (substring txt 0 (match-beginning 1))
  4838. " - " extra " " (match-string 2 txt)))
  4839. (setq txt (concat txt " - " extra))))
  4840. (setq txt (org-agenda-format-item
  4841. (cond
  4842. (closedp "Closed: ")
  4843. (statep (concat "State: (" state ")"))
  4844. (t (concat "Clocked: (" clocked ")")))
  4845. txt category tags timestr)))
  4846. (setq priority 100000)
  4847. (org-add-props txt props
  4848. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4849. 'priority priority 'org-category category
  4850. 'org-category-position org-category-pos
  4851. 'type "closed" 'date date
  4852. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4853. (push txt ee))
  4854. (goto-char (point-at-eol))))
  4855. (nreverse ee)))
  4856. (defun org-agenda-show-clocking-issues ()
  4857. "Add overlays, showing issues with clocking.
  4858. See also the user option `org-agenda-clock-consistency-checks'."
  4859. (interactive)
  4860. (let* ((pl org-agenda-clock-consistency-checks)
  4861. (re (concat "^[ \t]*"
  4862. org-clock-string
  4863. "[ \t]+"
  4864. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4865. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4866. (tlstart 0.)
  4867. (tlend 0.)
  4868. (maxtime (org-hh:mm-string-to-minutes
  4869. (or (plist-get pl :max-duration) "24:00")))
  4870. (mintime (org-hh:mm-string-to-minutes
  4871. (or (plist-get pl :min-duration) 0)))
  4872. (maxgap (org-hh:mm-string-to-minutes
  4873. ;; default 30:00 means never complain
  4874. (or (plist-get pl :max-gap) "30:00")))
  4875. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4876. (plist-get pl :gap-ok-around)))
  4877. (def-face (or (plist-get pl :default-face)
  4878. '((:background "DarkRed") (:foreground "white"))))
  4879. issue face m te ts dt ov)
  4880. (goto-char (point-min))
  4881. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4882. (setq issue nil face def-face)
  4883. (catch 'next
  4884. (setq m (org-get-at-bol 'org-marker)
  4885. te nil ts nil)
  4886. (unless (and m (markerp m))
  4887. (setq issue "No valid clock line") (throw 'next t))
  4888. (org-with-point-at m
  4889. (save-excursion
  4890. (goto-char (point-at-bol))
  4891. (unless (looking-at re)
  4892. (error "No valid Clock line")
  4893. (throw 'next t))
  4894. (unless (match-end 3)
  4895. (setq issue "No end time"
  4896. face (or (plist-get pl :no-end-time-face) face))
  4897. (throw 'next t))
  4898. (setq ts (match-string 1)
  4899. te (match-string 3)
  4900. ts (org-float-time
  4901. (apply 'encode-time (org-parse-time-string ts)))
  4902. te (org-float-time
  4903. (apply 'encode-time (org-parse-time-string te)))
  4904. dt (- te ts))))
  4905. (cond
  4906. ((> dt (* 60 maxtime))
  4907. ;; a very long clocking chunk
  4908. (setq issue (format "Clocking interval is very long: %s"
  4909. (org-minutes-to-hh:mm-string
  4910. (floor (/ (float dt) 60.))))
  4911. face (or (plist-get pl :long-face) face)))
  4912. ((< dt (* 60 mintime))
  4913. ;; a very short clocking chunk
  4914. (setq issue (format "Clocking interval is very short: %s"
  4915. (org-minutes-to-hh:mm-string
  4916. (floor (/ (float dt) 60.))))
  4917. face (or (plist-get pl :short-face) face)))
  4918. ((and (> tlend 0) (< ts tlend))
  4919. ;; Two clock entries are overlapping
  4920. (setq issue (format "Clocking overlap: %d minutes"
  4921. (/ (- tlend ts) 60))
  4922. face (or (plist-get pl :overlap-face) face)))
  4923. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4924. ;; There is a gap, lets see if we need to report it
  4925. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4926. (setq issue (format "Clocking gap: %d minutes"
  4927. (/ (- ts tlend) 60))
  4928. face (or (plist-get pl :gap-face) face))))
  4929. (t nil)))
  4930. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4931. (when issue
  4932. ;; OK, there was some issue, add an overlay to show the issue
  4933. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4934. (overlay-put ov 'before-string
  4935. (concat
  4936. (org-add-props
  4937. (format "%-43s" (concat " " issue))
  4938. nil
  4939. 'face face)
  4940. "\n"))
  4941. (overlay-put ov 'evaporate t)))))
  4942. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4943. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4944. (catch 'exit
  4945. (unless ok-list
  4946. ;; there are no OK times for gaps...
  4947. (throw 'exit nil))
  4948. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4949. ;; This is more than 24 hours, so it is OK.
  4950. ;; because we have at least one OK time, that must be in the
  4951. ;; 24 hour interval.
  4952. (throw 'exit t))
  4953. ;; We have a shorter gap.
  4954. ;; Now we have to get the minute of the day when these times are
  4955. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4956. (t2dec (decode-time (seconds-to-time t2)))
  4957. ;; compute the minute on the day
  4958. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4959. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4960. (when (< min2 min1)
  4961. ;; if min2 is smaller than min1, this means it is on the next day.
  4962. ;; Wrap it to after midnight.
  4963. (setq min2 (+ min2 1440)))
  4964. ;; Now check if any of the OK times is in the gap
  4965. (mapc (lambda (x)
  4966. ;; Wrap the time to after midnight if necessary
  4967. (if (< x min1) (setq x (+ x 1440)))
  4968. ;; Check if in interval
  4969. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4970. ok-list)
  4971. ;; Nope, this gap is not OK
  4972. nil)))
  4973. (defun org-agenda-get-deadlines ()
  4974. "Return the deadline information for agenda display."
  4975. (let* ((props (list 'mouse-face 'highlight
  4976. 'org-not-done-regexp org-not-done-regexp
  4977. 'org-todo-regexp org-todo-regexp
  4978. 'org-complex-heading-regexp org-complex-heading-regexp
  4979. 'help-echo
  4980. (format "mouse-2 or RET jump to org file %s"
  4981. (abbreviate-file-name buffer-file-name))))
  4982. (regexp org-deadline-time-regexp)
  4983. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4984. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4985. d2 diff dfrac wdays pos pos1 category org-category-pos
  4986. tags suppress-prewarning ee txt head face s todo-state
  4987. show-all upcomingp donep timestr)
  4988. (goto-char (point-min))
  4989. (while (re-search-forward regexp nil t)
  4990. (setq suppress-prewarning nil)
  4991. (catch :skip
  4992. (org-agenda-skip)
  4993. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4994. (save-match-data
  4995. (string-match org-scheduled-time-regexp
  4996. (buffer-substring (point-at-bol)
  4997. (point-at-eol)))))
  4998. (setq suppress-prewarning
  4999. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5000. org-agenda-skip-deadline-prewarning-if-scheduled
  5001. 0)))
  5002. (setq s (match-string 1)
  5003. txt nil
  5004. pos (1- (match-beginning 1))
  5005. todo-state (save-match-data (org-get-todo-state))
  5006. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5007. (member todo-state
  5008. org-agenda-repeating-timestamp-show-all))
  5009. d2 (org-time-string-to-absolute
  5010. (match-string 1) d1 'past show-all
  5011. (current-buffer) pos)
  5012. diff (- d2 d1)
  5013. wdays (if suppress-prewarning
  5014. (let ((org-deadline-warning-days suppress-prewarning))
  5015. (org-get-wdays s))
  5016. (org-get-wdays s))
  5017. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5018. upcomingp (and todayp (> diff 0)))
  5019. ;; When to show a deadline in the calendar:
  5020. ;; If the expiration is within wdays warning time.
  5021. ;; Past-due deadlines are only shown on the current date
  5022. (if (and (or (and (<= diff wdays)
  5023. (and todayp (not org-agenda-only-exact-dates)))
  5024. (= diff 0)))
  5025. (save-excursion
  5026. ;; (setq todo-state (org-get-todo-state))
  5027. (setq donep (member todo-state org-done-keywords))
  5028. (if (and donep
  5029. (or org-agenda-skip-deadline-if-done
  5030. (not (= diff 0))))
  5031. (setq txt nil)
  5032. (setq category (org-get-category)
  5033. org-category-pos (get-text-property (point) 'org-category-position))
  5034. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5035. (setq txt org-agenda-no-heading-message)
  5036. (goto-char (match-end 0))
  5037. (setq pos1 (match-beginning 0))
  5038. (setq tags (org-get-tags-at pos1))
  5039. (setq head (buffer-substring-no-properties
  5040. (point)
  5041. (progn (skip-chars-forward "^\r\n")
  5042. (point))))
  5043. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5044. (setq timestr
  5045. (concat (substring s (match-beginning 1)) " "))
  5046. (setq timestr 'time))
  5047. (setq txt (org-agenda-format-item
  5048. (if (= diff 0)
  5049. (car org-agenda-deadline-leaders)
  5050. (if (functionp
  5051. (nth 1 org-agenda-deadline-leaders))
  5052. (funcall
  5053. (nth 1 org-agenda-deadline-leaders)
  5054. diff date)
  5055. (format (nth 1 org-agenda-deadline-leaders)
  5056. diff)))
  5057. head category tags
  5058. (if (not (= diff 0)) nil timestr)))))
  5059. (when txt
  5060. (setq face (org-agenda-deadline-face dfrac))
  5061. (org-add-props txt props
  5062. 'org-marker (org-agenda-new-marker pos)
  5063. 'org-hd-marker (org-agenda-new-marker pos1)
  5064. 'priority (+ (- diff)
  5065. (org-get-priority txt))
  5066. 'org-category category
  5067. 'org-category-position org-category-pos
  5068. 'todo-state todo-state
  5069. 'type (if upcomingp "upcoming-deadline" "deadline")
  5070. 'date (if upcomingp date d2)
  5071. 'face (if donep 'org-agenda-done face)
  5072. 'undone-face face 'done-face 'org-agenda-done)
  5073. (push txt ee))))))
  5074. (nreverse ee)))
  5075. (defun org-agenda-deadline-face (fraction)
  5076. "Return the face to displaying a deadline item.
  5077. FRACTION is what fraction of the head-warning time has passed."
  5078. (let ((faces org-agenda-deadline-faces) f)
  5079. (catch 'exit
  5080. (while (setq f (pop faces))
  5081. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5082. (defun org-agenda-get-scheduled (&optional deadline-results)
  5083. "Return the scheduled information for agenda display."
  5084. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5085. 'org-todo-regexp org-todo-regexp
  5086. 'org-complex-heading-regexp org-complex-heading-regexp
  5087. 'done-face 'org-agenda-done
  5088. 'mouse-face 'highlight
  5089. 'help-echo
  5090. (format "mouse-2 or RET jump to org file %s"
  5091. (abbreviate-file-name buffer-file-name))))
  5092. (regexp org-scheduled-time-regexp)
  5093. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5094. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5095. mm
  5096. (deadline-position-alist
  5097. (mapcar (lambda (a) (and (setq mm (get-text-property
  5098. 0 'org-hd-marker a))
  5099. (cons (marker-position mm) a)))
  5100. deadline-results))
  5101. d2 diff pos pos1 category org-category-pos tags donep
  5102. ee txt head pastschedp todo-state face timestr s habitp show-all)
  5103. (goto-char (point-min))
  5104. (while (re-search-forward regexp nil t)
  5105. (catch :skip
  5106. (org-agenda-skip)
  5107. (setq s (match-string 1)
  5108. txt nil
  5109. pos (1- (match-beginning 1))
  5110. todo-state (save-match-data (org-get-todo-state))
  5111. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5112. (member todo-state
  5113. org-agenda-repeating-timestamp-show-all))
  5114. d2 (org-time-string-to-absolute
  5115. (match-string 1) d1 'past show-all
  5116. (current-buffer) pos)
  5117. diff (- d2 d1))
  5118. (setq pastschedp (and todayp (< diff 0)))
  5119. ;; When to show a scheduled item in the calendar:
  5120. ;; If it is on or past the date.
  5121. (when (or (and (< diff 0)
  5122. (< (abs diff) org-scheduled-past-days)
  5123. (and todayp (not org-agenda-only-exact-dates)))
  5124. (= diff 0))
  5125. (save-excursion
  5126. (setq donep (member todo-state org-done-keywords))
  5127. (if (and donep
  5128. (or org-agenda-skip-scheduled-if-done
  5129. (not (= diff 0))
  5130. (and (functionp 'org-is-habit-p)
  5131. (org-is-habit-p))))
  5132. (setq txt nil)
  5133. (setq habitp (and (functionp 'org-is-habit-p)
  5134. (org-is-habit-p)))
  5135. (setq category (org-get-category)
  5136. org-category-pos (get-text-property (point) 'org-category-position))
  5137. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5138. (setq txt org-agenda-no-heading-message)
  5139. (goto-char (match-end 0))
  5140. (setq pos1 (match-beginning 0))
  5141. (if habitp
  5142. (if (or (not org-habit-show-habits)
  5143. (and (not todayp)
  5144. org-habit-show-habits-only-for-today))
  5145. (throw :skip nil))
  5146. (if (and
  5147. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5148. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5149. pastschedp))
  5150. (setq mm (assoc pos1 deadline-position-alist)))
  5151. (throw :skip nil)))
  5152. (setq tags (org-get-tags-at))
  5153. (setq head (buffer-substring-no-properties
  5154. (point)
  5155. (progn (skip-chars-forward "^\r\n") (point))))
  5156. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5157. (setq timestr
  5158. (concat (substring s (match-beginning 1)) " "))
  5159. (setq timestr 'time))
  5160. (setq txt (org-agenda-format-item
  5161. (if (= diff 0)
  5162. (car org-agenda-scheduled-leaders)
  5163. (format (nth 1 org-agenda-scheduled-leaders)
  5164. (- 1 diff)))
  5165. head category tags
  5166. (if (not (= diff 0)) nil timestr)
  5167. nil habitp))))
  5168. (when txt
  5169. (setq face
  5170. (cond
  5171. ((and (not habitp) pastschedp)
  5172. 'org-scheduled-previously)
  5173. (todayp 'org-scheduled-today)
  5174. (t 'org-scheduled))
  5175. habitp (and habitp (org-habit-parse-todo)))
  5176. (org-add-props txt props
  5177. 'undone-face face
  5178. 'face (if donep 'org-agenda-done face)
  5179. 'org-marker (org-agenda-new-marker pos)
  5180. 'org-hd-marker (org-agenda-new-marker pos1)
  5181. 'type (if pastschedp "past-scheduled" "scheduled")
  5182. 'date (if pastschedp d2 date)
  5183. 'priority (if habitp
  5184. (org-habit-get-priority habitp)
  5185. (+ 94 (- 5 diff) (org-get-priority txt)))
  5186. 'org-category category
  5187. 'org-category-position org-category-pos
  5188. 'org-habit-p habitp
  5189. 'todo-state todo-state)
  5190. (push txt ee))))))
  5191. (nreverse ee)))
  5192. (defun org-agenda-get-blocks ()
  5193. "Return the date-range information for agenda display."
  5194. (let* ((props (list 'face nil
  5195. 'org-not-done-regexp org-not-done-regexp
  5196. 'org-todo-regexp org-todo-regexp
  5197. 'org-complex-heading-regexp org-complex-heading-regexp
  5198. 'mouse-face 'highlight
  5199. 'help-echo
  5200. (format "mouse-2 or RET jump to org file %s"
  5201. (abbreviate-file-name buffer-file-name))))
  5202. (regexp org-tr-regexp)
  5203. (d0 (calendar-absolute-from-gregorian date))
  5204. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5205. todo-state tags pos head donep)
  5206. (goto-char (point-min))
  5207. (while (re-search-forward regexp nil t)
  5208. (catch :skip
  5209. (org-agenda-skip)
  5210. (setq pos (point))
  5211. (let ((start-time (match-string 1))
  5212. (end-time (match-string 2)))
  5213. (setq s1 (match-string 1)
  5214. s2 (match-string 2)
  5215. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5216. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5217. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5218. ;; Only allow days between the limits, because the normal
  5219. ;; date stamps will catch the limits.
  5220. (save-excursion
  5221. (setq todo-state (org-get-todo-state))
  5222. (setq donep (member todo-state org-done-keywords))
  5223. (if (and donep org-agenda-skip-timestamp-if-done)
  5224. (throw :skip t))
  5225. (setq marker (org-agenda-new-marker (point)))
  5226. (setq category (org-get-category)
  5227. org-category-pos (get-text-property (point) 'org-category-position))
  5228. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5229. (setq txt org-agenda-no-heading-message)
  5230. (goto-char (match-beginning 0))
  5231. (setq hdmarker (org-agenda-new-marker (point)))
  5232. (setq tags (org-get-tags-at))
  5233. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5234. (setq head (match-string 1))
  5235. (let ((remove-re
  5236. (if org-agenda-remove-timeranges-from-blocks
  5237. (concat
  5238. "<" (regexp-quote s1) ".*?>"
  5239. "--"
  5240. "<" (regexp-quote s2) ".*?>")
  5241. nil)))
  5242. (setq txt (org-agenda-format-item
  5243. (format
  5244. (nth (if (= d1 d2) 0 1)
  5245. org-agenda-timerange-leaders)
  5246. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5247. head category tags
  5248. (cond ((and (= d1 d0) (= d2 d0))
  5249. (concat "<" start-time ">--<" end-time ">"))
  5250. ((= d1 d0)
  5251. (concat "<" start-time ">"))
  5252. ((= d2 d0)
  5253. (concat "<" end-time ">"))
  5254. (t nil))
  5255. remove-re))))
  5256. (org-add-props txt props
  5257. 'org-marker marker 'org-hd-marker hdmarker
  5258. 'type "block" 'date date
  5259. 'todo-state todo-state
  5260. 'priority (org-get-priority txt) 'org-category category
  5261. 'org-category-position org-category-pos)
  5262. (push txt ee))))
  5263. (goto-char pos)))
  5264. ;; Sort the entries by expiration date.
  5265. (nreverse ee)))
  5266. ;;; Agenda presentation and sorting
  5267. (defvar org-prefix-has-time nil
  5268. "A flag, set by `org-compile-prefix-format'.
  5269. The flag is set if the currently compiled format contains a `%t'.")
  5270. (defvar org-prefix-has-tag nil
  5271. "A flag, set by `org-compile-prefix-format'.
  5272. The flag is set if the currently compiled format contains a `%T'.")
  5273. (defvar org-prefix-has-effort nil
  5274. "A flag, set by `org-compile-prefix-format'.
  5275. The flag is set if the currently compiled format contains a `%e'.")
  5276. (defvar org-prefix-category-length nil
  5277. "Used by `org-compile-prefix-format' to remember the category field width.")
  5278. (defvar org-prefix-category-max-length nil
  5279. "Used by `org-compile-prefix-format' to remember the category field width.")
  5280. (defun org-agenda-get-category-icon (category)
  5281. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5282. (dolist (entry org-agenda-category-icon-alist)
  5283. (when (org-string-match-p (car entry) category)
  5284. (if (listp (cadr entry))
  5285. (return (cadr entry))
  5286. (return (apply 'create-image (cdr entry)))))))
  5287. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5288. remove-re habitp)
  5289. "Format TXT to be inserted into the agenda buffer.
  5290. In particular, it adds the prefix and corresponding text properties. EXTRA
  5291. must be a string and replaces the `%s' specifier in the prefix format.
  5292. CATEGORY (string, symbol or nil) may be used to overrule the default
  5293. category taken from local variable or file name. It will replace the `%c'
  5294. specifier in the format. DOTIME, when non-nil, indicates that a
  5295. time-of-day should be extracted from TXT for sorting of this entry, and for
  5296. the `%t' specifier in the format. When DOTIME is a string, this string is
  5297. searched for a time before TXT is. TAGS can be the tags of the headline.
  5298. Any match of REMOVE-RE will be removed from TXT."
  5299. ;; We keep the org-prefix-* variable values along with a compiled
  5300. ;; formatter, so that multiple agendas existing at the same time, do
  5301. ;; not step on each other toes.
  5302. ;;
  5303. ;; It was inconvenient to make these variables buffer local in
  5304. ;; Agenda buffers, because this function expects to be called with
  5305. ;; the buffer where item comes from being current, and not agenda
  5306. ;; buffer
  5307. (let* ((bindings (car org-prefix-format-compiled))
  5308. (formatter (cadr org-prefix-format-compiled)))
  5309. (loop for (var value) in bindings
  5310. do (set var value))
  5311. (save-match-data
  5312. ;; Diary entries sometimes have extra whitespace at the beginning
  5313. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5314. ;; Fix the tags part in txt
  5315. (setq txt (org-agenda-fix-displayed-tags
  5316. txt tags
  5317. org-agenda-show-inherited-tags
  5318. org-agenda-hide-tags-regexp))
  5319. (let* ((category (or category
  5320. (if (stringp org-category)
  5321. org-category
  5322. (and org-category (symbol-name org-category)))
  5323. (if buffer-file-name
  5324. (file-name-sans-extension
  5325. (file-name-nondirectory buffer-file-name))
  5326. "")))
  5327. (category-icon (org-agenda-get-category-icon category))
  5328. (category-icon (if category-icon
  5329. (propertize " " 'display category-icon)
  5330. ""))
  5331. ;; time, tag, effort are needed for the eval of the prefix format
  5332. (tag (if tags (nth (1- (length tags)) tags) ""))
  5333. time effort neffort
  5334. (ts (if dotime (concat
  5335. (if (stringp dotime) dotime "")
  5336. (and org-agenda-search-headline-for-time txt))))
  5337. (time-of-day (and dotime (org-get-time-of-day ts)))
  5338. stamp plain s0 s1 s2 rtn srp l
  5339. duration thecategory)
  5340. (and (derived-mode-p 'org-mode) buffer-file-name
  5341. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5342. (when (and dotime time-of-day)
  5343. ;; Extract starting and ending time and move them to prefix
  5344. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5345. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5346. (setq s0 (match-string 0 ts)
  5347. srp (and stamp (match-end 3))
  5348. s1 (match-string (if plain 1 2) ts)
  5349. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5350. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5351. ;; them, we might want to remove them there to avoid duplication.
  5352. ;; The user can turn this off with a variable.
  5353. (if (and org-prefix-has-time
  5354. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5355. (string-match (concat (regexp-quote s0) " *") txt)
  5356. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5357. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5358. (= (match-beginning 0) 0)
  5359. t))
  5360. (setq txt (replace-match "" nil nil txt))))
  5361. ;; Normalize the time(s) to 24 hour
  5362. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5363. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5364. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5365. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5366. (setq s2
  5367. (org-minutes-to-hh:mm-string
  5368. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5369. ;; Compute the duration
  5370. (when s2
  5371. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5372. (org-hh:mm-string-to-minutes s1)))))
  5373. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5374. txt)
  5375. ;; Tags are in the string
  5376. (if (or (eq org-agenda-remove-tags t)
  5377. (and org-agenda-remove-tags
  5378. org-prefix-has-tag))
  5379. (setq txt (replace-match "" t t txt))
  5380. (setq txt (replace-match
  5381. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5382. (match-string 2 txt))
  5383. t t txt))))
  5384. (when (derived-mode-p 'org-mode)
  5385. (setq effort
  5386. (condition-case nil
  5387. (org-get-effort
  5388. (or (get-text-property 0 'org-hd-marker txt)
  5389. (get-text-property 0 'org-marker txt)))
  5390. (error nil)))
  5391. (when effort
  5392. (setq neffort (org-duration-string-to-minutes effort)
  5393. effort (setq effort (concat "[" effort "]")))))
  5394. ;; prevent erroring out with %e format when there is no effort
  5395. (or effort (setq effort ""))
  5396. (when remove-re
  5397. (while (string-match remove-re txt)
  5398. (setq txt (replace-match "" t t txt))))
  5399. ;; Set org-heading property on `txt' to mark the start of the
  5400. ;; heading.
  5401. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5402. ;; Prepare the variables needed in the eval of the compiled format
  5403. (setq time (cond (s2 (concat
  5404. (org-agenda-time-of-day-to-ampm-maybe s1)
  5405. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5406. (if org-agenda-timegrid-use-ampm " ")))
  5407. (s1 (concat
  5408. (org-agenda-time-of-day-to-ampm-maybe s1)
  5409. (if org-agenda-timegrid-use-ampm
  5410. "........ "
  5411. "......")))
  5412. (t ""))
  5413. extra (or (and (not habitp) extra) "")
  5414. category (if (symbolp category) (symbol-name category) category)
  5415. thecategory (copy-sequence category))
  5416. (if (string-match org-bracket-link-regexp category)
  5417. (progn
  5418. (setq l (if (match-end 3)
  5419. (- (match-end 3) (match-beginning 3))
  5420. (- (match-end 1) (match-beginning 1))))
  5421. (when (< l (or org-prefix-category-length 0))
  5422. (setq category (copy-sequence category))
  5423. (org-add-props category nil
  5424. 'extra-space (make-string
  5425. (- org-prefix-category-length l 1) ?\ ))))
  5426. (if (and org-prefix-category-max-length
  5427. (>= (length category) org-prefix-category-max-length))
  5428. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5429. ;; Evaluate the compiled format
  5430. (setq rtn (concat (eval formatter) txt))
  5431. ;; And finally add the text properties
  5432. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5433. (org-add-props rtn nil
  5434. 'org-category (if thecategory (downcase thecategory) category)
  5435. 'tags (mapcar 'org-downcase-keep-props tags)
  5436. 'org-highest-priority org-highest-priority
  5437. 'org-lowest-priority org-lowest-priority
  5438. 'time-of-day time-of-day
  5439. 'duration duration
  5440. 'effort effort
  5441. 'effort-minutes neffort
  5442. 'txt txt
  5443. 'time time
  5444. 'extra extra
  5445. 'format org-prefix-format-compiled
  5446. 'dotime dotime)))))
  5447. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5448. "Remove tags string from TXT, and add a modified list of tags.
  5449. The modified list may contain inherited tags, and tags matched by
  5450. `org-agenda-hide-tags-regexp' will be removed."
  5451. (when (or add-inherited hide-re)
  5452. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5453. (setq txt (substring txt 0 (match-beginning 0))))
  5454. (setq tags
  5455. (delq nil
  5456. (mapcar (lambda (tg)
  5457. (if (or (and hide-re (string-match hide-re tg))
  5458. (and (not add-inherited)
  5459. (get-text-property 0 'inherited tg)))
  5460. nil
  5461. tg))
  5462. tags)))
  5463. (when tags
  5464. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5465. i)
  5466. (setq txt (concat txt " :"
  5467. (mapconcat
  5468. (lambda (x)
  5469. (setq i (get-text-property 0 'inherited x))
  5470. (if (and have-i (not i))
  5471. (progn
  5472. (setq have-i nil)
  5473. (concat ":" x))
  5474. x))
  5475. tags ":")
  5476. (if have-i "::" ":"))))))
  5477. txt)
  5478. (defun org-downcase-keep-props (s)
  5479. (let ((props (text-properties-at 0 s)))
  5480. (setq s (downcase s))
  5481. (add-text-properties 0 (length s) props s)
  5482. s))
  5483. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5484. (defvar org-agenda-sorting-strategy-selected nil)
  5485. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5486. (catch 'exit
  5487. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5488. ((and todayp (member 'today (car org-agenda-time-grid))))
  5489. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5490. ((member 'weekly (car org-agenda-time-grid)))
  5491. (t (throw 'exit list)))
  5492. (let* ((have (delq nil (mapcar
  5493. (lambda (x) (get-text-property 1 'time-of-day x))
  5494. list)))
  5495. (string (nth 1 org-agenda-time-grid))
  5496. (gridtimes (nth 2 org-agenda-time-grid))
  5497. (req (car org-agenda-time-grid))
  5498. (remove (member 'remove-match req))
  5499. new time)
  5500. (if (and (member 'require-timed req) (not have))
  5501. ;; don't show empty grid
  5502. (throw 'exit list))
  5503. (while (setq time (pop gridtimes))
  5504. (unless (and remove (member time have))
  5505. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5506. (push (org-agenda-format-item
  5507. nil string "" nil
  5508. (concat (substring time 0 -2) ":" (substring time -2)))
  5509. new)
  5510. (put-text-property
  5511. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5512. (when (and todayp org-agenda-show-current-time-in-grid)
  5513. (push (org-agenda-format-item
  5514. nil
  5515. org-agenda-current-time-string
  5516. "" nil
  5517. (format-time-string "%H:%M "))
  5518. new)
  5519. (put-text-property
  5520. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5521. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5522. (append new list)
  5523. (append list new)))))
  5524. (defun org-compile-prefix-format (key)
  5525. "Compile the prefix format into a Lisp form that can be evaluated.
  5526. The resulting form and associated variable bindings is returned
  5527. and stored in the variable `org-prefix-format-compiled'."
  5528. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5529. org-prefix-category-length nil
  5530. org-prefix-has-effort nil)
  5531. (let ((s (cond
  5532. ((stringp org-agenda-prefix-format)
  5533. org-agenda-prefix-format)
  5534. ((assq key org-agenda-prefix-format)
  5535. (cdr (assq key org-agenda-prefix-format)))
  5536. (t " %-12:c%?-12t% s")))
  5537. (start 0)
  5538. varform vars var e c f opt)
  5539. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5540. s start)
  5541. (setq var (or (cdr (assoc (match-string 4 s)
  5542. '(("c" . category) ("t" . time) ("s" . extra)
  5543. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5544. 'eval)
  5545. c (or (match-string 3 s) "")
  5546. opt (match-beginning 1)
  5547. start (1+ (match-beginning 0)))
  5548. (if (equal var 'time) (setq org-prefix-has-time t))
  5549. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5550. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5551. (setq f (concat "%" (match-string 2 s) "s"))
  5552. (when (equal var 'category)
  5553. (setq org-prefix-category-length
  5554. (floor (abs (string-to-number (match-string 2 s)))))
  5555. (setq org-prefix-category-max-length
  5556. (let ((x (match-string 2 s)))
  5557. (save-match-data
  5558. (if (string-match "\\.[0-9]+" x)
  5559. (string-to-number (substring (match-string 0 x) 1)))))))
  5560. (if (eq var 'eval)
  5561. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5562. (if opt
  5563. (setq varform
  5564. `(if (equal "" ,var)
  5565. ""
  5566. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5567. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5568. (setq s (replace-match "%s" t nil s))
  5569. (push varform vars))
  5570. (setq vars (nreverse vars))
  5571. (with-current-buffer org-agenda-buffer
  5572. (setq org-prefix-format-compiled
  5573. (list
  5574. `((org-prefix-has-time ,org-prefix-has-time)
  5575. (org-prefix-has-tag ,org-prefix-has-tag)
  5576. (org-prefix-category-length ,org-prefix-category-length)
  5577. (org-prefix-has-effort ,org-prefix-has-effort))
  5578. `(format ,s ,@vars))))))
  5579. (defun org-set-sorting-strategy (key)
  5580. (if (symbolp (car org-agenda-sorting-strategy))
  5581. ;; the old format
  5582. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5583. (setq org-agenda-sorting-strategy-selected
  5584. (or (cdr (assq key org-agenda-sorting-strategy))
  5585. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5586. '(time-up category-keep priority-down)))))
  5587. (defun org-get-time-of-day (s &optional string mod24)
  5588. "Check string S for a time of day.
  5589. If found, return it as a military time number between 0 and 2400.
  5590. If not found, return nil.
  5591. The optional STRING argument forces conversion into a 5 character wide string
  5592. HH:MM."
  5593. (save-match-data
  5594. (when
  5595. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5596. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5597. (let* ((h (string-to-number (match-string 1 s)))
  5598. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5599. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5600. (am-p (equal ampm "am"))
  5601. (h1 (cond ((not ampm) h)
  5602. ((= h 12) (if am-p 0 12))
  5603. (t (+ h (if am-p 0 12)))))
  5604. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5605. (mod h1 24) h1))
  5606. (t0 (+ (* 100 h2) m))
  5607. (t1 (concat (if (>= h1 24) "+" " ")
  5608. (if (and org-agenda-time-leading-zero
  5609. (< t0 1000)) "0" "")
  5610. (if (< t0 100) "0" "")
  5611. (if (< t0 10) "0" "")
  5612. (int-to-string t0))))
  5613. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5614. (defvar org-agenda-before-sorting-filter-function nil
  5615. "Function to be applied to agenda items prior to sorting.
  5616. Prior to sorting also means just before they are inserted into the agenda.
  5617. To aid sorting, you may revisit the original entries and add more text
  5618. properties which will later be used by the sorting functions.
  5619. The function should take a string argument, an agenda line.
  5620. It has access to the text properties in that line, which contain among
  5621. other things, the property `org-hd-marker' that points to the entry
  5622. where the line comes from. Note that not all lines going into the agenda
  5623. have this property, only most.
  5624. The function should return the modified string. It is probably best
  5625. to ONLY change text properties.
  5626. You can also use this function as a filter, by returning nil for lines
  5627. you don't want to have in the agenda at all. For this application, you
  5628. could bind the variable in the options section of a custom command.")
  5629. (defun org-finalize-agenda-entries (list &optional nosort)
  5630. "Sort and concatenate the agenda items."
  5631. (setq list (mapcar 'org-agenda-highlight-todo list))
  5632. (if nosort
  5633. list
  5634. (when org-agenda-before-sorting-filter-function
  5635. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5636. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5637. (defun org-agenda-highlight-todo (x)
  5638. (let ((org-done-keywords org-done-keywords-for-agenda)
  5639. (case-fold-search nil)
  5640. re)
  5641. (if (eq x 'line)
  5642. (save-excursion
  5643. (beginning-of-line 1)
  5644. (setq re (org-get-at-bol 'org-todo-regexp))
  5645. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5646. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5647. (add-text-properties (match-beginning 0) (match-end 1)
  5648. (list 'face (org-get-todo-face 1)))
  5649. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5650. (delete-region (match-beginning 1) (1- (match-end 0)))
  5651. (goto-char (match-beginning 1))
  5652. (insert (format org-agenda-todo-keyword-format s)))))
  5653. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5654. (setq re (get-text-property 0 'org-todo-regexp x))
  5655. (when (and re
  5656. ;; Test `pl' because if there's no heading content,
  5657. ;; there's no point matching to highlight. Note
  5658. ;; that if we didn't test `pl' first, and there
  5659. ;; happened to be no keyword from `org-todo-regexp'
  5660. ;; on this heading line, then the `equal' comparison
  5661. ;; afterwards would spuriously succeed in the case
  5662. ;; where `pl' is nil -- causing an args-out-of-range
  5663. ;; error when we try to add text properties to text
  5664. ;; that isn't there.
  5665. pl
  5666. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5667. x pl) pl))
  5668. (add-text-properties
  5669. (or (match-end 1) (match-end 0)) (match-end 0)
  5670. (list 'face (org-get-todo-face (match-string 2 x)))
  5671. x)
  5672. (when (match-end 1)
  5673. (setq x (concat (substring x 0 (match-end 1))
  5674. (format org-agenda-todo-keyword-format
  5675. (match-string 2 x))
  5676. (org-add-props " " (text-properties-at 0 x))
  5677. (substring x (match-end 3)))))))
  5678. x)))
  5679. (defsubst org-cmp-priority (a b)
  5680. "Compare the priorities of string A and B."
  5681. (let ((pa (or (get-text-property 1 'priority a) 0))
  5682. (pb (or (get-text-property 1 'priority b) 0)))
  5683. (cond ((> pa pb) +1)
  5684. ((< pa pb) -1)
  5685. (t nil))))
  5686. (defsubst org-cmp-effort (a b)
  5687. "Compare the effort values of string A and B."
  5688. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5689. (ea (or (get-text-property 1 'effort-minutes a) def))
  5690. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5691. (cond ((> ea eb) +1)
  5692. ((< ea eb) -1)
  5693. (t nil))))
  5694. (defsubst org-cmp-category (a b)
  5695. "Compare the string values of categories of strings A and B."
  5696. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5697. (cb (or (get-text-property 1 'org-category b) "")))
  5698. (cond ((string-lessp ca cb) -1)
  5699. ((string-lessp cb ca) +1)
  5700. (t nil))))
  5701. (defsubst org-cmp-todo-state (a b)
  5702. "Compare the todo states of strings A and B."
  5703. (let* ((ma (or (get-text-property 1 'org-marker a)
  5704. (get-text-property 1 'org-hd-marker a)))
  5705. (mb (or (get-text-property 1 'org-marker b)
  5706. (get-text-property 1 'org-hd-marker b)))
  5707. (fa (and ma (marker-buffer ma)))
  5708. (fb (and mb (marker-buffer mb)))
  5709. (todo-kwds
  5710. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5711. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5712. (ta (or (get-text-property 1 'todo-state a) ""))
  5713. (tb (or (get-text-property 1 'todo-state b) ""))
  5714. (la (- (length (member ta todo-kwds))))
  5715. (lb (- (length (member tb todo-kwds))))
  5716. (donepa (member ta org-done-keywords-for-agenda))
  5717. (donepb (member tb org-done-keywords-for-agenda)))
  5718. (cond ((and donepa (not donepb)) -1)
  5719. ((and (not donepa) donepb) +1)
  5720. ((< la lb) -1)
  5721. ((< lb la) +1)
  5722. (t nil))))
  5723. (defsubst org-cmp-alpha (a b)
  5724. "Compare the headlines, alphabetically."
  5725. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5726. (plb (text-property-any 0 (length b) 'org-heading t b))
  5727. (ta (and pla (substring a pla)))
  5728. (tb (and plb (substring b plb))))
  5729. (when pla
  5730. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5731. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5732. (setq ta (substring ta (match-end 0))))
  5733. (setq ta (downcase ta)))
  5734. (when plb
  5735. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5736. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5737. (setq tb (substring tb (match-end 0))))
  5738. (setq tb (downcase tb)))
  5739. (cond ((not ta) +1)
  5740. ((not tb) -1)
  5741. ((string-lessp ta tb) -1)
  5742. ((string-lessp tb ta) +1)
  5743. (t nil))))
  5744. (defsubst org-cmp-tag (a b)
  5745. "Compare the string values of the first tags of A and B."
  5746. (let ((ta (car (last (get-text-property 1 'tags a))))
  5747. (tb (car (last (get-text-property 1 'tags b)))))
  5748. (cond ((not ta) +1)
  5749. ((not tb) -1)
  5750. ((string-lessp ta tb) -1)
  5751. ((string-lessp tb ta) +1)
  5752. (t nil))))
  5753. (defsubst org-cmp-time (a b)
  5754. "Compare the time-of-day values of strings A and B."
  5755. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5756. (ta (or (get-text-property 1 'time-of-day a) def))
  5757. (tb (or (get-text-property 1 'time-of-day b) def)))
  5758. (cond ((< ta tb) -1)
  5759. ((< tb ta) +1)
  5760. (t nil))))
  5761. (defsubst org-cmp-habit-p (a b)
  5762. "Compare the todo states of strings A and B."
  5763. (let ((ha (get-text-property 1 'org-habit-p a))
  5764. (hb (get-text-property 1 'org-habit-p b)))
  5765. (cond ((and ha (not hb)) -1)
  5766. ((and (not ha) hb) +1)
  5767. (t nil))))
  5768. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5769. (defun org-entries-lessp (a b)
  5770. "Predicate for sorting agenda entries."
  5771. ;; The following variables will be used when the form is evaluated.
  5772. ;; So even though the compiler complains, keep them.
  5773. (let* ((ss org-agenda-sorting-strategy-selected)
  5774. (time-up (and (org-em 'time-up 'time-down ss)
  5775. (org-cmp-time a b)))
  5776. (time-down (if time-up (- time-up) nil))
  5777. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5778. (org-cmp-priority a b)))
  5779. (priority-down (if priority-up (- priority-up) nil))
  5780. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5781. (org-cmp-effort a b)))
  5782. (effort-down (if effort-up (- effort-up) nil))
  5783. (category-up (and (or (org-em 'category-up 'category-down ss)
  5784. (memq 'category-keep ss))
  5785. (org-cmp-category a b)))
  5786. (category-down (if category-up (- category-up) nil))
  5787. (category-keep (if category-up +1 nil))
  5788. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5789. (org-cmp-tag a b)))
  5790. (tag-down (if tag-up (- tag-up) nil))
  5791. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5792. (org-cmp-todo-state a b)))
  5793. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5794. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5795. (org-cmp-habit-p a b)))
  5796. (habit-down (if habit-up (- habit-up) nil))
  5797. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5798. (org-cmp-alpha a b)))
  5799. (alpha-down (if alpha-up (- alpha-up) nil))
  5800. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5801. user-defined-up user-defined-down)
  5802. (if (and need-user-cmp org-agenda-cmp-user-defined
  5803. (functionp org-agenda-cmp-user-defined))
  5804. (setq user-defined-up
  5805. (funcall org-agenda-cmp-user-defined a b)
  5806. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5807. (cdr (assoc
  5808. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5809. '((-1 . t) (1 . nil) (nil . nil))))))
  5810. ;;; Agenda restriction lock
  5811. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5812. "Overlay to mark the headline to which agenda commands are restricted.")
  5813. (overlay-put org-agenda-restriction-lock-overlay
  5814. 'face 'org-agenda-restriction-lock)
  5815. (overlay-put org-agenda-restriction-lock-overlay
  5816. 'help-echo "Agendas are currently limited to this subtree.")
  5817. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5818. (defun org-agenda-set-restriction-lock (&optional type)
  5819. "Set restriction lock for agenda, to current subtree or file.
  5820. Restriction will be the file if TYPE is `file', or if type is the
  5821. universal prefix '(4), or if the cursor is before the first headline
  5822. in the file. Otherwise, restriction will be to the current subtree."
  5823. (interactive "P")
  5824. (and (equal type '(4)) (setq type 'file))
  5825. (setq type (cond
  5826. (type type)
  5827. ((org-at-heading-p) 'subtree)
  5828. ((condition-case nil (org-back-to-heading t) (error nil))
  5829. 'subtree)
  5830. (t 'file)))
  5831. (if (eq type 'subtree)
  5832. (progn
  5833. (setq org-agenda-restrict t)
  5834. (setq org-agenda-overriding-restriction 'subtree)
  5835. (put 'org-agenda-files 'org-restrict
  5836. (list (buffer-file-name (buffer-base-buffer))))
  5837. (org-back-to-heading t)
  5838. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5839. (move-marker org-agenda-restrict-begin (point))
  5840. (move-marker org-agenda-restrict-end
  5841. (save-excursion (org-end-of-subtree t)))
  5842. (message "Locking agenda restriction to subtree"))
  5843. (put 'org-agenda-files 'org-restrict
  5844. (list (buffer-file-name (buffer-base-buffer))))
  5845. (setq org-agenda-restrict nil)
  5846. (setq org-agenda-overriding-restriction 'file)
  5847. (move-marker org-agenda-restrict-begin nil)
  5848. (move-marker org-agenda-restrict-end nil)
  5849. (message "Locking agenda restriction to file"))
  5850. (setq current-prefix-arg nil)
  5851. (org-agenda-maybe-redo))
  5852. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5853. "Remove the agenda restriction lock."
  5854. (interactive "P")
  5855. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5856. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5857. (setq org-agenda-overriding-restriction nil)
  5858. (setq org-agenda-restrict nil)
  5859. (put 'org-agenda-files 'org-restrict nil)
  5860. (move-marker org-agenda-restrict-begin nil)
  5861. (move-marker org-agenda-restrict-end nil)
  5862. (setq current-prefix-arg nil)
  5863. (message "Agenda restriction lock removed")
  5864. (or noupdate (org-agenda-maybe-redo)))
  5865. (defun org-agenda-maybe-redo ()
  5866. "If there is any window showing the agenda view, update it."
  5867. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5868. (w0 (selected-window)))
  5869. (when w
  5870. (select-window w)
  5871. (org-agenda-redo)
  5872. (select-window w0)
  5873. (if org-agenda-overriding-restriction
  5874. (message "Agenda view shifted to new %s restriction"
  5875. org-agenda-overriding-restriction)
  5876. (message "Agenda restriction lock removed")))))
  5877. ;;; Agenda commands
  5878. (defun org-agenda-check-type (error &rest types)
  5879. "Check if agenda buffer is of allowed type.
  5880. If ERROR is non-nil, throw an error, otherwise just return nil."
  5881. (if (memq org-agenda-type types)
  5882. t
  5883. (if error
  5884. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5885. nil)))
  5886. (defun org-agenda-Quit (&optional arg)
  5887. "Exit agenda by removing the window or the buffer"
  5888. (interactive)
  5889. (if org-agenda-columns-active
  5890. (org-columns-quit)
  5891. (let ((buf (current-buffer)))
  5892. (if (eq org-agenda-window-setup 'other-frame)
  5893. (progn
  5894. (org-agenda-reset-markers)
  5895. (kill-buffer buf)
  5896. (org-columns-remove-overlays)
  5897. (setq org-agenda-archives-mode nil)
  5898. (delete-frame))
  5899. (and (not (eq org-agenda-window-setup 'current-window))
  5900. (not (one-window-p))
  5901. (delete-window))
  5902. (org-agenda-reset-markers)
  5903. (kill-buffer buf)
  5904. (org-columns-remove-overlays)
  5905. (setq org-agenda-archives-mode nil)))
  5906. ;; Maybe restore the pre-agenda window configuration.
  5907. (and org-agenda-restore-windows-after-quit
  5908. (not (eq org-agenda-window-setup 'other-frame))
  5909. org-pre-agenda-window-conf
  5910. (set-window-configuration org-pre-agenda-window-conf))))
  5911. (defun org-agenda-quit ()
  5912. "Exit agenda by killing agenda buffer or burying it when
  5913. `org-agenda-sticky' is non-NIL"
  5914. (interactive)
  5915. (if org-agenda-columns-active
  5916. (org-columns-quit)
  5917. (if org-agenda-sticky
  5918. (let ((buf (current-buffer)))
  5919. (if (eq org-agenda-window-setup 'other-frame)
  5920. (progn
  5921. (delete-frame))
  5922. (and (not (eq org-agenda-window-setup 'current-window))
  5923. (not (one-window-p))
  5924. (delete-window)))
  5925. (with-current-buffer buf
  5926. (bury-buffer)
  5927. ;; Maybe restore the pre-agenda window configuration.
  5928. (and org-agenda-restore-windows-after-quit
  5929. (not (eq org-agenda-window-setup 'other-frame))
  5930. org-pre-agenda-window-conf
  5931. (set-window-configuration org-pre-agenda-window-conf))))
  5932. (org-agenda-Quit))))
  5933. (defun org-agenda-exit ()
  5934. "Exit agenda by removing the window or the buffer.
  5935. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5936. Org-mode buffers visited directly by the user will not be touched."
  5937. (interactive)
  5938. (org-release-buffers org-agenda-new-buffers)
  5939. (setq org-agenda-new-buffers nil)
  5940. (org-agenda-Quit))
  5941. (defun org-agenda-kill-all-agenda-buffers ()
  5942. "Kill all buffers in `org-agena-mode'.
  5943. This is used when toggling sticky agendas. You can also explicitly invoke it
  5944. with `C-c a C-k'."
  5945. (interactive)
  5946. (let (blist)
  5947. (dolist (buf (buffer-list))
  5948. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5949. (push buf blist)))
  5950. (mapc 'kill-buffer blist)))
  5951. (defun org-agenda-execute (arg)
  5952. "Execute another agenda command, keeping same window.
  5953. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5954. in the agenda."
  5955. (interactive "P")
  5956. (let ((org-agenda-window-setup 'current-window))
  5957. (org-agenda arg)))
  5958. (defun org-agenda-redo ()
  5959. "Rebuild Agenda.
  5960. When this is the global TODO list, a prefix argument will be interpreted."
  5961. (interactive)
  5962. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  5963. (org-agenda-sticky nil)
  5964. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  5965. org-agenda-buffer-name))
  5966. (org-agenda-keep-modes t)
  5967. (tag-filter org-agenda-tag-filter)
  5968. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5969. (top-cat-filter org-agenda-top-category-filter)
  5970. (cat-filter org-agenda-category-filter)
  5971. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5972. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5973. (cols org-agenda-columns-active)
  5974. (line (org-current-line))
  5975. (window-line (- line (org-current-line (window-start))))
  5976. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5977. (put 'org-agenda-tag-filter :preset-filter nil)
  5978. (put 'org-agenda-category-filter :preset-filter nil)
  5979. (and cols (org-columns-quit))
  5980. (message "Rebuilding agenda buffer...")
  5981. (org-let lprops '(eval org-agenda-redo-command))
  5982. (setq org-agenda-undo-list nil
  5983. org-agenda-pending-undo-list nil)
  5984. (message "Rebuilding agenda buffer...done")
  5985. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5986. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5987. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5988. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5989. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  5990. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5991. (org-goto-line line)
  5992. (recenter window-line)))
  5993. (defvar org-global-tags-completion-table nil)
  5994. (defvar org-agenda-filter-form nil)
  5995. (defvar org-agenda-filtered-by-category nil)
  5996. (defun org-agenda-filter-by-category (strip)
  5997. "Keep only those lines in the agenda buffer that have a specific category.
  5998. The category is that of the current line."
  5999. (interactive "P")
  6000. (if org-agenda-filtered-by-category
  6001. (org-agenda-filter-show-all-cat)
  6002. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6003. (if cat (org-agenda-filter-apply
  6004. (list (concat (if strip "-" "+") cat)) 'category)
  6005. (error "No category at point")))))
  6006. (defun org-find-top-category (&optional pos)
  6007. (save-excursion
  6008. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6009. (if pos (goto-char pos))
  6010. ;; Skip up to the topmost parent
  6011. (while (ignore-errors (outline-up-heading 1) t))
  6012. (ignore-errors
  6013. (nth 4 (org-heading-components))))))
  6014. (defvar org-agenda-filtered-by-top-category nil)
  6015. (defun org-agenda-filter-by-top-category (strip)
  6016. "Keep only those lines in the agenda buffer that have a specific category.
  6017. The category is that of the current line."
  6018. (interactive "P")
  6019. (if org-agenda-filtered-by-top-category
  6020. (progn
  6021. (setq org-agenda-filtered-by-top-category nil
  6022. org-agenda-top-category-filter nil)
  6023. (org-agenda-filter-show-all-cat))
  6024. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6025. (if cat (org-agenda-filter-top-category-apply cat strip)
  6026. (error "No top-level category at point")))))
  6027. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6028. "Keep only those lines in the agenda buffer that have a specific tag.
  6029. The tag is selected with its fast selection letter, as configured.
  6030. With prefix argument STRIP, remove all lines that do have the tag.
  6031. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6032. used to narrow the search - the interactive user can also press `-' or `+'
  6033. to switch to narrowing."
  6034. (interactive "P")
  6035. (let* ((alist org-tag-alist-for-agenda)
  6036. (tag-chars (mapconcat
  6037. (lambda (x) (if (and (not (symbolp (car x)))
  6038. (cdr x))
  6039. (char-to-string (cdr x))
  6040. ""))
  6041. alist ""))
  6042. (efforts (org-split-string
  6043. (or (cdr (assoc (concat org-effort-property "_ALL")
  6044. org-global-properties))
  6045. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6046. "")))
  6047. (effort-op org-agenda-filter-effort-default-operator)
  6048. (effort-prompt "")
  6049. (inhibit-read-only t)
  6050. (current org-agenda-tag-filter)
  6051. maybe-refresh a n tag)
  6052. (unless char
  6053. (message
  6054. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6055. (if narrow "Narrow" "Filter") tag-chars
  6056. (if org-agenda-auto-exclude-function "[RET], " ""))
  6057. (setq char (read-char-exclusive)))
  6058. (when (member char '(?+ ?-))
  6059. ;; Narrowing down
  6060. (cond ((equal char ?-) (setq strip t narrow t))
  6061. ((equal char ?+) (setq strip nil narrow t)))
  6062. (message
  6063. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6064. (setq char (read-char-exclusive)))
  6065. (when (member char '(?< ?> ?= ??))
  6066. ;; An effort operator
  6067. (setq effort-op (char-to-string char))
  6068. (setq alist nil) ; to make sure it will be interpreted as effort.
  6069. (unless (equal char ??)
  6070. (loop for i from 0 to 9 do
  6071. (setq effort-prompt
  6072. (concat
  6073. effort-prompt " ["
  6074. (if (= i 9) "0" (int-to-string (1+ i)))
  6075. "]" (nth i efforts))))
  6076. (message "Effort%s: %s " effort-op effort-prompt)
  6077. (setq char (read-char-exclusive))
  6078. (when (or (< char ?0) (> char ?9))
  6079. (error "Need 1-9,0 to select effort"))))
  6080. (when (equal char ?\t)
  6081. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6082. (org-set-local 'org-global-tags-completion-table
  6083. (org-global-tags-completion-table)))
  6084. (let ((completion-ignore-case t))
  6085. (setq tag (org-icompleting-read
  6086. "Tag: " org-global-tags-completion-table))))
  6087. (cond
  6088. ((equal char ?\r)
  6089. (org-agenda-filter-show-all-tag)
  6090. (when org-agenda-auto-exclude-function
  6091. (setq org-agenda-tag-filter '())
  6092. (dolist (tag (org-agenda-get-represented-tags))
  6093. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6094. (if modifier
  6095. (push modifier org-agenda-tag-filter))))
  6096. (if (not (null org-agenda-tag-filter))
  6097. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6098. (setq maybe-refresh t))
  6099. ((equal char ?/)
  6100. (org-agenda-filter-show-all-tag)
  6101. (when (get 'org-agenda-tag-filter :preset-filter)
  6102. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6103. (setq maybe-refresh t))
  6104. ((equal char ?. )
  6105. (setq org-agenda-tag-filter
  6106. (mapcar (lambda(tag) (concat "+" tag))
  6107. (org-get-at-bol 'tags)))
  6108. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6109. (setq maybe-refresh t))
  6110. ((or (equal char ?\ )
  6111. (setq a (rassoc char alist))
  6112. (and (>= char ?0) (<= char ?9)
  6113. (setq n (if (= char ?0) 9 (- char ?0 1))
  6114. tag (concat effort-op (nth n efforts))
  6115. a (cons tag nil)))
  6116. (and (= char ??)
  6117. (setq tag "?eff")
  6118. a (cons tag nil))
  6119. (and tag (setq a (cons tag nil))))
  6120. (org-agenda-filter-show-all-tag)
  6121. (setq tag (car a))
  6122. (setq org-agenda-tag-filter
  6123. (cons (concat (if strip "-" "+") tag)
  6124. (if narrow current nil)))
  6125. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6126. (setq maybe-refresh t))
  6127. (t (error "Invalid tag selection character %c" char)))
  6128. (when (and maybe-refresh
  6129. (eq org-agenda-clockreport-mode 'with-filter))
  6130. (org-agenda-redo))))
  6131. (defun org-agenda-get-represented-tags ()
  6132. "Get a list of all tags currently represented in the agenda."
  6133. (let (p tags)
  6134. (save-excursion
  6135. (goto-char (point-min))
  6136. (while (setq p (next-single-property-change (point) 'tags))
  6137. (goto-char p)
  6138. (mapc (lambda (x) (add-to-list 'tags x))
  6139. (get-text-property (point) 'tags))))
  6140. tags))
  6141. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6142. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6143. (interactive "P")
  6144. (org-agenda-filter-by-tag strip char 'refine))
  6145. (defun org-agenda-filter-make-matcher ()
  6146. "Create the form that tests a line for agenda filter."
  6147. (let (f f1)
  6148. ;; first compute the tag-filter matcher
  6149. (dolist (x (delete-dups
  6150. (append (get 'org-agenda-tag-filter
  6151. :preset-filter) org-agenda-tag-filter)))
  6152. (if (member x '("-" "+"))
  6153. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6154. (if (string-match "[<=>?]" x)
  6155. (setq f1 (org-agenda-filter-effort-form x))
  6156. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6157. (if (equal (string-to-char x) ?-)
  6158. (setq f1 (list 'not f1))))
  6159. (push f1 f))
  6160. ;; then compute the category-filter matcher
  6161. (dolist (x (delete-dups
  6162. (append (get 'org-agenda-category-filter
  6163. :preset-filter) org-agenda-category-filter)))
  6164. (if (equal "-" (substring x 0 1))
  6165. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6166. (setq f1 (list 'equal (substring x 1) 'cat)))
  6167. (push f1 f))
  6168. (cons 'and (nreverse f))))
  6169. (defun org-agenda-filter-effort-form (e)
  6170. "Return the form to compare the effort of the current line with what E says.
  6171. E looks like \"+<2:25\"."
  6172. (let (op)
  6173. (setq e (substring e 1))
  6174. (setq op (string-to-char e) e (substring e 1))
  6175. (setq op (cond ((equal op ?<) '<=)
  6176. ((equal op ?>) '>=)
  6177. ((equal op ??) op)
  6178. (t '=)))
  6179. (list 'org-agenda-compare-effort (list 'quote op)
  6180. (org-duration-string-to-minutes e))))
  6181. (defun org-agenda-compare-effort (op value)
  6182. "Compare the effort of the current line with VALUE, using OP.
  6183. If the line does not have an effort defined, return nil."
  6184. (let ((eff (org-get-at-bol 'effort-minutes)))
  6185. (if (equal op ??)
  6186. (not eff)
  6187. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6188. value))))
  6189. (defun org-agenda-filter-apply (filter type)
  6190. "Set FILTER as the new agenda filter and apply it."
  6191. (let (tags cat)
  6192. (if (eq type 'tag)
  6193. (setq org-agenda-tag-filter filter)
  6194. (setq org-agenda-category-filter filter))
  6195. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6196. (if (and (eq type 'category)
  6197. (not (equal (substring (car filter) 0 1) "-")))
  6198. ;; Only set `org-agenda-filtered-by-category' to t
  6199. ;; when a unique category is used as the filter
  6200. (setq org-agenda-filtered-by-category t))
  6201. (org-agenda-set-mode-name)
  6202. (save-excursion
  6203. (goto-char (point-min))
  6204. (while (not (eobp))
  6205. (if (org-get-at-bol 'org-marker)
  6206. (progn
  6207. (setq tags (org-get-at-bol 'tags) ; used in eval
  6208. cat (get-text-property (point) 'org-category))
  6209. (if (not (eval org-agenda-filter-form))
  6210. (org-agenda-filter-hide-line type))
  6211. (beginning-of-line 2))
  6212. (beginning-of-line 2))))
  6213. (if (get-char-property (point) 'invisible)
  6214. (ignore-errors (org-agenda-previous-line)))))
  6215. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6216. "Set FILTER as the new agenda filter and apply it."
  6217. (org-agenda-set-mode-name)
  6218. (save-excursion
  6219. (goto-char (point-min))
  6220. (while (not (eobp))
  6221. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6222. (topcat (and pos (org-find-top-category pos))))
  6223. (if (and topcat (funcall (if negative 'identity 'not)
  6224. (string= category topcat)))
  6225. (org-agenda-filter-hide-line 'category)))
  6226. (beginning-of-line 2)))
  6227. (if (get-char-property (point) 'invisible)
  6228. (org-agenda-previous-line))
  6229. (setq org-agenda-top-category-filter category
  6230. org-agenda-filtered-by-top-category t))
  6231. (defun org-agenda-filter-hide-line (type)
  6232. (let (ov)
  6233. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6234. (point-at-eol)))
  6235. (overlay-put ov 'invisible t)
  6236. (overlay-put ov 'type type)
  6237. (if (eq type 'tag)
  6238. (push ov org-agenda-tag-filter-overlays)
  6239. (push ov org-agenda-cat-filter-overlays))))
  6240. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6241. (setq pos (or pos (point)))
  6242. (save-excursion
  6243. (dolist (ov (overlays-at pos))
  6244. (when (and (overlay-get ov 'invisible)
  6245. (eq (overlay-get ov 'type) 'tag))
  6246. (goto-char pos)
  6247. (if (< (overlay-start ov) (point-at-eol))
  6248. (move-overlay ov (point-at-eol)
  6249. (overlay-end ov)))))))
  6250. (defun org-agenda-filter-show-all-tag nil
  6251. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6252. (setq org-agenda-tag-filter-overlays nil
  6253. org-agenda-tag-filter nil
  6254. org-agenda-filter-form nil)
  6255. (org-agenda-set-mode-name))
  6256. (defun org-agenda-filter-show-all-cat nil
  6257. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6258. (setq org-agenda-cat-filter-overlays nil
  6259. org-agenda-filtered-by-category nil
  6260. org-agenda-category-filter nil
  6261. org-agenda-filter-form nil)
  6262. (org-agenda-set-mode-name))
  6263. (defun org-agenda-manipulate-query-add ()
  6264. "Manipulate the query by adding a search term with positive selection.
  6265. Positive selection means the term must be matched for selection of an entry."
  6266. (interactive)
  6267. (org-agenda-manipulate-query ?\[))
  6268. (defun org-agenda-manipulate-query-subtract ()
  6269. "Manipulate the query by adding a search term with negative selection.
  6270. Negative selection means term must not be matched for selection of an entry."
  6271. (interactive)
  6272. (org-agenda-manipulate-query ?\]))
  6273. (defun org-agenda-manipulate-query-add-re ()
  6274. "Manipulate the query by adding a search regexp with positive selection.
  6275. Positive selection means the regexp must match for selection of an entry."
  6276. (interactive)
  6277. (org-agenda-manipulate-query ?\{))
  6278. (defun org-agenda-manipulate-query-subtract-re ()
  6279. "Manipulate the query by adding a search regexp with negative selection.
  6280. Negative selection means regexp must not match for selection of an entry."
  6281. (interactive)
  6282. (org-agenda-manipulate-query ?\}))
  6283. (defun org-agenda-manipulate-query (char)
  6284. (cond
  6285. ((memq org-agenda-type '(timeline agenda))
  6286. (let ((org-agenda-include-inactive-timestamps t))
  6287. (org-agenda-redo))
  6288. (message "Display now includes inactive timestamps as well"))
  6289. ((eq org-agenda-type 'search)
  6290. (org-add-to-string
  6291. 'org-agenda-query-string
  6292. (if org-agenda-last-search-view-search-was-boolean
  6293. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6294. (?\{ . " +{}") (?\} . " -{}"))))
  6295. " "))
  6296. (setq org-agenda-redo-command
  6297. (list 'org-search-view
  6298. org-todo-only
  6299. org-agenda-query-string
  6300. (+ (length org-agenda-query-string)
  6301. (if (member char '(?\{ ?\})) 0 1))))
  6302. (set-register org-agenda-query-register org-agenda-query-string)
  6303. (org-agenda-redo))
  6304. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6305. org-agenda-type))))
  6306. (defun org-add-to-string (var string)
  6307. (set var (concat (symbol-value var) string)))
  6308. (defun org-agenda-goto-date (date)
  6309. "Jump to DATE in agenda."
  6310. (interactive (list (let ((org-read-date-prefer-future
  6311. (eval org-agenda-jump-prefer-future)))
  6312. (org-read-date))))
  6313. (org-agenda-list nil date))
  6314. (defun org-agenda-goto-today ()
  6315. "Go to today."
  6316. (interactive)
  6317. (org-agenda-check-type t 'timeline 'agenda)
  6318. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6319. (cond
  6320. (tdpos (goto-char tdpos))
  6321. ((eq org-agenda-type 'agenda)
  6322. (let* ((sd (org-agenda-compute-starting-span
  6323. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6324. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6325. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6326. (org-agenda-redo)
  6327. (org-agenda-find-same-or-today-or-agenda)))
  6328. (t (error "Cannot find today")))))
  6329. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6330. (goto-char
  6331. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6332. (text-property-any (point-min) (point-max) 'org-today t)
  6333. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6334. (point-min))))
  6335. (defun org-agenda-later (arg)
  6336. "Go forward in time by thee current span.
  6337. With prefix ARG, go forward that many times the current span."
  6338. (interactive "p")
  6339. (org-agenda-check-type t 'agenda)
  6340. (let* ((span org-agenda-current-span)
  6341. (sd org-starting-day)
  6342. (greg (calendar-gregorian-from-absolute sd))
  6343. (cnt (org-get-at-bol 'org-day-cnt))
  6344. greg2)
  6345. (cond
  6346. ((eq span 'day)
  6347. (setq sd (+ arg sd)))
  6348. ((eq span 'week)
  6349. (setq sd (+ (* 7 arg) sd)))
  6350. ((eq span 'month)
  6351. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6352. sd (calendar-absolute-from-gregorian greg2))
  6353. (setcar greg2 (1+ (car greg2))))
  6354. ((eq span 'year)
  6355. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6356. sd (calendar-absolute-from-gregorian greg2))
  6357. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6358. (t
  6359. (setq sd (+ (* span arg) sd))))
  6360. (let ((org-agenda-overriding-arguments
  6361. (list (car org-agenda-last-arguments) sd span t)))
  6362. (org-agenda-redo)
  6363. (org-agenda-find-same-or-today-or-agenda cnt))))
  6364. (defun org-agenda-earlier (arg)
  6365. "Go backward in time by the current span.
  6366. With prefix ARG, go backward that many times the current span."
  6367. (interactive "p")
  6368. (org-agenda-later (- arg)))
  6369. (defun org-agenda-view-mode-dispatch ()
  6370. "Call one of the view mode commands."
  6371. (interactive)
  6372. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6373. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6374. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6375. [E]ntryText")
  6376. (let ((a (read-char-exclusive)))
  6377. (case a
  6378. (?\ (call-interactively 'org-agenda-reset-view))
  6379. (?d (call-interactively 'org-agenda-day-view))
  6380. (?w (call-interactively 'org-agenda-week-view))
  6381. (?m (call-interactively 'org-agenda-month-view))
  6382. (?y (call-interactively 'org-agenda-year-view))
  6383. (?l (call-interactively 'org-agenda-log-mode))
  6384. (?L (org-agenda-log-mode '(4)))
  6385. (?c (org-agenda-log-mode 'clockcheck))
  6386. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6387. (?a (call-interactively 'org-agenda-archives-mode))
  6388. (?A (org-agenda-archives-mode 'files))
  6389. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6390. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6391. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6392. (?D (call-interactively 'org-agenda-toggle-diary))
  6393. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6394. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6395. (org-agenda-check-type t 'timeline 'agenda)
  6396. (org-agenda-redo))
  6397. (message "Display now includes inactive timestamps as well"))
  6398. (?q (message "Abort"))
  6399. (otherwise (error "Invalid key" )))))
  6400. (defun org-agenda-reset-view ()
  6401. "Switch to default view for agenda."
  6402. (interactive)
  6403. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6404. (defun org-agenda-day-view (&optional day-of-year)
  6405. "Switch to daily view for agenda.
  6406. With argument DAY-OF-YEAR, switch to that day of the year."
  6407. (interactive "P")
  6408. (org-agenda-change-time-span 'day day-of-year))
  6409. (defun org-agenda-week-view (&optional iso-week)
  6410. "Switch to daily view for agenda.
  6411. With argument ISO-WEEK, switch to the corresponding ISO week.
  6412. If ISO-WEEK has more then 2 digits, only the last two encode the
  6413. week. Any digits before this encode a year. So 200712 means
  6414. week 12 of year 2007. Years in the range 1938-2037 can also be
  6415. written as 2-digit years."
  6416. (interactive "P")
  6417. (org-agenda-change-time-span 'week iso-week))
  6418. (defun org-agenda-month-view (&optional month)
  6419. "Switch to monthly view for agenda.
  6420. With argument MONTH, switch to that month."
  6421. (interactive "P")
  6422. (org-agenda-change-time-span 'month month))
  6423. (defun org-agenda-year-view (&optional year)
  6424. "Switch to yearly view for agenda.
  6425. With argument YEAR, switch to that year.
  6426. If MONTH has more then 2 digits, only the last two encode the
  6427. month. Any digits before this encode a year. So 200712 means
  6428. December year 2007. Years in the range 1938-2037 can also be
  6429. written as 2-digit years."
  6430. (interactive "P")
  6431. (when year
  6432. (setq year (org-small-year-to-year year)))
  6433. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6434. (org-agenda-change-time-span 'year year)
  6435. (error "Abort")))
  6436. (defun org-agenda-change-time-span (span &optional n)
  6437. "Change the agenda view to SPAN.
  6438. SPAN may be `day', `week', `month', `year'."
  6439. (org-agenda-check-type t 'agenda)
  6440. (if (and (not n) (equal org-agenda-current-span span))
  6441. (error "Viewing span is already \"%s\"" span))
  6442. (let* ((sd (or (org-get-at-bol 'day)
  6443. org-starting-day))
  6444. (sd (org-agenda-compute-starting-span sd span n))
  6445. (org-agenda-overriding-arguments
  6446. (or org-agenda-overriding-arguments
  6447. (list (car org-agenda-last-arguments) sd span t))))
  6448. (org-agenda-redo)
  6449. (org-agenda-find-same-or-today-or-agenda))
  6450. (org-agenda-set-mode-name)
  6451. (message "Switched to %s view" span))
  6452. (defun org-agenda-compute-starting-span (sd span &optional n)
  6453. "Compute starting date for agenda.
  6454. SPAN may be `day', `week', `month', `year'. The return value
  6455. is a cons cell with the starting date and the number of days,
  6456. so that the date SD will be in that range."
  6457. (let* ((greg (calendar-gregorian-from-absolute sd))
  6458. (dg (nth 1 greg))
  6459. (mg (car greg))
  6460. (yg (nth 2 greg)))
  6461. (cond
  6462. ((eq span 'day)
  6463. (when n
  6464. (setq sd (+ (calendar-absolute-from-gregorian
  6465. (list mg 1 yg))
  6466. n -1))))
  6467. ((eq span 'week)
  6468. (let* ((nt (calendar-day-of-week
  6469. (calendar-gregorian-from-absolute sd)))
  6470. (d (if org-agenda-start-on-weekday
  6471. (- nt org-agenda-start-on-weekday)
  6472. 0))
  6473. y1)
  6474. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6475. (when n
  6476. (require 'cal-iso)
  6477. (when (> n 99)
  6478. (setq y1 (org-small-year-to-year (/ n 100))
  6479. n (mod n 100)))
  6480. (setq sd
  6481. (calendar-absolute-from-iso
  6482. (list n 1
  6483. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6484. ((eq span 'month)
  6485. (let (y1)
  6486. (when (and n (> n 99))
  6487. (setq y1 (org-small-year-to-year (/ n 100))
  6488. n (mod n 100)))
  6489. (setq sd (calendar-absolute-from-gregorian
  6490. (list (or n mg) 1 (or y1 yg))))))
  6491. ((eq span 'year)
  6492. (setq sd (calendar-absolute-from-gregorian
  6493. (list 1 1 (or n yg))))))
  6494. sd))
  6495. (defun org-agenda-next-date-line (&optional arg)
  6496. "Jump to the next line indicating a date in agenda buffer."
  6497. (interactive "p")
  6498. (org-agenda-check-type t 'agenda 'timeline)
  6499. (beginning-of-line 1)
  6500. ;; This does not work if user makes date format that starts with a blank
  6501. (if (looking-at "^\\S-") (forward-char 1))
  6502. (if (not (re-search-forward "^\\S-" nil t arg))
  6503. (progn
  6504. (backward-char 1)
  6505. (error "No next date after this line in this buffer")))
  6506. (goto-char (match-beginning 0)))
  6507. (defun org-agenda-previous-date-line (&optional arg)
  6508. "Jump to the previous line indicating a date in agenda buffer."
  6509. (interactive "p")
  6510. (org-agenda-check-type t 'agenda 'timeline)
  6511. (beginning-of-line 1)
  6512. (if (not (re-search-backward "^\\S-" nil t arg))
  6513. (error "No previous date before this line in this buffer")))
  6514. ;; Initialize the highlight
  6515. (defvar org-hl (make-overlay 1 1))
  6516. (overlay-put org-hl 'face 'highlight)
  6517. (defun org-highlight (begin end &optional buffer)
  6518. "Highlight a region with overlay."
  6519. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6520. (defun org-unhighlight ()
  6521. "Detach overlay INDEX."
  6522. (org-detach-overlay org-hl))
  6523. ;; FIXME this is currently not used.
  6524. (defun org-highlight-until-next-command (beg end &optional buffer)
  6525. "Move the highlight overlay to BEG/END, remove it before the next command."
  6526. (org-highlight beg end buffer)
  6527. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6528. (defun org-unhighlight-once ()
  6529. "Remove the highlight from its position, and this function from the hook."
  6530. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6531. (org-unhighlight))
  6532. (defun org-agenda-follow-mode ()
  6533. "Toggle follow mode in an agenda buffer."
  6534. (interactive)
  6535. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6536. (org-agenda-set-mode-name)
  6537. (org-agenda-do-context-action)
  6538. (message "Follow mode is %s"
  6539. (if org-agenda-follow-mode "on" "off")))
  6540. (defun org-agenda-entry-text-mode (&optional arg)
  6541. "Toggle entry text mode in an agenda buffer."
  6542. (interactive "P")
  6543. (setq org-agenda-entry-text-mode (or (integerp arg)
  6544. (not org-agenda-entry-text-mode)))
  6545. (org-agenda-entry-text-hide)
  6546. (and org-agenda-entry-text-mode
  6547. (let ((org-agenda-entry-text-maxlines
  6548. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6549. (org-agenda-entry-text-show)))
  6550. (org-agenda-set-mode-name)
  6551. (message "Entry text mode is %s. Maximum number of lines is %d"
  6552. (if org-agenda-entry-text-mode "on" "off")
  6553. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6554. (defun org-agenda-clockreport-mode (&optional with-filter)
  6555. "Toggle clocktable mode in an agenda buffer.
  6556. With prefix arg WITH-FILTER, make the clocktable respect the current
  6557. agenda filter."
  6558. (interactive "P")
  6559. (org-agenda-check-type t 'agenda)
  6560. (if with-filter
  6561. (setq org-agenda-clockreport-mode 'with-filter)
  6562. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6563. (org-agenda-set-mode-name)
  6564. (org-agenda-redo)
  6565. (message "Clocktable mode is %s"
  6566. (if org-agenda-clockreport-mode "on" "off")))
  6567. (defun org-agenda-log-mode (&optional special)
  6568. "Toggle log mode in an agenda buffer.
  6569. With argument SPECIAL, show all possible log items, not only the ones
  6570. configured in `org-agenda-log-mode-items'.
  6571. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6572. (interactive "P")
  6573. (org-agenda-check-type t 'agenda 'timeline)
  6574. (setq org-agenda-show-log
  6575. (cond
  6576. ((equal special '(16)) 'only)
  6577. ((eq special 'clockcheck)
  6578. (if (eq org-agenda-show-log 'clockcheck)
  6579. nil 'clockcheck))
  6580. (special '(closed clock state))
  6581. (t (not org-agenda-show-log))))
  6582. (org-agenda-set-mode-name)
  6583. (org-agenda-redo)
  6584. (message "Log mode is %s"
  6585. (if org-agenda-show-log "on" "off")))
  6586. (defun org-agenda-archives-mode (&optional with-files)
  6587. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6588. When called with a prefix argument, include all archive files as well."
  6589. (interactive "P")
  6590. (setq org-agenda-archives-mode
  6591. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6592. (org-agenda-set-mode-name)
  6593. (org-agenda-redo)
  6594. (message
  6595. "%s"
  6596. (cond
  6597. ((eq org-agenda-archives-mode nil)
  6598. "No archives are included")
  6599. ((eq org-agenda-archives-mode 'trees)
  6600. (format "Trees with :%s: tag are included" org-archive-tag))
  6601. ((eq org-agenda-archives-mode t)
  6602. (format "Trees with :%s: tag and all active archive files are included"
  6603. org-archive-tag)))))
  6604. (defun org-agenda-toggle-diary ()
  6605. "Toggle diary inclusion in an agenda buffer."
  6606. (interactive)
  6607. (org-agenda-check-type t 'agenda)
  6608. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6609. (org-agenda-redo)
  6610. (org-agenda-set-mode-name)
  6611. (message "Diary inclusion turned %s"
  6612. (if org-agenda-include-diary "on" "off")))
  6613. (defun org-agenda-toggle-deadlines ()
  6614. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6615. (interactive)
  6616. (org-agenda-check-type t 'agenda)
  6617. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6618. (org-agenda-redo)
  6619. (org-agenda-set-mode-name)
  6620. (message "Deadlines inclusion turned %s"
  6621. (if org-agenda-include-deadlines "on" "off")))
  6622. (defun org-agenda-toggle-time-grid ()
  6623. "Toggle time grid in an agenda buffer."
  6624. (interactive)
  6625. (org-agenda-check-type t 'agenda)
  6626. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6627. (org-agenda-redo)
  6628. (org-agenda-set-mode-name)
  6629. (message "Time-grid turned %s"
  6630. (if org-agenda-use-time-grid "on" "off")))
  6631. (defun org-agenda-set-mode-name ()
  6632. "Set the mode name to indicate all the small mode settings."
  6633. (setq mode-name
  6634. (list "Org-Agenda"
  6635. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6636. " "
  6637. '(:eval (org-agenda-span-name org-agenda-current-span))
  6638. (if org-agenda-follow-mode " Follow" "")
  6639. (if org-agenda-entry-text-mode " ETxt" "")
  6640. (if org-agenda-include-diary " Diary" "")
  6641. (if org-agenda-include-deadlines " Ddl" "")
  6642. (if org-agenda-use-time-grid " Grid" "")
  6643. (if (and (boundp 'org-habit-show-habits)
  6644. org-habit-show-habits) " Habit" "")
  6645. (cond
  6646. ((consp org-agenda-show-log) " LogAll")
  6647. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6648. (org-agenda-show-log " Log")
  6649. (t ""))
  6650. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6651. :preset-filter))
  6652. '(:eval (org-propertize
  6653. (concat " <"
  6654. (mapconcat
  6655. 'identity
  6656. (append
  6657. (get 'org-agenda-category-filter :preset-filter)
  6658. org-agenda-category-filter)
  6659. "")
  6660. ">")
  6661. 'face 'org-agenda-filter-category
  6662. 'help-echo "Category used in filtering"))
  6663. "")
  6664. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6665. :preset-filter))
  6666. '(:eval (org-propertize
  6667. (concat " {"
  6668. (mapconcat
  6669. 'identity
  6670. (append
  6671. (get 'org-agenda-tag-filter :preset-filter)
  6672. org-agenda-tag-filter)
  6673. "")
  6674. "}")
  6675. 'face 'org-agenda-filter-tags
  6676. 'help-echo "Tags used in filtering"))
  6677. "")
  6678. (if org-agenda-archives-mode
  6679. (if (eq org-agenda-archives-mode t)
  6680. " Archives"
  6681. (format " :%s:" org-archive-tag))
  6682. "")
  6683. (if org-agenda-clockreport-mode
  6684. (if (eq org-agenda-clockreport-mode 'with-filter)
  6685. " Clock{}" " Clock")
  6686. "")))
  6687. (force-mode-line-update))
  6688. (defun org-agenda-post-command-hook ()
  6689. (setq org-agenda-type
  6690. (or (get-text-property (point) 'org-agenda-type)
  6691. (get-text-property (max (point-min) (1- (point)))
  6692. 'org-agenda-type))))
  6693. (defun org-agenda-next-line ()
  6694. "Move cursor to the next line, and show if follow mode is active."
  6695. (interactive)
  6696. (call-interactively 'next-line)
  6697. (org-agenda-do-context-action))
  6698. (defun org-agenda-previous-line ()
  6699. "Move cursor to the previous line, and show if follow-mode is active."
  6700. (interactive)
  6701. (call-interactively 'previous-line)
  6702. (org-agenda-do-context-action))
  6703. (defun org-agenda-do-context-action ()
  6704. "Show outline path and, maybe, follow mode window."
  6705. (let ((m (org-get-at-bol 'org-marker)))
  6706. (when (and (markerp m) (marker-buffer m))
  6707. (and org-agenda-follow-mode
  6708. (if org-agenda-follow-indirect
  6709. (org-agenda-tree-to-indirect-buffer)
  6710. (org-agenda-show)))
  6711. (and org-agenda-show-outline-path
  6712. (org-with-point-at m (org-display-outline-path t))))))
  6713. (defun org-agenda-show-priority ()
  6714. "Show the priority of the current item.
  6715. This priority is composed of the main priority given with the [#A] cookies,
  6716. and by additional input from the age of a schedules or deadline entry."
  6717. (interactive)
  6718. (let* ((pri (org-get-at-bol 'priority)))
  6719. (message "Priority is %d" (if pri pri -1000))))
  6720. (defun org-agenda-show-tags ()
  6721. "Show the tags applicable to the current item."
  6722. (interactive)
  6723. (let* ((tags (org-get-at-bol 'tags)))
  6724. (if tags
  6725. (message "Tags are :%s:"
  6726. (org-no-properties (mapconcat 'identity tags ":")))
  6727. (message "No tags associated with this line"))))
  6728. (defun org-agenda-goto (&optional highlight)
  6729. "Go to the Org-mode file which contains the item at point."
  6730. (interactive)
  6731. (let* ((marker (or (org-get-at-bol 'org-marker)
  6732. (org-agenda-error)))
  6733. (buffer (marker-buffer marker))
  6734. (pos (marker-position marker)))
  6735. (switch-to-buffer-other-window buffer)
  6736. (widen)
  6737. (push-mark)
  6738. (goto-char pos)
  6739. (when (derived-mode-p 'org-mode)
  6740. (org-show-context 'agenda)
  6741. (save-excursion
  6742. (and (outline-next-heading)
  6743. (org-flag-heading nil)))) ; show the next heading
  6744. (when (outline-invisible-p)
  6745. (show-entry)) ; display invisible text
  6746. (recenter (/ (window-height) 2))
  6747. (run-hooks 'org-agenda-after-show-hook)
  6748. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6749. (defvar org-agenda-after-show-hook nil
  6750. "Normal hook run after an item has been shown from the agenda.
  6751. Point is in the buffer where the item originated.")
  6752. (defun org-agenda-kill ()
  6753. "Kill the entry or subtree belonging to the current agenda entry."
  6754. (interactive)
  6755. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6756. (let* ((marker (or (org-get-at-bol 'org-marker)
  6757. (org-agenda-error)))
  6758. (buffer (marker-buffer marker))
  6759. (pos (marker-position marker))
  6760. (type (org-get-at-bol 'type))
  6761. dbeg dend (n 0) conf)
  6762. (org-with-remote-undo buffer
  6763. (with-current-buffer buffer
  6764. (save-excursion
  6765. (goto-char pos)
  6766. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  6767. (setq dbeg (progn (org-back-to-heading t) (point))
  6768. dend (org-end-of-subtree t t))
  6769. (setq dbeg (point-at-bol)
  6770. dend (min (point-max) (1+ (point-at-eol)))))
  6771. (goto-char dbeg)
  6772. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6773. (setq conf (or (eq t org-agenda-confirm-kill)
  6774. (and (numberp org-agenda-confirm-kill)
  6775. (> n org-agenda-confirm-kill))))
  6776. (and conf
  6777. (not (y-or-n-p
  6778. (format "Delete entry with %d lines in buffer \"%s\"? "
  6779. n (buffer-name buffer))))
  6780. (error "Abort"))
  6781. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6782. (with-current-buffer buffer (delete-region dbeg dend))
  6783. (message "Agenda item and source killed"))))
  6784. (defvar org-archive-default-command)
  6785. (defun org-agenda-archive-default ()
  6786. "Archive the entry or subtree belonging to the current agenda entry."
  6787. (interactive)
  6788. (require 'org-archive)
  6789. (org-agenda-archive-with org-archive-default-command))
  6790. (defun org-agenda-archive-default-with-confirmation ()
  6791. "Archive the entry or subtree belonging to the current agenda entry."
  6792. (interactive)
  6793. (require 'org-archive)
  6794. (org-agenda-archive-with org-archive-default-command 'confirm))
  6795. (defun org-agenda-archive ()
  6796. "Archive the entry or subtree belonging to the current agenda entry."
  6797. (interactive)
  6798. (org-agenda-archive-with 'org-archive-subtree))
  6799. (defun org-agenda-archive-to-archive-sibling ()
  6800. "Move the entry to the archive sibling."
  6801. (interactive)
  6802. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6803. (defun org-agenda-archive-with (cmd &optional confirm)
  6804. "Move the entry to the archive sibling."
  6805. (interactive)
  6806. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6807. (let* ((marker (or (org-get-at-bol 'org-marker)
  6808. (org-agenda-error)))
  6809. (buffer (marker-buffer marker))
  6810. (pos (marker-position marker)))
  6811. (org-with-remote-undo buffer
  6812. (with-current-buffer buffer
  6813. (if (derived-mode-p 'org-mode)
  6814. (if (and confirm
  6815. (not (y-or-n-p "Archive this subtree or entry? ")))
  6816. (error "Abort")
  6817. (save-excursion
  6818. (goto-char pos)
  6819. (org-remove-subtree-entries-from-agenda)
  6820. (org-back-to-heading t)
  6821. (funcall cmd)))
  6822. (error "Archiving works only in Org-mode files"))))))
  6823. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6824. "Remove all lines in the agenda that correspond to a given subtree.
  6825. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6826. If this information is not given, the function uses the tree at point."
  6827. (let ((buf (or buf (current-buffer))) m p)
  6828. (save-excursion
  6829. (unless (and beg end)
  6830. (org-back-to-heading t)
  6831. (setq beg (point))
  6832. (org-end-of-subtree t)
  6833. (setq end (point)))
  6834. (set-buffer (get-buffer org-agenda-buffer-name))
  6835. (save-excursion
  6836. (goto-char (point-max))
  6837. (beginning-of-line 1)
  6838. (while (not (bobp))
  6839. (when (and (setq m (org-get-at-bol 'org-marker))
  6840. (equal buf (marker-buffer m))
  6841. (setq p (marker-position m))
  6842. (>= p beg)
  6843. (< p end))
  6844. (let ((inhibit-read-only t))
  6845. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6846. (beginning-of-line 0))))))
  6847. (defun org-agenda-refile (&optional goto rfloc no-update)
  6848. "Refile the item at point."
  6849. (interactive "P")
  6850. (if (equal goto '(16))
  6851. (org-refile-goto-last-stored)
  6852. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6853. (org-agenda-error)))
  6854. (buffer (marker-buffer marker))
  6855. (pos (marker-position marker))
  6856. (rfloc (or rfloc
  6857. (org-refile-get-location
  6858. (if goto "Goto" "Refile to") buffer
  6859. org-refile-allow-creating-parent-nodes))))
  6860. (with-current-buffer buffer
  6861. (save-excursion
  6862. (save-restriction
  6863. (widen)
  6864. (goto-char marker)
  6865. (org-remove-subtree-entries-from-agenda)
  6866. (org-refile goto buffer rfloc)))))
  6867. (unless no-update (org-agenda-redo))))
  6868. (defun org-agenda-open-link (&optional arg)
  6869. "Follow the link in the current line, if any.
  6870. This looks for a link in the displayed line in the agenda. It also looks
  6871. at the text of the entry itself."
  6872. (interactive "P")
  6873. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6874. (org-get-at-bol 'org-marker)))
  6875. (buffer (and marker (marker-buffer marker)))
  6876. (prefix (buffer-substring
  6877. (point-at-bol) (point-at-eol))))
  6878. (cond
  6879. (buffer
  6880. (with-current-buffer buffer
  6881. (save-excursion
  6882. (save-restriction
  6883. (widen)
  6884. (goto-char marker)
  6885. (org-offer-links-in-entry arg prefix)))))
  6886. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6887. (save-excursion
  6888. (beginning-of-line 1)
  6889. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6890. (org-open-link-from-string (match-string 1)))
  6891. (t (error "No link to open here")))))
  6892. (defun org-agenda-copy-local-variable (var)
  6893. "Get a variable from a referenced buffer and install it here."
  6894. (let ((m (org-get-at-bol 'org-marker)))
  6895. (when (and m (buffer-live-p (marker-buffer m)))
  6896. (org-set-local var (with-current-buffer (marker-buffer m)
  6897. (symbol-value var))))))
  6898. (defun org-agenda-switch-to (&optional delete-other-windows)
  6899. "Go to the Org-mode file which contains the item at point."
  6900. (interactive)
  6901. (if (and org-return-follows-link
  6902. (not (org-get-at-bol 'org-marker))
  6903. (org-in-regexp org-bracket-link-regexp))
  6904. (org-open-link-from-string (match-string 0))
  6905. (let* ((marker (or (org-get-at-bol 'org-marker)
  6906. (org-agenda-error)))
  6907. (buffer (marker-buffer marker))
  6908. (pos (marker-position marker)))
  6909. (org-pop-to-buffer-same-window buffer)
  6910. (and delete-other-windows (delete-other-windows))
  6911. (widen)
  6912. (goto-char pos)
  6913. (when (derived-mode-p 'org-mode)
  6914. (org-show-context 'agenda)
  6915. (save-excursion
  6916. (and (outline-next-heading)
  6917. (org-flag-heading nil))) ; show the next heading
  6918. (when (outline-invisible-p)
  6919. (show-entry)))))) ; display invisible text
  6920. (defun org-agenda-goto-mouse (ev)
  6921. "Go to the Org-mode file which contains the item at the mouse click."
  6922. (interactive "e")
  6923. (mouse-set-point ev)
  6924. (org-agenda-goto))
  6925. (defun org-agenda-show (&optional full-entry)
  6926. "Display the Org-mode file which contains the item at point.
  6927. With prefix argument FULL-ENTRY, make the entire entry visible
  6928. if it was hidden in the outline."
  6929. (interactive "P")
  6930. (let ((win (selected-window)))
  6931. (if full-entry
  6932. (let ((org-show-entry-below t))
  6933. (org-agenda-goto t))
  6934. (org-agenda-goto t))
  6935. (select-window win)))
  6936. (defvar org-agenda-show-window nil)
  6937. (defun org-agenda-show-and-scroll-up (&optional arg)
  6938. "Display the Org-mode file which contains the item at point.
  6939. When called repeatedly, scroll the window that is displaying the buffer.
  6940. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6941. `show-subtree' to display the item, so that drawers and logbooks stay
  6942. folded."
  6943. (interactive "P")
  6944. (let ((win (selected-window)))
  6945. (if (and (window-live-p org-agenda-show-window)
  6946. (eq this-command last-command))
  6947. (progn
  6948. (select-window org-agenda-show-window)
  6949. (ignore-errors (scroll-up)))
  6950. (org-agenda-goto t)
  6951. (if arg (org-show-entry) (show-subtree))
  6952. (setq org-agenda-show-window (selected-window)))
  6953. (select-window win)))
  6954. (defun org-agenda-show-scroll-down ()
  6955. "Scroll down the window showing the agenda."
  6956. (interactive)
  6957. (let ((win (selected-window)))
  6958. (when (window-live-p org-agenda-show-window)
  6959. (select-window org-agenda-show-window)
  6960. (ignore-errors (scroll-down))
  6961. (select-window win))))
  6962. (defun org-agenda-show-1 (&optional more)
  6963. "Display the Org-mode file which contains the item at point.
  6964. The prefix arg selects the amount of information to display:
  6965. 0 hide the subtree
  6966. 1 just show the entry according to defaults.
  6967. 2 show the children view
  6968. 3 show the subtree view
  6969. 4 show the entire subtree and any LOGBOOK drawers
  6970. 5 show the entire subtree and any drawers
  6971. With prefix argument FULL-ENTRY, make the entire entry visible
  6972. if it was hidden in the outline."
  6973. (interactive "p")
  6974. (let ((win (selected-window)))
  6975. (org-agenda-goto t)
  6976. (org-recenter-heading 1)
  6977. (cond
  6978. ((= more 0)
  6979. (hide-subtree)
  6980. (save-excursion
  6981. (org-back-to-heading)
  6982. (run-hook-with-args 'org-cycle-hook 'folded))
  6983. (message "Remote: FOLDED"))
  6984. ((and (org-called-interactively-p 'any) (= more 1))
  6985. (message "Remote: show with default settings"))
  6986. ((= more 2)
  6987. (show-entry)
  6988. (show-children)
  6989. (save-excursion
  6990. (org-back-to-heading)
  6991. (run-hook-with-args 'org-cycle-hook 'children))
  6992. (message "Remote: CHILDREN"))
  6993. ((= more 3)
  6994. (show-subtree)
  6995. (save-excursion
  6996. (org-back-to-heading)
  6997. (run-hook-with-args 'org-cycle-hook 'subtree))
  6998. (message "Remote: SUBTREE"))
  6999. ((= more 4)
  7000. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7001. (org-drawer-regexp
  7002. (concat "^[ \t]*:\\("
  7003. (mapconcat 'regexp-quote org-drawers "\\|")
  7004. "\\):[ \t]*$")))
  7005. (show-subtree)
  7006. (save-excursion
  7007. (org-back-to-heading)
  7008. (org-cycle-hide-drawers 'subtree)))
  7009. (message "Remote: SUBTREE AND LOGBOOK"))
  7010. ((> more 4)
  7011. (show-subtree)
  7012. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7013. (select-window win)))
  7014. (defun org-recenter-heading (n)
  7015. (save-excursion
  7016. (org-back-to-heading)
  7017. (recenter n)))
  7018. (defvar org-agenda-cycle-counter nil)
  7019. (defun org-agenda-cycle-show (&optional n)
  7020. "Show the current entry in another window, with default settings.
  7021. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7022. When use repeatedly in immediate succession, the remote entry will cycle
  7023. through visibility
  7024. children -> subtree -> folded
  7025. When called with a numeric prefix arg, that arg will be passed through to
  7026. `org-agenda-show-1'. For the interpretation of that argument, see the
  7027. docstring of `org-agenda-show-1'."
  7028. (interactive "P")
  7029. (if (integerp n)
  7030. (setq org-agenda-cycle-counter n)
  7031. (if (not (eq last-command this-command))
  7032. (setq org-agenda-cycle-counter 1)
  7033. (if (equal org-agenda-cycle-counter 0)
  7034. (setq org-agenda-cycle-counter 2)
  7035. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7036. (if (> org-agenda-cycle-counter 3)
  7037. (setq org-agenda-cycle-counter 0)))))
  7038. (org-agenda-show-1 org-agenda-cycle-counter))
  7039. (defun org-agenda-recenter (arg)
  7040. "Display the Org-mode file which contains the item at point and recenter."
  7041. (interactive "P")
  7042. (let ((win (selected-window)))
  7043. (org-agenda-goto t)
  7044. (recenter arg)
  7045. (select-window win)))
  7046. (defun org-agenda-show-mouse (ev)
  7047. "Display the Org-mode file which contains the item at the mouse click."
  7048. (interactive "e")
  7049. (mouse-set-point ev)
  7050. (org-agenda-show))
  7051. (defun org-agenda-check-no-diary ()
  7052. "Check if the entry is a diary link and abort if yes."
  7053. (if (org-get-at-bol 'org-agenda-diary-link)
  7054. (org-agenda-error)))
  7055. (defun org-agenda-error ()
  7056. (error "Command not allowed in this line"))
  7057. (defun org-agenda-tree-to-indirect-buffer ()
  7058. "Show the subtree corresponding to the current entry in an indirect buffer.
  7059. This calls the command `org-tree-to-indirect-buffer' from the original
  7060. Org-mode buffer.
  7061. With numerical prefix arg ARG, go up to this level and then take that tree.
  7062. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7063. use the dedicated frame)."
  7064. (interactive)
  7065. (if (and current-prefix-arg (listp current-prefix-arg))
  7066. (org-agenda-do-tree-to-indirect-buffer)
  7067. (let ((agenda-window (selected-window))
  7068. (indirect-window
  7069. (and org-last-indirect-buffer
  7070. (get-buffer-window org-last-indirect-buffer))))
  7071. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7072. (unwind-protect
  7073. (progn
  7074. (unless (and indirect-window (window-live-p indirect-window))
  7075. (setq indirect-window (split-window agenda-window)))
  7076. (select-window indirect-window)
  7077. (switch-to-buffer org-last-indirect-buffer :norecord)
  7078. (fit-window-to-buffer indirect-window))
  7079. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7080. (defun org-agenda-do-tree-to-indirect-buffer ()
  7081. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7082. (org-agenda-check-no-diary)
  7083. (let* ((marker (or (org-get-at-bol 'org-marker)
  7084. (org-agenda-error)))
  7085. (buffer (marker-buffer marker))
  7086. (pos (marker-position marker)))
  7087. (with-current-buffer buffer
  7088. (save-excursion
  7089. (goto-char pos)
  7090. (call-interactively 'org-tree-to-indirect-buffer)))))
  7091. (defvar org-last-heading-marker (make-marker)
  7092. "Marker pointing to the headline that last changed its TODO state
  7093. by a remote command from the agenda.")
  7094. (defun org-agenda-todo-nextset ()
  7095. "Switch TODO entry to next sequence."
  7096. (interactive)
  7097. (org-agenda-todo 'nextset))
  7098. (defun org-agenda-todo-previousset ()
  7099. "Switch TODO entry to previous sequence."
  7100. (interactive)
  7101. (org-agenda-todo 'previousset))
  7102. (defun org-agenda-todo (&optional arg)
  7103. "Cycle TODO state of line at point, also in Org-mode file.
  7104. This changes the line at point, all other lines in the agenda referring to
  7105. the same tree node, and the headline of the tree node in the Org-mode file."
  7106. (interactive "P")
  7107. (org-agenda-check-no-diary)
  7108. (let* ((col (current-column))
  7109. (marker (or (org-get-at-bol 'org-marker)
  7110. (org-agenda-error)))
  7111. (buffer (marker-buffer marker))
  7112. (pos (marker-position marker))
  7113. (hdmarker (org-get-at-bol 'org-hd-marker))
  7114. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7115. (inhibit-read-only t)
  7116. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7117. (org-with-remote-undo buffer
  7118. (with-current-buffer buffer
  7119. (widen)
  7120. (goto-char pos)
  7121. (org-show-context 'agenda)
  7122. (save-excursion
  7123. (and (outline-next-heading)
  7124. (org-flag-heading nil))) ; show the next heading
  7125. (let ((current-prefix-arg arg))
  7126. (call-interactively 'org-todo))
  7127. (and (bolp) (forward-char 1))
  7128. (setq newhead (org-get-heading))
  7129. (when (and (org-bound-and-true-p
  7130. org-agenda-headline-snapshot-before-repeat)
  7131. (not (equal org-agenda-headline-snapshot-before-repeat
  7132. newhead))
  7133. todayp)
  7134. (setq newhead org-agenda-headline-snapshot-before-repeat
  7135. just-one t))
  7136. (save-excursion
  7137. (org-back-to-heading)
  7138. (move-marker org-last-heading-marker (point))))
  7139. (beginning-of-line 1)
  7140. (save-excursion
  7141. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7142. (org-move-to-column col))))
  7143. (defun org-agenda-add-note (&optional arg)
  7144. "Add a time-stamped note to the entry at point."
  7145. (interactive "P")
  7146. (org-agenda-check-no-diary)
  7147. (let* ((marker (or (org-get-at-bol 'org-marker)
  7148. (org-agenda-error)))
  7149. (buffer (marker-buffer marker))
  7150. (pos (marker-position marker))
  7151. (hdmarker (org-get-at-bol 'org-hd-marker))
  7152. (inhibit-read-only t))
  7153. (with-current-buffer buffer
  7154. (widen)
  7155. (goto-char pos)
  7156. (org-show-context 'agenda)
  7157. (save-excursion
  7158. (and (outline-next-heading)
  7159. (org-flag-heading nil))) ; show the next heading
  7160. (org-add-note))))
  7161. (defun org-agenda-change-all-lines (newhead hdmarker
  7162. &optional fixface just-this)
  7163. "Change all lines in the agenda buffer which match HDMARKER.
  7164. The new content of the line will be NEWHEAD (as modified by
  7165. `org-agenda-format-item'). HDMARKER is checked with
  7166. `equal' against all `org-hd-marker' text properties in the file.
  7167. If FIXFACE is non-nil, the face of each item is modified according to
  7168. the new TODO state.
  7169. If JUST-THIS is non-nil, change just the current line, not all.
  7170. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7171. (let* ((inhibit-read-only t)
  7172. (line (org-current-line))
  7173. (org-agenda-buffer (current-buffer))
  7174. (thetags (with-current-buffer (marker-buffer hdmarker)
  7175. (save-excursion (save-restriction (widen)
  7176. (goto-char hdmarker)
  7177. (org-get-tags-at)))))
  7178. props m pl undone-face done-face finish new dotime cat tags)
  7179. (save-excursion
  7180. (goto-char (point-max))
  7181. (beginning-of-line 1)
  7182. (while (not finish)
  7183. (setq finish (bobp))
  7184. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7185. (or (not just-this) (= (org-current-line) line))
  7186. (equal m hdmarker))
  7187. (setq props (text-properties-at (point))
  7188. dotime (org-get-at-bol 'dotime)
  7189. cat (org-get-at-bol 'org-category)
  7190. tags thetags
  7191. new
  7192. (let ((org-prefix-format-compiled
  7193. (or (get-text-property (point) 'format)
  7194. org-prefix-format-compiled))
  7195. (extra (org-get-at-bol 'extra)))
  7196. (with-current-buffer (marker-buffer hdmarker)
  7197. (save-excursion
  7198. (save-restriction
  7199. (widen)
  7200. (org-agenda-format-item extra newhead cat tags dotime)))))
  7201. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7202. undone-face (org-get-at-bol 'undone-face)
  7203. done-face (org-get-at-bol 'done-face))
  7204. (beginning-of-line 1)
  7205. (cond
  7206. ((equal new "")
  7207. (and (looking-at ".*\n?") (replace-match "")))
  7208. ((looking-at ".*")
  7209. (replace-match new t t)
  7210. (beginning-of-line 1)
  7211. (add-text-properties (point-at-bol) (point-at-eol) props)
  7212. (when fixface
  7213. (add-text-properties
  7214. (point-at-bol) (point-at-eol)
  7215. (list 'face
  7216. (if org-last-todo-state-is-todo
  7217. undone-face done-face))))
  7218. (org-agenda-highlight-todo 'line)
  7219. (beginning-of-line 1))
  7220. (t (error "Line update did not work"))))
  7221. (beginning-of-line 0)))
  7222. (org-finalize-agenda)))
  7223. (defun org-agenda-align-tags (&optional line)
  7224. "Align all tags in agenda items to `org-agenda-tags-column'."
  7225. (let ((inhibit-read-only t) l c)
  7226. (save-excursion
  7227. (goto-char (if line (point-at-bol) (point-min)))
  7228. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7229. (if line (point-at-eol) nil) t)
  7230. (add-text-properties
  7231. (match-beginning 2) (match-end 2)
  7232. (list 'face (delq nil (let ((prop (get-text-property
  7233. (match-beginning 2) 'face)))
  7234. (or (listp prop) (setq prop (list prop)))
  7235. (if (memq 'org-tag prop)
  7236. prop
  7237. (cons 'org-tag prop))))))
  7238. (setq l (- (match-end 2) (match-beginning 2))
  7239. c (if (< org-agenda-tags-column 0)
  7240. (- (abs org-agenda-tags-column) l)
  7241. org-agenda-tags-column))
  7242. (delete-region (match-beginning 1) (match-end 1))
  7243. (goto-char (match-beginning 1))
  7244. (insert (org-add-props
  7245. (make-string (max 1 (- c (current-column))) ?\ )
  7246. (plist-put (copy-sequence (text-properties-at (point)))
  7247. 'face nil))))
  7248. (goto-char (point-min))
  7249. (org-font-lock-add-tag-faces (point-max)))))
  7250. (defun org-agenda-priority-up ()
  7251. "Increase the priority of line at point, also in Org-mode file."
  7252. (interactive)
  7253. (org-agenda-priority 'up))
  7254. (defun org-agenda-priority-down ()
  7255. "Decrease the priority of line at point, also in Org-mode file."
  7256. (interactive)
  7257. (org-agenda-priority 'down))
  7258. (defun org-agenda-priority (&optional force-direction)
  7259. "Set the priority of line at point, also in Org-mode file.
  7260. This changes the line at point, all other lines in the agenda referring to
  7261. the same tree node, and the headline of the tree node in the Org-mode file."
  7262. (interactive)
  7263. (unless org-enable-priority-commands
  7264. (error "Priority commands are disabled"))
  7265. (org-agenda-check-no-diary)
  7266. (let* ((marker (or (org-get-at-bol 'org-marker)
  7267. (org-agenda-error)))
  7268. (hdmarker (org-get-at-bol 'org-hd-marker))
  7269. (buffer (marker-buffer hdmarker))
  7270. (pos (marker-position hdmarker))
  7271. (inhibit-read-only t)
  7272. newhead)
  7273. (org-with-remote-undo buffer
  7274. (with-current-buffer buffer
  7275. (widen)
  7276. (goto-char pos)
  7277. (org-show-context 'agenda)
  7278. (save-excursion
  7279. (and (outline-next-heading)
  7280. (org-flag-heading nil))) ; show the next heading
  7281. (funcall 'org-priority force-direction)
  7282. (end-of-line 1)
  7283. (setq newhead (org-get-heading)))
  7284. (org-agenda-change-all-lines newhead hdmarker)
  7285. (beginning-of-line 1))))
  7286. ;; FIXME: should fix the tags property of the agenda line.
  7287. (defun org-agenda-set-tags (&optional tag onoff)
  7288. "Set tags for the current headline."
  7289. (interactive)
  7290. (org-agenda-check-no-diary)
  7291. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7292. (call-interactively 'org-change-tag-in-region)
  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. (if tag
  7310. (org-toggle-tag tag onoff)
  7311. (call-interactively 'org-set-tags))
  7312. (end-of-line 1)
  7313. (setq newhead (org-get-heading)))
  7314. (org-agenda-change-all-lines newhead hdmarker)
  7315. (beginning-of-line 1)))))
  7316. (defun org-agenda-set-property ()
  7317. "Set a property for the current headline."
  7318. (interactive)
  7319. (org-agenda-check-no-diary)
  7320. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7321. (org-agenda-error)))
  7322. (buffer (marker-buffer hdmarker))
  7323. (pos (marker-position hdmarker))
  7324. (inhibit-read-only t)
  7325. newhead)
  7326. (org-with-remote-undo buffer
  7327. (with-current-buffer buffer
  7328. (widen)
  7329. (goto-char pos)
  7330. (save-excursion
  7331. (org-show-context 'agenda))
  7332. (save-excursion
  7333. (and (outline-next-heading)
  7334. (org-flag-heading nil))) ; show the next heading
  7335. (goto-char pos)
  7336. (call-interactively 'org-set-property)))))
  7337. (defun org-agenda-set-effort ()
  7338. "Set the effort property for the current headline."
  7339. (interactive)
  7340. (org-agenda-check-no-diary)
  7341. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7342. (org-agenda-error)))
  7343. (buffer (marker-buffer hdmarker))
  7344. (pos (marker-position hdmarker))
  7345. (inhibit-read-only t)
  7346. newhead)
  7347. (org-with-remote-undo buffer
  7348. (with-current-buffer buffer
  7349. (widen)
  7350. (goto-char pos)
  7351. (save-excursion
  7352. (org-show-context 'agenda))
  7353. (save-excursion
  7354. (and (outline-next-heading)
  7355. (org-flag-heading nil))) ; show the next heading
  7356. (goto-char pos)
  7357. (call-interactively 'org-set-effort)
  7358. (end-of-line 1)
  7359. (setq newhead (org-get-heading)))
  7360. (org-agenda-change-all-lines newhead hdmarker))))
  7361. (defun org-agenda-toggle-archive-tag ()
  7362. "Toggle the archive tag for the current entry."
  7363. (interactive)
  7364. (org-agenda-check-no-diary)
  7365. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7366. (org-agenda-error)))
  7367. (buffer (marker-buffer hdmarker))
  7368. (pos (marker-position hdmarker))
  7369. (inhibit-read-only t)
  7370. newhead)
  7371. (org-with-remote-undo buffer
  7372. (with-current-buffer buffer
  7373. (widen)
  7374. (goto-char pos)
  7375. (org-show-context 'agenda)
  7376. (save-excursion
  7377. (and (outline-next-heading)
  7378. (org-flag-heading nil))) ; show the next heading
  7379. (call-interactively 'org-toggle-archive-tag)
  7380. (end-of-line 1)
  7381. (setq newhead (org-get-heading)))
  7382. (org-agenda-change-all-lines newhead hdmarker)
  7383. (beginning-of-line 1))))
  7384. (defun org-agenda-do-date-later (arg)
  7385. (interactive "P")
  7386. (cond
  7387. ((or (equal arg '(16))
  7388. (memq last-command
  7389. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7390. (setq this-command 'org-agenda-date-later-minutes)
  7391. (org-agenda-date-later-minutes 1))
  7392. ((or (equal arg '(4))
  7393. (memq last-command
  7394. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7395. (setq this-command 'org-agenda-date-later-hours)
  7396. (org-agenda-date-later-hours 1))
  7397. (t
  7398. (org-agenda-date-later (prefix-numeric-value arg)))))
  7399. (defun org-agenda-do-date-earlier (arg)
  7400. (interactive "P")
  7401. (cond
  7402. ((or (equal arg '(16))
  7403. (memq last-command
  7404. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7405. (setq this-command 'org-agenda-date-earlier-minutes)
  7406. (org-agenda-date-earlier-minutes 1))
  7407. ((or (equal arg '(4))
  7408. (memq last-command
  7409. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7410. (setq this-command 'org-agenda-date-earlier-hours)
  7411. (org-agenda-date-earlier-hours 1))
  7412. (t
  7413. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7414. (defun org-agenda-date-later (arg &optional what)
  7415. "Change the date of this item to ARG day(s) later."
  7416. (interactive "p")
  7417. (org-agenda-check-type t 'agenda 'timeline)
  7418. (org-agenda-check-no-diary)
  7419. (let* ((marker (or (org-get-at-bol 'org-marker)
  7420. (org-agenda-error)))
  7421. (buffer (marker-buffer marker))
  7422. (pos (marker-position marker))
  7423. cdate today)
  7424. (org-with-remote-undo buffer
  7425. (with-current-buffer buffer
  7426. (widen)
  7427. (goto-char pos)
  7428. (if (not (org-at-timestamp-p))
  7429. (error "Cannot find time stamp"))
  7430. (when (and org-agenda-move-date-from-past-immediately-to-today
  7431. (equal arg 1)
  7432. (or (not what) (eq what 'day))
  7433. (not (save-match-data (org-at-date-range-p))))
  7434. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7435. cdate (calendar-absolute-from-gregorian
  7436. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7437. today (org-today))
  7438. (if (> today cdate)
  7439. ;; immediately shift to today
  7440. (setq arg (- today cdate))))
  7441. (org-timestamp-change arg (or what 'day))
  7442. (when (and (org-at-date-range-p)
  7443. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7444. (let ((end org-last-changed-timestamp))
  7445. (org-timestamp-change arg (or what 'day))
  7446. (setq org-last-changed-timestamp
  7447. (concat org-last-changed-timestamp "--" end)))))
  7448. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7449. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7450. (defun org-agenda-date-earlier (arg &optional what)
  7451. "Change the date of this item to ARG day(s) earlier."
  7452. (interactive "p")
  7453. (org-agenda-date-later (- arg) what))
  7454. (defun org-agenda-date-later-minutes (arg)
  7455. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7456. (interactive "p")
  7457. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7458. (org-agenda-date-later arg 'minute))
  7459. (defun org-agenda-date-earlier-minutes (arg)
  7460. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7461. (interactive "p")
  7462. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7463. (org-agenda-date-earlier arg 'minute))
  7464. (defun org-agenda-date-later-hours (arg)
  7465. "Change the time of this item, in hour steps."
  7466. (interactive "p")
  7467. (org-agenda-date-later arg 'hour))
  7468. (defun org-agenda-date-earlier-hours (arg)
  7469. "Change the time of this item, in hour steps."
  7470. (interactive "p")
  7471. (org-agenda-date-earlier arg 'hour))
  7472. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7473. "Show new date stamp via text properties."
  7474. ;; We use text properties to make this undoable
  7475. (let ((inhibit-read-only t)
  7476. (buffer-invisibility-spec))
  7477. (setq stamp (concat " " prefix " => " stamp))
  7478. (save-excursion
  7479. (goto-char (point-max))
  7480. (while (not (bobp))
  7481. (when (equal marker (org-get-at-bol 'org-marker))
  7482. (org-move-to-column (- (window-width) (length stamp)) t)
  7483. (org-agenda-fix-tags-filter-overlays-at (point))
  7484. (if (featurep 'xemacs)
  7485. ;; Use `duplicable' property to trigger undo recording
  7486. (let ((ex (make-extent nil nil))
  7487. (gl (make-glyph stamp)))
  7488. (set-glyph-face gl 'secondary-selection)
  7489. (set-extent-properties
  7490. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7491. (insert-extent ex (1- (point)) (point-at-eol)))
  7492. (add-text-properties
  7493. (1- (point)) (point-at-eol)
  7494. (list 'display (org-add-props stamp nil
  7495. 'face 'secondary-selection))))
  7496. (beginning-of-line 1))
  7497. (beginning-of-line 0)))))
  7498. (defun org-agenda-date-prompt (arg)
  7499. "Change the date of this item. Date is prompted for, with default today.
  7500. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7501. be used to request time specification in the time stamp."
  7502. (interactive "P")
  7503. (org-agenda-check-type t 'agenda 'timeline)
  7504. (org-agenda-check-no-diary)
  7505. (let* ((marker (or (org-get-at-bol 'org-marker)
  7506. (org-agenda-error)))
  7507. (buffer (marker-buffer marker))
  7508. (pos (marker-position marker)))
  7509. (org-with-remote-undo buffer
  7510. (with-current-buffer buffer
  7511. (widen)
  7512. (goto-char pos)
  7513. (if (not (org-at-timestamp-p t))
  7514. (error "Cannot find time stamp"))
  7515. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7516. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7517. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7518. (defun org-agenda-schedule (arg &optional time)
  7519. "Schedule the item at point.
  7520. ARG is passed through to `org-schedule'."
  7521. (interactive "P")
  7522. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7523. (org-agenda-check-no-diary)
  7524. (let* ((marker (or (org-get-at-bol 'org-marker)
  7525. (org-agenda-error)))
  7526. (type (marker-insertion-type marker))
  7527. (buffer (marker-buffer marker))
  7528. (pos (marker-position marker))
  7529. (org-insert-labeled-timestamps-at-point nil)
  7530. ts)
  7531. (set-marker-insertion-type marker t)
  7532. (org-with-remote-undo buffer
  7533. (with-current-buffer buffer
  7534. (widen)
  7535. (goto-char pos)
  7536. (setq ts (org-schedule arg time)))
  7537. (org-agenda-show-new-time marker ts "S"))
  7538. (message "Item scheduled for %s" ts)))
  7539. (defun org-agenda-deadline (arg &optional time)
  7540. "Schedule the item at point.
  7541. ARG is passed through to `org-deadline'."
  7542. (interactive "P")
  7543. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7544. (org-agenda-check-no-diary)
  7545. (let* ((marker (or (org-get-at-bol 'org-marker)
  7546. (org-agenda-error)))
  7547. (buffer (marker-buffer marker))
  7548. (pos (marker-position marker))
  7549. (org-insert-labeled-timestamps-at-point nil)
  7550. ts)
  7551. (org-with-remote-undo buffer
  7552. (with-current-buffer buffer
  7553. (widen)
  7554. (goto-char pos)
  7555. (setq ts (org-deadline arg time)))
  7556. (org-agenda-show-new-time marker ts "D"))
  7557. (message "Deadline for this item set to %s" ts)))
  7558. (defun org-agenda-action ()
  7559. "Select entry for agenda action, or execute an agenda action.
  7560. This command prompts for another letter. Valid inputs are:
  7561. m Mark the entry at point for an agenda action
  7562. s Schedule the marked entry to the date at the cursor
  7563. d Set the deadline of the marked entry to the date at the cursor
  7564. r Call `org-remember' with cursor date as the default date
  7565. c Call `org-capture' with cursor date as the default date
  7566. SPC Show marked entry in other window
  7567. TAB Visit marked entry in other window
  7568. The cursor may be at a date in the calendar, or in the Org agenda."
  7569. (interactive)
  7570. (let (ans)
  7571. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7572. (setq ans (read-char-exclusive))
  7573. (cond
  7574. ((equal ans ?m)
  7575. ;; Mark this entry
  7576. (if (eq major-mode 'org-agenda-mode)
  7577. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7578. (org-get-at-bol 'org-marker))))
  7579. (if m
  7580. (progn
  7581. (move-marker org-agenda-action-marker
  7582. (marker-position m) (marker-buffer m))
  7583. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7584. (error "Don't know which entry to mark")))
  7585. (error "This command works only in the agenda")))
  7586. ((equal ans ?s)
  7587. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7588. ((equal ans ?d)
  7589. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7590. ((equal ans ?r)
  7591. (org-agenda-do-action '(org-remember) t))
  7592. ((equal ans ?c)
  7593. (org-agenda-do-action '(org-capture) t))
  7594. ((equal ans ?\ )
  7595. (let ((cw (selected-window)))
  7596. (org-switch-to-buffer-other-window
  7597. (marker-buffer org-agenda-action-marker))
  7598. (goto-char org-agenda-action-marker)
  7599. (org-show-context 'agenda)
  7600. (select-window cw)))
  7601. ((equal ans ?\C-i)
  7602. (org-switch-to-buffer-other-window
  7603. (marker-buffer org-agenda-action-marker))
  7604. (goto-char org-agenda-action-marker)
  7605. (org-show-context 'agenda))
  7606. (t (error "Invalid agenda action %c" ans)))))
  7607. (defun org-agenda-do-action (form &optional current-buffer)
  7608. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7609. (let ((org-overriding-default-time (org-get-cursor-date)))
  7610. (if current-buffer
  7611. (eval form)
  7612. (if (not (marker-buffer org-agenda-action-marker))
  7613. (error "No entry has been selected for agenda action")
  7614. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7615. (save-excursion
  7616. (save-restriction
  7617. (widen)
  7618. (goto-char org-agenda-action-marker)
  7619. (eval form))))))))
  7620. (defun org-agenda-clock-in (&optional arg)
  7621. "Start the clock on the currently selected item."
  7622. (interactive "P")
  7623. (org-agenda-check-no-diary)
  7624. (if (equal arg '(4))
  7625. (org-clock-in arg)
  7626. (let* ((marker (or (org-get-at-bol 'org-marker)
  7627. (org-agenda-error)))
  7628. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7629. marker))
  7630. (pos (marker-position marker))
  7631. newhead)
  7632. (org-with-remote-undo (marker-buffer marker)
  7633. (with-current-buffer (marker-buffer marker)
  7634. (widen)
  7635. (goto-char pos)
  7636. (org-show-context 'agenda)
  7637. (org-show-entry)
  7638. (org-cycle-hide-drawers 'children)
  7639. (org-clock-in arg)
  7640. (setq newhead (org-get-heading)))
  7641. (org-agenda-change-all-lines newhead hdmarker)))))
  7642. (defun org-agenda-clock-out ()
  7643. "Stop the currently running clock."
  7644. (interactive)
  7645. (unless (marker-buffer org-clock-marker)
  7646. (error "No running clock"))
  7647. (let ((marker (make-marker)) newhead)
  7648. (org-with-remote-undo (marker-buffer org-clock-marker)
  7649. (with-current-buffer (marker-buffer org-clock-marker)
  7650. (save-excursion
  7651. (save-restriction
  7652. (widen)
  7653. (goto-char org-clock-marker)
  7654. (org-back-to-heading t)
  7655. (move-marker marker (point))
  7656. (org-clock-out)
  7657. (setq newhead (org-get-heading))))))
  7658. (org-agenda-change-all-lines newhead marker)
  7659. (move-marker marker nil)))
  7660. (defun org-agenda-clock-cancel (&optional arg)
  7661. "Cancel the currently running clock."
  7662. (interactive "P")
  7663. (unless (marker-buffer org-clock-marker)
  7664. (error "No running clock"))
  7665. (org-with-remote-undo (marker-buffer org-clock-marker)
  7666. (org-clock-cancel)))
  7667. (defun org-agenda-clock-goto ()
  7668. "Jump to the currently clocked in task within the agenda.
  7669. If the currently clocked in task is not listed in the agenda
  7670. buffer, display it in another window."
  7671. (interactive)
  7672. (let (pos)
  7673. (mapc (lambda (o)
  7674. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7675. (setq pos (overlay-start o))))
  7676. (overlays-in (point-min) (point-max)))
  7677. (cond (pos (goto-char pos))
  7678. ;; If the currently clocked entry is not in the agenda
  7679. ;; buffer, we visit it in another window:
  7680. (org-clock-current-task
  7681. (org-switch-to-buffer-other-window (org-clock-goto)))
  7682. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7683. (defun org-agenda-diary-entry-in-org-file ()
  7684. "Make a diary entry in the file `org-agenda-diary-file'."
  7685. (let (d1 d2 char (text "") dp1 dp2)
  7686. (if (equal (buffer-name) "*Calendar*")
  7687. (setq d1 (calendar-cursor-to-date t)
  7688. d2 (car calendar-mark-ring))
  7689. (setq dp1 (get-text-property (point-at-bol) 'day))
  7690. (unless dp1 (error "No date defined in current line"))
  7691. (setq d1 (calendar-gregorian-from-absolute dp1)
  7692. d2 (and (ignore-errors (mark))
  7693. (save-excursion
  7694. (goto-char (mark))
  7695. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7696. (calendar-gregorian-from-absolute dp2))))
  7697. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7698. (setq char (read-char-exclusive))
  7699. (cond
  7700. ((equal char ?d)
  7701. (setq text (read-string "Day entry: "))
  7702. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7703. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7704. ((equal char ?a)
  7705. (setq d1 (list (car d1) (nth 1 d1)
  7706. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7707. (nth 2 d1))))
  7708. (setq text (read-string "Anniversary (use %d to show years): "))
  7709. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7710. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7711. ((equal char ?b)
  7712. (setq text (read-string "Block entry: "))
  7713. (unless (and d1 d2 (not (equal d1 d2)))
  7714. (error "No block of days selected"))
  7715. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7716. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7717. ((equal char ?j)
  7718. (org-switch-to-buffer-other-window
  7719. (find-file-noselect org-agenda-diary-file))
  7720. (require 'org-datetree)
  7721. (org-datetree-find-date-create d1)
  7722. (org-reveal t))
  7723. (t (error "Invalid selection character `%c'" char)))))
  7724. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7725. "Where in `org-agenda-diary-file' should new entries be added?
  7726. Valid values:
  7727. date-tree in the date tree, as child of the date
  7728. top-level as top-level entries at the end of the file."
  7729. :group 'org-agenda
  7730. :type '(choice
  7731. (const :tag "in a date tree" date-tree)
  7732. (const :tag "as top level at end of file" top-level)))
  7733. (defcustom org-agenda-insert-diary-extract-time nil
  7734. "Non-nil means extract any time specification from the diary entry."
  7735. :group 'org-agenda
  7736. :version "24.1"
  7737. :type 'boolean)
  7738. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7739. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7740. If TEXT is not empty, it will become the headline of the new entry, and
  7741. the resulting entry will not be shown. When TEXT is empty, switch to
  7742. `org-agenda-diary-file' and let the user finish the entry there."
  7743. (let ((cw (current-window-configuration)))
  7744. (org-switch-to-buffer-other-window
  7745. (find-file-noselect org-agenda-diary-file))
  7746. (widen)
  7747. (goto-char (point-min))
  7748. (cond
  7749. ((eq type 'anniversary)
  7750. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7751. (progn
  7752. (or (org-at-heading-p t)
  7753. (progn
  7754. (outline-next-heading)
  7755. (insert "* Anniversaries\n\n")
  7756. (beginning-of-line -1)))))
  7757. (outline-next-heading)
  7758. (org-back-over-empty-lines)
  7759. (backward-char 1)
  7760. (insert "\n")
  7761. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7762. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7763. ((eq type 'day)
  7764. (let ((org-prefix-has-time t)
  7765. (org-agenda-time-leading-zero t)
  7766. fmt time time2)
  7767. (if org-agenda-insert-diary-extract-time
  7768. ;; Use org-agenda-format-item to parse text for a time-range and
  7769. ;; remove it. FIXME: This is a hack, we should refactor
  7770. ;; that function to make time extraction available separately
  7771. (setq fmt (org-agenda-format-item nil text nil nil t)
  7772. time (get-text-property 0 'time fmt)
  7773. time2 (if (> (length time) 0)
  7774. ;; split-string removes trailing ...... if
  7775. ;; no end time given. First space
  7776. ;; separates time from date.
  7777. (concat " " (car (split-string time "\\.")))
  7778. nil)
  7779. text (get-text-property 0 'txt fmt)))
  7780. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7781. (org-agenda-insert-diary-as-top-level text)
  7782. (require 'org-datetree)
  7783. (org-datetree-find-date-create d1)
  7784. (org-agenda-insert-diary-make-new-entry text))
  7785. (org-insert-time-stamp (org-time-from-absolute
  7786. (calendar-absolute-from-gregorian d1))
  7787. nil nil nil nil time2))
  7788. (end-of-line 0))
  7789. ((eq type 'block)
  7790. (if (> (calendar-absolute-from-gregorian d1)
  7791. (calendar-absolute-from-gregorian d2))
  7792. (setq d1 (prog1 d2 (setq d2 d1))))
  7793. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7794. (org-agenda-insert-diary-as-top-level text)
  7795. (require 'org-datetree)
  7796. (org-datetree-find-date-create d1)
  7797. (org-agenda-insert-diary-make-new-entry text))
  7798. (org-insert-time-stamp (org-time-from-absolute
  7799. (calendar-absolute-from-gregorian d1)))
  7800. (insert "--")
  7801. (org-insert-time-stamp (org-time-from-absolute
  7802. (calendar-absolute-from-gregorian d2)))
  7803. (end-of-line 0)))
  7804. (if (string-match "\\S-" text)
  7805. (progn
  7806. (set-window-configuration cw)
  7807. (message "%s entry added to %s"
  7808. (capitalize (symbol-name type))
  7809. (abbreviate-file-name org-agenda-diary-file)))
  7810. (org-reveal t)
  7811. (message "Please finish entry here"))))
  7812. (defun org-agenda-insert-diary-as-top-level (text)
  7813. "Make new entry as a top-level entry at the end of the file.
  7814. Add TEXT as headline, and position the cursor in the second line so that
  7815. a timestamp can be added there."
  7816. (widen)
  7817. (goto-char (point-max))
  7818. (or (bolp) (insert "\n"))
  7819. (insert "* " text "\n")
  7820. (if org-adapt-indentation (org-indent-to-column 2)))
  7821. (defun org-agenda-insert-diary-make-new-entry (text)
  7822. "Make new entry as last child of current entry.
  7823. Add TEXT as headline, and position the cursor in the second line so that
  7824. a timestamp can be added there."
  7825. (let ((org-show-following-heading t)
  7826. (org-show-siblings t)
  7827. (org-show-hierarchy-above t)
  7828. (org-show-entry-below t)
  7829. col)
  7830. (outline-next-heading)
  7831. (org-back-over-empty-lines)
  7832. (or (looking-at "[ \t]*$")
  7833. (progn (insert "\n") (backward-char 1)))
  7834. (org-insert-heading nil t)
  7835. (org-do-demote)
  7836. (setq col (current-column))
  7837. (insert text "\n")
  7838. (if org-adapt-indentation (org-indent-to-column col))
  7839. (let ((org-show-following-heading t)
  7840. (org-show-siblings t)
  7841. (org-show-hierarchy-above t)
  7842. (org-show-entry-below t))
  7843. (org-show-context))))
  7844. (defun org-agenda-diary-entry ()
  7845. "Make a diary entry, like the `i' command from the calendar.
  7846. All the standard commands work: block, weekly etc.
  7847. When `org-agenda-diary-file' points to a file,
  7848. `org-agenda-diary-entry-in-org-file' is called instead to create
  7849. entries in that Org-mode file."
  7850. (interactive)
  7851. (org-agenda-check-type t 'agenda 'timeline)
  7852. (if (not (eq org-agenda-diary-file 'diary-file))
  7853. (org-agenda-diary-entry-in-org-file)
  7854. (require 'diary-lib)
  7855. (let* ((char (progn
  7856. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7857. (read-char-exclusive)))
  7858. (cmd (cdr (assoc char
  7859. '((?d . insert-diary-entry)
  7860. (?w . insert-weekly-diary-entry)
  7861. (?m . insert-monthly-diary-entry)
  7862. (?y . insert-yearly-diary-entry)
  7863. (?a . insert-anniversary-diary-entry)
  7864. (?b . insert-block-diary-entry)
  7865. (?c . insert-cyclic-diary-entry)))))
  7866. (oldf (symbol-function 'calendar-cursor-to-date))
  7867. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7868. (point (point))
  7869. (mark (or (mark t) (point))))
  7870. (unless cmd
  7871. (error "No command associated with <%c>" char))
  7872. (unless (and (get-text-property point 'day)
  7873. (or (not (equal ?b char))
  7874. (get-text-property mark 'day)))
  7875. (error "Don't know which date to use for diary entry"))
  7876. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7877. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7878. (let ((calendar-mark-ring
  7879. (list (calendar-gregorian-from-absolute
  7880. (or (get-text-property mark 'day)
  7881. (get-text-property point 'day))))))
  7882. (unwind-protect
  7883. (progn
  7884. (fset 'calendar-cursor-to-date
  7885. (lambda (&optional error dummy)
  7886. (calendar-gregorian-from-absolute
  7887. (get-text-property point 'day))))
  7888. (call-interactively cmd))
  7889. (fset 'calendar-cursor-to-date oldf))))))
  7890. (defun org-agenda-execute-calendar-command (cmd)
  7891. "Execute a calendar command from the agenda, with the date associated to
  7892. the cursor position."
  7893. (org-agenda-check-type t 'agenda 'timeline)
  7894. (require 'diary-lib)
  7895. (unless (get-text-property (point) 'day)
  7896. (error "Don't know which date to use for calendar command"))
  7897. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7898. (point (point))
  7899. (date (calendar-gregorian-from-absolute
  7900. (get-text-property point 'day)))
  7901. ;; the following 2 vars are needed in the calendar
  7902. (displayed-month (car date))
  7903. (displayed-year (nth 2 date)))
  7904. (unwind-protect
  7905. (progn
  7906. (fset 'calendar-cursor-to-date
  7907. (lambda (&optional error dummy)
  7908. (calendar-gregorian-from-absolute
  7909. (get-text-property point 'day))))
  7910. (call-interactively cmd))
  7911. (fset 'calendar-cursor-to-date oldf))))
  7912. (defun org-agenda-phases-of-moon ()
  7913. "Display the phases of the moon for the 3 months around the cursor date."
  7914. (interactive)
  7915. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7916. (defun org-agenda-holidays ()
  7917. "Display the holidays for the 3 months around the cursor date."
  7918. (interactive)
  7919. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7920. (defvar calendar-longitude)
  7921. (defvar calendar-latitude)
  7922. (defvar calendar-location-name)
  7923. (defun org-agenda-sunrise-sunset (arg)
  7924. "Display sunrise and sunset for the cursor date.
  7925. Latitude and longitude can be specified with the variables
  7926. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7927. argument, latitude and longitude will be prompted for."
  7928. (interactive "P")
  7929. (require 'solar)
  7930. (let ((calendar-longitude (if arg nil calendar-longitude))
  7931. (calendar-latitude (if arg nil calendar-latitude))
  7932. (calendar-location-name
  7933. (if arg "the given coordinates" calendar-location-name)))
  7934. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7935. (defun org-agenda-goto-calendar ()
  7936. "Open the Emacs calendar with the date at the cursor."
  7937. (interactive)
  7938. (org-agenda-check-type t 'agenda 'timeline)
  7939. (let* ((day (or (get-text-property (point) 'day)
  7940. (error "Don't know which date to open in calendar")))
  7941. (date (calendar-gregorian-from-absolute day))
  7942. (calendar-move-hook nil)
  7943. (calendar-view-holidays-initially-flag nil)
  7944. (calendar-view-diary-initially-flag nil))
  7945. (calendar)
  7946. (calendar-goto-date date)))
  7947. ;;;###autoload
  7948. (defun org-calendar-goto-agenda ()
  7949. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7950. This is a command that has to be installed in `calendar-mode-map'."
  7951. (interactive)
  7952. (org-agenda-list nil (calendar-absolute-from-gregorian
  7953. (calendar-cursor-to-date))
  7954. nil))
  7955. (defun org-agenda-convert-date ()
  7956. (interactive)
  7957. (org-agenda-check-type t 'agenda 'timeline)
  7958. (let ((day (get-text-property (point) 'day))
  7959. date s)
  7960. (unless day
  7961. (error "Don't know which date to convert"))
  7962. (setq date (calendar-gregorian-from-absolute day))
  7963. (setq s (concat
  7964. "Gregorian: " (calendar-date-string date) "\n"
  7965. "ISO: " (calendar-iso-date-string date) "\n"
  7966. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7967. "Julian: " (calendar-julian-date-string date) "\n"
  7968. "Astron. JD: " (calendar-astro-date-string date)
  7969. " (Julian date number at noon UTC)\n"
  7970. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7971. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7972. "French: " (calendar-french-date-string date) "\n"
  7973. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7974. "Mayan: " (calendar-mayan-date-string date) "\n"
  7975. "Coptic: " (calendar-coptic-date-string date) "\n"
  7976. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7977. "Persian: " (calendar-persian-date-string date) "\n"
  7978. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7979. (with-output-to-temp-buffer "*Dates*"
  7980. (princ s))
  7981. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7982. ;;; Bulk commands
  7983. (defvar org-agenda-bulk-marked-entries nil
  7984. "List of markers that refer to marked entries in the agenda.")
  7985. (defun org-agenda-bulk-marked-p ()
  7986. (eq (get-char-property (point-at-bol) 'type)
  7987. 'org-marked-entry-overlay))
  7988. (defun org-agenda-bulk-mark (&optional arg)
  7989. "Mark the entry at point for future bulk action."
  7990. (interactive "p")
  7991. (dotimes (i (or arg 1))
  7992. (unless (org-get-at-bol 'org-agenda-diary-link)
  7993. (let* ((m (org-get-at-bol 'org-hd-marker))
  7994. ov)
  7995. (unless (org-agenda-bulk-marked-p)
  7996. (unless m (error "Nothing to mark at point"))
  7997. (push m org-agenda-bulk-marked-entries)
  7998. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7999. (org-overlay-display ov "> "
  8000. (org-get-todo-face "TODO")
  8001. 'evaporate)
  8002. (overlay-put ov 'type 'org-marked-entry-overlay))
  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-mark-regexp (regexp)
  8009. "Mark entries match REGEXP."
  8010. (interactive "sMark entries matching regexp: ")
  8011. (let (entries-marked)
  8012. (save-excursion
  8013. (goto-char (point-min))
  8014. (goto-char (next-single-property-change (point) 'txt))
  8015. (while (re-search-forward regexp nil t)
  8016. (when (string-match regexp (get-text-property (point) 'txt))
  8017. (setq entries-marked (+ entries-marked 1))
  8018. (call-interactively 'org-agenda-bulk-mark))))
  8019. (if (not entries-marked)
  8020. (message "No entry matching this regexp."))))
  8021. (defun org-agenda-bulk-unmark ()
  8022. "Unmark the entry at point for future bulk action."
  8023. (interactive)
  8024. (when (org-agenda-bulk-marked-p)
  8025. (org-agenda-bulk-remove-overlays
  8026. (point-at-bol) (+ 2 (point-at-bol)))
  8027. (setq org-agenda-bulk-marked-entries
  8028. (delete (org-get-at-bol 'org-hd-marker)
  8029. org-agenda-bulk-marked-entries)))
  8030. (beginning-of-line 2)
  8031. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8032. (beginning-of-line 2))
  8033. (message "%d entries marked for bulk action"
  8034. (length org-agenda-bulk-marked-entries)))
  8035. (defun org-agenda-bulk-toggle ()
  8036. "Toggle marking the entry at point for bulk action."
  8037. (interactive)
  8038. (if (org-agenda-bulk-marked-p)
  8039. (org-agenda-bulk-unmark)
  8040. (org-agenda-bulk-mark)))
  8041. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8042. "Remove the mark overlays between BEG and END in the agenda buffer.
  8043. BEG and END default to the buffer limits.
  8044. This only removes the overlays, it does not remove the markers
  8045. from the list in `org-agenda-bulk-marked-entries'."
  8046. (interactive)
  8047. (mapc (lambda (ov)
  8048. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8049. (delete-overlay ov)))
  8050. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8051. (defun org-agenda-bulk-remove-all-marks ()
  8052. "Remove all marks in the agenda buffer.
  8053. This will remove the markers, and the overlays."
  8054. (interactive)
  8055. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8056. (setq org-agenda-bulk-marked-entries nil)
  8057. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  8058. (defun org-agenda-bulk-action (&optional arg)
  8059. "Execute an remote-editing action on all marked entries.
  8060. The prefix arg is passed through to the command if possible."
  8061. (interactive "P")
  8062. ;; Make sure we have markers, and only valid ones
  8063. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8064. (mapc
  8065. (lambda (m)
  8066. (unless (and (markerp m)
  8067. (marker-buffer m)
  8068. (buffer-live-p (marker-buffer m))
  8069. (marker-position m))
  8070. (error "Marker %s for bulk command is invalid" m)))
  8071. org-agenda-bulk-marked-entries)
  8072. ;; Prompt for the bulk command
  8073. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  8074. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  8075. (when org-agenda-bulk-custom-functions
  8076. (concat " Custom: ["
  8077. (mapconcat (lambda(f) (char-to-string (car f)))
  8078. org-agenda-bulk-custom-functions "")
  8079. "]"))))
  8080. (let* ((action (read-char-exclusive))
  8081. (org-log-refile (if org-log-refile 'time nil))
  8082. (entries (reverse org-agenda-bulk-marked-entries))
  8083. redo-at-end
  8084. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8085. (cond
  8086. ((equal action ?$)
  8087. (setq cmd '(org-agenda-archive)))
  8088. ((equal action ?A)
  8089. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8090. ((member action '(?r ?w))
  8091. (setq rfloc (org-refile-get-location
  8092. "Refile to"
  8093. (marker-buffer (car org-agenda-bulk-marked-entries))
  8094. org-refile-allow-creating-parent-nodes))
  8095. (if (nth 3 rfloc)
  8096. (setcar (nthcdr 3 rfloc)
  8097. (move-marker (make-marker) (nth 3 rfloc)
  8098. (or (get-file-buffer (nth 1 rfloc))
  8099. (find-buffer-visiting (nth 1 rfloc))
  8100. (error "This should not happen")))))
  8101. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8102. redo-at-end t))
  8103. ((equal action ?t)
  8104. (setq state (org-icompleting-read
  8105. "Todo state: "
  8106. (with-current-buffer (marker-buffer (car entries))
  8107. (mapcar 'list org-todo-keywords-1))))
  8108. (setq cmd `(let ((org-inhibit-blocking t)
  8109. (org-inhibit-logging 'note))
  8110. (org-agenda-todo ,state))))
  8111. ((memq action '(?- ?+))
  8112. (setq tag (org-icompleting-read
  8113. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8114. (with-current-buffer (marker-buffer (car entries))
  8115. (delq nil
  8116. (mapcar (lambda (x)
  8117. (if (stringp (car x)) x)) org-tag-alist)))))
  8118. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8119. ((memq action '(?s ?d))
  8120. (let* ((date (unless arg
  8121. (org-read-date
  8122. nil nil nil
  8123. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8124. (ans (if arg nil org-read-date-final-answer))
  8125. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8126. (setq cmd `(let* ((bound (fboundp 'read-string))
  8127. (old (and bound (symbol-function 'read-string))))
  8128. (unwind-protect
  8129. (progn
  8130. (fset 'read-string (lambda (&rest ignore) ,ans))
  8131. (eval '(,c1 arg)))
  8132. (if bound
  8133. (fset 'read-string old)
  8134. (fmakunbound 'read-string)))))))
  8135. ((equal action ?S)
  8136. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8137. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8138. (let ((days (read-number
  8139. (format "Scatter tasks across how many %sdays: "
  8140. (if arg "week" "")) 7)))
  8141. (setq cmd
  8142. `(let ((distance (1+ (random ,days))))
  8143. (if arg
  8144. (let ((dist distance)
  8145. (day-of-week
  8146. (calendar-day-of-week
  8147. (calendar-gregorian-from-absolute (org-today)))))
  8148. (dotimes (i (1+ dist))
  8149. (while (member day-of-week org-agenda-weekend-days)
  8150. (incf distance)
  8151. (incf day-of-week)
  8152. (if (= day-of-week 7)
  8153. (setq day-of-week 0)))
  8154. (incf day-of-week)
  8155. (if (= day-of-week 7)
  8156. (setq day-of-week 0)))))
  8157. ;; silently fail when try to replan a sexp entry
  8158. (condition-case nil
  8159. (let* ((date (calendar-gregorian-from-absolute
  8160. (+ (org-today) distance)))
  8161. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8162. (nth 2 date))))
  8163. (org-agenda-schedule nil time))
  8164. (error nil)))))))
  8165. ((assoc action org-agenda-bulk-custom-functions)
  8166. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8167. redo-at-end t))
  8168. ((equal action ?f)
  8169. (setq cmd (list (intern
  8170. (org-icompleting-read "Function: "
  8171. obarray 'fboundp t nil nil)))))
  8172. (t (error "Invalid bulk action")))
  8173. ;; Sort the markers, to make sure that parents are handled before children
  8174. (setq entries (sort entries
  8175. (lambda (a b)
  8176. (cond
  8177. ((equal (marker-buffer a) (marker-buffer b))
  8178. (< (marker-position a) (marker-position b)))
  8179. (t
  8180. (string< (buffer-name (marker-buffer a))
  8181. (buffer-name (marker-buffer b))))))))
  8182. ;; Now loop over all markers and apply cmd
  8183. (while (setq e (pop entries))
  8184. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8185. (if (not pos)
  8186. (progn (message "Skipping removed entry at %s" e)
  8187. (setq cntskip (1+ cntskip)))
  8188. (goto-char pos)
  8189. (let (org-loop-over-headlines-in-active-region)
  8190. (eval cmd))
  8191. (setq org-agenda-bulk-marked-entries
  8192. (delete e org-agenda-bulk-marked-entries))
  8193. (setq cnt (1+ cnt))))
  8194. (setq org-agenda-bulk-marked-entries nil)
  8195. (org-agenda-bulk-remove-all-marks)
  8196. (when redo-at-end (org-agenda-redo))
  8197. (message "Acted on %d entries%s"
  8198. cnt
  8199. (if (= cntskip 0)
  8200. ""
  8201. (format ", skipped %d (disappeared before their turn)"
  8202. cntskip)))))
  8203. ;;; Flagging notes
  8204. (defun org-agenda-show-the-flagging-note ()
  8205. "Display the flagging note in the other window.
  8206. When called a second time in direct sequence, offer to remove the FLAGGING
  8207. tag and (if present) the flagging note."
  8208. (interactive)
  8209. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8210. (win (selected-window))
  8211. note heading newhead)
  8212. (unless hdmarker
  8213. (error "No linked entry at point"))
  8214. (if (and (eq this-command last-command)
  8215. (y-or-n-p "Unflag and remove any flagging note? "))
  8216. (progn
  8217. (org-agenda-remove-flag hdmarker)
  8218. (let ((win (get-buffer-window "*Flagging Note*")))
  8219. (and win (delete-window win)))
  8220. (message "Entry unflagged"))
  8221. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8222. (unless note
  8223. (error "No flagging note"))
  8224. (org-kill-new note)
  8225. (org-switch-to-buffer-other-window "*Flagging Note*")
  8226. (erase-buffer)
  8227. (insert note)
  8228. (goto-char (point-min))
  8229. (while (re-search-forward "\\\\n" nil t)
  8230. (replace-match "\n" t t))
  8231. (goto-char (point-min))
  8232. (select-window win)
  8233. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8234. (defun org-agenda-remove-flag (marker)
  8235. "Remove the FLAGGED tag and any flagging note in the entry."
  8236. (let (newhead)
  8237. (org-with-point-at marker
  8238. (org-toggle-tag "FLAGGED" 'off)
  8239. (org-entry-delete nil "THEFLAGGINGNOTE")
  8240. (setq newhead (org-get-heading)))
  8241. (org-agenda-change-all-lines newhead marker)
  8242. (message "Entry unflagged")))
  8243. (defun org-agenda-get-any-marker (&optional pos)
  8244. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8245. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8246. ;;; Appointment reminders
  8247. (defvar appt-time-msg-list)
  8248. ;;;###autoload
  8249. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8250. "Activate appointments found in `org-agenda-files'.
  8251. With a \\[universal-argument] prefix, refresh the list of
  8252. appointments.
  8253. If FILTER is t, interactively prompt the user for a regular
  8254. expression, and filter out entries that don't match it.
  8255. If FILTER is a string, use this string as a regular expression
  8256. for filtering entries out.
  8257. If FILTER is a function, filter out entries against which
  8258. calling the function returns nil. This function takes one
  8259. argument: an entry from `org-agenda-get-day-entries'.
  8260. FILTER can also be an alist with the car of each cell being
  8261. either 'headline or 'category. For example:
  8262. '((headline \"IMPORTANT\")
  8263. (category \"Work\"))
  8264. will only add headlines containing IMPORTANT or headlines
  8265. belonging to the \"Work\" category.
  8266. ARGS are symbols indicating what kind of entries to consider.
  8267. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8268. and :timestamp entries. See the docstring of `org-diary' for
  8269. details and examples."
  8270. (interactive "P")
  8271. (if refresh (setq appt-time-msg-list nil))
  8272. (if (eq filter t)
  8273. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8274. (let* ((cnt 0) ; count added events
  8275. (scope (or args '(:deadline :scheduled :timestamp)))
  8276. (org-agenda-new-buffers nil)
  8277. (org-deadline-warning-days 0)
  8278. ;; Do not use `org-today' here because appt only takes
  8279. ;; time and without date as argument, so it may pass wrong
  8280. ;; information otherwise
  8281. (today (org-date-to-gregorian
  8282. (time-to-days (current-time))))
  8283. (org-agenda-restrict nil)
  8284. (files (org-agenda-files 'unrestricted)) entries file
  8285. (org-agenda-buffer nil))
  8286. ;; Get all entries which may contain an appt
  8287. (org-prepare-agenda-buffers files)
  8288. (while (setq file (pop files))
  8289. (setq entries
  8290. (delq nil
  8291. (append entries
  8292. (apply 'org-agenda-get-day-entries
  8293. file today scope)))))
  8294. ;; Map thru entries and find if we should filter them out
  8295. (mapc
  8296. (lambda(x)
  8297. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8298. (cat (get-text-property 1 'org-category x))
  8299. (tod (get-text-property 1 'time-of-day x))
  8300. (ok (or (null filter)
  8301. (and (stringp filter) (string-match filter evt))
  8302. (and (functionp filter) (funcall filter x))
  8303. (and (listp filter)
  8304. (let ((cat-filter (cadr (assoc 'category filter)))
  8305. (evt-filter (cadr (assoc 'headline filter))))
  8306. (or (and (stringp cat-filter)
  8307. (string-match cat-filter cat))
  8308. (and (stringp evt-filter)
  8309. (string-match evt-filter evt))))))))
  8310. ;; FIXME: Shall we remove text-properties for the appt text?
  8311. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8312. (when (and ok tod)
  8313. (setq tod (concat "00" (number-to-string tod))
  8314. tod (when (string-match
  8315. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8316. (concat (match-string 1 tod) ":"
  8317. (match-string 2 tod))))
  8318. (appt-add tod evt)
  8319. (setq cnt (1+ cnt))))) entries)
  8320. (org-release-buffers org-agenda-new-buffers)
  8321. (if (eq cnt 0)
  8322. (message "No event to add")
  8323. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8324. (defun org-agenda-todayp (date)
  8325. "Does DATE mean today, when considering `org-extend-today-until'?"
  8326. (let ((today (org-today))
  8327. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8328. date)))
  8329. (eq date today)))
  8330. (defun org-agenda-todo-yesterday (&optional arg)
  8331. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8332. (interactive "P")
  8333. (let* ((hour (third (decode-time
  8334. (org-current-time))))
  8335. (org-extend-today-until (1+ hour)))
  8336. (org-agenda-todo arg)))
  8337. (provide 'org-agenda)
  8338. ;;; org-agenda.el ends here