org-agenda.el 265 KB

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