org-agenda.el 347 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048
  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. (defvar org-habit-show-all-today nil)
  80. ;; Defined somewhere in this file, but used before definition.
  81. (defvar org-agenda-buffer-name)
  82. (defvar org-agenda-overriding-header)
  83. (defvar org-agenda-title-append nil)
  84. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  85. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  86. (defvar org-agenda-undo-list)
  87. (defvar org-agenda-pending-undo-list)
  88. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  89. (defcustom org-agenda-confirm-kill 1
  90. "When set, remote killing from the agenda buffer needs confirmation.
  91. When t, a confirmation is always needed. When a number N, confirmation is
  92. only needed when the text to be killed contains more than N non-white lines."
  93. :group 'org-agenda
  94. :type '(choice
  95. (const :tag "Never" nil)
  96. (const :tag "Always" t)
  97. (integer :tag "When more than N lines")))
  98. (defcustom org-agenda-compact-blocks nil
  99. "Non-nil means make the block agenda more compact.
  100. This is done globally by leaving out lines like the agenda span
  101. name and week number or the separator lines."
  102. :group 'org-agenda
  103. :type 'boolean)
  104. (defcustom org-agenda-block-separator ?=
  105. "The separator between blocks in the agenda.
  106. If this is a string, it will be used as the separator, with a newline added.
  107. If it is a character, it will be repeated to fill the window width.
  108. If nil the separator is disabled. In `org-agenda-custom-commands' this
  109. addresses the separator between the current and the previous block."
  110. :group 'org-agenda
  111. :type '(choice
  112. (const :tag "Disabled" nil)
  113. (character)
  114. (string)))
  115. (defgroup org-agenda-export nil
  116. "Options concerning exporting agenda views in Org-mode."
  117. :tag "Org Agenda Export"
  118. :group 'org-agenda)
  119. (defcustom org-agenda-with-colors t
  120. "Non-nil means use colors in agenda views."
  121. :group 'org-agenda-export
  122. :type 'boolean)
  123. (defcustom org-agenda-exporter-settings nil
  124. "Alist of variable/value pairs that should be active during agenda export.
  125. This is a good place to set options for ps-print and for htmlize.
  126. Note that the way this is implemented, the values will be evaluated
  127. before assigned to the variables. So make sure to quote values you do
  128. *not* want evaluated, for example
  129. (setq org-agenda-exporter-settings
  130. '((ps-print-color-p 'black-white)))"
  131. :group 'org-agenda-export
  132. :type '(repeat
  133. (list
  134. (variable)
  135. (sexp :tag "Value"))))
  136. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  137. "Hook run in temporary buffer before writing it to an export file.
  138. A useful function is `org-agenda-add-entry-text'."
  139. :group 'org-agenda-export
  140. :type 'hook
  141. :options '(org-agenda-add-entry-text))
  142. (defcustom org-agenda-add-entry-text-maxlines 0
  143. "Maximum number of entry text lines to be added to agenda.
  144. This is only relevant when `org-agenda-add-entry-text' is part of
  145. `org-agenda-before-write-hook', which it is by default.
  146. When this is 0, nothing will happen. When it is greater than 0, it
  147. specifies the maximum number of lines that will be added for each entry
  148. that is listed in the agenda view.
  149. Note that this variable is not used during display, only when exporting
  150. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  151. and `org-agenda-entry-text-maxlines'."
  152. :group 'org-agenda
  153. :type 'integer)
  154. (defcustom org-agenda-add-entry-text-descriptive-links t
  155. "Non-nil means export org-links as descriptive links in agenda added text.
  156. This variable applies to the text added to the agenda when
  157. `org-agenda-add-entry-text-maxlines' is larger than 0.
  158. When this variable nil, the URL will (also) be shown."
  159. :group 'org-agenda
  160. :type 'boolean)
  161. (defcustom org-agenda-export-html-style ""
  162. "The style specification for exported HTML Agenda files.
  163. If this variable contains a string, it will replace the default <style>
  164. section as produced by `htmlize'.
  165. Since there are different ways of setting style information, this variable
  166. needs to contain the full HTML structure to provide a style, including the
  167. surrounding HTML tags. The style specifications should include definitions
  168. the fonts used by the agenda, here is an example:
  169. <style type=\"text/css\">
  170. p { font-weight: normal; color: gray; }
  171. .org-agenda-structure {
  172. font-size: 110%;
  173. color: #003399;
  174. font-weight: 600;
  175. }
  176. .org-todo {
  177. color: #cc6666;
  178. font-weight: bold;
  179. }
  180. .org-agenda-done {
  181. color: #339933;
  182. }
  183. .org-done {
  184. color: #339933;
  185. }
  186. .title { text-align: center; }
  187. .todo, .deadline { color: red; }
  188. .done { color: green; }
  189. </style>
  190. or, if you want to keep the style in a file,
  191. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  192. As the value of this option simply gets inserted into the HTML <head> header,
  193. you can \"misuse\" it to also add other text to the header. However,
  194. <style>...</style> is required, if not present the variable will be ignored."
  195. :group 'org-agenda-export
  196. :group 'org-export-html
  197. :type 'string)
  198. (defcustom org-agenda-persistent-filter nil
  199. "When set, keep filters from one agenda view to the next."
  200. :group 'org-agenda
  201. :type 'boolean)
  202. (defgroup org-agenda-custom-commands nil
  203. "Options concerning agenda views in Org-mode."
  204. :tag "Org Agenda Custom Commands"
  205. :group 'org-agenda)
  206. (defconst org-sorting-choice
  207. '(choice
  208. (const time-up) (const time-down)
  209. (const category-keep) (const category-up) (const category-down)
  210. (const tag-down) (const tag-up)
  211. (const priority-up) (const priority-down)
  212. (const todo-state-up) (const todo-state-down)
  213. (const effort-up) (const effort-down)
  214. (const habit-up) (const habit-down)
  215. (const alpha-up) (const alpha-down)
  216. (const user-defined-up) (const user-defined-down))
  217. "Sorting choices.")
  218. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  219. ;; the new variable `org-agenda-tag-filter-preset'.
  220. (if (fboundp 'defvaralias)
  221. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  222. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  223. (defconst org-agenda-custom-commands-local-options
  224. `(repeat :tag "Local settings for this command. Remember to quote values"
  225. (choice :tag "Setting"
  226. (list :tag "Heading for this block"
  227. (const org-agenda-overriding-header)
  228. (string :tag "Headline"))
  229. (list :tag "Files to be searched"
  230. (const org-agenda-files)
  231. (list
  232. (const :format "" quote)
  233. (repeat (file))))
  234. (list :tag "Sorting strategy"
  235. (const org-agenda-sorting-strategy)
  236. (list
  237. (const :format "" quote)
  238. (repeat
  239. ,org-sorting-choice)))
  240. (list :tag "Prefix format"
  241. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  242. (string))
  243. (list :tag "Number of days in agenda"
  244. (const org-agenda-span)
  245. (choice (const :tag "Day" 'day)
  246. (const :tag "Week" 'week)
  247. (const :tag "Month" 'month)
  248. (const :tag "Year" 'year)
  249. (integer :tag "Custom")))
  250. (list :tag "Fixed starting date"
  251. (const org-agenda-start-day)
  252. (string :value "2007-11-01"))
  253. (list :tag "Start on day of week"
  254. (const org-agenda-start-on-weekday)
  255. (choice :value 1
  256. (const :tag "Today" nil)
  257. (integer :tag "Weekday No.")))
  258. (list :tag "Include data from diary"
  259. (const org-agenda-include-diary)
  260. (boolean))
  261. (list :tag "Deadline Warning days"
  262. (const org-deadline-warning-days)
  263. (integer :value 1))
  264. (list :tag "Category filter preset"
  265. (const org-agenda-category-filter-preset)
  266. (list
  267. (const :format "" quote)
  268. (repeat
  269. (string :tag "+category or -category"))))
  270. (list :tag "Tags filter preset"
  271. (const org-agenda-tag-filter-preset)
  272. (list
  273. (const :format "" quote)
  274. (repeat
  275. (string :tag "+tag or -tag"))))
  276. (list :tag "Set daily/weekly entry types"
  277. (const org-agenda-entry-types)
  278. (list
  279. (const :format "" quote)
  280. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  281. (const :deadline)
  282. (const :scheduled)
  283. (const :timestamp)
  284. (const :sexp))))
  285. (list :tag "Standard skipping condition"
  286. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  287. (const org-agenda-skip-function)
  288. (list
  289. (const :format "" quote)
  290. (list
  291. (choice
  292. :tag "Skipping range"
  293. (const :tag "Skip entry" org-agenda-skip-entry-if)
  294. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  295. (repeat :inline t :tag "Conditions for skipping"
  296. (choice
  297. :tag "Condition type"
  298. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  299. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  300. (list :tag "TODO state is" :inline t
  301. (const 'todo)
  302. (choice
  303. (const :tag "any not-done state" 'todo)
  304. (const :tag "any done state" 'done)
  305. (const :tag "any state" 'any)
  306. (list :tag "Keyword list"
  307. (const :format "" quote)
  308. (repeat (string :tag "Keyword")))))
  309. (list :tag "TODO state is not" :inline t
  310. (const 'nottodo)
  311. (choice
  312. (const :tag "any not-done state" 'todo)
  313. (const :tag "any done state" 'done)
  314. (const :tag "any state" 'any)
  315. (list :tag "Keyword list"
  316. (const :format "" quote)
  317. (repeat (string :tag "Keyword")))))
  318. (const :tag "scheduled" 'scheduled)
  319. (const :tag "not scheduled" 'notscheduled)
  320. (const :tag "deadline" 'deadline)
  321. (const :tag "no deadline" 'notdeadline)
  322. (const :tag "timestamp" 'timestamp)
  323. (const :tag "no timestamp" 'nottimestamp))))))
  324. (list :tag "Non-standard skipping condition"
  325. :value (org-agenda-skip-function)
  326. (const org-agenda-skip-function)
  327. (sexp :tag "Function or form (quoted!)"))
  328. (list :tag "Any variable"
  329. (variable :tag "Variable")
  330. (sexp :tag "Value (sexp)"))))
  331. "Selection of examples for agenda command settings.
  332. This will be spliced into the custom type of
  333. `org-agenda-custom-commands'.")
  334. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  335. ((agenda "") (alltodo))))
  336. "Custom commands for the agenda.
  337. These commands will be offered on the splash screen displayed by the
  338. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  339. (key desc type match settings files)
  340. key The key (one or more characters as a string) to be associated
  341. with the command.
  342. desc A description of the command, when omitted or nil, a default
  343. description is built using MATCH.
  344. type The command type, any of the following symbols:
  345. agenda The daily/weekly agenda.
  346. todo Entries with a specific TODO keyword, in all agenda files.
  347. search Entries containing search words entry or headline.
  348. tags Tags/Property/TODO match in all agenda files.
  349. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  350. todo-tree Sparse tree of specific TODO keyword in *current* file.
  351. tags-tree Sparse tree with all tags matches in *current* file.
  352. occur-tree Occur sparse tree for *current* file.
  353. ... A user-defined function.
  354. match What to search for:
  355. - a single keyword for TODO keyword searches
  356. - a tags match expression for tags searches
  357. - a word search expression for text searches.
  358. - a regular expression for occur searches
  359. For all other commands, this should be the empty string.
  360. settings A list of option settings, similar to that in a let form, so like
  361. this: ((opt1 val1) (opt2 val2) ...). The values will be
  362. evaluated at the moment of execution, so quote them when needed.
  363. files A list of files file to write the produced agenda buffer to
  364. with the command `org-store-agenda-views'.
  365. If a file name ends in \".html\", an HTML version of the buffer
  366. is written out. If it ends in \".ps\", a postscript version is
  367. produced. Otherwise, only the plain text is written to the file.
  368. You can also define a set of commands, to create a composite agenda buffer.
  369. In this case, an entry looks like this:
  370. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  371. where
  372. desc A description string to be displayed in the dispatcher menu.
  373. cmd An agenda command, similar to the above. However, tree commands
  374. are not allowed, but instead you can get agenda and global todo list.
  375. So valid commands for a set are:
  376. (agenda \"\" settings)
  377. (alltodo \"\" settings)
  378. (stuck \"\" settings)
  379. (todo \"match\" settings files)
  380. (search \"match\" settings files)
  381. (tags \"match\" settings files)
  382. (tags-todo \"match\" settings files)
  383. Each command can carry a list of options, and another set of options can be
  384. given for the whole set of commands. Individual command options take
  385. precedence over the general options.
  386. When using several characters as key to a command, the first characters
  387. are prefix commands. For the dispatcher to display useful information, you
  388. should provide a description for the prefix, like
  389. (setq org-agenda-custom-commands
  390. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  391. (\"hl\" tags \"+HOME+Lisa\")
  392. (\"hp\" tags \"+HOME+Peter\")
  393. (\"hk\" tags \"+HOME+Kim\")))"
  394. :group 'org-agenda-custom-commands
  395. :type `(repeat
  396. (choice :value ("x" "Describe command here" tags "" nil)
  397. (list :tag "Single command"
  398. (string :tag "Access Key(s) ")
  399. (option (string :tag "Description"))
  400. (choice
  401. (const :tag "Agenda" agenda)
  402. (const :tag "TODO list" alltodo)
  403. (const :tag "Search words" search)
  404. (const :tag "Stuck projects" stuck)
  405. (const :tag "Tags/Property match (all agenda files)" tags)
  406. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  407. (const :tag "TODO keyword search (all agenda files)" todo)
  408. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  409. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  410. (const :tag "Occur tree (current buffer)" occur-tree)
  411. (sexp :tag "Other, user-defined function"))
  412. (string :tag "Match (only for some commands)")
  413. ,org-agenda-custom-commands-local-options
  414. (option (repeat :tag "Export" (file :tag "Export to"))))
  415. (list :tag "Command series, all agenda files"
  416. (string :tag "Access Key(s)")
  417. (string :tag "Description ")
  418. (repeat :tag "Component"
  419. (choice
  420. (list :tag "Agenda"
  421. (const :format "" agenda)
  422. (const :tag "" :format "" "")
  423. ,org-agenda-custom-commands-local-options)
  424. (list :tag "TODO list (all keywords)"
  425. (const :format "" alltodo)
  426. (const :tag "" :format "" "")
  427. ,org-agenda-custom-commands-local-options)
  428. (list :tag "Search words"
  429. (const :format "" search)
  430. (string :tag "Match")
  431. ,org-agenda-custom-commands-local-options)
  432. (list :tag "Stuck projects"
  433. (const :format "" stuck)
  434. (const :tag "" :format "" "")
  435. ,org-agenda-custom-commands-local-options)
  436. (list :tag "Tags search"
  437. (const :format "" tags)
  438. (string :tag "Match")
  439. ,org-agenda-custom-commands-local-options)
  440. (list :tag "Tags search, TODO entries only"
  441. (const :format "" tags-todo)
  442. (string :tag "Match")
  443. ,org-agenda-custom-commands-local-options)
  444. (list :tag "TODO keyword search"
  445. (const :format "" todo)
  446. (string :tag "Match")
  447. ,org-agenda-custom-commands-local-options)
  448. (list :tag "Other, user-defined function"
  449. (symbol :tag "function")
  450. (string :tag "Match")
  451. ,org-agenda-custom-commands-local-options)))
  452. (repeat :tag "Settings for entire command set"
  453. (list (variable :tag "Any variable")
  454. (sexp :tag "Value")))
  455. (option (repeat :tag "Export" (file :tag "Export to"))))
  456. (cons :tag "Prefix key documentation"
  457. (string :tag "Access Key(s)")
  458. (string :tag "Description ")))))
  459. (defcustom org-agenda-query-register ?o
  460. "The register holding the current query string.
  461. The purpose of this is that if you construct a query string interactively,
  462. you can then use it to define a custom command."
  463. :group 'org-agenda-custom-commands
  464. :type 'character)
  465. (defcustom org-stuck-projects
  466. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  467. "How to identify stuck projects.
  468. This is a list of four items:
  469. 1. A tags/todo/property matcher string that is used to identify a project.
  470. See the manual for a description of tag and property searches.
  471. The entire tree below a headline matched by this is considered one project.
  472. 2. A list of TODO keywords identifying non-stuck projects.
  473. If the project subtree contains any headline with one of these todo
  474. keywords, the project is considered to be not stuck. If you specify
  475. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  476. 3. A list of tags identifying non-stuck projects.
  477. If the project subtree contains any headline with one of these tags,
  478. the project is considered to be not stuck. If you specify \"*\" as
  479. a tag, any tag will mark the project unstuck. Note that this is about
  480. the explicit presence of a tag somewhere in the subtree, inherited
  481. tags to not count here. If inherited tags make a project not stuck,
  482. use \"-TAG\" in the tags part of the matcher under (1.) above.
  483. 4. An arbitrary regular expression matching non-stuck projects.
  484. If the project turns out to be not stuck, search continues also in the
  485. subtree to see if any of the subtasks have project status.
  486. See also the variable `org-tags-match-list-sublevels' which applies
  487. to projects matched by this search as well.
  488. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  489. or `C-c a #' to produce the list."
  490. :group 'org-agenda-custom-commands
  491. :type '(list
  492. (string :tag "Tags/TODO match to identify a project")
  493. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  494. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  495. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  496. (defcustom org-agenda-filter-effort-default-operator "<"
  497. "The default operator for effort estimate filtering.
  498. If you select an effort estimate limit without first pressing an operator,
  499. this one will be used."
  500. :group 'org-agenda-custom-commands
  501. :type '(choice (const :tag "less or equal" "<")
  502. (const :tag "greater or equal"">")
  503. (const :tag "equal" "=")))
  504. (defgroup org-agenda-skip nil
  505. "Options concerning skipping parts of agenda files."
  506. :tag "Org Agenda Skip"
  507. :group 'org-agenda)
  508. (defcustom org-agenda-skip-function-global nil
  509. "Function to be called at each match during agenda construction.
  510. If this function returns nil, the current match should not be skipped.
  511. If the function decided to skip an agenda match, is must return the
  512. buffer position from which the search should be continued.
  513. This may also be a Lisp form, which will be evaluated.
  514. This variable will be applied to every agenda match, including
  515. tags/property searches and TODO lists. So try to make the test function
  516. do its checking as efficiently as possible. To implement a skipping
  517. condition just for specific agenda commands, use the variable
  518. `org-agenda-skip-function' which can be set in the options section
  519. of custom agenda commands."
  520. :group 'org-agenda-skip
  521. :type 'sexp)
  522. (defgroup org-agenda-daily/weekly nil
  523. "Options concerning the daily/weekly agenda."
  524. :tag "Org Agenda Daily/Weekly"
  525. :group 'org-agenda)
  526. (defgroup org-agenda-todo-list nil
  527. "Options concerning the global todo list agenda view."
  528. :tag "Org Agenda Todo List"
  529. :group 'org-agenda)
  530. (defgroup org-agenda-match-view nil
  531. "Options concerning the general tags/property/todo match agenda view."
  532. :tag "Org Agenda Match View"
  533. :group 'org-agenda)
  534. (defgroup org-agenda-search-view nil
  535. "Options concerning the general tags/property/todo match agenda view."
  536. :tag "Org Agenda Match View"
  537. :group 'org-agenda)
  538. (defvar org-agenda-archives-mode nil
  539. "Non-nil means the agenda will include archived items.
  540. If this is the symbol `trees', trees in the selected agenda scope
  541. that are marked with the ARCHIVE tag will be included anyway. When this is
  542. t, also all archive files associated with the current selection of agenda
  543. files will be included.")
  544. (defcustom org-agenda-skip-comment-trees t
  545. "Non-nil means skip trees that start with the COMMENT keyword.
  546. When nil, these trees are also scanned by agenda commands."
  547. :group 'org-agenda-skip
  548. :type 'boolean)
  549. (defcustom org-agenda-todo-list-sublevels t
  550. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  551. When nil, the sublevels of a TODO entry are not checked, resulting in
  552. potentially much shorter TODO lists."
  553. :group 'org-agenda-skip
  554. :group 'org-agenda-todo-list
  555. :type 'boolean)
  556. (defcustom org-agenda-todo-ignore-with-date nil
  557. "Non-nil means don't show entries with a date in the global todo list.
  558. You can use this if you prefer to mark mere appointments with a TODO keyword,
  559. but don't want them to show up in the TODO list.
  560. When this is set, it also covers deadlines and scheduled items, the settings
  561. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  562. will be ignored.
  563. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  564. :group 'org-agenda-skip
  565. :group 'org-agenda-todo-list
  566. :type 'boolean)
  567. (defcustom org-agenda-todo-ignore-timestamp nil
  568. "Non-nil means don't show entries with a timestamp.
  569. This applies when creating the global todo list.
  570. Valid values are:
  571. past Don't show entries for today or in the past.
  572. future Don't show entries with a timestamp in the future.
  573. The idea behind this is that if it has a future
  574. timestamp, you don't want to think about it until the
  575. date.
  576. all Don't show any entries with a timestamp in the global todo list.
  577. The idea behind this is that by setting a timestamp, you
  578. have already \"taken care\" of this item.
  579. This variable can also have an integer as a value. If positive (N),
  580. todos with a timestamp N or more days in the future will be ignored. If
  581. negative (-N), todos with a timestamp N or more days in the past will be
  582. ignored. If 0, todos with a timestamp either today or in the future will
  583. be ignored. For example, a value of -1 will exclude todos with a
  584. timestamp in the past (yesterday or earlier), while a value of 7 will
  585. exclude todos with a timestamp a week or more in the future.
  586. See also `org-agenda-todo-ignore-with-date'.
  587. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  588. to make his option also apply to the tags-todo list."
  589. :group 'org-agenda-skip
  590. :group 'org-agenda-todo-list
  591. :version "24.1"
  592. :type '(choice
  593. (const :tag "Ignore future timestamp todos" future)
  594. (const :tag "Ignore past or present timestamp todos" past)
  595. (const :tag "Ignore all timestamp todos" all)
  596. (const :tag "Show timestamp todos" nil)
  597. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  598. (defcustom org-agenda-todo-ignore-scheduled nil
  599. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  600. This applies when creating the global todo list.
  601. Valid values are:
  602. past Don't show entries scheduled today or in the past.
  603. future Don't show entries scheduled in the future.
  604. The idea behind this is that by scheduling it, you don't want to
  605. think about it until the scheduled date.
  606. all Don't show any scheduled entries in the global todo list.
  607. The idea behind this is that by scheduling it, you have already
  608. \"taken care\" of this item.
  609. t Same as `all', for backward compatibility.
  610. This variable can also have an integer as a value. See
  611. `org-agenda-todo-ignore-timestamp' for more details.
  612. See also `org-agenda-todo-ignore-with-date'.
  613. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  614. to make his option also apply to the tags-todo list."
  615. :group 'org-agenda-skip
  616. :group 'org-agenda-todo-list
  617. :type '(choice
  618. (const :tag "Ignore future-scheduled todos" future)
  619. (const :tag "Ignore past- or present-scheduled todos" past)
  620. (const :tag "Ignore all scheduled todos" all)
  621. (const :tag "Ignore all scheduled todos (compatibility)" t)
  622. (const :tag "Show scheduled todos" nil)
  623. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  624. (defcustom org-agenda-todo-ignore-deadlines nil
  625. "Non-nil means ignore some deadlined TODO items when making TODO list.
  626. There are different motivations for using different values, please think
  627. carefully when configuring this variable.
  628. This applies when creating the global todo list.
  629. Valid values are:
  630. near Don't show near deadline entries. A deadline is near when it is
  631. closer than `org-deadline-warning-days' days. The idea behind this
  632. is that such items will appear in the agenda anyway.
  633. far Don't show TODO entries where a deadline has been defined, but
  634. the deadline is not near. This is useful if you don't want to
  635. use the todo list to figure out what to do now.
  636. past Don't show entries with a deadline timestamp for today or in the past.
  637. future Don't show entries with a deadline timestamp in the future, not even
  638. when they become `near' ones. Use it with caution.
  639. all Ignore all TODO entries that do have a deadline.
  640. t Same as `near', for backward compatibility.
  641. This variable can also have an integer as a value. See
  642. `org-agenda-todo-ignore-timestamp' for more details.
  643. See also `org-agenda-todo-ignore-with-date'.
  644. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  645. to make his option also apply to the tags-todo list."
  646. :group 'org-agenda-skip
  647. :group 'org-agenda-todo-list
  648. :type '(choice
  649. (const :tag "Ignore near deadlines" near)
  650. (const :tag "Ignore near deadlines (compatibility)" t)
  651. (const :tag "Ignore far deadlines" far)
  652. (const :tag "Ignore all TODOs with a deadlines" all)
  653. (const :tag "Show all TODOs, even if they have a deadline" nil)
  654. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  655. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  656. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  657. The variables
  658. `org-agenda-todo-ignore-with-date',
  659. `org-agenda-todo-ignore-timestamp',
  660. `org-agenda-todo-ignore-scheduled',
  661. `org-agenda-todo-ignore-deadlines'
  662. make the global TODO list skip entries that have time stamps of certain
  663. kinds. If this option is set, the same options will also apply for the
  664. tags-todo search, which is the general tags/property matcher
  665. restricted to unfinished TODO entries only."
  666. :group 'org-agenda-skip
  667. :group 'org-agenda-todo-list
  668. :group 'org-agenda-match-view
  669. :type 'boolean)
  670. (defcustom org-agenda-skip-scheduled-if-done nil
  671. "Non-nil means don't show scheduled items in agenda when they are done.
  672. This is relevant for the daily/weekly agenda, not for the TODO list. And
  673. it applies only to the actual date of the scheduling. Warnings about
  674. an item with a past scheduling dates are always turned off when the item
  675. is DONE."
  676. :group 'org-agenda-skip
  677. :group 'org-agenda-daily/weekly
  678. :type 'boolean)
  679. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  680. "Non-nil means skip scheduling line if same entry shows because of deadline.
  681. In the agenda of today, an entry can show up multiple times because
  682. it is both scheduled and has a nearby deadline, and maybe a plain time
  683. stamp as well.
  684. When this variable is t, then only the deadline is shown and the fact that
  685. the entry is scheduled today or was scheduled previously is not shown.
  686. When this variable is nil, the entry will be shown several times. When
  687. the variable is the symbol `not-today', then skip scheduled previously,
  688. but not scheduled today."
  689. :group 'org-agenda-skip
  690. :group 'org-agenda-daily/weekly
  691. :type '(choice
  692. (const :tag "Never" nil)
  693. (const :tag "Always" t)
  694. (const :tag "Not when scheduled today" not-today)))
  695. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  696. "Non-nil means skip timestamp line if same entry shows because of deadline.
  697. In the agenda of today, an entry can show up multiple times
  698. because it has both a plain timestamp and has a nearby deadline.
  699. When this variable is t, then only the deadline is shown and the
  700. fact that the entry has a timestamp for or including today is not
  701. shown. When this variable is nil, the entry will be shown
  702. several times."
  703. :group 'org-agenda-skip
  704. :group 'org-agenda-daily/weekly
  705. :version "24.1"
  706. :type '(choice
  707. (const :tag "Never" nil)
  708. (const :tag "Always" t)))
  709. (defcustom org-agenda-skip-deadline-if-done nil
  710. "Non-nil means don't show deadlines when the corresponding item is done.
  711. When nil, the deadline is still shown and should give you a happy feeling.
  712. This is relevant for the daily/weekly agenda. And it applied only to the
  713. actually date of the deadline. Warnings about approaching and past-due
  714. deadlines are always turned off when the item is DONE."
  715. :group 'org-agenda-skip
  716. :group 'org-agenda-daily/weekly
  717. :type 'boolean)
  718. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  719. "Non-nil means skip deadline prewarning when entry is also scheduled.
  720. This will apply on all days where a prewarning for the deadline would
  721. be shown, but not at the day when the entry is actually due. On that day,
  722. the deadline will be shown anyway.
  723. This variable may be set to nil, t, or a number which will then give
  724. the number of days before the actual deadline when the prewarnings
  725. should resume.
  726. This can be used in a workflow where the first showing of the deadline will
  727. trigger you to schedule it, and then you don't want to be reminded of it
  728. because you will take care of it on the day when scheduled."
  729. :group 'org-agenda-skip
  730. :group 'org-agenda-daily/weekly
  731. :version "24.1"
  732. :type '(choice
  733. (const :tag "Alwas show prewarning" nil)
  734. (const :tag "Remove prewarning if entry is scheduled" t)
  735. (integer :tag "Restart prewarning N days before deadline")))
  736. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  737. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  738. When non-nil, after the search for timestamps has matched once in an
  739. entry, the rest of the entry will not be searched."
  740. :group 'org-agenda-skip
  741. :type 'boolean)
  742. (defcustom org-agenda-skip-timestamp-if-done nil
  743. "Non-nil means don't select item by timestamp or -range if it is DONE."
  744. :group 'org-agenda-skip
  745. :group 'org-agenda-daily/weekly
  746. :type 'boolean)
  747. (defcustom org-agenda-dim-blocked-tasks t
  748. "Non-nil means dim blocked tasks in the agenda display.
  749. This causes some overhead during agenda construction, but if you
  750. have turned on `org-enforce-todo-dependencies',
  751. `org-enforce-todo-checkbox-dependencies', or any other blocking
  752. mechanism, this will create useful feedback in the agenda.
  753. Instead of t, this variable can also have the value `invisible'.
  754. Then blocked tasks will be invisible and only become visible when
  755. they become unblocked. An exemption to this behavior is when a task is
  756. blocked because of unchecked checkboxes below it. Since checkboxes do
  757. not show up in the agenda views, making this task invisible you remove any
  758. trace from agenda views that there is something to do. Therefore, a task
  759. that is blocked because of checkboxes will never be made invisible, it
  760. will only be dimmed."
  761. :group 'org-agenda-daily/weekly
  762. :group 'org-agenda-todo-list
  763. :type '(choice
  764. (const :tag "Do not dim" nil)
  765. (const :tag "Dim to a gray face" t)
  766. (const :tag "Make invisible" invisible)))
  767. (defcustom org-timeline-show-empty-dates 3
  768. "Non-nil means `org-timeline' also shows dates without an entry.
  769. When nil, only the days which actually have entries are shown.
  770. When t, all days between the first and the last date are shown.
  771. When an integer, show also empty dates, but if there is a gap of more than
  772. N days, just insert a special line indicating the size of the gap."
  773. :group 'org-agenda-skip
  774. :type '(choice
  775. (const :tag "None" nil)
  776. (const :tag "All" t)
  777. (integer :tag "at most")))
  778. (defgroup org-agenda-startup nil
  779. "Options concerning initial settings in the Agenda in Org Mode."
  780. :tag "Org Agenda Startup"
  781. :group 'org-agenda)
  782. (defcustom org-agenda-menu-show-matcher t
  783. "Non-nil means show the match string in the agenda dispatcher menu.
  784. When nil, the matcher string is not shown, but is put into the help-echo
  785. property so than moving the mouse over the command shows it.
  786. Setting it to nil is good if matcher strings are very long and/or if
  787. you want to use two-column display (see `org-agenda-menu-two-column')."
  788. :group 'org-agenda
  789. :version "24.1"
  790. :type 'boolean)
  791. (defcustom org-agenda-menu-two-column nil
  792. "Non-nil means, use two columns to show custom commands in the dispatcher.
  793. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  794. to nil."
  795. :group 'org-agenda
  796. :version "24.1"
  797. :type 'boolean)
  798. (defcustom org-finalize-agenda-hook nil
  799. "Hook run just before displaying an agenda buffer."
  800. :group 'org-agenda-startup
  801. :type 'hook)
  802. (defcustom org-agenda-mouse-1-follows-link nil
  803. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  804. A longer mouse click will still set point. Does not work on XEmacs.
  805. Needs to be set before org.el is loaded."
  806. :group 'org-agenda-startup
  807. :type 'boolean)
  808. (defcustom org-agenda-start-with-follow-mode nil
  809. "The initial value of follow mode in a newly created agenda window."
  810. :group 'org-agenda-startup
  811. :type 'boolean)
  812. (defcustom org-agenda-follow-indirect nil
  813. "Non-nil means `org-agenda-follow-mode' displays only the
  814. current item's tree, in an indirect buffer."
  815. :group 'org-agenda
  816. :version "24.1"
  817. :type 'boolean)
  818. (defcustom org-agenda-show-outline-path t
  819. "Non-nil means show outline path in echo area after line motion."
  820. :group 'org-agenda-startup
  821. :type 'boolean)
  822. (defcustom org-agenda-start-with-entry-text-mode nil
  823. "The initial value of entry-text-mode in a newly created agenda window."
  824. :group 'org-agenda-startup
  825. :type 'boolean)
  826. (defcustom org-agenda-entry-text-maxlines 5
  827. "Number of text lines to be added when `E' is pressed in the agenda.
  828. Note that this variable only used during agenda display. Add add entry text
  829. when exporting the agenda, configure the variable
  830. `org-agenda-add-entry-ext-maxlines'."
  831. :group 'org-agenda
  832. :type 'integer)
  833. (defcustom org-agenda-entry-text-exclude-regexps nil
  834. "List of regular expressions to clean up entry text.
  835. The complete matches of all regular expressions in this list will be
  836. removed from entry text before it is shown in the agenda."
  837. :group 'org-agenda
  838. :type '(repeat (regexp)))
  839. (defvar org-agenda-entry-text-cleanup-hook nil
  840. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  841. This cleanup is done in a temporary buffer, so the function may inspect and
  842. change the entire buffer.
  843. Some default stuff like drawers and scheduling/deadline dates will already
  844. have been removed when this is called, as will any matches for regular
  845. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  846. (defvar org-agenda-include-inactive-timestamps nil
  847. "Non-nil means include inactive time stamps in agenda and timeline.
  848. Dynamically scoped.")
  849. (defgroup org-agenda-windows nil
  850. "Options concerning the windows used by the Agenda in Org Mode."
  851. :tag "Org Agenda Windows"
  852. :group 'org-agenda)
  853. (defcustom org-agenda-window-setup 'reorganize-frame
  854. "How the agenda buffer should be displayed.
  855. Possible values for this option are:
  856. current-window Show agenda in the current window, keeping all other windows.
  857. other-window Use `switch-to-buffer-other-window' to display agenda.
  858. reorganize-frame Show only two windows on the current frame, the current
  859. window and the agenda.
  860. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  861. Also, when exiting the agenda, kill that frame.
  862. See also the variable `org-agenda-restore-windows-after-quit'."
  863. :group 'org-agenda-windows
  864. :type '(choice
  865. (const current-window)
  866. (const other-frame)
  867. (const other-window)
  868. (const reorganize-frame)))
  869. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  870. "The min and max height of the agenda window as a fraction of frame height.
  871. The value of the variable is a cons cell with two numbers between 0 and 1.
  872. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  873. :group 'org-agenda-windows
  874. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  875. (defcustom org-agenda-restore-windows-after-quit nil
  876. "Non-nil means restore window configuration upon exiting agenda.
  877. Before the window configuration is changed for displaying the agenda,
  878. the current status is recorded. When the agenda is exited with
  879. `q' or `x' and this option is set, the old state is restored. If
  880. `org-agenda-window-setup' is `other-frame', the value of this
  881. option will be ignored."
  882. :group 'org-agenda-windows
  883. :type 'boolean)
  884. (defcustom org-agenda-ndays nil
  885. "Number of days to include in overview display.
  886. Should be 1 or 7.
  887. Obsolete, see `org-agenda-span'."
  888. :group 'org-agenda-daily/weekly
  889. :type 'integer)
  890. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  891. (defcustom org-agenda-span 'week
  892. "Number of days to include in overview display.
  893. Can be day, week, month, year, or any number of days.
  894. Custom commands can set this variable in the options section."
  895. :group 'org-agenda-daily/weekly
  896. :type '(choice (const :tag "Day" day)
  897. (const :tag "Week" week)
  898. (const :tag "Month" month)
  899. (const :tag "Year" year)
  900. (integer :tag "Custom")))
  901. (defcustom org-agenda-start-on-weekday 1
  902. "Non-nil means start the overview always on the specified weekday.
  903. 0 denotes Sunday, 1 denotes Monday etc.
  904. When nil, always start on the current day.
  905. Custom commands can set this variable in the options section."
  906. :group 'org-agenda-daily/weekly
  907. :type '(choice (const :tag "Today" nil)
  908. (integer :tag "Weekday No.")))
  909. (defcustom org-agenda-show-all-dates t
  910. "Non-nil means `org-agenda' shows every day in the selected range.
  911. When nil, only the days which actually have entries are shown."
  912. :group 'org-agenda-daily/weekly
  913. :type 'boolean)
  914. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  915. "Format string for displaying dates in the agenda.
  916. Used by the daily/weekly agenda and by the timeline. This should be
  917. a format string understood by `format-time-string', or a function returning
  918. the formatted date as a string. The function must take a single argument,
  919. a calendar-style date list like (month day year)."
  920. :group 'org-agenda-daily/weekly
  921. :type '(choice
  922. (string :tag "Format string")
  923. (function :tag "Function")))
  924. (defun org-agenda-format-date-aligned (date)
  925. "Format a date string for display in the daily/weekly agenda, or timeline.
  926. This function makes sure that dates are aligned for easy reading."
  927. (require 'cal-iso)
  928. (let* ((dayname (calendar-day-name date))
  929. (day (cadr date))
  930. (day-of-week (calendar-day-of-week date))
  931. (month (car date))
  932. (monthname (calendar-month-name month))
  933. (year (nth 2 date))
  934. (iso-week (org-days-to-iso-week
  935. (calendar-absolute-from-gregorian date)))
  936. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  937. (1- year))
  938. ((and (= month 12) (<= iso-week 1))
  939. (1+ year))
  940. (t year)))
  941. (weekstring (if (= day-of-week 1)
  942. (format " W%02d" iso-week)
  943. "")))
  944. (format "%-10s %2d %s %4d%s"
  945. dayname day monthname year weekstring)))
  946. (defcustom org-agenda-time-leading-zero nil
  947. "Non-nil means use leading zero for military times in agenda.
  948. For example, 9:30am would become 09:30 rather than 9:30."
  949. :group 'org-agenda-daily/weekly
  950. :version "24.1"
  951. :type 'boolean)
  952. (defcustom org-agenda-timegrid-use-ampm nil
  953. "When set, show AM/PM style timestamps on the timegrid."
  954. :group 'org-agenda
  955. :version "24.1"
  956. :type 'boolean)
  957. (defun org-agenda-time-of-day-to-ampm (time)
  958. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  959. (let* ((hour-number (string-to-number (substring time 0 -3)))
  960. (minute (substring time -2))
  961. (ampm "am"))
  962. (cond
  963. ((equal hour-number 12)
  964. (setq ampm "pm"))
  965. ((> hour-number 12)
  966. (setq ampm "pm")
  967. (setq hour-number (- hour-number 12))))
  968. (concat
  969. (if org-agenda-time-leading-zero
  970. (format "%02d" hour-number)
  971. (format "%02s" (number-to-string hour-number)))
  972. ":" minute ampm)))
  973. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  974. "Conditionally convert TIME to AM/PM format
  975. based on `org-agenda-timegrid-use-ampm'"
  976. (if org-agenda-timegrid-use-ampm
  977. (org-agenda-time-of-day-to-ampm time)
  978. time))
  979. (defcustom org-agenda-weekend-days '(6 0)
  980. "Which days are weekend?
  981. These days get the special face `org-agenda-date-weekend' in the agenda
  982. and timeline buffers."
  983. :group 'org-agenda-daily/weekly
  984. :type '(set :greedy t
  985. (const :tag "Monday" 1)
  986. (const :tag "Tuesday" 2)
  987. (const :tag "Wednesday" 3)
  988. (const :tag "Thursday" 4)
  989. (const :tag "Friday" 5)
  990. (const :tag "Saturday" 6)
  991. (const :tag "Sunday" 0)))
  992. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  993. "Non-nil means jump to today when moving a past date forward in time.
  994. When using S-right in the agenda to move a a date forward, and the date
  995. stamp currently points to the past, the first key press will move it
  996. to today. WHen nil, just move one day forward even if the date stays
  997. in the past."
  998. :group 'org-agenda-daily/weekly
  999. :version "24.1"
  1000. :type 'boolean)
  1001. (defcustom org-agenda-include-diary nil
  1002. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1003. Custom commands can set this variable in the options section."
  1004. :group 'org-agenda-daily/weekly
  1005. :type 'boolean)
  1006. (defcustom org-agenda-include-deadlines t
  1007. "If non-nil, include entries within their deadline warning period.
  1008. Custom commands can set this variable in the options section."
  1009. :group 'org-agenda-daily/weekly
  1010. :version "24.1"
  1011. :type 'boolean)
  1012. (defcustom org-agenda-repeating-timestamp-show-all t
  1013. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1014. When set to a list of strings, only show occurrences of repeating
  1015. stamps for these TODO keywords. When nil, only one occurrence is
  1016. shown, either today or the nearest into the future."
  1017. :group 'org-agenda-daily/weekly
  1018. :type '(choice
  1019. (const :tag "Show repeating stamps" t)
  1020. (repeat :tag "Show repeating stamps for these TODO keywords"
  1021. (string :tag "TODO Keyword"))
  1022. (const :tag "Don't show repeating stamps" nil)))
  1023. (defcustom org-scheduled-past-days 10000
  1024. "No. of days to continue listing scheduled items that are not marked DONE.
  1025. When an item is scheduled on a date, it shows up in the agenda on this
  1026. day and will be listed until it is marked done for the number of days
  1027. given here."
  1028. :group 'org-agenda-daily/weekly
  1029. :type 'integer)
  1030. (defcustom org-agenda-log-mode-items '(closed clock)
  1031. "List of items that should be shown in agenda log mode.
  1032. This list may contain the following symbols:
  1033. closed Show entries that have been closed on that day.
  1034. clock Show entries that have received clocked time on that day.
  1035. state Show all logged state changes.
  1036. Note that instead of changing this variable, you can also press `C-u l' in
  1037. the agenda to display all available LOG items temporarily."
  1038. :group 'org-agenda-daily/weekly
  1039. :type '(set :greedy t (const closed) (const clock) (const state)))
  1040. (defcustom org-agenda-clock-consistency-checks
  1041. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1042. :gap-ok-around ("4:00")
  1043. :default-face ((:background "DarkRed") (:foreground "white"))
  1044. :overlap-face nil :gap-face nil :no-end-time-face nil
  1045. :long-face nil :short-face nil)
  1046. "This is a property list, with the following keys:
  1047. :max-duration Mark clocking chunks that are longer than this time.
  1048. This is a time string like \"HH:MM\", or the number
  1049. of minutes as an integer.
  1050. :min-duration Mark clocking chunks that are shorter that this.
  1051. This is a time string like \"HH:MM\", or the number
  1052. of minutes as an integer.
  1053. :max-gap Mark gaps between clocking chunks that are longer than
  1054. this duration. A number of minutes, or a string
  1055. like \"HH:MM\".
  1056. :gap-ok-around List of times during the day which are usually not working
  1057. times. When a gap is detected, but the gap contains any
  1058. of these times, the gap is *not* reported. For example,
  1059. if this is (\"4:00\" \"13:00\") then gaps that contain
  1060. 4:00 in the morning (i.e. the night) and 13:00
  1061. (i.e. a typical lunch time) do not cause a warning.
  1062. You should have at least one time during the night in this
  1063. list, or otherwise the first task each morning will trigger
  1064. a warning because it follows a long gap.
  1065. Furthermore, the following properties can be used to define faces for
  1066. issue display.
  1067. :default-face the default face, if the specific face is undefined
  1068. :overlap-face face for overlapping clocks
  1069. :gap-face face for gaps between clocks
  1070. :no-end-time-face face for incomplete clocks
  1071. :long-face face for clock intervals that are too long
  1072. :short-face face for clock intervals that are too short"
  1073. :group 'org-agenda-daily/weekly
  1074. :group 'org-clock
  1075. :version "24.1"
  1076. :type 'plist)
  1077. (defcustom org-agenda-log-mode-add-notes t
  1078. "Non-nil means add first line of notes to log entries in agenda views.
  1079. If a log item like a state change or a clock entry is associated with
  1080. notes, the first line of these notes will be added to the entry in the
  1081. agenda display."
  1082. :group 'org-agenda-daily/weekly
  1083. :type 'boolean)
  1084. (defcustom org-agenda-start-with-log-mode nil
  1085. "The initial value of log-mode in a newly created agenda window.
  1086. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1087. explanations on the possible values."
  1088. :group 'org-agenda-startup
  1089. :group 'org-agenda-daily/weekly
  1090. :type '(choice (const :tag "Don't show log items" nil)
  1091. (const :tag "Show only log items" 'only)
  1092. (const :tag "Show all possible log items" 'clockcheck)
  1093. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1094. (choice (const :tag "Show closed log items" 'closed)
  1095. (const :tag "Show clocked log items" 'clock)
  1096. (const :tag "Show all logged state changes" 'state)))))
  1097. (defcustom org-agenda-start-with-clockreport-mode nil
  1098. "The initial value of clockreport-mode in a newly created agenda window."
  1099. :group 'org-agenda-startup
  1100. :group 'org-agenda-daily/weekly
  1101. :type 'boolean)
  1102. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1103. "Property list with parameters for the clocktable in clockreport mode.
  1104. This is the display mode that shows a clock table in the daily/weekly
  1105. agenda, the properties for this dynamic block can be set here.
  1106. The usual clocktable parameters are allowed here, but you cannot set
  1107. the properties :name, :tstart, :tend, :block, and :scope - these will
  1108. be overwritten to make sure the content accurately reflects the
  1109. current display in the agenda."
  1110. :group 'org-agenda-daily/weekly
  1111. :type 'plist)
  1112. (defcustom org-agenda-search-view-always-boolean nil
  1113. "Non-nil means the search string is interpreted as individual parts.
  1114. The search string for search view can either be interpreted as a phrase,
  1115. or as a list of snippets that define a boolean search for a number of
  1116. strings.
  1117. When this is non-nil, the string will be split on whitespace, and each
  1118. snippet will be searched individually, and all must match in order to
  1119. select an entry. A snippet is then a single string of non-white
  1120. characters, or a string in double quotes, or a regexp in {} braces.
  1121. If a snippet is preceded by \"-\", the snippet must *not* match.
  1122. \"+\" is syntactic sugar for positive selection. Each snippet may
  1123. be found as a full word or a partial word, but see the variable
  1124. `org-agenda-search-view-force-full-words'.
  1125. When this is nil, search will look for the entire search phrase as one,
  1126. with each space character matching any amount of whitespace, including
  1127. line breaks.
  1128. Even when this is nil, you can still switch to Boolean search dynamically
  1129. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1130. is a regexp marked with braces like \"{abc}\", this will also switch to
  1131. boolean search."
  1132. :group 'org-agenda-search-view
  1133. :version "24.1"
  1134. :type 'boolean)
  1135. (if (fboundp 'defvaralias)
  1136. (defvaralias 'org-agenda-search-view-search-words-only
  1137. 'org-agenda-search-view-always-boolean))
  1138. (defcustom org-agenda-search-view-force-full-words nil
  1139. "Non-nil means, search words must be matches as complete words.
  1140. When nil, they may also match part of a word."
  1141. :group 'org-agenda-search-view
  1142. :version "24.1"
  1143. :type 'boolean)
  1144. (defgroup org-agenda-time-grid nil
  1145. "Options concerning the time grid in the Org-mode Agenda."
  1146. :tag "Org Agenda Time Grid"
  1147. :group 'org-agenda)
  1148. (defcustom org-agenda-search-headline-for-time t
  1149. "Non-nil means search headline for a time-of-day.
  1150. If the headline contains a time-of-day in one format or another, it will
  1151. be used to sort the entry into the time sequence of items for a day.
  1152. Some people have time stamps in the headline that refer to the creation
  1153. time or so, and then this produces an unwanted side effect. If this is
  1154. the case for your, use this variable to turn off searching the headline
  1155. for a time."
  1156. :group 'org-agenda-time-grid
  1157. :type 'boolean)
  1158. (defcustom org-agenda-use-time-grid t
  1159. "Non-nil means show a time grid in the agenda schedule.
  1160. A time grid is a set of lines for specific times (like every two hours between
  1161. 8:00 and 20:00). The items scheduled for a day at specific times are
  1162. sorted in between these lines.
  1163. For details about when the grid will be shown, and what it will look like, see
  1164. the variable `org-agenda-time-grid'."
  1165. :group 'org-agenda-time-grid
  1166. :type 'boolean)
  1167. (defcustom org-agenda-time-grid
  1168. '((daily today require-timed)
  1169. "----------------"
  1170. (800 1000 1200 1400 1600 1800 2000))
  1171. "The settings for time grid for agenda display.
  1172. This is a list of three items. The first item is again a list. It contains
  1173. symbols specifying conditions when the grid should be displayed:
  1174. daily if the agenda shows a single day
  1175. weekly if the agenda shows an entire week
  1176. today show grid on current date, independent of daily/weekly display
  1177. require-timed show grid only if at least one item has a time specification
  1178. The second item is a string which will be placed behind the grid time.
  1179. The third item is a list of integers, indicating the times that should have
  1180. a grid line."
  1181. :group 'org-agenda-time-grid
  1182. :type
  1183. '(list
  1184. (set :greedy t :tag "Grid Display Options"
  1185. (const :tag "Show grid in single day agenda display" daily)
  1186. (const :tag "Show grid in weekly agenda display" weekly)
  1187. (const :tag "Always show grid for today" today)
  1188. (const :tag "Show grid only if any timed entries are present"
  1189. require-timed)
  1190. (const :tag "Skip grid times already present in an entry"
  1191. remove-match))
  1192. (string :tag "Grid String")
  1193. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1194. (defcustom org-agenda-show-current-time-in-grid t
  1195. "Non-nil means show the current time in the time grid."
  1196. :group 'org-agenda-time-grid
  1197. :version "24.1"
  1198. :type 'boolean)
  1199. (defcustom org-agenda-current-time-string
  1200. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1201. "The string for the current time marker in the agenda."
  1202. :group 'org-agenda-time-grid
  1203. :version "24.1"
  1204. :type 'string)
  1205. (defgroup org-agenda-sorting nil
  1206. "Options concerning sorting in the Org-mode Agenda."
  1207. :tag "Org Agenda Sorting"
  1208. :group 'org-agenda)
  1209. (defcustom org-agenda-sorting-strategy
  1210. '((agenda habit-down time-up priority-down category-keep)
  1211. (todo priority-down category-keep)
  1212. (tags priority-down category-keep)
  1213. (search category-keep))
  1214. "Sorting structure for the agenda items of a single day.
  1215. This is a list of symbols which will be used in sequence to determine
  1216. if an entry should be listed before another entry. The following
  1217. symbols are recognized:
  1218. time-up Put entries with time-of-day indications first, early first
  1219. time-down Put entries with time-of-day indications first, late first
  1220. category-keep Keep the default order of categories, corresponding to the
  1221. sequence in `org-agenda-files'.
  1222. category-up Sort alphabetically by category, A-Z.
  1223. category-down Sort alphabetically by category, Z-A.
  1224. tag-up Sort alphabetically by last tag, A-Z.
  1225. tag-down Sort alphabetically by last tag, Z-A.
  1226. priority-up Sort numerically by priority, high priority last.
  1227. priority-down Sort numerically by priority, high priority first.
  1228. todo-state-up Sort by todo state, tasks that are done last.
  1229. todo-state-down Sort by todo state, tasks that are done first.
  1230. effort-up Sort numerically by estimated effort, high effort last.
  1231. effort-down Sort numerically by estimated effort, high effort first.
  1232. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1233. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1234. habit-up Put entries that are habits first
  1235. habit-down Put entries that are habits last
  1236. alpha-up Sort headlines alphabetically
  1237. alpha-down Sort headlines alphabetically, reversed
  1238. The different possibilities will be tried in sequence, and testing stops
  1239. if one comparison returns a \"not-equal\". For example, the default
  1240. '(time-up category-keep priority-down)
  1241. means: Pull out all entries having a specified time of day and sort them,
  1242. in order to make a time schedule for the current day the first thing in the
  1243. agenda listing for the day. Of the entries without a time indication, keep
  1244. the grouped in categories, don't sort the categories, but keep them in
  1245. the sequence given in `org-agenda-files'. Within each category sort by
  1246. priority.
  1247. Leaving out `category-keep' would mean that items will be sorted across
  1248. categories by priority.
  1249. Instead of a single list, this can also be a set of list for specific
  1250. contents, with a context symbol in the car of the list, any of
  1251. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1252. Custom commands can bind this variable in the options section."
  1253. :group 'org-agenda-sorting
  1254. :type `(choice
  1255. (repeat :tag "General" ,org-sorting-choice)
  1256. (list :tag "Individually"
  1257. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1258. (repeat ,org-sorting-choice))
  1259. (cons (const :tag "Strategy for TODO lists" todo)
  1260. (repeat ,org-sorting-choice))
  1261. (cons (const :tag "Strategy for Tags matches" tags)
  1262. (repeat ,org-sorting-choice))
  1263. (cons (const :tag "Strategy for search matches" search)
  1264. (repeat ,org-sorting-choice)))))
  1265. (defcustom org-agenda-cmp-user-defined nil
  1266. "A function to define the comparison `user-defined'.
  1267. This function must receive two arguments, agenda entry a and b.
  1268. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1269. the user comparison, return nil.
  1270. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1271. part of an agenda sorting strategy."
  1272. :group 'org-agenda-sorting
  1273. :type 'symbol)
  1274. (defcustom org-sort-agenda-notime-is-late t
  1275. "Non-nil means items without time are considered late.
  1276. This is only relevant for sorting. When t, items which have no explicit
  1277. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1278. do have a time. When nil, the default time is before 0:00. You can use this
  1279. option to decide if the schedule for today should come before or after timeless
  1280. agenda entries."
  1281. :group 'org-agenda-sorting
  1282. :type 'boolean)
  1283. (defcustom org-sort-agenda-noeffort-is-high t
  1284. "Non-nil means items without effort estimate are sorted as high effort.
  1285. This also applies when filtering an agenda view with respect to the
  1286. < or > effort operator. Then, tasks with no effort defined will be treated
  1287. as tasks with high effort.
  1288. When nil, such items are sorted as 0 minutes effort."
  1289. :group 'org-agenda-sorting
  1290. :type 'boolean)
  1291. (defgroup org-agenda-line-format nil
  1292. "Options concerning the entry prefix in the Org-mode agenda display."
  1293. :tag "Org Agenda Line Format"
  1294. :group 'org-agenda)
  1295. (defcustom org-agenda-prefix-format
  1296. '((agenda . " %i %-12:c%?-12t% s")
  1297. (timeline . " % s")
  1298. (todo . " %i %-12:c")
  1299. (tags . " %i %-12:c")
  1300. (search . " %i %-12:c"))
  1301. "Format specifications for the prefix of items in the agenda views.
  1302. An alist with five entries, each for the different agenda types. The
  1303. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1304. The values are format strings.
  1305. This format works similar to a printf format, with the following meaning:
  1306. %c the category of the item, \"Diary\" for entries from the diary,
  1307. or as given by the CATEGORY keyword or derived from the file name
  1308. %e the effort required by the item
  1309. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1310. %T the last tag of the item (ignore inherited tags, which come first)
  1311. %t the HH:MM time-of-day specification if one applies to the entry
  1312. %s Scheduling/Deadline information, a short string
  1313. %(expression) Eval EXPRESSION and replace the control string
  1314. by the result
  1315. All specifiers work basically like the standard `%s' of printf, but may
  1316. contain two additional characters: a question mark just after the `%'
  1317. and a whitespace/punctuation character just before the final letter.
  1318. If the first character after `%' is a question mark, the entire field
  1319. will only be included if the corresponding value applies to the current
  1320. entry. This is useful for fields which should have fixed width when
  1321. present, but zero width when absent. For example, \"%?-12t\" will
  1322. result in a 12 character time field if a time of the day is specified,
  1323. but will completely disappear in entries which do not contain a time.
  1324. If there is punctuation or whitespace character just before the final
  1325. format letter, this character will be appended to the field value if
  1326. the value is not empty. For example, the format \"%-12:c\" leads to
  1327. \"Diary: \" if the category is \"Diary\". If the category were be
  1328. empty, no additional colon would be inserted.
  1329. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1330. which means:
  1331. - Indent the line with two space characters
  1332. - Give the category a 12 chars wide field, padded with whitespace on
  1333. the right (because of `-'). Append a colon if there is a category
  1334. (because of `:').
  1335. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1336. time, don't put in an empty field, just skip it (because of '?').
  1337. - Finally, put the scheduling information.
  1338. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1339. `org-agenda-remove-tags'.
  1340. Custom commands can set this variable in the options section."
  1341. :type '(choice
  1342. (string :tag "General format")
  1343. (list :greedy t :tag "View dependent"
  1344. (cons (const agenda) (string :tag "Format"))
  1345. (cons (const timeline) (string :tag "Format"))
  1346. (cons (const todo) (string :tag "Format"))
  1347. (cons (const tags) (string :tag "Format"))
  1348. (cons (const search) (string :tag "Format"))))
  1349. :group 'org-agenda-line-format)
  1350. (defvar org-prefix-format-compiled nil
  1351. "The compiled prefix format and associated variables.
  1352. This is a list where first element is a list of variable bindings, and second
  1353. element is the compiled format expression. See the variable
  1354. `org-agenda-prefix-format'.")
  1355. (defcustom org-agenda-todo-keyword-format "%-1s"
  1356. "Format for the TODO keyword in agenda lines.
  1357. Set this to something like \"%-12s\" if you want all TODO keywords
  1358. to occupy a fixed space in the agenda display."
  1359. :group 'org-agenda-line-format
  1360. :type 'string)
  1361. (defcustom org-agenda-diary-sexp-prefix nil
  1362. "A regexp that matches part of a diary sexp entry
  1363. which should be treated as scheduling/deadline information in
  1364. `org-agenda'.
  1365. For example, you can use this to extract the `diary-remind-message' from
  1366. `diary-remind' entries."
  1367. :group 'org-agenda-line-format
  1368. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1369. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1370. "Text preceding timerange entries in the agenda view.
  1371. This is a list with two strings. The first applies when the range
  1372. is entirely on one day. The second applies if the range spans several days.
  1373. The strings may have two \"%d\" format specifiers which will be filled
  1374. with the sequence number of the days, and the total number of days in the
  1375. range, respectively."
  1376. :group 'org-agenda-line-format
  1377. :type '(list
  1378. (string :tag "Deadline today ")
  1379. (choice :tag "Deadline relative"
  1380. (string :tag "Format string")
  1381. (function))))
  1382. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1383. "Text preceding scheduled items in the agenda view.
  1384. This is a list with two strings. The first applies when the item is
  1385. scheduled on the current day. The second applies when it has been scheduled
  1386. previously, it may contain a %d indicating that this is the nth time that
  1387. this item is scheduled, due to automatic rescheduling of unfinished items
  1388. for the following day. So this number is one larger than the number of days
  1389. that passed since this item was scheduled first."
  1390. :group 'org-agenda-line-format
  1391. :type '(list
  1392. (string :tag "Scheduled today ")
  1393. (string :tag "Scheduled previously")))
  1394. (defcustom org-agenda-inactive-leader "["
  1395. "Text preceding item pulled into the agenda by inactive time stamps.
  1396. These entries are added to the agenda when pressing \"[\"."
  1397. :group 'org-agenda-line-format
  1398. :version "24.1"
  1399. :type '(list
  1400. (string :tag "Scheduled today ")
  1401. (string :tag "Scheduled previously")))
  1402. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1403. "Text preceding deadline items in the agenda view.
  1404. This is a list with two strings. The first applies when the item has its
  1405. deadline on the current day. The second applies when it is in the past or
  1406. in the future, it may contain %d to capture how many days away the deadline
  1407. is (was)."
  1408. :group 'org-agenda-line-format
  1409. :type '(list
  1410. (string :tag "Deadline today ")
  1411. (choice :tag "Deadline relative"
  1412. (string :tag "Format string")
  1413. (function))))
  1414. (defcustom org-agenda-remove-times-when-in-prefix t
  1415. "Non-nil means remove duplicate time specifications in agenda items.
  1416. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1417. time-of-day specification in a headline or diary entry is extracted and
  1418. placed into the prefix. If this option is non-nil, the original specification
  1419. \(a timestamp or -range, or just a plain time(range) specification like
  1420. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1421. cluttered.
  1422. The option can be t or nil. It may also be the symbol `beg', indicating
  1423. that the time should only be removed when it is located at the beginning of
  1424. the headline/diary entry."
  1425. :group 'org-agenda-line-format
  1426. :type '(choice
  1427. (const :tag "Always" t)
  1428. (const :tag "Never" nil)
  1429. (const :tag "When at beginning of entry" beg)))
  1430. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1431. "Non-nil means remove time ranges specifications in agenda
  1432. items that span on several days."
  1433. :group 'org-agenda-line-format
  1434. :version "24.1"
  1435. :type 'boolean)
  1436. (defcustom org-agenda-default-appointment-duration nil
  1437. "Default duration for appointments that only have a starting time.
  1438. When nil, no duration is specified in such cases.
  1439. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1440. :group 'org-agenda-line-format
  1441. :type '(choice
  1442. (integer :tag "Minutes")
  1443. (const :tag "No default duration")))
  1444. (defcustom org-agenda-show-inherited-tags t
  1445. "Non-nil means show inherited tags in each agenda line."
  1446. :group 'org-agenda-line-format
  1447. :type 'boolean)
  1448. (defcustom org-agenda-hide-tags-regexp nil
  1449. "Regular expression used to filter away specific tags in agenda views.
  1450. This means that these tags will be present, but not be shown in the agenda
  1451. line. Secondary filtering will still work on the hidden tags.
  1452. Nil means don't hide any tags."
  1453. :group 'org-agenda-line-format
  1454. :type '(choice
  1455. (const :tag "Hide none" nil)
  1456. (string :tag "Regexp ")))
  1457. (defcustom org-agenda-remove-tags nil
  1458. "Non-nil means remove the tags from the headline copy in the agenda.
  1459. When this is the symbol `prefix', only remove tags when
  1460. `org-agenda-prefix-format' contains a `%T' specifier."
  1461. :group 'org-agenda-line-format
  1462. :type '(choice
  1463. (const :tag "Always" t)
  1464. (const :tag "Never" nil)
  1465. (const :tag "When prefix format contains %T" prefix)))
  1466. (if (fboundp 'defvaralias)
  1467. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1468. 'org-agenda-remove-tags))
  1469. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1470. "Shift tags in agenda items to this column.
  1471. If this number is positive, it specifies the column. If it is negative,
  1472. it means that the tags should be flushright to that column. For example,
  1473. -80 works well for a normal 80 character screen."
  1474. :group 'org-agenda-line-format
  1475. :type 'integer)
  1476. (if (fboundp 'defvaralias)
  1477. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1478. (defcustom org-agenda-fontify-priorities 'cookies
  1479. "Non-nil means highlight low and high priorities in agenda.
  1480. When t, the highest priority entries are bold, lowest priority italic.
  1481. However, settings in `org-priority-faces' will overrule these faces.
  1482. When this variable is the symbol `cookies', only fontify the
  1483. cookies, not the entire task.
  1484. This may also be an association list of priority faces, whose
  1485. keys are the character values of `org-highest-priority',
  1486. `org-default-priority', and `org-lowest-priority' (the default values
  1487. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1488. color as a string, or a list like `(:background \"Red\")'.
  1489. If it is a color, the variable `org-faces-easy-properties'
  1490. determines if it is a foreground or a background color."
  1491. :group 'org-agenda-line-format
  1492. :type '(choice
  1493. (const :tag "Never" nil)
  1494. (const :tag "Defaults" t)
  1495. (const :tag "Cookies only" cookies)
  1496. (repeat :tag "Specify"
  1497. (list (character :tag "Priority" :value ?A)
  1498. (choice :tag "Face "
  1499. (string :tag "Color")
  1500. (sexp :tag "Face"))))))
  1501. (defcustom org-agenda-day-face-function nil
  1502. "Function called to determine what face should be used to display a day.
  1503. The only argument passed to that function is the day. It should
  1504. returns a face, or nil if does not want to specify a face and let
  1505. the normal rules apply."
  1506. :group 'org-agenda-line-format
  1507. :version "24.1"
  1508. :type 'function)
  1509. (defcustom org-agenda-category-icon-alist nil
  1510. "Alist of category icon to be displayed in agenda views.
  1511. Each entry should have the following format:
  1512. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1513. Where CATEGORY-REGEXP is a regexp matching the categories where
  1514. the icon should be displayed.
  1515. FILE-OR-DATA either a file path or a string containing image data.
  1516. The other fields can be omitted safely if not needed:
  1517. TYPE indicates the image type.
  1518. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1519. image data.
  1520. PROPS are additional image attributes to assign to the image,
  1521. like, e.g. `:ascent center'.
  1522. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1523. If you want to set the display properties yourself, just put a
  1524. list as second element:
  1525. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1526. For example, to display a 16px horizontal space for Emacs
  1527. category, you can use:
  1528. (\"Emacs\" '(space . (:width (16))))"
  1529. :group 'org-agenda-line-format
  1530. :version "24.1"
  1531. :type '(alist :key-type (string :tag "Regexp matching category")
  1532. :value-type (choice (list :tag "Icon"
  1533. (string :tag "File or data")
  1534. (symbol :tag "Type")
  1535. (boolean :tag "Data?")
  1536. (repeat :tag "Extra image properties" :inline t symbol))
  1537. (list :tag "Display properties" sexp))))
  1538. (defgroup org-agenda-column-view nil
  1539. "Options concerning column view in the agenda."
  1540. :tag "Org Agenda Column View"
  1541. :group 'org-agenda)
  1542. (defcustom org-agenda-columns-show-summaries t
  1543. "Non-nil means show summaries for columns displayed in the agenda view."
  1544. :group 'org-agenda-column-view
  1545. :type 'boolean)
  1546. (defcustom org-agenda-columns-compute-summary-properties t
  1547. "Non-nil means recompute all summary properties before column view.
  1548. When column view in the agenda is listing properties that have a summary
  1549. operator, it can go to all relevant buffers and recompute the summaries
  1550. there. This can mean overhead for the agenda column view, but is necessary
  1551. to have thing up to date.
  1552. As a special case, a CLOCKSUM property also makes sure that the clock
  1553. computations are current."
  1554. :group 'org-agenda-column-view
  1555. :type 'boolean)
  1556. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1557. "Non-nil means the duration of an appointment will add to day effort.
  1558. The property to which appointment durations will be added is the one given
  1559. in the option `org-effort-property'. If an appointment does not have
  1560. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1561. is not set, an appointment without end time will not contribute to the time
  1562. estimate."
  1563. :group 'org-agenda-column-view
  1564. :type 'boolean)
  1565. (defcustom org-agenda-auto-exclude-function nil
  1566. "A function called with a tag to decide if it is filtered on '/ RET'.
  1567. The sole argument to the function, which is called once for each
  1568. possible tag, is a string giving the name of the tag. The
  1569. function should return either nil if the tag should be included
  1570. as normal, or \"-<TAG>\" to exclude the tag.
  1571. Note that for the purpose of tag filtering, only the lower-case version of
  1572. all tags will be considered, so that this function will only ever see
  1573. the lower-case version of all tags."
  1574. :group 'org-agenda
  1575. :type 'function)
  1576. (defcustom org-agenda-bulk-custom-functions nil
  1577. "Alist of characters and custom functions for bulk actions.
  1578. For example, this value makes those two functions available:
  1579. '((?R set-category)
  1580. (?C bulk-cut))
  1581. With selected entries in an agenda buffer, `B R' will call
  1582. the custom function `set-category' on the selected entries.
  1583. Note that functions in this alist don't need to be quoted."
  1584. :type 'alist
  1585. :version "24.1"
  1586. :group 'org-agenda)
  1587. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1588. "Execute BODY with point at location given by `org-hd-marker' property.
  1589. If STRING is non-nil, the text property will be fetched from position 0
  1590. in that string. If STRING is nil, it will be fetched from the beginning
  1591. of the current line."
  1592. (org-with-gensyms (marker)
  1593. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1594. 'org-hd-marker ,string)))
  1595. (with-current-buffer (marker-buffer ,marker)
  1596. (save-excursion
  1597. (goto-char ,marker)
  1598. ,@body)))))
  1599. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1600. (defun org-add-agenda-custom-command (entry)
  1601. "Replace or add a command in `org-agenda-custom-commands'.
  1602. This is mostly for hacking and trying a new command - once the command
  1603. works you probably want to add it to `org-agenda-custom-commands' for good."
  1604. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1605. (if ass
  1606. (setcdr ass (cdr entry))
  1607. (push entry org-agenda-custom-commands))))
  1608. ;;; Define the org-agenda-mode
  1609. (defvar org-agenda-mode-map (make-sparse-keymap)
  1610. "Keymap for `org-agenda-mode'.")
  1611. (if (fboundp 'defvaralias)
  1612. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1613. (defvar org-agenda-menu) ; defined later in this file.
  1614. (defvar org-agenda-restrict) ; defined later in this file.
  1615. (defvar org-agenda-follow-mode nil)
  1616. (defvar org-agenda-entry-text-mode nil)
  1617. (defvar org-agenda-clockreport-mode nil)
  1618. (defvar org-agenda-show-log nil)
  1619. (defvar org-agenda-redo-command nil)
  1620. (defvar org-agenda-query-string nil)
  1621. (defvar org-agenda-mode-hook nil
  1622. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1623. (defvar org-agenda-type nil)
  1624. (defvar org-agenda-force-single-file nil)
  1625. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1626. ;;; Multiple agenda buffers support
  1627. (defcustom org-agenda-sticky nil
  1628. "Non-nil means agenda q key will bury agenda buffers.
  1629. Agenda commands will then show existing buffer instead of generating new ones.
  1630. When nil, `q' will kill the single agenda buffer."
  1631. :group 'org-agenda
  1632. :type 'boolean
  1633. :set (lambda (var val)
  1634. (if (boundp var)
  1635. (org-toggle-sticky-agenda (if val 1 0))
  1636. (set var val))))
  1637. (defun org-toggle-sticky-agenda (&optional arg)
  1638. "Toggle `org-agenda-sticky'."
  1639. (interactive "P")
  1640. (let ((new-value (if arg
  1641. (> (prefix-numeric-value arg) 0)
  1642. (not org-agenda-sticky))))
  1643. (if (equal new-value org-agenda-sticky)
  1644. (and (org-called-interactively-p 'interactive)
  1645. (message "Sticky agenda was already %s"
  1646. (if org-agenda-sticky "enabled" "disabled")))
  1647. (setq org-agenda-sticky new-value)
  1648. (org-agenda-kill-all-agenda-buffers)
  1649. (and (org-called-interactively-p 'interactive)
  1650. (message "Sticky agenda was %s"
  1651. (if org-agenda-sticky "enabled" "disabled"))))))
  1652. (defvar org-agenda-buffer nil
  1653. "Agenda buffer currently being generated.")
  1654. (defvar org-agenda-last-prefix-arg nil)
  1655. (defvar org-agenda-this-buffer-name nil)
  1656. (defvar org-agenda-doing-sticky-redo nil)
  1657. (defvar org-agenda-this-buffer-is-sticky nil)
  1658. (defconst org-agenda-local-vars
  1659. '(org-agenda-this-buffer-name
  1660. org-agenda-undo-list
  1661. org-agenda-pending-undo-list
  1662. org-agenda-follow-mode
  1663. org-agenda-entry-text-mode
  1664. org-agenda-clockreport-mode
  1665. org-agenda-show-log
  1666. org-agenda-redo-command
  1667. org-agenda-query-string
  1668. org-agenda-type
  1669. org-agenda-bulk-marked-entries
  1670. org-agenda-undo-has-started-in
  1671. org-agenda-last-arguments
  1672. org-agenda-info
  1673. org-agenda-tag-filter-overlays
  1674. org-agenda-cat-filter-overlays
  1675. org-pre-agenda-window-conf
  1676. org-agenda-columns-active
  1677. org-agenda-tag-filter
  1678. org-agenda-category-filter
  1679. org-agenda-markers
  1680. org-agenda-last-search-view-search-was-boolean
  1681. org-agenda-filtered-by-category
  1682. org-agenda-filter-form
  1683. org-agenda-show-window
  1684. org-agenda-cycle-counter
  1685. org-agenda-last-prefix-arg)
  1686. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1687. (defun org-agenda-mode ()
  1688. "Mode for time-sorted view on action items in Org-mode files.
  1689. The following commands are available:
  1690. \\{org-agenda-mode-map}"
  1691. (interactive)
  1692. (cond (org-agenda-doing-sticky-redo
  1693. ;; Refreshing sticky agenda-buffer
  1694. ;;
  1695. ;; Preserve the value of `org-agenda-local-vars' variables,
  1696. ;; while letting `kill-all-local-variables' kill the rest
  1697. (let ((save (buffer-local-variables)))
  1698. (kill-all-local-variables)
  1699. (mapc 'make-local-variable org-agenda-local-vars)
  1700. (dolist (elem save)
  1701. (let ((var (car elem))
  1702. (val (cdr elem)))
  1703. (when (and val
  1704. (member var org-agenda-local-vars))
  1705. (set var val)))))
  1706. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1707. (org-agenda-sticky
  1708. ;; Creating a sticky Agenda buffer for the first time
  1709. (kill-all-local-variables)
  1710. (mapc 'make-local-variable org-agenda-local-vars)
  1711. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1712. (t
  1713. ;; Creating a non-sticky agenda buffer
  1714. (kill-all-local-variables)
  1715. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1716. (setq org-agenda-undo-list nil
  1717. org-agenda-pending-undo-list nil
  1718. org-agenda-bulk-marked-entries nil)
  1719. (setq major-mode 'org-agenda-mode)
  1720. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1721. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1722. (setq mode-name "Org-Agenda")
  1723. (use-local-map org-agenda-mode-map)
  1724. (easy-menu-add org-agenda-menu)
  1725. (if org-startup-truncated (setq truncate-lines t))
  1726. (org-set-local 'line-move-visual nil)
  1727. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1728. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1729. ;; Make sure properties are removed when copying text
  1730. (make-local-variable 'filter-buffer-substring-functions)
  1731. (add-hook 'filter-buffer-substring-functions
  1732. (lambda (fun start end delete)
  1733. (substring-no-properties (funcall fun start end delete))))
  1734. (unless org-agenda-keep-modes
  1735. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1736. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1737. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1738. org-agenda-show-log org-agenda-start-with-log-mode))
  1739. (easy-menu-change
  1740. '("Agenda") "Agenda Files"
  1741. (append
  1742. (list
  1743. (vector
  1744. (if (get 'org-agenda-files 'org-restrict)
  1745. "Restricted to single file"
  1746. "Edit File List")
  1747. '(org-edit-agenda-file-list)
  1748. (not (get 'org-agenda-files 'org-restrict)))
  1749. "--")
  1750. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1751. (org-agenda-set-mode-name)
  1752. (apply
  1753. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1754. (list 'org-agenda-mode-hook)))
  1755. (substitute-key-definition 'undo 'org-agenda-undo
  1756. org-agenda-mode-map global-map)
  1757. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1758. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1759. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1760. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1761. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1762. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1763. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1764. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1765. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1766. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1767. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1768. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1769. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1770. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1771. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1772. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1773. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1774. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1775. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1776. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1777. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1778. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1779. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1780. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1781. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1782. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1783. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1784. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1785. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1786. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1787. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1788. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1789. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1790. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1791. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1792. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1793. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1794. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1795. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1796. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1797. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1798. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1799. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1800. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1801. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1802. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1803. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1804. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1805. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1806. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1807. (while l (org-defkey org-agenda-mode-map
  1808. (int-to-string (pop l)) 'digit-argument)))
  1809. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1810. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1811. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1812. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1813. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1814. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1815. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1816. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1817. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1818. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1819. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1820. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1821. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1822. 'org-clock-modify-effort-estimate)
  1823. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1824. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1825. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1826. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1827. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1828. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1829. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1830. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1831. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1832. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1833. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1834. (substitute-key-definition 'next-line 'org-agenda-next-line
  1835. org-agenda-mode-map global-map)
  1836. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1837. org-agenda-mode-map global-map)
  1838. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1839. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1840. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1841. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1842. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1843. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1844. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1845. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1846. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1847. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1848. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1849. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1850. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1851. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1852. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1853. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1854. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1855. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1856. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1857. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1858. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1859. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1860. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1861. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1862. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1863. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1864. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1865. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1866. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1867. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1868. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1869. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1870. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1871. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1872. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1873. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1874. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1875. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1876. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1877. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1878. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1879. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1880. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1881. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1882. (when org-agenda-mouse-1-follows-link
  1883. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1884. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1885. '("Agenda"
  1886. ("Agenda Files")
  1887. "--"
  1888. ("Agenda Dates"
  1889. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1890. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1891. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1892. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1893. "--"
  1894. ("View"
  1895. ["Day View" org-agenda-day-view
  1896. :active (org-agenda-check-type nil 'agenda)
  1897. :style radio :selected (eq org-agenda-current-span 'day)
  1898. :keys "v d (or just d)"]
  1899. ["Week View" org-agenda-week-view
  1900. :active (org-agenda-check-type nil 'agenda)
  1901. :style radio :selected (eq org-agenda-current-span 'week)
  1902. :keys "v w (or just w)"]
  1903. ["Month View" org-agenda-month-view
  1904. :active (org-agenda-check-type nil 'agenda)
  1905. :style radio :selected (eq org-agenda-current-span 'month)
  1906. :keys "v m"]
  1907. ["Year View" org-agenda-year-view
  1908. :active (org-agenda-check-type nil 'agenda)
  1909. :style radio :selected (eq org-agenda-current-span 'year)
  1910. :keys "v y"]
  1911. "--"
  1912. ["Include Diary" org-agenda-toggle-diary
  1913. :style toggle :selected org-agenda-include-diary
  1914. :active (org-agenda-check-type nil 'agenda)]
  1915. ["Include Deadlines" org-agenda-toggle-deadlines
  1916. :style toggle :selected org-agenda-include-deadlines
  1917. :active (org-agenda-check-type nil 'agenda)]
  1918. ["Use Time Grid" org-agenda-toggle-time-grid
  1919. :style toggle :selected org-agenda-use-time-grid
  1920. :active (org-agenda-check-type nil 'agenda)]
  1921. "--"
  1922. ["Show clock report" org-agenda-clockreport-mode
  1923. :style toggle :selected org-agenda-clockreport-mode
  1924. :active (org-agenda-check-type nil 'agenda)]
  1925. ["Show some entry text" org-agenda-entry-text-mode
  1926. :style toggle :selected org-agenda-entry-text-mode
  1927. :active t]
  1928. "--"
  1929. ["Show Logbook entries" org-agenda-log-mode
  1930. :style toggle :selected org-agenda-show-log
  1931. :active (org-agenda-check-type nil 'agenda 'timeline)
  1932. :keys "v l (or just l)"]
  1933. ["Include archived trees" org-agenda-archives-mode
  1934. :style toggle :selected org-agenda-archives-mode :active t
  1935. :keys "v a"]
  1936. ["Include archive files" (org-agenda-archives-mode t)
  1937. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1938. :keys "v A"]
  1939. "--"
  1940. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1941. ["Write view to file" org-agenda-write t]
  1942. ["Rebuild buffer" org-agenda-redo t]
  1943. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1944. "--"
  1945. ["Show original entry" org-agenda-show t]
  1946. ["Go To (other window)" org-agenda-goto t]
  1947. ["Go To (this window)" org-agenda-switch-to t]
  1948. ["Follow Mode" org-agenda-follow-mode
  1949. :style toggle :selected org-agenda-follow-mode :active t]
  1950. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1951. "--"
  1952. ("TODO"
  1953. ["Cycle TODO" org-agenda-todo t]
  1954. ["Next TODO set" org-agenda-todo-nextset t]
  1955. ["Previous TODO set" org-agenda-todo-previousset t]
  1956. ["Add note" org-agenda-add-note t])
  1957. ("Archive/Refile/Delete"
  1958. ["Archive default" org-agenda-archive-default t]
  1959. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1960. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1961. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1962. ["Archive subtree" org-agenda-archive t]
  1963. "--"
  1964. ["Refile" org-agenda-refile t]
  1965. "--"
  1966. ["Delete subtree" org-agenda-kill t])
  1967. ("Bulk action"
  1968. ["Mark entry" org-agenda-bulk-mark t]
  1969. ["Mark all" org-agenda-bulk-mark-all t]
  1970. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1971. ["Unmark entry" org-agenda-bulk-unmark t]
  1972. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
  1973. ["Act on all marked" org-agenda-bulk-action t]
  1974. "--"
  1975. ("Tags and Properties"
  1976. ["Show all Tags" org-agenda-show-tags t]
  1977. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1978. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1979. "--"
  1980. ["Column View" org-columns t])
  1981. ("Deadline/Schedule"
  1982. ["Schedule" org-agenda-schedule t]
  1983. ["Set Deadline" org-agenda-deadline t]
  1984. "--"
  1985. ["Mark item" org-agenda-action :active t :keys "k m"]
  1986. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1987. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1988. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1989. "--"
  1990. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1991. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1992. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1993. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1994. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1995. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1996. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1997. ("Clock and Effort"
  1998. ["Clock in" org-agenda-clock-in t]
  1999. ["Clock out" org-agenda-clock-out t]
  2000. ["Clock cancel" org-agenda-clock-cancel t]
  2001. ["Goto running clock" org-clock-goto t]
  2002. "--"
  2003. ["Set Effort" org-agenda-set-effort t]
  2004. ["Change clocked effort" org-clock-modify-effort-estimate
  2005. (org-clock-is-active)])
  2006. ("Priority"
  2007. ["Set Priority" org-agenda-priority t]
  2008. ["Increase Priority" org-agenda-priority-up t]
  2009. ["Decrease Priority" org-agenda-priority-down t]
  2010. ["Show Priority" org-agenda-show-priority t])
  2011. ("Calendar/Diary"
  2012. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2013. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2014. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2015. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2016. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2017. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2018. "--"
  2019. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2020. "--"
  2021. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2022. "--"
  2023. ("MobileOrg"
  2024. ["Push Files and Views" org-mobile-push t]
  2025. ["Get Captured and Flagged" org-mobile-pull t]
  2026. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2027. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2028. "--"
  2029. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2030. "--"
  2031. ["Quit" org-agenda-quit t]
  2032. ["Exit and Release Buffers" org-agenda-exit t]
  2033. ))
  2034. ;;; Agenda undo
  2035. (defvar org-agenda-allow-remote-undo t
  2036. "Non-nil means allow remote undo from the agenda buffer.")
  2037. (defvar org-agenda-undo-list nil
  2038. "List of undoable operations in the agenda since last refresh.")
  2039. (defvar org-agenda-undo-has-started-in nil
  2040. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2041. (defvar org-agenda-pending-undo-list nil
  2042. "In a series of undo commands, this is the list of remaining undo items.")
  2043. (defun org-agenda-undo ()
  2044. "Undo a remote editing step in the agenda.
  2045. This undoes changes both in the agenda buffer and in the remote buffer
  2046. that have been changed along."
  2047. (interactive)
  2048. (or org-agenda-allow-remote-undo
  2049. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2050. (if (not (eq this-command last-command))
  2051. (setq org-agenda-undo-has-started-in nil
  2052. org-agenda-pending-undo-list org-agenda-undo-list))
  2053. (if (not org-agenda-pending-undo-list)
  2054. (error "No further undo information"))
  2055. (let* ((entry (pop org-agenda-pending-undo-list))
  2056. buf line cmd rembuf)
  2057. (setq cmd (pop entry) line (pop entry))
  2058. (setq rembuf (nth 2 entry))
  2059. (org-with-remote-undo rembuf
  2060. (while (bufferp (setq buf (pop entry)))
  2061. (if (pop entry)
  2062. (with-current-buffer buf
  2063. (let ((last-undo-buffer buf)
  2064. (inhibit-read-only t))
  2065. (unless (memq buf org-agenda-undo-has-started-in)
  2066. (push buf org-agenda-undo-has-started-in)
  2067. (make-local-variable 'pending-undo-list)
  2068. (undo-start))
  2069. (while (and pending-undo-list
  2070. (listp pending-undo-list)
  2071. (not (car pending-undo-list)))
  2072. (pop pending-undo-list))
  2073. (undo-more 1))))))
  2074. (org-goto-line line)
  2075. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2076. (defun org-verify-change-for-undo (l1 l2)
  2077. "Verify that a real change occurred between the undo lists L1 and L2."
  2078. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2079. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2080. (not (eq l1 l2)))
  2081. ;;; Agenda dispatch
  2082. (defvar org-agenda-restrict nil)
  2083. (defvar org-agenda-restrict-begin (make-marker))
  2084. (defvar org-agenda-restrict-end (make-marker))
  2085. (defvar org-agenda-last-dispatch-buffer nil)
  2086. (defvar org-agenda-overriding-restriction nil)
  2087. ;;;###autoload
  2088. (defun org-agenda (&optional arg keys restriction)
  2089. "Dispatch agenda commands to collect entries to the agenda buffer.
  2090. Prompts for a command to execute. Any prefix arg will be passed
  2091. on to the selected command. The default selections are:
  2092. a Call `org-agenda-list' to display the agenda for current day or week.
  2093. t Call `org-todo-list' to display the global todo list.
  2094. T Call `org-todo-list' to display the global todo list, select only
  2095. entries with a specific TODO keyword (the user gets a prompt).
  2096. m Call `org-tags-view' to display headlines with tags matching
  2097. a condition (the user is prompted for the condition).
  2098. M Like `m', but select only TODO entries, no ordinary headlines.
  2099. L Create a timeline for the current buffer.
  2100. e Export views to associated files.
  2101. s Search entries for keywords.
  2102. / Multi occur across all agenda files and also files listed
  2103. in `org-agenda-text-search-extra-files'.
  2104. < Restrict agenda commands to buffer, subtree, or region.
  2105. Press several times to get the desired effect.
  2106. > Remove a previous restriction.
  2107. # List \"stuck\" projects.
  2108. ! Configure what \"stuck\" means.
  2109. C Configure custom agenda commands.
  2110. More commands can be added by configuring the variable
  2111. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2112. searches can be pre-defined in this way.
  2113. If the current buffer is in Org-mode and visiting a file, you can also
  2114. first press `<' once to indicate that the agenda should be temporarily
  2115. \(until the next use of \\[org-agenda]) restricted to the current file.
  2116. Pressing `<' twice means to restrict to the current subtree or region
  2117. \(if active)."
  2118. (interactive "P")
  2119. (catch 'exit
  2120. (let* ((prefix-descriptions nil)
  2121. (org-agenda-buffer-name org-agenda-buffer-name)
  2122. (org-agenda-window-setup (if (equal (buffer-name)
  2123. org-agenda-buffer-name)
  2124. 'current-window
  2125. org-agenda-window-setup))
  2126. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2127. (org-agenda-custom-commands
  2128. ;; normalize different versions
  2129. (delq nil
  2130. (mapcar
  2131. (lambda (x)
  2132. (cond ((stringp (cdr x))
  2133. (push x prefix-descriptions)
  2134. nil)
  2135. ((stringp (nth 1 x)) x)
  2136. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2137. (t (cons (car x) (cons "" (cdr x))))))
  2138. org-agenda-custom-commands)))
  2139. (buf (current-buffer))
  2140. (bfn (buffer-file-name (buffer-base-buffer)))
  2141. entry key type match lprops ans)
  2142. ;; Turn off restriction unless there is an overriding one,
  2143. (unless org-agenda-overriding-restriction
  2144. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2145. ;; There is a request to keep the file list in place
  2146. (put 'org-agenda-files 'org-restrict nil))
  2147. (setq org-agenda-restrict nil)
  2148. (move-marker org-agenda-restrict-begin nil)
  2149. (move-marker org-agenda-restrict-end nil))
  2150. ;; Delete old local properties
  2151. (put 'org-agenda-redo-command 'org-lprops nil)
  2152. ;; Delete previously set last-arguments
  2153. (put 'org-agenda-redo-command 'last-args nil)
  2154. ;; Remember where this call originated
  2155. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2156. (unless keys
  2157. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2158. keys (car ans)
  2159. restriction (cdr ans)))
  2160. ;; If we have sticky agenda buffers, set a name for the buffer,
  2161. ;; depending on the invoking keys. The user may still set this
  2162. ;; as a command option, which will overwrite what we do here.
  2163. (if org-agenda-sticky
  2164. (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
  2165. ;; Establish the restriction, if any
  2166. (when (and (not org-agenda-overriding-restriction) restriction)
  2167. (put 'org-agenda-files 'org-restrict (list bfn))
  2168. (cond
  2169. ((eq restriction 'region)
  2170. (setq org-agenda-restrict t)
  2171. (move-marker org-agenda-restrict-begin (region-beginning))
  2172. (move-marker org-agenda-restrict-end (region-end)))
  2173. ((eq restriction 'subtree)
  2174. (save-excursion
  2175. (setq org-agenda-restrict t)
  2176. (org-back-to-heading t)
  2177. (move-marker org-agenda-restrict-begin (point))
  2178. (move-marker org-agenda-restrict-end
  2179. (progn (org-end-of-subtree t)))))))
  2180. ;; For example the todo list should not need it (but does...)
  2181. (cond
  2182. ((setq entry (assoc keys org-agenda-custom-commands))
  2183. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2184. (progn
  2185. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2186. lprops (nth 4 entry))
  2187. (put 'org-agenda-redo-command 'org-lprops lprops)
  2188. (cond
  2189. ((eq type 'agenda)
  2190. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2191. ((eq type 'alltodo)
  2192. (org-let lprops '(org-todo-list current-prefix-arg)))
  2193. ((eq type 'search)
  2194. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2195. ((eq type 'stuck)
  2196. (org-let lprops '(org-agenda-list-stuck-projects
  2197. current-prefix-arg)))
  2198. ((eq type 'tags)
  2199. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2200. ((eq type 'tags-todo)
  2201. (org-let lprops '(org-tags-view '(4) match)))
  2202. ((eq type 'todo)
  2203. (org-let lprops '(org-todo-list match)))
  2204. ((eq type 'tags-tree)
  2205. (org-check-for-org-mode)
  2206. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2207. ((eq type 'todo-tree)
  2208. (org-check-for-org-mode)
  2209. (org-let lprops
  2210. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2211. (regexp-quote match) "\\>"))))
  2212. ((eq type 'occur-tree)
  2213. (org-check-for-org-mode)
  2214. (org-let lprops '(org-occur match)))
  2215. ((functionp type)
  2216. (org-let lprops '(funcall type match)))
  2217. ((fboundp type)
  2218. (org-let lprops '(funcall type match)))
  2219. (t (error "Invalid custom agenda command type %s" type))))
  2220. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2221. ((equal keys "C")
  2222. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2223. (customize-variable 'org-agenda-custom-commands))
  2224. ((equal keys "a") (call-interactively 'org-agenda-list))
  2225. ((equal keys "s") (call-interactively 'org-search-view))
  2226. ((equal keys "t") (call-interactively 'org-todo-list))
  2227. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2228. ((equal keys "m") (call-interactively 'org-tags-view))
  2229. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2230. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2231. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2232. (org-add-hook
  2233. 'post-command-hook
  2234. (lambda ()
  2235. (unless (current-message)
  2236. (let* ((m (org-agenda-get-any-marker))
  2237. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2238. (when note
  2239. (message (concat
  2240. "FLAGGING-NOTE ([?] for more info): "
  2241. (org-add-props
  2242. (replace-regexp-in-string
  2243. "\\\\n" "//"
  2244. (copy-sequence note))
  2245. nil 'face 'org-warning)))))))
  2246. t t))
  2247. ((equal keys "L")
  2248. (unless (derived-mode-p 'org-mode)
  2249. (error "This is not an Org-mode file"))
  2250. (unless restriction
  2251. (put 'org-agenda-files 'org-restrict (list bfn))
  2252. (org-call-with-arg 'org-timeline arg)))
  2253. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2254. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2255. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2256. (t (error "Invalid agenda key"))))))
  2257. (defun org-agenda-append-agenda ()
  2258. "Append another agenda view to the current one.
  2259. This function allows interactive building of block agendas.
  2260. Agenda views are separated by `org-agenda-block-separator'."
  2261. (interactive)
  2262. (unless (string= (buffer-name) org-agenda-buffer-name)
  2263. (error "Can only append from within agenda buffer"))
  2264. (let ((org-agenda-multi t))
  2265. (org-agenda)
  2266. (widen)))
  2267. (defun org-agenda-normalize-custom-commands (cmds)
  2268. (delq nil
  2269. (mapcar
  2270. (lambda (x)
  2271. (cond ((stringp (cdr x)) nil)
  2272. ((stringp (nth 1 x)) x)
  2273. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2274. (t (cons (car x) (cons "" (cdr x))))))
  2275. cmds)))
  2276. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2277. "The user interface for selecting an agenda command."
  2278. (catch 'exit
  2279. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2280. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2281. (region-p (org-region-active-p))
  2282. (custom org-agenda-custom-commands)
  2283. (selstring "")
  2284. restriction second-time
  2285. c entry key type match prefixes rmheader header-end custom1 desc
  2286. line lines left right n n1)
  2287. (save-window-excursion
  2288. (delete-other-windows)
  2289. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2290. (erase-buffer)
  2291. (insert (eval-when-compile
  2292. (let ((header
  2293. "Press key for an agenda command: < Buffer, subtree/region restriction
  2294. -------------------------------- > Remove restriction
  2295. a Agenda for current week or day e Export agenda views
  2296. t List of all TODO entries T Entries with special TODO kwd
  2297. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2298. L Timeline for current buffer # List stuck projects (!=configure)
  2299. s Search for keywords * Toggle sticky agenda views
  2300. / Multi-occur ? Find :FLAGGED: entries
  2301. C Configure custom agenda commands
  2302. ")
  2303. (start 0))
  2304. (while (string-match
  2305. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2306. header start)
  2307. (setq start (match-end 0))
  2308. (add-text-properties (match-beginning 2) (match-end 2)
  2309. '(face bold) header))
  2310. header)))
  2311. (setq header-end (move-marker (make-marker) (point)))
  2312. (while t
  2313. (setq custom1 custom)
  2314. (when (eq rmheader t)
  2315. (org-goto-line 1)
  2316. (re-search-forward ":" nil t)
  2317. (delete-region (match-end 0) (point-at-eol))
  2318. (forward-char 1)
  2319. (looking-at "-+")
  2320. (delete-region (match-end 0) (point-at-eol))
  2321. (move-marker header-end (match-end 0)))
  2322. (goto-char header-end)
  2323. (delete-region (point) (point-max))
  2324. ;; Produce all the lines that describe custom commands and prefixes
  2325. (setq lines nil)
  2326. (while (setq entry (pop custom1))
  2327. (setq key (car entry) desc (nth 1 entry)
  2328. type (nth 2 entry)
  2329. match (nth 3 entry))
  2330. (if (> (length key) 1)
  2331. (add-to-list 'prefixes (string-to-char key))
  2332. (setq line
  2333. (format
  2334. "%-4s%-14s"
  2335. (org-add-props (copy-sequence key)
  2336. '(face bold))
  2337. (cond
  2338. ((string-match "\\S-" desc) desc)
  2339. ((eq type 'agenda) "Agenda for current week or day")
  2340. ((eq type 'alltodo) "List of all TODO entries")
  2341. ((eq type 'search) "Word search")
  2342. ((eq type 'stuck) "List of stuck projects")
  2343. ((eq type 'todo) "TODO keyword")
  2344. ((eq type 'tags) "Tags query")
  2345. ((eq type 'tags-todo) "Tags (TODO)")
  2346. ((eq type 'tags-tree) "Tags tree")
  2347. ((eq type 'todo-tree) "TODO kwd tree")
  2348. ((eq type 'occur-tree) "Occur tree")
  2349. ((functionp type) (if (symbolp type)
  2350. (symbol-name type)
  2351. "Lambda expression"))
  2352. (t "???"))))
  2353. (if org-agenda-menu-show-matcher
  2354. (setq line
  2355. (concat line ": "
  2356. (cond
  2357. ((stringp match)
  2358. (setq match (copy-sequence match))
  2359. (org-add-props match nil 'face 'org-warning))
  2360. (match
  2361. (format "set of %d commands" (length match)))
  2362. (t ""))))
  2363. (if (org-string-nw-p match)
  2364. (add-text-properties
  2365. 0 (length line) (list 'help-echo
  2366. (concat "Matcher: "match)) line)))
  2367. (push line lines)))
  2368. (setq lines (nreverse lines))
  2369. (when prefixes
  2370. (mapc (lambda (x)
  2371. (push
  2372. (format "%s %s"
  2373. (org-add-props (char-to-string x)
  2374. nil 'face 'bold)
  2375. (or (cdr (assoc (concat selstring
  2376. (char-to-string x))
  2377. prefix-descriptions))
  2378. "Prefix key"))
  2379. lines))
  2380. prefixes))
  2381. ;; Check if we should display in two columns
  2382. (if org-agenda-menu-two-column
  2383. (progn
  2384. (setq n (length lines)
  2385. n1 (+ (/ n 2) (mod n 2))
  2386. right (nthcdr n1 lines)
  2387. left (copy-sequence lines))
  2388. (setcdr (nthcdr (1- n1) left) nil))
  2389. (setq left lines right nil))
  2390. (while left
  2391. (insert "\n" (pop left))
  2392. (when right
  2393. (if (< (current-column) 40)
  2394. (move-to-column 40 t)
  2395. (insert " "))
  2396. (insert (pop right))))
  2397. ;; Make the window the right size
  2398. (goto-char (point-min))
  2399. (if second-time
  2400. (if (not (pos-visible-in-window-p (point-max)))
  2401. (org-fit-window-to-buffer))
  2402. (setq second-time t)
  2403. (org-fit-window-to-buffer))
  2404. ;; Ask for selection
  2405. (message "Press key for agenda command%s:"
  2406. (if (or restrict-ok org-agenda-overriding-restriction)
  2407. (if org-agenda-overriding-restriction
  2408. " (restriction lock active)"
  2409. (if restriction
  2410. (format " (restricted to %s)" restriction)
  2411. " (unrestricted)"))
  2412. ""))
  2413. (setq c (read-char-exclusive))
  2414. (message "")
  2415. (cond
  2416. ((assoc (char-to-string c) custom)
  2417. (setq selstring (concat selstring (char-to-string c)))
  2418. (throw 'exit (cons selstring restriction)))
  2419. ((memq c prefixes)
  2420. (setq selstring (concat selstring (char-to-string c))
  2421. prefixes nil
  2422. rmheader (or rmheader t)
  2423. custom (delq nil (mapcar
  2424. (lambda (x)
  2425. (if (or (= (length (car x)) 1)
  2426. (/= (string-to-char (car x)) c))
  2427. nil
  2428. (cons (substring (car x) 1) (cdr x))))
  2429. custom))))
  2430. ((eq c ?*)
  2431. (call-interactively 'org-toggle-sticky-agenda)
  2432. (sit-for 2))
  2433. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2434. (message "Restriction is only possible in Org-mode buffers")
  2435. (ding) (sit-for 1))
  2436. ((eq c ?1)
  2437. (org-agenda-remove-restriction-lock 'noupdate)
  2438. (setq restriction 'buffer))
  2439. ((eq c ?0)
  2440. (org-agenda-remove-restriction-lock 'noupdate)
  2441. (setq restriction (if region-p 'region 'subtree)))
  2442. ((eq c ?<)
  2443. (org-agenda-remove-restriction-lock 'noupdate)
  2444. (setq restriction
  2445. (cond
  2446. ((eq restriction 'buffer)
  2447. (if region-p 'region 'subtree))
  2448. ((memq restriction '(subtree region))
  2449. nil)
  2450. (t 'buffer))))
  2451. ((eq c ?>)
  2452. (org-agenda-remove-restriction-lock 'noupdate)
  2453. (setq restriction nil))
  2454. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2455. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2456. ((and (> (length selstring) 0) (eq c ?\d))
  2457. (delete-window)
  2458. (org-agenda-get-restriction-and-command prefix-descriptions))
  2459. ((equal c ?q) (error "Abort"))
  2460. (t (error "Invalid key %c" c))))))))
  2461. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2462. (defvar org-agenda-last-arguments nil
  2463. "The arguments of the previous call to `org-agenda'.")
  2464. (defun org-agenda-run-series (name series)
  2465. (org-let (nth 1 series) '(org-prepare-agenda name))
  2466. ;; We need to reset agenda markers here, because when constructing a
  2467. ;; block agenda, the individual blocks do not do that.
  2468. (org-agenda-reset-markers)
  2469. (let* ((org-agenda-multi t)
  2470. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2471. (org-agenda-overriding-arguments
  2472. (or org-agenda-overriding-arguments
  2473. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2474. (get 'org-agenda-redo-command 'last-args))))
  2475. (cmds (car series))
  2476. (gprops (nth 1 series))
  2477. match ;; The byte compiler incorrectly complains about this. Keep it!
  2478. cmd type lprops)
  2479. (while (setq cmd (pop cmds))
  2480. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2481. (cond
  2482. ((eq type 'agenda)
  2483. (org-let2 gprops lprops
  2484. '(call-interactively 'org-agenda-list)))
  2485. ((eq type 'alltodo)
  2486. (org-let2 gprops lprops
  2487. '(call-interactively 'org-todo-list)))
  2488. ((eq type 'search)
  2489. (org-let2 gprops lprops
  2490. '(org-search-view current-prefix-arg match nil)))
  2491. ((eq type 'stuck)
  2492. (org-let2 gprops lprops
  2493. '(call-interactively 'org-agenda-list-stuck-projects)))
  2494. ((eq type 'tags)
  2495. (org-let2 gprops lprops
  2496. '(org-tags-view current-prefix-arg match)))
  2497. ((eq type 'tags-todo)
  2498. (org-let2 gprops lprops
  2499. '(org-tags-view '(4) match)))
  2500. ((eq type 'todo)
  2501. (org-let2 gprops lprops
  2502. '(org-todo-list match)))
  2503. ((fboundp type)
  2504. (org-let2 gprops lprops
  2505. '(funcall type match)))
  2506. (t (error "Invalid type in command series"))))
  2507. (widen)
  2508. (setq org-agenda-redo-command redo)
  2509. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2510. (goto-char (point-min)))
  2511. (org-fit-agenda-window)
  2512. (org-let (nth 1 series) '(org-finalize-agenda)))
  2513. ;;;###autoload
  2514. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2515. "Run an agenda command in batch mode and send the result to STDOUT.
  2516. If CMD-KEY is a string of length 1, it is used as a key in
  2517. `org-agenda-custom-commands' and triggers this command. If it is a
  2518. longer string it is used as a tags/todo match string.
  2519. Parameters are alternating variable names and values that will be bound
  2520. before running the agenda command."
  2521. (org-eval-in-environment (org-make-parameter-alist parameters)
  2522. (if (> (length cmd-key) 2)
  2523. (org-tags-view nil cmd-key)
  2524. (org-agenda nil cmd-key)))
  2525. (set-buffer org-agenda-buffer-name)
  2526. (princ (buffer-string)))
  2527. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2528. (defvar org-agenda-info nil)
  2529. ;;;###autoload
  2530. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2531. "Run an agenda command in batch mode and send the result to STDOUT.
  2532. If CMD-KEY is a string of length 1, it is used as a key in
  2533. `org-agenda-custom-commands' and triggers this command. If it is a
  2534. longer string it is used as a tags/todo match string.
  2535. Parameters are alternating variable names and values that will be bound
  2536. before running the agenda command.
  2537. The output gives a line for each selected agenda item. Each
  2538. item is a list of comma-separated values, like this:
  2539. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2540. category The category of the item
  2541. head The headline, without TODO kwd, TAGS and PRIORITY
  2542. type The type of the agenda entry, can be
  2543. todo selected in TODO match
  2544. tagsmatch selected in tags match
  2545. diary imported from diary
  2546. deadline a deadline on given date
  2547. scheduled scheduled on given date
  2548. timestamp entry has timestamp on given date
  2549. closed entry was closed on given date
  2550. upcoming-deadline warning about deadline
  2551. past-scheduled forwarded scheduled item
  2552. block entry has date block including g. date
  2553. todo The todo keyword, if any
  2554. tags All tags including inherited ones, separated by colons
  2555. date The relevant date, like 2007-2-14
  2556. time The time, like 15:00-16:50
  2557. extra Sting with extra planning info
  2558. priority-l The priority letter if any was given
  2559. priority-n The computed numerical priority
  2560. agenda-day The day in the agenda where this is listed"
  2561. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2562. (org-make-parameter-alist parameters))
  2563. (if (> (length cmd-key) 2)
  2564. (org-tags-view nil cmd-key)
  2565. (org-agenda nil cmd-key)))
  2566. (set-buffer org-agenda-buffer-name)
  2567. (let* ((lines (org-split-string (buffer-string) "\n"))
  2568. line)
  2569. (while (setq line (pop lines))
  2570. (catch 'next
  2571. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2572. (setq org-agenda-info
  2573. (org-fix-agenda-info (text-properties-at 0 line)))
  2574. (princ
  2575. (mapconcat 'org-agenda-export-csv-mapper
  2576. '(org-category txt type todo tags date time extra
  2577. priority-letter priority agenda-day)
  2578. ","))
  2579. (princ "\n")))))
  2580. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2581. (defun org-fix-agenda-info (props)
  2582. "Make sure all properties on an agenda item have a canonical form.
  2583. This ensures the export commands can easily use it."
  2584. (let (tmp re)
  2585. (when (setq tmp (plist-get props 'tags))
  2586. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2587. (when (setq tmp (plist-get props 'date))
  2588. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2589. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2590. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2591. (setq tmp (calendar-date-string tmp)))
  2592. (setq props (plist-put props 'date tmp)))
  2593. (when (setq tmp (plist-get props 'day))
  2594. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2595. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2596. (setq tmp (calendar-date-string tmp)))
  2597. (setq props (plist-put props 'day tmp))
  2598. (setq props (plist-put props 'agenda-day tmp)))
  2599. (when (setq tmp (plist-get props 'txt))
  2600. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2601. (plist-put props 'priority-letter (match-string 1 tmp))
  2602. (setq tmp (replace-match "" t t tmp)))
  2603. (when (and (setq re (plist-get props 'org-todo-regexp))
  2604. (setq re (concat "\\`\\.*" re " ?"))
  2605. (string-match re tmp))
  2606. (plist-put props 'todo (match-string 1 tmp))
  2607. (setq tmp (replace-match "" t t tmp)))
  2608. (plist-put props 'txt tmp)))
  2609. props)
  2610. (defun org-agenda-export-csv-mapper (prop)
  2611. (let ((res (plist-get org-agenda-info prop)))
  2612. (setq res
  2613. (cond
  2614. ((not res) "")
  2615. ((stringp res) res)
  2616. (t (prin1-to-string res))))
  2617. (while (string-match "," res)
  2618. (setq res (replace-match ";" t t res)))
  2619. (org-trim res)))
  2620. ;;;###autoload
  2621. (defun org-store-agenda-views (&rest parameters)
  2622. (interactive)
  2623. (eval (list 'org-batch-store-agenda-views)))
  2624. ;;;###autoload
  2625. (defmacro org-batch-store-agenda-views (&rest parameters)
  2626. "Run all custom agenda commands that have a file argument."
  2627. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2628. (pop-up-frames nil)
  2629. (dir default-directory)
  2630. (pars (org-make-parameter-alist parameters))
  2631. cmd thiscmdkey files opts cmd-or-set)
  2632. (save-window-excursion
  2633. (while cmds
  2634. (setq cmd (pop cmds)
  2635. thiscmdkey (car cmd)
  2636. cmd-or-set (nth 2 cmd)
  2637. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2638. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2639. (if (stringp files) (setq files (list files)))
  2640. (when files
  2641. (org-eval-in-environment (append org-agenda-exporter-settings
  2642. opts pars)
  2643. (org-agenda nil thiscmdkey))
  2644. (set-buffer org-agenda-buffer-name)
  2645. (while files
  2646. (org-eval-in-environment (append org-agenda-exporter-settings
  2647. opts pars)
  2648. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2649. (and (get-buffer org-agenda-buffer-name)
  2650. (kill-buffer org-agenda-buffer-name)))))))
  2651. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2652. (defun org-agenda-mark-header-line (pos)
  2653. "Mark the line at POS as an agenda structure header."
  2654. (save-excursion
  2655. (goto-char pos)
  2656. (put-text-property (point-at-bol) (point-at-eol)
  2657. 'org-agenda-structural-header t)
  2658. (when org-agenda-title-append
  2659. (put-text-property (point-at-bol) (point-at-eol)
  2660. 'org-agenda-title-append org-agenda-title-append))))
  2661. (defvar org-mobile-creating-agendas)
  2662. (defvar org-agenda-write-buffer-name "Agenda View")
  2663. (defun org-agenda-write (file &optional open nosettings)
  2664. "Write the current buffer (an agenda view) as a file.
  2665. Depending on the extension of the file name, plain text (.txt),
  2666. HTML (.html or .htm) or Postscript (.ps) is produced.
  2667. If the extension is .ics, run icalendar export over all files used
  2668. to construct the agenda and limit the export to entries listed in the
  2669. agenda now.
  2670. With prefix argument OPEN, open the new file immediately.
  2671. If NOSETTINGS is given, do not scope the settings of
  2672. `org-agenda-exporter-settings' into the export commands. This is used when
  2673. the settings have already been scoped and we do not wish to overrule other,
  2674. higher priority settings."
  2675. (interactive "FWrite agenda to file: \nP")
  2676. (if (not (file-writable-p file))
  2677. (error "Cannot write agenda to file %s" file))
  2678. (org-let (if nosettings nil org-agenda-exporter-settings)
  2679. '(save-excursion
  2680. (save-window-excursion
  2681. (org-agenda-mark-filtered-text)
  2682. (let ((bs (copy-sequence (buffer-string))) beg)
  2683. (org-agenda-unmark-filtered-text)
  2684. (with-temp-buffer
  2685. (rename-buffer org-agenda-write-buffer-name t)
  2686. (set-buffer-modified-p nil)
  2687. (insert bs)
  2688. (org-agenda-remove-marked-text 'org-filtered)
  2689. (while (setq beg (text-property-any (point-min) (point-max)
  2690. 'org-filtered t))
  2691. (delete-region
  2692. beg (or (next-single-property-change beg 'org-filtered)
  2693. (point-max))))
  2694. (run-hooks 'org-agenda-before-write-hook)
  2695. (cond
  2696. ((org-bound-and-true-p org-mobile-creating-agendas)
  2697. (org-mobile-write-agenda-for-mobile file))
  2698. ((string-match "\\.html?\\'" file)
  2699. (require 'htmlize)
  2700. (set-buffer (htmlize-buffer (current-buffer)))
  2701. (when (and org-agenda-export-html-style
  2702. (string-match "<style>" org-agenda-export-html-style))
  2703. ;; replace <style> section with org-agenda-export-html-style
  2704. (goto-char (point-min))
  2705. (kill-region (- (search-forward "<style") 6)
  2706. (search-forward "</style>"))
  2707. (insert org-agenda-export-html-style))
  2708. (write-file file)
  2709. (kill-buffer (current-buffer))
  2710. (message "HTML written to %s" file))
  2711. ((string-match "\\.ps\\'" file)
  2712. (require 'ps-print)
  2713. (ps-print-buffer-with-faces file)
  2714. (message "Postscript written to %s" file))
  2715. ((string-match "\\.pdf\\'" file)
  2716. (require 'ps-print)
  2717. (ps-print-buffer-with-faces
  2718. (concat (file-name-sans-extension file) ".ps"))
  2719. (call-process "ps2pdf" nil nil nil
  2720. (expand-file-name
  2721. (concat (file-name-sans-extension file) ".ps"))
  2722. (expand-file-name file))
  2723. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2724. (message "PDF written to %s" file))
  2725. ((string-match "\\.ics\\'" file)
  2726. (require 'org-icalendar)
  2727. (let ((org-agenda-marker-table
  2728. (org-create-marker-find-array
  2729. (org-agenda-collect-markers)))
  2730. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2731. (org-combined-agenda-icalendar-file file))
  2732. (apply 'org-export-icalendar 'combine
  2733. (org-agenda-files nil 'ifmode))))
  2734. (t
  2735. (let ((bs (buffer-string)))
  2736. (find-file file)
  2737. (erase-buffer)
  2738. (insert bs)
  2739. (save-buffer 0)
  2740. (kill-buffer (current-buffer))
  2741. (message "Plain text written to %s" file))))))))
  2742. (set-buffer org-agenda-buffer-name))
  2743. (when open (org-open-file file)))
  2744. (defvar org-agenda-tag-filter-overlays nil)
  2745. (defvar org-agenda-cat-filter-overlays nil)
  2746. (defun org-agenda-mark-filtered-text ()
  2747. "Mark all text hidden by filtering with a text property."
  2748. (let ((inhibit-read-only t))
  2749. (mapc
  2750. (lambda (o)
  2751. (when (equal (overlay-buffer o) (current-buffer))
  2752. (put-text-property
  2753. (overlay-start o) (overlay-end o)
  2754. 'org-filtered t)))
  2755. (append org-agenda-tag-filter-overlays
  2756. org-agenda-cat-filter-overlays))))
  2757. (defun org-agenda-unmark-filtered-text ()
  2758. "Remove the filtering text property."
  2759. (let ((inhibit-read-only t))
  2760. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2761. (defun org-agenda-remove-marked-text (property &optional value)
  2762. "Delete all text marked with VALUE of PROPERTY.
  2763. VALUE defaults to t."
  2764. (let (beg)
  2765. (setq value (or value t))
  2766. (while (setq beg (text-property-any (point-min) (point-max)
  2767. property value))
  2768. (delete-region
  2769. beg (or (next-single-property-change beg 'org-filtered)
  2770. (point-max))))))
  2771. (defun org-agenda-add-entry-text ()
  2772. "Add entry text to agenda lines.
  2773. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2774. entry text following headings shown in the agenda.
  2775. Drawers will be excluded, also the line with scheduling/deadline info."
  2776. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2777. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2778. (let (m txt)
  2779. (goto-char (point-min))
  2780. (while (not (eobp))
  2781. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2782. (beginning-of-line 2)
  2783. (setq txt (org-agenda-get-some-entry-text
  2784. m org-agenda-add-entry-text-maxlines " > "))
  2785. (end-of-line 1)
  2786. (if (string-match "\\S-" txt)
  2787. (insert "\n" txt)
  2788. (or (eobp) (forward-char 1))))))))
  2789. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2790. &rest keep)
  2791. "Extract entry text from MARKER, at most N-LINES lines.
  2792. This will ignore drawers etc, just get the text.
  2793. If INDENT is given, prefix every line with this string. If KEEP is
  2794. given, it is a list of symbols, defining stuff that should not be
  2795. removed from the entry content. Currently only `planning' is allowed here."
  2796. (let (txt drawer-re kwd-time-re ind)
  2797. (save-excursion
  2798. (with-current-buffer (marker-buffer marker)
  2799. (if (not (derived-mode-p 'org-mode))
  2800. (setq txt "")
  2801. (save-excursion
  2802. (save-restriction
  2803. (widen)
  2804. (goto-char marker)
  2805. (end-of-line 1)
  2806. (setq txt (buffer-substring
  2807. (min (1+ (point)) (point-max))
  2808. (progn (outline-next-heading) (point)))
  2809. drawer-re org-drawer-regexp
  2810. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2811. ".*\n?"))
  2812. (with-temp-buffer
  2813. (insert txt)
  2814. (when org-agenda-add-entry-text-descriptive-links
  2815. (goto-char (point-min))
  2816. (while (org-activate-bracket-links (point-max))
  2817. (add-text-properties (match-beginning 0) (match-end 0)
  2818. '(face org-link))))
  2819. (goto-char (point-min))
  2820. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2821. (set-text-properties (match-beginning 0) (match-end 0)
  2822. nil))
  2823. (goto-char (point-min))
  2824. (while (re-search-forward drawer-re nil t)
  2825. (delete-region
  2826. (match-beginning 0)
  2827. (progn (re-search-forward
  2828. "^[ \t]*:END:.*\n?" nil 'move)
  2829. (point))))
  2830. (unless (member 'planning keep)
  2831. (goto-char (point-min))
  2832. (while (re-search-forward kwd-time-re nil t)
  2833. (replace-match "")))
  2834. (goto-char (point-min))
  2835. (when org-agenda-entry-text-exclude-regexps
  2836. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2837. (while (setq re (pop re-list))
  2838. (goto-char (point-min))
  2839. (while (re-search-forward re nil t)
  2840. (replace-match "")))))
  2841. (goto-char (point-max))
  2842. (skip-chars-backward " \t\n")
  2843. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2844. ;; find and remove min common indentation
  2845. (goto-char (point-min))
  2846. (untabify (point-min) (point-max))
  2847. (setq ind (org-get-indentation))
  2848. (while (not (eobp))
  2849. (unless (looking-at "[ \t]*$")
  2850. (setq ind (min ind (org-get-indentation))))
  2851. (beginning-of-line 2))
  2852. (goto-char (point-min))
  2853. (while (not (eobp))
  2854. (unless (looking-at "[ \t]*$")
  2855. (move-to-column ind)
  2856. (delete-region (point-at-bol) (point)))
  2857. (beginning-of-line 2))
  2858. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2859. (goto-char (point-min))
  2860. (when indent
  2861. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2862. (replace-match indent t t)))
  2863. (goto-char (point-min))
  2864. (while (looking-at "[ \t]*\n") (replace-match ""))
  2865. (goto-char (point-max))
  2866. (when (> (org-current-line)
  2867. n-lines)
  2868. (org-goto-line (1+ n-lines))
  2869. (backward-char 1))
  2870. (setq txt (buffer-substring (point-min) (point)))))))))
  2871. txt))
  2872. (defun org-agenda-collect-markers ()
  2873. "Collect the markers pointing to entries in the agenda buffer."
  2874. (let (m markers)
  2875. (save-excursion
  2876. (goto-char (point-min))
  2877. (while (not (eobp))
  2878. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2879. (org-get-at-bol 'org-marker)))
  2880. (push m markers))
  2881. (beginning-of-line 2)))
  2882. (nreverse markers)))
  2883. (defun org-create-marker-find-array (marker-list)
  2884. "Create a alist of files names with all marker positions in that file."
  2885. (let (f tbl m a p)
  2886. (while (setq m (pop marker-list))
  2887. (setq p (marker-position m)
  2888. f (buffer-file-name (or (buffer-base-buffer
  2889. (marker-buffer m))
  2890. (marker-buffer m))))
  2891. (if (setq a (assoc f tbl))
  2892. (push (marker-position m) (cdr a))
  2893. (push (list f p) tbl)))
  2894. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2895. tbl)))
  2896. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2897. (defun org-check-agenda-marker-table ()
  2898. "Check of the current entry is on the marker list."
  2899. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2900. a)
  2901. (and (setq a (assoc file org-agenda-marker-table))
  2902. (save-match-data
  2903. (save-excursion
  2904. (org-back-to-heading t)
  2905. (member (point) (cdr a)))))))
  2906. (defun org-check-for-org-mode ()
  2907. "Make sure current buffer is in org-mode. Error if not."
  2908. (or (derived-mode-p 'org-mode)
  2909. (error "Cannot execute org-mode agenda command on buffer in %s"
  2910. major-mode)))
  2911. (defun org-fit-agenda-window ()
  2912. "Fit the window to the buffer size."
  2913. (and (memq org-agenda-window-setup '(reorganize-frame))
  2914. (fboundp 'fit-window-to-buffer)
  2915. (org-fit-window-to-buffer
  2916. nil
  2917. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2918. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2919. ;;; Agenda prepare and finalize
  2920. (defvar org-agenda-multi nil) ; dynamically scoped
  2921. (defvar org-agenda-buffer-name "*Org Agenda*")
  2922. (defvar org-pre-agenda-window-conf nil)
  2923. (defvar org-agenda-columns-active nil)
  2924. (defvar org-agenda-name nil)
  2925. (defvar org-agenda-tag-filter nil)
  2926. (defvar org-agenda-category-filter nil)
  2927. (defvar org-agenda-top-category-filter nil)
  2928. (defvar org-agenda-tag-filter-while-redo nil)
  2929. (defvar org-agenda-tag-filter-preset nil
  2930. "A preset of the tags filter used for secondary agenda filtering.
  2931. This must be a list of strings, each string must be a single tag preceded
  2932. by \"+\" or \"-\".
  2933. This variable should not be set directly, but agenda custom commands can
  2934. bind it in the options section. The preset filter is a global property of
  2935. the entire agenda view. In a block agenda, it will not work reliably to
  2936. define a filter for one of the individual blocks. You need to set it in
  2937. the global options and expect it to be applied to the entire view.")
  2938. (defvar org-agenda-category-filter-preset nil
  2939. "A preset of the category filter used for secondary agenda filtering.
  2940. This must be a list of strings, each string must be a single category
  2941. preceded by \"+\" or \"-\".
  2942. This variable should not be set directly, but agenda custom commands can
  2943. bind it in the options section. The preset filter is a global property of
  2944. the entire agenda view. In a block agenda, it will not work reliably to
  2945. define a filter for one of the individual blocks. You need to set it in
  2946. the global options and expect it to be applied to the entire view.")
  2947. (defun org-agenda-use-sticky-p ()
  2948. "Return non-nil if an agenda buffer named
  2949. `org-agenda-buffer-name' exists and should be shown instead of
  2950. generating a new one."
  2951. (and
  2952. ;; turned off by user
  2953. org-agenda-sticky
  2954. ;; For multi-agenda buffer already exists
  2955. (not org-agenda-multi)
  2956. ;; buffer found
  2957. (get-buffer org-agenda-buffer-name)
  2958. ;; C-u parameter is same as last call
  2959. (with-current-buffer (get-buffer org-agenda-buffer-name)
  2960. (and
  2961. (equal current-prefix-arg
  2962. org-agenda-last-prefix-arg)
  2963. ;; In case user turned stickiness on, while having existing
  2964. ;; Agenda buffer active, don't reuse that buffer, because it
  2965. ;; does not have org variables local
  2966. org-agenda-this-buffer-is-sticky))))
  2967. (defun org-prepare-agenda-window (abuf)
  2968. "Setup agenda buffer in the window."
  2969. (let* ((awin (get-buffer-window abuf))
  2970. wconf)
  2971. (cond
  2972. ((equal (current-buffer) abuf) nil)
  2973. (awin (select-window awin))
  2974. ((not (setq wconf (current-window-configuration))))
  2975. ((equal org-agenda-window-setup 'current-window)
  2976. (org-pop-to-buffer-same-window abuf))
  2977. ((equal org-agenda-window-setup 'other-window)
  2978. (org-switch-to-buffer-other-window abuf))
  2979. ((equal org-agenda-window-setup 'other-frame)
  2980. (switch-to-buffer-other-frame abuf))
  2981. ((equal org-agenda-window-setup 'reorganize-frame)
  2982. (delete-other-windows)
  2983. (org-switch-to-buffer-other-window abuf)))
  2984. ;; additional test in case agenda is invoked from within agenda
  2985. ;; buffer via elisp link
  2986. (unless (equal (current-buffer) abuf)
  2987. (org-pop-to-buffer-same-window abuf))
  2988. (setq org-pre-agenda-window-conf wconf)))
  2989. (defun org-prepare-agenda (&optional name)
  2990. (if (org-agenda-use-sticky-p)
  2991. (progn
  2992. ;; Popup existing buffer
  2993. (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
  2994. (message "Sticky Agenda buffer, use `r' to refresh")
  2995. (throw 'exit nil))
  2996. (setq org-todo-keywords-for-agenda nil)
  2997. (setq org-drawers-for-agenda nil)
  2998. (unless org-agenda-persistent-filter
  2999. (setq org-agenda-tag-filter nil
  3000. org-agenda-category-filter nil))
  3001. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  3002. (put 'org-agenda-category-filter :preset-filter
  3003. org-agenda-category-filter-preset)
  3004. (if org-agenda-multi
  3005. (progn
  3006. (setq buffer-read-only nil)
  3007. (goto-char (point-max))
  3008. (unless (or (bobp) org-agenda-compact-blocks
  3009. (not org-agenda-block-separator))
  3010. (insert "\n"
  3011. (if (stringp org-agenda-block-separator)
  3012. org-agenda-block-separator
  3013. (make-string (window-width) org-agenda-block-separator))
  3014. "\n"))
  3015. (narrow-to-region (point) (point-max)))
  3016. (setq org-done-keywords-for-agenda nil)
  3017. ;; Setting any org variables that are in org-agenda-local-vars
  3018. ;; list need to be done after the prepare call
  3019. (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
  3020. (setq buffer-read-only nil)
  3021. (org-agenda-reset-markers)
  3022. (let ((inhibit-read-only t)) (erase-buffer))
  3023. (org-agenda-mode)
  3024. (setq org-agenda-buffer (current-buffer))
  3025. (setq org-agenda-contributing-files nil)
  3026. (setq org-agenda-columns-active nil)
  3027. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  3028. (setq org-todo-keywords-for-agenda
  3029. (org-uniquify org-todo-keywords-for-agenda))
  3030. (setq org-done-keywords-for-agenda
  3031. (org-uniquify org-done-keywords-for-agenda))
  3032. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3033. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3034. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3035. (and name (not org-agenda-name)
  3036. (org-set-local 'org-agenda-name name)))
  3037. (setq buffer-read-only nil)))
  3038. (defun org-finalize-agenda ()
  3039. "Finishing touch for the agenda buffer, called just before displaying it."
  3040. (unless org-agenda-multi
  3041. (save-excursion
  3042. (let ((inhibit-read-only t))
  3043. (goto-char (point-min))
  3044. (while (org-activate-bracket-links (point-max))
  3045. (add-text-properties (match-beginning 0) (match-end 0)
  3046. '(face org-link)))
  3047. (org-agenda-align-tags)
  3048. (unless org-agenda-with-colors
  3049. (remove-text-properties (point-min) (point-max) '(face nil))))
  3050. (if (and (boundp 'org-agenda-overriding-columns-format)
  3051. org-agenda-overriding-columns-format)
  3052. (org-set-local 'org-agenda-overriding-columns-format
  3053. org-agenda-overriding-columns-format))
  3054. (if (and (boundp 'org-agenda-view-columns-initially)
  3055. org-agenda-view-columns-initially)
  3056. (org-agenda-columns))
  3057. (when org-agenda-fontify-priorities
  3058. (org-agenda-fontify-priorities))
  3059. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3060. (org-agenda-dim-blocked-tasks))
  3061. (org-agenda-mark-clocking-task)
  3062. (when org-agenda-entry-text-mode
  3063. (org-agenda-entry-text-hide)
  3064. (org-agenda-entry-text-show))
  3065. (if (functionp 'org-habit-insert-consistency-graphs)
  3066. (org-habit-insert-consistency-graphs))
  3067. (run-hooks 'org-finalize-agenda-hook)
  3068. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3069. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3070. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3071. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3072. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3073. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3074. )))
  3075. (defun org-agenda-mark-clocking-task ()
  3076. "Mark the current clock entry in the agenda if it is present."
  3077. (mapc (lambda (o)
  3078. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3079. (delete-overlay o)))
  3080. (overlays-in (point-min) (point-max)))
  3081. (when (marker-buffer org-clock-hd-marker)
  3082. (save-excursion
  3083. (goto-char (point-min))
  3084. (let (s ov)
  3085. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3086. (goto-char s)
  3087. (when (equal (org-get-at-bol 'org-hd-marker)
  3088. org-clock-hd-marker)
  3089. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3090. (overlay-put ov 'type 'org-agenda-clocking)
  3091. (overlay-put ov 'face 'org-agenda-clocking)
  3092. (overlay-put ov 'help-echo
  3093. "The clock is running in this item")))))))
  3094. (defun org-agenda-fontify-priorities ()
  3095. "Make highest priority lines bold, and lowest italic."
  3096. (interactive)
  3097. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3098. (delete-overlay o)))
  3099. (overlays-in (point-min) (point-max)))
  3100. (save-excursion
  3101. (let ((inhibit-read-only t)
  3102. b e p ov h l)
  3103. (goto-char (point-min))
  3104. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3105. (setq h (or (get-char-property (point) 'org-highest-priority)
  3106. org-highest-priority)
  3107. l (or (get-char-property (point) 'org-lowest-priority)
  3108. org-lowest-priority)
  3109. p (string-to-char (match-string 1))
  3110. b (match-beginning 0)
  3111. e (if (eq org-agenda-fontify-priorities 'cookies)
  3112. (match-end 0)
  3113. (point-at-eol))
  3114. ov (make-overlay b e))
  3115. (overlay-put
  3116. ov 'face
  3117. (cond ((org-face-from-face-or-color
  3118. 'priority nil
  3119. (cdr (assoc p org-priority-faces))))
  3120. ((and (listp org-agenda-fontify-priorities)
  3121. (org-face-from-face-or-color
  3122. 'priority nil
  3123. (cdr (assoc p org-agenda-fontify-priorities)))))
  3124. ((equal p l) 'italic)
  3125. ((equal p h) 'bold)))
  3126. (overlay-put ov 'org-type 'org-priority)))))
  3127. (defun org-agenda-dim-blocked-tasks ()
  3128. "Dim currently blocked TODO's in the agenda display."
  3129. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3130. (delete-overlay o)))
  3131. (overlays-in (point-min) (point-max)))
  3132. (save-excursion
  3133. (let ((inhibit-read-only t)
  3134. (org-depend-tag-blocked nil)
  3135. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3136. org-blocked-by-checkboxes
  3137. invis1 b e p ov h l)
  3138. (goto-char (point-min))
  3139. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3140. (and pos (goto-char (1+ pos))))
  3141. (setq org-blocked-by-checkboxes nil invis1 invis)
  3142. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3143. (when (and marker
  3144. (with-current-buffer (marker-buffer marker)
  3145. (save-excursion (goto-char marker)
  3146. (org-entry-blocked-p))))
  3147. (if org-blocked-by-checkboxes (setq invis1 nil))
  3148. (setq b (if invis1
  3149. (max (point-min) (1- (point-at-bol)))
  3150. (point-at-bol))
  3151. e (point-at-eol)
  3152. ov (make-overlay b e))
  3153. (if invis1
  3154. (overlay-put ov 'invisible t)
  3155. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3156. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3157. (defvar org-agenda-skip-function nil
  3158. "Function to be called at each match during agenda construction.
  3159. If this function returns nil, the current match should not be skipped.
  3160. Otherwise, the function must return a position from where the search
  3161. should be continued.
  3162. This may also be a Lisp form, it will be evaluated.
  3163. Never set this variable using `setq' or so, because then it will apply
  3164. to all future agenda commands. If you do want a global skipping condition,
  3165. use the option `org-agenda-skip-function-global' instead.
  3166. The correct usage for `org-agenda-skip-function' is to bind it with
  3167. `let' to scope it dynamically into the agenda-constructing command.
  3168. A good way to set it is through options in `org-agenda-custom-commands'.")
  3169. (defun org-agenda-skip ()
  3170. "Throw to `:skip' in places that should be skipped.
  3171. Also moves point to the end of the skipped region, so that search can
  3172. continue from there."
  3173. (let ((p (point-at-bol)) to)
  3174. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3175. (get-text-property p :org-archived)
  3176. (org-end-of-subtree t)
  3177. (throw :skip t))
  3178. (and org-agenda-skip-comment-trees
  3179. (get-text-property p :org-comment)
  3180. (org-end-of-subtree t)
  3181. (throw :skip t))
  3182. (if (equal (char-after p) ?#) (throw :skip t))
  3183. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3184. (org-agenda-skip-eval org-agenda-skip-function)))
  3185. (goto-char to)
  3186. (throw :skip t))))
  3187. (defun org-agenda-skip-eval (form)
  3188. "If FORM is a function or a list, call (or eval) is and return result.
  3189. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3190. and match data are returned to the previous state no matter what these
  3191. functions do."
  3192. (let (fp)
  3193. (and form
  3194. (or (setq fp (functionp form))
  3195. (consp form))
  3196. (save-excursion
  3197. (save-match-data
  3198. (if fp
  3199. (funcall form)
  3200. (eval form)))))))
  3201. (defvar org-agenda-markers nil
  3202. "List of all currently active markers created by `org-agenda'.")
  3203. (defvar org-agenda-last-marker-time (org-float-time)
  3204. "Creation time of the last agenda marker.")
  3205. (defun org-agenda-new-marker (&optional pos)
  3206. "Return a new agenda marker.
  3207. Org-mode keeps a list of these markers and resets them when they are
  3208. no longer in use."
  3209. (let ((m (copy-marker (or pos (point)))))
  3210. (setq org-agenda-last-marker-time (org-float-time))
  3211. (if org-agenda-buffer
  3212. (with-current-buffer org-agenda-buffer
  3213. (push m org-agenda-markers))
  3214. (push m org-agenda-markers))
  3215. m))
  3216. (defun org-agenda-reset-markers ()
  3217. "Reset markers created by `org-agenda'."
  3218. (while org-agenda-markers
  3219. (move-marker (pop org-agenda-markers) nil)))
  3220. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3221. "Save relative positions of markers in region.
  3222. This check for agenda markers in all agenda buffers currently active."
  3223. (dolist (buf (buffer-list))
  3224. (with-current-buffer buf
  3225. (when (eq major-mode 'org-agenda-mode)
  3226. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3227. org-agenda-markers)))))
  3228. ;;; Entry text mode
  3229. (defun org-agenda-entry-text-show-here ()
  3230. "Add some text from the entry as context to the current line."
  3231. (let (m txt o)
  3232. (setq m (org-get-at-bol 'org-hd-marker))
  3233. (unless (marker-buffer m)
  3234. (error "No marker points to an entry here"))
  3235. (setq txt (concat "\n" (org-no-properties
  3236. (org-agenda-get-some-entry-text
  3237. m org-agenda-entry-text-maxlines " > "))))
  3238. (when (string-match "\\S-" txt)
  3239. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3240. (overlay-put o 'evaporate t)
  3241. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3242. (overlay-put o 'after-string txt))))
  3243. (defun org-agenda-entry-text-show ()
  3244. "Add entry context for all agenda lines."
  3245. (interactive)
  3246. (save-excursion
  3247. (goto-char (point-max))
  3248. (beginning-of-line 1)
  3249. (while (not (bobp))
  3250. (when (org-get-at-bol 'org-hd-marker)
  3251. (org-agenda-entry-text-show-here))
  3252. (beginning-of-line 0))))
  3253. (defun org-agenda-entry-text-hide ()
  3254. "Remove any shown entry context."
  3255. (delq nil
  3256. (mapcar (lambda (o)
  3257. (if (eq (overlay-get o 'org-overlay-type)
  3258. 'agenda-entry-content)
  3259. (progn (delete-overlay o) t)))
  3260. (overlays-in (point-min) (point-max)))))
  3261. (defun org-agenda-get-day-face (date)
  3262. "Return the face DATE should be displayed with."
  3263. (or (and (functionp org-agenda-day-face-function)
  3264. (funcall org-agenda-day-face-function date))
  3265. (cond ((org-agenda-todayp date)
  3266. 'org-agenda-date-today)
  3267. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3268. 'org-agenda-date-weekend)
  3269. (t 'org-agenda-date))))
  3270. ;;; Agenda timeline
  3271. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3272. (defun org-timeline (&optional dotodo)
  3273. "Show a time-sorted view of the entries in the current org file.
  3274. Only entries with a time stamp of today or later will be listed. With
  3275. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3276. under the current date.
  3277. If the buffer contains an active region, only check the region for
  3278. dates."
  3279. (interactive "P")
  3280. (let* ((dopast t)
  3281. (org-agenda-show-log-scoped org-agenda-show-log)
  3282. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3283. (current-buffer))))
  3284. (date (calendar-current-date))
  3285. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3286. (end (if (org-region-active-p) (region-end) (point-max)))
  3287. (day-numbers (org-get-all-dates
  3288. beg end 'no-ranges
  3289. t org-agenda-show-log-scoped ; always include today
  3290. org-timeline-show-empty-dates))
  3291. (org-deadline-warning-days 0)
  3292. (org-agenda-only-exact-dates t)
  3293. (today (org-today))
  3294. (past t)
  3295. args
  3296. s e rtn d emptyp)
  3297. (setq org-agenda-redo-command
  3298. (list 'progn
  3299. (list 'org-switch-to-buffer-other-window (current-buffer))
  3300. (list 'org-timeline (list 'quote dotodo))))
  3301. (if (not dopast)
  3302. ;; Remove past dates from the list of dates.
  3303. (setq day-numbers (delq nil (mapcar (lambda(x)
  3304. (if (>= x today) x nil))
  3305. day-numbers))))
  3306. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3307. (org-compile-prefix-format 'timeline)
  3308. (org-set-sorting-strategy 'timeline)
  3309. (if org-agenda-show-log-scoped (push :closed args))
  3310. (push :timestamp args)
  3311. (push :deadline args)
  3312. (push :scheduled args)
  3313. (push :sexp args)
  3314. (if dotodo (push :todo args))
  3315. (insert "Timeline of file " entry "\n")
  3316. (add-text-properties (point-min) (point)
  3317. (list 'face 'org-agenda-structure))
  3318. (org-agenda-mark-header-line (point-min))
  3319. (while (setq d (pop day-numbers))
  3320. (if (and (listp d) (eq (car d) :omitted))
  3321. (progn
  3322. (setq s (point))
  3323. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3324. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3325. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3326. (if (and (>= d today)
  3327. dopast
  3328. past)
  3329. (progn
  3330. (setq past nil)
  3331. (insert (make-string 79 ?-) "\n")))
  3332. (setq date (calendar-gregorian-from-absolute d))
  3333. (setq s (point))
  3334. (setq rtn (and (not emptyp)
  3335. (apply 'org-agenda-get-day-entries entry
  3336. date args)))
  3337. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3338. (progn
  3339. (insert
  3340. (if (stringp org-agenda-format-date)
  3341. (format-time-string org-agenda-format-date
  3342. (org-time-from-absolute date))
  3343. (funcall org-agenda-format-date date))
  3344. "\n")
  3345. (put-text-property s (1- (point)) 'face
  3346. (org-agenda-get-day-face date))
  3347. (put-text-property s (1- (point)) 'org-date-line t)
  3348. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3349. (if (equal d today)
  3350. (put-text-property s (1- (point)) 'org-today t))
  3351. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3352. (put-text-property s (1- (point)) 'day d)))))
  3353. (goto-char (point-min))
  3354. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3355. (point-min)))
  3356. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3357. (org-finalize-agenda)
  3358. (setq buffer-read-only t)))
  3359. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3360. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3361. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3362. not every single day in the range. If FORCE-TODAY is non-nil, make
  3363. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3364. inactive time stamps (those in square brackets) are included.
  3365. When EMPTY is non-nil, also include days without any entries."
  3366. (let ((re (concat
  3367. (if pre-re pre-re "")
  3368. (if inactive org-ts-regexp-both org-ts-regexp)))
  3369. dates dates1 date day day1 day2 ts1 ts2 pos)
  3370. (if force-today
  3371. (setq dates (list (org-today))))
  3372. (save-excursion
  3373. (goto-char beg)
  3374. (while (re-search-forward re end t)
  3375. (setq day (time-to-days (org-time-string-to-time
  3376. (substring (match-string 1) 0 10)
  3377. (current-buffer) (match-beginning 0))))
  3378. (or (memq day dates) (push day dates)))
  3379. (unless no-ranges
  3380. (goto-char beg)
  3381. (while (re-search-forward org-tr-regexp end t)
  3382. (setq pos (match-beginning 0))
  3383. (setq ts1 (substring (match-string 1) 0 10)
  3384. ts2 (substring (match-string 2) 0 10)
  3385. day1 (time-to-days (org-time-string-to-time
  3386. ts1 (current-buffer) pos))
  3387. day2 (time-to-days (org-time-string-to-time
  3388. ts2 (current-buffer) pos)))
  3389. (while (< (setq day1 (1+ day1)) day2)
  3390. (or (memq day1 dates) (push day1 dates)))))
  3391. (setq dates (sort dates '<))
  3392. (when empty
  3393. (while (setq day (pop dates))
  3394. (setq day2 (car dates))
  3395. (push day dates1)
  3396. (when (and day2 empty)
  3397. (if (or (eq empty t)
  3398. (and (numberp empty) (<= (- day2 day) empty)))
  3399. (while (< (setq day (1+ day)) day2)
  3400. (push (list day) dates1))
  3401. (push (cons :omitted (- day2 day)) dates1))))
  3402. (setq dates (nreverse dates1)))
  3403. dates)))
  3404. ;;; Agenda Daily/Weekly
  3405. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3406. "Start day for the agenda view.
  3407. Custom commands can set this variable in the options section.")
  3408. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3409. (defvar org-agenda-current-span nil
  3410. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3411. (defvar org-arg-loc nil) ; local variable
  3412. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3413. "List of types searched for when creating the daily/weekly agenda.
  3414. This variable is a list of symbols that controls the types of
  3415. items that appear in the daily/weekly agenda. Allowed symbols in this
  3416. list are are
  3417. :timestamp List items containing a date stamp or date range matching
  3418. the selected date. This includes sexp entries in
  3419. angular brackets.
  3420. :sexp List entries resulting from plain diary-like sexps.
  3421. :deadline List deadline due on that date. When the date is today,
  3422. also list any deadlines past due, or due within
  3423. `org-deadline-warning-days'. `:deadline' must appear before
  3424. `:scheduled' if the setting of
  3425. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3426. any effect.
  3427. :scheduled List all items which are scheduled for the given date.
  3428. The diary for *today* also contains items which were
  3429. scheduled earlier and are not yet marked DONE.
  3430. By default, all four types are turned on.
  3431. Never set this variable globally using `setq', because then it
  3432. will apply to all future agenda commands. Instead, bind it with
  3433. `let' to scope it dynamically into the agenda-constructing
  3434. command. A good way to set it is through options in
  3435. `org-agenda-custom-commands'. For a more flexible (though
  3436. somewhat less efficient) way of determining what is included in
  3437. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3438. ;;;###autoload
  3439. (defun org-agenda-list (&optional arg start-day span)
  3440. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3441. The view will be for the current day or week, but from the overview buffer
  3442. you will be able to go to other days/weeks.
  3443. With a numeric prefix argument in an interactive call, the agenda will
  3444. span ARG days. Lisp programs should instead specify SPAN to change
  3445. the number of days. SPAN defaults to `org-agenda-span'.
  3446. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3447. given in `org-agenda-start-on-weekday'."
  3448. (interactive "P")
  3449. (if (and (integerp arg) (> arg 0))
  3450. (setq span arg arg nil))
  3451. (org-prepare-agenda "Day/Week")
  3452. (setq start-day (or start-day org-agenda-start-day))
  3453. (if org-agenda-overriding-arguments
  3454. (setq arg (car org-agenda-overriding-arguments)
  3455. start-day (nth 1 org-agenda-overriding-arguments)
  3456. span (nth 2 org-agenda-overriding-arguments)))
  3457. (if (stringp start-day)
  3458. ;; Convert to an absolute day number
  3459. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3460. (setq org-agenda-last-arguments (list arg start-day span))
  3461. (org-compile-prefix-format 'agenda)
  3462. (org-set-sorting-strategy 'agenda)
  3463. (let* ((span (org-agenda-ndays-to-span
  3464. (or span org-agenda-ndays org-agenda-span)))
  3465. (today (org-today))
  3466. (sd (or start-day today))
  3467. (ndays (org-agenda-span-to-ndays span sd))
  3468. (org-agenda-start-on-weekday
  3469. (if (eq ndays 7)
  3470. org-agenda-start-on-weekday))
  3471. (thefiles (org-agenda-files nil 'ifmode))
  3472. (files thefiles)
  3473. (start (if (or (null org-agenda-start-on-weekday)
  3474. (< ndays 7))
  3475. sd
  3476. (let* ((nt (calendar-day-of-week
  3477. (calendar-gregorian-from-absolute sd)))
  3478. (n1 org-agenda-start-on-weekday)
  3479. (d (- nt n1)))
  3480. (- sd (+ (if (< d 0) 7 0) d)))))
  3481. (day-numbers (list start))
  3482. (day-cnt 0)
  3483. (inhibit-redisplay (not debug-on-error))
  3484. (org-agenda-show-log-scoped org-agenda-show-log)
  3485. s e rtn rtnall file date d start-pos end-pos todayp
  3486. clocktable-start clocktable-end filter)
  3487. (setq org-agenda-redo-command
  3488. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3489. (dotimes (n (1- ndays))
  3490. (push (1+ (car day-numbers)) day-numbers))
  3491. (setq day-numbers (nreverse day-numbers))
  3492. (setq clocktable-start (car day-numbers)
  3493. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3494. (org-set-local 'org-starting-day (car day-numbers))
  3495. (org-set-local 'org-arg-loc arg)
  3496. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3497. (unless org-agenda-compact-blocks
  3498. (let* ((d1 (car day-numbers))
  3499. (d2 (org-last day-numbers))
  3500. (w1 (org-days-to-iso-week d1))
  3501. (w2 (org-days-to-iso-week d2)))
  3502. (setq s (point))
  3503. (if org-agenda-overriding-header
  3504. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3505. nil 'face 'org-agenda-structure) "\n")
  3506. (insert (org-agenda-span-name span)
  3507. "-agenda"
  3508. (if (< (- d2 d1) 350)
  3509. (if (= w1 w2)
  3510. (format " (W%02d)" w1)
  3511. (format " (W%02d-W%02d)" w1 w2))
  3512. "")
  3513. ":\n")))
  3514. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3515. 'org-date-line t))
  3516. (org-agenda-mark-header-line s))
  3517. (while (setq d (pop day-numbers))
  3518. (setq date (calendar-gregorian-from-absolute d)
  3519. s (point))
  3520. (if (or (setq todayp (= d today))
  3521. (and (not start-pos) (= d sd)))
  3522. (setq start-pos (point))
  3523. (if (and start-pos (not end-pos))
  3524. (setq end-pos (point))))
  3525. (setq files thefiles
  3526. rtnall nil)
  3527. (while (setq file (pop files))
  3528. (catch 'nextfile
  3529. (org-check-agenda-file file)
  3530. (let ((org-agenda-entry-types org-agenda-entry-types))
  3531. (unless org-agenda-include-deadlines
  3532. (setq org-agenda-entry-types
  3533. (delq :deadline org-agenda-entry-types)))
  3534. (cond
  3535. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3536. (setq rtn (org-agenda-get-day-entries
  3537. file date :closed)))
  3538. (org-agenda-show-log-scoped
  3539. (setq rtn (apply 'org-agenda-get-day-entries
  3540. file date
  3541. (append '(:closed) org-agenda-entry-types))))
  3542. (t
  3543. (setq rtn (apply 'org-agenda-get-day-entries
  3544. file date
  3545. org-agenda-entry-types)))))
  3546. (setq rtnall (append rtnall rtn)))) ;; all entries
  3547. (if org-agenda-include-diary
  3548. (let ((org-agenda-search-headline-for-time t))
  3549. (require 'diary-lib)
  3550. (setq rtn (org-get-entries-from-diary date))
  3551. (setq rtnall (append rtnall rtn))))
  3552. (if (or rtnall org-agenda-show-all-dates)
  3553. (progn
  3554. (setq day-cnt (1+ day-cnt))
  3555. (insert
  3556. (if (stringp org-agenda-format-date)
  3557. (format-time-string org-agenda-format-date
  3558. (org-time-from-absolute date))
  3559. (funcall org-agenda-format-date date))
  3560. "\n")
  3561. (put-text-property s (1- (point)) 'face
  3562. (org-agenda-get-day-face date))
  3563. (put-text-property s (1- (point)) 'org-date-line t)
  3564. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3565. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3566. (when todayp
  3567. (put-text-property s (1- (point)) 'org-today t))
  3568. (if rtnall (insert ;; all entries
  3569. (org-finalize-agenda-entries
  3570. (org-agenda-add-time-grid-maybe
  3571. rtnall ndays todayp))
  3572. "\n"))
  3573. (put-text-property s (1- (point)) 'day d)
  3574. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3575. (when (and org-agenda-clockreport-mode clocktable-start)
  3576. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3577. ;; the above line is to ensure the restricted range!
  3578. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3579. tbl)
  3580. (setq p (org-plist-delete p :block))
  3581. (setq p (plist-put p :tstart clocktable-start))
  3582. (setq p (plist-put p :tend clocktable-end))
  3583. (setq p (plist-put p :scope 'agenda))
  3584. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3585. (setq filter (or org-agenda-tag-filter-while-redo
  3586. (get 'org-agenda-tag-filter :preset-filter))))
  3587. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3588. (if (string-match "[<>=]" x)
  3589. ""
  3590. x))
  3591. filter ""))))
  3592. (setq tbl (apply 'org-get-clocktable p))
  3593. (insert tbl)))
  3594. (goto-char (point-min))
  3595. (or org-agenda-multi (org-fit-agenda-window))
  3596. (unless (and (pos-visible-in-window-p (point-min))
  3597. (pos-visible-in-window-p (point-max)))
  3598. (goto-char (1- (point-max)))
  3599. (recenter -1)
  3600. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3601. (progn
  3602. (goto-char (or start-pos 1))
  3603. (recenter 1))))
  3604. (goto-char (or start-pos 1))
  3605. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3606. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3607. (org-agenda-show-clocking-issues))
  3608. (org-finalize-agenda)
  3609. (setq buffer-read-only t)
  3610. (message "")))
  3611. (defun org-agenda-ndays-to-span (n)
  3612. "Return a span symbol for a span of N days, or N if none matches."
  3613. (cond ((symbolp n) n)
  3614. ((= n 1) 'day)
  3615. ((= n 7) 'week)
  3616. (t n)))
  3617. (defun org-agenda-span-to-ndays (span start-day)
  3618. "Return ndays from SPAN starting at START-DAY."
  3619. (cond ((numberp span) span)
  3620. ((eq span 'day) 1)
  3621. ((eq span 'week) 7)
  3622. ((eq span 'month)
  3623. (let ((date (calendar-gregorian-from-absolute start-day)))
  3624. (calendar-last-day-of-month (car date) (caddr date))))
  3625. ((eq span 'year)
  3626. (let ((date (calendar-gregorian-from-absolute start-day)))
  3627. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3628. (defun org-agenda-span-name (span)
  3629. "Return a SPAN name."
  3630. (if (null span)
  3631. ""
  3632. (if (symbolp span)
  3633. (capitalize (symbol-name span))
  3634. (format "%d days" span))))
  3635. ;;; Agenda word search
  3636. (defvar org-agenda-search-history nil)
  3637. (defvar org-todo-only nil)
  3638. (defvar org-search-syntax-table nil
  3639. "Special syntax table for org-mode search.
  3640. In this table, we have single quotes not as word constituents, to
  3641. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3642. (defun org-search-syntax-table ()
  3643. (unless org-search-syntax-table
  3644. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3645. (modify-syntax-entry ?' "." org-search-syntax-table)
  3646. (modify-syntax-entry ?` "." org-search-syntax-table))
  3647. org-search-syntax-table)
  3648. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3649. ;;;###autoload
  3650. (defun org-search-view (&optional todo-only string edit-at)
  3651. "Show all entries that contain a phrase or words or regular expressions.
  3652. With optional prefix argument TODO-ONLY, only consider entries that are
  3653. TODO entries. The argument STRING can be used to pass a default search
  3654. string into this function. If EDIT-AT is non-nil, it means that the
  3655. user should get a chance to edit this string, with cursor at position
  3656. EDIT-AT.
  3657. The search string can be viewed either as a phrase that should be found as
  3658. is, or it can be broken into a number of snippets, each of which must match
  3659. in a Boolean way to select an entry. The default depends on the variable
  3660. `org-agenda-search-view-always-boolean'.
  3661. Even if this is turned off (the default) you can always switch to
  3662. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3663. The default is a direct search of the whole phrase, where each space in
  3664. the search string can expand to an arbitrary amount of whitespace,
  3665. including newlines.
  3666. If using a Boolean search, the search string is split on whitespace and
  3667. each snippet is searched separately, with logical AND to select an entry.
  3668. Words prefixed with a minus must *not* occur in the entry. Words without
  3669. a prefix or prefixed with a plus must occur in the entry. Matching is
  3670. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3671. match whole words, not parts of a word) if
  3672. `org-agenda-search-view-force-full-words' is set (default is nil).
  3673. Boolean search snippets enclosed by curly braces are interpreted as
  3674. regular expressions that must or (when preceded with \"-\") must not
  3675. match in the entry. Snippets enclosed into double quotes will be taken
  3676. as a whole, to include whitespace.
  3677. - If the search string starts with an asterisk, search only in headlines.
  3678. - If (possibly after the leading star) the search string starts with an
  3679. exclamation mark, this also means to look at TODO entries only, an effect
  3680. that can also be achieved with a prefix argument.
  3681. - If (possibly after star and exclamation mark) the search string starts
  3682. with a colon, this will mean that the (non-regexp) snippets of the
  3683. Boolean search must match as full words.
  3684. This command searches the agenda files, and in addition the files listed
  3685. in `org-agenda-text-search-extra-files'."
  3686. (interactive "P")
  3687. (org-prepare-agenda "SEARCH")
  3688. (org-compile-prefix-format 'search)
  3689. (org-set-sorting-strategy 'search)
  3690. (let* ((props (list 'face nil
  3691. 'done-face 'org-agenda-done
  3692. 'org-not-done-regexp org-not-done-regexp
  3693. 'org-todo-regexp org-todo-regexp
  3694. 'org-complex-heading-regexp org-complex-heading-regexp
  3695. 'mouse-face 'highlight
  3696. 'help-echo (format "mouse-2 or RET jump to location")))
  3697. (full-words org-agenda-search-view-force-full-words)
  3698. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3699. regexp rtn rtnall files file pos
  3700. marker category org-category-pos tags c neg re boolean
  3701. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3702. (unless (and (not edit-at)
  3703. (stringp string)
  3704. (string-match "\\S-" string))
  3705. (setq string (read-string
  3706. (if org-agenda-search-view-always-boolean
  3707. "[+-]Word/{Regexp} ...: "
  3708. "Phrase, or [+-]Word/{Regexp} ...: ")
  3709. (cond
  3710. ((integerp edit-at) (cons string edit-at))
  3711. (edit-at string))
  3712. 'org-agenda-search-history)))
  3713. (org-set-local 'org-todo-only todo-only)
  3714. (setq org-agenda-redo-command
  3715. (list 'org-search-view (if todo-only t nil) string
  3716. '(if current-prefix-arg 1 nil)))
  3717. (setq org-agenda-query-string string)
  3718. (if (equal (string-to-char string) ?*)
  3719. (setq hdl-only t
  3720. words (substring string 1))
  3721. (setq words string))
  3722. (when (equal (string-to-char words) ?!)
  3723. (setq todo-only t
  3724. words (substring words 1)))
  3725. (when (equal (string-to-char words) ?:)
  3726. (setq full-words t
  3727. words (substring words 1)))
  3728. (if (or org-agenda-search-view-always-boolean
  3729. (member (string-to-char words) '(?- ?+ ?\{)))
  3730. (setq boolean t))
  3731. (setq words (org-split-string words))
  3732. (let (www w)
  3733. (while (setq w (pop words))
  3734. (while (and (string-match "\\\\\\'" w) words)
  3735. (setq w (concat (substring w 0 -1) " " (pop words))))
  3736. (push w www))
  3737. (setq words (nreverse www) www nil)
  3738. (while (setq w (pop words))
  3739. (when (and (string-match "\\`[-+]?{" w)
  3740. (not (string-match "}\\'" w)))
  3741. (while (and words (not (string-match "}\\'" (car words))))
  3742. (setq w (concat w " " (pop words))))
  3743. (setq w (concat w " " (pop words))))
  3744. (push w www))
  3745. (setq words (nreverse www)))
  3746. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3747. (when boolean
  3748. (let (wds w)
  3749. (while (setq w (pop words))
  3750. (if (or (equal (substring w 0 1) "\"")
  3751. (and (> (length w) 1)
  3752. (member (substring w 0 1) '("+" "-"))
  3753. (equal (substring w 1 2) "\"")))
  3754. (while (and words (not (equal (substring w -1) "\"")))
  3755. (setq w (concat w " " (pop words)))))
  3756. (and (string-match "\\`\\([-+]?\\)\"" w)
  3757. (setq w (replace-match "\\1" nil nil w)))
  3758. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3759. (push w wds))
  3760. (setq words (nreverse wds))))
  3761. (if boolean
  3762. (mapc (lambda (w)
  3763. (setq c (string-to-char w))
  3764. (if (equal c ?-)
  3765. (setq neg t w (substring w 1))
  3766. (if (equal c ?+)
  3767. (setq neg nil w (substring w 1))
  3768. (setq neg nil)))
  3769. (if (string-match "\\`{.*}\\'" w)
  3770. (setq re (substring w 1 -1))
  3771. (if full-words
  3772. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3773. (setq re (regexp-quote (downcase w)))))
  3774. (if neg (push re regexps-) (push re regexps+)))
  3775. words)
  3776. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3777. regexps+))
  3778. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3779. (if (not regexps+)
  3780. (setq regexp org-outline-regexp-bol)
  3781. (setq regexp (pop regexps+))
  3782. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3783. regexp))))
  3784. (setq files (org-agenda-files nil 'ifmode))
  3785. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3786. (pop org-agenda-text-search-extra-files)
  3787. (setq files (org-add-archive-files files)))
  3788. (setq files (append files org-agenda-text-search-extra-files)
  3789. rtnall nil)
  3790. (while (setq file (pop files))
  3791. (setq ee nil)
  3792. (catch 'nextfile
  3793. (org-check-agenda-file file)
  3794. (setq buffer (if (file-exists-p file)
  3795. (org-get-agenda-file-buffer file)
  3796. (error "No such file %s" file)))
  3797. (if (not buffer)
  3798. ;; If file does not exist, make sure an error message is sent
  3799. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3800. file))))
  3801. (with-current-buffer buffer
  3802. (with-syntax-table (org-search-syntax-table)
  3803. (unless (derived-mode-p 'org-mode)
  3804. (error "Agenda file %s is not in `org-mode'" file))
  3805. (let ((case-fold-search t))
  3806. (save-excursion
  3807. (save-restriction
  3808. (if org-agenda-restrict
  3809. (narrow-to-region org-agenda-restrict-begin
  3810. org-agenda-restrict-end)
  3811. (widen))
  3812. (goto-char (point-min))
  3813. (unless (or (org-at-heading-p)
  3814. (outline-next-heading))
  3815. (throw 'nextfile t))
  3816. (goto-char (max (point-min) (1- (point))))
  3817. (while (re-search-forward regexp nil t)
  3818. (org-back-to-heading t)
  3819. (skip-chars-forward "* ")
  3820. (setq beg (point-at-bol)
  3821. beg1 (point)
  3822. end (progn (outline-next-heading) (point)))
  3823. (catch :skip
  3824. (goto-char beg)
  3825. (org-agenda-skip)
  3826. (setq str (buffer-substring-no-properties
  3827. (point-at-bol)
  3828. (if hdl-only (point-at-eol) end)))
  3829. (mapc (lambda (wr) (when (string-match wr str)
  3830. (goto-char (1- end))
  3831. (throw :skip t)))
  3832. regexps-)
  3833. (mapc (lambda (wr) (unless (string-match wr str)
  3834. (goto-char (1- end))
  3835. (throw :skip t)))
  3836. (if todo-only
  3837. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3838. regexps+)
  3839. regexps+))
  3840. (goto-char beg)
  3841. (setq marker (org-agenda-new-marker (point))
  3842. category (org-get-category)
  3843. org-category-pos (get-text-property (point) 'org-category-position)
  3844. tags (org-get-tags-at (point))
  3845. txt (org-agenda-format-item
  3846. ""
  3847. (buffer-substring-no-properties
  3848. beg1 (point-at-eol))
  3849. category tags))
  3850. (org-add-props txt props
  3851. 'org-marker marker 'org-hd-marker marker
  3852. 'org-todo-regexp org-todo-regexp
  3853. 'org-complex-heading-regexp org-complex-heading-regexp
  3854. 'priority 1000 'org-category category
  3855. 'org-category-position org-category-pos
  3856. 'type "search")
  3857. (push txt ee)
  3858. (goto-char (1- end))))))))))
  3859. (setq rtn (nreverse ee))
  3860. (setq rtnall (append rtnall rtn)))
  3861. (if org-agenda-overriding-header
  3862. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3863. nil 'face 'org-agenda-structure) "\n")
  3864. (insert "Search words: ")
  3865. (add-text-properties (point-min) (1- (point))
  3866. (list 'face 'org-agenda-structure))
  3867. (setq pos (point))
  3868. (insert string "\n")
  3869. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3870. (setq pos (point))
  3871. (unless org-agenda-multi
  3872. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3873. (add-text-properties pos (1- (point))
  3874. (list 'face 'org-agenda-structure))))
  3875. (org-agenda-mark-header-line (point-min))
  3876. (when rtnall
  3877. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3878. (goto-char (point-min))
  3879. (or org-agenda-multi (org-fit-agenda-window))
  3880. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3881. (org-finalize-agenda)
  3882. (setq buffer-read-only t)))
  3883. ;;; Agenda TODO list
  3884. (defvar org-select-this-todo-keyword nil)
  3885. (defvar org-last-arg nil)
  3886. ;;;###autoload
  3887. (defun org-todo-list (arg)
  3888. "Show all (not done) TODO entries from all agenda file in a single list.
  3889. The prefix arg can be used to select a specific TODO keyword and limit
  3890. the list to these. When using \\[universal-argument], you will be prompted
  3891. for a keyword. A numeric prefix directly selects the Nth keyword in
  3892. `org-todo-keywords-1'."
  3893. (interactive "P")
  3894. (org-prepare-agenda "TODO")
  3895. (org-compile-prefix-format 'todo)
  3896. (org-set-sorting-strategy 'todo)
  3897. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3898. (let* ((today (org-today))
  3899. (date (calendar-gregorian-from-absolute today))
  3900. (kwds org-todo-keywords-for-agenda)
  3901. (completion-ignore-case t)
  3902. (org-select-this-todo-keyword
  3903. (if (stringp arg) arg
  3904. (and arg (integerp arg) (> arg 0)
  3905. (nth (1- arg) kwds))))
  3906. rtn rtnall files file pos)
  3907. (when (equal arg '(4))
  3908. (setq org-select-this-todo-keyword
  3909. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3910. (mapcar 'list kwds) nil nil)))
  3911. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3912. (org-set-local 'org-last-arg arg)
  3913. (setq org-agenda-redo-command
  3914. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3915. (setq files (org-agenda-files nil 'ifmode)
  3916. rtnall nil)
  3917. (while (setq file (pop files))
  3918. (catch 'nextfile
  3919. (org-check-agenda-file file)
  3920. (setq rtn (org-agenda-get-day-entries file date :todo))
  3921. (setq rtnall (append rtnall rtn))))
  3922. (if org-agenda-overriding-header
  3923. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3924. nil 'face 'org-agenda-structure) "\n")
  3925. (insert "Global list of TODO items of type: ")
  3926. (add-text-properties (point-min) (1- (point))
  3927. (list 'face 'org-agenda-structure
  3928. 'short-heading
  3929. (concat "ToDo: "
  3930. (or org-select-this-todo-keyword "ALL"))))
  3931. (org-agenda-mark-header-line (point-min))
  3932. (setq pos (point))
  3933. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3934. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3935. (setq pos (point))
  3936. (unless org-agenda-multi
  3937. (insert "Available with `N r': (0)ALL")
  3938. (let ((n 0) s)
  3939. (mapc (lambda (x)
  3940. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3941. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3942. (insert "\n "))
  3943. (insert " " s))
  3944. kwds))
  3945. (insert "\n"))
  3946. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3947. (org-agenda-mark-header-line (point-min))
  3948. (when rtnall
  3949. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3950. (goto-char (point-min))
  3951. (or org-agenda-multi (org-fit-agenda-window))
  3952. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3953. (org-finalize-agenda)
  3954. (setq buffer-read-only t)))
  3955. ;;; Agenda tags match
  3956. ;;;###autoload
  3957. (defun org-tags-view (&optional todo-only match)
  3958. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3959. The prefix arg TODO-ONLY limits the search to TODO entries."
  3960. (interactive "P")
  3961. (let* ((org-tags-match-list-sublevels
  3962. org-tags-match-list-sublevels)
  3963. (completion-ignore-case t)
  3964. rtn rtnall files file pos matcher
  3965. buffer)
  3966. (when (and (stringp match) (not (string-match "\\S-" match)))
  3967. (setq match nil))
  3968. (setq matcher (org-make-tags-matcher match)
  3969. match (car matcher) matcher (cdr matcher))
  3970. (org-prepare-agenda (concat "TAGS " match))
  3971. (org-compile-prefix-format 'tags)
  3972. (org-set-sorting-strategy 'tags)
  3973. (setq org-agenda-query-string match)
  3974. (setq org-agenda-redo-command
  3975. (list 'org-tags-view (list 'quote todo-only)
  3976. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3977. (setq files (org-agenda-files nil 'ifmode)
  3978. rtnall nil)
  3979. (while (setq file (pop files))
  3980. (catch 'nextfile
  3981. (org-check-agenda-file file)
  3982. (setq buffer (if (file-exists-p file)
  3983. (org-get-agenda-file-buffer file)
  3984. (error "No such file %s" file)))
  3985. (if (not buffer)
  3986. ;; If file does not exist, error message to agenda
  3987. (setq rtn (list
  3988. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3989. rtnall (append rtnall rtn))
  3990. (with-current-buffer buffer
  3991. (unless (derived-mode-p 'org-mode)
  3992. (error "Agenda file %s is not in `org-mode'" file))
  3993. (save-excursion
  3994. (save-restriction
  3995. (if org-agenda-restrict
  3996. (narrow-to-region org-agenda-restrict-begin
  3997. org-agenda-restrict-end)
  3998. (widen))
  3999. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4000. (setq rtnall (append rtnall rtn))))))))
  4001. (if org-agenda-overriding-header
  4002. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4003. nil 'face 'org-agenda-structure) "\n")
  4004. (insert "Headlines with TAGS match: ")
  4005. (add-text-properties (point-min) (1- (point))
  4006. (list 'face 'org-agenda-structure
  4007. 'short-heading
  4008. (concat "Match: " match)))
  4009. (setq pos (point))
  4010. (insert match "\n")
  4011. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4012. (setq pos (point))
  4013. (unless org-agenda-multi
  4014. (insert "Press `C-u r' to search again with new search string\n"))
  4015. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4016. (org-agenda-mark-header-line (point-min))
  4017. (when rtnall
  4018. (insert (org-finalize-agenda-entries rtnall) "\n"))
  4019. (goto-char (point-min))
  4020. (or org-agenda-multi (org-fit-agenda-window))
  4021. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  4022. (org-finalize-agenda)
  4023. (setq buffer-read-only t)))
  4024. ;;; Agenda Finding stuck projects
  4025. (defvar org-agenda-skip-regexp nil
  4026. "Regular expression used in skipping subtrees for the agenda.
  4027. This is basically a temporary global variable that can be set and then
  4028. used by user-defined selections using `org-agenda-skip-function'.")
  4029. (defvar org-agenda-overriding-header nil
  4030. "When set during agenda, todo and tags searches it replaces the header.
  4031. This variable should not be set directly, but custom commands can bind it
  4032. in the options section.")
  4033. (defun org-agenda-skip-entry-when-regexp-matches ()
  4034. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4035. If yes, it returns the end position of this entry, causing agenda commands
  4036. to skip the entry but continuing the search in the subtree. This is a
  4037. function that can be put into `org-agenda-skip-function' for the duration
  4038. of a command."
  4039. (let ((end (save-excursion (org-end-of-subtree t)))
  4040. skip)
  4041. (save-excursion
  4042. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4043. (and skip end)))
  4044. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4045. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4046. If yes, it returns the end position of this tree, causing agenda commands
  4047. to skip this subtree. This is a function that can be put into
  4048. `org-agenda-skip-function' for the duration of a command."
  4049. (let ((end (save-excursion (org-end-of-subtree t)))
  4050. skip)
  4051. (save-excursion
  4052. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4053. (and skip end)))
  4054. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4055. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4056. If yes, it returns the end position of the current entry (NOT the tree),
  4057. causing agenda commands to skip the entry but continuing the search in
  4058. the subtree. This is a function that can be put into
  4059. `org-agenda-skip-function' for the duration of a command. An important
  4060. use of this function is for the stuck project list."
  4061. (let ((end (save-excursion (org-end-of-subtree t)))
  4062. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4063. skip)
  4064. (save-excursion
  4065. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4066. (and skip entry-end)))
  4067. (defun org-agenda-skip-entry-if (&rest conditions)
  4068. "Skip entry if any of CONDITIONS is true.
  4069. See `org-agenda-skip-if' for details."
  4070. (org-agenda-skip-if nil conditions))
  4071. (defun org-agenda-skip-subtree-if (&rest conditions)
  4072. "Skip entry if any of CONDITIONS is true.
  4073. See `org-agenda-skip-if' for details."
  4074. (org-agenda-skip-if t conditions))
  4075. (defun org-agenda-skip-if (subtree conditions)
  4076. "Checks current entity for CONDITIONS.
  4077. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4078. the entry (i.e. the text before the next heading) is checked.
  4079. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4080. from different tests. Valid conditions are:
  4081. scheduled Check if there is a scheduled cookie
  4082. notscheduled Check if there is no scheduled cookie
  4083. deadline Check if there is a deadline
  4084. notdeadline Check if there is no deadline
  4085. timestamp Check if there is a timestamp (also deadline or scheduled)
  4086. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4087. regexp Check if regexp matches
  4088. notregexp Check if regexp does not match.
  4089. todo Check if TODO keyword matches
  4090. nottodo Check if TODO keyword does not match
  4091. The regexp is taken from the conditions list, it must come right after
  4092. the `regexp' or `notregexp' element.
  4093. `todo' and `nottodo' accept as an argument a list of todo
  4094. keywords, which may include \"*\" to match any todo keyword.
  4095. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4096. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4097. Instead of a list, a keyword class may be given. For example:
  4098. (org-agenda-skip-entry-if 'nottodo 'done)
  4099. would skip entries that haven't been marked with any of \"DONE\"
  4100. keywords. Possible classes are: `todo', `done', `any'.
  4101. If any of these conditions is met, this function returns the end point of
  4102. the entity, causing the search to continue from there. This is a function
  4103. that can be put into `org-agenda-skip-function' for the duration of a command."
  4104. (let (beg end m)
  4105. (org-back-to-heading t)
  4106. (setq beg (point)
  4107. end (if subtree
  4108. (progn (org-end-of-subtree t) (point))
  4109. (progn (outline-next-heading) (1- (point)))))
  4110. (goto-char beg)
  4111. (and
  4112. (or
  4113. (and (memq 'scheduled conditions)
  4114. (re-search-forward org-scheduled-time-regexp end t))
  4115. (and (memq 'notscheduled conditions)
  4116. (not (re-search-forward org-scheduled-time-regexp end t)))
  4117. (and (memq 'deadline conditions)
  4118. (re-search-forward org-deadline-time-regexp end t))
  4119. (and (memq 'notdeadline conditions)
  4120. (not (re-search-forward org-deadline-time-regexp end t)))
  4121. (and (memq 'timestamp conditions)
  4122. (re-search-forward org-ts-regexp end t))
  4123. (and (memq 'nottimestamp conditions)
  4124. (not (re-search-forward org-ts-regexp end t)))
  4125. (and (setq m (memq 'regexp conditions))
  4126. (stringp (nth 1 m))
  4127. (re-search-forward (nth 1 m) end t))
  4128. (and (setq m (memq 'notregexp conditions))
  4129. (stringp (nth 1 m))
  4130. (not (re-search-forward (nth 1 m) end t)))
  4131. (and (or
  4132. (setq m (memq 'nottodo conditions))
  4133. (setq m (memq 'todo-unblocked conditions))
  4134. (setq m (memq 'nottodo-unblocked conditions))
  4135. (setq m (memq 'todo conditions)))
  4136. (org-agenda-skip-if-todo m end)))
  4137. end)))
  4138. (defun org-agenda-skip-if-todo (args end)
  4139. "Helper function for `org-agenda-skip-if', do not use it directly.
  4140. ARGS is a list with first element either `todo', `nottodo',
  4141. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4142. a list of TODO keywords, or a state symbol `todo' or `done' or
  4143. `any'."
  4144. (let ((kw (car args))
  4145. (arg (cadr args))
  4146. todo-wds todo-re)
  4147. (setq todo-wds
  4148. (org-uniquify
  4149. (cond
  4150. ((listp arg) ;; list of keywords
  4151. (if (member "*" arg)
  4152. (mapcar 'substring-no-properties org-todo-keywords-1)
  4153. arg))
  4154. ((symbolp arg) ;; keyword class name
  4155. (cond
  4156. ((eq arg 'todo)
  4157. (org-delete-all org-done-keywords
  4158. (mapcar 'substring-no-properties
  4159. org-todo-keywords-1)))
  4160. ((eq arg 'done) org-done-keywords)
  4161. ((eq arg 'any)
  4162. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4163. (setq todo-re
  4164. (concat "^\\*+[ \t]+\\<\\("
  4165. (mapconcat 'identity todo-wds "\\|")
  4166. "\\)\\>"))
  4167. (cond
  4168. ((eq kw 'todo) (re-search-forward todo-re end t))
  4169. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4170. ((eq kw 'todo-unblocked)
  4171. (catch 'unblocked
  4172. (while (re-search-forward todo-re end t)
  4173. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4174. nil))
  4175. ((eq kw 'nottodo-unblocked)
  4176. (catch 'unblocked
  4177. (while (re-search-forward todo-re end t)
  4178. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4179. t))
  4180. )))
  4181. ;;;###autoload
  4182. (defun org-agenda-list-stuck-projects (&rest ignore)
  4183. "Create agenda view for projects that are stuck.
  4184. Stuck projects are project that have no next actions. For the definitions
  4185. of what a project is and how to check if it stuck, customize the variable
  4186. `org-stuck-projects'."
  4187. (interactive)
  4188. (let* ((org-agenda-skip-function
  4189. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4190. ;; We could have used org-agenda-skip-if here.
  4191. (org-agenda-overriding-header
  4192. (or org-agenda-overriding-header "List of stuck projects: "))
  4193. (matcher (nth 0 org-stuck-projects))
  4194. (todo (nth 1 org-stuck-projects))
  4195. (todo-wds (if (member "*" todo)
  4196. (progn
  4197. (org-prepare-agenda-buffers (org-agenda-files
  4198. nil 'ifmode))
  4199. (org-delete-all
  4200. org-done-keywords-for-agenda
  4201. (copy-sequence org-todo-keywords-for-agenda)))
  4202. todo))
  4203. (todo-re (concat "^\\*+[ \t]+\\("
  4204. (mapconcat 'identity todo-wds "\\|")
  4205. "\\)\\>"))
  4206. (tags (nth 2 org-stuck-projects))
  4207. (tags-re (if (member "*" tags)
  4208. (concat org-outline-regexp-bol
  4209. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4210. (if tags
  4211. (concat org-outline-regexp-bol
  4212. ".*:\\("
  4213. (mapconcat 'identity tags "\\|")
  4214. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4215. (gen-re (nth 3 org-stuck-projects))
  4216. (re-list
  4217. (delq nil
  4218. (list
  4219. (if todo todo-re)
  4220. (if tags tags-re)
  4221. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4222. gen-re)))))
  4223. (setq org-agenda-skip-regexp
  4224. (if re-list
  4225. (mapconcat 'identity re-list "\\|")
  4226. (error "No information how to identify unstuck projects")))
  4227. (org-tags-view nil matcher)
  4228. (with-current-buffer org-agenda-buffer-name
  4229. (setq org-agenda-redo-command
  4230. '(org-agenda-list-stuck-projects
  4231. (or current-prefix-arg org-last-arg))))))
  4232. ;;; Diary integration
  4233. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4234. (defvar diary-list-entries-hook)
  4235. (defvar diary-time-regexp)
  4236. (defun org-get-entries-from-diary (date)
  4237. "Get the (Emacs Calendar) diary entries for DATE."
  4238. (require 'diary-lib)
  4239. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4240. (diary-display-hook '(fancy-diary-display))
  4241. (diary-display-function 'fancy-diary-display)
  4242. (pop-up-frames nil)
  4243. (diary-list-entries-hook
  4244. (cons 'org-diary-default-entry diary-list-entries-hook))
  4245. (diary-file-name-prefix-function nil) ; turn this feature off
  4246. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4247. entries
  4248. (org-disable-agenda-to-diary t))
  4249. (save-excursion
  4250. (save-window-excursion
  4251. (funcall (if (fboundp 'diary-list-entries)
  4252. 'diary-list-entries 'list-diary-entries)
  4253. date 1)))
  4254. (if (not (get-buffer diary-fancy-buffer))
  4255. (setq entries nil)
  4256. (with-current-buffer diary-fancy-buffer
  4257. (setq buffer-read-only nil)
  4258. (if (zerop (buffer-size))
  4259. ;; No entries
  4260. (setq entries nil)
  4261. ;; Omit the date and other unnecessary stuff
  4262. (org-agenda-cleanup-fancy-diary)
  4263. ;; Add prefix to each line and extend the text properties
  4264. (if (zerop (buffer-size))
  4265. (setq entries nil)
  4266. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4267. (setq entries
  4268. (with-temp-buffer
  4269. (insert entries) (goto-char (point-min))
  4270. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4271. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4272. (replace-match (concat "; " (match-string 1)))))
  4273. (buffer-string)))))
  4274. (set-buffer-modified-p nil)
  4275. (kill-buffer diary-fancy-buffer)))
  4276. (when entries
  4277. (setq entries (org-split-string entries "\n"))
  4278. (setq entries
  4279. (mapcar
  4280. (lambda (x)
  4281. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4282. ;; Extend the text properties to the beginning of the line
  4283. (org-add-props x (text-properties-at (1- (length x)) x)
  4284. 'type "diary" 'date date 'face 'org-agenda-diary))
  4285. entries)))))
  4286. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4287. "Hook run when the fancy diary buffer is cleaned up.")
  4288. (defun org-agenda-cleanup-fancy-diary ()
  4289. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4290. This gets rid of the date, the underline under the date, and
  4291. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4292. date. It also removes lines that contain only whitespace."
  4293. (goto-char (point-min))
  4294. (if (looking-at ".*?:[ \t]*")
  4295. (progn
  4296. (replace-match "")
  4297. (re-search-forward "\n=+$" nil t)
  4298. (replace-match "")
  4299. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4300. (re-search-forward "\n=+$" nil t)
  4301. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4302. (goto-char (point-min))
  4303. (while (re-search-forward "^ +\n" nil t)
  4304. (replace-match ""))
  4305. (goto-char (point-min))
  4306. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4307. (replace-match ""))
  4308. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4309. ;; Make sure entries from the diary have the right text properties.
  4310. (eval-after-load "diary-lib"
  4311. '(if (boundp 'diary-modify-entry-list-string-function)
  4312. ;; We can rely on the hook, nothing to do
  4313. nil
  4314. ;; Hook not available, must use advice to make this work
  4315. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4316. "Make the position visible."
  4317. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4318. (stringp string)
  4319. buffer-file-name)
  4320. (setq string (org-modify-diary-entry-string string))))))
  4321. (defun org-modify-diary-entry-string (string)
  4322. "Add text properties to string, allowing org-mode to act on it."
  4323. (org-add-props string nil
  4324. 'mouse-face 'highlight
  4325. 'help-echo (if buffer-file-name
  4326. (format "mouse-2 or RET jump to diary file %s"
  4327. (abbreviate-file-name buffer-file-name))
  4328. "")
  4329. 'org-agenda-diary-link t
  4330. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4331. (defun org-diary-default-entry ()
  4332. "Add a dummy entry to the diary.
  4333. Needed to avoid empty dates which mess up holiday display."
  4334. ;; Catch the error if dealing with the new add-to-diary-alist
  4335. (when org-disable-agenda-to-diary
  4336. (condition-case nil
  4337. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4338. (error
  4339. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4340. (defun org-add-to-diary-list (&rest args)
  4341. (if (fboundp 'diary-add-to-list)
  4342. (apply 'diary-add-to-list args)
  4343. (apply 'add-to-diary-list args)))
  4344. (defvar org-diary-last-run-time nil)
  4345. ;;;###autoload
  4346. (defun org-diary (&rest args)
  4347. "Return diary information from org-files.
  4348. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4349. It accesses org files and extracts information from those files to be
  4350. listed in the diary. The function accepts arguments specifying what
  4351. items should be listed. For a list of arguments allowed here, see the
  4352. variable `org-agenda-entry-types'.
  4353. The call in the diary file should look like this:
  4354. &%%(org-diary) ~/path/to/some/orgfile.org
  4355. Use a separate line for each org file to check. Or, if you omit the file name,
  4356. all files listed in `org-agenda-files' will be checked automatically:
  4357. &%%(org-diary)
  4358. If you don't give any arguments (as in the example above), the default
  4359. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4360. So the example above may also be written as
  4361. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4362. The function expects the lisp variables `entry' and `date' to be provided
  4363. by the caller, because this is how the calendar works. Don't use this
  4364. function from a program - use `org-agenda-get-day-entries' instead."
  4365. (when (> (- (org-float-time)
  4366. org-agenda-last-marker-time)
  4367. 5)
  4368. ;; I am not sure if this works with sticky agendas, because the marker
  4369. ;; list is then no longer a global variable.
  4370. (org-agenda-reset-markers))
  4371. ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
  4372. (when (buffer-live-p org-agenda-buffer)
  4373. (org-compile-prefix-format 'agenda))
  4374. (org-set-sorting-strategy 'agenda)
  4375. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4376. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4377. (list entry)
  4378. (org-agenda-files t)))
  4379. (time (org-float-time))
  4380. file rtn results)
  4381. (when (or (not org-diary-last-run-time)
  4382. (> (- time
  4383. org-diary-last-run-time)
  4384. 3))
  4385. (org-prepare-agenda-buffers files))
  4386. (setq org-diary-last-run-time time)
  4387. ;; If this is called during org-agenda, don't return any entries to
  4388. ;; the calendar. Org Agenda will list these entries itself.
  4389. (if org-disable-agenda-to-diary (setq files nil))
  4390. (while (setq file (pop files))
  4391. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4392. (setq results (append results rtn)))
  4393. (if results
  4394. (concat (org-finalize-agenda-entries results) "\n"))))
  4395. ;;; Agenda entry finders
  4396. (defun org-agenda-get-day-entries (file date &rest args)
  4397. "Does the work for `org-diary' and `org-agenda'.
  4398. FILE is the path to a file to be checked for entries. DATE is date like
  4399. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4400. which kind of entries should be extracted. For details about these, see
  4401. the documentation of `org-diary'."
  4402. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4403. (let* ((org-startup-folded nil)
  4404. (org-startup-align-all-tables nil)
  4405. (buffer (if (file-exists-p file)
  4406. (org-get-agenda-file-buffer file)
  4407. (error "No such file %s" file)))
  4408. arg results rtn deadline-results)
  4409. (if (not buffer)
  4410. ;; If file does not exist, make sure an error message ends up in diary
  4411. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4412. (with-current-buffer buffer
  4413. (unless (derived-mode-p 'org-mode)
  4414. (error "Agenda file %s is not in `org-mode'" file))
  4415. (let ((case-fold-search nil))
  4416. (save-excursion
  4417. (save-restriction
  4418. (if org-agenda-restrict
  4419. (narrow-to-region org-agenda-restrict-begin
  4420. org-agenda-restrict-end)
  4421. (widen))
  4422. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4423. (while (setq arg (pop args))
  4424. (cond
  4425. ((and (eq arg :todo)
  4426. (equal date (calendar-gregorian-from-absolute
  4427. (org-today))))
  4428. (setq rtn (org-agenda-get-todos))
  4429. (setq results (append results rtn)))
  4430. ((eq arg :timestamp)
  4431. (setq rtn (org-agenda-get-blocks))
  4432. (setq results (append results rtn))
  4433. (setq rtn (org-agenda-get-timestamps deadline-results))
  4434. (setq results (append results rtn)))
  4435. ((eq arg :sexp)
  4436. (setq rtn (org-agenda-get-sexps))
  4437. (setq results (append results rtn)))
  4438. ((eq arg :scheduled)
  4439. (setq rtn (org-agenda-get-scheduled deadline-results))
  4440. (setq results (append results rtn)))
  4441. ((eq arg :closed)
  4442. (setq rtn (org-agenda-get-progress))
  4443. (setq results (append results rtn)))
  4444. ((eq arg :deadline)
  4445. (setq rtn (org-agenda-get-deadlines))
  4446. (setq deadline-results (copy-sequence rtn))
  4447. (setq results (append results rtn))))))))
  4448. results))))
  4449. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4450. (defun org-agenda-get-todos ()
  4451. "Return the TODO information for agenda display."
  4452. (let* ((props (list 'face nil
  4453. 'done-face 'org-agenda-done
  4454. 'org-not-done-regexp org-not-done-regexp
  4455. 'org-todo-regexp org-todo-regexp
  4456. 'org-complex-heading-regexp org-complex-heading-regexp
  4457. 'mouse-face 'highlight
  4458. 'help-echo
  4459. (format "mouse-2 or RET jump to org file %s"
  4460. (abbreviate-file-name buffer-file-name))))
  4461. (regexp (format org-heading-keyword-regexp-format
  4462. (cond
  4463. ((and org-select-this-todo-keyword
  4464. (equal org-select-this-todo-keyword "*"))
  4465. org-todo-regexp)
  4466. (org-select-this-todo-keyword
  4467. (concat "\\("
  4468. (mapconcat 'identity
  4469. (org-split-string
  4470. org-select-this-todo-keyword
  4471. "|")
  4472. "\\|") "\\)"))
  4473. (t org-not-done-regexp))))
  4474. marker priority category org-category-pos tags todo-state
  4475. ee txt beg end)
  4476. (goto-char (point-min))
  4477. (while (re-search-forward regexp nil t)
  4478. (catch :skip
  4479. (save-match-data
  4480. (beginning-of-line)
  4481. (org-agenda-skip)
  4482. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4483. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4484. (goto-char (1+ beg))
  4485. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4486. (throw :skip nil)))
  4487. (goto-char (match-beginning 2))
  4488. (setq marker (org-agenda-new-marker (match-beginning 0))
  4489. category (org-get-category)
  4490. org-category-pos (get-text-property (point) 'org-category-position)
  4491. txt (org-trim
  4492. (buffer-substring (match-beginning 2) (match-end 0)))
  4493. tags (org-get-tags-at (point))
  4494. txt (org-agenda-format-item "" txt category tags)
  4495. priority (1+ (org-get-priority txt))
  4496. todo-state (org-get-todo-state))
  4497. (org-add-props txt props
  4498. 'org-marker marker 'org-hd-marker marker
  4499. 'priority priority 'org-category category
  4500. 'org-category-position org-category-pos
  4501. 'type "todo" 'todo-state todo-state)
  4502. (push txt ee)
  4503. (if org-agenda-todo-list-sublevels
  4504. (goto-char (match-end 2))
  4505. (org-end-of-subtree 'invisible))))
  4506. (nreverse ee)))
  4507. (defun org-agenda-todo-custom-ignore-p (time n)
  4508. "Check whether timestamp is farther away then n number of days.
  4509. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4510. `org-agenda-todo-ignore-scheduled' or
  4511. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4512. (let ((days (org-days-to-time time)))
  4513. (if (>= n 0)
  4514. (>= days n)
  4515. (<= days n))))
  4516. ;;;###autoload
  4517. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4518. (&optional end)
  4519. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4520. (when (or org-agenda-todo-ignore-with-date
  4521. org-agenda-todo-ignore-scheduled
  4522. org-agenda-todo-ignore-deadlines
  4523. org-agenda-todo-ignore-timestamp)
  4524. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4525. (save-excursion
  4526. (or (and org-agenda-todo-ignore-with-date
  4527. (re-search-forward org-ts-regexp end t))
  4528. (and org-agenda-todo-ignore-scheduled
  4529. (re-search-forward org-scheduled-time-regexp end t)
  4530. (cond
  4531. ((eq org-agenda-todo-ignore-scheduled 'future)
  4532. (> (org-days-to-time (match-string 1)) 0))
  4533. ((eq org-agenda-todo-ignore-scheduled 'past)
  4534. (<= (org-days-to-time (match-string 1)) 0))
  4535. ((numberp org-agenda-todo-ignore-scheduled)
  4536. (org-agenda-todo-custom-ignore-p
  4537. (match-string 1) org-agenda-todo-ignore-scheduled))
  4538. (t)))
  4539. (and org-agenda-todo-ignore-deadlines
  4540. (re-search-forward org-deadline-time-regexp end t)
  4541. (cond
  4542. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4543. ((eq org-agenda-todo-ignore-deadlines 'far)
  4544. (not (org-deadline-close (match-string 1))))
  4545. ((eq org-agenda-todo-ignore-deadlines 'future)
  4546. (> (org-days-to-time (match-string 1)) 0))
  4547. ((eq org-agenda-todo-ignore-deadlines 'past)
  4548. (<= (org-days-to-time (match-string 1)) 0))
  4549. ((numberp org-agenda-todo-ignore-deadlines)
  4550. (org-agenda-todo-custom-ignore-p
  4551. (match-string 1) org-agenda-todo-ignore-deadlines))
  4552. (t (org-deadline-close (match-string 1)))))
  4553. (and org-agenda-todo-ignore-timestamp
  4554. (let ((buffer (current-buffer))
  4555. (regexp
  4556. (concat
  4557. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4558. (start (point)))
  4559. ;; Copy current buffer into a temporary one
  4560. (with-temp-buffer
  4561. (insert-buffer-substring buffer start end)
  4562. (goto-char (point-min))
  4563. ;; Delete SCHEDULED and DEADLINE items
  4564. (while (re-search-forward regexp end t)
  4565. (delete-region (match-beginning 0) (match-end 0)))
  4566. (goto-char (point-min))
  4567. ;; No search for timestamp left
  4568. (when (re-search-forward org-ts-regexp nil t)
  4569. (cond
  4570. ((eq org-agenda-todo-ignore-timestamp 'future)
  4571. (> (org-days-to-time (match-string 1)) 0))
  4572. ((eq org-agenda-todo-ignore-timestamp 'past)
  4573. (<= (org-days-to-time (match-string 1)) 0))
  4574. ((numberp org-agenda-todo-ignore-timestamp)
  4575. (org-agenda-todo-custom-ignore-p
  4576. (match-string 1) org-agenda-todo-ignore-timestamp))
  4577. (t))))))))))
  4578. (defconst org-agenda-no-heading-message
  4579. "No heading for this item in buffer or region.")
  4580. (defun org-agenda-get-timestamps (&optional deadline-results)
  4581. "Return the date stamp information for agenda display."
  4582. (let* ((props (list 'face 'org-agenda-calendar-event
  4583. 'org-not-done-regexp org-not-done-regexp
  4584. 'org-todo-regexp org-todo-regexp
  4585. 'org-complex-heading-regexp org-complex-heading-regexp
  4586. 'mouse-face 'highlight
  4587. 'help-echo
  4588. (format "mouse-2 or RET jump to org file %s"
  4589. (abbreviate-file-name buffer-file-name))))
  4590. (d1 (calendar-absolute-from-gregorian date))
  4591. mm
  4592. (deadline-position-alist
  4593. (mapcar (lambda (a) (and (setq mm (get-text-property
  4594. 0 'org-hd-marker a))
  4595. (cons (marker-position mm) a)))
  4596. deadline-results))
  4597. (remove-re org-ts-regexp)
  4598. (regexp
  4599. (concat
  4600. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4601. (regexp-quote
  4602. (substring
  4603. (format-time-string
  4604. (car org-time-stamp-formats)
  4605. (apply 'encode-time ; DATE bound by calendar
  4606. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4607. 1 11))
  4608. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4609. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4610. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4611. donep tmp priority category org-category-pos ee txt timestr tags
  4612. b0 b3 e3 head todo-state end-of-match show-all)
  4613. (goto-char (point-min))
  4614. (while (setq end-of-match (re-search-forward regexp nil t))
  4615. (setq b0 (match-beginning 0)
  4616. b3 (match-beginning 3) e3 (match-end 3)
  4617. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4618. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4619. (member todo-state
  4620. org-agenda-repeating-timestamp-show-all)))
  4621. (catch :skip
  4622. (and (org-at-date-range-p) (throw :skip nil))
  4623. (org-agenda-skip)
  4624. (if (and (match-end 1)
  4625. (not (= d1 (org-time-string-to-absolute
  4626. (match-string 1) d1 nil show-all
  4627. (current-buffer) b0))))
  4628. (throw :skip nil))
  4629. (if (and e3
  4630. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4631. (throw :skip nil))
  4632. (setq tmp (buffer-substring (max (point-min)
  4633. (- b0 org-ds-keyword-length))
  4634. b0)
  4635. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4636. inactivep (= (char-after b0) ?\[)
  4637. deadlinep (string-match org-deadline-regexp tmp)
  4638. scheduledp (string-match org-scheduled-regexp tmp)
  4639. closedp (and org-agenda-include-inactive-timestamps
  4640. (string-match org-closed-string tmp))
  4641. clockp (and org-agenda-include-inactive-timestamps
  4642. (or (string-match org-clock-string tmp)
  4643. (string-match "]-+\\'" tmp)))
  4644. donep (member todo-state org-done-keywords))
  4645. (if (or scheduledp deadlinep closedp clockp
  4646. (and donep org-agenda-skip-timestamp-if-done))
  4647. (throw :skip t))
  4648. (if (string-match ">" timestr)
  4649. ;; substring should only run to end of time stamp
  4650. (setq timestr (substring timestr 0 (match-end 0))))
  4651. (setq marker (org-agenda-new-marker b0)
  4652. category (org-get-category b0)
  4653. org-category-pos (get-text-property b0 'org-category-position))
  4654. (save-excursion
  4655. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4656. (setq txt org-agenda-no-heading-message)
  4657. (goto-char (match-beginning 0))
  4658. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4659. (assoc (point) deadline-position-alist))
  4660. (throw :skip nil))
  4661. (setq hdmarker (org-agenda-new-marker)
  4662. tags (org-get-tags-at))
  4663. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4664. (setq head (or (match-string 1) ""))
  4665. (setq txt (org-agenda-format-item
  4666. (if inactivep org-agenda-inactive-leader nil)
  4667. head category tags timestr
  4668. remove-re)))
  4669. (setq priority (org-get-priority txt))
  4670. (org-add-props txt props
  4671. 'org-marker marker 'org-hd-marker hdmarker)
  4672. (org-add-props txt nil 'priority priority
  4673. 'org-category category 'date date
  4674. 'org-category-position org-category-pos
  4675. 'todo-state todo-state
  4676. 'type "timestamp")
  4677. (push txt ee))
  4678. (if org-agenda-skip-additional-timestamps-same-entry
  4679. (outline-next-heading)
  4680. (goto-char end-of-match))))
  4681. (nreverse ee)))
  4682. (defun org-agenda-get-sexps ()
  4683. "Return the sexp information for agenda display."
  4684. (require 'diary-lib)
  4685. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4686. 'mouse-face 'highlight
  4687. 'help-echo
  4688. (format "mouse-2 or RET jump to org file %s"
  4689. (abbreviate-file-name buffer-file-name))))
  4690. (regexp "^&?%%(")
  4691. marker category extra org-category-pos ee txt tags entry
  4692. result beg b sexp sexp-entry todo-state)
  4693. (goto-char (point-min))
  4694. (while (re-search-forward regexp nil t)
  4695. (catch :skip
  4696. (org-agenda-skip)
  4697. (setq beg (match-beginning 0))
  4698. (goto-char (1- (match-end 0)))
  4699. (setq b (point))
  4700. (forward-sexp 1)
  4701. (setq sexp (buffer-substring b (point)))
  4702. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4703. (org-trim (match-string 1))
  4704. ""))
  4705. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4706. (when result
  4707. (setq marker (org-agenda-new-marker beg)
  4708. category (org-get-category beg)
  4709. org-category-pos (get-text-property beg 'org-category-position)
  4710. todo-state (org-get-todo-state))
  4711. (dolist (r (if (stringp result)
  4712. (list result)
  4713. result)) ;; we expect a list here
  4714. (when (and org-agenda-diary-sexp-prefix
  4715. (string-match org-agenda-diary-sexp-prefix r))
  4716. (setq extra (match-string 0 r)
  4717. r (replace-match "" nil nil r)))
  4718. (if (string-match "\\S-" r)
  4719. (setq txt r)
  4720. (setq txt "SEXP entry returned empty string"))
  4721. (setq txt (org-agenda-format-item
  4722. extra txt category tags 'time))
  4723. (org-add-props txt props 'org-marker marker)
  4724. (org-add-props txt nil
  4725. 'org-category category 'date date 'todo-state todo-state
  4726. 'org-category-position org-category-pos
  4727. 'type "sexp")
  4728. (push txt ee)))))
  4729. (nreverse ee)))
  4730. ;; Calendar sanity: define some functions that are independent of
  4731. ;; `calendar-date-style'.
  4732. ;; Normally I would like to use ISO format when calling the diary functions,
  4733. ;; but to make sure we still have Emacs 22 compatibility we bind
  4734. ;; also `european-calendar-style' and use european format
  4735. (defun org-anniversary (year month day &optional mark)
  4736. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4737. (org-no-warnings
  4738. (let ((calendar-date-style 'european) (european-calendar-style t))
  4739. (diary-anniversary day month year mark))))
  4740. (defun org-cyclic (N year month day &optional mark)
  4741. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4742. (org-no-warnings
  4743. (let ((calendar-date-style 'european) (european-calendar-style t))
  4744. (diary-cyclic N day month year mark))))
  4745. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4746. "Like `diary-block', but with fixed (ISO) order of arguments."
  4747. (org-no-warnings
  4748. (let ((calendar-date-style 'european) (european-calendar-style t))
  4749. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4750. (defun org-date (year month day &optional mark)
  4751. "Like `diary-date', but with fixed (ISO) order of arguments."
  4752. (org-no-warnings
  4753. (let ((calendar-date-style 'european) (european-calendar-style t))
  4754. (diary-date day month year mark))))
  4755. (defalias 'org-float 'diary-float)
  4756. ;; Define the` org-class' function
  4757. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4758. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4759. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4760. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4761. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4762. `holidays', then any date that is known by the Emacs calendar to be a
  4763. holiday will also be skipped."
  4764. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4765. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4766. (d (calendar-absolute-from-gregorian date)))
  4767. (and
  4768. (<= date1 d)
  4769. (<= d date2)
  4770. (= (calendar-day-of-week date) dayname)
  4771. (or (not skip-weeks)
  4772. (progn
  4773. (require 'cal-iso)
  4774. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4775. (not (and (memq 'holidays skip-weeks)
  4776. (calendar-check-holidays date)))
  4777. entry)))
  4778. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4779. "Like `org-class', but honor `calendar-date-style'.
  4780. The order of the first 2 times 3 arguments depends on the variable
  4781. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4782. So for American calendars, give this as MONTH DAY YEAR, for European as
  4783. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4784. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4785. is any number of ISO weeks in the block period for which the item should
  4786. be skipped.
  4787. This function is here only for backward compatibility and it is deprecated,
  4788. please use `org-class' instead."
  4789. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4790. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4791. (org-class
  4792. (nth 2 date1) (car date1) (nth 1 date1)
  4793. (nth 2 date2) (car date2) (nth 1 date2)
  4794. dayname skip-weeks)))
  4795. (make-obsolete 'org-diary-class 'org-class "")
  4796. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4797. (defalias 'org-get-closed 'org-agenda-get-progress)
  4798. (defun org-agenda-get-progress ()
  4799. "Return the logged TODO entries for agenda display."
  4800. (let* ((props (list 'mouse-face 'highlight
  4801. 'org-not-done-regexp org-not-done-regexp
  4802. 'org-todo-regexp org-todo-regexp
  4803. 'org-complex-heading-regexp org-complex-heading-regexp
  4804. 'help-echo
  4805. (format "mouse-2 or RET jump to org file %s"
  4806. (abbreviate-file-name buffer-file-name))))
  4807. (items (if (consp org-agenda-show-log-scoped)
  4808. org-agenda-show-log-scoped
  4809. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4810. '(clock)
  4811. org-agenda-log-mode-items)))
  4812. (parts
  4813. (delq nil
  4814. (list
  4815. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4816. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4817. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4818. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4819. (error "`org-agenda-log-mode-items' is empty")))
  4820. (regexp (concat
  4821. "\\(" parts-re "\\)"
  4822. " *\\["
  4823. (regexp-quote
  4824. (substring
  4825. (format-time-string
  4826. (car org-time-stamp-formats)
  4827. (apply 'encode-time ; DATE bound by calendar
  4828. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4829. 1 11))))
  4830. (org-agenda-search-headline-for-time nil)
  4831. marker hdmarker priority category org-category-pos tags closedp
  4832. statep clockp state ee txt extra timestr rest clocked)
  4833. (goto-char (point-min))
  4834. (while (re-search-forward regexp nil t)
  4835. (catch :skip
  4836. (org-agenda-skip)
  4837. (setq marker (org-agenda-new-marker (match-beginning 0))
  4838. closedp (equal (match-string 1) org-closed-string)
  4839. statep (equal (string-to-char (match-string 1)) ?-)
  4840. clockp (not (or closedp statep))
  4841. state (and statep (match-string 2))
  4842. category (org-get-category (match-beginning 0))
  4843. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4844. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4845. (when (string-match "\\]" timestr)
  4846. ;; substring should only run to end of time stamp
  4847. (setq rest (substring timestr (match-end 0))
  4848. timestr (substring timestr 0 (match-end 0)))
  4849. (if (and (not closedp) (not statep)
  4850. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4851. rest))
  4852. (progn (setq timestr (concat (substring timestr 0 -1)
  4853. "-" (match-string 1 rest) "]"))
  4854. (setq clocked (match-string 2 rest)))
  4855. (setq clocked "-")))
  4856. (save-excursion
  4857. (setq extra
  4858. (cond
  4859. ((not org-agenda-log-mode-add-notes) nil)
  4860. (statep
  4861. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4862. (match-string 1)))
  4863. (clockp
  4864. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4865. (match-string 1)))))
  4866. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4867. (setq txt org-agenda-no-heading-message)
  4868. (goto-char (match-beginning 0))
  4869. (setq hdmarker (org-agenda-new-marker)
  4870. tags (org-get-tags-at))
  4871. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4872. (setq txt (match-string 1))
  4873. (when extra
  4874. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4875. (setq txt (concat (substring txt 0 (match-beginning 1))
  4876. " - " extra " " (match-string 2 txt)))
  4877. (setq txt (concat txt " - " extra))))
  4878. (setq txt (org-agenda-format-item
  4879. (cond
  4880. (closedp "Closed: ")
  4881. (statep (concat "State: (" state ")"))
  4882. (t (concat "Clocked: (" clocked ")")))
  4883. txt category tags timestr)))
  4884. (setq priority 100000)
  4885. (org-add-props txt props
  4886. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4887. 'priority priority 'org-category category
  4888. 'org-category-position org-category-pos
  4889. 'type "closed" 'date date
  4890. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4891. (push txt ee))
  4892. (goto-char (point-at-eol))))
  4893. (nreverse ee)))
  4894. (defun org-agenda-show-clocking-issues ()
  4895. "Add overlays, showing issues with clocking.
  4896. See also the user option `org-agenda-clock-consistency-checks'."
  4897. (interactive)
  4898. (let* ((pl org-agenda-clock-consistency-checks)
  4899. (re (concat "^[ \t]*"
  4900. org-clock-string
  4901. "[ \t]+"
  4902. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4903. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4904. (tlstart 0.)
  4905. (tlend 0.)
  4906. (maxtime (org-hh:mm-string-to-minutes
  4907. (or (plist-get pl :max-duration) "24:00")))
  4908. (mintime (org-hh:mm-string-to-minutes
  4909. (or (plist-get pl :min-duration) 0)))
  4910. (maxgap (org-hh:mm-string-to-minutes
  4911. ;; default 30:00 means never complain
  4912. (or (plist-get pl :max-gap) "30:00")))
  4913. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4914. (plist-get pl :gap-ok-around)))
  4915. (def-face (or (plist-get pl :default-face)
  4916. '((:background "DarkRed") (:foreground "white"))))
  4917. issue face m te ts dt ov)
  4918. (goto-char (point-min))
  4919. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4920. (setq issue nil face def-face)
  4921. (catch 'next
  4922. (setq m (org-get-at-bol 'org-marker)
  4923. te nil ts nil)
  4924. (unless (and m (markerp m))
  4925. (setq issue "No valid clock line") (throw 'next t))
  4926. (org-with-point-at m
  4927. (save-excursion
  4928. (goto-char (point-at-bol))
  4929. (unless (looking-at re)
  4930. (error "No valid Clock line")
  4931. (throw 'next t))
  4932. (unless (match-end 3)
  4933. (setq issue "No end time"
  4934. face (or (plist-get pl :no-end-time-face) face))
  4935. (throw 'next t))
  4936. (setq ts (match-string 1)
  4937. te (match-string 3)
  4938. ts (org-float-time
  4939. (apply 'encode-time (org-parse-time-string ts)))
  4940. te (org-float-time
  4941. (apply 'encode-time (org-parse-time-string te)))
  4942. dt (- te ts))))
  4943. (cond
  4944. ((> dt (* 60 maxtime))
  4945. ;; a very long clocking chunk
  4946. (setq issue (format "Clocking interval is very long: %s"
  4947. (org-minutes-to-hh:mm-string
  4948. (floor (/ (float dt) 60.))))
  4949. face (or (plist-get pl :long-face) face)))
  4950. ((< dt (* 60 mintime))
  4951. ;; a very short clocking chunk
  4952. (setq issue (format "Clocking interval is very short: %s"
  4953. (org-minutes-to-hh:mm-string
  4954. (floor (/ (float dt) 60.))))
  4955. face (or (plist-get pl :short-face) face)))
  4956. ((and (> tlend 0) (< ts tlend))
  4957. ;; Two clock entries are overlapping
  4958. (setq issue (format "Clocking overlap: %d minutes"
  4959. (/ (- tlend ts) 60))
  4960. face (or (plist-get pl :overlap-face) face)))
  4961. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4962. ;; There is a gap, lets see if we need to report it
  4963. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4964. (setq issue (format "Clocking gap: %d minutes"
  4965. (/ (- ts tlend) 60))
  4966. face (or (plist-get pl :gap-face) face))))
  4967. (t nil)))
  4968. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4969. (when issue
  4970. ;; OK, there was some issue, add an overlay to show the issue
  4971. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4972. (overlay-put ov 'before-string
  4973. (concat
  4974. (org-add-props
  4975. (format "%-43s" (concat " " issue))
  4976. nil
  4977. 'face face)
  4978. "\n"))
  4979. (overlay-put ov 'evaporate t)))))
  4980. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4981. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4982. (catch 'exit
  4983. (unless ok-list
  4984. ;; there are no OK times for gaps...
  4985. (throw 'exit nil))
  4986. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4987. ;; This is more than 24 hours, so it is OK.
  4988. ;; because we have at least one OK time, that must be in the
  4989. ;; 24 hour interval.
  4990. (throw 'exit t))
  4991. ;; We have a shorter gap.
  4992. ;; Now we have to get the minute of the day when these times are
  4993. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4994. (t2dec (decode-time (seconds-to-time t2)))
  4995. ;; compute the minute on the day
  4996. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4997. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4998. (when (< min2 min1)
  4999. ;; if min2 is smaller than min1, this means it is on the next day.
  5000. ;; Wrap it to after midnight.
  5001. (setq min2 (+ min2 1440)))
  5002. ;; Now check if any of the OK times is in the gap
  5003. (mapc (lambda (x)
  5004. ;; Wrap the time to after midnight if necessary
  5005. (if (< x min1) (setq x (+ x 1440)))
  5006. ;; Check if in interval
  5007. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5008. ok-list)
  5009. ;; Nope, this gap is not OK
  5010. nil)))
  5011. (defun org-agenda-get-deadlines ()
  5012. "Return the deadline information for agenda display."
  5013. (let* ((props (list 'mouse-face 'highlight
  5014. 'org-not-done-regexp org-not-done-regexp
  5015. 'org-todo-regexp org-todo-regexp
  5016. 'org-complex-heading-regexp org-complex-heading-regexp
  5017. 'help-echo
  5018. (format "mouse-2 or RET jump to org file %s"
  5019. (abbreviate-file-name buffer-file-name))))
  5020. (regexp org-deadline-time-regexp)
  5021. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5022. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5023. d2 diff dfrac wdays pos pos1 category org-category-pos
  5024. tags suppress-prewarning ee txt head face s todo-state
  5025. show-all upcomingp donep timestr)
  5026. (goto-char (point-min))
  5027. (while (re-search-forward regexp nil t)
  5028. (setq suppress-prewarning nil)
  5029. (catch :skip
  5030. (org-agenda-skip)
  5031. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5032. (save-match-data
  5033. (string-match org-scheduled-time-regexp
  5034. (buffer-substring (point-at-bol)
  5035. (point-at-eol)))))
  5036. (setq suppress-prewarning
  5037. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5038. org-agenda-skip-deadline-prewarning-if-scheduled
  5039. 0)))
  5040. (setq s (match-string 1)
  5041. txt nil
  5042. pos (1- (match-beginning 1))
  5043. todo-state (save-match-data (org-get-todo-state))
  5044. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5045. (member todo-state
  5046. org-agenda-repeating-timestamp-show-all))
  5047. d2 (org-time-string-to-absolute
  5048. (match-string 1) d1 'past show-all
  5049. (current-buffer) pos)
  5050. diff (- d2 d1)
  5051. wdays (if suppress-prewarning
  5052. (let ((org-deadline-warning-days suppress-prewarning))
  5053. (org-get-wdays s))
  5054. (org-get-wdays s))
  5055. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5056. upcomingp (and todayp (> diff 0)))
  5057. ;; When to show a deadline in the calendar:
  5058. ;; If the expiration is within wdays warning time.
  5059. ;; Past-due deadlines are only shown on the current date
  5060. (if (and (or (and (<= diff wdays)
  5061. (and todayp (not org-agenda-only-exact-dates)))
  5062. (= diff 0)))
  5063. (save-excursion
  5064. ;; (setq todo-state (org-get-todo-state))
  5065. (setq donep (member todo-state org-done-keywords))
  5066. (if (and donep
  5067. (or org-agenda-skip-deadline-if-done
  5068. (not (= diff 0))))
  5069. (setq txt nil)
  5070. (setq category (org-get-category)
  5071. org-category-pos (get-text-property (point) 'org-category-position))
  5072. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5073. (setq txt org-agenda-no-heading-message)
  5074. (goto-char (match-end 0))
  5075. (setq pos1 (match-beginning 0))
  5076. (setq tags (org-get-tags-at pos1))
  5077. (setq head (buffer-substring-no-properties
  5078. (point)
  5079. (progn (skip-chars-forward "^\r\n")
  5080. (point))))
  5081. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5082. (setq timestr
  5083. (concat (substring s (match-beginning 1)) " "))
  5084. (setq timestr 'time))
  5085. (setq txt (org-agenda-format-item
  5086. (if (= diff 0)
  5087. (car org-agenda-deadline-leaders)
  5088. (if (functionp
  5089. (nth 1 org-agenda-deadline-leaders))
  5090. (funcall
  5091. (nth 1 org-agenda-deadline-leaders)
  5092. diff date)
  5093. (format (nth 1 org-agenda-deadline-leaders)
  5094. diff)))
  5095. head category tags
  5096. (if (not (= diff 0)) nil timestr)))))
  5097. (when txt
  5098. (setq face (org-agenda-deadline-face dfrac))
  5099. (org-add-props txt props
  5100. 'org-marker (org-agenda-new-marker pos)
  5101. 'org-hd-marker (org-agenda-new-marker pos1)
  5102. 'priority (+ (- diff)
  5103. (org-get-priority txt))
  5104. 'org-category category
  5105. 'org-category-position org-category-pos
  5106. 'todo-state todo-state
  5107. 'type (if upcomingp "upcoming-deadline" "deadline")
  5108. 'date (if upcomingp date d2)
  5109. 'face (if donep 'org-agenda-done face)
  5110. 'undone-face face 'done-face 'org-agenda-done)
  5111. (push txt ee))))))
  5112. (nreverse ee)))
  5113. (defun org-agenda-deadline-face (fraction)
  5114. "Return the face to displaying a deadline item.
  5115. FRACTION is what fraction of the head-warning time has passed."
  5116. (let ((faces org-agenda-deadline-faces) f)
  5117. (catch 'exit
  5118. (while (setq f (pop faces))
  5119. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5120. (defun org-agenda-get-scheduled (&optional deadline-results)
  5121. "Return the scheduled information for agenda display."
  5122. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5123. 'org-todo-regexp org-todo-regexp
  5124. 'org-complex-heading-regexp org-complex-heading-regexp
  5125. 'done-face 'org-agenda-done
  5126. 'mouse-face 'highlight
  5127. 'help-echo
  5128. (format "mouse-2 or RET jump to org file %s"
  5129. (abbreviate-file-name buffer-file-name))))
  5130. (regexp org-scheduled-time-regexp)
  5131. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5132. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5133. mm
  5134. (deadline-position-alist
  5135. (mapcar (lambda (a) (and (setq mm (get-text-property
  5136. 0 'org-hd-marker a))
  5137. (cons (marker-position mm) a)))
  5138. deadline-results))
  5139. d2 diff pos pos1 category org-category-pos tags donep
  5140. ee txt head pastschedp todo-state face timestr s habitp show-all
  5141. did-habit-check-p)
  5142. (goto-char (point-min))
  5143. (while (re-search-forward regexp nil t)
  5144. (catch :skip
  5145. (org-agenda-skip)
  5146. (setq s (match-string 1)
  5147. txt nil
  5148. pos (1- (match-beginning 1))
  5149. todo-state (save-match-data (org-get-todo-state))
  5150. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5151. (member todo-state
  5152. org-agenda-repeating-timestamp-show-all))
  5153. d2 (org-time-string-to-absolute
  5154. (match-string 1) d1 'past show-all
  5155. (current-buffer) pos)
  5156. diff (- d2 d1))
  5157. (setq pastschedp (and todayp (< diff 0)))
  5158. (setq did-habit-check-p nil)
  5159. ;; When to show a scheduled item in the calendar:
  5160. ;; If it is on or past the date.
  5161. (when (or (and (< diff 0)
  5162. (< (abs diff) org-scheduled-past-days)
  5163. (and todayp (not org-agenda-only-exact-dates)))
  5164. (= diff 0)
  5165. ;; org-is-habit-p uses org-entry-get, which is expansive
  5166. ;; so we go extra mile to only call it once
  5167. (and todayp
  5168. org-habit-show-all-today
  5169. (setq did-habit-check-p t)
  5170. (setq habitp (and (functionp 'org-is-habit-p)
  5171. (org-is-habit-p)))))
  5172. (save-excursion
  5173. (setq donep (member todo-state org-done-keywords))
  5174. (if (and donep
  5175. (or org-agenda-skip-scheduled-if-done
  5176. (not (= diff 0))
  5177. (and (functionp 'org-is-habit-p)
  5178. (org-is-habit-p))))
  5179. (setq txt nil)
  5180. (setq habitp (if did-habit-check-p habitp
  5181. (and (functionp 'org-is-habit-p)
  5182. (org-is-habit-p))))
  5183. (setq category (org-get-category)
  5184. org-category-pos (get-text-property (point) 'org-category-position))
  5185. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5186. (setq txt org-agenda-no-heading-message)
  5187. (goto-char (match-end 0))
  5188. (setq pos1 (match-beginning 0))
  5189. (if habitp
  5190. (if (or (not org-habit-show-habits)
  5191. (and (not todayp)
  5192. org-habit-show-habits-only-for-today))
  5193. (throw :skip nil))
  5194. (if (and
  5195. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5196. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5197. pastschedp))
  5198. (setq mm (assoc pos1 deadline-position-alist)))
  5199. (throw :skip nil)))
  5200. (setq tags (org-get-tags-at))
  5201. (setq head (buffer-substring-no-properties
  5202. (point)
  5203. (progn (skip-chars-forward "^\r\n") (point))))
  5204. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5205. (setq timestr
  5206. (concat (substring s (match-beginning 1)) " "))
  5207. (setq timestr 'time))
  5208. (setq txt (org-agenda-format-item
  5209. (if (= diff 0)
  5210. (car org-agenda-scheduled-leaders)
  5211. (format (nth 1 org-agenda-scheduled-leaders)
  5212. (- 1 diff)))
  5213. head category tags
  5214. (if (not (= diff 0)) nil timestr)
  5215. nil habitp))))
  5216. (when txt
  5217. (setq face
  5218. (cond
  5219. ((and (not habitp) pastschedp)
  5220. 'org-scheduled-previously)
  5221. (todayp 'org-scheduled-today)
  5222. (t 'org-scheduled))
  5223. habitp (and habitp (org-habit-parse-todo)))
  5224. (org-add-props txt props
  5225. 'undone-face face
  5226. 'face (if donep 'org-agenda-done face)
  5227. 'org-marker (org-agenda-new-marker pos)
  5228. 'org-hd-marker (org-agenda-new-marker pos1)
  5229. 'type (if pastschedp "past-scheduled" "scheduled")
  5230. 'date (if pastschedp d2 date)
  5231. 'priority (if habitp
  5232. (org-habit-get-priority habitp)
  5233. (+ 94 (- 5 diff) (org-get-priority txt)))
  5234. 'org-category category
  5235. 'org-category-position org-category-pos
  5236. 'org-habit-p habitp
  5237. 'todo-state todo-state)
  5238. (push txt ee))))))
  5239. (nreverse ee)))
  5240. (defun org-agenda-get-blocks ()
  5241. "Return the date-range information for agenda display."
  5242. (let* ((props (list 'face nil
  5243. 'org-not-done-regexp org-not-done-regexp
  5244. 'org-todo-regexp org-todo-regexp
  5245. 'org-complex-heading-regexp org-complex-heading-regexp
  5246. 'mouse-face 'highlight
  5247. 'help-echo
  5248. (format "mouse-2 or RET jump to org file %s"
  5249. (abbreviate-file-name buffer-file-name))))
  5250. (regexp org-tr-regexp)
  5251. (d0 (calendar-absolute-from-gregorian date))
  5252. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5253. todo-state tags pos head donep)
  5254. (goto-char (point-min))
  5255. (while (re-search-forward regexp nil t)
  5256. (catch :skip
  5257. (org-agenda-skip)
  5258. (setq pos (point))
  5259. (let ((start-time (match-string 1))
  5260. (end-time (match-string 2)))
  5261. (setq s1 (match-string 1)
  5262. s2 (match-string 2)
  5263. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5264. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5265. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5266. ;; Only allow days between the limits, because the normal
  5267. ;; date stamps will catch the limits.
  5268. (save-excursion
  5269. (setq todo-state (org-get-todo-state))
  5270. (setq donep (member todo-state org-done-keywords))
  5271. (if (and donep org-agenda-skip-timestamp-if-done)
  5272. (throw :skip t))
  5273. (setq marker (org-agenda-new-marker (point)))
  5274. (setq category (org-get-category)
  5275. org-category-pos (get-text-property (point) 'org-category-position))
  5276. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5277. (setq txt org-agenda-no-heading-message)
  5278. (goto-char (match-beginning 0))
  5279. (setq hdmarker (org-agenda-new-marker (point)))
  5280. (setq tags (org-get-tags-at))
  5281. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5282. (setq head (match-string 1))
  5283. (let ((remove-re
  5284. (if org-agenda-remove-timeranges-from-blocks
  5285. (concat
  5286. "<" (regexp-quote s1) ".*?>"
  5287. "--"
  5288. "<" (regexp-quote s2) ".*?>")
  5289. nil)))
  5290. (setq txt (org-agenda-format-item
  5291. (format
  5292. (nth (if (= d1 d2) 0 1)
  5293. org-agenda-timerange-leaders)
  5294. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5295. head category tags
  5296. (cond ((and (= d1 d0) (= d2 d0))
  5297. (concat "<" start-time ">--<" end-time ">"))
  5298. ((= d1 d0)
  5299. (concat "<" start-time ">"))
  5300. ((= d2 d0)
  5301. (concat "<" end-time ">"))
  5302. (t nil))
  5303. remove-re))))
  5304. (org-add-props txt props
  5305. 'org-marker marker 'org-hd-marker hdmarker
  5306. 'type "block" 'date date
  5307. 'todo-state todo-state
  5308. 'priority (org-get-priority txt) 'org-category category
  5309. 'org-category-position org-category-pos)
  5310. (push txt ee))))
  5311. (goto-char pos)))
  5312. ;; Sort the entries by expiration date.
  5313. (nreverse ee)))
  5314. ;;; Agenda presentation and sorting
  5315. (defvar org-prefix-has-time nil
  5316. "A flag, set by `org-compile-prefix-format'.
  5317. The flag is set if the currently compiled format contains a `%t'.")
  5318. (defvar org-prefix-has-tag nil
  5319. "A flag, set by `org-compile-prefix-format'.
  5320. The flag is set if the currently compiled format contains a `%T'.")
  5321. (defvar org-prefix-has-effort nil
  5322. "A flag, set by `org-compile-prefix-format'.
  5323. The flag is set if the currently compiled format contains a `%e'.")
  5324. (defvar org-prefix-category-length nil
  5325. "Used by `org-compile-prefix-format' to remember the category field width.")
  5326. (defvar org-prefix-category-max-length nil
  5327. "Used by `org-compile-prefix-format' to remember the category field width.")
  5328. (defun org-agenda-get-category-icon (category)
  5329. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5330. (dolist (entry org-agenda-category-icon-alist)
  5331. (when (org-string-match-p (car entry) category)
  5332. (if (listp (cadr entry))
  5333. (return (cadr entry))
  5334. (return (apply 'create-image (cdr entry)))))))
  5335. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5336. remove-re habitp)
  5337. "Format TXT to be inserted into the agenda buffer.
  5338. In particular, it adds the prefix and corresponding text properties. EXTRA
  5339. must be a string and replaces the `%s' specifier in the prefix format.
  5340. CATEGORY (string, symbol or nil) may be used to overrule the default
  5341. category taken from local variable or file name. It will replace the `%c'
  5342. specifier in the format. DOTIME, when non-nil, indicates that a
  5343. time-of-day should be extracted from TXT for sorting of this entry, and for
  5344. the `%t' specifier in the format. When DOTIME is a string, this string is
  5345. searched for a time before TXT is. TAGS can be the tags of the headline.
  5346. Any match of REMOVE-RE will be removed from TXT."
  5347. ;; We keep the org-prefix-* variable values along with a compiled
  5348. ;; formatter, so that multiple agendas existing at the same time, do
  5349. ;; not step on each other toes.
  5350. ;;
  5351. ;; It was inconvenient to make these variables buffer local in
  5352. ;; Agenda buffers, because this function expects to be called with
  5353. ;; the buffer where item comes from being current, and not agenda
  5354. ;; buffer
  5355. (let* ((bindings (car org-prefix-format-compiled))
  5356. (formatter (cadr org-prefix-format-compiled)))
  5357. (loop for (var value) in bindings
  5358. do (set var value))
  5359. (save-match-data
  5360. ;; Diary entries sometimes have extra whitespace at the beginning
  5361. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5362. ;; Fix the tags part in txt
  5363. (setq txt (org-agenda-fix-displayed-tags
  5364. txt tags
  5365. org-agenda-show-inherited-tags
  5366. org-agenda-hide-tags-regexp))
  5367. (let* ((category (or category
  5368. (if (stringp org-category)
  5369. org-category
  5370. (and org-category (symbol-name org-category)))
  5371. (if buffer-file-name
  5372. (file-name-sans-extension
  5373. (file-name-nondirectory buffer-file-name))
  5374. "")))
  5375. (category-icon (org-agenda-get-category-icon category))
  5376. (category-icon (if category-icon
  5377. (propertize " " 'display category-icon)
  5378. ""))
  5379. ;; time, tag, effort are needed for the eval of the prefix format
  5380. (tag (if tags (nth (1- (length tags)) tags) ""))
  5381. time effort neffort
  5382. (ts (if dotime (concat
  5383. (if (stringp dotime) dotime "")
  5384. (and org-agenda-search-headline-for-time txt))))
  5385. (time-of-day (and dotime (org-get-time-of-day ts)))
  5386. stamp plain s0 s1 s2 rtn srp l
  5387. duration thecategory)
  5388. (and (derived-mode-p 'org-mode) buffer-file-name
  5389. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5390. (when (and dotime time-of-day)
  5391. ;; Extract starting and ending time and move them to prefix
  5392. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5393. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5394. (setq s0 (match-string 0 ts)
  5395. srp (and stamp (match-end 3))
  5396. s1 (match-string (if plain 1 2) ts)
  5397. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5398. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5399. ;; them, we might want to remove them there to avoid duplication.
  5400. ;; The user can turn this off with a variable.
  5401. (if (and org-prefix-has-time
  5402. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5403. (string-match (concat (regexp-quote s0) " *") txt)
  5404. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5405. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5406. (= (match-beginning 0) 0)
  5407. t))
  5408. (setq txt (replace-match "" nil nil txt))))
  5409. ;; Normalize the time(s) to 24 hour
  5410. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5411. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5412. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5413. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5414. (setq s2
  5415. (org-minutes-to-hh:mm-string
  5416. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5417. ;; Compute the duration
  5418. (when s2
  5419. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5420. (org-hh:mm-string-to-minutes s1)))))
  5421. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5422. txt)
  5423. ;; Tags are in the string
  5424. (if (or (eq org-agenda-remove-tags t)
  5425. (and org-agenda-remove-tags
  5426. org-prefix-has-tag))
  5427. (setq txt (replace-match "" t t txt))
  5428. (setq txt (replace-match
  5429. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5430. (match-string 2 txt))
  5431. t t txt))))
  5432. (when (derived-mode-p 'org-mode)
  5433. (setq effort
  5434. (condition-case nil
  5435. (org-get-effort
  5436. (or (get-text-property 0 'org-hd-marker txt)
  5437. (get-text-property 0 'org-marker txt)))
  5438. (error nil)))
  5439. (when effort
  5440. (setq neffort (org-duration-string-to-minutes effort)
  5441. effort (setq effort (concat "[" effort "]")))))
  5442. ;; prevent erroring out with %e format when there is no effort
  5443. (or effort (setq effort ""))
  5444. (when remove-re
  5445. (while (string-match remove-re txt)
  5446. (setq txt (replace-match "" t t txt))))
  5447. ;; Set org-heading property on `txt' to mark the start of the
  5448. ;; heading.
  5449. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5450. ;; Prepare the variables needed in the eval of the compiled format
  5451. (setq time (cond (s2 (concat
  5452. (org-agenda-time-of-day-to-ampm-maybe s1)
  5453. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5454. (if org-agenda-timegrid-use-ampm " ")))
  5455. (s1 (concat
  5456. (org-agenda-time-of-day-to-ampm-maybe s1)
  5457. (if org-agenda-timegrid-use-ampm
  5458. "........ "
  5459. "......")))
  5460. (t ""))
  5461. extra (or (and (not habitp) extra) "")
  5462. category (if (symbolp category) (symbol-name category) category)
  5463. thecategory (copy-sequence category))
  5464. (if (string-match org-bracket-link-regexp category)
  5465. (progn
  5466. (setq l (if (match-end 3)
  5467. (- (match-end 3) (match-beginning 3))
  5468. (- (match-end 1) (match-beginning 1))))
  5469. (when (< l (or org-prefix-category-length 0))
  5470. (setq category (copy-sequence category))
  5471. (org-add-props category nil
  5472. 'extra-space (make-string
  5473. (- org-prefix-category-length l 1) ?\ ))))
  5474. (if (and org-prefix-category-max-length
  5475. (>= (length category) org-prefix-category-max-length))
  5476. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5477. ;; Evaluate the compiled format
  5478. (setq rtn (concat (eval formatter) txt))
  5479. ;; And finally add the text properties
  5480. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5481. (org-add-props rtn nil
  5482. 'org-category (if thecategory (downcase thecategory) category)
  5483. 'tags (mapcar 'org-downcase-keep-props tags)
  5484. 'org-highest-priority org-highest-priority
  5485. 'org-lowest-priority org-lowest-priority
  5486. 'time-of-day time-of-day
  5487. 'duration duration
  5488. 'effort effort
  5489. 'effort-minutes neffort
  5490. 'txt txt
  5491. 'time time
  5492. 'extra extra
  5493. 'format org-prefix-format-compiled
  5494. 'dotime dotime)))))
  5495. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5496. "Remove tags string from TXT, and add a modified list of tags.
  5497. The modified list may contain inherited tags, and tags matched by
  5498. `org-agenda-hide-tags-regexp' will be removed."
  5499. (when (or add-inherited hide-re)
  5500. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5501. (setq txt (substring txt 0 (match-beginning 0))))
  5502. (setq tags
  5503. (delq nil
  5504. (mapcar (lambda (tg)
  5505. (if (or (and hide-re (string-match hide-re tg))
  5506. (and (not add-inherited)
  5507. (get-text-property 0 'inherited tg)))
  5508. nil
  5509. tg))
  5510. tags)))
  5511. (when tags
  5512. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5513. i)
  5514. (setq txt (concat txt " :"
  5515. (mapconcat
  5516. (lambda (x)
  5517. (setq i (get-text-property 0 'inherited x))
  5518. (if (and have-i (not i))
  5519. (progn
  5520. (setq have-i nil)
  5521. (concat ":" x))
  5522. x))
  5523. tags ":")
  5524. (if have-i "::" ":"))))))
  5525. txt)
  5526. (defun org-downcase-keep-props (s)
  5527. (let ((props (text-properties-at 0 s)))
  5528. (setq s (downcase s))
  5529. (add-text-properties 0 (length s) props s)
  5530. s))
  5531. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5532. (defvar org-agenda-sorting-strategy-selected nil)
  5533. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5534. (catch 'exit
  5535. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5536. ((and todayp (member 'today (car org-agenda-time-grid))))
  5537. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5538. ((member 'weekly (car org-agenda-time-grid)))
  5539. (t (throw 'exit list)))
  5540. (let* ((have (delq nil (mapcar
  5541. (lambda (x) (get-text-property 1 'time-of-day x))
  5542. list)))
  5543. (string (nth 1 org-agenda-time-grid))
  5544. (gridtimes (nth 2 org-agenda-time-grid))
  5545. (req (car org-agenda-time-grid))
  5546. (remove (member 'remove-match req))
  5547. new time)
  5548. (if (and (member 'require-timed req) (not have))
  5549. ;; don't show empty grid
  5550. (throw 'exit list))
  5551. (while (setq time (pop gridtimes))
  5552. (unless (and remove (member time have))
  5553. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5554. (push (org-agenda-format-item
  5555. nil string "" nil
  5556. (concat (substring time 0 -2) ":" (substring time -2)))
  5557. new)
  5558. (put-text-property
  5559. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5560. (when (and todayp org-agenda-show-current-time-in-grid)
  5561. (push (org-agenda-format-item
  5562. nil
  5563. org-agenda-current-time-string
  5564. "" nil
  5565. (format-time-string "%H:%M "))
  5566. new)
  5567. (put-text-property
  5568. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5569. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5570. (append new list)
  5571. (append list new)))))
  5572. (defun org-compile-prefix-format (key)
  5573. "Compile the prefix format into a Lisp form that can be evaluated.
  5574. The resulting form and associated variable bindings is returned
  5575. and stored in the variable `org-prefix-format-compiled'."
  5576. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5577. org-prefix-category-length nil
  5578. org-prefix-has-effort nil)
  5579. (let ((s (cond
  5580. ((stringp org-agenda-prefix-format)
  5581. org-agenda-prefix-format)
  5582. ((assq key org-agenda-prefix-format)
  5583. (cdr (assq key org-agenda-prefix-format)))
  5584. (t " %-12:c%?-12t% s")))
  5585. (start 0)
  5586. varform vars var e c f opt)
  5587. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5588. s start)
  5589. (setq var (or (cdr (assoc (match-string 4 s)
  5590. '(("c" . category) ("t" . time) ("s" . extra)
  5591. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5592. 'eval)
  5593. c (or (match-string 3 s) "")
  5594. opt (match-beginning 1)
  5595. start (1+ (match-beginning 0)))
  5596. (if (equal var 'time) (setq org-prefix-has-time t))
  5597. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5598. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5599. (setq f (concat "%" (match-string 2 s) "s"))
  5600. (when (equal var 'category)
  5601. (setq org-prefix-category-length
  5602. (floor (abs (string-to-number (match-string 2 s)))))
  5603. (setq org-prefix-category-max-length
  5604. (let ((x (match-string 2 s)))
  5605. (save-match-data
  5606. (if (string-match "\\.[0-9]+" x)
  5607. (string-to-number (substring (match-string 0 x) 1)))))))
  5608. (if (eq var 'eval)
  5609. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5610. (if opt
  5611. (setq varform
  5612. `(if (equal "" ,var)
  5613. ""
  5614. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5615. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5616. (setq s (replace-match "%s" t nil s))
  5617. (push varform vars))
  5618. (setq vars (nreverse vars))
  5619. (with-current-buffer org-agenda-buffer
  5620. (setq org-prefix-format-compiled
  5621. (list
  5622. `((org-prefix-has-time ,org-prefix-has-time)
  5623. (org-prefix-has-tag ,org-prefix-has-tag)
  5624. (org-prefix-category-length ,org-prefix-category-length)
  5625. (org-prefix-has-effort ,org-prefix-has-effort))
  5626. `(format ,s ,@vars))))))
  5627. (defun org-set-sorting-strategy (key)
  5628. (if (symbolp (car org-agenda-sorting-strategy))
  5629. ;; the old format
  5630. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5631. (setq org-agenda-sorting-strategy-selected
  5632. (or (cdr (assq key org-agenda-sorting-strategy))
  5633. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5634. '(time-up category-keep priority-down)))))
  5635. (defun org-get-time-of-day (s &optional string mod24)
  5636. "Check string S for a time of day.
  5637. If found, return it as a military time number between 0 and 2400.
  5638. If not found, return nil.
  5639. The optional STRING argument forces conversion into a 5 character wide string
  5640. HH:MM."
  5641. (save-match-data
  5642. (when
  5643. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5644. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5645. (let* ((h (string-to-number (match-string 1 s)))
  5646. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5647. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5648. (am-p (equal ampm "am"))
  5649. (h1 (cond ((not ampm) h)
  5650. ((= h 12) (if am-p 0 12))
  5651. (t (+ h (if am-p 0 12)))))
  5652. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5653. (mod h1 24) h1))
  5654. (t0 (+ (* 100 h2) m))
  5655. (t1 (concat (if (>= h1 24) "+" " ")
  5656. (if (and org-agenda-time-leading-zero
  5657. (< t0 1000)) "0" "")
  5658. (if (< t0 100) "0" "")
  5659. (if (< t0 10) "0" "")
  5660. (int-to-string t0))))
  5661. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5662. (defvar org-agenda-before-sorting-filter-function nil
  5663. "Function to be applied to agenda items prior to sorting.
  5664. Prior to sorting also means just before they are inserted into the agenda.
  5665. To aid sorting, you may revisit the original entries and add more text
  5666. properties which will later be used by the sorting functions.
  5667. The function should take a string argument, an agenda line.
  5668. It has access to the text properties in that line, which contain among
  5669. other things, the property `org-hd-marker' that points to the entry
  5670. where the line comes from. Note that not all lines going into the agenda
  5671. have this property, only most.
  5672. The function should return the modified string. It is probably best
  5673. to ONLY change text properties.
  5674. You can also use this function as a filter, by returning nil for lines
  5675. you don't want to have in the agenda at all. For this application, you
  5676. could bind the variable in the options section of a custom command.")
  5677. (defun org-finalize-agenda-entries (list &optional nosort)
  5678. "Sort and concatenate the agenda items."
  5679. (setq list (mapcar 'org-agenda-highlight-todo list))
  5680. (if nosort
  5681. list
  5682. (when org-agenda-before-sorting-filter-function
  5683. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5684. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5685. (defun org-agenda-highlight-todo (x)
  5686. (let ((org-done-keywords org-done-keywords-for-agenda)
  5687. (case-fold-search nil)
  5688. re)
  5689. (if (eq x 'line)
  5690. (save-excursion
  5691. (beginning-of-line 1)
  5692. (setq re (org-get-at-bol 'org-todo-regexp))
  5693. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5694. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5695. (add-text-properties (match-beginning 0) (match-end 1)
  5696. (list 'face (org-get-todo-face 1)))
  5697. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5698. (delete-region (match-beginning 1) (1- (match-end 0)))
  5699. (goto-char (match-beginning 1))
  5700. (insert (format org-agenda-todo-keyword-format s)))))
  5701. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5702. (setq re (get-text-property 0 'org-todo-regexp x))
  5703. (when (and re
  5704. ;; Test `pl' because if there's no heading content,
  5705. ;; there's no point matching to highlight. Note
  5706. ;; that if we didn't test `pl' first, and there
  5707. ;; happened to be no keyword from `org-todo-regexp'
  5708. ;; on this heading line, then the `equal' comparison
  5709. ;; afterwards would spuriously succeed in the case
  5710. ;; where `pl' is nil -- causing an args-out-of-range
  5711. ;; error when we try to add text properties to text
  5712. ;; that isn't there.
  5713. pl
  5714. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5715. x pl) pl))
  5716. (add-text-properties
  5717. (or (match-end 1) (match-end 0)) (match-end 0)
  5718. (list 'face (org-get-todo-face (match-string 2 x)))
  5719. x)
  5720. (when (match-end 1)
  5721. (setq x (concat (substring x 0 (match-end 1))
  5722. (format org-agenda-todo-keyword-format
  5723. (match-string 2 x))
  5724. (org-add-props " " (text-properties-at 0 x))
  5725. (substring x (match-end 3)))))))
  5726. x)))
  5727. (defsubst org-cmp-priority (a b)
  5728. "Compare the priorities of string A and B."
  5729. (let ((pa (or (get-text-property 1 'priority a) 0))
  5730. (pb (or (get-text-property 1 'priority b) 0)))
  5731. (cond ((> pa pb) +1)
  5732. ((< pa pb) -1)
  5733. (t nil))))
  5734. (defsubst org-cmp-effort (a b)
  5735. "Compare the effort values of string A and B."
  5736. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5737. (ea (or (get-text-property 1 'effort-minutes a) def))
  5738. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5739. (cond ((> ea eb) +1)
  5740. ((< ea eb) -1)
  5741. (t nil))))
  5742. (defsubst org-cmp-category (a b)
  5743. "Compare the string values of categories of strings A and B."
  5744. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5745. (cb (or (get-text-property 1 'org-category b) "")))
  5746. (cond ((string-lessp ca cb) -1)
  5747. ((string-lessp cb ca) +1)
  5748. (t nil))))
  5749. (defsubst org-cmp-todo-state (a b)
  5750. "Compare the todo states of strings A and B."
  5751. (let* ((ma (or (get-text-property 1 'org-marker a)
  5752. (get-text-property 1 'org-hd-marker a)))
  5753. (mb (or (get-text-property 1 'org-marker b)
  5754. (get-text-property 1 'org-hd-marker b)))
  5755. (fa (and ma (marker-buffer ma)))
  5756. (fb (and mb (marker-buffer mb)))
  5757. (todo-kwds
  5758. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5759. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5760. (ta (or (get-text-property 1 'todo-state a) ""))
  5761. (tb (or (get-text-property 1 'todo-state b) ""))
  5762. (la (- (length (member ta todo-kwds))))
  5763. (lb (- (length (member tb todo-kwds))))
  5764. (donepa (member ta org-done-keywords-for-agenda))
  5765. (donepb (member tb org-done-keywords-for-agenda)))
  5766. (cond ((and donepa (not donepb)) -1)
  5767. ((and (not donepa) donepb) +1)
  5768. ((< la lb) -1)
  5769. ((< lb la) +1)
  5770. (t nil))))
  5771. (defsubst org-cmp-alpha (a b)
  5772. "Compare the headlines, alphabetically."
  5773. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5774. (plb (text-property-any 0 (length b) 'org-heading t b))
  5775. (ta (and pla (substring a pla)))
  5776. (tb (and plb (substring b plb))))
  5777. (when pla
  5778. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5779. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5780. (setq ta (substring ta (match-end 0))))
  5781. (setq ta (downcase ta)))
  5782. (when plb
  5783. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5784. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5785. (setq tb (substring tb (match-end 0))))
  5786. (setq tb (downcase tb)))
  5787. (cond ((not ta) +1)
  5788. ((not tb) -1)
  5789. ((string-lessp ta tb) -1)
  5790. ((string-lessp tb ta) +1)
  5791. (t nil))))
  5792. (defsubst org-cmp-tag (a b)
  5793. "Compare the string values of the first tags of A and B."
  5794. (let ((ta (car (last (get-text-property 1 'tags a))))
  5795. (tb (car (last (get-text-property 1 'tags b)))))
  5796. (cond ((not ta) +1)
  5797. ((not tb) -1)
  5798. ((string-lessp ta tb) -1)
  5799. ((string-lessp tb ta) +1)
  5800. (t nil))))
  5801. (defsubst org-cmp-time (a b)
  5802. "Compare the time-of-day values of strings A and B."
  5803. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5804. (ta (or (get-text-property 1 'time-of-day a) def))
  5805. (tb (or (get-text-property 1 'time-of-day b) def)))
  5806. (cond ((< ta tb) -1)
  5807. ((< tb ta) +1)
  5808. (t nil))))
  5809. (defsubst org-cmp-habit-p (a b)
  5810. "Compare the todo states of strings A and B."
  5811. (let ((ha (get-text-property 1 'org-habit-p a))
  5812. (hb (get-text-property 1 'org-habit-p b)))
  5813. (cond ((and ha (not hb)) -1)
  5814. ((and (not ha) hb) +1)
  5815. (t nil))))
  5816. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5817. (defun org-entries-lessp (a b)
  5818. "Predicate for sorting agenda entries."
  5819. ;; The following variables will be used when the form is evaluated.
  5820. ;; So even though the compiler complains, keep them.
  5821. (let* ((ss org-agenda-sorting-strategy-selected)
  5822. (time-up (and (org-em 'time-up 'time-down ss)
  5823. (org-cmp-time a b)))
  5824. (time-down (if time-up (- time-up) nil))
  5825. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5826. (org-cmp-priority a b)))
  5827. (priority-down (if priority-up (- priority-up) nil))
  5828. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5829. (org-cmp-effort a b)))
  5830. (effort-down (if effort-up (- effort-up) nil))
  5831. (category-up (and (or (org-em 'category-up 'category-down ss)
  5832. (memq 'category-keep ss))
  5833. (org-cmp-category a b)))
  5834. (category-down (if category-up (- category-up) nil))
  5835. (category-keep (if category-up +1 nil))
  5836. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5837. (org-cmp-tag a b)))
  5838. (tag-down (if tag-up (- tag-up) nil))
  5839. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5840. (org-cmp-todo-state a b)))
  5841. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5842. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5843. (org-cmp-habit-p a b)))
  5844. (habit-down (if habit-up (- habit-up) nil))
  5845. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5846. (org-cmp-alpha a b)))
  5847. (alpha-down (if alpha-up (- alpha-up) nil))
  5848. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5849. user-defined-up user-defined-down)
  5850. (if (and need-user-cmp org-agenda-cmp-user-defined
  5851. (functionp org-agenda-cmp-user-defined))
  5852. (setq user-defined-up
  5853. (funcall org-agenda-cmp-user-defined a b)
  5854. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5855. (cdr (assoc
  5856. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5857. '((-1 . t) (1 . nil) (nil . nil))))))
  5858. ;;; Agenda restriction lock
  5859. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5860. "Overlay to mark the headline to which agenda commands are restricted.")
  5861. (overlay-put org-agenda-restriction-lock-overlay
  5862. 'face 'org-agenda-restriction-lock)
  5863. (overlay-put org-agenda-restriction-lock-overlay
  5864. 'help-echo "Agendas are currently limited to this subtree.")
  5865. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5866. (defun org-agenda-set-restriction-lock (&optional type)
  5867. "Set restriction lock for agenda, to current subtree or file.
  5868. Restriction will be the file if TYPE is `file', or if type is the
  5869. universal prefix '(4), or if the cursor is before the first headline
  5870. in the file. Otherwise, restriction will be to the current subtree."
  5871. (interactive "P")
  5872. (and (equal type '(4)) (setq type 'file))
  5873. (setq type (cond
  5874. (type type)
  5875. ((org-at-heading-p) 'subtree)
  5876. ((condition-case nil (org-back-to-heading t) (error nil))
  5877. 'subtree)
  5878. (t 'file)))
  5879. (if (eq type 'subtree)
  5880. (progn
  5881. (setq org-agenda-restrict t)
  5882. (setq org-agenda-overriding-restriction 'subtree)
  5883. (put 'org-agenda-files 'org-restrict
  5884. (list (buffer-file-name (buffer-base-buffer))))
  5885. (org-back-to-heading t)
  5886. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5887. (move-marker org-agenda-restrict-begin (point))
  5888. (move-marker org-agenda-restrict-end
  5889. (save-excursion (org-end-of-subtree t)))
  5890. (message "Locking agenda restriction to subtree"))
  5891. (put 'org-agenda-files 'org-restrict
  5892. (list (buffer-file-name (buffer-base-buffer))))
  5893. (setq org-agenda-restrict nil)
  5894. (setq org-agenda-overriding-restriction 'file)
  5895. (move-marker org-agenda-restrict-begin nil)
  5896. (move-marker org-agenda-restrict-end nil)
  5897. (message "Locking agenda restriction to file"))
  5898. (setq current-prefix-arg nil)
  5899. (org-agenda-maybe-redo))
  5900. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5901. "Remove the agenda restriction lock."
  5902. (interactive "P")
  5903. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5904. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5905. (setq org-agenda-overriding-restriction nil)
  5906. (setq org-agenda-restrict nil)
  5907. (put 'org-agenda-files 'org-restrict nil)
  5908. (move-marker org-agenda-restrict-begin nil)
  5909. (move-marker org-agenda-restrict-end nil)
  5910. (setq current-prefix-arg nil)
  5911. (message "Agenda restriction lock removed")
  5912. (or noupdate (org-agenda-maybe-redo)))
  5913. (defun org-agenda-maybe-redo ()
  5914. "If there is any window showing the agenda view, update it."
  5915. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5916. (w0 (selected-window)))
  5917. (when w
  5918. (select-window w)
  5919. (org-agenda-redo)
  5920. (select-window w0)
  5921. (if org-agenda-overriding-restriction
  5922. (message "Agenda view shifted to new %s restriction"
  5923. org-agenda-overriding-restriction)
  5924. (message "Agenda restriction lock removed")))))
  5925. ;;; Agenda commands
  5926. (defun org-agenda-check-type (error &rest types)
  5927. "Check if agenda buffer is of allowed type.
  5928. If ERROR is non-nil, throw an error, otherwise just return nil."
  5929. (if (memq org-agenda-type types)
  5930. t
  5931. (if error
  5932. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5933. nil)))
  5934. (defun org-agenda-Quit (&optional arg)
  5935. "Exit agenda by removing the window or the buffer."
  5936. (interactive)
  5937. (if org-agenda-columns-active
  5938. (org-columns-quit)
  5939. (let ((buf (current-buffer)))
  5940. (if (eq org-agenda-window-setup 'other-frame)
  5941. (progn
  5942. (org-agenda-reset-markers)
  5943. (kill-buffer buf)
  5944. (org-columns-remove-overlays)
  5945. (setq org-agenda-archives-mode nil)
  5946. (delete-frame))
  5947. (and (not (eq org-agenda-window-setup 'current-window))
  5948. (not (one-window-p))
  5949. (delete-window))
  5950. (org-agenda-reset-markers)
  5951. (kill-buffer buf)
  5952. (org-columns-remove-overlays)
  5953. (setq org-agenda-archives-mode nil)))
  5954. ;; Maybe restore the pre-agenda window configuration.
  5955. (and org-agenda-restore-windows-after-quit
  5956. (not (eq org-agenda-window-setup 'other-frame))
  5957. org-pre-agenda-window-conf
  5958. (set-window-configuration org-pre-agenda-window-conf))))
  5959. (defun org-agenda-quit ()
  5960. "Exit agenda by killing agenda buffer or burying it when
  5961. `org-agenda-sticky' is non-NIL"
  5962. (interactive)
  5963. (if org-agenda-columns-active
  5964. (org-columns-quit)
  5965. (if org-agenda-sticky
  5966. (let ((buf (current-buffer)))
  5967. (if (eq org-agenda-window-setup 'other-frame)
  5968. (progn
  5969. (delete-frame))
  5970. (and (not (eq org-agenda-window-setup 'current-window))
  5971. (not (one-window-p))
  5972. (delete-window)))
  5973. (with-current-buffer buf
  5974. (bury-buffer)
  5975. ;; Maybe restore the pre-agenda window configuration.
  5976. (and org-agenda-restore-windows-after-quit
  5977. (not (eq org-agenda-window-setup 'other-frame))
  5978. org-pre-agenda-window-conf
  5979. (set-window-configuration org-pre-agenda-window-conf))))
  5980. (org-agenda-Quit))))
  5981. (defun org-agenda-exit ()
  5982. "Exit agenda by removing the window or the buffer.
  5983. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5984. Org-mode buffers visited directly by the user will not be touched."
  5985. (interactive)
  5986. (org-release-buffers org-agenda-new-buffers)
  5987. (setq org-agenda-new-buffers nil)
  5988. (org-agenda-Quit))
  5989. (defun org-agenda-kill-all-agenda-buffers ()
  5990. "Kill all buffers in `org-agena-mode'.
  5991. This is used when toggling sticky agendas. You can also explicitly invoke it
  5992. with `C-c a C-k'."
  5993. (interactive)
  5994. (let (blist)
  5995. (dolist (buf (buffer-list))
  5996. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5997. (push buf blist)))
  5998. (mapc 'kill-buffer blist)))
  5999. (defun org-agenda-execute (arg)
  6000. "Execute another agenda command, keeping same window.
  6001. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6002. in the agenda."
  6003. (interactive "P")
  6004. (let ((org-agenda-window-setup 'current-window))
  6005. (org-agenda arg)))
  6006. (defun org-agenda-redo ()
  6007. "Rebuild Agenda.
  6008. When this is the global TODO list, a prefix argument will be interpreted."
  6009. (interactive)
  6010. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  6011. (org-agenda-sticky nil)
  6012. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6013. org-agenda-buffer-name))
  6014. (org-agenda-keep-modes t)
  6015. (tag-filter org-agenda-tag-filter)
  6016. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6017. (top-cat-filter org-agenda-top-category-filter)
  6018. (cat-filter org-agenda-category-filter)
  6019. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6020. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6021. (cols org-agenda-columns-active)
  6022. (line (org-current-line))
  6023. (window-line (- line (org-current-line (window-start))))
  6024. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  6025. (put 'org-agenda-tag-filter :preset-filter nil)
  6026. (put 'org-agenda-category-filter :preset-filter nil)
  6027. (and cols (org-columns-quit))
  6028. (message "Rebuilding agenda buffer...")
  6029. (org-let lprops '(eval org-agenda-redo-command))
  6030. (setq org-agenda-undo-list nil
  6031. org-agenda-pending-undo-list nil)
  6032. (message "Rebuilding agenda buffer...done")
  6033. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6034. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6035. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6036. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6037. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6038. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6039. (org-goto-line line)
  6040. (recenter window-line)))
  6041. (defvar org-global-tags-completion-table nil)
  6042. (defvar org-agenda-filter-form nil)
  6043. (defvar org-agenda-filtered-by-category nil)
  6044. (defun org-agenda-filter-by-category (strip)
  6045. "Keep only those lines in the agenda buffer that have a specific category.
  6046. The category is that of the current line."
  6047. (interactive "P")
  6048. (if org-agenda-filtered-by-category
  6049. (org-agenda-filter-show-all-cat)
  6050. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6051. (if cat (org-agenda-filter-apply
  6052. (list (concat (if strip "-" "+") cat)) 'category)
  6053. (error "No category at point")))))
  6054. (defun org-find-top-category (&optional pos)
  6055. (save-excursion
  6056. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6057. (if pos (goto-char pos))
  6058. ;; Skip up to the topmost parent
  6059. (while (ignore-errors (outline-up-heading 1) t))
  6060. (ignore-errors
  6061. (nth 4 (org-heading-components))))))
  6062. (defvar org-agenda-filtered-by-top-category nil)
  6063. (defun org-agenda-filter-by-top-category (strip)
  6064. "Keep only those lines in the agenda buffer that have a specific category.
  6065. The category is that of the current line."
  6066. (interactive "P")
  6067. (if org-agenda-filtered-by-top-category
  6068. (progn
  6069. (setq org-agenda-filtered-by-top-category nil
  6070. org-agenda-top-category-filter nil)
  6071. (org-agenda-filter-show-all-cat))
  6072. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6073. (if cat (org-agenda-filter-top-category-apply cat strip)
  6074. (error "No top-level category at point")))))
  6075. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6076. "Keep only those lines in the agenda buffer that have a specific tag.
  6077. The tag is selected with its fast selection letter, as configured.
  6078. With prefix argument STRIP, remove all lines that do have the tag.
  6079. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6080. used to narrow the search - the interactive user can also press `-' or `+'
  6081. to switch to narrowing."
  6082. (interactive "P")
  6083. (let* ((alist org-tag-alist-for-agenda)
  6084. (tag-chars (mapconcat
  6085. (lambda (x) (if (and (not (symbolp (car x)))
  6086. (cdr x))
  6087. (char-to-string (cdr x))
  6088. ""))
  6089. alist ""))
  6090. (efforts (org-split-string
  6091. (or (cdr (assoc (concat org-effort-property "_ALL")
  6092. org-global-properties))
  6093. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6094. "")))
  6095. (effort-op org-agenda-filter-effort-default-operator)
  6096. (effort-prompt "")
  6097. (inhibit-read-only t)
  6098. (current org-agenda-tag-filter)
  6099. maybe-refresh a n tag)
  6100. (unless char
  6101. (message
  6102. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6103. (if narrow "Narrow" "Filter") tag-chars
  6104. (if org-agenda-auto-exclude-function "[RET], " ""))
  6105. (setq char (read-char-exclusive)))
  6106. (when (member char '(?+ ?-))
  6107. ;; Narrowing down
  6108. (cond ((equal char ?-) (setq strip t narrow t))
  6109. ((equal char ?+) (setq strip nil narrow t)))
  6110. (message
  6111. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6112. (setq char (read-char-exclusive)))
  6113. (when (member char '(?< ?> ?= ??))
  6114. ;; An effort operator
  6115. (setq effort-op (char-to-string char))
  6116. (setq alist nil) ; to make sure it will be interpreted as effort.
  6117. (unless (equal char ??)
  6118. (loop for i from 0 to 9 do
  6119. (setq effort-prompt
  6120. (concat
  6121. effort-prompt " ["
  6122. (if (= i 9) "0" (int-to-string (1+ i)))
  6123. "]" (nth i efforts))))
  6124. (message "Effort%s: %s " effort-op effort-prompt)
  6125. (setq char (read-char-exclusive))
  6126. (when (or (< char ?0) (> char ?9))
  6127. (error "Need 1-9,0 to select effort"))))
  6128. (when (equal char ?\t)
  6129. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6130. (org-set-local 'org-global-tags-completion-table
  6131. (org-global-tags-completion-table)))
  6132. (let ((completion-ignore-case t))
  6133. (setq tag (org-icompleting-read
  6134. "Tag: " org-global-tags-completion-table))))
  6135. (cond
  6136. ((equal char ?\r)
  6137. (org-agenda-filter-show-all-tag)
  6138. (when org-agenda-auto-exclude-function
  6139. (setq org-agenda-tag-filter '())
  6140. (dolist (tag (org-agenda-get-represented-tags))
  6141. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6142. (if modifier
  6143. (push modifier org-agenda-tag-filter))))
  6144. (if (not (null org-agenda-tag-filter))
  6145. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6146. (setq maybe-refresh t))
  6147. ((equal char ?/)
  6148. (org-agenda-filter-show-all-tag)
  6149. (when (get 'org-agenda-tag-filter :preset-filter)
  6150. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6151. (setq maybe-refresh t))
  6152. ((equal char ?. )
  6153. (setq org-agenda-tag-filter
  6154. (mapcar (lambda(tag) (concat "+" tag))
  6155. (org-get-at-bol 'tags)))
  6156. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6157. (setq maybe-refresh t))
  6158. ((or (equal char ?\ )
  6159. (setq a (rassoc char alist))
  6160. (and (>= char ?0) (<= char ?9)
  6161. (setq n (if (= char ?0) 9 (- char ?0 1))
  6162. tag (concat effort-op (nth n efforts))
  6163. a (cons tag nil)))
  6164. (and (= char ??)
  6165. (setq tag "?eff")
  6166. a (cons tag nil))
  6167. (and tag (setq a (cons tag nil))))
  6168. (org-agenda-filter-show-all-tag)
  6169. (setq tag (car a))
  6170. (setq org-agenda-tag-filter
  6171. (cons (concat (if strip "-" "+") tag)
  6172. (if narrow current nil)))
  6173. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6174. (setq maybe-refresh t))
  6175. (t (error "Invalid tag selection character %c" char)))
  6176. (when (and maybe-refresh
  6177. (eq org-agenda-clockreport-mode 'with-filter))
  6178. (org-agenda-redo))))
  6179. (defun org-agenda-get-represented-tags ()
  6180. "Get a list of all tags currently represented in the agenda."
  6181. (let (p tags)
  6182. (save-excursion
  6183. (goto-char (point-min))
  6184. (while (setq p (next-single-property-change (point) 'tags))
  6185. (goto-char p)
  6186. (mapc (lambda (x) (add-to-list 'tags x))
  6187. (get-text-property (point) 'tags))))
  6188. tags))
  6189. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6190. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6191. (interactive "P")
  6192. (org-agenda-filter-by-tag strip char 'refine))
  6193. (defun org-agenda-filter-make-matcher ()
  6194. "Create the form that tests a line for agenda filter."
  6195. (let (f f1)
  6196. ;; first compute the tag-filter matcher
  6197. (dolist (x (delete-dups
  6198. (append (get 'org-agenda-tag-filter
  6199. :preset-filter) org-agenda-tag-filter)))
  6200. (if (member x '("-" "+"))
  6201. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6202. (if (string-match "[<=>?]" x)
  6203. (setq f1 (org-agenda-filter-effort-form x))
  6204. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6205. (if (equal (string-to-char x) ?-)
  6206. (setq f1 (list 'not f1))))
  6207. (push f1 f))
  6208. ;; then compute the category-filter matcher
  6209. (dolist (x (delete-dups
  6210. (append (get 'org-agenda-category-filter
  6211. :preset-filter) org-agenda-category-filter)))
  6212. (if (equal "-" (substring x 0 1))
  6213. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6214. (setq f1 (list 'equal (substring x 1) 'cat)))
  6215. (push f1 f))
  6216. (cons 'and (nreverse f))))
  6217. (defun org-agenda-filter-effort-form (e)
  6218. "Return the form to compare the effort of the current line with what E says.
  6219. E looks like \"+<2:25\"."
  6220. (let (op)
  6221. (setq e (substring e 1))
  6222. (setq op (string-to-char e) e (substring e 1))
  6223. (setq op (cond ((equal op ?<) '<=)
  6224. ((equal op ?>) '>=)
  6225. ((equal op ??) op)
  6226. (t '=)))
  6227. (list 'org-agenda-compare-effort (list 'quote op)
  6228. (org-duration-string-to-minutes e))))
  6229. (defun org-agenda-compare-effort (op value)
  6230. "Compare the effort of the current line with VALUE, using OP.
  6231. If the line does not have an effort defined, return nil."
  6232. (let ((eff (org-get-at-bol 'effort-minutes)))
  6233. (if (equal op ??)
  6234. (not eff)
  6235. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6236. value))))
  6237. (defun org-agenda-filter-apply (filter type)
  6238. "Set FILTER as the new agenda filter and apply it."
  6239. (let (tags cat)
  6240. (if (eq type 'tag)
  6241. (setq org-agenda-tag-filter filter)
  6242. (setq org-agenda-category-filter filter))
  6243. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6244. (if (and (eq type 'category)
  6245. (not (equal (substring (car filter) 0 1) "-")))
  6246. ;; Only set `org-agenda-filtered-by-category' to t
  6247. ;; when a unique category is used as the filter
  6248. (setq org-agenda-filtered-by-category t))
  6249. (org-agenda-set-mode-name)
  6250. (save-excursion
  6251. (goto-char (point-min))
  6252. (while (not (eobp))
  6253. (if (org-get-at-bol 'org-marker)
  6254. (progn
  6255. (setq tags (org-get-at-bol 'tags) ; used in eval
  6256. cat (get-text-property (point) 'org-category))
  6257. (if (not (eval org-agenda-filter-form))
  6258. (org-agenda-filter-hide-line type))
  6259. (beginning-of-line 2))
  6260. (beginning-of-line 2))))
  6261. (if (get-char-property (point) 'invisible)
  6262. (ignore-errors (org-agenda-previous-line)))))
  6263. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6264. "Set FILTER as the new agenda filter and apply it."
  6265. (org-agenda-set-mode-name)
  6266. (save-excursion
  6267. (goto-char (point-min))
  6268. (while (not (eobp))
  6269. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6270. (topcat (and pos (org-find-top-category pos))))
  6271. (if (and topcat (funcall (if negative 'identity 'not)
  6272. (string= category topcat)))
  6273. (org-agenda-filter-hide-line 'category)))
  6274. (beginning-of-line 2)))
  6275. (if (get-char-property (point) 'invisible)
  6276. (org-agenda-previous-line))
  6277. (setq org-agenda-top-category-filter category
  6278. org-agenda-filtered-by-top-category t))
  6279. (defun org-agenda-filter-hide-line (type)
  6280. (let (ov)
  6281. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6282. (point-at-eol)))
  6283. (overlay-put ov 'invisible t)
  6284. (overlay-put ov 'type type)
  6285. (if (eq type 'tag)
  6286. (push ov org-agenda-tag-filter-overlays)
  6287. (push ov org-agenda-cat-filter-overlays))))
  6288. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6289. (setq pos (or pos (point)))
  6290. (save-excursion
  6291. (dolist (ov (overlays-at pos))
  6292. (when (and (overlay-get ov 'invisible)
  6293. (eq (overlay-get ov 'type) 'tag))
  6294. (goto-char pos)
  6295. (if (< (overlay-start ov) (point-at-eol))
  6296. (move-overlay ov (point-at-eol)
  6297. (overlay-end ov)))))))
  6298. (defun org-agenda-filter-show-all-tag nil
  6299. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6300. (setq org-agenda-tag-filter-overlays nil
  6301. org-agenda-tag-filter nil
  6302. org-agenda-filter-form nil)
  6303. (org-agenda-set-mode-name))
  6304. (defun org-agenda-filter-show-all-cat nil
  6305. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6306. (setq org-agenda-cat-filter-overlays nil
  6307. org-agenda-filtered-by-category nil
  6308. org-agenda-category-filter nil
  6309. org-agenda-filter-form nil)
  6310. (org-agenda-set-mode-name))
  6311. (defun org-agenda-manipulate-query-add ()
  6312. "Manipulate the query by adding a search term with positive selection.
  6313. Positive selection means the term must be matched for selection of an entry."
  6314. (interactive)
  6315. (org-agenda-manipulate-query ?\[))
  6316. (defun org-agenda-manipulate-query-subtract ()
  6317. "Manipulate the query by adding a search term with negative selection.
  6318. Negative selection means term must not be matched for selection of an entry."
  6319. (interactive)
  6320. (org-agenda-manipulate-query ?\]))
  6321. (defun org-agenda-manipulate-query-add-re ()
  6322. "Manipulate the query by adding a search regexp with positive selection.
  6323. Positive selection means the regexp must match for selection of an entry."
  6324. (interactive)
  6325. (org-agenda-manipulate-query ?\{))
  6326. (defun org-agenda-manipulate-query-subtract-re ()
  6327. "Manipulate the query by adding a search regexp with negative selection.
  6328. Negative selection means regexp must not match for selection of an entry."
  6329. (interactive)
  6330. (org-agenda-manipulate-query ?\}))
  6331. (defun org-agenda-manipulate-query (char)
  6332. (cond
  6333. ((memq org-agenda-type '(timeline agenda))
  6334. (let ((org-agenda-include-inactive-timestamps t))
  6335. (org-agenda-redo))
  6336. (message "Display now includes inactive timestamps as well"))
  6337. ((eq org-agenda-type 'search)
  6338. (org-add-to-string
  6339. 'org-agenda-query-string
  6340. (if org-agenda-last-search-view-search-was-boolean
  6341. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6342. (?\{ . " +{}") (?\} . " -{}"))))
  6343. " "))
  6344. (setq org-agenda-redo-command
  6345. (list 'org-search-view
  6346. org-todo-only
  6347. org-agenda-query-string
  6348. (+ (length org-agenda-query-string)
  6349. (if (member char '(?\{ ?\})) 0 1))))
  6350. (set-register org-agenda-query-register org-agenda-query-string)
  6351. (org-agenda-redo))
  6352. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6353. org-agenda-type))))
  6354. (defun org-add-to-string (var string)
  6355. (set var (concat (symbol-value var) string)))
  6356. (defun org-agenda-goto-date (date)
  6357. "Jump to DATE in agenda."
  6358. (interactive (list (let ((org-read-date-prefer-future
  6359. (eval org-agenda-jump-prefer-future)))
  6360. (org-read-date))))
  6361. (org-agenda-list nil date))
  6362. (defun org-agenda-goto-today ()
  6363. "Go to today."
  6364. (interactive)
  6365. (org-agenda-check-type t 'timeline 'agenda)
  6366. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6367. (cond
  6368. (tdpos (goto-char tdpos))
  6369. ((eq org-agenda-type 'agenda)
  6370. (let* ((sd (org-agenda-compute-starting-span
  6371. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6372. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6373. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6374. (org-agenda-redo)
  6375. (org-agenda-find-same-or-today-or-agenda)))
  6376. (t (error "Cannot find today")))))
  6377. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6378. (goto-char
  6379. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6380. (text-property-any (point-min) (point-max) 'org-today t)
  6381. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6382. (point-min))))
  6383. (defun org-agenda-later (arg)
  6384. "Go forward in time by thee current span.
  6385. With prefix ARG, go forward that many times the current span."
  6386. (interactive "p")
  6387. (org-agenda-check-type t 'agenda)
  6388. (let* ((span org-agenda-current-span)
  6389. (sd org-starting-day)
  6390. (greg (calendar-gregorian-from-absolute sd))
  6391. (cnt (org-get-at-bol 'org-day-cnt))
  6392. greg2)
  6393. (cond
  6394. ((eq span 'day)
  6395. (setq sd (+ arg sd)))
  6396. ((eq span 'week)
  6397. (setq sd (+ (* 7 arg) sd)))
  6398. ((eq span 'month)
  6399. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6400. sd (calendar-absolute-from-gregorian greg2))
  6401. (setcar greg2 (1+ (car greg2))))
  6402. ((eq span 'year)
  6403. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6404. sd (calendar-absolute-from-gregorian greg2))
  6405. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6406. (t
  6407. (setq sd (+ (* span arg) sd))))
  6408. (let ((org-agenda-overriding-arguments
  6409. (list (car org-agenda-last-arguments) sd span t)))
  6410. (org-agenda-redo)
  6411. (org-agenda-find-same-or-today-or-agenda cnt))))
  6412. (defun org-agenda-earlier (arg)
  6413. "Go backward in time by the current span.
  6414. With prefix ARG, go backward that many times the current span."
  6415. (interactive "p")
  6416. (org-agenda-later (- arg)))
  6417. (defun org-agenda-view-mode-dispatch ()
  6418. "Call one of the view mode commands."
  6419. (interactive)
  6420. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6421. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6422. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6423. (let ((a (read-char-exclusive)))
  6424. (case a
  6425. (?\ (call-interactively 'org-agenda-reset-view))
  6426. (?d (call-interactively 'org-agenda-day-view))
  6427. (?w (call-interactively 'org-agenda-week-view))
  6428. (?m (call-interactively 'org-agenda-month-view))
  6429. (?y (call-interactively 'org-agenda-year-view))
  6430. (?l (call-interactively 'org-agenda-log-mode))
  6431. (?L (org-agenda-log-mode '(4)))
  6432. (?c (org-agenda-log-mode 'clockcheck))
  6433. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6434. (?a (call-interactively 'org-agenda-archives-mode))
  6435. (?A (org-agenda-archives-mode 'files))
  6436. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6437. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6438. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6439. (?D (call-interactively 'org-agenda-toggle-diary))
  6440. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6441. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6442. (org-agenda-check-type t 'timeline 'agenda)
  6443. (org-agenda-redo))
  6444. (message "Display now includes inactive timestamps as well"))
  6445. (?q (message "Abort"))
  6446. (otherwise (error "Invalid key" )))))
  6447. (defun org-agenda-reset-view ()
  6448. "Switch to default view for agenda."
  6449. (interactive)
  6450. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6451. (defun org-agenda-day-view (&optional day-of-year)
  6452. "Switch to daily view for agenda.
  6453. With argument DAY-OF-YEAR, switch to that day of the year."
  6454. (interactive "P")
  6455. (org-agenda-change-time-span 'day day-of-year))
  6456. (defun org-agenda-week-view (&optional iso-week)
  6457. "Switch to daily view for agenda.
  6458. With argument ISO-WEEK, switch to the corresponding ISO week.
  6459. If ISO-WEEK has more then 2 digits, only the last two encode the
  6460. week. Any digits before this encode a year. So 200712 means
  6461. week 12 of year 2007. Years in the range 1938-2037 can also be
  6462. written as 2-digit years."
  6463. (interactive "P")
  6464. (org-agenda-change-time-span 'week iso-week))
  6465. (defun org-agenda-month-view (&optional month)
  6466. "Switch to monthly view for agenda.
  6467. With argument MONTH, switch to that month."
  6468. (interactive "P")
  6469. (org-agenda-change-time-span 'month month))
  6470. (defun org-agenda-year-view (&optional year)
  6471. "Switch to yearly view for agenda.
  6472. With argument YEAR, switch to that year.
  6473. If MONTH has more then 2 digits, only the last two encode the
  6474. month. Any digits before this encode a year. So 200712 means
  6475. December year 2007. Years in the range 1938-2037 can also be
  6476. written as 2-digit years."
  6477. (interactive "P")
  6478. (when year
  6479. (setq year (org-small-year-to-year year)))
  6480. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6481. (org-agenda-change-time-span 'year year)
  6482. (error "Abort")))
  6483. (defun org-agenda-change-time-span (span &optional n)
  6484. "Change the agenda view to SPAN.
  6485. SPAN may be `day', `week', `month', `year'."
  6486. (org-agenda-check-type t 'agenda)
  6487. (if (and (not n) (equal org-agenda-current-span span))
  6488. (error "Viewing span is already \"%s\"" span))
  6489. (let* ((sd (or (org-get-at-bol 'day)
  6490. org-starting-day))
  6491. (sd (org-agenda-compute-starting-span sd span n))
  6492. (org-agenda-overriding-arguments
  6493. (or org-agenda-overriding-arguments
  6494. (list (car org-agenda-last-arguments) sd span t))))
  6495. (org-agenda-redo)
  6496. (org-agenda-find-same-or-today-or-agenda))
  6497. (org-agenda-set-mode-name)
  6498. (message "Switched to %s view" span))
  6499. (defun org-agenda-compute-starting-span (sd span &optional n)
  6500. "Compute starting date for agenda.
  6501. SPAN may be `day', `week', `month', `year'. The return value
  6502. is a cons cell with the starting date and the number of days,
  6503. so that the date SD will be in that range."
  6504. (let* ((greg (calendar-gregorian-from-absolute sd))
  6505. (dg (nth 1 greg))
  6506. (mg (car greg))
  6507. (yg (nth 2 greg)))
  6508. (cond
  6509. ((eq span 'day)
  6510. (when n
  6511. (setq sd (+ (calendar-absolute-from-gregorian
  6512. (list mg 1 yg))
  6513. n -1))))
  6514. ((eq span 'week)
  6515. (let* ((nt (calendar-day-of-week
  6516. (calendar-gregorian-from-absolute sd)))
  6517. (d (if org-agenda-start-on-weekday
  6518. (- nt org-agenda-start-on-weekday)
  6519. 0))
  6520. y1)
  6521. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6522. (when n
  6523. (require 'cal-iso)
  6524. (when (> n 99)
  6525. (setq y1 (org-small-year-to-year (/ n 100))
  6526. n (mod n 100)))
  6527. (setq sd
  6528. (calendar-absolute-from-iso
  6529. (list n 1
  6530. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6531. ((eq span 'month)
  6532. (let (y1)
  6533. (when (and n (> n 99))
  6534. (setq y1 (org-small-year-to-year (/ n 100))
  6535. n (mod n 100)))
  6536. (setq sd (calendar-absolute-from-gregorian
  6537. (list (or n mg) 1 (or y1 yg))))))
  6538. ((eq span 'year)
  6539. (setq sd (calendar-absolute-from-gregorian
  6540. (list 1 1 (or n yg))))))
  6541. sd))
  6542. (defun org-agenda-next-date-line (&optional arg)
  6543. "Jump to the next line indicating a date in agenda buffer."
  6544. (interactive "p")
  6545. (org-agenda-check-type t 'agenda 'timeline)
  6546. (beginning-of-line 1)
  6547. ;; This does not work if user makes date format that starts with a blank
  6548. (if (looking-at "^\\S-") (forward-char 1))
  6549. (if (not (re-search-forward "^\\S-" nil t arg))
  6550. (progn
  6551. (backward-char 1)
  6552. (error "No next date after this line in this buffer")))
  6553. (goto-char (match-beginning 0)))
  6554. (defun org-agenda-previous-date-line (&optional arg)
  6555. "Jump to the previous line indicating a date in agenda buffer."
  6556. (interactive "p")
  6557. (org-agenda-check-type t 'agenda 'timeline)
  6558. (beginning-of-line 1)
  6559. (if (not (re-search-backward "^\\S-" nil t arg))
  6560. (error "No previous date before this line in this buffer")))
  6561. ;; Initialize the highlight
  6562. (defvar org-hl (make-overlay 1 1))
  6563. (overlay-put org-hl 'face 'highlight)
  6564. (defun org-highlight (begin end &optional buffer)
  6565. "Highlight a region with overlay."
  6566. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6567. (defun org-unhighlight ()
  6568. "Detach overlay INDEX."
  6569. (org-detach-overlay org-hl))
  6570. ;; FIXME this is currently not used.
  6571. (defun org-highlight-until-next-command (beg end &optional buffer)
  6572. "Move the highlight overlay to BEG/END, remove it before the next command."
  6573. (org-highlight beg end buffer)
  6574. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6575. (defun org-unhighlight-once ()
  6576. "Remove the highlight from its position, and this function from the hook."
  6577. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6578. (org-unhighlight))
  6579. (defun org-agenda-follow-mode ()
  6580. "Toggle follow mode in an agenda buffer."
  6581. (interactive)
  6582. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6583. (org-agenda-set-mode-name)
  6584. (org-agenda-do-context-action)
  6585. (message "Follow mode is %s"
  6586. (if org-agenda-follow-mode "on" "off")))
  6587. (defun org-agenda-entry-text-mode (&optional arg)
  6588. "Toggle entry text mode in an agenda buffer."
  6589. (interactive "P")
  6590. (setq org-agenda-entry-text-mode (or (integerp arg)
  6591. (not org-agenda-entry-text-mode)))
  6592. (org-agenda-entry-text-hide)
  6593. (and org-agenda-entry-text-mode
  6594. (let ((org-agenda-entry-text-maxlines
  6595. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6596. (org-agenda-entry-text-show)))
  6597. (org-agenda-set-mode-name)
  6598. (message "Entry text mode is %s. Maximum number of lines is %d"
  6599. (if org-agenda-entry-text-mode "on" "off")
  6600. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6601. (defun org-agenda-clockreport-mode (&optional with-filter)
  6602. "Toggle clocktable mode in an agenda buffer.
  6603. With prefix arg WITH-FILTER, make the clocktable respect the current
  6604. agenda filter."
  6605. (interactive "P")
  6606. (org-agenda-check-type t 'agenda)
  6607. (if with-filter
  6608. (setq org-agenda-clockreport-mode 'with-filter)
  6609. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6610. (org-agenda-set-mode-name)
  6611. (org-agenda-redo)
  6612. (message "Clocktable mode is %s"
  6613. (if org-agenda-clockreport-mode "on" "off")))
  6614. (defun org-agenda-log-mode (&optional special)
  6615. "Toggle log mode in an agenda buffer.
  6616. With argument SPECIAL, show all possible log items, not only the ones
  6617. configured in `org-agenda-log-mode-items'.
  6618. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6619. (interactive "P")
  6620. (org-agenda-check-type t 'agenda 'timeline)
  6621. (setq org-agenda-show-log
  6622. (cond
  6623. ((equal special '(16)) 'only)
  6624. ((eq special 'clockcheck)
  6625. (if (eq org-agenda-show-log 'clockcheck)
  6626. nil 'clockcheck))
  6627. (special '(closed clock state))
  6628. (t (not org-agenda-show-log))))
  6629. (org-agenda-set-mode-name)
  6630. (org-agenda-redo)
  6631. (message "Log mode is %s"
  6632. (if org-agenda-show-log "on" "off")))
  6633. (defun org-agenda-archives-mode (&optional with-files)
  6634. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6635. When called with a prefix argument, include all archive files as well."
  6636. (interactive "P")
  6637. (setq org-agenda-archives-mode
  6638. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6639. (org-agenda-set-mode-name)
  6640. (org-agenda-redo)
  6641. (message
  6642. "%s"
  6643. (cond
  6644. ((eq org-agenda-archives-mode nil)
  6645. "No archives are included")
  6646. ((eq org-agenda-archives-mode 'trees)
  6647. (format "Trees with :%s: tag are included" org-archive-tag))
  6648. ((eq org-agenda-archives-mode t)
  6649. (format "Trees with :%s: tag and all active archive files are included"
  6650. org-archive-tag)))))
  6651. (defun org-agenda-toggle-diary ()
  6652. "Toggle diary inclusion in an agenda buffer."
  6653. (interactive)
  6654. (org-agenda-check-type t 'agenda)
  6655. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6656. (org-agenda-redo)
  6657. (org-agenda-set-mode-name)
  6658. (message "Diary inclusion turned %s"
  6659. (if org-agenda-include-diary "on" "off")))
  6660. (defun org-agenda-toggle-deadlines ()
  6661. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6662. (interactive)
  6663. (org-agenda-check-type t 'agenda)
  6664. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6665. (org-agenda-redo)
  6666. (org-agenda-set-mode-name)
  6667. (message "Deadlines inclusion turned %s"
  6668. (if org-agenda-include-deadlines "on" "off")))
  6669. (defun org-agenda-toggle-time-grid ()
  6670. "Toggle time grid in an agenda buffer."
  6671. (interactive)
  6672. (org-agenda-check-type t 'agenda)
  6673. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6674. (org-agenda-redo)
  6675. (org-agenda-set-mode-name)
  6676. (message "Time-grid turned %s"
  6677. (if org-agenda-use-time-grid "on" "off")))
  6678. (defun org-agenda-set-mode-name ()
  6679. "Set the mode name to indicate all the small mode settings."
  6680. (setq mode-name
  6681. (list "Org-Agenda"
  6682. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6683. " "
  6684. '(:eval (org-agenda-span-name org-agenda-current-span))
  6685. (if org-agenda-follow-mode " Follow" "")
  6686. (if org-agenda-entry-text-mode " ETxt" "")
  6687. (if org-agenda-include-diary " Diary" "")
  6688. (if org-agenda-include-deadlines " Ddl" "")
  6689. (if org-agenda-use-time-grid " Grid" "")
  6690. (if (and (boundp 'org-habit-show-habits)
  6691. org-habit-show-habits) " Habit" "")
  6692. (cond
  6693. ((consp org-agenda-show-log) " LogAll")
  6694. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6695. (org-agenda-show-log " Log")
  6696. (t ""))
  6697. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6698. :preset-filter))
  6699. '(:eval (org-propertize
  6700. (concat " <"
  6701. (mapconcat
  6702. 'identity
  6703. (append
  6704. (get 'org-agenda-category-filter :preset-filter)
  6705. org-agenda-category-filter)
  6706. "")
  6707. ">")
  6708. 'face 'org-agenda-filter-category
  6709. 'help-echo "Category used in filtering"))
  6710. "")
  6711. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6712. :preset-filter))
  6713. '(:eval (org-propertize
  6714. (concat " {"
  6715. (mapconcat
  6716. 'identity
  6717. (append
  6718. (get 'org-agenda-tag-filter :preset-filter)
  6719. org-agenda-tag-filter)
  6720. "")
  6721. "}")
  6722. 'face 'org-agenda-filter-tags
  6723. 'help-echo "Tags used in filtering"))
  6724. "")
  6725. (if org-agenda-archives-mode
  6726. (if (eq org-agenda-archives-mode t)
  6727. " Archives"
  6728. (format " :%s:" org-archive-tag))
  6729. "")
  6730. (if org-agenda-clockreport-mode
  6731. (if (eq org-agenda-clockreport-mode 'with-filter)
  6732. " Clock{}" " Clock")
  6733. "")))
  6734. (force-mode-line-update))
  6735. (defun org-agenda-post-command-hook ()
  6736. (setq org-agenda-type
  6737. (or (get-text-property (point) 'org-agenda-type)
  6738. (get-text-property (max (point-min) (1- (point)))
  6739. 'org-agenda-type))))
  6740. (defun org-agenda-next-line ()
  6741. "Move cursor to the next line, and show if follow mode is active."
  6742. (interactive)
  6743. (call-interactively 'next-line)
  6744. (org-agenda-do-context-action))
  6745. (defun org-agenda-previous-line ()
  6746. "Move cursor to the previous line, and show if follow-mode is active."
  6747. (interactive)
  6748. (call-interactively 'previous-line)
  6749. (org-agenda-do-context-action))
  6750. (defun org-agenda-do-context-action ()
  6751. "Show outline path and, maybe, follow mode window."
  6752. (let ((m (org-get-at-bol 'org-marker)))
  6753. (when (and (markerp m) (marker-buffer m))
  6754. (and org-agenda-follow-mode
  6755. (if org-agenda-follow-indirect
  6756. (org-agenda-tree-to-indirect-buffer)
  6757. (org-agenda-show)))
  6758. (and org-agenda-show-outline-path
  6759. (org-with-point-at m (org-display-outline-path t))))))
  6760. (defun org-agenda-show-priority ()
  6761. "Show the priority of the current item.
  6762. This priority is composed of the main priority given with the [#A] cookies,
  6763. and by additional input from the age of a schedules or deadline entry."
  6764. (interactive)
  6765. (let* ((pri (org-get-at-bol 'priority)))
  6766. (message "Priority is %d" (if pri pri -1000))))
  6767. (defun org-agenda-show-tags ()
  6768. "Show the tags applicable to the current item."
  6769. (interactive)
  6770. (let* ((tags (org-get-at-bol 'tags)))
  6771. (if tags
  6772. (message "Tags are :%s:"
  6773. (org-no-properties (mapconcat 'identity tags ":")))
  6774. (message "No tags associated with this line"))))
  6775. (defun org-agenda-goto (&optional highlight)
  6776. "Go to the Org-mode file which contains the item at point."
  6777. (interactive)
  6778. (let* ((marker (or (org-get-at-bol 'org-marker)
  6779. (org-agenda-error)))
  6780. (buffer (marker-buffer marker))
  6781. (pos (marker-position marker)))
  6782. (switch-to-buffer-other-window buffer)
  6783. (widen)
  6784. (push-mark)
  6785. (goto-char pos)
  6786. (when (derived-mode-p 'org-mode)
  6787. (org-show-context 'agenda)
  6788. (save-excursion
  6789. (and (outline-next-heading)
  6790. (org-flag-heading nil)))) ; show the next heading
  6791. (when (outline-invisible-p)
  6792. (show-entry)) ; display invisible text
  6793. (recenter (/ (window-height) 2))
  6794. (run-hooks 'org-agenda-after-show-hook)
  6795. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6796. (defvar org-agenda-after-show-hook nil
  6797. "Normal hook run after an item has been shown from the agenda.
  6798. Point is in the buffer where the item originated.")
  6799. (defun org-agenda-kill ()
  6800. "Kill the entry or subtree belonging to the current agenda entry."
  6801. (interactive)
  6802. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6803. (let* ((marker (or (org-get-at-bol 'org-marker)
  6804. (org-agenda-error)))
  6805. (buffer (marker-buffer marker))
  6806. (pos (marker-position marker))
  6807. (type (org-get-at-bol 'type))
  6808. dbeg dend (n 0) conf)
  6809. (org-with-remote-undo buffer
  6810. (with-current-buffer buffer
  6811. (save-excursion
  6812. (goto-char pos)
  6813. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  6814. (setq dbeg (progn (org-back-to-heading t) (point))
  6815. dend (org-end-of-subtree t t))
  6816. (setq dbeg (point-at-bol)
  6817. dend (min (point-max) (1+ (point-at-eol)))))
  6818. (goto-char dbeg)
  6819. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6820. (setq conf (or (eq t org-agenda-confirm-kill)
  6821. (and (numberp org-agenda-confirm-kill)
  6822. (> n org-agenda-confirm-kill))))
  6823. (and conf
  6824. (not (y-or-n-p
  6825. (format "Delete entry with %d lines in buffer \"%s\"? "
  6826. n (buffer-name buffer))))
  6827. (error "Abort"))
  6828. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6829. (with-current-buffer buffer (delete-region dbeg dend))
  6830. (message "Agenda item and source killed"))))
  6831. (defvar org-archive-default-command)
  6832. (defun org-agenda-archive-default ()
  6833. "Archive the entry or subtree belonging to the current agenda entry."
  6834. (interactive)
  6835. (require 'org-archive)
  6836. (org-agenda-archive-with org-archive-default-command))
  6837. (defun org-agenda-archive-default-with-confirmation ()
  6838. "Archive the entry or subtree belonging to the current agenda entry."
  6839. (interactive)
  6840. (require 'org-archive)
  6841. (org-agenda-archive-with org-archive-default-command 'confirm))
  6842. (defun org-agenda-archive ()
  6843. "Archive the entry or subtree belonging to the current agenda entry."
  6844. (interactive)
  6845. (org-agenda-archive-with 'org-archive-subtree))
  6846. (defun org-agenda-archive-to-archive-sibling ()
  6847. "Move the entry to the archive sibling."
  6848. (interactive)
  6849. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6850. (defun org-agenda-archive-with (cmd &optional confirm)
  6851. "Move the entry to the archive sibling."
  6852. (interactive)
  6853. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6854. (let* ((marker (or (org-get-at-bol 'org-marker)
  6855. (org-agenda-error)))
  6856. (buffer (marker-buffer marker))
  6857. (pos (marker-position marker)))
  6858. (org-with-remote-undo buffer
  6859. (with-current-buffer buffer
  6860. (if (derived-mode-p 'org-mode)
  6861. (if (and confirm
  6862. (not (y-or-n-p "Archive this subtree or entry? ")))
  6863. (error "Abort")
  6864. (save-excursion
  6865. (goto-char pos)
  6866. (org-remove-subtree-entries-from-agenda)
  6867. (org-back-to-heading t)
  6868. (funcall cmd)))
  6869. (error "Archiving works only in Org-mode files"))))))
  6870. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6871. "Remove all lines in the agenda that correspond to a given subtree.
  6872. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6873. If this information is not given, the function uses the tree at point."
  6874. (let ((buf (or buf (current-buffer))) m p)
  6875. (save-excursion
  6876. (unless (and beg end)
  6877. (org-back-to-heading t)
  6878. (setq beg (point))
  6879. (org-end-of-subtree t)
  6880. (setq end (point)))
  6881. (set-buffer (get-buffer org-agenda-buffer-name))
  6882. (save-excursion
  6883. (goto-char (point-max))
  6884. (beginning-of-line 1)
  6885. (while (not (bobp))
  6886. (when (and (setq m (org-get-at-bol 'org-marker))
  6887. (equal buf (marker-buffer m))
  6888. (setq p (marker-position m))
  6889. (>= p beg)
  6890. (< p end))
  6891. (let ((inhibit-read-only t))
  6892. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6893. (beginning-of-line 0))))))
  6894. (defun org-agenda-refile (&optional goto rfloc no-update)
  6895. "Refile the item at point."
  6896. (interactive "P")
  6897. (if (equal goto '(16))
  6898. (org-refile-goto-last-stored)
  6899. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6900. (org-agenda-error)))
  6901. (buffer (marker-buffer marker))
  6902. (pos (marker-position marker))
  6903. (rfloc (or rfloc
  6904. (org-refile-get-location
  6905. (if goto "Goto" "Refile to") buffer
  6906. org-refile-allow-creating-parent-nodes))))
  6907. (with-current-buffer buffer
  6908. (save-excursion
  6909. (save-restriction
  6910. (widen)
  6911. (goto-char marker)
  6912. (org-remove-subtree-entries-from-agenda)
  6913. (org-refile goto buffer rfloc)))))
  6914. (unless no-update (org-agenda-redo))))
  6915. (defun org-agenda-open-link (&optional arg)
  6916. "Follow the link in the current line, if any.
  6917. This looks for a link in the displayed line in the agenda. It also looks
  6918. at the text of the entry itself."
  6919. (interactive "P")
  6920. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6921. (org-get-at-bol 'org-marker)))
  6922. (buffer (and marker (marker-buffer marker)))
  6923. (prefix (buffer-substring
  6924. (point-at-bol) (point-at-eol))))
  6925. (cond
  6926. (buffer
  6927. (with-current-buffer buffer
  6928. (save-excursion
  6929. (save-restriction
  6930. (widen)
  6931. (goto-char marker)
  6932. (org-offer-links-in-entry arg prefix)))))
  6933. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6934. (save-excursion
  6935. (beginning-of-line 1)
  6936. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6937. (org-open-link-from-string (match-string 1)))
  6938. (t (error "No link to open here")))))
  6939. (defun org-agenda-copy-local-variable (var)
  6940. "Get a variable from a referenced buffer and install it here."
  6941. (let ((m (org-get-at-bol 'org-marker)))
  6942. (when (and m (buffer-live-p (marker-buffer m)))
  6943. (org-set-local var (with-current-buffer (marker-buffer m)
  6944. (symbol-value var))))))
  6945. (defun org-agenda-switch-to (&optional delete-other-windows)
  6946. "Go to the Org-mode file which contains the item at point."
  6947. (interactive)
  6948. (if (and org-return-follows-link
  6949. (not (org-get-at-bol 'org-marker))
  6950. (org-in-regexp org-bracket-link-regexp))
  6951. (org-open-link-from-string (match-string 0))
  6952. (let* ((marker (or (org-get-at-bol 'org-marker)
  6953. (org-agenda-error)))
  6954. (buffer (marker-buffer marker))
  6955. (pos (marker-position marker)))
  6956. (org-pop-to-buffer-same-window buffer)
  6957. (and delete-other-windows (delete-other-windows))
  6958. (widen)
  6959. (goto-char pos)
  6960. (when (derived-mode-p 'org-mode)
  6961. (org-show-context 'agenda)
  6962. (save-excursion
  6963. (and (outline-next-heading)
  6964. (org-flag-heading nil))) ; show the next heading
  6965. (when (outline-invisible-p)
  6966. (show-entry)))))) ; display invisible text
  6967. (defun org-agenda-goto-mouse (ev)
  6968. "Go to the Org-mode file which contains the item at the mouse click."
  6969. (interactive "e")
  6970. (mouse-set-point ev)
  6971. (org-agenda-goto))
  6972. (defun org-agenda-show (&optional full-entry)
  6973. "Display the Org-mode file which contains the item at point.
  6974. With prefix argument FULL-ENTRY, make the entire entry visible
  6975. if it was hidden in the outline."
  6976. (interactive "P")
  6977. (let ((win (selected-window)))
  6978. (if full-entry
  6979. (let ((org-show-entry-below t))
  6980. (org-agenda-goto t))
  6981. (org-agenda-goto t))
  6982. (select-window win)))
  6983. (defvar org-agenda-show-window nil)
  6984. (defun org-agenda-show-and-scroll-up (&optional arg)
  6985. "Display the Org-mode file which contains the item at point.
  6986. When called repeatedly, scroll the window that is displaying the buffer.
  6987. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6988. `show-subtree' to display the item, so that drawers and logbooks stay
  6989. folded."
  6990. (interactive "P")
  6991. (let ((win (selected-window)))
  6992. (if (and (window-live-p org-agenda-show-window)
  6993. (eq this-command last-command))
  6994. (progn
  6995. (select-window org-agenda-show-window)
  6996. (ignore-errors (scroll-up)))
  6997. (org-agenda-goto t)
  6998. (if arg (org-show-entry) (show-subtree))
  6999. (setq org-agenda-show-window (selected-window)))
  7000. (select-window win)))
  7001. (defun org-agenda-show-scroll-down ()
  7002. "Scroll down the window showing the agenda."
  7003. (interactive)
  7004. (let ((win (selected-window)))
  7005. (when (window-live-p org-agenda-show-window)
  7006. (select-window org-agenda-show-window)
  7007. (ignore-errors (scroll-down))
  7008. (select-window win))))
  7009. (defun org-agenda-show-1 (&optional more)
  7010. "Display the Org-mode file which contains the item at point.
  7011. The prefix arg selects the amount of information to display:
  7012. 0 hide the subtree
  7013. 1 just show the entry according to defaults.
  7014. 2 show the children view
  7015. 3 show the subtree view
  7016. 4 show the entire subtree and any LOGBOOK drawers
  7017. 5 show the entire subtree and any drawers
  7018. With prefix argument FULL-ENTRY, make the entire entry visible
  7019. if it was hidden in the outline."
  7020. (interactive "p")
  7021. (let ((win (selected-window)))
  7022. (org-agenda-goto t)
  7023. (org-recenter-heading 1)
  7024. (cond
  7025. ((= more 0)
  7026. (hide-subtree)
  7027. (save-excursion
  7028. (org-back-to-heading)
  7029. (run-hook-with-args 'org-cycle-hook 'folded))
  7030. (message "Remote: FOLDED"))
  7031. ((and (org-called-interactively-p 'any) (= more 1))
  7032. (message "Remote: show with default settings"))
  7033. ((= more 2)
  7034. (show-entry)
  7035. (show-children)
  7036. (save-excursion
  7037. (org-back-to-heading)
  7038. (run-hook-with-args 'org-cycle-hook 'children))
  7039. (message "Remote: CHILDREN"))
  7040. ((= more 3)
  7041. (show-subtree)
  7042. (save-excursion
  7043. (org-back-to-heading)
  7044. (run-hook-with-args 'org-cycle-hook 'subtree))
  7045. (message "Remote: SUBTREE"))
  7046. ((= more 4)
  7047. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7048. (org-drawer-regexp
  7049. (concat "^[ \t]*:\\("
  7050. (mapconcat 'regexp-quote org-drawers "\\|")
  7051. "\\):[ \t]*$")))
  7052. (show-subtree)
  7053. (save-excursion
  7054. (org-back-to-heading)
  7055. (org-cycle-hide-drawers 'subtree)))
  7056. (message "Remote: SUBTREE AND LOGBOOK"))
  7057. ((> more 4)
  7058. (show-subtree)
  7059. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7060. (select-window win)))
  7061. (defun org-recenter-heading (n)
  7062. (save-excursion
  7063. (org-back-to-heading)
  7064. (recenter n)))
  7065. (defvar org-agenda-cycle-counter nil)
  7066. (defun org-agenda-cycle-show (&optional n)
  7067. "Show the current entry in another window, with default settings.
  7068. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7069. When use repeatedly in immediate succession, the remote entry will cycle
  7070. through visibility
  7071. children -> subtree -> folded
  7072. When called with a numeric prefix arg, that arg will be passed through to
  7073. `org-agenda-show-1'. For the interpretation of that argument, see the
  7074. docstring of `org-agenda-show-1'."
  7075. (interactive "P")
  7076. (if (integerp n)
  7077. (setq org-agenda-cycle-counter n)
  7078. (if (not (eq last-command this-command))
  7079. (setq org-agenda-cycle-counter 1)
  7080. (if (equal org-agenda-cycle-counter 0)
  7081. (setq org-agenda-cycle-counter 2)
  7082. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7083. (if (> org-agenda-cycle-counter 3)
  7084. (setq org-agenda-cycle-counter 0)))))
  7085. (org-agenda-show-1 org-agenda-cycle-counter))
  7086. (defun org-agenda-recenter (arg)
  7087. "Display the Org-mode file which contains the item at point and recenter."
  7088. (interactive "P")
  7089. (let ((win (selected-window)))
  7090. (org-agenda-goto t)
  7091. (recenter arg)
  7092. (select-window win)))
  7093. (defun org-agenda-show-mouse (ev)
  7094. "Display the Org-mode file which contains the item at the mouse click."
  7095. (interactive "e")
  7096. (mouse-set-point ev)
  7097. (org-agenda-show))
  7098. (defun org-agenda-check-no-diary ()
  7099. "Check if the entry is a diary link and abort if yes."
  7100. (if (org-get-at-bol 'org-agenda-diary-link)
  7101. (org-agenda-error)))
  7102. (defun org-agenda-error ()
  7103. (error "Command not allowed in this line"))
  7104. (defun org-agenda-tree-to-indirect-buffer ()
  7105. "Show the subtree corresponding to the current entry in an indirect buffer.
  7106. This calls the command `org-tree-to-indirect-buffer' from the original
  7107. Org-mode buffer.
  7108. With numerical prefix arg ARG, go up to this level and then take that tree.
  7109. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7110. use the dedicated frame)."
  7111. (interactive)
  7112. (if (and current-prefix-arg (listp current-prefix-arg))
  7113. (org-agenda-do-tree-to-indirect-buffer)
  7114. (let ((agenda-window (selected-window))
  7115. (indirect-window
  7116. (and org-last-indirect-buffer
  7117. (get-buffer-window org-last-indirect-buffer))))
  7118. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7119. (unwind-protect
  7120. (progn
  7121. (unless (and indirect-window (window-live-p indirect-window))
  7122. (setq indirect-window (split-window agenda-window)))
  7123. (select-window indirect-window)
  7124. (switch-to-buffer org-last-indirect-buffer :norecord)
  7125. (fit-window-to-buffer indirect-window))
  7126. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7127. (defun org-agenda-do-tree-to-indirect-buffer ()
  7128. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7129. (org-agenda-check-no-diary)
  7130. (let* ((marker (or (org-get-at-bol 'org-marker)
  7131. (org-agenda-error)))
  7132. (buffer (marker-buffer marker))
  7133. (pos (marker-position marker)))
  7134. (with-current-buffer buffer
  7135. (save-excursion
  7136. (goto-char pos)
  7137. (call-interactively 'org-tree-to-indirect-buffer)))))
  7138. (defvar org-last-heading-marker (make-marker)
  7139. "Marker pointing to the headline that last changed its TODO state
  7140. by a remote command from the agenda.")
  7141. (defun org-agenda-todo-nextset ()
  7142. "Switch TODO entry to next sequence."
  7143. (interactive)
  7144. (org-agenda-todo 'nextset))
  7145. (defun org-agenda-todo-previousset ()
  7146. "Switch TODO entry to previous sequence."
  7147. (interactive)
  7148. (org-agenda-todo 'previousset))
  7149. (defun org-agenda-todo (&optional arg)
  7150. "Cycle TODO state of line at point, also in Org-mode file.
  7151. This changes the line at point, all other lines in the agenda referring to
  7152. the same tree node, and the headline of the tree node in the Org-mode file."
  7153. (interactive "P")
  7154. (org-agenda-check-no-diary)
  7155. (let* ((col (current-column))
  7156. (marker (or (org-get-at-bol 'org-marker)
  7157. (org-agenda-error)))
  7158. (buffer (marker-buffer marker))
  7159. (pos (marker-position marker))
  7160. (hdmarker (org-get-at-bol 'org-hd-marker))
  7161. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7162. (inhibit-read-only t)
  7163. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7164. (org-with-remote-undo buffer
  7165. (with-current-buffer buffer
  7166. (widen)
  7167. (goto-char pos)
  7168. (org-show-context 'agenda)
  7169. (save-excursion
  7170. (and (outline-next-heading)
  7171. (org-flag-heading nil))) ; show the next heading
  7172. (let ((current-prefix-arg arg))
  7173. (call-interactively 'org-todo))
  7174. (and (bolp) (forward-char 1))
  7175. (setq newhead (org-get-heading))
  7176. (when (and (org-bound-and-true-p
  7177. org-agenda-headline-snapshot-before-repeat)
  7178. (not (equal org-agenda-headline-snapshot-before-repeat
  7179. newhead))
  7180. todayp)
  7181. (setq newhead org-agenda-headline-snapshot-before-repeat
  7182. just-one t))
  7183. (save-excursion
  7184. (org-back-to-heading)
  7185. (move-marker org-last-heading-marker (point))))
  7186. (beginning-of-line 1)
  7187. (save-excursion
  7188. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7189. (org-move-to-column col))))
  7190. (defun org-agenda-add-note (&optional arg)
  7191. "Add a time-stamped note to the entry at point."
  7192. (interactive "P")
  7193. (org-agenda-check-no-diary)
  7194. (let* ((marker (or (org-get-at-bol 'org-marker)
  7195. (org-agenda-error)))
  7196. (buffer (marker-buffer marker))
  7197. (pos (marker-position marker))
  7198. (hdmarker (org-get-at-bol 'org-hd-marker))
  7199. (inhibit-read-only t))
  7200. (with-current-buffer buffer
  7201. (widen)
  7202. (goto-char pos)
  7203. (org-show-context 'agenda)
  7204. (save-excursion
  7205. (and (outline-next-heading)
  7206. (org-flag-heading nil))) ; show the next heading
  7207. (org-add-note))))
  7208. (defun org-agenda-change-all-lines (newhead hdmarker
  7209. &optional fixface just-this)
  7210. "Change all lines in the agenda buffer which match HDMARKER.
  7211. The new content of the line will be NEWHEAD (as modified by
  7212. `org-agenda-format-item'). HDMARKER is checked with
  7213. `equal' against all `org-hd-marker' text properties in the file.
  7214. If FIXFACE is non-nil, the face of each item is modified according to
  7215. the new TODO state.
  7216. If JUST-THIS is non-nil, change just the current line, not all.
  7217. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7218. (let* ((inhibit-read-only t)
  7219. (line (org-current-line))
  7220. (org-agenda-buffer (current-buffer))
  7221. (thetags (with-current-buffer (marker-buffer hdmarker)
  7222. (save-excursion (save-restriction (widen)
  7223. (goto-char hdmarker)
  7224. (org-get-tags-at)))))
  7225. props m pl undone-face done-face finish new dotime cat tags)
  7226. (save-excursion
  7227. (goto-char (point-max))
  7228. (beginning-of-line 1)
  7229. (while (not finish)
  7230. (setq finish (bobp))
  7231. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7232. (or (not just-this) (= (org-current-line) line))
  7233. (equal m hdmarker))
  7234. (setq props (text-properties-at (point))
  7235. dotime (org-get-at-bol 'dotime)
  7236. cat (org-get-at-bol 'org-category)
  7237. tags thetags
  7238. new
  7239. (let ((org-prefix-format-compiled
  7240. (or (get-text-property (point) 'format)
  7241. org-prefix-format-compiled))
  7242. (extra (org-get-at-bol 'extra)))
  7243. (with-current-buffer (marker-buffer hdmarker)
  7244. (save-excursion
  7245. (save-restriction
  7246. (widen)
  7247. (org-agenda-format-item extra newhead cat tags dotime)))))
  7248. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7249. undone-face (org-get-at-bol 'undone-face)
  7250. done-face (org-get-at-bol 'done-face))
  7251. (beginning-of-line 1)
  7252. (cond
  7253. ((equal new "")
  7254. (and (looking-at ".*\n?") (replace-match "")))
  7255. ((looking-at ".*")
  7256. (replace-match new t t)
  7257. (beginning-of-line 1)
  7258. (add-text-properties (point-at-bol) (point-at-eol) props)
  7259. (when fixface
  7260. (add-text-properties
  7261. (point-at-bol) (point-at-eol)
  7262. (list 'face
  7263. (if org-last-todo-state-is-todo
  7264. undone-face done-face))))
  7265. (org-agenda-highlight-todo 'line)
  7266. (beginning-of-line 1))
  7267. (t (error "Line update did not work"))))
  7268. (beginning-of-line 0)))
  7269. (org-finalize-agenda)))
  7270. (defun org-agenda-align-tags (&optional line)
  7271. "Align all tags in agenda items to `org-agenda-tags-column'."
  7272. (let ((inhibit-read-only t) l c)
  7273. (save-excursion
  7274. (goto-char (if line (point-at-bol) (point-min)))
  7275. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7276. (if line (point-at-eol) nil) t)
  7277. (add-text-properties
  7278. (match-beginning 2) (match-end 2)
  7279. (list 'face (delq nil (let ((prop (get-text-property
  7280. (match-beginning 2) 'face)))
  7281. (or (listp prop) (setq prop (list prop)))
  7282. (if (memq 'org-tag prop)
  7283. prop
  7284. (cons 'org-tag prop))))))
  7285. (setq l (- (match-end 2) (match-beginning 2))
  7286. c (if (< org-agenda-tags-column 0)
  7287. (- (abs org-agenda-tags-column) l)
  7288. org-agenda-tags-column))
  7289. (delete-region (match-beginning 1) (match-end 1))
  7290. (goto-char (match-beginning 1))
  7291. (insert (org-add-props
  7292. (make-string (max 1 (- c (current-column))) ?\ )
  7293. (plist-put (copy-sequence (text-properties-at (point)))
  7294. 'face nil))))
  7295. (goto-char (point-min))
  7296. (org-font-lock-add-tag-faces (point-max)))))
  7297. (defun org-agenda-priority-up ()
  7298. "Increase the priority of line at point, also in Org-mode file."
  7299. (interactive)
  7300. (org-agenda-priority 'up))
  7301. (defun org-agenda-priority-down ()
  7302. "Decrease the priority of line at point, also in Org-mode file."
  7303. (interactive)
  7304. (org-agenda-priority 'down))
  7305. (defun org-agenda-priority (&optional force-direction)
  7306. "Set the priority of line at point, also in Org-mode file.
  7307. This changes the line at point, all other lines in the agenda referring to
  7308. the same tree node, and the headline of the tree node in the Org-mode file."
  7309. (interactive)
  7310. (unless org-enable-priority-commands
  7311. (error "Priority commands are disabled"))
  7312. (org-agenda-check-no-diary)
  7313. (let* ((marker (or (org-get-at-bol 'org-marker)
  7314. (org-agenda-error)))
  7315. (hdmarker (org-get-at-bol 'org-hd-marker))
  7316. (buffer (marker-buffer hdmarker))
  7317. (pos (marker-position hdmarker))
  7318. (inhibit-read-only t)
  7319. newhead)
  7320. (org-with-remote-undo buffer
  7321. (with-current-buffer buffer
  7322. (widen)
  7323. (goto-char pos)
  7324. (org-show-context 'agenda)
  7325. (save-excursion
  7326. (and (outline-next-heading)
  7327. (org-flag-heading nil))) ; show the next heading
  7328. (funcall 'org-priority force-direction)
  7329. (end-of-line 1)
  7330. (setq newhead (org-get-heading)))
  7331. (org-agenda-change-all-lines newhead hdmarker)
  7332. (beginning-of-line 1))))
  7333. ;; FIXME: should fix the tags property of the agenda line.
  7334. (defun org-agenda-set-tags (&optional tag onoff)
  7335. "Set tags for the current headline."
  7336. (interactive)
  7337. (org-agenda-check-no-diary)
  7338. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7339. (call-interactively 'org-change-tag-in-region)
  7340. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7341. (org-agenda-error)))
  7342. (buffer (marker-buffer hdmarker))
  7343. (pos (marker-position hdmarker))
  7344. (inhibit-read-only t)
  7345. newhead)
  7346. (org-with-remote-undo buffer
  7347. (with-current-buffer buffer
  7348. (widen)
  7349. (goto-char pos)
  7350. (save-excursion
  7351. (org-show-context 'agenda))
  7352. (save-excursion
  7353. (and (outline-next-heading)
  7354. (org-flag-heading nil))) ; show the next heading
  7355. (goto-char pos)
  7356. (if tag
  7357. (org-toggle-tag tag onoff)
  7358. (call-interactively 'org-set-tags))
  7359. (end-of-line 1)
  7360. (setq newhead (org-get-heading)))
  7361. (org-agenda-change-all-lines newhead hdmarker)
  7362. (beginning-of-line 1)))))
  7363. (defun org-agenda-set-property ()
  7364. "Set a property for the current headline."
  7365. (interactive)
  7366. (org-agenda-check-no-diary)
  7367. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7368. (org-agenda-error)))
  7369. (buffer (marker-buffer hdmarker))
  7370. (pos (marker-position hdmarker))
  7371. (inhibit-read-only t)
  7372. newhead)
  7373. (org-with-remote-undo buffer
  7374. (with-current-buffer buffer
  7375. (widen)
  7376. (goto-char pos)
  7377. (save-excursion
  7378. (org-show-context 'agenda))
  7379. (save-excursion
  7380. (and (outline-next-heading)
  7381. (org-flag-heading nil))) ; show the next heading
  7382. (goto-char pos)
  7383. (call-interactively 'org-set-property)))))
  7384. (defun org-agenda-set-effort ()
  7385. "Set the effort property for the current headline."
  7386. (interactive)
  7387. (org-agenda-check-no-diary)
  7388. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7389. (org-agenda-error)))
  7390. (buffer (marker-buffer hdmarker))
  7391. (pos (marker-position hdmarker))
  7392. (inhibit-read-only t)
  7393. newhead)
  7394. (org-with-remote-undo buffer
  7395. (with-current-buffer buffer
  7396. (widen)
  7397. (goto-char pos)
  7398. (save-excursion
  7399. (org-show-context 'agenda))
  7400. (save-excursion
  7401. (and (outline-next-heading)
  7402. (org-flag-heading nil))) ; show the next heading
  7403. (goto-char pos)
  7404. (call-interactively 'org-set-effort)
  7405. (end-of-line 1)
  7406. (setq newhead (org-get-heading)))
  7407. (org-agenda-change-all-lines newhead hdmarker))))
  7408. (defun org-agenda-toggle-archive-tag ()
  7409. "Toggle the archive tag for the current entry."
  7410. (interactive)
  7411. (org-agenda-check-no-diary)
  7412. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7413. (org-agenda-error)))
  7414. (buffer (marker-buffer hdmarker))
  7415. (pos (marker-position hdmarker))
  7416. (inhibit-read-only t)
  7417. newhead)
  7418. (org-with-remote-undo buffer
  7419. (with-current-buffer buffer
  7420. (widen)
  7421. (goto-char pos)
  7422. (org-show-context 'agenda)
  7423. (save-excursion
  7424. (and (outline-next-heading)
  7425. (org-flag-heading nil))) ; show the next heading
  7426. (call-interactively 'org-toggle-archive-tag)
  7427. (end-of-line 1)
  7428. (setq newhead (org-get-heading)))
  7429. (org-agenda-change-all-lines newhead hdmarker)
  7430. (beginning-of-line 1))))
  7431. (defun org-agenda-do-date-later (arg)
  7432. (interactive "P")
  7433. (cond
  7434. ((or (equal arg '(16))
  7435. (memq last-command
  7436. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7437. (setq this-command 'org-agenda-date-later-minutes)
  7438. (org-agenda-date-later-minutes 1))
  7439. ((or (equal arg '(4))
  7440. (memq last-command
  7441. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7442. (setq this-command 'org-agenda-date-later-hours)
  7443. (org-agenda-date-later-hours 1))
  7444. (t
  7445. (org-agenda-date-later (prefix-numeric-value arg)))))
  7446. (defun org-agenda-do-date-earlier (arg)
  7447. (interactive "P")
  7448. (cond
  7449. ((or (equal arg '(16))
  7450. (memq last-command
  7451. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7452. (setq this-command 'org-agenda-date-earlier-minutes)
  7453. (org-agenda-date-earlier-minutes 1))
  7454. ((or (equal arg '(4))
  7455. (memq last-command
  7456. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7457. (setq this-command 'org-agenda-date-earlier-hours)
  7458. (org-agenda-date-earlier-hours 1))
  7459. (t
  7460. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7461. (defun org-agenda-date-later (arg &optional what)
  7462. "Change the date of this item to ARG day(s) later."
  7463. (interactive "p")
  7464. (org-agenda-check-type t 'agenda 'timeline)
  7465. (org-agenda-check-no-diary)
  7466. (let* ((marker (or (org-get-at-bol 'org-marker)
  7467. (org-agenda-error)))
  7468. (buffer (marker-buffer marker))
  7469. (pos (marker-position marker))
  7470. cdate today)
  7471. (org-with-remote-undo buffer
  7472. (with-current-buffer buffer
  7473. (widen)
  7474. (goto-char pos)
  7475. (if (not (org-at-timestamp-p))
  7476. (error "Cannot find time stamp"))
  7477. (when (and org-agenda-move-date-from-past-immediately-to-today
  7478. (equal arg 1)
  7479. (or (not what) (eq what 'day))
  7480. (not (save-match-data (org-at-date-range-p))))
  7481. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7482. cdate (calendar-absolute-from-gregorian
  7483. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7484. today (org-today))
  7485. (if (> today cdate)
  7486. ;; immediately shift to today
  7487. (setq arg (- today cdate))))
  7488. (org-timestamp-change arg (or what 'day))
  7489. (when (and (org-at-date-range-p)
  7490. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7491. (let ((end org-last-changed-timestamp))
  7492. (org-timestamp-change arg (or what 'day))
  7493. (setq org-last-changed-timestamp
  7494. (concat org-last-changed-timestamp "--" end)))))
  7495. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7496. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7497. (defun org-agenda-date-earlier (arg &optional what)
  7498. "Change the date of this item to ARG day(s) earlier."
  7499. (interactive "p")
  7500. (org-agenda-date-later (- arg) what))
  7501. (defun org-agenda-date-later-minutes (arg)
  7502. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7503. (interactive "p")
  7504. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7505. (org-agenda-date-later arg 'minute))
  7506. (defun org-agenda-date-earlier-minutes (arg)
  7507. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7508. (interactive "p")
  7509. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7510. (org-agenda-date-earlier arg 'minute))
  7511. (defun org-agenda-date-later-hours (arg)
  7512. "Change the time of this item, in hour steps."
  7513. (interactive "p")
  7514. (org-agenda-date-later arg 'hour))
  7515. (defun org-agenda-date-earlier-hours (arg)
  7516. "Change the time of this item, in hour steps."
  7517. (interactive "p")
  7518. (org-agenda-date-earlier arg 'hour))
  7519. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7520. "Show new date stamp via text properties."
  7521. ;; We use text properties to make this undoable
  7522. (let ((inhibit-read-only t)
  7523. (buffer-invisibility-spec))
  7524. (setq stamp (concat " " prefix " => " stamp))
  7525. (save-excursion
  7526. (goto-char (point-max))
  7527. (while (not (bobp))
  7528. (when (equal marker (org-get-at-bol 'org-marker))
  7529. (org-move-to-column (- (window-width) (length stamp)) t)
  7530. (org-agenda-fix-tags-filter-overlays-at (point))
  7531. (if (featurep 'xemacs)
  7532. ;; Use `duplicable' property to trigger undo recording
  7533. (let ((ex (make-extent nil nil))
  7534. (gl (make-glyph stamp)))
  7535. (set-glyph-face gl 'secondary-selection)
  7536. (set-extent-properties
  7537. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7538. (insert-extent ex (1- (point)) (point-at-eol)))
  7539. (add-text-properties
  7540. (1- (point)) (point-at-eol)
  7541. (list 'display (org-add-props stamp nil
  7542. 'face 'secondary-selection))))
  7543. (beginning-of-line 1))
  7544. (beginning-of-line 0)))))
  7545. (defun org-agenda-date-prompt (arg)
  7546. "Change the date of this item. Date is prompted for, with default today.
  7547. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7548. be used to request time specification in the time stamp."
  7549. (interactive "P")
  7550. (org-agenda-check-type t 'agenda 'timeline)
  7551. (org-agenda-check-no-diary)
  7552. (let* ((marker (or (org-get-at-bol 'org-marker)
  7553. (org-agenda-error)))
  7554. (buffer (marker-buffer marker))
  7555. (pos (marker-position marker)))
  7556. (org-with-remote-undo buffer
  7557. (with-current-buffer buffer
  7558. (widen)
  7559. (goto-char pos)
  7560. (if (not (org-at-timestamp-p t))
  7561. (error "Cannot find time stamp"))
  7562. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7563. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7564. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7565. (defun org-agenda-schedule (arg &optional time)
  7566. "Schedule the item at point.
  7567. ARG is passed through to `org-schedule'."
  7568. (interactive "P")
  7569. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7570. (org-agenda-check-no-diary)
  7571. (let* ((marker (or (org-get-at-bol 'org-marker)
  7572. (org-agenda-error)))
  7573. (type (marker-insertion-type marker))
  7574. (buffer (marker-buffer marker))
  7575. (pos (marker-position marker))
  7576. (org-insert-labeled-timestamps-at-point nil)
  7577. ts)
  7578. (set-marker-insertion-type marker t)
  7579. (org-with-remote-undo buffer
  7580. (with-current-buffer buffer
  7581. (widen)
  7582. (goto-char pos)
  7583. (setq ts (org-schedule arg time)))
  7584. (org-agenda-show-new-time marker ts "S"))
  7585. (message "Item scheduled for %s" ts)))
  7586. (defun org-agenda-deadline (arg &optional time)
  7587. "Schedule the item at point.
  7588. ARG is passed through to `org-deadline'."
  7589. (interactive "P")
  7590. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7591. (org-agenda-check-no-diary)
  7592. (let* ((marker (or (org-get-at-bol 'org-marker)
  7593. (org-agenda-error)))
  7594. (buffer (marker-buffer marker))
  7595. (pos (marker-position marker))
  7596. (org-insert-labeled-timestamps-at-point nil)
  7597. ts)
  7598. (org-with-remote-undo buffer
  7599. (with-current-buffer buffer
  7600. (widen)
  7601. (goto-char pos)
  7602. (setq ts (org-deadline arg time)))
  7603. (org-agenda-show-new-time marker ts "D"))
  7604. (message "Deadline for this item set to %s" ts)))
  7605. (defun org-agenda-action ()
  7606. "Select entry for agenda action, or execute an agenda action.
  7607. This command prompts for another letter. Valid inputs are:
  7608. m Mark the entry at point for an agenda action
  7609. s Schedule the marked entry to the date at the cursor
  7610. d Set the deadline of the marked entry to the date at the cursor
  7611. r Call `org-remember' with cursor date as the default date
  7612. c Call `org-capture' with cursor date as the default date
  7613. SPC Show marked entry in other window
  7614. TAB Visit marked entry in other window
  7615. The cursor may be at a date in the calendar, or in the Org agenda."
  7616. (interactive)
  7617. (let (ans)
  7618. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7619. (setq ans (read-char-exclusive))
  7620. (cond
  7621. ((equal ans ?m)
  7622. ;; Mark this entry
  7623. (if (eq major-mode 'org-agenda-mode)
  7624. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7625. (org-get-at-bol 'org-marker))))
  7626. (if m
  7627. (progn
  7628. (move-marker org-agenda-action-marker
  7629. (marker-position m) (marker-buffer m))
  7630. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7631. (error "Don't know which entry to mark")))
  7632. (error "This command works only in the agenda")))
  7633. ((equal ans ?s)
  7634. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7635. ((equal ans ?d)
  7636. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7637. ((equal ans ?r)
  7638. (org-agenda-do-action '(org-remember) t))
  7639. ((equal ans ?c)
  7640. (org-agenda-do-action '(org-capture) t))
  7641. ((equal ans ?\ )
  7642. (let ((cw (selected-window)))
  7643. (org-switch-to-buffer-other-window
  7644. (marker-buffer org-agenda-action-marker))
  7645. (goto-char org-agenda-action-marker)
  7646. (org-show-context 'agenda)
  7647. (select-window cw)))
  7648. ((equal ans ?\C-i)
  7649. (org-switch-to-buffer-other-window
  7650. (marker-buffer org-agenda-action-marker))
  7651. (goto-char org-agenda-action-marker)
  7652. (org-show-context 'agenda))
  7653. (t (error "Invalid agenda action %c" ans)))))
  7654. (defun org-agenda-do-action (form &optional current-buffer)
  7655. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7656. (let ((org-overriding-default-time (org-get-cursor-date)))
  7657. (if current-buffer
  7658. (eval form)
  7659. (if (not (marker-buffer org-agenda-action-marker))
  7660. (error "No entry has been selected for agenda action")
  7661. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7662. (save-excursion
  7663. (save-restriction
  7664. (widen)
  7665. (goto-char org-agenda-action-marker)
  7666. (eval form))))))))
  7667. (defun org-agenda-clock-in (&optional arg)
  7668. "Start the clock on the currently selected item."
  7669. (interactive "P")
  7670. (org-agenda-check-no-diary)
  7671. (if (equal arg '(4))
  7672. (org-clock-in arg)
  7673. (let* ((marker (or (org-get-at-bol 'org-marker)
  7674. (org-agenda-error)))
  7675. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7676. marker))
  7677. (pos (marker-position marker))
  7678. newhead)
  7679. (org-with-remote-undo (marker-buffer marker)
  7680. (with-current-buffer (marker-buffer marker)
  7681. (widen)
  7682. (goto-char pos)
  7683. (org-show-context 'agenda)
  7684. (org-show-entry)
  7685. (org-cycle-hide-drawers 'children)
  7686. (org-clock-in arg)
  7687. (setq newhead (org-get-heading)))
  7688. (org-agenda-change-all-lines newhead hdmarker)))))
  7689. (defun org-agenda-clock-out ()
  7690. "Stop the currently running clock."
  7691. (interactive)
  7692. (unless (marker-buffer org-clock-marker)
  7693. (error "No running clock"))
  7694. (let ((marker (make-marker)) newhead)
  7695. (org-with-remote-undo (marker-buffer org-clock-marker)
  7696. (with-current-buffer (marker-buffer org-clock-marker)
  7697. (save-excursion
  7698. (save-restriction
  7699. (widen)
  7700. (goto-char org-clock-marker)
  7701. (org-back-to-heading t)
  7702. (move-marker marker (point))
  7703. (org-clock-out)
  7704. (setq newhead (org-get-heading))))))
  7705. (org-agenda-change-all-lines newhead marker)
  7706. (move-marker marker nil)))
  7707. (defun org-agenda-clock-cancel (&optional arg)
  7708. "Cancel the currently running clock."
  7709. (interactive "P")
  7710. (unless (marker-buffer org-clock-marker)
  7711. (error "No running clock"))
  7712. (org-with-remote-undo (marker-buffer org-clock-marker)
  7713. (org-clock-cancel)))
  7714. (defun org-agenda-clock-goto ()
  7715. "Jump to the currently clocked in task within the agenda.
  7716. If the currently clocked in task is not listed in the agenda
  7717. buffer, display it in another window."
  7718. (interactive)
  7719. (let (pos)
  7720. (mapc (lambda (o)
  7721. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7722. (setq pos (overlay-start o))))
  7723. (overlays-in (point-min) (point-max)))
  7724. (cond (pos (goto-char pos))
  7725. ;; If the currently clocked entry is not in the agenda
  7726. ;; buffer, we visit it in another window:
  7727. (org-clock-current-task
  7728. (org-switch-to-buffer-other-window (org-clock-goto)))
  7729. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7730. (defun org-agenda-diary-entry-in-org-file ()
  7731. "Make a diary entry in the file `org-agenda-diary-file'."
  7732. (let (d1 d2 char (text "") dp1 dp2)
  7733. (if (equal (buffer-name) "*Calendar*")
  7734. (setq d1 (calendar-cursor-to-date t)
  7735. d2 (car calendar-mark-ring))
  7736. (setq dp1 (get-text-property (point-at-bol) 'day))
  7737. (unless dp1 (error "No date defined in current line"))
  7738. (setq d1 (calendar-gregorian-from-absolute dp1)
  7739. d2 (and (ignore-errors (mark))
  7740. (save-excursion
  7741. (goto-char (mark))
  7742. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7743. (calendar-gregorian-from-absolute dp2))))
  7744. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7745. (setq char (read-char-exclusive))
  7746. (cond
  7747. ((equal char ?d)
  7748. (setq text (read-string "Day entry: "))
  7749. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7750. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7751. ((equal char ?a)
  7752. (setq d1 (list (car d1) (nth 1 d1)
  7753. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7754. (nth 2 d1))))
  7755. (setq text (read-string "Anniversary (use %d to show years): "))
  7756. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7757. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7758. ((equal char ?b)
  7759. (setq text (read-string "Block entry: "))
  7760. (unless (and d1 d2 (not (equal d1 d2)))
  7761. (error "No block of days selected"))
  7762. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7763. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7764. ((equal char ?j)
  7765. (org-switch-to-buffer-other-window
  7766. (find-file-noselect org-agenda-diary-file))
  7767. (require 'org-datetree)
  7768. (org-datetree-find-date-create d1)
  7769. (org-reveal t))
  7770. (t (error "Invalid selection character `%c'" char)))))
  7771. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7772. "Where in `org-agenda-diary-file' should new entries be added?
  7773. Valid values:
  7774. date-tree in the date tree, as child of the date
  7775. top-level as top-level entries at the end of the file."
  7776. :group 'org-agenda
  7777. :type '(choice
  7778. (const :tag "in a date tree" date-tree)
  7779. (const :tag "as top level at end of file" top-level)))
  7780. (defcustom org-agenda-insert-diary-extract-time nil
  7781. "Non-nil means extract any time specification from the diary entry."
  7782. :group 'org-agenda
  7783. :version "24.1"
  7784. :type 'boolean)
  7785. (defcustom org-agenda-bulk-mark-char ">"
  7786. "A single-character string to be used as the bulk mark."
  7787. :group 'org-agenda
  7788. :version "24.1"
  7789. :type 'string)
  7790. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7791. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7792. If TEXT is not empty, it will become the headline of the new entry, and
  7793. the resulting entry will not be shown. When TEXT is empty, switch to
  7794. `org-agenda-diary-file' and let the user finish the entry there."
  7795. (let ((cw (current-window-configuration)))
  7796. (org-switch-to-buffer-other-window
  7797. (find-file-noselect org-agenda-diary-file))
  7798. (widen)
  7799. (goto-char (point-min))
  7800. (cond
  7801. ((eq type 'anniversary)
  7802. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7803. (progn
  7804. (or (org-at-heading-p t)
  7805. (progn
  7806. (outline-next-heading)
  7807. (insert "* Anniversaries\n\n")
  7808. (beginning-of-line -1)))))
  7809. (outline-next-heading)
  7810. (org-back-over-empty-lines)
  7811. (backward-char 1)
  7812. (insert "\n")
  7813. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7814. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7815. ((eq type 'day)
  7816. (let ((org-prefix-has-time t)
  7817. (org-agenda-time-leading-zero t)
  7818. fmt time time2)
  7819. (if org-agenda-insert-diary-extract-time
  7820. ;; Use org-agenda-format-item to parse text for a time-range and
  7821. ;; remove it. FIXME: This is a hack, we should refactor
  7822. ;; that function to make time extraction available separately
  7823. (setq fmt (org-agenda-format-item nil text nil nil t)
  7824. time (get-text-property 0 'time fmt)
  7825. time2 (if (> (length time) 0)
  7826. ;; split-string removes trailing ...... if
  7827. ;; no end time given. First space
  7828. ;; separates time from date.
  7829. (concat " " (car (split-string time "\\.")))
  7830. nil)
  7831. text (get-text-property 0 'txt fmt)))
  7832. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7833. (org-agenda-insert-diary-as-top-level text)
  7834. (require 'org-datetree)
  7835. (org-datetree-find-date-create d1)
  7836. (org-agenda-insert-diary-make-new-entry text))
  7837. (org-insert-time-stamp (org-time-from-absolute
  7838. (calendar-absolute-from-gregorian d1))
  7839. nil nil nil nil time2))
  7840. (end-of-line 0))
  7841. ((eq type 'block)
  7842. (if (> (calendar-absolute-from-gregorian d1)
  7843. (calendar-absolute-from-gregorian d2))
  7844. (setq d1 (prog1 d2 (setq d2 d1))))
  7845. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7846. (org-agenda-insert-diary-as-top-level text)
  7847. (require 'org-datetree)
  7848. (org-datetree-find-date-create d1)
  7849. (org-agenda-insert-diary-make-new-entry text))
  7850. (org-insert-time-stamp (org-time-from-absolute
  7851. (calendar-absolute-from-gregorian d1)))
  7852. (insert "--")
  7853. (org-insert-time-stamp (org-time-from-absolute
  7854. (calendar-absolute-from-gregorian d2)))
  7855. (end-of-line 0)))
  7856. (if (string-match "\\S-" text)
  7857. (progn
  7858. (set-window-configuration cw)
  7859. (message "%s entry added to %s"
  7860. (capitalize (symbol-name type))
  7861. (abbreviate-file-name org-agenda-diary-file)))
  7862. (org-reveal t)
  7863. (message "Please finish entry here"))))
  7864. (defun org-agenda-insert-diary-as-top-level (text)
  7865. "Make new entry as a top-level entry at the end of the file.
  7866. Add TEXT as headline, and position the cursor in the second line so that
  7867. a timestamp can be added there."
  7868. (widen)
  7869. (goto-char (point-max))
  7870. (or (bolp) (insert "\n"))
  7871. (insert "* " text "\n")
  7872. (if org-adapt-indentation (org-indent-to-column 2)))
  7873. (defun org-agenda-insert-diary-make-new-entry (text)
  7874. "Make new entry as last child of current entry.
  7875. Add TEXT as headline, and position the cursor in the second line so that
  7876. a timestamp can be added there."
  7877. (let ((org-show-following-heading t)
  7878. (org-show-siblings t)
  7879. (org-show-hierarchy-above t)
  7880. (org-show-entry-below t)
  7881. col)
  7882. (outline-next-heading)
  7883. (org-back-over-empty-lines)
  7884. (or (looking-at "[ \t]*$")
  7885. (progn (insert "\n") (backward-char 1)))
  7886. (org-insert-heading nil t)
  7887. (org-do-demote)
  7888. (setq col (current-column))
  7889. (insert text "\n")
  7890. (if org-adapt-indentation (org-indent-to-column col))
  7891. (let ((org-show-following-heading t)
  7892. (org-show-siblings t)
  7893. (org-show-hierarchy-above t)
  7894. (org-show-entry-below t))
  7895. (org-show-context))))
  7896. (defun org-agenda-diary-entry ()
  7897. "Make a diary entry, like the `i' command from the calendar.
  7898. All the standard commands work: block, weekly etc.
  7899. When `org-agenda-diary-file' points to a file,
  7900. `org-agenda-diary-entry-in-org-file' is called instead to create
  7901. entries in that Org-mode file."
  7902. (interactive)
  7903. (org-agenda-check-type t 'agenda 'timeline)
  7904. (if (not (eq org-agenda-diary-file 'diary-file))
  7905. (org-agenda-diary-entry-in-org-file)
  7906. (require 'diary-lib)
  7907. (let* ((char (progn
  7908. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7909. (read-char-exclusive)))
  7910. (cmd (cdr (assoc char
  7911. '((?d . insert-diary-entry)
  7912. (?w . insert-weekly-diary-entry)
  7913. (?m . insert-monthly-diary-entry)
  7914. (?y . insert-yearly-diary-entry)
  7915. (?a . insert-anniversary-diary-entry)
  7916. (?b . insert-block-diary-entry)
  7917. (?c . insert-cyclic-diary-entry)))))
  7918. (oldf (symbol-function 'calendar-cursor-to-date))
  7919. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7920. (point (point))
  7921. (mark (or (mark t) (point))))
  7922. (unless cmd
  7923. (error "No command associated with <%c>" char))
  7924. (unless (and (get-text-property point 'day)
  7925. (or (not (equal ?b char))
  7926. (get-text-property mark 'day)))
  7927. (error "Don't know which date to use for diary entry"))
  7928. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7929. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7930. (let ((calendar-mark-ring
  7931. (list (calendar-gregorian-from-absolute
  7932. (or (get-text-property mark 'day)
  7933. (get-text-property point 'day))))))
  7934. (unwind-protect
  7935. (progn
  7936. (fset 'calendar-cursor-to-date
  7937. (lambda (&optional error dummy)
  7938. (calendar-gregorian-from-absolute
  7939. (get-text-property point 'day))))
  7940. (call-interactively cmd))
  7941. (fset 'calendar-cursor-to-date oldf))))))
  7942. (defun org-agenda-execute-calendar-command (cmd)
  7943. "Execute a calendar command from the agenda, with the date associated to
  7944. the cursor position."
  7945. (org-agenda-check-type t 'agenda 'timeline)
  7946. (require 'diary-lib)
  7947. (unless (get-text-property (point) 'day)
  7948. (error "Don't know which date to use for calendar command"))
  7949. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7950. (point (point))
  7951. (date (calendar-gregorian-from-absolute
  7952. (get-text-property point 'day)))
  7953. ;; the following 2 vars are needed in the calendar
  7954. (displayed-month (car date))
  7955. (displayed-year (nth 2 date)))
  7956. (unwind-protect
  7957. (progn
  7958. (fset 'calendar-cursor-to-date
  7959. (lambda (&optional error dummy)
  7960. (calendar-gregorian-from-absolute
  7961. (get-text-property point 'day))))
  7962. (call-interactively cmd))
  7963. (fset 'calendar-cursor-to-date oldf))))
  7964. (defun org-agenda-phases-of-moon ()
  7965. "Display the phases of the moon for the 3 months around the cursor date."
  7966. (interactive)
  7967. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7968. (defun org-agenda-holidays ()
  7969. "Display the holidays for the 3 months around the cursor date."
  7970. (interactive)
  7971. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7972. (defvar calendar-longitude)
  7973. (defvar calendar-latitude)
  7974. (defvar calendar-location-name)
  7975. (defun org-agenda-sunrise-sunset (arg)
  7976. "Display sunrise and sunset for the cursor date.
  7977. Latitude and longitude can be specified with the variables
  7978. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7979. argument, latitude and longitude will be prompted for."
  7980. (interactive "P")
  7981. (require 'solar)
  7982. (let ((calendar-longitude (if arg nil calendar-longitude))
  7983. (calendar-latitude (if arg nil calendar-latitude))
  7984. (calendar-location-name
  7985. (if arg "the given coordinates" calendar-location-name)))
  7986. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7987. (defun org-agenda-goto-calendar ()
  7988. "Open the Emacs calendar with the date at the cursor."
  7989. (interactive)
  7990. (org-agenda-check-type t 'agenda 'timeline)
  7991. (let* ((day (or (get-text-property (point) 'day)
  7992. (error "Don't know which date to open in calendar")))
  7993. (date (calendar-gregorian-from-absolute day))
  7994. (calendar-move-hook nil)
  7995. (calendar-view-holidays-initially-flag nil)
  7996. (calendar-view-diary-initially-flag nil))
  7997. (calendar)
  7998. (calendar-goto-date date)))
  7999. ;;;###autoload
  8000. (defun org-calendar-goto-agenda ()
  8001. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8002. This is a command that has to be installed in `calendar-mode-map'."
  8003. (interactive)
  8004. (org-agenda-list nil (calendar-absolute-from-gregorian
  8005. (calendar-cursor-to-date))
  8006. nil))
  8007. (defun org-agenda-convert-date ()
  8008. (interactive)
  8009. (org-agenda-check-type t 'agenda 'timeline)
  8010. (let ((day (get-text-property (point) 'day))
  8011. date s)
  8012. (unless day
  8013. (error "Don't know which date to convert"))
  8014. (setq date (calendar-gregorian-from-absolute day))
  8015. (setq s (concat
  8016. "Gregorian: " (calendar-date-string date) "\n"
  8017. "ISO: " (calendar-iso-date-string date) "\n"
  8018. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8019. "Julian: " (calendar-julian-date-string date) "\n"
  8020. "Astron. JD: " (calendar-astro-date-string date)
  8021. " (Julian date number at noon UTC)\n"
  8022. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8023. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8024. "French: " (calendar-french-date-string date) "\n"
  8025. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8026. "Mayan: " (calendar-mayan-date-string date) "\n"
  8027. "Coptic: " (calendar-coptic-date-string date) "\n"
  8028. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8029. "Persian: " (calendar-persian-date-string date) "\n"
  8030. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8031. (with-output-to-temp-buffer "*Dates*"
  8032. (princ s))
  8033. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8034. ;;; Bulk commands
  8035. (defvar org-agenda-bulk-marked-entries nil
  8036. "List of markers that refer to marked entries in the agenda.")
  8037. (defun org-agenda-bulk-marked-p ()
  8038. (eq (get-char-property (point-at-bol) 'type)
  8039. 'org-marked-entry-overlay))
  8040. (defun org-agenda-bulk-mark (&optional arg)
  8041. "Mark the entry at point for future bulk action."
  8042. (interactive "p")
  8043. (dotimes (i (or arg 1))
  8044. (unless (org-get-at-bol 'org-agenda-diary-link)
  8045. (let* ((m (org-get-at-bol 'org-hd-marker))
  8046. ov)
  8047. (unless (org-agenda-bulk-marked-p)
  8048. (unless m (error "Nothing to mark at point"))
  8049. (push m org-agenda-bulk-marked-entries)
  8050. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8051. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8052. (org-get-todo-face "TODO")
  8053. 'evaporate)
  8054. (overlay-put ov 'type 'org-marked-entry-overlay))
  8055. (beginning-of-line 2)
  8056. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8057. (beginning-of-line 2))
  8058. (message "%d entries marked for bulk action"
  8059. (length org-agenda-bulk-marked-entries))))))
  8060. (defun org-agenda-bulk-mark-all ()
  8061. "Mark all entries for future agenda bulk action."
  8062. (interactive)
  8063. (org-agenda-bulk-mark-regexp "."))
  8064. (defun org-agenda-bulk-mark-regexp (regexp)
  8065. "Mark entries matching REGEXP for future agenda bulk action."
  8066. (interactive "sMark entries matching regexp: ")
  8067. (let ((entries-marked 0))
  8068. (save-excursion
  8069. (goto-char (point-min))
  8070. (goto-char (next-single-property-change (point) 'txt))
  8071. (while (re-search-forward regexp nil t)
  8072. (when (string-match regexp (get-text-property (point) 'txt))
  8073. (setq entries-marked (1+ entries-marked))
  8074. (call-interactively 'org-agenda-bulk-mark))))
  8075. (if (not entries-marked)
  8076. (message "No entry matching this regexp."))))
  8077. (defun org-agenda-bulk-unmark (&optional arg)
  8078. "Unmark the entry at point for future bulk action."
  8079. (interactive "P")
  8080. (if arg
  8081. (org-agenda-bulk-unmark-all)
  8082. (cond ((org-agenda-bulk-marked-p)
  8083. (org-agenda-bulk-remove-overlays
  8084. (point-at-bol) (+ 2 (point-at-bol)))
  8085. (setq org-agenda-bulk-marked-entries
  8086. (delete (org-get-at-bol 'org-hd-marker)
  8087. org-agenda-bulk-marked-entries))
  8088. (beginning-of-line 2)
  8089. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8090. (beginning-of-line 2))
  8091. (message "%d entries left marked for bulk action"
  8092. (length org-agenda-bulk-marked-entries)))
  8093. (t (message "No entry to unmark here")))))
  8094. (defun org-agenda-bulk-toggle ()
  8095. "Toggle marking the entry at point for bulk action."
  8096. (interactive)
  8097. (if (org-agenda-bulk-marked-p)
  8098. (org-agenda-bulk-unmark)
  8099. (org-agenda-bulk-mark)))
  8100. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8101. "Remove the mark overlays between BEG and END in the agenda buffer.
  8102. BEG and END default to the buffer limits.
  8103. This only removes the overlays, it does not remove the markers
  8104. from the list in `org-agenda-bulk-marked-entries'."
  8105. (interactive)
  8106. (mapc (lambda (ov)
  8107. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8108. (delete-overlay ov)))
  8109. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8110. (defun org-agenda-bulk-unmark-all ()
  8111. "Remove all marks in the agenda buffer.
  8112. This will remove the markers and the overlays."
  8113. (interactive)
  8114. (if (null org-agenda-bulk-marked-entries)
  8115. (message "No entry to unmark")
  8116. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8117. (setq org-agenda-bulk-marked-entries nil)
  8118. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8119. (defcustom org-agenda-persistent-marks nil
  8120. "Non-nil means marked items will stay marked after a bulk action.
  8121. You can interactively and temporarily toggle by typing `p' when you
  8122. are prompted for a bulk action."
  8123. :group 'org-agenda
  8124. :version "24.1"
  8125. :type 'boolean)
  8126. (defun org-agenda-bulk-action (&optional arg)
  8127. "Execute an remote-editing action on all marked entries.
  8128. The prefix arg is passed through to the command if possible."
  8129. (interactive "P")
  8130. ;; Make sure we have markers, and only valid ones
  8131. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8132. (mapc
  8133. (lambda (m)
  8134. (unless (and (markerp m)
  8135. (marker-buffer m)
  8136. (buffer-live-p (marker-buffer m))
  8137. (marker-position m))
  8138. (error "Marker %s for bulk command is invalid" m)))
  8139. org-agenda-bulk-marked-entries)
  8140. ;; Prompt for the bulk command
  8141. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8142. (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
  8143. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
  8144. (when org-agenda-bulk-custom-functions
  8145. (concat " Custom: ["
  8146. (mapconcat (lambda(f) (char-to-string (car f)))
  8147. org-agenda-bulk-custom-functions "")
  8148. "]"))))
  8149. (catch 'exit
  8150. (let* ((action (read-char-exclusive))
  8151. (org-log-refile (if org-log-refile 'time nil))
  8152. (entries (reverse org-agenda-bulk-marked-entries))
  8153. redo-at-end
  8154. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8155. (cond
  8156. ((equal action ?p)
  8157. (let ((org-agenda-persistent-marks
  8158. (not org-agenda-persistent-marks)))
  8159. (org-agenda-bulk-action)
  8160. (throw 'exit nil)))
  8161. ((equal action ?$)
  8162. (setq cmd '(org-agenda-archive)))
  8163. ((equal action ?A)
  8164. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8165. ((member action '(?r ?w))
  8166. (setq rfloc (org-refile-get-location
  8167. "Refile to"
  8168. (marker-buffer (car org-agenda-bulk-marked-entries))
  8169. org-refile-allow-creating-parent-nodes))
  8170. (if (nth 3 rfloc)
  8171. (setcar (nthcdr 3 rfloc)
  8172. (move-marker (make-marker) (nth 3 rfloc)
  8173. (or (get-file-buffer (nth 1 rfloc))
  8174. (find-buffer-visiting (nth 1 rfloc))
  8175. (error "This should not happen")))))
  8176. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8177. redo-at-end t))
  8178. ((equal action ?t)
  8179. (setq state (org-icompleting-read
  8180. "Todo state: "
  8181. (with-current-buffer (marker-buffer (car entries))
  8182. (mapcar 'list org-todo-keywords-1))))
  8183. (setq cmd `(let ((org-inhibit-blocking t)
  8184. (org-inhibit-logging 'note))
  8185. (org-agenda-todo ,state))))
  8186. ((memq action '(?- ?+))
  8187. (setq tag (org-icompleting-read
  8188. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8189. (with-current-buffer (marker-buffer (car entries))
  8190. (delq nil
  8191. (mapcar (lambda (x)
  8192. (if (stringp (car x)) x)) org-tag-alist)))))
  8193. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8194. ((memq action '(?s ?d))
  8195. (let* ((date (unless arg
  8196. (org-read-date
  8197. nil nil nil
  8198. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8199. (ans (if arg nil org-read-date-final-answer))
  8200. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8201. (setq cmd `(let* ((bound (fboundp 'read-string))
  8202. (old (and bound (symbol-function 'read-string))))
  8203. (unwind-protect
  8204. (progn
  8205. (fset 'read-string (lambda (&rest ignore) ,ans))
  8206. (eval '(,c1 arg)))
  8207. (if bound
  8208. (fset 'read-string old)
  8209. (fmakunbound 'read-string)))))))
  8210. ((equal action ?S)
  8211. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8212. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8213. (let ((days (read-number
  8214. (format "Scatter tasks across how many %sdays: "
  8215. (if arg "week" "")) 7)))
  8216. (setq cmd
  8217. `(let ((distance (1+ (random ,days))))
  8218. (if arg
  8219. (let ((dist distance)
  8220. (day-of-week
  8221. (calendar-day-of-week
  8222. (calendar-gregorian-from-absolute (org-today)))))
  8223. (dotimes (i (1+ dist))
  8224. (while (member day-of-week org-agenda-weekend-days)
  8225. (incf distance)
  8226. (incf day-of-week)
  8227. (if (= day-of-week 7)
  8228. (setq day-of-week 0)))
  8229. (incf day-of-week)
  8230. (if (= day-of-week 7)
  8231. (setq day-of-week 0)))))
  8232. ;; silently fail when try to replan a sexp entry
  8233. (condition-case nil
  8234. (let* ((date (calendar-gregorian-from-absolute
  8235. (+ (org-today) distance)))
  8236. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8237. (nth 2 date))))
  8238. (org-agenda-schedule nil time))
  8239. (error nil)))))))
  8240. ((assoc action org-agenda-bulk-custom-functions)
  8241. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8242. redo-at-end t))
  8243. ((equal action ?f)
  8244. (setq cmd (list (intern
  8245. (org-icompleting-read "Function: "
  8246. obarray 'fboundp t nil nil)))))
  8247. (t (error "Invalid bulk action")))
  8248. ;; Sort the markers, to make sure that parents are handled before children
  8249. (setq entries (sort entries
  8250. (lambda (a b)
  8251. (cond
  8252. ((equal (marker-buffer a) (marker-buffer b))
  8253. (< (marker-position a) (marker-position b)))
  8254. (t
  8255. (string< (buffer-name (marker-buffer a))
  8256. (buffer-name (marker-buffer b))))))))
  8257. ;; Now loop over all markers and apply cmd
  8258. (while (setq e (pop entries))
  8259. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8260. (if (not pos)
  8261. (progn (message "Skipping removed entry at %s" e)
  8262. (setq cntskip (1+ cntskip)))
  8263. (goto-char pos)
  8264. (let (org-loop-over-headlines-in-active-region)
  8265. (eval cmd))
  8266. (when (not org-agenda-persistent-marks)
  8267. (setq org-agenda-bulk-marked-entries
  8268. (delete e org-agenda-bulk-marked-entries)))
  8269. (setq cnt (1+ cnt))))
  8270. (when (not org-agenda-persistent-marks)
  8271. (org-agenda-bulk-unmark-all))
  8272. (when redo-at-end (org-agenda-redo))
  8273. (message "Acted on %d entries%s%s"
  8274. cnt
  8275. (if (= cntskip 0)
  8276. ""
  8277. (format ", skipped %d (disappeared before their turn)"
  8278. cntskip))
  8279. (if (not org-agenda-persistent-marks)
  8280. "" " (kept marked)"))))))
  8281. ;;; Flagging notes
  8282. (defun org-agenda-show-the-flagging-note ()
  8283. "Display the flagging note in the other window.
  8284. When called a second time in direct sequence, offer to remove the FLAGGING
  8285. tag and (if present) the flagging note."
  8286. (interactive)
  8287. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8288. (win (selected-window))
  8289. note heading newhead)
  8290. (unless hdmarker
  8291. (error "No linked entry at point"))
  8292. (if (and (eq this-command last-command)
  8293. (y-or-n-p "Unflag and remove any flagging note? "))
  8294. (progn
  8295. (org-agenda-remove-flag hdmarker)
  8296. (let ((win (get-buffer-window "*Flagging Note*")))
  8297. (and win (delete-window win)))
  8298. (message "Entry unflagged"))
  8299. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8300. (unless note
  8301. (error "No flagging note"))
  8302. (org-kill-new note)
  8303. (org-switch-to-buffer-other-window "*Flagging Note*")
  8304. (erase-buffer)
  8305. (insert note)
  8306. (goto-char (point-min))
  8307. (while (re-search-forward "\\\\n" nil t)
  8308. (replace-match "\n" t t))
  8309. (goto-char (point-min))
  8310. (select-window win)
  8311. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8312. (defun org-agenda-remove-flag (marker)
  8313. "Remove the FLAGGED tag and any flagging note in the entry."
  8314. (let (newhead)
  8315. (org-with-point-at marker
  8316. (org-toggle-tag "FLAGGED" 'off)
  8317. (org-entry-delete nil "THEFLAGGINGNOTE")
  8318. (setq newhead (org-get-heading)))
  8319. (org-agenda-change-all-lines newhead marker)
  8320. (message "Entry unflagged")))
  8321. (defun org-agenda-get-any-marker (&optional pos)
  8322. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8323. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8324. ;;; Appointment reminders
  8325. (defvar appt-time-msg-list)
  8326. ;;;###autoload
  8327. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8328. "Activate appointments found in `org-agenda-files'.
  8329. With a \\[universal-argument] prefix, refresh the list of
  8330. appointments.
  8331. If FILTER is t, interactively prompt the user for a regular
  8332. expression, and filter out entries that don't match it.
  8333. If FILTER is a string, use this string as a regular expression
  8334. for filtering entries out.
  8335. If FILTER is a function, filter out entries against which
  8336. calling the function returns nil. This function takes one
  8337. argument: an entry from `org-agenda-get-day-entries'.
  8338. FILTER can also be an alist with the car of each cell being
  8339. either 'headline or 'category. For example:
  8340. '((headline \"IMPORTANT\")
  8341. (category \"Work\"))
  8342. will only add headlines containing IMPORTANT or headlines
  8343. belonging to the \"Work\" category.
  8344. ARGS are symbols indicating what kind of entries to consider.
  8345. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8346. and :timestamp entries. See the docstring of `org-diary' for
  8347. details and examples."
  8348. (interactive "P")
  8349. (if refresh (setq appt-time-msg-list nil))
  8350. (if (eq filter t)
  8351. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8352. (let* ((cnt 0) ; count added events
  8353. (scope (or args '(:deadline :scheduled :timestamp)))
  8354. (org-agenda-new-buffers nil)
  8355. (org-deadline-warning-days 0)
  8356. ;; Do not use `org-today' here because appt only takes
  8357. ;; time and without date as argument, so it may pass wrong
  8358. ;; information otherwise
  8359. (today (org-date-to-gregorian
  8360. (time-to-days (current-time))))
  8361. (org-agenda-restrict nil)
  8362. (files (org-agenda-files 'unrestricted)) entries file
  8363. (org-agenda-buffer nil))
  8364. ;; Get all entries which may contain an appt
  8365. (org-prepare-agenda-buffers files)
  8366. (while (setq file (pop files))
  8367. (setq entries
  8368. (delq nil
  8369. (append entries
  8370. (apply 'org-agenda-get-day-entries
  8371. file today scope)))))
  8372. ;; Map thru entries and find if we should filter them out
  8373. (mapc
  8374. (lambda(x)
  8375. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8376. (cat (get-text-property 1 'org-category x))
  8377. (tod (get-text-property 1 'time-of-day x))
  8378. (ok (or (null filter)
  8379. (and (stringp filter) (string-match filter evt))
  8380. (and (functionp filter) (funcall filter x))
  8381. (and (listp filter)
  8382. (let ((cat-filter (cadr (assoc 'category filter)))
  8383. (evt-filter (cadr (assoc 'headline filter))))
  8384. (or (and (stringp cat-filter)
  8385. (string-match cat-filter cat))
  8386. (and (stringp evt-filter)
  8387. (string-match evt-filter evt))))))))
  8388. ;; FIXME: Shall we remove text-properties for the appt text?
  8389. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8390. (when (and ok tod)
  8391. (setq tod (concat "00" (number-to-string tod))
  8392. tod (when (string-match
  8393. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8394. (concat (match-string 1 tod) ":"
  8395. (match-string 2 tod))))
  8396. (appt-add tod evt)
  8397. (setq cnt (1+ cnt))))) entries)
  8398. (org-release-buffers org-agenda-new-buffers)
  8399. (if (eq cnt 0)
  8400. (message "No event to add")
  8401. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8402. (defun org-agenda-todayp (date)
  8403. "Does DATE mean today, when considering `org-extend-today-until'?"
  8404. (let ((today (org-today))
  8405. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8406. date)))
  8407. (eq date today)))
  8408. (defun org-agenda-todo-yesterday (&optional arg)
  8409. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8410. (interactive "P")
  8411. (let* ((hour (third (decode-time
  8412. (org-current-time))))
  8413. (org-extend-today-until (1+ hour)))
  8414. (org-agenda-todo arg)))
  8415. (provide 'org-agenda)
  8416. ;;; org-agenda.el ends here