org-agenda.el 265 KB

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