org-agenda.el 354 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags to not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  661. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  662. The variables
  663. `org-agenda-todo-ignore-with-date',
  664. `org-agenda-todo-ignore-timestamp',
  665. `org-agenda-todo-ignore-scheduled',
  666. `org-agenda-todo-ignore-deadlines'
  667. make the global TODO list skip entries that have time stamps of certain
  668. kinds. If this option is set, the same options will also apply for the
  669. tags-todo search, which is the general tags/property matcher
  670. restricted to unfinished TODO entries only."
  671. :group 'org-agenda-skip
  672. :group 'org-agenda-todo-list
  673. :group 'org-agenda-match-view
  674. :type 'boolean)
  675. (defcustom org-agenda-skip-scheduled-if-done nil
  676. "Non-nil means don't show scheduled items in agenda when they are done.
  677. This is relevant for the daily/weekly agenda, not for the TODO list. And
  678. it applies only to the actual date of the scheduling. Warnings about
  679. an item with a past scheduling dates are always turned off when the item
  680. is DONE."
  681. :group 'org-agenda-skip
  682. :group 'org-agenda-daily/weekly
  683. :type 'boolean)
  684. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  685. "Non-nil means skip scheduling line if same entry shows because of deadline.
  686. In the agenda of today, an entry can show up multiple times because
  687. it is both scheduled and has a nearby deadline, and maybe a plain time
  688. stamp as well.
  689. When this variable is t, then only the deadline is shown and the fact that
  690. the entry is scheduled today or was scheduled previously is not shown.
  691. When this variable is nil, the entry will be shown several times. When
  692. the variable is the symbol `not-today', then skip scheduled previously,
  693. but not scheduled today."
  694. :group 'org-agenda-skip
  695. :group 'org-agenda-daily/weekly
  696. :type '(choice
  697. (const :tag "Never" nil)
  698. (const :tag "Always" t)
  699. (const :tag "Not when scheduled today" not-today)))
  700. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  701. "Non-nil means skip timestamp line if same entry shows because of deadline.
  702. In the agenda of today, an entry can show up multiple times
  703. because it has both a plain timestamp and has a nearby deadline.
  704. When this variable is t, then only the deadline is shown and the
  705. fact that the entry has a timestamp for or including today is not
  706. shown. When this variable is nil, the entry will be shown
  707. several times."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-daily/weekly
  710. :version "24.1"
  711. :type '(choice
  712. (const :tag "Never" nil)
  713. (const :tag "Always" t)))
  714. (defcustom org-agenda-skip-deadline-if-done nil
  715. "Non-nil means don't show deadlines when the corresponding item is done.
  716. When nil, the deadline is still shown and should give you a happy feeling.
  717. This is relevant for the daily/weekly agenda. And it applied only to the
  718. actually date of the deadline. Warnings about approaching and past-due
  719. deadlines are always turned off when the item is DONE."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :type 'boolean)
  723. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  724. "Non-nil means skip deadline prewarning when entry is also scheduled.
  725. This will apply on all days where a prewarning for the deadline would
  726. be shown, but not at the day when the entry is actually due. On that day,
  727. the deadline will be shown anyway.
  728. This variable may be set to nil, t, or a number which will then give
  729. the number of days before the actual deadline when the prewarnings
  730. should resume.
  731. This can be used in a workflow where the first showing of the deadline will
  732. trigger you to schedule it, and then you don't want to be reminded of it
  733. because you will take care of it on the day when scheduled."
  734. :group 'org-agenda-skip
  735. :group 'org-agenda-daily/weekly
  736. :version "24.1"
  737. :type '(choice
  738. (const :tag "Alwas show prewarning" nil)
  739. (const :tag "Remove prewarning if entry is scheduled" t)
  740. (integer :tag "Restart prewarning N days before deadline")))
  741. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  742. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  743. When non-nil, after the search for timestamps has matched once in an
  744. entry, the rest of the entry will not be searched."
  745. :group 'org-agenda-skip
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-timestamp-if-done nil
  748. "Non-nil means don't select item by timestamp or -range if it is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-dim-blocked-tasks t
  753. "Non-nil means dim blocked tasks in the agenda display.
  754. This causes some overhead during agenda construction, but if you
  755. have turned on `org-enforce-todo-dependencies',
  756. `org-enforce-todo-checkbox-dependencies', or any other blocking
  757. mechanism, this will create useful feedback in the agenda.
  758. Instead of t, this variable can also have the value `invisible'.
  759. Then blocked tasks will be invisible and only become visible when
  760. they become unblocked. An exemption to this behavior is when a task is
  761. blocked because of unchecked checkboxes below it. Since checkboxes do
  762. not show up in the agenda views, making this task invisible you remove any
  763. trace from agenda views that there is something to do. Therefore, a task
  764. that is blocked because of checkboxes will never be made invisible, it
  765. will only be dimmed."
  766. :group 'org-agenda-daily/weekly
  767. :group 'org-agenda-todo-list
  768. :type '(choice
  769. (const :tag "Do not dim" nil)
  770. (const :tag "Dim to a gray face" t)
  771. (const :tag "Make invisible" invisible)))
  772. (defcustom org-timeline-show-empty-dates 3
  773. "Non-nil means `org-timeline' also shows dates without an entry.
  774. When nil, only the days which actually have entries are shown.
  775. When t, all days between the first and the last date are shown.
  776. When an integer, show also empty dates, but if there is a gap of more than
  777. N days, just insert a special line indicating the size of the gap."
  778. :group 'org-agenda-skip
  779. :type '(choice
  780. (const :tag "None" nil)
  781. (const :tag "All" t)
  782. (integer :tag "at most")))
  783. (defgroup org-agenda-startup nil
  784. "Options concerning initial settings in the Agenda in Org Mode."
  785. :tag "Org Agenda Startup"
  786. :group 'org-agenda)
  787. (defcustom org-agenda-menu-show-matcher t
  788. "Non-nil means show the match string in the agenda dispatcher menu.
  789. When nil, the matcher string is not shown, but is put into the help-echo
  790. property so than moving the mouse over the command shows it.
  791. Setting it to nil is good if matcher strings are very long and/or if
  792. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  793. :group 'org-agenda
  794. :version "24.1"
  795. :type 'boolean)
  796. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  797. (defcustom org-agenda-menu-two-columns nil
  798. "Non-nil means, use two columns to show custom commands in the dispatcher.
  799. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  800. to nil."
  801. :group 'org-agenda
  802. :version "24.1"
  803. :type 'boolean)
  804. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  805. (defcustom org-agenda-finalize-hook nil
  806. "Hook run just before displaying an agenda buffer.
  807. The buffer is still writable when the hook is called.
  808. You can modify some of the buffer substrings but you should be
  809. extra careful not to modify the text properties of the agenda
  810. headlines as the agenda display heavily relies on them."
  811. :group 'org-agenda-startup
  812. :type 'hook)
  813. (defcustom org-agenda-mouse-1-follows-link nil
  814. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  815. A longer mouse click will still set point. Does not work on XEmacs.
  816. Needs to be set before org.el is loaded."
  817. :group 'org-agenda-startup
  818. :type 'boolean)
  819. (defcustom org-agenda-start-with-follow-mode nil
  820. "The initial value of follow mode in a newly created agenda window."
  821. :group 'org-agenda-startup
  822. :type 'boolean)
  823. (defcustom org-agenda-follow-indirect nil
  824. "Non-nil means `org-agenda-follow-mode' displays only the
  825. current item's tree, in an indirect buffer."
  826. :group 'org-agenda
  827. :version "24.1"
  828. :type 'boolean)
  829. (defcustom org-agenda-show-outline-path t
  830. "Non-nil means show outline path in echo area after line motion."
  831. :group 'org-agenda-startup
  832. :type 'boolean)
  833. (defcustom org-agenda-start-with-entry-text-mode nil
  834. "The initial value of entry-text-mode in a newly created agenda window."
  835. :group 'org-agenda-startup
  836. :type 'boolean)
  837. (defcustom org-agenda-entry-text-maxlines 5
  838. "Number of text lines to be added when `E' is pressed in the agenda.
  839. Note that this variable only used during agenda display. Add add entry text
  840. when exporting the agenda, configure the variable
  841. `org-agenda-add-entry-ext-maxlines'."
  842. :group 'org-agenda
  843. :type 'integer)
  844. (defcustom org-agenda-entry-text-exclude-regexps nil
  845. "List of regular expressions to clean up entry text.
  846. The complete matches of all regular expressions in this list will be
  847. removed from entry text before it is shown in the agenda."
  848. :group 'org-agenda
  849. :type '(repeat (regexp)))
  850. (defvar org-agenda-entry-text-cleanup-hook nil
  851. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  852. This cleanup is done in a temporary buffer, so the function may inspect and
  853. change the entire buffer.
  854. Some default stuff like drawers and scheduling/deadline dates will already
  855. have been removed when this is called, as will any matches for regular
  856. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  857. (defvar org-agenda-include-inactive-timestamps nil
  858. "Non-nil means include inactive time stamps in agenda and timeline.
  859. Dynamically scoped.")
  860. (defgroup org-agenda-windows nil
  861. "Options concerning the windows used by the Agenda in Org Mode."
  862. :tag "Org Agenda Windows"
  863. :group 'org-agenda)
  864. (defcustom org-agenda-window-setup 'reorganize-frame
  865. "How the agenda buffer should be displayed.
  866. Possible values for this option are:
  867. current-window Show agenda in the current window, keeping all other windows.
  868. other-window Use `switch-to-buffer-other-window' to display agenda.
  869. reorganize-frame Show only two windows on the current frame, the current
  870. window and the agenda.
  871. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  872. Also, when exiting the agenda, kill that frame.
  873. See also the variable `org-agenda-restore-windows-after-quit'."
  874. :group 'org-agenda-windows
  875. :type '(choice
  876. (const current-window)
  877. (const other-frame)
  878. (const other-window)
  879. (const reorganize-frame)))
  880. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  881. "The min and max height of the agenda window as a fraction of frame height.
  882. The value of the variable is a cons cell with two numbers between 0 and 1.
  883. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  884. :group 'org-agenda-windows
  885. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  886. (defcustom org-agenda-restore-windows-after-quit nil
  887. "Non-nil means restore window configuration upon exiting agenda.
  888. Before the window configuration is changed for displaying the agenda,
  889. the current status is recorded. When the agenda is exited with
  890. `q' or `x' and this option is set, the old state is restored. If
  891. `org-agenda-window-setup' is `other-frame', the value of this
  892. option will be ignored."
  893. :group 'org-agenda-windows
  894. :type 'boolean)
  895. (defcustom org-agenda-ndays nil
  896. "Number of days to include in overview display.
  897. Should be 1 or 7.
  898. Obsolete, see `org-agenda-span'."
  899. :group 'org-agenda-daily/weekly
  900. :type 'integer)
  901. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  902. (defcustom org-agenda-span 'week
  903. "Number of days to include in overview display.
  904. Can be day, week, month, year, or any number of days.
  905. Custom commands can set this variable in the options section."
  906. :group 'org-agenda-daily/weekly
  907. :type '(choice (const :tag "Day" day)
  908. (const :tag "Week" week)
  909. (const :tag "Month" month)
  910. (const :tag "Year" year)
  911. (integer :tag "Custom")))
  912. (defcustom org-agenda-start-on-weekday 1
  913. "Non-nil means start the overview always on the specified weekday.
  914. 0 denotes Sunday, 1 denotes Monday etc.
  915. When nil, always start on the current day.
  916. Custom commands can set this variable in the options section."
  917. :group 'org-agenda-daily/weekly
  918. :type '(choice (const :tag "Today" nil)
  919. (integer :tag "Weekday No.")))
  920. (defcustom org-agenda-show-all-dates t
  921. "Non-nil means `org-agenda' shows every day in the selected range.
  922. When nil, only the days which actually have entries are shown."
  923. :group 'org-agenda-daily/weekly
  924. :type 'boolean)
  925. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  926. "Format string for displaying dates in the agenda.
  927. Used by the daily/weekly agenda and by the timeline. This should be
  928. a format string understood by `format-time-string', or a function returning
  929. the formatted date as a string. The function must take a single argument,
  930. a calendar-style date list like (month day year)."
  931. :group 'org-agenda-daily/weekly
  932. :type '(choice
  933. (string :tag "Format string")
  934. (function :tag "Function")))
  935. (defun org-agenda-format-date-aligned (date)
  936. "Format a date string for display in the daily/weekly agenda, or timeline.
  937. This function makes sure that dates are aligned for easy reading."
  938. (require 'cal-iso)
  939. (let* ((dayname (calendar-day-name date))
  940. (day (cadr date))
  941. (day-of-week (calendar-day-of-week date))
  942. (month (car date))
  943. (monthname (calendar-month-name month))
  944. (year (nth 2 date))
  945. (iso-week (org-days-to-iso-week
  946. (calendar-absolute-from-gregorian date)))
  947. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  948. (1- year))
  949. ((and (= month 12) (<= iso-week 1))
  950. (1+ year))
  951. (t year)))
  952. (weekstring (if (= day-of-week 1)
  953. (format " W%02d" iso-week)
  954. "")))
  955. (format "%-10s %2d %s %4d%s"
  956. dayname day monthname year weekstring)))
  957. (defcustom org-agenda-time-leading-zero nil
  958. "Non-nil means use leading zero for military times in agenda.
  959. For example, 9:30am would become 09:30 rather than 9:30."
  960. :group 'org-agenda-daily/weekly
  961. :version "24.1"
  962. :type 'boolean)
  963. (defcustom org-agenda-timegrid-use-ampm nil
  964. "When set, show AM/PM style timestamps on the timegrid."
  965. :group 'org-agenda
  966. :version "24.1"
  967. :type 'boolean)
  968. (defun org-agenda-time-of-day-to-ampm (time)
  969. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  970. (let* ((hour-number (string-to-number (substring time 0 -3)))
  971. (minute (substring time -2))
  972. (ampm "am"))
  973. (cond
  974. ((equal hour-number 12)
  975. (setq ampm "pm"))
  976. ((> hour-number 12)
  977. (setq ampm "pm")
  978. (setq hour-number (- hour-number 12))))
  979. (concat
  980. (if org-agenda-time-leading-zero
  981. (format "%02d" hour-number)
  982. (format "%02s" (number-to-string hour-number)))
  983. ":" minute ampm)))
  984. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  985. "Conditionally convert TIME to AM/PM format
  986. based on `org-agenda-timegrid-use-ampm'"
  987. (if org-agenda-timegrid-use-ampm
  988. (org-agenda-time-of-day-to-ampm time)
  989. time))
  990. (defcustom org-agenda-weekend-days '(6 0)
  991. "Which days are weekend?
  992. These days get the special face `org-agenda-date-weekend' in the agenda
  993. and timeline buffers."
  994. :group 'org-agenda-daily/weekly
  995. :type '(set :greedy t
  996. (const :tag "Monday" 1)
  997. (const :tag "Tuesday" 2)
  998. (const :tag "Wednesday" 3)
  999. (const :tag "Thursday" 4)
  1000. (const :tag "Friday" 5)
  1001. (const :tag "Saturday" 6)
  1002. (const :tag "Sunday" 0)))
  1003. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1004. "Non-nil means jump to today when moving a past date forward in time.
  1005. When using S-right in the agenda to move a a date forward, and the date
  1006. stamp currently points to the past, the first key press will move it
  1007. to today. WHen nil, just move one day forward even if the date stays
  1008. in the past."
  1009. :group 'org-agenda-daily/weekly
  1010. :version "24.1"
  1011. :type 'boolean)
  1012. (defcustom org-agenda-include-diary nil
  1013. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1014. Custom commands can set this variable in the options section."
  1015. :group 'org-agenda-daily/weekly
  1016. :type 'boolean)
  1017. (defcustom org-agenda-include-deadlines t
  1018. "If non-nil, include entries within their deadline warning period.
  1019. Custom commands can set this variable in the options section."
  1020. :group 'org-agenda-daily/weekly
  1021. :version "24.1"
  1022. :type 'boolean)
  1023. (defcustom org-agenda-repeating-timestamp-show-all t
  1024. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1025. When set to a list of strings, only show occurrences of repeating
  1026. stamps for these TODO keywords. When nil, only one occurrence is
  1027. shown, either today or the nearest into the future."
  1028. :group 'org-agenda-daily/weekly
  1029. :type '(choice
  1030. (const :tag "Show repeating stamps" t)
  1031. (repeat :tag "Show repeating stamps for these TODO keywords"
  1032. (string :tag "TODO Keyword"))
  1033. (const :tag "Don't show repeating stamps" nil)))
  1034. (defcustom org-scheduled-past-days 10000
  1035. "No. of days to continue listing scheduled items that are not marked DONE.
  1036. When an item is scheduled on a date, it shows up in the agenda on this
  1037. day and will be listed until it is marked done for the number of days
  1038. given here."
  1039. :group 'org-agenda-daily/weekly
  1040. :type 'integer)
  1041. (defcustom org-agenda-log-mode-items '(closed clock)
  1042. "List of items that should be shown in agenda log mode.
  1043. This list may contain the following symbols:
  1044. closed Show entries that have been closed on that day.
  1045. clock Show entries that have received clocked time on that day.
  1046. state Show all logged state changes.
  1047. Note that instead of changing this variable, you can also press `C-u l' in
  1048. the agenda to display all available LOG items temporarily."
  1049. :group 'org-agenda-daily/weekly
  1050. :type '(set :greedy t (const closed) (const clock) (const state)))
  1051. (defcustom org-agenda-clock-consistency-checks
  1052. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1053. :gap-ok-around ("4:00")
  1054. :default-face ((:background "DarkRed") (:foreground "white"))
  1055. :overlap-face nil :gap-face nil :no-end-time-face nil
  1056. :long-face nil :short-face nil)
  1057. "This is a property list, with the following keys:
  1058. :max-duration Mark clocking chunks that are longer than this time.
  1059. This is a time string like \"HH:MM\", or the number
  1060. of minutes as an integer.
  1061. :min-duration Mark clocking chunks that are shorter that this.
  1062. This is a time string like \"HH:MM\", or the number
  1063. of minutes as an integer.
  1064. :max-gap Mark gaps between clocking chunks that are longer than
  1065. this duration. A number of minutes, or a string
  1066. like \"HH:MM\".
  1067. :gap-ok-around List of times during the day which are usually not working
  1068. times. When a gap is detected, but the gap contains any
  1069. of these times, the gap is *not* reported. For example,
  1070. if this is (\"4:00\" \"13:00\") then gaps that contain
  1071. 4:00 in the morning (i.e. the night) and 13:00
  1072. (i.e. a typical lunch time) do not cause a warning.
  1073. You should have at least one time during the night in this
  1074. list, or otherwise the first task each morning will trigger
  1075. a warning because it follows a long gap.
  1076. Furthermore, the following properties can be used to define faces for
  1077. issue display.
  1078. :default-face the default face, if the specific face is undefined
  1079. :overlap-face face for overlapping clocks
  1080. :gap-face face for gaps between clocks
  1081. :no-end-time-face face for incomplete clocks
  1082. :long-face face for clock intervals that are too long
  1083. :short-face face for clock intervals that are too short"
  1084. :group 'org-agenda-daily/weekly
  1085. :group 'org-clock
  1086. :version "24.1"
  1087. :type 'plist)
  1088. (defcustom org-agenda-log-mode-add-notes t
  1089. "Non-nil means add first line of notes to log entries in agenda views.
  1090. If a log item like a state change or a clock entry is associated with
  1091. notes, the first line of these notes will be added to the entry in the
  1092. agenda display."
  1093. :group 'org-agenda-daily/weekly
  1094. :type 'boolean)
  1095. (defcustom org-agenda-start-with-log-mode nil
  1096. "The initial value of log-mode in a newly created agenda window.
  1097. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1098. explanations on the possible values."
  1099. :group 'org-agenda-startup
  1100. :group 'org-agenda-daily/weekly
  1101. :type '(choice (const :tag "Don't show log items" nil)
  1102. (const :tag "Show only log items" 'only)
  1103. (const :tag "Show all possible log items" 'clockcheck)
  1104. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1105. (choice (const :tag "Show closed log items" 'closed)
  1106. (const :tag "Show clocked log items" 'clock)
  1107. (const :tag "Show all logged state changes" 'state)))))
  1108. (defcustom org-agenda-start-with-clockreport-mode nil
  1109. "The initial value of clockreport-mode in a newly created agenda window."
  1110. :group 'org-agenda-startup
  1111. :group 'org-agenda-daily/weekly
  1112. :type 'boolean)
  1113. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1114. "Property list with parameters for the clocktable in clockreport mode.
  1115. This is the display mode that shows a clock table in the daily/weekly
  1116. agenda, the properties for this dynamic block can be set here.
  1117. The usual clocktable parameters are allowed here, but you cannot set
  1118. the properties :name, :tstart, :tend, :block, and :scope - these will
  1119. be overwritten to make sure the content accurately reflects the
  1120. current display in the agenda."
  1121. :group 'org-agenda-daily/weekly
  1122. :type 'plist)
  1123. (defcustom org-agenda-search-view-always-boolean nil
  1124. "Non-nil means the search string is interpreted as individual parts.
  1125. The search string for search view can either be interpreted as a phrase,
  1126. or as a list of snippets that define a boolean search for a number of
  1127. strings.
  1128. When this is non-nil, the string will be split on whitespace, and each
  1129. snippet will be searched individually, and all must match in order to
  1130. select an entry. A snippet is then a single string of non-white
  1131. characters, or a string in double quotes, or a regexp in {} braces.
  1132. If a snippet is preceded by \"-\", the snippet must *not* match.
  1133. \"+\" is syntactic sugar for positive selection. Each snippet may
  1134. be found as a full word or a partial word, but see the variable
  1135. `org-agenda-search-view-force-full-words'.
  1136. When this is nil, search will look for the entire search phrase as one,
  1137. with each space character matching any amount of whitespace, including
  1138. line breaks.
  1139. Even when this is nil, you can still switch to Boolean search dynamically
  1140. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1141. is a regexp marked with braces like \"{abc}\", this will also switch to
  1142. boolean search."
  1143. :group 'org-agenda-search-view
  1144. :version "24.1"
  1145. :type 'boolean)
  1146. (if (fboundp 'defvaralias)
  1147. (defvaralias 'org-agenda-search-view-search-words-only
  1148. 'org-agenda-search-view-always-boolean))
  1149. (defcustom org-agenda-search-view-force-full-words nil
  1150. "Non-nil means, search words must be matches as complete words.
  1151. When nil, they may also match part of a word."
  1152. :group 'org-agenda-search-view
  1153. :version "24.1"
  1154. :type 'boolean)
  1155. (defgroup org-agenda-time-grid nil
  1156. "Options concerning the time grid in the Org-mode Agenda."
  1157. :tag "Org Agenda Time Grid"
  1158. :group 'org-agenda)
  1159. (defcustom org-agenda-search-headline-for-time t
  1160. "Non-nil means search headline for a time-of-day.
  1161. If the headline contains a time-of-day in one format or another, it will
  1162. be used to sort the entry into the time sequence of items for a day.
  1163. Some people have time stamps in the headline that refer to the creation
  1164. time or so, and then this produces an unwanted side effect. If this is
  1165. the case for your, use this variable to turn off searching the headline
  1166. for a time."
  1167. :group 'org-agenda-time-grid
  1168. :type 'boolean)
  1169. (defcustom org-agenda-use-time-grid t
  1170. "Non-nil means show a time grid in the agenda schedule.
  1171. A time grid is a set of lines for specific times (like every two hours between
  1172. 8:00 and 20:00). The items scheduled for a day at specific times are
  1173. sorted in between these lines.
  1174. For details about when the grid will be shown, and what it will look like, see
  1175. the variable `org-agenda-time-grid'."
  1176. :group 'org-agenda-time-grid
  1177. :type 'boolean)
  1178. (defcustom org-agenda-time-grid
  1179. '((daily today require-timed)
  1180. "----------------"
  1181. (800 1000 1200 1400 1600 1800 2000))
  1182. "The settings for time grid for agenda display.
  1183. This is a list of three items. The first item is again a list. It contains
  1184. symbols specifying conditions when the grid should be displayed:
  1185. daily if the agenda shows a single day
  1186. weekly if the agenda shows an entire week
  1187. today show grid on current date, independent of daily/weekly display
  1188. require-timed show grid only if at least one item has a time specification
  1189. The second item is a string which will be placed behind the grid time.
  1190. The third item is a list of integers, indicating the times that should have
  1191. a grid line."
  1192. :group 'org-agenda-time-grid
  1193. :type
  1194. '(list
  1195. (set :greedy t :tag "Grid Display Options"
  1196. (const :tag "Show grid in single day agenda display" daily)
  1197. (const :tag "Show grid in weekly agenda display" weekly)
  1198. (const :tag "Always show grid for today" today)
  1199. (const :tag "Show grid only if any timed entries are present"
  1200. require-timed)
  1201. (const :tag "Skip grid times already present in an entry"
  1202. remove-match))
  1203. (string :tag "Grid String")
  1204. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1205. (defcustom org-agenda-show-current-time-in-grid t
  1206. "Non-nil means show the current time in the time grid."
  1207. :group 'org-agenda-time-grid
  1208. :version "24.1"
  1209. :type 'boolean)
  1210. (defcustom org-agenda-current-time-string
  1211. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1212. "The string for the current time marker in the agenda."
  1213. :group 'org-agenda-time-grid
  1214. :version "24.1"
  1215. :type 'string)
  1216. (defgroup org-agenda-sorting nil
  1217. "Options concerning sorting in the Org-mode Agenda."
  1218. :tag "Org Agenda Sorting"
  1219. :group 'org-agenda)
  1220. (defcustom org-agenda-sorting-strategy
  1221. '((agenda habit-down time-up priority-down category-keep)
  1222. (todo priority-down category-keep)
  1223. (tags priority-down category-keep)
  1224. (search category-keep))
  1225. "Sorting structure for the agenda items of a single day.
  1226. This is a list of symbols which will be used in sequence to determine
  1227. if an entry should be listed before another entry. The following
  1228. symbols are recognized:
  1229. time-up Put entries with time-of-day indications first, early first
  1230. time-down Put entries with time-of-day indications first, late first
  1231. category-keep Keep the default order of categories, corresponding to the
  1232. sequence in `org-agenda-files'.
  1233. category-up Sort alphabetically by category, A-Z.
  1234. category-down Sort alphabetically by category, Z-A.
  1235. tag-up Sort alphabetically by last tag, A-Z.
  1236. tag-down Sort alphabetically by last tag, Z-A.
  1237. priority-up Sort numerically by priority, high priority last.
  1238. priority-down Sort numerically by priority, high priority first.
  1239. todo-state-up Sort by todo state, tasks that are done last.
  1240. todo-state-down Sort by todo state, tasks that are done first.
  1241. effort-up Sort numerically by estimated effort, high effort last.
  1242. effort-down Sort numerically by estimated effort, high effort first.
  1243. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1244. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1245. habit-up Put entries that are habits first
  1246. habit-down Put entries that are habits last
  1247. alpha-up Sort headlines alphabetically
  1248. alpha-down Sort headlines alphabetically, reversed
  1249. The different possibilities will be tried in sequence, and testing stops
  1250. if one comparison returns a \"not-equal\". For example, the default
  1251. '(time-up category-keep priority-down)
  1252. means: Pull out all entries having a specified time of day and sort them,
  1253. in order to make a time schedule for the current day the first thing in the
  1254. agenda listing for the day. Of the entries without a time indication, keep
  1255. the grouped in categories, don't sort the categories, but keep them in
  1256. the sequence given in `org-agenda-files'. Within each category sort by
  1257. priority.
  1258. Leaving out `category-keep' would mean that items will be sorted across
  1259. categories by priority.
  1260. Instead of a single list, this can also be a set of list for specific
  1261. contents, with a context symbol in the car of the list, any of
  1262. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1263. Custom commands can bind this variable in the options section."
  1264. :group 'org-agenda-sorting
  1265. :type `(choice
  1266. (repeat :tag "General" ,org-sorting-choice)
  1267. (list :tag "Individually"
  1268. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1269. (repeat ,org-sorting-choice))
  1270. (cons (const :tag "Strategy for TODO lists" todo)
  1271. (repeat ,org-sorting-choice))
  1272. (cons (const :tag "Strategy for Tags matches" tags)
  1273. (repeat ,org-sorting-choice))
  1274. (cons (const :tag "Strategy for search matches" search)
  1275. (repeat ,org-sorting-choice)))))
  1276. (defcustom org-agenda-cmp-user-defined nil
  1277. "A function to define the comparison `user-defined'.
  1278. This function must receive two arguments, agenda entry a and b.
  1279. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1280. the user comparison, return nil.
  1281. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1282. part of an agenda sorting strategy."
  1283. :group 'org-agenda-sorting
  1284. :type 'symbol)
  1285. (defcustom org-sort-agenda-notime-is-late t
  1286. "Non-nil means items without time are considered late.
  1287. This is only relevant for sorting. When t, items which have no explicit
  1288. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1289. do have a time. When nil, the default time is before 0:00. You can use this
  1290. option to decide if the schedule for today should come before or after timeless
  1291. agenda entries."
  1292. :group 'org-agenda-sorting
  1293. :type 'boolean)
  1294. (defcustom org-sort-agenda-noeffort-is-high t
  1295. "Non-nil means items without effort estimate are sorted as high effort.
  1296. This also applies when filtering an agenda view with respect to the
  1297. < or > effort operator. Then, tasks with no effort defined will be treated
  1298. as tasks with high effort.
  1299. When nil, such items are sorted as 0 minutes effort."
  1300. :group 'org-agenda-sorting
  1301. :type 'boolean)
  1302. (defgroup org-agenda-line-format nil
  1303. "Options concerning the entry prefix in the Org-mode agenda display."
  1304. :tag "Org Agenda Line Format"
  1305. :group 'org-agenda)
  1306. (defcustom org-agenda-prefix-format
  1307. '((agenda . " %i %-12:c%?-12t% s")
  1308. (timeline . " % s")
  1309. (todo . " %i %-12:c")
  1310. (tags . " %i %-12:c")
  1311. (search . " %i %-12:c"))
  1312. "Format specifications for the prefix of items in the agenda views.
  1313. An alist with five entries, each for the different agenda types. The
  1314. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1315. The values are format strings.
  1316. This format works similar to a printf format, with the following meaning:
  1317. %c the category of the item, \"Diary\" for entries from the diary,
  1318. or as given by the CATEGORY keyword or derived from the file name
  1319. %e the effort required by the item
  1320. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1321. %T the last tag of the item (ignore inherited tags, which come first)
  1322. %t the HH:MM time-of-day specification if one applies to the entry
  1323. %s Scheduling/Deadline information, a short string
  1324. %(expression) Eval EXPRESSION and replace the control string
  1325. by the result
  1326. All specifiers work basically like the standard `%s' of printf, but may
  1327. contain two additional characters: a question mark just after the `%'
  1328. and a whitespace/punctuation character just before the final letter.
  1329. If the first character after `%' is a question mark, the entire field
  1330. will only be included if the corresponding value applies to the current
  1331. entry. This is useful for fields which should have fixed width when
  1332. present, but zero width when absent. For example, \"%?-12t\" will
  1333. result in a 12 character time field if a time of the day is specified,
  1334. but will completely disappear in entries which do not contain a time.
  1335. If there is punctuation or whitespace character just before the final
  1336. format letter, this character will be appended to the field value if
  1337. the value is not empty. For example, the format \"%-12:c\" leads to
  1338. \"Diary: \" if the category is \"Diary\". If the category were be
  1339. empty, no additional colon would be inserted.
  1340. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1341. which means:
  1342. - Indent the line with two space characters
  1343. - Give the category a 12 chars wide field, padded with whitespace on
  1344. the right (because of `-'). Append a colon if there is a category
  1345. (because of `:').
  1346. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1347. time, don't put in an empty field, just skip it (because of '?').
  1348. - Finally, put the scheduling information.
  1349. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1350. `org-agenda-remove-tags'.
  1351. Custom commands can set this variable in the options section."
  1352. :type '(choice
  1353. (string :tag "General format")
  1354. (list :greedy t :tag "View dependent"
  1355. (cons (const agenda) (string :tag "Format"))
  1356. (cons (const timeline) (string :tag "Format"))
  1357. (cons (const todo) (string :tag "Format"))
  1358. (cons (const tags) (string :tag "Format"))
  1359. (cons (const search) (string :tag "Format"))))
  1360. :group 'org-agenda-line-format)
  1361. (defvar org-prefix-format-compiled nil
  1362. "The compiled prefix format and associated variables.
  1363. This is a list where first element is a list of variable bindings, and second
  1364. element is the compiled format expression. See the variable
  1365. `org-agenda-prefix-format'.")
  1366. (defcustom org-agenda-todo-keyword-format "%-1s"
  1367. "Format for the TODO keyword in agenda lines.
  1368. Set this to something like \"%-12s\" if you want all TODO keywords
  1369. to occupy a fixed space in the agenda display."
  1370. :group 'org-agenda-line-format
  1371. :type 'string)
  1372. (defcustom org-agenda-diary-sexp-prefix nil
  1373. "A regexp that matches part of a diary sexp entry
  1374. which should be treated as scheduling/deadline information in
  1375. `org-agenda'.
  1376. For example, you can use this to extract the `diary-remind-message' from
  1377. `diary-remind' entries."
  1378. :group 'org-agenda-line-format
  1379. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1380. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1381. "Text preceding timerange entries in the agenda view.
  1382. This is a list with two strings. The first applies when the range
  1383. is entirely on one day. The second applies if the range spans several days.
  1384. The strings may have two \"%d\" format specifiers which will be filled
  1385. with the sequence number of the days, and the total number of days in the
  1386. range, respectively."
  1387. :group 'org-agenda-line-format
  1388. :type '(list
  1389. (string :tag "Deadline today ")
  1390. (choice :tag "Deadline relative"
  1391. (string :tag "Format string")
  1392. (function))))
  1393. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1394. "Text preceding scheduled items in the agenda view.
  1395. This is a list with two strings. The first applies when the item is
  1396. scheduled on the current day. The second applies when it has been scheduled
  1397. previously, it may contain a %d indicating that this is the nth time that
  1398. this item is scheduled, due to automatic rescheduling of unfinished items
  1399. for the following day. So this number is one larger than the number of days
  1400. that passed since this item was scheduled first."
  1401. :group 'org-agenda-line-format
  1402. :type '(list
  1403. (string :tag "Scheduled today ")
  1404. (string :tag "Scheduled previously")))
  1405. (defcustom org-agenda-inactive-leader "["
  1406. "Text preceding item pulled into the agenda by inactive time stamps.
  1407. These entries are added to the agenda when pressing \"[\"."
  1408. :group 'org-agenda-line-format
  1409. :version "24.1"
  1410. :type '(list
  1411. (string :tag "Scheduled today ")
  1412. (string :tag "Scheduled previously")))
  1413. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1414. "Text preceding deadline items in the agenda view.
  1415. This is a list with two strings. The first applies when the item has its
  1416. deadline on the current day. The second applies when it is in the past or
  1417. in the future, it may contain %d to capture how many days away the deadline
  1418. is (was)."
  1419. :group 'org-agenda-line-format
  1420. :type '(list
  1421. (string :tag "Deadline today ")
  1422. (choice :tag "Deadline relative"
  1423. (string :tag "Format string")
  1424. (function))))
  1425. (defcustom org-agenda-remove-times-when-in-prefix t
  1426. "Non-nil means remove duplicate time specifications in agenda items.
  1427. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1428. time-of-day specification in a headline or diary entry is extracted and
  1429. placed into the prefix. If this option is non-nil, the original specification
  1430. \(a timestamp or -range, or just a plain time(range) specification like
  1431. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1432. cluttered.
  1433. The option can be t or nil. It may also be the symbol `beg', indicating
  1434. that the time should only be removed when it is located at the beginning of
  1435. the headline/diary entry."
  1436. :group 'org-agenda-line-format
  1437. :type '(choice
  1438. (const :tag "Always" t)
  1439. (const :tag "Never" nil)
  1440. (const :tag "When at beginning of entry" beg)))
  1441. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1442. "Non-nil means remove time ranges specifications in agenda
  1443. items that span on several days."
  1444. :group 'org-agenda-line-format
  1445. :version "24.1"
  1446. :type 'boolean)
  1447. (defcustom org-agenda-default-appointment-duration nil
  1448. "Default duration for appointments that only have a starting time.
  1449. When nil, no duration is specified in such cases.
  1450. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1451. :group 'org-agenda-line-format
  1452. :type '(choice
  1453. (integer :tag "Minutes")
  1454. (const :tag "No default duration")))
  1455. (defcustom org-agenda-show-inherited-tags t
  1456. "Non-nil means show inherited tags in each agenda line."
  1457. :group 'org-agenda-line-format
  1458. :type 'boolean)
  1459. (defcustom org-agenda-hide-tags-regexp nil
  1460. "Regular expression used to filter away specific tags in agenda views.
  1461. This means that these tags will be present, but not be shown in the agenda
  1462. line. Secondary filtering will still work on the hidden tags.
  1463. Nil means don't hide any tags."
  1464. :group 'org-agenda-line-format
  1465. :type '(choice
  1466. (const :tag "Hide none" nil)
  1467. (string :tag "Regexp ")))
  1468. (defcustom org-agenda-remove-tags nil
  1469. "Non-nil means remove the tags from the headline copy in the agenda.
  1470. When this is the symbol `prefix', only remove tags when
  1471. `org-agenda-prefix-format' contains a `%T' specifier."
  1472. :group 'org-agenda-line-format
  1473. :type '(choice
  1474. (const :tag "Always" t)
  1475. (const :tag "Never" nil)
  1476. (const :tag "When prefix format contains %T" prefix)))
  1477. (if (fboundp 'defvaralias)
  1478. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1479. 'org-agenda-remove-tags))
  1480. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1481. "Shift tags in agenda items to this column.
  1482. If this number is positive, it specifies the column. If it is negative,
  1483. it means that the tags should be flushright to that column. For example,
  1484. -80 works well for a normal 80 character screen."
  1485. :group 'org-agenda-line-format
  1486. :type 'integer)
  1487. (if (fboundp 'defvaralias)
  1488. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1489. (defcustom org-agenda-fontify-priorities 'cookies
  1490. "Non-nil means highlight low and high priorities in agenda.
  1491. When t, the highest priority entries are bold, lowest priority italic.
  1492. However, settings in `org-priority-faces' will overrule these faces.
  1493. When this variable is the symbol `cookies', only fontify the
  1494. cookies, not the entire task.
  1495. This may also be an association list of priority faces, whose
  1496. keys are the character values of `org-highest-priority',
  1497. `org-default-priority', and `org-lowest-priority' (the default values
  1498. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1499. color as a string, or a list like `(:background \"Red\")'.
  1500. If it is a color, the variable `org-faces-easy-properties'
  1501. determines if it is a foreground or a background color."
  1502. :group 'org-agenda-line-format
  1503. :type '(choice
  1504. (const :tag "Never" nil)
  1505. (const :tag "Defaults" t)
  1506. (const :tag "Cookies only" cookies)
  1507. (repeat :tag "Specify"
  1508. (list (character :tag "Priority" :value ?A)
  1509. (choice :tag "Face "
  1510. (string :tag "Color")
  1511. (sexp :tag "Face"))))))
  1512. (defcustom org-agenda-day-face-function nil
  1513. "Function called to determine what face should be used to display a day.
  1514. The only argument passed to that function is the day. It should
  1515. returns a face, or nil if does not want to specify a face and let
  1516. the normal rules apply."
  1517. :group 'org-agenda-line-format
  1518. :version "24.1"
  1519. :type 'function)
  1520. (defcustom org-agenda-category-icon-alist nil
  1521. "Alist of category icon to be displayed in agenda views.
  1522. Each entry should have the following format:
  1523. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1524. Where CATEGORY-REGEXP is a regexp matching the categories where
  1525. the icon should be displayed.
  1526. FILE-OR-DATA either a file path or a string containing image data.
  1527. The other fields can be omitted safely if not needed:
  1528. TYPE indicates the image type.
  1529. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1530. image data.
  1531. PROPS are additional image attributes to assign to the image,
  1532. like, e.g. `:ascent center'.
  1533. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1534. If you want to set the display properties yourself, just put a
  1535. list as second element:
  1536. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1537. For example, to display a 16px horizontal space for Emacs
  1538. category, you can use:
  1539. (\"Emacs\" '(space . (:width (16))))"
  1540. :group 'org-agenda-line-format
  1541. :version "24.1"
  1542. :type '(alist :key-type (string :tag "Regexp matching category")
  1543. :value-type (choice (list :tag "Icon"
  1544. (string :tag "File or data")
  1545. (symbol :tag "Type")
  1546. (boolean :tag "Data?")
  1547. (repeat :tag "Extra image properties" :inline t symbol))
  1548. (list :tag "Display properties" sexp))))
  1549. (defgroup org-agenda-column-view nil
  1550. "Options concerning column view in the agenda."
  1551. :tag "Org Agenda Column View"
  1552. :group 'org-agenda)
  1553. (defcustom org-agenda-columns-show-summaries t
  1554. "Non-nil means show summaries for columns displayed in the agenda view."
  1555. :group 'org-agenda-column-view
  1556. :type 'boolean)
  1557. (defcustom org-agenda-columns-compute-summary-properties t
  1558. "Non-nil means recompute all summary properties before column view.
  1559. When column view in the agenda is listing properties that have a summary
  1560. operator, it can go to all relevant buffers and recompute the summaries
  1561. there. This can mean overhead for the agenda column view, but is necessary
  1562. to have thing up to date.
  1563. As a special case, a CLOCKSUM property also makes sure that the clock
  1564. computations are current."
  1565. :group 'org-agenda-column-view
  1566. :type 'boolean)
  1567. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1568. "Non-nil means the duration of an appointment will add to day effort.
  1569. The property to which appointment durations will be added is the one given
  1570. in the option `org-effort-property'. If an appointment does not have
  1571. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1572. is not set, an appointment without end time will not contribute to the time
  1573. estimate."
  1574. :group 'org-agenda-column-view
  1575. :type 'boolean)
  1576. (defcustom org-agenda-auto-exclude-function nil
  1577. "A function called with a tag to decide if it is filtered on '/ RET'.
  1578. The sole argument to the function, which is called once for each
  1579. possible tag, is a string giving the name of the tag. The
  1580. function should return either nil if the tag should be included
  1581. as normal, or \"-<TAG>\" to exclude the tag.
  1582. Note that for the purpose of tag filtering, only the lower-case version of
  1583. all tags will be considered, so that this function will only ever see
  1584. the lower-case version of all tags."
  1585. :group 'org-agenda
  1586. :type 'function)
  1587. (defcustom org-agenda-bulk-custom-functions nil
  1588. "Alist of characters and custom functions for bulk actions.
  1589. For example, this value makes those two functions available:
  1590. '((?R set-category)
  1591. (?C bulk-cut))
  1592. With selected entries in an agenda buffer, `B R' will call
  1593. the custom function `set-category' on the selected entries.
  1594. Note that functions in this alist don't need to be quoted."
  1595. :type 'alist
  1596. :version "24.1"
  1597. :group 'org-agenda)
  1598. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1599. "Execute BODY with point at location given by `org-hd-marker' property.
  1600. If STRING is non-nil, the text property will be fetched from position 0
  1601. in that string. If STRING is nil, it will be fetched from the beginning
  1602. of the current line."
  1603. (org-with-gensyms (marker)
  1604. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1605. 'org-hd-marker ,string)))
  1606. (with-current-buffer (marker-buffer ,marker)
  1607. (save-excursion
  1608. (goto-char ,marker)
  1609. ,@body)))))
  1610. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1611. (defun org-add-agenda-custom-command (entry)
  1612. "Replace or add a command in `org-agenda-custom-commands'.
  1613. This is mostly for hacking and trying a new command - once the command
  1614. works you probably want to add it to `org-agenda-custom-commands' for good."
  1615. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1616. (if ass
  1617. (setcdr ass (cdr entry))
  1618. (push entry org-agenda-custom-commands))))
  1619. ;;; Define the org-agenda-mode
  1620. (defvar org-agenda-mode-map (make-sparse-keymap)
  1621. "Keymap for `org-agenda-mode'.")
  1622. (if (fboundp 'defvaralias)
  1623. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1624. (defvar org-agenda-menu) ; defined later in this file.
  1625. (defvar org-agenda-restrict nil) ; defined later in this file.
  1626. (defvar org-agenda-follow-mode nil)
  1627. (defvar org-agenda-entry-text-mode nil)
  1628. (defvar org-agenda-clockreport-mode nil)
  1629. (defvar org-agenda-show-log nil)
  1630. (defvar org-agenda-redo-command nil)
  1631. (defvar org-agenda-query-string nil)
  1632. (defvar org-agenda-mode-hook nil
  1633. "Hook run after `org-agenda-mode' is turned on.
  1634. The buffer is still writable when this hook is called.")
  1635. (defvar org-agenda-type nil)
  1636. (defvar org-agenda-force-single-file nil)
  1637. (defvar org-agenda-bulk-marked-entries nil
  1638. "List of markers that refer to marked entries in the agenda.")
  1639. ;;; Multiple agenda buffers support
  1640. (defcustom org-agenda-sticky nil
  1641. "Non-nil means agenda q key will bury agenda buffers.
  1642. Agenda commands will then show existing buffer instead of generating new ones.
  1643. When nil, `q' will kill the single agenda buffer."
  1644. :group 'org-agenda
  1645. ;; :version "24.3"
  1646. :type 'boolean)
  1647. ;;;###autoload
  1648. (defun org-toggle-sticky-agenda (&optional arg)
  1649. "Toggle `org-agenda-sticky'."
  1650. (interactive "P")
  1651. (let ((new-value (if arg
  1652. (> (prefix-numeric-value arg) 0)
  1653. (not org-agenda-sticky))))
  1654. (if (equal new-value org-agenda-sticky)
  1655. (and (org-called-interactively-p 'interactive)
  1656. (message "Sticky agenda was already %s"
  1657. (if org-agenda-sticky "enabled" "disabled")))
  1658. (setq org-agenda-sticky new-value)
  1659. (org-agenda-kill-all-agenda-buffers)
  1660. (and (org-called-interactively-p 'interactive)
  1661. (message "Sticky agenda was %s"
  1662. (if org-agenda-sticky "enabled" "disabled"))))))
  1663. (defvar org-agenda-buffer nil
  1664. "Agenda buffer currently being generated.")
  1665. (defvar org-agenda-last-prefix-arg nil)
  1666. (defvar org-agenda-this-buffer-name nil)
  1667. (defvar org-agenda-doing-sticky-redo nil)
  1668. (defvar org-agenda-this-buffer-is-sticky nil)
  1669. (defconst org-agenda-local-vars
  1670. '(org-agenda-this-buffer-name
  1671. org-agenda-undo-list
  1672. org-agenda-pending-undo-list
  1673. org-agenda-follow-mode
  1674. org-agenda-entry-text-mode
  1675. org-agenda-clockreport-mode
  1676. org-agenda-show-log
  1677. org-agenda-redo-command
  1678. org-agenda-query-string
  1679. org-agenda-type
  1680. org-agenda-bulk-marked-entries
  1681. org-agenda-undo-has-started-in
  1682. org-agenda-info
  1683. org-agenda-tag-filter-overlays
  1684. org-agenda-cat-filter-overlays
  1685. org-agenda-pre-window-conf
  1686. org-agenda-columns-active
  1687. org-agenda-tag-filter
  1688. org-agenda-category-filter
  1689. org-agenda-markers
  1690. org-agenda-last-search-view-search-was-boolean
  1691. org-agenda-filtered-by-category
  1692. org-agenda-filter-form
  1693. org-agenda-show-window
  1694. org-agenda-cycle-counter
  1695. org-agenda-last-prefix-arg)
  1696. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1697. (defun org-agenda-mode ()
  1698. "Mode for time-sorted view on action items in Org-mode files.
  1699. The following commands are available:
  1700. \\{org-agenda-mode-map}"
  1701. (interactive)
  1702. (cond (org-agenda-doing-sticky-redo
  1703. ;; Refreshing sticky agenda-buffer
  1704. ;;
  1705. ;; Preserve the value of `org-agenda-local-vars' variables,
  1706. ;; while letting `kill-all-local-variables' kill the rest
  1707. (let ((save (buffer-local-variables)))
  1708. (kill-all-local-variables)
  1709. (mapc 'make-local-variable org-agenda-local-vars)
  1710. (dolist (elem save)
  1711. (let ((var (car elem))
  1712. (val (cdr elem)))
  1713. (when (and val
  1714. (member var org-agenda-local-vars))
  1715. (set var val)))))
  1716. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1717. (org-agenda-sticky
  1718. ;; Creating a sticky Agenda buffer for the first time
  1719. (kill-all-local-variables)
  1720. (mapc 'make-local-variable org-agenda-local-vars)
  1721. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1722. (t
  1723. ;; Creating a non-sticky agenda buffer
  1724. (kill-all-local-variables)
  1725. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1726. (setq org-agenda-undo-list nil
  1727. org-agenda-pending-undo-list nil
  1728. org-agenda-bulk-marked-entries nil)
  1729. (setq major-mode 'org-agenda-mode)
  1730. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1731. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1732. (setq mode-name "Org-Agenda")
  1733. (use-local-map org-agenda-mode-map)
  1734. (easy-menu-add org-agenda-menu)
  1735. (if org-startup-truncated (setq truncate-lines t))
  1736. (org-set-local 'line-move-visual nil)
  1737. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1738. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1739. ;; Make sure properties are removed when copying text
  1740. (make-local-variable 'filter-buffer-substring-functions)
  1741. (add-hook 'filter-buffer-substring-functions
  1742. (lambda (fun start end delete)
  1743. (substring-no-properties (funcall fun start end delete))))
  1744. (unless org-agenda-keep-modes
  1745. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1746. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1747. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1748. org-agenda-show-log org-agenda-start-with-log-mode))
  1749. (easy-menu-change
  1750. '("Agenda") "Agenda Files"
  1751. (append
  1752. (list
  1753. (vector
  1754. (if (get 'org-agenda-files 'org-restrict)
  1755. "Restricted to single file"
  1756. "Edit File List")
  1757. '(org-edit-agenda-file-list)
  1758. (not (get 'org-agenda-files 'org-restrict)))
  1759. "--")
  1760. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1761. (org-agenda-set-mode-name)
  1762. (apply
  1763. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1764. (list 'org-agenda-mode-hook)))
  1765. (substitute-key-definition 'undo 'org-agenda-undo
  1766. org-agenda-mode-map global-map)
  1767. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1768. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1769. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1770. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1771. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1772. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1773. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1774. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1775. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1776. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1777. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1778. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1779. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1780. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1781. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1782. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1783. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1784. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1785. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1786. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1787. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1788. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1789. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1790. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1791. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1792. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1794. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1795. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1796. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1797. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1798. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1799. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1800. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1801. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1802. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1803. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1804. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1805. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1806. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1807. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1808. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1809. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1810. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1811. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1812. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1813. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1814. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1815. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1816. (while l (org-defkey org-agenda-mode-map
  1817. (int-to-string (pop l)) 'digit-argument)))
  1818. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1819. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1820. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1821. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1822. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1823. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1824. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1825. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1826. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1827. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1828. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1829. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1830. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1831. 'org-clock-modify-effort-estimate)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1833. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1834. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1835. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1836. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1837. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1838. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1839. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1840. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1841. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1842. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1843. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1844. (substitute-key-definition 'next-line 'org-agenda-next-line
  1845. org-agenda-mode-map global-map)
  1846. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1847. org-agenda-mode-map global-map)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1849. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1850. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1851. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1852. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1853. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1854. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1855. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1856. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1857. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1858. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1859. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1860. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1861. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1862. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1863. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1864. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1865. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1866. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1867. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1868. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1869. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1870. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1871. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1872. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1873. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1874. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1875. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1877. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1878. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1879. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1880. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1881. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1882. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1883. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1884. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1885. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1886. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1887. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1888. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1889. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1890. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1891. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1892. (when org-agenda-mouse-1-follows-link
  1893. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1894. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1895. '("Agenda"
  1896. ("Agenda Files")
  1897. "--"
  1898. ("Agenda Dates"
  1899. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1900. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1901. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1902. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1903. "--"
  1904. ("View"
  1905. ["Day View" org-agenda-day-view
  1906. :active (org-agenda-check-type nil 'agenda)
  1907. :style radio :selected (eq org-agenda-current-span 'day)
  1908. :keys "v d (or just d)"]
  1909. ["Week View" org-agenda-week-view
  1910. :active (org-agenda-check-type nil 'agenda)
  1911. :style radio :selected (eq org-agenda-current-span 'week)
  1912. :keys "v w (or just w)"]
  1913. ["Month View" org-agenda-month-view
  1914. :active (org-agenda-check-type nil 'agenda)
  1915. :style radio :selected (eq org-agenda-current-span 'month)
  1916. :keys "v m"]
  1917. ["Year View" org-agenda-year-view
  1918. :active (org-agenda-check-type nil 'agenda)
  1919. :style radio :selected (eq org-agenda-current-span 'year)
  1920. :keys "v y"]
  1921. "--"
  1922. ["Include Diary" org-agenda-toggle-diary
  1923. :style toggle :selected org-agenda-include-diary
  1924. :active (org-agenda-check-type nil 'agenda)]
  1925. ["Include Deadlines" org-agenda-toggle-deadlines
  1926. :style toggle :selected org-agenda-include-deadlines
  1927. :active (org-agenda-check-type nil 'agenda)]
  1928. ["Use Time Grid" org-agenda-toggle-time-grid
  1929. :style toggle :selected org-agenda-use-time-grid
  1930. :active (org-agenda-check-type nil 'agenda)]
  1931. "--"
  1932. ["Show clock report" org-agenda-clockreport-mode
  1933. :style toggle :selected org-agenda-clockreport-mode
  1934. :active (org-agenda-check-type nil 'agenda)]
  1935. ["Show some entry text" org-agenda-entry-text-mode
  1936. :style toggle :selected org-agenda-entry-text-mode
  1937. :active t]
  1938. "--"
  1939. ["Show Logbook entries" org-agenda-log-mode
  1940. :style toggle :selected org-agenda-show-log
  1941. :active (org-agenda-check-type nil 'agenda 'timeline)
  1942. :keys "v l (or just l)"]
  1943. ["Include archived trees" org-agenda-archives-mode
  1944. :style toggle :selected org-agenda-archives-mode :active t
  1945. :keys "v a"]
  1946. ["Include archive files" (org-agenda-archives-mode t)
  1947. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1948. :keys "v A"]
  1949. "--"
  1950. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1951. ["Write view to file" org-agenda-write t]
  1952. ["Rebuild buffer" org-agenda-redo t]
  1953. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1954. "--"
  1955. ["Show original entry" org-agenda-show t]
  1956. ["Go To (other window)" org-agenda-goto t]
  1957. ["Go To (this window)" org-agenda-switch-to t]
  1958. ["Capture with cursor date" org-agenda-capture t]
  1959. ["Follow Mode" org-agenda-follow-mode
  1960. :style toggle :selected org-agenda-follow-mode :active t]
  1961. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1962. "--"
  1963. ("TODO"
  1964. ["Cycle TODO" org-agenda-todo t]
  1965. ["Next TODO set" org-agenda-todo-nextset t]
  1966. ["Previous TODO set" org-agenda-todo-previousset t]
  1967. ["Add note" org-agenda-add-note t])
  1968. ("Archive/Refile/Delete"
  1969. ["Archive default" org-agenda-archive-default t]
  1970. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1971. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1972. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1973. ["Archive subtree" org-agenda-archive t]
  1974. "--"
  1975. ["Refile" org-agenda-refile t]
  1976. "--"
  1977. ["Delete subtree" org-agenda-kill t])
  1978. ("Bulk action"
  1979. ["Mark entry" org-agenda-bulk-mark t]
  1980. ["Mark all" org-agenda-bulk-mark-all t]
  1981. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1982. ["Unmark entry" org-agenda-bulk-unmark t]
  1983. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  1984. ["Act on all marked" org-agenda-bulk-action t]
  1985. "--"
  1986. ("Tags and Properties"
  1987. ["Show all Tags" org-agenda-show-tags t]
  1988. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1989. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1990. "--"
  1991. ["Column View" org-columns t])
  1992. ("Deadline/Schedule"
  1993. ["Schedule" org-agenda-schedule t]
  1994. ["Set Deadline" org-agenda-deadline t]
  1995. "--"
  1996. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1997. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1998. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1999. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2000. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2001. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2002. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2003. ("Clock and Effort"
  2004. ["Clock in" org-agenda-clock-in t]
  2005. ["Clock out" org-agenda-clock-out t]
  2006. ["Clock cancel" org-agenda-clock-cancel t]
  2007. ["Goto running clock" org-clock-goto t]
  2008. "--"
  2009. ["Set Effort" org-agenda-set-effort t]
  2010. ["Change clocked effort" org-clock-modify-effort-estimate
  2011. (org-clock-is-active)])
  2012. ("Priority"
  2013. ["Set Priority" org-agenda-priority t]
  2014. ["Increase Priority" org-agenda-priority-up t]
  2015. ["Decrease Priority" org-agenda-priority-down t]
  2016. ["Show Priority" org-show-priority t])
  2017. ("Calendar/Diary"
  2018. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2019. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2020. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2021. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2022. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2023. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2024. "--"
  2025. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2026. "--"
  2027. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2028. "--"
  2029. ("MobileOrg"
  2030. ["Push Files and Views" org-mobile-push t]
  2031. ["Get Captured and Flagged" org-mobile-pull t]
  2032. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2033. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2034. "--"
  2035. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2036. "--"
  2037. ["Quit" org-agenda-quit t]
  2038. ["Exit and Release Buffers" org-agenda-exit t]
  2039. ))
  2040. ;;; Agenda undo
  2041. (defvar org-agenda-allow-remote-undo t
  2042. "Non-nil means allow remote undo from the agenda buffer.")
  2043. (defvar org-agenda-undo-has-started-in nil
  2044. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2045. (defun org-agenda-undo ()
  2046. "Undo a remote editing step in the agenda.
  2047. This undoes changes both in the agenda buffer and in the remote buffer
  2048. that have been changed along."
  2049. (interactive)
  2050. (or org-agenda-allow-remote-undo
  2051. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2052. (if (not (eq this-command last-command))
  2053. (setq org-agenda-undo-has-started-in nil
  2054. org-agenda-pending-undo-list org-agenda-undo-list))
  2055. (if (not org-agenda-pending-undo-list)
  2056. (error "No further undo information"))
  2057. (let* ((entry (pop org-agenda-pending-undo-list))
  2058. buf line cmd rembuf)
  2059. (setq cmd (pop entry) line (pop entry))
  2060. (setq rembuf (nth 2 entry))
  2061. (org-with-remote-undo rembuf
  2062. (while (bufferp (setq buf (pop entry)))
  2063. (if (pop entry)
  2064. (with-current-buffer buf
  2065. (let ((last-undo-buffer buf)
  2066. (inhibit-read-only t))
  2067. (unless (memq buf org-agenda-undo-has-started-in)
  2068. (push buf org-agenda-undo-has-started-in)
  2069. (make-local-variable 'pending-undo-list)
  2070. (undo-start))
  2071. (while (and pending-undo-list
  2072. (listp pending-undo-list)
  2073. (not (car pending-undo-list)))
  2074. (pop pending-undo-list))
  2075. (undo-more 1))))))
  2076. (org-goto-line line)
  2077. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2078. (defun org-verify-change-for-undo (l1 l2)
  2079. "Verify that a real change occurred between the undo lists L1 and L2."
  2080. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2081. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2082. (not (eq l1 l2)))
  2083. ;;; Agenda dispatch
  2084. (defvar org-agenda-restrict-begin (make-marker))
  2085. (defvar org-agenda-restrict-end (make-marker))
  2086. (defvar org-agenda-last-dispatch-buffer nil)
  2087. (defvar org-agenda-overriding-restriction nil)
  2088. (defcustom org-agenda-custom-commands-contexts nil
  2089. "Alist of custom agenda keys and contextual rules.
  2090. For example, if you have a custom agenda command \"p\" and you
  2091. want this command to be accessible only from plain text files,
  2092. use this:
  2093. '((\"p\" (in-file . \"\\.txt\")))
  2094. Here are the available contexts definitions:
  2095. in-file: command displayed only in matching files
  2096. in-mode: command displayed only in matching modes
  2097. not-in-file: command not displayed in matching files
  2098. not-in-mode: command not displayed in matching modes
  2099. [function]: a custom function taking no argument
  2100. If you define several checks, the agenda command will be
  2101. accessible if there is at least one valid check.
  2102. You can also bind a key to another agenda custom command
  2103. depending on contextual rules.
  2104. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2105. Here it means: in .txt files, use \"p\" as the key for the
  2106. agenda command otherwise associated with \"q\". (The command
  2107. originally associated with \"q\" is not displayed to avoid
  2108. duplicates.)"
  2109. ;; :version "24.3"
  2110. :group 'org-agenda-custom-commands
  2111. :type '(repeat (list :tag "Rule"
  2112. (string :tag " Agenda key")
  2113. (string :tag "Replace by command")
  2114. (repeat :tag "Available when"
  2115. (choice
  2116. (cons :tag "Condition"
  2117. (choice
  2118. (const :tag "In file" in-file)
  2119. (const :tag "Not in file" not-in-file)
  2120. (const :tag "In mode" in-mode)
  2121. (const :tag "Not in mode" not-in-mode))
  2122. (regexp))
  2123. (function :tag "Custom function"))))))
  2124. (defvar org-keys nil)
  2125. (defvar org-match nil)
  2126. ;;;###autoload
  2127. (defun org-agenda (&optional arg org-keys restriction)
  2128. "Dispatch agenda commands to collect entries to the agenda buffer.
  2129. Prompts for a command to execute. Any prefix arg will be passed
  2130. on to the selected command. The default selections are:
  2131. a Call `org-agenda-list' to display the agenda for current day or week.
  2132. t Call `org-todo-list' to display the global todo list.
  2133. T Call `org-todo-list' to display the global todo list, select only
  2134. entries with a specific TODO keyword (the user gets a prompt).
  2135. m Call `org-tags-view' to display headlines with tags matching
  2136. a condition (the user is prompted for the condition).
  2137. M Like `m', but select only TODO entries, no ordinary headlines.
  2138. L Create a timeline for the current buffer.
  2139. e Export views to associated files.
  2140. s Search entries for keywords.
  2141. S Search entries for keywords, only with TODO keywords.
  2142. / Multi occur across all agenda files and also files listed
  2143. in `org-agenda-text-search-extra-files'.
  2144. < Restrict agenda commands to buffer, subtree, or region.
  2145. Press several times to get the desired effect.
  2146. > Remove a previous restriction.
  2147. # List \"stuck\" projects.
  2148. ! Configure what \"stuck\" means.
  2149. C Configure custom agenda commands.
  2150. More commands can be added by configuring the variable
  2151. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2152. searches can be pre-defined in this way.
  2153. If the current buffer is in Org-mode and visiting a file, you can also
  2154. first press `<' once to indicate that the agenda should be temporarily
  2155. \(until the next use of \\[org-agenda]) restricted to the current file.
  2156. Pressing `<' twice means to restrict to the current subtree or region
  2157. \(if active)."
  2158. (interactive "P")
  2159. (catch 'exit
  2160. (let* ((prefix-descriptions nil)
  2161. (org-agenda-buffer-name org-agenda-buffer-name)
  2162. (org-agenda-window-setup (if (equal (buffer-name)
  2163. org-agenda-buffer-name)
  2164. 'current-window
  2165. org-agenda-window-setup))
  2166. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2167. (org-agenda-custom-commands
  2168. ;; normalize different versions
  2169. (delq nil
  2170. (mapcar
  2171. (lambda (x)
  2172. (cond ((stringp (cdr x))
  2173. (push x prefix-descriptions)
  2174. nil)
  2175. ((stringp (nth 1 x)) x)
  2176. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2177. (t (cons (car x) (cons "" (cdr x))))))
  2178. org-agenda-custom-commands)))
  2179. (org-agenda-custom-commands
  2180. (org-contextualize-keys
  2181. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2182. (buf (current-buffer))
  2183. (bfn (buffer-file-name (buffer-base-buffer)))
  2184. entry key type org-match lprops ans)
  2185. ;; Turn off restriction unless there is an overriding one,
  2186. (unless org-agenda-overriding-restriction
  2187. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2188. ;; There is a request to keep the file list in place
  2189. (put 'org-agenda-files 'org-restrict nil))
  2190. (setq org-agenda-restrict nil)
  2191. (move-marker org-agenda-restrict-begin nil)
  2192. (move-marker org-agenda-restrict-end nil))
  2193. ;; Delete old local properties
  2194. (put 'org-agenda-redo-command 'org-lprops nil)
  2195. ;; Delete previously set last-arguments
  2196. (put 'org-agenda-redo-command 'last-args nil)
  2197. ;; Remember where this call originated
  2198. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2199. (unless org-keys
  2200. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2201. org-keys (car ans)
  2202. restriction (cdr ans)))
  2203. ;; If we have sticky agenda buffers, set a name for the buffer,
  2204. ;; depending on the invoking keys. The user may still set this
  2205. ;; as a command option, which will overwrite what we do here.
  2206. (if org-agenda-sticky
  2207. (setq org-agenda-buffer-name
  2208. (format "*Org Agenda(%s)*" org-keys)))
  2209. ;; Establish the restriction, if any
  2210. (when (and (not org-agenda-overriding-restriction) restriction)
  2211. (put 'org-agenda-files 'org-restrict (list bfn))
  2212. (cond
  2213. ((eq restriction 'region)
  2214. (setq org-agenda-restrict t)
  2215. (move-marker org-agenda-restrict-begin (region-beginning))
  2216. (move-marker org-agenda-restrict-end (region-end)))
  2217. ((eq restriction 'subtree)
  2218. (save-excursion
  2219. (setq org-agenda-restrict t)
  2220. (org-back-to-heading t)
  2221. (move-marker org-agenda-restrict-begin (point))
  2222. (move-marker org-agenda-restrict-end
  2223. (progn (org-end-of-subtree t)))))))
  2224. ;; For example the todo list should not need it (but does...)
  2225. (cond
  2226. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2227. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2228. (progn
  2229. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2230. lprops (nth 4 entry))
  2231. (if org-agenda-sticky
  2232. (setq org-agenda-buffer-name
  2233. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2234. (format "*Org Agenda(%s)*" org-keys))))
  2235. (put 'org-agenda-redo-command 'org-lprops lprops)
  2236. (cond
  2237. ((eq type 'agenda)
  2238. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2239. ((eq type 'alltodo)
  2240. (org-let lprops '(org-todo-list current-prefix-arg)))
  2241. ((eq type 'search)
  2242. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2243. ((eq type 'stuck)
  2244. (org-let lprops '(org-agenda-list-stuck-projects
  2245. current-prefix-arg)))
  2246. ((eq type 'tags)
  2247. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2248. ((eq type 'tags-todo)
  2249. (org-let lprops '(org-tags-view '(4) org-match)))
  2250. ((eq type 'todo)
  2251. (org-let lprops '(org-todo-list org-match)))
  2252. ((eq type 'tags-tree)
  2253. (org-check-for-org-mode)
  2254. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2255. ((eq type 'todo-tree)
  2256. (org-check-for-org-mode)
  2257. (org-let lprops
  2258. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2259. (regexp-quote org-match) "\\>"))))
  2260. ((eq type 'occur-tree)
  2261. (org-check-for-org-mode)
  2262. (org-let lprops '(org-occur org-match)))
  2263. ((functionp type)
  2264. (org-let lprops '(funcall type org-match)))
  2265. ((fboundp type)
  2266. (org-let lprops '(funcall type org-match)))
  2267. (t (error "Invalid custom agenda command type %s" type))))
  2268. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2269. ((equal org-keys "C")
  2270. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2271. (customize-variable 'org-agenda-custom-commands))
  2272. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2273. ((equal org-keys "s") (call-interactively 'org-search-view))
  2274. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2275. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2276. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2277. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2278. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2279. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2280. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2281. (org-add-hook
  2282. 'post-command-hook
  2283. (lambda ()
  2284. (unless (current-message)
  2285. (let* ((m (org-agenda-get-any-marker))
  2286. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2287. (when note
  2288. (message (concat
  2289. "FLAGGING-NOTE ([?] for more info): "
  2290. (org-add-props
  2291. (replace-regexp-in-string
  2292. "\\\\n" "//"
  2293. (copy-sequence note))
  2294. nil 'face 'org-warning)))))))
  2295. t t))
  2296. ((equal org-keys "L")
  2297. (unless (derived-mode-p 'org-mode)
  2298. (error "This is not an Org-mode file"))
  2299. (unless restriction
  2300. (put 'org-agenda-files 'org-restrict (list bfn))
  2301. (org-call-with-arg 'org-timeline arg)))
  2302. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2303. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2304. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2305. (t (error "Invalid agenda key"))))))
  2306. (defun org-agenda-append-agenda ()
  2307. "Append another agenda view to the current one.
  2308. This function allows interactive building of block agendas.
  2309. Agenda views are separated by `org-agenda-block-separator'."
  2310. (interactive)
  2311. (unless (derived-mode-p 'org-agenda-mode)
  2312. (error "Can only append from within agenda buffer"))
  2313. (let ((org-agenda-multi t))
  2314. (org-agenda)
  2315. (widen)
  2316. (org-agenda-finalize)
  2317. (org-agenda-fit-window-to-buffer)))
  2318. (defun org-agenda-normalize-custom-commands (cmds)
  2319. (delq nil
  2320. (mapcar
  2321. (lambda (x)
  2322. (cond ((stringp (cdr x)) nil)
  2323. ((stringp (nth 1 x)) x)
  2324. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2325. (t (cons (car x) (cons "" (cdr x))))))
  2326. cmds)))
  2327. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2328. "The user interface for selecting an agenda command."
  2329. (catch 'exit
  2330. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2331. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2332. (region-p (org-region-active-p))
  2333. (custom org-agenda-custom-commands)
  2334. (selstring "")
  2335. restriction second-time
  2336. c entry key type match prefixes rmheader header-end custom1 desc
  2337. line lines left right n n1)
  2338. (save-window-excursion
  2339. (delete-other-windows)
  2340. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2341. (erase-buffer)
  2342. (insert (eval-when-compile
  2343. (let ((header
  2344. "Press key for an agenda command: < Buffer, subtree/region restriction
  2345. -------------------------------- > Remove restriction
  2346. a Agenda for current week or day e Export agenda views
  2347. t List of all TODO entries T Entries with special TODO kwd
  2348. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2349. s Search for keywords S Like s, but only TODO entries
  2350. L Timeline for current buffer # List stuck projects (!=configure)
  2351. / Multi-occur C Configure custom agenda commands
  2352. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2353. ")
  2354. (start 0))
  2355. (while (string-match
  2356. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2357. header start)
  2358. (setq start (match-end 0))
  2359. (add-text-properties (match-beginning 2) (match-end 2)
  2360. '(face bold) header))
  2361. header)))
  2362. (setq header-end (move-marker (make-marker) (point)))
  2363. (while t
  2364. (setq custom1 custom)
  2365. (when (eq rmheader t)
  2366. (org-goto-line 1)
  2367. (re-search-forward ":" nil t)
  2368. (delete-region (match-end 0) (point-at-eol))
  2369. (forward-char 1)
  2370. (looking-at "-+")
  2371. (delete-region (match-end 0) (point-at-eol))
  2372. (move-marker header-end (match-end 0)))
  2373. (goto-char header-end)
  2374. (delete-region (point) (point-max))
  2375. ;; Produce all the lines that describe custom commands and prefixes
  2376. (setq lines nil)
  2377. (while (setq entry (pop custom1))
  2378. (setq key (car entry) desc (nth 1 entry)
  2379. type (nth 2 entry)
  2380. match (nth 3 entry))
  2381. (if (> (length key) 1)
  2382. (add-to-list 'prefixes (string-to-char key))
  2383. (setq line
  2384. (format
  2385. "%-4s%-14s"
  2386. (org-add-props (copy-sequence key)
  2387. '(face bold))
  2388. (cond
  2389. ((string-match "\\S-" desc) desc)
  2390. ((eq type 'agenda) "Agenda for current week or day")
  2391. ((eq type 'alltodo) "List of all TODO entries")
  2392. ((eq type 'search) "Word search")
  2393. ((eq type 'stuck) "List of stuck projects")
  2394. ((eq type 'todo) "TODO keyword")
  2395. ((eq type 'tags) "Tags query")
  2396. ((eq type 'tags-todo) "Tags (TODO)")
  2397. ((eq type 'tags-tree) "Tags tree")
  2398. ((eq type 'todo-tree) "TODO kwd tree")
  2399. ((eq type 'occur-tree) "Occur tree")
  2400. ((functionp type) (if (symbolp type)
  2401. (symbol-name type)
  2402. "Lambda expression"))
  2403. (t "???"))))
  2404. (if org-agenda-menu-show-matcher
  2405. (setq line
  2406. (concat line ": "
  2407. (cond
  2408. ((stringp match)
  2409. (setq match (copy-sequence match))
  2410. (org-add-props match nil 'face 'org-warning))
  2411. ((listp type)
  2412. (format "set of %d commands" (length type))))))
  2413. (if (org-string-nw-p match)
  2414. (add-text-properties
  2415. 0 (length line) (list 'help-echo
  2416. (concat "Matcher: " match)) line)))
  2417. (push line lines)))
  2418. (setq lines (nreverse lines))
  2419. (when prefixes
  2420. (mapc (lambda (x)
  2421. (push
  2422. (format "%s %s"
  2423. (org-add-props (char-to-string x)
  2424. nil 'face 'bold)
  2425. (or (cdr (assoc (concat selstring
  2426. (char-to-string x))
  2427. prefix-descriptions))
  2428. "Prefix key"))
  2429. lines))
  2430. prefixes))
  2431. ;; Check if we should display in two columns
  2432. (if org-agenda-menu-two-columns
  2433. (progn
  2434. (setq n (length lines)
  2435. n1 (+ (/ n 2) (mod n 2))
  2436. right (nthcdr n1 lines)
  2437. left (copy-sequence lines))
  2438. (setcdr (nthcdr (1- n1) left) nil))
  2439. (setq left lines right nil))
  2440. (while left
  2441. (insert "\n" (pop left))
  2442. (when right
  2443. (if (< (current-column) 40)
  2444. (move-to-column 40 t)
  2445. (insert " "))
  2446. (insert (pop right))))
  2447. ;; Make the window the right size
  2448. (goto-char (point-min))
  2449. (if second-time
  2450. (if (not (pos-visible-in-window-p (point-max)))
  2451. (org-fit-window-to-buffer))
  2452. (setq second-time t)
  2453. (org-fit-window-to-buffer))
  2454. ;; Ask for selection
  2455. (message "Press key for agenda command%s:"
  2456. (if (or restrict-ok org-agenda-overriding-restriction)
  2457. (if org-agenda-overriding-restriction
  2458. " (restriction lock active)"
  2459. (if restriction
  2460. (format " (restricted to %s)" restriction)
  2461. " (unrestricted)"))
  2462. ""))
  2463. (setq c (read-char-exclusive))
  2464. (message "")
  2465. (cond
  2466. ((assoc (char-to-string c) custom)
  2467. (setq selstring (concat selstring (char-to-string c)))
  2468. (throw 'exit (cons selstring restriction)))
  2469. ((memq c prefixes)
  2470. (setq selstring (concat selstring (char-to-string c))
  2471. prefixes nil
  2472. rmheader (or rmheader t)
  2473. custom (delq nil (mapcar
  2474. (lambda (x)
  2475. (if (or (= (length (car x)) 1)
  2476. (/= (string-to-char (car x)) c))
  2477. nil
  2478. (cons (substring (car x) 1) (cdr x))))
  2479. custom))))
  2480. ((eq c ?*)
  2481. (call-interactively 'org-toggle-sticky-agenda)
  2482. (sit-for 2))
  2483. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2484. (message "Restriction is only possible in Org-mode buffers")
  2485. (ding) (sit-for 1))
  2486. ((eq c ?1)
  2487. (org-agenda-remove-restriction-lock 'noupdate)
  2488. (setq restriction 'buffer))
  2489. ((eq c ?0)
  2490. (org-agenda-remove-restriction-lock 'noupdate)
  2491. (setq restriction (if region-p 'region 'subtree)))
  2492. ((eq c ?<)
  2493. (org-agenda-remove-restriction-lock 'noupdate)
  2494. (setq restriction
  2495. (cond
  2496. ((eq restriction 'buffer)
  2497. (if region-p 'region 'subtree))
  2498. ((memq restriction '(subtree region))
  2499. nil)
  2500. (t 'buffer))))
  2501. ((eq c ?>)
  2502. (org-agenda-remove-restriction-lock 'noupdate)
  2503. (setq restriction nil))
  2504. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2505. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2506. ((and (> (length selstring) 0) (eq c ?\d))
  2507. (delete-window)
  2508. (org-agenda-get-restriction-and-command prefix-descriptions))
  2509. ((equal c ?q) (error "Abort"))
  2510. (t (error "Invalid key %c" c))))))))
  2511. (defun org-agenda-fit-window-to-buffer ()
  2512. "Fit the window to the buffer size."
  2513. (and (memq org-agenda-window-setup '(reorganize-frame))
  2514. (fboundp 'fit-window-to-buffer)
  2515. (org-fit-window-to-buffer
  2516. nil
  2517. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2518. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2519. (defvar org-cmd nil)
  2520. (defvar org-agenda-overriding-cmd nil)
  2521. (defvar org-agenda-overriding-arguments nil)
  2522. (defvar org-agenda-overriding-cmd-arguments nil)
  2523. (defun org-agenda-run-series (name series)
  2524. (org-let (nth 1 series) '(org-agenda-prepare name))
  2525. ;; We need to reset agenda markers here, because when constructing a
  2526. ;; block agenda, the individual blocks do not do that.
  2527. (org-agenda-reset-markers)
  2528. (let* ((org-agenda-multi t)
  2529. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2530. (cmds (car series))
  2531. (gprops (nth 1 series))
  2532. match ;; The byte compiler incorrectly complains about this. Keep it!
  2533. org-cmd type lprops)
  2534. (while (setq org-cmd (pop cmds))
  2535. (setq type (car org-cmd)
  2536. match (eval (nth 1 org-cmd))
  2537. lprops (nth 2 org-cmd))
  2538. (let ((org-agenda-overriding-arguments
  2539. (if (eq org-agenda-overriding-cmd org-cmd)
  2540. (or org-agenda-overriding-arguments
  2541. org-agenda-overriding-cmd-arguments))))
  2542. (cond
  2543. ((eq type 'agenda)
  2544. (org-let2 gprops lprops
  2545. '(call-interactively 'org-agenda-list)))
  2546. ((eq type 'alltodo)
  2547. (org-let2 gprops lprops
  2548. '(call-interactively 'org-todo-list)))
  2549. ((eq type 'search)
  2550. (org-let2 gprops lprops
  2551. '(org-search-view current-prefix-arg match nil)))
  2552. ((eq type 'stuck)
  2553. (org-let2 gprops lprops
  2554. '(call-interactively 'org-agenda-list-stuck-projects)))
  2555. ((eq type 'tags)
  2556. (org-let2 gprops lprops
  2557. '(org-tags-view current-prefix-arg match)))
  2558. ((eq type 'tags-todo)
  2559. (org-let2 gprops lprops
  2560. '(org-tags-view '(4) match)))
  2561. ((eq type 'todo)
  2562. (org-let2 gprops lprops
  2563. '(org-todo-list match)))
  2564. ((fboundp type)
  2565. (org-let2 gprops lprops
  2566. '(funcall type match)))
  2567. (t (error "Invalid type in command series")))))
  2568. (widen)
  2569. (let ((inhibit-read-only t))
  2570. (add-text-properties (point-min) (point-max)
  2571. `(org-serie t org-serie-redo-cmd ,redo)))
  2572. (setq org-agenda-redo-command redo)
  2573. (goto-char (point-min)))
  2574. (org-agenda-fit-window-to-buffer)
  2575. (org-let (nth 1 series) '(org-agenda-finalize)))
  2576. ;;;###autoload
  2577. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2578. "Run an agenda command in batch mode and send the result to STDOUT.
  2579. If CMD-KEY is a string of length 1, it is used as a key in
  2580. `org-agenda-custom-commands' and triggers this command. If it is a
  2581. longer string it is used as a tags/todo match string.
  2582. Parameters are alternating variable names and values that will be bound
  2583. before running the agenda command."
  2584. (org-eval-in-environment (org-make-parameter-alist parameters)
  2585. (if (> (length cmd-key) 2)
  2586. (org-tags-view nil cmd-key)
  2587. (org-agenda nil cmd-key)))
  2588. (set-buffer org-agenda-buffer-name)
  2589. (princ (buffer-string)))
  2590. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2591. (defvar org-agenda-info nil)
  2592. ;;;###autoload
  2593. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2594. "Run an agenda command in batch mode and send the result to STDOUT.
  2595. If CMD-KEY is a string of length 1, it is used as a key in
  2596. `org-agenda-custom-commands' and triggers this command. If it is a
  2597. longer string it is used as a tags/todo match string.
  2598. Parameters are alternating variable names and values that will be bound
  2599. before running the agenda command.
  2600. The output gives a line for each selected agenda item. Each
  2601. item is a list of comma-separated values, like this:
  2602. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2603. category The category of the item
  2604. head The headline, without TODO kwd, TAGS and PRIORITY
  2605. type The type of the agenda entry, can be
  2606. todo selected in TODO match
  2607. tagsmatch selected in tags match
  2608. diary imported from diary
  2609. deadline a deadline on given date
  2610. scheduled scheduled on given date
  2611. timestamp entry has timestamp on given date
  2612. closed entry was closed on given date
  2613. upcoming-deadline warning about deadline
  2614. past-scheduled forwarded scheduled item
  2615. block entry has date block including g. date
  2616. todo The todo keyword, if any
  2617. tags All tags including inherited ones, separated by colons
  2618. date The relevant date, like 2007-2-14
  2619. time The time, like 15:00-16:50
  2620. extra Sting with extra planning info
  2621. priority-l The priority letter if any was given
  2622. priority-n The computed numerical priority
  2623. agenda-day The day in the agenda where this is listed"
  2624. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2625. (org-make-parameter-alist parameters))
  2626. (if (> (length cmd-key) 2)
  2627. (org-tags-view nil cmd-key)
  2628. (org-agenda nil cmd-key)))
  2629. (set-buffer org-agenda-buffer-name)
  2630. (let* ((lines (org-split-string (buffer-string) "\n"))
  2631. line)
  2632. (while (setq line (pop lines))
  2633. (catch 'next
  2634. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2635. (setq org-agenda-info
  2636. (org-fix-agenda-info (text-properties-at 0 line)))
  2637. (princ
  2638. (mapconcat 'org-agenda-export-csv-mapper
  2639. '(org-category txt type todo tags date time extra
  2640. priority-letter priority agenda-day)
  2641. ","))
  2642. (princ "\n")))))
  2643. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2644. (defun org-fix-agenda-info (props)
  2645. "Make sure all properties on an agenda item have a canonical form.
  2646. This ensures the export commands can easily use it."
  2647. (let (tmp re)
  2648. (when (setq tmp (plist-get props 'tags))
  2649. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2650. (when (setq tmp (plist-get props 'date))
  2651. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2652. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2653. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2654. (setq tmp (calendar-date-string tmp)))
  2655. (setq props (plist-put props 'date tmp)))
  2656. (when (setq tmp (plist-get props 'day))
  2657. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2658. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2659. (setq tmp (calendar-date-string tmp)))
  2660. (setq props (plist-put props 'day tmp))
  2661. (setq props (plist-put props 'agenda-day tmp)))
  2662. (when (setq tmp (plist-get props 'txt))
  2663. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2664. (plist-put props 'priority-letter (match-string 1 tmp))
  2665. (setq tmp (replace-match "" t t tmp)))
  2666. (when (and (setq re (plist-get props 'org-todo-regexp))
  2667. (setq re (concat "\\`\\.*" re " ?"))
  2668. (string-match re tmp))
  2669. (plist-put props 'todo (match-string 1 tmp))
  2670. (setq tmp (replace-match "" t t tmp)))
  2671. (plist-put props 'txt tmp)))
  2672. props)
  2673. (defun org-agenda-export-csv-mapper (prop)
  2674. (let ((res (plist-get org-agenda-info prop)))
  2675. (setq res
  2676. (cond
  2677. ((not res) "")
  2678. ((stringp res) res)
  2679. (t (prin1-to-string res))))
  2680. (while (string-match "," res)
  2681. (setq res (replace-match ";" t t res)))
  2682. (org-trim res)))
  2683. ;;;###autoload
  2684. (defun org-store-agenda-views (&rest parameters)
  2685. (interactive)
  2686. (eval (list 'org-batch-store-agenda-views)))
  2687. ;;;###autoload
  2688. (defmacro org-batch-store-agenda-views (&rest parameters)
  2689. "Run all custom agenda commands that have a file argument."
  2690. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2691. (pop-up-frames nil)
  2692. (dir default-directory)
  2693. (pars (org-make-parameter-alist parameters))
  2694. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2695. (save-window-excursion
  2696. (while cmds
  2697. (setq cmd (pop cmds)
  2698. thiscmdkey (car cmd)
  2699. thiscmdcmd (cdr cmd)
  2700. match (nth 2 thiscmdcmd)
  2701. bufname (if org-agenda-sticky
  2702. (or (and (stringp match)
  2703. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2704. (format "*Org Agenda(%s)*" thiscmdkey))
  2705. org-agenda-buffer-name)
  2706. cmd-or-set (nth 2 cmd)
  2707. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2708. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2709. (if (stringp files) (setq files (list files)))
  2710. (when files
  2711. (org-eval-in-environment (append org-agenda-exporter-settings
  2712. opts pars)
  2713. (org-agenda nil thiscmdkey))
  2714. (set-buffer bufname)
  2715. (while files
  2716. (org-eval-in-environment (append org-agenda-exporter-settings
  2717. opts pars)
  2718. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2719. (and (get-buffer bufname)
  2720. (kill-buffer bufname)))))))
  2721. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2722. (defvar org-agenda-current-span nil
  2723. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2724. (defun org-agenda-mark-header-line (pos)
  2725. "Mark the line at POS as an agenda structure header."
  2726. (save-excursion
  2727. (goto-char pos)
  2728. (put-text-property (point-at-bol) (point-at-eol)
  2729. 'org-agenda-structural-header t)
  2730. (when org-agenda-title-append
  2731. (put-text-property (point-at-bol) (point-at-eol)
  2732. 'org-agenda-title-append org-agenda-title-append))))
  2733. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2734. (defvar org-agenda-write-buffer-name "Agenda View")
  2735. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2736. "Write the current buffer (an agenda view) as a file.
  2737. Depending on the extension of the file name, plain text (.txt),
  2738. HTML (.html or .htm) or Postscript (.ps) is produced.
  2739. If the extension is .ics, run icalendar export over all files used
  2740. to construct the agenda and limit the export to entries listed in the
  2741. agenda now.
  2742. With prefix argument OPEN, open the new file immediately.
  2743. If NOSETTINGS is given, do not scope the settings of
  2744. `org-agenda-exporter-settings' into the export commands. This is used when
  2745. the settings have already been scoped and we do not wish to overrule other,
  2746. higher priority settings.
  2747. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2748. (interactive "FWrite agenda to file: \nP")
  2749. (if (not (file-writable-p file))
  2750. (error "Cannot write agenda to file %s" file))
  2751. (org-let (if nosettings nil org-agenda-exporter-settings)
  2752. '(save-excursion
  2753. (save-window-excursion
  2754. (org-agenda-mark-filtered-text)
  2755. (let ((bs (copy-sequence (buffer-string))) beg)
  2756. (org-agenda-unmark-filtered-text)
  2757. (with-temp-buffer
  2758. (rename-buffer org-agenda-write-buffer-name t)
  2759. (set-buffer-modified-p nil)
  2760. (insert bs)
  2761. (org-agenda-remove-marked-text 'org-filtered)
  2762. (while (setq beg (text-property-any (point-min) (point-max)
  2763. 'org-filtered t))
  2764. (delete-region
  2765. beg (or (next-single-property-change beg 'org-filtered)
  2766. (point-max))))
  2767. (run-hooks 'org-agenda-before-write-hook)
  2768. (cond
  2769. ((org-bound-and-true-p org-mobile-creating-agendas)
  2770. (org-mobile-write-agenda-for-mobile file))
  2771. ((string-match "\\.html?\\'" file)
  2772. (require 'htmlize)
  2773. (set-buffer (htmlize-buffer (current-buffer)))
  2774. (when org-agenda-export-html-style
  2775. ;; replace <style> section with org-agenda-export-html-style
  2776. (goto-char (point-min))
  2777. (kill-region (- (search-forward "<style") 6)
  2778. (search-forward "</style>"))
  2779. (insert org-agenda-export-html-style))
  2780. (write-file file)
  2781. (kill-buffer (current-buffer))
  2782. (message "HTML written to %s" file))
  2783. ((string-match "\\.ps\\'" file)
  2784. (require 'ps-print)
  2785. (ps-print-buffer-with-faces file)
  2786. (message "Postscript written to %s" file))
  2787. ((string-match "\\.pdf\\'" file)
  2788. (require 'ps-print)
  2789. (ps-print-buffer-with-faces
  2790. (concat (file-name-sans-extension file) ".ps"))
  2791. (call-process "ps2pdf" nil nil nil
  2792. (expand-file-name
  2793. (concat (file-name-sans-extension file) ".ps"))
  2794. (expand-file-name file))
  2795. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2796. (message "PDF written to %s" file))
  2797. ((string-match "\\.ics\\'" file)
  2798. (require 'org-icalendar)
  2799. (let ((org-agenda-marker-table
  2800. (org-create-marker-find-array
  2801. (org-agenda-collect-markers)))
  2802. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2803. (org-combined-agenda-icalendar-file file))
  2804. (apply 'org-export-icalendar 'combine
  2805. (org-agenda-files nil 'ifmode))))
  2806. (t
  2807. (let ((bs (buffer-string)))
  2808. (find-file file)
  2809. (erase-buffer)
  2810. (insert bs)
  2811. (save-buffer 0)
  2812. (kill-buffer (current-buffer))
  2813. (message "Plain text written to %s" file))))))))
  2814. (set-buffer (or agenda-bufname
  2815. (and (called-interactively-p 'any) (buffer-name))
  2816. org-agenda-buffer-name)))
  2817. (when open (org-open-file file)))
  2818. (defvar org-agenda-tag-filter-overlays nil)
  2819. (defvar org-agenda-cat-filter-overlays nil)
  2820. (defun org-agenda-mark-filtered-text ()
  2821. "Mark all text hidden by filtering with a text property."
  2822. (let ((inhibit-read-only t))
  2823. (mapc
  2824. (lambda (o)
  2825. (when (equal (overlay-buffer o) (current-buffer))
  2826. (put-text-property
  2827. (overlay-start o) (overlay-end o)
  2828. 'org-filtered t)))
  2829. (append org-agenda-tag-filter-overlays
  2830. org-agenda-cat-filter-overlays))))
  2831. (defun org-agenda-unmark-filtered-text ()
  2832. "Remove the filtering text property."
  2833. (let ((inhibit-read-only t))
  2834. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2835. (defun org-agenda-remove-marked-text (property &optional value)
  2836. "Delete all text marked with VALUE of PROPERTY.
  2837. VALUE defaults to t."
  2838. (let (beg)
  2839. (setq value (or value t))
  2840. (while (setq beg (text-property-any (point-min) (point-max)
  2841. property value))
  2842. (delete-region
  2843. beg (or (next-single-property-change beg 'org-filtered)
  2844. (point-max))))))
  2845. (defun org-agenda-add-entry-text ()
  2846. "Add entry text to agenda lines.
  2847. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2848. entry text following headings shown in the agenda.
  2849. Drawers will be excluded, also the line with scheduling/deadline info."
  2850. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2851. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2852. (let (m txt)
  2853. (goto-char (point-min))
  2854. (while (not (eobp))
  2855. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2856. (beginning-of-line 2)
  2857. (setq txt (org-agenda-get-some-entry-text
  2858. m org-agenda-add-entry-text-maxlines " > "))
  2859. (end-of-line 1)
  2860. (if (string-match "\\S-" txt)
  2861. (insert "\n" txt)
  2862. (or (eobp) (forward-char 1))))))))
  2863. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2864. &rest keep)
  2865. "Extract entry text from MARKER, at most N-LINES lines.
  2866. This will ignore drawers etc, just get the text.
  2867. If INDENT is given, prefix every line with this string. If KEEP is
  2868. given, it is a list of symbols, defining stuff that should not be
  2869. removed from the entry content. Currently only `planning' is allowed here."
  2870. (let (txt drawer-re kwd-time-re ind)
  2871. (save-excursion
  2872. (with-current-buffer (marker-buffer marker)
  2873. (if (not (derived-mode-p 'org-mode))
  2874. (setq txt "")
  2875. (save-excursion
  2876. (save-restriction
  2877. (widen)
  2878. (goto-char marker)
  2879. (end-of-line 1)
  2880. (setq txt (buffer-substring
  2881. (min (1+ (point)) (point-max))
  2882. (progn (outline-next-heading) (point)))
  2883. drawer-re org-drawer-regexp
  2884. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2885. ".*\n?"))
  2886. (with-temp-buffer
  2887. (insert txt)
  2888. (when org-agenda-add-entry-text-descriptive-links
  2889. (goto-char (point-min))
  2890. (while (org-activate-bracket-links (point-max))
  2891. (add-text-properties (match-beginning 0) (match-end 0)
  2892. '(face org-link))))
  2893. (goto-char (point-min))
  2894. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2895. (set-text-properties (match-beginning 0) (match-end 0)
  2896. nil))
  2897. (goto-char (point-min))
  2898. (while (re-search-forward drawer-re nil t)
  2899. (delete-region
  2900. (match-beginning 0)
  2901. (progn (re-search-forward
  2902. "^[ \t]*:END:.*\n?" nil 'move)
  2903. (point))))
  2904. (unless (member 'planning keep)
  2905. (goto-char (point-min))
  2906. (while (re-search-forward kwd-time-re nil t)
  2907. (replace-match "")))
  2908. (goto-char (point-min))
  2909. (when org-agenda-entry-text-exclude-regexps
  2910. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2911. (while (setq re (pop re-list))
  2912. (goto-char (point-min))
  2913. (while (re-search-forward re nil t)
  2914. (replace-match "")))))
  2915. (goto-char (point-max))
  2916. (skip-chars-backward " \t\n")
  2917. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2918. ;; find and remove min common indentation
  2919. (goto-char (point-min))
  2920. (untabify (point-min) (point-max))
  2921. (setq ind (org-get-indentation))
  2922. (while (not (eobp))
  2923. (unless (looking-at "[ \t]*$")
  2924. (setq ind (min ind (org-get-indentation))))
  2925. (beginning-of-line 2))
  2926. (goto-char (point-min))
  2927. (while (not (eobp))
  2928. (unless (looking-at "[ \t]*$")
  2929. (move-to-column ind)
  2930. (delete-region (point-at-bol) (point)))
  2931. (beginning-of-line 2))
  2932. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2933. (goto-char (point-min))
  2934. (when indent
  2935. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2936. (replace-match indent t t)))
  2937. (goto-char (point-min))
  2938. (while (looking-at "[ \t]*\n") (replace-match ""))
  2939. (goto-char (point-max))
  2940. (when (> (org-current-line)
  2941. n-lines)
  2942. (org-goto-line (1+ n-lines))
  2943. (backward-char 1))
  2944. (setq txt (buffer-substring (point-min) (point)))))))))
  2945. txt))
  2946. (defun org-agenda-collect-markers ()
  2947. "Collect the markers pointing to entries in the agenda buffer."
  2948. (let (m markers)
  2949. (save-excursion
  2950. (goto-char (point-min))
  2951. (while (not (eobp))
  2952. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2953. (org-get-at-bol 'org-marker)))
  2954. (push m markers))
  2955. (beginning-of-line 2)))
  2956. (nreverse markers)))
  2957. (defun org-create-marker-find-array (marker-list)
  2958. "Create a alist of files names with all marker positions in that file."
  2959. (let (f tbl m a p)
  2960. (while (setq m (pop marker-list))
  2961. (setq p (marker-position m)
  2962. f (buffer-file-name (or (buffer-base-buffer
  2963. (marker-buffer m))
  2964. (marker-buffer m))))
  2965. (if (setq a (assoc f tbl))
  2966. (push (marker-position m) (cdr a))
  2967. (push (list f p) tbl)))
  2968. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2969. tbl)))
  2970. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2971. (defun org-check-agenda-marker-table ()
  2972. "Check of the current entry is on the marker list."
  2973. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2974. a)
  2975. (and (setq a (assoc file org-agenda-marker-table))
  2976. (save-match-data
  2977. (save-excursion
  2978. (org-back-to-heading t)
  2979. (member (point) (cdr a)))))))
  2980. (defun org-check-for-org-mode ()
  2981. "Make sure current buffer is in org-mode. Error if not."
  2982. (or (derived-mode-p 'org-mode)
  2983. (error "Cannot execute org-mode agenda command on buffer in %s"
  2984. major-mode)))
  2985. ;;; Agenda prepare and finalize
  2986. (defvar org-agenda-multi nil) ; dynamically scoped
  2987. (defvar org-agenda-pre-window-conf nil)
  2988. (defvar org-agenda-columns-active nil)
  2989. (defvar org-agenda-name nil)
  2990. (defvar org-agenda-tag-filter nil)
  2991. (defvar org-agenda-category-filter nil)
  2992. (defvar org-agenda-top-category-filter nil)
  2993. (defvar org-agenda-tag-filter-while-redo nil)
  2994. (defvar org-agenda-tag-filter-preset nil
  2995. "A preset of the tags filter used for secondary agenda filtering.
  2996. This must be a list of strings, each string must be a single tag preceded
  2997. by \"+\" or \"-\".
  2998. This variable should not be set directly, but agenda custom commands can
  2999. bind it in the options section. The preset filter is a global property of
  3000. the entire agenda view. In a block agenda, it will not work reliably to
  3001. define a filter for one of the individual blocks. You need to set it in
  3002. the global options and expect it to be applied to the entire view.")
  3003. (defvar org-agenda-category-filter-preset nil
  3004. "A preset of the category filter used for secondary agenda filtering.
  3005. This must be a list of strings, each string must be a single category
  3006. preceded by \"+\" or \"-\".
  3007. This variable should not be set directly, but agenda custom commands can
  3008. bind it in the options section. The preset filter is a global property of
  3009. the entire agenda view. In a block agenda, it will not work reliably to
  3010. define a filter for one of the individual blocks. You need to set it in
  3011. the global options and expect it to be applied to the entire view.")
  3012. (defun org-agenda-use-sticky-p ()
  3013. "Return non-nil if an agenda buffer named
  3014. `org-agenda-buffer-name' exists and should be shown instead of
  3015. generating a new one."
  3016. (and
  3017. ;; turned off by user
  3018. org-agenda-sticky
  3019. ;; For multi-agenda buffer already exists
  3020. (not org-agenda-multi)
  3021. ;; buffer found
  3022. (get-buffer org-agenda-buffer-name)
  3023. ;; C-u parameter is same as last call
  3024. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3025. (and
  3026. (equal current-prefix-arg
  3027. org-agenda-last-prefix-arg)
  3028. ;; In case user turned stickiness on, while having existing
  3029. ;; Agenda buffer active, don't reuse that buffer, because it
  3030. ;; does not have org variables local
  3031. org-agenda-this-buffer-is-sticky))))
  3032. (defun org-agenda-prepare-window (abuf)
  3033. "Setup agenda buffer in the window."
  3034. (let* ((awin (get-buffer-window abuf))
  3035. wconf)
  3036. (cond
  3037. ((equal (current-buffer) abuf) nil)
  3038. (awin (select-window awin))
  3039. ((not (setq wconf (current-window-configuration))))
  3040. ((equal org-agenda-window-setup 'current-window)
  3041. (org-pop-to-buffer-same-window abuf))
  3042. ((equal org-agenda-window-setup 'other-window)
  3043. (org-switch-to-buffer-other-window abuf))
  3044. ((equal org-agenda-window-setup 'other-frame)
  3045. (switch-to-buffer-other-frame abuf))
  3046. ((equal org-agenda-window-setup 'reorganize-frame)
  3047. (delete-other-windows)
  3048. (org-switch-to-buffer-other-window abuf)))
  3049. ;; additional test in case agenda is invoked from within agenda
  3050. ;; buffer via elisp link
  3051. (unless (equal (current-buffer) abuf)
  3052. (org-pop-to-buffer-same-window abuf))
  3053. (setq org-agenda-pre-window-conf
  3054. (or org-agenda-pre-window-conf wconf))))
  3055. (defun org-agenda-prepare (&optional name)
  3056. (if (org-agenda-use-sticky-p)
  3057. (progn
  3058. ;; Popup existing buffer
  3059. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3060. (message "Sticky Agenda buffer, use `r' to refresh")
  3061. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3062. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3063. (setq org-todo-keywords-for-agenda nil)
  3064. (setq org-drawers-for-agenda nil)
  3065. (unless org-agenda-persistent-filter
  3066. (setq org-agenda-tag-filter nil
  3067. org-agenda-category-filter nil))
  3068. (put 'org-agenda-tag-filter :preset-filter
  3069. org-agenda-tag-filter-preset)
  3070. (put 'org-agenda-category-filter :preset-filter
  3071. org-agenda-category-filter-preset)
  3072. (if org-agenda-multi
  3073. (progn
  3074. (setq buffer-read-only nil)
  3075. (goto-char (point-max))
  3076. (unless (or (bobp) org-agenda-compact-blocks
  3077. (not org-agenda-block-separator))
  3078. (insert "\n"
  3079. (if (stringp org-agenda-block-separator)
  3080. org-agenda-block-separator
  3081. (make-string (window-width) org-agenda-block-separator))
  3082. "\n"))
  3083. (narrow-to-region (point) (point-max)))
  3084. (setq org-done-keywords-for-agenda nil)
  3085. ;; Setting any org variables that are in org-agenda-local-vars
  3086. ;; list need to be done after the prepare call
  3087. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3088. (setq buffer-read-only nil)
  3089. (org-agenda-reset-markers)
  3090. (let ((inhibit-read-only t)) (erase-buffer))
  3091. (org-agenda-mode)
  3092. (setq org-agenda-buffer (current-buffer))
  3093. (setq org-agenda-contributing-files nil)
  3094. (setq org-agenda-columns-active nil)
  3095. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3096. (setq org-todo-keywords-for-agenda
  3097. (org-uniquify org-todo-keywords-for-agenda))
  3098. (setq org-done-keywords-for-agenda
  3099. (org-uniquify org-done-keywords-for-agenda))
  3100. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3101. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3102. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3103. (and name (not org-agenda-name)
  3104. (org-set-local 'org-agenda-name name)))
  3105. (setq buffer-read-only nil)))
  3106. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3107. (defun org-agenda-finalize ()
  3108. "Finishing touch for the agenda buffer, called just before displaying it."
  3109. (unless org-agenda-multi
  3110. (save-excursion
  3111. (let ((inhibit-read-only t))
  3112. (goto-char (point-min))
  3113. (while (org-activate-bracket-links (point-max))
  3114. (add-text-properties (match-beginning 0) (match-end 0)
  3115. '(face org-link)))
  3116. (org-agenda-align-tags)
  3117. (unless org-agenda-with-colors
  3118. (remove-text-properties (point-min) (point-max) '(face nil))))
  3119. (if (and (boundp 'org-agenda-overriding-columns-format)
  3120. org-agenda-overriding-columns-format)
  3121. (org-set-local 'org-agenda-overriding-columns-format
  3122. org-agenda-overriding-columns-format))
  3123. (if (and (boundp 'org-agenda-view-columns-initially)
  3124. org-agenda-view-columns-initially)
  3125. (org-agenda-columns))
  3126. (when org-agenda-fontify-priorities
  3127. (org-agenda-fontify-priorities))
  3128. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3129. (org-agenda-dim-blocked-tasks))
  3130. (org-agenda-mark-clocking-task)
  3131. (when org-agenda-entry-text-mode
  3132. (org-agenda-entry-text-hide)
  3133. (org-agenda-entry-text-show))
  3134. (if (functionp 'org-habit-insert-consistency-graphs)
  3135. (org-habit-insert-consistency-graphs))
  3136. (let ((inhibit-read-only t))
  3137. (run-hooks 'org-agenda-finalize-hook))
  3138. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3139. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3140. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3141. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3142. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3143. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
  3144. (defun org-agenda-mark-clocking-task ()
  3145. "Mark the current clock entry in the agenda if it is present."
  3146. (mapc (lambda (o)
  3147. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3148. (delete-overlay o)))
  3149. (overlays-in (point-min) (point-max)))
  3150. (when (marker-buffer org-clock-hd-marker)
  3151. (save-excursion
  3152. (goto-char (point-min))
  3153. (let (s ov)
  3154. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3155. (goto-char s)
  3156. (when (equal (org-get-at-bol 'org-hd-marker)
  3157. org-clock-hd-marker)
  3158. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3159. (overlay-put ov 'type 'org-agenda-clocking)
  3160. (overlay-put ov 'face 'org-agenda-clocking)
  3161. (overlay-put ov 'help-echo
  3162. "The clock is running in this item")))))))
  3163. (defun org-agenda-fontify-priorities ()
  3164. "Make highest priority lines bold, and lowest italic."
  3165. (interactive)
  3166. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3167. (delete-overlay o)))
  3168. (overlays-in (point-min) (point-max)))
  3169. (save-excursion
  3170. (let ((inhibit-read-only t)
  3171. b e p ov h l)
  3172. (goto-char (point-min))
  3173. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3174. (setq h (or (get-char-property (point) 'org-highest-priority)
  3175. org-highest-priority)
  3176. l (or (get-char-property (point) 'org-lowest-priority)
  3177. org-lowest-priority)
  3178. p (string-to-char (match-string 1))
  3179. b (match-beginning 0)
  3180. e (if (eq org-agenda-fontify-priorities 'cookies)
  3181. (match-end 0)
  3182. (point-at-eol))
  3183. ov (make-overlay b e))
  3184. (overlay-put
  3185. ov 'face
  3186. (cond ((org-face-from-face-or-color
  3187. 'priority nil
  3188. (cdr (assoc p org-priority-faces))))
  3189. ((and (listp org-agenda-fontify-priorities)
  3190. (org-face-from-face-or-color
  3191. 'priority nil
  3192. (cdr (assoc p org-agenda-fontify-priorities)))))
  3193. ((equal p l) 'italic)
  3194. ((equal p h) 'bold)))
  3195. (overlay-put ov 'org-type 'org-priority)))))
  3196. (defun org-agenda-dim-blocked-tasks ()
  3197. "Dim currently blocked TODO's in the agenda display."
  3198. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3199. (delete-overlay o)))
  3200. (overlays-in (point-min) (point-max)))
  3201. (save-excursion
  3202. (let ((inhibit-read-only t)
  3203. (org-depend-tag-blocked nil)
  3204. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3205. org-blocked-by-checkboxes
  3206. invis1 b e p ov h l)
  3207. (goto-char (point-min))
  3208. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3209. (and pos (goto-char (1+ pos))))
  3210. (setq org-blocked-by-checkboxes nil invis1 invis)
  3211. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3212. (when (and marker
  3213. (with-current-buffer (marker-buffer marker)
  3214. (save-excursion (goto-char marker)
  3215. (org-entry-blocked-p))))
  3216. (if org-blocked-by-checkboxes (setq invis1 nil))
  3217. (setq b (if invis1
  3218. (max (point-min) (1- (point-at-bol)))
  3219. (point-at-bol))
  3220. e (point-at-eol)
  3221. ov (make-overlay b e))
  3222. (if invis1
  3223. (overlay-put ov 'invisible t)
  3224. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3225. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3226. (defvar org-agenda-skip-function nil
  3227. "Function to be called at each match during agenda construction.
  3228. If this function returns nil, the current match should not be skipped.
  3229. Otherwise, the function must return a position from where the search
  3230. should be continued.
  3231. This may also be a Lisp form, it will be evaluated.
  3232. Never set this variable using `setq' or so, because then it will apply
  3233. to all future agenda commands. If you do want a global skipping condition,
  3234. use the option `org-agenda-skip-function-global' instead.
  3235. The correct usage for `org-agenda-skip-function' is to bind it with
  3236. `let' to scope it dynamically into the agenda-constructing command.
  3237. A good way to set it is through options in `org-agenda-custom-commands'.")
  3238. (defun org-agenda-skip ()
  3239. "Throw to `:skip' in places that should be skipped.
  3240. Also moves point to the end of the skipped region, so that search can
  3241. continue from there."
  3242. (let ((p (point-at-bol)) to)
  3243. (when (org-in-src-block-p) (throw :skip t))
  3244. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3245. (get-text-property p :org-archived)
  3246. (org-end-of-subtree t)
  3247. (throw :skip t))
  3248. (and org-agenda-skip-comment-trees
  3249. (get-text-property p :org-comment)
  3250. (org-end-of-subtree t)
  3251. (throw :skip t))
  3252. (if (equal (char-after p) ?#) (throw :skip t))
  3253. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3254. (org-agenda-skip-eval org-agenda-skip-function)))
  3255. (goto-char to)
  3256. (throw :skip t))))
  3257. (defun org-agenda-skip-eval (form)
  3258. "If FORM is a function or a list, call (or eval) is and return result.
  3259. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3260. and match data are returned to the previous state no matter what these
  3261. functions do."
  3262. (let (fp)
  3263. (and form
  3264. (or (setq fp (functionp form))
  3265. (consp form))
  3266. (save-excursion
  3267. (save-match-data
  3268. (if fp
  3269. (funcall form)
  3270. (eval form)))))))
  3271. (defvar org-agenda-markers nil
  3272. "List of all currently active markers created by `org-agenda'.")
  3273. (defvar org-agenda-last-marker-time (org-float-time)
  3274. "Creation time of the last agenda marker.")
  3275. (defun org-agenda-new-marker (&optional pos)
  3276. "Return a new agenda marker.
  3277. Org-mode keeps a list of these markers and resets them when they are
  3278. no longer in use."
  3279. (let ((m (copy-marker (or pos (point)))))
  3280. (setq org-agenda-last-marker-time (org-float-time))
  3281. (if org-agenda-buffer
  3282. (with-current-buffer org-agenda-buffer
  3283. (push m org-agenda-markers))
  3284. (push m org-agenda-markers))
  3285. m))
  3286. (defun org-agenda-reset-markers ()
  3287. "Reset markers created by `org-agenda'."
  3288. (while org-agenda-markers
  3289. (move-marker (pop org-agenda-markers) nil)))
  3290. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3291. "Save relative positions of markers in region.
  3292. This check for agenda markers in all agenda buffers currently active."
  3293. (dolist (buf (buffer-list))
  3294. (with-current-buffer buf
  3295. (when (eq major-mode 'org-agenda-mode)
  3296. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3297. org-agenda-markers)))))
  3298. ;;; Entry text mode
  3299. (defun org-agenda-entry-text-show-here ()
  3300. "Add some text from the entry as context to the current line."
  3301. (let (m txt o)
  3302. (setq m (org-get-at-bol 'org-hd-marker))
  3303. (unless (marker-buffer m)
  3304. (error "No marker points to an entry here"))
  3305. (setq txt (concat "\n" (org-no-properties
  3306. (org-agenda-get-some-entry-text
  3307. m org-agenda-entry-text-maxlines " > "))))
  3308. (when (string-match "\\S-" txt)
  3309. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3310. (overlay-put o 'evaporate t)
  3311. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3312. (overlay-put o 'after-string txt))))
  3313. (defun org-agenda-entry-text-show ()
  3314. "Add entry context for all agenda lines."
  3315. (interactive)
  3316. (save-excursion
  3317. (goto-char (point-max))
  3318. (beginning-of-line 1)
  3319. (while (not (bobp))
  3320. (when (org-get-at-bol 'org-hd-marker)
  3321. (org-agenda-entry-text-show-here))
  3322. (beginning-of-line 0))))
  3323. (defun org-agenda-entry-text-hide ()
  3324. "Remove any shown entry context."
  3325. (delq nil
  3326. (mapcar (lambda (o)
  3327. (if (eq (overlay-get o 'org-overlay-type)
  3328. 'agenda-entry-content)
  3329. (progn (delete-overlay o) t)))
  3330. (overlays-in (point-min) (point-max)))))
  3331. (defun org-agenda-get-day-face (date)
  3332. "Return the face DATE should be displayed with."
  3333. (or (and (functionp org-agenda-day-face-function)
  3334. (funcall org-agenda-day-face-function date))
  3335. (cond ((org-agenda-todayp date)
  3336. 'org-agenda-date-today)
  3337. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3338. 'org-agenda-date-weekend)
  3339. (t 'org-agenda-date))))
  3340. ;;; Agenda timeline
  3341. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3342. (defun org-timeline (&optional dotodo)
  3343. "Show a time-sorted view of the entries in the current org file.
  3344. Only entries with a time stamp of today or later will be listed. With
  3345. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3346. under the current date.
  3347. If the buffer contains an active region, only check the region for
  3348. dates."
  3349. (interactive "P")
  3350. (let* ((dopast t)
  3351. (org-agenda-show-log-scoped org-agenda-show-log)
  3352. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3353. (current-buffer))))
  3354. (date (calendar-current-date))
  3355. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3356. (end (if (org-region-active-p) (region-end) (point-max)))
  3357. (day-numbers (org-get-all-dates
  3358. beg end 'no-ranges
  3359. t org-agenda-show-log-scoped ; always include today
  3360. org-timeline-show-empty-dates))
  3361. (org-deadline-warning-days 0)
  3362. (org-agenda-only-exact-dates t)
  3363. (today (org-today))
  3364. (past t)
  3365. args
  3366. s e rtn d emptyp)
  3367. (setq org-agenda-redo-command
  3368. (list 'progn
  3369. (list 'org-switch-to-buffer-other-window (current-buffer))
  3370. (list 'org-timeline (list 'quote dotodo))))
  3371. (if (not dopast)
  3372. ;; Remove past dates from the list of dates.
  3373. (setq day-numbers (delq nil (mapcar (lambda(x)
  3374. (if (>= x today) x nil))
  3375. day-numbers))))
  3376. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3377. (org-compile-prefix-format 'timeline)
  3378. (org-set-sorting-strategy 'timeline)
  3379. (if org-agenda-show-log-scoped (push :closed args))
  3380. (push :timestamp args)
  3381. (push :deadline args)
  3382. (push :scheduled args)
  3383. (push :sexp args)
  3384. (if dotodo (push :todo args))
  3385. (insert "Timeline of file " entry "\n")
  3386. (add-text-properties (point-min) (point)
  3387. (list 'face 'org-agenda-structure))
  3388. (org-agenda-mark-header-line (point-min))
  3389. (while (setq d (pop day-numbers))
  3390. (if (and (listp d) (eq (car d) :omitted))
  3391. (progn
  3392. (setq s (point))
  3393. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3394. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3395. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3396. (if (and (>= d today)
  3397. dopast
  3398. past)
  3399. (progn
  3400. (setq past nil)
  3401. (insert (make-string 79 ?-) "\n")))
  3402. (setq date (calendar-gregorian-from-absolute d))
  3403. (setq s (point))
  3404. (setq rtn (and (not emptyp)
  3405. (apply 'org-agenda-get-day-entries entry
  3406. date args)))
  3407. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3408. (progn
  3409. (insert
  3410. (if (stringp org-agenda-format-date)
  3411. (format-time-string org-agenda-format-date
  3412. (org-time-from-absolute date))
  3413. (funcall org-agenda-format-date date))
  3414. "\n")
  3415. (put-text-property s (1- (point)) 'face
  3416. (org-agenda-get-day-face date))
  3417. (put-text-property s (1- (point)) 'org-date-line t)
  3418. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3419. (if (equal d today)
  3420. (put-text-property s (1- (point)) 'org-today t))
  3421. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3422. (put-text-property s (1- (point)) 'day d)))))
  3423. (goto-char (point-min))
  3424. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3425. (point-min)))
  3426. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3427. (org-agenda-finalize)
  3428. (setq buffer-read-only t)))
  3429. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3430. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3431. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3432. not every single day in the range. If FORCE-TODAY is non-nil, make
  3433. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3434. inactive time stamps (those in square brackets) are included.
  3435. When EMPTY is non-nil, also include days without any entries."
  3436. (let ((re (concat
  3437. (if pre-re pre-re "")
  3438. (if inactive org-ts-regexp-both org-ts-regexp)))
  3439. dates dates1 date day day1 day2 ts1 ts2 pos)
  3440. (if force-today
  3441. (setq dates (list (org-today))))
  3442. (save-excursion
  3443. (goto-char beg)
  3444. (while (re-search-forward re end t)
  3445. (setq day (time-to-days (org-time-string-to-time
  3446. (substring (match-string 1) 0 10)
  3447. (current-buffer) (match-beginning 0))))
  3448. (or (memq day dates) (push day dates)))
  3449. (unless no-ranges
  3450. (goto-char beg)
  3451. (while (re-search-forward org-tr-regexp end t)
  3452. (setq pos (match-beginning 0))
  3453. (setq ts1 (substring (match-string 1) 0 10)
  3454. ts2 (substring (match-string 2) 0 10)
  3455. day1 (time-to-days (org-time-string-to-time
  3456. ts1 (current-buffer) pos))
  3457. day2 (time-to-days (org-time-string-to-time
  3458. ts2 (current-buffer) pos)))
  3459. (while (< (setq day1 (1+ day1)) day2)
  3460. (or (memq day1 dates) (push day1 dates)))))
  3461. (setq dates (sort dates '<))
  3462. (when empty
  3463. (while (setq day (pop dates))
  3464. (setq day2 (car dates))
  3465. (push day dates1)
  3466. (when (and day2 empty)
  3467. (if (or (eq empty t)
  3468. (and (numberp empty) (<= (- day2 day) empty)))
  3469. (while (< (setq day (1+ day)) day2)
  3470. (push (list day) dates1))
  3471. (push (cons :omitted (- day2 day)) dates1))))
  3472. (setq dates (nreverse dates1)))
  3473. dates)))
  3474. ;;; Agenda Daily/Weekly
  3475. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3476. "Start day for the agenda view.
  3477. Custom commands can set this variable in the options section.")
  3478. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3479. (defvar org-arg-loc nil) ; local variable
  3480. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3481. "List of types searched for when creating the daily/weekly agenda.
  3482. This variable is a list of symbols that controls the types of
  3483. items that appear in the daily/weekly agenda. Allowed symbols in this
  3484. list are are
  3485. :timestamp List items containing a date stamp or date range matching
  3486. the selected date. This includes sexp entries in
  3487. angular brackets.
  3488. :sexp List entries resulting from plain diary-like sexps.
  3489. :deadline List deadline due on that date. When the date is today,
  3490. also list any deadlines past due, or due within
  3491. `org-deadline-warning-days'. `:deadline' must appear before
  3492. `:scheduled' if the setting of
  3493. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3494. any effect.
  3495. :scheduled List all items which are scheduled for the given date.
  3496. The diary for *today* also contains items which were
  3497. scheduled earlier and are not yet marked DONE.
  3498. By default, all four types are turned on.
  3499. Never set this variable globally using `setq', because then it
  3500. will apply to all future agenda commands. Instead, bind it with
  3501. `let' to scope it dynamically into the agenda-constructing
  3502. command. A good way to set it is through options in
  3503. `org-agenda-custom-commands'. For a more flexible (though
  3504. somewhat less efficient) way of determining what is included in
  3505. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3506. (defvar org-agenda-buffer-tmp-name nil)
  3507. ;;;###autoload
  3508. (defun org-agenda-list (&optional arg start-day span)
  3509. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3510. The view will be for the current day or week, but from the overview buffer
  3511. you will be able to go to other days/weeks.
  3512. With a numeric prefix argument in an interactive call, the agenda will
  3513. span ARG days. Lisp programs should instead specify SPAN to change
  3514. the number of days. SPAN defaults to `org-agenda-span'.
  3515. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3516. given in `org-agenda-start-on-weekday'."
  3517. (interactive "P")
  3518. (if org-agenda-overriding-arguments
  3519. (setq arg (car org-agenda-overriding-arguments)
  3520. start-day (nth 1 org-agenda-overriding-arguments)
  3521. span (nth 2 org-agenda-overriding-arguments)))
  3522. (if (and (integerp arg) (> arg 0))
  3523. (setq span arg arg nil))
  3524. (catch 'exit
  3525. (setq org-agenda-buffer-name
  3526. (or org-agenda-buffer-tmp-name
  3527. (if org-agenda-sticky
  3528. (cond ((and org-keys (stringp org-match))
  3529. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3530. (org-keys
  3531. (format "*Org Agenda(%s)*" org-keys))
  3532. (t "*Org Agenda(a)*")))
  3533. org-agenda-buffer-name))
  3534. (org-agenda-prepare "Day/Week")
  3535. (setq start-day (or start-day org-agenda-start-day))
  3536. (if (stringp start-day)
  3537. ;; Convert to an absolute day number
  3538. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3539. (org-compile-prefix-format 'agenda)
  3540. (org-set-sorting-strategy 'agenda)
  3541. (let* ((span (org-agenda-ndays-to-span
  3542. (or span org-agenda-ndays org-agenda-span)))
  3543. (today (org-today))
  3544. (sd (or start-day today))
  3545. (ndays (org-agenda-span-to-ndays span sd))
  3546. (org-agenda-start-on-weekday
  3547. (if (eq ndays 7)
  3548. org-agenda-start-on-weekday))
  3549. (thefiles (org-agenda-files nil 'ifmode))
  3550. (files thefiles)
  3551. (start (if (or (null org-agenda-start-on-weekday)
  3552. (< ndays 7))
  3553. sd
  3554. (let* ((nt (calendar-day-of-week
  3555. (calendar-gregorian-from-absolute sd)))
  3556. (n1 org-agenda-start-on-weekday)
  3557. (d (- nt n1)))
  3558. (- sd (+ (if (< d 0) 7 0) d)))))
  3559. (day-numbers (list start))
  3560. (day-cnt 0)
  3561. (inhibit-redisplay (not debug-on-error))
  3562. (org-agenda-show-log-scoped org-agenda-show-log)
  3563. s e rtn rtnall file date d start-pos end-pos todayp
  3564. clocktable-start clocktable-end filter)
  3565. (setq org-agenda-redo-command
  3566. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3567. (dotimes (n (1- ndays))
  3568. (push (1+ (car day-numbers)) day-numbers))
  3569. (setq day-numbers (nreverse day-numbers))
  3570. (setq clocktable-start (car day-numbers)
  3571. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3572. (org-set-local 'org-starting-day (car day-numbers))
  3573. (org-set-local 'org-arg-loc arg)
  3574. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3575. (unless org-agenda-compact-blocks
  3576. (let* ((d1 (car day-numbers))
  3577. (d2 (org-last day-numbers))
  3578. (w1 (org-days-to-iso-week d1))
  3579. (w2 (org-days-to-iso-week d2)))
  3580. (setq s (point))
  3581. (if org-agenda-overriding-header
  3582. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3583. nil 'face 'org-agenda-structure) "\n")
  3584. (insert (org-agenda-span-name span)
  3585. "-agenda"
  3586. (if (< (- d2 d1) 350)
  3587. (if (= w1 w2)
  3588. (format " (W%02d)" w1)
  3589. (format " (W%02d-W%02d)" w1 w2))
  3590. "")
  3591. ":\n")))
  3592. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3593. 'org-date-line t))
  3594. (org-agenda-mark-header-line s))
  3595. (while (setq d (pop day-numbers))
  3596. (setq date (calendar-gregorian-from-absolute d)
  3597. s (point))
  3598. (if (or (setq todayp (= d today))
  3599. (and (not start-pos) (= d sd)))
  3600. (setq start-pos (point))
  3601. (if (and start-pos (not end-pos))
  3602. (setq end-pos (point))))
  3603. (setq files thefiles
  3604. rtnall nil)
  3605. (while (setq file (pop files))
  3606. (catch 'nextfile
  3607. (org-check-agenda-file file)
  3608. (let ((org-agenda-entry-types org-agenda-entry-types))
  3609. (unless org-agenda-include-deadlines
  3610. (setq org-agenda-entry-types
  3611. (delq :deadline org-agenda-entry-types)))
  3612. (cond
  3613. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3614. (setq rtn (org-agenda-get-day-entries
  3615. file date :closed)))
  3616. (org-agenda-show-log-scoped
  3617. (setq rtn (apply 'org-agenda-get-day-entries
  3618. file date
  3619. (append '(:closed) org-agenda-entry-types))))
  3620. (t
  3621. (setq rtn (apply 'org-agenda-get-day-entries
  3622. file date
  3623. org-agenda-entry-types)))))
  3624. (setq rtnall (append rtnall rtn)))) ;; all entries
  3625. (if org-agenda-include-diary
  3626. (let ((org-agenda-search-headline-for-time t))
  3627. (require 'diary-lib)
  3628. (setq rtn (org-get-entries-from-diary date))
  3629. (setq rtnall (append rtnall rtn))))
  3630. (if (or rtnall org-agenda-show-all-dates)
  3631. (progn
  3632. (setq day-cnt (1+ day-cnt))
  3633. (insert
  3634. (if (stringp org-agenda-format-date)
  3635. (format-time-string org-agenda-format-date
  3636. (org-time-from-absolute date))
  3637. (funcall org-agenda-format-date date))
  3638. "\n")
  3639. (put-text-property s (1- (point)) 'face
  3640. (org-agenda-get-day-face date))
  3641. (put-text-property s (1- (point)) 'org-date-line t)
  3642. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3643. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3644. (when todayp
  3645. (put-text-property s (1- (point)) 'org-today t))
  3646. (setq rtnall
  3647. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3648. (if rtnall (insert ;; all entries
  3649. (org-agenda-finalize-entries rtnall)
  3650. "\n"))
  3651. (put-text-property s (1- (point)) 'day d)
  3652. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3653. (when (and org-agenda-clockreport-mode clocktable-start)
  3654. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3655. ;; the above line is to ensure the restricted range!
  3656. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3657. tbl)
  3658. (setq p (org-plist-delete p :block))
  3659. (setq p (plist-put p :tstart clocktable-start))
  3660. (setq p (plist-put p :tend clocktable-end))
  3661. (setq p (plist-put p :scope 'agenda))
  3662. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3663. (setq filter (or org-agenda-tag-filter-while-redo
  3664. (get 'org-agenda-tag-filter :preset-filter))))
  3665. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3666. (if (string-match "[<>=]" x)
  3667. ""
  3668. x))
  3669. filter ""))))
  3670. (setq tbl (apply 'org-get-clocktable p))
  3671. (insert tbl)))
  3672. (goto-char (point-min))
  3673. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3674. (unless (and (pos-visible-in-window-p (point-min))
  3675. (pos-visible-in-window-p (point-max)))
  3676. (goto-char (1- (point-max)))
  3677. (recenter -1)
  3678. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3679. (progn
  3680. (goto-char (or start-pos 1))
  3681. (recenter 1))))
  3682. (goto-char (or start-pos 1))
  3683. (add-text-properties (point-min) (point-max)
  3684. `(org-agenda-type agenda
  3685. org-last-args (,arg ,start-day ,span)
  3686. org-redo-cmd ,org-agenda-redo-command
  3687. org-serie-cmd ,org-cmd))
  3688. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3689. (org-agenda-show-clocking-issues))
  3690. (org-agenda-finalize)
  3691. (setq buffer-read-only t)
  3692. (message ""))))
  3693. (defun org-agenda-ndays-to-span (n)
  3694. "Return a span symbol for a span of N days, or N if none matches."
  3695. (cond ((symbolp n) n)
  3696. ((= n 1) 'day)
  3697. ((= n 7) 'week)
  3698. (t n)))
  3699. (defun org-agenda-span-to-ndays (span &optional start-day)
  3700. "Return ndays from SPAN, possibly starting at START-DAY."
  3701. (cond ((numberp span) span)
  3702. ((eq span 'day) 1)
  3703. ((eq span 'week) 7)
  3704. ((eq span 'month)
  3705. (let ((date (calendar-gregorian-from-absolute start-day)))
  3706. (calendar-last-day-of-month (car date) (caddr date))))
  3707. ((eq span 'year)
  3708. (let ((date (calendar-gregorian-from-absolute start-day)))
  3709. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3710. (defun org-agenda-span-name (span)
  3711. "Return a SPAN name."
  3712. (if (null span)
  3713. ""
  3714. (if (symbolp span)
  3715. (capitalize (symbol-name span))
  3716. (format "%d days" span))))
  3717. ;;; Agenda word search
  3718. (defvar org-agenda-search-history nil)
  3719. (defvar org-search-syntax-table nil
  3720. "Special syntax table for org-mode search.
  3721. In this table, we have single quotes not as word constituents, to
  3722. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3723. (defvar org-mode-syntax-table) ; From org.el
  3724. (defun org-search-syntax-table ()
  3725. (unless org-search-syntax-table
  3726. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3727. (modify-syntax-entry ?' "." org-search-syntax-table)
  3728. (modify-syntax-entry ?` "." org-search-syntax-table))
  3729. org-search-syntax-table)
  3730. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3731. ;;;###autoload
  3732. (defun org-search-view (&optional todo-only string edit-at)
  3733. "Show all entries that contain a phrase or words or regular expressions.
  3734. With optional prefix argument TODO-ONLY, only consider entries that are
  3735. TODO entries. The argument STRING can be used to pass a default search
  3736. string into this function. If EDIT-AT is non-nil, it means that the
  3737. user should get a chance to edit this string, with cursor at position
  3738. EDIT-AT.
  3739. The search string can be viewed either as a phrase that should be found as
  3740. is, or it can be broken into a number of snippets, each of which must match
  3741. in a Boolean way to select an entry. The default depends on the variable
  3742. `org-agenda-search-view-always-boolean'.
  3743. Even if this is turned off (the default) you can always switch to
  3744. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3745. The default is a direct search of the whole phrase, where each space in
  3746. the search string can expand to an arbitrary amount of whitespace,
  3747. including newlines.
  3748. If using a Boolean search, the search string is split on whitespace and
  3749. each snippet is searched separately, with logical AND to select an entry.
  3750. Words prefixed with a minus must *not* occur in the entry. Words without
  3751. a prefix or prefixed with a plus must occur in the entry. Matching is
  3752. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3753. match whole words, not parts of a word) if
  3754. `org-agenda-search-view-force-full-words' is set (default is nil).
  3755. Boolean search snippets enclosed by curly braces are interpreted as
  3756. regular expressions that must or (when preceded with \"-\") must not
  3757. match in the entry. Snippets enclosed into double quotes will be taken
  3758. as a whole, to include whitespace.
  3759. - If the search string starts with an asterisk, search only in headlines.
  3760. - If (possibly after the leading star) the search string starts with an
  3761. exclamation mark, this also means to look at TODO entries only, an effect
  3762. that can also be achieved with a prefix argument.
  3763. - If (possibly after star and exclamation mark) the search string starts
  3764. with a colon, this will mean that the (non-regexp) snippets of the
  3765. Boolean search must match as full words.
  3766. This command searches the agenda files, and in addition the files listed
  3767. in `org-agenda-text-search-extra-files'."
  3768. (interactive "P")
  3769. (if org-agenda-overriding-arguments
  3770. (setq todo-only (car org-agenda-overriding-arguments)
  3771. string (nth 1 org-agenda-overriding-arguments)
  3772. edit-at (nth 2 org-agenda-overriding-arguments)))
  3773. (let* ((props (list 'face nil
  3774. 'done-face 'org-agenda-done
  3775. 'org-not-done-regexp org-not-done-regexp
  3776. 'org-todo-regexp org-todo-regexp
  3777. 'org-complex-heading-regexp org-complex-heading-regexp
  3778. 'mouse-face 'highlight
  3779. 'help-echo (format "mouse-2 or RET jump to location")))
  3780. (full-words org-agenda-search-view-force-full-words)
  3781. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3782. regexp rtn rtnall files file pos
  3783. marker category category-pos tags c neg re boolean
  3784. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3785. (unless (and (not edit-at)
  3786. (stringp string)
  3787. (string-match "\\S-" string))
  3788. (setq string (read-string
  3789. (if org-agenda-search-view-always-boolean
  3790. "[+-]Word/{Regexp} ...: "
  3791. "Phrase or [+-]Word/{Regexp} ...: ")
  3792. (cond
  3793. ((integerp edit-at) (cons string edit-at))
  3794. (edit-at string))
  3795. 'org-agenda-search-history)))
  3796. (catch 'exit
  3797. (if org-agenda-sticky
  3798. (setq org-agenda-buffer-name
  3799. (if (stringp string)
  3800. (format "*Org Agenda(%s:%s)*"
  3801. (or org-keys (or (and todo-only "S") "s")) string)
  3802. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3803. (org-agenda-prepare "SEARCH")
  3804. (org-compile-prefix-format 'search)
  3805. (org-set-sorting-strategy 'search)
  3806. (setq org-agenda-redo-command
  3807. (list 'org-search-view (if todo-only t nil)
  3808. (list 'if 'current-prefix-arg nil string)))
  3809. (setq org-agenda-query-string string)
  3810. (if (equal (string-to-char string) ?*)
  3811. (setq hdl-only t
  3812. words (substring string 1))
  3813. (setq words string))
  3814. (when (equal (string-to-char words) ?!)
  3815. (setq todo-only t
  3816. words (substring words 1)))
  3817. (when (equal (string-to-char words) ?:)
  3818. (setq full-words t
  3819. words (substring words 1)))
  3820. (if (or org-agenda-search-view-always-boolean
  3821. (member (string-to-char words) '(?- ?+ ?\{)))
  3822. (setq boolean t))
  3823. (setq words (org-split-string words))
  3824. (let (www w)
  3825. (while (setq w (pop words))
  3826. (while (and (string-match "\\\\\\'" w) words)
  3827. (setq w (concat (substring w 0 -1) " " (pop words))))
  3828. (push w www))
  3829. (setq words (nreverse www) www nil)
  3830. (while (setq w (pop words))
  3831. (when (and (string-match "\\`[-+]?{" w)
  3832. (not (string-match "}\\'" w)))
  3833. (while (and words (not (string-match "}\\'" (car words))))
  3834. (setq w (concat w " " (pop words))))
  3835. (setq w (concat w " " (pop words))))
  3836. (push w www))
  3837. (setq words (nreverse www)))
  3838. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3839. (when boolean
  3840. (let (wds w)
  3841. (while (setq w (pop words))
  3842. (if (or (equal (substring w 0 1) "\"")
  3843. (and (> (length w) 1)
  3844. (member (substring w 0 1) '("+" "-"))
  3845. (equal (substring w 1 2) "\"")))
  3846. (while (and words (not (equal (substring w -1) "\"")))
  3847. (setq w (concat w " " (pop words)))))
  3848. (and (string-match "\\`\\([-+]?\\)\"" w)
  3849. (setq w (replace-match "\\1" nil nil w)))
  3850. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3851. (push w wds))
  3852. (setq words (nreverse wds))))
  3853. (if boolean
  3854. (mapc (lambda (w)
  3855. (setq c (string-to-char w))
  3856. (if (equal c ?-)
  3857. (setq neg t w (substring w 1))
  3858. (if (equal c ?+)
  3859. (setq neg nil w (substring w 1))
  3860. (setq neg nil)))
  3861. (if (string-match "\\`{.*}\\'" w)
  3862. (setq re (substring w 1 -1))
  3863. (if full-words
  3864. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3865. (setq re (regexp-quote (downcase w)))))
  3866. (if neg (push re regexps-) (push re regexps+)))
  3867. words)
  3868. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3869. regexps+))
  3870. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3871. (if (not regexps+)
  3872. (setq regexp org-outline-regexp-bol)
  3873. (setq regexp (pop regexps+))
  3874. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3875. regexp))))
  3876. (setq files (org-agenda-files nil 'ifmode))
  3877. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3878. (pop org-agenda-text-search-extra-files)
  3879. (setq files (org-add-archive-files files)))
  3880. (setq files (append files org-agenda-text-search-extra-files)
  3881. rtnall nil)
  3882. (while (setq file (pop files))
  3883. (setq ee nil)
  3884. (catch 'nextfile
  3885. (org-check-agenda-file file)
  3886. (setq buffer (if (file-exists-p file)
  3887. (org-get-agenda-file-buffer file)
  3888. (error "No such file %s" file)))
  3889. (if (not buffer)
  3890. ;; If file does not exist, make sure an error message is sent
  3891. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3892. file))))
  3893. (with-current-buffer buffer
  3894. (with-syntax-table (org-search-syntax-table)
  3895. (unless (derived-mode-p 'org-mode)
  3896. (error "Agenda file %s is not in `org-mode'" file))
  3897. (let ((case-fold-search t))
  3898. (save-excursion
  3899. (save-restriction
  3900. (if org-agenda-restrict
  3901. (narrow-to-region org-agenda-restrict-begin
  3902. org-agenda-restrict-end)
  3903. (widen))
  3904. (goto-char (point-min))
  3905. (unless (or (org-at-heading-p)
  3906. (outline-next-heading))
  3907. (throw 'nextfile t))
  3908. (goto-char (max (point-min) (1- (point))))
  3909. (while (re-search-forward regexp nil t)
  3910. (org-back-to-heading t)
  3911. (skip-chars-forward "* ")
  3912. (setq beg (point-at-bol)
  3913. beg1 (point)
  3914. end (progn (outline-next-heading) (point)))
  3915. (catch :skip
  3916. (goto-char beg)
  3917. (org-agenda-skip)
  3918. (setq str (buffer-substring-no-properties
  3919. (point-at-bol)
  3920. (if hdl-only (point-at-eol) end)))
  3921. (mapc (lambda (wr) (when (string-match wr str)
  3922. (goto-char (1- end))
  3923. (throw :skip t)))
  3924. regexps-)
  3925. (mapc (lambda (wr) (unless (string-match wr str)
  3926. (goto-char (1- end))
  3927. (throw :skip t)))
  3928. (if todo-only
  3929. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3930. regexps+)
  3931. regexps+))
  3932. (goto-char beg)
  3933. (setq marker (org-agenda-new-marker (point))
  3934. category (org-get-category)
  3935. category-pos (get-text-property (point) 'org-category-position)
  3936. tags (org-get-tags-at (point))
  3937. txt (org-agenda-format-item
  3938. ""
  3939. (buffer-substring-no-properties
  3940. beg1 (point-at-eol))
  3941. category tags t))
  3942. (org-add-props txt props
  3943. 'org-marker marker 'org-hd-marker marker
  3944. 'org-todo-regexp org-todo-regexp
  3945. 'org-complex-heading-regexp org-complex-heading-regexp
  3946. 'priority 1000 'org-category category
  3947. 'org-category-position category-pos
  3948. 'type "search")
  3949. (push txt ee)
  3950. (goto-char (1- end))))))))))
  3951. (setq rtn (nreverse ee))
  3952. (setq rtnall (append rtnall rtn)))
  3953. (if org-agenda-overriding-header
  3954. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3955. nil 'face 'org-agenda-structure) "\n")
  3956. (insert "Search words: ")
  3957. (add-text-properties (point-min) (1- (point))
  3958. (list 'face 'org-agenda-structure))
  3959. (setq pos (point))
  3960. (insert string "\n")
  3961. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3962. (setq pos (point))
  3963. (unless org-agenda-multi
  3964. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3965. (add-text-properties pos (1- (point))
  3966. (list 'face 'org-agenda-structure))))
  3967. (org-agenda-mark-header-line (point-min))
  3968. (when rtnall
  3969. (insert (org-agenda-finalize-entries rtnall) "\n"))
  3970. (goto-char (point-min))
  3971. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3972. (add-text-properties (point-min) (point-max)
  3973. `(org-agenda-type search
  3974. org-last-args (,todo-only ,string ,edit-at)
  3975. org-redo-cmd ,org-agenda-redo-command
  3976. org-serie-cmd ,org-cmd))
  3977. (org-agenda-finalize)
  3978. (setq buffer-read-only t))))
  3979. ;;; Agenda TODO list
  3980. (defvar org-select-this-todo-keyword nil)
  3981. (defvar org-last-arg nil)
  3982. ;;;###autoload
  3983. (defun org-todo-list (&optional arg)
  3984. "Show all (not done) TODO entries from all agenda file in a single list.
  3985. The prefix arg can be used to select a specific TODO keyword and limit
  3986. the list to these. When using \\[universal-argument], you will be prompted
  3987. for a keyword. A numeric prefix directly selects the Nth keyword in
  3988. `org-todo-keywords-1'."
  3989. (interactive "P")
  3990. (if org-agenda-overriding-arguments
  3991. (setq arg org-agenda-overriding-arguments))
  3992. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3993. (let* ((today (org-today))
  3994. (date (calendar-gregorian-from-absolute today))
  3995. (kwds org-todo-keywords-for-agenda)
  3996. (completion-ignore-case t)
  3997. (org-select-this-todo-keyword
  3998. (if (stringp arg) arg
  3999. (and arg (integerp arg) (> arg 0)
  4000. (nth (1- arg) kwds))))
  4001. rtn rtnall files file pos)
  4002. (when (equal arg '(4))
  4003. (setq org-select-this-todo-keyword
  4004. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4005. (mapcar 'list kwds) nil nil)))
  4006. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4007. (catch 'exit
  4008. (if org-agenda-sticky
  4009. (setq org-agenda-buffer-name
  4010. (if (stringp org-select-this-todo-keyword)
  4011. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4012. org-select-this-todo-keyword)
  4013. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4014. (org-agenda-prepare "TODO")
  4015. (org-compile-prefix-format 'todo)
  4016. (org-set-sorting-strategy 'todo)
  4017. (setq org-agenda-redo-command
  4018. `(org-todo-list (or current-prefix-arg (quote ,arg))))
  4019. (setq files (org-agenda-files nil 'ifmode)
  4020. rtnall nil)
  4021. (while (setq file (pop files))
  4022. (catch 'nextfile
  4023. (org-check-agenda-file file)
  4024. (setq rtn (org-agenda-get-day-entries file date :todo))
  4025. (setq rtnall (append rtnall rtn))))
  4026. (if org-agenda-overriding-header
  4027. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4028. nil 'face 'org-agenda-structure) "\n")
  4029. (insert "Global list of TODO items of type: ")
  4030. (add-text-properties (point-min) (1- (point))
  4031. (list 'face 'org-agenda-structure
  4032. 'short-heading
  4033. (concat "ToDo: "
  4034. (or org-select-this-todo-keyword "ALL"))))
  4035. (org-agenda-mark-header-line (point-min))
  4036. (setq pos (point))
  4037. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4038. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4039. (setq pos (point))
  4040. (unless org-agenda-multi
  4041. (insert "Available with `N r': (0)[ALL]")
  4042. (let ((n 0) s)
  4043. (mapc (lambda (x)
  4044. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4045. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4046. (insert "\n "))
  4047. (insert " " s))
  4048. kwds))
  4049. (insert "\n"))
  4050. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4051. (org-agenda-mark-header-line (point-min))
  4052. (when rtnall
  4053. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4054. (goto-char (point-min))
  4055. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4056. (add-text-properties (point-min) (point-max)
  4057. `(org-agenda-type todo
  4058. org-last-args ,arg
  4059. org-redo-cmd ,org-agenda-redo-command
  4060. org-serie-cmd ,org-cmd))
  4061. (org-agenda-finalize)
  4062. (setq buffer-read-only t))))
  4063. ;;; Agenda tags match
  4064. ;;;###autoload
  4065. (defun org-tags-view (&optional todo-only match)
  4066. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4067. The prefix arg TODO-ONLY limits the search to TODO entries."
  4068. (interactive "P")
  4069. (if org-agenda-overriding-arguments
  4070. (setq todo-only (car org-agenda-overriding-arguments)
  4071. match (nth 1 org-agenda-overriding-arguments)))
  4072. (let* ((org-tags-match-list-sublevels
  4073. org-tags-match-list-sublevels)
  4074. (completion-ignore-case t)
  4075. rtn rtnall files file pos matcher
  4076. buffer)
  4077. (when (and (stringp match) (not (string-match "\\S-" match)))
  4078. (setq match nil))
  4079. (setq matcher (org-make-tags-matcher match)
  4080. match (car matcher) matcher (cdr matcher))
  4081. (catch 'exit
  4082. (if org-agenda-sticky
  4083. (setq org-agenda-buffer-name
  4084. (if (stringp match)
  4085. (format "*Org Agenda(%s:%s)*"
  4086. (or org-keys (or (and todo-only "M") "m")) match)
  4087. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4088. (org-agenda-prepare (concat "TAGS " match))
  4089. (org-compile-prefix-format 'tags)
  4090. (org-set-sorting-strategy 'tags)
  4091. (setq org-agenda-query-string match)
  4092. (setq org-agenda-redo-command
  4093. (list 'org-tags-view `(quote ,todo-only)
  4094. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4095. (setq files (org-agenda-files nil 'ifmode)
  4096. rtnall nil)
  4097. (while (setq file (pop files))
  4098. (catch 'nextfile
  4099. (org-check-agenda-file file)
  4100. (setq buffer (if (file-exists-p file)
  4101. (org-get-agenda-file-buffer file)
  4102. (error "No such file %s" file)))
  4103. (if (not buffer)
  4104. ;; If file does not exist, error message to agenda
  4105. (setq rtn (list
  4106. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4107. rtnall (append rtnall rtn))
  4108. (with-current-buffer buffer
  4109. (unless (derived-mode-p 'org-mode)
  4110. (error "Agenda file %s is not in `org-mode'" file))
  4111. (save-excursion
  4112. (save-restriction
  4113. (if org-agenda-restrict
  4114. (narrow-to-region org-agenda-restrict-begin
  4115. org-agenda-restrict-end)
  4116. (widen))
  4117. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4118. (setq rtnall (append rtnall rtn))))))))
  4119. (if org-agenda-overriding-header
  4120. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4121. nil 'face 'org-agenda-structure) "\n")
  4122. (insert "Headlines with TAGS match: ")
  4123. (add-text-properties (point-min) (1- (point))
  4124. (list 'face 'org-agenda-structure
  4125. 'short-heading
  4126. (concat "Match: " match)))
  4127. (setq pos (point))
  4128. (insert match "\n")
  4129. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4130. (setq pos (point))
  4131. (unless org-agenda-multi
  4132. (insert "Press `C-u r' to search again with new search string\n"))
  4133. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4134. (org-agenda-mark-header-line (point-min))
  4135. (when rtnall
  4136. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4137. (goto-char (point-min))
  4138. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4139. (add-text-properties (point-min) (point-max)
  4140. `(org-agenda-type tags
  4141. org-last-args (,todo-only ,match)
  4142. org-redo-cmd ,org-agenda-redo-command
  4143. org-serie-cmd ,org-cmd))
  4144. (org-agenda-finalize)
  4145. (setq buffer-read-only t))))
  4146. ;;; Agenda Finding stuck projects
  4147. (defvar org-agenda-skip-regexp nil
  4148. "Regular expression used in skipping subtrees for the agenda.
  4149. This is basically a temporary global variable that can be set and then
  4150. used by user-defined selections using `org-agenda-skip-function'.")
  4151. (defvar org-agenda-overriding-header nil
  4152. "When set during agenda, todo and tags searches it replaces the header.
  4153. This variable should not be set directly, but custom commands can bind it
  4154. in the options section.")
  4155. (defun org-agenda-skip-entry-when-regexp-matches ()
  4156. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4157. If yes, it returns the end position of this entry, causing agenda commands
  4158. to skip the entry but continuing the search in the subtree. This is a
  4159. function that can be put into `org-agenda-skip-function' for the duration
  4160. of a command."
  4161. (let ((end (save-excursion (org-end-of-subtree t)))
  4162. skip)
  4163. (save-excursion
  4164. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4165. (and skip end)))
  4166. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4167. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4168. If yes, it returns the end position of this tree, causing agenda commands
  4169. to skip this subtree. This is a function that can be put into
  4170. `org-agenda-skip-function' for the duration of a command."
  4171. (let ((end (save-excursion (org-end-of-subtree t)))
  4172. skip)
  4173. (save-excursion
  4174. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4175. (and skip end)))
  4176. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4177. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4178. If yes, it returns the end position of the current entry (NOT the tree),
  4179. causing agenda commands to skip the entry but continuing the search in
  4180. the subtree. This is a function that can be put into
  4181. `org-agenda-skip-function' for the duration of a command. An important
  4182. use of this function is for the stuck project list."
  4183. (let ((end (save-excursion (org-end-of-subtree t)))
  4184. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4185. skip)
  4186. (save-excursion
  4187. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4188. (and skip entry-end)))
  4189. (defun org-agenda-skip-entry-if (&rest conditions)
  4190. "Skip entry if any of CONDITIONS is true.
  4191. See `org-agenda-skip-if' for details."
  4192. (org-agenda-skip-if nil conditions))
  4193. (defun org-agenda-skip-subtree-if (&rest conditions)
  4194. "Skip entry if any of CONDITIONS is true.
  4195. See `org-agenda-skip-if' for details."
  4196. (org-agenda-skip-if t conditions))
  4197. (defun org-agenda-skip-if (subtree conditions)
  4198. "Checks current entity for CONDITIONS.
  4199. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4200. the entry (i.e. the text before the next heading) is checked.
  4201. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4202. from different tests. Valid conditions are:
  4203. scheduled Check if there is a scheduled cookie
  4204. notscheduled Check if there is no scheduled cookie
  4205. deadline Check if there is a deadline
  4206. notdeadline Check if there is no deadline
  4207. timestamp Check if there is a timestamp (also deadline or scheduled)
  4208. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4209. regexp Check if regexp matches
  4210. notregexp Check if regexp does not match.
  4211. todo Check if TODO keyword matches
  4212. nottodo Check if TODO keyword does not match
  4213. The regexp is taken from the conditions list, it must come right after
  4214. the `regexp' or `notregexp' element.
  4215. `todo' and `nottodo' accept as an argument a list of todo
  4216. keywords, which may include \"*\" to match any todo keyword.
  4217. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4218. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4219. Instead of a list, a keyword class may be given. For example:
  4220. (org-agenda-skip-entry-if 'nottodo 'done)
  4221. would skip entries that haven't been marked with any of \"DONE\"
  4222. keywords. Possible classes are: `todo', `done', `any'.
  4223. If any of these conditions is met, this function returns the end point of
  4224. the entity, causing the search to continue from there. This is a function
  4225. that can be put into `org-agenda-skip-function' for the duration of a command."
  4226. (let (beg end m)
  4227. (org-back-to-heading t)
  4228. (setq beg (point)
  4229. end (if subtree
  4230. (progn (org-end-of-subtree t) (point))
  4231. (progn (outline-next-heading) (1- (point)))))
  4232. (goto-char beg)
  4233. (and
  4234. (or
  4235. (and (memq 'scheduled conditions)
  4236. (re-search-forward org-scheduled-time-regexp end t))
  4237. (and (memq 'notscheduled conditions)
  4238. (not (re-search-forward org-scheduled-time-regexp end t)))
  4239. (and (memq 'deadline conditions)
  4240. (re-search-forward org-deadline-time-regexp end t))
  4241. (and (memq 'notdeadline conditions)
  4242. (not (re-search-forward org-deadline-time-regexp end t)))
  4243. (and (memq 'timestamp conditions)
  4244. (re-search-forward org-ts-regexp end t))
  4245. (and (memq 'nottimestamp conditions)
  4246. (not (re-search-forward org-ts-regexp end t)))
  4247. (and (setq m (memq 'regexp conditions))
  4248. (stringp (nth 1 m))
  4249. (re-search-forward (nth 1 m) end t))
  4250. (and (setq m (memq 'notregexp conditions))
  4251. (stringp (nth 1 m))
  4252. (not (re-search-forward (nth 1 m) end t)))
  4253. (and (or
  4254. (setq m (memq 'nottodo conditions))
  4255. (setq m (memq 'todo-unblocked conditions))
  4256. (setq m (memq 'nottodo-unblocked conditions))
  4257. (setq m (memq 'todo conditions)))
  4258. (org-agenda-skip-if-todo m end)))
  4259. end)))
  4260. (defun org-agenda-skip-if-todo (args end)
  4261. "Helper function for `org-agenda-skip-if', do not use it directly.
  4262. ARGS is a list with first element either `todo', `nottodo',
  4263. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4264. a list of TODO keywords, or a state symbol `todo' or `done' or
  4265. `any'."
  4266. (let ((kw (car args))
  4267. (arg (cadr args))
  4268. todo-wds todo-re)
  4269. (setq todo-wds
  4270. (org-uniquify
  4271. (cond
  4272. ((listp arg) ;; list of keywords
  4273. (if (member "*" arg)
  4274. (mapcar 'substring-no-properties org-todo-keywords-1)
  4275. arg))
  4276. ((symbolp arg) ;; keyword class name
  4277. (cond
  4278. ((eq arg 'todo)
  4279. (org-delete-all org-done-keywords
  4280. (mapcar 'substring-no-properties
  4281. org-todo-keywords-1)))
  4282. ((eq arg 'done) org-done-keywords)
  4283. ((eq arg 'any)
  4284. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4285. (setq todo-re
  4286. (concat "^\\*+[ \t]+\\<\\("
  4287. (mapconcat 'identity todo-wds "\\|")
  4288. "\\)\\>"))
  4289. (cond
  4290. ((eq kw 'todo) (re-search-forward todo-re end t))
  4291. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4292. ((eq kw 'todo-unblocked)
  4293. (catch 'unblocked
  4294. (while (re-search-forward todo-re end t)
  4295. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4296. nil))
  4297. ((eq kw 'nottodo-unblocked)
  4298. (catch 'unblocked
  4299. (while (re-search-forward todo-re end t)
  4300. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4301. t))
  4302. )))
  4303. ;;;###autoload
  4304. (defun org-agenda-list-stuck-projects (&rest ignore)
  4305. "Create agenda view for projects that are stuck.
  4306. Stuck projects are project that have no next actions. For the definitions
  4307. of what a project is and how to check if it stuck, customize the variable
  4308. `org-stuck-projects'."
  4309. (interactive)
  4310. (let* ((org-agenda-skip-function
  4311. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4312. ;; We could have used org-agenda-skip-if here.
  4313. (org-agenda-overriding-header
  4314. (or org-agenda-overriding-header "List of stuck projects: "))
  4315. (matcher (nth 0 org-stuck-projects))
  4316. (todo (nth 1 org-stuck-projects))
  4317. (todo-wds (if (member "*" todo)
  4318. (progn
  4319. (org-agenda-prepare-buffers (org-agenda-files
  4320. nil 'ifmode))
  4321. (org-delete-all
  4322. org-done-keywords-for-agenda
  4323. (copy-sequence org-todo-keywords-for-agenda)))
  4324. todo))
  4325. (todo-re (concat "^\\*+[ \t]+\\("
  4326. (mapconcat 'identity todo-wds "\\|")
  4327. "\\)\\>"))
  4328. (tags (nth 2 org-stuck-projects))
  4329. (tags-re (if (member "*" tags)
  4330. (concat org-outline-regexp-bol
  4331. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4332. (if tags
  4333. (concat org-outline-regexp-bol
  4334. ".*:\\("
  4335. (mapconcat 'identity tags "\\|")
  4336. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4337. (gen-re (nth 3 org-stuck-projects))
  4338. (re-list
  4339. (delq nil
  4340. (list
  4341. (if todo todo-re)
  4342. (if tags tags-re)
  4343. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4344. gen-re)))))
  4345. (setq org-agenda-skip-regexp
  4346. (if re-list
  4347. (mapconcat 'identity re-list "\\|")
  4348. (error "No information how to identify unstuck projects")))
  4349. (org-tags-view nil matcher)
  4350. (with-current-buffer org-agenda-buffer-name
  4351. (setq org-agenda-redo-command
  4352. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4353. ;;; Diary integration
  4354. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4355. (defvar diary-list-entries-hook)
  4356. (defvar diary-time-regexp)
  4357. (defun org-get-entries-from-diary (date)
  4358. "Get the (Emacs Calendar) diary entries for DATE."
  4359. (require 'diary-lib)
  4360. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4361. (diary-display-hook '(fancy-diary-display))
  4362. (diary-display-function 'fancy-diary-display)
  4363. (pop-up-frames nil)
  4364. (diary-list-entries-hook
  4365. (cons 'org-diary-default-entry diary-list-entries-hook))
  4366. (diary-file-name-prefix-function nil) ; turn this feature off
  4367. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4368. entries
  4369. (org-disable-agenda-to-diary t))
  4370. (save-excursion
  4371. (save-window-excursion
  4372. (funcall (if (fboundp 'diary-list-entries)
  4373. 'diary-list-entries 'list-diary-entries)
  4374. date 1)))
  4375. (if (not (get-buffer diary-fancy-buffer))
  4376. (setq entries nil)
  4377. (with-current-buffer diary-fancy-buffer
  4378. (setq buffer-read-only nil)
  4379. (if (zerop (buffer-size))
  4380. ;; No entries
  4381. (setq entries nil)
  4382. ;; Omit the date and other unnecessary stuff
  4383. (org-agenda-cleanup-fancy-diary)
  4384. ;; Add prefix to each line and extend the text properties
  4385. (if (zerop (buffer-size))
  4386. (setq entries nil)
  4387. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4388. (setq entries
  4389. (with-temp-buffer
  4390. (insert entries) (goto-char (point-min))
  4391. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4392. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4393. (replace-match (concat "; " (match-string 1)))))
  4394. (buffer-string)))))
  4395. (set-buffer-modified-p nil)
  4396. (kill-buffer diary-fancy-buffer)))
  4397. (when entries
  4398. (setq entries (org-split-string entries "\n"))
  4399. (setq entries
  4400. (mapcar
  4401. (lambda (x)
  4402. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4403. ;; Extend the text properties to the beginning of the line
  4404. (org-add-props x (text-properties-at (1- (length x)) x)
  4405. 'type "diary" 'date date 'face 'org-agenda-diary))
  4406. entries)))))
  4407. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4408. "Hook run when the fancy diary buffer is cleaned up.")
  4409. (defun org-agenda-cleanup-fancy-diary ()
  4410. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4411. This gets rid of the date, the underline under the date, and
  4412. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4413. date. It also removes lines that contain only whitespace."
  4414. (goto-char (point-min))
  4415. (if (looking-at ".*?:[ \t]*")
  4416. (progn
  4417. (replace-match "")
  4418. (re-search-forward "\n=+$" nil t)
  4419. (replace-match "")
  4420. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4421. (re-search-forward "\n=+$" nil t)
  4422. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4423. (goto-char (point-min))
  4424. (while (re-search-forward "^ +\n" nil t)
  4425. (replace-match ""))
  4426. (goto-char (point-min))
  4427. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4428. (replace-match ""))
  4429. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4430. ;; Make sure entries from the diary have the right text properties.
  4431. (eval-after-load "diary-lib"
  4432. '(if (boundp 'diary-modify-entry-list-string-function)
  4433. ;; We can rely on the hook, nothing to do
  4434. nil
  4435. ;; Hook not available, must use advice to make this work
  4436. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4437. "Make the position visible."
  4438. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4439. (stringp string)
  4440. buffer-file-name)
  4441. (setq string (org-modify-diary-entry-string string))))))
  4442. (defun org-modify-diary-entry-string (string)
  4443. "Add text properties to string, allowing org-mode to act on it."
  4444. (org-add-props string nil
  4445. 'mouse-face 'highlight
  4446. 'help-echo (if buffer-file-name
  4447. (format "mouse-2 or RET jump to diary file %s"
  4448. (abbreviate-file-name buffer-file-name))
  4449. "")
  4450. 'org-agenda-diary-link t
  4451. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4452. (defun org-diary-default-entry ()
  4453. "Add a dummy entry to the diary.
  4454. Needed to avoid empty dates which mess up holiday display."
  4455. ;; Catch the error if dealing with the new add-to-diary-alist
  4456. (when org-disable-agenda-to-diary
  4457. (condition-case nil
  4458. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4459. (error
  4460. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4461. (defun org-add-to-diary-list (&rest args)
  4462. (if (fboundp 'diary-add-to-list)
  4463. (apply 'diary-add-to-list args)
  4464. (apply 'add-to-diary-list args)))
  4465. (defvar org-diary-last-run-time nil)
  4466. ;;;###autoload
  4467. (defun org-diary (&rest args)
  4468. "Return diary information from org files.
  4469. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4470. It accesses org files and extracts information from those files to be
  4471. listed in the diary. The function accepts arguments specifying what
  4472. items should be listed. For a list of arguments allowed here, see the
  4473. variable `org-agenda-entry-types'.
  4474. The call in the diary file should look like this:
  4475. &%%(org-diary) ~/path/to/some/orgfile.org
  4476. Use a separate line for each org file to check. Or, if you omit the file name,
  4477. all files listed in `org-agenda-files' will be checked automatically:
  4478. &%%(org-diary)
  4479. If you don't give any arguments (as in the example above), the default
  4480. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4481. So the example above may also be written as
  4482. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4483. The function expects the lisp variables `entry' and `date' to be provided
  4484. by the caller, because this is how the calendar works. Don't use this
  4485. function from a program - use `org-agenda-get-day-entries' instead."
  4486. (when (> (- (org-float-time)
  4487. org-agenda-last-marker-time)
  4488. 5)
  4489. ;; I am not sure if this works with sticky agendas, because the marker
  4490. ;; list is then no longer a global variable.
  4491. (org-agenda-reset-markers))
  4492. (org-compile-prefix-format 'agenda)
  4493. (org-set-sorting-strategy 'agenda)
  4494. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4495. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4496. (list entry)
  4497. (org-agenda-files t)))
  4498. (time (org-float-time))
  4499. file rtn results)
  4500. (when (or (not org-diary-last-run-time)
  4501. (> (- time
  4502. org-diary-last-run-time)
  4503. 3))
  4504. (org-agenda-prepare-buffers files))
  4505. (setq org-diary-last-run-time time)
  4506. ;; If this is called during org-agenda, don't return any entries to
  4507. ;; the calendar. Org Agenda will list these entries itself.
  4508. (if org-disable-agenda-to-diary (setq files nil))
  4509. (while (setq file (pop files))
  4510. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4511. (setq results (append results rtn)))
  4512. (if results
  4513. (concat (org-agenda-finalize-entries results) "\n"))))
  4514. ;;; Agenda entry finders
  4515. (defun org-agenda-get-day-entries (file date &rest args)
  4516. "Does the work for `org-diary' and `org-agenda'.
  4517. FILE is the path to a file to be checked for entries. DATE is date like
  4518. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4519. which kind of entries should be extracted. For details about these, see
  4520. the documentation of `org-diary'."
  4521. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4522. (let* ((org-startup-folded nil)
  4523. (org-startup-align-all-tables nil)
  4524. (buffer (if (file-exists-p file)
  4525. (org-get-agenda-file-buffer file)
  4526. (error "No such file %s" file)))
  4527. arg results rtn deadline-results)
  4528. (if (not buffer)
  4529. ;; If file does not exist, make sure an error message ends up in diary
  4530. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4531. (with-current-buffer buffer
  4532. (unless (derived-mode-p 'org-mode)
  4533. (error "Agenda file %s is not in `org-mode'" file))
  4534. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4535. (let ((case-fold-search nil))
  4536. (save-excursion
  4537. (save-restriction
  4538. (if org-agenda-restrict
  4539. (narrow-to-region org-agenda-restrict-begin
  4540. org-agenda-restrict-end)
  4541. (widen))
  4542. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4543. (while (setq arg (pop args))
  4544. (cond
  4545. ((and (eq arg :todo)
  4546. (equal date (calendar-gregorian-from-absolute
  4547. (org-today))))
  4548. (setq rtn (org-agenda-get-todos))
  4549. (setq results (append results rtn)))
  4550. ((eq arg :timestamp)
  4551. (setq rtn (org-agenda-get-blocks))
  4552. (setq results (append results rtn))
  4553. (setq rtn (org-agenda-get-timestamps deadline-results))
  4554. (setq results (append results rtn)))
  4555. ((eq arg :sexp)
  4556. (setq rtn (org-agenda-get-sexps))
  4557. (setq results (append results rtn)))
  4558. ((eq arg :scheduled)
  4559. (setq rtn (org-agenda-get-scheduled deadline-results))
  4560. (setq results (append results rtn)))
  4561. ((eq arg :closed)
  4562. (setq rtn (org-agenda-get-progress))
  4563. (setq results (append results rtn)))
  4564. ((eq arg :deadline)
  4565. (setq rtn (org-agenda-get-deadlines))
  4566. (setq deadline-results (copy-sequence rtn))
  4567. (setq results (append results rtn))))))))
  4568. results))))
  4569. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4570. (defun org-agenda-get-todos ()
  4571. "Return the TODO information for agenda display."
  4572. (let* ((props (list 'face nil
  4573. 'done-face 'org-agenda-done
  4574. 'org-not-done-regexp org-not-done-regexp
  4575. 'org-todo-regexp org-todo-regexp
  4576. 'org-complex-heading-regexp org-complex-heading-regexp
  4577. 'mouse-face 'highlight
  4578. 'help-echo
  4579. (format "mouse-2 or RET jump to org file %s"
  4580. (abbreviate-file-name buffer-file-name))))
  4581. (regexp (format org-heading-keyword-regexp-format
  4582. (cond
  4583. ((and org-select-this-todo-keyword
  4584. (equal org-select-this-todo-keyword "*"))
  4585. org-todo-regexp)
  4586. (org-select-this-todo-keyword
  4587. (concat "\\("
  4588. (mapconcat 'identity
  4589. (org-split-string
  4590. org-select-this-todo-keyword
  4591. "|")
  4592. "\\|") "\\)"))
  4593. (t org-not-done-regexp))))
  4594. marker priority category category-pos tags todo-state
  4595. ee txt beg end)
  4596. (goto-char (point-min))
  4597. (while (re-search-forward regexp nil t)
  4598. (catch :skip
  4599. (save-match-data
  4600. (beginning-of-line)
  4601. (org-agenda-skip)
  4602. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4603. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4604. (goto-char (1+ beg))
  4605. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4606. (throw :skip nil)))
  4607. (goto-char (match-beginning 2))
  4608. (setq marker (org-agenda-new-marker (match-beginning 0))
  4609. category (org-get-category)
  4610. category-pos (get-text-property (point) 'org-category-position)
  4611. txt (org-trim
  4612. (buffer-substring (match-beginning 2) (match-end 0)))
  4613. tags (org-get-tags-at (point))
  4614. txt (org-agenda-format-item "" txt category tags t)
  4615. priority (1+ (org-get-priority txt))
  4616. todo-state (org-get-todo-state))
  4617. (org-add-props txt props
  4618. 'org-marker marker 'org-hd-marker marker
  4619. 'priority priority 'org-category category
  4620. 'org-category-position category-pos
  4621. 'type "todo" 'todo-state todo-state)
  4622. (push txt ee)
  4623. (if org-agenda-todo-list-sublevels
  4624. (goto-char (match-end 2))
  4625. (org-end-of-subtree 'invisible))))
  4626. (nreverse ee)))
  4627. (defun org-agenda-todo-custom-ignore-p (time n)
  4628. "Check whether timestamp is farther away than n number of days.
  4629. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4630. `org-agenda-todo-ignore-scheduled' or
  4631. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4632. (let ((days (org-days-to-time time)))
  4633. (if (>= n 0)
  4634. (>= days n)
  4635. (<= days n))))
  4636. ;;;###autoload
  4637. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4638. (&optional end)
  4639. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4640. (when (or org-agenda-todo-ignore-with-date
  4641. org-agenda-todo-ignore-scheduled
  4642. org-agenda-todo-ignore-deadlines
  4643. org-agenda-todo-ignore-timestamp)
  4644. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4645. (save-excursion
  4646. (or (and org-agenda-todo-ignore-with-date
  4647. (re-search-forward org-ts-regexp end t))
  4648. (and org-agenda-todo-ignore-scheduled
  4649. (re-search-forward org-scheduled-time-regexp end t)
  4650. (cond
  4651. ((eq org-agenda-todo-ignore-scheduled 'future)
  4652. (> (org-days-to-time (match-string 1)) 0))
  4653. ((eq org-agenda-todo-ignore-scheduled 'past)
  4654. (<= (org-days-to-time (match-string 1)) 0))
  4655. ((numberp org-agenda-todo-ignore-scheduled)
  4656. (org-agenda-todo-custom-ignore-p
  4657. (match-string 1) org-agenda-todo-ignore-scheduled))
  4658. (t)))
  4659. (and org-agenda-todo-ignore-deadlines
  4660. (re-search-forward org-deadline-time-regexp end t)
  4661. (cond
  4662. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4663. ((eq org-agenda-todo-ignore-deadlines 'far)
  4664. (not (org-deadline-close (match-string 1))))
  4665. ((eq org-agenda-todo-ignore-deadlines 'future)
  4666. (> (org-days-to-time (match-string 1)) 0))
  4667. ((eq org-agenda-todo-ignore-deadlines 'past)
  4668. (<= (org-days-to-time (match-string 1)) 0))
  4669. ((numberp org-agenda-todo-ignore-deadlines)
  4670. (org-agenda-todo-custom-ignore-p
  4671. (match-string 1) org-agenda-todo-ignore-deadlines))
  4672. (t (org-deadline-close (match-string 1)))))
  4673. (and org-agenda-todo-ignore-timestamp
  4674. (let ((buffer (current-buffer))
  4675. (regexp
  4676. (concat
  4677. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4678. (start (point)))
  4679. ;; Copy current buffer into a temporary one
  4680. (with-temp-buffer
  4681. (insert-buffer-substring buffer start end)
  4682. (goto-char (point-min))
  4683. ;; Delete SCHEDULED and DEADLINE items
  4684. (while (re-search-forward regexp end t)
  4685. (delete-region (match-beginning 0) (match-end 0)))
  4686. (goto-char (point-min))
  4687. ;; No search for timestamp left
  4688. (when (re-search-forward org-ts-regexp nil t)
  4689. (cond
  4690. ((eq org-agenda-todo-ignore-timestamp 'future)
  4691. (> (org-days-to-time (match-string 1)) 0))
  4692. ((eq org-agenda-todo-ignore-timestamp 'past)
  4693. (<= (org-days-to-time (match-string 1)) 0))
  4694. ((numberp org-agenda-todo-ignore-timestamp)
  4695. (org-agenda-todo-custom-ignore-p
  4696. (match-string 1) org-agenda-todo-ignore-timestamp))
  4697. (t))))))))))
  4698. (defconst org-agenda-no-heading-message
  4699. "No heading for this item in buffer or region.")
  4700. (defun org-agenda-get-timestamps (&optional deadline-results)
  4701. "Return the date stamp information for agenda display."
  4702. (let* ((props (list 'face 'org-agenda-calendar-event
  4703. 'org-not-done-regexp org-not-done-regexp
  4704. 'org-todo-regexp org-todo-regexp
  4705. 'org-complex-heading-regexp org-complex-heading-regexp
  4706. 'mouse-face 'highlight
  4707. 'help-echo
  4708. (format "mouse-2 or RET jump to org file %s"
  4709. (abbreviate-file-name buffer-file-name))))
  4710. (d1 (calendar-absolute-from-gregorian date))
  4711. mm
  4712. (deadline-position-alist
  4713. (mapcar (lambda (a) (and (setq mm (get-text-property
  4714. 0 'org-hd-marker a))
  4715. (cons (marker-position mm) a)))
  4716. deadline-results))
  4717. (remove-re org-ts-regexp)
  4718. (regexp
  4719. (concat
  4720. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4721. (regexp-quote
  4722. (substring
  4723. (format-time-string
  4724. (car org-time-stamp-formats)
  4725. (apply 'encode-time ; DATE bound by calendar
  4726. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4727. 1 11))
  4728. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4729. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4730. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4731. donep tmp priority category category-pos ee txt timestr tags
  4732. b0 b3 e3 head todo-state end-of-match show-all warntime)
  4733. (goto-char (point-min))
  4734. (while (setq end-of-match (re-search-forward regexp nil t))
  4735. (setq b0 (match-beginning 0)
  4736. b3 (match-beginning 3) e3 (match-end 3)
  4737. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4738. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4739. (member todo-state
  4740. org-agenda-repeating-timestamp-show-all)))
  4741. (catch :skip
  4742. (and (org-at-date-range-p) (throw :skip nil))
  4743. (org-agenda-skip)
  4744. (if (and (match-end 1)
  4745. (not (= d1 (org-time-string-to-absolute
  4746. (match-string 1) d1 nil show-all
  4747. (current-buffer) b0))))
  4748. (throw :skip nil))
  4749. (if (and e3
  4750. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4751. (throw :skip nil))
  4752. (setq tmp (buffer-substring (max (point-min)
  4753. (- b0 org-ds-keyword-length))
  4754. b0)
  4755. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4756. inactivep (= (char-after b0) ?\[)
  4757. deadlinep (string-match org-deadline-regexp tmp)
  4758. scheduledp (string-match org-scheduled-regexp tmp)
  4759. closedp (and org-agenda-include-inactive-timestamps
  4760. (string-match org-closed-string tmp))
  4761. clockp (and org-agenda-include-inactive-timestamps
  4762. (or (string-match org-clock-string tmp)
  4763. (string-match "]-+\\'" tmp)))
  4764. warntime (org-entry-get (point) "APPT_WARNTIME")
  4765. donep (member todo-state org-done-keywords))
  4766. (if (or scheduledp deadlinep closedp clockp
  4767. (and donep org-agenda-skip-timestamp-if-done))
  4768. (throw :skip t))
  4769. (if (string-match ">" timestr)
  4770. ;; substring should only run to end of time stamp
  4771. (setq timestr (substring timestr 0 (match-end 0))))
  4772. (setq marker (org-agenda-new-marker b0)
  4773. category (org-get-category b0)
  4774. category-pos (get-text-property b0 'org-category-position))
  4775. (save-excursion
  4776. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4777. (setq txt org-agenda-no-heading-message)
  4778. (goto-char (match-beginning 0))
  4779. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4780. (assoc (point) deadline-position-alist))
  4781. (throw :skip nil))
  4782. (setq hdmarker (org-agenda-new-marker)
  4783. tags (org-get-tags-at))
  4784. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4785. (setq head (or (match-string 1) ""))
  4786. (setq txt (org-agenda-format-item
  4787. (if inactivep org-agenda-inactive-leader nil)
  4788. head category tags timestr
  4789. remove-re t)))
  4790. (setq priority (org-get-priority txt))
  4791. (org-add-props txt props
  4792. 'org-marker marker 'org-hd-marker hdmarker)
  4793. (org-add-props txt nil 'priority priority
  4794. 'org-category category 'date date
  4795. 'org-category-position category-pos
  4796. 'todo-state todo-state
  4797. 'warntime warntime
  4798. 'type "timestamp")
  4799. (push txt ee))
  4800. (if org-agenda-skip-additional-timestamps-same-entry
  4801. (outline-next-heading)
  4802. (goto-char end-of-match))))
  4803. (nreverse ee)))
  4804. (defun org-agenda-get-sexps ()
  4805. "Return the sexp information for agenda display."
  4806. (require 'diary-lib)
  4807. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4808. 'mouse-face 'highlight
  4809. 'help-echo
  4810. (format "mouse-2 or RET jump to org file %s"
  4811. (abbreviate-file-name buffer-file-name))))
  4812. (regexp "^&?%%(")
  4813. marker category extra category-pos ee txt tags entry
  4814. result beg b sexp sexp-entry todo-state warntime)
  4815. (goto-char (point-min))
  4816. (while (re-search-forward regexp nil t)
  4817. (catch :skip
  4818. (org-agenda-skip)
  4819. (setq beg (match-beginning 0))
  4820. (goto-char (1- (match-end 0)))
  4821. (setq b (point))
  4822. (forward-sexp 1)
  4823. (setq sexp (buffer-substring b (point)))
  4824. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4825. (org-trim (match-string 1))
  4826. ""))
  4827. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4828. (when result
  4829. (setq marker (org-agenda-new-marker beg)
  4830. category (org-get-category beg)
  4831. category-pos (get-text-property beg 'org-category-position)
  4832. tags (save-excursion (org-backward-heading-same-level 0)
  4833. (org-get-tags-at))
  4834. todo-state (org-get-todo-state)
  4835. warntime (org-entry-get (point) "APPT_WARNTIME"))
  4836. (dolist (r (if (stringp result)
  4837. (list result)
  4838. result)) ;; we expect a list here
  4839. (when (and org-agenda-diary-sexp-prefix
  4840. (string-match org-agenda-diary-sexp-prefix r))
  4841. (setq extra (match-string 0 r)
  4842. r (replace-match "" nil nil r)))
  4843. (if (string-match "\\S-" r)
  4844. (setq txt r)
  4845. (setq txt "SEXP entry returned empty string"))
  4846. (setq txt (org-agenda-format-item
  4847. extra txt category tags 'time))
  4848. (org-add-props txt props 'org-marker marker)
  4849. (org-add-props txt nil
  4850. 'org-category category 'date date 'todo-state todo-state
  4851. 'org-category-position category-pos 'tags tags
  4852. 'type "sexp" 'warntime warntime)
  4853. (push txt ee)))))
  4854. (nreverse ee)))
  4855. ;; Calendar sanity: define some functions that are independent of
  4856. ;; `calendar-date-style'.
  4857. ;; Normally I would like to use ISO format when calling the diary functions,
  4858. ;; but to make sure we still have Emacs 22 compatibility we bind
  4859. ;; also `european-calendar-style' and use european format
  4860. (defun org-anniversary (year month day &optional mark)
  4861. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4862. (org-no-warnings
  4863. (let ((calendar-date-style 'european) (european-calendar-style t))
  4864. (diary-anniversary day month year mark))))
  4865. (defun org-cyclic (N year month day &optional mark)
  4866. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4867. (org-no-warnings
  4868. (let ((calendar-date-style 'european) (european-calendar-style t))
  4869. (diary-cyclic N day month year mark))))
  4870. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4871. "Like `diary-block', but with fixed (ISO) order of arguments."
  4872. (org-no-warnings
  4873. (let ((calendar-date-style 'european) (european-calendar-style t))
  4874. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4875. (defun org-date (year month day &optional mark)
  4876. "Like `diary-date', but with fixed (ISO) order of arguments."
  4877. (org-no-warnings
  4878. (let ((calendar-date-style 'european) (european-calendar-style t))
  4879. (diary-date day month year mark))))
  4880. (defalias 'org-float 'diary-float)
  4881. ;; Define the` org-class' function
  4882. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4883. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4884. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4885. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4886. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4887. `holidays', then any date that is known by the Emacs calendar to be a
  4888. holiday will also be skipped."
  4889. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4890. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4891. (d (calendar-absolute-from-gregorian date)))
  4892. (and
  4893. (<= date1 d)
  4894. (<= d date2)
  4895. (= (calendar-day-of-week date) dayname)
  4896. (or (not skip-weeks)
  4897. (progn
  4898. (require 'cal-iso)
  4899. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4900. (not (and (memq 'holidays skip-weeks)
  4901. (calendar-check-holidays date)))
  4902. entry)))
  4903. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4904. "Like `org-class', but honor `calendar-date-style'.
  4905. The order of the first 2 times 3 arguments depends on the variable
  4906. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4907. So for American calendars, give this as MONTH DAY YEAR, for European as
  4908. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4909. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4910. is any number of ISO weeks in the block period for which the item should
  4911. be skipped.
  4912. This function is here only for backward compatibility and it is deprecated,
  4913. please use `org-class' instead."
  4914. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4915. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4916. (org-class
  4917. (nth 2 date1) (car date1) (nth 1 date1)
  4918. (nth 2 date2) (car date2) (nth 1 date2)
  4919. dayname skip-weeks)))
  4920. (make-obsolete 'org-diary-class 'org-class "")
  4921. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  4922. (defalias 'org-get-closed 'org-agenda-get-progress)
  4923. (defun org-agenda-get-progress ()
  4924. "Return the logged TODO entries for agenda display."
  4925. (let* ((props (list 'mouse-face 'highlight
  4926. 'org-not-done-regexp org-not-done-regexp
  4927. 'org-todo-regexp org-todo-regexp
  4928. 'org-complex-heading-regexp org-complex-heading-regexp
  4929. 'help-echo
  4930. (format "mouse-2 or RET jump to org file %s"
  4931. (abbreviate-file-name buffer-file-name))))
  4932. (items (if (consp org-agenda-show-log-scoped)
  4933. org-agenda-show-log-scoped
  4934. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4935. '(clock)
  4936. org-agenda-log-mode-items)))
  4937. (parts
  4938. (delq nil
  4939. (list
  4940. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4941. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4942. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4943. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4944. (error "`org-agenda-log-mode-items' is empty")))
  4945. (regexp (concat
  4946. "\\(" parts-re "\\)"
  4947. " *\\["
  4948. (regexp-quote
  4949. (substring
  4950. (format-time-string
  4951. (car org-time-stamp-formats)
  4952. (apply 'encode-time ; DATE bound by calendar
  4953. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4954. 1 11))))
  4955. (org-agenda-search-headline-for-time nil)
  4956. marker hdmarker priority category category-pos tags closedp
  4957. statep clockp state ee txt extra timestr rest clocked)
  4958. (goto-char (point-min))
  4959. (while (re-search-forward regexp nil t)
  4960. (catch :skip
  4961. (org-agenda-skip)
  4962. (setq marker (org-agenda-new-marker (match-beginning 0))
  4963. closedp (equal (match-string 1) org-closed-string)
  4964. statep (equal (string-to-char (match-string 1)) ?-)
  4965. clockp (not (or closedp statep))
  4966. state (and statep (match-string 2))
  4967. category (org-get-category (match-beginning 0))
  4968. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4969. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4970. (when (string-match "\\]" timestr)
  4971. ;; substring should only run to end of time stamp
  4972. (setq rest (substring timestr (match-end 0))
  4973. timestr (substring timestr 0 (match-end 0)))
  4974. (if (and (not closedp) (not statep)
  4975. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4976. rest))
  4977. (progn (setq timestr (concat (substring timestr 0 -1)
  4978. "-" (match-string 1 rest) "]"))
  4979. (setq clocked (match-string 2 rest)))
  4980. (setq clocked "-")))
  4981. (save-excursion
  4982. (setq extra
  4983. (cond
  4984. ((not org-agenda-log-mode-add-notes) nil)
  4985. (statep
  4986. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4987. (match-string 1)))
  4988. (clockp
  4989. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4990. (match-string 1)))))
  4991. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4992. (setq txt org-agenda-no-heading-message)
  4993. (goto-char (match-beginning 0))
  4994. (setq hdmarker (org-agenda-new-marker)
  4995. tags (org-get-tags-at))
  4996. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4997. (setq txt (match-string 1))
  4998. (when extra
  4999. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5000. (setq txt (concat (substring txt 0 (match-beginning 1))
  5001. " - " extra " " (match-string 2 txt)))
  5002. (setq txt (concat txt " - " extra))))
  5003. (setq txt (org-agenda-format-item
  5004. (cond
  5005. (closedp "Closed: ")
  5006. (statep (concat "State: (" state ")"))
  5007. (t (concat "Clocked: (" clocked ")")))
  5008. txt category tags timestr)))
  5009. (setq priority 100000)
  5010. (org-add-props txt props
  5011. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5012. 'priority priority 'org-category category
  5013. 'org-category-position category-pos
  5014. 'type "closed" 'date date
  5015. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5016. (push txt ee))
  5017. (goto-char (point-at-eol))))
  5018. (nreverse ee)))
  5019. (defun org-agenda-show-clocking-issues ()
  5020. "Add overlays, showing issues with clocking.
  5021. See also the user option `org-agenda-clock-consistency-checks'."
  5022. (interactive)
  5023. (let* ((pl org-agenda-clock-consistency-checks)
  5024. (re (concat "^[ \t]*"
  5025. org-clock-string
  5026. "[ \t]+"
  5027. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5028. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5029. (tlstart 0.)
  5030. (tlend 0.)
  5031. (maxtime (org-hh:mm-string-to-minutes
  5032. (or (plist-get pl :max-duration) "24:00")))
  5033. (mintime (org-hh:mm-string-to-minutes
  5034. (or (plist-get pl :min-duration) 0)))
  5035. (maxgap (org-hh:mm-string-to-minutes
  5036. ;; default 30:00 means never complain
  5037. (or (plist-get pl :max-gap) "30:00")))
  5038. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5039. (plist-get pl :gap-ok-around)))
  5040. (def-face (or (plist-get pl :default-face)
  5041. '((:background "DarkRed") (:foreground "white"))))
  5042. issue face m te ts dt ov)
  5043. (goto-char (point-min))
  5044. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5045. (setq issue nil face def-face)
  5046. (catch 'next
  5047. (setq m (org-get-at-bol 'org-marker)
  5048. te nil ts nil)
  5049. (unless (and m (markerp m))
  5050. (setq issue "No valid clock line") (throw 'next t))
  5051. (org-with-point-at m
  5052. (save-excursion
  5053. (goto-char (point-at-bol))
  5054. (unless (looking-at re)
  5055. (error "No valid Clock line")
  5056. (throw 'next t))
  5057. (unless (match-end 3)
  5058. (setq issue "No end time"
  5059. face (or (plist-get pl :no-end-time-face) face))
  5060. (throw 'next t))
  5061. (setq ts (match-string 1)
  5062. te (match-string 3)
  5063. ts (org-float-time
  5064. (apply 'encode-time (org-parse-time-string ts)))
  5065. te (org-float-time
  5066. (apply 'encode-time (org-parse-time-string te)))
  5067. dt (- te ts))))
  5068. (cond
  5069. ((> dt (* 60 maxtime))
  5070. ;; a very long clocking chunk
  5071. (setq issue (format "Clocking interval is very long: %s"
  5072. (org-minutes-to-hh:mm-string
  5073. (floor (/ (float dt) 60.))))
  5074. face (or (plist-get pl :long-face) face)))
  5075. ((< dt (* 60 mintime))
  5076. ;; a very short clocking chunk
  5077. (setq issue (format "Clocking interval is very short: %s"
  5078. (org-minutes-to-hh:mm-string
  5079. (floor (/ (float dt) 60.))))
  5080. face (or (plist-get pl :short-face) face)))
  5081. ((and (> tlend 0) (< ts tlend))
  5082. ;; Two clock entries are overlapping
  5083. (setq issue (format "Clocking overlap: %d minutes"
  5084. (/ (- tlend ts) 60))
  5085. face (or (plist-get pl :overlap-face) face)))
  5086. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5087. ;; There is a gap, lets see if we need to report it
  5088. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5089. (setq issue (format "Clocking gap: %d minutes"
  5090. (/ (- ts tlend) 60))
  5091. face (or (plist-get pl :gap-face) face))))
  5092. (t nil)))
  5093. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5094. (when issue
  5095. ;; OK, there was some issue, add an overlay to show the issue
  5096. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5097. (overlay-put ov 'before-string
  5098. (concat
  5099. (org-add-props
  5100. (format "%-43s" (concat " " issue))
  5101. nil
  5102. 'face face)
  5103. "\n"))
  5104. (overlay-put ov 'evaporate t)))))
  5105. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5106. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5107. (catch 'exit
  5108. (unless ok-list
  5109. ;; there are no OK times for gaps...
  5110. (throw 'exit nil))
  5111. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5112. ;; This is more than 24 hours, so it is OK.
  5113. ;; because we have at least one OK time, that must be in the
  5114. ;; 24 hour interval.
  5115. (throw 'exit t))
  5116. ;; We have a shorter gap.
  5117. ;; Now we have to get the minute of the day when these times are
  5118. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5119. (t2dec (decode-time (seconds-to-time t2)))
  5120. ;; compute the minute on the day
  5121. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5122. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5123. (when (< min2 min1)
  5124. ;; if min2 is smaller than min1, this means it is on the next day.
  5125. ;; Wrap it to after midnight.
  5126. (setq min2 (+ min2 1440)))
  5127. ;; Now check if any of the OK times is in the gap
  5128. (mapc (lambda (x)
  5129. ;; Wrap the time to after midnight if necessary
  5130. (if (< x min1) (setq x (+ x 1440)))
  5131. ;; Check if in interval
  5132. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5133. ok-list)
  5134. ;; Nope, this gap is not OK
  5135. nil)))
  5136. (defun org-agenda-get-deadlines ()
  5137. "Return the deadline information for agenda display."
  5138. (let* ((props (list 'mouse-face 'highlight
  5139. 'org-not-done-regexp org-not-done-regexp
  5140. 'org-todo-regexp org-todo-regexp
  5141. 'org-complex-heading-regexp org-complex-heading-regexp
  5142. 'help-echo
  5143. (format "mouse-2 or RET jump to org file %s"
  5144. (abbreviate-file-name buffer-file-name))))
  5145. (regexp org-deadline-time-regexp)
  5146. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5147. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5148. d2 diff dfrac wdays pos pos1 category category-pos
  5149. tags suppress-prewarning ee txt head face s todo-state
  5150. show-all upcomingp donep timestr warntime)
  5151. (goto-char (point-min))
  5152. (while (re-search-forward regexp nil t)
  5153. (setq suppress-prewarning nil)
  5154. (catch :skip
  5155. (org-agenda-skip)
  5156. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5157. (save-match-data
  5158. (string-match org-scheduled-time-regexp
  5159. (buffer-substring (point-at-bol)
  5160. (point-at-eol)))))
  5161. (setq suppress-prewarning
  5162. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5163. org-agenda-skip-deadline-prewarning-if-scheduled
  5164. 0)))
  5165. (setq s (match-string 1)
  5166. txt nil
  5167. pos (1- (match-beginning 1))
  5168. todo-state (save-match-data (org-get-todo-state))
  5169. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5170. (member todo-state
  5171. org-agenda-repeating-timestamp-show-all))
  5172. d2 (org-time-string-to-absolute
  5173. (match-string 1) d1 'past show-all
  5174. (current-buffer) pos)
  5175. diff (- d2 d1)
  5176. wdays (if suppress-prewarning
  5177. (let ((org-deadline-warning-days suppress-prewarning))
  5178. (org-get-wdays s))
  5179. (org-get-wdays s))
  5180. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5181. upcomingp (and todayp (> diff 0)))
  5182. ;; When to show a deadline in the calendar:
  5183. ;; If the expiration is within wdays warning time.
  5184. ;; Past-due deadlines are only shown on the current date
  5185. (if (and (or (and (<= diff wdays)
  5186. (and todayp (not org-agenda-only-exact-dates)))
  5187. (= diff 0)))
  5188. (save-excursion
  5189. ;; (setq todo-state (org-get-todo-state))
  5190. (setq donep (member todo-state org-done-keywords))
  5191. (if (and donep
  5192. (or org-agenda-skip-deadline-if-done
  5193. (not (= diff 0))))
  5194. (setq txt nil)
  5195. (setq category (org-get-category)
  5196. warntime (org-entry-get (point) "APPT_WARNTIME")
  5197. category-pos (get-text-property (point) 'org-category-position))
  5198. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5199. (setq txt org-agenda-no-heading-message)
  5200. (goto-char (match-end 0))
  5201. (setq pos1 (match-beginning 0))
  5202. (setq tags (org-get-tags-at pos1))
  5203. (setq head (buffer-substring-no-properties
  5204. (point)
  5205. (progn (skip-chars-forward "^\r\n")
  5206. (point))))
  5207. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5208. (setq timestr
  5209. (concat (substring s (match-beginning 1)) " "))
  5210. (setq timestr 'time))
  5211. (setq txt (org-agenda-format-item
  5212. (if (= diff 0)
  5213. (car org-agenda-deadline-leaders)
  5214. (if (functionp
  5215. (nth 1 org-agenda-deadline-leaders))
  5216. (funcall
  5217. (nth 1 org-agenda-deadline-leaders)
  5218. diff date)
  5219. (format (nth 1 org-agenda-deadline-leaders)
  5220. diff)))
  5221. head category tags
  5222. (if (not (= diff 0)) nil timestr)))))
  5223. (when txt
  5224. (setq face (org-agenda-deadline-face dfrac))
  5225. (org-add-props txt props
  5226. 'org-marker (org-agenda-new-marker pos)
  5227. 'warntime warntime
  5228. 'org-hd-marker (org-agenda-new-marker pos1)
  5229. 'priority (+ (- diff)
  5230. (org-get-priority txt))
  5231. 'org-category category
  5232. 'org-category-position category-pos
  5233. 'todo-state todo-state
  5234. 'type (if upcomingp "upcoming-deadline" "deadline")
  5235. 'date (if upcomingp date d2)
  5236. 'face (if donep 'org-agenda-done face)
  5237. 'undone-face face 'done-face 'org-agenda-done)
  5238. (push txt ee))))))
  5239. (nreverse ee)))
  5240. (defun org-agenda-deadline-face (fraction)
  5241. "Return the face to displaying a deadline item.
  5242. FRACTION is what fraction of the head-warning time has passed."
  5243. (let ((faces org-agenda-deadline-faces) f)
  5244. (catch 'exit
  5245. (while (setq f (pop faces))
  5246. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5247. (defun org-agenda-get-scheduled (&optional deadline-results)
  5248. "Return the scheduled information for agenda display."
  5249. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5250. 'org-todo-regexp org-todo-regexp
  5251. 'org-complex-heading-regexp org-complex-heading-regexp
  5252. 'done-face 'org-agenda-done
  5253. 'mouse-face 'highlight
  5254. 'help-echo
  5255. (format "mouse-2 or RET jump to org file %s"
  5256. (abbreviate-file-name buffer-file-name))))
  5257. (regexp org-scheduled-time-regexp)
  5258. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5259. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5260. mm
  5261. (deadline-position-alist
  5262. (mapcar (lambda (a) (and (setq mm (get-text-property
  5263. 0 'org-hd-marker a))
  5264. (cons (marker-position mm) a)))
  5265. deadline-results))
  5266. d2 diff pos pos1 category category-pos tags donep
  5267. ee txt head pastschedp todo-state face timestr s habitp show-all
  5268. did-habit-check-p warntime)
  5269. (goto-char (point-min))
  5270. (while (re-search-forward regexp nil t)
  5271. (catch :skip
  5272. (org-agenda-skip)
  5273. (setq s (match-string 1)
  5274. txt nil
  5275. pos (1- (match-beginning 1))
  5276. todo-state (save-match-data (org-get-todo-state))
  5277. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5278. (member todo-state
  5279. org-agenda-repeating-timestamp-show-all))
  5280. d2 (org-time-string-to-absolute
  5281. (match-string 1) d1 'past show-all
  5282. (current-buffer) pos)
  5283. diff (- d2 d1)
  5284. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5285. (setq pastschedp (and todayp (< diff 0)))
  5286. (setq did-habit-check-p nil)
  5287. ;; When to show a scheduled item in the calendar:
  5288. ;; If it is on or past the date.
  5289. (when (or (and (< diff 0)
  5290. (< (abs diff) org-scheduled-past-days)
  5291. (and todayp (not org-agenda-only-exact-dates)))
  5292. (= diff 0)
  5293. ;; org-is-habit-p uses org-entry-get, which is expansive
  5294. ;; so we go extra mile to only call it once
  5295. (and todayp
  5296. (boundp 'org-habit-show-all-today)
  5297. org-habit-show-all-today
  5298. (setq did-habit-check-p t)
  5299. (setq habitp (and (functionp 'org-is-habit-p)
  5300. (org-is-habit-p)))))
  5301. (save-excursion
  5302. (setq donep (member todo-state org-done-keywords))
  5303. (if (and donep
  5304. (or org-agenda-skip-scheduled-if-done
  5305. (not (= diff 0))
  5306. (and (functionp 'org-is-habit-p)
  5307. (org-is-habit-p))))
  5308. (setq txt nil)
  5309. (setq habitp (if did-habit-check-p habitp
  5310. (and (functionp 'org-is-habit-p)
  5311. (org-is-habit-p))))
  5312. (setq category (org-get-category)
  5313. category-pos (get-text-property (point) 'org-category-position))
  5314. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5315. (setq txt org-agenda-no-heading-message)
  5316. (goto-char (match-end 0))
  5317. (setq pos1 (match-beginning 0))
  5318. (if habitp
  5319. (if (or (not org-habit-show-habits)
  5320. (and (not todayp)
  5321. (boundp 'org-habit-show-habits-only-for-today)
  5322. org-habit-show-habits-only-for-today))
  5323. (throw :skip nil))
  5324. (if (and
  5325. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5326. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5327. pastschedp))
  5328. (setq mm (assoc pos1 deadline-position-alist)))
  5329. (throw :skip nil)))
  5330. (setq tags (org-get-tags-at))
  5331. (setq head (buffer-substring-no-properties
  5332. (point)
  5333. (progn (skip-chars-forward "^\r\n") (point))))
  5334. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5335. (setq timestr
  5336. (concat (substring s (match-beginning 1)) " "))
  5337. (setq timestr 'time))
  5338. (setq txt (org-agenda-format-item
  5339. (if (= diff 0)
  5340. (car org-agenda-scheduled-leaders)
  5341. (format (nth 1 org-agenda-scheduled-leaders)
  5342. (- 1 diff)))
  5343. head category tags
  5344. (if (not (= diff 0)) nil timestr)
  5345. nil habitp))))
  5346. (when txt
  5347. (setq face
  5348. (cond
  5349. ((and (not habitp) pastschedp)
  5350. 'org-scheduled-previously)
  5351. (todayp 'org-scheduled-today)
  5352. (t 'org-scheduled))
  5353. habitp (and habitp (org-habit-parse-todo)))
  5354. (org-add-props txt props
  5355. 'undone-face face
  5356. 'face (if donep 'org-agenda-done face)
  5357. 'org-marker (org-agenda-new-marker pos)
  5358. 'org-hd-marker (org-agenda-new-marker pos1)
  5359. 'type (if pastschedp "past-scheduled" "scheduled")
  5360. 'date (if pastschedp d2 date)
  5361. 'warntime warntime
  5362. 'priority (if habitp
  5363. (org-habit-get-priority habitp)
  5364. (+ 94 (- 5 diff) (org-get-priority txt)))
  5365. 'org-category category
  5366. 'category-position category-pos
  5367. 'org-habit-p habitp
  5368. 'todo-state todo-state)
  5369. (push txt ee))))))
  5370. (nreverse ee)))
  5371. (defun org-agenda-get-blocks ()
  5372. "Return the date-range information for agenda display."
  5373. (let* ((props (list 'face nil
  5374. 'org-not-done-regexp org-not-done-regexp
  5375. 'org-todo-regexp org-todo-regexp
  5376. 'org-complex-heading-regexp org-complex-heading-regexp
  5377. 'mouse-face 'highlight
  5378. 'help-echo
  5379. (format "mouse-2 or RET jump to org file %s"
  5380. (abbreviate-file-name buffer-file-name))))
  5381. (regexp org-tr-regexp)
  5382. (d0 (calendar-absolute-from-gregorian date))
  5383. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5384. todo-state tags pos head donep)
  5385. (goto-char (point-min))
  5386. (while (re-search-forward regexp nil t)
  5387. (catch :skip
  5388. (org-agenda-skip)
  5389. (setq pos (point))
  5390. (let ((start-time (match-string 1))
  5391. (end-time (match-string 2)))
  5392. (setq s1 (match-string 1)
  5393. s2 (match-string 2)
  5394. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5395. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5396. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5397. ;; Only allow days between the limits, because the normal
  5398. ;; date stamps will catch the limits.
  5399. (save-excursion
  5400. (setq todo-state (org-get-todo-state))
  5401. (setq donep (member todo-state org-done-keywords))
  5402. (if (and donep org-agenda-skip-timestamp-if-done)
  5403. (throw :skip t))
  5404. (setq marker (org-agenda-new-marker (point)))
  5405. (setq category (org-get-category)
  5406. category-pos (get-text-property (point) 'org-category-position))
  5407. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5408. (setq txt org-agenda-no-heading-message)
  5409. (goto-char (match-beginning 0))
  5410. (setq hdmarker (org-agenda-new-marker (point)))
  5411. (setq tags (org-get-tags-at))
  5412. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5413. (setq head (match-string 1))
  5414. (let ((remove-re
  5415. (if org-agenda-remove-timeranges-from-blocks
  5416. (concat
  5417. "<" (regexp-quote s1) ".*?>"
  5418. "--"
  5419. "<" (regexp-quote s2) ".*?>")
  5420. nil)))
  5421. (setq txt (org-agenda-format-item
  5422. (format
  5423. (nth (if (= d1 d2) 0 1)
  5424. org-agenda-timerange-leaders)
  5425. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5426. head category tags
  5427. (cond ((and (= d1 d0) (= d2 d0))
  5428. (concat "<" start-time ">--<" end-time ">"))
  5429. ((= d1 d0)
  5430. (concat "<" start-time ">"))
  5431. ((= d2 d0)
  5432. (concat "<" end-time ">")))
  5433. remove-re t))))
  5434. (org-add-props txt props
  5435. 'org-marker marker 'org-hd-marker hdmarker
  5436. 'type "block" 'date date
  5437. 'todo-state todo-state
  5438. 'priority (org-get-priority txt) 'org-category category
  5439. 'org-category-position category-pos)
  5440. (push txt ee))))
  5441. (goto-char pos)))
  5442. ;; Sort the entries by expiration date.
  5443. (nreverse ee)))
  5444. ;;; Agenda presentation and sorting
  5445. (defvar org-prefix-has-time nil
  5446. "A flag, set by `org-compile-prefix-format'.
  5447. The flag is set if the currently compiled format contains a `%t'.")
  5448. (defvar org-prefix-has-tag nil
  5449. "A flag, set by `org-compile-prefix-format'.
  5450. The flag is set if the currently compiled format contains a `%T'.")
  5451. (defvar org-prefix-has-effort nil
  5452. "A flag, set by `org-compile-prefix-format'.
  5453. The flag is set if the currently compiled format contains a `%e'.")
  5454. (defvar org-prefix-category-length nil
  5455. "Used by `org-compile-prefix-format' to remember the category field width.")
  5456. (defvar org-prefix-category-max-length nil
  5457. "Used by `org-compile-prefix-format' to remember the category field width.")
  5458. (defun org-agenda-get-category-icon (category)
  5459. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5460. (dolist (entry org-agenda-category-icon-alist)
  5461. (when (org-string-match-p (car entry) category)
  5462. (if (listp (cadr entry))
  5463. (return (cadr entry))
  5464. (return (apply 'create-image (cdr entry)))))))
  5465. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5466. remove-re habitp)
  5467. "Format TXT to be inserted into the agenda buffer.
  5468. In particular, it adds the prefix and corresponding text properties. EXTRA
  5469. must be a string and replaces the `%s' specifier in the prefix format.
  5470. CATEGORY (string, symbol or nil) may be used to overrule the default
  5471. category taken from local variable or file name. It will replace the `%c'
  5472. specifier in the format. DOTIME, when non-nil, indicates that a
  5473. time-of-day should be extracted from TXT for sorting of this entry, and for
  5474. the `%t' specifier in the format. When DOTIME is a string, this string is
  5475. searched for a time before TXT is. TAGS can be the tags of the headline.
  5476. Any match of REMOVE-RE will be removed from TXT."
  5477. ;; We keep the org-prefix-* variable values along with a compiled
  5478. ;; formatter, so that multiple agendas existing at the same time, do
  5479. ;; not step on each other toes.
  5480. ;;
  5481. ;; It was inconvenient to make these variables buffer local in
  5482. ;; Agenda buffers, because this function expects to be called with
  5483. ;; the buffer where item comes from being current, and not agenda
  5484. ;; buffer
  5485. (let* ((bindings (car org-prefix-format-compiled))
  5486. (formatter (cadr org-prefix-format-compiled)))
  5487. (loop for (var value) in bindings
  5488. do (set var value))
  5489. (save-match-data
  5490. ;; Diary entries sometimes have extra whitespace at the beginning
  5491. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5492. ;; Fix the tags part in txt
  5493. (setq txt (org-agenda-fix-displayed-tags
  5494. txt tags
  5495. org-agenda-show-inherited-tags
  5496. org-agenda-hide-tags-regexp))
  5497. (let* ((category (or category
  5498. (if (stringp org-category)
  5499. org-category
  5500. (and org-category (symbol-name org-category)))
  5501. (if buffer-file-name
  5502. (file-name-sans-extension
  5503. (file-name-nondirectory buffer-file-name))
  5504. "")))
  5505. (category-icon (org-agenda-get-category-icon category))
  5506. (category-icon (if category-icon
  5507. (propertize " " 'display category-icon)
  5508. ""))
  5509. ;; time, tag, effort are needed for the eval of the prefix format
  5510. (tag (if tags (nth (1- (length tags)) tags) ""))
  5511. time effort neffort
  5512. (ts (if dotime (concat
  5513. (if (stringp dotime) dotime "")
  5514. (and org-agenda-search-headline-for-time txt))))
  5515. (time-of-day (and dotime (org-get-time-of-day ts)))
  5516. stamp plain s0 s1 s2 rtn srp l
  5517. duration thecategory)
  5518. (and (derived-mode-p 'org-mode) buffer-file-name
  5519. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5520. (when (and dotime time-of-day)
  5521. ;; Extract starting and ending time and move them to prefix
  5522. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5523. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5524. (setq s0 (match-string 0 ts)
  5525. srp (and stamp (match-end 3))
  5526. s1 (match-string (if plain 1 2) ts)
  5527. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5528. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5529. ;; them, we might want to remove them there to avoid duplication.
  5530. ;; The user can turn this off with a variable.
  5531. (if (and org-prefix-has-time
  5532. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5533. (string-match (concat (regexp-quote s0) " *") txt)
  5534. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5535. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5536. (= (match-beginning 0) 0)
  5537. t))
  5538. (setq txt (replace-match "" nil nil txt))))
  5539. ;; Normalize the time(s) to 24 hour
  5540. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5541. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5542. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5543. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5544. (setq s2
  5545. (org-minutes-to-hh:mm-string
  5546. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5547. ;; Compute the duration
  5548. (when s2
  5549. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5550. (org-hh:mm-string-to-minutes s1)))))
  5551. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5552. txt)
  5553. ;; Tags are in the string
  5554. (if (or (eq org-agenda-remove-tags t)
  5555. (and org-agenda-remove-tags
  5556. org-prefix-has-tag))
  5557. (setq txt (replace-match "" t t txt))
  5558. (setq txt (replace-match
  5559. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5560. (match-string 2 txt))
  5561. t t txt))))
  5562. (when (derived-mode-p 'org-mode)
  5563. (setq effort
  5564. (condition-case nil
  5565. (org-get-effort
  5566. (or (get-text-property 0 'org-hd-marker txt)
  5567. (get-text-property 0 'org-marker txt)))
  5568. (error nil)))
  5569. (when effort
  5570. (setq neffort (org-duration-string-to-minutes effort)
  5571. effort (setq effort (concat "[" effort "]")))))
  5572. ;; prevent erroring out with %e format when there is no effort
  5573. (or effort (setq effort ""))
  5574. (when remove-re
  5575. (while (string-match remove-re txt)
  5576. (setq txt (replace-match "" t t txt))))
  5577. ;; Set org-heading property on `txt' to mark the start of the
  5578. ;; heading.
  5579. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5580. ;; Prepare the variables needed in the eval of the compiled format
  5581. (setq time (cond (s2 (concat
  5582. (org-agenda-time-of-day-to-ampm-maybe s1)
  5583. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5584. (if org-agenda-timegrid-use-ampm " ")))
  5585. (s1 (concat
  5586. (org-agenda-time-of-day-to-ampm-maybe s1)
  5587. (if org-agenda-timegrid-use-ampm
  5588. "........ "
  5589. "......")))
  5590. (t ""))
  5591. extra (or (and (not habitp) extra) "")
  5592. category (if (symbolp category) (symbol-name category) category)
  5593. thecategory (copy-sequence category))
  5594. (if (string-match org-bracket-link-regexp category)
  5595. (progn
  5596. (setq l (if (match-end 3)
  5597. (- (match-end 3) (match-beginning 3))
  5598. (- (match-end 1) (match-beginning 1))))
  5599. (when (< l (or org-prefix-category-length 0))
  5600. (setq category (copy-sequence category))
  5601. (org-add-props category nil
  5602. 'extra-space (make-string
  5603. (- org-prefix-category-length l 1) ?\ ))))
  5604. (if (and org-prefix-category-max-length
  5605. (>= (length category) org-prefix-category-max-length))
  5606. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5607. ;; Evaluate the compiled format
  5608. (setq rtn (concat (eval formatter) txt))
  5609. ;; And finally add the text properties
  5610. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5611. (org-add-props rtn nil
  5612. 'org-category (if thecategory (downcase thecategory) category)
  5613. 'tags (mapcar 'org-downcase-keep-props tags)
  5614. 'org-highest-priority org-highest-priority
  5615. 'org-lowest-priority org-lowest-priority
  5616. 'time-of-day time-of-day
  5617. 'duration duration
  5618. 'effort effort
  5619. 'effort-minutes neffort
  5620. 'txt txt
  5621. 'time time
  5622. 'extra extra
  5623. 'format org-prefix-format-compiled
  5624. 'dotime dotime)))))
  5625. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5626. "Remove tags string from TXT, and add a modified list of tags.
  5627. The modified list may contain inherited tags, and tags matched by
  5628. `org-agenda-hide-tags-regexp' will be removed."
  5629. (when (or add-inherited hide-re)
  5630. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5631. (setq txt (substring txt 0 (match-beginning 0))))
  5632. (setq tags
  5633. (delq nil
  5634. (mapcar (lambda (tg)
  5635. (if (or (and hide-re (string-match hide-re tg))
  5636. (and (not add-inherited)
  5637. (get-text-property 0 'inherited tg)))
  5638. nil
  5639. tg))
  5640. tags)))
  5641. (when tags
  5642. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5643. i)
  5644. (setq txt (concat txt " :"
  5645. (mapconcat
  5646. (lambda (x)
  5647. (setq i (get-text-property 0 'inherited x))
  5648. (if (and have-i (not i))
  5649. (progn
  5650. (setq have-i nil)
  5651. (concat ":" x))
  5652. x))
  5653. tags ":")
  5654. (if have-i "::" ":"))))))
  5655. txt)
  5656. (defun org-downcase-keep-props (s)
  5657. (let ((props (text-properties-at 0 s)))
  5658. (setq s (downcase s))
  5659. (add-text-properties 0 (length s) props s)
  5660. s))
  5661. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5662. (defvar org-agenda-sorting-strategy-selected nil)
  5663. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5664. (catch 'exit
  5665. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5666. ((and todayp (member 'today (car org-agenda-time-grid))))
  5667. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5668. ((member 'weekly (car org-agenda-time-grid)))
  5669. (t (throw 'exit list)))
  5670. (let* ((have (delq nil (mapcar
  5671. (lambda (x) (get-text-property 1 'time-of-day x))
  5672. list)))
  5673. (string (nth 1 org-agenda-time-grid))
  5674. (gridtimes (nth 2 org-agenda-time-grid))
  5675. (req (car org-agenda-time-grid))
  5676. (remove (member 'remove-match req))
  5677. new time)
  5678. (if (and (member 'require-timed req) (not have))
  5679. ;; don't show empty grid
  5680. (throw 'exit list))
  5681. (while (setq time (pop gridtimes))
  5682. (unless (and remove (member time have))
  5683. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5684. (push (org-agenda-format-item
  5685. nil string "" nil
  5686. (concat (substring time 0 -2) ":" (substring time -2)))
  5687. new)
  5688. (put-text-property
  5689. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5690. (when (and todayp org-agenda-show-current-time-in-grid)
  5691. (push (org-agenda-format-item
  5692. nil
  5693. org-agenda-current-time-string
  5694. "" nil
  5695. (format-time-string "%H:%M "))
  5696. new)
  5697. (put-text-property
  5698. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5699. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5700. (append new list)
  5701. (append list new)))))
  5702. (defun org-compile-prefix-format (key)
  5703. "Compile the prefix format into a Lisp form that can be evaluated.
  5704. The resulting form and associated variable bindings is returned
  5705. and stored in the variable `org-prefix-format-compiled'."
  5706. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5707. org-prefix-category-length nil
  5708. org-prefix-has-effort nil)
  5709. (let ((s (cond
  5710. ((stringp org-agenda-prefix-format)
  5711. org-agenda-prefix-format)
  5712. ((assq key org-agenda-prefix-format)
  5713. (cdr (assq key org-agenda-prefix-format)))
  5714. (t " %-12:c%?-12t% s")))
  5715. (start 0)
  5716. varform vars var e c f opt)
  5717. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5718. s start)
  5719. (setq var (or (cdr (assoc (match-string 4 s)
  5720. '(("c" . category) ("t" . time) ("s" . extra)
  5721. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5722. 'eval)
  5723. c (or (match-string 3 s) "")
  5724. opt (match-beginning 1)
  5725. start (1+ (match-beginning 0)))
  5726. (if (equal var 'time) (setq org-prefix-has-time t))
  5727. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5728. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5729. (setq f (concat "%" (match-string 2 s) "s"))
  5730. (when (equal var 'category)
  5731. (setq org-prefix-category-length
  5732. (floor (abs (string-to-number (match-string 2 s)))))
  5733. (setq org-prefix-category-max-length
  5734. (let ((x (match-string 2 s)))
  5735. (save-match-data
  5736. (if (string-match "\\.[0-9]+" x)
  5737. (string-to-number (substring (match-string 0 x) 1)))))))
  5738. (if (eq var 'eval)
  5739. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5740. (if opt
  5741. (setq varform
  5742. `(if (equal "" ,var)
  5743. ""
  5744. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5745. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5746. (setq s (replace-match "%s" t nil s))
  5747. (push varform vars))
  5748. (setq vars (nreverse vars))
  5749. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5750. (setq org-prefix-format-compiled
  5751. (list
  5752. `((org-prefix-has-time ,org-prefix-has-time)
  5753. (org-prefix-has-tag ,org-prefix-has-tag)
  5754. (org-prefix-category-length ,org-prefix-category-length)
  5755. (org-prefix-has-effort ,org-prefix-has-effort))
  5756. `(format ,s ,@vars))))))
  5757. (defun org-set-sorting-strategy (key)
  5758. (if (symbolp (car org-agenda-sorting-strategy))
  5759. ;; the old format
  5760. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5761. (setq org-agenda-sorting-strategy-selected
  5762. (or (cdr (assq key org-agenda-sorting-strategy))
  5763. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5764. '(time-up category-keep priority-down)))))
  5765. (defun org-get-time-of-day (s &optional string mod24)
  5766. "Check string S for a time of day.
  5767. If found, return it as a military time number between 0 and 2400.
  5768. If not found, return nil.
  5769. The optional STRING argument forces conversion into a 5 character wide string
  5770. HH:MM."
  5771. (save-match-data
  5772. (when
  5773. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5774. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5775. (let* ((h (string-to-number (match-string 1 s)))
  5776. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5777. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5778. (am-p (equal ampm "am"))
  5779. (h1 (cond ((not ampm) h)
  5780. ((= h 12) (if am-p 0 12))
  5781. (t (+ h (if am-p 0 12)))))
  5782. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5783. (mod h1 24) h1))
  5784. (t0 (+ (* 100 h2) m))
  5785. (t1 (concat (if (>= h1 24) "+" " ")
  5786. (if (and org-agenda-time-leading-zero
  5787. (< t0 1000)) "0" "")
  5788. (if (< t0 100) "0" "")
  5789. (if (< t0 10) "0" "")
  5790. (int-to-string t0))))
  5791. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5792. (defvar org-agenda-before-sorting-filter-function nil
  5793. "Function to be applied to agenda items prior to sorting.
  5794. Prior to sorting also means just before they are inserted into the agenda.
  5795. To aid sorting, you may revisit the original entries and add more text
  5796. properties which will later be used by the sorting functions.
  5797. The function should take a string argument, an agenda line.
  5798. It has access to the text properties in that line, which contain among
  5799. other things, the property `org-hd-marker' that points to the entry
  5800. where the line comes from. Note that not all lines going into the agenda
  5801. have this property, only most.
  5802. The function should return the modified string. It is probably best
  5803. to ONLY change text properties.
  5804. You can also use this function as a filter, by returning nil for lines
  5805. you don't want to have in the agenda at all. For this application, you
  5806. could bind the variable in the options section of a custom command.")
  5807. (defun org-agenda-finalize-entries (list &optional nosort)
  5808. "Sort and concatenate the agenda items."
  5809. (setq list (mapcar 'org-agenda-highlight-todo list))
  5810. (if nosort
  5811. list
  5812. (when org-agenda-before-sorting-filter-function
  5813. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5814. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5815. (defun org-agenda-highlight-todo (x)
  5816. (let ((org-done-keywords org-done-keywords-for-agenda)
  5817. (case-fold-search nil)
  5818. re)
  5819. (if (eq x 'line)
  5820. (save-excursion
  5821. (beginning-of-line 1)
  5822. (setq re (org-get-at-bol 'org-todo-regexp))
  5823. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5824. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5825. (add-text-properties (match-beginning 0) (match-end 1)
  5826. (list 'face (org-get-todo-face 1)))
  5827. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5828. (delete-region (match-beginning 1) (1- (match-end 0)))
  5829. (goto-char (match-beginning 1))
  5830. (insert (format org-agenda-todo-keyword-format s)))))
  5831. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5832. (setq re (get-text-property 0 'org-todo-regexp x))
  5833. (when (and re
  5834. ;; Test `pl' because if there's no heading content,
  5835. ;; there's no point matching to highlight. Note
  5836. ;; that if we didn't test `pl' first, and there
  5837. ;; happened to be no keyword from `org-todo-regexp'
  5838. ;; on this heading line, then the `equal' comparison
  5839. ;; afterwards would spuriously succeed in the case
  5840. ;; where `pl' is nil -- causing an args-out-of-range
  5841. ;; error when we try to add text properties to text
  5842. ;; that isn't there.
  5843. pl
  5844. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5845. x pl) pl))
  5846. (add-text-properties
  5847. (or (match-end 1) (match-end 0)) (match-end 0)
  5848. (list 'face (org-get-todo-face (match-string 2 x)))
  5849. x)
  5850. (when (match-end 1)
  5851. (setq x (concat (substring x 0 (match-end 1))
  5852. (format org-agenda-todo-keyword-format
  5853. (match-string 2 x))
  5854. (org-add-props " " (text-properties-at 0 x))
  5855. (substring x (match-end 3)))))))
  5856. x)))
  5857. (defsubst org-cmp-priority (a b)
  5858. "Compare the priorities of string A and B."
  5859. (let ((pa (or (get-text-property 1 'priority a) 0))
  5860. (pb (or (get-text-property 1 'priority b) 0)))
  5861. (cond ((> pa pb) +1)
  5862. ((< pa pb) -1))))
  5863. (defsubst org-cmp-effort (a b)
  5864. "Compare the effort values of string A and B."
  5865. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5866. (ea (or (get-text-property 1 'effort-minutes a) def))
  5867. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5868. (cond ((> ea eb) +1)
  5869. ((< ea eb) -1))))
  5870. (defsubst org-cmp-category (a b)
  5871. "Compare the string values of categories of strings A and B."
  5872. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5873. (cb (or (get-text-property 1 'org-category b) "")))
  5874. (cond ((string-lessp ca cb) -1)
  5875. ((string-lessp cb ca) +1))))
  5876. (defsubst org-cmp-todo-state (a b)
  5877. "Compare the todo states of strings A and B."
  5878. (let* ((ma (or (get-text-property 1 'org-marker a)
  5879. (get-text-property 1 'org-hd-marker a)))
  5880. (mb (or (get-text-property 1 'org-marker b)
  5881. (get-text-property 1 'org-hd-marker b)))
  5882. (fa (and ma (marker-buffer ma)))
  5883. (fb (and mb (marker-buffer mb)))
  5884. (todo-kwds
  5885. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5886. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5887. (ta (or (get-text-property 1 'todo-state a) ""))
  5888. (tb (or (get-text-property 1 'todo-state b) ""))
  5889. (la (- (length (member ta todo-kwds))))
  5890. (lb (- (length (member tb todo-kwds))))
  5891. (donepa (member ta org-done-keywords-for-agenda))
  5892. (donepb (member tb org-done-keywords-for-agenda)))
  5893. (cond ((and donepa (not donepb)) -1)
  5894. ((and (not donepa) donepb) +1)
  5895. ((< la lb) -1)
  5896. ((< lb la) +1))))
  5897. (defsubst org-cmp-alpha (a b)
  5898. "Compare the headlines, alphabetically."
  5899. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5900. (plb (text-property-any 0 (length b) 'org-heading t b))
  5901. (ta (and pla (substring a pla)))
  5902. (tb (and plb (substring b plb))))
  5903. (when pla
  5904. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5905. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5906. (setq ta (substring ta (match-end 0))))
  5907. (setq ta (downcase ta)))
  5908. (when plb
  5909. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5910. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5911. (setq tb (substring tb (match-end 0))))
  5912. (setq tb (downcase tb)))
  5913. (cond ((not ta) +1)
  5914. ((not tb) -1)
  5915. ((string-lessp ta tb) -1)
  5916. ((string-lessp tb ta) +1))))
  5917. (defsubst org-cmp-tag (a b)
  5918. "Compare the string values of the first tags of A and B."
  5919. (let ((ta (car (last (get-text-property 1 'tags a))))
  5920. (tb (car (last (get-text-property 1 'tags b)))))
  5921. (cond ((not ta) +1)
  5922. ((not tb) -1)
  5923. ((string-lessp ta tb) -1)
  5924. ((string-lessp tb ta) +1))))
  5925. (defsubst org-cmp-time (a b)
  5926. "Compare the time-of-day values of strings A and B."
  5927. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5928. (ta (or (get-text-property 1 'time-of-day a) def))
  5929. (tb (or (get-text-property 1 'time-of-day b) def)))
  5930. (cond ((< ta tb) -1)
  5931. ((< tb ta) +1))))
  5932. (defsubst org-cmp-habit-p (a b)
  5933. "Compare the todo states of strings A and B."
  5934. (let ((ha (get-text-property 1 'org-habit-p a))
  5935. (hb (get-text-property 1 'org-habit-p b)))
  5936. (cond ((and ha (not hb)) -1)
  5937. ((and (not ha) hb) +1))))
  5938. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5939. (defun org-entries-lessp (a b)
  5940. "Predicate for sorting agenda entries."
  5941. ;; The following variables will be used when the form is evaluated.
  5942. ;; So even though the compiler complains, keep them.
  5943. (let* ((ss org-agenda-sorting-strategy-selected)
  5944. (time-up (and (org-em 'time-up 'time-down ss)
  5945. (org-cmp-time a b)))
  5946. (time-down (if time-up (- time-up) nil))
  5947. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5948. (org-cmp-priority a b)))
  5949. (priority-down (if priority-up (- priority-up) nil))
  5950. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5951. (org-cmp-effort a b)))
  5952. (effort-down (if effort-up (- effort-up) nil))
  5953. (category-up (and (or (org-em 'category-up 'category-down ss)
  5954. (memq 'category-keep ss))
  5955. (org-cmp-category a b)))
  5956. (category-down (if category-up (- category-up) nil))
  5957. (category-keep (if category-up +1 nil))
  5958. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5959. (org-cmp-tag a b)))
  5960. (tag-down (if tag-up (- tag-up) nil))
  5961. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5962. (org-cmp-todo-state a b)))
  5963. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5964. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5965. (org-cmp-habit-p a b)))
  5966. (habit-down (if habit-up (- habit-up) nil))
  5967. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5968. (org-cmp-alpha a b)))
  5969. (alpha-down (if alpha-up (- alpha-up) nil))
  5970. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5971. user-defined-up user-defined-down)
  5972. (if (and need-user-cmp org-agenda-cmp-user-defined
  5973. (functionp org-agenda-cmp-user-defined))
  5974. (setq user-defined-up
  5975. (funcall org-agenda-cmp-user-defined a b)
  5976. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5977. (cdr (assoc
  5978. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5979. '((-1 . t) (1 . nil) (nil . nil))))))
  5980. ;;; Agenda restriction lock
  5981. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5982. "Overlay to mark the headline to which agenda commands are restricted.")
  5983. (overlay-put org-agenda-restriction-lock-overlay
  5984. 'face 'org-agenda-restriction-lock)
  5985. (overlay-put org-agenda-restriction-lock-overlay
  5986. 'help-echo "Agendas are currently limited to this subtree.")
  5987. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5988. (defun org-agenda-set-restriction-lock (&optional type)
  5989. "Set restriction lock for agenda, to current subtree or file.
  5990. Restriction will be the file if TYPE is `file', or if type is the
  5991. universal prefix '(4), or if the cursor is before the first headline
  5992. in the file. Otherwise, restriction will be to the current subtree."
  5993. (interactive "P")
  5994. (and (equal type '(4)) (setq type 'file))
  5995. (setq type (cond
  5996. (type type)
  5997. ((org-at-heading-p) 'subtree)
  5998. ((condition-case nil (org-back-to-heading t) (error nil))
  5999. 'subtree)
  6000. (t 'file)))
  6001. (if (eq type 'subtree)
  6002. (progn
  6003. (setq org-agenda-restrict t)
  6004. (setq org-agenda-overriding-restriction 'subtree)
  6005. (put 'org-agenda-files 'org-restrict
  6006. (list (buffer-file-name (buffer-base-buffer))))
  6007. (org-back-to-heading t)
  6008. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6009. (move-marker org-agenda-restrict-begin (point))
  6010. (move-marker org-agenda-restrict-end
  6011. (save-excursion (org-end-of-subtree t)))
  6012. (message "Locking agenda restriction to subtree"))
  6013. (put 'org-agenda-files 'org-restrict
  6014. (list (buffer-file-name (buffer-base-buffer))))
  6015. (setq org-agenda-restrict nil)
  6016. (setq org-agenda-overriding-restriction 'file)
  6017. (move-marker org-agenda-restrict-begin nil)
  6018. (move-marker org-agenda-restrict-end nil)
  6019. (message "Locking agenda restriction to file"))
  6020. (setq current-prefix-arg nil)
  6021. (org-agenda-maybe-redo))
  6022. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6023. "Remove the agenda restriction lock."
  6024. (interactive "P")
  6025. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6026. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6027. (setq org-agenda-overriding-restriction nil)
  6028. (setq org-agenda-restrict nil)
  6029. (put 'org-agenda-files 'org-restrict nil)
  6030. (move-marker org-agenda-restrict-begin nil)
  6031. (move-marker org-agenda-restrict-end nil)
  6032. (setq current-prefix-arg nil)
  6033. (message "Agenda restriction lock removed")
  6034. (or noupdate (org-agenda-maybe-redo)))
  6035. (defun org-agenda-maybe-redo ()
  6036. "If there is any window showing the agenda view, update it."
  6037. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6038. (w0 (selected-window)))
  6039. (when w
  6040. (select-window w)
  6041. (org-agenda-redo)
  6042. (select-window w0)
  6043. (if org-agenda-overriding-restriction
  6044. (message "Agenda view shifted to new %s restriction"
  6045. org-agenda-overriding-restriction)
  6046. (message "Agenda restriction lock removed")))))
  6047. ;;; Agenda commands
  6048. (defun org-agenda-check-type (error &rest types)
  6049. "Check if agenda buffer is of allowed type.
  6050. If ERROR is non-nil, throw an error, otherwise just return nil."
  6051. (if (not org-agenda-type)
  6052. (error "No Org agenda currently displayed")
  6053. (if (memq org-agenda-type types)
  6054. t
  6055. (if error
  6056. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6057. nil))))
  6058. (defun org-agenda-Quit (&optional arg)
  6059. "Exit agenda by removing the window or the buffer."
  6060. (interactive)
  6061. (if org-agenda-columns-active
  6062. (org-columns-quit)
  6063. (let ((buf (current-buffer)))
  6064. (if (eq org-agenda-window-setup 'other-frame)
  6065. (progn
  6066. (org-agenda-reset-markers)
  6067. (kill-buffer buf)
  6068. (org-columns-remove-overlays)
  6069. (setq org-agenda-archives-mode nil)
  6070. (delete-frame))
  6071. (and (not (eq org-agenda-window-setup 'current-window))
  6072. (not (one-window-p))
  6073. (delete-window))
  6074. (org-agenda-reset-markers)
  6075. (kill-buffer buf)
  6076. (org-columns-remove-overlays)
  6077. (setq org-agenda-archives-mode nil)))
  6078. ;; Maybe restore the pre-agenda window configuration.
  6079. (and org-agenda-restore-windows-after-quit
  6080. (not (eq org-agenda-window-setup 'other-frame))
  6081. org-agenda-pre-window-conf
  6082. (set-window-configuration org-agenda-pre-window-conf)
  6083. (setq org-agenda-pre-window-conf nil))))
  6084. (defun org-agenda-quit ()
  6085. "Exit agenda by killing agenda buffer or burying it when
  6086. `org-agenda-sticky' is non-NIL"
  6087. (interactive)
  6088. (if org-agenda-columns-active
  6089. (org-columns-quit)
  6090. (if org-agenda-sticky
  6091. (let ((buf (current-buffer)))
  6092. (if (eq org-agenda-window-setup 'other-frame)
  6093. (progn
  6094. (delete-frame))
  6095. (and (not (eq org-agenda-window-setup 'current-window))
  6096. (not (one-window-p))
  6097. (delete-window)))
  6098. (with-current-buffer buf
  6099. (bury-buffer)
  6100. ;; Maybe restore the pre-agenda window configuration.
  6101. (and org-agenda-restore-windows-after-quit
  6102. (not (eq org-agenda-window-setup 'other-frame))
  6103. org-agenda-pre-window-conf
  6104. (set-window-configuration org-agenda-pre-window-conf)
  6105. (setq org-agenda-pre-window-conf nil))))
  6106. (org-agenda-Quit))))
  6107. (defun org-agenda-exit ()
  6108. "Exit agenda by removing the window or the buffer.
  6109. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6110. Org-mode buffers visited directly by the user will not be touched."
  6111. (interactive)
  6112. (org-release-buffers org-agenda-new-buffers)
  6113. (setq org-agenda-new-buffers nil)
  6114. (org-agenda-Quit))
  6115. (defun org-agenda-kill-all-agenda-buffers ()
  6116. "Kill all buffers in `org-agena-mode'.
  6117. This is used when toggling sticky agendas. You can also explicitly invoke it
  6118. with `C-c a C-k'."
  6119. (interactive)
  6120. (let (blist)
  6121. (dolist (buf (buffer-list))
  6122. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6123. (push buf blist)))
  6124. (mapc 'kill-buffer blist)))
  6125. (defun org-agenda-execute (arg)
  6126. "Execute another agenda command, keeping same window.
  6127. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6128. in the agenda."
  6129. (interactive "P")
  6130. (let ((org-agenda-window-setup 'current-window))
  6131. (org-agenda arg)))
  6132. (defun org-agenda-redo (&optional all)
  6133. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6134. (interactive "P")
  6135. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6136. (cpa (unless (eq all t) current-prefix-arg))
  6137. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6138. (org-agenda-sticky nil)
  6139. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6140. org-agenda-buffer-name))
  6141. (org-agenda-keep-modes t)
  6142. (tag-filter org-agenda-tag-filter)
  6143. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6144. (top-cat-filter org-agenda-top-category-filter)
  6145. (cat-filter org-agenda-category-filter)
  6146. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6147. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6148. (cols org-agenda-columns-active)
  6149. (line (org-current-line))
  6150. (window-line (- line (org-current-line (window-start))))
  6151. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6152. (redo-cmd (get-text-property p 'org-redo-cmd))
  6153. (last-args (get-text-property p 'org-last-args))
  6154. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6155. (org-agenda-overriding-cmd-arguments
  6156. (unless (eq all t)
  6157. (cond ((listp last-args)
  6158. (cons (or cpa (car last-args)) (cdr last-args)))
  6159. ((stringp last-args)
  6160. last-args))))
  6161. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6162. (put 'org-agenda-tag-filter :preset-filter nil)
  6163. (put 'org-agenda-category-filter :preset-filter nil)
  6164. (and cols (org-columns-quit))
  6165. (message "Rebuilding agenda buffer...")
  6166. (if serie-redo-cmd
  6167. (eval serie-redo-cmd)
  6168. (org-let lprops '(eval redo-cmd)))
  6169. (setq org-agenda-undo-list nil
  6170. org-agenda-pending-undo-list nil)
  6171. (message "Rebuilding agenda buffer...done")
  6172. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6173. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6174. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6175. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6176. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6177. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6178. (org-goto-line line)
  6179. (recenter window-line)))
  6180. (defvar org-global-tags-completion-table nil)
  6181. (defvar org-agenda-filter-form nil)
  6182. (defvar org-agenda-filtered-by-category nil)
  6183. (defun org-agenda-filter-by-category (strip)
  6184. "Keep only those lines in the agenda buffer that have a specific category.
  6185. The category is that of the current line."
  6186. (interactive "P")
  6187. (if (and org-agenda-filtered-by-category
  6188. org-agenda-category-filter)
  6189. (org-agenda-filter-show-all-cat)
  6190. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6191. (if cat (org-agenda-filter-apply
  6192. (list (concat (if strip "-" "+") cat)) 'category)
  6193. (error "No category at point")))))
  6194. (defun org-find-top-category (&optional pos)
  6195. (save-excursion
  6196. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6197. (if pos (goto-char pos))
  6198. ;; Skip up to the topmost parent
  6199. (while (ignore-errors (outline-up-heading 1) t))
  6200. (ignore-errors
  6201. (nth 4 (org-heading-components))))))
  6202. (defvar org-agenda-filtered-by-top-category nil)
  6203. (defun org-agenda-filter-by-top-category (strip)
  6204. "Keep only those lines in the agenda buffer that have a specific category.
  6205. The category is that of the current line."
  6206. (interactive "P")
  6207. (if org-agenda-filtered-by-top-category
  6208. (progn
  6209. (setq org-agenda-filtered-by-top-category nil
  6210. org-agenda-top-category-filter nil)
  6211. (org-agenda-filter-show-all-cat))
  6212. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6213. (if cat (org-agenda-filter-top-category-apply cat strip)
  6214. (error "No top-level category at point")))))
  6215. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6216. "Keep only those lines in the agenda buffer that have a specific tag.
  6217. The tag is selected with its fast selection letter, as configured.
  6218. With prefix argument STRIP, remove all lines that do have the tag.
  6219. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6220. used to narrow the search - the interactive user can also press `-' or `+'
  6221. to switch to narrowing."
  6222. (interactive "P")
  6223. (let* ((alist org-tag-alist-for-agenda)
  6224. (tag-chars (mapconcat
  6225. (lambda (x) (if (and (not (symbolp (car x)))
  6226. (cdr x))
  6227. (char-to-string (cdr x))
  6228. ""))
  6229. alist ""))
  6230. (efforts (org-split-string
  6231. (or (cdr (assoc (concat org-effort-property "_ALL")
  6232. org-global-properties))
  6233. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6234. "")))
  6235. (effort-op org-agenda-filter-effort-default-operator)
  6236. (effort-prompt "")
  6237. (inhibit-read-only t)
  6238. (current org-agenda-tag-filter)
  6239. maybe-refresh a n tag)
  6240. (unless char
  6241. (message
  6242. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6243. (if narrow "Narrow" "Filter") tag-chars
  6244. (if org-agenda-auto-exclude-function "[RET], " ""))
  6245. (setq char (read-char-exclusive)))
  6246. (when (member char '(?+ ?-))
  6247. ;; Narrowing down
  6248. (cond ((equal char ?-) (setq strip t narrow t))
  6249. ((equal char ?+) (setq strip nil narrow t)))
  6250. (message
  6251. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6252. (setq char (read-char-exclusive)))
  6253. (when (member char '(?< ?> ?= ??))
  6254. ;; An effort operator
  6255. (setq effort-op (char-to-string char))
  6256. (setq alist nil) ; to make sure it will be interpreted as effort.
  6257. (unless (equal char ??)
  6258. (loop for i from 0 to 9 do
  6259. (setq effort-prompt
  6260. (concat
  6261. effort-prompt " ["
  6262. (if (= i 9) "0" (int-to-string (1+ i)))
  6263. "]" (nth i efforts))))
  6264. (message "Effort%s: %s " effort-op effort-prompt)
  6265. (setq char (read-char-exclusive))
  6266. (when (or (< char ?0) (> char ?9))
  6267. (error "Need 1-9,0 to select effort"))))
  6268. (when (equal char ?\t)
  6269. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6270. (org-set-local 'org-global-tags-completion-table
  6271. (org-global-tags-completion-table)))
  6272. (let ((completion-ignore-case t))
  6273. (setq tag (org-icompleting-read
  6274. "Tag: " org-global-tags-completion-table))))
  6275. (cond
  6276. ((equal char ?\r)
  6277. (org-agenda-filter-show-all-tag)
  6278. (when org-agenda-auto-exclude-function
  6279. (setq org-agenda-tag-filter '())
  6280. (dolist (tag (org-agenda-get-represented-tags))
  6281. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6282. (if modifier
  6283. (push modifier org-agenda-tag-filter))))
  6284. (if (not (null org-agenda-tag-filter))
  6285. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6286. (setq maybe-refresh t))
  6287. ((equal char ?/)
  6288. (org-agenda-filter-show-all-tag)
  6289. (when (get 'org-agenda-tag-filter :preset-filter)
  6290. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6291. (setq maybe-refresh t))
  6292. ((equal char ?. )
  6293. (setq org-agenda-tag-filter
  6294. (mapcar (lambda(tag) (concat "+" tag))
  6295. (org-get-at-bol 'tags)))
  6296. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6297. (setq maybe-refresh t))
  6298. ((or (equal char ?\ )
  6299. (setq a (rassoc char alist))
  6300. (and (>= char ?0) (<= char ?9)
  6301. (setq n (if (= char ?0) 9 (- char ?0 1))
  6302. tag (concat effort-op (nth n efforts))
  6303. a (cons tag nil)))
  6304. (and (= char ??)
  6305. (setq tag "?eff")
  6306. a (cons tag nil))
  6307. (and tag (setq a (cons tag nil))))
  6308. (org-agenda-filter-show-all-tag)
  6309. (setq tag (car a))
  6310. (setq org-agenda-tag-filter
  6311. (cons (concat (if strip "-" "+") tag)
  6312. (if narrow current nil)))
  6313. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6314. (setq maybe-refresh t))
  6315. (t (error "Invalid tag selection character %c" char)))
  6316. (when (and maybe-refresh
  6317. (eq org-agenda-clockreport-mode 'with-filter))
  6318. (org-agenda-redo))))
  6319. (defun org-agenda-get-represented-tags ()
  6320. "Get a list of all tags currently represented in the agenda."
  6321. (let (p tags)
  6322. (save-excursion
  6323. (goto-char (point-min))
  6324. (while (setq p (next-single-property-change (point) 'tags))
  6325. (goto-char p)
  6326. (mapc (lambda (x) (add-to-list 'tags x))
  6327. (get-text-property (point) 'tags))))
  6328. tags))
  6329. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6330. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6331. (interactive "P")
  6332. (org-agenda-filter-by-tag strip char 'refine))
  6333. (defun org-agenda-filter-make-matcher ()
  6334. "Create the form that tests a line for agenda filter."
  6335. (let (f f1)
  6336. ;; first compute the tag-filter matcher
  6337. (dolist (x (delete-dups
  6338. (append (get 'org-agenda-tag-filter
  6339. :preset-filter) org-agenda-tag-filter)))
  6340. (if (member x '("-" "+"))
  6341. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6342. (if (string-match "[<=>?]" x)
  6343. (setq f1 (org-agenda-filter-effort-form x))
  6344. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6345. (if (equal (string-to-char x) ?-)
  6346. (setq f1 (list 'not f1))))
  6347. (push f1 f))
  6348. ;; then compute the category-filter matcher
  6349. (dolist (x (delete-dups
  6350. (append (get 'org-agenda-category-filter
  6351. :preset-filter) org-agenda-category-filter)))
  6352. (if (equal "-" (substring x 0 1))
  6353. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6354. (setq f1 (list 'equal (substring x 1) 'cat)))
  6355. (push f1 f))
  6356. (cons 'and (nreverse f))))
  6357. (defun org-agenda-filter-effort-form (e)
  6358. "Return the form to compare the effort of the current line with what E says.
  6359. E looks like \"+<2:25\"."
  6360. (let (op)
  6361. (setq e (substring e 1))
  6362. (setq op (string-to-char e) e (substring e 1))
  6363. (setq op (cond ((equal op ?<) '<=)
  6364. ((equal op ?>) '>=)
  6365. ((equal op ??) op)
  6366. (t '=)))
  6367. (list 'org-agenda-compare-effort (list 'quote op)
  6368. (org-duration-string-to-minutes e))))
  6369. (defun org-agenda-compare-effort (op value)
  6370. "Compare the effort of the current line with VALUE, using OP.
  6371. If the line does not have an effort defined, return nil."
  6372. (let ((eff (org-get-at-bol 'effort-minutes)))
  6373. (if (equal op ??)
  6374. (not eff)
  6375. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6376. value))))
  6377. (defun org-agenda-filter-apply (filter type)
  6378. "Set FILTER as the new agenda filter and apply it."
  6379. (let (tags cat)
  6380. (if (eq type 'tag)
  6381. (setq org-agenda-tag-filter filter)
  6382. (setq org-agenda-category-filter filter))
  6383. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6384. (if (and (eq type 'category)
  6385. (not (equal (substring (car filter) 0 1) "-")))
  6386. ;; Only set `org-agenda-filtered-by-category' to t
  6387. ;; when a unique category is used as the filter
  6388. (setq org-agenda-filtered-by-category t))
  6389. (org-agenda-set-mode-name)
  6390. (save-excursion
  6391. (goto-char (point-min))
  6392. (while (not (eobp))
  6393. (if (org-get-at-bol 'org-marker)
  6394. (progn
  6395. (setq tags (org-get-at-bol 'tags) ; used in eval
  6396. cat (get-text-property (point) 'org-category))
  6397. (if (not (eval org-agenda-filter-form))
  6398. (org-agenda-filter-hide-line type))
  6399. (beginning-of-line 2))
  6400. (beginning-of-line 2))))
  6401. (if (get-char-property (point) 'invisible)
  6402. (ignore-errors (org-agenda-previous-line)))))
  6403. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6404. "Set FILTER as the new agenda filter and apply it."
  6405. (org-agenda-set-mode-name)
  6406. (save-excursion
  6407. (goto-char (point-min))
  6408. (while (not (eobp))
  6409. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6410. (topcat (and pos (org-find-top-category pos))))
  6411. (if (and topcat (funcall (if negative 'identity 'not)
  6412. (string= category topcat)))
  6413. (org-agenda-filter-hide-line 'category)))
  6414. (beginning-of-line 2)))
  6415. (if (get-char-property (point) 'invisible)
  6416. (org-agenda-previous-line))
  6417. (setq org-agenda-top-category-filter category
  6418. org-agenda-filtered-by-top-category t))
  6419. (defun org-agenda-filter-hide-line (type)
  6420. (let (ov)
  6421. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6422. (point-at-eol)))
  6423. (overlay-put ov 'invisible t)
  6424. (overlay-put ov 'type type)
  6425. (if (eq type 'tag)
  6426. (push ov org-agenda-tag-filter-overlays)
  6427. (push ov org-agenda-cat-filter-overlays))))
  6428. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6429. (setq pos (or pos (point)))
  6430. (save-excursion
  6431. (dolist (ov (overlays-at pos))
  6432. (when (and (overlay-get ov 'invisible)
  6433. (eq (overlay-get ov 'type) 'tag))
  6434. (goto-char pos)
  6435. (if (< (overlay-start ov) (point-at-eol))
  6436. (move-overlay ov (point-at-eol)
  6437. (overlay-end ov)))))))
  6438. (defun org-agenda-filter-show-all-tag nil
  6439. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6440. (setq org-agenda-tag-filter-overlays nil
  6441. org-agenda-tag-filter nil
  6442. org-agenda-filter-form nil)
  6443. (org-agenda-set-mode-name))
  6444. (defun org-agenda-filter-show-all-cat nil
  6445. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6446. (setq org-agenda-cat-filter-overlays nil
  6447. org-agenda-filtered-by-category nil
  6448. org-agenda-category-filter nil
  6449. org-agenda-filter-form nil)
  6450. (org-agenda-set-mode-name))
  6451. (defun org-agenda-manipulate-query-add ()
  6452. "Manipulate the query by adding a search term with positive selection.
  6453. Positive selection means the term must be matched for selection of an entry."
  6454. (interactive)
  6455. (org-agenda-manipulate-query ?\[))
  6456. (defun org-agenda-manipulate-query-subtract ()
  6457. "Manipulate the query by adding a search term with negative selection.
  6458. Negative selection means term must not be matched for selection of an entry."
  6459. (interactive)
  6460. (org-agenda-manipulate-query ?\]))
  6461. (defun org-agenda-manipulate-query-add-re ()
  6462. "Manipulate the query by adding a search regexp with positive selection.
  6463. Positive selection means the regexp must match for selection of an entry."
  6464. (interactive)
  6465. (org-agenda-manipulate-query ?\{))
  6466. (defun org-agenda-manipulate-query-subtract-re ()
  6467. "Manipulate the query by adding a search regexp with negative selection.
  6468. Negative selection means regexp must not match for selection of an entry."
  6469. (interactive)
  6470. (org-agenda-manipulate-query ?\}))
  6471. (defun org-agenda-manipulate-query (char)
  6472. (cond
  6473. ((memq org-agenda-type '(timeline agenda))
  6474. (let ((org-agenda-include-inactive-timestamps t))
  6475. (org-agenda-redo))
  6476. (message "Display now includes inactive timestamps as well"))
  6477. ((eq org-agenda-type 'search)
  6478. (org-add-to-string
  6479. 'org-agenda-query-string
  6480. (if org-agenda-last-search-view-search-was-boolean
  6481. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6482. (?\{ . " +{}") (?\} . " -{}"))))
  6483. " "))
  6484. (setq org-agenda-redo-command
  6485. (list 'org-search-view
  6486. (car (get-text-property (min (1- (point-max)) (point))
  6487. 'org-last-args))
  6488. org-agenda-query-string
  6489. (+ (length org-agenda-query-string)
  6490. (if (member char '(?\{ ?\})) 0 1))))
  6491. (set-register org-agenda-query-register org-agenda-query-string)
  6492. (let ((org-agenda-overriding-arguments
  6493. (cdr org-agenda-redo-command)))
  6494. (org-agenda-redo)))
  6495. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6496. org-agenda-type))))
  6497. (defun org-add-to-string (var string)
  6498. (set var (concat (symbol-value var) string)))
  6499. (defun org-agenda-goto-date (span)
  6500. "Jump to DATE in agenda."
  6501. (interactive "P")
  6502. (let* ((org-read-date-prefer-future
  6503. (eval org-agenda-jump-prefer-future))
  6504. (date (org-read-date))
  6505. (org-agenda-sticky-orig org-agenda-sticky)
  6506. (org-agenda-buffer-tmp-name (buffer-name))
  6507. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6508. (0-arg (or current-prefix-arg (car args)))
  6509. (2-arg (nth 2 args))
  6510. (newcmd (list 'org-agenda-list 0-arg date
  6511. (org-agenda-span-to-ndays 2-arg)))
  6512. (newargs (cdr newcmd))
  6513. (inhibit-read-only t)
  6514. org-agenda-sticky)
  6515. (if (not (org-agenda-check-type t 'agenda))
  6516. (error "Not available in non-agenda blocks")
  6517. (add-text-properties (point-min) (point-max)
  6518. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6519. (org-agenda-redo)
  6520. (setq org-agenda-sticky org-agenda-sticky-orig
  6521. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6522. (defun org-agenda-goto-today ()
  6523. "Go to today."
  6524. (interactive)
  6525. (org-agenda-check-type t 'timeline 'agenda)
  6526. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6527. (curspan (nth 2 args))
  6528. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6529. (cond
  6530. (tdpos (goto-char tdpos))
  6531. ((eq org-agenda-type 'agenda)
  6532. (let* ((sd (org-agenda-compute-starting-span
  6533. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6534. (org-agenda-overriding-arguments args))
  6535. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6536. (org-agenda-redo)
  6537. (org-agenda-find-same-or-today-or-agenda)))
  6538. (t (error "Cannot find today")))))
  6539. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6540. (goto-char
  6541. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6542. (text-property-any (point-min) (point-max) 'org-today t)
  6543. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6544. (and (get-text-property (min (1- (point-max)) (point)) 'org-serie)
  6545. (org-agenda-goto-block-beginning))
  6546. (point-min))))
  6547. (defun org-agenda-goto-block-beginning ()
  6548. "Go the agenda block beginning."
  6549. (interactive)
  6550. (if (not (derived-mode-p 'org-agenda-mode))
  6551. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6552. (let (dest)
  6553. (save-excursion
  6554. (unless (looking-at "\\'")
  6555. (forward-char))
  6556. (let* ((prop 'org-agenda-structural-header)
  6557. (p (previous-single-property-change (point) prop))
  6558. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6559. (1- (point))) prop)))
  6560. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6561. (if (not dest)
  6562. (error "Cannot find the beginning of the blog")
  6563. (goto-char dest)
  6564. (move-beginning-of-line 1)))))
  6565. (defun org-agenda-later (arg)
  6566. "Go forward in time by thee current span.
  6567. With prefix ARG, go forward that many times the current span."
  6568. (interactive "p")
  6569. (org-agenda-check-type t 'agenda)
  6570. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6571. (span (or (nth 2 args) org-agenda-current-span))
  6572. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6573. (greg (calendar-gregorian-from-absolute sd))
  6574. (cnt (org-get-at-bol 'org-day-cnt))
  6575. greg2)
  6576. (cond
  6577. ((numberp span)
  6578. (setq sd (+ span sd)))
  6579. ((eq span 'day)
  6580. (setq sd (+ arg sd)))
  6581. ((eq span 'week)
  6582. (setq sd (+ (* 7 arg) sd)))
  6583. ((eq span 'month)
  6584. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6585. sd (calendar-absolute-from-gregorian greg2))
  6586. (setcar greg2 (1+ (car greg2))))
  6587. ((eq span 'year)
  6588. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6589. sd (calendar-absolute-from-gregorian greg2))
  6590. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6591. (t
  6592. (setq sd (+ (* span arg) sd))))
  6593. (let ((org-agenda-overriding-cmd
  6594. ;; `cmd' may have been set by `org-agenda-run-series' which
  6595. ;; uses `org-agenda-overriding-cmd' to decide whether
  6596. ;; overriding is allowed for `cmd'
  6597. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6598. (org-agenda-overriding-arguments
  6599. (list (car args) sd span)))
  6600. (org-agenda-redo)
  6601. (org-agenda-find-same-or-today-or-agenda cnt))))
  6602. (defun org-agenda-earlier (arg)
  6603. "Go backward in time by the current span.
  6604. With prefix ARG, go backward that many times the current span."
  6605. (interactive "p")
  6606. (org-agenda-later (- arg)))
  6607. (defun org-agenda-view-mode-dispatch ()
  6608. "Call one of the view mode commands."
  6609. (interactive)
  6610. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6611. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6612. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6613. (let ((a (read-char-exclusive)))
  6614. (case a
  6615. (?\ (call-interactively 'org-agenda-reset-view))
  6616. (?d (call-interactively 'org-agenda-day-view))
  6617. (?w (call-interactively 'org-agenda-week-view))
  6618. (?m (call-interactively 'org-agenda-month-view))
  6619. (?y (call-interactively 'org-agenda-year-view))
  6620. (?l (call-interactively 'org-agenda-log-mode))
  6621. (?L (org-agenda-log-mode '(4)))
  6622. (?c (org-agenda-log-mode 'clockcheck))
  6623. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6624. (?a (call-interactively 'org-agenda-archives-mode))
  6625. (?A (org-agenda-archives-mode 'files))
  6626. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6627. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6628. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6629. (?D (call-interactively 'org-agenda-toggle-diary))
  6630. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6631. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6632. (org-agenda-check-type t 'timeline 'agenda)
  6633. (org-agenda-redo))
  6634. (message "Display now includes inactive timestamps as well"))
  6635. (?q (message "Abort"))
  6636. (otherwise (error "Invalid key" )))))
  6637. (defun org-agenda-reset-view ()
  6638. "Switch to default view for agenda."
  6639. (interactive)
  6640. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6641. (defun org-agenda-day-view (&optional day-of-year)
  6642. "Switch to daily view for agenda.
  6643. With argument DAY-OF-YEAR, switch to that day of the year."
  6644. (interactive "P")
  6645. (org-agenda-change-time-span 'day day-of-year))
  6646. (defun org-agenda-week-view (&optional iso-week)
  6647. "Switch to daily view for agenda.
  6648. With argument ISO-WEEK, switch to the corresponding ISO week.
  6649. If ISO-WEEK has more then 2 digits, only the last two encode the
  6650. week. Any digits before this encode a year. So 200712 means
  6651. week 12 of year 2007. Years in the range 1938-2037 can also be
  6652. written as 2-digit years."
  6653. (interactive "P")
  6654. (org-agenda-change-time-span 'week iso-week))
  6655. (defun org-agenda-month-view (&optional month)
  6656. "Switch to monthly view for agenda.
  6657. With argument MONTH, switch to that month."
  6658. (interactive "P")
  6659. (org-agenda-change-time-span 'month month))
  6660. (defun org-agenda-year-view (&optional year)
  6661. "Switch to yearly view for agenda.
  6662. With argument YEAR, switch to that year.
  6663. If MONTH has more then 2 digits, only the last two encode the
  6664. month. Any digits before this encode a year. So 200712 means
  6665. December year 2007. Years in the range 1938-2037 can also be
  6666. written as 2-digit years."
  6667. (interactive "P")
  6668. (when year
  6669. (setq year (org-small-year-to-year year)))
  6670. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6671. (org-agenda-change-time-span 'year year)
  6672. (error "Abort")))
  6673. (defun org-agenda-change-time-span (span &optional n)
  6674. "Change the agenda view to SPAN.
  6675. SPAN may be `day', `week', `month', `year'."
  6676. (org-agenda-check-type t 'agenda)
  6677. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6678. (curspan (nth 2 args)))
  6679. (if (and (not n) (equal curspan span))
  6680. (error "Viewing span is already \"%s\"" span))
  6681. (let* ((sd (or (org-get-at-bol 'day)
  6682. (nth 1 args)
  6683. org-starting-day))
  6684. (sd (org-agenda-compute-starting-span sd span n))
  6685. (org-agenda-overriding-cmd
  6686. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6687. (org-agenda-overriding-arguments
  6688. (list (car args) sd span)))
  6689. (org-agenda-redo)
  6690. (org-agenda-find-same-or-today-or-agenda))
  6691. (org-agenda-set-mode-name)
  6692. (message "Switched to %s view" span)))
  6693. (defun org-agenda-compute-starting-span (sd span &optional n)
  6694. "Compute starting date for agenda.
  6695. SPAN may be `day', `week', `month', `year'. The return value
  6696. is a cons cell with the starting date and the number of days,
  6697. so that the date SD will be in that range."
  6698. (let* ((greg (calendar-gregorian-from-absolute sd))
  6699. (dg (nth 1 greg))
  6700. (mg (car greg))
  6701. (yg (nth 2 greg)))
  6702. (cond
  6703. ((eq span 'day)
  6704. (when n
  6705. (setq sd (+ (calendar-absolute-from-gregorian
  6706. (list mg 1 yg))
  6707. n -1))))
  6708. ((eq span 'week)
  6709. (let* ((nt (calendar-day-of-week
  6710. (calendar-gregorian-from-absolute sd)))
  6711. (d (if org-agenda-start-on-weekday
  6712. (- nt org-agenda-start-on-weekday)
  6713. 0))
  6714. y1)
  6715. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6716. (when n
  6717. (require 'cal-iso)
  6718. (when (> n 99)
  6719. (setq y1 (org-small-year-to-year (/ n 100))
  6720. n (mod n 100)))
  6721. (setq sd
  6722. (calendar-absolute-from-iso
  6723. (list n 1
  6724. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6725. ((eq span 'month)
  6726. (let (y1)
  6727. (when (and n (> n 99))
  6728. (setq y1 (org-small-year-to-year (/ n 100))
  6729. n (mod n 100)))
  6730. (setq sd (calendar-absolute-from-gregorian
  6731. (list (or n mg) 1 (or y1 yg))))))
  6732. ((eq span 'year)
  6733. (setq sd (calendar-absolute-from-gregorian
  6734. (list 1 1 (or n yg))))))
  6735. sd))
  6736. (defun org-agenda-next-date-line (&optional arg)
  6737. "Jump to the next line indicating a date in agenda buffer."
  6738. (interactive "p")
  6739. (org-agenda-check-type t 'agenda 'timeline)
  6740. (beginning-of-line 1)
  6741. ;; This does not work if user makes date format that starts with a blank
  6742. (if (looking-at "^\\S-") (forward-char 1))
  6743. (if (not (re-search-forward "^\\S-" nil t arg))
  6744. (progn
  6745. (backward-char 1)
  6746. (error "No next date after this line in this buffer")))
  6747. (goto-char (match-beginning 0)))
  6748. (defun org-agenda-previous-date-line (&optional arg)
  6749. "Jump to the previous line indicating a date in agenda buffer."
  6750. (interactive "p")
  6751. (org-agenda-check-type t 'agenda 'timeline)
  6752. (beginning-of-line 1)
  6753. (if (not (re-search-backward "^\\S-" nil t arg))
  6754. (error "No previous date before this line in this buffer")))
  6755. ;; Initialize the highlight
  6756. (defvar org-hl (make-overlay 1 1))
  6757. (overlay-put org-hl 'face 'highlight)
  6758. (defun org-highlight (begin end &optional buffer)
  6759. "Highlight a region with overlay."
  6760. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6761. (defun org-unhighlight ()
  6762. "Detach overlay INDEX."
  6763. (org-detach-overlay org-hl))
  6764. (defun org-unhighlight-once ()
  6765. "Remove the highlight from its position, and this function from the hook."
  6766. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6767. (org-unhighlight))
  6768. (defun org-agenda-follow-mode ()
  6769. "Toggle follow mode in an agenda buffer."
  6770. (interactive)
  6771. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6772. (org-agenda-set-mode-name)
  6773. (org-agenda-do-context-action)
  6774. (message "Follow mode is %s"
  6775. (if org-agenda-follow-mode "on" "off")))
  6776. (defun org-agenda-entry-text-mode (&optional arg)
  6777. "Toggle entry text mode in an agenda buffer."
  6778. (interactive "P")
  6779. (setq org-agenda-entry-text-mode (or (integerp arg)
  6780. (not org-agenda-entry-text-mode)))
  6781. (org-agenda-entry-text-hide)
  6782. (and org-agenda-entry-text-mode
  6783. (let ((org-agenda-entry-text-maxlines
  6784. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6785. (org-agenda-entry-text-show)))
  6786. (org-agenda-set-mode-name)
  6787. (message "Entry text mode is %s. Maximum number of lines is %d"
  6788. (if org-agenda-entry-text-mode "on" "off")
  6789. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6790. (defun org-agenda-clockreport-mode (&optional with-filter)
  6791. "Toggle clocktable mode in an agenda buffer.
  6792. With prefix arg WITH-FILTER, make the clocktable respect the current
  6793. agenda filter."
  6794. (interactive "P")
  6795. (org-agenda-check-type t 'agenda)
  6796. (if with-filter
  6797. (setq org-agenda-clockreport-mode 'with-filter)
  6798. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6799. (org-agenda-set-mode-name)
  6800. (org-agenda-redo)
  6801. (message "Clocktable mode is %s"
  6802. (if org-agenda-clockreport-mode "on" "off")))
  6803. (defun org-agenda-log-mode (&optional special)
  6804. "Toggle log mode in an agenda buffer.
  6805. With argument SPECIAL, show all possible log items, not only the ones
  6806. configured in `org-agenda-log-mode-items'.
  6807. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6808. (interactive "P")
  6809. (org-agenda-check-type t 'agenda 'timeline)
  6810. (setq org-agenda-show-log
  6811. (cond
  6812. ((equal special '(16)) 'only)
  6813. ((eq special 'clockcheck)
  6814. (if (eq org-agenda-show-log 'clockcheck)
  6815. nil 'clockcheck))
  6816. (special '(closed clock state))
  6817. (t (not org-agenda-show-log))))
  6818. (org-agenda-set-mode-name)
  6819. (org-agenda-redo)
  6820. (message "Log mode is %s"
  6821. (if org-agenda-show-log "on" "off")))
  6822. (defun org-agenda-archives-mode (&optional with-files)
  6823. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6824. When called with a prefix argument, include all archive files as well."
  6825. (interactive "P")
  6826. (setq org-agenda-archives-mode
  6827. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6828. (org-agenda-set-mode-name)
  6829. (org-agenda-redo)
  6830. (message
  6831. "%s"
  6832. (cond
  6833. ((eq org-agenda-archives-mode nil)
  6834. "No archives are included")
  6835. ((eq org-agenda-archives-mode 'trees)
  6836. (format "Trees with :%s: tag are included" org-archive-tag))
  6837. ((eq org-agenda-archives-mode t)
  6838. (format "Trees with :%s: tag and all active archive files are included"
  6839. org-archive-tag)))))
  6840. (defun org-agenda-toggle-diary ()
  6841. "Toggle diary inclusion in an agenda buffer."
  6842. (interactive)
  6843. (org-agenda-check-type t 'agenda)
  6844. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6845. (org-agenda-redo)
  6846. (org-agenda-set-mode-name)
  6847. (message "Diary inclusion turned %s"
  6848. (if org-agenda-include-diary "on" "off")))
  6849. (defun org-agenda-toggle-deadlines ()
  6850. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6851. (interactive)
  6852. (org-agenda-check-type t 'agenda)
  6853. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6854. (org-agenda-redo)
  6855. (org-agenda-set-mode-name)
  6856. (message "Deadlines inclusion turned %s"
  6857. (if org-agenda-include-deadlines "on" "off")))
  6858. (defun org-agenda-toggle-time-grid ()
  6859. "Toggle time grid in an agenda buffer."
  6860. (interactive)
  6861. (org-agenda-check-type t 'agenda)
  6862. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6863. (org-agenda-redo)
  6864. (org-agenda-set-mode-name)
  6865. (message "Time-grid turned %s"
  6866. (if org-agenda-use-time-grid "on" "off")))
  6867. (defun org-agenda-set-mode-name ()
  6868. "Set the mode name to indicate all the small mode settings."
  6869. (setq mode-name
  6870. (list "Org-Agenda"
  6871. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6872. " "
  6873. '(:eval (org-agenda-span-name org-agenda-current-span))
  6874. (if org-agenda-follow-mode " Follow" "")
  6875. (if org-agenda-entry-text-mode " ETxt" "")
  6876. (if org-agenda-include-diary " Diary" "")
  6877. (if org-agenda-include-deadlines " Ddl" "")
  6878. (if org-agenda-use-time-grid " Grid" "")
  6879. (if (and (boundp 'org-habit-show-habits)
  6880. org-habit-show-habits) " Habit" "")
  6881. (cond
  6882. ((consp org-agenda-show-log) " LogAll")
  6883. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6884. (org-agenda-show-log " Log")
  6885. (t ""))
  6886. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6887. :preset-filter))
  6888. '(:eval (org-propertize
  6889. (concat " <"
  6890. (mapconcat
  6891. 'identity
  6892. (append
  6893. (get 'org-agenda-category-filter :preset-filter)
  6894. org-agenda-category-filter)
  6895. "")
  6896. ">")
  6897. 'face 'org-agenda-filter-category
  6898. 'help-echo "Category used in filtering"))
  6899. "")
  6900. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6901. :preset-filter))
  6902. '(:eval (org-propertize
  6903. (concat " {"
  6904. (mapconcat
  6905. 'identity
  6906. (append
  6907. (get 'org-agenda-tag-filter :preset-filter)
  6908. org-agenda-tag-filter)
  6909. "")
  6910. "}")
  6911. 'face 'org-agenda-filter-tags
  6912. 'help-echo "Tags used in filtering"))
  6913. "")
  6914. (if org-agenda-archives-mode
  6915. (if (eq org-agenda-archives-mode t)
  6916. " Archives"
  6917. (format " :%s:" org-archive-tag))
  6918. "")
  6919. (if org-agenda-clockreport-mode
  6920. (if (eq org-agenda-clockreport-mode 'with-filter)
  6921. " Clock{}" " Clock")
  6922. "")))
  6923. (force-mode-line-update))
  6924. (define-obsolete-function-alias
  6925. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  6926. (defun org-agenda-update-agenda-type ()
  6927. "Update the agenda type after each command."
  6928. (setq org-agenda-type
  6929. (or (get-text-property (point) 'org-agenda-type)
  6930. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  6931. (defun org-agenda-next-line ()
  6932. "Move cursor to the next line, and show if follow mode is active."
  6933. (interactive)
  6934. (call-interactively 'next-line)
  6935. (org-agenda-do-context-action))
  6936. (defun org-agenda-previous-line ()
  6937. "Move cursor to the previous line, and show if follow-mode is active."
  6938. (interactive)
  6939. (call-interactively 'previous-line)
  6940. (org-agenda-do-context-action))
  6941. (defun org-agenda-next-item (n)
  6942. "Move cursor to next agenda item."
  6943. (interactive "p")
  6944. (let ((col (current-column)))
  6945. (dotimes (c n)
  6946. (when (next-single-property-change (point-at-eol) 'org-marker)
  6947. (move-end-of-line 1)
  6948. (goto-char (next-single-property-change (point) 'org-marker))))
  6949. (org-move-to-column col))
  6950. (org-agenda-do-context-action))
  6951. (defun org-agenda-previous-item (n)
  6952. "Move cursor to next agenda item."
  6953. (interactive "p")
  6954. (dotimes (c n)
  6955. (let ((col (current-column))
  6956. (goto (save-excursion
  6957. (move-end-of-line 0)
  6958. (previous-single-property-change (point) 'org-marker))))
  6959. (if goto (goto-char goto))
  6960. (org-move-to-column col)))
  6961. (org-agenda-do-context-action))
  6962. (defun org-agenda-do-context-action ()
  6963. "Show outline path and, maybe, follow mode window."
  6964. (let ((m (org-get-at-bol 'org-marker)))
  6965. (when (and (markerp m) (marker-buffer m))
  6966. (and org-agenda-follow-mode
  6967. (if org-agenda-follow-indirect
  6968. (org-agenda-tree-to-indirect-buffer nil)
  6969. (org-agenda-show)))
  6970. (and org-agenda-show-outline-path
  6971. (org-with-point-at m (org-display-outline-path t))))))
  6972. (defun org-agenda-show-tags ()
  6973. "Show the tags applicable to the current item."
  6974. (interactive)
  6975. (let* ((tags (org-get-at-bol 'tags)))
  6976. (if tags
  6977. (message "Tags are :%s:"
  6978. (org-no-properties (mapconcat 'identity tags ":")))
  6979. (message "No tags associated with this line"))))
  6980. (defun org-agenda-goto (&optional highlight)
  6981. "Go to the Org-mode file which contains the item at point."
  6982. (interactive)
  6983. (let* ((marker (or (org-get-at-bol 'org-marker)
  6984. (org-agenda-error)))
  6985. (buffer (marker-buffer marker))
  6986. (pos (marker-position marker)))
  6987. (switch-to-buffer-other-window buffer)
  6988. (widen)
  6989. (push-mark)
  6990. (goto-char pos)
  6991. (when (derived-mode-p 'org-mode)
  6992. (org-show-context 'agenda)
  6993. (save-excursion
  6994. (and (outline-next-heading)
  6995. (org-flag-heading nil)))) ; show the next heading
  6996. (when (outline-invisible-p)
  6997. (show-entry)) ; display invisible text
  6998. (recenter (/ (window-height) 2))
  6999. (run-hooks 'org-agenda-after-show-hook)
  7000. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7001. (defvar org-agenda-after-show-hook nil
  7002. "Normal hook run after an item has been shown from the agenda.
  7003. Point is in the buffer where the item originated.")
  7004. (defun org-agenda-kill ()
  7005. "Kill the entry or subtree belonging to the current agenda entry."
  7006. (interactive)
  7007. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7008. (let* ((bufname-orig (buffer-name))
  7009. (marker (or (org-get-at-bol 'org-marker)
  7010. (org-agenda-error)))
  7011. (buffer (marker-buffer marker))
  7012. (pos (marker-position marker))
  7013. (type (org-get-at-bol 'type))
  7014. dbeg dend (n 0) conf)
  7015. (org-with-remote-undo buffer
  7016. (with-current-buffer buffer
  7017. (save-excursion
  7018. (goto-char pos)
  7019. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7020. (setq dbeg (progn (org-back-to-heading t) (point))
  7021. dend (org-end-of-subtree t t))
  7022. (setq dbeg (point-at-bol)
  7023. dend (min (point-max) (1+ (point-at-eol)))))
  7024. (goto-char dbeg)
  7025. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7026. (setq conf (or (eq t org-agenda-confirm-kill)
  7027. (and (numberp org-agenda-confirm-kill)
  7028. (> n org-agenda-confirm-kill))))
  7029. (and conf
  7030. (not (y-or-n-p
  7031. (format "Delete entry with %d lines in buffer \"%s\"? "
  7032. n (buffer-name buffer))))
  7033. (error "Abort"))
  7034. (let ((org-agenda-buffer-name bufname-orig))
  7035. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7036. (with-current-buffer buffer (delete-region dbeg dend))
  7037. (message "Agenda item and source killed"))))
  7038. (defvar org-archive-default-command) ; defined in org-archive.el
  7039. (defun org-agenda-archive-default ()
  7040. "Archive the entry or subtree belonging to the current agenda entry."
  7041. (interactive)
  7042. (require 'org-archive)
  7043. (org-agenda-archive-with org-archive-default-command))
  7044. (defun org-agenda-archive-default-with-confirmation ()
  7045. "Archive the entry or subtree belonging to the current agenda entry."
  7046. (interactive)
  7047. (require 'org-archive)
  7048. (org-agenda-archive-with org-archive-default-command 'confirm))
  7049. (defun org-agenda-archive ()
  7050. "Archive the entry or subtree belonging to the current agenda entry."
  7051. (interactive)
  7052. (org-agenda-archive-with 'org-archive-subtree))
  7053. (defun org-agenda-archive-to-archive-sibling ()
  7054. "Move the entry to the archive sibling."
  7055. (interactive)
  7056. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7057. (defun org-agenda-archive-with (cmd &optional confirm)
  7058. "Move the entry to the archive sibling."
  7059. (interactive)
  7060. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7061. (let* ((bufname-orig (buffer-name))
  7062. (marker (or (org-get-at-bol 'org-marker)
  7063. (org-agenda-error)))
  7064. (buffer (marker-buffer marker))
  7065. (pos (marker-position marker)))
  7066. (org-with-remote-undo buffer
  7067. (with-current-buffer buffer
  7068. (if (derived-mode-p 'org-mode)
  7069. (if (and confirm
  7070. (not (y-or-n-p "Archive this subtree or entry? ")))
  7071. (error "Abort")
  7072. (save-excursion
  7073. (goto-char pos)
  7074. (let ((org-agenda-buffer-name bufname-orig))
  7075. (org-remove-subtree-entries-from-agenda))
  7076. (org-back-to-heading t)
  7077. (funcall cmd)))
  7078. (error "Archiving works only in Org-mode files"))))))
  7079. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7080. "Remove all lines in the agenda that correspond to a given subtree.
  7081. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7082. If this information is not given, the function uses the tree at point."
  7083. (let ((buf (or buf (current-buffer))) m p)
  7084. (save-excursion
  7085. (unless (and beg end)
  7086. (org-back-to-heading t)
  7087. (setq beg (point))
  7088. (org-end-of-subtree t)
  7089. (setq end (point)))
  7090. (set-buffer (get-buffer org-agenda-buffer-name))
  7091. (save-excursion
  7092. (goto-char (point-max))
  7093. (beginning-of-line 1)
  7094. (while (not (bobp))
  7095. (when (and (setq m (org-get-at-bol 'org-marker))
  7096. (equal buf (marker-buffer m))
  7097. (setq p (marker-position m))
  7098. (>= p beg)
  7099. (< p end))
  7100. (let ((inhibit-read-only t))
  7101. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7102. (beginning-of-line 0))))))
  7103. (defun org-agenda-refile (&optional goto rfloc no-update)
  7104. "Refile the item at point."
  7105. (interactive "P")
  7106. (if (equal goto '(16))
  7107. (org-refile-goto-last-stored)
  7108. (let* ((buffer-orig (buffer-name))
  7109. (marker (or (org-get-at-bol 'org-hd-marker)
  7110. (org-agenda-error)))
  7111. (buffer (marker-buffer marker))
  7112. (pos (marker-position marker))
  7113. (rfloc (or rfloc
  7114. (org-refile-get-location
  7115. (if goto "Goto" "Refile to") buffer
  7116. org-refile-allow-creating-parent-nodes))))
  7117. (with-current-buffer buffer
  7118. (save-excursion
  7119. (save-restriction
  7120. (widen)
  7121. (goto-char marker)
  7122. (let ((org-agenda-buffer-name buffer-orig))
  7123. (org-remove-subtree-entries-from-agenda))
  7124. (org-refile goto buffer rfloc)))))
  7125. (unless no-update (org-agenda-redo))))
  7126. (defun org-agenda-open-link (&optional arg)
  7127. "Follow the link in the current line, if any.
  7128. This looks for a link in the displayed line in the agenda. It also looks
  7129. at the text of the entry itself."
  7130. (interactive "P")
  7131. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7132. (org-get-at-bol 'org-marker)))
  7133. (buffer (and marker (marker-buffer marker)))
  7134. (prefix (buffer-substring
  7135. (point-at-bol) (point-at-eol))))
  7136. (cond
  7137. (buffer
  7138. (with-current-buffer buffer
  7139. (save-excursion
  7140. (save-restriction
  7141. (widen)
  7142. (goto-char marker)
  7143. (org-offer-links-in-entry arg prefix)))))
  7144. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7145. (save-excursion
  7146. (beginning-of-line 1)
  7147. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7148. (org-open-link-from-string (match-string 1)))
  7149. (t (error "No link to open here")))))
  7150. (defun org-agenda-copy-local-variable (var)
  7151. "Get a variable from a referenced buffer and install it here."
  7152. (let ((m (org-get-at-bol 'org-marker)))
  7153. (when (and m (buffer-live-p (marker-buffer m)))
  7154. (org-set-local var (with-current-buffer (marker-buffer m)
  7155. (symbol-value var))))))
  7156. (defun org-agenda-switch-to (&optional delete-other-windows)
  7157. "Go to the Org-mode file which contains the item at point."
  7158. (interactive)
  7159. (if (and org-return-follows-link
  7160. (not (org-get-at-bol 'org-marker))
  7161. (org-in-regexp org-bracket-link-regexp))
  7162. (org-open-link-from-string (match-string 0))
  7163. (let* ((marker (or (org-get-at-bol 'org-marker)
  7164. (org-agenda-error)))
  7165. (buffer (marker-buffer marker))
  7166. (pos (marker-position marker)))
  7167. (org-pop-to-buffer-same-window buffer)
  7168. (and delete-other-windows (delete-other-windows))
  7169. (widen)
  7170. (goto-char pos)
  7171. (when (derived-mode-p 'org-mode)
  7172. (org-show-context 'agenda)
  7173. (save-excursion
  7174. (and (outline-next-heading)
  7175. (org-flag-heading nil))) ; show the next heading
  7176. (when (outline-invisible-p)
  7177. (show-entry)) ; display invisible text
  7178. (run-hooks 'org-agenda-after-show-hook)))))
  7179. (defun org-agenda-goto-mouse (ev)
  7180. "Go to the Org-mode file which contains the item at the mouse click."
  7181. (interactive "e")
  7182. (mouse-set-point ev)
  7183. (org-agenda-goto))
  7184. (defun org-agenda-show (&optional full-entry)
  7185. "Display the Org-mode file which contains the item at point.
  7186. With prefix argument FULL-ENTRY, make the entire entry visible
  7187. if it was hidden in the outline."
  7188. (interactive "P")
  7189. (let ((win (selected-window)))
  7190. (if full-entry
  7191. (let ((org-show-entry-below t))
  7192. (org-agenda-goto t))
  7193. (org-agenda-goto t))
  7194. (select-window win)))
  7195. (defvar org-agenda-show-window nil)
  7196. (defun org-agenda-show-and-scroll-up (&optional arg)
  7197. "Display the Org-mode file which contains the item at point.
  7198. When called repeatedly, scroll the window that is displaying the buffer.
  7199. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7200. `show-subtree' to display the item, so that drawers and logbooks stay
  7201. folded."
  7202. (interactive "P")
  7203. (let ((win (selected-window)))
  7204. (if (and (window-live-p org-agenda-show-window)
  7205. (eq this-command last-command))
  7206. (progn
  7207. (select-window org-agenda-show-window)
  7208. (ignore-errors (scroll-up)))
  7209. (org-agenda-goto t)
  7210. (if arg (org-show-entry) (show-subtree))
  7211. (setq org-agenda-show-window (selected-window)))
  7212. (select-window win)))
  7213. (defun org-agenda-show-scroll-down ()
  7214. "Scroll down the window showing the agenda."
  7215. (interactive)
  7216. (let ((win (selected-window)))
  7217. (when (window-live-p org-agenda-show-window)
  7218. (select-window org-agenda-show-window)
  7219. (ignore-errors (scroll-down))
  7220. (select-window win))))
  7221. (defun org-agenda-show-1 (&optional more)
  7222. "Display the Org-mode file which contains the item at point.
  7223. The prefix arg selects the amount of information to display:
  7224. 0 hide the subtree
  7225. 1 just show the entry according to defaults.
  7226. 2 show the children view
  7227. 3 show the subtree view
  7228. 4 show the entire subtree and any LOGBOOK drawers
  7229. 5 show the entire subtree and any drawers
  7230. With prefix argument FULL-ENTRY, make the entire entry visible
  7231. if it was hidden in the outline."
  7232. (interactive "p")
  7233. (let ((win (selected-window)))
  7234. (org-agenda-goto t)
  7235. (org-recenter-heading 1)
  7236. (cond
  7237. ((= more 0)
  7238. (hide-subtree)
  7239. (save-excursion
  7240. (org-back-to-heading)
  7241. (run-hook-with-args 'org-cycle-hook 'folded))
  7242. (message "Remote: FOLDED"))
  7243. ((and (org-called-interactively-p 'any) (= more 1))
  7244. (message "Remote: show with default settings"))
  7245. ((= more 2)
  7246. (show-entry)
  7247. (show-children)
  7248. (save-excursion
  7249. (org-back-to-heading)
  7250. (run-hook-with-args 'org-cycle-hook 'children))
  7251. (message "Remote: CHILDREN"))
  7252. ((= more 3)
  7253. (show-subtree)
  7254. (save-excursion
  7255. (org-back-to-heading)
  7256. (run-hook-with-args 'org-cycle-hook 'subtree))
  7257. (message "Remote: SUBTREE"))
  7258. ((= more 4)
  7259. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7260. (org-drawer-regexp
  7261. (concat "^[ \t]*:\\("
  7262. (mapconcat 'regexp-quote org-drawers "\\|")
  7263. "\\):[ \t]*$")))
  7264. (show-subtree)
  7265. (save-excursion
  7266. (org-back-to-heading)
  7267. (org-cycle-hide-drawers 'subtree)))
  7268. (message "Remote: SUBTREE AND LOGBOOK"))
  7269. ((> more 4)
  7270. (show-subtree)
  7271. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7272. (select-window win)))
  7273. (defun org-recenter-heading (n)
  7274. (save-excursion
  7275. (org-back-to-heading)
  7276. (recenter n)))
  7277. (defvar org-agenda-cycle-counter nil)
  7278. (defun org-agenda-cycle-show (&optional n)
  7279. "Show the current entry in another window, with default settings.
  7280. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7281. When use repeatedly in immediate succession, the remote entry will cycle
  7282. through visibility
  7283. children -> subtree -> folded
  7284. When called with a numeric prefix arg, that arg will be passed through to
  7285. `org-agenda-show-1'. For the interpretation of that argument, see the
  7286. docstring of `org-agenda-show-1'."
  7287. (interactive "P")
  7288. (if (integerp n)
  7289. (setq org-agenda-cycle-counter n)
  7290. (if (not (eq last-command this-command))
  7291. (setq org-agenda-cycle-counter 1)
  7292. (if (equal org-agenda-cycle-counter 0)
  7293. (setq org-agenda-cycle-counter 2)
  7294. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7295. (if (> org-agenda-cycle-counter 3)
  7296. (setq org-agenda-cycle-counter 0)))))
  7297. (org-agenda-show-1 org-agenda-cycle-counter))
  7298. (defun org-agenda-recenter (arg)
  7299. "Display the Org-mode file which contains the item at point and recenter."
  7300. (interactive "P")
  7301. (let ((win (selected-window)))
  7302. (org-agenda-goto t)
  7303. (recenter arg)
  7304. (select-window win)))
  7305. (defun org-agenda-show-mouse (ev)
  7306. "Display the Org-mode file which contains the item at the mouse click."
  7307. (interactive "e")
  7308. (mouse-set-point ev)
  7309. (org-agenda-show))
  7310. (defun org-agenda-check-no-diary ()
  7311. "Check if the entry is a diary link and abort if yes."
  7312. (if (org-get-at-bol 'org-agenda-diary-link)
  7313. (org-agenda-error)))
  7314. (defun org-agenda-error ()
  7315. (error "Command not allowed in this line"))
  7316. (defun org-agenda-tree-to-indirect-buffer (arg)
  7317. "Show the subtree corresponding to the current entry in an indirect buffer.
  7318. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7319. With a numerical prefix ARG, go up to this level and then take that tree.
  7320. With a negative numeric ARG, go up by this number of levels.
  7321. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7322. use the dedicated frame)."
  7323. (interactive "P")
  7324. (if current-prefix-arg
  7325. (org-agenda-do-tree-to-indirect-buffer arg)
  7326. (let ((agenda-buffer (buffer-name))
  7327. (agenda-window (selected-window))
  7328. (indirect-window
  7329. (and org-last-indirect-buffer
  7330. (get-buffer-window org-last-indirect-buffer))))
  7331. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7332. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7333. (eq org-indirect-buffer-display 'dedicated-frame))
  7334. (unwind-protect
  7335. (progn
  7336. (unless (and indirect-window (window-live-p indirect-window)))
  7337. (setq indirect-window (split-window agenda-window)))
  7338. (and indirect-window (select-window indirect-window))
  7339. (switch-to-buffer org-last-indirect-buffer :norecord)
  7340. (fit-window-to-buffer indirect-window)))
  7341. (select-window (get-buffer-window agenda-buffer)))))
  7342. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7343. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7344. (org-agenda-check-no-diary)
  7345. (let* ((marker (or (org-get-at-bol 'org-marker)
  7346. (org-agenda-error)))
  7347. (buffer (marker-buffer marker))
  7348. (pos (marker-position marker)))
  7349. (with-current-buffer buffer
  7350. (save-excursion
  7351. (goto-char pos)
  7352. (funcall 'org-tree-to-indirect-buffer arg)))))
  7353. (defvar org-last-heading-marker (make-marker)
  7354. "Marker pointing to the headline that last changed its TODO state
  7355. by a remote command from the agenda.")
  7356. (defun org-agenda-todo-nextset ()
  7357. "Switch TODO entry to next sequence."
  7358. (interactive)
  7359. (org-agenda-todo 'nextset))
  7360. (defun org-agenda-todo-previousset ()
  7361. "Switch TODO entry to previous sequence."
  7362. (interactive)
  7363. (org-agenda-todo 'previousset))
  7364. (defun org-agenda-todo (&optional arg)
  7365. "Cycle TODO state of line at point, also in Org-mode file.
  7366. This changes the line at point, all other lines in the agenda referring to
  7367. the same tree node, and the headline of the tree node in the Org-mode file."
  7368. (interactive "P")
  7369. (org-agenda-check-no-diary)
  7370. (let* ((col (current-column))
  7371. (marker (or (org-get-at-bol 'org-marker)
  7372. (org-agenda-error)))
  7373. (buffer (marker-buffer marker))
  7374. (pos (marker-position marker))
  7375. (hdmarker (org-get-at-bol 'org-hd-marker))
  7376. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7377. (inhibit-read-only t)
  7378. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7379. (org-with-remote-undo buffer
  7380. (with-current-buffer buffer
  7381. (widen)
  7382. (goto-char pos)
  7383. (org-show-context 'agenda)
  7384. (save-excursion
  7385. (and (outline-next-heading)
  7386. (org-flag-heading nil))) ; show the next heading
  7387. (let ((current-prefix-arg arg))
  7388. (call-interactively 'org-todo))
  7389. (and (bolp) (forward-char 1))
  7390. (setq newhead (org-get-heading))
  7391. (when (and (org-bound-and-true-p
  7392. org-agenda-headline-snapshot-before-repeat)
  7393. (not (equal org-agenda-headline-snapshot-before-repeat
  7394. newhead))
  7395. todayp)
  7396. (setq newhead org-agenda-headline-snapshot-before-repeat
  7397. just-one t))
  7398. (save-excursion
  7399. (org-back-to-heading)
  7400. (move-marker org-last-heading-marker (point))))
  7401. (beginning-of-line 1)
  7402. (save-excursion
  7403. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7404. (org-move-to-column col))))
  7405. (defun org-agenda-add-note (&optional arg)
  7406. "Add a time-stamped note to the entry at point."
  7407. (interactive "P")
  7408. (org-agenda-check-no-diary)
  7409. (let* ((marker (or (org-get-at-bol 'org-marker)
  7410. (org-agenda-error)))
  7411. (buffer (marker-buffer marker))
  7412. (pos (marker-position marker))
  7413. (hdmarker (org-get-at-bol 'org-hd-marker))
  7414. (inhibit-read-only t))
  7415. (with-current-buffer buffer
  7416. (widen)
  7417. (goto-char pos)
  7418. (org-show-context 'agenda)
  7419. (save-excursion
  7420. (and (outline-next-heading)
  7421. (org-flag-heading nil))) ; show the next heading
  7422. (org-add-note))))
  7423. (defun org-agenda-change-all-lines (newhead hdmarker
  7424. &optional fixface just-this)
  7425. "Change all lines in the agenda buffer which match HDMARKER.
  7426. The new content of the line will be NEWHEAD (as modified by
  7427. `org-agenda-format-item'). HDMARKER is checked with
  7428. `equal' against all `org-hd-marker' text properties in the file.
  7429. If FIXFACE is non-nil, the face of each item is modified according to
  7430. the new TODO state.
  7431. If JUST-THIS is non-nil, change just the current line, not all.
  7432. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7433. (let* ((inhibit-read-only t)
  7434. (line (org-current-line))
  7435. (org-agenda-buffer (current-buffer))
  7436. (thetags (with-current-buffer (marker-buffer hdmarker)
  7437. (save-excursion (save-restriction (widen)
  7438. (goto-char hdmarker)
  7439. (org-get-tags-at)))))
  7440. props m pl undone-face done-face finish new dotime cat tags)
  7441. (save-excursion
  7442. (goto-char (point-max))
  7443. (beginning-of-line 1)
  7444. (while (not finish)
  7445. (setq finish (bobp))
  7446. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7447. (or (not just-this) (= (org-current-line) line))
  7448. (equal m hdmarker))
  7449. (setq props (text-properties-at (point))
  7450. dotime (org-get-at-bol 'dotime)
  7451. cat (org-get-at-bol 'org-category)
  7452. tags thetags
  7453. new
  7454. (let ((org-prefix-format-compiled
  7455. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7456. org-prefix-format-compiled))
  7457. (extra (org-get-at-bol 'extra)))
  7458. (with-current-buffer (marker-buffer hdmarker)
  7459. (save-excursion
  7460. (save-restriction
  7461. (widen)
  7462. (org-agenda-format-item extra newhead cat tags dotime)))))
  7463. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7464. undone-face (org-get-at-bol 'undone-face)
  7465. done-face (org-get-at-bol 'done-face))
  7466. (beginning-of-line 1)
  7467. (cond
  7468. ((equal new "")
  7469. (and (looking-at ".*\n?") (replace-match "")))
  7470. ((looking-at ".*")
  7471. (replace-match new t t)
  7472. (beginning-of-line 1)
  7473. (add-text-properties (point-at-bol) (point-at-eol) props)
  7474. (when fixface
  7475. (add-text-properties
  7476. (point-at-bol) (point-at-eol)
  7477. (list 'face
  7478. (if org-last-todo-state-is-todo
  7479. undone-face done-face))))
  7480. (org-agenda-highlight-todo 'line)
  7481. (beginning-of-line 1))
  7482. (t (error "Line update did not work"))))
  7483. (beginning-of-line 0)))
  7484. (org-agenda-finalize)))
  7485. (defun org-agenda-align-tags (&optional line)
  7486. "Align all tags in agenda items to `org-agenda-tags-column'."
  7487. (let ((inhibit-read-only t) l c)
  7488. (save-excursion
  7489. (goto-char (if line (point-at-bol) (point-min)))
  7490. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7491. (if line (point-at-eol) nil) t)
  7492. (add-text-properties
  7493. (match-beginning 2) (match-end 2)
  7494. (list 'face (delq nil (let ((prop (get-text-property
  7495. (match-beginning 2) 'face)))
  7496. (or (listp prop) (setq prop (list prop)))
  7497. (if (memq 'org-tag prop)
  7498. prop
  7499. (cons 'org-tag prop))))))
  7500. (setq l (- (match-end 2) (match-beginning 2))
  7501. c (if (< org-agenda-tags-column 0)
  7502. (- (abs org-agenda-tags-column) l)
  7503. org-agenda-tags-column))
  7504. (delete-region (match-beginning 1) (match-end 1))
  7505. (goto-char (match-beginning 1))
  7506. (insert (org-add-props
  7507. (make-string (max 1 (- c (current-column))) ?\ )
  7508. (plist-put (copy-sequence (text-properties-at (point)))
  7509. 'face nil))))
  7510. (goto-char (point-min))
  7511. (org-font-lock-add-tag-faces (point-max)))))
  7512. (defun org-agenda-priority-up ()
  7513. "Increase the priority of line at point, also in Org-mode file."
  7514. (interactive)
  7515. (org-agenda-priority 'up))
  7516. (defun org-agenda-priority-down ()
  7517. "Decrease the priority of line at point, also in Org-mode file."
  7518. (interactive)
  7519. (org-agenda-priority 'down))
  7520. (defun org-agenda-priority (&optional force-direction show)
  7521. "Set the priority of line at point, also in Org-mode file.
  7522. This changes the line at point, all other lines in the agenda referring to
  7523. the same tree node, and the headline of the tree node in the Org-mode file."
  7524. (interactive "P")
  7525. (if (equal force-direction '(4)) (setq show t))
  7526. (unless org-enable-priority-commands
  7527. (error "Priority commands are disabled"))
  7528. (org-agenda-check-no-diary)
  7529. (let* ((marker (or (org-get-at-bol 'org-marker)
  7530. (org-agenda-error)))
  7531. (hdmarker (org-get-at-bol 'org-hd-marker))
  7532. (buffer (marker-buffer hdmarker))
  7533. (pos (marker-position hdmarker))
  7534. (inhibit-read-only t)
  7535. newhead)
  7536. (org-with-remote-undo buffer
  7537. (with-current-buffer buffer
  7538. (widen)
  7539. (goto-char pos)
  7540. (org-show-context 'agenda)
  7541. (save-excursion
  7542. (and (outline-next-heading)
  7543. (org-flag-heading nil))) ; show the next heading
  7544. (funcall 'org-priority force-direction show)
  7545. (end-of-line 1)
  7546. (setq newhead (org-get-heading)))
  7547. (org-agenda-change-all-lines newhead hdmarker)
  7548. (beginning-of-line 1))))
  7549. ;; FIXME: should fix the tags property of the agenda line.
  7550. (defun org-agenda-set-tags (&optional tag onoff)
  7551. "Set tags for the current headline."
  7552. (interactive)
  7553. (org-agenda-check-no-diary)
  7554. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7555. (call-interactively 'org-change-tag-in-region)
  7556. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7557. (org-agenda-error)))
  7558. (buffer (marker-buffer hdmarker))
  7559. (pos (marker-position hdmarker))
  7560. (inhibit-read-only t)
  7561. newhead)
  7562. (org-with-remote-undo buffer
  7563. (with-current-buffer buffer
  7564. (widen)
  7565. (goto-char pos)
  7566. (save-excursion
  7567. (org-show-context 'agenda))
  7568. (save-excursion
  7569. (and (outline-next-heading)
  7570. (org-flag-heading nil))) ; show the next heading
  7571. (goto-char pos)
  7572. (if tag
  7573. (org-toggle-tag tag onoff)
  7574. (call-interactively 'org-set-tags))
  7575. (end-of-line 1)
  7576. (setq newhead (org-get-heading)))
  7577. (org-agenda-change-all-lines newhead hdmarker)
  7578. (beginning-of-line 1)))))
  7579. (defun org-agenda-set-property ()
  7580. "Set a property for the current headline."
  7581. (interactive)
  7582. (org-agenda-check-no-diary)
  7583. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7584. (org-agenda-error)))
  7585. (buffer (marker-buffer hdmarker))
  7586. (pos (marker-position hdmarker))
  7587. (inhibit-read-only t)
  7588. newhead)
  7589. (org-with-remote-undo buffer
  7590. (with-current-buffer buffer
  7591. (widen)
  7592. (goto-char pos)
  7593. (save-excursion
  7594. (org-show-context 'agenda))
  7595. (save-excursion
  7596. (and (outline-next-heading)
  7597. (org-flag-heading nil))) ; show the next heading
  7598. (goto-char pos)
  7599. (call-interactively 'org-set-property)))))
  7600. (defun org-agenda-set-effort ()
  7601. "Set the effort property for the current headline."
  7602. (interactive)
  7603. (org-agenda-check-no-diary)
  7604. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7605. (org-agenda-error)))
  7606. (buffer (marker-buffer hdmarker))
  7607. (pos (marker-position hdmarker))
  7608. (inhibit-read-only t)
  7609. newhead)
  7610. (org-with-remote-undo buffer
  7611. (with-current-buffer buffer
  7612. (widen)
  7613. (goto-char pos)
  7614. (save-excursion
  7615. (org-show-context 'agenda))
  7616. (save-excursion
  7617. (and (outline-next-heading)
  7618. (org-flag-heading nil))) ; show the next heading
  7619. (goto-char pos)
  7620. (call-interactively 'org-set-effort)
  7621. (end-of-line 1)
  7622. (setq newhead (org-get-heading)))
  7623. (org-agenda-change-all-lines newhead hdmarker))))
  7624. (defun org-agenda-toggle-archive-tag ()
  7625. "Toggle the archive tag for the current entry."
  7626. (interactive)
  7627. (org-agenda-check-no-diary)
  7628. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7629. (org-agenda-error)))
  7630. (buffer (marker-buffer hdmarker))
  7631. (pos (marker-position hdmarker))
  7632. (inhibit-read-only t)
  7633. newhead)
  7634. (org-with-remote-undo buffer
  7635. (with-current-buffer buffer
  7636. (widen)
  7637. (goto-char pos)
  7638. (org-show-context 'agenda)
  7639. (save-excursion
  7640. (and (outline-next-heading)
  7641. (org-flag-heading nil))) ; show the next heading
  7642. (call-interactively 'org-toggle-archive-tag)
  7643. (end-of-line 1)
  7644. (setq newhead (org-get-heading)))
  7645. (org-agenda-change-all-lines newhead hdmarker)
  7646. (beginning-of-line 1))))
  7647. (defun org-agenda-do-date-later (arg)
  7648. (interactive "P")
  7649. (cond
  7650. ((or (equal arg '(16))
  7651. (memq last-command
  7652. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7653. (setq this-command 'org-agenda-date-later-minutes)
  7654. (org-agenda-date-later-minutes 1))
  7655. ((or (equal arg '(4))
  7656. (memq last-command
  7657. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7658. (setq this-command 'org-agenda-date-later-hours)
  7659. (org-agenda-date-later-hours 1))
  7660. (t
  7661. (org-agenda-date-later (prefix-numeric-value arg)))))
  7662. (defun org-agenda-do-date-earlier (arg)
  7663. (interactive "P")
  7664. (cond
  7665. ((or (equal arg '(16))
  7666. (memq last-command
  7667. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7668. (setq this-command 'org-agenda-date-earlier-minutes)
  7669. (org-agenda-date-earlier-minutes 1))
  7670. ((or (equal arg '(4))
  7671. (memq last-command
  7672. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7673. (setq this-command 'org-agenda-date-earlier-hours)
  7674. (org-agenda-date-earlier-hours 1))
  7675. (t
  7676. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7677. (defun org-agenda-date-later (arg &optional what)
  7678. "Change the date of this item to ARG day(s) later."
  7679. (interactive "p")
  7680. (org-agenda-check-type t 'agenda 'timeline)
  7681. (org-agenda-check-no-diary)
  7682. (let* ((marker (or (org-get-at-bol 'org-marker)
  7683. (org-agenda-error)))
  7684. (buffer (marker-buffer marker))
  7685. (pos (marker-position marker))
  7686. cdate today)
  7687. (org-with-remote-undo buffer
  7688. (with-current-buffer buffer
  7689. (widen)
  7690. (goto-char pos)
  7691. (if (not (org-at-timestamp-p))
  7692. (error "Cannot find time stamp"))
  7693. (when (and org-agenda-move-date-from-past-immediately-to-today
  7694. (equal arg 1)
  7695. (or (not what) (eq what 'day))
  7696. (not (save-match-data (org-at-date-range-p))))
  7697. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7698. cdate (calendar-absolute-from-gregorian
  7699. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7700. today (org-today))
  7701. (if (> today cdate)
  7702. ;; immediately shift to today
  7703. (setq arg (- today cdate))))
  7704. (org-timestamp-change arg (or what 'day))
  7705. (when (and (org-at-date-range-p)
  7706. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7707. (let ((end org-last-changed-timestamp))
  7708. (org-timestamp-change arg (or what 'day))
  7709. (setq org-last-changed-timestamp
  7710. (concat org-last-changed-timestamp "--" end)))))
  7711. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7712. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7713. (defun org-agenda-date-earlier (arg &optional what)
  7714. "Change the date of this item to ARG day(s) earlier."
  7715. (interactive "p")
  7716. (org-agenda-date-later (- arg) what))
  7717. (defun org-agenda-date-later-minutes (arg)
  7718. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7719. (interactive "p")
  7720. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7721. (org-agenda-date-later arg 'minute))
  7722. (defun org-agenda-date-earlier-minutes (arg)
  7723. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7724. (interactive "p")
  7725. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7726. (org-agenda-date-earlier arg 'minute))
  7727. (defun org-agenda-date-later-hours (arg)
  7728. "Change the time of this item, in hour steps."
  7729. (interactive "p")
  7730. (org-agenda-date-later arg 'hour))
  7731. (defun org-agenda-date-earlier-hours (arg)
  7732. "Change the time of this item, in hour steps."
  7733. (interactive "p")
  7734. (org-agenda-date-earlier arg 'hour))
  7735. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7736. "Show new date stamp via text properties."
  7737. ;; We use text properties to make this undoable
  7738. (let ((inhibit-read-only t)
  7739. (buffer-invisibility-spec))
  7740. (setq stamp (concat " " prefix " => " stamp))
  7741. (save-excursion
  7742. (goto-char (point-max))
  7743. (while (not (bobp))
  7744. (when (equal marker (org-get-at-bol 'org-marker))
  7745. (org-move-to-column (- (window-width) (length stamp)) t)
  7746. (org-agenda-fix-tags-filter-overlays-at (point))
  7747. (if (featurep 'xemacs)
  7748. ;; Use `duplicable' property to trigger undo recording
  7749. (let ((ex (make-extent nil nil))
  7750. (gl (make-glyph stamp)))
  7751. (set-glyph-face gl 'secondary-selection)
  7752. (set-extent-properties
  7753. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7754. (insert-extent ex (1- (point)) (point-at-eol)))
  7755. (add-text-properties
  7756. (1- (point)) (point-at-eol)
  7757. (list 'display (org-add-props stamp nil
  7758. 'face 'secondary-selection))))
  7759. (beginning-of-line 1))
  7760. (beginning-of-line 0)))))
  7761. (defun org-agenda-date-prompt (arg)
  7762. "Change the date of this item. Date is prompted for, with default today.
  7763. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7764. be used to request time specification in the time stamp."
  7765. (interactive "P")
  7766. (org-agenda-check-type t 'agenda 'timeline)
  7767. (org-agenda-check-no-diary)
  7768. (let* ((marker (or (org-get-at-bol 'org-marker)
  7769. (org-agenda-error)))
  7770. (buffer (marker-buffer marker))
  7771. (pos (marker-position marker)))
  7772. (org-with-remote-undo buffer
  7773. (with-current-buffer buffer
  7774. (widen)
  7775. (goto-char pos)
  7776. (if (not (org-at-timestamp-p t))
  7777. (error "Cannot find time stamp"))
  7778. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7779. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7780. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7781. (defun org-agenda-schedule (arg &optional time)
  7782. "Schedule the item at point.
  7783. ARG is passed through to `org-schedule'."
  7784. (interactive "P")
  7785. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7786. (org-agenda-check-no-diary)
  7787. (let* ((marker (or (org-get-at-bol 'org-marker)
  7788. (org-agenda-error)))
  7789. (type (marker-insertion-type marker))
  7790. (buffer (marker-buffer marker))
  7791. (pos (marker-position marker))
  7792. (org-insert-labeled-timestamps-at-point nil)
  7793. ts)
  7794. (set-marker-insertion-type marker t)
  7795. (org-with-remote-undo buffer
  7796. (with-current-buffer buffer
  7797. (widen)
  7798. (goto-char pos)
  7799. (setq ts (org-schedule arg time)))
  7800. (org-agenda-show-new-time marker ts "S"))
  7801. (message "Item scheduled for %s" ts)))
  7802. (defun org-agenda-deadline (arg &optional time)
  7803. "Schedule the item at point.
  7804. ARG is passed through to `org-deadline'."
  7805. (interactive "P")
  7806. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7807. (org-agenda-check-no-diary)
  7808. (let* ((marker (or (org-get-at-bol 'org-marker)
  7809. (org-agenda-error)))
  7810. (buffer (marker-buffer marker))
  7811. (pos (marker-position marker))
  7812. (org-insert-labeled-timestamps-at-point nil)
  7813. ts)
  7814. (org-with-remote-undo buffer
  7815. (with-current-buffer buffer
  7816. (widen)
  7817. (goto-char pos)
  7818. (setq ts (org-deadline arg time)))
  7819. (org-agenda-show-new-time marker ts "D"))
  7820. (message "Deadline for this item set to %s" ts)))
  7821. (defun org-agenda-clock-in (&optional arg)
  7822. "Start the clock on the currently selected item."
  7823. (interactive "P")
  7824. (org-agenda-check-no-diary)
  7825. (if (equal arg '(4))
  7826. (org-clock-in arg)
  7827. (let* ((marker (or (org-get-at-bol 'org-marker)
  7828. (org-agenda-error)))
  7829. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7830. marker))
  7831. (pos (marker-position marker))
  7832. newhead)
  7833. (org-with-remote-undo (marker-buffer marker)
  7834. (with-current-buffer (marker-buffer marker)
  7835. (widen)
  7836. (goto-char pos)
  7837. (org-show-context 'agenda)
  7838. (org-show-entry)
  7839. (org-cycle-hide-drawers 'children)
  7840. (org-clock-in arg)
  7841. (setq newhead (org-get-heading)))
  7842. (org-agenda-change-all-lines newhead hdmarker)))))
  7843. (defun org-agenda-clock-out ()
  7844. "Stop the currently running clock."
  7845. (interactive)
  7846. (unless (marker-buffer org-clock-marker)
  7847. (error "No running clock"))
  7848. (let ((marker (make-marker)) newhead)
  7849. (org-with-remote-undo (marker-buffer org-clock-marker)
  7850. (with-current-buffer (marker-buffer org-clock-marker)
  7851. (save-excursion
  7852. (save-restriction
  7853. (widen)
  7854. (goto-char org-clock-marker)
  7855. (org-back-to-heading t)
  7856. (move-marker marker (point))
  7857. (org-clock-out)
  7858. (setq newhead (org-get-heading))))))
  7859. (org-agenda-change-all-lines newhead marker)
  7860. (move-marker marker nil)))
  7861. (defun org-agenda-clock-cancel (&optional arg)
  7862. "Cancel the currently running clock."
  7863. (interactive "P")
  7864. (unless (marker-buffer org-clock-marker)
  7865. (error "No running clock"))
  7866. (org-with-remote-undo (marker-buffer org-clock-marker)
  7867. (org-clock-cancel)))
  7868. (defun org-agenda-clock-goto ()
  7869. "Jump to the currently clocked in task within the agenda.
  7870. If the currently clocked in task is not listed in the agenda
  7871. buffer, display it in another window."
  7872. (interactive)
  7873. (let (pos)
  7874. (mapc (lambda (o)
  7875. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7876. (setq pos (overlay-start o))))
  7877. (overlays-in (point-min) (point-max)))
  7878. (cond (pos (goto-char pos))
  7879. ;; If the currently clocked entry is not in the agenda
  7880. ;; buffer, we visit it in another window:
  7881. (org-clock-current-task
  7882. (org-switch-to-buffer-other-window (org-clock-goto)))
  7883. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7884. (defun org-agenda-diary-entry-in-org-file ()
  7885. "Make a diary entry in the file `org-agenda-diary-file'."
  7886. (let (d1 d2 char (text "") dp1 dp2)
  7887. (if (equal (buffer-name) "*Calendar*")
  7888. (setq d1 (calendar-cursor-to-date t)
  7889. d2 (car calendar-mark-ring))
  7890. (setq dp1 (get-text-property (point-at-bol) 'day))
  7891. (unless dp1 (error "No date defined in current line"))
  7892. (setq d1 (calendar-gregorian-from-absolute dp1)
  7893. d2 (and (ignore-errors (mark))
  7894. (save-excursion
  7895. (goto-char (mark))
  7896. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7897. (calendar-gregorian-from-absolute dp2))))
  7898. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7899. (setq char (read-char-exclusive))
  7900. (cond
  7901. ((equal char ?d)
  7902. (setq text (read-string "Day entry: "))
  7903. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7904. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7905. ((equal char ?a)
  7906. (setq d1 (list (car d1) (nth 1 d1)
  7907. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7908. (nth 2 d1))))
  7909. (setq text (read-string "Anniversary (use %d to show years): "))
  7910. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7911. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7912. ((equal char ?b)
  7913. (setq text (read-string "Block entry: "))
  7914. (unless (and d1 d2 (not (equal d1 d2)))
  7915. (error "No block of days selected"))
  7916. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7917. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7918. ((equal char ?j)
  7919. (org-switch-to-buffer-other-window
  7920. (find-file-noselect org-agenda-diary-file))
  7921. (require 'org-datetree)
  7922. (org-datetree-find-date-create d1)
  7923. (org-reveal t))
  7924. (t (error "Invalid selection character `%c'" char)))))
  7925. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7926. "Where in `org-agenda-diary-file' should new entries be added?
  7927. Valid values:
  7928. date-tree in the date tree, as child of the date
  7929. top-level as top-level entries at the end of the file."
  7930. :group 'org-agenda
  7931. :type '(choice
  7932. (const :tag "in a date tree" date-tree)
  7933. (const :tag "as top level at end of file" top-level)))
  7934. (defcustom org-agenda-insert-diary-extract-time nil
  7935. "Non-nil means extract any time specification from the diary entry."
  7936. :group 'org-agenda
  7937. :version "24.1"
  7938. :type 'boolean)
  7939. (defcustom org-agenda-bulk-mark-char ">"
  7940. "A single-character string to be used as the bulk mark."
  7941. :group 'org-agenda
  7942. :version "24.1"
  7943. :type 'string)
  7944. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7945. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7946. If TEXT is not empty, it will become the headline of the new entry, and
  7947. the resulting entry will not be shown. When TEXT is empty, switch to
  7948. `org-agenda-diary-file' and let the user finish the entry there."
  7949. (let ((cw (current-window-configuration)))
  7950. (org-switch-to-buffer-other-window
  7951. (find-file-noselect org-agenda-diary-file))
  7952. (widen)
  7953. (goto-char (point-min))
  7954. (cond
  7955. ((eq type 'anniversary)
  7956. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7957. (progn
  7958. (or (org-at-heading-p t)
  7959. (progn
  7960. (outline-next-heading)
  7961. (insert "* Anniversaries\n\n")
  7962. (beginning-of-line -1)))))
  7963. (outline-next-heading)
  7964. (org-back-over-empty-lines)
  7965. (backward-char 1)
  7966. (insert "\n")
  7967. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7968. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7969. ((eq type 'day)
  7970. (let ((org-prefix-has-time t)
  7971. (org-agenda-time-leading-zero t)
  7972. fmt time time2)
  7973. (if org-agenda-insert-diary-extract-time
  7974. ;; Use org-agenda-format-item to parse text for a time-range and
  7975. ;; remove it. FIXME: This is a hack, we should refactor
  7976. ;; that function to make time extraction available separately
  7977. (setq fmt (org-agenda-format-item nil text nil nil t)
  7978. time (get-text-property 0 'time fmt)
  7979. time2 (if (> (length time) 0)
  7980. ;; split-string removes trailing ...... if
  7981. ;; no end time given. First space
  7982. ;; separates time from date.
  7983. (concat " " (car (split-string time "\\.")))
  7984. nil)
  7985. text (get-text-property 0 'txt fmt)))
  7986. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7987. (org-agenda-insert-diary-as-top-level text)
  7988. (require 'org-datetree)
  7989. (org-datetree-find-date-create d1)
  7990. (org-agenda-insert-diary-make-new-entry text))
  7991. (org-insert-time-stamp (org-time-from-absolute
  7992. (calendar-absolute-from-gregorian d1))
  7993. nil nil nil nil time2))
  7994. (end-of-line 0))
  7995. ((eq type 'block)
  7996. (if (> (calendar-absolute-from-gregorian d1)
  7997. (calendar-absolute-from-gregorian d2))
  7998. (setq d1 (prog1 d2 (setq d2 d1))))
  7999. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8000. (org-agenda-insert-diary-as-top-level text)
  8001. (require 'org-datetree)
  8002. (org-datetree-find-date-create d1)
  8003. (org-agenda-insert-diary-make-new-entry text))
  8004. (org-insert-time-stamp (org-time-from-absolute
  8005. (calendar-absolute-from-gregorian d1)))
  8006. (insert "--")
  8007. (org-insert-time-stamp (org-time-from-absolute
  8008. (calendar-absolute-from-gregorian d2)))
  8009. (end-of-line 0)))
  8010. (if (string-match "\\S-" text)
  8011. (progn
  8012. (set-window-configuration cw)
  8013. (message "%s entry added to %s"
  8014. (capitalize (symbol-name type))
  8015. (abbreviate-file-name org-agenda-diary-file)))
  8016. (org-reveal t)
  8017. (message "Please finish entry here"))))
  8018. (defun org-agenda-insert-diary-as-top-level (text)
  8019. "Make new entry as a top-level entry at the end of the file.
  8020. Add TEXT as headline, and position the cursor in the second line so that
  8021. a timestamp can be added there."
  8022. (widen)
  8023. (goto-char (point-max))
  8024. (or (bolp) (insert "\n"))
  8025. (insert "* " text "\n")
  8026. (if org-adapt-indentation (org-indent-to-column 2)))
  8027. (defun org-agenda-insert-diary-make-new-entry (text)
  8028. "Make new entry as last child of current entry.
  8029. Add TEXT as headline, and position the cursor in the second line so that
  8030. a timestamp can be added there."
  8031. (let ((org-show-following-heading t)
  8032. (org-show-siblings t)
  8033. (org-show-hierarchy-above t)
  8034. (org-show-entry-below t)
  8035. col)
  8036. (outline-next-heading)
  8037. (org-back-over-empty-lines)
  8038. (or (looking-at "[ \t]*$")
  8039. (progn (insert "\n") (backward-char 1)))
  8040. (org-insert-heading nil t)
  8041. (org-do-demote)
  8042. (setq col (current-column))
  8043. (insert text "\n")
  8044. (if org-adapt-indentation (org-indent-to-column col))
  8045. (let ((org-show-following-heading t)
  8046. (org-show-siblings t)
  8047. (org-show-hierarchy-above t)
  8048. (org-show-entry-below t))
  8049. (org-show-context))))
  8050. (defun org-agenda-diary-entry ()
  8051. "Make a diary entry, like the `i' command from the calendar.
  8052. All the standard commands work: block, weekly etc.
  8053. When `org-agenda-diary-file' points to a file,
  8054. `org-agenda-diary-entry-in-org-file' is called instead to create
  8055. entries in that Org-mode file."
  8056. (interactive)
  8057. (org-agenda-check-type t 'agenda 'timeline)
  8058. (if (not (eq org-agenda-diary-file 'diary-file))
  8059. (org-agenda-diary-entry-in-org-file)
  8060. (require 'diary-lib)
  8061. (let* ((char (progn
  8062. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8063. (read-char-exclusive)))
  8064. (cmd (cdr (assoc char
  8065. '((?d . insert-diary-entry)
  8066. (?w . insert-weekly-diary-entry)
  8067. (?m . insert-monthly-diary-entry)
  8068. (?y . insert-yearly-diary-entry)
  8069. (?a . insert-anniversary-diary-entry)
  8070. (?b . insert-block-diary-entry)
  8071. (?c . insert-cyclic-diary-entry)))))
  8072. (oldf (symbol-function 'calendar-cursor-to-date))
  8073. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8074. (point (point))
  8075. (mark (or (mark t) (point))))
  8076. (unless cmd
  8077. (error "No command associated with <%c>" char))
  8078. (unless (and (get-text-property point 'day)
  8079. (or (not (equal ?b char))
  8080. (get-text-property mark 'day)))
  8081. (error "Don't know which date to use for diary entry"))
  8082. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8083. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8084. (let ((calendar-mark-ring
  8085. (list (calendar-gregorian-from-absolute
  8086. (or (get-text-property mark 'day)
  8087. (get-text-property point 'day))))))
  8088. (unwind-protect
  8089. (progn
  8090. (fset 'calendar-cursor-to-date
  8091. (lambda (&optional error dummy)
  8092. (calendar-gregorian-from-absolute
  8093. (get-text-property point 'day))))
  8094. (call-interactively cmd))
  8095. (fset 'calendar-cursor-to-date oldf))))))
  8096. (defun org-agenda-execute-calendar-command (cmd)
  8097. "Execute a calendar command from the agenda with date from cursor."
  8098. (org-agenda-check-type t 'agenda 'timeline)
  8099. (require 'diary-lib)
  8100. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8101. (error "Don't know which date to use for the calendar command"))
  8102. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8103. (point (point))
  8104. (date (calendar-gregorian-from-absolute
  8105. (get-text-property point 'day)))
  8106. ;; the following 2 vars are needed in the calendar
  8107. (displayed-month (car date))
  8108. (displayed-year (nth 2 date)))
  8109. (unwind-protect
  8110. (progn
  8111. (fset 'calendar-cursor-to-date
  8112. (lambda (&optional error dummy)
  8113. (calendar-gregorian-from-absolute
  8114. (get-text-property point 'day))))
  8115. (call-interactively cmd))
  8116. (fset 'calendar-cursor-to-date oldf))))
  8117. (defun org-agenda-phases-of-moon ()
  8118. "Display the phases of the moon for the 3 months around the cursor date."
  8119. (interactive)
  8120. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8121. (defun org-agenda-holidays ()
  8122. "Display the holidays for the 3 months around the cursor date."
  8123. (interactive)
  8124. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8125. (defvar calendar-longitude) ; defined in calendar.el
  8126. (defvar calendar-latitude) ; defined in calendar.el
  8127. (defvar calendar-location-name) ; defined in calendar.el
  8128. (defun org-agenda-sunrise-sunset (arg)
  8129. "Display sunrise and sunset for the cursor date.
  8130. Latitude and longitude can be specified with the variables
  8131. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8132. argument, latitude and longitude will be prompted for."
  8133. (interactive "P")
  8134. (require 'solar)
  8135. (let ((calendar-longitude (if arg nil calendar-longitude))
  8136. (calendar-latitude (if arg nil calendar-latitude))
  8137. (calendar-location-name
  8138. (if arg "the given coordinates" calendar-location-name)))
  8139. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8140. (defun org-agenda-goto-calendar ()
  8141. "Open the Emacs calendar with the date at the cursor."
  8142. (interactive)
  8143. (org-agenda-check-type t 'agenda 'timeline)
  8144. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8145. (error "Don't know which date to open in calendar")))
  8146. (date (calendar-gregorian-from-absolute day))
  8147. (calendar-move-hook nil)
  8148. (calendar-view-holidays-initially-flag nil)
  8149. (calendar-view-diary-initially-flag nil))
  8150. (calendar)
  8151. (calendar-goto-date date)))
  8152. ;;;###autoload
  8153. (defun org-calendar-goto-agenda ()
  8154. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8155. This is a command that has to be installed in `calendar-mode-map'."
  8156. (interactive)
  8157. (org-agenda-list nil (calendar-absolute-from-gregorian
  8158. (calendar-cursor-to-date))
  8159. nil))
  8160. (defun org-agenda-convert-date ()
  8161. (interactive)
  8162. (org-agenda-check-type t 'agenda 'timeline)
  8163. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8164. date s)
  8165. (unless day
  8166. (error "Don't know which date to convert"))
  8167. (setq date (calendar-gregorian-from-absolute day))
  8168. (setq s (concat
  8169. "Gregorian: " (calendar-date-string date) "\n"
  8170. "ISO: " (calendar-iso-date-string date) "\n"
  8171. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8172. "Julian: " (calendar-julian-date-string date) "\n"
  8173. "Astron. JD: " (calendar-astro-date-string date)
  8174. " (Julian date number at noon UTC)\n"
  8175. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8176. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8177. "French: " (calendar-french-date-string date) "\n"
  8178. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8179. "Mayan: " (calendar-mayan-date-string date) "\n"
  8180. "Coptic: " (calendar-coptic-date-string date) "\n"
  8181. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8182. "Persian: " (calendar-persian-date-string date) "\n"
  8183. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8184. (with-output-to-temp-buffer "*Dates*"
  8185. (princ s))
  8186. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8187. ;;; Bulk commands
  8188. (defun org-agenda-bulk-marked-p ()
  8189. (eq (get-char-property (point-at-bol) 'type)
  8190. 'org-marked-entry-overlay))
  8191. (defun org-agenda-bulk-mark (&optional arg)
  8192. "Mark the entry at point for future bulk action."
  8193. (interactive "p")
  8194. (dotimes (i (or arg 1))
  8195. (unless (org-get-at-bol 'org-agenda-diary-link)
  8196. (let* ((m (org-get-at-bol 'org-hd-marker))
  8197. ov)
  8198. (unless (org-agenda-bulk-marked-p)
  8199. (unless m (error "Nothing to mark at point"))
  8200. (push m org-agenda-bulk-marked-entries)
  8201. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8202. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8203. (org-get-todo-face "TODO")
  8204. 'evaporate)
  8205. (overlay-put ov 'type 'org-marked-entry-overlay))
  8206. (beginning-of-line 2)
  8207. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8208. (beginning-of-line 2))
  8209. (message "%d entries marked for bulk action"
  8210. (length org-agenda-bulk-marked-entries))))))
  8211. (defun org-agenda-bulk-mark-all ()
  8212. "Mark all entries for future agenda bulk action."
  8213. (interactive)
  8214. (org-agenda-bulk-mark-regexp "."))
  8215. (defun org-agenda-bulk-mark-regexp (regexp)
  8216. "Mark entries matching REGEXP for future agenda bulk action."
  8217. (interactive "sMark entries matching regexp: ")
  8218. (let ((entries-marked 0))
  8219. (save-excursion
  8220. (goto-char (point-min))
  8221. (goto-char (next-single-property-change (point) 'txt))
  8222. (while (re-search-forward regexp nil t)
  8223. (when (string-match regexp (get-text-property (point) 'txt))
  8224. (setq entries-marked (1+ entries-marked))
  8225. (call-interactively 'org-agenda-bulk-mark))))
  8226. (if (not entries-marked)
  8227. (message "No entry matching this regexp."))))
  8228. (defun org-agenda-bulk-unmark (&optional arg)
  8229. "Unmark the entry at point for future bulk action."
  8230. (interactive "P")
  8231. (if arg
  8232. (org-agenda-bulk-unmark-all)
  8233. (cond ((org-agenda-bulk-marked-p)
  8234. (org-agenda-bulk-remove-overlays
  8235. (point-at-bol) (+ 2 (point-at-bol)))
  8236. (setq org-agenda-bulk-marked-entries
  8237. (delete (org-get-at-bol 'org-hd-marker)
  8238. org-agenda-bulk-marked-entries))
  8239. (beginning-of-line 2)
  8240. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8241. (beginning-of-line 2))
  8242. (message "%d entries left marked for bulk action"
  8243. (length org-agenda-bulk-marked-entries)))
  8244. (t (message "No entry to unmark here")))))
  8245. (defun org-agenda-bulk-toggle ()
  8246. "Toggle marking the entry at point for bulk action."
  8247. (interactive)
  8248. (if (org-agenda-bulk-marked-p)
  8249. (org-agenda-bulk-unmark)
  8250. (org-agenda-bulk-mark)))
  8251. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8252. "Remove the mark overlays between BEG and END in the agenda buffer.
  8253. BEG and END default to the buffer limits.
  8254. This only removes the overlays, it does not remove the markers
  8255. from the list in `org-agenda-bulk-marked-entries'."
  8256. (interactive)
  8257. (mapc (lambda (ov)
  8258. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8259. (delete-overlay ov)))
  8260. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8261. (defun org-agenda-bulk-unmark-all ()
  8262. "Remove all marks in the agenda buffer.
  8263. This will remove the markers and the overlays."
  8264. (interactive)
  8265. (if (null org-agenda-bulk-marked-entries)
  8266. (message "No entry to unmark")
  8267. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8268. (setq org-agenda-bulk-marked-entries nil)
  8269. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8270. (defcustom org-agenda-persistent-marks nil
  8271. "Non-nil means marked items will stay marked after a bulk action.
  8272. You can toggle this interactively by typing `p' when prompted for a
  8273. bulk action."
  8274. :group 'org-agenda
  8275. :version "24.1"
  8276. :type 'boolean)
  8277. (defun org-agenda-bulk-action (&optional arg)
  8278. "Execute an remote-editing action on all marked entries.
  8279. The prefix arg is passed through to the command if possible."
  8280. (interactive "P")
  8281. ;; Make sure we have markers, and only valid ones
  8282. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8283. (mapc
  8284. (lambda (m)
  8285. (unless (and (markerp m)
  8286. (marker-buffer m)
  8287. (buffer-live-p (marker-buffer m))
  8288. (marker-position m))
  8289. (error "Marker %s for bulk command is invalid" m)))
  8290. org-agenda-bulk-marked-entries)
  8291. ;; Prompt for the bulk command
  8292. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8293. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8294. "[S]catter [f]unction "
  8295. (when org-agenda-bulk-custom-functions
  8296. (concat " Custom: ["
  8297. (mapconcat (lambda(f) (char-to-string (car f)))
  8298. org-agenda-bulk-custom-functions "")
  8299. "]"))))
  8300. (catch 'exit
  8301. (let* ((action (read-char-exclusive))
  8302. (org-log-refile (if org-log-refile 'time nil))
  8303. (entries (reverse org-agenda-bulk-marked-entries))
  8304. (org-overriding-default-time
  8305. (if (get-text-property (point) 'org-agenda-date-header)
  8306. (org-get-cursor-date)))
  8307. redo-at-end
  8308. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8309. (cond
  8310. ((equal action ?p)
  8311. (let ((org-agenda-persistent-marks
  8312. (not org-agenda-persistent-marks)))
  8313. (org-agenda-bulk-action)
  8314. (throw 'exit nil)))
  8315. ((equal action ?$)
  8316. (setq cmd '(org-agenda-archive)))
  8317. ((equal action ?A)
  8318. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8319. ((member action '(?r ?w))
  8320. (setq rfloc (org-refile-get-location
  8321. "Refile to"
  8322. (marker-buffer (car entries))
  8323. org-refile-allow-creating-parent-nodes))
  8324. (if (nth 3 rfloc)
  8325. (setcar (nthcdr 3 rfloc)
  8326. (move-marker (make-marker) (nth 3 rfloc)
  8327. (or (get-file-buffer (nth 1 rfloc))
  8328. (find-buffer-visiting (nth 1 rfloc))
  8329. (error "This should not happen")))))
  8330. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8331. redo-at-end t))
  8332. ((equal action ?t)
  8333. (setq state (org-icompleting-read
  8334. "Todo state: "
  8335. (with-current-buffer (marker-buffer (car entries))
  8336. (mapcar 'list org-todo-keywords-1))))
  8337. (setq cmd `(let ((org-inhibit-blocking t)
  8338. (org-inhibit-logging 'note))
  8339. (org-agenda-todo ,state))))
  8340. ((memq action '(?- ?+))
  8341. (setq tag (org-icompleting-read
  8342. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8343. (with-current-buffer (marker-buffer (car entries))
  8344. (delq nil
  8345. (mapcar (lambda (x)
  8346. (if (stringp (car x)) x)) org-tag-alist)))))
  8347. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8348. ((memq action '(?s ?d))
  8349. (let* ((time
  8350. (unless arg
  8351. (org-read-date
  8352. nil nil nil
  8353. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8354. org-overriding-default-time)))
  8355. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8356. (setq cmd `(eval '(,c1 arg ,time)))))
  8357. ((equal action ?S)
  8358. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8359. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8360. (let ((days (read-number
  8361. (format "Scatter tasks across how many %sdays: "
  8362. (if arg "week" "")) 7)))
  8363. (setq cmd
  8364. `(let ((distance (1+ (random ,days))))
  8365. (if arg
  8366. (let ((dist distance)
  8367. (day-of-week
  8368. (calendar-day-of-week
  8369. (calendar-gregorian-from-absolute (org-today)))))
  8370. (dotimes (i (1+ dist))
  8371. (while (member day-of-week org-agenda-weekend-days)
  8372. (incf distance)
  8373. (incf day-of-week)
  8374. (if (= day-of-week 7)
  8375. (setq day-of-week 0)))
  8376. (incf day-of-week)
  8377. (if (= day-of-week 7)
  8378. (setq day-of-week 0)))))
  8379. ;; silently fail when try to replan a sexp entry
  8380. (condition-case nil
  8381. (let* ((date (calendar-gregorian-from-absolute
  8382. (+ (org-today) distance)))
  8383. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8384. (nth 2 date))))
  8385. (org-agenda-schedule nil time))
  8386. (error nil)))))))
  8387. ((assoc action org-agenda-bulk-custom-functions)
  8388. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8389. redo-at-end t))
  8390. ((equal action ?f)
  8391. (setq cmd (list (intern
  8392. (org-icompleting-read "Function: "
  8393. obarray 'fboundp t nil nil)))))
  8394. (t (error "Invalid bulk action")))
  8395. ;; Sort the markers, to make sure that parents are handled before children
  8396. (setq entries (sort entries
  8397. (lambda (a b)
  8398. (cond
  8399. ((equal (marker-buffer a) (marker-buffer b))
  8400. (< (marker-position a) (marker-position b)))
  8401. (t
  8402. (string< (buffer-name (marker-buffer a))
  8403. (buffer-name (marker-buffer b))))))))
  8404. ;; Now loop over all markers and apply cmd
  8405. (while (setq e (pop entries))
  8406. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8407. (if (not pos)
  8408. (progn (message "Skipping removed entry at %s" e)
  8409. (setq cntskip (1+ cntskip)))
  8410. (goto-char pos)
  8411. (let (org-loop-over-headlines-in-active-region)
  8412. (eval cmd))
  8413. (setq cnt (1+ cnt))))
  8414. (when redo-at-end (org-agenda-redo))
  8415. (unless org-agenda-persistent-marks
  8416. (org-agenda-bulk-unmark-all))
  8417. (message "Acted on %d entries%s%s"
  8418. cnt
  8419. (if (= cntskip 0)
  8420. ""
  8421. (format ", skipped %d (disappeared before their turn)"
  8422. cntskip))
  8423. (if (not org-agenda-persistent-marks)
  8424. "" " (kept marked)"))))))
  8425. (defun org-agenda-capture ()
  8426. "Call `org-capture' with the date at point."
  8427. (interactive)
  8428. (if (not (eq major-mode 'org-agenda-mode))
  8429. (error "You cannot do this outside of agenda buffers")
  8430. (let ((org-overriding-default-time
  8431. (org-get-cursor-date)))
  8432. (call-interactively 'org-capture))))
  8433. ;;; Flagging notes
  8434. (defun org-agenda-show-the-flagging-note ()
  8435. "Display the flagging note in the other window.
  8436. When called a second time in direct sequence, offer to remove the FLAGGING
  8437. tag and (if present) the flagging note."
  8438. (interactive)
  8439. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8440. (win (selected-window))
  8441. note heading newhead)
  8442. (unless hdmarker
  8443. (error "No linked entry at point"))
  8444. (if (and (eq this-command last-command)
  8445. (y-or-n-p "Unflag and remove any flagging note? "))
  8446. (progn
  8447. (org-agenda-remove-flag hdmarker)
  8448. (let ((win (get-buffer-window "*Flagging Note*")))
  8449. (and win (delete-window win)))
  8450. (message "Entry unflagged"))
  8451. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8452. (unless note
  8453. (error "No flagging note"))
  8454. (org-kill-new note)
  8455. (org-switch-to-buffer-other-window "*Flagging Note*")
  8456. (erase-buffer)
  8457. (insert note)
  8458. (goto-char (point-min))
  8459. (while (re-search-forward "\\\\n" nil t)
  8460. (replace-match "\n" t t))
  8461. (goto-char (point-min))
  8462. (select-window win)
  8463. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8464. (defun org-agenda-remove-flag (marker)
  8465. "Remove the FLAGGED tag and any flagging note in the entry."
  8466. (let (newhead)
  8467. (org-with-point-at marker
  8468. (org-toggle-tag "FLAGGED" 'off)
  8469. (org-entry-delete nil "THEFLAGGINGNOTE")
  8470. (setq newhead (org-get-heading)))
  8471. (org-agenda-change-all-lines newhead marker)
  8472. (message "Entry unflagged")))
  8473. (defun org-agenda-get-any-marker (&optional pos)
  8474. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8475. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8476. ;;; Appointment reminders
  8477. (defvar appt-time-msg-list) ; defined in appt.el
  8478. ;;;###autoload
  8479. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8480. "Activate appointments found in `org-agenda-files'.
  8481. With a \\[universal-argument] prefix, refresh the list of
  8482. appointments.
  8483. If FILTER is t, interactively prompt the user for a regular
  8484. expression, and filter out entries that don't match it.
  8485. If FILTER is a string, use this string as a regular expression
  8486. for filtering entries out.
  8487. If FILTER is a function, filter out entries against which
  8488. calling the function returns nil. This function takes one
  8489. argument: an entry from `org-agenda-get-day-entries'.
  8490. FILTER can also be an alist with the car of each cell being
  8491. either 'headline or 'category. For example:
  8492. '((headline \"IMPORTANT\")
  8493. (category \"Work\"))
  8494. will only add headlines containing IMPORTANT or headlines
  8495. belonging to the \"Work\" category.
  8496. ARGS are symbols indicating what kind of entries to consider.
  8497. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8498. and :timestamp entries. See the docstring of `org-diary' for
  8499. details and examples.
  8500. If an entry as a APPT_WARNTIME property, its value will be used
  8501. to override `appt-message-warning-time'."
  8502. (interactive "P")
  8503. (if refresh (setq appt-time-msg-list nil))
  8504. (if (eq filter t)
  8505. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8506. (let* ((cnt 0) ; count added events
  8507. (scope (or args '(:deadline :scheduled :timestamp)))
  8508. (org-agenda-new-buffers nil)
  8509. (org-deadline-warning-days 0)
  8510. ;; Do not use `org-today' here because appt only takes
  8511. ;; time and without date as argument, so it may pass wrong
  8512. ;; information otherwise
  8513. (today (org-date-to-gregorian
  8514. (time-to-days (current-time))))
  8515. (org-agenda-restrict nil)
  8516. (files (org-agenda-files 'unrestricted)) entries file
  8517. (org-agenda-buffer nil))
  8518. ;; Get all entries which may contain an appt
  8519. (org-agenda-prepare-buffers files)
  8520. (while (setq file (pop files))
  8521. (setq entries
  8522. (delq nil
  8523. (append entries
  8524. (apply 'org-agenda-get-day-entries
  8525. file today scope)))))
  8526. ;; Map thru entries and find if we should filter them out
  8527. (mapc
  8528. (lambda(x)
  8529. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8530. (cat (get-text-property 1 'org-category x))
  8531. (tod (get-text-property 1 'time-of-day x))
  8532. (ok (or (null filter)
  8533. (and (stringp filter) (string-match filter evt))
  8534. (and (functionp filter) (funcall filter x))
  8535. (and (listp filter)
  8536. (let ((cat-filter (cadr (assoc 'category filter)))
  8537. (evt-filter (cadr (assoc 'headline filter))))
  8538. (or (and (stringp cat-filter)
  8539. (string-match cat-filter cat))
  8540. (and (stringp evt-filter)
  8541. (string-match evt-filter evt)))))))
  8542. (wrn (get-text-property 1 'warntime x)))
  8543. ;; FIXME: Shall we remove text-properties for the appt text?
  8544. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8545. (when (and ok tod)
  8546. (setq tod (concat "00" (number-to-string tod))
  8547. tod (when (string-match
  8548. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8549. (concat (match-string 1 tod) ":"
  8550. (match-string 2 tod))))
  8551. (if (version< emacs-version "23.3")
  8552. (appt-add tod evt)
  8553. (appt-add tod evt wrn))
  8554. (setq cnt (1+ cnt))))) entries)
  8555. (org-release-buffers org-agenda-new-buffers)
  8556. (if (eq cnt 0)
  8557. (message "No event to add")
  8558. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8559. (defun org-agenda-todayp (date)
  8560. "Does DATE mean today, when considering `org-extend-today-until'?"
  8561. (let ((today (org-today))
  8562. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8563. date)))
  8564. (eq date today)))
  8565. (defun org-agenda-todo-yesterday (&optional arg)
  8566. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8567. (interactive "P")
  8568. (let* ((hour (third (decode-time
  8569. (org-current-time))))
  8570. (org-extend-today-until (1+ hour)))
  8571. (org-agenda-todo arg)))
  8572. (provide 'org-agenda)
  8573. ;;; org-agenda.el ends here