org-agenda.el 299 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.01trans
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-ndays)
  217. (integer :value 1))
  218. (list :tag "Fixed starting date"
  219. (const org-agenda-start-day)
  220. (string :value "2007-11-01"))
  221. (list :tag "Start on day of week"
  222. (const org-agenda-start-on-weekday)
  223. (choice :value 1
  224. (const :tag "Today" nil)
  225. (integer :tag "Weekday No.")))
  226. (list :tag "Include data from diary"
  227. (const org-agenda-include-diary)
  228. (boolean))
  229. (list :tag "Deadline Warning days"
  230. (const org-deadline-warning-days)
  231. (integer :value 1))
  232. (list :tag "Tags filter preset"
  233. (const org-agenda-filter-preset)
  234. (list
  235. (const :format "" quote)
  236. (repeat
  237. (string :tag "+tag or -tag"))))
  238. (list :tag "Set daily/weekly entry types"
  239. (const org-agenda-entry-types)
  240. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  241. (const :deadline)
  242. (const :scheduled)
  243. (const :timestamp)
  244. (const :sexp)))
  245. (list :tag "Standard skipping condition"
  246. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  247. (const org-agenda-skip-function)
  248. (list
  249. (const :format "" quote)
  250. (list
  251. (choice
  252. :tag "Skipping range"
  253. (const :tag "Skip entry" org-agenda-skip-entry-if)
  254. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  255. (repeat :inline t :tag "Conditions for skipping"
  256. (choice
  257. :tag "Condition type"
  258. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  259. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  260. (list :tag "TODO state is" :inline t
  261. (const 'todo)
  262. (choice
  263. (const :tag "any not-done state" 'todo)
  264. (const :tag "any done state" 'done)
  265. (const :tag "any state" 'any)
  266. (list :tag "Keyword list"
  267. (const :format "" quote)
  268. (repeat (string :tag "Keyword")))))
  269. (list :tag "TODO state is not" :inline t
  270. (const 'nottodo)
  271. (choice
  272. (const :tag "any not-done state" 'todo)
  273. (const :tag "any done state" 'done)
  274. (const :tag "any state" 'any)
  275. (list :tag "Keyword list"
  276. (const :format "" quote)
  277. (repeat (string :tag "Keyword")))))
  278. (const :tag "scheduled" 'scheduled)
  279. (const :tag "not scheduled" 'notscheduled)
  280. (const :tag "deadline" 'deadline)
  281. (const :tag "no deadline" 'notdeadline)
  282. (const :tag "timestamp" 'timestamp)
  283. (const :tag "no timestamp" 'nottimestamp))))))
  284. (list :tag "Non-standard skipping condition"
  285. :value (org-agenda-skip-function)
  286. (const org-agenda-skip-function)
  287. (sexp :tag "Function or form (quoted!)"))
  288. (list :tag "Any variable"
  289. (variable :tag "Variable")
  290. (sexp :tag "Value (sexp)"))))
  291. "Selection of examples for agenda command settings.
  292. This will be spliced into the custom type of
  293. `org-agenda-custom-commands'.")
  294. (defcustom org-agenda-custom-commands nil
  295. "Custom commands for the agenda.
  296. These commands will be offered on the splash screen displayed by the
  297. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  298. (key desc type match settings files)
  299. key The key (one or more characters as a string) to be associated
  300. with the command.
  301. desc A description of the command, when omitted or nil, a default
  302. description is built using MATCH.
  303. type The command type, any of the following symbols:
  304. agenda The daily/weekly agenda.
  305. todo Entries with a specific TODO keyword, in all agenda files.
  306. search Entries containing search words entry or headline.
  307. tags Tags/Property/TODO match in all agenda files.
  308. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  309. todo-tree Sparse tree of specific TODO keyword in *current* file.
  310. tags-tree Sparse tree with all tags matches in *current* file.
  311. occur-tree Occur sparse tree for *current* file.
  312. ... A user-defined function.
  313. match What to search for:
  314. - a single keyword for TODO keyword searches
  315. - a tags match expression for tags searches
  316. - a word search expression for text searches.
  317. - a regular expression for occur searches
  318. For all other commands, this should be the empty string.
  319. settings A list of option settings, similar to that in a let form, so like
  320. this: ((opt1 val1) (opt2 val2) ...). The values will be
  321. evaluated at the moment of execution, so quote them when needed.
  322. files A list of files file to write the produced agenda buffer to
  323. with the command `org-store-agenda-views'.
  324. If a file name ends in \".html\", an HTML version of the buffer
  325. is written out. If it ends in \".ps\", a postscript version is
  326. produced. Otherwise, only the plain text is written to the file.
  327. You can also define a set of commands, to create a composite agenda buffer.
  328. In this case, an entry looks like this:
  329. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  330. where
  331. desc A description string to be displayed in the dispatcher menu.
  332. cmd An agenda command, similar to the above. However, tree commands
  333. are no allowed, but instead you can get agenda and global todo list.
  334. So valid commands for a set are:
  335. (agenda \"\" settings)
  336. (alltodo \"\" settings)
  337. (stuck \"\" settings)
  338. (todo \"match\" settings files)
  339. (search \"match\" settings files)
  340. (tags \"match\" settings files)
  341. (tags-todo \"match\" settings files)
  342. Each command can carry a list of options, and another set of options can be
  343. given for the whole set of commands. Individual command options take
  344. precedence over the general options.
  345. When using several characters as key to a command, the first characters
  346. are prefix commands. For the dispatcher to display useful information, you
  347. should provide a description for the prefix, like
  348. (setq org-agenda-custom-commands
  349. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  350. (\"hl\" tags \"+HOME+Lisa\")
  351. (\"hp\" tags \"+HOME+Peter\")
  352. (\"hk\" tags \"+HOME+Kim\")))"
  353. :group 'org-agenda-custom-commands
  354. :type `(repeat
  355. (choice :value ("x" "Describe command here" tags "" nil)
  356. (list :tag "Single command"
  357. (string :tag "Access Key(s) ")
  358. (option (string :tag "Description"))
  359. (choice
  360. (const :tag "Agenda" agenda)
  361. (const :tag "TODO list" alltodo)
  362. (const :tag "Search words" search)
  363. (const :tag "Stuck projects" stuck)
  364. (const :tag "Tags/Property match (all agenda files)" tags)
  365. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  366. (const :tag "TODO keyword search (all agenda files)" todo)
  367. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  368. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  369. (const :tag "Occur tree (current buffer)" occur-tree)
  370. (sexp :tag "Other, user-defined function"))
  371. (string :tag "Match (only for some commands)")
  372. ,org-agenda-custom-commands-local-options
  373. (option (repeat :tag "Export" (file :tag "Export to"))))
  374. (list :tag "Command series, all agenda files"
  375. (string :tag "Access Key(s)")
  376. (string :tag "Description ")
  377. (repeat :tag "Component"
  378. (choice
  379. (list :tag "Agenda"
  380. (const :format "" agenda)
  381. (const :tag "" :format "" "")
  382. ,org-agenda-custom-commands-local-options)
  383. (list :tag "TODO list (all keywords)"
  384. (const :format "" alltodo)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "Search words"
  388. (const :format "" search)
  389. (string :tag "Match")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Stuck projects"
  392. (const :format "" stuck)
  393. (const :tag "" :format "" "")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Tags search"
  396. (const :format "" tags)
  397. (string :tag "Match")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search, TODO entries only"
  400. (const :format "" tags-todo)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "TODO keyword search"
  404. (const :format "" todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "Other, user-defined function"
  408. (symbol :tag "function")
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)))
  411. (repeat :tag "Settings for entire command set"
  412. (list (variable :tag "Any variable")
  413. (sexp :tag "Value")))
  414. (option (repeat :tag "Export" (file :tag "Export to"))))
  415. (cons :tag "Prefix key documentation"
  416. (string :tag "Access Key(s)")
  417. (string :tag "Description ")))))
  418. (defcustom org-agenda-query-register ?o
  419. "The register holding the current query string.
  420. The purpose of this is that if you construct a query string interactively,
  421. you can then use it to define a custom command."
  422. :group 'org-agenda-custom-commands
  423. :type 'character)
  424. (defcustom org-stuck-projects
  425. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  426. "How to identify stuck projects.
  427. This is a list of four items:
  428. 1. A tags/todo/property matcher string that is used to identify a project.
  429. See the manual for a description of tag and property searches.
  430. The entire tree below a headline matched by this is considered one project.
  431. 2. A list of TODO keywords identifying non-stuck projects.
  432. If the project subtree contains any headline with one of these todo
  433. keywords, the project is considered to be not stuck. If you specify
  434. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  435. 3. A list of tags identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these tags,
  437. the project is considered to be not stuck. If you specify \"*\" as
  438. a tag, any tag will mark the project unstuck. Note that this is about
  439. the explicit presence of a tag somewhere in the subtree, inherited
  440. tags to not count here. If inherited tags make a project not stuck,
  441. use \"-TAG\" in the tags part of the matcher under (1.) above.
  442. 4. An arbitrary regular expression matching non-stuck projects.
  443. If the project turns out to be not stuck, search continues also in the
  444. subtree to see if any of the subtasks have project status.
  445. See also the variable `org-tags-match-list-sublevels' which applies
  446. to projects matched by this search as well.
  447. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  448. or `C-c a #' to produce the list."
  449. :group 'org-agenda-custom-commands
  450. :type '(list
  451. (string :tag "Tags/TODO match to identify a project")
  452. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  453. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  454. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  455. (defcustom org-agenda-filter-effort-default-operator "<"
  456. "The default operator for effort estimate filtering.
  457. If you select an effort estimate limit without first pressing an operator,
  458. this one will be used."
  459. :group 'org-agenda-custom-commands
  460. :type '(choice (const :tag "less or equal" "<")
  461. (const :tag "greater or equal"">")
  462. (const :tag "equal" "=")))
  463. (defgroup org-agenda-skip nil
  464. "Options concerning skipping parts of agenda files."
  465. :tag "Org Agenda Skip"
  466. :group 'org-agenda)
  467. (defgroup org-agenda-daily/weekly nil
  468. "Options concerning the daily/weekly agenda."
  469. :tag "Org Agenda Daily/Weekly"
  470. :group 'org-agenda)
  471. (defgroup org-agenda-todo-list nil
  472. "Options concerning the global todo list agenda view."
  473. :tag "Org Agenda Todo List"
  474. :group 'org-agenda)
  475. (defgroup org-agenda-match-view nil
  476. "Options concerning the general tags/property/todo match agenda view."
  477. :tag "Org Agenda Match View"
  478. :group 'org-agenda)
  479. (defgroup org-agenda-search-view nil
  480. "Options concerning the general tags/property/todo match agenda view."
  481. :tag "Org Agenda Match View"
  482. :group 'org-agenda)
  483. (defvar org-agenda-archives-mode nil
  484. "Non-nil means the agenda will include archived items.
  485. If this is the symbol `trees', trees in the selected agenda scope
  486. that are marked with the ARCHIVE tag will be included anyway. When this is
  487. t, also all archive files associated with the current selection of agenda
  488. files will be included.")
  489. (defcustom org-agenda-skip-comment-trees t
  490. "Non-nil means skip trees that start with the COMMENT keyword.
  491. When nil, these trees are also scanned by agenda commands."
  492. :group 'org-agenda-skip
  493. :type 'boolean)
  494. (defcustom org-agenda-todo-list-sublevels t
  495. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  496. When nil, the sublevels of a TODO entry are not checked, resulting in
  497. potentially much shorter TODO lists."
  498. :group 'org-agenda-skip
  499. :group 'org-agenda-todo-list
  500. :type 'boolean)
  501. (defcustom org-agenda-todo-ignore-with-date nil
  502. "Non-nil means don't show entries with a date in the global todo list.
  503. You can use this if you prefer to mark mere appointments with a TODO keyword,
  504. but don't want them to show up in the TODO list.
  505. When this is set, it also covers deadlines and scheduled items, the settings
  506. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  507. will be ignored.
  508. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-todo-list
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-ignore-scheduled nil
  513. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  514. This applies when creating the global todo list.
  515. Valid values are:
  516. past Don't show entries scheduled today or in the past.
  517. future Don't show entries scheduled in the future.
  518. The idea behind this is that by scheduling it, you don't want to
  519. think about it until the scheduled date.
  520. all Don't show any scheduled entries in the global todo list.
  521. The idea behind this is that by scheduling it, you have already
  522. \"taken care\" of this item.
  523. t Same as `all', for backward compatibility.
  524. See also `org-agenda-todo-ignore-with-date'.
  525. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  526. to make his option also apply to the tags-todo list."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type '(choice
  530. (const :tag "Ignore future-scheduled todos" future)
  531. (const :tag "Ignore past- or present-scheduled todos" past)
  532. (const :tag "Ignore all scheduled todos" all)
  533. (const :tag "Ignore all scheduled todos (compatibility)" t)
  534. (const :tag "Show scheduled todos" nil)))
  535. (defcustom org-agenda-todo-ignore-deadlines nil
  536. "Non-nil means ignore some deadlined TODO items when making TODO list.
  537. There are different motivations for using different values, please think
  538. carefully when configuring this variable.
  539. This applies when creating the global todo list.
  540. Valid values are:
  541. near Don't show near deadline entries. A deadline is near when it is
  542. closer than `org-deadline-warning-days' days. The idea behind this
  543. is that such items will appear in the agenda anyway.
  544. far Don't show TODO entries where a deadline has been defined, but
  545. the deadline is not near. This is useful if you don't want to
  546. use the todo list to figure out what to do now.
  547. past Don't show entries with a deadline timestamp for today or in the past.
  548. future Don't show entries with a deadline timestamp in the future, not even
  549. when they become `near' ones. Use it with caution.
  550. all Ignore all TODO entries that do have a deadline.
  551. t Same as `near', for backward compatibility.
  552. See also `org-agenda-todo-ignore-with-date'.
  553. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  554. to make his option also apply to the tags-todo list."
  555. :group 'org-agenda-skip
  556. :group 'org-agenda-todo-list
  557. :type '(choice
  558. (const :tag "Ignore near deadlines" near)
  559. (const :tag "Ignore near deadlines (compatibility)" t)
  560. (const :tag "Ignore far deadlines" far)
  561. (const :tag "Ignore all TODOs with a deadlines" all)
  562. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  563. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  564. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  565. The variables
  566. `org-agenda-todo-ignore-with-date',
  567. `org-agenda-todo-ignore-scheduled'
  568. `org-agenda-todo-ignore-deadlines'
  569. make the global TODO list skip entries that have time stamps of certain
  570. kinds. If this option is set, the same options will also apply for the
  571. tags-todo search, which is the general tags/property matcher
  572. restricted to unfinished TODO entries only."
  573. :group 'org-agenda-skip
  574. :group 'org-agenda-todo-list
  575. :group 'org-agenda-match-view
  576. :type 'boolean)
  577. (defcustom org-agenda-skip-scheduled-if-done nil
  578. "Non-nil means don't show scheduled items in agenda when they are done.
  579. This is relevant for the daily/weekly agenda, not for the TODO list. And
  580. it applies only to the actual date of the scheduling. Warnings about
  581. an item with a past scheduling dates are always turned off when the item
  582. is DONE."
  583. :group 'org-agenda-skip
  584. :group 'org-agenda-daily/weekly
  585. :type 'boolean)
  586. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  587. "Non-nil means skip scheduling line if same entry shows because of deadline.
  588. In the agenda of today, an entry can show up multiple times because
  589. it is both scheduled and has a nearby deadline, and maybe a plain time
  590. stamp as well.
  591. When this variable is t, then only the deadline is shown and the fact that
  592. the entry is scheduled today or was scheduled previously is not shown.
  593. When this variable is nil, the entry will be shown several times. When
  594. the variable is the symbol `not-today', then skip scheduled previously,
  595. but not scheduled today."
  596. :group 'org-agenda-skip
  597. :group 'org-agenda-daily/weekly
  598. :type '(choice
  599. (const :tag "Never" nil)
  600. (const :tag "Always" t)
  601. (const :tag "Not when scheduled today" not-today)))
  602. (defcustom org-agenda-skip-deadline-if-done nil
  603. "Non-nil means don't show deadlines when the corresponding item is done.
  604. When nil, the deadline is still shown and should give you a happy feeling.
  605. This is relevant for the daily/weekly agenda. And it applied only to the
  606. actually date of the deadline. Warnings about approaching and past-due
  607. deadlines are always turned off when the item is DONE."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-daily/weekly
  610. :type 'boolean)
  611. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  612. "Non-nil means skip deadline prewarning when entry is also scheduled.
  613. This will apply on all days where a prewarning for the deadline would
  614. be shown, but not at the day when the entry is actually due. On that day,
  615. the deadline will be shown anyway.
  616. This variable may be set to nil, t, or a number which will then give
  617. the number of days before the actual deadline when the prewarnings
  618. should resume.
  619. This can be used in a workflow where the first showing of the deadline will
  620. trigger you to schedule it, and then you don't want to be reminded of it
  621. because you will take care of it on the day when scheduled."
  622. :group 'org-agenda-skip
  623. :group 'org-agenda-daily/weekly
  624. :type '(choice
  625. (const :tag "Alwas show prewarning" nil)
  626. (const :tag "Remove prewarning if entry is scheduled" t)
  627. (integer :tag "Restart prewarning N days before deadline")))
  628. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  629. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  630. When non-nil, after the search for timestamps has matched once in an
  631. entry, the rest of the entry will not be searched."
  632. :group 'org-agenda-skip
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-timestamp-if-done nil
  635. "Non-nil means don't select item by timestamp or -range if it is DONE."
  636. :group 'org-agenda-skip
  637. :group 'org-agenda-daily/weekly
  638. :type 'boolean)
  639. (defcustom org-agenda-dim-blocked-tasks t
  640. "Non-nil means dim blocked tasks in the agenda display.
  641. This causes some overhead during agenda construction, but if you
  642. have turned on `org-enforce-todo-dependencies',
  643. `org-enforce-todo-checkbox-dependencies', or any other blocking
  644. mechanism, this will create useful feedback in the agenda.
  645. Instead of t, this variable can also have the value `invisible'.
  646. Then blocked tasks will be invisible and only become visible when
  647. they become unblocked. An exemption to this behavior is when a task is
  648. blocked because of unchecked checkboxes below it. Since checkboxes do
  649. not show up in the agenda views, making this task invisible you remove any
  650. trace from agenda views that there is something to do. Therefore, a task
  651. that is blocked because of checkboxes will never be made invisible, it
  652. will only be dimmed."
  653. :group 'org-agenda-daily/weekly
  654. :group 'org-agenda-todo-list
  655. :type '(choice
  656. (const :tag "Do not dim" nil)
  657. (const :tag "Dim to a grey face" t)
  658. (const :tag "Make invisible" invisible)))
  659. (defcustom org-timeline-show-empty-dates 3
  660. "Non-nil means `org-timeline' also shows dates without an entry.
  661. When nil, only the days which actually have entries are shown.
  662. When t, all days between the first and the last date are shown.
  663. When an integer, show also empty dates, but if there is a gap of more than
  664. N days, just insert a special line indicating the size of the gap."
  665. :group 'org-agenda-skip
  666. :type '(choice
  667. (const :tag "None" nil)
  668. (const :tag "All" t)
  669. (integer :tag "at most")))
  670. (defgroup org-agenda-startup nil
  671. "Options concerning initial settings in the Agenda in Org Mode."
  672. :tag "Org Agenda Startup"
  673. :group 'org-agenda)
  674. (defcustom org-agenda-menu-show-matcher t
  675. "Non-nil menas show the match string in the agenda dispatcher menu.
  676. When nil, the matcher string is not shown, but is put into the help-echo
  677. property so than moving the mouse over the command shows it.
  678. Setting it to nil is good if matcher strings are very long and/or if
  679. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  680. :group 'org-agenda
  681. :type 'boolean)
  682. (defcustom org-agenda-menu-two-column nil
  683. "Non-nil means, use two columns to show custom commands in the dispatcher.
  684. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  685. to nil."
  686. :group 'org-agenda
  687. :type 'boolean)
  688. (defcustom org-finalize-agenda-hook nil
  689. "Hook run just before displaying an agenda buffer."
  690. :group 'org-agenda-startup
  691. :type 'hook)
  692. (defcustom org-agenda-mouse-1-follows-link nil
  693. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  694. A longer mouse click will still set point. Does not work on XEmacs.
  695. Needs to be set before org.el is loaded."
  696. :group 'org-agenda-startup
  697. :type 'boolean)
  698. (defcustom org-agenda-start-with-follow-mode nil
  699. "The initial value of follow mode in a newly created agenda window."
  700. :group 'org-agenda-startup
  701. :type 'boolean)
  702. (defcustom org-agenda-show-outline-path t
  703. "Non-nil means show outline path in echo area after line motion."
  704. :group 'org-agenda-startup
  705. :type 'boolean)
  706. (defcustom org-agenda-start-with-entry-text-mode nil
  707. "The initial value of entry-text-mode in a newly created agenda window."
  708. :group 'org-agenda-startup
  709. :type 'boolean)
  710. (defcustom org-agenda-entry-text-maxlines 5
  711. "Number of text lines to be added when `E' is pressed in the agenda.
  712. Note that this variable only used during agenda display. Add add entry text
  713. when exporting the agenda, configure the variable
  714. `org-agenda-add-entry-ext-maxlines'."
  715. :group 'org-agenda
  716. :type 'integer)
  717. (defcustom org-agenda-entry-text-exclude-regexps nil
  718. "List of regular expressions to clean up entry text.
  719. The complete matches of all regular expressions in this list will be
  720. removed from entry text before it is shown in the agenda."
  721. :group 'org-agenda
  722. :type '(repeat (regexp)))
  723. (defvar org-agenda-entry-text-cleanup-hook nil
  724. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  725. This cleanup is done in a temporary buffer, so the function may inspect and
  726. change the entire buffer.
  727. Some default stuff like drawers and scheduling/deadline dates will already
  728. have been removed when this is called, as will any matches for regular
  729. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  730. (defvar org-agenda-include-inactive-timestamps nil
  731. "Non-nil means include inactive time stamps in agenda and timeline.")
  732. (defgroup org-agenda-windows nil
  733. "Options concerning the windows used by the Agenda in Org Mode."
  734. :tag "Org Agenda Windows"
  735. :group 'org-agenda)
  736. (defcustom org-agenda-window-setup 'reorganize-frame
  737. "How the agenda buffer should be displayed.
  738. Possible values for this option are:
  739. current-window Show agenda in the current window, keeping all other windows.
  740. other-window Use `switch-to-buffer-other-window' to display agenda.
  741. reorganize-frame Show only two windows on the current frame, the current
  742. window and the agenda.
  743. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  744. Also, when exiting the agenda, kill that frame.
  745. See also the variable `org-agenda-restore-windows-after-quit'."
  746. :group 'org-agenda-windows
  747. :type '(choice
  748. (const current-window)
  749. (const other-frame)
  750. (const other-window)
  751. (const reorganize-frame)))
  752. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  753. "The min and max height of the agenda window as a fraction of frame height.
  754. The value of the variable is a cons cell with two numbers between 0 and 1.
  755. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  756. :group 'org-agenda-windows
  757. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  758. (defcustom org-agenda-restore-windows-after-quit nil
  759. "Non-nil means restore window configuration open exiting agenda.
  760. Before the window configuration is changed for displaying the agenda,
  761. the current status is recorded. When the agenda is exited with
  762. `q' or `x' and this option is set, the old state is restored. If
  763. `org-agenda-window-setup' is `other-frame', the value of this
  764. option will be ignored."
  765. :group 'org-agenda-windows
  766. :type 'boolean)
  767. (defcustom org-agenda-ndays 7
  768. "Number of days to include in overview display.
  769. Should be 1 or 7.
  770. Custom commands can set this variable in the options section."
  771. :group 'org-agenda-daily/weekly
  772. :type 'integer)
  773. (defcustom org-agenda-start-on-weekday 1
  774. "Non-nil means start the overview always on the specified weekday.
  775. 0 denotes Sunday, 1 denotes Monday etc.
  776. When nil, always start on the current day.
  777. Custom commands can set this variable in the options section."
  778. :group 'org-agenda-daily/weekly
  779. :type '(choice (const :tag "Today" nil)
  780. (integer :tag "Weekday No.")))
  781. (defcustom org-agenda-show-all-dates t
  782. "Non-nil means `org-agenda' shows every day in the selected range.
  783. When nil, only the days which actually have entries are shown."
  784. :group 'org-agenda-daily/weekly
  785. :type 'boolean)
  786. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  787. "Format string for displaying dates in the agenda.
  788. Used by the daily/weekly agenda and by the timeline. This should be
  789. a format string understood by `format-time-string', or a function returning
  790. the formatted date as a string. The function must take a single argument,
  791. a calendar-style date list like (month day year)."
  792. :group 'org-agenda-daily/weekly
  793. :type '(choice
  794. (string :tag "Format string")
  795. (function :tag "Function")))
  796. (defun org-agenda-format-date-aligned (date)
  797. "Format a date string for display in the daily/weekly agenda, or timeline.
  798. This function makes sure that dates are aligned for easy reading."
  799. (require 'cal-iso)
  800. (let* ((dayname (calendar-day-name date))
  801. (day (cadr date))
  802. (day-of-week (calendar-day-of-week date))
  803. (month (car date))
  804. (monthname (calendar-month-name month))
  805. (year (nth 2 date))
  806. (iso-week (org-days-to-iso-week
  807. (calendar-absolute-from-gregorian date)))
  808. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  809. (1- year))
  810. ((and (= month 12) (<= iso-week 1))
  811. (1+ year))
  812. (t year)))
  813. (weekstring (if (= day-of-week 1)
  814. (format " W%02d" iso-week)
  815. "")))
  816. (format "%-10s %2d %s %4d%s"
  817. dayname day monthname year weekstring)))
  818. (defcustom org-agenda-time-leading-zero nil
  819. "Non-nil means use leading zero for military times in agenda.
  820. For example, 9:30am would become 09:30 rather than 9:30."
  821. :group 'org-agenda-daily/weekly
  822. :type 'boolean)
  823. (defcustom org-agenda-weekend-days '(6 0)
  824. "Which days are weekend?
  825. These days get the special face `org-agenda-date-weekend' in the agenda
  826. and timeline buffers."
  827. :group 'org-agenda-daily/weekly
  828. :type '(set :greedy t
  829. (const :tag "Monday" 1)
  830. (const :tag "Tuesday" 2)
  831. (const :tag "Wednesday" 3)
  832. (const :tag "Thursday" 4)
  833. (const :tag "Friday" 5)
  834. (const :tag "Saturday" 6)
  835. (const :tag "Sunday" 0)))
  836. (defcustom org-agenda-include-diary nil
  837. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  838. Custom commands can set this variable in the options section."
  839. :group 'org-agenda-daily/weekly
  840. :type 'boolean)
  841. (defcustom org-agenda-include-deadlines t
  842. "If non-nil, include entries within their deadline warning period.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type 'boolean)
  846. (defcustom org-agenda-include-all-todo nil
  847. "Set means weekly/daily agenda will always contain all TODO entries.
  848. The TODO entries will be listed at the top of the agenda, before
  849. the entries for specific days.
  850. This option is deprecated, it is better to define a block agenda instead."
  851. :group 'org-agenda-daily/weekly
  852. :type 'boolean)
  853. (defcustom org-agenda-repeating-timestamp-show-all t
  854. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  855. When nil, only one occurrence is shown, either today or the
  856. nearest into the future."
  857. :group 'org-agenda-daily/weekly
  858. :type 'boolean)
  859. (defcustom org-scheduled-past-days 10000
  860. "No. of days to continue listing scheduled items that are not marked DONE.
  861. When an item is scheduled on a date, it shows up in the agenda on this
  862. day and will be listed until it is marked done for the number of days
  863. given here."
  864. :group 'org-agenda-daily/weekly
  865. :type 'integer)
  866. (defcustom org-agenda-log-mode-items '(closed clock)
  867. "List of items that should be shown in agenda log mode.
  868. This list may contain the following symbols:
  869. closed Show entries that have been closed on that day.
  870. clock Show entries that have received clocked time on that day.
  871. state Show all logged state changes.
  872. Note that instead of changing this variable, you can also press `C-u l' in
  873. the agenda to display all available LOG items temporarily."
  874. :group 'org-agenda-daily/weekly
  875. :type '(set :greedy t (const closed) (const clock) (const state)))
  876. (defcustom org-agenda-log-mode-add-notes t
  877. "Non-nil means add first line of notes to log entries in agenda views.
  878. If a log item like a state change or a clock entry is associated with
  879. notes, the first line of these notes will be added to the entry in the
  880. agenda display."
  881. :group 'org-agenda-daily/weekly
  882. :type 'boolean)
  883. (defcustom org-agenda-start-with-log-mode nil
  884. "The initial value of log-mode in a newly created agenda window."
  885. :group 'org-agenda-startup
  886. :group 'org-agenda-daily/weekly
  887. :type 'boolean)
  888. (defcustom org-agenda-start-with-clockreport-mode nil
  889. "The initial value of clockreport-mode in a newly created agenda window."
  890. :group 'org-agenda-startup
  891. :group 'org-agenda-daily/weekly
  892. :type 'boolean)
  893. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  894. "Property list with parameters for the clocktable in clockreport mode.
  895. This is the display mode that shows a clock table in the daily/weekly
  896. agenda, the properties for this dynamic block can be set here.
  897. The usual clocktable parameters are allowed here, but you cannot set
  898. the properties :name, :tstart, :tend, :block, and :scope - these will
  899. be overwritten to make sure the content accurately reflects the
  900. current display in the agenda."
  901. :group 'org-agenda-daily/weekly
  902. :type 'plist)
  903. (defcustom org-agenda-search-view-always-boolean nil
  904. "Non-nil means the search string is interpreted as individual parts.
  905. The search string for search view can either be interpreted as a phrase,
  906. or as a list of snippets that define a boolean search for a number of
  907. strings.
  908. When this is non-nil, the string will be split on whitespace, and each
  909. snippet will be searched individually, and all must match in order to
  910. select an entry. A snippet is then a single string of non-white
  911. characters, or a string in double quotes, or a regexp in {} braces.
  912. If a snippet is preceded by \"-\", the snippet must *not* match.
  913. \"+\" is syntactic sugar for positive selection. Each snippet may
  914. be found as a full word or a partial word, but see the variable
  915. `org-agenda-search-view-force-full-words'.
  916. When this is nil, search will look for the entire search phrase as one,
  917. with each space character matching any amount of whitespace, including
  918. line breaks.
  919. Even when this is nil, you can still switch to Boolean search dynamically
  920. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  921. is a regexp marked with braces like \"{abc}\", this will also switch to
  922. boolean search."
  923. :group 'org-agenda-search-view
  924. :type 'boolean)
  925. (if (fboundp 'defvaralias)
  926. (defvaralias 'org-agenda-search-view-search-words-only
  927. 'org-agenda-search-view-always-boolean))
  928. (defcustom org-agenda-search-view-force-full-words nil
  929. "Non-nil means, search words must be matches as complete words.
  930. When nil, they may also match part of a word."
  931. :group 'org-agenda-search-view
  932. :type 'boolean)
  933. (defgroup org-agenda-time-grid nil
  934. "Options concerning the time grid in the Org-mode Agenda."
  935. :tag "Org Agenda Time Grid"
  936. :group 'org-agenda)
  937. (defcustom org-agenda-search-headline-for-time t
  938. "Non-nil means search headline for a time-of-day.
  939. If the headline contains a time-of-day in one format or another, it will
  940. be used to sort the entry into the time sequence of items for a day.
  941. Some people have time stamps in the headline that refer to the creation
  942. time or so, and then this produces an unwanted side effect. If this is
  943. the case for your, use this variable to turn off searching the headline
  944. for a time."
  945. :group 'org-agenda-time-grid
  946. :type 'boolean)
  947. (defcustom org-agenda-use-time-grid t
  948. "Non-nil means show a time grid in the agenda schedule.
  949. A time grid is a set of lines for specific times (like every two hours between
  950. 8:00 and 20:00). The items scheduled for a day at specific times are
  951. sorted in between these lines.
  952. For details about when the grid will be shown, and what it will look like, see
  953. the variable `org-agenda-time-grid'."
  954. :group 'org-agenda-time-grid
  955. :type 'boolean)
  956. (defcustom org-agenda-time-grid
  957. '((daily today require-timed)
  958. "----------------"
  959. (800 1000 1200 1400 1600 1800 2000))
  960. "The settings for time grid for agenda display.
  961. This is a list of three items. The first item is again a list. It contains
  962. symbols specifying conditions when the grid should be displayed:
  963. daily if the agenda shows a single day
  964. weekly if the agenda shows an entire week
  965. today show grid on current date, independent of daily/weekly display
  966. require-timed show grid only if at least one item has a time specification
  967. The second item is a string which will be placed behind the grid time.
  968. The third item is a list of integers, indicating the times that should have
  969. a grid line."
  970. :group 'org-agenda-time-grid
  971. :type
  972. '(list
  973. (set :greedy t :tag "Grid Display Options"
  974. (const :tag "Show grid in single day agenda display" daily)
  975. (const :tag "Show grid in weekly agenda display" weekly)
  976. (const :tag "Always show grid for today" today)
  977. (const :tag "Show grid only if any timed entries are present"
  978. require-timed)
  979. (const :tag "Skip grid times already present in an entry"
  980. remove-match))
  981. (string :tag "Grid String")
  982. (repeat :tag "Grid Times" (integer :tag "Time"))))
  983. (defgroup org-agenda-sorting nil
  984. "Options concerning sorting in the Org-mode Agenda."
  985. :tag "Org Agenda Sorting"
  986. :group 'org-agenda)
  987. (defcustom org-agenda-sorting-strategy
  988. '((agenda habit-down time-up priority-down category-keep)
  989. (todo priority-down category-keep)
  990. (tags priority-down category-keep)
  991. (search category-keep))
  992. "Sorting structure for the agenda items of a single day.
  993. This is a list of symbols which will be used in sequence to determine
  994. if an entry should be listed before another entry. The following
  995. symbols are recognized:
  996. time-up Put entries with time-of-day indications first, early first
  997. time-down Put entries with time-of-day indications first, late first
  998. category-keep Keep the default order of categories, corresponding to the
  999. sequence in `org-agenda-files'.
  1000. category-up Sort alphabetically by category, A-Z.
  1001. category-down Sort alphabetically by category, Z-A.
  1002. tag-up Sort alphabetically by last tag, A-Z.
  1003. tag-down Sort alphabetically by last tag, Z-A.
  1004. priority-up Sort numerically by priority, high priority last.
  1005. priority-down Sort numerically by priority, high priority first.
  1006. todo-state-up Sort by todo state, tasks that are done last.
  1007. todo-state-down Sort by todo state, tasks that are done first.
  1008. effort-up Sort numerically by estimated effort, high effort last.
  1009. effort-down Sort numerically by estimated effort, high effort first.
  1010. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1011. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1012. habit-up Put entries that are habits first
  1013. habit-down Put entries that are habits last
  1014. alpha-up Sort headlines alphabetically
  1015. alpha-down Sort headlines alphabetically, reversed
  1016. The different possibilities will be tried in sequence, and testing stops
  1017. if one comparison returns a \"not-equal\". For example, the default
  1018. '(time-up category-keep priority-down)
  1019. means: Pull out all entries having a specified time of day and sort them,
  1020. in order to make a time schedule for the current day the first thing in the
  1021. agenda listing for the day. Of the entries without a time indication, keep
  1022. the grouped in categories, don't sort the categories, but keep them in
  1023. the sequence given in `org-agenda-files'. Within each category sort by
  1024. priority.
  1025. Leaving out `category-keep' would mean that items will be sorted across
  1026. categories by priority.
  1027. Instead of a single list, this can also be a set of list for specific
  1028. contents, with a context symbol in the car of the list, any of
  1029. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1030. Custom commands can bind this variable in the options section."
  1031. :group 'org-agenda-sorting
  1032. :type `(choice
  1033. (repeat :tag "General" ,org-sorting-choice)
  1034. (list :tag "Individually"
  1035. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1036. (repeat ,org-sorting-choice))
  1037. (cons (const :tag "Strategy for TODO lists" todo)
  1038. (repeat ,org-sorting-choice))
  1039. (cons (const :tag "Strategy for Tags matches" tags)
  1040. (repeat ,org-sorting-choice))
  1041. (cons (const :tag "Strategy for search matches" search)
  1042. (repeat ,org-sorting-choice)))))
  1043. (defcustom org-agenda-cmp-user-defined nil
  1044. "A function to define the comparison `user-defined'.
  1045. This function must receive two arguments, agenda entry a and b.
  1046. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1047. the user comparison, return nil.
  1048. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1049. part of an agenda sorting strategy."
  1050. :group 'org-agenda-sorting
  1051. :type 'symbol)
  1052. (defcustom org-sort-agenda-notime-is-late t
  1053. "Non-nil means items without time are considered late.
  1054. This is only relevant for sorting. When t, items which have no explicit
  1055. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1056. do have a time. When nil, the default time is before 0:00. You can use this
  1057. option to decide if the schedule for today should come before or after timeless
  1058. agenda entries."
  1059. :group 'org-agenda-sorting
  1060. :type 'boolean)
  1061. (defcustom org-sort-agenda-noeffort-is-high t
  1062. "Non-nil means items without effort estimate are sorted as high effort.
  1063. This also applies when filtering an agenda view with respect to the
  1064. < or > effort operator. Then, tasks with no effort defined will be treated
  1065. as tasks with high effort.
  1066. When nil, such items are sorted as 0 minutes effort."
  1067. :group 'org-agenda-sorting
  1068. :type 'boolean)
  1069. (defgroup org-agenda-line-format nil
  1070. "Options concerning the entry prefix in the Org-mode agenda display."
  1071. :tag "Org Agenda Line Format"
  1072. :group 'org-agenda)
  1073. (defcustom org-agenda-prefix-format
  1074. '((agenda . " %-12:c%?-12t% s")
  1075. (timeline . " % s")
  1076. (todo . " %-12:c")
  1077. (tags . " %-12:c")
  1078. (search . " %-12:c"))
  1079. "Format specifications for the prefix of items in the agenda views.
  1080. An alist with four entries, for the different agenda types. The keys to the
  1081. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1082. are format strings.
  1083. This format works similar to a printf format, with the following meaning:
  1084. %c the category of the item, \"Diary\" for entries from the diary, or
  1085. as given by the CATEGORY keyword or derived from the file name.
  1086. %T the *last* tag of the item. Last because inherited tags come
  1087. first in the list.
  1088. %t the time-of-day specification if one applies to the entry, in the
  1089. format HH:MM
  1090. %s Scheduling/Deadline information, a short string
  1091. All specifiers work basically like the standard `%s' of printf, but may
  1092. contain two additional characters: A question mark just after the `%' and
  1093. a whitespace/punctuation character just before the final letter.
  1094. If the first character after `%' is a question mark, the entire field
  1095. will only be included if the corresponding value applies to the
  1096. current entry. This is useful for fields which should have fixed
  1097. width when present, but zero width when absent. For example,
  1098. \"%?-12t\" will result in a 12 character time field if a time of the
  1099. day is specified, but will completely disappear in entries which do
  1100. not contain a time.
  1101. If there is punctuation or whitespace character just before the final
  1102. format letter, this character will be appended to the field value if
  1103. the value is not empty. For example, the format \"%-12:c\" leads to
  1104. \"Diary: \" if the category is \"Diary\". If the category were be
  1105. empty, no additional colon would be inserted.
  1106. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1107. - Indent the line with two space characters
  1108. - Give the category in a 12 chars wide field, padded with whitespace on
  1109. the right (because of `-'). Append a colon if there is a category
  1110. (because of `:').
  1111. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1112. time, don't put in an empty field, just skip it (because of '?').
  1113. - Finally, put the scheduling information and append a whitespace.
  1114. As another example, if you don't want the time-of-day of entries in
  1115. the prefix, you could use:
  1116. (setq org-agenda-prefix-format \" %-11:c% s\")
  1117. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1118. `org-agenda-remove-tags'.
  1119. Custom commands can set this variable in the options section."
  1120. :type '(choice
  1121. (string :tag "General format")
  1122. (list :greedy t :tag "View dependent"
  1123. (cons (const agenda) (string :tag "Format"))
  1124. (cons (const timeline) (string :tag "Format"))
  1125. (cons (const todo) (string :tag "Format"))
  1126. (cons (const tags) (string :tag "Format"))
  1127. (cons (const search) (string :tag "Format"))))
  1128. :group 'org-agenda-line-format)
  1129. (defvar org-prefix-format-compiled nil
  1130. "The compiled version of the most recently used prefix format.
  1131. See the variable `org-agenda-prefix-format'.")
  1132. (defcustom org-agenda-todo-keyword-format "%-1s"
  1133. "Format for the TODO keyword in agenda lines.
  1134. Set this to something like \"%-12s\" if you want all TODO keywords
  1135. to occupy a fixed space in the agenda display."
  1136. :group 'org-agenda-line-format
  1137. :type 'string)
  1138. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1139. "Text preceding timerange entries in the agenda view.
  1140. This is a list with two strings. The first applies when the range
  1141. is entirely on one day. The second applies if the range spans several days.
  1142. The strings may have two \"%d\" format specifiers which will be filled
  1143. with the sequence number of the days, and the total number of days in the
  1144. range, respectively."
  1145. :group 'org-agenda-line-format
  1146. :type '(list
  1147. (string :tag "Deadline today ")
  1148. (choice :tag "Deadline relative"
  1149. (string :tag "Format string")
  1150. (function))))
  1151. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1152. "Text preceding scheduled items in the agenda view.
  1153. This is a list with two strings. The first applies when the item is
  1154. scheduled on the current day. The second applies when it has been scheduled
  1155. previously, it may contain a %d indicating that this is the nth time that
  1156. this item is scheduled, due to automatic rescheduling of unfinished items
  1157. for the following day. So this number is one larger than the number of days
  1158. that passed since this item was scheduled first."
  1159. :group 'org-agenda-line-format
  1160. :type '(list
  1161. (string :tag "Scheduled today ")
  1162. (string :tag "Scheduled previously")))
  1163. (defcustom org-agenda-inactive-leader "["
  1164. "Text preceding item pulled into the agenda by inactive time stamps.
  1165. These entries are added to the agenda when pressing \"[\"."
  1166. :group 'org-agenda-line-format
  1167. :type '(list
  1168. (string :tag "Scheduled today ")
  1169. (string :tag "Scheduled previously")))
  1170. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1171. "Text preceding deadline items in the agenda view.
  1172. This is a list with two strings. The first applies when the item has its
  1173. deadline on the current day. The second applies when it is in the past or
  1174. in the future, it may contain %d to capture how many days away the deadline
  1175. is (was)."
  1176. :group 'org-agenda-line-format
  1177. :type '(list
  1178. (string :tag "Deadline today ")
  1179. (choice :tag "Deadline relative"
  1180. (string :tag "Format string")
  1181. (function))))
  1182. (defcustom org-agenda-remove-times-when-in-prefix t
  1183. "Non-nil means remove duplicate time specifications in agenda items.
  1184. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1185. time-of-day specification in a headline or diary entry is extracted and
  1186. placed into the prefix. If this option is non-nil, the original specification
  1187. \(a timestamp or -range, or just a plain time(range) specification like
  1188. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1189. cluttered.
  1190. The option can be t or nil. It may also be the symbol `beg', indicating
  1191. that the time should only be removed when it is located at the beginning of
  1192. the headline/diary entry."
  1193. :group 'org-agenda-line-format
  1194. :type '(choice
  1195. (const :tag "Always" t)
  1196. (const :tag "Never" nil)
  1197. (const :tag "When at beginning of entry" beg)))
  1198. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1199. "Non-nil means remove time ranges specifications in agenda
  1200. items that span on several days."
  1201. :group 'org-agenda-line-format
  1202. :type 'boolean)
  1203. (defcustom org-agenda-default-appointment-duration nil
  1204. "Default duration for appointments that only have a starting time.
  1205. When nil, no duration is specified in such cases.
  1206. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1207. :group 'org-agenda-line-format
  1208. :type '(choice
  1209. (integer :tag "Minutes")
  1210. (const :tag "No default duration")))
  1211. (defcustom org-agenda-show-inherited-tags t
  1212. "Non-nil means show inherited tags in each agenda line."
  1213. :group 'org-agenda-line-format
  1214. :type 'boolean)
  1215. (defcustom org-agenda-hide-tags-regexp nil
  1216. "Regular expression used to filter away specific tags in agenda views.
  1217. This means that these tags will be present, but not be shown in the agenda
  1218. line. Secondary filtering will still work on the hidden tags.
  1219. Nil means don't hide any tags."
  1220. :group 'org-agenda-line-format
  1221. :type '(choice
  1222. (const :tag "Hide none" nil)
  1223. (string :tag "Regexp ")))
  1224. (defcustom org-agenda-remove-tags nil
  1225. "Non-nil means remove the tags from the headline copy in the agenda.
  1226. When this is the symbol `prefix', only remove tags when
  1227. `org-agenda-prefix-format' contains a `%T' specifier."
  1228. :group 'org-agenda-line-format
  1229. :type '(choice
  1230. (const :tag "Always" t)
  1231. (const :tag "Never" nil)
  1232. (const :tag "When prefix format contains %T" prefix)))
  1233. (if (fboundp 'defvaralias)
  1234. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1235. 'org-agenda-remove-tags))
  1236. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1237. "Shift tags in agenda items to this column.
  1238. If this number is positive, it specifies the column. If it is negative,
  1239. it means that the tags should be flushright to that column. For example,
  1240. -80 works well for a normal 80 character screen."
  1241. :group 'org-agenda-line-format
  1242. :type 'integer)
  1243. (if (fboundp 'defvaralias)
  1244. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1245. (defcustom org-agenda-fontify-priorities 'cookies
  1246. "Non-nil means highlight low and high priorities in agenda.
  1247. When t, the highest priority entries are bold, lowest priority italic.
  1248. However, settings in `org-priority-faces' will overrule these faces.
  1249. When this variable is the symbol `cookies', only fontify the
  1250. cookies, not the entire task.
  1251. This may also be an association list of priority faces, whose
  1252. keys are the character values of `org-highest-priority',
  1253. `org-default-priority', and `org-lowest-priority' (the default values
  1254. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1255. color as a string, or a list like `(:background \"Red\")'.
  1256. If it is a color, the variable `org-faces-easy-properties'
  1257. determines if it is a foreground or a background color."
  1258. :group 'org-agenda-line-format
  1259. :type '(choice
  1260. (const :tag "Never" nil)
  1261. (const :tag "Defaults" t)
  1262. (const :tag "Cookies only" cookies)
  1263. (repeat :tag "Specify"
  1264. (list (character :tag "Priority" :value ?A)
  1265. (choice :tag "Face "
  1266. (string :tag "Color")
  1267. (sexp :tag "Face"))))))
  1268. (defgroup org-agenda-column-view nil
  1269. "Options concerning column view in the agenda."
  1270. :tag "Org Agenda Column View"
  1271. :group 'org-agenda)
  1272. (defcustom org-agenda-columns-show-summaries t
  1273. "Non-nil means show summaries for columns displayed in the agenda view."
  1274. :group 'org-agenda-column-view
  1275. :type 'boolean)
  1276. (defcustom org-agenda-columns-remove-prefix-from-item t
  1277. "Non-nil means remove the prefix from a headline for agenda column view.
  1278. The special ITEM field in the columns format contains the current line, with
  1279. all information shown in other columns (like the TODO state or a tag).
  1280. When this variable is non-nil, also the agenda prefix will be removed from
  1281. the content of the ITEM field, to make sure as much as possible of the
  1282. headline can be shown in the limited width of the field."
  1283. :group 'org-agenda
  1284. :type 'boolean)
  1285. (defcustom org-agenda-columns-compute-summary-properties t
  1286. "Non-nil means recompute all summary properties before column view.
  1287. When column view in the agenda is listing properties that have a summary
  1288. operator, it can go to all relevant buffers and recompute the summaries
  1289. there. This can mean overhead for the agenda column view, but is necessary
  1290. to have thing up to date.
  1291. As a special case, a CLOCKSUM property also makes sure that the clock
  1292. computations are current."
  1293. :group 'org-agenda-column-view
  1294. :type 'boolean)
  1295. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1296. "Non-nil means the duration of an appointment will add to day effort.
  1297. The property to which appointment durations will be added is the one given
  1298. in the option `org-effort-property'. If an appointment does not have
  1299. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1300. is not set, an appointment without end time will not contribute to the time
  1301. estimate."
  1302. :group 'org-agenda-column-view
  1303. :type 'boolean)
  1304. (defcustom org-agenda-auto-exclude-function nil
  1305. "A function called with a tag to decide if it is filtered on '/ RET'.
  1306. The sole argument to the function, which is called once for each
  1307. possible tag, is a string giving the name of the tag. The
  1308. function should return either nil if the tag should be included
  1309. as normal, or \"-<TAG>\" to exclude the tag.
  1310. Note that for the purpose of tag filtering, only the lower-case version of
  1311. all tags will be considered, so that this function will only ever see
  1312. the lower-case version of all tags."
  1313. :group 'org-agenda
  1314. :type 'function)
  1315. (eval-when-compile
  1316. (require 'cl))
  1317. (require 'org)
  1318. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1319. "Execute BODY with point at location given by `org-hd-marker' property.
  1320. If STRING is non-nil, the text property will be fetched from position 0
  1321. in that string. If STRING is nil, it will be fetched from the beginning
  1322. of the current line."
  1323. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1324. 'org-hd-marker string)))
  1325. (with-current-buffer (marker-buffer marker)
  1326. (save-excursion
  1327. (goto-char marker)
  1328. ,@body))))
  1329. (defun org-add-agenda-custom-command (entry)
  1330. "Replace or add a command in `org-agenda-custom-commands'.
  1331. This is mostly for hacking and trying a new command - once the command
  1332. works you probably want to add it to `org-agenda-custom-commands' for good."
  1333. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1334. (if ass
  1335. (setcdr ass (cdr entry))
  1336. (push entry org-agenda-custom-commands))))
  1337. ;;; Define the Org-agenda-mode
  1338. (defvar org-agenda-mode-map (make-sparse-keymap)
  1339. "Keymap for `org-agenda-mode'.")
  1340. (if (fboundp 'defvaralias)
  1341. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1342. (defvar org-agenda-menu) ; defined later in this file.
  1343. (defvar org-agenda-restrict) ; defined later in this file.
  1344. (defvar org-agenda-follow-mode nil)
  1345. (defvar org-agenda-entry-text-mode nil)
  1346. (defvar org-agenda-clockreport-mode nil)
  1347. (defvar org-agenda-show-log nil)
  1348. (defvar org-agenda-redo-command nil)
  1349. (defvar org-agenda-query-string nil)
  1350. (defvar org-agenda-mode-hook nil
  1351. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1352. (defvar org-agenda-type nil)
  1353. (defvar org-agenda-force-single-file nil)
  1354. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1355. (defun org-agenda-mode ()
  1356. "Mode for time-sorted view on action items in Org-mode files.
  1357. The following commands are available:
  1358. \\{org-agenda-mode-map}"
  1359. (interactive)
  1360. (kill-all-local-variables)
  1361. (setq org-agenda-undo-list nil
  1362. org-agenda-pending-undo-list nil
  1363. org-agenda-bulk-marked-entries nil)
  1364. (setq major-mode 'org-agenda-mode)
  1365. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1366. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1367. (setq mode-name "Org-Agenda")
  1368. (use-local-map org-agenda-mode-map)
  1369. (easy-menu-add org-agenda-menu)
  1370. (if org-startup-truncated (setq truncate-lines t))
  1371. (org-set-local 'line-move-visual nil)
  1372. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1373. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1374. ;; Make sure properties are removed when copying text
  1375. (when (boundp 'buffer-substring-filters)
  1376. (org-set-local 'buffer-substring-filters
  1377. (cons (lambda (x)
  1378. (set-text-properties 0 (length x) nil x) x)
  1379. buffer-substring-filters)))
  1380. (unless org-agenda-keep-modes
  1381. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1382. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1383. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1384. org-agenda-show-log org-agenda-start-with-log-mode))
  1385. (easy-menu-change
  1386. '("Agenda") "Agenda Files"
  1387. (append
  1388. (list
  1389. (vector
  1390. (if (get 'org-agenda-files 'org-restrict)
  1391. "Restricted to single file"
  1392. "Edit File List")
  1393. '(org-edit-agenda-file-list)
  1394. (not (get 'org-agenda-files 'org-restrict)))
  1395. "--")
  1396. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1397. (org-agenda-set-mode-name)
  1398. (apply
  1399. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1400. (list 'org-agenda-mode-hook)))
  1401. (substitute-key-definition 'undo 'org-agenda-undo
  1402. org-agenda-mode-map global-map)
  1403. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1404. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1405. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1406. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1407. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1408. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1409. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1410. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1411. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1412. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1413. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1414. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1415. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1416. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1417. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1418. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1419. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1420. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1421. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1422. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1423. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1424. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1425. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1426. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1427. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1428. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1429. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1430. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1431. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1432. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1433. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1434. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1435. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1436. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1437. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1438. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1439. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1440. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1441. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1442. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1443. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1444. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1445. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1446. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1447. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1448. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1449. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1450. (while l (org-defkey org-agenda-mode-map
  1451. (int-to-string (pop l)) 'digit-argument)))
  1452. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1453. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1454. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1455. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1456. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1457. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1458. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1459. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1460. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1461. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1462. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1463. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1464. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1465. 'org-clock-modify-effort-estimate)
  1466. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1467. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1468. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1469. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1470. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1471. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1472. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1473. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1474. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1475. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1476. (substitute-key-definition 'next-line 'org-agenda-next-line
  1477. org-agenda-mode-map global-map)
  1478. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1479. org-agenda-mode-map global-map)
  1480. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1481. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1482. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1483. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1484. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1485. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1486. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1487. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1488. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1489. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1490. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1491. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1492. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1493. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1494. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1495. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1496. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1497. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1498. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1499. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1500. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1501. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1502. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1503. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1504. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1505. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1506. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1507. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1508. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1509. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1510. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1511. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1512. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1513. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1514. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1515. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1516. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1517. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1518. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1519. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1520. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1521. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1522. (when org-agenda-mouse-1-follows-link
  1523. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1524. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1525. '("Agenda"
  1526. ("Agenda Files")
  1527. "--"
  1528. ("Agenda Dates"
  1529. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1530. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1531. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1532. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1533. "--"
  1534. ("View"
  1535. ["Day View" org-agenda-day-view
  1536. :active (org-agenda-check-type nil 'agenda)
  1537. :style radio :selected (equal org-agenda-ndays 1)
  1538. :keys "v d (or just d)"]
  1539. ["Week View" org-agenda-week-view
  1540. :active (org-agenda-check-type nil 'agenda)
  1541. :style radio :selected (equal org-agenda-ndays 7)
  1542. :keys "v w (or just w)"]
  1543. ["Month View" org-agenda-month-view
  1544. :active (org-agenda-check-type nil 'agenda)
  1545. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1546. :keys "v m"]
  1547. ["Year View" org-agenda-year-view
  1548. :active (org-agenda-check-type nil 'agenda)
  1549. :style radio :selected (member org-agenda-ndays '(365 366))
  1550. :keys "v y"]
  1551. "--"
  1552. ["Include Diary" org-agenda-toggle-diary
  1553. :style toggle :selected org-agenda-include-diary
  1554. :active (org-agenda-check-type nil 'agenda)]
  1555. ["Include Deadlines" org-agenda-toggle-deadlines
  1556. :style toggle :selected org-agenda-include-deadlines
  1557. :active (org-agenda-check-type nil 'agenda)]
  1558. ["Use Time Grid" org-agenda-toggle-time-grid
  1559. :style toggle :selected org-agenda-use-time-grid
  1560. :active (org-agenda-check-type nil 'agenda)]
  1561. "--"
  1562. ["Show clock report" org-agenda-clockreport-mode
  1563. :style toggle :selected org-agenda-clockreport-mode
  1564. :active (org-agenda-check-type nil 'agenda)]
  1565. ["Show some entry text" org-agenda-entry-text-mode
  1566. :style toggle :selected org-agenda-entry-text-mode
  1567. :active t]
  1568. "--"
  1569. ["Show Logbook entries" org-agenda-log-mode
  1570. :style toggle :selected org-agenda-show-log
  1571. :active (org-agenda-check-type nil 'agenda 'timeline)
  1572. :keys "v l (or just l)"]
  1573. ["Include archived trees" org-agenda-archives-mode
  1574. :style toggle :selected org-agenda-archives-mode :active t
  1575. :keys "v a"]
  1576. ["Include archive files" (org-agenda-archives-mode t)
  1577. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1578. :keys "v A"]
  1579. "--"
  1580. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1581. ["Write view to file" org-write-agenda t]
  1582. ["Rebuild buffer" org-agenda-redo t]
  1583. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1584. "--"
  1585. ["Show original entry" org-agenda-show t]
  1586. ["Go To (other window)" org-agenda-goto t]
  1587. ["Go To (this window)" org-agenda-switch-to t]
  1588. ["Follow Mode" org-agenda-follow-mode
  1589. :style toggle :selected org-agenda-follow-mode :active t]
  1590. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1591. "--"
  1592. ("TODO"
  1593. ["Cycle TODO" org-agenda-todo t]
  1594. ["Next TODO set" org-agenda-todo-nextset t]
  1595. ["Previous TODO set" org-agenda-todo-previousset t]
  1596. ["Add note" org-agenda-add-note t])
  1597. ("Archive/Refile/Delete"
  1598. ["Archive default" org-agenda-archive-default t]
  1599. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1600. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1601. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1602. ["Archive subtree" org-agenda-archive t]
  1603. "--"
  1604. ["Refile" org-agenda-refile t]
  1605. "--"
  1606. ["Delete subtree" org-agenda-kill t])
  1607. ("Bulk action"
  1608. ["Mark entry" org-agenda-bulk-mark t]
  1609. ["Unmark entry" org-agenda-bulk-unmark t]
  1610. ["Act on all marked" org-agenda-bulk-action t]
  1611. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1612. "--"
  1613. ("Tags and Properties"
  1614. ["Show all Tags" org-agenda-show-tags t]
  1615. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1616. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1617. "--"
  1618. ["Column View" org-columns t])
  1619. ("Deadline/Schedule"
  1620. ["Schedule" org-agenda-schedule t]
  1621. ["Set Deadline" org-agenda-deadline t]
  1622. "--"
  1623. ["Mark item" org-agenda-action :active t :keys "k m"]
  1624. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1625. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1626. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1627. "--"
  1628. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1629. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1630. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1631. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1632. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1633. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1634. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1635. ("Clock and Effort"
  1636. ["Clock in" org-agenda-clock-in t]
  1637. ["Clock out" org-agenda-clock-out t]
  1638. ["Clock cancel" org-agenda-clock-cancel t]
  1639. ["Goto running clock" org-clock-goto t]
  1640. "--"
  1641. ["Set Effort" org-agenda-set-effort t]
  1642. ["Change clocked effort" org-clock-modify-effort-estimate
  1643. (org-clock-is-active)])
  1644. ("Priority"
  1645. ["Set Priority" org-agenda-priority t]
  1646. ["Increase Priority" org-agenda-priority-up t]
  1647. ["Decrease Priority" org-agenda-priority-down t]
  1648. ["Show Priority" org-agenda-show-priority t])
  1649. ("Calendar/Diary"
  1650. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1651. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1652. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1653. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1654. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1655. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1656. "--"
  1657. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1658. "--"
  1659. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1660. "--"
  1661. ("MobileOrg"
  1662. ["Push Files and Views" org-mobile-push t]
  1663. ["Get Captured and Flagged" org-mobile-pull t]
  1664. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1665. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1666. "--"
  1667. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1668. "--"
  1669. ["Quit" org-agenda-quit t]
  1670. ["Exit and Release Buffers" org-agenda-exit t]
  1671. ))
  1672. ;;; Agenda undo
  1673. (defvar org-agenda-allow-remote-undo t
  1674. "Non-nil means allow remote undo from the agenda buffer.")
  1675. (defvar org-agenda-undo-list nil
  1676. "List of undoable operations in the agenda since last refresh.")
  1677. (defvar org-agenda-undo-has-started-in nil
  1678. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1679. (defvar org-agenda-pending-undo-list nil
  1680. "In a series of undo commands, this is the list of remaining undo items.")
  1681. (defun org-agenda-undo ()
  1682. "Undo a remote editing step in the agenda.
  1683. This undoes changes both in the agenda buffer and in the remote buffer
  1684. that have been changed along."
  1685. (interactive)
  1686. (or org-agenda-allow-remote-undo
  1687. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1688. (if (not (eq this-command last-command))
  1689. (setq org-agenda-undo-has-started-in nil
  1690. org-agenda-pending-undo-list org-agenda-undo-list))
  1691. (if (not org-agenda-pending-undo-list)
  1692. (error "No further undo information"))
  1693. (let* ((entry (pop org-agenda-pending-undo-list))
  1694. buf line cmd rembuf)
  1695. (setq cmd (pop entry) line (pop entry))
  1696. (setq rembuf (nth 2 entry))
  1697. (org-with-remote-undo rembuf
  1698. (while (bufferp (setq buf (pop entry)))
  1699. (if (pop entry)
  1700. (with-current-buffer buf
  1701. (let ((last-undo-buffer buf)
  1702. (inhibit-read-only t))
  1703. (unless (memq buf org-agenda-undo-has-started-in)
  1704. (push buf org-agenda-undo-has-started-in)
  1705. (make-local-variable 'pending-undo-list)
  1706. (undo-start))
  1707. (while (and pending-undo-list
  1708. (listp pending-undo-list)
  1709. (not (car pending-undo-list)))
  1710. (pop pending-undo-list))
  1711. (undo-more 1))))))
  1712. (org-goto-line line)
  1713. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1714. (defun org-verify-change-for-undo (l1 l2)
  1715. "Verify that a real change occurred between the undo lists L1 and L2."
  1716. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1717. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1718. (not (eq l1 l2)))
  1719. ;;; Agenda dispatch
  1720. (defvar org-agenda-restrict nil)
  1721. (defvar org-agenda-restrict-begin (make-marker))
  1722. (defvar org-agenda-restrict-end (make-marker))
  1723. (defvar org-agenda-last-dispatch-buffer nil)
  1724. (defvar org-agenda-overriding-restriction nil)
  1725. ;;;###autoload
  1726. (defun org-agenda (&optional arg keys restriction)
  1727. "Dispatch agenda commands to collect entries to the agenda buffer.
  1728. Prompts for a command to execute. Any prefix arg will be passed
  1729. on to the selected command. The default selections are:
  1730. a Call `org-agenda-list' to display the agenda for current day or week.
  1731. t Call `org-todo-list' to display the global todo list.
  1732. T Call `org-todo-list' to display the global todo list, select only
  1733. entries with a specific TODO keyword (the user gets a prompt).
  1734. m Call `org-tags-view' to display headlines with tags matching
  1735. a condition (the user is prompted for the condition).
  1736. M Like `m', but select only TODO entries, no ordinary headlines.
  1737. L Create a timeline for the current buffer.
  1738. e Export views to associated files.
  1739. s Search entries for keywords.
  1740. / Multi occur across all agenda files and also files listed
  1741. in `org-agenda-text-search-extra-files'.
  1742. < Restrict agenda commands to buffer, subtree, or region.
  1743. Press several times to get the desired effect.
  1744. > Remove a previous restriction.
  1745. # List \"stuck\" projects.
  1746. ! Configure what \"stuck\" means.
  1747. C Configure custom agenda commands.
  1748. More commands can be added by configuring the variable
  1749. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1750. searches can be pre-defined in this way.
  1751. If the current buffer is in Org-mode and visiting a file, you can also
  1752. first press `<' once to indicate that the agenda should be temporarily
  1753. \(until the next use of \\[org-agenda]) restricted to the current file.
  1754. Pressing `<' twice means to restrict to the current subtree or region
  1755. \(if active)."
  1756. (interactive "P")
  1757. (catch 'exit
  1758. (let* ((prefix-descriptions nil)
  1759. (org-agenda-window-setup (if (equal (buffer-name)
  1760. org-agenda-buffer-name)
  1761. 'current-window
  1762. org-agenda-window-setup))
  1763. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1764. (org-agenda-custom-commands
  1765. ;; normalize different versions
  1766. (delq nil
  1767. (mapcar
  1768. (lambda (x)
  1769. (cond ((stringp (cdr x))
  1770. (push x prefix-descriptions)
  1771. nil)
  1772. ((stringp (nth 1 x)) x)
  1773. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1774. (t (cons (car x) (cons "" (cdr x))))))
  1775. org-agenda-custom-commands)))
  1776. (buf (current-buffer))
  1777. (bfn (buffer-file-name (buffer-base-buffer)))
  1778. entry key type match lprops ans)
  1779. ;; Turn off restriction unless there is an overriding one,
  1780. (unless org-agenda-overriding-restriction
  1781. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1782. ;; There is a request to keep the file list in place
  1783. (put 'org-agenda-files 'org-restrict nil))
  1784. (setq org-agenda-restrict nil)
  1785. (move-marker org-agenda-restrict-begin nil)
  1786. (move-marker org-agenda-restrict-end nil))
  1787. ;; Delete old local properties
  1788. (put 'org-agenda-redo-command 'org-lprops nil)
  1789. ;; Remember where this call originated
  1790. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1791. (unless keys
  1792. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1793. keys (car ans)
  1794. restriction (cdr ans)))
  1795. ;; Establish the restriction, if any
  1796. (when (and (not org-agenda-overriding-restriction) restriction)
  1797. (put 'org-agenda-files 'org-restrict (list bfn))
  1798. (cond
  1799. ((eq restriction 'region)
  1800. (setq org-agenda-restrict t)
  1801. (move-marker org-agenda-restrict-begin (region-beginning))
  1802. (move-marker org-agenda-restrict-end (region-end)))
  1803. ((eq restriction 'subtree)
  1804. (save-excursion
  1805. (setq org-agenda-restrict t)
  1806. (org-back-to-heading t)
  1807. (move-marker org-agenda-restrict-begin (point))
  1808. (move-marker org-agenda-restrict-end
  1809. (progn (org-end-of-subtree t)))))))
  1810. ;; For example the todo list should not need it (but does...)
  1811. (cond
  1812. ((setq entry (assoc keys org-agenda-custom-commands))
  1813. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1814. (progn
  1815. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1816. lprops (nth 4 entry))
  1817. (put 'org-agenda-redo-command 'org-lprops lprops)
  1818. (cond
  1819. ((eq type 'agenda)
  1820. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1821. ((eq type 'alltodo)
  1822. (org-let lprops '(org-todo-list current-prefix-arg)))
  1823. ((eq type 'search)
  1824. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1825. ((eq type 'stuck)
  1826. (org-let lprops '(org-agenda-list-stuck-projects
  1827. current-prefix-arg)))
  1828. ((eq type 'tags)
  1829. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1830. ((eq type 'tags-todo)
  1831. (org-let lprops '(org-tags-view '(4) match)))
  1832. ((eq type 'todo)
  1833. (org-let lprops '(org-todo-list match)))
  1834. ((eq type 'tags-tree)
  1835. (org-check-for-org-mode)
  1836. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1837. ((eq type 'todo-tree)
  1838. (org-check-for-org-mode)
  1839. (org-let lprops
  1840. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1841. (regexp-quote match) "\\>"))))
  1842. ((eq type 'occur-tree)
  1843. (org-check-for-org-mode)
  1844. (org-let lprops '(org-occur match)))
  1845. ((functionp type)
  1846. (org-let lprops '(funcall type match)))
  1847. ((fboundp type)
  1848. (org-let lprops '(funcall type match)))
  1849. (t (error "Invalid custom agenda command type %s" type))))
  1850. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1851. ((equal keys "C")
  1852. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1853. (customize-variable 'org-agenda-custom-commands))
  1854. ((equal keys "a") (call-interactively 'org-agenda-list))
  1855. ((equal keys "s") (call-interactively 'org-search-view))
  1856. ((equal keys "t") (call-interactively 'org-todo-list))
  1857. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1858. ((equal keys "m") (call-interactively 'org-tags-view))
  1859. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1860. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1861. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1862. (org-add-hook
  1863. 'post-command-hook
  1864. (lambda ()
  1865. (unless (current-message)
  1866. (let* ((m (org-agenda-get-any-marker))
  1867. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1868. (when note
  1869. (message (concat
  1870. "FLAGGING-NOTE ([?] for more info): "
  1871. (org-add-props
  1872. (replace-regexp-in-string
  1873. "\\\\n" "//"
  1874. (copy-sequence note))
  1875. nil 'face 'org-warning)))))))
  1876. t t))
  1877. ((equal keys "L")
  1878. (unless (org-mode-p)
  1879. (error "This is not an Org-mode file"))
  1880. (unless restriction
  1881. (put 'org-agenda-files 'org-restrict (list bfn))
  1882. (org-call-with-arg 'org-timeline arg)))
  1883. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1884. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1885. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1886. (t (error "Invalid agenda key"))))))
  1887. (defun org-agenda-normalize-custom-commands (cmds)
  1888. (delq nil
  1889. (mapcar
  1890. (lambda (x)
  1891. (cond ((stringp (cdr x)) nil)
  1892. ((stringp (nth 1 x)) x)
  1893. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1894. (t (cons (car x) (cons "" (cdr x))))))
  1895. cmds)))
  1896. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1897. "The user interface for selecting an agenda command."
  1898. (catch 'exit
  1899. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1900. (restrict-ok (and bfn (org-mode-p)))
  1901. (region-p (org-region-active-p))
  1902. (custom org-agenda-custom-commands)
  1903. (selstring "")
  1904. restriction second-time
  1905. c entry key type match prefixes rmheader header-end custom1 desc
  1906. line lines left right n n1)
  1907. (save-window-excursion
  1908. (delete-other-windows)
  1909. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1910. (erase-buffer)
  1911. (insert (eval-when-compile
  1912. (let ((header
  1913. "
  1914. Press key for an agenda command: < Buffer, subtree/region restriction
  1915. -------------------------------- > Remove restriction
  1916. a Agenda for current week or day e Export agenda views
  1917. t List of all TODO entries T Entries with special TODO kwd
  1918. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1919. L Timeline for current buffer # List stuck projects (!=configure)
  1920. s Search for keywords C Configure custom agenda commands
  1921. / Multi-occur ? Find :FLAGGED: entries
  1922. ")
  1923. (start 0))
  1924. (while (string-match
  1925. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1926. header start)
  1927. (setq start (match-end 0))
  1928. (add-text-properties (match-beginning 2) (match-end 2)
  1929. '(face bold) header))
  1930. header)))
  1931. (setq header-end (move-marker (make-marker) (point)))
  1932. (while t
  1933. (setq custom1 custom)
  1934. (when (eq rmheader t)
  1935. (org-goto-line 1)
  1936. (re-search-forward ":" nil t)
  1937. (delete-region (match-end 0) (point-at-eol))
  1938. (forward-char 1)
  1939. (looking-at "-+")
  1940. (delete-region (match-end 0) (point-at-eol))
  1941. (move-marker header-end (match-end 0)))
  1942. (goto-char header-end)
  1943. (delete-region (point) (point-max))
  1944. ;; Produce all the lines that describe custom commands and prefixes
  1945. (setq lines nil)
  1946. (while (setq entry (pop custom1))
  1947. (setq key (car entry) desc (nth 1 entry)
  1948. type (nth 2 entry)
  1949. match (nth 3 entry))
  1950. (if (> (length key) 1)
  1951. (add-to-list 'prefixes (string-to-char key))
  1952. (setq line
  1953. (format
  1954. "%-4s%-14s"
  1955. (org-add-props (copy-sequence key)
  1956. '(face bold))
  1957. (cond
  1958. ((string-match "\\S-" desc) desc)
  1959. ((eq type 'agenda) "Agenda for current week or day")
  1960. ((eq type 'alltodo) "List of all TODO entries")
  1961. ((eq type 'search) "Word search")
  1962. ((eq type 'stuck) "List of stuck projects")
  1963. ((eq type 'todo) "TODO keyword")
  1964. ((eq type 'tags) "Tags query")
  1965. ((eq type 'tags-todo) "Tags (TODO)")
  1966. ((eq type 'tags-tree) "Tags tree")
  1967. ((eq type 'todo-tree) "TODO kwd tree")
  1968. ((eq type 'occur-tree) "Occur tree")
  1969. ((functionp type) (if (symbolp type)
  1970. (symbol-name type)
  1971. "Lambda expression"))
  1972. (t "???"))))
  1973. (if org-agenda-menu-show-matcher
  1974. (setq line
  1975. (concat line ": "
  1976. (cond
  1977. ((stringp match)
  1978. (setq match (copy-sequence match))
  1979. (org-add-props match nil 'face 'org-warning))
  1980. (match
  1981. (format "set of %d commands" (length match)))
  1982. (t ""))))
  1983. (if (org-string-nw-p match)
  1984. (add-text-properties
  1985. 0 (length line) (list 'help-echo
  1986. (concat "Matcher: "match)) line)))
  1987. (push line lines)))
  1988. (setq lines (nreverse lines))
  1989. (when prefixes
  1990. (mapc (lambda (x)
  1991. (push
  1992. (format "%s %s"
  1993. (org-add-props (char-to-string x)
  1994. nil 'face 'bold)
  1995. (or (cdr (assoc (concat selstring
  1996. (char-to-string x))
  1997. prefix-descriptions))
  1998. "Prefix key"))
  1999. lines))
  2000. prefixes))
  2001. ;; Check if we should display in two columns
  2002. (if org-agenda-menu-two-column
  2003. (progn
  2004. (setq n (length lines)
  2005. n1 (+ (/ n 2) (mod n 2))
  2006. right (nthcdr n1 lines)
  2007. left (copy-sequence lines))
  2008. (setcdr (nthcdr (1- n1) left) nil))
  2009. (setq left lines right nil))
  2010. (while left
  2011. (insert "\n" (pop left))
  2012. (when right
  2013. (if (< (current-column) 40)
  2014. (move-to-column 40 t)
  2015. (insert " "))
  2016. (insert (pop right))))
  2017. ;; Make the window the right size
  2018. (goto-char (point-min))
  2019. (if second-time
  2020. (if (not (pos-visible-in-window-p (point-max)))
  2021. (org-fit-window-to-buffer))
  2022. (setq second-time t)
  2023. (org-fit-window-to-buffer))
  2024. ;; Ask for selection
  2025. (message "Press key for agenda command%s:"
  2026. (if (or restrict-ok org-agenda-overriding-restriction)
  2027. (if org-agenda-overriding-restriction
  2028. " (restriction lock active)"
  2029. (if restriction
  2030. (format " (restricted to %s)" restriction)
  2031. " (unrestricted)"))
  2032. ""))
  2033. (setq c (read-char-exclusive))
  2034. (message "")
  2035. (cond
  2036. ((assoc (char-to-string c) custom)
  2037. (setq selstring (concat selstring (char-to-string c)))
  2038. (throw 'exit (cons selstring restriction)))
  2039. ((memq c prefixes)
  2040. (setq selstring (concat selstring (char-to-string c))
  2041. prefixes nil
  2042. rmheader (or rmheader t)
  2043. custom (delq nil (mapcar
  2044. (lambda (x)
  2045. (if (or (= (length (car x)) 1)
  2046. (/= (string-to-char (car x)) c))
  2047. nil
  2048. (cons (substring (car x) 1) (cdr x))))
  2049. custom))))
  2050. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2051. (message "Restriction is only possible in Org-mode buffers")
  2052. (ding) (sit-for 1))
  2053. ((eq c ?1)
  2054. (org-agenda-remove-restriction-lock 'noupdate)
  2055. (setq restriction 'buffer))
  2056. ((eq c ?0)
  2057. (org-agenda-remove-restriction-lock 'noupdate)
  2058. (setq restriction (if region-p 'region 'subtree)))
  2059. ((eq c ?<)
  2060. (org-agenda-remove-restriction-lock 'noupdate)
  2061. (setq restriction
  2062. (cond
  2063. ((eq restriction 'buffer)
  2064. (if region-p 'region 'subtree))
  2065. ((memq restriction '(subtree region))
  2066. nil)
  2067. (t 'buffer))))
  2068. ((eq c ?>)
  2069. (org-agenda-remove-restriction-lock 'noupdate)
  2070. (setq restriction nil))
  2071. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2072. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2073. ((and (> (length selstring) 0) (eq c ?\d))
  2074. (delete-window)
  2075. (org-agenda-get-restriction-and-command prefix-descriptions))
  2076. ((equal c ?q) (error "Abort"))
  2077. (t (error "Invalid key %c" c))))))))
  2078. (defun org-run-agenda-series (name series)
  2079. (org-let (nth 1 series) '(org-prepare-agenda name))
  2080. (let* ((org-agenda-multi t)
  2081. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2082. (cmds (car series))
  2083. (gprops (nth 1 series))
  2084. match ;; The byte compiler incorrectly complains about this. Keep it!
  2085. cmd type lprops)
  2086. (while (setq cmd (pop cmds))
  2087. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2088. (cond
  2089. ((eq type 'agenda)
  2090. (org-let2 gprops lprops
  2091. '(call-interactively 'org-agenda-list)))
  2092. ((eq type 'alltodo)
  2093. (org-let2 gprops lprops
  2094. '(call-interactively 'org-todo-list)))
  2095. ((eq type 'search)
  2096. (org-let2 gprops lprops
  2097. '(org-search-view current-prefix-arg match nil)))
  2098. ((eq type 'stuck)
  2099. (org-let2 gprops lprops
  2100. '(call-interactively 'org-agenda-list-stuck-projects)))
  2101. ((eq type 'tags)
  2102. (org-let2 gprops lprops
  2103. '(org-tags-view current-prefix-arg match)))
  2104. ((eq type 'tags-todo)
  2105. (org-let2 gprops lprops
  2106. '(org-tags-view '(4) match)))
  2107. ((eq type 'todo)
  2108. (org-let2 gprops lprops
  2109. '(org-todo-list match)))
  2110. ((fboundp type)
  2111. (org-let2 gprops lprops
  2112. '(funcall type match)))
  2113. (t (error "Invalid type in command series"))))
  2114. (widen)
  2115. (setq org-agenda-redo-command redo)
  2116. (goto-char (point-min)))
  2117. (org-fit-agenda-window)
  2118. (org-let (nth 1 series) '(org-finalize-agenda)))
  2119. ;;;###autoload
  2120. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2121. "Run an agenda command in batch mode and send the result to STDOUT.
  2122. If CMD-KEY is a string of length 1, it is used as a key in
  2123. `org-agenda-custom-commands' and triggers this command. If it is a
  2124. longer string it is used as a tags/todo match string.
  2125. Parameters are alternating variable names and values that will be bound
  2126. before running the agenda command."
  2127. (let (pars)
  2128. (while parameters
  2129. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2130. (if (> (length cmd-key) 2)
  2131. (eval (list 'let (nreverse pars)
  2132. (list 'org-tags-view nil cmd-key)))
  2133. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2134. (set-buffer org-agenda-buffer-name)
  2135. (princ (org-encode-for-stdout (buffer-string)))))
  2136. ;(defun org-encode-for-stdout (string)
  2137. ; (if (fboundp 'encode-coding-string)
  2138. ; (encode-coding-string string buffer-file-coding-system)
  2139. ; string))
  2140. (defun org-encode-for-stdout (string)
  2141. string)
  2142. (defvar org-agenda-info nil)
  2143. ;;;###autoload
  2144. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2145. "Run an agenda command in batch mode and send the result to STDOUT.
  2146. If CMD-KEY is a string of length 1, it is used as a key in
  2147. `org-agenda-custom-commands' and triggers this command. If it is a
  2148. longer string it is used as a tags/todo match string.
  2149. Parameters are alternating variable names and values that will be bound
  2150. before running the agenda command.
  2151. The output gives a line for each selected agenda item. Each
  2152. item is a list of comma-separated values, like this:
  2153. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2154. category The category of the item
  2155. head The headline, without TODO kwd, TAGS and PRIORITY
  2156. type The type of the agenda entry, can be
  2157. todo selected in TODO match
  2158. tagsmatch selected in tags match
  2159. diary imported from diary
  2160. deadline a deadline on given date
  2161. scheduled scheduled on given date
  2162. timestamp entry has timestamp on given date
  2163. closed entry was closed on given date
  2164. upcoming-deadline warning about deadline
  2165. past-scheduled forwarded scheduled item
  2166. block entry has date block including g. date
  2167. todo The todo keyword, if any
  2168. tags All tags including inherited ones, separated by colons
  2169. date The relevant date, like 2007-2-14
  2170. time The time, like 15:00-16:50
  2171. extra Sting with extra planning info
  2172. priority-l The priority letter if any was given
  2173. priority-n The computed numerical priority
  2174. agenda-day The day in the agenda where this is listed"
  2175. (let (pars)
  2176. (while parameters
  2177. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2178. (push (list 'org-agenda-remove-tags t) pars)
  2179. (if (> (length cmd-key) 2)
  2180. (eval (list 'let (nreverse pars)
  2181. (list 'org-tags-view nil cmd-key)))
  2182. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2183. (set-buffer org-agenda-buffer-name)
  2184. (let* ((lines (org-split-string (buffer-string) "\n"))
  2185. line)
  2186. (while (setq line (pop lines))
  2187. (catch 'next
  2188. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2189. (setq org-agenda-info
  2190. (org-fix-agenda-info (text-properties-at 0 line)))
  2191. (princ
  2192. (org-encode-for-stdout
  2193. (mapconcat 'org-agenda-export-csv-mapper
  2194. '(org-category txt type todo tags date time extra
  2195. priority-letter priority agenda-day)
  2196. ",")))
  2197. (princ "\n"))))))
  2198. (defun org-fix-agenda-info (props)
  2199. "Make sure all properties on an agenda item have a canonical form.
  2200. This ensures the export commands can easily use it."
  2201. (let (tmp re)
  2202. (when (setq tmp (plist-get props 'tags))
  2203. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2204. (when (setq tmp (plist-get props 'date))
  2205. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2206. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2207. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2208. (setq tmp (calendar-date-string tmp)))
  2209. (setq props (plist-put props 'date tmp)))
  2210. (when (setq tmp (plist-get props 'day))
  2211. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2212. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2213. (setq tmp (calendar-date-string tmp)))
  2214. (setq props (plist-put props 'day tmp))
  2215. (setq props (plist-put props 'agenda-day tmp)))
  2216. (when (setq tmp (plist-get props 'txt))
  2217. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2218. (plist-put props 'priority-letter (match-string 1 tmp))
  2219. (setq tmp (replace-match "" t t tmp)))
  2220. (when (and (setq re (plist-get props 'org-todo-regexp))
  2221. (setq re (concat "\\`\\.*" re " ?"))
  2222. (string-match re tmp))
  2223. (plist-put props 'todo (match-string 1 tmp))
  2224. (setq tmp (replace-match "" t t tmp)))
  2225. (plist-put props 'txt tmp)))
  2226. props)
  2227. (defun org-agenda-export-csv-mapper (prop)
  2228. (let ((res (plist-get org-agenda-info prop)))
  2229. (setq res
  2230. (cond
  2231. ((not res) "")
  2232. ((stringp res) res)
  2233. (t (prin1-to-string res))))
  2234. (while (string-match "," res)
  2235. (setq res (replace-match ";" t t res)))
  2236. (org-trim res)))
  2237. ;;;###autoload
  2238. (defun org-store-agenda-views (&rest parameters)
  2239. (interactive)
  2240. (eval (list 'org-batch-store-agenda-views)))
  2241. ;; FIXME, why is this a macro?????
  2242. ;;;###autoload
  2243. (defmacro org-batch-store-agenda-views (&rest parameters)
  2244. "Run all custom agenda commands that have a file argument."
  2245. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2246. (pop-up-frames nil)
  2247. (dir default-directory)
  2248. pars cmd thiscmdkey files opts cmd-or-set)
  2249. (while parameters
  2250. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2251. (setq pars (reverse pars))
  2252. (save-window-excursion
  2253. (while cmds
  2254. (setq cmd (pop cmds)
  2255. thiscmdkey (car cmd)
  2256. cmd-or-set (nth 2 cmd)
  2257. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2258. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2259. (if (stringp files) (setq files (list files)))
  2260. (when files
  2261. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2262. (list 'org-agenda nil thiscmdkey)))
  2263. (set-buffer org-agenda-buffer-name)
  2264. (while files
  2265. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2266. (list 'org-write-agenda
  2267. (expand-file-name (pop files) dir) nil t))))
  2268. (and (get-buffer org-agenda-buffer-name)
  2269. (kill-buffer org-agenda-buffer-name)))))))
  2270. (defun org-agenda-mark-header-line (pos)
  2271. "Mark the line at POS as an agenda structure header."
  2272. (save-excursion
  2273. (goto-char pos)
  2274. (put-text-property (point-at-bol) (point-at-eol)
  2275. 'org-agenda-structural-header t)
  2276. (when org-agenda-title-append
  2277. (put-text-property (point-at-bol) (point-at-eol)
  2278. 'org-agenda-title-append org-agenda-title-append))))
  2279. (defvar org-mobile-creating-agendas)
  2280. (defun org-write-agenda (file &optional open nosettings)
  2281. "Write the current buffer (an agenda view) as a file.
  2282. Depending on the extension of the file name, plain text (.txt),
  2283. HTML (.html or .htm) or Postscript (.ps) is produced.
  2284. If the extension is .ics, run icalendar export over all files used
  2285. to construct the agenda and limit the export to entries listed in the
  2286. agenda now.
  2287. With prefix argument OPEN, open the new file immediately.
  2288. If NOSETTINGS is given, do not scope the settings of
  2289. `org-agenda-exporter-settings' into the export commands. This is used when
  2290. the settings have already been scoped and we do not wish to overrule other,
  2291. higher priority settings."
  2292. (interactive "FWrite agenda to file: \nP")
  2293. (if (not (file-writable-p file))
  2294. (error "Cannot write agenda to file %s" file))
  2295. (org-let (if nosettings nil org-agenda-exporter-settings)
  2296. '(save-excursion
  2297. (save-window-excursion
  2298. (org-agenda-mark-filtered-text)
  2299. (let ((bs (copy-sequence (buffer-string))) beg)
  2300. (org-agenda-unmark-filtered-text)
  2301. (with-temp-buffer
  2302. (rename-buffer "Agenda View" t)
  2303. (set-buffer-modified-p nil)
  2304. (insert bs)
  2305. (org-agenda-remove-marked-text 'org-filtered)
  2306. (while (setq beg (text-property-any (point-min) (point-max)
  2307. 'org-filtered t))
  2308. (delete-region
  2309. beg (or (next-single-property-change beg 'org-filtered)
  2310. (point-max))))
  2311. (run-hooks 'org-agenda-before-write-hook)
  2312. (cond
  2313. ((org-bound-and-true-p org-mobile-creating-agendas)
  2314. (org-mobile-write-agenda-for-mobile file))
  2315. ((string-match "\\.html?\\'" file)
  2316. (require 'htmlize)
  2317. (set-buffer (htmlize-buffer (current-buffer)))
  2318. (when (and org-agenda-export-html-style
  2319. (string-match "<style>" org-agenda-export-html-style))
  2320. ;; replace <style> section with org-agenda-export-html-style
  2321. (goto-char (point-min))
  2322. (kill-region (- (search-forward "<style") 6)
  2323. (search-forward "</style>"))
  2324. (insert org-agenda-export-html-style))
  2325. (write-file file)
  2326. (kill-buffer (current-buffer))
  2327. (message "HTML written to %s" file))
  2328. ((string-match "\\.ps\\'" file)
  2329. (require 'ps-print)
  2330. (ps-print-buffer-with-faces file)
  2331. (message "Postscript written to %s" file))
  2332. ((string-match "\\.pdf\\'" file)
  2333. (require 'ps-print)
  2334. (ps-print-buffer-with-faces
  2335. (concat (file-name-sans-extension file) ".ps"))
  2336. (call-process "ps2pdf" nil nil nil
  2337. (expand-file-name
  2338. (concat (file-name-sans-extension file) ".ps"))
  2339. (expand-file-name file))
  2340. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2341. (message "PDF written to %s" file))
  2342. ((string-match "\\.ics\\'" file)
  2343. (require 'org-icalendar)
  2344. (let ((org-agenda-marker-table
  2345. (org-create-marker-find-array
  2346. (org-agenda-collect-markers)))
  2347. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2348. (org-combined-agenda-icalendar-file file))
  2349. (apply 'org-export-icalendar 'combine
  2350. (org-agenda-files nil 'ifmode))))
  2351. (t
  2352. (let ((bs (buffer-string)))
  2353. (find-file file)
  2354. (erase-buffer)
  2355. (insert bs)
  2356. (save-buffer 0)
  2357. (kill-buffer (current-buffer))
  2358. (message "Plain text written to %s" file))))))))
  2359. (set-buffer org-agenda-buffer-name))
  2360. (when open (org-open-file file)))
  2361. (defvar org-agenda-filter-overlays nil)
  2362. (defun org-agenda-mark-filtered-text ()
  2363. "Mark all text hidden by filtering with a text property."
  2364. (let ((inhibit-read-only t))
  2365. (mapc
  2366. (lambda (o)
  2367. (when (equal (overlay-buffer o) (current-buffer))
  2368. (put-text-property
  2369. (overlay-start o) (overlay-end o)
  2370. 'org-filtered t)))
  2371. org-agenda-filter-overlays)))
  2372. (defun org-agenda-unmark-filtered-text ()
  2373. "Remove the filtering text property."
  2374. (let ((inhibit-read-only t))
  2375. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2376. (defun org-agenda-remove-marked-text (property &optional value)
  2377. "Delete all text marked with VALUE of PROPERTY.
  2378. VALUE defaults to t."
  2379. (let (beg)
  2380. (setq value (or value t))
  2381. (while (setq beg (text-property-any (point-min) (point-max)
  2382. property value))
  2383. (delete-region
  2384. beg (or (next-single-property-change beg 'org-filtered)
  2385. (point-max))))))
  2386. (defun org-agenda-add-entry-text ()
  2387. "Add entry text to agenda lines.
  2388. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2389. entry text following headings shown in the agenda.
  2390. Drawers will be excluded, also the line with scheduling/deadline info."
  2391. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2392. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2393. (let (m txt)
  2394. (goto-char (point-min))
  2395. (while (not (eobp))
  2396. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2397. (beginning-of-line 2)
  2398. (setq txt (org-agenda-get-some-entry-text
  2399. m org-agenda-add-entry-text-maxlines " > "))
  2400. (end-of-line 1)
  2401. (if (string-match "\\S-" txt)
  2402. (insert "\n" txt)
  2403. (or (eobp) (forward-char 1))))))))
  2404. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2405. &rest keep)
  2406. "Extract entry text from MARKER, at most N-LINES lines.
  2407. This will ignore drawers etc, just get the text.
  2408. If INDENT is given, prefix every line with this string. If KEEP is
  2409. given, it is a list of symbols, defining stuff that should not be
  2410. removed from the entry content. Currently only `planning' is allowed here."
  2411. (let (txt drawer-re kwd-time-re ind)
  2412. (save-excursion
  2413. (with-current-buffer (marker-buffer marker)
  2414. (if (not (org-mode-p))
  2415. (setq txt "")
  2416. (save-excursion
  2417. (save-restriction
  2418. (widen)
  2419. (goto-char marker)
  2420. (end-of-line 1)
  2421. (setq txt (buffer-substring
  2422. (min (1+ (point)) (point-max))
  2423. (progn (outline-next-heading) (point)))
  2424. drawer-re org-drawer-regexp
  2425. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2426. ".*\n?"))
  2427. (with-temp-buffer
  2428. (insert txt)
  2429. (when org-agenda-add-entry-text-descriptive-links
  2430. (goto-char (point-min))
  2431. (while (org-activate-bracket-links (point-max))
  2432. (add-text-properties (match-beginning 0) (match-end 0)
  2433. '(face org-link))))
  2434. (goto-char (point-min))
  2435. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2436. (set-text-properties (match-beginning 0) (match-end 0)
  2437. nil))
  2438. (goto-char (point-min))
  2439. (while (re-search-forward drawer-re nil t)
  2440. (delete-region
  2441. (match-beginning 0)
  2442. (progn (re-search-forward
  2443. "^[ \t]*:END:.*\n?" nil 'move)
  2444. (point))))
  2445. (unless (member 'planning keep)
  2446. (goto-char (point-min))
  2447. (while (re-search-forward kwd-time-re nil t)
  2448. (replace-match "")))
  2449. (goto-char (point-min))
  2450. (when org-agenda-entry-text-exclude-regexps
  2451. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2452. (while (setq re (pop re-list))
  2453. (goto-char (point-min))
  2454. (while (re-search-forward re nil t)
  2455. (replace-match "")))))
  2456. (goto-char (point-max))
  2457. (skip-chars-backward " \t\n")
  2458. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2459. ;; find and remove min common indentation
  2460. (goto-char (point-min))
  2461. (untabify (point-min) (point-max))
  2462. (setq ind (org-get-indentation))
  2463. (while (not (eobp))
  2464. (unless (looking-at "[ \t]*$")
  2465. (setq ind (min ind (org-get-indentation))))
  2466. (beginning-of-line 2))
  2467. (goto-char (point-min))
  2468. (while (not (eobp))
  2469. (unless (looking-at "[ \t]*$")
  2470. (move-to-column ind)
  2471. (delete-region (point-at-bol) (point)))
  2472. (beginning-of-line 2))
  2473. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2474. (goto-char (point-min))
  2475. (when indent
  2476. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2477. (replace-match indent t t)))
  2478. (goto-char (point-min))
  2479. (while (looking-at "[ \t]*\n") (replace-match ""))
  2480. (goto-char (point-max))
  2481. (when (> (org-current-line)
  2482. n-lines)
  2483. (org-goto-line (1+ n-lines))
  2484. (backward-char 1))
  2485. (setq txt (buffer-substring (point-min) (point)))))))))
  2486. txt))
  2487. (defun org-agenda-collect-markers ()
  2488. "Collect the markers pointing to entries in the agenda buffer."
  2489. (let (m markers)
  2490. (save-excursion
  2491. (goto-char (point-min))
  2492. (while (not (eobp))
  2493. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2494. (org-get-at-bol 'org-marker)))
  2495. (push m markers))
  2496. (beginning-of-line 2)))
  2497. (nreverse markers)))
  2498. (defun org-create-marker-find-array (marker-list)
  2499. "Create a alist of files names with all marker positions in that file."
  2500. (let (f tbl m a p)
  2501. (while (setq m (pop marker-list))
  2502. (setq p (marker-position m)
  2503. f (buffer-file-name (or (buffer-base-buffer
  2504. (marker-buffer m))
  2505. (marker-buffer m))))
  2506. (if (setq a (assoc f tbl))
  2507. (push (marker-position m) (cdr a))
  2508. (push (list f p) tbl)))
  2509. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2510. tbl)))
  2511. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2512. (defun org-check-agenda-marker-table ()
  2513. "Check of the current entry is on the marker list."
  2514. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2515. a)
  2516. (and (setq a (assoc file org-agenda-marker-table))
  2517. (save-match-data
  2518. (save-excursion
  2519. (org-back-to-heading t)
  2520. (member (point) (cdr a)))))))
  2521. (defun org-check-for-org-mode ()
  2522. "Make sure current buffer is in org-mode. Error if not."
  2523. (or (org-mode-p)
  2524. (error "Cannot execute org-mode agenda command on buffer in %s"
  2525. major-mode)))
  2526. (defun org-fit-agenda-window ()
  2527. "Fit the window to the buffer size."
  2528. (and (memq org-agenda-window-setup '(reorganize-frame))
  2529. (fboundp 'fit-window-to-buffer)
  2530. (org-fit-window-to-buffer
  2531. nil
  2532. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2533. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2534. ;;; Agenda prepare and finalize
  2535. (defvar org-agenda-multi nil) ; dynamically scoped
  2536. (defvar org-agenda-buffer-name "*Org Agenda*")
  2537. (defvar org-pre-agenda-window-conf nil)
  2538. (defvar org-agenda-columns-active nil)
  2539. (defvar org-agenda-name nil)
  2540. (defvar org-agenda-filter nil)
  2541. (defvar org-agenda-filter-preset nil
  2542. "A preset of the tags filter used for secondary agenda filtering.
  2543. This must be a list of strings, each string must be a single tag preceded
  2544. by \"+\" or \"-\".
  2545. This variable should not be set directly, but agenda custom commands can
  2546. bind it in the options section. The preset filter is a global property of
  2547. the entire agenda view. In a block agenda, it will not work reliably to
  2548. define a filter for one of the individual blocks. You need to set it in
  2549. the global options and expect it to be applied to the entire view.")
  2550. (defun org-prepare-agenda (&optional name)
  2551. (setq org-todo-keywords-for-agenda nil)
  2552. (setq org-done-keywords-for-agenda nil)
  2553. (setq org-drawers-for-agenda nil)
  2554. (unless org-agenda-persistent-filter
  2555. (setq org-agenda-filter nil))
  2556. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2557. (if org-agenda-multi
  2558. (progn
  2559. (setq buffer-read-only nil)
  2560. (goto-char (point-max))
  2561. (unless (or (bobp) org-agenda-compact-blocks)
  2562. (insert "\n"
  2563. (if (stringp org-agenda-block-separator)
  2564. org-agenda-block-separator
  2565. (make-string (window-width) org-agenda-block-separator))
  2566. "\n"))
  2567. (narrow-to-region (point) (point-max)))
  2568. (org-agenda-reset-markers)
  2569. (setq org-agenda-contributing-files nil)
  2570. (setq org-agenda-columns-active nil)
  2571. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2572. (setq org-todo-keywords-for-agenda
  2573. (org-uniquify org-todo-keywords-for-agenda))
  2574. (setq org-done-keywords-for-agenda
  2575. (org-uniquify org-done-keywords-for-agenda))
  2576. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2577. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2578. (awin (get-buffer-window abuf)))
  2579. (cond
  2580. ((equal (current-buffer) abuf) nil)
  2581. (awin (select-window awin))
  2582. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2583. ((equal org-agenda-window-setup 'current-window)
  2584. (switch-to-buffer abuf))
  2585. ((equal org-agenda-window-setup 'other-window)
  2586. (org-switch-to-buffer-other-window abuf))
  2587. ((equal org-agenda-window-setup 'other-frame)
  2588. (switch-to-buffer-other-frame abuf))
  2589. ((equal org-agenda-window-setup 'reorganize-frame)
  2590. (delete-other-windows)
  2591. (org-switch-to-buffer-other-window abuf)))
  2592. ;; additional test in case agenda is invoked from within agenda
  2593. ;; buffer via elisp link
  2594. (unless (equal (current-buffer) abuf)
  2595. (switch-to-buffer abuf)))
  2596. (setq buffer-read-only nil)
  2597. (let ((inhibit-read-only t)) (erase-buffer))
  2598. (org-agenda-mode)
  2599. (and name (not org-agenda-name)
  2600. (org-set-local 'org-agenda-name name)))
  2601. (setq buffer-read-only nil))
  2602. (defun org-finalize-agenda ()
  2603. "Finishing touch for the agenda buffer, called just before displaying it."
  2604. (unless org-agenda-multi
  2605. (save-excursion
  2606. (let ((inhibit-read-only t))
  2607. (goto-char (point-min))
  2608. (while (org-activate-bracket-links (point-max))
  2609. (add-text-properties (match-beginning 0) (match-end 0)
  2610. '(face org-link)))
  2611. (org-agenda-align-tags)
  2612. (unless org-agenda-with-colors
  2613. (remove-text-properties (point-min) (point-max) '(face nil))))
  2614. (if (and (boundp 'org-agenda-overriding-columns-format)
  2615. org-agenda-overriding-columns-format)
  2616. (org-set-local 'org-agenda-overriding-columns-format
  2617. org-agenda-overriding-columns-format))
  2618. (if (and (boundp 'org-agenda-view-columns-initially)
  2619. org-agenda-view-columns-initially)
  2620. (org-agenda-columns))
  2621. (when org-agenda-fontify-priorities
  2622. (org-agenda-fontify-priorities))
  2623. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2624. (org-agenda-dim-blocked-tasks))
  2625. (org-agenda-mark-clocking-task)
  2626. (when org-agenda-entry-text-mode
  2627. (org-agenda-entry-text-hide)
  2628. (org-agenda-entry-text-show))
  2629. (if (functionp 'org-habit-insert-consistency-graphs)
  2630. (org-habit-insert-consistency-graphs))
  2631. (run-hooks 'org-finalize-agenda-hook)
  2632. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2633. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2634. (org-agenda-filter-apply org-agenda-filter))
  2635. )))
  2636. (defun org-agenda-mark-clocking-task ()
  2637. "Mark the current clock entry in the agenda if it is present."
  2638. (mapc (lambda (o)
  2639. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2640. (delete-overlay o)))
  2641. (overlays-in (point-min) (point-max)))
  2642. (when (marker-buffer org-clock-hd-marker)
  2643. (save-excursion
  2644. (goto-char (point-min))
  2645. (let (s ov)
  2646. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2647. (goto-char s)
  2648. (when (equal (org-get-at-bol 'org-hd-marker)
  2649. org-clock-hd-marker)
  2650. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2651. (overlay-put ov 'type 'org-agenda-clocking)
  2652. (overlay-put ov 'face 'org-agenda-clocking)
  2653. (overlay-put ov 'help-echo
  2654. "The clock is running in this item")))))))
  2655. (defun org-agenda-fontify-priorities ()
  2656. "Make highest priority lines bold, and lowest italic."
  2657. (interactive)
  2658. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2659. (delete-overlay o)))
  2660. (overlays-in (point-min) (point-max)))
  2661. (save-excursion
  2662. (let ((inhibit-read-only t)
  2663. b e p ov h l)
  2664. (goto-char (point-min))
  2665. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2666. (setq h (or (get-char-property (point) 'org-highest-priority)
  2667. org-highest-priority)
  2668. l (or (get-char-property (point) 'org-lowest-priority)
  2669. org-lowest-priority)
  2670. p (string-to-char (match-string 1))
  2671. b (match-beginning 0)
  2672. e (if (eq org-agenda-fontify-priorities 'cookies)
  2673. (match-end 0)
  2674. (point-at-eol))
  2675. ov (make-overlay b e))
  2676. (overlay-put
  2677. ov 'face
  2678. (cond ((org-face-from-face-or-color
  2679. 'priority nil
  2680. (cdr (assoc p org-priority-faces))))
  2681. ((and (listp org-agenda-fontify-priorities)
  2682. (org-face-from-face-or-color
  2683. 'priority nil
  2684. (cdr (assoc p org-agenda-fontify-priorities)))))
  2685. ((equal p l) 'italic)
  2686. ((equal p h) 'bold)))
  2687. (overlay-put ov 'org-type 'org-priority)))))
  2688. (defun org-agenda-dim-blocked-tasks ()
  2689. "Dim currently blocked TODO's in the agenda display."
  2690. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2691. (delete-overlay o)))
  2692. (overlays-in (point-min) (point-max)))
  2693. (save-excursion
  2694. (let ((inhibit-read-only t)
  2695. (org-depend-tag-blocked nil)
  2696. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2697. org-blocked-by-checkboxes
  2698. invis1 b e p ov h l)
  2699. (goto-char (point-min))
  2700. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2701. (and pos (goto-char (1+ pos))))
  2702. (setq org-blocked-by-checkboxes nil invis1 invis)
  2703. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2704. (when (and marker
  2705. (not (with-current-buffer (marker-buffer marker)
  2706. (save-excursion
  2707. (goto-char marker)
  2708. (if (org-entry-get nil "NOBLOCKING")
  2709. t ;; Never block this entry
  2710. (run-hook-with-args-until-failure
  2711. 'org-blocker-hook
  2712. (list :type 'todo-state-change
  2713. :position marker
  2714. :from 'todo
  2715. :to 'done)))))))
  2716. (if org-blocked-by-checkboxes (setq invis1 nil))
  2717. (setq b (if invis1
  2718. (max (point-min) (1- (point-at-bol)))
  2719. (point-at-bol))
  2720. e (point-at-eol)
  2721. ov (make-overlay b e))
  2722. (if invis1
  2723. (overlay-put ov 'invisible t)
  2724. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2725. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2726. (defvar org-agenda-skip-function nil
  2727. "Function to be called at each match during agenda construction.
  2728. If this function returns nil, the current match should not be skipped.
  2729. Otherwise, the function must return a position from where the search
  2730. should be continued.
  2731. This may also be a Lisp form, it will be evaluated.
  2732. Never set this variable using `setq' or so, because then it will apply
  2733. to all future agenda commands. Instead, bind it with `let' to scope
  2734. it dynamically into the agenda-constructing command. A good way to set
  2735. it is through options in `org-agenda-custom-commands'.")
  2736. (defun org-agenda-skip ()
  2737. "Throw to `:skip' in places that should be skipped.
  2738. Also moves point to the end of the skipped region, so that search can
  2739. continue from there."
  2740. (let ((p (point-at-bol)) to fp)
  2741. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2742. (get-text-property p :org-archived)
  2743. (org-end-of-subtree t)
  2744. (throw :skip t))
  2745. (and org-agenda-skip-comment-trees
  2746. (get-text-property p :org-comment)
  2747. (org-end-of-subtree t)
  2748. (throw :skip t))
  2749. (if (equal (char-after p) ?#) (throw :skip t))
  2750. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2751. (consp org-agenda-skip-function))
  2752. (setq to (save-excursion
  2753. (save-match-data
  2754. (if fp
  2755. (funcall org-agenda-skip-function)
  2756. (eval org-agenda-skip-function))))))
  2757. (goto-char to)
  2758. (throw :skip t))))
  2759. (defvar org-agenda-markers nil
  2760. "List of all currently active markers created by `org-agenda'.")
  2761. (defvar org-agenda-last-marker-time (org-float-time)
  2762. "Creation time of the last agenda marker.")
  2763. (defun org-agenda-new-marker (&optional pos)
  2764. "Return a new agenda marker.
  2765. Org-mode keeps a list of these markers and resets them when they are
  2766. no longer in use."
  2767. (let ((m (copy-marker (or pos (point)))))
  2768. (setq org-agenda-last-marker-time (org-float-time))
  2769. (push m org-agenda-markers)
  2770. m))
  2771. (defun org-agenda-reset-markers ()
  2772. "Reset markers created by `org-agenda'."
  2773. (while org-agenda-markers
  2774. (move-marker (pop org-agenda-markers) nil)))
  2775. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2776. "Save relative positions of markers in region."
  2777. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2778. org-agenda-markers))
  2779. ;;; Entry text mode
  2780. (defun org-agenda-entry-text-show-here ()
  2781. "Add some text from the entry as context to the current line."
  2782. (let (m txt o)
  2783. (setq m (org-get-at-bol 'org-hd-marker))
  2784. (unless (marker-buffer m)
  2785. (error "No marker points to an entry here"))
  2786. (setq txt (concat "\n" (org-no-properties
  2787. (org-agenda-get-some-entry-text
  2788. m org-agenda-entry-text-maxlines " > "))))
  2789. (when (string-match "\\S-" txt)
  2790. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2791. (overlay-put o 'evaporate t)
  2792. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2793. (overlay-put o 'after-string txt))))
  2794. (defun org-agenda-entry-text-show ()
  2795. "Add entry context for all agenda lines."
  2796. (interactive)
  2797. (save-excursion
  2798. (goto-char (point-max))
  2799. (beginning-of-line 1)
  2800. (while (not (bobp))
  2801. (when (org-get-at-bol 'org-hd-marker)
  2802. (org-agenda-entry-text-show-here))
  2803. (beginning-of-line 0))))
  2804. (defun org-agenda-entry-text-hide ()
  2805. "Remove any shown entry context."
  2806. (delq nil
  2807. (mapcar (lambda (o)
  2808. (if (eq (overlay-get o 'org-overlay-type)
  2809. 'agenda-entry-content)
  2810. (progn (delete-overlay o) t)))
  2811. (overlays-in (point-min) (point-max)))))
  2812. ;;; Agenda timeline
  2813. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2814. (defun org-timeline (&optional include-all)
  2815. "Show a time-sorted view of the entries in the current org file.
  2816. Only entries with a time stamp of today or later will be listed. With
  2817. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2818. under the current date.
  2819. If the buffer contains an active region, only check the region for
  2820. dates."
  2821. (interactive "P")
  2822. (org-compile-prefix-format 'timeline)
  2823. (org-set-sorting-strategy 'timeline)
  2824. (let* ((dopast t)
  2825. (dotodo include-all)
  2826. (doclosed org-agenda-show-log)
  2827. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2828. (current-buffer))))
  2829. (date (calendar-current-date))
  2830. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2831. (end (if (org-region-active-p) (region-end) (point-max)))
  2832. (day-numbers (org-get-all-dates beg end 'no-ranges
  2833. t doclosed ; always include today
  2834. org-timeline-show-empty-dates))
  2835. (org-deadline-warning-days 0)
  2836. (org-agenda-only-exact-dates t)
  2837. (today (time-to-days (current-time)))
  2838. (past t)
  2839. args
  2840. s e rtn d emptyp wd)
  2841. (setq org-agenda-redo-command
  2842. (list 'progn
  2843. (list 'org-switch-to-buffer-other-window (current-buffer))
  2844. (list 'org-timeline (list 'quote include-all))))
  2845. (if (not dopast)
  2846. ;; Remove past dates from the list of dates.
  2847. (setq day-numbers (delq nil (mapcar (lambda(x)
  2848. (if (>= x today) x nil))
  2849. day-numbers))))
  2850. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2851. (if doclosed (push :closed args))
  2852. (push :timestamp args)
  2853. (push :deadline args)
  2854. (push :scheduled args)
  2855. (push :sexp args)
  2856. (if dotodo (push :todo args))
  2857. (insert "Timeline of file " entry "\n")
  2858. (add-text-properties (point-min) (point)
  2859. (list 'face 'org-agenda-structure))
  2860. (org-agenda-mark-header-line (point-min))
  2861. (while (setq d (pop day-numbers))
  2862. (if (and (listp d) (eq (car d) :omitted))
  2863. (progn
  2864. (setq s (point))
  2865. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2866. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2867. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2868. (if (and (>= d today)
  2869. dopast
  2870. past)
  2871. (progn
  2872. (setq past nil)
  2873. (insert (make-string 79 ?-) "\n")))
  2874. (setq date (calendar-gregorian-from-absolute d)
  2875. wd (calendar-day-of-week date))
  2876. (setq s (point))
  2877. (setq rtn (and (not emptyp)
  2878. (apply 'org-agenda-get-day-entries entry
  2879. date args)))
  2880. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2881. (progn
  2882. (insert
  2883. (if (stringp org-agenda-format-date)
  2884. (format-time-string org-agenda-format-date
  2885. (org-time-from-absolute date))
  2886. (funcall org-agenda-format-date date))
  2887. "\n")
  2888. (put-text-property s (1- (point)) 'face
  2889. (if (member wd org-agenda-weekend-days)
  2890. 'org-agenda-date-weekend
  2891. 'org-agenda-date))
  2892. (put-text-property s (1- (point)) 'org-date-line t)
  2893. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2894. (if (equal d today)
  2895. (put-text-property s (1- (point)) 'org-today t))
  2896. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2897. (put-text-property s (1- (point)) 'day d)))))
  2898. (goto-char (point-min))
  2899. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2900. (point-min)))
  2901. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2902. (org-finalize-agenda)
  2903. (setq buffer-read-only t)))
  2904. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2905. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2906. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2907. not every single day in the range. If FORCE-TODAY is non-nil, make
  2908. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2909. inactive time stamps (those in square brackets) are included.
  2910. When EMPTY is non-nil, also include days without any entries."
  2911. (let ((re (concat
  2912. (if pre-re pre-re "")
  2913. (if inactive org-ts-regexp-both org-ts-regexp)))
  2914. dates dates1 date day day1 day2 ts1 ts2)
  2915. (if force-today
  2916. (setq dates (list (time-to-days (current-time)))))
  2917. (save-excursion
  2918. (goto-char beg)
  2919. (while (re-search-forward re end t)
  2920. (setq day (time-to-days (org-time-string-to-time
  2921. (substring (match-string 1) 0 10))))
  2922. (or (memq day dates) (push day dates)))
  2923. (unless no-ranges
  2924. (goto-char beg)
  2925. (while (re-search-forward org-tr-regexp end t)
  2926. (setq ts1 (substring (match-string 1) 0 10)
  2927. ts2 (substring (match-string 2) 0 10)
  2928. day1 (time-to-days (org-time-string-to-time ts1))
  2929. day2 (time-to-days (org-time-string-to-time ts2)))
  2930. (while (< (setq day1 (1+ day1)) day2)
  2931. (or (memq day1 dates) (push day1 dates)))))
  2932. (setq dates (sort dates '<))
  2933. (when empty
  2934. (while (setq day (pop dates))
  2935. (setq day2 (car dates))
  2936. (push day dates1)
  2937. (when (and day2 empty)
  2938. (if (or (eq empty t)
  2939. (and (numberp empty) (<= (- day2 day) empty)))
  2940. (while (< (setq day (1+ day)) day2)
  2941. (push (list day) dates1))
  2942. (push (cons :omitted (- day2 day)) dates1))))
  2943. (setq dates (nreverse dates1)))
  2944. dates)))
  2945. ;;; Agenda Daily/Weekly
  2946. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2947. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2948. "Custom commands can set this variable in the options section.")
  2949. (defvar org-agenda-last-arguments nil
  2950. "The arguments of the previous call to `org-agenda'.")
  2951. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2952. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2953. (defvar org-include-all-loc nil) ; local variable
  2954. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2955. "List of types searched for when creating the daily/weekly agenda.
  2956. This variable is a list of symbols that controls the types of
  2957. items that appear in the daily/weekly agenda. Allowed symbols in this
  2958. list are are
  2959. :timestamp List items containing a date stamp or date range matching
  2960. the selected date. This includes sexp entries in
  2961. angular brackets.
  2962. :sexp List entries resulting from plain diary-like sexps.
  2963. :deadline List deadline due on that date. When the date is today,
  2964. also list any deadlines past due, or due within
  2965. `org-deadline-warning-days'. `:deadline' must appear before
  2966. `:scheduled' if the setting of
  2967. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2968. any effect.
  2969. :scheduled List all items which are scheduled for the given date.
  2970. The diary for *today* also contains items which were
  2971. scheduled earlier and are not yet marked DONE.
  2972. By default, all four types are turned on.
  2973. Never set this variable globally using `setq', because then it
  2974. will apply to all future agenda commands. Instead, bind it with
  2975. `let' to scope it dynamically into the the agenda-constructing
  2976. command. A good way to set it is through options in
  2977. `org-agenda-custom-commands'. For a more flexible (though
  2978. somewhat less efficient) way of determining what is included in
  2979. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2980. ;;;###autoload
  2981. (defun org-agenda-list (&optional include-all start-day ndays)
  2982. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2983. The view will be for the current day or week, but from the overview buffer
  2984. you will be able to go to other days/weeks.
  2985. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2986. all unfinished TODO items will also be shown, before the agenda.
  2987. This feature is considered obsolete, please use the TODO list or a block
  2988. agenda instead.
  2989. With a numeric prefix argument in an interactive call, the agenda will
  2990. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2991. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2992. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2993. given in `org-agenda-start-on-weekday'."
  2994. (interactive "P")
  2995. (if (and (integerp include-all) (> include-all 0))
  2996. (setq ndays include-all include-all nil))
  2997. (setq ndays (or ndays org-agenda-ndays)
  2998. start-day (or start-day org-agenda-start-day))
  2999. (if org-agenda-overriding-arguments
  3000. (setq include-all (car org-agenda-overriding-arguments)
  3001. start-day (nth 1 org-agenda-overriding-arguments)
  3002. ndays (nth 2 org-agenda-overriding-arguments)))
  3003. (if (stringp start-day)
  3004. ;; Convert to an absolute day number
  3005. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3006. (setq org-agenda-last-arguments (list include-all start-day ndays))
  3007. (org-compile-prefix-format 'agenda)
  3008. (org-set-sorting-strategy 'agenda)
  3009. (let* ((org-agenda-start-on-weekday
  3010. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  3011. org-agenda-start-on-weekday nil))
  3012. (thefiles (org-agenda-files nil 'ifmode))
  3013. (files thefiles)
  3014. (today (time-to-days
  3015. (time-subtract (current-time)
  3016. (list 0 (* 3600 org-extend-today-until) 0))))
  3017. (sd (or start-day today))
  3018. (start (if (or (null org-agenda-start-on-weekday)
  3019. (< org-agenda-ndays 7))
  3020. sd
  3021. (let* ((nt (calendar-day-of-week
  3022. (calendar-gregorian-from-absolute sd)))
  3023. (n1 org-agenda-start-on-weekday)
  3024. (d (- nt n1)))
  3025. (- sd (+ (if (< d 0) 7 0) d)))))
  3026. (day-numbers (list start))
  3027. (day-cnt 0)
  3028. (inhibit-redisplay (not debug-on-error))
  3029. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  3030. clocktable-start clocktable-end)
  3031. (setq org-agenda-redo-command
  3032. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3033. ;; Make the list of days
  3034. (setq ndays (or ndays org-agenda-ndays)
  3035. nd ndays)
  3036. (while (> ndays 1)
  3037. (push (1+ (car day-numbers)) day-numbers)
  3038. (setq ndays (1- ndays)))
  3039. (setq day-numbers (nreverse day-numbers))
  3040. (setq clocktable-start (car day-numbers)
  3041. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3042. (org-prepare-agenda "Day/Week")
  3043. (org-set-local 'org-starting-day (car day-numbers))
  3044. (org-set-local 'org-include-all-loc include-all)
  3045. (org-set-local 'org-agenda-span
  3046. (org-agenda-ndays-to-span nd))
  3047. (when (and (or include-all org-agenda-include-all-todo)
  3048. (member today day-numbers))
  3049. (setq files thefiles
  3050. rtnall nil)
  3051. (while (setq file (pop files))
  3052. (catch 'nextfile
  3053. (org-check-agenda-file file)
  3054. (setq date (calendar-gregorian-from-absolute today)
  3055. rtn (org-agenda-get-day-entries
  3056. file date :todo))
  3057. (setq rtnall (append rtnall rtn))))
  3058. (when rtnall
  3059. (insert "All currently open TODO items:\n")
  3060. (add-text-properties (point-min) (1- (point))
  3061. (list 'face 'org-agenda-structure
  3062. 'short-heading "All TODO items"))
  3063. (org-agenda-mark-header-line (point-min))
  3064. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3065. (unless org-agenda-compact-blocks
  3066. (let* ((d1 (car day-numbers))
  3067. (d2 (org-last day-numbers))
  3068. (w1 (org-days-to-iso-week d1))
  3069. (w2 (org-days-to-iso-week d2)))
  3070. (setq s (point))
  3071. (if org-agenda-overriding-header
  3072. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3073. nil 'face 'org-agenda-structure) "\n")
  3074. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3075. "-agenda"
  3076. (if (< (- d2 d1) 350)
  3077. (if (= w1 w2)
  3078. (format " (W%02d)" w1)
  3079. (format " (W%02d-W%02d)" w1 w2))
  3080. "")
  3081. ":\n")))
  3082. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3083. 'org-date-line t))
  3084. (org-agenda-mark-header-line s))
  3085. (while (setq d (pop day-numbers))
  3086. (setq date (calendar-gregorian-from-absolute d)
  3087. wd (calendar-day-of-week date)
  3088. s (point))
  3089. (if (or (setq todayp (= d today))
  3090. (and (not start-pos) (= d sd)))
  3091. (setq start-pos (point))
  3092. (if (and start-pos (not end-pos))
  3093. (setq end-pos (point))))
  3094. (setq files thefiles
  3095. rtnall nil)
  3096. (while (setq file (pop files))
  3097. (catch 'nextfile
  3098. (org-check-agenda-file file)
  3099. (let ((org-agenda-entry-types org-agenda-entry-types))
  3100. (unless org-agenda-include-deadlines
  3101. (setq org-agenda-entry-types
  3102. (delq :deadline org-agenda-entry-types)))
  3103. (cond
  3104. ((eq org-agenda-show-log 'only)
  3105. (setq rtn (org-agenda-get-day-entries
  3106. file date :closed)))
  3107. (org-agenda-show-log
  3108. (setq rtn (apply 'org-agenda-get-day-entries
  3109. file date
  3110. (append '(:closed) org-agenda-entry-types))))
  3111. (t
  3112. (setq rtn (apply 'org-agenda-get-day-entries
  3113. file date
  3114. org-agenda-entry-types)))))
  3115. (setq rtnall (append rtnall rtn))))
  3116. (if org-agenda-include-diary
  3117. (let ((org-agenda-search-headline-for-time t))
  3118. (require 'diary-lib)
  3119. (setq rtn (org-get-entries-from-diary date))
  3120. (setq rtnall (append rtnall rtn))))
  3121. (if (or rtnall org-agenda-show-all-dates)
  3122. (progn
  3123. (setq day-cnt (1+ day-cnt))
  3124. (insert
  3125. (if (stringp org-agenda-format-date)
  3126. (format-time-string org-agenda-format-date
  3127. (org-time-from-absolute date))
  3128. (funcall org-agenda-format-date date))
  3129. "\n")
  3130. (put-text-property s (1- (point)) 'face
  3131. (if (member wd org-agenda-weekend-days)
  3132. 'org-agenda-date-weekend
  3133. 'org-agenda-date))
  3134. (put-text-property s (1- (point)) 'org-date-line t)
  3135. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3136. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3137. (when todayp
  3138. (put-text-property s (1- (point)) 'org-today t)
  3139. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3140. (if rtnall (insert
  3141. (org-finalize-agenda-entries
  3142. (org-agenda-add-time-grid-maybe
  3143. rtnall nd todayp))
  3144. "\n"))
  3145. (put-text-property s (1- (point)) 'day d)
  3146. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3147. (when (and org-agenda-clockreport-mode clocktable-start)
  3148. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3149. ;; the above line is to ensure the restricted range!
  3150. (p org-agenda-clockreport-parameter-plist)
  3151. tbl)
  3152. (setq p (org-plist-delete p :block))
  3153. (setq p (plist-put p :tstart clocktable-start))
  3154. (setq p (plist-put p :tend clocktable-end))
  3155. (setq p (plist-put p :scope 'agenda))
  3156. (setq tbl (apply 'org-get-clocktable p))
  3157. (insert tbl)))
  3158. (goto-char (point-min))
  3159. (or org-agenda-multi (org-fit-agenda-window))
  3160. (unless (and (pos-visible-in-window-p (point-min))
  3161. (pos-visible-in-window-p (point-max)))
  3162. (goto-char (1- (point-max)))
  3163. (recenter -1)
  3164. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3165. (progn
  3166. (goto-char (or start-pos 1))
  3167. (recenter 1))))
  3168. (goto-char (or start-pos 1))
  3169. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3170. (org-finalize-agenda)
  3171. (setq buffer-read-only t)
  3172. (message "")))
  3173. (defun org-agenda-ndays-to-span (n)
  3174. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3175. ;;; Agenda word search
  3176. (defvar org-agenda-search-history nil)
  3177. (defvar org-todo-only nil)
  3178. (defvar org-search-syntax-table nil
  3179. "Special syntax table for org-mode search.
  3180. In this table, we have single quotes not as word constituents, to
  3181. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3182. (defun org-search-syntax-table ()
  3183. (unless org-search-syntax-table
  3184. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3185. (modify-syntax-entry ?' "." org-search-syntax-table)
  3186. (modify-syntax-entry ?` "." org-search-syntax-table))
  3187. org-search-syntax-table)
  3188. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3189. ;;;###autoload
  3190. (defun org-search-view (&optional todo-only string edit-at)
  3191. "Show all entries that contain a phrase or words or regular expressions.
  3192. With optional prefix argument TODO-ONLY, only consider entries that are
  3193. TODO entries. The argument STRING can be used to pass a default search
  3194. string into this function. If EDIT-AT is non-nil, it means that the
  3195. user should get a chance to edit this string, with cursor at position
  3196. EDIT-AT.
  3197. The search string can be viewed either as a phrase that should be found as
  3198. is, or it can be broken into a number of snippets, each of which must match
  3199. in a Boolean way to select an entry. The default depends on the variable
  3200. `org-agenda-search-view-always-boolean'.
  3201. Even if this is turned off (the default) you can always switch to
  3202. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3203. The default is a direct search of the whole phrase, where each space in
  3204. the search string can expand to an arbitrary amount of whitespace,
  3205. including newlines.
  3206. If using a Boolean search, the search string is split on whitespace and
  3207. each snippet is searched separately, with logical AND to select an entry.
  3208. Words prefixed with a minus must *not* occur in the entry. Words without
  3209. a prefix or prefixed with a plus must occur in the entry. Matching is
  3210. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3211. match whole words, not parts of a word) if
  3212. `org-agenda-search-view-force-full-words' is set (default is nil).
  3213. Boolean search snippets enclosed by curly braces are interpreted as
  3214. regular expressions that must or (when preceded with \"-\") must not
  3215. match in the entry. Snippets enclosed into double quotes will be taken
  3216. as a whole, to include whitespace.
  3217. - If the search string starts with an asterisk, search only in headlines.
  3218. - If (possibly after the leading star) the search string starts with an
  3219. exclamation mark, this also means to look at TODO entries only, an effect
  3220. that can also be achieved with a prefix argument.
  3221. - If (possibly after star and exclamation mark) the search string starts
  3222. with a colon, this will mean that the (non-regexp) snippets of the
  3223. Boolean search must match as full words.
  3224. This command searches the agenda files, and in addition the files listed
  3225. in `org-agenda-text-search-extra-files'."
  3226. (interactive "P")
  3227. (org-compile-prefix-format 'search)
  3228. (org-set-sorting-strategy 'search)
  3229. (org-prepare-agenda "SEARCH")
  3230. (let* ((props (list 'face nil
  3231. 'done-face 'org-agenda-done
  3232. 'org-not-done-regexp org-not-done-regexp
  3233. 'org-todo-regexp org-todo-regexp
  3234. 'org-complex-heading-regexp org-complex-heading-regexp
  3235. 'mouse-face 'highlight
  3236. 'help-echo (format "mouse-2 or RET jump to location")))
  3237. (full-words org-agenda-search-view-force-full-words)
  3238. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3239. regexp rtn rtnall files file pos
  3240. marker category tags c neg re boolean
  3241. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3242. (unless (and (not edit-at)
  3243. (stringp string)
  3244. (string-match "\\S-" string))
  3245. (setq string (read-string
  3246. (if org-agenda-search-view-always-boolean
  3247. "[+-]Word/{Regexp} ...: "
  3248. "Phrase, or [+-]Word/{Regexp} ...: ")
  3249. (cond
  3250. ((integerp edit-at) (cons string edit-at))
  3251. (edit-at string))
  3252. 'org-agenda-search-history)))
  3253. (org-set-local 'org-todo-only todo-only)
  3254. (setq org-agenda-redo-command
  3255. (list 'org-search-view (if todo-only t nil) string
  3256. '(if current-prefix-arg 1 nil)))
  3257. (setq org-agenda-query-string string)
  3258. (if (equal (string-to-char string) ?*)
  3259. (setq hdl-only t
  3260. words (substring string 1))
  3261. (setq words string))
  3262. (when (equal (string-to-char words) ?!)
  3263. (setq todo-only t
  3264. words (substring words 1)))
  3265. (when (equal (string-to-char words) ?:)
  3266. (setq full-words t
  3267. words (substring words 1)))
  3268. (if (or org-agenda-search-view-always-boolean
  3269. (member (string-to-char words) '(?- ?+ ?\{)))
  3270. (setq boolean t))
  3271. (setq words (org-split-string words))
  3272. (let (www w)
  3273. (while (setq w (pop words))
  3274. (while (and (string-match "\\\\\\'" w) words)
  3275. (setq w (concat (substring w 0 -1) " " (pop words))))
  3276. (push w www))
  3277. (setq words (nreverse www) www nil)
  3278. (while (setq w (pop words))
  3279. (when (and (string-match "\\`[-+]?{" w)
  3280. (not (string-match "}\\'" w)))
  3281. (while (and words (not (string-match "}\\'" (car words))))
  3282. (setq w (concat w " " (pop words))))
  3283. (setq w (concat w " " (pop words))))
  3284. (push w www))
  3285. (setq words (nreverse www)))
  3286. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3287. (when boolean
  3288. (let (wds w)
  3289. (while (setq w (pop words))
  3290. (if (or (equal (substring w 0 1) "\"")
  3291. (and (> (length w) 1)
  3292. (member (substring w 0 1) '("+" "-"))
  3293. (equal (substring w 1 2) "\"")))
  3294. (while (and words (not (equal (substring w -1) "\"")))
  3295. (setq w (concat w " " (pop words)))))
  3296. (and (string-match "\\`\\([-+]?\\)\"" w)
  3297. (setq w (replace-match "\\1" nil nil w)))
  3298. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3299. (push w wds))
  3300. (setq words (nreverse wds))))
  3301. (if boolean
  3302. (mapc (lambda (w)
  3303. (setq c (string-to-char w))
  3304. (if (equal c ?-)
  3305. (setq neg t w (substring w 1))
  3306. (if (equal c ?+)
  3307. (setq neg nil w (substring w 1))
  3308. (setq neg nil)))
  3309. (if (string-match "\\`{.*}\\'" w)
  3310. (setq re (substring w 1 -1))
  3311. (if full-words
  3312. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3313. (setq re (regexp-quote (downcase w)))))
  3314. (if neg (push re regexps-) (push re regexps+)))
  3315. words)
  3316. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3317. regexps+))
  3318. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3319. (if (not regexps+)
  3320. (setq regexp (concat "^" org-outline-regexp))
  3321. (setq regexp (pop regexps+))
  3322. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3323. regexp))))
  3324. (setq files (org-agenda-files nil 'ifmode))
  3325. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3326. (pop org-agenda-text-search-extra-files)
  3327. (setq files (org-add-archive-files files)))
  3328. (setq files (append files org-agenda-text-search-extra-files)
  3329. rtnall nil)
  3330. (while (setq file (pop files))
  3331. (setq ee nil)
  3332. (catch 'nextfile
  3333. (org-check-agenda-file file)
  3334. (setq buffer (if (file-exists-p file)
  3335. (org-get-agenda-file-buffer file)
  3336. (error "No such file %s" file)))
  3337. (if (not buffer)
  3338. ;; If file does not exist, make sure an error message is sent
  3339. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3340. file))))
  3341. (with-current-buffer buffer
  3342. (with-syntax-table (org-search-syntax-table)
  3343. (unless (org-mode-p)
  3344. (error "Agenda file %s is not in `org-mode'" file))
  3345. (let ((case-fold-search t))
  3346. (save-excursion
  3347. (save-restriction
  3348. (if org-agenda-restrict
  3349. (narrow-to-region org-agenda-restrict-begin
  3350. org-agenda-restrict-end)
  3351. (widen))
  3352. (goto-char (point-min))
  3353. (unless (or (org-on-heading-p)
  3354. (outline-next-heading))
  3355. (throw 'nextfile t))
  3356. (goto-char (max (point-min) (1- (point))))
  3357. (while (re-search-forward regexp nil t)
  3358. (org-back-to-heading t)
  3359. (skip-chars-forward "* ")
  3360. (setq beg (point-at-bol)
  3361. beg1 (point)
  3362. end (progn (outline-next-heading) (point)))
  3363. (catch :skip
  3364. (goto-char beg)
  3365. (org-agenda-skip)
  3366. (setq str (buffer-substring-no-properties
  3367. (point-at-bol)
  3368. (if hdl-only (point-at-eol) end)))
  3369. (mapc (lambda (wr) (when (string-match wr str)
  3370. (goto-char (1- end))
  3371. (throw :skip t)))
  3372. regexps-)
  3373. (mapc (lambda (wr) (unless (string-match wr str)
  3374. (goto-char (1- end))
  3375. (throw :skip t)))
  3376. (if todo-only
  3377. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3378. regexps+)
  3379. regexps+))
  3380. (goto-char beg)
  3381. (setq marker (org-agenda-new-marker (point))
  3382. category (org-get-category)
  3383. tags (org-get-tags-at (point))
  3384. txt (org-format-agenda-item
  3385. ""
  3386. (buffer-substring-no-properties
  3387. beg1 (point-at-eol))
  3388. category tags))
  3389. (org-add-props txt props
  3390. 'org-marker marker 'org-hd-marker marker
  3391. 'org-todo-regexp org-todo-regexp
  3392. 'org-complex-heading-regexp org-complex-heading-regexp
  3393. 'priority 1000 'org-category category
  3394. 'type "search")
  3395. (push txt ee)
  3396. (goto-char (1- end))))))))))
  3397. (setq rtn (nreverse ee))
  3398. (setq rtnall (append rtnall rtn)))
  3399. (if org-agenda-overriding-header
  3400. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3401. nil 'face 'org-agenda-structure) "\n")
  3402. (insert "Search words: ")
  3403. (add-text-properties (point-min) (1- (point))
  3404. (list 'face 'org-agenda-structure))
  3405. (setq pos (point))
  3406. (insert string "\n")
  3407. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3408. (setq pos (point))
  3409. (unless org-agenda-multi
  3410. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3411. (add-text-properties pos (1- (point))
  3412. (list 'face 'org-agenda-structure))))
  3413. (org-agenda-mark-header-line (point-min))
  3414. (when rtnall
  3415. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3416. (goto-char (point-min))
  3417. (or org-agenda-multi (org-fit-agenda-window))
  3418. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3419. (org-finalize-agenda)
  3420. (setq buffer-read-only t)))
  3421. ;;; Agenda TODO list
  3422. (defvar org-select-this-todo-keyword nil)
  3423. (defvar org-last-arg nil)
  3424. ;;;###autoload
  3425. (defun org-todo-list (arg)
  3426. "Show all (not done) TODO entries from all agenda file in a single list.
  3427. The prefix arg can be used to select a specific TODO keyword and limit
  3428. the list to these. When using \\[universal-argument], you will be prompted
  3429. for a keyword. A numeric prefix directly selects the Nth keyword in
  3430. `org-todo-keywords-1'."
  3431. (interactive "P")
  3432. (org-compile-prefix-format 'todo)
  3433. (org-set-sorting-strategy 'todo)
  3434. (org-prepare-agenda "TODO")
  3435. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3436. (let* ((today (time-to-days (current-time)))
  3437. (date (calendar-gregorian-from-absolute today))
  3438. (kwds org-todo-keywords-for-agenda)
  3439. (completion-ignore-case t)
  3440. (org-select-this-todo-keyword
  3441. (if (stringp arg) arg
  3442. (and arg (integerp arg) (> arg 0)
  3443. (nth (1- arg) kwds))))
  3444. rtn rtnall files file pos)
  3445. (when (equal arg '(4))
  3446. (setq org-select-this-todo-keyword
  3447. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3448. (mapcar 'list kwds) nil nil)))
  3449. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3450. (org-set-local 'org-last-arg arg)
  3451. (setq org-agenda-redo-command
  3452. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3453. (setq files (org-agenda-files nil 'ifmode)
  3454. rtnall nil)
  3455. (while (setq file (pop files))
  3456. (catch 'nextfile
  3457. (org-check-agenda-file file)
  3458. (setq rtn (org-agenda-get-day-entries file date :todo))
  3459. (setq rtnall (append rtnall rtn))))
  3460. (if org-agenda-overriding-header
  3461. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3462. nil 'face 'org-agenda-structure) "\n")
  3463. (insert "Global list of TODO items of type: ")
  3464. (add-text-properties (point-min) (1- (point))
  3465. (list 'face 'org-agenda-structure
  3466. 'short-heading
  3467. (concat "ToDo: "
  3468. (or org-select-this-todo-keyword "ALL"))))
  3469. (org-agenda-mark-header-line (point-min))
  3470. (setq pos (point))
  3471. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3472. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3473. (setq pos (point))
  3474. (unless org-agenda-multi
  3475. (insert "Available with `N r': (0)ALL")
  3476. (let ((n 0) s)
  3477. (mapc (lambda (x)
  3478. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3479. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3480. (insert "\n "))
  3481. (insert " " s))
  3482. kwds))
  3483. (insert "\n"))
  3484. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3485. (org-agenda-mark-header-line (point-min))
  3486. (when rtnall
  3487. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3488. (goto-char (point-min))
  3489. (or org-agenda-multi (org-fit-agenda-window))
  3490. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3491. (org-finalize-agenda)
  3492. (setq buffer-read-only t)))
  3493. ;;; Agenda tags match
  3494. ;;;###autoload
  3495. (defun org-tags-view (&optional todo-only match)
  3496. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3497. The prefix arg TODO-ONLY limits the search to TODO entries."
  3498. (interactive "P")
  3499. (org-compile-prefix-format 'tags)
  3500. (org-set-sorting-strategy 'tags)
  3501. (let* ((org-tags-match-list-sublevels
  3502. org-tags-match-list-sublevels)
  3503. (completion-ignore-case t)
  3504. rtn rtnall files file pos matcher
  3505. buffer)
  3506. (when (and (stringp match) (not (string-match "\\S-" match)))
  3507. (setq match nil))
  3508. (setq matcher (org-make-tags-matcher match)
  3509. match (car matcher) matcher (cdr matcher))
  3510. (org-prepare-agenda (concat "TAGS " match))
  3511. (setq org-agenda-query-string match)
  3512. (setq org-agenda-redo-command
  3513. (list 'org-tags-view (list 'quote todo-only)
  3514. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3515. (setq files (org-agenda-files nil 'ifmode)
  3516. rtnall nil)
  3517. (while (setq file (pop files))
  3518. (catch 'nextfile
  3519. (org-check-agenda-file file)
  3520. (setq buffer (if (file-exists-p file)
  3521. (org-get-agenda-file-buffer file)
  3522. (error "No such file %s" file)))
  3523. (if (not buffer)
  3524. ;; If file does not exist, error message to agenda
  3525. (setq rtn (list
  3526. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3527. rtnall (append rtnall rtn))
  3528. (with-current-buffer buffer
  3529. (unless (org-mode-p)
  3530. (error "Agenda file %s is not in `org-mode'" file))
  3531. (save-excursion
  3532. (save-restriction
  3533. (if org-agenda-restrict
  3534. (narrow-to-region org-agenda-restrict-begin
  3535. org-agenda-restrict-end)
  3536. (widen))
  3537. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3538. (setq rtnall (append rtnall rtn))))))))
  3539. (if org-agenda-overriding-header
  3540. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3541. nil 'face 'org-agenda-structure) "\n")
  3542. (insert "Headlines with TAGS match: ")
  3543. (add-text-properties (point-min) (1- (point))
  3544. (list 'face 'org-agenda-structure
  3545. 'short-heading
  3546. (concat "Match: " match)))
  3547. (setq pos (point))
  3548. (insert match "\n")
  3549. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3550. (setq pos (point))
  3551. (unless org-agenda-multi
  3552. (insert "Press `C-u r' to search again with new search string\n"))
  3553. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3554. (org-agenda-mark-header-line (point-min))
  3555. (when rtnall
  3556. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3557. (goto-char (point-min))
  3558. (or org-agenda-multi (org-fit-agenda-window))
  3559. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3560. (org-finalize-agenda)
  3561. (setq buffer-read-only t)))
  3562. ;;; Agenda Finding stuck projects
  3563. (defvar org-agenda-skip-regexp nil
  3564. "Regular expression used in skipping subtrees for the agenda.
  3565. This is basically a temporary global variable that can be set and then
  3566. used by user-defined selections using `org-agenda-skip-function'.")
  3567. (defvar org-agenda-overriding-header nil
  3568. "When this is set during todo and tags searches, will replace header.
  3569. This variable should not be set directly, but custom commands can bind it
  3570. in the options section.")
  3571. (defun org-agenda-skip-entry-when-regexp-matches ()
  3572. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3573. If yes, it returns the end position of this entry, causing agenda commands
  3574. to skip the entry but continuing the search in the subtree. This is a
  3575. function that can be put into `org-agenda-skip-function' for the duration
  3576. of a command."
  3577. (let ((end (save-excursion (org-end-of-subtree t)))
  3578. skip)
  3579. (save-excursion
  3580. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3581. (and skip end)))
  3582. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3583. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3584. If yes, it returns the end position of this tree, causing agenda commands
  3585. to skip this subtree. This is a function that can be put into
  3586. `org-agenda-skip-function' for the duration of a command."
  3587. (let ((end (save-excursion (org-end-of-subtree t)))
  3588. skip)
  3589. (save-excursion
  3590. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3591. (and skip end)))
  3592. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3593. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3594. If yes, it returns the end position of the current entry (NOT the tree),
  3595. causing agenda commands to skip the entry but continuing the search in
  3596. the subtree. This is a function that can be put into
  3597. `org-agenda-skip-function' for the duration of a command. An important
  3598. use of this function is for the stuck project list."
  3599. (let ((end (save-excursion (org-end-of-subtree t)))
  3600. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3601. skip)
  3602. (save-excursion
  3603. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3604. (and skip entry-end)))
  3605. (defun org-agenda-skip-entry-if (&rest conditions)
  3606. "Skip entry if any of CONDITIONS is true.
  3607. See `org-agenda-skip-if' for details."
  3608. (org-agenda-skip-if nil conditions))
  3609. (defun org-agenda-skip-subtree-if (&rest conditions)
  3610. "Skip entry if any of CONDITIONS is true.
  3611. See `org-agenda-skip-if' for details."
  3612. (org-agenda-skip-if t conditions))
  3613. (defun org-agenda-skip-if (subtree conditions)
  3614. "Checks current entity for CONDITIONS.
  3615. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3616. the entry, i.e. the text before the next heading is checked.
  3617. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3618. from different tests. Valid conditions are:
  3619. scheduled Check if there is a scheduled cookie
  3620. notscheduled Check if there is no scheduled cookie
  3621. deadline Check if there is a deadline
  3622. notdeadline Check if there is no deadline
  3623. timestamp Check if there is a timestamp (also deadline or scheduled)
  3624. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3625. regexp Check if regexp matches
  3626. notregexp Check if regexp does not match.
  3627. todo Check if TODO keyword matches
  3628. nottodo Check if TODO keyword does not match
  3629. The regexp is taken from the conditions list, it must come right after
  3630. the `regexp' or `notregexp' element.
  3631. `todo' and `nottodo' accept as an argument a list of todo
  3632. keywords, which may include \"*\" to match any todo keyword.
  3633. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3634. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3635. Instead of a list a keyword class may be given
  3636. (org-agenda-skip-entry-if 'nottodo 'done)
  3637. would skip entries that haven't been marked with any of \"DONE\"
  3638. keywords. Possible classes are: `todo', `done', `any'.
  3639. If any of these conditions is met, this function returns the end point of
  3640. the entity, causing the search to continue from there. This is a function
  3641. that can be put into `org-agenda-skip-function' for the duration of a command."
  3642. (let (beg end m)
  3643. (org-back-to-heading t)
  3644. (setq beg (point)
  3645. end (if subtree
  3646. (progn (org-end-of-subtree t) (point))
  3647. (progn (outline-next-heading) (1- (point)))))
  3648. (goto-char beg)
  3649. (and
  3650. (or
  3651. (and (memq 'scheduled conditions)
  3652. (re-search-forward org-scheduled-time-regexp end t))
  3653. (and (memq 'notscheduled conditions)
  3654. (not (re-search-forward org-scheduled-time-regexp end t)))
  3655. (and (memq 'deadline conditions)
  3656. (re-search-forward org-deadline-time-regexp end t))
  3657. (and (memq 'notdeadline conditions)
  3658. (not (re-search-forward org-deadline-time-regexp end t)))
  3659. (and (memq 'timestamp conditions)
  3660. (re-search-forward org-ts-regexp end t))
  3661. (and (memq 'nottimestamp conditions)
  3662. (not (re-search-forward org-ts-regexp end t)))
  3663. (and (setq m (memq 'regexp conditions))
  3664. (stringp (nth 1 m))
  3665. (re-search-forward (nth 1 m) end t))
  3666. (and (setq m (memq 'notregexp conditions))
  3667. (stringp (nth 1 m))
  3668. (not (re-search-forward (nth 1 m) end t)))
  3669. (and (or
  3670. (setq m (memq 'todo conditions))
  3671. (setq m (memq 'nottodo conditions)))
  3672. (org-agenda-skip-if-todo m end)))
  3673. end)))
  3674. (defun org-agenda-skip-if-todo (args end)
  3675. "Helper function for `org-agenda-skip-if', do not use it directly.
  3676. ARGS is a list with first element either `todo' or `nottodo'.
  3677. The remainder is either a list of TODO keywords, or a state symbol
  3678. `todo' or `done' or `any'."
  3679. (let ((kw (car args))
  3680. (arg (cadr args))
  3681. todo-wds todo-re)
  3682. (setq todo-wds
  3683. (org-uniquify
  3684. (cond
  3685. ((listp arg) ;; list of keywords
  3686. (if (member "*" arg)
  3687. (mapcar 'substring-no-properties org-todo-keywords-1)
  3688. arg))
  3689. ((symbolp arg) ;; keyword class name
  3690. (cond
  3691. ((eq arg 'todo)
  3692. (org-delete-all org-done-keywords
  3693. (mapcar 'substring-no-properties
  3694. org-todo-keywords-1)))
  3695. ((eq arg 'done) org-done-keywords)
  3696. ((eq arg 'any)
  3697. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3698. (setq todo-re
  3699. (concat "^\\*+[ \t]+\\<\\("
  3700. (mapconcat 'identity todo-wds "\\|")
  3701. "\\)\\>"))
  3702. (if (eq kw 'todo)
  3703. (re-search-forward todo-re end t)
  3704. (not (re-search-forward todo-re end t)))))
  3705. ;;;###autoload
  3706. (defun org-agenda-list-stuck-projects (&rest ignore)
  3707. "Create agenda view for projects that are stuck.
  3708. Stuck projects are project that have no next actions. For the definitions
  3709. of what a project is and how to check if it stuck, customize the variable
  3710. `org-stuck-projects'."
  3711. (interactive)
  3712. (let* ((org-agenda-skip-function
  3713. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3714. ;; We could have used org-agenda-skip-if here.
  3715. (org-agenda-overriding-header
  3716. (or org-agenda-overriding-header "List of stuck projects: "))
  3717. (matcher (nth 0 org-stuck-projects))
  3718. (todo (nth 1 org-stuck-projects))
  3719. (todo-wds (if (member "*" todo)
  3720. (progn
  3721. (org-prepare-agenda-buffers (org-agenda-files
  3722. nil 'ifmode))
  3723. (org-delete-all
  3724. org-done-keywords-for-agenda
  3725. (copy-sequence org-todo-keywords-for-agenda)))
  3726. todo))
  3727. (todo-re (concat "^\\*+[ \t]+\\("
  3728. (mapconcat 'identity todo-wds "\\|")
  3729. "\\)\\>"))
  3730. (tags (nth 2 org-stuck-projects))
  3731. (tags-re (if (member "*" tags)
  3732. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3733. (if tags
  3734. (concat "^\\*+ .*:\\("
  3735. (mapconcat 'identity tags "\\|")
  3736. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3737. (gen-re (nth 3 org-stuck-projects))
  3738. (re-list
  3739. (delq nil
  3740. (list
  3741. (if todo todo-re)
  3742. (if tags tags-re)
  3743. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3744. gen-re)))))
  3745. (setq org-agenda-skip-regexp
  3746. (if re-list
  3747. (mapconcat 'identity re-list "\\|")
  3748. (error "No information how to identify unstuck projects")))
  3749. (org-tags-view nil matcher)
  3750. (with-current-buffer org-agenda-buffer-name
  3751. (setq org-agenda-redo-command
  3752. '(org-agenda-list-stuck-projects
  3753. (or current-prefix-arg org-last-arg))))))
  3754. ;;; Diary integration
  3755. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3756. (defvar list-diary-entries-hook)
  3757. (defun org-get-entries-from-diary (date)
  3758. "Get the (Emacs Calendar) diary entries for DATE."
  3759. (require 'diary-lib)
  3760. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3761. (diary-display-hook '(fancy-diary-display))
  3762. (diary-display-function 'fancy-diary-display)
  3763. (pop-up-frames nil)
  3764. (list-diary-entries-hook
  3765. (cons 'org-diary-default-entry list-diary-entries-hook))
  3766. (diary-file-name-prefix-function nil) ; turn this feature off
  3767. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3768. entries
  3769. (org-disable-agenda-to-diary t))
  3770. (save-excursion
  3771. (save-window-excursion
  3772. (funcall (if (fboundp 'diary-list-entries)
  3773. 'diary-list-entries 'list-diary-entries)
  3774. date 1)))
  3775. (if (not (get-buffer diary-fancy-buffer))
  3776. (setq entries nil)
  3777. (with-current-buffer diary-fancy-buffer
  3778. (setq buffer-read-only nil)
  3779. (if (zerop (buffer-size))
  3780. ;; No entries
  3781. (setq entries nil)
  3782. ;; Omit the date and other unnecessary stuff
  3783. (org-agenda-cleanup-fancy-diary)
  3784. ;; Add prefix to each line and extend the text properties
  3785. (if (zerop (buffer-size))
  3786. (setq entries nil)
  3787. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3788. (set-buffer-modified-p nil)
  3789. (kill-buffer diary-fancy-buffer)))
  3790. (when entries
  3791. (setq entries (org-split-string entries "\n"))
  3792. (setq entries
  3793. (mapcar
  3794. (lambda (x)
  3795. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3796. ;; Extend the text properties to the beginning of the line
  3797. (org-add-props x (text-properties-at (1- (length x)) x)
  3798. 'type "diary" 'date date 'face 'org-agenda-diary))
  3799. entries)))))
  3800. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3801. "Hook run when the fancy diary buffer is cleaned up.")
  3802. (defun org-agenda-cleanup-fancy-diary ()
  3803. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3804. This gets rid of the date, the underline under the date, and
  3805. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3806. date. It also removes lines that contain only whitespace."
  3807. (goto-char (point-min))
  3808. (if (looking-at ".*?:[ \t]*")
  3809. (progn
  3810. (replace-match "")
  3811. (re-search-forward "\n=+$" nil t)
  3812. (replace-match "")
  3813. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3814. (re-search-forward "\n=+$" nil t)
  3815. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3816. (goto-char (point-min))
  3817. (while (re-search-forward "^ +\n" nil t)
  3818. (replace-match ""))
  3819. (goto-char (point-min))
  3820. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3821. (replace-match ""))
  3822. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3823. ;; Make sure entries from the diary have the right text properties.
  3824. (eval-after-load "diary-lib"
  3825. '(if (boundp 'diary-modify-entry-list-string-function)
  3826. ;; We can rely on the hook, nothing to do
  3827. nil
  3828. ;; Hook not available, must use advice to make this work
  3829. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3830. "Make the position visible."
  3831. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3832. (stringp string)
  3833. buffer-file-name)
  3834. (setq string (org-modify-diary-entry-string string))))))
  3835. (defun org-modify-diary-entry-string (string)
  3836. "Add text properties to string, allowing org-mode to act on it."
  3837. (org-add-props string nil
  3838. 'mouse-face 'highlight
  3839. 'help-echo (if buffer-file-name
  3840. (format "mouse-2 or RET jump to diary file %s"
  3841. (abbreviate-file-name buffer-file-name))
  3842. "")
  3843. 'org-agenda-diary-link t
  3844. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3845. (defun org-diary-default-entry ()
  3846. "Add a dummy entry to the diary.
  3847. Needed to avoid empty dates which mess up holiday display."
  3848. ;; Catch the error if dealing with the new add-to-diary-alist
  3849. (when org-disable-agenda-to-diary
  3850. (condition-case nil
  3851. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3852. (error
  3853. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3854. (defun org-add-to-diary-list (&rest args)
  3855. (if (fboundp 'diary-add-to-list)
  3856. (apply 'diary-add-to-list args)
  3857. (apply 'add-to-diary-list args)))
  3858. (defvar org-diary-last-run-time nil)
  3859. ;;;###autoload
  3860. (defun org-diary (&rest args)
  3861. "Return diary information from org-files.
  3862. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3863. It accesses org files and extracts information from those files to be
  3864. listed in the diary. The function accepts arguments specifying what
  3865. items should be listed. For a list of arguments allowed here, see the
  3866. variable `org-agenda-entry-types'.
  3867. The call in the diary file should look like this:
  3868. &%%(org-diary) ~/path/to/some/orgfile.org
  3869. Use a separate line for each org file to check. Or, if you omit the file name,
  3870. all files listed in `org-agenda-files' will be checked automatically:
  3871. &%%(org-diary)
  3872. If you don't give any arguments (as in the example above), the default
  3873. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3874. So the example above may also be written as
  3875. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3876. The function expects the lisp variables `entry' and `date' to be provided
  3877. by the caller, because this is how the calendar works. Don't use this
  3878. function from a program - use `org-agenda-get-day-entries' instead."
  3879. (when (> (- (org-float-time)
  3880. org-agenda-last-marker-time)
  3881. 5)
  3882. (org-agenda-reset-markers))
  3883. (org-compile-prefix-format 'agenda)
  3884. (org-set-sorting-strategy 'agenda)
  3885. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3886. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3887. (list entry)
  3888. (org-agenda-files t)))
  3889. (time (org-float-time))
  3890. file rtn results)
  3891. (when (or (not org-diary-last-run-time)
  3892. (> (- time
  3893. org-diary-last-run-time)
  3894. 3))
  3895. (org-prepare-agenda-buffers files))
  3896. (setq org-diary-last-run-time time)
  3897. ;; If this is called during org-agenda, don't return any entries to
  3898. ;; the calendar. Org Agenda will list these entries itself.
  3899. (if org-disable-agenda-to-diary (setq files nil))
  3900. (while (setq file (pop files))
  3901. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3902. (setq results (append results rtn)))
  3903. (if results
  3904. (concat (org-finalize-agenda-entries results) "\n"))))
  3905. ;;; Agenda entry finders
  3906. (defun org-agenda-get-day-entries (file date &rest args)
  3907. "Does the work for `org-diary' and `org-agenda'.
  3908. FILE is the path to a file to be checked for entries. DATE is date like
  3909. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3910. which kind of entries should be extracted. For details about these, see
  3911. the documentation of `org-diary'."
  3912. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3913. (let* ((org-startup-folded nil)
  3914. (org-startup-align-all-tables nil)
  3915. (buffer (if (file-exists-p file)
  3916. (org-get-agenda-file-buffer file)
  3917. (error "No such file %s" file)))
  3918. arg results rtn deadline-results)
  3919. (if (not buffer)
  3920. ;; If file does not exist, make sure an error message ends up in diary
  3921. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3922. (with-current-buffer buffer
  3923. (unless (org-mode-p)
  3924. (error "Agenda file %s is not in `org-mode'" file))
  3925. (let ((case-fold-search nil))
  3926. (save-excursion
  3927. (save-restriction
  3928. (if org-agenda-restrict
  3929. (narrow-to-region org-agenda-restrict-begin
  3930. org-agenda-restrict-end)
  3931. (widen))
  3932. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3933. (while (setq arg (pop args))
  3934. (cond
  3935. ((and (eq arg :todo)
  3936. (equal date (calendar-current-date)))
  3937. (setq rtn (org-agenda-get-todos))
  3938. (setq results (append results rtn)))
  3939. ((eq arg :timestamp)
  3940. (setq rtn (org-agenda-get-blocks))
  3941. (setq results (append results rtn))
  3942. (setq rtn (org-agenda-get-timestamps))
  3943. (setq results (append results rtn)))
  3944. ((eq arg :sexp)
  3945. (setq rtn (org-agenda-get-sexps))
  3946. (setq results (append results rtn)))
  3947. ((eq arg :scheduled)
  3948. (setq rtn (org-agenda-get-scheduled deadline-results))
  3949. (setq results (append results rtn)))
  3950. ((eq arg :closed)
  3951. (setq rtn (org-agenda-get-progress))
  3952. (setq results (append results rtn)))
  3953. ((eq arg :deadline)
  3954. (setq rtn (org-agenda-get-deadlines))
  3955. (setq deadline-results (copy-sequence rtn))
  3956. (setq results (append results rtn))))))))
  3957. results))))
  3958. (defun org-agenda-get-todos ()
  3959. "Return the TODO information for agenda display."
  3960. (let* ((props (list 'face nil
  3961. 'done-face 'org-agenda-done
  3962. 'org-not-done-regexp org-not-done-regexp
  3963. 'org-todo-regexp org-todo-regexp
  3964. 'org-complex-heading-regexp org-complex-heading-regexp
  3965. 'mouse-face 'highlight
  3966. 'help-echo
  3967. (format "mouse-2 or RET jump to org file %s"
  3968. (abbreviate-file-name buffer-file-name))))
  3969. (regexp (concat "^\\*+[ \t]+\\("
  3970. (if org-select-this-todo-keyword
  3971. (if (equal org-select-this-todo-keyword "*")
  3972. org-todo-regexp
  3973. (concat "\\<\\("
  3974. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3975. "\\)\\>"))
  3976. org-not-done-regexp)
  3977. "[^\n\r]*\\)"))
  3978. marker priority category tags todo-state
  3979. ee txt beg end)
  3980. (goto-char (point-min))
  3981. (while (re-search-forward regexp nil t)
  3982. (catch :skip
  3983. (save-match-data
  3984. (beginning-of-line)
  3985. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3986. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3987. (goto-char (1+ beg))
  3988. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3989. (throw :skip nil)))
  3990. (goto-char beg)
  3991. (org-agenda-skip)
  3992. (goto-char (match-beginning 1))
  3993. (setq marker (org-agenda-new-marker (match-beginning 0))
  3994. category (org-get-category)
  3995. txt (match-string 1)
  3996. tags (org-get-tags-at (point))
  3997. txt (org-format-agenda-item "" txt category tags)
  3998. priority (1+ (org-get-priority txt))
  3999. todo-state (org-get-todo-state))
  4000. (org-add-props txt props
  4001. 'org-marker marker 'org-hd-marker marker
  4002. 'priority priority 'org-category category
  4003. 'type "todo" 'todo-state todo-state)
  4004. (push txt ee)
  4005. (if org-agenda-todo-list-sublevels
  4006. (goto-char (match-end 1))
  4007. (org-end-of-subtree 'invisible))))
  4008. (nreverse ee)))
  4009. ;;;###autoload
  4010. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4011. (&optional end)
  4012. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4013. (when (or org-agenda-todo-ignore-with-date
  4014. org-agenda-todo-ignore-scheduled
  4015. org-agenda-todo-ignore-deadlines)
  4016. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4017. (save-excursion
  4018. (or (and org-agenda-todo-ignore-with-date
  4019. (re-search-forward org-ts-regexp end t))
  4020. (and org-agenda-todo-ignore-scheduled
  4021. (re-search-forward org-scheduled-time-regexp end t)
  4022. (cond
  4023. ((eq org-agenda-todo-ignore-scheduled 'future)
  4024. (> (org-days-to-time (match-string 1)) 0))
  4025. ((eq org-agenda-todo-ignore-scheduled 'past)
  4026. (<= (org-days-to-time (match-string 1)) 0))
  4027. (t)))
  4028. (and org-agenda-todo-ignore-deadlines
  4029. (re-search-forward org-deadline-time-regexp end t)
  4030. (cond
  4031. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4032. ((eq org-agenda-todo-ignore-deadlines 'far)
  4033. (not (org-deadline-close (match-string 1))))
  4034. ((eq org-agenda-todo-ignore-deadlines 'future)
  4035. (> (org-days-to-time (match-string 1)) 0))
  4036. ((eq org-agenda-todo-ignore-deadlines 'past)
  4037. (<= (org-days-to-time (match-string 1)) 0))
  4038. (t (org-deadline-close (match-string 1)))))))))
  4039. (defconst org-agenda-no-heading-message
  4040. "No heading for this item in buffer or region.")
  4041. (defun org-agenda-get-timestamps ()
  4042. "Return the date stamp information for agenda display."
  4043. (let* ((props (list 'face nil
  4044. 'org-not-done-regexp org-not-done-regexp
  4045. 'org-todo-regexp org-todo-regexp
  4046. 'org-complex-heading-regexp org-complex-heading-regexp
  4047. 'mouse-face 'highlight
  4048. 'help-echo
  4049. (format "mouse-2 or RET jump to org file %s"
  4050. (abbreviate-file-name buffer-file-name))))
  4051. (d1 (calendar-absolute-from-gregorian date))
  4052. (remove-re
  4053. (concat
  4054. (regexp-quote
  4055. (format-time-string
  4056. "<%Y-%m-%d"
  4057. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4058. ".*?>"))
  4059. (regexp
  4060. (concat
  4061. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4062. (regexp-quote
  4063. (substring
  4064. (format-time-string
  4065. (car org-time-stamp-formats)
  4066. (apply 'encode-time ; DATE bound by calendar
  4067. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4068. 1 11))
  4069. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4070. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4071. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4072. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4073. todo-state end-of-match)
  4074. (goto-char (point-min))
  4075. (while (setq end-of-match (re-search-forward regexp nil t))
  4076. (setq b0 (match-beginning 0)
  4077. b3 (match-beginning 3) e3 (match-end 3))
  4078. (catch :skip
  4079. (and (org-at-date-range-p) (throw :skip nil))
  4080. (org-agenda-skip)
  4081. (if (and (match-end 1)
  4082. (not (= d1 (org-time-string-to-absolute
  4083. (match-string 1) d1 nil
  4084. org-agenda-repeating-timestamp-show-all))))
  4085. (throw :skip nil))
  4086. (if (and e3
  4087. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4088. (throw :skip nil))
  4089. (setq tmp (buffer-substring (max (point-min)
  4090. (- b0 org-ds-keyword-length))
  4091. b0)
  4092. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4093. inactivep (= (char-after b0) ?\[)
  4094. deadlinep (string-match org-deadline-regexp tmp)
  4095. scheduledp (string-match org-scheduled-regexp tmp)
  4096. closedp (and org-agenda-include-inactive-timestamps
  4097. (string-match org-closed-string tmp))
  4098. clockp (and org-agenda-include-inactive-timestamps
  4099. (or (string-match org-clock-string tmp)
  4100. (string-match "]-+\\'" tmp)))
  4101. todo-state (ignore-errors (org-get-todo-state))
  4102. donep (member todo-state org-done-keywords))
  4103. (if (or scheduledp deadlinep closedp clockp
  4104. (and donep org-agenda-skip-timestamp-if-done))
  4105. (throw :skip t))
  4106. (if (string-match ">" timestr)
  4107. ;; substring should only run to end of time stamp
  4108. (setq timestr (substring timestr 0 (match-end 0))))
  4109. (setq marker (org-agenda-new-marker b0)
  4110. category (org-get-category b0))
  4111. (save-excursion
  4112. (if (not (re-search-backward "^\\*+ " nil t))
  4113. (setq txt org-agenda-no-heading-message)
  4114. (goto-char (match-beginning 0))
  4115. (setq hdmarker (org-agenda-new-marker)
  4116. tags (org-get-tags-at))
  4117. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4118. (setq head (match-string 1))
  4119. (setq txt (org-format-agenda-item
  4120. (if inactivep org-agenda-inactive-leader nil)
  4121. head category tags timestr nil
  4122. remove-re)))
  4123. (setq priority (org-get-priority txt))
  4124. (org-add-props txt props
  4125. 'org-marker marker 'org-hd-marker hdmarker)
  4126. (org-add-props txt nil 'priority priority
  4127. 'org-category category 'date date
  4128. 'todo-state todo-state
  4129. 'type "timestamp")
  4130. (push txt ee))
  4131. (if org-agenda-skip-additional-timestamps-same-entry
  4132. (outline-next-heading)
  4133. (goto-char end-of-match))))
  4134. (nreverse ee)))
  4135. (defun org-agenda-get-sexps ()
  4136. "Return the sexp information for agenda display."
  4137. (require 'diary-lib)
  4138. (let* ((props (list 'face nil
  4139. 'mouse-face 'highlight
  4140. 'help-echo
  4141. (format "mouse-2 or RET jump to org file %s"
  4142. (abbreviate-file-name buffer-file-name))))
  4143. (regexp "^&?%%(")
  4144. marker category ee txt tags entry result beg b sexp sexp-entry
  4145. todo-state)
  4146. (goto-char (point-min))
  4147. (while (re-search-forward regexp nil t)
  4148. (catch :skip
  4149. (org-agenda-skip)
  4150. (setq beg (match-beginning 0))
  4151. (goto-char (1- (match-end 0)))
  4152. (setq b (point))
  4153. (forward-sexp 1)
  4154. (setq sexp (buffer-substring b (point)))
  4155. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4156. (org-trim (match-string 1))
  4157. ""))
  4158. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4159. (when result
  4160. (setq marker (org-agenda-new-marker beg)
  4161. category (org-get-category beg)
  4162. todo-state (org-get-todo-state))
  4163. (if (string-match "\\S-" result)
  4164. (setq txt result)
  4165. (setq txt "SEXP entry returned empty string"))
  4166. (setq txt (org-format-agenda-item
  4167. "" txt category tags 'time))
  4168. (org-add-props txt props 'org-marker marker)
  4169. (org-add-props txt nil
  4170. 'org-category category 'date date 'todo-state todo-state
  4171. 'type "sexp")
  4172. (push txt ee))))
  4173. (nreverse ee)))
  4174. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4175. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4176. The order of the first 2 times 3 arguments depends on the variable
  4177. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4178. So for American calendars, give this as MONTH DAY YEAR, for European as
  4179. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4180. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4181. is any number of ISO weeks in the block period for which the item should
  4182. be skipped."
  4183. (let* ((date1 (calendar-absolute-from-gregorian
  4184. (org-order-calendar-date-args m1 d1 y1)))
  4185. (date2 (calendar-absolute-from-gregorian
  4186. (org-order-calendar-date-args m2 d2 y2)))
  4187. (d (calendar-absolute-from-gregorian date)))
  4188. (and
  4189. (<= date1 d)
  4190. (<= d date2)
  4191. (= (calendar-day-of-week date) dayname)
  4192. (or (not skip-weeks)
  4193. (progn
  4194. (require 'cal-iso)
  4195. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4196. entry)))
  4197. (defalias 'org-get-closed 'org-agenda-get-progress)
  4198. (defun org-agenda-get-progress ()
  4199. "Return the logged TODO entries for agenda display."
  4200. (let* ((props (list 'mouse-face 'highlight
  4201. 'org-not-done-regexp org-not-done-regexp
  4202. 'org-todo-regexp org-todo-regexp
  4203. 'org-complex-heading-regexp org-complex-heading-regexp
  4204. 'help-echo
  4205. (format "mouse-2 or RET jump to org file %s"
  4206. (abbreviate-file-name buffer-file-name))))
  4207. (items (if (consp org-agenda-show-log)
  4208. org-agenda-show-log
  4209. org-agenda-log-mode-items))
  4210. (parts
  4211. (delq nil
  4212. (list
  4213. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4214. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4215. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4216. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4217. (error "`org-agenda-log-mode-items' is empty")))
  4218. (regexp (concat
  4219. "\\(" parts-re "\\)"
  4220. " *\\["
  4221. (regexp-quote
  4222. (substring
  4223. (format-time-string
  4224. (car org-time-stamp-formats)
  4225. (apply 'encode-time ; DATE bound by calendar
  4226. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4227. 1 11))))
  4228. (org-agenda-search-headline-for-time nil)
  4229. marker hdmarker priority category tags closedp statep clockp state
  4230. ee txt extra timestr rest clocked)
  4231. (goto-char (point-min))
  4232. (while (re-search-forward regexp nil t)
  4233. (catch :skip
  4234. (org-agenda-skip)
  4235. (setq marker (org-agenda-new-marker (match-beginning 0))
  4236. closedp (equal (match-string 1) org-closed-string)
  4237. statep (equal (string-to-char (match-string 1)) ?-)
  4238. clockp (not (or closedp statep))
  4239. state (and statep (match-string 2))
  4240. category (org-get-category (match-beginning 0))
  4241. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4242. )
  4243. (when (string-match "\\]" timestr)
  4244. ;; substring should only run to end of time stamp
  4245. (setq rest (substring timestr (match-end 0))
  4246. timestr (substring timestr 0 (match-end 0)))
  4247. (if (and (not closedp) (not statep)
  4248. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4249. (progn (setq timestr (concat (substring timestr 0 -1)
  4250. "-" (match-string 1 rest) "]"))
  4251. (setq clocked (match-string 2 rest)))
  4252. (setq clocked "-")))
  4253. (save-excursion
  4254. (setq extra nil)
  4255. (cond
  4256. ((not org-agenda-log-mode-add-notes))
  4257. (statep
  4258. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4259. (setq extra (match-string 1))))
  4260. (clockp
  4261. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4262. (setq extra (match-string 1)))))
  4263. (if (not (re-search-backward "^\\*+ " nil t))
  4264. (setq txt org-agenda-no-heading-message)
  4265. (goto-char (match-beginning 0))
  4266. (setq hdmarker (org-agenda-new-marker)
  4267. tags (org-get-tags-at))
  4268. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4269. (setq txt (match-string 1))
  4270. (when extra
  4271. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4272. (setq txt (concat (substring txt 0 (match-beginning 1))
  4273. " - " extra " " (match-string 2 txt)))
  4274. (setq txt (concat txt " - " extra))))
  4275. (setq txt (org-format-agenda-item
  4276. (cond
  4277. (closedp "Closed: ")
  4278. (statep (concat "State: (" state ")"))
  4279. (t (concat "Clocked: (" clocked ")")))
  4280. txt category tags timestr)))
  4281. (setq priority 100000)
  4282. (org-add-props txt props
  4283. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4284. 'priority priority 'org-category category
  4285. 'type "closed" 'date date
  4286. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4287. (push txt ee))
  4288. (goto-char (point-at-eol))))
  4289. (nreverse ee)))
  4290. (defun org-agenda-get-deadlines ()
  4291. "Return the deadline information for agenda display."
  4292. (let* ((props (list 'mouse-face 'highlight
  4293. 'org-not-done-regexp org-not-done-regexp
  4294. 'org-todo-regexp org-todo-regexp
  4295. 'org-complex-heading-regexp org-complex-heading-regexp
  4296. 'help-echo
  4297. (format "mouse-2 or RET jump to org file %s"
  4298. (abbreviate-file-name buffer-file-name))))
  4299. (regexp org-deadline-time-regexp)
  4300. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4301. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4302. d2 diff dfrac wdays pos pos1 category tags
  4303. suppress-prewarning
  4304. ee txt head face s todo-state upcomingp donep timestr)
  4305. (goto-char (point-min))
  4306. (while (re-search-forward regexp nil t)
  4307. (setq suppress-prewarning nil)
  4308. (catch :skip
  4309. (org-agenda-skip)
  4310. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4311. (save-match-data
  4312. (string-match org-scheduled-time-regexp
  4313. (buffer-substring (point-at-bol)
  4314. (point-at-eol)))))
  4315. (setq suppress-prewarning
  4316. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4317. org-agenda-skip-deadline-prewarning-if-scheduled
  4318. 0)))
  4319. (setq s (match-string 1)
  4320. txt nil
  4321. pos (1- (match-beginning 1))
  4322. d2 (org-time-string-to-absolute
  4323. (match-string 1) d1 'past
  4324. org-agenda-repeating-timestamp-show-all)
  4325. diff (- d2 d1)
  4326. wdays (if suppress-prewarning
  4327. (let ((org-deadline-warning-days suppress-prewarning))
  4328. (org-get-wdays s))
  4329. (org-get-wdays s))
  4330. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4331. upcomingp (and todayp (> diff 0)))
  4332. ;; When to show a deadline in the calendar:
  4333. ;; If the expiration is within wdays warning time.
  4334. ;; Past-due deadlines are only shown on the current date
  4335. (if (and (or (and (<= diff wdays)
  4336. (and todayp (not org-agenda-only-exact-dates)))
  4337. (= diff 0)))
  4338. (save-excursion
  4339. (setq todo-state (org-get-todo-state))
  4340. (setq donep (member todo-state org-done-keywords))
  4341. (if (and donep
  4342. (or org-agenda-skip-deadline-if-done
  4343. (not (= diff 0))))
  4344. (setq txt nil)
  4345. (setq category (org-get-category))
  4346. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4347. (setq txt org-agenda-no-heading-message)
  4348. (goto-char (match-end 0))
  4349. (setq pos1 (match-beginning 0))
  4350. (setq tags (org-get-tags-at pos1))
  4351. (setq head (buffer-substring-no-properties
  4352. (point)
  4353. (progn (skip-chars-forward "^\r\n")
  4354. (point))))
  4355. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4356. (setq timestr
  4357. (concat (substring s (match-beginning 1)) " "))
  4358. (setq timestr 'time))
  4359. (setq txt (org-format-agenda-item
  4360. (if (= diff 0)
  4361. (car org-agenda-deadline-leaders)
  4362. (if (functionp
  4363. (nth 1 org-agenda-deadline-leaders))
  4364. (funcall
  4365. (nth 1 org-agenda-deadline-leaders)
  4366. diff date)
  4367. (format (nth 1 org-agenda-deadline-leaders)
  4368. diff)))
  4369. head category tags
  4370. (if (not (= diff 0)) nil timestr)))))
  4371. (when txt
  4372. (setq face (org-agenda-deadline-face dfrac wdays))
  4373. (org-add-props txt props
  4374. 'org-marker (org-agenda-new-marker pos)
  4375. 'org-hd-marker (org-agenda-new-marker pos1)
  4376. 'priority (+ (- diff)
  4377. (org-get-priority txt))
  4378. 'org-category category
  4379. 'todo-state todo-state
  4380. 'type (if upcomingp "upcoming-deadline" "deadline")
  4381. 'date (if upcomingp date d2)
  4382. 'face (if donep 'org-agenda-done face)
  4383. 'undone-face face 'done-face 'org-agenda-done)
  4384. (push txt ee))))))
  4385. (nreverse ee)))
  4386. (defun org-agenda-deadline-face (fraction &optional wdays)
  4387. "Return the face to displaying a deadline item.
  4388. FRACTION is what fraction of the head-warning time has passed."
  4389. (if (equal wdays 0) (setq fraction 1.))
  4390. (let ((faces org-agenda-deadline-faces) f)
  4391. (catch 'exit
  4392. (while (setq f (pop faces))
  4393. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4394. (defun org-agenda-get-scheduled (&optional deadline-results)
  4395. "Return the scheduled information for agenda display."
  4396. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4397. 'org-todo-regexp org-todo-regexp
  4398. 'org-complex-heading-regexp org-complex-heading-regexp
  4399. 'done-face 'org-agenda-done
  4400. 'mouse-face 'highlight
  4401. 'help-echo
  4402. (format "mouse-2 or RET jump to org file %s"
  4403. (abbreviate-file-name buffer-file-name))))
  4404. (regexp org-scheduled-time-regexp)
  4405. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4406. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4407. mm
  4408. (deadline-position-alist
  4409. (mapcar (lambda (a) (and (setq mm (get-text-property
  4410. 0 'org-hd-marker a))
  4411. (cons (marker-position mm) a)))
  4412. deadline-results))
  4413. d2 diff pos pos1 category tags donep
  4414. ee txt head pastschedp todo-state face timestr s habitp)
  4415. (goto-char (point-min))
  4416. (while (re-search-forward regexp nil t)
  4417. (catch :skip
  4418. (org-agenda-skip)
  4419. (setq s (match-string 1)
  4420. txt nil
  4421. pos (1- (match-beginning 1))
  4422. d2 (org-time-string-to-absolute
  4423. (match-string 1) d1 'past
  4424. org-agenda-repeating-timestamp-show-all)
  4425. diff (- d2 d1))
  4426. (setq pastschedp (and todayp (< diff 0)))
  4427. ;; When to show a scheduled item in the calendar:
  4428. ;; If it is on or past the date.
  4429. (when (or (and (< diff 0)
  4430. (< (abs diff) org-scheduled-past-days)
  4431. (and todayp (not org-agenda-only-exact-dates)))
  4432. (= diff 0))
  4433. (save-excursion
  4434. (setq todo-state (org-get-todo-state))
  4435. (setq donep (member todo-state org-done-keywords))
  4436. (setq habitp (and (functionp 'org-is-habit-p)
  4437. (org-is-habit-p)))
  4438. (if (and donep
  4439. (or habitp org-agenda-skip-scheduled-if-done
  4440. (not (= diff 0))))
  4441. (setq txt nil)
  4442. (setq category (org-get-category))
  4443. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4444. (setq txt org-agenda-no-heading-message)
  4445. (goto-char (match-end 0))
  4446. (setq pos1 (match-beginning 0))
  4447. (if habitp
  4448. (if (or (not org-habit-show-habits)
  4449. (and (not todayp)
  4450. org-habit-show-habits-only-for-today))
  4451. (throw :skip nil))
  4452. (if (and
  4453. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4454. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4455. pastschedp))
  4456. (setq mm (assoc pos1 deadline-position-alist)))
  4457. (throw :skip nil)))
  4458. (setq tags (org-get-tags-at))
  4459. (setq head (buffer-substring-no-properties
  4460. (point)
  4461. (progn (skip-chars-forward "^\r\n") (point))))
  4462. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4463. (setq timestr
  4464. (concat (substring s (match-beginning 1)) " "))
  4465. (setq timestr 'time))
  4466. (setq txt (org-format-agenda-item
  4467. (if (= diff 0)
  4468. (car org-agenda-scheduled-leaders)
  4469. (format (nth 1 org-agenda-scheduled-leaders)
  4470. (- 1 diff)))
  4471. head category tags
  4472. (if (not (= diff 0)) nil timestr)
  4473. nil nil habitp))))
  4474. (when txt
  4475. (setq face
  4476. (cond
  4477. ((and (not habitp) pastschedp)
  4478. 'org-scheduled-previously)
  4479. (todayp 'org-scheduled-today)
  4480. (t 'org-scheduled))
  4481. habitp (and habitp (org-habit-parse-todo)))
  4482. (org-add-props txt props
  4483. 'undone-face face
  4484. 'face (if donep 'org-agenda-done face)
  4485. 'org-marker (org-agenda-new-marker pos)
  4486. 'org-hd-marker (org-agenda-new-marker pos1)
  4487. 'type (if pastschedp "past-scheduled" "scheduled")
  4488. 'date (if pastschedp d2 date)
  4489. 'priority (if habitp
  4490. (org-habit-get-priority habitp)
  4491. (+ 94 (- 5 diff) (org-get-priority txt)))
  4492. 'org-category category
  4493. 'org-habit-p habitp
  4494. 'todo-state todo-state)
  4495. (push txt ee))))))
  4496. (nreverse ee)))
  4497. (defun org-agenda-get-blocks ()
  4498. "Return the date-range information for agenda display."
  4499. (let* ((props (list 'face nil
  4500. 'org-not-done-regexp org-not-done-regexp
  4501. 'org-todo-regexp org-todo-regexp
  4502. 'org-complex-heading-regexp org-complex-heading-regexp
  4503. 'mouse-face 'highlight
  4504. 'help-echo
  4505. (format "mouse-2 or RET jump to org file %s"
  4506. (abbreviate-file-name buffer-file-name))))
  4507. (regexp org-tr-regexp)
  4508. (d0 (calendar-absolute-from-gregorian date))
  4509. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4510. head donep)
  4511. (goto-char (point-min))
  4512. (while (re-search-forward regexp nil t)
  4513. (catch :skip
  4514. (org-agenda-skip)
  4515. (setq pos (point))
  4516. (setq timestr (match-string 0)
  4517. s1 (match-string 1)
  4518. s2 (match-string 2)
  4519. d1 (time-to-days (org-time-string-to-time s1))
  4520. d2 (time-to-days (org-time-string-to-time s2)))
  4521. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4522. ;; Only allow days between the limits, because the normal
  4523. ;; date stamps will catch the limits.
  4524. (save-excursion
  4525. (setq todo-state (org-get-todo-state))
  4526. (setq donep (member todo-state org-done-keywords))
  4527. (if (and donep org-agenda-skip-timestamp-if-done)
  4528. (throw :skip t))
  4529. (setq marker (org-agenda-new-marker (point)))
  4530. (setq category (org-get-category))
  4531. (if (not (re-search-backward "^\\*+ " nil t))
  4532. (setq txt org-agenda-no-heading-message)
  4533. (goto-char (match-beginning 0))
  4534. (setq hdmarker (org-agenda-new-marker (point)))
  4535. (setq tags (org-get-tags-at))
  4536. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4537. (setq head (match-string 1))
  4538. (let ((remove-re
  4539. (if org-agenda-remove-timeranges-from-blocks
  4540. (concat
  4541. "<" (regexp-quote s1) ".*?>"
  4542. "--"
  4543. "<" (regexp-quote s2) ".*?>")
  4544. nil)))
  4545. (setq txt (org-format-agenda-item
  4546. (format
  4547. (nth (if (= d1 d2) 0 1)
  4548. org-agenda-timerange-leaders)
  4549. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4550. head category tags
  4551. timestr nil remove-re))))
  4552. (org-add-props txt props
  4553. 'org-marker marker 'org-hd-marker hdmarker
  4554. 'type "block" 'date date
  4555. 'todo-state todo-state
  4556. 'priority (org-get-priority txt) 'org-category category)
  4557. (push txt ee)))
  4558. (goto-char pos)))
  4559. ;; Sort the entries by expiration date.
  4560. (nreverse ee)))
  4561. ;;; Agenda presentation and sorting
  4562. (defvar org-prefix-has-time nil
  4563. "A flag, set by `org-compile-prefix-format'.
  4564. The flag is set if the currently compiled format contains a `%t'.")
  4565. (defvar org-prefix-has-tag nil
  4566. "A flag, set by `org-compile-prefix-format'.
  4567. The flag is set if the currently compiled format contains a `%T'.")
  4568. (defvar org-prefix-has-effort nil
  4569. "A flag, set by `org-compile-prefix-format'.
  4570. The flag is set if the currently compiled format contains a `%e'.")
  4571. (defvar org-prefix-category-length nil
  4572. "Used by `org-compile-prefix-format' to remember the category field width.")
  4573. (defvar org-prefix-category-max-length nil
  4574. "Used by `org-compile-prefix-format' to remember the category field width.")
  4575. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4576. noprefix remove-re habitp)
  4577. "Format TXT to be inserted into the agenda buffer.
  4578. In particular, it adds the prefix and corresponding text properties. EXTRA
  4579. must be a string and replaces the `%s' specifier in the prefix format.
  4580. CATEGORY (string, symbol or nil) may be used to overrule the default
  4581. category taken from local variable or file name. It will replace the `%c'
  4582. specifier in the format. DOTIME, when non-nil, indicates that a
  4583. time-of-day should be extracted from TXT for sorting of this entry, and for
  4584. the `%t' specifier in the format. When DOTIME is a string, this string is
  4585. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4586. only the correctly processes TXT should be returned - this is used by
  4587. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4588. Any match of REMOVE-RE will be removed from TXT."
  4589. (save-match-data
  4590. ;; Diary entries sometimes have extra whitespace at the beginning
  4591. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4592. ;; Fix the tags part in txt
  4593. (setq txt (org-agenda-fix-displayed-tags
  4594. txt tags
  4595. org-agenda-show-inherited-tags
  4596. org-agenda-hide-tags-regexp))
  4597. (let* ((category (or category
  4598. org-category
  4599. (if buffer-file-name
  4600. (file-name-sans-extension
  4601. (file-name-nondirectory buffer-file-name))
  4602. "")))
  4603. ;; time, tag, effort are needed for the eval of the prefix format
  4604. (tag (if tags (nth (1- (length tags)) tags) ""))
  4605. time effort neffort
  4606. (ts (if dotime (concat
  4607. (if (stringp dotime) dotime "")
  4608. (and org-agenda-search-headline-for-time txt))))
  4609. (time-of-day (and dotime (org-get-time-of-day ts)))
  4610. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4611. duration thecategory)
  4612. (and (org-mode-p) buffer-file-name
  4613. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4614. (when (and dotime time-of-day)
  4615. ;; Extract starting and ending time and move them to prefix
  4616. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4617. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4618. (setq s0 (match-string 0 ts)
  4619. srp (and stamp (match-end 3))
  4620. s1 (match-string (if plain 1 2) ts)
  4621. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4622. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4623. ;; them, we might want to remove them there to avoid duplication.
  4624. ;; The user can turn this off with a variable.
  4625. (if (and org-prefix-has-time
  4626. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4627. (string-match (concat (regexp-quote s0) " *") txt)
  4628. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4629. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4630. (= (match-beginning 0) 0)
  4631. t))
  4632. (setq txt (replace-match "" nil nil txt))))
  4633. ;; Normalize the time(s) to 24 hour
  4634. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4635. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4636. ;; Compute the duration
  4637. (when s1
  4638. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4639. (string-to-number (substring s1 3)))
  4640. t2 (cond
  4641. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4642. (string-to-number (substring s2 3))))
  4643. (org-agenda-default-appointment-duration
  4644. (+ t1 org-agenda-default-appointment-duration))
  4645. (t nil)))
  4646. (setq duration (if t2 (- t2 t1)))))
  4647. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4648. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4649. (let ((m (+ (string-to-number (match-string 2 s1))
  4650. (* 60 (string-to-number (match-string 1 s1)))
  4651. org-agenda-default-appointment-duration))
  4652. h)
  4653. (setq h (/ m 60) m (- m (* h 60)))
  4654. (setq s2 (format "%02d:%02d" h m))))
  4655. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4656. txt)
  4657. ;; Tags are in the string
  4658. (if (or (eq org-agenda-remove-tags t)
  4659. (and org-agenda-remove-tags
  4660. org-prefix-has-tag))
  4661. (setq txt (replace-match "" t t txt))
  4662. (setq txt (replace-match
  4663. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4664. (match-string 2 txt))
  4665. t t txt))))
  4666. (when (org-mode-p)
  4667. (setq effort
  4668. (condition-case nil
  4669. (org-get-effort
  4670. (or (get-text-property 0 'org-hd-marker txt)
  4671. (get-text-property 0 'org-marker txt)))
  4672. (error nil)))
  4673. (when effort
  4674. (setq neffort (org-hh:mm-string-to-minutes effort)
  4675. effort (setq effort (concat "[" effort "]" )))))
  4676. (when remove-re
  4677. (while (string-match remove-re txt)
  4678. (setq txt (replace-match "" t t txt))))
  4679. ;; Create the final string
  4680. (if noprefix
  4681. (setq rtn txt)
  4682. ;; Prepare the variables needed in the eval of the compiled format
  4683. (setq time (cond (s2 (concat s1 "-" s2))
  4684. (s1 (concat s1 "......"))
  4685. (t ""))
  4686. extra (or (and (not habitp) extra) "")
  4687. category (if (symbolp category) (symbol-name category) category)
  4688. thecategory (copy-sequence category))
  4689. (if (string-match org-bracket-link-regexp category)
  4690. (progn
  4691. (setq l (if (match-end 3)
  4692. (- (match-end 3) (match-beginning 3))
  4693. (- (match-end 1) (match-beginning 1))))
  4694. (when (< l (or org-prefix-category-length 0))
  4695. (setq category (copy-sequence category))
  4696. (org-add-props category nil
  4697. 'extra-space (make-string
  4698. (- org-prefix-category-length l 1) ?\ ))))
  4699. (if (and org-prefix-category-max-length
  4700. (>= (length category) org-prefix-category-max-length))
  4701. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4702. ;; Evaluate the compiled format
  4703. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4704. ;; And finally add the text properties
  4705. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4706. (org-add-props rtn nil
  4707. 'org-category (if thecategory (downcase thecategory) category)
  4708. 'tags (mapcar 'org-downcase-keep-props tags)
  4709. 'org-highest-priority org-highest-priority
  4710. 'org-lowest-priority org-lowest-priority
  4711. 'prefix-length (- (length rtn) (length txt))
  4712. 'time-of-day time-of-day
  4713. 'duration duration
  4714. 'effort effort
  4715. 'effort-minutes neffort
  4716. 'txt txt
  4717. 'time time
  4718. 'extra extra
  4719. 'dotime dotime))))
  4720. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4721. "Remove tags string from TXT, and add a modified list of tags.
  4722. The modified list may contain inherited tags, and tags matched by
  4723. `org-agenda-hide-tags-regexp' will be removed."
  4724. (when (or add-inherited hide-re)
  4725. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4726. (setq txt (substring txt 0 (match-beginning 0))))
  4727. (setq tags
  4728. (delq nil
  4729. (mapcar (lambda (tg)
  4730. (if (or (and hide-re (string-match hide-re tg))
  4731. (and (not add-inherited)
  4732. (get-text-property 0 'inherited tg)))
  4733. nil
  4734. tg))
  4735. tags)))
  4736. (when tags
  4737. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4738. i)
  4739. (setq txt (concat txt " :"
  4740. (mapconcat
  4741. (lambda (x)
  4742. (setq i (get-text-property 0 'inherited x))
  4743. (if (and have-i (not i))
  4744. (progn
  4745. (setq have-i nil)
  4746. (concat ":" x))
  4747. x))
  4748. tags ":")
  4749. (if have-i "::" ":"))))))
  4750. txt)
  4751. (defun org-downcase-keep-props (s)
  4752. (let ((props (text-properties-at 0 s)))
  4753. (setq s (downcase s))
  4754. (add-text-properties 0 (length s) props s)
  4755. s))
  4756. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4757. (defvar org-agenda-sorting-strategy-selected nil)
  4758. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4759. (catch 'exit
  4760. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4761. ((and todayp (member 'today (car org-agenda-time-grid))))
  4762. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4763. ((member 'weekly (car org-agenda-time-grid)))
  4764. (t (throw 'exit list)))
  4765. (let* ((have (delq nil (mapcar
  4766. (lambda (x) (get-text-property 1 'time-of-day x))
  4767. list)))
  4768. (string (nth 1 org-agenda-time-grid))
  4769. (gridtimes (nth 2 org-agenda-time-grid))
  4770. (req (car org-agenda-time-grid))
  4771. (remove (member 'remove-match req))
  4772. new time)
  4773. (if (and (member 'require-timed req) (not have))
  4774. ;; don't show empty grid
  4775. (throw 'exit list))
  4776. (while (setq time (pop gridtimes))
  4777. (unless (and remove (member time have))
  4778. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  4779. (push (org-format-agenda-item
  4780. nil string "" nil
  4781. (concat (substring time 0 -2) ":" (substring time -2)))
  4782. new)
  4783. (put-text-property
  4784. 2 (length (car new)) 'face 'org-time-grid (car new))))
  4785. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4786. (append new list)
  4787. (append list new)))))
  4788. (defun org-compile-prefix-format (key)
  4789. "Compile the prefix format into a Lisp form that can be evaluated.
  4790. The resulting form is returned and stored in the variable
  4791. `org-prefix-format-compiled'."
  4792. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4793. org-prefix-category-length nil org-prefix-has-effort nil)
  4794. (let ((s (cond
  4795. ((stringp org-agenda-prefix-format)
  4796. org-agenda-prefix-format)
  4797. ((assq key org-agenda-prefix-format)
  4798. (cdr (assq key org-agenda-prefix-format)))
  4799. (t " %-12:c%?-12t% s")))
  4800. (start 0)
  4801. varform vars var e c f opt)
  4802. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4803. s start)
  4804. (setq var (cdr (assoc (match-string 4 s)
  4805. '(("c" . category) ("t" . time) ("s" . extra)
  4806. ("T" . tag) ("e" . effort))))
  4807. c (or (match-string 3 s) "")
  4808. opt (match-beginning 1)
  4809. start (1+ (match-beginning 0)))
  4810. (if (equal var 'time) (setq org-prefix-has-time t))
  4811. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4812. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4813. (setq f (concat "%" (match-string 2 s) "s"))
  4814. (when (equal var 'category)
  4815. (setq org-prefix-category-length
  4816. (floor (abs (string-to-number (match-string 2 s)))))
  4817. (setq org-prefix-category-max-length
  4818. (let ((x (match-string 2 s)))
  4819. (save-match-data
  4820. (if (string-match "\\.[0-9]+" x)
  4821. (string-to-number (substring (match-string 0 x) 1)))))))
  4822. (if opt
  4823. (setq varform
  4824. `(if (equal "" ,var)
  4825. ""
  4826. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4827. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4828. (setq s (replace-match "%s" t nil s))
  4829. (push varform vars))
  4830. (setq vars (nreverse vars))
  4831. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4832. (defun org-set-sorting-strategy (key)
  4833. (if (symbolp (car org-agenda-sorting-strategy))
  4834. ;; the old format
  4835. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4836. (setq org-agenda-sorting-strategy-selected
  4837. (or (cdr (assq key org-agenda-sorting-strategy))
  4838. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4839. '(time-up category-keep priority-down)))))
  4840. (defun org-get-time-of-day (s &optional string mod24)
  4841. "Check string S for a time of day.
  4842. If found, return it as a military time number between 0 and 2400.
  4843. If not found, return nil.
  4844. The optional STRING argument forces conversion into a 5 character wide string
  4845. HH:MM."
  4846. (save-match-data
  4847. (when
  4848. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4849. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4850. (let* ((h (string-to-number (match-string 1 s)))
  4851. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4852. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4853. (am-p (equal ampm "am"))
  4854. (h1 (cond ((not ampm) h)
  4855. ((= h 12) (if am-p 0 12))
  4856. (t (+ h (if am-p 0 12)))))
  4857. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4858. (mod h1 24) h1))
  4859. (t0 (+ (* 100 h2) m))
  4860. (t1 (concat (if (>= h1 24) "+" " ")
  4861. (if (and org-agenda-time-leading-zero
  4862. (< t0 1000)) "0" "")
  4863. (if (< t0 100) "0" "")
  4864. (if (< t0 10) "0" "")
  4865. (int-to-string t0))))
  4866. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4867. (defvar org-agenda-before-sorting-filter-function nil
  4868. "Function to be applied to agenda items prior to sorting.
  4869. Prior to sorting also means just before they are inserted into the agenda.
  4870. To aid sorting, you may revisit the original entries and add more text
  4871. properties which will later be used by the sorting functions.
  4872. The function should take a string argument, an agenda line.
  4873. It has access to the text properties in that line, which contain among
  4874. other things, the property `org-hd-marker' that points to the entry
  4875. where the line comes from. Note that not all lines going into the agenda
  4876. have this property, only most.
  4877. The function should return the modified string. It is probably best
  4878. to ONLY change text properties.
  4879. You can also use this function as a filter, by returning nil for lines
  4880. you don't want to have in the agenda at all. For this application, you
  4881. could bind the variable in the options section of a custom command.")
  4882. (defun org-finalize-agenda-entries (list &optional nosort)
  4883. "Sort and concatenate the agenda items."
  4884. (setq list (mapcar 'org-agenda-highlight-todo list))
  4885. (if nosort
  4886. list
  4887. (when org-agenda-before-sorting-filter-function
  4888. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  4889. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4890. (defun org-agenda-highlight-todo (x)
  4891. (let ((org-done-keywords org-done-keywords-for-agenda)
  4892. (case-fold-search nil)
  4893. re pl)
  4894. (if (eq x 'line)
  4895. (save-excursion
  4896. (beginning-of-line 1)
  4897. (setq re (org-get-at-bol 'org-todo-regexp))
  4898. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4899. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4900. (add-text-properties (match-beginning 0) (match-end 1)
  4901. (list 'face (org-get-todo-face 1)))
  4902. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4903. (delete-region (match-beginning 1) (1- (match-end 0)))
  4904. (goto-char (match-beginning 1))
  4905. (insert (format org-agenda-todo-keyword-format s)))))
  4906. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4907. pl (get-text-property 0 'prefix-length x))
  4908. (when (and re
  4909. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4910. x (or pl 0)) pl))
  4911. (add-text-properties
  4912. (or (match-end 1) (match-end 0)) (match-end 0)
  4913. (list 'face (org-get-todo-face (match-string 2 x)))
  4914. x)
  4915. (when (match-end 1)
  4916. (setq x (concat (substring x 0 (match-end 1))
  4917. (format org-agenda-todo-keyword-format
  4918. (match-string 2 x))
  4919. (org-add-props " " (text-properties-at 0 x))
  4920. (substring x (match-end 3))))))
  4921. x)))
  4922. (defsubst org-cmp-priority (a b)
  4923. "Compare the priorities of string A and B."
  4924. (let ((pa (or (get-text-property 1 'priority a) 0))
  4925. (pb (or (get-text-property 1 'priority b) 0)))
  4926. (cond ((> pa pb) +1)
  4927. ((< pa pb) -1)
  4928. (t nil))))
  4929. (defsubst org-cmp-effort (a b)
  4930. "Compare the priorities of string A and B."
  4931. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4932. (ea (or (get-text-property 1 'effort-minutes a) def))
  4933. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4934. (cond ((> ea eb) +1)
  4935. ((< ea eb) -1)
  4936. (t nil))))
  4937. (defsubst org-cmp-category (a b)
  4938. "Compare the string values of categories of strings A and B."
  4939. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4940. (cb (or (get-text-property 1 'org-category b) "")))
  4941. (cond ((string-lessp ca cb) -1)
  4942. ((string-lessp cb ca) +1)
  4943. (t nil))))
  4944. (defsubst org-cmp-todo-state (a b)
  4945. "Compare the todo states of strings A and B."
  4946. (let* ((ma (or (get-text-property 1 'org-marker a)
  4947. (get-text-property 1 'org-hd-marker a)))
  4948. (mb (or (get-text-property 1 'org-marker b)
  4949. (get-text-property 1 'org-hd-marker b)))
  4950. (fa (and ma (marker-buffer ma)))
  4951. (fb (and mb (marker-buffer mb)))
  4952. (todo-kwds
  4953. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4954. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4955. (ta (or (get-text-property 1 'todo-state a) ""))
  4956. (tb (or (get-text-property 1 'todo-state b) ""))
  4957. (la (- (length (member ta todo-kwds))))
  4958. (lb (- (length (member tb todo-kwds))))
  4959. (donepa (member ta org-done-keywords-for-agenda))
  4960. (donepb (member tb org-done-keywords-for-agenda)))
  4961. (cond ((and donepa (not donepb)) -1)
  4962. ((and (not donepa) donepb) +1)
  4963. ((< la lb) -1)
  4964. ((< lb la) +1)
  4965. (t nil))))
  4966. (defsubst org-cmp-alpha (a b)
  4967. "Compare the headlines, alphabetically."
  4968. (let* ((pla (get-text-property 0 'prefix-length a))
  4969. (plb (get-text-property 0 'prefix-length b))
  4970. (ta (and pla (substring a pla)))
  4971. (tb (and plb (substring b plb))))
  4972. (when pla
  4973. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  4974. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  4975. (setq ta (substring ta (match-end 0))))
  4976. (setq ta (downcase ta)))
  4977. (when plb
  4978. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  4979. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  4980. (setq tb (substring tb (match-end 0))))
  4981. (setq tb (downcase tb)))
  4982. (cond ((not ta) +1)
  4983. ((not tb) -1)
  4984. ((string-lessp ta tb) -1)
  4985. ((string-lessp tb ta) +1)
  4986. (t nil))))
  4987. (defsubst org-cmp-tag (a b)
  4988. "Compare the string values of the first tags of A and B."
  4989. (let ((ta (car (last (get-text-property 1 'tags a))))
  4990. (tb (car (last (get-text-property 1 'tags b)))))
  4991. (cond ((not ta) +1)
  4992. ((not tb) -1)
  4993. ((string-lessp ta tb) -1)
  4994. ((string-lessp tb ta) +1)
  4995. (t nil))))
  4996. (defsubst org-cmp-time (a b)
  4997. "Compare the time-of-day values of strings A and B."
  4998. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4999. (ta (or (get-text-property 1 'time-of-day a) def))
  5000. (tb (or (get-text-property 1 'time-of-day b) def)))
  5001. (cond ((< ta tb) -1)
  5002. ((< tb ta) +1)
  5003. (t nil))))
  5004. (defsubst org-cmp-habit-p (a b)
  5005. "Compare the todo states of strings A and B."
  5006. (let ((ha (get-text-property 1 'org-habit-p a))
  5007. (hb (get-text-property 1 'org-habit-p b)))
  5008. (cond ((and ha (not hb)) -1)
  5009. ((and (not ha) hb) +1)
  5010. (t nil))))
  5011. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5012. (defun org-entries-lessp (a b)
  5013. "Predicate for sorting agenda entries."
  5014. ;; The following variables will be used when the form is evaluated.
  5015. ;; So even though the compiler complains, keep them.
  5016. (let* ((ss org-agenda-sorting-strategy-selected)
  5017. (time-up (and (org-em 'time-up 'time-down ss)
  5018. (org-cmp-time a b)))
  5019. (time-down (if time-up (- time-up) nil))
  5020. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5021. (org-cmp-priority a b)))
  5022. (priority-down (if priority-up (- priority-up) nil))
  5023. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5024. (org-cmp-effort a b)))
  5025. (effort-down (if effort-up (- effort-up) nil))
  5026. (category-up (and (or (org-em 'category-up 'category-down ss)
  5027. (memq 'category-keep ss))
  5028. (org-cmp-category a b)))
  5029. (category-down (if category-up (- category-up) nil))
  5030. (category-keep (if category-up +1 nil))
  5031. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5032. (org-cmp-tag a b)))
  5033. (tag-down (if tag-up (- tag-up) nil))
  5034. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5035. (org-cmp-todo-state a b)))
  5036. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5037. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5038. (org-cmp-habit-p a b)))
  5039. (habit-down (if habit-up (- habit-up) nil))
  5040. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5041. (org-cmp-alpha a b)))
  5042. (alpha-down (if alpha-up (- alpha-up) nil))
  5043. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5044. user-defined-up user-defined-down)
  5045. (if (and need-user-cmp org-agenda-cmp-user-defined
  5046. (functionp org-agenda-cmp-user-defined))
  5047. (setq user-defined-up
  5048. (funcall org-agenda-cmp-user-defined a b)
  5049. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5050. (cdr (assoc
  5051. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5052. '((-1 . t) (1 . nil) (nil . nil))))))
  5053. ;;; Agenda restriction lock
  5054. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5055. "Overlay to mark the headline to which agenda commands are restricted.")
  5056. (overlay-put org-agenda-restriction-lock-overlay
  5057. 'face 'org-agenda-restriction-lock)
  5058. (overlay-put org-agenda-restriction-lock-overlay
  5059. 'help-echo "Agendas are currently limited to this subtree.")
  5060. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5061. (defun org-agenda-set-restriction-lock (&optional type)
  5062. "Set restriction lock for agenda, to current subtree or file.
  5063. Restriction will be the file if TYPE is `file', or if type is the
  5064. universal prefix '(4), or if the cursor is before the first headline
  5065. in the file. Otherwise, restriction will be to the current subtree."
  5066. (interactive "P")
  5067. (and (equal type '(4)) (setq type 'file))
  5068. (setq type (cond
  5069. (type type)
  5070. ((org-at-heading-p) 'subtree)
  5071. ((condition-case nil (org-back-to-heading t) (error nil))
  5072. 'subtree)
  5073. (t 'file)))
  5074. (if (eq type 'subtree)
  5075. (progn
  5076. (setq org-agenda-restrict t)
  5077. (setq org-agenda-overriding-restriction 'subtree)
  5078. (put 'org-agenda-files 'org-restrict
  5079. (list (buffer-file-name (buffer-base-buffer))))
  5080. (org-back-to-heading t)
  5081. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5082. (move-marker org-agenda-restrict-begin (point))
  5083. (move-marker org-agenda-restrict-end
  5084. (save-excursion (org-end-of-subtree t)))
  5085. (message "Locking agenda restriction to subtree"))
  5086. (put 'org-agenda-files 'org-restrict
  5087. (list (buffer-file-name (buffer-base-buffer))))
  5088. (setq org-agenda-restrict nil)
  5089. (setq org-agenda-overriding-restriction 'file)
  5090. (move-marker org-agenda-restrict-begin nil)
  5091. (move-marker org-agenda-restrict-end nil)
  5092. (message "Locking agenda restriction to file"))
  5093. (setq current-prefix-arg nil)
  5094. (org-agenda-maybe-redo))
  5095. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5096. "Remove the agenda restriction lock."
  5097. (interactive "P")
  5098. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5099. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5100. (setq org-agenda-overriding-restriction nil)
  5101. (setq org-agenda-restrict nil)
  5102. (put 'org-agenda-files 'org-restrict nil)
  5103. (move-marker org-agenda-restrict-begin nil)
  5104. (move-marker org-agenda-restrict-end nil)
  5105. (setq current-prefix-arg nil)
  5106. (message "Agenda restriction lock removed")
  5107. (or noupdate (org-agenda-maybe-redo)))
  5108. (defun org-agenda-maybe-redo ()
  5109. "If there is any window showing the agenda view, update it."
  5110. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5111. (w0 (selected-window)))
  5112. (when w
  5113. (select-window w)
  5114. (org-agenda-redo)
  5115. (select-window w0)
  5116. (if org-agenda-overriding-restriction
  5117. (message "Agenda view shifted to new %s restriction"
  5118. org-agenda-overriding-restriction)
  5119. (message "Agenda restriction lock removed")))))
  5120. ;;; Agenda commands
  5121. (defun org-agenda-check-type (error &rest types)
  5122. "Check if agenda buffer is of allowed type.
  5123. If ERROR is non-nil, throw an error, otherwise just return nil."
  5124. (if (memq org-agenda-type types)
  5125. t
  5126. (if error
  5127. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5128. nil)))
  5129. (defun org-agenda-quit ()
  5130. "Exit agenda by removing the window or the buffer."
  5131. (interactive)
  5132. (if org-agenda-columns-active
  5133. (org-columns-quit)
  5134. (let ((buf (current-buffer)))
  5135. (if (eq org-agenda-window-setup 'other-frame)
  5136. (progn
  5137. (kill-buffer buf)
  5138. (org-agenda-reset-markers)
  5139. (org-columns-remove-overlays)
  5140. (setq org-agenda-archives-mode nil)
  5141. (delete-frame))
  5142. (and (not (eq org-agenda-window-setup 'current-window))
  5143. (not (one-window-p))
  5144. (delete-window))
  5145. (kill-buffer buf)
  5146. (org-agenda-reset-markers)
  5147. (org-columns-remove-overlays)
  5148. (setq org-agenda-archives-mode nil)))
  5149. ;; Maybe restore the pre-agenda window configuration.
  5150. (and org-agenda-restore-windows-after-quit
  5151. (not (eq org-agenda-window-setup 'other-frame))
  5152. org-pre-agenda-window-conf
  5153. (set-window-configuration org-pre-agenda-window-conf))))
  5154. (defun org-agenda-exit ()
  5155. "Exit agenda by removing the window or the buffer.
  5156. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5157. Org-mode buffers visited directly by the user will not be touched."
  5158. (interactive)
  5159. (org-release-buffers org-agenda-new-buffers)
  5160. (setq org-agenda-new-buffers nil)
  5161. (org-agenda-quit))
  5162. (defun org-agenda-execute (arg)
  5163. "Execute another agenda command, keeping same window.
  5164. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5165. in the agenda."
  5166. (interactive "P")
  5167. (let ((org-agenda-window-setup 'current-window))
  5168. (org-agenda arg)))
  5169. (defun org-agenda-redo ()
  5170. "Rebuild Agenda.
  5171. When this is the global TODO list, a prefix argument will be interpreted."
  5172. (interactive)
  5173. (let* ((org-agenda-keep-modes t)
  5174. (filter org-agenda-filter)
  5175. (preset (get 'org-agenda-filter :preset-filter))
  5176. (cols org-agenda-columns-active)
  5177. (line (org-current-line))
  5178. (window-line (- line (org-current-line (window-start))))
  5179. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5180. (put 'org-agenda-filter :preset-filter nil)
  5181. (and cols (org-columns-quit))
  5182. (message "Rebuilding agenda buffer...")
  5183. (org-let lprops '(eval org-agenda-redo-command))
  5184. (setq org-agenda-undo-list nil
  5185. org-agenda-pending-undo-list nil)
  5186. (message "Rebuilding agenda buffer...done")
  5187. (put 'org-agenda-filter :preset-filter preset)
  5188. (and (or filter preset) (org-agenda-filter-apply filter))
  5189. (and cols (interactive-p) (org-agenda-columns))
  5190. (org-goto-line line)
  5191. (recenter window-line)))
  5192. (defvar org-global-tags-completion-table nil)
  5193. (defvar org-agenda-filter-form nil)
  5194. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5195. "Keep only those lines in the agenda buffer that have a specific tag.
  5196. The tag is selected with its fast selection letter, as configured.
  5197. With prefix argument STRIP, remove all lines that do have the tag.
  5198. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5199. used to narrow the search - the interactive user can also press `-' or `+'
  5200. to switch to narrowing."
  5201. (interactive "P")
  5202. (let* ((alist org-tag-alist-for-agenda)
  5203. (tag-chars (mapconcat
  5204. (lambda (x) (if (and (not (symbolp (car x)))
  5205. (cdr x))
  5206. (char-to-string (cdr x))
  5207. ""))
  5208. alist ""))
  5209. (efforts (org-split-string
  5210. (or (cdr (assoc (concat org-effort-property "_ALL")
  5211. org-global-properties))
  5212. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5213. (effort-op org-agenda-filter-effort-default-operator)
  5214. (effort-prompt "")
  5215. (inhibit-read-only t)
  5216. (current org-agenda-filter)
  5217. a n tag)
  5218. (unless char
  5219. (message
  5220. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5221. (if narrow "Narrow" "Filter") tag-chars
  5222. (if org-agenda-auto-exclude-function "[RET], " ""))
  5223. (setq char (read-char)))
  5224. (when (member char '(?+ ?-))
  5225. ;; Narrowing down
  5226. (cond ((equal char ?-) (setq strip t narrow t))
  5227. ((equal char ?+) (setq strip nil narrow t)))
  5228. (message
  5229. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5230. (setq char (read-char)))
  5231. (when (member char '(?< ?> ?= ??))
  5232. ;; An effort operator
  5233. (setq effort-op (char-to-string char))
  5234. (setq alist nil) ; to make sure it will be interpreted as effort.
  5235. (unless (equal char ??)
  5236. (loop for i from 0 to 9 do
  5237. (setq effort-prompt
  5238. (concat
  5239. effort-prompt " ["
  5240. (if (= i 9) "0" (int-to-string (1+ i)))
  5241. "]" (nth i efforts))))
  5242. (message "Effort%s: %s " effort-op effort-prompt)
  5243. (setq char (read-char))
  5244. (when (or (< char ?0) (> char ?9))
  5245. (error "Need 1-9,0 to select effort" ))))
  5246. (when (equal char ?\t)
  5247. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5248. (org-set-local 'org-global-tags-completion-table
  5249. (org-global-tags-completion-table)))
  5250. (let ((completion-ignore-case t))
  5251. (setq tag (org-icompleting-read
  5252. "Tag: " org-global-tags-completion-table))))
  5253. (cond
  5254. ((equal char ?\r)
  5255. (org-agenda-filter-by-tag-show-all)
  5256. (when org-agenda-auto-exclude-function
  5257. (setq org-agenda-filter '())
  5258. (dolist (tag (org-agenda-get-represented-tags))
  5259. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5260. (if modifier
  5261. (push modifier org-agenda-filter))))
  5262. (if (not (null org-agenda-filter))
  5263. (org-agenda-filter-apply org-agenda-filter))))
  5264. ((equal char ?/)
  5265. (org-agenda-filter-by-tag-show-all)
  5266. (when (get 'org-agenda-filter :preset-filter)
  5267. (org-agenda-filter-apply org-agenda-filter)))
  5268. ((or (equal char ?\ )
  5269. (setq a (rassoc char alist))
  5270. (and (>= char ?0) (<= char ?9)
  5271. (setq n (if (= char ?0) 9 (- char ?0 1))
  5272. tag (concat effort-op (nth n efforts))
  5273. a (cons tag nil)))
  5274. (and (= char ??)
  5275. (setq tag "?eff")
  5276. a (cons tag nil))
  5277. (and tag (setq a (cons tag nil))))
  5278. (org-agenda-filter-by-tag-show-all)
  5279. (setq tag (car a))
  5280. (setq org-agenda-filter
  5281. (cons (concat (if strip "-" "+") tag)
  5282. (if narrow current nil)))
  5283. (org-agenda-filter-apply org-agenda-filter))
  5284. (t (error "Invalid tag selection character %c" char)))))
  5285. (defun org-agenda-get-represented-tags ()
  5286. "Get a list of all tags currently represented in the agenda."
  5287. (let (p tags)
  5288. (save-excursion
  5289. (goto-char (point-min))
  5290. (while (setq p (next-single-property-change (point) 'tags))
  5291. (goto-char p)
  5292. (mapc (lambda (x) (add-to-list 'tags x))
  5293. (get-text-property (point) 'tags))))
  5294. tags))
  5295. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5296. "Refine the current filter. See `org-agenda-filter-by-tag."
  5297. (interactive "P")
  5298. (org-agenda-filter-by-tag strip char 'refine))
  5299. (defun org-agenda-filter-make-matcher ()
  5300. "Create the form that tests a line for the agenda filter."
  5301. (let (f f1)
  5302. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5303. org-agenda-filter))
  5304. (if (member x '("-" "+"))
  5305. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5306. (if (string-match "[<=>?]" x)
  5307. (setq f1 (org-agenda-filter-effort-form x))
  5308. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5309. (if (equal (string-to-char x) ?-)
  5310. (setq f1 (list 'not f1))))
  5311. (push f1 f))
  5312. (cons 'and (nreverse f))))
  5313. (defun org-agenda-filter-effort-form (e)
  5314. "Return the form to compare the effort of the current line with what E says.
  5315. E looks like \"+<2:25\"."
  5316. (let (op)
  5317. (setq e (substring e 1))
  5318. (setq op (string-to-char e) e (substring e 1))
  5319. (setq op (cond ((equal op ?<) '<=)
  5320. ((equal op ?>) '>=)
  5321. ((equal op ??) op)
  5322. (t '=)))
  5323. (list 'org-agenda-compare-effort (list 'quote op)
  5324. (org-hh:mm-string-to-minutes e))))
  5325. (defun org-agenda-compare-effort (op value)
  5326. "Compare the effort of the current line with VALUE, using OP.
  5327. If the line does not have an effort defined, return nil."
  5328. (let ((eff (org-get-at-bol 'effort-minutes)))
  5329. (if (equal op ??)
  5330. (not eff)
  5331. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5332. value))))
  5333. (defun org-agenda-filter-apply (filter)
  5334. "Set FILTER as the new agenda filter and apply it."
  5335. (let (tags)
  5336. (setq org-agenda-filter filter
  5337. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5338. (org-agenda-set-mode-name)
  5339. (save-excursion
  5340. (goto-char (point-min))
  5341. (while (not (eobp))
  5342. (if (org-get-at-bol 'org-marker)
  5343. (progn
  5344. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5345. (if (not (eval org-agenda-filter-form))
  5346. (org-agenda-filter-by-tag-hide-line))
  5347. (beginning-of-line 2))
  5348. (beginning-of-line 2))))
  5349. (if (get-char-property (point) 'invisible)
  5350. (org-agenda-previous-line))))
  5351. (defun org-agenda-filter-by-tag-hide-line ()
  5352. (let (ov)
  5353. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5354. (point-at-eol)))
  5355. (overlay-put ov 'invisible t)
  5356. (overlay-put ov 'type 'tags-filter)
  5357. (push ov org-agenda-filter-overlays)))
  5358. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5359. (setq pos (or pos (point)))
  5360. (save-excursion
  5361. (dolist (ov (overlays-at pos))
  5362. (when (and (overlay-get ov 'invisible)
  5363. (eq (overlay-get ov 'type) 'tags-filter))
  5364. (goto-char pos)
  5365. (if (< (overlay-start ov) (point-at-eol))
  5366. (move-overlay ov (point-at-eol)
  5367. (overlay-end ov)))))))
  5368. (defun org-agenda-filter-by-tag-show-all ()
  5369. (mapc 'delete-overlay org-agenda-filter-overlays)
  5370. (setq org-agenda-filter-overlays nil)
  5371. (setq org-agenda-filter nil)
  5372. (setq org-agenda-filter-form nil)
  5373. (org-agenda-set-mode-name))
  5374. (defun org-agenda-manipulate-query-add ()
  5375. "Manipulate the query by adding a search term with positive selection.
  5376. Positive selection means the term must be matched for selection of an entry."
  5377. (interactive)
  5378. (org-agenda-manipulate-query ?\[))
  5379. (defun org-agenda-manipulate-query-subtract ()
  5380. "Manipulate the query by adding a search term with negative selection.
  5381. Negative selection means term must not be matched for selection of an entry."
  5382. (interactive)
  5383. (org-agenda-manipulate-query ?\]))
  5384. (defun org-agenda-manipulate-query-add-re ()
  5385. "Manipulate the query by adding a search regexp with positive selection.
  5386. Positive selection means the regexp must match for selection of an entry."
  5387. (interactive)
  5388. (org-agenda-manipulate-query ?\{))
  5389. (defun org-agenda-manipulate-query-subtract-re ()
  5390. "Manipulate the query by adding a search regexp with negative selection.
  5391. Negative selection means regexp must not match for selection of an entry."
  5392. (interactive)
  5393. (org-agenda-manipulate-query ?\}))
  5394. (defun org-agenda-manipulate-query (char)
  5395. (cond
  5396. ((memq org-agenda-type '(timeline agenda))
  5397. (let ((org-agenda-include-inactive-timestamps t))
  5398. (org-agenda-redo))
  5399. (message "Display now includes inactive timestamps as well"))
  5400. ((eq org-agenda-type 'search)
  5401. (org-add-to-string
  5402. 'org-agenda-query-string
  5403. (if org-agenda-last-search-view-search-was-boolean
  5404. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5405. (?\{ . " +{}") (?\} . " -{}"))))
  5406. " "))
  5407. (setq org-agenda-redo-command
  5408. (list 'org-search-view
  5409. org-todo-only
  5410. org-agenda-query-string
  5411. (+ (length org-agenda-query-string)
  5412. (if (member char '(?\{ ?\})) 0 1))))
  5413. (set-register org-agenda-query-register org-agenda-query-string)
  5414. (org-agenda-redo))
  5415. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5416. org-agenda-type))))
  5417. (defun org-add-to-string (var string)
  5418. (set var (concat (symbol-value var) string)))
  5419. (defun org-agenda-goto-date (date)
  5420. "Jump to DATE in agenda."
  5421. (interactive (list (let ((org-read-date-prefer-future
  5422. (eval org-agenda-jump-prefer-future)))
  5423. (org-read-date))))
  5424. (org-agenda-list nil date))
  5425. (defun org-agenda-goto-today ()
  5426. "Go to today."
  5427. (interactive)
  5428. (org-agenda-check-type t 'timeline 'agenda)
  5429. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5430. (cond
  5431. (tdpos (goto-char tdpos))
  5432. ((eq org-agenda-type 'agenda)
  5433. (let* ((sd (time-to-days
  5434. (time-subtract (current-time)
  5435. (list 0 (* 3600 org-extend-today-until) 0))))
  5436. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5437. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5438. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5439. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5440. (org-agenda-redo)
  5441. (org-agenda-find-same-or-today-or-agenda)))
  5442. (t (error "Cannot find today")))))
  5443. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5444. (goto-char
  5445. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5446. (text-property-any (point-min) (point-max) 'org-today t)
  5447. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5448. (point-min))))
  5449. (defun org-agenda-later (arg)
  5450. "Go forward in time by thee current span.
  5451. With prefix ARG, go forward that many times the current span."
  5452. (interactive "p")
  5453. (org-agenda-check-type t 'agenda)
  5454. (let* ((span org-agenda-span)
  5455. (sd org-starting-day)
  5456. (greg (calendar-gregorian-from-absolute sd))
  5457. (cnt (org-get-at-bol 'org-day-cnt))
  5458. greg2 nd)
  5459. (cond
  5460. ((eq span 'day)
  5461. (setq sd (+ arg sd) nd 1))
  5462. ((eq span 'week)
  5463. (setq sd (+ (* 7 arg) sd) nd 7))
  5464. ((eq span 'month)
  5465. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5466. sd (calendar-absolute-from-gregorian greg2))
  5467. (setcar greg2 (1+ (car greg2)))
  5468. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5469. ((eq span 'year)
  5470. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5471. sd (calendar-absolute-from-gregorian greg2))
  5472. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5473. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5474. (let ((org-agenda-overriding-arguments
  5475. (list (car org-agenda-last-arguments) sd nd t)))
  5476. (org-agenda-redo)
  5477. (org-agenda-find-same-or-today-or-agenda cnt))))
  5478. (defun org-agenda-earlier (arg)
  5479. "Go backward in time by the current span.
  5480. With prefix ARG, go backward that many times the current span."
  5481. (interactive "p")
  5482. (org-agenda-later (- arg)))
  5483. (defun org-agenda-view-mode-dispatch ()
  5484. "Call one of the view mode commands."
  5485. (interactive)
  5486. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5487. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5488. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5489. (let ((a (read-char-exclusive)))
  5490. (case a
  5491. (?d (call-interactively 'org-agenda-day-view))
  5492. (?w (call-interactively 'org-agenda-week-view))
  5493. (?m (call-interactively 'org-agenda-month-view))
  5494. (?y (call-interactively 'org-agenda-year-view))
  5495. (?l (call-interactively 'org-agenda-log-mode))
  5496. (?L (org-agenda-log-mode '(4)))
  5497. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5498. (?a (call-interactively 'org-agenda-archives-mode))
  5499. (?A (org-agenda-archives-mode 'files))
  5500. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5501. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5502. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5503. (?D (call-interactively 'org-agenda-toggle-diary))
  5504. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5505. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5506. (org-agenda-check-type t 'timeline 'agenda)
  5507. (org-agenda-redo))
  5508. (message "Display now includes inactive timestamps as well"))
  5509. (?q (message "Abort"))
  5510. (otherwise (error "Invalid key" )))))
  5511. (defun org-agenda-day-view (&optional day-of-year)
  5512. "Switch to daily view for agenda.
  5513. With argument DAY-OF-YEAR, switch to that day of the year."
  5514. (interactive "P")
  5515. (setq org-agenda-ndays 1)
  5516. (org-agenda-change-time-span 'day day-of-year))
  5517. (defun org-agenda-week-view (&optional iso-week)
  5518. "Switch to daily view for agenda.
  5519. With argument ISO-WEEK, switch to the corresponding ISO week.
  5520. If ISO-WEEK has more then 2 digits, only the last two encode the
  5521. week. Any digits before this encode a year. So 200712 means
  5522. week 12 of year 2007. Years in the range 1938-2037 can also be
  5523. written as 2-digit years."
  5524. (interactive "P")
  5525. (setq org-agenda-ndays 7)
  5526. (org-agenda-change-time-span 'week iso-week))
  5527. (defun org-agenda-month-view (&optional month)
  5528. "Switch to monthly view for agenda.
  5529. With argument MONTH, switch to that month."
  5530. (interactive "P")
  5531. (org-agenda-change-time-span 'month month))
  5532. (defun org-agenda-year-view (&optional year)
  5533. "Switch to yearly view for agenda.
  5534. With argument YEAR, switch to that year.
  5535. If MONTH has more then 2 digits, only the last two encode the
  5536. month. Any digits before this encode a year. So 200712 means
  5537. December year 2007. Years in the range 1938-2037 can also be
  5538. written as 2-digit years."
  5539. (interactive "P")
  5540. (when year
  5541. (setq year (org-small-year-to-year year)))
  5542. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5543. (org-agenda-change-time-span 'year year)
  5544. (error "Abort")))
  5545. (defun org-agenda-change-time-span (span &optional n)
  5546. "Change the agenda view to SPAN.
  5547. SPAN may be `day', `week', `month', `year'."
  5548. (org-agenda-check-type t 'agenda)
  5549. (if (and (not n) (equal org-agenda-span span))
  5550. (error "Viewing span is already \"%s\"" span))
  5551. (let* ((sd (or (org-get-at-bol 'day)
  5552. org-starting-day))
  5553. (computed (org-agenda-compute-time-span sd span n))
  5554. (org-agenda-overriding-arguments
  5555. (list (car org-agenda-last-arguments)
  5556. (car computed) (cdr computed) t)))
  5557. (org-agenda-redo)
  5558. (org-agenda-find-same-or-today-or-agenda))
  5559. (org-agenda-set-mode-name)
  5560. (message "Switched to %s view" span))
  5561. (defun org-agenda-compute-time-span (sd span &optional n)
  5562. "Compute starting date and number of days for agenda.
  5563. SPAN may be `day', `week', `month', `year'. The return value
  5564. is a cons cell with the starting date and the number of days,
  5565. so that the date SD will be in that range."
  5566. (let* ((greg (calendar-gregorian-from-absolute sd))
  5567. (dg (nth 1 greg))
  5568. (mg (car greg))
  5569. (yg (nth 2 greg))
  5570. nd w1 y1 m1 thisweek)
  5571. (cond
  5572. ((eq span 'day)
  5573. (when n
  5574. (setq sd (+ (calendar-absolute-from-gregorian
  5575. (list mg 1 yg))
  5576. n -1)))
  5577. (setq nd 1))
  5578. ((eq span 'week)
  5579. (let* ((nt (calendar-day-of-week
  5580. (calendar-gregorian-from-absolute sd)))
  5581. (d (if org-agenda-start-on-weekday
  5582. (- nt org-agenda-start-on-weekday)
  5583. 0)))
  5584. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5585. (when n
  5586. (require 'cal-iso)
  5587. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5588. (when (> n 99)
  5589. (setq y1 (org-small-year-to-year (/ n 100))
  5590. n (mod n 100)))
  5591. (setq sd
  5592. (calendar-absolute-from-iso
  5593. (list n 1
  5594. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5595. (setq nd 7)))
  5596. ((eq span 'month)
  5597. (when (and n (> n 99))
  5598. (setq y1 (org-small-year-to-year (/ n 100))
  5599. n (mod n 100)))
  5600. (setq sd (calendar-absolute-from-gregorian
  5601. (list (or n mg) 1 (or y1 yg)))
  5602. nd (- (calendar-absolute-from-gregorian
  5603. (list (1+ (or n mg)) 1 (or y1 yg)))
  5604. sd)))
  5605. ((eq span 'year)
  5606. (setq sd (calendar-absolute-from-gregorian
  5607. (list 1 1 (or n yg)))
  5608. nd (- (calendar-absolute-from-gregorian
  5609. (list 1 1 (1+ (or n yg))))
  5610. sd))))
  5611. (cons sd nd)))
  5612. (defun org-agenda-next-date-line (&optional arg)
  5613. "Jump to the next line indicating a date in agenda buffer."
  5614. (interactive "p")
  5615. (org-agenda-check-type t 'agenda 'timeline)
  5616. (beginning-of-line 1)
  5617. ;; This does not work if user makes date format that starts with a blank
  5618. (if (looking-at "^\\S-") (forward-char 1))
  5619. (if (not (re-search-forward "^\\S-" nil t arg))
  5620. (progn
  5621. (backward-char 1)
  5622. (error "No next date after this line in this buffer")))
  5623. (goto-char (match-beginning 0)))
  5624. (defun org-agenda-previous-date-line (&optional arg)
  5625. "Jump to the previous line indicating a date in agenda buffer."
  5626. (interactive "p")
  5627. (org-agenda-check-type t 'agenda 'timeline)
  5628. (beginning-of-line 1)
  5629. (if (not (re-search-backward "^\\S-" nil t arg))
  5630. (error "No previous date before this line in this buffer")))
  5631. ;; Initialize the highlight
  5632. (defvar org-hl (make-overlay 1 1))
  5633. (overlay-put org-hl 'face 'highlight)
  5634. (defun org-highlight (begin end &optional buffer)
  5635. "Highlight a region with overlay."
  5636. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5637. (defun org-unhighlight ()
  5638. "Detach overlay INDEX."
  5639. (org-detach-overlay org-hl))
  5640. ;; FIXME this is currently not used.
  5641. (defun org-highlight-until-next-command (beg end &optional buffer)
  5642. "Move the highlight overlay to BEG/END, remove it before the next command."
  5643. (org-highlight beg end buffer)
  5644. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5645. (defun org-unhighlight-once ()
  5646. "Remove the highlight from its position, and this function from the hook."
  5647. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5648. (org-unhighlight))
  5649. (defun org-agenda-follow-mode ()
  5650. "Toggle follow mode in an agenda buffer."
  5651. (interactive)
  5652. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5653. (org-agenda-set-mode-name)
  5654. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5655. (org-agenda-show))
  5656. (message "Follow mode is %s"
  5657. (if org-agenda-follow-mode "on" "off")))
  5658. (defun org-agenda-entry-text-mode (&optional arg)
  5659. "Toggle entry text mode in an agenda buffer."
  5660. (interactive "P")
  5661. (setq org-agenda-entry-text-mode (or (integerp arg)
  5662. (not org-agenda-entry-text-mode)))
  5663. (org-agenda-entry-text-hide)
  5664. (and org-agenda-entry-text-mode
  5665. (let ((org-agenda-entry-text-maxlines
  5666. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5667. (org-agenda-entry-text-show)))
  5668. (org-agenda-set-mode-name)
  5669. (message "Entry text mode is %s. Maximum number of lines is %d"
  5670. (if org-agenda-entry-text-mode "on" "off")
  5671. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5672. (defun org-agenda-clockreport-mode ()
  5673. "Toggle clocktable mode in an agenda buffer."
  5674. (interactive)
  5675. (org-agenda-check-type t 'agenda)
  5676. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5677. (org-agenda-set-mode-name)
  5678. (org-agenda-redo)
  5679. (message "Clocktable mode is %s"
  5680. (if org-agenda-clockreport-mode "on" "off")))
  5681. (defun org-agenda-log-mode (&optional special)
  5682. "Toggle log mode in an agenda buffer.
  5683. With argument SPECIAL, show all possible log items, not only the ones
  5684. configured in `org-agenda-log-mode-items'.
  5685. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5686. (interactive "P")
  5687. (org-agenda-check-type t 'agenda 'timeline)
  5688. (setq org-agenda-show-log
  5689. (if (equal special '(16))
  5690. 'only
  5691. (if special '(closed clock state)
  5692. (not org-agenda-show-log))))
  5693. (org-agenda-set-mode-name)
  5694. (org-agenda-redo)
  5695. (message "Log mode is %s"
  5696. (if org-agenda-show-log "on" "off")))
  5697. (defun org-agenda-archives-mode (&optional with-files)
  5698. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5699. When called with a prefix argument, include all archive files as well."
  5700. (interactive "P")
  5701. (setq org-agenda-archives-mode
  5702. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5703. (org-agenda-set-mode-name)
  5704. (org-agenda-redo)
  5705. (message
  5706. "%s"
  5707. (cond
  5708. ((eq org-agenda-archives-mode nil)
  5709. "No archives are included")
  5710. ((eq org-agenda-archives-mode 'trees)
  5711. (format "Trees with :%s: tag are included" org-archive-tag))
  5712. ((eq org-agenda-archives-mode t)
  5713. (format "Trees with :%s: tag and all active archive files are included"
  5714. org-archive-tag)))))
  5715. (defun org-agenda-toggle-diary ()
  5716. "Toggle diary inclusion in an agenda buffer."
  5717. (interactive)
  5718. (org-agenda-check-type t 'agenda)
  5719. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5720. (org-agenda-redo)
  5721. (org-agenda-set-mode-name)
  5722. (message "Diary inclusion turned %s"
  5723. (if org-agenda-include-diary "on" "off")))
  5724. (defun org-agenda-toggle-deadlines ()
  5725. "Toggle diary inclusion in an agenda buffer."
  5726. (interactive)
  5727. (org-agenda-check-type t 'agenda)
  5728. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5729. (org-agenda-redo)
  5730. (org-agenda-set-mode-name)
  5731. (message "Deadlines inclusion turned %s"
  5732. (if org-agenda-include-deadlines "on" "off")))
  5733. (defun org-agenda-toggle-time-grid ()
  5734. "Toggle time grid in an agenda buffer."
  5735. (interactive)
  5736. (org-agenda-check-type t 'agenda)
  5737. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5738. (org-agenda-redo)
  5739. (org-agenda-set-mode-name)
  5740. (message "Time-grid turned %s"
  5741. (if org-agenda-use-time-grid "on" "off")))
  5742. (defun org-agenda-set-mode-name ()
  5743. "Set the mode name to indicate all the small mode settings."
  5744. (setq mode-name
  5745. (concat "Org-Agenda"
  5746. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5747. (if (equal org-agenda-ndays 1) " Day" "")
  5748. (if (equal org-agenda-ndays 7) " Week" "")
  5749. (if org-agenda-follow-mode " Follow" "")
  5750. (if org-agenda-entry-text-mode " ETxt" "")
  5751. (if org-agenda-include-diary " Diary" "")
  5752. (if org-agenda-include-deadlines " Ddl" "")
  5753. (if org-agenda-use-time-grid " Grid" "")
  5754. (if (and (boundp 'org-habit-show-habits)
  5755. org-habit-show-habits) " Habit" "")
  5756. (if (consp org-agenda-show-log) " LogAll"
  5757. (if org-agenda-show-log " Log" ""))
  5758. (if (or org-agenda-filter (get 'org-agenda-filter
  5759. :preset-filter))
  5760. (concat " {" (mapconcat
  5761. 'identity
  5762. (append (get 'org-agenda-filter
  5763. :preset-filter)
  5764. org-agenda-filter) "") "}")
  5765. "")
  5766. (if org-agenda-archives-mode
  5767. (if (eq org-agenda-archives-mode t)
  5768. " Archives"
  5769. (format " :%s:" org-archive-tag))
  5770. "")
  5771. (if org-agenda-clockreport-mode " Clock" "")))
  5772. (force-mode-line-update))
  5773. (defun org-agenda-post-command-hook ()
  5774. (setq org-agenda-type
  5775. (or (get-text-property (point) 'org-agenda-type)
  5776. (get-text-property (max (point-min) (1- (point)))
  5777. 'org-agenda-type))))
  5778. (defun org-agenda-next-line ()
  5779. "Move cursor to the next line, and show if follow mode is active."
  5780. (interactive)
  5781. (call-interactively 'next-line)
  5782. (org-agenda-do-context-action))
  5783. (defun org-agenda-previous-line ()
  5784. "Move cursor to the previous line, and show if follow-mode is active."
  5785. (interactive)
  5786. (call-interactively 'previous-line)
  5787. (org-agenda-do-context-action))
  5788. (defun org-agenda-do-context-action ()
  5789. "Show outline path and, maybe, follow mode window."
  5790. (let ((m (org-get-at-bol 'org-marker)))
  5791. (if (and org-agenda-follow-mode m)
  5792. (org-agenda-show))
  5793. (if (and m org-agenda-show-outline-path)
  5794. (org-with-point-at m
  5795. (org-display-outline-path t)))))
  5796. (defun org-agenda-show-priority ()
  5797. "Show the priority of the current item.
  5798. This priority is composed of the main priority given with the [#A] cookies,
  5799. and by additional input from the age of a schedules or deadline entry."
  5800. (interactive)
  5801. (let* ((pri (org-get-at-bol 'priority)))
  5802. (message "Priority is %d" (if pri pri -1000))))
  5803. (defun org-agenda-show-tags ()
  5804. "Show the tags applicable to the current item."
  5805. (interactive)
  5806. (let* ((tags (org-get-at-bol 'tags)))
  5807. (if tags
  5808. (message "Tags are :%s:"
  5809. (org-no-properties (mapconcat 'identity tags ":")))
  5810. (message "No tags associated with this line"))))
  5811. (defun org-agenda-goto (&optional highlight)
  5812. "Go to the Org-mode file which contains the item at point."
  5813. (interactive)
  5814. (let* ((marker (or (org-get-at-bol 'org-marker)
  5815. (org-agenda-error)))
  5816. (buffer (marker-buffer marker))
  5817. (pos (marker-position marker)))
  5818. (switch-to-buffer-other-window buffer)
  5819. (widen)
  5820. (push-mark)
  5821. (goto-char pos)
  5822. (when (org-mode-p)
  5823. (org-show-context 'agenda)
  5824. (save-excursion
  5825. (and (outline-next-heading)
  5826. (org-flag-heading nil)))) ; show the next heading
  5827. (recenter (/ (window-height) 2))
  5828. (run-hooks 'org-agenda-after-show-hook)
  5829. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5830. (defvar org-agenda-after-show-hook nil
  5831. "Normal hook run after an item has been shown from the agenda.
  5832. Point is in the buffer where the item originated.")
  5833. (defun org-agenda-kill ()
  5834. "Kill the entry or subtree belonging to the current agenda entry."
  5835. (interactive)
  5836. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5837. (let* ((marker (or (org-get-at-bol 'org-marker)
  5838. (org-agenda-error)))
  5839. (buffer (marker-buffer marker))
  5840. (pos (marker-position marker))
  5841. (type (org-get-at-bol 'type))
  5842. dbeg dend (n 0) conf)
  5843. (org-with-remote-undo buffer
  5844. (with-current-buffer buffer
  5845. (save-excursion
  5846. (goto-char pos)
  5847. (if (and (org-mode-p) (not (member type '("sexp"))))
  5848. (setq dbeg (progn (org-back-to-heading t) (point))
  5849. dend (org-end-of-subtree t t))
  5850. (setq dbeg (point-at-bol)
  5851. dend (min (point-max) (1+ (point-at-eol)))))
  5852. (goto-char dbeg)
  5853. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5854. (setq conf (or (eq t org-agenda-confirm-kill)
  5855. (and (numberp org-agenda-confirm-kill)
  5856. (> n org-agenda-confirm-kill))))
  5857. (and conf
  5858. (not (y-or-n-p
  5859. (format "Delete entry with %d lines in buffer \"%s\"? "
  5860. n (buffer-name buffer))))
  5861. (error "Abort"))
  5862. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5863. (with-current-buffer buffer (delete-region dbeg dend))
  5864. (message "Agenda item and source killed"))))
  5865. (defvar org-archive-default-command)
  5866. (defun org-agenda-archive-default ()
  5867. "Archive the entry or subtree belonging to the current agenda entry."
  5868. (interactive)
  5869. (require 'org-archive)
  5870. (org-agenda-archive-with org-archive-default-command))
  5871. (defun org-agenda-archive-default-with-confirmation ()
  5872. "Archive the entry or subtree belonging to the current agenda entry."
  5873. (interactive)
  5874. (require 'org-archive)
  5875. (org-agenda-archive-with org-archive-default-command 'confirm))
  5876. (defun org-agenda-archive ()
  5877. "Archive the entry or subtree belonging to the current agenda entry."
  5878. (interactive)
  5879. (org-agenda-archive-with 'org-archive-subtree))
  5880. (defun org-agenda-archive-to-archive-sibling ()
  5881. "Move the entry to the archive sibling."
  5882. (interactive)
  5883. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5884. (defun org-agenda-archive-with (cmd &optional confirm)
  5885. "Move the entry to the archive sibling."
  5886. (interactive)
  5887. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5888. (let* ((marker (or (org-get-at-bol 'org-marker)
  5889. (org-agenda-error)))
  5890. (buffer (marker-buffer marker))
  5891. (pos (marker-position marker)))
  5892. (org-with-remote-undo buffer
  5893. (with-current-buffer buffer
  5894. (if (org-mode-p)
  5895. (if (and confirm
  5896. (not (y-or-n-p "Archive this subtree or entry? ")))
  5897. (error "Abort")
  5898. (save-excursion
  5899. (goto-char pos)
  5900. (org-remove-subtree-entries-from-agenda)
  5901. (org-back-to-heading t)
  5902. (funcall cmd)))
  5903. (error "Archiving works only in Org-mode files"))))))
  5904. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5905. "Remove all lines in the agenda that correspond to a given subtree.
  5906. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5907. If this information is not given, the function uses the tree at point."
  5908. (let ((buf (or buf (current-buffer))) m p)
  5909. (save-excursion
  5910. (unless (and beg end)
  5911. (org-back-to-heading t)
  5912. (setq beg (point))
  5913. (org-end-of-subtree t)
  5914. (setq end (point)))
  5915. (set-buffer (get-buffer org-agenda-buffer-name))
  5916. (save-excursion
  5917. (goto-char (point-max))
  5918. (beginning-of-line 1)
  5919. (while (not (bobp))
  5920. (when (and (setq m (org-get-at-bol 'org-marker))
  5921. (equal buf (marker-buffer m))
  5922. (setq p (marker-position m))
  5923. (>= p beg)
  5924. (< p end))
  5925. (let ((inhibit-read-only t))
  5926. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5927. (beginning-of-line 0))))))
  5928. (defun org-agenda-refile (&optional goto rfloc no-update)
  5929. "Refile the item at point."
  5930. (interactive "P")
  5931. (if (equal goto '(16))
  5932. (org-refile-goto-last-stored)
  5933. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5934. (org-agenda-error)))
  5935. (buffer (marker-buffer marker))
  5936. (pos (marker-position marker))
  5937. (rfloc (or rfloc
  5938. (org-refile-get-location
  5939. (if goto "Goto: " "Refile to: ") buffer
  5940. org-refile-allow-creating-parent-nodes))))
  5941. (with-current-buffer buffer
  5942. (save-excursion
  5943. (save-restriction
  5944. (widen)
  5945. (goto-char marker)
  5946. (org-remove-subtree-entries-from-agenda)
  5947. (org-refile goto buffer rfloc)))))
  5948. (unless no-update (org-agenda-redo))))
  5949. (defun org-agenda-open-link (&optional arg)
  5950. "Follow the link in the current line, if any.
  5951. This looks for a link in the displayed line in the agenda. It also looks
  5952. at the text of the entry itself."
  5953. (interactive "P")
  5954. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5955. (org-get-at-bol 'org-marker)))
  5956. (buffer (and marker (marker-buffer marker)))
  5957. (prefix (buffer-substring
  5958. (point-at-bol)
  5959. (+ (point-at-bol)
  5960. (or (org-get-at-bol 'prefix-length) 0)))))
  5961. (cond
  5962. (buffer
  5963. (with-current-buffer buffer
  5964. (save-excursion
  5965. (save-restriction
  5966. (widen)
  5967. (goto-char marker)
  5968. (org-offer-links-in-entry arg prefix)))))
  5969. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5970. (save-excursion
  5971. (beginning-of-line 1)
  5972. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5973. (org-open-link-from-string (match-string 1)))
  5974. (t (error "No link to open here")))))
  5975. (defun org-agenda-copy-local-variable (var)
  5976. "Get a variable from a referenced buffer and install it here."
  5977. (let ((m (org-get-at-bol 'org-marker)))
  5978. (when (and m (buffer-live-p (marker-buffer m)))
  5979. (org-set-local var (with-current-buffer (marker-buffer m)
  5980. (symbol-value var))))))
  5981. (defun org-agenda-switch-to (&optional delete-other-windows)
  5982. "Go to the Org-mode file which contains the item at point."
  5983. (interactive)
  5984. (if (and org-return-follows-link
  5985. (not (org-get-at-bol 'org-marker))
  5986. (org-in-regexp org-bracket-link-regexp))
  5987. (org-open-link-from-string (match-string 0))
  5988. (let* ((marker (or (org-get-at-bol 'org-marker)
  5989. (org-agenda-error)))
  5990. (buffer (marker-buffer marker))
  5991. (pos (marker-position marker)))
  5992. (switch-to-buffer buffer)
  5993. (and delete-other-windows (delete-other-windows))
  5994. (widen)
  5995. (goto-char pos)
  5996. (when (org-mode-p)
  5997. (org-show-context 'agenda)
  5998. (save-excursion
  5999. (and (outline-next-heading)
  6000. (org-flag-heading nil))))))) ; show the next heading
  6001. (defun org-agenda-goto-mouse (ev)
  6002. "Go to the Org-mode file which contains the item at the mouse click."
  6003. (interactive "e")
  6004. (mouse-set-point ev)
  6005. (org-agenda-goto))
  6006. (defun org-agenda-show (&optional full-entry)
  6007. "Display the Org-mode file which contains the item at point.
  6008. With prefix argument FULL-ENTRY, make the entire entry visible
  6009. if it was hidden in the outline."
  6010. (interactive "P")
  6011. (let ((win (selected-window)))
  6012. (if full-entry
  6013. (let ((org-show-entry-below t))
  6014. (org-agenda-goto t))
  6015. (org-agenda-goto t))
  6016. (select-window win)))
  6017. (defvar org-agenda-show-window nil)
  6018. (defun org-agenda-show-and-scroll-up ()
  6019. "Display the Org-mode file which contains the item at point.
  6020. When called repeatedly, scroll the window that is displaying the buffer."
  6021. (interactive)
  6022. (let ((win (selected-window)))
  6023. (if (and (window-live-p org-agenda-show-window)
  6024. (eq this-command last-command))
  6025. (progn
  6026. (select-window org-agenda-show-window)
  6027. (ignore-errors (scroll-up)))
  6028. (org-agenda-goto t)
  6029. (show-subtree)
  6030. (setq org-agenda-show-window (selected-window)))
  6031. (select-window win)))
  6032. (defun org-agenda-show-scroll-down ()
  6033. "Scroll down the window showing the agenda."
  6034. (interactive)
  6035. (let ((win (selected-window)))
  6036. (when (window-live-p org-agenda-show-window)
  6037. (select-window org-agenda-show-window)
  6038. (ignore-errors (scroll-down))
  6039. (select-window win))))
  6040. (defun org-agenda-show-1 (&optional more)
  6041. "Display the Org-mode file which contains the item at point.
  6042. The prefix arg selects the amount of information to display:
  6043. 0 hide the subtree
  6044. 1 just show the entry according to defaults.
  6045. 2 show the children view
  6046. 3 show the subtree view
  6047. 4 show the entire subtree and any LOGBOOK drawers
  6048. 5 show the entire subtree and any drawers
  6049. With prefix argument FULL-ENTRY, make the entire entry visible
  6050. if it was hidden in the outline."
  6051. (interactive "p")
  6052. (let ((win (selected-window)))
  6053. (org-agenda-goto t)
  6054. (org-recenter-heading 1)
  6055. (cond
  6056. ((= more 0)
  6057. (hide-subtree)
  6058. (save-excursion
  6059. (org-back-to-heading)
  6060. (run-hook-with-args 'org-cycle-hook 'folded))
  6061. (message "Remote: FOLDED"))
  6062. ((and (interactive-p) (= more 1))
  6063. (message "Remote: show with default settings"))
  6064. ((= more 2)
  6065. (show-entry)
  6066. (show-children)
  6067. (save-excursion
  6068. (org-back-to-heading)
  6069. (run-hook-with-args 'org-cycle-hook 'children))
  6070. (message "Remote: CHILDREN"))
  6071. ((= more 3)
  6072. (show-subtree)
  6073. (save-excursion
  6074. (org-back-to-heading)
  6075. (run-hook-with-args 'org-cycle-hook 'subtree))
  6076. (message "Remote: SUBTREE"))
  6077. ((= more 4)
  6078. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6079. (org-drawer-regexp
  6080. (concat "^[ \t]*:\\("
  6081. (mapconcat 'regexp-quote org-drawers "\\|")
  6082. "\\):[ \t]*$")))
  6083. (show-subtree)
  6084. (save-excursion
  6085. (org-back-to-heading)
  6086. (org-cycle-hide-drawers 'subtree)))
  6087. (message "Remote: SUBTREE AND LOGBOOK"))
  6088. ((> more 4)
  6089. (show-subtree)
  6090. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6091. (select-window win)))
  6092. (defun org-recenter-heading (n)
  6093. (save-excursion
  6094. (org-back-to-heading)
  6095. (recenter n)))
  6096. (defvar org-agenda-cycle-counter nil)
  6097. (defun org-agenda-cycle-show (&optional n)
  6098. "Show the current entry in another window, with default settings.
  6099. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6100. When use repeatedly in immediate succession, the remote entry will cycle
  6101. through visibility
  6102. children -> subtree -> folded
  6103. When called with a numeric prefix arg, that arg will be passed through to
  6104. `org-agenda-show-1'. For the interpretation of that argument, see the
  6105. docstring of `org-agenda-show-1'."
  6106. (interactive "P")
  6107. (if (integerp n)
  6108. (setq org-agenda-cycle-counter n)
  6109. (if (not (eq last-command this-command))
  6110. (setq org-agenda-cycle-counter 1)
  6111. (if (equal org-agenda-cycle-counter 0)
  6112. (setq org-agenda-cycle-counter 2)
  6113. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6114. (if (> org-agenda-cycle-counter 3)
  6115. (setq org-agenda-cycle-counter 0)))))
  6116. (org-agenda-show-1 org-agenda-cycle-counter))
  6117. (defun org-agenda-recenter (arg)
  6118. "Display the Org-mode file which contains the item at point and recenter."
  6119. (interactive "P")
  6120. (let ((win (selected-window)))
  6121. (org-agenda-goto t)
  6122. (recenter arg)
  6123. (select-window win)))
  6124. (defun org-agenda-show-mouse (ev)
  6125. "Display the Org-mode file which contains the item at the mouse click."
  6126. (interactive "e")
  6127. (mouse-set-point ev)
  6128. (org-agenda-show))
  6129. (defun org-agenda-check-no-diary ()
  6130. "Check if the entry is a diary link and abort if yes."
  6131. (if (org-get-at-bol 'org-agenda-diary-link)
  6132. (org-agenda-error)))
  6133. (defun org-agenda-error ()
  6134. (error "Command not allowed in this line"))
  6135. (defun org-agenda-tree-to-indirect-buffer ()
  6136. "Show the subtree corresponding to the current entry in an indirect buffer.
  6137. This calls the command `org-tree-to-indirect-buffer' from the original
  6138. Org-mode buffer.
  6139. With numerical prefix arg ARG, go up to this level and then take that tree.
  6140. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6141. use the dedicated frame)."
  6142. (interactive)
  6143. (org-agenda-check-no-diary)
  6144. (let* ((marker (or (org-get-at-bol 'org-marker)
  6145. (org-agenda-error)))
  6146. (buffer (marker-buffer marker))
  6147. (pos (marker-position marker)))
  6148. (with-current-buffer buffer
  6149. (save-excursion
  6150. (goto-char pos)
  6151. (call-interactively 'org-tree-to-indirect-buffer)))))
  6152. (defvar org-last-heading-marker (make-marker)
  6153. "Marker pointing to the headline that last changed its TODO state
  6154. by a remote command from the agenda.")
  6155. (defun org-agenda-todo-nextset ()
  6156. "Switch TODO entry to next sequence."
  6157. (interactive)
  6158. (org-agenda-todo 'nextset))
  6159. (defun org-agenda-todo-previousset ()
  6160. "Switch TODO entry to previous sequence."
  6161. (interactive)
  6162. (org-agenda-todo 'previousset))
  6163. (defun org-agenda-todo (&optional arg)
  6164. "Cycle TODO state of line at point, also in Org-mode file.
  6165. This changes the line at point, all other lines in the agenda referring to
  6166. the same tree node, and the headline of the tree node in the Org-mode file."
  6167. (interactive "P")
  6168. (org-agenda-check-no-diary)
  6169. (let* ((col (current-column))
  6170. (marker (or (org-get-at-bol 'org-marker)
  6171. (org-agenda-error)))
  6172. (buffer (marker-buffer marker))
  6173. (pos (marker-position marker))
  6174. (hdmarker (org-get-at-bol 'org-hd-marker))
  6175. (todayp (equal (org-get-at-bol 'day)
  6176. (time-to-days (current-time))))
  6177. (inhibit-read-only t)
  6178. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6179. (org-with-remote-undo buffer
  6180. (with-current-buffer buffer
  6181. (widen)
  6182. (goto-char pos)
  6183. (org-show-context 'agenda)
  6184. (save-excursion
  6185. (and (outline-next-heading)
  6186. (org-flag-heading nil))) ; show the next heading
  6187. (let ((current-prefix-arg arg))
  6188. (call-interactively 'org-todo))
  6189. (and (bolp) (forward-char 1))
  6190. (setq newhead (org-get-heading))
  6191. (when (and (org-bound-and-true-p
  6192. org-agenda-headline-snapshot-before-repeat)
  6193. (not (equal org-agenda-headline-snapshot-before-repeat
  6194. newhead))
  6195. todayp)
  6196. (setq newhead org-agenda-headline-snapshot-before-repeat
  6197. just-one t))
  6198. (save-excursion
  6199. (org-back-to-heading)
  6200. (move-marker org-last-heading-marker (point))))
  6201. (beginning-of-line 1)
  6202. (save-excursion
  6203. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6204. (org-move-to-column col))))
  6205. (defun org-agenda-add-note (&optional arg)
  6206. "Add a time-stamped note to the entry at point."
  6207. (interactive "P")
  6208. (org-agenda-check-no-diary)
  6209. (let* ((marker (or (org-get-at-bol 'org-marker)
  6210. (org-agenda-error)))
  6211. (buffer (marker-buffer marker))
  6212. (pos (marker-position marker))
  6213. (hdmarker (org-get-at-bol 'org-hd-marker))
  6214. (inhibit-read-only t))
  6215. (with-current-buffer buffer
  6216. (widen)
  6217. (goto-char pos)
  6218. (org-show-context 'agenda)
  6219. (save-excursion
  6220. (and (outline-next-heading)
  6221. (org-flag-heading nil))) ; show the next heading
  6222. (org-add-note))))
  6223. (defun org-agenda-change-all-lines (newhead hdmarker
  6224. &optional fixface just-this)
  6225. "Change all lines in the agenda buffer which match HDMARKER.
  6226. The new content of the line will be NEWHEAD (as modified by
  6227. `org-format-agenda-item'). HDMARKER is checked with
  6228. `equal' against all `org-hd-marker' text properties in the file.
  6229. If FIXFACE is non-nil, the face of each item is modified according to
  6230. the new TODO state.
  6231. If JUST-THIS is non-nil, change just the current line, not all.
  6232. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6233. (let* ((inhibit-read-only t)
  6234. (line (org-current-line))
  6235. (thetags (with-current-buffer (marker-buffer hdmarker)
  6236. (save-excursion (save-restriction (widen)
  6237. (goto-char hdmarker)
  6238. (org-get-tags-at)))))
  6239. props m pl undone-face done-face finish new dotime cat tags)
  6240. (save-excursion
  6241. (goto-char (point-max))
  6242. (beginning-of-line 1)
  6243. (while (not finish)
  6244. (setq finish (bobp))
  6245. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6246. (or (not just-this) (= (org-current-line) line))
  6247. (equal m hdmarker))
  6248. (setq props (text-properties-at (point))
  6249. dotime (org-get-at-bol 'dotime)
  6250. cat (org-get-at-bol 'org-category)
  6251. tags thetags
  6252. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6253. pl (org-get-at-bol 'prefix-length)
  6254. undone-face (org-get-at-bol 'undone-face)
  6255. done-face (org-get-at-bol 'done-face))
  6256. (goto-char (+ (point) pl))
  6257. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6258. (cond
  6259. ((equal new "")
  6260. (beginning-of-line 1)
  6261. (and (looking-at ".*\n?") (replace-match "")))
  6262. ((looking-at ".*")
  6263. (replace-match new t t)
  6264. (beginning-of-line 1)
  6265. (add-text-properties (point-at-bol) (point-at-eol) props)
  6266. (when fixface
  6267. (add-text-properties
  6268. (point-at-bol) (point-at-eol)
  6269. (list 'face
  6270. (if org-last-todo-state-is-todo
  6271. undone-face done-face))))
  6272. (org-agenda-highlight-todo 'line)
  6273. (beginning-of-line 1))
  6274. (t (error "Line update did not work"))))
  6275. (beginning-of-line 0)))
  6276. (org-finalize-agenda)))
  6277. (defun org-agenda-align-tags (&optional line)
  6278. "Align all tags in agenda items to `org-agenda-tags-column'."
  6279. (let ((inhibit-read-only t) l c)
  6280. (save-excursion
  6281. (goto-char (if line (point-at-bol) (point-min)))
  6282. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6283. (if line (point-at-eol) nil) t)
  6284. (add-text-properties
  6285. (match-beginning 2) (match-end 2)
  6286. (list 'face (delq nil (let ((prop (get-text-property
  6287. (match-beginning 2) 'face)))
  6288. (or (listp prop) (setq prop (list prop)))
  6289. (if (memq 'org-tag prop)
  6290. prop
  6291. (cons 'org-tag prop))))))
  6292. (setq l (- (match-end 2) (match-beginning 2))
  6293. c (if (< org-agenda-tags-column 0)
  6294. (- (abs org-agenda-tags-column) l)
  6295. org-agenda-tags-column))
  6296. (delete-region (match-beginning 1) (match-end 1))
  6297. (goto-char (match-beginning 1))
  6298. (insert (org-add-props
  6299. (make-string (max 1 (- c (current-column))) ?\ )
  6300. (plist-put (copy-sequence (text-properties-at (point)))
  6301. 'face nil))))
  6302. (goto-char (point-min))
  6303. (org-font-lock-add-tag-faces (point-max)))))
  6304. (defun org-agenda-priority-up ()
  6305. "Increase the priority of line at point, also in Org-mode file."
  6306. (interactive)
  6307. (org-agenda-priority 'up))
  6308. (defun org-agenda-priority-down ()
  6309. "Decrease the priority of line at point, also in Org-mode file."
  6310. (interactive)
  6311. (org-agenda-priority 'down))
  6312. (defun org-agenda-priority (&optional force-direction)
  6313. "Set the priority of line at point, also in Org-mode file.
  6314. This changes the line at point, all other lines in the agenda referring to
  6315. the same tree node, and the headline of the tree node in the Org-mode file."
  6316. (interactive)
  6317. (unless org-enable-priority-commands
  6318. (error "Priority commands are disabled"))
  6319. (org-agenda-check-no-diary)
  6320. (let* ((marker (or (org-get-at-bol 'org-marker)
  6321. (org-agenda-error)))
  6322. (hdmarker (org-get-at-bol 'org-hd-marker))
  6323. (buffer (marker-buffer hdmarker))
  6324. (pos (marker-position hdmarker))
  6325. (inhibit-read-only t)
  6326. newhead)
  6327. (org-with-remote-undo buffer
  6328. (with-current-buffer buffer
  6329. (widen)
  6330. (goto-char pos)
  6331. (org-show-context 'agenda)
  6332. (save-excursion
  6333. (and (outline-next-heading)
  6334. (org-flag-heading nil))) ; show the next heading
  6335. (funcall 'org-priority force-direction)
  6336. (end-of-line 1)
  6337. (setq newhead (org-get-heading)))
  6338. (org-agenda-change-all-lines newhead hdmarker)
  6339. (beginning-of-line 1))))
  6340. ;; FIXME: should fix the tags property of the agenda line.
  6341. (defun org-agenda-set-tags (&optional tag onoff)
  6342. "Set tags for the current headline."
  6343. (interactive)
  6344. (org-agenda-check-no-diary)
  6345. (if (and (org-region-active-p) (interactive-p))
  6346. (call-interactively 'org-change-tag-in-region)
  6347. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6348. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6349. (org-agenda-error)))
  6350. (buffer (marker-buffer hdmarker))
  6351. (pos (marker-position hdmarker))
  6352. (inhibit-read-only t)
  6353. newhead)
  6354. (org-with-remote-undo buffer
  6355. (with-current-buffer buffer
  6356. (widen)
  6357. (goto-char pos)
  6358. (save-excursion
  6359. (org-show-context 'agenda))
  6360. (save-excursion
  6361. (and (outline-next-heading)
  6362. (org-flag-heading nil))) ; show the next heading
  6363. (goto-char pos)
  6364. (if tag
  6365. (org-toggle-tag tag onoff)
  6366. (call-interactively 'org-set-tags))
  6367. (end-of-line 1)
  6368. (setq newhead (org-get-heading)))
  6369. (org-agenda-change-all-lines newhead hdmarker)
  6370. (beginning-of-line 1)))))
  6371. (defun org-agenda-set-property ()
  6372. "Set a property for the current headline."
  6373. (interactive)
  6374. (org-agenda-check-no-diary)
  6375. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6376. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6377. (org-agenda-error)))
  6378. (buffer (marker-buffer hdmarker))
  6379. (pos (marker-position hdmarker))
  6380. (inhibit-read-only t)
  6381. newhead)
  6382. (org-with-remote-undo buffer
  6383. (with-current-buffer buffer
  6384. (widen)
  6385. (goto-char pos)
  6386. (save-excursion
  6387. (org-show-context 'agenda))
  6388. (save-excursion
  6389. (and (outline-next-heading)
  6390. (org-flag-heading nil))) ; show the next heading
  6391. (goto-char pos)
  6392. (call-interactively 'org-set-property)))))
  6393. (defun org-agenda-set-effort ()
  6394. "Set the effort property for the current headline."
  6395. (interactive)
  6396. (org-agenda-check-no-diary)
  6397. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6398. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6399. (org-agenda-error)))
  6400. (buffer (marker-buffer hdmarker))
  6401. (pos (marker-position hdmarker))
  6402. (inhibit-read-only t)
  6403. newhead)
  6404. (org-with-remote-undo buffer
  6405. (with-current-buffer buffer
  6406. (widen)
  6407. (goto-char pos)
  6408. (save-excursion
  6409. (org-show-context 'agenda))
  6410. (save-excursion
  6411. (and (outline-next-heading)
  6412. (org-flag-heading nil))) ; show the next heading
  6413. (goto-char pos)
  6414. (call-interactively 'org-set-effort)
  6415. (end-of-line 1)))))
  6416. (defun org-agenda-toggle-archive-tag ()
  6417. "Toggle the archive tag for the current entry."
  6418. (interactive)
  6419. (org-agenda-check-no-diary)
  6420. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6421. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6422. (org-agenda-error)))
  6423. (buffer (marker-buffer hdmarker))
  6424. (pos (marker-position hdmarker))
  6425. (inhibit-read-only t)
  6426. newhead)
  6427. (org-with-remote-undo buffer
  6428. (with-current-buffer buffer
  6429. (widen)
  6430. (goto-char pos)
  6431. (org-show-context 'agenda)
  6432. (save-excursion
  6433. (and (outline-next-heading)
  6434. (org-flag-heading nil))) ; show the next heading
  6435. (call-interactively 'org-toggle-archive-tag)
  6436. (end-of-line 1)
  6437. (setq newhead (org-get-heading)))
  6438. (org-agenda-change-all-lines newhead hdmarker)
  6439. (beginning-of-line 1))))
  6440. (defun org-agenda-do-date-later (arg)
  6441. (interactive "P")
  6442. (cond
  6443. ((or (equal arg '(16))
  6444. (memq last-command
  6445. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6446. (setq this-command 'org-agenda-date-later-minutes)
  6447. (org-agenda-date-later-minutes 1))
  6448. ((or (equal arg '(4))
  6449. (memq last-command
  6450. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6451. (setq this-command 'org-agenda-date-later-hours)
  6452. (org-agenda-date-later-hours 1))
  6453. (t
  6454. (org-agenda-date-later (prefix-numeric-value arg)))))
  6455. (defun org-agenda-do-date-earlier (arg)
  6456. (interactive "P")
  6457. (cond
  6458. ((or (equal arg '(16))
  6459. (memq last-command
  6460. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6461. (setq this-command 'org-agenda-date-earlier-minutes)
  6462. (org-agenda-date-earlier-minutes 1))
  6463. ((or (equal arg '(4))
  6464. (memq last-command
  6465. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6466. (setq this-command 'org-agenda-date-earlier-hours)
  6467. (org-agenda-date-earlier-hours 1))
  6468. (t
  6469. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6470. (defun org-agenda-date-later (arg &optional what)
  6471. "Change the date of this item to one day later."
  6472. (interactive "p")
  6473. (org-agenda-check-type t 'agenda 'timeline)
  6474. (org-agenda-check-no-diary)
  6475. (let* ((marker (or (org-get-at-bol 'org-marker)
  6476. (org-agenda-error)))
  6477. (buffer (marker-buffer marker))
  6478. (pos (marker-position marker)))
  6479. (org-with-remote-undo buffer
  6480. (with-current-buffer buffer
  6481. (widen)
  6482. (goto-char pos)
  6483. (if (not (org-at-timestamp-p))
  6484. (error "Cannot find time stamp"))
  6485. (org-timestamp-change arg (or what 'day)))
  6486. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6487. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6488. (defun org-agenda-date-earlier (arg &optional what)
  6489. "Change the date of this item to one day earlier."
  6490. (interactive "p")
  6491. (org-agenda-date-later (- arg) what))
  6492. (defun org-agenda-date-later-minutes (arg)
  6493. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6494. (interactive "p")
  6495. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6496. (org-agenda-date-later arg 'minute))
  6497. (defun org-agenda-date-earlier-minutes (arg)
  6498. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6499. (interactive "p")
  6500. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6501. (org-agenda-date-earlier arg 'minute))
  6502. (defun org-agenda-date-later-hours (arg)
  6503. "Change the time of this item, in hour steps."
  6504. (interactive "p")
  6505. (org-agenda-date-later arg 'hour))
  6506. (defun org-agenda-date-earlier-hours (arg)
  6507. "Change the time of this item, in hour steps."
  6508. (interactive "p")
  6509. (org-agenda-date-earlier arg 'hour))
  6510. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6511. "Show new date stamp via text properties."
  6512. ;; We use text properties to make this undoable
  6513. (let ((inhibit-read-only t)
  6514. (buffer-invisibility-spec))
  6515. (setq stamp (concat " " prefix " => " stamp))
  6516. (save-excursion
  6517. (goto-char (point-max))
  6518. (while (not (bobp))
  6519. (when (equal marker (org-get-at-bol 'org-marker))
  6520. (org-move-to-column (- (window-width) (length stamp)) t)
  6521. (org-agenda-fix-tags-filter-overlays-at (point))
  6522. (if (featurep 'xemacs)
  6523. ;; Use `duplicable' property to trigger undo recording
  6524. (let ((ex (make-extent nil nil))
  6525. (gl (make-glyph stamp)))
  6526. (set-glyph-face gl 'secondary-selection)
  6527. (set-extent-properties
  6528. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6529. (insert-extent ex (1- (point)) (point-at-eol)))
  6530. (add-text-properties
  6531. (1- (point)) (point-at-eol)
  6532. (list 'display (org-add-props stamp nil
  6533. 'face 'secondary-selection))))
  6534. (beginning-of-line 1))
  6535. (beginning-of-line 0)))))
  6536. (defun org-agenda-date-prompt (arg)
  6537. "Change the date of this item. Date is prompted for, with default today.
  6538. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6539. be used to request time specification in the time stamp."
  6540. (interactive "P")
  6541. (org-agenda-check-type t 'agenda 'timeline)
  6542. (org-agenda-check-no-diary)
  6543. (let* ((marker (or (org-get-at-bol 'org-marker)
  6544. (org-agenda-error)))
  6545. (buffer (marker-buffer marker))
  6546. (pos (marker-position marker)))
  6547. (org-with-remote-undo buffer
  6548. (with-current-buffer buffer
  6549. (widen)
  6550. (goto-char pos)
  6551. (if (not (org-at-timestamp-p t))
  6552. (error "Cannot find time stamp"))
  6553. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6554. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6555. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6556. (defun org-agenda-schedule (arg)
  6557. "Schedule the item at point.
  6558. Arg is passed through to `org-schedule'."
  6559. (interactive "P")
  6560. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6561. (org-agenda-check-no-diary)
  6562. (let* ((marker (or (org-get-at-bol 'org-marker)
  6563. (org-agenda-error)))
  6564. (type (marker-insertion-type marker))
  6565. (buffer (marker-buffer marker))
  6566. (pos (marker-position marker))
  6567. (org-insert-labeled-timestamps-at-point nil)
  6568. ts)
  6569. (set-marker-insertion-type marker t)
  6570. (org-with-remote-undo buffer
  6571. (with-current-buffer buffer
  6572. (widen)
  6573. (goto-char pos)
  6574. (setq ts (org-schedule arg)))
  6575. (org-agenda-show-new-time marker ts "S"))
  6576. (message "Item scheduled for %s" ts)))
  6577. (defun org-agenda-deadline (arg)
  6578. "Schedule the item at point.
  6579. Arg is passed through to `org-deadline'."
  6580. (interactive "P")
  6581. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6582. (org-agenda-check-no-diary)
  6583. (let* ((marker (or (org-get-at-bol 'org-marker)
  6584. (org-agenda-error)))
  6585. (buffer (marker-buffer marker))
  6586. (pos (marker-position marker))
  6587. (org-insert-labeled-timestamps-at-point nil)
  6588. ts)
  6589. (org-with-remote-undo buffer
  6590. (with-current-buffer buffer
  6591. (widen)
  6592. (goto-char pos)
  6593. (setq ts (org-deadline arg)))
  6594. (org-agenda-show-new-time marker ts "D"))
  6595. (message "Deadline for this item set to %s" ts)))
  6596. (defun org-agenda-action ()
  6597. "Select entry for agenda action, or execute an agenda action.
  6598. This command prompts for another letter. Valid inputs are:
  6599. m Mark the entry at point for an agenda action
  6600. s Schedule the marked entry to the date at the cursor
  6601. d Set the deadline of the marked entry to the date at the cursor
  6602. r Call `org-remember' with cursor date as the default date
  6603. c Call `org-capture' with cursor date as the default date
  6604. SPC Show marked entry in other window
  6605. TAB Visit marked entry in other window
  6606. The cursor may be at a date in the calendar, or in the Org agenda."
  6607. (interactive)
  6608. (let (ans)
  6609. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6610. (setq ans (read-char-exclusive))
  6611. (cond
  6612. ((equal ans ?m)
  6613. ;; Mark this entry
  6614. (if (eq major-mode 'org-agenda-mode)
  6615. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6616. (org-get-at-bol 'org-marker))))
  6617. (if m
  6618. (progn
  6619. (move-marker org-agenda-action-marker
  6620. (marker-position m) (marker-buffer m))
  6621. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6622. (error "Don't know which entry to mark")))
  6623. (error "This command works only in the agenda")))
  6624. ((equal ans ?s)
  6625. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6626. ((equal ans ?d)
  6627. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6628. ((equal ans ?r)
  6629. (org-agenda-do-action '(org-remember) t))
  6630. ((equal ans ?c)
  6631. (org-agenda-do-action '(org-capture) t))
  6632. ((equal ans ?\ )
  6633. (let ((cw (selected-window)))
  6634. (org-switch-to-buffer-other-window
  6635. (marker-buffer org-agenda-action-marker))
  6636. (goto-char org-agenda-action-marker)
  6637. (org-show-context 'agenda)
  6638. (select-window cw)))
  6639. ((equal ans ?\C-i)
  6640. (org-switch-to-buffer-other-window
  6641. (marker-buffer org-agenda-action-marker))
  6642. (goto-char org-agenda-action-marker)
  6643. (org-show-context 'agenda))
  6644. (t (error "Invalid agenda action %c" ans)))))
  6645. (defun org-agenda-do-action (form &optional current-buffer)
  6646. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6647. (let ((org-overriding-default-time (org-get-cursor-date)))
  6648. (if current-buffer
  6649. (eval form)
  6650. (if (not (marker-buffer org-agenda-action-marker))
  6651. (error "No entry has been selected for agenda action")
  6652. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6653. (save-excursion
  6654. (save-restriction
  6655. (widen)
  6656. (goto-char org-agenda-action-marker)
  6657. (eval form))))))))
  6658. (defun org-agenda-clock-in (&optional arg)
  6659. "Start the clock on the currently selected item."
  6660. (interactive "P")
  6661. (org-agenda-check-no-diary)
  6662. (if (equal arg '(4))
  6663. (org-clock-in arg)
  6664. (let* ((marker (or (org-get-at-bol 'org-marker)
  6665. (org-agenda-error)))
  6666. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6667. marker))
  6668. (pos (marker-position marker))
  6669. newhead)
  6670. (org-with-remote-undo (marker-buffer marker)
  6671. (with-current-buffer (marker-buffer marker)
  6672. (widen)
  6673. (goto-char pos)
  6674. (org-show-context 'agenda)
  6675. (org-show-entry)
  6676. (org-cycle-hide-drawers 'children)
  6677. (org-clock-in arg)
  6678. (setq newhead (org-get-heading)))
  6679. (org-agenda-change-all-lines newhead hdmarker)))))
  6680. (defun org-agenda-clock-out ()
  6681. "Stop the currently running clock."
  6682. (interactive)
  6683. (unless (marker-buffer org-clock-marker)
  6684. (error "No running clock"))
  6685. (let ((marker (make-marker)) newhead)
  6686. (org-with-remote-undo (marker-buffer org-clock-marker)
  6687. (with-current-buffer (marker-buffer org-clock-marker)
  6688. (save-excursion
  6689. (save-restriction
  6690. (widen)
  6691. (goto-char org-clock-marker)
  6692. (org-back-to-heading t)
  6693. (move-marker marker (point))
  6694. (org-clock-out)
  6695. (setq newhead (org-get-heading))))))
  6696. (org-agenda-change-all-lines newhead marker)
  6697. (move-marker marker nil)))
  6698. (defun org-agenda-clock-cancel (&optional arg)
  6699. "Cancel the currently running clock."
  6700. (interactive "P")
  6701. (unless (marker-buffer org-clock-marker)
  6702. (error "No running clock"))
  6703. (org-with-remote-undo (marker-buffer org-clock-marker)
  6704. (org-clock-cancel)))
  6705. (defun org-agenda-clock-goto ()
  6706. "Jump to the currently clocked in task within the agenda.
  6707. If the currently clocked in task is not listed in the agenda
  6708. buffer, display it in another window."
  6709. (interactive)
  6710. (let (pos)
  6711. (mapc (lambda (o)
  6712. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6713. (setq pos (overlay-start o))))
  6714. (overlays-in (point-min) (point-max)))
  6715. (cond (pos (goto-char pos))
  6716. ;; If the currently clocked entry is not in the agenda
  6717. ;; buffer, we visit it in another window:
  6718. (org-clock-current-task
  6719. (org-switch-to-buffer-other-window (org-clock-goto)))
  6720. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6721. (defun org-agenda-diary-entry-in-org-file ()
  6722. "Make a diary entry in the file `org-agenda-diary-file'."
  6723. (let (d1 d2 char (text "") dp1 dp2)
  6724. (if (equal (buffer-name) "*Calendar*")
  6725. (setq d1 (calendar-cursor-to-date t)
  6726. d2 (car calendar-mark-ring))
  6727. (setq dp1 (get-text-property (point-at-bol) 'day))
  6728. (unless dp1 (error "No date defined in current line"))
  6729. (setq d1 (calendar-gregorian-from-absolute dp1)
  6730. d2 (and (ignore-errors (mark))
  6731. (save-excursion
  6732. (goto-char (mark))
  6733. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6734. (calendar-gregorian-from-absolute dp2))))
  6735. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6736. (setq char (read-char-exclusive))
  6737. (cond
  6738. ((equal char ?d)
  6739. (setq text (read-string "Day entry: "))
  6740. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6741. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6742. ((equal char ?a)
  6743. (setq d1 (list (car d1) (nth 1 d1)
  6744. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6745. (nth 2 d1))))
  6746. (setq text (read-string "Anniversary (use %d to show years): "))
  6747. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6748. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6749. ((equal char ?b)
  6750. (setq text (read-string "Block entry: "))
  6751. (unless (and d1 d2 (not (equal d1 d2)))
  6752. (error "No block of days selected"))
  6753. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6754. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6755. ((equal char ?j)
  6756. (org-switch-to-buffer-other-window
  6757. (find-file-noselect org-agenda-diary-file))
  6758. (require 'org-datetree)
  6759. (org-datetree-find-date-create d1)
  6760. (org-reveal t))
  6761. (t (error "Invalid selection character `%c'" char)))))
  6762. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6763. "Where in `org-agenda-diary-file' should new entries be added?
  6764. Valid values:
  6765. date-tree in the date tree, as child of the date
  6766. top-level as top-level entries at the end of the file."
  6767. :group 'org-agenda
  6768. :type '(choice
  6769. (const :tag "in a date tree" date-tree)
  6770. (const :tag "as top level at end of file" top-level)))
  6771. (defcustom org-agenda-insert-diary-extract-time nil
  6772. "Non-nil means extract any time specification from the diary entry."
  6773. :group 'org-agenda
  6774. :type 'boolean)
  6775. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6776. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6777. If TEXT is not empty, it will become the headline of the new entry, and
  6778. the resulting entry will not be shown. When TEXT is empty, switch to
  6779. `org-agenda-diary-file' and let the user finish the entry there."
  6780. (let ((cw (current-window-configuration)))
  6781. (org-switch-to-buffer-other-window
  6782. (find-file-noselect org-agenda-diary-file))
  6783. (widen)
  6784. (goto-char (point-min))
  6785. (cond
  6786. ((eq type 'anniversary)
  6787. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6788. (progn
  6789. (or (org-on-heading-p t)
  6790. (progn
  6791. (outline-next-heading)
  6792. (insert "* Anniversaries\n\n")
  6793. (beginning-of-line -1)))))
  6794. (outline-next-heading)
  6795. (org-back-over-empty-lines)
  6796. (backward-char 1)
  6797. (insert "\n")
  6798. (require 'diary-lib)
  6799. (let ((calendar-date-display-form
  6800. (if (if (boundp 'calendar-date-style)
  6801. (eq calendar-date-style 'european)
  6802. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  6803. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  6804. '(day " " month " " year)
  6805. '(month " " day " " year))))
  6806. (insert (format "%%%%(diary-anniversary %s) %s"
  6807. (calendar-date-string d1 nil t) text))))
  6808. ((eq type 'day)
  6809. (let ((org-prefix-has-time t)
  6810. (org-agenda-time-leading-zero t)
  6811. fmt time time2)
  6812. (if org-agenda-insert-diary-extract-time
  6813. ;; Use org-format-agenda-item to parse text for a time-range and
  6814. ;; remove it. FIXME: This is a hack, we should refactor
  6815. ;; that function to make time extraction available separately
  6816. (setq fmt (org-format-agenda-item nil text nil nil t)
  6817. time (get-text-property 0 'time fmt)
  6818. time2 (if (> (length time) 0)
  6819. ;; split-string removes trailing ...... if
  6820. ;; no end time given. First space
  6821. ;; separates time from date.
  6822. (concat " " (car (split-string time "\\.")))
  6823. nil)
  6824. text (get-text-property 0 'txt fmt)))
  6825. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6826. (org-agenda-insert-diary-as-top-level text)
  6827. (require 'org-datetree)
  6828. (org-datetree-find-date-create d1)
  6829. (org-agenda-insert-diary-make-new-entry text))
  6830. (org-insert-time-stamp (org-time-from-absolute
  6831. (calendar-absolute-from-gregorian d1))
  6832. nil nil nil nil time2))
  6833. (end-of-line 0))
  6834. ((eq type 'block)
  6835. (if (> (calendar-absolute-from-gregorian d1)
  6836. (calendar-absolute-from-gregorian d2))
  6837. (setq d1 (prog1 d2 (setq d2 d1))))
  6838. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6839. (org-agenda-insert-diary-as-top-level text)
  6840. (require 'org-datetree)
  6841. (org-datetree-find-date-create d1)
  6842. (org-agenda-insert-diary-make-new-entry text))
  6843. (org-insert-time-stamp (org-time-from-absolute
  6844. (calendar-absolute-from-gregorian d1)))
  6845. (insert "--")
  6846. (org-insert-time-stamp (org-time-from-absolute
  6847. (calendar-absolute-from-gregorian d2)))
  6848. (end-of-line 0)))
  6849. (if (string-match "\\S-" text)
  6850. (progn
  6851. (set-window-configuration cw)
  6852. (message "%s entry added to %s"
  6853. (capitalize (symbol-name type))
  6854. (abbreviate-file-name org-agenda-diary-file)))
  6855. (org-reveal t)
  6856. (message "Please finish entry here"))))
  6857. (defun org-agenda-insert-diary-as-top-level (text)
  6858. "Make new entry as a top-level entry at the end of the file.
  6859. Add TEXT as headline, and position the cursor in the second line so that
  6860. a timestamp can be added there."
  6861. (widen)
  6862. (goto-char (point-max))
  6863. (or (bolp) (insert "\n"))
  6864. (insert "* " text "\n")
  6865. (if org-adapt-indentation (org-indent-to-column 2)))
  6866. (defun org-agenda-insert-diary-make-new-entry (text)
  6867. "Make new entry as last child of current entry.
  6868. Add TEXT as headline, and position the cursor in the second line so that
  6869. a timestamp can be added there."
  6870. (let ((org-show-following-heading t)
  6871. (org-show-siblings t)
  6872. (org-show-hierarchy-above t)
  6873. (org-show-entry-below t)
  6874. col)
  6875. (outline-next-heading)
  6876. (org-back-over-empty-lines)
  6877. (or (looking-at "[ \t]*$")
  6878. (progn (insert "\n") (backward-char 1)))
  6879. (org-insert-heading nil t)
  6880. (org-do-demote)
  6881. (setq col (current-column))
  6882. (insert text "\n")
  6883. (if org-adapt-indentation (org-indent-to-column col))
  6884. (let ((org-show-following-heading t)
  6885. (org-show-siblings t)
  6886. (org-show-hierarchy-above t)
  6887. (org-show-entry-below t))
  6888. (org-show-context))))
  6889. (defun org-agenda-diary-entry ()
  6890. "Make a diary entry, like the `i' command from the calendar.
  6891. All the standard commands work: block, weekly etc.
  6892. When `org-agenda-diary-file' points to a file,
  6893. `org-agenda-diary-entry-in-org-file' is called instead to create
  6894. entries in that Org-mode file."
  6895. (interactive)
  6896. (org-agenda-check-type t 'agenda 'timeline)
  6897. (if (not (eq org-agenda-diary-file 'diary-file))
  6898. (org-agenda-diary-entry-in-org-file)
  6899. (require 'diary-lib)
  6900. (let* ((char (progn
  6901. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6902. (read-char-exclusive)))
  6903. (cmd (cdr (assoc char
  6904. '((?d . insert-diary-entry)
  6905. (?w . insert-weekly-diary-entry)
  6906. (?m . insert-monthly-diary-entry)
  6907. (?y . insert-yearly-diary-entry)
  6908. (?a . insert-anniversary-diary-entry)
  6909. (?b . insert-block-diary-entry)
  6910. (?c . insert-cyclic-diary-entry)))))
  6911. (oldf (symbol-function 'calendar-cursor-to-date))
  6912. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6913. (point (point))
  6914. (mark (or (mark t) (point))))
  6915. (unless cmd
  6916. (error "No command associated with <%c>" char))
  6917. (unless (and (get-text-property point 'day)
  6918. (or (not (equal ?b char))
  6919. (get-text-property mark 'day)))
  6920. (error "Don't know which date to use for diary entry"))
  6921. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6922. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6923. (let ((calendar-mark-ring
  6924. (list (calendar-gregorian-from-absolute
  6925. (or (get-text-property mark 'day)
  6926. (get-text-property point 'day))))))
  6927. (unwind-protect
  6928. (progn
  6929. (fset 'calendar-cursor-to-date
  6930. (lambda (&optional error dummy)
  6931. (calendar-gregorian-from-absolute
  6932. (get-text-property point 'day))))
  6933. (call-interactively cmd))
  6934. (fset 'calendar-cursor-to-date oldf))))))
  6935. (defun org-agenda-execute-calendar-command (cmd)
  6936. "Execute a calendar command from the agenda, with the date associated to
  6937. the cursor position."
  6938. (org-agenda-check-type t 'agenda 'timeline)
  6939. (require 'diary-lib)
  6940. (unless (get-text-property (point) 'day)
  6941. (error "Don't know which date to use for calendar command"))
  6942. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6943. (point (point))
  6944. (date (calendar-gregorian-from-absolute
  6945. (get-text-property point 'day)))
  6946. ;; the following 2 vars are needed in the calendar
  6947. (displayed-month (car date))
  6948. (displayed-year (nth 2 date)))
  6949. (unwind-protect
  6950. (progn
  6951. (fset 'calendar-cursor-to-date
  6952. (lambda (&optional error dummy)
  6953. (calendar-gregorian-from-absolute
  6954. (get-text-property point 'day))))
  6955. (call-interactively cmd))
  6956. (fset 'calendar-cursor-to-date oldf))))
  6957. (defun org-agenda-phases-of-moon ()
  6958. "Display the phases of the moon for the 3 months around the cursor date."
  6959. (interactive)
  6960. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6961. (defun org-agenda-holidays ()
  6962. "Display the holidays for the 3 months around the cursor date."
  6963. (interactive)
  6964. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6965. (defvar calendar-longitude)
  6966. (defvar calendar-latitude)
  6967. (defvar calendar-location-name)
  6968. (defun org-agenda-sunrise-sunset (arg)
  6969. "Display sunrise and sunset for the cursor date.
  6970. Latitude and longitude can be specified with the variables
  6971. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6972. argument, latitude and longitude will be prompted for."
  6973. (interactive "P")
  6974. (require 'solar)
  6975. (let ((calendar-longitude (if arg nil calendar-longitude))
  6976. (calendar-latitude (if arg nil calendar-latitude))
  6977. (calendar-location-name
  6978. (if arg "the given coordinates" calendar-location-name)))
  6979. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6980. (defun org-agenda-goto-calendar ()
  6981. "Open the Emacs calendar with the date at the cursor."
  6982. (interactive)
  6983. (org-agenda-check-type t 'agenda 'timeline)
  6984. (let* ((day (or (get-text-property (point) 'day)
  6985. (error "Don't know which date to open in calendar")))
  6986. (date (calendar-gregorian-from-absolute day))
  6987. (calendar-move-hook nil)
  6988. (calendar-view-holidays-initially-flag nil)
  6989. (calendar-view-diary-initially-flag nil))
  6990. (calendar)
  6991. (calendar-goto-date date)))
  6992. ;;;###autoload
  6993. (defun org-calendar-goto-agenda ()
  6994. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6995. This is a command that has to be installed in `calendar-mode-map'."
  6996. (interactive)
  6997. (org-agenda-list nil (calendar-absolute-from-gregorian
  6998. (calendar-cursor-to-date))
  6999. nil))
  7000. (defun org-agenda-convert-date ()
  7001. (interactive)
  7002. (org-agenda-check-type t 'agenda 'timeline)
  7003. (let ((day (get-text-property (point) 'day))
  7004. date s)
  7005. (unless day
  7006. (error "Don't know which date to convert"))
  7007. (setq date (calendar-gregorian-from-absolute day))
  7008. (setq s (concat
  7009. "Gregorian: " (calendar-date-string date) "\n"
  7010. "ISO: " (calendar-iso-date-string date) "\n"
  7011. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7012. "Julian: " (calendar-julian-date-string date) "\n"
  7013. "Astron. JD: " (calendar-astro-date-string date)
  7014. " (Julian date number at noon UTC)\n"
  7015. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7016. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7017. "French: " (calendar-french-date-string date) "\n"
  7018. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7019. "Mayan: " (calendar-mayan-date-string date) "\n"
  7020. "Coptic: " (calendar-coptic-date-string date) "\n"
  7021. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7022. "Persian: " (calendar-persian-date-string date) "\n"
  7023. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7024. (with-output-to-temp-buffer "*Dates*"
  7025. (princ s))
  7026. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7027. ;;; Bulk commands
  7028. (defvar org-agenda-bulk-marked-entries nil
  7029. "List of markers that refer to marked entries in the agenda.")
  7030. (defun org-agenda-bulk-marked-p ()
  7031. (eq (get-char-property (point-at-bol) 'type)
  7032. 'org-marked-entry-overlay))
  7033. (defun org-agenda-bulk-mark ()
  7034. "Mark the entry at point for future bulk action."
  7035. (interactive)
  7036. (org-agenda-check-no-diary)
  7037. (let* ((m (org-get-at-bol 'org-hd-marker))
  7038. ov)
  7039. (unless (org-agenda-bulk-marked-p)
  7040. (unless m (error "Nothing to mark at point"))
  7041. (push m org-agenda-bulk-marked-entries)
  7042. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7043. (org-overlay-display ov "> "
  7044. (org-get-todo-face "TODO")
  7045. 'evaporate)
  7046. (overlay-put ov 'type 'org-marked-entry-overlay))
  7047. (beginning-of-line 2)
  7048. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7049. (beginning-of-line 2))
  7050. (message "%d entries marked for bulk action"
  7051. (length org-agenda-bulk-marked-entries))))
  7052. (defun org-agenda-bulk-unmark ()
  7053. "Unmark the entry at point for future bulk action."
  7054. (interactive)
  7055. (when (org-agenda-bulk-marked-p)
  7056. (org-agenda-bulk-remove-overlays
  7057. (point-at-bol) (+ 2 (point-at-bol)))
  7058. (setq org-agenda-bulk-marked-entries
  7059. (delete (org-get-at-bol 'org-hd-marker)
  7060. org-agenda-bulk-marked-entries)))
  7061. (beginning-of-line 2)
  7062. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7063. (beginning-of-line 2))
  7064. (message "%d entries marked for bulk action"
  7065. (length org-agenda-bulk-marked-entries)))
  7066. (defun org-agenda-bulk-toggle ()
  7067. "Toggle marking the entry at point for bulk action."
  7068. (interactive)
  7069. (if (org-agenda-bulk-marked-p)
  7070. (org-agenda-bulk-unmark)
  7071. (org-agenda-bulk-mark)))
  7072. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7073. "Remove the mark overlays between BEG and END in the agenda buffer.
  7074. BEG and END default to the buffer limits.
  7075. This only removes the overlays, it does not remove the markers
  7076. from the list in `org-agenda-bulk-marked-entries'."
  7077. (interactive)
  7078. (mapc (lambda (ov)
  7079. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7080. (delete-overlay ov)))
  7081. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7082. (defun org-agenda-bulk-remove-all-marks ()
  7083. "Remove all marks in the agenda buffer.
  7084. This will remove the markers, and the overlays."
  7085. (interactive)
  7086. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7087. (setq org-agenda-bulk-marked-entries nil)
  7088. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7089. (defun org-agenda-bulk-action (&optional arg)
  7090. "Execute an remote-editing action on all marked entries.
  7091. The prefix arg is passed through to the command if possible."
  7092. (interactive "P")
  7093. (unless org-agenda-bulk-marked-entries
  7094. (error "No entries are marked"))
  7095. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7096. (let* ((action (read-char-exclusive))
  7097. (org-log-refile (if org-log-refile 'time nil))
  7098. (entries (reverse org-agenda-bulk-marked-entries))
  7099. redo-at-end
  7100. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7101. (cond
  7102. ((equal action ?$)
  7103. (setq cmd '(org-agenda-archive)))
  7104. ((equal action ?A)
  7105. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7106. ((member action '(?r ?w))
  7107. (setq rfloc (org-refile-get-location
  7108. "Refile to: "
  7109. (marker-buffer (car org-agenda-bulk-marked-entries))
  7110. org-refile-allow-creating-parent-nodes))
  7111. (if (nth 3 rfloc)
  7112. (setcar (nthcdr 3 rfloc)
  7113. (move-marker (make-marker) (nth 3 rfloc)
  7114. (or (get-file-buffer (nth 1 rfloc))
  7115. (find-buffer-visiting (nth 1 rfloc))
  7116. (error "This should not happen")))))
  7117. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7118. redo-at-end t))
  7119. ((equal action ?t)
  7120. (setq state (org-icompleting-read
  7121. "Todo state: "
  7122. (with-current-buffer (marker-buffer (car entries))
  7123. (mapcar 'list org-todo-keywords-1))))
  7124. (setq cmd `(let ((org-inhibit-blocking t)
  7125. (org-inhibit-logging 'note))
  7126. (org-agenda-todo ,state))))
  7127. ((memq action '(?- ?+))
  7128. (setq tag (org-icompleting-read
  7129. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7130. (with-current-buffer (marker-buffer (car entries))
  7131. (delq nil
  7132. (mapcar (lambda (x)
  7133. (if (stringp (car x)) x)) org-tag-alist)))))
  7134. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7135. ((memq action '(?s ?d))
  7136. (let* ((date (unless arg
  7137. (org-read-date
  7138. nil nil nil
  7139. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7140. (ans (if arg nil org-read-date-final-answer))
  7141. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7142. (setq cmd `(let* ((bound (fboundp 'read-string))
  7143. (old (and bound (symbol-function 'read-string))))
  7144. (unwind-protect
  7145. (progn
  7146. (fset 'read-string (lambda (&rest ignore) ,ans))
  7147. (eval '(,c1 arg)))
  7148. (if bound
  7149. (fset 'read-string old)
  7150. (fmakunbound 'read-string)))))))
  7151. (t (error "Invalid bulk action")))
  7152. ;; Sort the markers, to make sure that parents are handled before children
  7153. (setq entries (sort entries
  7154. (lambda (a b)
  7155. (cond
  7156. ((equal (marker-buffer a) (marker-buffer b))
  7157. (< (marker-position a) (marker-position b)))
  7158. (t
  7159. (string< (buffer-name (marker-buffer a))
  7160. (buffer-name (marker-buffer b))))))))
  7161. ;; Now loop over all markers and apply cmd
  7162. (while (setq e (pop entries))
  7163. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7164. (if (not pos)
  7165. (progn (message "Skipping removed entry at %s" e)
  7166. (setq cntskip (1+ cntskip)))
  7167. (goto-char pos)
  7168. (eval cmd)
  7169. (setq org-agenda-bulk-marked-entries
  7170. (delete e org-agenda-bulk-marked-entries))
  7171. (setq cnt (1+ cnt))))
  7172. (setq org-agenda-bulk-marked-entries nil)
  7173. (org-agenda-bulk-remove-all-marks)
  7174. (when redo-at-end (org-agenda-redo))
  7175. (message "Acted on %d entries%s"
  7176. cnt
  7177. (if (= cntskip 0)
  7178. ""
  7179. (format ", skipped %d (disappeared before their turn)"
  7180. cntskip)))))
  7181. ;;; Flagging notes
  7182. (defun org-agenda-show-the-flagging-note ()
  7183. "Display the flagging note in the other window.
  7184. When called a second time in direct sequence, offer to remove the FLAGGING
  7185. tag and (if present) the flagging note."
  7186. (interactive)
  7187. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7188. (win (selected-window))
  7189. note heading newhead)
  7190. (unless hdmarker
  7191. (error "No linked entry at point"))
  7192. (if (and (eq this-command last-command)
  7193. (y-or-n-p "Unflag and remove any flagging note? "))
  7194. (progn
  7195. (org-agenda-remove-flag hdmarker)
  7196. (let ((win (get-buffer-window "*Flagging Note*")))
  7197. (and win (delete-window win)))
  7198. (message "Entry unflaged"))
  7199. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7200. (unless note
  7201. (error "No flagging note"))
  7202. (org-kill-new note)
  7203. (org-switch-to-buffer-other-window "*Flagging Note*")
  7204. (erase-buffer)
  7205. (insert note)
  7206. (goto-char (point-min))
  7207. (while (re-search-forward "\\\\n" nil t)
  7208. (replace-match "\n" t t))
  7209. (goto-char (point-min))
  7210. (select-window win)
  7211. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7212. (defun org-agenda-remove-flag (marker)
  7213. "Remove the FLAGGED tag and any flagging note in the entry."
  7214. (let (newhead)
  7215. (org-with-point-at marker
  7216. (org-toggle-tag "FLAGGED" 'off)
  7217. (org-entry-delete nil "THEFLAGGINGNOTE")
  7218. (setq newhead (org-get-heading)))
  7219. (org-agenda-change-all-lines newhead marker)
  7220. (message "Entry unflaged")))
  7221. (defun org-agenda-get-any-marker (&optional pos)
  7222. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7223. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7224. ;;; Appointment reminders
  7225. (defvar appt-time-msg-list)
  7226. ;;;###autoload
  7227. (defun org-agenda-to-appt (&optional refresh filter)
  7228. "Activate appointments found in `org-agenda-files'.
  7229. With a \\[universal-argument] prefix, refresh the list of
  7230. appointments.
  7231. If FILTER is t, interactively prompt the user for a regular
  7232. expression, and filter out entries that don't match it.
  7233. If FILTER is a string, use this string as a regular expression
  7234. for filtering entries out.
  7235. FILTER can also be an alist with the car of each cell being
  7236. either 'headline or 'category. For example:
  7237. '((headline \"IMPORTANT\")
  7238. (category \"Work\"))
  7239. will only add headlines containing IMPORTANT or headlines
  7240. belonging to the \"Work\" category."
  7241. (interactive "P")
  7242. (if refresh (setq appt-time-msg-list nil))
  7243. (if (eq filter t)
  7244. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7245. (let* ((cnt 0) ; count added events
  7246. (org-agenda-new-buffers nil)
  7247. (org-deadline-warning-days 0)
  7248. (today (org-date-to-gregorian
  7249. (time-to-days (current-time))))
  7250. (org-agenda-restrict nil)
  7251. (files (org-agenda-files 'unrestricted)) entries file)
  7252. ;; Get all entries which may contain an appt
  7253. (org-prepare-agenda-buffers files)
  7254. (while (setq file (pop files))
  7255. (setq entries
  7256. (append entries
  7257. (org-agenda-get-day-entries
  7258. file today :timestamp :scheduled :deadline))))
  7259. (setq entries (delq nil entries))
  7260. ;; Map thru entries and find if we should filter them out
  7261. (mapc
  7262. (lambda(x)
  7263. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7264. (cat (get-text-property 1 'org-category x))
  7265. (tod (get-text-property 1 'time-of-day x))
  7266. (ok (or (null filter)
  7267. (and (stringp filter) (string-match filter evt))
  7268. (and (listp filter)
  7269. (or (string-match
  7270. (cadr (assoc 'category filter)) cat)
  7271. (string-match
  7272. (cadr (assoc 'headline filter)) evt))))))
  7273. ;; FIXME: Shall we remove text-properties for the appt text?
  7274. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7275. (when (and ok tod)
  7276. (setq tod (concat "00" (number-to-string tod))
  7277. tod (when (string-match
  7278. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7279. (concat (match-string 1 tod) ":"
  7280. (match-string 2 tod))))
  7281. (appt-add tod evt)
  7282. (setq cnt (1+ cnt))))) entries)
  7283. (org-release-buffers org-agenda-new-buffers)
  7284. (if (eq cnt 0)
  7285. (message "No event to add")
  7286. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7287. (defun org-agenda-todayp (date)
  7288. "Does DATE mean today, when considering `org-extend-today-until'?"
  7289. (let (today h)
  7290. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7291. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7292. (setq h (nth 2 (decode-time (current-time))))
  7293. (or (and (>= h org-extend-today-until)
  7294. (= date today))
  7295. (and (< h org-extend-today-until)
  7296. (= date (1- today))))))
  7297. (provide 'org-agenda)
  7298. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7299. ;;; org-agenda.el ends here