org-agenda.el 322 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441
  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.6
  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 globally by leaving out lines like the agenda span
  82. name and week number or the separator lines."
  83. :group 'org-agenda
  84. :type 'boolean)
  85. (defcustom org-agenda-block-separator ?=
  86. "The separator between blocks in the agenda.
  87. If this is a string, it will be used as the separator, with a newline added.
  88. If it is a character, it will be repeated to fill the window width.
  89. If nil the separator is disabled. In `org-agenda-custom-commands' this
  90. addresses the separator between the current and the previous block."
  91. :group 'org-agenda
  92. :type '(choice
  93. (const :tag "Disabled" nil)
  94. (character)
  95. (string)))
  96. (defgroup org-agenda-export nil
  97. "Options concerning exporting agenda views in Org-mode."
  98. :tag "Org Agenda Export"
  99. :group 'org-agenda)
  100. (defcustom org-agenda-with-colors t
  101. "Non-nil means use colors in agenda views."
  102. :group 'org-agenda-export
  103. :type 'boolean)
  104. (defcustom org-agenda-exporter-settings nil
  105. "Alist of variable/value pairs that should be active during agenda export.
  106. This is a good place to set options for ps-print and for htmlize.
  107. Note that the way this is implemented, the values will be evaluated
  108. before assigned to the variables. So make sure to quote values you do
  109. *not* want evaluated, for example
  110. (setq org-agenda-exporter-settings
  111. '((ps-print-color-p 'black-white)))"
  112. :group 'org-agenda-export
  113. :type '(repeat
  114. (list
  115. (variable)
  116. (sexp :tag "Value"))))
  117. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  118. "Hook run in temporary buffer before writing it to an export file.
  119. A useful function is `org-agenda-add-entry-text'."
  120. :group 'org-agenda-export
  121. :type 'hook
  122. :options '(org-agenda-add-entry-text))
  123. (defcustom org-agenda-add-entry-text-maxlines 0
  124. "Maximum number of entry text lines to be added to agenda.
  125. This is only relevant when `org-agenda-add-entry-text' is part of
  126. `org-agenda-before-write-hook', which it is by default.
  127. When this is 0, nothing will happen. When it is greater than 0, it
  128. specifies the maximum number of lines that will be added for each entry
  129. that is listed in the agenda view.
  130. Note that this variable is not used during display, only when exporting
  131. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  132. and `org-agenda-entry-text-maxlines'."
  133. :group 'org-agenda
  134. :type 'integer)
  135. (defcustom org-agenda-add-entry-text-descriptive-links t
  136. "Non-nil means export org-links as descriptive links in agenda added text.
  137. This variable applies to the text added to the agenda when
  138. `org-agenda-add-entry-text-maxlines' is larger than 0.
  139. When this variable nil, the URL will (also) be shown."
  140. :group 'org-agenda
  141. :type 'boolean)
  142. (defcustom org-agenda-export-html-style ""
  143. "The style specification for exported HTML Agenda files.
  144. If this variable contains a string, it will replace the default <style>
  145. section as produced by `htmlize'.
  146. Since there are different ways of setting style information, this variable
  147. needs to contain the full HTML structure to provide a style, including the
  148. surrounding HTML tags. The style specifications should include definitions
  149. the fonts used by the agenda, here is an example:
  150. <style type=\"text/css\">
  151. p { font-weight: normal; color: gray; }
  152. .org-agenda-structure {
  153. font-size: 110%;
  154. color: #003399;
  155. font-weight: 600;
  156. }
  157. .org-todo {
  158. color: #cc6666;
  159. font-weight: bold;
  160. }
  161. .org-agenda-done {
  162. color: #339933;
  163. }
  164. .org-done {
  165. color: #339933;
  166. }
  167. .title { text-align: center; }
  168. .todo, .deadline { color: red; }
  169. .done { color: green; }
  170. </style>
  171. or, if you want to keep the style in a file,
  172. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  173. As the value of this option simply gets inserted into the HTML <head> header,
  174. you can \"misuse\" it to also add other text to the header. However,
  175. <style>...</style> is required, if not present the variable will be ignored."
  176. :group 'org-agenda-export
  177. :group 'org-export-html
  178. :type 'string)
  179. (defcustom org-agenda-persistent-filter nil
  180. "When set, keep filters from one agenda view to the next."
  181. :group 'org-agenda
  182. :type 'boolean)
  183. (defgroup org-agenda-custom-commands nil
  184. "Options concerning agenda views in Org-mode."
  185. :tag "Org Agenda Custom Commands"
  186. :group 'org-agenda)
  187. (defconst org-sorting-choice
  188. '(choice
  189. (const time-up) (const time-down)
  190. (const category-keep) (const category-up) (const category-down)
  191. (const tag-down) (const tag-up)
  192. (const priority-up) (const priority-down)
  193. (const todo-state-up) (const todo-state-down)
  194. (const effort-up) (const effort-down)
  195. (const habit-up) (const habit-down)
  196. (const alpha-up) (const alpha-down)
  197. (const user-defined-up) (const user-defined-down))
  198. "Sorting choices.")
  199. (defconst org-agenda-custom-commands-local-options
  200. `(repeat :tag "Local settings for this command. Remember to quote values"
  201. (choice :tag "Setting"
  202. (list :tag "Heading for this block"
  203. (const org-agenda-overriding-header)
  204. (string :tag "Headline"))
  205. (list :tag "Files to be searched"
  206. (const org-agenda-files)
  207. (list
  208. (const :format "" quote)
  209. (repeat (file))))
  210. (list :tag "Sorting strategy"
  211. (const org-agenda-sorting-strategy)
  212. (list
  213. (const :format "" quote)
  214. (repeat
  215. ,org-sorting-choice)))
  216. (list :tag "Prefix format"
  217. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  218. (string))
  219. (list :tag "Number of days in agenda"
  220. (const org-agenda-span)
  221. (choice (const :tag "Day" 'day)
  222. (const :tag "Week" 'week)
  223. (const :tag "Month" 'month)
  224. (const :tag "Year" 'year)
  225. (integer :tag "Custom")))
  226. (list :tag "Fixed starting date"
  227. (const org-agenda-start-day)
  228. (string :value "2007-11-01"))
  229. (list :tag "Start on day of week"
  230. (const org-agenda-start-on-weekday)
  231. (choice :value 1
  232. (const :tag "Today" nil)
  233. (integer :tag "Weekday No.")))
  234. (list :tag "Include data from diary"
  235. (const org-agenda-include-diary)
  236. (boolean))
  237. (list :tag "Deadline Warning days"
  238. (const org-deadline-warning-days)
  239. (integer :value 1))
  240. (list :tag "Tags filter preset"
  241. (const org-agenda-filter-preset)
  242. (list
  243. (const :format "" quote)
  244. (repeat
  245. (string :tag "+tag or -tag"))))
  246. (list :tag "Set daily/weekly entry types"
  247. (const org-agenda-entry-types)
  248. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  249. (const :deadline)
  250. (const :scheduled)
  251. (const :timestamp)
  252. (const :sexp)))
  253. (list :tag "Standard skipping condition"
  254. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  255. (const org-agenda-skip-function)
  256. (list
  257. (const :format "" quote)
  258. (list
  259. (choice
  260. :tag "Skipping range"
  261. (const :tag "Skip entry" org-agenda-skip-entry-if)
  262. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  263. (repeat :inline t :tag "Conditions for skipping"
  264. (choice
  265. :tag "Condition type"
  266. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  267. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  268. (list :tag "TODO state is" :inline t
  269. (const 'todo)
  270. (choice
  271. (const :tag "any not-done state" 'todo)
  272. (const :tag "any done state" 'done)
  273. (const :tag "any state" 'any)
  274. (list :tag "Keyword list"
  275. (const :format "" quote)
  276. (repeat (string :tag "Keyword")))))
  277. (list :tag "TODO state is not" :inline t
  278. (const 'nottodo)
  279. (choice
  280. (const :tag "any not-done state" 'todo)
  281. (const :tag "any done state" 'done)
  282. (const :tag "any state" 'any)
  283. (list :tag "Keyword list"
  284. (const :format "" quote)
  285. (repeat (string :tag "Keyword")))))
  286. (const :tag "scheduled" 'scheduled)
  287. (const :tag "not scheduled" 'notscheduled)
  288. (const :tag "deadline" 'deadline)
  289. (const :tag "no deadline" 'notdeadline)
  290. (const :tag "timestamp" 'timestamp)
  291. (const :tag "no timestamp" 'nottimestamp))))))
  292. (list :tag "Non-standard skipping condition"
  293. :value (org-agenda-skip-function)
  294. (const org-agenda-skip-function)
  295. (sexp :tag "Function or form (quoted!)"))
  296. (list :tag "Any variable"
  297. (variable :tag "Variable")
  298. (sexp :tag "Value (sexp)"))))
  299. "Selection of examples for agenda command settings.
  300. This will be spliced into the custom type of
  301. `org-agenda-custom-commands'.")
  302. (defcustom org-agenda-custom-commands nil
  303. "Custom commands for the agenda.
  304. These commands will be offered on the splash screen displayed by the
  305. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  306. (key desc type match settings files)
  307. key The key (one or more characters as a string) to be associated
  308. with the command.
  309. desc A description of the command, when omitted or nil, a default
  310. description is built using MATCH.
  311. type The command type, any of the following symbols:
  312. agenda The daily/weekly agenda.
  313. todo Entries with a specific TODO keyword, in all agenda files.
  314. search Entries containing search words entry or headline.
  315. tags Tags/Property/TODO match in all agenda files.
  316. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  317. todo-tree Sparse tree of specific TODO keyword in *current* file.
  318. tags-tree Sparse tree with all tags matches in *current* file.
  319. occur-tree Occur sparse tree for *current* file.
  320. ... A user-defined function.
  321. match What to search for:
  322. - a single keyword for TODO keyword searches
  323. - a tags match expression for tags searches
  324. - a word search expression for text searches.
  325. - a regular expression for occur searches
  326. For all other commands, this should be the empty string.
  327. settings A list of option settings, similar to that in a let form, so like
  328. this: ((opt1 val1) (opt2 val2) ...). The values will be
  329. evaluated at the moment of execution, so quote them when needed.
  330. files A list of files file to write the produced agenda buffer to
  331. with the command `org-store-agenda-views'.
  332. If a file name ends in \".html\", an HTML version of the buffer
  333. is written out. If it ends in \".ps\", a postscript version is
  334. produced. Otherwise, only the plain text is written to the file.
  335. You can also define a set of commands, to create a composite agenda buffer.
  336. In this case, an entry looks like this:
  337. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  338. where
  339. desc A description string to be displayed in the dispatcher menu.
  340. cmd An agenda command, similar to the above. However, tree commands
  341. are no allowed, but instead you can get agenda and global todo list.
  342. So valid commands for a set are:
  343. (agenda \"\" settings)
  344. (alltodo \"\" settings)
  345. (stuck \"\" settings)
  346. (todo \"match\" settings files)
  347. (search \"match\" settings files)
  348. (tags \"match\" settings files)
  349. (tags-todo \"match\" settings files)
  350. Each command can carry a list of options, and another set of options can be
  351. given for the whole set of commands. Individual command options take
  352. precedence over the general options.
  353. When using several characters as key to a command, the first characters
  354. are prefix commands. For the dispatcher to display useful information, you
  355. should provide a description for the prefix, like
  356. (setq org-agenda-custom-commands
  357. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  358. (\"hl\" tags \"+HOME+Lisa\")
  359. (\"hp\" tags \"+HOME+Peter\")
  360. (\"hk\" tags \"+HOME+Kim\")))"
  361. :group 'org-agenda-custom-commands
  362. :type `(repeat
  363. (choice :value ("x" "Describe command here" tags "" nil)
  364. (list :tag "Single command"
  365. (string :tag "Access Key(s) ")
  366. (option (string :tag "Description"))
  367. (choice
  368. (const :tag "Agenda" agenda)
  369. (const :tag "TODO list" alltodo)
  370. (const :tag "Search words" search)
  371. (const :tag "Stuck projects" stuck)
  372. (const :tag "Tags/Property match (all agenda files)" tags)
  373. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  374. (const :tag "TODO keyword search (all agenda files)" todo)
  375. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  376. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  377. (const :tag "Occur tree (current buffer)" occur-tree)
  378. (sexp :tag "Other, user-defined function"))
  379. (string :tag "Match (only for some commands)")
  380. ,org-agenda-custom-commands-local-options
  381. (option (repeat :tag "Export" (file :tag "Export to"))))
  382. (list :tag "Command series, all agenda files"
  383. (string :tag "Access Key(s)")
  384. (string :tag "Description ")
  385. (repeat :tag "Component"
  386. (choice
  387. (list :tag "Agenda"
  388. (const :format "" agenda)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "TODO list (all keywords)"
  392. (const :format "" alltodo)
  393. (const :tag "" :format "" "")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Search words"
  396. (const :format "" search)
  397. (string :tag "Match")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Stuck projects"
  400. (const :format "" stuck)
  401. (const :tag "" :format "" "")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search"
  404. (const :format "" tags)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "Tags search, TODO entries only"
  408. (const :format "" tags-todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "TODO keyword search"
  412. (const :format "" todo)
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)
  415. (list :tag "Other, user-defined function"
  416. (symbol :tag "function")
  417. (string :tag "Match")
  418. ,org-agenda-custom-commands-local-options)))
  419. (repeat :tag "Settings for entire command set"
  420. (list (variable :tag "Any variable")
  421. (sexp :tag "Value")))
  422. (option (repeat :tag "Export" (file :tag "Export to"))))
  423. (cons :tag "Prefix key documentation"
  424. (string :tag "Access Key(s)")
  425. (string :tag "Description ")))))
  426. (defcustom org-agenda-query-register ?o
  427. "The register holding the current query string.
  428. The purpose of this is that if you construct a query string interactively,
  429. you can then use it to define a custom command."
  430. :group 'org-agenda-custom-commands
  431. :type 'character)
  432. (defcustom org-stuck-projects
  433. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  434. "How to identify stuck projects.
  435. This is a list of four items:
  436. 1. A tags/todo/property matcher string that is used to identify a project.
  437. See the manual for a description of tag and property searches.
  438. The entire tree below a headline matched by this is considered one project.
  439. 2. A list of TODO keywords identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these todo
  441. keywords, the project is considered to be not stuck. If you specify
  442. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  443. 3. A list of tags identifying non-stuck projects.
  444. If the project subtree contains any headline with one of these tags,
  445. the project is considered to be not stuck. If you specify \"*\" as
  446. a tag, any tag will mark the project unstuck. Note that this is about
  447. the explicit presence of a tag somewhere in the subtree, inherited
  448. tags to not count here. If inherited tags make a project not stuck,
  449. use \"-TAG\" in the tags part of the matcher under (1.) above.
  450. 4. An arbitrary regular expression matching non-stuck projects.
  451. If the project turns out to be not stuck, search continues also in the
  452. subtree to see if any of the subtasks have project status.
  453. See also the variable `org-tags-match-list-sublevels' which applies
  454. to projects matched by this search as well.
  455. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  456. or `C-c a #' to produce the list."
  457. :group 'org-agenda-custom-commands
  458. :type '(list
  459. (string :tag "Tags/TODO match to identify a project")
  460. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  461. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  462. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  463. (defcustom org-agenda-filter-effort-default-operator "<"
  464. "The default operator for effort estimate filtering.
  465. If you select an effort estimate limit without first pressing an operator,
  466. this one will be used."
  467. :group 'org-agenda-custom-commands
  468. :type '(choice (const :tag "less or equal" "<")
  469. (const :tag "greater or equal"">")
  470. (const :tag "equal" "=")))
  471. (defgroup org-agenda-skip nil
  472. "Options concerning skipping parts of agenda files."
  473. :tag "Org Agenda Skip"
  474. :group 'org-agenda)
  475. (defcustom org-agenda-skip-function-global nil
  476. "Function to be called at each match during agenda construction.
  477. If this function returns nil, the current match should not be skipped.
  478. If the function decided to skip an agenda match, is must return the
  479. buffer position from which the search should be continued.
  480. This may also be a Lisp form, which will be evaluated.
  481. This variable will be applied to every agenda match, including
  482. tags/property searches and TODO lists. So try to make the test function
  483. do its checking as efficiently as possible. To implement a skipping
  484. condition just for specific agenda commands, use the variable
  485. `org-agenda-skip-function' which can be set in the options section
  486. of custom agenda commands."
  487. :group 'org-agenda-skip
  488. :type 'sexp)
  489. (defgroup org-agenda-daily/weekly nil
  490. "Options concerning the daily/weekly agenda."
  491. :tag "Org Agenda Daily/Weekly"
  492. :group 'org-agenda)
  493. (defgroup org-agenda-todo-list nil
  494. "Options concerning the global todo list agenda view."
  495. :tag "Org Agenda Todo List"
  496. :group 'org-agenda)
  497. (defgroup org-agenda-match-view nil
  498. "Options concerning the general tags/property/todo match agenda view."
  499. :tag "Org Agenda Match View"
  500. :group 'org-agenda)
  501. (defgroup org-agenda-search-view nil
  502. "Options concerning the general tags/property/todo match agenda view."
  503. :tag "Org Agenda Match View"
  504. :group 'org-agenda)
  505. (defvar org-agenda-archives-mode nil
  506. "Non-nil means the agenda will include archived items.
  507. If this is the symbol `trees', trees in the selected agenda scope
  508. that are marked with the ARCHIVE tag will be included anyway. When this is
  509. t, also all archive files associated with the current selection of agenda
  510. files will be included.")
  511. (defcustom org-agenda-skip-comment-trees t
  512. "Non-nil means skip trees that start with the COMMENT keyword.
  513. When nil, these trees are also scanned by agenda commands."
  514. :group 'org-agenda-skip
  515. :type 'boolean)
  516. (defcustom org-agenda-todo-list-sublevels t
  517. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  518. When nil, the sublevels of a TODO entry are not checked, resulting in
  519. potentially much shorter TODO lists."
  520. :group 'org-agenda-skip
  521. :group 'org-agenda-todo-list
  522. :type 'boolean)
  523. (defcustom org-agenda-todo-ignore-with-date nil
  524. "Non-nil means don't show entries with a date in the global todo list.
  525. You can use this if you prefer to mark mere appointments with a TODO keyword,
  526. but don't want them to show up in the TODO list.
  527. When this is set, it also covers deadlines and scheduled items, the settings
  528. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  529. will be ignored.
  530. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  531. :group 'org-agenda-skip
  532. :group 'org-agenda-todo-list
  533. :type 'boolean)
  534. (defcustom org-agenda-todo-ignore-timestamp nil
  535. "Non-nil means don't show entries with a timestamp.
  536. This applies when creating the global todo list.
  537. Valid values are:
  538. past Don't show entries for today or in the past.
  539. future Don't show entries with a timestamp in the future.
  540. The idea behind this is that if it has a future
  541. timestamp, you don't want to think about it until the
  542. date.
  543. all Don't show any entries with a timestamp in the global todo list.
  544. The idea behind this is that by setting a timestamp, you
  545. have already \"taken care\" of this item.
  546. This variable can also have an integer as a value. If positive (N),
  547. todos with a timestamp N or more days in the future will be ignored. If
  548. negative (-N), todos with a timestamp N or more days in the past will be
  549. ignored. If 0, todos with a timestamp either today or in the future will
  550. be ignored. For example, a value of -1 will exclude todos with a
  551. timestamp in the past (yesterday or earlier), while a value of 7 will
  552. exclude todos with a timestamp a week or more in the future.
  553. See also `org-agenda-todo-ignore-with-date'.
  554. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  555. to make his option also apply to the tags-todo list."
  556. :group 'org-agenda-skip
  557. :group 'org-agenda-todo-list
  558. :type '(choice
  559. (const :tag "Ignore future timestamp todos" future)
  560. (const :tag "Ignore past or present timestamp todos" past)
  561. (const :tag "Ignore all timestamp todos" all)
  562. (const :tag "Show timestamp todos" nil)
  563. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  564. (defcustom org-agenda-todo-ignore-scheduled nil
  565. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  566. This applies when creating the global todo list.
  567. Valid values are:
  568. past Don't show entries scheduled today or in the past.
  569. future Don't show entries scheduled in the future.
  570. The idea behind this is that by scheduling it, you don't want to
  571. think about it until the scheduled date.
  572. all Don't show any scheduled entries in the global todo list.
  573. The idea behind this is that by scheduling it, you have already
  574. \"taken care\" of this item.
  575. t Same as `all', for backward compatibility.
  576. This variable can also have an integer as a value. See
  577. `org-agenda-todo-ignore-timestamp' for more details.
  578. See also `org-agenda-todo-ignore-with-date'.
  579. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  580. to make his option also apply to the tags-todo list."
  581. :group 'org-agenda-skip
  582. :group 'org-agenda-todo-list
  583. :type '(choice
  584. (const :tag "Ignore future-scheduled todos" future)
  585. (const :tag "Ignore past- or present-scheduled todos" past)
  586. (const :tag "Ignore all scheduled todos" all)
  587. (const :tag "Ignore all scheduled todos (compatibility)" t)
  588. (const :tag "Show scheduled todos" nil)
  589. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  590. (defcustom org-agenda-todo-ignore-deadlines nil
  591. "Non-nil means ignore some deadlined TODO items when making TODO list.
  592. There are different motivations for using different values, please think
  593. carefully when configuring this variable.
  594. This applies when creating the global todo list.
  595. Valid values are:
  596. near Don't show near deadline entries. A deadline is near when it is
  597. closer than `org-deadline-warning-days' days. The idea behind this
  598. is that such items will appear in the agenda anyway.
  599. far Don't show TODO entries where a deadline has been defined, but
  600. the deadline is not near. This is useful if you don't want to
  601. use the todo list to figure out what to do now.
  602. past Don't show entries with a deadline timestamp for today or in the past.
  603. future Don't show entries with a deadline timestamp in the future, not even
  604. when they become `near' ones. Use it with caution.
  605. all Ignore all TODO entries that do have a deadline.
  606. t Same as `near', for backward compatibility.
  607. This variable can also have an integer as a value. See
  608. `org-agenda-todo-ignore-timestamp' for more details.
  609. See also `org-agenda-todo-ignore-with-date'.
  610. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  611. to make his option also apply to the tags-todo list."
  612. :group 'org-agenda-skip
  613. :group 'org-agenda-todo-list
  614. :type '(choice
  615. (const :tag "Ignore near deadlines" near)
  616. (const :tag "Ignore near deadlines (compatibility)" t)
  617. (const :tag "Ignore far deadlines" far)
  618. (const :tag "Ignore all TODOs with a deadlines" all)
  619. (const :tag "Show all TODOs, even if they have a deadline" nil)
  620. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  621. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  622. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  623. The variables
  624. `org-agenda-todo-ignore-with-date',
  625. `org-agenda-todo-ignore-timestamp',
  626. `org-agenda-todo-ignore-scheduled',
  627. `org-agenda-todo-ignore-deadlines'
  628. make the global TODO list skip entries that have time stamps of certain
  629. kinds. If this option is set, the same options will also apply for the
  630. tags-todo search, which is the general tags/property matcher
  631. restricted to unfinished TODO entries only."
  632. :group 'org-agenda-skip
  633. :group 'org-agenda-todo-list
  634. :group 'org-agenda-match-view
  635. :type 'boolean)
  636. (defcustom org-agenda-skip-scheduled-if-done nil
  637. "Non-nil means don't show scheduled items in agenda when they are done.
  638. This is relevant for the daily/weekly agenda, not for the TODO list. And
  639. it applies only to the actual date of the scheduling. Warnings about
  640. an item with a past scheduling dates are always turned off when the item
  641. is DONE."
  642. :group 'org-agenda-skip
  643. :group 'org-agenda-daily/weekly
  644. :type 'boolean)
  645. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  646. "Non-nil means skip scheduling line if same entry shows because of deadline.
  647. In the agenda of today, an entry can show up multiple times because
  648. it is both scheduled and has a nearby deadline, and maybe a plain time
  649. stamp as well.
  650. When this variable is t, then only the deadline is shown and the fact that
  651. the entry is scheduled today or was scheduled previously is not shown.
  652. When this variable is nil, the entry will be shown several times. When
  653. the variable is the symbol `not-today', then skip scheduled previously,
  654. but not scheduled today."
  655. :group 'org-agenda-skip
  656. :group 'org-agenda-daily/weekly
  657. :type '(choice
  658. (const :tag "Never" nil)
  659. (const :tag "Always" t)
  660. (const :tag "Not when scheduled today" not-today)))
  661. (defcustom org-agenda-skip-deadline-if-done nil
  662. "Non-nil means don't show deadlines when the corresponding item is done.
  663. When nil, the deadline is still shown and should give you a happy feeling.
  664. This is relevant for the daily/weekly agenda. And it applied only to the
  665. actually date of the deadline. Warnings about approaching and past-due
  666. deadlines are always turned off when the item is DONE."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-daily/weekly
  669. :type 'boolean)
  670. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  671. "Non-nil means skip deadline prewarning when entry is also scheduled.
  672. This will apply on all days where a prewarning for the deadline would
  673. be shown, but not at the day when the entry is actually due. On that day,
  674. the deadline will be shown anyway.
  675. This variable may be set to nil, t, or a number which will then give
  676. the number of days before the actual deadline when the prewarnings
  677. should resume.
  678. This can be used in a workflow where the first showing of the deadline will
  679. trigger you to schedule it, and then you don't want to be reminded of it
  680. because you will take care of it on the day when scheduled."
  681. :group 'org-agenda-skip
  682. :group 'org-agenda-daily/weekly
  683. :type '(choice
  684. (const :tag "Alwas show prewarning" nil)
  685. (const :tag "Remove prewarning if entry is scheduled" t)
  686. (integer :tag "Restart prewarning N days before deadline")))
  687. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  688. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  689. When non-nil, after the search for timestamps has matched once in an
  690. entry, the rest of the entry will not be searched."
  691. :group 'org-agenda-skip
  692. :type 'boolean)
  693. (defcustom org-agenda-skip-timestamp-if-done nil
  694. "Non-nil means don't select item by timestamp or -range if it is DONE."
  695. :group 'org-agenda-skip
  696. :group 'org-agenda-daily/weekly
  697. :type 'boolean)
  698. (defcustom org-agenda-dim-blocked-tasks t
  699. "Non-nil means dim blocked tasks in the agenda display.
  700. This causes some overhead during agenda construction, but if you
  701. have turned on `org-enforce-todo-dependencies',
  702. `org-enforce-todo-checkbox-dependencies', or any other blocking
  703. mechanism, this will create useful feedback in the agenda.
  704. Instead of t, this variable can also have the value `invisible'.
  705. Then blocked tasks will be invisible and only become visible when
  706. they become unblocked. An exemption to this behavior is when a task is
  707. blocked because of unchecked checkboxes below it. Since checkboxes do
  708. not show up in the agenda views, making this task invisible you remove any
  709. trace from agenda views that there is something to do. Therefore, a task
  710. that is blocked because of checkboxes will never be made invisible, it
  711. will only be dimmed."
  712. :group 'org-agenda-daily/weekly
  713. :group 'org-agenda-todo-list
  714. :type '(choice
  715. (const :tag "Do not dim" nil)
  716. (const :tag "Dim to a grey face" t)
  717. (const :tag "Make invisible" invisible)))
  718. (defcustom org-timeline-show-empty-dates 3
  719. "Non-nil means `org-timeline' also shows dates without an entry.
  720. When nil, only the days which actually have entries are shown.
  721. When t, all days between the first and the last date are shown.
  722. When an integer, show also empty dates, but if there is a gap of more than
  723. N days, just insert a special line indicating the size of the gap."
  724. :group 'org-agenda-skip
  725. :type '(choice
  726. (const :tag "None" nil)
  727. (const :tag "All" t)
  728. (integer :tag "at most")))
  729. (defgroup org-agenda-startup nil
  730. "Options concerning initial settings in the Agenda in Org Mode."
  731. :tag "Org Agenda Startup"
  732. :group 'org-agenda)
  733. (defcustom org-agenda-menu-show-matcher t
  734. "Non-nil means show the match string in the agenda dispatcher menu.
  735. When nil, the matcher string is not shown, but is put into the help-echo
  736. property so than moving the mouse over the command shows it.
  737. Setting it to nil is good if matcher strings are very long and/or if
  738. you want to use two-column display (see `org-agenda-menu-two-column')."
  739. :group 'org-agenda
  740. :type 'boolean)
  741. (defcustom org-agenda-menu-two-column nil
  742. "Non-nil means, use two columns to show custom commands in the dispatcher.
  743. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  744. to nil."
  745. :group 'org-agenda
  746. :type 'boolean)
  747. (defcustom org-finalize-agenda-hook nil
  748. "Hook run just before displaying an agenda buffer."
  749. :group 'org-agenda-startup
  750. :type 'hook)
  751. (defcustom org-agenda-mouse-1-follows-link nil
  752. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  753. A longer mouse click will still set point. Does not work on XEmacs.
  754. Needs to be set before org.el is loaded."
  755. :group 'org-agenda-startup
  756. :type 'boolean)
  757. (defcustom org-agenda-start-with-follow-mode nil
  758. "The initial value of follow mode in a newly created agenda window."
  759. :group 'org-agenda-startup
  760. :type 'boolean)
  761. (defcustom org-agenda-show-outline-path t
  762. "Non-nil means show outline path in echo area after line motion."
  763. :group 'org-agenda-startup
  764. :type 'boolean)
  765. (defcustom org-agenda-start-with-entry-text-mode nil
  766. "The initial value of entry-text-mode in a newly created agenda window."
  767. :group 'org-agenda-startup
  768. :type 'boolean)
  769. (defcustom org-agenda-entry-text-maxlines 5
  770. "Number of text lines to be added when `E' is pressed in the agenda.
  771. Note that this variable only used during agenda display. Add add entry text
  772. when exporting the agenda, configure the variable
  773. `org-agenda-add-entry-ext-maxlines'."
  774. :group 'org-agenda
  775. :type 'integer)
  776. (defcustom org-agenda-entry-text-exclude-regexps nil
  777. "List of regular expressions to clean up entry text.
  778. The complete matches of all regular expressions in this list will be
  779. removed from entry text before it is shown in the agenda."
  780. :group 'org-agenda
  781. :type '(repeat (regexp)))
  782. (defvar org-agenda-entry-text-cleanup-hook nil
  783. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  784. This cleanup is done in a temporary buffer, so the function may inspect and
  785. change the entire buffer.
  786. Some default stuff like drawers and scheduling/deadline dates will already
  787. have been removed when this is called, as will any matches for regular
  788. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  789. (defvar org-agenda-include-inactive-timestamps nil
  790. "Non-nil means include inactive time stamps in agenda and timeline.")
  791. (defgroup org-agenda-windows nil
  792. "Options concerning the windows used by the Agenda in Org Mode."
  793. :tag "Org Agenda Windows"
  794. :group 'org-agenda)
  795. (defcustom org-agenda-window-setup 'reorganize-frame
  796. "How the agenda buffer should be displayed.
  797. Possible values for this option are:
  798. current-window Show agenda in the current window, keeping all other windows.
  799. other-window Use `switch-to-buffer-other-window' to display agenda.
  800. reorganize-frame Show only two windows on the current frame, the current
  801. window and the agenda.
  802. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  803. Also, when exiting the agenda, kill that frame.
  804. See also the variable `org-agenda-restore-windows-after-quit'."
  805. :group 'org-agenda-windows
  806. :type '(choice
  807. (const current-window)
  808. (const other-frame)
  809. (const other-window)
  810. (const reorganize-frame)))
  811. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  812. "The min and max height of the agenda window as a fraction of frame height.
  813. The value of the variable is a cons cell with two numbers between 0 and 1.
  814. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  815. :group 'org-agenda-windows
  816. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  817. (defcustom org-agenda-restore-windows-after-quit nil
  818. "Non-nil means restore window configuration upon exiting agenda.
  819. Before the window configuration is changed for displaying the agenda,
  820. the current status is recorded. When the agenda is exited with
  821. `q' or `x' and this option is set, the old state is restored. If
  822. `org-agenda-window-setup' is `other-frame', the value of this
  823. option will be ignored."
  824. :group 'org-agenda-windows
  825. :type 'boolean)
  826. (defcustom org-agenda-ndays nil
  827. "Number of days to include in overview display.
  828. Should be 1 or 7.
  829. Obsolete, see `org-agenda-span'."
  830. :group 'org-agenda-daily/weekly
  831. :type 'integer)
  832. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  833. (defcustom org-agenda-span 'week
  834. "Number of days to include in overview display.
  835. Can be day, week, month, year, or any number of days.
  836. Custom commands can set this variable in the options section."
  837. :group 'org-agenda-daily/weekly
  838. :type '(choice (const :tag "Day" day)
  839. (const :tag "Week" week)
  840. (const :tag "Month" month)
  841. (const :tag "Year" year)
  842. (integer :tag "Custom")))
  843. (defcustom org-agenda-start-on-weekday 1
  844. "Non-nil means start the overview always on the specified weekday.
  845. 0 denotes Sunday, 1 denotes Monday etc.
  846. When nil, always start on the current day.
  847. Custom commands can set this variable in the options section."
  848. :group 'org-agenda-daily/weekly
  849. :type '(choice (const :tag "Today" nil)
  850. (integer :tag "Weekday No.")))
  851. (defcustom org-agenda-show-all-dates t
  852. "Non-nil means `org-agenda' shows every day in the selected range.
  853. When nil, only the days which actually have entries are shown."
  854. :group 'org-agenda-daily/weekly
  855. :type 'boolean)
  856. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  857. "Format string for displaying dates in the agenda.
  858. Used by the daily/weekly agenda and by the timeline. This should be
  859. a format string understood by `format-time-string', or a function returning
  860. the formatted date as a string. The function must take a single argument,
  861. a calendar-style date list like (month day year)."
  862. :group 'org-agenda-daily/weekly
  863. :type '(choice
  864. (string :tag "Format string")
  865. (function :tag "Function")))
  866. (defun org-agenda-format-date-aligned (date)
  867. "Format a date string for display in the daily/weekly agenda, or timeline.
  868. This function makes sure that dates are aligned for easy reading."
  869. (require 'cal-iso)
  870. (let* ((dayname (calendar-day-name date))
  871. (day (cadr date))
  872. (day-of-week (calendar-day-of-week date))
  873. (month (car date))
  874. (monthname (calendar-month-name month))
  875. (year (nth 2 date))
  876. (iso-week (org-days-to-iso-week
  877. (calendar-absolute-from-gregorian date)))
  878. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  879. (1- year))
  880. ((and (= month 12) (<= iso-week 1))
  881. (1+ year))
  882. (t year)))
  883. (weekstring (if (= day-of-week 1)
  884. (format " W%02d" iso-week)
  885. "")))
  886. (format "%-10s %2d %s %4d%s"
  887. dayname day monthname year weekstring)))
  888. (defcustom org-agenda-time-leading-zero nil
  889. "Non-nil means use leading zero for military times in agenda.
  890. For example, 9:30am would become 09:30 rather than 9:30."
  891. :group 'org-agenda-daily/weekly
  892. :type 'boolean)
  893. (defcustom org-agenda-timegrid-use-ampm nil
  894. "When set, show AM/PM style timestamps on the timegrid."
  895. :group 'org-agenda
  896. :type 'boolean)
  897. (defun org-agenda-time-of-day-to-ampm (time)
  898. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  899. (let* ((hour-number (string-to-number (substring time 0 -3)))
  900. (minute (substring time -2))
  901. (ampm "am"))
  902. (cond
  903. ((equal hour-number 12)
  904. (setq ampm "pm"))
  905. ((> hour-number 12)
  906. (setq ampm "pm")
  907. (setq hour-number (- hour-number 12))))
  908. (concat
  909. (if org-agenda-time-leading-zero
  910. (format "%02d" hour-number)
  911. (format "%02s" (number-to-string hour-number)))
  912. ":" minute ampm)))
  913. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  914. "Conditionally convert TIME to AM/PM format
  915. based on `org-agenda-timegrid-use-ampm'"
  916. (if org-agenda-timegrid-use-ampm
  917. (org-agenda-time-of-day-to-ampm time)
  918. time))
  919. (defcustom org-agenda-weekend-days '(6 0)
  920. "Which days are weekend?
  921. These days get the special face `org-agenda-date-weekend' in the agenda
  922. and timeline buffers."
  923. :group 'org-agenda-daily/weekly
  924. :type '(set :greedy t
  925. (const :tag "Monday" 1)
  926. (const :tag "Tuesday" 2)
  927. (const :tag "Wednesday" 3)
  928. (const :tag "Thursday" 4)
  929. (const :tag "Friday" 5)
  930. (const :tag "Saturday" 6)
  931. (const :tag "Sunday" 0)))
  932. (defcustom org-agenda-include-diary nil
  933. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  934. Custom commands can set this variable in the options section."
  935. :group 'org-agenda-daily/weekly
  936. :type 'boolean)
  937. (defcustom org-agenda-include-deadlines t
  938. "If non-nil, include entries within their deadline warning period.
  939. Custom commands can set this variable in the options section."
  940. :group 'org-agenda-daily/weekly
  941. :type 'boolean)
  942. (defcustom org-agenda-include-all-todo nil
  943. "Set means weekly/daily agenda will always contain all TODO entries.
  944. The TODO entries will be listed at the top of the agenda, before
  945. the entries for specific days.
  946. This option is deprecated, it is better to define a block agenda instead."
  947. :group 'org-agenda-daily/weekly
  948. :type 'boolean)
  949. (defcustom org-agenda-repeating-timestamp-show-all t
  950. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  951. When set to a list of strings, only show occurrences of repeating
  952. stamps for these TODO keywords. When nil, only one occurrence is
  953. shown, either today or the nearest into the future."
  954. :group 'org-agenda-daily/weekly
  955. :type '(choice
  956. (const :tag "Show repeating stamps" t)
  957. (repeat :tag "Show repeating stamps for these TODO keywords"
  958. (string :tag "TODO Keyword"))
  959. (const :tag "Don't show repeating stamps" nil)))
  960. (defcustom org-scheduled-past-days 10000
  961. "No. of days to continue listing scheduled items that are not marked DONE.
  962. When an item is scheduled on a date, it shows up in the agenda on this
  963. day and will be listed until it is marked done for the number of days
  964. given here."
  965. :group 'org-agenda-daily/weekly
  966. :type 'integer)
  967. (defcustom org-agenda-log-mode-items '(closed clock)
  968. "List of items that should be shown in agenda log mode.
  969. This list may contain the following symbols:
  970. closed Show entries that have been closed on that day.
  971. clock Show entries that have received clocked time on that day.
  972. state Show all logged state changes.
  973. Note that instead of changing this variable, you can also press `C-u l' in
  974. the agenda to display all available LOG items temporarily."
  975. :group 'org-agenda-daily/weekly
  976. :type '(set :greedy t (const closed) (const clock) (const state)))
  977. (defcustom org-agenda-clock-consistency-checks
  978. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  979. :gap-ok-around ("4:00")
  980. :default-face ((:background "DarkRed") (:foreground "white"))
  981. :overlap-face nil :gap-face nil :no-end-time-face nil
  982. :long-face nil :short-face nil)
  983. "This is a property list, with the following keys:
  984. :max-duration Mark clocking chunks that are longer than this time.
  985. This is a time string like \"HH:MM\", or the number
  986. of minutes as an integer.
  987. :min-duration Mark clocking chunks that are shorter that this.
  988. This is a time string like \"HH:MM\", or the number
  989. of minutes as an integer.
  990. :max-gap Mark gaps between clocking chunks that are longer than
  991. this duration. A number of minutes, or a string
  992. like \"HH:MM\".
  993. :gap-ok-around List of times during the day which are usually not working
  994. times. When a gap is detected, but the gap contains any
  995. of these times, the gap is *not* reported. For example,
  996. if this is (\"4:00\" \"13:00\") then gaps that contain
  997. 4:00 in the morning (i.e. the night) and 13:00
  998. (i.e. a typical lunch time) do not cause a warning.
  999. You should have at least one time during the night in this
  1000. list, or otherwise the first task each morning will trigger
  1001. a warning because it follows a long gap.
  1002. Furthermore, the following properties can be used to define faces for
  1003. issue display.
  1004. :default-face the default face, if the specific face is undefined
  1005. :overlap-face face for overlapping clocks
  1006. :gap-face face for gaps between clocks
  1007. :no-end-time-face face for incomplete clocks
  1008. :long-face face for clock intervals that are too long
  1009. :short-face face for clock intervals that are too short"
  1010. :group 'org-agenda-daily/weekly
  1011. :group 'org-clock
  1012. :type 'plist)
  1013. (defcustom org-agenda-log-mode-add-notes t
  1014. "Non-nil means add first line of notes to log entries in agenda views.
  1015. If a log item like a state change or a clock entry is associated with
  1016. notes, the first line of these notes will be added to the entry in the
  1017. agenda display."
  1018. :group 'org-agenda-daily/weekly
  1019. :type 'boolean)
  1020. (defcustom org-agenda-start-with-log-mode nil
  1021. "The initial value of log-mode in a newly created agenda window."
  1022. :group 'org-agenda-startup
  1023. :group 'org-agenda-daily/weekly
  1024. :type 'boolean)
  1025. (defcustom org-agenda-start-with-clockreport-mode nil
  1026. "The initial value of clockreport-mode in a newly created agenda window."
  1027. :group 'org-agenda-startup
  1028. :group 'org-agenda-daily/weekly
  1029. :type 'boolean)
  1030. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1031. "Property list with parameters for the clocktable in clockreport mode.
  1032. This is the display mode that shows a clock table in the daily/weekly
  1033. agenda, the properties for this dynamic block can be set here.
  1034. The usual clocktable parameters are allowed here, but you cannot set
  1035. the properties :name, :tstart, :tend, :block, and :scope - these will
  1036. be overwritten to make sure the content accurately reflects the
  1037. current display in the agenda."
  1038. :group 'org-agenda-daily/weekly
  1039. :type 'plist)
  1040. (defcustom org-agenda-search-view-always-boolean nil
  1041. "Non-nil means the search string is interpreted as individual parts.
  1042. The search string for search view can either be interpreted as a phrase,
  1043. or as a list of snippets that define a boolean search for a number of
  1044. strings.
  1045. When this is non-nil, the string will be split on whitespace, and each
  1046. snippet will be searched individually, and all must match in order to
  1047. select an entry. A snippet is then a single string of non-white
  1048. characters, or a string in double quotes, or a regexp in {} braces.
  1049. If a snippet is preceded by \"-\", the snippet must *not* match.
  1050. \"+\" is syntactic sugar for positive selection. Each snippet may
  1051. be found as a full word or a partial word, but see the variable
  1052. `org-agenda-search-view-force-full-words'.
  1053. When this is nil, search will look for the entire search phrase as one,
  1054. with each space character matching any amount of whitespace, including
  1055. line breaks.
  1056. Even when this is nil, you can still switch to Boolean search dynamically
  1057. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1058. is a regexp marked with braces like \"{abc}\", this will also switch to
  1059. boolean search."
  1060. :group 'org-agenda-search-view
  1061. :type 'boolean)
  1062. (if (fboundp 'defvaralias)
  1063. (defvaralias 'org-agenda-search-view-search-words-only
  1064. 'org-agenda-search-view-always-boolean))
  1065. (defcustom org-agenda-search-view-force-full-words nil
  1066. "Non-nil means, search words must be matches as complete words.
  1067. When nil, they may also match part of a word."
  1068. :group 'org-agenda-search-view
  1069. :type 'boolean)
  1070. (defgroup org-agenda-time-grid nil
  1071. "Options concerning the time grid in the Org-mode Agenda."
  1072. :tag "Org Agenda Time Grid"
  1073. :group 'org-agenda)
  1074. (defcustom org-agenda-search-headline-for-time t
  1075. "Non-nil means search headline for a time-of-day.
  1076. If the headline contains a time-of-day in one format or another, it will
  1077. be used to sort the entry into the time sequence of items for a day.
  1078. Some people have time stamps in the headline that refer to the creation
  1079. time or so, and then this produces an unwanted side effect. If this is
  1080. the case for your, use this variable to turn off searching the headline
  1081. for a time."
  1082. :group 'org-agenda-time-grid
  1083. :type 'boolean)
  1084. (defcustom org-agenda-use-time-grid t
  1085. "Non-nil means show a time grid in the agenda schedule.
  1086. A time grid is a set of lines for specific times (like every two hours between
  1087. 8:00 and 20:00). The items scheduled for a day at specific times are
  1088. sorted in between these lines.
  1089. For details about when the grid will be shown, and what it will look like, see
  1090. the variable `org-agenda-time-grid'."
  1091. :group 'org-agenda-time-grid
  1092. :type 'boolean)
  1093. (defcustom org-agenda-time-grid
  1094. '((daily today require-timed)
  1095. "----------------"
  1096. (800 1000 1200 1400 1600 1800 2000))
  1097. "The settings for time grid for agenda display.
  1098. This is a list of three items. The first item is again a list. It contains
  1099. symbols specifying conditions when the grid should be displayed:
  1100. daily if the agenda shows a single day
  1101. weekly if the agenda shows an entire week
  1102. today show grid on current date, independent of daily/weekly display
  1103. require-timed show grid only if at least one item has a time specification
  1104. The second item is a string which will be placed behind the grid time.
  1105. The third item is a list of integers, indicating the times that should have
  1106. a grid line."
  1107. :group 'org-agenda-time-grid
  1108. :type
  1109. '(list
  1110. (set :greedy t :tag "Grid Display Options"
  1111. (const :tag "Show grid in single day agenda display" daily)
  1112. (const :tag "Show grid in weekly agenda display" weekly)
  1113. (const :tag "Always show grid for today" today)
  1114. (const :tag "Show grid only if any timed entries are present"
  1115. require-timed)
  1116. (const :tag "Skip grid times already present in an entry"
  1117. remove-match))
  1118. (string :tag "Grid String")
  1119. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1120. (defcustom org-agenda-show-current-time-in-grid t
  1121. "Non-nil means show the current time in the time grid."
  1122. :group 'org-agenda-time-grid
  1123. :type 'boolean)
  1124. (defcustom org-agenda-current-time-string
  1125. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1126. "The string for the current time marker in the agenda."
  1127. :group 'org-agenda-time-grid
  1128. :type 'string)
  1129. (defgroup org-agenda-sorting nil
  1130. "Options concerning sorting in the Org-mode Agenda."
  1131. :tag "Org Agenda Sorting"
  1132. :group 'org-agenda)
  1133. (defcustom org-agenda-sorting-strategy
  1134. '((agenda habit-down time-up priority-down category-keep)
  1135. (todo priority-down category-keep)
  1136. (tags priority-down category-keep)
  1137. (search category-keep))
  1138. "Sorting structure for the agenda items of a single day.
  1139. This is a list of symbols which will be used in sequence to determine
  1140. if an entry should be listed before another entry. The following
  1141. symbols are recognized:
  1142. time-up Put entries with time-of-day indications first, early first
  1143. time-down Put entries with time-of-day indications first, late first
  1144. category-keep Keep the default order of categories, corresponding to the
  1145. sequence in `org-agenda-files'.
  1146. category-up Sort alphabetically by category, A-Z.
  1147. category-down Sort alphabetically by category, Z-A.
  1148. tag-up Sort alphabetically by last tag, A-Z.
  1149. tag-down Sort alphabetically by last tag, Z-A.
  1150. priority-up Sort numerically by priority, high priority last.
  1151. priority-down Sort numerically by priority, high priority first.
  1152. todo-state-up Sort by todo state, tasks that are done last.
  1153. todo-state-down Sort by todo state, tasks that are done first.
  1154. effort-up Sort numerically by estimated effort, high effort last.
  1155. effort-down Sort numerically by estimated effort, high effort first.
  1156. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1157. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1158. habit-up Put entries that are habits first
  1159. habit-down Put entries that are habits last
  1160. alpha-up Sort headlines alphabetically
  1161. alpha-down Sort headlines alphabetically, reversed
  1162. The different possibilities will be tried in sequence, and testing stops
  1163. if one comparison returns a \"not-equal\". For example, the default
  1164. '(time-up category-keep priority-down)
  1165. means: Pull out all entries having a specified time of day and sort them,
  1166. in order to make a time schedule for the current day the first thing in the
  1167. agenda listing for the day. Of the entries without a time indication, keep
  1168. the grouped in categories, don't sort the categories, but keep them in
  1169. the sequence given in `org-agenda-files'. Within each category sort by
  1170. priority.
  1171. Leaving out `category-keep' would mean that items will be sorted across
  1172. categories by priority.
  1173. Instead of a single list, this can also be a set of list for specific
  1174. contents, with a context symbol in the car of the list, any of
  1175. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1176. Custom commands can bind this variable in the options section."
  1177. :group 'org-agenda-sorting
  1178. :type `(choice
  1179. (repeat :tag "General" ,org-sorting-choice)
  1180. (list :tag "Individually"
  1181. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1182. (repeat ,org-sorting-choice))
  1183. (cons (const :tag "Strategy for TODO lists" todo)
  1184. (repeat ,org-sorting-choice))
  1185. (cons (const :tag "Strategy for Tags matches" tags)
  1186. (repeat ,org-sorting-choice))
  1187. (cons (const :tag "Strategy for search matches" search)
  1188. (repeat ,org-sorting-choice)))))
  1189. (defcustom org-agenda-cmp-user-defined nil
  1190. "A function to define the comparison `user-defined'.
  1191. This function must receive two arguments, agenda entry a and b.
  1192. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1193. the user comparison, return nil.
  1194. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1195. part of an agenda sorting strategy."
  1196. :group 'org-agenda-sorting
  1197. :type 'symbol)
  1198. (defcustom org-sort-agenda-notime-is-late t
  1199. "Non-nil means items without time are considered late.
  1200. This is only relevant for sorting. When t, items which have no explicit
  1201. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1202. do have a time. When nil, the default time is before 0:00. You can use this
  1203. option to decide if the schedule for today should come before or after timeless
  1204. agenda entries."
  1205. :group 'org-agenda-sorting
  1206. :type 'boolean)
  1207. (defcustom org-sort-agenda-noeffort-is-high t
  1208. "Non-nil means items without effort estimate are sorted as high effort.
  1209. This also applies when filtering an agenda view with respect to the
  1210. < or > effort operator. Then, tasks with no effort defined will be treated
  1211. as tasks with high effort.
  1212. When nil, such items are sorted as 0 minutes effort."
  1213. :group 'org-agenda-sorting
  1214. :type 'boolean)
  1215. (defgroup org-agenda-line-format nil
  1216. "Options concerning the entry prefix in the Org-mode agenda display."
  1217. :tag "Org Agenda Line Format"
  1218. :group 'org-agenda)
  1219. (defcustom org-agenda-prefix-format
  1220. '((agenda . " %i %-12:c%?-12t% s")
  1221. (timeline . " % s")
  1222. (todo . " %i %-12:c")
  1223. (tags . " %i %-12:c")
  1224. (search . " %i %-12:c"))
  1225. "Format specifications for the prefix of items in the agenda views.
  1226. An alist with four entries, for the different agenda types. The keys to the
  1227. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1228. are format strings.
  1229. This format works similar to a printf format, with the following meaning:
  1230. %c the category of the item, \"Diary\" for entries from the diary, or
  1231. as given by the CATEGORY keyword or derived from the file name.
  1232. %i the icon category of the item, as give in
  1233. `org-agenda-category-icon-alist'.
  1234. %T the *last* tag of the item. Last because inherited tags come
  1235. first in the list.
  1236. %t the time-of-day specification if one applies to the entry, in the
  1237. format HH:MM
  1238. %s Scheduling/Deadline information, a short string
  1239. %(expression) Eval EXPRESSION and replace the control string
  1240. by the result
  1241. All specifiers work basically like the standard `%s' of printf, but may
  1242. contain two additional characters: A question mark just after the `%' and
  1243. a whitespace/punctuation character just before the final letter.
  1244. If the first character after `%' is a question mark, the entire field
  1245. will only be included if the corresponding value applies to the
  1246. current entry. This is useful for fields which should have fixed
  1247. width when present, but zero width when absent. For example,
  1248. \"%?-12t\" will result in a 12 character time field if a time of the
  1249. day is specified, but will completely disappear in entries which do
  1250. not contain a time.
  1251. If there is punctuation or whitespace character just before the final
  1252. format letter, this character will be appended to the field value if
  1253. the value is not empty. For example, the format \"%-12:c\" leads to
  1254. \"Diary: \" if the category is \"Diary\". If the category were be
  1255. empty, no additional colon would be inserted.
  1256. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1257. - Indent the line with two space characters
  1258. - Give the category in a 12 chars wide field, padded with whitespace on
  1259. the right (because of `-'). Append a colon if there is a category
  1260. (because of `:').
  1261. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1262. time, don't put in an empty field, just skip it (because of '?').
  1263. - Finally, put the scheduling information and append a whitespace.
  1264. As another example, if you don't want the time-of-day of entries in
  1265. the prefix, you could use:
  1266. (setq org-agenda-prefix-format \" %-11:c% s\")
  1267. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1268. `org-agenda-remove-tags'.
  1269. Custom commands can set this variable in the options section."
  1270. :type '(choice
  1271. (string :tag "General format")
  1272. (list :greedy t :tag "View dependent"
  1273. (cons (const agenda) (string :tag "Format"))
  1274. (cons (const timeline) (string :tag "Format"))
  1275. (cons (const todo) (string :tag "Format"))
  1276. (cons (const tags) (string :tag "Format"))
  1277. (cons (const search) (string :tag "Format"))))
  1278. :group 'org-agenda-line-format)
  1279. (defvar org-prefix-format-compiled nil
  1280. "The compiled version of the most recently used prefix format.
  1281. See the variable `org-agenda-prefix-format'.")
  1282. (defcustom org-agenda-todo-keyword-format "%-1s"
  1283. "Format for the TODO keyword in agenda lines.
  1284. Set this to something like \"%-12s\" if you want all TODO keywords
  1285. to occupy a fixed space in the agenda display."
  1286. :group 'org-agenda-line-format
  1287. :type 'string)
  1288. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1289. "Text preceding timerange entries in the agenda view.
  1290. This is a list with two strings. The first applies when the range
  1291. is entirely on one day. The second applies if the range spans several days.
  1292. The strings may have two \"%d\" format specifiers which will be filled
  1293. with the sequence number of the days, and the total number of days in the
  1294. range, respectively."
  1295. :group 'org-agenda-line-format
  1296. :type '(list
  1297. (string :tag "Deadline today ")
  1298. (choice :tag "Deadline relative"
  1299. (string :tag "Format string")
  1300. (function))))
  1301. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1302. "Text preceding scheduled items in the agenda view.
  1303. This is a list with two strings. The first applies when the item is
  1304. scheduled on the current day. The second applies when it has been scheduled
  1305. previously, it may contain a %d indicating that this is the nth time that
  1306. this item is scheduled, due to automatic rescheduling of unfinished items
  1307. for the following day. So this number is one larger than the number of days
  1308. that passed since this item was scheduled first."
  1309. :group 'org-agenda-line-format
  1310. :type '(list
  1311. (string :tag "Scheduled today ")
  1312. (string :tag "Scheduled previously")))
  1313. (defcustom org-agenda-inactive-leader "["
  1314. "Text preceding item pulled into the agenda by inactive time stamps.
  1315. These entries are added to the agenda when pressing \"[\"."
  1316. :group 'org-agenda-line-format
  1317. :type '(list
  1318. (string :tag "Scheduled today ")
  1319. (string :tag "Scheduled previously")))
  1320. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1321. "Text preceding deadline items in the agenda view.
  1322. This is a list with two strings. The first applies when the item has its
  1323. deadline on the current day. The second applies when it is in the past or
  1324. in the future, it may contain %d to capture how many days away the deadline
  1325. is (was)."
  1326. :group 'org-agenda-line-format
  1327. :type '(list
  1328. (string :tag "Deadline today ")
  1329. (choice :tag "Deadline relative"
  1330. (string :tag "Format string")
  1331. (function))))
  1332. (defcustom org-agenda-remove-times-when-in-prefix t
  1333. "Non-nil means remove duplicate time specifications in agenda items.
  1334. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1335. time-of-day specification in a headline or diary entry is extracted and
  1336. placed into the prefix. If this option is non-nil, the original specification
  1337. \(a timestamp or -range, or just a plain time(range) specification like
  1338. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1339. cluttered.
  1340. The option can be t or nil. It may also be the symbol `beg', indicating
  1341. that the time should only be removed when it is located at the beginning of
  1342. the headline/diary entry."
  1343. :group 'org-agenda-line-format
  1344. :type '(choice
  1345. (const :tag "Always" t)
  1346. (const :tag "Never" nil)
  1347. (const :tag "When at beginning of entry" beg)))
  1348. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1349. "Non-nil means remove time ranges specifications in agenda
  1350. items that span on several days."
  1351. :group 'org-agenda-line-format
  1352. :type 'boolean)
  1353. (defcustom org-agenda-default-appointment-duration nil
  1354. "Default duration for appointments that only have a starting time.
  1355. When nil, no duration is specified in such cases.
  1356. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1357. :group 'org-agenda-line-format
  1358. :type '(choice
  1359. (integer :tag "Minutes")
  1360. (const :tag "No default duration")))
  1361. (defcustom org-agenda-show-inherited-tags t
  1362. "Non-nil means show inherited tags in each agenda line."
  1363. :group 'org-agenda-line-format
  1364. :type 'boolean)
  1365. (defcustom org-agenda-hide-tags-regexp nil
  1366. "Regular expression used to filter away specific tags in agenda views.
  1367. This means that these tags will be present, but not be shown in the agenda
  1368. line. Secondary filtering will still work on the hidden tags.
  1369. Nil means don't hide any tags."
  1370. :group 'org-agenda-line-format
  1371. :type '(choice
  1372. (const :tag "Hide none" nil)
  1373. (string :tag "Regexp ")))
  1374. (defcustom org-agenda-remove-tags nil
  1375. "Non-nil means remove the tags from the headline copy in the agenda.
  1376. When this is the symbol `prefix', only remove tags when
  1377. `org-agenda-prefix-format' contains a `%T' specifier."
  1378. :group 'org-agenda-line-format
  1379. :type '(choice
  1380. (const :tag "Always" t)
  1381. (const :tag "Never" nil)
  1382. (const :tag "When prefix format contains %T" prefix)))
  1383. (if (fboundp 'defvaralias)
  1384. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1385. 'org-agenda-remove-tags))
  1386. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1387. "Shift tags in agenda items to this column.
  1388. If this number is positive, it specifies the column. If it is negative,
  1389. it means that the tags should be flushright to that column. For example,
  1390. -80 works well for a normal 80 character screen."
  1391. :group 'org-agenda-line-format
  1392. :type 'integer)
  1393. (if (fboundp 'defvaralias)
  1394. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1395. (defcustom org-agenda-fontify-priorities 'cookies
  1396. "Non-nil means highlight low and high priorities in agenda.
  1397. When t, the highest priority entries are bold, lowest priority italic.
  1398. However, settings in `org-priority-faces' will overrule these faces.
  1399. When this variable is the symbol `cookies', only fontify the
  1400. cookies, not the entire task.
  1401. This may also be an association list of priority faces, whose
  1402. keys are the character values of `org-highest-priority',
  1403. `org-default-priority', and `org-lowest-priority' (the default values
  1404. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1405. color as a string, or a list like `(:background \"Red\")'.
  1406. If it is a color, the variable `org-faces-easy-properties'
  1407. determines if it is a foreground or a background color."
  1408. :group 'org-agenda-line-format
  1409. :type '(choice
  1410. (const :tag "Never" nil)
  1411. (const :tag "Defaults" t)
  1412. (const :tag "Cookies only" cookies)
  1413. (repeat :tag "Specify"
  1414. (list (character :tag "Priority" :value ?A)
  1415. (choice :tag "Face "
  1416. (string :tag "Color")
  1417. (sexp :tag "Face"))))))
  1418. (defcustom org-agenda-day-face-function nil
  1419. "Function called to determine what face should be used to display a day.
  1420. The only argument passed to that function is the day. It should
  1421. returns a face, or nil if does not want to specify a face and let
  1422. the normal rules apply."
  1423. :group 'org-agenda-line-format
  1424. :type 'function)
  1425. (defcustom org-agenda-category-icon-alist nil
  1426. "Alist of category icon to be displayed in agenda views.
  1427. Each entry should have the following format:
  1428. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1429. Where CATEGORY-REGEXP is a regexp matching the categories where
  1430. the icon should be displayed.
  1431. FILE-OR-DATA either a file path or a string containing image data.
  1432. The other fields can be omited safely if not needed:
  1433. TYPE indicates the image type.
  1434. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1435. image data.
  1436. PROPS are additional image attributes to assign to the image,
  1437. like, e.g. `:ascent center'.
  1438. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1439. If you want to set the display properties yourself, just put a
  1440. list as second element:
  1441. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1442. For example, to display a 16px horizontal space for Emacs
  1443. category, you can use:
  1444. (\"Emacs\" '(space . (:width (16))))"
  1445. :group 'org-agenda-line-format
  1446. :type '(alist :key-type (string :tag "Regexp matching category")
  1447. :value-type (choice (list :tag "Icon"
  1448. (string :tag "File or data")
  1449. (symbol :tag "Type")
  1450. (boolean :tag "Data?")
  1451. (repeat :tag "Extra image properties" :inline t symbol))
  1452. (list :tag "Display properties" sexp))))
  1453. (defgroup org-agenda-column-view nil
  1454. "Options concerning column view in the agenda."
  1455. :tag "Org Agenda Column View"
  1456. :group 'org-agenda)
  1457. (defcustom org-agenda-columns-show-summaries t
  1458. "Non-nil means show summaries for columns displayed in the agenda view."
  1459. :group 'org-agenda-column-view
  1460. :type 'boolean)
  1461. (defcustom org-agenda-columns-compute-summary-properties t
  1462. "Non-nil means recompute all summary properties before column view.
  1463. When column view in the agenda is listing properties that have a summary
  1464. operator, it can go to all relevant buffers and recompute the summaries
  1465. there. This can mean overhead for the agenda column view, but is necessary
  1466. to have thing up to date.
  1467. As a special case, a CLOCKSUM property also makes sure that the clock
  1468. computations are current."
  1469. :group 'org-agenda-column-view
  1470. :type 'boolean)
  1471. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1472. "Non-nil means the duration of an appointment will add to day effort.
  1473. The property to which appointment durations will be added is the one given
  1474. in the option `org-effort-property'. If an appointment does not have
  1475. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1476. is not set, an appointment without end time will not contribute to the time
  1477. estimate."
  1478. :group 'org-agenda-column-view
  1479. :type 'boolean)
  1480. (defcustom org-agenda-auto-exclude-function nil
  1481. "A function called with a tag to decide if it is filtered on '/ RET'.
  1482. The sole argument to the function, which is called once for each
  1483. possible tag, is a string giving the name of the tag. The
  1484. function should return either nil if the tag should be included
  1485. as normal, or \"-<TAG>\" to exclude the tag.
  1486. Note that for the purpose of tag filtering, only the lower-case version of
  1487. all tags will be considered, so that this function will only ever see
  1488. the lower-case version of all tags."
  1489. :group 'org-agenda
  1490. :type 'function)
  1491. (defcustom org-agenda-bulk-custom-functions nil
  1492. "Alist of characters and custom functions for bulk action.
  1493. For example, this value makes those two functions available:
  1494. '((?R set-category)
  1495. (?C bulk-cut))
  1496. With selected entries in an agenda buffer, `B R' will execute
  1497. set-category on the selected entries. Note that functions in
  1498. this alist don't need to be quoted."
  1499. :type 'alist
  1500. :group 'org-agenda)
  1501. (eval-when-compile
  1502. (require 'cl))
  1503. (require 'org)
  1504. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1505. "Execute BODY with point at location given by `org-hd-marker' property.
  1506. If STRING is non-nil, the text property will be fetched from position 0
  1507. in that string. If STRING is nil, it will be fetched from the beginning
  1508. of the current line."
  1509. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1510. 'org-hd-marker string)))
  1511. (with-current-buffer (marker-buffer marker)
  1512. (save-excursion
  1513. (goto-char marker)
  1514. ,@body))))
  1515. (defun org-add-agenda-custom-command (entry)
  1516. "Replace or add a command in `org-agenda-custom-commands'.
  1517. This is mostly for hacking and trying a new command - once the command
  1518. works you probably want to add it to `org-agenda-custom-commands' for good."
  1519. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1520. (if ass
  1521. (setcdr ass (cdr entry))
  1522. (push entry org-agenda-custom-commands))))
  1523. ;;; Define the Org-agenda-mode
  1524. (defvar org-agenda-mode-map (make-sparse-keymap)
  1525. "Keymap for `org-agenda-mode'.")
  1526. (if (fboundp 'defvaralias)
  1527. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1528. (defvar org-agenda-menu) ; defined later in this file.
  1529. (defvar org-agenda-restrict) ; defined later in this file.
  1530. (defvar org-agenda-follow-mode nil)
  1531. (defvar org-agenda-entry-text-mode nil)
  1532. (defvar org-agenda-clockreport-mode nil)
  1533. (defvar org-agenda-show-log nil)
  1534. (defvar org-agenda-redo-command nil)
  1535. (defvar org-agenda-query-string nil)
  1536. (defvar org-agenda-mode-hook nil
  1537. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1538. (defvar org-agenda-type nil)
  1539. (defvar org-agenda-force-single-file nil)
  1540. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1541. (defun org-agenda-mode ()
  1542. "Mode for time-sorted view on action items in Org-mode files.
  1543. The following commands are available:
  1544. \\{org-agenda-mode-map}"
  1545. (interactive)
  1546. (kill-all-local-variables)
  1547. (setq org-agenda-undo-list nil
  1548. org-agenda-pending-undo-list nil
  1549. org-agenda-bulk-marked-entries nil)
  1550. (setq major-mode 'org-agenda-mode)
  1551. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1552. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1553. (setq mode-name "Org-Agenda")
  1554. (use-local-map org-agenda-mode-map)
  1555. (easy-menu-add org-agenda-menu)
  1556. (if org-startup-truncated (setq truncate-lines t))
  1557. (org-set-local 'line-move-visual nil)
  1558. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1559. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1560. ;; Make sure properties are removed when copying text
  1561. (when (boundp 'buffer-substring-filters)
  1562. (org-set-local 'buffer-substring-filters
  1563. (cons (lambda (x)
  1564. (set-text-properties 0 (length x) nil x) x)
  1565. buffer-substring-filters)))
  1566. (unless org-agenda-keep-modes
  1567. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1568. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1569. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1570. org-agenda-show-log org-agenda-start-with-log-mode))
  1571. (easy-menu-change
  1572. '("Agenda") "Agenda Files"
  1573. (append
  1574. (list
  1575. (vector
  1576. (if (get 'org-agenda-files 'org-restrict)
  1577. "Restricted to single file"
  1578. "Edit File List")
  1579. '(org-edit-agenda-file-list)
  1580. (not (get 'org-agenda-files 'org-restrict)))
  1581. "--")
  1582. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1583. (org-agenda-set-mode-name)
  1584. (apply
  1585. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1586. (list 'org-agenda-mode-hook)))
  1587. (substitute-key-definition 'undo 'org-agenda-undo
  1588. org-agenda-mode-map global-map)
  1589. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1590. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1591. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1592. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1593. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1594. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1595. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1596. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1597. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1598. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1599. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1600. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1601. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1602. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1603. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1604. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1605. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1606. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1607. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1608. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1609. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1610. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1611. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1612. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1613. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1614. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1615. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1616. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1617. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1618. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1619. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1620. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1621. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1622. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1623. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1624. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1625. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1627. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1628. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1630. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1631. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1632. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1633. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1634. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1635. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1636. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1637. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1638. (while l (org-defkey org-agenda-mode-map
  1639. (int-to-string (pop l)) 'digit-argument)))
  1640. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1641. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1642. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1643. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1644. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1645. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1646. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1647. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1648. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1649. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1650. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1651. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1652. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1653. 'org-clock-modify-effort-estimate)
  1654. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1655. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1656. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1657. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1658. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1659. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1660. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1661. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1662. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1663. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1664. (substitute-key-definition 'next-line 'org-agenda-next-line
  1665. org-agenda-mode-map global-map)
  1666. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1667. org-agenda-mode-map global-map)
  1668. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1669. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1670. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1671. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1672. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1673. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1674. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1675. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1676. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1677. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1678. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1679. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1680. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1681. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1682. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1683. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1684. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1685. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1686. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1687. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1688. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1689. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1690. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1691. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1692. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1693. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1694. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1695. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1696. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1697. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1698. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1699. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1700. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1701. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1702. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1703. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1704. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1705. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1706. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1707. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1708. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1709. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1710. (when org-agenda-mouse-1-follows-link
  1711. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1712. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1713. '("Agenda"
  1714. ("Agenda Files")
  1715. "--"
  1716. ("Agenda Dates"
  1717. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1718. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1719. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1720. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1721. "--"
  1722. ("View"
  1723. ["Day View" org-agenda-day-view
  1724. :active (org-agenda-check-type nil 'agenda)
  1725. :style radio :selected (eq org-agenda-current-span 'day)
  1726. :keys "v d (or just d)"]
  1727. ["Week View" org-agenda-week-view
  1728. :active (org-agenda-check-type nil 'agenda)
  1729. :style radio :selected (eq org-agenda-current-span 'week)
  1730. :keys "v w (or just w)"]
  1731. ["Month View" org-agenda-month-view
  1732. :active (org-agenda-check-type nil 'agenda)
  1733. :style radio :selected (eq org-agenda-current-span 'month)
  1734. :keys "v m"]
  1735. ["Year View" org-agenda-year-view
  1736. :active (org-agenda-check-type nil 'agenda)
  1737. :style radio :selected (eq org-agenda-current-span 'year)
  1738. :keys "v y"]
  1739. "--"
  1740. ["Include Diary" org-agenda-toggle-diary
  1741. :style toggle :selected org-agenda-include-diary
  1742. :active (org-agenda-check-type nil 'agenda)]
  1743. ["Include Deadlines" org-agenda-toggle-deadlines
  1744. :style toggle :selected org-agenda-include-deadlines
  1745. :active (org-agenda-check-type nil 'agenda)]
  1746. ["Use Time Grid" org-agenda-toggle-time-grid
  1747. :style toggle :selected org-agenda-use-time-grid
  1748. :active (org-agenda-check-type nil 'agenda)]
  1749. "--"
  1750. ["Show clock report" org-agenda-clockreport-mode
  1751. :style toggle :selected org-agenda-clockreport-mode
  1752. :active (org-agenda-check-type nil 'agenda)]
  1753. ["Show some entry text" org-agenda-entry-text-mode
  1754. :style toggle :selected org-agenda-entry-text-mode
  1755. :active t]
  1756. "--"
  1757. ["Show Logbook entries" org-agenda-log-mode
  1758. :style toggle :selected org-agenda-show-log
  1759. :active (org-agenda-check-type nil 'agenda 'timeline)
  1760. :keys "v l (or just l)"]
  1761. ["Include archived trees" org-agenda-archives-mode
  1762. :style toggle :selected org-agenda-archives-mode :active t
  1763. :keys "v a"]
  1764. ["Include archive files" (org-agenda-archives-mode t)
  1765. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1766. :keys "v A"]
  1767. "--"
  1768. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1769. ["Write view to file" org-write-agenda t]
  1770. ["Rebuild buffer" org-agenda-redo t]
  1771. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1772. "--"
  1773. ["Show original entry" org-agenda-show t]
  1774. ["Go To (other window)" org-agenda-goto t]
  1775. ["Go To (this window)" org-agenda-switch-to t]
  1776. ["Follow Mode" org-agenda-follow-mode
  1777. :style toggle :selected org-agenda-follow-mode :active t]
  1778. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1779. "--"
  1780. ("TODO"
  1781. ["Cycle TODO" org-agenda-todo t]
  1782. ["Next TODO set" org-agenda-todo-nextset t]
  1783. ["Previous TODO set" org-agenda-todo-previousset t]
  1784. ["Add note" org-agenda-add-note t])
  1785. ("Archive/Refile/Delete"
  1786. ["Archive default" org-agenda-archive-default t]
  1787. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1788. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1789. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1790. ["Archive subtree" org-agenda-archive t]
  1791. "--"
  1792. ["Refile" org-agenda-refile t]
  1793. "--"
  1794. ["Delete subtree" org-agenda-kill t])
  1795. ("Bulk action"
  1796. ["Mark entry" org-agenda-bulk-mark t]
  1797. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1798. ["Unmark entry" org-agenda-bulk-unmark t]
  1799. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1800. ["Act on all marked" org-agenda-bulk-action t]
  1801. "--"
  1802. ("Tags and Properties"
  1803. ["Show all Tags" org-agenda-show-tags t]
  1804. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1805. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1806. "--"
  1807. ["Column View" org-columns t])
  1808. ("Deadline/Schedule"
  1809. ["Schedule" org-agenda-schedule t]
  1810. ["Set Deadline" org-agenda-deadline t]
  1811. "--"
  1812. ["Mark item" org-agenda-action :active t :keys "k m"]
  1813. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1814. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1815. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1816. "--"
  1817. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1818. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1819. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1820. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1821. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1822. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1823. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1824. ("Clock and Effort"
  1825. ["Clock in" org-agenda-clock-in t]
  1826. ["Clock out" org-agenda-clock-out t]
  1827. ["Clock cancel" org-agenda-clock-cancel t]
  1828. ["Goto running clock" org-clock-goto t]
  1829. "--"
  1830. ["Set Effort" org-agenda-set-effort t]
  1831. ["Change clocked effort" org-clock-modify-effort-estimate
  1832. (org-clock-is-active)])
  1833. ("Priority"
  1834. ["Set Priority" org-agenda-priority t]
  1835. ["Increase Priority" org-agenda-priority-up t]
  1836. ["Decrease Priority" org-agenda-priority-down t]
  1837. ["Show Priority" org-agenda-show-priority t])
  1838. ("Calendar/Diary"
  1839. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1840. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1841. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1842. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1843. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1844. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1845. "--"
  1846. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1847. "--"
  1848. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1849. "--"
  1850. ("MobileOrg"
  1851. ["Push Files and Views" org-mobile-push t]
  1852. ["Get Captured and Flagged" org-mobile-pull t]
  1853. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1854. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1855. "--"
  1856. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1857. "--"
  1858. ["Quit" org-agenda-quit t]
  1859. ["Exit and Release Buffers" org-agenda-exit t]
  1860. ))
  1861. ;;; Agenda undo
  1862. (defvar org-agenda-allow-remote-undo t
  1863. "Non-nil means allow remote undo from the agenda buffer.")
  1864. (defvar org-agenda-undo-list nil
  1865. "List of undoable operations in the agenda since last refresh.")
  1866. (defvar org-agenda-undo-has-started-in nil
  1867. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1868. (defvar org-agenda-pending-undo-list nil
  1869. "In a series of undo commands, this is the list of remaining undo items.")
  1870. (defun org-agenda-undo ()
  1871. "Undo a remote editing step in the agenda.
  1872. This undoes changes both in the agenda buffer and in the remote buffer
  1873. that have been changed along."
  1874. (interactive)
  1875. (or org-agenda-allow-remote-undo
  1876. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1877. (if (not (eq this-command last-command))
  1878. (setq org-agenda-undo-has-started-in nil
  1879. org-agenda-pending-undo-list org-agenda-undo-list))
  1880. (if (not org-agenda-pending-undo-list)
  1881. (error "No further undo information"))
  1882. (let* ((entry (pop org-agenda-pending-undo-list))
  1883. buf line cmd rembuf)
  1884. (setq cmd (pop entry) line (pop entry))
  1885. (setq rembuf (nth 2 entry))
  1886. (org-with-remote-undo rembuf
  1887. (while (bufferp (setq buf (pop entry)))
  1888. (if (pop entry)
  1889. (with-current-buffer buf
  1890. (let ((last-undo-buffer buf)
  1891. (inhibit-read-only t))
  1892. (unless (memq buf org-agenda-undo-has-started-in)
  1893. (push buf org-agenda-undo-has-started-in)
  1894. (make-local-variable 'pending-undo-list)
  1895. (undo-start))
  1896. (while (and pending-undo-list
  1897. (listp pending-undo-list)
  1898. (not (car pending-undo-list)))
  1899. (pop pending-undo-list))
  1900. (undo-more 1))))))
  1901. (org-goto-line line)
  1902. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1903. (defun org-verify-change-for-undo (l1 l2)
  1904. "Verify that a real change occurred between the undo lists L1 and L2."
  1905. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1906. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1907. (not (eq l1 l2)))
  1908. ;;; Agenda dispatch
  1909. (defvar org-agenda-restrict nil)
  1910. (defvar org-agenda-restrict-begin (make-marker))
  1911. (defvar org-agenda-restrict-end (make-marker))
  1912. (defvar org-agenda-last-dispatch-buffer nil)
  1913. (defvar org-agenda-overriding-restriction nil)
  1914. ;;;###autoload
  1915. (defun org-agenda (&optional arg keys restriction)
  1916. "Dispatch agenda commands to collect entries to the agenda buffer.
  1917. Prompts for a command to execute. Any prefix arg will be passed
  1918. on to the selected command. The default selections are:
  1919. a Call `org-agenda-list' to display the agenda for current day or week.
  1920. t Call `org-todo-list' to display the global todo list.
  1921. T Call `org-todo-list' to display the global todo list, select only
  1922. entries with a specific TODO keyword (the user gets a prompt).
  1923. m Call `org-tags-view' to display headlines with tags matching
  1924. a condition (the user is prompted for the condition).
  1925. M Like `m', but select only TODO entries, no ordinary headlines.
  1926. L Create a timeline for the current buffer.
  1927. e Export views to associated files.
  1928. s Search entries for keywords.
  1929. / Multi occur across all agenda files and also files listed
  1930. in `org-agenda-text-search-extra-files'.
  1931. < Restrict agenda commands to buffer, subtree, or region.
  1932. Press several times to get the desired effect.
  1933. > Remove a previous restriction.
  1934. # List \"stuck\" projects.
  1935. ! Configure what \"stuck\" means.
  1936. C Configure custom agenda commands.
  1937. More commands can be added by configuring the variable
  1938. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1939. searches can be pre-defined in this way.
  1940. If the current buffer is in Org-mode and visiting a file, you can also
  1941. first press `<' once to indicate that the agenda should be temporarily
  1942. \(until the next use of \\[org-agenda]) restricted to the current file.
  1943. Pressing `<' twice means to restrict to the current subtree or region
  1944. \(if active)."
  1945. (interactive "P")
  1946. (catch 'exit
  1947. (let* ((prefix-descriptions nil)
  1948. (org-agenda-window-setup (if (equal (buffer-name)
  1949. org-agenda-buffer-name)
  1950. 'current-window
  1951. org-agenda-window-setup))
  1952. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1953. (org-agenda-custom-commands
  1954. ;; normalize different versions
  1955. (delq nil
  1956. (mapcar
  1957. (lambda (x)
  1958. (cond ((stringp (cdr x))
  1959. (push x prefix-descriptions)
  1960. nil)
  1961. ((stringp (nth 1 x)) x)
  1962. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1963. (t (cons (car x) (cons "" (cdr x))))))
  1964. org-agenda-custom-commands)))
  1965. (buf (current-buffer))
  1966. (bfn (buffer-file-name (buffer-base-buffer)))
  1967. entry key type match lprops ans)
  1968. ;; Turn off restriction unless there is an overriding one,
  1969. (unless org-agenda-overriding-restriction
  1970. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1971. ;; There is a request to keep the file list in place
  1972. (put 'org-agenda-files 'org-restrict nil))
  1973. (setq org-agenda-restrict nil)
  1974. (move-marker org-agenda-restrict-begin nil)
  1975. (move-marker org-agenda-restrict-end nil))
  1976. ;; Delete old local properties
  1977. (put 'org-agenda-redo-command 'org-lprops nil)
  1978. ;; Delete previously set last-arguments
  1979. (put 'org-agenda-redo-command 'last-args nil)
  1980. ;; Remember where this call originated
  1981. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1982. (unless keys
  1983. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1984. keys (car ans)
  1985. restriction (cdr ans)))
  1986. ;; Establish the restriction, if any
  1987. (when (and (not org-agenda-overriding-restriction) restriction)
  1988. (put 'org-agenda-files 'org-restrict (list bfn))
  1989. (cond
  1990. ((eq restriction 'region)
  1991. (setq org-agenda-restrict t)
  1992. (move-marker org-agenda-restrict-begin (region-beginning))
  1993. (move-marker org-agenda-restrict-end (region-end)))
  1994. ((eq restriction 'subtree)
  1995. (save-excursion
  1996. (setq org-agenda-restrict t)
  1997. (org-back-to-heading t)
  1998. (move-marker org-agenda-restrict-begin (point))
  1999. (move-marker org-agenda-restrict-end
  2000. (progn (org-end-of-subtree t)))))))
  2001. ;; For example the todo list should not need it (but does...)
  2002. (cond
  2003. ((setq entry (assoc keys org-agenda-custom-commands))
  2004. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2005. (progn
  2006. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2007. lprops (nth 4 entry))
  2008. (put 'org-agenda-redo-command 'org-lprops lprops)
  2009. (cond
  2010. ((eq type 'agenda)
  2011. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2012. ((eq type 'alltodo)
  2013. (org-let lprops '(org-todo-list current-prefix-arg)))
  2014. ((eq type 'search)
  2015. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2016. ((eq type 'stuck)
  2017. (org-let lprops '(org-agenda-list-stuck-projects
  2018. current-prefix-arg)))
  2019. ((eq type 'tags)
  2020. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2021. ((eq type 'tags-todo)
  2022. (org-let lprops '(org-tags-view '(4) match)))
  2023. ((eq type 'todo)
  2024. (org-let lprops '(org-todo-list match)))
  2025. ((eq type 'tags-tree)
  2026. (org-check-for-org-mode)
  2027. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2028. ((eq type 'todo-tree)
  2029. (org-check-for-org-mode)
  2030. (org-let lprops
  2031. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2032. (regexp-quote match) "\\>"))))
  2033. ((eq type 'occur-tree)
  2034. (org-check-for-org-mode)
  2035. (org-let lprops '(org-occur match)))
  2036. ((functionp type)
  2037. (org-let lprops '(funcall type match)))
  2038. ((fboundp type)
  2039. (org-let lprops '(funcall type match)))
  2040. (t (error "Invalid custom agenda command type %s" type))))
  2041. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2042. ((equal keys "C")
  2043. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2044. (customize-variable 'org-agenda-custom-commands))
  2045. ((equal keys "a") (call-interactively 'org-agenda-list))
  2046. ((equal keys "s") (call-interactively 'org-search-view))
  2047. ((equal keys "t") (call-interactively 'org-todo-list))
  2048. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2049. ((equal keys "m") (call-interactively 'org-tags-view))
  2050. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2051. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2052. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2053. (org-add-hook
  2054. 'post-command-hook
  2055. (lambda ()
  2056. (unless (current-message)
  2057. (let* ((m (org-agenda-get-any-marker))
  2058. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2059. (when note
  2060. (message (concat
  2061. "FLAGGING-NOTE ([?] for more info): "
  2062. (org-add-props
  2063. (replace-regexp-in-string
  2064. "\\\\n" "//"
  2065. (copy-sequence note))
  2066. nil 'face 'org-warning)))))))
  2067. t t))
  2068. ((equal keys "L")
  2069. (unless (org-mode-p)
  2070. (error "This is not an Org-mode file"))
  2071. (unless restriction
  2072. (put 'org-agenda-files 'org-restrict (list bfn))
  2073. (org-call-with-arg 'org-timeline arg)))
  2074. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2075. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2076. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2077. (t (error "Invalid agenda key"))))))
  2078. (defun org-agenda-append-agenda ()
  2079. "Append another agenda view to the current one.
  2080. This function allows interactive building of block agendas.
  2081. Agenda views are separated by `org-agenda-block-separator'."
  2082. (interactive)
  2083. (unless (string= (buffer-name) org-agenda-buffer-name)
  2084. (error "Can only append from within agenda buffer"))
  2085. (let ((org-agenda-multi t))
  2086. (org-agenda)
  2087. (widen)))
  2088. (defun org-agenda-normalize-custom-commands (cmds)
  2089. (delq nil
  2090. (mapcar
  2091. (lambda (x)
  2092. (cond ((stringp (cdr x)) nil)
  2093. ((stringp (nth 1 x)) x)
  2094. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2095. (t (cons (car x) (cons "" (cdr x))))))
  2096. cmds)))
  2097. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2098. "The user interface for selecting an agenda command."
  2099. (catch 'exit
  2100. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2101. (restrict-ok (and bfn (org-mode-p)))
  2102. (region-p (org-region-active-p))
  2103. (custom org-agenda-custom-commands)
  2104. (selstring "")
  2105. restriction second-time
  2106. c entry key type match prefixes rmheader header-end custom1 desc
  2107. line lines left right n n1)
  2108. (save-window-excursion
  2109. (delete-other-windows)
  2110. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2111. (erase-buffer)
  2112. (insert (eval-when-compile
  2113. (let ((header
  2114. "
  2115. Press key for an agenda command: < Buffer, subtree/region restriction
  2116. -------------------------------- > Remove restriction
  2117. a Agenda for current week or day e Export agenda views
  2118. t List of all TODO entries T Entries with special TODO kwd
  2119. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2120. L Timeline for current buffer # List stuck projects (!=configure)
  2121. s Search for keywords C Configure custom agenda commands
  2122. / Multi-occur ? Find :FLAGGED: entries
  2123. ")
  2124. (start 0))
  2125. (while (string-match
  2126. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2127. header start)
  2128. (setq start (match-end 0))
  2129. (add-text-properties (match-beginning 2) (match-end 2)
  2130. '(face bold) header))
  2131. header)))
  2132. (setq header-end (move-marker (make-marker) (point)))
  2133. (while t
  2134. (setq custom1 custom)
  2135. (when (eq rmheader t)
  2136. (org-goto-line 1)
  2137. (re-search-forward ":" nil t)
  2138. (delete-region (match-end 0) (point-at-eol))
  2139. (forward-char 1)
  2140. (looking-at "-+")
  2141. (delete-region (match-end 0) (point-at-eol))
  2142. (move-marker header-end (match-end 0)))
  2143. (goto-char header-end)
  2144. (delete-region (point) (point-max))
  2145. ;; Produce all the lines that describe custom commands and prefixes
  2146. (setq lines nil)
  2147. (while (setq entry (pop custom1))
  2148. (setq key (car entry) desc (nth 1 entry)
  2149. type (nth 2 entry)
  2150. match (nth 3 entry))
  2151. (if (> (length key) 1)
  2152. (add-to-list 'prefixes (string-to-char key))
  2153. (setq line
  2154. (format
  2155. "%-4s%-14s"
  2156. (org-add-props (copy-sequence key)
  2157. '(face bold))
  2158. (cond
  2159. ((string-match "\\S-" desc) desc)
  2160. ((eq type 'agenda) "Agenda for current week or day")
  2161. ((eq type 'alltodo) "List of all TODO entries")
  2162. ((eq type 'search) "Word search")
  2163. ((eq type 'stuck) "List of stuck projects")
  2164. ((eq type 'todo) "TODO keyword")
  2165. ((eq type 'tags) "Tags query")
  2166. ((eq type 'tags-todo) "Tags (TODO)")
  2167. ((eq type 'tags-tree) "Tags tree")
  2168. ((eq type 'todo-tree) "TODO kwd tree")
  2169. ((eq type 'occur-tree) "Occur tree")
  2170. ((functionp type) (if (symbolp type)
  2171. (symbol-name type)
  2172. "Lambda expression"))
  2173. (t "???"))))
  2174. (if org-agenda-menu-show-matcher
  2175. (setq line
  2176. (concat line ": "
  2177. (cond
  2178. ((stringp match)
  2179. (setq match (copy-sequence match))
  2180. (org-add-props match nil 'face 'org-warning))
  2181. (match
  2182. (format "set of %d commands" (length match)))
  2183. (t ""))))
  2184. (if (org-string-nw-p match)
  2185. (add-text-properties
  2186. 0 (length line) (list 'help-echo
  2187. (concat "Matcher: "match)) line)))
  2188. (push line lines)))
  2189. (setq lines (nreverse lines))
  2190. (when prefixes
  2191. (mapc (lambda (x)
  2192. (push
  2193. (format "%s %s"
  2194. (org-add-props (char-to-string x)
  2195. nil 'face 'bold)
  2196. (or (cdr (assoc (concat selstring
  2197. (char-to-string x))
  2198. prefix-descriptions))
  2199. "Prefix key"))
  2200. lines))
  2201. prefixes))
  2202. ;; Check if we should display in two columns
  2203. (if org-agenda-menu-two-column
  2204. (progn
  2205. (setq n (length lines)
  2206. n1 (+ (/ n 2) (mod n 2))
  2207. right (nthcdr n1 lines)
  2208. left (copy-sequence lines))
  2209. (setcdr (nthcdr (1- n1) left) nil))
  2210. (setq left lines right nil))
  2211. (while left
  2212. (insert "\n" (pop left))
  2213. (when right
  2214. (if (< (current-column) 40)
  2215. (move-to-column 40 t)
  2216. (insert " "))
  2217. (insert (pop right))))
  2218. ;; Make the window the right size
  2219. (goto-char (point-min))
  2220. (if second-time
  2221. (if (not (pos-visible-in-window-p (point-max)))
  2222. (org-fit-window-to-buffer))
  2223. (setq second-time t)
  2224. (org-fit-window-to-buffer))
  2225. ;; Ask for selection
  2226. (message "Press key for agenda command%s:"
  2227. (if (or restrict-ok org-agenda-overriding-restriction)
  2228. (if org-agenda-overriding-restriction
  2229. " (restriction lock active)"
  2230. (if restriction
  2231. (format " (restricted to %s)" restriction)
  2232. " (unrestricted)"))
  2233. ""))
  2234. (setq c (read-char-exclusive))
  2235. (message "")
  2236. (cond
  2237. ((assoc (char-to-string c) custom)
  2238. (setq selstring (concat selstring (char-to-string c)))
  2239. (throw 'exit (cons selstring restriction)))
  2240. ((memq c prefixes)
  2241. (setq selstring (concat selstring (char-to-string c))
  2242. prefixes nil
  2243. rmheader (or rmheader t)
  2244. custom (delq nil (mapcar
  2245. (lambda (x)
  2246. (if (or (= (length (car x)) 1)
  2247. (/= (string-to-char (car x)) c))
  2248. nil
  2249. (cons (substring (car x) 1) (cdr x))))
  2250. custom))))
  2251. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2252. (message "Restriction is only possible in Org-mode buffers")
  2253. (ding) (sit-for 1))
  2254. ((eq c ?1)
  2255. (org-agenda-remove-restriction-lock 'noupdate)
  2256. (setq restriction 'buffer))
  2257. ((eq c ?0)
  2258. (org-agenda-remove-restriction-lock 'noupdate)
  2259. (setq restriction (if region-p 'region 'subtree)))
  2260. ((eq c ?<)
  2261. (org-agenda-remove-restriction-lock 'noupdate)
  2262. (setq restriction
  2263. (cond
  2264. ((eq restriction 'buffer)
  2265. (if region-p 'region 'subtree))
  2266. ((memq restriction '(subtree region))
  2267. nil)
  2268. (t 'buffer))))
  2269. ((eq c ?>)
  2270. (org-agenda-remove-restriction-lock 'noupdate)
  2271. (setq restriction nil))
  2272. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2273. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2274. ((and (> (length selstring) 0) (eq c ?\d))
  2275. (delete-window)
  2276. (org-agenda-get-restriction-and-command prefix-descriptions))
  2277. ((equal c ?q) (error "Abort"))
  2278. (t (error "Invalid key %c" c))))))))
  2279. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2280. (defvar org-agenda-last-arguments nil
  2281. "The arguments of the previous call to `org-agenda'.")
  2282. (defun org-agenda-run-series (name series)
  2283. (org-let (nth 1 series) '(org-prepare-agenda name))
  2284. (let* ((org-agenda-multi t)
  2285. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2286. (org-agenda-overriding-arguments
  2287. (or org-agenda-overriding-arguments
  2288. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2289. (get 'org-agenda-redo-command 'last-args))))
  2290. (cmds (car series))
  2291. (gprops (nth 1 series))
  2292. match ;; The byte compiler incorrectly complains about this. Keep it!
  2293. cmd type lprops)
  2294. (while (setq cmd (pop cmds))
  2295. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2296. (cond
  2297. ((eq type 'agenda)
  2298. (org-let2 gprops lprops
  2299. '(call-interactively 'org-agenda-list)))
  2300. ((eq type 'alltodo)
  2301. (org-let2 gprops lprops
  2302. '(call-interactively 'org-todo-list)))
  2303. ((eq type 'search)
  2304. (org-let2 gprops lprops
  2305. '(org-search-view current-prefix-arg match nil)))
  2306. ((eq type 'stuck)
  2307. (org-let2 gprops lprops
  2308. '(call-interactively 'org-agenda-list-stuck-projects)))
  2309. ((eq type 'tags)
  2310. (org-let2 gprops lprops
  2311. '(org-tags-view current-prefix-arg match)))
  2312. ((eq type 'tags-todo)
  2313. (org-let2 gprops lprops
  2314. '(org-tags-view '(4) match)))
  2315. ((eq type 'todo)
  2316. (org-let2 gprops lprops
  2317. '(org-todo-list match)))
  2318. ((fboundp type)
  2319. (org-let2 gprops lprops
  2320. '(funcall type match)))
  2321. (t (error "Invalid type in command series"))))
  2322. (widen)
  2323. (setq org-agenda-redo-command redo)
  2324. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2325. (goto-char (point-min)))
  2326. (org-fit-agenda-window)
  2327. (org-let (nth 1 series) '(org-finalize-agenda)))
  2328. ;;;###autoload
  2329. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2330. "Run an agenda command in batch mode and send the result to STDOUT.
  2331. If CMD-KEY is a string of length 1, it is used as a key in
  2332. `org-agenda-custom-commands' and triggers this command. If it is a
  2333. longer string it is used as a tags/todo match string.
  2334. Parameters are alternating variable names and values that will be bound
  2335. before running the agenda command."
  2336. (let (pars)
  2337. (while parameters
  2338. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2339. (if (> (length cmd-key) 2)
  2340. (eval (list 'let (nreverse pars)
  2341. (list 'org-tags-view nil cmd-key)))
  2342. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2343. (set-buffer org-agenda-buffer-name)
  2344. (princ (org-encode-for-stdout (buffer-string)))))
  2345. ;(defun org-encode-for-stdout (string)
  2346. ; (if (fboundp 'encode-coding-string)
  2347. ; (encode-coding-string string buffer-file-coding-system)
  2348. ; string))
  2349. (defun org-encode-for-stdout (string)
  2350. string)
  2351. (defvar org-agenda-info nil)
  2352. ;;;###autoload
  2353. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2354. "Run an agenda command in batch mode and send the result to STDOUT.
  2355. If CMD-KEY is a string of length 1, it is used as a key in
  2356. `org-agenda-custom-commands' and triggers this command. If it is a
  2357. longer string it is used as a tags/todo match string.
  2358. Parameters are alternating variable names and values that will be bound
  2359. before running the agenda command.
  2360. The output gives a line for each selected agenda item. Each
  2361. item is a list of comma-separated values, like this:
  2362. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2363. category The category of the item
  2364. head The headline, without TODO kwd, TAGS and PRIORITY
  2365. type The type of the agenda entry, can be
  2366. todo selected in TODO match
  2367. tagsmatch selected in tags match
  2368. diary imported from diary
  2369. deadline a deadline on given date
  2370. scheduled scheduled on given date
  2371. timestamp entry has timestamp on given date
  2372. closed entry was closed on given date
  2373. upcoming-deadline warning about deadline
  2374. past-scheduled forwarded scheduled item
  2375. block entry has date block including g. date
  2376. todo The todo keyword, if any
  2377. tags All tags including inherited ones, separated by colons
  2378. date The relevant date, like 2007-2-14
  2379. time The time, like 15:00-16:50
  2380. extra Sting with extra planning info
  2381. priority-l The priority letter if any was given
  2382. priority-n The computed numerical priority
  2383. agenda-day The day in the agenda where this is listed"
  2384. (let (pars)
  2385. (while parameters
  2386. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2387. (push (list 'org-agenda-remove-tags t) pars)
  2388. (if (> (length cmd-key) 2)
  2389. (eval (list 'let (nreverse pars)
  2390. (list 'org-tags-view nil cmd-key)))
  2391. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2392. (set-buffer org-agenda-buffer-name)
  2393. (let* ((lines (org-split-string (buffer-string) "\n"))
  2394. line)
  2395. (while (setq line (pop lines))
  2396. (catch 'next
  2397. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2398. (setq org-agenda-info
  2399. (org-fix-agenda-info (text-properties-at 0 line)))
  2400. (princ
  2401. (org-encode-for-stdout
  2402. (mapconcat 'org-agenda-export-csv-mapper
  2403. '(org-category txt type todo tags date time extra
  2404. priority-letter priority agenda-day)
  2405. ",")))
  2406. (princ "\n"))))))
  2407. (defun org-fix-agenda-info (props)
  2408. "Make sure all properties on an agenda item have a canonical form.
  2409. This ensures the export commands can easily use it."
  2410. (let (tmp re)
  2411. (when (setq tmp (plist-get props 'tags))
  2412. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2413. (when (setq tmp (plist-get props 'date))
  2414. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2415. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2416. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2417. (setq tmp (calendar-date-string tmp)))
  2418. (setq props (plist-put props 'date tmp)))
  2419. (when (setq tmp (plist-get props 'day))
  2420. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2421. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2422. (setq tmp (calendar-date-string tmp)))
  2423. (setq props (plist-put props 'day tmp))
  2424. (setq props (plist-put props 'agenda-day tmp)))
  2425. (when (setq tmp (plist-get props 'txt))
  2426. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2427. (plist-put props 'priority-letter (match-string 1 tmp))
  2428. (setq tmp (replace-match "" t t tmp)))
  2429. (when (and (setq re (plist-get props 'org-todo-regexp))
  2430. (setq re (concat "\\`\\.*" re " ?"))
  2431. (string-match re tmp))
  2432. (plist-put props 'todo (match-string 1 tmp))
  2433. (setq tmp (replace-match "" t t tmp)))
  2434. (plist-put props 'txt tmp)))
  2435. props)
  2436. (defun org-agenda-export-csv-mapper (prop)
  2437. (let ((res (plist-get org-agenda-info prop)))
  2438. (setq res
  2439. (cond
  2440. ((not res) "")
  2441. ((stringp res) res)
  2442. (t (prin1-to-string res))))
  2443. (while (string-match "," res)
  2444. (setq res (replace-match ";" t t res)))
  2445. (org-trim res)))
  2446. ;;;###autoload
  2447. (defun org-store-agenda-views (&rest parameters)
  2448. (interactive)
  2449. (eval (list 'org-batch-store-agenda-views)))
  2450. ;; FIXME, why is this a macro?????
  2451. ;;;###autoload
  2452. (defmacro org-batch-store-agenda-views (&rest parameters)
  2453. "Run all custom agenda commands that have a file argument."
  2454. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2455. (pop-up-frames nil)
  2456. (dir default-directory)
  2457. pars cmd thiscmdkey files opts cmd-or-set)
  2458. (while parameters
  2459. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2460. (setq pars (reverse pars))
  2461. (save-window-excursion
  2462. (while cmds
  2463. (setq cmd (pop cmds)
  2464. thiscmdkey (car cmd)
  2465. cmd-or-set (nth 2 cmd)
  2466. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2467. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2468. (if (stringp files) (setq files (list files)))
  2469. (when files
  2470. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2471. (list 'org-agenda nil thiscmdkey)))
  2472. (set-buffer org-agenda-buffer-name)
  2473. (while files
  2474. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2475. (list 'org-write-agenda
  2476. (expand-file-name (pop files) dir) nil t))))
  2477. (and (get-buffer org-agenda-buffer-name)
  2478. (kill-buffer org-agenda-buffer-name)))))))
  2479. (defun org-agenda-mark-header-line (pos)
  2480. "Mark the line at POS as an agenda structure header."
  2481. (save-excursion
  2482. (goto-char pos)
  2483. (put-text-property (point-at-bol) (point-at-eol)
  2484. 'org-agenda-structural-header t)
  2485. (when org-agenda-title-append
  2486. (put-text-property (point-at-bol) (point-at-eol)
  2487. 'org-agenda-title-append org-agenda-title-append))))
  2488. (defvar org-mobile-creating-agendas)
  2489. (defun org-write-agenda (file &optional open nosettings)
  2490. "Write the current buffer (an agenda view) as a file.
  2491. Depending on the extension of the file name, plain text (.txt),
  2492. HTML (.html or .htm) or Postscript (.ps) is produced.
  2493. If the extension is .ics, run icalendar export over all files used
  2494. to construct the agenda and limit the export to entries listed in the
  2495. agenda now.
  2496. With prefix argument OPEN, open the new file immediately.
  2497. If NOSETTINGS is given, do not scope the settings of
  2498. `org-agenda-exporter-settings' into the export commands. This is used when
  2499. the settings have already been scoped and we do not wish to overrule other,
  2500. higher priority settings."
  2501. (interactive "FWrite agenda to file: \nP")
  2502. (if (not (file-writable-p file))
  2503. (error "Cannot write agenda to file %s" file))
  2504. (org-let (if nosettings nil org-agenda-exporter-settings)
  2505. '(save-excursion
  2506. (save-window-excursion
  2507. (org-agenda-mark-filtered-text)
  2508. (let ((bs (copy-sequence (buffer-string))) beg)
  2509. (org-agenda-unmark-filtered-text)
  2510. (with-temp-buffer
  2511. (rename-buffer "Agenda View" t)
  2512. (set-buffer-modified-p nil)
  2513. (insert bs)
  2514. (org-agenda-remove-marked-text 'org-filtered)
  2515. (while (setq beg (text-property-any (point-min) (point-max)
  2516. 'org-filtered t))
  2517. (delete-region
  2518. beg (or (next-single-property-change beg 'org-filtered)
  2519. (point-max))))
  2520. (run-hooks 'org-agenda-before-write-hook)
  2521. (cond
  2522. ((org-bound-and-true-p org-mobile-creating-agendas)
  2523. (org-mobile-write-agenda-for-mobile file))
  2524. ((string-match "\\.html?\\'" file)
  2525. (require 'htmlize)
  2526. (set-buffer (htmlize-buffer (current-buffer)))
  2527. (when (and org-agenda-export-html-style
  2528. (string-match "<style>" org-agenda-export-html-style))
  2529. ;; replace <style> section with org-agenda-export-html-style
  2530. (goto-char (point-min))
  2531. (kill-region (- (search-forward "<style") 6)
  2532. (search-forward "</style>"))
  2533. (insert org-agenda-export-html-style))
  2534. (write-file file)
  2535. (kill-buffer (current-buffer))
  2536. (message "HTML written to %s" file))
  2537. ((string-match "\\.ps\\'" file)
  2538. (require 'ps-print)
  2539. (ps-print-buffer-with-faces file)
  2540. (message "Postscript written to %s" file))
  2541. ((string-match "\\.pdf\\'" file)
  2542. (require 'ps-print)
  2543. (ps-print-buffer-with-faces
  2544. (concat (file-name-sans-extension file) ".ps"))
  2545. (call-process "ps2pdf" nil nil nil
  2546. (expand-file-name
  2547. (concat (file-name-sans-extension file) ".ps"))
  2548. (expand-file-name file))
  2549. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2550. (message "PDF written to %s" file))
  2551. ((string-match "\\.ics\\'" file)
  2552. (require 'org-icalendar)
  2553. (let ((org-agenda-marker-table
  2554. (org-create-marker-find-array
  2555. (org-agenda-collect-markers)))
  2556. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2557. (org-combined-agenda-icalendar-file file))
  2558. (apply 'org-export-icalendar 'combine
  2559. (org-agenda-files nil 'ifmode))))
  2560. (t
  2561. (let ((bs (buffer-string)))
  2562. (find-file file)
  2563. (erase-buffer)
  2564. (insert bs)
  2565. (save-buffer 0)
  2566. (kill-buffer (current-buffer))
  2567. (message "Plain text written to %s" file))))))))
  2568. (set-buffer org-agenda-buffer-name))
  2569. (when open (org-open-file file)))
  2570. (defvar org-agenda-filter-overlays nil)
  2571. (defun org-agenda-mark-filtered-text ()
  2572. "Mark all text hidden by filtering with a text property."
  2573. (let ((inhibit-read-only t))
  2574. (mapc
  2575. (lambda (o)
  2576. (when (equal (overlay-buffer o) (current-buffer))
  2577. (put-text-property
  2578. (overlay-start o) (overlay-end o)
  2579. 'org-filtered t)))
  2580. org-agenda-filter-overlays)))
  2581. (defun org-agenda-unmark-filtered-text ()
  2582. "Remove the filtering text property."
  2583. (let ((inhibit-read-only t))
  2584. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2585. (defun org-agenda-remove-marked-text (property &optional value)
  2586. "Delete all text marked with VALUE of PROPERTY.
  2587. VALUE defaults to t."
  2588. (let (beg)
  2589. (setq value (or value t))
  2590. (while (setq beg (text-property-any (point-min) (point-max)
  2591. property value))
  2592. (delete-region
  2593. beg (or (next-single-property-change beg 'org-filtered)
  2594. (point-max))))))
  2595. (defun org-agenda-add-entry-text ()
  2596. "Add entry text to agenda lines.
  2597. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2598. entry text following headings shown in the agenda.
  2599. Drawers will be excluded, also the line with scheduling/deadline info."
  2600. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2601. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2602. (let (m txt)
  2603. (goto-char (point-min))
  2604. (while (not (eobp))
  2605. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2606. (beginning-of-line 2)
  2607. (setq txt (org-agenda-get-some-entry-text
  2608. m org-agenda-add-entry-text-maxlines " > "))
  2609. (end-of-line 1)
  2610. (if (string-match "\\S-" txt)
  2611. (insert "\n" txt)
  2612. (or (eobp) (forward-char 1))))))))
  2613. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2614. &rest keep)
  2615. "Extract entry text from MARKER, at most N-LINES lines.
  2616. This will ignore drawers etc, just get the text.
  2617. If INDENT is given, prefix every line with this string. If KEEP is
  2618. given, it is a list of symbols, defining stuff that should not be
  2619. removed from the entry content. Currently only `planning' is allowed here."
  2620. (let (txt drawer-re kwd-time-re ind)
  2621. (save-excursion
  2622. (with-current-buffer (marker-buffer marker)
  2623. (if (not (org-mode-p))
  2624. (setq txt "")
  2625. (save-excursion
  2626. (save-restriction
  2627. (widen)
  2628. (goto-char marker)
  2629. (end-of-line 1)
  2630. (setq txt (buffer-substring
  2631. (min (1+ (point)) (point-max))
  2632. (progn (outline-next-heading) (point)))
  2633. drawer-re org-drawer-regexp
  2634. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2635. ".*\n?"))
  2636. (with-temp-buffer
  2637. (insert txt)
  2638. (when org-agenda-add-entry-text-descriptive-links
  2639. (goto-char (point-min))
  2640. (while (org-activate-bracket-links (point-max))
  2641. (add-text-properties (match-beginning 0) (match-end 0)
  2642. '(face org-link))))
  2643. (goto-char (point-min))
  2644. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2645. (set-text-properties (match-beginning 0) (match-end 0)
  2646. nil))
  2647. (goto-char (point-min))
  2648. (while (re-search-forward drawer-re nil t)
  2649. (delete-region
  2650. (match-beginning 0)
  2651. (progn (re-search-forward
  2652. "^[ \t]*:END:.*\n?" nil 'move)
  2653. (point))))
  2654. (unless (member 'planning keep)
  2655. (goto-char (point-min))
  2656. (while (re-search-forward kwd-time-re nil t)
  2657. (replace-match "")))
  2658. (goto-char (point-min))
  2659. (when org-agenda-entry-text-exclude-regexps
  2660. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2661. (while (setq re (pop re-list))
  2662. (goto-char (point-min))
  2663. (while (re-search-forward re nil t)
  2664. (replace-match "")))))
  2665. (goto-char (point-max))
  2666. (skip-chars-backward " \t\n")
  2667. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2668. ;; find and remove min common indentation
  2669. (goto-char (point-min))
  2670. (untabify (point-min) (point-max))
  2671. (setq ind (org-get-indentation))
  2672. (while (not (eobp))
  2673. (unless (looking-at "[ \t]*$")
  2674. (setq ind (min ind (org-get-indentation))))
  2675. (beginning-of-line 2))
  2676. (goto-char (point-min))
  2677. (while (not (eobp))
  2678. (unless (looking-at "[ \t]*$")
  2679. (move-to-column ind)
  2680. (delete-region (point-at-bol) (point)))
  2681. (beginning-of-line 2))
  2682. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2683. (goto-char (point-min))
  2684. (when indent
  2685. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2686. (replace-match indent t t)))
  2687. (goto-char (point-min))
  2688. (while (looking-at "[ \t]*\n") (replace-match ""))
  2689. (goto-char (point-max))
  2690. (when (> (org-current-line)
  2691. n-lines)
  2692. (org-goto-line (1+ n-lines))
  2693. (backward-char 1))
  2694. (setq txt (buffer-substring (point-min) (point)))))))))
  2695. txt))
  2696. (defun org-agenda-collect-markers ()
  2697. "Collect the markers pointing to entries in the agenda buffer."
  2698. (let (m markers)
  2699. (save-excursion
  2700. (goto-char (point-min))
  2701. (while (not (eobp))
  2702. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2703. (org-get-at-bol 'org-marker)))
  2704. (push m markers))
  2705. (beginning-of-line 2)))
  2706. (nreverse markers)))
  2707. (defun org-create-marker-find-array (marker-list)
  2708. "Create a alist of files names with all marker positions in that file."
  2709. (let (f tbl m a p)
  2710. (while (setq m (pop marker-list))
  2711. (setq p (marker-position m)
  2712. f (buffer-file-name (or (buffer-base-buffer
  2713. (marker-buffer m))
  2714. (marker-buffer m))))
  2715. (if (setq a (assoc f tbl))
  2716. (push (marker-position m) (cdr a))
  2717. (push (list f p) tbl)))
  2718. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2719. tbl)))
  2720. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2721. (defun org-check-agenda-marker-table ()
  2722. "Check of the current entry is on the marker list."
  2723. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2724. a)
  2725. (and (setq a (assoc file org-agenda-marker-table))
  2726. (save-match-data
  2727. (save-excursion
  2728. (org-back-to-heading t)
  2729. (member (point) (cdr a)))))))
  2730. (defun org-check-for-org-mode ()
  2731. "Make sure current buffer is in org-mode. Error if not."
  2732. (or (org-mode-p)
  2733. (error "Cannot execute org-mode agenda command on buffer in %s"
  2734. major-mode)))
  2735. (defun org-fit-agenda-window ()
  2736. "Fit the window to the buffer size."
  2737. (and (memq org-agenda-window-setup '(reorganize-frame))
  2738. (fboundp 'fit-window-to-buffer)
  2739. (org-fit-window-to-buffer
  2740. nil
  2741. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2742. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2743. ;;; Agenda prepare and finalize
  2744. (defvar org-agenda-multi nil) ; dynamically scoped
  2745. (defvar org-agenda-buffer-name "*Org Agenda*")
  2746. (defvar org-pre-agenda-window-conf nil)
  2747. (defvar org-agenda-columns-active nil)
  2748. (defvar org-agenda-name nil)
  2749. (defvar org-agenda-filter nil)
  2750. (defvar org-agenda-filter-while-redo nil)
  2751. (defvar org-agenda-filter-preset nil
  2752. "A preset of the tags filter used for secondary agenda filtering.
  2753. This must be a list of strings, each string must be a single tag preceded
  2754. by \"+\" or \"-\".
  2755. This variable should not be set directly, but agenda custom commands can
  2756. bind it in the options section. The preset filter is a global property of
  2757. the entire agenda view. In a block agenda, it will not work reliably to
  2758. define a filter for one of the individual blocks. You need to set it in
  2759. the global options and expect it to be applied to the entire view.")
  2760. (defun org-prepare-agenda (&optional name)
  2761. (setq org-todo-keywords-for-agenda nil)
  2762. (setq org-done-keywords-for-agenda nil)
  2763. (setq org-drawers-for-agenda nil)
  2764. (unless org-agenda-persistent-filter
  2765. (setq org-agenda-filter nil))
  2766. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2767. (if org-agenda-multi
  2768. (progn
  2769. (setq buffer-read-only nil)
  2770. (goto-char (point-max))
  2771. (unless (or (bobp) org-agenda-compact-blocks
  2772. (not org-agenda-block-separator))
  2773. (insert "\n"
  2774. (if (stringp org-agenda-block-separator)
  2775. org-agenda-block-separator
  2776. (make-string (window-width) org-agenda-block-separator))
  2777. "\n"))
  2778. (narrow-to-region (point) (point-max)))
  2779. (org-agenda-reset-markers)
  2780. (setq org-agenda-contributing-files nil)
  2781. (setq org-agenda-columns-active nil)
  2782. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2783. (setq org-todo-keywords-for-agenda
  2784. (org-uniquify org-todo-keywords-for-agenda))
  2785. (setq org-done-keywords-for-agenda
  2786. (org-uniquify org-done-keywords-for-agenda))
  2787. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2788. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2789. (awin (get-buffer-window abuf)))
  2790. (cond
  2791. ((equal (current-buffer) abuf) nil)
  2792. (awin (select-window awin))
  2793. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2794. ((equal org-agenda-window-setup 'current-window)
  2795. (switch-to-buffer abuf))
  2796. ((equal org-agenda-window-setup 'other-window)
  2797. (org-switch-to-buffer-other-window abuf))
  2798. ((equal org-agenda-window-setup 'other-frame)
  2799. (switch-to-buffer-other-frame abuf))
  2800. ((equal org-agenda-window-setup 'reorganize-frame)
  2801. (delete-other-windows)
  2802. (org-switch-to-buffer-other-window abuf)))
  2803. ;; additional test in case agenda is invoked from within agenda
  2804. ;; buffer via elisp link
  2805. (unless (equal (current-buffer) abuf)
  2806. (switch-to-buffer abuf)))
  2807. (setq buffer-read-only nil)
  2808. (let ((inhibit-read-only t)) (erase-buffer))
  2809. (org-agenda-mode)
  2810. (and name (not org-agenda-name)
  2811. (org-set-local 'org-agenda-name name)))
  2812. (setq buffer-read-only nil))
  2813. (defun org-finalize-agenda ()
  2814. "Finishing touch for the agenda buffer, called just before displaying it."
  2815. (unless org-agenda-multi
  2816. (save-excursion
  2817. (let ((inhibit-read-only t))
  2818. (goto-char (point-min))
  2819. (while (org-activate-bracket-links (point-max))
  2820. (add-text-properties (match-beginning 0) (match-end 0)
  2821. '(face org-link)))
  2822. (org-agenda-align-tags)
  2823. (unless org-agenda-with-colors
  2824. (remove-text-properties (point-min) (point-max) '(face nil))))
  2825. (if (and (boundp 'org-agenda-overriding-columns-format)
  2826. org-agenda-overriding-columns-format)
  2827. (org-set-local 'org-agenda-overriding-columns-format
  2828. org-agenda-overriding-columns-format))
  2829. (if (and (boundp 'org-agenda-view-columns-initially)
  2830. org-agenda-view-columns-initially)
  2831. (org-agenda-columns))
  2832. (when org-agenda-fontify-priorities
  2833. (org-agenda-fontify-priorities))
  2834. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2835. (org-agenda-dim-blocked-tasks))
  2836. (org-agenda-mark-clocking-task)
  2837. (when org-agenda-entry-text-mode
  2838. (org-agenda-entry-text-hide)
  2839. (org-agenda-entry-text-show))
  2840. (if (functionp 'org-habit-insert-consistency-graphs)
  2841. (org-habit-insert-consistency-graphs))
  2842. (run-hooks 'org-finalize-agenda-hook)
  2843. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2844. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2845. (org-agenda-filter-apply org-agenda-filter))
  2846. )))
  2847. (defun org-agenda-mark-clocking-task ()
  2848. "Mark the current clock entry in the agenda if it is present."
  2849. (mapc (lambda (o)
  2850. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2851. (delete-overlay o)))
  2852. (overlays-in (point-min) (point-max)))
  2853. (when (marker-buffer org-clock-hd-marker)
  2854. (save-excursion
  2855. (goto-char (point-min))
  2856. (let (s ov)
  2857. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2858. (goto-char s)
  2859. (when (equal (org-get-at-bol 'org-hd-marker)
  2860. org-clock-hd-marker)
  2861. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2862. (overlay-put ov 'type 'org-agenda-clocking)
  2863. (overlay-put ov 'face 'org-agenda-clocking)
  2864. (overlay-put ov 'help-echo
  2865. "The clock is running in this item")))))))
  2866. (defun org-agenda-fontify-priorities ()
  2867. "Make highest priority lines bold, and lowest italic."
  2868. (interactive)
  2869. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2870. (delete-overlay o)))
  2871. (overlays-in (point-min) (point-max)))
  2872. (save-excursion
  2873. (let ((inhibit-read-only t)
  2874. b e p ov h l)
  2875. (goto-char (point-min))
  2876. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2877. (setq h (or (get-char-property (point) 'org-highest-priority)
  2878. org-highest-priority)
  2879. l (or (get-char-property (point) 'org-lowest-priority)
  2880. org-lowest-priority)
  2881. p (string-to-char (match-string 1))
  2882. b (match-beginning 0)
  2883. e (if (eq org-agenda-fontify-priorities 'cookies)
  2884. (match-end 0)
  2885. (point-at-eol))
  2886. ov (make-overlay b e))
  2887. (overlay-put
  2888. ov 'face
  2889. (cond ((org-face-from-face-or-color
  2890. 'priority nil
  2891. (cdr (assoc p org-priority-faces))))
  2892. ((and (listp org-agenda-fontify-priorities)
  2893. (org-face-from-face-or-color
  2894. 'priority nil
  2895. (cdr (assoc p org-agenda-fontify-priorities)))))
  2896. ((equal p l) 'italic)
  2897. ((equal p h) 'bold)))
  2898. (overlay-put ov 'org-type 'org-priority)))))
  2899. (defun org-agenda-dim-blocked-tasks ()
  2900. "Dim currently blocked TODO's in the agenda display."
  2901. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2902. (delete-overlay o)))
  2903. (overlays-in (point-min) (point-max)))
  2904. (save-excursion
  2905. (let ((inhibit-read-only t)
  2906. (org-depend-tag-blocked nil)
  2907. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2908. org-blocked-by-checkboxes
  2909. invis1 b e p ov h l)
  2910. (goto-char (point-min))
  2911. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2912. (and pos (goto-char (1+ pos))))
  2913. (setq org-blocked-by-checkboxes nil invis1 invis)
  2914. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2915. (when (and marker
  2916. (not (with-current-buffer (marker-buffer marker)
  2917. (save-excursion
  2918. (goto-char marker)
  2919. (if (org-entry-get nil "NOBLOCKING")
  2920. t ;; Never block this entry
  2921. (run-hook-with-args-until-failure
  2922. 'org-blocker-hook
  2923. (list :type 'todo-state-change
  2924. :position marker
  2925. :from 'todo
  2926. :to 'done)))))))
  2927. (if org-blocked-by-checkboxes (setq invis1 nil))
  2928. (setq b (if invis1
  2929. (max (point-min) (1- (point-at-bol)))
  2930. (point-at-bol))
  2931. e (point-at-eol)
  2932. ov (make-overlay b e))
  2933. (if invis1
  2934. (overlay-put ov 'invisible t)
  2935. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2936. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2937. (defvar org-agenda-skip-function nil
  2938. "Function to be called at each match during agenda construction.
  2939. If this function returns nil, the current match should not be skipped.
  2940. Otherwise, the function must return a position from where the search
  2941. should be continued.
  2942. This may also be a Lisp form, it will be evaluated.
  2943. Never set this variable using `setq' or so, because then it will apply
  2944. to all future agenda commands. If you do want a global skipping condition,
  2945. use the option `org-agenda-skip-function-global' instead.
  2946. The correct usage for `org-agenda-skip-function' is to bind it with
  2947. `let' to scope it dynamically into the agenda-constructing command.
  2948. A good way to set it is through options in `org-agenda-custom-commands'.")
  2949. (defun org-agenda-skip ()
  2950. "Throw to `:skip' in places that should be skipped.
  2951. Also moves point to the end of the skipped region, so that search can
  2952. continue from there."
  2953. (let ((p (point-at-bol)) to)
  2954. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2955. (get-text-property p :org-archived)
  2956. (org-end-of-subtree t)
  2957. (throw :skip t))
  2958. (and org-agenda-skip-comment-trees
  2959. (get-text-property p :org-comment)
  2960. (org-end-of-subtree t)
  2961. (throw :skip t))
  2962. (if (equal (char-after p) ?#) (throw :skip t))
  2963. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2964. (org-agenda-skip-eval org-agenda-skip-function)))
  2965. (goto-char to)
  2966. (throw :skip t))))
  2967. (defun org-agenda-skip-eval (form)
  2968. "If FORM is a function or a list, call (or eval) is and return result.
  2969. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2970. and match data are returned to the previous state no matter what these
  2971. functions do."
  2972. (let (fp)
  2973. (and form
  2974. (or (setq fp (functionp form))
  2975. (consp form))
  2976. (save-excursion
  2977. (save-match-data
  2978. (if fp
  2979. (funcall form)
  2980. (eval form)))))))
  2981. (defvar org-agenda-markers nil
  2982. "List of all currently active markers created by `org-agenda'.")
  2983. (defvar org-agenda-last-marker-time (org-float-time)
  2984. "Creation time of the last agenda marker.")
  2985. (defun org-agenda-new-marker (&optional pos)
  2986. "Return a new agenda marker.
  2987. Org-mode keeps a list of these markers and resets them when they are
  2988. no longer in use."
  2989. (let ((m (copy-marker (or pos (point)))))
  2990. (setq org-agenda-last-marker-time (org-float-time))
  2991. (push m org-agenda-markers)
  2992. m))
  2993. (defun org-agenda-reset-markers ()
  2994. "Reset markers created by `org-agenda'."
  2995. (while org-agenda-markers
  2996. (move-marker (pop org-agenda-markers) nil)))
  2997. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2998. "Save relative positions of markers in region."
  2999. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3000. org-agenda-markers))
  3001. ;;; Entry text mode
  3002. (defun org-agenda-entry-text-show-here ()
  3003. "Add some text from the entry as context to the current line."
  3004. (let (m txt o)
  3005. (setq m (org-get-at-bol 'org-hd-marker))
  3006. (unless (marker-buffer m)
  3007. (error "No marker points to an entry here"))
  3008. (setq txt (concat "\n" (org-no-properties
  3009. (org-agenda-get-some-entry-text
  3010. m org-agenda-entry-text-maxlines " > "))))
  3011. (when (string-match "\\S-" txt)
  3012. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3013. (overlay-put o 'evaporate t)
  3014. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3015. (overlay-put o 'after-string txt))))
  3016. (defun org-agenda-entry-text-show ()
  3017. "Add entry context for all agenda lines."
  3018. (interactive)
  3019. (save-excursion
  3020. (goto-char (point-max))
  3021. (beginning-of-line 1)
  3022. (while (not (bobp))
  3023. (when (org-get-at-bol 'org-hd-marker)
  3024. (org-agenda-entry-text-show-here))
  3025. (beginning-of-line 0))))
  3026. (defun org-agenda-entry-text-hide ()
  3027. "Remove any shown entry context."
  3028. (delq nil
  3029. (mapcar (lambda (o)
  3030. (if (eq (overlay-get o 'org-overlay-type)
  3031. 'agenda-entry-content)
  3032. (progn (delete-overlay o) t)))
  3033. (overlays-in (point-min) (point-max)))))
  3034. (defun org-agenda-get-day-face (date)
  3035. "Return the face DATE should be displayed with."
  3036. (or (and (functionp org-agenda-day-face-function)
  3037. (funcall org-agenda-day-face-function date))
  3038. (cond ((org-agenda-todayp date)
  3039. 'org-agenda-date-today)
  3040. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3041. 'org-agenda-date-weekend)
  3042. (t 'org-agenda-date))))
  3043. ;;; Agenda timeline
  3044. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3045. (defun org-timeline (&optional include-all)
  3046. "Show a time-sorted view of the entries in the current org file.
  3047. Only entries with a time stamp of today or later will be listed. With
  3048. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3049. under the current date.
  3050. If the buffer contains an active region, only check the region for
  3051. dates."
  3052. (interactive "P")
  3053. (org-compile-prefix-format 'timeline)
  3054. (org-set-sorting-strategy 'timeline)
  3055. (let* ((dopast t)
  3056. (dotodo include-all)
  3057. (doclosed org-agenda-show-log)
  3058. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3059. (current-buffer))))
  3060. (date (calendar-current-date))
  3061. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3062. (end (if (org-region-active-p) (region-end) (point-max)))
  3063. (day-numbers (org-get-all-dates beg end 'no-ranges
  3064. t doclosed ; always include today
  3065. org-timeline-show-empty-dates))
  3066. (org-deadline-warning-days 0)
  3067. (org-agenda-only-exact-dates t)
  3068. (today (org-today))
  3069. (past t)
  3070. args
  3071. s e rtn d emptyp)
  3072. (setq org-agenda-redo-command
  3073. (list 'progn
  3074. (list 'org-switch-to-buffer-other-window (current-buffer))
  3075. (list 'org-timeline (list 'quote include-all))))
  3076. (if (not dopast)
  3077. ;; Remove past dates from the list of dates.
  3078. (setq day-numbers (delq nil (mapcar (lambda(x)
  3079. (if (>= x today) x nil))
  3080. day-numbers))))
  3081. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3082. (if doclosed (push :closed args))
  3083. (push :timestamp args)
  3084. (push :deadline args)
  3085. (push :scheduled args)
  3086. (push :sexp args)
  3087. (if dotodo (push :todo args))
  3088. (insert "Timeline of file " entry "\n")
  3089. (add-text-properties (point-min) (point)
  3090. (list 'face 'org-agenda-structure))
  3091. (org-agenda-mark-header-line (point-min))
  3092. (while (setq d (pop day-numbers))
  3093. (if (and (listp d) (eq (car d) :omitted))
  3094. (progn
  3095. (setq s (point))
  3096. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3097. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3098. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3099. (if (and (>= d today)
  3100. dopast
  3101. past)
  3102. (progn
  3103. (setq past nil)
  3104. (insert (make-string 79 ?-) "\n")))
  3105. (setq date (calendar-gregorian-from-absolute d))
  3106. (setq s (point))
  3107. (setq rtn (and (not emptyp)
  3108. (apply 'org-agenda-get-day-entries entry
  3109. date args)))
  3110. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3111. (progn
  3112. (insert
  3113. (if (stringp org-agenda-format-date)
  3114. (format-time-string org-agenda-format-date
  3115. (org-time-from-absolute date))
  3116. (funcall org-agenda-format-date date))
  3117. "\n")
  3118. (put-text-property s (1- (point)) 'face
  3119. (org-agenda-get-day-face date))
  3120. (put-text-property s (1- (point)) 'org-date-line t)
  3121. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3122. (if (equal d today)
  3123. (put-text-property s (1- (point)) 'org-today t))
  3124. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3125. (put-text-property s (1- (point)) 'day d)))))
  3126. (goto-char (point-min))
  3127. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3128. (point-min)))
  3129. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3130. (org-finalize-agenda)
  3131. (setq buffer-read-only t)))
  3132. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3133. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3134. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3135. not every single day in the range. If FORCE-TODAY is non-nil, make
  3136. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3137. inactive time stamps (those in square brackets) are included.
  3138. When EMPTY is non-nil, also include days without any entries."
  3139. (let ((re (concat
  3140. (if pre-re pre-re "")
  3141. (if inactive org-ts-regexp-both org-ts-regexp)))
  3142. dates dates1 date day day1 day2 ts1 ts2)
  3143. (if force-today
  3144. (setq dates (list (org-today))))
  3145. (save-excursion
  3146. (goto-char beg)
  3147. (while (re-search-forward re end t)
  3148. (setq day (time-to-days (org-time-string-to-time
  3149. (substring (match-string 1) 0 10))))
  3150. (or (memq day dates) (push day dates)))
  3151. (unless no-ranges
  3152. (goto-char beg)
  3153. (while (re-search-forward org-tr-regexp end t)
  3154. (setq ts1 (substring (match-string 1) 0 10)
  3155. ts2 (substring (match-string 2) 0 10)
  3156. day1 (time-to-days (org-time-string-to-time ts1))
  3157. day2 (time-to-days (org-time-string-to-time ts2)))
  3158. (while (< (setq day1 (1+ day1)) day2)
  3159. (or (memq day1 dates) (push day1 dates)))))
  3160. (setq dates (sort dates '<))
  3161. (when empty
  3162. (while (setq day (pop dates))
  3163. (setq day2 (car dates))
  3164. (push day dates1)
  3165. (when (and day2 empty)
  3166. (if (or (eq empty t)
  3167. (and (numberp empty) (<= (- day2 day) empty)))
  3168. (while (< (setq day (1+ day)) day2)
  3169. (push (list day) dates1))
  3170. (push (cons :omitted (- day2 day)) dates1))))
  3171. (setq dates (nreverse dates1)))
  3172. dates)))
  3173. ;;; Agenda Daily/Weekly
  3174. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3175. "Start day for the agenda view.
  3176. Custom commands can set this variable in the options section.")
  3177. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3178. (defvar org-agenda-current-span nil
  3179. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3180. (defvar org-include-all-loc nil) ; local variable
  3181. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3182. "List of types searched for when creating the daily/weekly agenda.
  3183. This variable is a list of symbols that controls the types of
  3184. items that appear in the daily/weekly agenda. Allowed symbols in this
  3185. list are are
  3186. :timestamp List items containing a date stamp or date range matching
  3187. the selected date. This includes sexp entries in
  3188. angular brackets.
  3189. :sexp List entries resulting from plain diary-like sexps.
  3190. :deadline List deadline due on that date. When the date is today,
  3191. also list any deadlines past due, or due within
  3192. `org-deadline-warning-days'. `:deadline' must appear before
  3193. `:scheduled' if the setting of
  3194. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3195. any effect.
  3196. :scheduled List all items which are scheduled for the given date.
  3197. The diary for *today* also contains items which were
  3198. scheduled earlier and are not yet marked DONE.
  3199. By default, all four types are turned on.
  3200. Never set this variable globally using `setq', because then it
  3201. will apply to all future agenda commands. Instead, bind it with
  3202. `let' to scope it dynamically into the agenda-constructing
  3203. command. A good way to set it is through options in
  3204. `org-agenda-custom-commands'. For a more flexible (though
  3205. somewhat less efficient) way of determining what is included in
  3206. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3207. ;;;###autoload
  3208. (defun org-agenda-list (&optional include-all start-day span)
  3209. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3210. The view will be for the current day or week, but from the overview buffer
  3211. you will be able to go to other days/weeks.
  3212. With a numeric prefix argument in an interactive call, the agenda will
  3213. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3214. the number of days. SPAN defaults to `org-agenda-span'.
  3215. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3216. given in `org-agenda-start-on-weekday'."
  3217. (interactive "P")
  3218. (if (and (integerp include-all) (> include-all 0))
  3219. (setq span include-all include-all nil))
  3220. (setq start-day (or start-day org-agenda-start-day))
  3221. (if org-agenda-overriding-arguments
  3222. (setq include-all (car org-agenda-overriding-arguments)
  3223. start-day (nth 1 org-agenda-overriding-arguments)
  3224. span (nth 2 org-agenda-overriding-arguments)))
  3225. (if (stringp start-day)
  3226. ;; Convert to an absolute day number
  3227. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3228. (setq org-agenda-last-arguments (list include-all start-day span))
  3229. (org-compile-prefix-format 'agenda)
  3230. (org-set-sorting-strategy 'agenda)
  3231. (let* ((span (org-agenda-ndays-to-span
  3232. (or span org-agenda-ndays org-agenda-span)))
  3233. (today (org-today))
  3234. (sd (or start-day today))
  3235. (ndays (org-agenda-span-to-ndays span sd))
  3236. (org-agenda-start-on-weekday
  3237. (if (eq ndays 7)
  3238. org-agenda-start-on-weekday))
  3239. (thefiles (org-agenda-files nil 'ifmode))
  3240. (files thefiles)
  3241. (start (if (or (null org-agenda-start-on-weekday)
  3242. (< ndays 7))
  3243. sd
  3244. (let* ((nt (calendar-day-of-week
  3245. (calendar-gregorian-from-absolute sd)))
  3246. (n1 org-agenda-start-on-weekday)
  3247. (d (- nt n1)))
  3248. (- sd (+ (if (< d 0) 7 0) d)))))
  3249. (day-numbers (list start))
  3250. (day-cnt 0)
  3251. (inhibit-redisplay (not debug-on-error))
  3252. s e rtn rtnall file date d start-pos end-pos todayp
  3253. clocktable-start clocktable-end filter)
  3254. (setq org-agenda-redo-command
  3255. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3256. (dotimes (n (1- ndays))
  3257. (push (1+ (car day-numbers)) day-numbers))
  3258. (setq day-numbers (nreverse day-numbers))
  3259. (setq clocktable-start (car day-numbers)
  3260. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3261. (org-prepare-agenda "Day/Week")
  3262. (org-set-local 'org-starting-day (car day-numbers))
  3263. (org-set-local 'org-include-all-loc include-all)
  3264. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3265. (unless org-agenda-compact-blocks
  3266. (let* ((d1 (car day-numbers))
  3267. (d2 (org-last day-numbers))
  3268. (w1 (org-days-to-iso-week d1))
  3269. (w2 (org-days-to-iso-week d2)))
  3270. (setq s (point))
  3271. (if org-agenda-overriding-header
  3272. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3273. nil 'face 'org-agenda-structure) "\n")
  3274. (insert (org-agenda-span-name span)
  3275. "-agenda"
  3276. (if (< (- d2 d1) 350)
  3277. (if (= w1 w2)
  3278. (format " (W%02d)" w1)
  3279. (format " (W%02d-W%02d)" w1 w2))
  3280. "")
  3281. ":\n")))
  3282. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3283. 'org-date-line t))
  3284. (org-agenda-mark-header-line s))
  3285. (while (setq d (pop day-numbers))
  3286. (setq date (calendar-gregorian-from-absolute d)
  3287. s (point))
  3288. (if (or (setq todayp (= d today))
  3289. (and (not start-pos) (= d sd)))
  3290. (setq start-pos (point))
  3291. (if (and start-pos (not end-pos))
  3292. (setq end-pos (point))))
  3293. (setq files thefiles
  3294. rtnall nil)
  3295. (while (setq file (pop files))
  3296. (catch 'nextfile
  3297. (org-check-agenda-file file)
  3298. (let ((org-agenda-entry-types org-agenda-entry-types))
  3299. (unless org-agenda-include-deadlines
  3300. (setq org-agenda-entry-types
  3301. (delq :deadline org-agenda-entry-types)))
  3302. (cond
  3303. ((memq org-agenda-show-log '(only clockcheck))
  3304. (setq rtn (org-agenda-get-day-entries
  3305. file date :closed)))
  3306. (org-agenda-show-log
  3307. (setq rtn (apply 'org-agenda-get-day-entries
  3308. file date
  3309. (append '(:closed) org-agenda-entry-types))))
  3310. (t
  3311. (setq rtn (apply 'org-agenda-get-day-entries
  3312. file date
  3313. org-agenda-entry-types)))))
  3314. (setq rtnall (append rtnall rtn))))
  3315. (if org-agenda-include-diary
  3316. (let ((org-agenda-search-headline-for-time t))
  3317. (require 'diary-lib)
  3318. (setq rtn (org-get-entries-from-diary date))
  3319. (setq rtnall (append rtnall rtn))))
  3320. (if (or rtnall org-agenda-show-all-dates)
  3321. (progn
  3322. (setq day-cnt (1+ day-cnt))
  3323. (insert
  3324. (if (stringp org-agenda-format-date)
  3325. (format-time-string org-agenda-format-date
  3326. (org-time-from-absolute date))
  3327. (funcall org-agenda-format-date date))
  3328. "\n")
  3329. (put-text-property s (1- (point)) 'face
  3330. (org-agenda-get-day-face date))
  3331. (put-text-property s (1- (point)) 'org-date-line t)
  3332. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3333. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3334. (when todayp
  3335. (put-text-property s (1- (point)) 'org-today t))
  3336. (if rtnall (insert
  3337. (org-finalize-agenda-entries
  3338. (org-agenda-add-time-grid-maybe
  3339. rtnall ndays todayp))
  3340. "\n"))
  3341. (put-text-property s (1- (point)) 'day d)
  3342. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3343. (when (and org-agenda-clockreport-mode clocktable-start)
  3344. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3345. ;; the above line is to ensure the restricted range!
  3346. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3347. tbl)
  3348. (setq p (org-plist-delete p :block))
  3349. (setq p (plist-put p :tstart clocktable-start))
  3350. (setq p (plist-put p :tend clocktable-end))
  3351. (setq p (plist-put p :scope 'agenda))
  3352. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3353. (setq filter (or org-agenda-filter-while-redo
  3354. (get 'org-agenda-filter :preset-filter))))
  3355. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3356. (if (string-match "[<>=]" x)
  3357. ""
  3358. x))
  3359. filter ""))))
  3360. (setq tbl (apply 'org-get-clocktable p))
  3361. (insert tbl)))
  3362. (goto-char (point-min))
  3363. (or org-agenda-multi (org-fit-agenda-window))
  3364. (unless (and (pos-visible-in-window-p (point-min))
  3365. (pos-visible-in-window-p (point-max)))
  3366. (goto-char (1- (point-max)))
  3367. (recenter -1)
  3368. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3369. (progn
  3370. (goto-char (or start-pos 1))
  3371. (recenter 1))))
  3372. (goto-char (or start-pos 1))
  3373. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3374. (if (eq org-agenda-show-log 'clockcheck)
  3375. (org-agenda-show-clocking-issues))
  3376. (org-finalize-agenda)
  3377. (setq buffer-read-only t)
  3378. (message "")))
  3379. (defun org-agenda-ndays-to-span (n)
  3380. "Return a span symbol for a span of N days, or N if none matches."
  3381. (cond ((symbolp n) n)
  3382. ((= n 1) 'day)
  3383. ((= n 7) 'week)
  3384. (t n)))
  3385. (defun org-agenda-span-to-ndays (span start-day)
  3386. "Return ndays from SPAN starting at START-DAY."
  3387. (cond ((numberp span) span)
  3388. ((eq span 'day) 1)
  3389. ((eq span 'week) 7)
  3390. ((eq span 'month)
  3391. (let ((date (calendar-gregorian-from-absolute start-day)))
  3392. (calendar-last-day-of-month (car date) (caddr date))))
  3393. ((eq span 'year)
  3394. (let ((date (calendar-gregorian-from-absolute start-day)))
  3395. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3396. (defun org-agenda-span-name (span)
  3397. "Return a SPAN name."
  3398. (if (null span)
  3399. ""
  3400. (if (symbolp span)
  3401. (capitalize (symbol-name span))
  3402. (format "%d days" span))))
  3403. ;;; Agenda word search
  3404. (defvar org-agenda-search-history nil)
  3405. (defvar org-todo-only nil)
  3406. (defvar org-search-syntax-table nil
  3407. "Special syntax table for org-mode search.
  3408. In this table, we have single quotes not as word constituents, to
  3409. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3410. (defun org-search-syntax-table ()
  3411. (unless org-search-syntax-table
  3412. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3413. (modify-syntax-entry ?' "." org-search-syntax-table)
  3414. (modify-syntax-entry ?` "." org-search-syntax-table))
  3415. org-search-syntax-table)
  3416. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3417. ;;;###autoload
  3418. (defun org-search-view (&optional todo-only string edit-at)
  3419. "Show all entries that contain a phrase or words or regular expressions.
  3420. With optional prefix argument TODO-ONLY, only consider entries that are
  3421. TODO entries. The argument STRING can be used to pass a default search
  3422. string into this function. If EDIT-AT is non-nil, it means that the
  3423. user should get a chance to edit this string, with cursor at position
  3424. EDIT-AT.
  3425. The search string can be viewed either as a phrase that should be found as
  3426. is, or it can be broken into a number of snippets, each of which must match
  3427. in a Boolean way to select an entry. The default depends on the variable
  3428. `org-agenda-search-view-always-boolean'.
  3429. Even if this is turned off (the default) you can always switch to
  3430. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3431. The default is a direct search of the whole phrase, where each space in
  3432. the search string can expand to an arbitrary amount of whitespace,
  3433. including newlines.
  3434. If using a Boolean search, the search string is split on whitespace and
  3435. each snippet is searched separately, with logical AND to select an entry.
  3436. Words prefixed with a minus must *not* occur in the entry. Words without
  3437. a prefix or prefixed with a plus must occur in the entry. Matching is
  3438. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3439. match whole words, not parts of a word) if
  3440. `org-agenda-search-view-force-full-words' is set (default is nil).
  3441. Boolean search snippets enclosed by curly braces are interpreted as
  3442. regular expressions that must or (when preceded with \"-\") must not
  3443. match in the entry. Snippets enclosed into double quotes will be taken
  3444. as a whole, to include whitespace.
  3445. - If the search string starts with an asterisk, search only in headlines.
  3446. - If (possibly after the leading star) the search string starts with an
  3447. exclamation mark, this also means to look at TODO entries only, an effect
  3448. that can also be achieved with a prefix argument.
  3449. - If (possibly after star and exclamation mark) the search string starts
  3450. with a colon, this will mean that the (non-regexp) snippets of the
  3451. Boolean search must match as full words.
  3452. This command searches the agenda files, and in addition the files listed
  3453. in `org-agenda-text-search-extra-files'."
  3454. (interactive "P")
  3455. (org-compile-prefix-format 'search)
  3456. (org-set-sorting-strategy 'search)
  3457. (org-prepare-agenda "SEARCH")
  3458. (let* ((props (list 'face nil
  3459. 'done-face 'org-agenda-done
  3460. 'org-not-done-regexp org-not-done-regexp
  3461. 'org-todo-regexp org-todo-regexp
  3462. 'org-complex-heading-regexp org-complex-heading-regexp
  3463. 'mouse-face 'highlight
  3464. 'help-echo (format "mouse-2 or RET jump to location")))
  3465. (full-words org-agenda-search-view-force-full-words)
  3466. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3467. regexp rtn rtnall files file pos
  3468. marker category tags c neg re boolean
  3469. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3470. (unless (and (not edit-at)
  3471. (stringp string)
  3472. (string-match "\\S-" string))
  3473. (setq string (read-string
  3474. (if org-agenda-search-view-always-boolean
  3475. "[+-]Word/{Regexp} ...: "
  3476. "Phrase, or [+-]Word/{Regexp} ...: ")
  3477. (cond
  3478. ((integerp edit-at) (cons string edit-at))
  3479. (edit-at string))
  3480. 'org-agenda-search-history)))
  3481. (org-set-local 'org-todo-only todo-only)
  3482. (setq org-agenda-redo-command
  3483. (list 'org-search-view (if todo-only t nil) string
  3484. '(if current-prefix-arg 1 nil)))
  3485. (setq org-agenda-query-string string)
  3486. (if (equal (string-to-char string) ?*)
  3487. (setq hdl-only t
  3488. words (substring string 1))
  3489. (setq words string))
  3490. (when (equal (string-to-char words) ?!)
  3491. (setq todo-only t
  3492. words (substring words 1)))
  3493. (when (equal (string-to-char words) ?:)
  3494. (setq full-words t
  3495. words (substring words 1)))
  3496. (if (or org-agenda-search-view-always-boolean
  3497. (member (string-to-char words) '(?- ?+ ?\{)))
  3498. (setq boolean t))
  3499. (setq words (org-split-string words))
  3500. (let (www w)
  3501. (while (setq w (pop words))
  3502. (while (and (string-match "\\\\\\'" w) words)
  3503. (setq w (concat (substring w 0 -1) " " (pop words))))
  3504. (push w www))
  3505. (setq words (nreverse www) www nil)
  3506. (while (setq w (pop words))
  3507. (when (and (string-match "\\`[-+]?{" w)
  3508. (not (string-match "}\\'" w)))
  3509. (while (and words (not (string-match "}\\'" (car words))))
  3510. (setq w (concat w " " (pop words))))
  3511. (setq w (concat w " " (pop words))))
  3512. (push w www))
  3513. (setq words (nreverse www)))
  3514. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3515. (when boolean
  3516. (let (wds w)
  3517. (while (setq w (pop words))
  3518. (if (or (equal (substring w 0 1) "\"")
  3519. (and (> (length w) 1)
  3520. (member (substring w 0 1) '("+" "-"))
  3521. (equal (substring w 1 2) "\"")))
  3522. (while (and words (not (equal (substring w -1) "\"")))
  3523. (setq w (concat w " " (pop words)))))
  3524. (and (string-match "\\`\\([-+]?\\)\"" w)
  3525. (setq w (replace-match "\\1" nil nil w)))
  3526. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3527. (push w wds))
  3528. (setq words (nreverse wds))))
  3529. (if boolean
  3530. (mapc (lambda (w)
  3531. (setq c (string-to-char w))
  3532. (if (equal c ?-)
  3533. (setq neg t w (substring w 1))
  3534. (if (equal c ?+)
  3535. (setq neg nil w (substring w 1))
  3536. (setq neg nil)))
  3537. (if (string-match "\\`{.*}\\'" w)
  3538. (setq re (substring w 1 -1))
  3539. (if full-words
  3540. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3541. (setq re (regexp-quote (downcase w)))))
  3542. (if neg (push re regexps-) (push re regexps+)))
  3543. words)
  3544. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3545. regexps+))
  3546. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3547. (if (not regexps+)
  3548. (setq regexp org-outline-regexp-bol)
  3549. (setq regexp (pop regexps+))
  3550. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3551. regexp))))
  3552. (setq files (org-agenda-files nil 'ifmode))
  3553. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3554. (pop org-agenda-text-search-extra-files)
  3555. (setq files (org-add-archive-files files)))
  3556. (setq files (append files org-agenda-text-search-extra-files)
  3557. rtnall nil)
  3558. (while (setq file (pop files))
  3559. (setq ee nil)
  3560. (catch 'nextfile
  3561. (org-check-agenda-file file)
  3562. (setq buffer (if (file-exists-p file)
  3563. (org-get-agenda-file-buffer file)
  3564. (error "No such file %s" file)))
  3565. (if (not buffer)
  3566. ;; If file does not exist, make sure an error message is sent
  3567. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3568. file))))
  3569. (with-current-buffer buffer
  3570. (with-syntax-table (org-search-syntax-table)
  3571. (unless (org-mode-p)
  3572. (error "Agenda file %s is not in `org-mode'" file))
  3573. (let ((case-fold-search t))
  3574. (save-excursion
  3575. (save-restriction
  3576. (if org-agenda-restrict
  3577. (narrow-to-region org-agenda-restrict-begin
  3578. org-agenda-restrict-end)
  3579. (widen))
  3580. (goto-char (point-min))
  3581. (unless (or (org-on-heading-p)
  3582. (outline-next-heading))
  3583. (throw 'nextfile t))
  3584. (goto-char (max (point-min) (1- (point))))
  3585. (while (re-search-forward regexp nil t)
  3586. (org-back-to-heading t)
  3587. (skip-chars-forward "* ")
  3588. (setq beg (point-at-bol)
  3589. beg1 (point)
  3590. end (progn (outline-next-heading) (point)))
  3591. (catch :skip
  3592. (goto-char beg)
  3593. (org-agenda-skip)
  3594. (setq str (buffer-substring-no-properties
  3595. (point-at-bol)
  3596. (if hdl-only (point-at-eol) end)))
  3597. (mapc (lambda (wr) (when (string-match wr str)
  3598. (goto-char (1- end))
  3599. (throw :skip t)))
  3600. regexps-)
  3601. (mapc (lambda (wr) (unless (string-match wr str)
  3602. (goto-char (1- end))
  3603. (throw :skip t)))
  3604. (if todo-only
  3605. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3606. regexps+)
  3607. regexps+))
  3608. (goto-char beg)
  3609. (setq marker (org-agenda-new-marker (point))
  3610. category (org-get-category)
  3611. tags (org-get-tags-at (point))
  3612. txt (org-format-agenda-item
  3613. ""
  3614. (buffer-substring-no-properties
  3615. beg1 (point-at-eol))
  3616. category tags))
  3617. (org-add-props txt props
  3618. 'org-marker marker 'org-hd-marker marker
  3619. 'org-todo-regexp org-todo-regexp
  3620. 'org-complex-heading-regexp org-complex-heading-regexp
  3621. 'priority 1000 'org-category category
  3622. 'type "search")
  3623. (push txt ee)
  3624. (goto-char (1- end))))))))))
  3625. (setq rtn (nreverse ee))
  3626. (setq rtnall (append rtnall rtn)))
  3627. (if org-agenda-overriding-header
  3628. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3629. nil 'face 'org-agenda-structure) "\n")
  3630. (insert "Search words: ")
  3631. (add-text-properties (point-min) (1- (point))
  3632. (list 'face 'org-agenda-structure))
  3633. (setq pos (point))
  3634. (insert string "\n")
  3635. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3636. (setq pos (point))
  3637. (unless org-agenda-multi
  3638. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3639. (add-text-properties pos (1- (point))
  3640. (list 'face 'org-agenda-structure))))
  3641. (org-agenda-mark-header-line (point-min))
  3642. (when rtnall
  3643. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3644. (goto-char (point-min))
  3645. (or org-agenda-multi (org-fit-agenda-window))
  3646. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3647. (org-finalize-agenda)
  3648. (setq buffer-read-only t)))
  3649. ;;; Agenda TODO list
  3650. (defvar org-select-this-todo-keyword nil)
  3651. (defvar org-last-arg nil)
  3652. ;;;###autoload
  3653. (defun org-todo-list (arg)
  3654. "Show all (not done) TODO entries from all agenda file in a single list.
  3655. The prefix arg can be used to select a specific TODO keyword and limit
  3656. the list to these. When using \\[universal-argument], you will be prompted
  3657. for a keyword. A numeric prefix directly selects the Nth keyword in
  3658. `org-todo-keywords-1'."
  3659. (interactive "P")
  3660. (org-compile-prefix-format 'todo)
  3661. (org-set-sorting-strategy 'todo)
  3662. (org-prepare-agenda "TODO")
  3663. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3664. (let* ((today (org-today))
  3665. (date (calendar-gregorian-from-absolute today))
  3666. (kwds org-todo-keywords-for-agenda)
  3667. (completion-ignore-case t)
  3668. (org-select-this-todo-keyword
  3669. (if (stringp arg) arg
  3670. (and arg (integerp arg) (> arg 0)
  3671. (nth (1- arg) kwds))))
  3672. rtn rtnall files file pos)
  3673. (when (equal arg '(4))
  3674. (setq org-select-this-todo-keyword
  3675. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3676. (mapcar 'list kwds) nil nil)))
  3677. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3678. (org-set-local 'org-last-arg arg)
  3679. (setq org-agenda-redo-command
  3680. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3681. (setq files (org-agenda-files nil 'ifmode)
  3682. rtnall nil)
  3683. (while (setq file (pop files))
  3684. (catch 'nextfile
  3685. (org-check-agenda-file file)
  3686. (setq rtn (org-agenda-get-day-entries file date :todo))
  3687. (setq rtnall (append rtnall rtn))))
  3688. (if org-agenda-overriding-header
  3689. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3690. nil 'face 'org-agenda-structure) "\n")
  3691. (insert "Global list of TODO items of type: ")
  3692. (add-text-properties (point-min) (1- (point))
  3693. (list 'face 'org-agenda-structure
  3694. 'short-heading
  3695. (concat "ToDo: "
  3696. (or org-select-this-todo-keyword "ALL"))))
  3697. (org-agenda-mark-header-line (point-min))
  3698. (setq pos (point))
  3699. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3700. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3701. (setq pos (point))
  3702. (unless org-agenda-multi
  3703. (insert "Available with `N r': (0)ALL")
  3704. (let ((n 0) s)
  3705. (mapc (lambda (x)
  3706. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3707. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3708. (insert "\n "))
  3709. (insert " " s))
  3710. kwds))
  3711. (insert "\n"))
  3712. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3713. (org-agenda-mark-header-line (point-min))
  3714. (when rtnall
  3715. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3716. (goto-char (point-min))
  3717. (or org-agenda-multi (org-fit-agenda-window))
  3718. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3719. (org-finalize-agenda)
  3720. (setq buffer-read-only t)))
  3721. ;;; Agenda tags match
  3722. ;;;###autoload
  3723. (defun org-tags-view (&optional todo-only match)
  3724. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3725. The prefix arg TODO-ONLY limits the search to TODO entries."
  3726. (interactive "P")
  3727. (org-compile-prefix-format 'tags)
  3728. (org-set-sorting-strategy 'tags)
  3729. (let* ((org-tags-match-list-sublevels
  3730. org-tags-match-list-sublevels)
  3731. (completion-ignore-case t)
  3732. rtn rtnall files file pos matcher
  3733. buffer)
  3734. (when (and (stringp match) (not (string-match "\\S-" match)))
  3735. (setq match nil))
  3736. (setq matcher (org-make-tags-matcher match)
  3737. match (car matcher) matcher (cdr matcher))
  3738. (org-prepare-agenda (concat "TAGS " match))
  3739. (setq org-agenda-query-string match)
  3740. (setq org-agenda-redo-command
  3741. (list 'org-tags-view (list 'quote todo-only)
  3742. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3743. (setq files (org-agenda-files nil 'ifmode)
  3744. rtnall nil)
  3745. (while (setq file (pop files))
  3746. (catch 'nextfile
  3747. (org-check-agenda-file file)
  3748. (setq buffer (if (file-exists-p file)
  3749. (org-get-agenda-file-buffer file)
  3750. (error "No such file %s" file)))
  3751. (if (not buffer)
  3752. ;; If file does not exist, error message to agenda
  3753. (setq rtn (list
  3754. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3755. rtnall (append rtnall rtn))
  3756. (with-current-buffer buffer
  3757. (unless (org-mode-p)
  3758. (error "Agenda file %s is not in `org-mode'" file))
  3759. (save-excursion
  3760. (save-restriction
  3761. (if org-agenda-restrict
  3762. (narrow-to-region org-agenda-restrict-begin
  3763. org-agenda-restrict-end)
  3764. (widen))
  3765. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3766. (setq rtnall (append rtnall rtn))))))))
  3767. (if org-agenda-overriding-header
  3768. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3769. nil 'face 'org-agenda-structure) "\n")
  3770. (insert "Headlines with TAGS match: ")
  3771. (add-text-properties (point-min) (1- (point))
  3772. (list 'face 'org-agenda-structure
  3773. 'short-heading
  3774. (concat "Match: " match)))
  3775. (setq pos (point))
  3776. (insert match "\n")
  3777. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3778. (setq pos (point))
  3779. (unless org-agenda-multi
  3780. (insert "Press `C-u r' to search again with new search string\n"))
  3781. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3782. (org-agenda-mark-header-line (point-min))
  3783. (when rtnall
  3784. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3785. (goto-char (point-min))
  3786. (or org-agenda-multi (org-fit-agenda-window))
  3787. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3788. (org-finalize-agenda)
  3789. (setq buffer-read-only t)))
  3790. ;;; Agenda Finding stuck projects
  3791. (defvar org-agenda-skip-regexp nil
  3792. "Regular expression used in skipping subtrees for the agenda.
  3793. This is basically a temporary global variable that can be set and then
  3794. used by user-defined selections using `org-agenda-skip-function'.")
  3795. (defvar org-agenda-overriding-header nil
  3796. "When set during agenda, todo and tags searches it replaces the header.
  3797. This variable should not be set directly, but custom commands can bind it
  3798. in the options section.")
  3799. (defun org-agenda-skip-entry-when-regexp-matches ()
  3800. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3801. If yes, it returns the end position of this entry, causing agenda commands
  3802. to skip the entry but continuing the search in the subtree. This is a
  3803. function that can be put into `org-agenda-skip-function' for the duration
  3804. of a command."
  3805. (let ((end (save-excursion (org-end-of-subtree t)))
  3806. skip)
  3807. (save-excursion
  3808. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3809. (and skip end)))
  3810. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3811. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3812. If yes, it returns the end position of this tree, causing agenda commands
  3813. to skip this subtree. This is a function that can be put into
  3814. `org-agenda-skip-function' for the duration of a command."
  3815. (let ((end (save-excursion (org-end-of-subtree t)))
  3816. skip)
  3817. (save-excursion
  3818. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3819. (and skip end)))
  3820. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3821. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3822. If yes, it returns the end position of the current entry (NOT the tree),
  3823. causing agenda commands to skip the entry but continuing the search in
  3824. the subtree. This is a function that can be put into
  3825. `org-agenda-skip-function' for the duration of a command. An important
  3826. use of this function is for the stuck project list."
  3827. (let ((end (save-excursion (org-end-of-subtree t)))
  3828. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3829. skip)
  3830. (save-excursion
  3831. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3832. (and skip entry-end)))
  3833. (defun org-agenda-skip-entry-if (&rest conditions)
  3834. "Skip entry if any of CONDITIONS is true.
  3835. See `org-agenda-skip-if' for details."
  3836. (org-agenda-skip-if nil conditions))
  3837. (defun org-agenda-skip-subtree-if (&rest conditions)
  3838. "Skip entry if any of CONDITIONS is true.
  3839. See `org-agenda-skip-if' for details."
  3840. (org-agenda-skip-if t conditions))
  3841. (defun org-agenda-skip-if (subtree conditions)
  3842. "Checks current entity for CONDITIONS.
  3843. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3844. the entry, i.e. the text before the next heading is checked.
  3845. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3846. from different tests. Valid conditions are:
  3847. scheduled Check if there is a scheduled cookie
  3848. notscheduled Check if there is no scheduled cookie
  3849. deadline Check if there is a deadline
  3850. notdeadline Check if there is no deadline
  3851. timestamp Check if there is a timestamp (also deadline or scheduled)
  3852. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3853. regexp Check if regexp matches
  3854. notregexp Check if regexp does not match.
  3855. todo Check if TODO keyword matches
  3856. nottodo Check if TODO keyword does not match
  3857. The regexp is taken from the conditions list, it must come right after
  3858. the `regexp' or `notregexp' element.
  3859. `todo' and `nottodo' accept as an argument a list of todo
  3860. keywords, which may include \"*\" to match any todo keyword.
  3861. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3862. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3863. Instead of a list a keyword class may be given
  3864. (org-agenda-skip-entry-if 'nottodo 'done)
  3865. would skip entries that haven't been marked with any of \"DONE\"
  3866. keywords. Possible classes are: `todo', `done', `any'.
  3867. If any of these conditions is met, this function returns the end point of
  3868. the entity, causing the search to continue from there. This is a function
  3869. that can be put into `org-agenda-skip-function' for the duration of a command."
  3870. (let (beg end m)
  3871. (org-back-to-heading t)
  3872. (setq beg (point)
  3873. end (if subtree
  3874. (progn (org-end-of-subtree t) (point))
  3875. (progn (outline-next-heading) (1- (point)))))
  3876. (goto-char beg)
  3877. (and
  3878. (or
  3879. (and (memq 'scheduled conditions)
  3880. (re-search-forward org-scheduled-time-regexp end t))
  3881. (and (memq 'notscheduled conditions)
  3882. (not (re-search-forward org-scheduled-time-regexp end t)))
  3883. (and (memq 'deadline conditions)
  3884. (re-search-forward org-deadline-time-regexp end t))
  3885. (and (memq 'notdeadline conditions)
  3886. (not (re-search-forward org-deadline-time-regexp end t)))
  3887. (and (memq 'timestamp conditions)
  3888. (re-search-forward org-ts-regexp end t))
  3889. (and (memq 'nottimestamp conditions)
  3890. (not (re-search-forward org-ts-regexp end t)))
  3891. (and (setq m (memq 'regexp conditions))
  3892. (stringp (nth 1 m))
  3893. (re-search-forward (nth 1 m) end t))
  3894. (and (setq m (memq 'notregexp conditions))
  3895. (stringp (nth 1 m))
  3896. (not (re-search-forward (nth 1 m) end t)))
  3897. (and (or
  3898. (setq m (memq 'todo conditions))
  3899. (setq m (memq 'nottodo conditions)))
  3900. (org-agenda-skip-if-todo m end)))
  3901. end)))
  3902. (defun org-agenda-skip-if-todo (args end)
  3903. "Helper function for `org-agenda-skip-if', do not use it directly.
  3904. ARGS is a list with first element either `todo' or `nottodo'.
  3905. The remainder is either a list of TODO keywords, or a state symbol
  3906. `todo' or `done' or `any'."
  3907. (let ((kw (car args))
  3908. (arg (cadr args))
  3909. todo-wds todo-re)
  3910. (setq todo-wds
  3911. (org-uniquify
  3912. (cond
  3913. ((listp arg) ;; list of keywords
  3914. (if (member "*" arg)
  3915. (mapcar 'substring-no-properties org-todo-keywords-1)
  3916. arg))
  3917. ((symbolp arg) ;; keyword class name
  3918. (cond
  3919. ((eq arg 'todo)
  3920. (org-delete-all org-done-keywords
  3921. (mapcar 'substring-no-properties
  3922. org-todo-keywords-1)))
  3923. ((eq arg 'done) org-done-keywords)
  3924. ((eq arg 'any)
  3925. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3926. (setq todo-re
  3927. (concat "^\\*+[ \t]+\\<\\("
  3928. (mapconcat 'identity todo-wds "\\|")
  3929. "\\)\\>"))
  3930. (if (eq kw 'todo)
  3931. (re-search-forward todo-re end t)
  3932. (not (re-search-forward todo-re end t)))))
  3933. ;;;###autoload
  3934. (defun org-agenda-list-stuck-projects (&rest ignore)
  3935. "Create agenda view for projects that are stuck.
  3936. Stuck projects are project that have no next actions. For the definitions
  3937. of what a project is and how to check if it stuck, customize the variable
  3938. `org-stuck-projects'."
  3939. (interactive)
  3940. (let* ((org-agenda-skip-function
  3941. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3942. ;; We could have used org-agenda-skip-if here.
  3943. (org-agenda-overriding-header
  3944. (or org-agenda-overriding-header "List of stuck projects: "))
  3945. (matcher (nth 0 org-stuck-projects))
  3946. (todo (nth 1 org-stuck-projects))
  3947. (todo-wds (if (member "*" todo)
  3948. (progn
  3949. (org-prepare-agenda-buffers (org-agenda-files
  3950. nil 'ifmode))
  3951. (org-delete-all
  3952. org-done-keywords-for-agenda
  3953. (copy-sequence org-todo-keywords-for-agenda)))
  3954. todo))
  3955. (todo-re (concat "^\\*+[ \t]+\\("
  3956. (mapconcat 'identity todo-wds "\\|")
  3957. "\\)\\>"))
  3958. (tags (nth 2 org-stuck-projects))
  3959. (tags-re (if (member "*" tags)
  3960. (org-re (concat org-outline-regexp-bol
  3961. ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3962. (if tags
  3963. (concat org-outline-regexp-bol
  3964. ".*:\\("
  3965. (mapconcat 'identity tags "\\|")
  3966. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3967. (gen-re (nth 3 org-stuck-projects))
  3968. (re-list
  3969. (delq nil
  3970. (list
  3971. (if todo todo-re)
  3972. (if tags tags-re)
  3973. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3974. gen-re)))))
  3975. (setq org-agenda-skip-regexp
  3976. (if re-list
  3977. (mapconcat 'identity re-list "\\|")
  3978. (error "No information how to identify unstuck projects")))
  3979. (org-tags-view nil matcher)
  3980. (with-current-buffer org-agenda-buffer-name
  3981. (setq org-agenda-redo-command
  3982. '(org-agenda-list-stuck-projects
  3983. (or current-prefix-arg org-last-arg))))))
  3984. ;;; Diary integration
  3985. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3986. (defvar list-diary-entries-hook)
  3987. (defvar diary-time-regexp)
  3988. (defun org-get-entries-from-diary (date)
  3989. "Get the (Emacs Calendar) diary entries for DATE."
  3990. (require 'diary-lib)
  3991. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3992. (diary-display-hook '(fancy-diary-display))
  3993. (diary-display-function 'fancy-diary-display)
  3994. (pop-up-frames nil)
  3995. (list-diary-entries-hook
  3996. (cons 'org-diary-default-entry list-diary-entries-hook))
  3997. (diary-file-name-prefix-function nil) ; turn this feature off
  3998. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3999. entries
  4000. (org-disable-agenda-to-diary t))
  4001. (save-excursion
  4002. (save-window-excursion
  4003. (funcall (if (fboundp 'diary-list-entries)
  4004. 'diary-list-entries 'list-diary-entries)
  4005. date 1)))
  4006. (if (not (get-buffer diary-fancy-buffer))
  4007. (setq entries nil)
  4008. (with-current-buffer diary-fancy-buffer
  4009. (setq buffer-read-only nil)
  4010. (if (zerop (buffer-size))
  4011. ;; No entries
  4012. (setq entries nil)
  4013. ;; Omit the date and other unnecessary stuff
  4014. (org-agenda-cleanup-fancy-diary)
  4015. ;; Add prefix to each line and extend the text properties
  4016. (if (zerop (buffer-size))
  4017. (setq entries nil)
  4018. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4019. (setq entries
  4020. (with-temp-buffer
  4021. (insert entries) (goto-char (point-min))
  4022. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4023. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4024. (replace-match (concat "; " (match-string 1)))))
  4025. (buffer-string)))))
  4026. (set-buffer-modified-p nil)
  4027. (kill-buffer diary-fancy-buffer)))
  4028. (when entries
  4029. (setq entries (org-split-string entries "\n"))
  4030. (setq entries
  4031. (mapcar
  4032. (lambda (x)
  4033. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4034. ;; Extend the text properties to the beginning of the line
  4035. (org-add-props x (text-properties-at (1- (length x)) x)
  4036. 'type "diary" 'date date 'face 'org-agenda-diary))
  4037. entries)))))
  4038. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4039. "Hook run when the fancy diary buffer is cleaned up.")
  4040. (defun org-agenda-cleanup-fancy-diary ()
  4041. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4042. This gets rid of the date, the underline under the date, and
  4043. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4044. date. It also removes lines that contain only whitespace."
  4045. (goto-char (point-min))
  4046. (if (looking-at ".*?:[ \t]*")
  4047. (progn
  4048. (replace-match "")
  4049. (re-search-forward "\n=+$" nil t)
  4050. (replace-match "")
  4051. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4052. (re-search-forward "\n=+$" nil t)
  4053. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4054. (goto-char (point-min))
  4055. (while (re-search-forward "^ +\n" nil t)
  4056. (replace-match ""))
  4057. (goto-char (point-min))
  4058. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4059. (replace-match ""))
  4060. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4061. ;; Make sure entries from the diary have the right text properties.
  4062. (eval-after-load "diary-lib"
  4063. '(if (boundp 'diary-modify-entry-list-string-function)
  4064. ;; We can rely on the hook, nothing to do
  4065. nil
  4066. ;; Hook not available, must use advice to make this work
  4067. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4068. "Make the position visible."
  4069. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4070. (stringp string)
  4071. buffer-file-name)
  4072. (setq string (org-modify-diary-entry-string string))))))
  4073. (defun org-modify-diary-entry-string (string)
  4074. "Add text properties to string, allowing org-mode to act on it."
  4075. (org-add-props string nil
  4076. 'mouse-face 'highlight
  4077. 'help-echo (if buffer-file-name
  4078. (format "mouse-2 or RET jump to diary file %s"
  4079. (abbreviate-file-name buffer-file-name))
  4080. "")
  4081. 'org-agenda-diary-link t
  4082. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4083. (defun org-diary-default-entry ()
  4084. "Add a dummy entry to the diary.
  4085. Needed to avoid empty dates which mess up holiday display."
  4086. ;; Catch the error if dealing with the new add-to-diary-alist
  4087. (when org-disable-agenda-to-diary
  4088. (condition-case nil
  4089. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4090. (error
  4091. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4092. (defun org-add-to-diary-list (&rest args)
  4093. (if (fboundp 'diary-add-to-list)
  4094. (apply 'diary-add-to-list args)
  4095. (apply 'add-to-diary-list args)))
  4096. (defvar org-diary-last-run-time nil)
  4097. ;;;###autoload
  4098. (defun org-diary (&rest args)
  4099. "Return diary information from org-files.
  4100. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4101. It accesses org files and extracts information from those files to be
  4102. listed in the diary. The function accepts arguments specifying what
  4103. items should be listed. For a list of arguments allowed here, see the
  4104. variable `org-agenda-entry-types'.
  4105. The call in the diary file should look like this:
  4106. &%%(org-diary) ~/path/to/some/orgfile.org
  4107. Use a separate line for each org file to check. Or, if you omit the file name,
  4108. all files listed in `org-agenda-files' will be checked automatically:
  4109. &%%(org-diary)
  4110. If you don't give any arguments (as in the example above), the default
  4111. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4112. So the example above may also be written as
  4113. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4114. The function expects the lisp variables `entry' and `date' to be provided
  4115. by the caller, because this is how the calendar works. Don't use this
  4116. function from a program - use `org-agenda-get-day-entries' instead."
  4117. (when (> (- (org-float-time)
  4118. org-agenda-last-marker-time)
  4119. 5)
  4120. (org-agenda-reset-markers))
  4121. (org-compile-prefix-format 'agenda)
  4122. (org-set-sorting-strategy 'agenda)
  4123. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4124. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4125. (list entry)
  4126. (org-agenda-files t)))
  4127. (time (org-float-time))
  4128. file rtn results)
  4129. (when (or (not org-diary-last-run-time)
  4130. (> (- time
  4131. org-diary-last-run-time)
  4132. 3))
  4133. (org-prepare-agenda-buffers files))
  4134. (setq org-diary-last-run-time time)
  4135. ;; If this is called during org-agenda, don't return any entries to
  4136. ;; the calendar. Org Agenda will list these entries itself.
  4137. (if org-disable-agenda-to-diary (setq files nil))
  4138. (while (setq file (pop files))
  4139. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4140. (setq results (append results rtn)))
  4141. (if results
  4142. (concat (org-finalize-agenda-entries results) "\n"))))
  4143. ;;; Agenda entry finders
  4144. (defun org-agenda-get-day-entries (file date &rest args)
  4145. "Does the work for `org-diary' and `org-agenda'.
  4146. FILE is the path to a file to be checked for entries. DATE is date like
  4147. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4148. which kind of entries should be extracted. For details about these, see
  4149. the documentation of `org-diary'."
  4150. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4151. (let* ((org-startup-folded nil)
  4152. (org-startup-align-all-tables nil)
  4153. (buffer (if (file-exists-p file)
  4154. (org-get-agenda-file-buffer file)
  4155. (error "No such file %s" file)))
  4156. arg results rtn deadline-results)
  4157. (if (not buffer)
  4158. ;; If file does not exist, make sure an error message ends up in diary
  4159. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4160. (with-current-buffer buffer
  4161. (unless (org-mode-p)
  4162. (error "Agenda file %s is not in `org-mode'" file))
  4163. (let ((case-fold-search nil))
  4164. (save-excursion
  4165. (save-restriction
  4166. (if org-agenda-restrict
  4167. (narrow-to-region org-agenda-restrict-begin
  4168. org-agenda-restrict-end)
  4169. (widen))
  4170. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4171. (while (setq arg (pop args))
  4172. (cond
  4173. ((and (eq arg :todo)
  4174. (equal date (calendar-gregorian-from-absolute
  4175. (org-today))))
  4176. (setq rtn (org-agenda-get-todos))
  4177. (setq results (append results rtn)))
  4178. ((eq arg :timestamp)
  4179. (setq rtn (org-agenda-get-blocks))
  4180. (setq results (append results rtn))
  4181. (setq rtn (org-agenda-get-timestamps))
  4182. (setq results (append results rtn)))
  4183. ((eq arg :sexp)
  4184. (setq rtn (org-agenda-get-sexps))
  4185. (setq results (append results rtn)))
  4186. ((eq arg :scheduled)
  4187. (setq rtn (org-agenda-get-scheduled deadline-results))
  4188. (setq results (append results rtn)))
  4189. ((eq arg :closed)
  4190. (setq rtn (org-agenda-get-progress))
  4191. (setq results (append results rtn)))
  4192. ((eq arg :deadline)
  4193. (setq rtn (org-agenda-get-deadlines))
  4194. (setq deadline-results (copy-sequence rtn))
  4195. (setq results (append results rtn))))))))
  4196. results))))
  4197. (defun org-agenda-get-todos ()
  4198. "Return the TODO information for agenda display."
  4199. (let* ((props (list 'face nil
  4200. 'done-face 'org-agenda-done
  4201. 'org-not-done-regexp org-not-done-regexp
  4202. 'org-todo-regexp org-todo-regexp
  4203. 'org-complex-heading-regexp org-complex-heading-regexp
  4204. 'mouse-face 'highlight
  4205. 'help-echo
  4206. (format "mouse-2 or RET jump to org file %s"
  4207. (abbreviate-file-name buffer-file-name))))
  4208. (regexp (concat "^\\*+[ \t]+\\("
  4209. (if org-select-this-todo-keyword
  4210. (if (equal org-select-this-todo-keyword "*")
  4211. org-todo-regexp
  4212. (concat "\\<\\("
  4213. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4214. "\\)\\>"))
  4215. org-not-done-regexp)
  4216. "[^\n\r]*\\)"))
  4217. marker priority category tags todo-state
  4218. ee txt beg end)
  4219. (goto-char (point-min))
  4220. (while (re-search-forward regexp nil t)
  4221. (catch :skip
  4222. (save-match-data
  4223. (beginning-of-line)
  4224. (org-agenda-skip)
  4225. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4226. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4227. (goto-char (1+ beg))
  4228. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4229. (throw :skip nil)))
  4230. (goto-char (match-beginning 1))
  4231. (setq marker (org-agenda-new-marker (match-beginning 0))
  4232. category (org-get-category)
  4233. txt (match-string 1)
  4234. tags (org-get-tags-at (point))
  4235. txt (org-format-agenda-item "" txt category tags)
  4236. priority (1+ (org-get-priority txt))
  4237. todo-state (org-get-todo-state))
  4238. (org-add-props txt props
  4239. 'org-marker marker 'org-hd-marker marker
  4240. 'priority priority 'org-category category
  4241. 'type "todo" 'todo-state todo-state)
  4242. (push txt ee)
  4243. (if org-agenda-todo-list-sublevels
  4244. (goto-char (match-end 1))
  4245. (org-end-of-subtree 'invisible))))
  4246. (nreverse ee)))
  4247. (defun org-agenda-todo-custom-ignore-p (time n)
  4248. "Check whether timestamp is farther away then n number of days.
  4249. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4250. `org-agenda-todo-ignore-scheduled' or
  4251. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4252. (let ((days (org-days-to-time time)))
  4253. (if (>= n 0)
  4254. (>= days n)
  4255. (<= days n))))
  4256. ;;;###autoload
  4257. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4258. (&optional end)
  4259. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4260. (when (or org-agenda-todo-ignore-with-date
  4261. org-agenda-todo-ignore-scheduled
  4262. org-agenda-todo-ignore-deadlines
  4263. org-agenda-todo-ignore-timestamp)
  4264. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4265. (save-excursion
  4266. (or (and org-agenda-todo-ignore-with-date
  4267. (re-search-forward org-ts-regexp end t))
  4268. (and org-agenda-todo-ignore-scheduled
  4269. (re-search-forward org-scheduled-time-regexp end t)
  4270. (cond
  4271. ((eq org-agenda-todo-ignore-scheduled 'future)
  4272. (> (org-days-to-time (match-string 1)) 0))
  4273. ((eq org-agenda-todo-ignore-scheduled 'past)
  4274. (<= (org-days-to-time (match-string 1)) 0))
  4275. ((numberp org-agenda-todo-ignore-scheduled)
  4276. (org-agenda-todo-custom-ignore-p
  4277. (match-string 1) org-agenda-todo-ignore-scheduled))
  4278. (t)))
  4279. (and org-agenda-todo-ignore-deadlines
  4280. (re-search-forward org-deadline-time-regexp end t)
  4281. (cond
  4282. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4283. ((eq org-agenda-todo-ignore-deadlines 'far)
  4284. (not (org-deadline-close (match-string 1))))
  4285. ((eq org-agenda-todo-ignore-deadlines 'future)
  4286. (> (org-days-to-time (match-string 1)) 0))
  4287. ((eq org-agenda-todo-ignore-deadlines 'past)
  4288. (<= (org-days-to-time (match-string 1)) 0))
  4289. ((numberp org-agenda-todo-ignore-deadlines)
  4290. (org-agenda-todo-custom-ignore-p
  4291. (match-string 1) org-agenda-todo-ignore-deadlines))
  4292. (t (org-deadline-close (match-string 1)))))
  4293. (and org-agenda-todo-ignore-timestamp
  4294. (let ((buffer (current-buffer))
  4295. (regexp
  4296. (concat
  4297. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4298. (start (point)))
  4299. ;; Copy current buffer into a temporary one
  4300. (with-temp-buffer
  4301. (insert-buffer-substring buffer start end)
  4302. (goto-char (point-min))
  4303. ;; Delete SCHEDULED and DEADLINE items
  4304. (while (re-search-forward regexp end t)
  4305. (delete-region (match-beginning 0) (match-end 0)))
  4306. (goto-char (point-min))
  4307. ;; No search for timestamp left
  4308. (when (re-search-forward org-ts-regexp nil t)
  4309. (cond
  4310. ((eq org-agenda-todo-ignore-timestamp 'future)
  4311. (> (org-days-to-time (match-string 1)) 0))
  4312. ((eq org-agenda-todo-ignore-timestamp 'past)
  4313. (<= (org-days-to-time (match-string 1)) 0))
  4314. ((numberp org-agenda-todo-ignore-timestamp)
  4315. (org-agenda-todo-custom-ignore-p
  4316. (match-string 1) org-agenda-todo-ignore-timestamp))
  4317. (t))))))))))
  4318. (defconst org-agenda-no-heading-message
  4319. "No heading for this item in buffer or region.")
  4320. (defun org-agenda-get-timestamps ()
  4321. "Return the date stamp information for agenda display."
  4322. (let* ((props (list 'face nil
  4323. 'org-not-done-regexp org-not-done-regexp
  4324. 'org-todo-regexp org-todo-regexp
  4325. 'org-complex-heading-regexp org-complex-heading-regexp
  4326. 'mouse-face 'highlight
  4327. 'help-echo
  4328. (format "mouse-2 or RET jump to org file %s"
  4329. (abbreviate-file-name buffer-file-name))))
  4330. (d1 (calendar-absolute-from-gregorian date))
  4331. (remove-re
  4332. (concat
  4333. (regexp-quote
  4334. (format-time-string
  4335. "<%Y-%m-%d"
  4336. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4337. ".*?>"))
  4338. (regexp
  4339. (concat
  4340. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4341. (regexp-quote
  4342. (substring
  4343. (format-time-string
  4344. (car org-time-stamp-formats)
  4345. (apply 'encode-time ; DATE bound by calendar
  4346. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4347. 1 11))
  4348. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4349. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4350. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4351. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4352. todo-state end-of-match show-all)
  4353. (goto-char (point-min))
  4354. (while (setq end-of-match (re-search-forward regexp nil t))
  4355. (setq b0 (match-beginning 0)
  4356. b3 (match-beginning 3) e3 (match-end 3)
  4357. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4358. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4359. (member todo-state
  4360. org-agenda-repeating-timestamp-show-all)))
  4361. (catch :skip
  4362. (and (org-at-date-range-p) (throw :skip nil))
  4363. (org-agenda-skip)
  4364. (if (and (match-end 1)
  4365. (not (= d1 (org-time-string-to-absolute
  4366. (match-string 1) d1 nil show-all))))
  4367. (throw :skip nil))
  4368. (if (and e3
  4369. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4370. (throw :skip nil))
  4371. (setq tmp (buffer-substring (max (point-min)
  4372. (- b0 org-ds-keyword-length))
  4373. b0)
  4374. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4375. inactivep (= (char-after b0) ?\[)
  4376. deadlinep (string-match org-deadline-regexp tmp)
  4377. scheduledp (string-match org-scheduled-regexp tmp)
  4378. closedp (and org-agenda-include-inactive-timestamps
  4379. (string-match org-closed-string tmp))
  4380. clockp (and org-agenda-include-inactive-timestamps
  4381. (or (string-match org-clock-string tmp)
  4382. (string-match "]-+\\'" tmp)))
  4383. donep (member todo-state org-done-keywords))
  4384. (if (or scheduledp deadlinep closedp clockp
  4385. (and donep org-agenda-skip-timestamp-if-done))
  4386. (throw :skip t))
  4387. (if (string-match ">" timestr)
  4388. ;; substring should only run to end of time stamp
  4389. (setq timestr (substring timestr 0 (match-end 0))))
  4390. (setq marker (org-agenda-new-marker b0)
  4391. category (org-get-category b0))
  4392. (save-excursion
  4393. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4394. (setq txt org-agenda-no-heading-message)
  4395. (goto-char (match-beginning 0))
  4396. (setq hdmarker (org-agenda-new-marker)
  4397. tags (org-get-tags-at))
  4398. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4399. (setq head (or (match-string 1) ""))
  4400. (setq txt (org-format-agenda-item
  4401. (if inactivep org-agenda-inactive-leader nil)
  4402. head category tags timestr
  4403. remove-re)))
  4404. (setq priority (org-get-priority txt))
  4405. (org-add-props txt props
  4406. 'org-marker marker 'org-hd-marker hdmarker)
  4407. (org-add-props txt nil 'priority priority
  4408. 'org-category category 'date date
  4409. 'todo-state todo-state
  4410. 'type "timestamp")
  4411. (push txt ee))
  4412. (if org-agenda-skip-additional-timestamps-same-entry
  4413. (outline-next-heading)
  4414. (goto-char end-of-match))))
  4415. (nreverse ee)))
  4416. (defun org-agenda-get-sexps ()
  4417. "Return the sexp information for agenda display."
  4418. (require 'diary-lib)
  4419. (let* ((props (list 'mouse-face 'highlight
  4420. 'help-echo
  4421. (format "mouse-2 or RET jump to org file %s"
  4422. (abbreviate-file-name buffer-file-name))))
  4423. (regexp "^&?%%(")
  4424. marker category ee txt tags entry result beg b sexp sexp-entry
  4425. todo-state)
  4426. (goto-char (point-min))
  4427. (while (re-search-forward regexp nil t)
  4428. (catch :skip
  4429. (org-agenda-skip)
  4430. (setq beg (match-beginning 0))
  4431. (goto-char (1- (match-end 0)))
  4432. (setq b (point))
  4433. (forward-sexp 1)
  4434. (setq sexp (buffer-substring b (point)))
  4435. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4436. (org-trim (match-string 1))
  4437. ""))
  4438. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4439. (when result
  4440. (setq marker (org-agenda-new-marker beg)
  4441. category (org-get-category beg)
  4442. todo-state (org-get-todo-state))
  4443. (dolist (r (if (stringp result)
  4444. (list result)
  4445. result)) ;; we expect a list here
  4446. (if (string-match "\\S-" r)
  4447. (setq txt r)
  4448. (setq txt "SEXP entry returned empty string"))
  4449. (setq txt (org-format-agenda-item
  4450. "" txt category tags 'time))
  4451. (org-add-props txt props 'org-marker marker)
  4452. (org-add-props txt nil
  4453. 'org-category category 'date date 'todo-state todo-state
  4454. 'type "sexp")
  4455. (push txt ee)))))
  4456. (nreverse ee)))
  4457. ;; Calendar sanity: define some functions that are independent of
  4458. ;; `calendar-date-style'.
  4459. ;; Normally I would like to use ISO format when calling the diary functions,
  4460. ;; but to make sure we still have Emacs 22 compatibility we bind
  4461. ;; also `european-calendar-style' and use european format
  4462. (defun org-anniversary (year month day &optional mark)
  4463. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4464. (org-no-warnings
  4465. (let ((calendar-date-style 'european) (european-calendar-style t))
  4466. (diary-anniversary day month year mark))))
  4467. (defun org-cyclic (N year month day &optional mark)
  4468. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4469. (org-no-warnings
  4470. (let ((calendar-date-style 'european) (european-calendar-style t))
  4471. (diary-cyclic N day month year mark))))
  4472. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4473. "Like `diary-block', but with fixed (ISO) order of arguments."
  4474. (org-no-warnings
  4475. (let ((calendar-date-style 'european) (european-calendar-style t))
  4476. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4477. (defun org-date (year month day &optional mark)
  4478. "Like `diary-date', but with fixed (ISO) order of arguments."
  4479. (org-no-warnings
  4480. (let ((calendar-date-style 'european) (european-calendar-style t))
  4481. (diary-date day month year mark))))
  4482. (defalias 'org-float 'diary-float)
  4483. ;; Define the` org-class' function
  4484. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4485. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4486. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4487. is any number of ISO weeks in the block period for which the item should
  4488. be skipped."
  4489. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4490. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4491. (d (calendar-absolute-from-gregorian date)))
  4492. (and
  4493. (<= date1 d)
  4494. (<= d date2)
  4495. (= (calendar-day-of-week date) dayname)
  4496. (or (not skip-weeks)
  4497. (progn
  4498. (require 'cal-iso)
  4499. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4500. entry)))
  4501. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4502. "Like `org-class', but honor `calendar-date-style'.
  4503. The order of the first 2 times 3 arguments depends on the variable
  4504. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4505. So for American calendars, give this as MONTH DAY YEAR, for European as
  4506. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4507. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4508. is any number of ISO weeks in the block period for which the item should
  4509. be skipped.
  4510. This function is here only for backward compatibility and it is deprecated,
  4511. please use `org-class' instead."
  4512. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4513. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4514. (org-class
  4515. (nth 2 date1) (car date1) (nth 1 date1)
  4516. (nth 2 date2) (car date2) (nth 1 date2)
  4517. dayname skip-weeks)))
  4518. (defalias 'org-get-closed 'org-agenda-get-progress)
  4519. (defun org-agenda-get-progress ()
  4520. "Return the logged TODO entries for agenda display."
  4521. (let* ((props (list 'mouse-face 'highlight
  4522. 'org-not-done-regexp org-not-done-regexp
  4523. 'org-todo-regexp org-todo-regexp
  4524. 'org-complex-heading-regexp org-complex-heading-regexp
  4525. 'help-echo
  4526. (format "mouse-2 or RET jump to org file %s"
  4527. (abbreviate-file-name buffer-file-name))))
  4528. (items (if (consp org-agenda-show-log)
  4529. org-agenda-show-log
  4530. (if (eq org-agenda-show-log 'clockcheck)
  4531. '(clock)
  4532. org-agenda-log-mode-items)))
  4533. (parts
  4534. (delq nil
  4535. (list
  4536. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4537. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4538. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4539. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4540. (error "`org-agenda-log-mode-items' is empty")))
  4541. (regexp (concat
  4542. "\\(" parts-re "\\)"
  4543. " *\\["
  4544. (regexp-quote
  4545. (substring
  4546. (format-time-string
  4547. (car org-time-stamp-formats)
  4548. (apply 'encode-time ; DATE bound by calendar
  4549. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4550. 1 11))))
  4551. (org-agenda-search-headline-for-time nil)
  4552. marker hdmarker priority category tags closedp statep clockp state
  4553. ee txt extra timestr rest clocked)
  4554. (goto-char (point-min))
  4555. (while (re-search-forward regexp nil t)
  4556. (catch :skip
  4557. (org-agenda-skip)
  4558. (setq marker (org-agenda-new-marker (match-beginning 0))
  4559. closedp (equal (match-string 1) org-closed-string)
  4560. statep (equal (string-to-char (match-string 1)) ?-)
  4561. clockp (not (or closedp statep))
  4562. state (and statep (match-string 2))
  4563. category (org-get-category (match-beginning 0))
  4564. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4565. )
  4566. (when (string-match "\\]" timestr)
  4567. ;; substring should only run to end of time stamp
  4568. (setq rest (substring timestr (match-end 0))
  4569. timestr (substring timestr 0 (match-end 0)))
  4570. (if (and (not closedp) (not statep)
  4571. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4572. (progn (setq timestr (concat (substring timestr 0 -1)
  4573. "-" (match-string 1 rest) "]"))
  4574. (setq clocked (match-string 2 rest)))
  4575. (setq clocked "-")))
  4576. (save-excursion
  4577. (setq extra
  4578. (cond
  4579. ((not org-agenda-log-mode-add-notes) nil)
  4580. (statep
  4581. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4582. (match-string 1)))
  4583. (clockp
  4584. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4585. (match-string 1)))))
  4586. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4587. (setq txt org-agenda-no-heading-message)
  4588. (goto-char (match-beginning 0))
  4589. (setq hdmarker (org-agenda-new-marker)
  4590. tags (org-get-tags-at))
  4591. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4592. (setq txt (match-string 1))
  4593. (when extra
  4594. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4595. (setq txt (concat (substring txt 0 (match-beginning 1))
  4596. " - " extra " " (match-string 2 txt)))
  4597. (setq txt (concat txt " - " extra))))
  4598. (setq txt (org-format-agenda-item
  4599. (cond
  4600. (closedp "Closed: ")
  4601. (statep (concat "State: (" state ")"))
  4602. (t (concat "Clocked: (" clocked ")")))
  4603. txt category tags timestr)))
  4604. (setq priority 100000)
  4605. (org-add-props txt props
  4606. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4607. 'priority priority 'org-category category
  4608. 'type "closed" 'date date
  4609. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4610. (push txt ee))
  4611. (goto-char (point-at-eol))))
  4612. (nreverse ee)))
  4613. (defun org-agenda-show-clocking-issues ()
  4614. "Add overlays, showing issues with clocking.
  4615. See also the user option `org-agenda-clock-consistency-checks'."
  4616. (interactive)
  4617. (let* ((pl org-agenda-clock-consistency-checks)
  4618. (re (concat "^[ \t]*"
  4619. org-clock-string
  4620. "[ \t]+"
  4621. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4622. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4623. (tlstart 0.)
  4624. (tlend 0.)
  4625. (maxtime (org-hh:mm-string-to-minutes
  4626. (or (plist-get pl :max-duration) "24:00")))
  4627. (mintime (org-hh:mm-string-to-minutes
  4628. (or (plist-get pl :min-duration) 0)))
  4629. (maxgap (org-hh:mm-string-to-minutes
  4630. ;; default 30:00 means never complain
  4631. (or (plist-get pl :max-gap) "30:00")))
  4632. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4633. (plist-get pl :gap-ok-around)))
  4634. (def-face (or (plist-get pl :default-face)
  4635. '((:background "DarkRed") (:foreground "white"))))
  4636. issue face m te ts dt ov)
  4637. (goto-char (point-min))
  4638. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4639. (setq issue nil face def-face)
  4640. (catch 'next
  4641. (setq m (org-get-at-bol 'org-marker)
  4642. te nil ts nil)
  4643. (unless (and m (markerp m))
  4644. (setq issue "No valid clock line") (throw 'next t))
  4645. (org-with-point-at m
  4646. (save-excursion
  4647. (goto-char (point-at-bol))
  4648. (unless (looking-at re)
  4649. (error "No valid Clock line")
  4650. (throw 'next t))
  4651. (unless (match-end 3)
  4652. (setq issue "No end time"
  4653. face (or (plist-get pl :no-end-time-face) face))
  4654. (throw 'next t))
  4655. (setq ts (match-string 1)
  4656. te (match-string 3)
  4657. ts (org-float-time
  4658. (apply 'encode-time (org-parse-time-string ts)))
  4659. te (org-float-time
  4660. (apply 'encode-time (org-parse-time-string te)))
  4661. dt (- te ts))))
  4662. (cond
  4663. ((> dt (* 60 maxtime))
  4664. ;; a very long clocking chunk
  4665. (setq issue (format "Clocking interval is very long: %s"
  4666. (org-minutes-to-hh:mm-string
  4667. (floor (/ (float dt) 60.))))
  4668. face (or (plist-get pl :long-face) face)))
  4669. ((< dt (* 60 mintime))
  4670. ;; a very short clocking chunk
  4671. (setq issue (format "Clocking interval is very short: %s"
  4672. (org-minutes-to-hh:mm-string
  4673. (floor (/ (float dt) 60.))))
  4674. face (or (plist-get pl :short-face) face)))
  4675. ((and (> tlend 0) (< ts tlend))
  4676. ;; Two clock entries are overlapping
  4677. (setq issue (format "Clocking overlap: %d minutes"
  4678. (/ (- tlend ts) 60))
  4679. face (or (plist-get pl :overlap-face) face)))
  4680. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4681. ;; There is a gap, lets see if we need to report it
  4682. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4683. (setq issue (format "Clocking gap: %d minutes"
  4684. (/ (- ts tlend) 60))
  4685. face (or (plist-get pl :gap-face) face))))
  4686. (t nil)))
  4687. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4688. (when issue
  4689. ;; OK, there was some issue, add an overlay to show the issue
  4690. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4691. (overlay-put ov 'before-string
  4692. (concat
  4693. (org-add-props
  4694. (format "%-43s" (concat " " issue))
  4695. nil
  4696. 'face face)
  4697. "\n"))
  4698. (overlay-put ov 'evaporate t)))))
  4699. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4700. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4701. (catch 'exit
  4702. (unless ok-list
  4703. ;; there are no OK times for gaps...
  4704. (throw 'exit nil))
  4705. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4706. ;; This is more than 24 hours, so it is OK.
  4707. ;; because we have at least one OK time, that must be in the
  4708. ;; 24 hour interval.
  4709. (throw 'exit t))
  4710. ;; We have a shorter gap.
  4711. ;; Now we have to get the minute of the day when these times are
  4712. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4713. (t2dec (decode-time (seconds-to-time t2)))
  4714. ;; compute the minute on the day
  4715. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4716. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4717. (when (< min2 min1)
  4718. ;; if min2 is smaller than min1, this means it is on the next day.
  4719. ;; Wrap it to after midnight.
  4720. (setq min2 (+ min2 1440)))
  4721. ;; Now check if any of the OK times is in the gap
  4722. (mapc (lambda (x)
  4723. ;; Wrap the time to after midnight if necessary
  4724. (if (< x min1) (setq x (+ x 1440)))
  4725. ;; Check if in interval
  4726. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4727. ok-list)
  4728. ;; Nope, this gap is not OK
  4729. nil)))
  4730. (defun org-agenda-get-deadlines ()
  4731. "Return the deadline information for agenda display."
  4732. (let* ((props (list 'mouse-face 'highlight
  4733. 'org-not-done-regexp org-not-done-regexp
  4734. 'org-todo-regexp org-todo-regexp
  4735. 'org-complex-heading-regexp org-complex-heading-regexp
  4736. 'help-echo
  4737. (format "mouse-2 or RET jump to org file %s"
  4738. (abbreviate-file-name buffer-file-name))))
  4739. (regexp org-deadline-time-regexp)
  4740. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4741. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4742. d2 diff dfrac wdays pos pos1 category tags
  4743. suppress-prewarning
  4744. ee txt head face s todo-state show-all upcomingp donep timestr)
  4745. (goto-char (point-min))
  4746. (while (re-search-forward regexp nil t)
  4747. (setq suppress-prewarning nil)
  4748. (catch :skip
  4749. (org-agenda-skip)
  4750. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4751. (save-match-data
  4752. (string-match org-scheduled-time-regexp
  4753. (buffer-substring (point-at-bol)
  4754. (point-at-eol)))))
  4755. (setq suppress-prewarning
  4756. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4757. org-agenda-skip-deadline-prewarning-if-scheduled
  4758. 0)))
  4759. (setq s (match-string 1)
  4760. txt nil
  4761. pos (1- (match-beginning 1))
  4762. todo-state (save-match-data (org-get-todo-state))
  4763. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4764. (member todo-state
  4765. org-agenda-repeating-timestamp-show-all))
  4766. d2 (org-time-string-to-absolute
  4767. (match-string 1) d1 'past show-all)
  4768. diff (- d2 d1)
  4769. wdays (if suppress-prewarning
  4770. (let ((org-deadline-warning-days suppress-prewarning))
  4771. (org-get-wdays s))
  4772. (org-get-wdays s))
  4773. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4774. upcomingp (and todayp (> diff 0)))
  4775. ;; When to show a deadline in the calendar:
  4776. ;; If the expiration is within wdays warning time.
  4777. ;; Past-due deadlines are only shown on the current date
  4778. (if (and (or (and (<= diff wdays)
  4779. (and todayp (not org-agenda-only-exact-dates)))
  4780. (= diff 0)))
  4781. (save-excursion
  4782. ;; (setq todo-state (org-get-todo-state))
  4783. (setq donep (member todo-state org-done-keywords))
  4784. (if (and donep
  4785. (or org-agenda-skip-deadline-if-done
  4786. (not (= diff 0))))
  4787. (setq txt nil)
  4788. (setq category (org-get-category))
  4789. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4790. (setq txt org-agenda-no-heading-message)
  4791. (goto-char (match-end 0))
  4792. (setq pos1 (match-beginning 0))
  4793. (setq tags (org-get-tags-at pos1))
  4794. (setq head (buffer-substring-no-properties
  4795. (point)
  4796. (progn (skip-chars-forward "^\r\n")
  4797. (point))))
  4798. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4799. (setq timestr
  4800. (concat (substring s (match-beginning 1)) " "))
  4801. (setq timestr 'time))
  4802. (setq txt (org-format-agenda-item
  4803. (if (= diff 0)
  4804. (car org-agenda-deadline-leaders)
  4805. (if (functionp
  4806. (nth 1 org-agenda-deadline-leaders))
  4807. (funcall
  4808. (nth 1 org-agenda-deadline-leaders)
  4809. diff date)
  4810. (format (nth 1 org-agenda-deadline-leaders)
  4811. diff)))
  4812. head category tags
  4813. (if (not (= diff 0)) nil timestr)))))
  4814. (when txt
  4815. (setq face (org-agenda-deadline-face dfrac wdays))
  4816. (org-add-props txt props
  4817. 'org-marker (org-agenda-new-marker pos)
  4818. 'org-hd-marker (org-agenda-new-marker pos1)
  4819. 'priority (+ (- diff)
  4820. (org-get-priority txt))
  4821. 'org-category category
  4822. 'todo-state todo-state
  4823. 'type (if upcomingp "upcoming-deadline" "deadline")
  4824. 'date (if upcomingp date d2)
  4825. 'face (if donep 'org-agenda-done face)
  4826. 'undone-face face 'done-face 'org-agenda-done)
  4827. (push txt ee))))))
  4828. (nreverse ee)))
  4829. (defun org-agenda-deadline-face (fraction &optional wdays)
  4830. "Return the face to displaying a deadline item.
  4831. FRACTION is what fraction of the head-warning time has passed."
  4832. (if (equal wdays 0) (setq fraction 1.))
  4833. (let ((faces org-agenda-deadline-faces) f)
  4834. (catch 'exit
  4835. (while (setq f (pop faces))
  4836. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4837. (defun org-agenda-get-scheduled (&optional deadline-results)
  4838. "Return the scheduled information for agenda display."
  4839. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4840. 'org-todo-regexp org-todo-regexp
  4841. 'org-complex-heading-regexp org-complex-heading-regexp
  4842. 'done-face 'org-agenda-done
  4843. 'mouse-face 'highlight
  4844. 'help-echo
  4845. (format "mouse-2 or RET jump to org file %s"
  4846. (abbreviate-file-name buffer-file-name))))
  4847. (regexp org-scheduled-time-regexp)
  4848. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4849. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4850. mm
  4851. (deadline-position-alist
  4852. (mapcar (lambda (a) (and (setq mm (get-text-property
  4853. 0 'org-hd-marker a))
  4854. (cons (marker-position mm) a)))
  4855. deadline-results))
  4856. d2 diff pos pos1 category tags donep
  4857. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4858. (goto-char (point-min))
  4859. (while (re-search-forward regexp nil t)
  4860. (catch :skip
  4861. (org-agenda-skip)
  4862. (setq s (match-string 1)
  4863. txt nil
  4864. pos (1- (match-beginning 1))
  4865. todo-state (save-match-data (org-get-todo-state))
  4866. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4867. (member todo-state
  4868. org-agenda-repeating-timestamp-show-all))
  4869. d2 (org-time-string-to-absolute
  4870. (match-string 1) d1 'past show-all)
  4871. diff (- d2 d1))
  4872. (setq pastschedp (and todayp (< diff 0)))
  4873. ;; When to show a scheduled item in the calendar:
  4874. ;; If it is on or past the date.
  4875. (when (or (and (< diff 0)
  4876. (< (abs diff) org-scheduled-past-days)
  4877. (and todayp (not org-agenda-only-exact-dates)))
  4878. (= diff 0))
  4879. (save-excursion
  4880. (setq donep (member todo-state org-done-keywords))
  4881. (if (and donep
  4882. (or org-agenda-skip-scheduled-if-done
  4883. (not (= diff 0))
  4884. (and (functionp 'org-is-habit-p)
  4885. (org-is-habit-p))))
  4886. (setq txt nil)
  4887. (setq habitp (and (functionp 'org-is-habit-p)
  4888. (org-is-habit-p)))
  4889. (setq category (org-get-category))
  4890. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4891. (setq txt org-agenda-no-heading-message)
  4892. (goto-char (match-end 0))
  4893. (setq pos1 (match-beginning 0))
  4894. (if habitp
  4895. (if (or (not org-habit-show-habits)
  4896. (and (not todayp)
  4897. org-habit-show-habits-only-for-today))
  4898. (throw :skip nil))
  4899. (if (and
  4900. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4901. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4902. pastschedp))
  4903. (setq mm (assoc pos1 deadline-position-alist)))
  4904. (throw :skip nil)))
  4905. (setq tags (org-get-tags-at))
  4906. (setq head (buffer-substring-no-properties
  4907. (point)
  4908. (progn (skip-chars-forward "^\r\n") (point))))
  4909. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4910. (setq timestr
  4911. (concat (substring s (match-beginning 1)) " "))
  4912. (setq timestr 'time))
  4913. (setq txt (org-format-agenda-item
  4914. (if (= diff 0)
  4915. (car org-agenda-scheduled-leaders)
  4916. (format (nth 1 org-agenda-scheduled-leaders)
  4917. (- 1 diff)))
  4918. head category tags
  4919. (if (not (= diff 0)) nil timestr)
  4920. nil habitp))))
  4921. (when txt
  4922. (setq face
  4923. (cond
  4924. ((and (not habitp) pastschedp)
  4925. 'org-scheduled-previously)
  4926. (todayp 'org-scheduled-today)
  4927. (t 'org-scheduled))
  4928. habitp (and habitp (org-habit-parse-todo)))
  4929. (org-add-props txt props
  4930. 'undone-face face
  4931. 'face (if donep 'org-agenda-done face)
  4932. 'org-marker (org-agenda-new-marker pos)
  4933. 'org-hd-marker (org-agenda-new-marker pos1)
  4934. 'type (if pastschedp "past-scheduled" "scheduled")
  4935. 'date (if pastschedp d2 date)
  4936. 'priority (if habitp
  4937. (org-habit-get-priority habitp)
  4938. (+ 94 (- 5 diff) (org-get-priority txt)))
  4939. 'org-category category
  4940. 'org-habit-p habitp
  4941. 'todo-state todo-state)
  4942. (push txt ee))))))
  4943. (nreverse ee)))
  4944. (defun org-agenda-get-blocks ()
  4945. "Return the date-range information for agenda display."
  4946. (let* ((props (list 'face nil
  4947. 'org-not-done-regexp org-not-done-regexp
  4948. 'org-todo-regexp org-todo-regexp
  4949. 'org-complex-heading-regexp org-complex-heading-regexp
  4950. 'mouse-face 'highlight
  4951. 'help-echo
  4952. (format "mouse-2 or RET jump to org file %s"
  4953. (abbreviate-file-name buffer-file-name))))
  4954. (regexp org-tr-regexp)
  4955. (d0 (calendar-absolute-from-gregorian date))
  4956. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4957. head donep)
  4958. (goto-char (point-min))
  4959. (while (re-search-forward regexp nil t)
  4960. (catch :skip
  4961. (org-agenda-skip)
  4962. (setq pos (point))
  4963. (let ((start-time (match-string 1))
  4964. (end-time (match-string 2)))
  4965. (setq s1 (match-string 1)
  4966. s2 (match-string 2)
  4967. d1 (time-to-days (org-time-string-to-time s1))
  4968. d2 (time-to-days (org-time-string-to-time s2)))
  4969. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4970. ;; Only allow days between the limits, because the normal
  4971. ;; date stamps will catch the limits.
  4972. (save-excursion
  4973. (setq todo-state (org-get-todo-state))
  4974. (setq donep (member todo-state org-done-keywords))
  4975. (if (and donep org-agenda-skip-timestamp-if-done)
  4976. (throw :skip t))
  4977. (setq marker (org-agenda-new-marker (point)))
  4978. (setq category (org-get-category))
  4979. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4980. (setq txt org-agenda-no-heading-message)
  4981. (goto-char (match-beginning 0))
  4982. (setq hdmarker (org-agenda-new-marker (point)))
  4983. (setq tags (org-get-tags-at))
  4984. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4985. (setq head (match-string 1))
  4986. (let ((remove-re
  4987. (if org-agenda-remove-timeranges-from-blocks
  4988. (concat
  4989. "<" (regexp-quote s1) ".*?>"
  4990. "--"
  4991. "<" (regexp-quote s2) ".*?>")
  4992. nil)))
  4993. (setq txt (org-format-agenda-item
  4994. (format
  4995. (nth (if (= d1 d2) 0 1)
  4996. org-agenda-timerange-leaders)
  4997. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4998. head category tags
  4999. (cond ((= d1 d0)
  5000. (concat "<" start-time ">"))
  5001. ((= d2 d0)
  5002. (concat "<" end-time ">"))
  5003. (t nil))
  5004. remove-re))))
  5005. (org-add-props txt props
  5006. 'org-marker marker 'org-hd-marker hdmarker
  5007. 'type "block" 'date date
  5008. 'todo-state todo-state
  5009. 'priority (org-get-priority txt) 'org-category category)
  5010. (push txt ee))))
  5011. (goto-char pos)))
  5012. ;; Sort the entries by expiration date.
  5013. (nreverse ee)))
  5014. ;;; Agenda presentation and sorting
  5015. (defvar org-prefix-has-time nil
  5016. "A flag, set by `org-compile-prefix-format'.
  5017. The flag is set if the currently compiled format contains a `%t'.")
  5018. (defvar org-prefix-has-tag nil
  5019. "A flag, set by `org-compile-prefix-format'.
  5020. The flag is set if the currently compiled format contains a `%T'.")
  5021. (defvar org-prefix-has-effort nil
  5022. "A flag, set by `org-compile-prefix-format'.
  5023. The flag is set if the currently compiled format contains a `%e'.")
  5024. (defvar org-prefix-category-length nil
  5025. "Used by `org-compile-prefix-format' to remember the category field width.")
  5026. (defvar org-prefix-category-max-length nil
  5027. "Used by `org-compile-prefix-format' to remember the category field width.")
  5028. (defun org-agenda-get-category-icon (category)
  5029. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5030. (dolist (entry org-agenda-category-icon-alist)
  5031. (when (org-string-match-p (car entry) category)
  5032. (if (listp (cadr entry))
  5033. (return (cadr entry))
  5034. (return (apply 'create-image (cdr entry)))))))
  5035. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5036. remove-re habitp)
  5037. "Format TXT to be inserted into the agenda buffer.
  5038. In particular, it adds the prefix and corresponding text properties. EXTRA
  5039. must be a string and replaces the `%s' specifier in the prefix format.
  5040. CATEGORY (string, symbol or nil) may be used to overrule the default
  5041. category taken from local variable or file name. It will replace the `%c'
  5042. specifier in the format. DOTIME, when non-nil, indicates that a
  5043. time-of-day should be extracted from TXT for sorting of this entry, and for
  5044. the `%t' specifier in the format. When DOTIME is a string, this string is
  5045. searched for a time before TXT is. TAGS can be the tags of the headline.
  5046. Any match of REMOVE-RE will be removed from TXT."
  5047. (save-match-data
  5048. ;; Diary entries sometimes have extra whitespace at the beginning
  5049. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5050. ;; Fix the tags part in txt
  5051. (setq txt (org-agenda-fix-displayed-tags
  5052. txt tags
  5053. org-agenda-show-inherited-tags
  5054. org-agenda-hide-tags-regexp))
  5055. (let* ((category (or category
  5056. (if (stringp org-category)
  5057. org-category
  5058. (and org-category (symbol-name org-category)))
  5059. (if buffer-file-name
  5060. (file-name-sans-extension
  5061. (file-name-nondirectory buffer-file-name))
  5062. "")))
  5063. (category-icon (org-agenda-get-category-icon category))
  5064. (category-icon (if category-icon
  5065. (propertize " " 'display category-icon)
  5066. ""))
  5067. ;; time, tag, effort are needed for the eval of the prefix format
  5068. (tag (if tags (nth (1- (length tags)) tags) ""))
  5069. time effort neffort
  5070. (ts (if dotime (concat
  5071. (if (stringp dotime) dotime "")
  5072. (and org-agenda-search-headline-for-time txt))))
  5073. (time-of-day (and dotime (org-get-time-of-day ts)))
  5074. stamp plain s0 s1 s2 rtn srp l
  5075. duration thecategory)
  5076. (and (org-mode-p) buffer-file-name
  5077. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5078. (when (and dotime time-of-day)
  5079. ;; Extract starting and ending time and move them to prefix
  5080. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5081. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5082. (setq s0 (match-string 0 ts)
  5083. srp (and stamp (match-end 3))
  5084. s1 (match-string (if plain 1 2) ts)
  5085. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5086. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5087. ;; them, we might want to remove them there to avoid duplication.
  5088. ;; The user can turn this off with a variable.
  5089. (if (and org-prefix-has-time
  5090. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5091. (string-match (concat (regexp-quote s0) " *") txt)
  5092. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5093. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5094. (= (match-beginning 0) 0)
  5095. t))
  5096. (setq txt (replace-match "" nil nil txt))))
  5097. ;; Normalize the time(s) to 24 hour
  5098. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5099. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5100. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5101. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5102. (setq s2
  5103. (org-minutes-to-hh:mm-string
  5104. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5105. ;; Compute the duration
  5106. (when s2
  5107. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5108. (org-hh:mm-string-to-minutes s1)))))
  5109. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5110. txt)
  5111. ;; Tags are in the string
  5112. (if (or (eq org-agenda-remove-tags t)
  5113. (and org-agenda-remove-tags
  5114. org-prefix-has-tag))
  5115. (setq txt (replace-match "" t t txt))
  5116. (setq txt (replace-match
  5117. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5118. (match-string 2 txt))
  5119. t t txt))))
  5120. (when (org-mode-p)
  5121. (setq effort
  5122. (condition-case nil
  5123. (org-get-effort
  5124. (or (get-text-property 0 'org-hd-marker txt)
  5125. (get-text-property 0 'org-marker txt)))
  5126. (error nil)))
  5127. (when effort
  5128. (setq neffort (org-duration-string-to-minutes effort)
  5129. effort (setq effort (concat "[" effort "]" )))))
  5130. (when remove-re
  5131. (while (string-match remove-re txt)
  5132. (setq txt (replace-match "" t t txt))))
  5133. ;; Set org-heading property on `txt' to mark the start of the
  5134. ;; heading.
  5135. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5136. ;; Prepare the variables needed in the eval of the compiled format
  5137. (setq time (cond (s2 (concat
  5138. (org-agenda-time-of-day-to-ampm-maybe s1)
  5139. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5140. (if org-agenda-timegrid-use-ampm " ")))
  5141. (s1 (concat
  5142. (org-agenda-time-of-day-to-ampm-maybe s1)
  5143. (if org-agenda-timegrid-use-ampm
  5144. "........ "
  5145. "......")))
  5146. (t ""))
  5147. extra (or (and (not habitp) extra) "")
  5148. category (if (symbolp category) (symbol-name category) category)
  5149. thecategory (copy-sequence category))
  5150. (if (string-match org-bracket-link-regexp category)
  5151. (progn
  5152. (setq l (if (match-end 3)
  5153. (- (match-end 3) (match-beginning 3))
  5154. (- (match-end 1) (match-beginning 1))))
  5155. (when (< l (or org-prefix-category-length 0))
  5156. (setq category (copy-sequence category))
  5157. (org-add-props category nil
  5158. 'extra-space (make-string
  5159. (- org-prefix-category-length l 1) ?\ ))))
  5160. (if (and org-prefix-category-max-length
  5161. (>= (length category) org-prefix-category-max-length))
  5162. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5163. ;; Evaluate the compiled format
  5164. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5165. ;; And finally add the text properties
  5166. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5167. (org-add-props rtn nil
  5168. 'org-category (if thecategory (downcase thecategory) category)
  5169. 'tags (mapcar 'org-downcase-keep-props tags)
  5170. 'org-highest-priority org-highest-priority
  5171. 'org-lowest-priority org-lowest-priority
  5172. 'time-of-day time-of-day
  5173. 'duration duration
  5174. 'effort effort
  5175. 'effort-minutes neffort
  5176. 'txt txt
  5177. 'time time
  5178. 'extra extra
  5179. 'dotime dotime))))
  5180. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5181. "Remove tags string from TXT, and add a modified list of tags.
  5182. The modified list may contain inherited tags, and tags matched by
  5183. `org-agenda-hide-tags-regexp' will be removed."
  5184. (when (or add-inherited hide-re)
  5185. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5186. (setq txt (substring txt 0 (match-beginning 0))))
  5187. (setq tags
  5188. (delq nil
  5189. (mapcar (lambda (tg)
  5190. (if (or (and hide-re (string-match hide-re tg))
  5191. (and (not add-inherited)
  5192. (get-text-property 0 'inherited tg)))
  5193. nil
  5194. tg))
  5195. tags)))
  5196. (when tags
  5197. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5198. i)
  5199. (setq txt (concat txt " :"
  5200. (mapconcat
  5201. (lambda (x)
  5202. (setq i (get-text-property 0 'inherited x))
  5203. (if (and have-i (not i))
  5204. (progn
  5205. (setq have-i nil)
  5206. (concat ":" x))
  5207. x))
  5208. tags ":")
  5209. (if have-i "::" ":"))))))
  5210. txt)
  5211. (defun org-downcase-keep-props (s)
  5212. (let ((props (text-properties-at 0 s)))
  5213. (setq s (downcase s))
  5214. (add-text-properties 0 (length s) props s)
  5215. s))
  5216. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5217. (defvar org-agenda-sorting-strategy-selected nil)
  5218. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5219. (catch 'exit
  5220. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5221. ((and todayp (member 'today (car org-agenda-time-grid))))
  5222. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5223. ((member 'weekly (car org-agenda-time-grid)))
  5224. (t (throw 'exit list)))
  5225. (let* ((have (delq nil (mapcar
  5226. (lambda (x) (get-text-property 1 'time-of-day x))
  5227. list)))
  5228. (string (nth 1 org-agenda-time-grid))
  5229. (gridtimes (nth 2 org-agenda-time-grid))
  5230. (req (car org-agenda-time-grid))
  5231. (remove (member 'remove-match req))
  5232. new time)
  5233. (if (and (member 'require-timed req) (not have))
  5234. ;; don't show empty grid
  5235. (throw 'exit list))
  5236. (while (setq time (pop gridtimes))
  5237. (unless (and remove (member time have))
  5238. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5239. (push (org-format-agenda-item
  5240. nil string "" nil
  5241. (concat (substring time 0 -2) ":" (substring time -2)))
  5242. new)
  5243. (put-text-property
  5244. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5245. (when (and todayp org-agenda-show-current-time-in-grid)
  5246. (push (org-format-agenda-item
  5247. nil
  5248. org-agenda-current-time-string
  5249. "" nil
  5250. (format-time-string "%H:%M "))
  5251. new)
  5252. (put-text-property
  5253. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5254. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5255. (append new list)
  5256. (append list new)))))
  5257. (defun org-compile-prefix-format (key)
  5258. "Compile the prefix format into a Lisp form that can be evaluated.
  5259. The resulting form is returned and stored in the variable
  5260. `org-prefix-format-compiled'."
  5261. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5262. org-prefix-category-length nil org-prefix-has-effort nil)
  5263. (let ((s (cond
  5264. ((stringp org-agenda-prefix-format)
  5265. org-agenda-prefix-format)
  5266. ((assq key org-agenda-prefix-format)
  5267. (cdr (assq key org-agenda-prefix-format)))
  5268. (t " %-12:c%?-12t% s")))
  5269. (start 0)
  5270. varform vars var e c f opt)
  5271. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5272. s start)
  5273. (setq var (or (cdr (assoc (match-string 4 s)
  5274. '(("c" . category) ("t" . time) ("s" . extra)
  5275. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5276. 'eval)
  5277. c (or (match-string 3 s) "")
  5278. opt (match-beginning 1)
  5279. start (1+ (match-beginning 0)))
  5280. (if (equal var 'time) (setq org-prefix-has-time t))
  5281. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5282. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5283. (setq f (concat "%" (match-string 2 s) "s"))
  5284. (when (equal var 'category)
  5285. (setq org-prefix-category-length
  5286. (floor (abs (string-to-number (match-string 2 s)))))
  5287. (setq org-prefix-category-max-length
  5288. (let ((x (match-string 2 s)))
  5289. (save-match-data
  5290. (if (string-match "\\.[0-9]+" x)
  5291. (string-to-number (substring (match-string 0 x) 1)))))))
  5292. (if (eq var 'eval)
  5293. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5294. (if opt
  5295. (setq varform
  5296. `(if (equal "" ,var)
  5297. ""
  5298. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5299. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5300. (setq s (replace-match "%s" t nil s))
  5301. (push varform vars))
  5302. (setq vars (nreverse vars))
  5303. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5304. (defun org-set-sorting-strategy (key)
  5305. (if (symbolp (car org-agenda-sorting-strategy))
  5306. ;; the old format
  5307. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5308. (setq org-agenda-sorting-strategy-selected
  5309. (or (cdr (assq key org-agenda-sorting-strategy))
  5310. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5311. '(time-up category-keep priority-down)))))
  5312. (defun org-get-time-of-day (s &optional string mod24)
  5313. "Check string S for a time of day.
  5314. If found, return it as a military time number between 0 and 2400.
  5315. If not found, return nil.
  5316. The optional STRING argument forces conversion into a 5 character wide string
  5317. HH:MM."
  5318. (save-match-data
  5319. (when
  5320. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5321. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5322. (let* ((h (string-to-number (match-string 1 s)))
  5323. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5324. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5325. (am-p (equal ampm "am"))
  5326. (h1 (cond ((not ampm) h)
  5327. ((= h 12) (if am-p 0 12))
  5328. (t (+ h (if am-p 0 12)))))
  5329. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5330. (mod h1 24) h1))
  5331. (t0 (+ (* 100 h2) m))
  5332. (t1 (concat (if (>= h1 24) "+" " ")
  5333. (if (and org-agenda-time-leading-zero
  5334. (< t0 1000)) "0" "")
  5335. (if (< t0 100) "0" "")
  5336. (if (< t0 10) "0" "")
  5337. (int-to-string t0))))
  5338. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5339. (defvar org-agenda-before-sorting-filter-function nil
  5340. "Function to be applied to agenda items prior to sorting.
  5341. Prior to sorting also means just before they are inserted into the agenda.
  5342. To aid sorting, you may revisit the original entries and add more text
  5343. properties which will later be used by the sorting functions.
  5344. The function should take a string argument, an agenda line.
  5345. It has access to the text properties in that line, which contain among
  5346. other things, the property `org-hd-marker' that points to the entry
  5347. where the line comes from. Note that not all lines going into the agenda
  5348. have this property, only most.
  5349. The function should return the modified string. It is probably best
  5350. to ONLY change text properties.
  5351. You can also use this function as a filter, by returning nil for lines
  5352. you don't want to have in the agenda at all. For this application, you
  5353. could bind the variable in the options section of a custom command.")
  5354. (defun org-finalize-agenda-entries (list &optional nosort)
  5355. "Sort and concatenate the agenda items."
  5356. (setq list (mapcar 'org-agenda-highlight-todo list))
  5357. (if nosort
  5358. list
  5359. (when org-agenda-before-sorting-filter-function
  5360. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5361. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5362. (defun org-agenda-highlight-todo (x)
  5363. (let ((org-done-keywords org-done-keywords-for-agenda)
  5364. (case-fold-search nil)
  5365. re)
  5366. (if (eq x 'line)
  5367. (save-excursion
  5368. (beginning-of-line 1)
  5369. (setq re (org-get-at-bol 'org-todo-regexp))
  5370. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5371. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5372. (add-text-properties (match-beginning 0) (match-end 1)
  5373. (list 'face (org-get-todo-face 1)))
  5374. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5375. (delete-region (match-beginning 1) (1- (match-end 0)))
  5376. (goto-char (match-beginning 1))
  5377. (insert (format org-agenda-todo-keyword-format s)))))
  5378. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5379. (setq re (get-text-property 0 'org-todo-regexp x))
  5380. (when (and re
  5381. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5382. x (or pl 0)) pl))
  5383. (add-text-properties
  5384. (or (match-end 1) (match-end 0)) (match-end 0)
  5385. (list 'face (org-get-todo-face (match-string 2 x)))
  5386. x)
  5387. (when (match-end 1)
  5388. (setq x (concat (substring x 0 (match-end 1))
  5389. (format org-agenda-todo-keyword-format
  5390. (match-string 2 x))
  5391. (org-add-props " " (text-properties-at 0 x))
  5392. (substring x (match-end 3)))))))
  5393. x)))
  5394. (defsubst org-cmp-priority (a b)
  5395. "Compare the priorities of string A and B."
  5396. (let ((pa (or (get-text-property 1 'priority a) 0))
  5397. (pb (or (get-text-property 1 'priority b) 0)))
  5398. (cond ((> pa pb) +1)
  5399. ((< pa pb) -1)
  5400. (t nil))))
  5401. (defsubst org-cmp-effort (a b)
  5402. "Compare the priorities of string A and B."
  5403. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5404. (ea (or (get-text-property 1 'effort-minutes a) def))
  5405. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5406. (cond ((> ea eb) +1)
  5407. ((< ea eb) -1)
  5408. (t nil))))
  5409. (defsubst org-cmp-category (a b)
  5410. "Compare the string values of categories of strings A and B."
  5411. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5412. (cb (or (get-text-property 1 'org-category b) "")))
  5413. (cond ((string-lessp ca cb) -1)
  5414. ((string-lessp cb ca) +1)
  5415. (t nil))))
  5416. (defsubst org-cmp-todo-state (a b)
  5417. "Compare the todo states of strings A and B."
  5418. (let* ((ma (or (get-text-property 1 'org-marker a)
  5419. (get-text-property 1 'org-hd-marker a)))
  5420. (mb (or (get-text-property 1 'org-marker b)
  5421. (get-text-property 1 'org-hd-marker b)))
  5422. (fa (and ma (marker-buffer ma)))
  5423. (fb (and mb (marker-buffer mb)))
  5424. (todo-kwds
  5425. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5426. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5427. (ta (or (get-text-property 1 'todo-state a) ""))
  5428. (tb (or (get-text-property 1 'todo-state b) ""))
  5429. (la (- (length (member ta todo-kwds))))
  5430. (lb (- (length (member tb todo-kwds))))
  5431. (donepa (member ta org-done-keywords-for-agenda))
  5432. (donepb (member tb org-done-keywords-for-agenda)))
  5433. (cond ((and donepa (not donepb)) -1)
  5434. ((and (not donepa) donepb) +1)
  5435. ((< la lb) -1)
  5436. ((< lb la) +1)
  5437. (t nil))))
  5438. (defsubst org-cmp-alpha (a b)
  5439. "Compare the headlines, alphabetically."
  5440. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5441. (plb (text-property-any 0 (length b) 'org-heading t b))
  5442. (ta (and pla (substring a pla)))
  5443. (tb (and plb (substring b plb))))
  5444. (when pla
  5445. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5446. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5447. (setq ta (substring ta (match-end 0))))
  5448. (setq ta (downcase ta)))
  5449. (when plb
  5450. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5451. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5452. (setq tb (substring tb (match-end 0))))
  5453. (setq tb (downcase tb)))
  5454. (cond ((not ta) +1)
  5455. ((not tb) -1)
  5456. ((string-lessp ta tb) -1)
  5457. ((string-lessp tb ta) +1)
  5458. (t nil))))
  5459. (defsubst org-cmp-tag (a b)
  5460. "Compare the string values of the first tags of A and B."
  5461. (let ((ta (car (last (get-text-property 1 'tags a))))
  5462. (tb (car (last (get-text-property 1 'tags b)))))
  5463. (cond ((not ta) +1)
  5464. ((not tb) -1)
  5465. ((string-lessp ta tb) -1)
  5466. ((string-lessp tb ta) +1)
  5467. (t nil))))
  5468. (defsubst org-cmp-time (a b)
  5469. "Compare the time-of-day values of strings A and B."
  5470. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5471. (ta (or (get-text-property 1 'time-of-day a) def))
  5472. (tb (or (get-text-property 1 'time-of-day b) def)))
  5473. (cond ((< ta tb) -1)
  5474. ((< tb ta) +1)
  5475. (t nil))))
  5476. (defsubst org-cmp-habit-p (a b)
  5477. "Compare the todo states of strings A and B."
  5478. (let ((ha (get-text-property 1 'org-habit-p a))
  5479. (hb (get-text-property 1 'org-habit-p b)))
  5480. (cond ((and ha (not hb)) -1)
  5481. ((and (not ha) hb) +1)
  5482. (t nil))))
  5483. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5484. (defun org-entries-lessp (a b)
  5485. "Predicate for sorting agenda entries."
  5486. ;; The following variables will be used when the form is evaluated.
  5487. ;; So even though the compiler complains, keep them.
  5488. (let* ((ss org-agenda-sorting-strategy-selected)
  5489. (time-up (and (org-em 'time-up 'time-down ss)
  5490. (org-cmp-time a b)))
  5491. (time-down (if time-up (- time-up) nil))
  5492. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5493. (org-cmp-priority a b)))
  5494. (priority-down (if priority-up (- priority-up) nil))
  5495. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5496. (org-cmp-effort a b)))
  5497. (effort-down (if effort-up (- effort-up) nil))
  5498. (category-up (and (or (org-em 'category-up 'category-down ss)
  5499. (memq 'category-keep ss))
  5500. (org-cmp-category a b)))
  5501. (category-down (if category-up (- category-up) nil))
  5502. (category-keep (if category-up +1 nil))
  5503. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5504. (org-cmp-tag a b)))
  5505. (tag-down (if tag-up (- tag-up) nil))
  5506. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5507. (org-cmp-todo-state a b)))
  5508. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5509. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5510. (org-cmp-habit-p a b)))
  5511. (habit-down (if habit-up (- habit-up) nil))
  5512. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5513. (org-cmp-alpha a b)))
  5514. (alpha-down (if alpha-up (- alpha-up) nil))
  5515. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5516. user-defined-up user-defined-down)
  5517. (if (and need-user-cmp org-agenda-cmp-user-defined
  5518. (functionp org-agenda-cmp-user-defined))
  5519. (setq user-defined-up
  5520. (funcall org-agenda-cmp-user-defined a b)
  5521. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5522. (cdr (assoc
  5523. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5524. '((-1 . t) (1 . nil) (nil . nil))))))
  5525. ;;; Agenda restriction lock
  5526. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5527. "Overlay to mark the headline to which agenda commands are restricted.")
  5528. (overlay-put org-agenda-restriction-lock-overlay
  5529. 'face 'org-agenda-restriction-lock)
  5530. (overlay-put org-agenda-restriction-lock-overlay
  5531. 'help-echo "Agendas are currently limited to this subtree.")
  5532. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5533. (defun org-agenda-set-restriction-lock (&optional type)
  5534. "Set restriction lock for agenda, to current subtree or file.
  5535. Restriction will be the file if TYPE is `file', or if type is the
  5536. universal prefix '(4), or if the cursor is before the first headline
  5537. in the file. Otherwise, restriction will be to the current subtree."
  5538. (interactive "P")
  5539. (and (equal type '(4)) (setq type 'file))
  5540. (setq type (cond
  5541. (type type)
  5542. ((org-at-heading-p) 'subtree)
  5543. ((condition-case nil (org-back-to-heading t) (error nil))
  5544. 'subtree)
  5545. (t 'file)))
  5546. (if (eq type 'subtree)
  5547. (progn
  5548. (setq org-agenda-restrict t)
  5549. (setq org-agenda-overriding-restriction 'subtree)
  5550. (put 'org-agenda-files 'org-restrict
  5551. (list (buffer-file-name (buffer-base-buffer))))
  5552. (org-back-to-heading t)
  5553. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5554. (move-marker org-agenda-restrict-begin (point))
  5555. (move-marker org-agenda-restrict-end
  5556. (save-excursion (org-end-of-subtree t)))
  5557. (message "Locking agenda restriction to subtree"))
  5558. (put 'org-agenda-files 'org-restrict
  5559. (list (buffer-file-name (buffer-base-buffer))))
  5560. (setq org-agenda-restrict nil)
  5561. (setq org-agenda-overriding-restriction 'file)
  5562. (move-marker org-agenda-restrict-begin nil)
  5563. (move-marker org-agenda-restrict-end nil)
  5564. (message "Locking agenda restriction to file"))
  5565. (setq current-prefix-arg nil)
  5566. (org-agenda-maybe-redo))
  5567. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5568. "Remove the agenda restriction lock."
  5569. (interactive "P")
  5570. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5571. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5572. (setq org-agenda-overriding-restriction nil)
  5573. (setq org-agenda-restrict nil)
  5574. (put 'org-agenda-files 'org-restrict nil)
  5575. (move-marker org-agenda-restrict-begin nil)
  5576. (move-marker org-agenda-restrict-end nil)
  5577. (setq current-prefix-arg nil)
  5578. (message "Agenda restriction lock removed")
  5579. (or noupdate (org-agenda-maybe-redo)))
  5580. (defun org-agenda-maybe-redo ()
  5581. "If there is any window showing the agenda view, update it."
  5582. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5583. (w0 (selected-window)))
  5584. (when w
  5585. (select-window w)
  5586. (org-agenda-redo)
  5587. (select-window w0)
  5588. (if org-agenda-overriding-restriction
  5589. (message "Agenda view shifted to new %s restriction"
  5590. org-agenda-overriding-restriction)
  5591. (message "Agenda restriction lock removed")))))
  5592. ;;; Agenda commands
  5593. (defun org-agenda-check-type (error &rest types)
  5594. "Check if agenda buffer is of allowed type.
  5595. If ERROR is non-nil, throw an error, otherwise just return nil."
  5596. (if (memq org-agenda-type types)
  5597. t
  5598. (if error
  5599. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5600. nil)))
  5601. (defun org-agenda-quit ()
  5602. "Exit agenda by removing the window or the buffer."
  5603. (interactive)
  5604. (if org-agenda-columns-active
  5605. (org-columns-quit)
  5606. (let ((buf (current-buffer)))
  5607. (if (eq org-agenda-window-setup 'other-frame)
  5608. (progn
  5609. (kill-buffer buf)
  5610. (org-agenda-reset-markers)
  5611. (org-columns-remove-overlays)
  5612. (setq org-agenda-archives-mode nil)
  5613. (delete-frame))
  5614. (and (not (eq org-agenda-window-setup 'current-window))
  5615. (not (one-window-p))
  5616. (delete-window))
  5617. (kill-buffer buf)
  5618. (org-agenda-reset-markers)
  5619. (org-columns-remove-overlays)
  5620. (setq org-agenda-archives-mode nil)))
  5621. ;; Maybe restore the pre-agenda window configuration.
  5622. (and org-agenda-restore-windows-after-quit
  5623. (not (eq org-agenda-window-setup 'other-frame))
  5624. org-pre-agenda-window-conf
  5625. (set-window-configuration org-pre-agenda-window-conf))))
  5626. (defun org-agenda-exit ()
  5627. "Exit agenda by removing the window or the buffer.
  5628. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5629. Org-mode buffers visited directly by the user will not be touched."
  5630. (interactive)
  5631. (org-release-buffers org-agenda-new-buffers)
  5632. (setq org-agenda-new-buffers nil)
  5633. (org-agenda-quit))
  5634. (defun org-agenda-execute (arg)
  5635. "Execute another agenda command, keeping same window.
  5636. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5637. in the agenda."
  5638. (interactive "P")
  5639. (let ((org-agenda-window-setup 'current-window))
  5640. (org-agenda arg)))
  5641. (defun org-agenda-redo ()
  5642. "Rebuild Agenda.
  5643. When this is the global TODO list, a prefix argument will be interpreted."
  5644. (interactive)
  5645. (let* ((org-agenda-keep-modes t)
  5646. (filter org-agenda-filter)
  5647. (preset (get 'org-agenda-filter :preset-filter))
  5648. (org-agenda-filter-while-redo (or filter preset))
  5649. (cols org-agenda-columns-active)
  5650. (line (org-current-line))
  5651. (window-line (- line (org-current-line (window-start))))
  5652. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5653. (put 'org-agenda-filter :preset-filter nil)
  5654. (and cols (org-columns-quit))
  5655. (message "Rebuilding agenda buffer...")
  5656. (org-let lprops '(eval org-agenda-redo-command))
  5657. (setq org-agenda-undo-list nil
  5658. org-agenda-pending-undo-list nil)
  5659. (message "Rebuilding agenda buffer...done")
  5660. (put 'org-agenda-filter :preset-filter preset)
  5661. (and (or filter preset) (org-agenda-filter-apply filter))
  5662. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5663. (org-goto-line line)
  5664. (recenter window-line)))
  5665. (defvar org-global-tags-completion-table nil)
  5666. (defvar org-agenda-filter-form nil)
  5667. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5668. "Keep only those lines in the agenda buffer that have a specific tag.
  5669. The tag is selected with its fast selection letter, as configured.
  5670. With prefix argument STRIP, remove all lines that do have the tag.
  5671. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5672. used to narrow the search - the interactive user can also press `-' or `+'
  5673. to switch to narrowing."
  5674. (interactive "P")
  5675. (let* ((alist org-tag-alist-for-agenda)
  5676. (tag-chars (mapconcat
  5677. (lambda (x) (if (and (not (symbolp (car x)))
  5678. (cdr x))
  5679. (char-to-string (cdr x))
  5680. ""))
  5681. alist ""))
  5682. (efforts (org-split-string
  5683. (or (cdr (assoc (concat org-effort-property "_ALL")
  5684. org-global-properties))
  5685. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5686. "")))
  5687. (effort-op org-agenda-filter-effort-default-operator)
  5688. (effort-prompt "")
  5689. (inhibit-read-only t)
  5690. (current org-agenda-filter)
  5691. maybe-refresh a n tag)
  5692. (unless char
  5693. (message
  5694. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5695. (if narrow "Narrow" "Filter") tag-chars
  5696. (if org-agenda-auto-exclude-function "[RET], " ""))
  5697. (setq char (read-char)))
  5698. (when (member char '(?+ ?-))
  5699. ;; Narrowing down
  5700. (cond ((equal char ?-) (setq strip t narrow t))
  5701. ((equal char ?+) (setq strip nil narrow t)))
  5702. (message
  5703. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5704. (setq char (read-char)))
  5705. (when (member char '(?< ?> ?= ??))
  5706. ;; An effort operator
  5707. (setq effort-op (char-to-string char))
  5708. (setq alist nil) ; to make sure it will be interpreted as effort.
  5709. (unless (equal char ??)
  5710. (loop for i from 0 to 9 do
  5711. (setq effort-prompt
  5712. (concat
  5713. effort-prompt " ["
  5714. (if (= i 9) "0" (int-to-string (1+ i)))
  5715. "]" (nth i efforts))))
  5716. (message "Effort%s: %s " effort-op effort-prompt)
  5717. (setq char (read-char))
  5718. (when (or (< char ?0) (> char ?9))
  5719. (error "Need 1-9,0 to select effort" ))))
  5720. (when (equal char ?\t)
  5721. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5722. (org-set-local 'org-global-tags-completion-table
  5723. (org-global-tags-completion-table)))
  5724. (let ((completion-ignore-case t))
  5725. (setq tag (org-icompleting-read
  5726. "Tag: " org-global-tags-completion-table))))
  5727. (cond
  5728. ((equal char ?\r)
  5729. (org-agenda-filter-by-tag-show-all)
  5730. (when org-agenda-auto-exclude-function
  5731. (setq org-agenda-filter '())
  5732. (dolist (tag (org-agenda-get-represented-tags))
  5733. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5734. (if modifier
  5735. (push modifier org-agenda-filter))))
  5736. (if (not (null org-agenda-filter))
  5737. (org-agenda-filter-apply org-agenda-filter)))
  5738. (setq maybe-refresh t))
  5739. ((equal char ?/)
  5740. (org-agenda-filter-by-tag-show-all)
  5741. (when (get 'org-agenda-filter :preset-filter)
  5742. (org-agenda-filter-apply org-agenda-filter))
  5743. (setq maybe-refresh t))
  5744. ((or (equal char ?\ )
  5745. (setq a (rassoc char alist))
  5746. (and (>= char ?0) (<= char ?9)
  5747. (setq n (if (= char ?0) 9 (- char ?0 1))
  5748. tag (concat effort-op (nth n efforts))
  5749. a (cons tag nil)))
  5750. (and (= char ??)
  5751. (setq tag "?eff")
  5752. a (cons tag nil))
  5753. (and tag (setq a (cons tag nil))))
  5754. (org-agenda-filter-by-tag-show-all)
  5755. (setq tag (car a))
  5756. (setq org-agenda-filter
  5757. (cons (concat (if strip "-" "+") tag)
  5758. (if narrow current nil)))
  5759. (org-agenda-filter-apply org-agenda-filter)
  5760. (setq maybe-refresh t))
  5761. (t (error "Invalid tag selection character %c" char)))
  5762. (when (and maybe-refresh
  5763. (eq org-agenda-clockreport-mode 'with-filter))
  5764. (org-agenda-redo))))
  5765. (defun org-agenda-get-represented-tags ()
  5766. "Get a list of all tags currently represented in the agenda."
  5767. (let (p tags)
  5768. (save-excursion
  5769. (goto-char (point-min))
  5770. (while (setq p (next-single-property-change (point) 'tags))
  5771. (goto-char p)
  5772. (mapc (lambda (x) (add-to-list 'tags x))
  5773. (get-text-property (point) 'tags))))
  5774. tags))
  5775. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5776. "Refine the current filter. See `org-agenda-filter-by-tag."
  5777. (interactive "P")
  5778. (org-agenda-filter-by-tag strip char 'refine))
  5779. (defun org-agenda-filter-make-matcher ()
  5780. "Create the form that tests a line for the agenda filter."
  5781. (let (f f1)
  5782. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5783. org-agenda-filter))
  5784. (if (member x '("-" "+"))
  5785. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5786. (if (string-match "[<=>?]" x)
  5787. (setq f1 (org-agenda-filter-effort-form x))
  5788. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5789. (if (equal (string-to-char x) ?-)
  5790. (setq f1 (list 'not f1))))
  5791. (push f1 f))
  5792. (cons 'and (nreverse f))))
  5793. (defun org-agenda-filter-effort-form (e)
  5794. "Return the form to compare the effort of the current line with what E says.
  5795. E looks like \"+<2:25\"."
  5796. (let (op)
  5797. (setq e (substring e 1))
  5798. (setq op (string-to-char e) e (substring e 1))
  5799. (setq op (cond ((equal op ?<) '<=)
  5800. ((equal op ?>) '>=)
  5801. ((equal op ??) op)
  5802. (t '=)))
  5803. (list 'org-agenda-compare-effort (list 'quote op)
  5804. (org-duration-string-to-minutes e))))
  5805. (defun org-agenda-compare-effort (op value)
  5806. "Compare the effort of the current line with VALUE, using OP.
  5807. If the line does not have an effort defined, return nil."
  5808. (let ((eff (org-get-at-bol 'effort-minutes)))
  5809. (if (equal op ??)
  5810. (not eff)
  5811. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5812. value))))
  5813. (defun org-agenda-filter-apply (filter)
  5814. "Set FILTER as the new agenda filter and apply it."
  5815. (let (tags)
  5816. (setq org-agenda-filter filter
  5817. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5818. (org-agenda-set-mode-name)
  5819. (save-excursion
  5820. (goto-char (point-min))
  5821. (while (not (eobp))
  5822. (if (org-get-at-bol 'org-marker)
  5823. (progn
  5824. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5825. (if (not (eval org-agenda-filter-form))
  5826. (org-agenda-filter-by-tag-hide-line))
  5827. (beginning-of-line 2))
  5828. (beginning-of-line 2))))
  5829. (if (get-char-property (point) 'invisible)
  5830. (org-agenda-previous-line))))
  5831. (defun org-agenda-filter-by-tag-hide-line ()
  5832. (let (ov)
  5833. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5834. (point-at-eol)))
  5835. (overlay-put ov 'invisible t)
  5836. (overlay-put ov 'type 'tags-filter)
  5837. (push ov org-agenda-filter-overlays)))
  5838. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5839. (setq pos (or pos (point)))
  5840. (save-excursion
  5841. (dolist (ov (overlays-at pos))
  5842. (when (and (overlay-get ov 'invisible)
  5843. (eq (overlay-get ov 'type) 'tags-filter))
  5844. (goto-char pos)
  5845. (if (< (overlay-start ov) (point-at-eol))
  5846. (move-overlay ov (point-at-eol)
  5847. (overlay-end ov)))))))
  5848. (defun org-agenda-filter-by-tag-show-all ()
  5849. (mapc 'delete-overlay org-agenda-filter-overlays)
  5850. (setq org-agenda-filter-overlays nil)
  5851. (setq org-agenda-filter nil)
  5852. (setq org-agenda-filter-form nil)
  5853. (org-agenda-set-mode-name))
  5854. (defun org-agenda-manipulate-query-add ()
  5855. "Manipulate the query by adding a search term with positive selection.
  5856. Positive selection means the term must be matched for selection of an entry."
  5857. (interactive)
  5858. (org-agenda-manipulate-query ?\[))
  5859. (defun org-agenda-manipulate-query-subtract ()
  5860. "Manipulate the query by adding a search term with negative selection.
  5861. Negative selection means term must not be matched for selection of an entry."
  5862. (interactive)
  5863. (org-agenda-manipulate-query ?\]))
  5864. (defun org-agenda-manipulate-query-add-re ()
  5865. "Manipulate the query by adding a search regexp with positive selection.
  5866. Positive selection means the regexp must match for selection of an entry."
  5867. (interactive)
  5868. (org-agenda-manipulate-query ?\{))
  5869. (defun org-agenda-manipulate-query-subtract-re ()
  5870. "Manipulate the query by adding a search regexp with negative selection.
  5871. Negative selection means regexp must not match for selection of an entry."
  5872. (interactive)
  5873. (org-agenda-manipulate-query ?\}))
  5874. (defun org-agenda-manipulate-query (char)
  5875. (cond
  5876. ((memq org-agenda-type '(timeline agenda))
  5877. (let ((org-agenda-include-inactive-timestamps t))
  5878. (org-agenda-redo))
  5879. (message "Display now includes inactive timestamps as well"))
  5880. ((eq org-agenda-type 'search)
  5881. (org-add-to-string
  5882. 'org-agenda-query-string
  5883. (if org-agenda-last-search-view-search-was-boolean
  5884. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5885. (?\{ . " +{}") (?\} . " -{}"))))
  5886. " "))
  5887. (setq org-agenda-redo-command
  5888. (list 'org-search-view
  5889. org-todo-only
  5890. org-agenda-query-string
  5891. (+ (length org-agenda-query-string)
  5892. (if (member char '(?\{ ?\})) 0 1))))
  5893. (set-register org-agenda-query-register org-agenda-query-string)
  5894. (org-agenda-redo))
  5895. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5896. org-agenda-type))))
  5897. (defun org-add-to-string (var string)
  5898. (set var (concat (symbol-value var) string)))
  5899. (defun org-agenda-goto-date (date)
  5900. "Jump to DATE in agenda."
  5901. (interactive (list (let ((org-read-date-prefer-future
  5902. (eval org-agenda-jump-prefer-future)))
  5903. (org-read-date))))
  5904. (org-agenda-list nil date))
  5905. (defun org-agenda-goto-today ()
  5906. "Go to today."
  5907. (interactive)
  5908. (org-agenda-check-type t 'timeline 'agenda)
  5909. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5910. (cond
  5911. (tdpos (goto-char tdpos))
  5912. ((eq org-agenda-type 'agenda)
  5913. (let* ((sd (org-agenda-compute-starting-span
  5914. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5915. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5916. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5917. (org-agenda-redo)
  5918. (org-agenda-find-same-or-today-or-agenda)))
  5919. (t (error "Cannot find today")))))
  5920. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5921. (goto-char
  5922. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5923. (text-property-any (point-min) (point-max) 'org-today t)
  5924. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5925. (point-min))))
  5926. (defun org-agenda-later (arg)
  5927. "Go forward in time by thee current span.
  5928. With prefix ARG, go forward that many times the current span."
  5929. (interactive "p")
  5930. (org-agenda-check-type t 'agenda)
  5931. (let* ((span org-agenda-current-span)
  5932. (sd org-starting-day)
  5933. (greg (calendar-gregorian-from-absolute sd))
  5934. (cnt (org-get-at-bol 'org-day-cnt))
  5935. greg2)
  5936. (cond
  5937. ((eq span 'day)
  5938. (setq sd (+ arg sd)))
  5939. ((eq span 'week)
  5940. (setq sd (+ (* 7 arg) sd)))
  5941. ((eq span 'month)
  5942. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5943. sd (calendar-absolute-from-gregorian greg2))
  5944. (setcar greg2 (1+ (car greg2))))
  5945. ((eq span 'year)
  5946. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5947. sd (calendar-absolute-from-gregorian greg2))
  5948. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5949. (t
  5950. (setq sd (+ (* span arg) sd))))
  5951. (let ((org-agenda-overriding-arguments
  5952. (list (car org-agenda-last-arguments) sd span t)))
  5953. (org-agenda-redo)
  5954. (org-agenda-find-same-or-today-or-agenda cnt))))
  5955. (defun org-agenda-earlier (arg)
  5956. "Go backward in time by the current span.
  5957. With prefix ARG, go backward that many times the current span."
  5958. (interactive "p")
  5959. (org-agenda-later (- arg)))
  5960. (defun org-agenda-view-mode-dispatch ()
  5961. "Call one of the view mode commands."
  5962. (interactive)
  5963. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5964. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5965. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5966. [E]ntryText")
  5967. (let ((a (read-char-exclusive)))
  5968. (case a
  5969. (?\ (call-interactively 'org-agenda-reset-view))
  5970. (?d (call-interactively 'org-agenda-day-view))
  5971. (?w (call-interactively 'org-agenda-week-view))
  5972. (?m (call-interactively 'org-agenda-month-view))
  5973. (?y (call-interactively 'org-agenda-year-view))
  5974. (?l (call-interactively 'org-agenda-log-mode))
  5975. (?L (org-agenda-log-mode '(4)))
  5976. (?c (org-agenda-log-mode 'clockcheck))
  5977. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5978. (?a (call-interactively 'org-agenda-archives-mode))
  5979. (?A (org-agenda-archives-mode 'files))
  5980. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5981. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5982. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5983. (?D (call-interactively 'org-agenda-toggle-diary))
  5984. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5985. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5986. (org-agenda-check-type t 'timeline 'agenda)
  5987. (org-agenda-redo))
  5988. (message "Display now includes inactive timestamps as well"))
  5989. (?q (message "Abort"))
  5990. (otherwise (error "Invalid key" )))))
  5991. (defun org-agenda-reset-view ()
  5992. "Switch to default view for agenda."
  5993. (interactive)
  5994. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5995. (defun org-agenda-day-view (&optional day-of-year)
  5996. "Switch to daily view for agenda.
  5997. With argument DAY-OF-YEAR, switch to that day of the year."
  5998. (interactive "P")
  5999. (org-agenda-change-time-span 'day day-of-year))
  6000. (defun org-agenda-week-view (&optional iso-week)
  6001. "Switch to daily view for agenda.
  6002. With argument ISO-WEEK, switch to the corresponding ISO week.
  6003. If ISO-WEEK has more then 2 digits, only the last two encode the
  6004. week. Any digits before this encode a year. So 200712 means
  6005. week 12 of year 2007. Years in the range 1938-2037 can also be
  6006. written as 2-digit years."
  6007. (interactive "P")
  6008. (org-agenda-change-time-span 'week iso-week))
  6009. (defun org-agenda-month-view (&optional month)
  6010. "Switch to monthly view for agenda.
  6011. With argument MONTH, switch to that month."
  6012. (interactive "P")
  6013. (org-agenda-change-time-span 'month month))
  6014. (defun org-agenda-year-view (&optional year)
  6015. "Switch to yearly view for agenda.
  6016. With argument YEAR, switch to that year.
  6017. If MONTH has more then 2 digits, only the last two encode the
  6018. month. Any digits before this encode a year. So 200712 means
  6019. December year 2007. Years in the range 1938-2037 can also be
  6020. written as 2-digit years."
  6021. (interactive "P")
  6022. (when year
  6023. (setq year (org-small-year-to-year year)))
  6024. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6025. (org-agenda-change-time-span 'year year)
  6026. (error "Abort")))
  6027. (defun org-agenda-change-time-span (span &optional n)
  6028. "Change the agenda view to SPAN.
  6029. SPAN may be `day', `week', `month', `year'."
  6030. (org-agenda-check-type t 'agenda)
  6031. (if (and (not n) (equal org-agenda-current-span span))
  6032. (error "Viewing span is already \"%s\"" span))
  6033. (let* ((sd (or (org-get-at-bol 'day)
  6034. org-starting-day))
  6035. (sd (org-agenda-compute-starting-span sd span n))
  6036. (org-agenda-overriding-arguments
  6037. (or org-agenda-overriding-arguments
  6038. (list (car org-agenda-last-arguments) sd span t))))
  6039. (org-agenda-redo)
  6040. (org-agenda-find-same-or-today-or-agenda))
  6041. (org-agenda-set-mode-name)
  6042. (message "Switched to %s view" span))
  6043. (defun org-agenda-compute-starting-span (sd span &optional n)
  6044. "Compute starting date for agenda.
  6045. SPAN may be `day', `week', `month', `year'. The return value
  6046. is a cons cell with the starting date and the number of days,
  6047. so that the date SD will be in that range."
  6048. (let* ((greg (calendar-gregorian-from-absolute sd))
  6049. (dg (nth 1 greg))
  6050. (mg (car greg))
  6051. (yg (nth 2 greg)))
  6052. (cond
  6053. ((eq span 'day)
  6054. (when n
  6055. (setq sd (+ (calendar-absolute-from-gregorian
  6056. (list mg 1 yg))
  6057. n -1))))
  6058. ((eq span 'week)
  6059. (let* ((nt (calendar-day-of-week
  6060. (calendar-gregorian-from-absolute sd)))
  6061. (d (if org-agenda-start-on-weekday
  6062. (- nt org-agenda-start-on-weekday)
  6063. 0))
  6064. y1)
  6065. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6066. (when n
  6067. (require 'cal-iso)
  6068. (when (> n 99)
  6069. (setq y1 (org-small-year-to-year (/ n 100))
  6070. n (mod n 100)))
  6071. (setq sd
  6072. (calendar-absolute-from-iso
  6073. (list n 1
  6074. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6075. ((eq span 'month)
  6076. (let (y1)
  6077. (when (and n (> n 99))
  6078. (setq y1 (org-small-year-to-year (/ n 100))
  6079. n (mod n 100)))
  6080. (setq sd (calendar-absolute-from-gregorian
  6081. (list (or n mg) 1 (or y1 yg))))))
  6082. ((eq span 'year)
  6083. (setq sd (calendar-absolute-from-gregorian
  6084. (list 1 1 (or n yg))))))
  6085. sd))
  6086. (defun org-agenda-next-date-line (&optional arg)
  6087. "Jump to the next line indicating a date in agenda buffer."
  6088. (interactive "p")
  6089. (org-agenda-check-type t 'agenda 'timeline)
  6090. (beginning-of-line 1)
  6091. ;; This does not work if user makes date format that starts with a blank
  6092. (if (looking-at "^\\S-") (forward-char 1))
  6093. (if (not (re-search-forward "^\\S-" nil t arg))
  6094. (progn
  6095. (backward-char 1)
  6096. (error "No next date after this line in this buffer")))
  6097. (goto-char (match-beginning 0)))
  6098. (defun org-agenda-previous-date-line (&optional arg)
  6099. "Jump to the previous line indicating a date in agenda buffer."
  6100. (interactive "p")
  6101. (org-agenda-check-type t 'agenda 'timeline)
  6102. (beginning-of-line 1)
  6103. (if (not (re-search-backward "^\\S-" nil t arg))
  6104. (error "No previous date before this line in this buffer")))
  6105. ;; Initialize the highlight
  6106. (defvar org-hl (make-overlay 1 1))
  6107. (overlay-put org-hl 'face 'highlight)
  6108. (defun org-highlight (begin end &optional buffer)
  6109. "Highlight a region with overlay."
  6110. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6111. (defun org-unhighlight ()
  6112. "Detach overlay INDEX."
  6113. (org-detach-overlay org-hl))
  6114. ;; FIXME this is currently not used.
  6115. (defun org-highlight-until-next-command (beg end &optional buffer)
  6116. "Move the highlight overlay to BEG/END, remove it before the next command."
  6117. (org-highlight beg end buffer)
  6118. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6119. (defun org-unhighlight-once ()
  6120. "Remove the highlight from its position, and this function from the hook."
  6121. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6122. (org-unhighlight))
  6123. (defun org-agenda-follow-mode ()
  6124. "Toggle follow mode in an agenda buffer."
  6125. (interactive)
  6126. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6127. (org-agenda-set-mode-name)
  6128. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6129. (org-agenda-show))
  6130. (message "Follow mode is %s"
  6131. (if org-agenda-follow-mode "on" "off")))
  6132. (defun org-agenda-entry-text-mode (&optional arg)
  6133. "Toggle entry text mode in an agenda buffer."
  6134. (interactive "P")
  6135. (setq org-agenda-entry-text-mode (or (integerp arg)
  6136. (not org-agenda-entry-text-mode)))
  6137. (org-agenda-entry-text-hide)
  6138. (and org-agenda-entry-text-mode
  6139. (let ((org-agenda-entry-text-maxlines
  6140. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6141. (org-agenda-entry-text-show)))
  6142. (org-agenda-set-mode-name)
  6143. (message "Entry text mode is %s. Maximum number of lines is %d"
  6144. (if org-agenda-entry-text-mode "on" "off")
  6145. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6146. (defun org-agenda-clockreport-mode (&optional with-filter)
  6147. "Toggle clocktable mode in an agenda buffer.
  6148. With prefix arg WITH-FILTER, make the clocktable respect the current
  6149. agenda filter."
  6150. (interactive "P")
  6151. (org-agenda-check-type t 'agenda)
  6152. (if with-filter
  6153. (setq org-agenda-clockreport-mode 'with-filter)
  6154. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6155. (org-agenda-set-mode-name)
  6156. (org-agenda-redo)
  6157. (message "Clocktable mode is %s"
  6158. (if org-agenda-clockreport-mode "on" "off")))
  6159. (defun org-agenda-log-mode (&optional special)
  6160. "Toggle log mode in an agenda buffer.
  6161. With argument SPECIAL, show all possible log items, not only the ones
  6162. configured in `org-agenda-log-mode-items'.
  6163. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6164. (interactive "P")
  6165. (org-agenda-check-type t 'agenda 'timeline)
  6166. (setq org-agenda-show-log
  6167. (cond
  6168. ((equal special '(16)) 'only)
  6169. ((eq special 'clockcheck)
  6170. (if (eq org-agenda-show-log 'clockcheck)
  6171. nil 'clockcheck))
  6172. (special '(closed clock state))
  6173. (t (not org-agenda-show-log))))
  6174. (org-agenda-set-mode-name)
  6175. (org-agenda-redo)
  6176. (message "Log mode is %s"
  6177. (if org-agenda-show-log "on" "off")))
  6178. (defun org-agenda-archives-mode (&optional with-files)
  6179. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6180. When called with a prefix argument, include all archive files as well."
  6181. (interactive "P")
  6182. (setq org-agenda-archives-mode
  6183. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6184. (org-agenda-set-mode-name)
  6185. (org-agenda-redo)
  6186. (message
  6187. "%s"
  6188. (cond
  6189. ((eq org-agenda-archives-mode nil)
  6190. "No archives are included")
  6191. ((eq org-agenda-archives-mode 'trees)
  6192. (format "Trees with :%s: tag are included" org-archive-tag))
  6193. ((eq org-agenda-archives-mode t)
  6194. (format "Trees with :%s: tag and all active archive files are included"
  6195. org-archive-tag)))))
  6196. (defun org-agenda-toggle-diary ()
  6197. "Toggle diary inclusion in an agenda buffer."
  6198. (interactive)
  6199. (org-agenda-check-type t 'agenda)
  6200. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6201. (org-agenda-redo)
  6202. (org-agenda-set-mode-name)
  6203. (message "Diary inclusion turned %s"
  6204. (if org-agenda-include-diary "on" "off")))
  6205. (defun org-agenda-toggle-deadlines ()
  6206. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6207. (interactive)
  6208. (org-agenda-check-type t 'agenda)
  6209. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6210. (org-agenda-redo)
  6211. (org-agenda-set-mode-name)
  6212. (message "Deadlines inclusion turned %s"
  6213. (if org-agenda-include-deadlines "on" "off")))
  6214. (defun org-agenda-toggle-time-grid ()
  6215. "Toggle time grid in an agenda buffer."
  6216. (interactive)
  6217. (org-agenda-check-type t 'agenda)
  6218. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6219. (org-agenda-redo)
  6220. (org-agenda-set-mode-name)
  6221. (message "Time-grid turned %s"
  6222. (if org-agenda-use-time-grid "on" "off")))
  6223. (defun org-agenda-set-mode-name ()
  6224. "Set the mode name to indicate all the small mode settings."
  6225. (setq mode-name
  6226. (list "Org-Agenda"
  6227. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6228. " "
  6229. '(:eval (org-agenda-span-name org-agenda-current-span))
  6230. (if org-agenda-follow-mode " Follow" "")
  6231. (if org-agenda-entry-text-mode " ETxt" "")
  6232. (if org-agenda-include-diary " Diary" "")
  6233. (if org-agenda-include-deadlines " Ddl" "")
  6234. (if org-agenda-use-time-grid " Grid" "")
  6235. (if (and (boundp 'org-habit-show-habits)
  6236. org-habit-show-habits) " Habit" "")
  6237. (cond
  6238. ((consp org-agenda-show-log) " LogAll")
  6239. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6240. (org-agenda-show-log " Log")
  6241. (t ""))
  6242. (if (or org-agenda-filter (get 'org-agenda-filter
  6243. :preset-filter))
  6244. (concat " {" (mapconcat
  6245. 'identity
  6246. (append (get 'org-agenda-filter
  6247. :preset-filter)
  6248. org-agenda-filter) "") "}")
  6249. "")
  6250. (if org-agenda-archives-mode
  6251. (if (eq org-agenda-archives-mode t)
  6252. " Archives"
  6253. (format " :%s:" org-archive-tag))
  6254. "")
  6255. (if org-agenda-clockreport-mode
  6256. (if (eq org-agenda-clockreport-mode 'with-filter)
  6257. " Clock{}" " Clock")
  6258. "")))
  6259. (force-mode-line-update))
  6260. (defun org-agenda-post-command-hook ()
  6261. (setq org-agenda-type
  6262. (or (get-text-property (point) 'org-agenda-type)
  6263. (get-text-property (max (point-min) (1- (point)))
  6264. 'org-agenda-type))))
  6265. (defun org-agenda-next-line ()
  6266. "Move cursor to the next line, and show if follow mode is active."
  6267. (interactive)
  6268. (call-interactively 'next-line)
  6269. (org-agenda-do-context-action))
  6270. (defun org-agenda-previous-line ()
  6271. "Move cursor to the previous line, and show if follow-mode is active."
  6272. (interactive)
  6273. (call-interactively 'previous-line)
  6274. (org-agenda-do-context-action))
  6275. (defun org-agenda-do-context-action ()
  6276. "Show outline path and, maybe, follow mode window."
  6277. (let ((m (org-get-at-bol 'org-marker)))
  6278. (if (and org-agenda-follow-mode m)
  6279. (org-agenda-show))
  6280. (if (and m org-agenda-show-outline-path)
  6281. (org-with-point-at m
  6282. (org-display-outline-path t)))))
  6283. (defun org-agenda-show-priority ()
  6284. "Show the priority of the current item.
  6285. This priority is composed of the main priority given with the [#A] cookies,
  6286. and by additional input from the age of a schedules or deadline entry."
  6287. (interactive)
  6288. (let* ((pri (org-get-at-bol 'priority)))
  6289. (message "Priority is %d" (if pri pri -1000))))
  6290. (defun org-agenda-show-tags ()
  6291. "Show the tags applicable to the current item."
  6292. (interactive)
  6293. (let* ((tags (org-get-at-bol 'tags)))
  6294. (if tags
  6295. (message "Tags are :%s:"
  6296. (org-no-properties (mapconcat 'identity tags ":")))
  6297. (message "No tags associated with this line"))))
  6298. (defun org-agenda-goto (&optional highlight)
  6299. "Go to the Org-mode file which contains the item at point."
  6300. (interactive)
  6301. (let* ((marker (or (org-get-at-bol 'org-marker)
  6302. (org-agenda-error)))
  6303. (buffer (marker-buffer marker))
  6304. (pos (marker-position marker)))
  6305. (switch-to-buffer-other-window buffer)
  6306. (widen)
  6307. (push-mark)
  6308. (goto-char pos)
  6309. (when (org-mode-p)
  6310. (org-show-context 'agenda)
  6311. (save-excursion
  6312. (and (outline-next-heading)
  6313. (org-flag-heading nil)))) ; show the next heading
  6314. (when (outline-invisible-p)
  6315. (show-entry)) ; display invisible text
  6316. (recenter (/ (window-height) 2))
  6317. (run-hooks 'org-agenda-after-show-hook)
  6318. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6319. (defvar org-agenda-after-show-hook nil
  6320. "Normal hook run after an item has been shown from the agenda.
  6321. Point is in the buffer where the item originated.")
  6322. (defun org-agenda-kill ()
  6323. "Kill the entry or subtree belonging to the current agenda entry."
  6324. (interactive)
  6325. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6326. (let* ((marker (or (org-get-at-bol 'org-marker)
  6327. (org-agenda-error)))
  6328. (buffer (marker-buffer marker))
  6329. (pos (marker-position marker))
  6330. (type (org-get-at-bol 'type))
  6331. dbeg dend (n 0) conf)
  6332. (org-with-remote-undo buffer
  6333. (with-current-buffer buffer
  6334. (save-excursion
  6335. (goto-char pos)
  6336. (if (and (org-mode-p) (not (member type '("sexp"))))
  6337. (setq dbeg (progn (org-back-to-heading t) (point))
  6338. dend (org-end-of-subtree t t))
  6339. (setq dbeg (point-at-bol)
  6340. dend (min (point-max) (1+ (point-at-eol)))))
  6341. (goto-char dbeg)
  6342. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6343. (setq conf (or (eq t org-agenda-confirm-kill)
  6344. (and (numberp org-agenda-confirm-kill)
  6345. (> n org-agenda-confirm-kill))))
  6346. (and conf
  6347. (not (y-or-n-p
  6348. (format "Delete entry with %d lines in buffer \"%s\"? "
  6349. n (buffer-name buffer))))
  6350. (error "Abort"))
  6351. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6352. (with-current-buffer buffer (delete-region dbeg dend))
  6353. (message "Agenda item and source killed"))))
  6354. (defvar org-archive-default-command)
  6355. (defun org-agenda-archive-default ()
  6356. "Archive the entry or subtree belonging to the current agenda entry."
  6357. (interactive)
  6358. (require 'org-archive)
  6359. (org-agenda-archive-with org-archive-default-command))
  6360. (defun org-agenda-archive-default-with-confirmation ()
  6361. "Archive the entry or subtree belonging to the current agenda entry."
  6362. (interactive)
  6363. (require 'org-archive)
  6364. (org-agenda-archive-with org-archive-default-command 'confirm))
  6365. (defun org-agenda-archive ()
  6366. "Archive the entry or subtree belonging to the current agenda entry."
  6367. (interactive)
  6368. (org-agenda-archive-with 'org-archive-subtree))
  6369. (defun org-agenda-archive-to-archive-sibling ()
  6370. "Move the entry to the archive sibling."
  6371. (interactive)
  6372. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6373. (defun org-agenda-archive-with (cmd &optional confirm)
  6374. "Move the entry to the archive sibling."
  6375. (interactive)
  6376. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6377. (let* ((marker (or (org-get-at-bol 'org-marker)
  6378. (org-agenda-error)))
  6379. (buffer (marker-buffer marker))
  6380. (pos (marker-position marker)))
  6381. (org-with-remote-undo buffer
  6382. (with-current-buffer buffer
  6383. (if (org-mode-p)
  6384. (if (and confirm
  6385. (not (y-or-n-p "Archive this subtree or entry? ")))
  6386. (error "Abort")
  6387. (save-excursion
  6388. (goto-char pos)
  6389. (org-remove-subtree-entries-from-agenda)
  6390. (org-back-to-heading t)
  6391. (funcall cmd)))
  6392. (error "Archiving works only in Org-mode files"))))))
  6393. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6394. "Remove all lines in the agenda that correspond to a given subtree.
  6395. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6396. If this information is not given, the function uses the tree at point."
  6397. (let ((buf (or buf (current-buffer))) m p)
  6398. (save-excursion
  6399. (unless (and beg end)
  6400. (org-back-to-heading t)
  6401. (setq beg (point))
  6402. (org-end-of-subtree t)
  6403. (setq end (point)))
  6404. (set-buffer (get-buffer org-agenda-buffer-name))
  6405. (save-excursion
  6406. (goto-char (point-max))
  6407. (beginning-of-line 1)
  6408. (while (not (bobp))
  6409. (when (and (setq m (org-get-at-bol 'org-marker))
  6410. (equal buf (marker-buffer m))
  6411. (setq p (marker-position m))
  6412. (>= p beg)
  6413. (< p end))
  6414. (let ((inhibit-read-only t))
  6415. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6416. (beginning-of-line 0))))))
  6417. (defun org-agenda-refile (&optional goto rfloc no-update)
  6418. "Refile the item at point."
  6419. (interactive "P")
  6420. (if (equal goto '(16))
  6421. (org-refile-goto-last-stored)
  6422. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6423. (org-agenda-error)))
  6424. (buffer (marker-buffer marker))
  6425. (pos (marker-position marker))
  6426. (rfloc (or rfloc
  6427. (org-refile-get-location
  6428. (if goto "Goto" "Refile to") buffer
  6429. org-refile-allow-creating-parent-nodes))))
  6430. (with-current-buffer buffer
  6431. (save-excursion
  6432. (save-restriction
  6433. (widen)
  6434. (goto-char marker)
  6435. (org-remove-subtree-entries-from-agenda)
  6436. (org-refile goto buffer rfloc)))))
  6437. (unless no-update (org-agenda-redo))))
  6438. (defun org-agenda-open-link (&optional arg)
  6439. "Follow the link in the current line, if any.
  6440. This looks for a link in the displayed line in the agenda. It also looks
  6441. at the text of the entry itself."
  6442. (interactive "P")
  6443. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6444. (org-get-at-bol 'org-marker)))
  6445. (buffer (and marker (marker-buffer marker)))
  6446. (prefix (buffer-substring
  6447. (point-at-bol) (point-at-eol))))
  6448. (cond
  6449. (buffer
  6450. (with-current-buffer buffer
  6451. (save-excursion
  6452. (save-restriction
  6453. (widen)
  6454. (goto-char marker)
  6455. (org-offer-links-in-entry arg prefix)))))
  6456. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6457. (save-excursion
  6458. (beginning-of-line 1)
  6459. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6460. (org-open-link-from-string (match-string 1)))
  6461. (t (error "No link to open here")))))
  6462. (defun org-agenda-copy-local-variable (var)
  6463. "Get a variable from a referenced buffer and install it here."
  6464. (let ((m (org-get-at-bol 'org-marker)))
  6465. (when (and m (buffer-live-p (marker-buffer m)))
  6466. (org-set-local var (with-current-buffer (marker-buffer m)
  6467. (symbol-value var))))))
  6468. (defun org-agenda-switch-to (&optional delete-other-windows)
  6469. "Go to the Org-mode file which contains the item at point."
  6470. (interactive)
  6471. (if (and org-return-follows-link
  6472. (not (org-get-at-bol 'org-marker))
  6473. (org-in-regexp org-bracket-link-regexp))
  6474. (org-open-link-from-string (match-string 0))
  6475. (let* ((marker (or (org-get-at-bol 'org-marker)
  6476. (org-agenda-error)))
  6477. (buffer (marker-buffer marker))
  6478. (pos (marker-position marker)))
  6479. (switch-to-buffer buffer)
  6480. (and delete-other-windows (delete-other-windows))
  6481. (widen)
  6482. (goto-char pos)
  6483. (when (org-mode-p)
  6484. (org-show-context 'agenda)
  6485. (save-excursion
  6486. (and (outline-next-heading)
  6487. (org-flag-heading nil))) ; show the next heading
  6488. (when (outline-invisible-p)
  6489. (show-entry)))))) ; display invisible text
  6490. (defun org-agenda-goto-mouse (ev)
  6491. "Go to the Org-mode file which contains the item at the mouse click."
  6492. (interactive "e")
  6493. (mouse-set-point ev)
  6494. (org-agenda-goto))
  6495. (defun org-agenda-show (&optional full-entry)
  6496. "Display the Org-mode file which contains the item at point.
  6497. With prefix argument FULL-ENTRY, make the entire entry visible
  6498. if it was hidden in the outline."
  6499. (interactive "P")
  6500. (let ((win (selected-window)))
  6501. (if full-entry
  6502. (let ((org-show-entry-below t))
  6503. (org-agenda-goto t))
  6504. (org-agenda-goto t))
  6505. (select-window win)))
  6506. (defvar org-agenda-show-window nil)
  6507. (defun org-agenda-show-and-scroll-up ()
  6508. "Display the Org-mode file which contains the item at point.
  6509. When called repeatedly, scroll the window that is displaying the buffer."
  6510. (interactive)
  6511. (let ((win (selected-window)))
  6512. (if (and (window-live-p org-agenda-show-window)
  6513. (eq this-command last-command))
  6514. (progn
  6515. (select-window org-agenda-show-window)
  6516. (ignore-errors (scroll-up)))
  6517. (org-agenda-goto t)
  6518. (show-subtree)
  6519. (setq org-agenda-show-window (selected-window)))
  6520. (select-window win)))
  6521. (defun org-agenda-show-scroll-down ()
  6522. "Scroll down the window showing the agenda."
  6523. (interactive)
  6524. (let ((win (selected-window)))
  6525. (when (window-live-p org-agenda-show-window)
  6526. (select-window org-agenda-show-window)
  6527. (ignore-errors (scroll-down))
  6528. (select-window win))))
  6529. (defun org-agenda-show-1 (&optional more)
  6530. "Display the Org-mode file which contains the item at point.
  6531. The prefix arg selects the amount of information to display:
  6532. 0 hide the subtree
  6533. 1 just show the entry according to defaults.
  6534. 2 show the children view
  6535. 3 show the subtree view
  6536. 4 show the entire subtree and any LOGBOOK drawers
  6537. 5 show the entire subtree and any drawers
  6538. With prefix argument FULL-ENTRY, make the entire entry visible
  6539. if it was hidden in the outline."
  6540. (interactive "p")
  6541. (let ((win (selected-window)))
  6542. (org-agenda-goto t)
  6543. (org-recenter-heading 1)
  6544. (cond
  6545. ((= more 0)
  6546. (hide-subtree)
  6547. (save-excursion
  6548. (org-back-to-heading)
  6549. (run-hook-with-args 'org-cycle-hook 'folded))
  6550. (message "Remote: FOLDED"))
  6551. ((and (org-called-interactively-p 'any) (= more 1))
  6552. (message "Remote: show with default settings"))
  6553. ((= more 2)
  6554. (show-entry)
  6555. (show-children)
  6556. (save-excursion
  6557. (org-back-to-heading)
  6558. (run-hook-with-args 'org-cycle-hook 'children))
  6559. (message "Remote: CHILDREN"))
  6560. ((= more 3)
  6561. (show-subtree)
  6562. (save-excursion
  6563. (org-back-to-heading)
  6564. (run-hook-with-args 'org-cycle-hook 'subtree))
  6565. (message "Remote: SUBTREE"))
  6566. ((= more 4)
  6567. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6568. (org-drawer-regexp
  6569. (concat "^[ \t]*:\\("
  6570. (mapconcat 'regexp-quote org-drawers "\\|")
  6571. "\\):[ \t]*$")))
  6572. (show-subtree)
  6573. (save-excursion
  6574. (org-back-to-heading)
  6575. (org-cycle-hide-drawers 'subtree)))
  6576. (message "Remote: SUBTREE AND LOGBOOK"))
  6577. ((> more 4)
  6578. (show-subtree)
  6579. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6580. (select-window win)))
  6581. (defun org-recenter-heading (n)
  6582. (save-excursion
  6583. (org-back-to-heading)
  6584. (recenter n)))
  6585. (defvar org-agenda-cycle-counter nil)
  6586. (defun org-agenda-cycle-show (&optional n)
  6587. "Show the current entry in another window, with default settings.
  6588. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6589. When use repeatedly in immediate succession, the remote entry will cycle
  6590. through visibility
  6591. children -> subtree -> folded
  6592. When called with a numeric prefix arg, that arg will be passed through to
  6593. `org-agenda-show-1'. For the interpretation of that argument, see the
  6594. docstring of `org-agenda-show-1'."
  6595. (interactive "P")
  6596. (if (integerp n)
  6597. (setq org-agenda-cycle-counter n)
  6598. (if (not (eq last-command this-command))
  6599. (setq org-agenda-cycle-counter 1)
  6600. (if (equal org-agenda-cycle-counter 0)
  6601. (setq org-agenda-cycle-counter 2)
  6602. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6603. (if (> org-agenda-cycle-counter 3)
  6604. (setq org-agenda-cycle-counter 0)))))
  6605. (org-agenda-show-1 org-agenda-cycle-counter))
  6606. (defun org-agenda-recenter (arg)
  6607. "Display the Org-mode file which contains the item at point and recenter."
  6608. (interactive "P")
  6609. (let ((win (selected-window)))
  6610. (org-agenda-goto t)
  6611. (recenter arg)
  6612. (select-window win)))
  6613. (defun org-agenda-show-mouse (ev)
  6614. "Display the Org-mode file which contains the item at the mouse click."
  6615. (interactive "e")
  6616. (mouse-set-point ev)
  6617. (org-agenda-show))
  6618. (defun org-agenda-check-no-diary ()
  6619. "Check if the entry is a diary link and abort if yes."
  6620. (if (org-get-at-bol 'org-agenda-diary-link)
  6621. (org-agenda-error)))
  6622. (defun org-agenda-error ()
  6623. (error "Command not allowed in this line"))
  6624. (defun org-agenda-tree-to-indirect-buffer ()
  6625. "Show the subtree corresponding to the current entry in an indirect buffer.
  6626. This calls the command `org-tree-to-indirect-buffer' from the original
  6627. Org-mode buffer.
  6628. With numerical prefix arg ARG, go up to this level and then take that tree.
  6629. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6630. use the dedicated frame)."
  6631. (interactive)
  6632. (org-agenda-check-no-diary)
  6633. (let* ((marker (or (org-get-at-bol 'org-marker)
  6634. (org-agenda-error)))
  6635. (buffer (marker-buffer marker))
  6636. (pos (marker-position marker)))
  6637. (with-current-buffer buffer
  6638. (save-excursion
  6639. (goto-char pos)
  6640. (call-interactively 'org-tree-to-indirect-buffer)))))
  6641. (defvar org-last-heading-marker (make-marker)
  6642. "Marker pointing to the headline that last changed its TODO state
  6643. by a remote command from the agenda.")
  6644. (defun org-agenda-todo-nextset ()
  6645. "Switch TODO entry to next sequence."
  6646. (interactive)
  6647. (org-agenda-todo 'nextset))
  6648. (defun org-agenda-todo-previousset ()
  6649. "Switch TODO entry to previous sequence."
  6650. (interactive)
  6651. (org-agenda-todo 'previousset))
  6652. (defun org-agenda-todo (&optional arg)
  6653. "Cycle TODO state of line at point, also in Org-mode file.
  6654. This changes the line at point, all other lines in the agenda referring to
  6655. the same tree node, and the headline of the tree node in the Org-mode file."
  6656. (interactive "P")
  6657. (org-agenda-check-no-diary)
  6658. (let* ((col (current-column))
  6659. (marker (or (org-get-at-bol 'org-marker)
  6660. (org-agenda-error)))
  6661. (buffer (marker-buffer marker))
  6662. (pos (marker-position marker))
  6663. (hdmarker (org-get-at-bol 'org-hd-marker))
  6664. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6665. (inhibit-read-only t)
  6666. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6667. (org-with-remote-undo buffer
  6668. (with-current-buffer buffer
  6669. (widen)
  6670. (goto-char pos)
  6671. (org-show-context 'agenda)
  6672. (save-excursion
  6673. (and (outline-next-heading)
  6674. (org-flag-heading nil))) ; show the next heading
  6675. (let ((current-prefix-arg arg))
  6676. (call-interactively 'org-todo))
  6677. (and (bolp) (forward-char 1))
  6678. (setq newhead (org-get-heading))
  6679. (when (and (org-bound-and-true-p
  6680. org-agenda-headline-snapshot-before-repeat)
  6681. (not (equal org-agenda-headline-snapshot-before-repeat
  6682. newhead))
  6683. todayp)
  6684. (setq newhead org-agenda-headline-snapshot-before-repeat
  6685. just-one t))
  6686. (save-excursion
  6687. (org-back-to-heading)
  6688. (move-marker org-last-heading-marker (point))))
  6689. (beginning-of-line 1)
  6690. (save-excursion
  6691. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6692. (org-move-to-column col))))
  6693. (defun org-agenda-add-note (&optional arg)
  6694. "Add a time-stamped note to the entry at point."
  6695. (interactive "P")
  6696. (org-agenda-check-no-diary)
  6697. (let* ((marker (or (org-get-at-bol 'org-marker)
  6698. (org-agenda-error)))
  6699. (buffer (marker-buffer marker))
  6700. (pos (marker-position marker))
  6701. (hdmarker (org-get-at-bol 'org-hd-marker))
  6702. (inhibit-read-only t))
  6703. (with-current-buffer buffer
  6704. (widen)
  6705. (goto-char pos)
  6706. (org-show-context 'agenda)
  6707. (save-excursion
  6708. (and (outline-next-heading)
  6709. (org-flag-heading nil))) ; show the next heading
  6710. (org-add-note))))
  6711. (defun org-agenda-change-all-lines (newhead hdmarker
  6712. &optional fixface just-this)
  6713. "Change all lines in the agenda buffer which match HDMARKER.
  6714. The new content of the line will be NEWHEAD (as modified by
  6715. `org-format-agenda-item'). HDMARKER is checked with
  6716. `equal' against all `org-hd-marker' text properties in the file.
  6717. If FIXFACE is non-nil, the face of each item is modified according to
  6718. the new TODO state.
  6719. If JUST-THIS is non-nil, change just the current line, not all.
  6720. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6721. (let* ((inhibit-read-only t)
  6722. (line (org-current-line))
  6723. (thetags (with-current-buffer (marker-buffer hdmarker)
  6724. (save-excursion (save-restriction (widen)
  6725. (goto-char hdmarker)
  6726. (org-get-tags-at)))))
  6727. props m pl undone-face done-face finish new dotime cat tags)
  6728. (save-excursion
  6729. (goto-char (point-max))
  6730. (beginning-of-line 1)
  6731. (while (not finish)
  6732. (setq finish (bobp))
  6733. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6734. (or (not just-this) (= (org-current-line) line))
  6735. (equal m hdmarker))
  6736. (setq props (text-properties-at (point))
  6737. dotime (org-get-at-bol 'dotime)
  6738. cat (org-get-at-bol 'org-category)
  6739. tags thetags
  6740. new (org-format-agenda-item (org-get-at-bol 'extra)
  6741. newhead cat tags dotime)
  6742. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6743. undone-face (org-get-at-bol 'undone-face)
  6744. done-face (org-get-at-bol 'done-face))
  6745. (beginning-of-line 1)
  6746. (cond
  6747. ((equal new "")
  6748. (and (looking-at ".*\n?") (replace-match "")))
  6749. ((looking-at ".*")
  6750. (replace-match new t t)
  6751. (beginning-of-line 1)
  6752. (add-text-properties (point-at-bol) (point-at-eol) props)
  6753. (when fixface
  6754. (add-text-properties
  6755. (point-at-bol) (point-at-eol)
  6756. (list 'face
  6757. (if org-last-todo-state-is-todo
  6758. undone-face done-face))))
  6759. (org-agenda-highlight-todo 'line)
  6760. (beginning-of-line 1))
  6761. (t (error "Line update did not work"))))
  6762. (beginning-of-line 0)))
  6763. (org-finalize-agenda)))
  6764. (defun org-agenda-align-tags (&optional line)
  6765. "Align all tags in agenda items to `org-agenda-tags-column'."
  6766. (let ((inhibit-read-only t) l c)
  6767. (save-excursion
  6768. (goto-char (if line (point-at-bol) (point-min)))
  6769. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6770. (if line (point-at-eol) nil) t)
  6771. (add-text-properties
  6772. (match-beginning 2) (match-end 2)
  6773. (list 'face (delq nil (let ((prop (get-text-property
  6774. (match-beginning 2) 'face)))
  6775. (or (listp prop) (setq prop (list prop)))
  6776. (if (memq 'org-tag prop)
  6777. prop
  6778. (cons 'org-tag prop))))))
  6779. (setq l (- (match-end 2) (match-beginning 2))
  6780. c (if (< org-agenda-tags-column 0)
  6781. (- (abs org-agenda-tags-column) l)
  6782. org-agenda-tags-column))
  6783. (delete-region (match-beginning 1) (match-end 1))
  6784. (goto-char (match-beginning 1))
  6785. (insert (org-add-props
  6786. (make-string (max 1 (- c (current-column))) ?\ )
  6787. (plist-put (copy-sequence (text-properties-at (point)))
  6788. 'face nil))))
  6789. (goto-char (point-min))
  6790. (org-font-lock-add-tag-faces (point-max)))))
  6791. (defun org-agenda-priority-up ()
  6792. "Increase the priority of line at point, also in Org-mode file."
  6793. (interactive)
  6794. (org-agenda-priority 'up))
  6795. (defun org-agenda-priority-down ()
  6796. "Decrease the priority of line at point, also in Org-mode file."
  6797. (interactive)
  6798. (org-agenda-priority 'down))
  6799. (defun org-agenda-priority (&optional force-direction)
  6800. "Set the priority of line at point, also in Org-mode file.
  6801. This changes the line at point, all other lines in the agenda referring to
  6802. the same tree node, and the headline of the tree node in the Org-mode file."
  6803. (interactive)
  6804. (unless org-enable-priority-commands
  6805. (error "Priority commands are disabled"))
  6806. (org-agenda-check-no-diary)
  6807. (let* ((marker (or (org-get-at-bol 'org-marker)
  6808. (org-agenda-error)))
  6809. (hdmarker (org-get-at-bol 'org-hd-marker))
  6810. (buffer (marker-buffer hdmarker))
  6811. (pos (marker-position hdmarker))
  6812. (inhibit-read-only t)
  6813. newhead)
  6814. (org-with-remote-undo buffer
  6815. (with-current-buffer buffer
  6816. (widen)
  6817. (goto-char pos)
  6818. (org-show-context 'agenda)
  6819. (save-excursion
  6820. (and (outline-next-heading)
  6821. (org-flag-heading nil))) ; show the next heading
  6822. (funcall 'org-priority force-direction)
  6823. (end-of-line 1)
  6824. (setq newhead (org-get-heading)))
  6825. (org-agenda-change-all-lines newhead hdmarker)
  6826. (beginning-of-line 1))))
  6827. ;; FIXME: should fix the tags property of the agenda line.
  6828. (defun org-agenda-set-tags (&optional tag onoff)
  6829. "Set tags for the current headline."
  6830. (interactive)
  6831. (org-agenda-check-no-diary)
  6832. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6833. (call-interactively 'org-change-tag-in-region)
  6834. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6835. (org-agenda-error)))
  6836. (buffer (marker-buffer hdmarker))
  6837. (pos (marker-position hdmarker))
  6838. (inhibit-read-only t)
  6839. newhead)
  6840. (org-with-remote-undo buffer
  6841. (with-current-buffer buffer
  6842. (widen)
  6843. (goto-char pos)
  6844. (save-excursion
  6845. (org-show-context 'agenda))
  6846. (save-excursion
  6847. (and (outline-next-heading)
  6848. (org-flag-heading nil))) ; show the next heading
  6849. (goto-char pos)
  6850. (if tag
  6851. (org-toggle-tag tag onoff)
  6852. (call-interactively 'org-set-tags))
  6853. (end-of-line 1)
  6854. (setq newhead (org-get-heading)))
  6855. (org-agenda-change-all-lines newhead hdmarker)
  6856. (beginning-of-line 1)))))
  6857. (defun org-agenda-set-property ()
  6858. "Set a property for the current headline."
  6859. (interactive)
  6860. (org-agenda-check-no-diary)
  6861. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6862. (org-agenda-error)))
  6863. (buffer (marker-buffer hdmarker))
  6864. (pos (marker-position hdmarker))
  6865. (inhibit-read-only t)
  6866. newhead)
  6867. (org-with-remote-undo buffer
  6868. (with-current-buffer buffer
  6869. (widen)
  6870. (goto-char pos)
  6871. (save-excursion
  6872. (org-show-context 'agenda))
  6873. (save-excursion
  6874. (and (outline-next-heading)
  6875. (org-flag-heading nil))) ; show the next heading
  6876. (goto-char pos)
  6877. (call-interactively 'org-set-property)))))
  6878. (defun org-agenda-set-effort ()
  6879. "Set the effort property for the current headline."
  6880. (interactive)
  6881. (org-agenda-check-no-diary)
  6882. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6883. (org-agenda-error)))
  6884. (buffer (marker-buffer hdmarker))
  6885. (pos (marker-position hdmarker))
  6886. (inhibit-read-only t)
  6887. newhead)
  6888. (org-with-remote-undo buffer
  6889. (with-current-buffer buffer
  6890. (widen)
  6891. (goto-char pos)
  6892. (save-excursion
  6893. (org-show-context 'agenda))
  6894. (save-excursion
  6895. (and (outline-next-heading)
  6896. (org-flag-heading nil))) ; show the next heading
  6897. (goto-char pos)
  6898. (call-interactively 'org-set-effort)
  6899. (end-of-line 1)))))
  6900. (defun org-agenda-toggle-archive-tag ()
  6901. "Toggle the archive tag for the current entry."
  6902. (interactive)
  6903. (org-agenda-check-no-diary)
  6904. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6905. (org-agenda-error)))
  6906. (buffer (marker-buffer hdmarker))
  6907. (pos (marker-position hdmarker))
  6908. (inhibit-read-only t)
  6909. newhead)
  6910. (org-with-remote-undo buffer
  6911. (with-current-buffer buffer
  6912. (widen)
  6913. (goto-char pos)
  6914. (org-show-context 'agenda)
  6915. (save-excursion
  6916. (and (outline-next-heading)
  6917. (org-flag-heading nil))) ; show the next heading
  6918. (call-interactively 'org-toggle-archive-tag)
  6919. (end-of-line 1)
  6920. (setq newhead (org-get-heading)))
  6921. (org-agenda-change-all-lines newhead hdmarker)
  6922. (beginning-of-line 1))))
  6923. (defun org-agenda-do-date-later (arg)
  6924. (interactive "P")
  6925. (cond
  6926. ((or (equal arg '(16))
  6927. (memq last-command
  6928. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6929. (setq this-command 'org-agenda-date-later-minutes)
  6930. (org-agenda-date-later-minutes 1))
  6931. ((or (equal arg '(4))
  6932. (memq last-command
  6933. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6934. (setq this-command 'org-agenda-date-later-hours)
  6935. (org-agenda-date-later-hours 1))
  6936. (t
  6937. (org-agenda-date-later (prefix-numeric-value arg)))))
  6938. (defun org-agenda-do-date-earlier (arg)
  6939. (interactive "P")
  6940. (cond
  6941. ((or (equal arg '(16))
  6942. (memq last-command
  6943. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6944. (setq this-command 'org-agenda-date-earlier-minutes)
  6945. (org-agenda-date-earlier-minutes 1))
  6946. ((or (equal arg '(4))
  6947. (memq last-command
  6948. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6949. (setq this-command 'org-agenda-date-earlier-hours)
  6950. (org-agenda-date-earlier-hours 1))
  6951. (t
  6952. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6953. (defun org-agenda-date-later (arg &optional what)
  6954. "Change the date of this item to ARG day(s) later."
  6955. (interactive "p")
  6956. (org-agenda-check-type t 'agenda 'timeline)
  6957. (org-agenda-check-no-diary)
  6958. (let* ((marker (or (org-get-at-bol 'org-marker)
  6959. (org-agenda-error)))
  6960. (buffer (marker-buffer marker))
  6961. (pos (marker-position marker)))
  6962. (org-with-remote-undo buffer
  6963. (with-current-buffer buffer
  6964. (widen)
  6965. (goto-char pos)
  6966. (if (not (org-at-timestamp-p))
  6967. (error "Cannot find time stamp"))
  6968. (org-timestamp-change arg (or what 'day)))
  6969. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6970. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6971. (defun org-agenda-date-earlier (arg &optional what)
  6972. "Change the date of this item to ARG day(s) earlier."
  6973. (interactive "p")
  6974. (org-agenda-date-later (- arg) what))
  6975. (defun org-agenda-date-later-minutes (arg)
  6976. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6977. (interactive "p")
  6978. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6979. (org-agenda-date-later arg 'minute))
  6980. (defun org-agenda-date-earlier-minutes (arg)
  6981. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6982. (interactive "p")
  6983. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6984. (org-agenda-date-earlier arg 'minute))
  6985. (defun org-agenda-date-later-hours (arg)
  6986. "Change the time of this item, in hour steps."
  6987. (interactive "p")
  6988. (org-agenda-date-later arg 'hour))
  6989. (defun org-agenda-date-earlier-hours (arg)
  6990. "Change the time of this item, in hour steps."
  6991. (interactive "p")
  6992. (org-agenda-date-earlier arg 'hour))
  6993. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6994. "Show new date stamp via text properties."
  6995. ;; We use text properties to make this undoable
  6996. (let ((inhibit-read-only t)
  6997. (buffer-invisibility-spec))
  6998. (setq stamp (concat " " prefix " => " stamp))
  6999. (save-excursion
  7000. (goto-char (point-max))
  7001. (while (not (bobp))
  7002. (when (equal marker (org-get-at-bol 'org-marker))
  7003. (org-move-to-column (- (window-width) (length stamp)) t)
  7004. (org-agenda-fix-tags-filter-overlays-at (point))
  7005. (if (featurep 'xemacs)
  7006. ;; Use `duplicable' property to trigger undo recording
  7007. (let ((ex (make-extent nil nil))
  7008. (gl (make-glyph stamp)))
  7009. (set-glyph-face gl 'secondary-selection)
  7010. (set-extent-properties
  7011. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7012. (insert-extent ex (1- (point)) (point-at-eol)))
  7013. (add-text-properties
  7014. (1- (point)) (point-at-eol)
  7015. (list 'display (org-add-props stamp nil
  7016. 'face 'secondary-selection))))
  7017. (beginning-of-line 1))
  7018. (beginning-of-line 0)))))
  7019. (defun org-agenda-date-prompt (arg)
  7020. "Change the date of this item. Date is prompted for, with default today.
  7021. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7022. be used to request time specification in the time stamp."
  7023. (interactive "P")
  7024. (org-agenda-check-type t 'agenda 'timeline)
  7025. (org-agenda-check-no-diary)
  7026. (let* ((marker (or (org-get-at-bol 'org-marker)
  7027. (org-agenda-error)))
  7028. (buffer (marker-buffer marker))
  7029. (pos (marker-position marker)))
  7030. (org-with-remote-undo buffer
  7031. (with-current-buffer buffer
  7032. (widen)
  7033. (goto-char pos)
  7034. (if (not (org-at-timestamp-p t))
  7035. (error "Cannot find time stamp"))
  7036. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7037. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7038. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7039. (defun org-agenda-schedule (arg &optional time)
  7040. "Schedule the item at point.
  7041. Arg is passed through to `org-schedule'."
  7042. (interactive "P")
  7043. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7044. (org-agenda-check-no-diary)
  7045. (let* ((marker (or (org-get-at-bol 'org-marker)
  7046. (org-agenda-error)))
  7047. (type (marker-insertion-type marker))
  7048. (buffer (marker-buffer marker))
  7049. (pos (marker-position marker))
  7050. (org-insert-labeled-timestamps-at-point nil)
  7051. ts)
  7052. (set-marker-insertion-type marker t)
  7053. (org-with-remote-undo buffer
  7054. (with-current-buffer buffer
  7055. (widen)
  7056. (goto-char pos)
  7057. (setq ts (org-schedule arg time)))
  7058. (org-agenda-show-new-time marker ts "S"))
  7059. (message "Item scheduled for %s" ts)))
  7060. (defun org-agenda-deadline (arg &optional time)
  7061. "Schedule the item at point.
  7062. Arg is passed through to `org-deadline'."
  7063. (interactive "P")
  7064. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7065. (org-agenda-check-no-diary)
  7066. (let* ((marker (or (org-get-at-bol 'org-marker)
  7067. (org-agenda-error)))
  7068. (buffer (marker-buffer marker))
  7069. (pos (marker-position marker))
  7070. (org-insert-labeled-timestamps-at-point nil)
  7071. ts)
  7072. (org-with-remote-undo buffer
  7073. (with-current-buffer buffer
  7074. (widen)
  7075. (goto-char pos)
  7076. (setq ts (org-deadline arg time)))
  7077. (org-agenda-show-new-time marker ts "D"))
  7078. (message "Deadline for this item set to %s" ts)))
  7079. (defun org-agenda-action ()
  7080. "Select entry for agenda action, or execute an agenda action.
  7081. This command prompts for another letter. Valid inputs are:
  7082. m Mark the entry at point for an agenda action
  7083. s Schedule the marked entry to the date at the cursor
  7084. d Set the deadline of the marked entry to the date at the cursor
  7085. r Call `org-remember' with cursor date as the default date
  7086. c Call `org-capture' with cursor date as the default date
  7087. SPC Show marked entry in other window
  7088. TAB Visit marked entry in other window
  7089. The cursor may be at a date in the calendar, or in the Org agenda."
  7090. (interactive)
  7091. (let (ans)
  7092. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7093. (setq ans (read-char-exclusive))
  7094. (cond
  7095. ((equal ans ?m)
  7096. ;; Mark this entry
  7097. (if (eq major-mode 'org-agenda-mode)
  7098. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7099. (org-get-at-bol 'org-marker))))
  7100. (if m
  7101. (progn
  7102. (move-marker org-agenda-action-marker
  7103. (marker-position m) (marker-buffer m))
  7104. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7105. (error "Don't know which entry to mark")))
  7106. (error "This command works only in the agenda")))
  7107. ((equal ans ?s)
  7108. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7109. ((equal ans ?d)
  7110. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7111. ((equal ans ?r)
  7112. (org-agenda-do-action '(org-remember) t))
  7113. ((equal ans ?c)
  7114. (org-agenda-do-action '(org-capture) t))
  7115. ((equal ans ?\ )
  7116. (let ((cw (selected-window)))
  7117. (org-switch-to-buffer-other-window
  7118. (marker-buffer org-agenda-action-marker))
  7119. (goto-char org-agenda-action-marker)
  7120. (org-show-context 'agenda)
  7121. (select-window cw)))
  7122. ((equal ans ?\C-i)
  7123. (org-switch-to-buffer-other-window
  7124. (marker-buffer org-agenda-action-marker))
  7125. (goto-char org-agenda-action-marker)
  7126. (org-show-context 'agenda))
  7127. (t (error "Invalid agenda action %c" ans)))))
  7128. (defun org-agenda-do-action (form &optional current-buffer)
  7129. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7130. (let ((org-overriding-default-time (org-get-cursor-date)))
  7131. (if current-buffer
  7132. (eval form)
  7133. (if (not (marker-buffer org-agenda-action-marker))
  7134. (error "No entry has been selected for agenda action")
  7135. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7136. (save-excursion
  7137. (save-restriction
  7138. (widen)
  7139. (goto-char org-agenda-action-marker)
  7140. (eval form))))))))
  7141. (defun org-agenda-clock-in (&optional arg)
  7142. "Start the clock on the currently selected item."
  7143. (interactive "P")
  7144. (org-agenda-check-no-diary)
  7145. (if (equal arg '(4))
  7146. (org-clock-in arg)
  7147. (let* ((marker (or (org-get-at-bol 'org-marker)
  7148. (org-agenda-error)))
  7149. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7150. marker))
  7151. (pos (marker-position marker))
  7152. newhead)
  7153. (org-with-remote-undo (marker-buffer marker)
  7154. (with-current-buffer (marker-buffer marker)
  7155. (widen)
  7156. (goto-char pos)
  7157. (org-show-context 'agenda)
  7158. (org-show-entry)
  7159. (org-cycle-hide-drawers 'children)
  7160. (org-clock-in arg)
  7161. (setq newhead (org-get-heading)))
  7162. (org-agenda-change-all-lines newhead hdmarker)))))
  7163. (defun org-agenda-clock-out ()
  7164. "Stop the currently running clock."
  7165. (interactive)
  7166. (unless (marker-buffer org-clock-marker)
  7167. (error "No running clock"))
  7168. (let ((marker (make-marker)) newhead)
  7169. (org-with-remote-undo (marker-buffer org-clock-marker)
  7170. (with-current-buffer (marker-buffer org-clock-marker)
  7171. (save-excursion
  7172. (save-restriction
  7173. (widen)
  7174. (goto-char org-clock-marker)
  7175. (org-back-to-heading t)
  7176. (move-marker marker (point))
  7177. (org-clock-out)
  7178. (setq newhead (org-get-heading))))))
  7179. (org-agenda-change-all-lines newhead marker)
  7180. (move-marker marker nil)))
  7181. (defun org-agenda-clock-cancel (&optional arg)
  7182. "Cancel the currently running clock."
  7183. (interactive "P")
  7184. (unless (marker-buffer org-clock-marker)
  7185. (error "No running clock"))
  7186. (org-with-remote-undo (marker-buffer org-clock-marker)
  7187. (org-clock-cancel)))
  7188. (defun org-agenda-clock-goto ()
  7189. "Jump to the currently clocked in task within the agenda.
  7190. If the currently clocked in task is not listed in the agenda
  7191. buffer, display it in another window."
  7192. (interactive)
  7193. (let (pos)
  7194. (mapc (lambda (o)
  7195. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7196. (setq pos (overlay-start o))))
  7197. (overlays-in (point-min) (point-max)))
  7198. (cond (pos (goto-char pos))
  7199. ;; If the currently clocked entry is not in the agenda
  7200. ;; buffer, we visit it in another window:
  7201. (org-clock-current-task
  7202. (org-switch-to-buffer-other-window (org-clock-goto)))
  7203. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7204. (defun org-agenda-diary-entry-in-org-file ()
  7205. "Make a diary entry in the file `org-agenda-diary-file'."
  7206. (let (d1 d2 char (text "") dp1 dp2)
  7207. (if (equal (buffer-name) "*Calendar*")
  7208. (setq d1 (calendar-cursor-to-date t)
  7209. d2 (car calendar-mark-ring))
  7210. (setq dp1 (get-text-property (point-at-bol) 'day))
  7211. (unless dp1 (error "No date defined in current line"))
  7212. (setq d1 (calendar-gregorian-from-absolute dp1)
  7213. d2 (and (ignore-errors (mark))
  7214. (save-excursion
  7215. (goto-char (mark))
  7216. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7217. (calendar-gregorian-from-absolute dp2))))
  7218. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7219. (setq char (read-char-exclusive))
  7220. (cond
  7221. ((equal char ?d)
  7222. (setq text (read-string "Day entry: "))
  7223. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7224. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7225. ((equal char ?a)
  7226. (setq d1 (list (car d1) (nth 1 d1)
  7227. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7228. (nth 2 d1))))
  7229. (setq text (read-string "Anniversary (use %d to show years): "))
  7230. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7231. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7232. ((equal char ?b)
  7233. (setq text (read-string "Block entry: "))
  7234. (unless (and d1 d2 (not (equal d1 d2)))
  7235. (error "No block of days selected"))
  7236. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7237. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7238. ((equal char ?j)
  7239. (org-switch-to-buffer-other-window
  7240. (find-file-noselect org-agenda-diary-file))
  7241. (require 'org-datetree)
  7242. (org-datetree-find-date-create d1)
  7243. (org-reveal t))
  7244. (t (error "Invalid selection character `%c'" char)))))
  7245. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7246. "Where in `org-agenda-diary-file' should new entries be added?
  7247. Valid values:
  7248. date-tree in the date tree, as child of the date
  7249. top-level as top-level entries at the end of the file."
  7250. :group 'org-agenda
  7251. :type '(choice
  7252. (const :tag "in a date tree" date-tree)
  7253. (const :tag "as top level at end of file" top-level)))
  7254. (defcustom org-agenda-insert-diary-extract-time nil
  7255. "Non-nil means extract any time specification from the diary entry."
  7256. :group 'org-agenda
  7257. :type 'boolean)
  7258. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7259. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7260. If TEXT is not empty, it will become the headline of the new entry, and
  7261. the resulting entry will not be shown. When TEXT is empty, switch to
  7262. `org-agenda-diary-file' and let the user finish the entry there."
  7263. (let ((cw (current-window-configuration)))
  7264. (org-switch-to-buffer-other-window
  7265. (find-file-noselect org-agenda-diary-file))
  7266. (widen)
  7267. (goto-char (point-min))
  7268. (cond
  7269. ((eq type 'anniversary)
  7270. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7271. (progn
  7272. (or (org-on-heading-p t)
  7273. (progn
  7274. (outline-next-heading)
  7275. (insert "* Anniversaries\n\n")
  7276. (beginning-of-line -1)))))
  7277. (outline-next-heading)
  7278. (org-back-over-empty-lines)
  7279. (backward-char 1)
  7280. (insert "\n")
  7281. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7282. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7283. ((eq type 'day)
  7284. (let ((org-prefix-has-time t)
  7285. (org-agenda-time-leading-zero t)
  7286. fmt time time2)
  7287. (if org-agenda-insert-diary-extract-time
  7288. ;; Use org-format-agenda-item to parse text for a time-range and
  7289. ;; remove it. FIXME: This is a hack, we should refactor
  7290. ;; that function to make time extraction available separately
  7291. (setq fmt (org-format-agenda-item nil text nil nil t)
  7292. time (get-text-property 0 'time fmt)
  7293. time2 (if (> (length time) 0)
  7294. ;; split-string removes trailing ...... if
  7295. ;; no end time given. First space
  7296. ;; separates time from date.
  7297. (concat " " (car (split-string time "\\.")))
  7298. nil)
  7299. text (get-text-property 0 'txt fmt)))
  7300. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7301. (org-agenda-insert-diary-as-top-level text)
  7302. (require 'org-datetree)
  7303. (org-datetree-find-date-create d1)
  7304. (org-agenda-insert-diary-make-new-entry text))
  7305. (org-insert-time-stamp (org-time-from-absolute
  7306. (calendar-absolute-from-gregorian d1))
  7307. nil nil nil nil time2))
  7308. (end-of-line 0))
  7309. ((eq type 'block)
  7310. (if (> (calendar-absolute-from-gregorian d1)
  7311. (calendar-absolute-from-gregorian d2))
  7312. (setq d1 (prog1 d2 (setq d2 d1))))
  7313. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7314. (org-agenda-insert-diary-as-top-level text)
  7315. (require 'org-datetree)
  7316. (org-datetree-find-date-create d1)
  7317. (org-agenda-insert-diary-make-new-entry text))
  7318. (org-insert-time-stamp (org-time-from-absolute
  7319. (calendar-absolute-from-gregorian d1)))
  7320. (insert "--")
  7321. (org-insert-time-stamp (org-time-from-absolute
  7322. (calendar-absolute-from-gregorian d2)))
  7323. (end-of-line 0)))
  7324. (if (string-match "\\S-" text)
  7325. (progn
  7326. (set-window-configuration cw)
  7327. (message "%s entry added to %s"
  7328. (capitalize (symbol-name type))
  7329. (abbreviate-file-name org-agenda-diary-file)))
  7330. (org-reveal t)
  7331. (message "Please finish entry here"))))
  7332. (defun org-agenda-insert-diary-as-top-level (text)
  7333. "Make new entry as a top-level entry at the end of the file.
  7334. Add TEXT as headline, and position the cursor in the second line so that
  7335. a timestamp can be added there."
  7336. (widen)
  7337. (goto-char (point-max))
  7338. (or (bolp) (insert "\n"))
  7339. (insert "* " text "\n")
  7340. (if org-adapt-indentation (org-indent-to-column 2)))
  7341. (defun org-agenda-insert-diary-make-new-entry (text)
  7342. "Make new entry as last child of current entry.
  7343. Add TEXT as headline, and position the cursor in the second line so that
  7344. a timestamp can be added there."
  7345. (let ((org-show-following-heading t)
  7346. (org-show-siblings t)
  7347. (org-show-hierarchy-above t)
  7348. (org-show-entry-below t)
  7349. col)
  7350. (outline-next-heading)
  7351. (org-back-over-empty-lines)
  7352. (or (looking-at "[ \t]*$")
  7353. (progn (insert "\n") (backward-char 1)))
  7354. (org-insert-heading nil t)
  7355. (org-do-demote)
  7356. (setq col (current-column))
  7357. (insert text "\n")
  7358. (if org-adapt-indentation (org-indent-to-column col))
  7359. (let ((org-show-following-heading t)
  7360. (org-show-siblings t)
  7361. (org-show-hierarchy-above t)
  7362. (org-show-entry-below t))
  7363. (org-show-context))))
  7364. (defun org-agenda-diary-entry ()
  7365. "Make a diary entry, like the `i' command from the calendar.
  7366. All the standard commands work: block, weekly etc.
  7367. When `org-agenda-diary-file' points to a file,
  7368. `org-agenda-diary-entry-in-org-file' is called instead to create
  7369. entries in that Org-mode file."
  7370. (interactive)
  7371. (org-agenda-check-type t 'agenda 'timeline)
  7372. (if (not (eq org-agenda-diary-file 'diary-file))
  7373. (org-agenda-diary-entry-in-org-file)
  7374. (require 'diary-lib)
  7375. (let* ((char (progn
  7376. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7377. (read-char-exclusive)))
  7378. (cmd (cdr (assoc char
  7379. '((?d . insert-diary-entry)
  7380. (?w . insert-weekly-diary-entry)
  7381. (?m . insert-monthly-diary-entry)
  7382. (?y . insert-yearly-diary-entry)
  7383. (?a . insert-anniversary-diary-entry)
  7384. (?b . insert-block-diary-entry)
  7385. (?c . insert-cyclic-diary-entry)))))
  7386. (oldf (symbol-function 'calendar-cursor-to-date))
  7387. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7388. (point (point))
  7389. (mark (or (mark t) (point))))
  7390. (unless cmd
  7391. (error "No command associated with <%c>" char))
  7392. (unless (and (get-text-property point 'day)
  7393. (or (not (equal ?b char))
  7394. (get-text-property mark 'day)))
  7395. (error "Don't know which date to use for diary entry"))
  7396. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7397. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7398. (let ((calendar-mark-ring
  7399. (list (calendar-gregorian-from-absolute
  7400. (or (get-text-property mark 'day)
  7401. (get-text-property point 'day))))))
  7402. (unwind-protect
  7403. (progn
  7404. (fset 'calendar-cursor-to-date
  7405. (lambda (&optional error dummy)
  7406. (calendar-gregorian-from-absolute
  7407. (get-text-property point 'day))))
  7408. (call-interactively cmd))
  7409. (fset 'calendar-cursor-to-date oldf))))))
  7410. (defun org-agenda-execute-calendar-command (cmd)
  7411. "Execute a calendar command from the agenda, with the date associated to
  7412. the cursor position."
  7413. (org-agenda-check-type t 'agenda 'timeline)
  7414. (require 'diary-lib)
  7415. (unless (get-text-property (point) 'day)
  7416. (error "Don't know which date to use for calendar command"))
  7417. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7418. (point (point))
  7419. (date (calendar-gregorian-from-absolute
  7420. (get-text-property point 'day)))
  7421. ;; the following 2 vars are needed in the calendar
  7422. (displayed-month (car date))
  7423. (displayed-year (nth 2 date)))
  7424. (unwind-protect
  7425. (progn
  7426. (fset 'calendar-cursor-to-date
  7427. (lambda (&optional error dummy)
  7428. (calendar-gregorian-from-absolute
  7429. (get-text-property point 'day))))
  7430. (call-interactively cmd))
  7431. (fset 'calendar-cursor-to-date oldf))))
  7432. (defun org-agenda-phases-of-moon ()
  7433. "Display the phases of the moon for the 3 months around the cursor date."
  7434. (interactive)
  7435. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7436. (defun org-agenda-holidays ()
  7437. "Display the holidays for the 3 months around the cursor date."
  7438. (interactive)
  7439. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7440. (defvar calendar-longitude)
  7441. (defvar calendar-latitude)
  7442. (defvar calendar-location-name)
  7443. (defun org-agenda-sunrise-sunset (arg)
  7444. "Display sunrise and sunset for the cursor date.
  7445. Latitude and longitude can be specified with the variables
  7446. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7447. argument, latitude and longitude will be prompted for."
  7448. (interactive "P")
  7449. (require 'solar)
  7450. (let ((calendar-longitude (if arg nil calendar-longitude))
  7451. (calendar-latitude (if arg nil calendar-latitude))
  7452. (calendar-location-name
  7453. (if arg "the given coordinates" calendar-location-name)))
  7454. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7455. (defun org-agenda-goto-calendar ()
  7456. "Open the Emacs calendar with the date at the cursor."
  7457. (interactive)
  7458. (org-agenda-check-type t 'agenda 'timeline)
  7459. (let* ((day (or (get-text-property (point) 'day)
  7460. (error "Don't know which date to open in calendar")))
  7461. (date (calendar-gregorian-from-absolute day))
  7462. (calendar-move-hook nil)
  7463. (calendar-view-holidays-initially-flag nil)
  7464. (calendar-view-diary-initially-flag nil))
  7465. (calendar)
  7466. (calendar-goto-date date)))
  7467. ;;;###autoload
  7468. (defun org-calendar-goto-agenda ()
  7469. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7470. This is a command that has to be installed in `calendar-mode-map'."
  7471. (interactive)
  7472. (org-agenda-list nil (calendar-absolute-from-gregorian
  7473. (calendar-cursor-to-date))
  7474. nil))
  7475. (defun org-agenda-convert-date ()
  7476. (interactive)
  7477. (org-agenda-check-type t 'agenda 'timeline)
  7478. (let ((day (get-text-property (point) 'day))
  7479. date s)
  7480. (unless day
  7481. (error "Don't know which date to convert"))
  7482. (setq date (calendar-gregorian-from-absolute day))
  7483. (setq s (concat
  7484. "Gregorian: " (calendar-date-string date) "\n"
  7485. "ISO: " (calendar-iso-date-string date) "\n"
  7486. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7487. "Julian: " (calendar-julian-date-string date) "\n"
  7488. "Astron. JD: " (calendar-astro-date-string date)
  7489. " (Julian date number at noon UTC)\n"
  7490. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7491. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7492. "French: " (calendar-french-date-string date) "\n"
  7493. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7494. "Mayan: " (calendar-mayan-date-string date) "\n"
  7495. "Coptic: " (calendar-coptic-date-string date) "\n"
  7496. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7497. "Persian: " (calendar-persian-date-string date) "\n"
  7498. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7499. (with-output-to-temp-buffer "*Dates*"
  7500. (princ s))
  7501. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7502. ;;; Bulk commands
  7503. (defvar org-agenda-bulk-marked-entries nil
  7504. "List of markers that refer to marked entries in the agenda.")
  7505. (defun org-agenda-bulk-marked-p ()
  7506. (eq (get-char-property (point-at-bol) 'type)
  7507. 'org-marked-entry-overlay))
  7508. (defun org-agenda-bulk-mark (&optional arg)
  7509. "Mark the entry at point for future bulk action."
  7510. (interactive "p")
  7511. (dotimes (i (max arg 1))
  7512. (unless (org-get-at-bol 'org-agenda-diary-link)
  7513. (let* ((m (org-get-at-bol 'org-hd-marker))
  7514. ov)
  7515. (unless (org-agenda-bulk-marked-p)
  7516. (unless m (error "Nothing to mark at point"))
  7517. (push m org-agenda-bulk-marked-entries)
  7518. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7519. (org-overlay-display ov "> "
  7520. (org-get-todo-face "TODO")
  7521. 'evaporate)
  7522. (overlay-put ov 'type 'org-marked-entry-overlay))
  7523. (beginning-of-line 2)
  7524. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7525. (beginning-of-line 2))
  7526. (message "%d entries marked for bulk action"
  7527. (length org-agenda-bulk-marked-entries))))))
  7528. (defun org-agenda-bulk-mark-regexp (regexp)
  7529. "Mark entries match REGEXP."
  7530. (interactive "sMark entries matching regexp: ")
  7531. (let (entries-marked)
  7532. (save-excursion
  7533. (goto-char (point-min))
  7534. (goto-char (next-single-property-change (point) 'txt))
  7535. (while (re-search-forward regexp nil t)
  7536. (when (string-match regexp (get-text-property (point) 'txt))
  7537. (setq entries-marked (+ entries-marked 1))
  7538. (call-interactively 'org-agenda-bulk-mark))))
  7539. (if (not entries-marked)
  7540. (message "No entry matching this regexp."))))
  7541. (defun org-agenda-bulk-unmark ()
  7542. "Unmark the entry at point for future bulk action."
  7543. (interactive)
  7544. (when (org-agenda-bulk-marked-p)
  7545. (org-agenda-bulk-remove-overlays
  7546. (point-at-bol) (+ 2 (point-at-bol)))
  7547. (setq org-agenda-bulk-marked-entries
  7548. (delete (org-get-at-bol 'org-hd-marker)
  7549. org-agenda-bulk-marked-entries)))
  7550. (beginning-of-line 2)
  7551. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7552. (beginning-of-line 2))
  7553. (message "%d entries marked for bulk action"
  7554. (length org-agenda-bulk-marked-entries)))
  7555. (defun org-agenda-bulk-toggle ()
  7556. "Toggle marking the entry at point for bulk action."
  7557. (interactive)
  7558. (if (org-agenda-bulk-marked-p)
  7559. (org-agenda-bulk-unmark)
  7560. (org-agenda-bulk-mark)))
  7561. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7562. "Remove the mark overlays between BEG and END in the agenda buffer.
  7563. BEG and END default to the buffer limits.
  7564. This only removes the overlays, it does not remove the markers
  7565. from the list in `org-agenda-bulk-marked-entries'."
  7566. (interactive)
  7567. (mapc (lambda (ov)
  7568. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7569. (delete-overlay ov)))
  7570. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7571. (defun org-agenda-bulk-remove-all-marks ()
  7572. "Remove all marks in the agenda buffer.
  7573. This will remove the markers, and the overlays."
  7574. (interactive)
  7575. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7576. (setq org-agenda-bulk-marked-entries nil)
  7577. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7578. (defun org-agenda-bulk-action (&optional arg)
  7579. "Execute an remote-editing action on all marked entries.
  7580. The prefix arg is passed through to the command if possible."
  7581. (interactive "P")
  7582. ;; Make sure we have markers, and only valid ones
  7583. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7584. (mapc
  7585. (lambda (m)
  7586. (unless (and (markerp m)
  7587. (marker-buffer m)
  7588. (buffer-live-p (marker-buffer m))
  7589. (marker-position m))
  7590. (error "Marker %s for bulk command is invalid" m)))
  7591. org-agenda-bulk-marked-entries)
  7592. ;; Prompt for the bulk command
  7593. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7594. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7595. (when org-agenda-bulk-custom-functions
  7596. (concat " Custom: ["
  7597. (mapconcat (lambda(f) (char-to-string (car f)))
  7598. org-agenda-bulk-custom-functions "")
  7599. "]"))))
  7600. (let* ((action (read-char-exclusive))
  7601. (org-log-refile (if org-log-refile 'time nil))
  7602. (entries (reverse org-agenda-bulk-marked-entries))
  7603. redo-at-end
  7604. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7605. (cond
  7606. ((equal action ?$)
  7607. (setq cmd '(org-agenda-archive)))
  7608. ((equal action ?A)
  7609. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7610. ((member action '(?r ?w))
  7611. (setq rfloc (org-refile-get-location
  7612. "Refile to"
  7613. (marker-buffer (car org-agenda-bulk-marked-entries))
  7614. org-refile-allow-creating-parent-nodes))
  7615. (if (nth 3 rfloc)
  7616. (setcar (nthcdr 3 rfloc)
  7617. (move-marker (make-marker) (nth 3 rfloc)
  7618. (or (get-file-buffer (nth 1 rfloc))
  7619. (find-buffer-visiting (nth 1 rfloc))
  7620. (error "This should not happen")))))
  7621. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7622. redo-at-end t))
  7623. ((equal action ?t)
  7624. (setq state (org-icompleting-read
  7625. "Todo state: "
  7626. (with-current-buffer (marker-buffer (car entries))
  7627. (mapcar 'list org-todo-keywords-1))))
  7628. (setq cmd `(let ((org-inhibit-blocking t)
  7629. (org-inhibit-logging 'note))
  7630. (org-agenda-todo ,state))))
  7631. ((memq action '(?- ?+))
  7632. (setq tag (org-icompleting-read
  7633. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7634. (with-current-buffer (marker-buffer (car entries))
  7635. (delq nil
  7636. (mapcar (lambda (x)
  7637. (if (stringp (car x)) x)) org-tag-alist)))))
  7638. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7639. ((memq action '(?s ?d))
  7640. (let* ((date (unless arg
  7641. (org-read-date
  7642. nil nil nil
  7643. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7644. (ans (if arg nil org-read-date-final-answer))
  7645. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7646. (setq cmd `(let* ((bound (fboundp 'read-string))
  7647. (old (and bound (symbol-function 'read-string))))
  7648. (unwind-protect
  7649. (progn
  7650. (fset 'read-string (lambda (&rest ignore) ,ans))
  7651. (eval '(,c1 arg)))
  7652. (if bound
  7653. (fset 'read-string old)
  7654. (fmakunbound 'read-string)))))))
  7655. ((equal action ?S)
  7656. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7657. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7658. (let ((days (read-number
  7659. (format "Scatter tasks across how many %sdays: "
  7660. (if arg "week" "")) 7)))
  7661. (setq cmd
  7662. `(let ((distance (1+ (random ,days))))
  7663. (if arg
  7664. (let ((dist distance)
  7665. (day-of-week
  7666. (calendar-day-of-week
  7667. (calendar-gregorian-from-absolute (org-today)))))
  7668. (dotimes (i (1+ dist))
  7669. (while (member day-of-week org-agenda-weekend-days)
  7670. (incf distance)
  7671. (incf day-of-week)
  7672. (if (= day-of-week 7)
  7673. (setq day-of-week 0)))
  7674. (incf day-of-week)
  7675. (if (= day-of-week 7)
  7676. (setq day-of-week 0)))))
  7677. ;; silently fail when try to replan a sexp entry
  7678. (condition-case nil
  7679. (let* ((date (calendar-gregorian-from-absolute
  7680. (+ (org-today) distance)))
  7681. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7682. (nth 2 date))))
  7683. (org-agenda-schedule nil time))
  7684. (error nil)))))))
  7685. ((assoc action org-agenda-bulk-custom-functions)
  7686. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7687. redo-at-end t))
  7688. ((equal action ?f)
  7689. (setq cmd (list (intern
  7690. (org-icompleting-read "Function: "
  7691. obarray 'fboundp t nil nil)))))
  7692. (t (error "Invalid bulk action")))
  7693. ;; Sort the markers, to make sure that parents are handled before children
  7694. (setq entries (sort entries
  7695. (lambda (a b)
  7696. (cond
  7697. ((equal (marker-buffer a) (marker-buffer b))
  7698. (< (marker-position a) (marker-position b)))
  7699. (t
  7700. (string< (buffer-name (marker-buffer a))
  7701. (buffer-name (marker-buffer b))))))))
  7702. ;; Now loop over all markers and apply cmd
  7703. (while (setq e (pop entries))
  7704. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7705. (if (not pos)
  7706. (progn (message "Skipping removed entry at %s" e)
  7707. (setq cntskip (1+ cntskip)))
  7708. (goto-char pos)
  7709. (eval cmd)
  7710. (setq org-agenda-bulk-marked-entries
  7711. (delete e org-agenda-bulk-marked-entries))
  7712. (setq cnt (1+ cnt))))
  7713. (setq org-agenda-bulk-marked-entries nil)
  7714. (org-agenda-bulk-remove-all-marks)
  7715. (when redo-at-end (org-agenda-redo))
  7716. (message "Acted on %d entries%s"
  7717. cnt
  7718. (if (= cntskip 0)
  7719. ""
  7720. (format ", skipped %d (disappeared before their turn)"
  7721. cntskip)))))
  7722. ;;; Flagging notes
  7723. (defun org-agenda-show-the-flagging-note ()
  7724. "Display the flagging note in the other window.
  7725. When called a second time in direct sequence, offer to remove the FLAGGING
  7726. tag and (if present) the flagging note."
  7727. (interactive)
  7728. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7729. (win (selected-window))
  7730. note heading newhead)
  7731. (unless hdmarker
  7732. (error "No linked entry at point"))
  7733. (if (and (eq this-command last-command)
  7734. (y-or-n-p "Unflag and remove any flagging note? "))
  7735. (progn
  7736. (org-agenda-remove-flag hdmarker)
  7737. (let ((win (get-buffer-window "*Flagging Note*")))
  7738. (and win (delete-window win)))
  7739. (message "Entry unflaged"))
  7740. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7741. (unless note
  7742. (error "No flagging note"))
  7743. (org-kill-new note)
  7744. (org-switch-to-buffer-other-window "*Flagging Note*")
  7745. (erase-buffer)
  7746. (insert note)
  7747. (goto-char (point-min))
  7748. (while (re-search-forward "\\\\n" nil t)
  7749. (replace-match "\n" t t))
  7750. (goto-char (point-min))
  7751. (select-window win)
  7752. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7753. (defun org-agenda-remove-flag (marker)
  7754. "Remove the FLAGGED tag and any flagging note in the entry."
  7755. (let (newhead)
  7756. (org-with-point-at marker
  7757. (org-toggle-tag "FLAGGED" 'off)
  7758. (org-entry-delete nil "THEFLAGGINGNOTE")
  7759. (setq newhead (org-get-heading)))
  7760. (org-agenda-change-all-lines newhead marker)
  7761. (message "Entry unflaged")))
  7762. (defun org-agenda-get-any-marker (&optional pos)
  7763. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7764. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7765. ;;; Appointment reminders
  7766. (defvar appt-time-msg-list)
  7767. ;;;###autoload
  7768. (defun org-agenda-to-appt (&optional refresh filter)
  7769. "Activate appointments found in `org-agenda-files'.
  7770. With a \\[universal-argument] prefix, refresh the list of
  7771. appointments.
  7772. If FILTER is t, interactively prompt the user for a regular
  7773. expression, and filter out entries that don't match it.
  7774. If FILTER is a string, use this string as a regular expression
  7775. for filtering entries out.
  7776. FILTER can also be an alist with the car of each cell being
  7777. either 'headline or 'category. For example:
  7778. '((headline \"IMPORTANT\")
  7779. (category \"Work\"))
  7780. will only add headlines containing IMPORTANT or headlines
  7781. belonging to the \"Work\" category."
  7782. (interactive "P")
  7783. (if refresh (setq appt-time-msg-list nil))
  7784. (if (eq filter t)
  7785. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7786. (let* ((cnt 0) ; count added events
  7787. (org-agenda-new-buffers nil)
  7788. (org-deadline-warning-days 0)
  7789. ;; Do not use `org-today' here because appt only takes
  7790. ;; time and without date as argument, so it may pass wrong
  7791. ;; information otherwise
  7792. (today (org-date-to-gregorian
  7793. (time-to-days (current-time))))
  7794. (org-agenda-restrict nil)
  7795. (files (org-agenda-files 'unrestricted)) entries file)
  7796. ;; Get all entries which may contain an appt
  7797. (org-prepare-agenda-buffers files)
  7798. (while (setq file (pop files))
  7799. (setq entries
  7800. (append entries
  7801. (org-agenda-get-day-entries
  7802. file today :timestamp :scheduled :deadline))))
  7803. (setq entries (delq nil entries))
  7804. ;; Map thru entries and find if we should filter them out
  7805. (mapc
  7806. (lambda(x)
  7807. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7808. (cat (get-text-property 1 'org-category x))
  7809. (tod (get-text-property 1 'time-of-day x))
  7810. (ok (or (null filter)
  7811. (and (stringp filter) (string-match filter evt))
  7812. (and (listp filter)
  7813. (or (string-match
  7814. (cadr (assoc 'category filter)) cat)
  7815. (string-match
  7816. (cadr (assoc 'headline filter)) evt))))))
  7817. ;; FIXME: Shall we remove text-properties for the appt text?
  7818. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7819. (when (and ok tod)
  7820. (setq tod (concat "00" (number-to-string tod))
  7821. tod (when (string-match
  7822. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7823. (concat (match-string 1 tod) ":"
  7824. (match-string 2 tod))))
  7825. (appt-add tod evt)
  7826. (setq cnt (1+ cnt))))) entries)
  7827. (org-release-buffers org-agenda-new-buffers)
  7828. (if (eq cnt 0)
  7829. (message "No event to add")
  7830. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7831. (defun org-agenda-todayp (date)
  7832. "Does DATE mean today, when considering `org-extend-today-until'?"
  7833. (let ((today (org-today))
  7834. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7835. date)))
  7836. (eq date today)))
  7837. (provide 'org-agenda)
  7838. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7839. ;;; org-agenda.el ends here