org-agenda.el 239 KB

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