org-agenda.el 259 KB

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