org-agenda.el 292 KB

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