org-agenda.el 377 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770
  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 timestamp-up) (const timestamp-down)
  215. (const scheduled-up) (const scheduled-down)
  216. (const deadline-up) (const deadline-down)
  217. (const ts-up) (const ts-down)
  218. (const tsia-up) (const tsia-down)
  219. (const category-keep) (const category-up) (const category-down)
  220. (const tag-down) (const tag-up)
  221. (const priority-up) (const priority-down)
  222. (const todo-state-up) (const todo-state-down)
  223. (const effort-up) (const effort-down)
  224. (const habit-up) (const habit-down)
  225. (const alpha-up) (const alpha-down)
  226. (const user-defined-up) (const user-defined-down))
  227. "Sorting choices.")
  228. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  229. ;; the new variable `org-agenda-tag-filter-preset'.
  230. (if (fboundp 'defvaralias)
  231. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  232. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  233. (defconst org-agenda-custom-commands-local-options
  234. `(repeat :tag "Local settings for this command. Remember to quote values"
  235. (choice :tag "Setting"
  236. (list :tag "Heading for this block"
  237. (const org-agenda-overriding-header)
  238. (string :tag "Headline"))
  239. (list :tag "Files to be searched"
  240. (const org-agenda-files)
  241. (list
  242. (const :format "" quote)
  243. (repeat (file))))
  244. (list :tag "Sorting strategy"
  245. (const org-agenda-sorting-strategy)
  246. (list
  247. (const :format "" quote)
  248. (repeat
  249. ,org-sorting-choice)))
  250. (list :tag "Prefix format"
  251. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  252. (string))
  253. (list :tag "Number of days in agenda"
  254. (const org-agenda-span)
  255. (choice (const :tag "Day" 'day)
  256. (const :tag "Week" 'week)
  257. (const :tag "Month" 'month)
  258. (const :tag "Year" 'year)
  259. (integer :tag "Custom")))
  260. (list :tag "Fixed starting date"
  261. (const org-agenda-start-day)
  262. (string :value "2007-11-01"))
  263. (list :tag "Start on day of week"
  264. (const org-agenda-start-on-weekday)
  265. (choice :value 1
  266. (const :tag "Today" nil)
  267. (integer :tag "Weekday No.")))
  268. (list :tag "Include data from diary"
  269. (const org-agenda-include-diary)
  270. (boolean))
  271. (list :tag "Deadline Warning days"
  272. (const org-deadline-warning-days)
  273. (integer :value 1))
  274. (list :tag "Category filter preset"
  275. (const org-agenda-category-filter-preset)
  276. (list
  277. (const :format "" quote)
  278. (repeat
  279. (string :tag "+category or -category"))))
  280. (list :tag "Tags filter preset"
  281. (const org-agenda-tag-filter-preset)
  282. (list
  283. (const :format "" quote)
  284. (repeat
  285. (string :tag "+tag or -tag"))))
  286. (list :tag "Set daily/weekly entry types"
  287. (const org-agenda-entry-types)
  288. (list
  289. (const :format "" quote)
  290. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  291. (const :deadline)
  292. (const :scheduled)
  293. (const :timestamp)
  294. (const :sexp))))
  295. (list :tag "Standard skipping condition"
  296. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  297. (const org-agenda-skip-function)
  298. (list
  299. (const :format "" quote)
  300. (list
  301. (choice
  302. :tag "Skipping range"
  303. (const :tag "Skip entry" org-agenda-skip-entry-if)
  304. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  305. (repeat :inline t :tag "Conditions for skipping"
  306. (choice
  307. :tag "Condition type"
  308. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  309. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  310. (list :tag "TODO state is" :inline t
  311. (const 'todo)
  312. (choice
  313. (const :tag "any not-done state" 'todo)
  314. (const :tag "any done state" 'done)
  315. (const :tag "any state" 'any)
  316. (list :tag "Keyword list"
  317. (const :format "" quote)
  318. (repeat (string :tag "Keyword")))))
  319. (list :tag "TODO state is not" :inline t
  320. (const 'nottodo)
  321. (choice
  322. (const :tag "any not-done state" 'todo)
  323. (const :tag "any done state" 'done)
  324. (const :tag "any state" 'any)
  325. (list :tag "Keyword list"
  326. (const :format "" quote)
  327. (repeat (string :tag "Keyword")))))
  328. (const :tag "scheduled" 'scheduled)
  329. (const :tag "not scheduled" 'notscheduled)
  330. (const :tag "deadline" 'deadline)
  331. (const :tag "no deadline" 'notdeadline)
  332. (const :tag "timestamp" 'timestamp)
  333. (const :tag "no timestamp" 'nottimestamp))))))
  334. (list :tag "Non-standard skipping condition"
  335. :value (org-agenda-skip-function)
  336. (const org-agenda-skip-function)
  337. (sexp :tag "Function or form (quoted!)"))
  338. (list :tag "Any variable"
  339. (variable :tag "Variable")
  340. (sexp :tag "Value (sexp)"))))
  341. "Selection of examples for agenda command settings.
  342. This will be spliced into the custom type of
  343. `org-agenda-custom-commands'.")
  344. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  345. ((agenda "") (alltodo))))
  346. "Custom commands for the agenda.
  347. These commands will be offered on the splash screen displayed by the
  348. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  349. (key desc type match settings files)
  350. key The key (one or more characters as a string) to be associated
  351. with the command.
  352. desc A description of the command, when omitted or nil, a default
  353. description is built using MATCH.
  354. type The command type, any of the following symbols:
  355. agenda The daily/weekly agenda.
  356. todo Entries with a specific TODO keyword, in all agenda files.
  357. search Entries containing search words entry or headline.
  358. tags Tags/Property/TODO match in all agenda files.
  359. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  360. todo-tree Sparse tree of specific TODO keyword in *current* file.
  361. tags-tree Sparse tree with all tags matches in *current* file.
  362. occur-tree Occur sparse tree for *current* file.
  363. ... A user-defined function.
  364. match What to search for:
  365. - a single keyword for TODO keyword searches
  366. - a tags match expression for tags searches
  367. - a word search expression for text searches.
  368. - a regular expression for occur searches
  369. For all other commands, this should be the empty string.
  370. settings A list of option settings, similar to that in a let form, so like
  371. this: ((opt1 val1) (opt2 val2) ...). The values will be
  372. evaluated at the moment of execution, so quote them when needed.
  373. files A list of files file to write the produced agenda buffer to
  374. with the command `org-store-agenda-views'.
  375. If a file name ends in \".html\", an HTML version of the buffer
  376. is written out. If it ends in \".ps\", a postscript version is
  377. produced. Otherwise, only the plain text is written to the file.
  378. You can also define a set of commands, to create a composite agenda buffer.
  379. In this case, an entry looks like this:
  380. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  381. where
  382. desc A description string to be displayed in the dispatcher menu.
  383. cmd An agenda command, similar to the above. However, tree commands
  384. are not allowed, but instead you can get agenda and global todo list.
  385. So valid commands for a set are:
  386. (agenda \"\" settings)
  387. (alltodo \"\" settings)
  388. (stuck \"\" settings)
  389. (todo \"match\" settings files)
  390. (search \"match\" settings files)
  391. (tags \"match\" settings files)
  392. (tags-todo \"match\" settings files)
  393. Each command can carry a list of options, and another set of options can be
  394. given for the whole set of commands. Individual command options take
  395. precedence over the general options.
  396. When using several characters as key to a command, the first characters
  397. are prefix commands. For the dispatcher to display useful information, you
  398. should provide a description for the prefix, like
  399. (setq org-agenda-custom-commands
  400. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  401. (\"hl\" tags \"+HOME+Lisa\")
  402. (\"hp\" tags \"+HOME+Peter\")
  403. (\"hk\" tags \"+HOME+Kim\")))"
  404. :group 'org-agenda-custom-commands
  405. :type `(repeat
  406. (choice :value ("x" "Describe command here" tags "" nil)
  407. (list :tag "Single command"
  408. (string :tag "Access Key(s) ")
  409. (option (string :tag "Description"))
  410. (choice
  411. (const :tag "Agenda" agenda)
  412. (const :tag "TODO list" alltodo)
  413. (const :tag "Search words" search)
  414. (const :tag "Stuck projects" stuck)
  415. (const :tag "Tags/Property match (all agenda files)" tags)
  416. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  417. (const :tag "TODO keyword search (all agenda files)" todo)
  418. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  419. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  420. (const :tag "Occur tree (current buffer)" occur-tree)
  421. (sexp :tag "Other, user-defined function"))
  422. (string :tag "Match (only for some commands)")
  423. ,org-agenda-custom-commands-local-options
  424. (option (repeat :tag "Export" (file :tag "Export to"))))
  425. (list :tag "Command series, all agenda files"
  426. (string :tag "Access Key(s)")
  427. (string :tag "Description ")
  428. (repeat :tag "Component"
  429. (choice
  430. (list :tag "Agenda"
  431. (const :format "" agenda)
  432. (const :tag "" :format "" "")
  433. ,org-agenda-custom-commands-local-options)
  434. (list :tag "TODO list (all keywords)"
  435. (const :format "" alltodo)
  436. (const :tag "" :format "" "")
  437. ,org-agenda-custom-commands-local-options)
  438. (list :tag "Search words"
  439. (const :format "" search)
  440. (string :tag "Match")
  441. ,org-agenda-custom-commands-local-options)
  442. (list :tag "Stuck projects"
  443. (const :format "" stuck)
  444. (const :tag "" :format "" "")
  445. ,org-agenda-custom-commands-local-options)
  446. (list :tag "Tags search"
  447. (const :format "" tags)
  448. (string :tag "Match")
  449. ,org-agenda-custom-commands-local-options)
  450. (list :tag "Tags search, TODO entries only"
  451. (const :format "" tags-todo)
  452. (string :tag "Match")
  453. ,org-agenda-custom-commands-local-options)
  454. (list :tag "TODO keyword search"
  455. (const :format "" todo)
  456. (string :tag "Match")
  457. ,org-agenda-custom-commands-local-options)
  458. (list :tag "Other, user-defined function"
  459. (symbol :tag "function")
  460. (string :tag "Match")
  461. ,org-agenda-custom-commands-local-options)))
  462. (repeat :tag "Settings for entire command set"
  463. (list (variable :tag "Any variable")
  464. (sexp :tag "Value")))
  465. (option (repeat :tag "Export" (file :tag "Export to"))))
  466. (cons :tag "Prefix key documentation"
  467. (string :tag "Access Key(s)")
  468. (string :tag "Description ")))))
  469. (defcustom org-agenda-query-register ?o
  470. "The register holding the current query string.
  471. The purpose of this is that if you construct a query string interactively,
  472. you can then use it to define a custom command."
  473. :group 'org-agenda-custom-commands
  474. :type 'character)
  475. (defcustom org-stuck-projects
  476. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  477. "How to identify stuck projects.
  478. This is a list of four items:
  479. 1. A tags/todo/property matcher string that is used to identify a project.
  480. See the manual for a description of tag and property searches.
  481. The entire tree below a headline matched by this is considered one project.
  482. 2. A list of TODO keywords identifying non-stuck projects.
  483. If the project subtree contains any headline with one of these todo
  484. keywords, the project is considered to be not stuck. If you specify
  485. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  486. 3. A list of tags identifying non-stuck projects.
  487. If the project subtree contains any headline with one of these tags,
  488. the project is considered to be not stuck. If you specify \"*\" as
  489. a tag, any tag will mark the project unstuck. Note that this is about
  490. the explicit presence of a tag somewhere in the subtree, inherited
  491. tags do not count here. If inherited tags make a project not stuck,
  492. use \"-TAG\" in the tags part of the matcher under (1.) above.
  493. 4. An arbitrary regular expression matching non-stuck projects.
  494. If the project turns out to be not stuck, search continues also in the
  495. subtree to see if any of the subtasks have project status.
  496. See also the variable `org-tags-match-list-sublevels' which applies
  497. to projects matched by this search as well.
  498. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  499. or `C-c a #' to produce the list."
  500. :group 'org-agenda-custom-commands
  501. :type '(list
  502. (string :tag "Tags/TODO match to identify a project")
  503. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  504. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  505. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  506. (defcustom org-agenda-filter-effort-default-operator "<"
  507. "The default operator for effort estimate filtering.
  508. If you select an effort estimate limit without first pressing an operator,
  509. this one will be used."
  510. :group 'org-agenda-custom-commands
  511. :type '(choice (const :tag "less or equal" "<")
  512. (const :tag "greater or equal"">")
  513. (const :tag "equal" "=")))
  514. (defgroup org-agenda-skip nil
  515. "Options concerning skipping parts of agenda files."
  516. :tag "Org Agenda Skip"
  517. :group 'org-agenda)
  518. (defcustom org-agenda-skip-function-global nil
  519. "Function to be called at each match during agenda construction.
  520. If this function returns nil, the current match should not be skipped.
  521. If the function decided to skip an agenda match, is must return the
  522. buffer position from which the search should be continued.
  523. This may also be a Lisp form, which will be evaluated.
  524. This variable will be applied to every agenda match, including
  525. tags/property searches and TODO lists. So try to make the test function
  526. do its checking as efficiently as possible. To implement a skipping
  527. condition just for specific agenda commands, use the variable
  528. `org-agenda-skip-function' which can be set in the options section
  529. of custom agenda commands."
  530. :group 'org-agenda-skip
  531. :type 'sexp)
  532. (defgroup org-agenda-daily/weekly nil
  533. "Options concerning the daily/weekly agenda."
  534. :tag "Org Agenda Daily/Weekly"
  535. :group 'org-agenda)
  536. (defgroup org-agenda-todo-list nil
  537. "Options concerning the global todo list agenda view."
  538. :tag "Org Agenda Todo List"
  539. :group 'org-agenda)
  540. (defgroup org-agenda-match-view nil
  541. "Options concerning the general tags/property/todo match agenda view."
  542. :tag "Org Agenda Match View"
  543. :group 'org-agenda)
  544. (defgroup org-agenda-search-view nil
  545. "Options concerning the general tags/property/todo match agenda view."
  546. :tag "Org Agenda Match View"
  547. :group 'org-agenda)
  548. (defvar org-agenda-archives-mode nil
  549. "Non-nil means the agenda will include archived items.
  550. If this is the symbol `trees', trees in the selected agenda scope
  551. that are marked with the ARCHIVE tag will be included anyway. When this is
  552. t, also all archive files associated with the current selection of agenda
  553. files will be included.")
  554. (defcustom org-agenda-skip-comment-trees t
  555. "Non-nil means skip trees that start with the COMMENT keyword.
  556. When nil, these trees are also scanned by agenda commands."
  557. :group 'org-agenda-skip
  558. :type 'boolean)
  559. (defcustom org-agenda-todo-list-sublevels t
  560. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  561. When nil, the sublevels of a TODO entry are not checked, resulting in
  562. potentially much shorter TODO lists."
  563. :group 'org-agenda-skip
  564. :group 'org-agenda-todo-list
  565. :type 'boolean)
  566. (defcustom org-agenda-todo-ignore-with-date nil
  567. "Non-nil means don't show entries with a date in the global todo list.
  568. You can use this if you prefer to mark mere appointments with a TODO keyword,
  569. but don't want them to show up in the TODO list.
  570. When this is set, it also covers deadlines and scheduled items, the settings
  571. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  572. will be ignored.
  573. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  574. :group 'org-agenda-skip
  575. :group 'org-agenda-todo-list
  576. :type 'boolean)
  577. (defcustom org-agenda-todo-ignore-timestamp nil
  578. "Non-nil means don't show entries with a timestamp.
  579. This applies when creating the global todo list.
  580. Valid values are:
  581. past Don't show entries for today or in the past.
  582. future Don't show entries with a timestamp in the future.
  583. The idea behind this is that if it has a future
  584. timestamp, you don't want to think about it until the
  585. date.
  586. all Don't show any entries with a timestamp in the global todo list.
  587. The idea behind this is that by setting a timestamp, you
  588. have already \"taken care\" of this item.
  589. This variable can also have an integer as a value. If positive (N),
  590. todos with a timestamp N or more days in the future will be ignored. If
  591. negative (-N), todos with a timestamp N or more days in the past will be
  592. ignored. If 0, todos with a timestamp either today or in the future will
  593. be ignored. For example, a value of -1 will exclude todos with a
  594. timestamp in the past (yesterday or earlier), while a value of 7 will
  595. exclude todos with a timestamp a week or more in the future.
  596. See also `org-agenda-todo-ignore-with-date'.
  597. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  598. to make his option also apply to the tags-todo list."
  599. :group 'org-agenda-skip
  600. :group 'org-agenda-todo-list
  601. :version "24.1"
  602. :type '(choice
  603. (const :tag "Ignore future timestamp todos" future)
  604. (const :tag "Ignore past or present timestamp todos" past)
  605. (const :tag "Ignore all timestamp todos" all)
  606. (const :tag "Show timestamp todos" nil)
  607. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  608. (defcustom org-agenda-todo-ignore-scheduled nil
  609. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  610. This applies when creating the global todo list.
  611. Valid values are:
  612. past Don't show entries scheduled today or in the past.
  613. future Don't show entries scheduled in the future.
  614. The idea behind this is that by scheduling it, you don't want to
  615. think about it until the scheduled date.
  616. all Don't show any scheduled entries in the global todo list.
  617. The idea behind this is that by scheduling it, you have already
  618. \"taken care\" of this item.
  619. t Same as `all', for backward compatibility.
  620. This variable can also have an integer as a value. See
  621. `org-agenda-todo-ignore-timestamp' for more details.
  622. See also `org-agenda-todo-ignore-with-date'.
  623. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  624. to make his option also apply to the tags-todo list."
  625. :group 'org-agenda-skip
  626. :group 'org-agenda-todo-list
  627. :type '(choice
  628. (const :tag "Ignore future-scheduled todos" future)
  629. (const :tag "Ignore past- or present-scheduled todos" past)
  630. (const :tag "Ignore all scheduled todos" all)
  631. (const :tag "Ignore all scheduled todos (compatibility)" t)
  632. (const :tag "Show scheduled todos" nil)
  633. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  634. (defcustom org-agenda-todo-ignore-deadlines nil
  635. "Non-nil means ignore some deadlined TODO items when making TODO list.
  636. There are different motivations for using different values, please think
  637. carefully when configuring this variable.
  638. This applies when creating the global todo list.
  639. Valid values are:
  640. near Don't show near deadline entries. A deadline is near when it is
  641. closer than `org-deadline-warning-days' days. The idea behind this
  642. is that such items will appear in the agenda anyway.
  643. far Don't show TODO entries where a deadline has been defined, but
  644. the deadline is not near. This is useful if you don't want to
  645. use the todo list to figure out what to do now.
  646. past Don't show entries with a deadline timestamp for today or in the past.
  647. future Don't show entries with a deadline timestamp in the future, not even
  648. when they become `near' ones. Use it with caution.
  649. all Ignore all TODO entries that do have a deadline.
  650. t Same as `near', for backward compatibility.
  651. This variable can also have an integer as a value. See
  652. `org-agenda-todo-ignore-timestamp' for more details.
  653. See also `org-agenda-todo-ignore-with-date'.
  654. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  655. to make his option also apply to the tags-todo list."
  656. :group 'org-agenda-skip
  657. :group 'org-agenda-todo-list
  658. :type '(choice
  659. (const :tag "Ignore near deadlines" near)
  660. (const :tag "Ignore near deadlines (compatibility)" t)
  661. (const :tag "Ignore far deadlines" far)
  662. (const :tag "Ignore all TODOs with a deadlines" all)
  663. (const :tag "Show all TODOs, even if they have a deadline" nil)
  664. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  665. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  666. "Time unit to use when possibly ignoring an agenda item.
  667. See the docstring of various `org-agenda-todo-ignore-*' options.
  668. The default is to compare time stamps using days. An item is thus
  669. considered to be in the future if it is at least one day after today.
  670. Non-nil means to compare time stamps using seconds. An item is then
  671. considered future if it has a time value later than current time."
  672. :group 'org-agenda-skip
  673. :group 'org-agenda-todo-list
  674. :version "24.4"
  675. :package-version '(Org . "8.0")
  676. :type '(choice
  677. (const :tag "Compare time with days" nil)
  678. (const :tag "Compare time with seconds" t)))
  679. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  680. "Non-nil means honor todo-list ignores options also in tags-todo search.
  681. The variables
  682. `org-agenda-todo-ignore-with-date',
  683. `org-agenda-todo-ignore-timestamp',
  684. `org-agenda-todo-ignore-scheduled',
  685. `org-agenda-todo-ignore-deadlines'
  686. make the global TODO list skip entries that have time stamps of certain
  687. kinds. If this option is set, the same options will also apply for the
  688. tags-todo search, which is the general tags/property matcher
  689. restricted to unfinished TODO entries only."
  690. :group 'org-agenda-skip
  691. :group 'org-agenda-todo-list
  692. :group 'org-agenda-match-view
  693. :type 'boolean)
  694. (defcustom org-agenda-skip-scheduled-if-done nil
  695. "Non-nil means don't show scheduled items in agenda when they are done.
  696. This is relevant for the daily/weekly agenda, not for the TODO list. And
  697. it applies only to the actual date of the scheduling. Warnings about
  698. an item with a past scheduling dates are always turned off when the item
  699. is DONE."
  700. :group 'org-agenda-skip
  701. :group 'org-agenda-daily/weekly
  702. :type 'boolean)
  703. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  704. "Non-nil means skip scheduling line if same entry shows because of deadline.
  705. In the agenda of today, an entry can show up multiple times
  706. because it is both scheduled and has a nearby deadline, and maybe
  707. a plain time stamp as well.
  708. When this variable is nil, the entry will be shown several times.
  709. When set to t, then only the deadline is shown and the fact that
  710. the entry is scheduled today or was scheduled previously is not
  711. shown.
  712. When set to the symbol `not-today', skip scheduled previously,
  713. but not scheduled today.
  714. When set to the symbol `repeated-after-deadline', skip scheduled
  715. items if they are repeated beyond the current dealine."
  716. :group 'org-agenda-skip
  717. :group 'org-agenda-daily/weekly
  718. :type '(choice
  719. (const :tag "Never" nil)
  720. (const :tag "Always" t)
  721. (const :tag "Not when scheduled today" not-today)
  722. (const :tag "When repeated past deadline" repeated-after-deadline)))
  723. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  724. "Non-nil means skip timestamp line if same entry shows because of deadline.
  725. In the agenda of today, an entry can show up multiple times
  726. because it has both a plain timestamp and has a nearby deadline.
  727. When this variable is t, then only the deadline is shown and the
  728. fact that the entry has a timestamp for or including today is not
  729. shown. When this variable is nil, the entry will be shown
  730. several times."
  731. :group 'org-agenda-skip
  732. :group 'org-agenda-daily/weekly
  733. :version "24.1"
  734. :type '(choice
  735. (const :tag "Never" nil)
  736. (const :tag "Always" t)))
  737. (defcustom org-agenda-skip-deadline-if-done nil
  738. "Non-nil means don't show deadlines when the corresponding item is done.
  739. When nil, the deadline is still shown and should give you a happy feeling.
  740. This is relevant for the daily/weekly agenda. And it applied only to the
  741. actually date of the deadline. Warnings about approaching and past-due
  742. deadlines are always turned off when the item is DONE."
  743. :group 'org-agenda-skip
  744. :group 'org-agenda-daily/weekly
  745. :type 'boolean)
  746. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  747. "Non-nil means skip deadline prewarning when entry is also scheduled.
  748. This will apply on all days where a prewarning for the deadline would
  749. be shown, but not at the day when the entry is actually due. On that day,
  750. the deadline will be shown anyway.
  751. This variable may be set to nil, t, the symbol `pre-scheduled',
  752. or a number which will then give the number of days before the actual
  753. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  754. eliminates the deadline prewarning only prior to the scheduled date.
  755. This can be used in a workflow where the first showing of the deadline will
  756. trigger you to schedule it, and then you don't want to be reminded of it
  757. because you will take care of it on the day when scheduled."
  758. :group 'org-agenda-skip
  759. :group 'org-agenda-daily/weekly
  760. :version "24.1"
  761. :type '(choice
  762. (const :tag "Always show prewarning" nil)
  763. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  764. (const :tag "Remove prewarning if entry is scheduled" t)
  765. (integer :tag "Restart prewarning N days before deadline")))
  766. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  767. "Non-nil means skip scheduled delay when entry also has a deadline.
  768. This variable may be set to nil, t, the symbol `post-deadline',
  769. or a number which will then give the number of days after the actual
  770. scheduled date when the delay should expire. The symbol `post-deadline'
  771. eliminates the schedule delay when the date is posterior to the deadline."
  772. :group 'org-agenda-skip
  773. :group 'org-agenda-daily/weekly
  774. :version "24.4"
  775. :package-version '(Org . "8.0")
  776. :type '(choice
  777. (const :tag "Always honor delay" nil)
  778. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  779. (const :tag "Ignore delay if entry has a deadline" t)
  780. (integer :tag "Honor delay up until N days after the scheduled date")))
  781. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  782. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  783. When non-nil, after the search for timestamps has matched once in an
  784. entry, the rest of the entry will not be searched."
  785. :group 'org-agenda-skip
  786. :type 'boolean)
  787. (defcustom org-agenda-skip-timestamp-if-done nil
  788. "Non-nil means don't select item by timestamp or -range if it is DONE."
  789. :group 'org-agenda-skip
  790. :group 'org-agenda-daily/weekly
  791. :type 'boolean)
  792. (defcustom org-agenda-dim-blocked-tasks t
  793. "Non-nil means dim blocked tasks in the agenda display.
  794. This causes some overhead during agenda construction, but if you
  795. have turned on `org-enforce-todo-dependencies',
  796. `org-enforce-todo-checkbox-dependencies', or any other blocking
  797. mechanism, this will create useful feedback in the agenda.
  798. Instead of t, this variable can also have the value `invisible'.
  799. Then blocked tasks will be invisible and only become visible when
  800. they become unblocked. An exemption to this behavior is when a task is
  801. blocked because of unchecked checkboxes below it. Since checkboxes do
  802. not show up in the agenda views, making this task invisible you remove any
  803. trace from agenda views that there is something to do. Therefore, a task
  804. that is blocked because of checkboxes will never be made invisible, it
  805. will only be dimmed."
  806. :group 'org-agenda-daily/weekly
  807. :group 'org-agenda-todo-list
  808. :version "24.3"
  809. :type '(choice
  810. (const :tag "Do not dim" nil)
  811. (const :tag "Dim to a gray face" t)
  812. (const :tag "Make invisible" invisible)))
  813. (defcustom org-timeline-show-empty-dates 3
  814. "Non-nil means `org-timeline' also shows dates without an entry.
  815. When nil, only the days which actually have entries are shown.
  816. When t, all days between the first and the last date are shown.
  817. When an integer, show also empty dates, but if there is a gap of more than
  818. N days, just insert a special line indicating the size of the gap."
  819. :group 'org-agenda-skip
  820. :type '(choice
  821. (const :tag "None" nil)
  822. (const :tag "All" t)
  823. (integer :tag "at most")))
  824. (defgroup org-agenda-startup nil
  825. "Options concerning initial settings in the Agenda in Org Mode."
  826. :tag "Org Agenda Startup"
  827. :group 'org-agenda)
  828. (defcustom org-agenda-menu-show-matcher t
  829. "Non-nil means show the match string in the agenda dispatcher menu.
  830. When nil, the matcher string is not shown, but is put into the help-echo
  831. property so than moving the mouse over the command shows it.
  832. Setting it to nil is good if matcher strings are very long and/or if
  833. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  834. :group 'org-agenda
  835. :version "24.1"
  836. :type 'boolean)
  837. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  838. (defcustom org-agenda-menu-two-columns nil
  839. "Non-nil means, use two columns to show custom commands in the dispatcher.
  840. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  841. to nil."
  842. :group 'org-agenda
  843. :version "24.1"
  844. :type 'boolean)
  845. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  846. (defcustom org-agenda-finalize-hook nil
  847. "Hook run just before displaying an agenda buffer.
  848. The buffer is still writable when the hook is called.
  849. You can modify some of the buffer substrings but you should be
  850. extra careful not to modify the text properties of the agenda
  851. headlines as the agenda display heavily relies on them."
  852. :group 'org-agenda-startup
  853. :type 'hook)
  854. (defcustom org-agenda-mouse-1-follows-link nil
  855. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  856. A longer mouse click will still set point. Does not work on XEmacs.
  857. Needs to be set before org.el is loaded."
  858. :group 'org-agenda-startup
  859. :type 'boolean)
  860. (defcustom org-agenda-start-with-follow-mode nil
  861. "The initial value of follow mode in a newly created agenda window."
  862. :group 'org-agenda-startup
  863. :type 'boolean)
  864. (defcustom org-agenda-follow-indirect nil
  865. "Non-nil means `org-agenda-follow-mode' displays only the
  866. current item's tree, in an indirect buffer."
  867. :group 'org-agenda
  868. :version "24.1"
  869. :type 'boolean)
  870. (defcustom org-agenda-show-outline-path t
  871. "Non-nil means show outline path in echo area after line motion."
  872. :group 'org-agenda-startup
  873. :type 'boolean)
  874. (defcustom org-agenda-start-with-entry-text-mode nil
  875. "The initial value of entry-text-mode in a newly created agenda window."
  876. :group 'org-agenda-startup
  877. :type 'boolean)
  878. (defcustom org-agenda-entry-text-maxlines 5
  879. "Number of text lines to be added when `E' is pressed in the agenda.
  880. Note that this variable only used during agenda display. Add add entry text
  881. when exporting the agenda, configure the variable
  882. `org-agenda-add-entry-ext-maxlines'."
  883. :group 'org-agenda
  884. :type 'integer)
  885. (defcustom org-agenda-entry-text-exclude-regexps nil
  886. "List of regular expressions to clean up entry text.
  887. The complete matches of all regular expressions in this list will be
  888. removed from entry text before it is shown in the agenda."
  889. :group 'org-agenda
  890. :type '(repeat (regexp)))
  891. (defcustom org-agenda-entry-text-leaders " > "
  892. "Text prepended to the entry text in agenda buffers."
  893. :version "24.4"
  894. :package-version '(Org . "8.0")
  895. :group 'org-agenda
  896. :type 'string)
  897. (defvar org-agenda-entry-text-cleanup-hook nil
  898. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  899. This cleanup is done in a temporary buffer, so the function may inspect and
  900. change the entire buffer.
  901. Some default stuff like drawers and scheduling/deadline dates will already
  902. have been removed when this is called, as will any matches for regular
  903. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  904. (defvar org-agenda-include-inactive-timestamps nil
  905. "Non-nil means include inactive time stamps in agenda and timeline.
  906. Dynamically scoped.")
  907. (defgroup org-agenda-windows nil
  908. "Options concerning the windows used by the Agenda in Org Mode."
  909. :tag "Org Agenda Windows"
  910. :group 'org-agenda)
  911. (defcustom org-agenda-window-setup 'reorganize-frame
  912. "How the agenda buffer should be displayed.
  913. Possible values for this option are:
  914. current-window Show agenda in the current window, keeping all other windows.
  915. other-window Use `switch-to-buffer-other-window' to display agenda.
  916. reorganize-frame Show only two windows on the current frame, the current
  917. window and the agenda.
  918. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  919. Also, when exiting the agenda, kill that frame.
  920. See also the variable `org-agenda-restore-windows-after-quit'."
  921. :group 'org-agenda-windows
  922. :type '(choice
  923. (const current-window)
  924. (const other-frame)
  925. (const other-window)
  926. (const reorganize-frame)))
  927. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  928. "The min and max height of the agenda window as a fraction of frame height.
  929. The value of the variable is a cons cell with two numbers between 0 and 1.
  930. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  931. :group 'org-agenda-windows
  932. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  933. (defcustom org-agenda-restore-windows-after-quit nil
  934. "Non-nil means restore window configuration upon exiting agenda.
  935. Before the window configuration is changed for displaying the agenda,
  936. the current status is recorded. When the agenda is exited with
  937. `q' or `x' and this option is set, the old state is restored. If
  938. `org-agenda-window-setup' is `other-frame', the value of this
  939. option will be ignored."
  940. :group 'org-agenda-windows
  941. :type 'boolean)
  942. (defcustom org-agenda-ndays nil
  943. "Number of days to include in overview display.
  944. Should be 1 or 7.
  945. Obsolete, see `org-agenda-span'."
  946. :group 'org-agenda-daily/weekly
  947. :type 'integer)
  948. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  949. (defcustom org-agenda-span 'week
  950. "Number of days to include in overview display.
  951. Can be day, week, month, year, or any number of days.
  952. Custom commands can set this variable in the options section."
  953. :group 'org-agenda-daily/weekly
  954. :type '(choice (const :tag "Day" day)
  955. (const :tag "Week" week)
  956. (const :tag "Month" month)
  957. (const :tag "Year" year)
  958. (integer :tag "Custom")))
  959. (defcustom org-agenda-start-on-weekday 1
  960. "Non-nil means start the overview always on the specified weekday.
  961. 0 denotes Sunday, 1 denotes Monday etc.
  962. When nil, always start on the current day.
  963. Custom commands can set this variable in the options section."
  964. :group 'org-agenda-daily/weekly
  965. :type '(choice (const :tag "Today" nil)
  966. (integer :tag "Weekday No.")))
  967. (defcustom org-agenda-show-all-dates t
  968. "Non-nil means `org-agenda' shows every day in the selected range.
  969. When nil, only the days which actually have entries are shown."
  970. :group 'org-agenda-daily/weekly
  971. :type 'boolean)
  972. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  973. "Format string for displaying dates in the agenda.
  974. Used by the daily/weekly agenda and by the timeline. This should be
  975. a format string understood by `format-time-string', or a function returning
  976. the formatted date as a string. The function must take a single argument,
  977. a calendar-style date list like (month day year)."
  978. :group 'org-agenda-daily/weekly
  979. :type '(choice
  980. (string :tag "Format string")
  981. (function :tag "Function")))
  982. (defun org-agenda-format-date-aligned (date)
  983. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  984. This function makes sure that dates are aligned for easy reading."
  985. (require 'cal-iso)
  986. (let* ((dayname (calendar-day-name date))
  987. (day (cadr date))
  988. (day-of-week (calendar-day-of-week date))
  989. (month (car date))
  990. (monthname (calendar-month-name month))
  991. (year (nth 2 date))
  992. (iso-week (org-days-to-iso-week
  993. (calendar-absolute-from-gregorian date)))
  994. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  995. (1- year))
  996. ((and (= month 12) (<= iso-week 1))
  997. (1+ year))
  998. (t year)))
  999. (weekstring (if (= day-of-week 1)
  1000. (format " W%02d" iso-week)
  1001. "")))
  1002. (format "%-10s %2d %s %4d%s"
  1003. dayname day monthname year weekstring)))
  1004. (defcustom org-agenda-time-leading-zero nil
  1005. "Non-nil means use leading zero for military times in agenda.
  1006. For example, 9:30am would become 09:30 rather than 9:30."
  1007. :group 'org-agenda-daily/weekly
  1008. :version "24.1"
  1009. :type 'boolean)
  1010. (defcustom org-agenda-timegrid-use-ampm nil
  1011. "When set, show AM/PM style timestamps on the timegrid."
  1012. :group 'org-agenda
  1013. :version "24.1"
  1014. :type 'boolean)
  1015. (defun org-agenda-time-of-day-to-ampm (time)
  1016. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1017. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1018. (minute (substring time -2))
  1019. (ampm "am"))
  1020. (cond
  1021. ((equal hour-number 12)
  1022. (setq ampm "pm"))
  1023. ((> hour-number 12)
  1024. (setq ampm "pm")
  1025. (setq hour-number (- hour-number 12))))
  1026. (concat
  1027. (if org-agenda-time-leading-zero
  1028. (format "%02d" hour-number)
  1029. (format "%02s" (number-to-string hour-number)))
  1030. ":" minute ampm)))
  1031. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1032. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1033. (if org-agenda-timegrid-use-ampm
  1034. (org-agenda-time-of-day-to-ampm time)
  1035. time))
  1036. (defcustom org-agenda-weekend-days '(6 0)
  1037. "Which days are weekend?
  1038. These days get the special face `org-agenda-date-weekend' in the agenda
  1039. and timeline buffers."
  1040. :group 'org-agenda-daily/weekly
  1041. :type '(set :greedy t
  1042. (const :tag "Monday" 1)
  1043. (const :tag "Tuesday" 2)
  1044. (const :tag "Wednesday" 3)
  1045. (const :tag "Thursday" 4)
  1046. (const :tag "Friday" 5)
  1047. (const :tag "Saturday" 6)
  1048. (const :tag "Sunday" 0)))
  1049. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1050. "Non-nil means jump to today when moving a past date forward in time.
  1051. When using S-right in the agenda to move a a date forward, and the date
  1052. stamp currently points to the past, the first key press will move it
  1053. to today. WHen nil, just move one day forward even if the date stays
  1054. in the past."
  1055. :group 'org-agenda-daily/weekly
  1056. :version "24.1"
  1057. :type 'boolean)
  1058. (defcustom org-agenda-include-diary nil
  1059. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1060. Custom commands can set this variable in the options section."
  1061. :group 'org-agenda-daily/weekly
  1062. :type 'boolean)
  1063. (defcustom org-agenda-include-deadlines t
  1064. "If non-nil, include entries within their deadline warning period.
  1065. Custom commands can set this variable in the options section."
  1066. :group 'org-agenda-daily/weekly
  1067. :version "24.1"
  1068. :type 'boolean)
  1069. (defcustom org-agenda-repeating-timestamp-show-all t
  1070. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1071. When set to a list of strings, only show occurrences of repeating
  1072. stamps for these TODO keywords. When nil, only one occurrence is
  1073. shown, either today or the nearest into the future."
  1074. :group 'org-agenda-daily/weekly
  1075. :type '(choice
  1076. (const :tag "Show repeating stamps" t)
  1077. (repeat :tag "Show repeating stamps for these TODO keywords"
  1078. (string :tag "TODO Keyword"))
  1079. (const :tag "Don't show repeating stamps" nil)))
  1080. (defcustom org-scheduled-past-days 10000
  1081. "Number of days to continue listing scheduled items not marked DONE.
  1082. When an item is scheduled on a date, it shows up in the agenda on this
  1083. day and will be listed until it is marked done for the number of days
  1084. given here."
  1085. :group 'org-agenda-daily/weekly
  1086. :type 'integer)
  1087. (defcustom org-agenda-log-mode-items '(closed clock)
  1088. "List of items that should be shown in agenda log mode.
  1089. This list may contain the following symbols:
  1090. closed Show entries that have been closed on that day.
  1091. clock Show entries that have received clocked time on that day.
  1092. state Show all logged state changes.
  1093. Note that instead of changing this variable, you can also press `C-u l' in
  1094. the agenda to display all available LOG items temporarily."
  1095. :group 'org-agenda-daily/weekly
  1096. :type '(set :greedy t (const closed) (const clock) (const state)))
  1097. (defcustom org-agenda-clock-consistency-checks
  1098. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1099. :gap-ok-around ("4:00")
  1100. :default-face ((:background "DarkRed") (:foreground "white"))
  1101. :overlap-face nil :gap-face nil :no-end-time-face nil
  1102. :long-face nil :short-face nil)
  1103. "This is a property list, with the following keys:
  1104. :max-duration Mark clocking chunks that are longer than this time.
  1105. This is a time string like \"HH:MM\", or the number
  1106. of minutes as an integer.
  1107. :min-duration Mark clocking chunks that are shorter that this.
  1108. This is a time string like \"HH:MM\", or the number
  1109. of minutes as an integer.
  1110. :max-gap Mark gaps between clocking chunks that are longer than
  1111. this duration. A number of minutes, or a string
  1112. like \"HH:MM\".
  1113. :gap-ok-around List of times during the day which are usually not working
  1114. times. When a gap is detected, but the gap contains any
  1115. of these times, the gap is *not* reported. For example,
  1116. if this is (\"4:00\" \"13:00\") then gaps that contain
  1117. 4:00 in the morning (i.e. the night) and 13:00
  1118. (i.e. a typical lunch time) do not cause a warning.
  1119. You should have at least one time during the night in this
  1120. list, or otherwise the first task each morning will trigger
  1121. a warning because it follows a long gap.
  1122. Furthermore, the following properties can be used to define faces for
  1123. issue display.
  1124. :default-face the default face, if the specific face is undefined
  1125. :overlap-face face for overlapping clocks
  1126. :gap-face face for gaps between clocks
  1127. :no-end-time-face face for incomplete clocks
  1128. :long-face face for clock intervals that are too long
  1129. :short-face face for clock intervals that are too short"
  1130. :group 'org-agenda-daily/weekly
  1131. :group 'org-clock
  1132. :version "24.1"
  1133. :type 'plist)
  1134. (defcustom org-agenda-log-mode-add-notes t
  1135. "Non-nil means add first line of notes to log entries in agenda views.
  1136. If a log item like a state change or a clock entry is associated with
  1137. notes, the first line of these notes will be added to the entry in the
  1138. agenda display."
  1139. :group 'org-agenda-daily/weekly
  1140. :type 'boolean)
  1141. (defcustom org-agenda-start-with-log-mode nil
  1142. "The initial value of log-mode in a newly created agenda window.
  1143. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1144. explanations on the possible values."
  1145. :group 'org-agenda-startup
  1146. :group 'org-agenda-daily/weekly
  1147. :type '(choice (const :tag "Don't show log items" nil)
  1148. (const :tag "Show only log items" 'only)
  1149. (const :tag "Show all possible log items" 'clockcheck)
  1150. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1151. (choice (const :tag "Show closed log items" 'closed)
  1152. (const :tag "Show clocked log items" 'clock)
  1153. (const :tag "Show all logged state changes" 'state)))))
  1154. (defcustom org-agenda-start-with-clockreport-mode nil
  1155. "The initial value of clockreport-mode in a newly created agenda window."
  1156. :group 'org-agenda-startup
  1157. :group 'org-agenda-daily/weekly
  1158. :type 'boolean)
  1159. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1160. "Property list with parameters for the clocktable in clockreport mode.
  1161. This is the display mode that shows a clock table in the daily/weekly
  1162. agenda, the properties for this dynamic block can be set here.
  1163. The usual clocktable parameters are allowed here, but you cannot set
  1164. the properties :name, :tstart, :tend, :block, and :scope - these will
  1165. be overwritten to make sure the content accurately reflects the
  1166. current display in the agenda."
  1167. :group 'org-agenda-daily/weekly
  1168. :type 'plist)
  1169. (defcustom org-agenda-search-view-always-boolean nil
  1170. "Non-nil means the search string is interpreted as individual parts.
  1171. The search string for search view can either be interpreted as a phrase,
  1172. or as a list of snippets that define a boolean search for a number of
  1173. strings.
  1174. When this is non-nil, the string will be split on whitespace, and each
  1175. snippet will be searched individually, and all must match in order to
  1176. select an entry. A snippet is then a single string of non-white
  1177. characters, or a string in double quotes, or a regexp in {} braces.
  1178. If a snippet is preceded by \"-\", the snippet must *not* match.
  1179. \"+\" is syntactic sugar for positive selection. Each snippet may
  1180. be found as a full word or a partial word, but see the variable
  1181. `org-agenda-search-view-force-full-words'.
  1182. When this is nil, search will look for the entire search phrase as one,
  1183. with each space character matching any amount of whitespace, including
  1184. line breaks.
  1185. Even when this is nil, you can still switch to Boolean search dynamically
  1186. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1187. is a regexp marked with braces like \"{abc}\", this will also switch to
  1188. boolean search."
  1189. :group 'org-agenda-search-view
  1190. :version "24.1"
  1191. :type 'boolean)
  1192. (if (fboundp 'defvaralias)
  1193. (defvaralias 'org-agenda-search-view-search-words-only
  1194. 'org-agenda-search-view-always-boolean))
  1195. (defcustom org-agenda-search-view-force-full-words nil
  1196. "Non-nil means, search words must be matches as complete words.
  1197. When nil, they may also match part of a word."
  1198. :group 'org-agenda-search-view
  1199. :version "24.1"
  1200. :type 'boolean)
  1201. (defcustom org-agenda-search-view-max-outline-level nil
  1202. "Maximum outline level to display in search view.
  1203. E.g. when this is set to 1, the search view will only
  1204. show headlines of level 1."
  1205. :group 'org-agenda-search-view
  1206. :version "24.4"
  1207. :package-version '(Org . "8.0")
  1208. :type 'integer)
  1209. (defgroup org-agenda-time-grid nil
  1210. "Options concerning the time grid in the Org-mode Agenda."
  1211. :tag "Org Agenda Time Grid"
  1212. :group 'org-agenda)
  1213. (defcustom org-agenda-search-headline-for-time t
  1214. "Non-nil means search headline for a time-of-day.
  1215. If the headline contains a time-of-day in one format or another, it will
  1216. be used to sort the entry into the time sequence of items for a day.
  1217. Some people have time stamps in the headline that refer to the creation
  1218. time or so, and then this produces an unwanted side effect. If this is
  1219. the case for your, use this variable to turn off searching the headline
  1220. for a time."
  1221. :group 'org-agenda-time-grid
  1222. :type 'boolean)
  1223. (defcustom org-agenda-use-time-grid t
  1224. "Non-nil means show a time grid in the agenda schedule.
  1225. A time grid is a set of lines for specific times (like every two hours between
  1226. 8:00 and 20:00). The items scheduled for a day at specific times are
  1227. sorted in between these lines.
  1228. For details about when the grid will be shown, and what it will look like, see
  1229. the variable `org-agenda-time-grid'."
  1230. :group 'org-agenda-time-grid
  1231. :type 'boolean)
  1232. (defcustom org-agenda-time-grid
  1233. '((daily today require-timed)
  1234. "----------------"
  1235. (800 1000 1200 1400 1600 1800 2000))
  1236. "The settings for time grid for agenda display.
  1237. This is a list of three items. The first item is again a list. It contains
  1238. symbols specifying conditions when the grid should be displayed:
  1239. daily if the agenda shows a single day
  1240. weekly if the agenda shows an entire week
  1241. today show grid on current date, independent of daily/weekly display
  1242. require-timed show grid only if at least one item has a time specification
  1243. The second item is a string which will be placed behind the grid time.
  1244. The third item is a list of integers, indicating the times that should have
  1245. a grid line."
  1246. :group 'org-agenda-time-grid
  1247. :type
  1248. '(list
  1249. (set :greedy t :tag "Grid Display Options"
  1250. (const :tag "Show grid in single day agenda display" daily)
  1251. (const :tag "Show grid in weekly agenda display" weekly)
  1252. (const :tag "Always show grid for today" today)
  1253. (const :tag "Show grid only if any timed entries are present"
  1254. require-timed)
  1255. (const :tag "Skip grid times already present in an entry"
  1256. remove-match))
  1257. (string :tag "Grid String")
  1258. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1259. (defcustom org-agenda-show-current-time-in-grid t
  1260. "Non-nil means show the current time in the time grid."
  1261. :group 'org-agenda-time-grid
  1262. :version "24.1"
  1263. :type 'boolean)
  1264. (defcustom org-agenda-current-time-string
  1265. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1266. "The string for the current time marker in the agenda."
  1267. :group 'org-agenda-time-grid
  1268. :version "24.1"
  1269. :type 'string)
  1270. (defgroup org-agenda-sorting nil
  1271. "Options concerning sorting in the Org-mode Agenda."
  1272. :tag "Org Agenda Sorting"
  1273. :group 'org-agenda)
  1274. (defcustom org-agenda-sorting-strategy
  1275. '((agenda habit-down time-up priority-down category-keep)
  1276. (todo priority-down category-keep)
  1277. (tags priority-down category-keep)
  1278. (search category-keep))
  1279. "Sorting structure for the agenda items of a single day.
  1280. This is a list of symbols which will be used in sequence to determine
  1281. if an entry should be listed before another entry. The following
  1282. symbols are recognized:
  1283. time-up Put entries with time-of-day indications first, early first
  1284. time-down Put entries with time-of-day indications first, late first
  1285. timestamp-up Sort by any timestamp, early first
  1286. timestamp-down Sort by any timestamp, late first
  1287. scheduled-up Sort by scheduled timestamp, early first
  1288. scheduled-down Sort by scheduled timestamp, late first
  1289. deadline-up Sort by deadline timestamp, early first
  1290. deadline-down Sort by deadline timestamp, late first
  1291. ts-up Sort by active timestamp, early first
  1292. ts-down Sort by active timestamp, late first
  1293. tsia-up Sort by inactive timestamp, early first
  1294. tsia-down Sort by inactive timestamp, late first
  1295. category-keep Keep the default order of categories, corresponding to the
  1296. sequence in `org-agenda-files'.
  1297. category-up Sort alphabetically by category, A-Z.
  1298. category-down Sort alphabetically by category, Z-A.
  1299. tag-up Sort alphabetically by last tag, A-Z.
  1300. tag-down Sort alphabetically by last tag, Z-A.
  1301. priority-up Sort numerically by priority, high priority last.
  1302. priority-down Sort numerically by priority, high priority first.
  1303. todo-state-up Sort by todo state, tasks that are done last.
  1304. todo-state-down Sort by todo state, tasks that are done first.
  1305. effort-up Sort numerically by estimated effort, high effort last.
  1306. effort-down Sort numerically by estimated effort, high effort first.
  1307. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1308. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1309. habit-up Put entries that are habits first
  1310. habit-down Put entries that are habits last
  1311. alpha-up Sort headlines alphabetically
  1312. alpha-down Sort headlines alphabetically, reversed
  1313. The different possibilities will be tried in sequence, and testing stops
  1314. if one comparison returns a \"not-equal\". For example, the default
  1315. '(time-up category-keep priority-down)
  1316. means: Pull out all entries having a specified time of day and sort them,
  1317. in order to make a time schedule for the current day the first thing in the
  1318. agenda listing for the day. Of the entries without a time indication, keep
  1319. the grouped in categories, don't sort the categories, but keep them in
  1320. the sequence given in `org-agenda-files'. Within each category sort by
  1321. priority.
  1322. Leaving out `category-keep' would mean that items will be sorted across
  1323. categories by priority.
  1324. Instead of a single list, this can also be a set of list for specific
  1325. contents, with a context symbol in the car of the list, any of
  1326. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1327. Custom commands can bind this variable in the options section."
  1328. :group 'org-agenda-sorting
  1329. :type `(choice
  1330. (repeat :tag "General" ,org-sorting-choice)
  1331. (list :tag "Individually"
  1332. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1333. (repeat ,org-sorting-choice))
  1334. (cons (const :tag "Strategy for TODO lists" todo)
  1335. (repeat ,org-sorting-choice))
  1336. (cons (const :tag "Strategy for Tags matches" tags)
  1337. (repeat ,org-sorting-choice))
  1338. (cons (const :tag "Strategy for search matches" search)
  1339. (repeat ,org-sorting-choice)))))
  1340. (defcustom org-agenda-cmp-user-defined nil
  1341. "A function to define the comparison `user-defined'.
  1342. This function must receive two arguments, agenda entry a and b.
  1343. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1344. the user comparison, return nil.
  1345. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1346. part of an agenda sorting strategy."
  1347. :group 'org-agenda-sorting
  1348. :type 'symbol)
  1349. (defcustom org-sort-agenda-notime-is-late t
  1350. "Non-nil means items without time are considered late.
  1351. This is only relevant for sorting. When t, items which have no explicit
  1352. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1353. do have a time. When nil, the default time is before 0:00. You can use this
  1354. option to decide if the schedule for today should come before or after timeless
  1355. agenda entries."
  1356. :group 'org-agenda-sorting
  1357. :type 'boolean)
  1358. (defcustom org-sort-agenda-noeffort-is-high t
  1359. "Non-nil means items without effort estimate are sorted as high effort.
  1360. This also applies when filtering an agenda view with respect to the
  1361. < or > effort operator. Then, tasks with no effort defined will be treated
  1362. as tasks with high effort.
  1363. When nil, such items are sorted as 0 minutes effort."
  1364. :group 'org-agenda-sorting
  1365. :type 'boolean)
  1366. (defgroup org-agenda-line-format nil
  1367. "Options concerning the entry prefix in the Org-mode agenda display."
  1368. :tag "Org Agenda Line Format"
  1369. :group 'org-agenda)
  1370. (defcustom org-agenda-prefix-format
  1371. '((agenda . " %i %-12:c%?-12t% s")
  1372. (timeline . " % s")
  1373. (todo . " %i %-12:c")
  1374. (tags . " %i %-12:c")
  1375. (search . " %i %-12:c"))
  1376. "Format specifications for the prefix of items in the agenda views.
  1377. An alist with five entries, each for the different agenda types. The
  1378. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1379. The values are format strings.
  1380. This format works similar to a printf format, with the following meaning:
  1381. %c the category of the item, \"Diary\" for entries from the diary,
  1382. or as given by the CATEGORY keyword or derived from the file name
  1383. %e the effort required by the item
  1384. %l the level of the item (insert X space(s) if item is of level X)
  1385. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1386. %T the last tag of the item (ignore inherited tags, which come first)
  1387. %t the HH:MM time-of-day specification if one applies to the entry
  1388. %s Scheduling/Deadline information, a short string
  1389. %b show breadcrumbs, i.e., the names of the higher levels
  1390. %(expression) Eval EXPRESSION and replace the control string
  1391. by the result
  1392. All specifiers work basically like the standard `%s' of printf, but may
  1393. contain two additional characters: a question mark just after the `%'
  1394. and a whitespace/punctuation character just before the final letter.
  1395. If the first character after `%' is a question mark, the entire field
  1396. will only be included if the corresponding value applies to the current
  1397. entry. This is useful for fields which should have fixed width when
  1398. present, but zero width when absent. For example, \"%?-12t\" will
  1399. result in a 12 character time field if a time of the day is specified,
  1400. but will completely disappear in entries which do not contain a time.
  1401. If there is punctuation or whitespace character just before the
  1402. final format letter, this character will be appended to the field
  1403. value if the value is not empty. For example, the format
  1404. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1405. the category is empty, no additional colon is inserted.
  1406. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1407. which means:
  1408. - Indent the line with two space characters
  1409. - Give the category a 12 chars wide field, padded with whitespace on
  1410. the right (because of `-'). Append a colon if there is a category
  1411. (because of `:').
  1412. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1413. time, don't put in an empty field, just skip it (because of '?').
  1414. - Finally, put the scheduling information.
  1415. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1416. `org-agenda-remove-tags'.
  1417. Custom commands can set this variable in the options section."
  1418. :type '(choice
  1419. (string :tag "General format")
  1420. (list :greedy t :tag "View dependent"
  1421. (cons (const agenda) (string :tag "Format"))
  1422. (cons (const timeline) (string :tag "Format"))
  1423. (cons (const todo) (string :tag "Format"))
  1424. (cons (const tags) (string :tag "Format"))
  1425. (cons (const search) (string :tag "Format"))))
  1426. :group 'org-agenda-line-format)
  1427. (defvar org-prefix-format-compiled nil
  1428. "The compiled prefix format and associated variables.
  1429. This is a list where first element is a list of variable bindings, and second
  1430. element is the compiled format expression. See the variable
  1431. `org-agenda-prefix-format'.")
  1432. (defcustom org-agenda-todo-keyword-format "%-1s"
  1433. "Format for the TODO keyword in agenda lines.
  1434. Set this to something like \"%-12s\" if you want all TODO keywords
  1435. to occupy a fixed space in the agenda display."
  1436. :group 'org-agenda-line-format
  1437. :type 'string)
  1438. (defcustom org-agenda-diary-sexp-prefix nil
  1439. "A regexp that matches part of a diary sexp entry
  1440. which should be treated as scheduling/deadline information in
  1441. `org-agenda'.
  1442. For example, you can use this to extract the `diary-remind-message' from
  1443. `diary-remind' entries."
  1444. :group 'org-agenda-line-format
  1445. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1446. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1447. "Text preceding timerange entries in the agenda view.
  1448. This is a list with two strings. The first applies when the range
  1449. is entirely on one day. The second applies if the range spans several days.
  1450. The strings may have two \"%d\" format specifiers which will be filled
  1451. with the sequence number of the days, and the total number of days in the
  1452. range, respectively."
  1453. :group 'org-agenda-line-format
  1454. :type '(list
  1455. (string :tag "Deadline today ")
  1456. (choice :tag "Deadline relative"
  1457. (string :tag "Format string")
  1458. (function))))
  1459. (defcustom org-agenda-scheduled-leaders '(" Scheduled: " "Sched.%3dx: ")
  1460. "Text preceding scheduled items in the agenda view.
  1461. This is a list with two strings. The first applies when the item is
  1462. scheduled on the current day. The second applies when it has been scheduled
  1463. previously, it may contain a %d indicating that this is the nth time that
  1464. this item is scheduled, due to automatic rescheduling of unfinished items
  1465. for the following day. So this number is one larger than the number of days
  1466. that passed since this item was scheduled first."
  1467. :group 'org-agenda-line-format
  1468. :version "24.4"
  1469. :package-version '(Org . "8.0")
  1470. :type '(list
  1471. (string :tag "Scheduled today ")
  1472. (string :tag "Scheduled previously")))
  1473. (defcustom org-agenda-inactive-leader "["
  1474. "Text preceding item pulled into the agenda by inactive time stamps.
  1475. These entries are added to the agenda when pressing \"[\"."
  1476. :group 'org-agenda-line-format
  1477. :version "24.1"
  1478. :type '(list
  1479. (string :tag "Scheduled today ")
  1480. (string :tag "Scheduled previously")))
  1481. (defcustom org-agenda-deadline-leaders '(" Deadline: " " In %3d d.: " "%3d d. ago: ")
  1482. "Text preceding deadline items in the agenda view.
  1483. This is a list with three strings. The first applies when the item has its
  1484. deadline on the current day. The second applies when the deadline is in the
  1485. future, the third one when it is in the past. The strings may contain %d
  1486. to capture the number of days."
  1487. :group 'org-agenda-line-format
  1488. :version "24.4"
  1489. :package-version '(Org . "8.0")
  1490. :type '(list
  1491. (string :tag "Deadline today ")
  1492. (choice :tag "Deadline relative"
  1493. (string :tag "Format string")
  1494. (function))))
  1495. (defcustom org-agenda-remove-times-when-in-prefix t
  1496. "Non-nil means remove duplicate time specifications in agenda items.
  1497. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1498. time-of-day specification in a headline or diary entry is extracted and
  1499. placed into the prefix. If this option is non-nil, the original specification
  1500. \(a timestamp or -range, or just a plain time(range) specification like
  1501. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1502. cluttered.
  1503. The option can be t or nil. It may also be the symbol `beg', indicating
  1504. that the time should only be removed when it is located at the beginning of
  1505. the headline/diary entry."
  1506. :group 'org-agenda-line-format
  1507. :type '(choice
  1508. (const :tag "Always" t)
  1509. (const :tag "Never" nil)
  1510. (const :tag "When at beginning of entry" beg)))
  1511. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1512. "Non-nil means remove time ranges specifications in agenda
  1513. items that span on several days."
  1514. :group 'org-agenda-line-format
  1515. :version "24.1"
  1516. :type 'boolean)
  1517. (defcustom org-agenda-default-appointment-duration nil
  1518. "Default duration for appointments that only have a starting time.
  1519. When nil, no duration is specified in such cases.
  1520. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1521. :group 'org-agenda-line-format
  1522. :type '(choice
  1523. (integer :tag "Minutes")
  1524. (const :tag "No default duration")))
  1525. (defcustom org-agenda-show-inherited-tags t
  1526. "Non-nil means show inherited tags in each agenda line.
  1527. When this option is set to 'always, it take precedences over
  1528. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1529. in every agenda.
  1530. When this option is set to t (the default), inherited tags are
  1531. shown when they are available, i.e. when the value of
  1532. `org-agenda-use-tag-inheritance' has been taken into account.
  1533. This can be set to a list of agenda types in which the agenda
  1534. must display the inherited tags. Available types are 'todo,
  1535. 'agenda, 'search and 'timeline.
  1536. When set to nil, never show inherited tags in agenda lines."
  1537. :group 'org-agenda-line-format
  1538. :group 'org-agenda
  1539. :version "24.3"
  1540. :type '(choice
  1541. (const :tag "Show inherited tags when available" t)
  1542. (const :tag "Always show inherited tags" 'always)
  1543. (repeat :tag "Show inherited tags only in selected agenda types"
  1544. (symbol :tag "Agenda type"))))
  1545. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1546. "List of agenda view types where to use tag inheritance.
  1547. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1548. controlled by `org-use-tag-inheritance'. In other agenda types,
  1549. `org-use-tag-inheritance' is not used for the selection of the
  1550. agenda entries. Still, you may want the agenda to be aware of
  1551. the inherited tags anyway, e.g. for later tag filtering.
  1552. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1553. This variable has no effect if `org-agenda-show-inherited-tags'
  1554. is set to 'always. In that case, the agenda is aware of those
  1555. tags.
  1556. The default value sets tags in every agenda type. Setting this
  1557. option to nil will speed up non-tags agenda view a lot."
  1558. :group 'org-agenda
  1559. :version "24.3"
  1560. :type '(choice
  1561. (const :tag "Use tag inheritance in all agenda types" t)
  1562. (repeat :tag "Use tag inheritance in selected agenda types"
  1563. (symbol :tag "Agenda type"))))
  1564. (defcustom org-agenda-hide-tags-regexp nil
  1565. "Regular expression used to filter away specific tags in agenda views.
  1566. This means that these tags will be present, but not be shown in the agenda
  1567. line. Secondary filtering will still work on the hidden tags.
  1568. Nil means don't hide any tags."
  1569. :group 'org-agenda-line-format
  1570. :type '(choice
  1571. (const :tag "Hide none" nil)
  1572. (string :tag "Regexp ")))
  1573. (defcustom org-agenda-remove-tags nil
  1574. "Non-nil means remove the tags from the headline copy in the agenda.
  1575. When this is the symbol `prefix', only remove tags when
  1576. `org-agenda-prefix-format' contains a `%T' specifier."
  1577. :group 'org-agenda-line-format
  1578. :type '(choice
  1579. (const :tag "Always" t)
  1580. (const :tag "Never" nil)
  1581. (const :tag "When prefix format contains %T" prefix)))
  1582. (if (fboundp 'defvaralias)
  1583. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1584. 'org-agenda-remove-tags))
  1585. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1586. "Shift tags in agenda items to this column.
  1587. If this number is positive, it specifies the column. If it is negative,
  1588. it means that the tags should be flushright to that column. For example,
  1589. -80 works well for a normal 80 character screen."
  1590. :group 'org-agenda-line-format
  1591. :type 'integer)
  1592. (if (fboundp 'defvaralias)
  1593. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1594. (defcustom org-agenda-fontify-priorities 'cookies
  1595. "Non-nil means highlight low and high priorities in agenda.
  1596. When t, the highest priority entries are bold, lowest priority italic.
  1597. However, settings in `org-priority-faces' will overrule these faces.
  1598. When this variable is the symbol `cookies', only fontify the
  1599. cookies, not the entire task.
  1600. This may also be an association list of priority faces, whose
  1601. keys are the character values of `org-highest-priority',
  1602. `org-default-priority', and `org-lowest-priority' (the default values
  1603. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1604. color as a string, or a list like `(:background \"Red\")'.
  1605. If it is a color, the variable `org-faces-easy-properties'
  1606. determines if it is a foreground or a background color."
  1607. :group 'org-agenda-line-format
  1608. :type '(choice
  1609. (const :tag "Never" nil)
  1610. (const :tag "Defaults" t)
  1611. (const :tag "Cookies only" cookies)
  1612. (repeat :tag "Specify"
  1613. (list (character :tag "Priority" :value ?A)
  1614. (choice :tag "Face "
  1615. (string :tag "Color")
  1616. (sexp :tag "Face"))))))
  1617. (defcustom org-agenda-day-face-function nil
  1618. "Function called to determine what face should be used to display a day.
  1619. The only argument passed to that function is the day. It should
  1620. returns a face, or nil if does not want to specify a face and let
  1621. the normal rules apply."
  1622. :group 'org-agenda-line-format
  1623. :version "24.1"
  1624. :type 'function)
  1625. (defcustom org-agenda-category-icon-alist nil
  1626. "Alist of category icon to be displayed in agenda views.
  1627. Each entry should have the following format:
  1628. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1629. Where CATEGORY-REGEXP is a regexp matching the categories where
  1630. the icon should be displayed.
  1631. FILE-OR-DATA either a file path or a string containing image data.
  1632. The other fields can be omitted safely if not needed:
  1633. TYPE indicates the image type.
  1634. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1635. image data.
  1636. PROPS are additional image attributes to assign to the image,
  1637. like, e.g. `:ascent center'.
  1638. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1639. If you want to set the display properties yourself, just put a
  1640. list as second element:
  1641. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1642. For example, to display a 16px horizontal space for Emacs
  1643. category, you can use:
  1644. (\"Emacs\" '(space . (:width (16))))"
  1645. :group 'org-agenda-line-format
  1646. :version "24.1"
  1647. :type '(alist :key-type (string :tag "Regexp matching category")
  1648. :value-type (choice (list :tag "Icon"
  1649. (string :tag "File or data")
  1650. (symbol :tag "Type")
  1651. (boolean :tag "Data?")
  1652. (repeat :tag "Extra image properties" :inline t symbol))
  1653. (list :tag "Display properties" sexp))))
  1654. (defgroup org-agenda-column-view nil
  1655. "Options concerning column view in the agenda."
  1656. :tag "Org Agenda Column View"
  1657. :group 'org-agenda)
  1658. (defcustom org-agenda-columns-show-summaries t
  1659. "Non-nil means show summaries for columns displayed in the agenda view."
  1660. :group 'org-agenda-column-view
  1661. :type 'boolean)
  1662. (defcustom org-agenda-columns-compute-summary-properties t
  1663. "Non-nil means recompute all summary properties before column view.
  1664. When column view in the agenda is listing properties that have a summary
  1665. operator, it can go to all relevant buffers and recompute the summaries
  1666. there. This can mean overhead for the agenda column view, but is necessary
  1667. to have thing up to date.
  1668. As a special case, a CLOCKSUM property also makes sure that the clock
  1669. computations are current."
  1670. :group 'org-agenda-column-view
  1671. :type 'boolean)
  1672. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1673. "Non-nil means the duration of an appointment will add to day effort.
  1674. The property to which appointment durations will be added is the one given
  1675. in the option `org-effort-property'. If an appointment does not have
  1676. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1677. is not set, an appointment without end time will not contribute to the time
  1678. estimate."
  1679. :group 'org-agenda-column-view
  1680. :type 'boolean)
  1681. (defcustom org-agenda-auto-exclude-function nil
  1682. "A function called with a tag to decide if it is filtered on '/ RET'.
  1683. The sole argument to the function, which is called once for each
  1684. possible tag, is a string giving the name of the tag. The
  1685. function should return either nil if the tag should be included
  1686. as normal, or \"-<TAG>\" to exclude the tag.
  1687. Note that for the purpose of tag filtering, only the lower-case version of
  1688. all tags will be considered, so that this function will only ever see
  1689. the lower-case version of all tags."
  1690. :group 'org-agenda
  1691. :type 'function)
  1692. (defcustom org-agenda-bulk-custom-functions nil
  1693. "Alist of characters and custom functions for bulk actions.
  1694. For example, this value makes those two functions available:
  1695. '((?R set-category)
  1696. (?C bulk-cut))
  1697. With selected entries in an agenda buffer, `B R' will call
  1698. the custom function `set-category' on the selected entries.
  1699. Note that functions in this alist don't need to be quoted."
  1700. :type 'alist
  1701. :version "24.1"
  1702. :group 'org-agenda)
  1703. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1704. "Execute BODY with point at location given by `org-hd-marker' property.
  1705. If STRING is non-nil, the text property will be fetched from position 0
  1706. in that string. If STRING is nil, it will be fetched from the beginning
  1707. of the current line."
  1708. (org-with-gensyms (marker)
  1709. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1710. 'org-hd-marker ,string)))
  1711. (with-current-buffer (marker-buffer ,marker)
  1712. (save-excursion
  1713. (goto-char ,marker)
  1714. ,@body)))))
  1715. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1716. (defun org-add-agenda-custom-command (entry)
  1717. "Replace or add a command in `org-agenda-custom-commands'.
  1718. This is mostly for hacking and trying a new command - once the command
  1719. works you probably want to add it to `org-agenda-custom-commands' for good."
  1720. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1721. (if ass
  1722. (setcdr ass (cdr entry))
  1723. (push entry org-agenda-custom-commands))))
  1724. ;;; Define the org-agenda-mode
  1725. (defvar org-agenda-mode-map (make-sparse-keymap)
  1726. "Keymap for `org-agenda-mode'.")
  1727. (if (fboundp 'defvaralias)
  1728. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1729. (defvar org-agenda-menu) ; defined later in this file.
  1730. (defvar org-agenda-restrict nil) ; defined later in this file.
  1731. (defvar org-agenda-follow-mode nil)
  1732. (defvar org-agenda-entry-text-mode nil)
  1733. (defvar org-agenda-clockreport-mode nil)
  1734. (defvar org-agenda-show-log nil)
  1735. (defvar org-agenda-redo-command nil)
  1736. (defvar org-agenda-query-string nil)
  1737. (defvar org-agenda-mode-hook nil
  1738. "Hook run after `org-agenda-mode' is turned on.
  1739. The buffer is still writable when this hook is called.")
  1740. (defvar org-agenda-type nil)
  1741. (defvar org-agenda-force-single-file nil)
  1742. (defvar org-agenda-bulk-marked-entries nil
  1743. "List of markers that refer to marked entries in the agenda.")
  1744. ;;; Multiple agenda buffers support
  1745. (defcustom org-agenda-sticky nil
  1746. "Non-nil means agenda q key will bury agenda buffers.
  1747. Agenda commands will then show existing buffer instead of generating new ones.
  1748. When nil, `q' will kill the single agenda buffer."
  1749. :group 'org-agenda
  1750. :version "24.3"
  1751. :type 'boolean)
  1752. ;;;###autoload
  1753. (defun org-toggle-sticky-agenda (&optional arg)
  1754. "Toggle `org-agenda-sticky'."
  1755. (interactive "P")
  1756. (let ((new-value (if arg
  1757. (> (prefix-numeric-value arg) 0)
  1758. (not org-agenda-sticky))))
  1759. (if (equal new-value org-agenda-sticky)
  1760. (and (org-called-interactively-p 'interactive)
  1761. (message "Sticky agenda was already %s"
  1762. (if org-agenda-sticky "enabled" "disabled")))
  1763. (setq org-agenda-sticky new-value)
  1764. (org-agenda-kill-all-agenda-buffers)
  1765. (and (org-called-interactively-p 'interactive)
  1766. (message "Sticky agenda was %s"
  1767. (if org-agenda-sticky "enabled" "disabled"))))))
  1768. (defvar org-agenda-buffer nil
  1769. "Agenda buffer currently being generated.")
  1770. (defvar org-agenda-last-prefix-arg nil)
  1771. (defvar org-agenda-this-buffer-name nil)
  1772. (defvar org-agenda-doing-sticky-redo nil)
  1773. (defvar org-agenda-this-buffer-is-sticky nil)
  1774. (defconst org-agenda-local-vars
  1775. '(org-agenda-this-buffer-name
  1776. org-agenda-undo-list
  1777. org-agenda-pending-undo-list
  1778. org-agenda-follow-mode
  1779. org-agenda-entry-text-mode
  1780. org-agenda-clockreport-mode
  1781. org-agenda-show-log
  1782. org-agenda-redo-command
  1783. org-agenda-query-string
  1784. org-agenda-type
  1785. org-agenda-bulk-marked-entries
  1786. org-agenda-undo-has-started-in
  1787. org-agenda-info
  1788. org-agenda-tag-filter-overlays
  1789. org-agenda-cat-filter-overlays
  1790. org-agenda-pre-window-conf
  1791. org-agenda-columns-active
  1792. org-agenda-tag-filter
  1793. org-agenda-category-filter
  1794. org-agenda-markers
  1795. org-agenda-last-search-view-search-was-boolean
  1796. org-agenda-filtered-by-category
  1797. org-agenda-filter-form
  1798. org-agenda-cycle-counter
  1799. org-agenda-last-prefix-arg)
  1800. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1801. (defun org-agenda-mode ()
  1802. "Mode for time-sorted view on action items in Org-mode files.
  1803. The following commands are available:
  1804. \\{org-agenda-mode-map}"
  1805. (interactive)
  1806. (cond (org-agenda-doing-sticky-redo
  1807. ;; Refreshing sticky agenda-buffer
  1808. ;;
  1809. ;; Preserve the value of `org-agenda-local-vars' variables,
  1810. ;; while letting `kill-all-local-variables' kill the rest
  1811. (let ((save (buffer-local-variables)))
  1812. (kill-all-local-variables)
  1813. (mapc 'make-local-variable org-agenda-local-vars)
  1814. (dolist (elem save)
  1815. (let ((var (car elem))
  1816. (val (cdr elem)))
  1817. (when (and val
  1818. (member var org-agenda-local-vars))
  1819. (set var val)))))
  1820. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1821. (org-agenda-sticky
  1822. ;; Creating a sticky Agenda buffer for the first time
  1823. (kill-all-local-variables)
  1824. (mapc 'make-local-variable org-agenda-local-vars)
  1825. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1826. (t
  1827. ;; Creating a non-sticky agenda buffer
  1828. (kill-all-local-variables)
  1829. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1830. (setq org-agenda-undo-list nil
  1831. org-agenda-pending-undo-list nil
  1832. org-agenda-bulk-marked-entries nil)
  1833. (setq major-mode 'org-agenda-mode)
  1834. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1835. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1836. (setq mode-name "Org-Agenda")
  1837. (use-local-map org-agenda-mode-map)
  1838. (easy-menu-add org-agenda-menu)
  1839. (if org-startup-truncated (setq truncate-lines t))
  1840. (org-set-local 'line-move-visual nil)
  1841. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1842. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1843. ;; Make sure properties are removed when copying text
  1844. (make-local-variable 'filter-buffer-substring-functions)
  1845. (add-hook 'filter-buffer-substring-functions
  1846. (lambda (fun start end delete)
  1847. (substring-no-properties (funcall fun start end delete))))
  1848. (unless org-agenda-keep-modes
  1849. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1850. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1851. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1852. org-agenda-show-log org-agenda-start-with-log-mode))
  1853. (easy-menu-change
  1854. '("Agenda") "Agenda Files"
  1855. (append
  1856. (list
  1857. (vector
  1858. (if (get 'org-agenda-files 'org-restrict)
  1859. "Restricted to single file"
  1860. "Edit File List")
  1861. '(org-edit-agenda-file-list)
  1862. (not (get 'org-agenda-files 'org-restrict)))
  1863. "--")
  1864. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1865. (org-agenda-set-mode-name)
  1866. (apply
  1867. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1868. (list 'org-agenda-mode-hook)))
  1869. (substitute-key-definition 'undo 'org-agenda-undo
  1870. org-agenda-mode-map global-map)
  1871. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1872. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1873. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1874. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1875. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1876. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1877. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1878. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1879. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1880. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1881. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1882. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1883. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1884. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1885. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1886. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1887. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1888. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1889. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1890. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1891. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1892. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1893. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1894. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1895. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1896. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1897. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1898. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1899. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1900. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1901. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1902. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1903. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1904. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1905. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1906. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1907. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1908. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1909. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1910. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1911. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1912. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1913. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1914. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1915. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1916. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1917. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1918. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1919. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1920. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1921. (while l (org-defkey org-agenda-mode-map
  1922. (int-to-string (pop l)) 'digit-argument)))
  1923. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1924. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1925. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1926. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1927. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1928. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1929. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1930. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1931. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1932. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1933. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1934. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1935. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1936. 'org-clock-modify-effort-estimate)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1938. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1939. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1940. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1941. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1942. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1943. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1944. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1945. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1946. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1947. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1948. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1949. (substitute-key-definition 'next-line 'org-agenda-next-line
  1950. org-agenda-mode-map global-map)
  1951. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1952. org-agenda-mode-map global-map)
  1953. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1954. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1955. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1956. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1957. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1958. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1959. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1960. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1961. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1962. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1963. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1964. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1965. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1966. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1967. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1968. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1969. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1970. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1971. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1972. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1973. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1974. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1975. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1976. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1977. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1978. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1979. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1980. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1981. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1982. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1983. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1984. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1985. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1986. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1987. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1988. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1989. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1990. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1991. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1992. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1993. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1994. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1995. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1996. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1997. (when org-agenda-mouse-1-follows-link
  1998. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1999. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2000. '("Agenda"
  2001. ("Agenda Files")
  2002. "--"
  2003. ("Agenda Dates"
  2004. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2005. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2006. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2007. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2008. "--"
  2009. ("View"
  2010. ["Day View" org-agenda-day-view
  2011. :active (org-agenda-check-type nil 'agenda)
  2012. :style radio :selected (eq org-agenda-current-span 'day)
  2013. :keys "v d (or just d)"]
  2014. ["Week View" org-agenda-week-view
  2015. :active (org-agenda-check-type nil 'agenda)
  2016. :style radio :selected (eq org-agenda-current-span 'week)
  2017. :keys "v w (or just w)"]
  2018. ["Month View" org-agenda-month-view
  2019. :active (org-agenda-check-type nil 'agenda)
  2020. :style radio :selected (eq org-agenda-current-span 'month)
  2021. :keys "v m"]
  2022. ["Year View" org-agenda-year-view
  2023. :active (org-agenda-check-type nil 'agenda)
  2024. :style radio :selected (eq org-agenda-current-span 'year)
  2025. :keys "v y"]
  2026. "--"
  2027. ["Include Diary" org-agenda-toggle-diary
  2028. :style toggle :selected org-agenda-include-diary
  2029. :active (org-agenda-check-type nil 'agenda)]
  2030. ["Include Deadlines" org-agenda-toggle-deadlines
  2031. :style toggle :selected org-agenda-include-deadlines
  2032. :active (org-agenda-check-type nil 'agenda)]
  2033. ["Use Time Grid" org-agenda-toggle-time-grid
  2034. :style toggle :selected org-agenda-use-time-grid
  2035. :active (org-agenda-check-type nil 'agenda)]
  2036. "--"
  2037. ["Show clock report" org-agenda-clockreport-mode
  2038. :style toggle :selected org-agenda-clockreport-mode
  2039. :active (org-agenda-check-type nil 'agenda)]
  2040. ["Show some entry text" org-agenda-entry-text-mode
  2041. :style toggle :selected org-agenda-entry-text-mode
  2042. :active t]
  2043. "--"
  2044. ["Show Logbook entries" org-agenda-log-mode
  2045. :style toggle :selected org-agenda-show-log
  2046. :active (org-agenda-check-type nil 'agenda 'timeline)
  2047. :keys "v l (or just l)"]
  2048. ["Include archived trees" org-agenda-archives-mode
  2049. :style toggle :selected org-agenda-archives-mode :active t
  2050. :keys "v a"]
  2051. ["Include archive files" (org-agenda-archives-mode t)
  2052. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2053. :keys "v A"]
  2054. "--"
  2055. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2056. ["Write view to file" org-agenda-write t]
  2057. ["Rebuild buffer" org-agenda-redo t]
  2058. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2059. "--"
  2060. ["Show original entry" org-agenda-show t]
  2061. ["Go To (other window)" org-agenda-goto t]
  2062. ["Go To (this window)" org-agenda-switch-to t]
  2063. ["Capture with cursor date" org-agenda-capture t]
  2064. ["Follow Mode" org-agenda-follow-mode
  2065. :style toggle :selected org-agenda-follow-mode :active t]
  2066. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2067. "--"
  2068. ("TODO"
  2069. ["Cycle TODO" org-agenda-todo t]
  2070. ["Next TODO set" org-agenda-todo-nextset t]
  2071. ["Previous TODO set" org-agenda-todo-previousset t]
  2072. ["Add note" org-agenda-add-note t])
  2073. ("Archive/Refile/Delete"
  2074. ["Archive default" org-agenda-archive-default t]
  2075. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2076. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2077. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2078. ["Archive subtree" org-agenda-archive t]
  2079. "--"
  2080. ["Refile" org-agenda-refile t]
  2081. "--"
  2082. ["Delete subtree" org-agenda-kill t])
  2083. ("Bulk action"
  2084. ["Mark entry" org-agenda-bulk-mark t]
  2085. ["Mark all" org-agenda-bulk-mark-all t]
  2086. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2087. ["Unmark entry" org-agenda-bulk-unmark t]
  2088. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2089. ["Act on all marked" org-agenda-bulk-action t]
  2090. "--"
  2091. ("Tags and Properties"
  2092. ["Show all Tags" org-agenda-show-tags t]
  2093. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2094. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2095. "--"
  2096. ["Column View" org-columns t])
  2097. ("Deadline/Schedule"
  2098. ["Schedule" org-agenda-schedule t]
  2099. ["Set Deadline" org-agenda-deadline t]
  2100. "--"
  2101. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2102. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2103. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2104. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2105. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2106. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2107. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2108. ("Clock and Effort"
  2109. ["Clock in" org-agenda-clock-in t]
  2110. ["Clock out" org-agenda-clock-out t]
  2111. ["Clock cancel" org-agenda-clock-cancel t]
  2112. ["Goto running clock" org-clock-goto t]
  2113. "--"
  2114. ["Set Effort" org-agenda-set-effort t]
  2115. ["Change clocked effort" org-clock-modify-effort-estimate
  2116. (org-clock-is-active)])
  2117. ("Priority"
  2118. ["Set Priority" org-agenda-priority t]
  2119. ["Increase Priority" org-agenda-priority-up t]
  2120. ["Decrease Priority" org-agenda-priority-down t]
  2121. ["Show Priority" org-show-priority t])
  2122. ("Calendar/Diary"
  2123. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2124. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2125. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2126. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2127. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2128. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2129. "--"
  2130. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2131. "--"
  2132. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2133. "--"
  2134. ("MobileOrg"
  2135. ["Push Files and Views" org-mobile-push t]
  2136. ["Get Captured and Flagged" org-mobile-pull t]
  2137. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2138. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2139. "--"
  2140. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2141. "--"
  2142. ["Quit" org-agenda-quit t]
  2143. ["Exit and Release Buffers" org-agenda-exit t]
  2144. ))
  2145. ;;; Agenda undo
  2146. (defvar org-agenda-allow-remote-undo t
  2147. "Non-nil means allow remote undo from the agenda buffer.")
  2148. (defvar org-agenda-undo-has-started-in nil
  2149. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2150. (defun org-agenda-undo ()
  2151. "Undo a remote editing step in the agenda.
  2152. This undoes changes both in the agenda buffer and in the remote buffer
  2153. that have been changed along."
  2154. (interactive)
  2155. (or org-agenda-allow-remote-undo
  2156. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2157. (if (not (eq this-command last-command))
  2158. (setq org-agenda-undo-has-started-in nil
  2159. org-agenda-pending-undo-list org-agenda-undo-list))
  2160. (if (not org-agenda-pending-undo-list)
  2161. (error "No further undo information"))
  2162. (let* ((entry (pop org-agenda-pending-undo-list))
  2163. buf line cmd rembuf)
  2164. (setq cmd (pop entry) line (pop entry))
  2165. (setq rembuf (nth 2 entry))
  2166. (org-with-remote-undo rembuf
  2167. (while (bufferp (setq buf (pop entry)))
  2168. (if (pop entry)
  2169. (with-current-buffer buf
  2170. (let ((last-undo-buffer buf)
  2171. (inhibit-read-only t))
  2172. (unless (memq buf org-agenda-undo-has-started-in)
  2173. (push buf org-agenda-undo-has-started-in)
  2174. (make-local-variable 'pending-undo-list)
  2175. (undo-start))
  2176. (while (and pending-undo-list
  2177. (listp pending-undo-list)
  2178. (not (car pending-undo-list)))
  2179. (pop pending-undo-list))
  2180. (undo-more 1))))))
  2181. (org-goto-line line)
  2182. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2183. (defun org-verify-change-for-undo (l1 l2)
  2184. "Verify that a real change occurred between the undo lists L1 and L2."
  2185. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2186. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2187. (not (eq l1 l2)))
  2188. ;;; Agenda dispatch
  2189. (defvar org-agenda-restrict-begin (make-marker))
  2190. (defvar org-agenda-restrict-end (make-marker))
  2191. (defvar org-agenda-last-dispatch-buffer nil)
  2192. (defvar org-agenda-overriding-restriction nil)
  2193. (defcustom org-agenda-custom-commands-contexts nil
  2194. "Alist of custom agenda keys and contextual rules.
  2195. For example, if you have a custom agenda command \"p\" and you
  2196. want this command to be accessible only from plain text files,
  2197. use this:
  2198. '((\"p\" ((in-file . \"\\.txt\"))))
  2199. Here are the available contexts definitions:
  2200. in-file: command displayed only in matching files
  2201. in-mode: command displayed only in matching modes
  2202. not-in-file: command not displayed in matching files
  2203. not-in-mode: command not displayed in matching modes
  2204. in-buffer: command displayed only in matching buffers
  2205. not-in-buffer: command not displayed in matching buffers
  2206. [function]: a custom function taking no argument
  2207. If you define several checks, the agenda command will be
  2208. accessible if there is at least one valid check.
  2209. You can also bind a key to another agenda custom command
  2210. depending on contextual rules.
  2211. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2212. Here it means: in .txt files, use \"p\" as the key for the
  2213. agenda command otherwise associated with \"q\". (The command
  2214. originally associated with \"q\" is not displayed to avoid
  2215. duplicates.)"
  2216. :version "24.3"
  2217. :group 'org-agenda-custom-commands
  2218. :type '(repeat (list :tag "Rule"
  2219. (string :tag " Agenda key")
  2220. (string :tag "Replace by command")
  2221. (repeat :tag "Available when"
  2222. (choice
  2223. (cons :tag "Condition"
  2224. (choice
  2225. (const :tag "In file" in-file)
  2226. (const :tag "Not in file" not-in-file)
  2227. (const :tag "In buffer" in-buffer)
  2228. (const :tag "Not in buffer" not-in-buffer)
  2229. (const :tag "In mode" in-mode)
  2230. (const :tag "Not in mode" not-in-mode))
  2231. (regexp))
  2232. (function :tag "Custom function"))))))
  2233. (defcustom org-agenda-max-entries nil
  2234. "Maximum number of entries to display in an agenda.
  2235. This can be nil (no limit) or an integer or an alist of agenda
  2236. types with an associated number of entries to display in this
  2237. type."
  2238. :version "24.4"
  2239. :package-version '(Org . "8.0")
  2240. :group 'org-agenda-custom-commands
  2241. :type '(choice (symbol :tag "No limit" nil)
  2242. (integer :tag "Max number of entries")
  2243. (repeat
  2244. (cons (choice :tag "Agenda type"
  2245. (const agenda)
  2246. (const todo)
  2247. (const tags)
  2248. (const search)
  2249. (const timeline))
  2250. (integer :tag "Max number of entries")))))
  2251. (defcustom org-agenda-max-todos nil
  2252. "Maximum number of TODOs to display in an agenda.
  2253. This can be nil (no limit) or an integer or an alist of agenda
  2254. types with an associated number of entries to display in this
  2255. type."
  2256. :version "24.4"
  2257. :package-version '(Org . "8.0")
  2258. :group 'org-agenda-custom-commands
  2259. :type '(choice (symbol :tag "No limit" nil)
  2260. (integer :tag "Max number of entries")
  2261. (repeat
  2262. (cons (choice :tag "Agenda type"
  2263. (const agenda)
  2264. (const todo)
  2265. (const tags)
  2266. (const search)
  2267. (const timeline))
  2268. (integer :tag "Max number of entries")))))
  2269. (defcustom org-agenda-max-tags nil
  2270. "Maximum number of tagged entries to display in an agenda.
  2271. This can be nil (no limit) or an integer or an alist of agenda
  2272. types with an associated number of entries to display in this
  2273. type."
  2274. :version "24.4"
  2275. :package-version '(Org . "8.0")
  2276. :group 'org-agenda-custom-commands
  2277. :type '(choice (symbol :tag "No limit" nil)
  2278. (integer :tag "Max number of entries")
  2279. (repeat
  2280. (cons (choice :tag "Agenda type"
  2281. (const agenda)
  2282. (const todo)
  2283. (const tags)
  2284. (const search)
  2285. (const timeline))
  2286. (integer :tag "Max number of entries")))))
  2287. (defcustom org-agenda-max-effort nil
  2288. "Maximum cumulated effort duration for the agenda.
  2289. This can be nil (no limit) or a number of minutes (as an integer)
  2290. or an alist of agenda types with an associated number of minutes
  2291. to limit entries to in this type."
  2292. :version "24.4"
  2293. :package-version '(Org . "8.0")
  2294. :group 'org-agenda-custom-commands
  2295. :type '(choice (symbol :tag "No limit" nil)
  2296. (integer :tag "Max number of entries")
  2297. (repeat
  2298. (cons (choice :tag "Agenda type"
  2299. (const agenda)
  2300. (const todo)
  2301. (const tags)
  2302. (const search)
  2303. (const timeline))
  2304. (integer :tag "Max number of entries")))))
  2305. (defvar org-keys nil)
  2306. (defvar org-match nil)
  2307. ;;;###autoload
  2308. (defun org-agenda (&optional arg org-keys restriction)
  2309. "Dispatch agenda commands to collect entries to the agenda buffer.
  2310. Prompts for a command to execute. Any prefix arg will be passed
  2311. on to the selected command. The default selections are:
  2312. a Call `org-agenda-list' to display the agenda for current day or week.
  2313. t Call `org-todo-list' to display the global todo list.
  2314. T Call `org-todo-list' to display the global todo list, select only
  2315. entries with a specific TODO keyword (the user gets a prompt).
  2316. m Call `org-tags-view' to display headlines with tags matching
  2317. a condition (the user is prompted for the condition).
  2318. M Like `m', but select only TODO entries, no ordinary headlines.
  2319. L Create a timeline for the current buffer.
  2320. e Export views to associated files.
  2321. s Search entries for keywords.
  2322. S Search entries for keywords, only with TODO keywords.
  2323. / Multi occur across all agenda files and also files listed
  2324. in `org-agenda-text-search-extra-files'.
  2325. < Restrict agenda commands to buffer, subtree, or region.
  2326. Press several times to get the desired effect.
  2327. > Remove a previous restriction.
  2328. # List \"stuck\" projects.
  2329. ! Configure what \"stuck\" means.
  2330. C Configure custom agenda commands.
  2331. More commands can be added by configuring the variable
  2332. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2333. searches can be pre-defined in this way.
  2334. If the current buffer is in Org-mode and visiting a file, you can also
  2335. first press `<' once to indicate that the agenda should be temporarily
  2336. \(until the next use of \\[org-agenda]) restricted to the current file.
  2337. Pressing `<' twice means to restrict to the current subtree or region
  2338. \(if active)."
  2339. (interactive "P")
  2340. (catch 'exit
  2341. (let* ((prefix-descriptions nil)
  2342. (org-agenda-buffer-name org-agenda-buffer-name)
  2343. (org-agenda-window-setup (if (equal (buffer-name)
  2344. org-agenda-buffer-name)
  2345. 'current-window
  2346. org-agenda-window-setup))
  2347. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2348. (org-agenda-custom-commands
  2349. ;; normalize different versions
  2350. (delq nil
  2351. (mapcar
  2352. (lambda (x)
  2353. (cond ((stringp (cdr x))
  2354. (push x prefix-descriptions)
  2355. nil)
  2356. ((stringp (nth 1 x)) x)
  2357. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2358. (t (cons (car x) (cons "" (cdr x))))))
  2359. org-agenda-custom-commands)))
  2360. (org-agenda-custom-commands
  2361. (org-contextualize-keys
  2362. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2363. (buf (current-buffer))
  2364. (bfn (buffer-file-name (buffer-base-buffer)))
  2365. entry key type org-match lprops ans)
  2366. ;; Turn off restriction unless there is an overriding one,
  2367. (unless org-agenda-overriding-restriction
  2368. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2369. ;; There is a request to keep the file list in place
  2370. (put 'org-agenda-files 'org-restrict nil))
  2371. (setq org-agenda-restrict nil)
  2372. (move-marker org-agenda-restrict-begin nil)
  2373. (move-marker org-agenda-restrict-end nil))
  2374. ;; Delete old local properties
  2375. (put 'org-agenda-redo-command 'org-lprops nil)
  2376. ;; Delete previously set last-arguments
  2377. (put 'org-agenda-redo-command 'last-args nil)
  2378. ;; Remember where this call originated
  2379. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2380. (unless org-keys
  2381. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2382. org-keys (car ans)
  2383. restriction (cdr ans)))
  2384. ;; If we have sticky agenda buffers, set a name for the buffer,
  2385. ;; depending on the invoking keys. The user may still set this
  2386. ;; as a command option, which will overwrite what we do here.
  2387. (if org-agenda-sticky
  2388. (setq org-agenda-buffer-name
  2389. (format "*Org Agenda(%s)*" org-keys)))
  2390. ;; Establish the restriction, if any
  2391. (when (and (not org-agenda-overriding-restriction) restriction)
  2392. (put 'org-agenda-files 'org-restrict (list bfn))
  2393. (cond
  2394. ((eq restriction 'region)
  2395. (setq org-agenda-restrict t)
  2396. (move-marker org-agenda-restrict-begin (region-beginning))
  2397. (move-marker org-agenda-restrict-end (region-end)))
  2398. ((eq restriction 'subtree)
  2399. (save-excursion
  2400. (setq org-agenda-restrict t)
  2401. (org-back-to-heading t)
  2402. (move-marker org-agenda-restrict-begin (point))
  2403. (move-marker org-agenda-restrict-end
  2404. (progn (org-end-of-subtree t)))))))
  2405. ;; For example the todo list should not need it (but does...)
  2406. (cond
  2407. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2408. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2409. (progn
  2410. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2411. lprops (nth 4 entry))
  2412. (if org-agenda-sticky
  2413. (setq org-agenda-buffer-name
  2414. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2415. (format "*Org Agenda(%s)*" org-keys))))
  2416. (put 'org-agenda-redo-command 'org-lprops lprops)
  2417. (cond
  2418. ((eq type 'agenda)
  2419. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2420. ((eq type 'alltodo)
  2421. (org-let lprops '(org-todo-list current-prefix-arg)))
  2422. ((eq type 'search)
  2423. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2424. ((eq type 'stuck)
  2425. (org-let lprops '(org-agenda-list-stuck-projects
  2426. current-prefix-arg)))
  2427. ((eq type 'tags)
  2428. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2429. ((eq type 'tags-todo)
  2430. (org-let lprops '(org-tags-view '(4) org-match)))
  2431. ((eq type 'todo)
  2432. (org-let lprops '(org-todo-list org-match)))
  2433. ((eq type 'tags-tree)
  2434. (org-check-for-org-mode)
  2435. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2436. ((eq type 'todo-tree)
  2437. (org-check-for-org-mode)
  2438. (org-let lprops
  2439. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2440. (regexp-quote org-match) "\\>"))))
  2441. ((eq type 'occur-tree)
  2442. (org-check-for-org-mode)
  2443. (org-let lprops '(org-occur org-match)))
  2444. ((functionp type)
  2445. (org-let lprops '(funcall type org-match)))
  2446. ((fboundp type)
  2447. (org-let lprops '(funcall type org-match)))
  2448. (t (error "Invalid custom agenda command type %s" type))))
  2449. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2450. ((equal org-keys "C")
  2451. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2452. (customize-variable 'org-agenda-custom-commands))
  2453. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2454. ((equal org-keys "s") (call-interactively 'org-search-view))
  2455. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2456. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2457. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2458. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2459. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2460. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2461. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2462. (org-add-hook
  2463. 'post-command-hook
  2464. (lambda ()
  2465. (unless (current-message)
  2466. (let* ((m (org-agenda-get-any-marker))
  2467. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2468. (when note
  2469. (message (concat
  2470. "FLAGGING-NOTE ([?] for more info): "
  2471. (org-add-props
  2472. (replace-regexp-in-string
  2473. "\\\\n" "//"
  2474. (copy-sequence note))
  2475. nil 'face 'org-warning)))))))
  2476. t t))
  2477. ((equal org-keys "L")
  2478. (unless (derived-mode-p 'org-mode)
  2479. (error "This is not an Org-mode file"))
  2480. (unless restriction
  2481. (put 'org-agenda-files 'org-restrict (list bfn))
  2482. (org-call-with-arg 'org-timeline arg)))
  2483. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2484. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2485. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2486. (t (error "Invalid agenda key"))))))
  2487. (defun org-agenda-append-agenda ()
  2488. "Append another agenda view to the current one.
  2489. This function allows interactive building of block agendas.
  2490. Agenda views are separated by `org-agenda-block-separator'."
  2491. (interactive)
  2492. (unless (derived-mode-p 'org-agenda-mode)
  2493. (error "Can only append from within agenda buffer"))
  2494. (let ((org-agenda-multi t))
  2495. (org-agenda)
  2496. (widen)
  2497. (org-agenda-finalize)
  2498. (org-agenda-fit-window-to-buffer)))
  2499. (defun org-agenda-normalize-custom-commands (cmds)
  2500. "Normalize custom commands CMDS."
  2501. (delq nil
  2502. (mapcar
  2503. (lambda (x)
  2504. (cond ((stringp (cdr x)) nil)
  2505. ((stringp (nth 1 x)) x)
  2506. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2507. (t (cons (car x) (cons "" (cdr x))))))
  2508. cmds)))
  2509. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2510. "The user interface for selecting an agenda command."
  2511. (catch 'exit
  2512. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2513. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2514. (region-p (org-region-active-p))
  2515. (custom org-agenda-custom-commands)
  2516. (selstring "")
  2517. restriction second-time
  2518. c entry key type match prefixes rmheader header-end custom1 desc
  2519. line lines left right n n1)
  2520. (save-window-excursion
  2521. (delete-other-windows)
  2522. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2523. (erase-buffer)
  2524. (insert (eval-when-compile
  2525. (let ((header
  2526. "Press key for an agenda command: < Buffer, subtree/region restriction
  2527. -------------------------------- > Remove restriction
  2528. a Agenda for current week or day e Export agenda views
  2529. t List of all TODO entries T Entries with special TODO kwd
  2530. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2531. s Search for keywords S Like s, but only TODO entries
  2532. L Timeline for current buffer # List stuck projects (!=configure)
  2533. / Multi-occur C Configure custom agenda commands
  2534. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2535. ")
  2536. (start 0))
  2537. (while (string-match
  2538. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2539. header start)
  2540. (setq start (match-end 0))
  2541. (add-text-properties (match-beginning 2) (match-end 2)
  2542. '(face bold) header))
  2543. header)))
  2544. (setq header-end (point-marker))
  2545. (while t
  2546. (setq custom1 custom)
  2547. (when (eq rmheader t)
  2548. (org-goto-line 1)
  2549. (re-search-forward ":" nil t)
  2550. (delete-region (match-end 0) (point-at-eol))
  2551. (forward-char 1)
  2552. (looking-at "-+")
  2553. (delete-region (match-end 0) (point-at-eol))
  2554. (move-marker header-end (match-end 0)))
  2555. (goto-char header-end)
  2556. (delete-region (point) (point-max))
  2557. ;; Produce all the lines that describe custom commands and prefixes
  2558. (setq lines nil)
  2559. (while (setq entry (pop custom1))
  2560. (setq key (car entry) desc (nth 1 entry)
  2561. type (nth 2 entry)
  2562. match (nth 3 entry))
  2563. (if (> (length key) 1)
  2564. (add-to-list 'prefixes (string-to-char key))
  2565. (setq line
  2566. (format
  2567. "%-4s%-14s"
  2568. (org-add-props (copy-sequence key)
  2569. '(face bold))
  2570. (cond
  2571. ((string-match "\\S-" desc) desc)
  2572. ((eq type 'agenda) "Agenda for current week or day")
  2573. ((eq type 'alltodo) "List of all TODO entries")
  2574. ((eq type 'search) "Word search")
  2575. ((eq type 'stuck) "List of stuck projects")
  2576. ((eq type 'todo) "TODO keyword")
  2577. ((eq type 'tags) "Tags query")
  2578. ((eq type 'tags-todo) "Tags (TODO)")
  2579. ((eq type 'tags-tree) "Tags tree")
  2580. ((eq type 'todo-tree) "TODO kwd tree")
  2581. ((eq type 'occur-tree) "Occur tree")
  2582. ((functionp type) (if (symbolp type)
  2583. (symbol-name type)
  2584. "Lambda expression"))
  2585. (t "???"))))
  2586. (if org-agenda-menu-show-matcher
  2587. (setq line
  2588. (concat line ": "
  2589. (cond
  2590. ((stringp match)
  2591. (setq match (copy-sequence match))
  2592. (org-add-props match nil 'face 'org-warning))
  2593. ((listp type)
  2594. (format "set of %d commands" (length type))))))
  2595. (if (org-string-nw-p match)
  2596. (add-text-properties
  2597. 0 (length line) (list 'help-echo
  2598. (concat "Matcher: " match)) line)))
  2599. (push line lines)))
  2600. (setq lines (nreverse lines))
  2601. (when prefixes
  2602. (mapc (lambda (x)
  2603. (push
  2604. (format "%s %s"
  2605. (org-add-props (char-to-string x)
  2606. nil 'face 'bold)
  2607. (or (cdr (assoc (concat selstring
  2608. (char-to-string x))
  2609. prefix-descriptions))
  2610. "Prefix key"))
  2611. lines))
  2612. prefixes))
  2613. ;; Check if we should display in two columns
  2614. (if org-agenda-menu-two-columns
  2615. (progn
  2616. (setq n (length lines)
  2617. n1 (+ (/ n 2) (mod n 2))
  2618. right (nthcdr n1 lines)
  2619. left (copy-sequence lines))
  2620. (setcdr (nthcdr (1- n1) left) nil))
  2621. (setq left lines right nil))
  2622. (while left
  2623. (insert "\n" (pop left))
  2624. (when right
  2625. (if (< (current-column) 40)
  2626. (move-to-column 40 t)
  2627. (insert " "))
  2628. (insert (pop right))))
  2629. ;; Make the window the right size
  2630. (goto-char (point-min))
  2631. (if second-time
  2632. (if (not (pos-visible-in-window-p (point-max)))
  2633. (org-fit-window-to-buffer))
  2634. (setq second-time t)
  2635. (org-fit-window-to-buffer))
  2636. ;; Ask for selection
  2637. (message "Press key for agenda command%s:"
  2638. (if (or restrict-ok org-agenda-overriding-restriction)
  2639. (if org-agenda-overriding-restriction
  2640. " (restriction lock active)"
  2641. (if restriction
  2642. (format " (restricted to %s)" restriction)
  2643. " (unrestricted)"))
  2644. ""))
  2645. (setq c (read-char-exclusive))
  2646. (message "")
  2647. (cond
  2648. ((assoc (char-to-string c) custom)
  2649. (setq selstring (concat selstring (char-to-string c)))
  2650. (throw 'exit (cons selstring restriction)))
  2651. ((memq c prefixes)
  2652. (setq selstring (concat selstring (char-to-string c))
  2653. prefixes nil
  2654. rmheader (or rmheader t)
  2655. custom (delq nil (mapcar
  2656. (lambda (x)
  2657. (if (or (= (length (car x)) 1)
  2658. (/= (string-to-char (car x)) c))
  2659. nil
  2660. (cons (substring (car x) 1) (cdr x))))
  2661. custom))))
  2662. ((eq c ?*)
  2663. (call-interactively 'org-toggle-sticky-agenda)
  2664. (sit-for 2))
  2665. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2666. (message "Restriction is only possible in Org-mode buffers")
  2667. (ding) (sit-for 1))
  2668. ((eq c ?1)
  2669. (org-agenda-remove-restriction-lock 'noupdate)
  2670. (setq restriction 'buffer))
  2671. ((eq c ?0)
  2672. (org-agenda-remove-restriction-lock 'noupdate)
  2673. (setq restriction (if region-p 'region 'subtree)))
  2674. ((eq c ?<)
  2675. (org-agenda-remove-restriction-lock 'noupdate)
  2676. (setq restriction
  2677. (cond
  2678. ((eq restriction 'buffer)
  2679. (if region-p 'region 'subtree))
  2680. ((memq restriction '(subtree region))
  2681. nil)
  2682. (t 'buffer))))
  2683. ((eq c ?>)
  2684. (org-agenda-remove-restriction-lock 'noupdate)
  2685. (setq restriction nil))
  2686. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2687. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2688. ((and (> (length selstring) 0) (eq c ?\d))
  2689. (delete-window)
  2690. (org-agenda-get-restriction-and-command prefix-descriptions))
  2691. ((equal c ?q) (error "Abort"))
  2692. (t (error "Invalid key %c" c))))))))
  2693. (defun org-agenda-fit-window-to-buffer ()
  2694. "Fit the window to the buffer size."
  2695. (and (memq org-agenda-window-setup '(reorganize-frame))
  2696. (fboundp 'fit-window-to-buffer)
  2697. (org-fit-window-to-buffer
  2698. nil
  2699. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2700. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2701. (defvar org-cmd nil)
  2702. (defvar org-agenda-overriding-cmd nil)
  2703. (defvar org-agenda-overriding-arguments nil)
  2704. (defvar org-agenda-overriding-cmd-arguments nil)
  2705. (defun org-agenda-run-series (name series)
  2706. "Run agenda NAME as a SERIES of agenda commands."
  2707. (org-let (nth 1 series) '(org-agenda-prepare name))
  2708. ;; We need to reset agenda markers here, because when constructing a
  2709. ;; block agenda, the individual blocks do not do that.
  2710. (org-agenda-reset-markers)
  2711. (let* ((org-agenda-multi t)
  2712. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2713. (cmds (car series))
  2714. (gprops (nth 1 series))
  2715. match ;; The byte compiler incorrectly complains about this. Keep it!
  2716. org-cmd type lprops)
  2717. (while (setq org-cmd (pop cmds))
  2718. (setq type (car org-cmd)
  2719. match (eval (nth 1 org-cmd))
  2720. lprops (nth 2 org-cmd))
  2721. (let ((org-agenda-overriding-arguments
  2722. (if (eq org-agenda-overriding-cmd org-cmd)
  2723. (or org-agenda-overriding-arguments
  2724. org-agenda-overriding-cmd-arguments))))
  2725. (cond
  2726. ((eq type 'agenda)
  2727. (org-let2 gprops lprops
  2728. '(call-interactively 'org-agenda-list)))
  2729. ((eq type 'alltodo)
  2730. (org-let2 gprops lprops
  2731. '(call-interactively 'org-todo-list)))
  2732. ((eq type 'search)
  2733. (org-let2 gprops lprops
  2734. '(org-search-view current-prefix-arg match nil)))
  2735. ((eq type 'stuck)
  2736. (org-let2 gprops lprops
  2737. '(call-interactively 'org-agenda-list-stuck-projects)))
  2738. ((eq type 'tags)
  2739. (org-let2 gprops lprops
  2740. '(org-tags-view current-prefix-arg match)))
  2741. ((eq type 'tags-todo)
  2742. (org-let2 gprops lprops
  2743. '(org-tags-view '(4) match)))
  2744. ((eq type 'todo)
  2745. (org-let2 gprops lprops
  2746. '(org-todo-list match)))
  2747. ((fboundp type)
  2748. (org-let2 gprops lprops
  2749. '(funcall type match)))
  2750. (t (error "Invalid type in command series")))))
  2751. (widen)
  2752. (let ((inhibit-read-only t))
  2753. (add-text-properties (point-min) (point-max)
  2754. `(org-series t org-series-redo-cmd ,redo)))
  2755. (setq org-agenda-redo-command redo)
  2756. (goto-char (point-min)))
  2757. (org-agenda-fit-window-to-buffer)
  2758. (org-let (nth 1 series) '(org-agenda-finalize)))
  2759. ;;;###autoload
  2760. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2761. "Run an agenda command in batch mode and send the result to STDOUT.
  2762. If CMD-KEY is a string of length 1, it is used as a key in
  2763. `org-agenda-custom-commands' and triggers this command. If it is a
  2764. longer string it is used as a tags/todo match string.
  2765. Parameters are alternating variable names and values that will be bound
  2766. before running the agenda command."
  2767. (org-eval-in-environment (org-make-parameter-alist parameters)
  2768. (if (> (length cmd-key) 2)
  2769. (org-tags-view nil cmd-key)
  2770. (org-agenda nil cmd-key)))
  2771. (set-buffer org-agenda-buffer-name)
  2772. (princ (buffer-string)))
  2773. (defvar org-agenda-info nil)
  2774. ;;;###autoload
  2775. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2776. "Run an agenda command in batch mode and send the result to STDOUT.
  2777. If CMD-KEY is a string of length 1, it is used as a key in
  2778. `org-agenda-custom-commands' and triggers this command. If it is a
  2779. longer string it is used as a tags/todo match string.
  2780. Parameters are alternating variable names and values that will be bound
  2781. before running the agenda command.
  2782. The output gives a line for each selected agenda item. Each
  2783. item is a list of comma-separated values, like this:
  2784. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2785. category The category of the item
  2786. head The headline, without TODO kwd, TAGS and PRIORITY
  2787. type The type of the agenda entry, can be
  2788. todo selected in TODO match
  2789. tagsmatch selected in tags match
  2790. diary imported from diary
  2791. deadline a deadline on given date
  2792. scheduled scheduled on given date
  2793. timestamp entry has timestamp on given date
  2794. closed entry was closed on given date
  2795. upcoming-deadline warning about deadline
  2796. past-scheduled forwarded scheduled item
  2797. block entry has date block including g. date
  2798. todo The todo keyword, if any
  2799. tags All tags including inherited ones, separated by colons
  2800. date The relevant date, like 2007-2-14
  2801. time The time, like 15:00-16:50
  2802. extra Sting with extra planning info
  2803. priority-l The priority letter if any was given
  2804. priority-n The computed numerical priority
  2805. agenda-day The day in the agenda where this is listed"
  2806. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2807. (org-make-parameter-alist parameters))
  2808. (if (> (length cmd-key) 2)
  2809. (org-tags-view nil cmd-key)
  2810. (org-agenda nil cmd-key)))
  2811. (set-buffer org-agenda-buffer-name)
  2812. (let* ((lines (org-split-string (buffer-string) "\n"))
  2813. line)
  2814. (while (setq line (pop lines))
  2815. (catch 'next
  2816. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2817. (setq org-agenda-info
  2818. (org-fix-agenda-info (text-properties-at 0 line)))
  2819. (princ
  2820. (mapconcat 'org-agenda-export-csv-mapper
  2821. '(org-category txt type todo tags date time extra
  2822. priority-letter priority agenda-day)
  2823. ","))
  2824. (princ "\n")))))
  2825. (defun org-fix-agenda-info (props)
  2826. "Make sure all properties on an agenda item have a canonical form.
  2827. This ensures the export commands can easily use it."
  2828. (let (tmp re)
  2829. (when (setq tmp (plist-get props 'tags))
  2830. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2831. (when (setq tmp (plist-get props 'date))
  2832. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2833. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2834. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2835. (setq tmp (calendar-date-string tmp)))
  2836. (setq props (plist-put props 'date tmp)))
  2837. (when (setq tmp (plist-get props 'day))
  2838. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2839. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2840. (setq tmp (calendar-date-string tmp)))
  2841. (setq props (plist-put props 'day tmp))
  2842. (setq props (plist-put props 'agenda-day tmp)))
  2843. (when (setq tmp (plist-get props 'txt))
  2844. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2845. (plist-put props 'priority-letter (match-string 1 tmp))
  2846. (setq tmp (replace-match "" t t tmp)))
  2847. (when (and (setq re (plist-get props 'org-todo-regexp))
  2848. (setq re (concat "\\`\\.*" re " ?"))
  2849. (string-match re tmp))
  2850. (plist-put props 'todo (match-string 1 tmp))
  2851. (setq tmp (replace-match "" t t tmp)))
  2852. (plist-put props 'txt tmp)))
  2853. props)
  2854. (defun org-agenda-export-csv-mapper (prop)
  2855. (let ((res (plist-get org-agenda-info prop)))
  2856. (setq res
  2857. (cond
  2858. ((not res) "")
  2859. ((stringp res) res)
  2860. (t (prin1-to-string res))))
  2861. (while (string-match "," res)
  2862. (setq res (replace-match ";" t t res)))
  2863. (org-trim res)))
  2864. ;;;###autoload
  2865. (defun org-store-agenda-views (&rest parameters)
  2866. "Store agenda views."
  2867. (interactive)
  2868. (eval (list 'org-batch-store-agenda-views)))
  2869. ;;;###autoload
  2870. (defmacro org-batch-store-agenda-views (&rest parameters)
  2871. "Run all custom agenda commands that have a file argument."
  2872. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2873. (pop-up-frames nil)
  2874. (dir default-directory)
  2875. (pars (org-make-parameter-alist parameters))
  2876. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2877. (save-window-excursion
  2878. (while cmds
  2879. (setq cmd (pop cmds)
  2880. thiscmdkey (car cmd)
  2881. thiscmdcmd (cdr cmd)
  2882. match (nth 2 thiscmdcmd)
  2883. bufname (if org-agenda-sticky
  2884. (or (and (stringp match)
  2885. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2886. (format "*Org Agenda(%s)*" thiscmdkey))
  2887. org-agenda-buffer-name)
  2888. cmd-or-set (nth 2 cmd)
  2889. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2890. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2891. (if (stringp files) (setq files (list files)))
  2892. (when files
  2893. (org-eval-in-environment (append org-agenda-exporter-settings
  2894. opts pars)
  2895. (org-agenda nil thiscmdkey))
  2896. (set-buffer bufname)
  2897. (while files
  2898. (org-eval-in-environment (append org-agenda-exporter-settings
  2899. opts pars)
  2900. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2901. (and (get-buffer bufname)
  2902. (kill-buffer bufname)))))))
  2903. (defvar org-agenda-current-span nil
  2904. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2905. (defun org-agenda-mark-header-line (pos)
  2906. "Mark the line at POS as an agenda structure header."
  2907. (save-excursion
  2908. (goto-char pos)
  2909. (put-text-property (point-at-bol) (point-at-eol)
  2910. 'org-agenda-structural-header t)
  2911. (when org-agenda-title-append
  2912. (put-text-property (point-at-bol) (point-at-eol)
  2913. 'org-agenda-title-append org-agenda-title-append))))
  2914. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2915. (defvar org-agenda-write-buffer-name "Agenda View")
  2916. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2917. "Write the current buffer (an agenda view) as a file.
  2918. Depending on the extension of the file name, plain text (.txt),
  2919. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2920. If the extension is .ics, run icalendar export over all files used
  2921. to construct the agenda and limit the export to entries listed in the
  2922. agenda now.
  2923. If the extension is .org, collect all subtrees corresponding to the
  2924. agenda entries and add them in an .org file.
  2925. With prefix argument OPEN, open the new file immediately.
  2926. If NOSETTINGS is given, do not scope the settings of
  2927. `org-agenda-exporter-settings' into the export commands. This is used when
  2928. the settings have already been scoped and we do not wish to overrule other,
  2929. higher priority settings.
  2930. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2931. (interactive "FWrite agenda to file: \nP")
  2932. (if (or (not (file-writable-p file))
  2933. (and (file-exists-p file)
  2934. (if (called-interactively-p 'any)
  2935. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  2936. (error "Cannot write agenda to file %s" file))
  2937. (org-let (if nosettings nil org-agenda-exporter-settings)
  2938. '(save-excursion
  2939. (save-window-excursion
  2940. (org-agenda-mark-filtered-text)
  2941. (let ((bs (copy-sequence (buffer-string))) beg content)
  2942. (org-agenda-unmark-filtered-text)
  2943. (with-temp-buffer
  2944. (rename-buffer org-agenda-write-buffer-name t)
  2945. (set-buffer-modified-p nil)
  2946. (insert bs)
  2947. (org-agenda-remove-marked-text 'org-filtered)
  2948. (while (setq beg (text-property-any (point-min) (point-max)
  2949. 'org-filtered t))
  2950. (delete-region
  2951. beg (or (next-single-property-change beg 'org-filtered)
  2952. (point-max))))
  2953. (run-hooks 'org-agenda-before-write-hook)
  2954. (cond
  2955. ((org-bound-and-true-p org-mobile-creating-agendas)
  2956. (org-mobile-write-agenda-for-mobile file))
  2957. ((string-match "\\.org\\'" file)
  2958. (let (content p m message-log-max)
  2959. (goto-char (point-min))
  2960. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  2961. (goto-char p)
  2962. (setq m (get-text-property (point) 'org-hd-marker))
  2963. (when m
  2964. (push (save-excursion
  2965. (set-buffer (marker-buffer m))
  2966. (goto-char m)
  2967. (org-copy-subtree 1 nil t t)
  2968. org-subtree-clip)
  2969. content)))
  2970. (find-file file)
  2971. (erase-buffer)
  2972. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  2973. (write-file file)
  2974. (kill-buffer (current-buffer))
  2975. (message "Org file written to %s" file)))
  2976. ((string-match "\\.html?\\'" file)
  2977. (require 'htmlize)
  2978. (set-buffer (htmlize-buffer (current-buffer)))
  2979. (when org-agenda-export-html-style
  2980. ;; replace <style> section with org-agenda-export-html-style
  2981. (goto-char (point-min))
  2982. (kill-region (- (search-forward "<style") 6)
  2983. (search-forward "</style>"))
  2984. (insert org-agenda-export-html-style))
  2985. (write-file file)
  2986. (kill-buffer (current-buffer))
  2987. (message "HTML written to %s" file))
  2988. ((string-match "\\.ps\\'" file)
  2989. (require 'ps-print)
  2990. (ps-print-buffer-with-faces file)
  2991. (message "Postscript written to %s" file))
  2992. ((string-match "\\.pdf\\'" file)
  2993. (require 'ps-print)
  2994. (ps-print-buffer-with-faces
  2995. (concat (file-name-sans-extension file) ".ps"))
  2996. (call-process "ps2pdf" nil nil nil
  2997. (expand-file-name
  2998. (concat (file-name-sans-extension file) ".ps"))
  2999. (expand-file-name file))
  3000. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3001. (message "PDF written to %s" file))
  3002. ((string-match "\\.ics\\'" file)
  3003. (require 'ox-icalendar)
  3004. (org-icalendar-export-current-agenda (expand-file-name file)))
  3005. (t
  3006. (let ((bs (buffer-string)))
  3007. (find-file file)
  3008. (erase-buffer)
  3009. (insert bs)
  3010. (save-buffer 0)
  3011. (kill-buffer (current-buffer))
  3012. (message "Plain text written to %s" file))))))))
  3013. (set-buffer (or agenda-bufname
  3014. (and (org-called-interactively-p 'any) (buffer-name))
  3015. org-agenda-buffer-name)))
  3016. (when open (org-open-file file)))
  3017. (defvar org-agenda-tag-filter-overlays nil)
  3018. (defvar org-agenda-cat-filter-overlays nil)
  3019. (defun org-agenda-mark-filtered-text ()
  3020. "Mark all text hidden by filtering with a text property."
  3021. (let ((inhibit-read-only t))
  3022. (mapc
  3023. (lambda (o)
  3024. (when (equal (overlay-buffer o) (current-buffer))
  3025. (put-text-property
  3026. (overlay-start o) (overlay-end o)
  3027. 'org-filtered t)))
  3028. (append org-agenda-tag-filter-overlays
  3029. org-agenda-cat-filter-overlays))))
  3030. (defun org-agenda-unmark-filtered-text ()
  3031. "Remove the filtering text property."
  3032. (let ((inhibit-read-only t))
  3033. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3034. (defun org-agenda-remove-marked-text (property &optional value)
  3035. "Delete all text marked with VALUE of PROPERTY.
  3036. VALUE defaults to t."
  3037. (let (beg)
  3038. (setq value (or value t))
  3039. (while (setq beg (text-property-any (point-min) (point-max)
  3040. property value))
  3041. (delete-region
  3042. beg (or (next-single-property-change beg 'org-filtered)
  3043. (point-max))))))
  3044. (defun org-agenda-add-entry-text ()
  3045. "Add entry text to agenda lines.
  3046. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3047. entry text following headings shown in the agenda.
  3048. Drawers will be excluded, also the line with scheduling/deadline info."
  3049. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3050. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3051. (let (m txt)
  3052. (goto-char (point-min))
  3053. (while (not (eobp))
  3054. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3055. (beginning-of-line 2)
  3056. (setq txt (org-agenda-get-some-entry-text
  3057. m org-agenda-add-entry-text-maxlines " > "))
  3058. (end-of-line 1)
  3059. (if (string-match "\\S-" txt)
  3060. (insert "\n" txt)
  3061. (or (eobp) (forward-char 1))))))))
  3062. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3063. &rest keep)
  3064. "Extract entry text from MARKER, at most N-LINES lines.
  3065. This will ignore drawers etc, just get the text.
  3066. If INDENT is given, prefix every line with this string. If KEEP is
  3067. given, it is a list of symbols, defining stuff that should not be
  3068. removed from the entry content. Currently only `planning' is allowed here."
  3069. (let (txt drawer-re kwd-time-re ind)
  3070. (save-excursion
  3071. (with-current-buffer (marker-buffer marker)
  3072. (if (not (derived-mode-p 'org-mode))
  3073. (setq txt "")
  3074. (save-excursion
  3075. (save-restriction
  3076. (widen)
  3077. (goto-char marker)
  3078. (end-of-line 1)
  3079. (setq txt (buffer-substring
  3080. (min (1+ (point)) (point-max))
  3081. (progn (outline-next-heading) (point)))
  3082. drawer-re org-drawer-regexp
  3083. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3084. ".*\n?"))
  3085. (with-temp-buffer
  3086. (insert txt)
  3087. (when org-agenda-add-entry-text-descriptive-links
  3088. (goto-char (point-min))
  3089. (while (org-activate-bracket-links (point-max))
  3090. (add-text-properties (match-beginning 0) (match-end 0)
  3091. '(face org-link))))
  3092. (goto-char (point-min))
  3093. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3094. (set-text-properties (match-beginning 0) (match-end 0)
  3095. nil))
  3096. (goto-char (point-min))
  3097. (while (re-search-forward drawer-re nil t)
  3098. (delete-region
  3099. (match-beginning 0)
  3100. (progn (re-search-forward
  3101. "^[ \t]*:END:.*\n?" nil 'move)
  3102. (point))))
  3103. (unless (member 'planning keep)
  3104. (goto-char (point-min))
  3105. (while (re-search-forward kwd-time-re nil t)
  3106. (replace-match "")))
  3107. (goto-char (point-min))
  3108. (when org-agenda-entry-text-exclude-regexps
  3109. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3110. (while (setq re (pop re-list))
  3111. (goto-char (point-min))
  3112. (while (re-search-forward re nil t)
  3113. (replace-match "")))))
  3114. (goto-char (point-max))
  3115. (skip-chars-backward " \t\n")
  3116. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3117. ;; find and remove min common indentation
  3118. (goto-char (point-min))
  3119. (untabify (point-min) (point-max))
  3120. (setq ind (org-get-indentation))
  3121. (while (not (eobp))
  3122. (unless (looking-at "[ \t]*$")
  3123. (setq ind (min ind (org-get-indentation))))
  3124. (beginning-of-line 2))
  3125. (goto-char (point-min))
  3126. (while (not (eobp))
  3127. (unless (looking-at "[ \t]*$")
  3128. (move-to-column ind)
  3129. (delete-region (point-at-bol) (point)))
  3130. (beginning-of-line 2))
  3131. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3132. (goto-char (point-min))
  3133. (when indent
  3134. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3135. (replace-match indent t t)))
  3136. (goto-char (point-min))
  3137. (while (looking-at "[ \t]*\n") (replace-match ""))
  3138. (goto-char (point-max))
  3139. (when (> (org-current-line)
  3140. n-lines)
  3141. (org-goto-line (1+ n-lines))
  3142. (backward-char 1))
  3143. (setq txt (buffer-substring (point-min) (point)))))))))
  3144. txt))
  3145. (defun org-check-for-org-mode ()
  3146. "Make sure current buffer is in org-mode. Error if not."
  3147. (or (derived-mode-p 'org-mode)
  3148. (error "Cannot execute org-mode agenda command on buffer in %s"
  3149. major-mode)))
  3150. ;;; Agenda prepare and finalize
  3151. (defvar org-agenda-multi nil) ; dynamically scoped
  3152. (defvar org-agenda-pre-window-conf nil)
  3153. (defvar org-agenda-columns-active nil)
  3154. (defvar org-agenda-name nil)
  3155. (defvar org-agenda-tag-filter nil)
  3156. (defvar org-agenda-category-filter nil)
  3157. (defvar org-agenda-top-category-filter nil)
  3158. (defvar org-agenda-tag-filter-while-redo nil)
  3159. (defvar org-agenda-tag-filter-preset nil
  3160. "A preset of the tags filter used for secondary agenda filtering.
  3161. This must be a list of strings, each string must be a single tag preceded
  3162. 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. (defvar org-agenda-category-filter-preset nil
  3169. "A preset of the category filter used for secondary agenda filtering.
  3170. This must be a list of strings, each string must be a single category
  3171. preceded by \"+\" or \"-\".
  3172. This variable should not be set directly, but agenda custom commands can
  3173. bind it in the options section. The preset filter is a global property of
  3174. the entire agenda view. In a block agenda, it will not work reliably to
  3175. define a filter for one of the individual blocks. You need to set it in
  3176. the global options and expect it to be applied to the entire view.")
  3177. (defun org-agenda-use-sticky-p ()
  3178. "Return non-nil if an agenda buffer named
  3179. `org-agenda-buffer-name' exists and should be shown instead of
  3180. generating a new one."
  3181. (and
  3182. ;; turned off by user
  3183. org-agenda-sticky
  3184. ;; For multi-agenda buffer already exists
  3185. (not org-agenda-multi)
  3186. ;; buffer found
  3187. (get-buffer org-agenda-buffer-name)
  3188. ;; C-u parameter is same as last call
  3189. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3190. (and
  3191. (equal current-prefix-arg
  3192. org-agenda-last-prefix-arg)
  3193. ;; In case user turned stickiness on, while having existing
  3194. ;; Agenda buffer active, don't reuse that buffer, because it
  3195. ;; does not have org variables local
  3196. org-agenda-this-buffer-is-sticky))))
  3197. (defun org-agenda-prepare-window (abuf)
  3198. "Setup agenda buffer in the window."
  3199. (let* ((awin (get-buffer-window abuf))
  3200. wconf)
  3201. (cond
  3202. ((equal (current-buffer) abuf) nil)
  3203. (awin (select-window awin))
  3204. ((not (setq wconf (current-window-configuration))))
  3205. ((equal org-agenda-window-setup 'current-window)
  3206. (org-pop-to-buffer-same-window abuf))
  3207. ((equal org-agenda-window-setup 'other-window)
  3208. (org-switch-to-buffer-other-window abuf))
  3209. ((equal org-agenda-window-setup 'other-frame)
  3210. (switch-to-buffer-other-frame abuf))
  3211. ((equal org-agenda-window-setup 'reorganize-frame)
  3212. (delete-other-windows)
  3213. (org-switch-to-buffer-other-window abuf)))
  3214. ;; additional test in case agenda is invoked from within agenda
  3215. ;; buffer via elisp link
  3216. (unless (equal (current-buffer) abuf)
  3217. (org-pop-to-buffer-same-window abuf))
  3218. (setq org-agenda-pre-window-conf
  3219. (or org-agenda-pre-window-conf wconf))))
  3220. (defun org-agenda-prepare (&optional name)
  3221. (if (org-agenda-use-sticky-p)
  3222. (progn
  3223. ;; Popup existing buffer
  3224. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3225. (message "Sticky Agenda buffer, use `r' to refresh")
  3226. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3227. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3228. (setq org-todo-keywords-for-agenda nil)
  3229. (setq org-drawers-for-agenda nil)
  3230. (unless org-agenda-persistent-filter
  3231. (setq org-agenda-tag-filter nil
  3232. org-agenda-category-filter nil))
  3233. (put 'org-agenda-tag-filter :preset-filter
  3234. org-agenda-tag-filter-preset)
  3235. (put 'org-agenda-category-filter :preset-filter
  3236. org-agenda-category-filter-preset)
  3237. (if org-agenda-multi
  3238. (progn
  3239. (setq buffer-read-only nil)
  3240. (goto-char (point-max))
  3241. (unless (or (bobp) org-agenda-compact-blocks
  3242. (not org-agenda-block-separator))
  3243. (insert "\n"
  3244. (if (stringp org-agenda-block-separator)
  3245. org-agenda-block-separator
  3246. (make-string (window-width) org-agenda-block-separator))
  3247. "\n"))
  3248. (narrow-to-region (point) (point-max)))
  3249. (setq org-done-keywords-for-agenda nil)
  3250. ;; Setting any org variables that are in org-agenda-local-vars
  3251. ;; list need to be done after the prepare call
  3252. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3253. (setq buffer-read-only nil)
  3254. (org-agenda-reset-markers)
  3255. (let ((inhibit-read-only t)) (erase-buffer))
  3256. (org-agenda-mode)
  3257. (setq org-agenda-buffer (current-buffer))
  3258. (setq org-agenda-contributing-files nil)
  3259. (setq org-agenda-columns-active nil)
  3260. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3261. (setq org-todo-keywords-for-agenda
  3262. (org-uniquify org-todo-keywords-for-agenda))
  3263. (setq org-done-keywords-for-agenda
  3264. (org-uniquify org-done-keywords-for-agenda))
  3265. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3266. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3267. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3268. (and name (not org-agenda-name)
  3269. (org-set-local 'org-agenda-name name)))
  3270. (setq buffer-read-only nil)))
  3271. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3272. (defun org-agenda-finalize ()
  3273. "Finishing touch for the agenda buffer, called just before displaying it."
  3274. (unless org-agenda-multi
  3275. (save-excursion
  3276. (let ((inhibit-read-only t))
  3277. (goto-char (point-min))
  3278. (save-excursion
  3279. (while (org-activate-bracket-links (point-max))
  3280. (add-text-properties (match-beginning 0) (match-end 0)
  3281. '(face org-link))))
  3282. (save-excursion
  3283. (while (org-activate-plain-links (point-max))
  3284. (add-text-properties (match-beginning 0) (match-end 0)
  3285. '(face org-link))))
  3286. (unless (eq org-agenda-remove-tags t)
  3287. (org-agenda-align-tags))
  3288. (unless org-agenda-with-colors
  3289. (remove-text-properties (point-min) (point-max) '(face nil)))
  3290. (if (and (boundp 'org-agenda-overriding-columns-format)
  3291. org-agenda-overriding-columns-format)
  3292. (org-set-local 'org-agenda-overriding-columns-format
  3293. org-agenda-overriding-columns-format))
  3294. (if (and (boundp 'org-agenda-view-columns-initially)
  3295. org-agenda-view-columns-initially)
  3296. (org-agenda-columns))
  3297. (when org-agenda-fontify-priorities
  3298. (org-agenda-fontify-priorities))
  3299. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3300. (org-agenda-dim-blocked-tasks))
  3301. ;; We need to widen when `org-agenda-finalize' is called from
  3302. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3303. (when org-clock-current-task
  3304. (save-restriction
  3305. (widen)
  3306. (org-agenda-mark-clocking-task)))
  3307. (when org-agenda-entry-text-mode
  3308. (org-agenda-entry-text-hide)
  3309. (org-agenda-entry-text-show))
  3310. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3311. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3312. (org-habit-insert-consistency-graphs))
  3313. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3314. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3315. (and (listp org-agenda-show-inherited-tags)
  3316. (memq org-agenda-type org-agenda-show-inherited-tags))
  3317. (and (eq org-agenda-show-inherited-tags t)
  3318. (or (eq org-agenda-use-tag-inheritance t)
  3319. (and (listp org-agenda-use-tag-inheritance)
  3320. (not (memq org-agenda-type
  3321. org-agenda-use-tag-inheritance))))))
  3322. (let (mrk)
  3323. (save-excursion
  3324. (goto-char (point-min))
  3325. (while (equal (forward-line) 0)
  3326. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3327. (get-text-property (point) 'org-hd-marker)))
  3328. (put-text-property (point-at-bol) (point-at-eol)
  3329. 'tags (org-with-point-at mrk
  3330. (delete-dups
  3331. (mapcar 'downcase (org-get-tags-at))))))))))
  3332. (run-hooks 'org-agenda-finalize-hook)
  3333. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3334. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3335. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3336. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3337. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3338. (defun org-agenda-mark-clocking-task ()
  3339. "Mark the current clock entry in the agenda if it is present."
  3340. (org-agenda-unmark-clocking-task)
  3341. (when (marker-buffer org-clock-hd-marker)
  3342. (save-excursion
  3343. (goto-char (point-min))
  3344. (let (s ov)
  3345. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3346. (goto-char s)
  3347. (when (equal (org-get-at-bol 'org-hd-marker)
  3348. org-clock-hd-marker)
  3349. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3350. (overlay-put ov 'type 'org-agenda-clocking)
  3351. (overlay-put ov 'face 'org-agenda-clocking)
  3352. (overlay-put ov 'help-echo
  3353. "The clock is running in this item")))))))
  3354. (defun org-agenda-unmark-clocking-task ()
  3355. "Unmark the current clocking task."
  3356. (mapc (lambda (o)
  3357. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3358. (delete-overlay o)))
  3359. (overlays-in (point-min) (point-max))))
  3360. (defun org-agenda-fontify-priorities ()
  3361. "Make highest priority lines bold, and lowest italic."
  3362. (interactive)
  3363. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3364. (delete-overlay o)))
  3365. (overlays-in (point-min) (point-max)))
  3366. (save-excursion
  3367. (let (b e p ov h l)
  3368. (goto-char (point-min))
  3369. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3370. (setq h (or (get-char-property (point) 'org-highest-priority)
  3371. org-highest-priority)
  3372. l (or (get-char-property (point) 'org-lowest-priority)
  3373. org-lowest-priority)
  3374. p (string-to-char (match-string 1))
  3375. b (match-beginning 0)
  3376. e (if (eq org-agenda-fontify-priorities 'cookies)
  3377. (match-end 0)
  3378. (point-at-eol))
  3379. ov (make-overlay b e))
  3380. (overlay-put
  3381. ov 'face
  3382. (cons (cond ((org-face-from-face-or-color
  3383. 'priority nil
  3384. (cdr (assoc p org-priority-faces))))
  3385. ((and (listp org-agenda-fontify-priorities)
  3386. (org-face-from-face-or-color
  3387. 'priority nil
  3388. (cdr (assoc p org-agenda-fontify-priorities)))))
  3389. ((equal p l) 'italic)
  3390. ((equal p h) 'bold))
  3391. 'org-priority))
  3392. (overlay-put ov 'org-type 'org-priority)))))
  3393. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3394. (interactive "P")
  3395. "Dim currently blocked TODO's in the agenda display."
  3396. (message "Dim or hide blocked tasks...")
  3397. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3398. (delete-overlay o)))
  3399. (overlays-in (point-min) (point-max)))
  3400. (save-excursion
  3401. (let ((inhibit-read-only t)
  3402. (org-depend-tag-blocked nil)
  3403. (invis (or (not (null invisible))
  3404. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3405. org-blocked-by-checkboxes
  3406. invis1 b e p ov h l)
  3407. (goto-char (point-min))
  3408. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3409. (and pos (goto-char (1+ pos))))
  3410. (setq org-blocked-by-checkboxes nil invis1 invis)
  3411. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3412. (when (and marker
  3413. (with-current-buffer (marker-buffer marker)
  3414. (save-excursion (goto-char marker)
  3415. (org-entry-blocked-p))))
  3416. (if org-blocked-by-checkboxes (setq invis1 nil))
  3417. (setq b (if invis1
  3418. (max (point-min) (1- (point-at-bol)))
  3419. (point-at-bol))
  3420. e (point-at-eol)
  3421. ov (make-overlay b e))
  3422. (if invis1
  3423. (overlay-put ov 'invisible t)
  3424. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3425. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3426. (message "Dim or hide blocked tasks...done"))
  3427. (defvar org-agenda-skip-function nil
  3428. "Function to be called at each match during agenda construction.
  3429. If this function returns nil, the current match should not be skipped.
  3430. Otherwise, the function must return a position from where the search
  3431. should be continued.
  3432. This may also be a Lisp form, it will be evaluated.
  3433. Never set this variable using `setq' or so, because then it will apply
  3434. to all future agenda commands. If you do want a global skipping condition,
  3435. use the option `org-agenda-skip-function-global' instead.
  3436. The correct usage for `org-agenda-skip-function' is to bind it with
  3437. `let' to scope it dynamically into the agenda-constructing command.
  3438. A good way to set it is through options in `org-agenda-custom-commands'.")
  3439. (defun org-agenda-skip ()
  3440. "Throw to `:skip' in places that should be skipped.
  3441. Also moves point to the end of the skipped region, so that search can
  3442. continue from there."
  3443. (let ((p (point-at-bol)) to)
  3444. (when (or
  3445. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3446. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3447. (get-text-property p :org-archived)
  3448. (org-end-of-subtree t))
  3449. (and org-agenda-skip-comment-trees
  3450. (get-text-property p :org-comment)
  3451. (org-end-of-subtree t))
  3452. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3453. (org-agenda-skip-eval org-agenda-skip-function)))
  3454. (goto-char to))
  3455. (org-in-src-block-p t))
  3456. (throw :skip t))))
  3457. (defun org-agenda-skip-eval (form)
  3458. "If FORM is a function or a list, call (or eval) is and return result.
  3459. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3460. and match data are returned to the previous state no matter what these
  3461. functions do."
  3462. (let (fp)
  3463. (and form
  3464. (or (setq fp (functionp form))
  3465. (consp form))
  3466. (save-excursion
  3467. (save-match-data
  3468. (if fp
  3469. (funcall form)
  3470. (eval form)))))))
  3471. (defvar org-agenda-markers nil
  3472. "List of all currently active markers created by `org-agenda'.")
  3473. (defvar org-agenda-last-marker-time (org-float-time)
  3474. "Creation time of the last agenda marker.")
  3475. (defun org-agenda-new-marker (&optional pos)
  3476. "Return a new agenda marker.
  3477. Org-mode keeps a list of these markers and resets them when they are
  3478. no longer in use."
  3479. (let ((m (copy-marker (or pos (point)))))
  3480. (setq org-agenda-last-marker-time (org-float-time))
  3481. (if org-agenda-buffer
  3482. (with-current-buffer org-agenda-buffer
  3483. (push m org-agenda-markers))
  3484. (push m org-agenda-markers))
  3485. m))
  3486. (defun org-agenda-reset-markers ()
  3487. "Reset markers created by `org-agenda'."
  3488. (while org-agenda-markers
  3489. (move-marker (pop org-agenda-markers) nil)))
  3490. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3491. "Save relative positions of markers in region.
  3492. This check for agenda markers in all agenda buffers currently active."
  3493. (dolist (buf (buffer-list))
  3494. (with-current-buffer buf
  3495. (when (eq major-mode 'org-agenda-mode)
  3496. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3497. org-agenda-markers)))))
  3498. ;;; Entry text mode
  3499. (defun org-agenda-entry-text-show-here ()
  3500. "Add some text from the entry as context to the current line."
  3501. (let (m txt o)
  3502. (setq m (org-get-at-bol 'org-hd-marker))
  3503. (unless (marker-buffer m)
  3504. (error "No marker points to an entry here"))
  3505. (setq txt (concat "\n" (org-no-properties
  3506. (org-agenda-get-some-entry-text
  3507. m org-agenda-entry-text-maxlines
  3508. org-agenda-entry-text-leaders))))
  3509. (when (string-match "\\S-" txt)
  3510. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3511. (overlay-put o 'evaporate t)
  3512. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3513. (overlay-put o 'after-string txt))))
  3514. (defun org-agenda-entry-text-show ()
  3515. "Add entry context for all agenda lines."
  3516. (interactive)
  3517. (save-excursion
  3518. (goto-char (point-max))
  3519. (beginning-of-line 1)
  3520. (while (not (bobp))
  3521. (when (org-get-at-bol 'org-hd-marker)
  3522. (org-agenda-entry-text-show-here))
  3523. (beginning-of-line 0))))
  3524. (defun org-agenda-entry-text-hide ()
  3525. "Remove any shown entry context."
  3526. (delq nil
  3527. (mapcar (lambda (o)
  3528. (if (eq (overlay-get o 'org-overlay-type)
  3529. 'agenda-entry-content)
  3530. (progn (delete-overlay o) t)))
  3531. (overlays-in (point-min) (point-max)))))
  3532. (defun org-agenda-get-day-face (date)
  3533. "Return the face DATE should be displayed with."
  3534. (or (and (functionp org-agenda-day-face-function)
  3535. (funcall org-agenda-day-face-function date))
  3536. (cond ((org-agenda-todayp date)
  3537. 'org-agenda-date-today)
  3538. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3539. 'org-agenda-date-weekend)
  3540. (t 'org-agenda-date))))
  3541. ;;; Agenda timeline
  3542. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3543. (defun org-timeline (&optional dotodo)
  3544. "Show a time-sorted view of the entries in the current org file.
  3545. Only entries with a time stamp of today or later will be listed. With
  3546. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3547. under the current date.
  3548. If the buffer contains an active region, only check the region for
  3549. dates."
  3550. (interactive "P")
  3551. (let* ((dopast t)
  3552. (org-agenda-show-log-scoped org-agenda-show-log)
  3553. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3554. (current-buffer))))
  3555. (date (calendar-current-date))
  3556. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3557. (end (if (org-region-active-p) (region-end) (point-max)))
  3558. (day-numbers (org-get-all-dates
  3559. beg end 'no-ranges
  3560. t org-agenda-show-log-scoped ; always include today
  3561. org-timeline-show-empty-dates))
  3562. (org-deadline-warning-days 0)
  3563. (org-agenda-only-exact-dates t)
  3564. (today (org-today))
  3565. (past t)
  3566. args
  3567. s e rtn d emptyp)
  3568. (setq org-agenda-redo-command
  3569. (list 'progn
  3570. (list 'org-switch-to-buffer-other-window (current-buffer))
  3571. (list 'org-timeline (list 'quote dotodo))))
  3572. (if (not dopast)
  3573. ;; Remove past dates from the list of dates.
  3574. (setq day-numbers (delq nil (mapcar (lambda(x)
  3575. (if (>= x today) x nil))
  3576. day-numbers))))
  3577. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3578. (org-compile-prefix-format 'timeline)
  3579. (org-set-sorting-strategy 'timeline)
  3580. (if org-agenda-show-log-scoped (push :closed args))
  3581. (push :timestamp args)
  3582. (push :deadline args)
  3583. (push :scheduled args)
  3584. (push :sexp args)
  3585. (if dotodo (push :todo args))
  3586. (insert "Timeline of file " entry "\n")
  3587. (add-text-properties (point-min) (point)
  3588. (list 'face 'org-agenda-structure))
  3589. (org-agenda-mark-header-line (point-min))
  3590. (while (setq d (pop day-numbers))
  3591. (if (and (listp d) (eq (car d) :omitted))
  3592. (progn
  3593. (setq s (point))
  3594. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3595. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3596. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3597. (if (and (>= d today)
  3598. dopast
  3599. past)
  3600. (progn
  3601. (setq past nil)
  3602. (insert (make-string 79 ?-) "\n")))
  3603. (setq date (calendar-gregorian-from-absolute d))
  3604. (setq s (point))
  3605. (setq rtn (and (not emptyp)
  3606. (apply 'org-agenda-get-day-entries entry
  3607. date args)))
  3608. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3609. (progn
  3610. (insert
  3611. (if (stringp org-agenda-format-date)
  3612. (format-time-string org-agenda-format-date
  3613. (org-time-from-absolute date))
  3614. (funcall org-agenda-format-date date))
  3615. "\n")
  3616. (put-text-property s (1- (point)) 'face
  3617. (org-agenda-get-day-face date))
  3618. (put-text-property s (1- (point)) 'org-date-line t)
  3619. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3620. (if (equal d today)
  3621. (put-text-property s (1- (point)) 'org-today t))
  3622. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3623. (put-text-property s (1- (point)) 'day d)))))
  3624. (goto-char (point-min))
  3625. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3626. (point-min)))
  3627. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3628. (org-agenda-finalize)
  3629. (setq buffer-read-only t)))
  3630. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3631. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3632. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3633. not every single day in the range. If FORCE-TODAY is non-nil, make
  3634. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3635. inactive time stamps (those in square brackets) are included.
  3636. When EMPTY is non-nil, also include days without any entries."
  3637. (let ((re (concat
  3638. (if pre-re pre-re "")
  3639. (if inactive org-ts-regexp-both org-ts-regexp)))
  3640. dates dates1 date day day1 day2 ts1 ts2 pos)
  3641. (if force-today
  3642. (setq dates (list (org-today))))
  3643. (save-excursion
  3644. (goto-char beg)
  3645. (while (re-search-forward re end t)
  3646. (setq day (time-to-days (org-time-string-to-time
  3647. (substring (match-string 1) 0 10)
  3648. (current-buffer) (match-beginning 0))))
  3649. (or (memq day dates) (push day dates)))
  3650. (unless no-ranges
  3651. (goto-char beg)
  3652. (while (re-search-forward org-tr-regexp end t)
  3653. (setq pos (match-beginning 0))
  3654. (setq ts1 (substring (match-string 1) 0 10)
  3655. ts2 (substring (match-string 2) 0 10)
  3656. day1 (time-to-days (org-time-string-to-time
  3657. ts1 (current-buffer) pos))
  3658. day2 (time-to-days (org-time-string-to-time
  3659. ts2 (current-buffer) pos)))
  3660. (while (< (setq day1 (1+ day1)) day2)
  3661. (or (memq day1 dates) (push day1 dates)))))
  3662. (setq dates (sort dates '<))
  3663. (when empty
  3664. (while (setq day (pop dates))
  3665. (setq day2 (car dates))
  3666. (push day dates1)
  3667. (when (and day2 empty)
  3668. (if (or (eq empty t)
  3669. (and (numberp empty) (<= (- day2 day) empty)))
  3670. (while (< (setq day (1+ day)) day2)
  3671. (push (list day) dates1))
  3672. (push (cons :omitted (- day2 day)) dates1))))
  3673. (setq dates (nreverse dates1)))
  3674. dates)))
  3675. ;;; Agenda Daily/Weekly
  3676. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3677. "Start day for the agenda view.
  3678. Custom commands can set this variable in the options section.
  3679. See the docstring of `org-read-date' on allowed values.")
  3680. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3681. (defvar org-arg-loc nil) ; local variable
  3682. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3683. "List of types searched for when creating the daily/weekly agenda.
  3684. This variable is a list of symbols that controls the types of
  3685. items that appear in the daily/weekly agenda. Allowed symbols in this
  3686. list are are
  3687. :timestamp List items containing a date stamp or date range matching
  3688. the selected date. This includes sexp entries in
  3689. angular brackets.
  3690. :sexp List entries resulting from plain diary-like sexps.
  3691. :deadline List deadline due on that date. When the date is today,
  3692. also list any deadlines past due, or due within
  3693. `org-deadline-warning-days'. `:deadline' must appear before
  3694. `:scheduled' if the setting of
  3695. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3696. any effect.
  3697. :scheduled List all items which are scheduled for the given date.
  3698. The diary for *today* also contains items which were
  3699. scheduled earlier and are not yet marked DONE.
  3700. By default, all four types are turned on.
  3701. Never set this variable globally using `setq', because then it
  3702. will apply to all future agenda commands. Instead, bind it with
  3703. `let' to scope it dynamically into the agenda-constructing
  3704. command. A good way to set it is through options in
  3705. `org-agenda-custom-commands'. For a more flexible (though
  3706. somewhat less efficient) way of determining what is included in
  3707. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3708. (defvar org-agenda-buffer-tmp-name nil)
  3709. ;;;###autoload
  3710. (defun org-agenda-list (&optional arg start-day span)
  3711. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3712. The view will be for the current day or week, but from the overview buffer
  3713. you will be able to go to other days/weeks.
  3714. With a numeric prefix argument in an interactive call, the agenda will
  3715. span ARG days. Lisp programs should instead specify SPAN to change
  3716. the number of days. SPAN defaults to `org-agenda-span'.
  3717. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3718. given in `org-agenda-start-on-weekday'."
  3719. (interactive "P")
  3720. (if org-agenda-overriding-arguments
  3721. (setq arg (car org-agenda-overriding-arguments)
  3722. start-day (nth 1 org-agenda-overriding-arguments)
  3723. span (nth 2 org-agenda-overriding-arguments)))
  3724. (if (and (integerp arg) (> arg 0))
  3725. (setq span arg arg nil))
  3726. (catch 'exit
  3727. (setq org-agenda-buffer-name
  3728. (or org-agenda-buffer-tmp-name
  3729. (if org-agenda-sticky
  3730. (cond ((and org-keys (stringp org-match))
  3731. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3732. (org-keys
  3733. (format "*Org Agenda(%s)*" org-keys))
  3734. (t "*Org Agenda(a)*")))
  3735. org-agenda-buffer-name))
  3736. (org-agenda-prepare "Day/Week")
  3737. (setq start-day (or start-day org-agenda-start-day))
  3738. (if (stringp start-day)
  3739. ;; Convert to an absolute day number
  3740. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3741. (org-compile-prefix-format 'agenda)
  3742. (org-set-sorting-strategy 'agenda)
  3743. (let* ((span (org-agenda-ndays-to-span
  3744. (or span org-agenda-ndays org-agenda-span)))
  3745. (today (org-today))
  3746. (sd (or start-day today))
  3747. (ndays (org-agenda-span-to-ndays span sd))
  3748. (org-agenda-start-on-weekday
  3749. (if (eq ndays 7)
  3750. org-agenda-start-on-weekday))
  3751. (thefiles (org-agenda-files nil 'ifmode))
  3752. (files thefiles)
  3753. (start (if (or (null org-agenda-start-on-weekday)
  3754. (< ndays 7))
  3755. sd
  3756. (let* ((nt (calendar-day-of-week
  3757. (calendar-gregorian-from-absolute sd)))
  3758. (n1 org-agenda-start-on-weekday)
  3759. (d (- nt n1)))
  3760. (- sd (+ (if (< d 0) 7 0) d)))))
  3761. (day-numbers (list start))
  3762. (day-cnt 0)
  3763. (inhibit-redisplay (not debug-on-error))
  3764. (org-agenda-show-log-scoped org-agenda-show-log)
  3765. s e rtn rtnall file date d start-pos end-pos todayp
  3766. clocktable-start clocktable-end filter)
  3767. (setq org-agenda-redo-command
  3768. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3769. (dotimes (n (1- ndays))
  3770. (push (1+ (car day-numbers)) day-numbers))
  3771. (setq day-numbers (nreverse day-numbers))
  3772. (setq clocktable-start (car day-numbers)
  3773. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3774. (org-set-local 'org-starting-day (car day-numbers))
  3775. (org-set-local 'org-arg-loc arg)
  3776. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3777. (unless org-agenda-compact-blocks
  3778. (let* ((d1 (car day-numbers))
  3779. (d2 (org-last day-numbers))
  3780. (w1 (org-days-to-iso-week d1))
  3781. (w2 (org-days-to-iso-week d2)))
  3782. (setq s (point))
  3783. (if org-agenda-overriding-header
  3784. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3785. nil 'face 'org-agenda-structure) "\n")
  3786. (insert (org-agenda-span-name span)
  3787. "-agenda"
  3788. (if (< (- d2 d1) 350)
  3789. (if (= w1 w2)
  3790. (format " (W%02d)" w1)
  3791. (format " (W%02d-W%02d)" w1 w2))
  3792. "")
  3793. ":\n")))
  3794. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3795. 'org-date-line t))
  3796. (org-agenda-mark-header-line s))
  3797. (while (setq d (pop day-numbers))
  3798. (setq date (calendar-gregorian-from-absolute d)
  3799. s (point))
  3800. (if (or (setq todayp (= d today))
  3801. (and (not start-pos) (= d sd)))
  3802. (setq start-pos (point))
  3803. (if (and start-pos (not end-pos))
  3804. (setq end-pos (point))))
  3805. (setq files thefiles
  3806. rtnall nil)
  3807. (while (setq file (pop files))
  3808. (catch 'nextfile
  3809. (org-check-agenda-file file)
  3810. (let ((org-agenda-entry-types org-agenda-entry-types))
  3811. (unless org-agenda-include-deadlines
  3812. (setq org-agenda-entry-types
  3813. (delq :deadline org-agenda-entry-types)))
  3814. (cond
  3815. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3816. (setq rtn (org-agenda-get-day-entries
  3817. file date :closed)))
  3818. (org-agenda-show-log-scoped
  3819. (setq rtn (apply 'org-agenda-get-day-entries
  3820. file date
  3821. (append '(:closed) org-agenda-entry-types))))
  3822. (t
  3823. (setq rtn (apply 'org-agenda-get-day-entries
  3824. file date
  3825. org-agenda-entry-types)))))
  3826. (setq rtnall (append rtnall rtn)))) ;; all entries
  3827. (if org-agenda-include-diary
  3828. (let ((org-agenda-search-headline-for-time t))
  3829. (require 'diary-lib)
  3830. (setq rtn (org-get-entries-from-diary date))
  3831. (setq rtnall (append rtnall rtn))))
  3832. (if (or rtnall org-agenda-show-all-dates)
  3833. (progn
  3834. (setq day-cnt (1+ day-cnt))
  3835. (insert
  3836. (if (stringp org-agenda-format-date)
  3837. (format-time-string org-agenda-format-date
  3838. (org-time-from-absolute date))
  3839. (funcall org-agenda-format-date date))
  3840. "\n")
  3841. (put-text-property s (1- (point)) 'face
  3842. (org-agenda-get-day-face date))
  3843. (put-text-property s (1- (point)) 'org-date-line t)
  3844. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3845. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3846. (when todayp
  3847. (put-text-property s (1- (point)) 'org-today t))
  3848. (setq rtnall
  3849. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3850. (if rtnall (insert ;; all entries
  3851. (org-agenda-finalize-entries rtnall 'agenda)
  3852. "\n"))
  3853. (put-text-property s (1- (point)) 'day d)
  3854. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3855. (when (and org-agenda-clockreport-mode clocktable-start)
  3856. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3857. ;; the above line is to ensure the restricted range!
  3858. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3859. tbl)
  3860. (setq p (org-plist-delete p :block))
  3861. (setq p (plist-put p :tstart clocktable-start))
  3862. (setq p (plist-put p :tend clocktable-end))
  3863. (setq p (plist-put p :scope 'agenda))
  3864. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3865. (setq filter (or org-agenda-tag-filter-while-redo
  3866. (get 'org-agenda-tag-filter :preset-filter))))
  3867. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3868. (if (string-match "[<>=]" x)
  3869. ""
  3870. x))
  3871. filter ""))))
  3872. (setq tbl (apply 'org-clock-get-clocktable p))
  3873. (insert tbl)))
  3874. (goto-char (point-min))
  3875. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3876. (unless (and (pos-visible-in-window-p (point-min))
  3877. (pos-visible-in-window-p (point-max)))
  3878. (goto-char (1- (point-max)))
  3879. (recenter -1)
  3880. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3881. (progn
  3882. (goto-char (or start-pos 1))
  3883. (recenter 1))))
  3884. (goto-char (or start-pos 1))
  3885. (add-text-properties (point-min) (point-max)
  3886. `(org-agenda-type agenda
  3887. org-last-args (,arg ,start-day ,span)
  3888. org-redo-cmd ,org-agenda-redo-command
  3889. org-series-cmd ,org-cmd))
  3890. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3891. (org-agenda-show-clocking-issues))
  3892. (org-agenda-finalize)
  3893. (setq buffer-read-only t)
  3894. (message ""))))
  3895. (defun org-agenda-ndays-to-span (n)
  3896. "Return a span symbol for a span of N days, or N if none matches."
  3897. (cond ((symbolp n) n)
  3898. ((= n 1) 'day)
  3899. ((= n 7) 'week)
  3900. (t n)))
  3901. (defun org-agenda-span-to-ndays (span &optional start-day)
  3902. "Return ndays from SPAN, possibly starting at START-DAY."
  3903. (cond ((numberp span) span)
  3904. ((eq span 'day) 1)
  3905. ((eq span 'week) 7)
  3906. ((eq span 'month)
  3907. (let ((date (calendar-gregorian-from-absolute start-day)))
  3908. (calendar-last-day-of-month (car date) (caddr date))))
  3909. ((eq span 'year)
  3910. (let ((date (calendar-gregorian-from-absolute start-day)))
  3911. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3912. (defun org-agenda-span-name (span)
  3913. "Return a SPAN name."
  3914. (if (null span)
  3915. ""
  3916. (if (symbolp span)
  3917. (capitalize (symbol-name span))
  3918. (format "%d days" span))))
  3919. ;;; Agenda word search
  3920. (defvar org-agenda-search-history nil)
  3921. (defvar org-search-syntax-table nil
  3922. "Special syntax table for org-mode search.
  3923. In this table, we have single quotes not as word constituents, to
  3924. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3925. (defvar org-mode-syntax-table) ; From org.el
  3926. (defun org-search-syntax-table ()
  3927. (unless org-search-syntax-table
  3928. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3929. (modify-syntax-entry ?' "." org-search-syntax-table)
  3930. (modify-syntax-entry ?` "." org-search-syntax-table))
  3931. org-search-syntax-table)
  3932. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3933. ;;;###autoload
  3934. (defun org-search-view (&optional todo-only string edit-at)
  3935. "Show all entries that contain a phrase or words or regular expressions.
  3936. With optional prefix argument TODO-ONLY, only consider entries that are
  3937. TODO entries. The argument STRING can be used to pass a default search
  3938. string into this function. If EDIT-AT is non-nil, it means that the
  3939. user should get a chance to edit this string, with cursor at position
  3940. EDIT-AT.
  3941. The search string can be viewed either as a phrase that should be found as
  3942. is, or it can be broken into a number of snippets, each of which must match
  3943. in a Boolean way to select an entry. The default depends on the variable
  3944. `org-agenda-search-view-always-boolean'.
  3945. Even if this is turned off (the default) you can always switch to
  3946. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3947. The default is a direct search of the whole phrase, where each space in
  3948. the search string can expand to an arbitrary amount of whitespace,
  3949. including newlines.
  3950. If using a Boolean search, the search string is split on whitespace and
  3951. each snippet is searched separately, with logical AND to select an entry.
  3952. Words prefixed with a minus must *not* occur in the entry. Words without
  3953. a prefix or prefixed with a plus must occur in the entry. Matching is
  3954. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3955. match whole words, not parts of a word) if
  3956. `org-agenda-search-view-force-full-words' is set (default is nil).
  3957. Boolean search snippets enclosed by curly braces are interpreted as
  3958. regular expressions that must or (when preceded with \"-\") must not
  3959. match in the entry. Snippets enclosed into double quotes will be taken
  3960. as a whole, to include whitespace.
  3961. - If the search string starts with an asterisk, search only in headlines.
  3962. - If (possibly after the leading star) the search string starts with an
  3963. exclamation mark, this also means to look at TODO entries only, an effect
  3964. that can also be achieved with a prefix argument.
  3965. - If (possibly after star and exclamation mark) the search string starts
  3966. with a colon, this will mean that the (non-regexp) snippets of the
  3967. Boolean search must match as full words.
  3968. This command searches the agenda files, and in addition the files listed
  3969. in `org-agenda-text-search-extra-files'."
  3970. (interactive "P")
  3971. (if org-agenda-overriding-arguments
  3972. (setq todo-only (car org-agenda-overriding-arguments)
  3973. string (nth 1 org-agenda-overriding-arguments)
  3974. edit-at (nth 2 org-agenda-overriding-arguments)))
  3975. (let* ((props (list 'face nil
  3976. 'done-face 'org-agenda-done
  3977. 'org-not-done-regexp org-not-done-regexp
  3978. 'org-todo-regexp org-todo-regexp
  3979. 'org-complex-heading-regexp org-complex-heading-regexp
  3980. 'mouse-face 'highlight
  3981. 'help-echo (format "mouse-2 or RET jump to location")))
  3982. (full-words org-agenda-search-view-force-full-words)
  3983. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3984. regexp rtn rtnall files file pos inherited-tags
  3985. marker category category-pos level tags c neg re boolean
  3986. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3987. (unless (and (not edit-at)
  3988. (stringp string)
  3989. (string-match "\\S-" string))
  3990. (setq string (read-string
  3991. (if org-agenda-search-view-always-boolean
  3992. "[+-]Word/{Regexp} ...: "
  3993. "Phrase or [+-]Word/{Regexp} ...: ")
  3994. (cond
  3995. ((integerp edit-at) (cons string edit-at))
  3996. (edit-at string))
  3997. 'org-agenda-search-history)))
  3998. (catch 'exit
  3999. (if org-agenda-sticky
  4000. (setq org-agenda-buffer-name
  4001. (if (stringp string)
  4002. (format "*Org Agenda(%s:%s)*"
  4003. (or org-keys (or (and todo-only "S") "s")) string)
  4004. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4005. (org-agenda-prepare "SEARCH")
  4006. (org-compile-prefix-format 'search)
  4007. (org-set-sorting-strategy 'search)
  4008. (setq org-agenda-redo-command
  4009. (list 'org-search-view (if todo-only t nil)
  4010. (list 'if 'current-prefix-arg nil string)))
  4011. (setq org-agenda-query-string string)
  4012. (if (equal (string-to-char string) ?*)
  4013. (setq hdl-only t
  4014. words (substring string 1))
  4015. (setq words string))
  4016. (when (equal (string-to-char words) ?!)
  4017. (setq todo-only t
  4018. words (substring words 1)))
  4019. (when (equal (string-to-char words) ?:)
  4020. (setq full-words t
  4021. words (substring words 1)))
  4022. (if (or org-agenda-search-view-always-boolean
  4023. (member (string-to-char words) '(?- ?+ ?\{)))
  4024. (setq boolean t))
  4025. (setq words (org-split-string words))
  4026. (let (www w)
  4027. (while (setq w (pop words))
  4028. (while (and (string-match "\\\\\\'" w) words)
  4029. (setq w (concat (substring w 0 -1) " " (pop words))))
  4030. (push w www))
  4031. (setq words (nreverse www) www nil)
  4032. (while (setq w (pop words))
  4033. (when (and (string-match "\\`[-+]?{" w)
  4034. (not (string-match "}\\'" w)))
  4035. (while (and words (not (string-match "}\\'" (car words))))
  4036. (setq w (concat w " " (pop words))))
  4037. (setq w (concat w " " (pop words))))
  4038. (push w www))
  4039. (setq words (nreverse www)))
  4040. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4041. (when boolean
  4042. (let (wds w)
  4043. (while (setq w (pop words))
  4044. (if (or (equal (substring w 0 1) "\"")
  4045. (and (> (length w) 1)
  4046. (member (substring w 0 1) '("+" "-"))
  4047. (equal (substring w 1 2) "\"")))
  4048. (while (and words (not (equal (substring w -1) "\"")))
  4049. (setq w (concat w " " (pop words)))))
  4050. (and (string-match "\\`\\([-+]?\\)\"" w)
  4051. (setq w (replace-match "\\1" nil nil w)))
  4052. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4053. (push w wds))
  4054. (setq words (nreverse wds))))
  4055. (if boolean
  4056. (mapc (lambda (w)
  4057. (setq c (string-to-char w))
  4058. (if (equal c ?-)
  4059. (setq neg t w (substring w 1))
  4060. (if (equal c ?+)
  4061. (setq neg nil w (substring w 1))
  4062. (setq neg nil)))
  4063. (if (string-match "\\`{.*}\\'" w)
  4064. (setq re (substring w 1 -1))
  4065. (if full-words
  4066. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4067. (setq re (regexp-quote (downcase w)))))
  4068. (if neg (push re regexps-) (push re regexps+)))
  4069. words)
  4070. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4071. regexps+))
  4072. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4073. (if (not regexps+)
  4074. (setq regexp org-outline-regexp-bol)
  4075. (setq regexp (pop regexps+))
  4076. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4077. regexp))))
  4078. (setq files (org-agenda-files nil 'ifmode))
  4079. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4080. (pop org-agenda-text-search-extra-files)
  4081. (setq files (org-add-archive-files files)))
  4082. (setq files (append files org-agenda-text-search-extra-files)
  4083. rtnall nil)
  4084. (while (setq file (pop files))
  4085. (setq ee nil)
  4086. (catch 'nextfile
  4087. (org-check-agenda-file file)
  4088. (setq buffer (if (file-exists-p file)
  4089. (org-get-agenda-file-buffer file)
  4090. (error "No such file %s" file)))
  4091. (if (not buffer)
  4092. ;; If file does not exist, make sure an error message is sent
  4093. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4094. file))))
  4095. (with-current-buffer buffer
  4096. (with-syntax-table (org-search-syntax-table)
  4097. (unless (derived-mode-p 'org-mode)
  4098. (error "Agenda file %s is not in `org-mode'" file))
  4099. (let ((case-fold-search t))
  4100. (save-excursion
  4101. (save-restriction
  4102. (if org-agenda-restrict
  4103. (narrow-to-region org-agenda-restrict-begin
  4104. org-agenda-restrict-end)
  4105. (widen))
  4106. (goto-char (point-min))
  4107. (unless (or (org-at-heading-p)
  4108. (outline-next-heading))
  4109. (throw 'nextfile t))
  4110. (goto-char (max (point-min) (1- (point))))
  4111. (while (re-search-forward regexp nil t)
  4112. (org-back-to-heading t)
  4113. (while (and org-agenda-search-view-max-outline-level
  4114. (> (org-reduced-level (org-outline-level))
  4115. org-agenda-search-view-max-outline-level)
  4116. (forward-line -1)
  4117. (outline-back-to-heading t)))
  4118. (skip-chars-forward "* ")
  4119. (setq beg (point-at-bol)
  4120. beg1 (point)
  4121. end (progn
  4122. (outline-next-heading)
  4123. (while (and org-agenda-search-view-max-outline-level
  4124. (> (org-reduced-level (org-outline-level))
  4125. org-agenda-search-view-max-outline-level)
  4126. (forward-line 1)
  4127. (outline-next-heading)))
  4128. (point)))
  4129. (catch :skip
  4130. (goto-char beg)
  4131. (org-agenda-skip)
  4132. (setq str (buffer-substring-no-properties
  4133. (point-at-bol)
  4134. (if hdl-only (point-at-eol) end)))
  4135. (mapc (lambda (wr) (when (string-match wr str)
  4136. (goto-char (1- end))
  4137. (throw :skip t)))
  4138. regexps-)
  4139. (mapc (lambda (wr) (unless (string-match wr str)
  4140. (goto-char (1- end))
  4141. (throw :skip t)))
  4142. (if todo-only
  4143. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4144. regexps+)
  4145. regexps+))
  4146. (goto-char beg)
  4147. (setq marker (org-agenda-new-marker (point))
  4148. category (org-get-category)
  4149. level (make-string (org-reduced-level (org-outline-level)) ? )
  4150. category-pos (get-text-property (point) 'org-category-position)
  4151. inherited-tags
  4152. (or (eq org-agenda-show-inherited-tags 'always)
  4153. (and (listp org-agenda-show-inherited-tags)
  4154. (memq 'todo org-agenda-show-inherited-tags))
  4155. (and (eq org-agenda-show-inherited-tags t)
  4156. (or (eq org-agenda-use-tag-inheritance t)
  4157. (memq 'todo org-agenda-use-tag-inheritance))))
  4158. tags (org-get-tags-at nil (not inherited-tags))
  4159. txt (org-agenda-format-item
  4160. ""
  4161. (buffer-substring-no-properties
  4162. beg1 (point-at-eol))
  4163. level category tags t))
  4164. (org-add-props txt props
  4165. 'org-marker marker 'org-hd-marker marker
  4166. 'org-todo-regexp org-todo-regexp
  4167. 'level level
  4168. 'org-complex-heading-regexp org-complex-heading-regexp
  4169. 'priority 1000 'org-category category
  4170. 'org-category-position category-pos
  4171. 'type "search")
  4172. (push txt ee)
  4173. (goto-char (1- end))))))))))
  4174. (setq rtn (nreverse ee))
  4175. (setq rtnall (append rtnall rtn)))
  4176. (if org-agenda-overriding-header
  4177. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4178. nil 'face 'org-agenda-structure) "\n")
  4179. (insert "Search words: ")
  4180. (add-text-properties (point-min) (1- (point))
  4181. (list 'face 'org-agenda-structure))
  4182. (setq pos (point))
  4183. (insert string "\n")
  4184. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4185. (setq pos (point))
  4186. (unless org-agenda-multi
  4187. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4188. (add-text-properties pos (1- (point))
  4189. (list 'face 'org-agenda-structure))))
  4190. (org-agenda-mark-header-line (point-min))
  4191. (when rtnall
  4192. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4193. (goto-char (point-min))
  4194. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4195. (add-text-properties (point-min) (point-max)
  4196. `(org-agenda-type search
  4197. org-last-args (,todo-only ,string ,edit-at)
  4198. org-redo-cmd ,org-agenda-redo-command
  4199. org-series-cmd ,org-cmd))
  4200. (org-agenda-finalize)
  4201. (setq buffer-read-only t))))
  4202. ;;; Agenda TODO list
  4203. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4204. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4205. (concat
  4206. (if (or (equal keywords "ALL") (not keywords))
  4207. (propertize "ALL" 'face 'warning)
  4208. (mapconcat
  4209. (lambda (kw)
  4210. (propertize kw 'face (org-get-todo-face kw)))
  4211. (org-split-string keywords "|")
  4212. "|"))
  4213. "\n"))
  4214. (defvar org-select-this-todo-keyword nil)
  4215. (defvar org-last-arg nil)
  4216. ;;;###autoload
  4217. (defun org-todo-list (&optional arg)
  4218. "Show all (not done) TODO entries from all agenda file in a single list.
  4219. The prefix arg can be used to select a specific TODO keyword and limit
  4220. the list to these. When using \\[universal-argument], you will be prompted
  4221. for a keyword. A numeric prefix directly selects the Nth keyword in
  4222. `org-todo-keywords-1'."
  4223. (interactive "P")
  4224. (if org-agenda-overriding-arguments
  4225. (setq arg org-agenda-overriding-arguments))
  4226. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4227. (let* ((today (org-today))
  4228. (date (calendar-gregorian-from-absolute today))
  4229. (kwds org-todo-keywords-for-agenda)
  4230. (completion-ignore-case t)
  4231. (org-select-this-todo-keyword
  4232. (if (stringp arg) arg
  4233. (and arg (integerp arg) (> arg 0)
  4234. (nth (1- arg) kwds))))
  4235. rtn rtnall files file pos)
  4236. (when (equal arg '(4))
  4237. (setq org-select-this-todo-keyword
  4238. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4239. (mapcar 'list kwds) nil nil)))
  4240. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4241. (catch 'exit
  4242. (if org-agenda-sticky
  4243. (setq org-agenda-buffer-name
  4244. (if (stringp org-select-this-todo-keyword)
  4245. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4246. org-select-this-todo-keyword)
  4247. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4248. (org-agenda-prepare "TODO")
  4249. (org-compile-prefix-format 'todo)
  4250. (org-set-sorting-strategy 'todo)
  4251. (setq org-agenda-redo-command
  4252. `(org-todo-list (or (and (numberp current-prefix-arg)
  4253. current-prefix-arg)
  4254. ,org-select-this-todo-keyword
  4255. current-prefix-arg ,arg)))
  4256. (setq files (org-agenda-files nil 'ifmode)
  4257. rtnall nil)
  4258. (while (setq file (pop files))
  4259. (catch 'nextfile
  4260. (org-check-agenda-file file)
  4261. (setq rtn (org-agenda-get-day-entries file date :todo))
  4262. (setq rtnall (append rtnall rtn))))
  4263. (if org-agenda-overriding-header
  4264. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4265. nil 'face 'org-agenda-structure) "\n")
  4266. (insert "Global list of TODO items of type: ")
  4267. (add-text-properties (point-min) (1- (point))
  4268. (list 'face 'org-agenda-structure
  4269. 'short-heading
  4270. (concat "ToDo: "
  4271. (or org-select-this-todo-keyword "ALL"))))
  4272. (org-agenda-mark-header-line (point-min))
  4273. (insert (org-agenda-propertize-selected-todo-keywords
  4274. org-select-this-todo-keyword))
  4275. (setq pos (point))
  4276. (unless org-agenda-multi
  4277. (insert "Available with `N r': (0)[ALL]")
  4278. (let ((n 0) s)
  4279. (mapc (lambda (x)
  4280. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4281. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4282. (insert "\n "))
  4283. (insert " " s))
  4284. kwds))
  4285. (insert "\n"))
  4286. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4287. (org-agenda-mark-header-line (point-min))
  4288. (when rtnall
  4289. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4290. (goto-char (point-min))
  4291. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4292. (add-text-properties (point-min) (point-max)
  4293. `(org-agenda-type todo
  4294. org-last-args ,arg
  4295. org-redo-cmd ,org-agenda-redo-command
  4296. org-series-cmd ,org-cmd))
  4297. (org-agenda-finalize)
  4298. (setq buffer-read-only t))))
  4299. ;;; Agenda tags match
  4300. ;;;###autoload
  4301. (defun org-tags-view (&optional todo-only match)
  4302. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4303. The prefix arg TODO-ONLY limits the search to TODO entries."
  4304. (interactive "P")
  4305. (if org-agenda-overriding-arguments
  4306. (setq todo-only (car org-agenda-overriding-arguments)
  4307. match (nth 1 org-agenda-overriding-arguments)))
  4308. (let* ((org-tags-match-list-sublevels
  4309. org-tags-match-list-sublevels)
  4310. (completion-ignore-case t)
  4311. rtn rtnall files file pos matcher
  4312. buffer)
  4313. (when (and (stringp match) (not (string-match "\\S-" match)))
  4314. (setq match nil))
  4315. (setq matcher (org-make-tags-matcher match)
  4316. match (car matcher) matcher (cdr matcher))
  4317. (catch 'exit
  4318. (if org-agenda-sticky
  4319. (setq org-agenda-buffer-name
  4320. (if (stringp match)
  4321. (format "*Org Agenda(%s:%s)*"
  4322. (or org-keys (or (and todo-only "M") "m")) match)
  4323. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4324. (org-agenda-prepare (concat "TAGS " match))
  4325. (org-compile-prefix-format 'tags)
  4326. (org-set-sorting-strategy 'tags)
  4327. (setq org-agenda-query-string match)
  4328. (setq org-agenda-redo-command
  4329. (list 'org-tags-view `(quote ,todo-only)
  4330. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4331. (setq files (org-agenda-files nil 'ifmode)
  4332. rtnall nil)
  4333. (while (setq file (pop files))
  4334. (catch 'nextfile
  4335. (org-check-agenda-file file)
  4336. (setq buffer (if (file-exists-p file)
  4337. (org-get-agenda-file-buffer file)
  4338. (error "No such file %s" file)))
  4339. (if (not buffer)
  4340. ;; If file does not exist, error message to agenda
  4341. (setq rtn (list
  4342. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4343. rtnall (append rtnall rtn))
  4344. (with-current-buffer buffer
  4345. (unless (derived-mode-p 'org-mode)
  4346. (error "Agenda file %s is not in `org-mode'" file))
  4347. (save-excursion
  4348. (save-restriction
  4349. (if org-agenda-restrict
  4350. (narrow-to-region org-agenda-restrict-begin
  4351. org-agenda-restrict-end)
  4352. (widen))
  4353. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4354. (setq rtnall (append rtnall rtn))))))))
  4355. (if org-agenda-overriding-header
  4356. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4357. nil 'face 'org-agenda-structure) "\n")
  4358. (insert "Headlines with TAGS match: ")
  4359. (add-text-properties (point-min) (1- (point))
  4360. (list 'face 'org-agenda-structure
  4361. 'short-heading
  4362. (concat "Match: " match)))
  4363. (setq pos (point))
  4364. (insert match "\n")
  4365. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4366. (setq pos (point))
  4367. (unless org-agenda-multi
  4368. (insert "Press `C-u r' to search again with new search string\n"))
  4369. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4370. (org-agenda-mark-header-line (point-min))
  4371. (when rtnall
  4372. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4373. (goto-char (point-min))
  4374. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4375. (add-text-properties (point-min) (point-max)
  4376. `(org-agenda-type tags
  4377. org-last-args (,todo-only ,match)
  4378. org-redo-cmd ,org-agenda-redo-command
  4379. org-series-cmd ,org-cmd))
  4380. (org-agenda-finalize)
  4381. (setq buffer-read-only t))))
  4382. ;;; Agenda Finding stuck projects
  4383. (defvar org-agenda-skip-regexp nil
  4384. "Regular expression used in skipping subtrees for the agenda.
  4385. This is basically a temporary global variable that can be set and then
  4386. used by user-defined selections using `org-agenda-skip-function'.")
  4387. (defvar org-agenda-overriding-header nil
  4388. "When set during agenda, todo and tags searches it replaces the header.
  4389. This variable should not be set directly, but custom commands can bind it
  4390. in the options section.")
  4391. (defun org-agenda-skip-entry-when-regexp-matches ()
  4392. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4393. If yes, it returns the end position of this entry, causing agenda commands
  4394. to skip the entry but continuing the search in the subtree. This is a
  4395. function that can be put into `org-agenda-skip-function' for the duration
  4396. of a command."
  4397. (let ((end (save-excursion (org-end-of-subtree t)))
  4398. skip)
  4399. (save-excursion
  4400. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4401. (and skip end)))
  4402. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4403. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4404. If yes, it returns the end position of this tree, causing agenda commands
  4405. to skip this subtree. This is a function that can be put into
  4406. `org-agenda-skip-function' for the duration of a command."
  4407. (let ((end (save-excursion (org-end-of-subtree t)))
  4408. skip)
  4409. (save-excursion
  4410. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4411. (and skip end)))
  4412. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4413. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4414. If yes, it returns the end position of the current entry (NOT the tree),
  4415. causing agenda commands to skip the entry but continuing the search in
  4416. the subtree. This is a function that can be put into
  4417. `org-agenda-skip-function' for the duration of a command. An important
  4418. use of this function is for the stuck project list."
  4419. (let ((end (save-excursion (org-end-of-subtree t)))
  4420. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4421. skip)
  4422. (save-excursion
  4423. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4424. (and skip entry-end)))
  4425. (defun org-agenda-skip-entry-if (&rest conditions)
  4426. "Skip entry if any of CONDITIONS is true.
  4427. See `org-agenda-skip-if' for details."
  4428. (org-agenda-skip-if nil conditions))
  4429. (defun org-agenda-skip-subtree-if (&rest conditions)
  4430. "Skip entry if any of CONDITIONS is true.
  4431. See `org-agenda-skip-if' for details."
  4432. (org-agenda-skip-if t conditions))
  4433. (defun org-agenda-skip-if (subtree conditions)
  4434. "Checks current entity for CONDITIONS.
  4435. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4436. the entry (i.e. the text before the next heading) is checked.
  4437. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4438. from different tests. Valid conditions are:
  4439. scheduled Check if there is a scheduled cookie
  4440. notscheduled Check if there is no scheduled cookie
  4441. deadline Check if there is a deadline
  4442. notdeadline Check if there is no deadline
  4443. timestamp Check if there is a timestamp (also deadline or scheduled)
  4444. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4445. regexp Check if regexp matches
  4446. notregexp Check if regexp does not match.
  4447. todo Check if TODO keyword matches
  4448. nottodo Check if TODO keyword does not match
  4449. The regexp is taken from the conditions list, it must come right after
  4450. the `regexp' or `notregexp' element.
  4451. `todo' and `nottodo' accept as an argument a list of todo
  4452. keywords, which may include \"*\" to match any todo keyword.
  4453. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4454. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4455. Instead of a list, a keyword class may be given. For example:
  4456. (org-agenda-skip-entry-if 'nottodo 'done)
  4457. would skip entries that haven't been marked with any of \"DONE\"
  4458. keywords. Possible classes are: `todo', `done', `any'.
  4459. If any of these conditions is met, this function returns the end point of
  4460. the entity, causing the search to continue from there. This is a function
  4461. that can be put into `org-agenda-skip-function' for the duration of a command."
  4462. (let (beg end m)
  4463. (org-back-to-heading t)
  4464. (setq beg (point)
  4465. end (if subtree
  4466. (progn (org-end-of-subtree t) (point))
  4467. (progn (outline-next-heading) (1- (point)))))
  4468. (goto-char beg)
  4469. (and
  4470. (or
  4471. (and (memq 'scheduled conditions)
  4472. (re-search-forward org-scheduled-time-regexp end t))
  4473. (and (memq 'notscheduled conditions)
  4474. (not (re-search-forward org-scheduled-time-regexp end t)))
  4475. (and (memq 'deadline conditions)
  4476. (re-search-forward org-deadline-time-regexp end t))
  4477. (and (memq 'notdeadline conditions)
  4478. (not (re-search-forward org-deadline-time-regexp end t)))
  4479. (and (memq 'timestamp conditions)
  4480. (re-search-forward org-ts-regexp end t))
  4481. (and (memq 'nottimestamp conditions)
  4482. (not (re-search-forward org-ts-regexp end t)))
  4483. (and (setq m (memq 'regexp conditions))
  4484. (stringp (nth 1 m))
  4485. (re-search-forward (nth 1 m) end t))
  4486. (and (setq m (memq 'notregexp conditions))
  4487. (stringp (nth 1 m))
  4488. (not (re-search-forward (nth 1 m) end t)))
  4489. (and (or
  4490. (setq m (memq 'nottodo conditions))
  4491. (setq m (memq 'todo-unblocked conditions))
  4492. (setq m (memq 'nottodo-unblocked conditions))
  4493. (setq m (memq 'todo conditions)))
  4494. (org-agenda-skip-if-todo m end)))
  4495. end)))
  4496. (defun org-agenda-skip-if-todo (args end)
  4497. "Helper function for `org-agenda-skip-if', do not use it directly.
  4498. ARGS is a list with first element either `todo', `nottodo',
  4499. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4500. a list of TODO keywords, or a state symbol `todo' or `done' or
  4501. `any'."
  4502. (let ((kw (car args))
  4503. (arg (cadr args))
  4504. todo-wds todo-re)
  4505. (setq todo-wds
  4506. (org-uniquify
  4507. (cond
  4508. ((listp arg) ;; list of keywords
  4509. (if (member "*" arg)
  4510. (mapcar 'substring-no-properties org-todo-keywords-1)
  4511. arg))
  4512. ((symbolp arg) ;; keyword class name
  4513. (cond
  4514. ((eq arg 'todo)
  4515. (org-delete-all org-done-keywords
  4516. (mapcar 'substring-no-properties
  4517. org-todo-keywords-1)))
  4518. ((eq arg 'done) org-done-keywords)
  4519. ((eq arg 'any)
  4520. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4521. (setq todo-re
  4522. (concat "^\\*+[ \t]+\\<\\("
  4523. (mapconcat 'identity todo-wds "\\|")
  4524. "\\)\\>"))
  4525. (cond
  4526. ((eq kw 'todo) (re-search-forward todo-re end t))
  4527. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4528. ((eq kw 'todo-unblocked)
  4529. (catch 'unblocked
  4530. (while (re-search-forward todo-re end t)
  4531. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4532. nil))
  4533. ((eq kw 'nottodo-unblocked)
  4534. (catch 'unblocked
  4535. (while (re-search-forward todo-re end t)
  4536. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4537. t))
  4538. )))
  4539. ;;;###autoload
  4540. (defun org-agenda-list-stuck-projects (&rest ignore)
  4541. "Create agenda view for projects that are stuck.
  4542. Stuck projects are project that have no next actions. For the definitions
  4543. of what a project is and how to check if it stuck, customize the variable
  4544. `org-stuck-projects'."
  4545. (interactive)
  4546. (let* ((org-agenda-skip-function
  4547. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4548. ;; We could have used org-agenda-skip-if here.
  4549. (org-agenda-overriding-header
  4550. (or org-agenda-overriding-header "List of stuck projects: "))
  4551. (matcher (nth 0 org-stuck-projects))
  4552. (todo (nth 1 org-stuck-projects))
  4553. (todo-wds (if (member "*" todo)
  4554. (progn
  4555. (org-agenda-prepare-buffers (org-agenda-files
  4556. nil 'ifmode))
  4557. (org-delete-all
  4558. org-done-keywords-for-agenda
  4559. (copy-sequence org-todo-keywords-for-agenda)))
  4560. todo))
  4561. (todo-re (concat "^\\*+[ \t]+\\("
  4562. (mapconcat 'identity todo-wds "\\|")
  4563. "\\)\\>"))
  4564. (tags (nth 2 org-stuck-projects))
  4565. (tags-re (if (member "*" tags)
  4566. (concat org-outline-regexp-bol
  4567. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4568. (if tags
  4569. (concat org-outline-regexp-bol
  4570. ".*:\\("
  4571. (mapconcat 'identity tags "\\|")
  4572. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4573. (gen-re (nth 3 org-stuck-projects))
  4574. (re-list
  4575. (delq nil
  4576. (list
  4577. (if todo todo-re)
  4578. (if tags tags-re)
  4579. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4580. gen-re)))))
  4581. (setq org-agenda-skip-regexp
  4582. (if re-list
  4583. (mapconcat 'identity re-list "\\|")
  4584. (error "No information how to identify unstuck projects")))
  4585. (org-tags-view nil matcher)
  4586. (with-current-buffer org-agenda-buffer-name
  4587. (setq org-agenda-redo-command
  4588. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4589. ;;; Diary integration
  4590. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4591. (defvar diary-list-entries-hook)
  4592. (defvar diary-time-regexp)
  4593. (defun org-get-entries-from-diary (date)
  4594. "Get the (Emacs Calendar) diary entries for DATE."
  4595. (require 'diary-lib)
  4596. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4597. (diary-display-hook '(fancy-diary-display))
  4598. (diary-display-function 'fancy-diary-display)
  4599. (pop-up-frames nil)
  4600. (diary-list-entries-hook
  4601. (cons 'org-diary-default-entry diary-list-entries-hook))
  4602. (diary-file-name-prefix nil) ; turn this feature off
  4603. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4604. entries
  4605. (org-disable-agenda-to-diary t))
  4606. (save-excursion
  4607. (save-window-excursion
  4608. (funcall (if (fboundp 'diary-list-entries)
  4609. 'diary-list-entries 'list-diary-entries)
  4610. date 1)))
  4611. (if (not (get-buffer diary-fancy-buffer))
  4612. (setq entries nil)
  4613. (with-current-buffer diary-fancy-buffer
  4614. (setq buffer-read-only nil)
  4615. (if (zerop (buffer-size))
  4616. ;; No entries
  4617. (setq entries nil)
  4618. ;; Omit the date and other unnecessary stuff
  4619. (org-agenda-cleanup-fancy-diary)
  4620. ;; Add prefix to each line and extend the text properties
  4621. (if (zerop (buffer-size))
  4622. (setq entries nil)
  4623. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4624. (setq entries
  4625. (with-temp-buffer
  4626. (insert entries) (goto-char (point-min))
  4627. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4628. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4629. (replace-match (concat "; " (match-string 1)))))
  4630. (buffer-string)))))
  4631. (set-buffer-modified-p nil)
  4632. (kill-buffer diary-fancy-buffer)))
  4633. (when entries
  4634. (setq entries (org-split-string entries "\n"))
  4635. (setq entries
  4636. (mapcar
  4637. (lambda (x)
  4638. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4639. ;; Extend the text properties to the beginning of the line
  4640. (org-add-props x (text-properties-at (1- (length x)) x)
  4641. 'type "diary" 'date date 'face 'org-agenda-diary))
  4642. entries)))))
  4643. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4644. "Hook run when the fancy diary buffer is cleaned up.")
  4645. (defun org-agenda-cleanup-fancy-diary ()
  4646. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4647. This gets rid of the date, the underline under the date, and
  4648. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4649. date. It also removes lines that contain only whitespace."
  4650. (goto-char (point-min))
  4651. (if (looking-at ".*?:[ \t]*")
  4652. (progn
  4653. (replace-match "")
  4654. (re-search-forward "\n=+$" nil t)
  4655. (replace-match "")
  4656. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4657. (re-search-forward "\n=+$" nil t)
  4658. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4659. (goto-char (point-min))
  4660. (while (re-search-forward "^ +\n" nil t)
  4661. (replace-match ""))
  4662. (goto-char (point-min))
  4663. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4664. (replace-match ""))
  4665. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4666. ;; Make sure entries from the diary have the right text properties.
  4667. (eval-after-load "diary-lib"
  4668. '(if (boundp 'diary-modify-entry-list-string-function)
  4669. ;; We can rely on the hook, nothing to do
  4670. nil
  4671. ;; Hook not available, must use advice to make this work
  4672. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4673. "Make the position visible."
  4674. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4675. (stringp string)
  4676. buffer-file-name)
  4677. (setq string (org-modify-diary-entry-string string))))))
  4678. (defun org-modify-diary-entry-string (string)
  4679. "Add text properties to string, allowing org-mode to act on it."
  4680. (org-add-props string nil
  4681. 'mouse-face 'highlight
  4682. 'help-echo (if buffer-file-name
  4683. (format "mouse-2 or RET jump to diary file %s"
  4684. (abbreviate-file-name buffer-file-name))
  4685. "")
  4686. 'org-agenda-diary-link t
  4687. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4688. (defun org-diary-default-entry ()
  4689. "Add a dummy entry to the diary.
  4690. Needed to avoid empty dates which mess up holiday display."
  4691. ;; Catch the error if dealing with the new add-to-diary-alist
  4692. (when org-disable-agenda-to-diary
  4693. (condition-case nil
  4694. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4695. (error
  4696. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4697. (defun org-add-to-diary-list (&rest args)
  4698. (if (fboundp 'diary-add-to-list)
  4699. (apply 'diary-add-to-list args)
  4700. (apply 'add-to-diary-list args)))
  4701. (defvar org-diary-last-run-time nil)
  4702. ;;;###autoload
  4703. (defun org-diary (&rest args)
  4704. "Return diary information from org files.
  4705. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4706. It accesses org files and extracts information from those files to be
  4707. listed in the diary. The function accepts arguments specifying what
  4708. items should be listed. For a list of arguments allowed here, see the
  4709. variable `org-agenda-entry-types'.
  4710. The call in the diary file should look like this:
  4711. &%%(org-diary) ~/path/to/some/orgfile.org
  4712. Use a separate line for each org file to check. Or, if you omit the file name,
  4713. all files listed in `org-agenda-files' will be checked automatically:
  4714. &%%(org-diary)
  4715. If you don't give any arguments (as in the example above), the default
  4716. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4717. So the example above may also be written as
  4718. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4719. The function expects the lisp variables `entry' and `date' to be provided
  4720. by the caller, because this is how the calendar works. Don't use this
  4721. function from a program - use `org-agenda-get-day-entries' instead."
  4722. (when (> (- (org-float-time)
  4723. org-agenda-last-marker-time)
  4724. 5)
  4725. ;; I am not sure if this works with sticky agendas, because the marker
  4726. ;; list is then no longer a global variable.
  4727. (org-agenda-reset-markers))
  4728. (org-compile-prefix-format 'agenda)
  4729. (org-set-sorting-strategy 'agenda)
  4730. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4731. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4732. (list entry)
  4733. (org-agenda-files t)))
  4734. (time (org-float-time))
  4735. file rtn results)
  4736. (when (or (not org-diary-last-run-time)
  4737. (> (- time
  4738. org-diary-last-run-time)
  4739. 3))
  4740. (org-agenda-prepare-buffers files))
  4741. (setq org-diary-last-run-time time)
  4742. ;; If this is called during org-agenda, don't return any entries to
  4743. ;; the calendar. Org Agenda will list these entries itself.
  4744. (if org-disable-agenda-to-diary (setq files nil))
  4745. (while (setq file (pop files))
  4746. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4747. (setq results (append results rtn)))
  4748. (when results
  4749. (setq results
  4750. (mapcar (lambda (i) (replace-regexp-in-string
  4751. org-bracket-link-regexp "\\3" i)) results))
  4752. (concat (org-agenda-finalize-entries results) "\n"))))
  4753. ;;; Agenda entry finders
  4754. (defun org-agenda-get-day-entries (file date &rest args)
  4755. "Does the work for `org-diary' and `org-agenda'.
  4756. FILE is the path to a file to be checked for entries. DATE is date like
  4757. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4758. which kind of entries should be extracted. For details about these, see
  4759. the documentation of `org-diary'."
  4760. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4761. (let* ((org-startup-folded nil)
  4762. (org-startup-align-all-tables nil)
  4763. (buffer (if (file-exists-p file)
  4764. (org-get-agenda-file-buffer file)
  4765. (error "No such file %s" file)))
  4766. arg results rtn deadline-results)
  4767. (if (not buffer)
  4768. ;; If file does not exist, make sure an error message ends up in diary
  4769. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4770. (with-current-buffer buffer
  4771. (unless (derived-mode-p 'org-mode)
  4772. (error "Agenda file %s is not in `org-mode'" file))
  4773. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4774. (let ((case-fold-search nil))
  4775. (save-excursion
  4776. (save-restriction
  4777. (if org-agenda-restrict
  4778. (narrow-to-region org-agenda-restrict-begin
  4779. org-agenda-restrict-end)
  4780. (widen))
  4781. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4782. (while (setq arg (pop args))
  4783. (cond
  4784. ((and (eq arg :todo)
  4785. (equal date (calendar-gregorian-from-absolute
  4786. (org-today))))
  4787. (setq rtn (org-agenda-get-todos))
  4788. (setq results (append results rtn)))
  4789. ((eq arg :timestamp)
  4790. (setq rtn (org-agenda-get-blocks))
  4791. (setq results (append results rtn))
  4792. (setq rtn (org-agenda-get-timestamps deadline-results))
  4793. (setq results (append results rtn)))
  4794. ((eq arg :sexp)
  4795. (setq rtn (org-agenda-get-sexps))
  4796. (setq results (append results rtn)))
  4797. ((eq arg :scheduled)
  4798. (setq rtn (org-agenda-get-scheduled deadline-results))
  4799. (setq results (append results rtn)))
  4800. ((eq arg :closed)
  4801. (setq rtn (org-agenda-get-progress))
  4802. (setq results (append results rtn)))
  4803. ((eq arg :deadline)
  4804. (setq rtn (org-agenda-get-deadlines))
  4805. (setq deadline-results (copy-sequence rtn))
  4806. (setq results (append results rtn))))))))
  4807. results))))
  4808. (defsubst org-em (x y list)
  4809. "Is X or Y a member of LIST?"
  4810. (or (memq x list) (memq y list)))
  4811. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4812. (defvar org-agenda-sorting-strategy-selected nil)
  4813. (defun org-agenda-get-todos ()
  4814. "Return the TODO information for agenda display."
  4815. (let* ((props (list 'face nil
  4816. 'done-face 'org-agenda-done
  4817. 'org-not-done-regexp org-not-done-regexp
  4818. 'org-todo-regexp org-todo-regexp
  4819. 'org-complex-heading-regexp org-complex-heading-regexp
  4820. 'mouse-face 'highlight
  4821. 'help-echo
  4822. (format "mouse-2 or RET jump to org file %s"
  4823. (abbreviate-file-name buffer-file-name))))
  4824. (regexp (format org-heading-keyword-regexp-format
  4825. (cond
  4826. ((and org-select-this-todo-keyword
  4827. (equal org-select-this-todo-keyword "*"))
  4828. org-todo-regexp)
  4829. (org-select-this-todo-keyword
  4830. (concat "\\("
  4831. (mapconcat 'identity
  4832. (org-split-string
  4833. org-select-this-todo-keyword
  4834. "|")
  4835. "\\|") "\\)"))
  4836. (t org-not-done-regexp))))
  4837. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4838. ee txt beg end inherited-tags)
  4839. (goto-char (point-min))
  4840. (while (re-search-forward regexp nil t)
  4841. (catch :skip
  4842. (save-match-data
  4843. (beginning-of-line)
  4844. (org-agenda-skip)
  4845. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4846. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4847. (goto-char (1+ beg))
  4848. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4849. (throw :skip nil)))
  4850. (goto-char (match-beginning 2))
  4851. (setq marker (org-agenda-new-marker (match-beginning 0))
  4852. category (org-get-category)
  4853. ts-date (let (ts)
  4854. (save-match-data
  4855. (cond ((org-em 'scheduled-up 'scheduled-down
  4856. org-agenda-sorting-strategy-selected)
  4857. (setq ts (org-entry-get (point) "SCHEDULED")
  4858. ts-date-type " scheduled"))
  4859. ((org-em 'deadline-up 'deadline-down
  4860. org-agenda-sorting-strategy-selected)
  4861. (setq ts (org-entry-get (point) "DEADLINE")
  4862. ts-date-type " deadline"))
  4863. ((org-em 'ts-up 'ts-down
  4864. org-agenda-sorting-strategy-selected)
  4865. (setq ts (org-entry-get (point) "TIMESTAMP")
  4866. ts-date-type " timestamp"))
  4867. ((org-em 'tsia-up 'tsia-down
  4868. org-agenda-sorting-strategy-selected)
  4869. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4870. ts-date-type " timestamp_ia"))
  4871. ((org-em 'timestamp-up 'timestamp-down
  4872. org-agenda-sorting-strategy-selected)
  4873. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4874. (org-entry-get (point) "DEADLINE")
  4875. (org-entry-get (point) "TIMESTAMP")
  4876. (org-entry-get (point) "TIMESTAMP_IA"))
  4877. ts-date-type ""))
  4878. (t (setq ts-date-type "")))
  4879. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4880. category-pos (get-text-property (point) 'org-category-position)
  4881. txt (org-trim
  4882. (buffer-substring (match-beginning 2) (match-end 0)))
  4883. inherited-tags
  4884. (or (eq org-agenda-show-inherited-tags 'always)
  4885. (and (listp org-agenda-show-inherited-tags)
  4886. (memq 'todo org-agenda-show-inherited-tags))
  4887. (and (eq org-agenda-show-inherited-tags t)
  4888. (or (eq org-agenda-use-tag-inheritance t)
  4889. (memq 'todo org-agenda-use-tag-inheritance))))
  4890. tags (org-get-tags-at nil (not inherited-tags))
  4891. level (make-string (org-reduced-level (org-outline-level)) ? )
  4892. txt (org-agenda-format-item "" txt level category tags t)
  4893. priority (1+ (org-get-priority txt))
  4894. todo-state (org-get-todo-state))
  4895. (org-add-props txt props
  4896. 'org-marker marker 'org-hd-marker marker
  4897. 'priority priority 'org-category category
  4898. 'level level
  4899. 'ts-date ts-date
  4900. 'org-category-position category-pos
  4901. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4902. (push txt ee)
  4903. (if org-agenda-todo-list-sublevels
  4904. (goto-char (match-end 2))
  4905. (org-end-of-subtree 'invisible))))
  4906. (nreverse ee)))
  4907. (defun org-agenda-todo-custom-ignore-p (time n)
  4908. "Check whether timestamp is farther away than n number of days.
  4909. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4910. `org-agenda-todo-ignore-scheduled' or
  4911. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4912. (let ((days (org-time-stamp-to-now
  4913. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4914. (if (>= n 0)
  4915. (>= days n)
  4916. (<= days n))))
  4917. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4918. (&optional end)
  4919. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4920. (when (or org-agenda-todo-ignore-with-date
  4921. org-agenda-todo-ignore-scheduled
  4922. org-agenda-todo-ignore-deadlines
  4923. org-agenda-todo-ignore-timestamp)
  4924. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4925. (save-excursion
  4926. (or (and org-agenda-todo-ignore-with-date
  4927. (re-search-forward org-ts-regexp end t))
  4928. (and org-agenda-todo-ignore-scheduled
  4929. (re-search-forward org-scheduled-time-regexp end t)
  4930. (cond
  4931. ((eq org-agenda-todo-ignore-scheduled 'future)
  4932. (> (org-time-stamp-to-now
  4933. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4934. ((eq org-agenda-todo-ignore-scheduled 'past)
  4935. (<= (org-time-stamp-to-now
  4936. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4937. ((numberp org-agenda-todo-ignore-scheduled)
  4938. (org-agenda-todo-custom-ignore-p
  4939. (match-string 1) org-agenda-todo-ignore-scheduled))
  4940. (t)))
  4941. (and org-agenda-todo-ignore-deadlines
  4942. (re-search-forward org-deadline-time-regexp end t)
  4943. (cond
  4944. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4945. ((eq org-agenda-todo-ignore-deadlines 'far)
  4946. (not (org-deadline-close (match-string 1))))
  4947. ((eq org-agenda-todo-ignore-deadlines 'future)
  4948. (> (org-time-stamp-to-now
  4949. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4950. ((eq org-agenda-todo-ignore-deadlines 'past)
  4951. (<= (org-time-stamp-to-now
  4952. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4953. ((numberp org-agenda-todo-ignore-deadlines)
  4954. (org-agenda-todo-custom-ignore-p
  4955. (match-string 1) org-agenda-todo-ignore-deadlines))
  4956. (t (org-deadline-close (match-string 1)))))
  4957. (and org-agenda-todo-ignore-timestamp
  4958. (let ((buffer (current-buffer))
  4959. (regexp
  4960. (concat
  4961. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4962. (start (point)))
  4963. ;; Copy current buffer into a temporary one
  4964. (with-temp-buffer
  4965. (insert-buffer-substring buffer start end)
  4966. (goto-char (point-min))
  4967. ;; Delete SCHEDULED and DEADLINE items
  4968. (while (re-search-forward regexp end t)
  4969. (delete-region (match-beginning 0) (match-end 0)))
  4970. (goto-char (point-min))
  4971. ;; No search for timestamp left
  4972. (when (re-search-forward org-ts-regexp nil t)
  4973. (cond
  4974. ((eq org-agenda-todo-ignore-timestamp 'future)
  4975. (> (org-time-stamp-to-now
  4976. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4977. ((eq org-agenda-todo-ignore-timestamp 'past)
  4978. (<= (org-time-stamp-to-now
  4979. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4980. ((numberp org-agenda-todo-ignore-timestamp)
  4981. (org-agenda-todo-custom-ignore-p
  4982. (match-string 1) org-agenda-todo-ignore-timestamp))
  4983. (t))))))))))
  4984. (defun org-agenda-get-timestamps (&optional deadline-results)
  4985. "Return the date stamp information for agenda display."
  4986. (let* ((props (list 'face 'org-agenda-calendar-event
  4987. 'org-not-done-regexp org-not-done-regexp
  4988. 'org-todo-regexp org-todo-regexp
  4989. 'org-complex-heading-regexp org-complex-heading-regexp
  4990. 'mouse-face 'highlight
  4991. 'help-echo
  4992. (format "mouse-2 or RET jump to org file %s"
  4993. (abbreviate-file-name buffer-file-name))))
  4994. (d1 (calendar-absolute-from-gregorian date))
  4995. mm
  4996. (deadline-position-alist
  4997. (mapcar (lambda (a) (and (setq mm (get-text-property
  4998. 0 'org-hd-marker a))
  4999. (cons (marker-position mm) a)))
  5000. deadline-results))
  5001. (remove-re org-ts-regexp)
  5002. (regexp
  5003. (concat
  5004. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5005. (regexp-quote
  5006. (substring
  5007. (format-time-string
  5008. (car org-time-stamp-formats)
  5009. (apply 'encode-time ; DATE bound by calendar
  5010. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5011. 1 11))
  5012. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5013. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5014. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5015. donep tmp priority category category-pos level ee txt timestr tags
  5016. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5017. inherited-tags ts-date)
  5018. (goto-char (point-min))
  5019. (while (setq end-of-match (re-search-forward regexp nil t))
  5020. (setq b0 (match-beginning 0)
  5021. b3 (match-beginning 3) e3 (match-end 3)
  5022. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5023. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5024. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5025. (member todo-state
  5026. org-agenda-repeating-timestamp-show-all)))
  5027. (catch :skip
  5028. (and (org-at-date-range-p) (throw :skip nil))
  5029. (org-agenda-skip)
  5030. (if (and (match-end 1)
  5031. (not (= d1 (org-time-string-to-absolute
  5032. (match-string 1) d1 nil show-all
  5033. (current-buffer) b0))))
  5034. (throw :skip nil))
  5035. (if (and e3
  5036. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5037. (throw :skip nil))
  5038. (setq tmp (buffer-substring (max (point-min)
  5039. (- b0 org-ds-keyword-length))
  5040. b0)
  5041. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5042. inactivep (= (char-after b0) ?\[)
  5043. deadlinep (string-match org-deadline-regexp tmp)
  5044. scheduledp (string-match org-scheduled-regexp tmp)
  5045. closedp (and org-agenda-include-inactive-timestamps
  5046. (string-match org-closed-string tmp))
  5047. clockp (and org-agenda-include-inactive-timestamps
  5048. (or (string-match org-clock-string tmp)
  5049. (string-match "]-+\\'" tmp)))
  5050. warntime (get-text-property (point) 'org-appt-warntime)
  5051. donep (member todo-state org-done-keywords))
  5052. (if (or scheduledp deadlinep closedp clockp
  5053. (and donep org-agenda-skip-timestamp-if-done))
  5054. (throw :skip t))
  5055. (if (string-match ">" timestr)
  5056. ;; substring should only run to end of time stamp
  5057. (setq timestr (substring timestr 0 (match-end 0))))
  5058. (setq marker (org-agenda-new-marker b0)
  5059. category (org-get-category b0)
  5060. category-pos (get-text-property b0 'org-category-position))
  5061. (save-excursion
  5062. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5063. (throw :skip nil)
  5064. (goto-char (match-beginning 0))
  5065. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5066. (assoc (point) deadline-position-alist))
  5067. (throw :skip nil))
  5068. (setq hdmarker (org-agenda-new-marker)
  5069. inherited-tags
  5070. (or (eq org-agenda-show-inherited-tags 'always)
  5071. (and (listp org-agenda-show-inherited-tags)
  5072. (memq 'agenda org-agenda-show-inherited-tags))
  5073. (and (eq org-agenda-show-inherited-tags t)
  5074. (or (eq org-agenda-use-tag-inheritance t)
  5075. (memq 'agenda org-agenda-use-tag-inheritance))))
  5076. tags (org-get-tags-at nil (not inherited-tags))
  5077. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5078. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5079. (setq head (or (match-string 1) ""))
  5080. (setq txt (org-agenda-format-item
  5081. (if inactivep org-agenda-inactive-leader nil)
  5082. head level category tags timestr
  5083. remove-re habitp)))
  5084. (setq priority (org-get-priority txt))
  5085. (org-add-props txt props 'priority priority
  5086. 'org-marker marker 'org-hd-marker hdmarker
  5087. 'org-category category 'date date
  5088. 'level level
  5089. 'ts-date
  5090. (ignore-errors (org-time-string-to-absolute timestr))
  5091. 'org-category-position category-pos
  5092. 'todo-state todo-state
  5093. 'warntime warntime
  5094. 'type "timestamp")
  5095. (push txt ee))
  5096. (if org-agenda-skip-additional-timestamps-same-entry
  5097. (outline-next-heading)
  5098. (goto-char end-of-match))))
  5099. (nreverse ee)))
  5100. (defun org-agenda-get-sexps ()
  5101. "Return the sexp information for agenda display."
  5102. (require 'diary-lib)
  5103. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5104. 'mouse-face 'highlight
  5105. 'help-echo
  5106. (format "mouse-2 or RET jump to org file %s"
  5107. (abbreviate-file-name buffer-file-name))))
  5108. (regexp "^&?%%(")
  5109. marker category extra category-pos level ee txt tags entry
  5110. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5111. (goto-char (point-min))
  5112. (while (re-search-forward regexp nil t)
  5113. (catch :skip
  5114. (org-agenda-skip)
  5115. (setq beg (match-beginning 0))
  5116. (goto-char (1- (match-end 0)))
  5117. (setq b (point))
  5118. (forward-sexp 1)
  5119. (setq sexp (buffer-substring b (point)))
  5120. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5121. (org-trim (match-string 1))
  5122. ""))
  5123. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5124. (when result
  5125. (setq marker (org-agenda-new-marker beg)
  5126. level (make-string (org-reduced-level (org-outline-level)) ? )
  5127. category (org-get-category beg)
  5128. category-pos (get-text-property beg 'org-category-position)
  5129. inherited-tags
  5130. (or (eq org-agenda-show-inherited-tags 'always)
  5131. (and (listp org-agenda-show-inherited-tags)
  5132. (memq 'agenda org-agenda-show-inherited-tags))
  5133. (and (eq org-agenda-show-inherited-tags t)
  5134. (or (eq org-agenda-use-tag-inheritance t)
  5135. (memq 'agenda org-agenda-use-tag-inheritance))))
  5136. tags (org-get-tags-at nil (not inherited-tags))
  5137. todo-state (org-get-todo-state)
  5138. warntime (get-text-property (point) 'org-appt-warntime)
  5139. extra nil)
  5140. (dolist (r (if (stringp result)
  5141. (list result)
  5142. result)) ;; we expect a list here
  5143. (when (and org-agenda-diary-sexp-prefix
  5144. (string-match org-agenda-diary-sexp-prefix r))
  5145. (setq extra (match-string 0 r)
  5146. r (replace-match "" nil nil r)))
  5147. (if (string-match "\\S-" r)
  5148. (setq txt r)
  5149. (setq txt "SEXP entry returned empty string"))
  5150. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5151. (org-add-props txt props 'org-marker marker
  5152. 'org-category category 'date date 'todo-state todo-state
  5153. 'org-category-position category-pos 'tags tags
  5154. 'level level
  5155. 'type "sexp" 'warntime warntime)
  5156. (push txt ee)))))
  5157. (nreverse ee)))
  5158. ;; Calendar sanity: define some functions that are independent of
  5159. ;; `calendar-date-style'.
  5160. ;; Normally I would like to use ISO format when calling the diary functions,
  5161. ;; but to make sure we still have Emacs 22 compatibility we bind
  5162. ;; also `european-calendar-style' and use european format
  5163. (defun org-anniversary (year month day &optional mark)
  5164. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5165. (org-no-warnings
  5166. (let ((calendar-date-style 'european) (european-calendar-style t))
  5167. (diary-anniversary day month year mark))))
  5168. (defun org-cyclic (N year month day &optional mark)
  5169. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5170. (org-no-warnings
  5171. (let ((calendar-date-style 'european) (european-calendar-style t))
  5172. (diary-cyclic N day month year mark))))
  5173. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5174. "Like `diary-block', but with fixed (ISO) order of arguments."
  5175. (org-no-warnings
  5176. (let ((calendar-date-style 'european) (european-calendar-style t))
  5177. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5178. (defun org-date (year month day &optional mark)
  5179. "Like `diary-date', but with fixed (ISO) order of arguments."
  5180. (org-no-warnings
  5181. (let ((calendar-date-style 'european) (european-calendar-style t))
  5182. (diary-date day month year mark))))
  5183. ;; Define the` org-class' function
  5184. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5185. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5186. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5187. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5188. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5189. `holidays', then any date that is known by the Emacs calendar to be a
  5190. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5191. then those holidays will be skipped."
  5192. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5193. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5194. (d (calendar-absolute-from-gregorian date))
  5195. (h (when skip-weeks (calendar-check-holidays date))))
  5196. (and
  5197. (<= date1 d)
  5198. (<= d date2)
  5199. (= (calendar-day-of-week date) dayname)
  5200. (or (not skip-weeks)
  5201. (progn
  5202. (require 'cal-iso)
  5203. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5204. (not (or (and h (memq 'holidays skip-weeks))
  5205. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5206. entry)))
  5207. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5208. "Like `org-class', but honor `calendar-date-style'.
  5209. The order of the first 2 times 3 arguments depends on the variable
  5210. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5211. So for American calendars, give this as MONTH DAY YEAR, for European as
  5212. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5213. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5214. is any number of ISO weeks in the block period for which the item should
  5215. be skipped.
  5216. This function is here only for backward compatibility and it is deprecated,
  5217. please use `org-class' instead."
  5218. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5219. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5220. (org-class
  5221. (nth 2 date1) (car date1) (nth 1 date1)
  5222. (nth 2 date2) (car date2) (nth 1 date2)
  5223. dayname skip-weeks)))
  5224. (make-obsolete 'org-diary-class 'org-class "")
  5225. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5226. (defalias 'org-get-closed 'org-agenda-get-progress)
  5227. (defun org-agenda-get-progress ()
  5228. "Return the logged TODO entries for agenda display."
  5229. (let* ((props (list 'mouse-face 'highlight
  5230. 'org-not-done-regexp org-not-done-regexp
  5231. 'org-todo-regexp org-todo-regexp
  5232. 'org-complex-heading-regexp org-complex-heading-regexp
  5233. 'help-echo
  5234. (format "mouse-2 or RET jump to org file %s"
  5235. (abbreviate-file-name buffer-file-name))))
  5236. (items (if (consp org-agenda-show-log-scoped)
  5237. org-agenda-show-log-scoped
  5238. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5239. '(clock)
  5240. org-agenda-log-mode-items)))
  5241. (parts
  5242. (delq nil
  5243. (list
  5244. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5245. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5246. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5247. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5248. (error "`org-agenda-log-mode-items' is empty")))
  5249. (regexp (concat
  5250. "\\(" parts-re "\\)"
  5251. " *\\["
  5252. (regexp-quote
  5253. (substring
  5254. (format-time-string
  5255. (car org-time-stamp-formats)
  5256. (apply 'encode-time ; DATE bound by calendar
  5257. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5258. 1 11))))
  5259. (org-agenda-search-headline-for-time nil)
  5260. marker hdmarker priority category category-pos level tags closedp
  5261. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5262. (goto-char (point-min))
  5263. (while (re-search-forward regexp nil t)
  5264. (catch :skip
  5265. (org-agenda-skip)
  5266. (setq marker (org-agenda-new-marker (match-beginning 0))
  5267. closedp (equal (match-string 1) org-closed-string)
  5268. statep (equal (string-to-char (match-string 1)) ?-)
  5269. clockp (not (or closedp statep))
  5270. state (and statep (match-string 2))
  5271. category (org-get-category (match-beginning 0))
  5272. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5273. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5274. (when (string-match "\\]" timestr)
  5275. ;; substring should only run to end of time stamp
  5276. (setq rest (substring timestr (match-end 0))
  5277. timestr (substring timestr 0 (match-end 0)))
  5278. (if (and (not closedp) (not statep)
  5279. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5280. rest))
  5281. (progn (setq timestr (concat (substring timestr 0 -1)
  5282. "-" (match-string 1 rest) "]"))
  5283. (setq clocked (match-string 2 rest)))
  5284. (setq clocked "-")))
  5285. (save-excursion
  5286. (setq extra
  5287. (cond
  5288. ((not org-agenda-log-mode-add-notes) nil)
  5289. (statep
  5290. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5291. (match-string 1)))
  5292. (clockp
  5293. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5294. (match-string 1)))))
  5295. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5296. (throw :skip nil)
  5297. (goto-char (match-beginning 0))
  5298. (setq hdmarker (org-agenda-new-marker)
  5299. inherited-tags
  5300. (or (eq org-agenda-show-inherited-tags 'always)
  5301. (and (listp org-agenda-show-inherited-tags)
  5302. (memq 'todo org-agenda-show-inherited-tags))
  5303. (and (eq org-agenda-show-inherited-tags t)
  5304. (or (eq org-agenda-use-tag-inheritance t)
  5305. (memq 'todo org-agenda-use-tag-inheritance))))
  5306. tags (org-get-tags-at nil (not inherited-tags))
  5307. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5308. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5309. (setq txt (match-string 1))
  5310. (when extra
  5311. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5312. (setq txt (concat (substring txt 0 (match-beginning 1))
  5313. " - " extra " " (match-string 2 txt)))
  5314. (setq txt (concat txt " - " extra))))
  5315. (setq txt (org-agenda-format-item
  5316. (cond
  5317. (closedp "Closed: ")
  5318. (statep (concat "State: (" state ")"))
  5319. (t (concat "Clocked: (" clocked ")")))
  5320. txt level category tags timestr)))
  5321. (setq priority 100000)
  5322. (org-add-props txt props
  5323. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5324. 'priority priority 'org-category category
  5325. 'org-category-position category-pos
  5326. 'level level
  5327. 'type "closed" 'date date
  5328. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5329. (push txt ee))
  5330. (goto-char (point-at-eol))))
  5331. (nreverse ee)))
  5332. (defun org-agenda-show-clocking-issues ()
  5333. "Add overlays, showing issues with clocking.
  5334. See also the user option `org-agenda-clock-consistency-checks'."
  5335. (interactive)
  5336. (let* ((org-time-clocksum-use-effort-durations nil)
  5337. (pl org-agenda-clock-consistency-checks)
  5338. (re (concat "^[ \t]*"
  5339. org-clock-string
  5340. "[ \t]+"
  5341. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5342. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5343. (tlstart 0.)
  5344. (tlend 0.)
  5345. (maxtime (org-hh:mm-string-to-minutes
  5346. (or (plist-get pl :max-duration) "24:00")))
  5347. (mintime (org-hh:mm-string-to-minutes
  5348. (or (plist-get pl :min-duration) 0)))
  5349. (maxgap (org-hh:mm-string-to-minutes
  5350. ;; default 30:00 means never complain
  5351. (or (plist-get pl :max-gap) "30:00")))
  5352. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5353. (plist-get pl :gap-ok-around)))
  5354. (def-face (or (plist-get pl :default-face)
  5355. '((:background "DarkRed") (:foreground "white"))))
  5356. issue face m te ts dt ov)
  5357. (goto-char (point-min))
  5358. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5359. (setq issue nil face def-face)
  5360. (catch 'next
  5361. (setq m (org-get-at-bol 'org-marker)
  5362. te nil ts nil)
  5363. (unless (and m (markerp m))
  5364. (setq issue "No valid clock line") (throw 'next t))
  5365. (org-with-point-at m
  5366. (save-excursion
  5367. (goto-char (point-at-bol))
  5368. (unless (looking-at re)
  5369. (error "No valid Clock line")
  5370. (throw 'next t))
  5371. (unless (match-end 3)
  5372. (setq issue "No end time"
  5373. face (or (plist-get pl :no-end-time-face) face))
  5374. (throw 'next t))
  5375. (setq ts (match-string 1)
  5376. te (match-string 3)
  5377. ts (org-float-time
  5378. (apply 'encode-time (org-parse-time-string ts)))
  5379. te (org-float-time
  5380. (apply 'encode-time (org-parse-time-string te)))
  5381. dt (- te ts))))
  5382. (cond
  5383. ((> dt (* 60 maxtime))
  5384. ;; a very long clocking chunk
  5385. (setq issue (format "Clocking interval is very long: %s"
  5386. (org-minutes-to-clocksum-string
  5387. (floor (/ (float dt) 60.))))
  5388. face (or (plist-get pl :long-face) face)))
  5389. ((< dt (* 60 mintime))
  5390. ;; a very short clocking chunk
  5391. (setq issue (format "Clocking interval is very short: %s"
  5392. (org-minutes-to-clocksum-string
  5393. (floor (/ (float dt) 60.))))
  5394. face (or (plist-get pl :short-face) face)))
  5395. ((and (> tlend 0) (< ts tlend))
  5396. ;; Two clock entries are overlapping
  5397. (setq issue (format "Clocking overlap: %d minutes"
  5398. (/ (- tlend ts) 60))
  5399. face (or (plist-get pl :overlap-face) face)))
  5400. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5401. ;; There is a gap, lets see if we need to report it
  5402. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5403. (setq issue (format "Clocking gap: %d minutes"
  5404. (/ (- ts tlend) 60))
  5405. face (or (plist-get pl :gap-face) face))))
  5406. (t nil)))
  5407. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5408. (when issue
  5409. ;; OK, there was some issue, add an overlay to show the issue
  5410. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5411. (overlay-put ov 'before-string
  5412. (concat
  5413. (org-add-props
  5414. (format "%-43s" (concat " " issue))
  5415. nil
  5416. 'face face)
  5417. "\n"))
  5418. (overlay-put ov 'evaporate t)))))
  5419. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5420. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5421. (catch 'exit
  5422. (unless ok-list
  5423. ;; there are no OK times for gaps...
  5424. (throw 'exit nil))
  5425. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5426. ;; This is more than 24 hours, so it is OK.
  5427. ;; because we have at least one OK time, that must be in the
  5428. ;; 24 hour interval.
  5429. (throw 'exit t))
  5430. ;; We have a shorter gap.
  5431. ;; Now we have to get the minute of the day when these times are
  5432. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5433. (t2dec (decode-time (seconds-to-time t2)))
  5434. ;; compute the minute on the day
  5435. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5436. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5437. (when (< min2 min1)
  5438. ;; if min2 is smaller than min1, this means it is on the next day.
  5439. ;; Wrap it to after midnight.
  5440. (setq min2 (+ min2 1440)))
  5441. ;; Now check if any of the OK times is in the gap
  5442. (mapc (lambda (x)
  5443. ;; Wrap the time to after midnight if necessary
  5444. (if (< x min1) (setq x (+ x 1440)))
  5445. ;; Check if in interval
  5446. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5447. ok-list)
  5448. ;; Nope, this gap is not OK
  5449. nil)))
  5450. (defun org-agenda-get-deadlines ()
  5451. "Return the deadline information for agenda display."
  5452. (let* ((props (list 'mouse-face 'highlight
  5453. 'org-not-done-regexp org-not-done-regexp
  5454. 'org-todo-regexp org-todo-regexp
  5455. 'org-complex-heading-regexp org-complex-heading-regexp
  5456. 'help-echo
  5457. (format "mouse-2 or RET jump to org file %s"
  5458. (abbreviate-file-name buffer-file-name))))
  5459. (regexp org-deadline-time-regexp)
  5460. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5461. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5462. (dl0 (car org-agenda-deadline-leaders))
  5463. (dl1 (nth 1 org-agenda-deadline-leaders))
  5464. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5465. d2 diff dfrac wdays pos pos1 category category-pos level
  5466. tags suppress-prewarning ee txt head face s todo-state
  5467. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5468. (goto-char (point-min))
  5469. (while (re-search-forward regexp nil t)
  5470. (catch :skip
  5471. (org-agenda-skip)
  5472. (setq s (match-string 1)
  5473. txt nil
  5474. pos (1- (match-beginning 1))
  5475. todo-state (save-match-data (org-get-todo-state))
  5476. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5477. (member todo-state
  5478. org-agenda-repeating-timestamp-show-all))
  5479. d2 (org-time-string-to-absolute
  5480. s d1 'past show-all (current-buffer) pos)
  5481. diff (- d2 d1))
  5482. (setq suppress-prewarning
  5483. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5484. (let ((item (buffer-substring (point-at-bol)
  5485. (point-at-eol))))
  5486. (save-match-data
  5487. (and (string-match
  5488. org-scheduled-time-regexp item)
  5489. (match-string 1 item)))))))
  5490. (cond
  5491. ((not ds) nil)
  5492. ;; The current item has a scheduled date (in ds), so
  5493. ;; evaluate its prewarning lead time.
  5494. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5495. ;; Use global prewarning-restart lead time.
  5496. org-agenda-skip-deadline-prewarning-if-scheduled)
  5497. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5498. 'pre-scheduled)
  5499. ;; Set prewarning to no earlier than scheduled.
  5500. (min (- d2 (org-time-string-to-absolute
  5501. ds d1 'past show-all (current-buffer) pos))
  5502. org-deadline-warning-days))
  5503. ;; Set prewarning to deadline.
  5504. (t 0))))
  5505. (setq wdays (if suppress-prewarning
  5506. (let ((org-deadline-warning-days suppress-prewarning))
  5507. (org-get-wdays s))
  5508. (org-get-wdays s))
  5509. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5510. upcomingp (and todayp (> diff 0)))
  5511. ;; When to show a deadline in the calendar:
  5512. ;; If the expiration is within wdays warning time.
  5513. ;; Past-due deadlines are only shown on the current date
  5514. (if (and (or (and (<= diff wdays)
  5515. (and todayp (not org-agenda-only-exact-dates)))
  5516. (= diff 0)))
  5517. (save-excursion
  5518. ;; (setq todo-state (org-get-todo-state))
  5519. (setq donep (member todo-state org-done-keywords))
  5520. (if (and donep
  5521. (or org-agenda-skip-deadline-if-done
  5522. (not (= diff 0))))
  5523. (setq txt nil)
  5524. (setq category (org-get-category)
  5525. warntime (get-text-property (point) 'org-appt-warntime)
  5526. category-pos (get-text-property (point) 'org-category-position))
  5527. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5528. (throw :skip nil)
  5529. (goto-char (match-end 0))
  5530. (setq pos1 (match-beginning 0))
  5531. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5532. (setq inherited-tags
  5533. (or (eq org-agenda-show-inherited-tags 'always)
  5534. (and (listp org-agenda-show-inherited-tags)
  5535. (memq 'agenda org-agenda-show-inherited-tags))
  5536. (and (eq org-agenda-show-inherited-tags t)
  5537. (or (eq org-agenda-use-tag-inheritance t)
  5538. (memq 'agenda org-agenda-use-tag-inheritance))))
  5539. tags (org-get-tags-at pos1 (not inherited-tags)))
  5540. (setq head (buffer-substring
  5541. (point)
  5542. (progn (skip-chars-forward "^\r\n")
  5543. (point))))
  5544. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5545. (setq timestr
  5546. (concat (substring s (match-beginning 1)) " "))
  5547. (setq timestr 'time))
  5548. (setq txt (org-agenda-format-item
  5549. (cond ((= diff 0) dl0)
  5550. ((> diff 0)
  5551. (if (functionp dl1)
  5552. (funcall dl1 diff date)
  5553. (format dl1 diff)))
  5554. (t
  5555. (if (functionp dl2)
  5556. (funcall dl2 diff date)
  5557. (format dl2 (if (string= dl2 dl1)
  5558. diff (abs diff))))))
  5559. head level category tags
  5560. (if (not (= diff 0)) nil timestr)))))
  5561. (when txt
  5562. (setq face (org-agenda-deadline-face dfrac))
  5563. (org-add-props txt props
  5564. 'org-marker (org-agenda-new-marker pos)
  5565. 'warntime warntime
  5566. 'level level
  5567. 'ts-date d2
  5568. 'org-hd-marker (org-agenda-new-marker pos1)
  5569. 'priority (+ (- diff)
  5570. (org-get-priority txt))
  5571. 'org-category category
  5572. 'org-category-position category-pos
  5573. 'todo-state todo-state
  5574. 'type (if upcomingp "upcoming-deadline" "deadline")
  5575. 'date (if upcomingp date d2)
  5576. 'face (if donep 'org-agenda-done face)
  5577. 'undone-face face 'done-face 'org-agenda-done)
  5578. (push txt ee))))))
  5579. (nreverse ee)))
  5580. (defun org-agenda-deadline-face (fraction)
  5581. "Return the face to displaying a deadline item.
  5582. FRACTION is what fraction of the head-warning time has passed."
  5583. (let ((faces org-agenda-deadline-faces) f)
  5584. (catch 'exit
  5585. (while (setq f (pop faces))
  5586. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5587. (defun org-agenda-get-scheduled (&optional deadline-results)
  5588. "Return the scheduled information for agenda display."
  5589. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5590. 'org-todo-regexp org-todo-regexp
  5591. 'org-complex-heading-regexp org-complex-heading-regexp
  5592. 'done-face 'org-agenda-done
  5593. 'mouse-face 'highlight
  5594. 'help-echo
  5595. (format "mouse-2 or RET jump to org file %s"
  5596. (abbreviate-file-name buffer-file-name))))
  5597. (regexp org-scheduled-time-regexp)
  5598. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5599. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5600. mm
  5601. (deadline-position-alist
  5602. (mapcar (lambda (a) (and (setq mm (get-text-property
  5603. 0 'org-hd-marker a))
  5604. (cons (marker-position mm) a)))
  5605. deadline-results))
  5606. d2 diff pos pos1 category category-pos level tags donep
  5607. ee txt head pastschedp todo-state face timestr s habitp show-all
  5608. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5609. ddays)
  5610. (goto-char (point-min))
  5611. (while (re-search-forward regexp nil t)
  5612. (catch :skip
  5613. (org-agenda-skip)
  5614. (setq s (match-string 1)
  5615. txt nil
  5616. pos (1- (match-beginning 1))
  5617. todo-state (save-match-data (org-get-todo-state))
  5618. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5619. (member todo-state
  5620. org-agenda-repeating-timestamp-show-all))
  5621. d2 (org-time-string-to-absolute
  5622. s d1 'past show-all (current-buffer) pos)
  5623. diff (- d2 d1)
  5624. warntime (get-text-property (point) 'org-appt-warntime))
  5625. (setq pastschedp (and todayp (< diff 0)))
  5626. (setq did-habit-check-p nil)
  5627. (setq suppress-delay
  5628. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5629. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5630. (save-match-data
  5631. (and (string-match
  5632. org-deadline-time-regexp item)
  5633. (match-string 1 item)))))))
  5634. (cond
  5635. ((not ds) nil)
  5636. ;; The current item has a deadline date (in ds), so
  5637. ;; evaluate its delay time.
  5638. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5639. ;; Use global delay time.
  5640. (- org-agenda-skip-scheduled-delay-if-deadline))
  5641. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5642. 'post-deadline)
  5643. ;; Set delay to no later than deadline.
  5644. (min (- d2 (org-time-string-to-absolute
  5645. ds d1 'past show-all (current-buffer) pos))
  5646. org-scheduled-delay-days))
  5647. (t 0))))
  5648. (setq ddays (if suppress-delay
  5649. (let ((org-scheduled-delay-days suppress-delay))
  5650. (org-get-wdays s t t))
  5651. (org-get-wdays s t)))
  5652. ;; Use a delay of 0 when there is a repeater and the delay is
  5653. ;; of the form --3d
  5654. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5655. (< (org-time-string-to-absolute s)
  5656. (org-time-string-to-absolute
  5657. s d2 'past nil (current-buffer) pos)))
  5658. (setq ddays 0))
  5659. ;; When to show a scheduled item in the calendar:
  5660. ;; If it is on or past the date.
  5661. (when (or (and (> ddays 0) (= diff (- ddays)))
  5662. (and (zerop ddays) (= diff 0))
  5663. (and (< (+ diff ddays) 0)
  5664. (< (abs diff) org-scheduled-past-days)
  5665. (and todayp (not org-agenda-only-exact-dates)))
  5666. ;; org-is-habit-p uses org-entry-get, which is expansive
  5667. ;; so we go extra mile to only call it once
  5668. (and todayp
  5669. (boundp 'org-habit-show-all-today)
  5670. org-habit-show-all-today
  5671. (setq did-habit-check-p t)
  5672. (setq habitp (and (functionp 'org-is-habit-p)
  5673. (org-is-habit-p)))))
  5674. (save-excursion
  5675. (setq donep (member todo-state org-done-keywords))
  5676. (if (and donep
  5677. (or org-agenda-skip-scheduled-if-done
  5678. (not (= diff 0))
  5679. (and (functionp 'org-is-habit-p)
  5680. (org-is-habit-p))))
  5681. (setq txt nil)
  5682. (setq habitp (if did-habit-check-p habitp
  5683. (and (functionp 'org-is-habit-p)
  5684. (org-is-habit-p))))
  5685. (setq category (org-get-category)
  5686. category-pos (get-text-property (point) 'org-category-position))
  5687. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5688. 'repeated-after-deadline)
  5689. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5690. (throw :skip nil))
  5691. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5692. (throw :skip nil)
  5693. (goto-char (match-end 0))
  5694. (setq pos1 (match-beginning 0))
  5695. (if habitp
  5696. (if (or (not org-habit-show-habits)
  5697. (and (not todayp)
  5698. (boundp 'org-habit-show-habits-only-for-today)
  5699. org-habit-show-habits-only-for-today))
  5700. (throw :skip nil))
  5701. (if (and
  5702. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5703. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5704. pastschedp))
  5705. (setq mm (assoc pos1 deadline-position-alist)))
  5706. (throw :skip nil)))
  5707. (setq inherited-tags
  5708. (or (eq org-agenda-show-inherited-tags 'always)
  5709. (and (listp org-agenda-show-inherited-tags)
  5710. (memq 'agenda org-agenda-show-inherited-tags))
  5711. (and (eq org-agenda-show-inherited-tags t)
  5712. (or (eq org-agenda-use-tag-inheritance t)
  5713. (memq 'agenda org-agenda-use-tag-inheritance))))
  5714. tags (org-get-tags-at nil (not inherited-tags)))
  5715. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5716. (setq head (buffer-substring
  5717. (point)
  5718. (progn (skip-chars-forward "^\r\n") (point))))
  5719. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5720. (setq timestr
  5721. (concat (substring s (match-beginning 1)) " "))
  5722. (setq timestr 'time))
  5723. (setq txt (org-agenda-format-item
  5724. (if (= diff 0)
  5725. (car org-agenda-scheduled-leaders)
  5726. (format (nth 1 org-agenda-scheduled-leaders)
  5727. (- 1 diff)))
  5728. head level category tags
  5729. (if (not (= diff 0)) nil timestr)
  5730. nil habitp))))
  5731. (when txt
  5732. (setq face
  5733. (cond
  5734. ((and (not habitp) pastschedp)
  5735. 'org-scheduled-previously)
  5736. (todayp 'org-scheduled-today)
  5737. (t 'org-scheduled))
  5738. habitp (and habitp (org-habit-parse-todo)))
  5739. (org-add-props txt props
  5740. 'undone-face face
  5741. 'face (if donep 'org-agenda-done face)
  5742. 'org-marker (org-agenda-new-marker pos)
  5743. 'org-hd-marker (org-agenda-new-marker pos1)
  5744. 'type (if pastschedp "past-scheduled" "scheduled")
  5745. 'date (if pastschedp d2 date)
  5746. 'ts-date d2
  5747. 'warntime warntime
  5748. 'level level
  5749. 'priority (if habitp
  5750. (org-habit-get-priority habitp)
  5751. (+ 94 (- 5 diff) (org-get-priority txt)))
  5752. 'org-category category
  5753. 'category-position category-pos
  5754. 'org-habit-p habitp
  5755. 'todo-state todo-state)
  5756. (push txt ee))))))
  5757. (nreverse ee)))
  5758. (defun org-agenda-get-blocks ()
  5759. "Return the date-range information for agenda display."
  5760. (let* ((props (list 'face nil
  5761. 'org-not-done-regexp org-not-done-regexp
  5762. 'org-todo-regexp org-todo-regexp
  5763. 'org-complex-heading-regexp org-complex-heading-regexp
  5764. 'mouse-face 'highlight
  5765. 'help-echo
  5766. (format "mouse-2 or RET jump to org file %s"
  5767. (abbreviate-file-name buffer-file-name))))
  5768. (regexp org-tr-regexp)
  5769. (d0 (calendar-absolute-from-gregorian date))
  5770. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5771. level todo-state tags pos head donep inherited-tags)
  5772. (goto-char (point-min))
  5773. (while (re-search-forward regexp nil t)
  5774. (catch :skip
  5775. (org-agenda-skip)
  5776. (setq pos (point))
  5777. (let ((start-time (match-string 1))
  5778. (end-time (match-string 2)))
  5779. (setq s1 (match-string 1)
  5780. s2 (match-string 2)
  5781. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5782. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5783. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5784. ;; Only allow days between the limits, because the normal
  5785. ;; date stamps will catch the limits.
  5786. (save-excursion
  5787. (setq todo-state (org-get-todo-state))
  5788. (setq donep (member todo-state org-done-keywords))
  5789. (if (and donep org-agenda-skip-timestamp-if-done)
  5790. (throw :skip t))
  5791. (setq marker (org-agenda-new-marker (point)))
  5792. (setq category (org-get-category)
  5793. category-pos (get-text-property (point) 'org-category-position))
  5794. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5795. (throw :skip nil)
  5796. (goto-char (match-beginning 0))
  5797. (setq hdmarker (org-agenda-new-marker (point))
  5798. inherited-tags
  5799. (or (eq org-agenda-show-inherited-tags 'always)
  5800. (and (listp org-agenda-show-inherited-tags)
  5801. (memq 'agenda org-agenda-show-inherited-tags))
  5802. (and (eq org-agenda-show-inherited-tags t)
  5803. (or (eq org-agenda-use-tag-inheritance t)
  5804. (memq 'agenda org-agenda-use-tag-inheritance))))
  5805. tags (org-get-tags-at nil (not inherited-tags)))
  5806. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5807. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5808. (setq head (match-string 1))
  5809. (let ((remove-re
  5810. (if org-agenda-remove-timeranges-from-blocks
  5811. (concat
  5812. "<" (regexp-quote s1) ".*?>"
  5813. "--"
  5814. "<" (regexp-quote s2) ".*?>")
  5815. nil)))
  5816. (setq txt (org-agenda-format-item
  5817. (format
  5818. (nth (if (= d1 d2) 0 1)
  5819. org-agenda-timerange-leaders)
  5820. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5821. head level category tags
  5822. (cond ((and (= d1 d0) (= d2 d0))
  5823. (concat "<" start-time ">--<" end-time ">"))
  5824. ((= d1 d0)
  5825. (concat "<" start-time ">"))
  5826. ((= d2 d0)
  5827. (concat "<" end-time ">")))
  5828. remove-re))))
  5829. (org-add-props txt props
  5830. 'org-marker marker 'org-hd-marker hdmarker
  5831. 'type "block" 'date date
  5832. 'level level
  5833. 'todo-state todo-state
  5834. 'priority (org-get-priority txt) 'org-category category
  5835. 'org-category-position category-pos)
  5836. (push txt ee))))
  5837. (goto-char pos)))
  5838. ;; Sort the entries by expiration date.
  5839. (nreverse ee)))
  5840. ;;; Agenda presentation and sorting
  5841. (defvar org-prefix-has-time nil
  5842. "A flag, set by `org-compile-prefix-format'.
  5843. The flag is set if the currently compiled format contains a `%t'.")
  5844. (defvar org-prefix-has-tag nil
  5845. "A flag, set by `org-compile-prefix-format'.
  5846. The flag is set if the currently compiled format contains a `%T'.")
  5847. (defvar org-prefix-has-effort nil
  5848. "A flag, set by `org-compile-prefix-format'.
  5849. The flag is set if the currently compiled format contains a `%e'.")
  5850. (defvar org-prefix-has-breadcrumbs nil
  5851. "A flag, set by `org-compile-prefix-format'.
  5852. The flag is set if the currently compiled format contains a `%b'.")
  5853. (defvar org-prefix-category-length nil
  5854. "Used by `org-compile-prefix-format' to remember the category field width.")
  5855. (defvar org-prefix-category-max-length nil
  5856. "Used by `org-compile-prefix-format' to remember the category field width.")
  5857. (defun org-agenda-get-category-icon (category)
  5858. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5859. (dolist (entry org-agenda-category-icon-alist)
  5860. (when (org-string-match-p (car entry) category)
  5861. (if (listp (cadr entry))
  5862. (return (cadr entry))
  5863. (return (apply 'create-image (cdr entry)))))))
  5864. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5865. remove-re habitp)
  5866. "Format TXT to be inserted into the agenda buffer.
  5867. In particular, add the prefix and corresponding text properties.
  5868. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5869. LEVEL may be a string to replace the `%l' specifier.
  5870. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5871. category taken from local variable or file name. It will replace the `%c'
  5872. specifier in the format.
  5873. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5874. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5875. When DOTIME is a string, this string is searched for a time before TXT is.
  5876. TAGS can be the tags of the headline.
  5877. Any match of REMOVE-RE will be removed from TXT."
  5878. ;; We keep the org-prefix-* variable values along with a compiled
  5879. ;; formatter, so that multiple agendas existing at the same time do
  5880. ;; not step on each other toes.
  5881. ;;
  5882. ;; It was inconvenient to make these variables buffer local in
  5883. ;; Agenda buffers, because this function expects to be called with
  5884. ;; the buffer where item comes from being current, and not agenda
  5885. ;; buffer
  5886. (let* ((bindings (car org-prefix-format-compiled))
  5887. (formatter (cadr org-prefix-format-compiled)))
  5888. (loop for (var value) in bindings
  5889. do (set var value))
  5890. (save-match-data
  5891. ;; Diary entries sometimes have extra whitespace at the beginning
  5892. (setq txt (org-trim txt))
  5893. ;; Fix the tags part in txt
  5894. (setq txt (org-agenda-fix-displayed-tags
  5895. txt tags
  5896. org-agenda-show-inherited-tags
  5897. org-agenda-hide-tags-regexp))
  5898. (let* ((category (or category
  5899. (if (stringp org-category)
  5900. org-category
  5901. (and org-category (symbol-name org-category)))
  5902. (if buffer-file-name
  5903. (file-name-sans-extension
  5904. (file-name-nondirectory buffer-file-name))
  5905. "")))
  5906. (category-icon (org-agenda-get-category-icon category))
  5907. (category-icon (if category-icon
  5908. (propertize " " 'display category-icon)
  5909. ""))
  5910. ;; time, tag, effort are needed for the eval of the prefix format
  5911. (tag (if tags (nth (1- (length tags)) tags) ""))
  5912. time effort neffort
  5913. (ts (if dotime (concat
  5914. (if (stringp dotime) dotime "")
  5915. (and org-agenda-search-headline-for-time txt))))
  5916. (time-of-day (and dotime (org-get-time-of-day ts)))
  5917. stamp plain s0 s1 s2 rtn srp l
  5918. duration thecategory breadcrumbs)
  5919. (and (derived-mode-p 'org-mode) buffer-file-name
  5920. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5921. (when (and dotime time-of-day)
  5922. ;; Extract starting and ending time and move them to prefix
  5923. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5924. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5925. (setq s0 (match-string 0 ts)
  5926. srp (and stamp (match-end 3))
  5927. s1 (match-string (if plain 1 2) ts)
  5928. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5929. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5930. ;; them, we might want to remove them there to avoid duplication.
  5931. ;; The user can turn this off with a variable.
  5932. (if (and org-prefix-has-time
  5933. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5934. (string-match (concat (regexp-quote s0) " *") txt)
  5935. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5936. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5937. (= (match-beginning 0) 0)
  5938. t))
  5939. (setq txt (replace-match "" nil nil txt))))
  5940. ;; Normalize the time(s) to 24 hour
  5941. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5942. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5943. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5944. (let (org-time-clocksum-use-effort-durations)
  5945. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5946. (setq s2
  5947. (org-minutes-to-clocksum-string
  5948. (+ (org-hh:mm-string-to-minutes s1)
  5949. org-agenda-default-appointment-duration)))))
  5950. ;; Compute the duration
  5951. (when s2
  5952. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5953. (org-hh:mm-string-to-minutes s1)))))
  5954. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5955. txt)
  5956. ;; Tags are in the string
  5957. (if (or (eq org-agenda-remove-tags t)
  5958. (and org-agenda-remove-tags
  5959. org-prefix-has-tag))
  5960. (setq txt (replace-match "" t t txt))
  5961. (setq txt (replace-match
  5962. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5963. (match-string 2 txt))
  5964. t t txt))))
  5965. (when (derived-mode-p 'org-mode)
  5966. (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
  5967. (if effort
  5968. (setq neffort (org-duration-string-to-minutes effort)
  5969. effort (setq effort (concat "[" effort "]")))
  5970. ;; prevent erroring out with %e format when there is no effort
  5971. (setq effort "")))
  5972. (when remove-re
  5973. (while (string-match remove-re txt)
  5974. (setq txt (replace-match "" t t txt))))
  5975. ;; Set org-heading property on `txt' to mark the start of the
  5976. ;; heading.
  5977. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5978. ;; Prepare the variables needed in the eval of the compiled format
  5979. (if org-prefix-has-breadcrumbs
  5980. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  5981. (let ((s (org-display-outline-path nil nil "->" t)))
  5982. (if (eq "" s) "" (concat s "->"))))))
  5983. (setq time (cond (s2 (concat
  5984. (org-agenda-time-of-day-to-ampm-maybe s1)
  5985. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5986. (if org-agenda-timegrid-use-ampm " ")))
  5987. (s1 (concat
  5988. (org-agenda-time-of-day-to-ampm-maybe s1)
  5989. (if org-agenda-timegrid-use-ampm
  5990. "........ "
  5991. "......")))
  5992. (t ""))
  5993. extra (or (and (not habitp) extra) "")
  5994. category (if (symbolp category) (symbol-name category) category)
  5995. thecategory (copy-sequence category)
  5996. level (or level ""))
  5997. (if (string-match org-bracket-link-regexp category)
  5998. (progn
  5999. (setq l (if (match-end 3)
  6000. (- (match-end 3) (match-beginning 3))
  6001. (- (match-end 1) (match-beginning 1))))
  6002. (when (< l (or org-prefix-category-length 0))
  6003. (setq category (copy-sequence category))
  6004. (org-add-props category nil
  6005. 'extra-space (make-string
  6006. (- org-prefix-category-length l 1) ?\ ))))
  6007. (if (and org-prefix-category-max-length
  6008. (>= (length category) org-prefix-category-max-length))
  6009. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6010. ;; Evaluate the compiled format
  6011. (setq rtn (concat (eval formatter) txt))
  6012. ;; And finally add the text properties
  6013. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6014. (org-add-props rtn nil
  6015. 'org-category (if thecategory (downcase thecategory) category)
  6016. 'tags (mapcar 'org-downcase-keep-props tags)
  6017. 'org-highest-priority org-highest-priority
  6018. 'org-lowest-priority org-lowest-priority
  6019. 'time-of-day time-of-day
  6020. 'duration duration
  6021. 'effort effort
  6022. 'effort-minutes neffort
  6023. 'breadcrumbs breadcrumbs
  6024. 'txt txt
  6025. 'level level
  6026. 'time time
  6027. 'extra extra
  6028. 'format org-prefix-format-compiled
  6029. 'dotime dotime)))))
  6030. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6031. "Remove tags string from TXT, and add a modified list of tags.
  6032. The modified list may contain inherited tags, and tags matched by
  6033. `org-agenda-hide-tags-regexp' will be removed."
  6034. (when (or add-inherited hide-re)
  6035. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6036. (setq txt (substring txt 0 (match-beginning 0))))
  6037. (setq tags
  6038. (delq nil
  6039. (mapcar (lambda (tg)
  6040. (if (or (and hide-re (string-match hide-re tg))
  6041. (and (not add-inherited)
  6042. (get-text-property 0 'inherited tg)))
  6043. nil
  6044. tg))
  6045. tags)))
  6046. (when tags
  6047. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6048. i)
  6049. (setq txt (concat txt " :"
  6050. (mapconcat
  6051. (lambda (x)
  6052. (setq i (get-text-property 0 'inherited x))
  6053. (if (and have-i (not i))
  6054. (progn
  6055. (setq have-i nil)
  6056. (concat ":" x))
  6057. x))
  6058. tags ":")
  6059. (if have-i "::" ":"))))))
  6060. txt)
  6061. (defun org-downcase-keep-props (s)
  6062. (let ((props (text-properties-at 0 s)))
  6063. (setq s (downcase s))
  6064. (add-text-properties 0 (length s) props s)
  6065. s))
  6066. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6067. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6068. "Add a time-grid for agenda items which need it.
  6069. LIST is the list of agenda items formatted by `org-agenda-list'.
  6070. NDAYS is the span of the current agenda view.
  6071. TODAYP is `t' when the current agenda view is on today."
  6072. (catch 'exit
  6073. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6074. ((and todayp (member 'today (car org-agenda-time-grid))))
  6075. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6076. ((member 'weekly (car org-agenda-time-grid)))
  6077. (t (throw 'exit list)))
  6078. (let* ((have (delq nil (mapcar
  6079. (lambda (x) (get-text-property 1 'time-of-day x))
  6080. list)))
  6081. (string (nth 1 org-agenda-time-grid))
  6082. (gridtimes (nth 2 org-agenda-time-grid))
  6083. (req (car org-agenda-time-grid))
  6084. (remove (member 'remove-match req))
  6085. new time)
  6086. (if (and (member 'require-timed req) (not have))
  6087. ;; don't show empty grid
  6088. (throw 'exit list))
  6089. (while (setq time (pop gridtimes))
  6090. (unless (and remove (member time have))
  6091. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6092. (push (org-agenda-format-item
  6093. nil string nil "" nil
  6094. (concat (substring time 0 -2) ":" (substring time -2)))
  6095. new)
  6096. (put-text-property
  6097. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6098. (when (and todayp org-agenda-show-current-time-in-grid)
  6099. (push (org-agenda-format-item
  6100. nil org-agenda-current-time-string nil "" nil
  6101. (format-time-string "%H:%M "))
  6102. new)
  6103. (put-text-property
  6104. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6105. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6106. (append new list)
  6107. (append list new)))))
  6108. (defun org-compile-prefix-format (key)
  6109. "Compile the prefix format into a Lisp form that can be evaluated.
  6110. The resulting form and associated variable bindings is returned
  6111. and stored in the variable `org-prefix-format-compiled'."
  6112. (setq org-prefix-has-time nil
  6113. org-prefix-has-tag nil
  6114. org-prefix-category-length nil
  6115. org-prefix-has-effort nil
  6116. org-prefix-has-breadcrumbs nil)
  6117. (let ((s (cond
  6118. ((stringp org-agenda-prefix-format)
  6119. org-agenda-prefix-format)
  6120. ((assq key org-agenda-prefix-format)
  6121. (cdr (assq key org-agenda-prefix-format)))
  6122. (t " %-12:c%?-12t% s")))
  6123. (start 0)
  6124. varform vars var e c f opt)
  6125. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6126. s start)
  6127. (setq var (or (cdr (assoc (match-string 4 s)
  6128. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6129. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6130. 'eval)
  6131. c (or (match-string 3 s) "")
  6132. opt (match-beginning 1)
  6133. start (1+ (match-beginning 0)))
  6134. (if (equal var 'time) (setq org-prefix-has-time t))
  6135. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6136. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6137. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6138. (setq f (concat "%" (match-string 2 s) "s"))
  6139. (when (equal var 'category)
  6140. (setq org-prefix-category-length
  6141. (floor (abs (string-to-number (match-string 2 s)))))
  6142. (setq org-prefix-category-max-length
  6143. (let ((x (match-string 2 s)))
  6144. (save-match-data
  6145. (if (string-match "\\.[0-9]+" x)
  6146. (string-to-number (substring (match-string 0 x) 1)))))))
  6147. (if (eq var 'eval)
  6148. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6149. (if opt
  6150. (setq varform
  6151. `(if (equal "" ,var)
  6152. ""
  6153. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6154. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6155. (setq s (replace-match "%s" t nil s))
  6156. (push varform vars))
  6157. (setq vars (nreverse vars))
  6158. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6159. (setq org-prefix-format-compiled
  6160. (list
  6161. `((org-prefix-has-time ,org-prefix-has-time)
  6162. (org-prefix-has-tag ,org-prefix-has-tag)
  6163. (org-prefix-category-length ,org-prefix-category-length)
  6164. (org-prefix-has-effort ,org-prefix-has-effort)
  6165. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6166. `(format ,s ,@vars))))))
  6167. (defun org-set-sorting-strategy (key)
  6168. (if (symbolp (car org-agenda-sorting-strategy))
  6169. ;; the old format
  6170. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6171. (setq org-agenda-sorting-strategy-selected
  6172. (or (cdr (assq key org-agenda-sorting-strategy))
  6173. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6174. '(time-up category-keep priority-down)))))
  6175. (defun org-get-time-of-day (s &optional string mod24)
  6176. "Check string S for a time of day.
  6177. If found, return it as a military time number between 0 and 2400.
  6178. If not found, return nil.
  6179. The optional STRING argument forces conversion into a 5 character wide string
  6180. HH:MM."
  6181. (save-match-data
  6182. (when
  6183. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6184. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6185. (let* ((h (string-to-number (match-string 1 s)))
  6186. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6187. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6188. (am-p (equal ampm "am"))
  6189. (h1 (cond ((not ampm) h)
  6190. ((= h 12) (if am-p 0 12))
  6191. (t (+ h (if am-p 0 12)))))
  6192. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6193. (mod h1 24) h1))
  6194. (t0 (+ (* 100 h2) m))
  6195. (t1 (concat (if (>= h1 24) "+" " ")
  6196. (if (and org-agenda-time-leading-zero
  6197. (< t0 1000)) "0" "")
  6198. (if (< t0 100) "0" "")
  6199. (if (< t0 10) "0" "")
  6200. (int-to-string t0))))
  6201. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6202. (defvar org-agenda-before-sorting-filter-function nil
  6203. "Function to be applied to agenda items prior to sorting.
  6204. Prior to sorting also means just before they are inserted into the agenda.
  6205. To aid sorting, you may revisit the original entries and add more text
  6206. properties which will later be used by the sorting functions.
  6207. The function should take a string argument, an agenda line.
  6208. It has access to the text properties in that line, which contain among
  6209. other things, the property `org-hd-marker' that points to the entry
  6210. where the line comes from. Note that not all lines going into the agenda
  6211. have this property, only most.
  6212. The function should return the modified string. It is probably best
  6213. to ONLY change text properties.
  6214. You can also use this function as a filter, by returning nil for lines
  6215. you don't want to have in the agenda at all. For this application, you
  6216. could bind the variable in the options section of a custom command.")
  6217. (defun org-agenda-finalize-entries (list &optional type)
  6218. "Sort, limit and concatenate the LIST of agenda items.
  6219. The optional argument TYPE tells the agenda type."
  6220. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6221. (cdr (assoc type org-agenda-max-effort)))
  6222. (t org-agenda-max-effort)))
  6223. (max-todo (cond ((listp org-agenda-max-todos)
  6224. (cdr (assoc type org-agenda-max-todos)))
  6225. (t org-agenda-max-todos)))
  6226. (max-tags (cond ((listp org-agenda-max-tags)
  6227. (cdr (assoc type org-agenda-max-tags)))
  6228. (t org-agenda-max-tags)))
  6229. (max-entries (cond ((listp org-agenda-max-entries)
  6230. (cdr (assoc type org-agenda-max-entries)))
  6231. (t org-agenda-max-entries))) l)
  6232. (when org-agenda-before-sorting-filter-function
  6233. (setq list
  6234. (delq nil
  6235. (mapcar
  6236. org-agenda-before-sorting-filter-function list))))
  6237. (setq list (mapcar 'org-agenda-highlight-todo list)
  6238. list (mapcar 'identity (sort list 'org-entries-lessp))
  6239. list (org-agenda-limit-entries
  6240. list 'effort-minutes max-effort 'identity)
  6241. list (org-agenda-limit-entries list 'todo-state max-todo)
  6242. list (org-agenda-limit-entries list 'tags max-tags)
  6243. list (org-agenda-limit-entries list 'org-hd-marker max-entries)
  6244. list (mapconcat 'identity list "\n"))))
  6245. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6246. "Limit the number of agenda entries."
  6247. (if limit
  6248. (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
  6249. (delq nil
  6250. (mapcar
  6251. (lambda (e)
  6252. (let ((pval (funcall f (get-text-property 1 prop e))))
  6253. (if pval (setq lim (+ lim pval)))
  6254. (if (or (not pval) (<= lim limit)) e)))
  6255. list)))
  6256. list))
  6257. (defun org-agenda-highlight-todo (x)
  6258. (let ((org-done-keywords org-done-keywords-for-agenda)
  6259. (case-fold-search nil)
  6260. re)
  6261. (if (eq x 'line)
  6262. (save-excursion
  6263. (beginning-of-line 1)
  6264. (setq re (org-get-at-bol 'org-todo-regexp))
  6265. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6266. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6267. (add-text-properties (match-beginning 0) (match-end 1)
  6268. (list 'face (org-get-todo-face 1)))
  6269. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6270. (delete-region (match-beginning 1) (1- (match-end 0)))
  6271. (goto-char (match-beginning 1))
  6272. (insert (format org-agenda-todo-keyword-format s)))))
  6273. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6274. (setq re (get-text-property 0 'org-todo-regexp x))
  6275. (when (and re
  6276. ;; Test `pl' because if there's no heading content,
  6277. ;; there's no point matching to highlight. Note
  6278. ;; that if we didn't test `pl' first, and there
  6279. ;; happened to be no keyword from `org-todo-regexp'
  6280. ;; on this heading line, then the `equal' comparison
  6281. ;; afterwards would spuriously succeed in the case
  6282. ;; where `pl' is nil -- causing an args-out-of-range
  6283. ;; error when we try to add text properties to text
  6284. ;; that isn't there.
  6285. pl
  6286. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6287. x pl) pl))
  6288. (add-text-properties
  6289. (or (match-end 1) (match-end 0)) (match-end 0)
  6290. (list 'face (org-get-todo-face (match-string 2 x)))
  6291. x)
  6292. (when (match-end 1)
  6293. (setq x (concat (substring x 0 (match-end 1))
  6294. (format org-agenda-todo-keyword-format
  6295. (match-string 2 x))
  6296. (org-add-props " " (text-properties-at 0 x))
  6297. (substring x (match-end 3)))))))
  6298. x)))
  6299. (defsubst org-cmp-priority (a b)
  6300. "Compare the priorities of string A and B."
  6301. (let ((pa (or (get-text-property 1 'priority a) 0))
  6302. (pb (or (get-text-property 1 'priority b) 0)))
  6303. (cond ((> pa pb) +1)
  6304. ((< pa pb) -1))))
  6305. (defsubst org-cmp-effort (a b)
  6306. "Compare the effort values of string A and B."
  6307. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6308. (ea (or (get-text-property 1 'effort-minutes a) def))
  6309. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6310. (cond ((> ea eb) +1)
  6311. ((< ea eb) -1))))
  6312. (defsubst org-cmp-category (a b)
  6313. "Compare the string values of categories of strings A and B."
  6314. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6315. (cb (or (get-text-property 1 'org-category b) "")))
  6316. (cond ((string-lessp ca cb) -1)
  6317. ((string-lessp cb ca) +1))))
  6318. (defsubst org-cmp-todo-state (a b)
  6319. "Compare the todo states of strings A and B."
  6320. (let* ((ma (or (get-text-property 1 'org-marker a)
  6321. (get-text-property 1 'org-hd-marker a)))
  6322. (mb (or (get-text-property 1 'org-marker b)
  6323. (get-text-property 1 'org-hd-marker b)))
  6324. (fa (and ma (marker-buffer ma)))
  6325. (fb (and mb (marker-buffer mb)))
  6326. (todo-kwds
  6327. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6328. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6329. (ta (or (get-text-property 1 'todo-state a) ""))
  6330. (tb (or (get-text-property 1 'todo-state b) ""))
  6331. (la (- (length (member ta todo-kwds))))
  6332. (lb (- (length (member tb todo-kwds))))
  6333. (donepa (member ta org-done-keywords-for-agenda))
  6334. (donepb (member tb org-done-keywords-for-agenda)))
  6335. (cond ((and donepa (not donepb)) -1)
  6336. ((and (not donepa) donepb) +1)
  6337. ((< la lb) -1)
  6338. ((< lb la) +1))))
  6339. (defsubst org-cmp-alpha (a b)
  6340. "Compare the headlines, alphabetically."
  6341. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6342. (plb (text-property-any 0 (length b) 'org-heading t b))
  6343. (ta (and pla (substring a pla)))
  6344. (tb (and plb (substring b plb))))
  6345. (when pla
  6346. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6347. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6348. (setq ta (substring ta (match-end 0))))
  6349. (setq ta (downcase ta)))
  6350. (when plb
  6351. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6352. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6353. (setq tb (substring tb (match-end 0))))
  6354. (setq tb (downcase tb)))
  6355. (cond ((not ta) +1)
  6356. ((not tb) -1)
  6357. ((string-lessp ta tb) -1)
  6358. ((string-lessp tb ta) +1))))
  6359. (defsubst org-cmp-tag (a b)
  6360. "Compare the string values of the first tags of A and B."
  6361. (let ((ta (car (last (get-text-property 1 'tags a))))
  6362. (tb (car (last (get-text-property 1 'tags b)))))
  6363. (cond ((not ta) +1)
  6364. ((not tb) -1)
  6365. ((string-lessp ta tb) -1)
  6366. ((string-lessp tb ta) +1))))
  6367. (defsubst org-cmp-time (a b)
  6368. "Compare the time-of-day values of strings A and B."
  6369. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6370. (ta (or (get-text-property 1 'time-of-day a) def))
  6371. (tb (or (get-text-property 1 'time-of-day b) def)))
  6372. (cond ((< ta tb) -1)
  6373. ((< tb ta) +1))))
  6374. (defsubst org-cmp-ts (a b &optional type)
  6375. "Compare the timestamps values of entries A and B.
  6376. When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
  6377. or \"timestamp_ia\", compare within each of these type.
  6378. When TYPE is the empty string, compare all timestamps
  6379. without respect of their type."
  6380. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6381. (ta (or (and (string-match type (get-text-property 1 'type a))
  6382. (get-text-property 1 'ts-date a)) def))
  6383. (tb (or (and (string-match type (get-text-property 1 'type b))
  6384. (get-text-property 1 'ts-date b)) def)))
  6385. (cond ((< ta tb) -1)
  6386. ((< tb ta) +1))))
  6387. (defsubst org-cmp-habit-p (a b)
  6388. "Compare the todo states of strings A and B."
  6389. (let ((ha (get-text-property 1 'org-habit-p a))
  6390. (hb (get-text-property 1 'org-habit-p b)))
  6391. (cond ((and ha (not hb)) -1)
  6392. ((and (not ha) hb) +1))))
  6393. (defun org-entries-lessp (a b)
  6394. "Predicate for sorting agenda entries."
  6395. ;; The following variables will be used when the form is evaluated.
  6396. ;; So even though the compiler complains, keep them.
  6397. (let* ((ss org-agenda-sorting-strategy-selected)
  6398. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6399. (org-cmp-ts a b "")))
  6400. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6401. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6402. (org-cmp-ts a b "scheduled")))
  6403. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6404. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6405. (org-cmp-ts a b "deadline")))
  6406. (deadline-down (if deadline-up (- deadline-up) nil))
  6407. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6408. (org-cmp-ts a b "iatimestamp_ia")))
  6409. (tsia-down (if tsia-up (- tsia-up) nil))
  6410. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6411. (org-cmp-ts a b "timestamp")))
  6412. (ts-down (if ts-up (- ts-up) nil))
  6413. (time-up (and (org-em 'time-up 'time-down ss)
  6414. (org-cmp-time a b)))
  6415. (time-down (if time-up (- time-up) nil))
  6416. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6417. (org-cmp-priority a b)))
  6418. (priority-down (if priority-up (- priority-up) nil))
  6419. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6420. (org-cmp-effort a b)))
  6421. (effort-down (if effort-up (- effort-up) nil))
  6422. (category-up (and (or (org-em 'category-up 'category-down ss)
  6423. (memq 'category-keep ss))
  6424. (org-cmp-category a b)))
  6425. (category-down (if category-up (- category-up) nil))
  6426. (category-keep (if category-up +1 nil))
  6427. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6428. (org-cmp-tag a b)))
  6429. (tag-down (if tag-up (- tag-up) nil))
  6430. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6431. (org-cmp-todo-state a b)))
  6432. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6433. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6434. (org-cmp-habit-p a b)))
  6435. (habit-down (if habit-up (- habit-up) nil))
  6436. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6437. (org-cmp-alpha a b)))
  6438. (alpha-down (if alpha-up (- alpha-up) nil))
  6439. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6440. user-defined-up user-defined-down)
  6441. (if (and need-user-cmp org-agenda-cmp-user-defined
  6442. (functionp org-agenda-cmp-user-defined))
  6443. (setq user-defined-up
  6444. (funcall org-agenda-cmp-user-defined a b)
  6445. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6446. (cdr (assoc
  6447. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6448. '((-1 . t) (1 . nil) (nil . nil))))))
  6449. ;;; Agenda restriction lock
  6450. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6451. "Overlay to mark the headline to which agenda commands are restricted.")
  6452. (overlay-put org-agenda-restriction-lock-overlay
  6453. 'face 'org-agenda-restriction-lock)
  6454. (overlay-put org-agenda-restriction-lock-overlay
  6455. 'help-echo "Agendas are currently limited to this subtree.")
  6456. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6457. (defun org-agenda-set-restriction-lock (&optional type)
  6458. "Set restriction lock for agenda, to current subtree or file.
  6459. Restriction will be the file if TYPE is `file', or if type is the
  6460. universal prefix '(4), or if the cursor is before the first headline
  6461. in the file. Otherwise, restriction will be to the current subtree."
  6462. (interactive "P")
  6463. (and (equal type '(4)) (setq type 'file))
  6464. (setq type (cond
  6465. (type type)
  6466. ((org-at-heading-p) 'subtree)
  6467. ((condition-case nil (org-back-to-heading t) (error nil))
  6468. 'subtree)
  6469. (t 'file)))
  6470. (if (eq type 'subtree)
  6471. (progn
  6472. (setq org-agenda-restrict t)
  6473. (setq org-agenda-overriding-restriction 'subtree)
  6474. (put 'org-agenda-files 'org-restrict
  6475. (list (buffer-file-name (buffer-base-buffer))))
  6476. (org-back-to-heading t)
  6477. (move-overlay org-agenda-restriction-lock-overlay
  6478. (point) (save-excursion (org-end-of-subtree t t) (point)))
  6479. (move-marker org-agenda-restrict-begin (point))
  6480. (move-marker org-agenda-restrict-end
  6481. (save-excursion (org-end-of-subtree t t)))
  6482. (message "Locking agenda restriction to subtree"))
  6483. (put 'org-agenda-files 'org-restrict
  6484. (list (buffer-file-name (buffer-base-buffer))))
  6485. (setq org-agenda-restrict nil)
  6486. (setq org-agenda-overriding-restriction 'file)
  6487. (move-marker org-agenda-restrict-begin nil)
  6488. (move-marker org-agenda-restrict-end nil)
  6489. (message "Locking agenda restriction to file"))
  6490. (setq current-prefix-arg nil)
  6491. (org-agenda-maybe-redo))
  6492. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6493. "Remove the agenda restriction lock."
  6494. (interactive "P")
  6495. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6496. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6497. (setq org-agenda-overriding-restriction nil)
  6498. (setq org-agenda-restrict nil)
  6499. (put 'org-agenda-files 'org-restrict nil)
  6500. (move-marker org-agenda-restrict-begin nil)
  6501. (move-marker org-agenda-restrict-end nil)
  6502. (setq current-prefix-arg nil)
  6503. (message "Agenda restriction lock removed")
  6504. (or noupdate (org-agenda-maybe-redo)))
  6505. (defun org-agenda-maybe-redo ()
  6506. "If there is any window showing the agenda view, update it."
  6507. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6508. (w0 (selected-window)))
  6509. (when w
  6510. (select-window w)
  6511. (org-agenda-redo)
  6512. (select-window w0)
  6513. (if org-agenda-overriding-restriction
  6514. (message "Agenda view shifted to new %s restriction"
  6515. org-agenda-overriding-restriction)
  6516. (message "Agenda restriction lock removed")))))
  6517. ;;; Agenda commands
  6518. (defun org-agenda-check-type (error &rest types)
  6519. "Check if agenda buffer is of allowed type.
  6520. If ERROR is non-nil, throw an error, otherwise just return nil.
  6521. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6522. (if (not org-agenda-type)
  6523. (error "No Org agenda currently displayed")
  6524. (if (memq org-agenda-type types)
  6525. t
  6526. (if error
  6527. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6528. nil))))
  6529. (defun org-agenda-Quit ()
  6530. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6531. Also restore the window configuration."
  6532. (interactive)
  6533. (if org-agenda-columns-active
  6534. (org-columns-quit)
  6535. (let ((buf (current-buffer)))
  6536. (if (eq org-agenda-window-setup 'other-frame)
  6537. (progn
  6538. (org-agenda-reset-markers)
  6539. (kill-buffer buf)
  6540. (org-columns-remove-overlays)
  6541. (setq org-agenda-archives-mode nil)
  6542. (delete-frame))
  6543. (and (not (eq org-agenda-window-setup 'current-window))
  6544. (not (one-window-p))
  6545. (delete-window))
  6546. (org-agenda-reset-markers)
  6547. (kill-buffer buf)
  6548. (org-columns-remove-overlays)
  6549. (setq org-agenda-archives-mode nil)))
  6550. ;; Maybe restore the pre-agenda window configuration.
  6551. (and org-agenda-restore-windows-after-quit
  6552. (not (eq org-agenda-window-setup 'other-frame))
  6553. org-agenda-pre-window-conf
  6554. (set-window-configuration org-agenda-pre-window-conf)
  6555. (setq org-agenda-pre-window-conf nil))))
  6556. (defun org-agenda-quit ()
  6557. "Exit the agenda and restore the window configuration.
  6558. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6559. (interactive)
  6560. (if (and (eq org-indirect-buffer-display 'other-window)
  6561. org-last-indirect-buffer)
  6562. (let ((org-last-indirect-window
  6563. (get-buffer-window org-last-indirect-buffer)))
  6564. (if org-last-indirect-window
  6565. (delete-window org-last-indirect-window))))
  6566. (if org-agenda-columns-active
  6567. (org-columns-quit)
  6568. (if org-agenda-sticky
  6569. (let ((buf (current-buffer)))
  6570. (if (eq org-agenda-window-setup 'other-frame)
  6571. (progn
  6572. (delete-frame))
  6573. (and (not (eq org-agenda-window-setup 'current-window))
  6574. (not (one-window-p))
  6575. (delete-window)))
  6576. (with-current-buffer buf
  6577. (bury-buffer)
  6578. ;; Maybe restore the pre-agenda window configuration.
  6579. (and org-agenda-restore-windows-after-quit
  6580. (not (eq org-agenda-window-setup 'other-frame))
  6581. org-agenda-pre-window-conf
  6582. (set-window-configuration org-agenda-pre-window-conf)
  6583. (setq org-agenda-pre-window-conf nil))))
  6584. (org-agenda-Quit))))
  6585. (defun org-agenda-exit ()
  6586. "Exit the agenda and restore the window configuration.
  6587. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6588. buffers visited directly by the user will not be touched."
  6589. (interactive)
  6590. (org-release-buffers org-agenda-new-buffers)
  6591. (setq org-agenda-new-buffers nil)
  6592. (org-agenda-Quit))
  6593. (defun org-agenda-kill-all-agenda-buffers ()
  6594. "Kill all buffers in `org-agenda-mode'.
  6595. This is used when toggling sticky agendas.
  6596. You can also explicitly invoke it with `C-c a C-k'."
  6597. (interactive)
  6598. (let (blist)
  6599. (dolist (buf (buffer-list))
  6600. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6601. (push buf blist)))
  6602. (mapc 'kill-buffer blist)))
  6603. (defun org-agenda-execute (arg)
  6604. "Execute another agenda command, keeping same window.
  6605. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6606. in the agenda."
  6607. (interactive "P")
  6608. (let ((org-agenda-window-setup 'current-window))
  6609. (org-agenda arg)))
  6610. (defun org-agenda-redo (&optional all)
  6611. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6612. (interactive "P")
  6613. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6614. (cpa (unless (eq all t) current-prefix-arg))
  6615. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6616. (org-agenda-sticky nil)
  6617. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6618. org-agenda-buffer-name))
  6619. (org-agenda-keep-modes t)
  6620. (tag-filter org-agenda-tag-filter)
  6621. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6622. (top-cat-filter org-agenda-top-category-filter)
  6623. (cat-filter org-agenda-category-filter)
  6624. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6625. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6626. (cols org-agenda-columns-active)
  6627. (line (org-current-line))
  6628. (window-line (- line (org-current-line (window-start))))
  6629. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6630. (redo-cmd (get-text-property p 'org-redo-cmd))
  6631. (last-args (get-text-property p 'org-last-args))
  6632. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6633. (org-agenda-overriding-cmd-arguments
  6634. (unless (eq all t)
  6635. (cond ((listp last-args)
  6636. (cons (or cpa (car last-args)) (cdr last-args)))
  6637. ((stringp last-args)
  6638. last-args))))
  6639. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6640. (put 'org-agenda-tag-filter :preset-filter nil)
  6641. (put 'org-agenda-category-filter :preset-filter nil)
  6642. (and cols (org-columns-quit))
  6643. (message "Rebuilding agenda buffer...")
  6644. (if series-redo-cmd
  6645. (eval series-redo-cmd)
  6646. (org-let lprops '(eval redo-cmd)))
  6647. (setq org-agenda-undo-list nil
  6648. org-agenda-pending-undo-list nil)
  6649. (message "Rebuilding agenda buffer...done")
  6650. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6651. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6652. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6653. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6654. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6655. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6656. (org-goto-line line)
  6657. (recenter window-line)))
  6658. (defvar org-global-tags-completion-table nil)
  6659. (defvar org-agenda-filter-form nil)
  6660. (defvar org-agenda-filtered-by-category nil)
  6661. (defun org-agenda-filter-by-category (strip)
  6662. "Keep only those lines in the agenda buffer that have a specific category.
  6663. The category is that of the current line."
  6664. (interactive "P")
  6665. (if (and org-agenda-filtered-by-category
  6666. org-agenda-category-filter)
  6667. (org-agenda-filter-show-all-cat)
  6668. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6669. (if cat (org-agenda-filter-apply
  6670. (list (concat (if strip "-" "+") cat)) 'category)
  6671. (error "No category at point")))))
  6672. (defun org-find-top-category (&optional pos)
  6673. (save-excursion
  6674. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6675. (if pos (goto-char pos))
  6676. ;; Skip up to the topmost parent
  6677. (while (ignore-errors (outline-up-heading 1) t))
  6678. (ignore-errors
  6679. (nth 4 (org-heading-components))))))
  6680. (defvar org-agenda-filtered-by-top-category nil)
  6681. (defun org-agenda-filter-by-top-category (strip)
  6682. "Keep only those lines in the agenda buffer that have a specific category.
  6683. The category is that of the current line."
  6684. (interactive "P")
  6685. (if org-agenda-filtered-by-top-category
  6686. (progn
  6687. (setq org-agenda-filtered-by-top-category nil
  6688. org-agenda-top-category-filter nil)
  6689. (org-agenda-filter-show-all-cat))
  6690. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6691. (if cat (org-agenda-filter-top-category-apply cat strip)
  6692. (error "No top-level category at point")))))
  6693. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6694. "Keep only those lines in the agenda buffer that have a specific tag.
  6695. The tag is selected with its fast selection letter, as configured.
  6696. With prefix argument STRIP, remove all lines that do have the tag.
  6697. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6698. used to narrow the search - the interactive user can also press `-' or `+'
  6699. to switch to narrowing."
  6700. (interactive "P")
  6701. (let* ((alist org-tag-alist-for-agenda)
  6702. (tag-chars (mapconcat
  6703. (lambda (x) (if (and (not (symbolp (car x)))
  6704. (cdr x))
  6705. (char-to-string (cdr x))
  6706. ""))
  6707. alist ""))
  6708. (efforts (org-split-string
  6709. (or (cdr (assoc (concat org-effort-property "_ALL")
  6710. org-global-properties))
  6711. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6712. "")))
  6713. (effort-op org-agenda-filter-effort-default-operator)
  6714. (effort-prompt "")
  6715. (inhibit-read-only t)
  6716. (current org-agenda-tag-filter)
  6717. maybe-refresh a n tag)
  6718. (unless char
  6719. (message
  6720. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6721. (if narrow "Narrow" "Filter") tag-chars
  6722. (if org-agenda-auto-exclude-function "[RET], " ""))
  6723. (setq char (read-char-exclusive)))
  6724. (when (member char '(?+ ?-))
  6725. ;; Narrowing down
  6726. (cond ((equal char ?-) (setq strip t narrow t))
  6727. ((equal char ?+) (setq strip nil narrow t)))
  6728. (message
  6729. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6730. (setq char (read-char-exclusive)))
  6731. (when (member char '(?< ?> ?= ??))
  6732. ;; An effort operator
  6733. (setq effort-op (char-to-string char))
  6734. (setq alist nil) ; to make sure it will be interpreted as effort.
  6735. (unless (equal char ??)
  6736. (loop for i from 0 to 9 do
  6737. (setq effort-prompt
  6738. (concat
  6739. effort-prompt " ["
  6740. (if (= i 9) "0" (int-to-string (1+ i)))
  6741. "]" (nth i efforts))))
  6742. (message "Effort%s: %s " effort-op effort-prompt)
  6743. (setq char (read-char-exclusive))
  6744. (when (or (< char ?0) (> char ?9))
  6745. (error "Need 1-9,0 to select effort"))))
  6746. (when (equal char ?\t)
  6747. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6748. (org-set-local 'org-global-tags-completion-table
  6749. (org-global-tags-completion-table)))
  6750. (let ((completion-ignore-case t))
  6751. (setq tag (org-icompleting-read
  6752. "Tag: " org-global-tags-completion-table))))
  6753. (cond
  6754. ((equal char ?\r)
  6755. (org-agenda-filter-show-all-tag)
  6756. (when org-agenda-auto-exclude-function
  6757. (setq org-agenda-tag-filter '())
  6758. (dolist (tag (org-agenda-get-represented-tags))
  6759. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6760. (if modifier
  6761. (push modifier org-agenda-tag-filter))))
  6762. (if (not (null org-agenda-tag-filter))
  6763. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6764. (setq maybe-refresh t))
  6765. ((equal char ?/)
  6766. (org-agenda-filter-show-all-tag)
  6767. (when (get 'org-agenda-tag-filter :preset-filter)
  6768. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6769. (setq maybe-refresh t))
  6770. ((equal char ?. )
  6771. (setq org-agenda-tag-filter
  6772. (mapcar (lambda(tag) (concat "+" tag))
  6773. (org-get-at-bol 'tags)))
  6774. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6775. (setq maybe-refresh t))
  6776. ((or (equal char ?\ )
  6777. (setq a (rassoc char alist))
  6778. (and (>= char ?0) (<= char ?9)
  6779. (setq n (if (= char ?0) 9 (- char ?0 1))
  6780. tag (concat effort-op (nth n efforts))
  6781. a (cons tag nil)))
  6782. (and (= char ??)
  6783. (setq tag "?eff")
  6784. a (cons tag nil))
  6785. (and tag (setq a (cons tag nil))))
  6786. (org-agenda-filter-show-all-tag)
  6787. (setq tag (car a))
  6788. (setq org-agenda-tag-filter
  6789. (cons (concat (if strip "-" "+") tag)
  6790. (if narrow current nil)))
  6791. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6792. (setq maybe-refresh t))
  6793. (t (error "Invalid tag selection character %c" char)))
  6794. (when (and maybe-refresh
  6795. (eq org-agenda-clockreport-mode 'with-filter))
  6796. (org-agenda-redo))))
  6797. (defun org-agenda-get-represented-tags ()
  6798. "Get a list of all tags currently represented in the agenda."
  6799. (let (p tags)
  6800. (save-excursion
  6801. (goto-char (point-min))
  6802. (while (setq p (next-single-property-change (point) 'tags))
  6803. (goto-char p)
  6804. (mapc (lambda (x) (add-to-list 'tags x))
  6805. (get-text-property (point) 'tags))))
  6806. tags))
  6807. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6808. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6809. (interactive "P")
  6810. (org-agenda-filter-by-tag strip char 'refine))
  6811. (defun org-agenda-filter-make-matcher ()
  6812. "Create the form that tests a line for agenda filter."
  6813. (let (f f1)
  6814. ;; first compute the tag-filter matcher
  6815. (dolist (x (delete-dups
  6816. (append (get 'org-agenda-tag-filter
  6817. :preset-filter) org-agenda-tag-filter)))
  6818. (if (member x '("-" "+"))
  6819. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6820. (if (string-match "[<=>?]" x)
  6821. (setq f1 (org-agenda-filter-effort-form x))
  6822. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6823. (if (equal (string-to-char x) ?-)
  6824. (setq f1 (list 'not f1))))
  6825. (push f1 f))
  6826. ;; then compute the category-filter matcher
  6827. (dolist (x (delete-dups
  6828. (append (get 'org-agenda-category-filter
  6829. :preset-filter) org-agenda-category-filter)))
  6830. (if (equal "-" (substring x 0 1))
  6831. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6832. (setq f1 (list 'equal (substring x 1) 'cat)))
  6833. (push f1 f))
  6834. (cons 'and (nreverse f))))
  6835. (defun org-agenda-filter-effort-form (e)
  6836. "Return the form to compare the effort of the current line with what E says.
  6837. E looks like \"+<2:25\"."
  6838. (let (op)
  6839. (setq e (substring e 1))
  6840. (setq op (string-to-char e) e (substring e 1))
  6841. (setq op (cond ((equal op ?<) '<=)
  6842. ((equal op ?>) '>=)
  6843. ((equal op ??) op)
  6844. (t '=)))
  6845. (list 'org-agenda-compare-effort (list 'quote op)
  6846. (org-duration-string-to-minutes e))))
  6847. (defun org-agenda-compare-effort (op value)
  6848. "Compare the effort of the current line with VALUE, using OP.
  6849. If the line does not have an effort defined, return nil."
  6850. (let ((eff (org-get-at-bol 'effort-minutes)))
  6851. (if (equal op ??)
  6852. (not eff)
  6853. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6854. value))))
  6855. (defun org-agenda-filter-apply (filter type)
  6856. "Set FILTER as the new agenda filter and apply it."
  6857. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  6858. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  6859. (let (tags cat)
  6860. (if (eq type 'tag)
  6861. (setq org-agenda-tag-filter filter)
  6862. (setq org-agenda-category-filter filter))
  6863. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6864. (if (and (eq type 'category)
  6865. (not (equal (substring (car filter) 0 1) "-")))
  6866. ;; Only set `org-agenda-filtered-by-category' to t
  6867. ;; when a unique category is used as the filter
  6868. (setq org-agenda-filtered-by-category t))
  6869. (org-agenda-set-mode-name)
  6870. (save-excursion
  6871. (goto-char (point-min))
  6872. (while (not (eobp))
  6873. (if (org-get-at-bol 'org-marker)
  6874. (progn
  6875. (setq tags (org-get-at-bol 'tags) ; used in eval
  6876. cat (get-text-property (point) 'org-category))
  6877. (if (not (eval org-agenda-filter-form))
  6878. (org-agenda-filter-hide-line type))
  6879. (beginning-of-line 2))
  6880. (beginning-of-line 2))))
  6881. (if (get-char-property (point) 'invisible)
  6882. (ignore-errors (org-agenda-previous-line)))))
  6883. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6884. "Set FILTER as the new agenda filter and apply it."
  6885. (org-agenda-set-mode-name)
  6886. (save-excursion
  6887. (goto-char (point-min))
  6888. (while (not (eobp))
  6889. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6890. (topcat (and pos (org-find-top-category pos))))
  6891. (if (and topcat (funcall (if negative 'identity 'not)
  6892. (string= category topcat)))
  6893. (org-agenda-filter-hide-line 'category)))
  6894. (beginning-of-line 2)))
  6895. (if (get-char-property (point) 'invisible)
  6896. (org-agenda-previous-line))
  6897. (setq org-agenda-top-category-filter category
  6898. org-agenda-filtered-by-top-category t))
  6899. (defun org-agenda-filter-hide-line (type)
  6900. (let (ov)
  6901. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6902. (point-at-eol)))
  6903. (overlay-put ov 'invisible t)
  6904. (overlay-put ov 'type type)
  6905. (if (eq type 'tag)
  6906. (push ov org-agenda-tag-filter-overlays)
  6907. (push ov org-agenda-cat-filter-overlays))))
  6908. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6909. (setq pos (or pos (point)))
  6910. (save-excursion
  6911. (dolist (ov (overlays-at pos))
  6912. (when (and (overlay-get ov 'invisible)
  6913. (eq (overlay-get ov 'type) 'tag))
  6914. (goto-char pos)
  6915. (if (< (overlay-start ov) (point-at-eol))
  6916. (move-overlay ov (point-at-eol)
  6917. (overlay-end ov)))))))
  6918. (defun org-agenda-filter-show-all-tag nil
  6919. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6920. (setq org-agenda-tag-filter-overlays nil
  6921. org-agenda-tag-filter nil
  6922. org-agenda-filter-form nil)
  6923. (org-agenda-set-mode-name))
  6924. (defun org-agenda-filter-show-all-cat nil
  6925. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6926. (setq org-agenda-cat-filter-overlays nil
  6927. org-agenda-filtered-by-category nil
  6928. org-agenda-category-filter nil
  6929. org-agenda-filter-form nil)
  6930. (org-agenda-set-mode-name))
  6931. (defun org-agenda-manipulate-query-add ()
  6932. "Manipulate the query by adding a search term with positive selection.
  6933. Positive selection means the term must be matched for selection of an entry."
  6934. (interactive)
  6935. (org-agenda-manipulate-query ?\[))
  6936. (defun org-agenda-manipulate-query-subtract ()
  6937. "Manipulate the query by adding a search term with negative selection.
  6938. Negative selection means term must not be matched for selection of an entry."
  6939. (interactive)
  6940. (org-agenda-manipulate-query ?\]))
  6941. (defun org-agenda-manipulate-query-add-re ()
  6942. "Manipulate the query by adding a search regexp with positive selection.
  6943. Positive selection means the regexp must match for selection of an entry."
  6944. (interactive)
  6945. (org-agenda-manipulate-query ?\{))
  6946. (defun org-agenda-manipulate-query-subtract-re ()
  6947. "Manipulate the query by adding a search regexp with negative selection.
  6948. Negative selection means regexp must not match for selection of an entry."
  6949. (interactive)
  6950. (org-agenda-manipulate-query ?\}))
  6951. (defun org-agenda-manipulate-query (char)
  6952. (cond
  6953. ((memq org-agenda-type '(timeline agenda))
  6954. (let ((org-agenda-include-inactive-timestamps t))
  6955. (org-agenda-redo))
  6956. (message "Display now includes inactive timestamps as well"))
  6957. ((eq org-agenda-type 'search)
  6958. (org-add-to-string
  6959. 'org-agenda-query-string
  6960. (if org-agenda-last-search-view-search-was-boolean
  6961. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6962. (?\{ . " +{}") (?\} . " -{}"))))
  6963. " "))
  6964. (setq org-agenda-redo-command
  6965. (list 'org-search-view
  6966. (car (get-text-property (min (1- (point-max)) (point))
  6967. 'org-last-args))
  6968. org-agenda-query-string
  6969. (+ (length org-agenda-query-string)
  6970. (if (member char '(?\{ ?\})) 0 1))))
  6971. (set-register org-agenda-query-register org-agenda-query-string)
  6972. (let ((org-agenda-overriding-arguments
  6973. (cdr org-agenda-redo-command)))
  6974. (org-agenda-redo)))
  6975. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6976. org-agenda-type))))
  6977. (defun org-add-to-string (var string)
  6978. (set var (concat (symbol-value var) string)))
  6979. (defun org-agenda-goto-date (span)
  6980. "Jump to DATE in agenda."
  6981. (interactive "P")
  6982. (let* ((org-read-date-prefer-future
  6983. (eval org-agenda-jump-prefer-future))
  6984. (date (org-read-date))
  6985. (org-agenda-sticky-orig org-agenda-sticky)
  6986. (org-agenda-buffer-tmp-name (buffer-name))
  6987. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6988. (0-arg (or current-prefix-arg (car args)))
  6989. (2-arg (nth 2 args))
  6990. (newcmd (list 'org-agenda-list 0-arg date
  6991. (org-agenda-span-to-ndays 2-arg)))
  6992. (newargs (cdr newcmd))
  6993. (inhibit-read-only t)
  6994. org-agenda-sticky)
  6995. (if (not (org-agenda-check-type t 'agenda))
  6996. (error "Not available in non-agenda blocks")
  6997. (add-text-properties (point-min) (point-max)
  6998. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6999. (org-agenda-redo)
  7000. (setq org-agenda-sticky org-agenda-sticky-orig
  7001. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7002. (defun org-agenda-goto-today ()
  7003. "Go to today."
  7004. (interactive)
  7005. (org-agenda-check-type t 'timeline 'agenda)
  7006. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7007. (curspan (nth 2 args))
  7008. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7009. (cond
  7010. (tdpos (goto-char tdpos))
  7011. ((eq org-agenda-type 'agenda)
  7012. (let* ((sd (org-agenda-compute-starting-span
  7013. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7014. (org-agenda-overriding-arguments args))
  7015. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7016. (org-agenda-redo)
  7017. (org-agenda-find-same-or-today-or-agenda)))
  7018. (t (error "Cannot find today")))))
  7019. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7020. (goto-char
  7021. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7022. (text-property-any (point-min) (point-max) 'org-today t)
  7023. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7024. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7025. (org-agenda-goto-block-beginning))
  7026. (point-min))))
  7027. (defun org-agenda-goto-block-beginning ()
  7028. "Go the agenda block beginning."
  7029. (interactive)
  7030. (if (not (derived-mode-p 'org-agenda-mode))
  7031. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7032. (let (dest)
  7033. (save-excursion
  7034. (unless (looking-at "\\'")
  7035. (forward-char))
  7036. (let* ((prop 'org-agenda-structural-header)
  7037. (p (previous-single-property-change (point) prop))
  7038. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7039. (1- (point))) prop)))
  7040. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7041. (if (not dest)
  7042. (error "Cannot find the beginning of the blog")
  7043. (goto-char dest)
  7044. (move-beginning-of-line 1)))))
  7045. (defun org-agenda-later (arg)
  7046. "Go forward in time by the current span.
  7047. With prefix ARG, go forward that many times the current span."
  7048. (interactive "p")
  7049. (org-agenda-check-type t 'agenda)
  7050. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7051. (span (or (nth 2 args) org-agenda-current-span))
  7052. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7053. (greg (calendar-gregorian-from-absolute sd))
  7054. (cnt (org-get-at-bol 'org-day-cnt))
  7055. greg2)
  7056. (cond
  7057. ((numberp span)
  7058. (setq sd (+ (* span arg) sd)))
  7059. ((eq span 'day)
  7060. (setq sd (+ arg sd)))
  7061. ((eq span 'week)
  7062. (setq sd (+ (* 7 arg) sd)))
  7063. ((eq span 'month)
  7064. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7065. sd (calendar-absolute-from-gregorian greg2))
  7066. (setcar greg2 (1+ (car greg2))))
  7067. ((eq span 'year)
  7068. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7069. sd (calendar-absolute-from-gregorian greg2))
  7070. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7071. (t
  7072. (setq sd (+ (* span arg) sd))))
  7073. (let ((org-agenda-overriding-cmd
  7074. ;; `cmd' may have been set by `org-agenda-run-series' which
  7075. ;; uses `org-agenda-overriding-cmd' to decide whether
  7076. ;; overriding is allowed for `cmd'
  7077. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7078. (org-agenda-overriding-arguments
  7079. (list (car args) sd span)))
  7080. (org-agenda-redo)
  7081. (org-agenda-find-same-or-today-or-agenda cnt))))
  7082. (defun org-agenda-earlier (arg)
  7083. "Go backward in time by the current span.
  7084. With prefix ARG, go backward that many times the current span."
  7085. (interactive "p")
  7086. (org-agenda-later (- arg)))
  7087. (defun org-agenda-view-mode-dispatch ()
  7088. "Call one of the view mode commands."
  7089. (interactive)
  7090. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  7091. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7092. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7093. (let ((a (read-char-exclusive)))
  7094. (case a
  7095. (?\ (call-interactively 'org-agenda-reset-view))
  7096. (?d (call-interactively 'org-agenda-day-view))
  7097. (?w (call-interactively 'org-agenda-week-view))
  7098. (?m (call-interactively 'org-agenda-month-view))
  7099. (?y (call-interactively 'org-agenda-year-view))
  7100. (?l (call-interactively 'org-agenda-log-mode))
  7101. (?L (org-agenda-log-mode '(4)))
  7102. (?c (org-agenda-log-mode 'clockcheck))
  7103. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7104. (?a (call-interactively 'org-agenda-archives-mode))
  7105. (?A (org-agenda-archives-mode 'files))
  7106. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7107. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7108. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7109. (?D (call-interactively 'org-agenda-toggle-diary))
  7110. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7111. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7112. (org-agenda-check-type t 'timeline 'agenda)
  7113. (org-agenda-redo))
  7114. (message "Display now includes inactive timestamps as well"))
  7115. (?q (message "Abort"))
  7116. (otherwise (error "Invalid key" )))))
  7117. (defun org-agenda-reset-view ()
  7118. "Switch to default view for agenda."
  7119. (interactive)
  7120. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7121. (defun org-agenda-day-view (&optional day-of-month)
  7122. "Switch to daily view for agenda.
  7123. With argument DAY-OF-MONTH, switch to that day of the month."
  7124. (interactive "P")
  7125. (org-agenda-change-time-span 'day day-of-month))
  7126. (defun org-agenda-week-view (&optional iso-week)
  7127. "Switch to daily view for agenda.
  7128. With argument ISO-WEEK, switch to the corresponding ISO week.
  7129. If ISO-WEEK has more then 2 digits, only the last two encode the
  7130. week. Any digits before this encode a year. So 200712 means
  7131. week 12 of year 2007. Years in the range 1938-2037 can also be
  7132. written as 2-digit years."
  7133. (interactive "P")
  7134. (org-agenda-change-time-span 'week iso-week))
  7135. (defun org-agenda-month-view (&optional month)
  7136. "Switch to monthly view for agenda.
  7137. With argument MONTH, switch to that month."
  7138. (interactive "P")
  7139. (org-agenda-change-time-span 'month month))
  7140. (defun org-agenda-year-view (&optional year)
  7141. "Switch to yearly view for agenda.
  7142. With argument YEAR, switch to that year.
  7143. If MONTH has more then 2 digits, only the last two encode the
  7144. month. Any digits before this encode a year. So 200712 means
  7145. December year 2007. Years in the range 1938-2037 can also be
  7146. written as 2-digit years."
  7147. (interactive "P")
  7148. (when year
  7149. (setq year (org-small-year-to-year year)))
  7150. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7151. (org-agenda-change-time-span 'year year)
  7152. (error "Abort")))
  7153. (defun org-agenda-change-time-span (span &optional n)
  7154. "Change the agenda view to SPAN.
  7155. SPAN may be `day', `week', `month', `year'."
  7156. (org-agenda-check-type t 'agenda)
  7157. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7158. (curspan (nth 2 args)))
  7159. (if (and (not n) (equal curspan span))
  7160. (error "Viewing span is already \"%s\"" span))
  7161. (let* ((sd (or (org-get-at-bol 'day)
  7162. (nth 1 args)
  7163. org-starting-day))
  7164. (sd (org-agenda-compute-starting-span sd span n))
  7165. (org-agenda-overriding-cmd
  7166. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7167. (org-agenda-overriding-arguments
  7168. (list (car args) sd span)))
  7169. (org-agenda-redo)
  7170. (org-agenda-find-same-or-today-or-agenda))
  7171. (org-agenda-set-mode-name)
  7172. (message "Switched to %s view" span)))
  7173. (defun org-agenda-compute-starting-span (sd span &optional n)
  7174. "Compute starting date for agenda.
  7175. SPAN may be `day', `week', `month', `year'. The return value
  7176. is a cons cell with the starting date and the number of days,
  7177. so that the date SD will be in that range."
  7178. (let* ((greg (calendar-gregorian-from-absolute sd))
  7179. (dg (nth 1 greg))
  7180. (mg (car greg))
  7181. (yg (nth 2 greg)))
  7182. (cond
  7183. ((eq span 'day)
  7184. (when n
  7185. (setq sd (+ (calendar-absolute-from-gregorian
  7186. (list mg 1 yg))
  7187. n -1))))
  7188. ((eq span 'week)
  7189. (let* ((nt (calendar-day-of-week
  7190. (calendar-gregorian-from-absolute sd)))
  7191. (d (if org-agenda-start-on-weekday
  7192. (- nt org-agenda-start-on-weekday)
  7193. 0))
  7194. y1)
  7195. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7196. (when n
  7197. (require 'cal-iso)
  7198. (when (> n 99)
  7199. (setq y1 (org-small-year-to-year (/ n 100))
  7200. n (mod n 100)))
  7201. (setq sd
  7202. (calendar-absolute-from-iso
  7203. (list n 1
  7204. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7205. ((eq span 'month)
  7206. (let (y1)
  7207. (when (and n (> n 99))
  7208. (setq y1 (org-small-year-to-year (/ n 100))
  7209. n (mod n 100)))
  7210. (setq sd (calendar-absolute-from-gregorian
  7211. (list (or n mg) 1 (or y1 yg))))))
  7212. ((eq span 'year)
  7213. (setq sd (calendar-absolute-from-gregorian
  7214. (list 1 1 (or n yg))))))
  7215. sd))
  7216. (defun org-agenda-next-date-line (&optional arg)
  7217. "Jump to the next line indicating a date in agenda buffer."
  7218. (interactive "p")
  7219. (org-agenda-check-type t 'agenda 'timeline)
  7220. (beginning-of-line 1)
  7221. ;; This does not work if user makes date format that starts with a blank
  7222. (if (looking-at "^\\S-") (forward-char 1))
  7223. (if (not (re-search-forward "^\\S-" nil t arg))
  7224. (progn
  7225. (backward-char 1)
  7226. (error "No next date after this line in this buffer")))
  7227. (goto-char (match-beginning 0)))
  7228. (defun org-agenda-previous-date-line (&optional arg)
  7229. "Jump to the previous line indicating a date in agenda buffer."
  7230. (interactive "p")
  7231. (org-agenda-check-type t 'agenda 'timeline)
  7232. (beginning-of-line 1)
  7233. (if (not (re-search-backward "^\\S-" nil t arg))
  7234. (error "No previous date before this line in this buffer")))
  7235. ;; Initialize the highlight
  7236. (defvar org-hl (make-overlay 1 1))
  7237. (overlay-put org-hl 'face 'highlight)
  7238. (defun org-highlight (begin end &optional buffer)
  7239. "Highlight a region with overlay."
  7240. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7241. (defun org-unhighlight ()
  7242. "Detach overlay INDEX."
  7243. (org-detach-overlay org-hl))
  7244. (defun org-unhighlight-once ()
  7245. "Remove the highlight from its position, and this function from the hook."
  7246. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7247. (org-unhighlight))
  7248. (defvar org-agenda-pre-follow-window-conf nil)
  7249. (defun org-agenda-follow-mode ()
  7250. "Toggle follow mode in an agenda buffer."
  7251. (interactive)
  7252. (unless org-agenda-follow-mode
  7253. (setq org-agenda-pre-follow-window-conf
  7254. (current-window-configuration)))
  7255. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7256. (unless org-agenda-follow-mode
  7257. (set-window-configuration org-agenda-pre-follow-window-conf))
  7258. (org-agenda-set-mode-name)
  7259. (org-agenda-do-context-action)
  7260. (message "Follow mode is %s"
  7261. (if org-agenda-follow-mode "on" "off")))
  7262. (defun org-agenda-entry-text-mode (&optional arg)
  7263. "Toggle entry text mode in an agenda buffer."
  7264. (interactive "P")
  7265. (if (or org-agenda-tag-filter
  7266. org-agenda-category-filter
  7267. org-agenda-top-category-filter)
  7268. (user-error "Can't show entry text in filtered views")
  7269. (setq org-agenda-entry-text-mode (or (integerp arg)
  7270. (not org-agenda-entry-text-mode)))
  7271. (org-agenda-entry-text-hide)
  7272. (and org-agenda-entry-text-mode
  7273. (let ((org-agenda-entry-text-maxlines
  7274. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7275. (org-agenda-entry-text-show)))
  7276. (org-agenda-set-mode-name)
  7277. (message "Entry text mode is %s%s"
  7278. (if org-agenda-entry-text-mode "on" "off")
  7279. (if (not org-agenda-entry-text-mode) ""
  7280. (format " (maximum number of lines is %d)"
  7281. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7282. (defun org-agenda-clockreport-mode (&optional with-filter)
  7283. "Toggle clocktable mode in an agenda buffer.
  7284. With prefix arg WITH-FILTER, make the clocktable respect the current
  7285. agenda filter."
  7286. (interactive "P")
  7287. (org-agenda-check-type t 'agenda)
  7288. (if with-filter
  7289. (setq org-agenda-clockreport-mode 'with-filter)
  7290. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7291. (org-agenda-set-mode-name)
  7292. (org-agenda-redo)
  7293. (message "Clocktable mode is %s"
  7294. (if org-agenda-clockreport-mode "on" "off")))
  7295. (defun org-agenda-log-mode (&optional special)
  7296. "Toggle log mode in an agenda buffer.
  7297. With argument SPECIAL, show all possible log items, not only the ones
  7298. configured in `org-agenda-log-mode-items'.
  7299. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7300. (interactive "P")
  7301. (org-agenda-check-type t 'agenda 'timeline)
  7302. (setq org-agenda-show-log
  7303. (cond
  7304. ((equal special '(16)) 'only)
  7305. ((eq special 'clockcheck)
  7306. (if (eq org-agenda-show-log 'clockcheck)
  7307. nil 'clockcheck))
  7308. (special '(closed clock state))
  7309. (t (not org-agenda-show-log))))
  7310. (org-agenda-set-mode-name)
  7311. (org-agenda-redo)
  7312. (message "Log mode is %s"
  7313. (if org-agenda-show-log "on" "off")))
  7314. (defun org-agenda-archives-mode (&optional with-files)
  7315. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7316. When called with a prefix argument, include all archive files as well."
  7317. (interactive "P")
  7318. (setq org-agenda-archives-mode
  7319. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7320. (org-agenda-set-mode-name)
  7321. (org-agenda-redo)
  7322. (message
  7323. "%s"
  7324. (cond
  7325. ((eq org-agenda-archives-mode nil)
  7326. "No archives are included")
  7327. ((eq org-agenda-archives-mode 'trees)
  7328. (format "Trees with :%s: tag are included" org-archive-tag))
  7329. ((eq org-agenda-archives-mode t)
  7330. (format "Trees with :%s: tag and all active archive files are included"
  7331. org-archive-tag)))))
  7332. (defun org-agenda-toggle-diary ()
  7333. "Toggle diary inclusion in an agenda buffer."
  7334. (interactive)
  7335. (org-agenda-check-type t 'agenda)
  7336. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7337. (org-agenda-redo)
  7338. (org-agenda-set-mode-name)
  7339. (message "Diary inclusion turned %s"
  7340. (if org-agenda-include-diary "on" "off")))
  7341. (defun org-agenda-toggle-deadlines ()
  7342. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7343. (interactive)
  7344. (org-agenda-check-type t 'agenda)
  7345. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7346. (org-agenda-redo)
  7347. (org-agenda-set-mode-name)
  7348. (message "Deadlines inclusion turned %s"
  7349. (if org-agenda-include-deadlines "on" "off")))
  7350. (defun org-agenda-toggle-time-grid ()
  7351. "Toggle time grid in an agenda buffer."
  7352. (interactive)
  7353. (org-agenda-check-type t 'agenda)
  7354. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7355. (org-agenda-redo)
  7356. (org-agenda-set-mode-name)
  7357. (message "Time-grid turned %s"
  7358. (if org-agenda-use-time-grid "on" "off")))
  7359. (defun org-agenda-set-mode-name ()
  7360. "Set the mode name to indicate all the small mode settings."
  7361. (setq mode-name
  7362. (list "Org-Agenda"
  7363. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7364. " "
  7365. '(:eval (org-agenda-span-name org-agenda-current-span))
  7366. (if org-agenda-follow-mode " Follow" "")
  7367. (if org-agenda-entry-text-mode " ETxt" "")
  7368. (if org-agenda-include-diary " Diary" "")
  7369. (if org-agenda-include-deadlines " Ddl" "")
  7370. (if org-agenda-use-time-grid " Grid" "")
  7371. (if (and (boundp 'org-habit-show-habits)
  7372. org-habit-show-habits) " Habit" "")
  7373. (cond
  7374. ((consp org-agenda-show-log) " LogAll")
  7375. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7376. (org-agenda-show-log " Log")
  7377. (t ""))
  7378. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7379. :preset-filter))
  7380. '(:eval (org-propertize
  7381. (concat " <"
  7382. (mapconcat
  7383. 'identity
  7384. (append
  7385. (get 'org-agenda-category-filter :preset-filter)
  7386. org-agenda-category-filter)
  7387. "")
  7388. ">")
  7389. 'face 'org-agenda-filter-category
  7390. 'help-echo "Category used in filtering"))
  7391. "")
  7392. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7393. :preset-filter))
  7394. '(:eval (org-propertize
  7395. (concat " {"
  7396. (mapconcat
  7397. 'identity
  7398. (append
  7399. (get 'org-agenda-tag-filter :preset-filter)
  7400. org-agenda-tag-filter)
  7401. "")
  7402. "}")
  7403. 'face 'org-agenda-filter-tags
  7404. 'help-echo "Tags used in filtering"))
  7405. "")
  7406. (if org-agenda-archives-mode
  7407. (if (eq org-agenda-archives-mode t)
  7408. " Archives"
  7409. (format " :%s:" org-archive-tag))
  7410. "")
  7411. (if org-agenda-clockreport-mode
  7412. (if (eq org-agenda-clockreport-mode 'with-filter)
  7413. " Clock{}" " Clock")
  7414. "")))
  7415. (force-mode-line-update))
  7416. (define-obsolete-function-alias
  7417. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7418. (defun org-agenda-update-agenda-type ()
  7419. "Update the agenda type after each command."
  7420. (setq org-agenda-type
  7421. (or (get-text-property (point) 'org-agenda-type)
  7422. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7423. (defun org-agenda-next-line ()
  7424. "Move cursor to the next line, and show if follow mode is active."
  7425. (interactive)
  7426. (call-interactively 'next-line)
  7427. (org-agenda-do-context-action))
  7428. (defun org-agenda-previous-line ()
  7429. "Move cursor to the previous line, and show if follow-mode is active."
  7430. (interactive)
  7431. (call-interactively 'previous-line)
  7432. (org-agenda-do-context-action))
  7433. (defun org-agenda-next-item (n)
  7434. "Move cursor to next agenda item."
  7435. (interactive "p")
  7436. (let ((col (current-column)))
  7437. (dotimes (c n)
  7438. (when (next-single-property-change (point-at-eol) 'org-marker)
  7439. (move-end-of-line 1)
  7440. (goto-char (next-single-property-change (point) 'org-marker))))
  7441. (org-move-to-column col))
  7442. (org-agenda-do-context-action))
  7443. (defun org-agenda-previous-item (n)
  7444. "Move cursor to next agenda item."
  7445. (interactive "p")
  7446. (dotimes (c n)
  7447. (let ((col (current-column))
  7448. (goto (save-excursion
  7449. (move-end-of-line 0)
  7450. (previous-single-property-change (point) 'org-marker))))
  7451. (if goto (goto-char goto))
  7452. (org-move-to-column col)))
  7453. (org-agenda-do-context-action))
  7454. (defun org-agenda-do-context-action ()
  7455. "Show outline path and, maybe, follow mode window."
  7456. (let ((m (org-get-at-bol 'org-marker)))
  7457. (when (and (markerp m) (marker-buffer m))
  7458. (and org-agenda-follow-mode
  7459. (if org-agenda-follow-indirect
  7460. (org-agenda-tree-to-indirect-buffer nil)
  7461. (org-agenda-show)))
  7462. (and org-agenda-show-outline-path
  7463. (org-with-point-at m (org-display-outline-path t))))))
  7464. (defun org-agenda-show-tags ()
  7465. "Show the tags applicable to the current item."
  7466. (interactive)
  7467. (let* ((tags (org-get-at-bol 'tags)))
  7468. (if tags
  7469. (message "Tags are :%s:"
  7470. (org-no-properties (mapconcat 'identity tags ":")))
  7471. (message "No tags associated with this line"))))
  7472. (defun org-agenda-goto (&optional highlight)
  7473. "Go to the Org-mode file which contains the item at point."
  7474. (interactive)
  7475. (let* ((marker (or (org-get-at-bol 'org-marker)
  7476. (org-agenda-error)))
  7477. (buffer (marker-buffer marker))
  7478. (pos (marker-position marker)))
  7479. (switch-to-buffer-other-window buffer)
  7480. (widen)
  7481. (push-mark)
  7482. (goto-char pos)
  7483. (when (derived-mode-p 'org-mode)
  7484. (org-show-context 'agenda)
  7485. (save-excursion
  7486. (and (outline-next-heading)
  7487. (org-flag-heading nil)))) ; show the next heading
  7488. (when (outline-invisible-p)
  7489. (show-entry)) ; display invisible text
  7490. (recenter (/ (window-height) 2))
  7491. (run-hooks 'org-agenda-after-show-hook)
  7492. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7493. (defvar org-agenda-after-show-hook nil
  7494. "Normal hook run after an item has been shown from the agenda.
  7495. Point is in the buffer where the item originated.")
  7496. (defun org-agenda-kill ()
  7497. "Kill the entry or subtree belonging to the current agenda entry."
  7498. (interactive)
  7499. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7500. (let* ((bufname-orig (buffer-name))
  7501. (marker (or (org-get-at-bol 'org-marker)
  7502. (org-agenda-error)))
  7503. (buffer (marker-buffer marker))
  7504. (pos (marker-position marker))
  7505. (type (org-get-at-bol 'type))
  7506. dbeg dend (n 0) conf)
  7507. (org-with-remote-undo buffer
  7508. (with-current-buffer buffer
  7509. (save-excursion
  7510. (goto-char pos)
  7511. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7512. (setq dbeg (progn (org-back-to-heading t) (point))
  7513. dend (org-end-of-subtree t t))
  7514. (setq dbeg (point-at-bol)
  7515. dend (min (point-max) (1+ (point-at-eol)))))
  7516. (goto-char dbeg)
  7517. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7518. (setq conf (or (eq t org-agenda-confirm-kill)
  7519. (and (numberp org-agenda-confirm-kill)
  7520. (> n org-agenda-confirm-kill))))
  7521. (and conf
  7522. (not (y-or-n-p
  7523. (format "Delete entry with %d lines in buffer \"%s\"? "
  7524. n (buffer-name buffer))))
  7525. (error "Abort"))
  7526. (let ((org-agenda-buffer-name bufname-orig))
  7527. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7528. (with-current-buffer buffer (delete-region dbeg dend))
  7529. (message "Agenda item and source killed"))))
  7530. (defvar org-archive-default-command) ; defined in org-archive.el
  7531. (defun org-agenda-archive-default ()
  7532. "Archive the entry or subtree belonging to the current agenda entry."
  7533. (interactive)
  7534. (require 'org-archive)
  7535. (org-agenda-archive-with org-archive-default-command))
  7536. (defun org-agenda-archive-default-with-confirmation ()
  7537. "Archive the entry or subtree belonging to the current agenda entry."
  7538. (interactive)
  7539. (require 'org-archive)
  7540. (org-agenda-archive-with org-archive-default-command 'confirm))
  7541. (defun org-agenda-archive ()
  7542. "Archive the entry or subtree belonging to the current agenda entry."
  7543. (interactive)
  7544. (org-agenda-archive-with 'org-archive-subtree))
  7545. (defun org-agenda-archive-to-archive-sibling ()
  7546. "Move the entry to the archive sibling."
  7547. (interactive)
  7548. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7549. (defun org-agenda-archive-with (cmd &optional confirm)
  7550. "Move the entry to the archive sibling."
  7551. (interactive)
  7552. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7553. (let* ((bufname-orig (buffer-name))
  7554. (marker (or (org-get-at-bol 'org-marker)
  7555. (org-agenda-error)))
  7556. (buffer (marker-buffer marker))
  7557. (pos (marker-position marker)))
  7558. (org-with-remote-undo buffer
  7559. (with-current-buffer buffer
  7560. (if (derived-mode-p 'org-mode)
  7561. (if (and confirm
  7562. (not (y-or-n-p "Archive this subtree or entry? ")))
  7563. (error "Abort")
  7564. (save-excursion
  7565. (goto-char pos)
  7566. (let ((org-agenda-buffer-name bufname-orig))
  7567. (org-remove-subtree-entries-from-agenda))
  7568. (org-back-to-heading t)
  7569. (funcall cmd)))
  7570. (error "Archiving works only in Org-mode files"))))))
  7571. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7572. "Remove all lines in the agenda that correspond to a given subtree.
  7573. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7574. If this information is not given, the function uses the tree at point."
  7575. (let ((buf (or buf (current-buffer))) m p)
  7576. (save-excursion
  7577. (unless (and beg end)
  7578. (org-back-to-heading t)
  7579. (setq beg (point))
  7580. (org-end-of-subtree t)
  7581. (setq end (point)))
  7582. (set-buffer (get-buffer org-agenda-buffer-name))
  7583. (save-excursion
  7584. (goto-char (point-max))
  7585. (beginning-of-line 1)
  7586. (while (not (bobp))
  7587. (when (and (setq m (org-get-at-bol 'org-marker))
  7588. (equal buf (marker-buffer m))
  7589. (setq p (marker-position m))
  7590. (>= p beg)
  7591. (< p end))
  7592. (let ((inhibit-read-only t))
  7593. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7594. (beginning-of-line 0))))))
  7595. (defun org-agenda-refile (&optional goto rfloc no-update)
  7596. "Refile the item at point.
  7597. When GOTO is 0 or '(64), clear the refile cache.
  7598. When GOTO is '(16), go to the location of the last refiled item.
  7599. RFLOC can be a refile location obtained in a different way.
  7600. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7601. (interactive "P")
  7602. (cond
  7603. ((member goto '(0 (64)))
  7604. (org-refile-cache-clear))
  7605. ((equal goto '(16))
  7606. (org-refile-goto-last-stored))
  7607. (t
  7608. (let* ((buffer-orig (buffer-name))
  7609. (marker (or (org-get-at-bol 'org-hd-marker)
  7610. (org-agenda-error)))
  7611. (buffer (marker-buffer marker))
  7612. (pos (marker-position marker))
  7613. (rfloc (or rfloc
  7614. (org-refile-get-location
  7615. (if goto "Goto" "Refile to") buffer
  7616. org-refile-allow-creating-parent-nodes))))
  7617. (with-current-buffer buffer
  7618. (save-excursion
  7619. (save-restriction
  7620. (widen)
  7621. (goto-char marker)
  7622. (let ((org-agenda-buffer-name buffer-orig))
  7623. (org-remove-subtree-entries-from-agenda))
  7624. (org-refile goto buffer rfloc)))))
  7625. (unless no-update (org-agenda-redo)))))
  7626. (defun org-agenda-open-link (&optional arg)
  7627. "Open the link(s) in the current entry, if any.
  7628. This looks for a link in the displayed line in the agenda.
  7629. It also looks at the text of the entry itself."
  7630. (interactive "P")
  7631. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7632. (org-get-at-bol 'org-marker)))
  7633. (buffer (and marker (marker-buffer marker)))
  7634. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7635. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7636. (lk0 (car lkall))
  7637. (lk (if (stringp lk0) (list lk0) lk0))
  7638. (lkend (cdr lkall))
  7639. trg)
  7640. (cond
  7641. ((and buffer lk)
  7642. (mapcar (lambda(l)
  7643. (with-current-buffer buffer
  7644. (setq trg (and (string-match org-bracket-link-regexp l)
  7645. (match-string 1 l)))
  7646. (if (or (not trg) (string-match org-any-link-re trg))
  7647. (save-excursion
  7648. (save-restriction
  7649. (widen)
  7650. (goto-char marker)
  7651. (when (search-forward l nil lkend)
  7652. (goto-char (match-beginning 0))
  7653. (org-open-at-point))))
  7654. ;; This is an internal link, widen the buffer
  7655. (switch-to-buffer-other-window buffer)
  7656. (widen)
  7657. (goto-char marker)
  7658. (when (search-forward l nil lkend)
  7659. (goto-char (match-beginning 0))
  7660. (org-open-at-point)))))
  7661. lk))
  7662. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7663. (save-excursion
  7664. (beginning-of-line 1)
  7665. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7666. (org-open-link-from-string (match-string 1)))
  7667. (t (message "No link to open here")))))
  7668. (defun org-agenda-copy-local-variable (var)
  7669. "Get a variable from a referenced buffer and install it here."
  7670. (let ((m (org-get-at-bol 'org-marker)))
  7671. (when (and m (buffer-live-p (marker-buffer m)))
  7672. (org-set-local var (with-current-buffer (marker-buffer m)
  7673. (symbol-value var))))))
  7674. (defun org-agenda-switch-to (&optional delete-other-windows)
  7675. "Go to the Org-mode file which contains the item at point."
  7676. (interactive)
  7677. (if (and org-return-follows-link
  7678. (not (org-get-at-bol 'org-marker))
  7679. (org-in-regexp org-bracket-link-regexp))
  7680. (org-open-link-from-string (match-string 0))
  7681. (let* ((marker (or (org-get-at-bol 'org-marker)
  7682. (org-agenda-error)))
  7683. (buffer (marker-buffer marker))
  7684. (pos (marker-position marker)))
  7685. (org-pop-to-buffer-same-window buffer)
  7686. (and delete-other-windows (delete-other-windows))
  7687. (widen)
  7688. (goto-char pos)
  7689. (when (derived-mode-p 'org-mode)
  7690. (org-show-context 'agenda)
  7691. (save-excursion
  7692. (and (outline-next-heading)
  7693. (org-flag-heading nil))) ; show the next heading
  7694. (when (outline-invisible-p)
  7695. (show-entry)) ; display invisible text
  7696. (run-hooks 'org-agenda-after-show-hook)))))
  7697. (defun org-agenda-goto-mouse (ev)
  7698. "Go to the Org-mode file which contains the item at the mouse click."
  7699. (interactive "e")
  7700. (mouse-set-point ev)
  7701. (org-agenda-goto))
  7702. (defun org-agenda-show (&optional full-entry)
  7703. "Display the Org-mode file which contains the item at point.
  7704. With prefix argument FULL-ENTRY, make the entire entry visible
  7705. if it was hidden in the outline."
  7706. (interactive "P")
  7707. (let ((win (selected-window)))
  7708. (if full-entry
  7709. (let ((org-show-entry-below t))
  7710. (org-agenda-goto t))
  7711. (org-agenda-goto t))
  7712. (select-window win)))
  7713. (defvar org-agenda-show-window nil)
  7714. (defun org-agenda-show-and-scroll-up (&optional arg)
  7715. "Display the Org-mode file which contains the item at point.
  7716. When called repeatedly, scroll the window that is displaying the buffer.
  7717. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7718. `show-subtree' to display the item, so that drawers and logbooks stay
  7719. folded."
  7720. (interactive "P")
  7721. (let ((win (selected-window)))
  7722. (if (and (window-live-p org-agenda-show-window)
  7723. (eq this-command last-command))
  7724. (progn
  7725. (select-window org-agenda-show-window)
  7726. (ignore-errors (scroll-up)))
  7727. (org-agenda-goto t)
  7728. (if arg (org-show-entry) (show-subtree))
  7729. (setq org-agenda-show-window (selected-window)))
  7730. (select-window win)))
  7731. (defun org-agenda-show-scroll-down ()
  7732. "Scroll down the window showing the agenda."
  7733. (interactive)
  7734. (let ((win (selected-window)))
  7735. (when (window-live-p org-agenda-show-window)
  7736. (select-window org-agenda-show-window)
  7737. (ignore-errors (scroll-down))
  7738. (select-window win))))
  7739. (defun org-agenda-show-1 (&optional more)
  7740. "Display the Org-mode file which contains the item at point.
  7741. The prefix arg selects the amount of information to display:
  7742. 0 hide the subtree
  7743. 1 just show the entry according to defaults.
  7744. 2 show the children view
  7745. 3 show the subtree view
  7746. 4 show the entire subtree and any LOGBOOK drawers
  7747. 5 show the entire subtree and any drawers
  7748. With prefix argument FULL-ENTRY, make the entire entry visible
  7749. if it was hidden in the outline."
  7750. (interactive "p")
  7751. (let ((win (selected-window)))
  7752. (org-agenda-goto t)
  7753. (org-recenter-heading 1)
  7754. (cond
  7755. ((= more 0)
  7756. (hide-subtree)
  7757. (save-excursion
  7758. (org-back-to-heading)
  7759. (run-hook-with-args 'org-cycle-hook 'folded))
  7760. (message "Remote: FOLDED"))
  7761. ((and (org-called-interactively-p 'any) (= more 1))
  7762. (message "Remote: show with default settings"))
  7763. ((= more 2)
  7764. (show-entry)
  7765. (show-children)
  7766. (save-excursion
  7767. (org-back-to-heading)
  7768. (run-hook-with-args 'org-cycle-hook 'children))
  7769. (message "Remote: CHILDREN"))
  7770. ((= more 3)
  7771. (show-subtree)
  7772. (save-excursion
  7773. (org-back-to-heading)
  7774. (run-hook-with-args 'org-cycle-hook 'subtree))
  7775. (message "Remote: SUBTREE"))
  7776. ((= more 4)
  7777. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7778. (org-drawer-regexp
  7779. (concat "^[ \t]*:\\("
  7780. (mapconcat 'regexp-quote org-drawers "\\|")
  7781. "\\):[ \t]*$")))
  7782. (show-subtree)
  7783. (save-excursion
  7784. (org-back-to-heading)
  7785. (org-cycle-hide-drawers 'subtree)))
  7786. (message "Remote: SUBTREE AND LOGBOOK"))
  7787. ((> more 4)
  7788. (show-subtree)
  7789. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7790. (select-window win)))
  7791. (defun org-recenter-heading (n)
  7792. (save-excursion
  7793. (org-back-to-heading)
  7794. (recenter n)))
  7795. (defvar org-agenda-cycle-counter nil)
  7796. (defun org-agenda-cycle-show (&optional n)
  7797. "Show the current entry in another window, with default settings.
  7798. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7799. When use repeatedly in immediate succession, the remote entry will cycle
  7800. through visibility
  7801. children -> subtree -> folded
  7802. When called with a numeric prefix arg, that arg will be passed through to
  7803. `org-agenda-show-1'. For the interpretation of that argument, see the
  7804. docstring of `org-agenda-show-1'."
  7805. (interactive "P")
  7806. (if (integerp n)
  7807. (setq org-agenda-cycle-counter n)
  7808. (if (not (eq last-command this-command))
  7809. (setq org-agenda-cycle-counter 1)
  7810. (if (equal org-agenda-cycle-counter 0)
  7811. (setq org-agenda-cycle-counter 2)
  7812. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7813. (if (> org-agenda-cycle-counter 3)
  7814. (setq org-agenda-cycle-counter 0)))))
  7815. (org-agenda-show-1 org-agenda-cycle-counter))
  7816. (defun org-agenda-recenter (arg)
  7817. "Display the Org-mode file which contains the item at point and recenter."
  7818. (interactive "P")
  7819. (let ((win (selected-window)))
  7820. (org-agenda-goto t)
  7821. (recenter arg)
  7822. (select-window win)))
  7823. (defun org-agenda-show-mouse (ev)
  7824. "Display the Org-mode file which contains the item at the mouse click."
  7825. (interactive "e")
  7826. (mouse-set-point ev)
  7827. (org-agenda-show))
  7828. (defun org-agenda-check-no-diary ()
  7829. "Check if the entry is a diary link and abort if yes."
  7830. (if (org-get-at-bol 'org-agenda-diary-link)
  7831. (org-agenda-error)))
  7832. (defun org-agenda-error ()
  7833. (error "Command not allowed in this line"))
  7834. (defun org-agenda-tree-to-indirect-buffer (arg)
  7835. "Show the subtree corresponding to the current entry in an indirect buffer.
  7836. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7837. With a numerical prefix ARG, go up to this level and then take that tree.
  7838. With a negative numeric ARG, go up by this number of levels.
  7839. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7840. use the dedicated frame)."
  7841. (interactive "P")
  7842. (if current-prefix-arg
  7843. (org-agenda-do-tree-to-indirect-buffer arg)
  7844. (let ((agenda-buffer (buffer-name))
  7845. (agenda-window (selected-window))
  7846. (indirect-window
  7847. (and org-last-indirect-buffer
  7848. (get-buffer-window org-last-indirect-buffer))))
  7849. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7850. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7851. (eq org-indirect-buffer-display 'dedicated-frame))
  7852. (unwind-protect
  7853. (unless (and indirect-window (window-live-p indirect-window))
  7854. (setq indirect-window (split-window agenda-window)))
  7855. (and indirect-window (select-window indirect-window))
  7856. (switch-to-buffer org-last-indirect-buffer :norecord)
  7857. (fit-window-to-buffer indirect-window)))
  7858. (select-window (get-buffer-window agenda-buffer)))))
  7859. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7860. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7861. (org-agenda-check-no-diary)
  7862. (let* ((marker (or (org-get-at-bol 'org-marker)
  7863. (org-agenda-error)))
  7864. (buffer (marker-buffer marker))
  7865. (pos (marker-position marker)))
  7866. (with-current-buffer buffer
  7867. (save-excursion
  7868. (goto-char pos)
  7869. (funcall 'org-tree-to-indirect-buffer arg)))))
  7870. (defvar org-last-heading-marker (make-marker)
  7871. "Marker pointing to the headline that last changed its TODO state
  7872. by a remote command from the agenda.")
  7873. (defun org-agenda-todo-nextset ()
  7874. "Switch TODO entry to next sequence."
  7875. (interactive)
  7876. (org-agenda-todo 'nextset))
  7877. (defun org-agenda-todo-previousset ()
  7878. "Switch TODO entry to previous sequence."
  7879. (interactive)
  7880. (org-agenda-todo 'previousset))
  7881. (defun org-agenda-todo (&optional arg)
  7882. "Cycle TODO state of line at point, also in Org-mode file.
  7883. This changes the line at point, all other lines in the agenda referring to
  7884. the same tree node, and the headline of the tree node in the Org-mode file."
  7885. (interactive "P")
  7886. (org-agenda-check-no-diary)
  7887. (let* ((col (current-column))
  7888. (marker (or (org-get-at-bol 'org-marker)
  7889. (org-agenda-error)))
  7890. (buffer (marker-buffer marker))
  7891. (pos (marker-position marker))
  7892. (hdmarker (org-get-at-bol 'org-hd-marker))
  7893. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7894. (inhibit-read-only t)
  7895. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7896. (org-with-remote-undo buffer
  7897. (with-current-buffer buffer
  7898. (widen)
  7899. (goto-char pos)
  7900. (org-show-context 'agenda)
  7901. (save-excursion
  7902. (and (outline-next-heading)
  7903. (org-flag-heading nil))) ; show the next heading
  7904. (let ((current-prefix-arg arg))
  7905. (call-interactively 'org-todo))
  7906. (and (bolp) (forward-char 1))
  7907. (setq newhead (org-get-heading))
  7908. (when (and (org-bound-and-true-p
  7909. org-agenda-headline-snapshot-before-repeat)
  7910. (not (equal org-agenda-headline-snapshot-before-repeat
  7911. newhead))
  7912. todayp)
  7913. (setq newhead org-agenda-headline-snapshot-before-repeat
  7914. just-one t))
  7915. (save-excursion
  7916. (org-back-to-heading)
  7917. (move-marker org-last-heading-marker (point))))
  7918. (beginning-of-line 1)
  7919. (save-excursion
  7920. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7921. (org-move-to-column col))))
  7922. (defun org-agenda-add-note (&optional arg)
  7923. "Add a time-stamped note to the entry at point."
  7924. (interactive "P")
  7925. (org-agenda-check-no-diary)
  7926. (let* ((marker (or (org-get-at-bol 'org-marker)
  7927. (org-agenda-error)))
  7928. (buffer (marker-buffer marker))
  7929. (pos (marker-position marker))
  7930. (hdmarker (org-get-at-bol 'org-hd-marker))
  7931. (inhibit-read-only t))
  7932. (with-current-buffer buffer
  7933. (widen)
  7934. (goto-char pos)
  7935. (org-show-context 'agenda)
  7936. (save-excursion
  7937. (and (outline-next-heading)
  7938. (org-flag-heading nil))) ; show the next heading
  7939. (org-add-note))))
  7940. (defun org-agenda-change-all-lines (newhead hdmarker
  7941. &optional fixface just-this)
  7942. "Change all lines in the agenda buffer which match HDMARKER.
  7943. The new content of the line will be NEWHEAD (as modified by
  7944. `org-agenda-format-item'). HDMARKER is checked with
  7945. `equal' against all `org-hd-marker' text properties in the file.
  7946. If FIXFACE is non-nil, the face of each item is modified according to
  7947. the new TODO state.
  7948. If JUST-THIS is non-nil, change just the current line, not all.
  7949. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7950. (let* ((inhibit-read-only t)
  7951. (line (org-current-line))
  7952. (org-agenda-buffer (current-buffer))
  7953. (thetags (with-current-buffer (marker-buffer hdmarker)
  7954. (save-excursion (save-restriction (widen)
  7955. (goto-char hdmarker)
  7956. (org-get-tags-at)))))
  7957. props m pl undone-face done-face finish new dotime level cat tags)
  7958. (save-excursion
  7959. (goto-char (point-max))
  7960. (beginning-of-line 1)
  7961. (while (not finish)
  7962. (setq finish (bobp))
  7963. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7964. (or (not just-this) (= (org-current-line) line))
  7965. (equal m hdmarker))
  7966. (setq props (text-properties-at (point))
  7967. dotime (org-get-at-bol 'dotime)
  7968. cat (org-get-at-bol 'org-category)
  7969. level (org-get-at-bol 'level)
  7970. tags thetags
  7971. new
  7972. (let ((org-prefix-format-compiled
  7973. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7974. org-prefix-format-compiled))
  7975. (extra (org-get-at-bol 'extra)))
  7976. (with-current-buffer (marker-buffer hdmarker)
  7977. (save-excursion
  7978. (save-restriction
  7979. (widen)
  7980. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7981. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7982. undone-face (org-get-at-bol 'undone-face)
  7983. done-face (org-get-at-bol 'done-face))
  7984. (beginning-of-line 1)
  7985. (cond
  7986. ((equal new "")
  7987. (and (looking-at ".*\n?") (replace-match "")))
  7988. ((looking-at ".*")
  7989. (replace-match new t t)
  7990. (beginning-of-line 1)
  7991. (add-text-properties (point-at-bol) (point-at-eol) props)
  7992. (when fixface
  7993. (add-text-properties
  7994. (point-at-bol) (point-at-eol)
  7995. (list 'face
  7996. (if org-last-todo-state-is-todo
  7997. undone-face done-face))))
  7998. (org-agenda-highlight-todo 'line)
  7999. (beginning-of-line 1))
  8000. (t (error "Line update did not work")))
  8001. (save-restriction
  8002. (narrow-to-region (point-at-bol) (point-at-eol))
  8003. (org-agenda-finalize)))
  8004. (beginning-of-line 0)))))
  8005. (defun org-agenda-align-tags (&optional line)
  8006. "Align all tags in agenda items to `org-agenda-tags-column'."
  8007. (let ((inhibit-read-only t) l c)
  8008. (save-excursion
  8009. (goto-char (if line (point-at-bol) (point-min)))
  8010. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8011. (if line (point-at-eol) nil) t)
  8012. (add-text-properties
  8013. (match-beginning 2) (match-end 2)
  8014. (list 'face (delq nil (let ((prop (get-text-property
  8015. (match-beginning 2) 'face)))
  8016. (or (listp prop) (setq prop (list prop)))
  8017. (if (memq 'org-tag prop)
  8018. prop
  8019. (cons 'org-tag prop))))))
  8020. (setq l (- (match-end 2) (match-beginning 2))
  8021. c (if (< org-agenda-tags-column 0)
  8022. (- (abs org-agenda-tags-column) l)
  8023. org-agenda-tags-column))
  8024. (delete-region (match-beginning 1) (match-end 1))
  8025. (goto-char (match-beginning 1))
  8026. (insert (org-add-props
  8027. (make-string (max 1 (- c (current-column))) ?\ )
  8028. (plist-put (copy-sequence (text-properties-at (point)))
  8029. 'face nil))))
  8030. (goto-char (point-min))
  8031. (org-font-lock-add-tag-faces (point-max)))))
  8032. (defun org-agenda-priority-up ()
  8033. "Increase the priority of line at point, also in Org-mode file."
  8034. (interactive)
  8035. (org-agenda-priority 'up))
  8036. (defun org-agenda-priority-down ()
  8037. "Decrease the priority of line at point, also in Org-mode file."
  8038. (interactive)
  8039. (org-agenda-priority 'down))
  8040. (defun org-agenda-priority (&optional force-direction)
  8041. "Set the priority of line at point, also in Org-mode file.
  8042. This changes the line at point, all other lines in the agenda referring to
  8043. the same tree node, and the headline of the tree node in the Org-mode file.
  8044. Called with a universal prefix arg, show the priority instead of setting it."
  8045. (interactive "P")
  8046. (if (equal force-direction '(4))
  8047. (org-show-priority)
  8048. (unless org-enable-priority-commands
  8049. (error "Priority commands are disabled"))
  8050. (org-agenda-check-no-diary)
  8051. (let* ((marker (or (org-get-at-bol 'org-marker)
  8052. (org-agenda-error)))
  8053. (hdmarker (org-get-at-bol 'org-hd-marker))
  8054. (buffer (marker-buffer hdmarker))
  8055. (pos (marker-position hdmarker))
  8056. (inhibit-read-only t)
  8057. newhead)
  8058. (org-with-remote-undo buffer
  8059. (with-current-buffer buffer
  8060. (widen)
  8061. (goto-char pos)
  8062. (org-show-context 'agenda)
  8063. (save-excursion
  8064. (and (outline-next-heading)
  8065. (org-flag-heading nil))) ; show the next heading
  8066. (funcall 'org-priority force-direction)
  8067. (end-of-line 1)
  8068. (setq newhead (org-get-heading)))
  8069. (org-agenda-change-all-lines newhead hdmarker)
  8070. (beginning-of-line 1)))))
  8071. ;; FIXME: should fix the tags property of the agenda line.
  8072. (defun org-agenda-set-tags (&optional tag onoff)
  8073. "Set tags for the current headline."
  8074. (interactive)
  8075. (org-agenda-check-no-diary)
  8076. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8077. (call-interactively 'org-change-tag-in-region)
  8078. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8079. (org-agenda-error)))
  8080. (buffer (marker-buffer hdmarker))
  8081. (pos (marker-position hdmarker))
  8082. (inhibit-read-only t)
  8083. newhead)
  8084. (org-with-remote-undo buffer
  8085. (with-current-buffer buffer
  8086. (widen)
  8087. (goto-char pos)
  8088. (save-excursion
  8089. (org-show-context 'agenda))
  8090. (save-excursion
  8091. (and (outline-next-heading)
  8092. (org-flag-heading nil))) ; show the next heading
  8093. (goto-char pos)
  8094. (if tag
  8095. (org-toggle-tag tag onoff)
  8096. (call-interactively 'org-set-tags))
  8097. (end-of-line 1)
  8098. (setq newhead (org-get-heading)))
  8099. (org-agenda-change-all-lines newhead hdmarker)
  8100. (beginning-of-line 1)))))
  8101. (defun org-agenda-set-property ()
  8102. "Set a property for the current headline."
  8103. (interactive)
  8104. (org-agenda-check-no-diary)
  8105. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8106. (org-agenda-error)))
  8107. (buffer (marker-buffer hdmarker))
  8108. (pos (marker-position hdmarker))
  8109. (inhibit-read-only t)
  8110. newhead)
  8111. (org-with-remote-undo buffer
  8112. (with-current-buffer buffer
  8113. (widen)
  8114. (goto-char pos)
  8115. (save-excursion
  8116. (org-show-context 'agenda))
  8117. (save-excursion
  8118. (and (outline-next-heading)
  8119. (org-flag-heading nil))) ; show the next heading
  8120. (goto-char pos)
  8121. (call-interactively 'org-set-property)))))
  8122. (defun org-agenda-set-effort ()
  8123. "Set the effort property for the current headline."
  8124. (interactive)
  8125. (org-agenda-check-no-diary)
  8126. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8127. (org-agenda-error)))
  8128. (buffer (marker-buffer hdmarker))
  8129. (pos (marker-position hdmarker))
  8130. (inhibit-read-only t)
  8131. newhead)
  8132. (org-with-remote-undo buffer
  8133. (with-current-buffer buffer
  8134. (widen)
  8135. (goto-char pos)
  8136. (save-excursion
  8137. (org-show-context 'agenda))
  8138. (save-excursion
  8139. (and (outline-next-heading)
  8140. (org-flag-heading nil))) ; show the next heading
  8141. (goto-char pos)
  8142. (call-interactively 'org-set-effort)
  8143. (end-of-line 1)
  8144. (setq newhead (org-get-heading)))
  8145. (org-agenda-change-all-lines newhead hdmarker))))
  8146. (defun org-agenda-toggle-archive-tag ()
  8147. "Toggle the archive tag for the current entry."
  8148. (interactive)
  8149. (org-agenda-check-no-diary)
  8150. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8151. (org-agenda-error)))
  8152. (buffer (marker-buffer hdmarker))
  8153. (pos (marker-position hdmarker))
  8154. (inhibit-read-only t)
  8155. newhead)
  8156. (org-with-remote-undo buffer
  8157. (with-current-buffer buffer
  8158. (widen)
  8159. (goto-char pos)
  8160. (org-show-context 'agenda)
  8161. (save-excursion
  8162. (and (outline-next-heading)
  8163. (org-flag-heading nil))) ; show the next heading
  8164. (call-interactively 'org-toggle-archive-tag)
  8165. (end-of-line 1)
  8166. (setq newhead (org-get-heading)))
  8167. (org-agenda-change-all-lines newhead hdmarker)
  8168. (beginning-of-line 1))))
  8169. (defun org-agenda-do-date-later (arg)
  8170. (interactive "P")
  8171. (cond
  8172. ((or (equal arg '(16))
  8173. (memq last-command
  8174. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8175. (setq this-command 'org-agenda-date-later-minutes)
  8176. (org-agenda-date-later-minutes 1))
  8177. ((or (equal arg '(4))
  8178. (memq last-command
  8179. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8180. (setq this-command 'org-agenda-date-later-hours)
  8181. (org-agenda-date-later-hours 1))
  8182. (t
  8183. (org-agenda-date-later (prefix-numeric-value arg)))))
  8184. (defun org-agenda-do-date-earlier (arg)
  8185. (interactive "P")
  8186. (cond
  8187. ((or (equal arg '(16))
  8188. (memq last-command
  8189. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8190. (setq this-command 'org-agenda-date-earlier-minutes)
  8191. (org-agenda-date-earlier-minutes 1))
  8192. ((or (equal arg '(4))
  8193. (memq last-command
  8194. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8195. (setq this-command 'org-agenda-date-earlier-hours)
  8196. (org-agenda-date-earlier-hours 1))
  8197. (t
  8198. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8199. (defun org-agenda-date-later (arg &optional what)
  8200. "Change the date of this item to ARG day(s) later."
  8201. (interactive "p")
  8202. (org-agenda-check-type t 'agenda 'timeline)
  8203. (org-agenda-check-no-diary)
  8204. (let* ((marker (or (org-get-at-bol 'org-marker)
  8205. (org-agenda-error)))
  8206. (buffer (marker-buffer marker))
  8207. (pos (marker-position marker))
  8208. cdate today)
  8209. (org-with-remote-undo buffer
  8210. (with-current-buffer buffer
  8211. (widen)
  8212. (goto-char pos)
  8213. (if (not (org-at-timestamp-p))
  8214. (error "Cannot find time stamp"))
  8215. (when (and org-agenda-move-date-from-past-immediately-to-today
  8216. (equal arg 1)
  8217. (or (not what) (eq what 'day))
  8218. (not (save-match-data (org-at-date-range-p))))
  8219. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8220. cdate (calendar-absolute-from-gregorian
  8221. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8222. today (org-today))
  8223. (if (> today cdate)
  8224. ;; immediately shift to today
  8225. (setq arg (- today cdate))))
  8226. (org-timestamp-change arg (or what 'day))
  8227. (when (and (org-at-date-range-p)
  8228. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8229. (let ((end org-last-changed-timestamp))
  8230. (org-timestamp-change arg (or what 'day))
  8231. (setq org-last-changed-timestamp
  8232. (concat org-last-changed-timestamp "--" end)))))
  8233. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8234. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8235. (defun org-agenda-date-earlier (arg &optional what)
  8236. "Change the date of this item to ARG day(s) earlier."
  8237. (interactive "p")
  8238. (org-agenda-date-later (- arg) what))
  8239. (defun org-agenda-date-later-minutes (arg)
  8240. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8241. (interactive "p")
  8242. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8243. (org-agenda-date-later arg 'minute))
  8244. (defun org-agenda-date-earlier-minutes (arg)
  8245. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8246. (interactive "p")
  8247. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8248. (org-agenda-date-earlier arg 'minute))
  8249. (defun org-agenda-date-later-hours (arg)
  8250. "Change the time of this item, in hour steps."
  8251. (interactive "p")
  8252. (org-agenda-date-later arg 'hour))
  8253. (defun org-agenda-date-earlier-hours (arg)
  8254. "Change the time of this item, in hour steps."
  8255. (interactive "p")
  8256. (org-agenda-date-earlier arg 'hour))
  8257. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8258. "Show new date stamp via text properties."
  8259. ;; We use text properties to make this undoable
  8260. (let ((inhibit-read-only t))
  8261. (setq stamp (concat prefix " => " stamp " "))
  8262. (save-excursion
  8263. (goto-char (point-max))
  8264. (while (not (bobp))
  8265. (when (equal marker (org-get-at-bol 'org-marker))
  8266. (org-move-to-column (- (window-width) (length stamp)) t)
  8267. (org-agenda-fix-tags-filter-overlays-at (point))
  8268. (if (featurep 'xemacs)
  8269. ;; Use `duplicable' property to trigger undo recording
  8270. (let ((ex (make-extent nil nil))
  8271. (gl (make-glyph stamp)))
  8272. (set-glyph-face gl 'secondary-selection)
  8273. (set-extent-properties
  8274. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8275. (insert-extent ex (1- (point)) (point-at-eol)))
  8276. (add-text-properties
  8277. (1- (point)) (point-at-eol)
  8278. (list 'display (org-add-props stamp nil
  8279. 'face 'secondary-selection))))
  8280. (beginning-of-line 1))
  8281. (beginning-of-line 0)))))
  8282. (defun org-agenda-date-prompt (arg)
  8283. "Change the date of this item. Date is prompted for, with default today.
  8284. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8285. be used to request time specification in the time stamp."
  8286. (interactive "P")
  8287. (org-agenda-check-type t 'agenda 'timeline)
  8288. (org-agenda-check-no-diary)
  8289. (let* ((marker (or (org-get-at-bol 'org-marker)
  8290. (org-agenda-error)))
  8291. (buffer (marker-buffer marker))
  8292. (pos (marker-position marker)))
  8293. (org-with-remote-undo buffer
  8294. (with-current-buffer buffer
  8295. (widen)
  8296. (goto-char pos)
  8297. (if (not (org-at-timestamp-p t))
  8298. (error "Cannot find time stamp"))
  8299. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8300. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8301. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8302. (defun org-agenda-schedule (arg &optional time)
  8303. "Schedule the item at point.
  8304. ARG is passed through to `org-schedule'."
  8305. (interactive "P")
  8306. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8307. (org-agenda-check-no-diary)
  8308. (let* ((marker (or (org-get-at-bol 'org-marker)
  8309. (org-agenda-error)))
  8310. (type (marker-insertion-type marker))
  8311. (buffer (marker-buffer marker))
  8312. (pos (marker-position marker))
  8313. (org-insert-labeled-timestamps-at-point nil)
  8314. ts)
  8315. (set-marker-insertion-type marker t)
  8316. (org-with-remote-undo buffer
  8317. (with-current-buffer buffer
  8318. (widen)
  8319. (goto-char pos)
  8320. (setq ts (org-schedule arg time)))
  8321. (org-agenda-show-new-time marker ts " S"))
  8322. (message "%s" ts)))
  8323. (defun org-agenda-deadline (arg &optional time)
  8324. "Schedule the item at point.
  8325. ARG is passed through to `org-deadline'."
  8326. (interactive "P")
  8327. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8328. (org-agenda-check-no-diary)
  8329. (let* ((marker (or (org-get-at-bol 'org-marker)
  8330. (org-agenda-error)))
  8331. (buffer (marker-buffer marker))
  8332. (pos (marker-position marker))
  8333. (org-insert-labeled-timestamps-at-point nil)
  8334. ts)
  8335. (org-with-remote-undo buffer
  8336. (with-current-buffer buffer
  8337. (widen)
  8338. (goto-char pos)
  8339. (setq ts (org-deadline arg time)))
  8340. (org-agenda-show-new-time marker ts " D"))
  8341. (message "%s" ts)))
  8342. (defun org-agenda-clock-in (&optional arg)
  8343. "Start the clock on the currently selected item."
  8344. (interactive "P")
  8345. (org-agenda-check-no-diary)
  8346. (if (equal arg '(4))
  8347. (org-clock-in arg)
  8348. (let* ((marker (or (org-get-at-bol 'org-marker)
  8349. (org-agenda-error)))
  8350. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8351. (pos (marker-position marker))
  8352. (col (current-column))
  8353. newhead)
  8354. (org-with-remote-undo (marker-buffer marker)
  8355. (with-current-buffer (marker-buffer marker)
  8356. (widen)
  8357. (goto-char pos)
  8358. (org-show-context 'agenda)
  8359. (org-show-entry)
  8360. (org-cycle-hide-drawers 'children)
  8361. (org-clock-in arg)
  8362. (setq newhead (org-get-heading)))
  8363. (org-agenda-change-all-lines newhead hdmarker))
  8364. (org-move-to-column col))))
  8365. (defun org-agenda-clock-out ()
  8366. "Stop the currently running clock."
  8367. (interactive)
  8368. (unless (marker-buffer org-clock-marker)
  8369. (error "No running clock"))
  8370. (let ((marker (make-marker)) (col (current-column)) newhead)
  8371. (org-with-remote-undo (marker-buffer org-clock-marker)
  8372. (with-current-buffer (marker-buffer org-clock-marker)
  8373. (save-excursion
  8374. (save-restriction
  8375. (widen)
  8376. (goto-char org-clock-marker)
  8377. (org-back-to-heading t)
  8378. (move-marker marker (point))
  8379. (org-clock-out)
  8380. (setq newhead (org-get-heading))))))
  8381. (org-agenda-change-all-lines newhead marker)
  8382. (move-marker marker nil)
  8383. (org-move-to-column col)
  8384. (org-agenda-unmark-clocking-task)))
  8385. (defun org-agenda-clock-cancel (&optional arg)
  8386. "Cancel the currently running clock."
  8387. (interactive "P")
  8388. (unless (marker-buffer org-clock-marker)
  8389. (error "No running clock"))
  8390. (org-with-remote-undo (marker-buffer org-clock-marker)
  8391. (org-clock-cancel)))
  8392. (defun org-agenda-clock-goto ()
  8393. "Jump to the currently clocked in task within the agenda.
  8394. If the currently clocked in task is not listed in the agenda
  8395. buffer, display it in another window."
  8396. (interactive)
  8397. (let (pos)
  8398. (mapc (lambda (o)
  8399. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8400. (setq pos (overlay-start o))))
  8401. (overlays-in (point-min) (point-max)))
  8402. (cond (pos (goto-char pos))
  8403. ;; If the currently clocked entry is not in the agenda
  8404. ;; buffer, we visit it in another window:
  8405. (org-clock-current-task
  8406. (org-switch-to-buffer-other-window (org-clock-goto)))
  8407. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8408. (defun org-agenda-diary-entry-in-org-file ()
  8409. "Make a diary entry in the file `org-agenda-diary-file'."
  8410. (let (d1 d2 char (text "") dp1 dp2)
  8411. (if (equal (buffer-name) "*Calendar*")
  8412. (setq d1 (calendar-cursor-to-date t)
  8413. d2 (car calendar-mark-ring))
  8414. (setq dp1 (get-text-property (point-at-bol) 'day))
  8415. (unless dp1 (error "No date defined in current line"))
  8416. (setq d1 (calendar-gregorian-from-absolute dp1)
  8417. d2 (and (ignore-errors (mark))
  8418. (save-excursion
  8419. (goto-char (mark))
  8420. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8421. (calendar-gregorian-from-absolute dp2))))
  8422. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8423. (setq char (read-char-exclusive))
  8424. (cond
  8425. ((equal char ?d)
  8426. (setq text (read-string "Day entry: "))
  8427. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8428. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8429. ((equal char ?a)
  8430. (setq d1 (list (car d1) (nth 1 d1)
  8431. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8432. (nth 2 d1))))
  8433. (setq text (read-string "Anniversary (use %d to show years): "))
  8434. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8435. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8436. ((equal char ?b)
  8437. (setq text (read-string "Block entry: "))
  8438. (unless (and d1 d2 (not (equal d1 d2)))
  8439. (error "No block of days selected"))
  8440. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8441. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8442. ((equal char ?j)
  8443. (org-switch-to-buffer-other-window
  8444. (find-file-noselect org-agenda-diary-file))
  8445. (require 'org-datetree)
  8446. (org-datetree-find-date-create d1)
  8447. (org-reveal t))
  8448. (t (error "Invalid selection character `%c'" char)))))
  8449. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8450. "Where in `org-agenda-diary-file' should new entries be added?
  8451. Valid values:
  8452. date-tree in the date tree, as child of the date
  8453. top-level as top-level entries at the end of the file."
  8454. :group 'org-agenda
  8455. :type '(choice
  8456. (const :tag "in a date tree" date-tree)
  8457. (const :tag "as top level at end of file" top-level)))
  8458. (defcustom org-agenda-insert-diary-extract-time nil
  8459. "Non-nil means extract any time specification from the diary entry."
  8460. :group 'org-agenda
  8461. :version "24.1"
  8462. :type 'boolean)
  8463. (defcustom org-agenda-bulk-mark-char ">"
  8464. "A single-character string to be used as the bulk mark."
  8465. :group 'org-agenda
  8466. :version "24.1"
  8467. :type 'string)
  8468. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8469. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8470. If TEXT is not empty, it will become the headline of the new entry, and
  8471. the resulting entry will not be shown. When TEXT is empty, switch to
  8472. `org-agenda-diary-file' and let the user finish the entry there."
  8473. (let ((cw (current-window-configuration)))
  8474. (org-switch-to-buffer-other-window
  8475. (find-file-noselect org-agenda-diary-file))
  8476. (widen)
  8477. (goto-char (point-min))
  8478. (cond
  8479. ((eq type 'anniversary)
  8480. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8481. (progn
  8482. (or (org-at-heading-p t)
  8483. (progn
  8484. (outline-next-heading)
  8485. (insert "* Anniversaries\n\n")
  8486. (beginning-of-line -1)))))
  8487. (outline-next-heading)
  8488. (org-back-over-empty-lines)
  8489. (backward-char 1)
  8490. (insert "\n")
  8491. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8492. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8493. ((eq type 'day)
  8494. (let ((org-prefix-has-time t)
  8495. (org-agenda-time-leading-zero t)
  8496. fmt time time2)
  8497. (if org-agenda-insert-diary-extract-time
  8498. ;; Use org-agenda-format-item to parse text for a time-range and
  8499. ;; remove it. FIXME: This is a hack, we should refactor
  8500. ;; that function to make time extraction available separately
  8501. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8502. time (get-text-property 0 'time fmt)
  8503. time2 (if (> (length time) 0)
  8504. ;; split-string removes trailing ...... if
  8505. ;; no end time given. First space
  8506. ;; separates time from date.
  8507. (concat " " (car (split-string time "\\.")))
  8508. nil)
  8509. text (get-text-property 0 'txt fmt)))
  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. nil nil nil nil time2))
  8518. (end-of-line 0))
  8519. ((eq type 'block)
  8520. (if (> (calendar-absolute-from-gregorian d1)
  8521. (calendar-absolute-from-gregorian d2))
  8522. (setq d1 (prog1 d2 (setq d2 d1))))
  8523. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8524. (org-agenda-insert-diary-as-top-level text)
  8525. (require 'org-datetree)
  8526. (org-datetree-find-date-create d1)
  8527. (org-agenda-insert-diary-make-new-entry text))
  8528. (org-insert-time-stamp (org-time-from-absolute
  8529. (calendar-absolute-from-gregorian d1)))
  8530. (insert "--")
  8531. (org-insert-time-stamp (org-time-from-absolute
  8532. (calendar-absolute-from-gregorian d2)))
  8533. (end-of-line 0)))
  8534. (if (string-match "\\S-" text)
  8535. (progn
  8536. (set-window-configuration cw)
  8537. (message "%s entry added to %s"
  8538. (capitalize (symbol-name type))
  8539. (abbreviate-file-name org-agenda-diary-file)))
  8540. (org-reveal t)
  8541. (message "Please finish entry here"))))
  8542. (defun org-agenda-insert-diary-as-top-level (text)
  8543. "Make new entry as a top-level entry at the end of the file.
  8544. Add TEXT as headline, and position the cursor in the second line so that
  8545. a timestamp can be added there."
  8546. (widen)
  8547. (goto-char (point-max))
  8548. (or (bolp) (insert "\n"))
  8549. (insert "* " text "\n")
  8550. (if org-adapt-indentation (org-indent-to-column 2)))
  8551. (defun org-agenda-insert-diary-make-new-entry (text)
  8552. "Make new entry as last child of current entry.
  8553. Add TEXT as headline, and position the cursor in the second line so that
  8554. a timestamp can be added there."
  8555. (let ((org-show-following-heading t)
  8556. (org-show-siblings t)
  8557. (org-show-hierarchy-above t)
  8558. (org-show-entry-below t)
  8559. col)
  8560. (outline-next-heading)
  8561. (org-back-over-empty-lines)
  8562. (or (looking-at "[ \t]*$")
  8563. (progn (insert "\n") (backward-char 1)))
  8564. (org-insert-heading nil t)
  8565. (org-do-demote)
  8566. (setq col (current-column))
  8567. (insert text "\n")
  8568. (if org-adapt-indentation (org-indent-to-column col))
  8569. (let ((org-show-following-heading t)
  8570. (org-show-siblings t)
  8571. (org-show-hierarchy-above t)
  8572. (org-show-entry-below t))
  8573. (org-show-context))))
  8574. (defun org-agenda-diary-entry ()
  8575. "Make a diary entry, like the `i' command from the calendar.
  8576. All the standard commands work: block, weekly etc.
  8577. When `org-agenda-diary-file' points to a file,
  8578. `org-agenda-diary-entry-in-org-file' is called instead to create
  8579. entries in that Org-mode file."
  8580. (interactive)
  8581. (if (not (eq org-agenda-diary-file 'diary-file))
  8582. (org-agenda-diary-entry-in-org-file)
  8583. (require 'diary-lib)
  8584. (let* ((char (progn
  8585. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8586. (read-char-exclusive)))
  8587. (cmd (cdr (assoc char
  8588. '((?d . insert-diary-entry)
  8589. (?w . insert-weekly-diary-entry)
  8590. (?m . insert-monthly-diary-entry)
  8591. (?y . insert-yearly-diary-entry)
  8592. (?a . insert-anniversary-diary-entry)
  8593. (?b . insert-block-diary-entry)
  8594. (?c . insert-cyclic-diary-entry)))))
  8595. (oldf (symbol-function 'calendar-cursor-to-date))
  8596. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8597. (point (point))
  8598. (mark (or (mark t) (point))))
  8599. (unless cmd
  8600. (error "No command associated with <%c>" char))
  8601. (unless (and (get-text-property point 'day)
  8602. (or (not (equal ?b char))
  8603. (get-text-property mark 'day)))
  8604. (error "Don't know which date to use for diary entry"))
  8605. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8606. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8607. (let ((calendar-mark-ring
  8608. (list (calendar-gregorian-from-absolute
  8609. (or (get-text-property mark 'day)
  8610. (get-text-property point 'day))))))
  8611. (unwind-protect
  8612. (progn
  8613. (fset 'calendar-cursor-to-date
  8614. (lambda (&optional error dummy)
  8615. (calendar-gregorian-from-absolute
  8616. (get-text-property point 'day))))
  8617. (call-interactively cmd))
  8618. (fset 'calendar-cursor-to-date oldf))))))
  8619. (defun org-agenda-execute-calendar-command (cmd)
  8620. "Execute a calendar command from the agenda with date from cursor."
  8621. (org-agenda-check-type t 'agenda 'timeline)
  8622. (require 'diary-lib)
  8623. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8624. (error "Don't know which date to use for the calendar command"))
  8625. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8626. (point (point))
  8627. (date (calendar-gregorian-from-absolute
  8628. (get-text-property point 'day)))
  8629. ;; the following 2 vars are needed in the calendar
  8630. (displayed-month (car date))
  8631. (displayed-year (nth 2 date)))
  8632. (unwind-protect
  8633. (progn
  8634. (fset 'calendar-cursor-to-date
  8635. (lambda (&optional error dummy)
  8636. (calendar-gregorian-from-absolute
  8637. (get-text-property point 'day))))
  8638. (call-interactively cmd))
  8639. (fset 'calendar-cursor-to-date oldf))))
  8640. (defun org-agenda-phases-of-moon ()
  8641. "Display the phases of the moon for the 3 months around the cursor date."
  8642. (interactive)
  8643. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8644. (defun org-agenda-holidays ()
  8645. "Display the holidays for the 3 months around the cursor date."
  8646. (interactive)
  8647. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8648. (defvar calendar-longitude) ; defined in calendar.el
  8649. (defvar calendar-latitude) ; defined in calendar.el
  8650. (defvar calendar-location-name) ; defined in calendar.el
  8651. (defun org-agenda-sunrise-sunset (arg)
  8652. "Display sunrise and sunset for the cursor date.
  8653. Latitude and longitude can be specified with the variables
  8654. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8655. argument, latitude and longitude will be prompted for."
  8656. (interactive "P")
  8657. (require 'solar)
  8658. (let ((calendar-longitude (if arg nil calendar-longitude))
  8659. (calendar-latitude (if arg nil calendar-latitude))
  8660. (calendar-location-name
  8661. (if arg "the given coordinates" calendar-location-name)))
  8662. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8663. (defun org-agenda-goto-calendar ()
  8664. "Open the Emacs calendar with the date at the cursor."
  8665. (interactive)
  8666. (org-agenda-check-type t 'agenda 'timeline)
  8667. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8668. (error "Don't know which date to open in calendar")))
  8669. (date (calendar-gregorian-from-absolute day))
  8670. (calendar-move-hook nil)
  8671. (calendar-view-holidays-initially-flag nil)
  8672. (calendar-view-diary-initially-flag nil))
  8673. (calendar)
  8674. (calendar-goto-date date)))
  8675. ;;;###autoload
  8676. (defun org-calendar-goto-agenda ()
  8677. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8678. This is a command that has to be installed in `calendar-mode-map'."
  8679. (interactive)
  8680. (org-agenda-list nil (calendar-absolute-from-gregorian
  8681. (calendar-cursor-to-date))
  8682. nil))
  8683. (defun org-agenda-convert-date ()
  8684. (interactive)
  8685. (org-agenda-check-type t 'agenda 'timeline)
  8686. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8687. date s)
  8688. (unless day
  8689. (error "Don't know which date to convert"))
  8690. (setq date (calendar-gregorian-from-absolute day))
  8691. (setq s (concat
  8692. "Gregorian: " (calendar-date-string date) "\n"
  8693. "ISO: " (calendar-iso-date-string date) "\n"
  8694. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8695. "Julian: " (calendar-julian-date-string date) "\n"
  8696. "Astron. JD: " (calendar-astro-date-string date)
  8697. " (Julian date number at noon UTC)\n"
  8698. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8699. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8700. "French: " (calendar-french-date-string date) "\n"
  8701. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8702. "Mayan: " (calendar-mayan-date-string date) "\n"
  8703. "Coptic: " (calendar-coptic-date-string date) "\n"
  8704. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8705. "Persian: " (calendar-persian-date-string date) "\n"
  8706. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8707. (with-output-to-temp-buffer "*Dates*"
  8708. (princ s))
  8709. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8710. ;;; Bulk commands
  8711. (defun org-agenda-bulk-marked-p ()
  8712. (eq (get-char-property (point-at-bol) 'type)
  8713. 'org-marked-entry-overlay))
  8714. (defun org-agenda-bulk-mark (&optional arg)
  8715. "Mark the entry at point for future bulk action."
  8716. (interactive "p")
  8717. (dotimes (i (or arg 1))
  8718. (unless (org-get-at-bol 'org-agenda-diary-link)
  8719. (let* ((m (org-get-at-bol 'org-hd-marker))
  8720. ov)
  8721. (unless (org-agenda-bulk-marked-p)
  8722. (unless m (error "Nothing to mark at point"))
  8723. (push m org-agenda-bulk-marked-entries)
  8724. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8725. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8726. (org-get-todo-face "TODO")
  8727. 'evaporate)
  8728. (overlay-put ov 'type 'org-marked-entry-overlay))
  8729. (beginning-of-line 2)
  8730. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8731. (beginning-of-line 2))
  8732. (message "%d entries marked for bulk action"
  8733. (length org-agenda-bulk-marked-entries))))))
  8734. (defun org-agenda-bulk-mark-all ()
  8735. "Mark all entries for future agenda bulk action."
  8736. (interactive)
  8737. (org-agenda-bulk-mark-regexp "."))
  8738. (defun org-agenda-bulk-mark-regexp (regexp)
  8739. "Mark entries matching REGEXP for future agenda bulk action."
  8740. (interactive "sMark entries matching regexp: ")
  8741. (let ((entries-marked 0))
  8742. (save-excursion
  8743. (goto-char (point-min))
  8744. (goto-char (next-single-property-change (point) 'txt))
  8745. (while (re-search-forward regexp nil t)
  8746. (when (string-match regexp (get-text-property (point) 'txt))
  8747. (setq entries-marked (1+ entries-marked))
  8748. (call-interactively 'org-agenda-bulk-mark))))
  8749. (if (not entries-marked)
  8750. (message "No entry matching this regexp."))))
  8751. (defun org-agenda-bulk-unmark (&optional arg)
  8752. "Unmark the entry at point for future bulk action."
  8753. (interactive "P")
  8754. (if arg
  8755. (org-agenda-bulk-unmark-all)
  8756. (cond ((org-agenda-bulk-marked-p)
  8757. (org-agenda-bulk-remove-overlays
  8758. (point-at-bol) (+ 2 (point-at-bol)))
  8759. (setq org-agenda-bulk-marked-entries
  8760. (delete (org-get-at-bol 'org-hd-marker)
  8761. org-agenda-bulk-marked-entries))
  8762. (beginning-of-line 2)
  8763. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8764. (beginning-of-line 2))
  8765. (message "%d entries left marked for bulk action"
  8766. (length org-agenda-bulk-marked-entries)))
  8767. (t (message "No entry to unmark here")))))
  8768. (defun org-agenda-bulk-toggle ()
  8769. "Toggle marking the entry at point for bulk action."
  8770. (interactive)
  8771. (if (org-agenda-bulk-marked-p)
  8772. (org-agenda-bulk-unmark)
  8773. (org-agenda-bulk-mark)))
  8774. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8775. "Remove the mark overlays between BEG and END in the agenda buffer.
  8776. BEG and END default to the buffer limits.
  8777. This only removes the overlays, it does not remove the markers
  8778. from the list in `org-agenda-bulk-marked-entries'."
  8779. (interactive)
  8780. (mapc (lambda (ov)
  8781. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8782. (delete-overlay ov)))
  8783. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8784. (defun org-agenda-bulk-unmark-all ()
  8785. "Remove all marks in the agenda buffer.
  8786. This will remove the markers and the overlays."
  8787. (interactive)
  8788. (if (null org-agenda-bulk-marked-entries)
  8789. (message "No entry to unmark")
  8790. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8791. (setq org-agenda-bulk-marked-entries nil)
  8792. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8793. (defcustom org-agenda-persistent-marks nil
  8794. "Non-nil means marked items will stay marked after a bulk action.
  8795. You can toggle this interactively by typing `p' when prompted for a
  8796. bulk action."
  8797. :group 'org-agenda
  8798. :version "24.1"
  8799. :type 'boolean)
  8800. (defun org-agenda-bulk-action (&optional arg)
  8801. "Execute an remote-editing action on all marked entries.
  8802. The prefix arg is passed through to the command if possible."
  8803. (interactive "P")
  8804. ;; Make sure we have markers, and only valid ones
  8805. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8806. (mapc
  8807. (lambda (m)
  8808. (unless (and (markerp m)
  8809. (marker-buffer m)
  8810. (buffer-live-p (marker-buffer m))
  8811. (marker-position m))
  8812. (error "Marker %s for bulk command is invalid" m)))
  8813. org-agenda-bulk-marked-entries)
  8814. ;; Prompt for the bulk command
  8815. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8816. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8817. "[S]catter [f]unction "
  8818. (when org-agenda-bulk-custom-functions
  8819. (concat " Custom: ["
  8820. (mapconcat (lambda(f) (char-to-string (car f)))
  8821. org-agenda-bulk-custom-functions "")
  8822. "]"))))
  8823. (catch 'exit
  8824. (let* ((action (read-char-exclusive))
  8825. (org-log-refile (if org-log-refile 'time nil))
  8826. (entries (reverse org-agenda-bulk-marked-entries))
  8827. (org-overriding-default-time
  8828. (if (get-text-property (point) 'org-agenda-date-header)
  8829. (org-get-cursor-date)))
  8830. redo-at-end
  8831. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8832. (cond
  8833. ((equal action ?p)
  8834. (let ((org-agenda-persistent-marks
  8835. (not org-agenda-persistent-marks)))
  8836. (org-agenda-bulk-action)
  8837. (throw 'exit nil)))
  8838. ((equal action ?$)
  8839. (setq cmd '(org-agenda-archive)))
  8840. ((equal action ?A)
  8841. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8842. ((member action '(?r ?w))
  8843. (setq rfloc (org-refile-get-location
  8844. "Refile to"
  8845. (marker-buffer (car entries))
  8846. org-refile-allow-creating-parent-nodes))
  8847. (if (nth 3 rfloc)
  8848. (setcar (nthcdr 3 rfloc)
  8849. (move-marker (make-marker) (nth 3 rfloc)
  8850. (or (get-file-buffer (nth 1 rfloc))
  8851. (find-buffer-visiting (nth 1 rfloc))
  8852. (error "This should not happen")))))
  8853. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8854. redo-at-end t))
  8855. ((equal action ?t)
  8856. (setq state (org-icompleting-read
  8857. "Todo state: "
  8858. (with-current-buffer (marker-buffer (car entries))
  8859. (mapcar 'list org-todo-keywords-1))))
  8860. (setq cmd `(let ((org-inhibit-blocking t)
  8861. (org-inhibit-logging 'note))
  8862. (org-agenda-todo ,state))))
  8863. ((memq action '(?- ?+))
  8864. (setq tag (org-icompleting-read
  8865. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8866. (with-current-buffer (marker-buffer (car entries))
  8867. (delq nil
  8868. (mapcar (lambda (x)
  8869. (if (stringp (car x)) x)) org-tag-alist)))))
  8870. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8871. ((memq action '(?s ?d))
  8872. (let* ((time
  8873. (unless arg
  8874. (org-read-date
  8875. nil nil nil
  8876. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8877. org-overriding-default-time)))
  8878. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8879. (setq cmd `(eval '(,c1 arg ,time)))))
  8880. ((equal action ?S)
  8881. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8882. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8883. (let ((days (read-number
  8884. (format "Scatter tasks across how many %sdays: "
  8885. (if arg "week" "")) 7)))
  8886. (setq cmd
  8887. `(let ((distance (1+ (random ,days))))
  8888. (if arg
  8889. (let ((dist distance)
  8890. (day-of-week
  8891. (calendar-day-of-week
  8892. (calendar-gregorian-from-absolute (org-today)))))
  8893. (dotimes (i (1+ dist))
  8894. (while (member day-of-week org-agenda-weekend-days)
  8895. (incf distance)
  8896. (incf day-of-week)
  8897. (if (= day-of-week 7)
  8898. (setq day-of-week 0)))
  8899. (incf day-of-week)
  8900. (if (= day-of-week 7)
  8901. (setq day-of-week 0)))))
  8902. ;; silently fail when try to replan a sexp entry
  8903. (condition-case nil
  8904. (let* ((date (calendar-gregorian-from-absolute
  8905. (+ (org-today) distance)))
  8906. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8907. (nth 2 date))))
  8908. (org-agenda-schedule nil time))
  8909. (error nil)))))))
  8910. ((assoc action org-agenda-bulk-custom-functions)
  8911. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8912. redo-at-end t))
  8913. ((equal action ?f)
  8914. (setq cmd (list (intern
  8915. (org-icompleting-read "Function: "
  8916. obarray 'fboundp t nil nil)))))
  8917. (t (error "Invalid bulk action")))
  8918. ;; Sort the markers, to make sure that parents are handled before children
  8919. (setq entries (sort entries
  8920. (lambda (a b)
  8921. (cond
  8922. ((equal (marker-buffer a) (marker-buffer b))
  8923. (< (marker-position a) (marker-position b)))
  8924. (t
  8925. (string< (buffer-name (marker-buffer a))
  8926. (buffer-name (marker-buffer b))))))))
  8927. ;; Now loop over all markers and apply cmd
  8928. (while (setq e (pop entries))
  8929. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8930. (if (not pos)
  8931. (progn (message "Skipping removed entry at %s" e)
  8932. (setq cntskip (1+ cntskip)))
  8933. (goto-char pos)
  8934. (let (org-loop-over-headlines-in-active-region)
  8935. (eval cmd))
  8936. (setq cnt (1+ cnt))))
  8937. (when redo-at-end (org-agenda-redo))
  8938. (unless org-agenda-persistent-marks
  8939. (org-agenda-bulk-unmark-all))
  8940. (message "Acted on %d entries%s%s"
  8941. cnt
  8942. (if (= cntskip 0)
  8943. ""
  8944. (format ", skipped %d (disappeared before their turn)"
  8945. cntskip))
  8946. (if (not org-agenda-persistent-marks)
  8947. "" " (kept marked)"))))))
  8948. (defun org-agenda-capture (&optional with-time)
  8949. "Call `org-capture' with the date at point.
  8950. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  8951. current HH:MM time."
  8952. (interactive "P")
  8953. (if (not (eq major-mode 'org-agenda-mode))
  8954. (user-error "You cannot do this outside of agenda buffers")
  8955. (let ((org-overriding-default-time
  8956. (org-get-cursor-date (equal with-time 1))))
  8957. (call-interactively 'org-capture))))
  8958. ;;; Flagging notes
  8959. (defun org-agenda-show-the-flagging-note ()
  8960. "Display the flagging note in the other window.
  8961. When called a second time in direct sequence, offer to remove the FLAGGING
  8962. tag and (if present) the flagging note."
  8963. (interactive)
  8964. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8965. (win (selected-window))
  8966. note heading newhead)
  8967. (unless hdmarker
  8968. (error "No linked entry at point"))
  8969. (if (and (eq this-command last-command)
  8970. (y-or-n-p "Unflag and remove any flagging note? "))
  8971. (progn
  8972. (org-agenda-remove-flag hdmarker)
  8973. (let ((win (get-buffer-window "*Flagging Note*")))
  8974. (and win (delete-window win)))
  8975. (message "Entry unflagged"))
  8976. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8977. (unless note
  8978. (error "No flagging note"))
  8979. (org-kill-new note)
  8980. (org-switch-to-buffer-other-window "*Flagging Note*")
  8981. (erase-buffer)
  8982. (insert note)
  8983. (goto-char (point-min))
  8984. (while (re-search-forward "\\\\n" nil t)
  8985. (replace-match "\n" t t))
  8986. (goto-char (point-min))
  8987. (select-window win)
  8988. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8989. (defun org-agenda-remove-flag (marker)
  8990. "Remove the FLAGGED tag and any flagging note in the entry."
  8991. (let (newhead)
  8992. (org-with-point-at marker
  8993. (org-toggle-tag "FLAGGED" 'off)
  8994. (org-entry-delete nil "THEFLAGGINGNOTE")
  8995. (setq newhead (org-get-heading)))
  8996. (org-agenda-change-all-lines newhead marker)
  8997. (message "Entry unflagged")))
  8998. (defun org-agenda-get-any-marker (&optional pos)
  8999. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9000. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9001. ;;; Appointment reminders
  9002. (defvar appt-time-msg-list) ; defined in appt.el
  9003. ;;;###autoload
  9004. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9005. "Activate appointments found in `org-agenda-files'.
  9006. With a \\[universal-argument] prefix, refresh the list of
  9007. appointments.
  9008. If FILTER is t, interactively prompt the user for a regular
  9009. expression, and filter out entries that don't match it.
  9010. If FILTER is a string, use this string as a regular expression
  9011. for filtering entries out.
  9012. If FILTER is a function, filter out entries against which
  9013. calling the function returns nil. This function takes one
  9014. argument: an entry from `org-agenda-get-day-entries'.
  9015. FILTER can also be an alist with the car of each cell being
  9016. either 'headline or 'category. For example:
  9017. '((headline \"IMPORTANT\")
  9018. (category \"Work\"))
  9019. will only add headlines containing IMPORTANT or headlines
  9020. belonging to the \"Work\" category.
  9021. ARGS are symbols indicating what kind of entries to consider.
  9022. By default `org-agenda-to-appt' will use :deadline, :scheduled
  9023. and :timestamp entries. See the docstring of `org-diary' for
  9024. details and examples.
  9025. If an entry has a APPT_WARNTIME property, its value will be used
  9026. to override `appt-message-warning-time'."
  9027. (interactive "P")
  9028. (if refresh (setq appt-time-msg-list nil))
  9029. (if (eq filter t)
  9030. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9031. (let* ((cnt 0) ; count added events
  9032. (scope (or args '(:deadline :scheduled :timestamp)))
  9033. (org-agenda-new-buffers nil)
  9034. (org-deadline-warning-days 0)
  9035. ;; Do not use `org-today' here because appt only takes
  9036. ;; time and without date as argument, so it may pass wrong
  9037. ;; information otherwise
  9038. (today (org-date-to-gregorian
  9039. (time-to-days (current-time))))
  9040. (org-agenda-restrict nil)
  9041. (files (org-agenda-files 'unrestricted)) entries file
  9042. (org-agenda-buffer nil))
  9043. ;; Get all entries which may contain an appt
  9044. (org-agenda-prepare-buffers files)
  9045. (while (setq file (pop files))
  9046. (setq entries
  9047. (delq nil
  9048. (append entries
  9049. (apply 'org-agenda-get-day-entries
  9050. file today scope)))))
  9051. ;; Map thru entries and find if we should filter them out
  9052. (mapc
  9053. (lambda(x)
  9054. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  9055. (cat (get-text-property 1 'org-category x))
  9056. (tod (get-text-property 1 'time-of-day x))
  9057. (ok (or (null filter)
  9058. (and (stringp filter) (string-match filter evt))
  9059. (and (functionp filter) (funcall filter x))
  9060. (and (listp filter)
  9061. (let ((cat-filter (cadr (assoc 'category filter)))
  9062. (evt-filter (cadr (assoc 'headline filter))))
  9063. (or (and (stringp cat-filter)
  9064. (string-match cat-filter cat))
  9065. (and (stringp evt-filter)
  9066. (string-match evt-filter evt)))))))
  9067. (wrn (get-text-property 1 'warntime x)))
  9068. ;; FIXME: Shall we remove text-properties for the appt text?
  9069. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9070. (when (and ok tod)
  9071. (setq tod (concat "00" (number-to-string tod))
  9072. tod (when (string-match
  9073. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9074. (concat (match-string 1 tod) ":"
  9075. (match-string 2 tod))))
  9076. (if (version< emacs-version "23.3")
  9077. (appt-add tod evt)
  9078. (appt-add tod evt wrn))
  9079. (setq cnt (1+ cnt))))) entries)
  9080. (org-release-buffers org-agenda-new-buffers)
  9081. (if (eq cnt 0)
  9082. (message "No event to add")
  9083. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9084. (defun org-agenda-todayp (date)
  9085. "Does DATE mean today, when considering `org-extend-today-until'?"
  9086. (let ((today (org-today))
  9087. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9088. date)))
  9089. (eq date today)))
  9090. (defun org-agenda-todo-yesterday (&optional arg)
  9091. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9092. (interactive "P")
  9093. (let* ((hour (third (decode-time
  9094. (org-current-time))))
  9095. (org-extend-today-until (1+ hour)))
  9096. (org-agenda-todo arg)))
  9097. (provide 'org-agenda)
  9098. ;;; org-agenda.el ends here