org-agenda.el 270 KB

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