org-agenda.el 311 KB

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