org-agenda.el 319 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.5
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-span)
  217. (choice (const :tag "Day" 'day)
  218. (const :tag "Week" 'week)
  219. (const :tag "Month" 'month)
  220. (const :tag "Year" 'year)
  221. (integer :tag "Custom")))
  222. (list :tag "Fixed starting date"
  223. (const org-agenda-start-day)
  224. (string :value "2007-11-01"))
  225. (list :tag "Start on day of week"
  226. (const org-agenda-start-on-weekday)
  227. (choice :value 1
  228. (const :tag "Today" nil)
  229. (integer :tag "Weekday No.")))
  230. (list :tag "Include data from diary"
  231. (const org-agenda-include-diary)
  232. (boolean))
  233. (list :tag "Deadline Warning days"
  234. (const org-deadline-warning-days)
  235. (integer :value 1))
  236. (list :tag "Tags filter preset"
  237. (const org-agenda-filter-preset)
  238. (list
  239. (const :format "" quote)
  240. (repeat
  241. (string :tag "+tag or -tag"))))
  242. (list :tag "Set daily/weekly entry types"
  243. (const org-agenda-entry-types)
  244. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  245. (const :deadline)
  246. (const :scheduled)
  247. (const :timestamp)
  248. (const :sexp)))
  249. (list :tag "Standard skipping condition"
  250. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  251. (const org-agenda-skip-function)
  252. (list
  253. (const :format "" quote)
  254. (list
  255. (choice
  256. :tag "Skipping range"
  257. (const :tag "Skip entry" org-agenda-skip-entry-if)
  258. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  259. (repeat :inline t :tag "Conditions for skipping"
  260. (choice
  261. :tag "Condition type"
  262. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  263. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  264. (list :tag "TODO state is" :inline t
  265. (const 'todo)
  266. (choice
  267. (const :tag "any not-done state" 'todo)
  268. (const :tag "any done state" 'done)
  269. (const :tag "any state" 'any)
  270. (list :tag "Keyword list"
  271. (const :format "" quote)
  272. (repeat (string :tag "Keyword")))))
  273. (list :tag "TODO state is not" :inline t
  274. (const 'nottodo)
  275. (choice
  276. (const :tag "any not-done state" 'todo)
  277. (const :tag "any done state" 'done)
  278. (const :tag "any state" 'any)
  279. (list :tag "Keyword list"
  280. (const :format "" quote)
  281. (repeat (string :tag "Keyword")))))
  282. (const :tag "scheduled" 'scheduled)
  283. (const :tag "not scheduled" 'notscheduled)
  284. (const :tag "deadline" 'deadline)
  285. (const :tag "no deadline" 'notdeadline)
  286. (const :tag "timestamp" 'timestamp)
  287. (const :tag "no timestamp" 'nottimestamp))))))
  288. (list :tag "Non-standard skipping condition"
  289. :value (org-agenda-skip-function)
  290. (const org-agenda-skip-function)
  291. (sexp :tag "Function or form (quoted!)"))
  292. (list :tag "Any variable"
  293. (variable :tag "Variable")
  294. (sexp :tag "Value (sexp)"))))
  295. "Selection of examples for agenda command settings.
  296. This will be spliced into the custom type of
  297. `org-agenda-custom-commands'.")
  298. (defcustom org-agenda-custom-commands nil
  299. "Custom commands for the agenda.
  300. These commands will be offered on the splash screen displayed by the
  301. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  302. (key desc type match settings files)
  303. key The key (one or more characters as a string) to be associated
  304. with the command.
  305. desc A description of the command, when omitted or nil, a default
  306. description is built using MATCH.
  307. type The command type, any of the following symbols:
  308. agenda The daily/weekly agenda.
  309. todo Entries with a specific TODO keyword, in all agenda files.
  310. search Entries containing search words entry or headline.
  311. tags Tags/Property/TODO match in all agenda files.
  312. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  313. todo-tree Sparse tree of specific TODO keyword in *current* file.
  314. tags-tree Sparse tree with all tags matches in *current* file.
  315. occur-tree Occur sparse tree for *current* file.
  316. ... A user-defined function.
  317. match What to search for:
  318. - a single keyword for TODO keyword searches
  319. - a tags match expression for tags searches
  320. - a word search expression for text searches.
  321. - a regular expression for occur searches
  322. For all other commands, this should be the empty string.
  323. settings A list of option settings, similar to that in a let form, so like
  324. this: ((opt1 val1) (opt2 val2) ...). The values will be
  325. evaluated at the moment of execution, so quote them when needed.
  326. files A list of files file to write the produced agenda buffer to
  327. with the command `org-store-agenda-views'.
  328. If a file name ends in \".html\", an HTML version of the buffer
  329. is written out. If it ends in \".ps\", a postscript version is
  330. produced. Otherwise, only the plain text is written to the file.
  331. You can also define a set of commands, to create a composite agenda buffer.
  332. In this case, an entry looks like this:
  333. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  334. where
  335. desc A description string to be displayed in the dispatcher menu.
  336. cmd An agenda command, similar to the above. However, tree commands
  337. are no allowed, but instead you can get agenda and global todo list.
  338. So valid commands for a set are:
  339. (agenda \"\" settings)
  340. (alltodo \"\" settings)
  341. (stuck \"\" settings)
  342. (todo \"match\" settings files)
  343. (search \"match\" settings files)
  344. (tags \"match\" settings files)
  345. (tags-todo \"match\" settings files)
  346. Each command can carry a list of options, and another set of options can be
  347. given for the whole set of commands. Individual command options take
  348. precedence over the general options.
  349. When using several characters as key to a command, the first characters
  350. are prefix commands. For the dispatcher to display useful information, you
  351. should provide a description for the prefix, like
  352. (setq org-agenda-custom-commands
  353. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  354. (\"hl\" tags \"+HOME+Lisa\")
  355. (\"hp\" tags \"+HOME+Peter\")
  356. (\"hk\" tags \"+HOME+Kim\")))"
  357. :group 'org-agenda-custom-commands
  358. :type `(repeat
  359. (choice :value ("x" "Describe command here" tags "" nil)
  360. (list :tag "Single command"
  361. (string :tag "Access Key(s) ")
  362. (option (string :tag "Description"))
  363. (choice
  364. (const :tag "Agenda" agenda)
  365. (const :tag "TODO list" alltodo)
  366. (const :tag "Search words" search)
  367. (const :tag "Stuck projects" stuck)
  368. (const :tag "Tags/Property match (all agenda files)" tags)
  369. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  370. (const :tag "TODO keyword search (all agenda files)" todo)
  371. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  372. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  373. (const :tag "Occur tree (current buffer)" occur-tree)
  374. (sexp :tag "Other, user-defined function"))
  375. (string :tag "Match (only for some commands)")
  376. ,org-agenda-custom-commands-local-options
  377. (option (repeat :tag "Export" (file :tag "Export to"))))
  378. (list :tag "Command series, all agenda files"
  379. (string :tag "Access Key(s)")
  380. (string :tag "Description ")
  381. (repeat :tag "Component"
  382. (choice
  383. (list :tag "Agenda"
  384. (const :format "" agenda)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "TODO list (all keywords)"
  388. (const :format "" alltodo)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Search words"
  392. (const :format "" search)
  393. (string :tag "Match")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Stuck projects"
  396. (const :format "" stuck)
  397. (const :tag "" :format "" "")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search"
  400. (const :format "" tags)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search, TODO entries only"
  404. (const :format "" tags-todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "TODO keyword search"
  408. (const :format "" todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "Other, user-defined function"
  412. (symbol :tag "function")
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)))
  415. (repeat :tag "Settings for entire command set"
  416. (list (variable :tag "Any variable")
  417. (sexp :tag "Value")))
  418. (option (repeat :tag "Export" (file :tag "Export to"))))
  419. (cons :tag "Prefix key documentation"
  420. (string :tag "Access Key(s)")
  421. (string :tag "Description ")))))
  422. (defcustom org-agenda-query-register ?o
  423. "The register holding the current query string.
  424. The purpose of this is that if you construct a query string interactively,
  425. you can then use it to define a custom command."
  426. :group 'org-agenda-custom-commands
  427. :type 'character)
  428. (defcustom org-stuck-projects
  429. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  430. "How to identify stuck projects.
  431. This is a list of four items:
  432. 1. A tags/todo/property matcher string that is used to identify a project.
  433. See the manual for a description of tag and property searches.
  434. The entire tree below a headline matched by this is considered one project.
  435. 2. A list of TODO keywords identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these todo
  437. keywords, the project is considered to be not stuck. If you specify
  438. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  439. 3. A list of tags identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these tags,
  441. the project is considered to be not stuck. If you specify \"*\" as
  442. a tag, any tag will mark the project unstuck. Note that this is about
  443. the explicit presence of a tag somewhere in the subtree, inherited
  444. tags to not count here. If inherited tags make a project not stuck,
  445. use \"-TAG\" in the tags part of the matcher under (1.) above.
  446. 4. An arbitrary regular expression matching non-stuck projects.
  447. If the project turns out to be not stuck, search continues also in the
  448. subtree to see if any of the subtasks have project status.
  449. See also the variable `org-tags-match-list-sublevels' which applies
  450. to projects matched by this search as well.
  451. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  452. or `C-c a #' to produce the list."
  453. :group 'org-agenda-custom-commands
  454. :type '(list
  455. (string :tag "Tags/TODO match to identify a project")
  456. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  457. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  458. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  459. (defcustom org-agenda-filter-effort-default-operator "<"
  460. "The default operator for effort estimate filtering.
  461. If you select an effort estimate limit without first pressing an operator,
  462. this one will be used."
  463. :group 'org-agenda-custom-commands
  464. :type '(choice (const :tag "less or equal" "<")
  465. (const :tag "greater or equal"">")
  466. (const :tag "equal" "=")))
  467. (defgroup org-agenda-skip nil
  468. "Options concerning skipping parts of agenda files."
  469. :tag "Org Agenda Skip"
  470. :group 'org-agenda)
  471. (defcustom org-agenda-skip-function-global nil
  472. "Function to be called at each match during agenda construction.
  473. If this function returns nil, the current match should not be skipped.
  474. If the function decided to skip an agenda match, is must return the
  475. buffer position from which the search should be continued.
  476. This may also be a Lisp form, which will be evaluated.
  477. This variable will be applied to every agenda match, including
  478. tags/property searches and TODO lists. So try to make the test function
  479. do its checking as efficiently as possible. To implement a skipping
  480. condition just for specific agenda commands, use the variable
  481. `org-agenda-skip-function' which can be set in the options section
  482. of custom agenda commands."
  483. :group 'org-agenda-skip
  484. :type 'sexp)
  485. (defgroup org-agenda-daily/weekly nil
  486. "Options concerning the daily/weekly agenda."
  487. :tag "Org Agenda Daily/Weekly"
  488. :group 'org-agenda)
  489. (defgroup org-agenda-todo-list nil
  490. "Options concerning the global todo list agenda view."
  491. :tag "Org Agenda Todo List"
  492. :group 'org-agenda)
  493. (defgroup org-agenda-match-view nil
  494. "Options concerning the general tags/property/todo match agenda view."
  495. :tag "Org Agenda Match View"
  496. :group 'org-agenda)
  497. (defgroup org-agenda-search-view nil
  498. "Options concerning the general tags/property/todo match agenda view."
  499. :tag "Org Agenda Match View"
  500. :group 'org-agenda)
  501. (defvar org-agenda-archives-mode nil
  502. "Non-nil means the agenda will include archived items.
  503. If this is the symbol `trees', trees in the selected agenda scope
  504. that are marked with the ARCHIVE tag will be included anyway. When this is
  505. t, also all archive files associated with the current selection of agenda
  506. files will be included.")
  507. (defcustom org-agenda-skip-comment-trees t
  508. "Non-nil means skip trees that start with the COMMENT keyword.
  509. When nil, these trees are also scanned by agenda commands."
  510. :group 'org-agenda-skip
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-list-sublevels t
  513. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  514. When nil, the sublevels of a TODO entry are not checked, resulting in
  515. potentially much shorter TODO lists."
  516. :group 'org-agenda-skip
  517. :group 'org-agenda-todo-list
  518. :type 'boolean)
  519. (defcustom org-agenda-todo-ignore-with-date nil
  520. "Non-nil means don't show entries with a date in the global todo list.
  521. You can use this if you prefer to mark mere appointments with a TODO keyword,
  522. but don't want them to show up in the TODO list.
  523. When this is set, it also covers deadlines and scheduled items, the settings
  524. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  525. will be ignored.
  526. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type 'boolean)
  530. (defcustom org-agenda-todo-ignore-timestamp nil
  531. "Non-nil means don't show entries with a timestamp.
  532. This applies when creating the global todo list.
  533. Valid values are:
  534. past Don't show entries for today or in the past.
  535. future Don't show entries with a timestamp in the future.
  536. The idea behind this is that if it has a future
  537. timestamp, you don't want to think about it until the
  538. date.
  539. all Don't show any entries with a timestamp in the global todo list.
  540. The idea behind this is that by setting a timestamp, you
  541. have already \"taken care\" of this item.
  542. This variable can also have an integer as a value. If positive (N),
  543. todos with a timestamp N or more days in the future will be ignored. If
  544. negative (-N), todos with a timestamp N or more days in the past will be
  545. ignored. If 0, todos with a timestamp either today or in the future will
  546. be ignored. For example, a value of -1 will exclude todos with a
  547. timestamp in the past (yesterday or earlier), while a value of 7 will
  548. exclude todos with a timestamp a week or more in the future.
  549. See also `org-agenda-todo-ignore-with-date'.
  550. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  551. to make his option also apply to the tags-todo list."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type '(choice
  555. (const :tag "Ignore future timestamp todos" future)
  556. (const :tag "Ignore past or present timestamp todos" past)
  557. (const :tag "Ignore all timestamp todos" all)
  558. (const :tag "Show timestamp todos" nil)
  559. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  560. (defcustom org-agenda-todo-ignore-scheduled nil
  561. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  562. This applies when creating the global todo list.
  563. Valid values are:
  564. past Don't show entries scheduled today or in the past.
  565. future Don't show entries scheduled in the future.
  566. The idea behind this is that by scheduling it, you don't want to
  567. think about it until the scheduled date.
  568. all Don't show any scheduled entries in the global todo list.
  569. The idea behind this is that by scheduling it, you have already
  570. \"taken care\" of this item.
  571. t Same as `all', for backward compatibility.
  572. This variable can also have an integer as a value. See
  573. `org-agenda-todo-ignore-timestamp' for more details.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore future-scheduled todos" future)
  581. (const :tag "Ignore past- or present-scheduled todos" past)
  582. (const :tag "Ignore all scheduled todos" all)
  583. (const :tag "Ignore all scheduled todos (compatibility)" t)
  584. (const :tag "Show scheduled todos" nil)
  585. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  586. (defcustom org-agenda-todo-ignore-deadlines nil
  587. "Non-nil means ignore some deadlined TODO items when making TODO list.
  588. There are different motivations for using different values, please think
  589. carefully when configuring this variable.
  590. This applies when creating the global todo list.
  591. Valid values are:
  592. near Don't show near deadline entries. A deadline is near when it is
  593. closer than `org-deadline-warning-days' days. The idea behind this
  594. is that such items will appear in the agenda anyway.
  595. far Don't show TODO entries where a deadline has been defined, but
  596. the deadline is not near. This is useful if you don't want to
  597. use the todo list to figure out what to do now.
  598. past Don't show entries with a deadline timestamp for today or in the past.
  599. future Don't show entries with a deadline timestamp in the future, not even
  600. when they become `near' ones. Use it with caution.
  601. all Ignore all TODO entries that do have a deadline.
  602. t Same as `near', for backward compatibility.
  603. This variable can also have an integer as a value. See
  604. `org-agenda-todo-ignore-timestamp' for more details.
  605. See also `org-agenda-todo-ignore-with-date'.
  606. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  607. to make his option also apply to the tags-todo list."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-todo-list
  610. :type '(choice
  611. (const :tag "Ignore near deadlines" near)
  612. (const :tag "Ignore near deadlines (compatibility)" t)
  613. (const :tag "Ignore far deadlines" far)
  614. (const :tag "Ignore all TODOs with a deadlines" all)
  615. (const :tag "Show all TODOs, even if they have a deadline" nil)
  616. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  617. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  618. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  619. The variables
  620. `org-agenda-todo-ignore-with-date',
  621. `org-agenda-todo-ignore-timestamp',
  622. `org-agenda-todo-ignore-scheduled',
  623. `org-agenda-todo-ignore-deadlines'
  624. make the global TODO list skip entries that have time stamps of certain
  625. kinds. If this option is set, the same options will also apply for the
  626. tags-todo search, which is the general tags/property matcher
  627. restricted to unfinished TODO entries only."
  628. :group 'org-agenda-skip
  629. :group 'org-agenda-todo-list
  630. :group 'org-agenda-match-view
  631. :type 'boolean)
  632. (defcustom org-agenda-skip-scheduled-if-done nil
  633. "Non-nil means don't show scheduled items in agenda when they are done.
  634. This is relevant for the daily/weekly agenda, not for the TODO list. And
  635. it applies only to the actual date of the scheduling. Warnings about
  636. an item with a past scheduling dates are always turned off when the item
  637. is DONE."
  638. :group 'org-agenda-skip
  639. :group 'org-agenda-daily/weekly
  640. :type 'boolean)
  641. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  642. "Non-nil means skip scheduling line if same entry shows because of deadline.
  643. In the agenda of today, an entry can show up multiple times because
  644. it is both scheduled and has a nearby deadline, and maybe a plain time
  645. stamp as well.
  646. When this variable is t, then only the deadline is shown and the fact that
  647. the entry is scheduled today or was scheduled previously is not shown.
  648. When this variable is nil, the entry will be shown several times. When
  649. the variable is the symbol `not-today', then skip scheduled previously,
  650. but not scheduled today."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-daily/weekly
  653. :type '(choice
  654. (const :tag "Never" nil)
  655. (const :tag "Always" t)
  656. (const :tag "Not when scheduled today" not-today)))
  657. (defcustom org-agenda-skip-deadline-if-done nil
  658. "Non-nil means don't show deadlines when the corresponding item is done.
  659. When nil, the deadline is still shown and should give you a happy feeling.
  660. This is relevant for the daily/weekly agenda. And it applied only to the
  661. actually date of the deadline. Warnings about approaching and past-due
  662. deadlines are always turned off when the item is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  667. "Non-nil means skip deadline prewarning when entry is also scheduled.
  668. This will apply on all days where a prewarning for the deadline would
  669. be shown, but not at the day when the entry is actually due. On that day,
  670. the deadline will be shown anyway.
  671. This variable may be set to nil, t, or a number which will then give
  672. the number of days before the actual deadline when the prewarnings
  673. should resume.
  674. This can be used in a workflow where the first showing of the deadline will
  675. trigger you to schedule it, and then you don't want to be reminded of it
  676. because you will take care of it on the day when scheduled."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-daily/weekly
  679. :type '(choice
  680. (const :tag "Alwas show prewarning" nil)
  681. (const :tag "Remove prewarning if entry is scheduled" t)
  682. (integer :tag "Restart prewarning N days before deadline")))
  683. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  684. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  685. When non-nil, after the search for timestamps has matched once in an
  686. entry, the rest of the entry will not be searched."
  687. :group 'org-agenda-skip
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-timestamp-if-done nil
  690. "Non-nil means don't select item by timestamp or -range if it is DONE."
  691. :group 'org-agenda-skip
  692. :group 'org-agenda-daily/weekly
  693. :type 'boolean)
  694. (defcustom org-agenda-dim-blocked-tasks t
  695. "Non-nil means dim blocked tasks in the agenda display.
  696. This causes some overhead during agenda construction, but if you
  697. have turned on `org-enforce-todo-dependencies',
  698. `org-enforce-todo-checkbox-dependencies', or any other blocking
  699. mechanism, this will create useful feedback in the agenda.
  700. Instead of t, this variable can also have the value `invisible'.
  701. Then blocked tasks will be invisible and only become visible when
  702. they become unblocked. An exemption to this behavior is when a task is
  703. blocked because of unchecked checkboxes below it. Since checkboxes do
  704. not show up in the agenda views, making this task invisible you remove any
  705. trace from agenda views that there is something to do. Therefore, a task
  706. that is blocked because of checkboxes will never be made invisible, it
  707. will only be dimmed."
  708. :group 'org-agenda-daily/weekly
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Do not dim" nil)
  712. (const :tag "Dim to a grey face" t)
  713. (const :tag "Make invisible" invisible)))
  714. (defcustom org-timeline-show-empty-dates 3
  715. "Non-nil means `org-timeline' also shows dates without an entry.
  716. When nil, only the days which actually have entries are shown.
  717. When t, all days between the first and the last date are shown.
  718. When an integer, show also empty dates, but if there is a gap of more than
  719. N days, just insert a special line indicating the size of the gap."
  720. :group 'org-agenda-skip
  721. :type '(choice
  722. (const :tag "None" nil)
  723. (const :tag "All" t)
  724. (integer :tag "at most")))
  725. (defgroup org-agenda-startup nil
  726. "Options concerning initial settings in the Agenda in Org Mode."
  727. :tag "Org Agenda Startup"
  728. :group 'org-agenda)
  729. (defcustom org-agenda-menu-show-matcher t
  730. "Non-nil means show the match string in the agenda dispatcher menu.
  731. When nil, the matcher string is not shown, but is put into the help-echo
  732. property so than moving the mouse over the command shows it.
  733. Setting it to nil is good if matcher strings are very long and/or if
  734. you want to use two-column display (see `org-agenda-menu-two-column')."
  735. :group 'org-agenda
  736. :type 'boolean)
  737. (defcustom org-agenda-menu-two-column nil
  738. "Non-nil means, use two columns to show custom commands in the dispatcher.
  739. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  740. to nil."
  741. :group 'org-agenda
  742. :type 'boolean)
  743. (defcustom org-finalize-agenda-hook nil
  744. "Hook run just before displaying an agenda buffer."
  745. :group 'org-agenda-startup
  746. :type 'hook)
  747. (defcustom org-agenda-mouse-1-follows-link nil
  748. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  749. A longer mouse click will still set point. Does not work on XEmacs.
  750. Needs to be set before org.el is loaded."
  751. :group 'org-agenda-startup
  752. :type 'boolean)
  753. (defcustom org-agenda-start-with-follow-mode nil
  754. "The initial value of follow mode in a newly created agenda window."
  755. :group 'org-agenda-startup
  756. :type 'boolean)
  757. (defcustom org-agenda-show-outline-path t
  758. "Non-nil means show outline path in echo area after line motion."
  759. :group 'org-agenda-startup
  760. :type 'boolean)
  761. (defcustom org-agenda-start-with-entry-text-mode nil
  762. "The initial value of entry-text-mode in a newly created agenda window."
  763. :group 'org-agenda-startup
  764. :type 'boolean)
  765. (defcustom org-agenda-entry-text-maxlines 5
  766. "Number of text lines to be added when `E' is pressed in the agenda.
  767. Note that this variable only used during agenda display. Add add entry text
  768. when exporting the agenda, configure the variable
  769. `org-agenda-add-entry-ext-maxlines'."
  770. :group 'org-agenda
  771. :type 'integer)
  772. (defcustom org-agenda-entry-text-exclude-regexps nil
  773. "List of regular expressions to clean up entry text.
  774. The complete matches of all regular expressions in this list will be
  775. removed from entry text before it is shown in the agenda."
  776. :group 'org-agenda
  777. :type '(repeat (regexp)))
  778. (defvar org-agenda-entry-text-cleanup-hook nil
  779. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  780. This cleanup is done in a temporary buffer, so the function may inspect and
  781. change the entire buffer.
  782. Some default stuff like drawers and scheduling/deadline dates will already
  783. have been removed when this is called, as will any matches for regular
  784. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  785. (defvar org-agenda-include-inactive-timestamps nil
  786. "Non-nil means include inactive time stamps in agenda and timeline.")
  787. (defgroup org-agenda-windows nil
  788. "Options concerning the windows used by the Agenda in Org Mode."
  789. :tag "Org Agenda Windows"
  790. :group 'org-agenda)
  791. (defcustom org-agenda-window-setup 'reorganize-frame
  792. "How the agenda buffer should be displayed.
  793. Possible values for this option are:
  794. current-window Show agenda in the current window, keeping all other windows.
  795. other-window Use `switch-to-buffer-other-window' to display agenda.
  796. reorganize-frame Show only two windows on the current frame, the current
  797. window and the agenda.
  798. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  799. Also, when exiting the agenda, kill that frame.
  800. See also the variable `org-agenda-restore-windows-after-quit'."
  801. :group 'org-agenda-windows
  802. :type '(choice
  803. (const current-window)
  804. (const other-frame)
  805. (const other-window)
  806. (const reorganize-frame)))
  807. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  808. "The min and max height of the agenda window as a fraction of frame height.
  809. The value of the variable is a cons cell with two numbers between 0 and 1.
  810. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  811. :group 'org-agenda-windows
  812. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  813. (defcustom org-agenda-restore-windows-after-quit nil
  814. "Non-nil means restore window configuration upon exiting agenda.
  815. Before the window configuration is changed for displaying the agenda,
  816. the current status is recorded. When the agenda is exited with
  817. `q' or `x' and this option is set, the old state is restored. If
  818. `org-agenda-window-setup' is `other-frame', the value of this
  819. option will be ignored."
  820. :group 'org-agenda-windows
  821. :type 'boolean)
  822. (defcustom org-agenda-ndays nil
  823. "Number of days to include in overview display.
  824. Should be 1 or 7.
  825. Obsolete, see `org-agenda-span'."
  826. :group 'org-agenda-daily/weekly
  827. :type 'integer)
  828. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  829. (defcustom org-agenda-span 'week
  830. "Number of days to include in overview display.
  831. Can be day, week, month, year, or any number of days.
  832. Custom commands can set this variable in the options section."
  833. :group 'org-agenda-daily/weekly
  834. :type '(choice (const :tag "Day" day)
  835. (const :tag "Week" week)
  836. (const :tag "Month" month)
  837. (const :tag "Year" year)
  838. (integer :tag "Custom")))
  839. (defcustom org-agenda-start-on-weekday 1
  840. "Non-nil means start the overview always on the specified weekday.
  841. 0 denotes Sunday, 1 denotes Monday etc.
  842. When nil, always start on the current day.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type '(choice (const :tag "Today" nil)
  846. (integer :tag "Weekday No.")))
  847. (defcustom org-agenda-show-all-dates t
  848. "Non-nil means `org-agenda' shows every day in the selected range.
  849. When nil, only the days which actually have entries are shown."
  850. :group 'org-agenda-daily/weekly
  851. :type 'boolean)
  852. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  853. "Format string for displaying dates in the agenda.
  854. Used by the daily/weekly agenda and by the timeline. This should be
  855. a format string understood by `format-time-string', or a function returning
  856. the formatted date as a string. The function must take a single argument,
  857. a calendar-style date list like (month day year)."
  858. :group 'org-agenda-daily/weekly
  859. :type '(choice
  860. (string :tag "Format string")
  861. (function :tag "Function")))
  862. (defun org-agenda-format-date-aligned (date)
  863. "Format a date string for display in the daily/weekly agenda, or timeline.
  864. This function makes sure that dates are aligned for easy reading."
  865. (require 'cal-iso)
  866. (let* ((dayname (calendar-day-name date))
  867. (day (cadr date))
  868. (day-of-week (calendar-day-of-week date))
  869. (month (car date))
  870. (monthname (calendar-month-name month))
  871. (year (nth 2 date))
  872. (iso-week (org-days-to-iso-week
  873. (calendar-absolute-from-gregorian date)))
  874. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  875. (1- year))
  876. ((and (= month 12) (<= iso-week 1))
  877. (1+ year))
  878. (t year)))
  879. (weekstring (if (= day-of-week 1)
  880. (format " W%02d" iso-week)
  881. "")))
  882. (format "%-10s %2d %s %4d%s"
  883. dayname day monthname year weekstring)))
  884. (defcustom org-agenda-time-leading-zero nil
  885. "Non-nil means use leading zero for military times in agenda.
  886. For example, 9:30am would become 09:30 rather than 9:30."
  887. :group 'org-agenda-daily/weekly
  888. :type 'boolean)
  889. (defcustom org-agenda-timegrid-use-ampm nil
  890. "When set, show AM/PM style timestamps on the timegrid."
  891. :group 'org-agenda
  892. :type 'boolean)
  893. (defun org-agenda-time-of-day-to-ampm (time)
  894. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  895. (let* ((hour-number (string-to-number (substring time 0 -3)))
  896. (minute (substring time -2))
  897. (ampm "am"))
  898. (cond
  899. ((equal hour-number 12)
  900. (setq ampm "pm"))
  901. ((> hour-number 12)
  902. (setq ampm "pm")
  903. (setq hour-number (- hour-number 12))))
  904. (concat
  905. (if org-agenda-time-leading-zero
  906. (format "%02d" hour-number)
  907. (format "%02s" (number-to-string hour-number)))
  908. ":" minute ampm)))
  909. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  910. "Conditionally convert TIME to AM/PM format
  911. based on `org-agenda-timegrid-use-ampm'"
  912. (if org-agenda-timegrid-use-ampm
  913. (org-agenda-time-of-day-to-ampm time)
  914. time))
  915. (defcustom org-agenda-weekend-days '(6 0)
  916. "Which days are weekend?
  917. These days get the special face `org-agenda-date-weekend' in the agenda
  918. and timeline buffers."
  919. :group 'org-agenda-daily/weekly
  920. :type '(set :greedy t
  921. (const :tag "Monday" 1)
  922. (const :tag "Tuesday" 2)
  923. (const :tag "Wednesday" 3)
  924. (const :tag "Thursday" 4)
  925. (const :tag "Friday" 5)
  926. (const :tag "Saturday" 6)
  927. (const :tag "Sunday" 0)))
  928. (defcustom org-agenda-include-diary nil
  929. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  930. Custom commands can set this variable in the options section."
  931. :group 'org-agenda-daily/weekly
  932. :type 'boolean)
  933. (defcustom org-agenda-include-deadlines t
  934. "If non-nil, include entries within their deadline warning period.
  935. Custom commands can set this variable in the options section."
  936. :group 'org-agenda-daily/weekly
  937. :type 'boolean)
  938. (defcustom org-agenda-include-all-todo nil
  939. "Set means weekly/daily agenda will always contain all TODO entries.
  940. The TODO entries will be listed at the top of the agenda, before
  941. the entries for specific days.
  942. This option is deprecated, it is better to define a block agenda instead."
  943. :group 'org-agenda-daily/weekly
  944. :type 'boolean)
  945. (defcustom org-agenda-repeating-timestamp-show-all t
  946. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  947. When set to a list of strings, only show occurrences of repeating
  948. stamps for these TODO keywords. When nil, only one occurrence is
  949. shown, either today or the nearest into the future."
  950. :group 'org-agenda-daily/weekly
  951. :type '(choice
  952. (const :tag "Show repeating stamps" t)
  953. (repeat :tag "Show repeating stamps for these TODO keywords"
  954. (string :tag "TODO Keyword"))
  955. (const :tag "Don't show repeating stamps" nil)))
  956. (defcustom org-scheduled-past-days 10000
  957. "No. of days to continue listing scheduled items that are not marked DONE.
  958. When an item is scheduled on a date, it shows up in the agenda on this
  959. day and will be listed until it is marked done for the number of days
  960. given here."
  961. :group 'org-agenda-daily/weekly
  962. :type 'integer)
  963. (defcustom org-agenda-log-mode-items '(closed clock)
  964. "List of items that should be shown in agenda log mode.
  965. This list may contain the following symbols:
  966. closed Show entries that have been closed on that day.
  967. clock Show entries that have received clocked time on that day.
  968. state Show all logged state changes.
  969. Note that instead of changing this variable, you can also press `C-u l' in
  970. the agenda to display all available LOG items temporarily."
  971. :group 'org-agenda-daily/weekly
  972. :type '(set :greedy t (const closed) (const clock) (const state)))
  973. (defcustom org-agenda-clock-consistency-checks
  974. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05" :gap-ok ("4:00"))
  975. "How to check clock times for consistency.
  976. This is a property list, with the following keys:
  977. :max-duration Mark clocking chunks that are longer than this time.
  978. This is a time string like \"HH:MM\", or the number
  979. of minutes as an integer.
  980. :min-duration Mark clocking chunks that are shorter that this.
  981. This is a time string like \"HH:MM\", or the number
  982. of minutes as an integer.
  983. :max-gap Mark gaps between clocking chunks that are longer than
  984. this duration. A number of minutes, or a string
  985. like \"HH:MM\".
  986. :gap-ok-around List of times during the day which are usually not working
  987. times. When a gap is detected, but the gap contains any
  988. of these times, the gap is *not* reported. For example,
  989. if this is (\"4:00\" \"13:00\") then gaps that contain
  990. 4:00 in the morning (i.e. the night) and 13:00
  991. (i.e. a typical lunch time) do not cause a warning.
  992. You should have at least one time during the night in this
  993. list, or otherwise the first task each morning will trigger
  994. a warning because it follows a long gap."
  995. :group 'org-agenda-daily/weekly
  996. :group 'org-clock
  997. :type 'plist)
  998. (defcustom org-agenda-log-mode-add-notes t
  999. "Non-nil means add first line of notes to log entries in agenda views.
  1000. If a log item like a state change or a clock entry is associated with
  1001. notes, the first line of these notes will be added to the entry in the
  1002. agenda display."
  1003. :group 'org-agenda-daily/weekly
  1004. :type 'boolean)
  1005. (defcustom org-agenda-start-with-log-mode nil
  1006. "The initial value of log-mode in a newly created agenda window."
  1007. :group 'org-agenda-startup
  1008. :group 'org-agenda-daily/weekly
  1009. :type 'boolean)
  1010. (defcustom org-agenda-start-with-clockreport-mode nil
  1011. "The initial value of clockreport-mode in a newly created agenda window."
  1012. :group 'org-agenda-startup
  1013. :group 'org-agenda-daily/weekly
  1014. :type 'boolean)
  1015. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1016. "Property list with parameters for the clocktable in clockreport mode.
  1017. This is the display mode that shows a clock table in the daily/weekly
  1018. agenda, the properties for this dynamic block can be set here.
  1019. The usual clocktable parameters are allowed here, but you cannot set
  1020. the properties :name, :tstart, :tend, :block, and :scope - these will
  1021. be overwritten to make sure the content accurately reflects the
  1022. current display in the agenda."
  1023. :group 'org-agenda-daily/weekly
  1024. :type 'plist)
  1025. (defcustom org-agenda-search-view-always-boolean nil
  1026. "Non-nil means the search string is interpreted as individual parts.
  1027. The search string for search view can either be interpreted as a phrase,
  1028. or as a list of snippets that define a boolean search for a number of
  1029. strings.
  1030. When this is non-nil, the string will be split on whitespace, and each
  1031. snippet will be searched individually, and all must match in order to
  1032. select an entry. A snippet is then a single string of non-white
  1033. characters, or a string in double quotes, or a regexp in {} braces.
  1034. If a snippet is preceded by \"-\", the snippet must *not* match.
  1035. \"+\" is syntactic sugar for positive selection. Each snippet may
  1036. be found as a full word or a partial word, but see the variable
  1037. `org-agenda-search-view-force-full-words'.
  1038. When this is nil, search will look for the entire search phrase as one,
  1039. with each space character matching any amount of whitespace, including
  1040. line breaks.
  1041. Even when this is nil, you can still switch to Boolean search dynamically
  1042. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1043. is a regexp marked with braces like \"{abc}\", this will also switch to
  1044. boolean search."
  1045. :group 'org-agenda-search-view
  1046. :type 'boolean)
  1047. (if (fboundp 'defvaralias)
  1048. (defvaralias 'org-agenda-search-view-search-words-only
  1049. 'org-agenda-search-view-always-boolean))
  1050. (defcustom org-agenda-search-view-force-full-words nil
  1051. "Non-nil means, search words must be matches as complete words.
  1052. When nil, they may also match part of a word."
  1053. :group 'org-agenda-search-view
  1054. :type 'boolean)
  1055. (defgroup org-agenda-time-grid nil
  1056. "Options concerning the time grid in the Org-mode Agenda."
  1057. :tag "Org Agenda Time Grid"
  1058. :group 'org-agenda)
  1059. (defcustom org-agenda-search-headline-for-time t
  1060. "Non-nil means search headline for a time-of-day.
  1061. If the headline contains a time-of-day in one format or another, it will
  1062. be used to sort the entry into the time sequence of items for a day.
  1063. Some people have time stamps in the headline that refer to the creation
  1064. time or so, and then this produces an unwanted side effect. If this is
  1065. the case for your, use this variable to turn off searching the headline
  1066. for a time."
  1067. :group 'org-agenda-time-grid
  1068. :type 'boolean)
  1069. (defcustom org-agenda-use-time-grid t
  1070. "Non-nil means show a time grid in the agenda schedule.
  1071. A time grid is a set of lines for specific times (like every two hours between
  1072. 8:00 and 20:00). The items scheduled for a day at specific times are
  1073. sorted in between these lines.
  1074. For details about when the grid will be shown, and what it will look like, see
  1075. the variable `org-agenda-time-grid'."
  1076. :group 'org-agenda-time-grid
  1077. :type 'boolean)
  1078. (defcustom org-agenda-time-grid
  1079. '((daily today require-timed)
  1080. "----------------"
  1081. (800 1000 1200 1400 1600 1800 2000))
  1082. "The settings for time grid for agenda display.
  1083. This is a list of three items. The first item is again a list. It contains
  1084. symbols specifying conditions when the grid should be displayed:
  1085. daily if the agenda shows a single day
  1086. weekly if the agenda shows an entire week
  1087. today show grid on current date, independent of daily/weekly display
  1088. require-timed show grid only if at least one item has a time specification
  1089. The second item is a string which will be placed behind the grid time.
  1090. The third item is a list of integers, indicating the times that should have
  1091. a grid line."
  1092. :group 'org-agenda-time-grid
  1093. :type
  1094. '(list
  1095. (set :greedy t :tag "Grid Display Options"
  1096. (const :tag "Show grid in single day agenda display" daily)
  1097. (const :tag "Show grid in weekly agenda display" weekly)
  1098. (const :tag "Always show grid for today" today)
  1099. (const :tag "Show grid only if any timed entries are present"
  1100. require-timed)
  1101. (const :tag "Skip grid times already present in an entry"
  1102. remove-match))
  1103. (string :tag "Grid String")
  1104. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1105. (defcustom org-agenda-show-current-time-in-grid t
  1106. "Non-nil means show the current time in the time grid."
  1107. :group 'org-agenda-time-grid
  1108. :type 'boolean)
  1109. (defcustom org-agenda-current-time-string
  1110. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1111. "The string for the current time marker in the agenda."
  1112. :group 'org-agenda-time-grid
  1113. :type 'string)
  1114. (defgroup org-agenda-sorting nil
  1115. "Options concerning sorting in the Org-mode Agenda."
  1116. :tag "Org Agenda Sorting"
  1117. :group 'org-agenda)
  1118. (defcustom org-agenda-sorting-strategy
  1119. '((agenda habit-down time-up priority-down category-keep)
  1120. (todo priority-down category-keep)
  1121. (tags priority-down category-keep)
  1122. (search category-keep))
  1123. "Sorting structure for the agenda items of a single day.
  1124. This is a list of symbols which will be used in sequence to determine
  1125. if an entry should be listed before another entry. The following
  1126. symbols are recognized:
  1127. time-up Put entries with time-of-day indications first, early first
  1128. time-down Put entries with time-of-day indications first, late first
  1129. category-keep Keep the default order of categories, corresponding to the
  1130. sequence in `org-agenda-files'.
  1131. category-up Sort alphabetically by category, A-Z.
  1132. category-down Sort alphabetically by category, Z-A.
  1133. tag-up Sort alphabetically by last tag, A-Z.
  1134. tag-down Sort alphabetically by last tag, Z-A.
  1135. priority-up Sort numerically by priority, high priority last.
  1136. priority-down Sort numerically by priority, high priority first.
  1137. todo-state-up Sort by todo state, tasks that are done last.
  1138. todo-state-down Sort by todo state, tasks that are done first.
  1139. effort-up Sort numerically by estimated effort, high effort last.
  1140. effort-down Sort numerically by estimated effort, high effort first.
  1141. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1142. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1143. habit-up Put entries that are habits first
  1144. habit-down Put entries that are habits last
  1145. alpha-up Sort headlines alphabetically
  1146. alpha-down Sort headlines alphabetically, reversed
  1147. The different possibilities will be tried in sequence, and testing stops
  1148. if one comparison returns a \"not-equal\". For example, the default
  1149. '(time-up category-keep priority-down)
  1150. means: Pull out all entries having a specified time of day and sort them,
  1151. in order to make a time schedule for the current day the first thing in the
  1152. agenda listing for the day. Of the entries without a time indication, keep
  1153. the grouped in categories, don't sort the categories, but keep them in
  1154. the sequence given in `org-agenda-files'. Within each category sort by
  1155. priority.
  1156. Leaving out `category-keep' would mean that items will be sorted across
  1157. categories by priority.
  1158. Instead of a single list, this can also be a set of list for specific
  1159. contents, with a context symbol in the car of the list, any of
  1160. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1161. Custom commands can bind this variable in the options section."
  1162. :group 'org-agenda-sorting
  1163. :type `(choice
  1164. (repeat :tag "General" ,org-sorting-choice)
  1165. (list :tag "Individually"
  1166. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1167. (repeat ,org-sorting-choice))
  1168. (cons (const :tag "Strategy for TODO lists" todo)
  1169. (repeat ,org-sorting-choice))
  1170. (cons (const :tag "Strategy for Tags matches" tags)
  1171. (repeat ,org-sorting-choice))
  1172. (cons (const :tag "Strategy for search matches" search)
  1173. (repeat ,org-sorting-choice)))))
  1174. (defcustom org-agenda-cmp-user-defined nil
  1175. "A function to define the comparison `user-defined'.
  1176. This function must receive two arguments, agenda entry a and b.
  1177. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1178. the user comparison, return nil.
  1179. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1180. part of an agenda sorting strategy."
  1181. :group 'org-agenda-sorting
  1182. :type 'symbol)
  1183. (defcustom org-sort-agenda-notime-is-late t
  1184. "Non-nil means items without time are considered late.
  1185. This is only relevant for sorting. When t, items which have no explicit
  1186. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1187. do have a time. When nil, the default time is before 0:00. You can use this
  1188. option to decide if the schedule for today should come before or after timeless
  1189. agenda entries."
  1190. :group 'org-agenda-sorting
  1191. :type 'boolean)
  1192. (defcustom org-sort-agenda-noeffort-is-high t
  1193. "Non-nil means items without effort estimate are sorted as high effort.
  1194. This also applies when filtering an agenda view with respect to the
  1195. < or > effort operator. Then, tasks with no effort defined will be treated
  1196. as tasks with high effort.
  1197. When nil, such items are sorted as 0 minutes effort."
  1198. :group 'org-agenda-sorting
  1199. :type 'boolean)
  1200. (defgroup org-agenda-line-format nil
  1201. "Options concerning the entry prefix in the Org-mode agenda display."
  1202. :tag "Org Agenda Line Format"
  1203. :group 'org-agenda)
  1204. (defcustom org-agenda-prefix-format
  1205. '((agenda . " %i %-12:c%?-12t% s")
  1206. (timeline . " % s")
  1207. (todo . " %i %-12:c")
  1208. (tags . " %i %-12:c")
  1209. (search . " %i %-12:c"))
  1210. "Format specifications for the prefix of items in the agenda views.
  1211. An alist with four entries, for the different agenda types. The keys to the
  1212. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1213. are format strings.
  1214. This format works similar to a printf format, with the following meaning:
  1215. %c the category of the item, \"Diary\" for entries from the diary, or
  1216. as given by the CATEGORY keyword or derived from the file name.
  1217. %i the icon category of the item, as give in
  1218. `org-agenda-category-icon-alist'.
  1219. %T the *last* tag of the item. Last because inherited tags come
  1220. first in the list.
  1221. %t the time-of-day specification if one applies to the entry, in the
  1222. format HH:MM
  1223. %s Scheduling/Deadline information, a short string
  1224. %(expression) Eval EXPRESSION and replace the control string
  1225. by the result
  1226. All specifiers work basically like the standard `%s' of printf, but may
  1227. contain two additional characters: A question mark just after the `%' and
  1228. a whitespace/punctuation character just before the final letter.
  1229. If the first character after `%' is a question mark, the entire field
  1230. will only be included if the corresponding value applies to the
  1231. current entry. This is useful for fields which should have fixed
  1232. width when present, but zero width when absent. For example,
  1233. \"%?-12t\" will result in a 12 character time field if a time of the
  1234. day is specified, but will completely disappear in entries which do
  1235. not contain a time.
  1236. If there is punctuation or whitespace character just before the final
  1237. format letter, this character will be appended to the field value if
  1238. the value is not empty. For example, the format \"%-12:c\" leads to
  1239. \"Diary: \" if the category is \"Diary\". If the category were be
  1240. empty, no additional colon would be inserted.
  1241. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1242. - Indent the line with two space characters
  1243. - Give the category in a 12 chars wide field, padded with whitespace on
  1244. the right (because of `-'). Append a colon if there is a category
  1245. (because of `:').
  1246. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1247. time, don't put in an empty field, just skip it (because of '?').
  1248. - Finally, put the scheduling information and append a whitespace.
  1249. As another example, if you don't want the time-of-day of entries in
  1250. the prefix, you could use:
  1251. (setq org-agenda-prefix-format \" %-11:c% s\")
  1252. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1253. `org-agenda-remove-tags'.
  1254. Custom commands can set this variable in the options section."
  1255. :type '(choice
  1256. (string :tag "General format")
  1257. (list :greedy t :tag "View dependent"
  1258. (cons (const agenda) (string :tag "Format"))
  1259. (cons (const timeline) (string :tag "Format"))
  1260. (cons (const todo) (string :tag "Format"))
  1261. (cons (const tags) (string :tag "Format"))
  1262. (cons (const search) (string :tag "Format"))))
  1263. :group 'org-agenda-line-format)
  1264. (defvar org-prefix-format-compiled nil
  1265. "The compiled version of the most recently used prefix format.
  1266. See the variable `org-agenda-prefix-format'.")
  1267. (defcustom org-agenda-todo-keyword-format "%-1s"
  1268. "Format for the TODO keyword in agenda lines.
  1269. Set this to something like \"%-12s\" if you want all TODO keywords
  1270. to occupy a fixed space in the agenda display."
  1271. :group 'org-agenda-line-format
  1272. :type 'string)
  1273. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1274. "Text preceding timerange entries in the agenda view.
  1275. This is a list with two strings. The first applies when the range
  1276. is entirely on one day. The second applies if the range spans several days.
  1277. The strings may have two \"%d\" format specifiers which will be filled
  1278. with the sequence number of the days, and the total number of days in the
  1279. range, respectively."
  1280. :group 'org-agenda-line-format
  1281. :type '(list
  1282. (string :tag "Deadline today ")
  1283. (choice :tag "Deadline relative"
  1284. (string :tag "Format string")
  1285. (function))))
  1286. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1287. "Text preceding scheduled items in the agenda view.
  1288. This is a list with two strings. The first applies when the item is
  1289. scheduled on the current day. The second applies when it has been scheduled
  1290. previously, it may contain a %d indicating that this is the nth time that
  1291. this item is scheduled, due to automatic rescheduling of unfinished items
  1292. for the following day. So this number is one larger than the number of days
  1293. that passed since this item was scheduled first."
  1294. :group 'org-agenda-line-format
  1295. :type '(list
  1296. (string :tag "Scheduled today ")
  1297. (string :tag "Scheduled previously")))
  1298. (defcustom org-agenda-inactive-leader "["
  1299. "Text preceding item pulled into the agenda by inactive time stamps.
  1300. These entries are added to the agenda when pressing \"[\"."
  1301. :group 'org-agenda-line-format
  1302. :type '(list
  1303. (string :tag "Scheduled today ")
  1304. (string :tag "Scheduled previously")))
  1305. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1306. "Text preceding deadline items in the agenda view.
  1307. This is a list with two strings. The first applies when the item has its
  1308. deadline on the current day. The second applies when it is in the past or
  1309. in the future, it may contain %d to capture how many days away the deadline
  1310. is (was)."
  1311. :group 'org-agenda-line-format
  1312. :type '(list
  1313. (string :tag "Deadline today ")
  1314. (choice :tag "Deadline relative"
  1315. (string :tag "Format string")
  1316. (function))))
  1317. (defcustom org-agenda-remove-times-when-in-prefix t
  1318. "Non-nil means remove duplicate time specifications in agenda items.
  1319. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1320. time-of-day specification in a headline or diary entry is extracted and
  1321. placed into the prefix. If this option is non-nil, the original specification
  1322. \(a timestamp or -range, or just a plain time(range) specification like
  1323. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1324. cluttered.
  1325. The option can be t or nil. It may also be the symbol `beg', indicating
  1326. that the time should only be removed when it is located at the beginning of
  1327. the headline/diary entry."
  1328. :group 'org-agenda-line-format
  1329. :type '(choice
  1330. (const :tag "Always" t)
  1331. (const :tag "Never" nil)
  1332. (const :tag "When at beginning of entry" beg)))
  1333. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1334. "Non-nil means remove time ranges specifications in agenda
  1335. items that span on several days."
  1336. :group 'org-agenda-line-format
  1337. :type 'boolean)
  1338. (defcustom org-agenda-default-appointment-duration nil
  1339. "Default duration for appointments that only have a starting time.
  1340. When nil, no duration is specified in such cases.
  1341. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1342. :group 'org-agenda-line-format
  1343. :type '(choice
  1344. (integer :tag "Minutes")
  1345. (const :tag "No default duration")))
  1346. (defcustom org-agenda-show-inherited-tags t
  1347. "Non-nil means show inherited tags in each agenda line."
  1348. :group 'org-agenda-line-format
  1349. :type 'boolean)
  1350. (defcustom org-agenda-hide-tags-regexp nil
  1351. "Regular expression used to filter away specific tags in agenda views.
  1352. This means that these tags will be present, but not be shown in the agenda
  1353. line. Secondary filtering will still work on the hidden tags.
  1354. Nil means don't hide any tags."
  1355. :group 'org-agenda-line-format
  1356. :type '(choice
  1357. (const :tag "Hide none" nil)
  1358. (string :tag "Regexp ")))
  1359. (defcustom org-agenda-remove-tags nil
  1360. "Non-nil means remove the tags from the headline copy in the agenda.
  1361. When this is the symbol `prefix', only remove tags when
  1362. `org-agenda-prefix-format' contains a `%T' specifier."
  1363. :group 'org-agenda-line-format
  1364. :type '(choice
  1365. (const :tag "Always" t)
  1366. (const :tag "Never" nil)
  1367. (const :tag "When prefix format contains %T" prefix)))
  1368. (if (fboundp 'defvaralias)
  1369. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1370. 'org-agenda-remove-tags))
  1371. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1372. "Shift tags in agenda items to this column.
  1373. If this number is positive, it specifies the column. If it is negative,
  1374. it means that the tags should be flushright to that column. For example,
  1375. -80 works well for a normal 80 character screen."
  1376. :group 'org-agenda-line-format
  1377. :type 'integer)
  1378. (if (fboundp 'defvaralias)
  1379. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1380. (defcustom org-agenda-fontify-priorities 'cookies
  1381. "Non-nil means highlight low and high priorities in agenda.
  1382. When t, the highest priority entries are bold, lowest priority italic.
  1383. However, settings in `org-priority-faces' will overrule these faces.
  1384. When this variable is the symbol `cookies', only fontify the
  1385. cookies, not the entire task.
  1386. This may also be an association list of priority faces, whose
  1387. keys are the character values of `org-highest-priority',
  1388. `org-default-priority', and `org-lowest-priority' (the default values
  1389. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1390. color as a string, or a list like `(:background \"Red\")'.
  1391. If it is a color, the variable `org-faces-easy-properties'
  1392. determines if it is a foreground or a background color."
  1393. :group 'org-agenda-line-format
  1394. :type '(choice
  1395. (const :tag "Never" nil)
  1396. (const :tag "Defaults" t)
  1397. (const :tag "Cookies only" cookies)
  1398. (repeat :tag "Specify"
  1399. (list (character :tag "Priority" :value ?A)
  1400. (choice :tag "Face "
  1401. (string :tag "Color")
  1402. (sexp :tag "Face"))))))
  1403. (defcustom org-agenda-day-face-function nil
  1404. "Function called to determine what face should be used to display a day.
  1405. The only argument passed to that function is the day. It should
  1406. returns a face, or nil if does not want to specify a face and let
  1407. the normal rules apply."
  1408. :group 'org-agenda-line-format
  1409. :type 'function)
  1410. (defcustom org-agenda-category-icon-alist nil
  1411. "Alist of category icon to be displayed in agenda views.
  1412. Each entry should have the following format:
  1413. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1414. Where CATEGORY-REGEXP is a regexp matching the categories where
  1415. the icon should be displayed.
  1416. FILE-OR-DATA either a file path or a string containing image data.
  1417. The other fields can be omited safely if not needed:
  1418. TYPE indicates the image type.
  1419. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1420. image data.
  1421. PROPS are additional image attributes to assign to the image,
  1422. like, e.g. `:ascent center'.
  1423. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1424. If you want to set the display properties yourself, just put a
  1425. list as second element:
  1426. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1427. For example, to display a 16px horizontal space for Emacs
  1428. category, you can use:
  1429. (\"Emacs\" '(space . (:width (16))))"
  1430. :group 'org-agenda-line-format
  1431. :type '(alist :key-type (string :tag "Regexp matching category")
  1432. :value-type (choice (list :tag "Icon"
  1433. (string :tag "File or data")
  1434. (symbol :tag "Type")
  1435. (boolean :tag "Data?")
  1436. (repeat :tag "Extra image properties" :inline t symbol))
  1437. (list :tag "Display properties" sexp))))
  1438. (defgroup org-agenda-column-view nil
  1439. "Options concerning column view in the agenda."
  1440. :tag "Org Agenda Column View"
  1441. :group 'org-agenda)
  1442. (defcustom org-agenda-columns-show-summaries t
  1443. "Non-nil means show summaries for columns displayed in the agenda view."
  1444. :group 'org-agenda-column-view
  1445. :type 'boolean)
  1446. (defcustom org-agenda-columns-compute-summary-properties t
  1447. "Non-nil means recompute all summary properties before column view.
  1448. When column view in the agenda is listing properties that have a summary
  1449. operator, it can go to all relevant buffers and recompute the summaries
  1450. there. This can mean overhead for the agenda column view, but is necessary
  1451. to have thing up to date.
  1452. As a special case, a CLOCKSUM property also makes sure that the clock
  1453. computations are current."
  1454. :group 'org-agenda-column-view
  1455. :type 'boolean)
  1456. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1457. "Non-nil means the duration of an appointment will add to day effort.
  1458. The property to which appointment durations will be added is the one given
  1459. in the option `org-effort-property'. If an appointment does not have
  1460. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1461. is not set, an appointment without end time will not contribute to the time
  1462. estimate."
  1463. :group 'org-agenda-column-view
  1464. :type 'boolean)
  1465. (defcustom org-agenda-auto-exclude-function nil
  1466. "A function called with a tag to decide if it is filtered on '/ RET'.
  1467. The sole argument to the function, which is called once for each
  1468. possible tag, is a string giving the name of the tag. The
  1469. function should return either nil if the tag should be included
  1470. as normal, or \"-<TAG>\" to exclude the tag.
  1471. Note that for the purpose of tag filtering, only the lower-case version of
  1472. all tags will be considered, so that this function will only ever see
  1473. the lower-case version of all tags."
  1474. :group 'org-agenda
  1475. :type 'function)
  1476. (eval-when-compile
  1477. (require 'cl))
  1478. (require 'org)
  1479. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1480. "Execute BODY with point at location given by `org-hd-marker' property.
  1481. If STRING is non-nil, the text property will be fetched from position 0
  1482. in that string. If STRING is nil, it will be fetched from the beginning
  1483. of the current line."
  1484. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1485. 'org-hd-marker string)))
  1486. (with-current-buffer (marker-buffer marker)
  1487. (save-excursion
  1488. (goto-char marker)
  1489. ,@body))))
  1490. (defun org-add-agenda-custom-command (entry)
  1491. "Replace or add a command in `org-agenda-custom-commands'.
  1492. This is mostly for hacking and trying a new command - once the command
  1493. works you probably want to add it to `org-agenda-custom-commands' for good."
  1494. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1495. (if ass
  1496. (setcdr ass (cdr entry))
  1497. (push entry org-agenda-custom-commands))))
  1498. ;;; Define the Org-agenda-mode
  1499. (defvar org-agenda-mode-map (make-sparse-keymap)
  1500. "Keymap for `org-agenda-mode'.")
  1501. (if (fboundp 'defvaralias)
  1502. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1503. (defvar org-agenda-menu) ; defined later in this file.
  1504. (defvar org-agenda-restrict) ; defined later in this file.
  1505. (defvar org-agenda-follow-mode nil)
  1506. (defvar org-agenda-entry-text-mode nil)
  1507. (defvar org-agenda-clockreport-mode nil)
  1508. (defvar org-agenda-show-log nil)
  1509. (defvar org-agenda-redo-command nil)
  1510. (defvar org-agenda-query-string nil)
  1511. (defvar org-agenda-mode-hook nil
  1512. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1513. (defvar org-agenda-type nil)
  1514. (defvar org-agenda-force-single-file nil)
  1515. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1516. (defun org-agenda-mode ()
  1517. "Mode for time-sorted view on action items in Org-mode files.
  1518. The following commands are available:
  1519. \\{org-agenda-mode-map}"
  1520. (interactive)
  1521. (kill-all-local-variables)
  1522. (setq org-agenda-undo-list nil
  1523. org-agenda-pending-undo-list nil
  1524. org-agenda-bulk-marked-entries nil)
  1525. (setq major-mode 'org-agenda-mode)
  1526. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1527. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1528. (setq mode-name "Org-Agenda")
  1529. (use-local-map org-agenda-mode-map)
  1530. (easy-menu-add org-agenda-menu)
  1531. (if org-startup-truncated (setq truncate-lines t))
  1532. (org-set-local 'line-move-visual nil)
  1533. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1534. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1535. ;; Make sure properties are removed when copying text
  1536. (when (boundp 'buffer-substring-filters)
  1537. (org-set-local 'buffer-substring-filters
  1538. (cons (lambda (x)
  1539. (set-text-properties 0 (length x) nil x) x)
  1540. buffer-substring-filters)))
  1541. (unless org-agenda-keep-modes
  1542. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1543. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1544. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1545. org-agenda-show-log org-agenda-start-with-log-mode))
  1546. (easy-menu-change
  1547. '("Agenda") "Agenda Files"
  1548. (append
  1549. (list
  1550. (vector
  1551. (if (get 'org-agenda-files 'org-restrict)
  1552. "Restricted to single file"
  1553. "Edit File List")
  1554. '(org-edit-agenda-file-list)
  1555. (not (get 'org-agenda-files 'org-restrict)))
  1556. "--")
  1557. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1558. (org-agenda-set-mode-name)
  1559. (apply
  1560. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1561. (list 'org-agenda-mode-hook)))
  1562. (substitute-key-definition 'undo 'org-agenda-undo
  1563. org-agenda-mode-map global-map)
  1564. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1565. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1566. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1567. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1568. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1569. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1570. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1571. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1572. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1573. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1574. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1575. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1576. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1577. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1578. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1579. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1580. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1581. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1582. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1583. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1584. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1585. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1586. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1587. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1588. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1589. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1590. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1591. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1592. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1593. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1594. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1595. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1596. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1597. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1598. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1599. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1600. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1601. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1602. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1603. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1604. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1605. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1606. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1607. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1608. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1609. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1610. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1611. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1612. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1613. (while l (org-defkey org-agenda-mode-map
  1614. (int-to-string (pop l)) 'digit-argument)))
  1615. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1616. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1617. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1618. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1619. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1620. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1621. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1622. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1623. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1624. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1625. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1627. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1628. 'org-clock-modify-effort-estimate)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1630. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1631. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1632. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1633. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1634. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1635. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1636. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1637. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1638. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1639. (substitute-key-definition 'next-line 'org-agenda-next-line
  1640. org-agenda-mode-map global-map)
  1641. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1642. org-agenda-mode-map global-map)
  1643. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1644. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1645. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1646. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1647. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1648. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1649. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1650. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1651. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1652. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1653. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1654. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1655. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1656. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1657. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1658. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1659. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1660. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1661. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1662. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1663. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1664. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1665. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1666. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1667. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1668. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1669. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1670. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1671. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1672. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1673. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1674. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1675. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1676. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1677. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1678. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1679. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1680. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1681. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1682. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1683. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1684. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1685. (when org-agenda-mouse-1-follows-link
  1686. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1687. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1688. '("Agenda"
  1689. ("Agenda Files")
  1690. "--"
  1691. ("Agenda Dates"
  1692. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1693. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1694. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1695. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1696. "--"
  1697. ("View"
  1698. ["Day View" org-agenda-day-view
  1699. :active (org-agenda-check-type nil 'agenda)
  1700. :style radio :selected (eq org-agenda-current-span 'day)
  1701. :keys "v d (or just d)"]
  1702. ["Week View" org-agenda-week-view
  1703. :active (org-agenda-check-type nil 'agenda)
  1704. :style radio :selected (eq org-agenda-current-span 'week)
  1705. :keys "v w (or just w)"]
  1706. ["Month View" org-agenda-month-view
  1707. :active (org-agenda-check-type nil 'agenda)
  1708. :style radio :selected (eq org-agenda-current-span 'month)
  1709. :keys "v m"]
  1710. ["Year View" org-agenda-year-view
  1711. :active (org-agenda-check-type nil 'agenda)
  1712. :style radio :selected (eq org-agenda-current-span 'year)
  1713. :keys "v y"]
  1714. "--"
  1715. ["Include Diary" org-agenda-toggle-diary
  1716. :style toggle :selected org-agenda-include-diary
  1717. :active (org-agenda-check-type nil 'agenda)]
  1718. ["Include Deadlines" org-agenda-toggle-deadlines
  1719. :style toggle :selected org-agenda-include-deadlines
  1720. :active (org-agenda-check-type nil 'agenda)]
  1721. ["Use Time Grid" org-agenda-toggle-time-grid
  1722. :style toggle :selected org-agenda-use-time-grid
  1723. :active (org-agenda-check-type nil 'agenda)]
  1724. "--"
  1725. ["Show clock report" org-agenda-clockreport-mode
  1726. :style toggle :selected org-agenda-clockreport-mode
  1727. :active (org-agenda-check-type nil 'agenda)]
  1728. ["Show some entry text" org-agenda-entry-text-mode
  1729. :style toggle :selected org-agenda-entry-text-mode
  1730. :active t]
  1731. "--"
  1732. ["Show Logbook entries" org-agenda-log-mode
  1733. :style toggle :selected org-agenda-show-log
  1734. :active (org-agenda-check-type nil 'agenda 'timeline)
  1735. :keys "v l (or just l)"]
  1736. ["Include archived trees" org-agenda-archives-mode
  1737. :style toggle :selected org-agenda-archives-mode :active t
  1738. :keys "v a"]
  1739. ["Include archive files" (org-agenda-archives-mode t)
  1740. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1741. :keys "v A"]
  1742. "--"
  1743. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1744. ["Write view to file" org-write-agenda t]
  1745. ["Rebuild buffer" org-agenda-redo t]
  1746. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1747. "--"
  1748. ["Show original entry" org-agenda-show t]
  1749. ["Go To (other window)" org-agenda-goto t]
  1750. ["Go To (this window)" org-agenda-switch-to t]
  1751. ["Follow Mode" org-agenda-follow-mode
  1752. :style toggle :selected org-agenda-follow-mode :active t]
  1753. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1754. "--"
  1755. ("TODO"
  1756. ["Cycle TODO" org-agenda-todo t]
  1757. ["Next TODO set" org-agenda-todo-nextset t]
  1758. ["Previous TODO set" org-agenda-todo-previousset t]
  1759. ["Add note" org-agenda-add-note t])
  1760. ("Archive/Refile/Delete"
  1761. ["Archive default" org-agenda-archive-default t]
  1762. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1763. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1764. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1765. ["Archive subtree" org-agenda-archive t]
  1766. "--"
  1767. ["Refile" org-agenda-refile t]
  1768. "--"
  1769. ["Delete subtree" org-agenda-kill t])
  1770. ("Bulk action"
  1771. ["Mark entry" org-agenda-bulk-mark t]
  1772. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1773. ["Unmark entry" org-agenda-bulk-unmark t]
  1774. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1775. ["Act on all marked" org-agenda-bulk-action t]
  1776. "--"
  1777. ("Tags and Properties"
  1778. ["Show all Tags" org-agenda-show-tags t]
  1779. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1780. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1781. "--"
  1782. ["Column View" org-columns t])
  1783. ("Deadline/Schedule"
  1784. ["Schedule" org-agenda-schedule t]
  1785. ["Set Deadline" org-agenda-deadline t]
  1786. "--"
  1787. ["Mark item" org-agenda-action :active t :keys "k m"]
  1788. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1789. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1790. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1791. "--"
  1792. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1793. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1794. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1795. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1796. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1797. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1798. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1799. ("Clock and Effort"
  1800. ["Clock in" org-agenda-clock-in t]
  1801. ["Clock out" org-agenda-clock-out t]
  1802. ["Clock cancel" org-agenda-clock-cancel t]
  1803. ["Goto running clock" org-clock-goto t]
  1804. "--"
  1805. ["Set Effort" org-agenda-set-effort t]
  1806. ["Change clocked effort" org-clock-modify-effort-estimate
  1807. (org-clock-is-active)])
  1808. ("Priority"
  1809. ["Set Priority" org-agenda-priority t]
  1810. ["Increase Priority" org-agenda-priority-up t]
  1811. ["Decrease Priority" org-agenda-priority-down t]
  1812. ["Show Priority" org-agenda-show-priority t])
  1813. ("Calendar/Diary"
  1814. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1815. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1816. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1817. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1818. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1819. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1820. "--"
  1821. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1822. "--"
  1823. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1824. "--"
  1825. ("MobileOrg"
  1826. ["Push Files and Views" org-mobile-push t]
  1827. ["Get Captured and Flagged" org-mobile-pull t]
  1828. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1829. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1830. "--"
  1831. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1832. "--"
  1833. ["Quit" org-agenda-quit t]
  1834. ["Exit and Release Buffers" org-agenda-exit t]
  1835. ))
  1836. ;;; Agenda undo
  1837. (defvar org-agenda-allow-remote-undo t
  1838. "Non-nil means allow remote undo from the agenda buffer.")
  1839. (defvar org-agenda-undo-list nil
  1840. "List of undoable operations in the agenda since last refresh.")
  1841. (defvar org-agenda-undo-has-started-in nil
  1842. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1843. (defvar org-agenda-pending-undo-list nil
  1844. "In a series of undo commands, this is the list of remaining undo items.")
  1845. (defun org-agenda-undo ()
  1846. "Undo a remote editing step in the agenda.
  1847. This undoes changes both in the agenda buffer and in the remote buffer
  1848. that have been changed along."
  1849. (interactive)
  1850. (or org-agenda-allow-remote-undo
  1851. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1852. (if (not (eq this-command last-command))
  1853. (setq org-agenda-undo-has-started-in nil
  1854. org-agenda-pending-undo-list org-agenda-undo-list))
  1855. (if (not org-agenda-pending-undo-list)
  1856. (error "No further undo information"))
  1857. (let* ((entry (pop org-agenda-pending-undo-list))
  1858. buf line cmd rembuf)
  1859. (setq cmd (pop entry) line (pop entry))
  1860. (setq rembuf (nth 2 entry))
  1861. (org-with-remote-undo rembuf
  1862. (while (bufferp (setq buf (pop entry)))
  1863. (if (pop entry)
  1864. (with-current-buffer buf
  1865. (let ((last-undo-buffer buf)
  1866. (inhibit-read-only t))
  1867. (unless (memq buf org-agenda-undo-has-started-in)
  1868. (push buf org-agenda-undo-has-started-in)
  1869. (make-local-variable 'pending-undo-list)
  1870. (undo-start))
  1871. (while (and pending-undo-list
  1872. (listp pending-undo-list)
  1873. (not (car pending-undo-list)))
  1874. (pop pending-undo-list))
  1875. (undo-more 1))))))
  1876. (org-goto-line line)
  1877. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1878. (defun org-verify-change-for-undo (l1 l2)
  1879. "Verify that a real change occurred between the undo lists L1 and L2."
  1880. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1881. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1882. (not (eq l1 l2)))
  1883. ;;; Agenda dispatch
  1884. (defvar org-agenda-restrict nil)
  1885. (defvar org-agenda-restrict-begin (make-marker))
  1886. (defvar org-agenda-restrict-end (make-marker))
  1887. (defvar org-agenda-last-dispatch-buffer nil)
  1888. (defvar org-agenda-overriding-restriction nil)
  1889. ;;;###autoload
  1890. (defun org-agenda (&optional arg keys restriction)
  1891. "Dispatch agenda commands to collect entries to the agenda buffer.
  1892. Prompts for a command to execute. Any prefix arg will be passed
  1893. on to the selected command. The default selections are:
  1894. a Call `org-agenda-list' to display the agenda for current day or week.
  1895. t Call `org-todo-list' to display the global todo list.
  1896. T Call `org-todo-list' to display the global todo list, select only
  1897. entries with a specific TODO keyword (the user gets a prompt).
  1898. m Call `org-tags-view' to display headlines with tags matching
  1899. a condition (the user is prompted for the condition).
  1900. M Like `m', but select only TODO entries, no ordinary headlines.
  1901. L Create a timeline for the current buffer.
  1902. e Export views to associated files.
  1903. s Search entries for keywords.
  1904. / Multi occur across all agenda files and also files listed
  1905. in `org-agenda-text-search-extra-files'.
  1906. < Restrict agenda commands to buffer, subtree, or region.
  1907. Press several times to get the desired effect.
  1908. > Remove a previous restriction.
  1909. # List \"stuck\" projects.
  1910. ! Configure what \"stuck\" means.
  1911. C Configure custom agenda commands.
  1912. More commands can be added by configuring the variable
  1913. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1914. searches can be pre-defined in this way.
  1915. If the current buffer is in Org-mode and visiting a file, you can also
  1916. first press `<' once to indicate that the agenda should be temporarily
  1917. \(until the next use of \\[org-agenda]) restricted to the current file.
  1918. Pressing `<' twice means to restrict to the current subtree or region
  1919. \(if active)."
  1920. (interactive "P")
  1921. (catch 'exit
  1922. (let* ((prefix-descriptions nil)
  1923. (org-agenda-window-setup (if (equal (buffer-name)
  1924. org-agenda-buffer-name)
  1925. 'current-window
  1926. org-agenda-window-setup))
  1927. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1928. (org-agenda-custom-commands
  1929. ;; normalize different versions
  1930. (delq nil
  1931. (mapcar
  1932. (lambda (x)
  1933. (cond ((stringp (cdr x))
  1934. (push x prefix-descriptions)
  1935. nil)
  1936. ((stringp (nth 1 x)) x)
  1937. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1938. (t (cons (car x) (cons "" (cdr x))))))
  1939. org-agenda-custom-commands)))
  1940. (buf (current-buffer))
  1941. (bfn (buffer-file-name (buffer-base-buffer)))
  1942. entry key type match lprops ans)
  1943. ;; Turn off restriction unless there is an overriding one,
  1944. (unless org-agenda-overriding-restriction
  1945. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1946. ;; There is a request to keep the file list in place
  1947. (put 'org-agenda-files 'org-restrict nil))
  1948. (setq org-agenda-restrict nil)
  1949. (move-marker org-agenda-restrict-begin nil)
  1950. (move-marker org-agenda-restrict-end nil))
  1951. ;; Delete old local properties
  1952. (put 'org-agenda-redo-command 'org-lprops nil)
  1953. ;; Delete previously set last-arguments
  1954. (put 'org-agenda-redo-command 'last-args nil)
  1955. ;; Remember where this call originated
  1956. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1957. (unless keys
  1958. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1959. keys (car ans)
  1960. restriction (cdr ans)))
  1961. ;; Establish the restriction, if any
  1962. (when (and (not org-agenda-overriding-restriction) restriction)
  1963. (put 'org-agenda-files 'org-restrict (list bfn))
  1964. (cond
  1965. ((eq restriction 'region)
  1966. (setq org-agenda-restrict t)
  1967. (move-marker org-agenda-restrict-begin (region-beginning))
  1968. (move-marker org-agenda-restrict-end (region-end)))
  1969. ((eq restriction 'subtree)
  1970. (save-excursion
  1971. (setq org-agenda-restrict t)
  1972. (org-back-to-heading t)
  1973. (move-marker org-agenda-restrict-begin (point))
  1974. (move-marker org-agenda-restrict-end
  1975. (progn (org-end-of-subtree t)))))))
  1976. ;; For example the todo list should not need it (but does...)
  1977. (cond
  1978. ((setq entry (assoc keys org-agenda-custom-commands))
  1979. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1980. (progn
  1981. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1982. lprops (nth 4 entry))
  1983. (put 'org-agenda-redo-command 'org-lprops lprops)
  1984. (cond
  1985. ((eq type 'agenda)
  1986. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1987. ((eq type 'alltodo)
  1988. (org-let lprops '(org-todo-list current-prefix-arg)))
  1989. ((eq type 'search)
  1990. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1991. ((eq type 'stuck)
  1992. (org-let lprops '(org-agenda-list-stuck-projects
  1993. current-prefix-arg)))
  1994. ((eq type 'tags)
  1995. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1996. ((eq type 'tags-todo)
  1997. (org-let lprops '(org-tags-view '(4) match)))
  1998. ((eq type 'todo)
  1999. (org-let lprops '(org-todo-list match)))
  2000. ((eq type 'tags-tree)
  2001. (org-check-for-org-mode)
  2002. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2003. ((eq type 'todo-tree)
  2004. (org-check-for-org-mode)
  2005. (org-let lprops
  2006. '(org-occur (concat "^" outline-regexp "[ \t]*"
  2007. (regexp-quote match) "\\>"))))
  2008. ((eq type 'occur-tree)
  2009. (org-check-for-org-mode)
  2010. (org-let lprops '(org-occur match)))
  2011. ((functionp type)
  2012. (org-let lprops '(funcall type match)))
  2013. ((fboundp type)
  2014. (org-let lprops '(funcall type match)))
  2015. (t (error "Invalid custom agenda command type %s" type))))
  2016. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2017. ((equal keys "C")
  2018. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2019. (customize-variable 'org-agenda-custom-commands))
  2020. ((equal keys "a") (call-interactively 'org-agenda-list))
  2021. ((equal keys "s") (call-interactively 'org-search-view))
  2022. ((equal keys "t") (call-interactively 'org-todo-list))
  2023. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2024. ((equal keys "m") (call-interactively 'org-tags-view))
  2025. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2026. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2027. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2028. (org-add-hook
  2029. 'post-command-hook
  2030. (lambda ()
  2031. (unless (current-message)
  2032. (let* ((m (org-agenda-get-any-marker))
  2033. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2034. (when note
  2035. (message (concat
  2036. "FLAGGING-NOTE ([?] for more info): "
  2037. (org-add-props
  2038. (replace-regexp-in-string
  2039. "\\\\n" "//"
  2040. (copy-sequence note))
  2041. nil 'face 'org-warning)))))))
  2042. t t))
  2043. ((equal keys "L")
  2044. (unless (org-mode-p)
  2045. (error "This is not an Org-mode file"))
  2046. (unless restriction
  2047. (put 'org-agenda-files 'org-restrict (list bfn))
  2048. (org-call-with-arg 'org-timeline arg)))
  2049. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2050. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2051. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2052. (t (error "Invalid agenda key"))))))
  2053. (defun org-agenda-append-agenda ()
  2054. "Append another agenda view to the current one.
  2055. This function allows interactive building of block agendas.
  2056. Agenda views are separated by `org-agenda-block-separator'."
  2057. (interactive)
  2058. (unless (string= (buffer-name) org-agenda-buffer-name)
  2059. (error "Can only append from within agenda buffer"))
  2060. (let ((org-agenda-multi t))
  2061. (org-agenda)
  2062. (widen)))
  2063. (defun org-agenda-normalize-custom-commands (cmds)
  2064. (delq nil
  2065. (mapcar
  2066. (lambda (x)
  2067. (cond ((stringp (cdr x)) nil)
  2068. ((stringp (nth 1 x)) x)
  2069. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2070. (t (cons (car x) (cons "" (cdr x))))))
  2071. cmds)))
  2072. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2073. "The user interface for selecting an agenda command."
  2074. (catch 'exit
  2075. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2076. (restrict-ok (and bfn (org-mode-p)))
  2077. (region-p (org-region-active-p))
  2078. (custom org-agenda-custom-commands)
  2079. (selstring "")
  2080. restriction second-time
  2081. c entry key type match prefixes rmheader header-end custom1 desc
  2082. line lines left right n n1)
  2083. (save-window-excursion
  2084. (delete-other-windows)
  2085. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2086. (erase-buffer)
  2087. (insert (eval-when-compile
  2088. (let ((header
  2089. "
  2090. Press key for an agenda command: < Buffer, subtree/region restriction
  2091. -------------------------------- > Remove restriction
  2092. a Agenda for current week or day e Export agenda views
  2093. t List of all TODO entries T Entries with special TODO kwd
  2094. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2095. L Timeline for current buffer # List stuck projects (!=configure)
  2096. s Search for keywords C Configure custom agenda commands
  2097. / Multi-occur ? Find :FLAGGED: entries
  2098. ")
  2099. (start 0))
  2100. (while (string-match
  2101. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2102. header start)
  2103. (setq start (match-end 0))
  2104. (add-text-properties (match-beginning 2) (match-end 2)
  2105. '(face bold) header))
  2106. header)))
  2107. (setq header-end (move-marker (make-marker) (point)))
  2108. (while t
  2109. (setq custom1 custom)
  2110. (when (eq rmheader t)
  2111. (org-goto-line 1)
  2112. (re-search-forward ":" nil t)
  2113. (delete-region (match-end 0) (point-at-eol))
  2114. (forward-char 1)
  2115. (looking-at "-+")
  2116. (delete-region (match-end 0) (point-at-eol))
  2117. (move-marker header-end (match-end 0)))
  2118. (goto-char header-end)
  2119. (delete-region (point) (point-max))
  2120. ;; Produce all the lines that describe custom commands and prefixes
  2121. (setq lines nil)
  2122. (while (setq entry (pop custom1))
  2123. (setq key (car entry) desc (nth 1 entry)
  2124. type (nth 2 entry)
  2125. match (nth 3 entry))
  2126. (if (> (length key) 1)
  2127. (add-to-list 'prefixes (string-to-char key))
  2128. (setq line
  2129. (format
  2130. "%-4s%-14s"
  2131. (org-add-props (copy-sequence key)
  2132. '(face bold))
  2133. (cond
  2134. ((string-match "\\S-" desc) desc)
  2135. ((eq type 'agenda) "Agenda for current week or day")
  2136. ((eq type 'alltodo) "List of all TODO entries")
  2137. ((eq type 'search) "Word search")
  2138. ((eq type 'stuck) "List of stuck projects")
  2139. ((eq type 'todo) "TODO keyword")
  2140. ((eq type 'tags) "Tags query")
  2141. ((eq type 'tags-todo) "Tags (TODO)")
  2142. ((eq type 'tags-tree) "Tags tree")
  2143. ((eq type 'todo-tree) "TODO kwd tree")
  2144. ((eq type 'occur-tree) "Occur tree")
  2145. ((functionp type) (if (symbolp type)
  2146. (symbol-name type)
  2147. "Lambda expression"))
  2148. (t "???"))))
  2149. (if org-agenda-menu-show-matcher
  2150. (setq line
  2151. (concat line ": "
  2152. (cond
  2153. ((stringp match)
  2154. (setq match (copy-sequence match))
  2155. (org-add-props match nil 'face 'org-warning))
  2156. (match
  2157. (format "set of %d commands" (length match)))
  2158. (t ""))))
  2159. (if (org-string-nw-p match)
  2160. (add-text-properties
  2161. 0 (length line) (list 'help-echo
  2162. (concat "Matcher: "match)) line)))
  2163. (push line lines)))
  2164. (setq lines (nreverse lines))
  2165. (when prefixes
  2166. (mapc (lambda (x)
  2167. (push
  2168. (format "%s %s"
  2169. (org-add-props (char-to-string x)
  2170. nil 'face 'bold)
  2171. (or (cdr (assoc (concat selstring
  2172. (char-to-string x))
  2173. prefix-descriptions))
  2174. "Prefix key"))
  2175. lines))
  2176. prefixes))
  2177. ;; Check if we should display in two columns
  2178. (if org-agenda-menu-two-column
  2179. (progn
  2180. (setq n (length lines)
  2181. n1 (+ (/ n 2) (mod n 2))
  2182. right (nthcdr n1 lines)
  2183. left (copy-sequence lines))
  2184. (setcdr (nthcdr (1- n1) left) nil))
  2185. (setq left lines right nil))
  2186. (while left
  2187. (insert "\n" (pop left))
  2188. (when right
  2189. (if (< (current-column) 40)
  2190. (move-to-column 40 t)
  2191. (insert " "))
  2192. (insert (pop right))))
  2193. ;; Make the window the right size
  2194. (goto-char (point-min))
  2195. (if second-time
  2196. (if (not (pos-visible-in-window-p (point-max)))
  2197. (org-fit-window-to-buffer))
  2198. (setq second-time t)
  2199. (org-fit-window-to-buffer))
  2200. ;; Ask for selection
  2201. (message "Press key for agenda command%s:"
  2202. (if (or restrict-ok org-agenda-overriding-restriction)
  2203. (if org-agenda-overriding-restriction
  2204. " (restriction lock active)"
  2205. (if restriction
  2206. (format " (restricted to %s)" restriction)
  2207. " (unrestricted)"))
  2208. ""))
  2209. (setq c (read-char-exclusive))
  2210. (message "")
  2211. (cond
  2212. ((assoc (char-to-string c) custom)
  2213. (setq selstring (concat selstring (char-to-string c)))
  2214. (throw 'exit (cons selstring restriction)))
  2215. ((memq c prefixes)
  2216. (setq selstring (concat selstring (char-to-string c))
  2217. prefixes nil
  2218. rmheader (or rmheader t)
  2219. custom (delq nil (mapcar
  2220. (lambda (x)
  2221. (if (or (= (length (car x)) 1)
  2222. (/= (string-to-char (car x)) c))
  2223. nil
  2224. (cons (substring (car x) 1) (cdr x))))
  2225. custom))))
  2226. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2227. (message "Restriction is only possible in Org-mode buffers")
  2228. (ding) (sit-for 1))
  2229. ((eq c ?1)
  2230. (org-agenda-remove-restriction-lock 'noupdate)
  2231. (setq restriction 'buffer))
  2232. ((eq c ?0)
  2233. (org-agenda-remove-restriction-lock 'noupdate)
  2234. (setq restriction (if region-p 'region 'subtree)))
  2235. ((eq c ?<)
  2236. (org-agenda-remove-restriction-lock 'noupdate)
  2237. (setq restriction
  2238. (cond
  2239. ((eq restriction 'buffer)
  2240. (if region-p 'region 'subtree))
  2241. ((memq restriction '(subtree region))
  2242. nil)
  2243. (t 'buffer))))
  2244. ((eq c ?>)
  2245. (org-agenda-remove-restriction-lock 'noupdate)
  2246. (setq restriction nil))
  2247. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2248. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2249. ((and (> (length selstring) 0) (eq c ?\d))
  2250. (delete-window)
  2251. (org-agenda-get-restriction-and-command prefix-descriptions))
  2252. ((equal c ?q) (error "Abort"))
  2253. (t (error "Invalid key %c" c))))))))
  2254. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2255. (defvar org-agenda-last-arguments nil
  2256. "The arguments of the previous call to `org-agenda'.")
  2257. (defun org-agenda-run-series (name series)
  2258. (org-let (nth 1 series) '(org-prepare-agenda name))
  2259. (let* ((org-agenda-multi t)
  2260. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2261. (org-agenda-overriding-arguments
  2262. (or org-agenda-overriding-arguments
  2263. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2264. (get 'org-agenda-redo-command 'last-args))))
  2265. (cmds (car series))
  2266. (gprops (nth 1 series))
  2267. match ;; The byte compiler incorrectly complains about this. Keep it!
  2268. cmd type lprops)
  2269. (while (setq cmd (pop cmds))
  2270. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2271. (cond
  2272. ((eq type 'agenda)
  2273. (org-let2 gprops lprops
  2274. '(call-interactively 'org-agenda-list)))
  2275. ((eq type 'alltodo)
  2276. (org-let2 gprops lprops
  2277. '(call-interactively 'org-todo-list)))
  2278. ((eq type 'search)
  2279. (org-let2 gprops lprops
  2280. '(org-search-view current-prefix-arg match nil)))
  2281. ((eq type 'stuck)
  2282. (org-let2 gprops lprops
  2283. '(call-interactively 'org-agenda-list-stuck-projects)))
  2284. ((eq type 'tags)
  2285. (org-let2 gprops lprops
  2286. '(org-tags-view current-prefix-arg match)))
  2287. ((eq type 'tags-todo)
  2288. (org-let2 gprops lprops
  2289. '(org-tags-view '(4) match)))
  2290. ((eq type 'todo)
  2291. (org-let2 gprops lprops
  2292. '(org-todo-list match)))
  2293. ((fboundp type)
  2294. (org-let2 gprops lprops
  2295. '(funcall type match)))
  2296. (t (error "Invalid type in command series"))))
  2297. (widen)
  2298. (setq org-agenda-redo-command redo)
  2299. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2300. (goto-char (point-min)))
  2301. (org-fit-agenda-window)
  2302. (org-let (nth 1 series) '(org-finalize-agenda)))
  2303. ;;;###autoload
  2304. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2305. "Run an agenda command in batch mode and send the result to STDOUT.
  2306. If CMD-KEY is a string of length 1, it is used as a key in
  2307. `org-agenda-custom-commands' and triggers this command. If it is a
  2308. longer string it is used as a tags/todo match string.
  2309. Parameters are alternating variable names and values that will be bound
  2310. before running the agenda command."
  2311. (let (pars)
  2312. (while parameters
  2313. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2314. (if (> (length cmd-key) 2)
  2315. (eval (list 'let (nreverse pars)
  2316. (list 'org-tags-view nil cmd-key)))
  2317. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2318. (set-buffer org-agenda-buffer-name)
  2319. (princ (org-encode-for-stdout (buffer-string)))))
  2320. ;(defun org-encode-for-stdout (string)
  2321. ; (if (fboundp 'encode-coding-string)
  2322. ; (encode-coding-string string buffer-file-coding-system)
  2323. ; string))
  2324. (defun org-encode-for-stdout (string)
  2325. string)
  2326. (defvar org-agenda-info nil)
  2327. ;;;###autoload
  2328. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2329. "Run an agenda command in batch mode and send the result to STDOUT.
  2330. If CMD-KEY is a string of length 1, it is used as a key in
  2331. `org-agenda-custom-commands' and triggers this command. If it is a
  2332. longer string it is used as a tags/todo match string.
  2333. Parameters are alternating variable names and values that will be bound
  2334. before running the agenda command.
  2335. The output gives a line for each selected agenda item. Each
  2336. item is a list of comma-separated values, like this:
  2337. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2338. category The category of the item
  2339. head The headline, without TODO kwd, TAGS and PRIORITY
  2340. type The type of the agenda entry, can be
  2341. todo selected in TODO match
  2342. tagsmatch selected in tags match
  2343. diary imported from diary
  2344. deadline a deadline on given date
  2345. scheduled scheduled on given date
  2346. timestamp entry has timestamp on given date
  2347. closed entry was closed on given date
  2348. upcoming-deadline warning about deadline
  2349. past-scheduled forwarded scheduled item
  2350. block entry has date block including g. date
  2351. todo The todo keyword, if any
  2352. tags All tags including inherited ones, separated by colons
  2353. date The relevant date, like 2007-2-14
  2354. time The time, like 15:00-16:50
  2355. extra Sting with extra planning info
  2356. priority-l The priority letter if any was given
  2357. priority-n The computed numerical priority
  2358. agenda-day The day in the agenda where this is listed"
  2359. (let (pars)
  2360. (while parameters
  2361. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2362. (push (list 'org-agenda-remove-tags t) pars)
  2363. (if (> (length cmd-key) 2)
  2364. (eval (list 'let (nreverse pars)
  2365. (list 'org-tags-view nil cmd-key)))
  2366. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2367. (set-buffer org-agenda-buffer-name)
  2368. (let* ((lines (org-split-string (buffer-string) "\n"))
  2369. line)
  2370. (while (setq line (pop lines))
  2371. (catch 'next
  2372. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2373. (setq org-agenda-info
  2374. (org-fix-agenda-info (text-properties-at 0 line)))
  2375. (princ
  2376. (org-encode-for-stdout
  2377. (mapconcat 'org-agenda-export-csv-mapper
  2378. '(org-category txt type todo tags date time extra
  2379. priority-letter priority agenda-day)
  2380. ",")))
  2381. (princ "\n"))))))
  2382. (defun org-fix-agenda-info (props)
  2383. "Make sure all properties on an agenda item have a canonical form.
  2384. This ensures the export commands can easily use it."
  2385. (let (tmp re)
  2386. (when (setq tmp (plist-get props 'tags))
  2387. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2388. (when (setq tmp (plist-get props 'date))
  2389. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2390. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2391. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2392. (setq tmp (calendar-date-string tmp)))
  2393. (setq props (plist-put props 'date tmp)))
  2394. (when (setq tmp (plist-get props 'day))
  2395. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2396. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2397. (setq tmp (calendar-date-string tmp)))
  2398. (setq props (plist-put props 'day tmp))
  2399. (setq props (plist-put props 'agenda-day tmp)))
  2400. (when (setq tmp (plist-get props 'txt))
  2401. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2402. (plist-put props 'priority-letter (match-string 1 tmp))
  2403. (setq tmp (replace-match "" t t tmp)))
  2404. (when (and (setq re (plist-get props 'org-todo-regexp))
  2405. (setq re (concat "\\`\\.*" re " ?"))
  2406. (string-match re tmp))
  2407. (plist-put props 'todo (match-string 1 tmp))
  2408. (setq tmp (replace-match "" t t tmp)))
  2409. (plist-put props 'txt tmp)))
  2410. props)
  2411. (defun org-agenda-export-csv-mapper (prop)
  2412. (let ((res (plist-get org-agenda-info prop)))
  2413. (setq res
  2414. (cond
  2415. ((not res) "")
  2416. ((stringp res) res)
  2417. (t (prin1-to-string res))))
  2418. (while (string-match "," res)
  2419. (setq res (replace-match ";" t t res)))
  2420. (org-trim res)))
  2421. ;;;###autoload
  2422. (defun org-store-agenda-views (&rest parameters)
  2423. (interactive)
  2424. (eval (list 'org-batch-store-agenda-views)))
  2425. ;; FIXME, why is this a macro?????
  2426. ;;;###autoload
  2427. (defmacro org-batch-store-agenda-views (&rest parameters)
  2428. "Run all custom agenda commands that have a file argument."
  2429. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2430. (pop-up-frames nil)
  2431. (dir default-directory)
  2432. pars cmd thiscmdkey files opts cmd-or-set)
  2433. (while parameters
  2434. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2435. (setq pars (reverse pars))
  2436. (save-window-excursion
  2437. (while cmds
  2438. (setq cmd (pop cmds)
  2439. thiscmdkey (car cmd)
  2440. cmd-or-set (nth 2 cmd)
  2441. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2442. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2443. (if (stringp files) (setq files (list files)))
  2444. (when files
  2445. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2446. (list 'org-agenda nil thiscmdkey)))
  2447. (set-buffer org-agenda-buffer-name)
  2448. (while files
  2449. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2450. (list 'org-write-agenda
  2451. (expand-file-name (pop files) dir) nil t))))
  2452. (and (get-buffer org-agenda-buffer-name)
  2453. (kill-buffer org-agenda-buffer-name)))))))
  2454. (defun org-agenda-mark-header-line (pos)
  2455. "Mark the line at POS as an agenda structure header."
  2456. (save-excursion
  2457. (goto-char pos)
  2458. (put-text-property (point-at-bol) (point-at-eol)
  2459. 'org-agenda-structural-header t)
  2460. (when org-agenda-title-append
  2461. (put-text-property (point-at-bol) (point-at-eol)
  2462. 'org-agenda-title-append org-agenda-title-append))))
  2463. (defvar org-mobile-creating-agendas)
  2464. (defun org-write-agenda (file &optional open nosettings)
  2465. "Write the current buffer (an agenda view) as a file.
  2466. Depending on the extension of the file name, plain text (.txt),
  2467. HTML (.html or .htm) or Postscript (.ps) is produced.
  2468. If the extension is .ics, run icalendar export over all files used
  2469. to construct the agenda and limit the export to entries listed in the
  2470. agenda now.
  2471. With prefix argument OPEN, open the new file immediately.
  2472. If NOSETTINGS is given, do not scope the settings of
  2473. `org-agenda-exporter-settings' into the export commands. This is used when
  2474. the settings have already been scoped and we do not wish to overrule other,
  2475. higher priority settings."
  2476. (interactive "FWrite agenda to file: \nP")
  2477. (if (not (file-writable-p file))
  2478. (error "Cannot write agenda to file %s" file))
  2479. (org-let (if nosettings nil org-agenda-exporter-settings)
  2480. '(save-excursion
  2481. (save-window-excursion
  2482. (org-agenda-mark-filtered-text)
  2483. (let ((bs (copy-sequence (buffer-string))) beg)
  2484. (org-agenda-unmark-filtered-text)
  2485. (with-temp-buffer
  2486. (rename-buffer "Agenda View" t)
  2487. (set-buffer-modified-p nil)
  2488. (insert bs)
  2489. (org-agenda-remove-marked-text 'org-filtered)
  2490. (while (setq beg (text-property-any (point-min) (point-max)
  2491. 'org-filtered t))
  2492. (delete-region
  2493. beg (or (next-single-property-change beg 'org-filtered)
  2494. (point-max))))
  2495. (run-hooks 'org-agenda-before-write-hook)
  2496. (cond
  2497. ((org-bound-and-true-p org-mobile-creating-agendas)
  2498. (org-mobile-write-agenda-for-mobile file))
  2499. ((string-match "\\.html?\\'" file)
  2500. (require 'htmlize)
  2501. (set-buffer (htmlize-buffer (current-buffer)))
  2502. (when (and org-agenda-export-html-style
  2503. (string-match "<style>" org-agenda-export-html-style))
  2504. ;; replace <style> section with org-agenda-export-html-style
  2505. (goto-char (point-min))
  2506. (kill-region (- (search-forward "<style") 6)
  2507. (search-forward "</style>"))
  2508. (insert org-agenda-export-html-style))
  2509. (write-file file)
  2510. (kill-buffer (current-buffer))
  2511. (message "HTML written to %s" file))
  2512. ((string-match "\\.ps\\'" file)
  2513. (require 'ps-print)
  2514. (ps-print-buffer-with-faces file)
  2515. (message "Postscript written to %s" file))
  2516. ((string-match "\\.pdf\\'" file)
  2517. (require 'ps-print)
  2518. (ps-print-buffer-with-faces
  2519. (concat (file-name-sans-extension file) ".ps"))
  2520. (call-process "ps2pdf" nil nil nil
  2521. (expand-file-name
  2522. (concat (file-name-sans-extension file) ".ps"))
  2523. (expand-file-name file))
  2524. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2525. (message "PDF written to %s" file))
  2526. ((string-match "\\.ics\\'" file)
  2527. (require 'org-icalendar)
  2528. (let ((org-agenda-marker-table
  2529. (org-create-marker-find-array
  2530. (org-agenda-collect-markers)))
  2531. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2532. (org-combined-agenda-icalendar-file file))
  2533. (apply 'org-export-icalendar 'combine
  2534. (org-agenda-files nil 'ifmode))))
  2535. (t
  2536. (let ((bs (buffer-string)))
  2537. (find-file file)
  2538. (erase-buffer)
  2539. (insert bs)
  2540. (save-buffer 0)
  2541. (kill-buffer (current-buffer))
  2542. (message "Plain text written to %s" file))))))))
  2543. (set-buffer org-agenda-buffer-name))
  2544. (when open (org-open-file file)))
  2545. (defvar org-agenda-filter-overlays nil)
  2546. (defun org-agenda-mark-filtered-text ()
  2547. "Mark all text hidden by filtering with a text property."
  2548. (let ((inhibit-read-only t))
  2549. (mapc
  2550. (lambda (o)
  2551. (when (equal (overlay-buffer o) (current-buffer))
  2552. (put-text-property
  2553. (overlay-start o) (overlay-end o)
  2554. 'org-filtered t)))
  2555. org-agenda-filter-overlays)))
  2556. (defun org-agenda-unmark-filtered-text ()
  2557. "Remove the filtering text property."
  2558. (let ((inhibit-read-only t))
  2559. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2560. (defun org-agenda-remove-marked-text (property &optional value)
  2561. "Delete all text marked with VALUE of PROPERTY.
  2562. VALUE defaults to t."
  2563. (let (beg)
  2564. (setq value (or value t))
  2565. (while (setq beg (text-property-any (point-min) (point-max)
  2566. property value))
  2567. (delete-region
  2568. beg (or (next-single-property-change beg 'org-filtered)
  2569. (point-max))))))
  2570. (defun org-agenda-add-entry-text ()
  2571. "Add entry text to agenda lines.
  2572. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2573. entry text following headings shown in the agenda.
  2574. Drawers will be excluded, also the line with scheduling/deadline info."
  2575. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2576. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2577. (let (m txt)
  2578. (goto-char (point-min))
  2579. (while (not (eobp))
  2580. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2581. (beginning-of-line 2)
  2582. (setq txt (org-agenda-get-some-entry-text
  2583. m org-agenda-add-entry-text-maxlines " > "))
  2584. (end-of-line 1)
  2585. (if (string-match "\\S-" txt)
  2586. (insert "\n" txt)
  2587. (or (eobp) (forward-char 1))))))))
  2588. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2589. &rest keep)
  2590. "Extract entry text from MARKER, at most N-LINES lines.
  2591. This will ignore drawers etc, just get the text.
  2592. If INDENT is given, prefix every line with this string. If KEEP is
  2593. given, it is a list of symbols, defining stuff that should not be
  2594. removed from the entry content. Currently only `planning' is allowed here."
  2595. (let (txt drawer-re kwd-time-re ind)
  2596. (save-excursion
  2597. (with-current-buffer (marker-buffer marker)
  2598. (if (not (org-mode-p))
  2599. (setq txt "")
  2600. (save-excursion
  2601. (save-restriction
  2602. (widen)
  2603. (goto-char marker)
  2604. (end-of-line 1)
  2605. (setq txt (buffer-substring
  2606. (min (1+ (point)) (point-max))
  2607. (progn (outline-next-heading) (point)))
  2608. drawer-re org-drawer-regexp
  2609. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2610. ".*\n?"))
  2611. (with-temp-buffer
  2612. (insert txt)
  2613. (when org-agenda-add-entry-text-descriptive-links
  2614. (goto-char (point-min))
  2615. (while (org-activate-bracket-links (point-max))
  2616. (add-text-properties (match-beginning 0) (match-end 0)
  2617. '(face org-link))))
  2618. (goto-char (point-min))
  2619. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2620. (set-text-properties (match-beginning 0) (match-end 0)
  2621. nil))
  2622. (goto-char (point-min))
  2623. (while (re-search-forward drawer-re nil t)
  2624. (delete-region
  2625. (match-beginning 0)
  2626. (progn (re-search-forward
  2627. "^[ \t]*:END:.*\n?" nil 'move)
  2628. (point))))
  2629. (unless (member 'planning keep)
  2630. (goto-char (point-min))
  2631. (while (re-search-forward kwd-time-re nil t)
  2632. (replace-match "")))
  2633. (goto-char (point-min))
  2634. (when org-agenda-entry-text-exclude-regexps
  2635. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2636. (while (setq re (pop re-list))
  2637. (goto-char (point-min))
  2638. (while (re-search-forward re nil t)
  2639. (replace-match "")))))
  2640. (goto-char (point-max))
  2641. (skip-chars-backward " \t\n")
  2642. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2643. ;; find and remove min common indentation
  2644. (goto-char (point-min))
  2645. (untabify (point-min) (point-max))
  2646. (setq ind (org-get-indentation))
  2647. (while (not (eobp))
  2648. (unless (looking-at "[ \t]*$")
  2649. (setq ind (min ind (org-get-indentation))))
  2650. (beginning-of-line 2))
  2651. (goto-char (point-min))
  2652. (while (not (eobp))
  2653. (unless (looking-at "[ \t]*$")
  2654. (move-to-column ind)
  2655. (delete-region (point-at-bol) (point)))
  2656. (beginning-of-line 2))
  2657. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2658. (goto-char (point-min))
  2659. (when indent
  2660. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2661. (replace-match indent t t)))
  2662. (goto-char (point-min))
  2663. (while (looking-at "[ \t]*\n") (replace-match ""))
  2664. (goto-char (point-max))
  2665. (when (> (org-current-line)
  2666. n-lines)
  2667. (org-goto-line (1+ n-lines))
  2668. (backward-char 1))
  2669. (setq txt (buffer-substring (point-min) (point)))))))))
  2670. txt))
  2671. (defun org-agenda-collect-markers ()
  2672. "Collect the markers pointing to entries in the agenda buffer."
  2673. (let (m markers)
  2674. (save-excursion
  2675. (goto-char (point-min))
  2676. (while (not (eobp))
  2677. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2678. (org-get-at-bol 'org-marker)))
  2679. (push m markers))
  2680. (beginning-of-line 2)))
  2681. (nreverse markers)))
  2682. (defun org-create-marker-find-array (marker-list)
  2683. "Create a alist of files names with all marker positions in that file."
  2684. (let (f tbl m a p)
  2685. (while (setq m (pop marker-list))
  2686. (setq p (marker-position m)
  2687. f (buffer-file-name (or (buffer-base-buffer
  2688. (marker-buffer m))
  2689. (marker-buffer m))))
  2690. (if (setq a (assoc f tbl))
  2691. (push (marker-position m) (cdr a))
  2692. (push (list f p) tbl)))
  2693. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2694. tbl)))
  2695. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2696. (defun org-check-agenda-marker-table ()
  2697. "Check of the current entry is on the marker list."
  2698. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2699. a)
  2700. (and (setq a (assoc file org-agenda-marker-table))
  2701. (save-match-data
  2702. (save-excursion
  2703. (org-back-to-heading t)
  2704. (member (point) (cdr a)))))))
  2705. (defun org-check-for-org-mode ()
  2706. "Make sure current buffer is in org-mode. Error if not."
  2707. (or (org-mode-p)
  2708. (error "Cannot execute org-mode agenda command on buffer in %s"
  2709. major-mode)))
  2710. (defun org-fit-agenda-window ()
  2711. "Fit the window to the buffer size."
  2712. (and (memq org-agenda-window-setup '(reorganize-frame))
  2713. (fboundp 'fit-window-to-buffer)
  2714. (org-fit-window-to-buffer
  2715. nil
  2716. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2717. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2718. ;;; Agenda prepare and finalize
  2719. (defvar org-agenda-multi nil) ; dynamically scoped
  2720. (defvar org-agenda-buffer-name "*Org Agenda*")
  2721. (defvar org-pre-agenda-window-conf nil)
  2722. (defvar org-agenda-columns-active nil)
  2723. (defvar org-agenda-name nil)
  2724. (defvar org-agenda-filter nil)
  2725. (defvar org-agenda-filter-while-redo nil)
  2726. (defvar org-agenda-filter-preset nil
  2727. "A preset of the tags filter used for secondary agenda filtering.
  2728. This must be a list of strings, each string must be a single tag preceded
  2729. by \"+\" or \"-\".
  2730. This variable should not be set directly, but agenda custom commands can
  2731. bind it in the options section. The preset filter is a global property of
  2732. the entire agenda view. In a block agenda, it will not work reliably to
  2733. define a filter for one of the individual blocks. You need to set it in
  2734. the global options and expect it to be applied to the entire view.")
  2735. (defun org-prepare-agenda (&optional name)
  2736. (setq org-todo-keywords-for-agenda nil)
  2737. (setq org-done-keywords-for-agenda nil)
  2738. (setq org-drawers-for-agenda nil)
  2739. (unless org-agenda-persistent-filter
  2740. (setq org-agenda-filter nil))
  2741. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2742. (if org-agenda-multi
  2743. (progn
  2744. (setq buffer-read-only nil)
  2745. (goto-char (point-max))
  2746. (unless (or (bobp) org-agenda-compact-blocks)
  2747. (insert "\n"
  2748. (if (stringp org-agenda-block-separator)
  2749. org-agenda-block-separator
  2750. (make-string (window-width) org-agenda-block-separator))
  2751. "\n"))
  2752. (narrow-to-region (point) (point-max)))
  2753. (org-agenda-reset-markers)
  2754. (setq org-agenda-contributing-files nil)
  2755. (setq org-agenda-columns-active nil)
  2756. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2757. (setq org-todo-keywords-for-agenda
  2758. (org-uniquify org-todo-keywords-for-agenda))
  2759. (setq org-done-keywords-for-agenda
  2760. (org-uniquify org-done-keywords-for-agenda))
  2761. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2762. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2763. (awin (get-buffer-window abuf)))
  2764. (cond
  2765. ((equal (current-buffer) abuf) nil)
  2766. (awin (select-window awin))
  2767. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2768. ((equal org-agenda-window-setup 'current-window)
  2769. (switch-to-buffer abuf))
  2770. ((equal org-agenda-window-setup 'other-window)
  2771. (org-switch-to-buffer-other-window abuf))
  2772. ((equal org-agenda-window-setup 'other-frame)
  2773. (switch-to-buffer-other-frame abuf))
  2774. ((equal org-agenda-window-setup 'reorganize-frame)
  2775. (delete-other-windows)
  2776. (org-switch-to-buffer-other-window abuf)))
  2777. ;; additional test in case agenda is invoked from within agenda
  2778. ;; buffer via elisp link
  2779. (unless (equal (current-buffer) abuf)
  2780. (switch-to-buffer abuf)))
  2781. (setq buffer-read-only nil)
  2782. (let ((inhibit-read-only t)) (erase-buffer))
  2783. (org-agenda-mode)
  2784. (and name (not org-agenda-name)
  2785. (org-set-local 'org-agenda-name name)))
  2786. (setq buffer-read-only nil))
  2787. (defun org-finalize-agenda ()
  2788. "Finishing touch for the agenda buffer, called just before displaying it."
  2789. (unless org-agenda-multi
  2790. (save-excursion
  2791. (let ((inhibit-read-only t))
  2792. (goto-char (point-min))
  2793. (while (org-activate-bracket-links (point-max))
  2794. (add-text-properties (match-beginning 0) (match-end 0)
  2795. '(face org-link)))
  2796. (org-agenda-align-tags)
  2797. (unless org-agenda-with-colors
  2798. (remove-text-properties (point-min) (point-max) '(face nil))))
  2799. (if (and (boundp 'org-agenda-overriding-columns-format)
  2800. org-agenda-overriding-columns-format)
  2801. (org-set-local 'org-agenda-overriding-columns-format
  2802. org-agenda-overriding-columns-format))
  2803. (if (and (boundp 'org-agenda-view-columns-initially)
  2804. org-agenda-view-columns-initially)
  2805. (org-agenda-columns))
  2806. (when org-agenda-fontify-priorities
  2807. (org-agenda-fontify-priorities))
  2808. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2809. (org-agenda-dim-blocked-tasks))
  2810. (org-agenda-mark-clocking-task)
  2811. (when org-agenda-entry-text-mode
  2812. (org-agenda-entry-text-hide)
  2813. (org-agenda-entry-text-show))
  2814. (if (functionp 'org-habit-insert-consistency-graphs)
  2815. (org-habit-insert-consistency-graphs))
  2816. (run-hooks 'org-finalize-agenda-hook)
  2817. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2818. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2819. (org-agenda-filter-apply org-agenda-filter))
  2820. )))
  2821. (defun org-agenda-mark-clocking-task ()
  2822. "Mark the current clock entry in the agenda if it is present."
  2823. (mapc (lambda (o)
  2824. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2825. (delete-overlay o)))
  2826. (overlays-in (point-min) (point-max)))
  2827. (when (marker-buffer org-clock-hd-marker)
  2828. (save-excursion
  2829. (goto-char (point-min))
  2830. (let (s ov)
  2831. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2832. (goto-char s)
  2833. (when (equal (org-get-at-bol 'org-hd-marker)
  2834. org-clock-hd-marker)
  2835. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2836. (overlay-put ov 'type 'org-agenda-clocking)
  2837. (overlay-put ov 'face 'org-agenda-clocking)
  2838. (overlay-put ov 'help-echo
  2839. "The clock is running in this item")))))))
  2840. (defun org-agenda-fontify-priorities ()
  2841. "Make highest priority lines bold, and lowest italic."
  2842. (interactive)
  2843. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2844. (delete-overlay o)))
  2845. (overlays-in (point-min) (point-max)))
  2846. (save-excursion
  2847. (let ((inhibit-read-only t)
  2848. b e p ov h l)
  2849. (goto-char (point-min))
  2850. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2851. (setq h (or (get-char-property (point) 'org-highest-priority)
  2852. org-highest-priority)
  2853. l (or (get-char-property (point) 'org-lowest-priority)
  2854. org-lowest-priority)
  2855. p (string-to-char (match-string 1))
  2856. b (match-beginning 0)
  2857. e (if (eq org-agenda-fontify-priorities 'cookies)
  2858. (match-end 0)
  2859. (point-at-eol))
  2860. ov (make-overlay b e))
  2861. (overlay-put
  2862. ov 'face
  2863. (cond ((org-face-from-face-or-color
  2864. 'priority nil
  2865. (cdr (assoc p org-priority-faces))))
  2866. ((and (listp org-agenda-fontify-priorities)
  2867. (org-face-from-face-or-color
  2868. 'priority nil
  2869. (cdr (assoc p org-agenda-fontify-priorities)))))
  2870. ((equal p l) 'italic)
  2871. ((equal p h) 'bold)))
  2872. (overlay-put ov 'org-type 'org-priority)))))
  2873. (defun org-agenda-dim-blocked-tasks ()
  2874. "Dim currently blocked TODO's in the agenda display."
  2875. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2876. (delete-overlay o)))
  2877. (overlays-in (point-min) (point-max)))
  2878. (save-excursion
  2879. (let ((inhibit-read-only t)
  2880. (org-depend-tag-blocked nil)
  2881. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2882. org-blocked-by-checkboxes
  2883. invis1 b e p ov h l)
  2884. (goto-char (point-min))
  2885. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2886. (and pos (goto-char (1+ pos))))
  2887. (setq org-blocked-by-checkboxes nil invis1 invis)
  2888. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2889. (when (and marker
  2890. (not (with-current-buffer (marker-buffer marker)
  2891. (save-excursion
  2892. (goto-char marker)
  2893. (if (org-entry-get nil "NOBLOCKING")
  2894. t ;; Never block this entry
  2895. (run-hook-with-args-until-failure
  2896. 'org-blocker-hook
  2897. (list :type 'todo-state-change
  2898. :position marker
  2899. :from 'todo
  2900. :to 'done)))))))
  2901. (if org-blocked-by-checkboxes (setq invis1 nil))
  2902. (setq b (if invis1
  2903. (max (point-min) (1- (point-at-bol)))
  2904. (point-at-bol))
  2905. e (point-at-eol)
  2906. ov (make-overlay b e))
  2907. (if invis1
  2908. (overlay-put ov 'invisible t)
  2909. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2910. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2911. (defvar org-agenda-skip-function nil
  2912. "Function to be called at each match during agenda construction.
  2913. If this function returns nil, the current match should not be skipped.
  2914. Otherwise, the function must return a position from where the search
  2915. should be continued.
  2916. This may also be a Lisp form, it will be evaluated.
  2917. Never set this variable using `setq' or so, because then it will apply
  2918. to all future agenda commands. If you do want a global skipping condition,
  2919. use the option `org-agenda-skip-function-global' instead.
  2920. The correct usage for `org-agenda-skip-function' is to bind it with
  2921. `let' to scope it dynamically into the agenda-constructing command.
  2922. A good way to set it is through options in `org-agenda-custom-commands'.")
  2923. (defun org-agenda-skip ()
  2924. "Throw to `:skip' in places that should be skipped.
  2925. Also moves point to the end of the skipped region, so that search can
  2926. continue from there."
  2927. (let ((p (point-at-bol)) to)
  2928. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2929. (get-text-property p :org-archived)
  2930. (org-end-of-subtree t)
  2931. (throw :skip t))
  2932. (and org-agenda-skip-comment-trees
  2933. (get-text-property p :org-comment)
  2934. (org-end-of-subtree t)
  2935. (throw :skip t))
  2936. (if (equal (char-after p) ?#) (throw :skip t))
  2937. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2938. (org-agenda-skip-eval org-agenda-skip-function)))
  2939. (goto-char to)
  2940. (throw :skip t))))
  2941. (defun org-agenda-skip-eval (form)
  2942. "If FORM is a function or a list, call (or eval) is and return result.
  2943. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2944. and match data are returned to the previous state no matter what these
  2945. functions do."
  2946. (let (fp)
  2947. (and form
  2948. (or (setq fp (functionp form))
  2949. (consp form))
  2950. (save-excursion
  2951. (save-match-data
  2952. (if fp
  2953. (funcall form)
  2954. (eval form)))))))
  2955. (defvar org-agenda-markers nil
  2956. "List of all currently active markers created by `org-agenda'.")
  2957. (defvar org-agenda-last-marker-time (org-float-time)
  2958. "Creation time of the last agenda marker.")
  2959. (defun org-agenda-new-marker (&optional pos)
  2960. "Return a new agenda marker.
  2961. Org-mode keeps a list of these markers and resets them when they are
  2962. no longer in use."
  2963. (let ((m (copy-marker (or pos (point)))))
  2964. (setq org-agenda-last-marker-time (org-float-time))
  2965. (push m org-agenda-markers)
  2966. m))
  2967. (defun org-agenda-reset-markers ()
  2968. "Reset markers created by `org-agenda'."
  2969. (while org-agenda-markers
  2970. (move-marker (pop org-agenda-markers) nil)))
  2971. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2972. "Save relative positions of markers in region."
  2973. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2974. org-agenda-markers))
  2975. ;;; Entry text mode
  2976. (defun org-agenda-entry-text-show-here ()
  2977. "Add some text from the entry as context to the current line."
  2978. (let (m txt o)
  2979. (setq m (org-get-at-bol 'org-hd-marker))
  2980. (unless (marker-buffer m)
  2981. (error "No marker points to an entry here"))
  2982. (setq txt (concat "\n" (org-no-properties
  2983. (org-agenda-get-some-entry-text
  2984. m org-agenda-entry-text-maxlines " > "))))
  2985. (when (string-match "\\S-" txt)
  2986. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2987. (overlay-put o 'evaporate t)
  2988. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2989. (overlay-put o 'after-string txt))))
  2990. (defun org-agenda-entry-text-show ()
  2991. "Add entry context for all agenda lines."
  2992. (interactive)
  2993. (save-excursion
  2994. (goto-char (point-max))
  2995. (beginning-of-line 1)
  2996. (while (not (bobp))
  2997. (when (org-get-at-bol 'org-hd-marker)
  2998. (org-agenda-entry-text-show-here))
  2999. (beginning-of-line 0))))
  3000. (defun org-agenda-entry-text-hide ()
  3001. "Remove any shown entry context."
  3002. (delq nil
  3003. (mapcar (lambda (o)
  3004. (if (eq (overlay-get o 'org-overlay-type)
  3005. 'agenda-entry-content)
  3006. (progn (delete-overlay o) t)))
  3007. (overlays-in (point-min) (point-max)))))
  3008. (defun org-agenda-get-day-face (date)
  3009. "Return the face DATE should be displayed with."
  3010. (or (and (functionp org-agenda-day-face-function)
  3011. (funcall org-agenda-day-face-function date))
  3012. (cond ((org-agenda-todayp date)
  3013. 'org-agenda-date-today)
  3014. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3015. 'org-agenda-date-weekend)
  3016. (t 'org-agenda-date))))
  3017. ;;; Agenda timeline
  3018. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3019. (defun org-timeline (&optional include-all)
  3020. "Show a time-sorted view of the entries in the current org file.
  3021. Only entries with a time stamp of today or later will be listed. With
  3022. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3023. under the current date.
  3024. If the buffer contains an active region, only check the region for
  3025. dates."
  3026. (interactive "P")
  3027. (org-compile-prefix-format 'timeline)
  3028. (org-set-sorting-strategy 'timeline)
  3029. (let* ((dopast t)
  3030. (dotodo include-all)
  3031. (doclosed org-agenda-show-log)
  3032. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3033. (current-buffer))))
  3034. (date (calendar-current-date))
  3035. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3036. (end (if (org-region-active-p) (region-end) (point-max)))
  3037. (day-numbers (org-get-all-dates beg end 'no-ranges
  3038. t doclosed ; always include today
  3039. org-timeline-show-empty-dates))
  3040. (org-deadline-warning-days 0)
  3041. (org-agenda-only-exact-dates t)
  3042. (today (org-today))
  3043. (past t)
  3044. args
  3045. s e rtn d emptyp)
  3046. (setq org-agenda-redo-command
  3047. (list 'progn
  3048. (list 'org-switch-to-buffer-other-window (current-buffer))
  3049. (list 'org-timeline (list 'quote include-all))))
  3050. (if (not dopast)
  3051. ;; Remove past dates from the list of dates.
  3052. (setq day-numbers (delq nil (mapcar (lambda(x)
  3053. (if (>= x today) x nil))
  3054. day-numbers))))
  3055. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3056. (if doclosed (push :closed args))
  3057. (push :timestamp args)
  3058. (push :deadline args)
  3059. (push :scheduled args)
  3060. (push :sexp args)
  3061. (if dotodo (push :todo args))
  3062. (insert "Timeline of file " entry "\n")
  3063. (add-text-properties (point-min) (point)
  3064. (list 'face 'org-agenda-structure))
  3065. (org-agenda-mark-header-line (point-min))
  3066. (while (setq d (pop day-numbers))
  3067. (if (and (listp d) (eq (car d) :omitted))
  3068. (progn
  3069. (setq s (point))
  3070. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3071. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3072. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3073. (if (and (>= d today)
  3074. dopast
  3075. past)
  3076. (progn
  3077. (setq past nil)
  3078. (insert (make-string 79 ?-) "\n")))
  3079. (setq date (calendar-gregorian-from-absolute d))
  3080. (setq s (point))
  3081. (setq rtn (and (not emptyp)
  3082. (apply 'org-agenda-get-day-entries entry
  3083. date args)))
  3084. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3085. (progn
  3086. (insert
  3087. (if (stringp org-agenda-format-date)
  3088. (format-time-string org-agenda-format-date
  3089. (org-time-from-absolute date))
  3090. (funcall org-agenda-format-date date))
  3091. "\n")
  3092. (put-text-property s (1- (point)) 'face
  3093. (org-agenda-get-day-face date))
  3094. (put-text-property s (1- (point)) 'org-date-line t)
  3095. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3096. (if (equal d today)
  3097. (put-text-property s (1- (point)) 'org-today t))
  3098. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3099. (put-text-property s (1- (point)) 'day d)))))
  3100. (goto-char (point-min))
  3101. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3102. (point-min)))
  3103. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3104. (org-finalize-agenda)
  3105. (setq buffer-read-only t)))
  3106. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3107. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3108. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3109. not every single day in the range. If FORCE-TODAY is non-nil, make
  3110. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3111. inactive time stamps (those in square brackets) are included.
  3112. When EMPTY is non-nil, also include days without any entries."
  3113. (let ((re (concat
  3114. (if pre-re pre-re "")
  3115. (if inactive org-ts-regexp-both org-ts-regexp)))
  3116. dates dates1 date day day1 day2 ts1 ts2)
  3117. (if force-today
  3118. (setq dates (list (org-today))))
  3119. (save-excursion
  3120. (goto-char beg)
  3121. (while (re-search-forward re end t)
  3122. (setq day (time-to-days (org-time-string-to-time
  3123. (substring (match-string 1) 0 10))))
  3124. (or (memq day dates) (push day dates)))
  3125. (unless no-ranges
  3126. (goto-char beg)
  3127. (while (re-search-forward org-tr-regexp end t)
  3128. (setq ts1 (substring (match-string 1) 0 10)
  3129. ts2 (substring (match-string 2) 0 10)
  3130. day1 (time-to-days (org-time-string-to-time ts1))
  3131. day2 (time-to-days (org-time-string-to-time ts2)))
  3132. (while (< (setq day1 (1+ day1)) day2)
  3133. (or (memq day1 dates) (push day1 dates)))))
  3134. (setq dates (sort dates '<))
  3135. (when empty
  3136. (while (setq day (pop dates))
  3137. (setq day2 (car dates))
  3138. (push day dates1)
  3139. (when (and day2 empty)
  3140. (if (or (eq empty t)
  3141. (and (numberp empty) (<= (- day2 day) empty)))
  3142. (while (< (setq day (1+ day)) day2)
  3143. (push (list day) dates1))
  3144. (push (cons :omitted (- day2 day)) dates1))))
  3145. (setq dates (nreverse dates1)))
  3146. dates)))
  3147. ;;; Agenda Daily/Weekly
  3148. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3149. "Start day for the agenda view.
  3150. Custom commands can set this variable in the options section.")
  3151. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3152. (defvar org-agenda-current-span nil
  3153. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3154. (defvar org-include-all-loc nil) ; local variable
  3155. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3156. "List of types searched for when creating the daily/weekly agenda.
  3157. This variable is a list of symbols that controls the types of
  3158. items that appear in the daily/weekly agenda. Allowed symbols in this
  3159. list are are
  3160. :timestamp List items containing a date stamp or date range matching
  3161. the selected date. This includes sexp entries in
  3162. angular brackets.
  3163. :sexp List entries resulting from plain diary-like sexps.
  3164. :deadline List deadline due on that date. When the date is today,
  3165. also list any deadlines past due, or due within
  3166. `org-deadline-warning-days'. `:deadline' must appear before
  3167. `:scheduled' if the setting of
  3168. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3169. any effect.
  3170. :scheduled List all items which are scheduled for the given date.
  3171. The diary for *today* also contains items which were
  3172. scheduled earlier and are not yet marked DONE.
  3173. By default, all four types are turned on.
  3174. Never set this variable globally using `setq', because then it
  3175. will apply to all future agenda commands. Instead, bind it with
  3176. `let' to scope it dynamically into the the agenda-constructing
  3177. command. A good way to set it is through options in
  3178. `org-agenda-custom-commands'. For a more flexible (though
  3179. somewhat less efficient) way of determining what is included in
  3180. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3181. ;;;###autoload
  3182. (defun org-agenda-list (&optional include-all start-day span)
  3183. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3184. The view will be for the current day or week, but from the overview buffer
  3185. you will be able to go to other days/weeks.
  3186. With a numeric prefix argument in an interactive call, the agenda will
  3187. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3188. the number of days. SPAN defaults to `org-agenda-span'.
  3189. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3190. given in `org-agenda-start-on-weekday'."
  3191. (interactive "P")
  3192. (if (and (integerp include-all) (> include-all 0))
  3193. (setq span include-all include-all nil))
  3194. (setq start-day (or start-day org-agenda-start-day))
  3195. (if org-agenda-overriding-arguments
  3196. (setq include-all (car org-agenda-overriding-arguments)
  3197. start-day (nth 1 org-agenda-overriding-arguments)
  3198. span (nth 2 org-agenda-overriding-arguments)))
  3199. (if (stringp start-day)
  3200. ;; Convert to an absolute day number
  3201. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3202. (setq org-agenda-last-arguments (list include-all start-day span))
  3203. (org-compile-prefix-format 'agenda)
  3204. (org-set-sorting-strategy 'agenda)
  3205. (let* ((span (org-agenda-ndays-to-span
  3206. (or span org-agenda-ndays org-agenda-span)))
  3207. (today (org-today))
  3208. (sd (or start-day today))
  3209. (ndays (org-agenda-span-to-ndays span sd))
  3210. (org-agenda-start-on-weekday
  3211. (if (eq ndays 7)
  3212. org-agenda-start-on-weekday))
  3213. (thefiles (org-agenda-files nil 'ifmode))
  3214. (files thefiles)
  3215. (start (if (or (null org-agenda-start-on-weekday)
  3216. (< ndays 7))
  3217. sd
  3218. (let* ((nt (calendar-day-of-week
  3219. (calendar-gregorian-from-absolute sd)))
  3220. (n1 org-agenda-start-on-weekday)
  3221. (d (- nt n1)))
  3222. (- sd (+ (if (< d 0) 7 0) d)))))
  3223. (day-numbers (list start))
  3224. (day-cnt 0)
  3225. (inhibit-redisplay (not debug-on-error))
  3226. s e rtn rtnall file date d start-pos end-pos todayp
  3227. clocktable-start clocktable-end filter)
  3228. (setq org-agenda-redo-command
  3229. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3230. (dotimes (n (1- ndays))
  3231. (push (1+ (car day-numbers)) day-numbers))
  3232. (setq day-numbers (nreverse day-numbers))
  3233. (setq clocktable-start (car day-numbers)
  3234. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3235. (org-prepare-agenda "Day/Week")
  3236. (org-set-local 'org-starting-day (car day-numbers))
  3237. (org-set-local 'org-include-all-loc include-all)
  3238. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3239. (unless org-agenda-compact-blocks
  3240. (let* ((d1 (car day-numbers))
  3241. (d2 (org-last day-numbers))
  3242. (w1 (org-days-to-iso-week d1))
  3243. (w2 (org-days-to-iso-week d2)))
  3244. (setq s (point))
  3245. (if org-agenda-overriding-header
  3246. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3247. nil 'face 'org-agenda-structure) "\n")
  3248. (insert (org-agenda-span-name span)
  3249. "-agenda"
  3250. (if (< (- d2 d1) 350)
  3251. (if (= w1 w2)
  3252. (format " (W%02d)" w1)
  3253. (format " (W%02d-W%02d)" w1 w2))
  3254. "")
  3255. ":\n")))
  3256. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3257. 'org-date-line t))
  3258. (org-agenda-mark-header-line s))
  3259. (while (setq d (pop day-numbers))
  3260. (setq date (calendar-gregorian-from-absolute d)
  3261. s (point))
  3262. (if (or (setq todayp (= d today))
  3263. (and (not start-pos) (= d sd)))
  3264. (setq start-pos (point))
  3265. (if (and start-pos (not end-pos))
  3266. (setq end-pos (point))))
  3267. (setq files thefiles
  3268. rtnall nil)
  3269. (while (setq file (pop files))
  3270. (catch 'nextfile
  3271. (org-check-agenda-file file)
  3272. (let ((org-agenda-entry-types org-agenda-entry-types))
  3273. (unless org-agenda-include-deadlines
  3274. (setq org-agenda-entry-types
  3275. (delq :deadline org-agenda-entry-types)))
  3276. (cond
  3277. ((memq org-agenda-show-log '(only clockcheck))
  3278. (setq rtn (org-agenda-get-day-entries
  3279. file date :closed)))
  3280. (org-agenda-show-log
  3281. (setq rtn (apply 'org-agenda-get-day-entries
  3282. file date
  3283. (append '(:closed) org-agenda-entry-types))))
  3284. (t
  3285. (setq rtn (apply 'org-agenda-get-day-entries
  3286. file date
  3287. org-agenda-entry-types)))))
  3288. (setq rtnall (append rtnall rtn))))
  3289. (if org-agenda-include-diary
  3290. (let ((org-agenda-search-headline-for-time t))
  3291. (require 'diary-lib)
  3292. (setq rtn (org-get-entries-from-diary date))
  3293. (setq rtnall (append rtnall rtn))))
  3294. (if (or rtnall org-agenda-show-all-dates)
  3295. (progn
  3296. (setq day-cnt (1+ day-cnt))
  3297. (insert
  3298. (if (stringp org-agenda-format-date)
  3299. (format-time-string org-agenda-format-date
  3300. (org-time-from-absolute date))
  3301. (funcall org-agenda-format-date date))
  3302. "\n")
  3303. (put-text-property s (1- (point)) 'face
  3304. (org-agenda-get-day-face date))
  3305. (put-text-property s (1- (point)) 'org-date-line t)
  3306. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3307. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3308. (when todayp
  3309. (put-text-property s (1- (point)) 'org-today t))
  3310. (if rtnall (insert
  3311. (org-finalize-agenda-entries
  3312. (org-agenda-add-time-grid-maybe
  3313. rtnall ndays todayp))
  3314. "\n"))
  3315. (put-text-property s (1- (point)) 'day d)
  3316. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3317. (when (and org-agenda-clockreport-mode clocktable-start)
  3318. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3319. ;; the above line is to ensure the restricted range!
  3320. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3321. tbl)
  3322. (setq p (org-plist-delete p :block))
  3323. (setq p (plist-put p :tstart clocktable-start))
  3324. (setq p (plist-put p :tend clocktable-end))
  3325. (setq p (plist-put p :scope 'agenda))
  3326. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3327. (setq filter (or org-agenda-filter-while-redo
  3328. (get 'org-agenda-filter :preset-filter))))
  3329. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3330. (if (string-match "[<>=]" x)
  3331. ""
  3332. x))
  3333. filter ""))))
  3334. (setq tbl (apply 'org-get-clocktable p))
  3335. (insert tbl)))
  3336. (goto-char (point-min))
  3337. (or org-agenda-multi (org-fit-agenda-window))
  3338. (unless (and (pos-visible-in-window-p (point-min))
  3339. (pos-visible-in-window-p (point-max)))
  3340. (goto-char (1- (point-max)))
  3341. (recenter -1)
  3342. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3343. (progn
  3344. (goto-char (or start-pos 1))
  3345. (recenter 1))))
  3346. (goto-char (or start-pos 1))
  3347. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3348. (if (eq org-agenda-show-log 'clockcheck)
  3349. (org-agenda-show-clocking-issues))
  3350. (org-finalize-agenda)
  3351. (setq buffer-read-only t)
  3352. (message "")))
  3353. (defun org-agenda-ndays-to-span (n)
  3354. "Return a span symbol for a span of N days, or N if none matches."
  3355. (cond ((symbolp n) n)
  3356. ((= n 1) 'day)
  3357. ((= n 7) 'week)
  3358. (t n)))
  3359. (defun org-agenda-span-to-ndays (span start-day)
  3360. "Return ndays from SPAN starting at START-DAY."
  3361. (cond ((numberp span) span)
  3362. ((eq span 'day) 1)
  3363. ((eq span 'week) 7)
  3364. ((eq span 'month)
  3365. (let ((date (calendar-gregorian-from-absolute start-day)))
  3366. (calendar-last-day-of-month (car date) (caddr date))))
  3367. ((eq span 'year)
  3368. (let ((date (calendar-gregorian-from-absolute start-day)))
  3369. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3370. (defun org-agenda-span-name (span)
  3371. "Return a SPAN name."
  3372. (if (null span)
  3373. ""
  3374. (if (symbolp span)
  3375. (capitalize (symbol-name span))
  3376. (format "%d days" span))))
  3377. ;;; Agenda word search
  3378. (defvar org-agenda-search-history nil)
  3379. (defvar org-todo-only nil)
  3380. (defvar org-search-syntax-table nil
  3381. "Special syntax table for org-mode search.
  3382. In this table, we have single quotes not as word constituents, to
  3383. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3384. (defun org-search-syntax-table ()
  3385. (unless org-search-syntax-table
  3386. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3387. (modify-syntax-entry ?' "." org-search-syntax-table)
  3388. (modify-syntax-entry ?` "." org-search-syntax-table))
  3389. org-search-syntax-table)
  3390. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3391. ;;;###autoload
  3392. (defun org-search-view (&optional todo-only string edit-at)
  3393. "Show all entries that contain a phrase or words or regular expressions.
  3394. With optional prefix argument TODO-ONLY, only consider entries that are
  3395. TODO entries. The argument STRING can be used to pass a default search
  3396. string into this function. If EDIT-AT is non-nil, it means that the
  3397. user should get a chance to edit this string, with cursor at position
  3398. EDIT-AT.
  3399. The search string can be viewed either as a phrase that should be found as
  3400. is, or it can be broken into a number of snippets, each of which must match
  3401. in a Boolean way to select an entry. The default depends on the variable
  3402. `org-agenda-search-view-always-boolean'.
  3403. Even if this is turned off (the default) you can always switch to
  3404. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3405. The default is a direct search of the whole phrase, where each space in
  3406. the search string can expand to an arbitrary amount of whitespace,
  3407. including newlines.
  3408. If using a Boolean search, the search string is split on whitespace and
  3409. each snippet is searched separately, with logical AND to select an entry.
  3410. Words prefixed with a minus must *not* occur in the entry. Words without
  3411. a prefix or prefixed with a plus must occur in the entry. Matching is
  3412. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3413. match whole words, not parts of a word) if
  3414. `org-agenda-search-view-force-full-words' is set (default is nil).
  3415. Boolean search snippets enclosed by curly braces are interpreted as
  3416. regular expressions that must or (when preceded with \"-\") must not
  3417. match in the entry. Snippets enclosed into double quotes will be taken
  3418. as a whole, to include whitespace.
  3419. - If the search string starts with an asterisk, search only in headlines.
  3420. - If (possibly after the leading star) the search string starts with an
  3421. exclamation mark, this also means to look at TODO entries only, an effect
  3422. that can also be achieved with a prefix argument.
  3423. - If (possibly after star and exclamation mark) the search string starts
  3424. with a colon, this will mean that the (non-regexp) snippets of the
  3425. Boolean search must match as full words.
  3426. This command searches the agenda files, and in addition the files listed
  3427. in `org-agenda-text-search-extra-files'."
  3428. (interactive "P")
  3429. (org-compile-prefix-format 'search)
  3430. (org-set-sorting-strategy 'search)
  3431. (org-prepare-agenda "SEARCH")
  3432. (let* ((props (list 'face nil
  3433. 'done-face 'org-agenda-done
  3434. 'org-not-done-regexp org-not-done-regexp
  3435. 'org-todo-regexp org-todo-regexp
  3436. 'org-complex-heading-regexp org-complex-heading-regexp
  3437. 'mouse-face 'highlight
  3438. 'help-echo (format "mouse-2 or RET jump to location")))
  3439. (full-words org-agenda-search-view-force-full-words)
  3440. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3441. regexp rtn rtnall files file pos
  3442. marker category tags c neg re boolean
  3443. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3444. (unless (and (not edit-at)
  3445. (stringp string)
  3446. (string-match "\\S-" string))
  3447. (setq string (read-string
  3448. (if org-agenda-search-view-always-boolean
  3449. "[+-]Word/{Regexp} ...: "
  3450. "Phrase, or [+-]Word/{Regexp} ...: ")
  3451. (cond
  3452. ((integerp edit-at) (cons string edit-at))
  3453. (edit-at string))
  3454. 'org-agenda-search-history)))
  3455. (org-set-local 'org-todo-only todo-only)
  3456. (setq org-agenda-redo-command
  3457. (list 'org-search-view (if todo-only t nil) string
  3458. '(if current-prefix-arg 1 nil)))
  3459. (setq org-agenda-query-string string)
  3460. (if (equal (string-to-char string) ?*)
  3461. (setq hdl-only t
  3462. words (substring string 1))
  3463. (setq words string))
  3464. (when (equal (string-to-char words) ?!)
  3465. (setq todo-only t
  3466. words (substring words 1)))
  3467. (when (equal (string-to-char words) ?:)
  3468. (setq full-words t
  3469. words (substring words 1)))
  3470. (if (or org-agenda-search-view-always-boolean
  3471. (member (string-to-char words) '(?- ?+ ?\{)))
  3472. (setq boolean t))
  3473. (setq words (org-split-string words))
  3474. (let (www w)
  3475. (while (setq w (pop words))
  3476. (while (and (string-match "\\\\\\'" w) words)
  3477. (setq w (concat (substring w 0 -1) " " (pop words))))
  3478. (push w www))
  3479. (setq words (nreverse www) www nil)
  3480. (while (setq w (pop words))
  3481. (when (and (string-match "\\`[-+]?{" w)
  3482. (not (string-match "}\\'" w)))
  3483. (while (and words (not (string-match "}\\'" (car words))))
  3484. (setq w (concat w " " (pop words))))
  3485. (setq w (concat w " " (pop words))))
  3486. (push w www))
  3487. (setq words (nreverse www)))
  3488. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3489. (when boolean
  3490. (let (wds w)
  3491. (while (setq w (pop words))
  3492. (if (or (equal (substring w 0 1) "\"")
  3493. (and (> (length w) 1)
  3494. (member (substring w 0 1) '("+" "-"))
  3495. (equal (substring w 1 2) "\"")))
  3496. (while (and words (not (equal (substring w -1) "\"")))
  3497. (setq w (concat w " " (pop words)))))
  3498. (and (string-match "\\`\\([-+]?\\)\"" w)
  3499. (setq w (replace-match "\\1" nil nil w)))
  3500. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3501. (push w wds))
  3502. (setq words (nreverse wds))))
  3503. (if boolean
  3504. (mapc (lambda (w)
  3505. (setq c (string-to-char w))
  3506. (if (equal c ?-)
  3507. (setq neg t w (substring w 1))
  3508. (if (equal c ?+)
  3509. (setq neg nil w (substring w 1))
  3510. (setq neg nil)))
  3511. (if (string-match "\\`{.*}\\'" w)
  3512. (setq re (substring w 1 -1))
  3513. (if full-words
  3514. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3515. (setq re (regexp-quote (downcase w)))))
  3516. (if neg (push re regexps-) (push re regexps+)))
  3517. words)
  3518. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3519. regexps+))
  3520. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3521. (if (not regexps+)
  3522. (setq regexp (concat "^" org-outline-regexp))
  3523. (setq regexp (pop regexps+))
  3524. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3525. regexp))))
  3526. (setq files (org-agenda-files nil 'ifmode))
  3527. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3528. (pop org-agenda-text-search-extra-files)
  3529. (setq files (org-add-archive-files files)))
  3530. (setq files (append files org-agenda-text-search-extra-files)
  3531. rtnall nil)
  3532. (while (setq file (pop files))
  3533. (setq ee nil)
  3534. (catch 'nextfile
  3535. (org-check-agenda-file file)
  3536. (setq buffer (if (file-exists-p file)
  3537. (org-get-agenda-file-buffer file)
  3538. (error "No such file %s" file)))
  3539. (if (not buffer)
  3540. ;; If file does not exist, make sure an error message is sent
  3541. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3542. file))))
  3543. (with-current-buffer buffer
  3544. (with-syntax-table (org-search-syntax-table)
  3545. (unless (org-mode-p)
  3546. (error "Agenda file %s is not in `org-mode'" file))
  3547. (let ((case-fold-search t))
  3548. (save-excursion
  3549. (save-restriction
  3550. (if org-agenda-restrict
  3551. (narrow-to-region org-agenda-restrict-begin
  3552. org-agenda-restrict-end)
  3553. (widen))
  3554. (goto-char (point-min))
  3555. (unless (or (org-on-heading-p)
  3556. (outline-next-heading))
  3557. (throw 'nextfile t))
  3558. (goto-char (max (point-min) (1- (point))))
  3559. (while (re-search-forward regexp nil t)
  3560. (org-back-to-heading t)
  3561. (skip-chars-forward "* ")
  3562. (setq beg (point-at-bol)
  3563. beg1 (point)
  3564. end (progn (outline-next-heading) (point)))
  3565. (catch :skip
  3566. (goto-char beg)
  3567. (org-agenda-skip)
  3568. (setq str (buffer-substring-no-properties
  3569. (point-at-bol)
  3570. (if hdl-only (point-at-eol) end)))
  3571. (mapc (lambda (wr) (when (string-match wr str)
  3572. (goto-char (1- end))
  3573. (throw :skip t)))
  3574. regexps-)
  3575. (mapc (lambda (wr) (unless (string-match wr str)
  3576. (goto-char (1- end))
  3577. (throw :skip t)))
  3578. (if todo-only
  3579. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3580. regexps+)
  3581. regexps+))
  3582. (goto-char beg)
  3583. (setq marker (org-agenda-new-marker (point))
  3584. category (org-get-category)
  3585. tags (org-get-tags-at (point))
  3586. txt (org-format-agenda-item
  3587. ""
  3588. (buffer-substring-no-properties
  3589. beg1 (point-at-eol))
  3590. category tags))
  3591. (org-add-props txt props
  3592. 'org-marker marker 'org-hd-marker marker
  3593. 'org-todo-regexp org-todo-regexp
  3594. 'org-complex-heading-regexp org-complex-heading-regexp
  3595. 'priority 1000 'org-category category
  3596. 'type "search")
  3597. (push txt ee)
  3598. (goto-char (1- end))))))))))
  3599. (setq rtn (nreverse ee))
  3600. (setq rtnall (append rtnall rtn)))
  3601. (if org-agenda-overriding-header
  3602. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3603. nil 'face 'org-agenda-structure) "\n")
  3604. (insert "Search words: ")
  3605. (add-text-properties (point-min) (1- (point))
  3606. (list 'face 'org-agenda-structure))
  3607. (setq pos (point))
  3608. (insert string "\n")
  3609. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3610. (setq pos (point))
  3611. (unless org-agenda-multi
  3612. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3613. (add-text-properties pos (1- (point))
  3614. (list 'face 'org-agenda-structure))))
  3615. (org-agenda-mark-header-line (point-min))
  3616. (when rtnall
  3617. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3618. (goto-char (point-min))
  3619. (or org-agenda-multi (org-fit-agenda-window))
  3620. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3621. (org-finalize-agenda)
  3622. (setq buffer-read-only t)))
  3623. ;;; Agenda TODO list
  3624. (defvar org-select-this-todo-keyword nil)
  3625. (defvar org-last-arg nil)
  3626. ;;;###autoload
  3627. (defun org-todo-list (arg)
  3628. "Show all (not done) TODO entries from all agenda file in a single list.
  3629. The prefix arg can be used to select a specific TODO keyword and limit
  3630. the list to these. When using \\[universal-argument], you will be prompted
  3631. for a keyword. A numeric prefix directly selects the Nth keyword in
  3632. `org-todo-keywords-1'."
  3633. (interactive "P")
  3634. (org-compile-prefix-format 'todo)
  3635. (org-set-sorting-strategy 'todo)
  3636. (org-prepare-agenda "TODO")
  3637. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3638. (let* ((today (org-today))
  3639. (date (calendar-gregorian-from-absolute today))
  3640. (kwds org-todo-keywords-for-agenda)
  3641. (completion-ignore-case t)
  3642. (org-select-this-todo-keyword
  3643. (if (stringp arg) arg
  3644. (and arg (integerp arg) (> arg 0)
  3645. (nth (1- arg) kwds))))
  3646. rtn rtnall files file pos)
  3647. (when (equal arg '(4))
  3648. (setq org-select-this-todo-keyword
  3649. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3650. (mapcar 'list kwds) nil nil)))
  3651. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3652. (org-set-local 'org-last-arg arg)
  3653. (setq org-agenda-redo-command
  3654. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3655. (setq files (org-agenda-files nil 'ifmode)
  3656. rtnall nil)
  3657. (while (setq file (pop files))
  3658. (catch 'nextfile
  3659. (org-check-agenda-file file)
  3660. (setq rtn (org-agenda-get-day-entries file date :todo))
  3661. (setq rtnall (append rtnall rtn))))
  3662. (if org-agenda-overriding-header
  3663. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3664. nil 'face 'org-agenda-structure) "\n")
  3665. (insert "Global list of TODO items of type: ")
  3666. (add-text-properties (point-min) (1- (point))
  3667. (list 'face 'org-agenda-structure
  3668. 'short-heading
  3669. (concat "ToDo: "
  3670. (or org-select-this-todo-keyword "ALL"))))
  3671. (org-agenda-mark-header-line (point-min))
  3672. (setq pos (point))
  3673. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3674. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3675. (setq pos (point))
  3676. (unless org-agenda-multi
  3677. (insert "Available with `N r': (0)ALL")
  3678. (let ((n 0) s)
  3679. (mapc (lambda (x)
  3680. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3681. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3682. (insert "\n "))
  3683. (insert " " s))
  3684. kwds))
  3685. (insert "\n"))
  3686. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3687. (org-agenda-mark-header-line (point-min))
  3688. (when rtnall
  3689. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3690. (goto-char (point-min))
  3691. (or org-agenda-multi (org-fit-agenda-window))
  3692. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3693. (org-finalize-agenda)
  3694. (setq buffer-read-only t)))
  3695. ;;; Agenda tags match
  3696. ;;;###autoload
  3697. (defun org-tags-view (&optional todo-only match)
  3698. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3699. The prefix arg TODO-ONLY limits the search to TODO entries."
  3700. (interactive "P")
  3701. (org-compile-prefix-format 'tags)
  3702. (org-set-sorting-strategy 'tags)
  3703. (let* ((org-tags-match-list-sublevels
  3704. org-tags-match-list-sublevels)
  3705. (completion-ignore-case t)
  3706. rtn rtnall files file pos matcher
  3707. buffer)
  3708. (when (and (stringp match) (not (string-match "\\S-" match)))
  3709. (setq match nil))
  3710. (setq matcher (org-make-tags-matcher match)
  3711. match (car matcher) matcher (cdr matcher))
  3712. (org-prepare-agenda (concat "TAGS " match))
  3713. (setq org-agenda-query-string match)
  3714. (setq org-agenda-redo-command
  3715. (list 'org-tags-view (list 'quote todo-only)
  3716. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3717. (setq files (org-agenda-files nil 'ifmode)
  3718. rtnall nil)
  3719. (while (setq file (pop files))
  3720. (catch 'nextfile
  3721. (org-check-agenda-file file)
  3722. (setq buffer (if (file-exists-p file)
  3723. (org-get-agenda-file-buffer file)
  3724. (error "No such file %s" file)))
  3725. (if (not buffer)
  3726. ;; If file does not exist, error message to agenda
  3727. (setq rtn (list
  3728. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3729. rtnall (append rtnall rtn))
  3730. (with-current-buffer buffer
  3731. (unless (org-mode-p)
  3732. (error "Agenda file %s is not in `org-mode'" file))
  3733. (save-excursion
  3734. (save-restriction
  3735. (if org-agenda-restrict
  3736. (narrow-to-region org-agenda-restrict-begin
  3737. org-agenda-restrict-end)
  3738. (widen))
  3739. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3740. (setq rtnall (append rtnall rtn))))))))
  3741. (if org-agenda-overriding-header
  3742. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3743. nil 'face 'org-agenda-structure) "\n")
  3744. (insert "Headlines with TAGS match: ")
  3745. (add-text-properties (point-min) (1- (point))
  3746. (list 'face 'org-agenda-structure
  3747. 'short-heading
  3748. (concat "Match: " match)))
  3749. (setq pos (point))
  3750. (insert match "\n")
  3751. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3752. (setq pos (point))
  3753. (unless org-agenda-multi
  3754. (insert "Press `C-u r' to search again with new search string\n"))
  3755. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3756. (org-agenda-mark-header-line (point-min))
  3757. (when rtnall
  3758. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3759. (goto-char (point-min))
  3760. (or org-agenda-multi (org-fit-agenda-window))
  3761. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3762. (org-finalize-agenda)
  3763. (setq buffer-read-only t)))
  3764. ;;; Agenda Finding stuck projects
  3765. (defvar org-agenda-skip-regexp nil
  3766. "Regular expression used in skipping subtrees for the agenda.
  3767. This is basically a temporary global variable that can be set and then
  3768. used by user-defined selections using `org-agenda-skip-function'.")
  3769. (defvar org-agenda-overriding-header nil
  3770. "When this is set during todo and tags searches, will replace header.
  3771. This variable should not be set directly, but custom commands can bind it
  3772. in the options section.")
  3773. (defun org-agenda-skip-entry-when-regexp-matches ()
  3774. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3775. If yes, it returns the end position of this entry, causing agenda commands
  3776. to skip the entry but continuing the search in the subtree. This is a
  3777. function that can be put into `org-agenda-skip-function' for the duration
  3778. of a command."
  3779. (let ((end (save-excursion (org-end-of-subtree t)))
  3780. skip)
  3781. (save-excursion
  3782. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3783. (and skip end)))
  3784. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3785. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3786. If yes, it returns the end position of this tree, causing agenda commands
  3787. to skip this subtree. This is a function that can be put into
  3788. `org-agenda-skip-function' for the duration of a command."
  3789. (let ((end (save-excursion (org-end-of-subtree t)))
  3790. skip)
  3791. (save-excursion
  3792. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3793. (and skip end)))
  3794. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3795. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3796. If yes, it returns the end position of the current entry (NOT the tree),
  3797. causing agenda commands to skip the entry but continuing the search in
  3798. the subtree. This is a function that can be put into
  3799. `org-agenda-skip-function' for the duration of a command. An important
  3800. use of this function is for the stuck project list."
  3801. (let ((end (save-excursion (org-end-of-subtree t)))
  3802. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3803. skip)
  3804. (save-excursion
  3805. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3806. (and skip entry-end)))
  3807. (defun org-agenda-skip-entry-if (&rest conditions)
  3808. "Skip entry if any of CONDITIONS is true.
  3809. See `org-agenda-skip-if' for details."
  3810. (org-agenda-skip-if nil conditions))
  3811. (defun org-agenda-skip-subtree-if (&rest conditions)
  3812. "Skip entry if any of CONDITIONS is true.
  3813. See `org-agenda-skip-if' for details."
  3814. (org-agenda-skip-if t conditions))
  3815. (defun org-agenda-skip-if (subtree conditions)
  3816. "Checks current entity for CONDITIONS.
  3817. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3818. the entry, i.e. the text before the next heading is checked.
  3819. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3820. from different tests. Valid conditions are:
  3821. scheduled Check if there is a scheduled cookie
  3822. notscheduled Check if there is no scheduled cookie
  3823. deadline Check if there is a deadline
  3824. notdeadline Check if there is no deadline
  3825. timestamp Check if there is a timestamp (also deadline or scheduled)
  3826. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3827. regexp Check if regexp matches
  3828. notregexp Check if regexp does not match.
  3829. todo Check if TODO keyword matches
  3830. nottodo Check if TODO keyword does not match
  3831. The regexp is taken from the conditions list, it must come right after
  3832. the `regexp' or `notregexp' element.
  3833. `todo' and `nottodo' accept as an argument a list of todo
  3834. keywords, which may include \"*\" to match any todo keyword.
  3835. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3836. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3837. Instead of a list a keyword class may be given
  3838. (org-agenda-skip-entry-if 'nottodo 'done)
  3839. would skip entries that haven't been marked with any of \"DONE\"
  3840. keywords. Possible classes are: `todo', `done', `any'.
  3841. If any of these conditions is met, this function returns the end point of
  3842. the entity, causing the search to continue from there. This is a function
  3843. that can be put into `org-agenda-skip-function' for the duration of a command."
  3844. (let (beg end m)
  3845. (org-back-to-heading t)
  3846. (setq beg (point)
  3847. end (if subtree
  3848. (progn (org-end-of-subtree t) (point))
  3849. (progn (outline-next-heading) (1- (point)))))
  3850. (goto-char beg)
  3851. (and
  3852. (or
  3853. (and (memq 'scheduled conditions)
  3854. (re-search-forward org-scheduled-time-regexp end t))
  3855. (and (memq 'notscheduled conditions)
  3856. (not (re-search-forward org-scheduled-time-regexp end t)))
  3857. (and (memq 'deadline conditions)
  3858. (re-search-forward org-deadline-time-regexp end t))
  3859. (and (memq 'notdeadline conditions)
  3860. (not (re-search-forward org-deadline-time-regexp end t)))
  3861. (and (memq 'timestamp conditions)
  3862. (re-search-forward org-ts-regexp end t))
  3863. (and (memq 'nottimestamp conditions)
  3864. (not (re-search-forward org-ts-regexp end t)))
  3865. (and (setq m (memq 'regexp conditions))
  3866. (stringp (nth 1 m))
  3867. (re-search-forward (nth 1 m) end t))
  3868. (and (setq m (memq 'notregexp conditions))
  3869. (stringp (nth 1 m))
  3870. (not (re-search-forward (nth 1 m) end t)))
  3871. (and (or
  3872. (setq m (memq 'todo conditions))
  3873. (setq m (memq 'nottodo conditions)))
  3874. (org-agenda-skip-if-todo m end)))
  3875. end)))
  3876. (defun org-agenda-skip-if-todo (args end)
  3877. "Helper function for `org-agenda-skip-if', do not use it directly.
  3878. ARGS is a list with first element either `todo' or `nottodo'.
  3879. The remainder is either a list of TODO keywords, or a state symbol
  3880. `todo' or `done' or `any'."
  3881. (let ((kw (car args))
  3882. (arg (cadr args))
  3883. todo-wds todo-re)
  3884. (setq todo-wds
  3885. (org-uniquify
  3886. (cond
  3887. ((listp arg) ;; list of keywords
  3888. (if (member "*" arg)
  3889. (mapcar 'substring-no-properties org-todo-keywords-1)
  3890. arg))
  3891. ((symbolp arg) ;; keyword class name
  3892. (cond
  3893. ((eq arg 'todo)
  3894. (org-delete-all org-done-keywords
  3895. (mapcar 'substring-no-properties
  3896. org-todo-keywords-1)))
  3897. ((eq arg 'done) org-done-keywords)
  3898. ((eq arg 'any)
  3899. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3900. (setq todo-re
  3901. (concat "^\\*+[ \t]+\\<\\("
  3902. (mapconcat 'identity todo-wds "\\|")
  3903. "\\)\\>"))
  3904. (if (eq kw 'todo)
  3905. (re-search-forward todo-re end t)
  3906. (not (re-search-forward todo-re end t)))))
  3907. ;;;###autoload
  3908. (defun org-agenda-list-stuck-projects (&rest ignore)
  3909. "Create agenda view for projects that are stuck.
  3910. Stuck projects are project that have no next actions. For the definitions
  3911. of what a project is and how to check if it stuck, customize the variable
  3912. `org-stuck-projects'."
  3913. (interactive)
  3914. (let* ((org-agenda-skip-function
  3915. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3916. ;; We could have used org-agenda-skip-if here.
  3917. (org-agenda-overriding-header
  3918. (or org-agenda-overriding-header "List of stuck projects: "))
  3919. (matcher (nth 0 org-stuck-projects))
  3920. (todo (nth 1 org-stuck-projects))
  3921. (todo-wds (if (member "*" todo)
  3922. (progn
  3923. (org-prepare-agenda-buffers (org-agenda-files
  3924. nil 'ifmode))
  3925. (org-delete-all
  3926. org-done-keywords-for-agenda
  3927. (copy-sequence org-todo-keywords-for-agenda)))
  3928. todo))
  3929. (todo-re (concat "^\\*+[ \t]+\\("
  3930. (mapconcat 'identity todo-wds "\\|")
  3931. "\\)\\>"))
  3932. (tags (nth 2 org-stuck-projects))
  3933. (tags-re (if (member "*" tags)
  3934. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3935. (if tags
  3936. (concat "^\\*+ .*:\\("
  3937. (mapconcat 'identity tags "\\|")
  3938. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3939. (gen-re (nth 3 org-stuck-projects))
  3940. (re-list
  3941. (delq nil
  3942. (list
  3943. (if todo todo-re)
  3944. (if tags tags-re)
  3945. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3946. gen-re)))))
  3947. (setq org-agenda-skip-regexp
  3948. (if re-list
  3949. (mapconcat 'identity re-list "\\|")
  3950. (error "No information how to identify unstuck projects")))
  3951. (org-tags-view nil matcher)
  3952. (with-current-buffer org-agenda-buffer-name
  3953. (setq org-agenda-redo-command
  3954. '(org-agenda-list-stuck-projects
  3955. (or current-prefix-arg org-last-arg))))))
  3956. ;;; Diary integration
  3957. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3958. (defvar list-diary-entries-hook)
  3959. (defvar diary-time-regexp)
  3960. (defun org-get-entries-from-diary (date)
  3961. "Get the (Emacs Calendar) diary entries for DATE."
  3962. (require 'diary-lib)
  3963. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3964. (diary-display-hook '(fancy-diary-display))
  3965. (diary-display-function 'fancy-diary-display)
  3966. (pop-up-frames nil)
  3967. (list-diary-entries-hook
  3968. (cons 'org-diary-default-entry list-diary-entries-hook))
  3969. (diary-file-name-prefix-function nil) ; turn this feature off
  3970. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3971. entries
  3972. (org-disable-agenda-to-diary t))
  3973. (save-excursion
  3974. (save-window-excursion
  3975. (funcall (if (fboundp 'diary-list-entries)
  3976. 'diary-list-entries 'list-diary-entries)
  3977. date 1)))
  3978. (if (not (get-buffer diary-fancy-buffer))
  3979. (setq entries nil)
  3980. (with-current-buffer diary-fancy-buffer
  3981. (setq buffer-read-only nil)
  3982. (if (zerop (buffer-size))
  3983. ;; No entries
  3984. (setq entries nil)
  3985. ;; Omit the date and other unnecessary stuff
  3986. (org-agenda-cleanup-fancy-diary)
  3987. ;; Add prefix to each line and extend the text properties
  3988. (if (zerop (buffer-size))
  3989. (setq entries nil)
  3990. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  3991. (setq entries
  3992. (with-temp-buffer
  3993. (insert entries) (goto-char (point-min))
  3994. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  3995. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  3996. (replace-match (concat "; " (match-string 1)))))
  3997. (buffer-string)))))
  3998. (set-buffer-modified-p nil)
  3999. (kill-buffer diary-fancy-buffer)))
  4000. (when entries
  4001. (setq entries (org-split-string entries "\n"))
  4002. (setq entries
  4003. (mapcar
  4004. (lambda (x)
  4005. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4006. ;; Extend the text properties to the beginning of the line
  4007. (org-add-props x (text-properties-at (1- (length x)) x)
  4008. 'type "diary" 'date date 'face 'org-agenda-diary))
  4009. entries)))))
  4010. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4011. "Hook run when the fancy diary buffer is cleaned up.")
  4012. (defun org-agenda-cleanup-fancy-diary ()
  4013. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4014. This gets rid of the date, the underline under the date, and
  4015. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4016. date. It also removes lines that contain only whitespace."
  4017. (goto-char (point-min))
  4018. (if (looking-at ".*?:[ \t]*")
  4019. (progn
  4020. (replace-match "")
  4021. (re-search-forward "\n=+$" nil t)
  4022. (replace-match "")
  4023. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4024. (re-search-forward "\n=+$" nil t)
  4025. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4026. (goto-char (point-min))
  4027. (while (re-search-forward "^ +\n" nil t)
  4028. (replace-match ""))
  4029. (goto-char (point-min))
  4030. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4031. (replace-match ""))
  4032. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4033. ;; Make sure entries from the diary have the right text properties.
  4034. (eval-after-load "diary-lib"
  4035. '(if (boundp 'diary-modify-entry-list-string-function)
  4036. ;; We can rely on the hook, nothing to do
  4037. nil
  4038. ;; Hook not available, must use advice to make this work
  4039. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4040. "Make the position visible."
  4041. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4042. (stringp string)
  4043. buffer-file-name)
  4044. (setq string (org-modify-diary-entry-string string))))))
  4045. (defun org-modify-diary-entry-string (string)
  4046. "Add text properties to string, allowing org-mode to act on it."
  4047. (org-add-props string nil
  4048. 'mouse-face 'highlight
  4049. 'help-echo (if buffer-file-name
  4050. (format "mouse-2 or RET jump to diary file %s"
  4051. (abbreviate-file-name buffer-file-name))
  4052. "")
  4053. 'org-agenda-diary-link t
  4054. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4055. (defun org-diary-default-entry ()
  4056. "Add a dummy entry to the diary.
  4057. Needed to avoid empty dates which mess up holiday display."
  4058. ;; Catch the error if dealing with the new add-to-diary-alist
  4059. (when org-disable-agenda-to-diary
  4060. (condition-case nil
  4061. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4062. (error
  4063. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4064. (defun org-add-to-diary-list (&rest args)
  4065. (if (fboundp 'diary-add-to-list)
  4066. (apply 'diary-add-to-list args)
  4067. (apply 'add-to-diary-list args)))
  4068. (defvar org-diary-last-run-time nil)
  4069. ;;;###autoload
  4070. (defun org-diary (&rest args)
  4071. "Return diary information from org-files.
  4072. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4073. It accesses org files and extracts information from those files to be
  4074. listed in the diary. The function accepts arguments specifying what
  4075. items should be listed. For a list of arguments allowed here, see the
  4076. variable `org-agenda-entry-types'.
  4077. The call in the diary file should look like this:
  4078. &%%(org-diary) ~/path/to/some/orgfile.org
  4079. Use a separate line for each org file to check. Or, if you omit the file name,
  4080. all files listed in `org-agenda-files' will be checked automatically:
  4081. &%%(org-diary)
  4082. If you don't give any arguments (as in the example above), the default
  4083. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4084. So the example above may also be written as
  4085. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4086. The function expects the lisp variables `entry' and `date' to be provided
  4087. by the caller, because this is how the calendar works. Don't use this
  4088. function from a program - use `org-agenda-get-day-entries' instead."
  4089. (when (> (- (org-float-time)
  4090. org-agenda-last-marker-time)
  4091. 5)
  4092. (org-agenda-reset-markers))
  4093. (org-compile-prefix-format 'agenda)
  4094. (org-set-sorting-strategy 'agenda)
  4095. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4096. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4097. (list entry)
  4098. (org-agenda-files t)))
  4099. (time (org-float-time))
  4100. file rtn results)
  4101. (when (or (not org-diary-last-run-time)
  4102. (> (- time
  4103. org-diary-last-run-time)
  4104. 3))
  4105. (org-prepare-agenda-buffers files))
  4106. (setq org-diary-last-run-time time)
  4107. ;; If this is called during org-agenda, don't return any entries to
  4108. ;; the calendar. Org Agenda will list these entries itself.
  4109. (if org-disable-agenda-to-diary (setq files nil))
  4110. (while (setq file (pop files))
  4111. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4112. (setq results (append results rtn)))
  4113. (if results
  4114. (concat (org-finalize-agenda-entries results) "\n"))))
  4115. ;;; Agenda entry finders
  4116. (defun org-agenda-get-day-entries (file date &rest args)
  4117. "Does the work for `org-diary' and `org-agenda'.
  4118. FILE is the path to a file to be checked for entries. DATE is date like
  4119. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4120. which kind of entries should be extracted. For details about these, see
  4121. the documentation of `org-diary'."
  4122. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4123. (let* ((org-startup-folded nil)
  4124. (org-startup-align-all-tables nil)
  4125. (buffer (if (file-exists-p file)
  4126. (org-get-agenda-file-buffer file)
  4127. (error "No such file %s" file)))
  4128. arg results rtn deadline-results)
  4129. (if (not buffer)
  4130. ;; If file does not exist, make sure an error message ends up in diary
  4131. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4132. (with-current-buffer buffer
  4133. (unless (org-mode-p)
  4134. (error "Agenda file %s is not in `org-mode'" file))
  4135. (let ((case-fold-search nil))
  4136. (save-excursion
  4137. (save-restriction
  4138. (if org-agenda-restrict
  4139. (narrow-to-region org-agenda-restrict-begin
  4140. org-agenda-restrict-end)
  4141. (widen))
  4142. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4143. (while (setq arg (pop args))
  4144. (cond
  4145. ((and (eq arg :todo)
  4146. (equal date (calendar-gregorian-from-absolute
  4147. (org-today))))
  4148. (setq rtn (org-agenda-get-todos))
  4149. (setq results (append results rtn)))
  4150. ((eq arg :timestamp)
  4151. (setq rtn (org-agenda-get-blocks))
  4152. (setq results (append results rtn))
  4153. (setq rtn (org-agenda-get-timestamps))
  4154. (setq results (append results rtn)))
  4155. ((eq arg :sexp)
  4156. (setq rtn (org-agenda-get-sexps))
  4157. (setq results (append results rtn)))
  4158. ((eq arg :scheduled)
  4159. (setq rtn (org-agenda-get-scheduled deadline-results))
  4160. (setq results (append results rtn)))
  4161. ((eq arg :closed)
  4162. (setq rtn (org-agenda-get-progress))
  4163. (setq results (append results rtn)))
  4164. ((eq arg :deadline)
  4165. (setq rtn (org-agenda-get-deadlines))
  4166. (setq deadline-results (copy-sequence rtn))
  4167. (setq results (append results rtn))))))))
  4168. results))))
  4169. (defun org-agenda-get-todos ()
  4170. "Return the TODO information for agenda display."
  4171. (let* ((props (list 'face nil
  4172. 'done-face 'org-agenda-done
  4173. 'org-not-done-regexp org-not-done-regexp
  4174. 'org-todo-regexp org-todo-regexp
  4175. 'org-complex-heading-regexp org-complex-heading-regexp
  4176. 'mouse-face 'highlight
  4177. 'help-echo
  4178. (format "mouse-2 or RET jump to org file %s"
  4179. (abbreviate-file-name buffer-file-name))))
  4180. (regexp (concat "^\\*+[ \t]+\\("
  4181. (if org-select-this-todo-keyword
  4182. (if (equal org-select-this-todo-keyword "*")
  4183. org-todo-regexp
  4184. (concat "\\<\\("
  4185. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4186. "\\)\\>"))
  4187. org-not-done-regexp)
  4188. "[^\n\r]*\\)"))
  4189. marker priority category tags todo-state
  4190. ee txt beg end)
  4191. (goto-char (point-min))
  4192. (while (re-search-forward regexp nil t)
  4193. (catch :skip
  4194. (save-match-data
  4195. (beginning-of-line)
  4196. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4197. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4198. (goto-char (1+ beg))
  4199. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4200. (throw :skip nil)))
  4201. (goto-char beg)
  4202. (org-agenda-skip)
  4203. (goto-char (match-beginning 1))
  4204. (setq marker (org-agenda-new-marker (match-beginning 0))
  4205. category (org-get-category)
  4206. txt (match-string 1)
  4207. tags (org-get-tags-at (point))
  4208. txt (org-format-agenda-item "" txt category tags)
  4209. priority (1+ (org-get-priority txt))
  4210. todo-state (org-get-todo-state))
  4211. (org-add-props txt props
  4212. 'org-marker marker 'org-hd-marker marker
  4213. 'priority priority 'org-category category
  4214. 'type "todo" 'todo-state todo-state)
  4215. (push txt ee)
  4216. (if org-agenda-todo-list-sublevels
  4217. (goto-char (match-end 1))
  4218. (org-end-of-subtree 'invisible))))
  4219. (nreverse ee)))
  4220. (defun org-agenda-todo-custom-ignore-p (time n)
  4221. "Check whether timestamp is farther away then n number of days.
  4222. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4223. `org-agenda-todo-ignore-scheduled' or
  4224. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4225. (let ((days (org-days-to-time time)))
  4226. (if (>= n 0)
  4227. (>= days n)
  4228. (<= days n))))
  4229. ;;;###autoload
  4230. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4231. (&optional end)
  4232. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4233. (when (or org-agenda-todo-ignore-with-date
  4234. org-agenda-todo-ignore-scheduled
  4235. org-agenda-todo-ignore-deadlines
  4236. org-agenda-todo-ignore-timestamp)
  4237. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4238. (save-excursion
  4239. (or (and org-agenda-todo-ignore-with-date
  4240. (re-search-forward org-ts-regexp end t))
  4241. (and org-agenda-todo-ignore-scheduled
  4242. (re-search-forward org-scheduled-time-regexp end t)
  4243. (cond
  4244. ((eq org-agenda-todo-ignore-scheduled 'future)
  4245. (> (org-days-to-time (match-string 1)) 0))
  4246. ((eq org-agenda-todo-ignore-scheduled 'past)
  4247. (<= (org-days-to-time (match-string 1)) 0))
  4248. ((numberp org-agenda-todo-ignore-scheduled)
  4249. (org-agenda-todo-custom-ignore-p
  4250. (match-string 1) org-agenda-todo-ignore-scheduled))
  4251. (t)))
  4252. (and org-agenda-todo-ignore-deadlines
  4253. (re-search-forward org-deadline-time-regexp end t)
  4254. (cond
  4255. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4256. ((eq org-agenda-todo-ignore-deadlines 'far)
  4257. (not (org-deadline-close (match-string 1))))
  4258. ((eq org-agenda-todo-ignore-deadlines 'future)
  4259. (> (org-days-to-time (match-string 1)) 0))
  4260. ((eq org-agenda-todo-ignore-deadlines 'past)
  4261. (<= (org-days-to-time (match-string 1)) 0))
  4262. ((numberp org-agenda-todo-ignore-deadlines)
  4263. (org-agenda-todo-custom-ignore-p
  4264. (match-string 1) org-agenda-todo-ignore-deadlines))
  4265. (t (org-deadline-close (match-string 1)))))
  4266. (and org-agenda-todo-ignore-timestamp
  4267. (let ((buffer (current-buffer))
  4268. (regexp
  4269. (concat
  4270. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4271. (start (point)))
  4272. ;; Copy current buffer into a temporary one
  4273. (with-temp-buffer
  4274. (insert-buffer-substring buffer start end)
  4275. (goto-char (point-min))
  4276. ;; Delete SCHEDULED and DEADLINE items
  4277. (while (re-search-forward regexp end t)
  4278. (delete-region (match-beginning 0) (match-end 0)))
  4279. (goto-char (point-min))
  4280. ;; No search for timestamp left
  4281. (when (re-search-forward org-ts-regexp nil t)
  4282. (cond
  4283. ((eq org-agenda-todo-ignore-timestamp 'future)
  4284. (> (org-days-to-time (match-string 1)) 0))
  4285. ((eq org-agenda-todo-ignore-timestamp 'past)
  4286. (<= (org-days-to-time (match-string 1)) 0))
  4287. ((numberp org-agenda-todo-ignore-timestamp)
  4288. (org-agenda-todo-custom-ignore-p
  4289. (match-string 1) org-agenda-todo-ignore-timestamp))
  4290. (t))))))))))
  4291. (defconst org-agenda-no-heading-message
  4292. "No heading for this item in buffer or region.")
  4293. (defun org-agenda-get-timestamps ()
  4294. "Return the date stamp information for agenda display."
  4295. (let* ((props (list 'face nil
  4296. 'org-not-done-regexp org-not-done-regexp
  4297. 'org-todo-regexp org-todo-regexp
  4298. 'org-complex-heading-regexp org-complex-heading-regexp
  4299. 'mouse-face 'highlight
  4300. 'help-echo
  4301. (format "mouse-2 or RET jump to org file %s"
  4302. (abbreviate-file-name buffer-file-name))))
  4303. (d1 (calendar-absolute-from-gregorian date))
  4304. (remove-re
  4305. (concat
  4306. (regexp-quote
  4307. (format-time-string
  4308. "<%Y-%m-%d"
  4309. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4310. ".*?>"))
  4311. (regexp
  4312. (concat
  4313. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4314. (regexp-quote
  4315. (substring
  4316. (format-time-string
  4317. (car org-time-stamp-formats)
  4318. (apply 'encode-time ; DATE bound by calendar
  4319. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4320. 1 11))
  4321. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4322. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4323. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4324. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4325. todo-state end-of-match show-all)
  4326. (goto-char (point-min))
  4327. (while (setq end-of-match (re-search-forward regexp nil t))
  4328. (setq b0 (match-beginning 0)
  4329. b3 (match-beginning 3) e3 (match-end 3)
  4330. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4331. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4332. (member todo-state
  4333. org-agenda-repeating-timestamp-show-all)))
  4334. (catch :skip
  4335. (and (org-at-date-range-p) (throw :skip nil))
  4336. (org-agenda-skip)
  4337. (if (and (match-end 1)
  4338. (not (= d1 (org-time-string-to-absolute
  4339. (match-string 1) d1 nil show-all))))
  4340. (throw :skip nil))
  4341. (if (and e3
  4342. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4343. (throw :skip nil))
  4344. (setq tmp (buffer-substring (max (point-min)
  4345. (- b0 org-ds-keyword-length))
  4346. b0)
  4347. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4348. inactivep (= (char-after b0) ?\[)
  4349. deadlinep (string-match org-deadline-regexp tmp)
  4350. scheduledp (string-match org-scheduled-regexp tmp)
  4351. closedp (and org-agenda-include-inactive-timestamps
  4352. (string-match org-closed-string tmp))
  4353. clockp (and org-agenda-include-inactive-timestamps
  4354. (or (string-match org-clock-string tmp)
  4355. (string-match "]-+\\'" tmp)))
  4356. donep (member todo-state org-done-keywords))
  4357. (if (or scheduledp deadlinep closedp clockp
  4358. (and donep org-agenda-skip-timestamp-if-done))
  4359. (throw :skip t))
  4360. (if (string-match ">" timestr)
  4361. ;; substring should only run to end of time stamp
  4362. (setq timestr (substring timestr 0 (match-end 0))))
  4363. (setq marker (org-agenda-new-marker b0)
  4364. category (org-get-category b0))
  4365. (save-excursion
  4366. (if (not (re-search-backward "^\\*+ " nil t))
  4367. (setq txt org-agenda-no-heading-message)
  4368. (goto-char (match-beginning 0))
  4369. (setq hdmarker (org-agenda-new-marker)
  4370. tags (org-get-tags-at))
  4371. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4372. (setq head (or (match-string 1) ""))
  4373. (setq txt (org-format-agenda-item
  4374. (if inactivep org-agenda-inactive-leader nil)
  4375. head category tags timestr
  4376. remove-re)))
  4377. (setq priority (org-get-priority txt))
  4378. (org-add-props txt props
  4379. 'org-marker marker 'org-hd-marker hdmarker)
  4380. (org-add-props txt nil 'priority priority
  4381. 'org-category category 'date date
  4382. 'todo-state todo-state
  4383. 'type "timestamp")
  4384. (push txt ee))
  4385. (if org-agenda-skip-additional-timestamps-same-entry
  4386. (outline-next-heading)
  4387. (goto-char end-of-match))))
  4388. (nreverse ee)))
  4389. (defun org-agenda-get-sexps ()
  4390. "Return the sexp information for agenda display."
  4391. (require 'diary-lib)
  4392. (let* ((props (list 'mouse-face 'highlight
  4393. 'help-echo
  4394. (format "mouse-2 or RET jump to org file %s"
  4395. (abbreviate-file-name buffer-file-name))))
  4396. (regexp "^&?%%(")
  4397. marker category ee txt tags entry result beg b sexp sexp-entry
  4398. todo-state)
  4399. (goto-char (point-min))
  4400. (while (re-search-forward regexp nil t)
  4401. (catch :skip
  4402. (org-agenda-skip)
  4403. (setq beg (match-beginning 0))
  4404. (goto-char (1- (match-end 0)))
  4405. (setq b (point))
  4406. (forward-sexp 1)
  4407. (setq sexp (buffer-substring b (point)))
  4408. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4409. (org-trim (match-string 1))
  4410. ""))
  4411. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4412. (when result
  4413. (setq marker (org-agenda-new-marker beg)
  4414. category (org-get-category beg)
  4415. todo-state (org-get-todo-state))
  4416. (dolist (r (if (stringp result)
  4417. (list result)
  4418. result)) ;; we expect a list here
  4419. (if (string-match "\\S-" r)
  4420. (setq txt r)
  4421. (setq txt "SEXP entry returned empty string"))
  4422. (setq txt (org-format-agenda-item
  4423. "" txt category tags 'time))
  4424. (org-add-props txt props 'org-marker marker)
  4425. (org-add-props txt nil
  4426. 'org-category category 'date date 'todo-state todo-state
  4427. 'type "sexp")
  4428. (push txt ee)))))
  4429. (nreverse ee)))
  4430. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4431. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4432. The order of the first 2 times 3 arguments depends on the variable
  4433. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4434. So for American calendars, give this as MONTH DAY YEAR, for European as
  4435. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4436. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4437. is any number of ISO weeks in the block period for which the item should
  4438. be skipped."
  4439. (let* ((date1 (calendar-absolute-from-gregorian
  4440. (org-order-calendar-date-args m1 d1 y1)))
  4441. (date2 (calendar-absolute-from-gregorian
  4442. (org-order-calendar-date-args m2 d2 y2)))
  4443. (d (calendar-absolute-from-gregorian date)))
  4444. (and
  4445. (<= date1 d)
  4446. (<= d date2)
  4447. (= (calendar-day-of-week date) dayname)
  4448. (or (not skip-weeks)
  4449. (progn
  4450. (require 'cal-iso)
  4451. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4452. entry)))
  4453. (defalias 'org-get-closed 'org-agenda-get-progress)
  4454. (defun org-agenda-get-progress ()
  4455. "Return the logged TODO entries for agenda display."
  4456. (let* ((props (list 'mouse-face 'highlight
  4457. 'org-not-done-regexp org-not-done-regexp
  4458. 'org-todo-regexp org-todo-regexp
  4459. 'org-complex-heading-regexp org-complex-heading-regexp
  4460. 'help-echo
  4461. (format "mouse-2 or RET jump to org file %s"
  4462. (abbreviate-file-name buffer-file-name))))
  4463. (items (if (consp org-agenda-show-log)
  4464. org-agenda-show-log
  4465. (if (eq org-agenda-show-log 'clockcheck)
  4466. '(clock)
  4467. org-agenda-log-mode-items)))
  4468. (parts
  4469. (delq nil
  4470. (list
  4471. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4472. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4473. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4474. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4475. (error "`org-agenda-log-mode-items' is empty")))
  4476. (regexp (concat
  4477. "\\(" parts-re "\\)"
  4478. " *\\["
  4479. (regexp-quote
  4480. (substring
  4481. (format-time-string
  4482. (car org-time-stamp-formats)
  4483. (apply 'encode-time ; DATE bound by calendar
  4484. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4485. 1 11))))
  4486. (org-agenda-search-headline-for-time nil)
  4487. marker hdmarker priority category tags closedp statep clockp state
  4488. ee txt extra timestr rest clocked)
  4489. (goto-char (point-min))
  4490. (while (re-search-forward regexp nil t)
  4491. (catch :skip
  4492. (org-agenda-skip)
  4493. (setq marker (org-agenda-new-marker (match-beginning 0))
  4494. closedp (equal (match-string 1) org-closed-string)
  4495. statep (equal (string-to-char (match-string 1)) ?-)
  4496. clockp (not (or closedp statep))
  4497. state (and statep (match-string 2))
  4498. category (org-get-category (match-beginning 0))
  4499. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4500. )
  4501. (when (string-match "\\]" timestr)
  4502. ;; substring should only run to end of time stamp
  4503. (setq rest (substring timestr (match-end 0))
  4504. timestr (substring timestr 0 (match-end 0)))
  4505. (if (and (not closedp) (not statep)
  4506. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4507. (progn (setq timestr (concat (substring timestr 0 -1)
  4508. "-" (match-string 1 rest) "]"))
  4509. (setq clocked (match-string 2 rest)))
  4510. (setq clocked "-")))
  4511. (save-excursion
  4512. (setq extra
  4513. (cond
  4514. ((not org-agenda-log-mode-add-notes) nil)
  4515. (statep
  4516. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4517. (match-string 1)))
  4518. (clockp
  4519. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4520. (match-string 1)))))
  4521. (if (not (re-search-backward "^\\*+ " nil t))
  4522. (setq txt org-agenda-no-heading-message)
  4523. (goto-char (match-beginning 0))
  4524. (setq hdmarker (org-agenda-new-marker)
  4525. tags (org-get-tags-at))
  4526. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4527. (setq txt (match-string 1))
  4528. (when extra
  4529. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4530. (setq txt (concat (substring txt 0 (match-beginning 1))
  4531. " - " extra " " (match-string 2 txt)))
  4532. (setq txt (concat txt " - " extra))))
  4533. (setq txt (org-format-agenda-item
  4534. (cond
  4535. (closedp "Closed: ")
  4536. (statep (concat "State: (" state ")"))
  4537. (t (concat "Clocked: (" clocked ")")))
  4538. txt category tags timestr)))
  4539. (setq priority 100000)
  4540. (org-add-props txt props
  4541. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4542. 'priority priority 'org-category category
  4543. 'type "closed" 'date date
  4544. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4545. (push txt ee))
  4546. (goto-char (point-at-eol))))
  4547. (nreverse ee)))
  4548. (defun org-agenda-show-clocking-issues ()
  4549. "Add overlays, showing issues with clocking.
  4550. See also the user option `org-agenda-clock-consistency-checks'."
  4551. (interactive)
  4552. (let* ((pl org-agenda-clock-consistency-checks)
  4553. (re (concat "^[ \t]*"
  4554. org-clock-string
  4555. "[ \t]+"
  4556. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4557. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4558. (tlstart 0.)
  4559. (tlend 0.)
  4560. (maxtime (org-hh:mm-string-to-minutes
  4561. (or (plist-get pl :max-duration) "24:00")))
  4562. (mintime (org-hh:mm-string-to-minutes
  4563. (or (plist-get pl :min-duration) 0)))
  4564. (maxgap (org-hh:mm-string-to-minutes
  4565. ;; default 30:00 means never complain
  4566. (or (plist-get pl :max-gap) "30:00")))
  4567. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4568. (plist-get pl :gap-ok-around)))
  4569. issue)
  4570. (goto-char (point-min))
  4571. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4572. (setq issue nil)
  4573. (catch 'next
  4574. (setq m (org-get-at-bol 'org-marker)
  4575. te nil ts nil)
  4576. (unless (and m (markerp m))
  4577. (setq issue "No valid clock line") (throw 'next t))
  4578. (org-with-point-at m
  4579. (save-excursion
  4580. (goto-char (point-at-bol))
  4581. (unless (looking-at re)
  4582. (error "No valid Clock line")
  4583. (throw 'next t))
  4584. (unless (match-end 3)
  4585. (setq issue "No end time")
  4586. (throw 'next t))
  4587. (setq ts (match-string 1)
  4588. te (match-string 3)
  4589. ts (org-float-time
  4590. (apply 'encode-time (org-parse-time-string ts)))
  4591. te (org-float-time
  4592. (apply 'encode-time (org-parse-time-string te)))
  4593. dt (- te ts))))
  4594. (cond
  4595. ((> dt (* 60 maxtime))
  4596. ;; a very long clocking chunk
  4597. (setq issue (format "Clocking interval is very long: %s"
  4598. (org-minutes-to-hh:mm-string
  4599. (floor (/ (float dt) 60.))))))
  4600. ((< dt (* 60 mintime))
  4601. ;; a very short clocking chunk
  4602. (setq issue (format "Clocking interval is very short: %s"
  4603. (org-minutes-to-hh:mm-string
  4604. (floor (/ (float dt) 60.))))))
  4605. ((and (> tlend 0) (< ts tlend))
  4606. ;; Two clock entries are overlapping
  4607. (setq issue (format "Clocking overlap: %d minutes" (/ (- tlend ts) 60))))
  4608. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4609. ;; There is a gap, lets see if we need to report it
  4610. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4611. (setq issue (format "Clocking gap: %d minutes"
  4612. (/ (- ts tlend) 60)))))
  4613. (t nil)))
  4614. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4615. (when issue
  4616. ;; OK, there was some issue, add an overlay to show the issue
  4617. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4618. (overlay-put ov 'before-string
  4619. (concat
  4620. (org-add-props
  4621. (format "%-43s" (concat " " issue))
  4622. nil
  4623. 'face '((:background "DarkRed") (:foreground "white")))
  4624. "\n"))
  4625. (overlay-put ov 'evaporate t)))))
  4626. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4627. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4628. (catch 'exit
  4629. (unless ok-list
  4630. ;; there are no OK times for gaps...
  4631. (throw 'exit nil))
  4632. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4633. ;; This is more than 24 hours, so it is OK.
  4634. ;; because we have at least one OK time, that must be in the
  4635. ;; 24 hour interval.
  4636. (throw 'exit t))
  4637. ;; We have a shorter gap.
  4638. ;; Now we have to get the minute of the day when these times are
  4639. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4640. (t2dec (decode-time (seconds-to-time t2)))
  4641. ;; compute the minute on the day
  4642. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4643. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4644. (when (< min2 min1)
  4645. ;; if min2 is smaller than min1, this means it is on the next day.
  4646. ;; Wrap it to after midnight.
  4647. (setq min2 (+ min2 1440)))
  4648. ;; Now check if any of the OK times is in the gap
  4649. (mapcar (lambda (x)
  4650. ;; Wrap the time to after midnight if necessary
  4651. (if (< x min1) (setq x (+ x 1440)))
  4652. ;; Check if in interval
  4653. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4654. ok-list)
  4655. ;; Nope, this gap is not OK
  4656. nil)))
  4657. (defun org-agenda-get-deadlines ()
  4658. "Return the deadline information for agenda display."
  4659. (let* ((props (list 'mouse-face 'highlight
  4660. 'org-not-done-regexp org-not-done-regexp
  4661. 'org-todo-regexp org-todo-regexp
  4662. 'org-complex-heading-regexp org-complex-heading-regexp
  4663. 'help-echo
  4664. (format "mouse-2 or RET jump to org file %s"
  4665. (abbreviate-file-name buffer-file-name))))
  4666. (regexp org-deadline-time-regexp)
  4667. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4668. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4669. d2 diff dfrac wdays pos pos1 category tags
  4670. suppress-prewarning
  4671. ee txt head face s todo-state show-all upcomingp donep timestr)
  4672. (goto-char (point-min))
  4673. (while (re-search-forward regexp nil t)
  4674. (setq suppress-prewarning nil)
  4675. (catch :skip
  4676. (org-agenda-skip)
  4677. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4678. (save-match-data
  4679. (string-match org-scheduled-time-regexp
  4680. (buffer-substring (point-at-bol)
  4681. (point-at-eol)))))
  4682. (setq suppress-prewarning
  4683. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4684. org-agenda-skip-deadline-prewarning-if-scheduled
  4685. 0)))
  4686. (setq s (match-string 1)
  4687. txt nil
  4688. pos (1- (match-beginning 1))
  4689. todo-state (save-match-data (org-get-todo-state))
  4690. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4691. (member todo-state
  4692. org-agenda-repeating-timestamp-show-all))
  4693. d2 (org-time-string-to-absolute
  4694. (match-string 1) d1 'past show-all)
  4695. diff (- d2 d1)
  4696. wdays (if suppress-prewarning
  4697. (let ((org-deadline-warning-days suppress-prewarning))
  4698. (org-get-wdays s))
  4699. (org-get-wdays s))
  4700. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4701. upcomingp (and todayp (> diff 0)))
  4702. ;; When to show a deadline in the calendar:
  4703. ;; If the expiration is within wdays warning time.
  4704. ;; Past-due deadlines are only shown on the current date
  4705. (if (and (or (and (<= diff wdays)
  4706. (and todayp (not org-agenda-only-exact-dates)))
  4707. (= diff 0)))
  4708. (save-excursion
  4709. ;; (setq todo-state (org-get-todo-state))
  4710. (setq donep (member todo-state org-done-keywords))
  4711. (if (and donep
  4712. (or org-agenda-skip-deadline-if-done
  4713. (not (= diff 0))))
  4714. (setq txt nil)
  4715. (setq category (org-get-category))
  4716. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4717. (setq txt org-agenda-no-heading-message)
  4718. (goto-char (match-end 0))
  4719. (setq pos1 (match-beginning 0))
  4720. (setq tags (org-get-tags-at pos1))
  4721. (setq head (buffer-substring-no-properties
  4722. (point)
  4723. (progn (skip-chars-forward "^\r\n")
  4724. (point))))
  4725. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4726. (setq timestr
  4727. (concat (substring s (match-beginning 1)) " "))
  4728. (setq timestr 'time))
  4729. (setq txt (org-format-agenda-item
  4730. (if (= diff 0)
  4731. (car org-agenda-deadline-leaders)
  4732. (if (functionp
  4733. (nth 1 org-agenda-deadline-leaders))
  4734. (funcall
  4735. (nth 1 org-agenda-deadline-leaders)
  4736. diff date)
  4737. (format (nth 1 org-agenda-deadline-leaders)
  4738. diff)))
  4739. head category tags
  4740. (if (not (= diff 0)) nil timestr)))))
  4741. (when txt
  4742. (setq face (org-agenda-deadline-face dfrac wdays))
  4743. (org-add-props txt props
  4744. 'org-marker (org-agenda-new-marker pos)
  4745. 'org-hd-marker (org-agenda-new-marker pos1)
  4746. 'priority (+ (- diff)
  4747. (org-get-priority txt))
  4748. 'org-category category
  4749. 'todo-state todo-state
  4750. 'type (if upcomingp "upcoming-deadline" "deadline")
  4751. 'date (if upcomingp date d2)
  4752. 'face (if donep 'org-agenda-done face)
  4753. 'undone-face face 'done-face 'org-agenda-done)
  4754. (push txt ee))))))
  4755. (nreverse ee)))
  4756. (defun org-agenda-deadline-face (fraction &optional wdays)
  4757. "Return the face to displaying a deadline item.
  4758. FRACTION is what fraction of the head-warning time has passed."
  4759. (if (equal wdays 0) (setq fraction 1.))
  4760. (let ((faces org-agenda-deadline-faces) f)
  4761. (catch 'exit
  4762. (while (setq f (pop faces))
  4763. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4764. (defun org-agenda-get-scheduled (&optional deadline-results)
  4765. "Return the scheduled information for agenda display."
  4766. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4767. 'org-todo-regexp org-todo-regexp
  4768. 'org-complex-heading-regexp org-complex-heading-regexp
  4769. 'done-face 'org-agenda-done
  4770. 'mouse-face 'highlight
  4771. 'help-echo
  4772. (format "mouse-2 or RET jump to org file %s"
  4773. (abbreviate-file-name buffer-file-name))))
  4774. (regexp org-scheduled-time-regexp)
  4775. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4776. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4777. mm
  4778. (deadline-position-alist
  4779. (mapcar (lambda (a) (and (setq mm (get-text-property
  4780. 0 'org-hd-marker a))
  4781. (cons (marker-position mm) a)))
  4782. deadline-results))
  4783. d2 diff pos pos1 category tags donep
  4784. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4785. (goto-char (point-min))
  4786. (while (re-search-forward regexp nil t)
  4787. (catch :skip
  4788. (org-agenda-skip)
  4789. (setq s (match-string 1)
  4790. txt nil
  4791. pos (1- (match-beginning 1))
  4792. todo-state (save-match-data (org-get-todo-state))
  4793. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4794. (member todo-state
  4795. org-agenda-repeating-timestamp-show-all))
  4796. d2 (org-time-string-to-absolute
  4797. (match-string 1) d1 'past show-all)
  4798. diff (- d2 d1))
  4799. (setq pastschedp (and todayp (< diff 0)))
  4800. ;; When to show a scheduled item in the calendar:
  4801. ;; If it is on or past the date.
  4802. (when (or (and (< diff 0)
  4803. (< (abs diff) org-scheduled-past-days)
  4804. (and todayp (not org-agenda-only-exact-dates)))
  4805. (= diff 0))
  4806. (save-excursion
  4807. (setq donep (member todo-state org-done-keywords))
  4808. (if (and donep
  4809. (or org-agenda-skip-scheduled-if-done
  4810. (not (= diff 0))
  4811. (and (functionp 'org-is-habit-p)
  4812. (org-is-habit-p))))
  4813. (setq txt nil)
  4814. (setq habitp (and (functionp 'org-is-habit-p)
  4815. (org-is-habit-p)))
  4816. (setq category (org-get-category))
  4817. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4818. (setq txt org-agenda-no-heading-message)
  4819. (goto-char (match-end 0))
  4820. (setq pos1 (match-beginning 0))
  4821. (if habitp
  4822. (if (or (not org-habit-show-habits)
  4823. (and (not todayp)
  4824. org-habit-show-habits-only-for-today))
  4825. (throw :skip nil))
  4826. (if (and
  4827. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4828. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4829. pastschedp))
  4830. (setq mm (assoc pos1 deadline-position-alist)))
  4831. (throw :skip nil)))
  4832. (setq tags (org-get-tags-at))
  4833. (setq head (buffer-substring-no-properties
  4834. (point)
  4835. (progn (skip-chars-forward "^\r\n") (point))))
  4836. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4837. (setq timestr
  4838. (concat (substring s (match-beginning 1)) " "))
  4839. (setq timestr 'time))
  4840. (setq txt (org-format-agenda-item
  4841. (if (= diff 0)
  4842. (car org-agenda-scheduled-leaders)
  4843. (format (nth 1 org-agenda-scheduled-leaders)
  4844. (- 1 diff)))
  4845. head category tags
  4846. (if (not (= diff 0)) nil timestr)
  4847. nil habitp))))
  4848. (when txt
  4849. (setq face
  4850. (cond
  4851. ((and (not habitp) pastschedp)
  4852. 'org-scheduled-previously)
  4853. (todayp 'org-scheduled-today)
  4854. (t 'org-scheduled))
  4855. habitp (and habitp (org-habit-parse-todo)))
  4856. (org-add-props txt props
  4857. 'undone-face face
  4858. 'face (if donep 'org-agenda-done face)
  4859. 'org-marker (org-agenda-new-marker pos)
  4860. 'org-hd-marker (org-agenda-new-marker pos1)
  4861. 'type (if pastschedp "past-scheduled" "scheduled")
  4862. 'date (if pastschedp d2 date)
  4863. 'priority (if habitp
  4864. (org-habit-get-priority habitp)
  4865. (+ 94 (- 5 diff) (org-get-priority txt)))
  4866. 'org-category category
  4867. 'org-habit-p habitp
  4868. 'todo-state todo-state)
  4869. (push txt ee))))))
  4870. (nreverse ee)))
  4871. (defun org-agenda-get-blocks ()
  4872. "Return the date-range information for agenda display."
  4873. (let* ((props (list 'face nil
  4874. 'org-not-done-regexp org-not-done-regexp
  4875. 'org-todo-regexp org-todo-regexp
  4876. 'org-complex-heading-regexp org-complex-heading-regexp
  4877. 'mouse-face 'highlight
  4878. 'help-echo
  4879. (format "mouse-2 or RET jump to org file %s"
  4880. (abbreviate-file-name buffer-file-name))))
  4881. (regexp org-tr-regexp)
  4882. (d0 (calendar-absolute-from-gregorian date))
  4883. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4884. head donep)
  4885. (goto-char (point-min))
  4886. (while (re-search-forward regexp nil t)
  4887. (catch :skip
  4888. (org-agenda-skip)
  4889. (setq pos (point))
  4890. (let ((start-time (match-string 1))
  4891. (end-time (match-string 2)))
  4892. (setq s1 (match-string 1)
  4893. s2 (match-string 2)
  4894. d1 (time-to-days (org-time-string-to-time s1))
  4895. d2 (time-to-days (org-time-string-to-time s2)))
  4896. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4897. ;; Only allow days between the limits, because the normal
  4898. ;; date stamps will catch the limits.
  4899. (save-excursion
  4900. (setq todo-state (org-get-todo-state))
  4901. (setq donep (member todo-state org-done-keywords))
  4902. (if (and donep org-agenda-skip-timestamp-if-done)
  4903. (throw :skip t))
  4904. (setq marker (org-agenda-new-marker (point)))
  4905. (setq category (org-get-category))
  4906. (if (not (re-search-backward "^\\*+ " nil t))
  4907. (setq txt org-agenda-no-heading-message)
  4908. (goto-char (match-beginning 0))
  4909. (setq hdmarker (org-agenda-new-marker (point)))
  4910. (setq tags (org-get-tags-at))
  4911. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4912. (setq head (match-string 1))
  4913. (let ((remove-re
  4914. (if org-agenda-remove-timeranges-from-blocks
  4915. (concat
  4916. "<" (regexp-quote s1) ".*?>"
  4917. "--"
  4918. "<" (regexp-quote s2) ".*?>")
  4919. nil)))
  4920. (setq txt (org-format-agenda-item
  4921. (format
  4922. (nth (if (= d1 d2) 0 1)
  4923. org-agenda-timerange-leaders)
  4924. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4925. head category tags
  4926. (cond ((= d1 d0)
  4927. (concat "<" start-time ">"))
  4928. ((= d2 d0)
  4929. (concat "<" end-time ">"))
  4930. (t nil))
  4931. remove-re))))
  4932. (org-add-props txt props
  4933. 'org-marker marker 'org-hd-marker hdmarker
  4934. 'type "block" 'date date
  4935. 'todo-state todo-state
  4936. 'priority (org-get-priority txt) 'org-category category)
  4937. (push txt ee))))
  4938. (goto-char pos)))
  4939. ;; Sort the entries by expiration date.
  4940. (nreverse ee)))
  4941. ;;; Agenda presentation and sorting
  4942. (defvar org-prefix-has-time nil
  4943. "A flag, set by `org-compile-prefix-format'.
  4944. The flag is set if the currently compiled format contains a `%t'.")
  4945. (defvar org-prefix-has-tag nil
  4946. "A flag, set by `org-compile-prefix-format'.
  4947. The flag is set if the currently compiled format contains a `%T'.")
  4948. (defvar org-prefix-has-effort nil
  4949. "A flag, set by `org-compile-prefix-format'.
  4950. The flag is set if the currently compiled format contains a `%e'.")
  4951. (defvar org-prefix-category-length nil
  4952. "Used by `org-compile-prefix-format' to remember the category field width.")
  4953. (defvar org-prefix-category-max-length nil
  4954. "Used by `org-compile-prefix-format' to remember the category field width.")
  4955. (defun org-agenda-get-category-icon (category)
  4956. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4957. (dolist (entry org-agenda-category-icon-alist)
  4958. (when (org-string-match-p (car entry) category)
  4959. (if (listp (cadr entry))
  4960. (return (cadr entry))
  4961. (return (apply 'create-image (cdr entry)))))))
  4962. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4963. remove-re habitp)
  4964. "Format TXT to be inserted into the agenda buffer.
  4965. In particular, it adds the prefix and corresponding text properties. EXTRA
  4966. must be a string and replaces the `%s' specifier in the prefix format.
  4967. CATEGORY (string, symbol or nil) may be used to overrule the default
  4968. category taken from local variable or file name. It will replace the `%c'
  4969. specifier in the format. DOTIME, when non-nil, indicates that a
  4970. time-of-day should be extracted from TXT for sorting of this entry, and for
  4971. the `%t' specifier in the format. When DOTIME is a string, this string is
  4972. searched for a time before TXT is. TAGS can be the tags of the headline.
  4973. Any match of REMOVE-RE will be removed from TXT."
  4974. (save-match-data
  4975. ;; Diary entries sometimes have extra whitespace at the beginning
  4976. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4977. ;; Fix the tags part in txt
  4978. (setq txt (org-agenda-fix-displayed-tags
  4979. txt tags
  4980. org-agenda-show-inherited-tags
  4981. org-agenda-hide-tags-regexp))
  4982. (let* ((category (or category
  4983. (if (stringp org-category)
  4984. org-category
  4985. (and org-category (symbol-name org-category)))
  4986. (if buffer-file-name
  4987. (file-name-sans-extension
  4988. (file-name-nondirectory buffer-file-name))
  4989. "")))
  4990. (category-icon (org-agenda-get-category-icon category))
  4991. (category-icon (if category-icon
  4992. (propertize " " 'display category-icon)
  4993. ""))
  4994. ;; time, tag, effort are needed for the eval of the prefix format
  4995. (tag (if tags (nth (1- (length tags)) tags) ""))
  4996. time effort neffort
  4997. (ts (if dotime (concat
  4998. (if (stringp dotime) dotime "")
  4999. (and org-agenda-search-headline-for-time txt))))
  5000. (time-of-day (and dotime (org-get-time-of-day ts)))
  5001. stamp plain s0 s1 s2 rtn srp l
  5002. duration thecategory)
  5003. (and (org-mode-p) buffer-file-name
  5004. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5005. (when (and dotime time-of-day)
  5006. ;; Extract starting and ending time and move them to prefix
  5007. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5008. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5009. (setq s0 (match-string 0 ts)
  5010. srp (and stamp (match-end 3))
  5011. s1 (match-string (if plain 1 2) ts)
  5012. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5013. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5014. ;; them, we might want to remove them there to avoid duplication.
  5015. ;; The user can turn this off with a variable.
  5016. (if (and org-prefix-has-time
  5017. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5018. (string-match (concat (regexp-quote s0) " *") txt)
  5019. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5020. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5021. (= (match-beginning 0) 0)
  5022. t))
  5023. (setq txt (replace-match "" nil nil txt))))
  5024. ;; Normalize the time(s) to 24 hour
  5025. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5026. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5027. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5028. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5029. (setq s2
  5030. (org-minutes-to-hh:mm-string
  5031. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5032. ;; Compute the duration
  5033. (when s2
  5034. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5035. (org-hh:mm-string-to-minutes s1)))))
  5036. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5037. txt)
  5038. ;; Tags are in the string
  5039. (if (or (eq org-agenda-remove-tags t)
  5040. (and org-agenda-remove-tags
  5041. org-prefix-has-tag))
  5042. (setq txt (replace-match "" t t txt))
  5043. (setq txt (replace-match
  5044. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5045. (match-string 2 txt))
  5046. t t txt))))
  5047. (when (org-mode-p)
  5048. (setq effort
  5049. (condition-case nil
  5050. (org-get-effort
  5051. (or (get-text-property 0 'org-hd-marker txt)
  5052. (get-text-property 0 'org-marker txt)))
  5053. (error nil)))
  5054. (when effort
  5055. (setq neffort (org-duration-string-to-minutes effort)
  5056. effort (setq effort (concat "[" effort "]" )))))
  5057. (when remove-re
  5058. (while (string-match remove-re txt)
  5059. (setq txt (replace-match "" t t txt))))
  5060. ;; Set org-heading property on `txt' to mark the start of the
  5061. ;; heading.
  5062. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5063. ;; Prepare the variables needed in the eval of the compiled format
  5064. (setq time (cond (s2 (concat
  5065. (org-agenda-time-of-day-to-ampm-maybe s1)
  5066. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5067. (if org-agenda-timegrid-use-ampm " ")))
  5068. (s1 (concat
  5069. (org-agenda-time-of-day-to-ampm-maybe s1)
  5070. (if org-agenda-timegrid-use-ampm
  5071. "........ "
  5072. "......")))
  5073. (t ""))
  5074. extra (or (and (not habitp) extra) "")
  5075. category (if (symbolp category) (symbol-name category) category)
  5076. thecategory (copy-sequence category))
  5077. (if (string-match org-bracket-link-regexp category)
  5078. (progn
  5079. (setq l (if (match-end 3)
  5080. (- (match-end 3) (match-beginning 3))
  5081. (- (match-end 1) (match-beginning 1))))
  5082. (when (< l (or org-prefix-category-length 0))
  5083. (setq category (copy-sequence category))
  5084. (org-add-props category nil
  5085. 'extra-space (make-string
  5086. (- org-prefix-category-length l 1) ?\ ))))
  5087. (if (and org-prefix-category-max-length
  5088. (>= (length category) org-prefix-category-max-length))
  5089. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5090. ;; Evaluate the compiled format
  5091. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5092. ;; And finally add the text properties
  5093. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5094. (org-add-props rtn nil
  5095. 'org-category (if thecategory (downcase thecategory) category)
  5096. 'tags (mapcar 'org-downcase-keep-props tags)
  5097. 'org-highest-priority org-highest-priority
  5098. 'org-lowest-priority org-lowest-priority
  5099. 'time-of-day time-of-day
  5100. 'duration duration
  5101. 'effort effort
  5102. 'effort-minutes neffort
  5103. 'txt txt
  5104. 'time time
  5105. 'extra extra
  5106. 'dotime dotime))))
  5107. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5108. "Remove tags string from TXT, and add a modified list of tags.
  5109. The modified list may contain inherited tags, and tags matched by
  5110. `org-agenda-hide-tags-regexp' will be removed."
  5111. (when (or add-inherited hide-re)
  5112. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5113. (setq txt (substring txt 0 (match-beginning 0))))
  5114. (setq tags
  5115. (delq nil
  5116. (mapcar (lambda (tg)
  5117. (if (or (and hide-re (string-match hide-re tg))
  5118. (and (not add-inherited)
  5119. (get-text-property 0 'inherited tg)))
  5120. nil
  5121. tg))
  5122. tags)))
  5123. (when tags
  5124. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5125. i)
  5126. (setq txt (concat txt " :"
  5127. (mapconcat
  5128. (lambda (x)
  5129. (setq i (get-text-property 0 'inherited x))
  5130. (if (and have-i (not i))
  5131. (progn
  5132. (setq have-i nil)
  5133. (concat ":" x))
  5134. x))
  5135. tags ":")
  5136. (if have-i "::" ":"))))))
  5137. txt)
  5138. (defun org-downcase-keep-props (s)
  5139. (let ((props (text-properties-at 0 s)))
  5140. (setq s (downcase s))
  5141. (add-text-properties 0 (length s) props s)
  5142. s))
  5143. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5144. (defvar org-agenda-sorting-strategy-selected nil)
  5145. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5146. (catch 'exit
  5147. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5148. ((and todayp (member 'today (car org-agenda-time-grid))))
  5149. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5150. ((member 'weekly (car org-agenda-time-grid)))
  5151. (t (throw 'exit list)))
  5152. (let* ((have (delq nil (mapcar
  5153. (lambda (x) (get-text-property 1 'time-of-day x))
  5154. list)))
  5155. (string (nth 1 org-agenda-time-grid))
  5156. (gridtimes (nth 2 org-agenda-time-grid))
  5157. (req (car org-agenda-time-grid))
  5158. (remove (member 'remove-match req))
  5159. new time)
  5160. (if (and (member 'require-timed req) (not have))
  5161. ;; don't show empty grid
  5162. (throw 'exit list))
  5163. (while (setq time (pop gridtimes))
  5164. (unless (and remove (member time have))
  5165. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5166. (push (org-format-agenda-item
  5167. nil string "" nil
  5168. (concat (substring time 0 -2) ":" (substring time -2)))
  5169. new)
  5170. (put-text-property
  5171. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5172. (when (and todayp org-agenda-show-current-time-in-grid)
  5173. (push (org-format-agenda-item
  5174. nil
  5175. org-agenda-current-time-string
  5176. "" nil
  5177. (format-time-string "%H:%M "))
  5178. new)
  5179. (put-text-property
  5180. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5181. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5182. (append new list)
  5183. (append list new)))))
  5184. (defun org-compile-prefix-format (key)
  5185. "Compile the prefix format into a Lisp form that can be evaluated.
  5186. The resulting form is returned and stored in the variable
  5187. `org-prefix-format-compiled'."
  5188. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5189. org-prefix-category-length nil org-prefix-has-effort nil)
  5190. (let ((s (cond
  5191. ((stringp org-agenda-prefix-format)
  5192. org-agenda-prefix-format)
  5193. ((assq key org-agenda-prefix-format)
  5194. (cdr (assq key org-agenda-prefix-format)))
  5195. (t " %-12:c%?-12t% s")))
  5196. (start 0)
  5197. varform vars var e c f opt)
  5198. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5199. s start)
  5200. (setq var (or (cdr (assoc (match-string 4 s)
  5201. '(("c" . category) ("t" . time) ("s" . extra)
  5202. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5203. 'eval)
  5204. c (or (match-string 3 s) "")
  5205. opt (match-beginning 1)
  5206. start (1+ (match-beginning 0)))
  5207. (if (equal var 'time) (setq org-prefix-has-time t))
  5208. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5209. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5210. (setq f (concat "%" (match-string 2 s) "s"))
  5211. (when (equal var 'category)
  5212. (setq org-prefix-category-length
  5213. (floor (abs (string-to-number (match-string 2 s)))))
  5214. (setq org-prefix-category-max-length
  5215. (let ((x (match-string 2 s)))
  5216. (save-match-data
  5217. (if (string-match "\\.[0-9]+" x)
  5218. (string-to-number (substring (match-string 0 x) 1)))))))
  5219. (if (eq var 'eval)
  5220. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5221. (if opt
  5222. (setq varform
  5223. `(if (equal "" ,var)
  5224. ""
  5225. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5226. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5227. (setq s (replace-match "%s" t nil s))
  5228. (push varform vars))
  5229. (setq vars (nreverse vars))
  5230. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5231. (defun org-set-sorting-strategy (key)
  5232. (if (symbolp (car org-agenda-sorting-strategy))
  5233. ;; the old format
  5234. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5235. (setq org-agenda-sorting-strategy-selected
  5236. (or (cdr (assq key org-agenda-sorting-strategy))
  5237. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5238. '(time-up category-keep priority-down)))))
  5239. (defun org-get-time-of-day (s &optional string mod24)
  5240. "Check string S for a time of day.
  5241. If found, return it as a military time number between 0 and 2400.
  5242. If not found, return nil.
  5243. The optional STRING argument forces conversion into a 5 character wide string
  5244. HH:MM."
  5245. (save-match-data
  5246. (when
  5247. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5248. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5249. (let* ((h (string-to-number (match-string 1 s)))
  5250. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5251. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5252. (am-p (equal ampm "am"))
  5253. (h1 (cond ((not ampm) h)
  5254. ((= h 12) (if am-p 0 12))
  5255. (t (+ h (if am-p 0 12)))))
  5256. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5257. (mod h1 24) h1))
  5258. (t0 (+ (* 100 h2) m))
  5259. (t1 (concat (if (>= h1 24) "+" " ")
  5260. (if (and org-agenda-time-leading-zero
  5261. (< t0 1000)) "0" "")
  5262. (if (< t0 100) "0" "")
  5263. (if (< t0 10) "0" "")
  5264. (int-to-string t0))))
  5265. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5266. (defvar org-agenda-before-sorting-filter-function nil
  5267. "Function to be applied to agenda items prior to sorting.
  5268. Prior to sorting also means just before they are inserted into the agenda.
  5269. To aid sorting, you may revisit the original entries and add more text
  5270. properties which will later be used by the sorting functions.
  5271. The function should take a string argument, an agenda line.
  5272. It has access to the text properties in that line, which contain among
  5273. other things, the property `org-hd-marker' that points to the entry
  5274. where the line comes from. Note that not all lines going into the agenda
  5275. have this property, only most.
  5276. The function should return the modified string. It is probably best
  5277. to ONLY change text properties.
  5278. You can also use this function as a filter, by returning nil for lines
  5279. you don't want to have in the agenda at all. For this application, you
  5280. could bind the variable in the options section of a custom command.")
  5281. (defun org-finalize-agenda-entries (list &optional nosort)
  5282. "Sort and concatenate the agenda items."
  5283. (setq list (mapcar 'org-agenda-highlight-todo list))
  5284. (if nosort
  5285. list
  5286. (when org-agenda-before-sorting-filter-function
  5287. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5288. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5289. (defun org-agenda-highlight-todo (x)
  5290. (let ((org-done-keywords org-done-keywords-for-agenda)
  5291. (case-fold-search nil)
  5292. re)
  5293. (if (eq x 'line)
  5294. (save-excursion
  5295. (beginning-of-line 1)
  5296. (setq re (org-get-at-bol 'org-todo-regexp))
  5297. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5298. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5299. (add-text-properties (match-beginning 0) (match-end 1)
  5300. (list 'face (org-get-todo-face 1)))
  5301. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5302. (delete-region (match-beginning 1) (1- (match-end 0)))
  5303. (goto-char (match-beginning 1))
  5304. (insert (format org-agenda-todo-keyword-format s)))))
  5305. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5306. (setq re (get-text-property 0 'org-todo-regexp x))
  5307. (when (and re
  5308. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5309. x (or pl 0)) pl))
  5310. (add-text-properties
  5311. (or (match-end 1) (match-end 0)) (match-end 0)
  5312. (list 'face (org-get-todo-face (match-string 2 x)))
  5313. x)
  5314. (when (match-end 1)
  5315. (setq x (concat (substring x 0 (match-end 1))
  5316. (format org-agenda-todo-keyword-format
  5317. (match-string 2 x))
  5318. (org-add-props " " (text-properties-at 0 x))
  5319. (substring x (match-end 3)))))))
  5320. x)))
  5321. (defsubst org-cmp-priority (a b)
  5322. "Compare the priorities of string A and B."
  5323. (let ((pa (or (get-text-property 1 'priority a) 0))
  5324. (pb (or (get-text-property 1 'priority b) 0)))
  5325. (cond ((> pa pb) +1)
  5326. ((< pa pb) -1)
  5327. (t nil))))
  5328. (defsubst org-cmp-effort (a b)
  5329. "Compare the priorities of string A and B."
  5330. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5331. (ea (or (get-text-property 1 'effort-minutes a) def))
  5332. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5333. (cond ((> ea eb) +1)
  5334. ((< ea eb) -1)
  5335. (t nil))))
  5336. (defsubst org-cmp-category (a b)
  5337. "Compare the string values of categories of strings A and B."
  5338. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5339. (cb (or (get-text-property 1 'org-category b) "")))
  5340. (cond ((string-lessp ca cb) -1)
  5341. ((string-lessp cb ca) +1)
  5342. (t nil))))
  5343. (defsubst org-cmp-todo-state (a b)
  5344. "Compare the todo states of strings A and B."
  5345. (let* ((ma (or (get-text-property 1 'org-marker a)
  5346. (get-text-property 1 'org-hd-marker a)))
  5347. (mb (or (get-text-property 1 'org-marker b)
  5348. (get-text-property 1 'org-hd-marker b)))
  5349. (fa (and ma (marker-buffer ma)))
  5350. (fb (and mb (marker-buffer mb)))
  5351. (todo-kwds
  5352. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5353. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5354. (ta (or (get-text-property 1 'todo-state a) ""))
  5355. (tb (or (get-text-property 1 'todo-state b) ""))
  5356. (la (- (length (member ta todo-kwds))))
  5357. (lb (- (length (member tb todo-kwds))))
  5358. (donepa (member ta org-done-keywords-for-agenda))
  5359. (donepb (member tb org-done-keywords-for-agenda)))
  5360. (cond ((and donepa (not donepb)) -1)
  5361. ((and (not donepa) donepb) +1)
  5362. ((< la lb) -1)
  5363. ((< lb la) +1)
  5364. (t nil))))
  5365. (defsubst org-cmp-alpha (a b)
  5366. "Compare the headlines, alphabetically."
  5367. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5368. (plb (text-property-any 0 (length b) 'org-heading t b))
  5369. (ta (and pla (substring a pla)))
  5370. (tb (and plb (substring b plb))))
  5371. (when pla
  5372. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5373. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5374. (setq ta (substring ta (match-end 0))))
  5375. (setq ta (downcase ta)))
  5376. (when plb
  5377. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5378. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5379. (setq tb (substring tb (match-end 0))))
  5380. (setq tb (downcase tb)))
  5381. (cond ((not ta) +1)
  5382. ((not tb) -1)
  5383. ((string-lessp ta tb) -1)
  5384. ((string-lessp tb ta) +1)
  5385. (t nil))))
  5386. (defsubst org-cmp-tag (a b)
  5387. "Compare the string values of the first tags of A and B."
  5388. (let ((ta (car (last (get-text-property 1 'tags a))))
  5389. (tb (car (last (get-text-property 1 'tags b)))))
  5390. (cond ((not ta) +1)
  5391. ((not tb) -1)
  5392. ((string-lessp ta tb) -1)
  5393. ((string-lessp tb ta) +1)
  5394. (t nil))))
  5395. (defsubst org-cmp-time (a b)
  5396. "Compare the time-of-day values of strings A and B."
  5397. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5398. (ta (or (get-text-property 1 'time-of-day a) def))
  5399. (tb (or (get-text-property 1 'time-of-day b) def)))
  5400. (cond ((< ta tb) -1)
  5401. ((< tb ta) +1)
  5402. (t nil))))
  5403. (defsubst org-cmp-habit-p (a b)
  5404. "Compare the todo states of strings A and B."
  5405. (let ((ha (get-text-property 1 'org-habit-p a))
  5406. (hb (get-text-property 1 'org-habit-p b)))
  5407. (cond ((and ha (not hb)) -1)
  5408. ((and (not ha) hb) +1)
  5409. (t nil))))
  5410. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5411. (defun org-entries-lessp (a b)
  5412. "Predicate for sorting agenda entries."
  5413. ;; The following variables will be used when the form is evaluated.
  5414. ;; So even though the compiler complains, keep them.
  5415. (let* ((ss org-agenda-sorting-strategy-selected)
  5416. (time-up (and (org-em 'time-up 'time-down ss)
  5417. (org-cmp-time a b)))
  5418. (time-down (if time-up (- time-up) nil))
  5419. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5420. (org-cmp-priority a b)))
  5421. (priority-down (if priority-up (- priority-up) nil))
  5422. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5423. (org-cmp-effort a b)))
  5424. (effort-down (if effort-up (- effort-up) nil))
  5425. (category-up (and (or (org-em 'category-up 'category-down ss)
  5426. (memq 'category-keep ss))
  5427. (org-cmp-category a b)))
  5428. (category-down (if category-up (- category-up) nil))
  5429. (category-keep (if category-up +1 nil))
  5430. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5431. (org-cmp-tag a b)))
  5432. (tag-down (if tag-up (- tag-up) nil))
  5433. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5434. (org-cmp-todo-state a b)))
  5435. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5436. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5437. (org-cmp-habit-p a b)))
  5438. (habit-down (if habit-up (- habit-up) nil))
  5439. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5440. (org-cmp-alpha a b)))
  5441. (alpha-down (if alpha-up (- alpha-up) nil))
  5442. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5443. user-defined-up user-defined-down)
  5444. (if (and need-user-cmp org-agenda-cmp-user-defined
  5445. (functionp org-agenda-cmp-user-defined))
  5446. (setq user-defined-up
  5447. (funcall org-agenda-cmp-user-defined a b)
  5448. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5449. (cdr (assoc
  5450. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5451. '((-1 . t) (1 . nil) (nil . nil))))))
  5452. ;;; Agenda restriction lock
  5453. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5454. "Overlay to mark the headline to which agenda commands are restricted.")
  5455. (overlay-put org-agenda-restriction-lock-overlay
  5456. 'face 'org-agenda-restriction-lock)
  5457. (overlay-put org-agenda-restriction-lock-overlay
  5458. 'help-echo "Agendas are currently limited to this subtree.")
  5459. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5460. (defun org-agenda-set-restriction-lock (&optional type)
  5461. "Set restriction lock for agenda, to current subtree or file.
  5462. Restriction will be the file if TYPE is `file', or if type is the
  5463. universal prefix '(4), or if the cursor is before the first headline
  5464. in the file. Otherwise, restriction will be to the current subtree."
  5465. (interactive "P")
  5466. (and (equal type '(4)) (setq type 'file))
  5467. (setq type (cond
  5468. (type type)
  5469. ((org-at-heading-p) 'subtree)
  5470. ((condition-case nil (org-back-to-heading t) (error nil))
  5471. 'subtree)
  5472. (t 'file)))
  5473. (if (eq type 'subtree)
  5474. (progn
  5475. (setq org-agenda-restrict t)
  5476. (setq org-agenda-overriding-restriction 'subtree)
  5477. (put 'org-agenda-files 'org-restrict
  5478. (list (buffer-file-name (buffer-base-buffer))))
  5479. (org-back-to-heading t)
  5480. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5481. (move-marker org-agenda-restrict-begin (point))
  5482. (move-marker org-agenda-restrict-end
  5483. (save-excursion (org-end-of-subtree t)))
  5484. (message "Locking agenda restriction to subtree"))
  5485. (put 'org-agenda-files 'org-restrict
  5486. (list (buffer-file-name (buffer-base-buffer))))
  5487. (setq org-agenda-restrict nil)
  5488. (setq org-agenda-overriding-restriction 'file)
  5489. (move-marker org-agenda-restrict-begin nil)
  5490. (move-marker org-agenda-restrict-end nil)
  5491. (message "Locking agenda restriction to file"))
  5492. (setq current-prefix-arg nil)
  5493. (org-agenda-maybe-redo))
  5494. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5495. "Remove the agenda restriction lock."
  5496. (interactive "P")
  5497. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5498. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5499. (setq org-agenda-overriding-restriction nil)
  5500. (setq org-agenda-restrict nil)
  5501. (put 'org-agenda-files 'org-restrict nil)
  5502. (move-marker org-agenda-restrict-begin nil)
  5503. (move-marker org-agenda-restrict-end nil)
  5504. (setq current-prefix-arg nil)
  5505. (message "Agenda restriction lock removed")
  5506. (or noupdate (org-agenda-maybe-redo)))
  5507. (defun org-agenda-maybe-redo ()
  5508. "If there is any window showing the agenda view, update it."
  5509. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5510. (w0 (selected-window)))
  5511. (when w
  5512. (select-window w)
  5513. (org-agenda-redo)
  5514. (select-window w0)
  5515. (if org-agenda-overriding-restriction
  5516. (message "Agenda view shifted to new %s restriction"
  5517. org-agenda-overriding-restriction)
  5518. (message "Agenda restriction lock removed")))))
  5519. ;;; Agenda commands
  5520. (defun org-agenda-check-type (error &rest types)
  5521. "Check if agenda buffer is of allowed type.
  5522. If ERROR is non-nil, throw an error, otherwise just return nil."
  5523. (if (memq org-agenda-type types)
  5524. t
  5525. (if error
  5526. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5527. nil)))
  5528. (defun org-agenda-quit ()
  5529. "Exit agenda by removing the window or the buffer."
  5530. (interactive)
  5531. (if org-agenda-columns-active
  5532. (org-columns-quit)
  5533. (let ((buf (current-buffer)))
  5534. (if (eq org-agenda-window-setup 'other-frame)
  5535. (progn
  5536. (kill-buffer buf)
  5537. (org-agenda-reset-markers)
  5538. (org-columns-remove-overlays)
  5539. (setq org-agenda-archives-mode nil)
  5540. (delete-frame))
  5541. (and (not (eq org-agenda-window-setup 'current-window))
  5542. (not (one-window-p))
  5543. (delete-window))
  5544. (kill-buffer buf)
  5545. (org-agenda-reset-markers)
  5546. (org-columns-remove-overlays)
  5547. (setq org-agenda-archives-mode nil)))
  5548. ;; Maybe restore the pre-agenda window configuration.
  5549. (and org-agenda-restore-windows-after-quit
  5550. (not (eq org-agenda-window-setup 'other-frame))
  5551. org-pre-agenda-window-conf
  5552. (set-window-configuration org-pre-agenda-window-conf))))
  5553. (defun org-agenda-exit ()
  5554. "Exit agenda by removing the window or the buffer.
  5555. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5556. Org-mode buffers visited directly by the user will not be touched."
  5557. (interactive)
  5558. (org-release-buffers org-agenda-new-buffers)
  5559. (setq org-agenda-new-buffers nil)
  5560. (org-agenda-quit))
  5561. (defun org-agenda-execute (arg)
  5562. "Execute another agenda command, keeping same window.
  5563. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5564. in the agenda."
  5565. (interactive "P")
  5566. (let ((org-agenda-window-setup 'current-window))
  5567. (org-agenda arg)))
  5568. (defun org-agenda-redo ()
  5569. "Rebuild Agenda.
  5570. When this is the global TODO list, a prefix argument will be interpreted."
  5571. (interactive)
  5572. (let* ((org-agenda-keep-modes t)
  5573. (filter org-agenda-filter)
  5574. (preset (get 'org-agenda-filter :preset-filter))
  5575. (org-agenda-filter-while-redo (or filter preset))
  5576. (cols org-agenda-columns-active)
  5577. (line (org-current-line))
  5578. (window-line (- line (org-current-line (window-start))))
  5579. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5580. (put 'org-agenda-filter :preset-filter nil)
  5581. (and cols (org-columns-quit))
  5582. (message "Rebuilding agenda buffer...")
  5583. (org-let lprops '(eval org-agenda-redo-command))
  5584. (setq org-agenda-undo-list nil
  5585. org-agenda-pending-undo-list nil)
  5586. (message "Rebuilding agenda buffer...done")
  5587. (put 'org-agenda-filter :preset-filter preset)
  5588. (and (or filter preset) (org-agenda-filter-apply filter))
  5589. (and cols (interactive-p) (org-agenda-columns))
  5590. (org-goto-line line)
  5591. (recenter window-line)))
  5592. (defvar org-global-tags-completion-table nil)
  5593. (defvar org-agenda-filter-form nil)
  5594. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5595. "Keep only those lines in the agenda buffer that have a specific tag.
  5596. The tag is selected with its fast selection letter, as configured.
  5597. With prefix argument STRIP, remove all lines that do have the tag.
  5598. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5599. used to narrow the search - the interactive user can also press `-' or `+'
  5600. to switch to narrowing."
  5601. (interactive "P")
  5602. (let* ((alist org-tag-alist-for-agenda)
  5603. (tag-chars (mapconcat
  5604. (lambda (x) (if (and (not (symbolp (car x)))
  5605. (cdr x))
  5606. (char-to-string (cdr x))
  5607. ""))
  5608. alist ""))
  5609. (efforts (org-split-string
  5610. (or (cdr (assoc (concat org-effort-property "_ALL")
  5611. org-global-properties))
  5612. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5613. "")))
  5614. (effort-op org-agenda-filter-effort-default-operator)
  5615. (effort-prompt "")
  5616. (inhibit-read-only t)
  5617. (current org-agenda-filter)
  5618. maybe-refresh a n tag)
  5619. (unless char
  5620. (message
  5621. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5622. (if narrow "Narrow" "Filter") tag-chars
  5623. (if org-agenda-auto-exclude-function "[RET], " ""))
  5624. (setq char (read-char)))
  5625. (when (member char '(?+ ?-))
  5626. ;; Narrowing down
  5627. (cond ((equal char ?-) (setq strip t narrow t))
  5628. ((equal char ?+) (setq strip nil narrow t)))
  5629. (message
  5630. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5631. (setq char (read-char)))
  5632. (when (member char '(?< ?> ?= ??))
  5633. ;; An effort operator
  5634. (setq effort-op (char-to-string char))
  5635. (setq alist nil) ; to make sure it will be interpreted as effort.
  5636. (unless (equal char ??)
  5637. (loop for i from 0 to 9 do
  5638. (setq effort-prompt
  5639. (concat
  5640. effort-prompt " ["
  5641. (if (= i 9) "0" (int-to-string (1+ i)))
  5642. "]" (nth i efforts))))
  5643. (message "Effort%s: %s " effort-op effort-prompt)
  5644. (setq char (read-char))
  5645. (when (or (< char ?0) (> char ?9))
  5646. (error "Need 1-9,0 to select effort" ))))
  5647. (when (equal char ?\t)
  5648. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5649. (org-set-local 'org-global-tags-completion-table
  5650. (org-global-tags-completion-table)))
  5651. (let ((completion-ignore-case t))
  5652. (setq tag (org-icompleting-read
  5653. "Tag: " org-global-tags-completion-table))))
  5654. (cond
  5655. ((equal char ?\r)
  5656. (org-agenda-filter-by-tag-show-all)
  5657. (when org-agenda-auto-exclude-function
  5658. (setq org-agenda-filter '())
  5659. (dolist (tag (org-agenda-get-represented-tags))
  5660. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5661. (if modifier
  5662. (push modifier org-agenda-filter))))
  5663. (if (not (null org-agenda-filter))
  5664. (org-agenda-filter-apply org-agenda-filter)))
  5665. (setq maybe-refresh t))
  5666. ((equal char ?/)
  5667. (org-agenda-filter-by-tag-show-all)
  5668. (when (get 'org-agenda-filter :preset-filter)
  5669. (org-agenda-filter-apply org-agenda-filter))
  5670. (setq maybe-refresh t))
  5671. ((or (equal char ?\ )
  5672. (setq a (rassoc char alist))
  5673. (and (>= char ?0) (<= char ?9)
  5674. (setq n (if (= char ?0) 9 (- char ?0 1))
  5675. tag (concat effort-op (nth n efforts))
  5676. a (cons tag nil)))
  5677. (and (= char ??)
  5678. (setq tag "?eff")
  5679. a (cons tag nil))
  5680. (and tag (setq a (cons tag nil))))
  5681. (org-agenda-filter-by-tag-show-all)
  5682. (setq tag (car a))
  5683. (setq org-agenda-filter
  5684. (cons (concat (if strip "-" "+") tag)
  5685. (if narrow current nil)))
  5686. (org-agenda-filter-apply org-agenda-filter)
  5687. (setq maybe-refresh t))
  5688. (t (error "Invalid tag selection character %c" char)))
  5689. (when (and maybe-refresh
  5690. (eq org-agenda-clockreport-mode 'with-filter))
  5691. (org-agenda-redo))))
  5692. (defun org-agenda-get-represented-tags ()
  5693. "Get a list of all tags currently represented in the agenda."
  5694. (let (p tags)
  5695. (save-excursion
  5696. (goto-char (point-min))
  5697. (while (setq p (next-single-property-change (point) 'tags))
  5698. (goto-char p)
  5699. (mapc (lambda (x) (add-to-list 'tags x))
  5700. (get-text-property (point) 'tags))))
  5701. tags))
  5702. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5703. "Refine the current filter. See `org-agenda-filter-by-tag."
  5704. (interactive "P")
  5705. (org-agenda-filter-by-tag strip char 'refine))
  5706. (defun org-agenda-filter-make-matcher ()
  5707. "Create the form that tests a line for the agenda filter."
  5708. (let (f f1)
  5709. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5710. org-agenda-filter))
  5711. (if (member x '("-" "+"))
  5712. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5713. (if (string-match "[<=>?]" x)
  5714. (setq f1 (org-agenda-filter-effort-form x))
  5715. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5716. (if (equal (string-to-char x) ?-)
  5717. (setq f1 (list 'not f1))))
  5718. (push f1 f))
  5719. (cons 'and (nreverse f))))
  5720. (defun org-agenda-filter-effort-form (e)
  5721. "Return the form to compare the effort of the current line with what E says.
  5722. E looks like \"+<2:25\"."
  5723. (let (op)
  5724. (setq e (substring e 1))
  5725. (setq op (string-to-char e) e (substring e 1))
  5726. (setq op (cond ((equal op ?<) '<=)
  5727. ((equal op ?>) '>=)
  5728. ((equal op ??) op)
  5729. (t '=)))
  5730. (list 'org-agenda-compare-effort (list 'quote op)
  5731. (org-duration-string-to-minutes e))))
  5732. (defun org-agenda-compare-effort (op value)
  5733. "Compare the effort of the current line with VALUE, using OP.
  5734. If the line does not have an effort defined, return nil."
  5735. (let ((eff (org-get-at-bol 'effort-minutes)))
  5736. (if (equal op ??)
  5737. (not eff)
  5738. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5739. value))))
  5740. (defun org-agenda-filter-apply (filter)
  5741. "Set FILTER as the new agenda filter and apply it."
  5742. (let (tags)
  5743. (setq org-agenda-filter filter
  5744. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5745. (org-agenda-set-mode-name)
  5746. (save-excursion
  5747. (goto-char (point-min))
  5748. (while (not (eobp))
  5749. (if (org-get-at-bol 'org-marker)
  5750. (progn
  5751. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5752. (if (not (eval org-agenda-filter-form))
  5753. (org-agenda-filter-by-tag-hide-line))
  5754. (beginning-of-line 2))
  5755. (beginning-of-line 2))))
  5756. (if (get-char-property (point) 'invisible)
  5757. (org-agenda-previous-line))))
  5758. (defun org-agenda-filter-by-tag-hide-line ()
  5759. (let (ov)
  5760. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5761. (point-at-eol)))
  5762. (overlay-put ov 'invisible t)
  5763. (overlay-put ov 'type 'tags-filter)
  5764. (push ov org-agenda-filter-overlays)))
  5765. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5766. (setq pos (or pos (point)))
  5767. (save-excursion
  5768. (dolist (ov (overlays-at pos))
  5769. (when (and (overlay-get ov 'invisible)
  5770. (eq (overlay-get ov 'type) 'tags-filter))
  5771. (goto-char pos)
  5772. (if (< (overlay-start ov) (point-at-eol))
  5773. (move-overlay ov (point-at-eol)
  5774. (overlay-end ov)))))))
  5775. (defun org-agenda-filter-by-tag-show-all ()
  5776. (mapc 'delete-overlay org-agenda-filter-overlays)
  5777. (setq org-agenda-filter-overlays nil)
  5778. (setq org-agenda-filter nil)
  5779. (setq org-agenda-filter-form nil)
  5780. (org-agenda-set-mode-name))
  5781. (defun org-agenda-manipulate-query-add ()
  5782. "Manipulate the query by adding a search term with positive selection.
  5783. Positive selection means the term must be matched for selection of an entry."
  5784. (interactive)
  5785. (org-agenda-manipulate-query ?\[))
  5786. (defun org-agenda-manipulate-query-subtract ()
  5787. "Manipulate the query by adding a search term with negative selection.
  5788. Negative selection means term must not be matched for selection of an entry."
  5789. (interactive)
  5790. (org-agenda-manipulate-query ?\]))
  5791. (defun org-agenda-manipulate-query-add-re ()
  5792. "Manipulate the query by adding a search regexp with positive selection.
  5793. Positive selection means the regexp must match for selection of an entry."
  5794. (interactive)
  5795. (org-agenda-manipulate-query ?\{))
  5796. (defun org-agenda-manipulate-query-subtract-re ()
  5797. "Manipulate the query by adding a search regexp with negative selection.
  5798. Negative selection means regexp must not match for selection of an entry."
  5799. (interactive)
  5800. (org-agenda-manipulate-query ?\}))
  5801. (defun org-agenda-manipulate-query (char)
  5802. (cond
  5803. ((memq org-agenda-type '(timeline agenda))
  5804. (let ((org-agenda-include-inactive-timestamps t))
  5805. (org-agenda-redo))
  5806. (message "Display now includes inactive timestamps as well"))
  5807. ((eq org-agenda-type 'search)
  5808. (org-add-to-string
  5809. 'org-agenda-query-string
  5810. (if org-agenda-last-search-view-search-was-boolean
  5811. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5812. (?\{ . " +{}") (?\} . " -{}"))))
  5813. " "))
  5814. (setq org-agenda-redo-command
  5815. (list 'org-search-view
  5816. org-todo-only
  5817. org-agenda-query-string
  5818. (+ (length org-agenda-query-string)
  5819. (if (member char '(?\{ ?\})) 0 1))))
  5820. (set-register org-agenda-query-register org-agenda-query-string)
  5821. (org-agenda-redo))
  5822. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5823. org-agenda-type))))
  5824. (defun org-add-to-string (var string)
  5825. (set var (concat (symbol-value var) string)))
  5826. (defun org-agenda-goto-date (date)
  5827. "Jump to DATE in agenda."
  5828. (interactive (list (let ((org-read-date-prefer-future
  5829. (eval org-agenda-jump-prefer-future)))
  5830. (org-read-date))))
  5831. (org-agenda-list nil date))
  5832. (defun org-agenda-goto-today ()
  5833. "Go to today."
  5834. (interactive)
  5835. (org-agenda-check-type t 'timeline 'agenda)
  5836. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5837. (cond
  5838. (tdpos (goto-char tdpos))
  5839. ((eq org-agenda-type 'agenda)
  5840. (let* ((sd (org-agenda-compute-starting-span
  5841. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5842. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5843. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5844. (org-agenda-redo)
  5845. (org-agenda-find-same-or-today-or-agenda)))
  5846. (t (error "Cannot find today")))))
  5847. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5848. (goto-char
  5849. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5850. (text-property-any (point-min) (point-max) 'org-today t)
  5851. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5852. (point-min))))
  5853. (defun org-agenda-later (arg)
  5854. "Go forward in time by thee current span.
  5855. With prefix ARG, go forward that many times the current span."
  5856. (interactive "p")
  5857. (org-agenda-check-type t 'agenda)
  5858. (let* ((span org-agenda-current-span)
  5859. (sd org-starting-day)
  5860. (greg (calendar-gregorian-from-absolute sd))
  5861. (cnt (org-get-at-bol 'org-day-cnt))
  5862. greg2)
  5863. (cond
  5864. ((eq span 'day)
  5865. (setq sd (+ arg sd)))
  5866. ((eq span 'week)
  5867. (setq sd (+ (* 7 arg) sd)))
  5868. ((eq span 'month)
  5869. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5870. sd (calendar-absolute-from-gregorian greg2))
  5871. (setcar greg2 (1+ (car greg2))))
  5872. ((eq span 'year)
  5873. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5874. sd (calendar-absolute-from-gregorian greg2))
  5875. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5876. (t
  5877. (setq sd (+ (* span arg) sd))))
  5878. (let ((org-agenda-overriding-arguments
  5879. (list (car org-agenda-last-arguments) sd span t)))
  5880. (org-agenda-redo)
  5881. (org-agenda-find-same-or-today-or-agenda cnt))))
  5882. (defun org-agenda-earlier (arg)
  5883. "Go backward in time by the current span.
  5884. With prefix ARG, go backward that many times the current span."
  5885. (interactive "p")
  5886. (org-agenda-later (- arg)))
  5887. (defun org-agenda-view-mode-dispatch ()
  5888. "Call one of the view mode commands."
  5889. (interactive)
  5890. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5891. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5892. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5893. [E]ntryText")
  5894. (let ((a (read-char-exclusive)))
  5895. (case a
  5896. (?\ (call-interactively 'org-agenda-reset-view))
  5897. (?d (call-interactively 'org-agenda-day-view))
  5898. (?w (call-interactively 'org-agenda-week-view))
  5899. (?m (call-interactively 'org-agenda-month-view))
  5900. (?y (call-interactively 'org-agenda-year-view))
  5901. (?l (call-interactively 'org-agenda-log-mode))
  5902. (?L (org-agenda-log-mode '(4)))
  5903. (?c (org-agenda-log-mode 'clockcheck))
  5904. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5905. (?a (call-interactively 'org-agenda-archives-mode))
  5906. (?A (org-agenda-archives-mode 'files))
  5907. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5908. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5909. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5910. (?D (call-interactively 'org-agenda-toggle-diary))
  5911. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5912. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5913. (org-agenda-check-type t 'timeline 'agenda)
  5914. (org-agenda-redo))
  5915. (message "Display now includes inactive timestamps as well"))
  5916. (?q (message "Abort"))
  5917. (otherwise (error "Invalid key" )))))
  5918. (defun org-agenda-reset-view ()
  5919. "Switch to default view for agenda."
  5920. (interactive)
  5921. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5922. (defun org-agenda-day-view (&optional day-of-year)
  5923. "Switch to daily view for agenda.
  5924. With argument DAY-OF-YEAR, switch to that day of the year."
  5925. (interactive "P")
  5926. (org-agenda-change-time-span 'day day-of-year))
  5927. (defun org-agenda-week-view (&optional iso-week)
  5928. "Switch to daily view for agenda.
  5929. With argument ISO-WEEK, switch to the corresponding ISO week.
  5930. If ISO-WEEK has more then 2 digits, only the last two encode the
  5931. week. Any digits before this encode a year. So 200712 means
  5932. week 12 of year 2007. Years in the range 1938-2037 can also be
  5933. written as 2-digit years."
  5934. (interactive "P")
  5935. (org-agenda-change-time-span 'week iso-week))
  5936. (defun org-agenda-month-view (&optional month)
  5937. "Switch to monthly view for agenda.
  5938. With argument MONTH, switch to that month."
  5939. (interactive "P")
  5940. (org-agenda-change-time-span 'month month))
  5941. (defun org-agenda-year-view (&optional year)
  5942. "Switch to yearly view for agenda.
  5943. With argument YEAR, switch to that year.
  5944. If MONTH has more then 2 digits, only the last two encode the
  5945. month. Any digits before this encode a year. So 200712 means
  5946. December year 2007. Years in the range 1938-2037 can also be
  5947. written as 2-digit years."
  5948. (interactive "P")
  5949. (when year
  5950. (setq year (org-small-year-to-year year)))
  5951. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5952. (org-agenda-change-time-span 'year year)
  5953. (error "Abort")))
  5954. (defun org-agenda-change-time-span (span &optional n)
  5955. "Change the agenda view to SPAN.
  5956. SPAN may be `day', `week', `month', `year'."
  5957. (org-agenda-check-type t 'agenda)
  5958. (if (and (not n) (equal org-agenda-current-span span))
  5959. (error "Viewing span is already \"%s\"" span))
  5960. (let* ((sd (or (org-get-at-bol 'day)
  5961. org-starting-day))
  5962. (sd (org-agenda-compute-starting-span sd span n))
  5963. (org-agenda-overriding-arguments
  5964. (or org-agenda-overriding-arguments
  5965. (list (car org-agenda-last-arguments) sd span t))))
  5966. (org-agenda-redo)
  5967. (org-agenda-find-same-or-today-or-agenda))
  5968. (org-agenda-set-mode-name)
  5969. (message "Switched to %s view" span))
  5970. (defun org-agenda-compute-starting-span (sd span &optional n)
  5971. "Compute starting date for agenda.
  5972. SPAN may be `day', `week', `month', `year'. The return value
  5973. is a cons cell with the starting date and the number of days,
  5974. so that the date SD will be in that range."
  5975. (let* ((greg (calendar-gregorian-from-absolute sd))
  5976. (dg (nth 1 greg))
  5977. (mg (car greg))
  5978. (yg (nth 2 greg)))
  5979. (cond
  5980. ((eq span 'day)
  5981. (when n
  5982. (setq sd (+ (calendar-absolute-from-gregorian
  5983. (list mg 1 yg))
  5984. n -1))))
  5985. ((eq span 'week)
  5986. (let* ((nt (calendar-day-of-week
  5987. (calendar-gregorian-from-absolute sd)))
  5988. (d (if org-agenda-start-on-weekday
  5989. (- nt org-agenda-start-on-weekday)
  5990. 0))
  5991. y1)
  5992. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5993. (when n
  5994. (require 'cal-iso)
  5995. (when (> n 99)
  5996. (setq y1 (org-small-year-to-year (/ n 100))
  5997. n (mod n 100)))
  5998. (setq sd
  5999. (calendar-absolute-from-iso
  6000. (list n 1
  6001. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6002. ((eq span 'month)
  6003. (let (y1)
  6004. (when (and n (> n 99))
  6005. (setq y1 (org-small-year-to-year (/ n 100))
  6006. n (mod n 100)))
  6007. (setq sd (calendar-absolute-from-gregorian
  6008. (list (or n mg) 1 (or y1 yg))))))
  6009. ((eq span 'year)
  6010. (setq sd (calendar-absolute-from-gregorian
  6011. (list 1 1 (or n yg))))))
  6012. sd))
  6013. (defun org-agenda-next-date-line (&optional arg)
  6014. "Jump to the next line indicating a date in agenda buffer."
  6015. (interactive "p")
  6016. (org-agenda-check-type t 'agenda 'timeline)
  6017. (beginning-of-line 1)
  6018. ;; This does not work if user makes date format that starts with a blank
  6019. (if (looking-at "^\\S-") (forward-char 1))
  6020. (if (not (re-search-forward "^\\S-" nil t arg))
  6021. (progn
  6022. (backward-char 1)
  6023. (error "No next date after this line in this buffer")))
  6024. (goto-char (match-beginning 0)))
  6025. (defun org-agenda-previous-date-line (&optional arg)
  6026. "Jump to the previous line indicating a date in agenda buffer."
  6027. (interactive "p")
  6028. (org-agenda-check-type t 'agenda 'timeline)
  6029. (beginning-of-line 1)
  6030. (if (not (re-search-backward "^\\S-" nil t arg))
  6031. (error "No previous date before this line in this buffer")))
  6032. ;; Initialize the highlight
  6033. (defvar org-hl (make-overlay 1 1))
  6034. (overlay-put org-hl 'face 'highlight)
  6035. (defun org-highlight (begin end &optional buffer)
  6036. "Highlight a region with overlay."
  6037. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6038. (defun org-unhighlight ()
  6039. "Detach overlay INDEX."
  6040. (org-detach-overlay org-hl))
  6041. ;; FIXME this is currently not used.
  6042. (defun org-highlight-until-next-command (beg end &optional buffer)
  6043. "Move the highlight overlay to BEG/END, remove it before the next command."
  6044. (org-highlight beg end buffer)
  6045. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6046. (defun org-unhighlight-once ()
  6047. "Remove the highlight from its position, and this function from the hook."
  6048. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6049. (org-unhighlight))
  6050. (defun org-agenda-follow-mode ()
  6051. "Toggle follow mode in an agenda buffer."
  6052. (interactive)
  6053. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6054. (org-agenda-set-mode-name)
  6055. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6056. (org-agenda-show))
  6057. (message "Follow mode is %s"
  6058. (if org-agenda-follow-mode "on" "off")))
  6059. (defun org-agenda-entry-text-mode (&optional arg)
  6060. "Toggle entry text mode in an agenda buffer."
  6061. (interactive "P")
  6062. (setq org-agenda-entry-text-mode (or (integerp arg)
  6063. (not org-agenda-entry-text-mode)))
  6064. (org-agenda-entry-text-hide)
  6065. (and org-agenda-entry-text-mode
  6066. (let ((org-agenda-entry-text-maxlines
  6067. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6068. (org-agenda-entry-text-show)))
  6069. (org-agenda-set-mode-name)
  6070. (message "Entry text mode is %s. Maximum number of lines is %d"
  6071. (if org-agenda-entry-text-mode "on" "off")
  6072. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6073. (defun org-agenda-clockreport-mode (&optional with-filter)
  6074. "Toggle clocktable mode in an agenda buffer.
  6075. With prefix arg WITH-FILTER, make the clocktable respect the current
  6076. agenda filter."
  6077. (interactive "P")
  6078. (org-agenda-check-type t 'agenda)
  6079. (if with-filter
  6080. (setq org-agenda-clockreport-mode 'with-filter)
  6081. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6082. (org-agenda-set-mode-name)
  6083. (org-agenda-redo)
  6084. (message "Clocktable mode is %s"
  6085. (if org-agenda-clockreport-mode "on" "off")))
  6086. (defun org-agenda-log-mode (&optional special)
  6087. "Toggle log mode in an agenda buffer.
  6088. With argument SPECIAL, show all possible log items, not only the ones
  6089. configured in `org-agenda-log-mode-items'.
  6090. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6091. (interactive "P")
  6092. (org-agenda-check-type t 'agenda 'timeline)
  6093. (setq org-agenda-show-log
  6094. (cond
  6095. ((equal special '(16)) 'only)
  6096. ((eq special 'clockcheck)
  6097. (if (eq org-agenda-show-log 'clockcheck)
  6098. nil 'clockcheck))
  6099. (special '(closed clock state))
  6100. (t (not org-agenda-show-log))))
  6101. (org-agenda-set-mode-name)
  6102. (org-agenda-redo)
  6103. (message "Log mode is %s"
  6104. (if org-agenda-show-log "on" "off")))
  6105. (defun org-agenda-archives-mode (&optional with-files)
  6106. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6107. When called with a prefix argument, include all archive files as well."
  6108. (interactive "P")
  6109. (setq org-agenda-archives-mode
  6110. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6111. (org-agenda-set-mode-name)
  6112. (org-agenda-redo)
  6113. (message
  6114. "%s"
  6115. (cond
  6116. ((eq org-agenda-archives-mode nil)
  6117. "No archives are included")
  6118. ((eq org-agenda-archives-mode 'trees)
  6119. (format "Trees with :%s: tag are included" org-archive-tag))
  6120. ((eq org-agenda-archives-mode t)
  6121. (format "Trees with :%s: tag and all active archive files are included"
  6122. org-archive-tag)))))
  6123. (defun org-agenda-toggle-diary ()
  6124. "Toggle diary inclusion in an agenda buffer."
  6125. (interactive)
  6126. (org-agenda-check-type t 'agenda)
  6127. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6128. (org-agenda-redo)
  6129. (org-agenda-set-mode-name)
  6130. (message "Diary inclusion turned %s"
  6131. (if org-agenda-include-diary "on" "off")))
  6132. (defun org-agenda-toggle-deadlines ()
  6133. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6134. (interactive)
  6135. (org-agenda-check-type t 'agenda)
  6136. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6137. (org-agenda-redo)
  6138. (org-agenda-set-mode-name)
  6139. (message "Deadlines inclusion turned %s"
  6140. (if org-agenda-include-deadlines "on" "off")))
  6141. (defun org-agenda-toggle-time-grid ()
  6142. "Toggle time grid in an agenda buffer."
  6143. (interactive)
  6144. (org-agenda-check-type t 'agenda)
  6145. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6146. (org-agenda-redo)
  6147. (org-agenda-set-mode-name)
  6148. (message "Time-grid turned %s"
  6149. (if org-agenda-use-time-grid "on" "off")))
  6150. (defun org-agenda-set-mode-name ()
  6151. "Set the mode name to indicate all the small mode settings."
  6152. (setq mode-name
  6153. (list "Org-Agenda"
  6154. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6155. " "
  6156. '(:eval (org-agenda-span-name org-agenda-current-span))
  6157. (if org-agenda-follow-mode " Follow" "")
  6158. (if org-agenda-entry-text-mode " ETxt" "")
  6159. (if org-agenda-include-diary " Diary" "")
  6160. (if org-agenda-include-deadlines " Ddl" "")
  6161. (if org-agenda-use-time-grid " Grid" "")
  6162. (if (and (boundp 'org-habit-show-habits)
  6163. org-habit-show-habits) " Habit" "")
  6164. (cond
  6165. ((consp org-agenda-show-log) " LogAll")
  6166. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6167. (org-agenda-show-log " Log")
  6168. (t ""))
  6169. (if (or org-agenda-filter (get 'org-agenda-filter
  6170. :preset-filter))
  6171. (concat " {" (mapconcat
  6172. 'identity
  6173. (append (get 'org-agenda-filter
  6174. :preset-filter)
  6175. org-agenda-filter) "") "}")
  6176. "")
  6177. (if org-agenda-archives-mode
  6178. (if (eq org-agenda-archives-mode t)
  6179. " Archives"
  6180. (format " :%s:" org-archive-tag))
  6181. "")
  6182. (if org-agenda-clockreport-mode
  6183. (if (eq org-agenda-clockreport-mode 'with-filter)
  6184. " Clock{}" " Clock")
  6185. "")))
  6186. (force-mode-line-update))
  6187. (defun org-agenda-post-command-hook ()
  6188. (setq org-agenda-type
  6189. (or (get-text-property (point) 'org-agenda-type)
  6190. (get-text-property (max (point-min) (1- (point)))
  6191. 'org-agenda-type))))
  6192. (defun org-agenda-next-line ()
  6193. "Move cursor to the next line, and show if follow mode is active."
  6194. (interactive)
  6195. (call-interactively 'next-line)
  6196. (org-agenda-do-context-action))
  6197. (defun org-agenda-previous-line ()
  6198. "Move cursor to the previous line, and show if follow-mode is active."
  6199. (interactive)
  6200. (call-interactively 'previous-line)
  6201. (org-agenda-do-context-action))
  6202. (defun org-agenda-do-context-action ()
  6203. "Show outline path and, maybe, follow mode window."
  6204. (let ((m (org-get-at-bol 'org-marker)))
  6205. (if (and org-agenda-follow-mode m)
  6206. (org-agenda-show))
  6207. (if (and m org-agenda-show-outline-path)
  6208. (org-with-point-at m
  6209. (org-display-outline-path t)))))
  6210. (defun org-agenda-show-priority ()
  6211. "Show the priority of the current item.
  6212. This priority is composed of the main priority given with the [#A] cookies,
  6213. and by additional input from the age of a schedules or deadline entry."
  6214. (interactive)
  6215. (let* ((pri (org-get-at-bol 'priority)))
  6216. (message "Priority is %d" (if pri pri -1000))))
  6217. (defun org-agenda-show-tags ()
  6218. "Show the tags applicable to the current item."
  6219. (interactive)
  6220. (let* ((tags (org-get-at-bol 'tags)))
  6221. (if tags
  6222. (message "Tags are :%s:"
  6223. (org-no-properties (mapconcat 'identity tags ":")))
  6224. (message "No tags associated with this line"))))
  6225. (defun org-agenda-goto (&optional highlight)
  6226. "Go to the Org-mode file which contains the item at point."
  6227. (interactive)
  6228. (let* ((marker (or (org-get-at-bol 'org-marker)
  6229. (org-agenda-error)))
  6230. (buffer (marker-buffer marker))
  6231. (pos (marker-position marker)))
  6232. (switch-to-buffer-other-window buffer)
  6233. (widen)
  6234. (push-mark)
  6235. (goto-char pos)
  6236. (when (org-mode-p)
  6237. (org-show-context 'agenda)
  6238. (save-excursion
  6239. (and (outline-next-heading)
  6240. (org-flag-heading nil)))) ; show the next heading
  6241. (when (outline-invisible-p)
  6242. (show-entry)) ; display invisible text
  6243. (recenter (/ (window-height) 2))
  6244. (run-hooks 'org-agenda-after-show-hook)
  6245. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6246. (defvar org-agenda-after-show-hook nil
  6247. "Normal hook run after an item has been shown from the agenda.
  6248. Point is in the buffer where the item originated.")
  6249. (defun org-agenda-kill ()
  6250. "Kill the entry or subtree belonging to the current agenda entry."
  6251. (interactive)
  6252. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6253. (let* ((marker (or (org-get-at-bol 'org-marker)
  6254. (org-agenda-error)))
  6255. (buffer (marker-buffer marker))
  6256. (pos (marker-position marker))
  6257. (type (org-get-at-bol 'type))
  6258. dbeg dend (n 0) conf)
  6259. (org-with-remote-undo buffer
  6260. (with-current-buffer buffer
  6261. (save-excursion
  6262. (goto-char pos)
  6263. (if (and (org-mode-p) (not (member type '("sexp"))))
  6264. (setq dbeg (progn (org-back-to-heading t) (point))
  6265. dend (org-end-of-subtree t t))
  6266. (setq dbeg (point-at-bol)
  6267. dend (min (point-max) (1+ (point-at-eol)))))
  6268. (goto-char dbeg)
  6269. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6270. (setq conf (or (eq t org-agenda-confirm-kill)
  6271. (and (numberp org-agenda-confirm-kill)
  6272. (> n org-agenda-confirm-kill))))
  6273. (and conf
  6274. (not (y-or-n-p
  6275. (format "Delete entry with %d lines in buffer \"%s\"? "
  6276. n (buffer-name buffer))))
  6277. (error "Abort"))
  6278. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6279. (with-current-buffer buffer (delete-region dbeg dend))
  6280. (message "Agenda item and source killed"))))
  6281. (defvar org-archive-default-command)
  6282. (defun org-agenda-archive-default ()
  6283. "Archive the entry or subtree belonging to the current agenda entry."
  6284. (interactive)
  6285. (require 'org-archive)
  6286. (org-agenda-archive-with org-archive-default-command))
  6287. (defun org-agenda-archive-default-with-confirmation ()
  6288. "Archive the entry or subtree belonging to the current agenda entry."
  6289. (interactive)
  6290. (require 'org-archive)
  6291. (org-agenda-archive-with org-archive-default-command 'confirm))
  6292. (defun org-agenda-archive ()
  6293. "Archive the entry or subtree belonging to the current agenda entry."
  6294. (interactive)
  6295. (org-agenda-archive-with 'org-archive-subtree))
  6296. (defun org-agenda-archive-to-archive-sibling ()
  6297. "Move the entry to the archive sibling."
  6298. (interactive)
  6299. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6300. (defun org-agenda-archive-with (cmd &optional confirm)
  6301. "Move the entry to the archive sibling."
  6302. (interactive)
  6303. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6304. (let* ((marker (or (org-get-at-bol 'org-marker)
  6305. (org-agenda-error)))
  6306. (buffer (marker-buffer marker))
  6307. (pos (marker-position marker)))
  6308. (org-with-remote-undo buffer
  6309. (with-current-buffer buffer
  6310. (if (org-mode-p)
  6311. (if (and confirm
  6312. (not (y-or-n-p "Archive this subtree or entry? ")))
  6313. (error "Abort")
  6314. (save-excursion
  6315. (goto-char pos)
  6316. (org-remove-subtree-entries-from-agenda)
  6317. (org-back-to-heading t)
  6318. (funcall cmd)))
  6319. (error "Archiving works only in Org-mode files"))))))
  6320. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6321. "Remove all lines in the agenda that correspond to a given subtree.
  6322. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6323. If this information is not given, the function uses the tree at point."
  6324. (let ((buf (or buf (current-buffer))) m p)
  6325. (save-excursion
  6326. (unless (and beg end)
  6327. (org-back-to-heading t)
  6328. (setq beg (point))
  6329. (org-end-of-subtree t)
  6330. (setq end (point)))
  6331. (set-buffer (get-buffer org-agenda-buffer-name))
  6332. (save-excursion
  6333. (goto-char (point-max))
  6334. (beginning-of-line 1)
  6335. (while (not (bobp))
  6336. (when (and (setq m (org-get-at-bol 'org-marker))
  6337. (equal buf (marker-buffer m))
  6338. (setq p (marker-position m))
  6339. (>= p beg)
  6340. (< p end))
  6341. (let ((inhibit-read-only t))
  6342. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6343. (beginning-of-line 0))))))
  6344. (defun org-agenda-refile (&optional goto rfloc no-update)
  6345. "Refile the item at point."
  6346. (interactive "P")
  6347. (if (equal goto '(16))
  6348. (org-refile-goto-last-stored)
  6349. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6350. (org-agenda-error)))
  6351. (buffer (marker-buffer marker))
  6352. (pos (marker-position marker))
  6353. (rfloc (or rfloc
  6354. (org-refile-get-location
  6355. (if goto "Goto" "Refile to") buffer
  6356. org-refile-allow-creating-parent-nodes))))
  6357. (with-current-buffer buffer
  6358. (save-excursion
  6359. (save-restriction
  6360. (widen)
  6361. (goto-char marker)
  6362. (org-remove-subtree-entries-from-agenda)
  6363. (org-refile goto buffer rfloc)))))
  6364. (unless no-update (org-agenda-redo))))
  6365. (defun org-agenda-open-link (&optional arg)
  6366. "Follow the link in the current line, if any.
  6367. This looks for a link in the displayed line in the agenda. It also looks
  6368. at the text of the entry itself."
  6369. (interactive "P")
  6370. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6371. (org-get-at-bol 'org-marker)))
  6372. (buffer (and marker (marker-buffer marker)))
  6373. (prefix (buffer-substring
  6374. (point-at-bol)
  6375. (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6376. (point-at-bol)))))
  6377. (cond
  6378. (buffer
  6379. (with-current-buffer buffer
  6380. (save-excursion
  6381. (save-restriction
  6382. (widen)
  6383. (goto-char marker)
  6384. (org-offer-links-in-entry arg prefix)))))
  6385. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6386. (save-excursion
  6387. (beginning-of-line 1)
  6388. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6389. (org-open-link-from-string (match-string 1)))
  6390. (t (error "No link to open here")))))
  6391. (defun org-agenda-copy-local-variable (var)
  6392. "Get a variable from a referenced buffer and install it here."
  6393. (let ((m (org-get-at-bol 'org-marker)))
  6394. (when (and m (buffer-live-p (marker-buffer m)))
  6395. (org-set-local var (with-current-buffer (marker-buffer m)
  6396. (symbol-value var))))))
  6397. (defun org-agenda-switch-to (&optional delete-other-windows)
  6398. "Go to the Org-mode file which contains the item at point."
  6399. (interactive)
  6400. (if (and org-return-follows-link
  6401. (not (org-get-at-bol 'org-marker))
  6402. (org-in-regexp org-bracket-link-regexp))
  6403. (org-open-link-from-string (match-string 0))
  6404. (let* ((marker (or (org-get-at-bol 'org-marker)
  6405. (org-agenda-error)))
  6406. (buffer (marker-buffer marker))
  6407. (pos (marker-position marker)))
  6408. (switch-to-buffer buffer)
  6409. (and delete-other-windows (delete-other-windows))
  6410. (widen)
  6411. (goto-char pos)
  6412. (when (org-mode-p)
  6413. (org-show-context 'agenda)
  6414. (save-excursion
  6415. (and (outline-next-heading)
  6416. (org-flag-heading nil))) ; show the next heading
  6417. (when (outline-invisible-p)
  6418. (show-entry)))))) ; display invisible text
  6419. (defun org-agenda-goto-mouse (ev)
  6420. "Go to the Org-mode file which contains the item at the mouse click."
  6421. (interactive "e")
  6422. (mouse-set-point ev)
  6423. (org-agenda-goto))
  6424. (defun org-agenda-show (&optional full-entry)
  6425. "Display the Org-mode file which contains the item at point.
  6426. With prefix argument FULL-ENTRY, make the entire entry visible
  6427. if it was hidden in the outline."
  6428. (interactive "P")
  6429. (let ((win (selected-window)))
  6430. (if full-entry
  6431. (let ((org-show-entry-below t))
  6432. (org-agenda-goto t))
  6433. (org-agenda-goto t))
  6434. (select-window win)))
  6435. (defvar org-agenda-show-window nil)
  6436. (defun org-agenda-show-and-scroll-up ()
  6437. "Display the Org-mode file which contains the item at point.
  6438. When called repeatedly, scroll the window that is displaying the buffer."
  6439. (interactive)
  6440. (let ((win (selected-window)))
  6441. (if (and (window-live-p org-agenda-show-window)
  6442. (eq this-command last-command))
  6443. (progn
  6444. (select-window org-agenda-show-window)
  6445. (ignore-errors (scroll-up)))
  6446. (org-agenda-goto t)
  6447. (show-subtree)
  6448. (setq org-agenda-show-window (selected-window)))
  6449. (select-window win)))
  6450. (defun org-agenda-show-scroll-down ()
  6451. "Scroll down the window showing the agenda."
  6452. (interactive)
  6453. (let ((win (selected-window)))
  6454. (when (window-live-p org-agenda-show-window)
  6455. (select-window org-agenda-show-window)
  6456. (ignore-errors (scroll-down))
  6457. (select-window win))))
  6458. (defun org-agenda-show-1 (&optional more)
  6459. "Display the Org-mode file which contains the item at point.
  6460. The prefix arg selects the amount of information to display:
  6461. 0 hide the subtree
  6462. 1 just show the entry according to defaults.
  6463. 2 show the children view
  6464. 3 show the subtree view
  6465. 4 show the entire subtree and any LOGBOOK drawers
  6466. 5 show the entire subtree and any drawers
  6467. With prefix argument FULL-ENTRY, make the entire entry visible
  6468. if it was hidden in the outline."
  6469. (interactive "p")
  6470. (let ((win (selected-window)))
  6471. (org-agenda-goto t)
  6472. (org-recenter-heading 1)
  6473. (cond
  6474. ((= more 0)
  6475. (hide-subtree)
  6476. (save-excursion
  6477. (org-back-to-heading)
  6478. (run-hook-with-args 'org-cycle-hook 'folded))
  6479. (message "Remote: FOLDED"))
  6480. ((and (interactive-p) (= more 1))
  6481. (message "Remote: show with default settings"))
  6482. ((= more 2)
  6483. (show-entry)
  6484. (show-children)
  6485. (save-excursion
  6486. (org-back-to-heading)
  6487. (run-hook-with-args 'org-cycle-hook 'children))
  6488. (message "Remote: CHILDREN"))
  6489. ((= more 3)
  6490. (show-subtree)
  6491. (save-excursion
  6492. (org-back-to-heading)
  6493. (run-hook-with-args 'org-cycle-hook 'subtree))
  6494. (message "Remote: SUBTREE"))
  6495. ((= more 4)
  6496. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6497. (org-drawer-regexp
  6498. (concat "^[ \t]*:\\("
  6499. (mapconcat 'regexp-quote org-drawers "\\|")
  6500. "\\):[ \t]*$")))
  6501. (show-subtree)
  6502. (save-excursion
  6503. (org-back-to-heading)
  6504. (org-cycle-hide-drawers 'subtree)))
  6505. (message "Remote: SUBTREE AND LOGBOOK"))
  6506. ((> more 4)
  6507. (show-subtree)
  6508. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6509. (select-window win)))
  6510. (defun org-recenter-heading (n)
  6511. (save-excursion
  6512. (org-back-to-heading)
  6513. (recenter n)))
  6514. (defvar org-agenda-cycle-counter nil)
  6515. (defun org-agenda-cycle-show (&optional n)
  6516. "Show the current entry in another window, with default settings.
  6517. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6518. When use repeatedly in immediate succession, the remote entry will cycle
  6519. through visibility
  6520. children -> subtree -> folded
  6521. When called with a numeric prefix arg, that arg will be passed through to
  6522. `org-agenda-show-1'. For the interpretation of that argument, see the
  6523. docstring of `org-agenda-show-1'."
  6524. (interactive "P")
  6525. (if (integerp n)
  6526. (setq org-agenda-cycle-counter n)
  6527. (if (not (eq last-command this-command))
  6528. (setq org-agenda-cycle-counter 1)
  6529. (if (equal org-agenda-cycle-counter 0)
  6530. (setq org-agenda-cycle-counter 2)
  6531. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6532. (if (> org-agenda-cycle-counter 3)
  6533. (setq org-agenda-cycle-counter 0)))))
  6534. (org-agenda-show-1 org-agenda-cycle-counter))
  6535. (defun org-agenda-recenter (arg)
  6536. "Display the Org-mode file which contains the item at point and recenter."
  6537. (interactive "P")
  6538. (let ((win (selected-window)))
  6539. (org-agenda-goto t)
  6540. (recenter arg)
  6541. (select-window win)))
  6542. (defun org-agenda-show-mouse (ev)
  6543. "Display the Org-mode file which contains the item at the mouse click."
  6544. (interactive "e")
  6545. (mouse-set-point ev)
  6546. (org-agenda-show))
  6547. (defun org-agenda-check-no-diary ()
  6548. "Check if the entry is a diary link and abort if yes."
  6549. (if (org-get-at-bol 'org-agenda-diary-link)
  6550. (org-agenda-error)))
  6551. (defun org-agenda-error ()
  6552. (error "Command not allowed in this line"))
  6553. (defun org-agenda-tree-to-indirect-buffer ()
  6554. "Show the subtree corresponding to the current entry in an indirect buffer.
  6555. This calls the command `org-tree-to-indirect-buffer' from the original
  6556. Org-mode buffer.
  6557. With numerical prefix arg ARG, go up to this level and then take that tree.
  6558. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6559. use the dedicated frame)."
  6560. (interactive)
  6561. (org-agenda-check-no-diary)
  6562. (let* ((marker (or (org-get-at-bol 'org-marker)
  6563. (org-agenda-error)))
  6564. (buffer (marker-buffer marker))
  6565. (pos (marker-position marker)))
  6566. (with-current-buffer buffer
  6567. (save-excursion
  6568. (goto-char pos)
  6569. (call-interactively 'org-tree-to-indirect-buffer)))))
  6570. (defvar org-last-heading-marker (make-marker)
  6571. "Marker pointing to the headline that last changed its TODO state
  6572. by a remote command from the agenda.")
  6573. (defun org-agenda-todo-nextset ()
  6574. "Switch TODO entry to next sequence."
  6575. (interactive)
  6576. (org-agenda-todo 'nextset))
  6577. (defun org-agenda-todo-previousset ()
  6578. "Switch TODO entry to previous sequence."
  6579. (interactive)
  6580. (org-agenda-todo 'previousset))
  6581. (defun org-agenda-todo (&optional arg)
  6582. "Cycle TODO state of line at point, also in Org-mode file.
  6583. This changes the line at point, all other lines in the agenda referring to
  6584. the same tree node, and the headline of the tree node in the Org-mode file."
  6585. (interactive "P")
  6586. (org-agenda-check-no-diary)
  6587. (let* ((col (current-column))
  6588. (marker (or (org-get-at-bol 'org-marker)
  6589. (org-agenda-error)))
  6590. (buffer (marker-buffer marker))
  6591. (pos (marker-position marker))
  6592. (hdmarker (org-get-at-bol 'org-hd-marker))
  6593. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6594. (inhibit-read-only t)
  6595. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6596. (org-with-remote-undo buffer
  6597. (with-current-buffer buffer
  6598. (widen)
  6599. (goto-char pos)
  6600. (org-show-context 'agenda)
  6601. (save-excursion
  6602. (and (outline-next-heading)
  6603. (org-flag-heading nil))) ; show the next heading
  6604. (let ((current-prefix-arg arg))
  6605. (call-interactively 'org-todo))
  6606. (and (bolp) (forward-char 1))
  6607. (setq newhead (org-get-heading))
  6608. (when (and (org-bound-and-true-p
  6609. org-agenda-headline-snapshot-before-repeat)
  6610. (not (equal org-agenda-headline-snapshot-before-repeat
  6611. newhead))
  6612. todayp)
  6613. (setq newhead org-agenda-headline-snapshot-before-repeat
  6614. just-one t))
  6615. (save-excursion
  6616. (org-back-to-heading)
  6617. (move-marker org-last-heading-marker (point))))
  6618. (beginning-of-line 1)
  6619. (save-excursion
  6620. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6621. (org-move-to-column col))))
  6622. (defun org-agenda-add-note (&optional arg)
  6623. "Add a time-stamped note to the entry at point."
  6624. (interactive "P")
  6625. (org-agenda-check-no-diary)
  6626. (let* ((marker (or (org-get-at-bol 'org-marker)
  6627. (org-agenda-error)))
  6628. (buffer (marker-buffer marker))
  6629. (pos (marker-position marker))
  6630. (hdmarker (org-get-at-bol 'org-hd-marker))
  6631. (inhibit-read-only t))
  6632. (with-current-buffer buffer
  6633. (widen)
  6634. (goto-char pos)
  6635. (org-show-context 'agenda)
  6636. (save-excursion
  6637. (and (outline-next-heading)
  6638. (org-flag-heading nil))) ; show the next heading
  6639. (org-add-note))))
  6640. (defun org-agenda-change-all-lines (newhead hdmarker
  6641. &optional fixface just-this)
  6642. "Change all lines in the agenda buffer which match HDMARKER.
  6643. The new content of the line will be NEWHEAD (as modified by
  6644. `org-format-agenda-item'). HDMARKER is checked with
  6645. `equal' against all `org-hd-marker' text properties in the file.
  6646. If FIXFACE is non-nil, the face of each item is modified according to
  6647. the new TODO state.
  6648. If JUST-THIS is non-nil, change just the current line, not all.
  6649. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6650. (let* ((inhibit-read-only t)
  6651. (line (org-current-line))
  6652. (thetags (with-current-buffer (marker-buffer hdmarker)
  6653. (save-excursion (save-restriction (widen)
  6654. (goto-char hdmarker)
  6655. (org-get-tags-at)))))
  6656. props m pl undone-face done-face finish new dotime cat tags)
  6657. (save-excursion
  6658. (goto-char (point-max))
  6659. (beginning-of-line 1)
  6660. (while (not finish)
  6661. (setq finish (bobp))
  6662. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6663. (or (not just-this) (= (org-current-line) line))
  6664. (equal m hdmarker))
  6665. (setq props (text-properties-at (point))
  6666. dotime (org-get-at-bol 'dotime)
  6667. cat (org-get-at-bol 'org-category)
  6668. tags thetags
  6669. new (org-format-agenda-item (org-get-at-bol 'extra)
  6670. newhead cat tags dotime)
  6671. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6672. undone-face (org-get-at-bol 'undone-face)
  6673. done-face (org-get-at-bol 'done-face))
  6674. (beginning-of-line 1)
  6675. (cond
  6676. ((equal new "")
  6677. (and (looking-at ".*\n?") (replace-match "")))
  6678. ((looking-at ".*")
  6679. (replace-match new t t)
  6680. (beginning-of-line 1)
  6681. (add-text-properties (point-at-bol) (point-at-eol) props)
  6682. (when fixface
  6683. (add-text-properties
  6684. (point-at-bol) (point-at-eol)
  6685. (list 'face
  6686. (if org-last-todo-state-is-todo
  6687. undone-face done-face))))
  6688. (org-agenda-highlight-todo 'line)
  6689. (beginning-of-line 1))
  6690. (t (error "Line update did not work"))))
  6691. (beginning-of-line 0)))
  6692. (org-finalize-agenda)))
  6693. (defun org-agenda-align-tags (&optional line)
  6694. "Align all tags in agenda items to `org-agenda-tags-column'."
  6695. (let ((inhibit-read-only t) l c)
  6696. (save-excursion
  6697. (goto-char (if line (point-at-bol) (point-min)))
  6698. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6699. (if line (point-at-eol) nil) t)
  6700. (add-text-properties
  6701. (match-beginning 2) (match-end 2)
  6702. (list 'face (delq nil (let ((prop (get-text-property
  6703. (match-beginning 2) 'face)))
  6704. (or (listp prop) (setq prop (list prop)))
  6705. (if (memq 'org-tag prop)
  6706. prop
  6707. (cons 'org-tag prop))))))
  6708. (setq l (- (match-end 2) (match-beginning 2))
  6709. c (if (< org-agenda-tags-column 0)
  6710. (- (abs org-agenda-tags-column) l)
  6711. org-agenda-tags-column))
  6712. (delete-region (match-beginning 1) (match-end 1))
  6713. (goto-char (match-beginning 1))
  6714. (insert (org-add-props
  6715. (make-string (max 1 (- c (current-column))) ?\ )
  6716. (plist-put (copy-sequence (text-properties-at (point)))
  6717. 'face nil))))
  6718. (goto-char (point-min))
  6719. (org-font-lock-add-tag-faces (point-max)))))
  6720. (defun org-agenda-priority-up ()
  6721. "Increase the priority of line at point, also in Org-mode file."
  6722. (interactive)
  6723. (org-agenda-priority 'up))
  6724. (defun org-agenda-priority-down ()
  6725. "Decrease the priority of line at point, also in Org-mode file."
  6726. (interactive)
  6727. (org-agenda-priority 'down))
  6728. (defun org-agenda-priority (&optional force-direction)
  6729. "Set the priority of line at point, also in Org-mode file.
  6730. This changes the line at point, all other lines in the agenda referring to
  6731. the same tree node, and the headline of the tree node in the Org-mode file."
  6732. (interactive)
  6733. (unless org-enable-priority-commands
  6734. (error "Priority commands are disabled"))
  6735. (org-agenda-check-no-diary)
  6736. (let* ((marker (or (org-get-at-bol 'org-marker)
  6737. (org-agenda-error)))
  6738. (hdmarker (org-get-at-bol 'org-hd-marker))
  6739. (buffer (marker-buffer hdmarker))
  6740. (pos (marker-position hdmarker))
  6741. (inhibit-read-only t)
  6742. newhead)
  6743. (org-with-remote-undo buffer
  6744. (with-current-buffer buffer
  6745. (widen)
  6746. (goto-char pos)
  6747. (org-show-context 'agenda)
  6748. (save-excursion
  6749. (and (outline-next-heading)
  6750. (org-flag-heading nil))) ; show the next heading
  6751. (funcall 'org-priority force-direction)
  6752. (end-of-line 1)
  6753. (setq newhead (org-get-heading)))
  6754. (org-agenda-change-all-lines newhead hdmarker)
  6755. (beginning-of-line 1))))
  6756. ;; FIXME: should fix the tags property of the agenda line.
  6757. (defun org-agenda-set-tags (&optional tag onoff)
  6758. "Set tags for the current headline."
  6759. (interactive)
  6760. (org-agenda-check-no-diary)
  6761. (if (and (org-region-active-p) (interactive-p))
  6762. (call-interactively 'org-change-tag-in-region)
  6763. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6764. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6765. (org-agenda-error)))
  6766. (buffer (marker-buffer hdmarker))
  6767. (pos (marker-position hdmarker))
  6768. (inhibit-read-only t)
  6769. newhead)
  6770. (org-with-remote-undo buffer
  6771. (with-current-buffer buffer
  6772. (widen)
  6773. (goto-char pos)
  6774. (save-excursion
  6775. (org-show-context 'agenda))
  6776. (save-excursion
  6777. (and (outline-next-heading)
  6778. (org-flag-heading nil))) ; show the next heading
  6779. (goto-char pos)
  6780. (if tag
  6781. (org-toggle-tag tag onoff)
  6782. (call-interactively 'org-set-tags))
  6783. (end-of-line 1)
  6784. (setq newhead (org-get-heading)))
  6785. (org-agenda-change-all-lines newhead hdmarker)
  6786. (beginning-of-line 1)))))
  6787. (defun org-agenda-set-property ()
  6788. "Set a property for the current headline."
  6789. (interactive)
  6790. (org-agenda-check-no-diary)
  6791. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6792. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6793. (org-agenda-error)))
  6794. (buffer (marker-buffer hdmarker))
  6795. (pos (marker-position hdmarker))
  6796. (inhibit-read-only t)
  6797. newhead)
  6798. (org-with-remote-undo buffer
  6799. (with-current-buffer buffer
  6800. (widen)
  6801. (goto-char pos)
  6802. (save-excursion
  6803. (org-show-context 'agenda))
  6804. (save-excursion
  6805. (and (outline-next-heading)
  6806. (org-flag-heading nil))) ; show the next heading
  6807. (goto-char pos)
  6808. (call-interactively 'org-set-property)))))
  6809. (defun org-agenda-set-effort ()
  6810. "Set the effort property for the current headline."
  6811. (interactive)
  6812. (org-agenda-check-no-diary)
  6813. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6814. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6815. (org-agenda-error)))
  6816. (buffer (marker-buffer hdmarker))
  6817. (pos (marker-position hdmarker))
  6818. (inhibit-read-only t)
  6819. newhead)
  6820. (org-with-remote-undo buffer
  6821. (with-current-buffer buffer
  6822. (widen)
  6823. (goto-char pos)
  6824. (save-excursion
  6825. (org-show-context 'agenda))
  6826. (save-excursion
  6827. (and (outline-next-heading)
  6828. (org-flag-heading nil))) ; show the next heading
  6829. (goto-char pos)
  6830. (call-interactively 'org-set-effort)
  6831. (end-of-line 1)))))
  6832. (defun org-agenda-toggle-archive-tag ()
  6833. "Toggle the archive tag for the current entry."
  6834. (interactive)
  6835. (org-agenda-check-no-diary)
  6836. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6837. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6838. (org-agenda-error)))
  6839. (buffer (marker-buffer hdmarker))
  6840. (pos (marker-position hdmarker))
  6841. (inhibit-read-only t)
  6842. newhead)
  6843. (org-with-remote-undo buffer
  6844. (with-current-buffer buffer
  6845. (widen)
  6846. (goto-char pos)
  6847. (org-show-context 'agenda)
  6848. (save-excursion
  6849. (and (outline-next-heading)
  6850. (org-flag-heading nil))) ; show the next heading
  6851. (call-interactively 'org-toggle-archive-tag)
  6852. (end-of-line 1)
  6853. (setq newhead (org-get-heading)))
  6854. (org-agenda-change-all-lines newhead hdmarker)
  6855. (beginning-of-line 1))))
  6856. (defun org-agenda-do-date-later (arg)
  6857. (interactive "P")
  6858. (cond
  6859. ((or (equal arg '(16))
  6860. (memq last-command
  6861. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6862. (setq this-command 'org-agenda-date-later-minutes)
  6863. (org-agenda-date-later-minutes 1))
  6864. ((or (equal arg '(4))
  6865. (memq last-command
  6866. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6867. (setq this-command 'org-agenda-date-later-hours)
  6868. (org-agenda-date-later-hours 1))
  6869. (t
  6870. (org-agenda-date-later (prefix-numeric-value arg)))))
  6871. (defun org-agenda-do-date-earlier (arg)
  6872. (interactive "P")
  6873. (cond
  6874. ((or (equal arg '(16))
  6875. (memq last-command
  6876. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6877. (setq this-command 'org-agenda-date-earlier-minutes)
  6878. (org-agenda-date-earlier-minutes 1))
  6879. ((or (equal arg '(4))
  6880. (memq last-command
  6881. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6882. (setq this-command 'org-agenda-date-earlier-hours)
  6883. (org-agenda-date-earlier-hours 1))
  6884. (t
  6885. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6886. (defun org-agenda-date-later (arg &optional what)
  6887. "Change the date of this item to ARG day(s) later."
  6888. (interactive "p")
  6889. (org-agenda-check-type t 'agenda 'timeline)
  6890. (org-agenda-check-no-diary)
  6891. (let* ((marker (or (org-get-at-bol 'org-marker)
  6892. (org-agenda-error)))
  6893. (buffer (marker-buffer marker))
  6894. (pos (marker-position marker)))
  6895. (org-with-remote-undo buffer
  6896. (with-current-buffer buffer
  6897. (widen)
  6898. (goto-char pos)
  6899. (if (not (org-at-timestamp-p))
  6900. (error "Cannot find time stamp"))
  6901. (org-timestamp-change arg (or what 'day)))
  6902. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6903. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6904. (defun org-agenda-date-earlier (arg &optional what)
  6905. "Change the date of this item to ARG day(s) earlier."
  6906. (interactive "p")
  6907. (org-agenda-date-later (- arg) what))
  6908. (defun org-agenda-date-later-minutes (arg)
  6909. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6910. (interactive "p")
  6911. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6912. (org-agenda-date-later arg 'minute))
  6913. (defun org-agenda-date-earlier-minutes (arg)
  6914. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6915. (interactive "p")
  6916. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6917. (org-agenda-date-earlier arg 'minute))
  6918. (defun org-agenda-date-later-hours (arg)
  6919. "Change the time of this item, in hour steps."
  6920. (interactive "p")
  6921. (org-agenda-date-later arg 'hour))
  6922. (defun org-agenda-date-earlier-hours (arg)
  6923. "Change the time of this item, in hour steps."
  6924. (interactive "p")
  6925. (org-agenda-date-earlier arg 'hour))
  6926. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6927. "Show new date stamp via text properties."
  6928. ;; We use text properties to make this undoable
  6929. (let ((inhibit-read-only t)
  6930. (buffer-invisibility-spec))
  6931. (setq stamp (concat " " prefix " => " stamp))
  6932. (save-excursion
  6933. (goto-char (point-max))
  6934. (while (not (bobp))
  6935. (when (equal marker (org-get-at-bol 'org-marker))
  6936. (org-move-to-column (- (window-width) (length stamp)) t)
  6937. (org-agenda-fix-tags-filter-overlays-at (point))
  6938. (if (featurep 'xemacs)
  6939. ;; Use `duplicable' property to trigger undo recording
  6940. (let ((ex (make-extent nil nil))
  6941. (gl (make-glyph stamp)))
  6942. (set-glyph-face gl 'secondary-selection)
  6943. (set-extent-properties
  6944. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6945. (insert-extent ex (1- (point)) (point-at-eol)))
  6946. (add-text-properties
  6947. (1- (point)) (point-at-eol)
  6948. (list 'display (org-add-props stamp nil
  6949. 'face 'secondary-selection))))
  6950. (beginning-of-line 1))
  6951. (beginning-of-line 0)))))
  6952. (defun org-agenda-date-prompt (arg)
  6953. "Change the date of this item. Date is prompted for, with default today.
  6954. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6955. be used to request time specification in the time stamp."
  6956. (interactive "P")
  6957. (org-agenda-check-type t 'agenda 'timeline)
  6958. (org-agenda-check-no-diary)
  6959. (let* ((marker (or (org-get-at-bol 'org-marker)
  6960. (org-agenda-error)))
  6961. (buffer (marker-buffer marker))
  6962. (pos (marker-position marker)))
  6963. (org-with-remote-undo buffer
  6964. (with-current-buffer buffer
  6965. (widen)
  6966. (goto-char pos)
  6967. (if (not (org-at-timestamp-p t))
  6968. (error "Cannot find time stamp"))
  6969. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6970. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6971. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6972. (defun org-agenda-schedule (arg &optional time)
  6973. "Schedule the item at point.
  6974. Arg is passed through to `org-schedule'."
  6975. (interactive "P")
  6976. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6977. (org-agenda-check-no-diary)
  6978. (let* ((marker (or (org-get-at-bol 'org-marker)
  6979. (org-agenda-error)))
  6980. (type (marker-insertion-type marker))
  6981. (buffer (marker-buffer marker))
  6982. (pos (marker-position marker))
  6983. (org-insert-labeled-timestamps-at-point nil)
  6984. ts)
  6985. (set-marker-insertion-type marker t)
  6986. (org-with-remote-undo buffer
  6987. (with-current-buffer buffer
  6988. (widen)
  6989. (goto-char pos)
  6990. (setq ts (org-schedule arg time)))
  6991. (org-agenda-show-new-time marker ts "S"))
  6992. (message "Item scheduled for %s" ts)))
  6993. (defun org-agenda-deadline (arg &optional time)
  6994. "Schedule the item at point.
  6995. Arg is passed through to `org-deadline'."
  6996. (interactive "P")
  6997. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6998. (org-agenda-check-no-diary)
  6999. (let* ((marker (or (org-get-at-bol 'org-marker)
  7000. (org-agenda-error)))
  7001. (buffer (marker-buffer marker))
  7002. (pos (marker-position marker))
  7003. (org-insert-labeled-timestamps-at-point nil)
  7004. ts)
  7005. (org-with-remote-undo buffer
  7006. (with-current-buffer buffer
  7007. (widen)
  7008. (goto-char pos)
  7009. (setq ts (org-deadline arg time)))
  7010. (org-agenda-show-new-time marker ts "D"))
  7011. (message "Deadline for this item set to %s" ts)))
  7012. (defun org-agenda-action ()
  7013. "Select entry for agenda action, or execute an agenda action.
  7014. This command prompts for another letter. Valid inputs are:
  7015. m Mark the entry at point for an agenda action
  7016. s Schedule the marked entry to the date at the cursor
  7017. d Set the deadline of the marked entry to the date at the cursor
  7018. r Call `org-remember' with cursor date as the default date
  7019. c Call `org-capture' with cursor date as the default date
  7020. SPC Show marked entry in other window
  7021. TAB Visit marked entry in other window
  7022. The cursor may be at a date in the calendar, or in the Org agenda."
  7023. (interactive)
  7024. (let (ans)
  7025. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7026. (setq ans (read-char-exclusive))
  7027. (cond
  7028. ((equal ans ?m)
  7029. ;; Mark this entry
  7030. (if (eq major-mode 'org-agenda-mode)
  7031. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7032. (org-get-at-bol 'org-marker))))
  7033. (if m
  7034. (progn
  7035. (move-marker org-agenda-action-marker
  7036. (marker-position m) (marker-buffer m))
  7037. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7038. (error "Don't know which entry to mark")))
  7039. (error "This command works only in the agenda")))
  7040. ((equal ans ?s)
  7041. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7042. ((equal ans ?d)
  7043. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7044. ((equal ans ?r)
  7045. (org-agenda-do-action '(org-remember) t))
  7046. ((equal ans ?c)
  7047. (org-agenda-do-action '(org-capture) t))
  7048. ((equal ans ?\ )
  7049. (let ((cw (selected-window)))
  7050. (org-switch-to-buffer-other-window
  7051. (marker-buffer org-agenda-action-marker))
  7052. (goto-char org-agenda-action-marker)
  7053. (org-show-context 'agenda)
  7054. (select-window cw)))
  7055. ((equal ans ?\C-i)
  7056. (org-switch-to-buffer-other-window
  7057. (marker-buffer org-agenda-action-marker))
  7058. (goto-char org-agenda-action-marker)
  7059. (org-show-context 'agenda))
  7060. (t (error "Invalid agenda action %c" ans)))))
  7061. (defun org-agenda-do-action (form &optional current-buffer)
  7062. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7063. (let ((org-overriding-default-time (org-get-cursor-date)))
  7064. (if current-buffer
  7065. (eval form)
  7066. (if (not (marker-buffer org-agenda-action-marker))
  7067. (error "No entry has been selected for agenda action")
  7068. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7069. (save-excursion
  7070. (save-restriction
  7071. (widen)
  7072. (goto-char org-agenda-action-marker)
  7073. (eval form))))))))
  7074. (defun org-agenda-clock-in (&optional arg)
  7075. "Start the clock on the currently selected item."
  7076. (interactive "P")
  7077. (org-agenda-check-no-diary)
  7078. (if (equal arg '(4))
  7079. (org-clock-in arg)
  7080. (let* ((marker (or (org-get-at-bol 'org-marker)
  7081. (org-agenda-error)))
  7082. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7083. marker))
  7084. (pos (marker-position marker))
  7085. newhead)
  7086. (org-with-remote-undo (marker-buffer marker)
  7087. (with-current-buffer (marker-buffer marker)
  7088. (widen)
  7089. (goto-char pos)
  7090. (org-show-context 'agenda)
  7091. (org-show-entry)
  7092. (org-cycle-hide-drawers 'children)
  7093. (org-clock-in arg)
  7094. (setq newhead (org-get-heading)))
  7095. (org-agenda-change-all-lines newhead hdmarker)))))
  7096. (defun org-agenda-clock-out ()
  7097. "Stop the currently running clock."
  7098. (interactive)
  7099. (unless (marker-buffer org-clock-marker)
  7100. (error "No running clock"))
  7101. (let ((marker (make-marker)) newhead)
  7102. (org-with-remote-undo (marker-buffer org-clock-marker)
  7103. (with-current-buffer (marker-buffer org-clock-marker)
  7104. (save-excursion
  7105. (save-restriction
  7106. (widen)
  7107. (goto-char org-clock-marker)
  7108. (org-back-to-heading t)
  7109. (move-marker marker (point))
  7110. (org-clock-out)
  7111. (setq newhead (org-get-heading))))))
  7112. (org-agenda-change-all-lines newhead marker)
  7113. (move-marker marker nil)))
  7114. (defun org-agenda-clock-cancel (&optional arg)
  7115. "Cancel the currently running clock."
  7116. (interactive "P")
  7117. (unless (marker-buffer org-clock-marker)
  7118. (error "No running clock"))
  7119. (org-with-remote-undo (marker-buffer org-clock-marker)
  7120. (org-clock-cancel)))
  7121. (defun org-agenda-clock-goto ()
  7122. "Jump to the currently clocked in task within the agenda.
  7123. If the currently clocked in task is not listed in the agenda
  7124. buffer, display it in another window."
  7125. (interactive)
  7126. (let (pos)
  7127. (mapc (lambda (o)
  7128. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7129. (setq pos (overlay-start o))))
  7130. (overlays-in (point-min) (point-max)))
  7131. (cond (pos (goto-char pos))
  7132. ;; If the currently clocked entry is not in the agenda
  7133. ;; buffer, we visit it in another window:
  7134. (org-clock-current-task
  7135. (org-switch-to-buffer-other-window (org-clock-goto)))
  7136. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7137. (defun org-agenda-diary-entry-in-org-file ()
  7138. "Make a diary entry in the file `org-agenda-diary-file'."
  7139. (let (d1 d2 char (text "") dp1 dp2)
  7140. (if (equal (buffer-name) "*Calendar*")
  7141. (setq d1 (calendar-cursor-to-date t)
  7142. d2 (car calendar-mark-ring))
  7143. (setq dp1 (get-text-property (point-at-bol) 'day))
  7144. (unless dp1 (error "No date defined in current line"))
  7145. (setq d1 (calendar-gregorian-from-absolute dp1)
  7146. d2 (and (ignore-errors (mark))
  7147. (save-excursion
  7148. (goto-char (mark))
  7149. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7150. (calendar-gregorian-from-absolute dp2))))
  7151. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7152. (setq char (read-char-exclusive))
  7153. (cond
  7154. ((equal char ?d)
  7155. (setq text (read-string "Day entry: "))
  7156. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7157. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7158. ((equal char ?a)
  7159. (setq d1 (list (car d1) (nth 1 d1)
  7160. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7161. (nth 2 d1))))
  7162. (setq text (read-string "Anniversary (use %d to show years): "))
  7163. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7164. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7165. ((equal char ?b)
  7166. (setq text (read-string "Block entry: "))
  7167. (unless (and d1 d2 (not (equal d1 d2)))
  7168. (error "No block of days selected"))
  7169. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7170. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7171. ((equal char ?j)
  7172. (org-switch-to-buffer-other-window
  7173. (find-file-noselect org-agenda-diary-file))
  7174. (require 'org-datetree)
  7175. (org-datetree-find-date-create d1)
  7176. (org-reveal t))
  7177. (t (error "Invalid selection character `%c'" char)))))
  7178. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7179. "Where in `org-agenda-diary-file' should new entries be added?
  7180. Valid values:
  7181. date-tree in the date tree, as child of the date
  7182. top-level as top-level entries at the end of the file."
  7183. :group 'org-agenda
  7184. :type '(choice
  7185. (const :tag "in a date tree" date-tree)
  7186. (const :tag "as top level at end of file" top-level)))
  7187. (defcustom org-agenda-insert-diary-extract-time nil
  7188. "Non-nil means extract any time specification from the diary entry."
  7189. :group 'org-agenda
  7190. :type 'boolean)
  7191. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7192. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7193. If TEXT is not empty, it will become the headline of the new entry, and
  7194. the resulting entry will not be shown. When TEXT is empty, switch to
  7195. `org-agenda-diary-file' and let the user finish the entry there."
  7196. (let ((cw (current-window-configuration)))
  7197. (org-switch-to-buffer-other-window
  7198. (find-file-noselect org-agenda-diary-file))
  7199. (widen)
  7200. (goto-char (point-min))
  7201. (cond
  7202. ((eq type 'anniversary)
  7203. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7204. (progn
  7205. (or (org-on-heading-p t)
  7206. (progn
  7207. (outline-next-heading)
  7208. (insert "* Anniversaries\n\n")
  7209. (beginning-of-line -1)))))
  7210. (outline-next-heading)
  7211. (org-back-over-empty-lines)
  7212. (backward-char 1)
  7213. (insert "\n")
  7214. (require 'diary-lib)
  7215. (let ((calendar-date-display-form
  7216. (if (if (boundp 'calendar-date-style)
  7217. (eq calendar-date-style 'european)
  7218. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  7219. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  7220. '(day " " month " " year)
  7221. '(month " " day " " year))))
  7222. (insert (format "%%%%(diary-anniversary %s) %s"
  7223. (calendar-date-string d1 nil t) text))))
  7224. ((eq type 'day)
  7225. (let ((org-prefix-has-time t)
  7226. (org-agenda-time-leading-zero t)
  7227. fmt time time2)
  7228. (if org-agenda-insert-diary-extract-time
  7229. ;; Use org-format-agenda-item to parse text for a time-range and
  7230. ;; remove it. FIXME: This is a hack, we should refactor
  7231. ;; that function to make time extraction available separately
  7232. (setq fmt (org-format-agenda-item nil text nil nil t)
  7233. time (get-text-property 0 'time fmt)
  7234. time2 (if (> (length time) 0)
  7235. ;; split-string removes trailing ...... if
  7236. ;; no end time given. First space
  7237. ;; separates time from date.
  7238. (concat " " (car (split-string time "\\.")))
  7239. nil)
  7240. text (get-text-property 0 'txt fmt)))
  7241. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7242. (org-agenda-insert-diary-as-top-level text)
  7243. (require 'org-datetree)
  7244. (org-datetree-find-date-create d1)
  7245. (org-agenda-insert-diary-make-new-entry text))
  7246. (org-insert-time-stamp (org-time-from-absolute
  7247. (calendar-absolute-from-gregorian d1))
  7248. nil nil nil nil time2))
  7249. (end-of-line 0))
  7250. ((eq type 'block)
  7251. (if (> (calendar-absolute-from-gregorian d1)
  7252. (calendar-absolute-from-gregorian d2))
  7253. (setq d1 (prog1 d2 (setq d2 d1))))
  7254. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7255. (org-agenda-insert-diary-as-top-level text)
  7256. (require 'org-datetree)
  7257. (org-datetree-find-date-create d1)
  7258. (org-agenda-insert-diary-make-new-entry text))
  7259. (org-insert-time-stamp (org-time-from-absolute
  7260. (calendar-absolute-from-gregorian d1)))
  7261. (insert "--")
  7262. (org-insert-time-stamp (org-time-from-absolute
  7263. (calendar-absolute-from-gregorian d2)))
  7264. (end-of-line 0)))
  7265. (if (string-match "\\S-" text)
  7266. (progn
  7267. (set-window-configuration cw)
  7268. (message "%s entry added to %s"
  7269. (capitalize (symbol-name type))
  7270. (abbreviate-file-name org-agenda-diary-file)))
  7271. (org-reveal t)
  7272. (message "Please finish entry here"))))
  7273. (defun org-agenda-insert-diary-as-top-level (text)
  7274. "Make new entry as a top-level entry at the end of the file.
  7275. Add TEXT as headline, and position the cursor in the second line so that
  7276. a timestamp can be added there."
  7277. (widen)
  7278. (goto-char (point-max))
  7279. (or (bolp) (insert "\n"))
  7280. (insert "* " text "\n")
  7281. (if org-adapt-indentation (org-indent-to-column 2)))
  7282. (defun org-agenda-insert-diary-make-new-entry (text)
  7283. "Make new entry as last child of current entry.
  7284. Add TEXT as headline, and position the cursor in the second line so that
  7285. a timestamp can be added there."
  7286. (let ((org-show-following-heading t)
  7287. (org-show-siblings t)
  7288. (org-show-hierarchy-above t)
  7289. (org-show-entry-below t)
  7290. col)
  7291. (outline-next-heading)
  7292. (org-back-over-empty-lines)
  7293. (or (looking-at "[ \t]*$")
  7294. (progn (insert "\n") (backward-char 1)))
  7295. (org-insert-heading nil t)
  7296. (org-do-demote)
  7297. (setq col (current-column))
  7298. (insert text "\n")
  7299. (if org-adapt-indentation (org-indent-to-column col))
  7300. (let ((org-show-following-heading t)
  7301. (org-show-siblings t)
  7302. (org-show-hierarchy-above t)
  7303. (org-show-entry-below t))
  7304. (org-show-context))))
  7305. (defun org-agenda-diary-entry ()
  7306. "Make a diary entry, like the `i' command from the calendar.
  7307. All the standard commands work: block, weekly etc.
  7308. When `org-agenda-diary-file' points to a file,
  7309. `org-agenda-diary-entry-in-org-file' is called instead to create
  7310. entries in that Org-mode file."
  7311. (interactive)
  7312. (org-agenda-check-type t 'agenda 'timeline)
  7313. (if (not (eq org-agenda-diary-file 'diary-file))
  7314. (org-agenda-diary-entry-in-org-file)
  7315. (require 'diary-lib)
  7316. (let* ((char (progn
  7317. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7318. (read-char-exclusive)))
  7319. (cmd (cdr (assoc char
  7320. '((?d . insert-diary-entry)
  7321. (?w . insert-weekly-diary-entry)
  7322. (?m . insert-monthly-diary-entry)
  7323. (?y . insert-yearly-diary-entry)
  7324. (?a . insert-anniversary-diary-entry)
  7325. (?b . insert-block-diary-entry)
  7326. (?c . insert-cyclic-diary-entry)))))
  7327. (oldf (symbol-function 'calendar-cursor-to-date))
  7328. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7329. (point (point))
  7330. (mark (or (mark t) (point))))
  7331. (unless cmd
  7332. (error "No command associated with <%c>" char))
  7333. (unless (and (get-text-property point 'day)
  7334. (or (not (equal ?b char))
  7335. (get-text-property mark 'day)))
  7336. (error "Don't know which date to use for diary entry"))
  7337. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7338. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7339. (let ((calendar-mark-ring
  7340. (list (calendar-gregorian-from-absolute
  7341. (or (get-text-property mark 'day)
  7342. (get-text-property point 'day))))))
  7343. (unwind-protect
  7344. (progn
  7345. (fset 'calendar-cursor-to-date
  7346. (lambda (&optional error dummy)
  7347. (calendar-gregorian-from-absolute
  7348. (get-text-property point 'day))))
  7349. (call-interactively cmd))
  7350. (fset 'calendar-cursor-to-date oldf))))))
  7351. (defun org-agenda-execute-calendar-command (cmd)
  7352. "Execute a calendar command from the agenda, with the date associated to
  7353. the cursor position."
  7354. (org-agenda-check-type t 'agenda 'timeline)
  7355. (require 'diary-lib)
  7356. (unless (get-text-property (point) 'day)
  7357. (error "Don't know which date to use for calendar command"))
  7358. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7359. (point (point))
  7360. (date (calendar-gregorian-from-absolute
  7361. (get-text-property point 'day)))
  7362. ;; the following 2 vars are needed in the calendar
  7363. (displayed-month (car date))
  7364. (displayed-year (nth 2 date)))
  7365. (unwind-protect
  7366. (progn
  7367. (fset 'calendar-cursor-to-date
  7368. (lambda (&optional error dummy)
  7369. (calendar-gregorian-from-absolute
  7370. (get-text-property point 'day))))
  7371. (call-interactively cmd))
  7372. (fset 'calendar-cursor-to-date oldf))))
  7373. (defun org-agenda-phases-of-moon ()
  7374. "Display the phases of the moon for the 3 months around the cursor date."
  7375. (interactive)
  7376. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7377. (defun org-agenda-holidays ()
  7378. "Display the holidays for the 3 months around the cursor date."
  7379. (interactive)
  7380. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7381. (defvar calendar-longitude)
  7382. (defvar calendar-latitude)
  7383. (defvar calendar-location-name)
  7384. (defun org-agenda-sunrise-sunset (arg)
  7385. "Display sunrise and sunset for the cursor date.
  7386. Latitude and longitude can be specified with the variables
  7387. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7388. argument, latitude and longitude will be prompted for."
  7389. (interactive "P")
  7390. (require 'solar)
  7391. (let ((calendar-longitude (if arg nil calendar-longitude))
  7392. (calendar-latitude (if arg nil calendar-latitude))
  7393. (calendar-location-name
  7394. (if arg "the given coordinates" calendar-location-name)))
  7395. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7396. (defun org-agenda-goto-calendar ()
  7397. "Open the Emacs calendar with the date at the cursor."
  7398. (interactive)
  7399. (org-agenda-check-type t 'agenda 'timeline)
  7400. (let* ((day (or (get-text-property (point) 'day)
  7401. (error "Don't know which date to open in calendar")))
  7402. (date (calendar-gregorian-from-absolute day))
  7403. (calendar-move-hook nil)
  7404. (calendar-view-holidays-initially-flag nil)
  7405. (calendar-view-diary-initially-flag nil))
  7406. (calendar)
  7407. (calendar-goto-date date)))
  7408. ;;;###autoload
  7409. (defun org-calendar-goto-agenda ()
  7410. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7411. This is a command that has to be installed in `calendar-mode-map'."
  7412. (interactive)
  7413. (org-agenda-list nil (calendar-absolute-from-gregorian
  7414. (calendar-cursor-to-date))
  7415. nil))
  7416. (defun org-agenda-convert-date ()
  7417. (interactive)
  7418. (org-agenda-check-type t 'agenda 'timeline)
  7419. (let ((day (get-text-property (point) 'day))
  7420. date s)
  7421. (unless day
  7422. (error "Don't know which date to convert"))
  7423. (setq date (calendar-gregorian-from-absolute day))
  7424. (setq s (concat
  7425. "Gregorian: " (calendar-date-string date) "\n"
  7426. "ISO: " (calendar-iso-date-string date) "\n"
  7427. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7428. "Julian: " (calendar-julian-date-string date) "\n"
  7429. "Astron. JD: " (calendar-astro-date-string date)
  7430. " (Julian date number at noon UTC)\n"
  7431. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7432. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7433. "French: " (calendar-french-date-string date) "\n"
  7434. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7435. "Mayan: " (calendar-mayan-date-string date) "\n"
  7436. "Coptic: " (calendar-coptic-date-string date) "\n"
  7437. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7438. "Persian: " (calendar-persian-date-string date) "\n"
  7439. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7440. (with-output-to-temp-buffer "*Dates*"
  7441. (princ s))
  7442. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7443. ;;; Bulk commands
  7444. (defvar org-agenda-bulk-marked-entries nil
  7445. "List of markers that refer to marked entries in the agenda.")
  7446. (defun org-agenda-bulk-marked-p ()
  7447. (eq (get-char-property (point-at-bol) 'type)
  7448. 'org-marked-entry-overlay))
  7449. (defun org-agenda-bulk-mark (&optional arg)
  7450. "Mark the entry at point for future bulk action."
  7451. (interactive "p")
  7452. (dotimes (i (max arg 1))
  7453. (unless (org-get-at-bol 'org-agenda-diary-link)
  7454. (let* ((m (org-get-at-bol 'org-hd-marker))
  7455. ov)
  7456. (unless (org-agenda-bulk-marked-p)
  7457. (unless m (error "Nothing to mark at point"))
  7458. (push m org-agenda-bulk-marked-entries)
  7459. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7460. (org-overlay-display ov "> "
  7461. (org-get-todo-face "TODO")
  7462. 'evaporate)
  7463. (overlay-put ov 'type 'org-marked-entry-overlay))
  7464. (beginning-of-line 2)
  7465. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7466. (beginning-of-line 2))
  7467. (message "%d entries marked for bulk action"
  7468. (length org-agenda-bulk-marked-entries))))))
  7469. (defun org-agenda-bulk-mark-regexp (regexp)
  7470. "Mark entries match REGEXP."
  7471. (interactive "sMark entries matching regexp: ")
  7472. (let (entries-marked)
  7473. (save-excursion
  7474. (goto-char (point-min))
  7475. (goto-char (next-single-property-change (point) 'txt))
  7476. (while (re-search-forward regexp nil t)
  7477. (when (string-match regexp (get-text-property (point) 'txt))
  7478. (setq entries-marked (+ entries-marked 1))
  7479. (call-interactively 'org-agenda-bulk-mark))))
  7480. (if (not entries-marked)
  7481. (message "No entry matching this regexp."))))
  7482. (defun org-agenda-bulk-unmark ()
  7483. "Unmark the entry at point for future bulk action."
  7484. (interactive)
  7485. (when (org-agenda-bulk-marked-p)
  7486. (org-agenda-bulk-remove-overlays
  7487. (point-at-bol) (+ 2 (point-at-bol)))
  7488. (setq org-agenda-bulk-marked-entries
  7489. (delete (org-get-at-bol 'org-hd-marker)
  7490. org-agenda-bulk-marked-entries)))
  7491. (beginning-of-line 2)
  7492. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7493. (beginning-of-line 2))
  7494. (message "%d entries marked for bulk action"
  7495. (length org-agenda-bulk-marked-entries)))
  7496. (defun org-agenda-bulk-toggle ()
  7497. "Toggle marking the entry at point for bulk action."
  7498. (interactive)
  7499. (if (org-agenda-bulk-marked-p)
  7500. (org-agenda-bulk-unmark)
  7501. (org-agenda-bulk-mark)))
  7502. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7503. "Remove the mark overlays between BEG and END in the agenda buffer.
  7504. BEG and END default to the buffer limits.
  7505. This only removes the overlays, it does not remove the markers
  7506. from the list in `org-agenda-bulk-marked-entries'."
  7507. (interactive)
  7508. (mapc (lambda (ov)
  7509. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7510. (delete-overlay ov)))
  7511. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7512. (defun org-agenda-bulk-remove-all-marks ()
  7513. "Remove all marks in the agenda buffer.
  7514. This will remove the markers, and the overlays."
  7515. (interactive)
  7516. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7517. (setq org-agenda-bulk-marked-entries nil)
  7518. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7519. (defun org-agenda-bulk-action (&optional arg)
  7520. "Execute an remote-editing action on all marked entries.
  7521. The prefix arg is passed through to the command if possible."
  7522. (interactive "P")
  7523. ;; Make sure we have markers, and only valid ones
  7524. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7525. (mapc
  7526. (lambda (m)
  7527. (unless (and (markerp m)
  7528. (marker-buffer m)
  7529. (buffer-live-p (marker-buffer m))
  7530. (marker-position m))
  7531. (error "Marker %s for bulk command is invalid" m)))
  7532. org-agenda-bulk-marked-entries)
  7533. ;; Prompt for the bulk command
  7534. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline [f]unction")
  7535. (let* ((action (read-char-exclusive))
  7536. (org-log-refile (if org-log-refile 'time nil))
  7537. (entries (reverse org-agenda-bulk-marked-entries))
  7538. redo-at-end
  7539. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7540. (cond
  7541. ((equal action ?$)
  7542. (setq cmd '(org-agenda-archive)))
  7543. ((equal action ?A)
  7544. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7545. ((member action '(?r ?w))
  7546. (setq rfloc (org-refile-get-location
  7547. "Refile to"
  7548. (marker-buffer (car org-agenda-bulk-marked-entries))
  7549. org-refile-allow-creating-parent-nodes))
  7550. (if (nth 3 rfloc)
  7551. (setcar (nthcdr 3 rfloc)
  7552. (move-marker (make-marker) (nth 3 rfloc)
  7553. (or (get-file-buffer (nth 1 rfloc))
  7554. (find-buffer-visiting (nth 1 rfloc))
  7555. (error "This should not happen")))))
  7556. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7557. redo-at-end t))
  7558. ((equal action ?t)
  7559. (setq state (org-icompleting-read
  7560. "Todo state: "
  7561. (with-current-buffer (marker-buffer (car entries))
  7562. (mapcar 'list org-todo-keywords-1))))
  7563. (setq cmd `(let ((org-inhibit-blocking t)
  7564. (org-inhibit-logging 'note))
  7565. (org-agenda-todo ,state))))
  7566. ((memq action '(?- ?+))
  7567. (setq tag (org-icompleting-read
  7568. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7569. (with-current-buffer (marker-buffer (car entries))
  7570. (delq nil
  7571. (mapcar (lambda (x)
  7572. (if (stringp (car x)) x)) org-tag-alist)))))
  7573. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7574. ((memq action '(?s ?d))
  7575. (let* ((date (unless arg
  7576. (org-read-date
  7577. nil nil nil
  7578. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7579. (ans (if arg nil org-read-date-final-answer))
  7580. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7581. (setq cmd `(let* ((bound (fboundp 'read-string))
  7582. (old (and bound (symbol-function 'read-string))))
  7583. (unwind-protect
  7584. (progn
  7585. (fset 'read-string (lambda (&rest ignore) ,ans))
  7586. (eval '(,c1 arg)))
  7587. (if bound
  7588. (fset 'read-string old)
  7589. (fmakunbound 'read-string)))))))
  7590. ((equal action ?S)
  7591. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7592. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7593. (let ((days (read-number
  7594. (format "Scatter tasks across how many %sdays: "
  7595. (if arg "week" "")) 7)))
  7596. (setq cmd
  7597. `(let ((distance (1+ (random ,days))))
  7598. (if arg
  7599. (let ((dist distance)
  7600. (day-of-week
  7601. (calendar-day-of-week
  7602. (calendar-gregorian-from-absolute (org-today)))))
  7603. (dotimes (i (1+ dist))
  7604. (while (member day-of-week org-agenda-weekend-days)
  7605. (incf distance)
  7606. (incf day-of-week)
  7607. (if (= day-of-week 7)
  7608. (setq day-of-week 0)))
  7609. (incf day-of-week)
  7610. (if (= day-of-week 7)
  7611. (setq day-of-week 0)))))
  7612. ;; silently fail when try to replan a sexp entry
  7613. (condition-case nil
  7614. (org-agenda-schedule nil
  7615. (days-to-time
  7616. (+ (org-today) distance)))
  7617. (error nil)))))))
  7618. ((equal action ?f)
  7619. (setq cmd (list (intern
  7620. (org-icompleting-read "Function: "
  7621. obarray 'fboundp t nil nil)))))
  7622. (t (error "Invalid bulk action")))
  7623. ;; Sort the markers, to make sure that parents are handled before children
  7624. (setq entries (sort entries
  7625. (lambda (a b)
  7626. (cond
  7627. ((equal (marker-buffer a) (marker-buffer b))
  7628. (< (marker-position a) (marker-position b)))
  7629. (t
  7630. (string< (buffer-name (marker-buffer a))
  7631. (buffer-name (marker-buffer b))))))))
  7632. ;; Now loop over all markers and apply cmd
  7633. (while (setq e (pop entries))
  7634. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7635. (if (not pos)
  7636. (progn (message "Skipping removed entry at %s" e)
  7637. (setq cntskip (1+ cntskip)))
  7638. (goto-char pos)
  7639. (eval cmd)
  7640. (setq org-agenda-bulk-marked-entries
  7641. (delete e org-agenda-bulk-marked-entries))
  7642. (setq cnt (1+ cnt))))
  7643. (setq org-agenda-bulk-marked-entries nil)
  7644. (org-agenda-bulk-remove-all-marks)
  7645. (when redo-at-end (org-agenda-redo))
  7646. (message "Acted on %d entries%s"
  7647. cnt
  7648. (if (= cntskip 0)
  7649. ""
  7650. (format ", skipped %d (disappeared before their turn)"
  7651. cntskip)))))
  7652. ;;; Flagging notes
  7653. (defun org-agenda-show-the-flagging-note ()
  7654. "Display the flagging note in the other window.
  7655. When called a second time in direct sequence, offer to remove the FLAGGING
  7656. tag and (if present) the flagging note."
  7657. (interactive)
  7658. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7659. (win (selected-window))
  7660. note heading newhead)
  7661. (unless hdmarker
  7662. (error "No linked entry at point"))
  7663. (if (and (eq this-command last-command)
  7664. (y-or-n-p "Unflag and remove any flagging note? "))
  7665. (progn
  7666. (org-agenda-remove-flag hdmarker)
  7667. (let ((win (get-buffer-window "*Flagging Note*")))
  7668. (and win (delete-window win)))
  7669. (message "Entry unflaged"))
  7670. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7671. (unless note
  7672. (error "No flagging note"))
  7673. (org-kill-new note)
  7674. (org-switch-to-buffer-other-window "*Flagging Note*")
  7675. (erase-buffer)
  7676. (insert note)
  7677. (goto-char (point-min))
  7678. (while (re-search-forward "\\\\n" nil t)
  7679. (replace-match "\n" t t))
  7680. (goto-char (point-min))
  7681. (select-window win)
  7682. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7683. (defun org-agenda-remove-flag (marker)
  7684. "Remove the FLAGGED tag and any flagging note in the entry."
  7685. (let (newhead)
  7686. (org-with-point-at marker
  7687. (org-toggle-tag "FLAGGED" 'off)
  7688. (org-entry-delete nil "THEFLAGGINGNOTE")
  7689. (setq newhead (org-get-heading)))
  7690. (org-agenda-change-all-lines newhead marker)
  7691. (message "Entry unflaged")))
  7692. (defun org-agenda-get-any-marker (&optional pos)
  7693. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7694. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7695. ;;; Appointment reminders
  7696. (defvar appt-time-msg-list)
  7697. ;;;###autoload
  7698. (defun org-agenda-to-appt (&optional refresh filter)
  7699. "Activate appointments found in `org-agenda-files'.
  7700. With a \\[universal-argument] prefix, refresh the list of
  7701. appointments.
  7702. If FILTER is t, interactively prompt the user for a regular
  7703. expression, and filter out entries that don't match it.
  7704. If FILTER is a string, use this string as a regular expression
  7705. for filtering entries out.
  7706. FILTER can also be an alist with the car of each cell being
  7707. either 'headline or 'category. For example:
  7708. '((headline \"IMPORTANT\")
  7709. (category \"Work\"))
  7710. will only add headlines containing IMPORTANT or headlines
  7711. belonging to the \"Work\" category."
  7712. (interactive "P")
  7713. (if refresh (setq appt-time-msg-list nil))
  7714. (if (eq filter t)
  7715. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7716. (let* ((cnt 0) ; count added events
  7717. (org-agenda-new-buffers nil)
  7718. (org-deadline-warning-days 0)
  7719. ;; Do not use `org-today' here because appt only takes
  7720. ;; time and without date as argument, so it may pass wrong
  7721. ;; information otherwise
  7722. (today (org-date-to-gregorian
  7723. (time-to-days (current-time))))
  7724. (org-agenda-restrict nil)
  7725. (files (org-agenda-files 'unrestricted)) entries file)
  7726. ;; Get all entries which may contain an appt
  7727. (org-prepare-agenda-buffers files)
  7728. (while (setq file (pop files))
  7729. (setq entries
  7730. (append entries
  7731. (org-agenda-get-day-entries
  7732. file today :timestamp :scheduled :deadline))))
  7733. (setq entries (delq nil entries))
  7734. ;; Map thru entries and find if we should filter them out
  7735. (mapc
  7736. (lambda(x)
  7737. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7738. (cat (get-text-property 1 'org-category x))
  7739. (tod (get-text-property 1 'time-of-day x))
  7740. (ok (or (null filter)
  7741. (and (stringp filter) (string-match filter evt))
  7742. (and (listp filter)
  7743. (or (string-match
  7744. (cadr (assoc 'category filter)) cat)
  7745. (string-match
  7746. (cadr (assoc 'headline filter)) evt))))))
  7747. ;; FIXME: Shall we remove text-properties for the appt text?
  7748. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7749. (when (and ok tod)
  7750. (setq tod (concat "00" (number-to-string tod))
  7751. tod (when (string-match
  7752. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7753. (concat (match-string 1 tod) ":"
  7754. (match-string 2 tod))))
  7755. (appt-add tod evt)
  7756. (setq cnt (1+ cnt))))) entries)
  7757. (org-release-buffers org-agenda-new-buffers)
  7758. (if (eq cnt 0)
  7759. (message "No event to add")
  7760. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7761. (defun org-agenda-todayp (date)
  7762. "Does DATE mean today, when considering `org-extend-today-until'?"
  7763. (let ((today (org-today))
  7764. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7765. date)))
  7766. (eq date today)))
  7767. (provide 'org-agenda)
  7768. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7769. ;;; org-agenda.el ends here