org-agenda.el 376 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 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 do 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-todo-ignore-time-comparison-use-seconds nil
  661. "Time unit to use when possibly ignoring an agenda item.
  662. See the docstring of various `org-agenda-todo-ignore-*' options.
  663. The default is to compare time stamps using days. An item is thus
  664. considered to be in the future if it is at least one day after today.
  665. Non-nil means to compare time stamps using seconds. An item is then
  666. considered future if it has a time value later than current time."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-todo-list
  669. :version "24.4"
  670. :package-version '(Org . "8.0")
  671. :type '(choice
  672. (const :tag "Compare time with days" nil)
  673. (const :tag "Compare time with seconds" t)))
  674. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  675. "Non-nil means honor todo-list ignores options also in tags-todo search.
  676. The variables
  677. `org-agenda-todo-ignore-with-date',
  678. `org-agenda-todo-ignore-timestamp',
  679. `org-agenda-todo-ignore-scheduled',
  680. `org-agenda-todo-ignore-deadlines'
  681. make the global TODO list skip entries that have time stamps of certain
  682. kinds. If this option is set, the same options will also apply for the
  683. tags-todo search, which is the general tags/property matcher
  684. restricted to unfinished TODO entries only."
  685. :group 'org-agenda-skip
  686. :group 'org-agenda-todo-list
  687. :group 'org-agenda-match-view
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-scheduled-if-done nil
  690. "Non-nil means don't show scheduled items in agenda when they are done.
  691. This is relevant for the daily/weekly agenda, not for the TODO list. And
  692. it applies only to the actual date of the scheduling. Warnings about
  693. an item with a past scheduling dates are always turned off when the item
  694. is DONE."
  695. :group 'org-agenda-skip
  696. :group 'org-agenda-daily/weekly
  697. :type 'boolean)
  698. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  699. "Non-nil means skip scheduling line if same entry shows because of deadline.
  700. In the agenda of today, an entry can show up multiple times because
  701. it is both scheduled and has a nearby deadline, and maybe a plain time
  702. stamp as well.
  703. When this variable is t, then only the deadline is shown and the fact that
  704. the entry is scheduled today or was scheduled previously is not shown.
  705. When this variable is nil, the entry will be shown several times. When
  706. the variable is the symbol `not-today', then skip scheduled previously,
  707. but not scheduled today."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-daily/weekly
  710. :type '(choice
  711. (const :tag "Never" nil)
  712. (const :tag "Always" t)
  713. (const :tag "Not when scheduled today" not-today)))
  714. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  715. "Non-nil means skip timestamp line if same entry shows because of deadline.
  716. In the agenda of today, an entry can show up multiple times
  717. because it has both a plain timestamp and has a nearby deadline.
  718. When this variable is t, then only the deadline is shown and the
  719. fact that the entry has a timestamp for or including today is not
  720. shown. When this variable is nil, the entry will be shown
  721. several times."
  722. :group 'org-agenda-skip
  723. :group 'org-agenda-daily/weekly
  724. :version "24.1"
  725. :type '(choice
  726. (const :tag "Never" nil)
  727. (const :tag "Always" t)))
  728. (defcustom org-agenda-skip-deadline-if-done nil
  729. "Non-nil means don't show deadlines when the corresponding item is done.
  730. When nil, the deadline is still shown and should give you a happy feeling.
  731. This is relevant for the daily/weekly agenda. And it applied only to the
  732. actually date of the deadline. Warnings about approaching and past-due
  733. deadlines are always turned off when the item is DONE."
  734. :group 'org-agenda-skip
  735. :group 'org-agenda-daily/weekly
  736. :type 'boolean)
  737. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  738. "Non-nil means skip deadline prewarning when entry is also scheduled.
  739. This will apply on all days where a prewarning for the deadline would
  740. be shown, but not at the day when the entry is actually due. On that day,
  741. the deadline will be shown anyway.
  742. This variable may be set to nil, t, the symbol `pre-scheduled',
  743. or a number which will then give the number of days before the actual
  744. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  745. eliminates the deadline prewarning only prior to the scheduled date.
  746. This can be used in a workflow where the first showing of the deadline will
  747. trigger you to schedule it, and then you don't want to be reminded of it
  748. because you will take care of it on the day when scheduled."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :version "24.1"
  752. :type '(choice
  753. (const :tag "Always show prewarning" nil)
  754. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  755. (const :tag "Remove prewarning if entry is scheduled" t)
  756. (integer :tag "Restart prewarning N days before deadline")))
  757. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  758. "Non-nil means skip scheduled delay when entry also has a deadline.
  759. This variable may be set to nil, t, the symbol `post-deadline',
  760. or a number which will then give the number of days after the actual
  761. scheduled date when the delay should expire. The symbol `post-deadline'
  762. eliminates the schedule delay when the date is posterior to the deadline."
  763. :group 'org-agenda-skip
  764. :group 'org-agenda-daily/weekly
  765. :version "24.4"
  766. :package-version '(Org . "8.0")
  767. :type '(choice
  768. (const :tag "Always honor delay" nil)
  769. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  770. (const :tag "Ignore delay if entry has a deadline" t)
  771. (integer :tag "Honor delay up until N days after the scheduled date")))
  772. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  773. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  774. When non-nil, after the search for timestamps has matched once in an
  775. entry, the rest of the entry will not be searched."
  776. :group 'org-agenda-skip
  777. :type 'boolean)
  778. (defcustom org-agenda-skip-timestamp-if-done nil
  779. "Non-nil means don't select item by timestamp or -range if it is DONE."
  780. :group 'org-agenda-skip
  781. :group 'org-agenda-daily/weekly
  782. :type 'boolean)
  783. (defcustom org-agenda-dim-blocked-tasks t
  784. "Non-nil means dim blocked tasks in the agenda display.
  785. This causes some overhead during agenda construction, but if you
  786. have turned on `org-enforce-todo-dependencies',
  787. `org-enforce-todo-checkbox-dependencies', or any other blocking
  788. mechanism, this will create useful feedback in the agenda.
  789. Instead of t, this variable can also have the value `invisible'.
  790. Then blocked tasks will be invisible and only become visible when
  791. they become unblocked. An exemption to this behavior is when a task is
  792. blocked because of unchecked checkboxes below it. Since checkboxes do
  793. not show up in the agenda views, making this task invisible you remove any
  794. trace from agenda views that there is something to do. Therefore, a task
  795. that is blocked because of checkboxes will never be made invisible, it
  796. will only be dimmed."
  797. :group 'org-agenda-daily/weekly
  798. :group 'org-agenda-todo-list
  799. :version "24.3"
  800. :type '(choice
  801. (const :tag "Do not dim" nil)
  802. (const :tag "Dim to a gray face" t)
  803. (const :tag "Make invisible" invisible)))
  804. (defcustom org-timeline-show-empty-dates 3
  805. "Non-nil means `org-timeline' also shows dates without an entry.
  806. When nil, only the days which actually have entries are shown.
  807. When t, all days between the first and the last date are shown.
  808. When an integer, show also empty dates, but if there is a gap of more than
  809. N days, just insert a special line indicating the size of the gap."
  810. :group 'org-agenda-skip
  811. :type '(choice
  812. (const :tag "None" nil)
  813. (const :tag "All" t)
  814. (integer :tag "at most")))
  815. (defgroup org-agenda-startup nil
  816. "Options concerning initial settings in the Agenda in Org Mode."
  817. :tag "Org Agenda Startup"
  818. :group 'org-agenda)
  819. (defcustom org-agenda-menu-show-matcher t
  820. "Non-nil means show the match string in the agenda dispatcher menu.
  821. When nil, the matcher string is not shown, but is put into the help-echo
  822. property so than moving the mouse over the command shows it.
  823. Setting it to nil is good if matcher strings are very long and/or if
  824. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  825. :group 'org-agenda
  826. :version "24.1"
  827. :type 'boolean)
  828. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  829. (defcustom org-agenda-menu-two-columns nil
  830. "Non-nil means, use two columns to show custom commands in the dispatcher.
  831. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  832. to nil."
  833. :group 'org-agenda
  834. :version "24.1"
  835. :type 'boolean)
  836. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  837. (defcustom org-agenda-finalize-hook nil
  838. "Hook run just before displaying an agenda buffer.
  839. The buffer is still writable when the hook is called.
  840. You can modify some of the buffer substrings but you should be
  841. extra careful not to modify the text properties of the agenda
  842. headlines as the agenda display heavily relies on them."
  843. :group 'org-agenda-startup
  844. :type 'hook)
  845. (defcustom org-agenda-mouse-1-follows-link nil
  846. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  847. A longer mouse click will still set point. Does not work on XEmacs.
  848. Needs to be set before org.el is loaded."
  849. :group 'org-agenda-startup
  850. :type 'boolean)
  851. (defcustom org-agenda-start-with-follow-mode nil
  852. "The initial value of follow mode in a newly created agenda window."
  853. :group 'org-agenda-startup
  854. :type 'boolean)
  855. (defcustom org-agenda-follow-indirect nil
  856. "Non-nil means `org-agenda-follow-mode' displays only the
  857. current item's tree, in an indirect buffer."
  858. :group 'org-agenda
  859. :version "24.1"
  860. :type 'boolean)
  861. (defcustom org-agenda-show-outline-path t
  862. "Non-nil means show outline path in echo area after line motion."
  863. :group 'org-agenda-startup
  864. :type 'boolean)
  865. (defcustom org-agenda-start-with-entry-text-mode nil
  866. "The initial value of entry-text-mode in a newly created agenda window."
  867. :group 'org-agenda-startup
  868. :type 'boolean)
  869. (defcustom org-agenda-entry-text-maxlines 5
  870. "Number of text lines to be added when `E' is pressed in the agenda.
  871. Note that this variable only used during agenda display. Add add entry text
  872. when exporting the agenda, configure the variable
  873. `org-agenda-add-entry-ext-maxlines'."
  874. :group 'org-agenda
  875. :type 'integer)
  876. (defcustom org-agenda-entry-text-exclude-regexps nil
  877. "List of regular expressions to clean up entry text.
  878. The complete matches of all regular expressions in this list will be
  879. removed from entry text before it is shown in the agenda."
  880. :group 'org-agenda
  881. :type '(repeat (regexp)))
  882. (defcustom org-agenda-entry-text-leaders " > "
  883. "Text prepended to the entry text in agenda buffers."
  884. :version "24.4"
  885. :package-version '(Org . "8.0")
  886. :group 'org-agenda
  887. :type 'string)
  888. (defvar org-agenda-entry-text-cleanup-hook nil
  889. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  890. This cleanup is done in a temporary buffer, so the function may inspect and
  891. change the entire buffer.
  892. Some default stuff like drawers and scheduling/deadline dates will already
  893. have been removed when this is called, as will any matches for regular
  894. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  895. (defvar org-agenda-include-inactive-timestamps nil
  896. "Non-nil means include inactive time stamps in agenda and timeline.
  897. Dynamically scoped.")
  898. (defgroup org-agenda-windows nil
  899. "Options concerning the windows used by the Agenda in Org Mode."
  900. :tag "Org Agenda Windows"
  901. :group 'org-agenda)
  902. (defcustom org-agenda-window-setup 'reorganize-frame
  903. "How the agenda buffer should be displayed.
  904. Possible values for this option are:
  905. current-window Show agenda in the current window, keeping all other windows.
  906. other-window Use `switch-to-buffer-other-window' to display agenda.
  907. reorganize-frame Show only two windows on the current frame, the current
  908. window and the agenda.
  909. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  910. Also, when exiting the agenda, kill that frame.
  911. See also the variable `org-agenda-restore-windows-after-quit'."
  912. :group 'org-agenda-windows
  913. :type '(choice
  914. (const current-window)
  915. (const other-frame)
  916. (const other-window)
  917. (const reorganize-frame)))
  918. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  919. "The min and max height of the agenda window as a fraction of frame height.
  920. The value of the variable is a cons cell with two numbers between 0 and 1.
  921. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  922. :group 'org-agenda-windows
  923. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  924. (defcustom org-agenda-restore-windows-after-quit nil
  925. "Non-nil means restore window configuration upon exiting agenda.
  926. Before the window configuration is changed for displaying the agenda,
  927. the current status is recorded. When the agenda is exited with
  928. `q' or `x' and this option is set, the old state is restored. If
  929. `org-agenda-window-setup' is `other-frame', the value of this
  930. option will be ignored."
  931. :group 'org-agenda-windows
  932. :type 'boolean)
  933. (defcustom org-agenda-ndays nil
  934. "Number of days to include in overview display.
  935. Should be 1 or 7.
  936. Obsolete, see `org-agenda-span'."
  937. :group 'org-agenda-daily/weekly
  938. :type 'integer)
  939. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  940. (defcustom org-agenda-span 'week
  941. "Number of days to include in overview display.
  942. Can be day, week, month, year, or any number of days.
  943. Custom commands can set this variable in the options section."
  944. :group 'org-agenda-daily/weekly
  945. :type '(choice (const :tag "Day" day)
  946. (const :tag "Week" week)
  947. (const :tag "Month" month)
  948. (const :tag "Year" year)
  949. (integer :tag "Custom")))
  950. (defcustom org-agenda-start-on-weekday 1
  951. "Non-nil means start the overview always on the specified weekday.
  952. 0 denotes Sunday, 1 denotes Monday etc.
  953. When nil, always start on the current day.
  954. Custom commands can set this variable in the options section."
  955. :group 'org-agenda-daily/weekly
  956. :type '(choice (const :tag "Today" nil)
  957. (integer :tag "Weekday No.")))
  958. (defcustom org-agenda-show-all-dates t
  959. "Non-nil means `org-agenda' shows every day in the selected range.
  960. When nil, only the days which actually have entries are shown."
  961. :group 'org-agenda-daily/weekly
  962. :type 'boolean)
  963. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  964. "Format string for displaying dates in the agenda.
  965. Used by the daily/weekly agenda and by the timeline. This should be
  966. a format string understood by `format-time-string', or a function returning
  967. the formatted date as a string. The function must take a single argument,
  968. a calendar-style date list like (month day year)."
  969. :group 'org-agenda-daily/weekly
  970. :type '(choice
  971. (string :tag "Format string")
  972. (function :tag "Function")))
  973. (defun org-agenda-format-date-aligned (date)
  974. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  975. This function makes sure that dates are aligned for easy reading."
  976. (require 'cal-iso)
  977. (let* ((dayname (calendar-day-name date))
  978. (day (cadr date))
  979. (day-of-week (calendar-day-of-week date))
  980. (month (car date))
  981. (monthname (calendar-month-name month))
  982. (year (nth 2 date))
  983. (iso-week (org-days-to-iso-week
  984. (calendar-absolute-from-gregorian date)))
  985. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  986. (1- year))
  987. ((and (= month 12) (<= iso-week 1))
  988. (1+ year))
  989. (t year)))
  990. (weekstring (if (= day-of-week 1)
  991. (format " W%02d" iso-week)
  992. "")))
  993. (format "%-10s %2d %s %4d%s"
  994. dayname day monthname year weekstring)))
  995. (defcustom org-agenda-time-leading-zero nil
  996. "Non-nil means use leading zero for military times in agenda.
  997. For example, 9:30am would become 09:30 rather than 9:30."
  998. :group 'org-agenda-daily/weekly
  999. :version "24.1"
  1000. :type 'boolean)
  1001. (defcustom org-agenda-timegrid-use-ampm nil
  1002. "When set, show AM/PM style timestamps on the timegrid."
  1003. :group 'org-agenda
  1004. :version "24.1"
  1005. :type 'boolean)
  1006. (defun org-agenda-time-of-day-to-ampm (time)
  1007. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1008. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1009. (minute (substring time -2))
  1010. (ampm "am"))
  1011. (cond
  1012. ((equal hour-number 12)
  1013. (setq ampm "pm"))
  1014. ((> hour-number 12)
  1015. (setq ampm "pm")
  1016. (setq hour-number (- hour-number 12))))
  1017. (concat
  1018. (if org-agenda-time-leading-zero
  1019. (format "%02d" hour-number)
  1020. (format "%02s" (number-to-string hour-number)))
  1021. ":" minute ampm)))
  1022. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1023. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1024. (if org-agenda-timegrid-use-ampm
  1025. (org-agenda-time-of-day-to-ampm time)
  1026. time))
  1027. (defcustom org-agenda-weekend-days '(6 0)
  1028. "Which days are weekend?
  1029. These days get the special face `org-agenda-date-weekend' in the agenda
  1030. and timeline buffers."
  1031. :group 'org-agenda-daily/weekly
  1032. :type '(set :greedy t
  1033. (const :tag "Monday" 1)
  1034. (const :tag "Tuesday" 2)
  1035. (const :tag "Wednesday" 3)
  1036. (const :tag "Thursday" 4)
  1037. (const :tag "Friday" 5)
  1038. (const :tag "Saturday" 6)
  1039. (const :tag "Sunday" 0)))
  1040. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1041. "Non-nil means jump to today when moving a past date forward in time.
  1042. When using S-right in the agenda to move a a date forward, and the date
  1043. stamp currently points to the past, the first key press will move it
  1044. to today. WHen nil, just move one day forward even if the date stays
  1045. in the past."
  1046. :group 'org-agenda-daily/weekly
  1047. :version "24.1"
  1048. :type 'boolean)
  1049. (defcustom org-agenda-include-diary nil
  1050. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1051. Custom commands can set this variable in the options section."
  1052. :group 'org-agenda-daily/weekly
  1053. :type 'boolean)
  1054. (defcustom org-agenda-include-deadlines t
  1055. "If non-nil, include entries within their deadline warning period.
  1056. Custom commands can set this variable in the options section."
  1057. :group 'org-agenda-daily/weekly
  1058. :version "24.1"
  1059. :type 'boolean)
  1060. (defcustom org-agenda-repeating-timestamp-show-all t
  1061. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1062. When set to a list of strings, only show occurrences of repeating
  1063. stamps for these TODO keywords. When nil, only one occurrence is
  1064. shown, either today or the nearest into the future."
  1065. :group 'org-agenda-daily/weekly
  1066. :type '(choice
  1067. (const :tag "Show repeating stamps" t)
  1068. (repeat :tag "Show repeating stamps for these TODO keywords"
  1069. (string :tag "TODO Keyword"))
  1070. (const :tag "Don't show repeating stamps" nil)))
  1071. (defcustom org-scheduled-past-days 10000
  1072. "Number of days to continue listing scheduled items not marked DONE.
  1073. When an item is scheduled on a date, it shows up in the agenda on this
  1074. day and will be listed until it is marked done for the number of days
  1075. given here."
  1076. :group 'org-agenda-daily/weekly
  1077. :type 'integer)
  1078. (defcustom org-agenda-log-mode-items '(closed clock)
  1079. "List of items that should be shown in agenda log mode.
  1080. This list may contain the following symbols:
  1081. closed Show entries that have been closed on that day.
  1082. clock Show entries that have received clocked time on that day.
  1083. state Show all logged state changes.
  1084. Note that instead of changing this variable, you can also press `C-u l' in
  1085. the agenda to display all available LOG items temporarily."
  1086. :group 'org-agenda-daily/weekly
  1087. :type '(set :greedy t (const closed) (const clock) (const state)))
  1088. (defcustom org-agenda-clock-consistency-checks
  1089. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1090. :gap-ok-around ("4:00")
  1091. :default-face ((:background "DarkRed") (:foreground "white"))
  1092. :overlap-face nil :gap-face nil :no-end-time-face nil
  1093. :long-face nil :short-face nil)
  1094. "This is a property list, with the following keys:
  1095. :max-duration Mark clocking chunks that are longer than this time.
  1096. This is a time string like \"HH:MM\", or the number
  1097. of minutes as an integer.
  1098. :min-duration Mark clocking chunks that are shorter that this.
  1099. This is a time string like \"HH:MM\", or the number
  1100. of minutes as an integer.
  1101. :max-gap Mark gaps between clocking chunks that are longer than
  1102. this duration. A number of minutes, or a string
  1103. like \"HH:MM\".
  1104. :gap-ok-around List of times during the day which are usually not working
  1105. times. When a gap is detected, but the gap contains any
  1106. of these times, the gap is *not* reported. For example,
  1107. if this is (\"4:00\" \"13:00\") then gaps that contain
  1108. 4:00 in the morning (i.e. the night) and 13:00
  1109. (i.e. a typical lunch time) do not cause a warning.
  1110. You should have at least one time during the night in this
  1111. list, or otherwise the first task each morning will trigger
  1112. a warning because it follows a long gap.
  1113. Furthermore, the following properties can be used to define faces for
  1114. issue display.
  1115. :default-face the default face, if the specific face is undefined
  1116. :overlap-face face for overlapping clocks
  1117. :gap-face face for gaps between clocks
  1118. :no-end-time-face face for incomplete clocks
  1119. :long-face face for clock intervals that are too long
  1120. :short-face face for clock intervals that are too short"
  1121. :group 'org-agenda-daily/weekly
  1122. :group 'org-clock
  1123. :version "24.1"
  1124. :type 'plist)
  1125. (defcustom org-agenda-log-mode-add-notes t
  1126. "Non-nil means add first line of notes to log entries in agenda views.
  1127. If a log item like a state change or a clock entry is associated with
  1128. notes, the first line of these notes will be added to the entry in the
  1129. agenda display."
  1130. :group 'org-agenda-daily/weekly
  1131. :type 'boolean)
  1132. (defcustom org-agenda-start-with-log-mode nil
  1133. "The initial value of log-mode in a newly created agenda window.
  1134. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1135. explanations on the possible values."
  1136. :group 'org-agenda-startup
  1137. :group 'org-agenda-daily/weekly
  1138. :type '(choice (const :tag "Don't show log items" nil)
  1139. (const :tag "Show only log items" 'only)
  1140. (const :tag "Show all possible log items" 'clockcheck)
  1141. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1142. (choice (const :tag "Show closed log items" 'closed)
  1143. (const :tag "Show clocked log items" 'clock)
  1144. (const :tag "Show all logged state changes" 'state)))))
  1145. (defcustom org-agenda-start-with-clockreport-mode nil
  1146. "The initial value of clockreport-mode in a newly created agenda window."
  1147. :group 'org-agenda-startup
  1148. :group 'org-agenda-daily/weekly
  1149. :type 'boolean)
  1150. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1151. "Property list with parameters for the clocktable in clockreport mode.
  1152. This is the display mode that shows a clock table in the daily/weekly
  1153. agenda, the properties for this dynamic block can be set here.
  1154. The usual clocktable parameters are allowed here, but you cannot set
  1155. the properties :name, :tstart, :tend, :block, and :scope - these will
  1156. be overwritten to make sure the content accurately reflects the
  1157. current display in the agenda."
  1158. :group 'org-agenda-daily/weekly
  1159. :type 'plist)
  1160. (defcustom org-agenda-search-view-always-boolean nil
  1161. "Non-nil means the search string is interpreted as individual parts.
  1162. The search string for search view can either be interpreted as a phrase,
  1163. or as a list of snippets that define a boolean search for a number of
  1164. strings.
  1165. When this is non-nil, the string will be split on whitespace, and each
  1166. snippet will be searched individually, and all must match in order to
  1167. select an entry. A snippet is then a single string of non-white
  1168. characters, or a string in double quotes, or a regexp in {} braces.
  1169. If a snippet is preceded by \"-\", the snippet must *not* match.
  1170. \"+\" is syntactic sugar for positive selection. Each snippet may
  1171. be found as a full word or a partial word, but see the variable
  1172. `org-agenda-search-view-force-full-words'.
  1173. When this is nil, search will look for the entire search phrase as one,
  1174. with each space character matching any amount of whitespace, including
  1175. line breaks.
  1176. Even when this is nil, you can still switch to Boolean search dynamically
  1177. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1178. is a regexp marked with braces like \"{abc}\", this will also switch to
  1179. boolean search."
  1180. :group 'org-agenda-search-view
  1181. :version "24.1"
  1182. :type 'boolean)
  1183. (if (fboundp 'defvaralias)
  1184. (defvaralias 'org-agenda-search-view-search-words-only
  1185. 'org-agenda-search-view-always-boolean))
  1186. (defcustom org-agenda-search-view-force-full-words nil
  1187. "Non-nil means, search words must be matches as complete words.
  1188. When nil, they may also match part of a word."
  1189. :group 'org-agenda-search-view
  1190. :version "24.1"
  1191. :type 'boolean)
  1192. (defcustom org-agenda-search-view-max-outline-level nil
  1193. "Maximum outline level to display in search view.
  1194. E.g. when this is set to 1, the search view will only
  1195. show headlines of level 1."
  1196. :group 'org-agenda-search-view
  1197. :version "24.4"
  1198. :package-version '(Org . "8.0")
  1199. :type 'integer)
  1200. (defgroup org-agenda-time-grid nil
  1201. "Options concerning the time grid in the Org-mode Agenda."
  1202. :tag "Org Agenda Time Grid"
  1203. :group 'org-agenda)
  1204. (defcustom org-agenda-search-headline-for-time t
  1205. "Non-nil means search headline for a time-of-day.
  1206. If the headline contains a time-of-day in one format or another, it will
  1207. be used to sort the entry into the time sequence of items for a day.
  1208. Some people have time stamps in the headline that refer to the creation
  1209. time or so, and then this produces an unwanted side effect. If this is
  1210. the case for your, use this variable to turn off searching the headline
  1211. for a time."
  1212. :group 'org-agenda-time-grid
  1213. :type 'boolean)
  1214. (defcustom org-agenda-use-time-grid t
  1215. "Non-nil means show a time grid in the agenda schedule.
  1216. A time grid is a set of lines for specific times (like every two hours between
  1217. 8:00 and 20:00). The items scheduled for a day at specific times are
  1218. sorted in between these lines.
  1219. For details about when the grid will be shown, and what it will look like, see
  1220. the variable `org-agenda-time-grid'."
  1221. :group 'org-agenda-time-grid
  1222. :type 'boolean)
  1223. (defcustom org-agenda-time-grid
  1224. '((daily today require-timed)
  1225. "----------------"
  1226. (800 1000 1200 1400 1600 1800 2000))
  1227. "The settings for time grid for agenda display.
  1228. This is a list of three items. The first item is again a list. It contains
  1229. symbols specifying conditions when the grid should be displayed:
  1230. daily if the agenda shows a single day
  1231. weekly if the agenda shows an entire week
  1232. today show grid on current date, independent of daily/weekly display
  1233. require-timed show grid only if at least one item has a time specification
  1234. The second item is a string which will be placed behind the grid time.
  1235. The third item is a list of integers, indicating the times that should have
  1236. a grid line."
  1237. :group 'org-agenda-time-grid
  1238. :type
  1239. '(list
  1240. (set :greedy t :tag "Grid Display Options"
  1241. (const :tag "Show grid in single day agenda display" daily)
  1242. (const :tag "Show grid in weekly agenda display" weekly)
  1243. (const :tag "Always show grid for today" today)
  1244. (const :tag "Show grid only if any timed entries are present"
  1245. require-timed)
  1246. (const :tag "Skip grid times already present in an entry"
  1247. remove-match))
  1248. (string :tag "Grid String")
  1249. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1250. (defcustom org-agenda-show-current-time-in-grid t
  1251. "Non-nil means show the current time in the time grid."
  1252. :group 'org-agenda-time-grid
  1253. :version "24.1"
  1254. :type 'boolean)
  1255. (defcustom org-agenda-current-time-string
  1256. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1257. "The string for the current time marker in the agenda."
  1258. :group 'org-agenda-time-grid
  1259. :version "24.1"
  1260. :type 'string)
  1261. (defgroup org-agenda-sorting nil
  1262. "Options concerning sorting in the Org-mode Agenda."
  1263. :tag "Org Agenda Sorting"
  1264. :group 'org-agenda)
  1265. (defcustom org-agenda-sorting-strategy
  1266. '((agenda habit-down time-up priority-down category-keep)
  1267. (todo priority-down category-keep)
  1268. (tags priority-down category-keep)
  1269. (search category-keep))
  1270. "Sorting structure for the agenda items of a single day.
  1271. This is a list of symbols which will be used in sequence to determine
  1272. if an entry should be listed before another entry. The following
  1273. symbols are recognized:
  1274. time-up Put entries with time-of-day indications first, early first
  1275. time-down Put entries with time-of-day indications first, late first
  1276. timestamp-up Sort by any timestamp, early first
  1277. timestamp-down Sort by any timestamp, late first
  1278. scheduled-up Sort by scheduled timestamp, early first
  1279. scheduled-down Sort by scheduled timestamp, late first
  1280. deadline-up Sort by deadline timestamp, early first
  1281. deadline-down Sort by deadline timestamp, late first
  1282. ts-up Sort by active timestamp, early first
  1283. ts-down Sort by active timestamp, late first
  1284. tsia-up Sort by inactive timestamp, early first
  1285. tsia-down Sort by inactive timestamp, late first
  1286. category-keep Keep the default order of categories, corresponding to the
  1287. sequence in `org-agenda-files'.
  1288. category-up Sort alphabetically by category, A-Z.
  1289. category-down Sort alphabetically by category, Z-A.
  1290. tag-up Sort alphabetically by last tag, A-Z.
  1291. tag-down Sort alphabetically by last tag, Z-A.
  1292. priority-up Sort numerically by priority, high priority last.
  1293. priority-down Sort numerically by priority, high priority first.
  1294. todo-state-up Sort by todo state, tasks that are done last.
  1295. todo-state-down Sort by todo state, tasks that are done first.
  1296. effort-up Sort numerically by estimated effort, high effort last.
  1297. effort-down Sort numerically by estimated effort, high effort first.
  1298. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1299. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1300. habit-up Put entries that are habits first
  1301. habit-down Put entries that are habits last
  1302. alpha-up Sort headlines alphabetically
  1303. alpha-down Sort headlines alphabetically, reversed
  1304. The different possibilities will be tried in sequence, and testing stops
  1305. if one comparison returns a \"not-equal\". For example, the default
  1306. '(time-up category-keep priority-down)
  1307. means: Pull out all entries having a specified time of day and sort them,
  1308. in order to make a time schedule for the current day the first thing in the
  1309. agenda listing for the day. Of the entries without a time indication, keep
  1310. the grouped in categories, don't sort the categories, but keep them in
  1311. the sequence given in `org-agenda-files'. Within each category sort by
  1312. priority.
  1313. Leaving out `category-keep' would mean that items will be sorted across
  1314. categories by priority.
  1315. Instead of a single list, this can also be a set of list for specific
  1316. contents, with a context symbol in the car of the list, any of
  1317. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1318. Custom commands can bind this variable in the options section."
  1319. :group 'org-agenda-sorting
  1320. :type `(choice
  1321. (repeat :tag "General" ,org-sorting-choice)
  1322. (list :tag "Individually"
  1323. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1324. (repeat ,org-sorting-choice))
  1325. (cons (const :tag "Strategy for TODO lists" todo)
  1326. (repeat ,org-sorting-choice))
  1327. (cons (const :tag "Strategy for Tags matches" tags)
  1328. (repeat ,org-sorting-choice))
  1329. (cons (const :tag "Strategy for search matches" search)
  1330. (repeat ,org-sorting-choice)))))
  1331. (defcustom org-agenda-cmp-user-defined nil
  1332. "A function to define the comparison `user-defined'.
  1333. This function must receive two arguments, agenda entry a and b.
  1334. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1335. the user comparison, return nil.
  1336. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1337. part of an agenda sorting strategy."
  1338. :group 'org-agenda-sorting
  1339. :type 'symbol)
  1340. (defcustom org-sort-agenda-notime-is-late t
  1341. "Non-nil means items without time are considered late.
  1342. This is only relevant for sorting. When t, items which have no explicit
  1343. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1344. do have a time. When nil, the default time is before 0:00. You can use this
  1345. option to decide if the schedule for today should come before or after timeless
  1346. agenda entries."
  1347. :group 'org-agenda-sorting
  1348. :type 'boolean)
  1349. (defcustom org-sort-agenda-noeffort-is-high t
  1350. "Non-nil means items without effort estimate are sorted as high effort.
  1351. This also applies when filtering an agenda view with respect to the
  1352. < or > effort operator. Then, tasks with no effort defined will be treated
  1353. as tasks with high effort.
  1354. When nil, such items are sorted as 0 minutes effort."
  1355. :group 'org-agenda-sorting
  1356. :type 'boolean)
  1357. (defgroup org-agenda-line-format nil
  1358. "Options concerning the entry prefix in the Org-mode agenda display."
  1359. :tag "Org Agenda Line Format"
  1360. :group 'org-agenda)
  1361. (defcustom org-agenda-prefix-format
  1362. '((agenda . " %i %-12:c%?-12t% s")
  1363. (timeline . " % s")
  1364. (todo . " %i %-12:c")
  1365. (tags . " %i %-12:c")
  1366. (search . " %i %-12:c"))
  1367. "Format specifications for the prefix of items in the agenda views.
  1368. An alist with five entries, each for the different agenda types. The
  1369. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1370. The values are format strings.
  1371. This format works similar to a printf format, with the following meaning:
  1372. %c the category of the item, \"Diary\" for entries from the diary,
  1373. or as given by the CATEGORY keyword or derived from the file name
  1374. %e the effort required by the item
  1375. %l the level of the item (insert X space(s) if item is of level X)
  1376. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1377. %T the last tag of the item (ignore inherited tags, which come first)
  1378. %t the HH:MM time-of-day specification if one applies to the entry
  1379. %s Scheduling/Deadline information, a short string
  1380. %b show breadcrumbs, i.e., the names of the higher levels
  1381. %(expression) Eval EXPRESSION and replace the control string
  1382. by the result
  1383. All specifiers work basically like the standard `%s' of printf, but may
  1384. contain two additional characters: a question mark just after the `%'
  1385. and a whitespace/punctuation character just before the final letter.
  1386. If the first character after `%' is a question mark, the entire field
  1387. will only be included if the corresponding value applies to the current
  1388. entry. This is useful for fields which should have fixed width when
  1389. present, but zero width when absent. For example, \"%?-12t\" will
  1390. result in a 12 character time field if a time of the day is specified,
  1391. but will completely disappear in entries which do not contain a time.
  1392. If there is punctuation or whitespace character just before the
  1393. final format letter, this character will be appended to the field
  1394. value if the value is not empty. For example, the format
  1395. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1396. the category is empty, no additional colon is inserted.
  1397. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1398. which means:
  1399. - Indent the line with two space characters
  1400. - Give the category a 12 chars wide field, padded with whitespace on
  1401. the right (because of `-'). Append a colon if there is a category
  1402. (because of `:').
  1403. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1404. time, don't put in an empty field, just skip it (because of '?').
  1405. - Finally, put the scheduling information.
  1406. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1407. `org-agenda-remove-tags'.
  1408. Custom commands can set this variable in the options section."
  1409. :type '(choice
  1410. (string :tag "General format")
  1411. (list :greedy t :tag "View dependent"
  1412. (cons (const agenda) (string :tag "Format"))
  1413. (cons (const timeline) (string :tag "Format"))
  1414. (cons (const todo) (string :tag "Format"))
  1415. (cons (const tags) (string :tag "Format"))
  1416. (cons (const search) (string :tag "Format"))))
  1417. :group 'org-agenda-line-format)
  1418. (defvar org-prefix-format-compiled nil
  1419. "The compiled prefix format and associated variables.
  1420. This is a list where first element is a list of variable bindings, and second
  1421. element is the compiled format expression. See the variable
  1422. `org-agenda-prefix-format'.")
  1423. (defcustom org-agenda-todo-keyword-format "%-1s"
  1424. "Format for the TODO keyword in agenda lines.
  1425. Set this to something like \"%-12s\" if you want all TODO keywords
  1426. to occupy a fixed space in the agenda display."
  1427. :group 'org-agenda-line-format
  1428. :type 'string)
  1429. (defcustom org-agenda-diary-sexp-prefix nil
  1430. "A regexp that matches part of a diary sexp entry
  1431. which should be treated as scheduling/deadline information in
  1432. `org-agenda'.
  1433. For example, you can use this to extract the `diary-remind-message' from
  1434. `diary-remind' entries."
  1435. :group 'org-agenda-line-format
  1436. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1437. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1438. "Text preceding timerange entries in the agenda view.
  1439. This is a list with two strings. The first applies when the range
  1440. is entirely on one day. The second applies if the range spans several days.
  1441. The strings may have two \"%d\" format specifiers which will be filled
  1442. with the sequence number of the days, and the total number of days in the
  1443. range, respectively."
  1444. :group 'org-agenda-line-format
  1445. :type '(list
  1446. (string :tag "Deadline today ")
  1447. (choice :tag "Deadline relative"
  1448. (string :tag "Format string")
  1449. (function))))
  1450. (defcustom org-agenda-scheduled-leaders '(" Scheduled: " "Sched.%3dx: ")
  1451. "Text preceding scheduled items in the agenda view.
  1452. This is a list with two strings. The first applies when the item is
  1453. scheduled on the current day. The second applies when it has been scheduled
  1454. previously, it may contain a %d indicating that this is the nth time that
  1455. this item is scheduled, due to automatic rescheduling of unfinished items
  1456. for the following day. So this number is one larger than the number of days
  1457. that passed since this item was scheduled first."
  1458. :group 'org-agenda-line-format
  1459. :version "24.4"
  1460. :package-version '(Org . "8.0")
  1461. :type '(list
  1462. (string :tag "Scheduled today ")
  1463. (string :tag "Scheduled previously")))
  1464. (defcustom org-agenda-inactive-leader "["
  1465. "Text preceding item pulled into the agenda by inactive time stamps.
  1466. These entries are added to the agenda when pressing \"[\"."
  1467. :group 'org-agenda-line-format
  1468. :version "24.1"
  1469. :type '(list
  1470. (string :tag "Scheduled today ")
  1471. (string :tag "Scheduled previously")))
  1472. (defcustom org-agenda-deadline-leaders '(" Deadline: " " In %3d d.: " "%3d d. ago: ")
  1473. "Text preceding deadline items in the agenda view.
  1474. This is a list with three strings. The first applies when the item has its
  1475. deadline on the current day. The second applies when the deadline is in the
  1476. future, the third one when it is in the past. The strings may contain %d
  1477. to capture the number of days."
  1478. :group 'org-agenda-line-format
  1479. :version "24.4"
  1480. :package-version '(Org . "8.0")
  1481. :type '(list
  1482. (string :tag "Deadline today ")
  1483. (choice :tag "Deadline relative"
  1484. (string :tag "Format string")
  1485. (function))))
  1486. (defcustom org-agenda-remove-times-when-in-prefix t
  1487. "Non-nil means remove duplicate time specifications in agenda items.
  1488. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1489. time-of-day specification in a headline or diary entry is extracted and
  1490. placed into the prefix. If this option is non-nil, the original specification
  1491. \(a timestamp or -range, or just a plain time(range) specification like
  1492. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1493. cluttered.
  1494. The option can be t or nil. It may also be the symbol `beg', indicating
  1495. that the time should only be removed when it is located at the beginning of
  1496. the headline/diary entry."
  1497. :group 'org-agenda-line-format
  1498. :type '(choice
  1499. (const :tag "Always" t)
  1500. (const :tag "Never" nil)
  1501. (const :tag "When at beginning of entry" beg)))
  1502. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1503. "Non-nil means remove time ranges specifications in agenda
  1504. items that span on several days."
  1505. :group 'org-agenda-line-format
  1506. :version "24.1"
  1507. :type 'boolean)
  1508. (defcustom org-agenda-default-appointment-duration nil
  1509. "Default duration for appointments that only have a starting time.
  1510. When nil, no duration is specified in such cases.
  1511. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1512. :group 'org-agenda-line-format
  1513. :type '(choice
  1514. (integer :tag "Minutes")
  1515. (const :tag "No default duration")))
  1516. (defcustom org-agenda-show-inherited-tags t
  1517. "Non-nil means show inherited tags in each agenda line.
  1518. When this option is set to 'always, it take precedences over
  1519. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1520. in every agenda.
  1521. When this option is set to t (the default), inherited tags are
  1522. shown when they are available, i.e. when the value of
  1523. `org-agenda-use-tag-inheritance' has been taken into account.
  1524. This can be set to a list of agenda types in which the agenda
  1525. must display the inherited tags. Available types are 'todo,
  1526. 'agenda, 'search and 'timeline.
  1527. When set to nil, never show inherited tags in agenda lines."
  1528. :group 'org-agenda-line-format
  1529. :group 'org-agenda
  1530. :version "24.3"
  1531. :type '(choice
  1532. (const :tag "Show inherited tags when available" t)
  1533. (const :tag "Always show inherited tags" 'always)
  1534. (repeat :tag "Show inherited tags only in selected agenda types"
  1535. (symbol :tag "Agenda type"))))
  1536. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1537. "List of agenda view types where to use tag inheritance.
  1538. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1539. controlled by `org-use-tag-inheritance'. In other agenda types,
  1540. `org-use-tag-inheritance' is not used for the selection of the
  1541. agenda entries. Still, you may want the agenda to be aware of
  1542. the inherited tags anyway, e.g. for later tag filtering.
  1543. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1544. This variable has no effect if `org-agenda-show-inherited-tags'
  1545. is set to 'always. In that case, the agenda is aware of those
  1546. tags.
  1547. The default value sets tags in every agenda type. Setting this
  1548. option to nil will speed up non-tags agenda view a lot."
  1549. :group 'org-agenda
  1550. :version "24.3"
  1551. :type '(choice
  1552. (const :tag "Use tag inheritance in all agenda types" t)
  1553. (repeat :tag "Use tag inheritance in selected agenda types"
  1554. (symbol :tag "Agenda type"))))
  1555. (defcustom org-agenda-hide-tags-regexp nil
  1556. "Regular expression used to filter away specific tags in agenda views.
  1557. This means that these tags will be present, but not be shown in the agenda
  1558. line. Secondary filtering will still work on the hidden tags.
  1559. Nil means don't hide any tags."
  1560. :group 'org-agenda-line-format
  1561. :type '(choice
  1562. (const :tag "Hide none" nil)
  1563. (string :tag "Regexp ")))
  1564. (defcustom org-agenda-remove-tags nil
  1565. "Non-nil means remove the tags from the headline copy in the agenda.
  1566. When this is the symbol `prefix', only remove tags when
  1567. `org-agenda-prefix-format' contains a `%T' specifier."
  1568. :group 'org-agenda-line-format
  1569. :type '(choice
  1570. (const :tag "Always" t)
  1571. (const :tag "Never" nil)
  1572. (const :tag "When prefix format contains %T" prefix)))
  1573. (if (fboundp 'defvaralias)
  1574. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1575. 'org-agenda-remove-tags))
  1576. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1577. "Shift tags in agenda items to this column.
  1578. If this number is positive, it specifies the column. If it is negative,
  1579. it means that the tags should be flushright to that column. For example,
  1580. -80 works well for a normal 80 character screen."
  1581. :group 'org-agenda-line-format
  1582. :type 'integer)
  1583. (if (fboundp 'defvaralias)
  1584. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1585. (defcustom org-agenda-fontify-priorities 'cookies
  1586. "Non-nil means highlight low and high priorities in agenda.
  1587. When t, the highest priority entries are bold, lowest priority italic.
  1588. However, settings in `org-priority-faces' will overrule these faces.
  1589. When this variable is the symbol `cookies', only fontify the
  1590. cookies, not the entire task.
  1591. This may also be an association list of priority faces, whose
  1592. keys are the character values of `org-highest-priority',
  1593. `org-default-priority', and `org-lowest-priority' (the default values
  1594. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1595. color as a string, or a list like `(:background \"Red\")'.
  1596. If it is a color, the variable `org-faces-easy-properties'
  1597. determines if it is a foreground or a background color."
  1598. :group 'org-agenda-line-format
  1599. :type '(choice
  1600. (const :tag "Never" nil)
  1601. (const :tag "Defaults" t)
  1602. (const :tag "Cookies only" cookies)
  1603. (repeat :tag "Specify"
  1604. (list (character :tag "Priority" :value ?A)
  1605. (choice :tag "Face "
  1606. (string :tag "Color")
  1607. (sexp :tag "Face"))))))
  1608. (defcustom org-agenda-day-face-function nil
  1609. "Function called to determine what face should be used to display a day.
  1610. The only argument passed to that function is the day. It should
  1611. returns a face, or nil if does not want to specify a face and let
  1612. the normal rules apply."
  1613. :group 'org-agenda-line-format
  1614. :version "24.1"
  1615. :type 'function)
  1616. (defcustom org-agenda-category-icon-alist nil
  1617. "Alist of category icon to be displayed in agenda views.
  1618. Each entry should have the following format:
  1619. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1620. Where CATEGORY-REGEXP is a regexp matching the categories where
  1621. the icon should be displayed.
  1622. FILE-OR-DATA either a file path or a string containing image data.
  1623. The other fields can be omitted safely if not needed:
  1624. TYPE indicates the image type.
  1625. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1626. image data.
  1627. PROPS are additional image attributes to assign to the image,
  1628. like, e.g. `:ascent center'.
  1629. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1630. If you want to set the display properties yourself, just put a
  1631. list as second element:
  1632. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1633. For example, to display a 16px horizontal space for Emacs
  1634. category, you can use:
  1635. (\"Emacs\" '(space . (:width (16))))"
  1636. :group 'org-agenda-line-format
  1637. :version "24.1"
  1638. :type '(alist :key-type (string :tag "Regexp matching category")
  1639. :value-type (choice (list :tag "Icon"
  1640. (string :tag "File or data")
  1641. (symbol :tag "Type")
  1642. (boolean :tag "Data?")
  1643. (repeat :tag "Extra image properties" :inline t symbol))
  1644. (list :tag "Display properties" sexp))))
  1645. (defgroup org-agenda-column-view nil
  1646. "Options concerning column view in the agenda."
  1647. :tag "Org Agenda Column View"
  1648. :group 'org-agenda)
  1649. (defcustom org-agenda-columns-show-summaries t
  1650. "Non-nil means show summaries for columns displayed in the agenda view."
  1651. :group 'org-agenda-column-view
  1652. :type 'boolean)
  1653. (defcustom org-agenda-columns-compute-summary-properties t
  1654. "Non-nil means recompute all summary properties before column view.
  1655. When column view in the agenda is listing properties that have a summary
  1656. operator, it can go to all relevant buffers and recompute the summaries
  1657. there. This can mean overhead for the agenda column view, but is necessary
  1658. to have thing up to date.
  1659. As a special case, a CLOCKSUM property also makes sure that the clock
  1660. computations are current."
  1661. :group 'org-agenda-column-view
  1662. :type 'boolean)
  1663. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1664. "Non-nil means the duration of an appointment will add to day effort.
  1665. The property to which appointment durations will be added is the one given
  1666. in the option `org-effort-property'. If an appointment does not have
  1667. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1668. is not set, an appointment without end time will not contribute to the time
  1669. estimate."
  1670. :group 'org-agenda-column-view
  1671. :type 'boolean)
  1672. (defcustom org-agenda-auto-exclude-function nil
  1673. "A function called with a tag to decide if it is filtered on '/ RET'.
  1674. The sole argument to the function, which is called once for each
  1675. possible tag, is a string giving the name of the tag. The
  1676. function should return either nil if the tag should be included
  1677. as normal, or \"-<TAG>\" to exclude the tag.
  1678. Note that for the purpose of tag filtering, only the lower-case version of
  1679. all tags will be considered, so that this function will only ever see
  1680. the lower-case version of all tags."
  1681. :group 'org-agenda
  1682. :type 'function)
  1683. (defcustom org-agenda-bulk-custom-functions nil
  1684. "Alist of characters and custom functions for bulk actions.
  1685. For example, this value makes those two functions available:
  1686. '((?R set-category)
  1687. (?C bulk-cut))
  1688. With selected entries in an agenda buffer, `B R' will call
  1689. the custom function `set-category' on the selected entries.
  1690. Note that functions in this alist don't need to be quoted."
  1691. :type 'alist
  1692. :version "24.1"
  1693. :group 'org-agenda)
  1694. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1695. "Execute BODY with point at location given by `org-hd-marker' property.
  1696. If STRING is non-nil, the text property will be fetched from position 0
  1697. in that string. If STRING is nil, it will be fetched from the beginning
  1698. of the current line."
  1699. (org-with-gensyms (marker)
  1700. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1701. 'org-hd-marker ,string)))
  1702. (with-current-buffer (marker-buffer ,marker)
  1703. (save-excursion
  1704. (goto-char ,marker)
  1705. ,@body)))))
  1706. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1707. (defun org-add-agenda-custom-command (entry)
  1708. "Replace or add a command in `org-agenda-custom-commands'.
  1709. This is mostly for hacking and trying a new command - once the command
  1710. works you probably want to add it to `org-agenda-custom-commands' for good."
  1711. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1712. (if ass
  1713. (setcdr ass (cdr entry))
  1714. (push entry org-agenda-custom-commands))))
  1715. ;;; Define the org-agenda-mode
  1716. (defvar org-agenda-mode-map (make-sparse-keymap)
  1717. "Keymap for `org-agenda-mode'.")
  1718. (if (fboundp 'defvaralias)
  1719. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1720. (defvar org-agenda-menu) ; defined later in this file.
  1721. (defvar org-agenda-restrict nil) ; defined later in this file.
  1722. (defvar org-agenda-follow-mode nil)
  1723. (defvar org-agenda-entry-text-mode nil)
  1724. (defvar org-agenda-clockreport-mode nil)
  1725. (defvar org-agenda-show-log nil)
  1726. (defvar org-agenda-redo-command nil)
  1727. (defvar org-agenda-query-string nil)
  1728. (defvar org-agenda-mode-hook nil
  1729. "Hook run after `org-agenda-mode' is turned on.
  1730. The buffer is still writable when this hook is called.")
  1731. (defvar org-agenda-type nil)
  1732. (defvar org-agenda-force-single-file nil)
  1733. (defvar org-agenda-bulk-marked-entries nil
  1734. "List of markers that refer to marked entries in the agenda.")
  1735. ;;; Multiple agenda buffers support
  1736. (defcustom org-agenda-sticky nil
  1737. "Non-nil means agenda q key will bury agenda buffers.
  1738. Agenda commands will then show existing buffer instead of generating new ones.
  1739. When nil, `q' will kill the single agenda buffer."
  1740. :group 'org-agenda
  1741. :version "24.3"
  1742. :type 'boolean)
  1743. ;;;###autoload
  1744. (defun org-toggle-sticky-agenda (&optional arg)
  1745. "Toggle `org-agenda-sticky'."
  1746. (interactive "P")
  1747. (let ((new-value (if arg
  1748. (> (prefix-numeric-value arg) 0)
  1749. (not org-agenda-sticky))))
  1750. (if (equal new-value org-agenda-sticky)
  1751. (and (org-called-interactively-p 'interactive)
  1752. (message "Sticky agenda was already %s"
  1753. (if org-agenda-sticky "enabled" "disabled")))
  1754. (setq org-agenda-sticky new-value)
  1755. (org-agenda-kill-all-agenda-buffers)
  1756. (and (org-called-interactively-p 'interactive)
  1757. (message "Sticky agenda was %s"
  1758. (if org-agenda-sticky "enabled" "disabled"))))))
  1759. (defvar org-agenda-buffer nil
  1760. "Agenda buffer currently being generated.")
  1761. (defvar org-agenda-last-prefix-arg nil)
  1762. (defvar org-agenda-this-buffer-name nil)
  1763. (defvar org-agenda-doing-sticky-redo nil)
  1764. (defvar org-agenda-this-buffer-is-sticky nil)
  1765. (defconst org-agenda-local-vars
  1766. '(org-agenda-this-buffer-name
  1767. org-agenda-undo-list
  1768. org-agenda-pending-undo-list
  1769. org-agenda-follow-mode
  1770. org-agenda-entry-text-mode
  1771. org-agenda-clockreport-mode
  1772. org-agenda-show-log
  1773. org-agenda-redo-command
  1774. org-agenda-query-string
  1775. org-agenda-type
  1776. org-agenda-bulk-marked-entries
  1777. org-agenda-undo-has-started-in
  1778. org-agenda-info
  1779. org-agenda-tag-filter-overlays
  1780. org-agenda-cat-filter-overlays
  1781. org-agenda-pre-window-conf
  1782. org-agenda-columns-active
  1783. org-agenda-tag-filter
  1784. org-agenda-category-filter
  1785. org-agenda-markers
  1786. org-agenda-last-search-view-search-was-boolean
  1787. org-agenda-filtered-by-category
  1788. org-agenda-filter-form
  1789. org-agenda-cycle-counter
  1790. org-agenda-last-prefix-arg)
  1791. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1792. (defun org-agenda-mode ()
  1793. "Mode for time-sorted view on action items in Org-mode files.
  1794. The following commands are available:
  1795. \\{org-agenda-mode-map}"
  1796. (interactive)
  1797. (cond (org-agenda-doing-sticky-redo
  1798. ;; Refreshing sticky agenda-buffer
  1799. ;;
  1800. ;; Preserve the value of `org-agenda-local-vars' variables,
  1801. ;; while letting `kill-all-local-variables' kill the rest
  1802. (let ((save (buffer-local-variables)))
  1803. (kill-all-local-variables)
  1804. (mapc 'make-local-variable org-agenda-local-vars)
  1805. (dolist (elem save)
  1806. (let ((var (car elem))
  1807. (val (cdr elem)))
  1808. (when (and val
  1809. (member var org-agenda-local-vars))
  1810. (set var val)))))
  1811. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1812. (org-agenda-sticky
  1813. ;; Creating a sticky Agenda buffer for the first time
  1814. (kill-all-local-variables)
  1815. (mapc 'make-local-variable org-agenda-local-vars)
  1816. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1817. (t
  1818. ;; Creating a non-sticky agenda buffer
  1819. (kill-all-local-variables)
  1820. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1821. (setq org-agenda-undo-list nil
  1822. org-agenda-pending-undo-list nil
  1823. org-agenda-bulk-marked-entries nil)
  1824. (setq major-mode 'org-agenda-mode)
  1825. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1826. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1827. (setq mode-name "Org-Agenda")
  1828. (use-local-map org-agenda-mode-map)
  1829. (easy-menu-add org-agenda-menu)
  1830. (if org-startup-truncated (setq truncate-lines t))
  1831. (org-set-local 'line-move-visual nil)
  1832. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1833. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1834. ;; Make sure properties are removed when copying text
  1835. (make-local-variable 'filter-buffer-substring-functions)
  1836. (add-hook 'filter-buffer-substring-functions
  1837. (lambda (fun start end delete)
  1838. (substring-no-properties (funcall fun start end delete))))
  1839. (unless org-agenda-keep-modes
  1840. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1841. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1842. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1843. org-agenda-show-log org-agenda-start-with-log-mode))
  1844. (easy-menu-change
  1845. '("Agenda") "Agenda Files"
  1846. (append
  1847. (list
  1848. (vector
  1849. (if (get 'org-agenda-files 'org-restrict)
  1850. "Restricted to single file"
  1851. "Edit File List")
  1852. '(org-edit-agenda-file-list)
  1853. (not (get 'org-agenda-files 'org-restrict)))
  1854. "--")
  1855. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1856. (org-agenda-set-mode-name)
  1857. (apply
  1858. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1859. (list 'org-agenda-mode-hook)))
  1860. (substitute-key-definition 'undo 'org-agenda-undo
  1861. org-agenda-mode-map global-map)
  1862. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1863. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1864. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1865. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1866. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1867. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1868. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1869. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1870. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1871. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1872. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1873. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1874. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1875. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1877. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1878. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1879. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1880. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1881. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1882. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1883. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1884. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1885. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1886. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1887. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1888. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1889. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1890. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1891. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1892. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1893. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1894. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1895. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1896. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1897. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1898. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1899. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1900. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1901. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1902. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1903. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1904. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1905. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1906. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1907. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1908. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1909. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1910. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1911. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1912. (while l (org-defkey org-agenda-mode-map
  1913. (int-to-string (pop l)) 'digit-argument)))
  1914. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1915. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1916. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1917. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1918. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1919. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1920. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1921. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1922. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1923. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1924. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1925. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1926. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1927. 'org-clock-modify-effort-estimate)
  1928. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1929. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1930. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1931. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1932. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1933. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1934. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1935. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1936. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1937. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1938. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1939. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1940. (substitute-key-definition 'next-line 'org-agenda-next-line
  1941. org-agenda-mode-map global-map)
  1942. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1943. org-agenda-mode-map global-map)
  1944. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1945. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1946. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1947. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1948. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1949. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1950. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1951. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1952. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1953. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1954. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1955. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1956. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1957. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1958. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1959. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1960. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1961. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1962. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1963. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1964. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1965. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1966. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1967. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1968. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1969. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1970. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1971. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1972. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1973. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1974. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1975. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1976. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1977. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1978. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1979. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1980. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1981. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1982. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1983. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1984. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1985. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1986. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1987. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1988. (when org-agenda-mouse-1-follows-link
  1989. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1990. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1991. '("Agenda"
  1992. ("Agenda Files")
  1993. "--"
  1994. ("Agenda Dates"
  1995. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1996. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1997. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1998. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1999. "--"
  2000. ("View"
  2001. ["Day View" org-agenda-day-view
  2002. :active (org-agenda-check-type nil 'agenda)
  2003. :style radio :selected (eq org-agenda-current-span 'day)
  2004. :keys "v d (or just d)"]
  2005. ["Week View" org-agenda-week-view
  2006. :active (org-agenda-check-type nil 'agenda)
  2007. :style radio :selected (eq org-agenda-current-span 'week)
  2008. :keys "v w (or just w)"]
  2009. ["Month View" org-agenda-month-view
  2010. :active (org-agenda-check-type nil 'agenda)
  2011. :style radio :selected (eq org-agenda-current-span 'month)
  2012. :keys "v m"]
  2013. ["Year View" org-agenda-year-view
  2014. :active (org-agenda-check-type nil 'agenda)
  2015. :style radio :selected (eq org-agenda-current-span 'year)
  2016. :keys "v y"]
  2017. "--"
  2018. ["Include Diary" org-agenda-toggle-diary
  2019. :style toggle :selected org-agenda-include-diary
  2020. :active (org-agenda-check-type nil 'agenda)]
  2021. ["Include Deadlines" org-agenda-toggle-deadlines
  2022. :style toggle :selected org-agenda-include-deadlines
  2023. :active (org-agenda-check-type nil 'agenda)]
  2024. ["Use Time Grid" org-agenda-toggle-time-grid
  2025. :style toggle :selected org-agenda-use-time-grid
  2026. :active (org-agenda-check-type nil 'agenda)]
  2027. "--"
  2028. ["Show clock report" org-agenda-clockreport-mode
  2029. :style toggle :selected org-agenda-clockreport-mode
  2030. :active (org-agenda-check-type nil 'agenda)]
  2031. ["Show some entry text" org-agenda-entry-text-mode
  2032. :style toggle :selected org-agenda-entry-text-mode
  2033. :active t]
  2034. "--"
  2035. ["Show Logbook entries" org-agenda-log-mode
  2036. :style toggle :selected org-agenda-show-log
  2037. :active (org-agenda-check-type nil 'agenda 'timeline)
  2038. :keys "v l (or just l)"]
  2039. ["Include archived trees" org-agenda-archives-mode
  2040. :style toggle :selected org-agenda-archives-mode :active t
  2041. :keys "v a"]
  2042. ["Include archive files" (org-agenda-archives-mode t)
  2043. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2044. :keys "v A"]
  2045. "--"
  2046. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2047. ["Write view to file" org-agenda-write t]
  2048. ["Rebuild buffer" org-agenda-redo t]
  2049. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2050. "--"
  2051. ["Show original entry" org-agenda-show t]
  2052. ["Go To (other window)" org-agenda-goto t]
  2053. ["Go To (this window)" org-agenda-switch-to t]
  2054. ["Capture with cursor date" org-agenda-capture t]
  2055. ["Follow Mode" org-agenda-follow-mode
  2056. :style toggle :selected org-agenda-follow-mode :active t]
  2057. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2058. "--"
  2059. ("TODO"
  2060. ["Cycle TODO" org-agenda-todo t]
  2061. ["Next TODO set" org-agenda-todo-nextset t]
  2062. ["Previous TODO set" org-agenda-todo-previousset t]
  2063. ["Add note" org-agenda-add-note t])
  2064. ("Archive/Refile/Delete"
  2065. ["Archive default" org-agenda-archive-default t]
  2066. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2067. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2068. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2069. ["Archive subtree" org-agenda-archive t]
  2070. "--"
  2071. ["Refile" org-agenda-refile t]
  2072. "--"
  2073. ["Delete subtree" org-agenda-kill t])
  2074. ("Bulk action"
  2075. ["Mark entry" org-agenda-bulk-mark t]
  2076. ["Mark all" org-agenda-bulk-mark-all t]
  2077. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2078. ["Unmark entry" org-agenda-bulk-unmark t]
  2079. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2080. ["Act on all marked" org-agenda-bulk-action t]
  2081. "--"
  2082. ("Tags and Properties"
  2083. ["Show all Tags" org-agenda-show-tags t]
  2084. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2085. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2086. "--"
  2087. ["Column View" org-columns t])
  2088. ("Deadline/Schedule"
  2089. ["Schedule" org-agenda-schedule t]
  2090. ["Set Deadline" org-agenda-deadline t]
  2091. "--"
  2092. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2093. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2094. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2095. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2096. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2097. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2098. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2099. ("Clock and Effort"
  2100. ["Clock in" org-agenda-clock-in t]
  2101. ["Clock out" org-agenda-clock-out t]
  2102. ["Clock cancel" org-agenda-clock-cancel t]
  2103. ["Goto running clock" org-clock-goto t]
  2104. "--"
  2105. ["Set Effort" org-agenda-set-effort t]
  2106. ["Change clocked effort" org-clock-modify-effort-estimate
  2107. (org-clock-is-active)])
  2108. ("Priority"
  2109. ["Set Priority" org-agenda-priority t]
  2110. ["Increase Priority" org-agenda-priority-up t]
  2111. ["Decrease Priority" org-agenda-priority-down t]
  2112. ["Show Priority" org-show-priority t])
  2113. ("Calendar/Diary"
  2114. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2115. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2116. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2117. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2118. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2119. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2120. "--"
  2121. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2122. "--"
  2123. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2124. "--"
  2125. ("MobileOrg"
  2126. ["Push Files and Views" org-mobile-push t]
  2127. ["Get Captured and Flagged" org-mobile-pull t]
  2128. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2129. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2130. "--"
  2131. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2132. "--"
  2133. ["Quit" org-agenda-quit t]
  2134. ["Exit and Release Buffers" org-agenda-exit t]
  2135. ))
  2136. ;;; Agenda undo
  2137. (defvar org-agenda-allow-remote-undo t
  2138. "Non-nil means allow remote undo from the agenda buffer.")
  2139. (defvar org-agenda-undo-has-started-in nil
  2140. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2141. (defun org-agenda-undo ()
  2142. "Undo a remote editing step in the agenda.
  2143. This undoes changes both in the agenda buffer and in the remote buffer
  2144. that have been changed along."
  2145. (interactive)
  2146. (or org-agenda-allow-remote-undo
  2147. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2148. (if (not (eq this-command last-command))
  2149. (setq org-agenda-undo-has-started-in nil
  2150. org-agenda-pending-undo-list org-agenda-undo-list))
  2151. (if (not org-agenda-pending-undo-list)
  2152. (error "No further undo information"))
  2153. (let* ((entry (pop org-agenda-pending-undo-list))
  2154. buf line cmd rembuf)
  2155. (setq cmd (pop entry) line (pop entry))
  2156. (setq rembuf (nth 2 entry))
  2157. (org-with-remote-undo rembuf
  2158. (while (bufferp (setq buf (pop entry)))
  2159. (if (pop entry)
  2160. (with-current-buffer buf
  2161. (let ((last-undo-buffer buf)
  2162. (inhibit-read-only t))
  2163. (unless (memq buf org-agenda-undo-has-started-in)
  2164. (push buf org-agenda-undo-has-started-in)
  2165. (make-local-variable 'pending-undo-list)
  2166. (undo-start))
  2167. (while (and pending-undo-list
  2168. (listp pending-undo-list)
  2169. (not (car pending-undo-list)))
  2170. (pop pending-undo-list))
  2171. (undo-more 1))))))
  2172. (org-goto-line line)
  2173. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2174. (defun org-verify-change-for-undo (l1 l2)
  2175. "Verify that a real change occurred between the undo lists L1 and L2."
  2176. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2177. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2178. (not (eq l1 l2)))
  2179. ;;; Agenda dispatch
  2180. (defvar org-agenda-restrict-begin (make-marker))
  2181. (defvar org-agenda-restrict-end (make-marker))
  2182. (defvar org-agenda-last-dispatch-buffer nil)
  2183. (defvar org-agenda-overriding-restriction nil)
  2184. (defcustom org-agenda-custom-commands-contexts nil
  2185. "Alist of custom agenda keys and contextual rules.
  2186. For example, if you have a custom agenda command \"p\" and you
  2187. want this command to be accessible only from plain text files,
  2188. use this:
  2189. '((\"p\" ((in-file . \"\\.txt\"))))
  2190. Here are the available contexts definitions:
  2191. in-file: command displayed only in matching files
  2192. in-mode: command displayed only in matching modes
  2193. not-in-file: command not displayed in matching files
  2194. not-in-mode: command not displayed in matching modes
  2195. in-buffer: command displayed only in matching buffers
  2196. not-in-buffer: command not displayed in matching buffers
  2197. [function]: a custom function taking no argument
  2198. If you define several checks, the agenda command will be
  2199. accessible if there is at least one valid check.
  2200. You can also bind a key to another agenda custom command
  2201. depending on contextual rules.
  2202. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2203. Here it means: in .txt files, use \"p\" as the key for the
  2204. agenda command otherwise associated with \"q\". (The command
  2205. originally associated with \"q\" is not displayed to avoid
  2206. duplicates.)"
  2207. :version "24.3"
  2208. :group 'org-agenda-custom-commands
  2209. :type '(repeat (list :tag "Rule"
  2210. (string :tag " Agenda key")
  2211. (string :tag "Replace by command")
  2212. (repeat :tag "Available when"
  2213. (choice
  2214. (cons :tag "Condition"
  2215. (choice
  2216. (const :tag "In file" in-file)
  2217. (const :tag "Not in file" not-in-file)
  2218. (const :tag "In buffer" in-buffer)
  2219. (const :tag "Not in buffer" not-in-buffer)
  2220. (const :tag "In mode" in-mode)
  2221. (const :tag "Not in mode" not-in-mode))
  2222. (regexp))
  2223. (function :tag "Custom function"))))))
  2224. (defcustom org-agenda-max-entries nil
  2225. "Maximum number of entries to display in an agenda.
  2226. This can be nil (no limit) or an integer or an alist of agenda
  2227. types with an associated number of entries to display in this
  2228. type."
  2229. :version "24.4"
  2230. :package-version '(Org . "8.0")
  2231. :group 'org-agenda-custom-commands
  2232. :type '(choice (symbol :tag "No limit" nil)
  2233. (integer :tag "Max number of entries")
  2234. (repeat
  2235. (cons (choice :tag "Agenda type"
  2236. (const agenda)
  2237. (const todo)
  2238. (const tags)
  2239. (const search)
  2240. (const timeline))
  2241. (integer :tag "Max number of entries")))))
  2242. (defcustom org-agenda-max-todos nil
  2243. "Maximum number of TODOs to display in an agenda.
  2244. This can be nil (no limit) or an integer or an alist of agenda
  2245. types with an associated number of entries to display in this
  2246. type."
  2247. :version "24.4"
  2248. :package-version '(Org . "8.0")
  2249. :group 'org-agenda-custom-commands
  2250. :type '(choice (symbol :tag "No limit" nil)
  2251. (integer :tag "Max number of entries")
  2252. (repeat
  2253. (cons (choice :tag "Agenda type"
  2254. (const agenda)
  2255. (const todo)
  2256. (const tags)
  2257. (const search)
  2258. (const timeline))
  2259. (integer :tag "Max number of entries")))))
  2260. (defcustom org-agenda-max-tags nil
  2261. "Maximum number of tagged entries to display in an agenda.
  2262. This can be nil (no limit) or an integer or an alist of agenda
  2263. types with an associated number of entries to display in this
  2264. type."
  2265. :version "24.4"
  2266. :package-version '(Org . "8.0")
  2267. :group 'org-agenda-custom-commands
  2268. :type '(choice (symbol :tag "No limit" nil)
  2269. (integer :tag "Max number of entries")
  2270. (repeat
  2271. (cons (choice :tag "Agenda type"
  2272. (const agenda)
  2273. (const todo)
  2274. (const tags)
  2275. (const search)
  2276. (const timeline))
  2277. (integer :tag "Max number of entries")))))
  2278. (defcustom org-agenda-max-effort nil
  2279. "Maximum cumulated effort duration for the agenda.
  2280. This can be nil (no limit) or a number of minutes (as an integer)
  2281. or an alist of agenda types with an associated number of minutes
  2282. to limit entries to in this type."
  2283. :version "24.4"
  2284. :package-version '(Org . "8.0")
  2285. :group 'org-agenda-custom-commands
  2286. :type '(choice (symbol :tag "No limit" nil)
  2287. (integer :tag "Max number of entries")
  2288. (repeat
  2289. (cons (choice :tag "Agenda type"
  2290. (const agenda)
  2291. (const todo)
  2292. (const tags)
  2293. (const search)
  2294. (const timeline))
  2295. (integer :tag "Max number of entries")))))
  2296. (defvar org-keys nil)
  2297. (defvar org-match nil)
  2298. ;;;###autoload
  2299. (defun org-agenda (&optional arg org-keys restriction)
  2300. "Dispatch agenda commands to collect entries to the agenda buffer.
  2301. Prompts for a command to execute. Any prefix arg will be passed
  2302. on to the selected command. The default selections are:
  2303. a Call `org-agenda-list' to display the agenda for current day or week.
  2304. t Call `org-todo-list' to display the global todo list.
  2305. T Call `org-todo-list' to display the global todo list, select only
  2306. entries with a specific TODO keyword (the user gets a prompt).
  2307. m Call `org-tags-view' to display headlines with tags matching
  2308. a condition (the user is prompted for the condition).
  2309. M Like `m', but select only TODO entries, no ordinary headlines.
  2310. L Create a timeline for the current buffer.
  2311. e Export views to associated files.
  2312. s Search entries for keywords.
  2313. S Search entries for keywords, only with TODO keywords.
  2314. / Multi occur across all agenda files and also files listed
  2315. in `org-agenda-text-search-extra-files'.
  2316. < Restrict agenda commands to buffer, subtree, or region.
  2317. Press several times to get the desired effect.
  2318. > Remove a previous restriction.
  2319. # List \"stuck\" projects.
  2320. ! Configure what \"stuck\" means.
  2321. C Configure custom agenda commands.
  2322. More commands can be added by configuring the variable
  2323. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2324. searches can be pre-defined in this way.
  2325. If the current buffer is in Org-mode and visiting a file, you can also
  2326. first press `<' once to indicate that the agenda should be temporarily
  2327. \(until the next use of \\[org-agenda]) restricted to the current file.
  2328. Pressing `<' twice means to restrict to the current subtree or region
  2329. \(if active)."
  2330. (interactive "P")
  2331. (catch 'exit
  2332. (let* ((prefix-descriptions nil)
  2333. (org-agenda-buffer-name org-agenda-buffer-name)
  2334. (org-agenda-window-setup (if (equal (buffer-name)
  2335. org-agenda-buffer-name)
  2336. 'current-window
  2337. org-agenda-window-setup))
  2338. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2339. (org-agenda-custom-commands
  2340. ;; normalize different versions
  2341. (delq nil
  2342. (mapcar
  2343. (lambda (x)
  2344. (cond ((stringp (cdr x))
  2345. (push x prefix-descriptions)
  2346. nil)
  2347. ((stringp (nth 1 x)) x)
  2348. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2349. (t (cons (car x) (cons "" (cdr x))))))
  2350. org-agenda-custom-commands)))
  2351. (org-agenda-custom-commands
  2352. (org-contextualize-keys
  2353. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2354. (buf (current-buffer))
  2355. (bfn (buffer-file-name (buffer-base-buffer)))
  2356. entry key type org-match lprops ans)
  2357. ;; Turn off restriction unless there is an overriding one,
  2358. (unless org-agenda-overriding-restriction
  2359. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2360. ;; There is a request to keep the file list in place
  2361. (put 'org-agenda-files 'org-restrict nil))
  2362. (setq org-agenda-restrict nil)
  2363. (move-marker org-agenda-restrict-begin nil)
  2364. (move-marker org-agenda-restrict-end nil))
  2365. ;; Delete old local properties
  2366. (put 'org-agenda-redo-command 'org-lprops nil)
  2367. ;; Delete previously set last-arguments
  2368. (put 'org-agenda-redo-command 'last-args nil)
  2369. ;; Remember where this call originated
  2370. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2371. (unless org-keys
  2372. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2373. org-keys (car ans)
  2374. restriction (cdr ans)))
  2375. ;; If we have sticky agenda buffers, set a name for the buffer,
  2376. ;; depending on the invoking keys. The user may still set this
  2377. ;; as a command option, which will overwrite what we do here.
  2378. (if org-agenda-sticky
  2379. (setq org-agenda-buffer-name
  2380. (format "*Org Agenda(%s)*" org-keys)))
  2381. ;; Establish the restriction, if any
  2382. (when (and (not org-agenda-overriding-restriction) restriction)
  2383. (put 'org-agenda-files 'org-restrict (list bfn))
  2384. (cond
  2385. ((eq restriction 'region)
  2386. (setq org-agenda-restrict t)
  2387. (move-marker org-agenda-restrict-begin (region-beginning))
  2388. (move-marker org-agenda-restrict-end (region-end)))
  2389. ((eq restriction 'subtree)
  2390. (save-excursion
  2391. (setq org-agenda-restrict t)
  2392. (org-back-to-heading t)
  2393. (move-marker org-agenda-restrict-begin (point))
  2394. (move-marker org-agenda-restrict-end
  2395. (progn (org-end-of-subtree t)))))))
  2396. ;; For example the todo list should not need it (but does...)
  2397. (cond
  2398. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2399. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2400. (progn
  2401. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2402. lprops (nth 4 entry))
  2403. (if org-agenda-sticky
  2404. (setq org-agenda-buffer-name
  2405. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2406. (format "*Org Agenda(%s)*" org-keys))))
  2407. (put 'org-agenda-redo-command 'org-lprops lprops)
  2408. (cond
  2409. ((eq type 'agenda)
  2410. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2411. ((eq type 'alltodo)
  2412. (org-let lprops '(org-todo-list current-prefix-arg)))
  2413. ((eq type 'search)
  2414. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2415. ((eq type 'stuck)
  2416. (org-let lprops '(org-agenda-list-stuck-projects
  2417. current-prefix-arg)))
  2418. ((eq type 'tags)
  2419. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2420. ((eq type 'tags-todo)
  2421. (org-let lprops '(org-tags-view '(4) org-match)))
  2422. ((eq type 'todo)
  2423. (org-let lprops '(org-todo-list org-match)))
  2424. ((eq type 'tags-tree)
  2425. (org-check-for-org-mode)
  2426. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2427. ((eq type 'todo-tree)
  2428. (org-check-for-org-mode)
  2429. (org-let lprops
  2430. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2431. (regexp-quote org-match) "\\>"))))
  2432. ((eq type 'occur-tree)
  2433. (org-check-for-org-mode)
  2434. (org-let lprops '(org-occur org-match)))
  2435. ((functionp type)
  2436. (org-let lprops '(funcall type org-match)))
  2437. ((fboundp type)
  2438. (org-let lprops '(funcall type org-match)))
  2439. (t (error "Invalid custom agenda command type %s" type))))
  2440. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2441. ((equal org-keys "C")
  2442. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2443. (customize-variable 'org-agenda-custom-commands))
  2444. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2445. ((equal org-keys "s") (call-interactively 'org-search-view))
  2446. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2447. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2448. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2449. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2450. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2451. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2452. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2453. (org-add-hook
  2454. 'post-command-hook
  2455. (lambda ()
  2456. (unless (current-message)
  2457. (let* ((m (org-agenda-get-any-marker))
  2458. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2459. (when note
  2460. (message (concat
  2461. "FLAGGING-NOTE ([?] for more info): "
  2462. (org-add-props
  2463. (replace-regexp-in-string
  2464. "\\\\n" "//"
  2465. (copy-sequence note))
  2466. nil 'face 'org-warning)))))))
  2467. t t))
  2468. ((equal org-keys "L")
  2469. (unless (derived-mode-p 'org-mode)
  2470. (error "This is not an Org-mode file"))
  2471. (unless restriction
  2472. (put 'org-agenda-files 'org-restrict (list bfn))
  2473. (org-call-with-arg 'org-timeline arg)))
  2474. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2475. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2476. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2477. (t (error "Invalid agenda key"))))))
  2478. (defun org-agenda-append-agenda ()
  2479. "Append another agenda view to the current one.
  2480. This function allows interactive building of block agendas.
  2481. Agenda views are separated by `org-agenda-block-separator'."
  2482. (interactive)
  2483. (unless (derived-mode-p 'org-agenda-mode)
  2484. (error "Can only append from within agenda buffer"))
  2485. (let ((org-agenda-multi t))
  2486. (org-agenda)
  2487. (widen)
  2488. (org-agenda-finalize)
  2489. (org-agenda-fit-window-to-buffer)))
  2490. (defun org-agenda-normalize-custom-commands (cmds)
  2491. "Normalize custom commands CMDS."
  2492. (delq nil
  2493. (mapcar
  2494. (lambda (x)
  2495. (cond ((stringp (cdr x)) nil)
  2496. ((stringp (nth 1 x)) x)
  2497. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2498. (t (cons (car x) (cons "" (cdr x))))))
  2499. cmds)))
  2500. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2501. "The user interface for selecting an agenda command."
  2502. (catch 'exit
  2503. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2504. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2505. (region-p (org-region-active-p))
  2506. (custom org-agenda-custom-commands)
  2507. (selstring "")
  2508. restriction second-time
  2509. c entry key type match prefixes rmheader header-end custom1 desc
  2510. line lines left right n n1)
  2511. (save-window-excursion
  2512. (delete-other-windows)
  2513. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2514. (erase-buffer)
  2515. (insert (eval-when-compile
  2516. (let ((header
  2517. "Press key for an agenda command: < Buffer, subtree/region restriction
  2518. -------------------------------- > Remove restriction
  2519. a Agenda for current week or day e Export agenda views
  2520. t List of all TODO entries T Entries with special TODO kwd
  2521. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2522. s Search for keywords S Like s, but only TODO entries
  2523. L Timeline for current buffer # List stuck projects (!=configure)
  2524. / Multi-occur C Configure custom agenda commands
  2525. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2526. ")
  2527. (start 0))
  2528. (while (string-match
  2529. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2530. header start)
  2531. (setq start (match-end 0))
  2532. (add-text-properties (match-beginning 2) (match-end 2)
  2533. '(face bold) header))
  2534. header)))
  2535. (setq header-end (point-marker))
  2536. (while t
  2537. (setq custom1 custom)
  2538. (when (eq rmheader t)
  2539. (org-goto-line 1)
  2540. (re-search-forward ":" nil t)
  2541. (delete-region (match-end 0) (point-at-eol))
  2542. (forward-char 1)
  2543. (looking-at "-+")
  2544. (delete-region (match-end 0) (point-at-eol))
  2545. (move-marker header-end (match-end 0)))
  2546. (goto-char header-end)
  2547. (delete-region (point) (point-max))
  2548. ;; Produce all the lines that describe custom commands and prefixes
  2549. (setq lines nil)
  2550. (while (setq entry (pop custom1))
  2551. (setq key (car entry) desc (nth 1 entry)
  2552. type (nth 2 entry)
  2553. match (nth 3 entry))
  2554. (if (> (length key) 1)
  2555. (add-to-list 'prefixes (string-to-char key))
  2556. (setq line
  2557. (format
  2558. "%-4s%-14s"
  2559. (org-add-props (copy-sequence key)
  2560. '(face bold))
  2561. (cond
  2562. ((string-match "\\S-" desc) desc)
  2563. ((eq type 'agenda) "Agenda for current week or day")
  2564. ((eq type 'alltodo) "List of all TODO entries")
  2565. ((eq type 'search) "Word search")
  2566. ((eq type 'stuck) "List of stuck projects")
  2567. ((eq type 'todo) "TODO keyword")
  2568. ((eq type 'tags) "Tags query")
  2569. ((eq type 'tags-todo) "Tags (TODO)")
  2570. ((eq type 'tags-tree) "Tags tree")
  2571. ((eq type 'todo-tree) "TODO kwd tree")
  2572. ((eq type 'occur-tree) "Occur tree")
  2573. ((functionp type) (if (symbolp type)
  2574. (symbol-name type)
  2575. "Lambda expression"))
  2576. (t "???"))))
  2577. (if org-agenda-menu-show-matcher
  2578. (setq line
  2579. (concat line ": "
  2580. (cond
  2581. ((stringp match)
  2582. (setq match (copy-sequence match))
  2583. (org-add-props match nil 'face 'org-warning))
  2584. ((listp type)
  2585. (format "set of %d commands" (length type))))))
  2586. (if (org-string-nw-p match)
  2587. (add-text-properties
  2588. 0 (length line) (list 'help-echo
  2589. (concat "Matcher: " match)) line)))
  2590. (push line lines)))
  2591. (setq lines (nreverse lines))
  2592. (when prefixes
  2593. (mapc (lambda (x)
  2594. (push
  2595. (format "%s %s"
  2596. (org-add-props (char-to-string x)
  2597. nil 'face 'bold)
  2598. (or (cdr (assoc (concat selstring
  2599. (char-to-string x))
  2600. prefix-descriptions))
  2601. "Prefix key"))
  2602. lines))
  2603. prefixes))
  2604. ;; Check if we should display in two columns
  2605. (if org-agenda-menu-two-columns
  2606. (progn
  2607. (setq n (length lines)
  2608. n1 (+ (/ n 2) (mod n 2))
  2609. right (nthcdr n1 lines)
  2610. left (copy-sequence lines))
  2611. (setcdr (nthcdr (1- n1) left) nil))
  2612. (setq left lines right nil))
  2613. (while left
  2614. (insert "\n" (pop left))
  2615. (when right
  2616. (if (< (current-column) 40)
  2617. (move-to-column 40 t)
  2618. (insert " "))
  2619. (insert (pop right))))
  2620. ;; Make the window the right size
  2621. (goto-char (point-min))
  2622. (if second-time
  2623. (if (not (pos-visible-in-window-p (point-max)))
  2624. (org-fit-window-to-buffer))
  2625. (setq second-time t)
  2626. (org-fit-window-to-buffer))
  2627. ;; Ask for selection
  2628. (message "Press key for agenda command%s:"
  2629. (if (or restrict-ok org-agenda-overriding-restriction)
  2630. (if org-agenda-overriding-restriction
  2631. " (restriction lock active)"
  2632. (if restriction
  2633. (format " (restricted to %s)" restriction)
  2634. " (unrestricted)"))
  2635. ""))
  2636. (setq c (read-char-exclusive))
  2637. (message "")
  2638. (cond
  2639. ((assoc (char-to-string c) custom)
  2640. (setq selstring (concat selstring (char-to-string c)))
  2641. (throw 'exit (cons selstring restriction)))
  2642. ((memq c prefixes)
  2643. (setq selstring (concat selstring (char-to-string c))
  2644. prefixes nil
  2645. rmheader (or rmheader t)
  2646. custom (delq nil (mapcar
  2647. (lambda (x)
  2648. (if (or (= (length (car x)) 1)
  2649. (/= (string-to-char (car x)) c))
  2650. nil
  2651. (cons (substring (car x) 1) (cdr x))))
  2652. custom))))
  2653. ((eq c ?*)
  2654. (call-interactively 'org-toggle-sticky-agenda)
  2655. (sit-for 2))
  2656. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2657. (message "Restriction is only possible in Org-mode buffers")
  2658. (ding) (sit-for 1))
  2659. ((eq c ?1)
  2660. (org-agenda-remove-restriction-lock 'noupdate)
  2661. (setq restriction 'buffer))
  2662. ((eq c ?0)
  2663. (org-agenda-remove-restriction-lock 'noupdate)
  2664. (setq restriction (if region-p 'region 'subtree)))
  2665. ((eq c ?<)
  2666. (org-agenda-remove-restriction-lock 'noupdate)
  2667. (setq restriction
  2668. (cond
  2669. ((eq restriction 'buffer)
  2670. (if region-p 'region 'subtree))
  2671. ((memq restriction '(subtree region))
  2672. nil)
  2673. (t 'buffer))))
  2674. ((eq c ?>)
  2675. (org-agenda-remove-restriction-lock 'noupdate)
  2676. (setq restriction nil))
  2677. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2678. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2679. ((and (> (length selstring) 0) (eq c ?\d))
  2680. (delete-window)
  2681. (org-agenda-get-restriction-and-command prefix-descriptions))
  2682. ((equal c ?q) (error "Abort"))
  2683. (t (error "Invalid key %c" c))))))))
  2684. (defun org-agenda-fit-window-to-buffer ()
  2685. "Fit the window to the buffer size."
  2686. (and (memq org-agenda-window-setup '(reorganize-frame))
  2687. (fboundp 'fit-window-to-buffer)
  2688. (org-fit-window-to-buffer
  2689. nil
  2690. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2691. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2692. (defvar org-cmd nil)
  2693. (defvar org-agenda-overriding-cmd nil)
  2694. (defvar org-agenda-overriding-arguments nil)
  2695. (defvar org-agenda-overriding-cmd-arguments nil)
  2696. (defun org-agenda-run-series (name series)
  2697. "Run agenda NAME as a SERIES of agenda commands."
  2698. (org-let (nth 1 series) '(org-agenda-prepare name))
  2699. ;; We need to reset agenda markers here, because when constructing a
  2700. ;; block agenda, the individual blocks do not do that.
  2701. (org-agenda-reset-markers)
  2702. (let* ((org-agenda-multi t)
  2703. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2704. (cmds (car series))
  2705. (gprops (nth 1 series))
  2706. match ;; The byte compiler incorrectly complains about this. Keep it!
  2707. org-cmd type lprops)
  2708. (while (setq org-cmd (pop cmds))
  2709. (setq type (car org-cmd)
  2710. match (eval (nth 1 org-cmd))
  2711. lprops (nth 2 org-cmd))
  2712. (let ((org-agenda-overriding-arguments
  2713. (if (eq org-agenda-overriding-cmd org-cmd)
  2714. (or org-agenda-overriding-arguments
  2715. org-agenda-overriding-cmd-arguments))))
  2716. (cond
  2717. ((eq type 'agenda)
  2718. (org-let2 gprops lprops
  2719. '(call-interactively 'org-agenda-list)))
  2720. ((eq type 'alltodo)
  2721. (org-let2 gprops lprops
  2722. '(call-interactively 'org-todo-list)))
  2723. ((eq type 'search)
  2724. (org-let2 gprops lprops
  2725. '(org-search-view current-prefix-arg match nil)))
  2726. ((eq type 'stuck)
  2727. (org-let2 gprops lprops
  2728. '(call-interactively 'org-agenda-list-stuck-projects)))
  2729. ((eq type 'tags)
  2730. (org-let2 gprops lprops
  2731. '(org-tags-view current-prefix-arg match)))
  2732. ((eq type 'tags-todo)
  2733. (org-let2 gprops lprops
  2734. '(org-tags-view '(4) match)))
  2735. ((eq type 'todo)
  2736. (org-let2 gprops lprops
  2737. '(org-todo-list match)))
  2738. ((fboundp type)
  2739. (org-let2 gprops lprops
  2740. '(funcall type match)))
  2741. (t (error "Invalid type in command series")))))
  2742. (widen)
  2743. (let ((inhibit-read-only t))
  2744. (add-text-properties (point-min) (point-max)
  2745. `(org-series t org-series-redo-cmd ,redo)))
  2746. (setq org-agenda-redo-command redo)
  2747. (goto-char (point-min)))
  2748. (org-agenda-fit-window-to-buffer)
  2749. (org-let (nth 1 series) '(org-agenda-finalize)))
  2750. ;;;###autoload
  2751. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2752. "Run an agenda command in batch mode and send the result to STDOUT.
  2753. If CMD-KEY is a string of length 1, it is used as a key in
  2754. `org-agenda-custom-commands' and triggers this command. If it is a
  2755. longer string it is used as a tags/todo match string.
  2756. Parameters are alternating variable names and values that will be bound
  2757. before running the agenda command."
  2758. (org-eval-in-environment (org-make-parameter-alist parameters)
  2759. (if (> (length cmd-key) 2)
  2760. (org-tags-view nil cmd-key)
  2761. (org-agenda nil cmd-key)))
  2762. (set-buffer org-agenda-buffer-name)
  2763. (princ (buffer-string)))
  2764. (defvar org-agenda-info nil)
  2765. ;;;###autoload
  2766. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2767. "Run an agenda command in batch mode and send the result to STDOUT.
  2768. If CMD-KEY is a string of length 1, it is used as a key in
  2769. `org-agenda-custom-commands' and triggers this command. If it is a
  2770. longer string it is used as a tags/todo match string.
  2771. Parameters are alternating variable names and values that will be bound
  2772. before running the agenda command.
  2773. The output gives a line for each selected agenda item. Each
  2774. item is a list of comma-separated values, like this:
  2775. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2776. category The category of the item
  2777. head The headline, without TODO kwd, TAGS and PRIORITY
  2778. type The type of the agenda entry, can be
  2779. todo selected in TODO match
  2780. tagsmatch selected in tags match
  2781. diary imported from diary
  2782. deadline a deadline on given date
  2783. scheduled scheduled on given date
  2784. timestamp entry has timestamp on given date
  2785. closed entry was closed on given date
  2786. upcoming-deadline warning about deadline
  2787. past-scheduled forwarded scheduled item
  2788. block entry has date block including g. date
  2789. todo The todo keyword, if any
  2790. tags All tags including inherited ones, separated by colons
  2791. date The relevant date, like 2007-2-14
  2792. time The time, like 15:00-16:50
  2793. extra Sting with extra planning info
  2794. priority-l The priority letter if any was given
  2795. priority-n The computed numerical priority
  2796. agenda-day The day in the agenda where this is listed"
  2797. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2798. (org-make-parameter-alist parameters))
  2799. (if (> (length cmd-key) 2)
  2800. (org-tags-view nil cmd-key)
  2801. (org-agenda nil cmd-key)))
  2802. (set-buffer org-agenda-buffer-name)
  2803. (let* ((lines (org-split-string (buffer-string) "\n"))
  2804. line)
  2805. (while (setq line (pop lines))
  2806. (catch 'next
  2807. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2808. (setq org-agenda-info
  2809. (org-fix-agenda-info (text-properties-at 0 line)))
  2810. (princ
  2811. (mapconcat 'org-agenda-export-csv-mapper
  2812. '(org-category txt type todo tags date time extra
  2813. priority-letter priority agenda-day)
  2814. ","))
  2815. (princ "\n")))))
  2816. (defun org-fix-agenda-info (props)
  2817. "Make sure all properties on an agenda item have a canonical form.
  2818. This ensures the export commands can easily use it."
  2819. (let (tmp re)
  2820. (when (setq tmp (plist-get props 'tags))
  2821. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2822. (when (setq tmp (plist-get props 'date))
  2823. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2824. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2825. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2826. (setq tmp (calendar-date-string tmp)))
  2827. (setq props (plist-put props 'date tmp)))
  2828. (when (setq tmp (plist-get props 'day))
  2829. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2830. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2831. (setq tmp (calendar-date-string tmp)))
  2832. (setq props (plist-put props 'day tmp))
  2833. (setq props (plist-put props 'agenda-day tmp)))
  2834. (when (setq tmp (plist-get props 'txt))
  2835. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2836. (plist-put props 'priority-letter (match-string 1 tmp))
  2837. (setq tmp (replace-match "" t t tmp)))
  2838. (when (and (setq re (plist-get props 'org-todo-regexp))
  2839. (setq re (concat "\\`\\.*" re " ?"))
  2840. (string-match re tmp))
  2841. (plist-put props 'todo (match-string 1 tmp))
  2842. (setq tmp (replace-match "" t t tmp)))
  2843. (plist-put props 'txt tmp)))
  2844. props)
  2845. (defun org-agenda-export-csv-mapper (prop)
  2846. (let ((res (plist-get org-agenda-info prop)))
  2847. (setq res
  2848. (cond
  2849. ((not res) "")
  2850. ((stringp res) res)
  2851. (t (prin1-to-string res))))
  2852. (while (string-match "," res)
  2853. (setq res (replace-match ";" t t res)))
  2854. (org-trim res)))
  2855. ;;;###autoload
  2856. (defun org-store-agenda-views (&rest parameters)
  2857. "Store agenda views."
  2858. (interactive)
  2859. (eval (list 'org-batch-store-agenda-views)))
  2860. ;;;###autoload
  2861. (defmacro org-batch-store-agenda-views (&rest parameters)
  2862. "Run all custom agenda commands that have a file argument."
  2863. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2864. (pop-up-frames nil)
  2865. (dir default-directory)
  2866. (pars (org-make-parameter-alist parameters))
  2867. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2868. (save-window-excursion
  2869. (while cmds
  2870. (setq cmd (pop cmds)
  2871. thiscmdkey (car cmd)
  2872. thiscmdcmd (cdr cmd)
  2873. match (nth 2 thiscmdcmd)
  2874. bufname (if org-agenda-sticky
  2875. (or (and (stringp match)
  2876. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2877. (format "*Org Agenda(%s)*" thiscmdkey))
  2878. org-agenda-buffer-name)
  2879. cmd-or-set (nth 2 cmd)
  2880. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2881. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2882. (if (stringp files) (setq files (list files)))
  2883. (when files
  2884. (org-eval-in-environment (append org-agenda-exporter-settings
  2885. opts pars)
  2886. (org-agenda nil thiscmdkey))
  2887. (set-buffer bufname)
  2888. (while files
  2889. (org-eval-in-environment (append org-agenda-exporter-settings
  2890. opts pars)
  2891. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2892. (and (get-buffer bufname)
  2893. (kill-buffer bufname)))))))
  2894. (defvar org-agenda-current-span nil
  2895. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2896. (defun org-agenda-mark-header-line (pos)
  2897. "Mark the line at POS as an agenda structure header."
  2898. (save-excursion
  2899. (goto-char pos)
  2900. (put-text-property (point-at-bol) (point-at-eol)
  2901. 'org-agenda-structural-header t)
  2902. (when org-agenda-title-append
  2903. (put-text-property (point-at-bol) (point-at-eol)
  2904. 'org-agenda-title-append org-agenda-title-append))))
  2905. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2906. (defvar org-agenda-write-buffer-name "Agenda View")
  2907. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2908. "Write the current buffer (an agenda view) as a file.
  2909. Depending on the extension of the file name, plain text (.txt),
  2910. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2911. If the extension is .ics, run icalendar export over all files used
  2912. to construct the agenda and limit the export to entries listed in the
  2913. agenda now.
  2914. If the extension is .org, collect all subtrees corresponding to the
  2915. agenda entries and add them in an .org file.
  2916. With prefix argument OPEN, open the new file immediately.
  2917. If NOSETTINGS is given, do not scope the settings of
  2918. `org-agenda-exporter-settings' into the export commands. This is used when
  2919. the settings have already been scoped and we do not wish to overrule other,
  2920. higher priority settings.
  2921. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2922. (interactive "FWrite agenda to file: \nP")
  2923. (if (or (not (file-writable-p file))
  2924. (and (file-exists-p file)
  2925. (if (called-interactively-p 'any)
  2926. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  2927. (error "Cannot write agenda to file %s" file))
  2928. (org-let (if nosettings nil org-agenda-exporter-settings)
  2929. '(save-excursion
  2930. (save-window-excursion
  2931. (org-agenda-mark-filtered-text)
  2932. (let ((bs (copy-sequence (buffer-string))) beg content)
  2933. (org-agenda-unmark-filtered-text)
  2934. (with-temp-buffer
  2935. (rename-buffer org-agenda-write-buffer-name t)
  2936. (set-buffer-modified-p nil)
  2937. (insert bs)
  2938. (org-agenda-remove-marked-text 'org-filtered)
  2939. (while (setq beg (text-property-any (point-min) (point-max)
  2940. 'org-filtered t))
  2941. (delete-region
  2942. beg (or (next-single-property-change beg 'org-filtered)
  2943. (point-max))))
  2944. (run-hooks 'org-agenda-before-write-hook)
  2945. (cond
  2946. ((org-bound-and-true-p org-mobile-creating-agendas)
  2947. (org-mobile-write-agenda-for-mobile file))
  2948. ((string-match "\\.org\\'" file)
  2949. (let (content p m message-log-max)
  2950. (goto-char (point-min))
  2951. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  2952. (goto-char p)
  2953. (setq m (get-text-property (point) 'org-hd-marker))
  2954. (when m
  2955. (push (save-excursion
  2956. (set-buffer (marker-buffer m))
  2957. (goto-char m)
  2958. (org-copy-subtree 1 nil t t)
  2959. org-subtree-clip)
  2960. content)))
  2961. (find-file file)
  2962. (erase-buffer)
  2963. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  2964. (write-file file)
  2965. (kill-buffer (current-buffer))
  2966. (message "Org file written to %s" file)))
  2967. ((string-match "\\.html?\\'" file)
  2968. (require 'htmlize)
  2969. (set-buffer (htmlize-buffer (current-buffer)))
  2970. (when org-agenda-export-html-style
  2971. ;; replace <style> section with org-agenda-export-html-style
  2972. (goto-char (point-min))
  2973. (kill-region (- (search-forward "<style") 6)
  2974. (search-forward "</style>"))
  2975. (insert org-agenda-export-html-style))
  2976. (write-file file)
  2977. (kill-buffer (current-buffer))
  2978. (message "HTML written to %s" file))
  2979. ((string-match "\\.ps\\'" file)
  2980. (require 'ps-print)
  2981. (ps-print-buffer-with-faces file)
  2982. (message "Postscript written to %s" file))
  2983. ((string-match "\\.pdf\\'" file)
  2984. (require 'ps-print)
  2985. (ps-print-buffer-with-faces
  2986. (concat (file-name-sans-extension file) ".ps"))
  2987. (call-process "ps2pdf" nil nil nil
  2988. (expand-file-name
  2989. (concat (file-name-sans-extension file) ".ps"))
  2990. (expand-file-name file))
  2991. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2992. (message "PDF written to %s" file))
  2993. ((string-match "\\.ics\\'" file)
  2994. (require 'ox-icalendar)
  2995. (org-icalendar-export-current-agenda (expand-file-name file)))
  2996. (t
  2997. (let ((bs (buffer-string)))
  2998. (find-file file)
  2999. (erase-buffer)
  3000. (insert bs)
  3001. (save-buffer 0)
  3002. (kill-buffer (current-buffer))
  3003. (message "Plain text written to %s" file))))))))
  3004. (set-buffer (or agenda-bufname
  3005. (and (org-called-interactively-p 'any) (buffer-name))
  3006. org-agenda-buffer-name)))
  3007. (when open (org-open-file file)))
  3008. (defvar org-agenda-tag-filter-overlays nil)
  3009. (defvar org-agenda-cat-filter-overlays nil)
  3010. (defun org-agenda-mark-filtered-text ()
  3011. "Mark all text hidden by filtering with a text property."
  3012. (let ((inhibit-read-only t))
  3013. (mapc
  3014. (lambda (o)
  3015. (when (equal (overlay-buffer o) (current-buffer))
  3016. (put-text-property
  3017. (overlay-start o) (overlay-end o)
  3018. 'org-filtered t)))
  3019. (append org-agenda-tag-filter-overlays
  3020. org-agenda-cat-filter-overlays))))
  3021. (defun org-agenda-unmark-filtered-text ()
  3022. "Remove the filtering text property."
  3023. (let ((inhibit-read-only t))
  3024. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3025. (defun org-agenda-remove-marked-text (property &optional value)
  3026. "Delete all text marked with VALUE of PROPERTY.
  3027. VALUE defaults to t."
  3028. (let (beg)
  3029. (setq value (or value t))
  3030. (while (setq beg (text-property-any (point-min) (point-max)
  3031. property value))
  3032. (delete-region
  3033. beg (or (next-single-property-change beg 'org-filtered)
  3034. (point-max))))))
  3035. (defun org-agenda-add-entry-text ()
  3036. "Add entry text to agenda lines.
  3037. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3038. entry text following headings shown in the agenda.
  3039. Drawers will be excluded, also the line with scheduling/deadline info."
  3040. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3041. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3042. (let (m txt)
  3043. (goto-char (point-min))
  3044. (while (not (eobp))
  3045. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3046. (beginning-of-line 2)
  3047. (setq txt (org-agenda-get-some-entry-text
  3048. m org-agenda-add-entry-text-maxlines " > "))
  3049. (end-of-line 1)
  3050. (if (string-match "\\S-" txt)
  3051. (insert "\n" txt)
  3052. (or (eobp) (forward-char 1))))))))
  3053. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3054. &rest keep)
  3055. "Extract entry text from MARKER, at most N-LINES lines.
  3056. This will ignore drawers etc, just get the text.
  3057. If INDENT is given, prefix every line with this string. If KEEP is
  3058. given, it is a list of symbols, defining stuff that should not be
  3059. removed from the entry content. Currently only `planning' is allowed here."
  3060. (let (txt drawer-re kwd-time-re ind)
  3061. (save-excursion
  3062. (with-current-buffer (marker-buffer marker)
  3063. (if (not (derived-mode-p 'org-mode))
  3064. (setq txt "")
  3065. (save-excursion
  3066. (save-restriction
  3067. (widen)
  3068. (goto-char marker)
  3069. (end-of-line 1)
  3070. (setq txt (buffer-substring
  3071. (min (1+ (point)) (point-max))
  3072. (progn (outline-next-heading) (point)))
  3073. drawer-re org-drawer-regexp
  3074. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3075. ".*\n?"))
  3076. (with-temp-buffer
  3077. (insert txt)
  3078. (when org-agenda-add-entry-text-descriptive-links
  3079. (goto-char (point-min))
  3080. (while (org-activate-bracket-links (point-max))
  3081. (add-text-properties (match-beginning 0) (match-end 0)
  3082. '(face org-link))))
  3083. (goto-char (point-min))
  3084. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3085. (set-text-properties (match-beginning 0) (match-end 0)
  3086. nil))
  3087. (goto-char (point-min))
  3088. (while (re-search-forward drawer-re nil t)
  3089. (delete-region
  3090. (match-beginning 0)
  3091. (progn (re-search-forward
  3092. "^[ \t]*:END:.*\n?" nil 'move)
  3093. (point))))
  3094. (unless (member 'planning keep)
  3095. (goto-char (point-min))
  3096. (while (re-search-forward kwd-time-re nil t)
  3097. (replace-match "")))
  3098. (goto-char (point-min))
  3099. (when org-agenda-entry-text-exclude-regexps
  3100. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3101. (while (setq re (pop re-list))
  3102. (goto-char (point-min))
  3103. (while (re-search-forward re nil t)
  3104. (replace-match "")))))
  3105. (goto-char (point-max))
  3106. (skip-chars-backward " \t\n")
  3107. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3108. ;; find and remove min common indentation
  3109. (goto-char (point-min))
  3110. (untabify (point-min) (point-max))
  3111. (setq ind (org-get-indentation))
  3112. (while (not (eobp))
  3113. (unless (looking-at "[ \t]*$")
  3114. (setq ind (min ind (org-get-indentation))))
  3115. (beginning-of-line 2))
  3116. (goto-char (point-min))
  3117. (while (not (eobp))
  3118. (unless (looking-at "[ \t]*$")
  3119. (move-to-column ind)
  3120. (delete-region (point-at-bol) (point)))
  3121. (beginning-of-line 2))
  3122. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3123. (goto-char (point-min))
  3124. (when indent
  3125. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3126. (replace-match indent t t)))
  3127. (goto-char (point-min))
  3128. (while (looking-at "[ \t]*\n") (replace-match ""))
  3129. (goto-char (point-max))
  3130. (when (> (org-current-line)
  3131. n-lines)
  3132. (org-goto-line (1+ n-lines))
  3133. (backward-char 1))
  3134. (setq txt (buffer-substring (point-min) (point)))))))))
  3135. txt))
  3136. (defun org-check-for-org-mode ()
  3137. "Make sure current buffer is in org-mode. Error if not."
  3138. (or (derived-mode-p 'org-mode)
  3139. (error "Cannot execute org-mode agenda command on buffer in %s"
  3140. major-mode)))
  3141. ;;; Agenda prepare and finalize
  3142. (defvar org-agenda-multi nil) ; dynamically scoped
  3143. (defvar org-agenda-pre-window-conf nil)
  3144. (defvar org-agenda-columns-active nil)
  3145. (defvar org-agenda-name nil)
  3146. (defvar org-agenda-tag-filter nil)
  3147. (defvar org-agenda-category-filter nil)
  3148. (defvar org-agenda-top-category-filter nil)
  3149. (defvar org-agenda-tag-filter-while-redo nil)
  3150. (defvar org-agenda-tag-filter-preset nil
  3151. "A preset of the tags filter used for secondary agenda filtering.
  3152. This must be a list of strings, each string must be a single tag preceded
  3153. by \"+\" or \"-\".
  3154. This variable should not be set directly, but agenda custom commands can
  3155. bind it in the options section. The preset filter is a global property of
  3156. the entire agenda view. In a block agenda, it will not work reliably to
  3157. define a filter for one of the individual blocks. You need to set it in
  3158. the global options and expect it to be applied to the entire view.")
  3159. (defvar org-agenda-category-filter-preset nil
  3160. "A preset of the category filter used for secondary agenda filtering.
  3161. This must be a list of strings, each string must be a single category
  3162. preceded by \"+\" or \"-\".
  3163. This variable should not be set directly, but agenda custom commands can
  3164. bind it in the options section. The preset filter is a global property of
  3165. the entire agenda view. In a block agenda, it will not work reliably to
  3166. define a filter for one of the individual blocks. You need to set it in
  3167. the global options and expect it to be applied to the entire view.")
  3168. (defun org-agenda-use-sticky-p ()
  3169. "Return non-nil if an agenda buffer named
  3170. `org-agenda-buffer-name' exists and should be shown instead of
  3171. generating a new one."
  3172. (and
  3173. ;; turned off by user
  3174. org-agenda-sticky
  3175. ;; For multi-agenda buffer already exists
  3176. (not org-agenda-multi)
  3177. ;; buffer found
  3178. (get-buffer org-agenda-buffer-name)
  3179. ;; C-u parameter is same as last call
  3180. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3181. (and
  3182. (equal current-prefix-arg
  3183. org-agenda-last-prefix-arg)
  3184. ;; In case user turned stickiness on, while having existing
  3185. ;; Agenda buffer active, don't reuse that buffer, because it
  3186. ;; does not have org variables local
  3187. org-agenda-this-buffer-is-sticky))))
  3188. (defun org-agenda-prepare-window (abuf)
  3189. "Setup agenda buffer in the window."
  3190. (let* ((awin (get-buffer-window abuf))
  3191. wconf)
  3192. (cond
  3193. ((equal (current-buffer) abuf) nil)
  3194. (awin (select-window awin))
  3195. ((not (setq wconf (current-window-configuration))))
  3196. ((equal org-agenda-window-setup 'current-window)
  3197. (org-pop-to-buffer-same-window abuf))
  3198. ((equal org-agenda-window-setup 'other-window)
  3199. (org-switch-to-buffer-other-window abuf))
  3200. ((equal org-agenda-window-setup 'other-frame)
  3201. (switch-to-buffer-other-frame abuf))
  3202. ((equal org-agenda-window-setup 'reorganize-frame)
  3203. (delete-other-windows)
  3204. (org-switch-to-buffer-other-window abuf)))
  3205. ;; additional test in case agenda is invoked from within agenda
  3206. ;; buffer via elisp link
  3207. (unless (equal (current-buffer) abuf)
  3208. (org-pop-to-buffer-same-window abuf))
  3209. (setq org-agenda-pre-window-conf
  3210. (or org-agenda-pre-window-conf wconf))))
  3211. (defun org-agenda-prepare (&optional name)
  3212. (if (org-agenda-use-sticky-p)
  3213. (progn
  3214. ;; Popup existing buffer
  3215. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3216. (message "Sticky Agenda buffer, use `r' to refresh")
  3217. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3218. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3219. (setq org-todo-keywords-for-agenda nil)
  3220. (setq org-drawers-for-agenda nil)
  3221. (unless org-agenda-persistent-filter
  3222. (setq org-agenda-tag-filter nil
  3223. org-agenda-category-filter nil))
  3224. (put 'org-agenda-tag-filter :preset-filter
  3225. org-agenda-tag-filter-preset)
  3226. (put 'org-agenda-category-filter :preset-filter
  3227. org-agenda-category-filter-preset)
  3228. (if org-agenda-multi
  3229. (progn
  3230. (setq buffer-read-only nil)
  3231. (goto-char (point-max))
  3232. (unless (or (bobp) org-agenda-compact-blocks
  3233. (not org-agenda-block-separator))
  3234. (insert "\n"
  3235. (if (stringp org-agenda-block-separator)
  3236. org-agenda-block-separator
  3237. (make-string (window-width) org-agenda-block-separator))
  3238. "\n"))
  3239. (narrow-to-region (point) (point-max)))
  3240. (setq org-done-keywords-for-agenda nil)
  3241. ;; Setting any org variables that are in org-agenda-local-vars
  3242. ;; list need to be done after the prepare call
  3243. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3244. (setq buffer-read-only nil)
  3245. (org-agenda-reset-markers)
  3246. (let ((inhibit-read-only t)) (erase-buffer))
  3247. (org-agenda-mode)
  3248. (setq org-agenda-buffer (current-buffer))
  3249. (setq org-agenda-contributing-files nil)
  3250. (setq org-agenda-columns-active nil)
  3251. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3252. (setq org-todo-keywords-for-agenda
  3253. (org-uniquify org-todo-keywords-for-agenda))
  3254. (setq org-done-keywords-for-agenda
  3255. (org-uniquify org-done-keywords-for-agenda))
  3256. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3257. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3258. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3259. (and name (not org-agenda-name)
  3260. (org-set-local 'org-agenda-name name)))
  3261. (setq buffer-read-only nil)))
  3262. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3263. (defun org-agenda-finalize ()
  3264. "Finishing touch for the agenda buffer, called just before displaying it."
  3265. (unless org-agenda-multi
  3266. (save-excursion
  3267. (let ((inhibit-read-only t))
  3268. (goto-char (point-min))
  3269. (save-excursion
  3270. (while (org-activate-bracket-links (point-max))
  3271. (add-text-properties (match-beginning 0) (match-end 0)
  3272. '(face org-link))))
  3273. (save-excursion
  3274. (while (org-activate-plain-links (point-max))
  3275. (add-text-properties (match-beginning 0) (match-end 0)
  3276. '(face org-link))))
  3277. (unless (eq org-agenda-remove-tags t)
  3278. (org-agenda-align-tags))
  3279. (unless org-agenda-with-colors
  3280. (remove-text-properties (point-min) (point-max) '(face nil)))
  3281. (if (and (boundp 'org-agenda-overriding-columns-format)
  3282. org-agenda-overriding-columns-format)
  3283. (org-set-local 'org-agenda-overriding-columns-format
  3284. org-agenda-overriding-columns-format))
  3285. (if (and (boundp 'org-agenda-view-columns-initially)
  3286. org-agenda-view-columns-initially)
  3287. (org-agenda-columns))
  3288. (when org-agenda-fontify-priorities
  3289. (org-agenda-fontify-priorities))
  3290. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3291. (org-agenda-dim-blocked-tasks))
  3292. ;; We need to widen when `org-agenda-finalize' is called from
  3293. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3294. (when org-clock-current-task
  3295. (save-restriction
  3296. (widen)
  3297. (org-agenda-mark-clocking-task)))
  3298. (when org-agenda-entry-text-mode
  3299. (org-agenda-entry-text-hide)
  3300. (org-agenda-entry-text-show))
  3301. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3302. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3303. (org-habit-insert-consistency-graphs))
  3304. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3305. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3306. (and (listp org-agenda-show-inherited-tags)
  3307. (memq org-agenda-type org-agenda-show-inherited-tags))
  3308. (and (eq org-agenda-show-inherited-tags t)
  3309. (or (eq org-agenda-use-tag-inheritance t)
  3310. (and (listp org-agenda-use-tag-inheritance)
  3311. (not (memq org-agenda-type
  3312. org-agenda-use-tag-inheritance))))))
  3313. (let (mrk)
  3314. (save-excursion
  3315. (goto-char (point-min))
  3316. (while (equal (forward-line) 0)
  3317. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3318. (get-text-property (point) 'org-hd-marker)))
  3319. (put-text-property (point-at-bol) (point-at-eol)
  3320. 'tags (org-with-point-at mrk
  3321. (delete-dups
  3322. (mapcar 'downcase (org-get-tags-at))))))))))
  3323. (run-hooks 'org-agenda-finalize-hook)
  3324. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3325. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3326. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3327. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3328. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3329. (defun org-agenda-mark-clocking-task ()
  3330. "Mark the current clock entry in the agenda if it is present."
  3331. (org-agenda-unmark-clocking-task)
  3332. (when (marker-buffer org-clock-hd-marker)
  3333. (save-excursion
  3334. (goto-char (point-min))
  3335. (let (s ov)
  3336. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3337. (goto-char s)
  3338. (when (equal (org-get-at-bol 'org-hd-marker)
  3339. org-clock-hd-marker)
  3340. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3341. (overlay-put ov 'type 'org-agenda-clocking)
  3342. (overlay-put ov 'face 'org-agenda-clocking)
  3343. (overlay-put ov 'help-echo
  3344. "The clock is running in this item")))))))
  3345. (defun org-agenda-unmark-clocking-task ()
  3346. "Unmark the current clocking task."
  3347. (mapc (lambda (o)
  3348. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3349. (delete-overlay o)))
  3350. (overlays-in (point-min) (point-max))))
  3351. (defun org-agenda-fontify-priorities ()
  3352. "Make highest priority lines bold, and lowest italic."
  3353. (interactive)
  3354. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3355. (delete-overlay o)))
  3356. (overlays-in (point-min) (point-max)))
  3357. (save-excursion
  3358. (let (b e p ov h l)
  3359. (goto-char (point-min))
  3360. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3361. (setq h (or (get-char-property (point) 'org-highest-priority)
  3362. org-highest-priority)
  3363. l (or (get-char-property (point) 'org-lowest-priority)
  3364. org-lowest-priority)
  3365. p (string-to-char (match-string 1))
  3366. b (match-beginning 0)
  3367. e (if (eq org-agenda-fontify-priorities 'cookies)
  3368. (match-end 0)
  3369. (point-at-eol))
  3370. ov (make-overlay b e))
  3371. (overlay-put
  3372. ov 'face
  3373. (cons (cond ((org-face-from-face-or-color
  3374. 'priority nil
  3375. (cdr (assoc p org-priority-faces))))
  3376. ((and (listp org-agenda-fontify-priorities)
  3377. (org-face-from-face-or-color
  3378. 'priority nil
  3379. (cdr (assoc p org-agenda-fontify-priorities)))))
  3380. ((equal p l) 'italic)
  3381. ((equal p h) 'bold))
  3382. 'org-priority))
  3383. (overlay-put ov 'org-type 'org-priority)))))
  3384. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3385. (interactive "P")
  3386. "Dim currently blocked TODO's in the agenda display."
  3387. (message "Dim or hide blocked tasks...")
  3388. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3389. (delete-overlay o)))
  3390. (overlays-in (point-min) (point-max)))
  3391. (save-excursion
  3392. (let ((inhibit-read-only t)
  3393. (org-depend-tag-blocked nil)
  3394. (invis (or (not (null invisible))
  3395. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3396. org-blocked-by-checkboxes
  3397. invis1 b e p ov h l)
  3398. (goto-char (point-min))
  3399. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3400. (and pos (goto-char (1+ pos))))
  3401. (setq org-blocked-by-checkboxes nil invis1 invis)
  3402. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3403. (when (and marker
  3404. (with-current-buffer (marker-buffer marker)
  3405. (save-excursion (goto-char marker)
  3406. (org-entry-blocked-p))))
  3407. (if org-blocked-by-checkboxes (setq invis1 nil))
  3408. (setq b (if invis1
  3409. (max (point-min) (1- (point-at-bol)))
  3410. (point-at-bol))
  3411. e (point-at-eol)
  3412. ov (make-overlay b e))
  3413. (if invis1
  3414. (overlay-put ov 'invisible t)
  3415. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3416. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3417. (message "Dim or hide blocked tasks...done"))
  3418. (defvar org-agenda-skip-function nil
  3419. "Function to be called at each match during agenda construction.
  3420. If this function returns nil, the current match should not be skipped.
  3421. Otherwise, the function must return a position from where the search
  3422. should be continued.
  3423. This may also be a Lisp form, it will be evaluated.
  3424. Never set this variable using `setq' or so, because then it will apply
  3425. to all future agenda commands. If you do want a global skipping condition,
  3426. use the option `org-agenda-skip-function-global' instead.
  3427. The correct usage for `org-agenda-skip-function' is to bind it with
  3428. `let' to scope it dynamically into the agenda-constructing command.
  3429. A good way to set it is through options in `org-agenda-custom-commands'.")
  3430. (defun org-agenda-skip ()
  3431. "Throw to `:skip' in places that should be skipped.
  3432. Also moves point to the end of the skipped region, so that search can
  3433. continue from there."
  3434. (let ((p (point-at-bol)) to)
  3435. (when (or
  3436. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3437. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3438. (get-text-property p :org-archived)
  3439. (org-end-of-subtree t))
  3440. (and org-agenda-skip-comment-trees
  3441. (get-text-property p :org-comment)
  3442. (org-end-of-subtree t))
  3443. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3444. (org-agenda-skip-eval org-agenda-skip-function)))
  3445. (goto-char to))
  3446. (org-in-src-block-p t))
  3447. (throw :skip t))))
  3448. (defun org-agenda-skip-eval (form)
  3449. "If FORM is a function or a list, call (or eval) is and return result.
  3450. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3451. and match data are returned to the previous state no matter what these
  3452. functions do."
  3453. (let (fp)
  3454. (and form
  3455. (or (setq fp (functionp form))
  3456. (consp form))
  3457. (save-excursion
  3458. (save-match-data
  3459. (if fp
  3460. (funcall form)
  3461. (eval form)))))))
  3462. (defvar org-agenda-markers nil
  3463. "List of all currently active markers created by `org-agenda'.")
  3464. (defvar org-agenda-last-marker-time (org-float-time)
  3465. "Creation time of the last agenda marker.")
  3466. (defun org-agenda-new-marker (&optional pos)
  3467. "Return a new agenda marker.
  3468. Org-mode keeps a list of these markers and resets them when they are
  3469. no longer in use."
  3470. (let ((m (copy-marker (or pos (point)))))
  3471. (setq org-agenda-last-marker-time (org-float-time))
  3472. (if org-agenda-buffer
  3473. (with-current-buffer org-agenda-buffer
  3474. (push m org-agenda-markers))
  3475. (push m org-agenda-markers))
  3476. m))
  3477. (defun org-agenda-reset-markers ()
  3478. "Reset markers created by `org-agenda'."
  3479. (while org-agenda-markers
  3480. (move-marker (pop org-agenda-markers) nil)))
  3481. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3482. "Save relative positions of markers in region.
  3483. This check for agenda markers in all agenda buffers currently active."
  3484. (dolist (buf (buffer-list))
  3485. (with-current-buffer buf
  3486. (when (eq major-mode 'org-agenda-mode)
  3487. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3488. org-agenda-markers)))))
  3489. ;;; Entry text mode
  3490. (defun org-agenda-entry-text-show-here ()
  3491. "Add some text from the entry as context to the current line."
  3492. (let (m txt o)
  3493. (setq m (org-get-at-bol 'org-hd-marker))
  3494. (unless (marker-buffer m)
  3495. (error "No marker points to an entry here"))
  3496. (setq txt (concat "\n" (org-no-properties
  3497. (org-agenda-get-some-entry-text
  3498. m org-agenda-entry-text-maxlines
  3499. org-agenda-entry-text-leaders))))
  3500. (when (string-match "\\S-" txt)
  3501. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3502. (overlay-put o 'evaporate t)
  3503. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3504. (overlay-put o 'after-string txt))))
  3505. (defun org-agenda-entry-text-show ()
  3506. "Add entry context for all agenda lines."
  3507. (interactive)
  3508. (save-excursion
  3509. (goto-char (point-max))
  3510. (beginning-of-line 1)
  3511. (while (not (bobp))
  3512. (when (org-get-at-bol 'org-hd-marker)
  3513. (org-agenda-entry-text-show-here))
  3514. (beginning-of-line 0))))
  3515. (defun org-agenda-entry-text-hide ()
  3516. "Remove any shown entry context."
  3517. (delq nil
  3518. (mapcar (lambda (o)
  3519. (if (eq (overlay-get o 'org-overlay-type)
  3520. 'agenda-entry-content)
  3521. (progn (delete-overlay o) t)))
  3522. (overlays-in (point-min) (point-max)))))
  3523. (defun org-agenda-get-day-face (date)
  3524. "Return the face DATE should be displayed with."
  3525. (or (and (functionp org-agenda-day-face-function)
  3526. (funcall org-agenda-day-face-function date))
  3527. (cond ((org-agenda-todayp date)
  3528. 'org-agenda-date-today)
  3529. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3530. 'org-agenda-date-weekend)
  3531. (t 'org-agenda-date))))
  3532. ;;; Agenda timeline
  3533. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3534. (defun org-timeline (&optional dotodo)
  3535. "Show a time-sorted view of the entries in the current org file.
  3536. Only entries with a time stamp of today or later will be listed. With
  3537. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3538. under the current date.
  3539. If the buffer contains an active region, only check the region for
  3540. dates."
  3541. (interactive "P")
  3542. (let* ((dopast t)
  3543. (org-agenda-show-log-scoped org-agenda-show-log)
  3544. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3545. (current-buffer))))
  3546. (date (calendar-current-date))
  3547. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3548. (end (if (org-region-active-p) (region-end) (point-max)))
  3549. (day-numbers (org-get-all-dates
  3550. beg end 'no-ranges
  3551. t org-agenda-show-log-scoped ; always include today
  3552. org-timeline-show-empty-dates))
  3553. (org-deadline-warning-days 0)
  3554. (org-agenda-only-exact-dates t)
  3555. (today (org-today))
  3556. (past t)
  3557. args
  3558. s e rtn d emptyp)
  3559. (setq org-agenda-redo-command
  3560. (list 'progn
  3561. (list 'org-switch-to-buffer-other-window (current-buffer))
  3562. (list 'org-timeline (list 'quote dotodo))))
  3563. (if (not dopast)
  3564. ;; Remove past dates from the list of dates.
  3565. (setq day-numbers (delq nil (mapcar (lambda(x)
  3566. (if (>= x today) x nil))
  3567. day-numbers))))
  3568. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3569. (org-compile-prefix-format 'timeline)
  3570. (org-set-sorting-strategy 'timeline)
  3571. (if org-agenda-show-log-scoped (push :closed args))
  3572. (push :timestamp args)
  3573. (push :deadline args)
  3574. (push :scheduled args)
  3575. (push :sexp args)
  3576. (if dotodo (push :todo args))
  3577. (insert "Timeline of file " entry "\n")
  3578. (add-text-properties (point-min) (point)
  3579. (list 'face 'org-agenda-structure))
  3580. (org-agenda-mark-header-line (point-min))
  3581. (while (setq d (pop day-numbers))
  3582. (if (and (listp d) (eq (car d) :omitted))
  3583. (progn
  3584. (setq s (point))
  3585. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3586. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3587. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3588. (if (and (>= d today)
  3589. dopast
  3590. past)
  3591. (progn
  3592. (setq past nil)
  3593. (insert (make-string 79 ?-) "\n")))
  3594. (setq date (calendar-gregorian-from-absolute d))
  3595. (setq s (point))
  3596. (setq rtn (and (not emptyp)
  3597. (apply 'org-agenda-get-day-entries entry
  3598. date args)))
  3599. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3600. (progn
  3601. (insert
  3602. (if (stringp org-agenda-format-date)
  3603. (format-time-string org-agenda-format-date
  3604. (org-time-from-absolute date))
  3605. (funcall org-agenda-format-date date))
  3606. "\n")
  3607. (put-text-property s (1- (point)) 'face
  3608. (org-agenda-get-day-face date))
  3609. (put-text-property s (1- (point)) 'org-date-line t)
  3610. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3611. (if (equal d today)
  3612. (put-text-property s (1- (point)) 'org-today t))
  3613. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3614. (put-text-property s (1- (point)) 'day d)))))
  3615. (goto-char (point-min))
  3616. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3617. (point-min)))
  3618. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3619. (org-agenda-finalize)
  3620. (setq buffer-read-only t)))
  3621. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3622. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3623. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3624. not every single day in the range. If FORCE-TODAY is non-nil, make
  3625. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3626. inactive time stamps (those in square brackets) are included.
  3627. When EMPTY is non-nil, also include days without any entries."
  3628. (let ((re (concat
  3629. (if pre-re pre-re "")
  3630. (if inactive org-ts-regexp-both org-ts-regexp)))
  3631. dates dates1 date day day1 day2 ts1 ts2 pos)
  3632. (if force-today
  3633. (setq dates (list (org-today))))
  3634. (save-excursion
  3635. (goto-char beg)
  3636. (while (re-search-forward re end t)
  3637. (setq day (time-to-days (org-time-string-to-time
  3638. (substring (match-string 1) 0 10)
  3639. (current-buffer) (match-beginning 0))))
  3640. (or (memq day dates) (push day dates)))
  3641. (unless no-ranges
  3642. (goto-char beg)
  3643. (while (re-search-forward org-tr-regexp end t)
  3644. (setq pos (match-beginning 0))
  3645. (setq ts1 (substring (match-string 1) 0 10)
  3646. ts2 (substring (match-string 2) 0 10)
  3647. day1 (time-to-days (org-time-string-to-time
  3648. ts1 (current-buffer) pos))
  3649. day2 (time-to-days (org-time-string-to-time
  3650. ts2 (current-buffer) pos)))
  3651. (while (< (setq day1 (1+ day1)) day2)
  3652. (or (memq day1 dates) (push day1 dates)))))
  3653. (setq dates (sort dates '<))
  3654. (when empty
  3655. (while (setq day (pop dates))
  3656. (setq day2 (car dates))
  3657. (push day dates1)
  3658. (when (and day2 empty)
  3659. (if (or (eq empty t)
  3660. (and (numberp empty) (<= (- day2 day) empty)))
  3661. (while (< (setq day (1+ day)) day2)
  3662. (push (list day) dates1))
  3663. (push (cons :omitted (- day2 day)) dates1))))
  3664. (setq dates (nreverse dates1)))
  3665. dates)))
  3666. ;;; Agenda Daily/Weekly
  3667. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3668. "Start day for the agenda view.
  3669. Custom commands can set this variable in the options section.
  3670. See the docstring of `org-read-date' on allowed values.")
  3671. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3672. (defvar org-arg-loc nil) ; local variable
  3673. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3674. "List of types searched for when creating the daily/weekly agenda.
  3675. This variable is a list of symbols that controls the types of
  3676. items that appear in the daily/weekly agenda. Allowed symbols in this
  3677. list are are
  3678. :timestamp List items containing a date stamp or date range matching
  3679. the selected date. This includes sexp entries in
  3680. angular brackets.
  3681. :sexp List entries resulting from plain diary-like sexps.
  3682. :deadline List deadline due on that date. When the date is today,
  3683. also list any deadlines past due, or due within
  3684. `org-deadline-warning-days'. `:deadline' must appear before
  3685. `:scheduled' if the setting of
  3686. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3687. any effect.
  3688. :scheduled List all items which are scheduled for the given date.
  3689. The diary for *today* also contains items which were
  3690. scheduled earlier and are not yet marked DONE.
  3691. By default, all four types are turned on.
  3692. Never set this variable globally using `setq', because then it
  3693. will apply to all future agenda commands. Instead, bind it with
  3694. `let' to scope it dynamically into the agenda-constructing
  3695. command. A good way to set it is through options in
  3696. `org-agenda-custom-commands'. For a more flexible (though
  3697. somewhat less efficient) way of determining what is included in
  3698. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3699. (defvar org-agenda-buffer-tmp-name nil)
  3700. ;;;###autoload
  3701. (defun org-agenda-list (&optional arg start-day span)
  3702. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3703. The view will be for the current day or week, but from the overview buffer
  3704. you will be able to go to other days/weeks.
  3705. With a numeric prefix argument in an interactive call, the agenda will
  3706. span ARG days. Lisp programs should instead specify SPAN to change
  3707. the number of days. SPAN defaults to `org-agenda-span'.
  3708. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3709. given in `org-agenda-start-on-weekday'."
  3710. (interactive "P")
  3711. (if org-agenda-overriding-arguments
  3712. (setq arg (car org-agenda-overriding-arguments)
  3713. start-day (nth 1 org-agenda-overriding-arguments)
  3714. span (nth 2 org-agenda-overriding-arguments)))
  3715. (if (and (integerp arg) (> arg 0))
  3716. (setq span arg arg nil))
  3717. (catch 'exit
  3718. (setq org-agenda-buffer-name
  3719. (or org-agenda-buffer-tmp-name
  3720. (if org-agenda-sticky
  3721. (cond ((and org-keys (stringp org-match))
  3722. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3723. (org-keys
  3724. (format "*Org Agenda(%s)*" org-keys))
  3725. (t "*Org Agenda(a)*")))
  3726. org-agenda-buffer-name))
  3727. (org-agenda-prepare "Day/Week")
  3728. (setq start-day (or start-day org-agenda-start-day))
  3729. (if (stringp start-day)
  3730. ;; Convert to an absolute day number
  3731. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3732. (org-compile-prefix-format 'agenda)
  3733. (org-set-sorting-strategy 'agenda)
  3734. (let* ((span (org-agenda-ndays-to-span
  3735. (or span org-agenda-ndays org-agenda-span)))
  3736. (today (org-today))
  3737. (sd (or start-day today))
  3738. (ndays (org-agenda-span-to-ndays span sd))
  3739. (org-agenda-start-on-weekday
  3740. (if (eq ndays 7)
  3741. org-agenda-start-on-weekday))
  3742. (thefiles (org-agenda-files nil 'ifmode))
  3743. (files thefiles)
  3744. (start (if (or (null org-agenda-start-on-weekday)
  3745. (< ndays 7))
  3746. sd
  3747. (let* ((nt (calendar-day-of-week
  3748. (calendar-gregorian-from-absolute sd)))
  3749. (n1 org-agenda-start-on-weekday)
  3750. (d (- nt n1)))
  3751. (- sd (+ (if (< d 0) 7 0) d)))))
  3752. (day-numbers (list start))
  3753. (day-cnt 0)
  3754. (inhibit-redisplay (not debug-on-error))
  3755. (org-agenda-show-log-scoped org-agenda-show-log)
  3756. s e rtn rtnall file date d start-pos end-pos todayp
  3757. clocktable-start clocktable-end filter)
  3758. (setq org-agenda-redo-command
  3759. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3760. (dotimes (n (1- ndays))
  3761. (push (1+ (car day-numbers)) day-numbers))
  3762. (setq day-numbers (nreverse day-numbers))
  3763. (setq clocktable-start (car day-numbers)
  3764. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3765. (org-set-local 'org-starting-day (car day-numbers))
  3766. (org-set-local 'org-arg-loc arg)
  3767. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3768. (unless org-agenda-compact-blocks
  3769. (let* ((d1 (car day-numbers))
  3770. (d2 (org-last day-numbers))
  3771. (w1 (org-days-to-iso-week d1))
  3772. (w2 (org-days-to-iso-week d2)))
  3773. (setq s (point))
  3774. (if org-agenda-overriding-header
  3775. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3776. nil 'face 'org-agenda-structure) "\n")
  3777. (insert (org-agenda-span-name span)
  3778. "-agenda"
  3779. (if (< (- d2 d1) 350)
  3780. (if (= w1 w2)
  3781. (format " (W%02d)" w1)
  3782. (format " (W%02d-W%02d)" w1 w2))
  3783. "")
  3784. ":\n")))
  3785. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3786. 'org-date-line t))
  3787. (org-agenda-mark-header-line s))
  3788. (while (setq d (pop day-numbers))
  3789. (setq date (calendar-gregorian-from-absolute d)
  3790. s (point))
  3791. (if (or (setq todayp (= d today))
  3792. (and (not start-pos) (= d sd)))
  3793. (setq start-pos (point))
  3794. (if (and start-pos (not end-pos))
  3795. (setq end-pos (point))))
  3796. (setq files thefiles
  3797. rtnall nil)
  3798. (while (setq file (pop files))
  3799. (catch 'nextfile
  3800. (org-check-agenda-file file)
  3801. (let ((org-agenda-entry-types org-agenda-entry-types))
  3802. (unless org-agenda-include-deadlines
  3803. (setq org-agenda-entry-types
  3804. (delq :deadline org-agenda-entry-types)))
  3805. (cond
  3806. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3807. (setq rtn (org-agenda-get-day-entries
  3808. file date :closed)))
  3809. (org-agenda-show-log-scoped
  3810. (setq rtn (apply 'org-agenda-get-day-entries
  3811. file date
  3812. (append '(:closed) org-agenda-entry-types))))
  3813. (t
  3814. (setq rtn (apply 'org-agenda-get-day-entries
  3815. file date
  3816. org-agenda-entry-types)))))
  3817. (setq rtnall (append rtnall rtn)))) ;; all entries
  3818. (if org-agenda-include-diary
  3819. (let ((org-agenda-search-headline-for-time t))
  3820. (require 'diary-lib)
  3821. (setq rtn (org-get-entries-from-diary date))
  3822. (setq rtnall (append rtnall rtn))))
  3823. (if (or rtnall org-agenda-show-all-dates)
  3824. (progn
  3825. (setq day-cnt (1+ day-cnt))
  3826. (insert
  3827. (if (stringp org-agenda-format-date)
  3828. (format-time-string org-agenda-format-date
  3829. (org-time-from-absolute date))
  3830. (funcall org-agenda-format-date date))
  3831. "\n")
  3832. (put-text-property s (1- (point)) 'face
  3833. (org-agenda-get-day-face date))
  3834. (put-text-property s (1- (point)) 'org-date-line t)
  3835. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3836. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3837. (when todayp
  3838. (put-text-property s (1- (point)) 'org-today t))
  3839. (setq rtnall
  3840. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3841. (if rtnall (insert ;; all entries
  3842. (org-agenda-finalize-entries rtnall 'agenda)
  3843. "\n"))
  3844. (put-text-property s (1- (point)) 'day d)
  3845. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3846. (when (and org-agenda-clockreport-mode clocktable-start)
  3847. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3848. ;; the above line is to ensure the restricted range!
  3849. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3850. tbl)
  3851. (setq p (org-plist-delete p :block))
  3852. (setq p (plist-put p :tstart clocktable-start))
  3853. (setq p (plist-put p :tend clocktable-end))
  3854. (setq p (plist-put p :scope 'agenda))
  3855. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3856. (setq filter (or org-agenda-tag-filter-while-redo
  3857. (get 'org-agenda-tag-filter :preset-filter))))
  3858. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3859. (if (string-match "[<>=]" x)
  3860. ""
  3861. x))
  3862. filter ""))))
  3863. (setq tbl (apply 'org-clock-get-clocktable p))
  3864. (insert tbl)))
  3865. (goto-char (point-min))
  3866. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3867. (unless (and (pos-visible-in-window-p (point-min))
  3868. (pos-visible-in-window-p (point-max)))
  3869. (goto-char (1- (point-max)))
  3870. (recenter -1)
  3871. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3872. (progn
  3873. (goto-char (or start-pos 1))
  3874. (recenter 1))))
  3875. (goto-char (or start-pos 1))
  3876. (add-text-properties (point-min) (point-max)
  3877. `(org-agenda-type agenda
  3878. org-last-args (,arg ,start-day ,span)
  3879. org-redo-cmd ,org-agenda-redo-command
  3880. org-series-cmd ,org-cmd))
  3881. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3882. (org-agenda-show-clocking-issues))
  3883. (org-agenda-finalize)
  3884. (setq buffer-read-only t)
  3885. (message ""))))
  3886. (defun org-agenda-ndays-to-span (n)
  3887. "Return a span symbol for a span of N days, or N if none matches."
  3888. (cond ((symbolp n) n)
  3889. ((= n 1) 'day)
  3890. ((= n 7) 'week)
  3891. (t n)))
  3892. (defun org-agenda-span-to-ndays (span &optional start-day)
  3893. "Return ndays from SPAN, possibly starting at START-DAY."
  3894. (cond ((numberp span) span)
  3895. ((eq span 'day) 1)
  3896. ((eq span 'week) 7)
  3897. ((eq span 'month)
  3898. (let ((date (calendar-gregorian-from-absolute start-day)))
  3899. (calendar-last-day-of-month (car date) (caddr date))))
  3900. ((eq span 'year)
  3901. (let ((date (calendar-gregorian-from-absolute start-day)))
  3902. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3903. (defun org-agenda-span-name (span)
  3904. "Return a SPAN name."
  3905. (if (null span)
  3906. ""
  3907. (if (symbolp span)
  3908. (capitalize (symbol-name span))
  3909. (format "%d days" span))))
  3910. ;;; Agenda word search
  3911. (defvar org-agenda-search-history nil)
  3912. (defvar org-search-syntax-table nil
  3913. "Special syntax table for org-mode search.
  3914. In this table, we have single quotes not as word constituents, to
  3915. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3916. (defvar org-mode-syntax-table) ; From org.el
  3917. (defun org-search-syntax-table ()
  3918. (unless org-search-syntax-table
  3919. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3920. (modify-syntax-entry ?' "." org-search-syntax-table)
  3921. (modify-syntax-entry ?` "." org-search-syntax-table))
  3922. org-search-syntax-table)
  3923. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3924. ;;;###autoload
  3925. (defun org-search-view (&optional todo-only string edit-at)
  3926. "Show all entries that contain a phrase or words or regular expressions.
  3927. With optional prefix argument TODO-ONLY, only consider entries that are
  3928. TODO entries. The argument STRING can be used to pass a default search
  3929. string into this function. If EDIT-AT is non-nil, it means that the
  3930. user should get a chance to edit this string, with cursor at position
  3931. EDIT-AT.
  3932. The search string can be viewed either as a phrase that should be found as
  3933. is, or it can be broken into a number of snippets, each of which must match
  3934. in a Boolean way to select an entry. The default depends on the variable
  3935. `org-agenda-search-view-always-boolean'.
  3936. Even if this is turned off (the default) you can always switch to
  3937. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3938. The default is a direct search of the whole phrase, where each space in
  3939. the search string can expand to an arbitrary amount of whitespace,
  3940. including newlines.
  3941. If using a Boolean search, the search string is split on whitespace and
  3942. each snippet is searched separately, with logical AND to select an entry.
  3943. Words prefixed with a minus must *not* occur in the entry. Words without
  3944. a prefix or prefixed with a plus must occur in the entry. Matching is
  3945. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3946. match whole words, not parts of a word) if
  3947. `org-agenda-search-view-force-full-words' is set (default is nil).
  3948. Boolean search snippets enclosed by curly braces are interpreted as
  3949. regular expressions that must or (when preceded with \"-\") must not
  3950. match in the entry. Snippets enclosed into double quotes will be taken
  3951. as a whole, to include whitespace.
  3952. - If the search string starts with an asterisk, search only in headlines.
  3953. - If (possibly after the leading star) the search string starts with an
  3954. exclamation mark, this also means to look at TODO entries only, an effect
  3955. that can also be achieved with a prefix argument.
  3956. - If (possibly after star and exclamation mark) the search string starts
  3957. with a colon, this will mean that the (non-regexp) snippets of the
  3958. Boolean search must match as full words.
  3959. This command searches the agenda files, and in addition the files listed
  3960. in `org-agenda-text-search-extra-files'."
  3961. (interactive "P")
  3962. (if org-agenda-overriding-arguments
  3963. (setq todo-only (car org-agenda-overriding-arguments)
  3964. string (nth 1 org-agenda-overriding-arguments)
  3965. edit-at (nth 2 org-agenda-overriding-arguments)))
  3966. (let* ((props (list 'face nil
  3967. 'done-face 'org-agenda-done
  3968. 'org-not-done-regexp org-not-done-regexp
  3969. 'org-todo-regexp org-todo-regexp
  3970. 'org-complex-heading-regexp org-complex-heading-regexp
  3971. 'mouse-face 'highlight
  3972. 'help-echo (format "mouse-2 or RET jump to location")))
  3973. (full-words org-agenda-search-view-force-full-words)
  3974. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3975. regexp rtn rtnall files file pos inherited-tags
  3976. marker category category-pos level tags c neg re boolean
  3977. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3978. (unless (and (not edit-at)
  3979. (stringp string)
  3980. (string-match "\\S-" string))
  3981. (setq string (read-string
  3982. (if org-agenda-search-view-always-boolean
  3983. "[+-]Word/{Regexp} ...: "
  3984. "Phrase or [+-]Word/{Regexp} ...: ")
  3985. (cond
  3986. ((integerp edit-at) (cons string edit-at))
  3987. (edit-at string))
  3988. 'org-agenda-search-history)))
  3989. (catch 'exit
  3990. (if org-agenda-sticky
  3991. (setq org-agenda-buffer-name
  3992. (if (stringp string)
  3993. (format "*Org Agenda(%s:%s)*"
  3994. (or org-keys (or (and todo-only "S") "s")) string)
  3995. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3996. (org-agenda-prepare "SEARCH")
  3997. (org-compile-prefix-format 'search)
  3998. (org-set-sorting-strategy 'search)
  3999. (setq org-agenda-redo-command
  4000. (list 'org-search-view (if todo-only t nil)
  4001. (list 'if 'current-prefix-arg nil string)))
  4002. (setq org-agenda-query-string string)
  4003. (if (equal (string-to-char string) ?*)
  4004. (setq hdl-only t
  4005. words (substring string 1))
  4006. (setq words string))
  4007. (when (equal (string-to-char words) ?!)
  4008. (setq todo-only t
  4009. words (substring words 1)))
  4010. (when (equal (string-to-char words) ?:)
  4011. (setq full-words t
  4012. words (substring words 1)))
  4013. (if (or org-agenda-search-view-always-boolean
  4014. (member (string-to-char words) '(?- ?+ ?\{)))
  4015. (setq boolean t))
  4016. (setq words (org-split-string words))
  4017. (let (www w)
  4018. (while (setq w (pop words))
  4019. (while (and (string-match "\\\\\\'" w) words)
  4020. (setq w (concat (substring w 0 -1) " " (pop words))))
  4021. (push w www))
  4022. (setq words (nreverse www) www nil)
  4023. (while (setq w (pop words))
  4024. (when (and (string-match "\\`[-+]?{" w)
  4025. (not (string-match "}\\'" w)))
  4026. (while (and words (not (string-match "}\\'" (car words))))
  4027. (setq w (concat w " " (pop words))))
  4028. (setq w (concat w " " (pop words))))
  4029. (push w www))
  4030. (setq words (nreverse www)))
  4031. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4032. (when boolean
  4033. (let (wds w)
  4034. (while (setq w (pop words))
  4035. (if (or (equal (substring w 0 1) "\"")
  4036. (and (> (length w) 1)
  4037. (member (substring w 0 1) '("+" "-"))
  4038. (equal (substring w 1 2) "\"")))
  4039. (while (and words (not (equal (substring w -1) "\"")))
  4040. (setq w (concat w " " (pop words)))))
  4041. (and (string-match "\\`\\([-+]?\\)\"" w)
  4042. (setq w (replace-match "\\1" nil nil w)))
  4043. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4044. (push w wds))
  4045. (setq words (nreverse wds))))
  4046. (if boolean
  4047. (mapc (lambda (w)
  4048. (setq c (string-to-char w))
  4049. (if (equal c ?-)
  4050. (setq neg t w (substring w 1))
  4051. (if (equal c ?+)
  4052. (setq neg nil w (substring w 1))
  4053. (setq neg nil)))
  4054. (if (string-match "\\`{.*}\\'" w)
  4055. (setq re (substring w 1 -1))
  4056. (if full-words
  4057. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4058. (setq re (regexp-quote (downcase w)))))
  4059. (if neg (push re regexps-) (push re regexps+)))
  4060. words)
  4061. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4062. regexps+))
  4063. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4064. (if (not regexps+)
  4065. (setq regexp org-outline-regexp-bol)
  4066. (setq regexp (pop regexps+))
  4067. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4068. regexp))))
  4069. (setq files (org-agenda-files nil 'ifmode))
  4070. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4071. (pop org-agenda-text-search-extra-files)
  4072. (setq files (org-add-archive-files files)))
  4073. (setq files (append files org-agenda-text-search-extra-files)
  4074. rtnall nil)
  4075. (while (setq file (pop files))
  4076. (setq ee nil)
  4077. (catch 'nextfile
  4078. (org-check-agenda-file file)
  4079. (setq buffer (if (file-exists-p file)
  4080. (org-get-agenda-file-buffer file)
  4081. (error "No such file %s" file)))
  4082. (if (not buffer)
  4083. ;; If file does not exist, make sure an error message is sent
  4084. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4085. file))))
  4086. (with-current-buffer buffer
  4087. (with-syntax-table (org-search-syntax-table)
  4088. (unless (derived-mode-p 'org-mode)
  4089. (error "Agenda file %s is not in `org-mode'" file))
  4090. (let ((case-fold-search t))
  4091. (save-excursion
  4092. (save-restriction
  4093. (if org-agenda-restrict
  4094. (narrow-to-region org-agenda-restrict-begin
  4095. org-agenda-restrict-end)
  4096. (widen))
  4097. (goto-char (point-min))
  4098. (unless (or (org-at-heading-p)
  4099. (outline-next-heading))
  4100. (throw 'nextfile t))
  4101. (goto-char (max (point-min) (1- (point))))
  4102. (while (re-search-forward regexp nil t)
  4103. (org-back-to-heading t)
  4104. (while (and org-agenda-search-view-max-outline-level
  4105. (> (org-reduced-level (org-outline-level))
  4106. org-agenda-search-view-max-outline-level)
  4107. (forward-line -1)
  4108. (outline-back-to-heading t)))
  4109. (skip-chars-forward "* ")
  4110. (setq beg (point-at-bol)
  4111. beg1 (point)
  4112. end (progn
  4113. (outline-next-heading)
  4114. (while (and org-agenda-search-view-max-outline-level
  4115. (> (org-reduced-level (org-outline-level))
  4116. org-agenda-search-view-max-outline-level)
  4117. (forward-line 1)
  4118. (outline-next-heading)))
  4119. (point)))
  4120. (catch :skip
  4121. (goto-char beg)
  4122. (org-agenda-skip)
  4123. (setq str (buffer-substring-no-properties
  4124. (point-at-bol)
  4125. (if hdl-only (point-at-eol) end)))
  4126. (mapc (lambda (wr) (when (string-match wr str)
  4127. (goto-char (1- end))
  4128. (throw :skip t)))
  4129. regexps-)
  4130. (mapc (lambda (wr) (unless (string-match wr str)
  4131. (goto-char (1- end))
  4132. (throw :skip t)))
  4133. (if todo-only
  4134. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4135. regexps+)
  4136. regexps+))
  4137. (goto-char beg)
  4138. (setq marker (org-agenda-new-marker (point))
  4139. category (org-get-category)
  4140. level (make-string (org-reduced-level (org-outline-level)) ? )
  4141. category-pos (get-text-property (point) 'org-category-position)
  4142. inherited-tags
  4143. (or (eq org-agenda-show-inherited-tags 'always)
  4144. (and (listp org-agenda-show-inherited-tags)
  4145. (memq 'todo org-agenda-show-inherited-tags))
  4146. (and (eq org-agenda-show-inherited-tags t)
  4147. (or (eq org-agenda-use-tag-inheritance t)
  4148. (memq 'todo org-agenda-use-tag-inheritance))))
  4149. tags (org-get-tags-at nil (not inherited-tags))
  4150. txt (org-agenda-format-item
  4151. ""
  4152. (buffer-substring-no-properties
  4153. beg1 (point-at-eol))
  4154. level category tags t))
  4155. (org-add-props txt props
  4156. 'org-marker marker 'org-hd-marker marker
  4157. 'org-todo-regexp org-todo-regexp
  4158. 'level level
  4159. 'org-complex-heading-regexp org-complex-heading-regexp
  4160. 'priority 1000 'org-category category
  4161. 'org-category-position category-pos
  4162. 'type "search")
  4163. (push txt ee)
  4164. (goto-char (1- end))))))))))
  4165. (setq rtn (nreverse ee))
  4166. (setq rtnall (append rtnall rtn)))
  4167. (if org-agenda-overriding-header
  4168. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4169. nil 'face 'org-agenda-structure) "\n")
  4170. (insert "Search words: ")
  4171. (add-text-properties (point-min) (1- (point))
  4172. (list 'face 'org-agenda-structure))
  4173. (setq pos (point))
  4174. (insert string "\n")
  4175. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4176. (setq pos (point))
  4177. (unless org-agenda-multi
  4178. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4179. (add-text-properties pos (1- (point))
  4180. (list 'face 'org-agenda-structure))))
  4181. (org-agenda-mark-header-line (point-min))
  4182. (when rtnall
  4183. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4184. (goto-char (point-min))
  4185. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4186. (add-text-properties (point-min) (point-max)
  4187. `(org-agenda-type search
  4188. org-last-args (,todo-only ,string ,edit-at)
  4189. org-redo-cmd ,org-agenda-redo-command
  4190. org-series-cmd ,org-cmd))
  4191. (org-agenda-finalize)
  4192. (setq buffer-read-only t))))
  4193. ;;; Agenda TODO list
  4194. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4195. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4196. (concat
  4197. (if (or (equal keywords "ALL") (not keywords))
  4198. (propertize "ALL" 'face 'warning)
  4199. (mapconcat
  4200. (lambda (kw)
  4201. (propertize kw 'face (org-get-todo-face kw)))
  4202. (org-split-string keywords "|")
  4203. "|"))
  4204. "\n"))
  4205. (defvar org-select-this-todo-keyword nil)
  4206. (defvar org-last-arg nil)
  4207. ;;;###autoload
  4208. (defun org-todo-list (&optional arg)
  4209. "Show all (not done) TODO entries from all agenda file in a single list.
  4210. The prefix arg can be used to select a specific TODO keyword and limit
  4211. the list to these. When using \\[universal-argument], you will be prompted
  4212. for a keyword. A numeric prefix directly selects the Nth keyword in
  4213. `org-todo-keywords-1'."
  4214. (interactive "P")
  4215. (if org-agenda-overriding-arguments
  4216. (setq arg org-agenda-overriding-arguments))
  4217. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4218. (let* ((today (org-today))
  4219. (date (calendar-gregorian-from-absolute today))
  4220. (kwds org-todo-keywords-for-agenda)
  4221. (completion-ignore-case t)
  4222. (org-select-this-todo-keyword
  4223. (if (stringp arg) arg
  4224. (and arg (integerp arg) (> arg 0)
  4225. (nth (1- arg) kwds))))
  4226. rtn rtnall files file pos)
  4227. (when (equal arg '(4))
  4228. (setq org-select-this-todo-keyword
  4229. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4230. (mapcar 'list kwds) nil nil)))
  4231. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4232. (catch 'exit
  4233. (if org-agenda-sticky
  4234. (setq org-agenda-buffer-name
  4235. (if (stringp org-select-this-todo-keyword)
  4236. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4237. org-select-this-todo-keyword)
  4238. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4239. (org-agenda-prepare "TODO")
  4240. (org-compile-prefix-format 'todo)
  4241. (org-set-sorting-strategy 'todo)
  4242. (setq org-agenda-redo-command
  4243. `(org-todo-list (or (and (numberp current-prefix-arg)
  4244. current-prefix-arg)
  4245. ,org-select-this-todo-keyword
  4246. current-prefix-arg ,arg)))
  4247. (setq files (org-agenda-files nil 'ifmode)
  4248. rtnall nil)
  4249. (while (setq file (pop files))
  4250. (catch 'nextfile
  4251. (org-check-agenda-file file)
  4252. (setq rtn (org-agenda-get-day-entries file date :todo))
  4253. (setq rtnall (append rtnall rtn))))
  4254. (if org-agenda-overriding-header
  4255. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4256. nil 'face 'org-agenda-structure) "\n")
  4257. (insert "Global list of TODO items of type: ")
  4258. (add-text-properties (point-min) (1- (point))
  4259. (list 'face 'org-agenda-structure
  4260. 'short-heading
  4261. (concat "ToDo: "
  4262. (or org-select-this-todo-keyword "ALL"))))
  4263. (org-agenda-mark-header-line (point-min))
  4264. (insert (org-agenda-propertize-selected-todo-keywords
  4265. org-select-this-todo-keyword))
  4266. (setq pos (point))
  4267. (unless org-agenda-multi
  4268. (insert "Available with `N r': (0)[ALL]")
  4269. (let ((n 0) s)
  4270. (mapc (lambda (x)
  4271. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4272. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4273. (insert "\n "))
  4274. (insert " " s))
  4275. kwds))
  4276. (insert "\n"))
  4277. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4278. (org-agenda-mark-header-line (point-min))
  4279. (when rtnall
  4280. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4281. (goto-char (point-min))
  4282. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4283. (add-text-properties (point-min) (point-max)
  4284. `(org-agenda-type todo
  4285. org-last-args ,arg
  4286. org-redo-cmd ,org-agenda-redo-command
  4287. org-series-cmd ,org-cmd))
  4288. (org-agenda-finalize)
  4289. (setq buffer-read-only t))))
  4290. ;;; Agenda tags match
  4291. ;;;###autoload
  4292. (defun org-tags-view (&optional todo-only match)
  4293. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4294. The prefix arg TODO-ONLY limits the search to TODO entries."
  4295. (interactive "P")
  4296. (if org-agenda-overriding-arguments
  4297. (setq todo-only (car org-agenda-overriding-arguments)
  4298. match (nth 1 org-agenda-overriding-arguments)))
  4299. (let* ((org-tags-match-list-sublevels
  4300. org-tags-match-list-sublevels)
  4301. (completion-ignore-case t)
  4302. rtn rtnall files file pos matcher
  4303. buffer)
  4304. (when (and (stringp match) (not (string-match "\\S-" match)))
  4305. (setq match nil))
  4306. (setq matcher (org-make-tags-matcher match)
  4307. match (car matcher) matcher (cdr matcher))
  4308. (catch 'exit
  4309. (if org-agenda-sticky
  4310. (setq org-agenda-buffer-name
  4311. (if (stringp match)
  4312. (format "*Org Agenda(%s:%s)*"
  4313. (or org-keys (or (and todo-only "M") "m")) match)
  4314. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4315. (org-agenda-prepare (concat "TAGS " match))
  4316. (org-compile-prefix-format 'tags)
  4317. (org-set-sorting-strategy 'tags)
  4318. (setq org-agenda-query-string match)
  4319. (setq org-agenda-redo-command
  4320. (list 'org-tags-view `(quote ,todo-only)
  4321. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4322. (setq files (org-agenda-files nil 'ifmode)
  4323. rtnall nil)
  4324. (while (setq file (pop files))
  4325. (catch 'nextfile
  4326. (org-check-agenda-file file)
  4327. (setq buffer (if (file-exists-p file)
  4328. (org-get-agenda-file-buffer file)
  4329. (error "No such file %s" file)))
  4330. (if (not buffer)
  4331. ;; If file does not exist, error message to agenda
  4332. (setq rtn (list
  4333. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4334. rtnall (append rtnall rtn))
  4335. (with-current-buffer buffer
  4336. (unless (derived-mode-p 'org-mode)
  4337. (error "Agenda file %s is not in `org-mode'" file))
  4338. (save-excursion
  4339. (save-restriction
  4340. (if org-agenda-restrict
  4341. (narrow-to-region org-agenda-restrict-begin
  4342. org-agenda-restrict-end)
  4343. (widen))
  4344. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4345. (setq rtnall (append rtnall rtn))))))))
  4346. (if org-agenda-overriding-header
  4347. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4348. nil 'face 'org-agenda-structure) "\n")
  4349. (insert "Headlines with TAGS match: ")
  4350. (add-text-properties (point-min) (1- (point))
  4351. (list 'face 'org-agenda-structure
  4352. 'short-heading
  4353. (concat "Match: " match)))
  4354. (setq pos (point))
  4355. (insert match "\n")
  4356. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4357. (setq pos (point))
  4358. (unless org-agenda-multi
  4359. (insert "Press `C-u r' to search again with new search string\n"))
  4360. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4361. (org-agenda-mark-header-line (point-min))
  4362. (when rtnall
  4363. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4364. (goto-char (point-min))
  4365. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4366. (add-text-properties (point-min) (point-max)
  4367. `(org-agenda-type tags
  4368. org-last-args (,todo-only ,match)
  4369. org-redo-cmd ,org-agenda-redo-command
  4370. org-series-cmd ,org-cmd))
  4371. (org-agenda-finalize)
  4372. (setq buffer-read-only t))))
  4373. ;;; Agenda Finding stuck projects
  4374. (defvar org-agenda-skip-regexp nil
  4375. "Regular expression used in skipping subtrees for the agenda.
  4376. This is basically a temporary global variable that can be set and then
  4377. used by user-defined selections using `org-agenda-skip-function'.")
  4378. (defvar org-agenda-overriding-header nil
  4379. "When set during agenda, todo and tags searches it replaces the header.
  4380. This variable should not be set directly, but custom commands can bind it
  4381. in the options section.")
  4382. (defun org-agenda-skip-entry-when-regexp-matches ()
  4383. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4384. If yes, it returns the end position of this entry, causing agenda commands
  4385. to skip the entry but continuing the search in the subtree. This is a
  4386. function that can be put into `org-agenda-skip-function' for the duration
  4387. of a command."
  4388. (let ((end (save-excursion (org-end-of-subtree t)))
  4389. skip)
  4390. (save-excursion
  4391. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4392. (and skip end)))
  4393. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4394. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4395. If yes, it returns the end position of this tree, causing agenda commands
  4396. to skip this subtree. This is a function that can be put into
  4397. `org-agenda-skip-function' for the duration of a command."
  4398. (let ((end (save-excursion (org-end-of-subtree t)))
  4399. skip)
  4400. (save-excursion
  4401. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4402. (and skip end)))
  4403. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4404. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4405. If yes, it returns the end position of the current entry (NOT the tree),
  4406. causing agenda commands to skip the entry but continuing the search in
  4407. the subtree. This is a function that can be put into
  4408. `org-agenda-skip-function' for the duration of a command. An important
  4409. use of this function is for the stuck project list."
  4410. (let ((end (save-excursion (org-end-of-subtree t)))
  4411. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4412. skip)
  4413. (save-excursion
  4414. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4415. (and skip entry-end)))
  4416. (defun org-agenda-skip-entry-if (&rest conditions)
  4417. "Skip entry if any of CONDITIONS is true.
  4418. See `org-agenda-skip-if' for details."
  4419. (org-agenda-skip-if nil conditions))
  4420. (defun org-agenda-skip-subtree-if (&rest conditions)
  4421. "Skip entry if any of CONDITIONS is true.
  4422. See `org-agenda-skip-if' for details."
  4423. (org-agenda-skip-if t conditions))
  4424. (defun org-agenda-skip-if (subtree conditions)
  4425. "Checks current entity for CONDITIONS.
  4426. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4427. the entry (i.e. the text before the next heading) is checked.
  4428. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4429. from different tests. Valid conditions are:
  4430. scheduled Check if there is a scheduled cookie
  4431. notscheduled Check if there is no scheduled cookie
  4432. deadline Check if there is a deadline
  4433. notdeadline Check if there is no deadline
  4434. timestamp Check if there is a timestamp (also deadline or scheduled)
  4435. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4436. regexp Check if regexp matches
  4437. notregexp Check if regexp does not match.
  4438. todo Check if TODO keyword matches
  4439. nottodo Check if TODO keyword does not match
  4440. The regexp is taken from the conditions list, it must come right after
  4441. the `regexp' or `notregexp' element.
  4442. `todo' and `nottodo' accept as an argument a list of todo
  4443. keywords, which may include \"*\" to match any todo keyword.
  4444. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4445. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4446. Instead of a list, a keyword class may be given. For example:
  4447. (org-agenda-skip-entry-if 'nottodo 'done)
  4448. would skip entries that haven't been marked with any of \"DONE\"
  4449. keywords. Possible classes are: `todo', `done', `any'.
  4450. If any of these conditions is met, this function returns the end point of
  4451. the entity, causing the search to continue from there. This is a function
  4452. that can be put into `org-agenda-skip-function' for the duration of a command."
  4453. (let (beg end m)
  4454. (org-back-to-heading t)
  4455. (setq beg (point)
  4456. end (if subtree
  4457. (progn (org-end-of-subtree t) (point))
  4458. (progn (outline-next-heading) (1- (point)))))
  4459. (goto-char beg)
  4460. (and
  4461. (or
  4462. (and (memq 'scheduled conditions)
  4463. (re-search-forward org-scheduled-time-regexp end t))
  4464. (and (memq 'notscheduled conditions)
  4465. (not (re-search-forward org-scheduled-time-regexp end t)))
  4466. (and (memq 'deadline conditions)
  4467. (re-search-forward org-deadline-time-regexp end t))
  4468. (and (memq 'notdeadline conditions)
  4469. (not (re-search-forward org-deadline-time-regexp end t)))
  4470. (and (memq 'timestamp conditions)
  4471. (re-search-forward org-ts-regexp end t))
  4472. (and (memq 'nottimestamp conditions)
  4473. (not (re-search-forward org-ts-regexp end t)))
  4474. (and (setq m (memq 'regexp conditions))
  4475. (stringp (nth 1 m))
  4476. (re-search-forward (nth 1 m) end t))
  4477. (and (setq m (memq 'notregexp conditions))
  4478. (stringp (nth 1 m))
  4479. (not (re-search-forward (nth 1 m) end t)))
  4480. (and (or
  4481. (setq m (memq 'nottodo conditions))
  4482. (setq m (memq 'todo-unblocked conditions))
  4483. (setq m (memq 'nottodo-unblocked conditions))
  4484. (setq m (memq 'todo conditions)))
  4485. (org-agenda-skip-if-todo m end)))
  4486. end)))
  4487. (defun org-agenda-skip-if-todo (args end)
  4488. "Helper function for `org-agenda-skip-if', do not use it directly.
  4489. ARGS is a list with first element either `todo', `nottodo',
  4490. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4491. a list of TODO keywords, or a state symbol `todo' or `done' or
  4492. `any'."
  4493. (let ((kw (car args))
  4494. (arg (cadr args))
  4495. todo-wds todo-re)
  4496. (setq todo-wds
  4497. (org-uniquify
  4498. (cond
  4499. ((listp arg) ;; list of keywords
  4500. (if (member "*" arg)
  4501. (mapcar 'substring-no-properties org-todo-keywords-1)
  4502. arg))
  4503. ((symbolp arg) ;; keyword class name
  4504. (cond
  4505. ((eq arg 'todo)
  4506. (org-delete-all org-done-keywords
  4507. (mapcar 'substring-no-properties
  4508. org-todo-keywords-1)))
  4509. ((eq arg 'done) org-done-keywords)
  4510. ((eq arg 'any)
  4511. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4512. (setq todo-re
  4513. (concat "^\\*+[ \t]+\\<\\("
  4514. (mapconcat 'identity todo-wds "\\|")
  4515. "\\)\\>"))
  4516. (cond
  4517. ((eq kw 'todo) (re-search-forward todo-re end t))
  4518. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4519. ((eq kw 'todo-unblocked)
  4520. (catch 'unblocked
  4521. (while (re-search-forward todo-re end t)
  4522. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4523. nil))
  4524. ((eq kw 'nottodo-unblocked)
  4525. (catch 'unblocked
  4526. (while (re-search-forward todo-re end t)
  4527. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4528. t))
  4529. )))
  4530. ;;;###autoload
  4531. (defun org-agenda-list-stuck-projects (&rest ignore)
  4532. "Create agenda view for projects that are stuck.
  4533. Stuck projects are project that have no next actions. For the definitions
  4534. of what a project is and how to check if it stuck, customize the variable
  4535. `org-stuck-projects'."
  4536. (interactive)
  4537. (let* ((org-agenda-skip-function
  4538. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4539. ;; We could have used org-agenda-skip-if here.
  4540. (org-agenda-overriding-header
  4541. (or org-agenda-overriding-header "List of stuck projects: "))
  4542. (matcher (nth 0 org-stuck-projects))
  4543. (todo (nth 1 org-stuck-projects))
  4544. (todo-wds (if (member "*" todo)
  4545. (progn
  4546. (org-agenda-prepare-buffers (org-agenda-files
  4547. nil 'ifmode))
  4548. (org-delete-all
  4549. org-done-keywords-for-agenda
  4550. (copy-sequence org-todo-keywords-for-agenda)))
  4551. todo))
  4552. (todo-re (concat "^\\*+[ \t]+\\("
  4553. (mapconcat 'identity todo-wds "\\|")
  4554. "\\)\\>"))
  4555. (tags (nth 2 org-stuck-projects))
  4556. (tags-re (if (member "*" tags)
  4557. (concat org-outline-regexp-bol
  4558. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4559. (if tags
  4560. (concat org-outline-regexp-bol
  4561. ".*:\\("
  4562. (mapconcat 'identity tags "\\|")
  4563. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4564. (gen-re (nth 3 org-stuck-projects))
  4565. (re-list
  4566. (delq nil
  4567. (list
  4568. (if todo todo-re)
  4569. (if tags tags-re)
  4570. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4571. gen-re)))))
  4572. (setq org-agenda-skip-regexp
  4573. (if re-list
  4574. (mapconcat 'identity re-list "\\|")
  4575. (error "No information how to identify unstuck projects")))
  4576. (org-tags-view nil matcher)
  4577. (with-current-buffer org-agenda-buffer-name
  4578. (setq org-agenda-redo-command
  4579. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4580. ;;; Diary integration
  4581. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4582. (defvar diary-list-entries-hook)
  4583. (defvar diary-time-regexp)
  4584. (defun org-get-entries-from-diary (date)
  4585. "Get the (Emacs Calendar) diary entries for DATE."
  4586. (require 'diary-lib)
  4587. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4588. (diary-display-hook '(fancy-diary-display))
  4589. (diary-display-function 'fancy-diary-display)
  4590. (pop-up-frames nil)
  4591. (diary-list-entries-hook
  4592. (cons 'org-diary-default-entry diary-list-entries-hook))
  4593. (diary-file-name-prefix nil) ; turn this feature off
  4594. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4595. entries
  4596. (org-disable-agenda-to-diary t))
  4597. (save-excursion
  4598. (save-window-excursion
  4599. (funcall (if (fboundp 'diary-list-entries)
  4600. 'diary-list-entries 'list-diary-entries)
  4601. date 1)))
  4602. (if (not (get-buffer diary-fancy-buffer))
  4603. (setq entries nil)
  4604. (with-current-buffer diary-fancy-buffer
  4605. (setq buffer-read-only nil)
  4606. (if (zerop (buffer-size))
  4607. ;; No entries
  4608. (setq entries nil)
  4609. ;; Omit the date and other unnecessary stuff
  4610. (org-agenda-cleanup-fancy-diary)
  4611. ;; Add prefix to each line and extend the text properties
  4612. (if (zerop (buffer-size))
  4613. (setq entries nil)
  4614. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4615. (setq entries
  4616. (with-temp-buffer
  4617. (insert entries) (goto-char (point-min))
  4618. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4619. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4620. (replace-match (concat "; " (match-string 1)))))
  4621. (buffer-string)))))
  4622. (set-buffer-modified-p nil)
  4623. (kill-buffer diary-fancy-buffer)))
  4624. (when entries
  4625. (setq entries (org-split-string entries "\n"))
  4626. (setq entries
  4627. (mapcar
  4628. (lambda (x)
  4629. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4630. ;; Extend the text properties to the beginning of the line
  4631. (org-add-props x (text-properties-at (1- (length x)) x)
  4632. 'type "diary" 'date date 'face 'org-agenda-diary))
  4633. entries)))))
  4634. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4635. "Hook run when the fancy diary buffer is cleaned up.")
  4636. (defun org-agenda-cleanup-fancy-diary ()
  4637. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4638. This gets rid of the date, the underline under the date, and
  4639. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4640. date. It also removes lines that contain only whitespace."
  4641. (goto-char (point-min))
  4642. (if (looking-at ".*?:[ \t]*")
  4643. (progn
  4644. (replace-match "")
  4645. (re-search-forward "\n=+$" nil t)
  4646. (replace-match "")
  4647. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4648. (re-search-forward "\n=+$" nil t)
  4649. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4650. (goto-char (point-min))
  4651. (while (re-search-forward "^ +\n" nil t)
  4652. (replace-match ""))
  4653. (goto-char (point-min))
  4654. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4655. (replace-match ""))
  4656. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4657. ;; Make sure entries from the diary have the right text properties.
  4658. (eval-after-load "diary-lib"
  4659. '(if (boundp 'diary-modify-entry-list-string-function)
  4660. ;; We can rely on the hook, nothing to do
  4661. nil
  4662. ;; Hook not available, must use advice to make this work
  4663. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4664. "Make the position visible."
  4665. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4666. (stringp string)
  4667. buffer-file-name)
  4668. (setq string (org-modify-diary-entry-string string))))))
  4669. (defun org-modify-diary-entry-string (string)
  4670. "Add text properties to string, allowing org-mode to act on it."
  4671. (org-add-props string nil
  4672. 'mouse-face 'highlight
  4673. 'help-echo (if buffer-file-name
  4674. (format "mouse-2 or RET jump to diary file %s"
  4675. (abbreviate-file-name buffer-file-name))
  4676. "")
  4677. 'org-agenda-diary-link t
  4678. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4679. (defun org-diary-default-entry ()
  4680. "Add a dummy entry to the diary.
  4681. Needed to avoid empty dates which mess up holiday display."
  4682. ;; Catch the error if dealing with the new add-to-diary-alist
  4683. (when org-disable-agenda-to-diary
  4684. (condition-case nil
  4685. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4686. (error
  4687. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4688. (defun org-add-to-diary-list (&rest args)
  4689. (if (fboundp 'diary-add-to-list)
  4690. (apply 'diary-add-to-list args)
  4691. (apply 'add-to-diary-list args)))
  4692. (defvar org-diary-last-run-time nil)
  4693. ;;;###autoload
  4694. (defun org-diary (&rest args)
  4695. "Return diary information from org files.
  4696. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4697. It accesses org files and extracts information from those files to be
  4698. listed in the diary. The function accepts arguments specifying what
  4699. items should be listed. For a list of arguments allowed here, see the
  4700. variable `org-agenda-entry-types'.
  4701. The call in the diary file should look like this:
  4702. &%%(org-diary) ~/path/to/some/orgfile.org
  4703. Use a separate line for each org file to check. Or, if you omit the file name,
  4704. all files listed in `org-agenda-files' will be checked automatically:
  4705. &%%(org-diary)
  4706. If you don't give any arguments (as in the example above), the default
  4707. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4708. So the example above may also be written as
  4709. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4710. The function expects the lisp variables `entry' and `date' to be provided
  4711. by the caller, because this is how the calendar works. Don't use this
  4712. function from a program - use `org-agenda-get-day-entries' instead."
  4713. (when (> (- (org-float-time)
  4714. org-agenda-last-marker-time)
  4715. 5)
  4716. ;; I am not sure if this works with sticky agendas, because the marker
  4717. ;; list is then no longer a global variable.
  4718. (org-agenda-reset-markers))
  4719. (org-compile-prefix-format 'agenda)
  4720. (org-set-sorting-strategy 'agenda)
  4721. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4722. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4723. (list entry)
  4724. (org-agenda-files t)))
  4725. (time (org-float-time))
  4726. file rtn results)
  4727. (when (or (not org-diary-last-run-time)
  4728. (> (- time
  4729. org-diary-last-run-time)
  4730. 3))
  4731. (org-agenda-prepare-buffers files))
  4732. (setq org-diary-last-run-time time)
  4733. ;; If this is called during org-agenda, don't return any entries to
  4734. ;; the calendar. Org Agenda will list these entries itself.
  4735. (if org-disable-agenda-to-diary (setq files nil))
  4736. (while (setq file (pop files))
  4737. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4738. (setq results (append results rtn)))
  4739. (when results
  4740. (setq results
  4741. (mapcar (lambda (i) (replace-regexp-in-string
  4742. org-bracket-link-regexp "\\3" i)) results))
  4743. (concat (org-agenda-finalize-entries results) "\n"))))
  4744. ;;; Agenda entry finders
  4745. (defun org-agenda-get-day-entries (file date &rest args)
  4746. "Does the work for `org-diary' and `org-agenda'.
  4747. FILE is the path to a file to be checked for entries. DATE is date like
  4748. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4749. which kind of entries should be extracted. For details about these, see
  4750. the documentation of `org-diary'."
  4751. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4752. (let* ((org-startup-folded nil)
  4753. (org-startup-align-all-tables nil)
  4754. (buffer (if (file-exists-p file)
  4755. (org-get-agenda-file-buffer file)
  4756. (error "No such file %s" file)))
  4757. arg results rtn deadline-results)
  4758. (if (not buffer)
  4759. ;; If file does not exist, make sure an error message ends up in diary
  4760. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4761. (with-current-buffer buffer
  4762. (unless (derived-mode-p 'org-mode)
  4763. (error "Agenda file %s is not in `org-mode'" file))
  4764. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4765. (let ((case-fold-search nil))
  4766. (save-excursion
  4767. (save-restriction
  4768. (if org-agenda-restrict
  4769. (narrow-to-region org-agenda-restrict-begin
  4770. org-agenda-restrict-end)
  4771. (widen))
  4772. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4773. (while (setq arg (pop args))
  4774. (cond
  4775. ((and (eq arg :todo)
  4776. (equal date (calendar-gregorian-from-absolute
  4777. (org-today))))
  4778. (setq rtn (org-agenda-get-todos))
  4779. (setq results (append results rtn)))
  4780. ((eq arg :timestamp)
  4781. (setq rtn (org-agenda-get-blocks))
  4782. (setq results (append results rtn))
  4783. (setq rtn (org-agenda-get-timestamps deadline-results))
  4784. (setq results (append results rtn)))
  4785. ((eq arg :sexp)
  4786. (setq rtn (org-agenda-get-sexps))
  4787. (setq results (append results rtn)))
  4788. ((eq arg :scheduled)
  4789. (setq rtn (org-agenda-get-scheduled deadline-results))
  4790. (setq results (append results rtn)))
  4791. ((eq arg :closed)
  4792. (setq rtn (org-agenda-get-progress))
  4793. (setq results (append results rtn)))
  4794. ((eq arg :deadline)
  4795. (setq rtn (org-agenda-get-deadlines))
  4796. (setq deadline-results (copy-sequence rtn))
  4797. (setq results (append results rtn))))))))
  4798. results))))
  4799. (defsubst org-em (x y list)
  4800. "Is X or Y a member of LIST?"
  4801. (or (memq x list) (memq y list)))
  4802. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4803. (defvar org-agenda-sorting-strategy-selected nil)
  4804. (defun org-agenda-get-todos ()
  4805. "Return the TODO information for agenda display."
  4806. (let* ((props (list 'face nil
  4807. 'done-face 'org-agenda-done
  4808. 'org-not-done-regexp org-not-done-regexp
  4809. 'org-todo-regexp org-todo-regexp
  4810. 'org-complex-heading-regexp org-complex-heading-regexp
  4811. 'mouse-face 'highlight
  4812. 'help-echo
  4813. (format "mouse-2 or RET jump to org file %s"
  4814. (abbreviate-file-name buffer-file-name))))
  4815. (regexp (format org-heading-keyword-regexp-format
  4816. (cond
  4817. ((and org-select-this-todo-keyword
  4818. (equal org-select-this-todo-keyword "*"))
  4819. org-todo-regexp)
  4820. (org-select-this-todo-keyword
  4821. (concat "\\("
  4822. (mapconcat 'identity
  4823. (org-split-string
  4824. org-select-this-todo-keyword
  4825. "|")
  4826. "\\|") "\\)"))
  4827. (t org-not-done-regexp))))
  4828. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4829. ee txt beg end inherited-tags)
  4830. (goto-char (point-min))
  4831. (while (re-search-forward regexp nil t)
  4832. (catch :skip
  4833. (save-match-data
  4834. (beginning-of-line)
  4835. (org-agenda-skip)
  4836. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4837. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4838. (goto-char (1+ beg))
  4839. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4840. (throw :skip nil)))
  4841. (goto-char (match-beginning 2))
  4842. (setq marker (org-agenda-new-marker (match-beginning 0))
  4843. category (org-get-category)
  4844. ts-date (let (ts)
  4845. (save-match-data
  4846. (cond ((org-em 'scheduled-up 'scheduled-down
  4847. org-agenda-sorting-strategy-selected)
  4848. (setq ts (org-entry-get (point) "SCHEDULED")
  4849. ts-date-type " scheduled"))
  4850. ((org-em 'deadline-up 'deadline-down
  4851. org-agenda-sorting-strategy-selected)
  4852. (setq ts (org-entry-get (point) "DEADLINE")
  4853. ts-date-type " deadline"))
  4854. ((org-em 'ts-up 'ts-down
  4855. org-agenda-sorting-strategy-selected)
  4856. (setq ts (org-entry-get (point) "TIMESTAMP")
  4857. ts-date-type " timestamp"))
  4858. ((org-em 'tsia-up 'tsia-down
  4859. org-agenda-sorting-strategy-selected)
  4860. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4861. ts-date-type " timestamp_ia"))
  4862. ((org-em 'timestamp-up 'timestamp-down
  4863. org-agenda-sorting-strategy-selected)
  4864. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4865. (org-entry-get (point) "DEADLINE")
  4866. (org-entry-get (point) "TIMESTAMP")
  4867. (org-entry-get (point) "TIMESTAMP_IA"))
  4868. ts-date-type ""))
  4869. (t (setq ts-date-type "")))
  4870. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4871. category-pos (get-text-property (point) 'org-category-position)
  4872. txt (org-trim
  4873. (buffer-substring (match-beginning 2) (match-end 0)))
  4874. inherited-tags
  4875. (or (eq org-agenda-show-inherited-tags 'always)
  4876. (and (listp org-agenda-show-inherited-tags)
  4877. (memq 'todo org-agenda-show-inherited-tags))
  4878. (and (eq org-agenda-show-inherited-tags t)
  4879. (or (eq org-agenda-use-tag-inheritance t)
  4880. (memq 'todo org-agenda-use-tag-inheritance))))
  4881. tags (org-get-tags-at nil (not inherited-tags))
  4882. level (make-string (org-reduced-level (org-outline-level)) ? )
  4883. txt (org-agenda-format-item "" txt level category tags t)
  4884. priority (1+ (org-get-priority txt))
  4885. todo-state (org-get-todo-state))
  4886. (org-add-props txt props
  4887. 'org-marker marker 'org-hd-marker marker
  4888. 'priority priority 'org-category category
  4889. 'level level
  4890. 'ts-date ts-date
  4891. 'org-category-position category-pos
  4892. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4893. (push txt ee)
  4894. (if org-agenda-todo-list-sublevels
  4895. (goto-char (match-end 2))
  4896. (org-end-of-subtree 'invisible))))
  4897. (nreverse ee)))
  4898. (defun org-agenda-todo-custom-ignore-p (time n)
  4899. "Check whether timestamp is farther away than n number of days.
  4900. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4901. `org-agenda-todo-ignore-scheduled' or
  4902. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4903. (let ((days (org-time-stamp-to-now
  4904. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4905. (if (>= n 0)
  4906. (>= days n)
  4907. (<= days n))))
  4908. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4909. (&optional end)
  4910. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4911. (when (or org-agenda-todo-ignore-with-date
  4912. org-agenda-todo-ignore-scheduled
  4913. org-agenda-todo-ignore-deadlines
  4914. org-agenda-todo-ignore-timestamp)
  4915. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4916. (save-excursion
  4917. (or (and org-agenda-todo-ignore-with-date
  4918. (re-search-forward org-ts-regexp end t))
  4919. (and org-agenda-todo-ignore-scheduled
  4920. (re-search-forward org-scheduled-time-regexp end t)
  4921. (cond
  4922. ((eq org-agenda-todo-ignore-scheduled 'future)
  4923. (> (org-time-stamp-to-now
  4924. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4925. ((eq org-agenda-todo-ignore-scheduled 'past)
  4926. (<= (org-time-stamp-to-now
  4927. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4928. ((numberp org-agenda-todo-ignore-scheduled)
  4929. (org-agenda-todo-custom-ignore-p
  4930. (match-string 1) org-agenda-todo-ignore-scheduled))
  4931. (t)))
  4932. (and org-agenda-todo-ignore-deadlines
  4933. (re-search-forward org-deadline-time-regexp end t)
  4934. (cond
  4935. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4936. ((eq org-agenda-todo-ignore-deadlines 'far)
  4937. (not (org-deadline-close (match-string 1))))
  4938. ((eq org-agenda-todo-ignore-deadlines 'future)
  4939. (> (org-time-stamp-to-now
  4940. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4941. ((eq org-agenda-todo-ignore-deadlines 'past)
  4942. (<= (org-time-stamp-to-now
  4943. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4944. ((numberp org-agenda-todo-ignore-deadlines)
  4945. (org-agenda-todo-custom-ignore-p
  4946. (match-string 1) org-agenda-todo-ignore-deadlines))
  4947. (t (org-deadline-close (match-string 1)))))
  4948. (and org-agenda-todo-ignore-timestamp
  4949. (let ((buffer (current-buffer))
  4950. (regexp
  4951. (concat
  4952. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4953. (start (point)))
  4954. ;; Copy current buffer into a temporary one
  4955. (with-temp-buffer
  4956. (insert-buffer-substring buffer start end)
  4957. (goto-char (point-min))
  4958. ;; Delete SCHEDULED and DEADLINE items
  4959. (while (re-search-forward regexp end t)
  4960. (delete-region (match-beginning 0) (match-end 0)))
  4961. (goto-char (point-min))
  4962. ;; No search for timestamp left
  4963. (when (re-search-forward org-ts-regexp nil t)
  4964. (cond
  4965. ((eq org-agenda-todo-ignore-timestamp 'future)
  4966. (> (org-time-stamp-to-now
  4967. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4968. ((eq org-agenda-todo-ignore-timestamp 'past)
  4969. (<= (org-time-stamp-to-now
  4970. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4971. ((numberp org-agenda-todo-ignore-timestamp)
  4972. (org-agenda-todo-custom-ignore-p
  4973. (match-string 1) org-agenda-todo-ignore-timestamp))
  4974. (t))))))))))
  4975. (defun org-agenda-get-timestamps (&optional deadline-results)
  4976. "Return the date stamp information for agenda display."
  4977. (let* ((props (list 'face 'org-agenda-calendar-event
  4978. 'org-not-done-regexp org-not-done-regexp
  4979. 'org-todo-regexp org-todo-regexp
  4980. 'org-complex-heading-regexp org-complex-heading-regexp
  4981. 'mouse-face 'highlight
  4982. 'help-echo
  4983. (format "mouse-2 or RET jump to org file %s"
  4984. (abbreviate-file-name buffer-file-name))))
  4985. (d1 (calendar-absolute-from-gregorian date))
  4986. mm
  4987. (deadline-position-alist
  4988. (mapcar (lambda (a) (and (setq mm (get-text-property
  4989. 0 'org-hd-marker a))
  4990. (cons (marker-position mm) a)))
  4991. deadline-results))
  4992. (remove-re org-ts-regexp)
  4993. (regexp
  4994. (concat
  4995. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4996. (regexp-quote
  4997. (substring
  4998. (format-time-string
  4999. (car org-time-stamp-formats)
  5000. (apply 'encode-time ; DATE bound by calendar
  5001. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5002. 1 11))
  5003. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5004. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5005. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5006. donep tmp priority category category-pos level ee txt timestr tags
  5007. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5008. inherited-tags ts-date)
  5009. (goto-char (point-min))
  5010. (while (setq end-of-match (re-search-forward regexp nil t))
  5011. (setq b0 (match-beginning 0)
  5012. b3 (match-beginning 3) e3 (match-end 3)
  5013. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5014. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5015. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5016. (member todo-state
  5017. org-agenda-repeating-timestamp-show-all)))
  5018. (catch :skip
  5019. (and (org-at-date-range-p) (throw :skip nil))
  5020. (org-agenda-skip)
  5021. (if (and (match-end 1)
  5022. (not (= d1 (org-time-string-to-absolute
  5023. (match-string 1) d1 nil show-all
  5024. (current-buffer) b0))))
  5025. (throw :skip nil))
  5026. (if (and e3
  5027. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5028. (throw :skip nil))
  5029. (setq tmp (buffer-substring (max (point-min)
  5030. (- b0 org-ds-keyword-length))
  5031. b0)
  5032. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5033. inactivep (= (char-after b0) ?\[)
  5034. deadlinep (string-match org-deadline-regexp tmp)
  5035. scheduledp (string-match org-scheduled-regexp tmp)
  5036. closedp (and org-agenda-include-inactive-timestamps
  5037. (string-match org-closed-string tmp))
  5038. clockp (and org-agenda-include-inactive-timestamps
  5039. (or (string-match org-clock-string tmp)
  5040. (string-match "]-+\\'" tmp)))
  5041. warntime (get-text-property (point) 'org-appt-warntime)
  5042. donep (member todo-state org-done-keywords))
  5043. (if (or scheduledp deadlinep closedp clockp
  5044. (and donep org-agenda-skip-timestamp-if-done))
  5045. (throw :skip t))
  5046. (if (string-match ">" timestr)
  5047. ;; substring should only run to end of time stamp
  5048. (setq timestr (substring timestr 0 (match-end 0))))
  5049. (setq marker (org-agenda-new-marker b0)
  5050. category (org-get-category b0)
  5051. category-pos (get-text-property b0 'org-category-position))
  5052. (save-excursion
  5053. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5054. (throw :skip nil)
  5055. (goto-char (match-beginning 0))
  5056. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5057. (assoc (point) deadline-position-alist))
  5058. (throw :skip nil))
  5059. (setq hdmarker (org-agenda-new-marker)
  5060. inherited-tags
  5061. (or (eq org-agenda-show-inherited-tags 'always)
  5062. (and (listp org-agenda-show-inherited-tags)
  5063. (memq 'agenda org-agenda-show-inherited-tags))
  5064. (and (eq org-agenda-show-inherited-tags t)
  5065. (or (eq org-agenda-use-tag-inheritance t)
  5066. (memq 'agenda org-agenda-use-tag-inheritance))))
  5067. tags (org-get-tags-at nil (not inherited-tags))
  5068. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5069. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5070. (setq head (or (match-string 1) ""))
  5071. (setq txt (org-agenda-format-item
  5072. (if inactivep org-agenda-inactive-leader nil)
  5073. head level category tags timestr
  5074. remove-re habitp)))
  5075. (setq priority (org-get-priority txt))
  5076. (org-add-props txt props 'priority priority
  5077. 'org-marker marker 'org-hd-marker hdmarker
  5078. 'org-category category 'date date
  5079. 'level level
  5080. 'ts-date
  5081. (ignore-errors (org-time-string-to-absolute timestr))
  5082. 'org-category-position category-pos
  5083. 'todo-state todo-state
  5084. 'warntime warntime
  5085. 'type "timestamp")
  5086. (push txt ee))
  5087. (if org-agenda-skip-additional-timestamps-same-entry
  5088. (outline-next-heading)
  5089. (goto-char end-of-match))))
  5090. (nreverse ee)))
  5091. (defun org-agenda-get-sexps ()
  5092. "Return the sexp information for agenda display."
  5093. (require 'diary-lib)
  5094. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5095. 'mouse-face 'highlight
  5096. 'help-echo
  5097. (format "mouse-2 or RET jump to org file %s"
  5098. (abbreviate-file-name buffer-file-name))))
  5099. (regexp "^&?%%(")
  5100. marker category extra category-pos level ee txt tags entry
  5101. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5102. (goto-char (point-min))
  5103. (while (re-search-forward regexp nil t)
  5104. (catch :skip
  5105. (org-agenda-skip)
  5106. (setq beg (match-beginning 0))
  5107. (goto-char (1- (match-end 0)))
  5108. (setq b (point))
  5109. (forward-sexp 1)
  5110. (setq sexp (buffer-substring b (point)))
  5111. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5112. (org-trim (match-string 1))
  5113. ""))
  5114. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5115. (when result
  5116. (setq marker (org-agenda-new-marker beg)
  5117. level (make-string (org-reduced-level (org-outline-level)) ? )
  5118. category (org-get-category beg)
  5119. category-pos (get-text-property beg 'org-category-position)
  5120. inherited-tags
  5121. (or (eq org-agenda-show-inherited-tags 'always)
  5122. (and (listp org-agenda-show-inherited-tags)
  5123. (memq 'agenda org-agenda-show-inherited-tags))
  5124. (and (eq org-agenda-show-inherited-tags t)
  5125. (or (eq org-agenda-use-tag-inheritance t)
  5126. (memq 'agenda org-agenda-use-tag-inheritance))))
  5127. tags (org-get-tags-at nil (not inherited-tags))
  5128. todo-state (org-get-todo-state)
  5129. warntime (get-text-property (point) 'org-appt-warntime)
  5130. extra nil)
  5131. (dolist (r (if (stringp result)
  5132. (list result)
  5133. result)) ;; we expect a list here
  5134. (when (and org-agenda-diary-sexp-prefix
  5135. (string-match org-agenda-diary-sexp-prefix r))
  5136. (setq extra (match-string 0 r)
  5137. r (replace-match "" nil nil r)))
  5138. (if (string-match "\\S-" r)
  5139. (setq txt r)
  5140. (setq txt "SEXP entry returned empty string"))
  5141. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5142. (org-add-props txt props 'org-marker marker
  5143. 'org-category category 'date date 'todo-state todo-state
  5144. 'org-category-position category-pos 'tags tags
  5145. 'level level
  5146. 'type "sexp" 'warntime warntime)
  5147. (push txt ee)))))
  5148. (nreverse ee)))
  5149. ;; Calendar sanity: define some functions that are independent of
  5150. ;; `calendar-date-style'.
  5151. ;; Normally I would like to use ISO format when calling the diary functions,
  5152. ;; but to make sure we still have Emacs 22 compatibility we bind
  5153. ;; also `european-calendar-style' and use european format
  5154. (defun org-anniversary (year month day &optional mark)
  5155. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5156. (org-no-warnings
  5157. (let ((calendar-date-style 'european) (european-calendar-style t))
  5158. (diary-anniversary day month year mark))))
  5159. (defun org-cyclic (N year month day &optional mark)
  5160. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5161. (org-no-warnings
  5162. (let ((calendar-date-style 'european) (european-calendar-style t))
  5163. (diary-cyclic N day month year mark))))
  5164. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5165. "Like `diary-block', but with fixed (ISO) order of arguments."
  5166. (org-no-warnings
  5167. (let ((calendar-date-style 'european) (european-calendar-style t))
  5168. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5169. (defun org-date (year month day &optional mark)
  5170. "Like `diary-date', but with fixed (ISO) order of arguments."
  5171. (org-no-warnings
  5172. (let ((calendar-date-style 'european) (european-calendar-style t))
  5173. (diary-date day month year mark))))
  5174. ;; Define the` org-class' function
  5175. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5176. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5177. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5178. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5179. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5180. `holidays', then any date that is known by the Emacs calendar to be a
  5181. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5182. then those holidays will be skipped."
  5183. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5184. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5185. (d (calendar-absolute-from-gregorian date))
  5186. (h (when skip-weeks (calendar-check-holidays date))))
  5187. (and
  5188. (<= date1 d)
  5189. (<= d date2)
  5190. (= (calendar-day-of-week date) dayname)
  5191. (or (not skip-weeks)
  5192. (progn
  5193. (require 'cal-iso)
  5194. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5195. (not (or (and h (memq 'holidays skip-weeks))
  5196. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5197. entry)))
  5198. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5199. "Like `org-class', but honor `calendar-date-style'.
  5200. The order of the first 2 times 3 arguments depends on the variable
  5201. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5202. So for American calendars, give this as MONTH DAY YEAR, for European as
  5203. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5204. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5205. is any number of ISO weeks in the block period for which the item should
  5206. be skipped.
  5207. This function is here only for backward compatibility and it is deprecated,
  5208. please use `org-class' instead."
  5209. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5210. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5211. (org-class
  5212. (nth 2 date1) (car date1) (nth 1 date1)
  5213. (nth 2 date2) (car date2) (nth 1 date2)
  5214. dayname skip-weeks)))
  5215. (make-obsolete 'org-diary-class 'org-class "")
  5216. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5217. (defalias 'org-get-closed 'org-agenda-get-progress)
  5218. (defun org-agenda-get-progress ()
  5219. "Return the logged TODO entries for agenda display."
  5220. (let* ((props (list 'mouse-face 'highlight
  5221. 'org-not-done-regexp org-not-done-regexp
  5222. 'org-todo-regexp org-todo-regexp
  5223. 'org-complex-heading-regexp org-complex-heading-regexp
  5224. 'help-echo
  5225. (format "mouse-2 or RET jump to org file %s"
  5226. (abbreviate-file-name buffer-file-name))))
  5227. (items (if (consp org-agenda-show-log-scoped)
  5228. org-agenda-show-log-scoped
  5229. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5230. '(clock)
  5231. org-agenda-log-mode-items)))
  5232. (parts
  5233. (delq nil
  5234. (list
  5235. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5236. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5237. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5238. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5239. (error "`org-agenda-log-mode-items' is empty")))
  5240. (regexp (concat
  5241. "\\(" parts-re "\\)"
  5242. " *\\["
  5243. (regexp-quote
  5244. (substring
  5245. (format-time-string
  5246. (car org-time-stamp-formats)
  5247. (apply 'encode-time ; DATE bound by calendar
  5248. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5249. 1 11))))
  5250. (org-agenda-search-headline-for-time nil)
  5251. marker hdmarker priority category category-pos level tags closedp
  5252. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5253. (goto-char (point-min))
  5254. (while (re-search-forward regexp nil t)
  5255. (catch :skip
  5256. (org-agenda-skip)
  5257. (setq marker (org-agenda-new-marker (match-beginning 0))
  5258. closedp (equal (match-string 1) org-closed-string)
  5259. statep (equal (string-to-char (match-string 1)) ?-)
  5260. clockp (not (or closedp statep))
  5261. state (and statep (match-string 2))
  5262. category (org-get-category (match-beginning 0))
  5263. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5264. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5265. (when (string-match "\\]" timestr)
  5266. ;; substring should only run to end of time stamp
  5267. (setq rest (substring timestr (match-end 0))
  5268. timestr (substring timestr 0 (match-end 0)))
  5269. (if (and (not closedp) (not statep)
  5270. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5271. rest))
  5272. (progn (setq timestr (concat (substring timestr 0 -1)
  5273. "-" (match-string 1 rest) "]"))
  5274. (setq clocked (match-string 2 rest)))
  5275. (setq clocked "-")))
  5276. (save-excursion
  5277. (setq extra
  5278. (cond
  5279. ((not org-agenda-log-mode-add-notes) nil)
  5280. (statep
  5281. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5282. (match-string 1)))
  5283. (clockp
  5284. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5285. (match-string 1)))))
  5286. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5287. (throw :skip nil)
  5288. (goto-char (match-beginning 0))
  5289. (setq hdmarker (org-agenda-new-marker)
  5290. inherited-tags
  5291. (or (eq org-agenda-show-inherited-tags 'always)
  5292. (and (listp org-agenda-show-inherited-tags)
  5293. (memq 'todo org-agenda-show-inherited-tags))
  5294. (and (eq org-agenda-show-inherited-tags t)
  5295. (or (eq org-agenda-use-tag-inheritance t)
  5296. (memq 'todo org-agenda-use-tag-inheritance))))
  5297. tags (org-get-tags-at nil (not inherited-tags))
  5298. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5299. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5300. (setq txt (match-string 1))
  5301. (when extra
  5302. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5303. (setq txt (concat (substring txt 0 (match-beginning 1))
  5304. " - " extra " " (match-string 2 txt)))
  5305. (setq txt (concat txt " - " extra))))
  5306. (setq txt (org-agenda-format-item
  5307. (cond
  5308. (closedp "Closed: ")
  5309. (statep (concat "State: (" state ")"))
  5310. (t (concat "Clocked: (" clocked ")")))
  5311. txt level category tags timestr)))
  5312. (setq priority 100000)
  5313. (org-add-props txt props
  5314. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5315. 'priority priority 'org-category category
  5316. 'org-category-position category-pos
  5317. 'level level
  5318. 'type "closed" 'date date
  5319. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5320. (push txt ee))
  5321. (goto-char (point-at-eol))))
  5322. (nreverse ee)))
  5323. (defun org-agenda-show-clocking-issues ()
  5324. "Add overlays, showing issues with clocking.
  5325. See also the user option `org-agenda-clock-consistency-checks'."
  5326. (interactive)
  5327. (let* ((org-time-clocksum-use-effort-durations nil)
  5328. (pl org-agenda-clock-consistency-checks)
  5329. (re (concat "^[ \t]*"
  5330. org-clock-string
  5331. "[ \t]+"
  5332. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5333. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5334. (tlstart 0.)
  5335. (tlend 0.)
  5336. (maxtime (org-hh:mm-string-to-minutes
  5337. (or (plist-get pl :max-duration) "24:00")))
  5338. (mintime (org-hh:mm-string-to-minutes
  5339. (or (plist-get pl :min-duration) 0)))
  5340. (maxgap (org-hh:mm-string-to-minutes
  5341. ;; default 30:00 means never complain
  5342. (or (plist-get pl :max-gap) "30:00")))
  5343. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5344. (plist-get pl :gap-ok-around)))
  5345. (def-face (or (plist-get pl :default-face)
  5346. '((:background "DarkRed") (:foreground "white"))))
  5347. issue face m te ts dt ov)
  5348. (goto-char (point-min))
  5349. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5350. (setq issue nil face def-face)
  5351. (catch 'next
  5352. (setq m (org-get-at-bol 'org-marker)
  5353. te nil ts nil)
  5354. (unless (and m (markerp m))
  5355. (setq issue "No valid clock line") (throw 'next t))
  5356. (org-with-point-at m
  5357. (save-excursion
  5358. (goto-char (point-at-bol))
  5359. (unless (looking-at re)
  5360. (error "No valid Clock line")
  5361. (throw 'next t))
  5362. (unless (match-end 3)
  5363. (setq issue "No end time"
  5364. face (or (plist-get pl :no-end-time-face) face))
  5365. (throw 'next t))
  5366. (setq ts (match-string 1)
  5367. te (match-string 3)
  5368. ts (org-float-time
  5369. (apply 'encode-time (org-parse-time-string ts)))
  5370. te (org-float-time
  5371. (apply 'encode-time (org-parse-time-string te)))
  5372. dt (- te ts))))
  5373. (cond
  5374. ((> dt (* 60 maxtime))
  5375. ;; a very long clocking chunk
  5376. (setq issue (format "Clocking interval is very long: %s"
  5377. (org-minutes-to-clocksum-string
  5378. (floor (/ (float dt) 60.))))
  5379. face (or (plist-get pl :long-face) face)))
  5380. ((< dt (* 60 mintime))
  5381. ;; a very short clocking chunk
  5382. (setq issue (format "Clocking interval is very short: %s"
  5383. (org-minutes-to-clocksum-string
  5384. (floor (/ (float dt) 60.))))
  5385. face (or (plist-get pl :short-face) face)))
  5386. ((and (> tlend 0) (< ts tlend))
  5387. ;; Two clock entries are overlapping
  5388. (setq issue (format "Clocking overlap: %d minutes"
  5389. (/ (- tlend ts) 60))
  5390. face (or (plist-get pl :overlap-face) face)))
  5391. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5392. ;; There is a gap, lets see if we need to report it
  5393. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5394. (setq issue (format "Clocking gap: %d minutes"
  5395. (/ (- ts tlend) 60))
  5396. face (or (plist-get pl :gap-face) face))))
  5397. (t nil)))
  5398. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5399. (when issue
  5400. ;; OK, there was some issue, add an overlay to show the issue
  5401. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5402. (overlay-put ov 'before-string
  5403. (concat
  5404. (org-add-props
  5405. (format "%-43s" (concat " " issue))
  5406. nil
  5407. 'face face)
  5408. "\n"))
  5409. (overlay-put ov 'evaporate t)))))
  5410. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5411. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5412. (catch 'exit
  5413. (unless ok-list
  5414. ;; there are no OK times for gaps...
  5415. (throw 'exit nil))
  5416. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5417. ;; This is more than 24 hours, so it is OK.
  5418. ;; because we have at least one OK time, that must be in the
  5419. ;; 24 hour interval.
  5420. (throw 'exit t))
  5421. ;; We have a shorter gap.
  5422. ;; Now we have to get the minute of the day when these times are
  5423. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5424. (t2dec (decode-time (seconds-to-time t2)))
  5425. ;; compute the minute on the day
  5426. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5427. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5428. (when (< min2 min1)
  5429. ;; if min2 is smaller than min1, this means it is on the next day.
  5430. ;; Wrap it to after midnight.
  5431. (setq min2 (+ min2 1440)))
  5432. ;; Now check if any of the OK times is in the gap
  5433. (mapc (lambda (x)
  5434. ;; Wrap the time to after midnight if necessary
  5435. (if (< x min1) (setq x (+ x 1440)))
  5436. ;; Check if in interval
  5437. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5438. ok-list)
  5439. ;; Nope, this gap is not OK
  5440. nil)))
  5441. (defun org-agenda-get-deadlines ()
  5442. "Return the deadline information for agenda display."
  5443. (let* ((props (list 'mouse-face 'highlight
  5444. 'org-not-done-regexp org-not-done-regexp
  5445. 'org-todo-regexp org-todo-regexp
  5446. 'org-complex-heading-regexp org-complex-heading-regexp
  5447. 'help-echo
  5448. (format "mouse-2 or RET jump to org file %s"
  5449. (abbreviate-file-name buffer-file-name))))
  5450. (regexp org-deadline-time-regexp)
  5451. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5452. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5453. (dl0 (car org-agenda-deadline-leaders))
  5454. (dl1 (nth 1 org-agenda-deadline-leaders))
  5455. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5456. d2 diff dfrac wdays pos pos1 category category-pos level
  5457. tags suppress-prewarning ee txt head face s todo-state
  5458. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5459. (goto-char (point-min))
  5460. (while (re-search-forward regexp nil t)
  5461. (catch :skip
  5462. (org-agenda-skip)
  5463. (setq s (match-string 1)
  5464. txt nil
  5465. pos (1- (match-beginning 1))
  5466. todo-state (save-match-data (org-get-todo-state))
  5467. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5468. (member todo-state
  5469. org-agenda-repeating-timestamp-show-all))
  5470. d2 (org-time-string-to-absolute
  5471. s d1 'past show-all (current-buffer) pos)
  5472. diff (- d2 d1))
  5473. (setq suppress-prewarning
  5474. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5475. (let ((item (buffer-substring (point-at-bol)
  5476. (point-at-eol))))
  5477. (save-match-data
  5478. (and (string-match
  5479. org-scheduled-time-regexp item)
  5480. (match-string 1 item)))))))
  5481. (cond
  5482. ((not ds) nil)
  5483. ;; The current item has a scheduled date (in ds), so
  5484. ;; evaluate its prewarning lead time.
  5485. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5486. ;; Use global prewarning-restart lead time.
  5487. org-agenda-skip-deadline-prewarning-if-scheduled)
  5488. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5489. 'pre-scheduled)
  5490. ;; Set prewarning to no earlier than scheduled.
  5491. (min (- d2 (org-time-string-to-absolute
  5492. ds d1 'past show-all (current-buffer) pos))
  5493. org-deadline-warning-days))
  5494. ;; Set prewarning to deadline.
  5495. (t 0))))
  5496. (setq wdays (if suppress-prewarning
  5497. (let ((org-deadline-warning-days suppress-prewarning))
  5498. (org-get-wdays s))
  5499. (org-get-wdays s))
  5500. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5501. upcomingp (and todayp (> diff 0)))
  5502. ;; When to show a deadline in the calendar:
  5503. ;; If the expiration is within wdays warning time.
  5504. ;; Past-due deadlines are only shown on the current date
  5505. (if (and (or (and (<= diff wdays)
  5506. (and todayp (not org-agenda-only-exact-dates)))
  5507. (= diff 0)))
  5508. (save-excursion
  5509. ;; (setq todo-state (org-get-todo-state))
  5510. (setq donep (member todo-state org-done-keywords))
  5511. (if (and donep
  5512. (or org-agenda-skip-deadline-if-done
  5513. (not (= diff 0))))
  5514. (setq txt nil)
  5515. (setq category (org-get-category)
  5516. warntime (get-text-property (point) 'org-appt-warntime)
  5517. category-pos (get-text-property (point) 'org-category-position))
  5518. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5519. (throw :skip nil)
  5520. (goto-char (match-end 0))
  5521. (setq pos1 (match-beginning 0))
  5522. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5523. (setq inherited-tags
  5524. (or (eq org-agenda-show-inherited-tags 'always)
  5525. (and (listp org-agenda-show-inherited-tags)
  5526. (memq 'agenda org-agenda-show-inherited-tags))
  5527. (and (eq org-agenda-show-inherited-tags t)
  5528. (or (eq org-agenda-use-tag-inheritance t)
  5529. (memq 'agenda org-agenda-use-tag-inheritance))))
  5530. tags (org-get-tags-at pos1 (not inherited-tags)))
  5531. (setq head (buffer-substring
  5532. (point)
  5533. (progn (skip-chars-forward "^\r\n")
  5534. (point))))
  5535. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5536. (setq timestr
  5537. (concat (substring s (match-beginning 1)) " "))
  5538. (setq timestr 'time))
  5539. (setq txt (org-agenda-format-item
  5540. (cond ((= diff 0) dl0)
  5541. ((> diff 0)
  5542. (if (functionp dl1)
  5543. (funcall dl1 diff date)
  5544. (format dl1 diff)))
  5545. (t
  5546. (if (functionp dl2)
  5547. (funcall dl2 diff date)
  5548. (format dl2 (if (string= dl2 dl1)
  5549. diff (abs diff))))))
  5550. head level category tags
  5551. (if (not (= diff 0)) nil timestr)))))
  5552. (when txt
  5553. (setq face (org-agenda-deadline-face dfrac))
  5554. (org-add-props txt props
  5555. 'org-marker (org-agenda-new-marker pos)
  5556. 'warntime warntime
  5557. 'level level
  5558. 'ts-date d2
  5559. 'org-hd-marker (org-agenda-new-marker pos1)
  5560. 'priority (+ (- diff)
  5561. (org-get-priority txt))
  5562. 'org-category category
  5563. 'org-category-position category-pos
  5564. 'todo-state todo-state
  5565. 'type (if upcomingp "upcoming-deadline" "deadline")
  5566. 'date (if upcomingp date d2)
  5567. 'face (if donep 'org-agenda-done face)
  5568. 'undone-face face 'done-face 'org-agenda-done)
  5569. (push txt ee))))))
  5570. (nreverse ee)))
  5571. (defun org-agenda-deadline-face (fraction)
  5572. "Return the face to displaying a deadline item.
  5573. FRACTION is what fraction of the head-warning time has passed."
  5574. (let ((faces org-agenda-deadline-faces) f)
  5575. (catch 'exit
  5576. (while (setq f (pop faces))
  5577. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5578. (defun org-agenda-get-scheduled (&optional deadline-results)
  5579. "Return the scheduled information for agenda display."
  5580. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5581. 'org-todo-regexp org-todo-regexp
  5582. 'org-complex-heading-regexp org-complex-heading-regexp
  5583. 'done-face 'org-agenda-done
  5584. 'mouse-face 'highlight
  5585. 'help-echo
  5586. (format "mouse-2 or RET jump to org file %s"
  5587. (abbreviate-file-name buffer-file-name))))
  5588. (regexp org-scheduled-time-regexp)
  5589. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5590. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5591. mm
  5592. (deadline-position-alist
  5593. (mapcar (lambda (a) (and (setq mm (get-text-property
  5594. 0 'org-hd-marker a))
  5595. (cons (marker-position mm) a)))
  5596. deadline-results))
  5597. d2 diff pos pos1 category category-pos level tags donep
  5598. ee txt head pastschedp todo-state face timestr s habitp show-all
  5599. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5600. ddays)
  5601. (goto-char (point-min))
  5602. (while (re-search-forward regexp nil t)
  5603. (catch :skip
  5604. (org-agenda-skip)
  5605. (setq s (match-string 1)
  5606. txt nil
  5607. pos (1- (match-beginning 1))
  5608. todo-state (save-match-data (org-get-todo-state))
  5609. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5610. (member todo-state
  5611. org-agenda-repeating-timestamp-show-all))
  5612. d2 (org-time-string-to-absolute
  5613. s d1 'past show-all (current-buffer) pos)
  5614. diff (- d2 d1)
  5615. warntime (get-text-property (point) 'org-appt-warntime))
  5616. (setq pastschedp (and todayp (< diff 0)))
  5617. (setq did-habit-check-p nil)
  5618. (setq suppress-delay
  5619. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5620. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5621. (save-match-data
  5622. (and (string-match
  5623. org-deadline-time-regexp item)
  5624. (match-string 1 item)))))))
  5625. (cond
  5626. ((not ds) nil)
  5627. ;; The current item has a deadline date (in ds), so
  5628. ;; evaluate its delay time.
  5629. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5630. ;; Use global delay time.
  5631. (- org-agenda-skip-scheduled-delay-if-deadline))
  5632. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5633. 'post-deadline)
  5634. ;; Set delay to no later than deadline.
  5635. (min (- d2 (org-time-string-to-absolute
  5636. ds d1 'past show-all (current-buffer) pos))
  5637. org-scheduled-delay-days))
  5638. (t 0))))
  5639. (setq ddays (if suppress-delay
  5640. (let ((org-scheduled-delay-days suppress-delay))
  5641. (org-get-wdays s t t))
  5642. (org-get-wdays s t)))
  5643. ;; Use a delay of 0 when there is a repeater and the delay is
  5644. ;; of the form --3d
  5645. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5646. (< (org-time-string-to-absolute s)
  5647. (org-time-string-to-absolute
  5648. s d2 'past nil (current-buffer) pos)))
  5649. (setq ddays 0))
  5650. ;; When to show a scheduled item in the calendar:
  5651. ;; If it is on or past the date.
  5652. (when (or (and (> ddays 0) (= diff (- ddays)))
  5653. (and (zerop ddays) (= diff 0))
  5654. (and (< (+ diff ddays) 0)
  5655. (< (abs diff) org-scheduled-past-days)
  5656. (and todayp (not org-agenda-only-exact-dates)))
  5657. ;; org-is-habit-p uses org-entry-get, which is expansive
  5658. ;; so we go extra mile to only call it once
  5659. (and todayp
  5660. (boundp 'org-habit-show-all-today)
  5661. org-habit-show-all-today
  5662. (setq did-habit-check-p t)
  5663. (setq habitp (and (functionp 'org-is-habit-p)
  5664. (org-is-habit-p)))))
  5665. (save-excursion
  5666. (setq donep (member todo-state org-done-keywords))
  5667. (if (and donep
  5668. (or org-agenda-skip-scheduled-if-done
  5669. (not (= diff 0))
  5670. (and (functionp 'org-is-habit-p)
  5671. (org-is-habit-p))))
  5672. (setq txt nil)
  5673. (setq habitp (if did-habit-check-p habitp
  5674. (and (functionp 'org-is-habit-p)
  5675. (org-is-habit-p))))
  5676. (setq category (org-get-category)
  5677. category-pos (get-text-property (point) 'org-category-position))
  5678. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5679. (throw :skip nil)
  5680. (goto-char (match-end 0))
  5681. (setq pos1 (match-beginning 0))
  5682. (if habitp
  5683. (if (or (not org-habit-show-habits)
  5684. (and (not todayp)
  5685. (boundp 'org-habit-show-habits-only-for-today)
  5686. org-habit-show-habits-only-for-today))
  5687. (throw :skip nil))
  5688. (if (and
  5689. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5690. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5691. pastschedp))
  5692. (setq mm (assoc pos1 deadline-position-alist)))
  5693. (throw :skip nil)))
  5694. (setq inherited-tags
  5695. (or (eq org-agenda-show-inherited-tags 'always)
  5696. (and (listp org-agenda-show-inherited-tags)
  5697. (memq 'agenda org-agenda-show-inherited-tags))
  5698. (and (eq org-agenda-show-inherited-tags t)
  5699. (or (eq org-agenda-use-tag-inheritance t)
  5700. (memq 'agenda org-agenda-use-tag-inheritance))))
  5701. tags (org-get-tags-at nil (not inherited-tags)))
  5702. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5703. (setq head (buffer-substring
  5704. (point)
  5705. (progn (skip-chars-forward "^\r\n") (point))))
  5706. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5707. (setq timestr
  5708. (concat (substring s (match-beginning 1)) " "))
  5709. (setq timestr 'time))
  5710. (setq txt (org-agenda-format-item
  5711. (if (= diff 0)
  5712. (car org-agenda-scheduled-leaders)
  5713. (format (nth 1 org-agenda-scheduled-leaders)
  5714. (- 1 diff)))
  5715. head level category tags
  5716. (if (not (= diff 0)) nil timestr)
  5717. nil habitp))))
  5718. (when txt
  5719. (setq face
  5720. (cond
  5721. ((and (not habitp) pastschedp)
  5722. 'org-scheduled-previously)
  5723. (todayp 'org-scheduled-today)
  5724. (t 'org-scheduled))
  5725. habitp (and habitp (org-habit-parse-todo)))
  5726. (org-add-props txt props
  5727. 'undone-face face
  5728. 'face (if donep 'org-agenda-done face)
  5729. 'org-marker (org-agenda-new-marker pos)
  5730. 'org-hd-marker (org-agenda-new-marker pos1)
  5731. 'type (if pastschedp "past-scheduled" "scheduled")
  5732. 'date (if pastschedp d2 date)
  5733. 'ts-date d2
  5734. 'warntime warntime
  5735. 'level level
  5736. 'priority (if habitp
  5737. (org-habit-get-priority habitp)
  5738. (+ 94 (- 5 diff) (org-get-priority txt)))
  5739. 'org-category category
  5740. 'category-position category-pos
  5741. 'org-habit-p habitp
  5742. 'todo-state todo-state)
  5743. (push txt ee))))))
  5744. (nreverse ee)))
  5745. (defun org-agenda-get-blocks ()
  5746. "Return the date-range information for agenda display."
  5747. (let* ((props (list 'face nil
  5748. 'org-not-done-regexp org-not-done-regexp
  5749. 'org-todo-regexp org-todo-regexp
  5750. 'org-complex-heading-regexp org-complex-heading-regexp
  5751. 'mouse-face 'highlight
  5752. 'help-echo
  5753. (format "mouse-2 or RET jump to org file %s"
  5754. (abbreviate-file-name buffer-file-name))))
  5755. (regexp org-tr-regexp)
  5756. (d0 (calendar-absolute-from-gregorian date))
  5757. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5758. level todo-state tags pos head donep inherited-tags)
  5759. (goto-char (point-min))
  5760. (while (re-search-forward regexp nil t)
  5761. (catch :skip
  5762. (org-agenda-skip)
  5763. (setq pos (point))
  5764. (let ((start-time (match-string 1))
  5765. (end-time (match-string 2)))
  5766. (setq s1 (match-string 1)
  5767. s2 (match-string 2)
  5768. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5769. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5770. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5771. ;; Only allow days between the limits, because the normal
  5772. ;; date stamps will catch the limits.
  5773. (save-excursion
  5774. (setq todo-state (org-get-todo-state))
  5775. (setq donep (member todo-state org-done-keywords))
  5776. (if (and donep org-agenda-skip-timestamp-if-done)
  5777. (throw :skip t))
  5778. (setq marker (org-agenda-new-marker (point)))
  5779. (setq category (org-get-category)
  5780. category-pos (get-text-property (point) 'org-category-position))
  5781. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5782. (throw :skip nil)
  5783. (goto-char (match-beginning 0))
  5784. (setq hdmarker (org-agenda-new-marker (point))
  5785. inherited-tags
  5786. (or (eq org-agenda-show-inherited-tags 'always)
  5787. (and (listp org-agenda-show-inherited-tags)
  5788. (memq 'agenda org-agenda-show-inherited-tags))
  5789. (and (eq org-agenda-show-inherited-tags t)
  5790. (or (eq org-agenda-use-tag-inheritance t)
  5791. (memq 'agenda org-agenda-use-tag-inheritance))))
  5792. tags (org-get-tags-at nil (not inherited-tags)))
  5793. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5794. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5795. (setq head (match-string 1))
  5796. (let ((remove-re
  5797. (if org-agenda-remove-timeranges-from-blocks
  5798. (concat
  5799. "<" (regexp-quote s1) ".*?>"
  5800. "--"
  5801. "<" (regexp-quote s2) ".*?>")
  5802. nil)))
  5803. (setq txt (org-agenda-format-item
  5804. (format
  5805. (nth (if (= d1 d2) 0 1)
  5806. org-agenda-timerange-leaders)
  5807. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5808. head level category tags
  5809. (cond ((and (= d1 d0) (= d2 d0))
  5810. (concat "<" start-time ">--<" end-time ">"))
  5811. ((= d1 d0)
  5812. (concat "<" start-time ">"))
  5813. ((= d2 d0)
  5814. (concat "<" end-time ">")))
  5815. remove-re))))
  5816. (org-add-props txt props
  5817. 'org-marker marker 'org-hd-marker hdmarker
  5818. 'type "block" 'date date
  5819. 'level level
  5820. 'todo-state todo-state
  5821. 'priority (org-get-priority txt) 'org-category category
  5822. 'org-category-position category-pos)
  5823. (push txt ee))))
  5824. (goto-char pos)))
  5825. ;; Sort the entries by expiration date.
  5826. (nreverse ee)))
  5827. ;;; Agenda presentation and sorting
  5828. (defvar org-prefix-has-time nil
  5829. "A flag, set by `org-compile-prefix-format'.
  5830. The flag is set if the currently compiled format contains a `%t'.")
  5831. (defvar org-prefix-has-tag nil
  5832. "A flag, set by `org-compile-prefix-format'.
  5833. The flag is set if the currently compiled format contains a `%T'.")
  5834. (defvar org-prefix-has-effort nil
  5835. "A flag, set by `org-compile-prefix-format'.
  5836. The flag is set if the currently compiled format contains a `%e'.")
  5837. (defvar org-prefix-has-breadcrumbs nil
  5838. "A flag, set by `org-compile-prefix-format'.
  5839. The flag is set if the currently compiled format contains a `%b'.")
  5840. (defvar org-prefix-category-length nil
  5841. "Used by `org-compile-prefix-format' to remember the category field width.")
  5842. (defvar org-prefix-category-max-length nil
  5843. "Used by `org-compile-prefix-format' to remember the category field width.")
  5844. (defun org-agenda-get-category-icon (category)
  5845. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5846. (dolist (entry org-agenda-category-icon-alist)
  5847. (when (org-string-match-p (car entry) category)
  5848. (if (listp (cadr entry))
  5849. (return (cadr entry))
  5850. (return (apply 'create-image (cdr entry)))))))
  5851. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5852. remove-re habitp)
  5853. "Format TXT to be inserted into the agenda buffer.
  5854. In particular, add the prefix and corresponding text properties.
  5855. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5856. LEVEL may be a string to replace the `%l' specifier.
  5857. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5858. category taken from local variable or file name. It will replace the `%c'
  5859. specifier in the format.
  5860. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5861. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5862. When DOTIME is a string, this string is searched for a time before TXT is.
  5863. TAGS can be the tags of the headline.
  5864. Any match of REMOVE-RE will be removed from TXT."
  5865. ;; We keep the org-prefix-* variable values along with a compiled
  5866. ;; formatter, so that multiple agendas existing at the same time do
  5867. ;; not step on each other toes.
  5868. ;;
  5869. ;; It was inconvenient to make these variables buffer local in
  5870. ;; Agenda buffers, because this function expects to be called with
  5871. ;; the buffer where item comes from being current, and not agenda
  5872. ;; buffer
  5873. (let* ((bindings (car org-prefix-format-compiled))
  5874. (formatter (cadr org-prefix-format-compiled)))
  5875. (loop for (var value) in bindings
  5876. do (set var value))
  5877. (save-match-data
  5878. ;; Diary entries sometimes have extra whitespace at the beginning
  5879. (setq txt (org-trim txt))
  5880. ;; Fix the tags part in txt
  5881. (setq txt (org-agenda-fix-displayed-tags
  5882. txt tags
  5883. org-agenda-show-inherited-tags
  5884. org-agenda-hide-tags-regexp))
  5885. (let* ((category (or category
  5886. (if (stringp org-category)
  5887. org-category
  5888. (and org-category (symbol-name org-category)))
  5889. (if buffer-file-name
  5890. (file-name-sans-extension
  5891. (file-name-nondirectory buffer-file-name))
  5892. "")))
  5893. (category-icon (org-agenda-get-category-icon category))
  5894. (category-icon (if category-icon
  5895. (propertize " " 'display category-icon)
  5896. ""))
  5897. ;; time, tag, effort are needed for the eval of the prefix format
  5898. (tag (if tags (nth (1- (length tags)) tags) ""))
  5899. time effort neffort
  5900. (ts (if dotime (concat
  5901. (if (stringp dotime) dotime "")
  5902. (and org-agenda-search-headline-for-time txt))))
  5903. (time-of-day (and dotime (org-get-time-of-day ts)))
  5904. stamp plain s0 s1 s2 rtn srp l
  5905. duration thecategory breadcrumbs)
  5906. (and (derived-mode-p 'org-mode) buffer-file-name
  5907. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5908. (when (and dotime time-of-day)
  5909. ;; Extract starting and ending time and move them to prefix
  5910. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5911. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5912. (setq s0 (match-string 0 ts)
  5913. srp (and stamp (match-end 3))
  5914. s1 (match-string (if plain 1 2) ts)
  5915. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5916. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5917. ;; them, we might want to remove them there to avoid duplication.
  5918. ;; The user can turn this off with a variable.
  5919. (if (and org-prefix-has-time
  5920. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5921. (string-match (concat (regexp-quote s0) " *") txt)
  5922. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5923. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5924. (= (match-beginning 0) 0)
  5925. t))
  5926. (setq txt (replace-match "" nil nil txt))))
  5927. ;; Normalize the time(s) to 24 hour
  5928. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5929. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5930. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5931. (let (org-time-clocksum-use-effort-durations)
  5932. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5933. (setq s2
  5934. (org-minutes-to-clocksum-string
  5935. (+ (org-hh:mm-string-to-minutes s1)
  5936. org-agenda-default-appointment-duration)))))
  5937. ;; Compute the duration
  5938. (when s2
  5939. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5940. (org-hh:mm-string-to-minutes s1)))))
  5941. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5942. txt)
  5943. ;; Tags are in the string
  5944. (if (or (eq org-agenda-remove-tags t)
  5945. (and org-agenda-remove-tags
  5946. org-prefix-has-tag))
  5947. (setq txt (replace-match "" t t txt))
  5948. (setq txt (replace-match
  5949. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5950. (match-string 2 txt))
  5951. t t txt))))
  5952. (when (derived-mode-p 'org-mode)
  5953. (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
  5954. (if effort
  5955. (setq neffort (org-duration-string-to-minutes effort)
  5956. effort (setq effort (concat "[" effort "]")))
  5957. ;; prevent erroring out with %e format when there is no effort
  5958. (setq effort "")))
  5959. (when remove-re
  5960. (while (string-match remove-re txt)
  5961. (setq txt (replace-match "" t t txt))))
  5962. ;; Set org-heading property on `txt' to mark the start of the
  5963. ;; heading.
  5964. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5965. ;; Prepare the variables needed in the eval of the compiled format
  5966. (if org-prefix-has-breadcrumbs
  5967. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  5968. (let ((s (org-display-outline-path nil nil "->" t)))
  5969. (if (eq "" s) "" (concat s "->"))))))
  5970. (setq time (cond (s2 (concat
  5971. (org-agenda-time-of-day-to-ampm-maybe s1)
  5972. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5973. (if org-agenda-timegrid-use-ampm " ")))
  5974. (s1 (concat
  5975. (org-agenda-time-of-day-to-ampm-maybe s1)
  5976. (if org-agenda-timegrid-use-ampm
  5977. "........ "
  5978. "......")))
  5979. (t ""))
  5980. extra (or (and (not habitp) extra) "")
  5981. category (if (symbolp category) (symbol-name category) category)
  5982. thecategory (copy-sequence category)
  5983. level (or level ""))
  5984. (if (string-match org-bracket-link-regexp category)
  5985. (progn
  5986. (setq l (if (match-end 3)
  5987. (- (match-end 3) (match-beginning 3))
  5988. (- (match-end 1) (match-beginning 1))))
  5989. (when (< l (or org-prefix-category-length 0))
  5990. (setq category (copy-sequence category))
  5991. (org-add-props category nil
  5992. 'extra-space (make-string
  5993. (- org-prefix-category-length l 1) ?\ ))))
  5994. (if (and org-prefix-category-max-length
  5995. (>= (length category) org-prefix-category-max-length))
  5996. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5997. ;; Evaluate the compiled format
  5998. (setq rtn (concat (eval formatter) txt))
  5999. ;; And finally add the text properties
  6000. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6001. (org-add-props rtn nil
  6002. 'org-category (if thecategory (downcase thecategory) category)
  6003. 'tags (mapcar 'org-downcase-keep-props tags)
  6004. 'org-highest-priority org-highest-priority
  6005. 'org-lowest-priority org-lowest-priority
  6006. 'time-of-day time-of-day
  6007. 'duration duration
  6008. 'effort effort
  6009. 'effort-minutes neffort
  6010. 'breadcrumbs breadcrumbs
  6011. 'txt txt
  6012. 'level level
  6013. 'time time
  6014. 'extra extra
  6015. 'format org-prefix-format-compiled
  6016. 'dotime dotime)))))
  6017. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6018. "Remove tags string from TXT, and add a modified list of tags.
  6019. The modified list may contain inherited tags, and tags matched by
  6020. `org-agenda-hide-tags-regexp' will be removed."
  6021. (when (or add-inherited hide-re)
  6022. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6023. (setq txt (substring txt 0 (match-beginning 0))))
  6024. (setq tags
  6025. (delq nil
  6026. (mapcar (lambda (tg)
  6027. (if (or (and hide-re (string-match hide-re tg))
  6028. (and (not add-inherited)
  6029. (get-text-property 0 'inherited tg)))
  6030. nil
  6031. tg))
  6032. tags)))
  6033. (when tags
  6034. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6035. i)
  6036. (setq txt (concat txt " :"
  6037. (mapconcat
  6038. (lambda (x)
  6039. (setq i (get-text-property 0 'inherited x))
  6040. (if (and have-i (not i))
  6041. (progn
  6042. (setq have-i nil)
  6043. (concat ":" x))
  6044. x))
  6045. tags ":")
  6046. (if have-i "::" ":"))))))
  6047. txt)
  6048. (defun org-downcase-keep-props (s)
  6049. (let ((props (text-properties-at 0 s)))
  6050. (setq s (downcase s))
  6051. (add-text-properties 0 (length s) props s)
  6052. s))
  6053. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6054. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6055. "Add a time-grid for agenda items which need it.
  6056. LIST is the list of agenda items formatted by `org-agenda-list'.
  6057. NDAYS is the span of the current agenda view.
  6058. TODAYP is `t' when the current agenda view is on today."
  6059. (catch 'exit
  6060. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6061. ((and todayp (member 'today (car org-agenda-time-grid))))
  6062. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6063. ((member 'weekly (car org-agenda-time-grid)))
  6064. (t (throw 'exit list)))
  6065. (let* ((have (delq nil (mapcar
  6066. (lambda (x) (get-text-property 1 'time-of-day x))
  6067. list)))
  6068. (string (nth 1 org-agenda-time-grid))
  6069. (gridtimes (nth 2 org-agenda-time-grid))
  6070. (req (car org-agenda-time-grid))
  6071. (remove (member 'remove-match req))
  6072. new time)
  6073. (if (and (member 'require-timed req) (not have))
  6074. ;; don't show empty grid
  6075. (throw 'exit list))
  6076. (while (setq time (pop gridtimes))
  6077. (unless (and remove (member time have))
  6078. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6079. (push (org-agenda-format-item
  6080. nil string nil "" nil
  6081. (concat (substring time 0 -2) ":" (substring time -2)))
  6082. new)
  6083. (put-text-property
  6084. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6085. (when (and todayp org-agenda-show-current-time-in-grid)
  6086. (push (org-agenda-format-item
  6087. nil org-agenda-current-time-string nil "" nil
  6088. (format-time-string "%H:%M "))
  6089. new)
  6090. (put-text-property
  6091. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6092. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6093. (append new list)
  6094. (append list new)))))
  6095. (defun org-compile-prefix-format (key)
  6096. "Compile the prefix format into a Lisp form that can be evaluated.
  6097. The resulting form and associated variable bindings is returned
  6098. and stored in the variable `org-prefix-format-compiled'."
  6099. (setq org-prefix-has-time nil
  6100. org-prefix-has-tag nil
  6101. org-prefix-category-length nil
  6102. org-prefix-has-effort nil
  6103. org-prefix-has-breadcrumbs nil)
  6104. (let ((s (cond
  6105. ((stringp org-agenda-prefix-format)
  6106. org-agenda-prefix-format)
  6107. ((assq key org-agenda-prefix-format)
  6108. (cdr (assq key org-agenda-prefix-format)))
  6109. (t " %-12:c%?-12t% s")))
  6110. (start 0)
  6111. varform vars var e c f opt)
  6112. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6113. s start)
  6114. (setq var (or (cdr (assoc (match-string 4 s)
  6115. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6116. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6117. 'eval)
  6118. c (or (match-string 3 s) "")
  6119. opt (match-beginning 1)
  6120. start (1+ (match-beginning 0)))
  6121. (if (equal var 'time) (setq org-prefix-has-time t))
  6122. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6123. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6124. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6125. (setq f (concat "%" (match-string 2 s) "s"))
  6126. (when (equal var 'category)
  6127. (setq org-prefix-category-length
  6128. (floor (abs (string-to-number (match-string 2 s)))))
  6129. (setq org-prefix-category-max-length
  6130. (let ((x (match-string 2 s)))
  6131. (save-match-data
  6132. (if (string-match "\\.[0-9]+" x)
  6133. (string-to-number (substring (match-string 0 x) 1)))))))
  6134. (if (eq var 'eval)
  6135. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6136. (if opt
  6137. (setq varform
  6138. `(if (equal "" ,var)
  6139. ""
  6140. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6141. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6142. (setq s (replace-match "%s" t nil s))
  6143. (push varform vars))
  6144. (setq vars (nreverse vars))
  6145. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6146. (setq org-prefix-format-compiled
  6147. (list
  6148. `((org-prefix-has-time ,org-prefix-has-time)
  6149. (org-prefix-has-tag ,org-prefix-has-tag)
  6150. (org-prefix-category-length ,org-prefix-category-length)
  6151. (org-prefix-has-effort ,org-prefix-has-effort)
  6152. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6153. `(format ,s ,@vars))))))
  6154. (defun org-set-sorting-strategy (key)
  6155. (if (symbolp (car org-agenda-sorting-strategy))
  6156. ;; the old format
  6157. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6158. (setq org-agenda-sorting-strategy-selected
  6159. (or (cdr (assq key org-agenda-sorting-strategy))
  6160. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6161. '(time-up category-keep priority-down)))))
  6162. (defun org-get-time-of-day (s &optional string mod24)
  6163. "Check string S for a time of day.
  6164. If found, return it as a military time number between 0 and 2400.
  6165. If not found, return nil.
  6166. The optional STRING argument forces conversion into a 5 character wide string
  6167. HH:MM."
  6168. (save-match-data
  6169. (when
  6170. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6171. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6172. (let* ((h (string-to-number (match-string 1 s)))
  6173. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6174. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6175. (am-p (equal ampm "am"))
  6176. (h1 (cond ((not ampm) h)
  6177. ((= h 12) (if am-p 0 12))
  6178. (t (+ h (if am-p 0 12)))))
  6179. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6180. (mod h1 24) h1))
  6181. (t0 (+ (* 100 h2) m))
  6182. (t1 (concat (if (>= h1 24) "+" " ")
  6183. (if (and org-agenda-time-leading-zero
  6184. (< t0 1000)) "0" "")
  6185. (if (< t0 100) "0" "")
  6186. (if (< t0 10) "0" "")
  6187. (int-to-string t0))))
  6188. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6189. (defvar org-agenda-before-sorting-filter-function nil
  6190. "Function to be applied to agenda items prior to sorting.
  6191. Prior to sorting also means just before they are inserted into the agenda.
  6192. To aid sorting, you may revisit the original entries and add more text
  6193. properties which will later be used by the sorting functions.
  6194. The function should take a string argument, an agenda line.
  6195. It has access to the text properties in that line, which contain among
  6196. other things, the property `org-hd-marker' that points to the entry
  6197. where the line comes from. Note that not all lines going into the agenda
  6198. have this property, only most.
  6199. The function should return the modified string. It is probably best
  6200. to ONLY change text properties.
  6201. You can also use this function as a filter, by returning nil for lines
  6202. you don't want to have in the agenda at all. For this application, you
  6203. could bind the variable in the options section of a custom command.")
  6204. (defun org-agenda-finalize-entries (list &optional type)
  6205. "Sort, limit and concatenate the LIST of agenda items.
  6206. The optional argument TYPE tells the agenda type."
  6207. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6208. (cdr (assoc type org-agenda-max-effort)))
  6209. (t org-agenda-max-effort)))
  6210. (max-todo (cond ((listp org-agenda-max-todos)
  6211. (cdr (assoc type org-agenda-max-todos)))
  6212. (t org-agenda-max-todos)))
  6213. (max-tags (cond ((listp org-agenda-max-tags)
  6214. (cdr (assoc type org-agenda-max-tags)))
  6215. (t org-agenda-max-tags)))
  6216. (max-entries (cond ((listp org-agenda-max-entries)
  6217. (cdr (assoc type org-agenda-max-entries)))
  6218. (t org-agenda-max-entries))) l)
  6219. (when org-agenda-before-sorting-filter-function
  6220. (setq list
  6221. (delq nil
  6222. (mapcar
  6223. org-agenda-before-sorting-filter-function list))))
  6224. (setq list (mapcar 'org-agenda-highlight-todo list)
  6225. list (mapcar 'identity (sort list 'org-entries-lessp))
  6226. list (org-agenda-limit-entries
  6227. list 'effort-minutes max-effort 'identity)
  6228. list (org-agenda-limit-entries list 'todo-state max-todo)
  6229. list (org-agenda-limit-entries list 'tags max-tags)
  6230. list (org-agenda-limit-entries list 'org-hd-marker max-entries)
  6231. list (mapconcat 'identity list "\n"))))
  6232. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6233. "Limit the number of agenda entries."
  6234. (if limit
  6235. (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
  6236. (delq nil
  6237. (mapcar
  6238. (lambda (e)
  6239. (let ((pval (funcall f (get-text-property 1 prop e))))
  6240. (if pval (setq lim (+ lim pval)))
  6241. (if (or (not pval) (<= lim limit)) e)))
  6242. list)))
  6243. list))
  6244. (defun org-agenda-highlight-todo (x)
  6245. (let ((org-done-keywords org-done-keywords-for-agenda)
  6246. (case-fold-search nil)
  6247. re)
  6248. (if (eq x 'line)
  6249. (save-excursion
  6250. (beginning-of-line 1)
  6251. (setq re (org-get-at-bol 'org-todo-regexp))
  6252. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6253. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6254. (add-text-properties (match-beginning 0) (match-end 1)
  6255. (list 'face (org-get-todo-face 1)))
  6256. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6257. (delete-region (match-beginning 1) (1- (match-end 0)))
  6258. (goto-char (match-beginning 1))
  6259. (insert (format org-agenda-todo-keyword-format s)))))
  6260. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6261. (setq re (get-text-property 0 'org-todo-regexp x))
  6262. (when (and re
  6263. ;; Test `pl' because if there's no heading content,
  6264. ;; there's no point matching to highlight. Note
  6265. ;; that if we didn't test `pl' first, and there
  6266. ;; happened to be no keyword from `org-todo-regexp'
  6267. ;; on this heading line, then the `equal' comparison
  6268. ;; afterwards would spuriously succeed in the case
  6269. ;; where `pl' is nil -- causing an args-out-of-range
  6270. ;; error when we try to add text properties to text
  6271. ;; that isn't there.
  6272. pl
  6273. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6274. x pl) pl))
  6275. (add-text-properties
  6276. (or (match-end 1) (match-end 0)) (match-end 0)
  6277. (list 'face (org-get-todo-face (match-string 2 x)))
  6278. x)
  6279. (when (match-end 1)
  6280. (setq x (concat (substring x 0 (match-end 1))
  6281. (format org-agenda-todo-keyword-format
  6282. (match-string 2 x))
  6283. (org-add-props " " (text-properties-at 0 x))
  6284. (substring x (match-end 3)))))))
  6285. x)))
  6286. (defsubst org-cmp-priority (a b)
  6287. "Compare the priorities of string A and B."
  6288. (let ((pa (or (get-text-property 1 'priority a) 0))
  6289. (pb (or (get-text-property 1 'priority b) 0)))
  6290. (cond ((> pa pb) +1)
  6291. ((< pa pb) -1))))
  6292. (defsubst org-cmp-effort (a b)
  6293. "Compare the effort values of string A and B."
  6294. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6295. (ea (or (get-text-property 1 'effort-minutes a) def))
  6296. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6297. (cond ((> ea eb) +1)
  6298. ((< ea eb) -1))))
  6299. (defsubst org-cmp-category (a b)
  6300. "Compare the string values of categories of strings A and B."
  6301. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6302. (cb (or (get-text-property 1 'org-category b) "")))
  6303. (cond ((string-lessp ca cb) -1)
  6304. ((string-lessp cb ca) +1))))
  6305. (defsubst org-cmp-todo-state (a b)
  6306. "Compare the todo states of strings A and B."
  6307. (let* ((ma (or (get-text-property 1 'org-marker a)
  6308. (get-text-property 1 'org-hd-marker a)))
  6309. (mb (or (get-text-property 1 'org-marker b)
  6310. (get-text-property 1 'org-hd-marker b)))
  6311. (fa (and ma (marker-buffer ma)))
  6312. (fb (and mb (marker-buffer mb)))
  6313. (todo-kwds
  6314. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6315. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6316. (ta (or (get-text-property 1 'todo-state a) ""))
  6317. (tb (or (get-text-property 1 'todo-state b) ""))
  6318. (la (- (length (member ta todo-kwds))))
  6319. (lb (- (length (member tb todo-kwds))))
  6320. (donepa (member ta org-done-keywords-for-agenda))
  6321. (donepb (member tb org-done-keywords-for-agenda)))
  6322. (cond ((and donepa (not donepb)) -1)
  6323. ((and (not donepa) donepb) +1)
  6324. ((< la lb) -1)
  6325. ((< lb la) +1))))
  6326. (defsubst org-cmp-alpha (a b)
  6327. "Compare the headlines, alphabetically."
  6328. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6329. (plb (text-property-any 0 (length b) 'org-heading t b))
  6330. (ta (and pla (substring a pla)))
  6331. (tb (and plb (substring b plb))))
  6332. (when pla
  6333. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6334. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6335. (setq ta (substring ta (match-end 0))))
  6336. (setq ta (downcase ta)))
  6337. (when plb
  6338. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6339. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6340. (setq tb (substring tb (match-end 0))))
  6341. (setq tb (downcase tb)))
  6342. (cond ((not ta) +1)
  6343. ((not tb) -1)
  6344. ((string-lessp ta tb) -1)
  6345. ((string-lessp tb ta) +1))))
  6346. (defsubst org-cmp-tag (a b)
  6347. "Compare the string values of the first tags of A and B."
  6348. (let ((ta (car (last (get-text-property 1 'tags a))))
  6349. (tb (car (last (get-text-property 1 'tags b)))))
  6350. (cond ((not ta) +1)
  6351. ((not tb) -1)
  6352. ((string-lessp ta tb) -1)
  6353. ((string-lessp tb ta) +1))))
  6354. (defsubst org-cmp-time (a b)
  6355. "Compare the time-of-day values of strings A and B."
  6356. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6357. (ta (or (get-text-property 1 'time-of-day a) def))
  6358. (tb (or (get-text-property 1 'time-of-day b) def)))
  6359. (cond ((< ta tb) -1)
  6360. ((< tb ta) +1))))
  6361. (defsubst org-cmp-ts (a b &optional type)
  6362. "Compare the timestamps values of entries A and B.
  6363. When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
  6364. or \"timestamp_ia\", compare within each of these type.
  6365. When TYPE is the empty string, compare all timestamps
  6366. without respect of their type."
  6367. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6368. (ta (or (and (string-match type (get-text-property 1 'type a))
  6369. (get-text-property 1 'ts-date a)) def))
  6370. (tb (or (and (string-match type (get-text-property 1 'type b))
  6371. (get-text-property 1 'ts-date b)) def)))
  6372. (cond ((< ta tb) -1)
  6373. ((< tb ta) +1))))
  6374. (defsubst org-cmp-habit-p (a b)
  6375. "Compare the todo states of strings A and B."
  6376. (let ((ha (get-text-property 1 'org-habit-p a))
  6377. (hb (get-text-property 1 'org-habit-p b)))
  6378. (cond ((and ha (not hb)) -1)
  6379. ((and (not ha) hb) +1))))
  6380. (defun org-entries-lessp (a b)
  6381. "Predicate for sorting agenda entries."
  6382. ;; The following variables will be used when the form is evaluated.
  6383. ;; So even though the compiler complains, keep them.
  6384. (let* ((ss org-agenda-sorting-strategy-selected)
  6385. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6386. (org-cmp-ts a b "")))
  6387. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6388. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6389. (org-cmp-ts a b "scheduled")))
  6390. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6391. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6392. (org-cmp-ts a b "deadline")))
  6393. (deadline-down (if deadline-up (- deadline-up) nil))
  6394. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6395. (org-cmp-ts a b "iatimestamp_ia")))
  6396. (tsia-down (if tsia-up (- tsia-up) nil))
  6397. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6398. (org-cmp-ts a b "timestamp")))
  6399. (ts-down (if ts-up (- ts-up) nil))
  6400. (time-up (and (org-em 'time-up 'time-down ss)
  6401. (org-cmp-time a b)))
  6402. (time-down (if time-up (- time-up) nil))
  6403. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6404. (org-cmp-priority a b)))
  6405. (priority-down (if priority-up (- priority-up) nil))
  6406. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6407. (org-cmp-effort a b)))
  6408. (effort-down (if effort-up (- effort-up) nil))
  6409. (category-up (and (or (org-em 'category-up 'category-down ss)
  6410. (memq 'category-keep ss))
  6411. (org-cmp-category a b)))
  6412. (category-down (if category-up (- category-up) nil))
  6413. (category-keep (if category-up +1 nil))
  6414. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6415. (org-cmp-tag a b)))
  6416. (tag-down (if tag-up (- tag-up) nil))
  6417. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6418. (org-cmp-todo-state a b)))
  6419. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6420. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6421. (org-cmp-habit-p a b)))
  6422. (habit-down (if habit-up (- habit-up) nil))
  6423. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6424. (org-cmp-alpha a b)))
  6425. (alpha-down (if alpha-up (- alpha-up) nil))
  6426. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6427. user-defined-up user-defined-down)
  6428. (if (and need-user-cmp org-agenda-cmp-user-defined
  6429. (functionp org-agenda-cmp-user-defined))
  6430. (setq user-defined-up
  6431. (funcall org-agenda-cmp-user-defined a b)
  6432. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6433. (cdr (assoc
  6434. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6435. '((-1 . t) (1 . nil) (nil . nil))))))
  6436. ;;; Agenda restriction lock
  6437. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6438. "Overlay to mark the headline to which agenda commands are restricted.")
  6439. (overlay-put org-agenda-restriction-lock-overlay
  6440. 'face 'org-agenda-restriction-lock)
  6441. (overlay-put org-agenda-restriction-lock-overlay
  6442. 'help-echo "Agendas are currently limited to this subtree.")
  6443. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6444. (defun org-agenda-set-restriction-lock (&optional type)
  6445. "Set restriction lock for agenda, to current subtree or file.
  6446. Restriction will be the file if TYPE is `file', or if type is the
  6447. universal prefix '(4), or if the cursor is before the first headline
  6448. in the file. Otherwise, restriction will be to the current subtree."
  6449. (interactive "P")
  6450. (and (equal type '(4)) (setq type 'file))
  6451. (setq type (cond
  6452. (type type)
  6453. ((org-at-heading-p) 'subtree)
  6454. ((condition-case nil (org-back-to-heading t) (error nil))
  6455. 'subtree)
  6456. (t 'file)))
  6457. (if (eq type 'subtree)
  6458. (progn
  6459. (setq org-agenda-restrict t)
  6460. (setq org-agenda-overriding-restriction 'subtree)
  6461. (put 'org-agenda-files 'org-restrict
  6462. (list (buffer-file-name (buffer-base-buffer))))
  6463. (org-back-to-heading t)
  6464. (move-overlay org-agenda-restriction-lock-overlay
  6465. (point) (save-excursion (org-end-of-subtree t t) (point)))
  6466. (move-marker org-agenda-restrict-begin (point))
  6467. (move-marker org-agenda-restrict-end
  6468. (save-excursion (org-end-of-subtree t t)))
  6469. (message "Locking agenda restriction to subtree"))
  6470. (put 'org-agenda-files 'org-restrict
  6471. (list (buffer-file-name (buffer-base-buffer))))
  6472. (setq org-agenda-restrict nil)
  6473. (setq org-agenda-overriding-restriction 'file)
  6474. (move-marker org-agenda-restrict-begin nil)
  6475. (move-marker org-agenda-restrict-end nil)
  6476. (message "Locking agenda restriction to file"))
  6477. (setq current-prefix-arg nil)
  6478. (org-agenda-maybe-redo))
  6479. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6480. "Remove the agenda restriction lock."
  6481. (interactive "P")
  6482. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6483. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6484. (setq org-agenda-overriding-restriction nil)
  6485. (setq org-agenda-restrict nil)
  6486. (put 'org-agenda-files 'org-restrict nil)
  6487. (move-marker org-agenda-restrict-begin nil)
  6488. (move-marker org-agenda-restrict-end nil)
  6489. (setq current-prefix-arg nil)
  6490. (message "Agenda restriction lock removed")
  6491. (or noupdate (org-agenda-maybe-redo)))
  6492. (defun org-agenda-maybe-redo ()
  6493. "If there is any window showing the agenda view, update it."
  6494. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6495. (w0 (selected-window)))
  6496. (when w
  6497. (select-window w)
  6498. (org-agenda-redo)
  6499. (select-window w0)
  6500. (if org-agenda-overriding-restriction
  6501. (message "Agenda view shifted to new %s restriction"
  6502. org-agenda-overriding-restriction)
  6503. (message "Agenda restriction lock removed")))))
  6504. ;;; Agenda commands
  6505. (defun org-agenda-check-type (error &rest types)
  6506. "Check if agenda buffer is of allowed type.
  6507. If ERROR is non-nil, throw an error, otherwise just return nil.
  6508. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6509. (if (not org-agenda-type)
  6510. (error "No Org agenda currently displayed")
  6511. (if (memq org-agenda-type types)
  6512. t
  6513. (if error
  6514. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6515. nil))))
  6516. (defun org-agenda-Quit ()
  6517. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6518. Also restore the window configuration."
  6519. (interactive)
  6520. (if org-agenda-columns-active
  6521. (org-columns-quit)
  6522. (let ((buf (current-buffer)))
  6523. (if (eq org-agenda-window-setup 'other-frame)
  6524. (progn
  6525. (org-agenda-reset-markers)
  6526. (kill-buffer buf)
  6527. (org-columns-remove-overlays)
  6528. (setq org-agenda-archives-mode nil)
  6529. (delete-frame))
  6530. (and (not (eq org-agenda-window-setup 'current-window))
  6531. (not (one-window-p))
  6532. (delete-window))
  6533. (org-agenda-reset-markers)
  6534. (kill-buffer buf)
  6535. (org-columns-remove-overlays)
  6536. (setq org-agenda-archives-mode nil)))
  6537. ;; Maybe restore the pre-agenda window configuration.
  6538. (and org-agenda-restore-windows-after-quit
  6539. (not (eq org-agenda-window-setup 'other-frame))
  6540. org-agenda-pre-window-conf
  6541. (set-window-configuration org-agenda-pre-window-conf)
  6542. (setq org-agenda-pre-window-conf nil))))
  6543. (defun org-agenda-quit ()
  6544. "Exit the agenda and restore the window configuration.
  6545. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6546. (interactive)
  6547. (if (and (eq org-indirect-buffer-display 'other-window)
  6548. org-last-indirect-buffer)
  6549. (let ((org-last-indirect-window
  6550. (get-buffer-window org-last-indirect-buffer)))
  6551. (if org-last-indirect-window
  6552. (delete-window org-last-indirect-window))))
  6553. (if org-agenda-columns-active
  6554. (org-columns-quit)
  6555. (if org-agenda-sticky
  6556. (let ((buf (current-buffer)))
  6557. (if (eq org-agenda-window-setup 'other-frame)
  6558. (progn
  6559. (delete-frame))
  6560. (and (not (eq org-agenda-window-setup 'current-window))
  6561. (not (one-window-p))
  6562. (delete-window)))
  6563. (with-current-buffer buf
  6564. (bury-buffer)
  6565. ;; Maybe restore the pre-agenda window configuration.
  6566. (and org-agenda-restore-windows-after-quit
  6567. (not (eq org-agenda-window-setup 'other-frame))
  6568. org-agenda-pre-window-conf
  6569. (set-window-configuration org-agenda-pre-window-conf)
  6570. (setq org-agenda-pre-window-conf nil))))
  6571. (org-agenda-Quit))))
  6572. (defun org-agenda-exit ()
  6573. "Exit the agenda and restore the window configuration.
  6574. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6575. buffers visited directly by the user will not be touched."
  6576. (interactive)
  6577. (org-release-buffers org-agenda-new-buffers)
  6578. (setq org-agenda-new-buffers nil)
  6579. (org-agenda-Quit))
  6580. (defun org-agenda-kill-all-agenda-buffers ()
  6581. "Kill all buffers in `org-agenda-mode'.
  6582. This is used when toggling sticky agendas.
  6583. You can also explicitly invoke it with `C-c a C-k'."
  6584. (interactive)
  6585. (let (blist)
  6586. (dolist (buf (buffer-list))
  6587. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6588. (push buf blist)))
  6589. (mapc 'kill-buffer blist)))
  6590. (defun org-agenda-execute (arg)
  6591. "Execute another agenda command, keeping same window.
  6592. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6593. in the agenda."
  6594. (interactive "P")
  6595. (let ((org-agenda-window-setup 'current-window))
  6596. (org-agenda arg)))
  6597. (defun org-agenda-redo (&optional all)
  6598. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6599. (interactive "P")
  6600. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6601. (cpa (unless (eq all t) current-prefix-arg))
  6602. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6603. (org-agenda-sticky nil)
  6604. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6605. org-agenda-buffer-name))
  6606. (org-agenda-keep-modes t)
  6607. (tag-filter org-agenda-tag-filter)
  6608. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6609. (top-cat-filter org-agenda-top-category-filter)
  6610. (cat-filter org-agenda-category-filter)
  6611. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6612. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6613. (cols org-agenda-columns-active)
  6614. (line (org-current-line))
  6615. (window-line (- line (org-current-line (window-start))))
  6616. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6617. (redo-cmd (get-text-property p 'org-redo-cmd))
  6618. (last-args (get-text-property p 'org-last-args))
  6619. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6620. (org-agenda-overriding-cmd-arguments
  6621. (unless (eq all t)
  6622. (cond ((listp last-args)
  6623. (cons (or cpa (car last-args)) (cdr last-args)))
  6624. ((stringp last-args)
  6625. last-args))))
  6626. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6627. (put 'org-agenda-tag-filter :preset-filter nil)
  6628. (put 'org-agenda-category-filter :preset-filter nil)
  6629. (and cols (org-columns-quit))
  6630. (message "Rebuilding agenda buffer...")
  6631. (if series-redo-cmd
  6632. (eval series-redo-cmd)
  6633. (org-let lprops '(eval redo-cmd)))
  6634. (setq org-agenda-undo-list nil
  6635. org-agenda-pending-undo-list nil)
  6636. (message "Rebuilding agenda buffer...done")
  6637. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6638. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6639. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6640. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6641. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6642. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6643. (org-goto-line line)
  6644. (recenter window-line)))
  6645. (defvar org-global-tags-completion-table nil)
  6646. (defvar org-agenda-filter-form nil)
  6647. (defvar org-agenda-filtered-by-category nil)
  6648. (defun org-agenda-filter-by-category (strip)
  6649. "Keep only those lines in the agenda buffer that have a specific category.
  6650. The category is that of the current line."
  6651. (interactive "P")
  6652. (if (and org-agenda-filtered-by-category
  6653. org-agenda-category-filter)
  6654. (org-agenda-filter-show-all-cat)
  6655. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6656. (if cat (org-agenda-filter-apply
  6657. (list (concat (if strip "-" "+") cat)) 'category)
  6658. (error "No category at point")))))
  6659. (defun org-find-top-category (&optional pos)
  6660. (save-excursion
  6661. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6662. (if pos (goto-char pos))
  6663. ;; Skip up to the topmost parent
  6664. (while (ignore-errors (outline-up-heading 1) t))
  6665. (ignore-errors
  6666. (nth 4 (org-heading-components))))))
  6667. (defvar org-agenda-filtered-by-top-category nil)
  6668. (defun org-agenda-filter-by-top-category (strip)
  6669. "Keep only those lines in the agenda buffer that have a specific category.
  6670. The category is that of the current line."
  6671. (interactive "P")
  6672. (if org-agenda-filtered-by-top-category
  6673. (progn
  6674. (setq org-agenda-filtered-by-top-category nil
  6675. org-agenda-top-category-filter nil)
  6676. (org-agenda-filter-show-all-cat))
  6677. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6678. (if cat (org-agenda-filter-top-category-apply cat strip)
  6679. (error "No top-level category at point")))))
  6680. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6681. "Keep only those lines in the agenda buffer that have a specific tag.
  6682. The tag is selected with its fast selection letter, as configured.
  6683. With prefix argument STRIP, remove all lines that do have the tag.
  6684. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6685. used to narrow the search - the interactive user can also press `-' or `+'
  6686. to switch to narrowing."
  6687. (interactive "P")
  6688. (let* ((alist org-tag-alist-for-agenda)
  6689. (tag-chars (mapconcat
  6690. (lambda (x) (if (and (not (symbolp (car x)))
  6691. (cdr x))
  6692. (char-to-string (cdr x))
  6693. ""))
  6694. alist ""))
  6695. (efforts (org-split-string
  6696. (or (cdr (assoc (concat org-effort-property "_ALL")
  6697. org-global-properties))
  6698. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6699. "")))
  6700. (effort-op org-agenda-filter-effort-default-operator)
  6701. (effort-prompt "")
  6702. (inhibit-read-only t)
  6703. (current org-agenda-tag-filter)
  6704. maybe-refresh a n tag)
  6705. (unless char
  6706. (message
  6707. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6708. (if narrow "Narrow" "Filter") tag-chars
  6709. (if org-agenda-auto-exclude-function "[RET], " ""))
  6710. (setq char (read-char-exclusive)))
  6711. (when (member char '(?+ ?-))
  6712. ;; Narrowing down
  6713. (cond ((equal char ?-) (setq strip t narrow t))
  6714. ((equal char ?+) (setq strip nil narrow t)))
  6715. (message
  6716. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6717. (setq char (read-char-exclusive)))
  6718. (when (member char '(?< ?> ?= ??))
  6719. ;; An effort operator
  6720. (setq effort-op (char-to-string char))
  6721. (setq alist nil) ; to make sure it will be interpreted as effort.
  6722. (unless (equal char ??)
  6723. (loop for i from 0 to 9 do
  6724. (setq effort-prompt
  6725. (concat
  6726. effort-prompt " ["
  6727. (if (= i 9) "0" (int-to-string (1+ i)))
  6728. "]" (nth i efforts))))
  6729. (message "Effort%s: %s " effort-op effort-prompt)
  6730. (setq char (read-char-exclusive))
  6731. (when (or (< char ?0) (> char ?9))
  6732. (error "Need 1-9,0 to select effort"))))
  6733. (when (equal char ?\t)
  6734. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6735. (org-set-local 'org-global-tags-completion-table
  6736. (org-global-tags-completion-table)))
  6737. (let ((completion-ignore-case t))
  6738. (setq tag (org-icompleting-read
  6739. "Tag: " org-global-tags-completion-table))))
  6740. (cond
  6741. ((equal char ?\r)
  6742. (org-agenda-filter-show-all-tag)
  6743. (when org-agenda-auto-exclude-function
  6744. (setq org-agenda-tag-filter '())
  6745. (dolist (tag (org-agenda-get-represented-tags))
  6746. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6747. (if modifier
  6748. (push modifier org-agenda-tag-filter))))
  6749. (if (not (null org-agenda-tag-filter))
  6750. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6751. (setq maybe-refresh t))
  6752. ((equal char ?/)
  6753. (org-agenda-filter-show-all-tag)
  6754. (when (get 'org-agenda-tag-filter :preset-filter)
  6755. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6756. (setq maybe-refresh t))
  6757. ((equal char ?. )
  6758. (setq org-agenda-tag-filter
  6759. (mapcar (lambda(tag) (concat "+" tag))
  6760. (org-get-at-bol 'tags)))
  6761. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6762. (setq maybe-refresh t))
  6763. ((or (equal char ?\ )
  6764. (setq a (rassoc char alist))
  6765. (and (>= char ?0) (<= char ?9)
  6766. (setq n (if (= char ?0) 9 (- char ?0 1))
  6767. tag (concat effort-op (nth n efforts))
  6768. a (cons tag nil)))
  6769. (and (= char ??)
  6770. (setq tag "?eff")
  6771. a (cons tag nil))
  6772. (and tag (setq a (cons tag nil))))
  6773. (org-agenda-filter-show-all-tag)
  6774. (setq tag (car a))
  6775. (setq org-agenda-tag-filter
  6776. (cons (concat (if strip "-" "+") tag)
  6777. (if narrow current nil)))
  6778. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6779. (setq maybe-refresh t))
  6780. (t (error "Invalid tag selection character %c" char)))
  6781. (when (and maybe-refresh
  6782. (eq org-agenda-clockreport-mode 'with-filter))
  6783. (org-agenda-redo))))
  6784. (defun org-agenda-get-represented-tags ()
  6785. "Get a list of all tags currently represented in the agenda."
  6786. (let (p tags)
  6787. (save-excursion
  6788. (goto-char (point-min))
  6789. (while (setq p (next-single-property-change (point) 'tags))
  6790. (goto-char p)
  6791. (mapc (lambda (x) (add-to-list 'tags x))
  6792. (get-text-property (point) 'tags))))
  6793. tags))
  6794. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6795. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6796. (interactive "P")
  6797. (org-agenda-filter-by-tag strip char 'refine))
  6798. (defun org-agenda-filter-make-matcher ()
  6799. "Create the form that tests a line for agenda filter."
  6800. (let (f f1)
  6801. ;; first compute the tag-filter matcher
  6802. (dolist (x (delete-dups
  6803. (append (get 'org-agenda-tag-filter
  6804. :preset-filter) org-agenda-tag-filter)))
  6805. (if (member x '("-" "+"))
  6806. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6807. (if (string-match "[<=>?]" x)
  6808. (setq f1 (org-agenda-filter-effort-form x))
  6809. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6810. (if (equal (string-to-char x) ?-)
  6811. (setq f1 (list 'not f1))))
  6812. (push f1 f))
  6813. ;; then compute the category-filter matcher
  6814. (dolist (x (delete-dups
  6815. (append (get 'org-agenda-category-filter
  6816. :preset-filter) org-agenda-category-filter)))
  6817. (if (equal "-" (substring x 0 1))
  6818. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6819. (setq f1 (list 'equal (substring x 1) 'cat)))
  6820. (push f1 f))
  6821. (cons 'and (nreverse f))))
  6822. (defun org-agenda-filter-effort-form (e)
  6823. "Return the form to compare the effort of the current line with what E says.
  6824. E looks like \"+<2:25\"."
  6825. (let (op)
  6826. (setq e (substring e 1))
  6827. (setq op (string-to-char e) e (substring e 1))
  6828. (setq op (cond ((equal op ?<) '<=)
  6829. ((equal op ?>) '>=)
  6830. ((equal op ??) op)
  6831. (t '=)))
  6832. (list 'org-agenda-compare-effort (list 'quote op)
  6833. (org-duration-string-to-minutes e))))
  6834. (defun org-agenda-compare-effort (op value)
  6835. "Compare the effort of the current line with VALUE, using OP.
  6836. If the line does not have an effort defined, return nil."
  6837. (let ((eff (org-get-at-bol 'effort-minutes)))
  6838. (if (equal op ??)
  6839. (not eff)
  6840. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6841. value))))
  6842. (defun org-agenda-filter-apply (filter type)
  6843. "Set FILTER as the new agenda filter and apply it."
  6844. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  6845. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  6846. (let (tags cat)
  6847. (if (eq type 'tag)
  6848. (setq org-agenda-tag-filter filter)
  6849. (setq org-agenda-category-filter filter))
  6850. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6851. (if (and (eq type 'category)
  6852. (not (equal (substring (car filter) 0 1) "-")))
  6853. ;; Only set `org-agenda-filtered-by-category' to t
  6854. ;; when a unique category is used as the filter
  6855. (setq org-agenda-filtered-by-category t))
  6856. (org-agenda-set-mode-name)
  6857. (save-excursion
  6858. (goto-char (point-min))
  6859. (while (not (eobp))
  6860. (if (org-get-at-bol 'org-marker)
  6861. (progn
  6862. (setq tags (org-get-at-bol 'tags) ; used in eval
  6863. cat (get-text-property (point) 'org-category))
  6864. (if (not (eval org-agenda-filter-form))
  6865. (org-agenda-filter-hide-line type))
  6866. (beginning-of-line 2))
  6867. (beginning-of-line 2))))
  6868. (if (get-char-property (point) 'invisible)
  6869. (ignore-errors (org-agenda-previous-line)))))
  6870. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6871. "Set FILTER as the new agenda filter and apply it."
  6872. (org-agenda-set-mode-name)
  6873. (save-excursion
  6874. (goto-char (point-min))
  6875. (while (not (eobp))
  6876. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6877. (topcat (and pos (org-find-top-category pos))))
  6878. (if (and topcat (funcall (if negative 'identity 'not)
  6879. (string= category topcat)))
  6880. (org-agenda-filter-hide-line 'category)))
  6881. (beginning-of-line 2)))
  6882. (if (get-char-property (point) 'invisible)
  6883. (org-agenda-previous-line))
  6884. (setq org-agenda-top-category-filter category
  6885. org-agenda-filtered-by-top-category t))
  6886. (defun org-agenda-filter-hide-line (type)
  6887. (let (ov)
  6888. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6889. (point-at-eol)))
  6890. (overlay-put ov 'invisible t)
  6891. (overlay-put ov 'type type)
  6892. (if (eq type 'tag)
  6893. (push ov org-agenda-tag-filter-overlays)
  6894. (push ov org-agenda-cat-filter-overlays))))
  6895. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6896. (setq pos (or pos (point)))
  6897. (save-excursion
  6898. (dolist (ov (overlays-at pos))
  6899. (when (and (overlay-get ov 'invisible)
  6900. (eq (overlay-get ov 'type) 'tag))
  6901. (goto-char pos)
  6902. (if (< (overlay-start ov) (point-at-eol))
  6903. (move-overlay ov (point-at-eol)
  6904. (overlay-end ov)))))))
  6905. (defun org-agenda-filter-show-all-tag nil
  6906. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6907. (setq org-agenda-tag-filter-overlays nil
  6908. org-agenda-tag-filter nil
  6909. org-agenda-filter-form nil)
  6910. (org-agenda-set-mode-name))
  6911. (defun org-agenda-filter-show-all-cat nil
  6912. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6913. (setq org-agenda-cat-filter-overlays nil
  6914. org-agenda-filtered-by-category nil
  6915. org-agenda-category-filter nil
  6916. org-agenda-filter-form nil)
  6917. (org-agenda-set-mode-name))
  6918. (defun org-agenda-manipulate-query-add ()
  6919. "Manipulate the query by adding a search term with positive selection.
  6920. Positive selection means the term must be matched for selection of an entry."
  6921. (interactive)
  6922. (org-agenda-manipulate-query ?\[))
  6923. (defun org-agenda-manipulate-query-subtract ()
  6924. "Manipulate the query by adding a search term with negative selection.
  6925. Negative selection means term must not be matched for selection of an entry."
  6926. (interactive)
  6927. (org-agenda-manipulate-query ?\]))
  6928. (defun org-agenda-manipulate-query-add-re ()
  6929. "Manipulate the query by adding a search regexp with positive selection.
  6930. Positive selection means the regexp must match for selection of an entry."
  6931. (interactive)
  6932. (org-agenda-manipulate-query ?\{))
  6933. (defun org-agenda-manipulate-query-subtract-re ()
  6934. "Manipulate the query by adding a search regexp with negative selection.
  6935. Negative selection means regexp must not match for selection of an entry."
  6936. (interactive)
  6937. (org-agenda-manipulate-query ?\}))
  6938. (defun org-agenda-manipulate-query (char)
  6939. (cond
  6940. ((memq org-agenda-type '(timeline agenda))
  6941. (let ((org-agenda-include-inactive-timestamps t))
  6942. (org-agenda-redo))
  6943. (message "Display now includes inactive timestamps as well"))
  6944. ((eq org-agenda-type 'search)
  6945. (org-add-to-string
  6946. 'org-agenda-query-string
  6947. (if org-agenda-last-search-view-search-was-boolean
  6948. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6949. (?\{ . " +{}") (?\} . " -{}"))))
  6950. " "))
  6951. (setq org-agenda-redo-command
  6952. (list 'org-search-view
  6953. (car (get-text-property (min (1- (point-max)) (point))
  6954. 'org-last-args))
  6955. org-agenda-query-string
  6956. (+ (length org-agenda-query-string)
  6957. (if (member char '(?\{ ?\})) 0 1))))
  6958. (set-register org-agenda-query-register org-agenda-query-string)
  6959. (let ((org-agenda-overriding-arguments
  6960. (cdr org-agenda-redo-command)))
  6961. (org-agenda-redo)))
  6962. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6963. org-agenda-type))))
  6964. (defun org-add-to-string (var string)
  6965. (set var (concat (symbol-value var) string)))
  6966. (defun org-agenda-goto-date (span)
  6967. "Jump to DATE in agenda."
  6968. (interactive "P")
  6969. (let* ((org-read-date-prefer-future
  6970. (eval org-agenda-jump-prefer-future))
  6971. (date (org-read-date))
  6972. (org-agenda-sticky-orig org-agenda-sticky)
  6973. (org-agenda-buffer-tmp-name (buffer-name))
  6974. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6975. (0-arg (or current-prefix-arg (car args)))
  6976. (2-arg (nth 2 args))
  6977. (newcmd (list 'org-agenda-list 0-arg date
  6978. (org-agenda-span-to-ndays 2-arg)))
  6979. (newargs (cdr newcmd))
  6980. (inhibit-read-only t)
  6981. org-agenda-sticky)
  6982. (if (not (org-agenda-check-type t 'agenda))
  6983. (error "Not available in non-agenda blocks")
  6984. (add-text-properties (point-min) (point-max)
  6985. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6986. (org-agenda-redo)
  6987. (setq org-agenda-sticky org-agenda-sticky-orig
  6988. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6989. (defun org-agenda-goto-today ()
  6990. "Go to today."
  6991. (interactive)
  6992. (org-agenda-check-type t 'timeline 'agenda)
  6993. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6994. (curspan (nth 2 args))
  6995. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6996. (cond
  6997. (tdpos (goto-char tdpos))
  6998. ((eq org-agenda-type 'agenda)
  6999. (let* ((sd (org-agenda-compute-starting-span
  7000. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7001. (org-agenda-overriding-arguments args))
  7002. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7003. (org-agenda-redo)
  7004. (org-agenda-find-same-or-today-or-agenda)))
  7005. (t (error "Cannot find today")))))
  7006. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7007. (goto-char
  7008. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7009. (text-property-any (point-min) (point-max) 'org-today t)
  7010. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7011. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7012. (org-agenda-goto-block-beginning))
  7013. (point-min))))
  7014. (defun org-agenda-goto-block-beginning ()
  7015. "Go the agenda block beginning."
  7016. (interactive)
  7017. (if (not (derived-mode-p 'org-agenda-mode))
  7018. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7019. (let (dest)
  7020. (save-excursion
  7021. (unless (looking-at "\\'")
  7022. (forward-char))
  7023. (let* ((prop 'org-agenda-structural-header)
  7024. (p (previous-single-property-change (point) prop))
  7025. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7026. (1- (point))) prop)))
  7027. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7028. (if (not dest)
  7029. (error "Cannot find the beginning of the blog")
  7030. (goto-char dest)
  7031. (move-beginning-of-line 1)))))
  7032. (defun org-agenda-later (arg)
  7033. "Go forward in time by the current span.
  7034. With prefix ARG, go forward that many times the current span."
  7035. (interactive "p")
  7036. (org-agenda-check-type t 'agenda)
  7037. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7038. (span (or (nth 2 args) org-agenda-current-span))
  7039. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7040. (greg (calendar-gregorian-from-absolute sd))
  7041. (cnt (org-get-at-bol 'org-day-cnt))
  7042. greg2)
  7043. (cond
  7044. ((numberp span)
  7045. (setq sd (+ (* span arg) sd)))
  7046. ((eq span 'day)
  7047. (setq sd (+ arg sd)))
  7048. ((eq span 'week)
  7049. (setq sd (+ (* 7 arg) sd)))
  7050. ((eq span 'month)
  7051. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7052. sd (calendar-absolute-from-gregorian greg2))
  7053. (setcar greg2 (1+ (car greg2))))
  7054. ((eq span 'year)
  7055. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7056. sd (calendar-absolute-from-gregorian greg2))
  7057. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7058. (t
  7059. (setq sd (+ (* span arg) sd))))
  7060. (let ((org-agenda-overriding-cmd
  7061. ;; `cmd' may have been set by `org-agenda-run-series' which
  7062. ;; uses `org-agenda-overriding-cmd' to decide whether
  7063. ;; overriding is allowed for `cmd'
  7064. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7065. (org-agenda-overriding-arguments
  7066. (list (car args) sd span)))
  7067. (org-agenda-redo)
  7068. (org-agenda-find-same-or-today-or-agenda cnt))))
  7069. (defun org-agenda-earlier (arg)
  7070. "Go backward in time by the current span.
  7071. With prefix ARG, go backward that many times the current span."
  7072. (interactive "p")
  7073. (org-agenda-later (- arg)))
  7074. (defun org-agenda-view-mode-dispatch ()
  7075. "Call one of the view mode commands."
  7076. (interactive)
  7077. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  7078. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7079. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7080. (let ((a (read-char-exclusive)))
  7081. (case a
  7082. (?\ (call-interactively 'org-agenda-reset-view))
  7083. (?d (call-interactively 'org-agenda-day-view))
  7084. (?w (call-interactively 'org-agenda-week-view))
  7085. (?m (call-interactively 'org-agenda-month-view))
  7086. (?y (call-interactively 'org-agenda-year-view))
  7087. (?l (call-interactively 'org-agenda-log-mode))
  7088. (?L (org-agenda-log-mode '(4)))
  7089. (?c (org-agenda-log-mode 'clockcheck))
  7090. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7091. (?a (call-interactively 'org-agenda-archives-mode))
  7092. (?A (org-agenda-archives-mode 'files))
  7093. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7094. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7095. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7096. (?D (call-interactively 'org-agenda-toggle-diary))
  7097. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7098. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7099. (org-agenda-check-type t 'timeline 'agenda)
  7100. (org-agenda-redo))
  7101. (message "Display now includes inactive timestamps as well"))
  7102. (?q (message "Abort"))
  7103. (otherwise (error "Invalid key" )))))
  7104. (defun org-agenda-reset-view ()
  7105. "Switch to default view for agenda."
  7106. (interactive)
  7107. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7108. (defun org-agenda-day-view (&optional day-of-month)
  7109. "Switch to daily view for agenda.
  7110. With argument DAY-OF-MONTH, switch to that day of the month."
  7111. (interactive "P")
  7112. (org-agenda-change-time-span 'day day-of-month))
  7113. (defun org-agenda-week-view (&optional iso-week)
  7114. "Switch to daily view for agenda.
  7115. With argument ISO-WEEK, switch to the corresponding ISO week.
  7116. If ISO-WEEK has more then 2 digits, only the last two encode the
  7117. week. Any digits before this encode a year. So 200712 means
  7118. week 12 of year 2007. Years in the range 1938-2037 can also be
  7119. written as 2-digit years."
  7120. (interactive "P")
  7121. (org-agenda-change-time-span 'week iso-week))
  7122. (defun org-agenda-month-view (&optional month)
  7123. "Switch to monthly view for agenda.
  7124. With argument MONTH, switch to that month."
  7125. (interactive "P")
  7126. (org-agenda-change-time-span 'month month))
  7127. (defun org-agenda-year-view (&optional year)
  7128. "Switch to yearly view for agenda.
  7129. With argument YEAR, switch to that year.
  7130. If MONTH has more then 2 digits, only the last two encode the
  7131. month. Any digits before this encode a year. So 200712 means
  7132. December year 2007. Years in the range 1938-2037 can also be
  7133. written as 2-digit years."
  7134. (interactive "P")
  7135. (when year
  7136. (setq year (org-small-year-to-year year)))
  7137. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7138. (org-agenda-change-time-span 'year year)
  7139. (error "Abort")))
  7140. (defun org-agenda-change-time-span (span &optional n)
  7141. "Change the agenda view to SPAN.
  7142. SPAN may be `day', `week', `month', `year'."
  7143. (org-agenda-check-type t 'agenda)
  7144. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7145. (curspan (nth 2 args)))
  7146. (if (and (not n) (equal curspan span))
  7147. (error "Viewing span is already \"%s\"" span))
  7148. (let* ((sd (or (org-get-at-bol 'day)
  7149. (nth 1 args)
  7150. org-starting-day))
  7151. (sd (org-agenda-compute-starting-span sd span n))
  7152. (org-agenda-overriding-cmd
  7153. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7154. (org-agenda-overriding-arguments
  7155. (list (car args) sd span)))
  7156. (org-agenda-redo)
  7157. (org-agenda-find-same-or-today-or-agenda))
  7158. (org-agenda-set-mode-name)
  7159. (message "Switched to %s view" span)))
  7160. (defun org-agenda-compute-starting-span (sd span &optional n)
  7161. "Compute starting date for agenda.
  7162. SPAN may be `day', `week', `month', `year'. The return value
  7163. is a cons cell with the starting date and the number of days,
  7164. so that the date SD will be in that range."
  7165. (let* ((greg (calendar-gregorian-from-absolute sd))
  7166. (dg (nth 1 greg))
  7167. (mg (car greg))
  7168. (yg (nth 2 greg)))
  7169. (cond
  7170. ((eq span 'day)
  7171. (when n
  7172. (setq sd (+ (calendar-absolute-from-gregorian
  7173. (list mg 1 yg))
  7174. n -1))))
  7175. ((eq span 'week)
  7176. (let* ((nt (calendar-day-of-week
  7177. (calendar-gregorian-from-absolute sd)))
  7178. (d (if org-agenda-start-on-weekday
  7179. (- nt org-agenda-start-on-weekday)
  7180. 0))
  7181. y1)
  7182. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7183. (when n
  7184. (require 'cal-iso)
  7185. (when (> n 99)
  7186. (setq y1 (org-small-year-to-year (/ n 100))
  7187. n (mod n 100)))
  7188. (setq sd
  7189. (calendar-absolute-from-iso
  7190. (list n 1
  7191. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7192. ((eq span 'month)
  7193. (let (y1)
  7194. (when (and n (> n 99))
  7195. (setq y1 (org-small-year-to-year (/ n 100))
  7196. n (mod n 100)))
  7197. (setq sd (calendar-absolute-from-gregorian
  7198. (list (or n mg) 1 (or y1 yg))))))
  7199. ((eq span 'year)
  7200. (setq sd (calendar-absolute-from-gregorian
  7201. (list 1 1 (or n yg))))))
  7202. sd))
  7203. (defun org-agenda-next-date-line (&optional arg)
  7204. "Jump to the next line indicating a date in agenda buffer."
  7205. (interactive "p")
  7206. (org-agenda-check-type t 'agenda 'timeline)
  7207. (beginning-of-line 1)
  7208. ;; This does not work if user makes date format that starts with a blank
  7209. (if (looking-at "^\\S-") (forward-char 1))
  7210. (if (not (re-search-forward "^\\S-" nil t arg))
  7211. (progn
  7212. (backward-char 1)
  7213. (error "No next date after this line in this buffer")))
  7214. (goto-char (match-beginning 0)))
  7215. (defun org-agenda-previous-date-line (&optional arg)
  7216. "Jump to the previous line indicating a date in agenda buffer."
  7217. (interactive "p")
  7218. (org-agenda-check-type t 'agenda 'timeline)
  7219. (beginning-of-line 1)
  7220. (if (not (re-search-backward "^\\S-" nil t arg))
  7221. (error "No previous date before this line in this buffer")))
  7222. ;; Initialize the highlight
  7223. (defvar org-hl (make-overlay 1 1))
  7224. (overlay-put org-hl 'face 'highlight)
  7225. (defun org-highlight (begin end &optional buffer)
  7226. "Highlight a region with overlay."
  7227. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7228. (defun org-unhighlight ()
  7229. "Detach overlay INDEX."
  7230. (org-detach-overlay org-hl))
  7231. (defun org-unhighlight-once ()
  7232. "Remove the highlight from its position, and this function from the hook."
  7233. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7234. (org-unhighlight))
  7235. (defvar org-agenda-pre-follow-window-conf nil)
  7236. (defun org-agenda-follow-mode ()
  7237. "Toggle follow mode in an agenda buffer."
  7238. (interactive)
  7239. (unless org-agenda-follow-mode
  7240. (setq org-agenda-pre-follow-window-conf
  7241. (current-window-configuration)))
  7242. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7243. (unless org-agenda-follow-mode
  7244. (set-window-configuration org-agenda-pre-follow-window-conf))
  7245. (org-agenda-set-mode-name)
  7246. (org-agenda-do-context-action)
  7247. (message "Follow mode is %s"
  7248. (if org-agenda-follow-mode "on" "off")))
  7249. (defun org-agenda-entry-text-mode (&optional arg)
  7250. "Toggle entry text mode in an agenda buffer."
  7251. (interactive "P")
  7252. (if (or org-agenda-tag-filter
  7253. org-agenda-category-filter
  7254. org-agenda-top-category-filter)
  7255. (user-error "Can't show entry text in filtered views")
  7256. (setq org-agenda-entry-text-mode (or (integerp arg)
  7257. (not org-agenda-entry-text-mode)))
  7258. (org-agenda-entry-text-hide)
  7259. (and org-agenda-entry-text-mode
  7260. (let ((org-agenda-entry-text-maxlines
  7261. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7262. (org-agenda-entry-text-show)))
  7263. (org-agenda-set-mode-name)
  7264. (message "Entry text mode is %s%s"
  7265. (if org-agenda-entry-text-mode "on" "off")
  7266. (if (not org-agenda-entry-text-mode) ""
  7267. (format " (maximum number of lines is %d)"
  7268. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7269. (defun org-agenda-clockreport-mode (&optional with-filter)
  7270. "Toggle clocktable mode in an agenda buffer.
  7271. With prefix arg WITH-FILTER, make the clocktable respect the current
  7272. agenda filter."
  7273. (interactive "P")
  7274. (org-agenda-check-type t 'agenda)
  7275. (if with-filter
  7276. (setq org-agenda-clockreport-mode 'with-filter)
  7277. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7278. (org-agenda-set-mode-name)
  7279. (org-agenda-redo)
  7280. (message "Clocktable mode is %s"
  7281. (if org-agenda-clockreport-mode "on" "off")))
  7282. (defun org-agenda-log-mode (&optional special)
  7283. "Toggle log mode in an agenda buffer.
  7284. With argument SPECIAL, show all possible log items, not only the ones
  7285. configured in `org-agenda-log-mode-items'.
  7286. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7287. (interactive "P")
  7288. (org-agenda-check-type t 'agenda 'timeline)
  7289. (setq org-agenda-show-log
  7290. (cond
  7291. ((equal special '(16)) 'only)
  7292. ((eq special 'clockcheck)
  7293. (if (eq org-agenda-show-log 'clockcheck)
  7294. nil 'clockcheck))
  7295. (special '(closed clock state))
  7296. (t (not org-agenda-show-log))))
  7297. (org-agenda-set-mode-name)
  7298. (org-agenda-redo)
  7299. (message "Log mode is %s"
  7300. (if org-agenda-show-log "on" "off")))
  7301. (defun org-agenda-archives-mode (&optional with-files)
  7302. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7303. When called with a prefix argument, include all archive files as well."
  7304. (interactive "P")
  7305. (setq org-agenda-archives-mode
  7306. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7307. (org-agenda-set-mode-name)
  7308. (org-agenda-redo)
  7309. (message
  7310. "%s"
  7311. (cond
  7312. ((eq org-agenda-archives-mode nil)
  7313. "No archives are included")
  7314. ((eq org-agenda-archives-mode 'trees)
  7315. (format "Trees with :%s: tag are included" org-archive-tag))
  7316. ((eq org-agenda-archives-mode t)
  7317. (format "Trees with :%s: tag and all active archive files are included"
  7318. org-archive-tag)))))
  7319. (defun org-agenda-toggle-diary ()
  7320. "Toggle diary inclusion in an agenda buffer."
  7321. (interactive)
  7322. (org-agenda-check-type t 'agenda)
  7323. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7324. (org-agenda-redo)
  7325. (org-agenda-set-mode-name)
  7326. (message "Diary inclusion turned %s"
  7327. (if org-agenda-include-diary "on" "off")))
  7328. (defun org-agenda-toggle-deadlines ()
  7329. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7330. (interactive)
  7331. (org-agenda-check-type t 'agenda)
  7332. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7333. (org-agenda-redo)
  7334. (org-agenda-set-mode-name)
  7335. (message "Deadlines inclusion turned %s"
  7336. (if org-agenda-include-deadlines "on" "off")))
  7337. (defun org-agenda-toggle-time-grid ()
  7338. "Toggle time grid in an agenda buffer."
  7339. (interactive)
  7340. (org-agenda-check-type t 'agenda)
  7341. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7342. (org-agenda-redo)
  7343. (org-agenda-set-mode-name)
  7344. (message "Time-grid turned %s"
  7345. (if org-agenda-use-time-grid "on" "off")))
  7346. (defun org-agenda-set-mode-name ()
  7347. "Set the mode name to indicate all the small mode settings."
  7348. (setq mode-name
  7349. (list "Org-Agenda"
  7350. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7351. " "
  7352. '(:eval (org-agenda-span-name org-agenda-current-span))
  7353. (if org-agenda-follow-mode " Follow" "")
  7354. (if org-agenda-entry-text-mode " ETxt" "")
  7355. (if org-agenda-include-diary " Diary" "")
  7356. (if org-agenda-include-deadlines " Ddl" "")
  7357. (if org-agenda-use-time-grid " Grid" "")
  7358. (if (and (boundp 'org-habit-show-habits)
  7359. org-habit-show-habits) " Habit" "")
  7360. (cond
  7361. ((consp org-agenda-show-log) " LogAll")
  7362. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7363. (org-agenda-show-log " Log")
  7364. (t ""))
  7365. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7366. :preset-filter))
  7367. '(:eval (org-propertize
  7368. (concat " <"
  7369. (mapconcat
  7370. 'identity
  7371. (append
  7372. (get 'org-agenda-category-filter :preset-filter)
  7373. org-agenda-category-filter)
  7374. "")
  7375. ">")
  7376. 'face 'org-agenda-filter-category
  7377. 'help-echo "Category used in filtering"))
  7378. "")
  7379. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7380. :preset-filter))
  7381. '(:eval (org-propertize
  7382. (concat " {"
  7383. (mapconcat
  7384. 'identity
  7385. (append
  7386. (get 'org-agenda-tag-filter :preset-filter)
  7387. org-agenda-tag-filter)
  7388. "")
  7389. "}")
  7390. 'face 'org-agenda-filter-tags
  7391. 'help-echo "Tags used in filtering"))
  7392. "")
  7393. (if org-agenda-archives-mode
  7394. (if (eq org-agenda-archives-mode t)
  7395. " Archives"
  7396. (format " :%s:" org-archive-tag))
  7397. "")
  7398. (if org-agenda-clockreport-mode
  7399. (if (eq org-agenda-clockreport-mode 'with-filter)
  7400. " Clock{}" " Clock")
  7401. "")))
  7402. (force-mode-line-update))
  7403. (define-obsolete-function-alias
  7404. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7405. (defun org-agenda-update-agenda-type ()
  7406. "Update the agenda type after each command."
  7407. (setq org-agenda-type
  7408. (or (get-text-property (point) 'org-agenda-type)
  7409. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7410. (defun org-agenda-next-line ()
  7411. "Move cursor to the next line, and show if follow mode is active."
  7412. (interactive)
  7413. (call-interactively 'next-line)
  7414. (org-agenda-do-context-action))
  7415. (defun org-agenda-previous-line ()
  7416. "Move cursor to the previous line, and show if follow-mode is active."
  7417. (interactive)
  7418. (call-interactively 'previous-line)
  7419. (org-agenda-do-context-action))
  7420. (defun org-agenda-next-item (n)
  7421. "Move cursor to next agenda item."
  7422. (interactive "p")
  7423. (let ((col (current-column)))
  7424. (dotimes (c n)
  7425. (when (next-single-property-change (point-at-eol) 'org-marker)
  7426. (move-end-of-line 1)
  7427. (goto-char (next-single-property-change (point) 'org-marker))))
  7428. (org-move-to-column col))
  7429. (org-agenda-do-context-action))
  7430. (defun org-agenda-previous-item (n)
  7431. "Move cursor to next agenda item."
  7432. (interactive "p")
  7433. (dotimes (c n)
  7434. (let ((col (current-column))
  7435. (goto (save-excursion
  7436. (move-end-of-line 0)
  7437. (previous-single-property-change (point) 'org-marker))))
  7438. (if goto (goto-char goto))
  7439. (org-move-to-column col)))
  7440. (org-agenda-do-context-action))
  7441. (defun org-agenda-do-context-action ()
  7442. "Show outline path and, maybe, follow mode window."
  7443. (let ((m (org-get-at-bol 'org-marker)))
  7444. (when (and (markerp m) (marker-buffer m))
  7445. (and org-agenda-follow-mode
  7446. (if org-agenda-follow-indirect
  7447. (org-agenda-tree-to-indirect-buffer nil)
  7448. (org-agenda-show)))
  7449. (and org-agenda-show-outline-path
  7450. (org-with-point-at m (org-display-outline-path t))))))
  7451. (defun org-agenda-show-tags ()
  7452. "Show the tags applicable to the current item."
  7453. (interactive)
  7454. (let* ((tags (org-get-at-bol 'tags)))
  7455. (if tags
  7456. (message "Tags are :%s:"
  7457. (org-no-properties (mapconcat 'identity tags ":")))
  7458. (message "No tags associated with this line"))))
  7459. (defun org-agenda-goto (&optional highlight)
  7460. "Go to the Org-mode file which contains the item at point."
  7461. (interactive)
  7462. (let* ((marker (or (org-get-at-bol 'org-marker)
  7463. (org-agenda-error)))
  7464. (buffer (marker-buffer marker))
  7465. (pos (marker-position marker)))
  7466. (switch-to-buffer-other-window buffer)
  7467. (widen)
  7468. (push-mark)
  7469. (goto-char pos)
  7470. (when (derived-mode-p 'org-mode)
  7471. (org-show-context 'agenda)
  7472. (save-excursion
  7473. (and (outline-next-heading)
  7474. (org-flag-heading nil)))) ; show the next heading
  7475. (when (outline-invisible-p)
  7476. (show-entry)) ; display invisible text
  7477. (recenter (/ (window-height) 2))
  7478. (run-hooks 'org-agenda-after-show-hook)
  7479. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7480. (defvar org-agenda-after-show-hook nil
  7481. "Normal hook run after an item has been shown from the agenda.
  7482. Point is in the buffer where the item originated.")
  7483. (defun org-agenda-kill ()
  7484. "Kill the entry or subtree belonging to the current agenda entry."
  7485. (interactive)
  7486. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7487. (let* ((bufname-orig (buffer-name))
  7488. (marker (or (org-get-at-bol 'org-marker)
  7489. (org-agenda-error)))
  7490. (buffer (marker-buffer marker))
  7491. (pos (marker-position marker))
  7492. (type (org-get-at-bol 'type))
  7493. dbeg dend (n 0) conf)
  7494. (org-with-remote-undo buffer
  7495. (with-current-buffer buffer
  7496. (save-excursion
  7497. (goto-char pos)
  7498. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7499. (setq dbeg (progn (org-back-to-heading t) (point))
  7500. dend (org-end-of-subtree t t))
  7501. (setq dbeg (point-at-bol)
  7502. dend (min (point-max) (1+ (point-at-eol)))))
  7503. (goto-char dbeg)
  7504. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7505. (setq conf (or (eq t org-agenda-confirm-kill)
  7506. (and (numberp org-agenda-confirm-kill)
  7507. (> n org-agenda-confirm-kill))))
  7508. (and conf
  7509. (not (y-or-n-p
  7510. (format "Delete entry with %d lines in buffer \"%s\"? "
  7511. n (buffer-name buffer))))
  7512. (error "Abort"))
  7513. (let ((org-agenda-buffer-name bufname-orig))
  7514. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7515. (with-current-buffer buffer (delete-region dbeg dend))
  7516. (message "Agenda item and source killed"))))
  7517. (defvar org-archive-default-command) ; defined in org-archive.el
  7518. (defun org-agenda-archive-default ()
  7519. "Archive the entry or subtree belonging to the current agenda entry."
  7520. (interactive)
  7521. (require 'org-archive)
  7522. (org-agenda-archive-with org-archive-default-command))
  7523. (defun org-agenda-archive-default-with-confirmation ()
  7524. "Archive the entry or subtree belonging to the current agenda entry."
  7525. (interactive)
  7526. (require 'org-archive)
  7527. (org-agenda-archive-with org-archive-default-command 'confirm))
  7528. (defun org-agenda-archive ()
  7529. "Archive the entry or subtree belonging to the current agenda entry."
  7530. (interactive)
  7531. (org-agenda-archive-with 'org-archive-subtree))
  7532. (defun org-agenda-archive-to-archive-sibling ()
  7533. "Move the entry to the archive sibling."
  7534. (interactive)
  7535. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7536. (defun org-agenda-archive-with (cmd &optional confirm)
  7537. "Move the entry to the archive sibling."
  7538. (interactive)
  7539. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7540. (let* ((bufname-orig (buffer-name))
  7541. (marker (or (org-get-at-bol 'org-marker)
  7542. (org-agenda-error)))
  7543. (buffer (marker-buffer marker))
  7544. (pos (marker-position marker)))
  7545. (org-with-remote-undo buffer
  7546. (with-current-buffer buffer
  7547. (if (derived-mode-p 'org-mode)
  7548. (if (and confirm
  7549. (not (y-or-n-p "Archive this subtree or entry? ")))
  7550. (error "Abort")
  7551. (save-excursion
  7552. (goto-char pos)
  7553. (let ((org-agenda-buffer-name bufname-orig))
  7554. (org-remove-subtree-entries-from-agenda))
  7555. (org-back-to-heading t)
  7556. (funcall cmd)))
  7557. (error "Archiving works only in Org-mode files"))))))
  7558. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7559. "Remove all lines in the agenda that correspond to a given subtree.
  7560. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7561. If this information is not given, the function uses the tree at point."
  7562. (let ((buf (or buf (current-buffer))) m p)
  7563. (save-excursion
  7564. (unless (and beg end)
  7565. (org-back-to-heading t)
  7566. (setq beg (point))
  7567. (org-end-of-subtree t)
  7568. (setq end (point)))
  7569. (set-buffer (get-buffer org-agenda-buffer-name))
  7570. (save-excursion
  7571. (goto-char (point-max))
  7572. (beginning-of-line 1)
  7573. (while (not (bobp))
  7574. (when (and (setq m (org-get-at-bol 'org-marker))
  7575. (equal buf (marker-buffer m))
  7576. (setq p (marker-position m))
  7577. (>= p beg)
  7578. (< p end))
  7579. (let ((inhibit-read-only t))
  7580. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7581. (beginning-of-line 0))))))
  7582. (defun org-agenda-refile (&optional goto rfloc no-update)
  7583. "Refile the item at point.
  7584. When GOTO is 0 or '(64), clear the refile cache.
  7585. When GOTO is '(16), go to the location of the last refiled item.
  7586. RFLOC can be a refile location obtained in a different way.
  7587. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7588. (interactive "P")
  7589. (cond
  7590. ((member goto '(0 (64)))
  7591. (org-refile-cache-clear))
  7592. ((equal goto '(16))
  7593. (org-refile-goto-last-stored))
  7594. (t
  7595. (let* ((buffer-orig (buffer-name))
  7596. (marker (or (org-get-at-bol 'org-hd-marker)
  7597. (org-agenda-error)))
  7598. (buffer (marker-buffer marker))
  7599. (pos (marker-position marker))
  7600. (rfloc (or rfloc
  7601. (org-refile-get-location
  7602. (if goto "Goto" "Refile to") buffer
  7603. org-refile-allow-creating-parent-nodes))))
  7604. (with-current-buffer buffer
  7605. (save-excursion
  7606. (save-restriction
  7607. (widen)
  7608. (goto-char marker)
  7609. (let ((org-agenda-buffer-name buffer-orig))
  7610. (org-remove-subtree-entries-from-agenda))
  7611. (org-refile goto buffer rfloc)))))
  7612. (unless no-update (org-agenda-redo)))))
  7613. (defun org-agenda-open-link (&optional arg)
  7614. "Open the link(s) in the current entry, if any.
  7615. This looks for a link in the displayed line in the agenda.
  7616. It also looks at the text of the entry itself."
  7617. (interactive "P")
  7618. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7619. (org-get-at-bol 'org-marker)))
  7620. (buffer (and marker (marker-buffer marker)))
  7621. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7622. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7623. (lk0 (car lkall))
  7624. (lk (if (stringp lk0) (list lk0) lk0))
  7625. (lkend (cdr lkall))
  7626. trg)
  7627. (cond
  7628. ((and buffer lk)
  7629. (mapcar (lambda(l)
  7630. (with-current-buffer buffer
  7631. (setq trg (and (string-match org-bracket-link-regexp l)
  7632. (match-string 1 l)))
  7633. (if (or (not trg) (string-match org-any-link-re trg))
  7634. (save-excursion
  7635. (save-restriction
  7636. (widen)
  7637. (goto-char marker)
  7638. (when (search-forward l nil lkend)
  7639. (goto-char (match-beginning 0))
  7640. (org-open-at-point))))
  7641. ;; This is an internal link, widen the buffer
  7642. (switch-to-buffer-other-window buffer)
  7643. (widen)
  7644. (goto-char marker)
  7645. (when (search-forward l nil lkend)
  7646. (goto-char (match-beginning 0))
  7647. (org-open-at-point)))))
  7648. lk))
  7649. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7650. (save-excursion
  7651. (beginning-of-line 1)
  7652. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7653. (org-open-link-from-string (match-string 1)))
  7654. (t (message "No link to open here")))))
  7655. (defun org-agenda-copy-local-variable (var)
  7656. "Get a variable from a referenced buffer and install it here."
  7657. (let ((m (org-get-at-bol 'org-marker)))
  7658. (when (and m (buffer-live-p (marker-buffer m)))
  7659. (org-set-local var (with-current-buffer (marker-buffer m)
  7660. (symbol-value var))))))
  7661. (defun org-agenda-switch-to (&optional delete-other-windows)
  7662. "Go to the Org-mode file which contains the item at point."
  7663. (interactive)
  7664. (if (and org-return-follows-link
  7665. (not (org-get-at-bol 'org-marker))
  7666. (org-in-regexp org-bracket-link-regexp))
  7667. (org-open-link-from-string (match-string 0))
  7668. (let* ((marker (or (org-get-at-bol 'org-marker)
  7669. (org-agenda-error)))
  7670. (buffer (marker-buffer marker))
  7671. (pos (marker-position marker)))
  7672. (org-pop-to-buffer-same-window buffer)
  7673. (and delete-other-windows (delete-other-windows))
  7674. (widen)
  7675. (goto-char pos)
  7676. (when (derived-mode-p 'org-mode)
  7677. (org-show-context 'agenda)
  7678. (save-excursion
  7679. (and (outline-next-heading)
  7680. (org-flag-heading nil))) ; show the next heading
  7681. (when (outline-invisible-p)
  7682. (show-entry)) ; display invisible text
  7683. (run-hooks 'org-agenda-after-show-hook)))))
  7684. (defun org-agenda-goto-mouse (ev)
  7685. "Go to the Org-mode file which contains the item at the mouse click."
  7686. (interactive "e")
  7687. (mouse-set-point ev)
  7688. (org-agenda-goto))
  7689. (defun org-agenda-show (&optional full-entry)
  7690. "Display the Org-mode file which contains the item at point.
  7691. With prefix argument FULL-ENTRY, make the entire entry visible
  7692. if it was hidden in the outline."
  7693. (interactive "P")
  7694. (let ((win (selected-window)))
  7695. (if full-entry
  7696. (let ((org-show-entry-below t))
  7697. (org-agenda-goto t))
  7698. (org-agenda-goto t))
  7699. (select-window win)))
  7700. (defvar org-agenda-show-window nil)
  7701. (defun org-agenda-show-and-scroll-up (&optional arg)
  7702. "Display the Org-mode file which contains the item at point.
  7703. When called repeatedly, scroll the window that is displaying the buffer.
  7704. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7705. `show-subtree' to display the item, so that drawers and logbooks stay
  7706. folded."
  7707. (interactive "P")
  7708. (let ((win (selected-window)))
  7709. (if (and (window-live-p org-agenda-show-window)
  7710. (eq this-command last-command))
  7711. (progn
  7712. (select-window org-agenda-show-window)
  7713. (ignore-errors (scroll-up)))
  7714. (org-agenda-goto t)
  7715. (if arg (org-show-entry) (show-subtree))
  7716. (setq org-agenda-show-window (selected-window)))
  7717. (select-window win)))
  7718. (defun org-agenda-show-scroll-down ()
  7719. "Scroll down the window showing the agenda."
  7720. (interactive)
  7721. (let ((win (selected-window)))
  7722. (when (window-live-p org-agenda-show-window)
  7723. (select-window org-agenda-show-window)
  7724. (ignore-errors (scroll-down))
  7725. (select-window win))))
  7726. (defun org-agenda-show-1 (&optional more)
  7727. "Display the Org-mode file which contains the item at point.
  7728. The prefix arg selects the amount of information to display:
  7729. 0 hide the subtree
  7730. 1 just show the entry according to defaults.
  7731. 2 show the children view
  7732. 3 show the subtree view
  7733. 4 show the entire subtree and any LOGBOOK drawers
  7734. 5 show the entire subtree and any drawers
  7735. With prefix argument FULL-ENTRY, make the entire entry visible
  7736. if it was hidden in the outline."
  7737. (interactive "p")
  7738. (let ((win (selected-window)))
  7739. (org-agenda-goto t)
  7740. (org-recenter-heading 1)
  7741. (cond
  7742. ((= more 0)
  7743. (hide-subtree)
  7744. (save-excursion
  7745. (org-back-to-heading)
  7746. (run-hook-with-args 'org-cycle-hook 'folded))
  7747. (message "Remote: FOLDED"))
  7748. ((and (org-called-interactively-p 'any) (= more 1))
  7749. (message "Remote: show with default settings"))
  7750. ((= more 2)
  7751. (show-entry)
  7752. (show-children)
  7753. (save-excursion
  7754. (org-back-to-heading)
  7755. (run-hook-with-args 'org-cycle-hook 'children))
  7756. (message "Remote: CHILDREN"))
  7757. ((= more 3)
  7758. (show-subtree)
  7759. (save-excursion
  7760. (org-back-to-heading)
  7761. (run-hook-with-args 'org-cycle-hook 'subtree))
  7762. (message "Remote: SUBTREE"))
  7763. ((= more 4)
  7764. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7765. (org-drawer-regexp
  7766. (concat "^[ \t]*:\\("
  7767. (mapconcat 'regexp-quote org-drawers "\\|")
  7768. "\\):[ \t]*$")))
  7769. (show-subtree)
  7770. (save-excursion
  7771. (org-back-to-heading)
  7772. (org-cycle-hide-drawers 'subtree)))
  7773. (message "Remote: SUBTREE AND LOGBOOK"))
  7774. ((> more 4)
  7775. (show-subtree)
  7776. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7777. (select-window win)))
  7778. (defun org-recenter-heading (n)
  7779. (save-excursion
  7780. (org-back-to-heading)
  7781. (recenter n)))
  7782. (defvar org-agenda-cycle-counter nil)
  7783. (defun org-agenda-cycle-show (&optional n)
  7784. "Show the current entry in another window, with default settings.
  7785. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7786. When use repeatedly in immediate succession, the remote entry will cycle
  7787. through visibility
  7788. children -> subtree -> folded
  7789. When called with a numeric prefix arg, that arg will be passed through to
  7790. `org-agenda-show-1'. For the interpretation of that argument, see the
  7791. docstring of `org-agenda-show-1'."
  7792. (interactive "P")
  7793. (if (integerp n)
  7794. (setq org-agenda-cycle-counter n)
  7795. (if (not (eq last-command this-command))
  7796. (setq org-agenda-cycle-counter 1)
  7797. (if (equal org-agenda-cycle-counter 0)
  7798. (setq org-agenda-cycle-counter 2)
  7799. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7800. (if (> org-agenda-cycle-counter 3)
  7801. (setq org-agenda-cycle-counter 0)))))
  7802. (org-agenda-show-1 org-agenda-cycle-counter))
  7803. (defun org-agenda-recenter (arg)
  7804. "Display the Org-mode file which contains the item at point and recenter."
  7805. (interactive "P")
  7806. (let ((win (selected-window)))
  7807. (org-agenda-goto t)
  7808. (recenter arg)
  7809. (select-window win)))
  7810. (defun org-agenda-show-mouse (ev)
  7811. "Display the Org-mode file which contains the item at the mouse click."
  7812. (interactive "e")
  7813. (mouse-set-point ev)
  7814. (org-agenda-show))
  7815. (defun org-agenda-check-no-diary ()
  7816. "Check if the entry is a diary link and abort if yes."
  7817. (if (org-get-at-bol 'org-agenda-diary-link)
  7818. (org-agenda-error)))
  7819. (defun org-agenda-error ()
  7820. (error "Command not allowed in this line"))
  7821. (defun org-agenda-tree-to-indirect-buffer (arg)
  7822. "Show the subtree corresponding to the current entry in an indirect buffer.
  7823. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7824. With a numerical prefix ARG, go up to this level and then take that tree.
  7825. With a negative numeric ARG, go up by this number of levels.
  7826. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7827. use the dedicated frame)."
  7828. (interactive "P")
  7829. (if current-prefix-arg
  7830. (org-agenda-do-tree-to-indirect-buffer arg)
  7831. (let ((agenda-buffer (buffer-name))
  7832. (agenda-window (selected-window))
  7833. (indirect-window
  7834. (and org-last-indirect-buffer
  7835. (get-buffer-window org-last-indirect-buffer))))
  7836. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7837. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7838. (eq org-indirect-buffer-display 'dedicated-frame))
  7839. (unwind-protect
  7840. (unless (and indirect-window (window-live-p indirect-window))
  7841. (setq indirect-window (split-window agenda-window)))
  7842. (and indirect-window (select-window indirect-window))
  7843. (switch-to-buffer org-last-indirect-buffer :norecord)
  7844. (fit-window-to-buffer indirect-window)))
  7845. (select-window (get-buffer-window agenda-buffer)))))
  7846. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7847. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7848. (org-agenda-check-no-diary)
  7849. (let* ((marker (or (org-get-at-bol 'org-marker)
  7850. (org-agenda-error)))
  7851. (buffer (marker-buffer marker))
  7852. (pos (marker-position marker)))
  7853. (with-current-buffer buffer
  7854. (save-excursion
  7855. (goto-char pos)
  7856. (funcall 'org-tree-to-indirect-buffer arg)))))
  7857. (defvar org-last-heading-marker (make-marker)
  7858. "Marker pointing to the headline that last changed its TODO state
  7859. by a remote command from the agenda.")
  7860. (defun org-agenda-todo-nextset ()
  7861. "Switch TODO entry to next sequence."
  7862. (interactive)
  7863. (org-agenda-todo 'nextset))
  7864. (defun org-agenda-todo-previousset ()
  7865. "Switch TODO entry to previous sequence."
  7866. (interactive)
  7867. (org-agenda-todo 'previousset))
  7868. (defun org-agenda-todo (&optional arg)
  7869. "Cycle TODO state of line at point, also in Org-mode file.
  7870. This changes the line at point, all other lines in the agenda referring to
  7871. the same tree node, and the headline of the tree node in the Org-mode file."
  7872. (interactive "P")
  7873. (org-agenda-check-no-diary)
  7874. (let* ((col (current-column))
  7875. (marker (or (org-get-at-bol 'org-marker)
  7876. (org-agenda-error)))
  7877. (buffer (marker-buffer marker))
  7878. (pos (marker-position marker))
  7879. (hdmarker (org-get-at-bol 'org-hd-marker))
  7880. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7881. (inhibit-read-only t)
  7882. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7883. (org-with-remote-undo buffer
  7884. (with-current-buffer buffer
  7885. (widen)
  7886. (goto-char pos)
  7887. (org-show-context 'agenda)
  7888. (save-excursion
  7889. (and (outline-next-heading)
  7890. (org-flag-heading nil))) ; show the next heading
  7891. (let ((current-prefix-arg arg))
  7892. (call-interactively 'org-todo))
  7893. (and (bolp) (forward-char 1))
  7894. (setq newhead (org-get-heading))
  7895. (when (and (org-bound-and-true-p
  7896. org-agenda-headline-snapshot-before-repeat)
  7897. (not (equal org-agenda-headline-snapshot-before-repeat
  7898. newhead))
  7899. todayp)
  7900. (setq newhead org-agenda-headline-snapshot-before-repeat
  7901. just-one t))
  7902. (save-excursion
  7903. (org-back-to-heading)
  7904. (move-marker org-last-heading-marker (point))))
  7905. (beginning-of-line 1)
  7906. (save-excursion
  7907. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7908. (org-move-to-column col))))
  7909. (defun org-agenda-add-note (&optional arg)
  7910. "Add a time-stamped note to the entry at point."
  7911. (interactive "P")
  7912. (org-agenda-check-no-diary)
  7913. (let* ((marker (or (org-get-at-bol 'org-marker)
  7914. (org-agenda-error)))
  7915. (buffer (marker-buffer marker))
  7916. (pos (marker-position marker))
  7917. (hdmarker (org-get-at-bol 'org-hd-marker))
  7918. (inhibit-read-only t))
  7919. (with-current-buffer buffer
  7920. (widen)
  7921. (goto-char pos)
  7922. (org-show-context 'agenda)
  7923. (save-excursion
  7924. (and (outline-next-heading)
  7925. (org-flag-heading nil))) ; show the next heading
  7926. (org-add-note))))
  7927. (defun org-agenda-change-all-lines (newhead hdmarker
  7928. &optional fixface just-this)
  7929. "Change all lines in the agenda buffer which match HDMARKER.
  7930. The new content of the line will be NEWHEAD (as modified by
  7931. `org-agenda-format-item'). HDMARKER is checked with
  7932. `equal' against all `org-hd-marker' text properties in the file.
  7933. If FIXFACE is non-nil, the face of each item is modified according to
  7934. the new TODO state.
  7935. If JUST-THIS is non-nil, change just the current line, not all.
  7936. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7937. (let* ((inhibit-read-only t)
  7938. (line (org-current-line))
  7939. (org-agenda-buffer (current-buffer))
  7940. (thetags (with-current-buffer (marker-buffer hdmarker)
  7941. (save-excursion (save-restriction (widen)
  7942. (goto-char hdmarker)
  7943. (org-get-tags-at)))))
  7944. props m pl undone-face done-face finish new dotime level cat tags)
  7945. (save-excursion
  7946. (goto-char (point-max))
  7947. (beginning-of-line 1)
  7948. (while (not finish)
  7949. (setq finish (bobp))
  7950. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7951. (or (not just-this) (= (org-current-line) line))
  7952. (equal m hdmarker))
  7953. (setq props (text-properties-at (point))
  7954. dotime (org-get-at-bol 'dotime)
  7955. cat (org-get-at-bol 'org-category)
  7956. level (org-get-at-bol 'level)
  7957. tags thetags
  7958. new
  7959. (let ((org-prefix-format-compiled
  7960. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7961. org-prefix-format-compiled))
  7962. (extra (org-get-at-bol 'extra)))
  7963. (with-current-buffer (marker-buffer hdmarker)
  7964. (save-excursion
  7965. (save-restriction
  7966. (widen)
  7967. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7968. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7969. undone-face (org-get-at-bol 'undone-face)
  7970. done-face (org-get-at-bol 'done-face))
  7971. (beginning-of-line 1)
  7972. (cond
  7973. ((equal new "")
  7974. (and (looking-at ".*\n?") (replace-match "")))
  7975. ((looking-at ".*")
  7976. (replace-match new t t)
  7977. (beginning-of-line 1)
  7978. (add-text-properties (point-at-bol) (point-at-eol) props)
  7979. (when fixface
  7980. (add-text-properties
  7981. (point-at-bol) (point-at-eol)
  7982. (list 'face
  7983. (if org-last-todo-state-is-todo
  7984. undone-face done-face))))
  7985. (org-agenda-highlight-todo 'line)
  7986. (beginning-of-line 1))
  7987. (t (error "Line update did not work")))
  7988. (save-restriction
  7989. (narrow-to-region (point-at-bol) (point-at-eol))
  7990. (org-agenda-finalize)))
  7991. (beginning-of-line 0)))))
  7992. (defun org-agenda-align-tags (&optional line)
  7993. "Align all tags in agenda items to `org-agenda-tags-column'."
  7994. (let ((inhibit-read-only t) l c)
  7995. (save-excursion
  7996. (goto-char (if line (point-at-bol) (point-min)))
  7997. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7998. (if line (point-at-eol) nil) t)
  7999. (add-text-properties
  8000. (match-beginning 2) (match-end 2)
  8001. (list 'face (delq nil (let ((prop (get-text-property
  8002. (match-beginning 2) 'face)))
  8003. (or (listp prop) (setq prop (list prop)))
  8004. (if (memq 'org-tag prop)
  8005. prop
  8006. (cons 'org-tag prop))))))
  8007. (setq l (- (match-end 2) (match-beginning 2))
  8008. c (if (< org-agenda-tags-column 0)
  8009. (- (abs org-agenda-tags-column) l)
  8010. org-agenda-tags-column))
  8011. (delete-region (match-beginning 1) (match-end 1))
  8012. (goto-char (match-beginning 1))
  8013. (insert (org-add-props
  8014. (make-string (max 1 (- c (current-column))) ?\ )
  8015. (plist-put (copy-sequence (text-properties-at (point)))
  8016. 'face nil))))
  8017. (goto-char (point-min))
  8018. (org-font-lock-add-tag-faces (point-max)))))
  8019. (defun org-agenda-priority-up ()
  8020. "Increase the priority of line at point, also in Org-mode file."
  8021. (interactive)
  8022. (org-agenda-priority 'up))
  8023. (defun org-agenda-priority-down ()
  8024. "Decrease the priority of line at point, also in Org-mode file."
  8025. (interactive)
  8026. (org-agenda-priority 'down))
  8027. (defun org-agenda-priority (&optional force-direction)
  8028. "Set the priority of line at point, also in Org-mode file.
  8029. This changes the line at point, all other lines in the agenda referring to
  8030. the same tree node, and the headline of the tree node in the Org-mode file.
  8031. Called with a universal prefix arg, show the priority instead of setting it."
  8032. (interactive "P")
  8033. (if (equal force-direction '(4))
  8034. (org-show-priority)
  8035. (unless org-enable-priority-commands
  8036. (error "Priority commands are disabled"))
  8037. (org-agenda-check-no-diary)
  8038. (let* ((marker (or (org-get-at-bol 'org-marker)
  8039. (org-agenda-error)))
  8040. (hdmarker (org-get-at-bol 'org-hd-marker))
  8041. (buffer (marker-buffer hdmarker))
  8042. (pos (marker-position hdmarker))
  8043. (inhibit-read-only t)
  8044. newhead)
  8045. (org-with-remote-undo buffer
  8046. (with-current-buffer buffer
  8047. (widen)
  8048. (goto-char pos)
  8049. (org-show-context 'agenda)
  8050. (save-excursion
  8051. (and (outline-next-heading)
  8052. (org-flag-heading nil))) ; show the next heading
  8053. (funcall 'org-priority force-direction)
  8054. (end-of-line 1)
  8055. (setq newhead (org-get-heading)))
  8056. (org-agenda-change-all-lines newhead hdmarker)
  8057. (beginning-of-line 1)))))
  8058. ;; FIXME: should fix the tags property of the agenda line.
  8059. (defun org-agenda-set-tags (&optional tag onoff)
  8060. "Set tags for the current headline."
  8061. (interactive)
  8062. (org-agenda-check-no-diary)
  8063. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8064. (call-interactively 'org-change-tag-in-region)
  8065. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8066. (org-agenda-error)))
  8067. (buffer (marker-buffer hdmarker))
  8068. (pos (marker-position hdmarker))
  8069. (inhibit-read-only t)
  8070. newhead)
  8071. (org-with-remote-undo buffer
  8072. (with-current-buffer buffer
  8073. (widen)
  8074. (goto-char pos)
  8075. (save-excursion
  8076. (org-show-context 'agenda))
  8077. (save-excursion
  8078. (and (outline-next-heading)
  8079. (org-flag-heading nil))) ; show the next heading
  8080. (goto-char pos)
  8081. (if tag
  8082. (org-toggle-tag tag onoff)
  8083. (call-interactively 'org-set-tags))
  8084. (end-of-line 1)
  8085. (setq newhead (org-get-heading)))
  8086. (org-agenda-change-all-lines newhead hdmarker)
  8087. (beginning-of-line 1)))))
  8088. (defun org-agenda-set-property ()
  8089. "Set a property for the current headline."
  8090. (interactive)
  8091. (org-agenda-check-no-diary)
  8092. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8093. (org-agenda-error)))
  8094. (buffer (marker-buffer hdmarker))
  8095. (pos (marker-position hdmarker))
  8096. (inhibit-read-only t)
  8097. newhead)
  8098. (org-with-remote-undo buffer
  8099. (with-current-buffer buffer
  8100. (widen)
  8101. (goto-char pos)
  8102. (save-excursion
  8103. (org-show-context 'agenda))
  8104. (save-excursion
  8105. (and (outline-next-heading)
  8106. (org-flag-heading nil))) ; show the next heading
  8107. (goto-char pos)
  8108. (call-interactively 'org-set-property)))))
  8109. (defun org-agenda-set-effort ()
  8110. "Set the effort property for the current headline."
  8111. (interactive)
  8112. (org-agenda-check-no-diary)
  8113. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8114. (org-agenda-error)))
  8115. (buffer (marker-buffer hdmarker))
  8116. (pos (marker-position hdmarker))
  8117. (inhibit-read-only t)
  8118. newhead)
  8119. (org-with-remote-undo buffer
  8120. (with-current-buffer buffer
  8121. (widen)
  8122. (goto-char pos)
  8123. (save-excursion
  8124. (org-show-context 'agenda))
  8125. (save-excursion
  8126. (and (outline-next-heading)
  8127. (org-flag-heading nil))) ; show the next heading
  8128. (goto-char pos)
  8129. (call-interactively 'org-set-effort)
  8130. (end-of-line 1)
  8131. (setq newhead (org-get-heading)))
  8132. (org-agenda-change-all-lines newhead hdmarker))))
  8133. (defun org-agenda-toggle-archive-tag ()
  8134. "Toggle the archive tag for the current entry."
  8135. (interactive)
  8136. (org-agenda-check-no-diary)
  8137. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8138. (org-agenda-error)))
  8139. (buffer (marker-buffer hdmarker))
  8140. (pos (marker-position hdmarker))
  8141. (inhibit-read-only t)
  8142. newhead)
  8143. (org-with-remote-undo buffer
  8144. (with-current-buffer buffer
  8145. (widen)
  8146. (goto-char pos)
  8147. (org-show-context 'agenda)
  8148. (save-excursion
  8149. (and (outline-next-heading)
  8150. (org-flag-heading nil))) ; show the next heading
  8151. (call-interactively 'org-toggle-archive-tag)
  8152. (end-of-line 1)
  8153. (setq newhead (org-get-heading)))
  8154. (org-agenda-change-all-lines newhead hdmarker)
  8155. (beginning-of-line 1))))
  8156. (defun org-agenda-do-date-later (arg)
  8157. (interactive "P")
  8158. (cond
  8159. ((or (equal arg '(16))
  8160. (memq last-command
  8161. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8162. (setq this-command 'org-agenda-date-later-minutes)
  8163. (org-agenda-date-later-minutes 1))
  8164. ((or (equal arg '(4))
  8165. (memq last-command
  8166. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8167. (setq this-command 'org-agenda-date-later-hours)
  8168. (org-agenda-date-later-hours 1))
  8169. (t
  8170. (org-agenda-date-later (prefix-numeric-value arg)))))
  8171. (defun org-agenda-do-date-earlier (arg)
  8172. (interactive "P")
  8173. (cond
  8174. ((or (equal arg '(16))
  8175. (memq last-command
  8176. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8177. (setq this-command 'org-agenda-date-earlier-minutes)
  8178. (org-agenda-date-earlier-minutes 1))
  8179. ((or (equal arg '(4))
  8180. (memq last-command
  8181. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8182. (setq this-command 'org-agenda-date-earlier-hours)
  8183. (org-agenda-date-earlier-hours 1))
  8184. (t
  8185. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8186. (defun org-agenda-date-later (arg &optional what)
  8187. "Change the date of this item to ARG day(s) later."
  8188. (interactive "p")
  8189. (org-agenda-check-type t 'agenda 'timeline)
  8190. (org-agenda-check-no-diary)
  8191. (let* ((marker (or (org-get-at-bol 'org-marker)
  8192. (org-agenda-error)))
  8193. (buffer (marker-buffer marker))
  8194. (pos (marker-position marker))
  8195. cdate today)
  8196. (org-with-remote-undo buffer
  8197. (with-current-buffer buffer
  8198. (widen)
  8199. (goto-char pos)
  8200. (if (not (org-at-timestamp-p))
  8201. (error "Cannot find time stamp"))
  8202. (when (and org-agenda-move-date-from-past-immediately-to-today
  8203. (equal arg 1)
  8204. (or (not what) (eq what 'day))
  8205. (not (save-match-data (org-at-date-range-p))))
  8206. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8207. cdate (calendar-absolute-from-gregorian
  8208. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8209. today (org-today))
  8210. (if (> today cdate)
  8211. ;; immediately shift to today
  8212. (setq arg (- today cdate))))
  8213. (org-timestamp-change arg (or what 'day))
  8214. (when (and (org-at-date-range-p)
  8215. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8216. (let ((end org-last-changed-timestamp))
  8217. (org-timestamp-change arg (or what 'day))
  8218. (setq org-last-changed-timestamp
  8219. (concat org-last-changed-timestamp "--" end)))))
  8220. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8221. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8222. (defun org-agenda-date-earlier (arg &optional what)
  8223. "Change the date of this item to ARG day(s) earlier."
  8224. (interactive "p")
  8225. (org-agenda-date-later (- arg) what))
  8226. (defun org-agenda-date-later-minutes (arg)
  8227. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8228. (interactive "p")
  8229. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8230. (org-agenda-date-later arg 'minute))
  8231. (defun org-agenda-date-earlier-minutes (arg)
  8232. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8233. (interactive "p")
  8234. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8235. (org-agenda-date-earlier arg 'minute))
  8236. (defun org-agenda-date-later-hours (arg)
  8237. "Change the time of this item, in hour steps."
  8238. (interactive "p")
  8239. (org-agenda-date-later arg 'hour))
  8240. (defun org-agenda-date-earlier-hours (arg)
  8241. "Change the time of this item, in hour steps."
  8242. (interactive "p")
  8243. (org-agenda-date-earlier arg 'hour))
  8244. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8245. "Show new date stamp via text properties."
  8246. ;; We use text properties to make this undoable
  8247. (let ((inhibit-read-only t))
  8248. (setq stamp (concat prefix " => " stamp " "))
  8249. (save-excursion
  8250. (goto-char (point-max))
  8251. (while (not (bobp))
  8252. (when (equal marker (org-get-at-bol 'org-marker))
  8253. (org-move-to-column (- (window-width) (length stamp)) t)
  8254. (org-agenda-fix-tags-filter-overlays-at (point))
  8255. (if (featurep 'xemacs)
  8256. ;; Use `duplicable' property to trigger undo recording
  8257. (let ((ex (make-extent nil nil))
  8258. (gl (make-glyph stamp)))
  8259. (set-glyph-face gl 'secondary-selection)
  8260. (set-extent-properties
  8261. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8262. (insert-extent ex (1- (point)) (point-at-eol)))
  8263. (add-text-properties
  8264. (1- (point)) (point-at-eol)
  8265. (list 'display (org-add-props stamp nil
  8266. 'face 'secondary-selection))))
  8267. (beginning-of-line 1))
  8268. (beginning-of-line 0)))))
  8269. (defun org-agenda-date-prompt (arg)
  8270. "Change the date of this item. Date is prompted for, with default today.
  8271. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8272. be used to request time specification in the time stamp."
  8273. (interactive "P")
  8274. (org-agenda-check-type t 'agenda 'timeline)
  8275. (org-agenda-check-no-diary)
  8276. (let* ((marker (or (org-get-at-bol 'org-marker)
  8277. (org-agenda-error)))
  8278. (buffer (marker-buffer marker))
  8279. (pos (marker-position marker)))
  8280. (org-with-remote-undo buffer
  8281. (with-current-buffer buffer
  8282. (widen)
  8283. (goto-char pos)
  8284. (if (not (org-at-timestamp-p t))
  8285. (error "Cannot find time stamp"))
  8286. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8287. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8288. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8289. (defun org-agenda-schedule (arg &optional time)
  8290. "Schedule the item at point.
  8291. ARG is passed through to `org-schedule'."
  8292. (interactive "P")
  8293. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8294. (org-agenda-check-no-diary)
  8295. (let* ((marker (or (org-get-at-bol 'org-marker)
  8296. (org-agenda-error)))
  8297. (type (marker-insertion-type marker))
  8298. (buffer (marker-buffer marker))
  8299. (pos (marker-position marker))
  8300. (org-insert-labeled-timestamps-at-point nil)
  8301. ts)
  8302. (set-marker-insertion-type marker t)
  8303. (org-with-remote-undo buffer
  8304. (with-current-buffer buffer
  8305. (widen)
  8306. (goto-char pos)
  8307. (setq ts (org-schedule arg time)))
  8308. (org-agenda-show-new-time marker ts " S"))
  8309. (message "%s" ts)))
  8310. (defun org-agenda-deadline (arg &optional time)
  8311. "Schedule the item at point.
  8312. ARG is passed through to `org-deadline'."
  8313. (interactive "P")
  8314. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8315. (org-agenda-check-no-diary)
  8316. (let* ((marker (or (org-get-at-bol 'org-marker)
  8317. (org-agenda-error)))
  8318. (buffer (marker-buffer marker))
  8319. (pos (marker-position marker))
  8320. (org-insert-labeled-timestamps-at-point nil)
  8321. ts)
  8322. (org-with-remote-undo buffer
  8323. (with-current-buffer buffer
  8324. (widen)
  8325. (goto-char pos)
  8326. (setq ts (org-deadline arg time)))
  8327. (org-agenda-show-new-time marker ts " D"))
  8328. (message "%s" ts)))
  8329. (defun org-agenda-clock-in (&optional arg)
  8330. "Start the clock on the currently selected item."
  8331. (interactive "P")
  8332. (org-agenda-check-no-diary)
  8333. (if (equal arg '(4))
  8334. (org-clock-in arg)
  8335. (let* ((marker (or (org-get-at-bol 'org-marker)
  8336. (org-agenda-error)))
  8337. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8338. (pos (marker-position marker))
  8339. (col (current-column))
  8340. newhead)
  8341. (org-with-remote-undo (marker-buffer marker)
  8342. (with-current-buffer (marker-buffer marker)
  8343. (widen)
  8344. (goto-char pos)
  8345. (org-show-context 'agenda)
  8346. (org-show-entry)
  8347. (org-cycle-hide-drawers 'children)
  8348. (org-clock-in arg)
  8349. (setq newhead (org-get-heading)))
  8350. (org-agenda-change-all-lines newhead hdmarker))
  8351. (org-move-to-column col))))
  8352. (defun org-agenda-clock-out ()
  8353. "Stop the currently running clock."
  8354. (interactive)
  8355. (unless (marker-buffer org-clock-marker)
  8356. (error "No running clock"))
  8357. (let ((marker (make-marker)) (col (current-column)) newhead)
  8358. (org-with-remote-undo (marker-buffer org-clock-marker)
  8359. (with-current-buffer (marker-buffer org-clock-marker)
  8360. (save-excursion
  8361. (save-restriction
  8362. (widen)
  8363. (goto-char org-clock-marker)
  8364. (org-back-to-heading t)
  8365. (move-marker marker (point))
  8366. (org-clock-out)
  8367. (setq newhead (org-get-heading))))))
  8368. (org-agenda-change-all-lines newhead marker)
  8369. (move-marker marker nil)
  8370. (org-move-to-column col)
  8371. (org-agenda-unmark-clocking-task)))
  8372. (defun org-agenda-clock-cancel (&optional arg)
  8373. "Cancel the currently running clock."
  8374. (interactive "P")
  8375. (unless (marker-buffer org-clock-marker)
  8376. (error "No running clock"))
  8377. (org-with-remote-undo (marker-buffer org-clock-marker)
  8378. (org-clock-cancel)))
  8379. (defun org-agenda-clock-goto ()
  8380. "Jump to the currently clocked in task within the agenda.
  8381. If the currently clocked in task is not listed in the agenda
  8382. buffer, display it in another window."
  8383. (interactive)
  8384. (let (pos)
  8385. (mapc (lambda (o)
  8386. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8387. (setq pos (overlay-start o))))
  8388. (overlays-in (point-min) (point-max)))
  8389. (cond (pos (goto-char pos))
  8390. ;; If the currently clocked entry is not in the agenda
  8391. ;; buffer, we visit it in another window:
  8392. (org-clock-current-task
  8393. (org-switch-to-buffer-other-window (org-clock-goto)))
  8394. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8395. (defun org-agenda-diary-entry-in-org-file ()
  8396. "Make a diary entry in the file `org-agenda-diary-file'."
  8397. (let (d1 d2 char (text "") dp1 dp2)
  8398. (if (equal (buffer-name) "*Calendar*")
  8399. (setq d1 (calendar-cursor-to-date t)
  8400. d2 (car calendar-mark-ring))
  8401. (setq dp1 (get-text-property (point-at-bol) 'day))
  8402. (unless dp1 (error "No date defined in current line"))
  8403. (setq d1 (calendar-gregorian-from-absolute dp1)
  8404. d2 (and (ignore-errors (mark))
  8405. (save-excursion
  8406. (goto-char (mark))
  8407. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8408. (calendar-gregorian-from-absolute dp2))))
  8409. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8410. (setq char (read-char-exclusive))
  8411. (cond
  8412. ((equal char ?d)
  8413. (setq text (read-string "Day entry: "))
  8414. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8415. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8416. ((equal char ?a)
  8417. (setq d1 (list (car d1) (nth 1 d1)
  8418. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8419. (nth 2 d1))))
  8420. (setq text (read-string "Anniversary (use %d to show years): "))
  8421. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8422. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8423. ((equal char ?b)
  8424. (setq text (read-string "Block entry: "))
  8425. (unless (and d1 d2 (not (equal d1 d2)))
  8426. (error "No block of days selected"))
  8427. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8428. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8429. ((equal char ?j)
  8430. (org-switch-to-buffer-other-window
  8431. (find-file-noselect org-agenda-diary-file))
  8432. (require 'org-datetree)
  8433. (org-datetree-find-date-create d1)
  8434. (org-reveal t))
  8435. (t (error "Invalid selection character `%c'" char)))))
  8436. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8437. "Where in `org-agenda-diary-file' should new entries be added?
  8438. Valid values:
  8439. date-tree in the date tree, as child of the date
  8440. top-level as top-level entries at the end of the file."
  8441. :group 'org-agenda
  8442. :type '(choice
  8443. (const :tag "in a date tree" date-tree)
  8444. (const :tag "as top level at end of file" top-level)))
  8445. (defcustom org-agenda-insert-diary-extract-time nil
  8446. "Non-nil means extract any time specification from the diary entry."
  8447. :group 'org-agenda
  8448. :version "24.1"
  8449. :type 'boolean)
  8450. (defcustom org-agenda-bulk-mark-char ">"
  8451. "A single-character string to be used as the bulk mark."
  8452. :group 'org-agenda
  8453. :version "24.1"
  8454. :type 'string)
  8455. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8456. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8457. If TEXT is not empty, it will become the headline of the new entry, and
  8458. the resulting entry will not be shown. When TEXT is empty, switch to
  8459. `org-agenda-diary-file' and let the user finish the entry there."
  8460. (let ((cw (current-window-configuration)))
  8461. (org-switch-to-buffer-other-window
  8462. (find-file-noselect org-agenda-diary-file))
  8463. (widen)
  8464. (goto-char (point-min))
  8465. (cond
  8466. ((eq type 'anniversary)
  8467. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8468. (progn
  8469. (or (org-at-heading-p t)
  8470. (progn
  8471. (outline-next-heading)
  8472. (insert "* Anniversaries\n\n")
  8473. (beginning-of-line -1)))))
  8474. (outline-next-heading)
  8475. (org-back-over-empty-lines)
  8476. (backward-char 1)
  8477. (insert "\n")
  8478. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8479. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8480. ((eq type 'day)
  8481. (let ((org-prefix-has-time t)
  8482. (org-agenda-time-leading-zero t)
  8483. fmt time time2)
  8484. (if org-agenda-insert-diary-extract-time
  8485. ;; Use org-agenda-format-item to parse text for a time-range and
  8486. ;; remove it. FIXME: This is a hack, we should refactor
  8487. ;; that function to make time extraction available separately
  8488. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8489. time (get-text-property 0 'time fmt)
  8490. time2 (if (> (length time) 0)
  8491. ;; split-string removes trailing ...... if
  8492. ;; no end time given. First space
  8493. ;; separates time from date.
  8494. (concat " " (car (split-string time "\\.")))
  8495. nil)
  8496. text (get-text-property 0 'txt fmt)))
  8497. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8498. (org-agenda-insert-diary-as-top-level text)
  8499. (require 'org-datetree)
  8500. (org-datetree-find-date-create d1)
  8501. (org-agenda-insert-diary-make-new-entry text))
  8502. (org-insert-time-stamp (org-time-from-absolute
  8503. (calendar-absolute-from-gregorian d1))
  8504. nil nil nil nil time2))
  8505. (end-of-line 0))
  8506. ((eq type 'block)
  8507. (if (> (calendar-absolute-from-gregorian d1)
  8508. (calendar-absolute-from-gregorian d2))
  8509. (setq d1 (prog1 d2 (setq d2 d1))))
  8510. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8511. (org-agenda-insert-diary-as-top-level text)
  8512. (require 'org-datetree)
  8513. (org-datetree-find-date-create d1)
  8514. (org-agenda-insert-diary-make-new-entry text))
  8515. (org-insert-time-stamp (org-time-from-absolute
  8516. (calendar-absolute-from-gregorian d1)))
  8517. (insert "--")
  8518. (org-insert-time-stamp (org-time-from-absolute
  8519. (calendar-absolute-from-gregorian d2)))
  8520. (end-of-line 0)))
  8521. (if (string-match "\\S-" text)
  8522. (progn
  8523. (set-window-configuration cw)
  8524. (message "%s entry added to %s"
  8525. (capitalize (symbol-name type))
  8526. (abbreviate-file-name org-agenda-diary-file)))
  8527. (org-reveal t)
  8528. (message "Please finish entry here"))))
  8529. (defun org-agenda-insert-diary-as-top-level (text)
  8530. "Make new entry as a top-level entry at the end of the file.
  8531. Add TEXT as headline, and position the cursor in the second line so that
  8532. a timestamp can be added there."
  8533. (widen)
  8534. (goto-char (point-max))
  8535. (or (bolp) (insert "\n"))
  8536. (insert "* " text "\n")
  8537. (if org-adapt-indentation (org-indent-to-column 2)))
  8538. (defun org-agenda-insert-diary-make-new-entry (text)
  8539. "Make new entry as last child of current entry.
  8540. Add TEXT as headline, and position the cursor in the second line so that
  8541. a timestamp can be added there."
  8542. (let ((org-show-following-heading t)
  8543. (org-show-siblings t)
  8544. (org-show-hierarchy-above t)
  8545. (org-show-entry-below t)
  8546. col)
  8547. (outline-next-heading)
  8548. (org-back-over-empty-lines)
  8549. (or (looking-at "[ \t]*$")
  8550. (progn (insert "\n") (backward-char 1)))
  8551. (org-insert-heading nil t)
  8552. (org-do-demote)
  8553. (setq col (current-column))
  8554. (insert text "\n")
  8555. (if org-adapt-indentation (org-indent-to-column col))
  8556. (let ((org-show-following-heading t)
  8557. (org-show-siblings t)
  8558. (org-show-hierarchy-above t)
  8559. (org-show-entry-below t))
  8560. (org-show-context))))
  8561. (defun org-agenda-diary-entry ()
  8562. "Make a diary entry, like the `i' command from the calendar.
  8563. All the standard commands work: block, weekly etc.
  8564. When `org-agenda-diary-file' points to a file,
  8565. `org-agenda-diary-entry-in-org-file' is called instead to create
  8566. entries in that Org-mode file."
  8567. (interactive)
  8568. (if (not (eq org-agenda-diary-file 'diary-file))
  8569. (org-agenda-diary-entry-in-org-file)
  8570. (require 'diary-lib)
  8571. (let* ((char (progn
  8572. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8573. (read-char-exclusive)))
  8574. (cmd (cdr (assoc char
  8575. '((?d . insert-diary-entry)
  8576. (?w . insert-weekly-diary-entry)
  8577. (?m . insert-monthly-diary-entry)
  8578. (?y . insert-yearly-diary-entry)
  8579. (?a . insert-anniversary-diary-entry)
  8580. (?b . insert-block-diary-entry)
  8581. (?c . insert-cyclic-diary-entry)))))
  8582. (oldf (symbol-function 'calendar-cursor-to-date))
  8583. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8584. (point (point))
  8585. (mark (or (mark t) (point))))
  8586. (unless cmd
  8587. (error "No command associated with <%c>" char))
  8588. (unless (and (get-text-property point 'day)
  8589. (or (not (equal ?b char))
  8590. (get-text-property mark 'day)))
  8591. (error "Don't know which date to use for diary entry"))
  8592. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8593. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8594. (let ((calendar-mark-ring
  8595. (list (calendar-gregorian-from-absolute
  8596. (or (get-text-property mark 'day)
  8597. (get-text-property point 'day))))))
  8598. (unwind-protect
  8599. (progn
  8600. (fset 'calendar-cursor-to-date
  8601. (lambda (&optional error dummy)
  8602. (calendar-gregorian-from-absolute
  8603. (get-text-property point 'day))))
  8604. (call-interactively cmd))
  8605. (fset 'calendar-cursor-to-date oldf))))))
  8606. (defun org-agenda-execute-calendar-command (cmd)
  8607. "Execute a calendar command from the agenda with date from cursor."
  8608. (org-agenda-check-type t 'agenda 'timeline)
  8609. (require 'diary-lib)
  8610. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8611. (error "Don't know which date to use for the calendar command"))
  8612. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8613. (point (point))
  8614. (date (calendar-gregorian-from-absolute
  8615. (get-text-property point 'day)))
  8616. ;; the following 2 vars are needed in the calendar
  8617. (displayed-month (car date))
  8618. (displayed-year (nth 2 date)))
  8619. (unwind-protect
  8620. (progn
  8621. (fset 'calendar-cursor-to-date
  8622. (lambda (&optional error dummy)
  8623. (calendar-gregorian-from-absolute
  8624. (get-text-property point 'day))))
  8625. (call-interactively cmd))
  8626. (fset 'calendar-cursor-to-date oldf))))
  8627. (defun org-agenda-phases-of-moon ()
  8628. "Display the phases of the moon for the 3 months around the cursor date."
  8629. (interactive)
  8630. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8631. (defun org-agenda-holidays ()
  8632. "Display the holidays for the 3 months around the cursor date."
  8633. (interactive)
  8634. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8635. (defvar calendar-longitude) ; defined in calendar.el
  8636. (defvar calendar-latitude) ; defined in calendar.el
  8637. (defvar calendar-location-name) ; defined in calendar.el
  8638. (defun org-agenda-sunrise-sunset (arg)
  8639. "Display sunrise and sunset for the cursor date.
  8640. Latitude and longitude can be specified with the variables
  8641. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8642. argument, latitude and longitude will be prompted for."
  8643. (interactive "P")
  8644. (require 'solar)
  8645. (let ((calendar-longitude (if arg nil calendar-longitude))
  8646. (calendar-latitude (if arg nil calendar-latitude))
  8647. (calendar-location-name
  8648. (if arg "the given coordinates" calendar-location-name)))
  8649. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8650. (defun org-agenda-goto-calendar ()
  8651. "Open the Emacs calendar with the date at the cursor."
  8652. (interactive)
  8653. (org-agenda-check-type t 'agenda 'timeline)
  8654. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8655. (error "Don't know which date to open in calendar")))
  8656. (date (calendar-gregorian-from-absolute day))
  8657. (calendar-move-hook nil)
  8658. (calendar-view-holidays-initially-flag nil)
  8659. (calendar-view-diary-initially-flag nil))
  8660. (calendar)
  8661. (calendar-goto-date date)))
  8662. ;;;###autoload
  8663. (defun org-calendar-goto-agenda ()
  8664. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8665. This is a command that has to be installed in `calendar-mode-map'."
  8666. (interactive)
  8667. (org-agenda-list nil (calendar-absolute-from-gregorian
  8668. (calendar-cursor-to-date))
  8669. nil))
  8670. (defun org-agenda-convert-date ()
  8671. (interactive)
  8672. (org-agenda-check-type t 'agenda 'timeline)
  8673. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8674. date s)
  8675. (unless day
  8676. (error "Don't know which date to convert"))
  8677. (setq date (calendar-gregorian-from-absolute day))
  8678. (setq s (concat
  8679. "Gregorian: " (calendar-date-string date) "\n"
  8680. "ISO: " (calendar-iso-date-string date) "\n"
  8681. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8682. "Julian: " (calendar-julian-date-string date) "\n"
  8683. "Astron. JD: " (calendar-astro-date-string date)
  8684. " (Julian date number at noon UTC)\n"
  8685. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8686. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8687. "French: " (calendar-french-date-string date) "\n"
  8688. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8689. "Mayan: " (calendar-mayan-date-string date) "\n"
  8690. "Coptic: " (calendar-coptic-date-string date) "\n"
  8691. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8692. "Persian: " (calendar-persian-date-string date) "\n"
  8693. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8694. (with-output-to-temp-buffer "*Dates*"
  8695. (princ s))
  8696. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8697. ;;; Bulk commands
  8698. (defun org-agenda-bulk-marked-p ()
  8699. (eq (get-char-property (point-at-bol) 'type)
  8700. 'org-marked-entry-overlay))
  8701. (defun org-agenda-bulk-mark (&optional arg)
  8702. "Mark the entry at point for future bulk action."
  8703. (interactive "p")
  8704. (dotimes (i (or arg 1))
  8705. (unless (org-get-at-bol 'org-agenda-diary-link)
  8706. (let* ((m (org-get-at-bol 'org-hd-marker))
  8707. ov)
  8708. (unless (org-agenda-bulk-marked-p)
  8709. (unless m (error "Nothing to mark at point"))
  8710. (push m org-agenda-bulk-marked-entries)
  8711. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8712. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8713. (org-get-todo-face "TODO")
  8714. 'evaporate)
  8715. (overlay-put ov 'type 'org-marked-entry-overlay))
  8716. (beginning-of-line 2)
  8717. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8718. (beginning-of-line 2))
  8719. (message "%d entries marked for bulk action"
  8720. (length org-agenda-bulk-marked-entries))))))
  8721. (defun org-agenda-bulk-mark-all ()
  8722. "Mark all entries for future agenda bulk action."
  8723. (interactive)
  8724. (org-agenda-bulk-mark-regexp "."))
  8725. (defun org-agenda-bulk-mark-regexp (regexp)
  8726. "Mark entries matching REGEXP for future agenda bulk action."
  8727. (interactive "sMark entries matching regexp: ")
  8728. (let ((entries-marked 0))
  8729. (save-excursion
  8730. (goto-char (point-min))
  8731. (goto-char (next-single-property-change (point) 'txt))
  8732. (while (re-search-forward regexp nil t)
  8733. (when (string-match regexp (get-text-property (point) 'txt))
  8734. (setq entries-marked (1+ entries-marked))
  8735. (call-interactively 'org-agenda-bulk-mark))))
  8736. (if (not entries-marked)
  8737. (message "No entry matching this regexp."))))
  8738. (defun org-agenda-bulk-unmark (&optional arg)
  8739. "Unmark the entry at point for future bulk action."
  8740. (interactive "P")
  8741. (if arg
  8742. (org-agenda-bulk-unmark-all)
  8743. (cond ((org-agenda-bulk-marked-p)
  8744. (org-agenda-bulk-remove-overlays
  8745. (point-at-bol) (+ 2 (point-at-bol)))
  8746. (setq org-agenda-bulk-marked-entries
  8747. (delete (org-get-at-bol 'org-hd-marker)
  8748. org-agenda-bulk-marked-entries))
  8749. (beginning-of-line 2)
  8750. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8751. (beginning-of-line 2))
  8752. (message "%d entries left marked for bulk action"
  8753. (length org-agenda-bulk-marked-entries)))
  8754. (t (message "No entry to unmark here")))))
  8755. (defun org-agenda-bulk-toggle ()
  8756. "Toggle marking the entry at point for bulk action."
  8757. (interactive)
  8758. (if (org-agenda-bulk-marked-p)
  8759. (org-agenda-bulk-unmark)
  8760. (org-agenda-bulk-mark)))
  8761. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8762. "Remove the mark overlays between BEG and END in the agenda buffer.
  8763. BEG and END default to the buffer limits.
  8764. This only removes the overlays, it does not remove the markers
  8765. from the list in `org-agenda-bulk-marked-entries'."
  8766. (interactive)
  8767. (mapc (lambda (ov)
  8768. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8769. (delete-overlay ov)))
  8770. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8771. (defun org-agenda-bulk-unmark-all ()