org-agenda.el 300 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868
  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.02trans
  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-while-redo nil)
  2542. (defvar org-agenda-filter-preset nil
  2543. "A preset of the tags filter used for secondary agenda filtering.
  2544. This must be a list of strings, each string must be a single tag preceded
  2545. by \"+\" or \"-\".
  2546. This variable should not be set directly, but agenda custom commands can
  2547. bind it in the options section. The preset filter is a global property of
  2548. the entire agenda view. In a block agenda, it will not work reliably to
  2549. define a filter for one of the individual blocks. You need to set it in
  2550. the global options and expect it to be applied to the entire view.")
  2551. (defun org-prepare-agenda (&optional name)
  2552. (setq org-todo-keywords-for-agenda nil)
  2553. (setq org-done-keywords-for-agenda nil)
  2554. (setq org-drawers-for-agenda nil)
  2555. (unless org-agenda-persistent-filter
  2556. (setq org-agenda-filter nil))
  2557. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2558. (if org-agenda-multi
  2559. (progn
  2560. (setq buffer-read-only nil)
  2561. (goto-char (point-max))
  2562. (unless (or (bobp) org-agenda-compact-blocks)
  2563. (insert "\n"
  2564. (if (stringp org-agenda-block-separator)
  2565. org-agenda-block-separator
  2566. (make-string (window-width) org-agenda-block-separator))
  2567. "\n"))
  2568. (narrow-to-region (point) (point-max)))
  2569. (org-agenda-reset-markers)
  2570. (setq org-agenda-contributing-files nil)
  2571. (setq org-agenda-columns-active nil)
  2572. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2573. (setq org-todo-keywords-for-agenda
  2574. (org-uniquify org-todo-keywords-for-agenda))
  2575. (setq org-done-keywords-for-agenda
  2576. (org-uniquify org-done-keywords-for-agenda))
  2577. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2578. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2579. (awin (get-buffer-window abuf)))
  2580. (cond
  2581. ((equal (current-buffer) abuf) nil)
  2582. (awin (select-window awin))
  2583. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2584. ((equal org-agenda-window-setup 'current-window)
  2585. (switch-to-buffer abuf))
  2586. ((equal org-agenda-window-setup 'other-window)
  2587. (org-switch-to-buffer-other-window abuf))
  2588. ((equal org-agenda-window-setup 'other-frame)
  2589. (switch-to-buffer-other-frame abuf))
  2590. ((equal org-agenda-window-setup 'reorganize-frame)
  2591. (delete-other-windows)
  2592. (org-switch-to-buffer-other-window abuf)))
  2593. ;; additional test in case agenda is invoked from within agenda
  2594. ;; buffer via elisp link
  2595. (unless (equal (current-buffer) abuf)
  2596. (switch-to-buffer abuf)))
  2597. (setq buffer-read-only nil)
  2598. (let ((inhibit-read-only t)) (erase-buffer))
  2599. (org-agenda-mode)
  2600. (and name (not org-agenda-name)
  2601. (org-set-local 'org-agenda-name name)))
  2602. (setq buffer-read-only nil))
  2603. (defun org-finalize-agenda ()
  2604. "Finishing touch for the agenda buffer, called just before displaying it."
  2605. (unless org-agenda-multi
  2606. (save-excursion
  2607. (let ((inhibit-read-only t))
  2608. (goto-char (point-min))
  2609. (while (org-activate-bracket-links (point-max))
  2610. (add-text-properties (match-beginning 0) (match-end 0)
  2611. '(face org-link)))
  2612. (org-agenda-align-tags)
  2613. (unless org-agenda-with-colors
  2614. (remove-text-properties (point-min) (point-max) '(face nil))))
  2615. (if (and (boundp 'org-agenda-overriding-columns-format)
  2616. org-agenda-overriding-columns-format)
  2617. (org-set-local 'org-agenda-overriding-columns-format
  2618. org-agenda-overriding-columns-format))
  2619. (if (and (boundp 'org-agenda-view-columns-initially)
  2620. org-agenda-view-columns-initially)
  2621. (org-agenda-columns))
  2622. (when org-agenda-fontify-priorities
  2623. (org-agenda-fontify-priorities))
  2624. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2625. (org-agenda-dim-blocked-tasks))
  2626. (org-agenda-mark-clocking-task)
  2627. (when org-agenda-entry-text-mode
  2628. (org-agenda-entry-text-hide)
  2629. (org-agenda-entry-text-show))
  2630. (if (functionp 'org-habit-insert-consistency-graphs)
  2631. (org-habit-insert-consistency-graphs))
  2632. (run-hooks 'org-finalize-agenda-hook)
  2633. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2634. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2635. (org-agenda-filter-apply org-agenda-filter))
  2636. )))
  2637. (defun org-agenda-mark-clocking-task ()
  2638. "Mark the current clock entry in the agenda if it is present."
  2639. (mapc (lambda (o)
  2640. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2641. (delete-overlay o)))
  2642. (overlays-in (point-min) (point-max)))
  2643. (when (marker-buffer org-clock-hd-marker)
  2644. (save-excursion
  2645. (goto-char (point-min))
  2646. (let (s ov)
  2647. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2648. (goto-char s)
  2649. (when (equal (org-get-at-bol 'org-hd-marker)
  2650. org-clock-hd-marker)
  2651. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2652. (overlay-put ov 'type 'org-agenda-clocking)
  2653. (overlay-put ov 'face 'org-agenda-clocking)
  2654. (overlay-put ov 'help-echo
  2655. "The clock is running in this item")))))))
  2656. (defun org-agenda-fontify-priorities ()
  2657. "Make highest priority lines bold, and lowest italic."
  2658. (interactive)
  2659. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2660. (delete-overlay o)))
  2661. (overlays-in (point-min) (point-max)))
  2662. (save-excursion
  2663. (let ((inhibit-read-only t)
  2664. b e p ov h l)
  2665. (goto-char (point-min))
  2666. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2667. (setq h (or (get-char-property (point) 'org-highest-priority)
  2668. org-highest-priority)
  2669. l (or (get-char-property (point) 'org-lowest-priority)
  2670. org-lowest-priority)
  2671. p (string-to-char (match-string 1))
  2672. b (match-beginning 0)
  2673. e (if (eq org-agenda-fontify-priorities 'cookies)
  2674. (match-end 0)
  2675. (point-at-eol))
  2676. ov (make-overlay b e))
  2677. (overlay-put
  2678. ov 'face
  2679. (cond ((org-face-from-face-or-color
  2680. 'priority nil
  2681. (cdr (assoc p org-priority-faces))))
  2682. ((and (listp org-agenda-fontify-priorities)
  2683. (org-face-from-face-or-color
  2684. 'priority nil
  2685. (cdr (assoc p org-agenda-fontify-priorities)))))
  2686. ((equal p l) 'italic)
  2687. ((equal p h) 'bold)))
  2688. (overlay-put ov 'org-type 'org-priority)))))
  2689. (defun org-agenda-dim-blocked-tasks ()
  2690. "Dim currently blocked TODO's in the agenda display."
  2691. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2692. (delete-overlay o)))
  2693. (overlays-in (point-min) (point-max)))
  2694. (save-excursion
  2695. (let ((inhibit-read-only t)
  2696. (org-depend-tag-blocked nil)
  2697. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2698. org-blocked-by-checkboxes
  2699. invis1 b e p ov h l)
  2700. (goto-char (point-min))
  2701. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2702. (and pos (goto-char (1+ pos))))
  2703. (setq org-blocked-by-checkboxes nil invis1 invis)
  2704. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2705. (when (and marker
  2706. (not (with-current-buffer (marker-buffer marker)
  2707. (save-excursion
  2708. (goto-char marker)
  2709. (if (org-entry-get nil "NOBLOCKING")
  2710. t ;; Never block this entry
  2711. (run-hook-with-args-until-failure
  2712. 'org-blocker-hook
  2713. (list :type 'todo-state-change
  2714. :position marker
  2715. :from 'todo
  2716. :to 'done)))))))
  2717. (if org-blocked-by-checkboxes (setq invis1 nil))
  2718. (setq b (if invis1
  2719. (max (point-min) (1- (point-at-bol)))
  2720. (point-at-bol))
  2721. e (point-at-eol)
  2722. ov (make-overlay b e))
  2723. (if invis1
  2724. (overlay-put ov 'invisible t)
  2725. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2726. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2727. (defvar org-agenda-skip-function nil
  2728. "Function to be called at each match during agenda construction.
  2729. If this function returns nil, the current match should not be skipped.
  2730. Otherwise, the function must return a position from where the search
  2731. should be continued.
  2732. This may also be a Lisp form, it will be evaluated.
  2733. Never set this variable using `setq' or so, because then it will apply
  2734. to all future agenda commands. Instead, bind it with `let' to scope
  2735. it dynamically into the agenda-constructing command. A good way to set
  2736. it is through options in `org-agenda-custom-commands'.")
  2737. (defun org-agenda-skip ()
  2738. "Throw to `:skip' in places that should be skipped.
  2739. Also moves point to the end of the skipped region, so that search can
  2740. continue from there."
  2741. (let ((p (point-at-bol)) to fp)
  2742. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2743. (get-text-property p :org-archived)
  2744. (org-end-of-subtree t)
  2745. (throw :skip t))
  2746. (and org-agenda-skip-comment-trees
  2747. (get-text-property p :org-comment)
  2748. (org-end-of-subtree t)
  2749. (throw :skip t))
  2750. (if (equal (char-after p) ?#) (throw :skip t))
  2751. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2752. (consp org-agenda-skip-function))
  2753. (setq to (save-excursion
  2754. (save-match-data
  2755. (if fp
  2756. (funcall org-agenda-skip-function)
  2757. (eval org-agenda-skip-function))))))
  2758. (goto-char to)
  2759. (throw :skip t))))
  2760. (defvar org-agenda-markers nil
  2761. "List of all currently active markers created by `org-agenda'.")
  2762. (defvar org-agenda-last-marker-time (org-float-time)
  2763. "Creation time of the last agenda marker.")
  2764. (defun org-agenda-new-marker (&optional pos)
  2765. "Return a new agenda marker.
  2766. Org-mode keeps a list of these markers and resets them when they are
  2767. no longer in use."
  2768. (let ((m (copy-marker (or pos (point)))))
  2769. (setq org-agenda-last-marker-time (org-float-time))
  2770. (push m org-agenda-markers)
  2771. m))
  2772. (defun org-agenda-reset-markers ()
  2773. "Reset markers created by `org-agenda'."
  2774. (while org-agenda-markers
  2775. (move-marker (pop org-agenda-markers) nil)))
  2776. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2777. "Save relative positions of markers in region."
  2778. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2779. org-agenda-markers))
  2780. ;;; Entry text mode
  2781. (defun org-agenda-entry-text-show-here ()
  2782. "Add some text from the entry as context to the current line."
  2783. (let (m txt o)
  2784. (setq m (org-get-at-bol 'org-hd-marker))
  2785. (unless (marker-buffer m)
  2786. (error "No marker points to an entry here"))
  2787. (setq txt (concat "\n" (org-no-properties
  2788. (org-agenda-get-some-entry-text
  2789. m org-agenda-entry-text-maxlines " > "))))
  2790. (when (string-match "\\S-" txt)
  2791. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2792. (overlay-put o 'evaporate t)
  2793. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2794. (overlay-put o 'after-string txt))))
  2795. (defun org-agenda-entry-text-show ()
  2796. "Add entry context for all agenda lines."
  2797. (interactive)
  2798. (save-excursion
  2799. (goto-char (point-max))
  2800. (beginning-of-line 1)
  2801. (while (not (bobp))
  2802. (when (org-get-at-bol 'org-hd-marker)
  2803. (org-agenda-entry-text-show-here))
  2804. (beginning-of-line 0))))
  2805. (defun org-agenda-entry-text-hide ()
  2806. "Remove any shown entry context."
  2807. (delq nil
  2808. (mapcar (lambda (o)
  2809. (if (eq (overlay-get o 'org-overlay-type)
  2810. 'agenda-entry-content)
  2811. (progn (delete-overlay o) t)))
  2812. (overlays-in (point-min) (point-max)))))
  2813. ;;; Agenda timeline
  2814. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2815. (defun org-timeline (&optional include-all)
  2816. "Show a time-sorted view of the entries in the current org file.
  2817. Only entries with a time stamp of today or later will be listed. With
  2818. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2819. under the current date.
  2820. If the buffer contains an active region, only check the region for
  2821. dates."
  2822. (interactive "P")
  2823. (org-compile-prefix-format 'timeline)
  2824. (org-set-sorting-strategy 'timeline)
  2825. (let* ((dopast t)
  2826. (dotodo include-all)
  2827. (doclosed org-agenda-show-log)
  2828. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2829. (current-buffer))))
  2830. (date (calendar-current-date))
  2831. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2832. (end (if (org-region-active-p) (region-end) (point-max)))
  2833. (day-numbers (org-get-all-dates beg end 'no-ranges
  2834. t doclosed ; always include today
  2835. org-timeline-show-empty-dates))
  2836. (org-deadline-warning-days 0)
  2837. (org-agenda-only-exact-dates t)
  2838. (today (time-to-days (current-time)))
  2839. (past t)
  2840. args
  2841. s e rtn d emptyp wd)
  2842. (setq org-agenda-redo-command
  2843. (list 'progn
  2844. (list 'org-switch-to-buffer-other-window (current-buffer))
  2845. (list 'org-timeline (list 'quote include-all))))
  2846. (if (not dopast)
  2847. ;; Remove past dates from the list of dates.
  2848. (setq day-numbers (delq nil (mapcar (lambda(x)
  2849. (if (>= x today) x nil))
  2850. day-numbers))))
  2851. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2852. (if doclosed (push :closed args))
  2853. (push :timestamp args)
  2854. (push :deadline args)
  2855. (push :scheduled args)
  2856. (push :sexp args)
  2857. (if dotodo (push :todo args))
  2858. (insert "Timeline of file " entry "\n")
  2859. (add-text-properties (point-min) (point)
  2860. (list 'face 'org-agenda-structure))
  2861. (org-agenda-mark-header-line (point-min))
  2862. (while (setq d (pop day-numbers))
  2863. (if (and (listp d) (eq (car d) :omitted))
  2864. (progn
  2865. (setq s (point))
  2866. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2867. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2868. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2869. (if (and (>= d today)
  2870. dopast
  2871. past)
  2872. (progn
  2873. (setq past nil)
  2874. (insert (make-string 79 ?-) "\n")))
  2875. (setq date (calendar-gregorian-from-absolute d)
  2876. wd (calendar-day-of-week date))
  2877. (setq s (point))
  2878. (setq rtn (and (not emptyp)
  2879. (apply 'org-agenda-get-day-entries entry
  2880. date args)))
  2881. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2882. (progn
  2883. (insert
  2884. (if (stringp org-agenda-format-date)
  2885. (format-time-string org-agenda-format-date
  2886. (org-time-from-absolute date))
  2887. (funcall org-agenda-format-date date))
  2888. "\n")
  2889. (put-text-property s (1- (point)) 'face
  2890. (if (member wd org-agenda-weekend-days)
  2891. 'org-agenda-date-weekend
  2892. 'org-agenda-date))
  2893. (put-text-property s (1- (point)) 'org-date-line t)
  2894. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2895. (if (equal d today)
  2896. (put-text-property s (1- (point)) 'org-today t))
  2897. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2898. (put-text-property s (1- (point)) 'day d)))))
  2899. (goto-char (point-min))
  2900. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2901. (point-min)))
  2902. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2903. (org-finalize-agenda)
  2904. (setq buffer-read-only t)))
  2905. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2906. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2907. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2908. not every single day in the range. If FORCE-TODAY is non-nil, make
  2909. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2910. inactive time stamps (those in square brackets) are included.
  2911. When EMPTY is non-nil, also include days without any entries."
  2912. (let ((re (concat
  2913. (if pre-re pre-re "")
  2914. (if inactive org-ts-regexp-both org-ts-regexp)))
  2915. dates dates1 date day day1 day2 ts1 ts2)
  2916. (if force-today
  2917. (setq dates (list (time-to-days (current-time)))))
  2918. (save-excursion
  2919. (goto-char beg)
  2920. (while (re-search-forward re end t)
  2921. (setq day (time-to-days (org-time-string-to-time
  2922. (substring (match-string 1) 0 10))))
  2923. (or (memq day dates) (push day dates)))
  2924. (unless no-ranges
  2925. (goto-char beg)
  2926. (while (re-search-forward org-tr-regexp end t)
  2927. (setq ts1 (substring (match-string 1) 0 10)
  2928. ts2 (substring (match-string 2) 0 10)
  2929. day1 (time-to-days (org-time-string-to-time ts1))
  2930. day2 (time-to-days (org-time-string-to-time ts2)))
  2931. (while (< (setq day1 (1+ day1)) day2)
  2932. (or (memq day1 dates) (push day1 dates)))))
  2933. (setq dates (sort dates '<))
  2934. (when empty
  2935. (while (setq day (pop dates))
  2936. (setq day2 (car dates))
  2937. (push day dates1)
  2938. (when (and day2 empty)
  2939. (if (or (eq empty t)
  2940. (and (numberp empty) (<= (- day2 day) empty)))
  2941. (while (< (setq day (1+ day)) day2)
  2942. (push (list day) dates1))
  2943. (push (cons :omitted (- day2 day)) dates1))))
  2944. (setq dates (nreverse dates1)))
  2945. dates)))
  2946. ;;; Agenda Daily/Weekly
  2947. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2948. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2949. "Custom commands can set this variable in the options section.")
  2950. (defvar org-agenda-last-arguments nil
  2951. "The arguments of the previous call to `org-agenda'.")
  2952. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2953. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2954. (defvar org-include-all-loc nil) ; local variable
  2955. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2956. "List of types searched for when creating the daily/weekly agenda.
  2957. This variable is a list of symbols that controls the types of
  2958. items that appear in the daily/weekly agenda. Allowed symbols in this
  2959. list are are
  2960. :timestamp List items containing a date stamp or date range matching
  2961. the selected date. This includes sexp entries in
  2962. angular brackets.
  2963. :sexp List entries resulting from plain diary-like sexps.
  2964. :deadline List deadline due on that date. When the date is today,
  2965. also list any deadlines past due, or due within
  2966. `org-deadline-warning-days'. `:deadline' must appear before
  2967. `:scheduled' if the setting of
  2968. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2969. any effect.
  2970. :scheduled List all items which are scheduled for the given date.
  2971. The diary for *today* also contains items which were
  2972. scheduled earlier and are not yet marked DONE.
  2973. By default, all four types are turned on.
  2974. Never set this variable globally using `setq', because then it
  2975. will apply to all future agenda commands. Instead, bind it with
  2976. `let' to scope it dynamically into the the agenda-constructing
  2977. command. A good way to set it is through options in
  2978. `org-agenda-custom-commands'. For a more flexible (though
  2979. somewhat less efficient) way of determining what is included in
  2980. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2981. ;;;###autoload
  2982. (defun org-agenda-list (&optional include-all start-day ndays)
  2983. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2984. The view will be for the current day or week, but from the overview buffer
  2985. you will be able to go to other days/weeks.
  2986. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2987. all unfinished TODO items will also be shown, before the agenda.
  2988. This feature is considered obsolete, please use the TODO list or a block
  2989. agenda instead.
  2990. With a numeric prefix argument in an interactive call, the agenda will
  2991. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2992. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2993. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2994. given in `org-agenda-start-on-weekday'."
  2995. (interactive "P")
  2996. (if (and (integerp include-all) (> include-all 0))
  2997. (setq ndays include-all include-all nil))
  2998. (setq ndays (or ndays org-agenda-ndays)
  2999. start-day (or start-day org-agenda-start-day))
  3000. (if org-agenda-overriding-arguments
  3001. (setq include-all (car org-agenda-overriding-arguments)
  3002. start-day (nth 1 org-agenda-overriding-arguments)
  3003. ndays (nth 2 org-agenda-overriding-arguments)))
  3004. (if (stringp start-day)
  3005. ;; Convert to an absolute day number
  3006. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3007. (setq org-agenda-last-arguments (list include-all start-day ndays))
  3008. (org-compile-prefix-format 'agenda)
  3009. (org-set-sorting-strategy 'agenda)
  3010. (let* ((org-agenda-start-on-weekday
  3011. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  3012. org-agenda-start-on-weekday nil))
  3013. (thefiles (org-agenda-files nil 'ifmode))
  3014. (files thefiles)
  3015. (today (time-to-days
  3016. (time-subtract (current-time)
  3017. (list 0 (* 3600 org-extend-today-until) 0))))
  3018. (sd (or start-day today))
  3019. (start (if (or (null org-agenda-start-on-weekday)
  3020. (< org-agenda-ndays 7))
  3021. sd
  3022. (let* ((nt (calendar-day-of-week
  3023. (calendar-gregorian-from-absolute sd)))
  3024. (n1 org-agenda-start-on-weekday)
  3025. (d (- nt n1)))
  3026. (- sd (+ (if (< d 0) 7 0) d)))))
  3027. (day-numbers (list start))
  3028. (day-cnt 0)
  3029. (inhibit-redisplay (not debug-on-error))
  3030. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  3031. clocktable-start clocktable-end filter)
  3032. (setq org-agenda-redo-command
  3033. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3034. ;; Make the list of days
  3035. (setq ndays (or ndays org-agenda-ndays)
  3036. nd ndays)
  3037. (while (> ndays 1)
  3038. (push (1+ (car day-numbers)) day-numbers)
  3039. (setq ndays (1- ndays)))
  3040. (setq day-numbers (nreverse day-numbers))
  3041. (setq clocktable-start (car day-numbers)
  3042. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3043. (org-prepare-agenda "Day/Week")
  3044. (org-set-local 'org-starting-day (car day-numbers))
  3045. (org-set-local 'org-include-all-loc include-all)
  3046. (org-set-local 'org-agenda-span
  3047. (org-agenda-ndays-to-span nd))
  3048. (when (and (or include-all org-agenda-include-all-todo)
  3049. (member today day-numbers))
  3050. (setq files thefiles
  3051. rtnall nil)
  3052. (while (setq file (pop files))
  3053. (catch 'nextfile
  3054. (org-check-agenda-file file)
  3055. (setq date (calendar-gregorian-from-absolute today)
  3056. rtn (org-agenda-get-day-entries
  3057. file date :todo))
  3058. (setq rtnall (append rtnall rtn))))
  3059. (when rtnall
  3060. (insert "All currently open TODO items:\n")
  3061. (add-text-properties (point-min) (1- (point))
  3062. (list 'face 'org-agenda-structure
  3063. 'short-heading "All TODO items"))
  3064. (org-agenda-mark-header-line (point-min))
  3065. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3066. (unless org-agenda-compact-blocks
  3067. (let* ((d1 (car day-numbers))
  3068. (d2 (org-last day-numbers))
  3069. (w1 (org-days-to-iso-week d1))
  3070. (w2 (org-days-to-iso-week d2)))
  3071. (setq s (point))
  3072. (if org-agenda-overriding-header
  3073. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3074. nil 'face 'org-agenda-structure) "\n")
  3075. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3076. "-agenda"
  3077. (if (< (- d2 d1) 350)
  3078. (if (= w1 w2)
  3079. (format " (W%02d)" w1)
  3080. (format " (W%02d-W%02d)" w1 w2))
  3081. "")
  3082. ":\n")))
  3083. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3084. 'org-date-line t))
  3085. (org-agenda-mark-header-line s))
  3086. (while (setq d (pop day-numbers))
  3087. (setq date (calendar-gregorian-from-absolute d)
  3088. wd (calendar-day-of-week date)
  3089. s (point))
  3090. (if (or (setq todayp (= d today))
  3091. (and (not start-pos) (= d sd)))
  3092. (setq start-pos (point))
  3093. (if (and start-pos (not end-pos))
  3094. (setq end-pos (point))))
  3095. (setq files thefiles
  3096. rtnall nil)
  3097. (while (setq file (pop files))
  3098. (catch 'nextfile
  3099. (org-check-agenda-file file)
  3100. (let ((org-agenda-entry-types org-agenda-entry-types))
  3101. (unless org-agenda-include-deadlines
  3102. (setq org-agenda-entry-types
  3103. (delq :deadline org-agenda-entry-types)))
  3104. (cond
  3105. ((eq org-agenda-show-log 'only)
  3106. (setq rtn (org-agenda-get-day-entries
  3107. file date :closed)))
  3108. (org-agenda-show-log
  3109. (setq rtn (apply 'org-agenda-get-day-entries
  3110. file date
  3111. (append '(:closed) org-agenda-entry-types))))
  3112. (t
  3113. (setq rtn (apply 'org-agenda-get-day-entries
  3114. file date
  3115. org-agenda-entry-types)))))
  3116. (setq rtnall (append rtnall rtn))))
  3117. (if org-agenda-include-diary
  3118. (let ((org-agenda-search-headline-for-time t))
  3119. (require 'diary-lib)
  3120. (setq rtn (org-get-entries-from-diary date))
  3121. (setq rtnall (append rtnall rtn))))
  3122. (if (or rtnall org-agenda-show-all-dates)
  3123. (progn
  3124. (setq day-cnt (1+ day-cnt))
  3125. (insert
  3126. (if (stringp org-agenda-format-date)
  3127. (format-time-string org-agenda-format-date
  3128. (org-time-from-absolute date))
  3129. (funcall org-agenda-format-date date))
  3130. "\n")
  3131. (put-text-property s (1- (point)) 'face
  3132. (if (member wd org-agenda-weekend-days)
  3133. 'org-agenda-date-weekend
  3134. 'org-agenda-date))
  3135. (put-text-property s (1- (point)) 'org-date-line t)
  3136. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3137. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3138. (when todayp
  3139. (put-text-property s (1- (point)) 'org-today t)
  3140. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3141. (if rtnall (insert
  3142. (org-finalize-agenda-entries
  3143. (org-agenda-add-time-grid-maybe
  3144. rtnall nd todayp))
  3145. "\n"))
  3146. (put-text-property s (1- (point)) 'day d)
  3147. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3148. (when (and org-agenda-clockreport-mode clocktable-start)
  3149. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3150. ;; the above line is to ensure the restricted range!
  3151. (p org-agenda-clockreport-parameter-plist)
  3152. tbl)
  3153. (setq p (org-plist-delete p :block))
  3154. (setq p (plist-put p :tstart clocktable-start))
  3155. (setq p (plist-put p :tend clocktable-end))
  3156. (setq p (plist-put p :scope 'agenda))
  3157. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3158. (setq filter (or org-agenda-filter-while-redo
  3159. (get 'org-agenda-filter :preset-filter))))
  3160. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3161. (if (string-match "[<>=]" x)
  3162. ""
  3163. x))
  3164. filter ""))))
  3165. (message "%s" (plist-get p :tags)) (sit-for 2)
  3166. (setq tbl (apply 'org-get-clocktable p))
  3167. (insert tbl)))
  3168. (goto-char (point-min))
  3169. (or org-agenda-multi (org-fit-agenda-window))
  3170. (unless (and (pos-visible-in-window-p (point-min))
  3171. (pos-visible-in-window-p (point-max)))
  3172. (goto-char (1- (point-max)))
  3173. (recenter -1)
  3174. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3175. (progn
  3176. (goto-char (or start-pos 1))
  3177. (recenter 1))))
  3178. (goto-char (or start-pos 1))
  3179. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3180. (org-finalize-agenda)
  3181. (setq buffer-read-only t)
  3182. (message "")))
  3183. (defun org-agenda-ndays-to-span (n)
  3184. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3185. ;;; Agenda word search
  3186. (defvar org-agenda-search-history nil)
  3187. (defvar org-todo-only nil)
  3188. (defvar org-search-syntax-table nil
  3189. "Special syntax table for org-mode search.
  3190. In this table, we have single quotes not as word constituents, to
  3191. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3192. (defun org-search-syntax-table ()
  3193. (unless org-search-syntax-table
  3194. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3195. (modify-syntax-entry ?' "." org-search-syntax-table)
  3196. (modify-syntax-entry ?` "." org-search-syntax-table))
  3197. org-search-syntax-table)
  3198. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3199. ;;;###autoload
  3200. (defun org-search-view (&optional todo-only string edit-at)
  3201. "Show all entries that contain a phrase or words or regular expressions.
  3202. With optional prefix argument TODO-ONLY, only consider entries that are
  3203. TODO entries. The argument STRING can be used to pass a default search
  3204. string into this function. If EDIT-AT is non-nil, it means that the
  3205. user should get a chance to edit this string, with cursor at position
  3206. EDIT-AT.
  3207. The search string can be viewed either as a phrase that should be found as
  3208. is, or it can be broken into a number of snippets, each of which must match
  3209. in a Boolean way to select an entry. The default depends on the variable
  3210. `org-agenda-search-view-always-boolean'.
  3211. Even if this is turned off (the default) you can always switch to
  3212. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3213. The default is a direct search of the whole phrase, where each space in
  3214. the search string can expand to an arbitrary amount of whitespace,
  3215. including newlines.
  3216. If using a Boolean search, the search string is split on whitespace and
  3217. each snippet is searched separately, with logical AND to select an entry.
  3218. Words prefixed with a minus must *not* occur in the entry. Words without
  3219. a prefix or prefixed with a plus must occur in the entry. Matching is
  3220. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3221. match whole words, not parts of a word) if
  3222. `org-agenda-search-view-force-full-words' is set (default is nil).
  3223. Boolean search snippets enclosed by curly braces are interpreted as
  3224. regular expressions that must or (when preceded with \"-\") must not
  3225. match in the entry. Snippets enclosed into double quotes will be taken
  3226. as a whole, to include whitespace.
  3227. - If the search string starts with an asterisk, search only in headlines.
  3228. - If (possibly after the leading star) the search string starts with an
  3229. exclamation mark, this also means to look at TODO entries only, an effect
  3230. that can also be achieved with a prefix argument.
  3231. - If (possibly after star and exclamation mark) the search string starts
  3232. with a colon, this will mean that the (non-regexp) snippets of the
  3233. Boolean search must match as full words.
  3234. This command searches the agenda files, and in addition the files listed
  3235. in `org-agenda-text-search-extra-files'."
  3236. (interactive "P")
  3237. (org-compile-prefix-format 'search)
  3238. (org-set-sorting-strategy 'search)
  3239. (org-prepare-agenda "SEARCH")
  3240. (let* ((props (list 'face nil
  3241. 'done-face 'org-agenda-done
  3242. 'org-not-done-regexp org-not-done-regexp
  3243. 'org-todo-regexp org-todo-regexp
  3244. 'org-complex-heading-regexp org-complex-heading-regexp
  3245. 'mouse-face 'highlight
  3246. 'help-echo (format "mouse-2 or RET jump to location")))
  3247. (full-words org-agenda-search-view-force-full-words)
  3248. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3249. regexp rtn rtnall files file pos
  3250. marker category tags c neg re boolean
  3251. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3252. (unless (and (not edit-at)
  3253. (stringp string)
  3254. (string-match "\\S-" string))
  3255. (setq string (read-string
  3256. (if org-agenda-search-view-always-boolean
  3257. "[+-]Word/{Regexp} ...: "
  3258. "Phrase, or [+-]Word/{Regexp} ...: ")
  3259. (cond
  3260. ((integerp edit-at) (cons string edit-at))
  3261. (edit-at string))
  3262. 'org-agenda-search-history)))
  3263. (org-set-local 'org-todo-only todo-only)
  3264. (setq org-agenda-redo-command
  3265. (list 'org-search-view (if todo-only t nil) string
  3266. '(if current-prefix-arg 1 nil)))
  3267. (setq org-agenda-query-string string)
  3268. (if (equal (string-to-char string) ?*)
  3269. (setq hdl-only t
  3270. words (substring string 1))
  3271. (setq words string))
  3272. (when (equal (string-to-char words) ?!)
  3273. (setq todo-only t
  3274. words (substring words 1)))
  3275. (when (equal (string-to-char words) ?:)
  3276. (setq full-words t
  3277. words (substring words 1)))
  3278. (if (or org-agenda-search-view-always-boolean
  3279. (member (string-to-char words) '(?- ?+ ?\{)))
  3280. (setq boolean t))
  3281. (setq words (org-split-string words))
  3282. (let (www w)
  3283. (while (setq w (pop words))
  3284. (while (and (string-match "\\\\\\'" w) words)
  3285. (setq w (concat (substring w 0 -1) " " (pop words))))
  3286. (push w www))
  3287. (setq words (nreverse www) www nil)
  3288. (while (setq w (pop words))
  3289. (when (and (string-match "\\`[-+]?{" w)
  3290. (not (string-match "}\\'" w)))
  3291. (while (and words (not (string-match "}\\'" (car words))))
  3292. (setq w (concat w " " (pop words))))
  3293. (setq w (concat w " " (pop words))))
  3294. (push w www))
  3295. (setq words (nreverse www)))
  3296. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3297. (when boolean
  3298. (let (wds w)
  3299. (while (setq w (pop words))
  3300. (if (or (equal (substring w 0 1) "\"")
  3301. (and (> (length w) 1)
  3302. (member (substring w 0 1) '("+" "-"))
  3303. (equal (substring w 1 2) "\"")))
  3304. (while (and words (not (equal (substring w -1) "\"")))
  3305. (setq w (concat w " " (pop words)))))
  3306. (and (string-match "\\`\\([-+]?\\)\"" w)
  3307. (setq w (replace-match "\\1" nil nil w)))
  3308. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3309. (push w wds))
  3310. (setq words (nreverse wds))))
  3311. (if boolean
  3312. (mapc (lambda (w)
  3313. (setq c (string-to-char w))
  3314. (if (equal c ?-)
  3315. (setq neg t w (substring w 1))
  3316. (if (equal c ?+)
  3317. (setq neg nil w (substring w 1))
  3318. (setq neg nil)))
  3319. (if (string-match "\\`{.*}\\'" w)
  3320. (setq re (substring w 1 -1))
  3321. (if full-words
  3322. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3323. (setq re (regexp-quote (downcase w)))))
  3324. (if neg (push re regexps-) (push re regexps+)))
  3325. words)
  3326. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3327. regexps+))
  3328. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3329. (if (not regexps+)
  3330. (setq regexp (concat "^" org-outline-regexp))
  3331. (setq regexp (pop regexps+))
  3332. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3333. regexp))))
  3334. (setq files (org-agenda-files nil 'ifmode))
  3335. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3336. (pop org-agenda-text-search-extra-files)
  3337. (setq files (org-add-archive-files files)))
  3338. (setq files (append files org-agenda-text-search-extra-files)
  3339. rtnall nil)
  3340. (while (setq file (pop files))
  3341. (setq ee nil)
  3342. (catch 'nextfile
  3343. (org-check-agenda-file file)
  3344. (setq buffer (if (file-exists-p file)
  3345. (org-get-agenda-file-buffer file)
  3346. (error "No such file %s" file)))
  3347. (if (not buffer)
  3348. ;; If file does not exist, make sure an error message is sent
  3349. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3350. file))))
  3351. (with-current-buffer buffer
  3352. (with-syntax-table (org-search-syntax-table)
  3353. (unless (org-mode-p)
  3354. (error "Agenda file %s is not in `org-mode'" file))
  3355. (let ((case-fold-search t))
  3356. (save-excursion
  3357. (save-restriction
  3358. (if org-agenda-restrict
  3359. (narrow-to-region org-agenda-restrict-begin
  3360. org-agenda-restrict-end)
  3361. (widen))
  3362. (goto-char (point-min))
  3363. (unless (or (org-on-heading-p)
  3364. (outline-next-heading))
  3365. (throw 'nextfile t))
  3366. (goto-char (max (point-min) (1- (point))))
  3367. (while (re-search-forward regexp nil t)
  3368. (org-back-to-heading t)
  3369. (skip-chars-forward "* ")
  3370. (setq beg (point-at-bol)
  3371. beg1 (point)
  3372. end (progn (outline-next-heading) (point)))
  3373. (catch :skip
  3374. (goto-char beg)
  3375. (org-agenda-skip)
  3376. (setq str (buffer-substring-no-properties
  3377. (point-at-bol)
  3378. (if hdl-only (point-at-eol) end)))
  3379. (mapc (lambda (wr) (when (string-match wr str)
  3380. (goto-char (1- end))
  3381. (throw :skip t)))
  3382. regexps-)
  3383. (mapc (lambda (wr) (unless (string-match wr str)
  3384. (goto-char (1- end))
  3385. (throw :skip t)))
  3386. (if todo-only
  3387. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3388. regexps+)
  3389. regexps+))
  3390. (goto-char beg)
  3391. (setq marker (org-agenda-new-marker (point))
  3392. category (org-get-category)
  3393. tags (org-get-tags-at (point))
  3394. txt (org-format-agenda-item
  3395. ""
  3396. (buffer-substring-no-properties
  3397. beg1 (point-at-eol))
  3398. category tags))
  3399. (org-add-props txt props
  3400. 'org-marker marker 'org-hd-marker marker
  3401. 'org-todo-regexp org-todo-regexp
  3402. 'org-complex-heading-regexp org-complex-heading-regexp
  3403. 'priority 1000 'org-category category
  3404. 'type "search")
  3405. (push txt ee)
  3406. (goto-char (1- end))))))))))
  3407. (setq rtn (nreverse ee))
  3408. (setq rtnall (append rtnall rtn)))
  3409. (if org-agenda-overriding-header
  3410. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3411. nil 'face 'org-agenda-structure) "\n")
  3412. (insert "Search words: ")
  3413. (add-text-properties (point-min) (1- (point))
  3414. (list 'face 'org-agenda-structure))
  3415. (setq pos (point))
  3416. (insert string "\n")
  3417. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3418. (setq pos (point))
  3419. (unless org-agenda-multi
  3420. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3421. (add-text-properties pos (1- (point))
  3422. (list 'face 'org-agenda-structure))))
  3423. (org-agenda-mark-header-line (point-min))
  3424. (when rtnall
  3425. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3426. (goto-char (point-min))
  3427. (or org-agenda-multi (org-fit-agenda-window))
  3428. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3429. (org-finalize-agenda)
  3430. (setq buffer-read-only t)))
  3431. ;;; Agenda TODO list
  3432. (defvar org-select-this-todo-keyword nil)
  3433. (defvar org-last-arg nil)
  3434. ;;;###autoload
  3435. (defun org-todo-list (arg)
  3436. "Show all (not done) TODO entries from all agenda file in a single list.
  3437. The prefix arg can be used to select a specific TODO keyword and limit
  3438. the list to these. When using \\[universal-argument], you will be prompted
  3439. for a keyword. A numeric prefix directly selects the Nth keyword in
  3440. `org-todo-keywords-1'."
  3441. (interactive "P")
  3442. (org-compile-prefix-format 'todo)
  3443. (org-set-sorting-strategy 'todo)
  3444. (org-prepare-agenda "TODO")
  3445. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3446. (let* ((today (time-to-days (current-time)))
  3447. (date (calendar-gregorian-from-absolute today))
  3448. (kwds org-todo-keywords-for-agenda)
  3449. (completion-ignore-case t)
  3450. (org-select-this-todo-keyword
  3451. (if (stringp arg) arg
  3452. (and arg (integerp arg) (> arg 0)
  3453. (nth (1- arg) kwds))))
  3454. rtn rtnall files file pos)
  3455. (when (equal arg '(4))
  3456. (setq org-select-this-todo-keyword
  3457. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3458. (mapcar 'list kwds) nil nil)))
  3459. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3460. (org-set-local 'org-last-arg arg)
  3461. (setq org-agenda-redo-command
  3462. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3463. (setq files (org-agenda-files nil 'ifmode)
  3464. rtnall nil)
  3465. (while (setq file (pop files))
  3466. (catch 'nextfile
  3467. (org-check-agenda-file file)
  3468. (setq rtn (org-agenda-get-day-entries file date :todo))
  3469. (setq rtnall (append rtnall rtn))))
  3470. (if org-agenda-overriding-header
  3471. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3472. nil 'face 'org-agenda-structure) "\n")
  3473. (insert "Global list of TODO items of type: ")
  3474. (add-text-properties (point-min) (1- (point))
  3475. (list 'face 'org-agenda-structure
  3476. 'short-heading
  3477. (concat "ToDo: "
  3478. (or org-select-this-todo-keyword "ALL"))))
  3479. (org-agenda-mark-header-line (point-min))
  3480. (setq pos (point))
  3481. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3482. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3483. (setq pos (point))
  3484. (unless org-agenda-multi
  3485. (insert "Available with `N r': (0)ALL")
  3486. (let ((n 0) s)
  3487. (mapc (lambda (x)
  3488. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3489. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3490. (insert "\n "))
  3491. (insert " " s))
  3492. kwds))
  3493. (insert "\n"))
  3494. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3495. (org-agenda-mark-header-line (point-min))
  3496. (when rtnall
  3497. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3498. (goto-char (point-min))
  3499. (or org-agenda-multi (org-fit-agenda-window))
  3500. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3501. (org-finalize-agenda)
  3502. (setq buffer-read-only t)))
  3503. ;;; Agenda tags match
  3504. ;;;###autoload
  3505. (defun org-tags-view (&optional todo-only match)
  3506. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3507. The prefix arg TODO-ONLY limits the search to TODO entries."
  3508. (interactive "P")
  3509. (org-compile-prefix-format 'tags)
  3510. (org-set-sorting-strategy 'tags)
  3511. (let* ((org-tags-match-list-sublevels
  3512. org-tags-match-list-sublevels)
  3513. (completion-ignore-case t)
  3514. rtn rtnall files file pos matcher
  3515. buffer)
  3516. (when (and (stringp match) (not (string-match "\\S-" match)))
  3517. (setq match nil))
  3518. (setq matcher (org-make-tags-matcher match)
  3519. match (car matcher) matcher (cdr matcher))
  3520. (org-prepare-agenda (concat "TAGS " match))
  3521. (setq org-agenda-query-string match)
  3522. (setq org-agenda-redo-command
  3523. (list 'org-tags-view (list 'quote todo-only)
  3524. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3525. (setq files (org-agenda-files nil 'ifmode)
  3526. rtnall nil)
  3527. (while (setq file (pop files))
  3528. (catch 'nextfile
  3529. (org-check-agenda-file file)
  3530. (setq buffer (if (file-exists-p file)
  3531. (org-get-agenda-file-buffer file)
  3532. (error "No such file %s" file)))
  3533. (if (not buffer)
  3534. ;; If file does not exist, error message to agenda
  3535. (setq rtn (list
  3536. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3537. rtnall (append rtnall rtn))
  3538. (with-current-buffer buffer
  3539. (unless (org-mode-p)
  3540. (error "Agenda file %s is not in `org-mode'" file))
  3541. (save-excursion
  3542. (save-restriction
  3543. (if org-agenda-restrict
  3544. (narrow-to-region org-agenda-restrict-begin
  3545. org-agenda-restrict-end)
  3546. (widen))
  3547. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3548. (setq rtnall (append rtnall rtn))))))))
  3549. (if org-agenda-overriding-header
  3550. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3551. nil 'face 'org-agenda-structure) "\n")
  3552. (insert "Headlines with TAGS match: ")
  3553. (add-text-properties (point-min) (1- (point))
  3554. (list 'face 'org-agenda-structure
  3555. 'short-heading
  3556. (concat "Match: " match)))
  3557. (setq pos (point))
  3558. (insert match "\n")
  3559. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3560. (setq pos (point))
  3561. (unless org-agenda-multi
  3562. (insert "Press `C-u r' to search again with new search string\n"))
  3563. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3564. (org-agenda-mark-header-line (point-min))
  3565. (when rtnall
  3566. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3567. (goto-char (point-min))
  3568. (or org-agenda-multi (org-fit-agenda-window))
  3569. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3570. (org-finalize-agenda)
  3571. (setq buffer-read-only t)))
  3572. ;;; Agenda Finding stuck projects
  3573. (defvar org-agenda-skip-regexp nil
  3574. "Regular expression used in skipping subtrees for the agenda.
  3575. This is basically a temporary global variable that can be set and then
  3576. used by user-defined selections using `org-agenda-skip-function'.")
  3577. (defvar org-agenda-overriding-header nil
  3578. "When this is set during todo and tags searches, will replace header.
  3579. This variable should not be set directly, but custom commands can bind it
  3580. in the options section.")
  3581. (defun org-agenda-skip-entry-when-regexp-matches ()
  3582. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3583. If yes, it returns the end position of this entry, causing agenda commands
  3584. to skip the entry but continuing the search in the subtree. This is a
  3585. function that can be put into `org-agenda-skip-function' for the duration
  3586. 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-subtree-when-regexp-matches ()
  3593. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3594. If yes, it returns the end position of this tree, causing agenda commands
  3595. to skip this subtree. This is a function that can be put into
  3596. `org-agenda-skip-function' for the duration of a command."
  3597. (let ((end (save-excursion (org-end-of-subtree t)))
  3598. skip)
  3599. (save-excursion
  3600. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3601. (and skip end)))
  3602. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3603. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3604. If yes, it returns the end position of the current entry (NOT the tree),
  3605. causing agenda commands to skip the entry but continuing the search in
  3606. the subtree. This is a function that can be put into
  3607. `org-agenda-skip-function' for the duration of a command. An important
  3608. use of this function is for the stuck project list."
  3609. (let ((end (save-excursion (org-end-of-subtree t)))
  3610. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3611. skip)
  3612. (save-excursion
  3613. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3614. (and skip entry-end)))
  3615. (defun org-agenda-skip-entry-if (&rest conditions)
  3616. "Skip entry if any of CONDITIONS is true.
  3617. See `org-agenda-skip-if' for details."
  3618. (org-agenda-skip-if nil conditions))
  3619. (defun org-agenda-skip-subtree-if (&rest conditions)
  3620. "Skip entry if any of CONDITIONS is true.
  3621. See `org-agenda-skip-if' for details."
  3622. (org-agenda-skip-if t conditions))
  3623. (defun org-agenda-skip-if (subtree conditions)
  3624. "Checks current entity for CONDITIONS.
  3625. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3626. the entry, i.e. the text before the next heading is checked.
  3627. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3628. from different tests. Valid conditions are:
  3629. scheduled Check if there is a scheduled cookie
  3630. notscheduled Check if there is no scheduled cookie
  3631. deadline Check if there is a deadline
  3632. notdeadline Check if there is no deadline
  3633. timestamp Check if there is a timestamp (also deadline or scheduled)
  3634. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3635. regexp Check if regexp matches
  3636. notregexp Check if regexp does not match.
  3637. todo Check if TODO keyword matches
  3638. nottodo Check if TODO keyword does not match
  3639. The regexp is taken from the conditions list, it must come right after
  3640. the `regexp' or `notregexp' element.
  3641. `todo' and `nottodo' accept as an argument a list of todo
  3642. keywords, which may include \"*\" to match any todo keyword.
  3643. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3644. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3645. Instead of a list a keyword class may be given
  3646. (org-agenda-skip-entry-if 'nottodo 'done)
  3647. would skip entries that haven't been marked with any of \"DONE\"
  3648. keywords. Possible classes are: `todo', `done', `any'.
  3649. If any of these conditions is met, this function returns the end point of
  3650. the entity, causing the search to continue from there. This is a function
  3651. that can be put into `org-agenda-skip-function' for the duration of a command."
  3652. (let (beg end m)
  3653. (org-back-to-heading t)
  3654. (setq beg (point)
  3655. end (if subtree
  3656. (progn (org-end-of-subtree t) (point))
  3657. (progn (outline-next-heading) (1- (point)))))
  3658. (goto-char beg)
  3659. (and
  3660. (or
  3661. (and (memq 'scheduled conditions)
  3662. (re-search-forward org-scheduled-time-regexp end t))
  3663. (and (memq 'notscheduled conditions)
  3664. (not (re-search-forward org-scheduled-time-regexp end t)))
  3665. (and (memq 'deadline conditions)
  3666. (re-search-forward org-deadline-time-regexp end t))
  3667. (and (memq 'notdeadline conditions)
  3668. (not (re-search-forward org-deadline-time-regexp end t)))
  3669. (and (memq 'timestamp conditions)
  3670. (re-search-forward org-ts-regexp end t))
  3671. (and (memq 'nottimestamp conditions)
  3672. (not (re-search-forward org-ts-regexp end t)))
  3673. (and (setq m (memq 'regexp conditions))
  3674. (stringp (nth 1 m))
  3675. (re-search-forward (nth 1 m) end t))
  3676. (and (setq m (memq 'notregexp conditions))
  3677. (stringp (nth 1 m))
  3678. (not (re-search-forward (nth 1 m) end t)))
  3679. (and (or
  3680. (setq m (memq 'todo conditions))
  3681. (setq m (memq 'nottodo conditions)))
  3682. (org-agenda-skip-if-todo m end)))
  3683. end)))
  3684. (defun org-agenda-skip-if-todo (args end)
  3685. "Helper function for `org-agenda-skip-if', do not use it directly.
  3686. ARGS is a list with first element either `todo' or `nottodo'.
  3687. The remainder is either a list of TODO keywords, or a state symbol
  3688. `todo' or `done' or `any'."
  3689. (let ((kw (car args))
  3690. (arg (cadr args))
  3691. todo-wds todo-re)
  3692. (setq todo-wds
  3693. (org-uniquify
  3694. (cond
  3695. ((listp arg) ;; list of keywords
  3696. (if (member "*" arg)
  3697. (mapcar 'substring-no-properties org-todo-keywords-1)
  3698. arg))
  3699. ((symbolp arg) ;; keyword class name
  3700. (cond
  3701. ((eq arg 'todo)
  3702. (org-delete-all org-done-keywords
  3703. (mapcar 'substring-no-properties
  3704. org-todo-keywords-1)))
  3705. ((eq arg 'done) org-done-keywords)
  3706. ((eq arg 'any)
  3707. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3708. (setq todo-re
  3709. (concat "^\\*+[ \t]+\\<\\("
  3710. (mapconcat 'identity todo-wds "\\|")
  3711. "\\)\\>"))
  3712. (if (eq kw 'todo)
  3713. (re-search-forward todo-re end t)
  3714. (not (re-search-forward todo-re end t)))))
  3715. ;;;###autoload
  3716. (defun org-agenda-list-stuck-projects (&rest ignore)
  3717. "Create agenda view for projects that are stuck.
  3718. Stuck projects are project that have no next actions. For the definitions
  3719. of what a project is and how to check if it stuck, customize the variable
  3720. `org-stuck-projects'."
  3721. (interactive)
  3722. (let* ((org-agenda-skip-function
  3723. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3724. ;; We could have used org-agenda-skip-if here.
  3725. (org-agenda-overriding-header
  3726. (or org-agenda-overriding-header "List of stuck projects: "))
  3727. (matcher (nth 0 org-stuck-projects))
  3728. (todo (nth 1 org-stuck-projects))
  3729. (todo-wds (if (member "*" todo)
  3730. (progn
  3731. (org-prepare-agenda-buffers (org-agenda-files
  3732. nil 'ifmode))
  3733. (org-delete-all
  3734. org-done-keywords-for-agenda
  3735. (copy-sequence org-todo-keywords-for-agenda)))
  3736. todo))
  3737. (todo-re (concat "^\\*+[ \t]+\\("
  3738. (mapconcat 'identity todo-wds "\\|")
  3739. "\\)\\>"))
  3740. (tags (nth 2 org-stuck-projects))
  3741. (tags-re (if (member "*" tags)
  3742. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3743. (if tags
  3744. (concat "^\\*+ .*:\\("
  3745. (mapconcat 'identity tags "\\|")
  3746. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3747. (gen-re (nth 3 org-stuck-projects))
  3748. (re-list
  3749. (delq nil
  3750. (list
  3751. (if todo todo-re)
  3752. (if tags tags-re)
  3753. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3754. gen-re)))))
  3755. (setq org-agenda-skip-regexp
  3756. (if re-list
  3757. (mapconcat 'identity re-list "\\|")
  3758. (error "No information how to identify unstuck projects")))
  3759. (org-tags-view nil matcher)
  3760. (with-current-buffer org-agenda-buffer-name
  3761. (setq org-agenda-redo-command
  3762. '(org-agenda-list-stuck-projects
  3763. (or current-prefix-arg org-last-arg))))))
  3764. ;;; Diary integration
  3765. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3766. (defvar list-diary-entries-hook)
  3767. (defun org-get-entries-from-diary (date)
  3768. "Get the (Emacs Calendar) diary entries for DATE."
  3769. (require 'diary-lib)
  3770. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3771. (diary-display-hook '(fancy-diary-display))
  3772. (diary-display-function 'fancy-diary-display)
  3773. (pop-up-frames nil)
  3774. (list-diary-entries-hook
  3775. (cons 'org-diary-default-entry list-diary-entries-hook))
  3776. (diary-file-name-prefix-function nil) ; turn this feature off
  3777. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3778. entries
  3779. (org-disable-agenda-to-diary t))
  3780. (save-excursion
  3781. (save-window-excursion
  3782. (funcall (if (fboundp 'diary-list-entries)
  3783. 'diary-list-entries 'list-diary-entries)
  3784. date 1)))
  3785. (if (not (get-buffer diary-fancy-buffer))
  3786. (setq entries nil)
  3787. (with-current-buffer diary-fancy-buffer
  3788. (setq buffer-read-only nil)
  3789. (if (zerop (buffer-size))
  3790. ;; No entries
  3791. (setq entries nil)
  3792. ;; Omit the date and other unnecessary stuff
  3793. (org-agenda-cleanup-fancy-diary)
  3794. ;; Add prefix to each line and extend the text properties
  3795. (if (zerop (buffer-size))
  3796. (setq entries nil)
  3797. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3798. (set-buffer-modified-p nil)
  3799. (kill-buffer diary-fancy-buffer)))
  3800. (when entries
  3801. (setq entries (org-split-string entries "\n"))
  3802. (setq entries
  3803. (mapcar
  3804. (lambda (x)
  3805. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3806. ;; Extend the text properties to the beginning of the line
  3807. (org-add-props x (text-properties-at (1- (length x)) x)
  3808. 'type "diary" 'date date 'face 'org-agenda-diary))
  3809. entries)))))
  3810. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3811. "Hook run when the fancy diary buffer is cleaned up.")
  3812. (defun org-agenda-cleanup-fancy-diary ()
  3813. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3814. This gets rid of the date, the underline under the date, and
  3815. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3816. date. It also removes lines that contain only whitespace."
  3817. (goto-char (point-min))
  3818. (if (looking-at ".*?:[ \t]*")
  3819. (progn
  3820. (replace-match "")
  3821. (re-search-forward "\n=+$" nil t)
  3822. (replace-match "")
  3823. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3824. (re-search-forward "\n=+$" nil t)
  3825. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3826. (goto-char (point-min))
  3827. (while (re-search-forward "^ +\n" nil t)
  3828. (replace-match ""))
  3829. (goto-char (point-min))
  3830. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3831. (replace-match ""))
  3832. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3833. ;; Make sure entries from the diary have the right text properties.
  3834. (eval-after-load "diary-lib"
  3835. '(if (boundp 'diary-modify-entry-list-string-function)
  3836. ;; We can rely on the hook, nothing to do
  3837. nil
  3838. ;; Hook not available, must use advice to make this work
  3839. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3840. "Make the position visible."
  3841. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3842. (stringp string)
  3843. buffer-file-name)
  3844. (setq string (org-modify-diary-entry-string string))))))
  3845. (defun org-modify-diary-entry-string (string)
  3846. "Add text properties to string, allowing org-mode to act on it."
  3847. (org-add-props string nil
  3848. 'mouse-face 'highlight
  3849. 'help-echo (if buffer-file-name
  3850. (format "mouse-2 or RET jump to diary file %s"
  3851. (abbreviate-file-name buffer-file-name))
  3852. "")
  3853. 'org-agenda-diary-link t
  3854. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3855. (defun org-diary-default-entry ()
  3856. "Add a dummy entry to the diary.
  3857. Needed to avoid empty dates which mess up holiday display."
  3858. ;; Catch the error if dealing with the new add-to-diary-alist
  3859. (when org-disable-agenda-to-diary
  3860. (condition-case nil
  3861. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3862. (error
  3863. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3864. (defun org-add-to-diary-list (&rest args)
  3865. (if (fboundp 'diary-add-to-list)
  3866. (apply 'diary-add-to-list args)
  3867. (apply 'add-to-diary-list args)))
  3868. (defvar org-diary-last-run-time nil)
  3869. ;;;###autoload
  3870. (defun org-diary (&rest args)
  3871. "Return diary information from org-files.
  3872. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3873. It accesses org files and extracts information from those files to be
  3874. listed in the diary. The function accepts arguments specifying what
  3875. items should be listed. For a list of arguments allowed here, see the
  3876. variable `org-agenda-entry-types'.
  3877. The call in the diary file should look like this:
  3878. &%%(org-diary) ~/path/to/some/orgfile.org
  3879. Use a separate line for each org file to check. Or, if you omit the file name,
  3880. all files listed in `org-agenda-files' will be checked automatically:
  3881. &%%(org-diary)
  3882. If you don't give any arguments (as in the example above), the default
  3883. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3884. So the example above may also be written as
  3885. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3886. The function expects the lisp variables `entry' and `date' to be provided
  3887. by the caller, because this is how the calendar works. Don't use this
  3888. function from a program - use `org-agenda-get-day-entries' instead."
  3889. (when (> (- (org-float-time)
  3890. org-agenda-last-marker-time)
  3891. 5)
  3892. (org-agenda-reset-markers))
  3893. (org-compile-prefix-format 'agenda)
  3894. (org-set-sorting-strategy 'agenda)
  3895. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3896. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3897. (list entry)
  3898. (org-agenda-files t)))
  3899. (time (org-float-time))
  3900. file rtn results)
  3901. (when (or (not org-diary-last-run-time)
  3902. (> (- time
  3903. org-diary-last-run-time)
  3904. 3))
  3905. (org-prepare-agenda-buffers files))
  3906. (setq org-diary-last-run-time time)
  3907. ;; If this is called during org-agenda, don't return any entries to
  3908. ;; the calendar. Org Agenda will list these entries itself.
  3909. (if org-disable-agenda-to-diary (setq files nil))
  3910. (while (setq file (pop files))
  3911. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3912. (setq results (append results rtn)))
  3913. (if results
  3914. (concat (org-finalize-agenda-entries results) "\n"))))
  3915. ;;; Agenda entry finders
  3916. (defun org-agenda-get-day-entries (file date &rest args)
  3917. "Does the work for `org-diary' and `org-agenda'.
  3918. FILE is the path to a file to be checked for entries. DATE is date like
  3919. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3920. which kind of entries should be extracted. For details about these, see
  3921. the documentation of `org-diary'."
  3922. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3923. (let* ((org-startup-folded nil)
  3924. (org-startup-align-all-tables nil)
  3925. (buffer (if (file-exists-p file)
  3926. (org-get-agenda-file-buffer file)
  3927. (error "No such file %s" file)))
  3928. arg results rtn deadline-results)
  3929. (if (not buffer)
  3930. ;; If file does not exist, make sure an error message ends up in diary
  3931. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3932. (with-current-buffer buffer
  3933. (unless (org-mode-p)
  3934. (error "Agenda file %s is not in `org-mode'" file))
  3935. (let ((case-fold-search nil))
  3936. (save-excursion
  3937. (save-restriction
  3938. (if org-agenda-restrict
  3939. (narrow-to-region org-agenda-restrict-begin
  3940. org-agenda-restrict-end)
  3941. (widen))
  3942. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3943. (while (setq arg (pop args))
  3944. (cond
  3945. ((and (eq arg :todo)
  3946. (equal date (calendar-current-date)))
  3947. (setq rtn (org-agenda-get-todos))
  3948. (setq results (append results rtn)))
  3949. ((eq arg :timestamp)
  3950. (setq rtn (org-agenda-get-blocks))
  3951. (setq results (append results rtn))
  3952. (setq rtn (org-agenda-get-timestamps))
  3953. (setq results (append results rtn)))
  3954. ((eq arg :sexp)
  3955. (setq rtn (org-agenda-get-sexps))
  3956. (setq results (append results rtn)))
  3957. ((eq arg :scheduled)
  3958. (setq rtn (org-agenda-get-scheduled deadline-results))
  3959. (setq results (append results rtn)))
  3960. ((eq arg :closed)
  3961. (setq rtn (org-agenda-get-progress))
  3962. (setq results (append results rtn)))
  3963. ((eq arg :deadline)
  3964. (setq rtn (org-agenda-get-deadlines))
  3965. (setq deadline-results (copy-sequence rtn))
  3966. (setq results (append results rtn))))))))
  3967. results))))
  3968. (defun org-agenda-get-todos ()
  3969. "Return the TODO information for agenda display."
  3970. (let* ((props (list 'face nil
  3971. 'done-face 'org-agenda-done
  3972. 'org-not-done-regexp org-not-done-regexp
  3973. 'org-todo-regexp org-todo-regexp
  3974. 'org-complex-heading-regexp org-complex-heading-regexp
  3975. 'mouse-face 'highlight
  3976. 'help-echo
  3977. (format "mouse-2 or RET jump to org file %s"
  3978. (abbreviate-file-name buffer-file-name))))
  3979. (regexp (concat "^\\*+[ \t]+\\("
  3980. (if org-select-this-todo-keyword
  3981. (if (equal org-select-this-todo-keyword "*")
  3982. org-todo-regexp
  3983. (concat "\\<\\("
  3984. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3985. "\\)\\>"))
  3986. org-not-done-regexp)
  3987. "[^\n\r]*\\)"))
  3988. marker priority category tags todo-state
  3989. ee txt beg end)
  3990. (goto-char (point-min))
  3991. (while (re-search-forward regexp nil t)
  3992. (catch :skip
  3993. (save-match-data
  3994. (beginning-of-line)
  3995. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3996. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3997. (goto-char (1+ beg))
  3998. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3999. (throw :skip nil)))
  4000. (goto-char beg)
  4001. (org-agenda-skip)
  4002. (goto-char (match-beginning 1))
  4003. (setq marker (org-agenda-new-marker (match-beginning 0))
  4004. category (org-get-category)
  4005. txt (match-string 1)
  4006. tags (org-get-tags-at (point))
  4007. txt (org-format-agenda-item "" txt category tags)
  4008. priority (1+ (org-get-priority txt))
  4009. todo-state (org-get-todo-state))
  4010. (org-add-props txt props
  4011. 'org-marker marker 'org-hd-marker marker
  4012. 'priority priority 'org-category category
  4013. 'type "todo" 'todo-state todo-state)
  4014. (push txt ee)
  4015. (if org-agenda-todo-list-sublevels
  4016. (goto-char (match-end 1))
  4017. (org-end-of-subtree 'invisible))))
  4018. (nreverse ee)))
  4019. ;;;###autoload
  4020. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4021. (&optional end)
  4022. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4023. (when (or org-agenda-todo-ignore-with-date
  4024. org-agenda-todo-ignore-scheduled
  4025. org-agenda-todo-ignore-deadlines)
  4026. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4027. (save-excursion
  4028. (or (and org-agenda-todo-ignore-with-date
  4029. (re-search-forward org-ts-regexp end t))
  4030. (and org-agenda-todo-ignore-scheduled
  4031. (re-search-forward org-scheduled-time-regexp end t)
  4032. (cond
  4033. ((eq org-agenda-todo-ignore-scheduled 'future)
  4034. (> (org-days-to-time (match-string 1)) 0))
  4035. ((eq org-agenda-todo-ignore-scheduled 'past)
  4036. (<= (org-days-to-time (match-string 1)) 0))
  4037. (t)))
  4038. (and org-agenda-todo-ignore-deadlines
  4039. (re-search-forward org-deadline-time-regexp end t)
  4040. (cond
  4041. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4042. ((eq org-agenda-todo-ignore-deadlines 'far)
  4043. (not (org-deadline-close (match-string 1))))
  4044. ((eq org-agenda-todo-ignore-deadlines 'future)
  4045. (> (org-days-to-time (match-string 1)) 0))
  4046. ((eq org-agenda-todo-ignore-deadlines 'past)
  4047. (<= (org-days-to-time (match-string 1)) 0))
  4048. (t (org-deadline-close (match-string 1)))))))))
  4049. (defconst org-agenda-no-heading-message
  4050. "No heading for this item in buffer or region.")
  4051. (defun org-agenda-get-timestamps ()
  4052. "Return the date stamp information for agenda display."
  4053. (let* ((props (list 'face nil
  4054. 'org-not-done-regexp org-not-done-regexp
  4055. 'org-todo-regexp org-todo-regexp
  4056. 'org-complex-heading-regexp org-complex-heading-regexp
  4057. 'mouse-face 'highlight
  4058. 'help-echo
  4059. (format "mouse-2 or RET jump to org file %s"
  4060. (abbreviate-file-name buffer-file-name))))
  4061. (d1 (calendar-absolute-from-gregorian date))
  4062. (remove-re
  4063. (concat
  4064. (regexp-quote
  4065. (format-time-string
  4066. "<%Y-%m-%d"
  4067. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4068. ".*?>"))
  4069. (regexp
  4070. (concat
  4071. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4072. (regexp-quote
  4073. (substring
  4074. (format-time-string
  4075. (car org-time-stamp-formats)
  4076. (apply 'encode-time ; DATE bound by calendar
  4077. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4078. 1 11))
  4079. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4080. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4081. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4082. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4083. todo-state end-of-match)
  4084. (goto-char (point-min))
  4085. (while (setq end-of-match (re-search-forward regexp nil t))
  4086. (setq b0 (match-beginning 0)
  4087. b3 (match-beginning 3) e3 (match-end 3))
  4088. (catch :skip
  4089. (and (org-at-date-range-p) (throw :skip nil))
  4090. (org-agenda-skip)
  4091. (if (and (match-end 1)
  4092. (not (= d1 (org-time-string-to-absolute
  4093. (match-string 1) d1 nil
  4094. org-agenda-repeating-timestamp-show-all))))
  4095. (throw :skip nil))
  4096. (if (and e3
  4097. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4098. (throw :skip nil))
  4099. (setq tmp (buffer-substring (max (point-min)
  4100. (- b0 org-ds-keyword-length))
  4101. b0)
  4102. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4103. inactivep (= (char-after b0) ?\[)
  4104. deadlinep (string-match org-deadline-regexp tmp)
  4105. scheduledp (string-match org-scheduled-regexp tmp)
  4106. closedp (and org-agenda-include-inactive-timestamps
  4107. (string-match org-closed-string tmp))
  4108. clockp (and org-agenda-include-inactive-timestamps
  4109. (or (string-match org-clock-string tmp)
  4110. (string-match "]-+\\'" tmp)))
  4111. todo-state (ignore-errors (org-get-todo-state))
  4112. donep (member todo-state org-done-keywords))
  4113. (if (or scheduledp deadlinep closedp clockp
  4114. (and donep org-agenda-skip-timestamp-if-done))
  4115. (throw :skip t))
  4116. (if (string-match ">" timestr)
  4117. ;; substring should only run to end of time stamp
  4118. (setq timestr (substring timestr 0 (match-end 0))))
  4119. (setq marker (org-agenda-new-marker b0)
  4120. category (org-get-category b0))
  4121. (save-excursion
  4122. (if (not (re-search-backward "^\\*+ " nil t))
  4123. (setq txt org-agenda-no-heading-message)
  4124. (goto-char (match-beginning 0))
  4125. (setq hdmarker (org-agenda-new-marker)
  4126. tags (org-get-tags-at))
  4127. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4128. (setq head (match-string 1))
  4129. (setq txt (org-format-agenda-item
  4130. (if inactivep org-agenda-inactive-leader nil)
  4131. head category tags timestr nil
  4132. remove-re)))
  4133. (setq priority (org-get-priority txt))
  4134. (org-add-props txt props
  4135. 'org-marker marker 'org-hd-marker hdmarker)
  4136. (org-add-props txt nil 'priority priority
  4137. 'org-category category 'date date
  4138. 'todo-state todo-state
  4139. 'type "timestamp")
  4140. (push txt ee))
  4141. (if org-agenda-skip-additional-timestamps-same-entry
  4142. (outline-next-heading)
  4143. (goto-char end-of-match))))
  4144. (nreverse ee)))
  4145. (defun org-agenda-get-sexps ()
  4146. "Return the sexp information for agenda display."
  4147. (require 'diary-lib)
  4148. (let* ((props (list 'face nil
  4149. 'mouse-face 'highlight
  4150. 'help-echo
  4151. (format "mouse-2 or RET jump to org file %s"
  4152. (abbreviate-file-name buffer-file-name))))
  4153. (regexp "^&?%%(")
  4154. marker category ee txt tags entry result beg b sexp sexp-entry
  4155. todo-state)
  4156. (goto-char (point-min))
  4157. (while (re-search-forward regexp nil t)
  4158. (catch :skip
  4159. (org-agenda-skip)
  4160. (setq beg (match-beginning 0))
  4161. (goto-char (1- (match-end 0)))
  4162. (setq b (point))
  4163. (forward-sexp 1)
  4164. (setq sexp (buffer-substring b (point)))
  4165. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4166. (org-trim (match-string 1))
  4167. ""))
  4168. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4169. (when result
  4170. (setq marker (org-agenda-new-marker beg)
  4171. category (org-get-category beg)
  4172. todo-state (org-get-todo-state))
  4173. (dolist (r (if (stringp result)
  4174. (list result)
  4175. result)) ;; we expect a list here
  4176. (if (string-match "\\S-" r)
  4177. (setq txt r)
  4178. (setq txt "SEXP entry returned empty string"))
  4179. (setq txt (org-format-agenda-item
  4180. "" txt category tags 'time))
  4181. (org-add-props txt props 'org-marker marker)
  4182. (org-add-props txt nil
  4183. 'org-category category 'date date 'todo-state todo-state
  4184. 'type "sexp")
  4185. (push txt ee)))))
  4186. (nreverse ee)))
  4187. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4188. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4189. The order of the first 2 times 3 arguments depends on the variable
  4190. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4191. So for American calendars, give this as MONTH DAY YEAR, for European as
  4192. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4193. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4194. is any number of ISO weeks in the block period for which the item should
  4195. be skipped."
  4196. (let* ((date1 (calendar-absolute-from-gregorian
  4197. (org-order-calendar-date-args m1 d1 y1)))
  4198. (date2 (calendar-absolute-from-gregorian
  4199. (org-order-calendar-date-args m2 d2 y2)))
  4200. (d (calendar-absolute-from-gregorian date)))
  4201. (and
  4202. (<= date1 d)
  4203. (<= d date2)
  4204. (= (calendar-day-of-week date) dayname)
  4205. (or (not skip-weeks)
  4206. (progn
  4207. (require 'cal-iso)
  4208. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4209. entry)))
  4210. (defalias 'org-get-closed 'org-agenda-get-progress)
  4211. (defun org-agenda-get-progress ()
  4212. "Return the logged TODO entries for agenda display."
  4213. (let* ((props (list 'mouse-face 'highlight
  4214. 'org-not-done-regexp org-not-done-regexp
  4215. 'org-todo-regexp org-todo-regexp
  4216. 'org-complex-heading-regexp org-complex-heading-regexp
  4217. 'help-echo
  4218. (format "mouse-2 or RET jump to org file %s"
  4219. (abbreviate-file-name buffer-file-name))))
  4220. (items (if (consp org-agenda-show-log)
  4221. org-agenda-show-log
  4222. org-agenda-log-mode-items))
  4223. (parts
  4224. (delq nil
  4225. (list
  4226. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4227. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4228. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4229. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4230. (error "`org-agenda-log-mode-items' is empty")))
  4231. (regexp (concat
  4232. "\\(" parts-re "\\)"
  4233. " *\\["
  4234. (regexp-quote
  4235. (substring
  4236. (format-time-string
  4237. (car org-time-stamp-formats)
  4238. (apply 'encode-time ; DATE bound by calendar
  4239. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4240. 1 11))))
  4241. (org-agenda-search-headline-for-time nil)
  4242. marker hdmarker priority category tags closedp statep clockp state
  4243. ee txt extra timestr rest clocked)
  4244. (goto-char (point-min))
  4245. (while (re-search-forward regexp nil t)
  4246. (catch :skip
  4247. (org-agenda-skip)
  4248. (setq marker (org-agenda-new-marker (match-beginning 0))
  4249. closedp (equal (match-string 1) org-closed-string)
  4250. statep (equal (string-to-char (match-string 1)) ?-)
  4251. clockp (not (or closedp statep))
  4252. state (and statep (match-string 2))
  4253. category (org-get-category (match-beginning 0))
  4254. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4255. )
  4256. (when (string-match "\\]" timestr)
  4257. ;; substring should only run to end of time stamp
  4258. (setq rest (substring timestr (match-end 0))
  4259. timestr (substring timestr 0 (match-end 0)))
  4260. (if (and (not closedp) (not statep)
  4261. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4262. (progn (setq timestr (concat (substring timestr 0 -1)
  4263. "-" (match-string 1 rest) "]"))
  4264. (setq clocked (match-string 2 rest)))
  4265. (setq clocked "-")))
  4266. (save-excursion
  4267. (setq extra nil)
  4268. (cond
  4269. ((not org-agenda-log-mode-add-notes))
  4270. (statep
  4271. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4272. (setq extra (match-string 1))))
  4273. (clockp
  4274. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4275. (setq extra (match-string 1)))))
  4276. (if (not (re-search-backward "^\\*+ " nil t))
  4277. (setq txt org-agenda-no-heading-message)
  4278. (goto-char (match-beginning 0))
  4279. (setq hdmarker (org-agenda-new-marker)
  4280. tags (org-get-tags-at))
  4281. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4282. (setq txt (match-string 1))
  4283. (when extra
  4284. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4285. (setq txt (concat (substring txt 0 (match-beginning 1))
  4286. " - " extra " " (match-string 2 txt)))
  4287. (setq txt (concat txt " - " extra))))
  4288. (setq txt (org-format-agenda-item
  4289. (cond
  4290. (closedp "Closed: ")
  4291. (statep (concat "State: (" state ")"))
  4292. (t (concat "Clocked: (" clocked ")")))
  4293. txt category tags timestr)))
  4294. (setq priority 100000)
  4295. (org-add-props txt props
  4296. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4297. 'priority priority 'org-category category
  4298. 'type "closed" 'date date
  4299. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4300. (push txt ee))
  4301. (goto-char (point-at-eol))))
  4302. (nreverse ee)))
  4303. (defun org-agenda-get-deadlines ()
  4304. "Return the deadline information for agenda display."
  4305. (let* ((props (list 'mouse-face 'highlight
  4306. 'org-not-done-regexp org-not-done-regexp
  4307. 'org-todo-regexp org-todo-regexp
  4308. 'org-complex-heading-regexp org-complex-heading-regexp
  4309. 'help-echo
  4310. (format "mouse-2 or RET jump to org file %s"
  4311. (abbreviate-file-name buffer-file-name))))
  4312. (regexp org-deadline-time-regexp)
  4313. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4314. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4315. d2 diff dfrac wdays pos pos1 category tags
  4316. suppress-prewarning
  4317. ee txt head face s todo-state upcomingp donep timestr)
  4318. (goto-char (point-min))
  4319. (while (re-search-forward regexp nil t)
  4320. (setq suppress-prewarning nil)
  4321. (catch :skip
  4322. (org-agenda-skip)
  4323. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4324. (save-match-data
  4325. (string-match org-scheduled-time-regexp
  4326. (buffer-substring (point-at-bol)
  4327. (point-at-eol)))))
  4328. (setq suppress-prewarning
  4329. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4330. org-agenda-skip-deadline-prewarning-if-scheduled
  4331. 0)))
  4332. (setq s (match-string 1)
  4333. txt nil
  4334. pos (1- (match-beginning 1))
  4335. d2 (org-time-string-to-absolute
  4336. (match-string 1) d1 'past
  4337. org-agenda-repeating-timestamp-show-all)
  4338. diff (- d2 d1)
  4339. wdays (if suppress-prewarning
  4340. (let ((org-deadline-warning-days suppress-prewarning))
  4341. (org-get-wdays s))
  4342. (org-get-wdays s))
  4343. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4344. upcomingp (and todayp (> diff 0)))
  4345. ;; When to show a deadline in the calendar:
  4346. ;; If the expiration is within wdays warning time.
  4347. ;; Past-due deadlines are only shown on the current date
  4348. (if (and (or (and (<= diff wdays)
  4349. (and todayp (not org-agenda-only-exact-dates)))
  4350. (= diff 0)))
  4351. (save-excursion
  4352. (setq todo-state (org-get-todo-state))
  4353. (setq donep (member todo-state org-done-keywords))
  4354. (if (and donep
  4355. (or org-agenda-skip-deadline-if-done
  4356. (not (= diff 0))))
  4357. (setq txt nil)
  4358. (setq category (org-get-category))
  4359. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4360. (setq txt org-agenda-no-heading-message)
  4361. (goto-char (match-end 0))
  4362. (setq pos1 (match-beginning 0))
  4363. (setq tags (org-get-tags-at pos1))
  4364. (setq head (buffer-substring-no-properties
  4365. (point)
  4366. (progn (skip-chars-forward "^\r\n")
  4367. (point))))
  4368. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4369. (setq timestr
  4370. (concat (substring s (match-beginning 1)) " "))
  4371. (setq timestr 'time))
  4372. (setq txt (org-format-agenda-item
  4373. (if (= diff 0)
  4374. (car org-agenda-deadline-leaders)
  4375. (if (functionp
  4376. (nth 1 org-agenda-deadline-leaders))
  4377. (funcall
  4378. (nth 1 org-agenda-deadline-leaders)
  4379. diff date)
  4380. (format (nth 1 org-agenda-deadline-leaders)
  4381. diff)))
  4382. head category tags
  4383. (if (not (= diff 0)) nil timestr)))))
  4384. (when txt
  4385. (setq face (org-agenda-deadline-face dfrac wdays))
  4386. (org-add-props txt props
  4387. 'org-marker (org-agenda-new-marker pos)
  4388. 'org-hd-marker (org-agenda-new-marker pos1)
  4389. 'priority (+ (- diff)
  4390. (org-get-priority txt))
  4391. 'org-category category
  4392. 'todo-state todo-state
  4393. 'type (if upcomingp "upcoming-deadline" "deadline")
  4394. 'date (if upcomingp date d2)
  4395. 'face (if donep 'org-agenda-done face)
  4396. 'undone-face face 'done-face 'org-agenda-done)
  4397. (push txt ee))))))
  4398. (nreverse ee)))
  4399. (defun org-agenda-deadline-face (fraction &optional wdays)
  4400. "Return the face to displaying a deadline item.
  4401. FRACTION is what fraction of the head-warning time has passed."
  4402. (if (equal wdays 0) (setq fraction 1.))
  4403. (let ((faces org-agenda-deadline-faces) f)
  4404. (catch 'exit
  4405. (while (setq f (pop faces))
  4406. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4407. (defun org-agenda-get-scheduled (&optional deadline-results)
  4408. "Return the scheduled information for agenda display."
  4409. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4410. 'org-todo-regexp org-todo-regexp
  4411. 'org-complex-heading-regexp org-complex-heading-regexp
  4412. 'done-face 'org-agenda-done
  4413. 'mouse-face 'highlight
  4414. 'help-echo
  4415. (format "mouse-2 or RET jump to org file %s"
  4416. (abbreviate-file-name buffer-file-name))))
  4417. (regexp org-scheduled-time-regexp)
  4418. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4419. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4420. mm
  4421. (deadline-position-alist
  4422. (mapcar (lambda (a) (and (setq mm (get-text-property
  4423. 0 'org-hd-marker a))
  4424. (cons (marker-position mm) a)))
  4425. deadline-results))
  4426. d2 diff pos pos1 category tags donep
  4427. ee txt head pastschedp todo-state face timestr s habitp)
  4428. (goto-char (point-min))
  4429. (while (re-search-forward regexp nil t)
  4430. (catch :skip
  4431. (org-agenda-skip)
  4432. (setq s (match-string 1)
  4433. txt nil
  4434. pos (1- (match-beginning 1))
  4435. d2 (org-time-string-to-absolute
  4436. (match-string 1) d1 'past
  4437. org-agenda-repeating-timestamp-show-all)
  4438. diff (- d2 d1))
  4439. (setq pastschedp (and todayp (< diff 0)))
  4440. ;; When to show a scheduled item in the calendar:
  4441. ;; If it is on or past the date.
  4442. (when (or (and (< diff 0)
  4443. (< (abs diff) org-scheduled-past-days)
  4444. (and todayp (not org-agenda-only-exact-dates)))
  4445. (= diff 0))
  4446. (save-excursion
  4447. (setq todo-state (org-get-todo-state))
  4448. (setq donep (member todo-state org-done-keywords))
  4449. (setq habitp (and (functionp 'org-is-habit-p)
  4450. (org-is-habit-p)))
  4451. (if (and donep
  4452. (or habitp org-agenda-skip-scheduled-if-done
  4453. (not (= diff 0))))
  4454. (setq txt nil)
  4455. (setq category (org-get-category))
  4456. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4457. (setq txt org-agenda-no-heading-message)
  4458. (goto-char (match-end 0))
  4459. (setq pos1 (match-beginning 0))
  4460. (if habitp
  4461. (if (or (not org-habit-show-habits)
  4462. (and (not todayp)
  4463. org-habit-show-habits-only-for-today))
  4464. (throw :skip nil))
  4465. (if (and
  4466. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4467. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4468. pastschedp))
  4469. (setq mm (assoc pos1 deadline-position-alist)))
  4470. (throw :skip nil)))
  4471. (setq tags (org-get-tags-at))
  4472. (setq head (buffer-substring-no-properties
  4473. (point)
  4474. (progn (skip-chars-forward "^\r\n") (point))))
  4475. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4476. (setq timestr
  4477. (concat (substring s (match-beginning 1)) " "))
  4478. (setq timestr 'time))
  4479. (setq txt (org-format-agenda-item
  4480. (if (= diff 0)
  4481. (car org-agenda-scheduled-leaders)
  4482. (format (nth 1 org-agenda-scheduled-leaders)
  4483. (- 1 diff)))
  4484. head category tags
  4485. (if (not (= diff 0)) nil timestr)
  4486. nil nil habitp))))
  4487. (when txt
  4488. (setq face
  4489. (cond
  4490. ((and (not habitp) pastschedp)
  4491. 'org-scheduled-previously)
  4492. (todayp 'org-scheduled-today)
  4493. (t 'org-scheduled))
  4494. habitp (and habitp (org-habit-parse-todo)))
  4495. (org-add-props txt props
  4496. 'undone-face face
  4497. 'face (if donep 'org-agenda-done face)
  4498. 'org-marker (org-agenda-new-marker pos)
  4499. 'org-hd-marker (org-agenda-new-marker pos1)
  4500. 'type (if pastschedp "past-scheduled" "scheduled")
  4501. 'date (if pastschedp d2 date)
  4502. 'priority (if habitp
  4503. (org-habit-get-priority habitp)
  4504. (+ 94 (- 5 diff) (org-get-priority txt)))
  4505. 'org-category category
  4506. 'org-habit-p habitp
  4507. 'todo-state todo-state)
  4508. (push txt ee))))))
  4509. (nreverse ee)))
  4510. (defun org-agenda-get-blocks ()
  4511. "Return the date-range information for agenda display."
  4512. (let* ((props (list 'face nil
  4513. 'org-not-done-regexp org-not-done-regexp
  4514. 'org-todo-regexp org-todo-regexp
  4515. 'org-complex-heading-regexp org-complex-heading-regexp
  4516. 'mouse-face 'highlight
  4517. 'help-echo
  4518. (format "mouse-2 or RET jump to org file %s"
  4519. (abbreviate-file-name buffer-file-name))))
  4520. (regexp org-tr-regexp)
  4521. (d0 (calendar-absolute-from-gregorian date))
  4522. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4523. head donep)
  4524. (goto-char (point-min))
  4525. (while (re-search-forward regexp nil t)
  4526. (catch :skip
  4527. (org-agenda-skip)
  4528. (setq pos (point))
  4529. (setq timestr (match-string 0)
  4530. s1 (match-string 1)
  4531. s2 (match-string 2)
  4532. d1 (time-to-days (org-time-string-to-time s1))
  4533. d2 (time-to-days (org-time-string-to-time s2)))
  4534. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4535. ;; Only allow days between the limits, because the normal
  4536. ;; date stamps will catch the limits.
  4537. (save-excursion
  4538. (setq todo-state (org-get-todo-state))
  4539. (setq donep (member todo-state org-done-keywords))
  4540. (if (and donep org-agenda-skip-timestamp-if-done)
  4541. (throw :skip t))
  4542. (setq marker (org-agenda-new-marker (point)))
  4543. (setq category (org-get-category))
  4544. (if (not (re-search-backward "^\\*+ " nil t))
  4545. (setq txt org-agenda-no-heading-message)
  4546. (goto-char (match-beginning 0))
  4547. (setq hdmarker (org-agenda-new-marker (point)))
  4548. (setq tags (org-get-tags-at))
  4549. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4550. (setq head (match-string 1))
  4551. (let ((remove-re
  4552. (if org-agenda-remove-timeranges-from-blocks
  4553. (concat
  4554. "<" (regexp-quote s1) ".*?>"
  4555. "--"
  4556. "<" (regexp-quote s2) ".*?>")
  4557. nil)))
  4558. (setq txt (org-format-agenda-item
  4559. (format
  4560. (nth (if (= d1 d2) 0 1)
  4561. org-agenda-timerange-leaders)
  4562. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4563. head category tags
  4564. timestr nil remove-re))))
  4565. (org-add-props txt props
  4566. 'org-marker marker 'org-hd-marker hdmarker
  4567. 'type "block" 'date date
  4568. 'todo-state todo-state
  4569. 'priority (org-get-priority txt) 'org-category category)
  4570. (push txt ee)))
  4571. (goto-char pos)))
  4572. ;; Sort the entries by expiration date.
  4573. (nreverse ee)))
  4574. ;;; Agenda presentation and sorting
  4575. (defvar org-prefix-has-time nil
  4576. "A flag, set by `org-compile-prefix-format'.
  4577. The flag is set if the currently compiled format contains a `%t'.")
  4578. (defvar org-prefix-has-tag nil
  4579. "A flag, set by `org-compile-prefix-format'.
  4580. The flag is set if the currently compiled format contains a `%T'.")
  4581. (defvar org-prefix-has-effort nil
  4582. "A flag, set by `org-compile-prefix-format'.
  4583. The flag is set if the currently compiled format contains a `%e'.")
  4584. (defvar org-prefix-category-length nil
  4585. "Used by `org-compile-prefix-format' to remember the category field width.")
  4586. (defvar org-prefix-category-max-length nil
  4587. "Used by `org-compile-prefix-format' to remember the category field width.")
  4588. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4589. noprefix remove-re habitp)
  4590. "Format TXT to be inserted into the agenda buffer.
  4591. In particular, it adds the prefix and corresponding text properties. EXTRA
  4592. must be a string and replaces the `%s' specifier in the prefix format.
  4593. CATEGORY (string, symbol or nil) may be used to overrule the default
  4594. category taken from local variable or file name. It will replace the `%c'
  4595. specifier in the format. DOTIME, when non-nil, indicates that a
  4596. time-of-day should be extracted from TXT for sorting of this entry, and for
  4597. the `%t' specifier in the format. When DOTIME is a string, this string is
  4598. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4599. only the correctly processes TXT should be returned - this is used by
  4600. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4601. Any match of REMOVE-RE will be removed from TXT."
  4602. (save-match-data
  4603. ;; Diary entries sometimes have extra whitespace at the beginning
  4604. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4605. ;; Fix the tags part in txt
  4606. (setq txt (org-agenda-fix-displayed-tags
  4607. txt tags
  4608. org-agenda-show-inherited-tags
  4609. org-agenda-hide-tags-regexp))
  4610. (let* ((category (or category
  4611. org-category
  4612. (if buffer-file-name
  4613. (file-name-sans-extension
  4614. (file-name-nondirectory buffer-file-name))
  4615. "")))
  4616. ;; time, tag, effort are needed for the eval of the prefix format
  4617. (tag (if tags (nth (1- (length tags)) tags) ""))
  4618. time effort neffort
  4619. (ts (if dotime (concat
  4620. (if (stringp dotime) dotime "")
  4621. (and org-agenda-search-headline-for-time txt))))
  4622. (time-of-day (and dotime (org-get-time-of-day ts)))
  4623. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4624. duration thecategory)
  4625. (and (org-mode-p) buffer-file-name
  4626. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4627. (when (and dotime time-of-day)
  4628. ;; Extract starting and ending time and move them to prefix
  4629. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4630. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4631. (setq s0 (match-string 0 ts)
  4632. srp (and stamp (match-end 3))
  4633. s1 (match-string (if plain 1 2) ts)
  4634. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4635. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4636. ;; them, we might want to remove them there to avoid duplication.
  4637. ;; The user can turn this off with a variable.
  4638. (if (and org-prefix-has-time
  4639. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4640. (string-match (concat (regexp-quote s0) " *") txt)
  4641. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4642. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4643. (= (match-beginning 0) 0)
  4644. t))
  4645. (setq txt (replace-match "" nil nil txt))))
  4646. ;; Normalize the time(s) to 24 hour
  4647. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4648. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4649. ;; Compute the duration
  4650. (when s1
  4651. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4652. (string-to-number (substring s1 3)))
  4653. t2 (cond
  4654. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4655. (string-to-number (substring s2 3))))
  4656. (org-agenda-default-appointment-duration
  4657. (+ t1 org-agenda-default-appointment-duration))
  4658. (t nil)))
  4659. (setq duration (if t2 (- t2 t1)))))
  4660. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4661. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4662. (let ((m (+ (string-to-number (match-string 2 s1))
  4663. (* 60 (string-to-number (match-string 1 s1)))
  4664. org-agenda-default-appointment-duration))
  4665. h)
  4666. (setq h (/ m 60) m (- m (* h 60)))
  4667. (setq s2 (format "%02d:%02d" h m))))
  4668. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4669. txt)
  4670. ;; Tags are in the string
  4671. (if (or (eq org-agenda-remove-tags t)
  4672. (and org-agenda-remove-tags
  4673. org-prefix-has-tag))
  4674. (setq txt (replace-match "" t t txt))
  4675. (setq txt (replace-match
  4676. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4677. (match-string 2 txt))
  4678. t t txt))))
  4679. (when (org-mode-p)
  4680. (setq effort
  4681. (condition-case nil
  4682. (org-get-effort
  4683. (or (get-text-property 0 'org-hd-marker txt)
  4684. (get-text-property 0 'org-marker txt)))
  4685. (error nil)))
  4686. (when effort
  4687. (setq neffort (org-hh:mm-string-to-minutes effort)
  4688. effort (setq effort (concat "[" effort "]" )))))
  4689. (when remove-re
  4690. (while (string-match remove-re txt)
  4691. (setq txt (replace-match "" t t txt))))
  4692. ;; Create the final string
  4693. (if noprefix
  4694. (setq rtn txt)
  4695. ;; Prepare the variables needed in the eval of the compiled format
  4696. (setq time (cond (s2 (concat s1 "-" s2))
  4697. (s1 (concat s1 "......"))
  4698. (t ""))
  4699. extra (or (and (not habitp) extra) "")
  4700. category (if (symbolp category) (symbol-name category) category)
  4701. thecategory (copy-sequence category))
  4702. (if (string-match org-bracket-link-regexp category)
  4703. (progn
  4704. (setq l (if (match-end 3)
  4705. (- (match-end 3) (match-beginning 3))
  4706. (- (match-end 1) (match-beginning 1))))
  4707. (when (< l (or org-prefix-category-length 0))
  4708. (setq category (copy-sequence category))
  4709. (org-add-props category nil
  4710. 'extra-space (make-string
  4711. (- org-prefix-category-length l 1) ?\ ))))
  4712. (if (and org-prefix-category-max-length
  4713. (>= (length category) org-prefix-category-max-length))
  4714. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4715. ;; Evaluate the compiled format
  4716. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4717. ;; And finally add the text properties
  4718. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4719. (org-add-props rtn nil
  4720. 'org-category (if thecategory (downcase thecategory) category)
  4721. 'tags (mapcar 'org-downcase-keep-props tags)
  4722. 'org-highest-priority org-highest-priority
  4723. 'org-lowest-priority org-lowest-priority
  4724. 'prefix-length (- (length rtn) (length txt))
  4725. 'time-of-day time-of-day
  4726. 'duration duration
  4727. 'effort effort
  4728. 'effort-minutes neffort
  4729. 'txt txt
  4730. 'time time
  4731. 'extra extra
  4732. 'dotime dotime))))
  4733. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4734. "Remove tags string from TXT, and add a modified list of tags.
  4735. The modified list may contain inherited tags, and tags matched by
  4736. `org-agenda-hide-tags-regexp' will be removed."
  4737. (when (or add-inherited hide-re)
  4738. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4739. (setq txt (substring txt 0 (match-beginning 0))))
  4740. (setq tags
  4741. (delq nil
  4742. (mapcar (lambda (tg)
  4743. (if (or (and hide-re (string-match hide-re tg))
  4744. (and (not add-inherited)
  4745. (get-text-property 0 'inherited tg)))
  4746. nil
  4747. tg))
  4748. tags)))
  4749. (when tags
  4750. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4751. i)
  4752. (setq txt (concat txt " :"
  4753. (mapconcat
  4754. (lambda (x)
  4755. (setq i (get-text-property 0 'inherited x))
  4756. (if (and have-i (not i))
  4757. (progn
  4758. (setq have-i nil)
  4759. (concat ":" x))
  4760. x))
  4761. tags ":")
  4762. (if have-i "::" ":"))))))
  4763. txt)
  4764. (defun org-downcase-keep-props (s)
  4765. (let ((props (text-properties-at 0 s)))
  4766. (setq s (downcase s))
  4767. (add-text-properties 0 (length s) props s)
  4768. s))
  4769. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4770. (defvar org-agenda-sorting-strategy-selected nil)
  4771. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4772. (catch 'exit
  4773. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4774. ((and todayp (member 'today (car org-agenda-time-grid))))
  4775. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4776. ((member 'weekly (car org-agenda-time-grid)))
  4777. (t (throw 'exit list)))
  4778. (let* ((have (delq nil (mapcar
  4779. (lambda (x) (get-text-property 1 'time-of-day x))
  4780. list)))
  4781. (string (nth 1 org-agenda-time-grid))
  4782. (gridtimes (nth 2 org-agenda-time-grid))
  4783. (req (car org-agenda-time-grid))
  4784. (remove (member 'remove-match req))
  4785. new time)
  4786. (if (and (member 'require-timed req) (not have))
  4787. ;; don't show empty grid
  4788. (throw 'exit list))
  4789. (while (setq time (pop gridtimes))
  4790. (unless (and remove (member time have))
  4791. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  4792. (push (org-format-agenda-item
  4793. nil string "" nil
  4794. (concat (substring time 0 -2) ":" (substring time -2)))
  4795. new)
  4796. (put-text-property
  4797. 2 (length (car new)) 'face 'org-time-grid (car new))))
  4798. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4799. (append new list)
  4800. (append list new)))))
  4801. (defun org-compile-prefix-format (key)
  4802. "Compile the prefix format into a Lisp form that can be evaluated.
  4803. The resulting form is returned and stored in the variable
  4804. `org-prefix-format-compiled'."
  4805. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4806. org-prefix-category-length nil org-prefix-has-effort nil)
  4807. (let ((s (cond
  4808. ((stringp org-agenda-prefix-format)
  4809. org-agenda-prefix-format)
  4810. ((assq key org-agenda-prefix-format)
  4811. (cdr (assq key org-agenda-prefix-format)))
  4812. (t " %-12:c%?-12t% s")))
  4813. (start 0)
  4814. varform vars var e c f opt)
  4815. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4816. s start)
  4817. (setq var (cdr (assoc (match-string 4 s)
  4818. '(("c" . category) ("t" . time) ("s" . extra)
  4819. ("T" . tag) ("e" . effort))))
  4820. c (or (match-string 3 s) "")
  4821. opt (match-beginning 1)
  4822. start (1+ (match-beginning 0)))
  4823. (if (equal var 'time) (setq org-prefix-has-time t))
  4824. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4825. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4826. (setq f (concat "%" (match-string 2 s) "s"))
  4827. (when (equal var 'category)
  4828. (setq org-prefix-category-length
  4829. (floor (abs (string-to-number (match-string 2 s)))))
  4830. (setq org-prefix-category-max-length
  4831. (let ((x (match-string 2 s)))
  4832. (save-match-data
  4833. (if (string-match "\\.[0-9]+" x)
  4834. (string-to-number (substring (match-string 0 x) 1)))))))
  4835. (if opt
  4836. (setq varform
  4837. `(if (equal "" ,var)
  4838. ""
  4839. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4840. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4841. (setq s (replace-match "%s" t nil s))
  4842. (push varform vars))
  4843. (setq vars (nreverse vars))
  4844. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4845. (defun org-set-sorting-strategy (key)
  4846. (if (symbolp (car org-agenda-sorting-strategy))
  4847. ;; the old format
  4848. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4849. (setq org-agenda-sorting-strategy-selected
  4850. (or (cdr (assq key org-agenda-sorting-strategy))
  4851. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4852. '(time-up category-keep priority-down)))))
  4853. (defun org-get-time-of-day (s &optional string mod24)
  4854. "Check string S for a time of day.
  4855. If found, return it as a military time number between 0 and 2400.
  4856. If not found, return nil.
  4857. The optional STRING argument forces conversion into a 5 character wide string
  4858. HH:MM."
  4859. (save-match-data
  4860. (when
  4861. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4862. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4863. (let* ((h (string-to-number (match-string 1 s)))
  4864. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4865. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4866. (am-p (equal ampm "am"))
  4867. (h1 (cond ((not ampm) h)
  4868. ((= h 12) (if am-p 0 12))
  4869. (t (+ h (if am-p 0 12)))))
  4870. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4871. (mod h1 24) h1))
  4872. (t0 (+ (* 100 h2) m))
  4873. (t1 (concat (if (>= h1 24) "+" " ")
  4874. (if (and org-agenda-time-leading-zero
  4875. (< t0 1000)) "0" "")
  4876. (if (< t0 100) "0" "")
  4877. (if (< t0 10) "0" "")
  4878. (int-to-string t0))))
  4879. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4880. (defvar org-agenda-before-sorting-filter-function nil
  4881. "Function to be applied to agenda items prior to sorting.
  4882. Prior to sorting also means just before they are inserted into the agenda.
  4883. To aid sorting, you may revisit the original entries and add more text
  4884. properties which will later be used by the sorting functions.
  4885. The function should take a string argument, an agenda line.
  4886. It has access to the text properties in that line, which contain among
  4887. other things, the property `org-hd-marker' that points to the entry
  4888. where the line comes from. Note that not all lines going into the agenda
  4889. have this property, only most.
  4890. The function should return the modified string. It is probably best
  4891. to ONLY change text properties.
  4892. You can also use this function as a filter, by returning nil for lines
  4893. you don't want to have in the agenda at all. For this application, you
  4894. could bind the variable in the options section of a custom command.")
  4895. (defun org-finalize-agenda-entries (list &optional nosort)
  4896. "Sort and concatenate the agenda items."
  4897. (setq list (mapcar 'org-agenda-highlight-todo list))
  4898. (if nosort
  4899. list
  4900. (when org-agenda-before-sorting-filter-function
  4901. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  4902. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4903. (defun org-agenda-highlight-todo (x)
  4904. (let ((org-done-keywords org-done-keywords-for-agenda)
  4905. (case-fold-search nil)
  4906. re pl)
  4907. (if (eq x 'line)
  4908. (save-excursion
  4909. (beginning-of-line 1)
  4910. (setq re (org-get-at-bol 'org-todo-regexp))
  4911. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4912. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4913. (add-text-properties (match-beginning 0) (match-end 1)
  4914. (list 'face (org-get-todo-face 1)))
  4915. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4916. (delete-region (match-beginning 1) (1- (match-end 0)))
  4917. (goto-char (match-beginning 1))
  4918. (insert (format org-agenda-todo-keyword-format s)))))
  4919. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4920. pl (get-text-property 0 'prefix-length x))
  4921. (when (and re
  4922. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4923. x (or pl 0)) pl))
  4924. (add-text-properties
  4925. (or (match-end 1) (match-end 0)) (match-end 0)
  4926. (list 'face (org-get-todo-face (match-string 2 x)))
  4927. x)
  4928. (when (match-end 1)
  4929. (setq x (concat (substring x 0 (match-end 1))
  4930. (format org-agenda-todo-keyword-format
  4931. (match-string 2 x))
  4932. (org-add-props " " (text-properties-at 0 x))
  4933. (substring x (match-end 3))))))
  4934. x)))
  4935. (defsubst org-cmp-priority (a b)
  4936. "Compare the priorities of string A and B."
  4937. (let ((pa (or (get-text-property 1 'priority a) 0))
  4938. (pb (or (get-text-property 1 'priority b) 0)))
  4939. (cond ((> pa pb) +1)
  4940. ((< pa pb) -1)
  4941. (t nil))))
  4942. (defsubst org-cmp-effort (a b)
  4943. "Compare the priorities of string A and B."
  4944. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4945. (ea (or (get-text-property 1 'effort-minutes a) def))
  4946. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4947. (cond ((> ea eb) +1)
  4948. ((< ea eb) -1)
  4949. (t nil))))
  4950. (defsubst org-cmp-category (a b)
  4951. "Compare the string values of categories of strings A and B."
  4952. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4953. (cb (or (get-text-property 1 'org-category b) "")))
  4954. (cond ((string-lessp ca cb) -1)
  4955. ((string-lessp cb ca) +1)
  4956. (t nil))))
  4957. (defsubst org-cmp-todo-state (a b)
  4958. "Compare the todo states of strings A and B."
  4959. (let* ((ma (or (get-text-property 1 'org-marker a)
  4960. (get-text-property 1 'org-hd-marker a)))
  4961. (mb (or (get-text-property 1 'org-marker b)
  4962. (get-text-property 1 'org-hd-marker b)))
  4963. (fa (and ma (marker-buffer ma)))
  4964. (fb (and mb (marker-buffer mb)))
  4965. (todo-kwds
  4966. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4967. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4968. (ta (or (get-text-property 1 'todo-state a) ""))
  4969. (tb (or (get-text-property 1 'todo-state b) ""))
  4970. (la (- (length (member ta todo-kwds))))
  4971. (lb (- (length (member tb todo-kwds))))
  4972. (donepa (member ta org-done-keywords-for-agenda))
  4973. (donepb (member tb org-done-keywords-for-agenda)))
  4974. (cond ((and donepa (not donepb)) -1)
  4975. ((and (not donepa) donepb) +1)
  4976. ((< la lb) -1)
  4977. ((< lb la) +1)
  4978. (t nil))))
  4979. (defsubst org-cmp-alpha (a b)
  4980. "Compare the headlines, alphabetically."
  4981. (let* ((pla (get-text-property 0 'prefix-length a))
  4982. (plb (get-text-property 0 'prefix-length b))
  4983. (ta (and pla (substring a pla)))
  4984. (tb (and plb (substring b plb))))
  4985. (when pla
  4986. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  4987. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  4988. (setq ta (substring ta (match-end 0))))
  4989. (setq ta (downcase ta)))
  4990. (when plb
  4991. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  4992. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  4993. (setq tb (substring tb (match-end 0))))
  4994. (setq tb (downcase tb)))
  4995. (cond ((not ta) +1)
  4996. ((not tb) -1)
  4997. ((string-lessp ta tb) -1)
  4998. ((string-lessp tb ta) +1)
  4999. (t nil))))
  5000. (defsubst org-cmp-tag (a b)
  5001. "Compare the string values of the first tags of A and B."
  5002. (let ((ta (car (last (get-text-property 1 'tags a))))
  5003. (tb (car (last (get-text-property 1 'tags b)))))
  5004. (cond ((not ta) +1)
  5005. ((not tb) -1)
  5006. ((string-lessp ta tb) -1)
  5007. ((string-lessp tb ta) +1)
  5008. (t nil))))
  5009. (defsubst org-cmp-time (a b)
  5010. "Compare the time-of-day values of strings A and B."
  5011. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5012. (ta (or (get-text-property 1 'time-of-day a) def))
  5013. (tb (or (get-text-property 1 'time-of-day b) def)))
  5014. (cond ((< ta tb) -1)
  5015. ((< tb ta) +1)
  5016. (t nil))))
  5017. (defsubst org-cmp-habit-p (a b)
  5018. "Compare the todo states of strings A and B."
  5019. (let ((ha (get-text-property 1 'org-habit-p a))
  5020. (hb (get-text-property 1 'org-habit-p b)))
  5021. (cond ((and ha (not hb)) -1)
  5022. ((and (not ha) hb) +1)
  5023. (t nil))))
  5024. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5025. (defun org-entries-lessp (a b)
  5026. "Predicate for sorting agenda entries."
  5027. ;; The following variables will be used when the form is evaluated.
  5028. ;; So even though the compiler complains, keep them.
  5029. (let* ((ss org-agenda-sorting-strategy-selected)
  5030. (time-up (and (org-em 'time-up 'time-down ss)
  5031. (org-cmp-time a b)))
  5032. (time-down (if time-up (- time-up) nil))
  5033. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5034. (org-cmp-priority a b)))
  5035. (priority-down (if priority-up (- priority-up) nil))
  5036. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5037. (org-cmp-effort a b)))
  5038. (effort-down (if effort-up (- effort-up) nil))
  5039. (category-up (and (or (org-em 'category-up 'category-down ss)
  5040. (memq 'category-keep ss))
  5041. (org-cmp-category a b)))
  5042. (category-down (if category-up (- category-up) nil))
  5043. (category-keep (if category-up +1 nil))
  5044. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5045. (org-cmp-tag a b)))
  5046. (tag-down (if tag-up (- tag-up) nil))
  5047. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5048. (org-cmp-todo-state a b)))
  5049. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5050. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5051. (org-cmp-habit-p a b)))
  5052. (habit-down (if habit-up (- habit-up) nil))
  5053. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5054. (org-cmp-alpha a b)))
  5055. (alpha-down (if alpha-up (- alpha-up) nil))
  5056. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5057. user-defined-up user-defined-down)
  5058. (if (and need-user-cmp org-agenda-cmp-user-defined
  5059. (functionp org-agenda-cmp-user-defined))
  5060. (setq user-defined-up
  5061. (funcall org-agenda-cmp-user-defined a b)
  5062. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5063. (cdr (assoc
  5064. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5065. '((-1 . t) (1 . nil) (nil . nil))))))
  5066. ;;; Agenda restriction lock
  5067. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5068. "Overlay to mark the headline to which agenda commands are restricted.")
  5069. (overlay-put org-agenda-restriction-lock-overlay
  5070. 'face 'org-agenda-restriction-lock)
  5071. (overlay-put org-agenda-restriction-lock-overlay
  5072. 'help-echo "Agendas are currently limited to this subtree.")
  5073. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5074. (defun org-agenda-set-restriction-lock (&optional type)
  5075. "Set restriction lock for agenda, to current subtree or file.
  5076. Restriction will be the file if TYPE is `file', or if type is the
  5077. universal prefix '(4), or if the cursor is before the first headline
  5078. in the file. Otherwise, restriction will be to the current subtree."
  5079. (interactive "P")
  5080. (and (equal type '(4)) (setq type 'file))
  5081. (setq type (cond
  5082. (type type)
  5083. ((org-at-heading-p) 'subtree)
  5084. ((condition-case nil (org-back-to-heading t) (error nil))
  5085. 'subtree)
  5086. (t 'file)))
  5087. (if (eq type 'subtree)
  5088. (progn
  5089. (setq org-agenda-restrict t)
  5090. (setq org-agenda-overriding-restriction 'subtree)
  5091. (put 'org-agenda-files 'org-restrict
  5092. (list (buffer-file-name (buffer-base-buffer))))
  5093. (org-back-to-heading t)
  5094. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5095. (move-marker org-agenda-restrict-begin (point))
  5096. (move-marker org-agenda-restrict-end
  5097. (save-excursion (org-end-of-subtree t)))
  5098. (message "Locking agenda restriction to subtree"))
  5099. (put 'org-agenda-files 'org-restrict
  5100. (list (buffer-file-name (buffer-base-buffer))))
  5101. (setq org-agenda-restrict nil)
  5102. (setq org-agenda-overriding-restriction 'file)
  5103. (move-marker org-agenda-restrict-begin nil)
  5104. (move-marker org-agenda-restrict-end nil)
  5105. (message "Locking agenda restriction to file"))
  5106. (setq current-prefix-arg nil)
  5107. (org-agenda-maybe-redo))
  5108. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5109. "Remove the agenda restriction lock."
  5110. (interactive "P")
  5111. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5112. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5113. (setq org-agenda-overriding-restriction nil)
  5114. (setq org-agenda-restrict nil)
  5115. (put 'org-agenda-files 'org-restrict nil)
  5116. (move-marker org-agenda-restrict-begin nil)
  5117. (move-marker org-agenda-restrict-end nil)
  5118. (setq current-prefix-arg nil)
  5119. (message "Agenda restriction lock removed")
  5120. (or noupdate (org-agenda-maybe-redo)))
  5121. (defun org-agenda-maybe-redo ()
  5122. "If there is any window showing the agenda view, update it."
  5123. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5124. (w0 (selected-window)))
  5125. (when w
  5126. (select-window w)
  5127. (org-agenda-redo)
  5128. (select-window w0)
  5129. (if org-agenda-overriding-restriction
  5130. (message "Agenda view shifted to new %s restriction"
  5131. org-agenda-overriding-restriction)
  5132. (message "Agenda restriction lock removed")))))
  5133. ;;; Agenda commands
  5134. (defun org-agenda-check-type (error &rest types)
  5135. "Check if agenda buffer is of allowed type.
  5136. If ERROR is non-nil, throw an error, otherwise just return nil."
  5137. (if (memq org-agenda-type types)
  5138. t
  5139. (if error
  5140. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5141. nil)))
  5142. (defun org-agenda-quit ()
  5143. "Exit agenda by removing the window or the buffer."
  5144. (interactive)
  5145. (if org-agenda-columns-active
  5146. (org-columns-quit)
  5147. (let ((buf (current-buffer)))
  5148. (if (eq org-agenda-window-setup 'other-frame)
  5149. (progn
  5150. (kill-buffer buf)
  5151. (org-agenda-reset-markers)
  5152. (org-columns-remove-overlays)
  5153. (setq org-agenda-archives-mode nil)
  5154. (delete-frame))
  5155. (and (not (eq org-agenda-window-setup 'current-window))
  5156. (not (one-window-p))
  5157. (delete-window))
  5158. (kill-buffer buf)
  5159. (org-agenda-reset-markers)
  5160. (org-columns-remove-overlays)
  5161. (setq org-agenda-archives-mode nil)))
  5162. ;; Maybe restore the pre-agenda window configuration.
  5163. (and org-agenda-restore-windows-after-quit
  5164. (not (eq org-agenda-window-setup 'other-frame))
  5165. org-pre-agenda-window-conf
  5166. (set-window-configuration org-pre-agenda-window-conf))))
  5167. (defun org-agenda-exit ()
  5168. "Exit agenda by removing the window or the buffer.
  5169. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5170. Org-mode buffers visited directly by the user will not be touched."
  5171. (interactive)
  5172. (org-release-buffers org-agenda-new-buffers)
  5173. (setq org-agenda-new-buffers nil)
  5174. (org-agenda-quit))
  5175. (defun org-agenda-execute (arg)
  5176. "Execute another agenda command, keeping same window.
  5177. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5178. in the agenda."
  5179. (interactive "P")
  5180. (let ((org-agenda-window-setup 'current-window))
  5181. (org-agenda arg)))
  5182. (defun org-agenda-redo ()
  5183. "Rebuild Agenda.
  5184. When this is the global TODO list, a prefix argument will be interpreted."
  5185. (interactive)
  5186. (let* ((org-agenda-keep-modes t)
  5187. (filter org-agenda-filter)
  5188. (preset (get 'org-agenda-filter :preset-filter))
  5189. (org-agenda-filter-while-redo (or filter preset))
  5190. (cols org-agenda-columns-active)
  5191. (line (org-current-line))
  5192. (window-line (- line (org-current-line (window-start))))
  5193. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5194. (put 'org-agenda-filter :preset-filter nil)
  5195. (and cols (org-columns-quit))
  5196. (message "Rebuilding agenda buffer...")
  5197. (org-let lprops '(eval org-agenda-redo-command))
  5198. (setq org-agenda-undo-list nil
  5199. org-agenda-pending-undo-list nil)
  5200. (message "Rebuilding agenda buffer...done")
  5201. (put 'org-agenda-filter :preset-filter preset)
  5202. (and (or filter preset) (org-agenda-filter-apply filter))
  5203. (and cols (interactive-p) (org-agenda-columns))
  5204. (org-goto-line line)
  5205. (recenter window-line)))
  5206. (defvar org-global-tags-completion-table nil)
  5207. (defvar org-agenda-filter-form nil)
  5208. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5209. "Keep only those lines in the agenda buffer that have a specific tag.
  5210. The tag is selected with its fast selection letter, as configured.
  5211. With prefix argument STRIP, remove all lines that do have the tag.
  5212. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5213. used to narrow the search - the interactive user can also press `-' or `+'
  5214. to switch to narrowing."
  5215. (interactive "P")
  5216. (let* ((alist org-tag-alist-for-agenda)
  5217. (tag-chars (mapconcat
  5218. (lambda (x) (if (and (not (symbolp (car x)))
  5219. (cdr x))
  5220. (char-to-string (cdr x))
  5221. ""))
  5222. alist ""))
  5223. (efforts (org-split-string
  5224. (or (cdr (assoc (concat org-effort-property "_ALL")
  5225. org-global-properties))
  5226. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5227. (effort-op org-agenda-filter-effort-default-operator)
  5228. (effort-prompt "")
  5229. (inhibit-read-only t)
  5230. (current org-agenda-filter)
  5231. a n tag)
  5232. (unless char
  5233. (message
  5234. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5235. (if narrow "Narrow" "Filter") tag-chars
  5236. (if org-agenda-auto-exclude-function "[RET], " ""))
  5237. (setq char (read-char)))
  5238. (when (member char '(?+ ?-))
  5239. ;; Narrowing down
  5240. (cond ((equal char ?-) (setq strip t narrow t))
  5241. ((equal char ?+) (setq strip nil narrow t)))
  5242. (message
  5243. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5244. (setq char (read-char)))
  5245. (when (member char '(?< ?> ?= ??))
  5246. ;; An effort operator
  5247. (setq effort-op (char-to-string char))
  5248. (setq alist nil) ; to make sure it will be interpreted as effort.
  5249. (unless (equal char ??)
  5250. (loop for i from 0 to 9 do
  5251. (setq effort-prompt
  5252. (concat
  5253. effort-prompt " ["
  5254. (if (= i 9) "0" (int-to-string (1+ i)))
  5255. "]" (nth i efforts))))
  5256. (message "Effort%s: %s " effort-op effort-prompt)
  5257. (setq char (read-char))
  5258. (when (or (< char ?0) (> char ?9))
  5259. (error "Need 1-9,0 to select effort" ))))
  5260. (when (equal char ?\t)
  5261. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5262. (org-set-local 'org-global-tags-completion-table
  5263. (org-global-tags-completion-table)))
  5264. (let ((completion-ignore-case t))
  5265. (setq tag (org-icompleting-read
  5266. "Tag: " org-global-tags-completion-table))))
  5267. (cond
  5268. ((equal char ?\r)
  5269. (org-agenda-filter-by-tag-show-all)
  5270. (when org-agenda-auto-exclude-function
  5271. (setq org-agenda-filter '())
  5272. (dolist (tag (org-agenda-get-represented-tags))
  5273. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5274. (if modifier
  5275. (push modifier org-agenda-filter))))
  5276. (if (not (null org-agenda-filter))
  5277. (org-agenda-filter-apply org-agenda-filter))))
  5278. ((equal char ?/)
  5279. (org-agenda-filter-by-tag-show-all)
  5280. (when (get 'org-agenda-filter :preset-filter)
  5281. (org-agenda-filter-apply org-agenda-filter)))
  5282. ((or (equal char ?\ )
  5283. (setq a (rassoc char alist))
  5284. (and (>= char ?0) (<= char ?9)
  5285. (setq n (if (= char ?0) 9 (- char ?0 1))
  5286. tag (concat effort-op (nth n efforts))
  5287. a (cons tag nil)))
  5288. (and (= char ??)
  5289. (setq tag "?eff")
  5290. a (cons tag nil))
  5291. (and tag (setq a (cons tag nil))))
  5292. (org-agenda-filter-by-tag-show-all)
  5293. (setq tag (car a))
  5294. (setq org-agenda-filter
  5295. (cons (concat (if strip "-" "+") tag)
  5296. (if narrow current nil)))
  5297. (org-agenda-filter-apply org-agenda-filter))
  5298. (t (error "Invalid tag selection character %c" char)))))
  5299. (defun org-agenda-get-represented-tags ()
  5300. "Get a list of all tags currently represented in the agenda."
  5301. (let (p tags)
  5302. (save-excursion
  5303. (goto-char (point-min))
  5304. (while (setq p (next-single-property-change (point) 'tags))
  5305. (goto-char p)
  5306. (mapc (lambda (x) (add-to-list 'tags x))
  5307. (get-text-property (point) 'tags))))
  5308. tags))
  5309. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5310. "Refine the current filter. See `org-agenda-filter-by-tag."
  5311. (interactive "P")
  5312. (org-agenda-filter-by-tag strip char 'refine))
  5313. (defun org-agenda-filter-make-matcher ()
  5314. "Create the form that tests a line for the agenda filter."
  5315. (let (f f1)
  5316. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5317. org-agenda-filter))
  5318. (if (member x '("-" "+"))
  5319. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5320. (if (string-match "[<=>?]" x)
  5321. (setq f1 (org-agenda-filter-effort-form x))
  5322. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5323. (if (equal (string-to-char x) ?-)
  5324. (setq f1 (list 'not f1))))
  5325. (push f1 f))
  5326. (cons 'and (nreverse f))))
  5327. (defun org-agenda-filter-effort-form (e)
  5328. "Return the form to compare the effort of the current line with what E says.
  5329. E looks like \"+<2:25\"."
  5330. (let (op)
  5331. (setq e (substring e 1))
  5332. (setq op (string-to-char e) e (substring e 1))
  5333. (setq op (cond ((equal op ?<) '<=)
  5334. ((equal op ?>) '>=)
  5335. ((equal op ??) op)
  5336. (t '=)))
  5337. (list 'org-agenda-compare-effort (list 'quote op)
  5338. (org-hh:mm-string-to-minutes e))))
  5339. (defun org-agenda-compare-effort (op value)
  5340. "Compare the effort of the current line with VALUE, using OP.
  5341. If the line does not have an effort defined, return nil."
  5342. (let ((eff (org-get-at-bol 'effort-minutes)))
  5343. (if (equal op ??)
  5344. (not eff)
  5345. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5346. value))))
  5347. (defun org-agenda-filter-apply (filter)
  5348. "Set FILTER as the new agenda filter and apply it."
  5349. (let (tags)
  5350. (setq org-agenda-filter filter
  5351. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5352. (org-agenda-set-mode-name)
  5353. (save-excursion
  5354. (goto-char (point-min))
  5355. (while (not (eobp))
  5356. (if (org-get-at-bol 'org-marker)
  5357. (progn
  5358. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5359. (if (not (eval org-agenda-filter-form))
  5360. (org-agenda-filter-by-tag-hide-line))
  5361. (beginning-of-line 2))
  5362. (beginning-of-line 2))))
  5363. (if (get-char-property (point) 'invisible)
  5364. (org-agenda-previous-line))))
  5365. (defun org-agenda-filter-by-tag-hide-line ()
  5366. (let (ov)
  5367. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5368. (point-at-eol)))
  5369. (overlay-put ov 'invisible t)
  5370. (overlay-put ov 'type 'tags-filter)
  5371. (push ov org-agenda-filter-overlays)))
  5372. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5373. (setq pos (or pos (point)))
  5374. (save-excursion
  5375. (dolist (ov (overlays-at pos))
  5376. (when (and (overlay-get ov 'invisible)
  5377. (eq (overlay-get ov 'type) 'tags-filter))
  5378. (goto-char pos)
  5379. (if (< (overlay-start ov) (point-at-eol))
  5380. (move-overlay ov (point-at-eol)
  5381. (overlay-end ov)))))))
  5382. (defun org-agenda-filter-by-tag-show-all ()
  5383. (mapc 'delete-overlay org-agenda-filter-overlays)
  5384. (setq org-agenda-filter-overlays nil)
  5385. (setq org-agenda-filter nil)
  5386. (setq org-agenda-filter-form nil)
  5387. (org-agenda-set-mode-name))
  5388. (defun org-agenda-manipulate-query-add ()
  5389. "Manipulate the query by adding a search term with positive selection.
  5390. Positive selection means the term must be matched for selection of an entry."
  5391. (interactive)
  5392. (org-agenda-manipulate-query ?\[))
  5393. (defun org-agenda-manipulate-query-subtract ()
  5394. "Manipulate the query by adding a search term with negative selection.
  5395. Negative selection means term must not be matched for selection of an entry."
  5396. (interactive)
  5397. (org-agenda-manipulate-query ?\]))
  5398. (defun org-agenda-manipulate-query-add-re ()
  5399. "Manipulate the query by adding a search regexp with positive selection.
  5400. Positive selection means the regexp must match for selection of an entry."
  5401. (interactive)
  5402. (org-agenda-manipulate-query ?\{))
  5403. (defun org-agenda-manipulate-query-subtract-re ()
  5404. "Manipulate the query by adding a search regexp with negative selection.
  5405. Negative selection means regexp must not match for selection of an entry."
  5406. (interactive)
  5407. (org-agenda-manipulate-query ?\}))
  5408. (defun org-agenda-manipulate-query (char)
  5409. (cond
  5410. ((memq org-agenda-type '(timeline agenda))
  5411. (let ((org-agenda-include-inactive-timestamps t))
  5412. (org-agenda-redo))
  5413. (message "Display now includes inactive timestamps as well"))
  5414. ((eq org-agenda-type 'search)
  5415. (org-add-to-string
  5416. 'org-agenda-query-string
  5417. (if org-agenda-last-search-view-search-was-boolean
  5418. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5419. (?\{ . " +{}") (?\} . " -{}"))))
  5420. " "))
  5421. (setq org-agenda-redo-command
  5422. (list 'org-search-view
  5423. org-todo-only
  5424. org-agenda-query-string
  5425. (+ (length org-agenda-query-string)
  5426. (if (member char '(?\{ ?\})) 0 1))))
  5427. (set-register org-agenda-query-register org-agenda-query-string)
  5428. (org-agenda-redo))
  5429. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5430. org-agenda-type))))
  5431. (defun org-add-to-string (var string)
  5432. (set var (concat (symbol-value var) string)))
  5433. (defun org-agenda-goto-date (date)
  5434. "Jump to DATE in agenda."
  5435. (interactive (list (let ((org-read-date-prefer-future
  5436. (eval org-agenda-jump-prefer-future)))
  5437. (org-read-date))))
  5438. (org-agenda-list nil date))
  5439. (defun org-agenda-goto-today ()
  5440. "Go to today."
  5441. (interactive)
  5442. (org-agenda-check-type t 'timeline 'agenda)
  5443. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5444. (cond
  5445. (tdpos (goto-char tdpos))
  5446. ((eq org-agenda-type 'agenda)
  5447. (let* ((sd (time-to-days
  5448. (time-subtract (current-time)
  5449. (list 0 (* 3600 org-extend-today-until) 0))))
  5450. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5451. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5452. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5453. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5454. (org-agenda-redo)
  5455. (org-agenda-find-same-or-today-or-agenda)))
  5456. (t (error "Cannot find today")))))
  5457. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5458. (goto-char
  5459. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5460. (text-property-any (point-min) (point-max) 'org-today t)
  5461. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5462. (point-min))))
  5463. (defun org-agenda-later (arg)
  5464. "Go forward in time by thee current span.
  5465. With prefix ARG, go forward that many times the current span."
  5466. (interactive "p")
  5467. (org-agenda-check-type t 'agenda)
  5468. (let* ((span org-agenda-span)
  5469. (sd org-starting-day)
  5470. (greg (calendar-gregorian-from-absolute sd))
  5471. (cnt (org-get-at-bol 'org-day-cnt))
  5472. greg2 nd)
  5473. (cond
  5474. ((eq span 'day)
  5475. (setq sd (+ arg sd) nd 1))
  5476. ((eq span 'week)
  5477. (setq sd (+ (* 7 arg) sd) nd 7))
  5478. ((eq span 'month)
  5479. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5480. sd (calendar-absolute-from-gregorian greg2))
  5481. (setcar greg2 (1+ (car greg2)))
  5482. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5483. ((eq span 'year)
  5484. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5485. sd (calendar-absolute-from-gregorian greg2))
  5486. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5487. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5488. (let ((org-agenda-overriding-arguments
  5489. (list (car org-agenda-last-arguments) sd nd t)))
  5490. (org-agenda-redo)
  5491. (org-agenda-find-same-or-today-or-agenda cnt))))
  5492. (defun org-agenda-earlier (arg)
  5493. "Go backward in time by the current span.
  5494. With prefix ARG, go backward that many times the current span."
  5495. (interactive "p")
  5496. (org-agenda-later (- arg)))
  5497. (defun org-agenda-view-mode-dispatch ()
  5498. "Call one of the view mode commands."
  5499. (interactive)
  5500. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5501. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5502. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5503. (let ((a (read-char-exclusive)))
  5504. (case a
  5505. (?d (call-interactively 'org-agenda-day-view))
  5506. (?w (call-interactively 'org-agenda-week-view))
  5507. (?m (call-interactively 'org-agenda-month-view))
  5508. (?y (call-interactively 'org-agenda-year-view))
  5509. (?l (call-interactively 'org-agenda-log-mode))
  5510. (?L (org-agenda-log-mode '(4)))
  5511. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5512. (?a (call-interactively 'org-agenda-archives-mode))
  5513. (?A (org-agenda-archives-mode 'files))
  5514. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5515. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5516. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5517. (?D (call-interactively 'org-agenda-toggle-diary))
  5518. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5519. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5520. (org-agenda-check-type t 'timeline 'agenda)
  5521. (org-agenda-redo))
  5522. (message "Display now includes inactive timestamps as well"))
  5523. (?q (message "Abort"))
  5524. (otherwise (error "Invalid key" )))))
  5525. (defun org-agenda-day-view (&optional day-of-year)
  5526. "Switch to daily view for agenda.
  5527. With argument DAY-OF-YEAR, switch to that day of the year."
  5528. (interactive "P")
  5529. (setq org-agenda-ndays 1)
  5530. (org-agenda-change-time-span 'day day-of-year))
  5531. (defun org-agenda-week-view (&optional iso-week)
  5532. "Switch to daily view for agenda.
  5533. With argument ISO-WEEK, switch to the corresponding ISO week.
  5534. If ISO-WEEK has more then 2 digits, only the last two encode the
  5535. week. Any digits before this encode a year. So 200712 means
  5536. week 12 of year 2007. Years in the range 1938-2037 can also be
  5537. written as 2-digit years."
  5538. (interactive "P")
  5539. (setq org-agenda-ndays 7)
  5540. (org-agenda-change-time-span 'week iso-week))
  5541. (defun org-agenda-month-view (&optional month)
  5542. "Switch to monthly view for agenda.
  5543. With argument MONTH, switch to that month."
  5544. (interactive "P")
  5545. (org-agenda-change-time-span 'month month))
  5546. (defun org-agenda-year-view (&optional year)
  5547. "Switch to yearly view for agenda.
  5548. With argument YEAR, switch to that year.
  5549. If MONTH has more then 2 digits, only the last two encode the
  5550. month. Any digits before this encode a year. So 200712 means
  5551. December year 2007. Years in the range 1938-2037 can also be
  5552. written as 2-digit years."
  5553. (interactive "P")
  5554. (when year
  5555. (setq year (org-small-year-to-year year)))
  5556. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5557. (org-agenda-change-time-span 'year year)
  5558. (error "Abort")))
  5559. (defun org-agenda-change-time-span (span &optional n)
  5560. "Change the agenda view to SPAN.
  5561. SPAN may be `day', `week', `month', `year'."
  5562. (org-agenda-check-type t 'agenda)
  5563. (if (and (not n) (equal org-agenda-span span))
  5564. (error "Viewing span is already \"%s\"" span))
  5565. (let* ((sd (or (org-get-at-bol 'day)
  5566. org-starting-day))
  5567. (computed (org-agenda-compute-time-span sd span n))
  5568. (org-agenda-overriding-arguments
  5569. (list (car org-agenda-last-arguments)
  5570. (car computed) (cdr computed) t)))
  5571. (org-agenda-redo)
  5572. (org-agenda-find-same-or-today-or-agenda))
  5573. (org-agenda-set-mode-name)
  5574. (message "Switched to %s view" span))
  5575. (defun org-agenda-compute-time-span (sd span &optional n)
  5576. "Compute starting date and number of days for agenda.
  5577. SPAN may be `day', `week', `month', `year'. The return value
  5578. is a cons cell with the starting date and the number of days,
  5579. so that the date SD will be in that range."
  5580. (let* ((greg (calendar-gregorian-from-absolute sd))
  5581. (dg (nth 1 greg))
  5582. (mg (car greg))
  5583. (yg (nth 2 greg))
  5584. nd w1 y1 m1 thisweek)
  5585. (cond
  5586. ((eq span 'day)
  5587. (when n
  5588. (setq sd (+ (calendar-absolute-from-gregorian
  5589. (list mg 1 yg))
  5590. n -1)))
  5591. (setq nd 1))
  5592. ((eq span 'week)
  5593. (let* ((nt (calendar-day-of-week
  5594. (calendar-gregorian-from-absolute sd)))
  5595. (d (if org-agenda-start-on-weekday
  5596. (- nt org-agenda-start-on-weekday)
  5597. 0)))
  5598. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5599. (when n
  5600. (require 'cal-iso)
  5601. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5602. (when (> n 99)
  5603. (setq y1 (org-small-year-to-year (/ n 100))
  5604. n (mod n 100)))
  5605. (setq sd
  5606. (calendar-absolute-from-iso
  5607. (list n 1
  5608. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5609. (setq nd 7)))
  5610. ((eq span 'month)
  5611. (when (and n (> n 99))
  5612. (setq y1 (org-small-year-to-year (/ n 100))
  5613. n (mod n 100)))
  5614. (setq sd (calendar-absolute-from-gregorian
  5615. (list (or n mg) 1 (or y1 yg)))
  5616. nd (- (calendar-absolute-from-gregorian
  5617. (list (1+ (or n mg)) 1 (or y1 yg)))
  5618. sd)))
  5619. ((eq span 'year)
  5620. (setq sd (calendar-absolute-from-gregorian
  5621. (list 1 1 (or n yg)))
  5622. nd (- (calendar-absolute-from-gregorian
  5623. (list 1 1 (1+ (or n yg))))
  5624. sd))))
  5625. (cons sd nd)))
  5626. (defun org-agenda-next-date-line (&optional arg)
  5627. "Jump to the next line indicating a date in agenda buffer."
  5628. (interactive "p")
  5629. (org-agenda-check-type t 'agenda 'timeline)
  5630. (beginning-of-line 1)
  5631. ;; This does not work if user makes date format that starts with a blank
  5632. (if (looking-at "^\\S-") (forward-char 1))
  5633. (if (not (re-search-forward "^\\S-" nil t arg))
  5634. (progn
  5635. (backward-char 1)
  5636. (error "No next date after this line in this buffer")))
  5637. (goto-char (match-beginning 0)))
  5638. (defun org-agenda-previous-date-line (&optional arg)
  5639. "Jump to the previous line indicating a date in agenda buffer."
  5640. (interactive "p")
  5641. (org-agenda-check-type t 'agenda 'timeline)
  5642. (beginning-of-line 1)
  5643. (if (not (re-search-backward "^\\S-" nil t arg))
  5644. (error "No previous date before this line in this buffer")))
  5645. ;; Initialize the highlight
  5646. (defvar org-hl (make-overlay 1 1))
  5647. (overlay-put org-hl 'face 'highlight)
  5648. (defun org-highlight (begin end &optional buffer)
  5649. "Highlight a region with overlay."
  5650. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5651. (defun org-unhighlight ()
  5652. "Detach overlay INDEX."
  5653. (org-detach-overlay org-hl))
  5654. ;; FIXME this is currently not used.
  5655. (defun org-highlight-until-next-command (beg end &optional buffer)
  5656. "Move the highlight overlay to BEG/END, remove it before the next command."
  5657. (org-highlight beg end buffer)
  5658. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5659. (defun org-unhighlight-once ()
  5660. "Remove the highlight from its position, and this function from the hook."
  5661. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5662. (org-unhighlight))
  5663. (defun org-agenda-follow-mode ()
  5664. "Toggle follow mode in an agenda buffer."
  5665. (interactive)
  5666. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5667. (org-agenda-set-mode-name)
  5668. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5669. (org-agenda-show))
  5670. (message "Follow mode is %s"
  5671. (if org-agenda-follow-mode "on" "off")))
  5672. (defun org-agenda-entry-text-mode (&optional arg)
  5673. "Toggle entry text mode in an agenda buffer."
  5674. (interactive "P")
  5675. (setq org-agenda-entry-text-mode (or (integerp arg)
  5676. (not org-agenda-entry-text-mode)))
  5677. (org-agenda-entry-text-hide)
  5678. (and org-agenda-entry-text-mode
  5679. (let ((org-agenda-entry-text-maxlines
  5680. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5681. (org-agenda-entry-text-show)))
  5682. (org-agenda-set-mode-name)
  5683. (message "Entry text mode is %s. Maximum number of lines is %d"
  5684. (if org-agenda-entry-text-mode "on" "off")
  5685. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5686. (defun org-agenda-clockreport-mode (&optional with-filter)
  5687. "Toggle clocktable mode in an agenda buffer.
  5688. With prefix arg WITH-FILTER, make the clocktable respect the current
  5689. agenda filter."
  5690. (interactive "P")
  5691. (org-agenda-check-type t 'agenda)
  5692. (if with-filter
  5693. (setq org-agenda-clockreport-mode 'with-filter)
  5694. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5695. (org-agenda-set-mode-name)
  5696. (org-agenda-redo)
  5697. (message "Clocktable mode is %s"
  5698. (if org-agenda-clockreport-mode "on" "off")))
  5699. (defun org-agenda-log-mode (&optional special)
  5700. "Toggle log mode in an agenda buffer.
  5701. With argument SPECIAL, show all possible log items, not only the ones
  5702. configured in `org-agenda-log-mode-items'.
  5703. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5704. (interactive "P")
  5705. (org-agenda-check-type t 'agenda 'timeline)
  5706. (setq org-agenda-show-log
  5707. (if (equal special '(16))
  5708. 'only
  5709. (if special '(closed clock state)
  5710. (not org-agenda-show-log))))
  5711. (org-agenda-set-mode-name)
  5712. (org-agenda-redo)
  5713. (message "Log mode is %s"
  5714. (if org-agenda-show-log "on" "off")))
  5715. (defun org-agenda-archives-mode (&optional with-files)
  5716. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5717. When called with a prefix argument, include all archive files as well."
  5718. (interactive "P")
  5719. (setq org-agenda-archives-mode
  5720. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5721. (org-agenda-set-mode-name)
  5722. (org-agenda-redo)
  5723. (message
  5724. "%s"
  5725. (cond
  5726. ((eq org-agenda-archives-mode nil)
  5727. "No archives are included")
  5728. ((eq org-agenda-archives-mode 'trees)
  5729. (format "Trees with :%s: tag are included" org-archive-tag))
  5730. ((eq org-agenda-archives-mode t)
  5731. (format "Trees with :%s: tag and all active archive files are included"
  5732. org-archive-tag)))))
  5733. (defun org-agenda-toggle-diary ()
  5734. "Toggle diary inclusion in an agenda buffer."
  5735. (interactive)
  5736. (org-agenda-check-type t 'agenda)
  5737. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5738. (org-agenda-redo)
  5739. (org-agenda-set-mode-name)
  5740. (message "Diary inclusion turned %s"
  5741. (if org-agenda-include-diary "on" "off")))
  5742. (defun org-agenda-toggle-deadlines ()
  5743. "Toggle diary inclusion in an agenda buffer."
  5744. (interactive)
  5745. (org-agenda-check-type t 'agenda)
  5746. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5747. (org-agenda-redo)
  5748. (org-agenda-set-mode-name)
  5749. (message "Deadlines inclusion turned %s"
  5750. (if org-agenda-include-deadlines "on" "off")))
  5751. (defun org-agenda-toggle-time-grid ()
  5752. "Toggle time grid in an agenda buffer."
  5753. (interactive)
  5754. (org-agenda-check-type t 'agenda)
  5755. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5756. (org-agenda-redo)
  5757. (org-agenda-set-mode-name)
  5758. (message "Time-grid turned %s"
  5759. (if org-agenda-use-time-grid "on" "off")))
  5760. (defun org-agenda-set-mode-name ()
  5761. "Set the mode name to indicate all the small mode settings."
  5762. (setq mode-name
  5763. (concat "Org-Agenda"
  5764. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5765. (if (equal org-agenda-ndays 1) " Day" "")
  5766. (if (equal org-agenda-ndays 7) " Week" "")
  5767. (if org-agenda-follow-mode " Follow" "")
  5768. (if org-agenda-entry-text-mode " ETxt" "")
  5769. (if org-agenda-include-diary " Diary" "")
  5770. (if org-agenda-include-deadlines " Ddl" "")
  5771. (if org-agenda-use-time-grid " Grid" "")
  5772. (if (and (boundp 'org-habit-show-habits)
  5773. org-habit-show-habits) " Habit" "")
  5774. (if (consp org-agenda-show-log) " LogAll"
  5775. (if org-agenda-show-log " Log" ""))
  5776. (if (or org-agenda-filter (get 'org-agenda-filter
  5777. :preset-filter))
  5778. (concat " {" (mapconcat
  5779. 'identity
  5780. (append (get 'org-agenda-filter
  5781. :preset-filter)
  5782. org-agenda-filter) "") "}")
  5783. "")
  5784. (if org-agenda-archives-mode
  5785. (if (eq org-agenda-archives-mode t)
  5786. " Archives"
  5787. (format " :%s:" org-archive-tag))
  5788. "")
  5789. (if org-agenda-clockreport-mode
  5790. (if (eq org-agenda-clockreport-mode 'with-filter)
  5791. " Clock{}" " Clock")
  5792. "")))
  5793. (force-mode-line-update))
  5794. (defun org-agenda-post-command-hook ()
  5795. (setq org-agenda-type
  5796. (or (get-text-property (point) 'org-agenda-type)
  5797. (get-text-property (max (point-min) (1- (point)))
  5798. 'org-agenda-type))))
  5799. (defun org-agenda-next-line ()
  5800. "Move cursor to the next line, and show if follow mode is active."
  5801. (interactive)
  5802. (call-interactively 'next-line)
  5803. (org-agenda-do-context-action))
  5804. (defun org-agenda-previous-line ()
  5805. "Move cursor to the previous line, and show if follow-mode is active."
  5806. (interactive)
  5807. (call-interactively 'previous-line)
  5808. (org-agenda-do-context-action))
  5809. (defun org-agenda-do-context-action ()
  5810. "Show outline path and, maybe, follow mode window."
  5811. (let ((m (org-get-at-bol 'org-marker)))
  5812. (if (and org-agenda-follow-mode m)
  5813. (org-agenda-show))
  5814. (if (and m org-agenda-show-outline-path)
  5815. (org-with-point-at m
  5816. (org-display-outline-path t)))))
  5817. (defun org-agenda-show-priority ()
  5818. "Show the priority of the current item.
  5819. This priority is composed of the main priority given with the [#A] cookies,
  5820. and by additional input from the age of a schedules or deadline entry."
  5821. (interactive)
  5822. (let* ((pri (org-get-at-bol 'priority)))
  5823. (message "Priority is %d" (if pri pri -1000))))
  5824. (defun org-agenda-show-tags ()
  5825. "Show the tags applicable to the current item."
  5826. (interactive)
  5827. (let* ((tags (org-get-at-bol 'tags)))
  5828. (if tags
  5829. (message "Tags are :%s:"
  5830. (org-no-properties (mapconcat 'identity tags ":")))
  5831. (message "No tags associated with this line"))))
  5832. (defun org-agenda-goto (&optional highlight)
  5833. "Go to the Org-mode file which contains the item at point."
  5834. (interactive)
  5835. (let* ((marker (or (org-get-at-bol 'org-marker)
  5836. (org-agenda-error)))
  5837. (buffer (marker-buffer marker))
  5838. (pos (marker-position marker)))
  5839. (switch-to-buffer-other-window buffer)
  5840. (widen)
  5841. (push-mark)
  5842. (goto-char pos)
  5843. (when (org-mode-p)
  5844. (org-show-context 'agenda)
  5845. (save-excursion
  5846. (and (outline-next-heading)
  5847. (org-flag-heading nil)))) ; show the next heading
  5848. (recenter (/ (window-height) 2))
  5849. (run-hooks 'org-agenda-after-show-hook)
  5850. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5851. (defvar org-agenda-after-show-hook nil
  5852. "Normal hook run after an item has been shown from the agenda.
  5853. Point is in the buffer where the item originated.")
  5854. (defun org-agenda-kill ()
  5855. "Kill the entry or subtree belonging to the current agenda entry."
  5856. (interactive)
  5857. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5858. (let* ((marker (or (org-get-at-bol 'org-marker)
  5859. (org-agenda-error)))
  5860. (buffer (marker-buffer marker))
  5861. (pos (marker-position marker))
  5862. (type (org-get-at-bol 'type))
  5863. dbeg dend (n 0) conf)
  5864. (org-with-remote-undo buffer
  5865. (with-current-buffer buffer
  5866. (save-excursion
  5867. (goto-char pos)
  5868. (if (and (org-mode-p) (not (member type '("sexp"))))
  5869. (setq dbeg (progn (org-back-to-heading t) (point))
  5870. dend (org-end-of-subtree t t))
  5871. (setq dbeg (point-at-bol)
  5872. dend (min (point-max) (1+ (point-at-eol)))))
  5873. (goto-char dbeg)
  5874. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5875. (setq conf (or (eq t org-agenda-confirm-kill)
  5876. (and (numberp org-agenda-confirm-kill)
  5877. (> n org-agenda-confirm-kill))))
  5878. (and conf
  5879. (not (y-or-n-p
  5880. (format "Delete entry with %d lines in buffer \"%s\"? "
  5881. n (buffer-name buffer))))
  5882. (error "Abort"))
  5883. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5884. (with-current-buffer buffer (delete-region dbeg dend))
  5885. (message "Agenda item and source killed"))))
  5886. (defvar org-archive-default-command)
  5887. (defun org-agenda-archive-default ()
  5888. "Archive the entry or subtree belonging to the current agenda entry."
  5889. (interactive)
  5890. (require 'org-archive)
  5891. (org-agenda-archive-with org-archive-default-command))
  5892. (defun org-agenda-archive-default-with-confirmation ()
  5893. "Archive the entry or subtree belonging to the current agenda entry."
  5894. (interactive)
  5895. (require 'org-archive)
  5896. (org-agenda-archive-with org-archive-default-command 'confirm))
  5897. (defun org-agenda-archive ()
  5898. "Archive the entry or subtree belonging to the current agenda entry."
  5899. (interactive)
  5900. (org-agenda-archive-with 'org-archive-subtree))
  5901. (defun org-agenda-archive-to-archive-sibling ()
  5902. "Move the entry to the archive sibling."
  5903. (interactive)
  5904. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5905. (defun org-agenda-archive-with (cmd &optional confirm)
  5906. "Move the entry to the archive sibling."
  5907. (interactive)
  5908. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5909. (let* ((marker (or (org-get-at-bol 'org-marker)
  5910. (org-agenda-error)))
  5911. (buffer (marker-buffer marker))
  5912. (pos (marker-position marker)))
  5913. (org-with-remote-undo buffer
  5914. (with-current-buffer buffer
  5915. (if (org-mode-p)
  5916. (if (and confirm
  5917. (not (y-or-n-p "Archive this subtree or entry? ")))
  5918. (error "Abort")
  5919. (save-excursion
  5920. (goto-char pos)
  5921. (org-remove-subtree-entries-from-agenda)
  5922. (org-back-to-heading t)
  5923. (funcall cmd)))
  5924. (error "Archiving works only in Org-mode files"))))))
  5925. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5926. "Remove all lines in the agenda that correspond to a given subtree.
  5927. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5928. If this information is not given, the function uses the tree at point."
  5929. (let ((buf (or buf (current-buffer))) m p)
  5930. (save-excursion
  5931. (unless (and beg end)
  5932. (org-back-to-heading t)
  5933. (setq beg (point))
  5934. (org-end-of-subtree t)
  5935. (setq end (point)))
  5936. (set-buffer (get-buffer org-agenda-buffer-name))
  5937. (save-excursion
  5938. (goto-char (point-max))
  5939. (beginning-of-line 1)
  5940. (while (not (bobp))
  5941. (when (and (setq m (org-get-at-bol 'org-marker))
  5942. (equal buf (marker-buffer m))
  5943. (setq p (marker-position m))
  5944. (>= p beg)
  5945. (< p end))
  5946. (let ((inhibit-read-only t))
  5947. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5948. (beginning-of-line 0))))))
  5949. (defun org-agenda-refile (&optional goto rfloc no-update)
  5950. "Refile the item at point."
  5951. (interactive "P")
  5952. (if (equal goto '(16))
  5953. (org-refile-goto-last-stored)
  5954. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5955. (org-agenda-error)))
  5956. (buffer (marker-buffer marker))
  5957. (pos (marker-position marker))
  5958. (rfloc (or rfloc
  5959. (org-refile-get-location
  5960. (if goto "Goto: " "Refile to: ") buffer
  5961. org-refile-allow-creating-parent-nodes))))
  5962. (with-current-buffer buffer
  5963. (save-excursion
  5964. (save-restriction
  5965. (widen)
  5966. (goto-char marker)
  5967. (org-remove-subtree-entries-from-agenda)
  5968. (org-refile goto buffer rfloc)))))
  5969. (unless no-update (org-agenda-redo))))
  5970. (defun org-agenda-open-link (&optional arg)
  5971. "Follow the link in the current line, if any.
  5972. This looks for a link in the displayed line in the agenda. It also looks
  5973. at the text of the entry itself."
  5974. (interactive "P")
  5975. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5976. (org-get-at-bol 'org-marker)))
  5977. (buffer (and marker (marker-buffer marker)))
  5978. (prefix (buffer-substring
  5979. (point-at-bol)
  5980. (+ (point-at-bol)
  5981. (or (org-get-at-bol 'prefix-length) 0)))))
  5982. (cond
  5983. (buffer
  5984. (with-current-buffer buffer
  5985. (save-excursion
  5986. (save-restriction
  5987. (widen)
  5988. (goto-char marker)
  5989. (org-offer-links-in-entry arg prefix)))))
  5990. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5991. (save-excursion
  5992. (beginning-of-line 1)
  5993. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5994. (org-open-link-from-string (match-string 1)))
  5995. (t (error "No link to open here")))))
  5996. (defun org-agenda-copy-local-variable (var)
  5997. "Get a variable from a referenced buffer and install it here."
  5998. (let ((m (org-get-at-bol 'org-marker)))
  5999. (when (and m (buffer-live-p (marker-buffer m)))
  6000. (org-set-local var (with-current-buffer (marker-buffer m)
  6001. (symbol-value var))))))
  6002. (defun org-agenda-switch-to (&optional delete-other-windows)
  6003. "Go to the Org-mode file which contains the item at point."
  6004. (interactive)
  6005. (if (and org-return-follows-link
  6006. (not (org-get-at-bol 'org-marker))
  6007. (org-in-regexp org-bracket-link-regexp))
  6008. (org-open-link-from-string (match-string 0))
  6009. (let* ((marker (or (org-get-at-bol 'org-marker)
  6010. (org-agenda-error)))
  6011. (buffer (marker-buffer marker))
  6012. (pos (marker-position marker)))
  6013. (switch-to-buffer buffer)
  6014. (and delete-other-windows (delete-other-windows))
  6015. (widen)
  6016. (goto-char pos)
  6017. (when (org-mode-p)
  6018. (org-show-context 'agenda)
  6019. (save-excursion
  6020. (and (outline-next-heading)
  6021. (org-flag-heading nil))))))) ; show the next heading
  6022. (defun org-agenda-goto-mouse (ev)
  6023. "Go to the Org-mode file which contains the item at the mouse click."
  6024. (interactive "e")
  6025. (mouse-set-point ev)
  6026. (org-agenda-goto))
  6027. (defun org-agenda-show (&optional full-entry)
  6028. "Display the Org-mode file which contains the item at point.
  6029. With prefix argument FULL-ENTRY, make the entire entry visible
  6030. if it was hidden in the outline."
  6031. (interactive "P")
  6032. (let ((win (selected-window)))
  6033. (if full-entry
  6034. (let ((org-show-entry-below t))
  6035. (org-agenda-goto t))
  6036. (org-agenda-goto t))
  6037. (select-window win)))
  6038. (defvar org-agenda-show-window nil)
  6039. (defun org-agenda-show-and-scroll-up ()
  6040. "Display the Org-mode file which contains the item at point.
  6041. When called repeatedly, scroll the window that is displaying the buffer."
  6042. (interactive)
  6043. (let ((win (selected-window)))
  6044. (if (and (window-live-p org-agenda-show-window)
  6045. (eq this-command last-command))
  6046. (progn
  6047. (select-window org-agenda-show-window)
  6048. (ignore-errors (scroll-up)))
  6049. (org-agenda-goto t)
  6050. (show-subtree)
  6051. (setq org-agenda-show-window (selected-window)))
  6052. (select-window win)))
  6053. (defun org-agenda-show-scroll-down ()
  6054. "Scroll down the window showing the agenda."
  6055. (interactive)
  6056. (let ((win (selected-window)))
  6057. (when (window-live-p org-agenda-show-window)
  6058. (select-window org-agenda-show-window)
  6059. (ignore-errors (scroll-down))
  6060. (select-window win))))
  6061. (defun org-agenda-show-1 (&optional more)
  6062. "Display the Org-mode file which contains the item at point.
  6063. The prefix arg selects the amount of information to display:
  6064. 0 hide the subtree
  6065. 1 just show the entry according to defaults.
  6066. 2 show the children view
  6067. 3 show the subtree view
  6068. 4 show the entire subtree and any LOGBOOK drawers
  6069. 5 show the entire subtree and any drawers
  6070. With prefix argument FULL-ENTRY, make the entire entry visible
  6071. if it was hidden in the outline."
  6072. (interactive "p")
  6073. (let ((win (selected-window)))
  6074. (org-agenda-goto t)
  6075. (org-recenter-heading 1)
  6076. (cond
  6077. ((= more 0)
  6078. (hide-subtree)
  6079. (save-excursion
  6080. (org-back-to-heading)
  6081. (run-hook-with-args 'org-cycle-hook 'folded))
  6082. (message "Remote: FOLDED"))
  6083. ((and (interactive-p) (= more 1))
  6084. (message "Remote: show with default settings"))
  6085. ((= more 2)
  6086. (show-entry)
  6087. (show-children)
  6088. (save-excursion
  6089. (org-back-to-heading)
  6090. (run-hook-with-args 'org-cycle-hook 'children))
  6091. (message "Remote: CHILDREN"))
  6092. ((= more 3)
  6093. (show-subtree)
  6094. (save-excursion
  6095. (org-back-to-heading)
  6096. (run-hook-with-args 'org-cycle-hook 'subtree))
  6097. (message "Remote: SUBTREE"))
  6098. ((= more 4)
  6099. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6100. (org-drawer-regexp
  6101. (concat "^[ \t]*:\\("
  6102. (mapconcat 'regexp-quote org-drawers "\\|")
  6103. "\\):[ \t]*$")))
  6104. (show-subtree)
  6105. (save-excursion
  6106. (org-back-to-heading)
  6107. (org-cycle-hide-drawers 'subtree)))
  6108. (message "Remote: SUBTREE AND LOGBOOK"))
  6109. ((> more 4)
  6110. (show-subtree)
  6111. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6112. (select-window win)))
  6113. (defun org-recenter-heading (n)
  6114. (save-excursion
  6115. (org-back-to-heading)
  6116. (recenter n)))
  6117. (defvar org-agenda-cycle-counter nil)
  6118. (defun org-agenda-cycle-show (&optional n)
  6119. "Show the current entry in another window, with default settings.
  6120. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6121. When use repeatedly in immediate succession, the remote entry will cycle
  6122. through visibility
  6123. children -> subtree -> folded
  6124. When called with a numeric prefix arg, that arg will be passed through to
  6125. `org-agenda-show-1'. For the interpretation of that argument, see the
  6126. docstring of `org-agenda-show-1'."
  6127. (interactive "P")
  6128. (if (integerp n)
  6129. (setq org-agenda-cycle-counter n)
  6130. (if (not (eq last-command this-command))
  6131. (setq org-agenda-cycle-counter 1)
  6132. (if (equal org-agenda-cycle-counter 0)
  6133. (setq org-agenda-cycle-counter 2)
  6134. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6135. (if (> org-agenda-cycle-counter 3)
  6136. (setq org-agenda-cycle-counter 0)))))
  6137. (org-agenda-show-1 org-agenda-cycle-counter))
  6138. (defun org-agenda-recenter (arg)
  6139. "Display the Org-mode file which contains the item at point and recenter."
  6140. (interactive "P")
  6141. (let ((win (selected-window)))
  6142. (org-agenda-goto t)
  6143. (recenter arg)
  6144. (select-window win)))
  6145. (defun org-agenda-show-mouse (ev)
  6146. "Display the Org-mode file which contains the item at the mouse click."
  6147. (interactive "e")
  6148. (mouse-set-point ev)
  6149. (org-agenda-show))
  6150. (defun org-agenda-check-no-diary ()
  6151. "Check if the entry is a diary link and abort if yes."
  6152. (if (org-get-at-bol 'org-agenda-diary-link)
  6153. (org-agenda-error)))
  6154. (defun org-agenda-error ()
  6155. (error "Command not allowed in this line"))
  6156. (defun org-agenda-tree-to-indirect-buffer ()
  6157. "Show the subtree corresponding to the current entry in an indirect buffer.
  6158. This calls the command `org-tree-to-indirect-buffer' from the original
  6159. Org-mode buffer.
  6160. With numerical prefix arg ARG, go up to this level and then take that tree.
  6161. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6162. use the dedicated frame)."
  6163. (interactive)
  6164. (org-agenda-check-no-diary)
  6165. (let* ((marker (or (org-get-at-bol 'org-marker)
  6166. (org-agenda-error)))
  6167. (buffer (marker-buffer marker))
  6168. (pos (marker-position marker)))
  6169. (with-current-buffer buffer
  6170. (save-excursion
  6171. (goto-char pos)
  6172. (call-interactively 'org-tree-to-indirect-buffer)))))
  6173. (defvar org-last-heading-marker (make-marker)
  6174. "Marker pointing to the headline that last changed its TODO state
  6175. by a remote command from the agenda.")
  6176. (defun org-agenda-todo-nextset ()
  6177. "Switch TODO entry to next sequence."
  6178. (interactive)
  6179. (org-agenda-todo 'nextset))
  6180. (defun org-agenda-todo-previousset ()
  6181. "Switch TODO entry to previous sequence."
  6182. (interactive)
  6183. (org-agenda-todo 'previousset))
  6184. (defun org-agenda-todo (&optional arg)
  6185. "Cycle TODO state of line at point, also in Org-mode file.
  6186. This changes the line at point, all other lines in the agenda referring to
  6187. the same tree node, and the headline of the tree node in the Org-mode file."
  6188. (interactive "P")
  6189. (org-agenda-check-no-diary)
  6190. (let* ((col (current-column))
  6191. (marker (or (org-get-at-bol 'org-marker)
  6192. (org-agenda-error)))
  6193. (buffer (marker-buffer marker))
  6194. (pos (marker-position marker))
  6195. (hdmarker (org-get-at-bol 'org-hd-marker))
  6196. (todayp (equal (org-get-at-bol 'day)
  6197. (time-to-days (current-time))))
  6198. (inhibit-read-only t)
  6199. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6200. (org-with-remote-undo buffer
  6201. (with-current-buffer buffer
  6202. (widen)
  6203. (goto-char pos)
  6204. (org-show-context 'agenda)
  6205. (save-excursion
  6206. (and (outline-next-heading)
  6207. (org-flag-heading nil))) ; show the next heading
  6208. (let ((current-prefix-arg arg))
  6209. (call-interactively 'org-todo))
  6210. (and (bolp) (forward-char 1))
  6211. (setq newhead (org-get-heading))
  6212. (when (and (org-bound-and-true-p
  6213. org-agenda-headline-snapshot-before-repeat)
  6214. (not (equal org-agenda-headline-snapshot-before-repeat
  6215. newhead))
  6216. todayp)
  6217. (setq newhead org-agenda-headline-snapshot-before-repeat
  6218. just-one t))
  6219. (save-excursion
  6220. (org-back-to-heading)
  6221. (move-marker org-last-heading-marker (point))))
  6222. (beginning-of-line 1)
  6223. (save-excursion
  6224. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6225. (org-move-to-column col))))
  6226. (defun org-agenda-add-note (&optional arg)
  6227. "Add a time-stamped note to the entry at point."
  6228. (interactive "P")
  6229. (org-agenda-check-no-diary)
  6230. (let* ((marker (or (org-get-at-bol 'org-marker)
  6231. (org-agenda-error)))
  6232. (buffer (marker-buffer marker))
  6233. (pos (marker-position marker))
  6234. (hdmarker (org-get-at-bol 'org-hd-marker))
  6235. (inhibit-read-only t))
  6236. (with-current-buffer buffer
  6237. (widen)
  6238. (goto-char pos)
  6239. (org-show-context 'agenda)
  6240. (save-excursion
  6241. (and (outline-next-heading)
  6242. (org-flag-heading nil))) ; show the next heading
  6243. (org-add-note))))
  6244. (defun org-agenda-change-all-lines (newhead hdmarker
  6245. &optional fixface just-this)
  6246. "Change all lines in the agenda buffer which match HDMARKER.
  6247. The new content of the line will be NEWHEAD (as modified by
  6248. `org-format-agenda-item'). HDMARKER is checked with
  6249. `equal' against all `org-hd-marker' text properties in the file.
  6250. If FIXFACE is non-nil, the face of each item is modified according to
  6251. the new TODO state.
  6252. If JUST-THIS is non-nil, change just the current line, not all.
  6253. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6254. (let* ((inhibit-read-only t)
  6255. (line (org-current-line))
  6256. (thetags (with-current-buffer (marker-buffer hdmarker)
  6257. (save-excursion (save-restriction (widen)
  6258. (goto-char hdmarker)
  6259. (org-get-tags-at)))))
  6260. props m pl undone-face done-face finish new dotime cat tags)
  6261. (save-excursion
  6262. (goto-char (point-max))
  6263. (beginning-of-line 1)
  6264. (while (not finish)
  6265. (setq finish (bobp))
  6266. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6267. (or (not just-this) (= (org-current-line) line))
  6268. (equal m hdmarker))
  6269. (setq props (text-properties-at (point))
  6270. dotime (org-get-at-bol 'dotime)
  6271. cat (org-get-at-bol 'org-category)
  6272. tags thetags
  6273. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6274. pl (org-get-at-bol 'prefix-length)
  6275. undone-face (org-get-at-bol 'undone-face)
  6276. done-face (org-get-at-bol 'done-face))
  6277. (goto-char (+ (point) pl))
  6278. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6279. (cond
  6280. ((equal new "")
  6281. (beginning-of-line 1)
  6282. (and (looking-at ".*\n?") (replace-match "")))
  6283. ((looking-at ".*")
  6284. (replace-match new t t)
  6285. (beginning-of-line 1)
  6286. (add-text-properties (point-at-bol) (point-at-eol) props)
  6287. (when fixface
  6288. (add-text-properties
  6289. (point-at-bol) (point-at-eol)
  6290. (list 'face
  6291. (if org-last-todo-state-is-todo
  6292. undone-face done-face))))
  6293. (org-agenda-highlight-todo 'line)
  6294. (beginning-of-line 1))
  6295. (t (error "Line update did not work"))))
  6296. (beginning-of-line 0)))
  6297. (org-finalize-agenda)))
  6298. (defun org-agenda-align-tags (&optional line)
  6299. "Align all tags in agenda items to `org-agenda-tags-column'."
  6300. (let ((inhibit-read-only t) l c)
  6301. (save-excursion
  6302. (goto-char (if line (point-at-bol) (point-min)))
  6303. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6304. (if line (point-at-eol) nil) t)
  6305. (add-text-properties
  6306. (match-beginning 2) (match-end 2)
  6307. (list 'face (delq nil (let ((prop (get-text-property
  6308. (match-beginning 2) 'face)))
  6309. (or (listp prop) (setq prop (list prop)))
  6310. (if (memq 'org-tag prop)
  6311. prop
  6312. (cons 'org-tag prop))))))
  6313. (setq l (- (match-end 2) (match-beginning 2))
  6314. c (if (< org-agenda-tags-column 0)
  6315. (- (abs org-agenda-tags-column) l)
  6316. org-agenda-tags-column))
  6317. (delete-region (match-beginning 1) (match-end 1))
  6318. (goto-char (match-beginning 1))
  6319. (insert (org-add-props
  6320. (make-string (max 1 (- c (current-column))) ?\ )
  6321. (plist-put (copy-sequence (text-properties-at (point)))
  6322. 'face nil))))
  6323. (goto-char (point-min))
  6324. (org-font-lock-add-tag-faces (point-max)))))
  6325. (defun org-agenda-priority-up ()
  6326. "Increase the priority of line at point, also in Org-mode file."
  6327. (interactive)
  6328. (org-agenda-priority 'up))
  6329. (defun org-agenda-priority-down ()
  6330. "Decrease the priority of line at point, also in Org-mode file."
  6331. (interactive)
  6332. (org-agenda-priority 'down))
  6333. (defun org-agenda-priority (&optional force-direction)
  6334. "Set the priority of line at point, also in Org-mode file.
  6335. This changes the line at point, all other lines in the agenda referring to
  6336. the same tree node, and the headline of the tree node in the Org-mode file."
  6337. (interactive)
  6338. (unless org-enable-priority-commands
  6339. (error "Priority commands are disabled"))
  6340. (org-agenda-check-no-diary)
  6341. (let* ((marker (or (org-get-at-bol 'org-marker)
  6342. (org-agenda-error)))
  6343. (hdmarker (org-get-at-bol 'org-hd-marker))
  6344. (buffer (marker-buffer hdmarker))
  6345. (pos (marker-position hdmarker))
  6346. (inhibit-read-only t)
  6347. newhead)
  6348. (org-with-remote-undo buffer
  6349. (with-current-buffer buffer
  6350. (widen)
  6351. (goto-char pos)
  6352. (org-show-context 'agenda)
  6353. (save-excursion
  6354. (and (outline-next-heading)
  6355. (org-flag-heading nil))) ; show the next heading
  6356. (funcall 'org-priority force-direction)
  6357. (end-of-line 1)
  6358. (setq newhead (org-get-heading)))
  6359. (org-agenda-change-all-lines newhead hdmarker)
  6360. (beginning-of-line 1))))
  6361. ;; FIXME: should fix the tags property of the agenda line.
  6362. (defun org-agenda-set-tags (&optional tag onoff)
  6363. "Set tags for the current headline."
  6364. (interactive)
  6365. (org-agenda-check-no-diary)
  6366. (if (and (org-region-active-p) (interactive-p))
  6367. (call-interactively 'org-change-tag-in-region)
  6368. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6369. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6370. (org-agenda-error)))
  6371. (buffer (marker-buffer hdmarker))
  6372. (pos (marker-position hdmarker))
  6373. (inhibit-read-only t)
  6374. newhead)
  6375. (org-with-remote-undo buffer
  6376. (with-current-buffer buffer
  6377. (widen)
  6378. (goto-char pos)
  6379. (save-excursion
  6380. (org-show-context 'agenda))
  6381. (save-excursion
  6382. (and (outline-next-heading)
  6383. (org-flag-heading nil))) ; show the next heading
  6384. (goto-char pos)
  6385. (if tag
  6386. (org-toggle-tag tag onoff)
  6387. (call-interactively 'org-set-tags))
  6388. (end-of-line 1)
  6389. (setq newhead (org-get-heading)))
  6390. (org-agenda-change-all-lines newhead hdmarker)
  6391. (beginning-of-line 1)))))
  6392. (defun org-agenda-set-property ()
  6393. "Set a property for the current headline."
  6394. (interactive)
  6395. (org-agenda-check-no-diary)
  6396. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6397. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6398. (org-agenda-error)))
  6399. (buffer (marker-buffer hdmarker))
  6400. (pos (marker-position hdmarker))
  6401. (inhibit-read-only t)
  6402. newhead)
  6403. (org-with-remote-undo buffer
  6404. (with-current-buffer buffer
  6405. (widen)
  6406. (goto-char pos)
  6407. (save-excursion
  6408. (org-show-context 'agenda))
  6409. (save-excursion
  6410. (and (outline-next-heading)
  6411. (org-flag-heading nil))) ; show the next heading
  6412. (goto-char pos)
  6413. (call-interactively 'org-set-property)))))
  6414. (defun org-agenda-set-effort ()
  6415. "Set the effort property for the current headline."
  6416. (interactive)
  6417. (org-agenda-check-no-diary)
  6418. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6419. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6420. (org-agenda-error)))
  6421. (buffer (marker-buffer hdmarker))
  6422. (pos (marker-position hdmarker))
  6423. (inhibit-read-only t)
  6424. newhead)
  6425. (org-with-remote-undo buffer
  6426. (with-current-buffer buffer
  6427. (widen)
  6428. (goto-char pos)
  6429. (save-excursion
  6430. (org-show-context 'agenda))
  6431. (save-excursion
  6432. (and (outline-next-heading)
  6433. (org-flag-heading nil))) ; show the next heading
  6434. (goto-char pos)
  6435. (call-interactively 'org-set-effort)
  6436. (end-of-line 1)))))
  6437. (defun org-agenda-toggle-archive-tag ()
  6438. "Toggle the archive tag for the current entry."
  6439. (interactive)
  6440. (org-agenda-check-no-diary)
  6441. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6442. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6443. (org-agenda-error)))
  6444. (buffer (marker-buffer hdmarker))
  6445. (pos (marker-position hdmarker))
  6446. (inhibit-read-only t)
  6447. newhead)
  6448. (org-with-remote-undo buffer
  6449. (with-current-buffer buffer
  6450. (widen)
  6451. (goto-char pos)
  6452. (org-show-context 'agenda)
  6453. (save-excursion
  6454. (and (outline-next-heading)
  6455. (org-flag-heading nil))) ; show the next heading
  6456. (call-interactively 'org-toggle-archive-tag)
  6457. (end-of-line 1)
  6458. (setq newhead (org-get-heading)))
  6459. (org-agenda-change-all-lines newhead hdmarker)
  6460. (beginning-of-line 1))))
  6461. (defun org-agenda-do-date-later (arg)
  6462. (interactive "P")
  6463. (cond
  6464. ((or (equal arg '(16))
  6465. (memq last-command
  6466. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6467. (setq this-command 'org-agenda-date-later-minutes)
  6468. (org-agenda-date-later-minutes 1))
  6469. ((or (equal arg '(4))
  6470. (memq last-command
  6471. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6472. (setq this-command 'org-agenda-date-later-hours)
  6473. (org-agenda-date-later-hours 1))
  6474. (t
  6475. (org-agenda-date-later (prefix-numeric-value arg)))))
  6476. (defun org-agenda-do-date-earlier (arg)
  6477. (interactive "P")
  6478. (cond
  6479. ((or (equal arg '(16))
  6480. (memq last-command
  6481. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6482. (setq this-command 'org-agenda-date-earlier-minutes)
  6483. (org-agenda-date-earlier-minutes 1))
  6484. ((or (equal arg '(4))
  6485. (memq last-command
  6486. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6487. (setq this-command 'org-agenda-date-earlier-hours)
  6488. (org-agenda-date-earlier-hours 1))
  6489. (t
  6490. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6491. (defun org-agenda-date-later (arg &optional what)
  6492. "Change the date of this item to one day later."
  6493. (interactive "p")
  6494. (org-agenda-check-type t 'agenda 'timeline)
  6495. (org-agenda-check-no-diary)
  6496. (let* ((marker (or (org-get-at-bol 'org-marker)
  6497. (org-agenda-error)))
  6498. (buffer (marker-buffer marker))
  6499. (pos (marker-position marker)))
  6500. (org-with-remote-undo buffer
  6501. (with-current-buffer buffer
  6502. (widen)
  6503. (goto-char pos)
  6504. (if (not (org-at-timestamp-p))
  6505. (error "Cannot find time stamp"))
  6506. (org-timestamp-change arg (or what 'day)))
  6507. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6508. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6509. (defun org-agenda-date-earlier (arg &optional what)
  6510. "Change the date of this item to one day earlier."
  6511. (interactive "p")
  6512. (org-agenda-date-later (- arg) what))
  6513. (defun org-agenda-date-later-minutes (arg)
  6514. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6515. (interactive "p")
  6516. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6517. (org-agenda-date-later arg 'minute))
  6518. (defun org-agenda-date-earlier-minutes (arg)
  6519. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6520. (interactive "p")
  6521. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6522. (org-agenda-date-earlier arg 'minute))
  6523. (defun org-agenda-date-later-hours (arg)
  6524. "Change the time of this item, in hour steps."
  6525. (interactive "p")
  6526. (org-agenda-date-later arg 'hour))
  6527. (defun org-agenda-date-earlier-hours (arg)
  6528. "Change the time of this item, in hour steps."
  6529. (interactive "p")
  6530. (org-agenda-date-earlier arg 'hour))
  6531. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6532. "Show new date stamp via text properties."
  6533. ;; We use text properties to make this undoable
  6534. (let ((inhibit-read-only t)
  6535. (buffer-invisibility-spec))
  6536. (setq stamp (concat " " prefix " => " stamp))
  6537. (save-excursion
  6538. (goto-char (point-max))
  6539. (while (not (bobp))
  6540. (when (equal marker (org-get-at-bol 'org-marker))
  6541. (org-move-to-column (- (window-width) (length stamp)) t)
  6542. (org-agenda-fix-tags-filter-overlays-at (point))
  6543. (if (featurep 'xemacs)
  6544. ;; Use `duplicable' property to trigger undo recording
  6545. (let ((ex (make-extent nil nil))
  6546. (gl (make-glyph stamp)))
  6547. (set-glyph-face gl 'secondary-selection)
  6548. (set-extent-properties
  6549. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6550. (insert-extent ex (1- (point)) (point-at-eol)))
  6551. (add-text-properties
  6552. (1- (point)) (point-at-eol)
  6553. (list 'display (org-add-props stamp nil
  6554. 'face 'secondary-selection))))
  6555. (beginning-of-line 1))
  6556. (beginning-of-line 0)))))
  6557. (defun org-agenda-date-prompt (arg)
  6558. "Change the date of this item. Date is prompted for, with default today.
  6559. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6560. be used to request time specification in the time stamp."
  6561. (interactive "P")
  6562. (org-agenda-check-type t 'agenda 'timeline)
  6563. (org-agenda-check-no-diary)
  6564. (let* ((marker (or (org-get-at-bol 'org-marker)
  6565. (org-agenda-error)))
  6566. (buffer (marker-buffer marker))
  6567. (pos (marker-position marker)))
  6568. (org-with-remote-undo buffer
  6569. (with-current-buffer buffer
  6570. (widen)
  6571. (goto-char pos)
  6572. (if (not (org-at-timestamp-p t))
  6573. (error "Cannot find time stamp"))
  6574. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6575. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6576. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6577. (defun org-agenda-schedule (arg)
  6578. "Schedule the item at point.
  6579. Arg is passed through to `org-schedule'."
  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. (type (marker-insertion-type marker))
  6586. (buffer (marker-buffer marker))
  6587. (pos (marker-position marker))
  6588. (org-insert-labeled-timestamps-at-point nil)
  6589. ts)
  6590. (set-marker-insertion-type marker t)
  6591. (org-with-remote-undo buffer
  6592. (with-current-buffer buffer
  6593. (widen)
  6594. (goto-char pos)
  6595. (setq ts (org-schedule arg)))
  6596. (org-agenda-show-new-time marker ts "S"))
  6597. (message "Item scheduled for %s" ts)))
  6598. (defun org-agenda-deadline (arg)
  6599. "Schedule the item at point.
  6600. Arg is passed through to `org-deadline'."
  6601. (interactive "P")
  6602. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6603. (org-agenda-check-no-diary)
  6604. (let* ((marker (or (org-get-at-bol 'org-marker)
  6605. (org-agenda-error)))
  6606. (buffer (marker-buffer marker))
  6607. (pos (marker-position marker))
  6608. (org-insert-labeled-timestamps-at-point nil)
  6609. ts)
  6610. (org-with-remote-undo buffer
  6611. (with-current-buffer buffer
  6612. (widen)
  6613. (goto-char pos)
  6614. (setq ts (org-deadline arg)))
  6615. (org-agenda-show-new-time marker ts "D"))
  6616. (message "Deadline for this item set to %s" ts)))
  6617. (defun org-agenda-action ()
  6618. "Select entry for agenda action, or execute an agenda action.
  6619. This command prompts for another letter. Valid inputs are:
  6620. m Mark the entry at point for an agenda action
  6621. s Schedule the marked entry to the date at the cursor
  6622. d Set the deadline of the marked entry to the date at the cursor
  6623. r Call `org-remember' with cursor date as the default date
  6624. c Call `org-capture' with cursor date as the default date
  6625. SPC Show marked entry in other window
  6626. TAB Visit marked entry in other window
  6627. The cursor may be at a date in the calendar, or in the Org agenda."
  6628. (interactive)
  6629. (let (ans)
  6630. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6631. (setq ans (read-char-exclusive))
  6632. (cond
  6633. ((equal ans ?m)
  6634. ;; Mark this entry
  6635. (if (eq major-mode 'org-agenda-mode)
  6636. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6637. (org-get-at-bol 'org-marker))))
  6638. (if m
  6639. (progn
  6640. (move-marker org-agenda-action-marker
  6641. (marker-position m) (marker-buffer m))
  6642. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6643. (error "Don't know which entry to mark")))
  6644. (error "This command works only in the agenda")))
  6645. ((equal ans ?s)
  6646. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6647. ((equal ans ?d)
  6648. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6649. ((equal ans ?r)
  6650. (org-agenda-do-action '(org-remember) t))
  6651. ((equal ans ?c)
  6652. (org-agenda-do-action '(org-capture) t))
  6653. ((equal ans ?\ )
  6654. (let ((cw (selected-window)))
  6655. (org-switch-to-buffer-other-window
  6656. (marker-buffer org-agenda-action-marker))
  6657. (goto-char org-agenda-action-marker)
  6658. (org-show-context 'agenda)
  6659. (select-window cw)))
  6660. ((equal ans ?\C-i)
  6661. (org-switch-to-buffer-other-window
  6662. (marker-buffer org-agenda-action-marker))
  6663. (goto-char org-agenda-action-marker)
  6664. (org-show-context 'agenda))
  6665. (t (error "Invalid agenda action %c" ans)))))
  6666. (defun org-agenda-do-action (form &optional current-buffer)
  6667. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6668. (let ((org-overriding-default-time (org-get-cursor-date)))
  6669. (if current-buffer
  6670. (eval form)
  6671. (if (not (marker-buffer org-agenda-action-marker))
  6672. (error "No entry has been selected for agenda action")
  6673. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6674. (save-excursion
  6675. (save-restriction
  6676. (widen)
  6677. (goto-char org-agenda-action-marker)
  6678. (eval form))))))))
  6679. (defun org-agenda-clock-in (&optional arg)
  6680. "Start the clock on the currently selected item."
  6681. (interactive "P")
  6682. (org-agenda-check-no-diary)
  6683. (if (equal arg '(4))
  6684. (org-clock-in arg)
  6685. (let* ((marker (or (org-get-at-bol 'org-marker)
  6686. (org-agenda-error)))
  6687. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6688. marker))
  6689. (pos (marker-position marker))
  6690. newhead)
  6691. (org-with-remote-undo (marker-buffer marker)
  6692. (with-current-buffer (marker-buffer marker)
  6693. (widen)
  6694. (goto-char pos)
  6695. (org-show-context 'agenda)
  6696. (org-show-entry)
  6697. (org-cycle-hide-drawers 'children)
  6698. (org-clock-in arg)
  6699. (setq newhead (org-get-heading)))
  6700. (org-agenda-change-all-lines newhead hdmarker)))))
  6701. (defun org-agenda-clock-out ()
  6702. "Stop the currently running clock."
  6703. (interactive)
  6704. (unless (marker-buffer org-clock-marker)
  6705. (error "No running clock"))
  6706. (let ((marker (make-marker)) newhead)
  6707. (org-with-remote-undo (marker-buffer org-clock-marker)
  6708. (with-current-buffer (marker-buffer org-clock-marker)
  6709. (save-excursion
  6710. (save-restriction
  6711. (widen)
  6712. (goto-char org-clock-marker)
  6713. (org-back-to-heading t)
  6714. (move-marker marker (point))
  6715. (org-clock-out)
  6716. (setq newhead (org-get-heading))))))
  6717. (org-agenda-change-all-lines newhead marker)
  6718. (move-marker marker nil)))
  6719. (defun org-agenda-clock-cancel (&optional arg)
  6720. "Cancel the currently running clock."
  6721. (interactive "P")
  6722. (unless (marker-buffer org-clock-marker)
  6723. (error "No running clock"))
  6724. (org-with-remote-undo (marker-buffer org-clock-marker)
  6725. (org-clock-cancel)))
  6726. (defun org-agenda-clock-goto ()
  6727. "Jump to the currently clocked in task within the agenda.
  6728. If the currently clocked in task is not listed in the agenda
  6729. buffer, display it in another window."
  6730. (interactive)
  6731. (let (pos)
  6732. (mapc (lambda (o)
  6733. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6734. (setq pos (overlay-start o))))
  6735. (overlays-in (point-min) (point-max)))
  6736. (cond (pos (goto-char pos))
  6737. ;; If the currently clocked entry is not in the agenda
  6738. ;; buffer, we visit it in another window:
  6739. (org-clock-current-task
  6740. (org-switch-to-buffer-other-window (org-clock-goto)))
  6741. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6742. (defun org-agenda-diary-entry-in-org-file ()
  6743. "Make a diary entry in the file `org-agenda-diary-file'."
  6744. (let (d1 d2 char (text "") dp1 dp2)
  6745. (if (equal (buffer-name) "*Calendar*")
  6746. (setq d1 (calendar-cursor-to-date t)
  6747. d2 (car calendar-mark-ring))
  6748. (setq dp1 (get-text-property (point-at-bol) 'day))
  6749. (unless dp1 (error "No date defined in current line"))
  6750. (setq d1 (calendar-gregorian-from-absolute dp1)
  6751. d2 (and (ignore-errors (mark))
  6752. (save-excursion
  6753. (goto-char (mark))
  6754. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6755. (calendar-gregorian-from-absolute dp2))))
  6756. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6757. (setq char (read-char-exclusive))
  6758. (cond
  6759. ((equal char ?d)
  6760. (setq text (read-string "Day entry: "))
  6761. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6762. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6763. ((equal char ?a)
  6764. (setq d1 (list (car d1) (nth 1 d1)
  6765. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6766. (nth 2 d1))))
  6767. (setq text (read-string "Anniversary (use %d to show years): "))
  6768. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6769. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6770. ((equal char ?b)
  6771. (setq text (read-string "Block entry: "))
  6772. (unless (and d1 d2 (not (equal d1 d2)))
  6773. (error "No block of days selected"))
  6774. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6775. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6776. ((equal char ?j)
  6777. (org-switch-to-buffer-other-window
  6778. (find-file-noselect org-agenda-diary-file))
  6779. (require 'org-datetree)
  6780. (org-datetree-find-date-create d1)
  6781. (org-reveal t))
  6782. (t (error "Invalid selection character `%c'" char)))))
  6783. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6784. "Where in `org-agenda-diary-file' should new entries be added?
  6785. Valid values:
  6786. date-tree in the date tree, as child of the date
  6787. top-level as top-level entries at the end of the file."
  6788. :group 'org-agenda
  6789. :type '(choice
  6790. (const :tag "in a date tree" date-tree)
  6791. (const :tag "as top level at end of file" top-level)))
  6792. (defcustom org-agenda-insert-diary-extract-time nil
  6793. "Non-nil means extract any time specification from the diary entry."
  6794. :group 'org-agenda
  6795. :type 'boolean)
  6796. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6797. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6798. If TEXT is not empty, it will become the headline of the new entry, and
  6799. the resulting entry will not be shown. When TEXT is empty, switch to
  6800. `org-agenda-diary-file' and let the user finish the entry there."
  6801. (let ((cw (current-window-configuration)))
  6802. (org-switch-to-buffer-other-window
  6803. (find-file-noselect org-agenda-diary-file))
  6804. (widen)
  6805. (goto-char (point-min))
  6806. (cond
  6807. ((eq type 'anniversary)
  6808. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6809. (progn
  6810. (or (org-on-heading-p t)
  6811. (progn
  6812. (outline-next-heading)
  6813. (insert "* Anniversaries\n\n")
  6814. (beginning-of-line -1)))))
  6815. (outline-next-heading)
  6816. (org-back-over-empty-lines)
  6817. (backward-char 1)
  6818. (insert "\n")
  6819. (require 'diary-lib)
  6820. (let ((calendar-date-display-form
  6821. (if (if (boundp 'calendar-date-style)
  6822. (eq calendar-date-style 'european)
  6823. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  6824. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  6825. '(day " " month " " year)
  6826. '(month " " day " " year))))
  6827. (insert (format "%%%%(diary-anniversary %s) %s"
  6828. (calendar-date-string d1 nil t) text))))
  6829. ((eq type 'day)
  6830. (let ((org-prefix-has-time t)
  6831. (org-agenda-time-leading-zero t)
  6832. fmt time time2)
  6833. (if org-agenda-insert-diary-extract-time
  6834. ;; Use org-format-agenda-item to parse text for a time-range and
  6835. ;; remove it. FIXME: This is a hack, we should refactor
  6836. ;; that function to make time extraction available separately
  6837. (setq fmt (org-format-agenda-item nil text nil nil t)
  6838. time (get-text-property 0 'time fmt)
  6839. time2 (if (> (length time) 0)
  6840. ;; split-string removes trailing ...... if
  6841. ;; no end time given. First space
  6842. ;; separates time from date.
  6843. (concat " " (car (split-string time "\\.")))
  6844. nil)
  6845. text (get-text-property 0 'txt fmt)))
  6846. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6847. (org-agenda-insert-diary-as-top-level text)
  6848. (require 'org-datetree)
  6849. (org-datetree-find-date-create d1)
  6850. (org-agenda-insert-diary-make-new-entry text))
  6851. (org-insert-time-stamp (org-time-from-absolute
  6852. (calendar-absolute-from-gregorian d1))
  6853. nil nil nil nil time2))
  6854. (end-of-line 0))
  6855. ((eq type 'block)
  6856. (if (> (calendar-absolute-from-gregorian d1)
  6857. (calendar-absolute-from-gregorian d2))
  6858. (setq d1 (prog1 d2 (setq d2 d1))))
  6859. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6860. (org-agenda-insert-diary-as-top-level text)
  6861. (require 'org-datetree)
  6862. (org-datetree-find-date-create d1)
  6863. (org-agenda-insert-diary-make-new-entry text))
  6864. (org-insert-time-stamp (org-time-from-absolute
  6865. (calendar-absolute-from-gregorian d1)))
  6866. (insert "--")
  6867. (org-insert-time-stamp (org-time-from-absolute
  6868. (calendar-absolute-from-gregorian d2)))
  6869. (end-of-line 0)))
  6870. (if (string-match "\\S-" text)
  6871. (progn
  6872. (set-window-configuration cw)
  6873. (message "%s entry added to %s"
  6874. (capitalize (symbol-name type))
  6875. (abbreviate-file-name org-agenda-diary-file)))
  6876. (org-reveal t)
  6877. (message "Please finish entry here"))))
  6878. (defun org-agenda-insert-diary-as-top-level (text)
  6879. "Make new entry as a top-level entry at the end of the file.
  6880. Add TEXT as headline, and position the cursor in the second line so that
  6881. a timestamp can be added there."
  6882. (widen)
  6883. (goto-char (point-max))
  6884. (or (bolp) (insert "\n"))
  6885. (insert "* " text "\n")
  6886. (if org-adapt-indentation (org-indent-to-column 2)))
  6887. (defun org-agenda-insert-diary-make-new-entry (text)
  6888. "Make new entry as last child of current entry.
  6889. Add TEXT as headline, and position the cursor in the second line so that
  6890. a timestamp can be added there."
  6891. (let ((org-show-following-heading t)
  6892. (org-show-siblings t)
  6893. (org-show-hierarchy-above t)
  6894. (org-show-entry-below t)
  6895. col)
  6896. (outline-next-heading)
  6897. (org-back-over-empty-lines)
  6898. (or (looking-at "[ \t]*$")
  6899. (progn (insert "\n") (backward-char 1)))
  6900. (org-insert-heading nil t)
  6901. (org-do-demote)
  6902. (setq col (current-column))
  6903. (insert text "\n")
  6904. (if org-adapt-indentation (org-indent-to-column col))
  6905. (let ((org-show-following-heading t)
  6906. (org-show-siblings t)
  6907. (org-show-hierarchy-above t)
  6908. (org-show-entry-below t))
  6909. (org-show-context))))
  6910. (defun org-agenda-diary-entry ()
  6911. "Make a diary entry, like the `i' command from the calendar.
  6912. All the standard commands work: block, weekly etc.
  6913. When `org-agenda-diary-file' points to a file,
  6914. `org-agenda-diary-entry-in-org-file' is called instead to create
  6915. entries in that Org-mode file."
  6916. (interactive)
  6917. (org-agenda-check-type t 'agenda 'timeline)
  6918. (if (not (eq org-agenda-diary-file 'diary-file))
  6919. (org-agenda-diary-entry-in-org-file)
  6920. (require 'diary-lib)
  6921. (let* ((char (progn
  6922. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6923. (read-char-exclusive)))
  6924. (cmd (cdr (assoc char
  6925. '((?d . insert-diary-entry)
  6926. (?w . insert-weekly-diary-entry)
  6927. (?m . insert-monthly-diary-entry)
  6928. (?y . insert-yearly-diary-entry)
  6929. (?a . insert-anniversary-diary-entry)
  6930. (?b . insert-block-diary-entry)
  6931. (?c . insert-cyclic-diary-entry)))))
  6932. (oldf (symbol-function 'calendar-cursor-to-date))
  6933. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6934. (point (point))
  6935. (mark (or (mark t) (point))))
  6936. (unless cmd
  6937. (error "No command associated with <%c>" char))
  6938. (unless (and (get-text-property point 'day)
  6939. (or (not (equal ?b char))
  6940. (get-text-property mark 'day)))
  6941. (error "Don't know which date to use for diary entry"))
  6942. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6943. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6944. (let ((calendar-mark-ring
  6945. (list (calendar-gregorian-from-absolute
  6946. (or (get-text-property mark 'day)
  6947. (get-text-property point 'day))))))
  6948. (unwind-protect
  6949. (progn
  6950. (fset 'calendar-cursor-to-date
  6951. (lambda (&optional error dummy)
  6952. (calendar-gregorian-from-absolute
  6953. (get-text-property point 'day))))
  6954. (call-interactively cmd))
  6955. (fset 'calendar-cursor-to-date oldf))))))
  6956. (defun org-agenda-execute-calendar-command (cmd)
  6957. "Execute a calendar command from the agenda, with the date associated to
  6958. the cursor position."
  6959. (org-agenda-check-type t 'agenda 'timeline)
  6960. (require 'diary-lib)
  6961. (unless (get-text-property (point) 'day)
  6962. (error "Don't know which date to use for calendar command"))
  6963. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6964. (point (point))
  6965. (date (calendar-gregorian-from-absolute
  6966. (get-text-property point 'day)))
  6967. ;; the following 2 vars are needed in the calendar
  6968. (displayed-month (car date))
  6969. (displayed-year (nth 2 date)))
  6970. (unwind-protect
  6971. (progn
  6972. (fset 'calendar-cursor-to-date
  6973. (lambda (&optional error dummy)
  6974. (calendar-gregorian-from-absolute
  6975. (get-text-property point 'day))))
  6976. (call-interactively cmd))
  6977. (fset 'calendar-cursor-to-date oldf))))
  6978. (defun org-agenda-phases-of-moon ()
  6979. "Display the phases of the moon for the 3 months around the cursor date."
  6980. (interactive)
  6981. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6982. (defun org-agenda-holidays ()
  6983. "Display the holidays for the 3 months around the cursor date."
  6984. (interactive)
  6985. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6986. (defvar calendar-longitude)
  6987. (defvar calendar-latitude)
  6988. (defvar calendar-location-name)
  6989. (defun org-agenda-sunrise-sunset (arg)
  6990. "Display sunrise and sunset for the cursor date.
  6991. Latitude and longitude can be specified with the variables
  6992. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6993. argument, latitude and longitude will be prompted for."
  6994. (interactive "P")
  6995. (require 'solar)
  6996. (let ((calendar-longitude (if arg nil calendar-longitude))
  6997. (calendar-latitude (if arg nil calendar-latitude))
  6998. (calendar-location-name
  6999. (if arg "the given coordinates" calendar-location-name)))
  7000. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7001. (defun org-agenda-goto-calendar ()
  7002. "Open the Emacs calendar with the date at the cursor."
  7003. (interactive)
  7004. (org-agenda-check-type t 'agenda 'timeline)
  7005. (let* ((day (or (get-text-property (point) 'day)
  7006. (error "Don't know which date to open in calendar")))
  7007. (date (calendar-gregorian-from-absolute day))
  7008. (calendar-move-hook nil)
  7009. (calendar-view-holidays-initially-flag nil)
  7010. (calendar-view-diary-initially-flag nil))
  7011. (calendar)
  7012. (calendar-goto-date date)))
  7013. ;;;###autoload
  7014. (defun org-calendar-goto-agenda ()
  7015. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7016. This is a command that has to be installed in `calendar-mode-map'."
  7017. (interactive)
  7018. (org-agenda-list nil (calendar-absolute-from-gregorian
  7019. (calendar-cursor-to-date))
  7020. nil))
  7021. (defun org-agenda-convert-date ()
  7022. (interactive)
  7023. (org-agenda-check-type t 'agenda 'timeline)
  7024. (let ((day (get-text-property (point) 'day))
  7025. date s)
  7026. (unless day
  7027. (error "Don't know which date to convert"))
  7028. (setq date (calendar-gregorian-from-absolute day))
  7029. (setq s (concat
  7030. "Gregorian: " (calendar-date-string date) "\n"
  7031. "ISO: " (calendar-iso-date-string date) "\n"
  7032. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7033. "Julian: " (calendar-julian-date-string date) "\n"
  7034. "Astron. JD: " (calendar-astro-date-string date)
  7035. " (Julian date number at noon UTC)\n"
  7036. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7037. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7038. "French: " (calendar-french-date-string date) "\n"
  7039. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7040. "Mayan: " (calendar-mayan-date-string date) "\n"
  7041. "Coptic: " (calendar-coptic-date-string date) "\n"
  7042. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7043. "Persian: " (calendar-persian-date-string date) "\n"
  7044. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7045. (with-output-to-temp-buffer "*Dates*"
  7046. (princ s))
  7047. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7048. ;;; Bulk commands
  7049. (defvar org-agenda-bulk-marked-entries nil
  7050. "List of markers that refer to marked entries in the agenda.")
  7051. (defun org-agenda-bulk-marked-p ()
  7052. (eq (get-char-property (point-at-bol) 'type)
  7053. 'org-marked-entry-overlay))
  7054. (defun org-agenda-bulk-mark ()
  7055. "Mark the entry at point for future bulk action."
  7056. (interactive)
  7057. (org-agenda-check-no-diary)
  7058. (let* ((m (org-get-at-bol 'org-hd-marker))
  7059. ov)
  7060. (unless (org-agenda-bulk-marked-p)
  7061. (unless m (error "Nothing to mark at point"))
  7062. (push m org-agenda-bulk-marked-entries)
  7063. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7064. (org-overlay-display ov "> "
  7065. (org-get-todo-face "TODO")
  7066. 'evaporate)
  7067. (overlay-put ov 'type 'org-marked-entry-overlay))
  7068. (beginning-of-line 2)
  7069. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7070. (beginning-of-line 2))
  7071. (message "%d entries marked for bulk action"
  7072. (length org-agenda-bulk-marked-entries))))
  7073. (defun org-agenda-bulk-unmark ()
  7074. "Unmark the entry at point for future bulk action."
  7075. (interactive)
  7076. (when (org-agenda-bulk-marked-p)
  7077. (org-agenda-bulk-remove-overlays
  7078. (point-at-bol) (+ 2 (point-at-bol)))
  7079. (setq org-agenda-bulk-marked-entries
  7080. (delete (org-get-at-bol 'org-hd-marker)
  7081. org-agenda-bulk-marked-entries)))
  7082. (beginning-of-line 2)
  7083. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7084. (beginning-of-line 2))
  7085. (message "%d entries marked for bulk action"
  7086. (length org-agenda-bulk-marked-entries)))
  7087. (defun org-agenda-bulk-toggle ()
  7088. "Toggle marking the entry at point for bulk action."
  7089. (interactive)
  7090. (if (org-agenda-bulk-marked-p)
  7091. (org-agenda-bulk-unmark)
  7092. (org-agenda-bulk-mark)))
  7093. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7094. "Remove the mark overlays between BEG and END in the agenda buffer.
  7095. BEG and END default to the buffer limits.
  7096. This only removes the overlays, it does not remove the markers
  7097. from the list in `org-agenda-bulk-marked-entries'."
  7098. (interactive)
  7099. (mapc (lambda (ov)
  7100. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7101. (delete-overlay ov)))
  7102. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7103. (defun org-agenda-bulk-remove-all-marks ()
  7104. "Remove all marks in the agenda buffer.
  7105. This will remove the markers, and the overlays."
  7106. (interactive)
  7107. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7108. (setq org-agenda-bulk-marked-entries nil)
  7109. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7110. (defun org-agenda-bulk-action (&optional arg)
  7111. "Execute an remote-editing action on all marked entries.
  7112. The prefix arg is passed through to the command if possible."
  7113. (interactive "P")
  7114. (unless org-agenda-bulk-marked-entries
  7115. (error "No entries are marked"))
  7116. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7117. (let* ((action (read-char-exclusive))
  7118. (org-log-refile (if org-log-refile 'time nil))
  7119. (entries (reverse org-agenda-bulk-marked-entries))
  7120. redo-at-end
  7121. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7122. (cond
  7123. ((equal action ?$)
  7124. (setq cmd '(org-agenda-archive)))
  7125. ((equal action ?A)
  7126. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7127. ((member action '(?r ?w))
  7128. (setq rfloc (org-refile-get-location
  7129. "Refile to: "
  7130. (marker-buffer (car org-agenda-bulk-marked-entries))
  7131. org-refile-allow-creating-parent-nodes))
  7132. (if (nth 3 rfloc)
  7133. (setcar (nthcdr 3 rfloc)
  7134. (move-marker (make-marker) (nth 3 rfloc)
  7135. (or (get-file-buffer (nth 1 rfloc))
  7136. (find-buffer-visiting (nth 1 rfloc))
  7137. (error "This should not happen")))))
  7138. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7139. redo-at-end t))
  7140. ((equal action ?t)
  7141. (setq state (org-icompleting-read
  7142. "Todo state: "
  7143. (with-current-buffer (marker-buffer (car entries))
  7144. (mapcar 'list org-todo-keywords-1))))
  7145. (setq cmd `(let ((org-inhibit-blocking t)
  7146. (org-inhibit-logging 'note))
  7147. (org-agenda-todo ,state))))
  7148. ((memq action '(?- ?+))
  7149. (setq tag (org-icompleting-read
  7150. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7151. (with-current-buffer (marker-buffer (car entries))
  7152. (delq nil
  7153. (mapcar (lambda (x)
  7154. (if (stringp (car x)) x)) org-tag-alist)))))
  7155. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7156. ((memq action '(?s ?d))
  7157. (let* ((date (unless arg
  7158. (org-read-date
  7159. nil nil nil
  7160. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7161. (ans (if arg nil org-read-date-final-answer))
  7162. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7163. (setq cmd `(let* ((bound (fboundp 'read-string))
  7164. (old (and bound (symbol-function 'read-string))))
  7165. (unwind-protect
  7166. (progn
  7167. (fset 'read-string (lambda (&rest ignore) ,ans))
  7168. (eval '(,c1 arg)))
  7169. (if bound
  7170. (fset 'read-string old)
  7171. (fmakunbound 'read-string)))))))
  7172. (t (error "Invalid bulk action")))
  7173. ;; Sort the markers, to make sure that parents are handled before children
  7174. (setq entries (sort entries
  7175. (lambda (a b)
  7176. (cond
  7177. ((equal (marker-buffer a) (marker-buffer b))
  7178. (< (marker-position a) (marker-position b)))
  7179. (t
  7180. (string< (buffer-name (marker-buffer a))
  7181. (buffer-name (marker-buffer b))))))))
  7182. ;; Now loop over all markers and apply cmd
  7183. (while (setq e (pop entries))
  7184. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7185. (if (not pos)
  7186. (progn (message "Skipping removed entry at %s" e)
  7187. (setq cntskip (1+ cntskip)))
  7188. (goto-char pos)
  7189. (eval cmd)
  7190. (setq org-agenda-bulk-marked-entries
  7191. (delete e org-agenda-bulk-marked-entries))
  7192. (setq cnt (1+ cnt))))
  7193. (setq org-agenda-bulk-marked-entries nil)
  7194. (org-agenda-bulk-remove-all-marks)
  7195. (when redo-at-end (org-agenda-redo))
  7196. (message "Acted on %d entries%s"
  7197. cnt
  7198. (if (= cntskip 0)
  7199. ""
  7200. (format ", skipped %d (disappeared before their turn)"
  7201. cntskip)))))
  7202. ;;; Flagging notes
  7203. (defun org-agenda-show-the-flagging-note ()
  7204. "Display the flagging note in the other window.
  7205. When called a second time in direct sequence, offer to remove the FLAGGING
  7206. tag and (if present) the flagging note."
  7207. (interactive)
  7208. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7209. (win (selected-window))
  7210. note heading newhead)
  7211. (unless hdmarker
  7212. (error "No linked entry at point"))
  7213. (if (and (eq this-command last-command)
  7214. (y-or-n-p "Unflag and remove any flagging note? "))
  7215. (progn
  7216. (org-agenda-remove-flag hdmarker)
  7217. (let ((win (get-buffer-window "*Flagging Note*")))
  7218. (and win (delete-window win)))
  7219. (message "Entry unflaged"))
  7220. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7221. (unless note
  7222. (error "No flagging note"))
  7223. (org-kill-new note)
  7224. (org-switch-to-buffer-other-window "*Flagging Note*")
  7225. (erase-buffer)
  7226. (insert note)
  7227. (goto-char (point-min))
  7228. (while (re-search-forward "\\\\n" nil t)
  7229. (replace-match "\n" t t))
  7230. (goto-char (point-min))
  7231. (select-window win)
  7232. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7233. (defun org-agenda-remove-flag (marker)
  7234. "Remove the FLAGGED tag and any flagging note in the entry."
  7235. (let (newhead)
  7236. (org-with-point-at marker
  7237. (org-toggle-tag "FLAGGED" 'off)
  7238. (org-entry-delete nil "THEFLAGGINGNOTE")
  7239. (setq newhead (org-get-heading)))
  7240. (org-agenda-change-all-lines newhead marker)
  7241. (message "Entry unflaged")))
  7242. (defun org-agenda-get-any-marker (&optional pos)
  7243. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7244. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7245. ;;; Appointment reminders
  7246. (defvar appt-time-msg-list)
  7247. ;;;###autoload
  7248. (defun org-agenda-to-appt (&optional refresh filter)
  7249. "Activate appointments found in `org-agenda-files'.
  7250. With a \\[universal-argument] prefix, refresh the list of
  7251. appointments.
  7252. If FILTER is t, interactively prompt the user for a regular
  7253. expression, and filter out entries that don't match it.
  7254. If FILTER is a string, use this string as a regular expression
  7255. for filtering entries out.
  7256. FILTER can also be an alist with the car of each cell being
  7257. either 'headline or 'category. For example:
  7258. '((headline \"IMPORTANT\")
  7259. (category \"Work\"))
  7260. will only add headlines containing IMPORTANT or headlines
  7261. belonging to the \"Work\" category."
  7262. (interactive "P")
  7263. (if refresh (setq appt-time-msg-list nil))
  7264. (if (eq filter t)
  7265. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7266. (let* ((cnt 0) ; count added events
  7267. (org-agenda-new-buffers nil)
  7268. (org-deadline-warning-days 0)
  7269. (today (org-date-to-gregorian
  7270. (time-to-days (current-time))))
  7271. (org-agenda-restrict nil)
  7272. (files (org-agenda-files 'unrestricted)) entries file)
  7273. ;; Get all entries which may contain an appt
  7274. (org-prepare-agenda-buffers files)
  7275. (while (setq file (pop files))
  7276. (setq entries
  7277. (append entries
  7278. (org-agenda-get-day-entries
  7279. file today :timestamp :scheduled :deadline))))
  7280. (setq entries (delq nil entries))
  7281. ;; Map thru entries and find if we should filter them out
  7282. (mapc
  7283. (lambda(x)
  7284. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7285. (cat (get-text-property 1 'org-category x))
  7286. (tod (get-text-property 1 'time-of-day x))
  7287. (ok (or (null filter)
  7288. (and (stringp filter) (string-match filter evt))
  7289. (and (listp filter)
  7290. (or (string-match
  7291. (cadr (assoc 'category filter)) cat)
  7292. (string-match
  7293. (cadr (assoc 'headline filter)) evt))))))
  7294. ;; FIXME: Shall we remove text-properties for the appt text?
  7295. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7296. (when (and ok tod)
  7297. (setq tod (concat "00" (number-to-string tod))
  7298. tod (when (string-match
  7299. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7300. (concat (match-string 1 tod) ":"
  7301. (match-string 2 tod))))
  7302. (appt-add tod evt)
  7303. (setq cnt (1+ cnt))))) entries)
  7304. (org-release-buffers org-agenda-new-buffers)
  7305. (if (eq cnt 0)
  7306. (message "No event to add")
  7307. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7308. (defun org-agenda-todayp (date)
  7309. "Does DATE mean today, when considering `org-extend-today-until'?"
  7310. (let (today h)
  7311. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7312. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7313. (setq h (nth 2 (decode-time (current-time))))
  7314. (or (and (>= h org-extend-today-until)
  7315. (= date today))
  7316. (and (< h org-extend-today-until)
  7317. (= date (1- today))))))
  7318. (provide 'org-agenda)
  7319. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7320. ;;; org-agenda.el ends here