org-agenda.el 269 KB

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