org-agenda.el 291 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  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: 6.34trans
  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. (require 'calendar))
  30. (declare-function diary-add-to-list "diary-lib"
  31. (date string specifier &optional marker globcolor literal))
  32. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  33. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  34. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  35. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  36. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  38. (declare-function calendar-french-date-string "cal-french" (&optional date))
  39. (declare-function calendar-goto-date "cal-move" (date))
  40. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  41. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  42. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  43. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  44. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  45. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  46. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  47. (declare-function org-datetree-find-date-create "org-datetree"
  48. (date &optional keep-restriction))
  49. (declare-function org-columns-quit "org-colview" ())
  50. (declare-function diary-date-display-form "diary-lib" (&optional type))
  51. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  52. (declare-function org-habit-insert-consistency-graphs
  53. "org-habit" (&optional line))
  54. (declare-function org-is-habit-p "org-habit" (&optional pom))
  55. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  56. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  57. (defvar calendar-mode-map)
  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 org-agenda-entry-text-mode and the
  128. variable `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. (defgroup org-agenda-custom-commands nil
  176. "Options concerning agenda views in Org-mode."
  177. :tag "Org Agenda Custom Commands"
  178. :group 'org-agenda)
  179. (defconst org-sorting-choice
  180. '(choice
  181. (const time-up) (const time-down)
  182. (const category-keep) (const category-up) (const category-down)
  183. (const tag-down) (const tag-up)
  184. (const priority-up) (const priority-down)
  185. (const todo-state-up) (const todo-state-down)
  186. (const effort-up) (const effort-down)
  187. (const habit-up) (const habit-down)
  188. (const user-defined-up) (const user-defined-down))
  189. "Sorting choices.")
  190. (defconst org-agenda-custom-commands-local-options
  191. `(repeat :tag "Local settings for this command. Remember to quote values"
  192. (choice :tag "Setting"
  193. (list :tag "Heading for this block"
  194. (const org-agenda-overriding-header)
  195. (string :tag "Headline"))
  196. (list :tag "Files to be searched"
  197. (const org-agenda-files)
  198. (list
  199. (const :format "" quote)
  200. (repeat (file))))
  201. (list :tag "Sorting strategy"
  202. (const org-agenda-sorting-strategy)
  203. (list
  204. (const :format "" quote)
  205. (repeat
  206. ,org-sorting-choice)))
  207. (list :tag "Prefix format"
  208. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  209. (string))
  210. (list :tag "Number of days in agenda"
  211. (const org-agenda-ndays)
  212. (integer :value 1))
  213. (list :tag "Fixed starting date"
  214. (const org-agenda-start-day)
  215. (string :value "2007-11-01"))
  216. (list :tag "Start on day of week"
  217. (const org-agenda-start-on-weekday)
  218. (choice :value 1
  219. (const :tag "Today" nil)
  220. (integer :tag "Weekday No.")))
  221. (list :tag "Include data from diary"
  222. (const org-agenda-include-diary)
  223. (boolean))
  224. (list :tag "Deadline Warning days"
  225. (const org-deadline-warning-days)
  226. (integer :value 1))
  227. (list :tag "Tags filter preset"
  228. (const org-agenda-filter-preset)
  229. (list
  230. (const :format "" quote)
  231. (repeat
  232. (string :tag "+tag or -tag"))))
  233. (list :tag "Set daily/weekly entry types"
  234. (const org-agenda-entry-types)
  235. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  236. (const :deadline)
  237. (const :scheduled)
  238. (const :timestamp)
  239. (const :sexp)))
  240. (list :tag "Standard skipping condition"
  241. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  242. (const org-agenda-skip-function)
  243. (list
  244. (const :format "" quote)
  245. (list
  246. (choice
  247. :tag "Skipping range"
  248. (const :tag "Skip entry" org-agenda-skip-entry-if)
  249. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  250. (repeat :inline t :tag "Conditions for skipping"
  251. (choice
  252. :tag "Condition type"
  253. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  254. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  255. (list :tag "TODO state is" :inline t
  256. (const 'todo)
  257. (choice
  258. (const :tag "any not-done state" 'todo)
  259. (const :tag "any done state" 'done)
  260. (const :tag "any state" 'any)
  261. (list :tag "Keyword list"
  262. (const :format "" quote)
  263. (repeat (string :tag "Keyword")))))
  264. (list :tag "TODO state is not" :inline t
  265. (const 'nottodo)
  266. (choice
  267. (const :tag "any not-done state" 'todo)
  268. (const :tag "any done state" 'done)
  269. (const :tag "any state" 'any)
  270. (list :tag "Keyword list"
  271. (const :format "" quote)
  272. (repeat (string :tag "Keyword")))))
  273. (const :tag "scheduled" 'scheduled)
  274. (const :tag "not scheduled" 'notscheduled)
  275. (const :tag "deadline" 'deadline)
  276. (const :tag "no deadline" 'notdeadline)
  277. (const :tag "timestamp" 'timestamp)
  278. (const :tag "no timestamp" 'nottimestamp))))))
  279. (list :tag "Non-standard skipping condition"
  280. :value (org-agenda-skip-function)
  281. (const org-agenda-skip-function)
  282. (sexp :tag "Function or form (quoted!)"))
  283. (list :tag "Any variable"
  284. (variable :tag "Variable")
  285. (sexp :tag "Value (sexp)"))))
  286. "Selection of examples for agenda command settings.
  287. This will be spliced into the custom type of
  288. `org-agenda-custom-commands'.")
  289. (defcustom org-agenda-custom-commands nil
  290. "Custom commands for the agenda.
  291. These commands will be offered on the splash screen displayed by the
  292. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  293. (key desc type match settings files)
  294. key The key (one or more characters as a string) to be associated
  295. with the command.
  296. desc A description of the command, when omitted or nil, a default
  297. description is built using MATCH.
  298. type The command type, any of the following symbols:
  299. agenda The daily/weekly agenda.
  300. todo Entries with a specific TODO keyword, in all agenda files.
  301. search Entries containing search words entry or headline.
  302. tags Tags/Property/TODO match in all agenda files.
  303. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  304. todo-tree Sparse tree of specific TODO keyword in *current* file.
  305. tags-tree Sparse tree with all tags matches in *current* file.
  306. occur-tree Occur sparse tree for *current* file.
  307. ... A user-defined function.
  308. match What to search for:
  309. - a single keyword for TODO keyword searches
  310. - a tags match expression for tags searches
  311. - a word search expression for text searches.
  312. - a regular expression for occur searches
  313. For all other commands, this should be the empty string.
  314. settings A list of option settings, similar to that in a let form, so like
  315. this: ((opt1 val1) (opt2 val2) ...). The values will be
  316. evaluated at the moment of execution, so quote them when needed.
  317. files A list of files file to write the produced agenda buffer to
  318. with the command `org-store-agenda-views'.
  319. If a file name ends in \".html\", an HTML version of the buffer
  320. is written out. If it ends in \".ps\", a postscript version is
  321. produced. Otherwise, only the plain text is written to the file.
  322. You can also define a set of commands, to create a composite agenda buffer.
  323. In this case, an entry looks like this:
  324. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  325. where
  326. desc A description string to be displayed in the dispatcher menu.
  327. cmd An agenda command, similar to the above. However, tree commands
  328. are no allowed, but instead you can get agenda and global todo list.
  329. So valid commands for a set are:
  330. (agenda \"\" settings)
  331. (alltodo \"\" settings)
  332. (stuck \"\" settings)
  333. (todo \"match\" settings files)
  334. (search \"match\" settings files)
  335. (tags \"match\" settings files)
  336. (tags-todo \"match\" settings files)
  337. Each command can carry a list of options, and another set of options can be
  338. given for the whole set of commands. Individual command options take
  339. precedence over the general options.
  340. When using several characters as key to a command, the first characters
  341. are prefix commands. For the dispatcher to display useful information, you
  342. should provide a description for the prefix, like
  343. (setq org-agenda-custom-commands
  344. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  345. (\"hl\" tags \"+HOME+Lisa\")
  346. (\"hp\" tags \"+HOME+Peter\")
  347. (\"hk\" tags \"+HOME+Kim\")))"
  348. :group 'org-agenda-custom-commands
  349. :type `(repeat
  350. (choice :value ("x" "Describe command here" tags "" nil)
  351. (list :tag "Single command"
  352. (string :tag "Access Key(s) ")
  353. (option (string :tag "Description"))
  354. (choice
  355. (const :tag "Agenda" agenda)
  356. (const :tag "TODO list" alltodo)
  357. (const :tag "Search words" search)
  358. (const :tag "Stuck projects" stuck)
  359. (const :tag "Tags/Property match (all agenda files)" tags)
  360. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  361. (const :tag "TODO keyword search (all agenda files)" todo)
  362. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  363. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  364. (const :tag "Occur tree (current buffer)" occur-tree)
  365. (sexp :tag "Other, user-defined function"))
  366. (string :tag "Match (only for some commands)")
  367. ,org-agenda-custom-commands-local-options
  368. (option (repeat :tag "Export" (file :tag "Export to"))))
  369. (list :tag "Command series, all agenda files"
  370. (string :tag "Access Key(s)")
  371. (string :tag "Description ")
  372. (repeat :tag "Component"
  373. (choice
  374. (list :tag "Agenda"
  375. (const :format "" agenda)
  376. (const :tag "" :format "" "")
  377. ,org-agenda-custom-commands-local-options)
  378. (list :tag "TODO list (all keywords)"
  379. (const :format "" alltodo)
  380. (const :tag "" :format "" "")
  381. ,org-agenda-custom-commands-local-options)
  382. (list :tag "Search words"
  383. (const :format "" search)
  384. (string :tag "Match")
  385. ,org-agenda-custom-commands-local-options)
  386. (list :tag "Stuck projects"
  387. (const :format "" stuck)
  388. (const :tag "" :format "" "")
  389. ,org-agenda-custom-commands-local-options)
  390. (list :tag "Tags search"
  391. (const :format "" tags)
  392. (string :tag "Match")
  393. ,org-agenda-custom-commands-local-options)
  394. (list :tag "Tags search, TODO entries only"
  395. (const :format "" tags-todo)
  396. (string :tag "Match")
  397. ,org-agenda-custom-commands-local-options)
  398. (list :tag "TODO keyword search"
  399. (const :format "" todo)
  400. (string :tag "Match")
  401. ,org-agenda-custom-commands-local-options)
  402. (list :tag "Other, user-defined function"
  403. (symbol :tag "function")
  404. (string :tag "Match")
  405. ,org-agenda-custom-commands-local-options)))
  406. (repeat :tag "Settings for entire command set"
  407. (list (variable :tag "Any variable")
  408. (sexp :tag "Value")))
  409. (option (repeat :tag "Export" (file :tag "Export to"))))
  410. (cons :tag "Prefix key documentation"
  411. (string :tag "Access Key(s)")
  412. (string :tag "Description ")))))
  413. (defcustom org-agenda-query-register ?o
  414. "The register holding the current query string.
  415. The purpose of this is that if you construct a query string interactively,
  416. you can then use it to define a custom command."
  417. :group 'org-agenda-custom-commands
  418. :type 'character)
  419. (defcustom org-stuck-projects
  420. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  421. "How to identify stuck projects.
  422. This is a list of four items:
  423. 1. A tags/todo/property matcher string that is used to identify a project.
  424. See the manual for a description of tag and property searches.
  425. The entire tree below a headline matched by this is considered one project.
  426. 2. A list of TODO keywords identifying non-stuck projects.
  427. If the project subtree contains any headline with one of these todo
  428. keywords, the project is considered to be not stuck. If you specify
  429. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  430. 3. A list of tags identifying non-stuck projects.
  431. If the project subtree contains any headline with one of these tags,
  432. the project is considered to be not stuck. If you specify \"*\" as
  433. a tag, any tag will mark the project unstuck. Note that this is about
  434. the explicit presence of a tag somewhere in the subtree, inherited
  435. tags to not count here. If inherited tags make a project not stuck,
  436. use \"-TAG\" in the tags part of the matcher under (1.) above.
  437. 4. An arbitrary regular expression matching non-stuck projects.
  438. If the project turns out to be not stuck, search continues also in the
  439. subtree to see if any of the subtasks have project status.
  440. See also the variable `org-tags-match-list-sublevels' which applies
  441. to projects matched by this search as well.
  442. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  443. or `C-c a #' to produce the list."
  444. :group 'org-agenda-custom-commands
  445. :type '(list
  446. (string :tag "Tags/TODO match to identify a project")
  447. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  448. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  449. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  450. (defcustom org-agenda-filter-effort-default-operator "<"
  451. "The default operator for effort estimate filtering.
  452. If you select an effort estimate limit without first pressing an operator,
  453. this one will be used."
  454. :group 'org-agenda-custom-commands
  455. :type '(choice (const :tag "less or equal" "<")
  456. (const :tag "greater or equal"">")
  457. (const :tag "equal" "=")))
  458. (defgroup org-agenda-skip nil
  459. "Options concerning skipping parts of agenda files."
  460. :tag "Org Agenda Skip"
  461. :group 'org-agenda)
  462. (defgroup org-agenda-daily/weekly nil
  463. "Options concerning the daily/weekly agenda."
  464. :tag "Org Agenda Daily/Weekly"
  465. :group 'org-agenda)
  466. (defgroup org-agenda-todo-list nil
  467. "Options concerning the global todo list agenda view."
  468. :tag "Org Agenda Todo List"
  469. :group 'org-agenda)
  470. (defgroup org-agenda-match-view nil
  471. "Options concerning the general tags/property/todo match agenda view."
  472. :tag "Org Agenda Match View"
  473. :group 'org-agenda)
  474. (defgroup org-agenda-search-view nil
  475. "Options concerning the general tags/property/todo match agenda view."
  476. :tag "Org Agenda Match View"
  477. :group 'org-agenda)
  478. (defvar org-agenda-archives-mode nil
  479. "Non-nil means the agenda will include archived items.
  480. If this is the symbol `trees', trees in the selected agenda scope
  481. that are marked with the ARCHIVE tag will be included anyway. When this is
  482. t, also all archive files associated with the current selection of agenda
  483. files will be included.")
  484. (defcustom org-agenda-skip-comment-trees t
  485. "Non-nil means skip trees that start with the COMMENT keyword.
  486. When nil, these trees are also scanned by agenda commands."
  487. :group 'org-agenda-skip
  488. :type 'boolean)
  489. (defcustom org-agenda-todo-list-sublevels t
  490. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  491. When nil, the sublevels of a TODO entry are not checked, resulting in
  492. potentially much shorter TODO lists."
  493. :group 'org-agenda-skip
  494. :group 'org-agenda-todo-list
  495. :type 'boolean)
  496. (defcustom org-agenda-todo-ignore-with-date nil
  497. "Non-nil means don't show entries with a date in the global todo list.
  498. You can use this if you prefer to mark mere appointments with a TODO keyword,
  499. but don't want them to show up in the TODO list.
  500. When this is set, it also covers deadlines and scheduled items, the settings
  501. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  502. will be ignored.
  503. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  504. :group 'org-agenda-skip
  505. :group 'org-agenda-todo-list
  506. :type 'boolean)
  507. (defcustom org-agenda-todo-ignore-scheduled nil
  508. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  509. This applies when creating the global todo list.
  510. Valid values are:
  511. past Don't show entries scheduled today or in the past.
  512. future Don't show entries scheduled in the future.
  513. The idea behind this is that by scheduling it, you don't want to
  514. think about it until the scheduled date.
  515. all Don't show any scheduled entries in the global todo list.
  516. The idea behind this is that by scheduling it, you have already
  517. \"taken care\" of this item.
  518. t Same as `all', for backward compatibility.
  519. See also `org-agenda-todo-ignore-with-date'.
  520. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  521. to make his option also apply to the tags-todo list."
  522. :group 'org-agenda-skip
  523. :group 'org-agenda-todo-list
  524. :type '(choice
  525. (const :tag "Ignore future-scheduled todos" future)
  526. (const :tag "Ignore past- or present-scheduled todos" past)
  527. (const :tag "Ignore all scheduled todos" all)
  528. (const :tag "Ignore all scheduled todos (compatibility)" t)
  529. (const :tag "Show scheduled todos" nil)))
  530. (defcustom org-agenda-todo-ignore-deadlines nil
  531. "Non-nil means ignore some deadlined TODO items when making TODO list.
  532. This applie when creating the global todo list.
  533. Valid values are:
  534. near Don't show near deadline entries. A deadline is near when it is
  535. closer than `org-deadline-warning-days' days. The idea behind this
  536. is that such items will appear in the agenda anyway.
  537. far Don't show far deadline entries. This is useful if you don't want
  538. to use the todo list to figure out what to do now.
  539. all Ignore all TODO entries that do have a deadline.
  540. t Same as `near', for backward compatibility.
  541. See also `org-agenda-todo-ignore-with-date'.
  542. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  543. to make his option also apply to the tags-todo list."
  544. :group 'org-agenda-skip
  545. :group 'org-agenda-todo-list
  546. :type '(choice
  547. (const :tag "Ignore near deadlines" near)
  548. (const :tag "Ignore near deadlines (compatibility)" t)
  549. (const :tag "Ignore far deadlines" far)
  550. (const :tag "Ignore all TODOs with a deadlines" all)
  551. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  552. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  553. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  554. The variables
  555. `org-agenda-todo-ignore-with-date',
  556. `org-agenda-todo-ignore-scheduled'
  557. `org-agenda-todo-ignore-deadlines'
  558. make the global TODO list skip entries that have time stamps of certain
  559. kinds. If this option is set, the same options will also apply for the
  560. tags-todo search, which is the general tags/property matcher
  561. restricted to unfinished TODO entries only."
  562. :group 'org-agenda-skip
  563. :group 'org-agenda-todo-list
  564. :group 'org-agenda-match-view
  565. :type 'boolean)
  566. (defcustom org-agenda-skip-scheduled-if-done nil
  567. "Non-nil means don't show scheduled items in agenda when they are done.
  568. This is relevant for the daily/weekly agenda, not for the TODO list. And
  569. it applies only to the actual date of the scheduling. Warnings about
  570. an item with a past scheduling dates are always turned off when the item
  571. is DONE."
  572. :group 'org-agenda-skip
  573. :group 'org-agenda-daily/weekly
  574. :type 'boolean)
  575. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  576. "Non-nil means skip scheduling line if same entry shows because of deadline.
  577. In the agenda of today, an entry can show up multiple times because
  578. it is both scheduled and has a nearby deadline, and maybe a plain time
  579. stamp as well.
  580. When this variable is t, then only the deadline is shown and the fact that
  581. the entry is scheduled today or was scheduled previously is not shown.
  582. When this variable is nil, the entry will be shown several times. When
  583. the variable is the symbol `not-today', then skip scheduled previously,
  584. but not scheduled today."
  585. :group 'org-agenda-skip
  586. :group 'org-agenda-daily/weekly
  587. :type '(choice
  588. (const :tag "Never" nil)
  589. (const :tag "Always" t)
  590. (const :tag "Not when scheduled today" not-today)))
  591. (defcustom org-agenda-skip-deadline-if-done nil
  592. "Non-nil means don't show deadlines when the corresponding item is done.
  593. When nil, the deadline is still shown and should give you a happy feeling.
  594. This is relevant for the daily/weekly agenda. And it applied only to the
  595. actually date of the deadline. Warnings about approaching and past-due
  596. deadlines are always turned off when the item is DONE."
  597. :group 'org-agenda-skip
  598. :group 'org-agenda-daily/weekly
  599. :type 'boolean)
  600. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  601. "Non-nil means skip deadline prewarning when entry is also scheduled.
  602. This will apply on all days where a prewarning for the deadline would
  603. be shown, but not at the day when the entry is actually due. On that day,
  604. the deadline will be shown anyway.
  605. This variable may be set to nil, t, or a number which will then give
  606. the number of days before the actual deadline when the prewarnings
  607. should resume.
  608. This can be used in a workflow where the first showing of the deadline will
  609. trigger you to schedule it, and then you don't want to be reminded of it
  610. because you will take care of it on the day when scheduled."
  611. :group 'org-agenda-skip
  612. :group 'org-agenda-daily/weekly
  613. :type '(choice
  614. (const :tag "Alwas show prewarning" nil)
  615. (const :tag "Remove prewarning if entry is scheduled" t)
  616. (integer :tag "Restart prewarning N days before deadline")))
  617. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  618. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  619. When non-nil, after the search for timestamps has matched once in an
  620. entry, the rest of the entry will not be searched."
  621. :group 'org-agenda-skip
  622. :type 'boolean)
  623. (defcustom org-agenda-skip-timestamp-if-done nil
  624. "Non-nil means don't select item by timestamp or -range if it is DONE."
  625. :group 'org-agenda-skip
  626. :group 'org-agenda-daily/weekly
  627. :type 'boolean)
  628. (defcustom org-agenda-dim-blocked-tasks t
  629. "Non-nil means dim blocked tasks in the agenda display.
  630. This causes some overhead during agenda construction, but if you
  631. have turned on `org-enforce-todo-dependencies',
  632. `org-enforce-todo-checkbox-dependencies', or any other blocking
  633. mechanism, this will create useful feedback in the agenda.
  634. Instead of t, this variable can also have the value `invisible'.
  635. Then blocked tasks will be invisible and only become visible when
  636. they become unblocked. An exemption to this behavior is when a task is
  637. blocked because of unchecked checkboxes below it. Since checkboxes do
  638. not show up in the agenda views, making this task invisible you remove any
  639. trace from agenda views that there is something to do. Therefore, a task
  640. that is blocked because of checkboxes will never be made invisible, it
  641. will only be dimmed."
  642. :group 'org-agenda-daily/weekly
  643. :group 'org-agenda-todo-list
  644. :type '(choice
  645. (const :tag "Do not dim" nil)
  646. (const :tag "Dim to a grey face" t)
  647. (const :tag "Make invisible" invisible)))
  648. (defcustom org-timeline-show-empty-dates 3
  649. "Non-nil means `org-timeline' also shows dates without an entry.
  650. When nil, only the days which actually have entries are shown.
  651. When t, all days between the first and the last date are shown.
  652. When an integer, show also empty dates, but if there is a gap of more than
  653. N days, just insert a special line indicating the size of the gap."
  654. :group 'org-agenda-skip
  655. :type '(choice
  656. (const :tag "None" nil)
  657. (const :tag "All" t)
  658. (integer :tag "at most")))
  659. (defgroup org-agenda-startup nil
  660. "Options concerning initial settings in the Agenda in Org Mode."
  661. :tag "Org Agenda Startup"
  662. :group 'org-agenda)
  663. (defcustom org-finalize-agenda-hook nil
  664. "Hook run just before displaying an agenda buffer."
  665. :group 'org-agenda-startup
  666. :type 'hook)
  667. (defcustom org-agenda-mouse-1-follows-link nil
  668. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  669. A longer mouse click will still set point. Does not work on XEmacs.
  670. Needs to be set before org.el is loaded."
  671. :group 'org-agenda-startup
  672. :type 'boolean)
  673. (defcustom org-agenda-start-with-follow-mode nil
  674. "The initial value of follow-mode in a newly created agenda window."
  675. :group 'org-agenda-startup
  676. :type 'boolean)
  677. (defcustom org-agenda-show-outline-path t
  678. "Non-nil means show outline path in echo area after line motion."
  679. :group 'org-agenda-startup
  680. :type 'boolean)
  681. (defcustom org-agenda-start-with-entry-text-mode nil
  682. "The initial value of entry-text-mode in a newly created agenda window."
  683. :group 'org-agenda-startup
  684. :type 'boolean)
  685. (defcustom org-agenda-entry-text-maxlines 5
  686. "Number of text lines to be added when `E' is pressed in the agenda.
  687. Note that this variable only used during agenda display. Add add entry text
  688. when exporting the agenda, configure the variable
  689. `org-agenda-add-entry-ext-maxlines'."
  690. :group 'org-agenda
  691. :type 'integer)
  692. (defcustom org-agenda-entry-text-exclude-regexps nil
  693. "List of regular expressions to clean up entry text.
  694. The complete matches of all regular expressions in this list will be
  695. removed from entry text before it is shown in the agenda."
  696. :group 'org-agenda
  697. :type '(repeat (regexp)))
  698. (defvar org-agenda-entry-text-cleanup-hook nil
  699. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  700. This cleanup is done in a temporary buffer, so the function may inspect and
  701. change the entire buffer.
  702. Some default stuff like drawers and scheduling/deadline dates will already
  703. have been removed when this is called, as will any matches for regular
  704. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  705. (defvar org-agenda-include-inactive-timestamps nil
  706. "Non-nil means include inactive time stamps in agenda and timeline.")
  707. (defgroup org-agenda-windows nil
  708. "Options concerning the windows used by the Agenda in Org Mode."
  709. :tag "Org Agenda Windows"
  710. :group 'org-agenda)
  711. (defcustom org-agenda-window-setup 'reorganize-frame
  712. "How the agenda buffer should be displayed.
  713. Possible values for this option are:
  714. current-window Show agenda in the current window, keeping all other windows.
  715. other-window Use `switch-to-buffer-other-window' to display agenda.
  716. reorganize-frame Show only two windows on the current frame, the current
  717. window and the agenda.
  718. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  719. Also, when exiting the agenda, kill that frame.
  720. See also the variable `org-agenda-restore-windows-after-quit'."
  721. :group 'org-agenda-windows
  722. :type '(choice
  723. (const current-window)
  724. (const other-frame)
  725. (const other-window)
  726. (const reorganize-frame)))
  727. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  728. "The min and max height of the agenda window as a fraction of frame height.
  729. The value of the variable is a cons cell with two numbers between 0 and 1.
  730. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  731. :group 'org-agenda-windows
  732. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  733. (defcustom org-agenda-restore-windows-after-quit nil
  734. "Non-nil means restore window configuration open exiting agenda.
  735. Before the window configuration is changed for displaying the agenda,
  736. the current status is recorded. When the agenda is exited with
  737. `q' or `x' and this option is set, the old state is restored. If
  738. `org-agenda-window-setup' is `other-frame', the value of this
  739. option will be ignored."
  740. :group 'org-agenda-windows
  741. :type 'boolean)
  742. (defcustom org-agenda-ndays 7
  743. "Number of days to include in overview display.
  744. Should be 1 or 7.
  745. Custom commands can set this variable in the options section."
  746. :group 'org-agenda-daily/weekly
  747. :type 'integer)
  748. (defcustom org-agenda-start-on-weekday 1
  749. "Non-nil means start the overview always on the specified weekday.
  750. 0 denotes Sunday, 1 denotes Monday etc.
  751. When nil, always start on the current day.
  752. Custom commands can set this variable in the options section."
  753. :group 'org-agenda-daily/weekly
  754. :type '(choice (const :tag "Today" nil)
  755. (integer :tag "Weekday No.")))
  756. (defcustom org-agenda-show-all-dates t
  757. "Non-nil means `org-agenda' shows every day in the selected range.
  758. When nil, only the days which actually have entries are shown."
  759. :group 'org-agenda-daily/weekly
  760. :type 'boolean)
  761. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  762. "Format string for displaying dates in the agenda.
  763. Used by the daily/weekly agenda and by the timeline. This should be
  764. a format string understood by `format-time-string', or a function returning
  765. the formatted date as a string. The function must take a single argument,
  766. a calendar-style date list like (month day year)."
  767. :group 'org-agenda-daily/weekly
  768. :type '(choice
  769. (string :tag "Format string")
  770. (function :tag "Function")))
  771. (defun org-agenda-format-date-aligned (date)
  772. "Format a date string for display in the daily/weekly agenda, or timeline.
  773. This function makes sure that dates are aligned for easy reading."
  774. (require 'cal-iso)
  775. (let* ((dayname (calendar-day-name date))
  776. (day (cadr date))
  777. (day-of-week (calendar-day-of-week date))
  778. (month (car date))
  779. (monthname (calendar-month-name month))
  780. (year (nth 2 date))
  781. (iso-week (org-days-to-iso-week
  782. (calendar-absolute-from-gregorian date)))
  783. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  784. (1- year))
  785. ((and (= month 12) (<= iso-week 1))
  786. (1+ year))
  787. (t year)))
  788. (weekstring (if (= day-of-week 1)
  789. (format " W%02d" iso-week)
  790. "")))
  791. (format "%-10s %2d %s %4d%s"
  792. dayname day monthname year weekstring)))
  793. (defcustom org-agenda-time-leading-zero nil
  794. "Non-nil means use leading zero for military times in agenda.
  795. For example, 9:30am would become 09:30 rather than 9:30."
  796. :group 'org-agenda-daily/weekly
  797. :type 'boolean)
  798. (defcustom org-agenda-weekend-days '(6 0)
  799. "Which days are weekend?
  800. These days get the special face `org-agenda-date-weekend' in the agenda
  801. and timeline buffers."
  802. :group 'org-agenda-daily/weekly
  803. :type '(set :greedy t
  804. (const :tag "Monday" 1)
  805. (const :tag "Tuesday" 2)
  806. (const :tag "Wednesday" 3)
  807. (const :tag "Thursday" 4)
  808. (const :tag "Friday" 5)
  809. (const :tag "Saturday" 6)
  810. (const :tag "Sunday" 0)))
  811. (defcustom org-agenda-include-diary nil
  812. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  813. Custom commands can set this variable in the options section."
  814. :group 'org-agenda-daily/weekly
  815. :type 'boolean)
  816. (defcustom org-agenda-include-deadlines t
  817. "If non-nil, include entries within their deadline warning period.
  818. Custom commands can set this variable in the options section."
  819. :group 'org-agenda-daily/weekly
  820. :type 'boolean)
  821. (defcustom org-agenda-include-all-todo nil
  822. "Set means weekly/daily agenda will always contain all TODO entries.
  823. The TODO entries will be listed at the top of the agenda, before
  824. the entries for specific days.
  825. This option is deprecated, it is better to define a block agenda instead."
  826. :group 'org-agenda-daily/weekly
  827. :type 'boolean)
  828. (defcustom org-agenda-repeating-timestamp-show-all t
  829. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  830. When nil, only one occurrence is shown, either today or the
  831. nearest into the future."
  832. :group 'org-agenda-daily/weekly
  833. :type 'boolean)
  834. (defcustom org-scheduled-past-days 10000
  835. "No. of days to continue listing scheduled items that are not marked DONE.
  836. When an item is scheduled on a date, it shows up in the agenda on this
  837. day and will be listed until it is marked done for the number of days
  838. given here."
  839. :group 'org-agenda-daily/weekly
  840. :type 'integer)
  841. (defcustom org-agenda-log-mode-items '(closed clock)
  842. "List of items that should be shown in agenda log mode.
  843. This list may contain the following symbols:
  844. closed Show entries that have been closed on that day.
  845. clock Show entries that have received clocked time on that day.
  846. state Show all logged state changes.
  847. Note that instead of changing this variable, you can also press `C-u l' in
  848. the agenda to display all available LOG items temporarily."
  849. :group 'org-agenda-daily/weekly
  850. :type '(set :greedy t (const closed) (const clock) (const state)))
  851. (defcustom org-agenda-log-mode-add-notes t
  852. "Non-nil means add first line of notes to log entries in agenda views.
  853. If a log item like a state change or a clock entry is associated with
  854. notes, the first line of these notes will be added to the entry in the
  855. agenda display."
  856. :group 'org-agenda-daily/weekly
  857. :type 'boolean)
  858. (defcustom org-agenda-start-with-log-mode nil
  859. "The initial value of log-mode in a newly created agenda window."
  860. :group 'org-agenda-startup
  861. :group 'org-agenda-daily/weekly
  862. :type 'boolean)
  863. (defcustom org-agenda-start-with-clockreport-mode nil
  864. "The initial value of clockreport-mode in a newly created agenda window."
  865. :group 'org-agenda-startup
  866. :group 'org-agenda-daily/weekly
  867. :type 'boolean)
  868. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  869. "Property list with parameters for the clocktable in clockreport mode.
  870. This is the display mode that shows a clock table in the daily/weekly
  871. agenda, the properties for this dynamic block can be set here.
  872. The usual clocktable parameters are allowed here, but you cannot set
  873. the properties :name, :tstart, :tend, :block, and :scope - these will
  874. be overwritten to make sure the content accurately reflects the
  875. current display in the agenda."
  876. :group 'org-agenda-daily/weekly
  877. :type 'plist)
  878. (defcustom org-agenda-search-view-always-boolean nil
  879. "Non-nil means the search string is interpreted as individual parts.
  880. The search string for search view can either be interpreted as a phrase,
  881. or as a list of snippets that define a boolean search for a number of
  882. strings.
  883. When this is non-nil, the string will be split on whitespace, and each
  884. snippet will be searched individually, and all must match in order to
  885. select an entry. A snippet is then a single string of non-white
  886. characters, or a string in double quotes, or a regexp in {} braces.
  887. If a snippet is preceeded by \"-\", the snippet must *not* match.
  888. \"+\" is syntactic sugar for positive selection. Each snippet may
  889. be found as a full word or a partial word, but see the variable
  890. `org-agenda-search-view-force-full-words'.
  891. When this is nil, search will look for the entire search phrase as one,
  892. with each space character matching any amount of whitespace, including
  893. line breaks.
  894. Even when this is nil, you can still switch to Boolean search dynamically
  895. by preceeding the first snippet with \"+\" or \"-\". If the first snippet
  896. is a regexp marked with braces like \"{abc}\", this will also switch to
  897. boolean search."
  898. :group 'org-agenda-search-view
  899. :type 'boolean)
  900. (if (fboundp 'defvaralias)
  901. (defvaralias 'org-agenda-search-view-search-words-only
  902. 'org-agenda-search-view-always-boolean))
  903. (defcustom org-agenda-search-view-force-full-words nil
  904. "Non-nil me
  905. ans, search words must be matches as complete words.
  906. When nil, they may also match part of a word."
  907. :group 'org-agenda-search-view
  908. :type 'boolean)
  909. (defgroup org-agenda-time-grid nil
  910. "Options concerning the time grid in the Org-mode Agenda."
  911. :tag "Org Agenda Time Grid"
  912. :group 'org-agenda)
  913. (defcustom org-agenda-search-headline-for-time t
  914. "Non-nil means search headline for a time-of-day.
  915. If the headline contains a time-of-day in one format or another, it will
  916. be used to sort the entry into the time sequence of items for a day.
  917. Some people have time stamps in the headline that refer to the creation
  918. time or so, and then this produces an unwanted side effect. If this is
  919. the case for your, use this variable to turn off searching the headline
  920. for a time."
  921. :group 'org-agenda-time-grid
  922. :type 'boolean)
  923. (defcustom org-agenda-use-time-grid t
  924. "Non-nil means show a time grid in the agenda schedule.
  925. A time grid is a set of lines for specific times (like every two hours between
  926. 8:00 and 20:00). The items scheduled for a day at specific times are
  927. sorted in between these lines.
  928. For details about when the grid will be shown, and what it will look like, see
  929. the variable `org-agenda-time-grid'."
  930. :group 'org-agenda-time-grid
  931. :type 'boolean)
  932. (defcustom org-agenda-time-grid
  933. '((daily today require-timed)
  934. "----------------"
  935. (800 1000 1200 1400 1600 1800 2000))
  936. "The settings for time grid for agenda display.
  937. This is a list of three items. The first item is again a list. It contains
  938. symbols specifying conditions when the grid should be displayed:
  939. daily if the agenda shows a single day
  940. weekly if the agenda shows an entire week
  941. today show grid on current date, independent of daily/weekly display
  942. require-timed show grid only if at least one item has a time specification
  943. The second item is a string which will be placed behind the grid time.
  944. The third item is a list of integers, indicating the times that should have
  945. a grid line."
  946. :group 'org-agenda-time-grid
  947. :type
  948. '(list
  949. (set :greedy t :tag "Grid Display Options"
  950. (const :tag "Show grid in single day agenda display" daily)
  951. (const :tag "Show grid in weekly agenda display" weekly)
  952. (const :tag "Always show grid for today" today)
  953. (const :tag "Show grid only if any timed entries are present"
  954. require-timed)
  955. (const :tag "Skip grid times already present in an entry"
  956. remove-match))
  957. (string :tag "Grid String")
  958. (repeat :tag "Grid Times" (integer :tag "Time"))))
  959. (defgroup org-agenda-sorting nil
  960. "Options concerning sorting in the Org-mode Agenda."
  961. :tag "Org Agenda Sorting"
  962. :group 'org-agenda)
  963. (defcustom org-agenda-sorting-strategy
  964. '((agenda habit-down time-up priority-down category-keep)
  965. (todo priority-down category-keep)
  966. (tags priority-down category-keep)
  967. (search category-keep))
  968. "Sorting structure for the agenda items of a single day.
  969. This is a list of symbols which will be used in sequence to determine
  970. if an entry should be listed before another entry. The following
  971. symbols are recognized:
  972. time-up Put entries with time-of-day indications first, early first
  973. time-down Put entries with time-of-day indications first, late first
  974. category-keep Keep the default order of categories, corresponding to the
  975. sequence in `org-agenda-files'.
  976. category-up Sort alphabetically by category, A-Z.
  977. category-down Sort alphabetically by category, Z-A.
  978. tag-up Sort alphabetically by last tag, A-Z.
  979. tag-down Sort alphabetically by last tag, Z-A.
  980. priority-up Sort numerically by priority, high priority last.
  981. priority-down Sort numerically by priority, high priority first.
  982. todo-state-up Sort by todo state, tasks that are done last.
  983. todo-state-down Sort by todo state, tasks that are done first.
  984. effort-up Sort numerically by estimated effort, high effort last.
  985. effort-down Sort numerically by estimated effort, high effort first.
  986. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  987. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  988. habit-up Put entries that are habits first
  989. habit-down Put entries that are habits last
  990. The different possibilities will be tried in sequence, and testing stops
  991. if one comparison returns a \"not-equal\". For example, the default
  992. '(time-up category-keep priority-down)
  993. means: Pull out all entries having a specified time of day and sort them,
  994. in order to make a time schedule for the current day the first thing in the
  995. agenda listing for the day. Of the entries without a time indication, keep
  996. the grouped in categories, don't sort the categories, but keep them in
  997. the sequence given in `org-agenda-files'. Within each category sort by
  998. priority.
  999. Leaving out `category-keep' would mean that items will be sorted across
  1000. categories by priority.
  1001. Instead of a single list, this can also be a set of list for specific
  1002. contents, with a context symbol in the car of the list, any of
  1003. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1004. Custom commands can bind this variable in the options section."
  1005. :group 'org-agenda-sorting
  1006. :type `(choice
  1007. (repeat :tag "General" ,org-sorting-choice)
  1008. (list :tag "Individually"
  1009. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1010. (repeat ,org-sorting-choice))
  1011. (cons (const :tag "Strategy for TODO lists" todo)
  1012. (repeat ,org-sorting-choice))
  1013. (cons (const :tag "Strategy for Tags matches" tags)
  1014. (repeat ,org-sorting-choice))
  1015. (cons (const :tag "Strategy for search matches" search)
  1016. (repeat ,org-sorting-choice)))))
  1017. (defcustom org-agenda-cmp-user-defined nil
  1018. "A function to define the comparison `user-defined'.
  1019. This function must receive two arguments, agenda entry a and b.
  1020. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1021. the user comparison, return nil.
  1022. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1023. part of an agenda sorting strategy."
  1024. :group 'org-agenda-sorting
  1025. :type 'symbol)
  1026. (defcustom org-sort-agenda-notime-is-late t
  1027. "Non-nil means items without time are considered late.
  1028. This is only relevant for sorting. When t, items which have no explicit
  1029. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1030. do have a time. When nil, the default time is before 0:00. You can use this
  1031. option to decide if the schedule for today should come before or after timeless
  1032. agenda entries."
  1033. :group 'org-agenda-sorting
  1034. :type 'boolean)
  1035. (defcustom org-sort-agenda-noeffort-is-high t
  1036. "Non-nil means items without effort estimate are sorted as high effort.
  1037. This also applies when filtering an agenda view with respect to the
  1038. < or > effort operator. Then, tasks with no effort defined will be treated
  1039. as tasks with high effort.
  1040. When nil, such items are sorted as 0 minutes effort."
  1041. :group 'org-agenda-sorting
  1042. :type 'boolean)
  1043. (defgroup org-agenda-line-format nil
  1044. "Options concerning the entry prefix in the Org-mode agenda display."
  1045. :tag "Org Agenda Line Format"
  1046. :group 'org-agenda)
  1047. (defcustom org-agenda-prefix-format
  1048. '((agenda . " %-12:c%?-12t% s")
  1049. (timeline . " % s")
  1050. (todo . " %-12:c")
  1051. (tags . " %-12:c")
  1052. (search . " %-12:c"))
  1053. "Format specifications for the prefix of items in the agenda views.
  1054. An alist with four entries, for the different agenda types. The keys to the
  1055. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1056. are format strings.
  1057. This format works similar to a printf format, with the following meaning:
  1058. %c the category of the item, \"Diary\" for entries from the diary, or
  1059. as given by the CATEGORY keyword or derived from the file name.
  1060. %T the *last* tag of the item. Last because inherited tags come
  1061. first in the list.
  1062. %t the time-of-day specification if one applies to the entry, in the
  1063. format HH:MM
  1064. %s Scheduling/Deadline information, a short string
  1065. All specifiers work basically like the standard `%s' of printf, but may
  1066. contain two additional characters: A question mark just after the `%' and
  1067. a whitespace/punctuation character just before the final letter.
  1068. If the first character after `%' is a question mark, the entire field
  1069. will only be included if the corresponding value applies to the
  1070. current entry. This is useful for fields which should have fixed
  1071. width when present, but zero width when absent. For example,
  1072. \"%?-12t\" will result in a 12 character time field if a time of the
  1073. day is specified, but will completely disappear in entries which do
  1074. not contain a time.
  1075. If there is punctuation or whitespace character just before the final
  1076. format letter, this character will be appended to the field value if
  1077. the value is not empty. For example, the format \"%-12:c\" leads to
  1078. \"Diary: \" if the category is \"Diary\". If the category were be
  1079. empty, no additional colon would be inserted.
  1080. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1081. - Indent the line with two space characters
  1082. - Give the category in a 12 chars wide field, padded with whitespace on
  1083. the right (because of `-'). Append a colon if there is a category
  1084. (because of `:').
  1085. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1086. time, don't put in an empty field, just skip it (because of '?').
  1087. - Finally, put the scheduling information and append a whitespace.
  1088. As another example, if you don't want the time-of-day of entries in
  1089. the prefix, you could use:
  1090. (setq org-agenda-prefix-format \" %-11:c% s\")
  1091. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1092. `org-agenda-remove-tags'.
  1093. Custom commands can set this variable in the options section."
  1094. :type '(choice
  1095. (string :tag "General format")
  1096. (list :greedy t :tag "View dependent"
  1097. (cons (const agenda) (string :tag "Format"))
  1098. (cons (const timeline) (string :tag "Format"))
  1099. (cons (const todo) (string :tag "Format"))
  1100. (cons (const tags) (string :tag "Format"))
  1101. (cons (const search) (string :tag "Format"))))
  1102. :group 'org-agenda-line-format)
  1103. (defvar org-prefix-format-compiled nil
  1104. "The compiled version of the most recently used prefix format.
  1105. See the variable `org-agenda-prefix-format'.")
  1106. (defcustom org-agenda-todo-keyword-format "%-1s"
  1107. "Format for the TODO keyword in agenda lines.
  1108. Set this to something like \"%-12s\" if you want all TODO keywords
  1109. to occupy a fixed space in the agenda display."
  1110. :group 'org-agenda-line-format
  1111. :type 'string)
  1112. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1113. "Text preceding timerange entries in the agenda view.
  1114. This is a list with two strings. The first applies when the range
  1115. is entirely on one day. The second applies if the range spans several days.
  1116. The strings may have two \"%d\" format specifiers which will be filled
  1117. with the sequence number of the days, and the total number of days in the
  1118. range, respectively."
  1119. :group 'org-agenda-line-format
  1120. :type '(list
  1121. (string :tag "Deadline today ")
  1122. (choice :tag "Deadline relative"
  1123. (string :tag "Format string")
  1124. (function))))
  1125. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1126. "Text preceeding scheduled items in the agenda view.
  1127. This is a list with two strings. The first applies when the item is
  1128. scheduled on the current day. The second applies when it has been scheduled
  1129. previously, it may contain a %d indicating that this is the nth time that
  1130. this item is scheduled, due to automatic rescheduling of unfinished items
  1131. for the following day. So this number is one larger than the number of days
  1132. that passed since this item was scheduled first."
  1133. :group 'org-agenda-line-format
  1134. :type '(list
  1135. (string :tag "Scheduled today ")
  1136. (string :tag "Scheduled previously")))
  1137. (defcustom org-agenda-inactive-leader "["
  1138. "Text preceeding item pulled into the agenda by inactive time stamps.
  1139. These entries are added to the agenda when pressing \"[\"."
  1140. :group 'org-agenda-line-format
  1141. :type '(list
  1142. (string :tag "Scheduled today ")
  1143. (string :tag "Scheduled previously")))
  1144. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1145. "Text preceeding deadline items in the agenda view.
  1146. This is a list with two strings. The first applies when the item has its
  1147. deadline on the current day. The second applies when it is in the past or
  1148. in the future, it may contain %d to capture how many days away the deadline
  1149. is (was)."
  1150. :group 'org-agenda-line-format
  1151. :type '(list
  1152. (string :tag "Deadline today ")
  1153. (choice :tag "Deadline relative"
  1154. (string :tag "Format string")
  1155. (function))))
  1156. (defcustom org-agenda-remove-times-when-in-prefix t
  1157. "Non-nil means remove duplicate time specifications in agenda items.
  1158. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1159. time-of-day specification in a headline or diary entry is extracted and
  1160. placed into the prefix. If this option is non-nil, the original specification
  1161. \(a timestamp or -range, or just a plain time(range) specification like
  1162. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1163. cluttered.
  1164. The option can be t or nil. It may also be the symbol `beg', indicating
  1165. that the time should only be removed what it is located at the beginning of
  1166. the headline/diary entry."
  1167. :group 'org-agenda-line-format
  1168. :type '(choice
  1169. (const :tag "Always" t)
  1170. (const :tag "Never" nil)
  1171. (const :tag "When at beginning of entry" beg)))
  1172. (defcustom org-agenda-default-appointment-duration nil
  1173. "Default duration for appointments that only have a starting time.
  1174. When nil, no duration is specified in such cases.
  1175. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1176. :group 'org-agenda-line-format
  1177. :type '(choice
  1178. (integer :tag "Minutes")
  1179. (const :tag "No default duration")))
  1180. (defcustom org-agenda-show-inherited-tags t
  1181. "Non-nil means show inherited tags in each agenda line."
  1182. :group 'org-agenda-line-format
  1183. :type 'boolean)
  1184. (defcustom org-agenda-hide-tags-regexp nil
  1185. "Regular expression used to filter away specific tags in agenda views.
  1186. This means that these tags will be present, but not be shown in the agenda
  1187. line. Secondayt filltering will still work on the hidden tags.
  1188. Nil means don't hide any tags."
  1189. :group 'org-agenda-line-format
  1190. :type '(choice
  1191. (const :tag "Hide none" nil)
  1192. (string :tag "Regexp ")))
  1193. (defcustom org-agenda-remove-tags nil
  1194. "Non-nil means remove the tags from the headline copy in the agenda.
  1195. When this is the symbol `prefix', only remove tags when
  1196. `org-agenda-prefix-format' contains a `%T' specifier."
  1197. :group 'org-agenda-line-format
  1198. :type '(choice
  1199. (const :tag "Always" t)
  1200. (const :tag "Never" nil)
  1201. (const :tag "When prefix format contains %T" prefix)))
  1202. (if (fboundp 'defvaralias)
  1203. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1204. 'org-agenda-remove-tags))
  1205. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1206. "Shift tags in agenda items to this column.
  1207. If this number is positive, it specifies the column. If it is negative,
  1208. it means that the tags should be flushright to that column. For example,
  1209. -80 works well for a normal 80 character screen."
  1210. :group 'org-agenda-line-format
  1211. :type 'integer)
  1212. (if (fboundp 'defvaralias)
  1213. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1214. (defcustom org-agenda-fontify-priorities 'cookies
  1215. "Non-nil means highlight low and high priorities in agenda.
  1216. When t, the highest priority entries are bold, lowest priority italic.
  1217. However, settings in org-priority-faces will overrule these faces.
  1218. When this variable is the symbol `cookies', only fontify the
  1219. cookies, not the entire task.
  1220. This may also be an association list of priority faces, whose
  1221. keys are the character values of `org-highest-priority',
  1222. `org-default-priority', and `org-lowest-priority' (the default values
  1223. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1224. color as a string, or a list like `(:background \"Red\")'.
  1225. If it is a color, the variable `org-faces-easy-properties'
  1226. determines if it is a foreground or a background color."
  1227. :group 'org-agenda-line-format
  1228. :type '(choice
  1229. (const :tag "Never" nil)
  1230. (const :tag "Defaults" t)
  1231. (const :tag "Cookies only" cookies)
  1232. (repeat :tag "Specify"
  1233. (list (character :tag "Priority" :value ?A)
  1234. (choice :tag "Face "
  1235. (string :tag "Color")
  1236. (sexp :tag "Face"))))))
  1237. (defgroup org-agenda-column-view nil
  1238. "Options concerning column view in the agenda."
  1239. :tag "Org Agenda Column View"
  1240. :group 'org-agenda)
  1241. (defcustom org-agenda-columns-show-summaries t
  1242. "Non-nil means show summaries for columns displayed in the agenda view."
  1243. :group 'org-agenda-column-view
  1244. :type 'boolean)
  1245. (defcustom org-agenda-columns-remove-prefix-from-item t
  1246. "Non-nil means remove the prefix from a headline for agenda column view.
  1247. The special ITEM field in the columns format contains the current line, with
  1248. all information shown in other columns (like the TODO state or a tag).
  1249. When this variable is non-nil, also the agenda prefix will be removed from
  1250. the content of the ITEM field, to make sure as much as possible of the
  1251. headline can be shown in the limited width of the field."
  1252. :group 'org-agenda
  1253. :type 'boolean)
  1254. (defcustom org-agenda-columns-compute-summary-properties t
  1255. "Non-nil means recompute all summary properties before column view.
  1256. When column view in the agenda is listing properties that have a summary
  1257. operator, it can go to all relevant buffers and recompute the summaries
  1258. there. This can mean overhead for the agenda column view, but is necessary
  1259. to have thing up to date.
  1260. As a special case, a CLOCKSUM property also makes sure that the clock
  1261. computations are current."
  1262. :group 'org-agenda-column-view
  1263. :type 'boolean)
  1264. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1265. "Non-nil means the duration of an appointment will add to day effort.
  1266. The property to which appointment durations will be added is the one given
  1267. in the option `org-effort-property'. If an appointment does not have
  1268. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1269. is not set, an appointment without end time will not contribute to the time
  1270. estimate."
  1271. :group 'org-agenda-column-view
  1272. :type 'boolean)
  1273. (defcustom org-agenda-auto-exclude-function nil
  1274. "A function called with a tag to decide if it is filtered on '/ RET'.
  1275. The sole argument to the function, which is called once for each
  1276. possible tag, is a string giving the name of the tag. The
  1277. function should return either nil if the tag should be included
  1278. as normal, or \"-<TAG>\" to exclude the tag.
  1279. Note that for the purpose of tag filtering, only the lower-case version of
  1280. all tags will be considered, so that this function will only ever see
  1281. the lower-case version of all tags."
  1282. :group 'org-agenda
  1283. :type 'function)
  1284. (eval-when-compile
  1285. (require 'cl))
  1286. (require 'org)
  1287. (defun org-add-agenda-custom-command (entry)
  1288. "Replace or add a command in `org-agenda-custom-commands'.
  1289. This is mostly for hacking and trying a new command - once the command
  1290. works you probably want to add it to `org-agenda-custom-commands' for good."
  1291. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1292. (if ass
  1293. (setcdr ass (cdr entry))
  1294. (push entry org-agenda-custom-commands))))
  1295. ;;; Define the Org-agenda-mode
  1296. (defvar org-agenda-mode-map (make-sparse-keymap)
  1297. "Keymap for `org-agenda-mode'.")
  1298. (if (fboundp 'defvaralias)
  1299. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1300. (defvar org-agenda-menu) ; defined later in this file.
  1301. (defvar org-agenda-restrict) ; defined later in this file.
  1302. (defvar org-agenda-follow-mode nil)
  1303. (defvar org-agenda-entry-text-mode nil)
  1304. (defvar org-agenda-clockreport-mode nil)
  1305. (defvar org-agenda-show-log nil)
  1306. (defvar org-agenda-redo-command nil)
  1307. (defvar org-agenda-query-string nil)
  1308. (defvar org-agenda-mode-hook nil
  1309. "Hook for org-agenda-mode, run after the mode is turned on.")
  1310. (defvar org-agenda-type nil)
  1311. (defvar org-agenda-force-single-file nil)
  1312. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1313. (defun org-agenda-mode ()
  1314. "Mode for time-sorted view on action items in Org-mode files.
  1315. The following commands are available:
  1316. \\{org-agenda-mode-map}"
  1317. (interactive)
  1318. (kill-all-local-variables)
  1319. (setq org-agenda-undo-list nil
  1320. org-agenda-pending-undo-list nil
  1321. org-agenda-bulk-marked-entries nil)
  1322. (setq major-mode 'org-agenda-mode)
  1323. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1324. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1325. (setq mode-name "Org-Agenda")
  1326. (use-local-map org-agenda-mode-map)
  1327. (easy-menu-add org-agenda-menu)
  1328. (if org-startup-truncated (setq truncate-lines t))
  1329. (org-set-local 'line-move-visual nil)
  1330. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1331. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1332. ;; Make sure properties are removed when copying text
  1333. (when (boundp 'buffer-substring-filters)
  1334. (org-set-local 'buffer-substring-filters
  1335. (cons (lambda (x)
  1336. (set-text-properties 0 (length x) nil x) x)
  1337. buffer-substring-filters)))
  1338. (unless org-agenda-keep-modes
  1339. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1340. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1341. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1342. org-agenda-show-log org-agenda-start-with-log-mode))
  1343. (easy-menu-change
  1344. '("Agenda") "Agenda Files"
  1345. (append
  1346. (list
  1347. (vector
  1348. (if (get 'org-agenda-files 'org-restrict)
  1349. "Restricted to single file"
  1350. "Edit File List")
  1351. '(org-edit-agenda-file-list)
  1352. (not (get 'org-agenda-files 'org-restrict)))
  1353. "--")
  1354. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1355. (org-agenda-set-mode-name)
  1356. (apply
  1357. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1358. (list 'org-agenda-mode-hook)))
  1359. (substitute-key-definition 'undo 'org-agenda-undo
  1360. org-agenda-mode-map global-map)
  1361. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1362. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1363. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1364. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1365. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1366. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1367. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1368. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1369. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1370. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1371. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1372. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1373. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1374. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1375. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1376. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1377. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1378. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1379. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1380. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1381. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1382. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1383. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1384. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1385. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1386. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1387. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1388. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1389. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1390. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1391. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1392. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1393. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1394. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1395. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1396. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1397. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1398. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1399. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1400. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1401. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1402. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1403. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1404. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1405. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1406. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1407. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1408. (while l (org-defkey org-agenda-mode-map
  1409. (int-to-string (pop l)) 'digit-argument)))
  1410. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1411. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1412. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1413. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1414. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1415. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1416. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1417. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1418. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1419. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1420. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1421. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1422. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1423. 'org-clock-modify-effort-estimate)
  1424. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1425. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1426. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1427. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1428. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1429. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1430. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1431. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1432. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1433. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1434. (substitute-key-definition 'next-line 'org-agenda-next-line
  1435. org-agenda-mode-map global-map)
  1436. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1437. org-agenda-mode-map global-map)
  1438. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1439. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1440. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1441. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1442. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1443. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1444. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1445. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1446. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1447. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1448. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1449. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1450. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1451. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1452. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1453. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1454. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1455. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1456. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1457. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1458. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1459. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1460. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1461. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1462. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1463. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1464. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1465. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1466. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1467. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1468. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1469. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1470. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1471. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1472. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1473. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1474. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1475. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1476. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1477. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1478. (org-defkey org-agenda-mode-map
  1479. (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
  1480. (org-defkey org-agenda-mode-map
  1481. (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
  1482. (when org-agenda-mouse-1-follows-link
  1483. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1484. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1485. '("Agenda"
  1486. ("Agenda Files")
  1487. "--"
  1488. ("Agenda Dates"
  1489. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1490. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1491. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1492. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1493. "--"
  1494. ("View"
  1495. ["Day View" org-agenda-day-view
  1496. :active (org-agenda-check-type nil 'agenda)
  1497. :style radio :selected (equal org-agenda-ndays 1)
  1498. :keys "v d (or just d)"]
  1499. ["Week View" org-agenda-week-view
  1500. :active (org-agenda-check-type nil 'agenda)
  1501. :style radio :selected (equal org-agenda-ndays 7)
  1502. :keys "v w (or just w)"]
  1503. ["Month View" org-agenda-month-view
  1504. :active (org-agenda-check-type nil 'agenda)
  1505. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1506. :keys "v m"]
  1507. ["Year View" org-agenda-year-view
  1508. :active (org-agenda-check-type nil 'agenda)
  1509. :style radio :selected (member org-agenda-ndays '(365 366))
  1510. :keys "v y"]
  1511. "--"
  1512. ["Include Diary" org-agenda-toggle-diary
  1513. :style toggle :selected org-agenda-include-diary
  1514. :active (org-agenda-check-type nil 'agenda)]
  1515. ["Include Deadlines" org-agenda-toggle-deadlines
  1516. :style toggle :selected org-agenda-include-deadlines
  1517. :active (org-agenda-check-type nil 'agenda)]
  1518. ["Use Time Grid" org-agenda-toggle-time-grid
  1519. :style toggle :selected org-agenda-use-time-grid
  1520. :active (org-agenda-check-type nil 'agenda)]
  1521. "--"
  1522. ["Show clock report" org-agenda-clockreport-mode
  1523. :style toggle :selected org-agenda-clockreport-mode
  1524. :active (org-agenda-check-type nil 'agenda)]
  1525. ["Show some entry text" org-agenda-entry-text-mode
  1526. :style toggle :selected org-agenda-entry-text-mode
  1527. :active t]
  1528. "--"
  1529. ["Show Logbook entries" org-agenda-log-mode
  1530. :style toggle :selected org-agenda-show-log
  1531. :active (org-agenda-check-type nil 'agenda 'timeline)
  1532. :keys "v l (or just l)"]
  1533. ["Include archived trees" org-agenda-archives-mode
  1534. :style toggle :selected org-agenda-archives-mode :active t
  1535. :keys "v a"]
  1536. ["Include archive files" (org-agenda-archives-mode t)
  1537. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1538. :keys "v A"]
  1539. "--"
  1540. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1541. ["Write view to file" org-write-agenda t]
  1542. ["Rebuild buffer" org-agenda-redo t]
  1543. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1544. "--"
  1545. ["Show original entry" org-agenda-show t]
  1546. ["Go To (other window)" org-agenda-goto t]
  1547. ["Go To (this window)" org-agenda-switch-to t]
  1548. ["Follow Mode" org-agenda-follow-mode
  1549. :style toggle :selected org-agenda-follow-mode :active t]
  1550. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1551. "--"
  1552. ("TODO"
  1553. ["Cycle TODO" org-agenda-todo t]
  1554. ["Next TODO set" org-agenda-todo-nextset t]
  1555. ["Previous TODO set" org-agenda-todo-previousset t]
  1556. ["Add note" org-agenda-add-note t])
  1557. ("Archive/Refile/Delete"
  1558. ["Archive default" org-agenda-archive-default t]
  1559. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1560. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1561. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1562. ["Archive subtree" org-agenda-archive t]
  1563. "--"
  1564. ["Refile" org-agenda-refile t]
  1565. "--"
  1566. ["Delete subtree" org-agenda-kill t])
  1567. ("Bulk action"
  1568. ["Mark entry" org-agenda-bulk-mark t]
  1569. ["Unmark entry" org-agenda-bulk-unmark t]
  1570. ["Act on all marked" org-agenda-bulk-action t]
  1571. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1572. "--"
  1573. ("Tags and Properties"
  1574. ["Show all Tags" org-agenda-show-tags t]
  1575. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1576. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1577. "--"
  1578. ["Column View" org-columns t])
  1579. ("Deadline/Schedule"
  1580. ["Schedule" org-agenda-schedule t]
  1581. ["Set Deadline" org-agenda-deadline t]
  1582. "--"
  1583. ["Mark item" org-agenda-action :active t :keys "k m"]
  1584. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1585. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1586. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1587. "--"
  1588. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1589. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1590. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1591. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1592. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1593. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1594. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1595. ("Clock and Effort"
  1596. ["Clock in" org-agenda-clock-in t]
  1597. ["Clock out" org-agenda-clock-out t]
  1598. ["Clock cancel" org-agenda-clock-cancel t]
  1599. ["Goto running clock" org-clock-goto t]
  1600. "--"
  1601. ["Set Effort" org-agenda-set-effort t]
  1602. ["Change clocked effort" org-clock-modify-effort-estimate
  1603. (org-clock-is-active)])
  1604. ("Priority"
  1605. ["Set Priority" org-agenda-priority t]
  1606. ["Increase Priority" org-agenda-priority-up t]
  1607. ["Decrease Priority" org-agenda-priority-down t]
  1608. ["Show Priority" org-agenda-show-priority t])
  1609. ("Calendar/Diary"
  1610. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1611. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1612. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1613. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1614. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1615. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1616. "--"
  1617. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1618. "--"
  1619. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1620. "--"
  1621. ("MobileOrg"
  1622. ["Push Files and Views" org-mobile-push t]
  1623. ["Get Captured and Flagged" org-mobile-pull t]
  1624. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1625. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1626. "--"
  1627. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1628. "--"
  1629. ["Quit" org-agenda-quit t]
  1630. ["Exit and Release Buffers" org-agenda-exit t]
  1631. ))
  1632. ;;; Agenda undo
  1633. (defvar org-agenda-allow-remote-undo t
  1634. "Non-nil means allow remote undo from the agenda buffer.")
  1635. (defvar org-agenda-undo-list nil
  1636. "List of undoable operations in the agenda since last refresh.")
  1637. (defvar org-agenda-undo-has-started-in nil
  1638. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1639. (defvar org-agenda-pending-undo-list nil
  1640. "In a series of undo commands, this is the list of remaining undo items.")
  1641. (defun org-agenda-undo ()
  1642. "Undo a remote editing step in the agenda.
  1643. This undoes changes both in the agenda buffer and in the remote buffer
  1644. that have been changed along."
  1645. (interactive)
  1646. (or org-agenda-allow-remote-undo
  1647. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1648. (if (not (eq this-command last-command))
  1649. (setq org-agenda-undo-has-started-in nil
  1650. org-agenda-pending-undo-list org-agenda-undo-list))
  1651. (if (not org-agenda-pending-undo-list)
  1652. (error "No further undo information"))
  1653. (let* ((entry (pop org-agenda-pending-undo-list))
  1654. buf line cmd rembuf)
  1655. (setq cmd (pop entry) line (pop entry))
  1656. (setq rembuf (nth 2 entry))
  1657. (org-with-remote-undo rembuf
  1658. (while (bufferp (setq buf (pop entry)))
  1659. (if (pop entry)
  1660. (with-current-buffer buf
  1661. (let ((last-undo-buffer buf)
  1662. (inhibit-read-only t))
  1663. (unless (memq buf org-agenda-undo-has-started-in)
  1664. (push buf org-agenda-undo-has-started-in)
  1665. (make-local-variable 'pending-undo-list)
  1666. (undo-start))
  1667. (while (and pending-undo-list
  1668. (listp pending-undo-list)
  1669. (not (car pending-undo-list)))
  1670. (pop pending-undo-list))
  1671. (undo-more 1))))))
  1672. (org-goto-line line)
  1673. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1674. (defun org-verify-change-for-undo (l1 l2)
  1675. "Verify that a real change occurred between the undo lists L1 and L2."
  1676. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1677. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1678. (not (eq l1 l2)))
  1679. ;;; Agenda dispatch
  1680. (defvar org-agenda-restrict nil)
  1681. (defvar org-agenda-restrict-begin (make-marker))
  1682. (defvar org-agenda-restrict-end (make-marker))
  1683. (defvar org-agenda-last-dispatch-buffer nil)
  1684. (defvar org-agenda-overriding-restriction nil)
  1685. ;;;###autoload
  1686. (defun org-agenda (&optional arg keys restriction)
  1687. "Dispatch agenda commands to collect entries to the agenda buffer.
  1688. Prompts for a command to execute. Any prefix arg will be passed
  1689. on to the selected command. The default selections are:
  1690. a Call `org-agenda-list' to display the agenda for current day or week.
  1691. t Call `org-todo-list' to display the global todo list.
  1692. T Call `org-todo-list' to display the global todo list, select only
  1693. entries with a specific TODO keyword (the user gets a prompt).
  1694. m Call `org-tags-view' to display headlines with tags matching
  1695. a condition (the user is prompted for the condition).
  1696. M Like `m', but select only TODO entries, no ordinary headlines.
  1697. L Create a timeline for the current buffer.
  1698. e Export views to associated files.
  1699. s Search entries for keywords.
  1700. / Multi occur across all agenda files and also files listed
  1701. in `org-agenda-text-search-extra-files'.
  1702. < Restrict agenda commands to buffer, subtree, or region.
  1703. Press several times to get the desired effect.
  1704. > Remove a previous restriction.
  1705. # List \"stuck\" projects.
  1706. ! Configure what \"stuck\" means.
  1707. C Configure custom agenda commands.
  1708. More commands can be added by configuring the variable
  1709. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1710. searches can be pre-defined in this way.
  1711. If the current buffer is in Org-mode and visiting a file, you can also
  1712. first press `<' once to indicate that the agenda should be temporarily
  1713. \(until the next use of \\[org-agenda]) restricted to the current file.
  1714. Pressing `<' twice means to restrict to the current subtree or region
  1715. \(if active)."
  1716. (interactive "P")
  1717. (catch 'exit
  1718. (let* ((prefix-descriptions nil)
  1719. (org-agenda-window-setup (if (equal (buffer-name)
  1720. org-agenda-buffer-name)
  1721. 'current-window
  1722. org-agenda-window-setup))
  1723. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1724. (org-agenda-custom-commands
  1725. ;; normalize different versions
  1726. (delq nil
  1727. (mapcar
  1728. (lambda (x)
  1729. (cond ((stringp (cdr x))
  1730. (push x prefix-descriptions)
  1731. nil)
  1732. ((stringp (nth 1 x)) x)
  1733. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1734. (t (cons (car x) (cons "" (cdr x))))))
  1735. org-agenda-custom-commands)))
  1736. (buf (current-buffer))
  1737. (bfn (buffer-file-name (buffer-base-buffer)))
  1738. entry key type match lprops ans)
  1739. ;; Turn off restriction unless there is an overriding one,
  1740. (unless org-agenda-overriding-restriction
  1741. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1742. ;; There is a request to keep the file list in place
  1743. (put 'org-agenda-files 'org-restrict nil))
  1744. (setq org-agenda-restrict nil)
  1745. (move-marker org-agenda-restrict-begin nil)
  1746. (move-marker org-agenda-restrict-end nil))
  1747. ;; Delete old local properties
  1748. (put 'org-agenda-redo-command 'org-lprops nil)
  1749. ;; Remember where this call originated
  1750. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1751. (unless keys
  1752. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1753. keys (car ans)
  1754. restriction (cdr ans)))
  1755. ;; Establish the restriction, if any
  1756. (when (and (not org-agenda-overriding-restriction) restriction)
  1757. (put 'org-agenda-files 'org-restrict (list bfn))
  1758. (cond
  1759. ((eq restriction 'region)
  1760. (setq org-agenda-restrict t)
  1761. (move-marker org-agenda-restrict-begin (region-beginning))
  1762. (move-marker org-agenda-restrict-end (region-end)))
  1763. ((eq restriction 'subtree)
  1764. (save-excursion
  1765. (setq org-agenda-restrict t)
  1766. (org-back-to-heading t)
  1767. (move-marker org-agenda-restrict-begin (point))
  1768. (move-marker org-agenda-restrict-end
  1769. (progn (org-end-of-subtree t)))))))
  1770. (require 'calendar) ; FIXME: can we avoid this for some commands?
  1771. ;; For example the todo list should not need it (but does...)
  1772. (cond
  1773. ((setq entry (assoc keys org-agenda-custom-commands))
  1774. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1775. (progn
  1776. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1777. lprops (nth 4 entry))
  1778. (put 'org-agenda-redo-command 'org-lprops lprops)
  1779. (cond
  1780. ((eq type 'agenda)
  1781. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1782. ((eq type 'alltodo)
  1783. (org-let lprops '(org-todo-list current-prefix-arg)))
  1784. ((eq type 'search)
  1785. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1786. ((eq type 'stuck)
  1787. (org-let lprops '(org-agenda-list-stuck-projects
  1788. current-prefix-arg)))
  1789. ((eq type 'tags)
  1790. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1791. ((eq type 'tags-todo)
  1792. (org-let lprops '(org-tags-view '(4) match)))
  1793. ((eq type 'todo)
  1794. (org-let lprops '(org-todo-list match)))
  1795. ((eq type 'tags-tree)
  1796. (org-check-for-org-mode)
  1797. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1798. ((eq type 'todo-tree)
  1799. (org-check-for-org-mode)
  1800. (org-let lprops
  1801. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1802. (regexp-quote match) "\\>"))))
  1803. ((eq type 'occur-tree)
  1804. (org-check-for-org-mode)
  1805. (org-let lprops '(org-occur match)))
  1806. ((functionp type)
  1807. (org-let lprops '(funcall type match)))
  1808. ((fboundp type)
  1809. (org-let lprops '(funcall type match)))
  1810. (t (error "Invalid custom agenda command type %s" type))))
  1811. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1812. ((equal keys "C")
  1813. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1814. (customize-variable 'org-agenda-custom-commands))
  1815. ((equal keys "a") (call-interactively 'org-agenda-list))
  1816. ((equal keys "s") (call-interactively 'org-search-view))
  1817. ((equal keys "t") (call-interactively 'org-todo-list))
  1818. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1819. ((equal keys "m") (call-interactively 'org-tags-view))
  1820. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1821. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1822. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1823. (org-add-hook
  1824. 'post-command-hook
  1825. (lambda ()
  1826. (unless (current-message)
  1827. (let* ((m (org-agenda-get-any-marker))
  1828. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1829. (when note
  1830. (message (concat
  1831. "FLAGGING-NOTE ([?] for more info): "
  1832. (org-add-props
  1833. (replace-regexp-in-string
  1834. "\\\\n" "//"
  1835. (copy-sequence note))
  1836. nil 'face 'org-warning)))))))
  1837. t t))
  1838. ((equal keys "L")
  1839. (unless (org-mode-p)
  1840. (error "This is not an Org-mode file"))
  1841. (unless restriction
  1842. (put 'org-agenda-files 'org-restrict (list bfn))
  1843. (org-call-with-arg 'org-timeline arg)))
  1844. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1845. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1846. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1847. (t (error "Invalid agenda key"))))))
  1848. (defun org-agenda-normalize-custom-commands (cmds)
  1849. (delq nil
  1850. (mapcar
  1851. (lambda (x)
  1852. (cond ((stringp (cdr x)) nil)
  1853. ((stringp (nth 1 x)) x)
  1854. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1855. (t (cons (car x) (cons "" (cdr x))))))
  1856. cmds)))
  1857. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1858. "The user interface for selecting an agenda command."
  1859. (catch 'exit
  1860. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1861. (restrict-ok (and bfn (org-mode-p)))
  1862. (region-p (org-region-active-p))
  1863. (custom org-agenda-custom-commands)
  1864. (selstring "")
  1865. restriction second-time
  1866. c entry key type match prefixes rmheader header-end custom1 desc)
  1867. (save-window-excursion
  1868. (delete-other-windows)
  1869. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1870. (erase-buffer)
  1871. (insert (eval-when-compile
  1872. (let ((header
  1873. "
  1874. Press key for an agenda command: < Buffer, subtree/region restriction
  1875. -------------------------------- > Remove restriction
  1876. a Agenda for current week or day e Export agenda views
  1877. t List of all TODO entries T Entries with special TODO kwd
  1878. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1879. L Timeline for current buffer # List stuck projects (!=configure)
  1880. s Search for keywords C Configure custom agenda commands
  1881. / Multi-occur ? Find :FLAGGED: entries
  1882. ")
  1883. (start 0))
  1884. (while (string-match
  1885. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1886. header start)
  1887. (setq start (match-end 0))
  1888. (add-text-properties (match-beginning 2) (match-end 2)
  1889. '(face bold) header))
  1890. header)))
  1891. (setq header-end (move-marker (make-marker) (point)))
  1892. (while t
  1893. (setq custom1 custom)
  1894. (when (eq rmheader t)
  1895. (org-goto-line 1)
  1896. (re-search-forward ":" nil t)
  1897. (delete-region (match-end 0) (point-at-eol))
  1898. (forward-char 1)
  1899. (looking-at "-+")
  1900. (delete-region (match-end 0) (point-at-eol))
  1901. (move-marker header-end (match-end 0)))
  1902. (goto-char header-end)
  1903. (delete-region (point) (point-max))
  1904. (while (setq entry (pop custom1))
  1905. (setq key (car entry) desc (nth 1 entry)
  1906. type (nth 2 entry)
  1907. match (nth 3 entry))
  1908. (if (> (length key) 1)
  1909. (add-to-list 'prefixes (string-to-char key))
  1910. (insert
  1911. (format
  1912. "\n%-4s%-14s: %s"
  1913. (org-add-props (copy-sequence key)
  1914. '(face bold))
  1915. (cond
  1916. ((string-match "\\S-" desc) desc)
  1917. ((eq type 'agenda) "Agenda for current week or day")
  1918. ((eq type 'alltodo) "List of all TODO entries")
  1919. ((eq type 'search) "Word search")
  1920. ((eq type 'stuck) "List of stuck projects")
  1921. ((eq type 'todo) "TODO keyword")
  1922. ((eq type 'tags) "Tags query")
  1923. ((eq type 'tags-todo) "Tags (TODO)")
  1924. ((eq type 'tags-tree) "Tags tree")
  1925. ((eq type 'todo-tree) "TODO kwd tree")
  1926. ((eq type 'occur-tree) "Occur tree")
  1927. ((functionp type) (if (symbolp type)
  1928. (symbol-name type)
  1929. "Lambda expression"))
  1930. (t "???"))
  1931. (cond
  1932. ((stringp match)
  1933. (setq match (copy-sequence match))
  1934. (org-add-props match nil 'face 'org-warning))
  1935. (match
  1936. (format "set of %d commands" (length match)))
  1937. (t ""))))))
  1938. (when prefixes
  1939. (mapc (lambda (x)
  1940. (insert
  1941. (format "\n%s %s"
  1942. (org-add-props (char-to-string x)
  1943. nil 'face 'bold)
  1944. (or (cdr (assoc (concat selstring (char-to-string x))
  1945. prefix-descriptions))
  1946. "Prefix key"))))
  1947. prefixes))
  1948. (goto-char (point-min))
  1949. (if second-time
  1950. (if (not (pos-visible-in-window-p (point-max)))
  1951. (org-fit-window-to-buffer))
  1952. (setq second-time t)
  1953. (org-fit-window-to-buffer))
  1954. (message "Press key for agenda command%s:"
  1955. (if (or restrict-ok org-agenda-overriding-restriction)
  1956. (if org-agenda-overriding-restriction
  1957. " (restriction lock active)"
  1958. (if restriction
  1959. (format " (restricted to %s)" restriction)
  1960. " (unrestricted)"))
  1961. ""))
  1962. (setq c (read-char-exclusive))
  1963. (message "")
  1964. (cond
  1965. ((assoc (char-to-string c) custom)
  1966. (setq selstring (concat selstring (char-to-string c)))
  1967. (throw 'exit (cons selstring restriction)))
  1968. ((memq c prefixes)
  1969. (setq selstring (concat selstring (char-to-string c))
  1970. prefixes nil
  1971. rmheader (or rmheader t)
  1972. custom (delq nil (mapcar
  1973. (lambda (x)
  1974. (if (or (= (length (car x)) 1)
  1975. (/= (string-to-char (car x)) c))
  1976. nil
  1977. (cons (substring (car x) 1) (cdr x))))
  1978. custom))))
  1979. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1980. (message "Restriction is only possible in Org-mode buffers")
  1981. (ding) (sit-for 1))
  1982. ((eq c ?1)
  1983. (org-agenda-remove-restriction-lock 'noupdate)
  1984. (setq restriction 'buffer))
  1985. ((eq c ?0)
  1986. (org-agenda-remove-restriction-lock 'noupdate)
  1987. (setq restriction (if region-p 'region 'subtree)))
  1988. ((eq c ?<)
  1989. (org-agenda-remove-restriction-lock 'noupdate)
  1990. (setq restriction
  1991. (cond
  1992. ((eq restriction 'buffer)
  1993. (if region-p 'region 'subtree))
  1994. ((memq restriction '(subtree region))
  1995. nil)
  1996. (t 'buffer))))
  1997. ((eq c ?>)
  1998. (org-agenda-remove-restriction-lock 'noupdate)
  1999. (setq restriction nil))
  2000. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2001. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2002. ((and (> (length selstring) 0) (eq c ?\d))
  2003. (delete-window)
  2004. (org-agenda-get-restriction-and-command prefix-descriptions))
  2005. ((equal c ?q) (error "Abort"))
  2006. (t (error "Invalid key %c" c))))))))
  2007. (defun org-run-agenda-series (name series)
  2008. (org-let (nth 1 series) '(org-prepare-agenda name))
  2009. (let* ((org-agenda-multi t)
  2010. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2011. (cmds (car series))
  2012. (gprops (nth 1 series))
  2013. match ;; The byte compiler incorrectly complains about this. Keep it!
  2014. cmd type lprops)
  2015. (while (setq cmd (pop cmds))
  2016. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2017. (cond
  2018. ((eq type 'agenda)
  2019. (org-let2 gprops lprops
  2020. '(call-interactively 'org-agenda-list)))
  2021. ((eq type 'alltodo)
  2022. (org-let2 gprops lprops
  2023. '(call-interactively 'org-todo-list)))
  2024. ((eq type 'search)
  2025. (org-let2 gprops lprops
  2026. '(org-search-view current-prefix-arg match nil)))
  2027. ((eq type 'stuck)
  2028. (org-let2 gprops lprops
  2029. '(call-interactively 'org-agenda-list-stuck-projects)))
  2030. ((eq type 'tags)
  2031. (org-let2 gprops lprops
  2032. '(org-tags-view current-prefix-arg match)))
  2033. ((eq type 'tags-todo)
  2034. (org-let2 gprops lprops
  2035. '(org-tags-view '(4) match)))
  2036. ((eq type 'todo)
  2037. (org-let2 gprops lprops
  2038. '(org-todo-list match)))
  2039. ((fboundp type)
  2040. (org-let2 gprops lprops
  2041. '(funcall type match)))
  2042. (t (error "Invalid type in command series"))))
  2043. (widen)
  2044. (setq org-agenda-redo-command redo)
  2045. (goto-char (point-min)))
  2046. (org-fit-agenda-window)
  2047. (org-let (nth 1 series) '(org-finalize-agenda)))
  2048. ;;;###autoload
  2049. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2050. "Run an agenda command in batch mode and send the result to STDOUT.
  2051. If CMD-KEY is a string of length 1, it is used as a key in
  2052. `org-agenda-custom-commands' and triggers this command. If it is a
  2053. longer string it is used as a tags/todo match string.
  2054. Paramters are alternating variable names and values that will be bound
  2055. before running the agenda command."
  2056. (let (pars)
  2057. (while parameters
  2058. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2059. (if (> (length cmd-key) 2)
  2060. (eval (list 'let (nreverse pars)
  2061. (list 'org-tags-view nil cmd-key)))
  2062. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2063. (set-buffer org-agenda-buffer-name)
  2064. (princ (org-encode-for-stdout (buffer-string)))))
  2065. ;(defun org-encode-for-stdout (string)
  2066. ; (if (fboundp 'encode-coding-string)
  2067. ; (encode-coding-string string buffer-file-coding-system)
  2068. ; string))
  2069. (defun org-encode-for-stdout (string)
  2070. string)
  2071. (defvar org-agenda-info nil)
  2072. ;;;###autoload
  2073. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2074. "Run an agenda command in batch mode and send the result to STDOUT.
  2075. If CMD-KEY is a string of length 1, it is used as a key in
  2076. `org-agenda-custom-commands' and triggers this command. If it is a
  2077. longer string it is used as a tags/todo match string.
  2078. Paramters are alternating variable names and values that will be bound
  2079. before running the agenda command.
  2080. The output gives a line for each selected agenda item. Each
  2081. item is a list of comma-separated values, like this:
  2082. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2083. category The category of the item
  2084. head The headline, without TODO kwd, TAGS and PRIORITY
  2085. type The type of the agenda entry, can be
  2086. todo selected in TODO match
  2087. tagsmatch selected in tags match
  2088. diary imported from diary
  2089. deadline a deadline on given date
  2090. scheduled scheduled on given date
  2091. timestamp entry has timestamp on given date
  2092. closed entry was closed on given date
  2093. upcoming-deadline warning about deadline
  2094. past-scheduled forwarded scheduled item
  2095. block entry has date block including g. date
  2096. todo The todo keyword, if any
  2097. tags All tags including inherited ones, separated by colons
  2098. date The relevant date, like 2007-2-14
  2099. time The time, like 15:00-16:50
  2100. extra Sting with extra planning info
  2101. priority-l The priority letter if any was given
  2102. priority-n The computed numerical priority
  2103. agenda-day The day in the agenda where this is listed"
  2104. (let (pars)
  2105. (while parameters
  2106. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2107. (push (list 'org-agenda-remove-tags t) pars)
  2108. (if (> (length cmd-key) 2)
  2109. (eval (list 'let (nreverse pars)
  2110. (list 'org-tags-view nil cmd-key)))
  2111. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2112. (set-buffer org-agenda-buffer-name)
  2113. (let* ((lines (org-split-string (buffer-string) "\n"))
  2114. line)
  2115. (while (setq line (pop lines))
  2116. (catch 'next
  2117. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2118. (setq org-agenda-info
  2119. (org-fix-agenda-info (text-properties-at 0 line)))
  2120. (princ
  2121. (org-encode-for-stdout
  2122. (mapconcat 'org-agenda-export-csv-mapper
  2123. '(org-category txt type todo tags date time extra
  2124. priority-letter priority agenda-day)
  2125. ",")))
  2126. (princ "\n"))))))
  2127. (defun org-fix-agenda-info (props)
  2128. "Make sure all properties on an agenda item have a canonical form,
  2129. so the export commands can easily use it."
  2130. (let (tmp re)
  2131. (when (setq tmp (plist-get props 'tags))
  2132. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2133. (when (setq tmp (plist-get props 'date))
  2134. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2135. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2136. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2137. (setq tmp (calendar-date-string tmp)))
  2138. (setq props (plist-put props 'date tmp)))
  2139. (when (setq tmp (plist-get props 'day))
  2140. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2141. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2142. (setq tmp (calendar-date-string tmp)))
  2143. (setq props (plist-put props 'day tmp))
  2144. (setq props (plist-put props 'agenda-day tmp)))
  2145. (when (setq tmp (plist-get props 'txt))
  2146. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2147. (plist-put props 'priority-letter (match-string 1 tmp))
  2148. (setq tmp (replace-match "" t t tmp)))
  2149. (when (and (setq re (plist-get props 'org-todo-regexp))
  2150. (setq re (concat "\\`\\.*" re " ?"))
  2151. (string-match re tmp))
  2152. (plist-put props 'todo (match-string 1 tmp))
  2153. (setq tmp (replace-match "" t t tmp)))
  2154. (plist-put props 'txt tmp)))
  2155. props)
  2156. (defun org-agenda-export-csv-mapper (prop)
  2157. (let ((res (plist-get org-agenda-info prop)))
  2158. (setq res
  2159. (cond
  2160. ((not res) "")
  2161. ((stringp res) res)
  2162. (t (prin1-to-string res))))
  2163. (while (string-match "," res)
  2164. (setq res (replace-match ";" t t res)))
  2165. (org-trim res)))
  2166. ;;;###autoload
  2167. (defun org-store-agenda-views (&rest parameters)
  2168. (interactive)
  2169. (eval (list 'org-batch-store-agenda-views)))
  2170. ;; FIXME, why is this a macro?????
  2171. ;;;###autoload
  2172. (defmacro org-batch-store-agenda-views (&rest parameters)
  2173. "Run all custom agenda commands that have a file argument."
  2174. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2175. (pop-up-frames nil)
  2176. (dir default-directory)
  2177. pars cmd thiscmdkey files opts cmd-or-set)
  2178. (while parameters
  2179. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2180. (setq pars (reverse pars))
  2181. (save-window-excursion
  2182. (while cmds
  2183. (setq cmd (pop cmds)
  2184. thiscmdkey (car cmd)
  2185. cmd-or-set (nth 2 cmd)
  2186. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2187. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2188. (if (stringp files) (setq files (list files)))
  2189. (when files
  2190. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2191. (list 'org-agenda nil thiscmdkey)))
  2192. (set-buffer org-agenda-buffer-name)
  2193. (while files
  2194. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2195. (list 'org-write-agenda
  2196. (expand-file-name (pop files) dir) nil t))))
  2197. (and (get-buffer org-agenda-buffer-name)
  2198. (kill-buffer org-agenda-buffer-name)))))))
  2199. (defun org-agenda-mark-header-line (pos)
  2200. "Mark the line at POS as an agenda structure header."
  2201. (save-excursion
  2202. (goto-char pos)
  2203. (put-text-property (point-at-bol) (point-at-eol)
  2204. 'org-agenda-structural-header t)
  2205. (when org-agenda-title-append
  2206. (put-text-property (point-at-bol) (point-at-eol)
  2207. 'org-agenda-title-append org-agenda-title-append))))
  2208. (defvar org-mobile-creating-agendas)
  2209. (defun org-write-agenda (file &optional open nosettings)
  2210. "Write the current buffer (an agenda view) as a file.
  2211. Depending on the extension of the file name, plain text (.txt),
  2212. HTML (.html or .htm) or Postscript (.ps) is produced.
  2213. If the extension is .ics, run icalendar export over all files used
  2214. to construct the agenda and limit the export to entries listed in the
  2215. agenda now.
  2216. With prefix argument OPEN, open the new file immediately.
  2217. If NOSETTINGS is given, do not scope the settings of
  2218. `org-agenda-exporter-settings' into the export commands. This is used when
  2219. the settings have already been scoped and we do not wish to overrule other,
  2220. higher priority settings."
  2221. (interactive "FWrite agenda to file: \nP")
  2222. (if (not (file-writable-p file))
  2223. (error "Cannot write agenda to file %s" file))
  2224. (cond
  2225. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2226. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2227. (org-let (if nosettings nil org-agenda-exporter-settings)
  2228. '(save-excursion
  2229. (save-window-excursion
  2230. (org-agenda-mark-filtered-text)
  2231. (let ((bs (copy-sequence (buffer-string))) beg)
  2232. (org-agenda-unmark-filtered-text)
  2233. (with-temp-buffer
  2234. (insert bs)
  2235. (org-agenda-remove-marked-text 'org-filtered)
  2236. (while (setq beg (text-property-any (point-min) (point-max)
  2237. 'org-filtered t))
  2238. (delete-region
  2239. beg (or (next-single-property-change beg 'org-filtered)
  2240. (point-max))))
  2241. (run-hooks 'org-agenda-before-write-hook)
  2242. (cond
  2243. ((org-bound-and-true-p org-mobile-creating-agendas)
  2244. (org-mobile-write-agenda-for-mobile file))
  2245. ((string-match "\\.html?\\'" file)
  2246. (set-buffer (htmlize-buffer (current-buffer)))
  2247. (when (and org-agenda-export-html-style
  2248. (string-match "<style>" org-agenda-export-html-style))
  2249. ;; replace <style> section with org-agenda-export-html-style
  2250. (goto-char (point-min))
  2251. (kill-region (- (search-forward "<style") 6)
  2252. (search-forward "</style>"))
  2253. (insert org-agenda-export-html-style))
  2254. (write-file file)
  2255. (kill-buffer (current-buffer))
  2256. (message "HTML written to %s" file))
  2257. ((string-match "\\.ps\\'" file)
  2258. (require 'ps-print)
  2259. (flet ((ps-get-buffer-name () "Agenda View"))
  2260. (ps-print-buffer-with-faces file))
  2261. (message "Postscript written to %s" file))
  2262. ((string-match "\\.pdf\\'" file)
  2263. (require 'ps-print)
  2264. (flet ((ps-get-buffer-name () "Agenda View"))
  2265. (ps-print-buffer-with-faces
  2266. (concat (file-name-sans-extension file) ".ps")))
  2267. (call-process "ps2pdf" nil nil nil
  2268. (expand-file-name
  2269. (concat (file-name-sans-extension file) ".ps"))
  2270. (expand-file-name file))
  2271. (message "PDF written to %s" file))
  2272. ((string-match "\\.ics\\'" file)
  2273. (require 'org-icalendar)
  2274. (let ((org-agenda-marker-table
  2275. (org-create-marker-find-array
  2276. (org-agenda-collect-markers)))
  2277. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2278. (org-combined-agenda-icalendar-file file))
  2279. (apply 'org-export-icalendar 'combine
  2280. (org-agenda-files nil 'ifmode))))
  2281. (t
  2282. (let ((bs (buffer-string)))
  2283. (find-file file)
  2284. (erase-buffer)
  2285. (insert bs)
  2286. (save-buffer 0)
  2287. (kill-buffer (current-buffer))
  2288. (message "Plain text written to %s" file))))))))
  2289. (set-buffer org-agenda-buffer-name))
  2290. (when open (org-open-file file)))
  2291. (defvar org-agenda-filter-overlays nil)
  2292. (defun org-agenda-mark-filtered-text ()
  2293. "Mark all text hidden by filtering with a text property."
  2294. (let ((inhibit-read-only t))
  2295. (mapc
  2296. (lambda (o)
  2297. (when (equal (org-overlay-buffer o) (current-buffer))
  2298. (put-text-property
  2299. (org-overlay-start o) (org-overlay-end o)
  2300. 'org-filtered t)))
  2301. org-agenda-filter-overlays)))
  2302. (defun org-agenda-unmark-filtered-text ()
  2303. "Remove the filtering text property."
  2304. (let ((inhibit-read-only t))
  2305. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2306. (defun org-agenda-remove-marked-text (property &optional value)
  2307. "Delete all text marked with VALUE of PROPERTY.
  2308. VALUE defaults to t."
  2309. (let (beg)
  2310. (setq value (or value t))
  2311. (while (setq beg (text-property-any (point-min) (point-max)
  2312. property value))
  2313. (delete-region
  2314. beg (or (next-single-property-change beg 'org-filtered)
  2315. (point-max))))))
  2316. (defun org-agenda-add-entry-text ()
  2317. "Add entry text to agenda lines.
  2318. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2319. entry text following headings shown in the agenda.
  2320. Drawers will be excluded, also the line with scheduling/deadline info."
  2321. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2322. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2323. (let (m txt)
  2324. (goto-char (point-min))
  2325. (while (not (eobp))
  2326. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2327. (beginning-of-line 2)
  2328. (setq txt (org-agenda-get-some-entry-text
  2329. m org-agenda-add-entry-text-maxlines " > "))
  2330. (end-of-line 1)
  2331. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2332. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2333. &rest keep)
  2334. "Extract entry text from MARKER, at most N-LINES lines.
  2335. This will ignore drawers etc, just get the text.
  2336. If INDENT is given, prefix every line with this string. If KEEP is
  2337. given, it is a list of symbols, defining stuff that should not be
  2338. removed from the entry content. Currently only `planning' is allowed here."
  2339. (let (txt drawer-re kwd-time-re ind)
  2340. (save-excursion
  2341. (with-current-buffer (marker-buffer marker)
  2342. (if (not (org-mode-p))
  2343. (setq txt "")
  2344. (save-excursion
  2345. (save-restriction
  2346. (widen)
  2347. (goto-char marker)
  2348. (end-of-line 1)
  2349. (setq txt (buffer-substring
  2350. (min (1+ (point)) (point-max))
  2351. (progn (outline-next-heading) (point)))
  2352. drawer-re org-drawer-regexp
  2353. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2354. ".*\n?"))
  2355. (with-temp-buffer
  2356. (insert txt)
  2357. (when org-agenda-add-entry-text-descriptive-links
  2358. (goto-char (point-min))
  2359. (while (org-activate-bracket-links (point-max))
  2360. (add-text-properties (match-beginning 0) (match-end 0)
  2361. '(face org-link))))
  2362. (goto-char (point-min))
  2363. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2364. (set-text-properties (match-beginning 0) (match-end 0)
  2365. nil))
  2366. (goto-char (point-min))
  2367. (while (re-search-forward drawer-re nil t)
  2368. (delete-region
  2369. (match-beginning 0)
  2370. (progn (re-search-forward
  2371. "^[ \t]*:END:.*\n?" nil 'move)
  2372. (point))))
  2373. (unless (member 'planning keep)
  2374. (goto-char (point-min))
  2375. (while (re-search-forward kwd-time-re nil t)
  2376. (replace-match "")))
  2377. (goto-char (point-min))
  2378. (when org-agenda-entry-text-exclude-regexps
  2379. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2380. (while (setq re (pop re-list))
  2381. (goto-char (point-min))
  2382. (while (re-search-forward re nil t)
  2383. (replace-match "")))))
  2384. (goto-char (point-max))
  2385. (skip-chars-backward " \t\n")
  2386. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2387. ;; find and remove min common indentation
  2388. (goto-char (point-min))
  2389. (untabify (point-min) (point-max))
  2390. (setq ind (org-get-indentation))
  2391. (while (not (eobp))
  2392. (unless (looking-at "[ \t]*$")
  2393. (setq ind (min ind (org-get-indentation))))
  2394. (beginning-of-line 2))
  2395. (goto-char (point-min))
  2396. (while (not (eobp))
  2397. (unless (looking-at "[ \t]*$")
  2398. (move-to-column ind)
  2399. (delete-region (point-at-bol) (point)))
  2400. (beginning-of-line 2))
  2401. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2402. (goto-char (point-min))
  2403. (when indent
  2404. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2405. (replace-match indent t t)))
  2406. (goto-char (point-min))
  2407. (while (looking-at "[ \t]*\n") (replace-match ""))
  2408. (goto-char (point-max))
  2409. (when (> (org-current-line)
  2410. n-lines)
  2411. (org-goto-line (1+ n-lines))
  2412. (backward-char 1))
  2413. (setq txt (buffer-substring (point-min) (point)))))))))
  2414. txt))
  2415. (defun org-agenda-collect-markers ()
  2416. "Collect the markers pointing to entries in the agenda buffer."
  2417. (let (m markers)
  2418. (save-excursion
  2419. (goto-char (point-min))
  2420. (while (not (eobp))
  2421. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2422. (org-get-at-bol 'org-marker)))
  2423. (push m markers))
  2424. (beginning-of-line 2)))
  2425. (nreverse markers)))
  2426. (defun org-create-marker-find-array (marker-list)
  2427. "Create a alist of files names with all marker positions in that file."
  2428. (let (f tbl m a p)
  2429. (while (setq m (pop marker-list))
  2430. (setq p (marker-position m)
  2431. f (buffer-file-name (or (buffer-base-buffer
  2432. (marker-buffer m))
  2433. (marker-buffer m))))
  2434. (if (setq a (assoc f tbl))
  2435. (push (marker-position m) (cdr a))
  2436. (push (list f p) tbl)))
  2437. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2438. tbl)))
  2439. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2440. (defun org-check-agenda-marker-table ()
  2441. "Check of the current entry is on the marker list."
  2442. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2443. a)
  2444. (and (setq a (assoc file org-agenda-marker-table))
  2445. (save-match-data
  2446. (save-excursion
  2447. (org-back-to-heading t)
  2448. (member (point) (cdr a)))))))
  2449. (defun org-check-for-org-mode ()
  2450. "Make sure current buffer is in org-mode. Error if not."
  2451. (or (org-mode-p)
  2452. (error "Cannot execute org-mode agenda command on buffer in %s"
  2453. major-mode)))
  2454. (defun org-fit-agenda-window ()
  2455. "Fit the window to the buffer size."
  2456. (and (memq org-agenda-window-setup '(reorganize-frame))
  2457. (fboundp 'fit-window-to-buffer)
  2458. (org-fit-window-to-buffer
  2459. nil
  2460. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2461. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2462. ;;; Agenda prepare and finalize
  2463. (defvar org-agenda-multi nil) ; dynamically scoped
  2464. (defvar org-agenda-buffer-name "*Org Agenda*")
  2465. (defvar org-pre-agenda-window-conf nil)
  2466. (defvar org-agenda-columns-active nil)
  2467. (defvar org-agenda-name nil)
  2468. (defvar org-agenda-filter nil)
  2469. (defvar org-agenda-filter-preset nil
  2470. "A preset of the tags filter used for secondary agenda filtering.
  2471. This must be a list of strings, each string must be a single tag preceeded
  2472. by \"+\" or \"-\".
  2473. This variable should not be set directly, but agenda custom commands can
  2474. bind it in the options section.")
  2475. (defun org-prepare-agenda (&optional name)
  2476. (setq org-todo-keywords-for-agenda nil)
  2477. (setq org-done-keywords-for-agenda nil)
  2478. (setq org-drawers-for-agenda nil)
  2479. (setq org-agenda-filter nil)
  2480. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2481. (if org-agenda-multi
  2482. (progn
  2483. (setq buffer-read-only nil)
  2484. (goto-char (point-max))
  2485. (unless (or (bobp) org-agenda-compact-blocks)
  2486. (insert "\n"
  2487. (if (stringp org-agenda-block-separator)
  2488. org-agenda-block-separator
  2489. (make-string (window-width) org-agenda-block-separator))
  2490. "\n"))
  2491. (narrow-to-region (point) (point-max)))
  2492. (org-agenda-reset-markers)
  2493. (setq org-agenda-contributing-files nil)
  2494. (setq org-agenda-columns-active nil)
  2495. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2496. (setq org-todo-keywords-for-agenda
  2497. (org-uniquify org-todo-keywords-for-agenda))
  2498. (setq org-done-keywords-for-agenda
  2499. (org-uniquify org-done-keywords-for-agenda))
  2500. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2501. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2502. (awin (get-buffer-window abuf)))
  2503. (cond
  2504. ((equal (current-buffer) abuf) nil)
  2505. (awin (select-window awin))
  2506. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2507. ((equal org-agenda-window-setup 'current-window)
  2508. (switch-to-buffer abuf))
  2509. ((equal org-agenda-window-setup 'other-window)
  2510. (org-switch-to-buffer-other-window abuf))
  2511. ((equal org-agenda-window-setup 'other-frame)
  2512. (switch-to-buffer-other-frame abuf))
  2513. ((equal org-agenda-window-setup 'reorganize-frame)
  2514. (delete-other-windows)
  2515. (org-switch-to-buffer-other-window abuf))))
  2516. (setq buffer-read-only nil)
  2517. (let ((inhibit-read-only t)) (erase-buffer))
  2518. (org-agenda-mode)
  2519. (and name (not org-agenda-name)
  2520. (org-set-local 'org-agenda-name name)))
  2521. (setq buffer-read-only nil))
  2522. (defun org-finalize-agenda ()
  2523. "Finishing touch for the agenda buffer, called just before displaying it."
  2524. (unless org-agenda-multi
  2525. (save-excursion
  2526. (let ((inhibit-read-only t))
  2527. (goto-char (point-min))
  2528. (while (org-activate-bracket-links (point-max))
  2529. (add-text-properties (match-beginning 0) (match-end 0)
  2530. '(face org-link)))
  2531. (org-agenda-align-tags)
  2532. (unless org-agenda-with-colors
  2533. (remove-text-properties (point-min) (point-max) '(face nil))))
  2534. (if (and (boundp 'org-agenda-overriding-columns-format)
  2535. org-agenda-overriding-columns-format)
  2536. (org-set-local 'org-agenda-overriding-columns-format
  2537. org-agenda-overriding-columns-format))
  2538. (if (and (boundp 'org-agenda-view-columns-initially)
  2539. org-agenda-view-columns-initially)
  2540. (org-agenda-columns))
  2541. (when org-agenda-fontify-priorities
  2542. (org-agenda-fontify-priorities))
  2543. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2544. (org-agenda-dim-blocked-tasks))
  2545. (org-agenda-mark-clocking-task)
  2546. (when org-agenda-entry-text-mode
  2547. (org-agenda-entry-text-hide)
  2548. (org-agenda-entry-text-show))
  2549. (if (functionp 'org-habit-insert-consistency-graphs)
  2550. (org-habit-insert-consistency-graphs))
  2551. (run-hooks 'org-finalize-agenda-hook)
  2552. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2553. (when (get 'org-agenda-filter :preset-filter)
  2554. (org-agenda-filter-apply org-agenda-filter))
  2555. )))
  2556. (defun org-agenda-mark-clocking-task ()
  2557. "Mark the current clock entry in the agenda if it is present."
  2558. (mapc (lambda (o)
  2559. (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
  2560. (org-delete-overlay o)))
  2561. (org-overlays-in (point-min) (point-max)))
  2562. (when (marker-buffer org-clock-hd-marker)
  2563. (save-excursion
  2564. (goto-char (point-min))
  2565. (let (s ov)
  2566. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2567. (goto-char s)
  2568. (when (equal (org-get-at-bol 'org-hd-marker)
  2569. org-clock-hd-marker)
  2570. (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
  2571. (org-overlay-put ov 'type 'org-agenda-clocking)
  2572. (org-overlay-put ov 'face 'org-agenda-clocking)
  2573. (org-overlay-put ov 'help-echo
  2574. "The clock is running in this item")))))))
  2575. (defun org-agenda-fontify-priorities ()
  2576. "Make highest priority lines bold, and lowest italic."
  2577. (interactive)
  2578. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
  2579. (org-delete-overlay o)))
  2580. (org-overlays-in (point-min) (point-max)))
  2581. (save-excursion
  2582. (let ((inhibit-read-only t)
  2583. b e p ov h l)
  2584. (goto-char (point-min))
  2585. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2586. (setq h (or (get-char-property (point) 'org-highest-priority)
  2587. org-highest-priority)
  2588. l (or (get-char-property (point) 'org-lowest-priority)
  2589. org-lowest-priority)
  2590. p (string-to-char (match-string 1))
  2591. b (match-beginning 0)
  2592. e (if (eq org-agenda-fontify-priorities 'cookies)
  2593. (match-end 0)
  2594. (point-at-eol))
  2595. ov (org-make-overlay b e))
  2596. (org-overlay-put
  2597. ov 'face
  2598. (cond ((org-face-from-face-or-color
  2599. 'priority nil
  2600. (cdr (assoc p org-priority-faces))))
  2601. ((and (listp org-agenda-fontify-priorities)
  2602. (org-face-from-face-or-color
  2603. 'priority nil
  2604. (cdr (assoc p org-agenda-fontify-priorities)))))
  2605. ((equal p l) 'italic)
  2606. ((equal p h) 'bold)))
  2607. (org-overlay-put ov 'org-type 'org-priority)))))
  2608. (defun org-agenda-dim-blocked-tasks ()
  2609. "Dim currently blocked TODO's in the agenda display."
  2610. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
  2611. (org-delete-overlay o)))
  2612. (org-overlays-in (point-min) (point-max)))
  2613. (save-excursion
  2614. (let ((inhibit-read-only t)
  2615. (org-depend-tag-blocked nil)
  2616. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2617. org-blocked-by-checkboxes
  2618. invis1 b e p ov h l)
  2619. (goto-char (point-min))
  2620. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2621. (and pos (goto-char (1+ pos))))
  2622. (setq org-blocked-by-checkboxes nil invis1 invis)
  2623. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2624. (when (and marker
  2625. (not (with-current-buffer (marker-buffer marker)
  2626. (save-excursion
  2627. (goto-char marker)
  2628. (if (org-entry-get nil "NOBLOCKING")
  2629. t ;; Never block this entry
  2630. (run-hook-with-args-until-failure
  2631. 'org-blocker-hook
  2632. (list :type 'todo-state-change
  2633. :position marker
  2634. :from 'todo
  2635. :to 'done)))))))
  2636. (if org-blocked-by-checkboxes (setq invis1 nil))
  2637. (setq b (if invis1
  2638. (max (point-min) (1- (point-at-bol)))
  2639. (point-at-bol))
  2640. e (point-at-eol)
  2641. ov (org-make-overlay b e))
  2642. (if invis1
  2643. (org-overlay-put ov 'invisible t)
  2644. (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2645. (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
  2646. (defvar org-agenda-skip-function nil
  2647. "Function to be called at each match during agenda construction.
  2648. If this function returns nil, the current match should not be skipped.
  2649. Otherwise, the function must return a position from where the search
  2650. should be continued.
  2651. This may also be a Lisp form, it will be evaluated.
  2652. Never set this variable using `setq' or so, because then it will apply
  2653. to all future agenda commands. Instead, bind it with `let' to scope
  2654. it dynamically into the agenda-constructing command. A good way to set
  2655. it is through options in org-agenda-custom-commands.")
  2656. (defun org-agenda-skip ()
  2657. "Throw to `:skip' in places that should be skipped.
  2658. Also moves point to the end of the skipped region, so that search can
  2659. continue from there."
  2660. (let ((p (point-at-bol)) to fp)
  2661. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2662. (get-text-property p :org-archived)
  2663. (org-end-of-subtree t)
  2664. (throw :skip t))
  2665. (and org-agenda-skip-comment-trees
  2666. (get-text-property p :org-comment)
  2667. (org-end-of-subtree t)
  2668. (throw :skip t))
  2669. (if (equal (char-after p) ?#) (throw :skip t))
  2670. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2671. (consp org-agenda-skip-function))
  2672. (setq to (save-excursion
  2673. (save-match-data
  2674. (if fp
  2675. (funcall org-agenda-skip-function)
  2676. (eval org-agenda-skip-function))))))
  2677. (goto-char to)
  2678. (throw :skip t))))
  2679. (defvar org-agenda-markers nil
  2680. "List of all currently active markers created by `org-agenda'.")
  2681. (defvar org-agenda-last-marker-time (org-float-time)
  2682. "Creation time of the last agenda marker.")
  2683. (defun org-agenda-new-marker (&optional pos)
  2684. "Return a new agenda marker.
  2685. Org-mode keeps a list of these markers and resets them when they are
  2686. no longer in use."
  2687. (let ((m (copy-marker (or pos (point)))))
  2688. (setq org-agenda-last-marker-time (org-float-time))
  2689. (push m org-agenda-markers)
  2690. m))
  2691. (defun org-agenda-reset-markers ()
  2692. "Reset markers created by `org-agenda'."
  2693. (while org-agenda-markers
  2694. (move-marker (pop org-agenda-markers) nil)))
  2695. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2696. "Save relative positions of markers in region."
  2697. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2698. org-agenda-markers))
  2699. ;;; Entry text mode
  2700. (defun org-agenda-entry-text-show-here ()
  2701. "Add some text from the entry as context to the current line."
  2702. (let (m txt o)
  2703. (setq m (org-get-at-bol 'org-hd-marker))
  2704. (unless (marker-buffer m)
  2705. (error "No marker points to an entry here"))
  2706. (setq txt (concat "\n" (org-no-properties
  2707. (org-agenda-get-some-entry-text
  2708. m org-agenda-entry-text-maxlines " > "))))
  2709. (when (string-match "\\S-" txt)
  2710. (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
  2711. (org-overlay-put o 'evaporate t)
  2712. (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
  2713. (org-overlay-put o 'after-string txt))))
  2714. (defun org-agenda-entry-text-show ()
  2715. "Add entry context for all agenda lines."
  2716. (interactive)
  2717. (save-excursion
  2718. (goto-char (point-max))
  2719. (beginning-of-line 1)
  2720. (while (not (bobp))
  2721. (when (org-get-at-bol 'org-hd-marker)
  2722. (org-agenda-entry-text-show-here))
  2723. (beginning-of-line 0))))
  2724. (defun org-agenda-entry-text-hide ()
  2725. "Remove any shown entry context."
  2726. (delq nil
  2727. (mapcar (lambda (o)
  2728. (if (eq (org-overlay-get o 'org-overlay-type)
  2729. 'agenda-entry-content)
  2730. (progn (org-delete-overlay o) t)))
  2731. (org-overlays-in (point-min) (point-max)))))
  2732. ;;; Agenda timeline
  2733. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2734. (defun org-timeline (&optional include-all)
  2735. "Show a time-sorted view of the entries in the current org file.
  2736. Only entries with a time stamp of today or later will be listed. With
  2737. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2738. under the current date.
  2739. If the buffer contains an active region, only check the region for
  2740. dates."
  2741. (interactive "P")
  2742. (require 'calendar)
  2743. (org-compile-prefix-format 'timeline)
  2744. (org-set-sorting-strategy 'timeline)
  2745. (let* ((dopast t)
  2746. (dotodo include-all)
  2747. (doclosed org-agenda-show-log)
  2748. (entry buffer-file-name)
  2749. (date (calendar-current-date))
  2750. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2751. (end (if (org-region-active-p) (region-end) (point-max)))
  2752. (day-numbers (org-get-all-dates beg end 'no-ranges
  2753. t doclosed ; always include today
  2754. org-timeline-show-empty-dates))
  2755. (org-deadline-warning-days 0)
  2756. (org-agenda-only-exact-dates t)
  2757. (today (time-to-days (current-time)))
  2758. (past t)
  2759. args
  2760. s e rtn d emptyp wd)
  2761. (setq org-agenda-redo-command
  2762. (list 'progn
  2763. (list 'org-switch-to-buffer-other-window (current-buffer))
  2764. (list 'org-timeline (list 'quote include-all))))
  2765. (if (not dopast)
  2766. ;; Remove past dates from the list of dates.
  2767. (setq day-numbers (delq nil (mapcar (lambda(x)
  2768. (if (>= x today) x nil))
  2769. day-numbers))))
  2770. (org-prepare-agenda (concat "Timeline "
  2771. (file-name-nondirectory buffer-file-name)))
  2772. (if doclosed (push :closed args))
  2773. (push :timestamp args)
  2774. (push :deadline args)
  2775. (push :scheduled args)
  2776. (push :sexp args)
  2777. (if dotodo (push :todo args))
  2778. (insert "Timeline of file " entry "\n")
  2779. (add-text-properties (point-min) (point)
  2780. (list 'face 'org-agenda-structure))
  2781. (org-agenda-mark-header-line (point-min))
  2782. (while (setq d (pop day-numbers))
  2783. (if (and (listp d) (eq (car d) :omitted))
  2784. (progn
  2785. (setq s (point))
  2786. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2787. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2788. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2789. (if (and (>= d today)
  2790. dopast
  2791. past)
  2792. (progn
  2793. (setq past nil)
  2794. (insert (make-string 79 ?-) "\n")))
  2795. (setq date (calendar-gregorian-from-absolute d)
  2796. wd (calendar-day-of-week date))
  2797. (setq s (point))
  2798. (setq rtn (and (not emptyp)
  2799. (apply 'org-agenda-get-day-entries entry
  2800. date args)))
  2801. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2802. (progn
  2803. (insert
  2804. (if (stringp org-agenda-format-date)
  2805. (format-time-string org-agenda-format-date
  2806. (org-time-from-absolute date))
  2807. (funcall org-agenda-format-date date))
  2808. "\n")
  2809. (put-text-property s (1- (point)) 'face
  2810. (if (member wd org-agenda-weekend-days)
  2811. 'org-agenda-date-weekend
  2812. 'org-agenda-date))
  2813. (put-text-property s (1- (point)) 'org-date-line t)
  2814. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2815. (if (equal d today)
  2816. (put-text-property s (1- (point)) 'org-today t))
  2817. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2818. (put-text-property s (1- (point)) 'day d)))))
  2819. (goto-char (point-min))
  2820. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2821. (point-min)))
  2822. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2823. (org-finalize-agenda)
  2824. (setq buffer-read-only t)))
  2825. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2826. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2827. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2828. not every single day in the range. If FORCE-TODAY is non-nil, make
  2829. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2830. inactive time stamps (those in square brackets) are included.
  2831. When EMPTY is non-nil, also include days without any entries."
  2832. (let ((re (concat
  2833. (if pre-re pre-re "")
  2834. (if inactive org-ts-regexp-both org-ts-regexp)))
  2835. dates dates1 date day day1 day2 ts1 ts2)
  2836. (if force-today
  2837. (setq dates (list (time-to-days (current-time)))))
  2838. (save-excursion
  2839. (goto-char beg)
  2840. (while (re-search-forward re end t)
  2841. (setq day (time-to-days (org-time-string-to-time
  2842. (substring (match-string 1) 0 10))))
  2843. (or (memq day dates) (push day dates)))
  2844. (unless no-ranges
  2845. (goto-char beg)
  2846. (while (re-search-forward org-tr-regexp end t)
  2847. (setq ts1 (substring (match-string 1) 0 10)
  2848. ts2 (substring (match-string 2) 0 10)
  2849. day1 (time-to-days (org-time-string-to-time ts1))
  2850. day2 (time-to-days (org-time-string-to-time ts2)))
  2851. (while (< (setq day1 (1+ day1)) day2)
  2852. (or (memq day1 dates) (push day1 dates)))))
  2853. (setq dates (sort dates '<))
  2854. (when empty
  2855. (while (setq day (pop dates))
  2856. (setq day2 (car dates))
  2857. (push day dates1)
  2858. (when (and day2 empty)
  2859. (if (or (eq empty t)
  2860. (and (numberp empty) (<= (- day2 day) empty)))
  2861. (while (< (setq day (1+ day)) day2)
  2862. (push (list day) dates1))
  2863. (push (cons :omitted (- day2 day)) dates1))))
  2864. (setq dates (nreverse dates1)))
  2865. dates)))
  2866. ;;; Agenda Daily/Weekly
  2867. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2868. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2869. "Custom commands can set this variable in the options section.")
  2870. (defvar org-agenda-last-arguments nil
  2871. "The arguments of the previous call to org-agenda")
  2872. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2873. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2874. (defvar org-include-all-loc nil) ; local variable
  2875. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2876. "List of types searched for when creating the daily/weekly agenda.
  2877. This variable is a list of symbols that controls the types of
  2878. items that appear in the daily/weekly agenda. Allowed symbols in this
  2879. list are are
  2880. :timestamp List items containing a date stamp or date range matching
  2881. the selected date. This includes sexp entries in
  2882. angular brackets.
  2883. :sexp List entries resulting from plain diary-like sexps.
  2884. :deadline List deadline due on that date. When the date is today,
  2885. also list any deadlines past due, or due within
  2886. `org-deadline-warning-days'. `:deadline' must appear before
  2887. `:scheduled' if the setting of
  2888. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2889. any effect.
  2890. :scheduled List all items which are scheduled for the given date.
  2891. The diary for *today* also contains items which were
  2892. scheduled earlier and are not yet marked DONE.
  2893. By default, all four types are turned on.
  2894. Never set this variable globally using `setq', because then it
  2895. will apply to all future agenda commands. Instead, bind it with
  2896. `let' to scope it dynamically into the the agenda-constructing
  2897. command. A good way to set it is through options in
  2898. `org-agenda-custom-commands'. For a more flexible (though
  2899. somewhat less efficient) way of determining what is included in
  2900. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2901. ;;;###autoload
  2902. (defun org-agenda-list (&optional include-all start-day ndays)
  2903. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2904. The view will be for the current day or week, but from the overview buffer
  2905. you will be able to go to other days/weeks.
  2906. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2907. all unfinished TODO items will also be shown, before the agenda.
  2908. This feature is considered obsolete, please use the TODO list or a block
  2909. agenda instead.
  2910. With a numeric prefix argument in an interactive call, the agenda will
  2911. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2912. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2913. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2914. given in `org-agenda-start-on-weekday'."
  2915. (interactive "P")
  2916. (if (and (integerp include-all) (> include-all 0))
  2917. (setq ndays include-all include-all nil))
  2918. (setq ndays (or ndays org-agenda-ndays)
  2919. start-day (or start-day org-agenda-start-day))
  2920. (if org-agenda-overriding-arguments
  2921. (setq include-all (car org-agenda-overriding-arguments)
  2922. start-day (nth 1 org-agenda-overriding-arguments)
  2923. ndays (nth 2 org-agenda-overriding-arguments)))
  2924. (if (stringp start-day)
  2925. ;; Convert to an absolute day number
  2926. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2927. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2928. (org-compile-prefix-format 'agenda)
  2929. (org-set-sorting-strategy 'agenda)
  2930. (require 'calendar)
  2931. (let* ((org-agenda-start-on-weekday
  2932. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2933. org-agenda-start-on-weekday nil))
  2934. (thefiles (org-agenda-files nil 'ifmode))
  2935. (files thefiles)
  2936. (today (time-to-days
  2937. (time-subtract (current-time)
  2938. (list 0 (* 3600 org-extend-today-until) 0))))
  2939. (sd (or start-day today))
  2940. (start (if (or (null org-agenda-start-on-weekday)
  2941. (< org-agenda-ndays 7))
  2942. sd
  2943. (let* ((nt (calendar-day-of-week
  2944. (calendar-gregorian-from-absolute sd)))
  2945. (n1 org-agenda-start-on-weekday)
  2946. (d (- nt n1)))
  2947. (- sd (+ (if (< d 0) 7 0) d)))))
  2948. (day-numbers (list start))
  2949. (day-cnt 0)
  2950. (inhibit-redisplay (not debug-on-error))
  2951. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2952. clocktable-start clocktable-end)
  2953. (setq org-agenda-redo-command
  2954. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2955. ;; Make the list of days
  2956. (setq ndays (or ndays org-agenda-ndays)
  2957. nd ndays)
  2958. (while (> ndays 1)
  2959. (push (1+ (car day-numbers)) day-numbers)
  2960. (setq ndays (1- ndays)))
  2961. (setq day-numbers (nreverse day-numbers))
  2962. (setq clocktable-start (car day-numbers)
  2963. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2964. (org-prepare-agenda "Day/Week")
  2965. (org-set-local 'org-starting-day (car day-numbers))
  2966. (org-set-local 'org-include-all-loc include-all)
  2967. (org-set-local 'org-agenda-span
  2968. (org-agenda-ndays-to-span nd))
  2969. (when (and (or include-all org-agenda-include-all-todo)
  2970. (member today day-numbers))
  2971. (setq files thefiles
  2972. rtnall nil)
  2973. (while (setq file (pop files))
  2974. (catch 'nextfile
  2975. (org-check-agenda-file file)
  2976. (setq date (calendar-gregorian-from-absolute today)
  2977. rtn (org-agenda-get-day-entries
  2978. file date :todo))
  2979. (setq rtnall (append rtnall rtn))))
  2980. (when rtnall
  2981. (insert "All currently open TODO items:\n")
  2982. (add-text-properties (point-min) (1- (point))
  2983. (list 'face 'org-agenda-structure
  2984. 'short-heading "All TODO items"))
  2985. (org-agenda-mark-header-line (point-min))
  2986. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2987. (unless org-agenda-compact-blocks
  2988. (let* ((d1 (car day-numbers))
  2989. (d2 (org-last day-numbers))
  2990. (w1 (org-days-to-iso-week d1))
  2991. (w2 (org-days-to-iso-week d2)))
  2992. (setq s (point))
  2993. (if org-agenda-overriding-header
  2994. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2995. nil 'face 'org-agenda-structure) "\n")
  2996. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  2997. "-agenda"
  2998. (if (< (- d2 d1) 350)
  2999. (if (= w1 w2)
  3000. (format " (W%02d)" w1)
  3001. (format " (W%02d-W%02d)" w1 w2))
  3002. "")
  3003. ":\n")))
  3004. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3005. 'org-date-line t))
  3006. (org-agenda-mark-header-line s))
  3007. (while (setq d (pop day-numbers))
  3008. (setq date (calendar-gregorian-from-absolute d)
  3009. wd (calendar-day-of-week date)
  3010. s (point))
  3011. (if (or (setq todayp (= d today))
  3012. (and (not start-pos) (= d sd)))
  3013. (setq start-pos (point))
  3014. (if (and start-pos (not end-pos))
  3015. (setq end-pos (point))))
  3016. (setq files thefiles
  3017. rtnall nil)
  3018. (while (setq file (pop files))
  3019. (catch 'nextfile
  3020. (org-check-agenda-file file)
  3021. (let ((org-agenda-entry-types org-agenda-entry-types))
  3022. (if org-agenda-include-deadlines
  3023. (add-to-list 'org-agenda-entry-types :deadline)
  3024. (setq org-agenda-entry-types
  3025. (delq :deadline org-agenda-entry-types)))
  3026. (cond
  3027. ((eq org-agenda-show-log 'only)
  3028. (setq rtn (org-agenda-get-day-entries
  3029. file date :closed)))
  3030. (org-agenda-show-log
  3031. (setq rtn (apply 'org-agenda-get-day-entries
  3032. file date
  3033. (append '(:closed) org-agenda-entry-types))))
  3034. (t
  3035. (setq rtn (apply 'org-agenda-get-day-entries
  3036. file date
  3037. org-agenda-entry-types)))))
  3038. (setq rtnall (append rtnall rtn))))
  3039. (if org-agenda-include-diary
  3040. (let ((org-agenda-search-headline-for-time t))
  3041. (require 'diary-lib)
  3042. (setq rtn (org-get-entries-from-diary date))
  3043. (setq rtnall (append rtnall rtn))))
  3044. (if (or rtnall org-agenda-show-all-dates)
  3045. (progn
  3046. (setq day-cnt (1+ day-cnt))
  3047. (insert
  3048. (if (stringp org-agenda-format-date)
  3049. (format-time-string org-agenda-format-date
  3050. (org-time-from-absolute date))
  3051. (funcall org-agenda-format-date date))
  3052. "\n")
  3053. (put-text-property s (1- (point)) 'face
  3054. (if (member wd org-agenda-weekend-days)
  3055. 'org-agenda-date-weekend
  3056. 'org-agenda-date))
  3057. (put-text-property s (1- (point)) 'org-date-line t)
  3058. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3059. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3060. (when todayp
  3061. (put-text-property s (1- (point)) 'org-today t)
  3062. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3063. (if rtnall (insert
  3064. (org-finalize-agenda-entries
  3065. (org-agenda-add-time-grid-maybe
  3066. rtnall nd todayp))
  3067. "\n"))
  3068. (put-text-property s (1- (point)) 'day d)
  3069. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3070. (when (and org-agenda-clockreport-mode clocktable-start)
  3071. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3072. ;; the above line is to ensure the restricted range!
  3073. (p org-agenda-clockreport-parameter-plist)
  3074. tbl)
  3075. (setq p (org-plist-delete p :block))
  3076. (setq p (plist-put p :tstart clocktable-start))
  3077. (setq p (plist-put p :tend clocktable-end))
  3078. (setq p (plist-put p :scope 'agenda))
  3079. (setq tbl (apply 'org-get-clocktable p))
  3080. (insert tbl)))
  3081. (goto-char (point-min))
  3082. (or org-agenda-multi (org-fit-agenda-window))
  3083. (unless (and (pos-visible-in-window-p (point-min))
  3084. (pos-visible-in-window-p (point-max)))
  3085. (goto-char (1- (point-max)))
  3086. (recenter -1)
  3087. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3088. (progn
  3089. (goto-char (or start-pos 1))
  3090. (recenter 1))))
  3091. (goto-char (or start-pos 1))
  3092. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3093. (org-finalize-agenda)
  3094. (setq buffer-read-only t)
  3095. (message "")))
  3096. (defun org-agenda-ndays-to-span (n)
  3097. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3098. ;;; Agenda word search
  3099. (defvar org-agenda-search-history nil)
  3100. (defvar org-todo-only nil)
  3101. (defvar org-search-syntax-table nil
  3102. "Special syntax table for org-mode search.
  3103. In this table, we have single quotes not as word constituents, to
  3104. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3105. (defun org-search-syntax-table ()
  3106. (unless org-search-syntax-table
  3107. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3108. (modify-syntax-entry ?' "." org-search-syntax-table)
  3109. (modify-syntax-entry ?` "." org-search-syntax-table))
  3110. org-search-syntax-table)
  3111. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3112. ;;;###autoload
  3113. (defun org-search-view (&optional todo-only string edit-at)
  3114. "Show all entries that contain a phrase or words or regular expressions.
  3115. With optional prefix argument TODO-ONLY, only consider entries that are
  3116. TODO entries. The argument STRING can be used to pass a default search
  3117. string into this function. If EDIT-AT is non-nil, it means that the
  3118. user should get a chance to edit this string, with cursor at position
  3119. EDIT-AT.
  3120. The search string can be viewed either as a phrase that should be found as
  3121. is, or it can be broken into a number of snippets, each of which must match
  3122. in a Boolean way to select an entry. The default depends on the variable
  3123. `org-agenda-search-view-always-boolean'.
  3124. Even if this is turned off (the default) you can always switch to
  3125. Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
  3126. The default is a direct search of the whole phrase, where each space in
  3127. the search string can expand to an arbitrary amount of whitespace,
  3128. including newlines.
  3129. If using a Boolean search, the search string is split on whitespace and
  3130. each snippet is searched separately, with logical AND to select an entry.
  3131. Words prefixed with a minus must *not* occur in the entry. Words without
  3132. a prefix or prefixed with a plus must occur in the entry. Matching is
  3133. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3134. match whole words, not parts of a word) if
  3135. `org-agenda-search-view-force-full-words' is set (default is nil).
  3136. Boolean search snippets enclosed by curly braces are interpreted as
  3137. regular expressions that must or (when preceeded with \"-\") must not
  3138. match in the entry. Snippets enclosed into double quotes will be taken
  3139. as a whole, to incude whitespace.
  3140. - If the search string starts with an asterisk, search only in headlines.
  3141. - If (possibly after the leading star) the search string starts with an
  3142. exclamation mark, this also means to look at TODO entries only, an effect
  3143. that can also be achieved with a prefix argument.
  3144. - If (possibly after star and exclamation mark) the search string starts
  3145. with a colon, this will mean that the (non-regexp) snippets of the
  3146. Boolean search must match as full words.
  3147. This command searches the agenda files, and in addition the files listed
  3148. in `org-agenda-text-search-extra-files'."
  3149. (interactive "P")
  3150. (org-compile-prefix-format 'search)
  3151. (org-set-sorting-strategy 'search)
  3152. (org-prepare-agenda "SEARCH")
  3153. (let* ((props (list 'face nil
  3154. 'done-face 'org-agenda-done
  3155. 'org-not-done-regexp org-not-done-regexp
  3156. 'org-todo-regexp org-todo-regexp
  3157. 'org-complex-heading-regexp org-complex-heading-regexp
  3158. 'mouse-face 'highlight
  3159. 'help-echo (format "mouse-2 or RET jump to location")))
  3160. (full-words org-agenda-search-view-force-full-words)
  3161. regexp rtn rtnall files file pos
  3162. marker category tags c neg re boolean
  3163. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3164. (unless (and (not edit-at)
  3165. (stringp string)
  3166. (string-match "\\S-" string))
  3167. (setq string (read-string
  3168. (if org-agenda-search-view-always-boolean
  3169. "[+-]Word/{Regexp} ...: "
  3170. "Phrase, or [+-]Word/{Regexp} ...: ")
  3171. (cond
  3172. ((integerp edit-at) (cons string edit-at))
  3173. (edit-at string))
  3174. 'org-agenda-search-history)))
  3175. (org-set-local 'org-todo-only todo-only)
  3176. (setq org-agenda-redo-command
  3177. (list 'org-search-view (if todo-only t nil) string
  3178. '(if current-prefix-arg 1 nil)))
  3179. (setq org-agenda-query-string string)
  3180. (if (equal (string-to-char string) ?*)
  3181. (setq hdl-only t
  3182. words (substring string 1))
  3183. (setq words string))
  3184. (when (equal (string-to-char words) ?!)
  3185. (setq todo-only t
  3186. words (substring words 1)))
  3187. (when (equal (string-to-char words) ?:)
  3188. (setq full-words t
  3189. words (substring words 1)))
  3190. (if (or org-agenda-search-view-always-boolean
  3191. (member (string-to-char words) '(?- ?+ ?\{)))
  3192. (setq boolean t))
  3193. (setq words (org-split-string words))
  3194. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3195. (when boolean
  3196. (let (wds w)
  3197. (while (setq w (pop words))
  3198. (if (or (equal (substring w 0 1) "\"")
  3199. (and (> (length w) 1)
  3200. (member (substring w 0 1) '("+" "-"))
  3201. (equal (substring w 1 2) "\"")))
  3202. (while (and words (not (equal (substring w -1) "\"")))
  3203. (setq w (concat w " " (pop words)))))
  3204. (and (string-match "\\`\\([-+]?\\)\"" w)
  3205. (setq w (replace-match "\\1" nil nil w)))
  3206. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3207. (push w wds))
  3208. (setq words (nreverse wds))))
  3209. (if boolean
  3210. (mapc (lambda (w)
  3211. (setq c (string-to-char w))
  3212. (if (equal c ?-)
  3213. (setq neg t w (substring w 1))
  3214. (if (equal c ?+)
  3215. (setq neg nil w (substring w 1))
  3216. (setq neg nil)))
  3217. (if (string-match "\\`{.*}\\'" w)
  3218. (setq re (substring w 1 -1))
  3219. (if full-words
  3220. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3221. (setq re (regexp-quote (downcase w)))))
  3222. (if neg (push re regexps-) (push re regexps+)))
  3223. words)
  3224. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3225. regexps+))
  3226. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3227. (if (not regexps+)
  3228. (setq regexp (concat "^" org-outline-regexp))
  3229. (setq regexp (pop regexps+))
  3230. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3231. regexp))))
  3232. (setq files (org-agenda-files nil 'ifmode))
  3233. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3234. (pop org-agenda-text-search-extra-files)
  3235. (setq files (org-add-archive-files files)))
  3236. (setq files (append files org-agenda-text-search-extra-files)
  3237. rtnall nil)
  3238. (while (setq file (pop files))
  3239. (setq ee nil)
  3240. (catch 'nextfile
  3241. (org-check-agenda-file file)
  3242. (setq buffer (if (file-exists-p file)
  3243. (org-get-agenda-file-buffer file)
  3244. (error "No such file %s" file)))
  3245. (if (not buffer)
  3246. ;; If file does not exist, make sure an error message is sent
  3247. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3248. file))))
  3249. (with-current-buffer buffer
  3250. (with-syntax-table (org-search-syntax-table)
  3251. (unless (org-mode-p)
  3252. (error "Agenda file %s is not in `org-mode'" file))
  3253. (let ((case-fold-search t))
  3254. (save-excursion
  3255. (save-restriction
  3256. (if org-agenda-restrict
  3257. (narrow-to-region org-agenda-restrict-begin
  3258. org-agenda-restrict-end)
  3259. (widen))
  3260. (goto-char (point-min))
  3261. (unless (or (org-on-heading-p)
  3262. (outline-next-heading))
  3263. (throw 'nextfile t))
  3264. (goto-char (max (point-min) (1- (point))))
  3265. (while (re-search-forward regexp nil t)
  3266. (org-back-to-heading t)
  3267. (skip-chars-forward "* ")
  3268. (setq beg (point-at-bol)
  3269. beg1 (point)
  3270. end (progn (outline-next-heading) (point)))
  3271. (catch :skip
  3272. (goto-char beg)
  3273. (org-agenda-skip)
  3274. (setq str (buffer-substring-no-properties
  3275. (point-at-bol)
  3276. (if hdl-only (point-at-eol) end)))
  3277. (mapc (lambda (wr) (when (string-match wr str)
  3278. (goto-char (1- end))
  3279. (throw :skip t)))
  3280. regexps-)
  3281. (mapc (lambda (wr) (unless (string-match wr str)
  3282. (goto-char (1- end))
  3283. (throw :skip t)))
  3284. (if todo-only
  3285. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3286. regexps+)
  3287. regexps+))
  3288. (goto-char beg)
  3289. (setq marker (org-agenda-new-marker (point))
  3290. category (org-get-category)
  3291. tags (org-get-tags-at (point))
  3292. txt (org-format-agenda-item
  3293. ""
  3294. (buffer-substring-no-properties
  3295. beg1 (point-at-eol))
  3296. category tags))
  3297. (org-add-props txt props
  3298. 'org-marker marker 'org-hd-marker marker
  3299. 'org-todo-regexp org-todo-regexp
  3300. 'org-complex-heading-regexp org-complex-heading-regexp
  3301. 'priority 1000 'org-category category
  3302. 'type "search")
  3303. (push txt ee)
  3304. (goto-char (1- end))))))))))
  3305. (setq rtn (nreverse ee))
  3306. (setq rtnall (append rtnall rtn)))
  3307. (if org-agenda-overriding-header
  3308. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3309. nil 'face 'org-agenda-structure) "\n")
  3310. (insert "Search words: ")
  3311. (add-text-properties (point-min) (1- (point))
  3312. (list 'face 'org-agenda-structure))
  3313. (setq pos (point))
  3314. (insert string "\n")
  3315. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3316. (setq pos (point))
  3317. (unless org-agenda-multi
  3318. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3319. (add-text-properties pos (1- (point))
  3320. (list 'face 'org-agenda-structure))))
  3321. (org-agenda-mark-header-line (point-min))
  3322. (when rtnall
  3323. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3324. (goto-char (point-min))
  3325. (or org-agenda-multi (org-fit-agenda-window))
  3326. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3327. (org-finalize-agenda)
  3328. (setq buffer-read-only t)))
  3329. ;;; Agenda TODO list
  3330. (defvar org-select-this-todo-keyword nil)
  3331. (defvar org-last-arg nil)
  3332. ;;;###autoload
  3333. (defun org-todo-list (arg)
  3334. "Show all TODO entries from all agenda file in a single list.
  3335. The prefix arg can be used to select a specific TODO keyword and limit
  3336. the list to these. When using \\[universal-argument], you will be prompted
  3337. for a keyword. A numeric prefix directly selects the Nth keyword in
  3338. `org-todo-keywords-1'."
  3339. (interactive "P")
  3340. (require 'calendar)
  3341. (org-compile-prefix-format 'todo)
  3342. (org-set-sorting-strategy 'todo)
  3343. (org-prepare-agenda "TODO")
  3344. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3345. (let* ((today (time-to-days (current-time)))
  3346. (date (calendar-gregorian-from-absolute today))
  3347. (kwds org-todo-keywords-for-agenda)
  3348. (completion-ignore-case t)
  3349. (org-select-this-todo-keyword
  3350. (if (stringp arg) arg
  3351. (and arg (integerp arg) (> arg 0)
  3352. (nth (1- arg) kwds))))
  3353. rtn rtnall files file pos)
  3354. (when (equal arg '(4))
  3355. (setq org-select-this-todo-keyword
  3356. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3357. (mapcar 'list kwds) nil nil)))
  3358. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3359. (org-set-local 'org-last-arg arg)
  3360. (setq org-agenda-redo-command
  3361. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3362. (setq files (org-agenda-files nil 'ifmode)
  3363. rtnall nil)
  3364. (while (setq file (pop files))
  3365. (catch 'nextfile
  3366. (org-check-agenda-file file)
  3367. (setq rtn (org-agenda-get-day-entries file date :todo))
  3368. (setq rtnall (append rtnall rtn))))
  3369. (if org-agenda-overriding-header
  3370. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3371. nil 'face 'org-agenda-structure) "\n")
  3372. (insert "Global list of TODO items of type: ")
  3373. (add-text-properties (point-min) (1- (point))
  3374. (list 'face 'org-agenda-structure
  3375. 'short-heading
  3376. (concat "ToDo: "
  3377. (or org-select-this-todo-keyword "ALL"))))
  3378. (org-agenda-mark-header-line (point-min))
  3379. (setq pos (point))
  3380. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3381. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3382. (setq pos (point))
  3383. (unless org-agenda-multi
  3384. (insert "Available with `N r': (0)ALL")
  3385. (let ((n 0) s)
  3386. (mapc (lambda (x)
  3387. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3388. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3389. (insert "\n "))
  3390. (insert " " s))
  3391. kwds))
  3392. (insert "\n"))
  3393. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3394. (org-agenda-mark-header-line (point-min))
  3395. (when rtnall
  3396. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3397. (goto-char (point-min))
  3398. (or org-agenda-multi (org-fit-agenda-window))
  3399. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3400. (org-finalize-agenda)
  3401. (setq buffer-read-only t)))
  3402. ;;; Agenda tags match
  3403. ;;;###autoload
  3404. (defun org-tags-view (&optional todo-only match)
  3405. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3406. The prefix arg TODO-ONLY limits the search to TODO entries."
  3407. (interactive "P")
  3408. (org-compile-prefix-format 'tags)
  3409. (org-set-sorting-strategy 'tags)
  3410. (let* ((org-tags-match-list-sublevels
  3411. org-tags-match-list-sublevels)
  3412. (completion-ignore-case t)
  3413. rtn rtnall files file pos matcher
  3414. buffer)
  3415. (when (and (stringp match) (not (string-match "\\S-" match)))
  3416. (setq match nil))
  3417. (setq matcher (org-make-tags-matcher match)
  3418. match (car matcher) matcher (cdr matcher))
  3419. (org-prepare-agenda (concat "TAGS " match))
  3420. (setq org-agenda-query-string match)
  3421. (setq org-agenda-redo-command
  3422. (list 'org-tags-view (list 'quote todo-only)
  3423. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3424. (setq files (org-agenda-files nil 'ifmode)
  3425. rtnall nil)
  3426. (while (setq file (pop files))
  3427. (catch 'nextfile
  3428. (org-check-agenda-file file)
  3429. (setq buffer (if (file-exists-p file)
  3430. (org-get-agenda-file-buffer file)
  3431. (error "No such file %s" file)))
  3432. (if (not buffer)
  3433. ;; If file does not exist, error message to agenda
  3434. (setq rtn (list
  3435. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3436. rtnall (append rtnall rtn))
  3437. (with-current-buffer buffer
  3438. (unless (org-mode-p)
  3439. (error "Agenda file %s is not in `org-mode'" file))
  3440. (save-excursion
  3441. (save-restriction
  3442. (if org-agenda-restrict
  3443. (narrow-to-region org-agenda-restrict-begin
  3444. org-agenda-restrict-end)
  3445. (widen))
  3446. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3447. (setq rtnall (append rtnall rtn))))))))
  3448. (if org-agenda-overriding-header
  3449. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3450. nil 'face 'org-agenda-structure) "\n")
  3451. (insert "Headlines with TAGS match: ")
  3452. (add-text-properties (point-min) (1- (point))
  3453. (list 'face 'org-agenda-structure
  3454. 'short-heading
  3455. (concat "Match: " match)))
  3456. (setq pos (point))
  3457. (insert match "\n")
  3458. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3459. (setq pos (point))
  3460. (unless org-agenda-multi
  3461. (insert "Press `C-u r' to search again with new search string\n"))
  3462. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3463. (org-agenda-mark-header-line (point-min))
  3464. (when rtnall
  3465. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3466. (goto-char (point-min))
  3467. (or org-agenda-multi (org-fit-agenda-window))
  3468. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3469. (org-finalize-agenda)
  3470. (setq buffer-read-only t)))
  3471. ;;; Agenda Finding stuck projects
  3472. (defvar org-agenda-skip-regexp nil
  3473. "Regular expression used in skipping subtrees for the agenda.
  3474. This is basically a temporary global variable that can be set and then
  3475. used by user-defined selections using `org-agenda-skip-function'.")
  3476. (defvar org-agenda-overriding-header nil
  3477. "When this is set during todo and tags searches, will replace header.
  3478. This variable should not be set directly, but custom commands can bind it
  3479. in the options section.")
  3480. (defun org-agenda-skip-entry-when-regexp-matches ()
  3481. "Checks if the current entry contains match for `org-agenda-skip-regexp'.
  3482. If yes, it returns the end position of this entry, causing agenda commands
  3483. to skip the entry but continuing the search in the subtree. This is a
  3484. function that can be put into `org-agenda-skip-function' for the duration
  3485. of a command."
  3486. (let ((end (save-excursion (org-end-of-subtree t)))
  3487. skip)
  3488. (save-excursion
  3489. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3490. (and skip end)))
  3491. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3492. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3493. If yes, it returns the end position of this tree, causing agenda commands
  3494. to skip this subtree. This is a function that can be put into
  3495. `org-agenda-skip-function' for the duration of a command."
  3496. (let ((end (save-excursion (org-end-of-subtree t)))
  3497. skip)
  3498. (save-excursion
  3499. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3500. (and skip end)))
  3501. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3502. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3503. If yes, it returns the end position of the current entry (NOT the tree),
  3504. causing agenda commands to skip the entry but continuing the search in
  3505. the subtree. This is a function that can be put into
  3506. `org-agenda-skip-function' for the duration of a command. An important
  3507. use of this function is for the stuck project list."
  3508. (let ((end (save-excursion (org-end-of-subtree t)))
  3509. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3510. skip)
  3511. (save-excursion
  3512. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3513. (and skip entry-end)))
  3514. (defun org-agenda-skip-entry-if (&rest conditions)
  3515. "Skip entry if any of CONDITIONS is true.
  3516. See `org-agenda-skip-if' for details."
  3517. (org-agenda-skip-if nil conditions))
  3518. (defun org-agenda-skip-subtree-if (&rest conditions)
  3519. "Skip entry if any of CONDITIONS is true.
  3520. See `org-agenda-skip-if' for details."
  3521. (org-agenda-skip-if t conditions))
  3522. (defun org-agenda-skip-if (subtree conditions)
  3523. "Checks current entity for CONDITIONS.
  3524. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3525. the entry, i.e. the text before the next heading is checked.
  3526. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3527. from different tests. Valid conditions are:
  3528. scheduled Check if there is a scheduled cookie
  3529. notscheduled Check if there is no scheduled cookie
  3530. deadline Check if there is a deadline
  3531. notdeadline Check if there is no deadline
  3532. timestamp Check if there is a timestamp (also deadline or scheduled)
  3533. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3534. regexp Check if regexp matches
  3535. notregexp Check if regexp does not match.
  3536. todo Check if TODO keyword matches
  3537. nottodo Check if TODO keyword does not match
  3538. The regexp is taken from the conditions list, it must come right after
  3539. the `regexp' or `notregexp' element.
  3540. `todo' and `nottodo' accept as an argument a list of todo
  3541. keywords, which may include \"*\" to match any todo keyword.
  3542. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3543. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3544. Instead of a list a keyword class may be given
  3545. (org-agenda-skip-entry-if 'nottodo 'done)
  3546. would skip entries that haven't been marked with any of \"DONE\"
  3547. keywords. Possible classes are: `todo', `done', `any'.
  3548. If any of these conditions is met, this function returns the end point of
  3549. the entity, causing the search to continue from there. This is a function
  3550. that can be put into `org-agenda-skip-function' for the duration of a command."
  3551. (let (beg end m)
  3552. (org-back-to-heading t)
  3553. (setq beg (point)
  3554. end (if subtree
  3555. (progn (org-end-of-subtree t) (point))
  3556. (progn (outline-next-heading) (1- (point)))))
  3557. (goto-char beg)
  3558. (and
  3559. (or
  3560. (and (memq 'scheduled conditions)
  3561. (re-search-forward org-scheduled-time-regexp end t))
  3562. (and (memq 'notscheduled conditions)
  3563. (not (re-search-forward org-scheduled-time-regexp end t)))
  3564. (and (memq 'deadline conditions)
  3565. (re-search-forward org-deadline-time-regexp end t))
  3566. (and (memq 'notdeadline conditions)
  3567. (not (re-search-forward org-deadline-time-regexp end t)))
  3568. (and (memq 'timestamp conditions)
  3569. (re-search-forward org-ts-regexp end t))
  3570. (and (memq 'nottimestamp conditions)
  3571. (not (re-search-forward org-ts-regexp end t)))
  3572. (and (setq m (memq 'regexp conditions))
  3573. (stringp (nth 1 m))
  3574. (re-search-forward (nth 1 m) end t))
  3575. (and (setq m (memq 'notregexp conditions))
  3576. (stringp (nth 1 m))
  3577. (not (re-search-forward (nth 1 m) end t)))
  3578. (and (or
  3579. (setq m (memq 'todo conditions))
  3580. (setq m (memq 'nottodo conditions)))
  3581. (org-agenda-skip-if-todo m end)))
  3582. end)))
  3583. (defun org-agenda-skip-if-todo (args end)
  3584. "Helper function for `org-agenda-skip-if', do not use it directly.
  3585. ARGS is a list with first element either `todo' or `nottodo'.
  3586. The remainder is either a list of TODO keywords, or a state symbol
  3587. `todo' or `done' or `any'."
  3588. (let ((kw (car args))
  3589. (arg (cadr args))
  3590. todo-wds todo-re)
  3591. (setq todo-wds
  3592. (org-uniquify
  3593. (cond
  3594. ((listp arg) ;; list of keywords
  3595. (if (member "*" arg)
  3596. (mapcar 'substring-no-properties org-todo-keywords-1)
  3597. arg))
  3598. ((symbolp arg) ;; keyword class name
  3599. (cond
  3600. ((eq arg 'todo)
  3601. (org-delete-all org-done-keywords
  3602. (mapcar 'substring-no-properties
  3603. org-todo-keywords-1)))
  3604. ((eq arg 'done) org-done-keywords)
  3605. ((eq arg 'any)
  3606. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3607. (setq todo-re
  3608. (concat "^\\*+[ \t]+\\<\\("
  3609. (mapconcat 'identity todo-wds "\\|")
  3610. "\\)\\>"))
  3611. (if (eq kw 'todo)
  3612. (re-search-forward todo-re end t)
  3613. (not (re-search-forward todo-re end t)))))
  3614. ;;;###autoload
  3615. (defun org-agenda-list-stuck-projects (&rest ignore)
  3616. "Create agenda view for projects that are stuck.
  3617. Stuck projects are project that have no next actions. For the definitions
  3618. of what a project is and how to check if it stuck, customize the variable
  3619. `org-stuck-projects'.
  3620. MATCH is being ignored."
  3621. (interactive)
  3622. (let* ((org-agenda-skip-function
  3623. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3624. ;; We could have used org-agenda-skip-if here.
  3625. (org-agenda-overriding-header
  3626. (or org-agenda-overriding-header "List of stuck projects: "))
  3627. (matcher (nth 0 org-stuck-projects))
  3628. (todo (nth 1 org-stuck-projects))
  3629. (todo-wds (if (member "*" todo)
  3630. (progn
  3631. (org-prepare-agenda-buffers (org-agenda-files
  3632. nil 'ifmode))
  3633. (org-delete-all
  3634. org-done-keywords-for-agenda
  3635. (copy-sequence org-todo-keywords-for-agenda)))
  3636. todo))
  3637. (todo-re (concat "^\\*+[ \t]+\\("
  3638. (mapconcat 'identity todo-wds "\\|")
  3639. "\\)\\>"))
  3640. (tags (nth 2 org-stuck-projects))
  3641. (tags-re (if (member "*" tags)
  3642. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3643. (if tags
  3644. (concat "^\\*+ .*:\\("
  3645. (mapconcat 'identity tags "\\|")
  3646. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3647. (gen-re (nth 3 org-stuck-projects))
  3648. (re-list
  3649. (delq nil
  3650. (list
  3651. (if todo todo-re)
  3652. (if tags tags-re)
  3653. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3654. gen-re)))))
  3655. (setq org-agenda-skip-regexp
  3656. (if re-list
  3657. (mapconcat 'identity re-list "\\|")
  3658. (error "No information how to identify unstuck projects")))
  3659. (org-tags-view nil matcher)
  3660. (with-current-buffer org-agenda-buffer-name
  3661. (setq org-agenda-redo-command
  3662. '(org-agenda-list-stuck-projects
  3663. (or current-prefix-arg org-last-arg))))))
  3664. ;;; Diary integration
  3665. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3666. (defvar list-diary-entries-hook)
  3667. (defun org-get-entries-from-diary (date)
  3668. "Get the (Emacs Calendar) diary entries for DATE."
  3669. (require 'diary-lib)
  3670. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3671. (fancy-diary-buffer diary-fancy-buffer)
  3672. (diary-display-hook '(fancy-diary-display))
  3673. (diary-display-function 'fancy-diary-display)
  3674. (pop-up-frames nil)
  3675. (list-diary-entries-hook
  3676. (cons 'org-diary-default-entry list-diary-entries-hook))
  3677. (diary-file-name-prefix-function nil) ; turn this feature off
  3678. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3679. entries
  3680. (org-disable-agenda-to-diary t))
  3681. (save-excursion
  3682. (save-window-excursion
  3683. (funcall (if (fboundp 'diary-list-entries)
  3684. 'diary-list-entries 'list-diary-entries)
  3685. date 1)))
  3686. (if (not (get-buffer diary-fancy-buffer))
  3687. (setq entries nil)
  3688. (with-current-buffer diary-fancy-buffer
  3689. (setq buffer-read-only nil)
  3690. (if (zerop (buffer-size))
  3691. ;; No entries
  3692. (setq entries nil)
  3693. ;; Omit the date and other unnecessary stuff
  3694. (org-agenda-cleanup-fancy-diary)
  3695. ;; Add prefix to each line and extend the text properties
  3696. (if (zerop (buffer-size))
  3697. (setq entries nil)
  3698. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3699. (set-buffer-modified-p nil)
  3700. (kill-buffer diary-fancy-buffer)))
  3701. (when entries
  3702. (setq entries (org-split-string entries "\n"))
  3703. (setq entries
  3704. (mapcar
  3705. (lambda (x)
  3706. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3707. ;; Extend the text properties to the beginning of the line
  3708. (org-add-props x (text-properties-at (1- (length x)) x)
  3709. 'type "diary" 'date date 'face 'org-agenda-diary))
  3710. entries)))))
  3711. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3712. "Hook run when the fancy diary buffer is cleaned up.")
  3713. (defun org-agenda-cleanup-fancy-diary ()
  3714. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3715. This gets rid of the date, the underline under the date, and
  3716. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3717. date. It also removes lines that contain only whitespace."
  3718. (goto-char (point-min))
  3719. (if (looking-at ".*?:[ \t]*")
  3720. (progn
  3721. (replace-match "")
  3722. (re-search-forward "\n=+$" nil t)
  3723. (replace-match "")
  3724. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3725. (re-search-forward "\n=+$" nil t)
  3726. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3727. (goto-char (point-min))
  3728. (while (re-search-forward "^ +\n" nil t)
  3729. (replace-match ""))
  3730. (goto-char (point-min))
  3731. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3732. (replace-match ""))
  3733. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3734. ;; Make sure entries from the diary have the right text properties.
  3735. (eval-after-load "diary-lib"
  3736. '(if (boundp 'diary-modify-entry-list-string-function)
  3737. ;; We can rely on the hook, nothing to do
  3738. nil
  3739. ;; Hook not available, must use advice to make this work
  3740. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3741. "Make the position visible."
  3742. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3743. (stringp string)
  3744. buffer-file-name)
  3745. (setq string (org-modify-diary-entry-string string))))))
  3746. (defun org-modify-diary-entry-string (string)
  3747. "Add text properties to string, allowing org-mode to act on it."
  3748. (org-add-props string nil
  3749. 'mouse-face 'highlight
  3750. 'help-echo (if buffer-file-name
  3751. (format "mouse-2 or RET jump to diary file %s"
  3752. (abbreviate-file-name buffer-file-name))
  3753. "")
  3754. 'org-agenda-diary-link t
  3755. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3756. (defun org-diary-default-entry ()
  3757. "Add a dummy entry to the diary.
  3758. Needed to avoid empty dates which mess up holiday display."
  3759. ;; Catch the error if dealing with the new add-to-diary-alist
  3760. (when org-disable-agenda-to-diary
  3761. (condition-case nil
  3762. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3763. (error
  3764. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3765. (defun org-add-to-diary-list (&rest args)
  3766. (if (fboundp 'diary-add-to-list)
  3767. (apply 'diary-add-to-list args)
  3768. (apply 'add-to-diary-list args)))
  3769. ;;;###autoload
  3770. (defun org-diary (&rest args)
  3771. "Return diary information from org-files.
  3772. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3773. It accesses org files and extracts information from those files to be
  3774. listed in the diary. The function accepts arguments specifying what
  3775. items should be listed. For a list of arguments allowed here, see the
  3776. variable `org-agenda-entry-types'.
  3777. The call in the diary file should look like this:
  3778. &%%(org-diary) ~/path/to/some/orgfile.org
  3779. Use a separate line for each org file to check. Or, if you omit the file name,
  3780. all files listed in `org-agenda-files' will be checked automatically:
  3781. &%%(org-diary)
  3782. If you don't give any arguments (as in the example above), the default
  3783. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3784. So the example above may also be written as
  3785. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3786. The function expects the lisp variables `entry' and `date' to be provided
  3787. by the caller, because this is how the calendar works. Don't use this
  3788. function from a program - use `org-agenda-get-day-entries' instead."
  3789. (when (> (- (org-float-time)
  3790. org-agenda-last-marker-time)
  3791. 5)
  3792. (org-agenda-reset-markers))
  3793. (org-compile-prefix-format 'agenda)
  3794. (org-set-sorting-strategy 'agenda)
  3795. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3796. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3797. (list entry)
  3798. (org-agenda-files t)))
  3799. file rtn results)
  3800. (org-prepare-agenda-buffers files)
  3801. ;; If this is called during org-agenda, don't return any entries to
  3802. ;; the calendar. Org Agenda will list these entries itself.
  3803. (if org-disable-agenda-to-diary (setq files nil))
  3804. (while (setq file (pop files))
  3805. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3806. (setq results (append results rtn)))
  3807. (if results
  3808. (concat (org-finalize-agenda-entries results) "\n"))))
  3809. ;;; Agenda entry finders
  3810. (defun org-agenda-get-day-entries (file date &rest args)
  3811. "Does the work for `org-diary' and `org-agenda'.
  3812. FILE is the path to a file to be checked for entries. DATE is date like
  3813. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3814. which kind of entries should be extracted. For details about these, see
  3815. the documentation of `org-diary'."
  3816. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3817. (let* ((org-startup-folded nil)
  3818. (org-startup-align-all-tables nil)
  3819. (buffer (if (file-exists-p file)
  3820. (org-get-agenda-file-buffer file)
  3821. (error "No such file %s" file)))
  3822. arg results rtn deadline-results)
  3823. (if (not buffer)
  3824. ;; If file does not exist, make sure an error message ends up in diary
  3825. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3826. (with-current-buffer buffer
  3827. (unless (org-mode-p)
  3828. (error "Agenda file %s is not in `org-mode'" file))
  3829. (let ((case-fold-search nil))
  3830. (save-excursion
  3831. (save-restriction
  3832. (if org-agenda-restrict
  3833. (narrow-to-region org-agenda-restrict-begin
  3834. org-agenda-restrict-end)
  3835. (widen))
  3836. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3837. (while (setq arg (pop args))
  3838. (cond
  3839. ((and (eq arg :todo)
  3840. (equal date (calendar-current-date)))
  3841. (setq rtn (org-agenda-get-todos))
  3842. (setq results (append results rtn)))
  3843. ((eq arg :timestamp)
  3844. (setq rtn (org-agenda-get-blocks))
  3845. (setq results (append results rtn))
  3846. (setq rtn (org-agenda-get-timestamps))
  3847. (setq results (append results rtn)))
  3848. ((eq arg :sexp)
  3849. (setq rtn (org-agenda-get-sexps))
  3850. (setq results (append results rtn)))
  3851. ((eq arg :scheduled)
  3852. (setq rtn (org-agenda-get-scheduled deadline-results))
  3853. (setq results (append results rtn)))
  3854. ((eq arg :closed)
  3855. (setq rtn (org-agenda-get-progress))
  3856. (setq results (append results rtn)))
  3857. ((eq arg :deadline)
  3858. (setq rtn (org-agenda-get-deadlines))
  3859. (setq deadline-results (copy-sequence rtn))
  3860. (setq results (append results rtn))))))))
  3861. results))))
  3862. (defun org-agenda-get-todos ()
  3863. "Return the TODO information for agenda display."
  3864. (let* ((props (list 'face nil
  3865. 'done-face 'org-agenda-done
  3866. 'org-not-done-regexp org-not-done-regexp
  3867. 'org-todo-regexp org-todo-regexp
  3868. 'org-complex-heading-regexp org-complex-heading-regexp
  3869. 'mouse-face 'highlight
  3870. 'help-echo
  3871. (format "mouse-2 or RET jump to org file %s"
  3872. (abbreviate-file-name buffer-file-name))))
  3873. (regexp (concat "^\\*+[ \t]+\\("
  3874. (if org-select-this-todo-keyword
  3875. (if (equal org-select-this-todo-keyword "*")
  3876. org-todo-regexp
  3877. (concat "\\<\\("
  3878. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3879. "\\)\\>"))
  3880. org-not-done-regexp)
  3881. "[^\n\r]*\\)"))
  3882. marker priority category tags todo-state
  3883. ee txt beg end)
  3884. (goto-char (point-min))
  3885. (while (re-search-forward regexp nil t)
  3886. (catch :skip
  3887. (save-match-data
  3888. (beginning-of-line)
  3889. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3890. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3891. (goto-char (1+ beg))
  3892. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3893. (throw :skip nil)))
  3894. (goto-char beg)
  3895. (org-agenda-skip)
  3896. (goto-char (match-beginning 1))
  3897. (setq marker (org-agenda-new-marker (match-beginning 0))
  3898. category (org-get-category)
  3899. txt (match-string 1)
  3900. tags (org-get-tags-at (point))
  3901. txt (org-format-agenda-item "" txt category tags)
  3902. priority (1+ (org-get-priority txt))
  3903. todo-state (org-get-todo-state))
  3904. (org-add-props txt props
  3905. 'org-marker marker 'org-hd-marker marker
  3906. 'priority priority 'org-category category
  3907. 'type "todo" 'todo-state todo-state)
  3908. (push txt ee)
  3909. (if org-agenda-todo-list-sublevels
  3910. (goto-char (match-end 1))
  3911. (org-end-of-subtree 'invisible))))
  3912. (nreverse ee)))
  3913. ;;;###autoload
  3914. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  3915. (&optional end)
  3916. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  3917. (when (or org-agenda-todo-ignore-with-date
  3918. org-agenda-todo-ignore-scheduled
  3919. org-agenda-todo-ignore-deadlines)
  3920. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3921. (save-excursion
  3922. (or (and org-agenda-todo-ignore-with-date
  3923. (re-search-forward org-ts-regexp end t))
  3924. (and org-agenda-todo-ignore-scheduled
  3925. (re-search-forward org-scheduled-time-regexp end t)
  3926. (cond
  3927. ((eq org-agenda-todo-ignore-scheduled 'future)
  3928. (> (org-days-to-time (match-string 1)) 0))
  3929. ((eq org-agenda-todo-ignore-scheduled 'past)
  3930. (<= (org-days-to-time (match-string 1)) 0))
  3931. (t)))
  3932. (and org-agenda-todo-ignore-deadlines
  3933. (re-search-forward org-deadline-time-regexp end t)
  3934. (cond
  3935. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  3936. ((eq org-agenda-todo-ignore-deadlines 'far)
  3937. (not (org-deadline-close (match-string 1))))
  3938. (t (org-deadline-close (match-string 1)))))))))
  3939. (defconst org-agenda-no-heading-message
  3940. "No heading for this item in buffer or region.")
  3941. (defun org-agenda-get-timestamps ()
  3942. "Return the date stamp information for agenda display."
  3943. (let* ((props (list 'face nil
  3944. 'org-not-done-regexp org-not-done-regexp
  3945. 'org-todo-regexp org-todo-regexp
  3946. 'org-complex-heading-regexp org-complex-heading-regexp
  3947. 'mouse-face 'highlight
  3948. 'help-echo
  3949. (format "mouse-2 or RET jump to org file %s"
  3950. (abbreviate-file-name buffer-file-name))))
  3951. (d1 (calendar-absolute-from-gregorian date))
  3952. (remove-re
  3953. (concat
  3954. (regexp-quote
  3955. (format-time-string
  3956. "<%Y-%m-%d"
  3957. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  3958. ".*?>"))
  3959. (regexp
  3960. (concat
  3961. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  3962. (regexp-quote
  3963. (substring
  3964. (format-time-string
  3965. (car org-time-stamp-formats)
  3966. (apply 'encode-time ; DATE bound by calendar
  3967. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3968. 1 11))
  3969. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  3970. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  3971. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  3972. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  3973. todo-state end-of-match)
  3974. (goto-char (point-min))
  3975. (while (setq end-of-match (re-search-forward regexp nil t))
  3976. (setq b0 (match-beginning 0)
  3977. b3 (match-beginning 3) e3 (match-end 3))
  3978. (catch :skip
  3979. (and (org-at-date-range-p) (throw :skip nil))
  3980. (org-agenda-skip)
  3981. (if (and (match-end 1)
  3982. (not (= d1 (org-time-string-to-absolute
  3983. (match-string 1) d1 nil
  3984. org-agenda-repeating-timestamp-show-all))))
  3985. (throw :skip nil))
  3986. (if (and e3
  3987. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  3988. (throw :skip nil))
  3989. (setq tmp (buffer-substring (max (point-min)
  3990. (- b0 org-ds-keyword-length))
  3991. b0)
  3992. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  3993. inactivep (= (char-after b0) ?\[)
  3994. deadlinep (string-match org-deadline-regexp tmp)
  3995. scheduledp (string-match org-scheduled-regexp tmp)
  3996. closedp (and org-agenda-include-inactive-timestamps
  3997. (string-match org-closed-string tmp))
  3998. clockp (and org-agenda-include-inactive-timestamps
  3999. (or (string-match org-clock-string tmp)
  4000. (string-match "]-+\\'" tmp)))
  4001. todo-state (org-get-todo-state)
  4002. donep (member todo-state org-done-keywords))
  4003. (if (or scheduledp deadlinep closedp clockp
  4004. (and donep org-agenda-skip-timestamp-if-done))
  4005. (throw :skip t))
  4006. (if (string-match ">" timestr)
  4007. ;; substring should only run to end of time stamp
  4008. (setq timestr (substring timestr 0 (match-end 0))))
  4009. (setq marker (org-agenda-new-marker b0)
  4010. category (org-get-category b0))
  4011. (save-excursion
  4012. (if (not (re-search-backward "^\\*+ " nil t))
  4013. (setq txt org-agenda-no-heading-message)
  4014. (goto-char (match-beginning 0))
  4015. (setq hdmarker (org-agenda-new-marker)
  4016. tags (org-get-tags-at))
  4017. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4018. (setq head (match-string 1))
  4019. (setq txt (org-format-agenda-item
  4020. (if inactivep org-agenda-inactive-leader nil)
  4021. head category tags timestr nil
  4022. remove-re)))
  4023. (setq priority (org-get-priority txt))
  4024. (org-add-props txt props
  4025. 'org-marker marker 'org-hd-marker hdmarker)
  4026. (org-add-props txt nil 'priority priority
  4027. 'org-category category 'date date
  4028. 'todo-state todo-state
  4029. 'type "timestamp")
  4030. (push txt ee))
  4031. (if org-agenda-skip-additional-timestamps-same-entry
  4032. (outline-next-heading)
  4033. (goto-char end-of-match))))
  4034. (nreverse ee)))
  4035. (defun org-agenda-get-sexps ()
  4036. "Return the sexp information for agenda display."
  4037. (require 'diary-lib)
  4038. (let* ((props (list 'face nil
  4039. 'mouse-face 'highlight
  4040. 'help-echo
  4041. (format "mouse-2 or RET jump to org file %s"
  4042. (abbreviate-file-name buffer-file-name))))
  4043. (regexp "^&?%%(")
  4044. marker category ee txt tags entry result beg b sexp sexp-entry
  4045. todo-state)
  4046. (goto-char (point-min))
  4047. (while (re-search-forward regexp nil t)
  4048. (catch :skip
  4049. (org-agenda-skip)
  4050. (setq beg (match-beginning 0))
  4051. (goto-char (1- (match-end 0)))
  4052. (setq b (point))
  4053. (forward-sexp 1)
  4054. (setq sexp (buffer-substring b (point)))
  4055. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4056. (org-trim (match-string 1))
  4057. ""))
  4058. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4059. (when result
  4060. (setq marker (org-agenda-new-marker beg)
  4061. category (org-get-category beg)
  4062. todo-state (org-get-todo-state))
  4063. (if (string-match "\\S-" result)
  4064. (setq txt result)
  4065. (setq txt "SEXP entry returned empty string"))
  4066. (setq txt (org-format-agenda-item
  4067. "" txt category tags 'time))
  4068. (org-add-props txt props 'org-marker marker)
  4069. (org-add-props txt nil
  4070. 'org-category category 'date date 'todo-state todo-state
  4071. 'type "sexp")
  4072. (push txt ee))))
  4073. (nreverse ee)))
  4074. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4075. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4076. The order of the first 2 times 3 arguments depends on the variable
  4077. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4078. So for american calendars, give this as MONTH DAY YEAR, for european as
  4079. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4080. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4081. is any number of ISO weeks in the block period for which the item should
  4082. be skipped."
  4083. (let* ((date1 (calendar-absolute-from-gregorian
  4084. (org-order-calendar-date-args m1 d1 y1)))
  4085. (date2 (calendar-absolute-from-gregorian
  4086. (org-order-calendar-date-args m2 d2 y2)))
  4087. (d (calendar-absolute-from-gregorian date)))
  4088. (and
  4089. (<= date1 d)
  4090. (<= d date2)
  4091. (= (calendar-day-of-week date) dayname)
  4092. (or (not skip-weeks)
  4093. (progn
  4094. (require 'cal-iso)
  4095. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4096. entry)))
  4097. (defalias 'org-get-closed 'org-agenda-get-progress)
  4098. (defun org-agenda-get-progress ()
  4099. "Return the logged TODO entries for agenda display."
  4100. (let* ((props (list 'mouse-face 'highlight
  4101. 'org-not-done-regexp org-not-done-regexp
  4102. 'org-todo-regexp org-todo-regexp
  4103. 'org-complex-heading-regexp org-complex-heading-regexp
  4104. 'help-echo
  4105. (format "mouse-2 or RET jump to org file %s"
  4106. (abbreviate-file-name buffer-file-name))))
  4107. (items (if (consp org-agenda-show-log)
  4108. org-agenda-show-log
  4109. org-agenda-log-mode-items))
  4110. (parts
  4111. (delq nil
  4112. (list
  4113. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4114. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4115. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4116. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4117. (error "`org-agenda-log-mode-items' is empty")))
  4118. (regexp (concat
  4119. "\\(" parts-re "\\)"
  4120. " *\\["
  4121. (regexp-quote
  4122. (substring
  4123. (format-time-string
  4124. (car org-time-stamp-formats)
  4125. (apply 'encode-time ; DATE bound by calendar
  4126. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4127. 1 11))))
  4128. (org-agenda-search-headline-for-time nil)
  4129. marker hdmarker priority category tags closedp statep clockp state
  4130. ee txt extra timestr rest clocked)
  4131. (goto-char (point-min))
  4132. (while (re-search-forward regexp nil t)
  4133. (catch :skip
  4134. (org-agenda-skip)
  4135. (setq marker (org-agenda-new-marker (match-beginning 0))
  4136. closedp (equal (match-string 1) org-closed-string)
  4137. statep (equal (string-to-char (match-string 1)) ?-)
  4138. clockp (not (or closedp statep))
  4139. state (and statep (match-string 2))
  4140. category (org-get-category (match-beginning 0))
  4141. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4142. )
  4143. (when (string-match "\\]" timestr)
  4144. ;; substring should only run to end of time stamp
  4145. (setq rest (substring timestr (match-end 0))
  4146. timestr (substring timestr 0 (match-end 0)))
  4147. (if (and (not closedp) (not statep)
  4148. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4149. (progn (setq timestr (concat (substring timestr 0 -1)
  4150. "-" (match-string 1 rest) "]"))
  4151. (setq clocked (match-string 2 rest)))
  4152. (setq clocked "-")))
  4153. (save-excursion
  4154. (cond
  4155. ((not org-agenda-log-mode-add-notes) (setq extra nil))
  4156. (statep
  4157. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4158. (setq extra (match-string 1))))
  4159. (clockp
  4160. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4161. (setq extra (match-string 1))))
  4162. (t (setq extra nil)))
  4163. (if (not (re-search-backward "^\\*+ " nil t))
  4164. (setq txt org-agenda-no-heading-message)
  4165. (goto-char (match-beginning 0))
  4166. (setq hdmarker (org-agenda-new-marker)
  4167. tags (org-get-tags-at))
  4168. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4169. (setq txt (match-string 1))
  4170. (when extra
  4171. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4172. (setq txt (concat (substring txt 0 (match-beginning 1))
  4173. " - " extra " " (match-string 2 txt)))
  4174. (setq txt (concat txt " - " extra))))
  4175. (setq txt (org-format-agenda-item
  4176. (cond
  4177. (closedp "Closed: ")
  4178. (statep (concat "State: (" state ")"))
  4179. (t (concat "Clocked: (" clocked ")")))
  4180. txt category tags timestr)))
  4181. (setq priority 100000)
  4182. (org-add-props txt props
  4183. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4184. 'priority priority 'org-category category
  4185. 'type "closed" 'date date
  4186. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4187. (push txt ee))
  4188. (goto-char (point-at-eol))))
  4189. (nreverse ee)))
  4190. (defun org-agenda-get-deadlines ()
  4191. "Return the deadline information for agenda display."
  4192. (let* ((props (list 'mouse-face 'highlight
  4193. 'org-not-done-regexp org-not-done-regexp
  4194. 'org-todo-regexp org-todo-regexp
  4195. 'org-complex-heading-regexp org-complex-heading-regexp
  4196. 'help-echo
  4197. (format "mouse-2 or RET jump to org file %s"
  4198. (abbreviate-file-name buffer-file-name))))
  4199. (regexp org-deadline-time-regexp)
  4200. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4201. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4202. d2 diff dfrac wdays pos pos1 category tags
  4203. suppress-prewarning
  4204. ee txt head face s todo-state upcomingp donep timestr)
  4205. (goto-char (point-min))
  4206. (while (re-search-forward regexp nil t)
  4207. (setq suppress-prewarning nil)
  4208. (catch :skip
  4209. (org-agenda-skip)
  4210. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4211. (save-match-data
  4212. (string-match org-scheduled-time-regexp
  4213. (buffer-substring (point-at-bol)
  4214. (point-at-eol)))))
  4215. (setq suppress-prewarning
  4216. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4217. org-agenda-skip-deadline-prewarning-if-scheduled
  4218. 0)))
  4219. (setq s (match-string 1)
  4220. txt nil
  4221. pos (1- (match-beginning 1))
  4222. d2 (org-time-string-to-absolute
  4223. (match-string 1) d1 'past
  4224. org-agenda-repeating-timestamp-show-all)
  4225. diff (- d2 d1)
  4226. wdays (if suppress-prewarning
  4227. (let ((org-deadline-warning-days suppress-prewarning))
  4228. (org-get-wdays s))
  4229. (org-get-wdays s))
  4230. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4231. upcomingp (and todayp (> diff 0)))
  4232. ;; When to show a deadline in the calendar:
  4233. ;; If the expiration is within wdays warning time.
  4234. ;; Past-due deadlines are only shown on the current date
  4235. (if (and (or (and (<= diff wdays)
  4236. (and todayp (not org-agenda-only-exact-dates)))
  4237. (= diff 0)))
  4238. (save-excursion
  4239. (setq todo-state (org-get-todo-state))
  4240. (setq donep (member todo-state org-done-keywords))
  4241. (if (and donep
  4242. (or org-agenda-skip-deadline-if-done
  4243. (not (= diff 0))))
  4244. (setq txt nil)
  4245. (setq category (org-get-category))
  4246. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4247. (setq txt org-agenda-no-heading-message)
  4248. (goto-char (match-end 0))
  4249. (setq pos1 (match-beginning 0))
  4250. (setq tags (org-get-tags-at pos1))
  4251. (setq head (buffer-substring-no-properties
  4252. (point)
  4253. (progn (skip-chars-forward "^\r\n")
  4254. (point))))
  4255. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4256. (setq timestr
  4257. (concat (substring s (match-beginning 1)) " "))
  4258. (setq timestr 'time))
  4259. (setq txt (org-format-agenda-item
  4260. (if (= diff 0)
  4261. (car org-agenda-deadline-leaders)
  4262. (if (functionp
  4263. (nth 1 org-agenda-deadline-leaders))
  4264. (funcall
  4265. (nth 1 org-agenda-deadline-leaders)
  4266. diff date)
  4267. (format (nth 1 org-agenda-deadline-leaders)
  4268. diff)))
  4269. head category tags
  4270. (if (not (= diff 0)) nil timestr)))))
  4271. (when txt
  4272. (setq face (org-agenda-deadline-face dfrac wdays))
  4273. (org-add-props txt props
  4274. 'org-marker (org-agenda-new-marker pos)
  4275. 'org-hd-marker (org-agenda-new-marker pos1)
  4276. 'priority (+ (- diff)
  4277. (org-get-priority txt))
  4278. 'org-category category
  4279. 'todo-state todo-state
  4280. 'type (if upcomingp "upcoming-deadline" "deadline")
  4281. 'date (if upcomingp date d2)
  4282. 'face (if donep 'org-agenda-done face)
  4283. 'undone-face face 'done-face 'org-agenda-done)
  4284. (push txt ee))))))
  4285. (nreverse ee)))
  4286. (defun org-agenda-deadline-face (fraction &optional wdays)
  4287. "Return the face to displaying a deadline item.
  4288. FRACTION is what fraction of the head-warning time has passed."
  4289. (if (equal wdays 0) (setq fraction 1.))
  4290. (let ((faces org-agenda-deadline-faces) f)
  4291. (catch 'exit
  4292. (while (setq f (pop faces))
  4293. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4294. (defun org-agenda-get-scheduled (&optional deadline-results)
  4295. "Return the scheduled information for agenda display."
  4296. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4297. 'org-todo-regexp org-todo-regexp
  4298. 'org-complex-heading-regexp org-complex-heading-regexp
  4299. 'done-face 'org-agenda-done
  4300. 'mouse-face 'highlight
  4301. 'help-echo
  4302. (format "mouse-2 or RET jump to org file %s"
  4303. (abbreviate-file-name buffer-file-name))))
  4304. (regexp org-scheduled-time-regexp)
  4305. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4306. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4307. mm
  4308. (deadline-position-alist
  4309. (mapcar (lambda (a) (and (setq mm (get-text-property
  4310. 0 'org-hd-marker a))
  4311. (cons (marker-position mm) a)))
  4312. deadline-results))
  4313. d2 diff pos pos1 category tags donep
  4314. ee txt head pastschedp todo-state face timestr s habitp)
  4315. (goto-char (point-min))
  4316. (while (re-search-forward regexp nil t)
  4317. (catch :skip
  4318. (org-agenda-skip)
  4319. (setq s (match-string 1)
  4320. txt nil
  4321. pos (1- (match-beginning 1))
  4322. d2 (org-time-string-to-absolute
  4323. (match-string 1) d1 'past
  4324. org-agenda-repeating-timestamp-show-all)
  4325. diff (- d2 d1))
  4326. (setq pastschedp (and todayp (< diff 0)))
  4327. ;; When to show a scheduled item in the calendar:
  4328. ;; If it is on or past the date.
  4329. (when (or (and (< diff 0)
  4330. (< (abs diff) org-scheduled-past-days)
  4331. (and todayp (not org-agenda-only-exact-dates)))
  4332. (= diff 0))
  4333. (save-excursion
  4334. (setq todo-state (org-get-todo-state))
  4335. (setq donep (member todo-state org-done-keywords))
  4336. (setq habitp (and (functionp 'org-is-habit-p)
  4337. (org-is-habit-p)))
  4338. (if (and donep
  4339. (or habitp org-agenda-skip-scheduled-if-done
  4340. (not (= diff 0))))
  4341. (setq txt nil)
  4342. (setq category (org-get-category))
  4343. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4344. (setq txt org-agenda-no-heading-message)
  4345. (goto-char (match-end 0))
  4346. (setq pos1 (match-beginning 0))
  4347. (if habitp
  4348. (if (or (not org-habit-show-habits)
  4349. (and (not todayp)
  4350. org-habit-show-habits-only-for-today))
  4351. (throw :skip nil))
  4352. (if (and
  4353. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4354. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4355. pastschedp))
  4356. (setq mm (assoc pos1 deadline-position-alist)))
  4357. (throw :skip nil)))
  4358. (setq tags (org-get-tags-at))
  4359. (setq head (buffer-substring-no-properties
  4360. (point)
  4361. (progn (skip-chars-forward "^\r\n") (point))))
  4362. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4363. (setq timestr
  4364. (concat (substring s (match-beginning 1)) " "))
  4365. (setq timestr 'time))
  4366. (setq txt (org-format-agenda-item
  4367. (if (= diff 0)
  4368. (car org-agenda-scheduled-leaders)
  4369. (format (nth 1 org-agenda-scheduled-leaders)
  4370. (- 1 diff)))
  4371. head category tags
  4372. (if (not (= diff 0)) nil timestr)
  4373. nil nil habitp))))
  4374. (when txt
  4375. (setq face
  4376. (cond
  4377. ((and (not habitp) pastschedp)
  4378. 'org-scheduled-previously)
  4379. (todayp 'org-scheduled-today)
  4380. (t 'org-scheduled))
  4381. habitp (and habitp (org-habit-parse-todo)))
  4382. (org-add-props txt props
  4383. 'undone-face face
  4384. 'face (if donep 'org-agenda-done face)
  4385. 'org-marker (org-agenda-new-marker pos)
  4386. 'org-hd-marker (org-agenda-new-marker pos1)
  4387. 'type (if pastschedp "past-scheduled" "scheduled")
  4388. 'date (if pastschedp d2 date)
  4389. 'priority (if habitp
  4390. (org-habit-get-priority habitp)
  4391. (+ 94 (- 5 diff) (org-get-priority txt)))
  4392. 'org-category category
  4393. 'org-habit-p habitp
  4394. 'todo-state todo-state)
  4395. (push txt ee))))))
  4396. (nreverse ee)))
  4397. (defun org-agenda-get-blocks ()
  4398. "Return the date-range information for agenda display."
  4399. (let* ((props (list 'face nil
  4400. 'org-not-done-regexp org-not-done-regexp
  4401. 'org-todo-regexp org-todo-regexp
  4402. 'org-complex-heading-regexp org-complex-heading-regexp
  4403. 'mouse-face 'highlight
  4404. 'help-echo
  4405. (format "mouse-2 or RET jump to org file %s"
  4406. (abbreviate-file-name buffer-file-name))))
  4407. (regexp org-tr-regexp)
  4408. (d0 (calendar-absolute-from-gregorian date))
  4409. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4410. head donep)
  4411. (goto-char (point-min))
  4412. (while (re-search-forward regexp nil t)
  4413. (catch :skip
  4414. (org-agenda-skip)
  4415. (setq pos (point))
  4416. (setq timestr (match-string 0)
  4417. s1 (match-string 1)
  4418. s2 (match-string 2)
  4419. d1 (time-to-days (org-time-string-to-time s1))
  4420. d2 (time-to-days (org-time-string-to-time s2)))
  4421. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4422. ;; Only allow days between the limits, because the normal
  4423. ;; date stamps will catch the limits.
  4424. (save-excursion
  4425. (setq todo-state (org-get-todo-state))
  4426. (setq donep (member todo-state org-done-keywords))
  4427. (if (and donep org-agenda-skip-timestamp-if-done)
  4428. (throw :skip t))
  4429. (setq marker (org-agenda-new-marker (point)))
  4430. (setq category (org-get-category))
  4431. (if (not (re-search-backward "^\\*+ " nil t))
  4432. (setq txt org-agenda-no-heading-message)
  4433. (goto-char (match-beginning 0))
  4434. (setq hdmarker (org-agenda-new-marker (point)))
  4435. (setq tags (org-get-tags-at))
  4436. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4437. (setq head (match-string 1))
  4438. (setq txt (org-format-agenda-item
  4439. (format
  4440. (nth (if (= d1 d2) 0 1)
  4441. org-agenda-timerange-leaders)
  4442. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4443. head category tags
  4444. timestr)))
  4445. (org-add-props txt props
  4446. 'org-marker marker 'org-hd-marker hdmarker
  4447. 'type "block" 'date date
  4448. 'todo-state todo-state
  4449. 'priority (org-get-priority txt) 'org-category category)
  4450. (push txt ee)))
  4451. (goto-char pos)))
  4452. ;; Sort the entries by expiration date.
  4453. (nreverse ee)))
  4454. ;;; Agenda presentation and sorting
  4455. (defvar org-prefix-has-time nil
  4456. "A flag, set by `org-compile-prefix-format'.
  4457. The flag is set if the currently compiled format contains a `%t'.")
  4458. (defvar org-prefix-has-tag nil
  4459. "A flag, set by `org-compile-prefix-format'.
  4460. The flag is set if the currently compiled format contains a `%T'.")
  4461. (defvar org-prefix-has-effort nil
  4462. "A flag, set by `org-compile-prefix-format'.
  4463. The flag is set if the currently compiled format contains a `%e'.")
  4464. (defvar org-prefix-category-length nil
  4465. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4466. (defvar org-prefix-category-max-length nil
  4467. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4468. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4469. noprefix remove-re habitp)
  4470. "Format TXT to be inserted into the agenda buffer.
  4471. In particular, it adds the prefix and corresponding text properties. EXTRA
  4472. must be a string and replaces the `%s' specifier in the prefix format.
  4473. CATEGORY (string, symbol or nil) may be used to overrule the default
  4474. category taken from local variable or file name. It will replace the `%c'
  4475. specifier in the format. DOTIME, when non-nil, indicates that a
  4476. time-of-day should be extracted from TXT for sorting of this entry, and for
  4477. the `%t' specifier in the format. When DOTIME is a string, this string is
  4478. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4479. only the correctly processes TXT should be returned - this is used by
  4480. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4481. Any match of REMOVE-RE will be removed from TXT."
  4482. (save-match-data
  4483. ;; Diary entries sometimes have extra whitespace at the beginning
  4484. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4485. ;; Fix the tags part in txt
  4486. (setq txt (org-agenda-fix-displayed-tags
  4487. txt tags
  4488. org-agenda-show-inherited-tags
  4489. org-agenda-hide-tags-regexp))
  4490. (let* ((category (or category
  4491. org-category
  4492. (if buffer-file-name
  4493. (file-name-sans-extension
  4494. (file-name-nondirectory buffer-file-name))
  4495. "")))
  4496. ;; time, tag, effort are needed for the eval of the prefix format
  4497. (tag (if tags (nth (1- (length tags)) tags) ""))
  4498. time effort neffort
  4499. (ts (if dotime (concat
  4500. (if (stringp dotime) dotime "")
  4501. (and org-agenda-search-headline-for-time txt))))
  4502. (time-of-day (and dotime (org-get-time-of-day ts)))
  4503. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4504. duration thecategory)
  4505. (and (org-mode-p) buffer-file-name
  4506. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4507. (when (and dotime time-of-day)
  4508. ;; Extract starting and ending time and move them to prefix
  4509. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4510. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4511. (setq s0 (match-string 0 ts)
  4512. srp (and stamp (match-end 3))
  4513. s1 (match-string (if plain 1 2) ts)
  4514. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4515. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4516. ;; them, we might want to remove them there to avoid duplication.
  4517. ;; The user can turn this off with a variable.
  4518. (if (and org-prefix-has-time
  4519. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4520. (string-match (concat (regexp-quote s0) " *") txt)
  4521. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4522. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4523. (= (match-beginning 0) 0)
  4524. t))
  4525. (setq txt (replace-match "" nil nil txt))))
  4526. ;; Normalize the time(s) to 24 hour
  4527. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4528. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4529. ;; Compute the duration
  4530. (when s1
  4531. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4532. (string-to-number (substring s1 3)))
  4533. t2 (cond
  4534. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4535. (string-to-number (substring s2 3))))
  4536. (org-agenda-default-appointment-duration
  4537. (+ t1 org-agenda-default-appointment-duration))
  4538. (t nil)))
  4539. (setq duration (if t2 (- t2 t1)))))
  4540. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4541. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4542. (let ((m (+ (string-to-number (match-string 2 s1))
  4543. (* 60 (string-to-number (match-string 1 s1)))
  4544. org-agenda-default-appointment-duration))
  4545. h)
  4546. (setq h (/ m 60) m (- m (* h 60)))
  4547. (setq s2 (format "%02d:%02d" h m))))
  4548. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4549. txt)
  4550. ;; Tags are in the string
  4551. (if (or (eq org-agenda-remove-tags t)
  4552. (and org-agenda-remove-tags
  4553. org-prefix-has-tag))
  4554. (setq txt (replace-match "" t t txt))
  4555. (setq txt (replace-match
  4556. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4557. (match-string 2 txt))
  4558. t t txt))))
  4559. (when (org-mode-p)
  4560. (setq effort
  4561. (condition-case nil
  4562. (org-get-effort
  4563. (or (get-text-property 0 'org-hd-marker txt)
  4564. (get-text-property 0 'org-marker txt)))
  4565. (error nil)))
  4566. (when effort
  4567. (setq neffort (org-hh:mm-string-to-minutes effort)
  4568. effort (setq effort (concat "[" effort "]" )))))
  4569. (when remove-re
  4570. (while (string-match remove-re txt)
  4571. (setq txt (replace-match "" t t txt))))
  4572. ;; Create the final string
  4573. (if noprefix
  4574. (setq rtn txt)
  4575. ;; Prepare the variables needed in the eval of the compiled format
  4576. (setq time (cond (s2 (concat s1 "-" s2))
  4577. (s1 (concat s1 "......"))
  4578. (t ""))
  4579. extra (or (and (not habitp) extra) "")
  4580. category (if (symbolp category) (symbol-name category) category)
  4581. thecategory (copy-sequence category))
  4582. (if (string-match org-bracket-link-regexp category)
  4583. (progn
  4584. (setq l (if (match-end 3)
  4585. (- (match-end 3) (match-beginning 3))
  4586. (- (match-end 1) (match-beginning 1))))
  4587. (when (< l (or org-prefix-category-length 0))
  4588. (setq category (copy-sequence category))
  4589. (org-add-props category nil
  4590. 'extra-space (make-string
  4591. (- org-prefix-category-length l 1) ?\ ))))
  4592. (if (and org-prefix-category-max-length
  4593. (>= (length category) org-prefix-category-max-length))
  4594. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4595. ;; Evaluate the compiled format
  4596. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4597. ;; And finally add the text properties
  4598. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4599. (org-add-props rtn nil
  4600. 'org-category (if thecategory (downcase thecategory) category)
  4601. 'tags (mapcar 'org-downcase-keep-props tags)
  4602. 'org-highest-priority org-highest-priority
  4603. 'org-lowest-priority org-lowest-priority
  4604. 'prefix-length (- (length rtn) (length txt))
  4605. 'time-of-day time-of-day
  4606. 'duration duration
  4607. 'effort effort
  4608. 'effort-minutes neffort
  4609. 'txt txt
  4610. 'time time
  4611. 'extra extra
  4612. 'dotime dotime))))
  4613. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4614. "Remove tags string from TXT, and add a modified list of tags.
  4615. The modified list may contain inherited tags, and tags matched by
  4616. `org-agenda-hide-tags-regexp' will be removed."
  4617. (when (or add-inherited hide-re)
  4618. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4619. (setq txt (substring txt 0 (match-beginning 0))))
  4620. (setq tags
  4621. (delq nil
  4622. (mapcar (lambda (tg)
  4623. (if (or (and hide-re (string-match hide-re tg))
  4624. (and (not add-inherited)
  4625. (get-text-property 0 'inherited tg)))
  4626. nil
  4627. tg))
  4628. tags)))
  4629. (when tags
  4630. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4631. i)
  4632. (setq txt (concat txt " :"
  4633. (mapconcat
  4634. (lambda (x)
  4635. (setq i (get-text-property 0 'inherited x))
  4636. (if (and have-i (not i))
  4637. (progn
  4638. (setq have-i nil)
  4639. (concat ":" x))
  4640. x))
  4641. tags ":")
  4642. (if have-i "::" ":"))))))
  4643. txt)
  4644. (defun org-downcase-keep-props (s)
  4645. (let ((props (text-properties-at 0 s)))
  4646. (setq s (downcase s))
  4647. (add-text-properties 0 (length s) props s)
  4648. s))
  4649. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4650. (defvar org-agenda-sorting-strategy-selected nil)
  4651. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4652. (catch 'exit
  4653. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4654. ((and todayp (member 'today (car org-agenda-time-grid))))
  4655. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4656. ((member 'weekly (car org-agenda-time-grid)))
  4657. (t (throw 'exit list)))
  4658. (let* ((have (delq nil (mapcar
  4659. (lambda (x) (get-text-property 1 'time-of-day x))
  4660. list)))
  4661. (string (nth 1 org-agenda-time-grid))
  4662. (gridtimes (nth 2 org-agenda-time-grid))
  4663. (req (car org-agenda-time-grid))
  4664. (remove (member 'remove-match req))
  4665. new time)
  4666. (if (and (member 'require-timed req) (not have))
  4667. ;; don't show empty grid
  4668. (throw 'exit list))
  4669. (while (setq time (pop gridtimes))
  4670. (unless (and remove (member time have))
  4671. (setq time (int-to-string time))
  4672. (push (org-format-agenda-item
  4673. nil string "" nil
  4674. (concat (substring time 0 -2) ":" (substring time -2)))
  4675. new)
  4676. (put-text-property
  4677. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4678. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4679. (append new list)
  4680. (append list new)))))
  4681. (defun org-compile-prefix-format (key)
  4682. "Compile the prefix format into a Lisp form that can be evaluated.
  4683. The resulting form is returned and stored in the variable
  4684. `org-prefix-format-compiled'."
  4685. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4686. org-prefix-category-length nil org-prefix-has-effort nil)
  4687. (let ((s (cond
  4688. ((stringp org-agenda-prefix-format)
  4689. org-agenda-prefix-format)
  4690. ((assq key org-agenda-prefix-format)
  4691. (cdr (assq key org-agenda-prefix-format)))
  4692. (t " %-12:c%?-12t% s")))
  4693. (start 0)
  4694. varform vars var e c f opt)
  4695. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4696. s start)
  4697. (setq var (cdr (assoc (match-string 4 s)
  4698. '(("c" . category) ("t" . time) ("s" . extra)
  4699. ("T" . tag) ("e" . effort))))
  4700. c (or (match-string 3 s) "")
  4701. opt (match-beginning 1)
  4702. start (1+ (match-beginning 0)))
  4703. (if (equal var 'time) (setq org-prefix-has-time t))
  4704. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4705. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4706. (setq f (concat "%" (match-string 2 s) "s"))
  4707. (when (equal var 'category)
  4708. (setq org-prefix-category-length
  4709. (floor (abs (string-to-number (match-string 2 s)))))
  4710. (setq org-prefix-category-max-length
  4711. (let ((x (match-string 2 s)))
  4712. (save-match-data
  4713. (if (string-match "\\.[0-9]+" x)
  4714. (string-to-number (substring (match-string 0 x) 1)))))))
  4715. (if opt
  4716. (setq varform
  4717. `(if (equal "" ,var)
  4718. ""
  4719. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4720. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4721. (setq s (replace-match "%s" t nil s))
  4722. (push varform vars))
  4723. (setq vars (nreverse vars))
  4724. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4725. (defun org-set-sorting-strategy (key)
  4726. (if (symbolp (car org-agenda-sorting-strategy))
  4727. ;; the old format
  4728. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4729. (setq org-agenda-sorting-strategy-selected
  4730. (or (cdr (assq key org-agenda-sorting-strategy))
  4731. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4732. '(time-up category-keep priority-down)))))
  4733. (defun org-get-time-of-day (s &optional string mod24)
  4734. "Check string S for a time of day.
  4735. If found, return it as a military time number between 0 and 2400.
  4736. If not found, return nil.
  4737. The optional STRING argument forces conversion into a 5 character wide string
  4738. HH:MM."
  4739. (save-match-data
  4740. (when
  4741. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4742. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4743. (let* ((h (string-to-number (match-string 1 s)))
  4744. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4745. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4746. (am-p (equal ampm "am"))
  4747. (h1 (cond ((not ampm) h)
  4748. ((= h 12) (if am-p 0 12))
  4749. (t (+ h (if am-p 0 12)))))
  4750. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4751. (mod h1 24) h1))
  4752. (t0 (+ (* 100 h2) m))
  4753. (t1 (concat (if (>= h1 24) "+" " ")
  4754. (if (and org-agenda-time-leading-zero
  4755. (< t0 1000)) "0" "")
  4756. (if (< t0 100) "0" "")
  4757. (if (< t0 10) "0" "")
  4758. (int-to-string t0))))
  4759. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4760. (defun org-finalize-agenda-entries (list &optional nosort)
  4761. "Sort and concatenate the agenda items."
  4762. (setq list (mapcar 'org-agenda-highlight-todo list))
  4763. (if nosort
  4764. list
  4765. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4766. (defun org-agenda-highlight-todo (x)
  4767. (let ((org-done-keywords org-done-keywords-for-agenda)
  4768. (case-fold-search nil)
  4769. re pl)
  4770. (if (eq x 'line)
  4771. (save-excursion
  4772. (beginning-of-line 1)
  4773. (setq re (org-get-at-bol 'org-todo-regexp))
  4774. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4775. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4776. (add-text-properties (match-beginning 0) (match-end 1)
  4777. (list 'face (org-get-todo-face 1)))
  4778. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4779. (delete-region (match-beginning 1) (1- (match-end 0)))
  4780. (goto-char (match-beginning 1))
  4781. (insert (format org-agenda-todo-keyword-format s)))))
  4782. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4783. pl (get-text-property 0 'prefix-length x))
  4784. (when (and re
  4785. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4786. x (or pl 0)) pl))
  4787. (add-text-properties
  4788. (or (match-end 1) (match-end 0)) (match-end 0)
  4789. (list 'face (org-get-todo-face (match-string 2 x)))
  4790. x)
  4791. (setq x (concat (substring x 0 (match-end 1))
  4792. (format org-agenda-todo-keyword-format
  4793. (match-string 2 x))
  4794. (org-add-props " " (text-properties-at 0 x))
  4795. (substring x (match-end 3)))))
  4796. x)))
  4797. (defsubst org-cmp-priority (a b)
  4798. "Compare the priorities of string A and B."
  4799. (let ((pa (or (get-text-property 1 'priority a) 0))
  4800. (pb (or (get-text-property 1 'priority b) 0)))
  4801. (cond ((> pa pb) +1)
  4802. ((< pa pb) -1)
  4803. (t nil))))
  4804. (defsubst org-cmp-effort (a b)
  4805. "Compare the priorities of string A and B."
  4806. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4807. (ea (or (get-text-property 1 'effort-minutes a) def))
  4808. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4809. (cond ((> ea eb) +1)
  4810. ((< ea eb) -1)
  4811. (t nil))))
  4812. (defsubst org-cmp-category (a b)
  4813. "Compare the string values of categories of strings A and B."
  4814. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4815. (cb (or (get-text-property 1 'org-category b) "")))
  4816. (cond ((string-lessp ca cb) -1)
  4817. ((string-lessp cb ca) +1)
  4818. (t nil))))
  4819. (defsubst org-cmp-todo-state (a b)
  4820. "Compare the todo states of strings A and B."
  4821. (let* ((ma (or (get-text-property 1 'org-marker a)
  4822. (get-text-property 1 'org-hd-marker a)))
  4823. (mb (or (get-text-property 1 'org-marker b)
  4824. (get-text-property 1 'org-hd-marker b)))
  4825. (fa (and ma (marker-buffer ma)))
  4826. (fb (and mb (marker-buffer mb)))
  4827. (todo-kwds
  4828. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4829. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4830. (ta (or (get-text-property 1 'todo-state a) ""))
  4831. (tb (or (get-text-property 1 'todo-state b) ""))
  4832. (la (- (length (member ta todo-kwds))))
  4833. (lb (- (length (member tb todo-kwds))))
  4834. (donepa (member ta org-done-keywords-for-agenda))
  4835. (donepb (member tb org-done-keywords-for-agenda)))
  4836. (cond ((and donepa (not donepb)) -1)
  4837. ((and (not donepa) donepb) +1)
  4838. ((< la lb) -1)
  4839. ((< lb la) +1)
  4840. (t nil))))
  4841. (defsubst org-cmp-tag (a b)
  4842. "Compare the string values of the first tags of A and B."
  4843. (let ((ta (car (last (get-text-property 1 'tags a))))
  4844. (tb (car (last (get-text-property 1 'tags b)))))
  4845. (cond ((not ta) +1)
  4846. ((not tb) -1)
  4847. ((string-lessp ta tb) -1)
  4848. ((string-lessp tb ta) +1)
  4849. (t nil))))
  4850. (defsubst org-cmp-time (a b)
  4851. "Compare the time-of-day values of strings A and B."
  4852. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4853. (ta (or (get-text-property 1 'time-of-day a) def))
  4854. (tb (or (get-text-property 1 'time-of-day b) def)))
  4855. (cond ((< ta tb) -1)
  4856. ((< tb ta) +1)
  4857. (t nil))))
  4858. (defsubst org-cmp-habit-p (a b)
  4859. "Compare the todo states of strings A and B."
  4860. (let ((ha (get-text-property 1 'org-habit-p a))
  4861. (hb (get-text-property 1 'org-habit-p b)))
  4862. (cond ((and ha (not hb)) -1)
  4863. ((and (not ha) hb) +1)
  4864. (t nil))))
  4865. (defun org-entries-lessp (a b)
  4866. "Predicate for sorting agenda entries."
  4867. ;; The following variables will be used when the form is evaluated.
  4868. ;; So even though the compiler complains, keep them.
  4869. (let* ((time-up (org-cmp-time a b))
  4870. (time-down (if time-up (- time-up) nil))
  4871. (priority-up (org-cmp-priority a b))
  4872. (priority-down (if priority-up (- priority-up) nil))
  4873. (effort-up (org-cmp-effort a b))
  4874. (effort-down (if effort-up (- effort-up) nil))
  4875. (category-up (org-cmp-category a b))
  4876. (category-down (if category-up (- category-up) nil))
  4877. (category-keep (if category-up +1 nil))
  4878. (tag-up (org-cmp-tag a b))
  4879. (tag-down (if tag-up (- tag-up) nil))
  4880. (todo-state-up (org-cmp-todo-state a b))
  4881. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4882. (habit-up (org-cmp-habit-p a b))
  4883. (habit-down (if habit-up (- habit-up) nil))
  4884. user-defined-up user-defined-down)
  4885. (if (and org-agenda-cmp-user-defined
  4886. (functionp org-agenda-cmp-user-defined))
  4887. (setq user-defined-up
  4888. (funcall org-agenda-cmp-user-defined a b)
  4889. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  4890. (cdr (assoc
  4891. (eval (cons 'or org-agenda-sorting-strategy-selected))
  4892. '((-1 . t) (1 . nil) (nil . nil))))))
  4893. ;;; Agenda restriction lock
  4894. (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
  4895. "Overlay to mark the headline to which agenda commands are restricted.")
  4896. (org-overlay-put org-agenda-restriction-lock-overlay
  4897. 'face 'org-agenda-restriction-lock)
  4898. (org-overlay-put org-agenda-restriction-lock-overlay
  4899. 'help-echo "Agendas are currently limited to this subtree.")
  4900. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4901. (defun org-agenda-set-restriction-lock (&optional type)
  4902. "Set restriction lock for agenda, to current subtree or file.
  4903. Restriction will be the file if TYPE is `file', or if type is the
  4904. universal prefix '(4), or if the cursor is before the first headline
  4905. in the file. Otherwise, restriction will be to the current subtree."
  4906. (interactive "P")
  4907. (and (equal type '(4)) (setq type 'file))
  4908. (setq type (cond
  4909. (type type)
  4910. ((org-at-heading-p) 'subtree)
  4911. ((condition-case nil (org-back-to-heading t) (error nil))
  4912. 'subtree)
  4913. (t 'file)))
  4914. (if (eq type 'subtree)
  4915. (progn
  4916. (setq org-agenda-restrict t)
  4917. (setq org-agenda-overriding-restriction 'subtree)
  4918. (put 'org-agenda-files 'org-restrict
  4919. (list (buffer-file-name (buffer-base-buffer))))
  4920. (org-back-to-heading t)
  4921. (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  4922. (move-marker org-agenda-restrict-begin (point))
  4923. (move-marker org-agenda-restrict-end
  4924. (save-excursion (org-end-of-subtree t)))
  4925. (message "Locking agenda restriction to subtree"))
  4926. (put 'org-agenda-files 'org-restrict
  4927. (list (buffer-file-name (buffer-base-buffer))))
  4928. (setq org-agenda-restrict nil)
  4929. (setq org-agenda-overriding-restriction 'file)
  4930. (move-marker org-agenda-restrict-begin nil)
  4931. (move-marker org-agenda-restrict-end nil)
  4932. (message "Locking agenda restriction to file"))
  4933. (setq current-prefix-arg nil)
  4934. (org-agenda-maybe-redo))
  4935. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  4936. "Remove the agenda restriction lock."
  4937. (interactive "P")
  4938. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4939. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  4940. (setq org-agenda-overriding-restriction nil)
  4941. (setq org-agenda-restrict nil)
  4942. (put 'org-agenda-files 'org-restrict nil)
  4943. (move-marker org-agenda-restrict-begin nil)
  4944. (move-marker org-agenda-restrict-end nil)
  4945. (setq current-prefix-arg nil)
  4946. (message "Agenda restriction lock removed")
  4947. (or noupdate (org-agenda-maybe-redo)))
  4948. (defun org-agenda-maybe-redo ()
  4949. "If there is any window showing the agenda view, update it."
  4950. (let ((w (get-buffer-window org-agenda-buffer-name t))
  4951. (w0 (selected-window)))
  4952. (when w
  4953. (select-window w)
  4954. (org-agenda-redo)
  4955. (select-window w0)
  4956. (if org-agenda-overriding-restriction
  4957. (message "Agenda view shifted to new %s restriction"
  4958. org-agenda-overriding-restriction)
  4959. (message "Agenda restriction lock removed")))))
  4960. ;;; Agenda commands
  4961. (defun org-agenda-check-type (error &rest types)
  4962. "Check if agenda buffer is of allowed type.
  4963. If ERROR is non-nil, throw an error, otherwise just return nil."
  4964. (if (memq org-agenda-type types)
  4965. t
  4966. (if error
  4967. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  4968. nil)))
  4969. (defun org-agenda-quit ()
  4970. "Exit agenda by removing the window or the buffer."
  4971. (interactive)
  4972. (if org-agenda-columns-active
  4973. (org-columns-quit)
  4974. (let ((buf (current-buffer)))
  4975. (if (eq org-agenda-window-setup 'other-frame)
  4976. (progn
  4977. (kill-buffer buf)
  4978. (org-agenda-reset-markers)
  4979. (org-columns-remove-overlays)
  4980. (setq org-agenda-archives-mode nil)
  4981. (delete-frame))
  4982. (and (not (eq org-agenda-window-setup 'current-window))
  4983. (not (one-window-p))
  4984. (delete-window))
  4985. (kill-buffer buf)
  4986. (org-agenda-reset-markers)
  4987. (org-columns-remove-overlays)
  4988. (setq org-agenda-archives-mode nil)))
  4989. ;; Maybe restore the pre-agenda window configuration.
  4990. (and org-agenda-restore-windows-after-quit
  4991. (not (eq org-agenda-window-setup 'other-frame))
  4992. org-pre-agenda-window-conf
  4993. (set-window-configuration org-pre-agenda-window-conf))))
  4994. (defun org-agenda-exit ()
  4995. "Exit agenda by removing the window or the buffer.
  4996. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  4997. Org-mode buffers visited directly by the user will not be touched."
  4998. (interactive)
  4999. (org-release-buffers org-agenda-new-buffers)
  5000. (setq org-agenda-new-buffers nil)
  5001. (org-agenda-quit))
  5002. (defun org-agenda-execute (arg)
  5003. "Execute another agenda command, keeping same window.\\<global-map>
  5004. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  5005. (interactive "P")
  5006. (let ((org-agenda-window-setup 'current-window))
  5007. (org-agenda arg)))
  5008. (defun org-agenda-redo ()
  5009. "Rebuild Agenda.
  5010. When this is the global TODO list, a prefix argument will be interpreted."
  5011. (interactive)
  5012. (let* ((org-agenda-keep-modes t)
  5013. (filter org-agenda-filter)
  5014. (preset (get 'org-agenda-filter :preset-filter))
  5015. (cols org-agenda-columns-active)
  5016. (line (org-current-line))
  5017. (window-line (- line (org-current-line (window-start))))
  5018. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5019. (put 'org-agenda-filter :preset-filter nil)
  5020. (and cols (org-columns-quit))
  5021. (message "Rebuilding agenda buffer...")
  5022. (org-let lprops '(eval org-agenda-redo-command))
  5023. (setq org-agenda-undo-list nil
  5024. org-agenda-pending-undo-list nil)
  5025. (message "Rebuilding agenda buffer...done")
  5026. (put 'org-agenda-filter :preset-filter preset)
  5027. (and (or filter preset) (org-agenda-filter-apply filter))
  5028. (and cols (interactive-p) (org-agenda-columns))
  5029. (org-goto-line line)
  5030. (recenter window-line)))
  5031. (defvar org-global-tags-completion-table nil)
  5032. (defvar org-agenda-filter-form nil)
  5033. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5034. "Keep only those lines in the agenda buffer that have a specific tag.
  5035. The tag is selected with its fast selection letter, as configured.
  5036. With prefix argument STRIP, remove all lines that do have the tag.
  5037. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5038. used to narrow the search - the interactive user can also press `-' or `+'
  5039. to switch to narrowing."
  5040. (interactive "P")
  5041. (let* ((alist org-tag-alist-for-agenda)
  5042. (tag-chars (mapconcat
  5043. (lambda (x) (if (and (not (symbolp (car x)))
  5044. (cdr x))
  5045. (char-to-string (cdr x))
  5046. ""))
  5047. alist ""))
  5048. (efforts (org-split-string
  5049. (or (cdr (assoc (concat org-effort-property "_ALL")
  5050. org-global-properties))
  5051. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5052. (effort-op org-agenda-filter-effort-default-operator)
  5053. (effort-prompt "")
  5054. (inhibit-read-only t)
  5055. (current org-agenda-filter)
  5056. a n tag)
  5057. (unless char
  5058. (message
  5059. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5060. (if narrow "Narrow" "Filter") tag-chars
  5061. (if org-agenda-auto-exclude-function "[RET], " ""))
  5062. (setq char (read-char)))
  5063. (when (member char '(?+ ?-))
  5064. ;; Narrowing down
  5065. (cond ((equal char ?-) (setq strip t narrow t))
  5066. ((equal char ?+) (setq strip nil narrow t)))
  5067. (message
  5068. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5069. (setq char (read-char)))
  5070. (when (member char '(?< ?> ?= ??))
  5071. ;; An effort operator
  5072. (setq effort-op (char-to-string char))
  5073. (setq alist nil) ; to make sure it will be interpreted as effort.
  5074. (unless (equal char ??)
  5075. (loop for i from 0 to 9 do
  5076. (setq effort-prompt
  5077. (concat
  5078. effort-prompt " ["
  5079. (if (= i 9) "0" (int-to-string (1+ i)))
  5080. "]" (nth i efforts))))
  5081. (message "Effort%s: %s " effort-op effort-prompt)
  5082. (setq char (read-char))
  5083. (when (or (< char ?0) (> char ?9))
  5084. (error "Need 1-9,0 to select effort" ))))
  5085. (when (equal char ?\t)
  5086. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5087. (org-set-local 'org-global-tags-completion-table
  5088. (org-global-tags-completion-table)))
  5089. (let ((completion-ignore-case t))
  5090. (setq tag (org-icompleting-read
  5091. "Tag: " org-global-tags-completion-table))))
  5092. (cond
  5093. ((equal char ?\r)
  5094. (org-agenda-filter-by-tag-show-all)
  5095. (when org-agenda-auto-exclude-function
  5096. (setq org-agenda-filter '())
  5097. (dolist (tag (org-agenda-get-represented-tags))
  5098. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5099. (if modifier
  5100. (push modifier org-agenda-filter))))
  5101. (if (not (null org-agenda-filter))
  5102. (org-agenda-filter-apply org-agenda-filter))))
  5103. ((equal char ?/)
  5104. (org-agenda-filter-by-tag-show-all)
  5105. (when (get 'org-agenda-filter :preset-filter)
  5106. (org-agenda-filter-apply org-agenda-filter)))
  5107. ((or (equal char ?\ )
  5108. (setq a (rassoc char alist))
  5109. (and (>= char ?0) (<= char ?9)
  5110. (setq n (if (= char ?0) 9 (- char ?0 1))
  5111. tag (concat effort-op (nth n efforts))
  5112. a (cons tag nil)))
  5113. (and (= char ??)
  5114. (setq tag "?eff")
  5115. a (cons tag nil))
  5116. (and tag (setq a (cons tag nil))))
  5117. (org-agenda-filter-by-tag-show-all)
  5118. (setq tag (car a))
  5119. (setq org-agenda-filter
  5120. (cons (concat (if strip "-" "+") tag)
  5121. (if narrow current nil)))
  5122. (org-agenda-filter-apply org-agenda-filter))
  5123. (t (error "Invalid tag selection character %c" char)))))
  5124. (defun org-agenda-get-represented-tags ()
  5125. "Get a list of all tags currently represented in the agenda."
  5126. (let (p tags)
  5127. (save-excursion
  5128. (goto-char (point-min))
  5129. (while (setq p (next-single-property-change (point) 'tags))
  5130. (goto-char p)
  5131. (mapc (lambda (x) (add-to-list 'tags x))
  5132. (get-text-property (point) 'tags))))
  5133. tags))
  5134. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5135. "Refine the current filter. See `org-agenda-filter-by-tag."
  5136. (interactive "P")
  5137. (org-agenda-filter-by-tag strip char 'refine))
  5138. (defun org-agenda-filter-make-matcher ()
  5139. "Create the form that tests a line for the agenda filter."
  5140. (let (f f1)
  5141. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5142. org-agenda-filter))
  5143. (if (member x '("-" "+"))
  5144. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5145. (if (string-match "[<=>?]" x)
  5146. (setq f1 (org-agenda-filter-effort-form x))
  5147. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5148. (if (equal (string-to-char x) ?-)
  5149. (setq f1 (list 'not f1))))
  5150. (push f1 f))
  5151. (cons 'and (nreverse f))))
  5152. (defun org-agenda-filter-effort-form (e)
  5153. "Return the form to compare the effort of the current line with what E says.
  5154. E looks line \"+<2:25\"."
  5155. (let (op)
  5156. (setq e (substring e 1))
  5157. (setq op (string-to-char e) e (substring e 1))
  5158. (setq op (cond ((equal op ?<) '<=)
  5159. ((equal op ?>) '>=)
  5160. ((equal op ??) op)
  5161. (t '=)))
  5162. (list 'org-agenda-compare-effort (list 'quote op)
  5163. (org-hh:mm-string-to-minutes e))))
  5164. (defun org-agenda-compare-effort (op value)
  5165. "Compare the effort of the current line with VALUE, using OP.
  5166. If the line does not have an effort defined, return nil."
  5167. (let ((eff (org-get-at-bol 'effort-minutes)))
  5168. (if (equal op ??)
  5169. (not eff)
  5170. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5171. value))))
  5172. (defun org-agenda-filter-apply (filter)
  5173. "Set FILTER as the new agenda filter and apply it."
  5174. (let (tags)
  5175. (setq org-agenda-filter filter
  5176. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5177. (org-agenda-set-mode-name)
  5178. (save-excursion
  5179. (goto-char (point-min))
  5180. (while (not (eobp))
  5181. (if (org-get-at-bol 'org-marker)
  5182. (progn
  5183. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5184. (if (not (eval org-agenda-filter-form))
  5185. (org-agenda-filter-by-tag-hide-line))
  5186. (beginning-of-line 2))
  5187. (beginning-of-line 2))))))
  5188. (defun org-agenda-filter-by-tag-hide-line ()
  5189. (let (ov)
  5190. (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
  5191. (point-at-eol)))
  5192. (org-overlay-put ov 'invisible t)
  5193. (org-overlay-put ov 'type 'tags-filter)
  5194. (push ov org-agenda-filter-overlays)))
  5195. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5196. (setq pos (or pos (point)))
  5197. (save-excursion
  5198. (dolist (ov (org-overlays-at pos))
  5199. (when (and (org-overlay-get ov 'invisible)
  5200. (eq (org-overlay-get ov 'type) 'tags-filter))
  5201. (goto-char pos)
  5202. (if (< (org-overlay-start ov) (point-at-eol))
  5203. (org-move-overlay ov (point-at-eol)
  5204. (org-overlay-end ov)))))))
  5205. (defun org-agenda-filter-by-tag-show-all ()
  5206. (mapc 'org-delete-overlay org-agenda-filter-overlays)
  5207. (setq org-agenda-filter-overlays nil)
  5208. (setq org-agenda-filter nil)
  5209. (setq org-agenda-filter-form nil)
  5210. (org-agenda-set-mode-name))
  5211. (defun org-agenda-manipulate-query-add ()
  5212. "Manipulate the query by adding a search term with positive selection.
  5213. Positive selection means the term must be matched for selection of an entry."
  5214. (interactive)
  5215. (org-agenda-manipulate-query ?\[))
  5216. (defun org-agenda-manipulate-query-subtract ()
  5217. "Manipulate the query by adding a search term with negative selection.
  5218. Negative selection means term must not be matched for selection of an entry."
  5219. (interactive)
  5220. (org-agenda-manipulate-query ?\]))
  5221. (defun org-agenda-manipulate-query-add-re ()
  5222. "Manipulate the query by adding a search regexp with positive selection.
  5223. Positive selection means the regexp must match for selection of an entry."
  5224. (interactive)
  5225. (org-agenda-manipulate-query ?\{))
  5226. (defun org-agenda-manipulate-query-subtract-re ()
  5227. "Manipulate the query by adding a search regexp with negative selection.
  5228. Negative selection means regexp must not match for selection of an entry."
  5229. (interactive)
  5230. (org-agenda-manipulate-query ?\}))
  5231. (defun org-agenda-manipulate-query (char)
  5232. (cond
  5233. ((memq org-agenda-type '(timeline agenda))
  5234. (let ((org-agenda-include-inactive-timestamps t))
  5235. (org-agenda-redo))
  5236. (message "Display now includes inactive timestamps as well"))
  5237. ((eq org-agenda-type 'search)
  5238. (org-add-to-string
  5239. 'org-agenda-query-string
  5240. (if org-agenda-last-search-view-search-was-boolean
  5241. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5242. (?\{ . " +{}") (?\} . " -{}"))))
  5243. " "))
  5244. (setq org-agenda-redo-command
  5245. (list 'org-search-view
  5246. org-todo-only
  5247. org-agenda-query-string
  5248. (+ (length org-agenda-query-string)
  5249. (if (member char '(?\{ ?\})) 0 1))))
  5250. (set-register org-agenda-query-register org-agenda-query-string)
  5251. (org-agenda-redo))
  5252. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5253. org-agenda-type))))
  5254. (defun org-add-to-string (var string)
  5255. (set var (concat (symbol-value var) string)))
  5256. (defun org-agenda-goto-date (date)
  5257. "Jump to DATE in agenda."
  5258. (interactive (list (org-read-date)))
  5259. (org-agenda-list nil date))
  5260. (defun org-agenda-goto-today ()
  5261. "Go to today."
  5262. (interactive)
  5263. (org-agenda-check-type t 'timeline 'agenda)
  5264. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5265. (cond
  5266. (tdpos (goto-char tdpos))
  5267. ((eq org-agenda-type 'agenda)
  5268. (let* ((sd (time-to-days
  5269. (time-subtract (current-time)
  5270. (list 0 (* 3600 org-extend-today-until) 0))))
  5271. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5272. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5273. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5274. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5275. (org-agenda-redo)
  5276. (org-agenda-find-same-or-today-or-agenda)))
  5277. (t (error "Cannot find today")))))
  5278. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5279. (goto-char
  5280. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5281. (text-property-any (point-min) (point-max) 'org-today t)
  5282. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5283. (point-min))))
  5284. (defun org-agenda-later (arg)
  5285. "Go forward in time by thee current span.
  5286. With prefix ARG, go forward that many times the current span."
  5287. (interactive "p")
  5288. (org-agenda-check-type t 'agenda)
  5289. (let* ((span org-agenda-span)
  5290. (sd org-starting-day)
  5291. (greg (calendar-gregorian-from-absolute sd))
  5292. (cnt (org-get-at-bol 'org-day-cnt))
  5293. greg2 nd)
  5294. (cond
  5295. ((eq span 'day)
  5296. (setq sd (+ arg sd) nd 1))
  5297. ((eq span 'week)
  5298. (setq sd (+ (* 7 arg) sd) nd 7))
  5299. ((eq span 'month)
  5300. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5301. sd (calendar-absolute-from-gregorian greg2))
  5302. (setcar greg2 (1+ (car greg2)))
  5303. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5304. ((eq span 'year)
  5305. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5306. sd (calendar-absolute-from-gregorian greg2))
  5307. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5308. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5309. (let ((org-agenda-overriding-arguments
  5310. (list (car org-agenda-last-arguments) sd nd t)))
  5311. (org-agenda-redo)
  5312. (org-agenda-find-same-or-today-or-agenda cnt))))
  5313. (defun org-agenda-earlier (arg)
  5314. "Go backward in time by the current span.
  5315. With prefix ARG, go backward that many times the current span."
  5316. (interactive "p")
  5317. (org-agenda-later (- arg)))
  5318. (defun org-agenda-view-mode-dispatch ()
  5319. "Call one of the view mode commands."
  5320. (interactive)
  5321. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5322. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5323. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5324. (let ((a (read-char-exclusive)))
  5325. (case a
  5326. (?d (call-interactively 'org-agenda-day-view))
  5327. (?w (call-interactively 'org-agenda-week-view))
  5328. (?m (call-interactively 'org-agenda-month-view))
  5329. (?y (call-interactively 'org-agenda-year-view))
  5330. (?l (call-interactively 'org-agenda-log-mode))
  5331. (?L (org-agenda-log-mode '(4)))
  5332. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5333. (?a (call-interactively 'org-agenda-archives-mode))
  5334. (?A (org-agenda-archives-mode 'files))
  5335. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5336. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5337. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5338. (?D (call-interactively 'org-agenda-toggle-diary))
  5339. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5340. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5341. (org-agenda-check-type t 'timeline 'agenda)
  5342. (org-agenda-redo))
  5343. (message "Display now includes inactive timestamps as well"))
  5344. (?q (message "Abort"))
  5345. (otherwise (error "Invalid key" )))))
  5346. (defun org-agenda-day-view (&optional day-of-year)
  5347. "Switch to daily view for agenda.
  5348. With argument DAY-OF-YEAR, switch to that day of the year."
  5349. (interactive "P")
  5350. (setq org-agenda-ndays 1)
  5351. (org-agenda-change-time-span 'day day-of-year))
  5352. (defun org-agenda-week-view (&optional iso-week)
  5353. "Switch to daily view for agenda.
  5354. With argument ISO-WEEK, switch to the corresponding ISO week.
  5355. If ISO-WEEK has more then 2 digits, only the last two encode the
  5356. week. Any digits before this encode a year. So 200712 means
  5357. week 12 of year 2007. Years in the range 1938-2037 can also be
  5358. written as 2-digit years."
  5359. (interactive "P")
  5360. (setq org-agenda-ndays 7)
  5361. (org-agenda-change-time-span 'week iso-week))
  5362. (defun org-agenda-month-view (&optional month)
  5363. "Switch to monthly view for agenda.
  5364. With argument MONTH, switch to that month."
  5365. (interactive "P")
  5366. (org-agenda-change-time-span 'month month))
  5367. (defun org-agenda-year-view (&optional year)
  5368. "Switch to yearly view for agenda.
  5369. With argument YEAR, switch to that year.
  5370. If MONTH has more then 2 digits, only the last two encode the
  5371. month. Any digits before this encode a year. So 200712 means
  5372. December year 2007. Years in the range 1938-2037 can also be
  5373. written as 2-digit years."
  5374. (interactive "P")
  5375. (when year
  5376. (setq year (org-small-year-to-year year)))
  5377. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5378. (org-agenda-change-time-span 'year year)
  5379. (error "Abort")))
  5380. (defun org-agenda-change-time-span (span &optional n)
  5381. "Change the agenda view to SPAN.
  5382. SPAN may be `day', `week', `month', `year'."
  5383. (org-agenda-check-type t 'agenda)
  5384. (if (and (not n) (equal org-agenda-span span))
  5385. (error "Viewing span is already \"%s\"" span))
  5386. (let* ((sd (or (org-get-at-bol 'day)
  5387. org-starting-day))
  5388. (computed (org-agenda-compute-time-span sd span n))
  5389. (org-agenda-overriding-arguments
  5390. (list (car org-agenda-last-arguments)
  5391. (car computed) (cdr computed) t)))
  5392. (org-agenda-redo)
  5393. (org-agenda-find-same-or-today-or-agenda))
  5394. (org-agenda-set-mode-name)
  5395. (message "Switched to %s view" span))
  5396. (defun org-agenda-compute-time-span (sd span &optional n)
  5397. "Compute starting date and number of days for agenda.
  5398. SPAN may be `day', `week', `month', `year'. The return value
  5399. is a cons cell with the starting date and the number of days,
  5400. so that the date SD will be in that range."
  5401. (let* ((greg (calendar-gregorian-from-absolute sd))
  5402. (dg (nth 1 greg))
  5403. (mg (car greg))
  5404. (yg (nth 2 greg))
  5405. nd w1 y1 m1 thisweek)
  5406. (cond
  5407. ((eq span 'day)
  5408. (when n
  5409. (setq sd (+ (calendar-absolute-from-gregorian
  5410. (list mg 1 yg))
  5411. n -1)))
  5412. (setq nd 1))
  5413. ((eq span 'week)
  5414. (let* ((nt (calendar-day-of-week
  5415. (calendar-gregorian-from-absolute sd)))
  5416. (d (if org-agenda-start-on-weekday
  5417. (- nt org-agenda-start-on-weekday)
  5418. 0)))
  5419. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5420. (when n
  5421. (require 'cal-iso)
  5422. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5423. (when (> n 99)
  5424. (setq y1 (org-small-year-to-year (/ n 100))
  5425. n (mod n 100)))
  5426. (setq sd
  5427. (calendar-absolute-from-iso
  5428. (list n 1
  5429. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5430. (setq nd 7)))
  5431. ((eq span 'month)
  5432. (when (and n (> n 99))
  5433. (setq y1 (org-small-year-to-year (/ n 100))
  5434. n (mod n 100)))
  5435. (setq sd (calendar-absolute-from-gregorian
  5436. (list (or n mg) 1 (or y1 yg)))
  5437. nd (- (calendar-absolute-from-gregorian
  5438. (list (1+ (or n mg)) 1 (or y1 yg)))
  5439. sd)))
  5440. ((eq span 'year)
  5441. (setq sd (calendar-absolute-from-gregorian
  5442. (list 1 1 (or n yg)))
  5443. nd (- (calendar-absolute-from-gregorian
  5444. (list 1 1 (1+ (or n yg))))
  5445. sd))))
  5446. (cons sd nd)))
  5447. (defun org-agenda-next-date-line (&optional arg)
  5448. "Jump to the next line indicating a date in agenda buffer."
  5449. (interactive "p")
  5450. (org-agenda-check-type t 'agenda 'timeline)
  5451. (beginning-of-line 1)
  5452. ;; This does not work if user makes date format that starts with a blank
  5453. (if (looking-at "^\\S-") (forward-char 1))
  5454. (if (not (re-search-forward "^\\S-" nil t arg))
  5455. (progn
  5456. (backward-char 1)
  5457. (error "No next date after this line in this buffer")))
  5458. (goto-char (match-beginning 0)))
  5459. (defun org-agenda-previous-date-line (&optional arg)
  5460. "Jump to the previous line indicating a date in agenda buffer."
  5461. (interactive "p")
  5462. (org-agenda-check-type t 'agenda 'timeline)
  5463. (beginning-of-line 1)
  5464. (if (not (re-search-backward "^\\S-" nil t arg))
  5465. (error "No previous date before this line in this buffer")))
  5466. ;; Initialize the highlight
  5467. (defvar org-hl (org-make-overlay 1 1))
  5468. (org-overlay-put org-hl 'face 'highlight)
  5469. (defun org-highlight (begin end &optional buffer)
  5470. "Highlight a region with overlay."
  5471. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  5472. org-hl begin end (or buffer (current-buffer))))
  5473. (defun org-unhighlight ()
  5474. "Detach overlay INDEX."
  5475. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  5476. ;; FIXME this is currently not used.
  5477. (defun org-highlight-until-next-command (beg end &optional buffer)
  5478. "Move the highlight overlay to BEG/END, remove it before the next command."
  5479. (org-highlight beg end buffer)
  5480. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5481. (defun org-unhighlight-once ()
  5482. "Remove the highlight from its position, and this function from the hook."
  5483. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5484. (org-unhighlight))
  5485. (defun org-agenda-follow-mode ()
  5486. "Toggle follow mode in an agenda buffer."
  5487. (interactive)
  5488. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5489. (org-agenda-set-mode-name)
  5490. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5491. (org-agenda-show))
  5492. (message "Follow mode is %s"
  5493. (if org-agenda-follow-mode "on" "off")))
  5494. (defun org-agenda-entry-text-mode (&optional arg)
  5495. "Toggle entry text mode in an agenda buffer."
  5496. (interactive "P")
  5497. (if (integerp arg)
  5498. (setq org-agenda-entry-text-mode t)
  5499. (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
  5500. (org-agenda-entry-text-hide)
  5501. (and org-agenda-entry-text-mode
  5502. (let ((org-agenda-entry-text-maxlines
  5503. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5504. (org-agenda-entry-text-show)))
  5505. (org-agenda-set-mode-name)
  5506. (message "Entry text mode is %s. Maximum number of lines is %d"
  5507. (if org-agenda-entry-text-mode "on" "off")
  5508. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5509. (defun org-agenda-clockreport-mode ()
  5510. "Toggle clocktable mode in an agenda buffer."
  5511. (interactive)
  5512. (org-agenda-check-type t 'agenda)
  5513. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5514. (org-agenda-set-mode-name)
  5515. (org-agenda-redo)
  5516. (message "Clocktable mode is %s"
  5517. (if org-agenda-clockreport-mode "on" "off")))
  5518. (defun org-agenda-log-mode (&optional special)
  5519. "Toggle log mode in an agenda buffer.
  5520. With argument SPECIAL, show all possible log items, not only the ones
  5521. configured in `org-agenda-log-mode-items'.
  5522. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5523. (interactive "P")
  5524. (org-agenda-check-type t 'agenda 'timeline)
  5525. (setq org-agenda-show-log
  5526. (if (equal special '(16))
  5527. 'only
  5528. (if special '(closed clock state)
  5529. (not org-agenda-show-log))))
  5530. (org-agenda-set-mode-name)
  5531. (org-agenda-redo)
  5532. (message "Log mode is %s"
  5533. (if org-agenda-show-log "on" "off")))
  5534. (defun org-agenda-archives-mode (&optional with-files)
  5535. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5536. When called with a prefix argument, include all archive files as well."
  5537. (interactive "P")
  5538. (setq org-agenda-archives-mode
  5539. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5540. (org-agenda-set-mode-name)
  5541. (org-agenda-redo)
  5542. (message
  5543. "%s"
  5544. (cond
  5545. ((eq org-agenda-archives-mode nil)
  5546. "No archives are included")
  5547. ((eq org-agenda-archives-mode 'trees)
  5548. (format "Trees with :%s: tag are included" org-archive-tag))
  5549. ((eq org-agenda-archives-mode t)
  5550. (format "Trees with :%s: tag and all active archive files are included"
  5551. org-archive-tag)))))
  5552. (defun org-agenda-toggle-diary ()
  5553. "Toggle diary inclusion in an agenda buffer."
  5554. (interactive)
  5555. (org-agenda-check-type t 'agenda)
  5556. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5557. (org-agenda-redo)
  5558. (org-agenda-set-mode-name)
  5559. (message "Diary inclusion turned %s"
  5560. (if org-agenda-include-diary "on" "off")))
  5561. (defun org-agenda-toggle-deadlines ()
  5562. "Toggle diary inclusion in an agenda buffer."
  5563. (interactive)
  5564. (org-agenda-check-type t 'agenda)
  5565. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5566. (org-agenda-redo)
  5567. (org-agenda-set-mode-name)
  5568. (message "Deadlines inclusion turned %s"
  5569. (if org-agenda-include-deadlines "on" "off")))
  5570. (defun org-agenda-toggle-time-grid ()
  5571. "Toggle time grid in an agenda buffer."
  5572. (interactive)
  5573. (org-agenda-check-type t 'agenda)
  5574. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5575. (org-agenda-redo)
  5576. (org-agenda-set-mode-name)
  5577. (message "Time-grid turned %s"
  5578. (if org-agenda-use-time-grid "on" "off")))
  5579. (defun org-agenda-set-mode-name ()
  5580. "Set the mode name to indicate all the small mode settings."
  5581. (setq mode-name
  5582. (concat "Org-Agenda"
  5583. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5584. (if (equal org-agenda-ndays 1) " Day" "")
  5585. (if (equal org-agenda-ndays 7) " Week" "")
  5586. (if org-agenda-follow-mode " Follow" "")
  5587. (if org-agenda-entry-text-mode " ETxt" "")
  5588. (if org-agenda-include-diary " Diary" "")
  5589. (if org-agenda-include-deadlines " Ddl" "")
  5590. (if org-agenda-use-time-grid " Grid" "")
  5591. (if (and (boundp 'org-habit-show-habits)
  5592. org-habit-show-habits) " Habit" "")
  5593. (if (consp org-agenda-show-log) " LogAll"
  5594. (if org-agenda-show-log " Log" ""))
  5595. (if (or org-agenda-filter (get 'org-agenda-filter
  5596. :preset-filter))
  5597. (concat " {" (mapconcat
  5598. 'identity
  5599. (append (get 'org-agenda-filter
  5600. :preset-filter)
  5601. org-agenda-filter) "") "}")
  5602. "")
  5603. (if org-agenda-archives-mode
  5604. (if (eq org-agenda-archives-mode t)
  5605. " Archives"
  5606. (format " :%s:" org-archive-tag))
  5607. "")
  5608. (if org-agenda-clockreport-mode " Clock" "")))
  5609. (force-mode-line-update))
  5610. (defun org-agenda-post-command-hook ()
  5611. (setq org-agenda-type
  5612. (or (get-text-property (point) 'org-agenda-type)
  5613. (get-text-property (max (point-min) (1- (point)))
  5614. 'org-agenda-type))))
  5615. (defun org-agenda-next-line ()
  5616. "Move cursor to the next line, and show if follow-mode is active."
  5617. (interactive)
  5618. (call-interactively 'next-line)
  5619. (org-agenda-do-context-action))
  5620. (defun org-agenda-previous-line ()
  5621. "Move cursor to the previous line, and show if follow-mode is active."
  5622. (interactive)
  5623. (call-interactively 'previous-line)
  5624. (org-agenda-do-context-action))
  5625. (defun org-agenda-do-context-action ()
  5626. "Show outline path and, maybe, follow-mode window."
  5627. (let ((m (org-get-at-bol 'org-marker)))
  5628. (if (and org-agenda-follow-mode m)
  5629. (org-agenda-show))
  5630. (if (and m org-agenda-show-outline-path)
  5631. (org-with-point-at m
  5632. (org-display-outline-path t)))))
  5633. (defun org-agenda-show-priority ()
  5634. "Show the priority of the current item.
  5635. This priority is composed of the main priority given with the [#A] cookies,
  5636. and by additional input from the age of a schedules or deadline entry."
  5637. (interactive)
  5638. (let* ((pri (org-get-at-bol 'priority)))
  5639. (message "Priority is %d" (if pri pri -1000))))
  5640. (defun org-agenda-show-tags ()
  5641. "Show the tags applicable to the current item."
  5642. (interactive)
  5643. (let* ((tags (org-get-at-bol 'tags)))
  5644. (if tags
  5645. (message "Tags are :%s:"
  5646. (org-no-properties (mapconcat 'identity tags ":")))
  5647. (message "No tags associated with this line"))))
  5648. (defun org-agenda-goto (&optional highlight)
  5649. "Go to the Org-mode file which contains the item at point."
  5650. (interactive)
  5651. (let* ((marker (or (org-get-at-bol 'org-marker)
  5652. (org-agenda-error)))
  5653. (buffer (marker-buffer marker))
  5654. (pos (marker-position marker)))
  5655. (switch-to-buffer-other-window buffer)
  5656. (widen)
  5657. (goto-char pos)
  5658. (when (org-mode-p)
  5659. (org-show-context 'agenda)
  5660. (save-excursion
  5661. (and (outline-next-heading)
  5662. (org-flag-heading nil)))) ; show the next heading
  5663. (recenter (/ (window-height) 2))
  5664. (run-hooks 'org-agenda-after-show-hook)
  5665. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5666. (defvar org-agenda-after-show-hook nil
  5667. "Normal hook run after an item has been shown from the agenda.
  5668. Point is in the buffer where the item originated.")
  5669. (defun org-agenda-kill ()
  5670. "Kill the entry or subtree belonging to the current agenda entry."
  5671. (interactive)
  5672. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5673. (let* ((marker (or (org-get-at-bol 'org-marker)
  5674. (org-agenda-error)))
  5675. (buffer (marker-buffer marker))
  5676. (pos (marker-position marker))
  5677. (type (org-get-at-bol 'type))
  5678. dbeg dend (n 0) conf)
  5679. (org-with-remote-undo buffer
  5680. (with-current-buffer buffer
  5681. (save-excursion
  5682. (goto-char pos)
  5683. (if (and (org-mode-p) (not (member type '("sexp"))))
  5684. (setq dbeg (progn (org-back-to-heading t) (point))
  5685. dend (org-end-of-subtree t t))
  5686. (setq dbeg (point-at-bol)
  5687. dend (min (point-max) (1+ (point-at-eol)))))
  5688. (goto-char dbeg)
  5689. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5690. (setq conf (or (eq t org-agenda-confirm-kill)
  5691. (and (numberp org-agenda-confirm-kill)
  5692. (> n org-agenda-confirm-kill))))
  5693. (and conf
  5694. (not (y-or-n-p
  5695. (format "Delete entry with %d lines in buffer \"%s\"? "
  5696. n (buffer-name buffer))))
  5697. (error "Abort"))
  5698. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5699. (with-current-buffer buffer (delete-region dbeg dend))
  5700. (message "Agenda item and source killed"))))
  5701. (defvar org-archive-default-command)
  5702. (defun org-agenda-archive-default ()
  5703. "Archive the entry or subtree belonging to the current agenda entry."
  5704. (interactive)
  5705. (require 'org-archive)
  5706. (org-agenda-archive-with org-archive-default-command))
  5707. (defun org-agenda-archive-default-with-confirmation ()
  5708. "Archive the entry or subtree belonging to the current agenda entry."
  5709. (interactive)
  5710. (require 'org-archive)
  5711. (org-agenda-archive-with org-archive-default-command 'confirm))
  5712. (defun org-agenda-archive ()
  5713. "Archive the entry or subtree belonging to the current agenda entry."
  5714. (interactive)
  5715. (org-agenda-archive-with 'org-archive-subtree))
  5716. (defun org-agenda-archive-to-archive-sibling ()
  5717. "Move the entry to the archive sibling."
  5718. (interactive)
  5719. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5720. (defun org-agenda-archive-with (cmd &optional confirm)
  5721. "Move the entry to the archive sibling."
  5722. (interactive)
  5723. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5724. (let* ((marker (or (org-get-at-bol 'org-marker)
  5725. (org-agenda-error)))
  5726. (buffer (marker-buffer marker))
  5727. (pos (marker-position marker)))
  5728. (org-with-remote-undo buffer
  5729. (with-current-buffer buffer
  5730. (if (org-mode-p)
  5731. (if (and confirm
  5732. (not (y-or-n-p "Archive this subtree or entry? ")))
  5733. (error "Abort")
  5734. (save-excursion
  5735. (goto-char pos)
  5736. (org-remove-subtree-entries-from-agenda)
  5737. (org-back-to-heading t)
  5738. (funcall cmd)))
  5739. (error "Archiving works only in Org-mode files"))))))
  5740. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5741. "Remove all lines in the agenda that correspond to a given subtree.
  5742. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5743. If this information is not given, the function uses the tree at point."
  5744. (let ((buf (or buf (current-buffer))) m p)
  5745. (save-excursion
  5746. (unless (and beg end)
  5747. (org-back-to-heading t)
  5748. (setq beg (point))
  5749. (org-end-of-subtree t)
  5750. (setq end (point)))
  5751. (set-buffer (get-buffer org-agenda-buffer-name))
  5752. (save-excursion
  5753. (goto-char (point-max))
  5754. (beginning-of-line 1)
  5755. (while (not (bobp))
  5756. (when (and (setq m (org-get-at-bol 'org-marker))
  5757. (equal buf (marker-buffer m))
  5758. (setq p (marker-position m))
  5759. (>= p beg)
  5760. (< p end))
  5761. (let ((inhibit-read-only t))
  5762. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5763. (beginning-of-line 0))))))
  5764. (defun org-agenda-refile (&optional goto rfloc)
  5765. "Refile the item at point."
  5766. (interactive "P")
  5767. (if (equal goto '(16))
  5768. (org-refile-goto-last-stored)
  5769. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5770. (org-agenda-error)))
  5771. (buffer (marker-buffer marker))
  5772. (pos (marker-position marker))
  5773. (rfloc (or rfloc
  5774. (org-refile-get-location
  5775. (if goto "Goto: " "Refile to: ") buffer
  5776. org-refile-allow-creating-parent-nodes))))
  5777. (with-current-buffer buffer
  5778. (save-excursion
  5779. (save-restriction
  5780. (widen)
  5781. (goto-char marker)
  5782. (org-remove-subtree-entries-from-agenda)
  5783. (org-refile goto buffer rfloc)))))))
  5784. (defun org-agenda-open-link (&optional arg)
  5785. "Follow the link in the current line, if any.
  5786. This looks for a link in the displayed line in the agenda. It also looks
  5787. at the text of the entry itself."
  5788. (interactive "P")
  5789. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5790. (org-get-at-bol 'org-marker)))
  5791. (buffer (and marker (marker-buffer marker)))
  5792. (prefix (buffer-substring
  5793. (point-at-bol)
  5794. (+ (point-at-bol)
  5795. (or (org-get-at-bol 'prefix-length) 0)))))
  5796. (cond
  5797. (buffer
  5798. (with-current-buffer buffer
  5799. (save-excursion
  5800. (save-restriction
  5801. (widen)
  5802. (goto-char marker)
  5803. (org-offer-links-in-entry arg prefix)))))
  5804. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5805. (save-excursion
  5806. (beginning-of-line 1)
  5807. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5808. (org-open-link-from-string (match-string 1)))
  5809. (t (error "No link to open here")))))
  5810. (defun org-agenda-copy-local-variable (var)
  5811. "Get a variable from a referenced buffer and install it here."
  5812. (let ((m (org-get-at-bol 'org-marker)))
  5813. (when (and m (buffer-live-p (marker-buffer m)))
  5814. (org-set-local var (with-current-buffer (marker-buffer m)
  5815. (symbol-value var))))))
  5816. (defun org-agenda-switch-to (&optional delete-other-windows)
  5817. "Go to the Org-mode file which contains the item at point."
  5818. (interactive)
  5819. (if (and org-return-follows-link
  5820. (not (org-get-at-bol 'org-marker))
  5821. (org-in-regexp org-bracket-link-regexp))
  5822. (org-open-link-from-string (match-string 0))
  5823. (let* ((marker (or (org-get-at-bol 'org-marker)
  5824. (org-agenda-error)))
  5825. (buffer (marker-buffer marker))
  5826. (pos (marker-position marker)))
  5827. (switch-to-buffer buffer)
  5828. (and delete-other-windows (delete-other-windows))
  5829. (widen)
  5830. (goto-char pos)
  5831. (when (org-mode-p)
  5832. (org-show-context 'agenda)
  5833. (save-excursion
  5834. (and (outline-next-heading)
  5835. (org-flag-heading nil))))))) ; show the next heading
  5836. (defun org-agenda-goto-mouse (ev)
  5837. "Go to the Org-mode file which contains the item at the mouse click."
  5838. (interactive "e")
  5839. (mouse-set-point ev)
  5840. (org-agenda-goto))
  5841. (defun org-agenda-show (&optional full-entry)
  5842. "Display the Org-mode file which contains the item at point.
  5843. With prefix argument FULL-ENTRY, make the entire entry visible
  5844. if it was hidden in the outline."
  5845. (interactive "P")
  5846. (let ((win (selected-window)))
  5847. (if full-entry
  5848. (let ((org-show-entry-below t))
  5849. (org-agenda-goto t))
  5850. (org-agenda-goto t))
  5851. (select-window win)))
  5852. (defvar org-agenda-show-window nil)
  5853. (defun org-agenda-show-and-scroll-up ()
  5854. "Display the Org-mode file which contains the item at point.
  5855. When called repeatedly, scroll the window that is displaying the buffer."
  5856. (interactive)
  5857. (let ((win (selected-window)))
  5858. (if (and (window-live-p org-agenda-show-window)
  5859. (eq this-command last-command))
  5860. (progn
  5861. (select-window org-agenda-show-window)
  5862. (ignore-errors (scroll-up)))
  5863. (org-agenda-goto t)
  5864. (show-subtree)
  5865. (setq org-agenda-show-window (selected-window)))
  5866. (select-window win)))
  5867. (defun org-agenda-show-scroll-down ()
  5868. "Scroll down the window showing the agenda."
  5869. (interactive)
  5870. (let ((win (selected-window)))
  5871. (when (window-live-p org-agenda-show-window)
  5872. (select-window org-agenda-show-window)
  5873. (ignore-errors (scroll-down))
  5874. (select-window win))))
  5875. (defun org-agenda-show-1 (&optional more)
  5876. "Display the Org-mode file which contains the item at point.
  5877. The prefix arg selects the amount of information to display:
  5878. 0 hide the subtree
  5879. 1 just show the entry according to defaults.
  5880. 2 show the children view
  5881. 3 show the subtree view
  5882. 4 show the entire subtree and any LOGBOOK drawers
  5883. 5 show the entire subtree and any drawers
  5884. With prefix argument FULL-ENTRY, make the entire entry visible
  5885. if it was hidden in the outline."
  5886. (interactive "p")
  5887. (let ((win (selected-window)))
  5888. (org-agenda-goto t)
  5889. (org-recenter-heading 1)
  5890. (cond
  5891. ((= more 0)
  5892. (hide-subtree)
  5893. (save-excursion
  5894. (org-back-to-heading)
  5895. (run-hook-with-args 'org-cycle-hook 'folded))
  5896. (message "Remote: FOLDED"))
  5897. ((and (interactive-p) (= more 1))
  5898. (message "Remote: show with default settings"))
  5899. ((= more 2)
  5900. (show-entry)
  5901. (show-children)
  5902. (save-excursion
  5903. (org-back-to-heading)
  5904. (run-hook-with-args 'org-cycle-hook 'children))
  5905. (message "Remote: CHILDREN"))
  5906. ((= more 3)
  5907. (show-subtree)
  5908. (save-excursion
  5909. (org-back-to-heading)
  5910. (run-hook-with-args 'org-cycle-hook 'subtree))
  5911. (message "Remote: SUBTREE"))
  5912. ((= more 4)
  5913. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  5914. (org-drawer-regexp
  5915. (concat "^[ \t]*:\\("
  5916. (mapconcat 'regexp-quote org-drawers "\\|")
  5917. "\\):[ \t]*$")))
  5918. (show-subtree)
  5919. (save-excursion
  5920. (org-back-to-heading)
  5921. (org-cycle-hide-drawers 'subtree)))
  5922. (message "Remote: SUBTREE AND LOGBOOK"))
  5923. ((> more 4)
  5924. (show-subtree)
  5925. (message "Remote: SUBTREE AND ALL DRAWERS")))
  5926. (select-window win)))
  5927. (defun org-recenter-heading (n)
  5928. (save-excursion
  5929. (org-back-to-heading)
  5930. (recenter n)))
  5931. (defvar org-agenda-cycle-counter nil)
  5932. (defun org-agenda-cycle-show (&optional n)
  5933. "Show the current entry in another window, with default settings.
  5934. Default settings are taken from `org-show-hierarchy-above' and siblings.
  5935. When use repeatedly in immediate succession, the remote entry will cycle
  5936. through visibility
  5937. children -> subtree -> folded
  5938. When called with a numeric prefix arg, that arg will be passed through to
  5939. `org-agenda-show-1'. For the interpretation of that argument, see the
  5940. docstring of `org-agenda-show-1'."
  5941. (interactive "P")
  5942. (if (integerp n)
  5943. (setq org-agenda-cycle-counter n)
  5944. (if (not (eq last-command this-command))
  5945. (setq org-agenda-cycle-counter 1)
  5946. (if (equal org-agenda-cycle-counter 0)
  5947. (setq org-agenda-cycle-counter 2)
  5948. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  5949. (if (> org-agenda-cycle-counter 3)
  5950. (setq org-agenda-cycle-counter 0)))))
  5951. (org-agenda-show-1 org-agenda-cycle-counter))
  5952. (defun org-agenda-recenter (arg)
  5953. "Display the Org-mode file which contains the item at point and recenter."
  5954. (interactive "P")
  5955. (let ((win (selected-window)))
  5956. (org-agenda-goto t)
  5957. (recenter arg)
  5958. (select-window win)))
  5959. (defun org-agenda-show-mouse (ev)
  5960. "Display the Org-mode file which contains the item at the mouse click."
  5961. (interactive "e")
  5962. (mouse-set-point ev)
  5963. (org-agenda-show))
  5964. (defun org-agenda-check-no-diary ()
  5965. "Check if the entry is a diary link and abort if yes."
  5966. (if (org-get-at-bol 'org-agenda-diary-link)
  5967. (org-agenda-error)))
  5968. (defun org-agenda-error ()
  5969. (error "Command not allowed in this line"))
  5970. (defun org-agenda-tree-to-indirect-buffer ()
  5971. "Show the subtree corresponding to the current entry in an indirect buffer.
  5972. This calls the command `org-tree-to-indirect-buffer' from the original
  5973. Org-mode buffer.
  5974. With numerical prefix arg ARG, go up to this level and then take that tree.
  5975. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  5976. dedicated frame)."
  5977. (interactive)
  5978. (org-agenda-check-no-diary)
  5979. (let* ((marker (or (org-get-at-bol 'org-marker)
  5980. (org-agenda-error)))
  5981. (buffer (marker-buffer marker))
  5982. (pos (marker-position marker)))
  5983. (with-current-buffer buffer
  5984. (save-excursion
  5985. (goto-char pos)
  5986. (call-interactively 'org-tree-to-indirect-buffer)))))
  5987. (defvar org-last-heading-marker (make-marker)
  5988. "Marker pointing to the headline that last changed its TODO state
  5989. by a remote command from the agenda.")
  5990. (defun org-agenda-todo-nextset ()
  5991. "Switch TODO entry to next sequence."
  5992. (interactive)
  5993. (org-agenda-todo 'nextset))
  5994. (defun org-agenda-todo-previousset ()
  5995. "Switch TODO entry to previous sequence."
  5996. (interactive)
  5997. (org-agenda-todo 'previousset))
  5998. (defun org-agenda-todo (&optional arg)
  5999. "Cycle TODO state of line at point, also in Org-mode file.
  6000. This changes the line at point, all other lines in the agenda referring to
  6001. the same tree node, and the headline of the tree node in the Org-mode file."
  6002. (interactive "P")
  6003. (org-agenda-check-no-diary)
  6004. (let* ((col (current-column))
  6005. (marker (or (org-get-at-bol 'org-marker)
  6006. (org-agenda-error)))
  6007. (buffer (marker-buffer marker))
  6008. (pos (marker-position marker))
  6009. (hdmarker (org-get-at-bol 'org-hd-marker))
  6010. (todayp (equal (org-get-at-bol 'day)
  6011. (time-to-days (current-time))))
  6012. (inhibit-read-only t)
  6013. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6014. (org-with-remote-undo buffer
  6015. (with-current-buffer buffer
  6016. (widen)
  6017. (goto-char pos)
  6018. (org-show-context 'agenda)
  6019. (save-excursion
  6020. (and (outline-next-heading)
  6021. (org-flag-heading nil))) ; show the next heading
  6022. (let ((current-prefix-arg arg))
  6023. (call-interactively 'org-todo))
  6024. (and (bolp) (forward-char 1))
  6025. (setq newhead (org-get-heading))
  6026. (when (and (org-bound-and-true-p
  6027. org-agenda-headline-snapshot-before-repeat)
  6028. (not (equal org-agenda-headline-snapshot-before-repeat
  6029. newhead))
  6030. todayp)
  6031. (setq newhead org-agenda-headline-snapshot-before-repeat
  6032. just-one t))
  6033. (save-excursion
  6034. (org-back-to-heading)
  6035. (move-marker org-last-heading-marker (point))))
  6036. (beginning-of-line 1)
  6037. (save-excursion
  6038. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6039. (org-move-to-column col))))
  6040. (defun org-agenda-add-note (&optional arg)
  6041. "Add a time-stamped note to the entry at point."
  6042. (interactive "P")
  6043. (org-agenda-check-no-diary)
  6044. (let* ((marker (or (org-get-at-bol 'org-marker)
  6045. (org-agenda-error)))
  6046. (buffer (marker-buffer marker))
  6047. (pos (marker-position marker))
  6048. (hdmarker (org-get-at-bol 'org-hd-marker))
  6049. (inhibit-read-only t))
  6050. (with-current-buffer buffer
  6051. (widen)
  6052. (goto-char pos)
  6053. (org-show-context 'agenda)
  6054. (save-excursion
  6055. (and (outline-next-heading)
  6056. (org-flag-heading nil))) ; show the next heading
  6057. (org-add-note))))
  6058. (defun org-agenda-change-all-lines (newhead hdmarker
  6059. &optional fixface just-this)
  6060. "Change all lines in the agenda buffer which match HDMARKER.
  6061. The new content of the line will be NEWHEAD (as modified by
  6062. `org-format-agenda-item'). HDMARKER is checked with
  6063. `equal' against all `org-hd-marker' text properties in the file.
  6064. If FIXFACE is non-nil, the face of each item is modified according to
  6065. the new TODO state.
  6066. If JUST-THIS is non-nil, change just the current line, not all.
  6067. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6068. (let* ((inhibit-read-only t)
  6069. (line (org-current-line))
  6070. (thetags (with-current-buffer (marker-buffer hdmarker)
  6071. (save-excursion (save-restriction (widen)
  6072. (goto-char hdmarker)
  6073. (org-get-tags-at)))))
  6074. props m pl undone-face done-face finish new dotime cat tags)
  6075. (save-excursion
  6076. (goto-char (point-max))
  6077. (beginning-of-line 1)
  6078. (while (not finish)
  6079. (setq finish (bobp))
  6080. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6081. (or (not just-this) (= (org-current-line) line))
  6082. (equal m hdmarker))
  6083. (setq props (text-properties-at (point))
  6084. dotime (org-get-at-bol 'dotime)
  6085. cat (org-get-at-bol 'org-category)
  6086. tags thetags
  6087. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6088. pl (org-get-at-bol 'prefix-length)
  6089. undone-face (org-get-at-bol 'undone-face)
  6090. done-face (org-get-at-bol 'done-face))
  6091. (goto-char (+ (point) pl))
  6092. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6093. (cond
  6094. ((equal new "")
  6095. (beginning-of-line 1)
  6096. (and (looking-at ".*\n?") (replace-match "")))
  6097. ((looking-at ".*")
  6098. (replace-match new t t)
  6099. (beginning-of-line 1)
  6100. (add-text-properties (point-at-bol) (point-at-eol) props)
  6101. (when fixface
  6102. (add-text-properties
  6103. (point-at-bol) (point-at-eol)
  6104. (list 'face
  6105. (if org-last-todo-state-is-todo
  6106. undone-face done-face))))
  6107. (org-agenda-highlight-todo 'line)
  6108. (beginning-of-line 1))
  6109. (t (error "Line update did not work"))))
  6110. (beginning-of-line 0)))
  6111. (org-finalize-agenda)))
  6112. (defun org-agenda-align-tags (&optional line)
  6113. "Align all tags in agenda items to `org-agenda-tags-column'."
  6114. (let ((inhibit-read-only t) l c)
  6115. (save-excursion
  6116. (goto-char (if line (point-at-bol) (point-min)))
  6117. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  6118. (if line (point-at-eol) nil) t)
  6119. (add-text-properties
  6120. (match-beginning 2) (match-end 2)
  6121. (list 'face (delq nil (let ((prop (get-text-property
  6122. (match-beginning 2) 'face)))
  6123. (or (listp prop) (setq prop (list prop)))
  6124. (if (memq 'org-tag prop)
  6125. prop
  6126. (cons 'org-tag prop))))))
  6127. (setq l (- (match-end 2) (match-beginning 2))
  6128. c (if (< org-agenda-tags-column 0)
  6129. (- (abs org-agenda-tags-column) l)
  6130. org-agenda-tags-column))
  6131. (delete-region (match-beginning 1) (match-end 1))
  6132. (goto-char (match-beginning 1))
  6133. (insert (org-add-props
  6134. (make-string (max 1 (- c (current-column))) ?\ )
  6135. (plist-put (copy-sequence (text-properties-at (point)))
  6136. 'face nil))))
  6137. (goto-char (point-min))
  6138. (org-font-lock-add-tag-faces (point-max)))))
  6139. (defun org-agenda-priority-up ()
  6140. "Increase the priority of line at point, also in Org-mode file."
  6141. (interactive)
  6142. (org-agenda-priority 'up))
  6143. (defun org-agenda-priority-down ()
  6144. "Decrease the priority of line at point, also in Org-mode file."
  6145. (interactive)
  6146. (org-agenda-priority 'down))
  6147. (defun org-agenda-priority (&optional force-direction)
  6148. "Set the priority of line at point, also in Org-mode file.
  6149. This changes the line at point, all other lines in the agenda referring to
  6150. the same tree node, and the headline of the tree node in the Org-mode file."
  6151. (interactive)
  6152. (unless org-enable-priority-commands
  6153. (error "Priority commands are disabled"))
  6154. (org-agenda-check-no-diary)
  6155. (let* ((marker (or (org-get-at-bol 'org-marker)
  6156. (org-agenda-error)))
  6157. (hdmarker (org-get-at-bol 'org-hd-marker))
  6158. (buffer (marker-buffer hdmarker))
  6159. (pos (marker-position hdmarker))
  6160. (inhibit-read-only t)
  6161. newhead)
  6162. (org-with-remote-undo buffer
  6163. (with-current-buffer buffer
  6164. (widen)
  6165. (goto-char pos)
  6166. (org-show-context 'agenda)
  6167. (save-excursion
  6168. (and (outline-next-heading)
  6169. (org-flag-heading nil))) ; show the next heading
  6170. (funcall 'org-priority force-direction)
  6171. (end-of-line 1)
  6172. (setq newhead (org-get-heading)))
  6173. (org-agenda-change-all-lines newhead hdmarker)
  6174. (beginning-of-line 1))))
  6175. ;; FIXME: should fix the tags property of the agenda line.
  6176. (defun org-agenda-set-tags (&optional tag onoff)
  6177. "Set tags for the current headline."
  6178. (interactive)
  6179. (org-agenda-check-no-diary)
  6180. (if (and (org-region-active-p) (interactive-p))
  6181. (call-interactively 'org-change-tag-in-region)
  6182. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6183. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6184. (org-agenda-error)))
  6185. (buffer (marker-buffer hdmarker))
  6186. (pos (marker-position hdmarker))
  6187. (inhibit-read-only t)
  6188. newhead)
  6189. (org-with-remote-undo buffer
  6190. (with-current-buffer buffer
  6191. (widen)
  6192. (goto-char pos)
  6193. (save-excursion
  6194. (org-show-context 'agenda))
  6195. (save-excursion
  6196. (and (outline-next-heading)
  6197. (org-flag-heading nil))) ; show the next heading
  6198. (goto-char pos)
  6199. (if tag
  6200. (org-toggle-tag tag onoff)
  6201. (call-interactively 'org-set-tags))
  6202. (end-of-line 1)
  6203. (setq newhead (org-get-heading)))
  6204. (org-agenda-change-all-lines newhead hdmarker)
  6205. (beginning-of-line 1)))))
  6206. (defun org-agenda-set-property ()
  6207. "Set a property for the current headline."
  6208. (interactive)
  6209. (org-agenda-check-no-diary)
  6210. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6211. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6212. (org-agenda-error)))
  6213. (buffer (marker-buffer hdmarker))
  6214. (pos (marker-position hdmarker))
  6215. (inhibit-read-only t)
  6216. newhead)
  6217. (org-with-remote-undo buffer
  6218. (with-current-buffer buffer
  6219. (widen)
  6220. (goto-char pos)
  6221. (save-excursion
  6222. (org-show-context 'agenda))
  6223. (save-excursion
  6224. (and (outline-next-heading)
  6225. (org-flag-heading nil))) ; show the next heading
  6226. (goto-char pos)
  6227. (call-interactively 'org-set-property)))))
  6228. (defun org-agenda-set-effort ()
  6229. "Set the effort property for the current headline."
  6230. (interactive)
  6231. (org-agenda-check-no-diary)
  6232. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6233. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6234. (org-agenda-error)))
  6235. (buffer (marker-buffer hdmarker))
  6236. (pos (marker-position hdmarker))
  6237. (inhibit-read-only t)
  6238. newhead)
  6239. (org-with-remote-undo buffer
  6240. (with-current-buffer buffer
  6241. (widen)
  6242. (goto-char pos)
  6243. (save-excursion
  6244. (org-show-context 'agenda))
  6245. (save-excursion
  6246. (and (outline-next-heading)
  6247. (org-flag-heading nil))) ; show the next heading
  6248. (goto-char pos)
  6249. (call-interactively 'org-set-effort)
  6250. (end-of-line 1)))))
  6251. (defun org-agenda-toggle-archive-tag ()
  6252. "Toggle the archive tag for the current entry."
  6253. (interactive)
  6254. (org-agenda-check-no-diary)
  6255. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6256. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6257. (org-agenda-error)))
  6258. (buffer (marker-buffer hdmarker))
  6259. (pos (marker-position hdmarker))
  6260. (inhibit-read-only t)
  6261. newhead)
  6262. (org-with-remote-undo buffer
  6263. (with-current-buffer buffer
  6264. (widen)
  6265. (goto-char pos)
  6266. (org-show-context 'agenda)
  6267. (save-excursion
  6268. (and (outline-next-heading)
  6269. (org-flag-heading nil))) ; show the next heading
  6270. (call-interactively 'org-toggle-archive-tag)
  6271. (end-of-line 1)
  6272. (setq newhead (org-get-heading)))
  6273. (org-agenda-change-all-lines newhead hdmarker)
  6274. (beginning-of-line 1))))
  6275. (defun org-agenda-do-date-later (arg)
  6276. (interactive "P")
  6277. (cond
  6278. ((or (equal arg '(16))
  6279. (memq last-command
  6280. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6281. (setq this-command 'org-agenda-date-later-minutes)
  6282. (org-agenda-date-later-minutes 1))
  6283. ((or (equal arg '(4))
  6284. (memq last-command
  6285. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6286. (setq this-command 'org-agenda-date-later-hours)
  6287. (org-agenda-date-later-hours 1))
  6288. (t
  6289. (org-agenda-date-later (prefix-numeric-value arg)))))
  6290. (defun org-agenda-do-date-earlier (arg)
  6291. (interactive "P")
  6292. (cond
  6293. ((or (equal arg '(16))
  6294. (memq last-command
  6295. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6296. (setq this-command 'org-agenda-date-earlier-minutes)
  6297. (org-agenda-date-earlier-minutes 1))
  6298. ((or (equal arg '(4))
  6299. (memq last-command
  6300. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6301. (setq this-command 'org-agenda-date-earlier-hours)
  6302. (org-agenda-date-earlier-hours 1))
  6303. (t
  6304. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6305. (defun org-agenda-date-later (arg &optional what)
  6306. "Change the date of this item to one day later."
  6307. (interactive "p")
  6308. (org-agenda-check-type t 'agenda 'timeline)
  6309. (org-agenda-check-no-diary)
  6310. (let* ((marker (or (org-get-at-bol 'org-marker)
  6311. (org-agenda-error)))
  6312. (buffer (marker-buffer marker))
  6313. (pos (marker-position marker)))
  6314. (org-with-remote-undo buffer
  6315. (with-current-buffer buffer
  6316. (widen)
  6317. (goto-char pos)
  6318. (if (not (org-at-timestamp-p))
  6319. (error "Cannot find time stamp"))
  6320. (org-timestamp-change arg (or what 'day)))
  6321. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6322. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6323. (defun org-agenda-date-earlier (arg &optional what)
  6324. "Change the date of this item to one day earlier."
  6325. (interactive "p")
  6326. (org-agenda-date-later (- arg) what))
  6327. (defun org-agenda-date-later-minutes (arg)
  6328. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6329. (interactive "p")
  6330. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6331. (org-agenda-date-later arg 'minute))
  6332. (defun org-agenda-date-earlier-minutes (arg)
  6333. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6334. (interactive "p")
  6335. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6336. (org-agenda-date-earlier arg 'minute))
  6337. (defun org-agenda-date-later-hours (arg)
  6338. "Change the time of this item, in hour steps."
  6339. (interactive "p")
  6340. (org-agenda-date-later arg 'hour))
  6341. (defun org-agenda-date-earlier-hours (arg)
  6342. "Change the time of this item, in hour steps."
  6343. (interactive "p")
  6344. (org-agenda-date-earlier arg 'hour))
  6345. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6346. "Show new date stamp via text properties."
  6347. ;; We use text properties to make this undoable
  6348. (let ((inhibit-read-only t)
  6349. (buffer-invisibility-spec))
  6350. (setq stamp (concat " " prefix " => " stamp))
  6351. (save-excursion
  6352. (goto-char (point-max))
  6353. (while (not (bobp))
  6354. (when (equal marker (org-get-at-bol 'org-marker))
  6355. (org-move-to-column (- (window-width) (length stamp)) t)
  6356. (org-agenda-fix-tags-filter-overlays-at (point))
  6357. (if (featurep 'xemacs)
  6358. ;; Use `duplicable' property to trigger undo recording
  6359. (let ((ex (make-extent nil nil))
  6360. (gl (make-glyph stamp)))
  6361. (set-glyph-face gl 'secondary-selection)
  6362. (set-extent-properties
  6363. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6364. (insert-extent ex (1- (point)) (point-at-eol)))
  6365. (add-text-properties
  6366. (1- (point)) (point-at-eol)
  6367. (list 'display (org-add-props stamp nil
  6368. 'face 'secondary-selection))))
  6369. (beginning-of-line 1))
  6370. (beginning-of-line 0)))))
  6371. (defun org-agenda-date-prompt (arg)
  6372. "Change the date of this item. Date is prompted for, with default today.
  6373. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6374. be used to request time specification in the time stamp."
  6375. (interactive "P")
  6376. (org-agenda-check-type t 'agenda 'timeline)
  6377. (org-agenda-check-no-diary)
  6378. (let* ((marker (or (org-get-at-bol 'org-marker)
  6379. (org-agenda-error)))
  6380. (buffer (marker-buffer marker))
  6381. (pos (marker-position marker)))
  6382. (org-with-remote-undo buffer
  6383. (with-current-buffer buffer
  6384. (widen)
  6385. (goto-char pos)
  6386. (if (not (org-at-timestamp-p t))
  6387. (error "Cannot find time stamp"))
  6388. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6389. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6390. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6391. (defun org-agenda-schedule (arg)
  6392. "Schedule the item at point.
  6393. Arg is passed through to `org-schedule'."
  6394. (interactive "P")
  6395. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6396. (org-agenda-check-no-diary)
  6397. (let* ((marker (or (org-get-at-bol 'org-marker)
  6398. (org-agenda-error)))
  6399. (type (marker-insertion-type marker))
  6400. (buffer (marker-buffer marker))
  6401. (pos (marker-position marker))
  6402. (org-insert-labeled-timestamps-at-point nil)
  6403. ts)
  6404. (set-marker-insertion-type marker t)
  6405. (org-with-remote-undo buffer
  6406. (with-current-buffer buffer
  6407. (widen)
  6408. (goto-char pos)
  6409. (setq ts (org-schedule arg)))
  6410. (org-agenda-show-new-time marker ts "S"))
  6411. (message "Item scheduled for %s" ts)))
  6412. (defun org-agenda-deadline (arg)
  6413. "Schedule the item at point.
  6414. Arg is passed through to `org-deadline'."
  6415. (interactive "P")
  6416. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6417. (org-agenda-check-no-diary)
  6418. (let* ((marker (or (org-get-at-bol 'org-marker)
  6419. (org-agenda-error)))
  6420. (buffer (marker-buffer marker))
  6421. (pos (marker-position marker))
  6422. (org-insert-labeled-timestamps-at-point nil)
  6423. ts)
  6424. (org-with-remote-undo buffer
  6425. (with-current-buffer buffer
  6426. (widen)
  6427. (goto-char pos)
  6428. (setq ts (org-deadline arg)))
  6429. (org-agenda-show-new-time marker ts "D"))
  6430. (message "Deadline for this item set to %s" ts)))
  6431. (defun org-agenda-action ()
  6432. "Select entry for agenda action, or execute an agenda action.
  6433. This command prompts for another letter. Valid inputs are:
  6434. m Mark the entry at point for an agenda action
  6435. s Schedule the marked entry to the date at the cursor
  6436. d Set the deadline of the marked entry to the date at the cursor
  6437. r Call `org-remember' with cursor date as the default date
  6438. SPC Show marked entry in other window
  6439. TAB Visit marked entry in other window
  6440. The cursor may be at a date in the calendar, or in the Org agenda."
  6441. (interactive)
  6442. (let (ans)
  6443. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  6444. (setq ans (read-char-exclusive))
  6445. (cond
  6446. ((equal ans ?m)
  6447. ;; Mark this entry
  6448. (if (eq major-mode 'org-agenda-mode)
  6449. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6450. (org-get-at-bol 'org-marker))))
  6451. (if m
  6452. (progn
  6453. (move-marker org-agenda-action-marker
  6454. (marker-position m) (marker-buffer m))
  6455. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6456. (error "Don't know which entry to mark")))
  6457. (error "This command works only in the agenda")))
  6458. ((equal ans ?s)
  6459. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6460. ((equal ans ?d)
  6461. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6462. ((equal ans ?r)
  6463. (org-agenda-do-action '(org-remember) t))
  6464. ((equal ans ?\ )
  6465. (let ((cw (selected-window)))
  6466. (org-switch-to-buffer-other-window
  6467. (marker-buffer org-agenda-action-marker))
  6468. (goto-char org-agenda-action-marker)
  6469. (org-show-context 'agenda)
  6470. (select-window cw)))
  6471. ((equal ans ?\C-i)
  6472. (org-switch-to-buffer-other-window
  6473. (marker-buffer org-agenda-action-marker))
  6474. (goto-char org-agenda-action-marker)
  6475. (org-show-context 'agenda))
  6476. (t (error "Invalid agenda action %c" ans)))))
  6477. (defun org-agenda-do-action (form &optional current-buffer)
  6478. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6479. (let ((org-overriding-default-time (org-get-cursor-date)))
  6480. (if current-buffer
  6481. (eval form)
  6482. (if (not (marker-buffer org-agenda-action-marker))
  6483. (error "No entry has been selected for agenda action")
  6484. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6485. (save-excursion
  6486. (save-restriction
  6487. (widen)
  6488. (goto-char org-agenda-action-marker)
  6489. (eval form))))))))
  6490. (defun org-agenda-clock-in (&optional arg)
  6491. "Start the clock on the currently selected item."
  6492. (interactive "P")
  6493. (org-agenda-check-no-diary)
  6494. (if (equal arg '(4))
  6495. (org-clock-in arg)
  6496. (let* ((marker (or (org-get-at-bol 'org-marker)
  6497. (org-agenda-error)))
  6498. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6499. marker))
  6500. (pos (marker-position marker))
  6501. newhead)
  6502. (org-with-remote-undo (marker-buffer marker)
  6503. (with-current-buffer (marker-buffer marker)
  6504. (widen)
  6505. (goto-char pos)
  6506. (org-show-context 'agenda)
  6507. (org-show-entry)
  6508. (org-cycle-hide-drawers 'children)
  6509. (org-clock-in arg)
  6510. (setq newhead (org-get-heading)))
  6511. (org-agenda-change-all-lines newhead hdmarker)))))
  6512. (defun org-agenda-clock-out (&optional arg)
  6513. "Stop the currently running clock."
  6514. (interactive "P")
  6515. (unless (marker-buffer org-clock-marker)
  6516. (error "No running clock"))
  6517. (let ((marker (make-marker)) newhead)
  6518. (org-with-remote-undo (marker-buffer org-clock-marker)
  6519. (with-current-buffer (marker-buffer org-clock-marker)
  6520. (save-excursion
  6521. (save-restriction
  6522. (widen)
  6523. (goto-char org-clock-marker)
  6524. (org-back-to-heading t)
  6525. (move-marker marker (point))
  6526. (org-clock-out)
  6527. (setq newhead (org-get-heading))))))
  6528. (org-agenda-change-all-lines newhead marker)
  6529. (move-marker marker nil)))
  6530. (defun org-agenda-clock-cancel (&optional arg)
  6531. "Cancel the currently running clock."
  6532. (interactive "P")
  6533. (unless (marker-buffer org-clock-marker)
  6534. (error "No running clock"))
  6535. (org-with-remote-undo (marker-buffer org-clock-marker)
  6536. (org-clock-cancel)))
  6537. (defun org-agenda-diary-entry-in-org-file ()
  6538. "Make a diary entry in the file `org-agenda-diary-file'."
  6539. (let (d1 d2 char (text "") dp1 dp2)
  6540. (if (equal (buffer-name) "*Calendar*")
  6541. (setq d1 (calendar-cursor-to-date t)
  6542. d2 (car calendar-mark-ring))
  6543. (setq dp1 (get-text-property (point-at-bol) 'day))
  6544. (unless dp1 (error "No date defined in current line"))
  6545. (setq d1 (calendar-gregorian-from-absolute dp1)
  6546. d2 (and (ignore-errors (mark))
  6547. (save-excursion
  6548. (goto-char (mark))
  6549. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6550. (calendar-gregorian-from-absolute dp2))))
  6551. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6552. (setq char (read-char-exclusive))
  6553. (cond
  6554. ((equal char ?d)
  6555. (setq text (read-string "Day entry: "))
  6556. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6557. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6558. ((equal char ?a)
  6559. (setq d1 (list (car d1) (nth 1 d1)
  6560. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6561. (nth 2 d1))))
  6562. (setq text (read-string "Anniversary (use %d to show years): "))
  6563. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6564. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6565. ((equal char ?b)
  6566. (setq text (read-string "Block entry: "))
  6567. (unless (and d1 d2 (not (equal d1 d2)))
  6568. (error "No block of days selected"))
  6569. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6570. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6571. ((equal char ?j)
  6572. (org-switch-to-buffer-other-window
  6573. (find-file-noselect org-agenda-diary-file))
  6574. (require 'org-datetree)
  6575. (org-datetree-find-date-create d1)
  6576. (org-reveal t))
  6577. (t (error "Invalid selection character `%c'" char)))))
  6578. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6579. "Where in `org-agenda-diary-file' should new entries be added?
  6580. Valid values:
  6581. date-tree in the date tree, as child of the date
  6582. top-level as top-level entries at the end of the file."
  6583. :group 'org-agenda
  6584. :type '(choice
  6585. (const :tag "in a date tree" date-tree)
  6586. (const :tag "as top level at end of file" top-level)))
  6587. (defcustom org-agenda-insert-diary-extract-time nil
  6588. "Non-nil means extract any time specification from the diary entry."
  6589. :group 'org-agenda
  6590. :type 'boolean)
  6591. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6592. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6593. If TEXT is not empty, it will become the headline of the new entry, and
  6594. the resulting entry will not be shown. When TEXT is empty, switch to
  6595. `org-agenda-diary-file' and let the user finish the entry there."
  6596. (let ((cw (current-window-configuration)))
  6597. (org-switch-to-buffer-other-window
  6598. (find-file-noselect org-agenda-diary-file))
  6599. (widen)
  6600. (goto-char (point-min))
  6601. (cond
  6602. ((eq type 'anniversary)
  6603. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6604. (progn
  6605. (or (org-on-heading-p t)
  6606. (progn
  6607. (outline-next-heading)
  6608. (insert "* Anniversaries\n\n")
  6609. (beginning-of-line -1)))))
  6610. (outline-next-heading)
  6611. (org-back-over-empty-lines)
  6612. (backward-char 1)
  6613. (insert "\n")
  6614. (require 'diary-lib)
  6615. (let ((calendar-date-display-form
  6616. (if (if (boundp 'calendar-date-style)
  6617. (eq calendar-date-style 'european)
  6618. (org-bound-and-true-p european-calendar-style)) ; Emacs 22
  6619. '(day " " month " " year)
  6620. '(month " " day " " year))))
  6621. (insert (format "%%%%(diary-anniversary %s) %s"
  6622. (calendar-date-string d1 nil t) text))))
  6623. ((eq type 'day)
  6624. (let*
  6625. (fmt time time2
  6626. (org-agenda-time-leading-zero t))
  6627. (if org-agenda-insert-diary-extract-time
  6628. ;; Use org-format-agenda-item to parse text for a time-range and
  6629. ;; remove it.
  6630. (setq fmt (org-format-agenda-item nil text nil nil t)
  6631. time (get-text-property 0 'time fmt)
  6632. time2 (if (> (length time) 0)
  6633. ;; split-string removes trailing ...... if
  6634. ;; no end time given. First space
  6635. ;; separates time from date.
  6636. (concat " " (car (split-string time "\\.")))
  6637. nil)
  6638. text (get-text-property 0 'txt fmt)))
  6639. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6640. (org-agenda-insert-diary-as-top-level text)
  6641. (require 'org-datetree)
  6642. (org-datetree-find-date-create d1)
  6643. (org-agenda-insert-diary-make-new-entry text))
  6644. (org-insert-time-stamp (org-time-from-absolute
  6645. (calendar-absolute-from-gregorian d1))
  6646. nil nil nil nil time2))
  6647. (end-of-line 0))
  6648. ((eq type 'block)
  6649. (if (> (calendar-absolute-from-gregorian d1)
  6650. (calendar-absolute-from-gregorian d2))
  6651. (setq d1 (prog1 d2 (setq d2 d1))))
  6652. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6653. (org-agenda-insert-diary-as-top-level text)
  6654. (require 'org-datetree)
  6655. (org-datetree-find-date-create d1)
  6656. (org-agenda-insert-diary-make-new-entry text))
  6657. (org-insert-time-stamp (org-time-from-absolute
  6658. (calendar-absolute-from-gregorian d1)))
  6659. (insert "--")
  6660. (org-insert-time-stamp (org-time-from-absolute
  6661. (calendar-absolute-from-gregorian d2)))
  6662. (end-of-line 0)))
  6663. (if (string-match "\\S-" text)
  6664. (progn
  6665. (set-window-configuration cw)
  6666. (message "%s entry added to %s"
  6667. (capitalize (symbol-name type))
  6668. (abbreviate-file-name org-agenda-diary-file)))
  6669. (org-reveal t)
  6670. (message "Please finish entry here"))))
  6671. (defun org-agenda-insert-diary-as-top-level (text)
  6672. "Make new entry as a top-level entry at the end of the file.
  6673. Add TEXT as headline, and position the cursor in the second line so that
  6674. a timestamp can be added there."
  6675. (widen)
  6676. (goto-char (point-max))
  6677. (or (bolp) (insert "\n"))
  6678. (insert "* " text "\n")
  6679. (if org-adapt-indentation (org-indent-to-column 2)))
  6680. (defun org-agenda-insert-diary-make-new-entry (text)
  6681. "Make new entry as last child of current entry.
  6682. Add TEXT as headline, and position the cursor in the second line so that
  6683. a timestamp can be added there."
  6684. (let ((org-show-following-heading t)
  6685. (org-show-siblings t)
  6686. (org-show-hierarchy-above t)
  6687. (org-show-entry-below t)
  6688. col)
  6689. (outline-next-heading)
  6690. (org-back-over-empty-lines)
  6691. (or (looking-at "[ \t]*$")
  6692. (progn (insert "\n") (backward-char 1)))
  6693. (org-insert-heading nil t)
  6694. (org-do-demote)
  6695. (setq col (current-column))
  6696. (insert text "\n")
  6697. (if org-adapt-indentation (org-indent-to-column col))
  6698. (let ((org-show-following-heading t)
  6699. (org-show-siblings t)
  6700. (org-show-hierarchy-above t)
  6701. (org-show-entry-below t))
  6702. (org-show-context))))
  6703. (defun org-agenda-diary-entry ()
  6704. "Make a diary entry, like the `i' command from the calendar.
  6705. All the standard commands work: block, weekly etc.
  6706. When `org-agenda-diary-file' points to a file,
  6707. `org-agenda-diary-entry-in-org-file' is called instead to create
  6708. entries in that Org-mode file."
  6709. (interactive)
  6710. (org-agenda-check-type t 'agenda 'timeline)
  6711. (if (not (eq org-agenda-diary-file 'diary-file))
  6712. (org-agenda-diary-entry-in-org-file)
  6713. (require 'diary-lib)
  6714. (let* ((char (progn
  6715. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6716. (read-char-exclusive)))
  6717. (cmd (cdr (assoc char
  6718. '((?d . insert-diary-entry)
  6719. (?w . insert-weekly-diary-entry)
  6720. (?m . insert-monthly-diary-entry)
  6721. (?y . insert-yearly-diary-entry)
  6722. (?a . insert-anniversary-diary-entry)
  6723. (?b . insert-block-diary-entry)
  6724. (?c . insert-cyclic-diary-entry)))))
  6725. (oldf (symbol-function 'calendar-cursor-to-date))
  6726. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6727. (point (point))
  6728. (mark (or (mark t) (point))))
  6729. (unless cmd
  6730. (error "No command associated with <%c>" char))
  6731. (unless (and (get-text-property point 'day)
  6732. (or (not (equal ?b char))
  6733. (get-text-property mark 'day)))
  6734. (error "Don't know which date to use for diary entry"))
  6735. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6736. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6737. (let ((calendar-mark-ring
  6738. (list (calendar-gregorian-from-absolute
  6739. (or (get-text-property mark 'day)
  6740. (get-text-property point 'day))))))
  6741. (unwind-protect
  6742. (progn
  6743. (fset 'calendar-cursor-to-date
  6744. (lambda (&optional error dummy)
  6745. (calendar-gregorian-from-absolute
  6746. (get-text-property point 'day))))
  6747. (call-interactively cmd))
  6748. (fset 'calendar-cursor-to-date oldf))))))
  6749. (defun org-agenda-execute-calendar-command (cmd)
  6750. "Execute a calendar command from the agenda, with the date associated to
  6751. the cursor position."
  6752. (org-agenda-check-type t 'agenda 'timeline)
  6753. (require 'diary-lib)
  6754. (unless (get-text-property (point) 'day)
  6755. (error "Don't know which date to use for calendar command"))
  6756. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6757. (point (point))
  6758. (date (calendar-gregorian-from-absolute
  6759. (get-text-property point 'day)))
  6760. ;; the following 2 vars are needed in the calendar
  6761. (displayed-month (car date))
  6762. (displayed-year (nth 2 date)))
  6763. (unwind-protect
  6764. (progn
  6765. (fset 'calendar-cursor-to-date
  6766. (lambda (&optional error dummy)
  6767. (calendar-gregorian-from-absolute
  6768. (get-text-property point 'day))))
  6769. (call-interactively cmd))
  6770. (fset 'calendar-cursor-to-date oldf))))
  6771. (defun org-agenda-phases-of-moon ()
  6772. "Display the phases of the moon for the 3 months around the cursor date."
  6773. (interactive)
  6774. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6775. (defun org-agenda-holidays ()
  6776. "Display the holidays for the 3 months around the cursor date."
  6777. (interactive)
  6778. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6779. (defvar calendar-longitude)
  6780. (defvar calendar-latitude)
  6781. (defvar calendar-location-name)
  6782. (defun org-agenda-sunrise-sunset (arg)
  6783. "Display sunrise and sunset for the cursor date.
  6784. Latitude and longitude can be specified with the variables
  6785. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6786. argument, latitude and longitude will be prompted for."
  6787. (interactive "P")
  6788. (require 'solar)
  6789. (let ((calendar-longitude (if arg nil calendar-longitude))
  6790. (calendar-latitude (if arg nil calendar-latitude))
  6791. (calendar-location-name
  6792. (if arg "the given coordinates" calendar-location-name)))
  6793. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6794. (defun org-agenda-goto-calendar ()
  6795. "Open the Emacs calendar with the date at the cursor."
  6796. (interactive)
  6797. (org-agenda-check-type t 'agenda 'timeline)
  6798. (let* ((day (or (get-text-property (point) 'day)
  6799. (error "Don't know which date to open in calendar")))
  6800. (date (calendar-gregorian-from-absolute day))
  6801. (calendar-move-hook nil)
  6802. (calendar-view-holidays-initially-flag nil)
  6803. (calendar-view-diary-initially-flag nil)
  6804. (view-calendar-holidays-initially nil)
  6805. (view-diary-entries-initially nil))
  6806. (calendar)
  6807. (calendar-goto-date date)))
  6808. ;;;###autoload
  6809. (defun org-calendar-goto-agenda ()
  6810. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6811. This is a command that has to be installed in `calendar-mode-map'."
  6812. (interactive)
  6813. (org-agenda-list nil (calendar-absolute-from-gregorian
  6814. (calendar-cursor-to-date))
  6815. nil))
  6816. (defun org-agenda-convert-date ()
  6817. (interactive)
  6818. (org-agenda-check-type t 'agenda 'timeline)
  6819. (let ((day (get-text-property (point) 'day))
  6820. date s)
  6821. (unless day
  6822. (error "Don't know which date to convert"))
  6823. (setq date (calendar-gregorian-from-absolute day))
  6824. (setq s (concat
  6825. "Gregorian: " (calendar-date-string date) "\n"
  6826. "ISO: " (calendar-iso-date-string date) "\n"
  6827. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6828. "Julian: " (calendar-julian-date-string date) "\n"
  6829. "Astron. JD: " (calendar-astro-date-string date)
  6830. " (Julian date number at noon UTC)\n"
  6831. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6832. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6833. "French: " (calendar-french-date-string date) "\n"
  6834. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6835. "Mayan: " (calendar-mayan-date-string date) "\n"
  6836. "Coptic: " (calendar-coptic-date-string date) "\n"
  6837. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6838. "Persian: " (calendar-persian-date-string date) "\n"
  6839. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6840. (with-output-to-temp-buffer "*Dates*"
  6841. (princ s))
  6842. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6843. ;;; Bulk commands
  6844. (defvar org-agenda-bulk-marked-entries nil
  6845. "List of markers that refer to marked entries in the agenda.")
  6846. (defun org-agenda-bulk-marked-p ()
  6847. (eq (get-char-property (point-at-bol) 'type)
  6848. 'org-marked-entry-overlay))
  6849. (defun org-agenda-bulk-mark ()
  6850. "Mark the entry at point for future bulk action."
  6851. (interactive)
  6852. (org-agenda-check-no-diary)
  6853. (let* ((m (org-get-at-bol 'org-hd-marker))
  6854. ov)
  6855. (unless (org-agenda-bulk-marked-p)
  6856. (unless m (error "Nothing to mark at point"))
  6857. (push m org-agenda-bulk-marked-entries)
  6858. (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  6859. (org-overlay-display ov "> "
  6860. (org-get-todo-face "TODO")
  6861. 'evaporate)
  6862. (org-overlay-put ov 'type 'org-marked-entry-overlay))
  6863. (beginning-of-line 2)
  6864. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6865. (beginning-of-line 2))
  6866. (message "%d entries marked for bulk action"
  6867. (length org-agenda-bulk-marked-entries))))
  6868. (defun org-agenda-bulk-unmark ()
  6869. "Unmark the entry at point for future bulk action."
  6870. (interactive)
  6871. (when (org-agenda-bulk-marked-p)
  6872. (org-agenda-bulk-remove-overlays
  6873. (point-at-bol) (+ 2 (point-at-bol)))
  6874. (setq org-agenda-bulk-marked-entries
  6875. (delete (org-get-at-bol 'org-hd-marker)
  6876. org-agenda-bulk-marked-entries)))
  6877. (beginning-of-line 2)
  6878. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6879. (beginning-of-line 2))
  6880. (message "%d entries marked for bulk action"
  6881. (length org-agenda-bulk-marked-entries)))
  6882. (defun org-agenda-bulk-toggle ()
  6883. "Toggle marking the entry at point for bulk action."
  6884. (interactive)
  6885. (if (org-agenda-bulk-marked-p)
  6886. (org-agenda-bulk-unmark)
  6887. (org-agenda-bulk-mark)))
  6888. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  6889. "Remove the mark overlays between BEG and END in the agenda buffer.
  6890. BEG and END default to the buffer limits.
  6891. This only removes the overlays, it does not remove the markers
  6892. from the list in `org-agenda-bulk-marked-entries'."
  6893. (interactive)
  6894. (mapc (lambda (ov)
  6895. (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
  6896. (org-delete-overlay ov)))
  6897. (org-overlays-in (or beg (point-min)) (or end (point-max)))))
  6898. (defun org-agenda-bulk-remove-all-marks ()
  6899. "Remove all marks in the agenda buffer.
  6900. This will remove the markers, and the overlays."
  6901. (interactive)
  6902. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  6903. (setq org-agenda-bulk-marked-entries nil)
  6904. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  6905. (defun org-agenda-bulk-action (&optional arg)
  6906. "Execute an remote-editing action on all marked entries.
  6907. The prefix arg is passed through to the command if possible."
  6908. (interactive "P")
  6909. (unless org-agenda-bulk-marked-entries
  6910. (error "No entries are marked"))
  6911. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  6912. (let* ((action (read-char-exclusive))
  6913. (entries (reverse org-agenda-bulk-marked-entries))
  6914. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  6915. (cond
  6916. ((equal action ?$)
  6917. (setq cmd '(org-agenda-archive)))
  6918. ((equal action ?A)
  6919. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  6920. ((member action '(?r ?w))
  6921. (setq rfloc (org-refile-get-location
  6922. "Refile to: "
  6923. (marker-buffer (car org-agenda-bulk-marked-entries))
  6924. org-refile-allow-creating-parent-nodes))
  6925. (setcar (nthcdr 3 rfloc)
  6926. (move-marker (make-marker) (nth 3 rfloc)
  6927. (or (get-file-buffer (nth 1 rfloc))
  6928. (find-buffer-visiting (nth 1 rfloc))
  6929. (error "This should not happen"))))
  6930. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
  6931. ((equal action ?t)
  6932. (setq state (org-icompleting-read
  6933. "Todo state: "
  6934. (with-current-buffer (marker-buffer (car entries))
  6935. (mapcar 'list org-todo-keywords-1))))
  6936. (setq cmd `(let ((org-inhibit-blocking t)
  6937. (org-inhibit-logging 'note))
  6938. (org-agenda-todo ,state))))
  6939. ((memq action '(?- ?+))
  6940. (setq tag (org-icompleting-read
  6941. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  6942. (with-current-buffer (marker-buffer (car entries))
  6943. (delq nil
  6944. (mapcar (lambda (x)
  6945. (if (stringp (car x)) x)) org-tag-alist)))))
  6946. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  6947. ((memq action '(?s ?d))
  6948. (let* ((date (unless arg
  6949. (org-read-date
  6950. nil nil nil
  6951. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  6952. (ans (if arg nil org-read-date-final-answer))
  6953. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  6954. (setq cmd `(let* ((bound (fboundp 'read-string))
  6955. (old (and bound (symbol-function 'read-string))))
  6956. (unwind-protect
  6957. (progn
  6958. (fset 'read-string (lambda (&rest ignore) ,ans))
  6959. (eval '(,c1 arg)))
  6960. (if bound
  6961. (fset 'read-string old)
  6962. (fmakunbound 'read-string)))))))
  6963. (t (error "Invalid bulk action")))
  6964. ;; Sort the markers, to make sure that parents are handled before children
  6965. (setq entries (sort entries
  6966. (lambda (a b)
  6967. (cond
  6968. ((equal (marker-buffer a) (marker-buffer b))
  6969. (< (marker-position a) (marker-position b)))
  6970. (t
  6971. (string< (buffer-name (marker-buffer a))
  6972. (buffer-name (marker-buffer b))))))))
  6973. ;; Now loop over all markers and apply cmd
  6974. (while (setq e (pop entries))
  6975. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  6976. (if (not pos)
  6977. (progn (message "Skipping removed entry at %s" e)
  6978. (setq cntskip (1+ cntskip)))
  6979. (goto-char pos)
  6980. (eval cmd)
  6981. (setq org-agenda-bulk-marked-entries
  6982. (delete e org-agenda-bulk-marked-entries))
  6983. (setq cnt (1+ cnt))))
  6984. (setq org-agenda-bulk-marked-entries nil)
  6985. (org-agenda-bulk-remove-all-marks)
  6986. (message "Acted on %d entries%s"
  6987. cnt
  6988. (if (= cntskip 0)
  6989. ""
  6990. (format ", skipped %d (disappeared before their turn)"
  6991. cntskip)))))
  6992. ;;; Flagging notes
  6993. (defun org-agenda-show-the-flagging-note ()
  6994. "Display the flagging note in the other window.
  6995. When called a second time in direct sequence, offer to remove the FLAGGING
  6996. tag and (if present) the flagging note."
  6997. (interactive)
  6998. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  6999. (win (selected-window))
  7000. note heading newhead)
  7001. (unless hdmarker
  7002. (error "No linked entry at point"))
  7003. (if (and (eq this-command last-command)
  7004. (y-or-n-p "Unflag and remove any flagging note? "))
  7005. (progn
  7006. (org-agenda-remove-flag hdmarker)
  7007. (let ((win (get-buffer-window "*Flagging Note*")))
  7008. (and win (delete-window win)))
  7009. (message "Entry unflaged"))
  7010. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7011. (unless note
  7012. (error "No flagging note"))
  7013. (org-kill-new note)
  7014. (org-switch-to-buffer-other-window "*Flagging Note*")
  7015. (erase-buffer)
  7016. (insert note)
  7017. (goto-char (point-min))
  7018. (while (re-search-forward "\\\\n" nil t)
  7019. (replace-match "\n" t t))
  7020. (goto-char (point-min))
  7021. (select-window win)
  7022. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7023. (defun org-agenda-remove-flag (marker)
  7024. "Remove the FLAGGED tag and any flagging note in the entry."
  7025. (let (newhead)
  7026. (org-with-point-at marker
  7027. (org-toggle-tag "FLAGGED" 'off)
  7028. (org-entry-delete nil "THEFLAGGINGNOTE")
  7029. (setq newhead (org-get-heading)))
  7030. (org-agenda-change-all-lines newhead marker)
  7031. (message "Entry unflaged")))
  7032. (defun org-agenda-get-any-marker (&optional pos)
  7033. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7034. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7035. ;;; Appointment reminders
  7036. (defvar appt-time-msg-list)
  7037. ;;;###autoload
  7038. (defun org-agenda-to-appt (&optional refresh filter)
  7039. "Activate appointments found in `org-agenda-files'.
  7040. With a \\[universal-argument] prefix, refresh the list of
  7041. appointments.
  7042. If FILTER is t, interactively prompt the user for a regular
  7043. expression, and filter out entries that don't match it.
  7044. If FILTER is a string, use this string as a regular expression
  7045. for filtering entries out.
  7046. FILTER can also be an alist with the car of each cell being
  7047. either 'headline or 'category. For example:
  7048. '((headline \"IMPORTANT\")
  7049. (category \"Work\"))
  7050. will only add headlines containing IMPORTANT or headlines
  7051. belonging to the \"Work\" category."
  7052. (interactive "P")
  7053. (require 'calendar)
  7054. (if refresh (setq appt-time-msg-list nil))
  7055. (if (eq filter t)
  7056. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7057. (let* ((cnt 0) ; count added events
  7058. (org-agenda-new-buffers nil)
  7059. (org-deadline-warning-days 0)
  7060. (today (org-date-to-gregorian
  7061. (time-to-days (current-time))))
  7062. (org-agenda-restrict nil)
  7063. (files (org-agenda-files 'unrestricted)) entries file)
  7064. ;; Get all entries which may contain an appt
  7065. (org-prepare-agenda-buffers files)
  7066. (while (setq file (pop files))
  7067. (setq entries
  7068. (append entries
  7069. (org-agenda-get-day-entries
  7070. file today :timestamp :scheduled :deadline))))
  7071. (setq entries (delq nil entries))
  7072. ;; Map thru entries and find if we should filter them out
  7073. (mapc
  7074. (lambda(x)
  7075. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7076. (cat (get-text-property 1 'org-category x))
  7077. (tod (get-text-property 1 'time-of-day x))
  7078. (ok (or (null filter)
  7079. (and (stringp filter) (string-match filter evt))
  7080. (and (listp filter)
  7081. (or (string-match
  7082. (cadr (assoc 'category filter)) cat)
  7083. (string-match
  7084. (cadr (assoc 'headline filter)) evt))))))
  7085. ;; FIXME: Shall we remove text-properties for the appt text?
  7086. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7087. (when (and ok tod)
  7088. (setq tod (concat "00" (number-to-string tod))
  7089. tod (when (string-match
  7090. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7091. (concat (match-string 1 tod) ":"
  7092. (match-string 2 tod))))
  7093. (appt-add tod evt)
  7094. (setq cnt (1+ cnt))))) entries)
  7095. (org-release-buffers org-agenda-new-buffers)
  7096. (if (eq cnt 0)
  7097. (message "No event to add")
  7098. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7099. (defun org-agenda-todayp (date)
  7100. "Does DATE mean today, when considering `org-extend-today-until'?"
  7101. (let (today h)
  7102. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7103. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7104. (setq h (nth 2 (decode-time (current-time))))
  7105. (or (and (>= h org-extend-today-until)
  7106. (= date today))
  7107. (and (< h org-extend-today-until)
  7108. (= date (1- today))))))
  7109. (provide 'org-agenda)
  7110. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7111. ;;; org-agenda.el ends here