org-agenda.el 292 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661
  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.35e
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl)
  29. (require 'calendar))
  30. (declare-function diary-add-to-list "diary-lib"
  31. (date string specifier &optional marker globcolor literal))
  32. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  33. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  34. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  35. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  36. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  38. (declare-function calendar-french-date-string "cal-french" (&optional date))
  39. (declare-function calendar-goto-date "cal-move" (date))
  40. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  41. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  42. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  43. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  44. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  45. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  46. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  47. (declare-function org-datetree-find-date-create "org-datetree"
  48. (date &optional keep-restriction))
  49. (declare-function org-columns-quit "org-colview" ())
  50. (declare-function diary-date-display-form "diary-lib" (&optional type))
  51. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  52. (declare-function org-habit-insert-consistency-graphs
  53. "org-habit" (&optional line))
  54. (declare-function org-is-habit-p "org-habit" (&optional pom))
  55. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  56. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  57. (defvar calendar-mode-map)
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see org-agenda-entry-text-mode and the
  128. variable `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defgroup org-agenda-custom-commands nil
  176. "Options concerning agenda views in Org-mode."
  177. :tag "Org Agenda Custom Commands"
  178. :group 'org-agenda)
  179. (defconst org-sorting-choice
  180. '(choice
  181. (const time-up) (const time-down)
  182. (const category-keep) (const category-up) (const category-down)
  183. (const tag-down) (const tag-up)
  184. (const priority-up) (const priority-down)
  185. (const todo-state-up) (const todo-state-down)
  186. (const effort-up) (const effort-down)
  187. (const habit-up) (const habit-down)
  188. (const user-defined-up) (const user-defined-down))
  189. "Sorting choices.")
  190. (defconst org-agenda-custom-commands-local-options
  191. `(repeat :tag "Local settings for this command. Remember to quote values"
  192. (choice :tag "Setting"
  193. (list :tag "Heading for this block"
  194. (const org-agenda-overriding-header)
  195. (string :tag "Headline"))
  196. (list :tag "Files to be searched"
  197. (const org-agenda-files)
  198. (list
  199. (const :format "" quote)
  200. (repeat (file))))
  201. (list :tag "Sorting strategy"
  202. (const org-agenda-sorting-strategy)
  203. (list
  204. (const :format "" quote)
  205. (repeat
  206. ,org-sorting-choice)))
  207. (list :tag "Prefix format"
  208. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  209. (string))
  210. (list :tag "Number of days in agenda"
  211. (const org-agenda-ndays)
  212. (integer :value 1))
  213. (list :tag "Fixed starting date"
  214. (const org-agenda-start-day)
  215. (string :value "2007-11-01"))
  216. (list :tag "Start on day of week"
  217. (const org-agenda-start-on-weekday)
  218. (choice :value 1
  219. (const :tag "Today" nil)
  220. (integer :tag "Weekday No.")))
  221. (list :tag "Include data from diary"
  222. (const org-agenda-include-diary)
  223. (boolean))
  224. (list :tag "Deadline Warning days"
  225. (const org-deadline-warning-days)
  226. (integer :value 1))
  227. (list :tag "Tags filter preset"
  228. (const org-agenda-filter-preset)
  229. (list
  230. (const :format "" quote)
  231. (repeat
  232. (string :tag "+tag or -tag"))))
  233. (list :tag "Set daily/weekly entry types"
  234. (const org-agenda-entry-types)
  235. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  236. (const :deadline)
  237. (const :scheduled)
  238. (const :timestamp)
  239. (const :sexp)))
  240. (list :tag "Standard skipping condition"
  241. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  242. (const org-agenda-skip-function)
  243. (list
  244. (const :format "" quote)
  245. (list
  246. (choice
  247. :tag "Skipping range"
  248. (const :tag "Skip entry" org-agenda-skip-entry-if)
  249. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  250. (repeat :inline t :tag "Conditions for skipping"
  251. (choice
  252. :tag "Condition type"
  253. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  254. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  255. (list :tag "TODO state is" :inline t
  256. (const 'todo)
  257. (choice
  258. (const :tag "any not-done state" 'todo)
  259. (const :tag "any done state" 'done)
  260. (const :tag "any state" 'any)
  261. (list :tag "Keyword list"
  262. (const :format "" quote)
  263. (repeat (string :tag "Keyword")))))
  264. (list :tag "TODO state is not" :inline t
  265. (const 'nottodo)
  266. (choice
  267. (const :tag "any not-done state" 'todo)
  268. (const :tag "any done state" 'done)
  269. (const :tag "any state" 'any)
  270. (list :tag "Keyword list"
  271. (const :format "" quote)
  272. (repeat (string :tag "Keyword")))))
  273. (const :tag "scheduled" 'scheduled)
  274. (const :tag "not scheduled" 'notscheduled)
  275. (const :tag "deadline" 'deadline)
  276. (const :tag "no deadline" 'notdeadline)
  277. (const :tag "timestamp" 'timestamp)
  278. (const :tag "no timestamp" 'nottimestamp))))))
  279. (list :tag "Non-standard skipping condition"
  280. :value (org-agenda-skip-function)
  281. (const org-agenda-skip-function)
  282. (sexp :tag "Function or form (quoted!)"))
  283. (list :tag "Any variable"
  284. (variable :tag "Variable")
  285. (sexp :tag "Value (sexp)"))))
  286. "Selection of examples for agenda command settings.
  287. This will be spliced into the custom type of
  288. `org-agenda-custom-commands'.")
  289. (defcustom org-agenda-custom-commands nil
  290. "Custom commands for the agenda.
  291. These commands will be offered on the splash screen displayed by the
  292. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  293. (key desc type match settings files)
  294. key The key (one or more characters as a string) to be associated
  295. with the command.
  296. desc A description of the command, when omitted or nil, a default
  297. description is built using MATCH.
  298. type The command type, any of the following symbols:
  299. agenda The daily/weekly agenda.
  300. todo Entries with a specific TODO keyword, in all agenda files.
  301. search Entries containing search words entry or headline.
  302. tags Tags/Property/TODO match in all agenda files.
  303. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  304. todo-tree Sparse tree of specific TODO keyword in *current* file.
  305. tags-tree Sparse tree with all tags matches in *current* file.
  306. occur-tree Occur sparse tree for *current* file.
  307. ... A user-defined function.
  308. match What to search for:
  309. - a single keyword for TODO keyword searches
  310. - a tags match expression for tags searches
  311. - a word search expression for text searches.
  312. - a regular expression for occur searches
  313. For all other commands, this should be the empty string.
  314. settings A list of option settings, similar to that in a let form, so like
  315. this: ((opt1 val1) (opt2 val2) ...). The values will be
  316. evaluated at the moment of execution, so quote them when needed.
  317. files A list of files file to write the produced agenda buffer to
  318. with the command `org-store-agenda-views'.
  319. If a file name ends in \".html\", an HTML version of the buffer
  320. is written out. If it ends in \".ps\", a postscript version is
  321. produced. Otherwise, only the plain text is written to the file.
  322. You can also define a set of commands, to create a composite agenda buffer.
  323. In this case, an entry looks like this:
  324. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  325. where
  326. desc A description string to be displayed in the dispatcher menu.
  327. cmd An agenda command, similar to the above. However, tree commands
  328. are no allowed, but instead you can get agenda and global todo list.
  329. So valid commands for a set are:
  330. (agenda \"\" settings)
  331. (alltodo \"\" settings)
  332. (stuck \"\" settings)
  333. (todo \"match\" settings files)
  334. (search \"match\" settings files)
  335. (tags \"match\" settings files)
  336. (tags-todo \"match\" settings files)
  337. Each command can carry a list of options, and another set of options can be
  338. given for the whole set of commands. Individual command options take
  339. precedence over the general options.
  340. When using several characters as key to a command, the first characters
  341. are prefix commands. For the dispatcher to display useful information, you
  342. should provide a description for the prefix, like
  343. (setq org-agenda-custom-commands
  344. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  345. (\"hl\" tags \"+HOME+Lisa\")
  346. (\"hp\" tags \"+HOME+Peter\")
  347. (\"hk\" tags \"+HOME+Kim\")))"
  348. :group 'org-agenda-custom-commands
  349. :type `(repeat
  350. (choice :value ("x" "Describe command here" tags "" nil)
  351. (list :tag "Single command"
  352. (string :tag "Access Key(s) ")
  353. (option (string :tag "Description"))
  354. (choice
  355. (const :tag "Agenda" agenda)
  356. (const :tag "TODO list" alltodo)
  357. (const :tag "Search words" search)
  358. (const :tag "Stuck projects" stuck)
  359. (const :tag "Tags/Property match (all agenda files)" tags)
  360. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  361. (const :tag "TODO keyword search (all agenda files)" todo)
  362. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  363. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  364. (const :tag "Occur tree (current buffer)" occur-tree)
  365. (sexp :tag "Other, user-defined function"))
  366. (string :tag "Match (only for some commands)")
  367. ,org-agenda-custom-commands-local-options
  368. (option (repeat :tag "Export" (file :tag "Export to"))))
  369. (list :tag "Command series, all agenda files"
  370. (string :tag "Access Key(s)")
  371. (string :tag "Description ")
  372. (repeat :tag "Component"
  373. (choice
  374. (list :tag "Agenda"
  375. (const :format "" agenda)
  376. (const :tag "" :format "" "")
  377. ,org-agenda-custom-commands-local-options)
  378. (list :tag "TODO list (all keywords)"
  379. (const :format "" alltodo)
  380. (const :tag "" :format "" "")
  381. ,org-agenda-custom-commands-local-options)
  382. (list :tag "Search words"
  383. (const :format "" search)
  384. (string :tag "Match")
  385. ,org-agenda-custom-commands-local-options)
  386. (list :tag "Stuck projects"
  387. (const :format "" stuck)
  388. (const :tag "" :format "" "")
  389. ,org-agenda-custom-commands-local-options)
  390. (list :tag "Tags search"
  391. (const :format "" tags)
  392. (string :tag "Match")
  393. ,org-agenda-custom-commands-local-options)
  394. (list :tag "Tags search, TODO entries only"
  395. (const :format "" tags-todo)
  396. (string :tag "Match")
  397. ,org-agenda-custom-commands-local-options)
  398. (list :tag "TODO keyword search"
  399. (const :format "" todo)
  400. (string :tag "Match")
  401. ,org-agenda-custom-commands-local-options)
  402. (list :tag "Other, user-defined function"
  403. (symbol :tag "function")
  404. (string :tag "Match")
  405. ,org-agenda-custom-commands-local-options)))
  406. (repeat :tag "Settings for entire command set"
  407. (list (variable :tag "Any variable")
  408. (sexp :tag "Value")))
  409. (option (repeat :tag "Export" (file :tag "Export to"))))
  410. (cons :tag "Prefix key documentation"
  411. (string :tag "Access Key(s)")
  412. (string :tag "Description ")))))
  413. (defcustom org-agenda-query-register ?o
  414. "The register holding the current query string.
  415. The purpose of this is that if you construct a query string interactively,
  416. you can then use it to define a custom command."
  417. :group 'org-agenda-custom-commands
  418. :type 'character)
  419. (defcustom org-stuck-projects
  420. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  421. "How to identify stuck projects.
  422. This is a list of four items:
  423. 1. A tags/todo/property matcher string that is used to identify a project.
  424. See the manual for a description of tag and property searches.
  425. The entire tree below a headline matched by this is considered one project.
  426. 2. A list of TODO keywords identifying non-stuck projects.
  427. If the project subtree contains any headline with one of these todo
  428. keywords, the project is considered to be not stuck. If you specify
  429. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  430. 3. A list of tags identifying non-stuck projects.
  431. If the project subtree contains any headline with one of these tags,
  432. the project is considered to be not stuck. If you specify \"*\" as
  433. a tag, any tag will mark the project unstuck. Note that this is about
  434. the explicit presence of a tag somewhere in the subtree, inherited
  435. tags to not count here. If inherited tags make a project not stuck,
  436. use \"-TAG\" in the tags part of the matcher under (1.) above.
  437. 4. An arbitrary regular expression matching non-stuck projects.
  438. If the project turns out to be not stuck, search continues also in the
  439. subtree to see if any of the subtasks have project status.
  440. See also the variable `org-tags-match-list-sublevels' which applies
  441. to projects matched by this search as well.
  442. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  443. or `C-c a #' to produce the list."
  444. :group 'org-agenda-custom-commands
  445. :type '(list
  446. (string :tag "Tags/TODO match to identify a project")
  447. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  448. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  449. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  450. (defcustom org-agenda-filter-effort-default-operator "<"
  451. "The default operator for effort estimate filtering.
  452. If you select an effort estimate limit without first pressing an operator,
  453. this one will be used."
  454. :group 'org-agenda-custom-commands
  455. :type '(choice (const :tag "less or equal" "<")
  456. (const :tag "greater or equal"">")
  457. (const :tag "equal" "=")))
  458. (defgroup org-agenda-skip nil
  459. "Options concerning skipping parts of agenda files."
  460. :tag "Org Agenda Skip"
  461. :group 'org-agenda)
  462. (defgroup org-agenda-daily/weekly nil
  463. "Options concerning the daily/weekly agenda."
  464. :tag "Org Agenda Daily/Weekly"
  465. :group 'org-agenda)
  466. (defgroup org-agenda-todo-list nil
  467. "Options concerning the global todo list agenda view."
  468. :tag "Org Agenda Todo List"
  469. :group 'org-agenda)
  470. (defgroup org-agenda-match-view nil
  471. "Options concerning the general tags/property/todo match agenda view."
  472. :tag "Org Agenda Match View"
  473. :group 'org-agenda)
  474. (defgroup org-agenda-search-view nil
  475. "Options concerning the general tags/property/todo match agenda view."
  476. :tag "Org Agenda Match View"
  477. :group 'org-agenda)
  478. (defvar org-agenda-archives-mode nil
  479. "Non-nil means the agenda will include archived items.
  480. If this is the symbol `trees', trees in the selected agenda scope
  481. that are marked with the ARCHIVE tag will be included anyway. When this is
  482. t, also all archive files associated with the current selection of agenda
  483. files will be included.")
  484. (defcustom org-agenda-skip-comment-trees t
  485. "Non-nil means skip trees that start with the COMMENT keyword.
  486. When nil, these trees are also scanned by agenda commands."
  487. :group 'org-agenda-skip
  488. :type 'boolean)
  489. (defcustom org-agenda-todo-list-sublevels t
  490. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  491. When nil, the sublevels of a TODO entry are not checked, resulting in
  492. potentially much shorter TODO lists."
  493. :group 'org-agenda-skip
  494. :group 'org-agenda-todo-list
  495. :type 'boolean)
  496. (defcustom org-agenda-todo-ignore-with-date nil
  497. "Non-nil means don't show entries with a date in the global todo list.
  498. You can use this if you prefer to mark mere appointments with a TODO keyword,
  499. but don't want them to show up in the TODO list.
  500. When this is set, it also covers deadlines and scheduled items, the settings
  501. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  502. will be ignored.
  503. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  504. :group 'org-agenda-skip
  505. :group 'org-agenda-todo-list
  506. :type 'boolean)
  507. (defcustom org-agenda-todo-ignore-scheduled nil
  508. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  509. This applies when creating the global todo list.
  510. Valid values are:
  511. past Don't show entries scheduled today or in the past.
  512. future Don't show entries scheduled in the future.
  513. The idea behind this is that by scheduling it, you don't want to
  514. think about it until the scheduled date.
  515. all Don't show any scheduled entries in the global todo list.
  516. The idea behind this is that by scheduling it, you have already
  517. \"taken care\" of this item.
  518. t Same as `all', for backward compatibility.
  519. See also `org-agenda-todo-ignore-with-date'.
  520. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  521. to make his option also apply to the tags-todo list."
  522. :group 'org-agenda-skip
  523. :group 'org-agenda-todo-list
  524. :type '(choice
  525. (const :tag "Ignore future-scheduled todos" future)
  526. (const :tag "Ignore past- or present-scheduled todos" past)
  527. (const :tag "Ignore all scheduled todos" all)
  528. (const :tag "Ignore all scheduled todos (compatibility)" t)
  529. (const :tag "Show scheduled todos" nil)))
  530. (defcustom org-agenda-todo-ignore-deadlines nil
  531. "Non-nil means ignore some deadlined TODO items when making TODO list.
  532. There are different motivations for using different values, please think
  533. carefully when configuring this variable.
  534. This applie when creating the global todo list.
  535. Valid values are:
  536. near Don't show near deadline entries. A deadline is near when it is
  537. closer than `org-deadline-warning-days' days. The idea behind this
  538. is that such items will appear in the agenda anyway.
  539. far Don't show TODO entries where a deadline has been defined, but
  540. the deadline is not near. This is useful if you don't want to
  541. use the todo list to figure out what to do now.
  542. past Don't show entries with a deadline timestamp for today or in the past.
  543. future Don't show entries with a deadline timestamp in the future, not even
  544. when they become `near' ones. Use it with caution.
  545. all Ignore all TODO entries that do have a deadline.
  546. t Same as `near', for backward compatibility.
  547. See also `org-agenda-todo-ignore-with-date'.
  548. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  549. to make his option also apply to the tags-todo list."
  550. :group 'org-agenda-skip
  551. :group 'org-agenda-todo-list
  552. :type '(choice
  553. (const :tag "Ignore near deadlines" near)
  554. (const :tag "Ignore near deadlines (compatibility)" t)
  555. (const :tag "Ignore far deadlines" far)
  556. (const :tag "Ignore all TODOs with a deadlines" all)
  557. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  558. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  559. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  560. The variables
  561. `org-agenda-todo-ignore-with-date',
  562. `org-agenda-todo-ignore-scheduled'
  563. `org-agenda-todo-ignore-deadlines'
  564. make the global TODO list skip entries that have time stamps of certain
  565. kinds. If this option is set, the same options will also apply for the
  566. tags-todo search, which is the general tags/property matcher
  567. restricted to unfinished TODO entries only."
  568. :group 'org-agenda-skip
  569. :group 'org-agenda-todo-list
  570. :group 'org-agenda-match-view
  571. :type 'boolean)
  572. (defcustom org-agenda-skip-scheduled-if-done nil
  573. "Non-nil means don't show scheduled items in agenda when they are done.
  574. This is relevant for the daily/weekly agenda, not for the TODO list. And
  575. it applies only to the actual date of the scheduling. Warnings about
  576. an item with a past scheduling dates are always turned off when the item
  577. is DONE."
  578. :group 'org-agenda-skip
  579. :group 'org-agenda-daily/weekly
  580. :type 'boolean)
  581. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  582. "Non-nil means skip scheduling line if same entry shows because of deadline.
  583. In the agenda of today, an entry can show up multiple times because
  584. it is both scheduled and has a nearby deadline, and maybe a plain time
  585. stamp as well.
  586. When this variable is t, then only the deadline is shown and the fact that
  587. the entry is scheduled today or was scheduled previously is not shown.
  588. When this variable is nil, the entry will be shown several times. When
  589. the variable is the symbol `not-today', then skip scheduled previously,
  590. but not scheduled today."
  591. :group 'org-agenda-skip
  592. :group 'org-agenda-daily/weekly
  593. :type '(choice
  594. (const :tag "Never" nil)
  595. (const :tag "Always" t)
  596. (const :tag "Not when scheduled today" not-today)))
  597. (defcustom org-agenda-skip-deadline-if-done nil
  598. "Non-nil means don't show deadlines when the corresponding item is done.
  599. When nil, the deadline is still shown and should give you a happy feeling.
  600. This is relevant for the daily/weekly agenda. And it applied only to the
  601. actually date of the deadline. Warnings about approaching and past-due
  602. deadlines are always turned off when the item is DONE."
  603. :group 'org-agenda-skip
  604. :group 'org-agenda-daily/weekly
  605. :type 'boolean)
  606. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  607. "Non-nil means skip deadline prewarning when entry is also scheduled.
  608. This will apply on all days where a prewarning for the deadline would
  609. be shown, but not at the day when the entry is actually due. On that day,
  610. the deadline will be shown anyway.
  611. This variable may be set to nil, t, or a number which will then give
  612. the number of days before the actual deadline when the prewarnings
  613. should resume.
  614. This can be used in a workflow where the first showing of the deadline will
  615. trigger you to schedule it, and then you don't want to be reminded of it
  616. because you will take care of it on the day when scheduled."
  617. :group 'org-agenda-skip
  618. :group 'org-agenda-daily/weekly
  619. :type '(choice
  620. (const :tag "Alwas show prewarning" nil)
  621. (const :tag "Remove prewarning if entry is scheduled" t)
  622. (integer :tag "Restart prewarning N days before deadline")))
  623. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  624. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  625. When non-nil, after the search for timestamps has matched once in an
  626. entry, the rest of the entry will not be searched."
  627. :group 'org-agenda-skip
  628. :type 'boolean)
  629. (defcustom org-agenda-skip-timestamp-if-done nil
  630. "Non-nil means don't select item by timestamp or -range if it is DONE."
  631. :group 'org-agenda-skip
  632. :group 'org-agenda-daily/weekly
  633. :type 'boolean)
  634. (defcustom org-agenda-dim-blocked-tasks t
  635. "Non-nil means dim blocked tasks in the agenda display.
  636. This causes some overhead during agenda construction, but if you
  637. have turned on `org-enforce-todo-dependencies',
  638. `org-enforce-todo-checkbox-dependencies', or any other blocking
  639. mechanism, this will create useful feedback in the agenda.
  640. Instead of t, this variable can also have the value `invisible'.
  641. Then blocked tasks will be invisible and only become visible when
  642. they become unblocked. An exemption to this behavior is when a task is
  643. blocked because of unchecked checkboxes below it. Since checkboxes do
  644. not show up in the agenda views, making this task invisible you remove any
  645. trace from agenda views that there is something to do. Therefore, a task
  646. that is blocked because of checkboxes will never be made invisible, it
  647. will only be dimmed."
  648. :group 'org-agenda-daily/weekly
  649. :group 'org-agenda-todo-list
  650. :type '(choice
  651. (const :tag "Do not dim" nil)
  652. (const :tag "Dim to a grey face" t)
  653. (const :tag "Make invisible" invisible)))
  654. (defcustom org-timeline-show-empty-dates 3
  655. "Non-nil means `org-timeline' also shows dates without an entry.
  656. When nil, only the days which actually have entries are shown.
  657. When t, all days between the first and the last date are shown.
  658. When an integer, show also empty dates, but if there is a gap of more than
  659. N days, just insert a special line indicating the size of the gap."
  660. :group 'org-agenda-skip
  661. :type '(choice
  662. (const :tag "None" nil)
  663. (const :tag "All" t)
  664. (integer :tag "at most")))
  665. (defgroup org-agenda-startup nil
  666. "Options concerning initial settings in the Agenda in Org Mode."
  667. :tag "Org Agenda Startup"
  668. :group 'org-agenda)
  669. (defcustom org-finalize-agenda-hook nil
  670. "Hook run just before displaying an agenda buffer."
  671. :group 'org-agenda-startup
  672. :type 'hook)
  673. (defcustom org-agenda-mouse-1-follows-link nil
  674. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  675. A longer mouse click will still set point. Does not work on XEmacs.
  676. Needs to be set before org.el is loaded."
  677. :group 'org-agenda-startup
  678. :type 'boolean)
  679. (defcustom org-agenda-start-with-follow-mode nil
  680. "The initial value of follow-mode in a newly created agenda window."
  681. :group 'org-agenda-startup
  682. :type 'boolean)
  683. (defcustom org-agenda-show-outline-path t
  684. "Non-nil means show outline path in echo area after line motion."
  685. :group 'org-agenda-startup
  686. :type 'boolean)
  687. (defcustom org-agenda-start-with-entry-text-mode nil
  688. "The initial value of entry-text-mode in a newly created agenda window."
  689. :group 'org-agenda-startup
  690. :type 'boolean)
  691. (defcustom org-agenda-entry-text-maxlines 5
  692. "Number of text lines to be added when `E' is pressed in the agenda.
  693. Note that this variable only used during agenda display. Add add entry text
  694. when exporting the agenda, configure the variable
  695. `org-agenda-add-entry-ext-maxlines'."
  696. :group 'org-agenda
  697. :type 'integer)
  698. (defcustom org-agenda-entry-text-exclude-regexps nil
  699. "List of regular expressions to clean up entry text.
  700. The complete matches of all regular expressions in this list will be
  701. removed from entry text before it is shown in the agenda."
  702. :group 'org-agenda
  703. :type '(repeat (regexp)))
  704. (defvar org-agenda-entry-text-cleanup-hook nil
  705. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  706. This cleanup is done in a temporary buffer, so the function may inspect and
  707. change the entire buffer.
  708. Some default stuff like drawers and scheduling/deadline dates will already
  709. have been removed when this is called, as will any matches for regular
  710. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  711. (defvar org-agenda-include-inactive-timestamps nil
  712. "Non-nil means include inactive time stamps in agenda and timeline.")
  713. (defgroup org-agenda-windows nil
  714. "Options concerning the windows used by the Agenda in Org Mode."
  715. :tag "Org Agenda Windows"
  716. :group 'org-agenda)
  717. (defcustom org-agenda-window-setup 'reorganize-frame
  718. "How the agenda buffer should be displayed.
  719. Possible values for this option are:
  720. current-window Show agenda in the current window, keeping all other windows.
  721. other-window Use `switch-to-buffer-other-window' to display agenda.
  722. reorganize-frame Show only two windows on the current frame, the current
  723. window and the agenda.
  724. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  725. Also, when exiting the agenda, kill that frame.
  726. See also the variable `org-agenda-restore-windows-after-quit'."
  727. :group 'org-agenda-windows
  728. :type '(choice
  729. (const current-window)
  730. (const other-frame)
  731. (const other-window)
  732. (const reorganize-frame)))
  733. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  734. "The min and max height of the agenda window as a fraction of frame height.
  735. The value of the variable is a cons cell with two numbers between 0 and 1.
  736. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  737. :group 'org-agenda-windows
  738. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  739. (defcustom org-agenda-restore-windows-after-quit nil
  740. "Non-nil means restore window configuration open exiting agenda.
  741. Before the window configuration is changed for displaying the agenda,
  742. the current status is recorded. When the agenda is exited with
  743. `q' or `x' and this option is set, the old state is restored. If
  744. `org-agenda-window-setup' is `other-frame', the value of this
  745. option will be ignored."
  746. :group 'org-agenda-windows
  747. :type 'boolean)
  748. (defcustom org-agenda-ndays 7
  749. "Number of days to include in overview display.
  750. Should be 1 or 7.
  751. Custom commands can set this variable in the options section."
  752. :group 'org-agenda-daily/weekly
  753. :type 'integer)
  754. (defcustom org-agenda-start-on-weekday 1
  755. "Non-nil means start the overview always on the specified weekday.
  756. 0 denotes Sunday, 1 denotes Monday etc.
  757. When nil, always start on the current day.
  758. Custom commands can set this variable in the options section."
  759. :group 'org-agenda-daily/weekly
  760. :type '(choice (const :tag "Today" nil)
  761. (integer :tag "Weekday No.")))
  762. (defcustom org-agenda-show-all-dates t
  763. "Non-nil means `org-agenda' shows every day in the selected range.
  764. When nil, only the days which actually have entries are shown."
  765. :group 'org-agenda-daily/weekly
  766. :type 'boolean)
  767. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  768. "Format string for displaying dates in the agenda.
  769. Used by the daily/weekly agenda and by the timeline. This should be
  770. a format string understood by `format-time-string', or a function returning
  771. the formatted date as a string. The function must take a single argument,
  772. a calendar-style date list like (month day year)."
  773. :group 'org-agenda-daily/weekly
  774. :type '(choice
  775. (string :tag "Format string")
  776. (function :tag "Function")))
  777. (defun org-agenda-format-date-aligned (date)
  778. "Format a date string for display in the daily/weekly agenda, or timeline.
  779. This function makes sure that dates are aligned for easy reading."
  780. (require 'cal-iso)
  781. (let* ((dayname (calendar-day-name date))
  782. (day (cadr date))
  783. (day-of-week (calendar-day-of-week date))
  784. (month (car date))
  785. (monthname (calendar-month-name month))
  786. (year (nth 2 date))
  787. (iso-week (org-days-to-iso-week
  788. (calendar-absolute-from-gregorian date)))
  789. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  790. (1- year))
  791. ((and (= month 12) (<= iso-week 1))
  792. (1+ year))
  793. (t year)))
  794. (weekstring (if (= day-of-week 1)
  795. (format " W%02d" iso-week)
  796. "")))
  797. (format "%-10s %2d %s %4d%s"
  798. dayname day monthname year weekstring)))
  799. (defcustom org-agenda-time-leading-zero nil
  800. "Non-nil means use leading zero for military times in agenda.
  801. For example, 9:30am would become 09:30 rather than 9:30."
  802. :group 'org-agenda-daily/weekly
  803. :type 'boolean)
  804. (defcustom org-agenda-weekend-days '(6 0)
  805. "Which days are weekend?
  806. These days get the special face `org-agenda-date-weekend' in the agenda
  807. and timeline buffers."
  808. :group 'org-agenda-daily/weekly
  809. :type '(set :greedy t
  810. (const :tag "Monday" 1)
  811. (const :tag "Tuesday" 2)
  812. (const :tag "Wednesday" 3)
  813. (const :tag "Thursday" 4)
  814. (const :tag "Friday" 5)
  815. (const :tag "Saturday" 6)
  816. (const :tag "Sunday" 0)))
  817. (defcustom org-agenda-include-diary nil
  818. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  819. Custom commands can set this variable in the options section."
  820. :group 'org-agenda-daily/weekly
  821. :type 'boolean)
  822. (defcustom org-agenda-include-deadlines t
  823. "If non-nil, include entries within their deadline warning period.
  824. Custom commands can set this variable in the options section."
  825. :group 'org-agenda-daily/weekly
  826. :type 'boolean)
  827. (defcustom org-agenda-include-all-todo nil
  828. "Set means weekly/daily agenda will always contain all TODO entries.
  829. The TODO entries will be listed at the top of the agenda, before
  830. the entries for specific days.
  831. This option is deprecated, it is better to define a block agenda instead."
  832. :group 'org-agenda-daily/weekly
  833. :type 'boolean)
  834. (defcustom org-agenda-repeating-timestamp-show-all t
  835. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  836. When nil, only one occurrence is shown, either today or the
  837. nearest into the future."
  838. :group 'org-agenda-daily/weekly
  839. :type 'boolean)
  840. (defcustom org-scheduled-past-days 10000
  841. "No. of days to continue listing scheduled items that are not marked DONE.
  842. When an item is scheduled on a date, it shows up in the agenda on this
  843. day and will be listed until it is marked done for the number of days
  844. given here."
  845. :group 'org-agenda-daily/weekly
  846. :type 'integer)
  847. (defcustom org-agenda-log-mode-items '(closed clock)
  848. "List of items that should be shown in agenda log mode.
  849. This list may contain the following symbols:
  850. closed Show entries that have been closed on that day.
  851. clock Show entries that have received clocked time on that day.
  852. state Show all logged state changes.
  853. Note that instead of changing this variable, you can also press `C-u l' in
  854. the agenda to display all available LOG items temporarily."
  855. :group 'org-agenda-daily/weekly
  856. :type '(set :greedy t (const closed) (const clock) (const state)))
  857. (defcustom org-agenda-log-mode-add-notes t
  858. "Non-nil means add first line of notes to log entries in agenda views.
  859. If a log item like a state change or a clock entry is associated with
  860. notes, the first line of these notes will be added to the entry in the
  861. agenda display."
  862. :group 'org-agenda-daily/weekly
  863. :type 'boolean)
  864. (defcustom org-agenda-start-with-log-mode nil
  865. "The initial value of log-mode in a newly created agenda window."
  866. :group 'org-agenda-startup
  867. :group 'org-agenda-daily/weekly
  868. :type 'boolean)
  869. (defcustom org-agenda-start-with-clockreport-mode nil
  870. "The initial value of clockreport-mode in a newly created agenda window."
  871. :group 'org-agenda-startup
  872. :group 'org-agenda-daily/weekly
  873. :type 'boolean)
  874. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  875. "Property list with parameters for the clocktable in clockreport mode.
  876. This is the display mode that shows a clock table in the daily/weekly
  877. agenda, the properties for this dynamic block can be set here.
  878. The usual clocktable parameters are allowed here, but you cannot set
  879. the properties :name, :tstart, :tend, :block, and :scope - these will
  880. be overwritten to make sure the content accurately reflects the
  881. current display in the agenda."
  882. :group 'org-agenda-daily/weekly
  883. :type 'plist)
  884. (defcustom org-agenda-search-view-always-boolean nil
  885. "Non-nil means the search string is interpreted as individual parts.
  886. The search string for search view can either be interpreted as a phrase,
  887. or as a list of snippets that define a boolean search for a number of
  888. strings.
  889. When this is non-nil, the string will be split on whitespace, and each
  890. snippet will be searched individually, and all must match in order to
  891. select an entry. A snippet is then a single string of non-white
  892. characters, or a string in double quotes, or a regexp in {} braces.
  893. If a snippet is preceeded by \"-\", the snippet must *not* match.
  894. \"+\" is syntactic sugar for positive selection. Each snippet may
  895. be found as a full word or a partial word, but see the variable
  896. `org-agenda-search-view-force-full-words'.
  897. When this is nil, search will look for the entire search phrase as one,
  898. with each space character matching any amount of whitespace, including
  899. line breaks.
  900. Even when this is nil, you can still switch to Boolean search dynamically
  901. by preceeding the first snippet with \"+\" or \"-\". If the first snippet
  902. is a regexp marked with braces like \"{abc}\", this will also switch to
  903. boolean search."
  904. :group 'org-agenda-search-view
  905. :type 'boolean)
  906. (if (fboundp 'defvaralias)
  907. (defvaralias 'org-agenda-search-view-search-words-only
  908. 'org-agenda-search-view-always-boolean))
  909. (defcustom org-agenda-search-view-force-full-words nil
  910. "Non-nil me
  911. ans, search words must be matches as complete words.
  912. When nil, they may also match part of a word."
  913. :group 'org-agenda-search-view
  914. :type 'boolean)
  915. (defgroup org-agenda-time-grid nil
  916. "Options concerning the time grid in the Org-mode Agenda."
  917. :tag "Org Agenda Time Grid"
  918. :group 'org-agenda)
  919. (defcustom org-agenda-search-headline-for-time t
  920. "Non-nil means search headline for a time-of-day.
  921. If the headline contains a time-of-day in one format or another, it will
  922. be used to sort the entry into the time sequence of items for a day.
  923. Some people have time stamps in the headline that refer to the creation
  924. time or so, and then this produces an unwanted side effect. If this is
  925. the case for your, use this variable to turn off searching the headline
  926. for a time."
  927. :group 'org-agenda-time-grid
  928. :type 'boolean)
  929. (defcustom org-agenda-use-time-grid t
  930. "Non-nil means show a time grid in the agenda schedule.
  931. A time grid is a set of lines for specific times (like every two hours between
  932. 8:00 and 20:00). The items scheduled for a day at specific times are
  933. sorted in between these lines.
  934. For details about when the grid will be shown, and what it will look like, see
  935. the variable `org-agenda-time-grid'."
  936. :group 'org-agenda-time-grid
  937. :type 'boolean)
  938. (defcustom org-agenda-time-grid
  939. '((daily today require-timed)
  940. "----------------"
  941. (800 1000 1200 1400 1600 1800 2000))
  942. "The settings for time grid for agenda display.
  943. This is a list of three items. The first item is again a list. It contains
  944. symbols specifying conditions when the grid should be displayed:
  945. daily if the agenda shows a single day
  946. weekly if the agenda shows an entire week
  947. today show grid on current date, independent of daily/weekly display
  948. require-timed show grid only if at least one item has a time specification
  949. The second item is a string which will be placed behind the grid time.
  950. The third item is a list of integers, indicating the times that should have
  951. a grid line."
  952. :group 'org-agenda-time-grid
  953. :type
  954. '(list
  955. (set :greedy t :tag "Grid Display Options"
  956. (const :tag "Show grid in single day agenda display" daily)
  957. (const :tag "Show grid in weekly agenda display" weekly)
  958. (const :tag "Always show grid for today" today)
  959. (const :tag "Show grid only if any timed entries are present"
  960. require-timed)
  961. (const :tag "Skip grid times already present in an entry"
  962. remove-match))
  963. (string :tag "Grid String")
  964. (repeat :tag "Grid Times" (integer :tag "Time"))))
  965. (defgroup org-agenda-sorting nil
  966. "Options concerning sorting in the Org-mode Agenda."
  967. :tag "Org Agenda Sorting"
  968. :group 'org-agenda)
  969. (defcustom org-agenda-sorting-strategy
  970. '((agenda habit-down time-up priority-down category-keep)
  971. (todo priority-down category-keep)
  972. (tags priority-down category-keep)
  973. (search category-keep))
  974. "Sorting structure for the agenda items of a single day.
  975. This is a list of symbols which will be used in sequence to determine
  976. if an entry should be listed before another entry. The following
  977. symbols are recognized:
  978. time-up Put entries with time-of-day indications first, early first
  979. time-down Put entries with time-of-day indications first, late first
  980. category-keep Keep the default order of categories, corresponding to the
  981. sequence in `org-agenda-files'.
  982. category-up Sort alphabetically by category, A-Z.
  983. category-down Sort alphabetically by category, Z-A.
  984. tag-up Sort alphabetically by last tag, A-Z.
  985. tag-down Sort alphabetically by last tag, Z-A.
  986. priority-up Sort numerically by priority, high priority last.
  987. priority-down Sort numerically by priority, high priority first.
  988. todo-state-up Sort by todo state, tasks that are done last.
  989. todo-state-down Sort by todo state, tasks that are done first.
  990. effort-up Sort numerically by estimated effort, high effort last.
  991. effort-down Sort numerically by estimated effort, high effort first.
  992. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  993. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  994. habit-up Put entries that are habits first
  995. habit-down Put entries that are habits last
  996. The different possibilities will be tried in sequence, and testing stops
  997. if one comparison returns a \"not-equal\". For example, the default
  998. '(time-up category-keep priority-down)
  999. means: Pull out all entries having a specified time of day and sort them,
  1000. in order to make a time schedule for the current day the first thing in the
  1001. agenda listing for the day. Of the entries without a time indication, keep
  1002. the grouped in categories, don't sort the categories, but keep them in
  1003. the sequence given in `org-agenda-files'. Within each category sort by
  1004. priority.
  1005. Leaving out `category-keep' would mean that items will be sorted across
  1006. categories by priority.
  1007. Instead of a single list, this can also be a set of list for specific
  1008. contents, with a context symbol in the car of the list, any of
  1009. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1010. Custom commands can bind this variable in the options section."
  1011. :group 'org-agenda-sorting
  1012. :type `(choice
  1013. (repeat :tag "General" ,org-sorting-choice)
  1014. (list :tag "Individually"
  1015. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1016. (repeat ,org-sorting-choice))
  1017. (cons (const :tag "Strategy for TODO lists" todo)
  1018. (repeat ,org-sorting-choice))
  1019. (cons (const :tag "Strategy for Tags matches" tags)
  1020. (repeat ,org-sorting-choice))
  1021. (cons (const :tag "Strategy for search matches" search)
  1022. (repeat ,org-sorting-choice)))))
  1023. (defcustom org-agenda-cmp-user-defined nil
  1024. "A function to define the comparison `user-defined'.
  1025. This function must receive two arguments, agenda entry a and b.
  1026. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1027. the user comparison, return nil.
  1028. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1029. part of an agenda sorting strategy."
  1030. :group 'org-agenda-sorting
  1031. :type 'symbol)
  1032. (defcustom org-sort-agenda-notime-is-late t
  1033. "Non-nil means items without time are considered late.
  1034. This is only relevant for sorting. When t, items which have no explicit
  1035. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1036. do have a time. When nil, the default time is before 0:00. You can use this
  1037. option to decide if the schedule for today should come before or after timeless
  1038. agenda entries."
  1039. :group 'org-agenda-sorting
  1040. :type 'boolean)
  1041. (defcustom org-sort-agenda-noeffort-is-high t
  1042. "Non-nil means items without effort estimate are sorted as high effort.
  1043. This also applies when filtering an agenda view with respect to the
  1044. < or > effort operator. Then, tasks with no effort defined will be treated
  1045. as tasks with high effort.
  1046. When nil, such items are sorted as 0 minutes effort."
  1047. :group 'org-agenda-sorting
  1048. :type 'boolean)
  1049. (defgroup org-agenda-line-format nil
  1050. "Options concerning the entry prefix in the Org-mode agenda display."
  1051. :tag "Org Agenda Line Format"
  1052. :group 'org-agenda)
  1053. (defcustom org-agenda-prefix-format
  1054. '((agenda . " %-12:c%?-12t% s")
  1055. (timeline . " % s")
  1056. (todo . " %-12:c")
  1057. (tags . " %-12:c")
  1058. (search . " %-12:c"))
  1059. "Format specifications for the prefix of items in the agenda views.
  1060. An alist with four entries, for the different agenda types. The keys to the
  1061. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1062. are format strings.
  1063. This format works similar to a printf format, with the following meaning:
  1064. %c the category of the item, \"Diary\" for entries from the diary, or
  1065. as given by the CATEGORY keyword or derived from the file name.
  1066. %T the *last* tag of the item. Last because inherited tags come
  1067. first in the list.
  1068. %t the time-of-day specification if one applies to the entry, in the
  1069. format HH:MM
  1070. %s Scheduling/Deadline information, a short string
  1071. All specifiers work basically like the standard `%s' of printf, but may
  1072. contain two additional characters: A question mark just after the `%' and
  1073. a whitespace/punctuation character just before the final letter.
  1074. If the first character after `%' is a question mark, the entire field
  1075. will only be included if the corresponding value applies to the
  1076. current entry. This is useful for fields which should have fixed
  1077. width when present, but zero width when absent. For example,
  1078. \"%?-12t\" will result in a 12 character time field if a time of the
  1079. day is specified, but will completely disappear in entries which do
  1080. not contain a time.
  1081. If there is punctuation or whitespace character just before the final
  1082. format letter, this character will be appended to the field value if
  1083. the value is not empty. For example, the format \"%-12:c\" leads to
  1084. \"Diary: \" if the category is \"Diary\". If the category were be
  1085. empty, no additional colon would be inserted.
  1086. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1087. - Indent the line with two space characters
  1088. - Give the category in a 12 chars wide field, padded with whitespace on
  1089. the right (because of `-'). Append a colon if there is a category
  1090. (because of `:').
  1091. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1092. time, don't put in an empty field, just skip it (because of '?').
  1093. - Finally, put the scheduling information and append a whitespace.
  1094. As another example, if you don't want the time-of-day of entries in
  1095. the prefix, you could use:
  1096. (setq org-agenda-prefix-format \" %-11:c% s\")
  1097. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1098. `org-agenda-remove-tags'.
  1099. Custom commands can set this variable in the options section."
  1100. :type '(choice
  1101. (string :tag "General format")
  1102. (list :greedy t :tag "View dependent"
  1103. (cons (const agenda) (string :tag "Format"))
  1104. (cons (const timeline) (string :tag "Format"))
  1105. (cons (const todo) (string :tag "Format"))
  1106. (cons (const tags) (string :tag "Format"))
  1107. (cons (const search) (string :tag "Format"))))
  1108. :group 'org-agenda-line-format)
  1109. (defvar org-prefix-format-compiled nil
  1110. "The compiled version of the most recently used prefix format.
  1111. See the variable `org-agenda-prefix-format'.")
  1112. (defcustom org-agenda-todo-keyword-format "%-1s"
  1113. "Format for the TODO keyword in agenda lines.
  1114. Set this to something like \"%-12s\" if you want all TODO keywords
  1115. to occupy a fixed space in the agenda display."
  1116. :group 'org-agenda-line-format
  1117. :type 'string)
  1118. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1119. "Text preceding timerange entries in the agenda view.
  1120. This is a list with two strings. The first applies when the range
  1121. is entirely on one day. The second applies if the range spans several days.
  1122. The strings may have two \"%d\" format specifiers which will be filled
  1123. with the sequence number of the days, and the total number of days in the
  1124. range, respectively."
  1125. :group 'org-agenda-line-format
  1126. :type '(list
  1127. (string :tag "Deadline today ")
  1128. (choice :tag "Deadline relative"
  1129. (string :tag "Format string")
  1130. (function))))
  1131. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1132. "Text preceeding scheduled items in the agenda view.
  1133. This is a list with two strings. The first applies when the item is
  1134. scheduled on the current day. The second applies when it has been scheduled
  1135. previously, it may contain a %d indicating that this is the nth time that
  1136. this item is scheduled, due to automatic rescheduling of unfinished items
  1137. for the following day. So this number is one larger than the number of days
  1138. that passed since this item was scheduled first."
  1139. :group 'org-agenda-line-format
  1140. :type '(list
  1141. (string :tag "Scheduled today ")
  1142. (string :tag "Scheduled previously")))
  1143. (defcustom org-agenda-inactive-leader "["
  1144. "Text preceeding item pulled into the agenda by inactive time stamps.
  1145. These entries are added to the agenda when pressing \"[\"."
  1146. :group 'org-agenda-line-format
  1147. :type '(list
  1148. (string :tag "Scheduled today ")
  1149. (string :tag "Scheduled previously")))
  1150. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1151. "Text preceeding deadline items in the agenda view.
  1152. This is a list with two strings. The first applies when the item has its
  1153. deadline on the current day. The second applies when it is in the past or
  1154. in the future, it may contain %d to capture how many days away the deadline
  1155. is (was)."
  1156. :group 'org-agenda-line-format
  1157. :type '(list
  1158. (string :tag "Deadline today ")
  1159. (choice :tag "Deadline relative"
  1160. (string :tag "Format string")
  1161. (function))))
  1162. (defcustom org-agenda-remove-times-when-in-prefix t
  1163. "Non-nil means remove duplicate time specifications in agenda items.
  1164. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1165. time-of-day specification in a headline or diary entry is extracted and
  1166. placed into the prefix. If this option is non-nil, the original specification
  1167. \(a timestamp or -range, or just a plain time(range) specification like
  1168. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1169. cluttered.
  1170. The option can be t or nil. It may also be the symbol `beg', indicating
  1171. that the time should only be removed what it is located at the beginning of
  1172. the headline/diary entry."
  1173. :group 'org-agenda-line-format
  1174. :type '(choice
  1175. (const :tag "Always" t)
  1176. (const :tag "Never" nil)
  1177. (const :tag "When at beginning of entry" beg)))
  1178. (defcustom org-agenda-default-appointment-duration nil
  1179. "Default duration for appointments that only have a starting time.
  1180. When nil, no duration is specified in such cases.
  1181. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1182. :group 'org-agenda-line-format
  1183. :type '(choice
  1184. (integer :tag "Minutes")
  1185. (const :tag "No default duration")))
  1186. (defcustom org-agenda-show-inherited-tags t
  1187. "Non-nil means show inherited tags in each agenda line."
  1188. :group 'org-agenda-line-format
  1189. :type 'boolean)
  1190. (defcustom org-agenda-hide-tags-regexp nil
  1191. "Regular expression used to filter away specific tags in agenda views.
  1192. This means that these tags will be present, but not be shown in the agenda
  1193. line. Secondayt filltering will still work on the hidden tags.
  1194. Nil means don't hide any tags."
  1195. :group 'org-agenda-line-format
  1196. :type '(choice
  1197. (const :tag "Hide none" nil)
  1198. (string :tag "Regexp ")))
  1199. (defcustom org-agenda-remove-tags nil
  1200. "Non-nil means remove the tags from the headline copy in the agenda.
  1201. When this is the symbol `prefix', only remove tags when
  1202. `org-agenda-prefix-format' contains a `%T' specifier."
  1203. :group 'org-agenda-line-format
  1204. :type '(choice
  1205. (const :tag "Always" t)
  1206. (const :tag "Never" nil)
  1207. (const :tag "When prefix format contains %T" prefix)))
  1208. (if (fboundp 'defvaralias)
  1209. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1210. 'org-agenda-remove-tags))
  1211. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1212. "Shift tags in agenda items to this column.
  1213. If this number is positive, it specifies the column. If it is negative,
  1214. it means that the tags should be flushright to that column. For example,
  1215. -80 works well for a normal 80 character screen."
  1216. :group 'org-agenda-line-format
  1217. :type 'integer)
  1218. (if (fboundp 'defvaralias)
  1219. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1220. (defcustom org-agenda-fontify-priorities 'cookies
  1221. "Non-nil means highlight low and high priorities in agenda.
  1222. When t, the highest priority entries are bold, lowest priority italic.
  1223. However, settings in org-priority-faces will overrule these faces.
  1224. When this variable is the symbol `cookies', only fontify the
  1225. cookies, not the entire task.
  1226. This may also be an association list of priority faces, whose
  1227. keys are the character values of `org-highest-priority',
  1228. `org-default-priority', and `org-lowest-priority' (the default values
  1229. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1230. color as a string, or a list like `(:background \"Red\")'.
  1231. If it is a color, the variable `org-faces-easy-properties'
  1232. determines if it is a foreground or a background color."
  1233. :group 'org-agenda-line-format
  1234. :type '(choice
  1235. (const :tag "Never" nil)
  1236. (const :tag "Defaults" t)
  1237. (const :tag "Cookies only" cookies)
  1238. (repeat :tag "Specify"
  1239. (list (character :tag "Priority" :value ?A)
  1240. (choice :tag "Face "
  1241. (string :tag "Color")
  1242. (sexp :tag "Face"))))))
  1243. (defgroup org-agenda-column-view nil
  1244. "Options concerning column view in the agenda."
  1245. :tag "Org Agenda Column View"
  1246. :group 'org-agenda)
  1247. (defcustom org-agenda-columns-show-summaries t
  1248. "Non-nil means show summaries for columns displayed in the agenda view."
  1249. :group 'org-agenda-column-view
  1250. :type 'boolean)
  1251. (defcustom org-agenda-columns-remove-prefix-from-item t
  1252. "Non-nil means remove the prefix from a headline for agenda column view.
  1253. The special ITEM field in the columns format contains the current line, with
  1254. all information shown in other columns (like the TODO state or a tag).
  1255. When this variable is non-nil, also the agenda prefix will be removed from
  1256. the content of the ITEM field, to make sure as much as possible of the
  1257. headline can be shown in the limited width of the field."
  1258. :group 'org-agenda
  1259. :type 'boolean)
  1260. (defcustom org-agenda-columns-compute-summary-properties t
  1261. "Non-nil means recompute all summary properties before column view.
  1262. When column view in the agenda is listing properties that have a summary
  1263. operator, it can go to all relevant buffers and recompute the summaries
  1264. there. This can mean overhead for the agenda column view, but is necessary
  1265. to have thing up to date.
  1266. As a special case, a CLOCKSUM property also makes sure that the clock
  1267. computations are current."
  1268. :group 'org-agenda-column-view
  1269. :type 'boolean)
  1270. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1271. "Non-nil means the duration of an appointment will add to day effort.
  1272. The property to which appointment durations will be added is the one given
  1273. in the option `org-effort-property'. If an appointment does not have
  1274. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1275. is not set, an appointment without end time will not contribute to the time
  1276. estimate."
  1277. :group 'org-agenda-column-view
  1278. :type 'boolean)
  1279. (defcustom org-agenda-auto-exclude-function nil
  1280. "A function called with a tag to decide if it is filtered on '/ RET'.
  1281. The sole argument to the function, which is called once for each
  1282. possible tag, is a string giving the name of the tag. The
  1283. function should return either nil if the tag should be included
  1284. as normal, or \"-<TAG>\" to exclude the tag.
  1285. Note that for the purpose of tag filtering, only the lower-case version of
  1286. all tags will be considered, so that this function will only ever see
  1287. the lower-case version of all tags."
  1288. :group 'org-agenda
  1289. :type 'function)
  1290. (eval-when-compile
  1291. (require 'cl))
  1292. (require 'org)
  1293. (defun org-add-agenda-custom-command (entry)
  1294. "Replace or add a command in `org-agenda-custom-commands'.
  1295. This is mostly for hacking and trying a new command - once the command
  1296. works you probably want to add it to `org-agenda-custom-commands' for good."
  1297. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1298. (if ass
  1299. (setcdr ass (cdr entry))
  1300. (push entry org-agenda-custom-commands))))
  1301. ;;; Define the Org-agenda-mode
  1302. (defvar org-agenda-mode-map (make-sparse-keymap)
  1303. "Keymap for `org-agenda-mode'.")
  1304. (if (fboundp 'defvaralias)
  1305. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1306. (defvar org-agenda-menu) ; defined later in this file.
  1307. (defvar org-agenda-restrict) ; defined later in this file.
  1308. (defvar org-agenda-follow-mode nil)
  1309. (defvar org-agenda-entry-text-mode nil)
  1310. (defvar org-agenda-clockreport-mode nil)
  1311. (defvar org-agenda-show-log nil)
  1312. (defvar org-agenda-redo-command nil)
  1313. (defvar org-agenda-query-string nil)
  1314. (defvar org-agenda-mode-hook nil
  1315. "Hook for org-agenda-mode, run after the mode is turned on.")
  1316. (defvar org-agenda-type nil)
  1317. (defvar org-agenda-force-single-file nil)
  1318. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1319. (defun org-agenda-mode ()
  1320. "Mode for time-sorted view on action items in Org-mode files.
  1321. The following commands are available:
  1322. \\{org-agenda-mode-map}"
  1323. (interactive)
  1324. (kill-all-local-variables)
  1325. (setq org-agenda-undo-list nil
  1326. org-agenda-pending-undo-list nil
  1327. org-agenda-bulk-marked-entries nil)
  1328. (setq major-mode 'org-agenda-mode)
  1329. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1330. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1331. (setq mode-name "Org-Agenda")
  1332. (use-local-map org-agenda-mode-map)
  1333. (easy-menu-add org-agenda-menu)
  1334. (if org-startup-truncated (setq truncate-lines t))
  1335. (org-set-local 'line-move-visual nil)
  1336. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1337. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1338. ;; Make sure properties are removed when copying text
  1339. (when (boundp 'buffer-substring-filters)
  1340. (org-set-local 'buffer-substring-filters
  1341. (cons (lambda (x)
  1342. (set-text-properties 0 (length x) nil x) x)
  1343. buffer-substring-filters)))
  1344. (unless org-agenda-keep-modes
  1345. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1346. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1347. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1348. org-agenda-show-log org-agenda-start-with-log-mode))
  1349. (easy-menu-change
  1350. '("Agenda") "Agenda Files"
  1351. (append
  1352. (list
  1353. (vector
  1354. (if (get 'org-agenda-files 'org-restrict)
  1355. "Restricted to single file"
  1356. "Edit File List")
  1357. '(org-edit-agenda-file-list)
  1358. (not (get 'org-agenda-files 'org-restrict)))
  1359. "--")
  1360. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1361. (org-agenda-set-mode-name)
  1362. (apply
  1363. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1364. (list 'org-agenda-mode-hook)))
  1365. (substitute-key-definition 'undo 'org-agenda-undo
  1366. org-agenda-mode-map global-map)
  1367. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1368. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1369. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1370. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1371. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1372. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1373. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1374. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1375. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1376. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1377. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1378. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1379. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1380. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1381. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1382. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1383. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1384. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1385. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1386. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1387. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1388. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1389. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1390. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1391. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1392. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1393. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1394. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1395. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1396. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1397. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1398. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1399. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1400. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1401. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1402. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1403. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1404. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1405. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1406. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1407. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1408. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1409. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1410. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1411. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1412. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1413. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1414. (while l (org-defkey org-agenda-mode-map
  1415. (int-to-string (pop l)) 'digit-argument)))
  1416. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1417. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1418. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1419. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1420. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1421. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1422. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1423. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1424. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1425. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1426. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1427. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1428. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1429. 'org-clock-modify-effort-estimate)
  1430. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1431. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1432. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1433. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1434. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1435. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1436. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1437. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1438. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1439. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1440. (substitute-key-definition 'next-line 'org-agenda-next-line
  1441. org-agenda-mode-map global-map)
  1442. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1443. org-agenda-mode-map global-map)
  1444. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1445. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1446. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1447. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1448. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1449. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1450. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1451. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1452. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1453. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1454. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1455. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1456. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1457. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1458. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1459. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1460. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1461. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1462. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1463. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1464. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1465. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1466. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1467. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1468. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1469. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1470. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1471. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1472. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1473. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1474. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1475. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1476. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1477. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1478. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1479. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1480. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1481. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1482. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1483. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1484. (org-defkey org-agenda-mode-map
  1485. (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
  1486. (org-defkey org-agenda-mode-map
  1487. (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
  1488. (when org-agenda-mouse-1-follows-link
  1489. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1490. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1491. '("Agenda"
  1492. ("Agenda Files")
  1493. "--"
  1494. ("Agenda Dates"
  1495. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1496. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1497. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1498. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1499. "--"
  1500. ("View"
  1501. ["Day View" org-agenda-day-view
  1502. :active (org-agenda-check-type nil 'agenda)
  1503. :style radio :selected (equal org-agenda-ndays 1)
  1504. :keys "v d (or just d)"]
  1505. ["Week View" org-agenda-week-view
  1506. :active (org-agenda-check-type nil 'agenda)
  1507. :style radio :selected (equal org-agenda-ndays 7)
  1508. :keys "v w (or just w)"]
  1509. ["Month View" org-agenda-month-view
  1510. :active (org-agenda-check-type nil 'agenda)
  1511. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1512. :keys "v m"]
  1513. ["Year View" org-agenda-year-view
  1514. :active (org-agenda-check-type nil 'agenda)
  1515. :style radio :selected (member org-agenda-ndays '(365 366))
  1516. :keys "v y"]
  1517. "--"
  1518. ["Include Diary" org-agenda-toggle-diary
  1519. :style toggle :selected org-agenda-include-diary
  1520. :active (org-agenda-check-type nil 'agenda)]
  1521. ["Include Deadlines" org-agenda-toggle-deadlines
  1522. :style toggle :selected org-agenda-include-deadlines
  1523. :active (org-agenda-check-type nil 'agenda)]
  1524. ["Use Time Grid" org-agenda-toggle-time-grid
  1525. :style toggle :selected org-agenda-use-time-grid
  1526. :active (org-agenda-check-type nil 'agenda)]
  1527. "--"
  1528. ["Show clock report" org-agenda-clockreport-mode
  1529. :style toggle :selected org-agenda-clockreport-mode
  1530. :active (org-agenda-check-type nil 'agenda)]
  1531. ["Show some entry text" org-agenda-entry-text-mode
  1532. :style toggle :selected org-agenda-entry-text-mode
  1533. :active t]
  1534. "--"
  1535. ["Show Logbook entries" org-agenda-log-mode
  1536. :style toggle :selected org-agenda-show-log
  1537. :active (org-agenda-check-type nil 'agenda 'timeline)
  1538. :keys "v l (or just l)"]
  1539. ["Include archived trees" org-agenda-archives-mode
  1540. :style toggle :selected org-agenda-archives-mode :active t
  1541. :keys "v a"]
  1542. ["Include archive files" (org-agenda-archives-mode t)
  1543. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1544. :keys "v A"]
  1545. "--"
  1546. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1547. ["Write view to file" org-write-agenda t]
  1548. ["Rebuild buffer" org-agenda-redo t]
  1549. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1550. "--"
  1551. ["Show original entry" org-agenda-show t]
  1552. ["Go To (other window)" org-agenda-goto t]
  1553. ["Go To (this window)" org-agenda-switch-to t]
  1554. ["Follow Mode" org-agenda-follow-mode
  1555. :style toggle :selected org-agenda-follow-mode :active t]
  1556. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1557. "--"
  1558. ("TODO"
  1559. ["Cycle TODO" org-agenda-todo t]
  1560. ["Next TODO set" org-agenda-todo-nextset t]
  1561. ["Previous TODO set" org-agenda-todo-previousset t]
  1562. ["Add note" org-agenda-add-note t])
  1563. ("Archive/Refile/Delete"
  1564. ["Archive default" org-agenda-archive-default t]
  1565. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1566. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1567. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1568. ["Archive subtree" org-agenda-archive t]
  1569. "--"
  1570. ["Refile" org-agenda-refile t]
  1571. "--"
  1572. ["Delete subtree" org-agenda-kill t])
  1573. ("Bulk action"
  1574. ["Mark entry" org-agenda-bulk-mark t]
  1575. ["Unmark entry" org-agenda-bulk-unmark t]
  1576. ["Act on all marked" org-agenda-bulk-action t]
  1577. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1578. "--"
  1579. ("Tags and Properties"
  1580. ["Show all Tags" org-agenda-show-tags t]
  1581. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1582. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1583. "--"
  1584. ["Column View" org-columns t])
  1585. ("Deadline/Schedule"
  1586. ["Schedule" org-agenda-schedule t]
  1587. ["Set Deadline" org-agenda-deadline t]
  1588. "--"
  1589. ["Mark item" org-agenda-action :active t :keys "k m"]
  1590. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1591. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1592. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1593. "--"
  1594. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1595. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1596. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1597. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1598. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1599. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1600. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1601. ("Clock and Effort"
  1602. ["Clock in" org-agenda-clock-in t]
  1603. ["Clock out" org-agenda-clock-out t]
  1604. ["Clock cancel" org-agenda-clock-cancel t]
  1605. ["Goto running clock" org-clock-goto t]
  1606. "--"
  1607. ["Set Effort" org-agenda-set-effort t]
  1608. ["Change clocked effort" org-clock-modify-effort-estimate
  1609. (org-clock-is-active)])
  1610. ("Priority"
  1611. ["Set Priority" org-agenda-priority t]
  1612. ["Increase Priority" org-agenda-priority-up t]
  1613. ["Decrease Priority" org-agenda-priority-down t]
  1614. ["Show Priority" org-agenda-show-priority t])
  1615. ("Calendar/Diary"
  1616. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1617. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1618. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1619. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1620. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1621. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1622. "--"
  1623. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1624. "--"
  1625. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1626. "--"
  1627. ("MobileOrg"
  1628. ["Push Files and Views" org-mobile-push t]
  1629. ["Get Captured and Flagged" org-mobile-pull t]
  1630. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1631. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1632. "--"
  1633. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1634. "--"
  1635. ["Quit" org-agenda-quit t]
  1636. ["Exit and Release Buffers" org-agenda-exit t]
  1637. ))
  1638. ;;; Agenda undo
  1639. (defvar org-agenda-allow-remote-undo t
  1640. "Non-nil means allow remote undo from the agenda buffer.")
  1641. (defvar org-agenda-undo-list nil
  1642. "List of undoable operations in the agenda since last refresh.")
  1643. (defvar org-agenda-undo-has-started-in nil
  1644. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1645. (defvar org-agenda-pending-undo-list nil
  1646. "In a series of undo commands, this is the list of remaining undo items.")
  1647. (defun org-agenda-undo ()
  1648. "Undo a remote editing step in the agenda.
  1649. This undoes changes both in the agenda buffer and in the remote buffer
  1650. that have been changed along."
  1651. (interactive)
  1652. (or org-agenda-allow-remote-undo
  1653. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1654. (if (not (eq this-command last-command))
  1655. (setq org-agenda-undo-has-started-in nil
  1656. org-agenda-pending-undo-list org-agenda-undo-list))
  1657. (if (not org-agenda-pending-undo-list)
  1658. (error "No further undo information"))
  1659. (let* ((entry (pop org-agenda-pending-undo-list))
  1660. buf line cmd rembuf)
  1661. (setq cmd (pop entry) line (pop entry))
  1662. (setq rembuf (nth 2 entry))
  1663. (org-with-remote-undo rembuf
  1664. (while (bufferp (setq buf (pop entry)))
  1665. (if (pop entry)
  1666. (with-current-buffer buf
  1667. (let ((last-undo-buffer buf)
  1668. (inhibit-read-only t))
  1669. (unless (memq buf org-agenda-undo-has-started-in)
  1670. (push buf org-agenda-undo-has-started-in)
  1671. (make-local-variable 'pending-undo-list)
  1672. (undo-start))
  1673. (while (and pending-undo-list
  1674. (listp pending-undo-list)
  1675. (not (car pending-undo-list)))
  1676. (pop pending-undo-list))
  1677. (undo-more 1))))))
  1678. (org-goto-line line)
  1679. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1680. (defun org-verify-change-for-undo (l1 l2)
  1681. "Verify that a real change occurred between the undo lists L1 and L2."
  1682. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1683. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1684. (not (eq l1 l2)))
  1685. ;;; Agenda dispatch
  1686. (defvar org-agenda-restrict nil)
  1687. (defvar org-agenda-restrict-begin (make-marker))
  1688. (defvar org-agenda-restrict-end (make-marker))
  1689. (defvar org-agenda-last-dispatch-buffer nil)
  1690. (defvar org-agenda-overriding-restriction nil)
  1691. ;;;###autoload
  1692. (defun org-agenda (&optional arg keys restriction)
  1693. "Dispatch agenda commands to collect entries to the agenda buffer.
  1694. Prompts for a command to execute. Any prefix arg will be passed
  1695. on to the selected command. The default selections are:
  1696. a Call `org-agenda-list' to display the agenda for current day or week.
  1697. t Call `org-todo-list' to display the global todo list.
  1698. T Call `org-todo-list' to display the global todo list, select only
  1699. entries with a specific TODO keyword (the user gets a prompt).
  1700. m Call `org-tags-view' to display headlines with tags matching
  1701. a condition (the user is prompted for the condition).
  1702. M Like `m', but select only TODO entries, no ordinary headlines.
  1703. L Create a timeline for the current buffer.
  1704. e Export views to associated files.
  1705. s Search entries for keywords.
  1706. / Multi occur across all agenda files and also files listed
  1707. in `org-agenda-text-search-extra-files'.
  1708. < Restrict agenda commands to buffer, subtree, or region.
  1709. Press several times to get the desired effect.
  1710. > Remove a previous restriction.
  1711. # List \"stuck\" projects.
  1712. ! Configure what \"stuck\" means.
  1713. C Configure custom agenda commands.
  1714. More commands can be added by configuring the variable
  1715. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1716. searches can be pre-defined in this way.
  1717. If the current buffer is in Org-mode and visiting a file, you can also
  1718. first press `<' once to indicate that the agenda should be temporarily
  1719. \(until the next use of \\[org-agenda]) restricted to the current file.
  1720. Pressing `<' twice means to restrict to the current subtree or region
  1721. \(if active)."
  1722. (interactive "P")
  1723. (catch 'exit
  1724. (let* ((prefix-descriptions nil)
  1725. (org-agenda-window-setup (if (equal (buffer-name)
  1726. org-agenda-buffer-name)
  1727. 'current-window
  1728. org-agenda-window-setup))
  1729. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1730. (org-agenda-custom-commands
  1731. ;; normalize different versions
  1732. (delq nil
  1733. (mapcar
  1734. (lambda (x)
  1735. (cond ((stringp (cdr x))
  1736. (push x prefix-descriptions)
  1737. nil)
  1738. ((stringp (nth 1 x)) x)
  1739. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1740. (t (cons (car x) (cons "" (cdr x))))))
  1741. org-agenda-custom-commands)))
  1742. (buf (current-buffer))
  1743. (bfn (buffer-file-name (buffer-base-buffer)))
  1744. entry key type match lprops ans)
  1745. ;; Turn off restriction unless there is an overriding one,
  1746. (unless org-agenda-overriding-restriction
  1747. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1748. ;; There is a request to keep the file list in place
  1749. (put 'org-agenda-files 'org-restrict nil))
  1750. (setq org-agenda-restrict nil)
  1751. (move-marker org-agenda-restrict-begin nil)
  1752. (move-marker org-agenda-restrict-end nil))
  1753. ;; Delete old local properties
  1754. (put 'org-agenda-redo-command 'org-lprops nil)
  1755. ;; Remember where this call originated
  1756. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1757. (unless keys
  1758. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1759. keys (car ans)
  1760. restriction (cdr ans)))
  1761. ;; Establish the restriction, if any
  1762. (when (and (not org-agenda-overriding-restriction) restriction)
  1763. (put 'org-agenda-files 'org-restrict (list bfn))
  1764. (cond
  1765. ((eq restriction 'region)
  1766. (setq org-agenda-restrict t)
  1767. (move-marker org-agenda-restrict-begin (region-beginning))
  1768. (move-marker org-agenda-restrict-end (region-end)))
  1769. ((eq restriction 'subtree)
  1770. (save-excursion
  1771. (setq org-agenda-restrict t)
  1772. (org-back-to-heading t)
  1773. (move-marker org-agenda-restrict-begin (point))
  1774. (move-marker org-agenda-restrict-end
  1775. (progn (org-end-of-subtree t)))))))
  1776. (require 'calendar) ; FIXME: can we avoid this for some commands?
  1777. ;; For example the todo list should not need it (but does...)
  1778. (cond
  1779. ((setq entry (assoc keys org-agenda-custom-commands))
  1780. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1781. (progn
  1782. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1783. lprops (nth 4 entry))
  1784. (put 'org-agenda-redo-command 'org-lprops lprops)
  1785. (cond
  1786. ((eq type 'agenda)
  1787. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1788. ((eq type 'alltodo)
  1789. (org-let lprops '(org-todo-list current-prefix-arg)))
  1790. ((eq type 'search)
  1791. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1792. ((eq type 'stuck)
  1793. (org-let lprops '(org-agenda-list-stuck-projects
  1794. current-prefix-arg)))
  1795. ((eq type 'tags)
  1796. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1797. ((eq type 'tags-todo)
  1798. (org-let lprops '(org-tags-view '(4) match)))
  1799. ((eq type 'todo)
  1800. (org-let lprops '(org-todo-list match)))
  1801. ((eq type 'tags-tree)
  1802. (org-check-for-org-mode)
  1803. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1804. ((eq type 'todo-tree)
  1805. (org-check-for-org-mode)
  1806. (org-let lprops
  1807. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1808. (regexp-quote match) "\\>"))))
  1809. ((eq type 'occur-tree)
  1810. (org-check-for-org-mode)
  1811. (org-let lprops '(org-occur match)))
  1812. ((functionp type)
  1813. (org-let lprops '(funcall type match)))
  1814. ((fboundp type)
  1815. (org-let lprops '(funcall type match)))
  1816. (t (error "Invalid custom agenda command type %s" type))))
  1817. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1818. ((equal keys "C")
  1819. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1820. (customize-variable 'org-agenda-custom-commands))
  1821. ((equal keys "a") (call-interactively 'org-agenda-list))
  1822. ((equal keys "s") (call-interactively 'org-search-view))
  1823. ((equal keys "t") (call-interactively 'org-todo-list))
  1824. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1825. ((equal keys "m") (call-interactively 'org-tags-view))
  1826. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1827. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1828. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1829. (org-add-hook
  1830. 'post-command-hook
  1831. (lambda ()
  1832. (unless (current-message)
  1833. (let* ((m (org-agenda-get-any-marker))
  1834. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1835. (when note
  1836. (message (concat
  1837. "FLAGGING-NOTE ([?] for more info): "
  1838. (org-add-props
  1839. (replace-regexp-in-string
  1840. "\\\\n" "//"
  1841. (copy-sequence note))
  1842. nil 'face 'org-warning)))))))
  1843. t t))
  1844. ((equal keys "L")
  1845. (unless (org-mode-p)
  1846. (error "This is not an Org-mode file"))
  1847. (unless restriction
  1848. (put 'org-agenda-files 'org-restrict (list bfn))
  1849. (org-call-with-arg 'org-timeline arg)))
  1850. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1851. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1852. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1853. (t (error "Invalid agenda key"))))))
  1854. (defun org-agenda-normalize-custom-commands (cmds)
  1855. (delq nil
  1856. (mapcar
  1857. (lambda (x)
  1858. (cond ((stringp (cdr x)) nil)
  1859. ((stringp (nth 1 x)) x)
  1860. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1861. (t (cons (car x) (cons "" (cdr x))))))
  1862. cmds)))
  1863. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1864. "The user interface for selecting an agenda command."
  1865. (catch 'exit
  1866. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1867. (restrict-ok (and bfn (org-mode-p)))
  1868. (region-p (org-region-active-p))
  1869. (custom org-agenda-custom-commands)
  1870. (selstring "")
  1871. restriction second-time
  1872. c entry key type match prefixes rmheader header-end custom1 desc)
  1873. (save-window-excursion
  1874. (delete-other-windows)
  1875. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1876. (erase-buffer)
  1877. (insert (eval-when-compile
  1878. (let ((header
  1879. "
  1880. Press key for an agenda command: < Buffer, subtree/region restriction
  1881. -------------------------------- > Remove restriction
  1882. a Agenda for current week or day e Export agenda views
  1883. t List of all TODO entries T Entries with special TODO kwd
  1884. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1885. L Timeline for current buffer # List stuck projects (!=configure)
  1886. s Search for keywords C Configure custom agenda commands
  1887. / Multi-occur ? Find :FLAGGED: entries
  1888. ")
  1889. (start 0))
  1890. (while (string-match
  1891. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1892. header start)
  1893. (setq start (match-end 0))
  1894. (add-text-properties (match-beginning 2) (match-end 2)
  1895. '(face bold) header))
  1896. header)))
  1897. (setq header-end (move-marker (make-marker) (point)))
  1898. (while t
  1899. (setq custom1 custom)
  1900. (when (eq rmheader t)
  1901. (org-goto-line 1)
  1902. (re-search-forward ":" nil t)
  1903. (delete-region (match-end 0) (point-at-eol))
  1904. (forward-char 1)
  1905. (looking-at "-+")
  1906. (delete-region (match-end 0) (point-at-eol))
  1907. (move-marker header-end (match-end 0)))
  1908. (goto-char header-end)
  1909. (delete-region (point) (point-max))
  1910. (while (setq entry (pop custom1))
  1911. (setq key (car entry) desc (nth 1 entry)
  1912. type (nth 2 entry)
  1913. match (nth 3 entry))
  1914. (if (> (length key) 1)
  1915. (add-to-list 'prefixes (string-to-char key))
  1916. (insert
  1917. (format
  1918. "\n%-4s%-14s: %s"
  1919. (org-add-props (copy-sequence key)
  1920. '(face bold))
  1921. (cond
  1922. ((string-match "\\S-" desc) desc)
  1923. ((eq type 'agenda) "Agenda for current week or day")
  1924. ((eq type 'alltodo) "List of all TODO entries")
  1925. ((eq type 'search) "Word search")
  1926. ((eq type 'stuck) "List of stuck projects")
  1927. ((eq type 'todo) "TODO keyword")
  1928. ((eq type 'tags) "Tags query")
  1929. ((eq type 'tags-todo) "Tags (TODO)")
  1930. ((eq type 'tags-tree) "Tags tree")
  1931. ((eq type 'todo-tree) "TODO kwd tree")
  1932. ((eq type 'occur-tree) "Occur tree")
  1933. ((functionp type) (if (symbolp type)
  1934. (symbol-name type)
  1935. "Lambda expression"))
  1936. (t "???"))
  1937. (cond
  1938. ((stringp match)
  1939. (setq match (copy-sequence match))
  1940. (org-add-props match nil 'face 'org-warning))
  1941. (match
  1942. (format "set of %d commands" (length match)))
  1943. (t ""))))))
  1944. (when prefixes
  1945. (mapc (lambda (x)
  1946. (insert
  1947. (format "\n%s %s"
  1948. (org-add-props (char-to-string x)
  1949. nil 'face 'bold)
  1950. (or (cdr (assoc (concat selstring (char-to-string x))
  1951. prefix-descriptions))
  1952. "Prefix key"))))
  1953. prefixes))
  1954. (goto-char (point-min))
  1955. (if second-time
  1956. (if (not (pos-visible-in-window-p (point-max)))
  1957. (org-fit-window-to-buffer))
  1958. (setq second-time t)
  1959. (org-fit-window-to-buffer))
  1960. (message "Press key for agenda command%s:"
  1961. (if (or restrict-ok org-agenda-overriding-restriction)
  1962. (if org-agenda-overriding-restriction
  1963. " (restriction lock active)"
  1964. (if restriction
  1965. (format " (restricted to %s)" restriction)
  1966. " (unrestricted)"))
  1967. ""))
  1968. (setq c (read-char-exclusive))
  1969. (message "")
  1970. (cond
  1971. ((assoc (char-to-string c) custom)
  1972. (setq selstring (concat selstring (char-to-string c)))
  1973. (throw 'exit (cons selstring restriction)))
  1974. ((memq c prefixes)
  1975. (setq selstring (concat selstring (char-to-string c))
  1976. prefixes nil
  1977. rmheader (or rmheader t)
  1978. custom (delq nil (mapcar
  1979. (lambda (x)
  1980. (if (or (= (length (car x)) 1)
  1981. (/= (string-to-char (car x)) c))
  1982. nil
  1983. (cons (substring (car x) 1) (cdr x))))
  1984. custom))))
  1985. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1986. (message "Restriction is only possible in Org-mode buffers")
  1987. (ding) (sit-for 1))
  1988. ((eq c ?1)
  1989. (org-agenda-remove-restriction-lock 'noupdate)
  1990. (setq restriction 'buffer))
  1991. ((eq c ?0)
  1992. (org-agenda-remove-restriction-lock 'noupdate)
  1993. (setq restriction (if region-p 'region 'subtree)))
  1994. ((eq c ?<)
  1995. (org-agenda-remove-restriction-lock 'noupdate)
  1996. (setq restriction
  1997. (cond
  1998. ((eq restriction 'buffer)
  1999. (if region-p 'region 'subtree))
  2000. ((memq restriction '(subtree region))
  2001. nil)
  2002. (t 'buffer))))
  2003. ((eq c ?>)
  2004. (org-agenda-remove-restriction-lock 'noupdate)
  2005. (setq restriction nil))
  2006. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2007. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2008. ((and (> (length selstring) 0) (eq c ?\d))
  2009. (delete-window)
  2010. (org-agenda-get-restriction-and-command prefix-descriptions))
  2011. ((equal c ?q) (error "Abort"))
  2012. (t (error "Invalid key %c" c))))))))
  2013. (defun org-run-agenda-series (name series)
  2014. (org-let (nth 1 series) '(org-prepare-agenda name))
  2015. (let* ((org-agenda-multi t)
  2016. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2017. (cmds (car series))
  2018. (gprops (nth 1 series))
  2019. match ;; The byte compiler incorrectly complains about this. Keep it!
  2020. cmd type lprops)
  2021. (while (setq cmd (pop cmds))
  2022. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2023. (cond
  2024. ((eq type 'agenda)
  2025. (org-let2 gprops lprops
  2026. '(call-interactively 'org-agenda-list)))
  2027. ((eq type 'alltodo)
  2028. (org-let2 gprops lprops
  2029. '(call-interactively 'org-todo-list)))
  2030. ((eq type 'search)
  2031. (org-let2 gprops lprops
  2032. '(org-search-view current-prefix-arg match nil)))
  2033. ((eq type 'stuck)
  2034. (org-let2 gprops lprops
  2035. '(call-interactively 'org-agenda-list-stuck-projects)))
  2036. ((eq type 'tags)
  2037. (org-let2 gprops lprops
  2038. '(org-tags-view current-prefix-arg match)))
  2039. ((eq type 'tags-todo)
  2040. (org-let2 gprops lprops
  2041. '(org-tags-view '(4) match)))
  2042. ((eq type 'todo)
  2043. (org-let2 gprops lprops
  2044. '(org-todo-list match)))
  2045. ((fboundp type)
  2046. (org-let2 gprops lprops
  2047. '(funcall type match)))
  2048. (t (error "Invalid type in command series"))))
  2049. (widen)
  2050. (setq org-agenda-redo-command redo)
  2051. (goto-char (point-min)))
  2052. (org-fit-agenda-window)
  2053. (org-let (nth 1 series) '(org-finalize-agenda)))
  2054. ;;;###autoload
  2055. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2056. "Run an agenda command in batch mode and send the result to STDOUT.
  2057. If CMD-KEY is a string of length 1, it is used as a key in
  2058. `org-agenda-custom-commands' and triggers this command. If it is a
  2059. longer string it is used as a tags/todo match string.
  2060. Paramters are alternating variable names and values that will be bound
  2061. before running the agenda command."
  2062. (let (pars)
  2063. (while parameters
  2064. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2065. (if (> (length cmd-key) 2)
  2066. (eval (list 'let (nreverse pars)
  2067. (list 'org-tags-view nil cmd-key)))
  2068. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2069. (set-buffer org-agenda-buffer-name)
  2070. (princ (org-encode-for-stdout (buffer-string)))))
  2071. ;(defun org-encode-for-stdout (string)
  2072. ; (if (fboundp 'encode-coding-string)
  2073. ; (encode-coding-string string buffer-file-coding-system)
  2074. ; string))
  2075. (defun org-encode-for-stdout (string)
  2076. string)
  2077. (defvar org-agenda-info nil)
  2078. ;;;###autoload
  2079. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2080. "Run an agenda command in batch mode and send the result to STDOUT.
  2081. If CMD-KEY is a string of length 1, it is used as a key in
  2082. `org-agenda-custom-commands' and triggers this command. If it is a
  2083. longer string it is used as a tags/todo match string.
  2084. Paramters are alternating variable names and values that will be bound
  2085. before running the agenda command.
  2086. The output gives a line for each selected agenda item. Each
  2087. item is a list of comma-separated values, like this:
  2088. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2089. category The category of the item
  2090. head The headline, without TODO kwd, TAGS and PRIORITY
  2091. type The type of the agenda entry, can be
  2092. todo selected in TODO match
  2093. tagsmatch selected in tags match
  2094. diary imported from diary
  2095. deadline a deadline on given date
  2096. scheduled scheduled on given date
  2097. timestamp entry has timestamp on given date
  2098. closed entry was closed on given date
  2099. upcoming-deadline warning about deadline
  2100. past-scheduled forwarded scheduled item
  2101. block entry has date block including g. date
  2102. todo The todo keyword, if any
  2103. tags All tags including inherited ones, separated by colons
  2104. date The relevant date, like 2007-2-14
  2105. time The time, like 15:00-16:50
  2106. extra Sting with extra planning info
  2107. priority-l The priority letter if any was given
  2108. priority-n The computed numerical priority
  2109. agenda-day The day in the agenda where this is listed"
  2110. (let (pars)
  2111. (while parameters
  2112. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2113. (push (list 'org-agenda-remove-tags t) pars)
  2114. (if (> (length cmd-key) 2)
  2115. (eval (list 'let (nreverse pars)
  2116. (list 'org-tags-view nil cmd-key)))
  2117. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2118. (set-buffer org-agenda-buffer-name)
  2119. (let* ((lines (org-split-string (buffer-string) "\n"))
  2120. line)
  2121. (while (setq line (pop lines))
  2122. (catch 'next
  2123. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2124. (setq org-agenda-info
  2125. (org-fix-agenda-info (text-properties-at 0 line)))
  2126. (princ
  2127. (org-encode-for-stdout
  2128. (mapconcat 'org-agenda-export-csv-mapper
  2129. '(org-category txt type todo tags date time extra
  2130. priority-letter priority agenda-day)
  2131. ",")))
  2132. (princ "\n"))))))
  2133. (defun org-fix-agenda-info (props)
  2134. "Make sure all properties on an agenda item have a canonical form,
  2135. so the export commands can easily use it."
  2136. (let (tmp re)
  2137. (when (setq tmp (plist-get props 'tags))
  2138. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2139. (when (setq tmp (plist-get props 'date))
  2140. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2141. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2142. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2143. (setq tmp (calendar-date-string tmp)))
  2144. (setq props (plist-put props 'date tmp)))
  2145. (when (setq tmp (plist-get props 'day))
  2146. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2147. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2148. (setq tmp (calendar-date-string tmp)))
  2149. (setq props (plist-put props 'day tmp))
  2150. (setq props (plist-put props 'agenda-day tmp)))
  2151. (when (setq tmp (plist-get props 'txt))
  2152. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2153. (plist-put props 'priority-letter (match-string 1 tmp))
  2154. (setq tmp (replace-match "" t t tmp)))
  2155. (when (and (setq re (plist-get props 'org-todo-regexp))
  2156. (setq re (concat "\\`\\.*" re " ?"))
  2157. (string-match re tmp))
  2158. (plist-put props 'todo (match-string 1 tmp))
  2159. (setq tmp (replace-match "" t t tmp)))
  2160. (plist-put props 'txt tmp)))
  2161. props)
  2162. (defun org-agenda-export-csv-mapper (prop)
  2163. (let ((res (plist-get org-agenda-info prop)))
  2164. (setq res
  2165. (cond
  2166. ((not res) "")
  2167. ((stringp res) res)
  2168. (t (prin1-to-string res))))
  2169. (while (string-match "," res)
  2170. (setq res (replace-match ";" t t res)))
  2171. (org-trim res)))
  2172. ;;;###autoload
  2173. (defun org-store-agenda-views (&rest parameters)
  2174. (interactive)
  2175. (eval (list 'org-batch-store-agenda-views)))
  2176. ;; FIXME, why is this a macro?????
  2177. ;;;###autoload
  2178. (defmacro org-batch-store-agenda-views (&rest parameters)
  2179. "Run all custom agenda commands that have a file argument."
  2180. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2181. (pop-up-frames nil)
  2182. (dir default-directory)
  2183. pars cmd thiscmdkey files opts cmd-or-set)
  2184. (while parameters
  2185. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2186. (setq pars (reverse pars))
  2187. (save-window-excursion
  2188. (while cmds
  2189. (setq cmd (pop cmds)
  2190. thiscmdkey (car cmd)
  2191. cmd-or-set (nth 2 cmd)
  2192. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2193. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2194. (if (stringp files) (setq files (list files)))
  2195. (when files
  2196. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2197. (list 'org-agenda nil thiscmdkey)))
  2198. (set-buffer org-agenda-buffer-name)
  2199. (while files
  2200. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2201. (list 'org-write-agenda
  2202. (expand-file-name (pop files) dir) nil t))))
  2203. (and (get-buffer org-agenda-buffer-name)
  2204. (kill-buffer org-agenda-buffer-name)))))))
  2205. (defun org-agenda-mark-header-line (pos)
  2206. "Mark the line at POS as an agenda structure header."
  2207. (save-excursion
  2208. (goto-char pos)
  2209. (put-text-property (point-at-bol) (point-at-eol)
  2210. 'org-agenda-structural-header t)
  2211. (when org-agenda-title-append
  2212. (put-text-property (point-at-bol) (point-at-eol)
  2213. 'org-agenda-title-append org-agenda-title-append))))
  2214. (defvar org-mobile-creating-agendas)
  2215. (defun org-write-agenda (file &optional open nosettings)
  2216. "Write the current buffer (an agenda view) as a file.
  2217. Depending on the extension of the file name, plain text (.txt),
  2218. HTML (.html or .htm) or Postscript (.ps) is produced.
  2219. If the extension is .ics, run icalendar export over all files used
  2220. to construct the agenda and limit the export to entries listed in the
  2221. agenda now.
  2222. With prefix argument OPEN, open the new file immediately.
  2223. If NOSETTINGS is given, do not scope the settings of
  2224. `org-agenda-exporter-settings' into the export commands. This is used when
  2225. the settings have already been scoped and we do not wish to overrule other,
  2226. higher priority settings."
  2227. (interactive "FWrite agenda to file: \nP")
  2228. (if (not (file-writable-p file))
  2229. (error "Cannot write agenda to file %s" file))
  2230. (cond
  2231. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2232. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2233. (org-let (if nosettings nil org-agenda-exporter-settings)
  2234. '(save-excursion
  2235. (save-window-excursion
  2236. (org-agenda-mark-filtered-text)
  2237. (let ((bs (copy-sequence (buffer-string))) beg)
  2238. (org-agenda-unmark-filtered-text)
  2239. (with-temp-buffer
  2240. (insert bs)
  2241. (org-agenda-remove-marked-text 'org-filtered)
  2242. (while (setq beg (text-property-any (point-min) (point-max)
  2243. 'org-filtered t))
  2244. (delete-region
  2245. beg (or (next-single-property-change beg 'org-filtered)
  2246. (point-max))))
  2247. (run-hooks 'org-agenda-before-write-hook)
  2248. (cond
  2249. ((org-bound-and-true-p org-mobile-creating-agendas)
  2250. (org-mobile-write-agenda-for-mobile file))
  2251. ((string-match "\\.html?\\'" file)
  2252. (set-buffer (htmlize-buffer (current-buffer)))
  2253. (when (and org-agenda-export-html-style
  2254. (string-match "<style>" org-agenda-export-html-style))
  2255. ;; replace <style> section with org-agenda-export-html-style
  2256. (goto-char (point-min))
  2257. (kill-region (- (search-forward "<style") 6)
  2258. (search-forward "</style>"))
  2259. (insert org-agenda-export-html-style))
  2260. (write-file file)
  2261. (kill-buffer (current-buffer))
  2262. (message "HTML written to %s" file))
  2263. ((string-match "\\.ps\\'" file)
  2264. (require 'ps-print)
  2265. (flet ((ps-get-buffer-name () "Agenda View"))
  2266. (ps-print-buffer-with-faces file))
  2267. (message "Postscript written to %s" file))
  2268. ((string-match "\\.pdf\\'" file)
  2269. (require 'ps-print)
  2270. (flet ((ps-get-buffer-name () "Agenda View"))
  2271. (ps-print-buffer-with-faces
  2272. (concat (file-name-sans-extension file) ".ps")))
  2273. (call-process "ps2pdf" nil nil nil
  2274. (expand-file-name
  2275. (concat (file-name-sans-extension file) ".ps"))
  2276. (expand-file-name file))
  2277. (message "PDF written to %s" file))
  2278. ((string-match "\\.ics\\'" file)
  2279. (require 'org-icalendar)
  2280. (let ((org-agenda-marker-table
  2281. (org-create-marker-find-array
  2282. (org-agenda-collect-markers)))
  2283. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2284. (org-combined-agenda-icalendar-file file))
  2285. (apply 'org-export-icalendar 'combine
  2286. (org-agenda-files nil 'ifmode))))
  2287. (t
  2288. (let ((bs (buffer-string)))
  2289. (find-file file)
  2290. (erase-buffer)
  2291. (insert bs)
  2292. (save-buffer 0)
  2293. (kill-buffer (current-buffer))
  2294. (message "Plain text written to %s" file))))))))
  2295. (set-buffer org-agenda-buffer-name))
  2296. (when open (org-open-file file)))
  2297. (defvar org-agenda-filter-overlays nil)
  2298. (defun org-agenda-mark-filtered-text ()
  2299. "Mark all text hidden by filtering with a text property."
  2300. (let ((inhibit-read-only t))
  2301. (mapc
  2302. (lambda (o)
  2303. (when (equal (org-overlay-buffer o) (current-buffer))
  2304. (put-text-property
  2305. (org-overlay-start o) (org-overlay-end o)
  2306. 'org-filtered t)))
  2307. org-agenda-filter-overlays)))
  2308. (defun org-agenda-unmark-filtered-text ()
  2309. "Remove the filtering text property."
  2310. (let ((inhibit-read-only t))
  2311. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2312. (defun org-agenda-remove-marked-text (property &optional value)
  2313. "Delete all text marked with VALUE of PROPERTY.
  2314. VALUE defaults to t."
  2315. (let (beg)
  2316. (setq value (or value t))
  2317. (while (setq beg (text-property-any (point-min) (point-max)
  2318. property value))
  2319. (delete-region
  2320. beg (or (next-single-property-change beg 'org-filtered)
  2321. (point-max))))))
  2322. (defun org-agenda-add-entry-text ()
  2323. "Add entry text to agenda lines.
  2324. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2325. entry text following headings shown in the agenda.
  2326. Drawers will be excluded, also the line with scheduling/deadline info."
  2327. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2328. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2329. (let (m txt)
  2330. (goto-char (point-min))
  2331. (while (not (eobp))
  2332. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2333. (beginning-of-line 2)
  2334. (setq txt (org-agenda-get-some-entry-text
  2335. m org-agenda-add-entry-text-maxlines " > "))
  2336. (end-of-line 1)
  2337. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2338. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2339. &rest keep)
  2340. "Extract entry text from MARKER, at most N-LINES lines.
  2341. This will ignore drawers etc, just get the text.
  2342. If INDENT is given, prefix every line with this string. If KEEP is
  2343. given, it is a list of symbols, defining stuff that should not be
  2344. removed from the entry content. Currently only `planning' is allowed here."
  2345. (let (txt drawer-re kwd-time-re ind)
  2346. (save-excursion
  2347. (with-current-buffer (marker-buffer marker)
  2348. (if (not (org-mode-p))
  2349. (setq txt "")
  2350. (save-excursion
  2351. (save-restriction
  2352. (widen)
  2353. (goto-char marker)
  2354. (end-of-line 1)
  2355. (setq txt (buffer-substring
  2356. (min (1+ (point)) (point-max))
  2357. (progn (outline-next-heading) (point)))
  2358. drawer-re org-drawer-regexp
  2359. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2360. ".*\n?"))
  2361. (with-temp-buffer
  2362. (insert txt)
  2363. (when org-agenda-add-entry-text-descriptive-links
  2364. (goto-char (point-min))
  2365. (while (org-activate-bracket-links (point-max))
  2366. (add-text-properties (match-beginning 0) (match-end 0)
  2367. '(face org-link))))
  2368. (goto-char (point-min))
  2369. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2370. (set-text-properties (match-beginning 0) (match-end 0)
  2371. nil))
  2372. (goto-char (point-min))
  2373. (while (re-search-forward drawer-re nil t)
  2374. (delete-region
  2375. (match-beginning 0)
  2376. (progn (re-search-forward
  2377. "^[ \t]*:END:.*\n?" nil 'move)
  2378. (point))))
  2379. (unless (member 'planning keep)
  2380. (goto-char (point-min))
  2381. (while (re-search-forward kwd-time-re nil t)
  2382. (replace-match "")))
  2383. (goto-char (point-min))
  2384. (when org-agenda-entry-text-exclude-regexps
  2385. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2386. (while (setq re (pop re-list))
  2387. (goto-char (point-min))
  2388. (while (re-search-forward re nil t)
  2389. (replace-match "")))))
  2390. (goto-char (point-max))
  2391. (skip-chars-backward " \t\n")
  2392. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2393. ;; find and remove min common indentation
  2394. (goto-char (point-min))
  2395. (untabify (point-min) (point-max))
  2396. (setq ind (org-get-indentation))
  2397. (while (not (eobp))
  2398. (unless (looking-at "[ \t]*$")
  2399. (setq ind (min ind (org-get-indentation))))
  2400. (beginning-of-line 2))
  2401. (goto-char (point-min))
  2402. (while (not (eobp))
  2403. (unless (looking-at "[ \t]*$")
  2404. (move-to-column ind)
  2405. (delete-region (point-at-bol) (point)))
  2406. (beginning-of-line 2))
  2407. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2408. (goto-char (point-min))
  2409. (when indent
  2410. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2411. (replace-match indent t t)))
  2412. (goto-char (point-min))
  2413. (while (looking-at "[ \t]*\n") (replace-match ""))
  2414. (goto-char (point-max))
  2415. (when (> (org-current-line)
  2416. n-lines)
  2417. (org-goto-line (1+ n-lines))
  2418. (backward-char 1))
  2419. (setq txt (buffer-substring (point-min) (point)))))))))
  2420. txt))
  2421. (defun org-agenda-collect-markers ()
  2422. "Collect the markers pointing to entries in the agenda buffer."
  2423. (let (m markers)
  2424. (save-excursion
  2425. (goto-char (point-min))
  2426. (while (not (eobp))
  2427. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2428. (org-get-at-bol 'org-marker)))
  2429. (push m markers))
  2430. (beginning-of-line 2)))
  2431. (nreverse markers)))
  2432. (defun org-create-marker-find-array (marker-list)
  2433. "Create a alist of files names with all marker positions in that file."
  2434. (let (f tbl m a p)
  2435. (while (setq m (pop marker-list))
  2436. (setq p (marker-position m)
  2437. f (buffer-file-name (or (buffer-base-buffer
  2438. (marker-buffer m))
  2439. (marker-buffer m))))
  2440. (if (setq a (assoc f tbl))
  2441. (push (marker-position m) (cdr a))
  2442. (push (list f p) tbl)))
  2443. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2444. tbl)))
  2445. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2446. (defun org-check-agenda-marker-table ()
  2447. "Check of the current entry is on the marker list."
  2448. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2449. a)
  2450. (and (setq a (assoc file org-agenda-marker-table))
  2451. (save-match-data
  2452. (save-excursion
  2453. (org-back-to-heading t)
  2454. (member (point) (cdr a)))))))
  2455. (defun org-check-for-org-mode ()
  2456. "Make sure current buffer is in org-mode. Error if not."
  2457. (or (org-mode-p)
  2458. (error "Cannot execute org-mode agenda command on buffer in %s"
  2459. major-mode)))
  2460. (defun org-fit-agenda-window ()
  2461. "Fit the window to the buffer size."
  2462. (and (memq org-agenda-window-setup '(reorganize-frame))
  2463. (fboundp 'fit-window-to-buffer)
  2464. (org-fit-window-to-buffer
  2465. nil
  2466. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2467. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2468. ;;; Agenda prepare and finalize
  2469. (defvar org-agenda-multi nil) ; dynamically scoped
  2470. (defvar org-agenda-buffer-name "*Org Agenda*")
  2471. (defvar org-pre-agenda-window-conf nil)
  2472. (defvar org-agenda-columns-active nil)
  2473. (defvar org-agenda-name nil)
  2474. (defvar org-agenda-filter nil)
  2475. (defvar org-agenda-filter-preset nil
  2476. "A preset of the tags filter used for secondary agenda filtering.
  2477. This must be a list of strings, each string must be a single tag preceeded
  2478. by \"+\" or \"-\".
  2479. This variable should not be set directly, but agenda custom commands can
  2480. bind it in the options section.")
  2481. (defun org-prepare-agenda (&optional name)
  2482. (setq org-todo-keywords-for-agenda nil)
  2483. (setq org-done-keywords-for-agenda nil)
  2484. (setq org-drawers-for-agenda nil)
  2485. (setq org-agenda-filter nil)
  2486. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2487. (if org-agenda-multi
  2488. (progn
  2489. (setq buffer-read-only nil)
  2490. (goto-char (point-max))
  2491. (unless (or (bobp) org-agenda-compact-blocks)
  2492. (insert "\n"
  2493. (if (stringp org-agenda-block-separator)
  2494. org-agenda-block-separator
  2495. (make-string (window-width) org-agenda-block-separator))
  2496. "\n"))
  2497. (narrow-to-region (point) (point-max)))
  2498. (org-agenda-reset-markers)
  2499. (setq org-agenda-contributing-files nil)
  2500. (setq org-agenda-columns-active nil)
  2501. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2502. (setq org-todo-keywords-for-agenda
  2503. (org-uniquify org-todo-keywords-for-agenda))
  2504. (setq org-done-keywords-for-agenda
  2505. (org-uniquify org-done-keywords-for-agenda))
  2506. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2507. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2508. (awin (get-buffer-window abuf)))
  2509. (cond
  2510. ((equal (current-buffer) abuf) nil)
  2511. (awin (select-window awin))
  2512. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2513. ((equal org-agenda-window-setup 'current-window)
  2514. (switch-to-buffer abuf))
  2515. ((equal org-agenda-window-setup 'other-window)
  2516. (org-switch-to-buffer-other-window abuf))
  2517. ((equal org-agenda-window-setup 'other-frame)
  2518. (switch-to-buffer-other-frame abuf))
  2519. ((equal org-agenda-window-setup 'reorganize-frame)
  2520. (delete-other-windows)
  2521. (org-switch-to-buffer-other-window abuf))))
  2522. (setq buffer-read-only nil)
  2523. (let ((inhibit-read-only t)) (erase-buffer))
  2524. (org-agenda-mode)
  2525. (and name (not org-agenda-name)
  2526. (org-set-local 'org-agenda-name name)))
  2527. (setq buffer-read-only nil))
  2528. (defun org-finalize-agenda ()
  2529. "Finishing touch for the agenda buffer, called just before displaying it."
  2530. (unless org-agenda-multi
  2531. (save-excursion
  2532. (let ((inhibit-read-only t))
  2533. (goto-char (point-min))
  2534. (while (org-activate-bracket-links (point-max))
  2535. (add-text-properties (match-beginning 0) (match-end 0)
  2536. '(face org-link)))
  2537. (org-agenda-align-tags)
  2538. (unless org-agenda-with-colors
  2539. (remove-text-properties (point-min) (point-max) '(face nil))))
  2540. (if (and (boundp 'org-agenda-overriding-columns-format)
  2541. org-agenda-overriding-columns-format)
  2542. (org-set-local 'org-agenda-overriding-columns-format
  2543. org-agenda-overriding-columns-format))
  2544. (if (and (boundp 'org-agenda-view-columns-initially)
  2545. org-agenda-view-columns-initially)
  2546. (org-agenda-columns))
  2547. (when org-agenda-fontify-priorities
  2548. (org-agenda-fontify-priorities))
  2549. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2550. (org-agenda-dim-blocked-tasks))
  2551. (org-agenda-mark-clocking-task)
  2552. (when org-agenda-entry-text-mode
  2553. (org-agenda-entry-text-hide)
  2554. (org-agenda-entry-text-show))
  2555. (if (functionp 'org-habit-insert-consistency-graphs)
  2556. (org-habit-insert-consistency-graphs))
  2557. (run-hooks 'org-finalize-agenda-hook)
  2558. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2559. (when (get 'org-agenda-filter :preset-filter)
  2560. (org-agenda-filter-apply org-agenda-filter))
  2561. )))
  2562. (defun org-agenda-mark-clocking-task ()
  2563. "Mark the current clock entry in the agenda if it is present."
  2564. (mapc (lambda (o)
  2565. (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
  2566. (org-delete-overlay o)))
  2567. (org-overlays-in (point-min) (point-max)))
  2568. (when (marker-buffer org-clock-hd-marker)
  2569. (save-excursion
  2570. (goto-char (point-min))
  2571. (let (s ov)
  2572. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2573. (goto-char s)
  2574. (when (equal (org-get-at-bol 'org-hd-marker)
  2575. org-clock-hd-marker)
  2576. (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
  2577. (org-overlay-put ov 'type 'org-agenda-clocking)
  2578. (org-overlay-put ov 'face 'org-agenda-clocking)
  2579. (org-overlay-put ov 'help-echo
  2580. "The clock is running in this item")))))))
  2581. (defun org-agenda-fontify-priorities ()
  2582. "Make highest priority lines bold, and lowest italic."
  2583. (interactive)
  2584. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
  2585. (org-delete-overlay o)))
  2586. (org-overlays-in (point-min) (point-max)))
  2587. (save-excursion
  2588. (let ((inhibit-read-only t)
  2589. b e p ov h l)
  2590. (goto-char (point-min))
  2591. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2592. (setq h (or (get-char-property (point) 'org-highest-priority)
  2593. org-highest-priority)
  2594. l (or (get-char-property (point) 'org-lowest-priority)
  2595. org-lowest-priority)
  2596. p (string-to-char (match-string 1))
  2597. b (match-beginning 0)
  2598. e (if (eq org-agenda-fontify-priorities 'cookies)
  2599. (match-end 0)
  2600. (point-at-eol))
  2601. ov (org-make-overlay b e))
  2602. (org-overlay-put
  2603. ov 'face
  2604. (cond ((org-face-from-face-or-color
  2605. 'priority nil
  2606. (cdr (assoc p org-priority-faces))))
  2607. ((and (listp org-agenda-fontify-priorities)
  2608. (org-face-from-face-or-color
  2609. 'priority nil
  2610. (cdr (assoc p org-agenda-fontify-priorities)))))
  2611. ((equal p l) 'italic)
  2612. ((equal p h) 'bold)))
  2613. (org-overlay-put ov 'org-type 'org-priority)))))
  2614. (defun org-agenda-dim-blocked-tasks ()
  2615. "Dim currently blocked TODO's in the agenda display."
  2616. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
  2617. (org-delete-overlay o)))
  2618. (org-overlays-in (point-min) (point-max)))
  2619. (save-excursion
  2620. (let ((inhibit-read-only t)
  2621. (org-depend-tag-blocked nil)
  2622. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2623. org-blocked-by-checkboxes
  2624. invis1 b e p ov h l)
  2625. (goto-char (point-min))
  2626. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2627. (and pos (goto-char (1+ pos))))
  2628. (setq org-blocked-by-checkboxes nil invis1 invis)
  2629. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2630. (when (and marker
  2631. (not (with-current-buffer (marker-buffer marker)
  2632. (save-excursion
  2633. (goto-char marker)
  2634. (if (org-entry-get nil "NOBLOCKING")
  2635. t ;; Never block this entry
  2636. (run-hook-with-args-until-failure
  2637. 'org-blocker-hook
  2638. (list :type 'todo-state-change
  2639. :position marker
  2640. :from 'todo
  2641. :to 'done)))))))
  2642. (if org-blocked-by-checkboxes (setq invis1 nil))
  2643. (setq b (if invis1
  2644. (max (point-min) (1- (point-at-bol)))
  2645. (point-at-bol))
  2646. e (point-at-eol)
  2647. ov (org-make-overlay b e))
  2648. (if invis1
  2649. (org-overlay-put ov 'invisible t)
  2650. (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2651. (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
  2652. (defvar org-agenda-skip-function nil
  2653. "Function to be called at each match during agenda construction.
  2654. If this function returns nil, the current match should not be skipped.
  2655. Otherwise, the function must return a position from where the search
  2656. should be continued.
  2657. This may also be a Lisp form, it will be evaluated.
  2658. Never set this variable using `setq' or so, because then it will apply
  2659. to all future agenda commands. Instead, bind it with `let' to scope
  2660. it dynamically into the agenda-constructing command. A good way to set
  2661. it is through options in org-agenda-custom-commands.")
  2662. (defun org-agenda-skip ()
  2663. "Throw to `:skip' in places that should be skipped.
  2664. Also moves point to the end of the skipped region, so that search can
  2665. continue from there."
  2666. (let ((p (point-at-bol)) to fp)
  2667. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2668. (get-text-property p :org-archived)
  2669. (org-end-of-subtree t)
  2670. (throw :skip t))
  2671. (and org-agenda-skip-comment-trees
  2672. (get-text-property p :org-comment)
  2673. (org-end-of-subtree t)
  2674. (throw :skip t))
  2675. (if (equal (char-after p) ?#) (throw :skip t))
  2676. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2677. (consp org-agenda-skip-function))
  2678. (setq to (save-excursion
  2679. (save-match-data
  2680. (if fp
  2681. (funcall org-agenda-skip-function)
  2682. (eval org-agenda-skip-function))))))
  2683. (goto-char to)
  2684. (throw :skip t))))
  2685. (defvar org-agenda-markers nil
  2686. "List of all currently active markers created by `org-agenda'.")
  2687. (defvar org-agenda-last-marker-time (org-float-time)
  2688. "Creation time of the last agenda marker.")
  2689. (defun org-agenda-new-marker (&optional pos)
  2690. "Return a new agenda marker.
  2691. Org-mode keeps a list of these markers and resets them when they are
  2692. no longer in use."
  2693. (let ((m (copy-marker (or pos (point)))))
  2694. (setq org-agenda-last-marker-time (org-float-time))
  2695. (push m org-agenda-markers)
  2696. m))
  2697. (defun org-agenda-reset-markers ()
  2698. "Reset markers created by `org-agenda'."
  2699. (while org-agenda-markers
  2700. (move-marker (pop org-agenda-markers) nil)))
  2701. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2702. "Save relative positions of markers in region."
  2703. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2704. org-agenda-markers))
  2705. ;;; Entry text mode
  2706. (defun org-agenda-entry-text-show-here ()
  2707. "Add some text from the entry as context to the current line."
  2708. (let (m txt o)
  2709. (setq m (org-get-at-bol 'org-hd-marker))
  2710. (unless (marker-buffer m)
  2711. (error "No marker points to an entry here"))
  2712. (setq txt (concat "\n" (org-no-properties
  2713. (org-agenda-get-some-entry-text
  2714. m org-agenda-entry-text-maxlines " > "))))
  2715. (when (string-match "\\S-" txt)
  2716. (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
  2717. (org-overlay-put o 'evaporate t)
  2718. (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
  2719. (org-overlay-put o 'after-string txt))))
  2720. (defun org-agenda-entry-text-show ()
  2721. "Add entry context for all agenda lines."
  2722. (interactive)
  2723. (save-excursion
  2724. (goto-char (point-max))
  2725. (beginning-of-line 1)
  2726. (while (not (bobp))
  2727. (when (org-get-at-bol 'org-hd-marker)
  2728. (org-agenda-entry-text-show-here))
  2729. (beginning-of-line 0))))
  2730. (defun org-agenda-entry-text-hide ()
  2731. "Remove any shown entry context."
  2732. (delq nil
  2733. (mapcar (lambda (o)
  2734. (if (eq (org-overlay-get o 'org-overlay-type)
  2735. 'agenda-entry-content)
  2736. (progn (org-delete-overlay o) t)))
  2737. (org-overlays-in (point-min) (point-max)))))
  2738. ;;; Agenda timeline
  2739. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2740. (defun org-timeline (&optional include-all)
  2741. "Show a time-sorted view of the entries in the current org file.
  2742. Only entries with a time stamp of today or later will be listed. With
  2743. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2744. under the current date.
  2745. If the buffer contains an active region, only check the region for
  2746. dates."
  2747. (interactive "P")
  2748. (require 'calendar)
  2749. (org-compile-prefix-format 'timeline)
  2750. (org-set-sorting-strategy 'timeline)
  2751. (let* ((dopast t)
  2752. (dotodo include-all)
  2753. (doclosed org-agenda-show-log)
  2754. (entry buffer-file-name)
  2755. (date (calendar-current-date))
  2756. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2757. (end (if (org-region-active-p) (region-end) (point-max)))
  2758. (day-numbers (org-get-all-dates beg end 'no-ranges
  2759. t doclosed ; always include today
  2760. org-timeline-show-empty-dates))
  2761. (org-deadline-warning-days 0)
  2762. (org-agenda-only-exact-dates t)
  2763. (today (time-to-days (current-time)))
  2764. (past t)
  2765. args
  2766. s e rtn d emptyp wd)
  2767. (setq org-agenda-redo-command
  2768. (list 'progn
  2769. (list 'org-switch-to-buffer-other-window (current-buffer))
  2770. (list 'org-timeline (list 'quote include-all))))
  2771. (if (not dopast)
  2772. ;; Remove past dates from the list of dates.
  2773. (setq day-numbers (delq nil (mapcar (lambda(x)
  2774. (if (>= x today) x nil))
  2775. day-numbers))))
  2776. (org-prepare-agenda (concat "Timeline "
  2777. (file-name-nondirectory buffer-file-name)))
  2778. (if doclosed (push :closed args))
  2779. (push :timestamp args)
  2780. (push :deadline args)
  2781. (push :scheduled args)
  2782. (push :sexp args)
  2783. (if dotodo (push :todo args))
  2784. (insert "Timeline of file " entry "\n")
  2785. (add-text-properties (point-min) (point)
  2786. (list 'face 'org-agenda-structure))
  2787. (org-agenda-mark-header-line (point-min))
  2788. (while (setq d (pop day-numbers))
  2789. (if (and (listp d) (eq (car d) :omitted))
  2790. (progn
  2791. (setq s (point))
  2792. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2793. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2794. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2795. (if (and (>= d today)
  2796. dopast
  2797. past)
  2798. (progn
  2799. (setq past nil)
  2800. (insert (make-string 79 ?-) "\n")))
  2801. (setq date (calendar-gregorian-from-absolute d)
  2802. wd (calendar-day-of-week date))
  2803. (setq s (point))
  2804. (setq rtn (and (not emptyp)
  2805. (apply 'org-agenda-get-day-entries entry
  2806. date args)))
  2807. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2808. (progn
  2809. (insert
  2810. (if (stringp org-agenda-format-date)
  2811. (format-time-string org-agenda-format-date
  2812. (org-time-from-absolute date))
  2813. (funcall org-agenda-format-date date))
  2814. "\n")
  2815. (put-text-property s (1- (point)) 'face
  2816. (if (member wd org-agenda-weekend-days)
  2817. 'org-agenda-date-weekend
  2818. 'org-agenda-date))
  2819. (put-text-property s (1- (point)) 'org-date-line t)
  2820. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2821. (if (equal d today)
  2822. (put-text-property s (1- (point)) 'org-today t))
  2823. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2824. (put-text-property s (1- (point)) 'day d)))))
  2825. (goto-char (point-min))
  2826. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2827. (point-min)))
  2828. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2829. (org-finalize-agenda)
  2830. (setq buffer-read-only t)))
  2831. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2832. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2833. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2834. not every single day in the range. If FORCE-TODAY is non-nil, make
  2835. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2836. inactive time stamps (those in square brackets) are included.
  2837. When EMPTY is non-nil, also include days without any entries."
  2838. (let ((re (concat
  2839. (if pre-re pre-re "")
  2840. (if inactive org-ts-regexp-both org-ts-regexp)))
  2841. dates dates1 date day day1 day2 ts1 ts2)
  2842. (if force-today
  2843. (setq dates (list (time-to-days (current-time)))))
  2844. (save-excursion
  2845. (goto-char beg)
  2846. (while (re-search-forward re end t)
  2847. (setq day (time-to-days (org-time-string-to-time
  2848. (substring (match-string 1) 0 10))))
  2849. (or (memq day dates) (push day dates)))
  2850. (unless no-ranges
  2851. (goto-char beg)
  2852. (while (re-search-forward org-tr-regexp end t)
  2853. (setq ts1 (substring (match-string 1) 0 10)
  2854. ts2 (substring (match-string 2) 0 10)
  2855. day1 (time-to-days (org-time-string-to-time ts1))
  2856. day2 (time-to-days (org-time-string-to-time ts2)))
  2857. (while (< (setq day1 (1+ day1)) day2)
  2858. (or (memq day1 dates) (push day1 dates)))))
  2859. (setq dates (sort dates '<))
  2860. (when empty
  2861. (while (setq day (pop dates))
  2862. (setq day2 (car dates))
  2863. (push day dates1)
  2864. (when (and day2 empty)
  2865. (if (or (eq empty t)
  2866. (and (numberp empty) (<= (- day2 day) empty)))
  2867. (while (< (setq day (1+ day)) day2)
  2868. (push (list day) dates1))
  2869. (push (cons :omitted (- day2 day)) dates1))))
  2870. (setq dates (nreverse dates1)))
  2871. dates)))
  2872. ;;; Agenda Daily/Weekly
  2873. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2874. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2875. "Custom commands can set this variable in the options section.")
  2876. (defvar org-agenda-last-arguments nil
  2877. "The arguments of the previous call to org-agenda")
  2878. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2879. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2880. (defvar org-include-all-loc nil) ; local variable
  2881. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2882. "List of types searched for when creating the daily/weekly agenda.
  2883. This variable is a list of symbols that controls the types of
  2884. items that appear in the daily/weekly agenda. Allowed symbols in this
  2885. list are are
  2886. :timestamp List items containing a date stamp or date range matching
  2887. the selected date. This includes sexp entries in
  2888. angular brackets.
  2889. :sexp List entries resulting from plain diary-like sexps.
  2890. :deadline List deadline due on that date. When the date is today,
  2891. also list any deadlines past due, or due within
  2892. `org-deadline-warning-days'. `:deadline' must appear before
  2893. `:scheduled' if the setting of
  2894. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2895. any effect.
  2896. :scheduled List all items which are scheduled for the given date.
  2897. The diary for *today* also contains items which were
  2898. scheduled earlier and are not yet marked DONE.
  2899. By default, all four types are turned on.
  2900. Never set this variable globally using `setq', because then it
  2901. will apply to all future agenda commands. Instead, bind it with
  2902. `let' to scope it dynamically into the the agenda-constructing
  2903. command. A good way to set it is through options in
  2904. `org-agenda-custom-commands'. For a more flexible (though
  2905. somewhat less efficient) way of determining what is included in
  2906. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2907. ;;;###autoload
  2908. (defun org-agenda-list (&optional include-all start-day ndays)
  2909. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2910. The view will be for the current day or week, but from the overview buffer
  2911. you will be able to go to other days/weeks.
  2912. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2913. all unfinished TODO items will also be shown, before the agenda.
  2914. This feature is considered obsolete, please use the TODO list or a block
  2915. agenda instead.
  2916. With a numeric prefix argument in an interactive call, the agenda will
  2917. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2918. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2919. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2920. given in `org-agenda-start-on-weekday'."
  2921. (interactive "P")
  2922. (if (and (integerp include-all) (> include-all 0))
  2923. (setq ndays include-all include-all nil))
  2924. (setq ndays (or ndays org-agenda-ndays)
  2925. start-day (or start-day org-agenda-start-day))
  2926. (if org-agenda-overriding-arguments
  2927. (setq include-all (car org-agenda-overriding-arguments)
  2928. start-day (nth 1 org-agenda-overriding-arguments)
  2929. ndays (nth 2 org-agenda-overriding-arguments)))
  2930. (if (stringp start-day)
  2931. ;; Convert to an absolute day number
  2932. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2933. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2934. (org-compile-prefix-format 'agenda)
  2935. (org-set-sorting-strategy 'agenda)
  2936. (require 'calendar)
  2937. (let* ((org-agenda-start-on-weekday
  2938. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2939. org-agenda-start-on-weekday nil))
  2940. (thefiles (org-agenda-files nil 'ifmode))
  2941. (files thefiles)
  2942. (today (time-to-days
  2943. (time-subtract (current-time)
  2944. (list 0 (* 3600 org-extend-today-until) 0))))
  2945. (sd (or start-day today))
  2946. (start (if (or (null org-agenda-start-on-weekday)
  2947. (< org-agenda-ndays 7))
  2948. sd
  2949. (let* ((nt (calendar-day-of-week
  2950. (calendar-gregorian-from-absolute sd)))
  2951. (n1 org-agenda-start-on-weekday)
  2952. (d (- nt n1)))
  2953. (- sd (+ (if (< d 0) 7 0) d)))))
  2954. (day-numbers (list start))
  2955. (day-cnt 0)
  2956. (inhibit-redisplay (not debug-on-error))
  2957. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2958. clocktable-start clocktable-end)
  2959. (setq org-agenda-redo-command
  2960. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2961. ;; Make the list of days
  2962. (setq ndays (or ndays org-agenda-ndays)
  2963. nd ndays)
  2964. (while (> ndays 1)
  2965. (push (1+ (car day-numbers)) day-numbers)
  2966. (setq ndays (1- ndays)))
  2967. (setq day-numbers (nreverse day-numbers))
  2968. (setq clocktable-start (car day-numbers)
  2969. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2970. (org-prepare-agenda "Day/Week")
  2971. (org-set-local 'org-starting-day (car day-numbers))
  2972. (org-set-local 'org-include-all-loc include-all)
  2973. (org-set-local 'org-agenda-span
  2974. (org-agenda-ndays-to-span nd))
  2975. (when (and (or include-all org-agenda-include-all-todo)
  2976. (member today day-numbers))
  2977. (setq files thefiles
  2978. rtnall nil)
  2979. (while (setq file (pop files))
  2980. (catch 'nextfile
  2981. (org-check-agenda-file file)
  2982. (setq date (calendar-gregorian-from-absolute today)
  2983. rtn (org-agenda-get-day-entries
  2984. file date :todo))
  2985. (setq rtnall (append rtnall rtn))))
  2986. (when rtnall
  2987. (insert "All currently open TODO items:\n")
  2988. (add-text-properties (point-min) (1- (point))
  2989. (list 'face 'org-agenda-structure
  2990. 'short-heading "All TODO items"))
  2991. (org-agenda-mark-header-line (point-min))
  2992. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2993. (unless org-agenda-compact-blocks
  2994. (let* ((d1 (car day-numbers))
  2995. (d2 (org-last day-numbers))
  2996. (w1 (org-days-to-iso-week d1))
  2997. (w2 (org-days-to-iso-week d2)))
  2998. (setq s (point))
  2999. (if org-agenda-overriding-header
  3000. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3001. nil 'face 'org-agenda-structure) "\n")
  3002. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3003. "-agenda"
  3004. (if (< (- d2 d1) 350)
  3005. (if (= w1 w2)
  3006. (format " (W%02d)" w1)
  3007. (format " (W%02d-W%02d)" w1 w2))
  3008. "")
  3009. ":\n")))
  3010. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3011. 'org-date-line t))
  3012. (org-agenda-mark-header-line s))
  3013. (while (setq d (pop day-numbers))
  3014. (setq date (calendar-gregorian-from-absolute d)
  3015. wd (calendar-day-of-week date)
  3016. s (point))
  3017. (if (or (setq todayp (= d today))
  3018. (and (not start-pos) (= d sd)))
  3019. (setq start-pos (point))
  3020. (if (and start-pos (not end-pos))
  3021. (setq end-pos (point))))
  3022. (setq files thefiles
  3023. rtnall nil)
  3024. (while (setq file (pop files))
  3025. (catch 'nextfile
  3026. (org-check-agenda-file file)
  3027. (let ((org-agenda-entry-types org-agenda-entry-types))
  3028. (unless org-agenda-include-deadlines
  3029. (setq org-agenda-entry-types
  3030. (delq :deadline org-agenda-entry-types)))
  3031. (cond
  3032. ((eq org-agenda-show-log 'only)
  3033. (setq rtn (org-agenda-get-day-entries
  3034. file date :closed)))
  3035. (org-agenda-show-log
  3036. (setq rtn (apply 'org-agenda-get-day-entries
  3037. file date
  3038. (append '(:closed) org-agenda-entry-types))))
  3039. (t
  3040. (setq rtn (apply 'org-agenda-get-day-entries
  3041. file date
  3042. org-agenda-entry-types)))))
  3043. (setq rtnall (append rtnall rtn))))
  3044. (if org-agenda-include-diary
  3045. (let ((org-agenda-search-headline-for-time t))
  3046. (require 'diary-lib)
  3047. (setq rtn (org-get-entries-from-diary date))
  3048. (setq rtnall (append rtnall rtn))))
  3049. (if (or rtnall org-agenda-show-all-dates)
  3050. (progn
  3051. (setq day-cnt (1+ day-cnt))
  3052. (insert
  3053. (if (stringp org-agenda-format-date)
  3054. (format-time-string org-agenda-format-date
  3055. (org-time-from-absolute date))
  3056. (funcall org-agenda-format-date date))
  3057. "\n")
  3058. (put-text-property s (1- (point)) 'face
  3059. (if (member wd org-agenda-weekend-days)
  3060. 'org-agenda-date-weekend
  3061. 'org-agenda-date))
  3062. (put-text-property s (1- (point)) 'org-date-line t)
  3063. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3064. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3065. (when todayp
  3066. (put-text-property s (1- (point)) 'org-today t)
  3067. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3068. (if rtnall (insert
  3069. (org-finalize-agenda-entries
  3070. (org-agenda-add-time-grid-maybe
  3071. rtnall nd todayp))
  3072. "\n"))
  3073. (put-text-property s (1- (point)) 'day d)
  3074. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3075. (when (and org-agenda-clockreport-mode clocktable-start)
  3076. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3077. ;; the above line is to ensure the restricted range!
  3078. (p org-agenda-clockreport-parameter-plist)
  3079. tbl)
  3080. (setq p (org-plist-delete p :block))
  3081. (setq p (plist-put p :tstart clocktable-start))
  3082. (setq p (plist-put p :tend clocktable-end))
  3083. (setq p (plist-put p :scope 'agenda))
  3084. (setq tbl (apply 'org-get-clocktable p))
  3085. (insert tbl)))
  3086. (goto-char (point-min))
  3087. (or org-agenda-multi (org-fit-agenda-window))
  3088. (unless (and (pos-visible-in-window-p (point-min))
  3089. (pos-visible-in-window-p (point-max)))
  3090. (goto-char (1- (point-max)))
  3091. (recenter -1)
  3092. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3093. (progn
  3094. (goto-char (or start-pos 1))
  3095. (recenter 1))))
  3096. (goto-char (or start-pos 1))
  3097. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3098. (org-finalize-agenda)
  3099. (setq buffer-read-only t)
  3100. (message "")))
  3101. (defun org-agenda-ndays-to-span (n)
  3102. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3103. ;;; Agenda word search
  3104. (defvar org-agenda-search-history nil)
  3105. (defvar org-todo-only nil)
  3106. (defvar org-search-syntax-table nil
  3107. "Special syntax table for org-mode search.
  3108. In this table, we have single quotes not as word constituents, to
  3109. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3110. (defun org-search-syntax-table ()
  3111. (unless org-search-syntax-table
  3112. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3113. (modify-syntax-entry ?' "." org-search-syntax-table)
  3114. (modify-syntax-entry ?` "." org-search-syntax-table))
  3115. org-search-syntax-table)
  3116. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3117. ;;;###autoload
  3118. (defun org-search-view (&optional todo-only string edit-at)
  3119. "Show all entries that contain a phrase or words or regular expressions.
  3120. With optional prefix argument TODO-ONLY, only consider entries that are
  3121. TODO entries. The argument STRING can be used to pass a default search
  3122. string into this function. If EDIT-AT is non-nil, it means that the
  3123. user should get a chance to edit this string, with cursor at position
  3124. EDIT-AT.
  3125. The search string can be viewed either as a phrase that should be found as
  3126. is, or it can be broken into a number of snippets, each of which must match
  3127. in a Boolean way to select an entry. The default depends on the variable
  3128. `org-agenda-search-view-always-boolean'.
  3129. Even if this is turned off (the default) you can always switch to
  3130. Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
  3131. The default is a direct search of the whole phrase, where each space in
  3132. the search string can expand to an arbitrary amount of whitespace,
  3133. including newlines.
  3134. If using a Boolean search, the search string is split on whitespace and
  3135. each snippet is searched separately, with logical AND to select an entry.
  3136. Words prefixed with a minus must *not* occur in the entry. Words without
  3137. a prefix or prefixed with a plus must occur in the entry. Matching is
  3138. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3139. match whole words, not parts of a word) if
  3140. `org-agenda-search-view-force-full-words' is set (default is nil).
  3141. Boolean search snippets enclosed by curly braces are interpreted as
  3142. regular expressions that must or (when preceeded with \"-\") must not
  3143. match in the entry. Snippets enclosed into double quotes will be taken
  3144. as a whole, to incude whitespace.
  3145. - If the search string starts with an asterisk, search only in headlines.
  3146. - If (possibly after the leading star) the search string starts with an
  3147. exclamation mark, this also means to look at TODO entries only, an effect
  3148. that can also be achieved with a prefix argument.
  3149. - If (possibly after star and exclamation mark) the search string starts
  3150. with a colon, this will mean that the (non-regexp) snippets of the
  3151. Boolean search must match as full words.
  3152. This command searches the agenda files, and in addition the files listed
  3153. in `org-agenda-text-search-extra-files'."
  3154. (interactive "P")
  3155. (org-compile-prefix-format 'search)
  3156. (org-set-sorting-strategy 'search)
  3157. (org-prepare-agenda "SEARCH")
  3158. (let* ((props (list 'face nil
  3159. 'done-face 'org-agenda-done
  3160. 'org-not-done-regexp org-not-done-regexp
  3161. 'org-todo-regexp org-todo-regexp
  3162. 'org-complex-heading-regexp org-complex-heading-regexp
  3163. 'mouse-face 'highlight
  3164. 'help-echo (format "mouse-2 or RET jump to location")))
  3165. (full-words org-agenda-search-view-force-full-words)
  3166. regexp rtn rtnall files file pos
  3167. marker category tags c neg re boolean
  3168. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3169. (unless (and (not edit-at)
  3170. (stringp string)
  3171. (string-match "\\S-" string))
  3172. (setq string (read-string
  3173. (if org-agenda-search-view-always-boolean
  3174. "[+-]Word/{Regexp} ...: "
  3175. "Phrase, or [+-]Word/{Regexp} ...: ")
  3176. (cond
  3177. ((integerp edit-at) (cons string edit-at))
  3178. (edit-at string))
  3179. 'org-agenda-search-history)))
  3180. (org-set-local 'org-todo-only todo-only)
  3181. (setq org-agenda-redo-command
  3182. (list 'org-search-view (if todo-only t nil) string
  3183. '(if current-prefix-arg 1 nil)))
  3184. (setq org-agenda-query-string string)
  3185. (if (equal (string-to-char string) ?*)
  3186. (setq hdl-only t
  3187. words (substring string 1))
  3188. (setq words string))
  3189. (when (equal (string-to-char words) ?!)
  3190. (setq todo-only t
  3191. words (substring words 1)))
  3192. (when (equal (string-to-char words) ?:)
  3193. (setq full-words t
  3194. words (substring words 1)))
  3195. (if (or org-agenda-search-view-always-boolean
  3196. (member (string-to-char words) '(?- ?+ ?\{)))
  3197. (setq boolean t))
  3198. (setq words (org-split-string words))
  3199. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3200. (when boolean
  3201. (let (wds w)
  3202. (while (setq w (pop words))
  3203. (if (or (equal (substring w 0 1) "\"")
  3204. (and (> (length w) 1)
  3205. (member (substring w 0 1) '("+" "-"))
  3206. (equal (substring w 1 2) "\"")))
  3207. (while (and words (not (equal (substring w -1) "\"")))
  3208. (setq w (concat w " " (pop words)))))
  3209. (and (string-match "\\`\\([-+]?\\)\"" w)
  3210. (setq w (replace-match "\\1" nil nil w)))
  3211. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3212. (push w wds))
  3213. (setq words (nreverse wds))))
  3214. (if boolean
  3215. (mapc (lambda (w)
  3216. (setq c (string-to-char w))
  3217. (if (equal c ?-)
  3218. (setq neg t w (substring w 1))
  3219. (if (equal c ?+)
  3220. (setq neg nil w (substring w 1))
  3221. (setq neg nil)))
  3222. (if (string-match "\\`{.*}\\'" w)
  3223. (setq re (substring w 1 -1))
  3224. (if full-words
  3225. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3226. (setq re (regexp-quote (downcase w)))))
  3227. (if neg (push re regexps-) (push re regexps+)))
  3228. words)
  3229. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3230. regexps+))
  3231. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3232. (if (not regexps+)
  3233. (setq regexp (concat "^" org-outline-regexp))
  3234. (setq regexp (pop regexps+))
  3235. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3236. regexp))))
  3237. (setq files (org-agenda-files nil 'ifmode))
  3238. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3239. (pop org-agenda-text-search-extra-files)
  3240. (setq files (org-add-archive-files files)))
  3241. (setq files (append files org-agenda-text-search-extra-files)
  3242. rtnall nil)
  3243. (while (setq file (pop files))
  3244. (setq ee nil)
  3245. (catch 'nextfile
  3246. (org-check-agenda-file file)
  3247. (setq buffer (if (file-exists-p file)
  3248. (org-get-agenda-file-buffer file)
  3249. (error "No such file %s" file)))
  3250. (if (not buffer)
  3251. ;; If file does not exist, make sure an error message is sent
  3252. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3253. file))))
  3254. (with-current-buffer buffer
  3255. (with-syntax-table (org-search-syntax-table)
  3256. (unless (org-mode-p)
  3257. (error "Agenda file %s is not in `org-mode'" file))
  3258. (let ((case-fold-search t))
  3259. (save-excursion
  3260. (save-restriction
  3261. (if org-agenda-restrict
  3262. (narrow-to-region org-agenda-restrict-begin
  3263. org-agenda-restrict-end)
  3264. (widen))
  3265. (goto-char (point-min))
  3266. (unless (or (org-on-heading-p)
  3267. (outline-next-heading))
  3268. (throw 'nextfile t))
  3269. (goto-char (max (point-min) (1- (point))))
  3270. (while (re-search-forward regexp nil t)
  3271. (org-back-to-heading t)
  3272. (skip-chars-forward "* ")
  3273. (setq beg (point-at-bol)
  3274. beg1 (point)
  3275. end (progn (outline-next-heading) (point)))
  3276. (catch :skip
  3277. (goto-char beg)
  3278. (org-agenda-skip)
  3279. (setq str (buffer-substring-no-properties
  3280. (point-at-bol)
  3281. (if hdl-only (point-at-eol) end)))
  3282. (mapc (lambda (wr) (when (string-match wr str)
  3283. (goto-char (1- end))
  3284. (throw :skip t)))
  3285. regexps-)
  3286. (mapc (lambda (wr) (unless (string-match wr str)
  3287. (goto-char (1- end))
  3288. (throw :skip t)))
  3289. (if todo-only
  3290. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3291. regexps+)
  3292. regexps+))
  3293. (goto-char beg)
  3294. (setq marker (org-agenda-new-marker (point))
  3295. category (org-get-category)
  3296. tags (org-get-tags-at (point))
  3297. txt (org-format-agenda-item
  3298. ""
  3299. (buffer-substring-no-properties
  3300. beg1 (point-at-eol))
  3301. category tags))
  3302. (org-add-props txt props
  3303. 'org-marker marker 'org-hd-marker marker
  3304. 'org-todo-regexp org-todo-regexp
  3305. 'org-complex-heading-regexp org-complex-heading-regexp
  3306. 'priority 1000 'org-category category
  3307. 'type "search")
  3308. (push txt ee)
  3309. (goto-char (1- end))))))))))
  3310. (setq rtn (nreverse ee))
  3311. (setq rtnall (append rtnall rtn)))
  3312. (if org-agenda-overriding-header
  3313. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3314. nil 'face 'org-agenda-structure) "\n")
  3315. (insert "Search words: ")
  3316. (add-text-properties (point-min) (1- (point))
  3317. (list 'face 'org-agenda-structure))
  3318. (setq pos (point))
  3319. (insert string "\n")
  3320. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3321. (setq pos (point))
  3322. (unless org-agenda-multi
  3323. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3324. (add-text-properties pos (1- (point))
  3325. (list 'face 'org-agenda-structure))))
  3326. (org-agenda-mark-header-line (point-min))
  3327. (when rtnall
  3328. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3329. (goto-char (point-min))
  3330. (or org-agenda-multi (org-fit-agenda-window))
  3331. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3332. (org-finalize-agenda)
  3333. (setq buffer-read-only t)))
  3334. ;;; Agenda TODO list
  3335. (defvar org-select-this-todo-keyword nil)
  3336. (defvar org-last-arg nil)
  3337. ;;;###autoload
  3338. (defun org-todo-list (arg)
  3339. "Show all TODO entries from all agenda file in a single list.
  3340. The prefix arg can be used to select a specific TODO keyword and limit
  3341. the list to these. When using \\[universal-argument], you will be prompted
  3342. for a keyword. A numeric prefix directly selects the Nth keyword in
  3343. `org-todo-keywords-1'."
  3344. (interactive "P")
  3345. (require 'calendar)
  3346. (org-compile-prefix-format 'todo)
  3347. (org-set-sorting-strategy 'todo)
  3348. (org-prepare-agenda "TODO")
  3349. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3350. (let* ((today (time-to-days (current-time)))
  3351. (date (calendar-gregorian-from-absolute today))
  3352. (kwds org-todo-keywords-for-agenda)
  3353. (completion-ignore-case t)
  3354. (org-select-this-todo-keyword
  3355. (if (stringp arg) arg
  3356. (and arg (integerp arg) (> arg 0)
  3357. (nth (1- arg) kwds))))
  3358. rtn rtnall files file pos)
  3359. (when (equal arg '(4))
  3360. (setq org-select-this-todo-keyword
  3361. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3362. (mapcar 'list kwds) nil nil)))
  3363. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3364. (org-set-local 'org-last-arg arg)
  3365. (setq org-agenda-redo-command
  3366. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3367. (setq files (org-agenda-files nil 'ifmode)
  3368. rtnall nil)
  3369. (while (setq file (pop files))
  3370. (catch 'nextfile
  3371. (org-check-agenda-file file)
  3372. (setq rtn (org-agenda-get-day-entries file date :todo))
  3373. (setq rtnall (append rtnall rtn))))
  3374. (if org-agenda-overriding-header
  3375. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3376. nil 'face 'org-agenda-structure) "\n")
  3377. (insert "Global list of TODO items of type: ")
  3378. (add-text-properties (point-min) (1- (point))
  3379. (list 'face 'org-agenda-structure
  3380. 'short-heading
  3381. (concat "ToDo: "
  3382. (or org-select-this-todo-keyword "ALL"))))
  3383. (org-agenda-mark-header-line (point-min))
  3384. (setq pos (point))
  3385. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3386. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3387. (setq pos (point))
  3388. (unless org-agenda-multi
  3389. (insert "Available with `N r': (0)ALL")
  3390. (let ((n 0) s)
  3391. (mapc (lambda (x)
  3392. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3393. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3394. (insert "\n "))
  3395. (insert " " s))
  3396. kwds))
  3397. (insert "\n"))
  3398. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3399. (org-agenda-mark-header-line (point-min))
  3400. (when rtnall
  3401. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3402. (goto-char (point-min))
  3403. (or org-agenda-multi (org-fit-agenda-window))
  3404. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3405. (org-finalize-agenda)
  3406. (setq buffer-read-only t)))
  3407. ;;; Agenda tags match
  3408. ;;;###autoload
  3409. (defun org-tags-view (&optional todo-only match)
  3410. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3411. The prefix arg TODO-ONLY limits the search to TODO entries."
  3412. (interactive "P")
  3413. (org-compile-prefix-format 'tags)
  3414. (org-set-sorting-strategy 'tags)
  3415. (let* ((org-tags-match-list-sublevels
  3416. org-tags-match-list-sublevels)
  3417. (completion-ignore-case t)
  3418. rtn rtnall files file pos matcher
  3419. buffer)
  3420. (when (and (stringp match) (not (string-match "\\S-" match)))
  3421. (setq match nil))
  3422. (setq matcher (org-make-tags-matcher match)
  3423. match (car matcher) matcher (cdr matcher))
  3424. (org-prepare-agenda (concat "TAGS " match))
  3425. (setq org-agenda-query-string match)
  3426. (setq org-agenda-redo-command
  3427. (list 'org-tags-view (list 'quote todo-only)
  3428. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3429. (setq files (org-agenda-files nil 'ifmode)
  3430. rtnall nil)
  3431. (while (setq file (pop files))
  3432. (catch 'nextfile
  3433. (org-check-agenda-file file)
  3434. (setq buffer (if (file-exists-p file)
  3435. (org-get-agenda-file-buffer file)
  3436. (error "No such file %s" file)))
  3437. (if (not buffer)
  3438. ;; If file does not exist, error message to agenda
  3439. (setq rtn (list
  3440. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3441. rtnall (append rtnall rtn))
  3442. (with-current-buffer buffer
  3443. (unless (org-mode-p)
  3444. (error "Agenda file %s is not in `org-mode'" file))
  3445. (save-excursion
  3446. (save-restriction
  3447. (if org-agenda-restrict
  3448. (narrow-to-region org-agenda-restrict-begin
  3449. org-agenda-restrict-end)
  3450. (widen))
  3451. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3452. (setq rtnall (append rtnall rtn))))))))
  3453. (if org-agenda-overriding-header
  3454. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3455. nil 'face 'org-agenda-structure) "\n")
  3456. (insert "Headlines with TAGS match: ")
  3457. (add-text-properties (point-min) (1- (point))
  3458. (list 'face 'org-agenda-structure
  3459. 'short-heading
  3460. (concat "Match: " match)))
  3461. (setq pos (point))
  3462. (insert match "\n")
  3463. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3464. (setq pos (point))
  3465. (unless org-agenda-multi
  3466. (insert "Press `C-u r' to search again with new search string\n"))
  3467. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3468. (org-agenda-mark-header-line (point-min))
  3469. (when rtnall
  3470. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3471. (goto-char (point-min))
  3472. (or org-agenda-multi (org-fit-agenda-window))
  3473. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3474. (org-finalize-agenda)
  3475. (setq buffer-read-only t)))
  3476. ;;; Agenda Finding stuck projects
  3477. (defvar org-agenda-skip-regexp nil
  3478. "Regular expression used in skipping subtrees for the agenda.
  3479. This is basically a temporary global variable that can be set and then
  3480. used by user-defined selections using `org-agenda-skip-function'.")
  3481. (defvar org-agenda-overriding-header nil
  3482. "When this is set during todo and tags searches, will replace header.
  3483. This variable should not be set directly, but custom commands can bind it
  3484. in the options section.")
  3485. (defun org-agenda-skip-entry-when-regexp-matches ()
  3486. "Checks if the current entry contains match for `org-agenda-skip-regexp'.
  3487. If yes, it returns the end position of this entry, causing agenda commands
  3488. to skip the entry but continuing the search in the subtree. This is a
  3489. function that can be put into `org-agenda-skip-function' for the duration
  3490. of a command."
  3491. (let ((end (save-excursion (org-end-of-subtree t)))
  3492. skip)
  3493. (save-excursion
  3494. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3495. (and skip end)))
  3496. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3497. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3498. If yes, it returns the end position of this tree, causing agenda commands
  3499. to skip this subtree. This is a function that can be put into
  3500. `org-agenda-skip-function' for the duration of a command."
  3501. (let ((end (save-excursion (org-end-of-subtree t)))
  3502. skip)
  3503. (save-excursion
  3504. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3505. (and skip end)))
  3506. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3507. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3508. If yes, it returns the end position of the current entry (NOT the tree),
  3509. causing agenda commands to skip the entry but continuing the search in
  3510. the subtree. This is a function that can be put into
  3511. `org-agenda-skip-function' for the duration of a command. An important
  3512. use of this function is for the stuck project list."
  3513. (let ((end (save-excursion (org-end-of-subtree t)))
  3514. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3515. skip)
  3516. (save-excursion
  3517. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3518. (and skip entry-end)))
  3519. (defun org-agenda-skip-entry-if (&rest conditions)
  3520. "Skip entry if any of CONDITIONS is true.
  3521. See `org-agenda-skip-if' for details."
  3522. (org-agenda-skip-if nil conditions))
  3523. (defun org-agenda-skip-subtree-if (&rest conditions)
  3524. "Skip entry if any of CONDITIONS is true.
  3525. See `org-agenda-skip-if' for details."
  3526. (org-agenda-skip-if t conditions))
  3527. (defun org-agenda-skip-if (subtree conditions)
  3528. "Checks current entity for CONDITIONS.
  3529. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3530. the entry, i.e. the text before the next heading is checked.
  3531. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3532. from different tests. Valid conditions are:
  3533. scheduled Check if there is a scheduled cookie
  3534. notscheduled Check if there is no scheduled cookie
  3535. deadline Check if there is a deadline
  3536. notdeadline Check if there is no deadline
  3537. timestamp Check if there is a timestamp (also deadline or scheduled)
  3538. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3539. regexp Check if regexp matches
  3540. notregexp Check if regexp does not match.
  3541. todo Check if TODO keyword matches
  3542. nottodo Check if TODO keyword does not match
  3543. The regexp is taken from the conditions list, it must come right after
  3544. the `regexp' or `notregexp' element.
  3545. `todo' and `nottodo' accept as an argument a list of todo
  3546. keywords, which may include \"*\" to match any todo keyword.
  3547. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3548. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3549. Instead of a list a keyword class may be given
  3550. (org-agenda-skip-entry-if 'nottodo 'done)
  3551. would skip entries that haven't been marked with any of \"DONE\"
  3552. keywords. Possible classes are: `todo', `done', `any'.
  3553. If any of these conditions is met, this function returns the end point of
  3554. the entity, causing the search to continue from there. This is a function
  3555. that can be put into `org-agenda-skip-function' for the duration of a command."
  3556. (let (beg end m)
  3557. (org-back-to-heading t)
  3558. (setq beg (point)
  3559. end (if subtree
  3560. (progn (org-end-of-subtree t) (point))
  3561. (progn (outline-next-heading) (1- (point)))))
  3562. (goto-char beg)
  3563. (and
  3564. (or
  3565. (and (memq 'scheduled conditions)
  3566. (re-search-forward org-scheduled-time-regexp end t))
  3567. (and (memq 'notscheduled conditions)
  3568. (not (re-search-forward org-scheduled-time-regexp end t)))
  3569. (and (memq 'deadline conditions)
  3570. (re-search-forward org-deadline-time-regexp end t))
  3571. (and (memq 'notdeadline conditions)
  3572. (not (re-search-forward org-deadline-time-regexp end t)))
  3573. (and (memq 'timestamp conditions)
  3574. (re-search-forward org-ts-regexp end t))
  3575. (and (memq 'nottimestamp conditions)
  3576. (not (re-search-forward org-ts-regexp end t)))
  3577. (and (setq m (memq 'regexp conditions))
  3578. (stringp (nth 1 m))
  3579. (re-search-forward (nth 1 m) end t))
  3580. (and (setq m (memq 'notregexp conditions))
  3581. (stringp (nth 1 m))
  3582. (not (re-search-forward (nth 1 m) end t)))
  3583. (and (or
  3584. (setq m (memq 'todo conditions))
  3585. (setq m (memq 'nottodo conditions)))
  3586. (org-agenda-skip-if-todo m end)))
  3587. end)))
  3588. (defun org-agenda-skip-if-todo (args end)
  3589. "Helper function for `org-agenda-skip-if', do not use it directly.
  3590. ARGS is a list with first element either `todo' or `nottodo'.
  3591. The remainder is either a list of TODO keywords, or a state symbol
  3592. `todo' or `done' or `any'."
  3593. (let ((kw (car args))
  3594. (arg (cadr args))
  3595. todo-wds todo-re)
  3596. (setq todo-wds
  3597. (org-uniquify
  3598. (cond
  3599. ((listp arg) ;; list of keywords
  3600. (if (member "*" arg)
  3601. (mapcar 'substring-no-properties org-todo-keywords-1)
  3602. arg))
  3603. ((symbolp arg) ;; keyword class name
  3604. (cond
  3605. ((eq arg 'todo)
  3606. (org-delete-all org-done-keywords
  3607. (mapcar 'substring-no-properties
  3608. org-todo-keywords-1)))
  3609. ((eq arg 'done) org-done-keywords)
  3610. ((eq arg 'any)
  3611. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3612. (setq todo-re
  3613. (concat "^\\*+[ \t]+\\<\\("
  3614. (mapconcat 'identity todo-wds "\\|")
  3615. "\\)\\>"))
  3616. (if (eq kw 'todo)
  3617. (re-search-forward todo-re end t)
  3618. (not (re-search-forward todo-re end t)))))
  3619. ;;;###autoload
  3620. (defun org-agenda-list-stuck-projects (&rest ignore)
  3621. "Create agenda view for projects that are stuck.
  3622. Stuck projects are project that have no next actions. For the definitions
  3623. of what a project is and how to check if it stuck, customize the variable
  3624. `org-stuck-projects'.
  3625. MATCH is being ignored."
  3626. (interactive)
  3627. (let* ((org-agenda-skip-function
  3628. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3629. ;; We could have used org-agenda-skip-if here.
  3630. (org-agenda-overriding-header
  3631. (or org-agenda-overriding-header "List of stuck projects: "))
  3632. (matcher (nth 0 org-stuck-projects))
  3633. (todo (nth 1 org-stuck-projects))
  3634. (todo-wds (if (member "*" todo)
  3635. (progn
  3636. (org-prepare-agenda-buffers (org-agenda-files
  3637. nil 'ifmode))
  3638. (org-delete-all
  3639. org-done-keywords-for-agenda
  3640. (copy-sequence org-todo-keywords-for-agenda)))
  3641. todo))
  3642. (todo-re (concat "^\\*+[ \t]+\\("
  3643. (mapconcat 'identity todo-wds "\\|")
  3644. "\\)\\>"))
  3645. (tags (nth 2 org-stuck-projects))
  3646. (tags-re (if (member "*" tags)
  3647. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3648. (if tags
  3649. (concat "^\\*+ .*:\\("
  3650. (mapconcat 'identity tags "\\|")
  3651. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3652. (gen-re (nth 3 org-stuck-projects))
  3653. (re-list
  3654. (delq nil
  3655. (list
  3656. (if todo todo-re)
  3657. (if tags tags-re)
  3658. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3659. gen-re)))))
  3660. (setq org-agenda-skip-regexp
  3661. (if re-list
  3662. (mapconcat 'identity re-list "\\|")
  3663. (error "No information how to identify unstuck projects")))
  3664. (org-tags-view nil matcher)
  3665. (with-current-buffer org-agenda-buffer-name
  3666. (setq org-agenda-redo-command
  3667. '(org-agenda-list-stuck-projects
  3668. (or current-prefix-arg org-last-arg))))))
  3669. ;;; Diary integration
  3670. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3671. (defvar list-diary-entries-hook)
  3672. (defun org-get-entries-from-diary (date)
  3673. "Get the (Emacs Calendar) diary entries for DATE."
  3674. (require 'diary-lib)
  3675. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3676. (fancy-diary-buffer diary-fancy-buffer)
  3677. (diary-display-hook '(fancy-diary-display))
  3678. (diary-display-function 'fancy-diary-display)
  3679. (pop-up-frames nil)
  3680. (list-diary-entries-hook
  3681. (cons 'org-diary-default-entry list-diary-entries-hook))
  3682. (diary-file-name-prefix-function nil) ; turn this feature off
  3683. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3684. entries
  3685. (org-disable-agenda-to-diary t))
  3686. (save-excursion
  3687. (save-window-excursion
  3688. (funcall (if (fboundp 'diary-list-entries)
  3689. 'diary-list-entries 'list-diary-entries)
  3690. date 1)))
  3691. (if (not (get-buffer diary-fancy-buffer))
  3692. (setq entries nil)
  3693. (with-current-buffer diary-fancy-buffer
  3694. (setq buffer-read-only nil)
  3695. (if (zerop (buffer-size))
  3696. ;; No entries
  3697. (setq entries nil)
  3698. ;; Omit the date and other unnecessary stuff
  3699. (org-agenda-cleanup-fancy-diary)
  3700. ;; Add prefix to each line and extend the text properties
  3701. (if (zerop (buffer-size))
  3702. (setq entries nil)
  3703. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3704. (set-buffer-modified-p nil)
  3705. (kill-buffer diary-fancy-buffer)))
  3706. (when entries
  3707. (setq entries (org-split-string entries "\n"))
  3708. (setq entries
  3709. (mapcar
  3710. (lambda (x)
  3711. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3712. ;; Extend the text properties to the beginning of the line
  3713. (org-add-props x (text-properties-at (1- (length x)) x)
  3714. 'type "diary" 'date date 'face 'org-agenda-diary))
  3715. entries)))))
  3716. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3717. "Hook run when the fancy diary buffer is cleaned up.")
  3718. (defun org-agenda-cleanup-fancy-diary ()
  3719. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3720. This gets rid of the date, the underline under the date, and
  3721. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3722. date. It also removes lines that contain only whitespace."
  3723. (goto-char (point-min))
  3724. (if (looking-at ".*?:[ \t]*")
  3725. (progn
  3726. (replace-match "")
  3727. (re-search-forward "\n=+$" nil t)
  3728. (replace-match "")
  3729. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3730. (re-search-forward "\n=+$" nil t)
  3731. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3732. (goto-char (point-min))
  3733. (while (re-search-forward "^ +\n" nil t)
  3734. (replace-match ""))
  3735. (goto-char (point-min))
  3736. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3737. (replace-match ""))
  3738. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3739. ;; Make sure entries from the diary have the right text properties.
  3740. (eval-after-load "diary-lib"
  3741. '(if (boundp 'diary-modify-entry-list-string-function)
  3742. ;; We can rely on the hook, nothing to do
  3743. nil
  3744. ;; Hook not available, must use advice to make this work
  3745. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3746. "Make the position visible."
  3747. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3748. (stringp string)
  3749. buffer-file-name)
  3750. (setq string (org-modify-diary-entry-string string))))))
  3751. (defun org-modify-diary-entry-string (string)
  3752. "Add text properties to string, allowing org-mode to act on it."
  3753. (org-add-props string nil
  3754. 'mouse-face 'highlight
  3755. 'help-echo (if buffer-file-name
  3756. (format "mouse-2 or RET jump to diary file %s"
  3757. (abbreviate-file-name buffer-file-name))
  3758. "")
  3759. 'org-agenda-diary-link t
  3760. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3761. (defun org-diary-default-entry ()
  3762. "Add a dummy entry to the diary.
  3763. Needed to avoid empty dates which mess up holiday display."
  3764. ;; Catch the error if dealing with the new add-to-diary-alist
  3765. (when org-disable-agenda-to-diary
  3766. (condition-case nil
  3767. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3768. (error
  3769. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3770. (defun org-add-to-diary-list (&rest args)
  3771. (if (fboundp 'diary-add-to-list)
  3772. (apply 'diary-add-to-list args)
  3773. (apply 'add-to-diary-list args)))
  3774. (defvar org-diary-last-run-time nil)
  3775. ;;;###autoload
  3776. (defun org-diary (&rest args)
  3777. "Return diary information from org-files.
  3778. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3779. It accesses org files and extracts information from those files to be
  3780. listed in the diary. The function accepts arguments specifying what
  3781. items should be listed. For a list of arguments allowed here, see the
  3782. variable `org-agenda-entry-types'.
  3783. The call in the diary file should look like this:
  3784. &%%(org-diary) ~/path/to/some/orgfile.org
  3785. Use a separate line for each org file to check. Or, if you omit the file name,
  3786. all files listed in `org-agenda-files' will be checked automatically:
  3787. &%%(org-diary)
  3788. If you don't give any arguments (as in the example above), the default
  3789. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3790. So the example above may also be written as
  3791. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3792. The function expects the lisp variables `entry' and `date' to be provided
  3793. by the caller, because this is how the calendar works. Don't use this
  3794. function from a program - use `org-agenda-get-day-entries' instead."
  3795. (when (> (- (org-float-time)
  3796. org-agenda-last-marker-time)
  3797. 5)
  3798. (org-agenda-reset-markers))
  3799. (org-compile-prefix-format 'agenda)
  3800. (org-set-sorting-strategy 'agenda)
  3801. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3802. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3803. (list entry)
  3804. (org-agenda-files t)))
  3805. (time (org-float-time))
  3806. file rtn results)
  3807. (when (or (not org-diary-last-run-time)
  3808. (> (- time
  3809. org-diary-last-run-time)
  3810. 3))
  3811. (org-prepare-agenda-buffers files))
  3812. (setq org-diary-last-run-time time)
  3813. ;; If this is called during org-agenda, don't return any entries to
  3814. ;; the calendar. Org Agenda will list these entries itself.
  3815. (if org-disable-agenda-to-diary (setq files nil))
  3816. (while (setq file (pop files))
  3817. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3818. (setq results (append results rtn)))
  3819. (if results
  3820. (concat (org-finalize-agenda-entries results) "\n"))))
  3821. ;;; Agenda entry finders
  3822. (defun org-agenda-get-day-entries (file date &rest args)
  3823. "Does the work for `org-diary' and `org-agenda'.
  3824. FILE is the path to a file to be checked for entries. DATE is date like
  3825. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3826. which kind of entries should be extracted. For details about these, see
  3827. the documentation of `org-diary'."
  3828. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3829. (let* ((org-startup-folded nil)
  3830. (org-startup-align-all-tables nil)
  3831. (buffer (if (file-exists-p file)
  3832. (org-get-agenda-file-buffer file)
  3833. (error "No such file %s" file)))
  3834. arg results rtn deadline-results)
  3835. (if (not buffer)
  3836. ;; If file does not exist, make sure an error message ends up in diary
  3837. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3838. (with-current-buffer buffer
  3839. (unless (org-mode-p)
  3840. (error "Agenda file %s is not in `org-mode'" file))
  3841. (let ((case-fold-search nil))
  3842. (save-excursion
  3843. (save-restriction
  3844. (if org-agenda-restrict
  3845. (narrow-to-region org-agenda-restrict-begin
  3846. org-agenda-restrict-end)
  3847. (widen))
  3848. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3849. (while (setq arg (pop args))
  3850. (cond
  3851. ((and (eq arg :todo)
  3852. (equal date (calendar-current-date)))
  3853. (setq rtn (org-agenda-get-todos))
  3854. (setq results (append results rtn)))
  3855. ((eq arg :timestamp)
  3856. (setq rtn (org-agenda-get-blocks))
  3857. (setq results (append results rtn))
  3858. (setq rtn (org-agenda-get-timestamps))
  3859. (setq results (append results rtn)))
  3860. ((eq arg :sexp)
  3861. (setq rtn (org-agenda-get-sexps))
  3862. (setq results (append results rtn)))
  3863. ((eq arg :scheduled)
  3864. (setq rtn (org-agenda-get-scheduled deadline-results))
  3865. (setq results (append results rtn)))
  3866. ((eq arg :closed)
  3867. (setq rtn (org-agenda-get-progress))
  3868. (setq results (append results rtn)))
  3869. ((eq arg :deadline)
  3870. (setq rtn (org-agenda-get-deadlines))
  3871. (setq deadline-results (copy-sequence rtn))
  3872. (setq results (append results rtn))))))))
  3873. results))))
  3874. (defun org-agenda-get-todos ()
  3875. "Return the TODO information for agenda display."
  3876. (let* ((props (list 'face nil
  3877. 'done-face 'org-agenda-done
  3878. 'org-not-done-regexp org-not-done-regexp
  3879. 'org-todo-regexp org-todo-regexp
  3880. 'org-complex-heading-regexp org-complex-heading-regexp
  3881. 'mouse-face 'highlight
  3882. 'help-echo
  3883. (format "mouse-2 or RET jump to org file %s"
  3884. (abbreviate-file-name buffer-file-name))))
  3885. (regexp (concat "^\\*+[ \t]+\\("
  3886. (if org-select-this-todo-keyword
  3887. (if (equal org-select-this-todo-keyword "*")
  3888. org-todo-regexp
  3889. (concat "\\<\\("
  3890. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3891. "\\)\\>"))
  3892. org-not-done-regexp)
  3893. "[^\n\r]*\\)"))
  3894. marker priority category tags todo-state
  3895. ee txt beg end)
  3896. (goto-char (point-min))
  3897. (while (re-search-forward regexp nil t)
  3898. (catch :skip
  3899. (save-match-data
  3900. (beginning-of-line)
  3901. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3902. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3903. (goto-char (1+ beg))
  3904. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3905. (throw :skip nil)))
  3906. (goto-char beg)
  3907. (org-agenda-skip)
  3908. (goto-char (match-beginning 1))
  3909. (setq marker (org-agenda-new-marker (match-beginning 0))
  3910. category (org-get-category)
  3911. txt (match-string 1)
  3912. tags (org-get-tags-at (point))
  3913. txt (org-format-agenda-item "" txt category tags)
  3914. priority (1+ (org-get-priority txt))
  3915. todo-state (org-get-todo-state))
  3916. (org-add-props txt props
  3917. 'org-marker marker 'org-hd-marker marker
  3918. 'priority priority 'org-category category
  3919. 'type "todo" 'todo-state todo-state)
  3920. (push txt ee)
  3921. (if org-agenda-todo-list-sublevels
  3922. (goto-char (match-end 1))
  3923. (org-end-of-subtree 'invisible))))
  3924. (nreverse ee)))
  3925. ;;;###autoload
  3926. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  3927. (&optional end)
  3928. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  3929. (when (or org-agenda-todo-ignore-with-date
  3930. org-agenda-todo-ignore-scheduled
  3931. org-agenda-todo-ignore-deadlines)
  3932. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3933. (save-excursion
  3934. (or (and org-agenda-todo-ignore-with-date
  3935. (re-search-forward org-ts-regexp end t))
  3936. (and org-agenda-todo-ignore-scheduled
  3937. (re-search-forward org-scheduled-time-regexp end t)
  3938. (cond
  3939. ((eq org-agenda-todo-ignore-scheduled 'future)
  3940. (> (org-days-to-time (match-string 1)) 0))
  3941. ((eq org-agenda-todo-ignore-scheduled 'past)
  3942. (<= (org-days-to-time (match-string 1)) 0))
  3943. (t)))
  3944. (and org-agenda-todo-ignore-deadlines
  3945. (re-search-forward org-deadline-time-regexp end t)
  3946. (cond
  3947. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  3948. ((eq org-agenda-todo-ignore-deadlines 'far)
  3949. (not (org-deadline-close (match-string 1))))
  3950. ((eq org-agenda-todo-ignore-deadlines 'future)
  3951. (> (org-days-to-time (match-string 1)) 0))
  3952. ((eq org-agenda-todo-ignore-deadlines 'past)
  3953. (<= (org-days-to-time (match-string 1)) 0))
  3954. (t (org-deadline-close (match-string 1)))))))))
  3955. (defconst org-agenda-no-heading-message
  3956. "No heading for this item in buffer or region.")
  3957. (defun org-agenda-get-timestamps ()
  3958. "Return the date stamp information for agenda display."
  3959. (let* ((props (list 'face nil
  3960. 'org-not-done-regexp org-not-done-regexp
  3961. 'org-todo-regexp org-todo-regexp
  3962. 'org-complex-heading-regexp org-complex-heading-regexp
  3963. 'mouse-face 'highlight
  3964. 'help-echo
  3965. (format "mouse-2 or RET jump to org file %s"
  3966. (abbreviate-file-name buffer-file-name))))
  3967. (d1 (calendar-absolute-from-gregorian date))
  3968. (remove-re
  3969. (concat
  3970. (regexp-quote
  3971. (format-time-string
  3972. "<%Y-%m-%d"
  3973. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  3974. ".*?>"))
  3975. (regexp
  3976. (concat
  3977. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  3978. (regexp-quote
  3979. (substring
  3980. (format-time-string
  3981. (car org-time-stamp-formats)
  3982. (apply 'encode-time ; DATE bound by calendar
  3983. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3984. 1 11))
  3985. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  3986. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  3987. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  3988. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  3989. todo-state end-of-match)
  3990. (goto-char (point-min))
  3991. (while (setq end-of-match (re-search-forward regexp nil t))
  3992. (setq b0 (match-beginning 0)
  3993. b3 (match-beginning 3) e3 (match-end 3))
  3994. (catch :skip
  3995. (and (org-at-date-range-p) (throw :skip nil))
  3996. (org-agenda-skip)
  3997. (if (and (match-end 1)
  3998. (not (= d1 (org-time-string-to-absolute
  3999. (match-string 1) d1 nil
  4000. org-agenda-repeating-timestamp-show-all))))
  4001. (throw :skip nil))
  4002. (if (and e3
  4003. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4004. (throw :skip nil))
  4005. (setq tmp (buffer-substring (max (point-min)
  4006. (- b0 org-ds-keyword-length))
  4007. b0)
  4008. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4009. inactivep (= (char-after b0) ?\[)
  4010. deadlinep (string-match org-deadline-regexp tmp)
  4011. scheduledp (string-match org-scheduled-regexp tmp)
  4012. closedp (and org-agenda-include-inactive-timestamps
  4013. (string-match org-closed-string tmp))
  4014. clockp (and org-agenda-include-inactive-timestamps
  4015. (or (string-match org-clock-string tmp)
  4016. (string-match "]-+\\'" tmp)))
  4017. todo-state (org-get-todo-state)
  4018. donep (member todo-state org-done-keywords))
  4019. (if (or scheduledp deadlinep closedp clockp
  4020. (and donep org-agenda-skip-timestamp-if-done))
  4021. (throw :skip t))
  4022. (if (string-match ">" timestr)
  4023. ;; substring should only run to end of time stamp
  4024. (setq timestr (substring timestr 0 (match-end 0))))
  4025. (setq marker (org-agenda-new-marker b0)
  4026. category (org-get-category b0))
  4027. (save-excursion
  4028. (if (not (re-search-backward "^\\*+ " nil t))
  4029. (setq txt org-agenda-no-heading-message)
  4030. (goto-char (match-beginning 0))
  4031. (setq hdmarker (org-agenda-new-marker)
  4032. tags (org-get-tags-at))
  4033. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4034. (setq head (match-string 1))
  4035. (setq txt (org-format-agenda-item
  4036. (if inactivep org-agenda-inactive-leader nil)
  4037. head category tags timestr nil
  4038. remove-re)))
  4039. (setq priority (org-get-priority txt))
  4040. (org-add-props txt props
  4041. 'org-marker marker 'org-hd-marker hdmarker)
  4042. (org-add-props txt nil 'priority priority
  4043. 'org-category category 'date date
  4044. 'todo-state todo-state
  4045. 'type "timestamp")
  4046. (push txt ee))
  4047. (if org-agenda-skip-additional-timestamps-same-entry
  4048. (outline-next-heading)
  4049. (goto-char end-of-match))))
  4050. (nreverse ee)))
  4051. (defun org-agenda-get-sexps ()
  4052. "Return the sexp information for agenda display."
  4053. (require 'diary-lib)
  4054. (let* ((props (list 'face nil
  4055. 'mouse-face 'highlight
  4056. 'help-echo
  4057. (format "mouse-2 or RET jump to org file %s"
  4058. (abbreviate-file-name buffer-file-name))))
  4059. (regexp "^&?%%(")
  4060. marker category ee txt tags entry result beg b sexp sexp-entry
  4061. todo-state)
  4062. (goto-char (point-min))
  4063. (while (re-search-forward regexp nil t)
  4064. (catch :skip
  4065. (org-agenda-skip)
  4066. (setq beg (match-beginning 0))
  4067. (goto-char (1- (match-end 0)))
  4068. (setq b (point))
  4069. (forward-sexp 1)
  4070. (setq sexp (buffer-substring b (point)))
  4071. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4072. (org-trim (match-string 1))
  4073. ""))
  4074. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4075. (when result
  4076. (setq marker (org-agenda-new-marker beg)
  4077. category (org-get-category beg)
  4078. todo-state (org-get-todo-state))
  4079. (if (string-match "\\S-" result)
  4080. (setq txt result)
  4081. (setq txt "SEXP entry returned empty string"))
  4082. (setq txt (org-format-agenda-item
  4083. "" txt category tags 'time))
  4084. (org-add-props txt props 'org-marker marker)
  4085. (org-add-props txt nil
  4086. 'org-category category 'date date 'todo-state todo-state
  4087. 'type "sexp")
  4088. (push txt ee))))
  4089. (nreverse ee)))
  4090. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4091. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4092. The order of the first 2 times 3 arguments depends on the variable
  4093. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4094. So for american calendars, give this as MONTH DAY YEAR, for european as
  4095. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4096. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4097. is any number of ISO weeks in the block period for which the item should
  4098. be skipped."
  4099. (let* ((date1 (calendar-absolute-from-gregorian
  4100. (org-order-calendar-date-args m1 d1 y1)))
  4101. (date2 (calendar-absolute-from-gregorian
  4102. (org-order-calendar-date-args m2 d2 y2)))
  4103. (d (calendar-absolute-from-gregorian date)))
  4104. (and
  4105. (<= date1 d)
  4106. (<= d date2)
  4107. (= (calendar-day-of-week date) dayname)
  4108. (or (not skip-weeks)
  4109. (progn
  4110. (require 'cal-iso)
  4111. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4112. entry)))
  4113. (defalias 'org-get-closed 'org-agenda-get-progress)
  4114. (defun org-agenda-get-progress ()
  4115. "Return the logged TODO entries for agenda display."
  4116. (let* ((props (list 'mouse-face 'highlight
  4117. 'org-not-done-regexp org-not-done-regexp
  4118. 'org-todo-regexp org-todo-regexp
  4119. 'org-complex-heading-regexp org-complex-heading-regexp
  4120. 'help-echo
  4121. (format "mouse-2 or RET jump to org file %s"
  4122. (abbreviate-file-name buffer-file-name))))
  4123. (items (if (consp org-agenda-show-log)
  4124. org-agenda-show-log
  4125. org-agenda-log-mode-items))
  4126. (parts
  4127. (delq nil
  4128. (list
  4129. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4130. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4131. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4132. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4133. (error "`org-agenda-log-mode-items' is empty")))
  4134. (regexp (concat
  4135. "\\(" parts-re "\\)"
  4136. " *\\["
  4137. (regexp-quote
  4138. (substring
  4139. (format-time-string
  4140. (car org-time-stamp-formats)
  4141. (apply 'encode-time ; DATE bound by calendar
  4142. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4143. 1 11))))
  4144. (org-agenda-search-headline-for-time nil)
  4145. marker hdmarker priority category tags closedp statep clockp state
  4146. ee txt extra timestr rest clocked)
  4147. (goto-char (point-min))
  4148. (while (re-search-forward regexp nil t)
  4149. (catch :skip
  4150. (org-agenda-skip)
  4151. (setq marker (org-agenda-new-marker (match-beginning 0))
  4152. closedp (equal (match-string 1) org-closed-string)
  4153. statep (equal (string-to-char (match-string 1)) ?-)
  4154. clockp (not (or closedp statep))
  4155. state (and statep (match-string 2))
  4156. category (org-get-category (match-beginning 0))
  4157. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4158. )
  4159. (when (string-match "\\]" timestr)
  4160. ;; substring should only run to end of time stamp
  4161. (setq rest (substring timestr (match-end 0))
  4162. timestr (substring timestr 0 (match-end 0)))
  4163. (if (and (not closedp) (not statep)
  4164. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4165. (progn (setq timestr (concat (substring timestr 0 -1)
  4166. "-" (match-string 1 rest) "]"))
  4167. (setq clocked (match-string 2 rest)))
  4168. (setq clocked "-")))
  4169. (save-excursion
  4170. (cond
  4171. ((not org-agenda-log-mode-add-notes) (setq extra nil))
  4172. (statep
  4173. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4174. (setq extra (match-string 1))))
  4175. (clockp
  4176. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4177. (setq extra (match-string 1))))
  4178. (t (setq extra nil)))
  4179. (if (not (re-search-backward "^\\*+ " nil t))
  4180. (setq txt org-agenda-no-heading-message)
  4181. (goto-char (match-beginning 0))
  4182. (setq hdmarker (org-agenda-new-marker)
  4183. tags (org-get-tags-at))
  4184. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4185. (setq txt (match-string 1))
  4186. (when extra
  4187. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4188. (setq txt (concat (substring txt 0 (match-beginning 1))
  4189. " - " extra " " (match-string 2 txt)))
  4190. (setq txt (concat txt " - " extra))))
  4191. (setq txt (org-format-agenda-item
  4192. (cond
  4193. (closedp "Closed: ")
  4194. (statep (concat "State: (" state ")"))
  4195. (t (concat "Clocked: (" clocked ")")))
  4196. txt category tags timestr)))
  4197. (setq priority 100000)
  4198. (org-add-props txt props
  4199. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4200. 'priority priority 'org-category category
  4201. 'type "closed" 'date date
  4202. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4203. (push txt ee))
  4204. (goto-char (point-at-eol))))
  4205. (nreverse ee)))
  4206. (defun org-agenda-get-deadlines ()
  4207. "Return the deadline information for agenda display."
  4208. (let* ((props (list 'mouse-face 'highlight
  4209. 'org-not-done-regexp org-not-done-regexp
  4210. 'org-todo-regexp org-todo-regexp
  4211. 'org-complex-heading-regexp org-complex-heading-regexp
  4212. 'help-echo
  4213. (format "mouse-2 or RET jump to org file %s"
  4214. (abbreviate-file-name buffer-file-name))))
  4215. (regexp org-deadline-time-regexp)
  4216. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4217. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4218. d2 diff dfrac wdays pos pos1 category tags
  4219. suppress-prewarning
  4220. ee txt head face s todo-state upcomingp donep timestr)
  4221. (goto-char (point-min))
  4222. (while (re-search-forward regexp nil t)
  4223. (setq suppress-prewarning nil)
  4224. (catch :skip
  4225. (org-agenda-skip)
  4226. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4227. (save-match-data
  4228. (string-match org-scheduled-time-regexp
  4229. (buffer-substring (point-at-bol)
  4230. (point-at-eol)))))
  4231. (setq suppress-prewarning
  4232. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4233. org-agenda-skip-deadline-prewarning-if-scheduled
  4234. 0)))
  4235. (setq s (match-string 1)
  4236. txt nil
  4237. pos (1- (match-beginning 1))
  4238. d2 (org-time-string-to-absolute
  4239. (match-string 1) d1 'past
  4240. org-agenda-repeating-timestamp-show-all)
  4241. diff (- d2 d1)
  4242. wdays (if suppress-prewarning
  4243. (let ((org-deadline-warning-days suppress-prewarning))
  4244. (org-get-wdays s))
  4245. (org-get-wdays s))
  4246. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4247. upcomingp (and todayp (> diff 0)))
  4248. ;; When to show a deadline in the calendar:
  4249. ;; If the expiration is within wdays warning time.
  4250. ;; Past-due deadlines are only shown on the current date
  4251. (if (and (or (and (<= diff wdays)
  4252. (and todayp (not org-agenda-only-exact-dates)))
  4253. (= diff 0)))
  4254. (save-excursion
  4255. (setq todo-state (org-get-todo-state))
  4256. (setq donep (member todo-state org-done-keywords))
  4257. (if (and donep
  4258. (or org-agenda-skip-deadline-if-done
  4259. (not (= diff 0))))
  4260. (setq txt nil)
  4261. (setq category (org-get-category))
  4262. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4263. (setq txt org-agenda-no-heading-message)
  4264. (goto-char (match-end 0))
  4265. (setq pos1 (match-beginning 0))
  4266. (setq tags (org-get-tags-at pos1))
  4267. (setq head (buffer-substring-no-properties
  4268. (point)
  4269. (progn (skip-chars-forward "^\r\n")
  4270. (point))))
  4271. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4272. (setq timestr
  4273. (concat (substring s (match-beginning 1)) " "))
  4274. (setq timestr 'time))
  4275. (setq txt (org-format-agenda-item
  4276. (if (= diff 0)
  4277. (car org-agenda-deadline-leaders)
  4278. (if (functionp
  4279. (nth 1 org-agenda-deadline-leaders))
  4280. (funcall
  4281. (nth 1 org-agenda-deadline-leaders)
  4282. diff date)
  4283. (format (nth 1 org-agenda-deadline-leaders)
  4284. diff)))
  4285. head category tags
  4286. (if (not (= diff 0)) nil timestr)))))
  4287. (when txt
  4288. (setq face (org-agenda-deadline-face dfrac wdays))
  4289. (org-add-props txt props
  4290. 'org-marker (org-agenda-new-marker pos)
  4291. 'org-hd-marker (org-agenda-new-marker pos1)
  4292. 'priority (+ (- diff)
  4293. (org-get-priority txt))
  4294. 'org-category category
  4295. 'todo-state todo-state
  4296. 'type (if upcomingp "upcoming-deadline" "deadline")
  4297. 'date (if upcomingp date d2)
  4298. 'face (if donep 'org-agenda-done face)
  4299. 'undone-face face 'done-face 'org-agenda-done)
  4300. (push txt ee))))))
  4301. (nreverse ee)))
  4302. (defun org-agenda-deadline-face (fraction &optional wdays)
  4303. "Return the face to displaying a deadline item.
  4304. FRACTION is what fraction of the head-warning time has passed."
  4305. (if (equal wdays 0) (setq fraction 1.))
  4306. (let ((faces org-agenda-deadline-faces) f)
  4307. (catch 'exit
  4308. (while (setq f (pop faces))
  4309. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4310. (defun org-agenda-get-scheduled (&optional deadline-results)
  4311. "Return the scheduled information for agenda display."
  4312. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4313. 'org-todo-regexp org-todo-regexp
  4314. 'org-complex-heading-regexp org-complex-heading-regexp
  4315. 'done-face 'org-agenda-done
  4316. 'mouse-face 'highlight
  4317. 'help-echo
  4318. (format "mouse-2 or RET jump to org file %s"
  4319. (abbreviate-file-name buffer-file-name))))
  4320. (regexp org-scheduled-time-regexp)
  4321. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4322. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4323. mm
  4324. (deadline-position-alist
  4325. (mapcar (lambda (a) (and (setq mm (get-text-property
  4326. 0 'org-hd-marker a))
  4327. (cons (marker-position mm) a)))
  4328. deadline-results))
  4329. d2 diff pos pos1 category tags donep
  4330. ee txt head pastschedp todo-state face timestr s habitp)
  4331. (goto-char (point-min))
  4332. (while (re-search-forward regexp nil t)
  4333. (catch :skip
  4334. (org-agenda-skip)
  4335. (setq s (match-string 1)
  4336. txt nil
  4337. pos (1- (match-beginning 1))
  4338. d2 (org-time-string-to-absolute
  4339. (match-string 1) d1 'past
  4340. org-agenda-repeating-timestamp-show-all)
  4341. diff (- d2 d1))
  4342. (setq pastschedp (and todayp (< diff 0)))
  4343. ;; When to show a scheduled item in the calendar:
  4344. ;; If it is on or past the date.
  4345. (when (or (and (< diff 0)
  4346. (< (abs diff) org-scheduled-past-days)
  4347. (and todayp (not org-agenda-only-exact-dates)))
  4348. (= diff 0))
  4349. (save-excursion
  4350. (setq todo-state (org-get-todo-state))
  4351. (setq donep (member todo-state org-done-keywords))
  4352. (setq habitp (and (functionp 'org-is-habit-p)
  4353. (org-is-habit-p)))
  4354. (if (and donep
  4355. (or habitp org-agenda-skip-scheduled-if-done
  4356. (not (= diff 0))))
  4357. (setq txt nil)
  4358. (setq category (org-get-category))
  4359. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4360. (setq txt org-agenda-no-heading-message)
  4361. (goto-char (match-end 0))
  4362. (setq pos1 (match-beginning 0))
  4363. (if habitp
  4364. (if (or (not org-habit-show-habits)
  4365. (and (not todayp)
  4366. org-habit-show-habits-only-for-today))
  4367. (throw :skip nil))
  4368. (if (and
  4369. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4370. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4371. pastschedp))
  4372. (setq mm (assoc pos1 deadline-position-alist)))
  4373. (throw :skip nil)))
  4374. (setq tags (org-get-tags-at))
  4375. (setq head (buffer-substring-no-properties
  4376. (point)
  4377. (progn (skip-chars-forward "^\r\n") (point))))
  4378. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4379. (setq timestr
  4380. (concat (substring s (match-beginning 1)) " "))
  4381. (setq timestr 'time))
  4382. (setq txt (org-format-agenda-item
  4383. (if (= diff 0)
  4384. (car org-agenda-scheduled-leaders)
  4385. (format (nth 1 org-agenda-scheduled-leaders)
  4386. (- 1 diff)))
  4387. head category tags
  4388. (if (not (= diff 0)) nil timestr)
  4389. nil nil habitp))))
  4390. (when txt
  4391. (setq face
  4392. (cond
  4393. ((and (not habitp) pastschedp)
  4394. 'org-scheduled-previously)
  4395. (todayp 'org-scheduled-today)
  4396. (t 'org-scheduled))
  4397. habitp (and habitp (org-habit-parse-todo)))
  4398. (org-add-props txt props
  4399. 'undone-face face
  4400. 'face (if donep 'org-agenda-done face)
  4401. 'org-marker (org-agenda-new-marker pos)
  4402. 'org-hd-marker (org-agenda-new-marker pos1)
  4403. 'type (if pastschedp "past-scheduled" "scheduled")
  4404. 'date (if pastschedp d2 date)
  4405. 'priority (if habitp
  4406. (org-habit-get-priority habitp)
  4407. (+ 94 (- 5 diff) (org-get-priority txt)))
  4408. 'org-category category
  4409. 'org-habit-p habitp
  4410. 'todo-state todo-state)
  4411. (push txt ee))))))
  4412. (nreverse ee)))
  4413. (defun org-agenda-get-blocks ()
  4414. "Return the date-range information for agenda display."
  4415. (let* ((props (list 'face nil
  4416. 'org-not-done-regexp org-not-done-regexp
  4417. 'org-todo-regexp org-todo-regexp
  4418. 'org-complex-heading-regexp org-complex-heading-regexp
  4419. 'mouse-face 'highlight
  4420. 'help-echo
  4421. (format "mouse-2 or RET jump to org file %s"
  4422. (abbreviate-file-name buffer-file-name))))
  4423. (regexp org-tr-regexp)
  4424. (d0 (calendar-absolute-from-gregorian date))
  4425. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4426. head donep)
  4427. (goto-char (point-min))
  4428. (while (re-search-forward regexp nil t)
  4429. (catch :skip
  4430. (org-agenda-skip)
  4431. (setq pos (point))
  4432. (setq timestr (match-string 0)
  4433. s1 (match-string 1)
  4434. s2 (match-string 2)
  4435. d1 (time-to-days (org-time-string-to-time s1))
  4436. d2 (time-to-days (org-time-string-to-time s2)))
  4437. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4438. ;; Only allow days between the limits, because the normal
  4439. ;; date stamps will catch the limits.
  4440. (save-excursion
  4441. (setq todo-state (org-get-todo-state))
  4442. (setq donep (member todo-state org-done-keywords))
  4443. (if (and donep org-agenda-skip-timestamp-if-done)
  4444. (throw :skip t))
  4445. (setq marker (org-agenda-new-marker (point)))
  4446. (setq category (org-get-category))
  4447. (if (not (re-search-backward "^\\*+ " nil t))
  4448. (setq txt org-agenda-no-heading-message)
  4449. (goto-char (match-beginning 0))
  4450. (setq hdmarker (org-agenda-new-marker (point)))
  4451. (setq tags (org-get-tags-at))
  4452. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4453. (setq head (match-string 1))
  4454. (setq txt (org-format-agenda-item
  4455. (format
  4456. (nth (if (= d1 d2) 0 1)
  4457. org-agenda-timerange-leaders)
  4458. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4459. head category tags
  4460. timestr)))
  4461. (org-add-props txt props
  4462. 'org-marker marker 'org-hd-marker hdmarker
  4463. 'type "block" 'date date
  4464. 'todo-state todo-state
  4465. 'priority (org-get-priority txt) 'org-category category)
  4466. (push txt ee)))
  4467. (goto-char pos)))
  4468. ;; Sort the entries by expiration date.
  4469. (nreverse ee)))
  4470. ;;; Agenda presentation and sorting
  4471. (defvar org-prefix-has-time nil
  4472. "A flag, set by `org-compile-prefix-format'.
  4473. The flag is set if the currently compiled format contains a `%t'.")
  4474. (defvar org-prefix-has-tag nil
  4475. "A flag, set by `org-compile-prefix-format'.
  4476. The flag is set if the currently compiled format contains a `%T'.")
  4477. (defvar org-prefix-has-effort nil
  4478. "A flag, set by `org-compile-prefix-format'.
  4479. The flag is set if the currently compiled format contains a `%e'.")
  4480. (defvar org-prefix-category-length nil
  4481. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4482. (defvar org-prefix-category-max-length nil
  4483. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4484. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4485. noprefix remove-re habitp)
  4486. "Format TXT to be inserted into the agenda buffer.
  4487. In particular, it adds the prefix and corresponding text properties. EXTRA
  4488. must be a string and replaces the `%s' specifier in the prefix format.
  4489. CATEGORY (string, symbol or nil) may be used to overrule the default
  4490. category taken from local variable or file name. It will replace the `%c'
  4491. specifier in the format. DOTIME, when non-nil, indicates that a
  4492. time-of-day should be extracted from TXT for sorting of this entry, and for
  4493. the `%t' specifier in the format. When DOTIME is a string, this string is
  4494. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4495. only the correctly processes TXT should be returned - this is used by
  4496. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4497. Any match of REMOVE-RE will be removed from TXT."
  4498. (save-match-data
  4499. ;; Diary entries sometimes have extra whitespace at the beginning
  4500. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4501. ;; Fix the tags part in txt
  4502. (setq txt (org-agenda-fix-displayed-tags
  4503. txt tags
  4504. org-agenda-show-inherited-tags
  4505. org-agenda-hide-tags-regexp))
  4506. (let* ((category (or category
  4507. org-category
  4508. (if buffer-file-name
  4509. (file-name-sans-extension
  4510. (file-name-nondirectory buffer-file-name))
  4511. "")))
  4512. ;; time, tag, effort are needed for the eval of the prefix format
  4513. (tag (if tags (nth (1- (length tags)) tags) ""))
  4514. time effort neffort
  4515. (ts (if dotime (concat
  4516. (if (stringp dotime) dotime "")
  4517. (and org-agenda-search-headline-for-time txt))))
  4518. (time-of-day (and dotime (org-get-time-of-day ts)))
  4519. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4520. duration thecategory)
  4521. (and (org-mode-p) buffer-file-name
  4522. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4523. (when (and dotime time-of-day)
  4524. ;; Extract starting and ending time and move them to prefix
  4525. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4526. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4527. (setq s0 (match-string 0 ts)
  4528. srp (and stamp (match-end 3))
  4529. s1 (match-string (if plain 1 2) ts)
  4530. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4531. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4532. ;; them, we might want to remove them there to avoid duplication.
  4533. ;; The user can turn this off with a variable.
  4534. (if (and org-prefix-has-time
  4535. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4536. (string-match (concat (regexp-quote s0) " *") txt)
  4537. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4538. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4539. (= (match-beginning 0) 0)
  4540. t))
  4541. (setq txt (replace-match "" nil nil txt))))
  4542. ;; Normalize the time(s) to 24 hour
  4543. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4544. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4545. ;; Compute the duration
  4546. (when s1
  4547. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4548. (string-to-number (substring s1 3)))
  4549. t2 (cond
  4550. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4551. (string-to-number (substring s2 3))))
  4552. (org-agenda-default-appointment-duration
  4553. (+ t1 org-agenda-default-appointment-duration))
  4554. (t nil)))
  4555. (setq duration (if t2 (- t2 t1)))))
  4556. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4557. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4558. (let ((m (+ (string-to-number (match-string 2 s1))
  4559. (* 60 (string-to-number (match-string 1 s1)))
  4560. org-agenda-default-appointment-duration))
  4561. h)
  4562. (setq h (/ m 60) m (- m (* h 60)))
  4563. (setq s2 (format "%02d:%02d" h m))))
  4564. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4565. txt)
  4566. ;; Tags are in the string
  4567. (if (or (eq org-agenda-remove-tags t)
  4568. (and org-agenda-remove-tags
  4569. org-prefix-has-tag))
  4570. (setq txt (replace-match "" t t txt))
  4571. (setq txt (replace-match
  4572. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4573. (match-string 2 txt))
  4574. t t txt))))
  4575. (when (org-mode-p)
  4576. (setq effort
  4577. (condition-case nil
  4578. (org-get-effort
  4579. (or (get-text-property 0 'org-hd-marker txt)
  4580. (get-text-property 0 'org-marker txt)))
  4581. (error nil)))
  4582. (when effort
  4583. (setq neffort (org-hh:mm-string-to-minutes effort)
  4584. effort (setq effort (concat "[" effort "]" )))))
  4585. (when remove-re
  4586. (while (string-match remove-re txt)
  4587. (setq txt (replace-match "" t t txt))))
  4588. ;; Create the final string
  4589. (if noprefix
  4590. (setq rtn txt)
  4591. ;; Prepare the variables needed in the eval of the compiled format
  4592. (setq time (cond (s2 (concat s1 "-" s2))
  4593. (s1 (concat s1 "......"))
  4594. (t ""))
  4595. extra (or (and (not habitp) extra) "")
  4596. category (if (symbolp category) (symbol-name category) category)
  4597. thecategory (copy-sequence category))
  4598. (if (string-match org-bracket-link-regexp category)
  4599. (progn
  4600. (setq l (if (match-end 3)
  4601. (- (match-end 3) (match-beginning 3))
  4602. (- (match-end 1) (match-beginning 1))))
  4603. (when (< l (or org-prefix-category-length 0))
  4604. (setq category (copy-sequence category))
  4605. (org-add-props category nil
  4606. 'extra-space (make-string
  4607. (- org-prefix-category-length l 1) ?\ ))))
  4608. (if (and org-prefix-category-max-length
  4609. (>= (length category) org-prefix-category-max-length))
  4610. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4611. ;; Evaluate the compiled format
  4612. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4613. ;; And finally add the text properties
  4614. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4615. (org-add-props rtn nil
  4616. 'org-category (if thecategory (downcase thecategory) category)
  4617. 'tags (mapcar 'org-downcase-keep-props tags)
  4618. 'org-highest-priority org-highest-priority
  4619. 'org-lowest-priority org-lowest-priority
  4620. 'prefix-length (- (length rtn) (length txt))
  4621. 'time-of-day time-of-day
  4622. 'duration duration
  4623. 'effort effort
  4624. 'effort-minutes neffort
  4625. 'txt txt
  4626. 'time time
  4627. 'extra extra
  4628. 'dotime dotime))))
  4629. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4630. "Remove tags string from TXT, and add a modified list of tags.
  4631. The modified list may contain inherited tags, and tags matched by
  4632. `org-agenda-hide-tags-regexp' will be removed."
  4633. (when (or add-inherited hide-re)
  4634. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4635. (setq txt (substring txt 0 (match-beginning 0))))
  4636. (setq tags
  4637. (delq nil
  4638. (mapcar (lambda (tg)
  4639. (if (or (and hide-re (string-match hide-re tg))
  4640. (and (not add-inherited)
  4641. (get-text-property 0 'inherited tg)))
  4642. nil
  4643. tg))
  4644. tags)))
  4645. (when tags
  4646. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4647. i)
  4648. (setq txt (concat txt " :"
  4649. (mapconcat
  4650. (lambda (x)
  4651. (setq i (get-text-property 0 'inherited x))
  4652. (if (and have-i (not i))
  4653. (progn
  4654. (setq have-i nil)
  4655. (concat ":" x))
  4656. x))
  4657. tags ":")
  4658. (if have-i "::" ":"))))))
  4659. txt)
  4660. (defun org-downcase-keep-props (s)
  4661. (let ((props (text-properties-at 0 s)))
  4662. (setq s (downcase s))
  4663. (add-text-properties 0 (length s) props s)
  4664. s))
  4665. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4666. (defvar org-agenda-sorting-strategy-selected nil)
  4667. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4668. (catch 'exit
  4669. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4670. ((and todayp (member 'today (car org-agenda-time-grid))))
  4671. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4672. ((member 'weekly (car org-agenda-time-grid)))
  4673. (t (throw 'exit list)))
  4674. (let* ((have (delq nil (mapcar
  4675. (lambda (x) (get-text-property 1 'time-of-day x))
  4676. list)))
  4677. (string (nth 1 org-agenda-time-grid))
  4678. (gridtimes (nth 2 org-agenda-time-grid))
  4679. (req (car org-agenda-time-grid))
  4680. (remove (member 'remove-match req))
  4681. new time)
  4682. (if (and (member 'require-timed req) (not have))
  4683. ;; don't show empty grid
  4684. (throw 'exit list))
  4685. (while (setq time (pop gridtimes))
  4686. (unless (and remove (member time have))
  4687. (setq time (int-to-string time))
  4688. (push (org-format-agenda-item
  4689. nil string "" nil
  4690. (concat (substring time 0 -2) ":" (substring time -2)))
  4691. new)
  4692. (put-text-property
  4693. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4694. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4695. (append new list)
  4696. (append list new)))))
  4697. (defun org-compile-prefix-format (key)
  4698. "Compile the prefix format into a Lisp form that can be evaluated.
  4699. The resulting form is returned and stored in the variable
  4700. `org-prefix-format-compiled'."
  4701. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4702. org-prefix-category-length nil org-prefix-has-effort nil)
  4703. (let ((s (cond
  4704. ((stringp org-agenda-prefix-format)
  4705. org-agenda-prefix-format)
  4706. ((assq key org-agenda-prefix-format)
  4707. (cdr (assq key org-agenda-prefix-format)))
  4708. (t " %-12:c%?-12t% s")))
  4709. (start 0)
  4710. varform vars var e c f opt)
  4711. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4712. s start)
  4713. (setq var (cdr (assoc (match-string 4 s)
  4714. '(("c" . category) ("t" . time) ("s" . extra)
  4715. ("T" . tag) ("e" . effort))))
  4716. c (or (match-string 3 s) "")
  4717. opt (match-beginning 1)
  4718. start (1+ (match-beginning 0)))
  4719. (if (equal var 'time) (setq org-prefix-has-time t))
  4720. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4721. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4722. (setq f (concat "%" (match-string 2 s) "s"))
  4723. (when (equal var 'category)
  4724. (setq org-prefix-category-length
  4725. (floor (abs (string-to-number (match-string 2 s)))))
  4726. (setq org-prefix-category-max-length
  4727. (let ((x (match-string 2 s)))
  4728. (save-match-data
  4729. (if (string-match "\\.[0-9]+" x)
  4730. (string-to-number (substring (match-string 0 x) 1)))))))
  4731. (if opt
  4732. (setq varform
  4733. `(if (equal "" ,var)
  4734. ""
  4735. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4736. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4737. (setq s (replace-match "%s" t nil s))
  4738. (push varform vars))
  4739. (setq vars (nreverse vars))
  4740. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4741. (defun org-set-sorting-strategy (key)
  4742. (if (symbolp (car org-agenda-sorting-strategy))
  4743. ;; the old format
  4744. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4745. (setq org-agenda-sorting-strategy-selected
  4746. (or (cdr (assq key org-agenda-sorting-strategy))
  4747. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4748. '(time-up category-keep priority-down)))))
  4749. (defun org-get-time-of-day (s &optional string mod24)
  4750. "Check string S for a time of day.
  4751. If found, return it as a military time number between 0 and 2400.
  4752. If not found, return nil.
  4753. The optional STRING argument forces conversion into a 5 character wide string
  4754. HH:MM."
  4755. (save-match-data
  4756. (when
  4757. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4758. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4759. (let* ((h (string-to-number (match-string 1 s)))
  4760. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4761. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4762. (am-p (equal ampm "am"))
  4763. (h1 (cond ((not ampm) h)
  4764. ((= h 12) (if am-p 0 12))
  4765. (t (+ h (if am-p 0 12)))))
  4766. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4767. (mod h1 24) h1))
  4768. (t0 (+ (* 100 h2) m))
  4769. (t1 (concat (if (>= h1 24) "+" " ")
  4770. (if (and org-agenda-time-leading-zero
  4771. (< t0 1000)) "0" "")
  4772. (if (< t0 100) "0" "")
  4773. (if (< t0 10) "0" "")
  4774. (int-to-string t0))))
  4775. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4776. (defun org-finalize-agenda-entries (list &optional nosort)
  4777. "Sort and concatenate the agenda items."
  4778. (setq list (mapcar 'org-agenda-highlight-todo list))
  4779. (if nosort
  4780. list
  4781. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4782. (defun org-agenda-highlight-todo (x)
  4783. (let ((org-done-keywords org-done-keywords-for-agenda)
  4784. (case-fold-search nil)
  4785. re pl)
  4786. (if (eq x 'line)
  4787. (save-excursion
  4788. (beginning-of-line 1)
  4789. (setq re (org-get-at-bol 'org-todo-regexp))
  4790. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4791. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4792. (add-text-properties (match-beginning 0) (match-end 1)
  4793. (list 'face (org-get-todo-face 1)))
  4794. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4795. (delete-region (match-beginning 1) (1- (match-end 0)))
  4796. (goto-char (match-beginning 1))
  4797. (insert (format org-agenda-todo-keyword-format s)))))
  4798. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4799. pl (get-text-property 0 'prefix-length x))
  4800. (when (and re
  4801. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4802. x (or pl 0)) pl))
  4803. (add-text-properties
  4804. (or (match-end 1) (match-end 0)) (match-end 0)
  4805. (list 'face (org-get-todo-face (match-string 2 x)))
  4806. x)
  4807. (setq x (concat (substring x 0 (match-end 1))
  4808. (format org-agenda-todo-keyword-format
  4809. (match-string 2 x))
  4810. (org-add-props " " (text-properties-at 0 x))
  4811. (substring x (match-end 3)))))
  4812. x)))
  4813. (defsubst org-cmp-priority (a b)
  4814. "Compare the priorities of string A and B."
  4815. (let ((pa (or (get-text-property 1 'priority a) 0))
  4816. (pb (or (get-text-property 1 'priority b) 0)))
  4817. (cond ((> pa pb) +1)
  4818. ((< pa pb) -1)
  4819. (t nil))))
  4820. (defsubst org-cmp-effort (a b)
  4821. "Compare the priorities of string A and B."
  4822. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4823. (ea (or (get-text-property 1 'effort-minutes a) def))
  4824. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4825. (cond ((> ea eb) +1)
  4826. ((< ea eb) -1)
  4827. (t nil))))
  4828. (defsubst org-cmp-category (a b)
  4829. "Compare the string values of categories of strings A and B."
  4830. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4831. (cb (or (get-text-property 1 'org-category b) "")))
  4832. (cond ((string-lessp ca cb) -1)
  4833. ((string-lessp cb ca) +1)
  4834. (t nil))))
  4835. (defsubst org-cmp-todo-state (a b)
  4836. "Compare the todo states of strings A and B."
  4837. (let* ((ma (or (get-text-property 1 'org-marker a)
  4838. (get-text-property 1 'org-hd-marker a)))
  4839. (mb (or (get-text-property 1 'org-marker b)
  4840. (get-text-property 1 'org-hd-marker b)))
  4841. (fa (and ma (marker-buffer ma)))
  4842. (fb (and mb (marker-buffer mb)))
  4843. (todo-kwds
  4844. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4845. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4846. (ta (or (get-text-property 1 'todo-state a) ""))
  4847. (tb (or (get-text-property 1 'todo-state b) ""))
  4848. (la (- (length (member ta todo-kwds))))
  4849. (lb (- (length (member tb todo-kwds))))
  4850. (donepa (member ta org-done-keywords-for-agenda))
  4851. (donepb (member tb org-done-keywords-for-agenda)))
  4852. (cond ((and donepa (not donepb)) -1)
  4853. ((and (not donepa) donepb) +1)
  4854. ((< la lb) -1)
  4855. ((< lb la) +1)
  4856. (t nil))))
  4857. (defsubst org-cmp-tag (a b)
  4858. "Compare the string values of the first tags of A and B."
  4859. (let ((ta (car (last (get-text-property 1 'tags a))))
  4860. (tb (car (last (get-text-property 1 'tags b)))))
  4861. (cond ((not ta) +1)
  4862. ((not tb) -1)
  4863. ((string-lessp ta tb) -1)
  4864. ((string-lessp tb ta) +1)
  4865. (t nil))))
  4866. (defsubst org-cmp-time (a b)
  4867. "Compare the time-of-day values of strings A and B."
  4868. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4869. (ta (or (get-text-property 1 'time-of-day a) def))
  4870. (tb (or (get-text-property 1 'time-of-day b) def)))
  4871. (cond ((< ta tb) -1)
  4872. ((< tb ta) +1)
  4873. (t nil))))
  4874. (defsubst org-cmp-habit-p (a b)
  4875. "Compare the todo states of strings A and B."
  4876. (let ((ha (get-text-property 1 'org-habit-p a))
  4877. (hb (get-text-property 1 'org-habit-p b)))
  4878. (cond ((and ha (not hb)) -1)
  4879. ((and (not ha) hb) +1)
  4880. (t nil))))
  4881. (defun org-entries-lessp (a b)
  4882. "Predicate for sorting agenda entries."
  4883. ;; The following variables will be used when the form is evaluated.
  4884. ;; So even though the compiler complains, keep them.
  4885. (let* ((time-up (org-cmp-time a b))
  4886. (time-down (if time-up (- time-up) nil))
  4887. (priority-up (org-cmp-priority a b))
  4888. (priority-down (if priority-up (- priority-up) nil))
  4889. (effort-up (org-cmp-effort a b))
  4890. (effort-down (if effort-up (- effort-up) nil))
  4891. (category-up (org-cmp-category a b))
  4892. (category-down (if category-up (- category-up) nil))
  4893. (category-keep (if category-up +1 nil))
  4894. (tag-up (org-cmp-tag a b))
  4895. (tag-down (if tag-up (- tag-up) nil))
  4896. (todo-state-up (org-cmp-todo-state a b))
  4897. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4898. (habit-up (org-cmp-habit-p a b))
  4899. (habit-down (if habit-up (- habit-up) nil))
  4900. user-defined-up user-defined-down)
  4901. (if (and org-agenda-cmp-user-defined
  4902. (functionp org-agenda-cmp-user-defined))
  4903. (setq user-defined-up
  4904. (funcall org-agenda-cmp-user-defined a b)
  4905. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  4906. (cdr (assoc
  4907. (eval (cons 'or org-agenda-sorting-strategy-selected))
  4908. '((-1 . t) (1 . nil) (nil . nil))))))
  4909. ;;; Agenda restriction lock
  4910. (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
  4911. "Overlay to mark the headline to which agenda commands are restricted.")
  4912. (org-overlay-put org-agenda-restriction-lock-overlay
  4913. 'face 'org-agenda-restriction-lock)
  4914. (org-overlay-put org-agenda-restriction-lock-overlay
  4915. 'help-echo "Agendas are currently limited to this subtree.")
  4916. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4917. (defun org-agenda-set-restriction-lock (&optional type)
  4918. "Set restriction lock for agenda, to current subtree or file.
  4919. Restriction will be the file if TYPE is `file', or if type is the
  4920. universal prefix '(4), or if the cursor is before the first headline
  4921. in the file. Otherwise, restriction will be to the current subtree."
  4922. (interactive "P")
  4923. (and (equal type '(4)) (setq type 'file))
  4924. (setq type (cond
  4925. (type type)
  4926. ((org-at-heading-p) 'subtree)
  4927. ((condition-case nil (org-back-to-heading t) (error nil))
  4928. 'subtree)
  4929. (t 'file)))
  4930. (if (eq type 'subtree)
  4931. (progn
  4932. (setq org-agenda-restrict t)
  4933. (setq org-agenda-overriding-restriction 'subtree)
  4934. (put 'org-agenda-files 'org-restrict
  4935. (list (buffer-file-name (buffer-base-buffer))))
  4936. (org-back-to-heading t)
  4937. (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  4938. (move-marker org-agenda-restrict-begin (point))
  4939. (move-marker org-agenda-restrict-end
  4940. (save-excursion (org-end-of-subtree t)))
  4941. (message "Locking agenda restriction to subtree"))
  4942. (put 'org-agenda-files 'org-restrict
  4943. (list (buffer-file-name (buffer-base-buffer))))
  4944. (setq org-agenda-restrict nil)
  4945. (setq org-agenda-overriding-restriction 'file)
  4946. (move-marker org-agenda-restrict-begin nil)
  4947. (move-marker org-agenda-restrict-end nil)
  4948. (message "Locking agenda restriction to file"))
  4949. (setq current-prefix-arg nil)
  4950. (org-agenda-maybe-redo))
  4951. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  4952. "Remove the agenda restriction lock."
  4953. (interactive "P")
  4954. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4955. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  4956. (setq org-agenda-overriding-restriction nil)
  4957. (setq org-agenda-restrict nil)
  4958. (put 'org-agenda-files 'org-restrict nil)
  4959. (move-marker org-agenda-restrict-begin nil)
  4960. (move-marker org-agenda-restrict-end nil)
  4961. (setq current-prefix-arg nil)
  4962. (message "Agenda restriction lock removed")
  4963. (or noupdate (org-agenda-maybe-redo)))
  4964. (defun org-agenda-maybe-redo ()
  4965. "If there is any window showing the agenda view, update it."
  4966. (let ((w (get-buffer-window org-agenda-buffer-name t))
  4967. (w0 (selected-window)))
  4968. (when w
  4969. (select-window w)
  4970. (org-agenda-redo)
  4971. (select-window w0)
  4972. (if org-agenda-overriding-restriction
  4973. (message "Agenda view shifted to new %s restriction"
  4974. org-agenda-overriding-restriction)
  4975. (message "Agenda restriction lock removed")))))
  4976. ;;; Agenda commands
  4977. (defun org-agenda-check-type (error &rest types)
  4978. "Check if agenda buffer is of allowed type.
  4979. If ERROR is non-nil, throw an error, otherwise just return nil."
  4980. (if (memq org-agenda-type types)
  4981. t
  4982. (if error
  4983. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  4984. nil)))
  4985. (defun org-agenda-quit ()
  4986. "Exit agenda by removing the window or the buffer."
  4987. (interactive)
  4988. (if org-agenda-columns-active
  4989. (org-columns-quit)
  4990. (let ((buf (current-buffer)))
  4991. (if (eq org-agenda-window-setup 'other-frame)
  4992. (progn
  4993. (kill-buffer buf)
  4994. (org-agenda-reset-markers)
  4995. (org-columns-remove-overlays)
  4996. (setq org-agenda-archives-mode nil)
  4997. (delete-frame))
  4998. (and (not (eq org-agenda-window-setup 'current-window))
  4999. (not (one-window-p))
  5000. (delete-window))
  5001. (kill-buffer buf)
  5002. (org-agenda-reset-markers)
  5003. (org-columns-remove-overlays)
  5004. (setq org-agenda-archives-mode nil)))
  5005. ;; Maybe restore the pre-agenda window configuration.
  5006. (and org-agenda-restore-windows-after-quit
  5007. (not (eq org-agenda-window-setup 'other-frame))
  5008. org-pre-agenda-window-conf
  5009. (set-window-configuration org-pre-agenda-window-conf))))
  5010. (defun org-agenda-exit ()
  5011. "Exit agenda by removing the window or the buffer.
  5012. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5013. Org-mode buffers visited directly by the user will not be touched."
  5014. (interactive)
  5015. (org-release-buffers org-agenda-new-buffers)
  5016. (setq org-agenda-new-buffers nil)
  5017. (org-agenda-quit))
  5018. (defun org-agenda-execute (arg)
  5019. "Execute another agenda command, keeping same window.\\<global-map>
  5020. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  5021. (interactive "P")
  5022. (let ((org-agenda-window-setup 'current-window))
  5023. (org-agenda arg)))
  5024. (defun org-agenda-redo ()
  5025. "Rebuild Agenda.
  5026. When this is the global TODO list, a prefix argument will be interpreted."
  5027. (interactive)
  5028. (let* ((org-agenda-keep-modes t)
  5029. (filter org-agenda-filter)
  5030. (preset (get 'org-agenda-filter :preset-filter))
  5031. (cols org-agenda-columns-active)
  5032. (line (org-current-line))
  5033. (window-line (- line (org-current-line (window-start))))
  5034. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5035. (put 'org-agenda-filter :preset-filter nil)
  5036. (and cols (org-columns-quit))
  5037. (message "Rebuilding agenda buffer...")
  5038. (org-let lprops '(eval org-agenda-redo-command))
  5039. (setq org-agenda-undo-list nil
  5040. org-agenda-pending-undo-list nil)
  5041. (message "Rebuilding agenda buffer...done")
  5042. (put 'org-agenda-filter :preset-filter preset)
  5043. (and (or filter preset) (org-agenda-filter-apply filter))
  5044. (and cols (interactive-p) (org-agenda-columns))
  5045. (org-goto-line line)
  5046. (recenter window-line)))
  5047. (defvar org-global-tags-completion-table nil)
  5048. (defvar org-agenda-filter-form nil)
  5049. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5050. "Keep only those lines in the agenda buffer that have a specific tag.
  5051. The tag is selected with its fast selection letter, as configured.
  5052. With prefix argument STRIP, remove all lines that do have the tag.
  5053. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5054. used to narrow the search - the interactive user can also press `-' or `+'
  5055. to switch to narrowing."
  5056. (interactive "P")
  5057. (let* ((alist org-tag-alist-for-agenda)
  5058. (tag-chars (mapconcat
  5059. (lambda (x) (if (and (not (symbolp (car x)))
  5060. (cdr x))
  5061. (char-to-string (cdr x))
  5062. ""))
  5063. alist ""))
  5064. (efforts (org-split-string
  5065. (or (cdr (assoc (concat org-effort-property "_ALL")
  5066. org-global-properties))
  5067. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5068. (effort-op org-agenda-filter-effort-default-operator)
  5069. (effort-prompt "")
  5070. (inhibit-read-only t)
  5071. (current org-agenda-filter)
  5072. a n tag)
  5073. (unless char
  5074. (message
  5075. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5076. (if narrow "Narrow" "Filter") tag-chars
  5077. (if org-agenda-auto-exclude-function "[RET], " ""))
  5078. (setq char (read-char)))
  5079. (when (member char '(?+ ?-))
  5080. ;; Narrowing down
  5081. (cond ((equal char ?-) (setq strip t narrow t))
  5082. ((equal char ?+) (setq strip nil narrow t)))
  5083. (message
  5084. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5085. (setq char (read-char)))
  5086. (when (member char '(?< ?> ?= ??))
  5087. ;; An effort operator
  5088. (setq effort-op (char-to-string char))
  5089. (setq alist nil) ; to make sure it will be interpreted as effort.
  5090. (unless (equal char ??)
  5091. (loop for i from 0 to 9 do
  5092. (setq effort-prompt
  5093. (concat
  5094. effort-prompt " ["
  5095. (if (= i 9) "0" (int-to-string (1+ i)))
  5096. "]" (nth i efforts))))
  5097. (message "Effort%s: %s " effort-op effort-prompt)
  5098. (setq char (read-char))
  5099. (when (or (< char ?0) (> char ?9))
  5100. (error "Need 1-9,0 to select effort" ))))
  5101. (when (equal char ?\t)
  5102. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5103. (org-set-local 'org-global-tags-completion-table
  5104. (org-global-tags-completion-table)))
  5105. (let ((completion-ignore-case t))
  5106. (setq tag (org-icompleting-read
  5107. "Tag: " org-global-tags-completion-table))))
  5108. (cond
  5109. ((equal char ?\r)
  5110. (org-agenda-filter-by-tag-show-all)
  5111. (when org-agenda-auto-exclude-function
  5112. (setq org-agenda-filter '())
  5113. (dolist (tag (org-agenda-get-represented-tags))
  5114. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5115. (if modifier
  5116. (push modifier org-agenda-filter))))
  5117. (if (not (null org-agenda-filter))
  5118. (org-agenda-filter-apply org-agenda-filter))))
  5119. ((equal char ?/)
  5120. (org-agenda-filter-by-tag-show-all)
  5121. (when (get 'org-agenda-filter :preset-filter)
  5122. (org-agenda-filter-apply org-agenda-filter)))
  5123. ((or (equal char ?\ )
  5124. (setq a (rassoc char alist))
  5125. (and (>= char ?0) (<= char ?9)
  5126. (setq n (if (= char ?0) 9 (- char ?0 1))
  5127. tag (concat effort-op (nth n efforts))
  5128. a (cons tag nil)))
  5129. (and (= char ??)
  5130. (setq tag "?eff")
  5131. a (cons tag nil))
  5132. (and tag (setq a (cons tag nil))))
  5133. (org-agenda-filter-by-tag-show-all)
  5134. (setq tag (car a))
  5135. (setq org-agenda-filter
  5136. (cons (concat (if strip "-" "+") tag)
  5137. (if narrow current nil)))
  5138. (org-agenda-filter-apply org-agenda-filter))
  5139. (t (error "Invalid tag selection character %c" char)))))
  5140. (defun org-agenda-get-represented-tags ()
  5141. "Get a list of all tags currently represented in the agenda."
  5142. (let (p tags)
  5143. (save-excursion
  5144. (goto-char (point-min))
  5145. (while (setq p (next-single-property-change (point) 'tags))
  5146. (goto-char p)
  5147. (mapc (lambda (x) (add-to-list 'tags x))
  5148. (get-text-property (point) 'tags))))
  5149. tags))
  5150. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5151. "Refine the current filter. See `org-agenda-filter-by-tag."
  5152. (interactive "P")
  5153. (org-agenda-filter-by-tag strip char 'refine))
  5154. (defun org-agenda-filter-make-matcher ()
  5155. "Create the form that tests a line for the agenda filter."
  5156. (let (f f1)
  5157. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5158. org-agenda-filter))
  5159. (if (member x '("-" "+"))
  5160. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5161. (if (string-match "[<=>?]" x)
  5162. (setq f1 (org-agenda-filter-effort-form x))
  5163. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5164. (if (equal (string-to-char x) ?-)
  5165. (setq f1 (list 'not f1))))
  5166. (push f1 f))
  5167. (cons 'and (nreverse f))))
  5168. (defun org-agenda-filter-effort-form (e)
  5169. "Return the form to compare the effort of the current line with what E says.
  5170. E looks line \"+<2:25\"."
  5171. (let (op)
  5172. (setq e (substring e 1))
  5173. (setq op (string-to-char e) e (substring e 1))
  5174. (setq op (cond ((equal op ?<) '<=)
  5175. ((equal op ?>) '>=)
  5176. ((equal op ??) op)
  5177. (t '=)))
  5178. (list 'org-agenda-compare-effort (list 'quote op)
  5179. (org-hh:mm-string-to-minutes e))))
  5180. (defun org-agenda-compare-effort (op value)
  5181. "Compare the effort of the current line with VALUE, using OP.
  5182. If the line does not have an effort defined, return nil."
  5183. (let ((eff (org-get-at-bol 'effort-minutes)))
  5184. (if (equal op ??)
  5185. (not eff)
  5186. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5187. value))))
  5188. (defun org-agenda-filter-apply (filter)
  5189. "Set FILTER as the new agenda filter and apply it."
  5190. (let (tags)
  5191. (setq org-agenda-filter filter
  5192. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5193. (org-agenda-set-mode-name)
  5194. (save-excursion
  5195. (goto-char (point-min))
  5196. (while (not (eobp))
  5197. (if (org-get-at-bol 'org-marker)
  5198. (progn
  5199. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5200. (if (not (eval org-agenda-filter-form))
  5201. (org-agenda-filter-by-tag-hide-line))
  5202. (beginning-of-line 2))
  5203. (beginning-of-line 2))))))
  5204. (defun org-agenda-filter-by-tag-hide-line ()
  5205. (let (ov)
  5206. (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
  5207. (point-at-eol)))
  5208. (org-overlay-put ov 'invisible t)
  5209. (org-overlay-put ov 'type 'tags-filter)
  5210. (push ov org-agenda-filter-overlays)))
  5211. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5212. (setq pos (or pos (point)))
  5213. (save-excursion
  5214. (dolist (ov (org-overlays-at pos))
  5215. (when (and (org-overlay-get ov 'invisible)
  5216. (eq (org-overlay-get ov 'type) 'tags-filter))
  5217. (goto-char pos)
  5218. (if (< (org-overlay-start ov) (point-at-eol))
  5219. (org-move-overlay ov (point-at-eol)
  5220. (org-overlay-end ov)))))))
  5221. (defun org-agenda-filter-by-tag-show-all ()
  5222. (mapc 'org-delete-overlay org-agenda-filter-overlays)
  5223. (setq org-agenda-filter-overlays nil)
  5224. (setq org-agenda-filter nil)
  5225. (setq org-agenda-filter-form nil)
  5226. (org-agenda-set-mode-name))
  5227. (defun org-agenda-manipulate-query-add ()
  5228. "Manipulate the query by adding a search term with positive selection.
  5229. Positive selection means the term must be matched for selection of an entry."
  5230. (interactive)
  5231. (org-agenda-manipulate-query ?\[))
  5232. (defun org-agenda-manipulate-query-subtract ()
  5233. "Manipulate the query by adding a search term with negative selection.
  5234. Negative selection means term must not be matched for selection of an entry."
  5235. (interactive)
  5236. (org-agenda-manipulate-query ?\]))
  5237. (defun org-agenda-manipulate-query-add-re ()
  5238. "Manipulate the query by adding a search regexp with positive selection.
  5239. Positive selection means the regexp must match for selection of an entry."
  5240. (interactive)
  5241. (org-agenda-manipulate-query ?\{))
  5242. (defun org-agenda-manipulate-query-subtract-re ()
  5243. "Manipulate the query by adding a search regexp with negative selection.
  5244. Negative selection means regexp must not match for selection of an entry."
  5245. (interactive)
  5246. (org-agenda-manipulate-query ?\}))
  5247. (defun org-agenda-manipulate-query (char)
  5248. (cond
  5249. ((memq org-agenda-type '(timeline agenda))
  5250. (let ((org-agenda-include-inactive-timestamps t))
  5251. (org-agenda-redo))
  5252. (message "Display now includes inactive timestamps as well"))
  5253. ((eq org-agenda-type 'search)
  5254. (org-add-to-string
  5255. 'org-agenda-query-string
  5256. (if org-agenda-last-search-view-search-was-boolean
  5257. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5258. (?\{ . " +{}") (?\} . " -{}"))))
  5259. " "))
  5260. (setq org-agenda-redo-command
  5261. (list 'org-search-view
  5262. org-todo-only
  5263. org-agenda-query-string
  5264. (+ (length org-agenda-query-string)
  5265. (if (member char '(?\{ ?\})) 0 1))))
  5266. (set-register org-agenda-query-register org-agenda-query-string)
  5267. (org-agenda-redo))
  5268. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5269. org-agenda-type))))
  5270. (defun org-add-to-string (var string)
  5271. (set var (concat (symbol-value var) string)))
  5272. (defun org-agenda-goto-date (date)
  5273. "Jump to DATE in agenda."
  5274. (interactive (list (org-read-date)))
  5275. (org-agenda-list nil date))
  5276. (defun org-agenda-goto-today ()
  5277. "Go to today."
  5278. (interactive)
  5279. (org-agenda-check-type t 'timeline 'agenda)
  5280. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5281. (cond
  5282. (tdpos (goto-char tdpos))
  5283. ((eq org-agenda-type 'agenda)
  5284. (let* ((sd (time-to-days
  5285. (time-subtract (current-time)
  5286. (list 0 (* 3600 org-extend-today-until) 0))))
  5287. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5288. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5289. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5290. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5291. (org-agenda-redo)
  5292. (org-agenda-find-same-or-today-or-agenda)))
  5293. (t (error "Cannot find today")))))
  5294. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5295. (goto-char
  5296. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5297. (text-property-any (point-min) (point-max) 'org-today t)
  5298. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5299. (point-min))))
  5300. (defun org-agenda-later (arg)
  5301. "Go forward in time by thee current span.
  5302. With prefix ARG, go forward that many times the current span."
  5303. (interactive "p")
  5304. (org-agenda-check-type t 'agenda)
  5305. (let* ((span org-agenda-span)
  5306. (sd org-starting-day)
  5307. (greg (calendar-gregorian-from-absolute sd))
  5308. (cnt (org-get-at-bol 'org-day-cnt))
  5309. greg2 nd)
  5310. (cond
  5311. ((eq span 'day)
  5312. (setq sd (+ arg sd) nd 1))
  5313. ((eq span 'week)
  5314. (setq sd (+ (* 7 arg) sd) nd 7))
  5315. ((eq span 'month)
  5316. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5317. sd (calendar-absolute-from-gregorian greg2))
  5318. (setcar greg2 (1+ (car greg2)))
  5319. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5320. ((eq span 'year)
  5321. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5322. sd (calendar-absolute-from-gregorian greg2))
  5323. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5324. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5325. (let ((org-agenda-overriding-arguments
  5326. (list (car org-agenda-last-arguments) sd nd t)))
  5327. (org-agenda-redo)
  5328. (org-agenda-find-same-or-today-or-agenda cnt))))
  5329. (defun org-agenda-earlier (arg)
  5330. "Go backward in time by the current span.
  5331. With prefix ARG, go backward that many times the current span."
  5332. (interactive "p")
  5333. (org-agenda-later (- arg)))
  5334. (defun org-agenda-view-mode-dispatch ()
  5335. "Call one of the view mode commands."
  5336. (interactive)
  5337. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5338. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5339. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5340. (let ((a (read-char-exclusive)))
  5341. (case a
  5342. (?d (call-interactively 'org-agenda-day-view))
  5343. (?w (call-interactively 'org-agenda-week-view))
  5344. (?m (call-interactively 'org-agenda-month-view))
  5345. (?y (call-interactively 'org-agenda-year-view))
  5346. (?l (call-interactively 'org-agenda-log-mode))
  5347. (?L (org-agenda-log-mode '(4)))
  5348. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5349. (?a (call-interactively 'org-agenda-archives-mode))
  5350. (?A (org-agenda-archives-mode 'files))
  5351. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5352. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5353. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5354. (?D (call-interactively 'org-agenda-toggle-diary))
  5355. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5356. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5357. (org-agenda-check-type t 'timeline 'agenda)
  5358. (org-agenda-redo))
  5359. (message "Display now includes inactive timestamps as well"))
  5360. (?q (message "Abort"))
  5361. (otherwise (error "Invalid key" )))))
  5362. (defun org-agenda-day-view (&optional day-of-year)
  5363. "Switch to daily view for agenda.
  5364. With argument DAY-OF-YEAR, switch to that day of the year."
  5365. (interactive "P")
  5366. (setq org-agenda-ndays 1)
  5367. (org-agenda-change-time-span 'day day-of-year))
  5368. (defun org-agenda-week-view (&optional iso-week)
  5369. "Switch to daily view for agenda.
  5370. With argument ISO-WEEK, switch to the corresponding ISO week.
  5371. If ISO-WEEK has more then 2 digits, only the last two encode the
  5372. week. Any digits before this encode a year. So 200712 means
  5373. week 12 of year 2007. Years in the range 1938-2037 can also be
  5374. written as 2-digit years."
  5375. (interactive "P")
  5376. (setq org-agenda-ndays 7)
  5377. (org-agenda-change-time-span 'week iso-week))
  5378. (defun org-agenda-month-view (&optional month)
  5379. "Switch to monthly view for agenda.
  5380. With argument MONTH, switch to that month."
  5381. (interactive "P")
  5382. (org-agenda-change-time-span 'month month))
  5383. (defun org-agenda-year-view (&optional year)
  5384. "Switch to yearly view for agenda.
  5385. With argument YEAR, switch to that year.
  5386. If MONTH has more then 2 digits, only the last two encode the
  5387. month. Any digits before this encode a year. So 200712 means
  5388. December year 2007. Years in the range 1938-2037 can also be
  5389. written as 2-digit years."
  5390. (interactive "P")
  5391. (when year
  5392. (setq year (org-small-year-to-year year)))
  5393. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5394. (org-agenda-change-time-span 'year year)
  5395. (error "Abort")))
  5396. (defun org-agenda-change-time-span (span &optional n)
  5397. "Change the agenda view to SPAN.
  5398. SPAN may be `day', `week', `month', `year'."
  5399. (org-agenda-check-type t 'agenda)
  5400. (if (and (not n) (equal org-agenda-span span))
  5401. (error "Viewing span is already \"%s\"" span))
  5402. (let* ((sd (or (org-get-at-bol 'day)
  5403. org-starting-day))
  5404. (computed (org-agenda-compute-time-span sd span n))
  5405. (org-agenda-overriding-arguments
  5406. (list (car org-agenda-last-arguments)
  5407. (car computed) (cdr computed) t)))
  5408. (org-agenda-redo)
  5409. (org-agenda-find-same-or-today-or-agenda))
  5410. (org-agenda-set-mode-name)
  5411. (message "Switched to %s view" span))
  5412. (defun org-agenda-compute-time-span (sd span &optional n)
  5413. "Compute starting date and number of days for agenda.
  5414. SPAN may be `day', `week', `month', `year'. The return value
  5415. is a cons cell with the starting date and the number of days,
  5416. so that the date SD will be in that range."
  5417. (let* ((greg (calendar-gregorian-from-absolute sd))
  5418. (dg (nth 1 greg))
  5419. (mg (car greg))
  5420. (yg (nth 2 greg))
  5421. nd w1 y1 m1 thisweek)
  5422. (cond
  5423. ((eq span 'day)
  5424. (when n
  5425. (setq sd (+ (calendar-absolute-from-gregorian
  5426. (list mg 1 yg))
  5427. n -1)))
  5428. (setq nd 1))
  5429. ((eq span 'week)
  5430. (let* ((nt (calendar-day-of-week
  5431. (calendar-gregorian-from-absolute sd)))
  5432. (d (if org-agenda-start-on-weekday
  5433. (- nt org-agenda-start-on-weekday)
  5434. 0)))
  5435. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5436. (when n
  5437. (require 'cal-iso)
  5438. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5439. (when (> n 99)
  5440. (setq y1 (org-small-year-to-year (/ n 100))
  5441. n (mod n 100)))
  5442. (setq sd
  5443. (calendar-absolute-from-iso
  5444. (list n 1
  5445. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5446. (setq nd 7)))
  5447. ((eq span 'month)
  5448. (when (and n (> n 99))
  5449. (setq y1 (org-small-year-to-year (/ n 100))
  5450. n (mod n 100)))
  5451. (setq sd (calendar-absolute-from-gregorian
  5452. (list (or n mg) 1 (or y1 yg)))
  5453. nd (- (calendar-absolute-from-gregorian
  5454. (list (1+ (or n mg)) 1 (or y1 yg)))
  5455. sd)))
  5456. ((eq span 'year)
  5457. (setq sd (calendar-absolute-from-gregorian
  5458. (list 1 1 (or n yg)))
  5459. nd (- (calendar-absolute-from-gregorian
  5460. (list 1 1 (1+ (or n yg))))
  5461. sd))))
  5462. (cons sd nd)))
  5463. (defun org-agenda-next-date-line (&optional arg)
  5464. "Jump to the next line indicating a date in agenda buffer."
  5465. (interactive "p")
  5466. (org-agenda-check-type t 'agenda 'timeline)
  5467. (beginning-of-line 1)
  5468. ;; This does not work if user makes date format that starts with a blank
  5469. (if (looking-at "^\\S-") (forward-char 1))
  5470. (if (not (re-search-forward "^\\S-" nil t arg))
  5471. (progn
  5472. (backward-char 1)
  5473. (error "No next date after this line in this buffer")))
  5474. (goto-char (match-beginning 0)))
  5475. (defun org-agenda-previous-date-line (&optional arg)
  5476. "Jump to the previous line indicating a date in agenda buffer."
  5477. (interactive "p")
  5478. (org-agenda-check-type t 'agenda 'timeline)
  5479. (beginning-of-line 1)
  5480. (if (not (re-search-backward "^\\S-" nil t arg))
  5481. (error "No previous date before this line in this buffer")))
  5482. ;; Initialize the highlight
  5483. (defvar org-hl (org-make-overlay 1 1))
  5484. (org-overlay-put org-hl 'face 'highlight)
  5485. (defun org-highlight (begin end &optional buffer)
  5486. "Highlight a region with overlay."
  5487. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  5488. org-hl begin end (or buffer (current-buffer))))
  5489. (defun org-unhighlight ()
  5490. "Detach overlay INDEX."
  5491. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  5492. ;; FIXME this is currently not used.
  5493. (defun org-highlight-until-next-command (beg end &optional buffer)
  5494. "Move the highlight overlay to BEG/END, remove it before the next command."
  5495. (org-highlight beg end buffer)
  5496. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5497. (defun org-unhighlight-once ()
  5498. "Remove the highlight from its position, and this function from the hook."
  5499. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5500. (org-unhighlight))
  5501. (defun org-agenda-follow-mode ()
  5502. "Toggle follow mode in an agenda buffer."
  5503. (interactive)
  5504. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5505. (org-agenda-set-mode-name)
  5506. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5507. (org-agenda-show))
  5508. (message "Follow mode is %s"
  5509. (if org-agenda-follow-mode "on" "off")))
  5510. (defun org-agenda-entry-text-mode (&optional arg)
  5511. "Toggle entry text mode in an agenda buffer."
  5512. (interactive "P")
  5513. (if (integerp arg)
  5514. (setq org-agenda-entry-text-mode t)
  5515. (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
  5516. (org-agenda-entry-text-hide)
  5517. (and org-agenda-entry-text-mode
  5518. (let ((org-agenda-entry-text-maxlines
  5519. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5520. (org-agenda-entry-text-show)))
  5521. (org-agenda-set-mode-name)
  5522. (message "Entry text mode is %s. Maximum number of lines is %d"
  5523. (if org-agenda-entry-text-mode "on" "off")
  5524. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5525. (defun org-agenda-clockreport-mode ()
  5526. "Toggle clocktable mode in an agenda buffer."
  5527. (interactive)
  5528. (org-agenda-check-type t 'agenda)
  5529. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5530. (org-agenda-set-mode-name)
  5531. (org-agenda-redo)
  5532. (message "Clocktable mode is %s"
  5533. (if org-agenda-clockreport-mode "on" "off")))
  5534. (defun org-agenda-log-mode (&optional special)
  5535. "Toggle log mode in an agenda buffer.
  5536. With argument SPECIAL, show all possible log items, not only the ones
  5537. configured in `org-agenda-log-mode-items'.
  5538. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5539. (interactive "P")
  5540. (org-agenda-check-type t 'agenda 'timeline)
  5541. (setq org-agenda-show-log
  5542. (if (equal special '(16))
  5543. 'only
  5544. (if special '(closed clock state)
  5545. (not org-agenda-show-log))))
  5546. (org-agenda-set-mode-name)
  5547. (org-agenda-redo)
  5548. (message "Log mode is %s"
  5549. (if org-agenda-show-log "on" "off")))
  5550. (defun org-agenda-archives-mode (&optional with-files)
  5551. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5552. When called with a prefix argument, include all archive files as well."
  5553. (interactive "P")
  5554. (setq org-agenda-archives-mode
  5555. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5556. (org-agenda-set-mode-name)
  5557. (org-agenda-redo)
  5558. (message
  5559. "%s"
  5560. (cond
  5561. ((eq org-agenda-archives-mode nil)
  5562. "No archives are included")
  5563. ((eq org-agenda-archives-mode 'trees)
  5564. (format "Trees with :%s: tag are included" org-archive-tag))
  5565. ((eq org-agenda-archives-mode t)
  5566. (format "Trees with :%s: tag and all active archive files are included"
  5567. org-archive-tag)))))
  5568. (defun org-agenda-toggle-diary ()
  5569. "Toggle diary inclusion in an agenda buffer."
  5570. (interactive)
  5571. (org-agenda-check-type t 'agenda)
  5572. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5573. (org-agenda-redo)
  5574. (org-agenda-set-mode-name)
  5575. (message "Diary inclusion turned %s"
  5576. (if org-agenda-include-diary "on" "off")))
  5577. (defun org-agenda-toggle-deadlines ()
  5578. "Toggle diary inclusion in an agenda buffer."
  5579. (interactive)
  5580. (org-agenda-check-type t 'agenda)
  5581. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5582. (org-agenda-redo)
  5583. (org-agenda-set-mode-name)
  5584. (message "Deadlines inclusion turned %s"
  5585. (if org-agenda-include-deadlines "on" "off")))
  5586. (defun org-agenda-toggle-time-grid ()
  5587. "Toggle time grid in an agenda buffer."
  5588. (interactive)
  5589. (org-agenda-check-type t 'agenda)
  5590. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5591. (org-agenda-redo)
  5592. (org-agenda-set-mode-name)
  5593. (message "Time-grid turned %s"
  5594. (if org-agenda-use-time-grid "on" "off")))
  5595. (defun org-agenda-set-mode-name ()
  5596. "Set the mode name to indicate all the small mode settings."
  5597. (setq mode-name
  5598. (concat "Org-Agenda"
  5599. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5600. (if (equal org-agenda-ndays 1) " Day" "")
  5601. (if (equal org-agenda-ndays 7) " Week" "")
  5602. (if org-agenda-follow-mode " Follow" "")
  5603. (if org-agenda-entry-text-mode " ETxt" "")
  5604. (if org-agenda-include-diary " Diary" "")
  5605. (if org-agenda-include-deadlines " Ddl" "")
  5606. (if org-agenda-use-time-grid " Grid" "")
  5607. (if (and (boundp 'org-habit-show-habits)
  5608. org-habit-show-habits) " Habit" "")
  5609. (if (consp org-agenda-show-log) " LogAll"
  5610. (if org-agenda-show-log " Log" ""))
  5611. (if (or org-agenda-filter (get 'org-agenda-filter
  5612. :preset-filter))
  5613. (concat " {" (mapconcat
  5614. 'identity
  5615. (append (get 'org-agenda-filter
  5616. :preset-filter)
  5617. org-agenda-filter) "") "}")
  5618. "")
  5619. (if org-agenda-archives-mode
  5620. (if (eq org-agenda-archives-mode t)
  5621. " Archives"
  5622. (format " :%s:" org-archive-tag))
  5623. "")
  5624. (if org-agenda-clockreport-mode " Clock" "")))
  5625. (force-mode-line-update))
  5626. (defun org-agenda-post-command-hook ()
  5627. (setq org-agenda-type
  5628. (or (get-text-property (point) 'org-agenda-type)
  5629. (get-text-property (max (point-min) (1- (point)))
  5630. 'org-agenda-type))))
  5631. (defun org-agenda-next-line ()
  5632. "Move cursor to the next line, and show if follow-mode is active."
  5633. (interactive)
  5634. (call-interactively 'next-line)
  5635. (org-agenda-do-context-action))
  5636. (defun org-agenda-previous-line ()
  5637. "Move cursor to the previous line, and show if follow-mode is active."
  5638. (interactive)
  5639. (call-interactively 'previous-line)
  5640. (org-agenda-do-context-action))
  5641. (defun org-agenda-do-context-action ()
  5642. "Show outline path and, maybe, follow-mode window."
  5643. (let ((m (org-get-at-bol 'org-marker)))
  5644. (if (and org-agenda-follow-mode m)
  5645. (org-agenda-show))
  5646. (if (and m org-agenda-show-outline-path)
  5647. (org-with-point-at m
  5648. (org-display-outline-path t)))))
  5649. (defun org-agenda-show-priority ()
  5650. "Show the priority of the current item.
  5651. This priority is composed of the main priority given with the [#A] cookies,
  5652. and by additional input from the age of a schedules or deadline entry."
  5653. (interactive)
  5654. (let* ((pri (org-get-at-bol 'priority)))
  5655. (message "Priority is %d" (if pri pri -1000))))
  5656. (defun org-agenda-show-tags ()
  5657. "Show the tags applicable to the current item."
  5658. (interactive)
  5659. (let* ((tags (org-get-at-bol 'tags)))
  5660. (if tags
  5661. (message "Tags are :%s:"
  5662. (org-no-properties (mapconcat 'identity tags ":")))
  5663. (message "No tags associated with this line"))))
  5664. (defun org-agenda-goto (&optional highlight)
  5665. "Go to the Org-mode file which contains the item at point."
  5666. (interactive)
  5667. (let* ((marker (or (org-get-at-bol 'org-marker)
  5668. (org-agenda-error)))
  5669. (buffer (marker-buffer marker))
  5670. (pos (marker-position marker)))
  5671. (switch-to-buffer-other-window buffer)
  5672. (widen)
  5673. (goto-char pos)
  5674. (when (org-mode-p)
  5675. (org-show-context 'agenda)
  5676. (save-excursion
  5677. (and (outline-next-heading)
  5678. (org-flag-heading nil)))) ; show the next heading
  5679. (recenter (/ (window-height) 2))
  5680. (run-hooks 'org-agenda-after-show-hook)
  5681. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5682. (defvar org-agenda-after-show-hook nil
  5683. "Normal hook run after an item has been shown from the agenda.
  5684. Point is in the buffer where the item originated.")
  5685. (defun org-agenda-kill ()
  5686. "Kill the entry or subtree belonging to the current agenda entry."
  5687. (interactive)
  5688. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5689. (let* ((marker (or (org-get-at-bol 'org-marker)
  5690. (org-agenda-error)))
  5691. (buffer (marker-buffer marker))
  5692. (pos (marker-position marker))
  5693. (type (org-get-at-bol 'type))
  5694. dbeg dend (n 0) conf)
  5695. (org-with-remote-undo buffer
  5696. (with-current-buffer buffer
  5697. (save-excursion
  5698. (goto-char pos)
  5699. (if (and (org-mode-p) (not (member type '("sexp"))))
  5700. (setq dbeg (progn (org-back-to-heading t) (point))
  5701. dend (org-end-of-subtree t t))
  5702. (setq dbeg (point-at-bol)
  5703. dend (min (point-max) (1+ (point-at-eol)))))
  5704. (goto-char dbeg)
  5705. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5706. (setq conf (or (eq t org-agenda-confirm-kill)
  5707. (and (numberp org-agenda-confirm-kill)
  5708. (> n org-agenda-confirm-kill))))
  5709. (and conf
  5710. (not (y-or-n-p
  5711. (format "Delete entry with %d lines in buffer \"%s\"? "
  5712. n (buffer-name buffer))))
  5713. (error "Abort"))
  5714. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5715. (with-current-buffer buffer (delete-region dbeg dend))
  5716. (message "Agenda item and source killed"))))
  5717. (defvar org-archive-default-command)
  5718. (defun org-agenda-archive-default ()
  5719. "Archive the entry or subtree belonging to the current agenda entry."
  5720. (interactive)
  5721. (require 'org-archive)
  5722. (org-agenda-archive-with org-archive-default-command))
  5723. (defun org-agenda-archive-default-with-confirmation ()
  5724. "Archive the entry or subtree belonging to the current agenda entry."
  5725. (interactive)
  5726. (require 'org-archive)
  5727. (org-agenda-archive-with org-archive-default-command 'confirm))
  5728. (defun org-agenda-archive ()
  5729. "Archive the entry or subtree belonging to the current agenda entry."
  5730. (interactive)
  5731. (org-agenda-archive-with 'org-archive-subtree))
  5732. (defun org-agenda-archive-to-archive-sibling ()
  5733. "Move the entry to the archive sibling."
  5734. (interactive)
  5735. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5736. (defun org-agenda-archive-with (cmd &optional confirm)
  5737. "Move the entry to the archive sibling."
  5738. (interactive)
  5739. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5740. (let* ((marker (or (org-get-at-bol 'org-marker)
  5741. (org-agenda-error)))
  5742. (buffer (marker-buffer marker))
  5743. (pos (marker-position marker)))
  5744. (org-with-remote-undo buffer
  5745. (with-current-buffer buffer
  5746. (if (org-mode-p)
  5747. (if (and confirm
  5748. (not (y-or-n-p "Archive this subtree or entry? ")))
  5749. (error "Abort")
  5750. (save-excursion
  5751. (goto-char pos)
  5752. (org-remove-subtree-entries-from-agenda)
  5753. (org-back-to-heading t)
  5754. (funcall cmd)))
  5755. (error "Archiving works only in Org-mode files"))))))
  5756. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5757. "Remove all lines in the agenda that correspond to a given subtree.
  5758. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5759. If this information is not given, the function uses the tree at point."
  5760. (let ((buf (or buf (current-buffer))) m p)
  5761. (save-excursion
  5762. (unless (and beg end)
  5763. (org-back-to-heading t)
  5764. (setq beg (point))
  5765. (org-end-of-subtree t)
  5766. (setq end (point)))
  5767. (set-buffer (get-buffer org-agenda-buffer-name))
  5768. (save-excursion
  5769. (goto-char (point-max))
  5770. (beginning-of-line 1)
  5771. (while (not (bobp))
  5772. (when (and (setq m (org-get-at-bol 'org-marker))
  5773. (equal buf (marker-buffer m))
  5774. (setq p (marker-position m))
  5775. (>= p beg)
  5776. (< p end))
  5777. (let ((inhibit-read-only t))
  5778. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5779. (beginning-of-line 0))))))
  5780. (defun org-agenda-refile (&optional goto rfloc)
  5781. "Refile the item at point."
  5782. (interactive "P")
  5783. (if (equal goto '(16))
  5784. (org-refile-goto-last-stored)
  5785. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5786. (org-agenda-error)))
  5787. (buffer (marker-buffer marker))
  5788. (pos (marker-position marker))
  5789. (rfloc (or rfloc
  5790. (org-refile-get-location
  5791. (if goto "Goto: " "Refile to: ") buffer
  5792. org-refile-allow-creating-parent-nodes))))
  5793. (with-current-buffer buffer
  5794. (save-excursion
  5795. (save-restriction
  5796. (widen)
  5797. (goto-char marker)
  5798. (org-remove-subtree-entries-from-agenda)
  5799. (org-refile goto buffer rfloc)))))))
  5800. (defun org-agenda-open-link (&optional arg)
  5801. "Follow the link in the current line, if any.
  5802. This looks for a link in the displayed line in the agenda. It also looks
  5803. at the text of the entry itself."
  5804. (interactive "P")
  5805. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5806. (org-get-at-bol 'org-marker)))
  5807. (buffer (and marker (marker-buffer marker)))
  5808. (prefix (buffer-substring
  5809. (point-at-bol)
  5810. (+ (point-at-bol)
  5811. (or (org-get-at-bol 'prefix-length) 0)))))
  5812. (cond
  5813. (buffer
  5814. (with-current-buffer buffer
  5815. (save-excursion
  5816. (save-restriction
  5817. (widen)
  5818. (goto-char marker)
  5819. (org-offer-links-in-entry arg prefix)))))
  5820. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5821. (save-excursion
  5822. (beginning-of-line 1)
  5823. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5824. (org-open-link-from-string (match-string 1)))
  5825. (t (error "No link to open here")))))
  5826. (defun org-agenda-copy-local-variable (var)
  5827. "Get a variable from a referenced buffer and install it here."
  5828. (let ((m (org-get-at-bol 'org-marker)))
  5829. (when (and m (buffer-live-p (marker-buffer m)))
  5830. (org-set-local var (with-current-buffer (marker-buffer m)
  5831. (symbol-value var))))))
  5832. (defun org-agenda-switch-to (&optional delete-other-windows)
  5833. "Go to the Org-mode file which contains the item at point."
  5834. (interactive)
  5835. (if (and org-return-follows-link
  5836. (not (org-get-at-bol 'org-marker))
  5837. (org-in-regexp org-bracket-link-regexp))
  5838. (org-open-link-from-string (match-string 0))
  5839. (let* ((marker (or (org-get-at-bol 'org-marker)
  5840. (org-agenda-error)))
  5841. (buffer (marker-buffer marker))
  5842. (pos (marker-position marker)))
  5843. (switch-to-buffer buffer)
  5844. (and delete-other-windows (delete-other-windows))
  5845. (widen)
  5846. (goto-char pos)
  5847. (when (org-mode-p)
  5848. (org-show-context 'agenda)
  5849. (save-excursion
  5850. (and (outline-next-heading)
  5851. (org-flag-heading nil))))))) ; show the next heading
  5852. (defun org-agenda-goto-mouse (ev)
  5853. "Go to the Org-mode file which contains the item at the mouse click."
  5854. (interactive "e")
  5855. (mouse-set-point ev)
  5856. (org-agenda-goto))
  5857. (defun org-agenda-show (&optional full-entry)
  5858. "Display the Org-mode file which contains the item at point.
  5859. With prefix argument FULL-ENTRY, make the entire entry visible
  5860. if it was hidden in the outline."
  5861. (interactive "P")
  5862. (let ((win (selected-window)))
  5863. (if full-entry
  5864. (let ((org-show-entry-below t))
  5865. (org-agenda-goto t))
  5866. (org-agenda-goto t))
  5867. (select-window win)))
  5868. (defvar org-agenda-show-window nil)
  5869. (defun org-agenda-show-and-scroll-up ()
  5870. "Display the Org-mode file which contains the item at point.
  5871. When called repeatedly, scroll the window that is displaying the buffer."
  5872. (interactive)
  5873. (let ((win (selected-window)))
  5874. (if (and (window-live-p org-agenda-show-window)
  5875. (eq this-command last-command))
  5876. (progn
  5877. (select-window org-agenda-show-window)
  5878. (ignore-errors (scroll-up)))
  5879. (org-agenda-goto t)
  5880. (show-subtree)
  5881. (setq org-agenda-show-window (selected-window)))
  5882. (select-window win)))
  5883. (defun org-agenda-show-scroll-down ()
  5884. "Scroll down the window showing the agenda."
  5885. (interactive)
  5886. (let ((win (selected-window)))
  5887. (when (window-live-p org-agenda-show-window)
  5888. (select-window org-agenda-show-window)
  5889. (ignore-errors (scroll-down))
  5890. (select-window win))))
  5891. (defun org-agenda-show-1 (&optional more)
  5892. "Display the Org-mode file which contains the item at point.
  5893. The prefix arg selects the amount of information to display:
  5894. 0 hide the subtree
  5895. 1 just show the entry according to defaults.
  5896. 2 show the children view
  5897. 3 show the subtree view
  5898. 4 show the entire subtree and any LOGBOOK drawers
  5899. 5 show the entire subtree and any drawers
  5900. With prefix argument FULL-ENTRY, make the entire entry visible
  5901. if it was hidden in the outline."
  5902. (interactive "p")
  5903. (let ((win (selected-window)))
  5904. (org-agenda-goto t)
  5905. (org-recenter-heading 1)
  5906. (cond
  5907. ((= more 0)
  5908. (hide-subtree)
  5909. (save-excursion
  5910. (org-back-to-heading)
  5911. (run-hook-with-args 'org-cycle-hook 'folded))
  5912. (message "Remote: FOLDED"))
  5913. ((and (interactive-p) (= more 1))
  5914. (message "Remote: show with default settings"))
  5915. ((= more 2)
  5916. (show-entry)
  5917. (show-children)
  5918. (save-excursion
  5919. (org-back-to-heading)
  5920. (run-hook-with-args 'org-cycle-hook 'children))
  5921. (message "Remote: CHILDREN"))
  5922. ((= more 3)
  5923. (show-subtree)
  5924. (save-excursion
  5925. (org-back-to-heading)
  5926. (run-hook-with-args 'org-cycle-hook 'subtree))
  5927. (message "Remote: SUBTREE"))
  5928. ((= more 4)
  5929. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  5930. (org-drawer-regexp
  5931. (concat "^[ \t]*:\\("
  5932. (mapconcat 'regexp-quote org-drawers "\\|")
  5933. "\\):[ \t]*$")))
  5934. (show-subtree)
  5935. (save-excursion
  5936. (org-back-to-heading)
  5937. (org-cycle-hide-drawers 'subtree)))
  5938. (message "Remote: SUBTREE AND LOGBOOK"))
  5939. ((> more 4)
  5940. (show-subtree)
  5941. (message "Remote: SUBTREE AND ALL DRAWERS")))
  5942. (select-window win)))
  5943. (defun org-recenter-heading (n)
  5944. (save-excursion
  5945. (org-back-to-heading)
  5946. (recenter n)))
  5947. (defvar org-agenda-cycle-counter nil)
  5948. (defun org-agenda-cycle-show (&optional n)
  5949. "Show the current entry in another window, with default settings.
  5950. Default settings are taken from `org-show-hierarchy-above' and siblings.
  5951. When use repeatedly in immediate succession, the remote entry will cycle
  5952. through visibility
  5953. children -> subtree -> folded
  5954. When called with a numeric prefix arg, that arg will be passed through to
  5955. `org-agenda-show-1'. For the interpretation of that argument, see the
  5956. docstring of `org-agenda-show-1'."
  5957. (interactive "P")
  5958. (if (integerp n)
  5959. (setq org-agenda-cycle-counter n)
  5960. (if (not (eq last-command this-command))
  5961. (setq org-agenda-cycle-counter 1)
  5962. (if (equal org-agenda-cycle-counter 0)
  5963. (setq org-agenda-cycle-counter 2)
  5964. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  5965. (if (> org-agenda-cycle-counter 3)
  5966. (setq org-agenda-cycle-counter 0)))))
  5967. (org-agenda-show-1 org-agenda-cycle-counter))
  5968. (defun org-agenda-recenter (arg)
  5969. "Display the Org-mode file which contains the item at point and recenter."
  5970. (interactive "P")
  5971. (let ((win (selected-window)))
  5972. (org-agenda-goto t)
  5973. (recenter arg)
  5974. (select-window win)))
  5975. (defun org-agenda-show-mouse (ev)
  5976. "Display the Org-mode file which contains the item at the mouse click."
  5977. (interactive "e")
  5978. (mouse-set-point ev)
  5979. (org-agenda-show))
  5980. (defun org-agenda-check-no-diary ()
  5981. "Check if the entry is a diary link and abort if yes."
  5982. (if (org-get-at-bol 'org-agenda-diary-link)
  5983. (org-agenda-error)))
  5984. (defun org-agenda-error ()
  5985. (error "Command not allowed in this line"))
  5986. (defun org-agenda-tree-to-indirect-buffer ()
  5987. "Show the subtree corresponding to the current entry in an indirect buffer.
  5988. This calls the command `org-tree-to-indirect-buffer' from the original
  5989. Org-mode buffer.
  5990. With numerical prefix arg ARG, go up to this level and then take that tree.
  5991. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  5992. dedicated frame)."
  5993. (interactive)
  5994. (org-agenda-check-no-diary)
  5995. (let* ((marker (or (org-get-at-bol 'org-marker)
  5996. (org-agenda-error)))
  5997. (buffer (marker-buffer marker))
  5998. (pos (marker-position marker)))
  5999. (with-current-buffer buffer
  6000. (save-excursion
  6001. (goto-char pos)
  6002. (call-interactively 'org-tree-to-indirect-buffer)))))
  6003. (defvar org-last-heading-marker (make-marker)
  6004. "Marker pointing to the headline that last changed its TODO state
  6005. by a remote command from the agenda.")
  6006. (defun org-agenda-todo-nextset ()
  6007. "Switch TODO entry to next sequence."
  6008. (interactive)
  6009. (org-agenda-todo 'nextset))
  6010. (defun org-agenda-todo-previousset ()
  6011. "Switch TODO entry to previous sequence."
  6012. (interactive)
  6013. (org-agenda-todo 'previousset))
  6014. (defun org-agenda-todo (&optional arg)
  6015. "Cycle TODO state of line at point, also in Org-mode file.
  6016. This changes the line at point, all other lines in the agenda referring to
  6017. the same tree node, and the headline of the tree node in the Org-mode file."
  6018. (interactive "P")
  6019. (org-agenda-check-no-diary)
  6020. (let* ((col (current-column))
  6021. (marker (or (org-get-at-bol 'org-marker)
  6022. (org-agenda-error)))
  6023. (buffer (marker-buffer marker))
  6024. (pos (marker-position marker))
  6025. (hdmarker (org-get-at-bol 'org-hd-marker))
  6026. (todayp (equal (org-get-at-bol 'day)
  6027. (time-to-days (current-time))))
  6028. (inhibit-read-only t)
  6029. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6030. (org-with-remote-undo buffer
  6031. (with-current-buffer buffer
  6032. (widen)
  6033. (goto-char pos)
  6034. (org-show-context 'agenda)
  6035. (save-excursion
  6036. (and (outline-next-heading)
  6037. (org-flag-heading nil))) ; show the next heading
  6038. (let ((current-prefix-arg arg))
  6039. (call-interactively 'org-todo))
  6040. (and (bolp) (forward-char 1))
  6041. (setq newhead (org-get-heading))
  6042. (when (and (org-bound-and-true-p
  6043. org-agenda-headline-snapshot-before-repeat)
  6044. (not (equal org-agenda-headline-snapshot-before-repeat
  6045. newhead))
  6046. todayp)
  6047. (setq newhead org-agenda-headline-snapshot-before-repeat
  6048. just-one t))
  6049. (save-excursion
  6050. (org-back-to-heading)
  6051. (move-marker org-last-heading-marker (point))))
  6052. (beginning-of-line 1)
  6053. (save-excursion
  6054. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6055. (org-move-to-column col))))
  6056. (defun org-agenda-add-note (&optional arg)
  6057. "Add a time-stamped note to the entry at point."
  6058. (interactive "P")
  6059. (org-agenda-check-no-diary)
  6060. (let* ((marker (or (org-get-at-bol 'org-marker)
  6061. (org-agenda-error)))
  6062. (buffer (marker-buffer marker))
  6063. (pos (marker-position marker))
  6064. (hdmarker (org-get-at-bol 'org-hd-marker))
  6065. (inhibit-read-only t))
  6066. (with-current-buffer buffer
  6067. (widen)
  6068. (goto-char pos)
  6069. (org-show-context 'agenda)
  6070. (save-excursion
  6071. (and (outline-next-heading)
  6072. (org-flag-heading nil))) ; show the next heading
  6073. (org-add-note))))
  6074. (defun org-agenda-change-all-lines (newhead hdmarker
  6075. &optional fixface just-this)
  6076. "Change all lines in the agenda buffer which match HDMARKER.
  6077. The new content of the line will be NEWHEAD (as modified by
  6078. `org-format-agenda-item'). HDMARKER is checked with
  6079. `equal' against all `org-hd-marker' text properties in the file.
  6080. If FIXFACE is non-nil, the face of each item is modified according to
  6081. the new TODO state.
  6082. If JUST-THIS is non-nil, change just the current line, not all.
  6083. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6084. (let* ((inhibit-read-only t)
  6085. (line (org-current-line))
  6086. (thetags (with-current-buffer (marker-buffer hdmarker)
  6087. (save-excursion (save-restriction (widen)
  6088. (goto-char hdmarker)
  6089. (org-get-tags-at)))))
  6090. props m pl undone-face done-face finish new dotime cat tags)
  6091. (save-excursion
  6092. (goto-char (point-max))
  6093. (beginning-of-line 1)
  6094. (while (not finish)
  6095. (setq finish (bobp))
  6096. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6097. (or (not just-this) (= (org-current-line) line))
  6098. (equal m hdmarker))
  6099. (setq props (text-properties-at (point))
  6100. dotime (org-get-at-bol 'dotime)
  6101. cat (org-get-at-bol 'org-category)
  6102. tags thetags
  6103. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6104. pl (org-get-at-bol 'prefix-length)
  6105. undone-face (org-get-at-bol 'undone-face)
  6106. done-face (org-get-at-bol 'done-face))
  6107. (goto-char (+ (point) pl))
  6108. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6109. (cond
  6110. ((equal new "")
  6111. (beginning-of-line 1)
  6112. (and (looking-at ".*\n?") (replace-match "")))
  6113. ((looking-at ".*")
  6114. (replace-match new t t)
  6115. (beginning-of-line 1)
  6116. (add-text-properties (point-at-bol) (point-at-eol) props)
  6117. (when fixface
  6118. (add-text-properties
  6119. (point-at-bol) (point-at-eol)
  6120. (list 'face
  6121. (if org-last-todo-state-is-todo
  6122. undone-face done-face))))
  6123. (org-agenda-highlight-todo 'line)
  6124. (beginning-of-line 1))
  6125. (t (error "Line update did not work"))))
  6126. (beginning-of-line 0)))
  6127. (org-finalize-agenda)))
  6128. (defun org-agenda-align-tags (&optional line)
  6129. "Align all tags in agenda items to `org-agenda-tags-column'."
  6130. (let ((inhibit-read-only t) l c)
  6131. (save-excursion
  6132. (goto-char (if line (point-at-bol) (point-min)))
  6133. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  6134. (if line (point-at-eol) nil) t)
  6135. (add-text-properties
  6136. (match-beginning 2) (match-end 2)
  6137. (list 'face (delq nil (let ((prop (get-text-property
  6138. (match-beginning 2) 'face)))
  6139. (or (listp prop) (setq prop (list prop)))
  6140. (if (memq 'org-tag prop)
  6141. prop
  6142. (cons 'org-tag prop))))))
  6143. (setq l (- (match-end 2) (match-beginning 2))
  6144. c (if (< org-agenda-tags-column 0)
  6145. (- (abs org-agenda-tags-column) l)
  6146. org-agenda-tags-column))
  6147. (delete-region (match-beginning 1) (match-end 1))
  6148. (goto-char (match-beginning 1))
  6149. (insert (org-add-props
  6150. (make-string (max 1 (- c (current-column))) ?\ )
  6151. (plist-put (copy-sequence (text-properties-at (point)))
  6152. 'face nil))))
  6153. (goto-char (point-min))
  6154. (org-font-lock-add-tag-faces (point-max)))))
  6155. (defun org-agenda-priority-up ()
  6156. "Increase the priority of line at point, also in Org-mode file."
  6157. (interactive)
  6158. (org-agenda-priority 'up))
  6159. (defun org-agenda-priority-down ()
  6160. "Decrease the priority of line at point, also in Org-mode file."
  6161. (interactive)
  6162. (org-agenda-priority 'down))
  6163. (defun org-agenda-priority (&optional force-direction)
  6164. "Set the priority of line at point, also in Org-mode file.
  6165. This changes the line at point, all other lines in the agenda referring to
  6166. the same tree node, and the headline of the tree node in the Org-mode file."
  6167. (interactive)
  6168. (unless org-enable-priority-commands
  6169. (error "Priority commands are disabled"))
  6170. (org-agenda-check-no-diary)
  6171. (let* ((marker (or (org-get-at-bol 'org-marker)
  6172. (org-agenda-error)))
  6173. (hdmarker (org-get-at-bol 'org-hd-marker))
  6174. (buffer (marker-buffer hdmarker))
  6175. (pos (marker-position hdmarker))
  6176. (inhibit-read-only t)
  6177. newhead)
  6178. (org-with-remote-undo buffer
  6179. (with-current-buffer buffer
  6180. (widen)
  6181. (goto-char pos)
  6182. (org-show-context 'agenda)
  6183. (save-excursion
  6184. (and (outline-next-heading)
  6185. (org-flag-heading nil))) ; show the next heading
  6186. (funcall 'org-priority force-direction)
  6187. (end-of-line 1)
  6188. (setq newhead (org-get-heading)))
  6189. (org-agenda-change-all-lines newhead hdmarker)
  6190. (beginning-of-line 1))))
  6191. ;; FIXME: should fix the tags property of the agenda line.
  6192. (defun org-agenda-set-tags (&optional tag onoff)
  6193. "Set tags for the current headline."
  6194. (interactive)
  6195. (org-agenda-check-no-diary)
  6196. (if (and (org-region-active-p) (interactive-p))
  6197. (call-interactively 'org-change-tag-in-region)
  6198. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6199. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6200. (org-agenda-error)))
  6201. (buffer (marker-buffer hdmarker))
  6202. (pos (marker-position hdmarker))
  6203. (inhibit-read-only t)
  6204. newhead)
  6205. (org-with-remote-undo buffer
  6206. (with-current-buffer buffer
  6207. (widen)
  6208. (goto-char pos)
  6209. (save-excursion
  6210. (org-show-context 'agenda))
  6211. (save-excursion
  6212. (and (outline-next-heading)
  6213. (org-flag-heading nil))) ; show the next heading
  6214. (goto-char pos)
  6215. (if tag
  6216. (org-toggle-tag tag onoff)
  6217. (call-interactively 'org-set-tags))
  6218. (end-of-line 1)
  6219. (setq newhead (org-get-heading)))
  6220. (org-agenda-change-all-lines newhead hdmarker)
  6221. (beginning-of-line 1)))))
  6222. (defun org-agenda-set-property ()
  6223. "Set a property for the current headline."
  6224. (interactive)
  6225. (org-agenda-check-no-diary)
  6226. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6227. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6228. (org-agenda-error)))
  6229. (buffer (marker-buffer hdmarker))
  6230. (pos (marker-position hdmarker))
  6231. (inhibit-read-only t)
  6232. newhead)
  6233. (org-with-remote-undo buffer
  6234. (with-current-buffer buffer
  6235. (widen)
  6236. (goto-char pos)
  6237. (save-excursion
  6238. (org-show-context 'agenda))
  6239. (save-excursion
  6240. (and (outline-next-heading)
  6241. (org-flag-heading nil))) ; show the next heading
  6242. (goto-char pos)
  6243. (call-interactively 'org-set-property)))))
  6244. (defun org-agenda-set-effort ()
  6245. "Set the effort property for the current headline."
  6246. (interactive)
  6247. (org-agenda-check-no-diary)
  6248. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6249. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6250. (org-agenda-error)))
  6251. (buffer (marker-buffer hdmarker))
  6252. (pos (marker-position hdmarker))
  6253. (inhibit-read-only t)
  6254. newhead)
  6255. (org-with-remote-undo buffer
  6256. (with-current-buffer buffer
  6257. (widen)
  6258. (goto-char pos)
  6259. (save-excursion
  6260. (org-show-context 'agenda))
  6261. (save-excursion
  6262. (and (outline-next-heading)
  6263. (org-flag-heading nil))) ; show the next heading
  6264. (goto-char pos)
  6265. (call-interactively 'org-set-effort)
  6266. (end-of-line 1)))))
  6267. (defun org-agenda-toggle-archive-tag ()
  6268. "Toggle the archive tag for the current entry."
  6269. (interactive)
  6270. (org-agenda-check-no-diary)
  6271. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6272. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6273. (org-agenda-error)))
  6274. (buffer (marker-buffer hdmarker))
  6275. (pos (marker-position hdmarker))
  6276. (inhibit-read-only t)
  6277. newhead)
  6278. (org-with-remote-undo buffer
  6279. (with-current-buffer buffer
  6280. (widen)
  6281. (goto-char pos)
  6282. (org-show-context 'agenda)
  6283. (save-excursion
  6284. (and (outline-next-heading)
  6285. (org-flag-heading nil))) ; show the next heading
  6286. (call-interactively 'org-toggle-archive-tag)
  6287. (end-of-line 1)
  6288. (setq newhead (org-get-heading)))
  6289. (org-agenda-change-all-lines newhead hdmarker)
  6290. (beginning-of-line 1))))
  6291. (defun org-agenda-do-date-later (arg)
  6292. (interactive "P")
  6293. (cond
  6294. ((or (equal arg '(16))
  6295. (memq last-command
  6296. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6297. (setq this-command 'org-agenda-date-later-minutes)
  6298. (org-agenda-date-later-minutes 1))
  6299. ((or (equal arg '(4))
  6300. (memq last-command
  6301. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6302. (setq this-command 'org-agenda-date-later-hours)
  6303. (org-agenda-date-later-hours 1))
  6304. (t
  6305. (org-agenda-date-later (prefix-numeric-value arg)))))
  6306. (defun org-agenda-do-date-earlier (arg)
  6307. (interactive "P")
  6308. (cond
  6309. ((or (equal arg '(16))
  6310. (memq last-command
  6311. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6312. (setq this-command 'org-agenda-date-earlier-minutes)
  6313. (org-agenda-date-earlier-minutes 1))
  6314. ((or (equal arg '(4))
  6315. (memq last-command
  6316. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6317. (setq this-command 'org-agenda-date-earlier-hours)
  6318. (org-agenda-date-earlier-hours 1))
  6319. (t
  6320. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6321. (defun org-agenda-date-later (arg &optional what)
  6322. "Change the date of this item to one day later."
  6323. (interactive "p")
  6324. (org-agenda-check-type t 'agenda 'timeline)
  6325. (org-agenda-check-no-diary)
  6326. (let* ((marker (or (org-get-at-bol 'org-marker)
  6327. (org-agenda-error)))
  6328. (buffer (marker-buffer marker))
  6329. (pos (marker-position marker)))
  6330. (org-with-remote-undo buffer
  6331. (with-current-buffer buffer
  6332. (widen)
  6333. (goto-char pos)
  6334. (if (not (org-at-timestamp-p))
  6335. (error "Cannot find time stamp"))
  6336. (org-timestamp-change arg (or what 'day)))
  6337. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6338. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6339. (defun org-agenda-date-earlier (arg &optional what)
  6340. "Change the date of this item to one day earlier."
  6341. (interactive "p")
  6342. (org-agenda-date-later (- arg) what))
  6343. (defun org-agenda-date-later-minutes (arg)
  6344. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6345. (interactive "p")
  6346. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6347. (org-agenda-date-later arg 'minute))
  6348. (defun org-agenda-date-earlier-minutes (arg)
  6349. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6350. (interactive "p")
  6351. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6352. (org-agenda-date-earlier arg 'minute))
  6353. (defun org-agenda-date-later-hours (arg)
  6354. "Change the time of this item, in hour steps."
  6355. (interactive "p")
  6356. (org-agenda-date-later arg 'hour))
  6357. (defun org-agenda-date-earlier-hours (arg)
  6358. "Change the time of this item, in hour steps."
  6359. (interactive "p")
  6360. (org-agenda-date-earlier arg 'hour))
  6361. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6362. "Show new date stamp via text properties."
  6363. ;; We use text properties to make this undoable
  6364. (let ((inhibit-read-only t)
  6365. (buffer-invisibility-spec))
  6366. (setq stamp (concat " " prefix " => " stamp))
  6367. (save-excursion
  6368. (goto-char (point-max))
  6369. (while (not (bobp))
  6370. (when (equal marker (org-get-at-bol 'org-marker))
  6371. (org-move-to-column (- (window-width) (length stamp)) t)
  6372. (org-agenda-fix-tags-filter-overlays-at (point))
  6373. (if (featurep 'xemacs)
  6374. ;; Use `duplicable' property to trigger undo recording
  6375. (let ((ex (make-extent nil nil))
  6376. (gl (make-glyph stamp)))
  6377. (set-glyph-face gl 'secondary-selection)
  6378. (set-extent-properties
  6379. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6380. (insert-extent ex (1- (point)) (point-at-eol)))
  6381. (add-text-properties
  6382. (1- (point)) (point-at-eol)
  6383. (list 'display (org-add-props stamp nil
  6384. 'face 'secondary-selection))))
  6385. (beginning-of-line 1))
  6386. (beginning-of-line 0)))))
  6387. (defun org-agenda-date-prompt (arg)
  6388. "Change the date of this item. Date is prompted for, with default today.
  6389. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6390. be used to request time specification in the time stamp."
  6391. (interactive "P")
  6392. (org-agenda-check-type t 'agenda 'timeline)
  6393. (org-agenda-check-no-diary)
  6394. (let* ((marker (or (org-get-at-bol 'org-marker)
  6395. (org-agenda-error)))
  6396. (buffer (marker-buffer marker))
  6397. (pos (marker-position marker)))
  6398. (org-with-remote-undo buffer
  6399. (with-current-buffer buffer
  6400. (widen)
  6401. (goto-char pos)
  6402. (if (not (org-at-timestamp-p t))
  6403. (error "Cannot find time stamp"))
  6404. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6405. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6406. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6407. (defun org-agenda-schedule (arg)
  6408. "Schedule the item at point.
  6409. Arg is passed through to `org-schedule'."
  6410. (interactive "P")
  6411. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6412. (org-agenda-check-no-diary)
  6413. (let* ((marker (or (org-get-at-bol 'org-marker)
  6414. (org-agenda-error)))
  6415. (type (marker-insertion-type marker))
  6416. (buffer (marker-buffer marker))
  6417. (pos (marker-position marker))
  6418. (org-insert-labeled-timestamps-at-point nil)
  6419. ts)
  6420. (set-marker-insertion-type marker t)
  6421. (org-with-remote-undo buffer
  6422. (with-current-buffer buffer
  6423. (widen)
  6424. (goto-char pos)
  6425. (setq ts (org-schedule arg)))
  6426. (org-agenda-show-new-time marker ts "S"))
  6427. (message "Item scheduled for %s" ts)))
  6428. (defun org-agenda-deadline (arg)
  6429. "Schedule the item at point.
  6430. Arg is passed through to `org-deadline'."
  6431. (interactive "P")
  6432. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6433. (org-agenda-check-no-diary)
  6434. (let* ((marker (or (org-get-at-bol 'org-marker)
  6435. (org-agenda-error)))
  6436. (buffer (marker-buffer marker))
  6437. (pos (marker-position marker))
  6438. (org-insert-labeled-timestamps-at-point nil)
  6439. ts)
  6440. (org-with-remote-undo buffer
  6441. (with-current-buffer buffer
  6442. (widen)
  6443. (goto-char pos)
  6444. (setq ts (org-deadline arg)))
  6445. (org-agenda-show-new-time marker ts "D"))
  6446. (message "Deadline for this item set to %s" ts)))
  6447. (defun org-agenda-action ()
  6448. "Select entry for agenda action, or execute an agenda action.
  6449. This command prompts for another letter. Valid inputs are:
  6450. m Mark the entry at point for an agenda action
  6451. s Schedule the marked entry to the date at the cursor
  6452. d Set the deadline of the marked entry to the date at the cursor
  6453. r Call `org-remember' with cursor date as the default date
  6454. SPC Show marked entry in other window
  6455. TAB Visit marked entry in other window
  6456. The cursor may be at a date in the calendar, or in the Org agenda."
  6457. (interactive)
  6458. (let (ans)
  6459. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  6460. (setq ans (read-char-exclusive))
  6461. (cond
  6462. ((equal ans ?m)
  6463. ;; Mark this entry
  6464. (if (eq major-mode 'org-agenda-mode)
  6465. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6466. (org-get-at-bol 'org-marker))))
  6467. (if m
  6468. (progn
  6469. (move-marker org-agenda-action-marker
  6470. (marker-position m) (marker-buffer m))
  6471. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6472. (error "Don't know which entry to mark")))
  6473. (error "This command works only in the agenda")))
  6474. ((equal ans ?s)
  6475. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6476. ((equal ans ?d)
  6477. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6478. ((equal ans ?r)
  6479. (org-agenda-do-action '(org-remember) t))
  6480. ((equal ans ?\ )
  6481. (let ((cw (selected-window)))
  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. (select-window cw)))
  6487. ((equal ans ?\C-i)
  6488. (org-switch-to-buffer-other-window
  6489. (marker-buffer org-agenda-action-marker))
  6490. (goto-char org-agenda-action-marker)
  6491. (org-show-context 'agenda))
  6492. (t (error "Invalid agenda action %c" ans)))))
  6493. (defun org-agenda-do-action (form &optional current-buffer)
  6494. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6495. (let ((org-overriding-default-time (org-get-cursor-date)))
  6496. (if current-buffer
  6497. (eval form)
  6498. (if (not (marker-buffer org-agenda-action-marker))
  6499. (error "No entry has been selected for agenda action")
  6500. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6501. (save-excursion
  6502. (save-restriction
  6503. (widen)
  6504. (goto-char org-agenda-action-marker)
  6505. (eval form))))))))
  6506. (defun org-agenda-clock-in (&optional arg)
  6507. "Start the clock on the currently selected item."
  6508. (interactive "P")
  6509. (org-agenda-check-no-diary)
  6510. (if (equal arg '(4))
  6511. (org-clock-in arg)
  6512. (let* ((marker (or (org-get-at-bol 'org-marker)
  6513. (org-agenda-error)))
  6514. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6515. marker))
  6516. (pos (marker-position marker))
  6517. newhead)
  6518. (org-with-remote-undo (marker-buffer marker)
  6519. (with-current-buffer (marker-buffer marker)
  6520. (widen)
  6521. (goto-char pos)
  6522. (org-show-context 'agenda)
  6523. (org-show-entry)
  6524. (org-cycle-hide-drawers 'children)
  6525. (org-clock-in arg)
  6526. (setq newhead (org-get-heading)))
  6527. (org-agenda-change-all-lines newhead hdmarker)))))
  6528. (defun org-agenda-clock-out (&optional arg)
  6529. "Stop the currently running clock."
  6530. (interactive "P")
  6531. (unless (marker-buffer org-clock-marker)
  6532. (error "No running clock"))
  6533. (let ((marker (make-marker)) newhead)
  6534. (org-with-remote-undo (marker-buffer org-clock-marker)
  6535. (with-current-buffer (marker-buffer org-clock-marker)
  6536. (save-excursion
  6537. (save-restriction
  6538. (widen)
  6539. (goto-char org-clock-marker)
  6540. (org-back-to-heading t)
  6541. (move-marker marker (point))
  6542. (org-clock-out)
  6543. (setq newhead (org-get-heading))))))
  6544. (org-agenda-change-all-lines newhead marker)
  6545. (move-marker marker nil)))
  6546. (defun org-agenda-clock-cancel (&optional arg)
  6547. "Cancel the currently running clock."
  6548. (interactive "P")
  6549. (unless (marker-buffer org-clock-marker)
  6550. (error "No running clock"))
  6551. (org-with-remote-undo (marker-buffer org-clock-marker)
  6552. (org-clock-cancel)))
  6553. (defun org-agenda-diary-entry-in-org-file ()
  6554. "Make a diary entry in the file `org-agenda-diary-file'."
  6555. (let (d1 d2 char (text "") dp1 dp2)
  6556. (if (equal (buffer-name) "*Calendar*")
  6557. (setq d1 (calendar-cursor-to-date t)
  6558. d2 (car calendar-mark-ring))
  6559. (setq dp1 (get-text-property (point-at-bol) 'day))
  6560. (unless dp1 (error "No date defined in current line"))
  6561. (setq d1 (calendar-gregorian-from-absolute dp1)
  6562. d2 (and (ignore-errors (mark))
  6563. (save-excursion
  6564. (goto-char (mark))
  6565. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6566. (calendar-gregorian-from-absolute dp2))))
  6567. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6568. (setq char (read-char-exclusive))
  6569. (cond
  6570. ((equal char ?d)
  6571. (setq text (read-string "Day entry: "))
  6572. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6573. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6574. ((equal char ?a)
  6575. (setq d1 (list (car d1) (nth 1 d1)
  6576. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6577. (nth 2 d1))))
  6578. (setq text (read-string "Anniversary (use %d to show years): "))
  6579. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6580. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6581. ((equal char ?b)
  6582. (setq text (read-string "Block entry: "))
  6583. (unless (and d1 d2 (not (equal d1 d2)))
  6584. (error "No block of days selected"))
  6585. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6586. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6587. ((equal char ?j)
  6588. (org-switch-to-buffer-other-window
  6589. (find-file-noselect org-agenda-diary-file))
  6590. (require 'org-datetree)
  6591. (org-datetree-find-date-create d1)
  6592. (org-reveal t))
  6593. (t (error "Invalid selection character `%c'" char)))))
  6594. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6595. "Where in `org-agenda-diary-file' should new entries be added?
  6596. Valid values:
  6597. date-tree in the date tree, as child of the date
  6598. top-level as top-level entries at the end of the file."
  6599. :group 'org-agenda
  6600. :type '(choice
  6601. (const :tag "in a date tree" date-tree)
  6602. (const :tag "as top level at end of file" top-level)))
  6603. (defcustom org-agenda-insert-diary-extract-time nil
  6604. "Non-nil means extract any time specification from the diary entry."
  6605. :group 'org-agenda
  6606. :type 'boolean)
  6607. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6608. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6609. If TEXT is not empty, it will become the headline of the new entry, and
  6610. the resulting entry will not be shown. When TEXT is empty, switch to
  6611. `org-agenda-diary-file' and let the user finish the entry there."
  6612. (let ((cw (current-window-configuration)))
  6613. (org-switch-to-buffer-other-window
  6614. (find-file-noselect org-agenda-diary-file))
  6615. (widen)
  6616. (goto-char (point-min))
  6617. (cond
  6618. ((eq type 'anniversary)
  6619. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6620. (progn
  6621. (or (org-on-heading-p t)
  6622. (progn
  6623. (outline-next-heading)
  6624. (insert "* Anniversaries\n\n")
  6625. (beginning-of-line -1)))))
  6626. (outline-next-heading)
  6627. (org-back-over-empty-lines)
  6628. (backward-char 1)
  6629. (insert "\n")
  6630. (require 'diary-lib)
  6631. (let ((calendar-date-display-form
  6632. (if (if (boundp 'calendar-date-style)
  6633. (eq calendar-date-style 'european)
  6634. (org-bound-and-true-p european-calendar-style)) ; Emacs 22
  6635. '(day " " month " " year)
  6636. '(month " " day " " year))))
  6637. (insert (format "%%%%(diary-anniversary %s) %s"
  6638. (calendar-date-string d1 nil t) text))))
  6639. ((eq type 'day)
  6640. (let ((org-prefix-has-time t)
  6641. (org-agenda-time-leading-zero t)
  6642. fmt time time2)
  6643. (if org-agenda-insert-diary-extract-time
  6644. ;; Use org-format-agenda-item to parse text for a time-range and
  6645. ;; remove it. FIXME: This is a hack, we should refactor
  6646. ;; that function to make time extraction available separately
  6647. (setq fmt (org-format-agenda-item nil text nil nil t)
  6648. time (get-text-property 0 'time fmt)
  6649. time2 (if (> (length time) 0)
  6650. ;; split-string removes trailing ...... if
  6651. ;; no end time given. First space
  6652. ;; separates time from date.
  6653. (concat " " (car (split-string time "\\.")))
  6654. nil)
  6655. text (get-text-property 0 'txt fmt)))
  6656. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6657. (org-agenda-insert-diary-as-top-level text)
  6658. (require 'org-datetree)
  6659. (org-datetree-find-date-create d1)
  6660. (org-agenda-insert-diary-make-new-entry text))
  6661. (org-insert-time-stamp (org-time-from-absolute
  6662. (calendar-absolute-from-gregorian d1))
  6663. nil nil nil nil time2))
  6664. (end-of-line 0))
  6665. ((eq type 'block)
  6666. (if (> (calendar-absolute-from-gregorian d1)
  6667. (calendar-absolute-from-gregorian d2))
  6668. (setq d1 (prog1 d2 (setq d2 d1))))
  6669. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6670. (org-agenda-insert-diary-as-top-level text)
  6671. (require 'org-datetree)
  6672. (org-datetree-find-date-create d1)
  6673. (org-agenda-insert-diary-make-new-entry text))
  6674. (org-insert-time-stamp (org-time-from-absolute
  6675. (calendar-absolute-from-gregorian d1)))
  6676. (insert "--")
  6677. (org-insert-time-stamp (org-time-from-absolute
  6678. (calendar-absolute-from-gregorian d2)))
  6679. (end-of-line 0)))
  6680. (if (string-match "\\S-" text)
  6681. (progn
  6682. (set-window-configuration cw)
  6683. (message "%s entry added to %s"
  6684. (capitalize (symbol-name type))
  6685. (abbreviate-file-name org-agenda-diary-file)))
  6686. (org-reveal t)
  6687. (message "Please finish entry here"))))
  6688. (defun org-agenda-insert-diary-as-top-level (text)
  6689. "Make new entry as a top-level entry at the end of the file.
  6690. Add TEXT as headline, and position the cursor in the second line so that
  6691. a timestamp can be added there."
  6692. (widen)
  6693. (goto-char (point-max))
  6694. (or (bolp) (insert "\n"))
  6695. (insert "* " text "\n")
  6696. (if org-adapt-indentation (org-indent-to-column 2)))
  6697. (defun org-agenda-insert-diary-make-new-entry (text)
  6698. "Make new entry as last child of current entry.
  6699. Add TEXT as headline, and position the cursor in the second line so that
  6700. a timestamp can be added there."
  6701. (let ((org-show-following-heading t)
  6702. (org-show-siblings t)
  6703. (org-show-hierarchy-above t)
  6704. (org-show-entry-below t)
  6705. col)
  6706. (outline-next-heading)
  6707. (org-back-over-empty-lines)
  6708. (or (looking-at "[ \t]*$")
  6709. (progn (insert "\n") (backward-char 1)))
  6710. (org-insert-heading nil t)
  6711. (org-do-demote)
  6712. (setq col (current-column))
  6713. (insert text "\n")
  6714. (if org-adapt-indentation (org-indent-to-column col))
  6715. (let ((org-show-following-heading t)
  6716. (org-show-siblings t)
  6717. (org-show-hierarchy-above t)
  6718. (org-show-entry-below t))
  6719. (org-show-context))))
  6720. (defun org-agenda-diary-entry ()
  6721. "Make a diary entry, like the `i' command from the calendar.
  6722. All the standard commands work: block, weekly etc.
  6723. When `org-agenda-diary-file' points to a file,
  6724. `org-agenda-diary-entry-in-org-file' is called instead to create
  6725. entries in that Org-mode file."
  6726. (interactive)
  6727. (org-agenda-check-type t 'agenda 'timeline)
  6728. (if (not (eq org-agenda-diary-file 'diary-file))
  6729. (org-agenda-diary-entry-in-org-file)
  6730. (require 'diary-lib)
  6731. (let* ((char (progn
  6732. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6733. (read-char-exclusive)))
  6734. (cmd (cdr (assoc char
  6735. '((?d . insert-diary-entry)
  6736. (?w . insert-weekly-diary-entry)
  6737. (?m . insert-monthly-diary-entry)
  6738. (?y . insert-yearly-diary-entry)
  6739. (?a . insert-anniversary-diary-entry)
  6740. (?b . insert-block-diary-entry)
  6741. (?c . insert-cyclic-diary-entry)))))
  6742. (oldf (symbol-function 'calendar-cursor-to-date))
  6743. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6744. (point (point))
  6745. (mark (or (mark t) (point))))
  6746. (unless cmd
  6747. (error "No command associated with <%c>" char))
  6748. (unless (and (get-text-property point 'day)
  6749. (or (not (equal ?b char))
  6750. (get-text-property mark 'day)))
  6751. (error "Don't know which date to use for diary entry"))
  6752. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6753. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6754. (let ((calendar-mark-ring
  6755. (list (calendar-gregorian-from-absolute
  6756. (or (get-text-property mark 'day)
  6757. (get-text-property point 'day))))))
  6758. (unwind-protect
  6759. (progn
  6760. (fset 'calendar-cursor-to-date
  6761. (lambda (&optional error dummy)
  6762. (calendar-gregorian-from-absolute
  6763. (get-text-property point 'day))))
  6764. (call-interactively cmd))
  6765. (fset 'calendar-cursor-to-date oldf))))))
  6766. (defun org-agenda-execute-calendar-command (cmd)
  6767. "Execute a calendar command from the agenda, with the date associated to
  6768. the cursor position."
  6769. (org-agenda-check-type t 'agenda 'timeline)
  6770. (require 'diary-lib)
  6771. (unless (get-text-property (point) 'day)
  6772. (error "Don't know which date to use for calendar command"))
  6773. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6774. (point (point))
  6775. (date (calendar-gregorian-from-absolute
  6776. (get-text-property point 'day)))
  6777. ;; the following 2 vars are needed in the calendar
  6778. (displayed-month (car date))
  6779. (displayed-year (nth 2 date)))
  6780. (unwind-protect
  6781. (progn
  6782. (fset 'calendar-cursor-to-date
  6783. (lambda (&optional error dummy)
  6784. (calendar-gregorian-from-absolute
  6785. (get-text-property point 'day))))
  6786. (call-interactively cmd))
  6787. (fset 'calendar-cursor-to-date oldf))))
  6788. (defun org-agenda-phases-of-moon ()
  6789. "Display the phases of the moon for the 3 months around the cursor date."
  6790. (interactive)
  6791. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6792. (defun org-agenda-holidays ()
  6793. "Display the holidays for the 3 months around the cursor date."
  6794. (interactive)
  6795. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6796. (defvar calendar-longitude)
  6797. (defvar calendar-latitude)
  6798. (defvar calendar-location-name)
  6799. (defun org-agenda-sunrise-sunset (arg)
  6800. "Display sunrise and sunset for the cursor date.
  6801. Latitude and longitude can be specified with the variables
  6802. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6803. argument, latitude and longitude will be prompted for."
  6804. (interactive "P")
  6805. (require 'solar)
  6806. (let ((calendar-longitude (if arg nil calendar-longitude))
  6807. (calendar-latitude (if arg nil calendar-latitude))
  6808. (calendar-location-name
  6809. (if arg "the given coordinates" calendar-location-name)))
  6810. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6811. (defun org-agenda-goto-calendar ()
  6812. "Open the Emacs calendar with the date at the cursor."
  6813. (interactive)
  6814. (org-agenda-check-type t 'agenda 'timeline)
  6815. (let* ((day (or (get-text-property (point) 'day)
  6816. (error "Don't know which date to open in calendar")))
  6817. (date (calendar-gregorian-from-absolute day))
  6818. (calendar-move-hook nil)
  6819. (calendar-view-holidays-initially-flag nil)
  6820. (calendar-view-diary-initially-flag nil)
  6821. (view-calendar-holidays-initially nil)
  6822. (view-diary-entries-initially nil))
  6823. (calendar)
  6824. (calendar-goto-date date)))
  6825. ;;;###autoload
  6826. (defun org-calendar-goto-agenda ()
  6827. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6828. This is a command that has to be installed in `calendar-mode-map'."
  6829. (interactive)
  6830. (org-agenda-list nil (calendar-absolute-from-gregorian
  6831. (calendar-cursor-to-date))
  6832. nil))
  6833. (defun org-agenda-convert-date ()
  6834. (interactive)
  6835. (org-agenda-check-type t 'agenda 'timeline)
  6836. (let ((day (get-text-property (point) 'day))
  6837. date s)
  6838. (unless day
  6839. (error "Don't know which date to convert"))
  6840. (setq date (calendar-gregorian-from-absolute day))
  6841. (setq s (concat
  6842. "Gregorian: " (calendar-date-string date) "\n"
  6843. "ISO: " (calendar-iso-date-string date) "\n"
  6844. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6845. "Julian: " (calendar-julian-date-string date) "\n"
  6846. "Astron. JD: " (calendar-astro-date-string date)
  6847. " (Julian date number at noon UTC)\n"
  6848. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6849. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6850. "French: " (calendar-french-date-string date) "\n"
  6851. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6852. "Mayan: " (calendar-mayan-date-string date) "\n"
  6853. "Coptic: " (calendar-coptic-date-string date) "\n"
  6854. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6855. "Persian: " (calendar-persian-date-string date) "\n"
  6856. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6857. (with-output-to-temp-buffer "*Dates*"
  6858. (princ s))
  6859. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6860. ;;; Bulk commands
  6861. (defvar org-agenda-bulk-marked-entries nil
  6862. "List of markers that refer to marked entries in the agenda.")
  6863. (defun org-agenda-bulk-marked-p ()
  6864. (eq (get-char-property (point-at-bol) 'type)
  6865. 'org-marked-entry-overlay))
  6866. (defun org-agenda-bulk-mark ()
  6867. "Mark the entry at point for future bulk action."
  6868. (interactive)
  6869. (org-agenda-check-no-diary)
  6870. (let* ((m (org-get-at-bol 'org-hd-marker))
  6871. ov)
  6872. (unless (org-agenda-bulk-marked-p)
  6873. (unless m (error "Nothing to mark at point"))
  6874. (push m org-agenda-bulk-marked-entries)
  6875. (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  6876. (org-overlay-display ov "> "
  6877. (org-get-todo-face "TODO")
  6878. 'evaporate)
  6879. (org-overlay-put ov 'type 'org-marked-entry-overlay))
  6880. (beginning-of-line 2)
  6881. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6882. (beginning-of-line 2))
  6883. (message "%d entries marked for bulk action"
  6884. (length org-agenda-bulk-marked-entries))))
  6885. (defun org-agenda-bulk-unmark ()
  6886. "Unmark the entry at point for future bulk action."
  6887. (interactive)
  6888. (when (org-agenda-bulk-marked-p)
  6889. (org-agenda-bulk-remove-overlays
  6890. (point-at-bol) (+ 2 (point-at-bol)))
  6891. (setq org-agenda-bulk-marked-entries
  6892. (delete (org-get-at-bol 'org-hd-marker)
  6893. org-agenda-bulk-marked-entries)))
  6894. (beginning-of-line 2)
  6895. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6896. (beginning-of-line 2))
  6897. (message "%d entries marked for bulk action"
  6898. (length org-agenda-bulk-marked-entries)))
  6899. (defun org-agenda-bulk-toggle ()
  6900. "Toggle marking the entry at point for bulk action."
  6901. (interactive)
  6902. (if (org-agenda-bulk-marked-p)
  6903. (org-agenda-bulk-unmark)
  6904. (org-agenda-bulk-mark)))
  6905. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  6906. "Remove the mark overlays between BEG and END in the agenda buffer.
  6907. BEG and END default to the buffer limits.
  6908. This only removes the overlays, it does not remove the markers
  6909. from the list in `org-agenda-bulk-marked-entries'."
  6910. (interactive)
  6911. (mapc (lambda (ov)
  6912. (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
  6913. (org-delete-overlay ov)))
  6914. (org-overlays-in (or beg (point-min)) (or end (point-max)))))
  6915. (defun org-agenda-bulk-remove-all-marks ()
  6916. "Remove all marks in the agenda buffer.
  6917. This will remove the markers, and the overlays."
  6918. (interactive)
  6919. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  6920. (setq org-agenda-bulk-marked-entries nil)
  6921. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  6922. (defun org-agenda-bulk-action (&optional arg)
  6923. "Execute an remote-editing action on all marked entries.
  6924. The prefix arg is passed through to the command if possible."
  6925. (interactive "P")
  6926. (unless org-agenda-bulk-marked-entries
  6927. (error "No entries are marked"))
  6928. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  6929. (let* ((action (read-char-exclusive))
  6930. (org-log-refile (if org-log-refile 'time nil))
  6931. (entries (reverse org-agenda-bulk-marked-entries))
  6932. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  6933. (cond
  6934. ((equal action ?$)
  6935. (setq cmd '(org-agenda-archive)))
  6936. ((equal action ?A)
  6937. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  6938. ((member action '(?r ?w))
  6939. (setq rfloc (org-refile-get-location
  6940. "Refile to: "
  6941. (marker-buffer (car org-agenda-bulk-marked-entries))
  6942. org-refile-allow-creating-parent-nodes))
  6943. (setcar (nthcdr 3 rfloc)
  6944. (move-marker (make-marker) (nth 3 rfloc)
  6945. (or (get-file-buffer (nth 1 rfloc))
  6946. (find-buffer-visiting (nth 1 rfloc))
  6947. (error "This should not happen"))))
  6948. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
  6949. ((equal action ?t)
  6950. (setq state (org-icompleting-read
  6951. "Todo state: "
  6952. (with-current-buffer (marker-buffer (car entries))
  6953. (mapcar 'list org-todo-keywords-1))))
  6954. (setq cmd `(let ((org-inhibit-blocking t)
  6955. (org-inhibit-logging 'note))
  6956. (org-agenda-todo ,state))))
  6957. ((memq action '(?- ?+))
  6958. (setq tag (org-icompleting-read
  6959. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  6960. (with-current-buffer (marker-buffer (car entries))
  6961. (delq nil
  6962. (mapcar (lambda (x)
  6963. (if (stringp (car x)) x)) org-tag-alist)))))
  6964. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  6965. ((memq action '(?s ?d))
  6966. (let* ((date (unless arg
  6967. (org-read-date
  6968. nil nil nil
  6969. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  6970. (ans (if arg nil org-read-date-final-answer))
  6971. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  6972. (setq cmd `(let* ((bound (fboundp 'read-string))
  6973. (old (and bound (symbol-function 'read-string))))
  6974. (unwind-protect
  6975. (progn
  6976. (fset 'read-string (lambda (&rest ignore) ,ans))
  6977. (eval '(,c1 arg)))
  6978. (if bound
  6979. (fset 'read-string old)
  6980. (fmakunbound 'read-string)))))))
  6981. (t (error "Invalid bulk action")))
  6982. ;; Sort the markers, to make sure that parents are handled before children
  6983. (setq entries (sort entries
  6984. (lambda (a b)
  6985. (cond
  6986. ((equal (marker-buffer a) (marker-buffer b))
  6987. (< (marker-position a) (marker-position b)))
  6988. (t
  6989. (string< (buffer-name (marker-buffer a))
  6990. (buffer-name (marker-buffer b))))))))
  6991. ;; Now loop over all markers and apply cmd
  6992. (while (setq e (pop entries))
  6993. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  6994. (if (not pos)
  6995. (progn (message "Skipping removed entry at %s" e)
  6996. (setq cntskip (1+ cntskip)))
  6997. (goto-char pos)
  6998. (eval cmd)
  6999. (setq org-agenda-bulk-marked-entries
  7000. (delete e org-agenda-bulk-marked-entries))
  7001. (setq cnt (1+ cnt))))
  7002. (setq org-agenda-bulk-marked-entries nil)
  7003. (org-agenda-bulk-remove-all-marks)
  7004. (message "Acted on %d entries%s"
  7005. cnt
  7006. (if (= cntskip 0)
  7007. ""
  7008. (format ", skipped %d (disappeared before their turn)"
  7009. cntskip)))))
  7010. ;;; Flagging notes
  7011. (defun org-agenda-show-the-flagging-note ()
  7012. "Display the flagging note in the other window.
  7013. When called a second time in direct sequence, offer to remove the FLAGGING
  7014. tag and (if present) the flagging note."
  7015. (interactive)
  7016. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7017. (win (selected-window))
  7018. note heading newhead)
  7019. (unless hdmarker
  7020. (error "No linked entry at point"))
  7021. (if (and (eq this-command last-command)
  7022. (y-or-n-p "Unflag and remove any flagging note? "))
  7023. (progn
  7024. (org-agenda-remove-flag hdmarker)
  7025. (let ((win (get-buffer-window "*Flagging Note*")))
  7026. (and win (delete-window win)))
  7027. (message "Entry unflaged"))
  7028. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7029. (unless note
  7030. (error "No flagging note"))
  7031. (org-kill-new note)
  7032. (org-switch-to-buffer-other-window "*Flagging Note*")
  7033. (erase-buffer)
  7034. (insert note)
  7035. (goto-char (point-min))
  7036. (while (re-search-forward "\\\\n" nil t)
  7037. (replace-match "\n" t t))
  7038. (goto-char (point-min))
  7039. (select-window win)
  7040. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7041. (defun org-agenda-remove-flag (marker)
  7042. "Remove the FLAGGED tag and any flagging note in the entry."
  7043. (let (newhead)
  7044. (org-with-point-at marker
  7045. (org-toggle-tag "FLAGGED" 'off)
  7046. (org-entry-delete nil "THEFLAGGINGNOTE")
  7047. (setq newhead (org-get-heading)))
  7048. (org-agenda-change-all-lines newhead marker)
  7049. (message "Entry unflaged")))
  7050. (defun org-agenda-get-any-marker (&optional pos)
  7051. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7052. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7053. ;;; Appointment reminders
  7054. (defvar appt-time-msg-list)
  7055. ;;;###autoload
  7056. (defun org-agenda-to-appt (&optional refresh filter)
  7057. "Activate appointments found in `org-agenda-files'.
  7058. With a \\[universal-argument] prefix, refresh the list of
  7059. appointments.
  7060. If FILTER is t, interactively prompt the user for a regular
  7061. expression, and filter out entries that don't match it.
  7062. If FILTER is a string, use this string as a regular expression
  7063. for filtering entries out.
  7064. FILTER can also be an alist with the car of each cell being
  7065. either 'headline or 'category. For example:
  7066. '((headline \"IMPORTANT\")
  7067. (category \"Work\"))
  7068. will only add headlines containing IMPORTANT or headlines
  7069. belonging to the \"Work\" category."
  7070. (interactive "P")
  7071. (require 'calendar)
  7072. (if refresh (setq appt-time-msg-list nil))
  7073. (if (eq filter t)
  7074. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7075. (let* ((cnt 0) ; count added events
  7076. (org-agenda-new-buffers nil)
  7077. (org-deadline-warning-days 0)
  7078. (today (org-date-to-gregorian
  7079. (time-to-days (current-time))))
  7080. (org-agenda-restrict nil)
  7081. (files (org-agenda-files 'unrestricted)) entries file)
  7082. ;; Get all entries which may contain an appt
  7083. (org-prepare-agenda-buffers files)
  7084. (while (setq file (pop files))
  7085. (setq entries
  7086. (append entries
  7087. (org-agenda-get-day-entries
  7088. file today :timestamp :scheduled :deadline))))
  7089. (setq entries (delq nil entries))
  7090. ;; Map thru entries and find if we should filter them out
  7091. (mapc
  7092. (lambda(x)
  7093. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7094. (cat (get-text-property 1 'org-category x))
  7095. (tod (get-text-property 1 'time-of-day x))
  7096. (ok (or (null filter)
  7097. (and (stringp filter) (string-match filter evt))
  7098. (and (listp filter)
  7099. (or (string-match
  7100. (cadr (assoc 'category filter)) cat)
  7101. (string-match
  7102. (cadr (assoc 'headline filter)) evt))))))
  7103. ;; FIXME: Shall we remove text-properties for the appt text?
  7104. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7105. (when (and ok tod)
  7106. (setq tod (concat "00" (number-to-string tod))
  7107. tod (when (string-match
  7108. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7109. (concat (match-string 1 tod) ":"
  7110. (match-string 2 tod))))
  7111. (appt-add tod evt)
  7112. (setq cnt (1+ cnt))))) entries)
  7113. (org-release-buffers org-agenda-new-buffers)
  7114. (if (eq cnt 0)
  7115. (message "No event to add")
  7116. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7117. (defun org-agenda-todayp (date)
  7118. "Does DATE mean today, when considering `org-extend-today-until'?"
  7119. (let (today h)
  7120. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7121. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7122. (setq h (nth 2 (decode-time (current-time))))
  7123. (or (and (>= h org-extend-today-until)
  7124. (= date today))
  7125. (and (< h org-extend-today-until)
  7126. (= date (1- today))))))
  7127. (provide 'org-agenda)
  7128. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7129. ;;; org-agenda.el ends here