org-agenda.el 314 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.5
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-span)
  217. (choice (const :tag "Day" 'day)
  218. (const :tag "Week" 'week)
  219. (const :tag "Month" 'month)
  220. (const :tag "Year" 'year)
  221. (integer :tag "Custom")))
  222. (list :tag "Fixed starting date"
  223. (const org-agenda-start-day)
  224. (string :value "2007-11-01"))
  225. (list :tag "Start on day of week"
  226. (const org-agenda-start-on-weekday)
  227. (choice :value 1
  228. (const :tag "Today" nil)
  229. (integer :tag "Weekday No.")))
  230. (list :tag "Include data from diary"
  231. (const org-agenda-include-diary)
  232. (boolean))
  233. (list :tag "Deadline Warning days"
  234. (const org-deadline-warning-days)
  235. (integer :value 1))
  236. (list :tag "Tags filter preset"
  237. (const org-agenda-filter-preset)
  238. (list
  239. (const :format "" quote)
  240. (repeat
  241. (string :tag "+tag or -tag"))))
  242. (list :tag "Set daily/weekly entry types"
  243. (const org-agenda-entry-types)
  244. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  245. (const :deadline)
  246. (const :scheduled)
  247. (const :timestamp)
  248. (const :sexp)))
  249. (list :tag "Standard skipping condition"
  250. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  251. (const org-agenda-skip-function)
  252. (list
  253. (const :format "" quote)
  254. (list
  255. (choice
  256. :tag "Skipping range"
  257. (const :tag "Skip entry" org-agenda-skip-entry-if)
  258. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  259. (repeat :inline t :tag "Conditions for skipping"
  260. (choice
  261. :tag "Condition type"
  262. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  263. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  264. (list :tag "TODO state is" :inline t
  265. (const 'todo)
  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. (list :tag "TODO state is not" :inline t
  274. (const 'nottodo)
  275. (choice
  276. (const :tag "any not-done state" 'todo)
  277. (const :tag "any done state" 'done)
  278. (const :tag "any state" 'any)
  279. (list :tag "Keyword list"
  280. (const :format "" quote)
  281. (repeat (string :tag "Keyword")))))
  282. (const :tag "scheduled" 'scheduled)
  283. (const :tag "not scheduled" 'notscheduled)
  284. (const :tag "deadline" 'deadline)
  285. (const :tag "no deadline" 'notdeadline)
  286. (const :tag "timestamp" 'timestamp)
  287. (const :tag "no timestamp" 'nottimestamp))))))
  288. (list :tag "Non-standard skipping condition"
  289. :value (org-agenda-skip-function)
  290. (const org-agenda-skip-function)
  291. (sexp :tag "Function or form (quoted!)"))
  292. (list :tag "Any variable"
  293. (variable :tag "Variable")
  294. (sexp :tag "Value (sexp)"))))
  295. "Selection of examples for agenda command settings.
  296. This will be spliced into the custom type of
  297. `org-agenda-custom-commands'.")
  298. (defcustom org-agenda-custom-commands nil
  299. "Custom commands for the agenda.
  300. These commands will be offered on the splash screen displayed by the
  301. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  302. (key desc type match settings files)
  303. key The key (one or more characters as a string) to be associated
  304. with the command.
  305. desc A description of the command, when omitted or nil, a default
  306. description is built using MATCH.
  307. type The command type, any of the following symbols:
  308. agenda The daily/weekly agenda.
  309. todo Entries with a specific TODO keyword, in all agenda files.
  310. search Entries containing search words entry or headline.
  311. tags Tags/Property/TODO match in all agenda files.
  312. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  313. todo-tree Sparse tree of specific TODO keyword in *current* file.
  314. tags-tree Sparse tree with all tags matches in *current* file.
  315. occur-tree Occur sparse tree for *current* file.
  316. ... A user-defined function.
  317. match What to search for:
  318. - a single keyword for TODO keyword searches
  319. - a tags match expression for tags searches
  320. - a word search expression for text searches.
  321. - a regular expression for occur searches
  322. For all other commands, this should be the empty string.
  323. settings A list of option settings, similar to that in a let form, so like
  324. this: ((opt1 val1) (opt2 val2) ...). The values will be
  325. evaluated at the moment of execution, so quote them when needed.
  326. files A list of files file to write the produced agenda buffer to
  327. with the command `org-store-agenda-views'.
  328. If a file name ends in \".html\", an HTML version of the buffer
  329. is written out. If it ends in \".ps\", a postscript version is
  330. produced. Otherwise, only the plain text is written to the file.
  331. You can also define a set of commands, to create a composite agenda buffer.
  332. In this case, an entry looks like this:
  333. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  334. where
  335. desc A description string to be displayed in the dispatcher menu.
  336. cmd An agenda command, similar to the above. However, tree commands
  337. are no allowed, but instead you can get agenda and global todo list.
  338. So valid commands for a set are:
  339. (agenda \"\" settings)
  340. (alltodo \"\" settings)
  341. (stuck \"\" settings)
  342. (todo \"match\" settings files)
  343. (search \"match\" settings files)
  344. (tags \"match\" settings files)
  345. (tags-todo \"match\" settings files)
  346. Each command can carry a list of options, and another set of options can be
  347. given for the whole set of commands. Individual command options take
  348. precedence over the general options.
  349. When using several characters as key to a command, the first characters
  350. are prefix commands. For the dispatcher to display useful information, you
  351. should provide a description for the prefix, like
  352. (setq org-agenda-custom-commands
  353. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  354. (\"hl\" tags \"+HOME+Lisa\")
  355. (\"hp\" tags \"+HOME+Peter\")
  356. (\"hk\" tags \"+HOME+Kim\")))"
  357. :group 'org-agenda-custom-commands
  358. :type `(repeat
  359. (choice :value ("x" "Describe command here" tags "" nil)
  360. (list :tag "Single command"
  361. (string :tag "Access Key(s) ")
  362. (option (string :tag "Description"))
  363. (choice
  364. (const :tag "Agenda" agenda)
  365. (const :tag "TODO list" alltodo)
  366. (const :tag "Search words" search)
  367. (const :tag "Stuck projects" stuck)
  368. (const :tag "Tags/Property match (all agenda files)" tags)
  369. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  370. (const :tag "TODO keyword search (all agenda files)" todo)
  371. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  372. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  373. (const :tag "Occur tree (current buffer)" occur-tree)
  374. (sexp :tag "Other, user-defined function"))
  375. (string :tag "Match (only for some commands)")
  376. ,org-agenda-custom-commands-local-options
  377. (option (repeat :tag "Export" (file :tag "Export to"))))
  378. (list :tag "Command series, all agenda files"
  379. (string :tag "Access Key(s)")
  380. (string :tag "Description ")
  381. (repeat :tag "Component"
  382. (choice
  383. (list :tag "Agenda"
  384. (const :format "" agenda)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "TODO list (all keywords)"
  388. (const :format "" alltodo)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Search words"
  392. (const :format "" search)
  393. (string :tag "Match")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Stuck projects"
  396. (const :format "" stuck)
  397. (const :tag "" :format "" "")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search"
  400. (const :format "" tags)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search, TODO entries only"
  404. (const :format "" tags-todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "TODO keyword search"
  408. (const :format "" todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "Other, user-defined function"
  412. (symbol :tag "function")
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)))
  415. (repeat :tag "Settings for entire command set"
  416. (list (variable :tag "Any variable")
  417. (sexp :tag "Value")))
  418. (option (repeat :tag "Export" (file :tag "Export to"))))
  419. (cons :tag "Prefix key documentation"
  420. (string :tag "Access Key(s)")
  421. (string :tag "Description ")))))
  422. (defcustom org-agenda-query-register ?o
  423. "The register holding the current query string.
  424. The purpose of this is that if you construct a query string interactively,
  425. you can then use it to define a custom command."
  426. :group 'org-agenda-custom-commands
  427. :type 'character)
  428. (defcustom org-stuck-projects
  429. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  430. "How to identify stuck projects.
  431. This is a list of four items:
  432. 1. A tags/todo/property matcher string that is used to identify a project.
  433. See the manual for a description of tag and property searches.
  434. The entire tree below a headline matched by this is considered one project.
  435. 2. A list of TODO keywords identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these todo
  437. keywords, the project is considered to be not stuck. If you specify
  438. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  439. 3. A list of tags identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these tags,
  441. the project is considered to be not stuck. If you specify \"*\" as
  442. a tag, any tag will mark the project unstuck. Note that this is about
  443. the explicit presence of a tag somewhere in the subtree, inherited
  444. tags to not count here. If inherited tags make a project not stuck,
  445. use \"-TAG\" in the tags part of the matcher under (1.) above.
  446. 4. An arbitrary regular expression matching non-stuck projects.
  447. If the project turns out to be not stuck, search continues also in the
  448. subtree to see if any of the subtasks have project status.
  449. See also the variable `org-tags-match-list-sublevels' which applies
  450. to projects matched by this search as well.
  451. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  452. or `C-c a #' to produce the list."
  453. :group 'org-agenda-custom-commands
  454. :type '(list
  455. (string :tag "Tags/TODO match to identify a project")
  456. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  457. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  458. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  459. (defcustom org-agenda-filter-effort-default-operator "<"
  460. "The default operator for effort estimate filtering.
  461. If you select an effort estimate limit without first pressing an operator,
  462. this one will be used."
  463. :group 'org-agenda-custom-commands
  464. :type '(choice (const :tag "less or equal" "<")
  465. (const :tag "greater or equal"">")
  466. (const :tag "equal" "=")))
  467. (defgroup org-agenda-skip nil
  468. "Options concerning skipping parts of agenda files."
  469. :tag "Org Agenda Skip"
  470. :group 'org-agenda)
  471. (defcustom org-agenda-skip-function-global nil
  472. "Function to be called at each match during agenda construction.
  473. If this function returns nil, the current match should not be skipped.
  474. If the function decided to skip an agenda match, is must return the
  475. buffer position from which the search should be continued.
  476. This may also be a Lisp form, which will be evaluated.
  477. This variable will be applied to every agenda match, including
  478. tags/property searches and TODO lists. So try to make the test function
  479. do its checking as efficiently as possible. To implement a skipping
  480. condition just for specific agenda commands, use the variable
  481. `org-agenda-skip-function' which can be set in the options section
  482. of custom agenda commands."
  483. :group 'org-agenda-skip
  484. :type 'sexp)
  485. (defgroup org-agenda-daily/weekly nil
  486. "Options concerning the daily/weekly agenda."
  487. :tag "Org Agenda Daily/Weekly"
  488. :group 'org-agenda)
  489. (defgroup org-agenda-todo-list nil
  490. "Options concerning the global todo list agenda view."
  491. :tag "Org Agenda Todo List"
  492. :group 'org-agenda)
  493. (defgroup org-agenda-match-view nil
  494. "Options concerning the general tags/property/todo match agenda view."
  495. :tag "Org Agenda Match View"
  496. :group 'org-agenda)
  497. (defgroup org-agenda-search-view nil
  498. "Options concerning the general tags/property/todo match agenda view."
  499. :tag "Org Agenda Match View"
  500. :group 'org-agenda)
  501. (defvar org-agenda-archives-mode nil
  502. "Non-nil means the agenda will include archived items.
  503. If this is the symbol `trees', trees in the selected agenda scope
  504. that are marked with the ARCHIVE tag will be included anyway. When this is
  505. t, also all archive files associated with the current selection of agenda
  506. files will be included.")
  507. (defcustom org-agenda-skip-comment-trees t
  508. "Non-nil means skip trees that start with the COMMENT keyword.
  509. When nil, these trees are also scanned by agenda commands."
  510. :group 'org-agenda-skip
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-list-sublevels t
  513. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  514. When nil, the sublevels of a TODO entry are not checked, resulting in
  515. potentially much shorter TODO lists."
  516. :group 'org-agenda-skip
  517. :group 'org-agenda-todo-list
  518. :type 'boolean)
  519. (defcustom org-agenda-todo-ignore-with-date nil
  520. "Non-nil means don't show entries with a date in the global todo list.
  521. You can use this if you prefer to mark mere appointments with a TODO keyword,
  522. but don't want them to show up in the TODO list.
  523. When this is set, it also covers deadlines and scheduled items, the settings
  524. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  525. will be ignored.
  526. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type 'boolean)
  530. (defcustom org-agenda-todo-ignore-timestamp nil
  531. "Non-nil means don't show entries with a timestamp.
  532. This applies when creating the global todo list.
  533. Valid values are:
  534. past Don't show entries for today or in the past.
  535. future Don't show entries with a timestamp in the future.
  536. The idea behind this is that if it has a future
  537. timestamp, you don't want to think about it until the
  538. date.
  539. all Don't show any entries with a timestamp in the global todo list.
  540. The idea behind this is that by setting a timestamp, you
  541. have already \"taken care\" of this item.
  542. This variable can also have an integer as a value. If positive (N),
  543. todos with a timestamp N or more days in the future will be ignored. If
  544. negative (-N), todos with a timestamp N or more days in the past will be
  545. ignored. If 0, todos with a timestamp either today or in the future will
  546. be ignored. For example, a value of -1 will exclude todos with a
  547. timestamp in the past (yesterday or earlier), while a value of 7 will
  548. exclude todos with a timestamp a week or more in the future.
  549. See also `org-agenda-todo-ignore-with-date'.
  550. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  551. to make his option also apply to the tags-todo list."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type '(choice
  555. (const :tag "Ignore future timestamp todos" future)
  556. (const :tag "Ignore past or present timestamp todos" past)
  557. (const :tag "Ignore all timestamp todos" all)
  558. (const :tag "Show timestamp todos" nil)
  559. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  560. (defcustom org-agenda-todo-ignore-scheduled nil
  561. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  562. This applies when creating the global todo list.
  563. Valid values are:
  564. past Don't show entries scheduled today or in the past.
  565. future Don't show entries scheduled in the future.
  566. The idea behind this is that by scheduling it, you don't want to
  567. think about it until the scheduled date.
  568. all Don't show any scheduled entries in the global todo list.
  569. The idea behind this is that by scheduling it, you have already
  570. \"taken care\" of this item.
  571. t Same as `all', for backward compatibility.
  572. This variable can also have an integer as a value. See
  573. `org-agenda-todo-ignore-timestamp' for more details.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore future-scheduled todos" future)
  581. (const :tag "Ignore past- or present-scheduled todos" past)
  582. (const :tag "Ignore all scheduled todos" all)
  583. (const :tag "Ignore all scheduled todos (compatibility)" t)
  584. (const :tag "Show scheduled todos" nil)
  585. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  586. (defcustom org-agenda-todo-ignore-deadlines nil
  587. "Non-nil means ignore some deadlined TODO items when making TODO list.
  588. There are different motivations for using different values, please think
  589. carefully when configuring this variable.
  590. This applies when creating the global todo list.
  591. Valid values are:
  592. near Don't show near deadline entries. A deadline is near when it is
  593. closer than `org-deadline-warning-days' days. The idea behind this
  594. is that such items will appear in the agenda anyway.
  595. far Don't show TODO entries where a deadline has been defined, but
  596. the deadline is not near. This is useful if you don't want to
  597. use the todo list to figure out what to do now.
  598. past Don't show entries with a deadline timestamp for today or in the past.
  599. future Don't show entries with a deadline timestamp in the future, not even
  600. when they become `near' ones. Use it with caution.
  601. all Ignore all TODO entries that do have a deadline.
  602. t Same as `near', for backward compatibility.
  603. This variable can also have an integer as a value. See
  604. `org-agenda-todo-ignore-timestamp' for more details.
  605. See also `org-agenda-todo-ignore-with-date'.
  606. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  607. to make his option also apply to the tags-todo list."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-todo-list
  610. :type '(choice
  611. (const :tag "Ignore near deadlines" near)
  612. (const :tag "Ignore near deadlines (compatibility)" t)
  613. (const :tag "Ignore far deadlines" far)
  614. (const :tag "Ignore all TODOs with a deadlines" all)
  615. (const :tag "Show all TODOs, even if they have a deadline" nil)
  616. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  617. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  618. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  619. The variables
  620. `org-agenda-todo-ignore-with-date',
  621. `org-agenda-todo-ignore-timestamp',
  622. `org-agenda-todo-ignore-scheduled',
  623. `org-agenda-todo-ignore-deadlines'
  624. make the global TODO list skip entries that have time stamps of certain
  625. kinds. If this option is set, the same options will also apply for the
  626. tags-todo search, which is the general tags/property matcher
  627. restricted to unfinished TODO entries only."
  628. :group 'org-agenda-skip
  629. :group 'org-agenda-todo-list
  630. :group 'org-agenda-match-view
  631. :type 'boolean)
  632. (defcustom org-agenda-skip-scheduled-if-done nil
  633. "Non-nil means don't show scheduled items in agenda when they are done.
  634. This is relevant for the daily/weekly agenda, not for the TODO list. And
  635. it applies only to the actual date of the scheduling. Warnings about
  636. an item with a past scheduling dates are always turned off when the item
  637. is DONE."
  638. :group 'org-agenda-skip
  639. :group 'org-agenda-daily/weekly
  640. :type 'boolean)
  641. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  642. "Non-nil means skip scheduling line if same entry shows because of deadline.
  643. In the agenda of today, an entry can show up multiple times because
  644. it is both scheduled and has a nearby deadline, and maybe a plain time
  645. stamp as well.
  646. When this variable is t, then only the deadline is shown and the fact that
  647. the entry is scheduled today or was scheduled previously is not shown.
  648. When this variable is nil, the entry will be shown several times. When
  649. the variable is the symbol `not-today', then skip scheduled previously,
  650. but not scheduled today."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-daily/weekly
  653. :type '(choice
  654. (const :tag "Never" nil)
  655. (const :tag "Always" t)
  656. (const :tag "Not when scheduled today" not-today)))
  657. (defcustom org-agenda-skip-deadline-if-done nil
  658. "Non-nil means don't show deadlines when the corresponding item is done.
  659. When nil, the deadline is still shown and should give you a happy feeling.
  660. This is relevant for the daily/weekly agenda. And it applied only to the
  661. actually date of the deadline. Warnings about approaching and past-due
  662. deadlines are always turned off when the item is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  667. "Non-nil means skip deadline prewarning when entry is also scheduled.
  668. This will apply on all days where a prewarning for the deadline would
  669. be shown, but not at the day when the entry is actually due. On that day,
  670. the deadline will be shown anyway.
  671. This variable may be set to nil, t, or a number which will then give
  672. the number of days before the actual deadline when the prewarnings
  673. should resume.
  674. This can be used in a workflow where the first showing of the deadline will
  675. trigger you to schedule it, and then you don't want to be reminded of it
  676. because you will take care of it on the day when scheduled."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-daily/weekly
  679. :type '(choice
  680. (const :tag "Alwas show prewarning" nil)
  681. (const :tag "Remove prewarning if entry is scheduled" t)
  682. (integer :tag "Restart prewarning N days before deadline")))
  683. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  684. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  685. When non-nil, after the search for timestamps has matched once in an
  686. entry, the rest of the entry will not be searched."
  687. :group 'org-agenda-skip
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-timestamp-if-done nil
  690. "Non-nil means don't select item by timestamp or -range if it is DONE."
  691. :group 'org-agenda-skip
  692. :group 'org-agenda-daily/weekly
  693. :type 'boolean)
  694. (defcustom org-agenda-dim-blocked-tasks t
  695. "Non-nil means dim blocked tasks in the agenda display.
  696. This causes some overhead during agenda construction, but if you
  697. have turned on `org-enforce-todo-dependencies',
  698. `org-enforce-todo-checkbox-dependencies', or any other blocking
  699. mechanism, this will create useful feedback in the agenda.
  700. Instead of t, this variable can also have the value `invisible'.
  701. Then blocked tasks will be invisible and only become visible when
  702. they become unblocked. An exemption to this behavior is when a task is
  703. blocked because of unchecked checkboxes below it. Since checkboxes do
  704. not show up in the agenda views, making this task invisible you remove any
  705. trace from agenda views that there is something to do. Therefore, a task
  706. that is blocked because of checkboxes will never be made invisible, it
  707. will only be dimmed."
  708. :group 'org-agenda-daily/weekly
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Do not dim" nil)
  712. (const :tag "Dim to a grey face" t)
  713. (const :tag "Make invisible" invisible)))
  714. (defcustom org-timeline-show-empty-dates 3
  715. "Non-nil means `org-timeline' also shows dates without an entry.
  716. When nil, only the days which actually have entries are shown.
  717. When t, all days between the first and the last date are shown.
  718. When an integer, show also empty dates, but if there is a gap of more than
  719. N days, just insert a special line indicating the size of the gap."
  720. :group 'org-agenda-skip
  721. :type '(choice
  722. (const :tag "None" nil)
  723. (const :tag "All" t)
  724. (integer :tag "at most")))
  725. (defgroup org-agenda-startup nil
  726. "Options concerning initial settings in the Agenda in Org Mode."
  727. :tag "Org Agenda Startup"
  728. :group 'org-agenda)
  729. (defcustom org-agenda-menu-show-matcher t
  730. "Non-nil means show the match string in the agenda dispatcher menu.
  731. When nil, the matcher string is not shown, but is put into the help-echo
  732. property so than moving the mouse over the command shows it.
  733. Setting it to nil is good if matcher strings are very long and/or if
  734. you want to use two-column display (see `org-agenda-menu-two-column')."
  735. :group 'org-agenda
  736. :type 'boolean)
  737. (defcustom org-agenda-menu-two-column nil
  738. "Non-nil means, use two columns to show custom commands in the dispatcher.
  739. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  740. to nil."
  741. :group 'org-agenda
  742. :type 'boolean)
  743. (defcustom org-finalize-agenda-hook nil
  744. "Hook run just before displaying an agenda buffer."
  745. :group 'org-agenda-startup
  746. :type 'hook)
  747. (defcustom org-agenda-mouse-1-follows-link nil
  748. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  749. A longer mouse click will still set point. Does not work on XEmacs.
  750. Needs to be set before org.el is loaded."
  751. :group 'org-agenda-startup
  752. :type 'boolean)
  753. (defcustom org-agenda-start-with-follow-mode nil
  754. "The initial value of follow mode in a newly created agenda window."
  755. :group 'org-agenda-startup
  756. :type 'boolean)
  757. (defcustom org-agenda-show-outline-path t
  758. "Non-nil means show outline path in echo area after line motion."
  759. :group 'org-agenda-startup
  760. :type 'boolean)
  761. (defcustom org-agenda-start-with-entry-text-mode nil
  762. "The initial value of entry-text-mode in a newly created agenda window."
  763. :group 'org-agenda-startup
  764. :type 'boolean)
  765. (defcustom org-agenda-entry-text-maxlines 5
  766. "Number of text lines to be added when `E' is pressed in the agenda.
  767. Note that this variable only used during agenda display. Add add entry text
  768. when exporting the agenda, configure the variable
  769. `org-agenda-add-entry-ext-maxlines'."
  770. :group 'org-agenda
  771. :type 'integer)
  772. (defcustom org-agenda-entry-text-exclude-regexps nil
  773. "List of regular expressions to clean up entry text.
  774. The complete matches of all regular expressions in this list will be
  775. removed from entry text before it is shown in the agenda."
  776. :group 'org-agenda
  777. :type '(repeat (regexp)))
  778. (defvar org-agenda-entry-text-cleanup-hook nil
  779. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  780. This cleanup is done in a temporary buffer, so the function may inspect and
  781. change the entire buffer.
  782. Some default stuff like drawers and scheduling/deadline dates will already
  783. have been removed when this is called, as will any matches for regular
  784. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  785. (defvar org-agenda-include-inactive-timestamps nil
  786. "Non-nil means include inactive time stamps in agenda and timeline.")
  787. (defgroup org-agenda-windows nil
  788. "Options concerning the windows used by the Agenda in Org Mode."
  789. :tag "Org Agenda Windows"
  790. :group 'org-agenda)
  791. (defcustom org-agenda-window-setup 'reorganize-frame
  792. "How the agenda buffer should be displayed.
  793. Possible values for this option are:
  794. current-window Show agenda in the current window, keeping all other windows.
  795. other-window Use `switch-to-buffer-other-window' to display agenda.
  796. reorganize-frame Show only two windows on the current frame, the current
  797. window and the agenda.
  798. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  799. Also, when exiting the agenda, kill that frame.
  800. See also the variable `org-agenda-restore-windows-after-quit'."
  801. :group 'org-agenda-windows
  802. :type '(choice
  803. (const current-window)
  804. (const other-frame)
  805. (const other-window)
  806. (const reorganize-frame)))
  807. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  808. "The min and max height of the agenda window as a fraction of frame height.
  809. The value of the variable is a cons cell with two numbers between 0 and 1.
  810. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  811. :group 'org-agenda-windows
  812. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  813. (defcustom org-agenda-restore-windows-after-quit nil
  814. "Non-nil means restore window configuration upon exiting agenda.
  815. Before the window configuration is changed for displaying the agenda,
  816. the current status is recorded. When the agenda is exited with
  817. `q' or `x' and this option is set, the old state is restored. If
  818. `org-agenda-window-setup' is `other-frame', the value of this
  819. option will be ignored."
  820. :group 'org-agenda-windows
  821. :type 'boolean)
  822. (defcustom org-agenda-ndays nil
  823. "Number of days to include in overview display.
  824. Should be 1 or 7.
  825. Obsolete, see `org-agenda-span'."
  826. :group 'org-agenda-daily/weekly
  827. :type 'integer)
  828. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  829. (defcustom org-agenda-span 'week
  830. "Number of days to include in overview display.
  831. Can be day, week, month, year, or any number of days.
  832. Custom commands can set this variable in the options section."
  833. :group 'org-agenda-daily/weekly
  834. :type '(choice (const :tag "Day" day)
  835. (const :tag "Week" week)
  836. (const :tag "Month" month)
  837. (const :tag "Year" year)
  838. (integer :tag "Custom")))
  839. (defcustom org-agenda-start-on-weekday 1
  840. "Non-nil means start the overview always on the specified weekday.
  841. 0 denotes Sunday, 1 denotes Monday etc.
  842. When nil, always start on the current day.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type '(choice (const :tag "Today" nil)
  846. (integer :tag "Weekday No.")))
  847. (defcustom org-agenda-show-all-dates t
  848. "Non-nil means `org-agenda' shows every day in the selected range.
  849. When nil, only the days which actually have entries are shown."
  850. :group 'org-agenda-daily/weekly
  851. :type 'boolean)
  852. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  853. "Format string for displaying dates in the agenda.
  854. Used by the daily/weekly agenda and by the timeline. This should be
  855. a format string understood by `format-time-string', or a function returning
  856. the formatted date as a string. The function must take a single argument,
  857. a calendar-style date list like (month day year)."
  858. :group 'org-agenda-daily/weekly
  859. :type '(choice
  860. (string :tag "Format string")
  861. (function :tag "Function")))
  862. (defun org-agenda-format-date-aligned (date)
  863. "Format a date string for display in the daily/weekly agenda, or timeline.
  864. This function makes sure that dates are aligned for easy reading."
  865. (require 'cal-iso)
  866. (let* ((dayname (calendar-day-name date))
  867. (day (cadr date))
  868. (day-of-week (calendar-day-of-week date))
  869. (month (car date))
  870. (monthname (calendar-month-name month))
  871. (year (nth 2 date))
  872. (iso-week (org-days-to-iso-week
  873. (calendar-absolute-from-gregorian date)))
  874. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  875. (1- year))
  876. ((and (= month 12) (<= iso-week 1))
  877. (1+ year))
  878. (t year)))
  879. (weekstring (if (= day-of-week 1)
  880. (format " W%02d" iso-week)
  881. "")))
  882. (format "%-10s %2d %s %4d%s"
  883. dayname day monthname year weekstring)))
  884. (defcustom org-agenda-time-leading-zero nil
  885. "Non-nil means use leading zero for military times in agenda.
  886. For example, 9:30am would become 09:30 rather than 9:30."
  887. :group 'org-agenda-daily/weekly
  888. :type 'boolean)
  889. (defcustom org-agenda-timegrid-use-ampm nil
  890. "When set, show AM/PM style timestamps on the timegrid."
  891. :group 'org-agenda
  892. :type 'boolean)
  893. (defun org-agenda-time-of-day-to-ampm (time)
  894. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  895. (let* ((hour-number (string-to-number (substring time 0 -3)))
  896. (minute (substring time -2))
  897. (ampm "am"))
  898. (cond
  899. ((equal hour-number 12)
  900. (setq ampm "pm"))
  901. ((> hour-number 12)
  902. (setq ampm "pm")
  903. (setq hour-number (- hour-number 12))))
  904. (concat
  905. (if org-agenda-time-leading-zero
  906. (format "%02d" hour-number)
  907. (format "%02s" (number-to-string hour-number)))
  908. ":" minute ampm)))
  909. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  910. "Conditionally convert TIME to AM/PM format
  911. based on `org-agenda-timegrid-use-ampm'"
  912. (if org-agenda-timegrid-use-ampm
  913. (org-agenda-time-of-day-to-ampm time)
  914. time))
  915. (defcustom org-agenda-weekend-days '(6 0)
  916. "Which days are weekend?
  917. These days get the special face `org-agenda-date-weekend' in the agenda
  918. and timeline buffers."
  919. :group 'org-agenda-daily/weekly
  920. :type '(set :greedy t
  921. (const :tag "Monday" 1)
  922. (const :tag "Tuesday" 2)
  923. (const :tag "Wednesday" 3)
  924. (const :tag "Thursday" 4)
  925. (const :tag "Friday" 5)
  926. (const :tag "Saturday" 6)
  927. (const :tag "Sunday" 0)))
  928. (defcustom org-agenda-include-diary nil
  929. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  930. Custom commands can set this variable in the options section."
  931. :group 'org-agenda-daily/weekly
  932. :type 'boolean)
  933. (defcustom org-agenda-include-deadlines t
  934. "If non-nil, include entries within their deadline warning period.
  935. Custom commands can set this variable in the options section."
  936. :group 'org-agenda-daily/weekly
  937. :type 'boolean)
  938. (defcustom org-agenda-include-all-todo nil
  939. "Set means weekly/daily agenda will always contain all TODO entries.
  940. The TODO entries will be listed at the top of the agenda, before
  941. the entries for specific days.
  942. This option is deprecated, it is better to define a block agenda instead."
  943. :group 'org-agenda-daily/weekly
  944. :type 'boolean)
  945. (defcustom org-agenda-repeating-timestamp-show-all t
  946. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  947. When set to a list of strings, only show occurrences of repeating
  948. stamps for these TODO keywords. When nil, only one occurrence is
  949. shown, either today or the nearest into the future."
  950. :group 'org-agenda-daily/weekly
  951. :type '(choice
  952. (const :tag "Show repeating stamps" t)
  953. (repeat :tag "Show repeating stamps for these TODO keywords"
  954. (string :tag "TODO Keyword"))
  955. (const :tag "Don't show repeating stamps" nil)))
  956. (defcustom org-scheduled-past-days 10000
  957. "No. of days to continue listing scheduled items that are not marked DONE.
  958. When an item is scheduled on a date, it shows up in the agenda on this
  959. day and will be listed until it is marked done for the number of days
  960. given here."
  961. :group 'org-agenda-daily/weekly
  962. :type 'integer)
  963. (defcustom org-agenda-log-mode-items '(closed clock)
  964. "List of items that should be shown in agenda log mode.
  965. This list may contain the following symbols:
  966. closed Show entries that have been closed on that day.
  967. clock Show entries that have received clocked time on that day.
  968. state Show all logged state changes.
  969. Note that instead of changing this variable, you can also press `C-u l' in
  970. the agenda to display all available LOG items temporarily."
  971. :group 'org-agenda-daily/weekly
  972. :type '(set :greedy t (const closed) (const clock) (const state)))
  973. (defcustom org-agenda-log-mode-add-notes t
  974. "Non-nil means add first line of notes to log entries in agenda views.
  975. If a log item like a state change or a clock entry is associated with
  976. notes, the first line of these notes will be added to the entry in the
  977. agenda display."
  978. :group 'org-agenda-daily/weekly
  979. :type 'boolean)
  980. (defcustom org-agenda-start-with-log-mode nil
  981. "The initial value of log-mode in a newly created agenda window."
  982. :group 'org-agenda-startup
  983. :group 'org-agenda-daily/weekly
  984. :type 'boolean)
  985. (defcustom org-agenda-start-with-clockreport-mode nil
  986. "The initial value of clockreport-mode in a newly created agenda window."
  987. :group 'org-agenda-startup
  988. :group 'org-agenda-daily/weekly
  989. :type 'boolean)
  990. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  991. "Property list with parameters for the clocktable in clockreport mode.
  992. This is the display mode that shows a clock table in the daily/weekly
  993. agenda, the properties for this dynamic block can be set here.
  994. The usual clocktable parameters are allowed here, but you cannot set
  995. the properties :name, :tstart, :tend, :block, and :scope - these will
  996. be overwritten to make sure the content accurately reflects the
  997. current display in the agenda."
  998. :group 'org-agenda-daily/weekly
  999. :type 'plist)
  1000. (defcustom org-agenda-search-view-always-boolean nil
  1001. "Non-nil means the search string is interpreted as individual parts.
  1002. The search string for search view can either be interpreted as a phrase,
  1003. or as a list of snippets that define a boolean search for a number of
  1004. strings.
  1005. When this is non-nil, the string will be split on whitespace, and each
  1006. snippet will be searched individually, and all must match in order to
  1007. select an entry. A snippet is then a single string of non-white
  1008. characters, or a string in double quotes, or a regexp in {} braces.
  1009. If a snippet is preceded by \"-\", the snippet must *not* match.
  1010. \"+\" is syntactic sugar for positive selection. Each snippet may
  1011. be found as a full word or a partial word, but see the variable
  1012. `org-agenda-search-view-force-full-words'.
  1013. When this is nil, search will look for the entire search phrase as one,
  1014. with each space character matching any amount of whitespace, including
  1015. line breaks.
  1016. Even when this is nil, you can still switch to Boolean search dynamically
  1017. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1018. is a regexp marked with braces like \"{abc}\", this will also switch to
  1019. boolean search."
  1020. :group 'org-agenda-search-view
  1021. :type 'boolean)
  1022. (if (fboundp 'defvaralias)
  1023. (defvaralias 'org-agenda-search-view-search-words-only
  1024. 'org-agenda-search-view-always-boolean))
  1025. (defcustom org-agenda-search-view-force-full-words nil
  1026. "Non-nil means, search words must be matches as complete words.
  1027. When nil, they may also match part of a word."
  1028. :group 'org-agenda-search-view
  1029. :type 'boolean)
  1030. (defgroup org-agenda-time-grid nil
  1031. "Options concerning the time grid in the Org-mode Agenda."
  1032. :tag "Org Agenda Time Grid"
  1033. :group 'org-agenda)
  1034. (defcustom org-agenda-search-headline-for-time t
  1035. "Non-nil means search headline for a time-of-day.
  1036. If the headline contains a time-of-day in one format or another, it will
  1037. be used to sort the entry into the time sequence of items for a day.
  1038. Some people have time stamps in the headline that refer to the creation
  1039. time or so, and then this produces an unwanted side effect. If this is
  1040. the case for your, use this variable to turn off searching the headline
  1041. for a time."
  1042. :group 'org-agenda-time-grid
  1043. :type 'boolean)
  1044. (defcustom org-agenda-use-time-grid t
  1045. "Non-nil means show a time grid in the agenda schedule.
  1046. A time grid is a set of lines for specific times (like every two hours between
  1047. 8:00 and 20:00). The items scheduled for a day at specific times are
  1048. sorted in between these lines.
  1049. For details about when the grid will be shown, and what it will look like, see
  1050. the variable `org-agenda-time-grid'."
  1051. :group 'org-agenda-time-grid
  1052. :type 'boolean)
  1053. (defcustom org-agenda-time-grid
  1054. '((daily today require-timed)
  1055. "----------------"
  1056. (800 1000 1200 1400 1600 1800 2000))
  1057. "The settings for time grid for agenda display.
  1058. This is a list of three items. The first item is again a list. It contains
  1059. symbols specifying conditions when the grid should be displayed:
  1060. daily if the agenda shows a single day
  1061. weekly if the agenda shows an entire week
  1062. today show grid on current date, independent of daily/weekly display
  1063. require-timed show grid only if at least one item has a time specification
  1064. The second item is a string which will be placed behind the grid time.
  1065. The third item is a list of integers, indicating the times that should have
  1066. a grid line."
  1067. :group 'org-agenda-time-grid
  1068. :type
  1069. '(list
  1070. (set :greedy t :tag "Grid Display Options"
  1071. (const :tag "Show grid in single day agenda display" daily)
  1072. (const :tag "Show grid in weekly agenda display" weekly)
  1073. (const :tag "Always show grid for today" today)
  1074. (const :tag "Show grid only if any timed entries are present"
  1075. require-timed)
  1076. (const :tag "Skip grid times already present in an entry"
  1077. remove-match))
  1078. (string :tag "Grid String")
  1079. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1080. (defcustom org-agenda-show-current-time-in-grid t
  1081. "Non-nil means show the current time in the time grid."
  1082. :group 'org-agenda-time-grid
  1083. :type 'boolean)
  1084. (defcustom org-agenda-current-time-string
  1085. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1086. "The string for the current time marker in the agenda."
  1087. :group 'org-agenda-time-grid
  1088. :type 'string)
  1089. (defgroup org-agenda-sorting nil
  1090. "Options concerning sorting in the Org-mode Agenda."
  1091. :tag "Org Agenda Sorting"
  1092. :group 'org-agenda)
  1093. (defcustom org-agenda-sorting-strategy
  1094. '((agenda habit-down time-up priority-down category-keep)
  1095. (todo priority-down category-keep)
  1096. (tags priority-down category-keep)
  1097. (search category-keep))
  1098. "Sorting structure for the agenda items of a single day.
  1099. This is a list of symbols which will be used in sequence to determine
  1100. if an entry should be listed before another entry. The following
  1101. symbols are recognized:
  1102. time-up Put entries with time-of-day indications first, early first
  1103. time-down Put entries with time-of-day indications first, late first
  1104. category-keep Keep the default order of categories, corresponding to the
  1105. sequence in `org-agenda-files'.
  1106. category-up Sort alphabetically by category, A-Z.
  1107. category-down Sort alphabetically by category, Z-A.
  1108. tag-up Sort alphabetically by last tag, A-Z.
  1109. tag-down Sort alphabetically by last tag, Z-A.
  1110. priority-up Sort numerically by priority, high priority last.
  1111. priority-down Sort numerically by priority, high priority first.
  1112. todo-state-up Sort by todo state, tasks that are done last.
  1113. todo-state-down Sort by todo state, tasks that are done first.
  1114. effort-up Sort numerically by estimated effort, high effort last.
  1115. effort-down Sort numerically by estimated effort, high effort first.
  1116. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1117. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1118. habit-up Put entries that are habits first
  1119. habit-down Put entries that are habits last
  1120. alpha-up Sort headlines alphabetically
  1121. alpha-down Sort headlines alphabetically, reversed
  1122. The different possibilities will be tried in sequence, and testing stops
  1123. if one comparison returns a \"not-equal\". For example, the default
  1124. '(time-up category-keep priority-down)
  1125. means: Pull out all entries having a specified time of day and sort them,
  1126. in order to make a time schedule for the current day the first thing in the
  1127. agenda listing for the day. Of the entries without a time indication, keep
  1128. the grouped in categories, don't sort the categories, but keep them in
  1129. the sequence given in `org-agenda-files'. Within each category sort by
  1130. priority.
  1131. Leaving out `category-keep' would mean that items will be sorted across
  1132. categories by priority.
  1133. Instead of a single list, this can also be a set of list for specific
  1134. contents, with a context symbol in the car of the list, any of
  1135. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1136. Custom commands can bind this variable in the options section."
  1137. :group 'org-agenda-sorting
  1138. :type `(choice
  1139. (repeat :tag "General" ,org-sorting-choice)
  1140. (list :tag "Individually"
  1141. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1142. (repeat ,org-sorting-choice))
  1143. (cons (const :tag "Strategy for TODO lists" todo)
  1144. (repeat ,org-sorting-choice))
  1145. (cons (const :tag "Strategy for Tags matches" tags)
  1146. (repeat ,org-sorting-choice))
  1147. (cons (const :tag "Strategy for search matches" search)
  1148. (repeat ,org-sorting-choice)))))
  1149. (defcustom org-agenda-cmp-user-defined nil
  1150. "A function to define the comparison `user-defined'.
  1151. This function must receive two arguments, agenda entry a and b.
  1152. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1153. the user comparison, return nil.
  1154. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1155. part of an agenda sorting strategy."
  1156. :group 'org-agenda-sorting
  1157. :type 'symbol)
  1158. (defcustom org-sort-agenda-notime-is-late t
  1159. "Non-nil means items without time are considered late.
  1160. This is only relevant for sorting. When t, items which have no explicit
  1161. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1162. do have a time. When nil, the default time is before 0:00. You can use this
  1163. option to decide if the schedule for today should come before or after timeless
  1164. agenda entries."
  1165. :group 'org-agenda-sorting
  1166. :type 'boolean)
  1167. (defcustom org-sort-agenda-noeffort-is-high t
  1168. "Non-nil means items without effort estimate are sorted as high effort.
  1169. This also applies when filtering an agenda view with respect to the
  1170. < or > effort operator. Then, tasks with no effort defined will be treated
  1171. as tasks with high effort.
  1172. When nil, such items are sorted as 0 minutes effort."
  1173. :group 'org-agenda-sorting
  1174. :type 'boolean)
  1175. (defgroup org-agenda-line-format nil
  1176. "Options concerning the entry prefix in the Org-mode agenda display."
  1177. :tag "Org Agenda Line Format"
  1178. :group 'org-agenda)
  1179. (defcustom org-agenda-prefix-format
  1180. '((agenda . " %i %-12:c%?-12t% s")
  1181. (timeline . " % s")
  1182. (todo . " %i %-12:c")
  1183. (tags . " %i %-12:c")
  1184. (search . " %i %-12:c"))
  1185. "Format specifications for the prefix of items in the agenda views.
  1186. An alist with four entries, for the different agenda types. The keys to the
  1187. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1188. are format strings.
  1189. This format works similar to a printf format, with the following meaning:
  1190. %c the category of the item, \"Diary\" for entries from the diary, or
  1191. as given by the CATEGORY keyword or derived from the file name.
  1192. %i the icon category of the item, as give in
  1193. `org-agenda-category-icon-alist'.
  1194. %T the *last* tag of the item. Last because inherited tags come
  1195. first in the list.
  1196. %t the time-of-day specification if one applies to the entry, in the
  1197. format HH:MM
  1198. %s Scheduling/Deadline information, a short string
  1199. %(expression) Eval EXPRESSION and replace the control string
  1200. by the result
  1201. All specifiers work basically like the standard `%s' of printf, but may
  1202. contain two additional characters: A question mark just after the `%' and
  1203. a whitespace/punctuation character just before the final letter.
  1204. If the first character after `%' is a question mark, the entire field
  1205. will only be included if the corresponding value applies to the
  1206. current entry. This is useful for fields which should have fixed
  1207. width when present, but zero width when absent. For example,
  1208. \"%?-12t\" will result in a 12 character time field if a time of the
  1209. day is specified, but will completely disappear in entries which do
  1210. not contain a time.
  1211. If there is punctuation or whitespace character just before the final
  1212. format letter, this character will be appended to the field value if
  1213. the value is not empty. For example, the format \"%-12:c\" leads to
  1214. \"Diary: \" if the category is \"Diary\". If the category were be
  1215. empty, no additional colon would be inserted.
  1216. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1217. - Indent the line with two space characters
  1218. - Give the category in a 12 chars wide field, padded with whitespace on
  1219. the right (because of `-'). Append a colon if there is a category
  1220. (because of `:').
  1221. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1222. time, don't put in an empty field, just skip it (because of '?').
  1223. - Finally, put the scheduling information and append a whitespace.
  1224. As another example, if you don't want the time-of-day of entries in
  1225. the prefix, you could use:
  1226. (setq org-agenda-prefix-format \" %-11:c% s\")
  1227. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1228. `org-agenda-remove-tags'.
  1229. Custom commands can set this variable in the options section."
  1230. :type '(choice
  1231. (string :tag "General format")
  1232. (list :greedy t :tag "View dependent"
  1233. (cons (const agenda) (string :tag "Format"))
  1234. (cons (const timeline) (string :tag "Format"))
  1235. (cons (const todo) (string :tag "Format"))
  1236. (cons (const tags) (string :tag "Format"))
  1237. (cons (const search) (string :tag "Format"))))
  1238. :group 'org-agenda-line-format)
  1239. (defvar org-prefix-format-compiled nil
  1240. "The compiled version of the most recently used prefix format.
  1241. See the variable `org-agenda-prefix-format'.")
  1242. (defcustom org-agenda-todo-keyword-format "%-1s"
  1243. "Format for the TODO keyword in agenda lines.
  1244. Set this to something like \"%-12s\" if you want all TODO keywords
  1245. to occupy a fixed space in the agenda display."
  1246. :group 'org-agenda-line-format
  1247. :type 'string)
  1248. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1249. "Text preceding timerange entries in the agenda view.
  1250. This is a list with two strings. The first applies when the range
  1251. is entirely on one day. The second applies if the range spans several days.
  1252. The strings may have two \"%d\" format specifiers which will be filled
  1253. with the sequence number of the days, and the total number of days in the
  1254. range, respectively."
  1255. :group 'org-agenda-line-format
  1256. :type '(list
  1257. (string :tag "Deadline today ")
  1258. (choice :tag "Deadline relative"
  1259. (string :tag "Format string")
  1260. (function))))
  1261. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1262. "Text preceding scheduled items in the agenda view.
  1263. This is a list with two strings. The first applies when the item is
  1264. scheduled on the current day. The second applies when it has been scheduled
  1265. previously, it may contain a %d indicating that this is the nth time that
  1266. this item is scheduled, due to automatic rescheduling of unfinished items
  1267. for the following day. So this number is one larger than the number of days
  1268. that passed since this item was scheduled first."
  1269. :group 'org-agenda-line-format
  1270. :type '(list
  1271. (string :tag "Scheduled today ")
  1272. (string :tag "Scheduled previously")))
  1273. (defcustom org-agenda-inactive-leader "["
  1274. "Text preceding item pulled into the agenda by inactive time stamps.
  1275. These entries are added to the agenda when pressing \"[\"."
  1276. :group 'org-agenda-line-format
  1277. :type '(list
  1278. (string :tag "Scheduled today ")
  1279. (string :tag "Scheduled previously")))
  1280. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1281. "Text preceding deadline items in the agenda view.
  1282. This is a list with two strings. The first applies when the item has its
  1283. deadline on the current day. The second applies when it is in the past or
  1284. in the future, it may contain %d to capture how many days away the deadline
  1285. is (was)."
  1286. :group 'org-agenda-line-format
  1287. :type '(list
  1288. (string :tag "Deadline today ")
  1289. (choice :tag "Deadline relative"
  1290. (string :tag "Format string")
  1291. (function))))
  1292. (defcustom org-agenda-remove-times-when-in-prefix t
  1293. "Non-nil means remove duplicate time specifications in agenda items.
  1294. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1295. time-of-day specification in a headline or diary entry is extracted and
  1296. placed into the prefix. If this option is non-nil, the original specification
  1297. \(a timestamp or -range, or just a plain time(range) specification like
  1298. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1299. cluttered.
  1300. The option can be t or nil. It may also be the symbol `beg', indicating
  1301. that the time should only be removed when it is located at the beginning of
  1302. the headline/diary entry."
  1303. :group 'org-agenda-line-format
  1304. :type '(choice
  1305. (const :tag "Always" t)
  1306. (const :tag "Never" nil)
  1307. (const :tag "When at beginning of entry" beg)))
  1308. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1309. "Non-nil means remove time ranges specifications in agenda
  1310. items that span on several days."
  1311. :group 'org-agenda-line-format
  1312. :type 'boolean)
  1313. (defcustom org-agenda-default-appointment-duration nil
  1314. "Default duration for appointments that only have a starting time.
  1315. When nil, no duration is specified in such cases.
  1316. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1317. :group 'org-agenda-line-format
  1318. :type '(choice
  1319. (integer :tag "Minutes")
  1320. (const :tag "No default duration")))
  1321. (defcustom org-agenda-show-inherited-tags t
  1322. "Non-nil means show inherited tags in each agenda line."
  1323. :group 'org-agenda-line-format
  1324. :type 'boolean)
  1325. (defcustom org-agenda-hide-tags-regexp nil
  1326. "Regular expression used to filter away specific tags in agenda views.
  1327. This means that these tags will be present, but not be shown in the agenda
  1328. line. Secondary filtering will still work on the hidden tags.
  1329. Nil means don't hide any tags."
  1330. :group 'org-agenda-line-format
  1331. :type '(choice
  1332. (const :tag "Hide none" nil)
  1333. (string :tag "Regexp ")))
  1334. (defcustom org-agenda-remove-tags nil
  1335. "Non-nil means remove the tags from the headline copy in the agenda.
  1336. When this is the symbol `prefix', only remove tags when
  1337. `org-agenda-prefix-format' contains a `%T' specifier."
  1338. :group 'org-agenda-line-format
  1339. :type '(choice
  1340. (const :tag "Always" t)
  1341. (const :tag "Never" nil)
  1342. (const :tag "When prefix format contains %T" prefix)))
  1343. (if (fboundp 'defvaralias)
  1344. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1345. 'org-agenda-remove-tags))
  1346. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1347. "Shift tags in agenda items to this column.
  1348. If this number is positive, it specifies the column. If it is negative,
  1349. it means that the tags should be flushright to that column. For example,
  1350. -80 works well for a normal 80 character screen."
  1351. :group 'org-agenda-line-format
  1352. :type 'integer)
  1353. (if (fboundp 'defvaralias)
  1354. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1355. (defcustom org-agenda-fontify-priorities 'cookies
  1356. "Non-nil means highlight low and high priorities in agenda.
  1357. When t, the highest priority entries are bold, lowest priority italic.
  1358. However, settings in `org-priority-faces' will overrule these faces.
  1359. When this variable is the symbol `cookies', only fontify the
  1360. cookies, not the entire task.
  1361. This may also be an association list of priority faces, whose
  1362. keys are the character values of `org-highest-priority',
  1363. `org-default-priority', and `org-lowest-priority' (the default values
  1364. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1365. color as a string, or a list like `(:background \"Red\")'.
  1366. If it is a color, the variable `org-faces-easy-properties'
  1367. determines if it is a foreground or a background color."
  1368. :group 'org-agenda-line-format
  1369. :type '(choice
  1370. (const :tag "Never" nil)
  1371. (const :tag "Defaults" t)
  1372. (const :tag "Cookies only" cookies)
  1373. (repeat :tag "Specify"
  1374. (list (character :tag "Priority" :value ?A)
  1375. (choice :tag "Face "
  1376. (string :tag "Color")
  1377. (sexp :tag "Face"))))))
  1378. (defcustom org-agenda-day-face-function nil
  1379. "Function called to determine what face should be used to display a day.
  1380. The only argument passed to that function is the day. It should
  1381. returns a face, or nil if does not want to specify a face and let
  1382. the normal rules apply."
  1383. :group 'org-agenda-line-format
  1384. :type 'function)
  1385. (defcustom org-agenda-category-icon-alist nil
  1386. "Alist of category icon to be displayed in agenda views.
  1387. Each entry should have the following format:
  1388. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1389. Where CATEGORY-REGEXP is a regexp matching the categories where
  1390. the icon should be displayed.
  1391. FILE-OR-DATA either a file path or a string containing image data.
  1392. The other fields can be omited safely if not needed:
  1393. TYPE indicates the image type.
  1394. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1395. image data.
  1396. PROPS are additional image attributes to assign to the image,
  1397. like, e.g. `:ascent center'.
  1398. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1399. If you want to set the display properties yourself, just put a
  1400. list as second element:
  1401. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1402. For example, to display a 16px horizontal space for Emacs
  1403. category, you can use:
  1404. (\"Emacs\" '(space . (:width (16))))"
  1405. :group 'org-agenda-line-format
  1406. :type '(alist :key-type (string :tag "Regexp matching category")
  1407. :value-type (choice (list :tag "Icon"
  1408. (string :tag "File or data")
  1409. (symbol :tag "Type")
  1410. (boolean :tag "Data?")
  1411. (repeat :tag "Extra image properties" :inline t symbol))
  1412. (list :tag "Display properties" sexp))))
  1413. (defgroup org-agenda-column-view nil
  1414. "Options concerning column view in the agenda."
  1415. :tag "Org Agenda Column View"
  1416. :group 'org-agenda)
  1417. (defcustom org-agenda-columns-show-summaries t
  1418. "Non-nil means show summaries for columns displayed in the agenda view."
  1419. :group 'org-agenda-column-view
  1420. :type 'boolean)
  1421. (defcustom org-agenda-columns-remove-prefix-from-item t
  1422. "Non-nil means remove the prefix from a headline for agenda column view.
  1423. The special ITEM field in the columns format contains the current line, with
  1424. all information shown in other columns (like the TODO state or a tag).
  1425. When this variable is non-nil, also the agenda prefix will be removed from
  1426. the content of the ITEM field, to make sure as much as possible of the
  1427. headline can be shown in the limited width of the field."
  1428. :group 'org-agenda
  1429. :type 'boolean)
  1430. (defcustom org-agenda-columns-compute-summary-properties t
  1431. "Non-nil means recompute all summary properties before column view.
  1432. When column view in the agenda is listing properties that have a summary
  1433. operator, it can go to all relevant buffers and recompute the summaries
  1434. there. This can mean overhead for the agenda column view, but is necessary
  1435. to have thing up to date.
  1436. As a special case, a CLOCKSUM property also makes sure that the clock
  1437. computations are current."
  1438. :group 'org-agenda-column-view
  1439. :type 'boolean)
  1440. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1441. "Non-nil means the duration of an appointment will add to day effort.
  1442. The property to which appointment durations will be added is the one given
  1443. in the option `org-effort-property'. If an appointment does not have
  1444. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1445. is not set, an appointment without end time will not contribute to the time
  1446. estimate."
  1447. :group 'org-agenda-column-view
  1448. :type 'boolean)
  1449. (defcustom org-agenda-auto-exclude-function nil
  1450. "A function called with a tag to decide if it is filtered on '/ RET'.
  1451. The sole argument to the function, which is called once for each
  1452. possible tag, is a string giving the name of the tag. The
  1453. function should return either nil if the tag should be included
  1454. as normal, or \"-<TAG>\" to exclude the tag.
  1455. Note that for the purpose of tag filtering, only the lower-case version of
  1456. all tags will be considered, so that this function will only ever see
  1457. the lower-case version of all tags."
  1458. :group 'org-agenda
  1459. :type 'function)
  1460. (eval-when-compile
  1461. (require 'cl))
  1462. (require 'org)
  1463. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1464. "Execute BODY with point at location given by `org-hd-marker' property.
  1465. If STRING is non-nil, the text property will be fetched from position 0
  1466. in that string. If STRING is nil, it will be fetched from the beginning
  1467. of the current line."
  1468. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1469. 'org-hd-marker string)))
  1470. (with-current-buffer (marker-buffer marker)
  1471. (save-excursion
  1472. (goto-char marker)
  1473. ,@body))))
  1474. (defun org-add-agenda-custom-command (entry)
  1475. "Replace or add a command in `org-agenda-custom-commands'.
  1476. This is mostly for hacking and trying a new command - once the command
  1477. works you probably want to add it to `org-agenda-custom-commands' for good."
  1478. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1479. (if ass
  1480. (setcdr ass (cdr entry))
  1481. (push entry org-agenda-custom-commands))))
  1482. ;;; Define the Org-agenda-mode
  1483. (defvar org-agenda-mode-map (make-sparse-keymap)
  1484. "Keymap for `org-agenda-mode'.")
  1485. (if (fboundp 'defvaralias)
  1486. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1487. (defvar org-agenda-menu) ; defined later in this file.
  1488. (defvar org-agenda-restrict) ; defined later in this file.
  1489. (defvar org-agenda-follow-mode nil)
  1490. (defvar org-agenda-entry-text-mode nil)
  1491. (defvar org-agenda-clockreport-mode nil)
  1492. (defvar org-agenda-show-log nil)
  1493. (defvar org-agenda-redo-command nil)
  1494. (defvar org-agenda-query-string nil)
  1495. (defvar org-agenda-mode-hook nil
  1496. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1497. (defvar org-agenda-type nil)
  1498. (defvar org-agenda-force-single-file nil)
  1499. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1500. (defun org-agenda-mode ()
  1501. "Mode for time-sorted view on action items in Org-mode files.
  1502. The following commands are available:
  1503. \\{org-agenda-mode-map}"
  1504. (interactive)
  1505. (kill-all-local-variables)
  1506. (setq org-agenda-undo-list nil
  1507. org-agenda-pending-undo-list nil
  1508. org-agenda-bulk-marked-entries nil)
  1509. (setq major-mode 'org-agenda-mode)
  1510. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1511. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1512. (setq mode-name "Org-Agenda")
  1513. (use-local-map org-agenda-mode-map)
  1514. (easy-menu-add org-agenda-menu)
  1515. (if org-startup-truncated (setq truncate-lines t))
  1516. (org-set-local 'line-move-visual nil)
  1517. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1518. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1519. ;; Make sure properties are removed when copying text
  1520. (when (boundp 'buffer-substring-filters)
  1521. (org-set-local 'buffer-substring-filters
  1522. (cons (lambda (x)
  1523. (set-text-properties 0 (length x) nil x) x)
  1524. buffer-substring-filters)))
  1525. (unless org-agenda-keep-modes
  1526. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1527. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1528. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1529. org-agenda-show-log org-agenda-start-with-log-mode))
  1530. (easy-menu-change
  1531. '("Agenda") "Agenda Files"
  1532. (append
  1533. (list
  1534. (vector
  1535. (if (get 'org-agenda-files 'org-restrict)
  1536. "Restricted to single file"
  1537. "Edit File List")
  1538. '(org-edit-agenda-file-list)
  1539. (not (get 'org-agenda-files 'org-restrict)))
  1540. "--")
  1541. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1542. (org-agenda-set-mode-name)
  1543. (apply
  1544. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1545. (list 'org-agenda-mode-hook)))
  1546. (substitute-key-definition 'undo 'org-agenda-undo
  1547. org-agenda-mode-map global-map)
  1548. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1549. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1550. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1551. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1552. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1553. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1554. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1555. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1556. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1557. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1558. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1559. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1560. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1561. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1562. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1563. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1564. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1565. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1566. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1567. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1568. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1569. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1570. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1571. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1572. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1573. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1574. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1575. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1576. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1577. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1578. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1579. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1580. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1581. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1582. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1583. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1584. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1585. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1586. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1587. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1588. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1589. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1590. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1591. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1592. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1593. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1594. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1595. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1596. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1597. (while l (org-defkey org-agenda-mode-map
  1598. (int-to-string (pop l)) 'digit-argument)))
  1599. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1600. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1601. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1602. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1603. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1604. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1605. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1606. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1607. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1608. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1609. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1610. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1611. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1612. 'org-clock-modify-effort-estimate)
  1613. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1614. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1615. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1616. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1617. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1618. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1619. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1620. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1621. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1622. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1623. (substitute-key-definition 'next-line 'org-agenda-next-line
  1624. org-agenda-mode-map global-map)
  1625. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1626. org-agenda-mode-map global-map)
  1627. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1628. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1630. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1631. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1632. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1633. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1634. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1635. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1636. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1637. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1638. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1639. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1640. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1641. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1642. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1643. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1644. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1645. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1646. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1647. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1648. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1649. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1650. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1651. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1652. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1653. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1654. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1655. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1656. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1657. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1658. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1659. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1660. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1661. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1662. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1663. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1664. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1666. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1667. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1668. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1669. (when org-agenda-mouse-1-follows-link
  1670. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1671. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1672. '("Agenda"
  1673. ("Agenda Files")
  1674. "--"
  1675. ("Agenda Dates"
  1676. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1677. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1678. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1679. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1680. "--"
  1681. ("View"
  1682. ["Day View" org-agenda-day-view
  1683. :active (org-agenda-check-type nil 'agenda)
  1684. :style radio :selected (eq org-agenda-current-span 'day)
  1685. :keys "v d (or just d)"]
  1686. ["Week View" org-agenda-week-view
  1687. :active (org-agenda-check-type nil 'agenda)
  1688. :style radio :selected (eq org-agenda-current-span 'week)
  1689. :keys "v w (or just w)"]
  1690. ["Month View" org-agenda-month-view
  1691. :active (org-agenda-check-type nil 'agenda)
  1692. :style radio :selected (eq org-agenda-current-span 'month)
  1693. :keys "v m"]
  1694. ["Year View" org-agenda-year-view
  1695. :active (org-agenda-check-type nil 'agenda)
  1696. :style radio :selected (eq org-agenda-current-span 'year)
  1697. :keys "v y"]
  1698. "--"
  1699. ["Include Diary" org-agenda-toggle-diary
  1700. :style toggle :selected org-agenda-include-diary
  1701. :active (org-agenda-check-type nil 'agenda)]
  1702. ["Include Deadlines" org-agenda-toggle-deadlines
  1703. :style toggle :selected org-agenda-include-deadlines
  1704. :active (org-agenda-check-type nil 'agenda)]
  1705. ["Use Time Grid" org-agenda-toggle-time-grid
  1706. :style toggle :selected org-agenda-use-time-grid
  1707. :active (org-agenda-check-type nil 'agenda)]
  1708. "--"
  1709. ["Show clock report" org-agenda-clockreport-mode
  1710. :style toggle :selected org-agenda-clockreport-mode
  1711. :active (org-agenda-check-type nil 'agenda)]
  1712. ["Show some entry text" org-agenda-entry-text-mode
  1713. :style toggle :selected org-agenda-entry-text-mode
  1714. :active t]
  1715. "--"
  1716. ["Show Logbook entries" org-agenda-log-mode
  1717. :style toggle :selected org-agenda-show-log
  1718. :active (org-agenda-check-type nil 'agenda 'timeline)
  1719. :keys "v l (or just l)"]
  1720. ["Include archived trees" org-agenda-archives-mode
  1721. :style toggle :selected org-agenda-archives-mode :active t
  1722. :keys "v a"]
  1723. ["Include archive files" (org-agenda-archives-mode t)
  1724. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1725. :keys "v A"]
  1726. "--"
  1727. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1728. ["Write view to file" org-write-agenda t]
  1729. ["Rebuild buffer" org-agenda-redo t]
  1730. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1731. "--"
  1732. ["Show original entry" org-agenda-show t]
  1733. ["Go To (other window)" org-agenda-goto t]
  1734. ["Go To (this window)" org-agenda-switch-to t]
  1735. ["Follow Mode" org-agenda-follow-mode
  1736. :style toggle :selected org-agenda-follow-mode :active t]
  1737. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1738. "--"
  1739. ("TODO"
  1740. ["Cycle TODO" org-agenda-todo t]
  1741. ["Next TODO set" org-agenda-todo-nextset t]
  1742. ["Previous TODO set" org-agenda-todo-previousset t]
  1743. ["Add note" org-agenda-add-note t])
  1744. ("Archive/Refile/Delete"
  1745. ["Archive default" org-agenda-archive-default t]
  1746. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1747. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1748. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1749. ["Archive subtree" org-agenda-archive t]
  1750. "--"
  1751. ["Refile" org-agenda-refile t]
  1752. "--"
  1753. ["Delete subtree" org-agenda-kill t])
  1754. ("Bulk action"
  1755. ["Mark entry" org-agenda-bulk-mark t]
  1756. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1757. ["Unmark entry" org-agenda-bulk-unmark t]
  1758. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1759. ["Act on all marked" org-agenda-bulk-action t]
  1760. "--"
  1761. ("Tags and Properties"
  1762. ["Show all Tags" org-agenda-show-tags t]
  1763. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1764. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1765. "--"
  1766. ["Column View" org-columns t])
  1767. ("Deadline/Schedule"
  1768. ["Schedule" org-agenda-schedule t]
  1769. ["Set Deadline" org-agenda-deadline t]
  1770. "--"
  1771. ["Mark item" org-agenda-action :active t :keys "k m"]
  1772. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1773. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1774. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1775. "--"
  1776. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1777. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1778. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1779. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1780. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1781. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1782. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1783. ("Clock and Effort"
  1784. ["Clock in" org-agenda-clock-in t]
  1785. ["Clock out" org-agenda-clock-out t]
  1786. ["Clock cancel" org-agenda-clock-cancel t]
  1787. ["Goto running clock" org-clock-goto t]
  1788. "--"
  1789. ["Set Effort" org-agenda-set-effort t]
  1790. ["Change clocked effort" org-clock-modify-effort-estimate
  1791. (org-clock-is-active)])
  1792. ("Priority"
  1793. ["Set Priority" org-agenda-priority t]
  1794. ["Increase Priority" org-agenda-priority-up t]
  1795. ["Decrease Priority" org-agenda-priority-down t]
  1796. ["Show Priority" org-agenda-show-priority t])
  1797. ("Calendar/Diary"
  1798. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1799. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1800. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1801. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1802. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1803. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1804. "--"
  1805. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1806. "--"
  1807. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1808. "--"
  1809. ("MobileOrg"
  1810. ["Push Files and Views" org-mobile-push t]
  1811. ["Get Captured and Flagged" org-mobile-pull t]
  1812. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1813. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1814. "--"
  1815. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1816. "--"
  1817. ["Quit" org-agenda-quit t]
  1818. ["Exit and Release Buffers" org-agenda-exit t]
  1819. ))
  1820. ;;; Agenda undo
  1821. (defvar org-agenda-allow-remote-undo t
  1822. "Non-nil means allow remote undo from the agenda buffer.")
  1823. (defvar org-agenda-undo-list nil
  1824. "List of undoable operations in the agenda since last refresh.")
  1825. (defvar org-agenda-undo-has-started-in nil
  1826. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1827. (defvar org-agenda-pending-undo-list nil
  1828. "In a series of undo commands, this is the list of remaining undo items.")
  1829. (defun org-agenda-undo ()
  1830. "Undo a remote editing step in the agenda.
  1831. This undoes changes both in the agenda buffer and in the remote buffer
  1832. that have been changed along."
  1833. (interactive)
  1834. (or org-agenda-allow-remote-undo
  1835. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1836. (if (not (eq this-command last-command))
  1837. (setq org-agenda-undo-has-started-in nil
  1838. org-agenda-pending-undo-list org-agenda-undo-list))
  1839. (if (not org-agenda-pending-undo-list)
  1840. (error "No further undo information"))
  1841. (let* ((entry (pop org-agenda-pending-undo-list))
  1842. buf line cmd rembuf)
  1843. (setq cmd (pop entry) line (pop entry))
  1844. (setq rembuf (nth 2 entry))
  1845. (org-with-remote-undo rembuf
  1846. (while (bufferp (setq buf (pop entry)))
  1847. (if (pop entry)
  1848. (with-current-buffer buf
  1849. (let ((last-undo-buffer buf)
  1850. (inhibit-read-only t))
  1851. (unless (memq buf org-agenda-undo-has-started-in)
  1852. (push buf org-agenda-undo-has-started-in)
  1853. (make-local-variable 'pending-undo-list)
  1854. (undo-start))
  1855. (while (and pending-undo-list
  1856. (listp pending-undo-list)
  1857. (not (car pending-undo-list)))
  1858. (pop pending-undo-list))
  1859. (undo-more 1))))))
  1860. (org-goto-line line)
  1861. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1862. (defun org-verify-change-for-undo (l1 l2)
  1863. "Verify that a real change occurred between the undo lists L1 and L2."
  1864. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1865. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1866. (not (eq l1 l2)))
  1867. ;;; Agenda dispatch
  1868. (defvar org-agenda-restrict nil)
  1869. (defvar org-agenda-restrict-begin (make-marker))
  1870. (defvar org-agenda-restrict-end (make-marker))
  1871. (defvar org-agenda-last-dispatch-buffer nil)
  1872. (defvar org-agenda-overriding-restriction nil)
  1873. ;;;###autoload
  1874. (defun org-agenda (&optional arg keys restriction)
  1875. "Dispatch agenda commands to collect entries to the agenda buffer.
  1876. Prompts for a command to execute. Any prefix arg will be passed
  1877. on to the selected command. The default selections are:
  1878. a Call `org-agenda-list' to display the agenda for current day or week.
  1879. t Call `org-todo-list' to display the global todo list.
  1880. T Call `org-todo-list' to display the global todo list, select only
  1881. entries with a specific TODO keyword (the user gets a prompt).
  1882. m Call `org-tags-view' to display headlines with tags matching
  1883. a condition (the user is prompted for the condition).
  1884. M Like `m', but select only TODO entries, no ordinary headlines.
  1885. L Create a timeline for the current buffer.
  1886. e Export views to associated files.
  1887. s Search entries for keywords.
  1888. / Multi occur across all agenda files and also files listed
  1889. in `org-agenda-text-search-extra-files'.
  1890. < Restrict agenda commands to buffer, subtree, or region.
  1891. Press several times to get the desired effect.
  1892. > Remove a previous restriction.
  1893. # List \"stuck\" projects.
  1894. ! Configure what \"stuck\" means.
  1895. C Configure custom agenda commands.
  1896. More commands can be added by configuring the variable
  1897. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1898. searches can be pre-defined in this way.
  1899. If the current buffer is in Org-mode and visiting a file, you can also
  1900. first press `<' once to indicate that the agenda should be temporarily
  1901. \(until the next use of \\[org-agenda]) restricted to the current file.
  1902. Pressing `<' twice means to restrict to the current subtree or region
  1903. \(if active)."
  1904. (interactive "P")
  1905. (catch 'exit
  1906. (let* ((prefix-descriptions nil)
  1907. (org-agenda-window-setup (if (equal (buffer-name)
  1908. org-agenda-buffer-name)
  1909. 'current-window
  1910. org-agenda-window-setup))
  1911. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1912. (org-agenda-custom-commands
  1913. ;; normalize different versions
  1914. (delq nil
  1915. (mapcar
  1916. (lambda (x)
  1917. (cond ((stringp (cdr x))
  1918. (push x prefix-descriptions)
  1919. nil)
  1920. ((stringp (nth 1 x)) x)
  1921. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1922. (t (cons (car x) (cons "" (cdr x))))))
  1923. org-agenda-custom-commands)))
  1924. (buf (current-buffer))
  1925. (bfn (buffer-file-name (buffer-base-buffer)))
  1926. entry key type match lprops ans)
  1927. ;; Turn off restriction unless there is an overriding one,
  1928. (unless org-agenda-overriding-restriction
  1929. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1930. ;; There is a request to keep the file list in place
  1931. (put 'org-agenda-files 'org-restrict nil))
  1932. (setq org-agenda-restrict nil)
  1933. (move-marker org-agenda-restrict-begin nil)
  1934. (move-marker org-agenda-restrict-end nil))
  1935. ;; Delete old local properties
  1936. (put 'org-agenda-redo-command 'org-lprops nil)
  1937. ;; Delete previously set last-arguments
  1938. (put 'org-agenda-redo-command 'last-args nil)
  1939. ;; Remember where this call originated
  1940. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1941. (unless keys
  1942. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1943. keys (car ans)
  1944. restriction (cdr ans)))
  1945. ;; Establish the restriction, if any
  1946. (when (and (not org-agenda-overriding-restriction) restriction)
  1947. (put 'org-agenda-files 'org-restrict (list bfn))
  1948. (cond
  1949. ((eq restriction 'region)
  1950. (setq org-agenda-restrict t)
  1951. (move-marker org-agenda-restrict-begin (region-beginning))
  1952. (move-marker org-agenda-restrict-end (region-end)))
  1953. ((eq restriction 'subtree)
  1954. (save-excursion
  1955. (setq org-agenda-restrict t)
  1956. (org-back-to-heading t)
  1957. (move-marker org-agenda-restrict-begin (point))
  1958. (move-marker org-agenda-restrict-end
  1959. (progn (org-end-of-subtree t)))))))
  1960. ;; For example the todo list should not need it (but does...)
  1961. (cond
  1962. ((setq entry (assoc keys org-agenda-custom-commands))
  1963. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1964. (progn
  1965. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1966. lprops (nth 4 entry))
  1967. (put 'org-agenda-redo-command 'org-lprops lprops)
  1968. (cond
  1969. ((eq type 'agenda)
  1970. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1971. ((eq type 'alltodo)
  1972. (org-let lprops '(org-todo-list current-prefix-arg)))
  1973. ((eq type 'search)
  1974. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1975. ((eq type 'stuck)
  1976. (org-let lprops '(org-agenda-list-stuck-projects
  1977. current-prefix-arg)))
  1978. ((eq type 'tags)
  1979. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1980. ((eq type 'tags-todo)
  1981. (org-let lprops '(org-tags-view '(4) match)))
  1982. ((eq type 'todo)
  1983. (org-let lprops '(org-todo-list match)))
  1984. ((eq type 'tags-tree)
  1985. (org-check-for-org-mode)
  1986. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1987. ((eq type 'todo-tree)
  1988. (org-check-for-org-mode)
  1989. (org-let lprops
  1990. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1991. (regexp-quote match) "\\>"))))
  1992. ((eq type 'occur-tree)
  1993. (org-check-for-org-mode)
  1994. (org-let lprops '(org-occur match)))
  1995. ((functionp type)
  1996. (org-let lprops '(funcall type match)))
  1997. ((fboundp type)
  1998. (org-let lprops '(funcall type match)))
  1999. (t (error "Invalid custom agenda command type %s" type))))
  2000. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2001. ((equal keys "C")
  2002. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2003. (customize-variable 'org-agenda-custom-commands))
  2004. ((equal keys "a") (call-interactively 'org-agenda-list))
  2005. ((equal keys "s") (call-interactively 'org-search-view))
  2006. ((equal keys "t") (call-interactively 'org-todo-list))
  2007. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2008. ((equal keys "m") (call-interactively 'org-tags-view))
  2009. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2010. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2011. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2012. (org-add-hook
  2013. 'post-command-hook
  2014. (lambda ()
  2015. (unless (current-message)
  2016. (let* ((m (org-agenda-get-any-marker))
  2017. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2018. (when note
  2019. (message (concat
  2020. "FLAGGING-NOTE ([?] for more info): "
  2021. (org-add-props
  2022. (replace-regexp-in-string
  2023. "\\\\n" "//"
  2024. (copy-sequence note))
  2025. nil 'face 'org-warning)))))))
  2026. t t))
  2027. ((equal keys "L")
  2028. (unless (org-mode-p)
  2029. (error "This is not an Org-mode file"))
  2030. (unless restriction
  2031. (put 'org-agenda-files 'org-restrict (list bfn))
  2032. (org-call-with-arg 'org-timeline arg)))
  2033. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2034. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2035. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2036. (t (error "Invalid agenda key"))))))
  2037. (defun org-agenda-append-agenda ()
  2038. "Append another agenda view to the current one.
  2039. This function allows interactive building of block agendas.
  2040. Agenda views are separated by `org-agenda-block-separator'."
  2041. (interactive)
  2042. (unless (string= (buffer-name) org-agenda-buffer-name)
  2043. (error "Can only append from within agenda buffer"))
  2044. (let ((org-agenda-multi t))
  2045. (org-agenda)
  2046. (widen)))
  2047. (defun org-agenda-normalize-custom-commands (cmds)
  2048. (delq nil
  2049. (mapcar
  2050. (lambda (x)
  2051. (cond ((stringp (cdr x)) nil)
  2052. ((stringp (nth 1 x)) x)
  2053. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2054. (t (cons (car x) (cons "" (cdr x))))))
  2055. cmds)))
  2056. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2057. "The user interface for selecting an agenda command."
  2058. (catch 'exit
  2059. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2060. (restrict-ok (and bfn (org-mode-p)))
  2061. (region-p (org-region-active-p))
  2062. (custom org-agenda-custom-commands)
  2063. (selstring "")
  2064. restriction second-time
  2065. c entry key type match prefixes rmheader header-end custom1 desc
  2066. line lines left right n n1)
  2067. (save-window-excursion
  2068. (delete-other-windows)
  2069. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2070. (erase-buffer)
  2071. (insert (eval-when-compile
  2072. (let ((header
  2073. "
  2074. Press key for an agenda command: < Buffer, subtree/region restriction
  2075. -------------------------------- > Remove restriction
  2076. a Agenda for current week or day e Export agenda views
  2077. t List of all TODO entries T Entries with special TODO kwd
  2078. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2079. L Timeline for current buffer # List stuck projects (!=configure)
  2080. s Search for keywords C Configure custom agenda commands
  2081. / Multi-occur ? Find :FLAGGED: entries
  2082. ")
  2083. (start 0))
  2084. (while (string-match
  2085. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2086. header start)
  2087. (setq start (match-end 0))
  2088. (add-text-properties (match-beginning 2) (match-end 2)
  2089. '(face bold) header))
  2090. header)))
  2091. (setq header-end (move-marker (make-marker) (point)))
  2092. (while t
  2093. (setq custom1 custom)
  2094. (when (eq rmheader t)
  2095. (org-goto-line 1)
  2096. (re-search-forward ":" nil t)
  2097. (delete-region (match-end 0) (point-at-eol))
  2098. (forward-char 1)
  2099. (looking-at "-+")
  2100. (delete-region (match-end 0) (point-at-eol))
  2101. (move-marker header-end (match-end 0)))
  2102. (goto-char header-end)
  2103. (delete-region (point) (point-max))
  2104. ;; Produce all the lines that describe custom commands and prefixes
  2105. (setq lines nil)
  2106. (while (setq entry (pop custom1))
  2107. (setq key (car entry) desc (nth 1 entry)
  2108. type (nth 2 entry)
  2109. match (nth 3 entry))
  2110. (if (> (length key) 1)
  2111. (add-to-list 'prefixes (string-to-char key))
  2112. (setq line
  2113. (format
  2114. "%-4s%-14s"
  2115. (org-add-props (copy-sequence key)
  2116. '(face bold))
  2117. (cond
  2118. ((string-match "\\S-" desc) desc)
  2119. ((eq type 'agenda) "Agenda for current week or day")
  2120. ((eq type 'alltodo) "List of all TODO entries")
  2121. ((eq type 'search) "Word search")
  2122. ((eq type 'stuck) "List of stuck projects")
  2123. ((eq type 'todo) "TODO keyword")
  2124. ((eq type 'tags) "Tags query")
  2125. ((eq type 'tags-todo) "Tags (TODO)")
  2126. ((eq type 'tags-tree) "Tags tree")
  2127. ((eq type 'todo-tree) "TODO kwd tree")
  2128. ((eq type 'occur-tree) "Occur tree")
  2129. ((functionp type) (if (symbolp type)
  2130. (symbol-name type)
  2131. "Lambda expression"))
  2132. (t "???"))))
  2133. (if org-agenda-menu-show-matcher
  2134. (setq line
  2135. (concat line ": "
  2136. (cond
  2137. ((stringp match)
  2138. (setq match (copy-sequence match))
  2139. (org-add-props match nil 'face 'org-warning))
  2140. (match
  2141. (format "set of %d commands" (length match)))
  2142. (t ""))))
  2143. (if (org-string-nw-p match)
  2144. (add-text-properties
  2145. 0 (length line) (list 'help-echo
  2146. (concat "Matcher: "match)) line)))
  2147. (push line lines)))
  2148. (setq lines (nreverse lines))
  2149. (when prefixes
  2150. (mapc (lambda (x)
  2151. (push
  2152. (format "%s %s"
  2153. (org-add-props (char-to-string x)
  2154. nil 'face 'bold)
  2155. (or (cdr (assoc (concat selstring
  2156. (char-to-string x))
  2157. prefix-descriptions))
  2158. "Prefix key"))
  2159. lines))
  2160. prefixes))
  2161. ;; Check if we should display in two columns
  2162. (if org-agenda-menu-two-column
  2163. (progn
  2164. (setq n (length lines)
  2165. n1 (+ (/ n 2) (mod n 2))
  2166. right (nthcdr n1 lines)
  2167. left (copy-sequence lines))
  2168. (setcdr (nthcdr (1- n1) left) nil))
  2169. (setq left lines right nil))
  2170. (while left
  2171. (insert "\n" (pop left))
  2172. (when right
  2173. (if (< (current-column) 40)
  2174. (move-to-column 40 t)
  2175. (insert " "))
  2176. (insert (pop right))))
  2177. ;; Make the window the right size
  2178. (goto-char (point-min))
  2179. (if second-time
  2180. (if (not (pos-visible-in-window-p (point-max)))
  2181. (org-fit-window-to-buffer))
  2182. (setq second-time t)
  2183. (org-fit-window-to-buffer))
  2184. ;; Ask for selection
  2185. (message "Press key for agenda command%s:"
  2186. (if (or restrict-ok org-agenda-overriding-restriction)
  2187. (if org-agenda-overriding-restriction
  2188. " (restriction lock active)"
  2189. (if restriction
  2190. (format " (restricted to %s)" restriction)
  2191. " (unrestricted)"))
  2192. ""))
  2193. (setq c (read-char-exclusive))
  2194. (message "")
  2195. (cond
  2196. ((assoc (char-to-string c) custom)
  2197. (setq selstring (concat selstring (char-to-string c)))
  2198. (throw 'exit (cons selstring restriction)))
  2199. ((memq c prefixes)
  2200. (setq selstring (concat selstring (char-to-string c))
  2201. prefixes nil
  2202. rmheader (or rmheader t)
  2203. custom (delq nil (mapcar
  2204. (lambda (x)
  2205. (if (or (= (length (car x)) 1)
  2206. (/= (string-to-char (car x)) c))
  2207. nil
  2208. (cons (substring (car x) 1) (cdr x))))
  2209. custom))))
  2210. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2211. (message "Restriction is only possible in Org-mode buffers")
  2212. (ding) (sit-for 1))
  2213. ((eq c ?1)
  2214. (org-agenda-remove-restriction-lock 'noupdate)
  2215. (setq restriction 'buffer))
  2216. ((eq c ?0)
  2217. (org-agenda-remove-restriction-lock 'noupdate)
  2218. (setq restriction (if region-p 'region 'subtree)))
  2219. ((eq c ?<)
  2220. (org-agenda-remove-restriction-lock 'noupdate)
  2221. (setq restriction
  2222. (cond
  2223. ((eq restriction 'buffer)
  2224. (if region-p 'region 'subtree))
  2225. ((memq restriction '(subtree region))
  2226. nil)
  2227. (t 'buffer))))
  2228. ((eq c ?>)
  2229. (org-agenda-remove-restriction-lock 'noupdate)
  2230. (setq restriction nil))
  2231. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2232. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2233. ((and (> (length selstring) 0) (eq c ?\d))
  2234. (delete-window)
  2235. (org-agenda-get-restriction-and-command prefix-descriptions))
  2236. ((equal c ?q) (error "Abort"))
  2237. (t (error "Invalid key %c" c))))))))
  2238. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2239. (defvar org-agenda-last-arguments nil
  2240. "The arguments of the previous call to `org-agenda'.")
  2241. (defun org-agenda-run-series (name series)
  2242. (org-let (nth 1 series) '(org-prepare-agenda name))
  2243. (let* ((org-agenda-multi t)
  2244. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2245. (org-agenda-overriding-arguments
  2246. (or org-agenda-overriding-arguments
  2247. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2248. (get 'org-agenda-redo-command 'last-args))))
  2249. (cmds (car series))
  2250. (gprops (nth 1 series))
  2251. match ;; The byte compiler incorrectly complains about this. Keep it!
  2252. cmd type lprops)
  2253. (while (setq cmd (pop cmds))
  2254. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2255. (cond
  2256. ((eq type 'agenda)
  2257. (org-let2 gprops lprops
  2258. '(call-interactively 'org-agenda-list)))
  2259. ((eq type 'alltodo)
  2260. (org-let2 gprops lprops
  2261. '(call-interactively 'org-todo-list)))
  2262. ((eq type 'search)
  2263. (org-let2 gprops lprops
  2264. '(org-search-view current-prefix-arg match nil)))
  2265. ((eq type 'stuck)
  2266. (org-let2 gprops lprops
  2267. '(call-interactively 'org-agenda-list-stuck-projects)))
  2268. ((eq type 'tags)
  2269. (org-let2 gprops lprops
  2270. '(org-tags-view current-prefix-arg match)))
  2271. ((eq type 'tags-todo)
  2272. (org-let2 gprops lprops
  2273. '(org-tags-view '(4) match)))
  2274. ((eq type 'todo)
  2275. (org-let2 gprops lprops
  2276. '(org-todo-list match)))
  2277. ((fboundp type)
  2278. (org-let2 gprops lprops
  2279. '(funcall type match)))
  2280. (t (error "Invalid type in command series"))))
  2281. (widen)
  2282. (setq org-agenda-redo-command redo)
  2283. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2284. (goto-char (point-min)))
  2285. (org-fit-agenda-window)
  2286. (org-let (nth 1 series) '(org-finalize-agenda)))
  2287. ;;;###autoload
  2288. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2289. "Run an agenda command in batch mode and send the result to STDOUT.
  2290. If CMD-KEY is a string of length 1, it is used as a key in
  2291. `org-agenda-custom-commands' and triggers this command. If it is a
  2292. longer string it is used as a tags/todo match string.
  2293. Parameters are alternating variable names and values that will be bound
  2294. before running the agenda command."
  2295. (let (pars)
  2296. (while parameters
  2297. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2298. (if (> (length cmd-key) 2)
  2299. (eval (list 'let (nreverse pars)
  2300. (list 'org-tags-view nil cmd-key)))
  2301. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2302. (set-buffer org-agenda-buffer-name)
  2303. (princ (org-encode-for-stdout (buffer-string)))))
  2304. ;(defun org-encode-for-stdout (string)
  2305. ; (if (fboundp 'encode-coding-string)
  2306. ; (encode-coding-string string buffer-file-coding-system)
  2307. ; string))
  2308. (defun org-encode-for-stdout (string)
  2309. string)
  2310. (defvar org-agenda-info nil)
  2311. ;;;###autoload
  2312. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2313. "Run an agenda command in batch mode and send the result to STDOUT.
  2314. If CMD-KEY is a string of length 1, it is used as a key in
  2315. `org-agenda-custom-commands' and triggers this command. If it is a
  2316. longer string it is used as a tags/todo match string.
  2317. Parameters are alternating variable names and values that will be bound
  2318. before running the agenda command.
  2319. The output gives a line for each selected agenda item. Each
  2320. item is a list of comma-separated values, like this:
  2321. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2322. category The category of the item
  2323. head The headline, without TODO kwd, TAGS and PRIORITY
  2324. type The type of the agenda entry, can be
  2325. todo selected in TODO match
  2326. tagsmatch selected in tags match
  2327. diary imported from diary
  2328. deadline a deadline on given date
  2329. scheduled scheduled on given date
  2330. timestamp entry has timestamp on given date
  2331. closed entry was closed on given date
  2332. upcoming-deadline warning about deadline
  2333. past-scheduled forwarded scheduled item
  2334. block entry has date block including g. date
  2335. todo The todo keyword, if any
  2336. tags All tags including inherited ones, separated by colons
  2337. date The relevant date, like 2007-2-14
  2338. time The time, like 15:00-16:50
  2339. extra Sting with extra planning info
  2340. priority-l The priority letter if any was given
  2341. priority-n The computed numerical priority
  2342. agenda-day The day in the agenda where this is listed"
  2343. (let (pars)
  2344. (while parameters
  2345. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2346. (push (list 'org-agenda-remove-tags t) pars)
  2347. (if (> (length cmd-key) 2)
  2348. (eval (list 'let (nreverse pars)
  2349. (list 'org-tags-view nil cmd-key)))
  2350. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2351. (set-buffer org-agenda-buffer-name)
  2352. (let* ((lines (org-split-string (buffer-string) "\n"))
  2353. line)
  2354. (while (setq line (pop lines))
  2355. (catch 'next
  2356. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2357. (setq org-agenda-info
  2358. (org-fix-agenda-info (text-properties-at 0 line)))
  2359. (princ
  2360. (org-encode-for-stdout
  2361. (mapconcat 'org-agenda-export-csv-mapper
  2362. '(org-category txt type todo tags date time extra
  2363. priority-letter priority agenda-day)
  2364. ",")))
  2365. (princ "\n"))))))
  2366. (defun org-fix-agenda-info (props)
  2367. "Make sure all properties on an agenda item have a canonical form.
  2368. This ensures the export commands can easily use it."
  2369. (let (tmp re)
  2370. (when (setq tmp (plist-get props 'tags))
  2371. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2372. (when (setq tmp (plist-get props 'date))
  2373. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2374. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2375. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2376. (setq tmp (calendar-date-string tmp)))
  2377. (setq props (plist-put props 'date tmp)))
  2378. (when (setq tmp (plist-get props 'day))
  2379. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2380. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2381. (setq tmp (calendar-date-string tmp)))
  2382. (setq props (plist-put props 'day tmp))
  2383. (setq props (plist-put props 'agenda-day tmp)))
  2384. (when (setq tmp (plist-get props 'txt))
  2385. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2386. (plist-put props 'priority-letter (match-string 1 tmp))
  2387. (setq tmp (replace-match "" t t tmp)))
  2388. (when (and (setq re (plist-get props 'org-todo-regexp))
  2389. (setq re (concat "\\`\\.*" re " ?"))
  2390. (string-match re tmp))
  2391. (plist-put props 'todo (match-string 1 tmp))
  2392. (setq tmp (replace-match "" t t tmp)))
  2393. (plist-put props 'txt tmp)))
  2394. props)
  2395. (defun org-agenda-export-csv-mapper (prop)
  2396. (let ((res (plist-get org-agenda-info prop)))
  2397. (setq res
  2398. (cond
  2399. ((not res) "")
  2400. ((stringp res) res)
  2401. (t (prin1-to-string res))))
  2402. (while (string-match "," res)
  2403. (setq res (replace-match ";" t t res)))
  2404. (org-trim res)))
  2405. ;;;###autoload
  2406. (defun org-store-agenda-views (&rest parameters)
  2407. (interactive)
  2408. (eval (list 'org-batch-store-agenda-views)))
  2409. ;; FIXME, why is this a macro?????
  2410. ;;;###autoload
  2411. (defmacro org-batch-store-agenda-views (&rest parameters)
  2412. "Run all custom agenda commands that have a file argument."
  2413. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2414. (pop-up-frames nil)
  2415. (dir default-directory)
  2416. pars cmd thiscmdkey files opts cmd-or-set)
  2417. (while parameters
  2418. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2419. (setq pars (reverse pars))
  2420. (save-window-excursion
  2421. (while cmds
  2422. (setq cmd (pop cmds)
  2423. thiscmdkey (car cmd)
  2424. cmd-or-set (nth 2 cmd)
  2425. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2426. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2427. (if (stringp files) (setq files (list files)))
  2428. (when files
  2429. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2430. (list 'org-agenda nil thiscmdkey)))
  2431. (set-buffer org-agenda-buffer-name)
  2432. (while files
  2433. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2434. (list 'org-write-agenda
  2435. (expand-file-name (pop files) dir) nil t))))
  2436. (and (get-buffer org-agenda-buffer-name)
  2437. (kill-buffer org-agenda-buffer-name)))))))
  2438. (defun org-agenda-mark-header-line (pos)
  2439. "Mark the line at POS as an agenda structure header."
  2440. (save-excursion
  2441. (goto-char pos)
  2442. (put-text-property (point-at-bol) (point-at-eol)
  2443. 'org-agenda-structural-header t)
  2444. (when org-agenda-title-append
  2445. (put-text-property (point-at-bol) (point-at-eol)
  2446. 'org-agenda-title-append org-agenda-title-append))))
  2447. (defvar org-mobile-creating-agendas)
  2448. (defun org-write-agenda (file &optional open nosettings)
  2449. "Write the current buffer (an agenda view) as a file.
  2450. Depending on the extension of the file name, plain text (.txt),
  2451. HTML (.html or .htm) or Postscript (.ps) is produced.
  2452. If the extension is .ics, run icalendar export over all files used
  2453. to construct the agenda and limit the export to entries listed in the
  2454. agenda now.
  2455. With prefix argument OPEN, open the new file immediately.
  2456. If NOSETTINGS is given, do not scope the settings of
  2457. `org-agenda-exporter-settings' into the export commands. This is used when
  2458. the settings have already been scoped and we do not wish to overrule other,
  2459. higher priority settings."
  2460. (interactive "FWrite agenda to file: \nP")
  2461. (if (not (file-writable-p file))
  2462. (error "Cannot write agenda to file %s" file))
  2463. (org-let (if nosettings nil org-agenda-exporter-settings)
  2464. '(save-excursion
  2465. (save-window-excursion
  2466. (org-agenda-mark-filtered-text)
  2467. (let ((bs (copy-sequence (buffer-string))) beg)
  2468. (org-agenda-unmark-filtered-text)
  2469. (with-temp-buffer
  2470. (rename-buffer "Agenda View" t)
  2471. (set-buffer-modified-p nil)
  2472. (insert bs)
  2473. (org-agenda-remove-marked-text 'org-filtered)
  2474. (while (setq beg (text-property-any (point-min) (point-max)
  2475. 'org-filtered t))
  2476. (delete-region
  2477. beg (or (next-single-property-change beg 'org-filtered)
  2478. (point-max))))
  2479. (run-hooks 'org-agenda-before-write-hook)
  2480. (cond
  2481. ((org-bound-and-true-p org-mobile-creating-agendas)
  2482. (org-mobile-write-agenda-for-mobile file))
  2483. ((string-match "\\.html?\\'" file)
  2484. (require 'htmlize)
  2485. (set-buffer (htmlize-buffer (current-buffer)))
  2486. (when (and org-agenda-export-html-style
  2487. (string-match "<style>" org-agenda-export-html-style))
  2488. ;; replace <style> section with org-agenda-export-html-style
  2489. (goto-char (point-min))
  2490. (kill-region (- (search-forward "<style") 6)
  2491. (search-forward "</style>"))
  2492. (insert org-agenda-export-html-style))
  2493. (write-file file)
  2494. (kill-buffer (current-buffer))
  2495. (message "HTML written to %s" file))
  2496. ((string-match "\\.ps\\'" file)
  2497. (require 'ps-print)
  2498. (ps-print-buffer-with-faces file)
  2499. (message "Postscript written to %s" file))
  2500. ((string-match "\\.pdf\\'" file)
  2501. (require 'ps-print)
  2502. (ps-print-buffer-with-faces
  2503. (concat (file-name-sans-extension file) ".ps"))
  2504. (call-process "ps2pdf" nil nil nil
  2505. (expand-file-name
  2506. (concat (file-name-sans-extension file) ".ps"))
  2507. (expand-file-name file))
  2508. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2509. (message "PDF written to %s" file))
  2510. ((string-match "\\.ics\\'" file)
  2511. (require 'org-icalendar)
  2512. (let ((org-agenda-marker-table
  2513. (org-create-marker-find-array
  2514. (org-agenda-collect-markers)))
  2515. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2516. (org-combined-agenda-icalendar-file file))
  2517. (apply 'org-export-icalendar 'combine
  2518. (org-agenda-files nil 'ifmode))))
  2519. (t
  2520. (let ((bs (buffer-string)))
  2521. (find-file file)
  2522. (erase-buffer)
  2523. (insert bs)
  2524. (save-buffer 0)
  2525. (kill-buffer (current-buffer))
  2526. (message "Plain text written to %s" file))))))))
  2527. (set-buffer org-agenda-buffer-name))
  2528. (when open (org-open-file file)))
  2529. (defvar org-agenda-filter-overlays nil)
  2530. (defun org-agenda-mark-filtered-text ()
  2531. "Mark all text hidden by filtering with a text property."
  2532. (let ((inhibit-read-only t))
  2533. (mapc
  2534. (lambda (o)
  2535. (when (equal (overlay-buffer o) (current-buffer))
  2536. (put-text-property
  2537. (overlay-start o) (overlay-end o)
  2538. 'org-filtered t)))
  2539. org-agenda-filter-overlays)))
  2540. (defun org-agenda-unmark-filtered-text ()
  2541. "Remove the filtering text property."
  2542. (let ((inhibit-read-only t))
  2543. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2544. (defun org-agenda-remove-marked-text (property &optional value)
  2545. "Delete all text marked with VALUE of PROPERTY.
  2546. VALUE defaults to t."
  2547. (let (beg)
  2548. (setq value (or value t))
  2549. (while (setq beg (text-property-any (point-min) (point-max)
  2550. property value))
  2551. (delete-region
  2552. beg (or (next-single-property-change beg 'org-filtered)
  2553. (point-max))))))
  2554. (defun org-agenda-add-entry-text ()
  2555. "Add entry text to agenda lines.
  2556. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2557. entry text following headings shown in the agenda.
  2558. Drawers will be excluded, also the line with scheduling/deadline info."
  2559. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2560. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2561. (let (m txt)
  2562. (goto-char (point-min))
  2563. (while (not (eobp))
  2564. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2565. (beginning-of-line 2)
  2566. (setq txt (org-agenda-get-some-entry-text
  2567. m org-agenda-add-entry-text-maxlines " > "))
  2568. (end-of-line 1)
  2569. (if (string-match "\\S-" txt)
  2570. (insert "\n" txt)
  2571. (or (eobp) (forward-char 1))))))))
  2572. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2573. &rest keep)
  2574. "Extract entry text from MARKER, at most N-LINES lines.
  2575. This will ignore drawers etc, just get the text.
  2576. If INDENT is given, prefix every line with this string. If KEEP is
  2577. given, it is a list of symbols, defining stuff that should not be
  2578. removed from the entry content. Currently only `planning' is allowed here."
  2579. (let (txt drawer-re kwd-time-re ind)
  2580. (save-excursion
  2581. (with-current-buffer (marker-buffer marker)
  2582. (if (not (org-mode-p))
  2583. (setq txt "")
  2584. (save-excursion
  2585. (save-restriction
  2586. (widen)
  2587. (goto-char marker)
  2588. (end-of-line 1)
  2589. (setq txt (buffer-substring
  2590. (min (1+ (point)) (point-max))
  2591. (progn (outline-next-heading) (point)))
  2592. drawer-re org-drawer-regexp
  2593. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2594. ".*\n?"))
  2595. (with-temp-buffer
  2596. (insert txt)
  2597. (when org-agenda-add-entry-text-descriptive-links
  2598. (goto-char (point-min))
  2599. (while (org-activate-bracket-links (point-max))
  2600. (add-text-properties (match-beginning 0) (match-end 0)
  2601. '(face org-link))))
  2602. (goto-char (point-min))
  2603. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2604. (set-text-properties (match-beginning 0) (match-end 0)
  2605. nil))
  2606. (goto-char (point-min))
  2607. (while (re-search-forward drawer-re nil t)
  2608. (delete-region
  2609. (match-beginning 0)
  2610. (progn (re-search-forward
  2611. "^[ \t]*:END:.*\n?" nil 'move)
  2612. (point))))
  2613. (unless (member 'planning keep)
  2614. (goto-char (point-min))
  2615. (while (re-search-forward kwd-time-re nil t)
  2616. (replace-match "")))
  2617. (goto-char (point-min))
  2618. (when org-agenda-entry-text-exclude-regexps
  2619. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2620. (while (setq re (pop re-list))
  2621. (goto-char (point-min))
  2622. (while (re-search-forward re nil t)
  2623. (replace-match "")))))
  2624. (goto-char (point-max))
  2625. (skip-chars-backward " \t\n")
  2626. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2627. ;; find and remove min common indentation
  2628. (goto-char (point-min))
  2629. (untabify (point-min) (point-max))
  2630. (setq ind (org-get-indentation))
  2631. (while (not (eobp))
  2632. (unless (looking-at "[ \t]*$")
  2633. (setq ind (min ind (org-get-indentation))))
  2634. (beginning-of-line 2))
  2635. (goto-char (point-min))
  2636. (while (not (eobp))
  2637. (unless (looking-at "[ \t]*$")
  2638. (move-to-column ind)
  2639. (delete-region (point-at-bol) (point)))
  2640. (beginning-of-line 2))
  2641. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2642. (goto-char (point-min))
  2643. (when indent
  2644. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2645. (replace-match indent t t)))
  2646. (goto-char (point-min))
  2647. (while (looking-at "[ \t]*\n") (replace-match ""))
  2648. (goto-char (point-max))
  2649. (when (> (org-current-line)
  2650. n-lines)
  2651. (org-goto-line (1+ n-lines))
  2652. (backward-char 1))
  2653. (setq txt (buffer-substring (point-min) (point)))))))))
  2654. txt))
  2655. (defun org-agenda-collect-markers ()
  2656. "Collect the markers pointing to entries in the agenda buffer."
  2657. (let (m markers)
  2658. (save-excursion
  2659. (goto-char (point-min))
  2660. (while (not (eobp))
  2661. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2662. (org-get-at-bol 'org-marker)))
  2663. (push m markers))
  2664. (beginning-of-line 2)))
  2665. (nreverse markers)))
  2666. (defun org-create-marker-find-array (marker-list)
  2667. "Create a alist of files names with all marker positions in that file."
  2668. (let (f tbl m a p)
  2669. (while (setq m (pop marker-list))
  2670. (setq p (marker-position m)
  2671. f (buffer-file-name (or (buffer-base-buffer
  2672. (marker-buffer m))
  2673. (marker-buffer m))))
  2674. (if (setq a (assoc f tbl))
  2675. (push (marker-position m) (cdr a))
  2676. (push (list f p) tbl)))
  2677. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2678. tbl)))
  2679. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2680. (defun org-check-agenda-marker-table ()
  2681. "Check of the current entry is on the marker list."
  2682. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2683. a)
  2684. (and (setq a (assoc file org-agenda-marker-table))
  2685. (save-match-data
  2686. (save-excursion
  2687. (org-back-to-heading t)
  2688. (member (point) (cdr a)))))))
  2689. (defun org-check-for-org-mode ()
  2690. "Make sure current buffer is in org-mode. Error if not."
  2691. (or (org-mode-p)
  2692. (error "Cannot execute org-mode agenda command on buffer in %s"
  2693. major-mode)))
  2694. (defun org-fit-agenda-window ()
  2695. "Fit the window to the buffer size."
  2696. (and (memq org-agenda-window-setup '(reorganize-frame))
  2697. (fboundp 'fit-window-to-buffer)
  2698. (org-fit-window-to-buffer
  2699. nil
  2700. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2701. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2702. ;;; Agenda prepare and finalize
  2703. (defvar org-agenda-multi nil) ; dynamically scoped
  2704. (defvar org-agenda-buffer-name "*Org Agenda*")
  2705. (defvar org-pre-agenda-window-conf nil)
  2706. (defvar org-agenda-columns-active nil)
  2707. (defvar org-agenda-name nil)
  2708. (defvar org-agenda-filter nil)
  2709. (defvar org-agenda-filter-while-redo nil)
  2710. (defvar org-agenda-filter-preset nil
  2711. "A preset of the tags filter used for secondary agenda filtering.
  2712. This must be a list of strings, each string must be a single tag preceded
  2713. by \"+\" or \"-\".
  2714. This variable should not be set directly, but agenda custom commands can
  2715. bind it in the options section. The preset filter is a global property of
  2716. the entire agenda view. In a block agenda, it will not work reliably to
  2717. define a filter for one of the individual blocks. You need to set it in
  2718. the global options and expect it to be applied to the entire view.")
  2719. (defun org-prepare-agenda (&optional name)
  2720. (setq org-todo-keywords-for-agenda nil)
  2721. (setq org-done-keywords-for-agenda nil)
  2722. (setq org-drawers-for-agenda nil)
  2723. (unless org-agenda-persistent-filter
  2724. (setq org-agenda-filter nil))
  2725. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2726. (if org-agenda-multi
  2727. (progn
  2728. (setq buffer-read-only nil)
  2729. (goto-char (point-max))
  2730. (unless (or (bobp) org-agenda-compact-blocks)
  2731. (insert "\n"
  2732. (if (stringp org-agenda-block-separator)
  2733. org-agenda-block-separator
  2734. (make-string (window-width) org-agenda-block-separator))
  2735. "\n"))
  2736. (narrow-to-region (point) (point-max)))
  2737. (org-agenda-reset-markers)
  2738. (setq org-agenda-contributing-files nil)
  2739. (setq org-agenda-columns-active nil)
  2740. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2741. (setq org-todo-keywords-for-agenda
  2742. (org-uniquify org-todo-keywords-for-agenda))
  2743. (setq org-done-keywords-for-agenda
  2744. (org-uniquify org-done-keywords-for-agenda))
  2745. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2746. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2747. (awin (get-buffer-window abuf)))
  2748. (cond
  2749. ((equal (current-buffer) abuf) nil)
  2750. (awin (select-window awin))
  2751. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2752. ((equal org-agenda-window-setup 'current-window)
  2753. (switch-to-buffer abuf))
  2754. ((equal org-agenda-window-setup 'other-window)
  2755. (org-switch-to-buffer-other-window abuf))
  2756. ((equal org-agenda-window-setup 'other-frame)
  2757. (switch-to-buffer-other-frame abuf))
  2758. ((equal org-agenda-window-setup 'reorganize-frame)
  2759. (delete-other-windows)
  2760. (org-switch-to-buffer-other-window abuf)))
  2761. ;; additional test in case agenda is invoked from within agenda
  2762. ;; buffer via elisp link
  2763. (unless (equal (current-buffer) abuf)
  2764. (switch-to-buffer abuf)))
  2765. (setq buffer-read-only nil)
  2766. (let ((inhibit-read-only t)) (erase-buffer))
  2767. (org-agenda-mode)
  2768. (and name (not org-agenda-name)
  2769. (org-set-local 'org-agenda-name name)))
  2770. (setq buffer-read-only nil))
  2771. (defun org-finalize-agenda ()
  2772. "Finishing touch for the agenda buffer, called just before displaying it."
  2773. (unless org-agenda-multi
  2774. (save-excursion
  2775. (let ((inhibit-read-only t))
  2776. (goto-char (point-min))
  2777. (while (org-activate-bracket-links (point-max))
  2778. (add-text-properties (match-beginning 0) (match-end 0)
  2779. '(face org-link)))
  2780. (org-agenda-align-tags)
  2781. (unless org-agenda-with-colors
  2782. (remove-text-properties (point-min) (point-max) '(face nil))))
  2783. (if (and (boundp 'org-agenda-overriding-columns-format)
  2784. org-agenda-overriding-columns-format)
  2785. (org-set-local 'org-agenda-overriding-columns-format
  2786. org-agenda-overriding-columns-format))
  2787. (if (and (boundp 'org-agenda-view-columns-initially)
  2788. org-agenda-view-columns-initially)
  2789. (org-agenda-columns))
  2790. (when org-agenda-fontify-priorities
  2791. (org-agenda-fontify-priorities))
  2792. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2793. (org-agenda-dim-blocked-tasks))
  2794. (org-agenda-mark-clocking-task)
  2795. (when org-agenda-entry-text-mode
  2796. (org-agenda-entry-text-hide)
  2797. (org-agenda-entry-text-show))
  2798. (if (functionp 'org-habit-insert-consistency-graphs)
  2799. (org-habit-insert-consistency-graphs))
  2800. (run-hooks 'org-finalize-agenda-hook)
  2801. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2802. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2803. (org-agenda-filter-apply org-agenda-filter))
  2804. )))
  2805. (defun org-agenda-mark-clocking-task ()
  2806. "Mark the current clock entry in the agenda if it is present."
  2807. (mapc (lambda (o)
  2808. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2809. (delete-overlay o)))
  2810. (overlays-in (point-min) (point-max)))
  2811. (when (marker-buffer org-clock-hd-marker)
  2812. (save-excursion
  2813. (goto-char (point-min))
  2814. (let (s ov)
  2815. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2816. (goto-char s)
  2817. (when (equal (org-get-at-bol 'org-hd-marker)
  2818. org-clock-hd-marker)
  2819. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2820. (overlay-put ov 'type 'org-agenda-clocking)
  2821. (overlay-put ov 'face 'org-agenda-clocking)
  2822. (overlay-put ov 'help-echo
  2823. "The clock is running in this item")))))))
  2824. (defun org-agenda-fontify-priorities ()
  2825. "Make highest priority lines bold, and lowest italic."
  2826. (interactive)
  2827. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2828. (delete-overlay o)))
  2829. (overlays-in (point-min) (point-max)))
  2830. (save-excursion
  2831. (let ((inhibit-read-only t)
  2832. b e p ov h l)
  2833. (goto-char (point-min))
  2834. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2835. (setq h (or (get-char-property (point) 'org-highest-priority)
  2836. org-highest-priority)
  2837. l (or (get-char-property (point) 'org-lowest-priority)
  2838. org-lowest-priority)
  2839. p (string-to-char (match-string 1))
  2840. b (match-beginning 0)
  2841. e (if (eq org-agenda-fontify-priorities 'cookies)
  2842. (match-end 0)
  2843. (point-at-eol))
  2844. ov (make-overlay b e))
  2845. (overlay-put
  2846. ov 'face
  2847. (cond ((org-face-from-face-or-color
  2848. 'priority nil
  2849. (cdr (assoc p org-priority-faces))))
  2850. ((and (listp org-agenda-fontify-priorities)
  2851. (org-face-from-face-or-color
  2852. 'priority nil
  2853. (cdr (assoc p org-agenda-fontify-priorities)))))
  2854. ((equal p l) 'italic)
  2855. ((equal p h) 'bold)))
  2856. (overlay-put ov 'org-type 'org-priority)))))
  2857. (defun org-agenda-dim-blocked-tasks ()
  2858. "Dim currently blocked TODO's in the agenda display."
  2859. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2860. (delete-overlay o)))
  2861. (overlays-in (point-min) (point-max)))
  2862. (save-excursion
  2863. (let ((inhibit-read-only t)
  2864. (org-depend-tag-blocked nil)
  2865. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2866. org-blocked-by-checkboxes
  2867. invis1 b e p ov h l)
  2868. (goto-char (point-min))
  2869. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2870. (and pos (goto-char (1+ pos))))
  2871. (setq org-blocked-by-checkboxes nil invis1 invis)
  2872. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2873. (when (and marker
  2874. (not (with-current-buffer (marker-buffer marker)
  2875. (save-excursion
  2876. (goto-char marker)
  2877. (if (org-entry-get nil "NOBLOCKING")
  2878. t ;; Never block this entry
  2879. (run-hook-with-args-until-failure
  2880. 'org-blocker-hook
  2881. (list :type 'todo-state-change
  2882. :position marker
  2883. :from 'todo
  2884. :to 'done)))))))
  2885. (if org-blocked-by-checkboxes (setq invis1 nil))
  2886. (setq b (if invis1
  2887. (max (point-min) (1- (point-at-bol)))
  2888. (point-at-bol))
  2889. e (point-at-eol)
  2890. ov (make-overlay b e))
  2891. (if invis1
  2892. (overlay-put ov 'invisible t)
  2893. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2894. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2895. (defvar org-agenda-skip-function nil
  2896. "Function to be called at each match during agenda construction.
  2897. If this function returns nil, the current match should not be skipped.
  2898. Otherwise, the function must return a position from where the search
  2899. should be continued.
  2900. This may also be a Lisp form, it will be evaluated.
  2901. Never set this variable using `setq' or so, because then it will apply
  2902. to all future agenda commands. If you do want a global skipping condition,
  2903. use the option `org-agenda-skip-function-global' instead.
  2904. The correct usage for `org-agenda-skip-function' is to bind it with
  2905. `let' to scope it dynamically into the agenda-constructing command.
  2906. A good way to set it is through options in `org-agenda-custom-commands'.")
  2907. (defun org-agenda-skip ()
  2908. "Throw to `:skip' in places that should be skipped.
  2909. Also moves point to the end of the skipped region, so that search can
  2910. continue from there."
  2911. (let ((p (point-at-bol)) to)
  2912. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2913. (get-text-property p :org-archived)
  2914. (org-end-of-subtree t)
  2915. (throw :skip t))
  2916. (and org-agenda-skip-comment-trees
  2917. (get-text-property p :org-comment)
  2918. (org-end-of-subtree t)
  2919. (throw :skip t))
  2920. (if (equal (char-after p) ?#) (throw :skip t))
  2921. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2922. (org-agenda-skip-eval org-agenda-skip-function)))
  2923. (goto-char to)
  2924. (throw :skip t))))
  2925. (defun org-agenda-skip-eval (form)
  2926. "If FORM is a function or a list, call (or eval) is and return result.
  2927. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2928. and match data are returned to the previous state no matter what these
  2929. functions do."
  2930. (let (fp)
  2931. (and form
  2932. (or (setq fp (functionp form))
  2933. (consp form))
  2934. (save-excursion
  2935. (save-match-data
  2936. (if fp
  2937. (funcall form)
  2938. (eval form)))))))
  2939. (defvar org-agenda-markers nil
  2940. "List of all currently active markers created by `org-agenda'.")
  2941. (defvar org-agenda-last-marker-time (org-float-time)
  2942. "Creation time of the last agenda marker.")
  2943. (defun org-agenda-new-marker (&optional pos)
  2944. "Return a new agenda marker.
  2945. Org-mode keeps a list of these markers and resets them when they are
  2946. no longer in use."
  2947. (let ((m (copy-marker (or pos (point)))))
  2948. (setq org-agenda-last-marker-time (org-float-time))
  2949. (push m org-agenda-markers)
  2950. m))
  2951. (defun org-agenda-reset-markers ()
  2952. "Reset markers created by `org-agenda'."
  2953. (while org-agenda-markers
  2954. (move-marker (pop org-agenda-markers) nil)))
  2955. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2956. "Save relative positions of markers in region."
  2957. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2958. org-agenda-markers))
  2959. ;;; Entry text mode
  2960. (defun org-agenda-entry-text-show-here ()
  2961. "Add some text from the entry as context to the current line."
  2962. (let (m txt o)
  2963. (setq m (org-get-at-bol 'org-hd-marker))
  2964. (unless (marker-buffer m)
  2965. (error "No marker points to an entry here"))
  2966. (setq txt (concat "\n" (org-no-properties
  2967. (org-agenda-get-some-entry-text
  2968. m org-agenda-entry-text-maxlines " > "))))
  2969. (when (string-match "\\S-" txt)
  2970. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2971. (overlay-put o 'evaporate t)
  2972. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2973. (overlay-put o 'after-string txt))))
  2974. (defun org-agenda-entry-text-show ()
  2975. "Add entry context for all agenda lines."
  2976. (interactive)
  2977. (save-excursion
  2978. (goto-char (point-max))
  2979. (beginning-of-line 1)
  2980. (while (not (bobp))
  2981. (when (org-get-at-bol 'org-hd-marker)
  2982. (org-agenda-entry-text-show-here))
  2983. (beginning-of-line 0))))
  2984. (defun org-agenda-entry-text-hide ()
  2985. "Remove any shown entry context."
  2986. (delq nil
  2987. (mapcar (lambda (o)
  2988. (if (eq (overlay-get o 'org-overlay-type)
  2989. 'agenda-entry-content)
  2990. (progn (delete-overlay o) t)))
  2991. (overlays-in (point-min) (point-max)))))
  2992. (defun org-agenda-get-day-face (date)
  2993. "Return the face DATE should be displayed with."
  2994. (or (and (functionp org-agenda-day-face-function)
  2995. (funcall org-agenda-day-face-function date))
  2996. (cond ((org-agenda-todayp date)
  2997. 'org-agenda-date-today)
  2998. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  2999. 'org-agenda-date-weekend)
  3000. (t 'org-agenda-date))))
  3001. ;;; Agenda timeline
  3002. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3003. (defun org-timeline (&optional include-all)
  3004. "Show a time-sorted view of the entries in the current org file.
  3005. Only entries with a time stamp of today or later will be listed. With
  3006. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3007. under the current date.
  3008. If the buffer contains an active region, only check the region for
  3009. dates."
  3010. (interactive "P")
  3011. (org-compile-prefix-format 'timeline)
  3012. (org-set-sorting-strategy 'timeline)
  3013. (let* ((dopast t)
  3014. (dotodo include-all)
  3015. (doclosed org-agenda-show-log)
  3016. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3017. (current-buffer))))
  3018. (date (calendar-current-date))
  3019. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3020. (end (if (org-region-active-p) (region-end) (point-max)))
  3021. (day-numbers (org-get-all-dates beg end 'no-ranges
  3022. t doclosed ; always include today
  3023. org-timeline-show-empty-dates))
  3024. (org-deadline-warning-days 0)
  3025. (org-agenda-only-exact-dates t)
  3026. (today (org-today))
  3027. (past t)
  3028. args
  3029. s e rtn d emptyp)
  3030. (setq org-agenda-redo-command
  3031. (list 'progn
  3032. (list 'org-switch-to-buffer-other-window (current-buffer))
  3033. (list 'org-timeline (list 'quote include-all))))
  3034. (if (not dopast)
  3035. ;; Remove past dates from the list of dates.
  3036. (setq day-numbers (delq nil (mapcar (lambda(x)
  3037. (if (>= x today) x nil))
  3038. day-numbers))))
  3039. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3040. (if doclosed (push :closed args))
  3041. (push :timestamp args)
  3042. (push :deadline args)
  3043. (push :scheduled args)
  3044. (push :sexp args)
  3045. (if dotodo (push :todo args))
  3046. (insert "Timeline of file " entry "\n")
  3047. (add-text-properties (point-min) (point)
  3048. (list 'face 'org-agenda-structure))
  3049. (org-agenda-mark-header-line (point-min))
  3050. (while (setq d (pop day-numbers))
  3051. (if (and (listp d) (eq (car d) :omitted))
  3052. (progn
  3053. (setq s (point))
  3054. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3055. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3056. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3057. (if (and (>= d today)
  3058. dopast
  3059. past)
  3060. (progn
  3061. (setq past nil)
  3062. (insert (make-string 79 ?-) "\n")))
  3063. (setq date (calendar-gregorian-from-absolute d))
  3064. (setq s (point))
  3065. (setq rtn (and (not emptyp)
  3066. (apply 'org-agenda-get-day-entries entry
  3067. date args)))
  3068. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3069. (progn
  3070. (insert
  3071. (if (stringp org-agenda-format-date)
  3072. (format-time-string org-agenda-format-date
  3073. (org-time-from-absolute date))
  3074. (funcall org-agenda-format-date date))
  3075. "\n")
  3076. (put-text-property s (1- (point)) 'face
  3077. (org-agenda-get-day-face date))
  3078. (put-text-property s (1- (point)) 'org-date-line t)
  3079. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3080. (if (equal d today)
  3081. (put-text-property s (1- (point)) 'org-today t))
  3082. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3083. (put-text-property s (1- (point)) 'day d)))))
  3084. (goto-char (point-min))
  3085. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3086. (point-min)))
  3087. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3088. (org-finalize-agenda)
  3089. (setq buffer-read-only t)))
  3090. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3091. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3092. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3093. not every single day in the range. If FORCE-TODAY is non-nil, make
  3094. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3095. inactive time stamps (those in square brackets) are included.
  3096. When EMPTY is non-nil, also include days without any entries."
  3097. (let ((re (concat
  3098. (if pre-re pre-re "")
  3099. (if inactive org-ts-regexp-both org-ts-regexp)))
  3100. dates dates1 date day day1 day2 ts1 ts2)
  3101. (if force-today
  3102. (setq dates (list (org-today))))
  3103. (save-excursion
  3104. (goto-char beg)
  3105. (while (re-search-forward re end t)
  3106. (setq day (time-to-days (org-time-string-to-time
  3107. (substring (match-string 1) 0 10))))
  3108. (or (memq day dates) (push day dates)))
  3109. (unless no-ranges
  3110. (goto-char beg)
  3111. (while (re-search-forward org-tr-regexp end t)
  3112. (setq ts1 (substring (match-string 1) 0 10)
  3113. ts2 (substring (match-string 2) 0 10)
  3114. day1 (time-to-days (org-time-string-to-time ts1))
  3115. day2 (time-to-days (org-time-string-to-time ts2)))
  3116. (while (< (setq day1 (1+ day1)) day2)
  3117. (or (memq day1 dates) (push day1 dates)))))
  3118. (setq dates (sort dates '<))
  3119. (when empty
  3120. (while (setq day (pop dates))
  3121. (setq day2 (car dates))
  3122. (push day dates1)
  3123. (when (and day2 empty)
  3124. (if (or (eq empty t)
  3125. (and (numberp empty) (<= (- day2 day) empty)))
  3126. (while (< (setq day (1+ day)) day2)
  3127. (push (list day) dates1))
  3128. (push (cons :omitted (- day2 day)) dates1))))
  3129. (setq dates (nreverse dates1)))
  3130. dates)))
  3131. ;;; Agenda Daily/Weekly
  3132. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3133. "Custom commands can set this variable in the options section.")
  3134. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3135. (defvar org-agenda-current-span nil
  3136. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3137. (defvar org-include-all-loc nil) ; local variable
  3138. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3139. "List of types searched for when creating the daily/weekly agenda.
  3140. This variable is a list of symbols that controls the types of
  3141. items that appear in the daily/weekly agenda. Allowed symbols in this
  3142. list are are
  3143. :timestamp List items containing a date stamp or date range matching
  3144. the selected date. This includes sexp entries in
  3145. angular brackets.
  3146. :sexp List entries resulting from plain diary-like sexps.
  3147. :deadline List deadline due on that date. When the date is today,
  3148. also list any deadlines past due, or due within
  3149. `org-deadline-warning-days'. `:deadline' must appear before
  3150. `:scheduled' if the setting of
  3151. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3152. any effect.
  3153. :scheduled List all items which are scheduled for the given date.
  3154. The diary for *today* also contains items which were
  3155. scheduled earlier and are not yet marked DONE.
  3156. By default, all four types are turned on.
  3157. Never set this variable globally using `setq', because then it
  3158. will apply to all future agenda commands. Instead, bind it with
  3159. `let' to scope it dynamically into the the agenda-constructing
  3160. command. A good way to set it is through options in
  3161. `org-agenda-custom-commands'. For a more flexible (though
  3162. somewhat less efficient) way of determining what is included in
  3163. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3164. ;;;###autoload
  3165. (defun org-agenda-list (&optional include-all start-day span)
  3166. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3167. The view will be for the current day or week, but from the overview buffer
  3168. you will be able to go to other days/weeks.
  3169. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3170. all unfinished TODO items will also be shown, before the agenda.
  3171. This feature is considered obsolete, please use the TODO list or a block
  3172. agenda instead.
  3173. With a numeric prefix argument in an interactive call, the agenda will
  3174. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3175. the number of days. SPAN defaults to `org-agenda-span'.
  3176. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3177. given in `org-agenda-start-on-weekday'."
  3178. (interactive "P")
  3179. (if (and (integerp include-all) (> include-all 0))
  3180. (setq span include-all include-all nil))
  3181. (setq start-day (or start-day org-agenda-start-day))
  3182. (if org-agenda-overriding-arguments
  3183. (setq include-all (car org-agenda-overriding-arguments)
  3184. start-day (nth 1 org-agenda-overriding-arguments)
  3185. span (nth 2 org-agenda-overriding-arguments)))
  3186. (if (stringp start-day)
  3187. ;; Convert to an absolute day number
  3188. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3189. (setq org-agenda-last-arguments (list include-all start-day span))
  3190. (org-compile-prefix-format 'agenda)
  3191. (org-set-sorting-strategy 'agenda)
  3192. (let* ((span (org-agenda-ndays-to-span
  3193. (or span org-agenda-ndays org-agenda-span)))
  3194. (today (org-today))
  3195. (sd (or start-day today))
  3196. (ndays (org-agenda-span-to-ndays span sd))
  3197. (org-agenda-start-on-weekday
  3198. (if (eq ndays 7)
  3199. org-agenda-start-on-weekday))
  3200. (thefiles (org-agenda-files nil 'ifmode))
  3201. (files thefiles)
  3202. (start (if (or (null org-agenda-start-on-weekday)
  3203. (< ndays 7))
  3204. sd
  3205. (let* ((nt (calendar-day-of-week
  3206. (calendar-gregorian-from-absolute sd)))
  3207. (n1 org-agenda-start-on-weekday)
  3208. (d (- nt n1)))
  3209. (- sd (+ (if (< d 0) 7 0) d)))))
  3210. (day-numbers (list start))
  3211. (day-cnt 0)
  3212. (inhibit-redisplay (not debug-on-error))
  3213. s e rtn rtnall file date d start-pos end-pos todayp
  3214. clocktable-start clocktable-end filter)
  3215. (setq org-agenda-redo-command
  3216. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3217. (dotimes (n (1- ndays))
  3218. (push (1+ (car day-numbers)) day-numbers))
  3219. (setq day-numbers (nreverse day-numbers))
  3220. (setq clocktable-start (car day-numbers)
  3221. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3222. (org-prepare-agenda "Day/Week")
  3223. (org-set-local 'org-starting-day (car day-numbers))
  3224. (org-set-local 'org-include-all-loc include-all)
  3225. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3226. (when (and (or include-all org-agenda-include-all-todo)
  3227. (member today day-numbers))
  3228. (setq files thefiles
  3229. rtnall nil)
  3230. (while (setq file (pop files))
  3231. (catch 'nextfile
  3232. (org-check-agenda-file file)
  3233. (setq date (calendar-gregorian-from-absolute today)
  3234. rtn (org-agenda-get-day-entries
  3235. file date :todo))
  3236. (setq rtnall (append rtnall rtn))))
  3237. (when rtnall
  3238. (insert "All currently open TODO items:\n")
  3239. (add-text-properties (point-min) (1- (point))
  3240. (list 'face 'org-agenda-structure
  3241. 'short-heading "All TODO items"))
  3242. (org-agenda-mark-header-line (point-min))
  3243. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3244. (unless org-agenda-compact-blocks
  3245. (let* ((d1 (car day-numbers))
  3246. (d2 (org-last day-numbers))
  3247. (w1 (org-days-to-iso-week d1))
  3248. (w2 (org-days-to-iso-week d2)))
  3249. (setq s (point))
  3250. (if org-agenda-overriding-header
  3251. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3252. nil 'face 'org-agenda-structure) "\n")
  3253. (insert (org-agenda-span-name span)
  3254. "-agenda"
  3255. (if (< (- d2 d1) 350)
  3256. (if (= w1 w2)
  3257. (format " (W%02d)" w1)
  3258. (format " (W%02d-W%02d)" w1 w2))
  3259. "")
  3260. ":\n")))
  3261. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3262. 'org-date-line t))
  3263. (org-agenda-mark-header-line s))
  3264. (while (setq d (pop day-numbers))
  3265. (setq date (calendar-gregorian-from-absolute d)
  3266. s (point))
  3267. (if (or (setq todayp (= d today))
  3268. (and (not start-pos) (= d sd)))
  3269. (setq start-pos (point))
  3270. (if (and start-pos (not end-pos))
  3271. (setq end-pos (point))))
  3272. (setq files thefiles
  3273. rtnall nil)
  3274. (while (setq file (pop files))
  3275. (catch 'nextfile
  3276. (org-check-agenda-file file)
  3277. (let ((org-agenda-entry-types org-agenda-entry-types))
  3278. (unless org-agenda-include-deadlines
  3279. (setq org-agenda-entry-types
  3280. (delq :deadline org-agenda-entry-types)))
  3281. (cond
  3282. ((eq org-agenda-show-log 'only)
  3283. (setq rtn (org-agenda-get-day-entries
  3284. file date :closed)))
  3285. (org-agenda-show-log
  3286. (setq rtn (apply 'org-agenda-get-day-entries
  3287. file date
  3288. (append '(:closed) org-agenda-entry-types))))
  3289. (t
  3290. (setq rtn (apply 'org-agenda-get-day-entries
  3291. file date
  3292. org-agenda-entry-types)))))
  3293. (setq rtnall (append rtnall rtn))))
  3294. (if org-agenda-include-diary
  3295. (let ((org-agenda-search-headline-for-time t))
  3296. (require 'diary-lib)
  3297. (setq rtn (org-get-entries-from-diary date))
  3298. (setq rtnall (append rtnall rtn))))
  3299. (if (or rtnall org-agenda-show-all-dates)
  3300. (progn
  3301. (setq day-cnt (1+ day-cnt))
  3302. (insert
  3303. (if (stringp org-agenda-format-date)
  3304. (format-time-string org-agenda-format-date
  3305. (org-time-from-absolute date))
  3306. (funcall org-agenda-format-date date))
  3307. "\n")
  3308. (put-text-property s (1- (point)) 'face
  3309. (org-agenda-get-day-face date))
  3310. (put-text-property s (1- (point)) 'org-date-line t)
  3311. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3312. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3313. (when todayp
  3314. (put-text-property s (1- (point)) 'org-today t))
  3315. (if rtnall (insert
  3316. (org-finalize-agenda-entries
  3317. (org-agenda-add-time-grid-maybe
  3318. rtnall ndays todayp))
  3319. "\n"))
  3320. (put-text-property s (1- (point)) 'day d)
  3321. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3322. (when (and org-agenda-clockreport-mode clocktable-start)
  3323. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3324. ;; the above line is to ensure the restricted range!
  3325. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3326. tbl)
  3327. (setq p (org-plist-delete p :block))
  3328. (setq p (plist-put p :tstart clocktable-start))
  3329. (setq p (plist-put p :tend clocktable-end))
  3330. (setq p (plist-put p :scope 'agenda))
  3331. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3332. (setq filter (or org-agenda-filter-while-redo
  3333. (get 'org-agenda-filter :preset-filter))))
  3334. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3335. (if (string-match "[<>=]" x)
  3336. ""
  3337. x))
  3338. filter ""))))
  3339. (setq tbl (apply 'org-get-clocktable p))
  3340. (insert tbl)))
  3341. (goto-char (point-min))
  3342. (or org-agenda-multi (org-fit-agenda-window))
  3343. (unless (and (pos-visible-in-window-p (point-min))
  3344. (pos-visible-in-window-p (point-max)))
  3345. (goto-char (1- (point-max)))
  3346. (recenter -1)
  3347. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3348. (progn
  3349. (goto-char (or start-pos 1))
  3350. (recenter 1))))
  3351. (goto-char (or start-pos 1))
  3352. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3353. (org-finalize-agenda)
  3354. (setq buffer-read-only t)
  3355. (message "")))
  3356. (defun org-agenda-ndays-to-span (n)
  3357. "Return a span symbol for a span of N days, or N if none matches."
  3358. (cond ((symbolp n) n)
  3359. ((= n 1) 'day)
  3360. ((= n 7) 'week)
  3361. (t n)))
  3362. (defun org-agenda-span-to-ndays (span start-day)
  3363. "Return ndays from SPAN starting at START-DAY."
  3364. (cond ((numberp span) span)
  3365. ((eq span 'day) 1)
  3366. ((eq span 'week) 7)
  3367. ((eq span 'month)
  3368. (let ((date (calendar-gregorian-from-absolute start-day)))
  3369. (calendar-last-day-of-month (car date) (caddr date))))
  3370. ((eq span 'year)
  3371. (let ((date (calendar-gregorian-from-absolute start-day)))
  3372. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3373. (defun org-agenda-span-name (span)
  3374. "Return a SPAN name."
  3375. (if (null span)
  3376. ""
  3377. (if (symbolp span)
  3378. (capitalize (symbol-name span))
  3379. (format "%d days" span))))
  3380. ;;; Agenda word search
  3381. (defvar org-agenda-search-history nil)
  3382. (defvar org-todo-only nil)
  3383. (defvar org-search-syntax-table nil
  3384. "Special syntax table for org-mode search.
  3385. In this table, we have single quotes not as word constituents, to
  3386. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3387. (defun org-search-syntax-table ()
  3388. (unless org-search-syntax-table
  3389. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3390. (modify-syntax-entry ?' "." org-search-syntax-table)
  3391. (modify-syntax-entry ?` "." org-search-syntax-table))
  3392. org-search-syntax-table)
  3393. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3394. ;;;###autoload
  3395. (defun org-search-view (&optional todo-only string edit-at)
  3396. "Show all entries that contain a phrase or words or regular expressions.
  3397. With optional prefix argument TODO-ONLY, only consider entries that are
  3398. TODO entries. The argument STRING can be used to pass a default search
  3399. string into this function. If EDIT-AT is non-nil, it means that the
  3400. user should get a chance to edit this string, with cursor at position
  3401. EDIT-AT.
  3402. The search string can be viewed either as a phrase that should be found as
  3403. is, or it can be broken into a number of snippets, each of which must match
  3404. in a Boolean way to select an entry. The default depends on the variable
  3405. `org-agenda-search-view-always-boolean'.
  3406. Even if this is turned off (the default) you can always switch to
  3407. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3408. The default is a direct search of the whole phrase, where each space in
  3409. the search string can expand to an arbitrary amount of whitespace,
  3410. including newlines.
  3411. If using a Boolean search, the search string is split on whitespace and
  3412. each snippet is searched separately, with logical AND to select an entry.
  3413. Words prefixed with a minus must *not* occur in the entry. Words without
  3414. a prefix or prefixed with a plus must occur in the entry. Matching is
  3415. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3416. match whole words, not parts of a word) if
  3417. `org-agenda-search-view-force-full-words' is set (default is nil).
  3418. Boolean search snippets enclosed by curly braces are interpreted as
  3419. regular expressions that must or (when preceded with \"-\") must not
  3420. match in the entry. Snippets enclosed into double quotes will be taken
  3421. as a whole, to include whitespace.
  3422. - If the search string starts with an asterisk, search only in headlines.
  3423. - If (possibly after the leading star) the search string starts with an
  3424. exclamation mark, this also means to look at TODO entries only, an effect
  3425. that can also be achieved with a prefix argument.
  3426. - If (possibly after star and exclamation mark) the search string starts
  3427. with a colon, this will mean that the (non-regexp) snippets of the
  3428. Boolean search must match as full words.
  3429. This command searches the agenda files, and in addition the files listed
  3430. in `org-agenda-text-search-extra-files'."
  3431. (interactive "P")
  3432. (org-compile-prefix-format 'search)
  3433. (org-set-sorting-strategy 'search)
  3434. (org-prepare-agenda "SEARCH")
  3435. (let* ((props (list 'face nil
  3436. 'done-face 'org-agenda-done
  3437. 'org-not-done-regexp org-not-done-regexp
  3438. 'org-todo-regexp org-todo-regexp
  3439. 'org-complex-heading-regexp org-complex-heading-regexp
  3440. 'mouse-face 'highlight
  3441. 'help-echo (format "mouse-2 or RET jump to location")))
  3442. (full-words org-agenda-search-view-force-full-words)
  3443. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3444. regexp rtn rtnall files file pos
  3445. marker category tags c neg re boolean
  3446. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3447. (unless (and (not edit-at)
  3448. (stringp string)
  3449. (string-match "\\S-" string))
  3450. (setq string (read-string
  3451. (if org-agenda-search-view-always-boolean
  3452. "[+-]Word/{Regexp} ...: "
  3453. "Phrase, or [+-]Word/{Regexp} ...: ")
  3454. (cond
  3455. ((integerp edit-at) (cons string edit-at))
  3456. (edit-at string))
  3457. 'org-agenda-search-history)))
  3458. (org-set-local 'org-todo-only todo-only)
  3459. (setq org-agenda-redo-command
  3460. (list 'org-search-view (if todo-only t nil) string
  3461. '(if current-prefix-arg 1 nil)))
  3462. (setq org-agenda-query-string string)
  3463. (if (equal (string-to-char string) ?*)
  3464. (setq hdl-only t
  3465. words (substring string 1))
  3466. (setq words string))
  3467. (when (equal (string-to-char words) ?!)
  3468. (setq todo-only t
  3469. words (substring words 1)))
  3470. (when (equal (string-to-char words) ?:)
  3471. (setq full-words t
  3472. words (substring words 1)))
  3473. (if (or org-agenda-search-view-always-boolean
  3474. (member (string-to-char words) '(?- ?+ ?\{)))
  3475. (setq boolean t))
  3476. (setq words (org-split-string words))
  3477. (let (www w)
  3478. (while (setq w (pop words))
  3479. (while (and (string-match "\\\\\\'" w) words)
  3480. (setq w (concat (substring w 0 -1) " " (pop words))))
  3481. (push w www))
  3482. (setq words (nreverse www) www nil)
  3483. (while (setq w (pop words))
  3484. (when (and (string-match "\\`[-+]?{" w)
  3485. (not (string-match "}\\'" w)))
  3486. (while (and words (not (string-match "}\\'" (car words))))
  3487. (setq w (concat w " " (pop words))))
  3488. (setq w (concat w " " (pop words))))
  3489. (push w www))
  3490. (setq words (nreverse www)))
  3491. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3492. (when boolean
  3493. (let (wds w)
  3494. (while (setq w (pop words))
  3495. (if (or (equal (substring w 0 1) "\"")
  3496. (and (> (length w) 1)
  3497. (member (substring w 0 1) '("+" "-"))
  3498. (equal (substring w 1 2) "\"")))
  3499. (while (and words (not (equal (substring w -1) "\"")))
  3500. (setq w (concat w " " (pop words)))))
  3501. (and (string-match "\\`\\([-+]?\\)\"" w)
  3502. (setq w (replace-match "\\1" nil nil w)))
  3503. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3504. (push w wds))
  3505. (setq words (nreverse wds))))
  3506. (if boolean
  3507. (mapc (lambda (w)
  3508. (setq c (string-to-char w))
  3509. (if (equal c ?-)
  3510. (setq neg t w (substring w 1))
  3511. (if (equal c ?+)
  3512. (setq neg nil w (substring w 1))
  3513. (setq neg nil)))
  3514. (if (string-match "\\`{.*}\\'" w)
  3515. (setq re (substring w 1 -1))
  3516. (if full-words
  3517. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3518. (setq re (regexp-quote (downcase w)))))
  3519. (if neg (push re regexps-) (push re regexps+)))
  3520. words)
  3521. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3522. regexps+))
  3523. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3524. (if (not regexps+)
  3525. (setq regexp (concat "^" org-outline-regexp))
  3526. (setq regexp (pop regexps+))
  3527. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3528. regexp))))
  3529. (setq files (org-agenda-files nil 'ifmode))
  3530. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3531. (pop org-agenda-text-search-extra-files)
  3532. (setq files (org-add-archive-files files)))
  3533. (setq files (append files org-agenda-text-search-extra-files)
  3534. rtnall nil)
  3535. (while (setq file (pop files))
  3536. (setq ee nil)
  3537. (catch 'nextfile
  3538. (org-check-agenda-file file)
  3539. (setq buffer (if (file-exists-p file)
  3540. (org-get-agenda-file-buffer file)
  3541. (error "No such file %s" file)))
  3542. (if (not buffer)
  3543. ;; If file does not exist, make sure an error message is sent
  3544. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3545. file))))
  3546. (with-current-buffer buffer
  3547. (with-syntax-table (org-search-syntax-table)
  3548. (unless (org-mode-p)
  3549. (error "Agenda file %s is not in `org-mode'" file))
  3550. (let ((case-fold-search t))
  3551. (save-excursion
  3552. (save-restriction
  3553. (if org-agenda-restrict
  3554. (narrow-to-region org-agenda-restrict-begin
  3555. org-agenda-restrict-end)
  3556. (widen))
  3557. (goto-char (point-min))
  3558. (unless (or (org-on-heading-p)
  3559. (outline-next-heading))
  3560. (throw 'nextfile t))
  3561. (goto-char (max (point-min) (1- (point))))
  3562. (while (re-search-forward regexp nil t)
  3563. (org-back-to-heading t)
  3564. (skip-chars-forward "* ")
  3565. (setq beg (point-at-bol)
  3566. beg1 (point)
  3567. end (progn (outline-next-heading) (point)))
  3568. (catch :skip
  3569. (goto-char beg)
  3570. (org-agenda-skip)
  3571. (setq str (buffer-substring-no-properties
  3572. (point-at-bol)
  3573. (if hdl-only (point-at-eol) end)))
  3574. (mapc (lambda (wr) (when (string-match wr str)
  3575. (goto-char (1- end))
  3576. (throw :skip t)))
  3577. regexps-)
  3578. (mapc (lambda (wr) (unless (string-match wr str)
  3579. (goto-char (1- end))
  3580. (throw :skip t)))
  3581. (if todo-only
  3582. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3583. regexps+)
  3584. regexps+))
  3585. (goto-char beg)
  3586. (setq marker (org-agenda-new-marker (point))
  3587. category (org-get-category)
  3588. tags (org-get-tags-at (point))
  3589. txt (org-format-agenda-item
  3590. ""
  3591. (buffer-substring-no-properties
  3592. beg1 (point-at-eol))
  3593. category tags))
  3594. (org-add-props txt props
  3595. 'org-marker marker 'org-hd-marker marker
  3596. 'org-todo-regexp org-todo-regexp
  3597. 'org-complex-heading-regexp org-complex-heading-regexp
  3598. 'priority 1000 'org-category category
  3599. 'type "search")
  3600. (push txt ee)
  3601. (goto-char (1- end))))))))))
  3602. (setq rtn (nreverse ee))
  3603. (setq rtnall (append rtnall rtn)))
  3604. (if org-agenda-overriding-header
  3605. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3606. nil 'face 'org-agenda-structure) "\n")
  3607. (insert "Search words: ")
  3608. (add-text-properties (point-min) (1- (point))
  3609. (list 'face 'org-agenda-structure))
  3610. (setq pos (point))
  3611. (insert string "\n")
  3612. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3613. (setq pos (point))
  3614. (unless org-agenda-multi
  3615. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3616. (add-text-properties pos (1- (point))
  3617. (list 'face 'org-agenda-structure))))
  3618. (org-agenda-mark-header-line (point-min))
  3619. (when rtnall
  3620. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3621. (goto-char (point-min))
  3622. (or org-agenda-multi (org-fit-agenda-window))
  3623. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3624. (org-finalize-agenda)
  3625. (setq buffer-read-only t)))
  3626. ;;; Agenda TODO list
  3627. (defvar org-select-this-todo-keyword nil)
  3628. (defvar org-last-arg nil)
  3629. ;;;###autoload
  3630. (defun org-todo-list (arg)
  3631. "Show all (not done) TODO entries from all agenda file in a single list.
  3632. The prefix arg can be used to select a specific TODO keyword and limit
  3633. the list to these. When using \\[universal-argument], you will be prompted
  3634. for a keyword. A numeric prefix directly selects the Nth keyword in
  3635. `org-todo-keywords-1'."
  3636. (interactive "P")
  3637. (org-compile-prefix-format 'todo)
  3638. (org-set-sorting-strategy 'todo)
  3639. (org-prepare-agenda "TODO")
  3640. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3641. (let* ((today (org-today))
  3642. (date (calendar-gregorian-from-absolute today))
  3643. (kwds org-todo-keywords-for-agenda)
  3644. (completion-ignore-case t)
  3645. (org-select-this-todo-keyword
  3646. (if (stringp arg) arg
  3647. (and arg (integerp arg) (> arg 0)
  3648. (nth (1- arg) kwds))))
  3649. rtn rtnall files file pos)
  3650. (when (equal arg '(4))
  3651. (setq org-select-this-todo-keyword
  3652. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3653. (mapcar 'list kwds) nil nil)))
  3654. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3655. (org-set-local 'org-last-arg arg)
  3656. (setq org-agenda-redo-command
  3657. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3658. (setq files (org-agenda-files nil 'ifmode)
  3659. rtnall nil)
  3660. (while (setq file (pop files))
  3661. (catch 'nextfile
  3662. (org-check-agenda-file file)
  3663. (setq rtn (org-agenda-get-day-entries file date :todo))
  3664. (setq rtnall (append rtnall rtn))))
  3665. (if org-agenda-overriding-header
  3666. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3667. nil 'face 'org-agenda-structure) "\n")
  3668. (insert "Global list of TODO items of type: ")
  3669. (add-text-properties (point-min) (1- (point))
  3670. (list 'face 'org-agenda-structure
  3671. 'short-heading
  3672. (concat "ToDo: "
  3673. (or org-select-this-todo-keyword "ALL"))))
  3674. (org-agenda-mark-header-line (point-min))
  3675. (setq pos (point))
  3676. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3677. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3678. (setq pos (point))
  3679. (unless org-agenda-multi
  3680. (insert "Available with `N r': (0)ALL")
  3681. (let ((n 0) s)
  3682. (mapc (lambda (x)
  3683. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3684. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3685. (insert "\n "))
  3686. (insert " " s))
  3687. kwds))
  3688. (insert "\n"))
  3689. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3690. (org-agenda-mark-header-line (point-min))
  3691. (when rtnall
  3692. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3693. (goto-char (point-min))
  3694. (or org-agenda-multi (org-fit-agenda-window))
  3695. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3696. (org-finalize-agenda)
  3697. (setq buffer-read-only t)))
  3698. ;;; Agenda tags match
  3699. ;;;###autoload
  3700. (defun org-tags-view (&optional todo-only match)
  3701. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3702. The prefix arg TODO-ONLY limits the search to TODO entries."
  3703. (interactive "P")
  3704. (org-compile-prefix-format 'tags)
  3705. (org-set-sorting-strategy 'tags)
  3706. (let* ((org-tags-match-list-sublevels
  3707. org-tags-match-list-sublevels)
  3708. (completion-ignore-case t)
  3709. rtn rtnall files file pos matcher
  3710. buffer)
  3711. (when (and (stringp match) (not (string-match "\\S-" match)))
  3712. (setq match nil))
  3713. (setq matcher (org-make-tags-matcher match)
  3714. match (car matcher) matcher (cdr matcher))
  3715. (org-prepare-agenda (concat "TAGS " match))
  3716. (setq org-agenda-query-string match)
  3717. (setq org-agenda-redo-command
  3718. (list 'org-tags-view (list 'quote todo-only)
  3719. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3720. (setq files (org-agenda-files nil 'ifmode)
  3721. rtnall nil)
  3722. (while (setq file (pop files))
  3723. (catch 'nextfile
  3724. (org-check-agenda-file file)
  3725. (setq buffer (if (file-exists-p file)
  3726. (org-get-agenda-file-buffer file)
  3727. (error "No such file %s" file)))
  3728. (if (not buffer)
  3729. ;; If file does not exist, error message to agenda
  3730. (setq rtn (list
  3731. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3732. rtnall (append rtnall rtn))
  3733. (with-current-buffer buffer
  3734. (unless (org-mode-p)
  3735. (error "Agenda file %s is not in `org-mode'" file))
  3736. (save-excursion
  3737. (save-restriction
  3738. (if org-agenda-restrict
  3739. (narrow-to-region org-agenda-restrict-begin
  3740. org-agenda-restrict-end)
  3741. (widen))
  3742. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3743. (setq rtnall (append rtnall rtn))))))))
  3744. (if org-agenda-overriding-header
  3745. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3746. nil 'face 'org-agenda-structure) "\n")
  3747. (insert "Headlines with TAGS match: ")
  3748. (add-text-properties (point-min) (1- (point))
  3749. (list 'face 'org-agenda-structure
  3750. 'short-heading
  3751. (concat "Match: " match)))
  3752. (setq pos (point))
  3753. (insert match "\n")
  3754. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3755. (setq pos (point))
  3756. (unless org-agenda-multi
  3757. (insert "Press `C-u r' to search again with new search string\n"))
  3758. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3759. (org-agenda-mark-header-line (point-min))
  3760. (when rtnall
  3761. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3762. (goto-char (point-min))
  3763. (or org-agenda-multi (org-fit-agenda-window))
  3764. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3765. (org-finalize-agenda)
  3766. (setq buffer-read-only t)))
  3767. ;;; Agenda Finding stuck projects
  3768. (defvar org-agenda-skip-regexp nil
  3769. "Regular expression used in skipping subtrees for the agenda.
  3770. This is basically a temporary global variable that can be set and then
  3771. used by user-defined selections using `org-agenda-skip-function'.")
  3772. (defvar org-agenda-overriding-header nil
  3773. "When this is set during todo and tags searches, will replace header.
  3774. This variable should not be set directly, but custom commands can bind it
  3775. in the options section.")
  3776. (defun org-agenda-skip-entry-when-regexp-matches ()
  3777. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3778. If yes, it returns the end position of this entry, causing agenda commands
  3779. to skip the entry but continuing the search in the subtree. This is a
  3780. function that can be put into `org-agenda-skip-function' for the duration
  3781. of a command."
  3782. (let ((end (save-excursion (org-end-of-subtree t)))
  3783. skip)
  3784. (save-excursion
  3785. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3786. (and skip end)))
  3787. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3788. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3789. If yes, it returns the end position of this tree, causing agenda commands
  3790. to skip this subtree. This is a function that can be put into
  3791. `org-agenda-skip-function' for the duration of a command."
  3792. (let ((end (save-excursion (org-end-of-subtree t)))
  3793. skip)
  3794. (save-excursion
  3795. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3796. (and skip end)))
  3797. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3798. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3799. If yes, it returns the end position of the current entry (NOT the tree),
  3800. causing agenda commands to skip the entry but continuing the search in
  3801. the subtree. This is a function that can be put into
  3802. `org-agenda-skip-function' for the duration of a command. An important
  3803. use of this function is for the stuck project list."
  3804. (let ((end (save-excursion (org-end-of-subtree t)))
  3805. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3806. skip)
  3807. (save-excursion
  3808. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3809. (and skip entry-end)))
  3810. (defun org-agenda-skip-entry-if (&rest conditions)
  3811. "Skip entry if any of CONDITIONS is true.
  3812. See `org-agenda-skip-if' for details."
  3813. (org-agenda-skip-if nil conditions))
  3814. (defun org-agenda-skip-subtree-if (&rest conditions)
  3815. "Skip entry if any of CONDITIONS is true.
  3816. See `org-agenda-skip-if' for details."
  3817. (org-agenda-skip-if t conditions))
  3818. (defun org-agenda-skip-if (subtree conditions)
  3819. "Checks current entity for CONDITIONS.
  3820. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3821. the entry, i.e. the text before the next heading is checked.
  3822. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3823. from different tests. Valid conditions are:
  3824. scheduled Check if there is a scheduled cookie
  3825. notscheduled Check if there is no scheduled cookie
  3826. deadline Check if there is a deadline
  3827. notdeadline Check if there is no deadline
  3828. timestamp Check if there is a timestamp (also deadline or scheduled)
  3829. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3830. regexp Check if regexp matches
  3831. notregexp Check if regexp does not match.
  3832. todo Check if TODO keyword matches
  3833. nottodo Check if TODO keyword does not match
  3834. The regexp is taken from the conditions list, it must come right after
  3835. the `regexp' or `notregexp' element.
  3836. `todo' and `nottodo' accept as an argument a list of todo
  3837. keywords, which may include \"*\" to match any todo keyword.
  3838. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3839. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3840. Instead of a list a keyword class may be given
  3841. (org-agenda-skip-entry-if 'nottodo 'done)
  3842. would skip entries that haven't been marked with any of \"DONE\"
  3843. keywords. Possible classes are: `todo', `done', `any'.
  3844. If any of these conditions is met, this function returns the end point of
  3845. the entity, causing the search to continue from there. This is a function
  3846. that can be put into `org-agenda-skip-function' for the duration of a command."
  3847. (let (beg end m)
  3848. (org-back-to-heading t)
  3849. (setq beg (point)
  3850. end (if subtree
  3851. (progn (org-end-of-subtree t) (point))
  3852. (progn (outline-next-heading) (1- (point)))))
  3853. (goto-char beg)
  3854. (and
  3855. (or
  3856. (and (memq 'scheduled conditions)
  3857. (re-search-forward org-scheduled-time-regexp end t))
  3858. (and (memq 'notscheduled conditions)
  3859. (not (re-search-forward org-scheduled-time-regexp end t)))
  3860. (and (memq 'deadline conditions)
  3861. (re-search-forward org-deadline-time-regexp end t))
  3862. (and (memq 'notdeadline conditions)
  3863. (not (re-search-forward org-deadline-time-regexp end t)))
  3864. (and (memq 'timestamp conditions)
  3865. (re-search-forward org-ts-regexp end t))
  3866. (and (memq 'nottimestamp conditions)
  3867. (not (re-search-forward org-ts-regexp end t)))
  3868. (and (setq m (memq 'regexp conditions))
  3869. (stringp (nth 1 m))
  3870. (re-search-forward (nth 1 m) end t))
  3871. (and (setq m (memq 'notregexp conditions))
  3872. (stringp (nth 1 m))
  3873. (not (re-search-forward (nth 1 m) end t)))
  3874. (and (or
  3875. (setq m (memq 'todo conditions))
  3876. (setq m (memq 'nottodo conditions)))
  3877. (org-agenda-skip-if-todo m end)))
  3878. end)))
  3879. (defun org-agenda-skip-if-todo (args end)
  3880. "Helper function for `org-agenda-skip-if', do not use it directly.
  3881. ARGS is a list with first element either `todo' or `nottodo'.
  3882. The remainder is either a list of TODO keywords, or a state symbol
  3883. `todo' or `done' or `any'."
  3884. (let ((kw (car args))
  3885. (arg (cadr args))
  3886. todo-wds todo-re)
  3887. (setq todo-wds
  3888. (org-uniquify
  3889. (cond
  3890. ((listp arg) ;; list of keywords
  3891. (if (member "*" arg)
  3892. (mapcar 'substring-no-properties org-todo-keywords-1)
  3893. arg))
  3894. ((symbolp arg) ;; keyword class name
  3895. (cond
  3896. ((eq arg 'todo)
  3897. (org-delete-all org-done-keywords
  3898. (mapcar 'substring-no-properties
  3899. org-todo-keywords-1)))
  3900. ((eq arg 'done) org-done-keywords)
  3901. ((eq arg 'any)
  3902. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3903. (setq todo-re
  3904. (concat "^\\*+[ \t]+\\<\\("
  3905. (mapconcat 'identity todo-wds "\\|")
  3906. "\\)\\>"))
  3907. (if (eq kw 'todo)
  3908. (re-search-forward todo-re end t)
  3909. (not (re-search-forward todo-re end t)))))
  3910. ;;;###autoload
  3911. (defun org-agenda-list-stuck-projects (&rest ignore)
  3912. "Create agenda view for projects that are stuck.
  3913. Stuck projects are project that have no next actions. For the definitions
  3914. of what a project is and how to check if it stuck, customize the variable
  3915. `org-stuck-projects'."
  3916. (interactive)
  3917. (let* ((org-agenda-skip-function
  3918. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3919. ;; We could have used org-agenda-skip-if here.
  3920. (org-agenda-overriding-header
  3921. (or org-agenda-overriding-header "List of stuck projects: "))
  3922. (matcher (nth 0 org-stuck-projects))
  3923. (todo (nth 1 org-stuck-projects))
  3924. (todo-wds (if (member "*" todo)
  3925. (progn
  3926. (org-prepare-agenda-buffers (org-agenda-files
  3927. nil 'ifmode))
  3928. (org-delete-all
  3929. org-done-keywords-for-agenda
  3930. (copy-sequence org-todo-keywords-for-agenda)))
  3931. todo))
  3932. (todo-re (concat "^\\*+[ \t]+\\("
  3933. (mapconcat 'identity todo-wds "\\|")
  3934. "\\)\\>"))
  3935. (tags (nth 2 org-stuck-projects))
  3936. (tags-re (if (member "*" tags)
  3937. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3938. (if tags
  3939. (concat "^\\*+ .*:\\("
  3940. (mapconcat 'identity tags "\\|")
  3941. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3942. (gen-re (nth 3 org-stuck-projects))
  3943. (re-list
  3944. (delq nil
  3945. (list
  3946. (if todo todo-re)
  3947. (if tags tags-re)
  3948. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3949. gen-re)))))
  3950. (setq org-agenda-skip-regexp
  3951. (if re-list
  3952. (mapconcat 'identity re-list "\\|")
  3953. (error "No information how to identify unstuck projects")))
  3954. (org-tags-view nil matcher)
  3955. (with-current-buffer org-agenda-buffer-name
  3956. (setq org-agenda-redo-command
  3957. '(org-agenda-list-stuck-projects
  3958. (or current-prefix-arg org-last-arg))))))
  3959. ;;; Diary integration
  3960. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3961. (defvar list-diary-entries-hook)
  3962. (defvar diary-time-regexp)
  3963. (defun org-get-entries-from-diary (date)
  3964. "Get the (Emacs Calendar) diary entries for DATE."
  3965. (require 'diary-lib)
  3966. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3967. (diary-display-hook '(fancy-diary-display))
  3968. (diary-display-function 'fancy-diary-display)
  3969. (pop-up-frames nil)
  3970. (list-diary-entries-hook
  3971. (cons 'org-diary-default-entry list-diary-entries-hook))
  3972. (diary-file-name-prefix-function nil) ; turn this feature off
  3973. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3974. entries
  3975. (org-disable-agenda-to-diary t))
  3976. (save-excursion
  3977. (save-window-excursion
  3978. (funcall (if (fboundp 'diary-list-entries)
  3979. 'diary-list-entries 'list-diary-entries)
  3980. date 1)))
  3981. (if (not (get-buffer diary-fancy-buffer))
  3982. (setq entries nil)
  3983. (with-current-buffer diary-fancy-buffer
  3984. (setq buffer-read-only nil)
  3985. (if (zerop (buffer-size))
  3986. ;; No entries
  3987. (setq entries nil)
  3988. ;; Omit the date and other unnecessary stuff
  3989. (org-agenda-cleanup-fancy-diary)
  3990. ;; Add prefix to each line and extend the text properties
  3991. (if (zerop (buffer-size))
  3992. (setq entries nil)
  3993. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  3994. (setq entries
  3995. (with-temp-buffer
  3996. (insert entries) (goto-char (point-min))
  3997. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  3998. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  3999. (replace-match (concat "; " (match-string 1)))))
  4000. (buffer-string)))))
  4001. (set-buffer-modified-p nil)
  4002. (kill-buffer diary-fancy-buffer)))
  4003. (when entries
  4004. (setq entries (org-split-string entries "\n"))
  4005. (setq entries
  4006. (mapcar
  4007. (lambda (x)
  4008. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4009. ;; Extend the text properties to the beginning of the line
  4010. (org-add-props x (text-properties-at (1- (length x)) x)
  4011. 'type "diary" 'date date 'face 'org-agenda-diary))
  4012. entries)))))
  4013. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4014. "Hook run when the fancy diary buffer is cleaned up.")
  4015. (defun org-agenda-cleanup-fancy-diary ()
  4016. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4017. This gets rid of the date, the underline under the date, and
  4018. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4019. date. It also removes lines that contain only whitespace."
  4020. (goto-char (point-min))
  4021. (if (looking-at ".*?:[ \t]*")
  4022. (progn
  4023. (replace-match "")
  4024. (re-search-forward "\n=+$" nil t)
  4025. (replace-match "")
  4026. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4027. (re-search-forward "\n=+$" nil t)
  4028. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4029. (goto-char (point-min))
  4030. (while (re-search-forward "^ +\n" nil t)
  4031. (replace-match ""))
  4032. (goto-char (point-min))
  4033. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4034. (replace-match ""))
  4035. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4036. ;; Make sure entries from the diary have the right text properties.
  4037. (eval-after-load "diary-lib"
  4038. '(if (boundp 'diary-modify-entry-list-string-function)
  4039. ;; We can rely on the hook, nothing to do
  4040. nil
  4041. ;; Hook not available, must use advice to make this work
  4042. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4043. "Make the position visible."
  4044. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4045. (stringp string)
  4046. buffer-file-name)
  4047. (setq string (org-modify-diary-entry-string string))))))
  4048. (defun org-modify-diary-entry-string (string)
  4049. "Add text properties to string, allowing org-mode to act on it."
  4050. (org-add-props string nil
  4051. 'mouse-face 'highlight
  4052. 'help-echo (if buffer-file-name
  4053. (format "mouse-2 or RET jump to diary file %s"
  4054. (abbreviate-file-name buffer-file-name))
  4055. "")
  4056. 'org-agenda-diary-link t
  4057. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4058. (defun org-diary-default-entry ()
  4059. "Add a dummy entry to the diary.
  4060. Needed to avoid empty dates which mess up holiday display."
  4061. ;; Catch the error if dealing with the new add-to-diary-alist
  4062. (when org-disable-agenda-to-diary
  4063. (condition-case nil
  4064. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4065. (error
  4066. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4067. (defun org-add-to-diary-list (&rest args)
  4068. (if (fboundp 'diary-add-to-list)
  4069. (apply 'diary-add-to-list args)
  4070. (apply 'add-to-diary-list args)))
  4071. (defvar org-diary-last-run-time nil)
  4072. ;;;###autoload
  4073. (defun org-diary (&rest args)
  4074. "Return diary information from org-files.
  4075. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4076. It accesses org files and extracts information from those files to be
  4077. listed in the diary. The function accepts arguments specifying what
  4078. items should be listed. For a list of arguments allowed here, see the
  4079. variable `org-agenda-entry-types'.
  4080. The call in the diary file should look like this:
  4081. &%%(org-diary) ~/path/to/some/orgfile.org
  4082. Use a separate line for each org file to check. Or, if you omit the file name,
  4083. all files listed in `org-agenda-files' will be checked automatically:
  4084. &%%(org-diary)
  4085. If you don't give any arguments (as in the example above), the default
  4086. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4087. So the example above may also be written as
  4088. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4089. The function expects the lisp variables `entry' and `date' to be provided
  4090. by the caller, because this is how the calendar works. Don't use this
  4091. function from a program - use `org-agenda-get-day-entries' instead."
  4092. (when (> (- (org-float-time)
  4093. org-agenda-last-marker-time)
  4094. 5)
  4095. (org-agenda-reset-markers))
  4096. (org-compile-prefix-format 'agenda)
  4097. (org-set-sorting-strategy 'agenda)
  4098. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4099. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4100. (list entry)
  4101. (org-agenda-files t)))
  4102. (time (org-float-time))
  4103. file rtn results)
  4104. (when (or (not org-diary-last-run-time)
  4105. (> (- time
  4106. org-diary-last-run-time)
  4107. 3))
  4108. (org-prepare-agenda-buffers files))
  4109. (setq org-diary-last-run-time time)
  4110. ;; If this is called during org-agenda, don't return any entries to
  4111. ;; the calendar. Org Agenda will list these entries itself.
  4112. (if org-disable-agenda-to-diary (setq files nil))
  4113. (while (setq file (pop files))
  4114. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4115. (setq results (append results rtn)))
  4116. (if results
  4117. (concat (org-finalize-agenda-entries results) "\n"))))
  4118. ;;; Agenda entry finders
  4119. (defun org-agenda-get-day-entries (file date &rest args)
  4120. "Does the work for `org-diary' and `org-agenda'.
  4121. FILE is the path to a file to be checked for entries. DATE is date like
  4122. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4123. which kind of entries should be extracted. For details about these, see
  4124. the documentation of `org-diary'."
  4125. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4126. (let* ((org-startup-folded nil)
  4127. (org-startup-align-all-tables nil)
  4128. (buffer (if (file-exists-p file)
  4129. (org-get-agenda-file-buffer file)
  4130. (error "No such file %s" file)))
  4131. arg results rtn deadline-results)
  4132. (if (not buffer)
  4133. ;; If file does not exist, make sure an error message ends up in diary
  4134. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4135. (with-current-buffer buffer
  4136. (unless (org-mode-p)
  4137. (error "Agenda file %s is not in `org-mode'" file))
  4138. (let ((case-fold-search nil))
  4139. (save-excursion
  4140. (save-restriction
  4141. (if org-agenda-restrict
  4142. (narrow-to-region org-agenda-restrict-begin
  4143. org-agenda-restrict-end)
  4144. (widen))
  4145. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4146. (while (setq arg (pop args))
  4147. (cond
  4148. ((and (eq arg :todo)
  4149. (equal date (calendar-gregorian-from-absolute
  4150. (org-today))))
  4151. (setq rtn (org-agenda-get-todos))
  4152. (setq results (append results rtn)))
  4153. ((eq arg :timestamp)
  4154. (setq rtn (org-agenda-get-blocks))
  4155. (setq results (append results rtn))
  4156. (setq rtn (org-agenda-get-timestamps))
  4157. (setq results (append results rtn)))
  4158. ((eq arg :sexp)
  4159. (setq rtn (org-agenda-get-sexps))
  4160. (setq results (append results rtn)))
  4161. ((eq arg :scheduled)
  4162. (setq rtn (org-agenda-get-scheduled deadline-results))
  4163. (setq results (append results rtn)))
  4164. ((eq arg :closed)
  4165. (setq rtn (org-agenda-get-progress))
  4166. (setq results (append results rtn)))
  4167. ((eq arg :deadline)
  4168. (setq rtn (org-agenda-get-deadlines))
  4169. (setq deadline-results (copy-sequence rtn))
  4170. (setq results (append results rtn))))))))
  4171. results))))
  4172. (defun org-agenda-get-todos ()
  4173. "Return the TODO information for agenda display."
  4174. (let* ((props (list 'face nil
  4175. 'done-face 'org-agenda-done
  4176. 'org-not-done-regexp org-not-done-regexp
  4177. 'org-todo-regexp org-todo-regexp
  4178. 'org-complex-heading-regexp org-complex-heading-regexp
  4179. 'mouse-face 'highlight
  4180. 'help-echo
  4181. (format "mouse-2 or RET jump to org file %s"
  4182. (abbreviate-file-name buffer-file-name))))
  4183. (regexp (concat "^\\*+[ \t]+\\("
  4184. (if org-select-this-todo-keyword
  4185. (if (equal org-select-this-todo-keyword "*")
  4186. org-todo-regexp
  4187. (concat "\\<\\("
  4188. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4189. "\\)\\>"))
  4190. org-not-done-regexp)
  4191. "[^\n\r]*\\)"))
  4192. marker priority category tags todo-state
  4193. ee txt beg end)
  4194. (goto-char (point-min))
  4195. (while (re-search-forward regexp nil t)
  4196. (catch :skip
  4197. (save-match-data
  4198. (beginning-of-line)
  4199. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4200. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4201. (goto-char (1+ beg))
  4202. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4203. (throw :skip nil)))
  4204. (goto-char beg)
  4205. (org-agenda-skip)
  4206. (goto-char (match-beginning 1))
  4207. (setq marker (org-agenda-new-marker (match-beginning 0))
  4208. category (org-get-category)
  4209. txt (match-string 1)
  4210. tags (org-get-tags-at (point))
  4211. txt (org-format-agenda-item "" txt category tags)
  4212. priority (1+ (org-get-priority txt))
  4213. todo-state (org-get-todo-state))
  4214. (org-add-props txt props
  4215. 'org-marker marker 'org-hd-marker marker
  4216. 'priority priority 'org-category category
  4217. 'type "todo" 'todo-state todo-state)
  4218. (push txt ee)
  4219. (if org-agenda-todo-list-sublevels
  4220. (goto-char (match-end 1))
  4221. (org-end-of-subtree 'invisible))))
  4222. (nreverse ee)))
  4223. (defun org-agenda-todo-custom-ignore-p (time n)
  4224. "Check whether timestamp is farther away then n number of days.
  4225. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4226. `org-agenda-todo-ignore-scheduled' or
  4227. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4228. (let ((days (org-days-to-time time)))
  4229. (if (>= n 0)
  4230. (>= days n)
  4231. (<= days n))))
  4232. ;;;###autoload
  4233. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4234. (&optional end)
  4235. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4236. (when (or org-agenda-todo-ignore-with-date
  4237. org-agenda-todo-ignore-scheduled
  4238. org-agenda-todo-ignore-deadlines
  4239. org-agenda-todo-ignore-timestamp)
  4240. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4241. (save-excursion
  4242. (or (and org-agenda-todo-ignore-with-date
  4243. (re-search-forward org-ts-regexp end t))
  4244. (and org-agenda-todo-ignore-scheduled
  4245. (re-search-forward org-scheduled-time-regexp end t)
  4246. (cond
  4247. ((eq org-agenda-todo-ignore-scheduled 'future)
  4248. (> (org-days-to-time (match-string 1)) 0))
  4249. ((eq org-agenda-todo-ignore-scheduled 'past)
  4250. (<= (org-days-to-time (match-string 1)) 0))
  4251. ((numberp org-agenda-todo-ignore-scheduled)
  4252. (org-agenda-todo-custom-ignore-p
  4253. (match-string 1) org-agenda-todo-ignore-scheduled))
  4254. (t)))
  4255. (and org-agenda-todo-ignore-deadlines
  4256. (re-search-forward org-deadline-time-regexp end t)
  4257. (cond
  4258. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4259. ((eq org-agenda-todo-ignore-deadlines 'far)
  4260. (not (org-deadline-close (match-string 1))))
  4261. ((eq org-agenda-todo-ignore-deadlines 'future)
  4262. (> (org-days-to-time (match-string 1)) 0))
  4263. ((eq org-agenda-todo-ignore-deadlines 'past)
  4264. (<= (org-days-to-time (match-string 1)) 0))
  4265. ((numberp org-agenda-todo-ignore-deadlines)
  4266. (org-agenda-todo-custom-ignore-p
  4267. (match-string 1) org-agenda-todo-ignore-deadlines))
  4268. (t (org-deadline-close (match-string 1)))))
  4269. (and org-agenda-todo-ignore-timestamp
  4270. (let ((buffer (current-buffer))
  4271. (regexp
  4272. (concat
  4273. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4274. (start (point)))
  4275. ;; Copy current buffer into a temporary one
  4276. (with-temp-buffer
  4277. (insert-buffer-substring buffer start end)
  4278. (goto-char (point-min))
  4279. ;; Delete SCHEDULED and DEADLINE items
  4280. (while (re-search-forward regexp end t)
  4281. (delete-region (match-beginning 0) (match-end 0)))
  4282. (goto-char (point-min))
  4283. ;; No search for timestamp left
  4284. (when (re-search-forward org-ts-regexp nil t)
  4285. (cond
  4286. ((eq org-agenda-todo-ignore-timestamp 'future)
  4287. (> (org-days-to-time (match-string 1)) 0))
  4288. ((eq org-agenda-todo-ignore-timestamp 'past)
  4289. (<= (org-days-to-time (match-string 1)) 0))
  4290. ((numberp org-agenda-todo-ignore-timestamp)
  4291. (org-agenda-todo-custom-ignore-p
  4292. (match-string 1) org-agenda-todo-ignore-timestamp))
  4293. (t))))))))))
  4294. (defconst org-agenda-no-heading-message
  4295. "No heading for this item in buffer or region.")
  4296. (defun org-agenda-get-timestamps ()
  4297. "Return the date stamp information for agenda display."
  4298. (let* ((props (list 'face nil
  4299. 'org-not-done-regexp org-not-done-regexp
  4300. 'org-todo-regexp org-todo-regexp
  4301. 'org-complex-heading-regexp org-complex-heading-regexp
  4302. 'mouse-face 'highlight
  4303. 'help-echo
  4304. (format "mouse-2 or RET jump to org file %s"
  4305. (abbreviate-file-name buffer-file-name))))
  4306. (d1 (calendar-absolute-from-gregorian date))
  4307. (remove-re
  4308. (concat
  4309. (regexp-quote
  4310. (format-time-string
  4311. "<%Y-%m-%d"
  4312. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4313. ".*?>"))
  4314. (regexp
  4315. (concat
  4316. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4317. (regexp-quote
  4318. (substring
  4319. (format-time-string
  4320. (car org-time-stamp-formats)
  4321. (apply 'encode-time ; DATE bound by calendar
  4322. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4323. 1 11))
  4324. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4325. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4326. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4327. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4328. todo-state end-of-match show-all)
  4329. (goto-char (point-min))
  4330. (while (setq end-of-match (re-search-forward regexp nil t))
  4331. (setq b0 (match-beginning 0)
  4332. b3 (match-beginning 3) e3 (match-end 3)
  4333. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4334. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4335. (member todo-state
  4336. org-agenda-repeating-timestamp-show-all)))
  4337. (catch :skip
  4338. (and (org-at-date-range-p) (throw :skip nil))
  4339. (org-agenda-skip)
  4340. (if (and (match-end 1)
  4341. (not (= d1 (org-time-string-to-absolute
  4342. (match-string 1) d1 nil show-all))))
  4343. (throw :skip nil))
  4344. (if (and e3
  4345. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4346. (throw :skip nil))
  4347. (setq tmp (buffer-substring (max (point-min)
  4348. (- b0 org-ds-keyword-length))
  4349. b0)
  4350. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4351. inactivep (= (char-after b0) ?\[)
  4352. deadlinep (string-match org-deadline-regexp tmp)
  4353. scheduledp (string-match org-scheduled-regexp tmp)
  4354. closedp (and org-agenda-include-inactive-timestamps
  4355. (string-match org-closed-string tmp))
  4356. clockp (and org-agenda-include-inactive-timestamps
  4357. (or (string-match org-clock-string tmp)
  4358. (string-match "]-+\\'" tmp)))
  4359. donep (member todo-state org-done-keywords))
  4360. (if (or scheduledp deadlinep closedp clockp
  4361. (and donep org-agenda-skip-timestamp-if-done))
  4362. (throw :skip t))
  4363. (if (string-match ">" timestr)
  4364. ;; substring should only run to end of time stamp
  4365. (setq timestr (substring timestr 0 (match-end 0))))
  4366. (setq marker (org-agenda-new-marker b0)
  4367. category (org-get-category b0))
  4368. (save-excursion
  4369. (if (not (re-search-backward "^\\*+ " nil t))
  4370. (setq txt org-agenda-no-heading-message)
  4371. (goto-char (match-beginning 0))
  4372. (setq hdmarker (org-agenda-new-marker)
  4373. tags (org-get-tags-at))
  4374. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4375. (setq head (match-string 1))
  4376. (setq txt (org-format-agenda-item
  4377. (if inactivep org-agenda-inactive-leader nil)
  4378. head category tags timestr nil
  4379. remove-re)))
  4380. (setq priority (org-get-priority txt))
  4381. (org-add-props txt props
  4382. 'org-marker marker 'org-hd-marker hdmarker)
  4383. (org-add-props txt nil 'priority priority
  4384. 'org-category category 'date date
  4385. 'todo-state todo-state
  4386. 'type "timestamp")
  4387. (push txt ee))
  4388. (if org-agenda-skip-additional-timestamps-same-entry
  4389. (outline-next-heading)
  4390. (goto-char end-of-match))))
  4391. (nreverse ee)))
  4392. (defun org-agenda-get-sexps ()
  4393. "Return the sexp information for agenda display."
  4394. (require 'diary-lib)
  4395. (let* ((props (list 'mouse-face 'highlight
  4396. 'help-echo
  4397. (format "mouse-2 or RET jump to org file %s"
  4398. (abbreviate-file-name buffer-file-name))))
  4399. (regexp "^&?%%(")
  4400. marker category ee txt tags entry result beg b sexp sexp-entry
  4401. todo-state)
  4402. (goto-char (point-min))
  4403. (while (re-search-forward regexp nil t)
  4404. (catch :skip
  4405. (org-agenda-skip)
  4406. (setq beg (match-beginning 0))
  4407. (goto-char (1- (match-end 0)))
  4408. (setq b (point))
  4409. (forward-sexp 1)
  4410. (setq sexp (buffer-substring b (point)))
  4411. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4412. (org-trim (match-string 1))
  4413. ""))
  4414. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4415. (when result
  4416. (setq marker (org-agenda-new-marker beg)
  4417. category (org-get-category beg)
  4418. todo-state (org-get-todo-state))
  4419. (dolist (r (if (stringp result)
  4420. (list result)
  4421. result)) ;; we expect a list here
  4422. (if (string-match "\\S-" r)
  4423. (setq txt r)
  4424. (setq txt "SEXP entry returned empty string"))
  4425. (setq txt (org-format-agenda-item
  4426. "" txt category tags 'time))
  4427. (org-add-props txt props 'org-marker marker)
  4428. (org-add-props txt nil
  4429. 'org-category category 'date date 'todo-state todo-state
  4430. 'type "sexp")
  4431. (push txt ee)))))
  4432. (nreverse ee)))
  4433. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4434. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4435. The order of the first 2 times 3 arguments depends on the variable
  4436. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4437. So for American calendars, give this as MONTH DAY YEAR, for European as
  4438. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4439. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4440. is any number of ISO weeks in the block period for which the item should
  4441. be skipped."
  4442. (let* ((date1 (calendar-absolute-from-gregorian
  4443. (org-order-calendar-date-args m1 d1 y1)))
  4444. (date2 (calendar-absolute-from-gregorian
  4445. (org-order-calendar-date-args m2 d2 y2)))
  4446. (d (calendar-absolute-from-gregorian date)))
  4447. (and
  4448. (<= date1 d)
  4449. (<= d date2)
  4450. (= (calendar-day-of-week date) dayname)
  4451. (or (not skip-weeks)
  4452. (progn
  4453. (require 'cal-iso)
  4454. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4455. entry)))
  4456. (defalias 'org-get-closed 'org-agenda-get-progress)
  4457. (defun org-agenda-get-progress ()
  4458. "Return the logged TODO entries for agenda display."
  4459. (let* ((props (list 'mouse-face 'highlight
  4460. 'org-not-done-regexp org-not-done-regexp
  4461. 'org-todo-regexp org-todo-regexp
  4462. 'org-complex-heading-regexp org-complex-heading-regexp
  4463. 'help-echo
  4464. (format "mouse-2 or RET jump to org file %s"
  4465. (abbreviate-file-name buffer-file-name))))
  4466. (items (if (consp org-agenda-show-log)
  4467. org-agenda-show-log
  4468. org-agenda-log-mode-items))
  4469. (parts
  4470. (delq nil
  4471. (list
  4472. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4473. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4474. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4475. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4476. (error "`org-agenda-log-mode-items' is empty")))
  4477. (regexp (concat
  4478. "\\(" parts-re "\\)"
  4479. " *\\["
  4480. (regexp-quote
  4481. (substring
  4482. (format-time-string
  4483. (car org-time-stamp-formats)
  4484. (apply 'encode-time ; DATE bound by calendar
  4485. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4486. 1 11))))
  4487. (org-agenda-search-headline-for-time nil)
  4488. marker hdmarker priority category tags closedp statep clockp state
  4489. ee txt extra timestr rest clocked)
  4490. (goto-char (point-min))
  4491. (while (re-search-forward regexp nil t)
  4492. (catch :skip
  4493. (org-agenda-skip)
  4494. (setq marker (org-agenda-new-marker (match-beginning 0))
  4495. closedp (equal (match-string 1) org-closed-string)
  4496. statep (equal (string-to-char (match-string 1)) ?-)
  4497. clockp (not (or closedp statep))
  4498. state (and statep (match-string 2))
  4499. category (org-get-category (match-beginning 0))
  4500. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4501. )
  4502. (when (string-match "\\]" timestr)
  4503. ;; substring should only run to end of time stamp
  4504. (setq rest (substring timestr (match-end 0))
  4505. timestr (substring timestr 0 (match-end 0)))
  4506. (if (and (not closedp) (not statep)
  4507. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4508. (progn (setq timestr (concat (substring timestr 0 -1)
  4509. "-" (match-string 1 rest) "]"))
  4510. (setq clocked (match-string 2 rest)))
  4511. (setq clocked "-")))
  4512. (save-excursion
  4513. (setq extra
  4514. (cond
  4515. ((not org-agenda-log-mode-add-notes) nil)
  4516. (statep
  4517. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4518. (match-string 1)))
  4519. (clockp
  4520. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4521. (match-string 1)))))
  4522. (if (not (re-search-backward "^\\*+ " nil t))
  4523. (setq txt org-agenda-no-heading-message)
  4524. (goto-char (match-beginning 0))
  4525. (setq hdmarker (org-agenda-new-marker)
  4526. tags (org-get-tags-at))
  4527. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4528. (setq txt (match-string 1))
  4529. (when extra
  4530. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4531. (setq txt (concat (substring txt 0 (match-beginning 1))
  4532. " - " extra " " (match-string 2 txt)))
  4533. (setq txt (concat txt " - " extra))))
  4534. (setq txt (org-format-agenda-item
  4535. (cond
  4536. (closedp "Closed: ")
  4537. (statep (concat "State: (" state ")"))
  4538. (t (concat "Clocked: (" clocked ")")))
  4539. txt category tags timestr)))
  4540. (setq priority 100000)
  4541. (org-add-props txt props
  4542. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4543. 'priority priority 'org-category category
  4544. 'type "closed" 'date date
  4545. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4546. (push txt ee))
  4547. (goto-char (point-at-eol))))
  4548. (nreverse ee)))
  4549. (defun org-agenda-get-deadlines ()
  4550. "Return the deadline information for agenda display."
  4551. (let* ((props (list 'mouse-face 'highlight
  4552. 'org-not-done-regexp org-not-done-regexp
  4553. 'org-todo-regexp org-todo-regexp
  4554. 'org-complex-heading-regexp org-complex-heading-regexp
  4555. 'help-echo
  4556. (format "mouse-2 or RET jump to org file %s"
  4557. (abbreviate-file-name buffer-file-name))))
  4558. (regexp org-deadline-time-regexp)
  4559. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4560. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4561. d2 diff dfrac wdays pos pos1 category tags
  4562. suppress-prewarning
  4563. ee txt head face s todo-state show-all upcomingp donep timestr)
  4564. (goto-char (point-min))
  4565. (while (re-search-forward regexp nil t)
  4566. (setq suppress-prewarning nil)
  4567. (catch :skip
  4568. (org-agenda-skip)
  4569. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4570. (save-match-data
  4571. (string-match org-scheduled-time-regexp
  4572. (buffer-substring (point-at-bol)
  4573. (point-at-eol)))))
  4574. (setq suppress-prewarning
  4575. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4576. org-agenda-skip-deadline-prewarning-if-scheduled
  4577. 0)))
  4578. (setq s (match-string 1)
  4579. txt nil
  4580. pos (1- (match-beginning 1))
  4581. todo-state (save-match-data (org-get-todo-state))
  4582. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4583. (member todo-state
  4584. org-agenda-repeating-timestamp-show-all))
  4585. d2 (org-time-string-to-absolute
  4586. (match-string 1) d1 'past show-all)
  4587. diff (- d2 d1)
  4588. wdays (if suppress-prewarning
  4589. (let ((org-deadline-warning-days suppress-prewarning))
  4590. (org-get-wdays s))
  4591. (org-get-wdays s))
  4592. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4593. upcomingp (and todayp (> diff 0)))
  4594. ;; When to show a deadline in the calendar:
  4595. ;; If the expiration is within wdays warning time.
  4596. ;; Past-due deadlines are only shown on the current date
  4597. (if (and (or (and (<= diff wdays)
  4598. (and todayp (not org-agenda-only-exact-dates)))
  4599. (= diff 0)))
  4600. (save-excursion
  4601. ;; (setq todo-state (org-get-todo-state))
  4602. (setq donep (member todo-state org-done-keywords))
  4603. (if (and donep
  4604. (or org-agenda-skip-deadline-if-done
  4605. (not (= diff 0))))
  4606. (setq txt nil)
  4607. (setq category (org-get-category))
  4608. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4609. (setq txt org-agenda-no-heading-message)
  4610. (goto-char (match-end 0))
  4611. (setq pos1 (match-beginning 0))
  4612. (setq tags (org-get-tags-at pos1))
  4613. (setq head (buffer-substring-no-properties
  4614. (point)
  4615. (progn (skip-chars-forward "^\r\n")
  4616. (point))))
  4617. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4618. (setq timestr
  4619. (concat (substring s (match-beginning 1)) " "))
  4620. (setq timestr 'time))
  4621. (setq txt (org-format-agenda-item
  4622. (if (= diff 0)
  4623. (car org-agenda-deadline-leaders)
  4624. (if (functionp
  4625. (nth 1 org-agenda-deadline-leaders))
  4626. (funcall
  4627. (nth 1 org-agenda-deadline-leaders)
  4628. diff date)
  4629. (format (nth 1 org-agenda-deadline-leaders)
  4630. diff)))
  4631. head category tags
  4632. (if (not (= diff 0)) nil timestr)))))
  4633. (when txt
  4634. (setq face (org-agenda-deadline-face dfrac wdays))
  4635. (org-add-props txt props
  4636. 'org-marker (org-agenda-new-marker pos)
  4637. 'org-hd-marker (org-agenda-new-marker pos1)
  4638. 'priority (+ (- diff)
  4639. (org-get-priority txt))
  4640. 'org-category category
  4641. 'todo-state todo-state
  4642. 'type (if upcomingp "upcoming-deadline" "deadline")
  4643. 'date (if upcomingp date d2)
  4644. 'face (if donep 'org-agenda-done face)
  4645. 'undone-face face 'done-face 'org-agenda-done)
  4646. (push txt ee))))))
  4647. (nreverse ee)))
  4648. (defun org-agenda-deadline-face (fraction &optional wdays)
  4649. "Return the face to displaying a deadline item.
  4650. FRACTION is what fraction of the head-warning time has passed."
  4651. (if (equal wdays 0) (setq fraction 1.))
  4652. (let ((faces org-agenda-deadline-faces) f)
  4653. (catch 'exit
  4654. (while (setq f (pop faces))
  4655. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4656. (defun org-agenda-get-scheduled (&optional deadline-results)
  4657. "Return the scheduled information for agenda display."
  4658. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4659. 'org-todo-regexp org-todo-regexp
  4660. 'org-complex-heading-regexp org-complex-heading-regexp
  4661. 'done-face 'org-agenda-done
  4662. 'mouse-face 'highlight
  4663. 'help-echo
  4664. (format "mouse-2 or RET jump to org file %s"
  4665. (abbreviate-file-name buffer-file-name))))
  4666. (regexp org-scheduled-time-regexp)
  4667. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4668. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4669. mm
  4670. (deadline-position-alist
  4671. (mapcar (lambda (a) (and (setq mm (get-text-property
  4672. 0 'org-hd-marker a))
  4673. (cons (marker-position mm) a)))
  4674. deadline-results))
  4675. d2 diff pos pos1 category tags donep
  4676. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4677. (goto-char (point-min))
  4678. (while (re-search-forward regexp nil t)
  4679. (catch :skip
  4680. (org-agenda-skip)
  4681. (setq s (match-string 1)
  4682. txt nil
  4683. pos (1- (match-beginning 1))
  4684. todo-state (save-match-data (org-get-todo-state))
  4685. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4686. (member todo-state
  4687. org-agenda-repeating-timestamp-show-all))
  4688. d2 (org-time-string-to-absolute
  4689. (match-string 1) d1 'past show-all)
  4690. diff (- d2 d1))
  4691. (setq pastschedp (and todayp (< diff 0)))
  4692. ;; When to show a scheduled item in the calendar:
  4693. ;; If it is on or past the date.
  4694. (when (or (and (< diff 0)
  4695. (< (abs diff) org-scheduled-past-days)
  4696. (and todayp (not org-agenda-only-exact-dates)))
  4697. (= diff 0))
  4698. (save-excursion
  4699. (setq donep (member todo-state org-done-keywords))
  4700. (if (and donep
  4701. (or org-agenda-skip-scheduled-if-done
  4702. (not (= diff 0))
  4703. (and (functionp 'org-is-habit-p)
  4704. (org-is-habit-p))))
  4705. (setq txt nil)
  4706. (setq habitp (and (functionp 'org-is-habit-p)
  4707. (org-is-habit-p)))
  4708. (setq category (org-get-category))
  4709. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4710. (setq txt org-agenda-no-heading-message)
  4711. (goto-char (match-end 0))
  4712. (setq pos1 (match-beginning 0))
  4713. (if habitp
  4714. (if (or (not org-habit-show-habits)
  4715. (and (not todayp)
  4716. org-habit-show-habits-only-for-today))
  4717. (throw :skip nil))
  4718. (if (and
  4719. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4720. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4721. pastschedp))
  4722. (setq mm (assoc pos1 deadline-position-alist)))
  4723. (throw :skip nil)))
  4724. (setq tags (org-get-tags-at))
  4725. (setq head (buffer-substring-no-properties
  4726. (point)
  4727. (progn (skip-chars-forward "^\r\n") (point))))
  4728. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4729. (setq timestr
  4730. (concat (substring s (match-beginning 1)) " "))
  4731. (setq timestr 'time))
  4732. (setq txt (org-format-agenda-item
  4733. (if (= diff 0)
  4734. (car org-agenda-scheduled-leaders)
  4735. (format (nth 1 org-agenda-scheduled-leaders)
  4736. (- 1 diff)))
  4737. head category tags
  4738. (if (not (= diff 0)) nil timestr)
  4739. nil nil habitp))))
  4740. (when txt
  4741. (setq face
  4742. (cond
  4743. ((and (not habitp) pastschedp)
  4744. 'org-scheduled-previously)
  4745. (todayp 'org-scheduled-today)
  4746. (t 'org-scheduled))
  4747. habitp (and habitp (org-habit-parse-todo)))
  4748. (org-add-props txt props
  4749. 'undone-face face
  4750. 'face (if donep 'org-agenda-done face)
  4751. 'org-marker (org-agenda-new-marker pos)
  4752. 'org-hd-marker (org-agenda-new-marker pos1)
  4753. 'type (if pastschedp "past-scheduled" "scheduled")
  4754. 'date (if pastschedp d2 date)
  4755. 'priority (if habitp
  4756. (org-habit-get-priority habitp)
  4757. (+ 94 (- 5 diff) (org-get-priority txt)))
  4758. 'org-category category
  4759. 'org-habit-p habitp
  4760. 'todo-state todo-state)
  4761. (push txt ee))))))
  4762. (nreverse ee)))
  4763. (defun org-agenda-get-blocks ()
  4764. "Return the date-range information for agenda display."
  4765. (let* ((props (list 'face nil
  4766. 'org-not-done-regexp org-not-done-regexp
  4767. 'org-todo-regexp org-todo-regexp
  4768. 'org-complex-heading-regexp org-complex-heading-regexp
  4769. 'mouse-face 'highlight
  4770. 'help-echo
  4771. (format "mouse-2 or RET jump to org file %s"
  4772. (abbreviate-file-name buffer-file-name))))
  4773. (regexp org-tr-regexp)
  4774. (d0 (calendar-absolute-from-gregorian date))
  4775. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4776. head donep)
  4777. (goto-char (point-min))
  4778. (while (re-search-forward regexp nil t)
  4779. (catch :skip
  4780. (org-agenda-skip)
  4781. (setq pos (point))
  4782. (let ((start-time (match-string 1))
  4783. (end-time (match-string 2)))
  4784. (setq s1 (match-string 1)
  4785. s2 (match-string 2)
  4786. d1 (time-to-days (org-time-string-to-time s1))
  4787. d2 (time-to-days (org-time-string-to-time s2)))
  4788. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4789. ;; Only allow days between the limits, because the normal
  4790. ;; date stamps will catch the limits.
  4791. (save-excursion
  4792. (setq todo-state (org-get-todo-state))
  4793. (setq donep (member todo-state org-done-keywords))
  4794. (if (and donep org-agenda-skip-timestamp-if-done)
  4795. (throw :skip t))
  4796. (setq marker (org-agenda-new-marker (point)))
  4797. (setq category (org-get-category))
  4798. (if (not (re-search-backward "^\\*+ " nil t))
  4799. (setq txt org-agenda-no-heading-message)
  4800. (goto-char (match-beginning 0))
  4801. (setq hdmarker (org-agenda-new-marker (point)))
  4802. (setq tags (org-get-tags-at))
  4803. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4804. (setq head (match-string 1))
  4805. (let ((remove-re
  4806. (if org-agenda-remove-timeranges-from-blocks
  4807. (concat
  4808. "<" (regexp-quote s1) ".*?>"
  4809. "--"
  4810. "<" (regexp-quote s2) ".*?>")
  4811. nil)))
  4812. (setq txt (org-format-agenda-item
  4813. (format
  4814. (nth (if (= d1 d2) 0 1)
  4815. org-agenda-timerange-leaders)
  4816. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4817. head category tags
  4818. (cond ((= d1 d0)
  4819. (concat "<" start-time ">"))
  4820. ((= d2 d0)
  4821. (concat "<" end-time ">"))
  4822. (t nil))
  4823. remove-re))))
  4824. (org-add-props txt props
  4825. 'org-marker marker 'org-hd-marker hdmarker
  4826. 'type "block" 'date date
  4827. 'todo-state todo-state
  4828. 'priority (org-get-priority txt) 'org-category category)
  4829. (push txt ee))))
  4830. (goto-char pos)))
  4831. ;; Sort the entries by expiration date.
  4832. (nreverse ee)))
  4833. ;;; Agenda presentation and sorting
  4834. (defvar org-prefix-has-time nil
  4835. "A flag, set by `org-compile-prefix-format'.
  4836. The flag is set if the currently compiled format contains a `%t'.")
  4837. (defvar org-prefix-has-tag nil
  4838. "A flag, set by `org-compile-prefix-format'.
  4839. The flag is set if the currently compiled format contains a `%T'.")
  4840. (defvar org-prefix-has-effort nil
  4841. "A flag, set by `org-compile-prefix-format'.
  4842. The flag is set if the currently compiled format contains a `%e'.")
  4843. (defvar org-prefix-category-length nil
  4844. "Used by `org-compile-prefix-format' to remember the category field width.")
  4845. (defvar org-prefix-category-max-length nil
  4846. "Used by `org-compile-prefix-format' to remember the category field width.")
  4847. (defun org-agenda-get-category-icon (category)
  4848. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4849. (dolist (entry org-agenda-category-icon-alist)
  4850. (when (org-string-match-p (car entry) category)
  4851. (if (listp (cadr entry))
  4852. (return (cadr entry))
  4853. (return (apply 'create-image (cdr entry)))))))
  4854. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4855. noprefix remove-re habitp)
  4856. "Format TXT to be inserted into the agenda buffer.
  4857. In particular, it adds the prefix and corresponding text properties. EXTRA
  4858. must be a string and replaces the `%s' specifier in the prefix format.
  4859. CATEGORY (string, symbol or nil) may be used to overrule the default
  4860. category taken from local variable or file name. It will replace the `%c'
  4861. specifier in the format. DOTIME, when non-nil, indicates that a
  4862. time-of-day should be extracted from TXT for sorting of this entry, and for
  4863. the `%t' specifier in the format. When DOTIME is a string, this string is
  4864. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4865. only the correctly processes TXT should be returned - this is used by
  4866. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4867. Any match of REMOVE-RE will be removed from TXT."
  4868. (save-match-data
  4869. ;; Diary entries sometimes have extra whitespace at the beginning
  4870. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4871. ;; Fix the tags part in txt
  4872. (setq txt (org-agenda-fix-displayed-tags
  4873. txt tags
  4874. org-agenda-show-inherited-tags
  4875. org-agenda-hide-tags-regexp))
  4876. (let* ((category (or category
  4877. (if (stringp org-category)
  4878. org-category
  4879. (and org-category (symbol-name org-category)))
  4880. (if buffer-file-name
  4881. (file-name-sans-extension
  4882. (file-name-nondirectory buffer-file-name))
  4883. "")))
  4884. (category-icon (org-agenda-get-category-icon category))
  4885. (category-icon (if category-icon
  4886. (propertize " " 'display category-icon)
  4887. ""))
  4888. ;; time, tag, effort are needed for the eval of the prefix format
  4889. (tag (if tags (nth (1- (length tags)) tags) ""))
  4890. time effort neffort
  4891. (ts (if dotime (concat
  4892. (if (stringp dotime) dotime "")
  4893. (and org-agenda-search-headline-for-time txt))))
  4894. (time-of-day (and dotime (org-get-time-of-day ts)))
  4895. stamp plain s0 s1 s2 rtn srp l
  4896. duration thecategory)
  4897. (and (org-mode-p) buffer-file-name
  4898. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4899. (when (and dotime time-of-day)
  4900. ;; Extract starting and ending time and move them to prefix
  4901. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4902. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4903. (setq s0 (match-string 0 ts)
  4904. srp (and stamp (match-end 3))
  4905. s1 (match-string (if plain 1 2) ts)
  4906. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4907. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4908. ;; them, we might want to remove them there to avoid duplication.
  4909. ;; The user can turn this off with a variable.
  4910. (if (and org-prefix-has-time
  4911. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4912. (string-match (concat (regexp-quote s0) " *") txt)
  4913. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4914. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4915. (= (match-beginning 0) 0)
  4916. t))
  4917. (setq txt (replace-match "" nil nil txt))))
  4918. ;; Normalize the time(s) to 24 hour
  4919. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4920. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4921. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  4922. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  4923. (setq s2
  4924. (org-minutes-to-hh:mm-string
  4925. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  4926. ;; Compute the duration
  4927. (when s2
  4928. (setq duration (- (org-hh:mm-string-to-minutes s2)
  4929. (org-hh:mm-string-to-minutes s1)))))
  4930. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4931. txt)
  4932. ;; Tags are in the string
  4933. (if (or (eq org-agenda-remove-tags t)
  4934. (and org-agenda-remove-tags
  4935. org-prefix-has-tag))
  4936. (setq txt (replace-match "" t t txt))
  4937. (setq txt (replace-match
  4938. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4939. (match-string 2 txt))
  4940. t t txt))))
  4941. (when (org-mode-p)
  4942. (setq effort
  4943. (condition-case nil
  4944. (org-get-effort
  4945. (or (get-text-property 0 'org-hd-marker txt)
  4946. (get-text-property 0 'org-marker txt)))
  4947. (error nil)))
  4948. (when effort
  4949. (setq neffort (org-duration-string-to-minutes effort)
  4950. effort (setq effort (concat "[" effort "]" )))))
  4951. (when remove-re
  4952. (while (string-match remove-re txt)
  4953. (setq txt (replace-match "" t t txt))))
  4954. ;; Create the final string
  4955. (if noprefix
  4956. (setq rtn txt)
  4957. ;; Prepare the variables needed in the eval of the compiled format
  4958. (setq time (cond (s2 (concat
  4959. (org-agenda-time-of-day-to-ampm-maybe s1)
  4960. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  4961. (if org-agenda-timegrid-use-ampm " ")))
  4962. (s1 (concat
  4963. (org-agenda-time-of-day-to-ampm-maybe s1)
  4964. (if org-agenda-timegrid-use-ampm
  4965. "........ "
  4966. "......")))
  4967. (t ""))
  4968. extra (or (and (not habitp) extra) "")
  4969. category (if (symbolp category) (symbol-name category) category)
  4970. thecategory (copy-sequence category))
  4971. (if (string-match org-bracket-link-regexp category)
  4972. (progn
  4973. (setq l (if (match-end 3)
  4974. (- (match-end 3) (match-beginning 3))
  4975. (- (match-end 1) (match-beginning 1))))
  4976. (when (< l (or org-prefix-category-length 0))
  4977. (setq category (copy-sequence category))
  4978. (org-add-props category nil
  4979. 'extra-space (make-string
  4980. (- org-prefix-category-length l 1) ?\ ))))
  4981. (if (and org-prefix-category-max-length
  4982. (>= (length category) org-prefix-category-max-length))
  4983. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4984. ;; Evaluate the compiled format
  4985. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4986. ;; And finally add the text properties
  4987. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4988. (org-add-props rtn nil
  4989. 'org-category (if thecategory (downcase thecategory) category)
  4990. 'tags (mapcar 'org-downcase-keep-props tags)
  4991. 'org-highest-priority org-highest-priority
  4992. 'org-lowest-priority org-lowest-priority
  4993. 'prefix-length (- (length rtn) (length txt))
  4994. 'time-of-day time-of-day
  4995. 'duration duration
  4996. 'effort effort
  4997. 'effort-minutes neffort
  4998. 'txt txt
  4999. 'time time
  5000. 'extra extra
  5001. 'dotime dotime))))
  5002. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5003. "Remove tags string from TXT, and add a modified list of tags.
  5004. The modified list may contain inherited tags, and tags matched by
  5005. `org-agenda-hide-tags-regexp' will be removed."
  5006. (when (or add-inherited hide-re)
  5007. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5008. (setq txt (substring txt 0 (match-beginning 0))))
  5009. (setq tags
  5010. (delq nil
  5011. (mapcar (lambda (tg)
  5012. (if (or (and hide-re (string-match hide-re tg))
  5013. (and (not add-inherited)
  5014. (get-text-property 0 'inherited tg)))
  5015. nil
  5016. tg))
  5017. tags)))
  5018. (when tags
  5019. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5020. i)
  5021. (setq txt (concat txt " :"
  5022. (mapconcat
  5023. (lambda (x)
  5024. (setq i (get-text-property 0 'inherited x))
  5025. (if (and have-i (not i))
  5026. (progn
  5027. (setq have-i nil)
  5028. (concat ":" x))
  5029. x))
  5030. tags ":")
  5031. (if have-i "::" ":"))))))
  5032. txt)
  5033. (defun org-downcase-keep-props (s)
  5034. (let ((props (text-properties-at 0 s)))
  5035. (setq s (downcase s))
  5036. (add-text-properties 0 (length s) props s)
  5037. s))
  5038. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5039. (defvar org-agenda-sorting-strategy-selected nil)
  5040. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5041. (catch 'exit
  5042. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5043. ((and todayp (member 'today (car org-agenda-time-grid))))
  5044. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5045. ((member 'weekly (car org-agenda-time-grid)))
  5046. (t (throw 'exit list)))
  5047. (let* ((have (delq nil (mapcar
  5048. (lambda (x) (get-text-property 1 'time-of-day x))
  5049. list)))
  5050. (string (nth 1 org-agenda-time-grid))
  5051. (gridtimes (nth 2 org-agenda-time-grid))
  5052. (req (car org-agenda-time-grid))
  5053. (remove (member 'remove-match req))
  5054. new time)
  5055. (if (and (member 'require-timed req) (not have))
  5056. ;; don't show empty grid
  5057. (throw 'exit list))
  5058. (while (setq time (pop gridtimes))
  5059. (unless (and remove (member time have))
  5060. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5061. (push (org-format-agenda-item
  5062. nil string "" nil
  5063. (concat (substring time 0 -2) ":" (substring time -2)))
  5064. new)
  5065. (put-text-property
  5066. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5067. (when (and todayp org-agenda-show-current-time-in-grid)
  5068. (push (org-format-agenda-item
  5069. nil
  5070. org-agenda-current-time-string
  5071. "" nil
  5072. (format-time-string "%H:%M "))
  5073. new)
  5074. (put-text-property
  5075. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5076. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5077. (append new list)
  5078. (append list new)))))
  5079. (defun org-compile-prefix-format (key)
  5080. "Compile the prefix format into a Lisp form that can be evaluated.
  5081. The resulting form is returned and stored in the variable
  5082. `org-prefix-format-compiled'."
  5083. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5084. org-prefix-category-length nil org-prefix-has-effort nil)
  5085. (let ((s (cond
  5086. ((stringp org-agenda-prefix-format)
  5087. org-agenda-prefix-format)
  5088. ((assq key org-agenda-prefix-format)
  5089. (cdr (assq key org-agenda-prefix-format)))
  5090. (t " %-12:c%?-12t% s")))
  5091. (start 0)
  5092. varform vars var e c f opt)
  5093. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5094. s start)
  5095. (setq var (or (cdr (assoc (match-string 4 s)
  5096. '(("c" . category) ("t" . time) ("s" . extra)
  5097. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5098. 'eval)
  5099. c (or (match-string 3 s) "")
  5100. opt (match-beginning 1)
  5101. start (1+ (match-beginning 0)))
  5102. (if (equal var 'time) (setq org-prefix-has-time t))
  5103. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5104. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5105. (setq f (concat "%" (match-string 2 s) "s"))
  5106. (when (equal var 'category)
  5107. (setq org-prefix-category-length
  5108. (floor (abs (string-to-number (match-string 2 s)))))
  5109. (setq org-prefix-category-max-length
  5110. (let ((x (match-string 2 s)))
  5111. (save-match-data
  5112. (if (string-match "\\.[0-9]+" x)
  5113. (string-to-number (substring (match-string 0 x) 1)))))))
  5114. (if (eq var 'eval)
  5115. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5116. (if opt
  5117. (setq varform
  5118. `(if (equal "" ,var)
  5119. ""
  5120. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5121. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5122. (setq s (replace-match "%s" t nil s))
  5123. (push varform vars))
  5124. (setq vars (nreverse vars))
  5125. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5126. (defun org-set-sorting-strategy (key)
  5127. (if (symbolp (car org-agenda-sorting-strategy))
  5128. ;; the old format
  5129. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5130. (setq org-agenda-sorting-strategy-selected
  5131. (or (cdr (assq key org-agenda-sorting-strategy))
  5132. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5133. '(time-up category-keep priority-down)))))
  5134. (defun org-get-time-of-day (s &optional string mod24)
  5135. "Check string S for a time of day.
  5136. If found, return it as a military time number between 0 and 2400.
  5137. If not found, return nil.
  5138. The optional STRING argument forces conversion into a 5 character wide string
  5139. HH:MM."
  5140. (save-match-data
  5141. (when
  5142. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5143. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5144. (let* ((h (string-to-number (match-string 1 s)))
  5145. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5146. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5147. (am-p (equal ampm "am"))
  5148. (h1 (cond ((not ampm) h)
  5149. ((= h 12) (if am-p 0 12))
  5150. (t (+ h (if am-p 0 12)))))
  5151. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5152. (mod h1 24) h1))
  5153. (t0 (+ (* 100 h2) m))
  5154. (t1 (concat (if (>= h1 24) "+" " ")
  5155. (if (and org-agenda-time-leading-zero
  5156. (< t0 1000)) "0" "")
  5157. (if (< t0 100) "0" "")
  5158. (if (< t0 10) "0" "")
  5159. (int-to-string t0))))
  5160. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5161. (defvar org-agenda-before-sorting-filter-function nil
  5162. "Function to be applied to agenda items prior to sorting.
  5163. Prior to sorting also means just before they are inserted into the agenda.
  5164. To aid sorting, you may revisit the original entries and add more text
  5165. properties which will later be used by the sorting functions.
  5166. The function should take a string argument, an agenda line.
  5167. It has access to the text properties in that line, which contain among
  5168. other things, the property `org-hd-marker' that points to the entry
  5169. where the line comes from. Note that not all lines going into the agenda
  5170. have this property, only most.
  5171. The function should return the modified string. It is probably best
  5172. to ONLY change text properties.
  5173. You can also use this function as a filter, by returning nil for lines
  5174. you don't want to have in the agenda at all. For this application, you
  5175. could bind the variable in the options section of a custom command.")
  5176. (defun org-finalize-agenda-entries (list &optional nosort)
  5177. "Sort and concatenate the agenda items."
  5178. (setq list (mapcar 'org-agenda-highlight-todo list))
  5179. (if nosort
  5180. list
  5181. (when org-agenda-before-sorting-filter-function
  5182. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5183. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5184. (defun org-agenda-highlight-todo (x)
  5185. (let ((org-done-keywords org-done-keywords-for-agenda)
  5186. (case-fold-search nil)
  5187. re pl)
  5188. (if (eq x 'line)
  5189. (save-excursion
  5190. (beginning-of-line 1)
  5191. (setq re (org-get-at-bol 'org-todo-regexp))
  5192. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  5193. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5194. (add-text-properties (match-beginning 0) (match-end 1)
  5195. (list 'face (org-get-todo-face 1)))
  5196. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5197. (delete-region (match-beginning 1) (1- (match-end 0)))
  5198. (goto-char (match-beginning 1))
  5199. (insert (format org-agenda-todo-keyword-format s)))))
  5200. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  5201. pl (get-text-property 0 'prefix-length x))
  5202. (when (and re
  5203. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5204. x (or pl 0)) pl))
  5205. (add-text-properties
  5206. (or (match-end 1) (match-end 0)) (match-end 0)
  5207. (list 'face (org-get-todo-face (match-string 2 x)))
  5208. x)
  5209. (when (match-end 1)
  5210. (setq x (concat (substring x 0 (match-end 1))
  5211. (format org-agenda-todo-keyword-format
  5212. (match-string 2 x))
  5213. (org-add-props " " (text-properties-at 0 x))
  5214. (substring x (match-end 3))))))
  5215. x)))
  5216. (defsubst org-cmp-priority (a b)
  5217. "Compare the priorities of string A and B."
  5218. (let ((pa (or (get-text-property 1 'priority a) 0))
  5219. (pb (or (get-text-property 1 'priority b) 0)))
  5220. (cond ((> pa pb) +1)
  5221. ((< pa pb) -1)
  5222. (t nil))))
  5223. (defsubst org-cmp-effort (a b)
  5224. "Compare the priorities of string A and B."
  5225. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5226. (ea (or (get-text-property 1 'effort-minutes a) def))
  5227. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5228. (cond ((> ea eb) +1)
  5229. ((< ea eb) -1)
  5230. (t nil))))
  5231. (defsubst org-cmp-category (a b)
  5232. "Compare the string values of categories of strings A and B."
  5233. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5234. (cb (or (get-text-property 1 'org-category b) "")))
  5235. (cond ((string-lessp ca cb) -1)
  5236. ((string-lessp cb ca) +1)
  5237. (t nil))))
  5238. (defsubst org-cmp-todo-state (a b)
  5239. "Compare the todo states of strings A and B."
  5240. (let* ((ma (or (get-text-property 1 'org-marker a)
  5241. (get-text-property 1 'org-hd-marker a)))
  5242. (mb (or (get-text-property 1 'org-marker b)
  5243. (get-text-property 1 'org-hd-marker b)))
  5244. (fa (and ma (marker-buffer ma)))
  5245. (fb (and mb (marker-buffer mb)))
  5246. (todo-kwds
  5247. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5248. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5249. (ta (or (get-text-property 1 'todo-state a) ""))
  5250. (tb (or (get-text-property 1 'todo-state b) ""))
  5251. (la (- (length (member ta todo-kwds))))
  5252. (lb (- (length (member tb todo-kwds))))
  5253. (donepa (member ta org-done-keywords-for-agenda))
  5254. (donepb (member tb org-done-keywords-for-agenda)))
  5255. (cond ((and donepa (not donepb)) -1)
  5256. ((and (not donepa) donepb) +1)
  5257. ((< la lb) -1)
  5258. ((< lb la) +1)
  5259. (t nil))))
  5260. (defsubst org-cmp-alpha (a b)
  5261. "Compare the headlines, alphabetically."
  5262. (let* ((pla (get-text-property 0 'prefix-length a))
  5263. (plb (get-text-property 0 'prefix-length b))
  5264. (ta (and pla (substring a pla)))
  5265. (tb (and plb (substring b plb))))
  5266. (when pla
  5267. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5268. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5269. (setq ta (substring ta (match-end 0))))
  5270. (setq ta (downcase ta)))
  5271. (when plb
  5272. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5273. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5274. (setq tb (substring tb (match-end 0))))
  5275. (setq tb (downcase tb)))
  5276. (cond ((not ta) +1)
  5277. ((not tb) -1)
  5278. ((string-lessp ta tb) -1)
  5279. ((string-lessp tb ta) +1)
  5280. (t nil))))
  5281. (defsubst org-cmp-tag (a b)
  5282. "Compare the string values of the first tags of A and B."
  5283. (let ((ta (car (last (get-text-property 1 'tags a))))
  5284. (tb (car (last (get-text-property 1 'tags b)))))
  5285. (cond ((not ta) +1)
  5286. ((not tb) -1)
  5287. ((string-lessp ta tb) -1)
  5288. ((string-lessp tb ta) +1)
  5289. (t nil))))
  5290. (defsubst org-cmp-time (a b)
  5291. "Compare the time-of-day values of strings A and B."
  5292. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5293. (ta (or (get-text-property 1 'time-of-day a) def))
  5294. (tb (or (get-text-property 1 'time-of-day b) def)))
  5295. (cond ((< ta tb) -1)
  5296. ((< tb ta) +1)
  5297. (t nil))))
  5298. (defsubst org-cmp-habit-p (a b)
  5299. "Compare the todo states of strings A and B."
  5300. (let ((ha (get-text-property 1 'org-habit-p a))
  5301. (hb (get-text-property 1 'org-habit-p b)))
  5302. (cond ((and ha (not hb)) -1)
  5303. ((and (not ha) hb) +1)
  5304. (t nil))))
  5305. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5306. (defun org-entries-lessp (a b)
  5307. "Predicate for sorting agenda entries."
  5308. ;; The following variables will be used when the form is evaluated.
  5309. ;; So even though the compiler complains, keep them.
  5310. (let* ((ss org-agenda-sorting-strategy-selected)
  5311. (time-up (and (org-em 'time-up 'time-down ss)
  5312. (org-cmp-time a b)))
  5313. (time-down (if time-up (- time-up) nil))
  5314. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5315. (org-cmp-priority a b)))
  5316. (priority-down (if priority-up (- priority-up) nil))
  5317. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5318. (org-cmp-effort a b)))
  5319. (effort-down (if effort-up (- effort-up) nil))
  5320. (category-up (and (or (org-em 'category-up 'category-down ss)
  5321. (memq 'category-keep ss))
  5322. (org-cmp-category a b)))
  5323. (category-down (if category-up (- category-up) nil))
  5324. (category-keep (if category-up +1 nil))
  5325. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5326. (org-cmp-tag a b)))
  5327. (tag-down (if tag-up (- tag-up) nil))
  5328. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5329. (org-cmp-todo-state a b)))
  5330. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5331. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5332. (org-cmp-habit-p a b)))
  5333. (habit-down (if habit-up (- habit-up) nil))
  5334. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5335. (org-cmp-alpha a b)))
  5336. (alpha-down (if alpha-up (- alpha-up) nil))
  5337. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5338. user-defined-up user-defined-down)
  5339. (if (and need-user-cmp org-agenda-cmp-user-defined
  5340. (functionp org-agenda-cmp-user-defined))
  5341. (setq user-defined-up
  5342. (funcall org-agenda-cmp-user-defined a b)
  5343. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5344. (cdr (assoc
  5345. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5346. '((-1 . t) (1 . nil) (nil . nil))))))
  5347. ;;; Agenda restriction lock
  5348. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5349. "Overlay to mark the headline to which agenda commands are restricted.")
  5350. (overlay-put org-agenda-restriction-lock-overlay
  5351. 'face 'org-agenda-restriction-lock)
  5352. (overlay-put org-agenda-restriction-lock-overlay
  5353. 'help-echo "Agendas are currently limited to this subtree.")
  5354. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5355. (defun org-agenda-set-restriction-lock (&optional type)
  5356. "Set restriction lock for agenda, to current subtree or file.
  5357. Restriction will be the file if TYPE is `file', or if type is the
  5358. universal prefix '(4), or if the cursor is before the first headline
  5359. in the file. Otherwise, restriction will be to the current subtree."
  5360. (interactive "P")
  5361. (and (equal type '(4)) (setq type 'file))
  5362. (setq type (cond
  5363. (type type)
  5364. ((org-at-heading-p) 'subtree)
  5365. ((condition-case nil (org-back-to-heading t) (error nil))
  5366. 'subtree)
  5367. (t 'file)))
  5368. (if (eq type 'subtree)
  5369. (progn
  5370. (setq org-agenda-restrict t)
  5371. (setq org-agenda-overriding-restriction 'subtree)
  5372. (put 'org-agenda-files 'org-restrict
  5373. (list (buffer-file-name (buffer-base-buffer))))
  5374. (org-back-to-heading t)
  5375. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5376. (move-marker org-agenda-restrict-begin (point))
  5377. (move-marker org-agenda-restrict-end
  5378. (save-excursion (org-end-of-subtree t)))
  5379. (message "Locking agenda restriction to subtree"))
  5380. (put 'org-agenda-files 'org-restrict
  5381. (list (buffer-file-name (buffer-base-buffer))))
  5382. (setq org-agenda-restrict nil)
  5383. (setq org-agenda-overriding-restriction 'file)
  5384. (move-marker org-agenda-restrict-begin nil)
  5385. (move-marker org-agenda-restrict-end nil)
  5386. (message "Locking agenda restriction to file"))
  5387. (setq current-prefix-arg nil)
  5388. (org-agenda-maybe-redo))
  5389. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5390. "Remove the agenda restriction lock."
  5391. (interactive "P")
  5392. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5393. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5394. (setq org-agenda-overriding-restriction nil)
  5395. (setq org-agenda-restrict nil)
  5396. (put 'org-agenda-files 'org-restrict nil)
  5397. (move-marker org-agenda-restrict-begin nil)
  5398. (move-marker org-agenda-restrict-end nil)
  5399. (setq current-prefix-arg nil)
  5400. (message "Agenda restriction lock removed")
  5401. (or noupdate (org-agenda-maybe-redo)))
  5402. (defun org-agenda-maybe-redo ()
  5403. "If there is any window showing the agenda view, update it."
  5404. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5405. (w0 (selected-window)))
  5406. (when w
  5407. (select-window w)
  5408. (org-agenda-redo)
  5409. (select-window w0)
  5410. (if org-agenda-overriding-restriction
  5411. (message "Agenda view shifted to new %s restriction"
  5412. org-agenda-overriding-restriction)
  5413. (message "Agenda restriction lock removed")))))
  5414. ;;; Agenda commands
  5415. (defun org-agenda-check-type (error &rest types)
  5416. "Check if agenda buffer is of allowed type.
  5417. If ERROR is non-nil, throw an error, otherwise just return nil."
  5418. (if (memq org-agenda-type types)
  5419. t
  5420. (if error
  5421. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5422. nil)))
  5423. (defun org-agenda-quit ()
  5424. "Exit agenda by removing the window or the buffer."
  5425. (interactive)
  5426. (if org-agenda-columns-active
  5427. (org-columns-quit)
  5428. (let ((buf (current-buffer)))
  5429. (if (eq org-agenda-window-setup 'other-frame)
  5430. (progn
  5431. (kill-buffer buf)
  5432. (org-agenda-reset-markers)
  5433. (org-columns-remove-overlays)
  5434. (setq org-agenda-archives-mode nil)
  5435. (delete-frame))
  5436. (and (not (eq org-agenda-window-setup 'current-window))
  5437. (not (one-window-p))
  5438. (delete-window))
  5439. (kill-buffer buf)
  5440. (org-agenda-reset-markers)
  5441. (org-columns-remove-overlays)
  5442. (setq org-agenda-archives-mode nil)))
  5443. ;; Maybe restore the pre-agenda window configuration.
  5444. (and org-agenda-restore-windows-after-quit
  5445. (not (eq org-agenda-window-setup 'other-frame))
  5446. org-pre-agenda-window-conf
  5447. (set-window-configuration org-pre-agenda-window-conf))))
  5448. (defun org-agenda-exit ()
  5449. "Exit agenda by removing the window or the buffer.
  5450. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5451. Org-mode buffers visited directly by the user will not be touched."
  5452. (interactive)
  5453. (org-release-buffers org-agenda-new-buffers)
  5454. (setq org-agenda-new-buffers nil)
  5455. (org-agenda-quit))
  5456. (defun org-agenda-execute (arg)
  5457. "Execute another agenda command, keeping same window.
  5458. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5459. in the agenda."
  5460. (interactive "P")
  5461. (let ((org-agenda-window-setup 'current-window))
  5462. (org-agenda arg)))
  5463. (defun org-agenda-redo ()
  5464. "Rebuild Agenda.
  5465. When this is the global TODO list, a prefix argument will be interpreted."
  5466. (interactive)
  5467. (let* ((org-agenda-keep-modes t)
  5468. (filter org-agenda-filter)
  5469. (preset (get 'org-agenda-filter :preset-filter))
  5470. (org-agenda-filter-while-redo (or filter preset))
  5471. (cols org-agenda-columns-active)
  5472. (line (org-current-line))
  5473. (window-line (- line (org-current-line (window-start))))
  5474. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5475. (put 'org-agenda-filter :preset-filter nil)
  5476. (and cols (org-columns-quit))
  5477. (message "Rebuilding agenda buffer...")
  5478. (org-let lprops '(eval org-agenda-redo-command))
  5479. (setq org-agenda-undo-list nil
  5480. org-agenda-pending-undo-list nil)
  5481. (message "Rebuilding agenda buffer...done")
  5482. (put 'org-agenda-filter :preset-filter preset)
  5483. (and (or filter preset) (org-agenda-filter-apply filter))
  5484. (and cols (interactive-p) (org-agenda-columns))
  5485. (org-goto-line line)
  5486. (recenter window-line)))
  5487. (defvar org-global-tags-completion-table nil)
  5488. (defvar org-agenda-filter-form nil)
  5489. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5490. "Keep only those lines in the agenda buffer that have a specific tag.
  5491. The tag is selected with its fast selection letter, as configured.
  5492. With prefix argument STRIP, remove all lines that do have the tag.
  5493. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5494. used to narrow the search - the interactive user can also press `-' or `+'
  5495. to switch to narrowing."
  5496. (interactive "P")
  5497. (let* ((alist org-tag-alist-for-agenda)
  5498. (tag-chars (mapconcat
  5499. (lambda (x) (if (and (not (symbolp (car x)))
  5500. (cdr x))
  5501. (char-to-string (cdr x))
  5502. ""))
  5503. alist ""))
  5504. (efforts (org-split-string
  5505. (or (cdr (assoc (concat org-effort-property "_ALL")
  5506. org-global-properties))
  5507. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5508. (effort-op org-agenda-filter-effort-default-operator)
  5509. (effort-prompt "")
  5510. (inhibit-read-only t)
  5511. (current org-agenda-filter)
  5512. maybe-reftresh a n tag)
  5513. (unless char
  5514. (message
  5515. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5516. (if narrow "Narrow" "Filter") tag-chars
  5517. (if org-agenda-auto-exclude-function "[RET], " ""))
  5518. (setq char (read-char)))
  5519. (when (member char '(?+ ?-))
  5520. ;; Narrowing down
  5521. (cond ((equal char ?-) (setq strip t narrow t))
  5522. ((equal char ?+) (setq strip nil narrow t)))
  5523. (message
  5524. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5525. (setq char (read-char)))
  5526. (when (member char '(?< ?> ?= ??))
  5527. ;; An effort operator
  5528. (setq effort-op (char-to-string char))
  5529. (setq alist nil) ; to make sure it will be interpreted as effort.
  5530. (unless (equal char ??)
  5531. (loop for i from 0 to 9 do
  5532. (setq effort-prompt
  5533. (concat
  5534. effort-prompt " ["
  5535. (if (= i 9) "0" (int-to-string (1+ i)))
  5536. "]" (nth i efforts))))
  5537. (message "Effort%s: %s " effort-op effort-prompt)
  5538. (setq char (read-char))
  5539. (when (or (< char ?0) (> char ?9))
  5540. (error "Need 1-9,0 to select effort" ))))
  5541. (when (equal char ?\t)
  5542. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5543. (org-set-local 'org-global-tags-completion-table
  5544. (org-global-tags-completion-table)))
  5545. (let ((completion-ignore-case t))
  5546. (setq tag (org-icompleting-read
  5547. "Tag: " org-global-tags-completion-table))))
  5548. (cond
  5549. ((equal char ?\r)
  5550. (org-agenda-filter-by-tag-show-all)
  5551. (when org-agenda-auto-exclude-function
  5552. (setq org-agenda-filter '())
  5553. (dolist (tag (org-agenda-get-represented-tags))
  5554. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5555. (if modifier
  5556. (push modifier org-agenda-filter))))
  5557. (if (not (null org-agenda-filter))
  5558. (org-agenda-filter-apply org-agenda-filter)))
  5559. (setq maybe-reftresh t))
  5560. ((equal char ?/)
  5561. (org-agenda-filter-by-tag-show-all)
  5562. (when (get 'org-agenda-filter :preset-filter)
  5563. (org-agenda-filter-apply org-agenda-filter))
  5564. (setq maybe-reftresh t))
  5565. ((or (equal char ?\ )
  5566. (setq a (rassoc char alist))
  5567. (and (>= char ?0) (<= char ?9)
  5568. (setq n (if (= char ?0) 9 (- char ?0 1))
  5569. tag (concat effort-op (nth n efforts))
  5570. a (cons tag nil)))
  5571. (and (= char ??)
  5572. (setq tag "?eff")
  5573. a (cons tag nil))
  5574. (and tag (setq a (cons tag nil))))
  5575. (org-agenda-filter-by-tag-show-all)
  5576. (setq tag (car a))
  5577. (setq org-agenda-filter
  5578. (cons (concat (if strip "-" "+") tag)
  5579. (if narrow current nil)))
  5580. (org-agenda-filter-apply org-agenda-filter)
  5581. (setq maybe-reftresh t))
  5582. (t (error "Invalid tag selection character %c" char)))
  5583. (when (and maybe-reftresh
  5584. (eq org-agenda-clockreport-mode 'with-filter))
  5585. (org-agenda-redo))))
  5586. (defun org-agenda-get-represented-tags ()
  5587. "Get a list of all tags currently represented in the agenda."
  5588. (let (p tags)
  5589. (save-excursion
  5590. (goto-char (point-min))
  5591. (while (setq p (next-single-property-change (point) 'tags))
  5592. (goto-char p)
  5593. (mapc (lambda (x) (add-to-list 'tags x))
  5594. (get-text-property (point) 'tags))))
  5595. tags))
  5596. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5597. "Refine the current filter. See `org-agenda-filter-by-tag."
  5598. (interactive "P")
  5599. (org-agenda-filter-by-tag strip char 'refine))
  5600. (defun org-agenda-filter-make-matcher ()
  5601. "Create the form that tests a line for the agenda filter."
  5602. (let (f f1)
  5603. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5604. org-agenda-filter))
  5605. (if (member x '("-" "+"))
  5606. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5607. (if (string-match "[<=>?]" x)
  5608. (setq f1 (org-agenda-filter-effort-form x))
  5609. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5610. (if (equal (string-to-char x) ?-)
  5611. (setq f1 (list 'not f1))))
  5612. (push f1 f))
  5613. (cons 'and (nreverse f))))
  5614. (defun org-agenda-filter-effort-form (e)
  5615. "Return the form to compare the effort of the current line with what E says.
  5616. E looks like \"+<2:25\"."
  5617. (let (op)
  5618. (setq e (substring e 1))
  5619. (setq op (string-to-char e) e (substring e 1))
  5620. (setq op (cond ((equal op ?<) '<=)
  5621. ((equal op ?>) '>=)
  5622. ((equal op ??) op)
  5623. (t '=)))
  5624. (list 'org-agenda-compare-effort (list 'quote op)
  5625. (org-duration-string-to-minutes e))))
  5626. (defun org-agenda-compare-effort (op value)
  5627. "Compare the effort of the current line with VALUE, using OP.
  5628. If the line does not have an effort defined, return nil."
  5629. (let ((eff (org-get-at-bol 'effort-minutes)))
  5630. (if (equal op ??)
  5631. (not eff)
  5632. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5633. value))))
  5634. (defun org-agenda-filter-apply (filter)
  5635. "Set FILTER as the new agenda filter and apply it."
  5636. (let (tags)
  5637. (setq org-agenda-filter filter
  5638. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5639. (org-agenda-set-mode-name)
  5640. (save-excursion
  5641. (goto-char (point-min))
  5642. (while (not (eobp))
  5643. (if (org-get-at-bol 'org-marker)
  5644. (progn
  5645. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5646. (if (not (eval org-agenda-filter-form))
  5647. (org-agenda-filter-by-tag-hide-line))
  5648. (beginning-of-line 2))
  5649. (beginning-of-line 2))))
  5650. (if (get-char-property (point) 'invisible)
  5651. (org-agenda-previous-line))))
  5652. (defun org-agenda-filter-by-tag-hide-line ()
  5653. (let (ov)
  5654. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5655. (point-at-eol)))
  5656. (overlay-put ov 'invisible t)
  5657. (overlay-put ov 'type 'tags-filter)
  5658. (push ov org-agenda-filter-overlays)))
  5659. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5660. (setq pos (or pos (point)))
  5661. (save-excursion
  5662. (dolist (ov (overlays-at pos))
  5663. (when (and (overlay-get ov 'invisible)
  5664. (eq (overlay-get ov 'type) 'tags-filter))
  5665. (goto-char pos)
  5666. (if (< (overlay-start ov) (point-at-eol))
  5667. (move-overlay ov (point-at-eol)
  5668. (overlay-end ov)))))))
  5669. (defun org-agenda-filter-by-tag-show-all ()
  5670. (mapc 'delete-overlay org-agenda-filter-overlays)
  5671. (setq org-agenda-filter-overlays nil)
  5672. (setq org-agenda-filter nil)
  5673. (setq org-agenda-filter-form nil)
  5674. (org-agenda-set-mode-name))
  5675. (defun org-agenda-manipulate-query-add ()
  5676. "Manipulate the query by adding a search term with positive selection.
  5677. Positive selection means the term must be matched for selection of an entry."
  5678. (interactive)
  5679. (org-agenda-manipulate-query ?\[))
  5680. (defun org-agenda-manipulate-query-subtract ()
  5681. "Manipulate the query by adding a search term with negative selection.
  5682. Negative selection means term must not be matched for selection of an entry."
  5683. (interactive)
  5684. (org-agenda-manipulate-query ?\]))
  5685. (defun org-agenda-manipulate-query-add-re ()
  5686. "Manipulate the query by adding a search regexp with positive selection.
  5687. Positive selection means the regexp must match for selection of an entry."
  5688. (interactive)
  5689. (org-agenda-manipulate-query ?\{))
  5690. (defun org-agenda-manipulate-query-subtract-re ()
  5691. "Manipulate the query by adding a search regexp with negative selection.
  5692. Negative selection means regexp must not match for selection of an entry."
  5693. (interactive)
  5694. (org-agenda-manipulate-query ?\}))
  5695. (defun org-agenda-manipulate-query (char)
  5696. (cond
  5697. ((memq org-agenda-type '(timeline agenda))
  5698. (let ((org-agenda-include-inactive-timestamps t))
  5699. (org-agenda-redo))
  5700. (message "Display now includes inactive timestamps as well"))
  5701. ((eq org-agenda-type 'search)
  5702. (org-add-to-string
  5703. 'org-agenda-query-string
  5704. (if org-agenda-last-search-view-search-was-boolean
  5705. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5706. (?\{ . " +{}") (?\} . " -{}"))))
  5707. " "))
  5708. (setq org-agenda-redo-command
  5709. (list 'org-search-view
  5710. org-todo-only
  5711. org-agenda-query-string
  5712. (+ (length org-agenda-query-string)
  5713. (if (member char '(?\{ ?\})) 0 1))))
  5714. (set-register org-agenda-query-register org-agenda-query-string)
  5715. (org-agenda-redo))
  5716. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5717. org-agenda-type))))
  5718. (defun org-add-to-string (var string)
  5719. (set var (concat (symbol-value var) string)))
  5720. (defun org-agenda-goto-date (date)
  5721. "Jump to DATE in agenda."
  5722. (interactive (list (let ((org-read-date-prefer-future
  5723. (eval org-agenda-jump-prefer-future)))
  5724. (org-read-date))))
  5725. (org-agenda-list nil date))
  5726. (defun org-agenda-goto-today ()
  5727. "Go to today."
  5728. (interactive)
  5729. (org-agenda-check-type t 'timeline 'agenda)
  5730. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5731. (cond
  5732. (tdpos (goto-char tdpos))
  5733. ((eq org-agenda-type 'agenda)
  5734. (let* ((sd (org-agenda-compute-starting-span
  5735. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5736. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5737. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5738. (org-agenda-redo)
  5739. (org-agenda-find-same-or-today-or-agenda)))
  5740. (t (error "Cannot find today")))))
  5741. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5742. (goto-char
  5743. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5744. (text-property-any (point-min) (point-max) 'org-today t)
  5745. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5746. (point-min))))
  5747. (defun org-agenda-later (arg)
  5748. "Go forward in time by thee current span.
  5749. With prefix ARG, go forward that many times the current span."
  5750. (interactive "p")
  5751. (org-agenda-check-type t 'agenda)
  5752. (let* ((span org-agenda-current-span)
  5753. (sd org-starting-day)
  5754. (greg (calendar-gregorian-from-absolute sd))
  5755. (cnt (org-get-at-bol 'org-day-cnt))
  5756. greg2)
  5757. (cond
  5758. ((eq span 'day)
  5759. (setq sd (+ arg sd)))
  5760. ((eq span 'week)
  5761. (setq sd (+ (* 7 arg) sd)))
  5762. ((eq span 'month)
  5763. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5764. sd (calendar-absolute-from-gregorian greg2))
  5765. (setcar greg2 (1+ (car greg2))))
  5766. ((eq span 'year)
  5767. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5768. sd (calendar-absolute-from-gregorian greg2))
  5769. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5770. (t
  5771. (setq sd (+ (* span arg) sd))))
  5772. (let ((org-agenda-overriding-arguments
  5773. (list (car org-agenda-last-arguments) sd span t)))
  5774. (org-agenda-redo)
  5775. (org-agenda-find-same-or-today-or-agenda cnt))))
  5776. (defun org-agenda-earlier (arg)
  5777. "Go backward in time by the current span.
  5778. With prefix ARG, go backward that many times the current span."
  5779. (interactive "p")
  5780. (org-agenda-later (- arg)))
  5781. (defun org-agenda-view-mode-dispatch ()
  5782. "Call one of the view mode commands."
  5783. (interactive)
  5784. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5785. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5786. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5787. (let ((a (read-char-exclusive)))
  5788. (case a
  5789. (?\ (call-interactively 'org-agenda-reset-view))
  5790. (?d (call-interactively 'org-agenda-day-view))
  5791. (?w (call-interactively 'org-agenda-week-view))
  5792. (?m (call-interactively 'org-agenda-month-view))
  5793. (?y (call-interactively 'org-agenda-year-view))
  5794. (?l (call-interactively 'org-agenda-log-mode))
  5795. (?L (org-agenda-log-mode '(4)))
  5796. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5797. (?a (call-interactively 'org-agenda-archives-mode))
  5798. (?A (org-agenda-archives-mode 'files))
  5799. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5800. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5801. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5802. (?D (call-interactively 'org-agenda-toggle-diary))
  5803. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5804. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5805. (org-agenda-check-type t 'timeline 'agenda)
  5806. (org-agenda-redo))
  5807. (message "Display now includes inactive timestamps as well"))
  5808. (?q (message "Abort"))
  5809. (otherwise (error "Invalid key" )))))
  5810. (defun org-agenda-reset-view ()
  5811. "Switch to default view for agenda."
  5812. (interactive)
  5813. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5814. (defun org-agenda-day-view (&optional day-of-year)
  5815. "Switch to daily view for agenda.
  5816. With argument DAY-OF-YEAR, switch to that day of the year."
  5817. (interactive "P")
  5818. (org-agenda-change-time-span 'day day-of-year))
  5819. (defun org-agenda-week-view (&optional iso-week)
  5820. "Switch to daily view for agenda.
  5821. With argument ISO-WEEK, switch to the corresponding ISO week.
  5822. If ISO-WEEK has more then 2 digits, only the last two encode the
  5823. week. Any digits before this encode a year. So 200712 means
  5824. week 12 of year 2007. Years in the range 1938-2037 can also be
  5825. written as 2-digit years."
  5826. (interactive "P")
  5827. (org-agenda-change-time-span 'week iso-week))
  5828. (defun org-agenda-month-view (&optional month)
  5829. "Switch to monthly view for agenda.
  5830. With argument MONTH, switch to that month."
  5831. (interactive "P")
  5832. (org-agenda-change-time-span 'month month))
  5833. (defun org-agenda-year-view (&optional year)
  5834. "Switch to yearly view for agenda.
  5835. With argument YEAR, switch to that year.
  5836. If MONTH has more then 2 digits, only the last two encode the
  5837. month. Any digits before this encode a year. So 200712 means
  5838. December year 2007. Years in the range 1938-2037 can also be
  5839. written as 2-digit years."
  5840. (interactive "P")
  5841. (when year
  5842. (setq year (org-small-year-to-year year)))
  5843. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5844. (org-agenda-change-time-span 'year year)
  5845. (error "Abort")))
  5846. (defun org-agenda-change-time-span (span &optional n)
  5847. "Change the agenda view to SPAN.
  5848. SPAN may be `day', `week', `month', `year'."
  5849. (org-agenda-check-type t 'agenda)
  5850. (if (and (not n) (equal org-agenda-current-span span))
  5851. (error "Viewing span is already \"%s\"" span))
  5852. (let* ((sd (or (org-get-at-bol 'day)
  5853. org-starting-day))
  5854. (sd (org-agenda-compute-starting-span sd span n))
  5855. (org-agenda-overriding-arguments
  5856. (or org-agenda-overriding-arguments
  5857. (list (car org-agenda-last-arguments) sd span t))))
  5858. (org-agenda-redo)
  5859. (org-agenda-find-same-or-today-or-agenda))
  5860. (org-agenda-set-mode-name)
  5861. (message "Switched to %s view" span))
  5862. (defun org-agenda-compute-starting-span (sd span &optional n)
  5863. "Compute starting date for agenda.
  5864. SPAN may be `day', `week', `month', `year'. The return value
  5865. is a cons cell with the starting date and the number of days,
  5866. so that the date SD will be in that range."
  5867. (let* ((greg (calendar-gregorian-from-absolute sd))
  5868. (dg (nth 1 greg))
  5869. (mg (car greg))
  5870. (yg (nth 2 greg)))
  5871. (cond
  5872. ((eq span 'day)
  5873. (when n
  5874. (setq sd (+ (calendar-absolute-from-gregorian
  5875. (list mg 1 yg))
  5876. n -1))))
  5877. ((eq span 'week)
  5878. (let* ((nt (calendar-day-of-week
  5879. (calendar-gregorian-from-absolute sd)))
  5880. (d (if org-agenda-start-on-weekday
  5881. (- nt org-agenda-start-on-weekday)
  5882. 0))
  5883. y1)
  5884. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5885. (when n
  5886. (require 'cal-iso)
  5887. (when (> n 99)
  5888. (setq y1 (org-small-year-to-year (/ n 100))
  5889. n (mod n 100)))
  5890. (setq sd
  5891. (calendar-absolute-from-iso
  5892. (list n 1
  5893. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  5894. ((eq span 'month)
  5895. (let (y1)
  5896. (when (and n (> n 99))
  5897. (setq y1 (org-small-year-to-year (/ n 100))
  5898. n (mod n 100)))
  5899. (setq sd (calendar-absolute-from-gregorian
  5900. (list (or n mg) 1 (or y1 yg))))))
  5901. ((eq span 'year)
  5902. (setq sd (calendar-absolute-from-gregorian
  5903. (list 1 1 (or n yg))))))
  5904. sd))
  5905. (defun org-agenda-next-date-line (&optional arg)
  5906. "Jump to the next line indicating a date in agenda buffer."
  5907. (interactive "p")
  5908. (org-agenda-check-type t 'agenda 'timeline)
  5909. (beginning-of-line 1)
  5910. ;; This does not work if user makes date format that starts with a blank
  5911. (if (looking-at "^\\S-") (forward-char 1))
  5912. (if (not (re-search-forward "^\\S-" nil t arg))
  5913. (progn
  5914. (backward-char 1)
  5915. (error "No next date after this line in this buffer")))
  5916. (goto-char (match-beginning 0)))
  5917. (defun org-agenda-previous-date-line (&optional arg)
  5918. "Jump to the previous line indicating a date in agenda buffer."
  5919. (interactive "p")
  5920. (org-agenda-check-type t 'agenda 'timeline)
  5921. (beginning-of-line 1)
  5922. (if (not (re-search-backward "^\\S-" nil t arg))
  5923. (error "No previous date before this line in this buffer")))
  5924. ;; Initialize the highlight
  5925. (defvar org-hl (make-overlay 1 1))
  5926. (overlay-put org-hl 'face 'highlight)
  5927. (defun org-highlight (begin end &optional buffer)
  5928. "Highlight a region with overlay."
  5929. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5930. (defun org-unhighlight ()
  5931. "Detach overlay INDEX."
  5932. (org-detach-overlay org-hl))
  5933. ;; FIXME this is currently not used.
  5934. (defun org-highlight-until-next-command (beg end &optional buffer)
  5935. "Move the highlight overlay to BEG/END, remove it before the next command."
  5936. (org-highlight beg end buffer)
  5937. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5938. (defun org-unhighlight-once ()
  5939. "Remove the highlight from its position, and this function from the hook."
  5940. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5941. (org-unhighlight))
  5942. (defun org-agenda-follow-mode ()
  5943. "Toggle follow mode in an agenda buffer."
  5944. (interactive)
  5945. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5946. (org-agenda-set-mode-name)
  5947. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5948. (org-agenda-show))
  5949. (message "Follow mode is %s"
  5950. (if org-agenda-follow-mode "on" "off")))
  5951. (defun org-agenda-entry-text-mode (&optional arg)
  5952. "Toggle entry text mode in an agenda buffer."
  5953. (interactive "P")
  5954. (setq org-agenda-entry-text-mode (or (integerp arg)
  5955. (not org-agenda-entry-text-mode)))
  5956. (org-agenda-entry-text-hide)
  5957. (and org-agenda-entry-text-mode
  5958. (let ((org-agenda-entry-text-maxlines
  5959. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5960. (org-agenda-entry-text-show)))
  5961. (org-agenda-set-mode-name)
  5962. (message "Entry text mode is %s. Maximum number of lines is %d"
  5963. (if org-agenda-entry-text-mode "on" "off")
  5964. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5965. (defun org-agenda-clockreport-mode (&optional with-filter)
  5966. "Toggle clocktable mode in an agenda buffer.
  5967. With prefix arg WITH-FILTER, make the clocktable respect the current
  5968. agenda filter."
  5969. (interactive "P")
  5970. (org-agenda-check-type t 'agenda)
  5971. (if with-filter
  5972. (setq org-agenda-clockreport-mode 'with-filter)
  5973. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5974. (org-agenda-set-mode-name)
  5975. (org-agenda-redo)
  5976. (message "Clocktable mode is %s"
  5977. (if org-agenda-clockreport-mode "on" "off")))
  5978. (defun org-agenda-log-mode (&optional special)
  5979. "Toggle log mode in an agenda buffer.
  5980. With argument SPECIAL, show all possible log items, not only the ones
  5981. configured in `org-agenda-log-mode-items'.
  5982. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5983. (interactive "P")
  5984. (org-agenda-check-type t 'agenda 'timeline)
  5985. (setq org-agenda-show-log
  5986. (if (equal special '(16))
  5987. 'only
  5988. (if special '(closed clock state)
  5989. (not org-agenda-show-log))))
  5990. (org-agenda-set-mode-name)
  5991. (org-agenda-redo)
  5992. (message "Log mode is %s"
  5993. (if org-agenda-show-log "on" "off")))
  5994. (defun org-agenda-archives-mode (&optional with-files)
  5995. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5996. When called with a prefix argument, include all archive files as well."
  5997. (interactive "P")
  5998. (setq org-agenda-archives-mode
  5999. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6000. (org-agenda-set-mode-name)
  6001. (org-agenda-redo)
  6002. (message
  6003. "%s"
  6004. (cond
  6005. ((eq org-agenda-archives-mode nil)
  6006. "No archives are included")
  6007. ((eq org-agenda-archives-mode 'trees)
  6008. (format "Trees with :%s: tag are included" org-archive-tag))
  6009. ((eq org-agenda-archives-mode t)
  6010. (format "Trees with :%s: tag and all active archive files are included"
  6011. org-archive-tag)))))
  6012. (defun org-agenda-toggle-diary ()
  6013. "Toggle diary inclusion in an agenda buffer."
  6014. (interactive)
  6015. (org-agenda-check-type t 'agenda)
  6016. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6017. (org-agenda-redo)
  6018. (org-agenda-set-mode-name)
  6019. (message "Diary inclusion turned %s"
  6020. (if org-agenda-include-diary "on" "off")))
  6021. (defun org-agenda-toggle-deadlines ()
  6022. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6023. (interactive)
  6024. (org-agenda-check-type t 'agenda)
  6025. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6026. (org-agenda-redo)
  6027. (org-agenda-set-mode-name)
  6028. (message "Deadlines inclusion turned %s"
  6029. (if org-agenda-include-deadlines "on" "off")))
  6030. (defun org-agenda-toggle-time-grid ()
  6031. "Toggle time grid in an agenda buffer."
  6032. (interactive)
  6033. (org-agenda-check-type t 'agenda)
  6034. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6035. (org-agenda-redo)
  6036. (org-agenda-set-mode-name)
  6037. (message "Time-grid turned %s"
  6038. (if org-agenda-use-time-grid "on" "off")))
  6039. (defun org-agenda-set-mode-name ()
  6040. "Set the mode name to indicate all the small mode settings."
  6041. (setq mode-name
  6042. (list "Org-Agenda"
  6043. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6044. " "
  6045. '(:eval (org-agenda-span-name org-agenda-current-span))
  6046. (if org-agenda-follow-mode " Follow" "")
  6047. (if org-agenda-entry-text-mode " ETxt" "")
  6048. (if org-agenda-include-diary " Diary" "")
  6049. (if org-agenda-include-deadlines " Ddl" "")
  6050. (if org-agenda-use-time-grid " Grid" "")
  6051. (if (and (boundp 'org-habit-show-habits)
  6052. org-habit-show-habits) " Habit" "")
  6053. (if (consp org-agenda-show-log) " LogAll"
  6054. (if org-agenda-show-log " Log" ""))
  6055. (if (or org-agenda-filter (get 'org-agenda-filter
  6056. :preset-filter))
  6057. (concat " {" (mapconcat
  6058. 'identity
  6059. (append (get 'org-agenda-filter
  6060. :preset-filter)
  6061. org-agenda-filter) "") "}")
  6062. "")
  6063. (if org-agenda-archives-mode
  6064. (if (eq org-agenda-archives-mode t)
  6065. " Archives"
  6066. (format " :%s:" org-archive-tag))
  6067. "")
  6068. (if org-agenda-clockreport-mode
  6069. (if (eq org-agenda-clockreport-mode 'with-filter)
  6070. " Clock{}" " Clock")
  6071. "")))
  6072. (force-mode-line-update))
  6073. (defun org-agenda-post-command-hook ()
  6074. (setq org-agenda-type
  6075. (or (get-text-property (point) 'org-agenda-type)
  6076. (get-text-property (max (point-min) (1- (point)))
  6077. 'org-agenda-type))))
  6078. (defun org-agenda-next-line ()
  6079. "Move cursor to the next line, and show if follow mode is active."
  6080. (interactive)
  6081. (call-interactively 'next-line)
  6082. (org-agenda-do-context-action))
  6083. (defun org-agenda-previous-line ()
  6084. "Move cursor to the previous line, and show if follow-mode is active."
  6085. (interactive)
  6086. (call-interactively 'previous-line)
  6087. (org-agenda-do-context-action))
  6088. (defun org-agenda-do-context-action ()
  6089. "Show outline path and, maybe, follow mode window."
  6090. (let ((m (org-get-at-bol 'org-marker)))
  6091. (if (and org-agenda-follow-mode m)
  6092. (org-agenda-show))
  6093. (if (and m org-agenda-show-outline-path)
  6094. (org-with-point-at m
  6095. (org-display-outline-path t)))))
  6096. (defun org-agenda-show-priority ()
  6097. "Show the priority of the current item.
  6098. This priority is composed of the main priority given with the [#A] cookies,
  6099. and by additional input from the age of a schedules or deadline entry."
  6100. (interactive)
  6101. (let* ((pri (org-get-at-bol 'priority)))
  6102. (message "Priority is %d" (if pri pri -1000))))
  6103. (defun org-agenda-show-tags ()
  6104. "Show the tags applicable to the current item."
  6105. (interactive)
  6106. (let* ((tags (org-get-at-bol 'tags)))
  6107. (if tags
  6108. (message "Tags are :%s:"
  6109. (org-no-properties (mapconcat 'identity tags ":")))
  6110. (message "No tags associated with this line"))))
  6111. (defun org-agenda-goto (&optional highlight)
  6112. "Go to the Org-mode file which contains the item at point."
  6113. (interactive)
  6114. (let* ((marker (or (org-get-at-bol 'org-marker)
  6115. (org-agenda-error)))
  6116. (buffer (marker-buffer marker))
  6117. (pos (marker-position marker)))
  6118. (switch-to-buffer-other-window buffer)
  6119. (widen)
  6120. (push-mark)
  6121. (goto-char pos)
  6122. (when (org-mode-p)
  6123. (org-show-context 'agenda)
  6124. (save-excursion
  6125. (and (outline-next-heading)
  6126. (org-flag-heading nil)))) ; show the next heading
  6127. (when (outline-invisible-p)
  6128. (show-entry)) ; display invisible text
  6129. (recenter (/ (window-height) 2))
  6130. (run-hooks 'org-agenda-after-show-hook)
  6131. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6132. (defvar org-agenda-after-show-hook nil
  6133. "Normal hook run after an item has been shown from the agenda.
  6134. Point is in the buffer where the item originated.")
  6135. (defun org-agenda-kill ()
  6136. "Kill the entry or subtree belonging to the current agenda entry."
  6137. (interactive)
  6138. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6139. (let* ((marker (or (org-get-at-bol 'org-marker)
  6140. (org-agenda-error)))
  6141. (buffer (marker-buffer marker))
  6142. (pos (marker-position marker))
  6143. (type (org-get-at-bol 'type))
  6144. dbeg dend (n 0) conf)
  6145. (org-with-remote-undo buffer
  6146. (with-current-buffer buffer
  6147. (save-excursion
  6148. (goto-char pos)
  6149. (if (and (org-mode-p) (not (member type '("sexp"))))
  6150. (setq dbeg (progn (org-back-to-heading t) (point))
  6151. dend (org-end-of-subtree t t))
  6152. (setq dbeg (point-at-bol)
  6153. dend (min (point-max) (1+ (point-at-eol)))))
  6154. (goto-char dbeg)
  6155. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6156. (setq conf (or (eq t org-agenda-confirm-kill)
  6157. (and (numberp org-agenda-confirm-kill)
  6158. (> n org-agenda-confirm-kill))))
  6159. (and conf
  6160. (not (y-or-n-p
  6161. (format "Delete entry with %d lines in buffer \"%s\"? "
  6162. n (buffer-name buffer))))
  6163. (error "Abort"))
  6164. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6165. (with-current-buffer buffer (delete-region dbeg dend))
  6166. (message "Agenda item and source killed"))))
  6167. (defvar org-archive-default-command)
  6168. (defun org-agenda-archive-default ()
  6169. "Archive the entry or subtree belonging to the current agenda entry."
  6170. (interactive)
  6171. (require 'org-archive)
  6172. (org-agenda-archive-with org-archive-default-command))
  6173. (defun org-agenda-archive-default-with-confirmation ()
  6174. "Archive the entry or subtree belonging to the current agenda entry."
  6175. (interactive)
  6176. (require 'org-archive)
  6177. (org-agenda-archive-with org-archive-default-command 'confirm))
  6178. (defun org-agenda-archive ()
  6179. "Archive the entry or subtree belonging to the current agenda entry."
  6180. (interactive)
  6181. (org-agenda-archive-with 'org-archive-subtree))
  6182. (defun org-agenda-archive-to-archive-sibling ()
  6183. "Move the entry to the archive sibling."
  6184. (interactive)
  6185. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6186. (defun org-agenda-archive-with (cmd &optional confirm)
  6187. "Move the entry to the archive sibling."
  6188. (interactive)
  6189. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6190. (let* ((marker (or (org-get-at-bol 'org-marker)
  6191. (org-agenda-error)))
  6192. (buffer (marker-buffer marker))
  6193. (pos (marker-position marker)))
  6194. (org-with-remote-undo buffer
  6195. (with-current-buffer buffer
  6196. (if (org-mode-p)
  6197. (if (and confirm
  6198. (not (y-or-n-p "Archive this subtree or entry? ")))
  6199. (error "Abort")
  6200. (save-excursion
  6201. (goto-char pos)
  6202. (org-remove-subtree-entries-from-agenda)
  6203. (org-back-to-heading t)
  6204. (funcall cmd)))
  6205. (error "Archiving works only in Org-mode files"))))))
  6206. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6207. "Remove all lines in the agenda that correspond to a given subtree.
  6208. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6209. If this information is not given, the function uses the tree at point."
  6210. (let ((buf (or buf (current-buffer))) m p)
  6211. (save-excursion
  6212. (unless (and beg end)
  6213. (org-back-to-heading t)
  6214. (setq beg (point))
  6215. (org-end-of-subtree t)
  6216. (setq end (point)))
  6217. (set-buffer (get-buffer org-agenda-buffer-name))
  6218. (save-excursion
  6219. (goto-char (point-max))
  6220. (beginning-of-line 1)
  6221. (while (not (bobp))
  6222. (when (and (setq m (org-get-at-bol 'org-marker))
  6223. (equal buf (marker-buffer m))
  6224. (setq p (marker-position m))
  6225. (>= p beg)
  6226. (< p end))
  6227. (let ((inhibit-read-only t))
  6228. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6229. (beginning-of-line 0))))))
  6230. (defun org-agenda-refile (&optional goto rfloc no-update)
  6231. "Refile the item at point."
  6232. (interactive "P")
  6233. (if (equal goto '(16))
  6234. (org-refile-goto-last-stored)
  6235. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6236. (org-agenda-error)))
  6237. (buffer (marker-buffer marker))
  6238. (pos (marker-position marker))
  6239. (rfloc (or rfloc
  6240. (org-refile-get-location
  6241. (if goto "Goto" "Refile to") buffer
  6242. org-refile-allow-creating-parent-nodes))))
  6243. (with-current-buffer buffer
  6244. (save-excursion
  6245. (save-restriction
  6246. (widen)
  6247. (goto-char marker)
  6248. (org-remove-subtree-entries-from-agenda)
  6249. (org-refile goto buffer rfloc)))))
  6250. (unless no-update (org-agenda-redo))))
  6251. (defun org-agenda-open-link (&optional arg)
  6252. "Follow the link in the current line, if any.
  6253. This looks for a link in the displayed line in the agenda. It also looks
  6254. at the text of the entry itself."
  6255. (interactive "P")
  6256. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6257. (org-get-at-bol 'org-marker)))
  6258. (buffer (and marker (marker-buffer marker)))
  6259. (prefix (buffer-substring
  6260. (point-at-bol)
  6261. (+ (point-at-bol)
  6262. (or (org-get-at-bol 'prefix-length) 0)))))
  6263. (cond
  6264. (buffer
  6265. (with-current-buffer buffer
  6266. (save-excursion
  6267. (save-restriction
  6268. (widen)
  6269. (goto-char marker)
  6270. (org-offer-links-in-entry arg prefix)))))
  6271. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6272. (save-excursion
  6273. (beginning-of-line 1)
  6274. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6275. (org-open-link-from-string (match-string 1)))
  6276. (t (error "No link to open here")))))
  6277. (defun org-agenda-copy-local-variable (var)
  6278. "Get a variable from a referenced buffer and install it here."
  6279. (let ((m (org-get-at-bol 'org-marker)))
  6280. (when (and m (buffer-live-p (marker-buffer m)))
  6281. (org-set-local var (with-current-buffer (marker-buffer m)
  6282. (symbol-value var))))))
  6283. (defun org-agenda-switch-to (&optional delete-other-windows)
  6284. "Go to the Org-mode file which contains the item at point."
  6285. (interactive)
  6286. (if (and org-return-follows-link
  6287. (not (org-get-at-bol 'org-marker))
  6288. (org-in-regexp org-bracket-link-regexp))
  6289. (org-open-link-from-string (match-string 0))
  6290. (let* ((marker (or (org-get-at-bol 'org-marker)
  6291. (org-agenda-error)))
  6292. (buffer (marker-buffer marker))
  6293. (pos (marker-position marker)))
  6294. (switch-to-buffer buffer)
  6295. (and delete-other-windows (delete-other-windows))
  6296. (widen)
  6297. (goto-char pos)
  6298. (when (org-mode-p)
  6299. (org-show-context 'agenda)
  6300. (save-excursion
  6301. (and (outline-next-heading)
  6302. (org-flag-heading nil))) ; show the next heading
  6303. (when (outline-invisible-p)
  6304. (show-entry)))))) ; display invisible text
  6305. (defun org-agenda-goto-mouse (ev)
  6306. "Go to the Org-mode file which contains the item at the mouse click."
  6307. (interactive "e")
  6308. (mouse-set-point ev)
  6309. (org-agenda-goto))
  6310. (defun org-agenda-show (&optional full-entry)
  6311. "Display the Org-mode file which contains the item at point.
  6312. With prefix argument FULL-ENTRY, make the entire entry visible
  6313. if it was hidden in the outline."
  6314. (interactive "P")
  6315. (let ((win (selected-window)))
  6316. (if full-entry
  6317. (let ((org-show-entry-below t))
  6318. (org-agenda-goto t))
  6319. (org-agenda-goto t))
  6320. (select-window win)))
  6321. (defvar org-agenda-show-window nil)
  6322. (defun org-agenda-show-and-scroll-up ()
  6323. "Display the Org-mode file which contains the item at point.
  6324. When called repeatedly, scroll the window that is displaying the buffer."
  6325. (interactive)
  6326. (let ((win (selected-window)))
  6327. (if (and (window-live-p org-agenda-show-window)
  6328. (eq this-command last-command))
  6329. (progn
  6330. (select-window org-agenda-show-window)
  6331. (ignore-errors (scroll-up)))
  6332. (org-agenda-goto t)
  6333. (show-subtree)
  6334. (setq org-agenda-show-window (selected-window)))
  6335. (select-window win)))
  6336. (defun org-agenda-show-scroll-down ()
  6337. "Scroll down the window showing the agenda."
  6338. (interactive)
  6339. (let ((win (selected-window)))
  6340. (when (window-live-p org-agenda-show-window)
  6341. (select-window org-agenda-show-window)
  6342. (ignore-errors (scroll-down))
  6343. (select-window win))))
  6344. (defun org-agenda-show-1 (&optional more)
  6345. "Display the Org-mode file which contains the item at point.
  6346. The prefix arg selects the amount of information to display:
  6347. 0 hide the subtree
  6348. 1 just show the entry according to defaults.
  6349. 2 show the children view
  6350. 3 show the subtree view
  6351. 4 show the entire subtree and any LOGBOOK drawers
  6352. 5 show the entire subtree and any drawers
  6353. With prefix argument FULL-ENTRY, make the entire entry visible
  6354. if it was hidden in the outline."
  6355. (interactive "p")
  6356. (let ((win (selected-window)))
  6357. (org-agenda-goto t)
  6358. (org-recenter-heading 1)
  6359. (cond
  6360. ((= more 0)
  6361. (hide-subtree)
  6362. (save-excursion
  6363. (org-back-to-heading)
  6364. (run-hook-with-args 'org-cycle-hook 'folded))
  6365. (message "Remote: FOLDED"))
  6366. ((and (interactive-p) (= more 1))
  6367. (message "Remote: show with default settings"))
  6368. ((= more 2)
  6369. (show-entry)
  6370. (show-children)
  6371. (save-excursion
  6372. (org-back-to-heading)
  6373. (run-hook-with-args 'org-cycle-hook 'children))
  6374. (message "Remote: CHILDREN"))
  6375. ((= more 3)
  6376. (show-subtree)
  6377. (save-excursion
  6378. (org-back-to-heading)
  6379. (run-hook-with-args 'org-cycle-hook 'subtree))
  6380. (message "Remote: SUBTREE"))
  6381. ((= more 4)
  6382. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6383. (org-drawer-regexp
  6384. (concat "^[ \t]*:\\("
  6385. (mapconcat 'regexp-quote org-drawers "\\|")
  6386. "\\):[ \t]*$")))
  6387. (show-subtree)
  6388. (save-excursion
  6389. (org-back-to-heading)
  6390. (org-cycle-hide-drawers 'subtree)))
  6391. (message "Remote: SUBTREE AND LOGBOOK"))
  6392. ((> more 4)
  6393. (show-subtree)
  6394. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6395. (select-window win)))
  6396. (defun org-recenter-heading (n)
  6397. (save-excursion
  6398. (org-back-to-heading)
  6399. (recenter n)))
  6400. (defvar org-agenda-cycle-counter nil)
  6401. (defun org-agenda-cycle-show (&optional n)
  6402. "Show the current entry in another window, with default settings.
  6403. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6404. When use repeatedly in immediate succession, the remote entry will cycle
  6405. through visibility
  6406. children -> subtree -> folded
  6407. When called with a numeric prefix arg, that arg will be passed through to
  6408. `org-agenda-show-1'. For the interpretation of that argument, see the
  6409. docstring of `org-agenda-show-1'."
  6410. (interactive "P")
  6411. (if (integerp n)
  6412. (setq org-agenda-cycle-counter n)
  6413. (if (not (eq last-command this-command))
  6414. (setq org-agenda-cycle-counter 1)
  6415. (if (equal org-agenda-cycle-counter 0)
  6416. (setq org-agenda-cycle-counter 2)
  6417. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6418. (if (> org-agenda-cycle-counter 3)
  6419. (setq org-agenda-cycle-counter 0)))))
  6420. (org-agenda-show-1 org-agenda-cycle-counter))
  6421. (defun org-agenda-recenter (arg)
  6422. "Display the Org-mode file which contains the item at point and recenter."
  6423. (interactive "P")
  6424. (let ((win (selected-window)))
  6425. (org-agenda-goto t)
  6426. (recenter arg)
  6427. (select-window win)))
  6428. (defun org-agenda-show-mouse (ev)
  6429. "Display the Org-mode file which contains the item at the mouse click."
  6430. (interactive "e")
  6431. (mouse-set-point ev)
  6432. (org-agenda-show))
  6433. (defun org-agenda-check-no-diary ()
  6434. "Check if the entry is a diary link and abort if yes."
  6435. (if (org-get-at-bol 'org-agenda-diary-link)
  6436. (org-agenda-error)))
  6437. (defun org-agenda-error ()
  6438. (error "Command not allowed in this line"))
  6439. (defun org-agenda-tree-to-indirect-buffer ()
  6440. "Show the subtree corresponding to the current entry in an indirect buffer.
  6441. This calls the command `org-tree-to-indirect-buffer' from the original
  6442. Org-mode buffer.
  6443. With numerical prefix arg ARG, go up to this level and then take that tree.
  6444. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6445. use the dedicated frame)."
  6446. (interactive)
  6447. (org-agenda-check-no-diary)
  6448. (let* ((marker (or (org-get-at-bol 'org-marker)
  6449. (org-agenda-error)))
  6450. (buffer (marker-buffer marker))
  6451. (pos (marker-position marker)))
  6452. (with-current-buffer buffer
  6453. (save-excursion
  6454. (goto-char pos)
  6455. (call-interactively 'org-tree-to-indirect-buffer)))))
  6456. (defvar org-last-heading-marker (make-marker)
  6457. "Marker pointing to the headline that last changed its TODO state
  6458. by a remote command from the agenda.")
  6459. (defun org-agenda-todo-nextset ()
  6460. "Switch TODO entry to next sequence."
  6461. (interactive)
  6462. (org-agenda-todo 'nextset))
  6463. (defun org-agenda-todo-previousset ()
  6464. "Switch TODO entry to previous sequence."
  6465. (interactive)
  6466. (org-agenda-todo 'previousset))
  6467. (defun org-agenda-todo (&optional arg)
  6468. "Cycle TODO state of line at point, also in Org-mode file.
  6469. This changes the line at point, all other lines in the agenda referring to
  6470. the same tree node, and the headline of the tree node in the Org-mode file."
  6471. (interactive "P")
  6472. (org-agenda-check-no-diary)
  6473. (let* ((col (current-column))
  6474. (marker (or (org-get-at-bol 'org-marker)
  6475. (org-agenda-error)))
  6476. (buffer (marker-buffer marker))
  6477. (pos (marker-position marker))
  6478. (hdmarker (org-get-at-bol 'org-hd-marker))
  6479. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6480. (inhibit-read-only t)
  6481. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6482. (org-with-remote-undo buffer
  6483. (with-current-buffer buffer
  6484. (widen)
  6485. (goto-char pos)
  6486. (org-show-context 'agenda)
  6487. (save-excursion
  6488. (and (outline-next-heading)
  6489. (org-flag-heading nil))) ; show the next heading
  6490. (let ((current-prefix-arg arg))
  6491. (call-interactively 'org-todo))
  6492. (and (bolp) (forward-char 1))
  6493. (setq newhead (org-get-heading))
  6494. (when (and (org-bound-and-true-p
  6495. org-agenda-headline-snapshot-before-repeat)
  6496. (not (equal org-agenda-headline-snapshot-before-repeat
  6497. newhead))
  6498. todayp)
  6499. (setq newhead org-agenda-headline-snapshot-before-repeat
  6500. just-one t))
  6501. (save-excursion
  6502. (org-back-to-heading)
  6503. (move-marker org-last-heading-marker (point))))
  6504. (beginning-of-line 1)
  6505. (save-excursion
  6506. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6507. (org-move-to-column col))))
  6508. (defun org-agenda-add-note (&optional arg)
  6509. "Add a time-stamped note to the entry at point."
  6510. (interactive "P")
  6511. (org-agenda-check-no-diary)
  6512. (let* ((marker (or (org-get-at-bol 'org-marker)
  6513. (org-agenda-error)))
  6514. (buffer (marker-buffer marker))
  6515. (pos (marker-position marker))
  6516. (hdmarker (org-get-at-bol 'org-hd-marker))
  6517. (inhibit-read-only t))
  6518. (with-current-buffer buffer
  6519. (widen)
  6520. (goto-char pos)
  6521. (org-show-context 'agenda)
  6522. (save-excursion
  6523. (and (outline-next-heading)
  6524. (org-flag-heading nil))) ; show the next heading
  6525. (org-add-note))))
  6526. (defun org-agenda-change-all-lines (newhead hdmarker
  6527. &optional fixface just-this)
  6528. "Change all lines in the agenda buffer which match HDMARKER.
  6529. The new content of the line will be NEWHEAD (as modified by
  6530. `org-format-agenda-item'). HDMARKER is checked with
  6531. `equal' against all `org-hd-marker' text properties in the file.
  6532. If FIXFACE is non-nil, the face of each item is modified according to
  6533. the new TODO state.
  6534. If JUST-THIS is non-nil, change just the current line, not all.
  6535. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6536. (let* ((inhibit-read-only t)
  6537. (line (org-current-line))
  6538. (thetags (with-current-buffer (marker-buffer hdmarker)
  6539. (save-excursion (save-restriction (widen)
  6540. (goto-char hdmarker)
  6541. (org-get-tags-at)))))
  6542. props m pl undone-face done-face finish new dotime cat tags)
  6543. (save-excursion
  6544. (goto-char (point-max))
  6545. (beginning-of-line 1)
  6546. (while (not finish)
  6547. (setq finish (bobp))
  6548. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6549. (or (not just-this) (= (org-current-line) line))
  6550. (equal m hdmarker))
  6551. (setq props (text-properties-at (point))
  6552. dotime (org-get-at-bol 'dotime)
  6553. cat (org-get-at-bol 'org-category)
  6554. tags thetags
  6555. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6556. pl (org-get-at-bol 'prefix-length)
  6557. undone-face (org-get-at-bol 'undone-face)
  6558. done-face (org-get-at-bol 'done-face))
  6559. (goto-char (+ (point) pl))
  6560. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6561. (cond
  6562. ((equal new "")
  6563. (beginning-of-line 1)
  6564. (and (looking-at ".*\n?") (replace-match "")))
  6565. ((looking-at ".*")
  6566. (replace-match new t t)
  6567. (beginning-of-line 1)
  6568. (add-text-properties (point-at-bol) (point-at-eol) props)
  6569. (when fixface
  6570. (add-text-properties
  6571. (point-at-bol) (point-at-eol)
  6572. (list 'face
  6573. (if org-last-todo-state-is-todo
  6574. undone-face done-face))))
  6575. (org-agenda-highlight-todo 'line)
  6576. (beginning-of-line 1))
  6577. (t (error "Line update did not work"))))
  6578. (beginning-of-line 0)))
  6579. (org-finalize-agenda)))
  6580. (defun org-agenda-align-tags (&optional line)
  6581. "Align all tags in agenda items to `org-agenda-tags-column'."
  6582. (let ((inhibit-read-only t) l c)
  6583. (save-excursion
  6584. (goto-char (if line (point-at-bol) (point-min)))
  6585. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6586. (if line (point-at-eol) nil) t)
  6587. (add-text-properties
  6588. (match-beginning 2) (match-end 2)
  6589. (list 'face (delq nil (let ((prop (get-text-property
  6590. (match-beginning 2) 'face)))
  6591. (or (listp prop) (setq prop (list prop)))
  6592. (if (memq 'org-tag prop)
  6593. prop
  6594. (cons 'org-tag prop))))))
  6595. (setq l (- (match-end 2) (match-beginning 2))
  6596. c (if (< org-agenda-tags-column 0)
  6597. (- (abs org-agenda-tags-column) l)
  6598. org-agenda-tags-column))
  6599. (delete-region (match-beginning 1) (match-end 1))
  6600. (goto-char (match-beginning 1))
  6601. (insert (org-add-props
  6602. (make-string (max 1 (- c (current-column))) ?\ )
  6603. (plist-put (copy-sequence (text-properties-at (point)))
  6604. 'face nil))))
  6605. (goto-char (point-min))
  6606. (org-font-lock-add-tag-faces (point-max)))))
  6607. (defun org-agenda-priority-up ()
  6608. "Increase the priority of line at point, also in Org-mode file."
  6609. (interactive)
  6610. (org-agenda-priority 'up))
  6611. (defun org-agenda-priority-down ()
  6612. "Decrease the priority of line at point, also in Org-mode file."
  6613. (interactive)
  6614. (org-agenda-priority 'down))
  6615. (defun org-agenda-priority (&optional force-direction)
  6616. "Set the priority of line at point, also in Org-mode file.
  6617. This changes the line at point, all other lines in the agenda referring to
  6618. the same tree node, and the headline of the tree node in the Org-mode file."
  6619. (interactive)
  6620. (unless org-enable-priority-commands
  6621. (error "Priority commands are disabled"))
  6622. (org-agenda-check-no-diary)
  6623. (let* ((marker (or (org-get-at-bol 'org-marker)
  6624. (org-agenda-error)))
  6625. (hdmarker (org-get-at-bol 'org-hd-marker))
  6626. (buffer (marker-buffer hdmarker))
  6627. (pos (marker-position hdmarker))
  6628. (inhibit-read-only t)
  6629. newhead)
  6630. (org-with-remote-undo buffer
  6631. (with-current-buffer buffer
  6632. (widen)
  6633. (goto-char pos)
  6634. (org-show-context 'agenda)
  6635. (save-excursion
  6636. (and (outline-next-heading)
  6637. (org-flag-heading nil))) ; show the next heading
  6638. (funcall 'org-priority force-direction)
  6639. (end-of-line 1)
  6640. (setq newhead (org-get-heading)))
  6641. (org-agenda-change-all-lines newhead hdmarker)
  6642. (beginning-of-line 1))))
  6643. ;; FIXME: should fix the tags property of the agenda line.
  6644. (defun org-agenda-set-tags (&optional tag onoff)
  6645. "Set tags for the current headline."
  6646. (interactive)
  6647. (org-agenda-check-no-diary)
  6648. (if (and (org-region-active-p) (interactive-p))
  6649. (call-interactively 'org-change-tag-in-region)
  6650. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6651. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6652. (org-agenda-error)))
  6653. (buffer (marker-buffer hdmarker))
  6654. (pos (marker-position hdmarker))
  6655. (inhibit-read-only t)
  6656. newhead)
  6657. (org-with-remote-undo buffer
  6658. (with-current-buffer buffer
  6659. (widen)
  6660. (goto-char pos)
  6661. (save-excursion
  6662. (org-show-context 'agenda))
  6663. (save-excursion
  6664. (and (outline-next-heading)
  6665. (org-flag-heading nil))) ; show the next heading
  6666. (goto-char pos)
  6667. (if tag
  6668. (org-toggle-tag tag onoff)
  6669. (call-interactively 'org-set-tags))
  6670. (end-of-line 1)
  6671. (setq newhead (org-get-heading)))
  6672. (org-agenda-change-all-lines newhead hdmarker)
  6673. (beginning-of-line 1)))))
  6674. (defun org-agenda-set-property ()
  6675. "Set a property for the current headline."
  6676. (interactive)
  6677. (org-agenda-check-no-diary)
  6678. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6679. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6680. (org-agenda-error)))
  6681. (buffer (marker-buffer hdmarker))
  6682. (pos (marker-position hdmarker))
  6683. (inhibit-read-only t)
  6684. newhead)
  6685. (org-with-remote-undo buffer
  6686. (with-current-buffer buffer
  6687. (widen)
  6688. (goto-char pos)
  6689. (save-excursion
  6690. (org-show-context 'agenda))
  6691. (save-excursion
  6692. (and (outline-next-heading)
  6693. (org-flag-heading nil))) ; show the next heading
  6694. (goto-char pos)
  6695. (call-interactively 'org-set-property)))))
  6696. (defun org-agenda-set-effort ()
  6697. "Set the effort property for the current headline."
  6698. (interactive)
  6699. (org-agenda-check-no-diary)
  6700. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6701. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6702. (org-agenda-error)))
  6703. (buffer (marker-buffer hdmarker))
  6704. (pos (marker-position hdmarker))
  6705. (inhibit-read-only t)
  6706. newhead)
  6707. (org-with-remote-undo buffer
  6708. (with-current-buffer buffer
  6709. (widen)
  6710. (goto-char pos)
  6711. (save-excursion
  6712. (org-show-context 'agenda))
  6713. (save-excursion
  6714. (and (outline-next-heading)
  6715. (org-flag-heading nil))) ; show the next heading
  6716. (goto-char pos)
  6717. (call-interactively 'org-set-effort)
  6718. (end-of-line 1)))))
  6719. (defun org-agenda-toggle-archive-tag ()
  6720. "Toggle the archive tag for the current entry."
  6721. (interactive)
  6722. (org-agenda-check-no-diary)
  6723. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6724. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6725. (org-agenda-error)))
  6726. (buffer (marker-buffer hdmarker))
  6727. (pos (marker-position hdmarker))
  6728. (inhibit-read-only t)
  6729. newhead)
  6730. (org-with-remote-undo buffer
  6731. (with-current-buffer buffer
  6732. (widen)
  6733. (goto-char pos)
  6734. (org-show-context 'agenda)
  6735. (save-excursion
  6736. (and (outline-next-heading)
  6737. (org-flag-heading nil))) ; show the next heading
  6738. (call-interactively 'org-toggle-archive-tag)
  6739. (end-of-line 1)
  6740. (setq newhead (org-get-heading)))
  6741. (org-agenda-change-all-lines newhead hdmarker)
  6742. (beginning-of-line 1))))
  6743. (defun org-agenda-do-date-later (arg)
  6744. (interactive "P")
  6745. (cond
  6746. ((or (equal arg '(16))
  6747. (memq last-command
  6748. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6749. (setq this-command 'org-agenda-date-later-minutes)
  6750. (org-agenda-date-later-minutes 1))
  6751. ((or (equal arg '(4))
  6752. (memq last-command
  6753. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6754. (setq this-command 'org-agenda-date-later-hours)
  6755. (org-agenda-date-later-hours 1))
  6756. (t
  6757. (org-agenda-date-later (prefix-numeric-value arg)))))
  6758. (defun org-agenda-do-date-earlier (arg)
  6759. (interactive "P")
  6760. (cond
  6761. ((or (equal arg '(16))
  6762. (memq last-command
  6763. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6764. (setq this-command 'org-agenda-date-earlier-minutes)
  6765. (org-agenda-date-earlier-minutes 1))
  6766. ((or (equal arg '(4))
  6767. (memq last-command
  6768. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6769. (setq this-command 'org-agenda-date-earlier-hours)
  6770. (org-agenda-date-earlier-hours 1))
  6771. (t
  6772. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6773. (defun org-agenda-date-later (arg &optional what)
  6774. "Change the date of this item to ARG day(s) later."
  6775. (interactive "p")
  6776. (org-agenda-check-type t 'agenda 'timeline)
  6777. (org-agenda-check-no-diary)
  6778. (let* ((marker (or (org-get-at-bol 'org-marker)
  6779. (org-agenda-error)))
  6780. (buffer (marker-buffer marker))
  6781. (pos (marker-position marker)))
  6782. (org-with-remote-undo buffer
  6783. (with-current-buffer buffer
  6784. (widen)
  6785. (goto-char pos)
  6786. (if (not (org-at-timestamp-p))
  6787. (error "Cannot find time stamp"))
  6788. (org-timestamp-change arg (or what 'day)))
  6789. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6790. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6791. (defun org-agenda-date-earlier (arg &optional what)
  6792. "Change the date of this item to ARG day(s) earlier."
  6793. (interactive "p")
  6794. (org-agenda-date-later (- arg) what))
  6795. (defun org-agenda-date-later-minutes (arg)
  6796. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6797. (interactive "p")
  6798. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6799. (org-agenda-date-later arg 'minute))
  6800. (defun org-agenda-date-earlier-minutes (arg)
  6801. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6802. (interactive "p")
  6803. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6804. (org-agenda-date-earlier arg 'minute))
  6805. (defun org-agenda-date-later-hours (arg)
  6806. "Change the time of this item, in hour steps."
  6807. (interactive "p")
  6808. (org-agenda-date-later arg 'hour))
  6809. (defun org-agenda-date-earlier-hours (arg)
  6810. "Change the time of this item, in hour steps."
  6811. (interactive "p")
  6812. (org-agenda-date-earlier arg 'hour))
  6813. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6814. "Show new date stamp via text properties."
  6815. ;; We use text properties to make this undoable
  6816. (let ((inhibit-read-only t)
  6817. (buffer-invisibility-spec))
  6818. (setq stamp (concat " " prefix " => " stamp))
  6819. (save-excursion
  6820. (goto-char (point-max))
  6821. (while (not (bobp))
  6822. (when (equal marker (org-get-at-bol 'org-marker))
  6823. (org-move-to-column (- (window-width) (length stamp)) t)
  6824. (org-agenda-fix-tags-filter-overlays-at (point))
  6825. (if (featurep 'xemacs)
  6826. ;; Use `duplicable' property to trigger undo recording
  6827. (let ((ex (make-extent nil nil))
  6828. (gl (make-glyph stamp)))
  6829. (set-glyph-face gl 'secondary-selection)
  6830. (set-extent-properties
  6831. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6832. (insert-extent ex (1- (point)) (point-at-eol)))
  6833. (add-text-properties
  6834. (1- (point)) (point-at-eol)
  6835. (list 'display (org-add-props stamp nil
  6836. 'face 'secondary-selection))))
  6837. (beginning-of-line 1))
  6838. (beginning-of-line 0)))))
  6839. (defun org-agenda-date-prompt (arg)
  6840. "Change the date of this item. Date is prompted for, with default today.
  6841. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6842. be used to request time specification in the time stamp."
  6843. (interactive "P")
  6844. (org-agenda-check-type t 'agenda 'timeline)
  6845. (org-agenda-check-no-diary)
  6846. (let* ((marker (or (org-get-at-bol 'org-marker)
  6847. (org-agenda-error)))
  6848. (buffer (marker-buffer marker))
  6849. (pos (marker-position marker)))
  6850. (org-with-remote-undo buffer
  6851. (with-current-buffer buffer
  6852. (widen)
  6853. (goto-char pos)
  6854. (if (not (org-at-timestamp-p t))
  6855. (error "Cannot find time stamp"))
  6856. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6857. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6858. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6859. (defun org-agenda-schedule (arg &optional time)
  6860. "Schedule the item at point.
  6861. Arg is passed through to `org-schedule'."
  6862. (interactive "P")
  6863. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6864. (org-agenda-check-no-diary)
  6865. (let* ((marker (or (org-get-at-bol 'org-marker)
  6866. (org-agenda-error)))
  6867. (type (marker-insertion-type marker))
  6868. (buffer (marker-buffer marker))
  6869. (pos (marker-position marker))
  6870. (org-insert-labeled-timestamps-at-point nil)
  6871. ts)
  6872. (set-marker-insertion-type marker t)
  6873. (org-with-remote-undo buffer
  6874. (with-current-buffer buffer
  6875. (widen)
  6876. (goto-char pos)
  6877. (setq ts (org-schedule arg time)))
  6878. (org-agenda-show-new-time marker ts "S"))
  6879. (message "Item scheduled for %s" ts)))
  6880. (defun org-agenda-deadline (arg &optional time)
  6881. "Schedule the item at point.
  6882. Arg is passed through to `org-deadline'."
  6883. (interactive "P")
  6884. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6885. (org-agenda-check-no-diary)
  6886. (let* ((marker (or (org-get-at-bol 'org-marker)
  6887. (org-agenda-error)))
  6888. (buffer (marker-buffer marker))
  6889. (pos (marker-position marker))
  6890. (org-insert-labeled-timestamps-at-point nil)
  6891. ts)
  6892. (org-with-remote-undo buffer
  6893. (with-current-buffer buffer
  6894. (widen)
  6895. (goto-char pos)
  6896. (setq ts (org-deadline arg time)))
  6897. (org-agenda-show-new-time marker ts "D"))
  6898. (message "Deadline for this item set to %s" ts)))
  6899. (defun org-agenda-action ()
  6900. "Select entry for agenda action, or execute an agenda action.
  6901. This command prompts for another letter. Valid inputs are:
  6902. m Mark the entry at point for an agenda action
  6903. s Schedule the marked entry to the date at the cursor
  6904. d Set the deadline of the marked entry to the date at the cursor
  6905. r Call `org-remember' with cursor date as the default date
  6906. c Call `org-capture' with cursor date as the default date
  6907. SPC Show marked entry in other window
  6908. TAB Visit marked entry in other window
  6909. The cursor may be at a date in the calendar, or in the Org agenda."
  6910. (interactive)
  6911. (let (ans)
  6912. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6913. (setq ans (read-char-exclusive))
  6914. (cond
  6915. ((equal ans ?m)
  6916. ;; Mark this entry
  6917. (if (eq major-mode 'org-agenda-mode)
  6918. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6919. (org-get-at-bol 'org-marker))))
  6920. (if m
  6921. (progn
  6922. (move-marker org-agenda-action-marker
  6923. (marker-position m) (marker-buffer m))
  6924. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6925. (error "Don't know which entry to mark")))
  6926. (error "This command works only in the agenda")))
  6927. ((equal ans ?s)
  6928. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6929. ((equal ans ?d)
  6930. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6931. ((equal ans ?r)
  6932. (org-agenda-do-action '(org-remember) t))
  6933. ((equal ans ?c)
  6934. (org-agenda-do-action '(org-capture) t))
  6935. ((equal ans ?\ )
  6936. (let ((cw (selected-window)))
  6937. (org-switch-to-buffer-other-window
  6938. (marker-buffer org-agenda-action-marker))
  6939. (goto-char org-agenda-action-marker)
  6940. (org-show-context 'agenda)
  6941. (select-window cw)))
  6942. ((equal ans ?\C-i)
  6943. (org-switch-to-buffer-other-window
  6944. (marker-buffer org-agenda-action-marker))
  6945. (goto-char org-agenda-action-marker)
  6946. (org-show-context 'agenda))
  6947. (t (error "Invalid agenda action %c" ans)))))
  6948. (defun org-agenda-do-action (form &optional current-buffer)
  6949. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6950. (let ((org-overriding-default-time (org-get-cursor-date)))
  6951. (if current-buffer
  6952. (eval form)
  6953. (if (not (marker-buffer org-agenda-action-marker))
  6954. (error "No entry has been selected for agenda action")
  6955. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6956. (save-excursion
  6957. (save-restriction
  6958. (widen)
  6959. (goto-char org-agenda-action-marker)
  6960. (eval form))))))))
  6961. (defun org-agenda-clock-in (&optional arg)
  6962. "Start the clock on the currently selected item."
  6963. (interactive "P")
  6964. (org-agenda-check-no-diary)
  6965. (if (equal arg '(4))
  6966. (org-clock-in arg)
  6967. (let* ((marker (or (org-get-at-bol 'org-marker)
  6968. (org-agenda-error)))
  6969. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6970. marker))
  6971. (pos (marker-position marker))
  6972. newhead)
  6973. (org-with-remote-undo (marker-buffer marker)
  6974. (with-current-buffer (marker-buffer marker)
  6975. (widen)
  6976. (goto-char pos)
  6977. (org-show-context 'agenda)
  6978. (org-show-entry)
  6979. (org-cycle-hide-drawers 'children)
  6980. (org-clock-in arg)
  6981. (setq newhead (org-get-heading)))
  6982. (org-agenda-change-all-lines newhead hdmarker)))))
  6983. (defun org-agenda-clock-out ()
  6984. "Stop the currently running clock."
  6985. (interactive)
  6986. (unless (marker-buffer org-clock-marker)
  6987. (error "No running clock"))
  6988. (let ((marker (make-marker)) newhead)
  6989. (org-with-remote-undo (marker-buffer org-clock-marker)
  6990. (with-current-buffer (marker-buffer org-clock-marker)
  6991. (save-excursion
  6992. (save-restriction
  6993. (widen)
  6994. (goto-char org-clock-marker)
  6995. (org-back-to-heading t)
  6996. (move-marker marker (point))
  6997. (org-clock-out)
  6998. (setq newhead (org-get-heading))))))
  6999. (org-agenda-change-all-lines newhead marker)
  7000. (move-marker marker nil)))
  7001. (defun org-agenda-clock-cancel (&optional arg)
  7002. "Cancel the currently running clock."
  7003. (interactive "P")
  7004. (unless (marker-buffer org-clock-marker)
  7005. (error "No running clock"))
  7006. (org-with-remote-undo (marker-buffer org-clock-marker)
  7007. (org-clock-cancel)))
  7008. (defun org-agenda-clock-goto ()
  7009. "Jump to the currently clocked in task within the agenda.
  7010. If the currently clocked in task is not listed in the agenda
  7011. buffer, display it in another window."
  7012. (interactive)
  7013. (let (pos)
  7014. (mapc (lambda (o)
  7015. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7016. (setq pos (overlay-start o))))
  7017. (overlays-in (point-min) (point-max)))
  7018. (cond (pos (goto-char pos))
  7019. ;; If the currently clocked entry is not in the agenda
  7020. ;; buffer, we visit it in another window:
  7021. (org-clock-current-task
  7022. (org-switch-to-buffer-other-window (org-clock-goto)))
  7023. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7024. (defun org-agenda-diary-entry-in-org-file ()
  7025. "Make a diary entry in the file `org-agenda-diary-file'."
  7026. (let (d1 d2 char (text "") dp1 dp2)
  7027. (if (equal (buffer-name) "*Calendar*")
  7028. (setq d1 (calendar-cursor-to-date t)
  7029. d2 (car calendar-mark-ring))
  7030. (setq dp1 (get-text-property (point-at-bol) 'day))
  7031. (unless dp1 (error "No date defined in current line"))
  7032. (setq d1 (calendar-gregorian-from-absolute dp1)
  7033. d2 (and (ignore-errors (mark))
  7034. (save-excursion
  7035. (goto-char (mark))
  7036. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7037. (calendar-gregorian-from-absolute dp2))))
  7038. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7039. (setq char (read-char-exclusive))
  7040. (cond
  7041. ((equal char ?d)
  7042. (setq text (read-string "Day entry: "))
  7043. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7044. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7045. ((equal char ?a)
  7046. (setq d1 (list (car d1) (nth 1 d1)
  7047. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7048. (nth 2 d1))))
  7049. (setq text (read-string "Anniversary (use %d to show years): "))
  7050. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7051. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7052. ((equal char ?b)
  7053. (setq text (read-string "Block entry: "))
  7054. (unless (and d1 d2 (not (equal d1 d2)))
  7055. (error "No block of days selected"))
  7056. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7057. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7058. ((equal char ?j)
  7059. (org-switch-to-buffer-other-window
  7060. (find-file-noselect org-agenda-diary-file))
  7061. (require 'org-datetree)
  7062. (org-datetree-find-date-create d1)
  7063. (org-reveal t))
  7064. (t (error "Invalid selection character `%c'" char)))))
  7065. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7066. "Where in `org-agenda-diary-file' should new entries be added?
  7067. Valid values:
  7068. date-tree in the date tree, as child of the date
  7069. top-level as top-level entries at the end of the file."
  7070. :group 'org-agenda
  7071. :type '(choice
  7072. (const :tag "in a date tree" date-tree)
  7073. (const :tag "as top level at end of file" top-level)))
  7074. (defcustom org-agenda-insert-diary-extract-time nil
  7075. "Non-nil means extract any time specification from the diary entry."
  7076. :group 'org-agenda
  7077. :type 'boolean)
  7078. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7079. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7080. If TEXT is not empty, it will become the headline of the new entry, and
  7081. the resulting entry will not be shown. When TEXT is empty, switch to
  7082. `org-agenda-diary-file' and let the user finish the entry there."
  7083. (let ((cw (current-window-configuration)))
  7084. (org-switch-to-buffer-other-window
  7085. (find-file-noselect org-agenda-diary-file))
  7086. (widen)
  7087. (goto-char (point-min))
  7088. (cond
  7089. ((eq type 'anniversary)
  7090. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7091. (progn
  7092. (or (org-on-heading-p t)
  7093. (progn
  7094. (outline-next-heading)
  7095. (insert "* Anniversaries\n\n")
  7096. (beginning-of-line -1)))))
  7097. (outline-next-heading)
  7098. (org-back-over-empty-lines)
  7099. (backward-char 1)
  7100. (insert "\n")
  7101. (require 'diary-lib)
  7102. (let ((calendar-date-display-form
  7103. (if (if (boundp 'calendar-date-style)
  7104. (eq calendar-date-style 'european)
  7105. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  7106. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  7107. '(day " " month " " year)
  7108. '(month " " day " " year))))
  7109. (insert (format "%%%%(diary-anniversary %s) %s"
  7110. (calendar-date-string d1 nil t) text))))
  7111. ((eq type 'day)
  7112. (let ((org-prefix-has-time t)
  7113. (org-agenda-time-leading-zero t)
  7114. fmt time time2)
  7115. (if org-agenda-insert-diary-extract-time
  7116. ;; Use org-format-agenda-item to parse text for a time-range and
  7117. ;; remove it. FIXME: This is a hack, we should refactor
  7118. ;; that function to make time extraction available separately
  7119. (setq fmt (org-format-agenda-item nil text nil nil t)
  7120. time (get-text-property 0 'time fmt)
  7121. time2 (if (> (length time) 0)
  7122. ;; split-string removes trailing ...... if
  7123. ;; no end time given. First space
  7124. ;; separates time from date.
  7125. (concat " " (car (split-string time "\\.")))
  7126. nil)
  7127. text (get-text-property 0 'txt fmt)))
  7128. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7129. (org-agenda-insert-diary-as-top-level text)
  7130. (require 'org-datetree)
  7131. (org-datetree-find-date-create d1)
  7132. (org-agenda-insert-diary-make-new-entry text))
  7133. (org-insert-time-stamp (org-time-from-absolute
  7134. (calendar-absolute-from-gregorian d1))
  7135. nil nil nil nil time2))
  7136. (end-of-line 0))
  7137. ((eq type 'block)
  7138. (if (> (calendar-absolute-from-gregorian d1)
  7139. (calendar-absolute-from-gregorian d2))
  7140. (setq d1 (prog1 d2 (setq d2 d1))))
  7141. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7142. (org-agenda-insert-diary-as-top-level text)
  7143. (require 'org-datetree)
  7144. (org-datetree-find-date-create d1)
  7145. (org-agenda-insert-diary-make-new-entry text))
  7146. (org-insert-time-stamp (org-time-from-absolute
  7147. (calendar-absolute-from-gregorian d1)))
  7148. (insert "--")
  7149. (org-insert-time-stamp (org-time-from-absolute
  7150. (calendar-absolute-from-gregorian d2)))
  7151. (end-of-line 0)))
  7152. (if (string-match "\\S-" text)
  7153. (progn
  7154. (set-window-configuration cw)
  7155. (message "%s entry added to %s"
  7156. (capitalize (symbol-name type))
  7157. (abbreviate-file-name org-agenda-diary-file)))
  7158. (org-reveal t)
  7159. (message "Please finish entry here"))))
  7160. (defun org-agenda-insert-diary-as-top-level (text)
  7161. "Make new entry as a top-level entry at the end of the file.
  7162. Add TEXT as headline, and position the cursor in the second line so that
  7163. a timestamp can be added there."
  7164. (widen)
  7165. (goto-char (point-max))
  7166. (or (bolp) (insert "\n"))
  7167. (insert "* " text "\n")
  7168. (if org-adapt-indentation (org-indent-to-column 2)))
  7169. (defun org-agenda-insert-diary-make-new-entry (text)
  7170. "Make new entry as last child of current entry.
  7171. Add TEXT as headline, and position the cursor in the second line so that
  7172. a timestamp can be added there."
  7173. (let ((org-show-following-heading t)
  7174. (org-show-siblings t)
  7175. (org-show-hierarchy-above t)
  7176. (org-show-entry-below t)
  7177. col)
  7178. (outline-next-heading)
  7179. (org-back-over-empty-lines)
  7180. (or (looking-at "[ \t]*$")
  7181. (progn (insert "\n") (backward-char 1)))
  7182. (org-insert-heading nil t)
  7183. (org-do-demote)
  7184. (setq col (current-column))
  7185. (insert text "\n")
  7186. (if org-adapt-indentation (org-indent-to-column col))
  7187. (let ((org-show-following-heading t)
  7188. (org-show-siblings t)
  7189. (org-show-hierarchy-above t)
  7190. (org-show-entry-below t))
  7191. (org-show-context))))
  7192. (defun org-agenda-diary-entry ()
  7193. "Make a diary entry, like the `i' command from the calendar.
  7194. All the standard commands work: block, weekly etc.
  7195. When `org-agenda-diary-file' points to a file,
  7196. `org-agenda-diary-entry-in-org-file' is called instead to create
  7197. entries in that Org-mode file."
  7198. (interactive)
  7199. (org-agenda-check-type t 'agenda 'timeline)
  7200. (if (not (eq org-agenda-diary-file 'diary-file))
  7201. (org-agenda-diary-entry-in-org-file)
  7202. (require 'diary-lib)
  7203. (let* ((char (progn
  7204. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7205. (read-char-exclusive)))
  7206. (cmd (cdr (assoc char
  7207. '((?d . insert-diary-entry)
  7208. (?w . insert-weekly-diary-entry)
  7209. (?m . insert-monthly-diary-entry)
  7210. (?y . insert-yearly-diary-entry)
  7211. (?a . insert-anniversary-diary-entry)
  7212. (?b . insert-block-diary-entry)
  7213. (?c . insert-cyclic-diary-entry)))))
  7214. (oldf (symbol-function 'calendar-cursor-to-date))
  7215. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7216. (point (point))
  7217. (mark (or (mark t) (point))))
  7218. (unless cmd
  7219. (error "No command associated with <%c>" char))
  7220. (unless (and (get-text-property point 'day)
  7221. (or (not (equal ?b char))
  7222. (get-text-property mark 'day)))
  7223. (error "Don't know which date to use for diary entry"))
  7224. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7225. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7226. (let ((calendar-mark-ring
  7227. (list (calendar-gregorian-from-absolute
  7228. (or (get-text-property mark 'day)
  7229. (get-text-property point 'day))))))
  7230. (unwind-protect
  7231. (progn
  7232. (fset 'calendar-cursor-to-date
  7233. (lambda (&optional error dummy)
  7234. (calendar-gregorian-from-absolute
  7235. (get-text-property point 'day))))
  7236. (call-interactively cmd))
  7237. (fset 'calendar-cursor-to-date oldf))))))
  7238. (defun org-agenda-execute-calendar-command (cmd)
  7239. "Execute a calendar command from the agenda, with the date associated to
  7240. the cursor position."
  7241. (org-agenda-check-type t 'agenda 'timeline)
  7242. (require 'diary-lib)
  7243. (unless (get-text-property (point) 'day)
  7244. (error "Don't know which date to use for calendar command"))
  7245. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7246. (point (point))
  7247. (date (calendar-gregorian-from-absolute
  7248. (get-text-property point 'day)))
  7249. ;; the following 2 vars are needed in the calendar
  7250. (displayed-month (car date))
  7251. (displayed-year (nth 2 date)))
  7252. (unwind-protect
  7253. (progn
  7254. (fset 'calendar-cursor-to-date
  7255. (lambda (&optional error dummy)
  7256. (calendar-gregorian-from-absolute
  7257. (get-text-property point 'day))))
  7258. (call-interactively cmd))
  7259. (fset 'calendar-cursor-to-date oldf))))
  7260. (defun org-agenda-phases-of-moon ()
  7261. "Display the phases of the moon for the 3 months around the cursor date."
  7262. (interactive)
  7263. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7264. (defun org-agenda-holidays ()
  7265. "Display the holidays for the 3 months around the cursor date."
  7266. (interactive)
  7267. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7268. (defvar calendar-longitude)
  7269. (defvar calendar-latitude)
  7270. (defvar calendar-location-name)
  7271. (defun org-agenda-sunrise-sunset (arg)
  7272. "Display sunrise and sunset for the cursor date.
  7273. Latitude and longitude can be specified with the variables
  7274. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7275. argument, latitude and longitude will be prompted for."
  7276. (interactive "P")
  7277. (require 'solar)
  7278. (let ((calendar-longitude (if arg nil calendar-longitude))
  7279. (calendar-latitude (if arg nil calendar-latitude))
  7280. (calendar-location-name
  7281. (if arg "the given coordinates" calendar-location-name)))
  7282. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7283. (defun org-agenda-goto-calendar ()
  7284. "Open the Emacs calendar with the date at the cursor."
  7285. (interactive)
  7286. (org-agenda-check-type t 'agenda 'timeline)
  7287. (let* ((day (or (get-text-property (point) 'day)
  7288. (error "Don't know which date to open in calendar")))
  7289. (date (calendar-gregorian-from-absolute day))
  7290. (calendar-move-hook nil)
  7291. (calendar-view-holidays-initially-flag nil)
  7292. (calendar-view-diary-initially-flag nil))
  7293. (calendar)
  7294. (calendar-goto-date date)))
  7295. ;;;###autoload
  7296. (defun org-calendar-goto-agenda ()
  7297. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7298. This is a command that has to be installed in `calendar-mode-map'."
  7299. (interactive)
  7300. (org-agenda-list nil (calendar-absolute-from-gregorian
  7301. (calendar-cursor-to-date))
  7302. nil))
  7303. (defun org-agenda-convert-date ()
  7304. (interactive)
  7305. (org-agenda-check-type t 'agenda 'timeline)
  7306. (let ((day (get-text-property (point) 'day))
  7307. date s)
  7308. (unless day
  7309. (error "Don't know which date to convert"))
  7310. (setq date (calendar-gregorian-from-absolute day))
  7311. (setq s (concat
  7312. "Gregorian: " (calendar-date-string date) "\n"
  7313. "ISO: " (calendar-iso-date-string date) "\n"
  7314. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7315. "Julian: " (calendar-julian-date-string date) "\n"
  7316. "Astron. JD: " (calendar-astro-date-string date)
  7317. " (Julian date number at noon UTC)\n"
  7318. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7319. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7320. "French: " (calendar-french-date-string date) "\n"
  7321. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7322. "Mayan: " (calendar-mayan-date-string date) "\n"
  7323. "Coptic: " (calendar-coptic-date-string date) "\n"
  7324. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7325. "Persian: " (calendar-persian-date-string date) "\n"
  7326. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7327. (with-output-to-temp-buffer "*Dates*"
  7328. (princ s))
  7329. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7330. ;;; Bulk commands
  7331. (defvar org-agenda-bulk-marked-entries nil
  7332. "List of markers that refer to marked entries in the agenda.")
  7333. (defun org-agenda-bulk-marked-p ()
  7334. (eq (get-char-property (point-at-bol) 'type)
  7335. 'org-marked-entry-overlay))
  7336. (defun org-agenda-bulk-mark (&optional arg)
  7337. "Mark the entry at point for future bulk action."
  7338. (interactive "p")
  7339. (dotimes (i (max arg 1))
  7340. (unless (org-get-at-bol 'org-agenda-diary-link)
  7341. (let* ((m (org-get-at-bol 'org-hd-marker))
  7342. ov)
  7343. (unless (org-agenda-bulk-marked-p)
  7344. (unless m (error "Nothing to mark at point"))
  7345. (push m org-agenda-bulk-marked-entries)
  7346. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7347. (org-overlay-display ov "> "
  7348. (org-get-todo-face "TODO")
  7349. 'evaporate)
  7350. (overlay-put ov 'type 'org-marked-entry-overlay))
  7351. (beginning-of-line 2)
  7352. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7353. (beginning-of-line 2))
  7354. (message "%d entries marked for bulk action"
  7355. (length org-agenda-bulk-marked-entries))))))
  7356. (defun org-agenda-bulk-mark-regexp (regexp)
  7357. "Mark entries match REGEXP."
  7358. (interactive "sMark entries matching regexp: ")
  7359. (let (entries-marked)
  7360. (save-excursion
  7361. (goto-char (point-min))
  7362. (goto-char (next-single-property-change (point) 'txt))
  7363. (while (re-search-forward regexp nil t)
  7364. (when (string-match regexp (get-text-property (point) 'txt))
  7365. (setq entries-marked (+ entries-marked 1))
  7366. (call-interactively 'org-agenda-bulk-mark))))
  7367. (if (not entries-marked)
  7368. (message "No entry matching this regexp."))))
  7369. (defun org-agenda-bulk-unmark ()
  7370. "Unmark the entry at point for future bulk action."
  7371. (interactive)
  7372. (when (org-agenda-bulk-marked-p)
  7373. (org-agenda-bulk-remove-overlays
  7374. (point-at-bol) (+ 2 (point-at-bol)))
  7375. (setq org-agenda-bulk-marked-entries
  7376. (delete (org-get-at-bol 'org-hd-marker)
  7377. org-agenda-bulk-marked-entries)))
  7378. (beginning-of-line 2)
  7379. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7380. (beginning-of-line 2))
  7381. (message "%d entries marked for bulk action"
  7382. (length org-agenda-bulk-marked-entries)))
  7383. (defun org-agenda-bulk-toggle ()
  7384. "Toggle marking the entry at point for bulk action."
  7385. (interactive)
  7386. (if (org-agenda-bulk-marked-p)
  7387. (org-agenda-bulk-unmark)
  7388. (org-agenda-bulk-mark)))
  7389. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7390. "Remove the mark overlays between BEG and END in the agenda buffer.
  7391. BEG and END default to the buffer limits.
  7392. This only removes the overlays, it does not remove the markers
  7393. from the list in `org-agenda-bulk-marked-entries'."
  7394. (interactive)
  7395. (mapc (lambda (ov)
  7396. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7397. (delete-overlay ov)))
  7398. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7399. (defun org-agenda-bulk-remove-all-marks ()
  7400. "Remove all marks in the agenda buffer.
  7401. This will remove the markers, and the overlays."
  7402. (interactive)
  7403. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7404. (setq org-agenda-bulk-marked-entries nil)
  7405. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7406. (defun org-agenda-bulk-action (&optional arg)
  7407. "Execute an remote-editing action on all marked entries.
  7408. The prefix arg is passed through to the command if possible."
  7409. (interactive "P")
  7410. (unless org-agenda-bulk-marked-entries
  7411. (error "No entries are marked"))
  7412. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
  7413. (let* ((action (read-char-exclusive))
  7414. (org-log-refile (if org-log-refile 'time nil))
  7415. (entries (reverse org-agenda-bulk-marked-entries))
  7416. redo-at-end
  7417. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7418. (cond
  7419. ((equal action ?$)
  7420. (setq cmd '(org-agenda-archive)))
  7421. ((equal action ?A)
  7422. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7423. ((member action '(?r ?w))
  7424. (setq rfloc (org-refile-get-location
  7425. "Refile to"
  7426. (marker-buffer (car org-agenda-bulk-marked-entries))
  7427. org-refile-allow-creating-parent-nodes))
  7428. (if (nth 3 rfloc)
  7429. (setcar (nthcdr 3 rfloc)
  7430. (move-marker (make-marker) (nth 3 rfloc)
  7431. (or (get-file-buffer (nth 1 rfloc))
  7432. (find-buffer-visiting (nth 1 rfloc))
  7433. (error "This should not happen")))))
  7434. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7435. redo-at-end t))
  7436. ((equal action ?t)
  7437. (setq state (org-icompleting-read
  7438. "Todo state: "
  7439. (with-current-buffer (marker-buffer (car entries))
  7440. (mapcar 'list org-todo-keywords-1))))
  7441. (setq cmd `(let ((org-inhibit-blocking t)
  7442. (org-inhibit-logging 'note))
  7443. (org-agenda-todo ,state))))
  7444. ((memq action '(?- ?+))
  7445. (setq tag (org-icompleting-read
  7446. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7447. (with-current-buffer (marker-buffer (car entries))
  7448. (delq nil
  7449. (mapcar (lambda (x)
  7450. (if (stringp (car x)) x)) org-tag-alist)))))
  7451. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7452. ((memq action '(?s ?d))
  7453. (let* ((date (unless arg
  7454. (org-read-date
  7455. nil nil nil
  7456. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7457. (ans (if arg nil org-read-date-final-answer))
  7458. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7459. (setq cmd `(let* ((bound (fboundp 'read-string))
  7460. (old (and bound (symbol-function 'read-string))))
  7461. (unwind-protect
  7462. (progn
  7463. (fset 'read-string (lambda (&rest ignore) ,ans))
  7464. (eval '(,c1 arg)))
  7465. (if bound
  7466. (fset 'read-string old)
  7467. (fmakunbound 'read-string)))))))
  7468. ((equal action ?S)
  7469. (if (not (org-agenda-check-type nil 'agenda 'timeline))
  7470. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7471. (let ((days (read-number
  7472. (format "Scatter tasks across how many %sdays: "
  7473. (if arg "week" "")) 7)))
  7474. (setq cmd
  7475. `(let ((distance (1+ (random ,days))))
  7476. (if arg
  7477. (let ((dist distance)
  7478. (day-of-week
  7479. (calendar-day-of-week
  7480. (calendar-gregorian-from-absolute (org-today)))))
  7481. (dotimes (i (1+ dist))
  7482. (while (member day-of-week org-agenda-weekend-days)
  7483. (incf distance)
  7484. (incf day-of-week)
  7485. (if (= day-of-week 7)
  7486. (setq day-of-week 0)))
  7487. (incf day-of-week)
  7488. (if (= day-of-week 7)
  7489. (setq day-of-week 0)))))
  7490. ;; silently fail when try to replan a sexp entry
  7491. (condition-case nil
  7492. (org-agenda-date-later distance)
  7493. (error nil)))))))
  7494. (t (error "Invalid bulk action")))
  7495. ;; Sort the markers, to make sure that parents are handled before children
  7496. (setq entries (sort entries
  7497. (lambda (a b)
  7498. (cond
  7499. ((equal (marker-buffer a) (marker-buffer b))
  7500. (< (marker-position a) (marker-position b)))
  7501. (t
  7502. (string< (buffer-name (marker-buffer a))
  7503. (buffer-name (marker-buffer b))))))))
  7504. ;; Now loop over all markers and apply cmd
  7505. (while (setq e (pop entries))
  7506. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7507. (if (not pos)
  7508. (progn (message "Skipping removed entry at %s" e)
  7509. (setq cntskip (1+ cntskip)))
  7510. (goto-char pos)
  7511. (eval cmd)
  7512. (setq org-agenda-bulk-marked-entries
  7513. (delete e org-agenda-bulk-marked-entries))
  7514. (setq cnt (1+ cnt))))
  7515. (setq org-agenda-bulk-marked-entries nil)
  7516. (org-agenda-bulk-remove-all-marks)
  7517. (when redo-at-end (org-agenda-redo))
  7518. (message "Acted on %d entries%s"
  7519. cnt
  7520. (if (= cntskip 0)
  7521. ""
  7522. (format ", skipped %d (disappeared before their turn)"
  7523. cntskip)))))
  7524. ;;; Flagging notes
  7525. (defun org-agenda-show-the-flagging-note ()
  7526. "Display the flagging note in the other window.
  7527. When called a second time in direct sequence, offer to remove the FLAGGING
  7528. tag and (if present) the flagging note."
  7529. (interactive)
  7530. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7531. (win (selected-window))
  7532. note heading newhead)
  7533. (unless hdmarker
  7534. (error "No linked entry at point"))
  7535. (if (and (eq this-command last-command)
  7536. (y-or-n-p "Unflag and remove any flagging note? "))
  7537. (progn
  7538. (org-agenda-remove-flag hdmarker)
  7539. (let ((win (get-buffer-window "*Flagging Note*")))
  7540. (and win (delete-window win)))
  7541. (message "Entry unflaged"))
  7542. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7543. (unless note
  7544. (error "No flagging note"))
  7545. (org-kill-new note)
  7546. (org-switch-to-buffer-other-window "*Flagging Note*")
  7547. (erase-buffer)
  7548. (insert note)
  7549. (goto-char (point-min))
  7550. (while (re-search-forward "\\\\n" nil t)
  7551. (replace-match "\n" t t))
  7552. (goto-char (point-min))
  7553. (select-window win)
  7554. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7555. (defun org-agenda-remove-flag (marker)
  7556. "Remove the FLAGGED tag and any flagging note in the entry."
  7557. (let (newhead)
  7558. (org-with-point-at marker
  7559. (org-toggle-tag "FLAGGED" 'off)
  7560. (org-entry-delete nil "THEFLAGGINGNOTE")
  7561. (setq newhead (org-get-heading)))
  7562. (org-agenda-change-all-lines newhead marker)
  7563. (message "Entry unflaged")))
  7564. (defun org-agenda-get-any-marker (&optional pos)
  7565. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7566. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7567. ;;; Appointment reminders
  7568. (defvar appt-time-msg-list)
  7569. ;;;###autoload
  7570. (defun org-agenda-to-appt (&optional refresh filter)
  7571. "Activate appointments found in `org-agenda-files'.
  7572. With a \\[universal-argument] prefix, refresh the list of
  7573. appointments.
  7574. If FILTER is t, interactively prompt the user for a regular
  7575. expression, and filter out entries that don't match it.
  7576. If FILTER is a string, use this string as a regular expression
  7577. for filtering entries out.
  7578. FILTER can also be an alist with the car of each cell being
  7579. either 'headline or 'category. For example:
  7580. '((headline \"IMPORTANT\")
  7581. (category \"Work\"))
  7582. will only add headlines containing IMPORTANT or headlines
  7583. belonging to the \"Work\" category."
  7584. (interactive "P")
  7585. (if refresh (setq appt-time-msg-list nil))
  7586. (if (eq filter t)
  7587. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7588. (let* ((cnt 0) ; count added events
  7589. (org-agenda-new-buffers nil)
  7590. (org-deadline-warning-days 0)
  7591. ;; Do not use `org-today' here because appt only takes
  7592. ;; time and without date as argument, so it may pass wrong
  7593. ;; information otherwise
  7594. (today (org-date-to-gregorian
  7595. (time-to-days (current-time))))
  7596. (org-agenda-restrict nil)
  7597. (files (org-agenda-files 'unrestricted)) entries file)
  7598. ;; Get all entries which may contain an appt
  7599. (org-prepare-agenda-buffers files)
  7600. (while (setq file (pop files))
  7601. (setq entries
  7602. (append entries
  7603. (org-agenda-get-day-entries
  7604. file today :timestamp :scheduled :deadline))))
  7605. (setq entries (delq nil entries))
  7606. ;; Map thru entries and find if we should filter them out
  7607. (mapc
  7608. (lambda(x)
  7609. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7610. (cat (get-text-property 1 'org-category x))
  7611. (tod (get-text-property 1 'time-of-day x))
  7612. (ok (or (null filter)
  7613. (and (stringp filter) (string-match filter evt))
  7614. (and (listp filter)
  7615. (or (string-match
  7616. (cadr (assoc 'category filter)) cat)
  7617. (string-match
  7618. (cadr (assoc 'headline filter)) evt))))))
  7619. ;; FIXME: Shall we remove text-properties for the appt text?
  7620. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7621. (when (and ok tod)
  7622. (setq tod (concat "00" (number-to-string tod))
  7623. tod (when (string-match
  7624. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7625. (concat (match-string 1 tod) ":"
  7626. (match-string 2 tod))))
  7627. (appt-add tod evt)
  7628. (setq cnt (1+ cnt))))) entries)
  7629. (org-release-buffers org-agenda-new-buffers)
  7630. (if (eq cnt 0)
  7631. (message "No event to add")
  7632. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7633. (defun org-agenda-todayp (date)
  7634. "Does DATE mean today, when considering `org-extend-today-until'?"
  7635. (let ((today (org-today))
  7636. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7637. date)))
  7638. (eq date today)))
  7639. (provide 'org-agenda)
  7640. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7641. ;;; org-agenda.el ends here