org-agenda.el 324 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a conveniant way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function org-datetree-find-date-create "org-datetree"
  62. (date &optional keep-restriction))
  63. (declare-function org-columns-quit "org-colview" ())
  64. (declare-function diary-date-display-form "diary-lib" (&optional type))
  65. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  66. (declare-function org-habit-insert-consistency-graphs
  67. "org-habit" (&optional line))
  68. (declare-function org-is-habit-p "org-habit" (&optional pom))
  69. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  70. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  71. (declare-function org-pop-to-buffer-same-window "org-compat"
  72. (&optional buffer-or-name norecord label))
  73. (defvar calendar-mode-map)
  74. (defvar org-clock-current-task) ; defined in org-clock.el
  75. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  76. (defvar org-habit-show-habits)
  77. (defvar org-habit-show-habits-only-for-today)
  78. ;; Defined somewhere in this file, but used before definition.
  79. (defvar org-agenda-buffer-name)
  80. (defvar org-agenda-overriding-header)
  81. (defvar org-agenda-title-append nil)
  82. (defvar entry)
  83. (defvar date)
  84. (defvar org-agenda-undo-list)
  85. (defvar org-agenda-pending-undo-list)
  86. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  87. (defcustom org-agenda-confirm-kill 1
  88. "When set, remote killing from the agenda buffer needs confirmation.
  89. When t, a confirmation is always needed. When a number N, confirmation is
  90. only needed when the text to be killed contains more than N non-white lines."
  91. :group 'org-agenda
  92. :type '(choice
  93. (const :tag "Never" nil)
  94. (const :tag "Always" t)
  95. (integer :tag "When more than N lines")))
  96. (defcustom org-agenda-compact-blocks nil
  97. "Non-nil means make the block agenda more compact.
  98. This is done globally by leaving out lines like the agenda span
  99. name and week number or the separator lines."
  100. :group 'org-agenda
  101. :type 'boolean)
  102. (defcustom org-agenda-block-separator ?=
  103. "The separator between blocks in the agenda.
  104. If this is a string, it will be used as the separator, with a newline added.
  105. If it is a character, it will be repeated to fill the window width.
  106. If nil the separator is disabled. In `org-agenda-custom-commands' this
  107. addresses the separator between the current and the previous block."
  108. :group 'org-agenda
  109. :type '(choice
  110. (const :tag "Disabled" nil)
  111. (character)
  112. (string)))
  113. (defgroup org-agenda-export nil
  114. "Options concerning exporting agenda views in Org-mode."
  115. :tag "Org Agenda Export"
  116. :group 'org-agenda)
  117. (defcustom org-agenda-with-colors t
  118. "Non-nil means use colors in agenda views."
  119. :group 'org-agenda-export
  120. :type 'boolean)
  121. (defcustom org-agenda-exporter-settings nil
  122. "Alist of variable/value pairs that should be active during agenda export.
  123. This is a good place to set options for ps-print and for htmlize.
  124. Note that the way this is implemented, the values will be evaluated
  125. before assigned to the variables. So make sure to quote values you do
  126. *not* want evaluated, for example
  127. (setq org-agenda-exporter-settings
  128. '((ps-print-color-p 'black-white)))"
  129. :group 'org-agenda-export
  130. :type '(repeat
  131. (list
  132. (variable)
  133. (sexp :tag "Value"))))
  134. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  135. "Hook run in temporary buffer before writing it to an export file.
  136. A useful function is `org-agenda-add-entry-text'."
  137. :group 'org-agenda-export
  138. :type 'hook
  139. :options '(org-agenda-add-entry-text))
  140. (defcustom org-agenda-add-entry-text-maxlines 0
  141. "Maximum number of entry text lines to be added to agenda.
  142. This is only relevant when `org-agenda-add-entry-text' is part of
  143. `org-agenda-before-write-hook', which it is by default.
  144. When this is 0, nothing will happen. When it is greater than 0, it
  145. specifies the maximum number of lines that will be added for each entry
  146. that is listed in the agenda view.
  147. Note that this variable is not used during display, only when exporting
  148. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  149. and `org-agenda-entry-text-maxlines'."
  150. :group 'org-agenda
  151. :type 'integer)
  152. (defcustom org-agenda-add-entry-text-descriptive-links t
  153. "Non-nil means export org-links as descriptive links in agenda added text.
  154. This variable applies to the text added to the agenda when
  155. `org-agenda-add-entry-text-maxlines' is larger than 0.
  156. When this variable nil, the URL will (also) be shown."
  157. :group 'org-agenda
  158. :type 'boolean)
  159. (defcustom org-agenda-export-html-style ""
  160. "The style specification for exported HTML Agenda files.
  161. If this variable contains a string, it will replace the default <style>
  162. section as produced by `htmlize'.
  163. Since there are different ways of setting style information, this variable
  164. needs to contain the full HTML structure to provide a style, including the
  165. surrounding HTML tags. The style specifications should include definitions
  166. the fonts used by the agenda, here is an example:
  167. <style type=\"text/css\">
  168. p { font-weight: normal; color: gray; }
  169. .org-agenda-structure {
  170. font-size: 110%;
  171. color: #003399;
  172. font-weight: 600;
  173. }
  174. .org-todo {
  175. color: #cc6666;
  176. font-weight: bold;
  177. }
  178. .org-agenda-done {
  179. color: #339933;
  180. }
  181. .org-done {
  182. color: #339933;
  183. }
  184. .title { text-align: center; }
  185. .todo, .deadline { color: red; }
  186. .done { color: green; }
  187. </style>
  188. or, if you want to keep the style in a file,
  189. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  190. As the value of this option simply gets inserted into the HTML <head> header,
  191. you can \"misuse\" it to also add other text to the header. However,
  192. <style>...</style> is required, if not present the variable will be ignored."
  193. :group 'org-agenda-export
  194. :group 'org-export-html
  195. :type 'string)
  196. (defcustom org-agenda-persistent-filter nil
  197. "When set, keep filters from one agenda view to the next."
  198. :group 'org-agenda
  199. :type 'boolean)
  200. (defgroup org-agenda-custom-commands nil
  201. "Options concerning agenda views in Org-mode."
  202. :tag "Org Agenda Custom Commands"
  203. :group 'org-agenda)
  204. (defconst org-sorting-choice
  205. '(choice
  206. (const time-up) (const time-down)
  207. (const category-keep) (const category-up) (const category-down)
  208. (const tag-down) (const tag-up)
  209. (const priority-up) (const priority-down)
  210. (const todo-state-up) (const todo-state-down)
  211. (const effort-up) (const effort-down)
  212. (const habit-up) (const habit-down)
  213. (const alpha-up) (const alpha-down)
  214. (const user-defined-up) (const user-defined-down))
  215. "Sorting choices.")
  216. (defconst org-agenda-custom-commands-local-options
  217. `(repeat :tag "Local settings for this command. Remember to quote values"
  218. (choice :tag "Setting"
  219. (list :tag "Heading for this block"
  220. (const org-agenda-overriding-header)
  221. (string :tag "Headline"))
  222. (list :tag "Files to be searched"
  223. (const org-agenda-files)
  224. (list
  225. (const :format "" quote)
  226. (repeat (file))))
  227. (list :tag "Sorting strategy"
  228. (const org-agenda-sorting-strategy)
  229. (list
  230. (const :format "" quote)
  231. (repeat
  232. ,org-sorting-choice)))
  233. (list :tag "Prefix format"
  234. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  235. (string))
  236. (list :tag "Number of days in agenda"
  237. (const org-agenda-span)
  238. (choice (const :tag "Day" 'day)
  239. (const :tag "Week" 'week)
  240. (const :tag "Month" 'month)
  241. (const :tag "Year" 'year)
  242. (integer :tag "Custom")))
  243. (list :tag "Fixed starting date"
  244. (const org-agenda-start-day)
  245. (string :value "2007-11-01"))
  246. (list :tag "Start on day of week"
  247. (const org-agenda-start-on-weekday)
  248. (choice :value 1
  249. (const :tag "Today" nil)
  250. (integer :tag "Weekday No.")))
  251. (list :tag "Include data from diary"
  252. (const org-agenda-include-diary)
  253. (boolean))
  254. (list :tag "Deadline Warning days"
  255. (const org-deadline-warning-days)
  256. (integer :value 1))
  257. (list :tag "Tags filter preset"
  258. (const org-agenda-filter-preset)
  259. (list
  260. (const :format "" quote)
  261. (repeat
  262. (string :tag "+tag or -tag"))))
  263. (list :tag "Set daily/weekly entry types"
  264. (const org-agenda-entry-types)
  265. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  266. (const :deadline)
  267. (const :scheduled)
  268. (const :timestamp)
  269. (const :sexp)))
  270. (list :tag "Standard skipping condition"
  271. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  272. (const org-agenda-skip-function)
  273. (list
  274. (const :format "" quote)
  275. (list
  276. (choice
  277. :tag "Skipping range"
  278. (const :tag "Skip entry" org-agenda-skip-entry-if)
  279. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  280. (repeat :inline t :tag "Conditions for skipping"
  281. (choice
  282. :tag "Condition type"
  283. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  284. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  285. (list :tag "TODO state is" :inline t
  286. (const 'todo)
  287. (choice
  288. (const :tag "any not-done state" 'todo)
  289. (const :tag "any done state" 'done)
  290. (const :tag "any state" 'any)
  291. (list :tag "Keyword list"
  292. (const :format "" quote)
  293. (repeat (string :tag "Keyword")))))
  294. (list :tag "TODO state is not" :inline t
  295. (const 'nottodo)
  296. (choice
  297. (const :tag "any not-done state" 'todo)
  298. (const :tag "any done state" 'done)
  299. (const :tag "any state" 'any)
  300. (list :tag "Keyword list"
  301. (const :format "" quote)
  302. (repeat (string :tag "Keyword")))))
  303. (const :tag "scheduled" 'scheduled)
  304. (const :tag "not scheduled" 'notscheduled)
  305. (const :tag "deadline" 'deadline)
  306. (const :tag "no deadline" 'notdeadline)
  307. (const :tag "timestamp" 'timestamp)
  308. (const :tag "no timestamp" 'nottimestamp))))))
  309. (list :tag "Non-standard skipping condition"
  310. :value (org-agenda-skip-function)
  311. (const org-agenda-skip-function)
  312. (sexp :tag "Function or form (quoted!)"))
  313. (list :tag "Any variable"
  314. (variable :tag "Variable")
  315. (sexp :tag "Value (sexp)"))))
  316. "Selection of examples for agenda command settings.
  317. This will be spliced into the custom type of
  318. `org-agenda-custom-commands'.")
  319. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  320. ((agenda "") (alltodo))))
  321. "Custom commands for the agenda.
  322. These commands will be offered on the splash screen displayed by the
  323. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  324. (key desc type match settings files)
  325. key The key (one or more characters as a string) to be associated
  326. with the command.
  327. desc A description of the command, when omitted or nil, a default
  328. description is built using MATCH.
  329. type The command type, any of the following symbols:
  330. agenda The daily/weekly agenda.
  331. todo Entries with a specific TODO keyword, in all agenda files.
  332. search Entries containing search words entry or headline.
  333. tags Tags/Property/TODO match in all agenda files.
  334. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  335. todo-tree Sparse tree of specific TODO keyword in *current* file.
  336. tags-tree Sparse tree with all tags matches in *current* file.
  337. occur-tree Occur sparse tree for *current* file.
  338. ... A user-defined function.
  339. match What to search for:
  340. - a single keyword for TODO keyword searches
  341. - a tags match expression for tags searches
  342. - a word search expression for text searches.
  343. - a regular expression for occur searches
  344. For all other commands, this should be the empty string.
  345. settings A list of option settings, similar to that in a let form, so like
  346. this: ((opt1 val1) (opt2 val2) ...). The values will be
  347. evaluated at the moment of execution, so quote them when needed.
  348. files A list of files file to write the produced agenda buffer to
  349. with the command `org-store-agenda-views'.
  350. If a file name ends in \".html\", an HTML version of the buffer
  351. is written out. If it ends in \".ps\", a postscript version is
  352. produced. Otherwise, only the plain text is written to the file.
  353. You can also define a set of commands, to create a composite agenda buffer.
  354. In this case, an entry looks like this:
  355. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  356. where
  357. desc A description string to be displayed in the dispatcher menu.
  358. cmd An agenda command, similar to the above. However, tree commands
  359. are no allowed, but instead you can get agenda and global todo list.
  360. So valid commands for a set are:
  361. (agenda \"\" settings)
  362. (alltodo \"\" settings)
  363. (stuck \"\" settings)
  364. (todo \"match\" settings files)
  365. (search \"match\" settings files)
  366. (tags \"match\" settings files)
  367. (tags-todo \"match\" settings files)
  368. Each command can carry a list of options, and another set of options can be
  369. given for the whole set of commands. Individual command options take
  370. precedence over the general options.
  371. When using several characters as key to a command, the first characters
  372. are prefix commands. For the dispatcher to display useful information, you
  373. should provide a description for the prefix, like
  374. (setq org-agenda-custom-commands
  375. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  376. (\"hl\" tags \"+HOME+Lisa\")
  377. (\"hp\" tags \"+HOME+Peter\")
  378. (\"hk\" tags \"+HOME+Kim\")))"
  379. :group 'org-agenda-custom-commands
  380. :type `(repeat
  381. (choice :value ("x" "Describe command here" tags "" nil)
  382. (list :tag "Single command"
  383. (string :tag "Access Key(s) ")
  384. (option (string :tag "Description"))
  385. (choice
  386. (const :tag "Agenda" agenda)
  387. (const :tag "TODO list" alltodo)
  388. (const :tag "Search words" search)
  389. (const :tag "Stuck projects" stuck)
  390. (const :tag "Tags/Property match (all agenda files)" tags)
  391. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  392. (const :tag "TODO keyword search (all agenda files)" todo)
  393. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  394. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  395. (const :tag "Occur tree (current buffer)" occur-tree)
  396. (sexp :tag "Other, user-defined function"))
  397. (string :tag "Match (only for some commands)")
  398. ,org-agenda-custom-commands-local-options
  399. (option (repeat :tag "Export" (file :tag "Export to"))))
  400. (list :tag "Command series, all agenda files"
  401. (string :tag "Access Key(s)")
  402. (string :tag "Description ")
  403. (repeat :tag "Component"
  404. (choice
  405. (list :tag "Agenda"
  406. (const :format "" agenda)
  407. (const :tag "" :format "" "")
  408. ,org-agenda-custom-commands-local-options)
  409. (list :tag "TODO list (all keywords)"
  410. (const :format "" alltodo)
  411. (const :tag "" :format "" "")
  412. ,org-agenda-custom-commands-local-options)
  413. (list :tag "Search words"
  414. (const :format "" search)
  415. (string :tag "Match")
  416. ,org-agenda-custom-commands-local-options)
  417. (list :tag "Stuck projects"
  418. (const :format "" stuck)
  419. (const :tag "" :format "" "")
  420. ,org-agenda-custom-commands-local-options)
  421. (list :tag "Tags search"
  422. (const :format "" tags)
  423. (string :tag "Match")
  424. ,org-agenda-custom-commands-local-options)
  425. (list :tag "Tags search, TODO entries only"
  426. (const :format "" tags-todo)
  427. (string :tag "Match")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO keyword search"
  430. (const :format "" todo)
  431. (string :tag "Match")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Other, user-defined function"
  434. (symbol :tag "function")
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)))
  437. (repeat :tag "Settings for entire command set"
  438. (list (variable :tag "Any variable")
  439. (sexp :tag "Value")))
  440. (option (repeat :tag "Export" (file :tag "Export to"))))
  441. (cons :tag "Prefix key documentation"
  442. (string :tag "Access Key(s)")
  443. (string :tag "Description ")))))
  444. (defcustom org-agenda-query-register ?o
  445. "The register holding the current query string.
  446. The purpose of this is that if you construct a query string interactively,
  447. you can then use it to define a custom command."
  448. :group 'org-agenda-custom-commands
  449. :type 'character)
  450. (defcustom org-stuck-projects
  451. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  452. "How to identify stuck projects.
  453. This is a list of four items:
  454. 1. A tags/todo/property matcher string that is used to identify a project.
  455. See the manual for a description of tag and property searches.
  456. The entire tree below a headline matched by this is considered one project.
  457. 2. A list of TODO keywords identifying non-stuck projects.
  458. If the project subtree contains any headline with one of these todo
  459. keywords, the project is considered to be not stuck. If you specify
  460. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  461. 3. A list of tags identifying non-stuck projects.
  462. If the project subtree contains any headline with one of these tags,
  463. the project is considered to be not stuck. If you specify \"*\" as
  464. a tag, any tag will mark the project unstuck. Note that this is about
  465. the explicit presence of a tag somewhere in the subtree, inherited
  466. tags to not count here. If inherited tags make a project not stuck,
  467. use \"-TAG\" in the tags part of the matcher under (1.) above.
  468. 4. An arbitrary regular expression matching non-stuck projects.
  469. If the project turns out to be not stuck, search continues also in the
  470. subtree to see if any of the subtasks have project status.
  471. See also the variable `org-tags-match-list-sublevels' which applies
  472. to projects matched by this search as well.
  473. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  474. or `C-c a #' to produce the list."
  475. :group 'org-agenda-custom-commands
  476. :type '(list
  477. (string :tag "Tags/TODO match to identify a project")
  478. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  479. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  480. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  481. (defcustom org-agenda-filter-effort-default-operator "<"
  482. "The default operator for effort estimate filtering.
  483. If you select an effort estimate limit without first pressing an operator,
  484. this one will be used."
  485. :group 'org-agenda-custom-commands
  486. :type '(choice (const :tag "less or equal" "<")
  487. (const :tag "greater or equal"">")
  488. (const :tag "equal" "=")))
  489. (defgroup org-agenda-skip nil
  490. "Options concerning skipping parts of agenda files."
  491. :tag "Org Agenda Skip"
  492. :group 'org-agenda)
  493. (defcustom org-agenda-skip-function-global nil
  494. "Function to be called at each match during agenda construction.
  495. If this function returns nil, the current match should not be skipped.
  496. If the function decided to skip an agenda match, is must return the
  497. buffer position from which the search should be continued.
  498. This may also be a Lisp form, which will be evaluated.
  499. This variable will be applied to every agenda match, including
  500. tags/property searches and TODO lists. So try to make the test function
  501. do its checking as efficiently as possible. To implement a skipping
  502. condition just for specific agenda commands, use the variable
  503. `org-agenda-skip-function' which can be set in the options section
  504. of custom agenda commands."
  505. :group 'org-agenda-skip
  506. :type 'sexp)
  507. (defgroup org-agenda-daily/weekly nil
  508. "Options concerning the daily/weekly agenda."
  509. :tag "Org Agenda Daily/Weekly"
  510. :group 'org-agenda)
  511. (defgroup org-agenda-todo-list nil
  512. "Options concerning the global todo list agenda view."
  513. :tag "Org Agenda Todo List"
  514. :group 'org-agenda)
  515. (defgroup org-agenda-match-view nil
  516. "Options concerning the general tags/property/todo match agenda view."
  517. :tag "Org Agenda Match View"
  518. :group 'org-agenda)
  519. (defgroup org-agenda-search-view nil
  520. "Options concerning the general tags/property/todo match agenda view."
  521. :tag "Org Agenda Match View"
  522. :group 'org-agenda)
  523. (defvar org-agenda-archives-mode nil
  524. "Non-nil means the agenda will include archived items.
  525. If this is the symbol `trees', trees in the selected agenda scope
  526. that are marked with the ARCHIVE tag will be included anyway. When this is
  527. t, also all archive files associated with the current selection of agenda
  528. files will be included.")
  529. (defcustom org-agenda-skip-comment-trees t
  530. "Non-nil means skip trees that start with the COMMENT keyword.
  531. When nil, these trees are also scanned by agenda commands."
  532. :group 'org-agenda-skip
  533. :type 'boolean)
  534. (defcustom org-agenda-todo-list-sublevels t
  535. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  536. When nil, the sublevels of a TODO entry are not checked, resulting in
  537. potentially much shorter TODO lists."
  538. :group 'org-agenda-skip
  539. :group 'org-agenda-todo-list
  540. :type 'boolean)
  541. (defcustom org-agenda-todo-ignore-with-date nil
  542. "Non-nil means don't show entries with a date in the global todo list.
  543. You can use this if you prefer to mark mere appointments with a TODO keyword,
  544. but don't want them to show up in the TODO list.
  545. When this is set, it also covers deadlines and scheduled items, the settings
  546. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  547. will be ignored.
  548. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  549. :group 'org-agenda-skip
  550. :group 'org-agenda-todo-list
  551. :type 'boolean)
  552. (defcustom org-agenda-todo-ignore-timestamp nil
  553. "Non-nil means don't show entries with a timestamp.
  554. This applies when creating the global todo list.
  555. Valid values are:
  556. past Don't show entries for today or in the past.
  557. future Don't show entries with a timestamp in the future.
  558. The idea behind this is that if it has a future
  559. timestamp, you don't want to think about it until the
  560. date.
  561. all Don't show any entries with a timestamp in the global todo list.
  562. The idea behind this is that by setting a timestamp, you
  563. have already \"taken care\" of this item.
  564. This variable can also have an integer as a value. If positive (N),
  565. todos with a timestamp N or more days in the future will be ignored. If
  566. negative (-N), todos with a timestamp N or more days in the past will be
  567. ignored. If 0, todos with a timestamp either today or in the future will
  568. be ignored. For example, a value of -1 will exclude todos with a
  569. timestamp in the past (yesterday or earlier), while a value of 7 will
  570. exclude todos with a timestamp a week or more in the future.
  571. See also `org-agenda-todo-ignore-with-date'.
  572. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  573. to make his option also apply to the tags-todo list."
  574. :group 'org-agenda-skip
  575. :group 'org-agenda-todo-list
  576. :type '(choice
  577. (const :tag "Ignore future timestamp todos" future)
  578. (const :tag "Ignore past or present timestamp todos" past)
  579. (const :tag "Ignore all timestamp todos" all)
  580. (const :tag "Show timestamp todos" nil)
  581. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  582. (defcustom org-agenda-todo-ignore-scheduled nil
  583. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  584. This applies when creating the global todo list.
  585. Valid values are:
  586. past Don't show entries scheduled today or in the past.
  587. future Don't show entries scheduled in the future.
  588. The idea behind this is that by scheduling it, you don't want to
  589. think about it until the scheduled date.
  590. all Don't show any scheduled entries in the global todo list.
  591. The idea behind this is that by scheduling it, you have already
  592. \"taken care\" of this item.
  593. t Same as `all', for backward compatibility.
  594. This variable can also have an integer as a value. See
  595. `org-agenda-todo-ignore-timestamp' for more details.
  596. See also `org-agenda-todo-ignore-with-date'.
  597. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  598. to make his option also apply to the tags-todo list."
  599. :group 'org-agenda-skip
  600. :group 'org-agenda-todo-list
  601. :type '(choice
  602. (const :tag "Ignore future-scheduled todos" future)
  603. (const :tag "Ignore past- or present-scheduled todos" past)
  604. (const :tag "Ignore all scheduled todos" all)
  605. (const :tag "Ignore all scheduled todos (compatibility)" t)
  606. (const :tag "Show scheduled todos" nil)
  607. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  608. (defcustom org-agenda-todo-ignore-deadlines nil
  609. "Non-nil means ignore some deadlined TODO items when making TODO list.
  610. There are different motivations for using different values, please think
  611. carefully when configuring this variable.
  612. This applies when creating the global todo list.
  613. Valid values are:
  614. near Don't show near deadline entries. A deadline is near when it is
  615. closer than `org-deadline-warning-days' days. The idea behind this
  616. is that such items will appear in the agenda anyway.
  617. far Don't show TODO entries where a deadline has been defined, but
  618. the deadline is not near. This is useful if you don't want to
  619. use the todo list to figure out what to do now.
  620. past Don't show entries with a deadline timestamp for today or in the past.
  621. future Don't show entries with a deadline timestamp in the future, not even
  622. when they become `near' ones. Use it with caution.
  623. all Ignore all TODO entries that do have a deadline.
  624. t Same as `near', for backward compatibility.
  625. This variable can also have an integer as a value. See
  626. `org-agenda-todo-ignore-timestamp' for more details.
  627. See also `org-agenda-todo-ignore-with-date'.
  628. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  629. to make his option also apply to the tags-todo list."
  630. :group 'org-agenda-skip
  631. :group 'org-agenda-todo-list
  632. :type '(choice
  633. (const :tag "Ignore near deadlines" near)
  634. (const :tag "Ignore near deadlines (compatibility)" t)
  635. (const :tag "Ignore far deadlines" far)
  636. (const :tag "Ignore all TODOs with a deadlines" all)
  637. (const :tag "Show all TODOs, even if they have a deadline" nil)
  638. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  639. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  640. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  641. The variables
  642. `org-agenda-todo-ignore-with-date',
  643. `org-agenda-todo-ignore-timestamp',
  644. `org-agenda-todo-ignore-scheduled',
  645. `org-agenda-todo-ignore-deadlines'
  646. make the global TODO list skip entries that have time stamps of certain
  647. kinds. If this option is set, the same options will also apply for the
  648. tags-todo search, which is the general tags/property matcher
  649. restricted to unfinished TODO entries only."
  650. :group 'org-agenda-skip
  651. :group 'org-agenda-todo-list
  652. :group 'org-agenda-match-view
  653. :type 'boolean)
  654. (defcustom org-agenda-skip-scheduled-if-done nil
  655. "Non-nil means don't show scheduled items in agenda when they are done.
  656. This is relevant for the daily/weekly agenda, not for the TODO list. And
  657. it applies only to the actual date of the scheduling. Warnings about
  658. an item with a past scheduling dates are always turned off when the item
  659. is DONE."
  660. :group 'org-agenda-skip
  661. :group 'org-agenda-daily/weekly
  662. :type 'boolean)
  663. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  664. "Non-nil means skip scheduling line if same entry shows because of deadline.
  665. In the agenda of today, an entry can show up multiple times because
  666. it is both scheduled and has a nearby deadline, and maybe a plain time
  667. stamp as well.
  668. When this variable is t, then only the deadline is shown and the fact that
  669. the entry is scheduled today or was scheduled previously is not shown.
  670. When this variable is nil, the entry will be shown several times. When
  671. the variable is the symbol `not-today', then skip scheduled previously,
  672. but not scheduled today."
  673. :group 'org-agenda-skip
  674. :group 'org-agenda-daily/weekly
  675. :type '(choice
  676. (const :tag "Never" nil)
  677. (const :tag "Always" t)
  678. (const :tag "Not when scheduled today" not-today)))
  679. (defcustom org-agenda-skip-deadline-if-done nil
  680. "Non-nil means don't show deadlines when the corresponding item is done.
  681. When nil, the deadline is still shown and should give you a happy feeling.
  682. This is relevant for the daily/weekly agenda. And it applied only to the
  683. actually date of the deadline. Warnings about approaching and past-due
  684. deadlines are always turned off when the item is DONE."
  685. :group 'org-agenda-skip
  686. :group 'org-agenda-daily/weekly
  687. :type 'boolean)
  688. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  689. "Non-nil means skip deadline prewarning when entry is also scheduled.
  690. This will apply on all days where a prewarning for the deadline would
  691. be shown, but not at the day when the entry is actually due. On that day,
  692. the deadline will be shown anyway.
  693. This variable may be set to nil, t, or a number which will then give
  694. the number of days before the actual deadline when the prewarnings
  695. should resume.
  696. This can be used in a workflow where the first showing of the deadline will
  697. trigger you to schedule it, and then you don't want to be reminded of it
  698. because you will take care of it on the day when scheduled."
  699. :group 'org-agenda-skip
  700. :group 'org-agenda-daily/weekly
  701. :type '(choice
  702. (const :tag "Alwas show prewarning" nil)
  703. (const :tag "Remove prewarning if entry is scheduled" t)
  704. (integer :tag "Restart prewarning N days before deadline")))
  705. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  706. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  707. When non-nil, after the search for timestamps has matched once in an
  708. entry, the rest of the entry will not be searched."
  709. :group 'org-agenda-skip
  710. :type 'boolean)
  711. (defcustom org-agenda-skip-timestamp-if-done nil
  712. "Non-nil means don't select item by timestamp or -range if it is DONE."
  713. :group 'org-agenda-skip
  714. :group 'org-agenda-daily/weekly
  715. :type 'boolean)
  716. (defcustom org-agenda-dim-blocked-tasks t
  717. "Non-nil means dim blocked tasks in the agenda display.
  718. This causes some overhead during agenda construction, but if you
  719. have turned on `org-enforce-todo-dependencies',
  720. `org-enforce-todo-checkbox-dependencies', or any other blocking
  721. mechanism, this will create useful feedback in the agenda.
  722. Instead of t, this variable can also have the value `invisible'.
  723. Then blocked tasks will be invisible and only become visible when
  724. they become unblocked. An exemption to this behavior is when a task is
  725. blocked because of unchecked checkboxes below it. Since checkboxes do
  726. not show up in the agenda views, making this task invisible you remove any
  727. trace from agenda views that there is something to do. Therefore, a task
  728. that is blocked because of checkboxes will never be made invisible, it
  729. will only be dimmed."
  730. :group 'org-agenda-daily/weekly
  731. :group 'org-agenda-todo-list
  732. :type '(choice
  733. (const :tag "Do not dim" nil)
  734. (const :tag "Dim to a grey face" t)
  735. (const :tag "Make invisible" invisible)))
  736. (defcustom org-timeline-show-empty-dates 3
  737. "Non-nil means `org-timeline' also shows dates without an entry.
  738. When nil, only the days which actually have entries are shown.
  739. When t, all days between the first and the last date are shown.
  740. When an integer, show also empty dates, but if there is a gap of more than
  741. N days, just insert a special line indicating the size of the gap."
  742. :group 'org-agenda-skip
  743. :type '(choice
  744. (const :tag "None" nil)
  745. (const :tag "All" t)
  746. (integer :tag "at most")))
  747. (defgroup org-agenda-startup nil
  748. "Options concerning initial settings in the Agenda in Org Mode."
  749. :tag "Org Agenda Startup"
  750. :group 'org-agenda)
  751. (defcustom org-agenda-menu-show-matcher t
  752. "Non-nil means show the match string in the agenda dispatcher menu.
  753. When nil, the matcher string is not shown, but is put into the help-echo
  754. property so than moving the mouse over the command shows it.
  755. Setting it to nil is good if matcher strings are very long and/or if
  756. you want to use two-column display (see `org-agenda-menu-two-column')."
  757. :group 'org-agenda
  758. :type 'boolean)
  759. (defcustom org-agenda-menu-two-column nil
  760. "Non-nil means, use two columns to show custom commands in the dispatcher.
  761. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  762. to nil."
  763. :group 'org-agenda
  764. :type 'boolean)
  765. (defcustom org-finalize-agenda-hook nil
  766. "Hook run just before displaying an agenda buffer."
  767. :group 'org-agenda-startup
  768. :type 'hook)
  769. (defcustom org-agenda-mouse-1-follows-link nil
  770. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  771. A longer mouse click will still set point. Does not work on XEmacs.
  772. Needs to be set before org.el is loaded."
  773. :group 'org-agenda-startup
  774. :type 'boolean)
  775. (defcustom org-agenda-start-with-follow-mode nil
  776. "The initial value of follow mode in a newly created agenda window."
  777. :group 'org-agenda-startup
  778. :type 'boolean)
  779. (defcustom org-agenda-follow-indirect nil
  780. "Non-nil means `org-agenda-follow-mode' displays only the
  781. current item's tree, in an indirect buffer."
  782. :group 'org-agenda
  783. :type 'boolean)
  784. (defcustom org-agenda-show-outline-path t
  785. "Non-nil means show outline path in echo area after line motion."
  786. :group 'org-agenda-startup
  787. :type 'boolean)
  788. (defcustom org-agenda-start-with-entry-text-mode nil
  789. "The initial value of entry-text-mode in a newly created agenda window."
  790. :group 'org-agenda-startup
  791. :type 'boolean)
  792. (defcustom org-agenda-entry-text-maxlines 5
  793. "Number of text lines to be added when `E' is pressed in the agenda.
  794. Note that this variable only used during agenda display. Add add entry text
  795. when exporting the agenda, configure the variable
  796. `org-agenda-add-entry-ext-maxlines'."
  797. :group 'org-agenda
  798. :type 'integer)
  799. (defcustom org-agenda-entry-text-exclude-regexps nil
  800. "List of regular expressions to clean up entry text.
  801. The complete matches of all regular expressions in this list will be
  802. removed from entry text before it is shown in the agenda."
  803. :group 'org-agenda
  804. :type '(repeat (regexp)))
  805. (defvar org-agenda-entry-text-cleanup-hook nil
  806. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  807. This cleanup is done in a temporary buffer, so the function may inspect and
  808. change the entire buffer.
  809. Some default stuff like drawers and scheduling/deadline dates will already
  810. have been removed when this is called, as will any matches for regular
  811. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  812. (defvar org-agenda-include-inactive-timestamps nil
  813. "Non-nil means include inactive time stamps in agenda and timeline.")
  814. (defgroup org-agenda-windows nil
  815. "Options concerning the windows used by the Agenda in Org Mode."
  816. :tag "Org Agenda Windows"
  817. :group 'org-agenda)
  818. (defcustom org-agenda-window-setup 'reorganize-frame
  819. "How the agenda buffer should be displayed.
  820. Possible values for this option are:
  821. current-window Show agenda in the current window, keeping all other windows.
  822. other-window Use `switch-to-buffer-other-window' to display agenda.
  823. reorganize-frame Show only two windows on the current frame, the current
  824. window and the agenda.
  825. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  826. Also, when exiting the agenda, kill that frame.
  827. See also the variable `org-agenda-restore-windows-after-quit'."
  828. :group 'org-agenda-windows
  829. :type '(choice
  830. (const current-window)
  831. (const other-frame)
  832. (const other-window)
  833. (const reorganize-frame)))
  834. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  835. "The min and max height of the agenda window as a fraction of frame height.
  836. The value of the variable is a cons cell with two numbers between 0 and 1.
  837. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  838. :group 'org-agenda-windows
  839. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  840. (defcustom org-agenda-restore-windows-after-quit nil
  841. "Non-nil means restore window configuration upon exiting agenda.
  842. Before the window configuration is changed for displaying the agenda,
  843. the current status is recorded. When the agenda is exited with
  844. `q' or `x' and this option is set, the old state is restored. If
  845. `org-agenda-window-setup' is `other-frame', the value of this
  846. option will be ignored."
  847. :group 'org-agenda-windows
  848. :type 'boolean)
  849. (defcustom org-agenda-ndays nil
  850. "Number of days to include in overview display.
  851. Should be 1 or 7.
  852. Obsolete, see `org-agenda-span'."
  853. :group 'org-agenda-daily/weekly
  854. :type 'integer)
  855. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  856. (defcustom org-agenda-span 'week
  857. "Number of days to include in overview display.
  858. Can be day, week, month, year, or any number of days.
  859. Custom commands can set this variable in the options section."
  860. :group 'org-agenda-daily/weekly
  861. :type '(choice (const :tag "Day" day)
  862. (const :tag "Week" week)
  863. (const :tag "Month" month)
  864. (const :tag "Year" year)
  865. (integer :tag "Custom")))
  866. (defcustom org-agenda-start-on-weekday 1
  867. "Non-nil means start the overview always on the specified weekday.
  868. 0 denotes Sunday, 1 denotes Monday etc.
  869. When nil, always start on the current day.
  870. Custom commands can set this variable in the options section."
  871. :group 'org-agenda-daily/weekly
  872. :type '(choice (const :tag "Today" nil)
  873. (integer :tag "Weekday No.")))
  874. (defcustom org-agenda-show-all-dates t
  875. "Non-nil means `org-agenda' shows every day in the selected range.
  876. When nil, only the days which actually have entries are shown."
  877. :group 'org-agenda-daily/weekly
  878. :type 'boolean)
  879. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  880. "Format string for displaying dates in the agenda.
  881. Used by the daily/weekly agenda and by the timeline. This should be
  882. a format string understood by `format-time-string', or a function returning
  883. the formatted date as a string. The function must take a single argument,
  884. a calendar-style date list like (month day year)."
  885. :group 'org-agenda-daily/weekly
  886. :type '(choice
  887. (string :tag "Format string")
  888. (function :tag "Function")))
  889. (defun org-agenda-format-date-aligned (date)
  890. "Format a date string for display in the daily/weekly agenda, or timeline.
  891. This function makes sure that dates are aligned for easy reading."
  892. (require 'cal-iso)
  893. (let* ((dayname (calendar-day-name date))
  894. (day (cadr date))
  895. (day-of-week (calendar-day-of-week date))
  896. (month (car date))
  897. (monthname (calendar-month-name month))
  898. (year (nth 2 date))
  899. (iso-week (org-days-to-iso-week
  900. (calendar-absolute-from-gregorian date)))
  901. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  902. (1- year))
  903. ((and (= month 12) (<= iso-week 1))
  904. (1+ year))
  905. (t year)))
  906. (weekstring (if (= day-of-week 1)
  907. (format " W%02d" iso-week)
  908. "")))
  909. (format "%-10s %2d %s %4d%s"
  910. dayname day monthname year weekstring)))
  911. (defcustom org-agenda-time-leading-zero nil
  912. "Non-nil means use leading zero for military times in agenda.
  913. For example, 9:30am would become 09:30 rather than 9:30."
  914. :group 'org-agenda-daily/weekly
  915. :type 'boolean)
  916. (defcustom org-agenda-timegrid-use-ampm nil
  917. "When set, show AM/PM style timestamps on the timegrid."
  918. :group 'org-agenda
  919. :type 'boolean)
  920. (defun org-agenda-time-of-day-to-ampm (time)
  921. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  922. (let* ((hour-number (string-to-number (substring time 0 -3)))
  923. (minute (substring time -2))
  924. (ampm "am"))
  925. (cond
  926. ((equal hour-number 12)
  927. (setq ampm "pm"))
  928. ((> hour-number 12)
  929. (setq ampm "pm")
  930. (setq hour-number (- hour-number 12))))
  931. (concat
  932. (if org-agenda-time-leading-zero
  933. (format "%02d" hour-number)
  934. (format "%02s" (number-to-string hour-number)))
  935. ":" minute ampm)))
  936. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  937. "Conditionally convert TIME to AM/PM format
  938. based on `org-agenda-timegrid-use-ampm'"
  939. (if org-agenda-timegrid-use-ampm
  940. (org-agenda-time-of-day-to-ampm time)
  941. time))
  942. (defcustom org-agenda-weekend-days '(6 0)
  943. "Which days are weekend?
  944. These days get the special face `org-agenda-date-weekend' in the agenda
  945. and timeline buffers."
  946. :group 'org-agenda-daily/weekly
  947. :type '(set :greedy t
  948. (const :tag "Monday" 1)
  949. (const :tag "Tuesday" 2)
  950. (const :tag "Wednesday" 3)
  951. (const :tag "Thursday" 4)
  952. (const :tag "Friday" 5)
  953. (const :tag "Saturday" 6)
  954. (const :tag "Sunday" 0)))
  955. (defcustom org-agenda-include-diary nil
  956. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  957. Custom commands can set this variable in the options section."
  958. :group 'org-agenda-daily/weekly
  959. :type 'boolean)
  960. (defcustom org-agenda-include-deadlines t
  961. "If non-nil, include entries within their deadline warning period.
  962. Custom commands can set this variable in the options section."
  963. :group 'org-agenda-daily/weekly
  964. :type 'boolean)
  965. (defcustom org-agenda-repeating-timestamp-show-all t
  966. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  967. When set to a list of strings, only show occurrences of repeating
  968. stamps for these TODO keywords. When nil, only one occurrence is
  969. shown, either today or the nearest into the future."
  970. :group 'org-agenda-daily/weekly
  971. :type '(choice
  972. (const :tag "Show repeating stamps" t)
  973. (repeat :tag "Show repeating stamps for these TODO keywords"
  974. (string :tag "TODO Keyword"))
  975. (const :tag "Don't show repeating stamps" nil)))
  976. (defcustom org-scheduled-past-days 10000
  977. "No. of days to continue listing scheduled items that are not marked DONE.
  978. When an item is scheduled on a date, it shows up in the agenda on this
  979. day and will be listed until it is marked done for the number of days
  980. given here."
  981. :group 'org-agenda-daily/weekly
  982. :type 'integer)
  983. (defcustom org-agenda-log-mode-items '(closed clock)
  984. "List of items that should be shown in agenda log mode.
  985. This list may contain the following symbols:
  986. closed Show entries that have been closed on that day.
  987. clock Show entries that have received clocked time on that day.
  988. state Show all logged state changes.
  989. Note that instead of changing this variable, you can also press `C-u l' in
  990. the agenda to display all available LOG items temporarily."
  991. :group 'org-agenda-daily/weekly
  992. :type '(set :greedy t (const closed) (const clock) (const state)))
  993. (defcustom org-agenda-clock-consistency-checks
  994. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  995. :gap-ok-around ("4:00")
  996. :default-face ((:background "DarkRed") (:foreground "white"))
  997. :overlap-face nil :gap-face nil :no-end-time-face nil
  998. :long-face nil :short-face nil)
  999. "This is a property list, with the following keys:
  1000. :max-duration Mark clocking chunks that are longer than this time.
  1001. This is a time string like \"HH:MM\", or the number
  1002. of minutes as an integer.
  1003. :min-duration Mark clocking chunks that are shorter that this.
  1004. This is a time string like \"HH:MM\", or the number
  1005. of minutes as an integer.
  1006. :max-gap Mark gaps between clocking chunks that are longer than
  1007. this duration. A number of minutes, or a string
  1008. like \"HH:MM\".
  1009. :gap-ok-around List of times during the day which are usually not working
  1010. times. When a gap is detected, but the gap contains any
  1011. of these times, the gap is *not* reported. For example,
  1012. if this is (\"4:00\" \"13:00\") then gaps that contain
  1013. 4:00 in the morning (i.e. the night) and 13:00
  1014. (i.e. a typical lunch time) do not cause a warning.
  1015. You should have at least one time during the night in this
  1016. list, or otherwise the first task each morning will trigger
  1017. a warning because it follows a long gap.
  1018. Furthermore, the following properties can be used to define faces for
  1019. issue display.
  1020. :default-face the default face, if the specific face is undefined
  1021. :overlap-face face for overlapping clocks
  1022. :gap-face face for gaps between clocks
  1023. :no-end-time-face face for incomplete clocks
  1024. :long-face face for clock intervals that are too long
  1025. :short-face face for clock intervals that are too short"
  1026. :group 'org-agenda-daily/weekly
  1027. :group 'org-clock
  1028. :type 'plist)
  1029. (defcustom org-agenda-log-mode-add-notes t
  1030. "Non-nil means add first line of notes to log entries in agenda views.
  1031. If a log item like a state change or a clock entry is associated with
  1032. notes, the first line of these notes will be added to the entry in the
  1033. agenda display."
  1034. :group 'org-agenda-daily/weekly
  1035. :type 'boolean)
  1036. (defcustom org-agenda-start-with-log-mode nil
  1037. "The initial value of log-mode in a newly created agenda window."
  1038. :group 'org-agenda-startup
  1039. :group 'org-agenda-daily/weekly
  1040. :type 'boolean)
  1041. (defcustom org-agenda-start-with-clockreport-mode nil
  1042. "The initial value of clockreport-mode in a newly created agenda window."
  1043. :group 'org-agenda-startup
  1044. :group 'org-agenda-daily/weekly
  1045. :type 'boolean)
  1046. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1047. "Property list with parameters for the clocktable in clockreport mode.
  1048. This is the display mode that shows a clock table in the daily/weekly
  1049. agenda, the properties for this dynamic block can be set here.
  1050. The usual clocktable parameters are allowed here, but you cannot set
  1051. the properties :name, :tstart, :tend, :block, and :scope - these will
  1052. be overwritten to make sure the content accurately reflects the
  1053. current display in the agenda."
  1054. :group 'org-agenda-daily/weekly
  1055. :type 'plist)
  1056. (defcustom org-agenda-search-view-always-boolean nil
  1057. "Non-nil means the search string is interpreted as individual parts.
  1058. The search string for search view can either be interpreted as a phrase,
  1059. or as a list of snippets that define a boolean search for a number of
  1060. strings.
  1061. When this is non-nil, the string will be split on whitespace, and each
  1062. snippet will be searched individually, and all must match in order to
  1063. select an entry. A snippet is then a single string of non-white
  1064. characters, or a string in double quotes, or a regexp in {} braces.
  1065. If a snippet is preceded by \"-\", the snippet must *not* match.
  1066. \"+\" is syntactic sugar for positive selection. Each snippet may
  1067. be found as a full word or a partial word, but see the variable
  1068. `org-agenda-search-view-force-full-words'.
  1069. When this is nil, search will look for the entire search phrase as one,
  1070. with each space character matching any amount of whitespace, including
  1071. line breaks.
  1072. Even when this is nil, you can still switch to Boolean search dynamically
  1073. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1074. is a regexp marked with braces like \"{abc}\", this will also switch to
  1075. boolean search."
  1076. :group 'org-agenda-search-view
  1077. :type 'boolean)
  1078. (if (fboundp 'defvaralias)
  1079. (defvaralias 'org-agenda-search-view-search-words-only
  1080. 'org-agenda-search-view-always-boolean))
  1081. (defcustom org-agenda-search-view-force-full-words nil
  1082. "Non-nil means, search words must be matches as complete words.
  1083. When nil, they may also match part of a word."
  1084. :group 'org-agenda-search-view
  1085. :type 'boolean)
  1086. (defgroup org-agenda-time-grid nil
  1087. "Options concerning the time grid in the Org-mode Agenda."
  1088. :tag "Org Agenda Time Grid"
  1089. :group 'org-agenda)
  1090. (defcustom org-agenda-search-headline-for-time t
  1091. "Non-nil means search headline for a time-of-day.
  1092. If the headline contains a time-of-day in one format or another, it will
  1093. be used to sort the entry into the time sequence of items for a day.
  1094. Some people have time stamps in the headline that refer to the creation
  1095. time or so, and then this produces an unwanted side effect. If this is
  1096. the case for your, use this variable to turn off searching the headline
  1097. for a time."
  1098. :group 'org-agenda-time-grid
  1099. :type 'boolean)
  1100. (defcustom org-agenda-use-time-grid t
  1101. "Non-nil means show a time grid in the agenda schedule.
  1102. A time grid is a set of lines for specific times (like every two hours between
  1103. 8:00 and 20:00). The items scheduled for a day at specific times are
  1104. sorted in between these lines.
  1105. For details about when the grid will be shown, and what it will look like, see
  1106. the variable `org-agenda-time-grid'."
  1107. :group 'org-agenda-time-grid
  1108. :type 'boolean)
  1109. (defcustom org-agenda-time-grid
  1110. '((daily today require-timed)
  1111. "----------------"
  1112. (800 1000 1200 1400 1600 1800 2000))
  1113. "The settings for time grid for agenda display.
  1114. This is a list of three items. The first item is again a list. It contains
  1115. symbols specifying conditions when the grid should be displayed:
  1116. daily if the agenda shows a single day
  1117. weekly if the agenda shows an entire week
  1118. today show grid on current date, independent of daily/weekly display
  1119. require-timed show grid only if at least one item has a time specification
  1120. The second item is a string which will be placed behind the grid time.
  1121. The third item is a list of integers, indicating the times that should have
  1122. a grid line."
  1123. :group 'org-agenda-time-grid
  1124. :type
  1125. '(list
  1126. (set :greedy t :tag "Grid Display Options"
  1127. (const :tag "Show grid in single day agenda display" daily)
  1128. (const :tag "Show grid in weekly agenda display" weekly)
  1129. (const :tag "Always show grid for today" today)
  1130. (const :tag "Show grid only if any timed entries are present"
  1131. require-timed)
  1132. (const :tag "Skip grid times already present in an entry"
  1133. remove-match))
  1134. (string :tag "Grid String")
  1135. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1136. (defcustom org-agenda-show-current-time-in-grid t
  1137. "Non-nil means show the current time in the time grid."
  1138. :group 'org-agenda-time-grid
  1139. :type 'boolean)
  1140. (defcustom org-agenda-current-time-string
  1141. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1142. "The string for the current time marker in the agenda."
  1143. :group 'org-agenda-time-grid
  1144. :type 'string)
  1145. (defgroup org-agenda-sorting nil
  1146. "Options concerning sorting in the Org-mode Agenda."
  1147. :tag "Org Agenda Sorting"
  1148. :group 'org-agenda)
  1149. (defcustom org-agenda-sorting-strategy
  1150. '((agenda habit-down time-up priority-down category-keep)
  1151. (todo priority-down category-keep)
  1152. (tags priority-down category-keep)
  1153. (search category-keep))
  1154. "Sorting structure for the agenda items of a single day.
  1155. This is a list of symbols which will be used in sequence to determine
  1156. if an entry should be listed before another entry. The following
  1157. symbols are recognized:
  1158. time-up Put entries with time-of-day indications first, early first
  1159. time-down Put entries with time-of-day indications first, late first
  1160. category-keep Keep the default order of categories, corresponding to the
  1161. sequence in `org-agenda-files'.
  1162. category-up Sort alphabetically by category, A-Z.
  1163. category-down Sort alphabetically by category, Z-A.
  1164. tag-up Sort alphabetically by last tag, A-Z.
  1165. tag-down Sort alphabetically by last tag, Z-A.
  1166. priority-up Sort numerically by priority, high priority last.
  1167. priority-down Sort numerically by priority, high priority first.
  1168. todo-state-up Sort by todo state, tasks that are done last.
  1169. todo-state-down Sort by todo state, tasks that are done first.
  1170. effort-up Sort numerically by estimated effort, high effort last.
  1171. effort-down Sort numerically by estimated effort, high effort first.
  1172. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1173. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1174. habit-up Put entries that are habits first
  1175. habit-down Put entries that are habits last
  1176. alpha-up Sort headlines alphabetically
  1177. alpha-down Sort headlines alphabetically, reversed
  1178. The different possibilities will be tried in sequence, and testing stops
  1179. if one comparison returns a \"not-equal\". For example, the default
  1180. '(time-up category-keep priority-down)
  1181. means: Pull out all entries having a specified time of day and sort them,
  1182. in order to make a time schedule for the current day the first thing in the
  1183. agenda listing for the day. Of the entries without a time indication, keep
  1184. the grouped in categories, don't sort the categories, but keep them in
  1185. the sequence given in `org-agenda-files'. Within each category sort by
  1186. priority.
  1187. Leaving out `category-keep' would mean that items will be sorted across
  1188. categories by priority.
  1189. Instead of a single list, this can also be a set of list for specific
  1190. contents, with a context symbol in the car of the list, any of
  1191. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1192. Custom commands can bind this variable in the options section."
  1193. :group 'org-agenda-sorting
  1194. :type `(choice
  1195. (repeat :tag "General" ,org-sorting-choice)
  1196. (list :tag "Individually"
  1197. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1198. (repeat ,org-sorting-choice))
  1199. (cons (const :tag "Strategy for TODO lists" todo)
  1200. (repeat ,org-sorting-choice))
  1201. (cons (const :tag "Strategy for Tags matches" tags)
  1202. (repeat ,org-sorting-choice))
  1203. (cons (const :tag "Strategy for search matches" search)
  1204. (repeat ,org-sorting-choice)))))
  1205. (defcustom org-agenda-cmp-user-defined nil
  1206. "A function to define the comparison `user-defined'.
  1207. This function must receive two arguments, agenda entry a and b.
  1208. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1209. the user comparison, return nil.
  1210. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1211. part of an agenda sorting strategy."
  1212. :group 'org-agenda-sorting
  1213. :type 'symbol)
  1214. (defcustom org-sort-agenda-notime-is-late t
  1215. "Non-nil means items without time are considered late.
  1216. This is only relevant for sorting. When t, items which have no explicit
  1217. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1218. do have a time. When nil, the default time is before 0:00. You can use this
  1219. option to decide if the schedule for today should come before or after timeless
  1220. agenda entries."
  1221. :group 'org-agenda-sorting
  1222. :type 'boolean)
  1223. (defcustom org-sort-agenda-noeffort-is-high t
  1224. "Non-nil means items without effort estimate are sorted as high effort.
  1225. This also applies when filtering an agenda view with respect to the
  1226. < or > effort operator. Then, tasks with no effort defined will be treated
  1227. as tasks with high effort.
  1228. When nil, such items are sorted as 0 minutes effort."
  1229. :group 'org-agenda-sorting
  1230. :type 'boolean)
  1231. (defgroup org-agenda-line-format nil
  1232. "Options concerning the entry prefix in the Org-mode agenda display."
  1233. :tag "Org Agenda Line Format"
  1234. :group 'org-agenda)
  1235. (defcustom org-agenda-prefix-format
  1236. '((agenda . " %i %-12:c%?-12t% s")
  1237. (timeline . " % s")
  1238. (todo . " %i %-12:c")
  1239. (tags . " %i %-12:c")
  1240. (search . " %i %-12:c"))
  1241. "Format specifications for the prefix of items in the agenda views.
  1242. An alist with five entries, each for the different agenda types. The
  1243. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1244. The values are format strings.
  1245. This format works similar to a printf format, with the following meaning:
  1246. %c the category of the item, \"Diary\" for entries from the diary,
  1247. or as given by the CATEGORY keyword or derived from the file name
  1248. %e the effort required by the item
  1249. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1250. %T the last tag of the item (ignore inherited tags, which come first)
  1251. %t the HH:MM time-of-day specification if one applies to the entry
  1252. %s Scheduling/Deadline information, a short string
  1253. %(expression) Eval EXPRESSION and replace the control string
  1254. by the result
  1255. All specifiers work basically like the standard `%s' of printf, but may
  1256. contain two additional characters: a question mark just after the `%'
  1257. and a whitespace/punctuation character just before the final letter.
  1258. If the first character after `%' is a question mark, the entire field
  1259. will only be included if the corresponding value applies to the current
  1260. entry. This is useful for fields which should have fixed width when
  1261. present, but zero width when absent. For example, \"%?-12t\" will
  1262. result in a 12 character time field if a time of the day is specified,
  1263. but will completely disappear in entries which do not contain a time.
  1264. If there is punctuation or whitespace character just before the final
  1265. format letter, this character will be appended to the field value if
  1266. the value is not empty. For example, the format \"%-12:c\" leads to
  1267. \"Diary: \" if the category is \"Diary\". If the category were be
  1268. empty, no additional colon would be inserted.
  1269. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1270. which means:
  1271. - Indent the line with two space characters
  1272. - Give the category a 12 chars wide field, padded with whitespace on
  1273. the right (because of `-'). Append a colon if there is a category
  1274. (because of `:').
  1275. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1276. time, don't put in an empty field, just skip it (because of '?').
  1277. - Finally, put the scheduling information.
  1278. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1279. `org-agenda-remove-tags'.
  1280. Custom commands can set this variable in the options section."
  1281. :type '(choice
  1282. (string :tag "General format")
  1283. (list :greedy t :tag "View dependent"
  1284. (cons (const agenda) (string :tag "Format"))
  1285. (cons (const timeline) (string :tag "Format"))
  1286. (cons (const todo) (string :tag "Format"))
  1287. (cons (const tags) (string :tag "Format"))
  1288. (cons (const search) (string :tag "Format"))))
  1289. :group 'org-agenda-line-format)
  1290. (defvar org-prefix-format-compiled nil
  1291. "The compiled version of the most recently used prefix format.
  1292. See the variable `org-agenda-prefix-format'.")
  1293. (defcustom org-agenda-todo-keyword-format "%-1s"
  1294. "Format for the TODO keyword in agenda lines.
  1295. Set this to something like \"%-12s\" if you want all TODO keywords
  1296. to occupy a fixed space in the agenda display."
  1297. :group 'org-agenda-line-format
  1298. :type 'string)
  1299. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1300. "Text preceding timerange entries in the agenda view.
  1301. This is a list with two strings. The first applies when the range
  1302. is entirely on one day. The second applies if the range spans several days.
  1303. The strings may have two \"%d\" format specifiers which will be filled
  1304. with the sequence number of the days, and the total number of days in the
  1305. range, respectively."
  1306. :group 'org-agenda-line-format
  1307. :type '(list
  1308. (string :tag "Deadline today ")
  1309. (choice :tag "Deadline relative"
  1310. (string :tag "Format string")
  1311. (function))))
  1312. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1313. "Text preceding scheduled items in the agenda view.
  1314. This is a list with two strings. The first applies when the item is
  1315. scheduled on the current day. The second applies when it has been scheduled
  1316. previously, it may contain a %d indicating that this is the nth time that
  1317. this item is scheduled, due to automatic rescheduling of unfinished items
  1318. for the following day. So this number is one larger than the number of days
  1319. that passed since this item was scheduled first."
  1320. :group 'org-agenda-line-format
  1321. :type '(list
  1322. (string :tag "Scheduled today ")
  1323. (string :tag "Scheduled previously")))
  1324. (defcustom org-agenda-inactive-leader "["
  1325. "Text preceding item pulled into the agenda by inactive time stamps.
  1326. These entries are added to the agenda when pressing \"[\"."
  1327. :group 'org-agenda-line-format
  1328. :type '(list
  1329. (string :tag "Scheduled today ")
  1330. (string :tag "Scheduled previously")))
  1331. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1332. "Text preceding deadline items in the agenda view.
  1333. This is a list with two strings. The first applies when the item has its
  1334. deadline on the current day. The second applies when it is in the past or
  1335. in the future, it may contain %d to capture how many days away the deadline
  1336. is (was)."
  1337. :group 'org-agenda-line-format
  1338. :type '(list
  1339. (string :tag "Deadline today ")
  1340. (choice :tag "Deadline relative"
  1341. (string :tag "Format string")
  1342. (function))))
  1343. (defcustom org-agenda-remove-times-when-in-prefix t
  1344. "Non-nil means remove duplicate time specifications in agenda items.
  1345. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1346. time-of-day specification in a headline or diary entry is extracted and
  1347. placed into the prefix. If this option is non-nil, the original specification
  1348. \(a timestamp or -range, or just a plain time(range) specification like
  1349. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1350. cluttered.
  1351. The option can be t or nil. It may also be the symbol `beg', indicating
  1352. that the time should only be removed when it is located at the beginning of
  1353. the headline/diary entry."
  1354. :group 'org-agenda-line-format
  1355. :type '(choice
  1356. (const :tag "Always" t)
  1357. (const :tag "Never" nil)
  1358. (const :tag "When at beginning of entry" beg)))
  1359. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1360. "Non-nil means remove time ranges specifications in agenda
  1361. items that span on several days."
  1362. :group 'org-agenda-line-format
  1363. :type 'boolean)
  1364. (defcustom org-agenda-default-appointment-duration nil
  1365. "Default duration for appointments that only have a starting time.
  1366. When nil, no duration is specified in such cases.
  1367. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1368. :group 'org-agenda-line-format
  1369. :type '(choice
  1370. (integer :tag "Minutes")
  1371. (const :tag "No default duration")))
  1372. (defcustom org-agenda-show-inherited-tags t
  1373. "Non-nil means show inherited tags in each agenda line."
  1374. :group 'org-agenda-line-format
  1375. :type 'boolean)
  1376. (defcustom org-agenda-hide-tags-regexp nil
  1377. "Regular expression used to filter away specific tags in agenda views.
  1378. This means that these tags will be present, but not be shown in the agenda
  1379. line. Secondary filtering will still work on the hidden tags.
  1380. Nil means don't hide any tags."
  1381. :group 'org-agenda-line-format
  1382. :type '(choice
  1383. (const :tag "Hide none" nil)
  1384. (string :tag "Regexp ")))
  1385. (defcustom org-agenda-remove-tags nil
  1386. "Non-nil means remove the tags from the headline copy in the agenda.
  1387. When this is the symbol `prefix', only remove tags when
  1388. `org-agenda-prefix-format' contains a `%T' specifier."
  1389. :group 'org-agenda-line-format
  1390. :type '(choice
  1391. (const :tag "Always" t)
  1392. (const :tag "Never" nil)
  1393. (const :tag "When prefix format contains %T" prefix)))
  1394. (if (fboundp 'defvaralias)
  1395. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1396. 'org-agenda-remove-tags))
  1397. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1398. "Shift tags in agenda items to this column.
  1399. If this number is positive, it specifies the column. If it is negative,
  1400. it means that the tags should be flushright to that column. For example,
  1401. -80 works well for a normal 80 character screen."
  1402. :group 'org-agenda-line-format
  1403. :type 'integer)
  1404. (if (fboundp 'defvaralias)
  1405. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1406. (defcustom org-agenda-fontify-priorities 'cookies
  1407. "Non-nil means highlight low and high priorities in agenda.
  1408. When t, the highest priority entries are bold, lowest priority italic.
  1409. However, settings in `org-priority-faces' will overrule these faces.
  1410. When this variable is the symbol `cookies', only fontify the
  1411. cookies, not the entire task.
  1412. This may also be an association list of priority faces, whose
  1413. keys are the character values of `org-highest-priority',
  1414. `org-default-priority', and `org-lowest-priority' (the default values
  1415. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1416. color as a string, or a list like `(:background \"Red\")'.
  1417. If it is a color, the variable `org-faces-easy-properties'
  1418. determines if it is a foreground or a background color."
  1419. :group 'org-agenda-line-format
  1420. :type '(choice
  1421. (const :tag "Never" nil)
  1422. (const :tag "Defaults" t)
  1423. (const :tag "Cookies only" cookies)
  1424. (repeat :tag "Specify"
  1425. (list (character :tag "Priority" :value ?A)
  1426. (choice :tag "Face "
  1427. (string :tag "Color")
  1428. (sexp :tag "Face"))))))
  1429. (defcustom org-agenda-day-face-function nil
  1430. "Function called to determine what face should be used to display a day.
  1431. The only argument passed to that function is the day. It should
  1432. returns a face, or nil if does not want to specify a face and let
  1433. the normal rules apply."
  1434. :group 'org-agenda-line-format
  1435. :type 'function)
  1436. (defcustom org-agenda-category-icon-alist nil
  1437. "Alist of category icon to be displayed in agenda views.
  1438. Each entry should have the following format:
  1439. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1440. Where CATEGORY-REGEXP is a regexp matching the categories where
  1441. the icon should be displayed.
  1442. FILE-OR-DATA either a file path or a string containing image data.
  1443. The other fields can be omited safely if not needed:
  1444. TYPE indicates the image type.
  1445. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1446. image data.
  1447. PROPS are additional image attributes to assign to the image,
  1448. like, e.g. `:ascent center'.
  1449. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1450. If you want to set the display properties yourself, just put a
  1451. list as second element:
  1452. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1453. For example, to display a 16px horizontal space for Emacs
  1454. category, you can use:
  1455. (\"Emacs\" '(space . (:width (16))))"
  1456. :group 'org-agenda-line-format
  1457. :type '(alist :key-type (string :tag "Regexp matching category")
  1458. :value-type (choice (list :tag "Icon"
  1459. (string :tag "File or data")
  1460. (symbol :tag "Type")
  1461. (boolean :tag "Data?")
  1462. (repeat :tag "Extra image properties" :inline t symbol))
  1463. (list :tag "Display properties" sexp))))
  1464. (defgroup org-agenda-column-view nil
  1465. "Options concerning column view in the agenda."
  1466. :tag "Org Agenda Column View"
  1467. :group 'org-agenda)
  1468. (defcustom org-agenda-columns-show-summaries t
  1469. "Non-nil means show summaries for columns displayed in the agenda view."
  1470. :group 'org-agenda-column-view
  1471. :type 'boolean)
  1472. (defcustom org-agenda-columns-compute-summary-properties t
  1473. "Non-nil means recompute all summary properties before column view.
  1474. When column view in the agenda is listing properties that have a summary
  1475. operator, it can go to all relevant buffers and recompute the summaries
  1476. there. This can mean overhead for the agenda column view, but is necessary
  1477. to have thing up to date.
  1478. As a special case, a CLOCKSUM property also makes sure that the clock
  1479. computations are current."
  1480. :group 'org-agenda-column-view
  1481. :type 'boolean)
  1482. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1483. "Non-nil means the duration of an appointment will add to day effort.
  1484. The property to which appointment durations will be added is the one given
  1485. in the option `org-effort-property'. If an appointment does not have
  1486. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1487. is not set, an appointment without end time will not contribute to the time
  1488. estimate."
  1489. :group 'org-agenda-column-view
  1490. :type 'boolean)
  1491. (defcustom org-agenda-auto-exclude-function nil
  1492. "A function called with a tag to decide if it is filtered on '/ RET'.
  1493. The sole argument to the function, which is called once for each
  1494. possible tag, is a string giving the name of the tag. The
  1495. function should return either nil if the tag should be included
  1496. as normal, or \"-<TAG>\" to exclude the tag.
  1497. Note that for the purpose of tag filtering, only the lower-case version of
  1498. all tags will be considered, so that this function will only ever see
  1499. the lower-case version of all tags."
  1500. :group 'org-agenda
  1501. :type 'function)
  1502. (defcustom org-agenda-bulk-custom-functions nil
  1503. "Alist of characters and custom functions for bulk actions.
  1504. For example, this value makes those two functions available:
  1505. '((?R set-category)
  1506. (?C bulk-cut))
  1507. With selected entries in an agenda buffer, `B R' will call
  1508. the custom function `set-category' on the selected entries.
  1509. Note that functions in this alist don't need to be quoted."
  1510. :type 'alist
  1511. :group 'org-agenda)
  1512. (eval-when-compile
  1513. (require 'cl))
  1514. (require 'org)
  1515. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1516. "Execute BODY with point at location given by `org-hd-marker' property.
  1517. If STRING is non-nil, the text property will be fetched from position 0
  1518. in that string. If STRING is nil, it will be fetched from the beginning
  1519. of the current line."
  1520. (org-with-gensyms (marker)
  1521. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1522. 'org-hd-marker string)))
  1523. (with-current-buffer (marker-buffer ,marker)
  1524. (save-excursion
  1525. (goto-char ,marker)
  1526. ,@body)))))
  1527. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1528. (defun org-add-agenda-custom-command (entry)
  1529. "Replace or add a command in `org-agenda-custom-commands'.
  1530. This is mostly for hacking and trying a new command - once the command
  1531. works you probably want to add it to `org-agenda-custom-commands' for good."
  1532. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1533. (if ass
  1534. (setcdr ass (cdr entry))
  1535. (push entry org-agenda-custom-commands))))
  1536. ;;; Define the Org-agenda-mode
  1537. (defvar org-agenda-mode-map (make-sparse-keymap)
  1538. "Keymap for `org-agenda-mode'.")
  1539. (if (fboundp 'defvaralias)
  1540. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1541. (defvar org-agenda-menu) ; defined later in this file.
  1542. (defvar org-agenda-restrict) ; defined later in this file.
  1543. (defvar org-agenda-follow-mode nil)
  1544. (defvar org-agenda-entry-text-mode nil)
  1545. (defvar org-agenda-clockreport-mode nil)
  1546. (defvar org-agenda-show-log nil)
  1547. (defvar org-agenda-redo-command nil)
  1548. (defvar org-agenda-query-string nil)
  1549. (defvar org-agenda-mode-hook nil
  1550. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1551. (defvar org-agenda-type nil)
  1552. (defvar org-agenda-force-single-file nil)
  1553. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1554. (defun org-agenda-mode ()
  1555. "Mode for time-sorted view on action items in Org-mode files.
  1556. The following commands are available:
  1557. \\{org-agenda-mode-map}"
  1558. (interactive)
  1559. (kill-all-local-variables)
  1560. (setq org-agenda-undo-list nil
  1561. org-agenda-pending-undo-list nil
  1562. org-agenda-bulk-marked-entries nil)
  1563. (setq major-mode 'org-agenda-mode)
  1564. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1565. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1566. (setq mode-name "Org-Agenda")
  1567. (use-local-map org-agenda-mode-map)
  1568. (easy-menu-add org-agenda-menu)
  1569. (if org-startup-truncated (setq truncate-lines t))
  1570. (org-set-local 'line-move-visual nil)
  1571. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1572. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1573. ;; Make sure properties are removed when copying text
  1574. (when (boundp 'buffer-substring-filters)
  1575. (org-set-local 'buffer-substring-filters
  1576. (cons (lambda (x)
  1577. (set-text-properties 0 (length x) nil x) x)
  1578. buffer-substring-filters)))
  1579. (unless org-agenda-keep-modes
  1580. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1581. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1582. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1583. org-agenda-show-log org-agenda-start-with-log-mode))
  1584. (easy-menu-change
  1585. '("Agenda") "Agenda Files"
  1586. (append
  1587. (list
  1588. (vector
  1589. (if (get 'org-agenda-files 'org-restrict)
  1590. "Restricted to single file"
  1591. "Edit File List")
  1592. '(org-edit-agenda-file-list)
  1593. (not (get 'org-agenda-files 'org-restrict)))
  1594. "--")
  1595. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1596. (org-agenda-set-mode-name)
  1597. (apply
  1598. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1599. (list 'org-agenda-mode-hook)))
  1600. (substitute-key-definition 'undo 'org-agenda-undo
  1601. org-agenda-mode-map global-map)
  1602. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1603. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1604. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1605. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1606. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1607. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1608. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1609. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1610. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1611. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1612. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1613. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1614. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1615. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1616. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1617. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1618. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1619. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1620. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1621. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1622. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1623. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1624. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1625. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1627. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1628. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1630. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1631. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1632. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1633. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1634. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1635. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1636. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1637. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1638. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1639. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1640. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1641. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1642. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1643. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1644. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1645. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1646. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1647. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1648. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1649. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1650. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1651. (while l (org-defkey org-agenda-mode-map
  1652. (int-to-string (pop l)) 'digit-argument)))
  1653. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1654. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1655. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1656. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1657. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1658. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1659. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1660. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1661. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1662. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1663. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1664. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1666. 'org-clock-modify-effort-estimate)
  1667. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1668. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1669. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1670. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1671. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1672. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1673. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1674. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1675. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1676. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1677. (substitute-key-definition 'next-line 'org-agenda-next-line
  1678. org-agenda-mode-map global-map)
  1679. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1680. org-agenda-mode-map global-map)
  1681. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1682. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1683. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1684. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1685. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1686. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1687. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1688. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1689. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1690. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1691. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1692. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1693. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1694. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1695. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1696. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1697. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1698. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1699. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1700. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1701. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1702. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1703. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1704. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1705. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1706. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1707. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1708. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1709. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1710. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1711. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1712. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1713. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1714. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1715. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1716. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1717. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1718. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1719. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1720. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1721. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1722. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1723. (when org-agenda-mouse-1-follows-link
  1724. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1725. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1726. '("Agenda"
  1727. ("Agenda Files")
  1728. "--"
  1729. ("Agenda Dates"
  1730. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1731. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1732. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1733. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1734. "--"
  1735. ("View"
  1736. ["Day View" org-agenda-day-view
  1737. :active (org-agenda-check-type nil 'agenda)
  1738. :style radio :selected (eq org-agenda-current-span 'day)
  1739. :keys "v d (or just d)"]
  1740. ["Week View" org-agenda-week-view
  1741. :active (org-agenda-check-type nil 'agenda)
  1742. :style radio :selected (eq org-agenda-current-span 'week)
  1743. :keys "v w (or just w)"]
  1744. ["Month View" org-agenda-month-view
  1745. :active (org-agenda-check-type nil 'agenda)
  1746. :style radio :selected (eq org-agenda-current-span 'month)
  1747. :keys "v m"]
  1748. ["Year View" org-agenda-year-view
  1749. :active (org-agenda-check-type nil 'agenda)
  1750. :style radio :selected (eq org-agenda-current-span 'year)
  1751. :keys "v y"]
  1752. "--"
  1753. ["Include Diary" org-agenda-toggle-diary
  1754. :style toggle :selected org-agenda-include-diary
  1755. :active (org-agenda-check-type nil 'agenda)]
  1756. ["Include Deadlines" org-agenda-toggle-deadlines
  1757. :style toggle :selected org-agenda-include-deadlines
  1758. :active (org-agenda-check-type nil 'agenda)]
  1759. ["Use Time Grid" org-agenda-toggle-time-grid
  1760. :style toggle :selected org-agenda-use-time-grid
  1761. :active (org-agenda-check-type nil 'agenda)]
  1762. "--"
  1763. ["Show clock report" org-agenda-clockreport-mode
  1764. :style toggle :selected org-agenda-clockreport-mode
  1765. :active (org-agenda-check-type nil 'agenda)]
  1766. ["Show some entry text" org-agenda-entry-text-mode
  1767. :style toggle :selected org-agenda-entry-text-mode
  1768. :active t]
  1769. "--"
  1770. ["Show Logbook entries" org-agenda-log-mode
  1771. :style toggle :selected org-agenda-show-log
  1772. :active (org-agenda-check-type nil 'agenda 'timeline)
  1773. :keys "v l (or just l)"]
  1774. ["Include archived trees" org-agenda-archives-mode
  1775. :style toggle :selected org-agenda-archives-mode :active t
  1776. :keys "v a"]
  1777. ["Include archive files" (org-agenda-archives-mode t)
  1778. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1779. :keys "v A"]
  1780. "--"
  1781. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1782. ["Write view to file" org-write-agenda t]
  1783. ["Rebuild buffer" org-agenda-redo t]
  1784. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1785. "--"
  1786. ["Show original entry" org-agenda-show t]
  1787. ["Go To (other window)" org-agenda-goto t]
  1788. ["Go To (this window)" org-agenda-switch-to t]
  1789. ["Follow Mode" org-agenda-follow-mode
  1790. :style toggle :selected org-agenda-follow-mode :active t]
  1791. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1792. "--"
  1793. ("TODO"
  1794. ["Cycle TODO" org-agenda-todo t]
  1795. ["Next TODO set" org-agenda-todo-nextset t]
  1796. ["Previous TODO set" org-agenda-todo-previousset t]
  1797. ["Add note" org-agenda-add-note t])
  1798. ("Archive/Refile/Delete"
  1799. ["Archive default" org-agenda-archive-default t]
  1800. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1801. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1802. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1803. ["Archive subtree" org-agenda-archive t]
  1804. "--"
  1805. ["Refile" org-agenda-refile t]
  1806. "--"
  1807. ["Delete subtree" org-agenda-kill t])
  1808. ("Bulk action"
  1809. ["Mark entry" org-agenda-bulk-mark t]
  1810. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1811. ["Unmark entry" org-agenda-bulk-unmark t]
  1812. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1813. ["Act on all marked" org-agenda-bulk-action t]
  1814. "--"
  1815. ("Tags and Properties"
  1816. ["Show all Tags" org-agenda-show-tags t]
  1817. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1818. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1819. "--"
  1820. ["Column View" org-columns t])
  1821. ("Deadline/Schedule"
  1822. ["Schedule" org-agenda-schedule t]
  1823. ["Set Deadline" org-agenda-deadline t]
  1824. "--"
  1825. ["Mark item" org-agenda-action :active t :keys "k m"]
  1826. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1827. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1828. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1829. "--"
  1830. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1831. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1832. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1833. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1834. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1835. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1836. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1837. ("Clock and Effort"
  1838. ["Clock in" org-agenda-clock-in t]
  1839. ["Clock out" org-agenda-clock-out t]
  1840. ["Clock cancel" org-agenda-clock-cancel t]
  1841. ["Goto running clock" org-clock-goto t]
  1842. "--"
  1843. ["Set Effort" org-agenda-set-effort t]
  1844. ["Change clocked effort" org-clock-modify-effort-estimate
  1845. (org-clock-is-active)])
  1846. ("Priority"
  1847. ["Set Priority" org-agenda-priority t]
  1848. ["Increase Priority" org-agenda-priority-up t]
  1849. ["Decrease Priority" org-agenda-priority-down t]
  1850. ["Show Priority" org-agenda-show-priority t])
  1851. ("Calendar/Diary"
  1852. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1853. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1854. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1855. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1856. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1857. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1858. "--"
  1859. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1860. "--"
  1861. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1862. "--"
  1863. ("MobileOrg"
  1864. ["Push Files and Views" org-mobile-push t]
  1865. ["Get Captured and Flagged" org-mobile-pull t]
  1866. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1867. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1868. "--"
  1869. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1870. "--"
  1871. ["Quit" org-agenda-quit t]
  1872. ["Exit and Release Buffers" org-agenda-exit t]
  1873. ))
  1874. ;;; Agenda undo
  1875. (defvar org-agenda-allow-remote-undo t
  1876. "Non-nil means allow remote undo from the agenda buffer.")
  1877. (defvar org-agenda-undo-list nil
  1878. "List of undoable operations in the agenda since last refresh.")
  1879. (defvar org-agenda-undo-has-started-in nil
  1880. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1881. (defvar org-agenda-pending-undo-list nil
  1882. "In a series of undo commands, this is the list of remaining undo items.")
  1883. (defun org-agenda-undo ()
  1884. "Undo a remote editing step in the agenda.
  1885. This undoes changes both in the agenda buffer and in the remote buffer
  1886. that have been changed along."
  1887. (interactive)
  1888. (or org-agenda-allow-remote-undo
  1889. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1890. (if (not (eq this-command last-command))
  1891. (setq org-agenda-undo-has-started-in nil
  1892. org-agenda-pending-undo-list org-agenda-undo-list))
  1893. (if (not org-agenda-pending-undo-list)
  1894. (error "No further undo information"))
  1895. (let* ((entry (pop org-agenda-pending-undo-list))
  1896. buf line cmd rembuf)
  1897. (setq cmd (pop entry) line (pop entry))
  1898. (setq rembuf (nth 2 entry))
  1899. (org-with-remote-undo rembuf
  1900. (while (bufferp (setq buf (pop entry)))
  1901. (if (pop entry)
  1902. (with-current-buffer buf
  1903. (let ((last-undo-buffer buf)
  1904. (inhibit-read-only t))
  1905. (unless (memq buf org-agenda-undo-has-started-in)
  1906. (push buf org-agenda-undo-has-started-in)
  1907. (make-local-variable 'pending-undo-list)
  1908. (undo-start))
  1909. (while (and pending-undo-list
  1910. (listp pending-undo-list)
  1911. (not (car pending-undo-list)))
  1912. (pop pending-undo-list))
  1913. (undo-more 1))))))
  1914. (org-goto-line line)
  1915. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1916. (defun org-verify-change-for-undo (l1 l2)
  1917. "Verify that a real change occurred between the undo lists L1 and L2."
  1918. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1919. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1920. (not (eq l1 l2)))
  1921. ;;; Agenda dispatch
  1922. (defvar org-agenda-restrict nil)
  1923. (defvar org-agenda-restrict-begin (make-marker))
  1924. (defvar org-agenda-restrict-end (make-marker))
  1925. (defvar org-agenda-last-dispatch-buffer nil)
  1926. (defvar org-agenda-overriding-restriction nil)
  1927. ;;;###autoload
  1928. (defun org-agenda (&optional arg keys restriction)
  1929. "Dispatch agenda commands to collect entries to the agenda buffer.
  1930. Prompts for a command to execute. Any prefix arg will be passed
  1931. on to the selected command. The default selections are:
  1932. a Call `org-agenda-list' to display the agenda for current day or week.
  1933. t Call `org-todo-list' to display the global todo list.
  1934. T Call `org-todo-list' to display the global todo list, select only
  1935. entries with a specific TODO keyword (the user gets a prompt).
  1936. m Call `org-tags-view' to display headlines with tags matching
  1937. a condition (the user is prompted for the condition).
  1938. M Like `m', but select only TODO entries, no ordinary headlines.
  1939. L Create a timeline for the current buffer.
  1940. e Export views to associated files.
  1941. s Search entries for keywords.
  1942. / Multi occur across all agenda files and also files listed
  1943. in `org-agenda-text-search-extra-files'.
  1944. < Restrict agenda commands to buffer, subtree, or region.
  1945. Press several times to get the desired effect.
  1946. > Remove a previous restriction.
  1947. # List \"stuck\" projects.
  1948. ! Configure what \"stuck\" means.
  1949. C Configure custom agenda commands.
  1950. More commands can be added by configuring the variable
  1951. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1952. searches can be pre-defined in this way.
  1953. If the current buffer is in Org-mode and visiting a file, you can also
  1954. first press `<' once to indicate that the agenda should be temporarily
  1955. \(until the next use of \\[org-agenda]) restricted to the current file.
  1956. Pressing `<' twice means to restrict to the current subtree or region
  1957. \(if active)."
  1958. (interactive "P")
  1959. (catch 'exit
  1960. (let* ((prefix-descriptions nil)
  1961. (org-agenda-window-setup (if (equal (buffer-name)
  1962. org-agenda-buffer-name)
  1963. 'current-window
  1964. org-agenda-window-setup))
  1965. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1966. (org-agenda-custom-commands
  1967. ;; normalize different versions
  1968. (delq nil
  1969. (mapcar
  1970. (lambda (x)
  1971. (cond ((stringp (cdr x))
  1972. (push x prefix-descriptions)
  1973. nil)
  1974. ((stringp (nth 1 x)) x)
  1975. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1976. (t (cons (car x) (cons "" (cdr x))))))
  1977. org-agenda-custom-commands)))
  1978. (buf (current-buffer))
  1979. (bfn (buffer-file-name (buffer-base-buffer)))
  1980. entry key type match lprops ans)
  1981. ;; Turn off restriction unless there is an overriding one,
  1982. (unless org-agenda-overriding-restriction
  1983. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1984. ;; There is a request to keep the file list in place
  1985. (put 'org-agenda-files 'org-restrict nil))
  1986. (setq org-agenda-restrict nil)
  1987. (move-marker org-agenda-restrict-begin nil)
  1988. (move-marker org-agenda-restrict-end nil))
  1989. ;; Delete old local properties
  1990. (put 'org-agenda-redo-command 'org-lprops nil)
  1991. ;; Delete previously set last-arguments
  1992. (put 'org-agenda-redo-command 'last-args nil)
  1993. ;; Remember where this call originated
  1994. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1995. (unless keys
  1996. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1997. keys (car ans)
  1998. restriction (cdr ans)))
  1999. ;; Establish the restriction, if any
  2000. (when (and (not org-agenda-overriding-restriction) restriction)
  2001. (put 'org-agenda-files 'org-restrict (list bfn))
  2002. (cond
  2003. ((eq restriction 'region)
  2004. (setq org-agenda-restrict t)
  2005. (move-marker org-agenda-restrict-begin (region-beginning))
  2006. (move-marker org-agenda-restrict-end (region-end)))
  2007. ((eq restriction 'subtree)
  2008. (save-excursion
  2009. (setq org-agenda-restrict t)
  2010. (org-back-to-heading t)
  2011. (move-marker org-agenda-restrict-begin (point))
  2012. (move-marker org-agenda-restrict-end
  2013. (progn (org-end-of-subtree t)))))))
  2014. ;; For example the todo list should not need it (but does...)
  2015. (cond
  2016. ((setq entry (assoc keys org-agenda-custom-commands))
  2017. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2018. (progn
  2019. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2020. lprops (nth 4 entry))
  2021. (put 'org-agenda-redo-command 'org-lprops lprops)
  2022. (cond
  2023. ((eq type 'agenda)
  2024. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2025. ((eq type 'alltodo)
  2026. (org-let lprops '(org-todo-list current-prefix-arg)))
  2027. ((eq type 'search)
  2028. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2029. ((eq type 'stuck)
  2030. (org-let lprops '(org-agenda-list-stuck-projects
  2031. current-prefix-arg)))
  2032. ((eq type 'tags)
  2033. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2034. ((eq type 'tags-todo)
  2035. (org-let lprops '(org-tags-view '(4) match)))
  2036. ((eq type 'todo)
  2037. (org-let lprops '(org-todo-list match)))
  2038. ((eq type 'tags-tree)
  2039. (org-check-for-org-mode)
  2040. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2041. ((eq type 'todo-tree)
  2042. (org-check-for-org-mode)
  2043. (org-let lprops
  2044. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2045. (regexp-quote match) "\\>"))))
  2046. ((eq type 'occur-tree)
  2047. (org-check-for-org-mode)
  2048. (org-let lprops '(org-occur match)))
  2049. ((functionp type)
  2050. (org-let lprops '(funcall type match)))
  2051. ((fboundp type)
  2052. (org-let lprops '(funcall type match)))
  2053. (t (error "Invalid custom agenda command type %s" type))))
  2054. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2055. ((equal keys "C")
  2056. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2057. (customize-variable 'org-agenda-custom-commands))
  2058. ((equal keys "a") (call-interactively 'org-agenda-list))
  2059. ((equal keys "s") (call-interactively 'org-search-view))
  2060. ((equal keys "t") (call-interactively 'org-todo-list))
  2061. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2062. ((equal keys "m") (call-interactively 'org-tags-view))
  2063. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2064. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2065. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2066. (org-add-hook
  2067. 'post-command-hook
  2068. (lambda ()
  2069. (unless (current-message)
  2070. (let* ((m (org-agenda-get-any-marker))
  2071. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2072. (when note
  2073. (message (concat
  2074. "FLAGGING-NOTE ([?] for more info): "
  2075. (org-add-props
  2076. (replace-regexp-in-string
  2077. "\\\\n" "//"
  2078. (copy-sequence note))
  2079. nil 'face 'org-warning)))))))
  2080. t t))
  2081. ((equal keys "L")
  2082. (unless (org-mode-p)
  2083. (error "This is not an Org-mode file"))
  2084. (unless restriction
  2085. (put 'org-agenda-files 'org-restrict (list bfn))
  2086. (org-call-with-arg 'org-timeline arg)))
  2087. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2088. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2089. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2090. (t (error "Invalid agenda key"))))))
  2091. (defun org-agenda-append-agenda ()
  2092. "Append another agenda view to the current one.
  2093. This function allows interactive building of block agendas.
  2094. Agenda views are separated by `org-agenda-block-separator'."
  2095. (interactive)
  2096. (unless (string= (buffer-name) org-agenda-buffer-name)
  2097. (error "Can only append from within agenda buffer"))
  2098. (let ((org-agenda-multi t))
  2099. (org-agenda)
  2100. (widen)))
  2101. (defun org-agenda-normalize-custom-commands (cmds)
  2102. (delq nil
  2103. (mapcar
  2104. (lambda (x)
  2105. (cond ((stringp (cdr x)) nil)
  2106. ((stringp (nth 1 x)) x)
  2107. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2108. (t (cons (car x) (cons "" (cdr x))))))
  2109. cmds)))
  2110. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2111. "The user interface for selecting an agenda command."
  2112. (catch 'exit
  2113. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2114. (restrict-ok (and bfn (org-mode-p)))
  2115. (region-p (org-region-active-p))
  2116. (custom org-agenda-custom-commands)
  2117. (selstring "")
  2118. restriction second-time
  2119. c entry key type match prefixes rmheader header-end custom1 desc
  2120. line lines left right n n1)
  2121. (save-window-excursion
  2122. (delete-other-windows)
  2123. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2124. (erase-buffer)
  2125. (insert (eval-when-compile
  2126. (let ((header
  2127. "
  2128. Press key for an agenda command: < Buffer, subtree/region restriction
  2129. -------------------------------- > Remove restriction
  2130. a Agenda for current week or day e Export agenda views
  2131. t List of all TODO entries T Entries with special TODO kwd
  2132. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2133. L Timeline for current buffer # List stuck projects (!=configure)
  2134. s Search for keywords C Configure custom agenda commands
  2135. / Multi-occur ? Find :FLAGGED: entries
  2136. ")
  2137. (start 0))
  2138. (while (string-match
  2139. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2140. header start)
  2141. (setq start (match-end 0))
  2142. (add-text-properties (match-beginning 2) (match-end 2)
  2143. '(face bold) header))
  2144. header)))
  2145. (setq header-end (move-marker (make-marker) (point)))
  2146. (while t
  2147. (setq custom1 custom)
  2148. (when (eq rmheader t)
  2149. (org-goto-line 1)
  2150. (re-search-forward ":" nil t)
  2151. (delete-region (match-end 0) (point-at-eol))
  2152. (forward-char 1)
  2153. (looking-at "-+")
  2154. (delete-region (match-end 0) (point-at-eol))
  2155. (move-marker header-end (match-end 0)))
  2156. (goto-char header-end)
  2157. (delete-region (point) (point-max))
  2158. ;; Produce all the lines that describe custom commands and prefixes
  2159. (setq lines nil)
  2160. (while (setq entry (pop custom1))
  2161. (setq key (car entry) desc (nth 1 entry)
  2162. type (nth 2 entry)
  2163. match (nth 3 entry))
  2164. (if (> (length key) 1)
  2165. (add-to-list 'prefixes (string-to-char key))
  2166. (setq line
  2167. (format
  2168. "%-4s%-14s"
  2169. (org-add-props (copy-sequence key)
  2170. '(face bold))
  2171. (cond
  2172. ((string-match "\\S-" desc) desc)
  2173. ((eq type 'agenda) "Agenda for current week or day")
  2174. ((eq type 'alltodo) "List of all TODO entries")
  2175. ((eq type 'search) "Word search")
  2176. ((eq type 'stuck) "List of stuck projects")
  2177. ((eq type 'todo) "TODO keyword")
  2178. ((eq type 'tags) "Tags query")
  2179. ((eq type 'tags-todo) "Tags (TODO)")
  2180. ((eq type 'tags-tree) "Tags tree")
  2181. ((eq type 'todo-tree) "TODO kwd tree")
  2182. ((eq type 'occur-tree) "Occur tree")
  2183. ((functionp type) (if (symbolp type)
  2184. (symbol-name type)
  2185. "Lambda expression"))
  2186. (t "???"))))
  2187. (if org-agenda-menu-show-matcher
  2188. (setq line
  2189. (concat line ": "
  2190. (cond
  2191. ((stringp match)
  2192. (setq match (copy-sequence match))
  2193. (org-add-props match nil 'face 'org-warning))
  2194. (match
  2195. (format "set of %d commands" (length match)))
  2196. (t ""))))
  2197. (if (org-string-nw-p match)
  2198. (add-text-properties
  2199. 0 (length line) (list 'help-echo
  2200. (concat "Matcher: "match)) line)))
  2201. (push line lines)))
  2202. (setq lines (nreverse lines))
  2203. (when prefixes
  2204. (mapc (lambda (x)
  2205. (push
  2206. (format "%s %s"
  2207. (org-add-props (char-to-string x)
  2208. nil 'face 'bold)
  2209. (or (cdr (assoc (concat selstring
  2210. (char-to-string x))
  2211. prefix-descriptions))
  2212. "Prefix key"))
  2213. lines))
  2214. prefixes))
  2215. ;; Check if we should display in two columns
  2216. (if org-agenda-menu-two-column
  2217. (progn
  2218. (setq n (length lines)
  2219. n1 (+ (/ n 2) (mod n 2))
  2220. right (nthcdr n1 lines)
  2221. left (copy-sequence lines))
  2222. (setcdr (nthcdr (1- n1) left) nil))
  2223. (setq left lines right nil))
  2224. (while left
  2225. (insert "\n" (pop left))
  2226. (when right
  2227. (if (< (current-column) 40)
  2228. (move-to-column 40 t)
  2229. (insert " "))
  2230. (insert (pop right))))
  2231. ;; Make the window the right size
  2232. (goto-char (point-min))
  2233. (if second-time
  2234. (if (not (pos-visible-in-window-p (point-max)))
  2235. (org-fit-window-to-buffer))
  2236. (setq second-time t)
  2237. (org-fit-window-to-buffer))
  2238. ;; Ask for selection
  2239. (message "Press key for agenda command%s:"
  2240. (if (or restrict-ok org-agenda-overriding-restriction)
  2241. (if org-agenda-overriding-restriction
  2242. " (restriction lock active)"
  2243. (if restriction
  2244. (format " (restricted to %s)" restriction)
  2245. " (unrestricted)"))
  2246. ""))
  2247. (setq c (read-char-exclusive))
  2248. (message "")
  2249. (cond
  2250. ((assoc (char-to-string c) custom)
  2251. (setq selstring (concat selstring (char-to-string c)))
  2252. (throw 'exit (cons selstring restriction)))
  2253. ((memq c prefixes)
  2254. (setq selstring (concat selstring (char-to-string c))
  2255. prefixes nil
  2256. rmheader (or rmheader t)
  2257. custom (delq nil (mapcar
  2258. (lambda (x)
  2259. (if (or (= (length (car x)) 1)
  2260. (/= (string-to-char (car x)) c))
  2261. nil
  2262. (cons (substring (car x) 1) (cdr x))))
  2263. custom))))
  2264. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2265. (message "Restriction is only possible in Org-mode buffers")
  2266. (ding) (sit-for 1))
  2267. ((eq c ?1)
  2268. (org-agenda-remove-restriction-lock 'noupdate)
  2269. (setq restriction 'buffer))
  2270. ((eq c ?0)
  2271. (org-agenda-remove-restriction-lock 'noupdate)
  2272. (setq restriction (if region-p 'region 'subtree)))
  2273. ((eq c ?<)
  2274. (org-agenda-remove-restriction-lock 'noupdate)
  2275. (setq restriction
  2276. (cond
  2277. ((eq restriction 'buffer)
  2278. (if region-p 'region 'subtree))
  2279. ((memq restriction '(subtree region))
  2280. nil)
  2281. (t 'buffer))))
  2282. ((eq c ?>)
  2283. (org-agenda-remove-restriction-lock 'noupdate)
  2284. (setq restriction nil))
  2285. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2286. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2287. ((and (> (length selstring) 0) (eq c ?\d))
  2288. (delete-window)
  2289. (org-agenda-get-restriction-and-command prefix-descriptions))
  2290. ((equal c ?q) (error "Abort"))
  2291. (t (error "Invalid key %c" c))))))))
  2292. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2293. (defvar org-agenda-last-arguments nil
  2294. "The arguments of the previous call to `org-agenda'.")
  2295. (defun org-agenda-run-series (name series)
  2296. (org-let (nth 1 series) '(org-prepare-agenda name))
  2297. (let* ((org-agenda-multi t)
  2298. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2299. (org-agenda-overriding-arguments
  2300. (or org-agenda-overriding-arguments
  2301. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2302. (get 'org-agenda-redo-command 'last-args))))
  2303. (cmds (car series))
  2304. (gprops (nth 1 series))
  2305. match ;; The byte compiler incorrectly complains about this. Keep it!
  2306. cmd type lprops)
  2307. (while (setq cmd (pop cmds))
  2308. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2309. (cond
  2310. ((eq type 'agenda)
  2311. (org-let2 gprops lprops
  2312. '(call-interactively 'org-agenda-list)))
  2313. ((eq type 'alltodo)
  2314. (org-let2 gprops lprops
  2315. '(call-interactively 'org-todo-list)))
  2316. ((eq type 'search)
  2317. (org-let2 gprops lprops
  2318. '(org-search-view current-prefix-arg match nil)))
  2319. ((eq type 'stuck)
  2320. (org-let2 gprops lprops
  2321. '(call-interactively 'org-agenda-list-stuck-projects)))
  2322. ((eq type 'tags)
  2323. (org-let2 gprops lprops
  2324. '(org-tags-view current-prefix-arg match)))
  2325. ((eq type 'tags-todo)
  2326. (org-let2 gprops lprops
  2327. '(org-tags-view '(4) match)))
  2328. ((eq type 'todo)
  2329. (org-let2 gprops lprops
  2330. '(org-todo-list match)))
  2331. ((fboundp type)
  2332. (org-let2 gprops lprops
  2333. '(funcall type match)))
  2334. (t (error "Invalid type in command series"))))
  2335. (widen)
  2336. (setq org-agenda-redo-command redo)
  2337. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2338. (goto-char (point-min)))
  2339. (org-fit-agenda-window)
  2340. (org-let (nth 1 series) '(org-finalize-agenda)))
  2341. ;;;###autoload
  2342. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2343. "Run an agenda command in batch mode and send the result to STDOUT.
  2344. If CMD-KEY is a string of length 1, it is used as a key in
  2345. `org-agenda-custom-commands' and triggers this command. If it is a
  2346. longer string it is used as a tags/todo match string.
  2347. Parameters are alternating variable names and values that will be bound
  2348. before running the agenda command."
  2349. (org-eval-in-environment (org-make-parameter-alist parameters)
  2350. (if (> (length cmd-key) 2)
  2351. (org-tags-view nil cmd-key)
  2352. (org-agenda nil cmd-key)))
  2353. (set-buffer org-agenda-buffer-name)
  2354. (princ (org-encode-for-stdout (buffer-string))))
  2355. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2356. ;(defun org-encode-for-stdout (string)
  2357. ; (if (fboundp 'encode-coding-string)
  2358. ; (encode-coding-string string buffer-file-coding-system)
  2359. ; string))
  2360. (defun org-encode-for-stdout (string)
  2361. string)
  2362. (defvar org-agenda-info nil)
  2363. ;;;###autoload
  2364. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2365. "Run an agenda command in batch mode and send the result to STDOUT.
  2366. If CMD-KEY is a string of length 1, it is used as a key in
  2367. `org-agenda-custom-commands' and triggers this command. If it is a
  2368. longer string it is used as a tags/todo match string.
  2369. Parameters are alternating variable names and values that will be bound
  2370. before running the agenda command.
  2371. The output gives a line for each selected agenda item. Each
  2372. item is a list of comma-separated values, like this:
  2373. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2374. category The category of the item
  2375. head The headline, without TODO kwd, TAGS and PRIORITY
  2376. type The type of the agenda entry, can be
  2377. todo selected in TODO match
  2378. tagsmatch selected in tags match
  2379. diary imported from diary
  2380. deadline a deadline on given date
  2381. scheduled scheduled on given date
  2382. timestamp entry has timestamp on given date
  2383. closed entry was closed on given date
  2384. upcoming-deadline warning about deadline
  2385. past-scheduled forwarded scheduled item
  2386. block entry has date block including g. date
  2387. todo The todo keyword, if any
  2388. tags All tags including inherited ones, separated by colons
  2389. date The relevant date, like 2007-2-14
  2390. time The time, like 15:00-16:50
  2391. extra Sting with extra planning info
  2392. priority-l The priority letter if any was given
  2393. priority-n The computed numerical priority
  2394. agenda-day The day in the agenda where this is listed"
  2395. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2396. (org-make-parameter-alist parameters))
  2397. (if (> (length cmd-key) 2)
  2398. (org-tags-view nil cmd-key)
  2399. (org-agenda nil cmd-key)))
  2400. (set-buffer org-agenda-buffer-name)
  2401. (let* ((lines (org-split-string (buffer-string) "\n"))
  2402. line)
  2403. (while (setq line (pop lines))
  2404. (catch 'next
  2405. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2406. (setq org-agenda-info
  2407. (org-fix-agenda-info (text-properties-at 0 line)))
  2408. (princ
  2409. (org-encode-for-stdout
  2410. (mapconcat 'org-agenda-export-csv-mapper
  2411. '(org-category txt type todo tags date time extra
  2412. priority-letter priority agenda-day)
  2413. ",")))
  2414. (princ "\n")))))
  2415. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2416. (defun org-fix-agenda-info (props)
  2417. "Make sure all properties on an agenda item have a canonical form.
  2418. This ensures the export commands can easily use it."
  2419. (let (tmp re)
  2420. (when (setq tmp (plist-get props 'tags))
  2421. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2422. (when (setq tmp (plist-get props 'date))
  2423. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2424. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2425. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2426. (setq tmp (calendar-date-string tmp)))
  2427. (setq props (plist-put props 'date tmp)))
  2428. (when (setq tmp (plist-get props 'day))
  2429. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2430. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2431. (setq tmp (calendar-date-string tmp)))
  2432. (setq props (plist-put props 'day tmp))
  2433. (setq props (plist-put props 'agenda-day tmp)))
  2434. (when (setq tmp (plist-get props 'txt))
  2435. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2436. (plist-put props 'priority-letter (match-string 1 tmp))
  2437. (setq tmp (replace-match "" t t tmp)))
  2438. (when (and (setq re (plist-get props 'org-todo-regexp))
  2439. (setq re (concat "\\`\\.*" re " ?"))
  2440. (string-match re tmp))
  2441. (plist-put props 'todo (match-string 1 tmp))
  2442. (setq tmp (replace-match "" t t tmp)))
  2443. (plist-put props 'txt tmp)))
  2444. props)
  2445. (defun org-agenda-export-csv-mapper (prop)
  2446. (let ((res (plist-get org-agenda-info prop)))
  2447. (setq res
  2448. (cond
  2449. ((not res) "")
  2450. ((stringp res) res)
  2451. (t (prin1-to-string res))))
  2452. (while (string-match "," res)
  2453. (setq res (replace-match ";" t t res)))
  2454. (org-trim res)))
  2455. ;;;###autoload
  2456. (defun org-store-agenda-views (&rest parameters)
  2457. (interactive)
  2458. (eval (list 'org-batch-store-agenda-views)))
  2459. ;;;###autoload
  2460. (defmacro org-batch-store-agenda-views (&rest parameters)
  2461. "Run all custom agenda commands that have a file argument."
  2462. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2463. (pop-up-frames nil)
  2464. (dir default-directory)
  2465. (pars (org-make-parameter-alist parameters))
  2466. cmd thiscmdkey files opts cmd-or-set)
  2467. (save-window-excursion
  2468. (while cmds
  2469. (setq cmd (pop cmds)
  2470. thiscmdkey (car cmd)
  2471. cmd-or-set (nth 2 cmd)
  2472. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2473. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2474. (if (stringp files) (setq files (list files)))
  2475. (when files
  2476. (org-eval-in-environment (append org-agenda-exporter-settings
  2477. opts pars)
  2478. (org-agenda nil thiscmdkey))
  2479. (set-buffer org-agenda-buffer-name)
  2480. (while files
  2481. (org-eval-in-environment (append org-agenda-exporter-settings
  2482. opts pars)
  2483. (org-write-agenda (expand-file-name (pop files) dir) nil t)))
  2484. (and (get-buffer org-agenda-buffer-name)
  2485. (kill-buffer org-agenda-buffer-name)))))))
  2486. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2487. (defun org-agenda-mark-header-line (pos)
  2488. "Mark the line at POS as an agenda structure header."
  2489. (save-excursion
  2490. (goto-char pos)
  2491. (put-text-property (point-at-bol) (point-at-eol)
  2492. 'org-agenda-structural-header t)
  2493. (when org-agenda-title-append
  2494. (put-text-property (point-at-bol) (point-at-eol)
  2495. 'org-agenda-title-append org-agenda-title-append))))
  2496. (defvar org-mobile-creating-agendas)
  2497. (defun org-write-agenda (file &optional open nosettings)
  2498. "Write the current buffer (an agenda view) as a file.
  2499. Depending on the extension of the file name, plain text (.txt),
  2500. HTML (.html or .htm) or Postscript (.ps) is produced.
  2501. If the extension is .ics, run icalendar export over all files used
  2502. to construct the agenda and limit the export to entries listed in the
  2503. agenda now.
  2504. With prefix argument OPEN, open the new file immediately.
  2505. If NOSETTINGS is given, do not scope the settings of
  2506. `org-agenda-exporter-settings' into the export commands. This is used when
  2507. the settings have already been scoped and we do not wish to overrule other,
  2508. higher priority settings."
  2509. (interactive "FWrite agenda to file: \nP")
  2510. (if (not (file-writable-p file))
  2511. (error "Cannot write agenda to file %s" file))
  2512. (org-let (if nosettings nil org-agenda-exporter-settings)
  2513. '(save-excursion
  2514. (save-window-excursion
  2515. (org-agenda-mark-filtered-text)
  2516. (let ((bs (copy-sequence (buffer-string))) beg)
  2517. (org-agenda-unmark-filtered-text)
  2518. (with-temp-buffer
  2519. (rename-buffer "Agenda View" t)
  2520. (set-buffer-modified-p nil)
  2521. (insert bs)
  2522. (org-agenda-remove-marked-text 'org-filtered)
  2523. (while (setq beg (text-property-any (point-min) (point-max)
  2524. 'org-filtered t))
  2525. (delete-region
  2526. beg (or (next-single-property-change beg 'org-filtered)
  2527. (point-max))))
  2528. (run-hooks 'org-agenda-before-write-hook)
  2529. (cond
  2530. ((org-bound-and-true-p org-mobile-creating-agendas)
  2531. (org-mobile-write-agenda-for-mobile file))
  2532. ((string-match "\\.html?\\'" file)
  2533. (require 'htmlize)
  2534. (set-buffer (htmlize-buffer (current-buffer)))
  2535. (when (and org-agenda-export-html-style
  2536. (string-match "<style>" org-agenda-export-html-style))
  2537. ;; replace <style> section with org-agenda-export-html-style
  2538. (goto-char (point-min))
  2539. (kill-region (- (search-forward "<style") 6)
  2540. (search-forward "</style>"))
  2541. (insert org-agenda-export-html-style))
  2542. (write-file file)
  2543. (kill-buffer (current-buffer))
  2544. (message "HTML written to %s" file))
  2545. ((string-match "\\.ps\\'" file)
  2546. (require 'ps-print)
  2547. (ps-print-buffer-with-faces file)
  2548. (message "Postscript written to %s" file))
  2549. ((string-match "\\.pdf\\'" file)
  2550. (require 'ps-print)
  2551. (ps-print-buffer-with-faces
  2552. (concat (file-name-sans-extension file) ".ps"))
  2553. (call-process "ps2pdf" nil nil nil
  2554. (expand-file-name
  2555. (concat (file-name-sans-extension file) ".ps"))
  2556. (expand-file-name file))
  2557. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2558. (message "PDF written to %s" file))
  2559. ((string-match "\\.ics\\'" file)
  2560. (require 'org-icalendar)
  2561. (let ((org-agenda-marker-table
  2562. (org-create-marker-find-array
  2563. (org-agenda-collect-markers)))
  2564. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2565. (org-combined-agenda-icalendar-file file))
  2566. (apply 'org-export-icalendar 'combine
  2567. (org-agenda-files nil 'ifmode))))
  2568. (t
  2569. (let ((bs (buffer-string)))
  2570. (find-file file)
  2571. (erase-buffer)
  2572. (insert bs)
  2573. (save-buffer 0)
  2574. (kill-buffer (current-buffer))
  2575. (message "Plain text written to %s" file))))))))
  2576. (set-buffer org-agenda-buffer-name))
  2577. (when open (org-open-file file)))
  2578. (defvar org-agenda-filter-overlays nil)
  2579. (defun org-agenda-mark-filtered-text ()
  2580. "Mark all text hidden by filtering with a text property."
  2581. (let ((inhibit-read-only t))
  2582. (mapc
  2583. (lambda (o)
  2584. (when (equal (overlay-buffer o) (current-buffer))
  2585. (put-text-property
  2586. (overlay-start o) (overlay-end o)
  2587. 'org-filtered t)))
  2588. org-agenda-filter-overlays)))
  2589. (defun org-agenda-unmark-filtered-text ()
  2590. "Remove the filtering text property."
  2591. (let ((inhibit-read-only t))
  2592. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2593. (defun org-agenda-remove-marked-text (property &optional value)
  2594. "Delete all text marked with VALUE of PROPERTY.
  2595. VALUE defaults to t."
  2596. (let (beg)
  2597. (setq value (or value t))
  2598. (while (setq beg (text-property-any (point-min) (point-max)
  2599. property value))
  2600. (delete-region
  2601. beg (or (next-single-property-change beg 'org-filtered)
  2602. (point-max))))))
  2603. (defun org-agenda-add-entry-text ()
  2604. "Add entry text to agenda lines.
  2605. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2606. entry text following headings shown in the agenda.
  2607. Drawers will be excluded, also the line with scheduling/deadline info."
  2608. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2609. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2610. (let (m txt)
  2611. (goto-char (point-min))
  2612. (while (not (eobp))
  2613. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2614. (beginning-of-line 2)
  2615. (setq txt (org-agenda-get-some-entry-text
  2616. m org-agenda-add-entry-text-maxlines " > "))
  2617. (end-of-line 1)
  2618. (if (string-match "\\S-" txt)
  2619. (insert "\n" txt)
  2620. (or (eobp) (forward-char 1))))))))
  2621. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2622. &rest keep)
  2623. "Extract entry text from MARKER, at most N-LINES lines.
  2624. This will ignore drawers etc, just get the text.
  2625. If INDENT is given, prefix every line with this string. If KEEP is
  2626. given, it is a list of symbols, defining stuff that should not be
  2627. removed from the entry content. Currently only `planning' is allowed here."
  2628. (let (txt drawer-re kwd-time-re ind)
  2629. (save-excursion
  2630. (with-current-buffer (marker-buffer marker)
  2631. (if (not (org-mode-p))
  2632. (setq txt "")
  2633. (save-excursion
  2634. (save-restriction
  2635. (widen)
  2636. (goto-char marker)
  2637. (end-of-line 1)
  2638. (setq txt (buffer-substring
  2639. (min (1+ (point)) (point-max))
  2640. (progn (outline-next-heading) (point)))
  2641. drawer-re org-drawer-regexp
  2642. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2643. ".*\n?"))
  2644. (with-temp-buffer
  2645. (insert txt)
  2646. (when org-agenda-add-entry-text-descriptive-links
  2647. (goto-char (point-min))
  2648. (while (org-activate-bracket-links (point-max))
  2649. (add-text-properties (match-beginning 0) (match-end 0)
  2650. '(face org-link))))
  2651. (goto-char (point-min))
  2652. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2653. (set-text-properties (match-beginning 0) (match-end 0)
  2654. nil))
  2655. (goto-char (point-min))
  2656. (while (re-search-forward drawer-re nil t)
  2657. (delete-region
  2658. (match-beginning 0)
  2659. (progn (re-search-forward
  2660. "^[ \t]*:END:.*\n?" nil 'move)
  2661. (point))))
  2662. (unless (member 'planning keep)
  2663. (goto-char (point-min))
  2664. (while (re-search-forward kwd-time-re nil t)
  2665. (replace-match "")))
  2666. (goto-char (point-min))
  2667. (when org-agenda-entry-text-exclude-regexps
  2668. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2669. (while (setq re (pop re-list))
  2670. (goto-char (point-min))
  2671. (while (re-search-forward re nil t)
  2672. (replace-match "")))))
  2673. (goto-char (point-max))
  2674. (skip-chars-backward " \t\n")
  2675. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2676. ;; find and remove min common indentation
  2677. (goto-char (point-min))
  2678. (untabify (point-min) (point-max))
  2679. (setq ind (org-get-indentation))
  2680. (while (not (eobp))
  2681. (unless (looking-at "[ \t]*$")
  2682. (setq ind (min ind (org-get-indentation))))
  2683. (beginning-of-line 2))
  2684. (goto-char (point-min))
  2685. (while (not (eobp))
  2686. (unless (looking-at "[ \t]*$")
  2687. (move-to-column ind)
  2688. (delete-region (point-at-bol) (point)))
  2689. (beginning-of-line 2))
  2690. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2691. (goto-char (point-min))
  2692. (when indent
  2693. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2694. (replace-match indent t t)))
  2695. (goto-char (point-min))
  2696. (while (looking-at "[ \t]*\n") (replace-match ""))
  2697. (goto-char (point-max))
  2698. (when (> (org-current-line)
  2699. n-lines)
  2700. (org-goto-line (1+ n-lines))
  2701. (backward-char 1))
  2702. (setq txt (buffer-substring (point-min) (point)))))))))
  2703. txt))
  2704. (defun org-agenda-collect-markers ()
  2705. "Collect the markers pointing to entries in the agenda buffer."
  2706. (let (m markers)
  2707. (save-excursion
  2708. (goto-char (point-min))
  2709. (while (not (eobp))
  2710. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2711. (org-get-at-bol 'org-marker)))
  2712. (push m markers))
  2713. (beginning-of-line 2)))
  2714. (nreverse markers)))
  2715. (defun org-create-marker-find-array (marker-list)
  2716. "Create a alist of files names with all marker positions in that file."
  2717. (let (f tbl m a p)
  2718. (while (setq m (pop marker-list))
  2719. (setq p (marker-position m)
  2720. f (buffer-file-name (or (buffer-base-buffer
  2721. (marker-buffer m))
  2722. (marker-buffer m))))
  2723. (if (setq a (assoc f tbl))
  2724. (push (marker-position m) (cdr a))
  2725. (push (list f p) tbl)))
  2726. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2727. tbl)))
  2728. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2729. (defun org-check-agenda-marker-table ()
  2730. "Check of the current entry is on the marker list."
  2731. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2732. a)
  2733. (and (setq a (assoc file org-agenda-marker-table))
  2734. (save-match-data
  2735. (save-excursion
  2736. (org-back-to-heading t)
  2737. (member (point) (cdr a)))))))
  2738. (defun org-check-for-org-mode ()
  2739. "Make sure current buffer is in org-mode. Error if not."
  2740. (or (org-mode-p)
  2741. (error "Cannot execute org-mode agenda command on buffer in %s"
  2742. major-mode)))
  2743. (defun org-fit-agenda-window ()
  2744. "Fit the window to the buffer size."
  2745. (and (memq org-agenda-window-setup '(reorganize-frame))
  2746. (fboundp 'fit-window-to-buffer)
  2747. (org-fit-window-to-buffer
  2748. nil
  2749. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2750. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2751. ;;; Agenda prepare and finalize
  2752. (defvar org-agenda-multi nil) ; dynamically scoped
  2753. (defvar org-agenda-buffer-name "*Org Agenda*")
  2754. (defvar org-pre-agenda-window-conf nil)
  2755. (defvar org-agenda-columns-active nil)
  2756. (defvar org-agenda-name nil)
  2757. (defvar org-agenda-filter nil)
  2758. (defvar org-agenda-filter-while-redo nil)
  2759. (defvar org-agenda-filter-preset nil
  2760. "A preset of the tags filter used for secondary agenda filtering.
  2761. This must be a list of strings, each string must be a single tag preceded
  2762. by \"+\" or \"-\".
  2763. This variable should not be set directly, but agenda custom commands can
  2764. bind it in the options section. The preset filter is a global property of
  2765. the entire agenda view. In a block agenda, it will not work reliably to
  2766. define a filter for one of the individual blocks. You need to set it in
  2767. the global options and expect it to be applied to the entire view.")
  2768. (defun org-prepare-agenda (&optional name)
  2769. (setq org-todo-keywords-for-agenda nil)
  2770. (setq org-done-keywords-for-agenda nil)
  2771. (setq org-drawers-for-agenda nil)
  2772. (unless org-agenda-persistent-filter
  2773. (setq org-agenda-filter nil))
  2774. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2775. (if org-agenda-multi
  2776. (progn
  2777. (setq buffer-read-only nil)
  2778. (goto-char (point-max))
  2779. (unless (or (bobp) org-agenda-compact-blocks
  2780. (not org-agenda-block-separator))
  2781. (insert "\n"
  2782. (if (stringp org-agenda-block-separator)
  2783. org-agenda-block-separator
  2784. (make-string (window-width) org-agenda-block-separator))
  2785. "\n"))
  2786. (narrow-to-region (point) (point-max)))
  2787. (org-agenda-reset-markers)
  2788. (setq org-agenda-contributing-files nil)
  2789. (setq org-agenda-columns-active nil)
  2790. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2791. (setq org-todo-keywords-for-agenda
  2792. (org-uniquify org-todo-keywords-for-agenda))
  2793. (setq org-done-keywords-for-agenda
  2794. (org-uniquify org-done-keywords-for-agenda))
  2795. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2796. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2797. (awin (get-buffer-window abuf)))
  2798. (cond
  2799. ((equal (current-buffer) abuf) nil)
  2800. (awin (select-window awin))
  2801. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2802. ((equal org-agenda-window-setup 'current-window)
  2803. (org-pop-to-buffer-same-window abuf))
  2804. ((equal org-agenda-window-setup 'other-window)
  2805. (org-switch-to-buffer-other-window abuf))
  2806. ((equal org-agenda-window-setup 'other-frame)
  2807. (switch-to-buffer-other-frame abuf))
  2808. ((equal org-agenda-window-setup 'reorganize-frame)
  2809. (delete-other-windows)
  2810. (org-switch-to-buffer-other-window abuf)))
  2811. ;; additional test in case agenda is invoked from within agenda
  2812. ;; buffer via elisp link
  2813. (unless (equal (current-buffer) abuf)
  2814. (org-pop-to-buffer-same-window abuf)))
  2815. (setq buffer-read-only nil)
  2816. (let ((inhibit-read-only t)) (erase-buffer))
  2817. (org-agenda-mode)
  2818. (and name (not org-agenda-name)
  2819. (org-set-local 'org-agenda-name name)))
  2820. (setq buffer-read-only nil))
  2821. (defun org-finalize-agenda ()
  2822. "Finishing touch for the agenda buffer, called just before displaying it."
  2823. (unless org-agenda-multi
  2824. (save-excursion
  2825. (let ((inhibit-read-only t))
  2826. (goto-char (point-min))
  2827. (while (org-activate-bracket-links (point-max))
  2828. (add-text-properties (match-beginning 0) (match-end 0)
  2829. '(face org-link)))
  2830. (org-agenda-align-tags)
  2831. (unless org-agenda-with-colors
  2832. (remove-text-properties (point-min) (point-max) '(face nil))))
  2833. (if (and (boundp 'org-agenda-overriding-columns-format)
  2834. org-agenda-overriding-columns-format)
  2835. (org-set-local 'org-agenda-overriding-columns-format
  2836. org-agenda-overriding-columns-format))
  2837. (if (and (boundp 'org-agenda-view-columns-initially)
  2838. org-agenda-view-columns-initially)
  2839. (org-agenda-columns))
  2840. (when org-agenda-fontify-priorities
  2841. (org-agenda-fontify-priorities))
  2842. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2843. (org-agenda-dim-blocked-tasks))
  2844. (org-agenda-mark-clocking-task)
  2845. (when org-agenda-entry-text-mode
  2846. (org-agenda-entry-text-hide)
  2847. (org-agenda-entry-text-show))
  2848. (if (functionp 'org-habit-insert-consistency-graphs)
  2849. (org-habit-insert-consistency-graphs))
  2850. (run-hooks 'org-finalize-agenda-hook)
  2851. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2852. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2853. (org-agenda-filter-apply org-agenda-filter))
  2854. )))
  2855. (defun org-agenda-mark-clocking-task ()
  2856. "Mark the current clock entry in the agenda if it is present."
  2857. (mapc (lambda (o)
  2858. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2859. (delete-overlay o)))
  2860. (overlays-in (point-min) (point-max)))
  2861. (when (marker-buffer org-clock-hd-marker)
  2862. (save-excursion
  2863. (goto-char (point-min))
  2864. (let (s ov)
  2865. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2866. (goto-char s)
  2867. (when (equal (org-get-at-bol 'org-hd-marker)
  2868. org-clock-hd-marker)
  2869. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2870. (overlay-put ov 'type 'org-agenda-clocking)
  2871. (overlay-put ov 'face 'org-agenda-clocking)
  2872. (overlay-put ov 'help-echo
  2873. "The clock is running in this item")))))))
  2874. (defun org-agenda-fontify-priorities ()
  2875. "Make highest priority lines bold, and lowest italic."
  2876. (interactive)
  2877. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2878. (delete-overlay o)))
  2879. (overlays-in (point-min) (point-max)))
  2880. (save-excursion
  2881. (let ((inhibit-read-only t)
  2882. b e p ov h l)
  2883. (goto-char (point-min))
  2884. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2885. (setq h (or (get-char-property (point) 'org-highest-priority)
  2886. org-highest-priority)
  2887. l (or (get-char-property (point) 'org-lowest-priority)
  2888. org-lowest-priority)
  2889. p (string-to-char (match-string 1))
  2890. b (match-beginning 0)
  2891. e (if (eq org-agenda-fontify-priorities 'cookies)
  2892. (match-end 0)
  2893. (point-at-eol))
  2894. ov (make-overlay b e))
  2895. (overlay-put
  2896. ov 'face
  2897. (cond ((org-face-from-face-or-color
  2898. 'priority nil
  2899. (cdr (assoc p org-priority-faces))))
  2900. ((and (listp org-agenda-fontify-priorities)
  2901. (org-face-from-face-or-color
  2902. 'priority nil
  2903. (cdr (assoc p org-agenda-fontify-priorities)))))
  2904. ((equal p l) 'italic)
  2905. ((equal p h) 'bold)))
  2906. (overlay-put ov 'org-type 'org-priority)))))
  2907. (defun org-agenda-dim-blocked-tasks ()
  2908. "Dim currently blocked TODO's in the agenda display."
  2909. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2910. (delete-overlay o)))
  2911. (overlays-in (point-min) (point-max)))
  2912. (save-excursion
  2913. (let ((inhibit-read-only t)
  2914. (org-depend-tag-blocked nil)
  2915. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2916. org-blocked-by-checkboxes
  2917. invis1 b e p ov h l)
  2918. (goto-char (point-min))
  2919. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2920. (and pos (goto-char (1+ pos))))
  2921. (setq org-blocked-by-checkboxes nil invis1 invis)
  2922. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2923. (when (and marker
  2924. (with-current-buffer (marker-buffer marker)
  2925. (save-excursion (goto-char marker)
  2926. (org-entry-blocked-p))))
  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 dotodo)
  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. (doclosed org-agenda-show-log)
  3057. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3058. (current-buffer))))
  3059. (date (calendar-current-date))
  3060. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3061. (end (if (org-region-active-p) (region-end) (point-max)))
  3062. (day-numbers (org-get-all-dates beg end 'no-ranges
  3063. t doclosed ; always include today
  3064. org-timeline-show-empty-dates))
  3065. (org-deadline-warning-days 0)
  3066. (org-agenda-only-exact-dates t)
  3067. (today (org-today))
  3068. (past t)
  3069. args
  3070. s e rtn d emptyp)
  3071. (setq org-agenda-redo-command
  3072. (list 'progn
  3073. (list 'org-switch-to-buffer-other-window (current-buffer))
  3074. (list 'org-timeline (list 'quote dotodo))))
  3075. (if (not dopast)
  3076. ;; Remove past dates from the list of dates.
  3077. (setq day-numbers (delq nil (mapcar (lambda(x)
  3078. (if (>= x today) x nil))
  3079. day-numbers))))
  3080. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3081. (if doclosed (push :closed args))
  3082. (push :timestamp args)
  3083. (push :deadline args)
  3084. (push :scheduled args)
  3085. (push :sexp args)
  3086. (if dotodo (push :todo args))
  3087. (insert "Timeline of file " entry "\n")
  3088. (add-text-properties (point-min) (point)
  3089. (list 'face 'org-agenda-structure))
  3090. (org-agenda-mark-header-line (point-min))
  3091. (while (setq d (pop day-numbers))
  3092. (if (and (listp d) (eq (car d) :omitted))
  3093. (progn
  3094. (setq s (point))
  3095. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3096. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3097. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3098. (if (and (>= d today)
  3099. dopast
  3100. past)
  3101. (progn
  3102. (setq past nil)
  3103. (insert (make-string 79 ?-) "\n")))
  3104. (setq date (calendar-gregorian-from-absolute d))
  3105. (setq s (point))
  3106. (setq rtn (and (not emptyp)
  3107. (apply 'org-agenda-get-day-entries entry
  3108. date args)))
  3109. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3110. (progn
  3111. (insert
  3112. (if (stringp org-agenda-format-date)
  3113. (format-time-string org-agenda-format-date
  3114. (org-time-from-absolute date))
  3115. (funcall org-agenda-format-date date))
  3116. "\n")
  3117. (put-text-property s (1- (point)) 'face
  3118. (org-agenda-get-day-face date))
  3119. (put-text-property s (1- (point)) 'org-date-line t)
  3120. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3121. (if (equal d today)
  3122. (put-text-property s (1- (point)) 'org-today t))
  3123. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3124. (put-text-property s (1- (point)) 'day d)))))
  3125. (goto-char (point-min))
  3126. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3127. (point-min)))
  3128. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3129. (org-finalize-agenda)
  3130. (setq buffer-read-only t)))
  3131. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3132. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3133. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3134. not every single day in the range. If FORCE-TODAY is non-nil, make
  3135. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3136. inactive time stamps (those in square brackets) are included.
  3137. When EMPTY is non-nil, also include days without any entries."
  3138. (let ((re (concat
  3139. (if pre-re pre-re "")
  3140. (if inactive org-ts-regexp-both org-ts-regexp)))
  3141. dates dates1 date day day1 day2 ts1 ts2 pos)
  3142. (if force-today
  3143. (setq dates (list (org-today))))
  3144. (save-excursion
  3145. (goto-char beg)
  3146. (while (re-search-forward re end t)
  3147. (setq day (time-to-days (org-time-string-to-time
  3148. (substring (match-string 1) 0 10)
  3149. (current-buffer) (match-beginning 0))))
  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 pos (match-beginning 0))
  3155. (setq ts1 (substring (match-string 1) 0 10)
  3156. ts2 (substring (match-string 2) 0 10)
  3157. day1 (time-to-days (org-time-string-to-time
  3158. ts1 (current-buffer) pos))
  3159. day2 (time-to-days (org-time-string-to-time
  3160. ts2 (current-buffer) pos)))
  3161. (while (< (setq day1 (1+ day1)) day2)
  3162. (or (memq day1 dates) (push day1 dates)))))
  3163. (setq dates (sort dates '<))
  3164. (when empty
  3165. (while (setq day (pop dates))
  3166. (setq day2 (car dates))
  3167. (push day dates1)
  3168. (when (and day2 empty)
  3169. (if (or (eq empty t)
  3170. (and (numberp empty) (<= (- day2 day) empty)))
  3171. (while (< (setq day (1+ day)) day2)
  3172. (push (list day) dates1))
  3173. (push (cons :omitted (- day2 day)) dates1))))
  3174. (setq dates (nreverse dates1)))
  3175. dates)))
  3176. ;;; Agenda Daily/Weekly
  3177. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3178. "Start day for the agenda view.
  3179. Custom commands can set this variable in the options section.")
  3180. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3181. (defvar org-agenda-current-span nil
  3182. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3183. (defvar org-arg-loc nil) ; local variable
  3184. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3185. "List of types searched for when creating the daily/weekly agenda.
  3186. This variable is a list of symbols that controls the types of
  3187. items that appear in the daily/weekly agenda. Allowed symbols in this
  3188. list are are
  3189. :timestamp List items containing a date stamp or date range matching
  3190. the selected date. This includes sexp entries in
  3191. angular brackets.
  3192. :sexp List entries resulting from plain diary-like sexps.
  3193. :deadline List deadline due on that date. When the date is today,
  3194. also list any deadlines past due, or due within
  3195. `org-deadline-warning-days'. `:deadline' must appear before
  3196. `:scheduled' if the setting of
  3197. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3198. any effect.
  3199. :scheduled List all items which are scheduled for the given date.
  3200. The diary for *today* also contains items which were
  3201. scheduled earlier and are not yet marked DONE.
  3202. By default, all four types are turned on.
  3203. Never set this variable globally using `setq', because then it
  3204. will apply to all future agenda commands. Instead, bind it with
  3205. `let' to scope it dynamically into the agenda-constructing
  3206. command. A good way to set it is through options in
  3207. `org-agenda-custom-commands'. For a more flexible (though
  3208. somewhat less efficient) way of determining what is included in
  3209. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3210. ;;;###autoload
  3211. (defun org-agenda-list (&optional arg start-day span)
  3212. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3213. The view will be for the current day or week, but from the overview buffer
  3214. you will be able to go to other days/weeks.
  3215. With a numeric prefix argument in an interactive call, the agenda will
  3216. span ARG days. Lisp programs should instead specify SPAN to change
  3217. the number of days. SPAN defaults to `org-agenda-span'.
  3218. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3219. given in `org-agenda-start-on-weekday'."
  3220. (interactive "P")
  3221. (if (and (integerp arg) (> arg 0))
  3222. (setq span arg arg nil))
  3223. (setq start-day (or start-day org-agenda-start-day))
  3224. (if org-agenda-overriding-arguments
  3225. (setq arg (car org-agenda-overriding-arguments)
  3226. start-day (nth 1 org-agenda-overriding-arguments)
  3227. span (nth 2 org-agenda-overriding-arguments)))
  3228. (if (stringp start-day)
  3229. ;; Convert to an absolute day number
  3230. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3231. (setq org-agenda-last-arguments (list arg start-day span))
  3232. (org-compile-prefix-format 'agenda)
  3233. (org-set-sorting-strategy 'agenda)
  3234. (let* ((span (org-agenda-ndays-to-span
  3235. (or span org-agenda-ndays org-agenda-span)))
  3236. (today (org-today))
  3237. (sd (or start-day today))
  3238. (ndays (org-agenda-span-to-ndays span sd))
  3239. (org-agenda-start-on-weekday
  3240. (if (eq ndays 7)
  3241. org-agenda-start-on-weekday))
  3242. (thefiles (org-agenda-files nil 'ifmode))
  3243. (files thefiles)
  3244. (start (if (or (null org-agenda-start-on-weekday)
  3245. (< ndays 7))
  3246. sd
  3247. (let* ((nt (calendar-day-of-week
  3248. (calendar-gregorian-from-absolute sd)))
  3249. (n1 org-agenda-start-on-weekday)
  3250. (d (- nt n1)))
  3251. (- sd (+ (if (< d 0) 7 0) d)))))
  3252. (day-numbers (list start))
  3253. (day-cnt 0)
  3254. (inhibit-redisplay (not debug-on-error))
  3255. s e rtn rtnall file date d start-pos end-pos todayp
  3256. clocktable-start clocktable-end filter)
  3257. (setq org-agenda-redo-command
  3258. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3259. (dotimes (n (1- ndays))
  3260. (push (1+ (car day-numbers)) day-numbers))
  3261. (setq day-numbers (nreverse day-numbers))
  3262. (setq clocktable-start (car day-numbers)
  3263. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3264. (org-prepare-agenda "Day/Week")
  3265. (org-set-local 'org-starting-day (car day-numbers))
  3266. (org-set-local 'org-arg-loc arg)
  3267. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3268. (unless org-agenda-compact-blocks
  3269. (let* ((d1 (car day-numbers))
  3270. (d2 (org-last day-numbers))
  3271. (w1 (org-days-to-iso-week d1))
  3272. (w2 (org-days-to-iso-week d2)))
  3273. (setq s (point))
  3274. (if org-agenda-overriding-header
  3275. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3276. nil 'face 'org-agenda-structure) "\n")
  3277. (insert (org-agenda-span-name span)
  3278. "-agenda"
  3279. (if (< (- d2 d1) 350)
  3280. (if (= w1 w2)
  3281. (format " (W%02d)" w1)
  3282. (format " (W%02d-W%02d)" w1 w2))
  3283. "")
  3284. ":\n")))
  3285. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3286. 'org-date-line t))
  3287. (org-agenda-mark-header-line s))
  3288. (while (setq d (pop day-numbers))
  3289. (setq date (calendar-gregorian-from-absolute d)
  3290. s (point))
  3291. (if (or (setq todayp (= d today))
  3292. (and (not start-pos) (= d sd)))
  3293. (setq start-pos (point))
  3294. (if (and start-pos (not end-pos))
  3295. (setq end-pos (point))))
  3296. (setq files thefiles
  3297. rtnall nil)
  3298. (while (setq file (pop files))
  3299. (catch 'nextfile
  3300. (org-check-agenda-file file)
  3301. (let ((org-agenda-entry-types org-agenda-entry-types))
  3302. (unless org-agenda-include-deadlines
  3303. (setq org-agenda-entry-types
  3304. (delq :deadline org-agenda-entry-types)))
  3305. (cond
  3306. ((memq org-agenda-show-log '(only clockcheck))
  3307. (setq rtn (org-agenda-get-day-entries
  3308. file date :closed)))
  3309. (org-agenda-show-log
  3310. (setq rtn (apply 'org-agenda-get-day-entries
  3311. file date
  3312. (append '(:closed) org-agenda-entry-types))))
  3313. (t
  3314. (setq rtn (apply 'org-agenda-get-day-entries
  3315. file date
  3316. org-agenda-entry-types)))))
  3317. (setq rtnall (append rtnall rtn))))
  3318. (if org-agenda-include-diary
  3319. (let ((org-agenda-search-headline-for-time t))
  3320. (require 'diary-lib)
  3321. (setq rtn (org-get-entries-from-diary date))
  3322. (setq rtnall (append rtnall rtn))))
  3323. (if (or rtnall org-agenda-show-all-dates)
  3324. (progn
  3325. (setq day-cnt (1+ day-cnt))
  3326. (insert
  3327. (if (stringp org-agenda-format-date)
  3328. (format-time-string org-agenda-format-date
  3329. (org-time-from-absolute date))
  3330. (funcall org-agenda-format-date date))
  3331. "\n")
  3332. (put-text-property s (1- (point)) 'face
  3333. (org-agenda-get-day-face date))
  3334. (put-text-property s (1- (point)) 'org-date-line t)
  3335. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3336. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3337. (when todayp
  3338. (put-text-property s (1- (point)) 'org-today t))
  3339. (if rtnall (insert
  3340. (org-finalize-agenda-entries
  3341. (org-agenda-add-time-grid-maybe
  3342. rtnall ndays todayp))
  3343. "\n"))
  3344. (put-text-property s (1- (point)) 'day d)
  3345. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3346. (when (and org-agenda-clockreport-mode clocktable-start)
  3347. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3348. ;; the above line is to ensure the restricted range!
  3349. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3350. tbl)
  3351. (setq p (org-plist-delete p :block))
  3352. (setq p (plist-put p :tstart clocktable-start))
  3353. (setq p (plist-put p :tend clocktable-end))
  3354. (setq p (plist-put p :scope 'agenda))
  3355. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3356. (setq filter (or org-agenda-filter-while-redo
  3357. (get 'org-agenda-filter :preset-filter))))
  3358. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3359. (if (string-match "[<>=]" x)
  3360. ""
  3361. x))
  3362. filter ""))))
  3363. (setq tbl (apply 'org-get-clocktable p))
  3364. (insert tbl)))
  3365. (goto-char (point-min))
  3366. (or org-agenda-multi (org-fit-agenda-window))
  3367. (unless (and (pos-visible-in-window-p (point-min))
  3368. (pos-visible-in-window-p (point-max)))
  3369. (goto-char (1- (point-max)))
  3370. (recenter -1)
  3371. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3372. (progn
  3373. (goto-char (or start-pos 1))
  3374. (recenter 1))))
  3375. (goto-char (or start-pos 1))
  3376. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3377. (if (eq org-agenda-show-log 'clockcheck)
  3378. (org-agenda-show-clocking-issues))
  3379. (org-finalize-agenda)
  3380. (setq buffer-read-only t)
  3381. (message "")))
  3382. (defun org-agenda-ndays-to-span (n)
  3383. "Return a span symbol for a span of N days, or N if none matches."
  3384. (cond ((symbolp n) n)
  3385. ((= n 1) 'day)
  3386. ((= n 7) 'week)
  3387. (t n)))
  3388. (defun org-agenda-span-to-ndays (span start-day)
  3389. "Return ndays from SPAN starting at START-DAY."
  3390. (cond ((numberp span) span)
  3391. ((eq span 'day) 1)
  3392. ((eq span 'week) 7)
  3393. ((eq span 'month)
  3394. (let ((date (calendar-gregorian-from-absolute start-day)))
  3395. (calendar-last-day-of-month (car date) (caddr date))))
  3396. ((eq span 'year)
  3397. (let ((date (calendar-gregorian-from-absolute start-day)))
  3398. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3399. (defun org-agenda-span-name (span)
  3400. "Return a SPAN name."
  3401. (if (null span)
  3402. ""
  3403. (if (symbolp span)
  3404. (capitalize (symbol-name span))
  3405. (format "%d days" span))))
  3406. ;;; Agenda word search
  3407. (defvar org-agenda-search-history nil)
  3408. (defvar org-todo-only nil)
  3409. (defvar org-search-syntax-table nil
  3410. "Special syntax table for org-mode search.
  3411. In this table, we have single quotes not as word constituents, to
  3412. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3413. (defun org-search-syntax-table ()
  3414. (unless org-search-syntax-table
  3415. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3416. (modify-syntax-entry ?' "." org-search-syntax-table)
  3417. (modify-syntax-entry ?` "." org-search-syntax-table))
  3418. org-search-syntax-table)
  3419. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3420. ;;;###autoload
  3421. (defun org-search-view (&optional todo-only string edit-at)
  3422. "Show all entries that contain a phrase or words or regular expressions.
  3423. With optional prefix argument TODO-ONLY, only consider entries that are
  3424. TODO entries. The argument STRING can be used to pass a default search
  3425. string into this function. If EDIT-AT is non-nil, it means that the
  3426. user should get a chance to edit this string, with cursor at position
  3427. EDIT-AT.
  3428. The search string can be viewed either as a phrase that should be found as
  3429. is, or it can be broken into a number of snippets, each of which must match
  3430. in a Boolean way to select an entry. The default depends on the variable
  3431. `org-agenda-search-view-always-boolean'.
  3432. Even if this is turned off (the default) you can always switch to
  3433. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3434. The default is a direct search of the whole phrase, where each space in
  3435. the search string can expand to an arbitrary amount of whitespace,
  3436. including newlines.
  3437. If using a Boolean search, the search string is split on whitespace and
  3438. each snippet is searched separately, with logical AND to select an entry.
  3439. Words prefixed with a minus must *not* occur in the entry. Words without
  3440. a prefix or prefixed with a plus must occur in the entry. Matching is
  3441. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3442. match whole words, not parts of a word) if
  3443. `org-agenda-search-view-force-full-words' is set (default is nil).
  3444. Boolean search snippets enclosed by curly braces are interpreted as
  3445. regular expressions that must or (when preceded with \"-\") must not
  3446. match in the entry. Snippets enclosed into double quotes will be taken
  3447. as a whole, to include whitespace.
  3448. - If the search string starts with an asterisk, search only in headlines.
  3449. - If (possibly after the leading star) the search string starts with an
  3450. exclamation mark, this also means to look at TODO entries only, an effect
  3451. that can also be achieved with a prefix argument.
  3452. - If (possibly after star and exclamation mark) the search string starts
  3453. with a colon, this will mean that the (non-regexp) snippets of the
  3454. Boolean search must match as full words.
  3455. This command searches the agenda files, and in addition the files listed
  3456. in `org-agenda-text-search-extra-files'."
  3457. (interactive "P")
  3458. (org-compile-prefix-format 'search)
  3459. (org-set-sorting-strategy 'search)
  3460. (org-prepare-agenda "SEARCH")
  3461. (let* ((props (list 'face nil
  3462. 'done-face 'org-agenda-done
  3463. 'org-not-done-regexp org-not-done-regexp
  3464. 'org-todo-regexp org-todo-regexp
  3465. 'org-complex-heading-regexp org-complex-heading-regexp
  3466. 'mouse-face 'highlight
  3467. 'help-echo (format "mouse-2 or RET jump to location")))
  3468. (full-words org-agenda-search-view-force-full-words)
  3469. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3470. regexp rtn rtnall files file pos
  3471. marker category category-pos tags c neg re boolean
  3472. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3473. (unless (and (not edit-at)
  3474. (stringp string)
  3475. (string-match "\\S-" string))
  3476. (setq string (read-string
  3477. (if org-agenda-search-view-always-boolean
  3478. "[+-]Word/{Regexp} ...: "
  3479. "Phrase, or [+-]Word/{Regexp} ...: ")
  3480. (cond
  3481. ((integerp edit-at) (cons string edit-at))
  3482. (edit-at string))
  3483. 'org-agenda-search-history)))
  3484. (org-set-local 'org-todo-only todo-only)
  3485. (setq org-agenda-redo-command
  3486. (list 'org-search-view (if todo-only t nil) string
  3487. '(if current-prefix-arg 1 nil)))
  3488. (setq org-agenda-query-string string)
  3489. (if (equal (string-to-char string) ?*)
  3490. (setq hdl-only t
  3491. words (substring string 1))
  3492. (setq words string))
  3493. (when (equal (string-to-char words) ?!)
  3494. (setq todo-only t
  3495. words (substring words 1)))
  3496. (when (equal (string-to-char words) ?:)
  3497. (setq full-words t
  3498. words (substring words 1)))
  3499. (if (or org-agenda-search-view-always-boolean
  3500. (member (string-to-char words) '(?- ?+ ?\{)))
  3501. (setq boolean t))
  3502. (setq words (org-split-string words))
  3503. (let (www w)
  3504. (while (setq w (pop words))
  3505. (while (and (string-match "\\\\\\'" w) words)
  3506. (setq w (concat (substring w 0 -1) " " (pop words))))
  3507. (push w www))
  3508. (setq words (nreverse www) www nil)
  3509. (while (setq w (pop words))
  3510. (when (and (string-match "\\`[-+]?{" w)
  3511. (not (string-match "}\\'" w)))
  3512. (while (and words (not (string-match "}\\'" (car words))))
  3513. (setq w (concat w " " (pop words))))
  3514. (setq w (concat w " " (pop words))))
  3515. (push w www))
  3516. (setq words (nreverse www)))
  3517. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3518. (when boolean
  3519. (let (wds w)
  3520. (while (setq w (pop words))
  3521. (if (or (equal (substring w 0 1) "\"")
  3522. (and (> (length w) 1)
  3523. (member (substring w 0 1) '("+" "-"))
  3524. (equal (substring w 1 2) "\"")))
  3525. (while (and words (not (equal (substring w -1) "\"")))
  3526. (setq w (concat w " " (pop words)))))
  3527. (and (string-match "\\`\\([-+]?\\)\"" w)
  3528. (setq w (replace-match "\\1" nil nil w)))
  3529. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3530. (push w wds))
  3531. (setq words (nreverse wds))))
  3532. (if boolean
  3533. (mapc (lambda (w)
  3534. (setq c (string-to-char w))
  3535. (if (equal c ?-)
  3536. (setq neg t w (substring w 1))
  3537. (if (equal c ?+)
  3538. (setq neg nil w (substring w 1))
  3539. (setq neg nil)))
  3540. (if (string-match "\\`{.*}\\'" w)
  3541. (setq re (substring w 1 -1))
  3542. (if full-words
  3543. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3544. (setq re (regexp-quote (downcase w)))))
  3545. (if neg (push re regexps-) (push re regexps+)))
  3546. words)
  3547. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3548. regexps+))
  3549. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3550. (if (not regexps+)
  3551. (setq regexp org-outline-regexp-bol)
  3552. (setq regexp (pop regexps+))
  3553. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3554. regexp))))
  3555. (setq files (org-agenda-files nil 'ifmode))
  3556. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3557. (pop org-agenda-text-search-extra-files)
  3558. (setq files (org-add-archive-files files)))
  3559. (setq files (append files org-agenda-text-search-extra-files)
  3560. rtnall nil)
  3561. (while (setq file (pop files))
  3562. (setq ee nil)
  3563. (catch 'nextfile
  3564. (org-check-agenda-file file)
  3565. (setq buffer (if (file-exists-p file)
  3566. (org-get-agenda-file-buffer file)
  3567. (error "No such file %s" file)))
  3568. (if (not buffer)
  3569. ;; If file does not exist, make sure an error message is sent
  3570. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3571. file))))
  3572. (with-current-buffer buffer
  3573. (with-syntax-table (org-search-syntax-table)
  3574. (unless (org-mode-p)
  3575. (error "Agenda file %s is not in `org-mode'" file))
  3576. (let ((case-fold-search t))
  3577. (save-excursion
  3578. (save-restriction
  3579. (if org-agenda-restrict
  3580. (narrow-to-region org-agenda-restrict-begin
  3581. org-agenda-restrict-end)
  3582. (widen))
  3583. (goto-char (point-min))
  3584. (unless (or (org-on-heading-p)
  3585. (outline-next-heading))
  3586. (throw 'nextfile t))
  3587. (goto-char (max (point-min) (1- (point))))
  3588. (while (re-search-forward regexp nil t)
  3589. (org-back-to-heading t)
  3590. (skip-chars-forward "* ")
  3591. (setq beg (point-at-bol)
  3592. beg1 (point)
  3593. end (progn (outline-next-heading) (point)))
  3594. (catch :skip
  3595. (goto-char beg)
  3596. (org-agenda-skip)
  3597. (setq str (buffer-substring-no-properties
  3598. (point-at-bol)
  3599. (if hdl-only (point-at-eol) end)))
  3600. (mapc (lambda (wr) (when (string-match wr str)
  3601. (goto-char (1- end))
  3602. (throw :skip t)))
  3603. regexps-)
  3604. (mapc (lambda (wr) (unless (string-match wr str)
  3605. (goto-char (1- end))
  3606. (throw :skip t)))
  3607. (if todo-only
  3608. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3609. regexps+)
  3610. regexps+))
  3611. (goto-char beg)
  3612. (setq marker (org-agenda-new-marker (point))
  3613. category (org-get-category)
  3614. category-pos (get-text-property (point) 'org-category-position)
  3615. tags (org-get-tags-at (point))
  3616. txt (org-format-agenda-item
  3617. ""
  3618. (buffer-substring-no-properties
  3619. beg1 (point-at-eol))
  3620. category tags))
  3621. (org-add-props txt props
  3622. 'org-marker marker 'org-hd-marker marker
  3623. 'org-todo-regexp org-todo-regexp
  3624. 'org-complex-heading-regexp org-complex-heading-regexp
  3625. 'priority 1000 'org-category category
  3626. 'org-category-position category-pos
  3627. 'type "search")
  3628. (push txt ee)
  3629. (goto-char (1- end))))))))))
  3630. (setq rtn (nreverse ee))
  3631. (setq rtnall (append rtnall rtn)))
  3632. (if org-agenda-overriding-header
  3633. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3634. nil 'face 'org-agenda-structure) "\n")
  3635. (insert "Search words: ")
  3636. (add-text-properties (point-min) (1- (point))
  3637. (list 'face 'org-agenda-structure))
  3638. (setq pos (point))
  3639. (insert string "\n")
  3640. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3641. (setq pos (point))
  3642. (unless org-agenda-multi
  3643. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3644. (add-text-properties pos (1- (point))
  3645. (list 'face 'org-agenda-structure))))
  3646. (org-agenda-mark-header-line (point-min))
  3647. (when rtnall
  3648. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3649. (goto-char (point-min))
  3650. (or org-agenda-multi (org-fit-agenda-window))
  3651. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3652. (org-finalize-agenda)
  3653. (setq buffer-read-only t)))
  3654. ;;; Agenda TODO list
  3655. (defvar org-select-this-todo-keyword nil)
  3656. (defvar org-last-arg nil)
  3657. ;;;###autoload
  3658. (defun org-todo-list (arg)
  3659. "Show all (not done) TODO entries from all agenda file in a single list.
  3660. The prefix arg can be used to select a specific TODO keyword and limit
  3661. the list to these. When using \\[universal-argument], you will be prompted
  3662. for a keyword. A numeric prefix directly selects the Nth keyword in
  3663. `org-todo-keywords-1'."
  3664. (interactive "P")
  3665. (org-compile-prefix-format 'todo)
  3666. (org-set-sorting-strategy 'todo)
  3667. (org-prepare-agenda "TODO")
  3668. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3669. (let* ((today (org-today))
  3670. (date (calendar-gregorian-from-absolute today))
  3671. (kwds org-todo-keywords-for-agenda)
  3672. (completion-ignore-case t)
  3673. (org-select-this-todo-keyword
  3674. (if (stringp arg) arg
  3675. (and arg (integerp arg) (> arg 0)
  3676. (nth (1- arg) kwds))))
  3677. rtn rtnall files file pos)
  3678. (when (equal arg '(4))
  3679. (setq org-select-this-todo-keyword
  3680. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3681. (mapcar 'list kwds) nil nil)))
  3682. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3683. (org-set-local 'org-last-arg arg)
  3684. (setq org-agenda-redo-command
  3685. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3686. (setq files (org-agenda-files nil 'ifmode)
  3687. rtnall nil)
  3688. (while (setq file (pop files))
  3689. (catch 'nextfile
  3690. (org-check-agenda-file file)
  3691. (setq rtn (org-agenda-get-day-entries file date :todo))
  3692. (setq rtnall (append rtnall rtn))))
  3693. (if org-agenda-overriding-header
  3694. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3695. nil 'face 'org-agenda-structure) "\n")
  3696. (insert "Global list of TODO items of type: ")
  3697. (add-text-properties (point-min) (1- (point))
  3698. (list 'face 'org-agenda-structure
  3699. 'short-heading
  3700. (concat "ToDo: "
  3701. (or org-select-this-todo-keyword "ALL"))))
  3702. (org-agenda-mark-header-line (point-min))
  3703. (setq pos (point))
  3704. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3705. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3706. (setq pos (point))
  3707. (unless org-agenda-multi
  3708. (insert "Available with `N r': (0)ALL")
  3709. (let ((n 0) s)
  3710. (mapc (lambda (x)
  3711. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3712. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3713. (insert "\n "))
  3714. (insert " " s))
  3715. kwds))
  3716. (insert "\n"))
  3717. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3718. (org-agenda-mark-header-line (point-min))
  3719. (when rtnall
  3720. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3721. (goto-char (point-min))
  3722. (or org-agenda-multi (org-fit-agenda-window))
  3723. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3724. (org-finalize-agenda)
  3725. (setq buffer-read-only t)))
  3726. ;;; Agenda tags match
  3727. ;;;###autoload
  3728. (defun org-tags-view (&optional todo-only match)
  3729. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3730. The prefix arg TODO-ONLY limits the search to TODO entries."
  3731. (interactive "P")
  3732. (org-compile-prefix-format 'tags)
  3733. (org-set-sorting-strategy 'tags)
  3734. (let* ((org-tags-match-list-sublevels
  3735. org-tags-match-list-sublevels)
  3736. (completion-ignore-case t)
  3737. rtn rtnall files file pos matcher
  3738. buffer)
  3739. (when (and (stringp match) (not (string-match "\\S-" match)))
  3740. (setq match nil))
  3741. (setq matcher (org-make-tags-matcher match)
  3742. match (car matcher) matcher (cdr matcher))
  3743. (org-prepare-agenda (concat "TAGS " match))
  3744. (setq org-agenda-query-string match)
  3745. (setq org-agenda-redo-command
  3746. (list 'org-tags-view (list 'quote todo-only)
  3747. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3748. (setq files (org-agenda-files nil 'ifmode)
  3749. rtnall nil)
  3750. (while (setq file (pop files))
  3751. (catch 'nextfile
  3752. (org-check-agenda-file file)
  3753. (setq buffer (if (file-exists-p file)
  3754. (org-get-agenda-file-buffer file)
  3755. (error "No such file %s" file)))
  3756. (if (not buffer)
  3757. ;; If file does not exist, error message to agenda
  3758. (setq rtn (list
  3759. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3760. rtnall (append rtnall rtn))
  3761. (with-current-buffer buffer
  3762. (unless (org-mode-p)
  3763. (error "Agenda file %s is not in `org-mode'" file))
  3764. (save-excursion
  3765. (save-restriction
  3766. (if org-agenda-restrict
  3767. (narrow-to-region org-agenda-restrict-begin
  3768. org-agenda-restrict-end)
  3769. (widen))
  3770. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3771. (setq rtnall (append rtnall rtn))))))))
  3772. (if org-agenda-overriding-header
  3773. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3774. nil 'face 'org-agenda-structure) "\n")
  3775. (insert "Headlines with TAGS match: ")
  3776. (add-text-properties (point-min) (1- (point))
  3777. (list 'face 'org-agenda-structure
  3778. 'short-heading
  3779. (concat "Match: " match)))
  3780. (setq pos (point))
  3781. (insert match "\n")
  3782. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3783. (setq pos (point))
  3784. (unless org-agenda-multi
  3785. (insert "Press `C-u r' to search again with new search string\n"))
  3786. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3787. (org-agenda-mark-header-line (point-min))
  3788. (when rtnall
  3789. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3790. (goto-char (point-min))
  3791. (or org-agenda-multi (org-fit-agenda-window))
  3792. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3793. (org-finalize-agenda)
  3794. (setq buffer-read-only t)))
  3795. ;;; Agenda Finding stuck projects
  3796. (defvar org-agenda-skip-regexp nil
  3797. "Regular expression used in skipping subtrees for the agenda.
  3798. This is basically a temporary global variable that can be set and then
  3799. used by user-defined selections using `org-agenda-skip-function'.")
  3800. (defvar org-agenda-overriding-header nil
  3801. "When set during agenda, todo and tags searches it replaces the header.
  3802. This variable should not be set directly, but custom commands can bind it
  3803. in the options section.")
  3804. (defun org-agenda-skip-entry-when-regexp-matches ()
  3805. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3806. If yes, it returns the end position of this entry, causing agenda commands
  3807. to skip the entry but continuing the search in the subtree. This is a
  3808. function that can be put into `org-agenda-skip-function' for the duration
  3809. of a command."
  3810. (let ((end (save-excursion (org-end-of-subtree t)))
  3811. skip)
  3812. (save-excursion
  3813. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3814. (and skip end)))
  3815. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3816. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3817. If yes, it returns the end position of this tree, causing agenda commands
  3818. to skip this subtree. This is a function that can be put into
  3819. `org-agenda-skip-function' for the duration of a command."
  3820. (let ((end (save-excursion (org-end-of-subtree t)))
  3821. skip)
  3822. (save-excursion
  3823. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3824. (and skip end)))
  3825. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3826. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3827. If yes, it returns the end position of the current entry (NOT the tree),
  3828. causing agenda commands to skip the entry but continuing the search in
  3829. the subtree. This is a function that can be put into
  3830. `org-agenda-skip-function' for the duration of a command. An important
  3831. use of this function is for the stuck project list."
  3832. (let ((end (save-excursion (org-end-of-subtree t)))
  3833. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3834. skip)
  3835. (save-excursion
  3836. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3837. (and skip entry-end)))
  3838. (defun org-agenda-skip-entry-if (&rest conditions)
  3839. "Skip entry if any of CONDITIONS is true.
  3840. See `org-agenda-skip-if' for details."
  3841. (org-agenda-skip-if nil conditions))
  3842. (defun org-agenda-skip-subtree-if (&rest conditions)
  3843. "Skip entry if any of CONDITIONS is true.
  3844. See `org-agenda-skip-if' for details."
  3845. (org-agenda-skip-if t conditions))
  3846. (defun org-agenda-skip-if (subtree conditions)
  3847. "Checks current entity for CONDITIONS.
  3848. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3849. the entry, i.e. the text before the next heading is checked.
  3850. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3851. from different tests. Valid conditions are:
  3852. scheduled Check if there is a scheduled cookie
  3853. notscheduled Check if there is no scheduled cookie
  3854. deadline Check if there is a deadline
  3855. notdeadline Check if there is no deadline
  3856. timestamp Check if there is a timestamp (also deadline or scheduled)
  3857. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3858. regexp Check if regexp matches
  3859. notregexp Check if regexp does not match.
  3860. todo Check if TODO keyword matches
  3861. nottodo Check if TODO keyword does not match
  3862. The regexp is taken from the conditions list, it must come right after
  3863. the `regexp' or `notregexp' element.
  3864. `todo' and `nottodo' accept as an argument a list of todo
  3865. keywords, which may include \"*\" to match any todo keyword.
  3866. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3867. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3868. Instead of a list a keyword class may be given
  3869. (org-agenda-skip-entry-if 'nottodo 'done)
  3870. would skip entries that haven't been marked with any of \"DONE\"
  3871. keywords. Possible classes are: `todo', `done', `any'.
  3872. If any of these conditions is met, this function returns the end point of
  3873. the entity, causing the search to continue from there. This is a function
  3874. that can be put into `org-agenda-skip-function' for the duration of a command."
  3875. (let (beg end m)
  3876. (org-back-to-heading t)
  3877. (setq beg (point)
  3878. end (if subtree
  3879. (progn (org-end-of-subtree t) (point))
  3880. (progn (outline-next-heading) (1- (point)))))
  3881. (goto-char beg)
  3882. (and
  3883. (or
  3884. (and (memq 'scheduled conditions)
  3885. (re-search-forward org-scheduled-time-regexp end t))
  3886. (and (memq 'notscheduled conditions)
  3887. (not (re-search-forward org-scheduled-time-regexp end t)))
  3888. (and (memq 'deadline conditions)
  3889. (re-search-forward org-deadline-time-regexp end t))
  3890. (and (memq 'notdeadline conditions)
  3891. (not (re-search-forward org-deadline-time-regexp end t)))
  3892. (and (memq 'timestamp conditions)
  3893. (re-search-forward org-ts-regexp end t))
  3894. (and (memq 'nottimestamp conditions)
  3895. (not (re-search-forward org-ts-regexp end t)))
  3896. (and (setq m (memq 'regexp conditions))
  3897. (stringp (nth 1 m))
  3898. (re-search-forward (nth 1 m) end t))
  3899. (and (setq m (memq 'notregexp conditions))
  3900. (stringp (nth 1 m))
  3901. (not (re-search-forward (nth 1 m) end t)))
  3902. (and (or
  3903. (setq m (memq 'todo conditions))
  3904. (setq m (memq 'nottodo conditions)))
  3905. (org-agenda-skip-if-todo m end)))
  3906. end)))
  3907. (defun org-agenda-skip-if-todo (args end)
  3908. "Helper function for `org-agenda-skip-if', do not use it directly.
  3909. ARGS is a list with first element either `todo' or `nottodo'.
  3910. The remainder is either a list of TODO keywords, or a state symbol
  3911. `todo' or `done' or `any'."
  3912. (let ((kw (car args))
  3913. (arg (cadr args))
  3914. todo-wds todo-re)
  3915. (setq todo-wds
  3916. (org-uniquify
  3917. (cond
  3918. ((listp arg) ;; list of keywords
  3919. (if (member "*" arg)
  3920. (mapcar 'substring-no-properties org-todo-keywords-1)
  3921. arg))
  3922. ((symbolp arg) ;; keyword class name
  3923. (cond
  3924. ((eq arg 'todo)
  3925. (org-delete-all org-done-keywords
  3926. (mapcar 'substring-no-properties
  3927. org-todo-keywords-1)))
  3928. ((eq arg 'done) org-done-keywords)
  3929. ((eq arg 'any)
  3930. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3931. (setq todo-re
  3932. (concat "^\\*+[ \t]+\\<\\("
  3933. (mapconcat 'identity todo-wds "\\|")
  3934. "\\)\\>"))
  3935. (if (eq kw 'todo)
  3936. (re-search-forward todo-re end t)
  3937. (not (re-search-forward todo-re end t)))))
  3938. ;;;###autoload
  3939. (defun org-agenda-list-stuck-projects (&rest ignore)
  3940. "Create agenda view for projects that are stuck.
  3941. Stuck projects are project that have no next actions. For the definitions
  3942. of what a project is and how to check if it stuck, customize the variable
  3943. `org-stuck-projects'."
  3944. (interactive)
  3945. (let* ((org-agenda-skip-function
  3946. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3947. ;; We could have used org-agenda-skip-if here.
  3948. (org-agenda-overriding-header
  3949. (or org-agenda-overriding-header "List of stuck projects: "))
  3950. (matcher (nth 0 org-stuck-projects))
  3951. (todo (nth 1 org-stuck-projects))
  3952. (todo-wds (if (member "*" todo)
  3953. (progn
  3954. (org-prepare-agenda-buffers (org-agenda-files
  3955. nil 'ifmode))
  3956. (org-delete-all
  3957. org-done-keywords-for-agenda
  3958. (copy-sequence org-todo-keywords-for-agenda)))
  3959. todo))
  3960. (todo-re (concat "^\\*+[ \t]+\\("
  3961. (mapconcat 'identity todo-wds "\\|")
  3962. "\\)\\>"))
  3963. (tags (nth 2 org-stuck-projects))
  3964. (tags-re (if (member "*" tags)
  3965. (org-re (concat org-outline-regexp-bol
  3966. ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3967. (if tags
  3968. (concat org-outline-regexp-bol
  3969. ".*:\\("
  3970. (mapconcat 'identity tags "\\|")
  3971. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3972. (gen-re (nth 3 org-stuck-projects))
  3973. (re-list
  3974. (delq nil
  3975. (list
  3976. (if todo todo-re)
  3977. (if tags tags-re)
  3978. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3979. gen-re)))))
  3980. (setq org-agenda-skip-regexp
  3981. (if re-list
  3982. (mapconcat 'identity re-list "\\|")
  3983. (error "No information how to identify unstuck projects")))
  3984. (org-tags-view nil matcher)
  3985. (with-current-buffer org-agenda-buffer-name
  3986. (setq org-agenda-redo-command
  3987. '(org-agenda-list-stuck-projects
  3988. (or current-prefix-arg org-last-arg))))))
  3989. ;;; Diary integration
  3990. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3991. (defvar list-diary-entries-hook)
  3992. (defvar diary-time-regexp)
  3993. (defun org-get-entries-from-diary (date)
  3994. "Get the (Emacs Calendar) diary entries for DATE."
  3995. (require 'diary-lib)
  3996. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3997. (diary-display-hook '(fancy-diary-display))
  3998. (diary-display-function 'fancy-diary-display)
  3999. (pop-up-frames nil)
  4000. (list-diary-entries-hook
  4001. (cons 'org-diary-default-entry list-diary-entries-hook))
  4002. (diary-file-name-prefix-function nil) ; turn this feature off
  4003. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4004. entries
  4005. (org-disable-agenda-to-diary t))
  4006. (save-excursion
  4007. (save-window-excursion
  4008. (funcall (if (fboundp 'diary-list-entries)
  4009. 'diary-list-entries 'list-diary-entries)
  4010. date 1)))
  4011. (if (not (get-buffer diary-fancy-buffer))
  4012. (setq entries nil)
  4013. (with-current-buffer diary-fancy-buffer
  4014. (setq buffer-read-only nil)
  4015. (if (zerop (buffer-size))
  4016. ;; No entries
  4017. (setq entries nil)
  4018. ;; Omit the date and other unnecessary stuff
  4019. (org-agenda-cleanup-fancy-diary)
  4020. ;; Add prefix to each line and extend the text properties
  4021. (if (zerop (buffer-size))
  4022. (setq entries nil)
  4023. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4024. (setq entries
  4025. (with-temp-buffer
  4026. (insert entries) (goto-char (point-min))
  4027. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4028. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4029. (replace-match (concat "; " (match-string 1)))))
  4030. (buffer-string)))))
  4031. (set-buffer-modified-p nil)
  4032. (kill-buffer diary-fancy-buffer)))
  4033. (when entries
  4034. (setq entries (org-split-string entries "\n"))
  4035. (setq entries
  4036. (mapcar
  4037. (lambda (x)
  4038. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4039. ;; Extend the text properties to the beginning of the line
  4040. (org-add-props x (text-properties-at (1- (length x)) x)
  4041. 'type "diary" 'date date 'face 'org-agenda-diary))
  4042. entries)))))
  4043. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4044. "Hook run when the fancy diary buffer is cleaned up.")
  4045. (defun org-agenda-cleanup-fancy-diary ()
  4046. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4047. This gets rid of the date, the underline under the date, and
  4048. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4049. date. It also removes lines that contain only whitespace."
  4050. (goto-char (point-min))
  4051. (if (looking-at ".*?:[ \t]*")
  4052. (progn
  4053. (replace-match "")
  4054. (re-search-forward "\n=+$" nil t)
  4055. (replace-match "")
  4056. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4057. (re-search-forward "\n=+$" nil t)
  4058. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4059. (goto-char (point-min))
  4060. (while (re-search-forward "^ +\n" nil t)
  4061. (replace-match ""))
  4062. (goto-char (point-min))
  4063. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4064. (replace-match ""))
  4065. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4066. ;; Make sure entries from the diary have the right text properties.
  4067. (eval-after-load "diary-lib"
  4068. '(if (boundp 'diary-modify-entry-list-string-function)
  4069. ;; We can rely on the hook, nothing to do
  4070. nil
  4071. ;; Hook not available, must use advice to make this work
  4072. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4073. "Make the position visible."
  4074. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4075. (stringp string)
  4076. buffer-file-name)
  4077. (setq string (org-modify-diary-entry-string string))))))
  4078. (defun org-modify-diary-entry-string (string)
  4079. "Add text properties to string, allowing org-mode to act on it."
  4080. (org-add-props string nil
  4081. 'mouse-face 'highlight
  4082. 'help-echo (if buffer-file-name
  4083. (format "mouse-2 or RET jump to diary file %s"
  4084. (abbreviate-file-name buffer-file-name))
  4085. "")
  4086. 'org-agenda-diary-link t
  4087. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4088. (defun org-diary-default-entry ()
  4089. "Add a dummy entry to the diary.
  4090. Needed to avoid empty dates which mess up holiday display."
  4091. ;; Catch the error if dealing with the new add-to-diary-alist
  4092. (when org-disable-agenda-to-diary
  4093. (condition-case nil
  4094. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4095. (error
  4096. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4097. (defun org-add-to-diary-list (&rest args)
  4098. (if (fboundp 'diary-add-to-list)
  4099. (apply 'diary-add-to-list args)
  4100. (apply 'add-to-diary-list args)))
  4101. (defvar org-diary-last-run-time nil)
  4102. ;;;###autoload
  4103. (defun org-diary (&rest args)
  4104. "Return diary information from org-files.
  4105. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4106. It accesses org files and extracts information from those files to be
  4107. listed in the diary. The function accepts arguments specifying what
  4108. items should be listed. For a list of arguments allowed here, see the
  4109. variable `org-agenda-entry-types'.
  4110. The call in the diary file should look like this:
  4111. &%%(org-diary) ~/path/to/some/orgfile.org
  4112. Use a separate line for each org file to check. Or, if you omit the file name,
  4113. all files listed in `org-agenda-files' will be checked automatically:
  4114. &%%(org-diary)
  4115. If you don't give any arguments (as in the example above), the default
  4116. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4117. So the example above may also be written as
  4118. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4119. The function expects the lisp variables `entry' and `date' to be provided
  4120. by the caller, because this is how the calendar works. Don't use this
  4121. function from a program - use `org-agenda-get-day-entries' instead."
  4122. (when (> (- (org-float-time)
  4123. org-agenda-last-marker-time)
  4124. 5)
  4125. (org-agenda-reset-markers))
  4126. (org-compile-prefix-format 'agenda)
  4127. (org-set-sorting-strategy 'agenda)
  4128. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4129. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4130. (list entry)
  4131. (org-agenda-files t)))
  4132. (time (org-float-time))
  4133. file rtn results)
  4134. (when (or (not org-diary-last-run-time)
  4135. (> (- time
  4136. org-diary-last-run-time)
  4137. 3))
  4138. (org-prepare-agenda-buffers files))
  4139. (setq org-diary-last-run-time time)
  4140. ;; If this is called during org-agenda, don't return any entries to
  4141. ;; the calendar. Org Agenda will list these entries itself.
  4142. (if org-disable-agenda-to-diary (setq files nil))
  4143. (while (setq file (pop files))
  4144. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4145. (setq results (append results rtn)))
  4146. (if results
  4147. (concat (org-finalize-agenda-entries results) "\n"))))
  4148. ;;; Agenda entry finders
  4149. (defun org-agenda-get-day-entries (file date &rest args)
  4150. "Does the work for `org-diary' and `org-agenda'.
  4151. FILE is the path to a file to be checked for entries. DATE is date like
  4152. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4153. which kind of entries should be extracted. For details about these, see
  4154. the documentation of `org-diary'."
  4155. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4156. (let* ((org-startup-folded nil)
  4157. (org-startup-align-all-tables nil)
  4158. (buffer (if (file-exists-p file)
  4159. (org-get-agenda-file-buffer file)
  4160. (error "No such file %s" file)))
  4161. arg results rtn deadline-results)
  4162. (if (not buffer)
  4163. ;; If file does not exist, make sure an error message ends up in diary
  4164. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4165. (with-current-buffer buffer
  4166. (unless (org-mode-p)
  4167. (error "Agenda file %s is not in `org-mode'" file))
  4168. (let ((case-fold-search nil))
  4169. (save-excursion
  4170. (save-restriction
  4171. (if org-agenda-restrict
  4172. (narrow-to-region org-agenda-restrict-begin
  4173. org-agenda-restrict-end)
  4174. (widen))
  4175. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4176. (while (setq arg (pop args))
  4177. (cond
  4178. ((and (eq arg :todo)
  4179. (equal date (calendar-gregorian-from-absolute
  4180. (org-today))))
  4181. (setq rtn (org-agenda-get-todos))
  4182. (setq results (append results rtn)))
  4183. ((eq arg :timestamp)
  4184. (setq rtn (org-agenda-get-blocks))
  4185. (setq results (append results rtn))
  4186. (setq rtn (org-agenda-get-timestamps))
  4187. (setq results (append results rtn)))
  4188. ((eq arg :sexp)
  4189. (setq rtn (org-agenda-get-sexps))
  4190. (setq results (append results rtn)))
  4191. ((eq arg :scheduled)
  4192. (setq rtn (org-agenda-get-scheduled deadline-results))
  4193. (setq results (append results rtn)))
  4194. ((eq arg :closed)
  4195. (setq rtn (org-agenda-get-progress))
  4196. (setq results (append results rtn)))
  4197. ((eq arg :deadline)
  4198. (setq rtn (org-agenda-get-deadlines))
  4199. (setq deadline-results (copy-sequence rtn))
  4200. (setq results (append results rtn))))))))
  4201. results))))
  4202. (defun org-agenda-get-todos ()
  4203. "Return the TODO information for agenda display."
  4204. (let* ((props (list 'face nil
  4205. 'done-face 'org-agenda-done
  4206. 'org-not-done-regexp org-not-done-regexp
  4207. 'org-todo-regexp org-todo-regexp
  4208. 'org-complex-heading-regexp org-complex-heading-regexp
  4209. 'mouse-face 'highlight
  4210. 'help-echo
  4211. (format "mouse-2 or RET jump to org file %s"
  4212. (abbreviate-file-name buffer-file-name))))
  4213. (regexp (concat "^\\*+[ \t]+\\("
  4214. (if org-select-this-todo-keyword
  4215. (if (equal org-select-this-todo-keyword "*")
  4216. org-todo-regexp
  4217. (concat "\\<\\("
  4218. (mapconcat 'identity
  4219. (org-split-string
  4220. org-select-this-todo-keyword "|") "\\|")
  4221. "\\)\\>"))
  4222. org-not-done-regexp)
  4223. "[^\n\r]*\\)"))
  4224. marker priority category category-pos tags todo-state ee txt beg end)
  4225. (goto-char (point-min))
  4226. (while (re-search-forward regexp nil t)
  4227. (catch :skip
  4228. (save-match-data
  4229. (beginning-of-line)
  4230. (org-agenda-skip)
  4231. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4232. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4233. (goto-char (1+ beg))
  4234. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4235. (throw :skip nil)))
  4236. (goto-char (match-beginning 1))
  4237. (setq marker (org-agenda-new-marker (match-beginning 0))
  4238. category (org-get-category)
  4239. category-pos (get-text-property (point) 'org-category-position)
  4240. txt (match-string 1)
  4241. tags (org-get-tags-at (point))
  4242. txt (org-format-agenda-item "" txt category tags)
  4243. priority (1+ (org-get-priority txt))
  4244. todo-state (org-get-todo-state))
  4245. (org-add-props txt props
  4246. 'org-marker marker 'org-hd-marker marker
  4247. 'priority priority 'org-category category
  4248. 'org-category-position category-pos
  4249. 'type "todo" 'todo-state todo-state)
  4250. (push txt ee)
  4251. (if org-agenda-todo-list-sublevels
  4252. (goto-char (match-end 1))
  4253. (org-end-of-subtree 'invisible))))
  4254. (nreverse ee)))
  4255. (defun org-agenda-todo-custom-ignore-p (time n)
  4256. "Check whether timestamp is farther away then n number of days.
  4257. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4258. `org-agenda-todo-ignore-scheduled' or
  4259. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4260. (let ((days (org-days-to-time time)))
  4261. (if (>= n 0)
  4262. (>= days n)
  4263. (<= days n))))
  4264. ;;;###autoload
  4265. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4266. (&optional end)
  4267. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4268. (when (or org-agenda-todo-ignore-with-date
  4269. org-agenda-todo-ignore-scheduled
  4270. org-agenda-todo-ignore-deadlines
  4271. org-agenda-todo-ignore-timestamp)
  4272. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4273. (save-excursion
  4274. (or (and org-agenda-todo-ignore-with-date
  4275. (re-search-forward org-ts-regexp end t))
  4276. (and org-agenda-todo-ignore-scheduled
  4277. (re-search-forward org-scheduled-time-regexp end t)
  4278. (cond
  4279. ((eq org-agenda-todo-ignore-scheduled 'future)
  4280. (> (org-days-to-time (match-string 1)) 0))
  4281. ((eq org-agenda-todo-ignore-scheduled 'past)
  4282. (<= (org-days-to-time (match-string 1)) 0))
  4283. ((numberp org-agenda-todo-ignore-scheduled)
  4284. (org-agenda-todo-custom-ignore-p
  4285. (match-string 1) org-agenda-todo-ignore-scheduled))
  4286. (t)))
  4287. (and org-agenda-todo-ignore-deadlines
  4288. (re-search-forward org-deadline-time-regexp end t)
  4289. (cond
  4290. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4291. ((eq org-agenda-todo-ignore-deadlines 'far)
  4292. (not (org-deadline-close (match-string 1))))
  4293. ((eq org-agenda-todo-ignore-deadlines 'future)
  4294. (> (org-days-to-time (match-string 1)) 0))
  4295. ((eq org-agenda-todo-ignore-deadlines 'past)
  4296. (<= (org-days-to-time (match-string 1)) 0))
  4297. ((numberp org-agenda-todo-ignore-deadlines)
  4298. (org-agenda-todo-custom-ignore-p
  4299. (match-string 1) org-agenda-todo-ignore-deadlines))
  4300. (t (org-deadline-close (match-string 1)))))
  4301. (and org-agenda-todo-ignore-timestamp
  4302. (let ((buffer (current-buffer))
  4303. (regexp
  4304. (concat
  4305. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4306. (start (point)))
  4307. ;; Copy current buffer into a temporary one
  4308. (with-temp-buffer
  4309. (insert-buffer-substring buffer start end)
  4310. (goto-char (point-min))
  4311. ;; Delete SCHEDULED and DEADLINE items
  4312. (while (re-search-forward regexp end t)
  4313. (delete-region (match-beginning 0) (match-end 0)))
  4314. (goto-char (point-min))
  4315. ;; No search for timestamp left
  4316. (when (re-search-forward org-ts-regexp nil t)
  4317. (cond
  4318. ((eq org-agenda-todo-ignore-timestamp 'future)
  4319. (> (org-days-to-time (match-string 1)) 0))
  4320. ((eq org-agenda-todo-ignore-timestamp 'past)
  4321. (<= (org-days-to-time (match-string 1)) 0))
  4322. ((numberp org-agenda-todo-ignore-timestamp)
  4323. (org-agenda-todo-custom-ignore-p
  4324. (match-string 1) org-agenda-todo-ignore-timestamp))
  4325. (t))))))))))
  4326. (defconst org-agenda-no-heading-message
  4327. "No heading for this item in buffer or region.")
  4328. (defun org-agenda-get-timestamps ()
  4329. "Return the date stamp information for agenda display."
  4330. (let* ((props (list 'face nil
  4331. 'org-not-done-regexp org-not-done-regexp
  4332. 'org-todo-regexp org-todo-regexp
  4333. 'org-complex-heading-regexp org-complex-heading-regexp
  4334. 'mouse-face 'highlight
  4335. 'help-echo
  4336. (format "mouse-2 or RET jump to org file %s"
  4337. (abbreviate-file-name buffer-file-name))))
  4338. (d1 (calendar-absolute-from-gregorian date))
  4339. (remove-re
  4340. (concat
  4341. (regexp-quote
  4342. (format-time-string
  4343. "<%Y-%m-%d"
  4344. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4345. ".*?>"))
  4346. (regexp
  4347. (concat
  4348. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4349. (regexp-quote
  4350. (substring
  4351. (format-time-string
  4352. (car org-time-stamp-formats)
  4353. (apply 'encode-time ; DATE bound by calendar
  4354. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4355. 1 11))
  4356. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4357. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4358. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4359. donep tmp priority category category-pos ee txt timestr tags
  4360. b0 b3 e3 head todo-state end-of-match show-all)
  4361. (goto-char (point-min))
  4362. (while (setq end-of-match (re-search-forward regexp nil t))
  4363. (setq b0 (match-beginning 0)
  4364. b3 (match-beginning 3) e3 (match-end 3)
  4365. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4366. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4367. (member todo-state
  4368. org-agenda-repeating-timestamp-show-all)))
  4369. (catch :skip
  4370. (and (org-at-date-range-p) (throw :skip nil))
  4371. (org-agenda-skip)
  4372. (if (and (match-end 1)
  4373. (not (= d1 (org-time-string-to-absolute
  4374. (match-string 1) d1 nil show-all
  4375. (current-buffer) b0))))
  4376. (throw :skip nil))
  4377. (if (and e3
  4378. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4379. (throw :skip nil))
  4380. (setq tmp (buffer-substring (max (point-min)
  4381. (- b0 org-ds-keyword-length))
  4382. b0)
  4383. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4384. inactivep (= (char-after b0) ?\[)
  4385. deadlinep (string-match org-deadline-regexp tmp)
  4386. scheduledp (string-match org-scheduled-regexp tmp)
  4387. closedp (and org-agenda-include-inactive-timestamps
  4388. (string-match org-closed-string tmp))
  4389. clockp (and org-agenda-include-inactive-timestamps
  4390. (or (string-match org-clock-string tmp)
  4391. (string-match "]-+\\'" tmp)))
  4392. donep (member todo-state org-done-keywords))
  4393. (if (or scheduledp deadlinep closedp clockp
  4394. (and donep org-agenda-skip-timestamp-if-done))
  4395. (throw :skip t))
  4396. (if (string-match ">" timestr)
  4397. ;; substring should only run to end of time stamp
  4398. (setq timestr (substring timestr 0 (match-end 0))))
  4399. (setq marker (org-agenda-new-marker b0)
  4400. category (org-get-category b0)
  4401. category-pos (get-text-property b0 'org-category-position))
  4402. (save-excursion
  4403. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4404. (setq txt org-agenda-no-heading-message)
  4405. (goto-char (match-beginning 0))
  4406. (setq hdmarker (org-agenda-new-marker)
  4407. tags (org-get-tags-at))
  4408. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4409. (setq head (or (match-string 1) ""))
  4410. (setq txt (org-format-agenda-item
  4411. (if inactivep org-agenda-inactive-leader nil)
  4412. head category tags timestr
  4413. remove-re)))
  4414. (setq priority (org-get-priority txt))
  4415. (org-add-props txt props
  4416. 'org-marker marker 'org-hd-marker hdmarker)
  4417. (org-add-props txt nil 'priority priority
  4418. 'org-category category 'date date
  4419. 'org-category-position category-pos
  4420. 'todo-state todo-state
  4421. 'type "timestamp")
  4422. (push txt ee))
  4423. (if org-agenda-skip-additional-timestamps-same-entry
  4424. (outline-next-heading)
  4425. (goto-char end-of-match))))
  4426. (nreverse ee)))
  4427. (defun org-agenda-get-sexps ()
  4428. "Return the sexp information for agenda display."
  4429. (require 'diary-lib)
  4430. (let* ((props (list 'mouse-face 'highlight
  4431. 'help-echo
  4432. (format "mouse-2 or RET jump to org file %s"
  4433. (abbreviate-file-name buffer-file-name))))
  4434. (regexp "^&?%%(")
  4435. marker category category-pos ee txt tags entry
  4436. result beg b sexp sexp-entry todo-state)
  4437. (goto-char (point-min))
  4438. (while (re-search-forward regexp nil t)
  4439. (catch :skip
  4440. (org-agenda-skip)
  4441. (setq beg (match-beginning 0))
  4442. (goto-char (1- (match-end 0)))
  4443. (setq b (point))
  4444. (forward-sexp 1)
  4445. (setq sexp (buffer-substring b (point)))
  4446. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4447. (org-trim (match-string 1))
  4448. ""))
  4449. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4450. (when result
  4451. (setq marker (org-agenda-new-marker beg)
  4452. category (org-get-category beg)
  4453. category-pos (get-text-property beg 'org-category-position)
  4454. todo-state (org-get-todo-state))
  4455. (dolist (r (if (stringp result)
  4456. (list result)
  4457. result)) ;; we expect a list here
  4458. (if (string-match "\\S-" r)
  4459. (setq txt r)
  4460. (setq txt "SEXP entry returned empty string"))
  4461. (setq txt (org-format-agenda-item
  4462. "" txt category tags 'time))
  4463. (org-add-props txt props 'org-marker marker)
  4464. (org-add-props txt nil
  4465. 'org-category category 'date date 'todo-state todo-state
  4466. 'org-category-position category-pos
  4467. 'type "sexp")
  4468. (push txt ee)))))
  4469. (nreverse ee)))
  4470. ;; Calendar sanity: define some functions that are independent of
  4471. ;; `calendar-date-style'.
  4472. ;; Normally I would like to use ISO format when calling the diary functions,
  4473. ;; but to make sure we still have Emacs 22 compatibility we bind
  4474. ;; also `european-calendar-style' and use european format
  4475. (defun org-anniversary (year month day &optional mark)
  4476. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4477. (org-no-warnings
  4478. (let ((calendar-date-style 'european) (european-calendar-style t))
  4479. (diary-anniversary day month year mark))))
  4480. (defun org-cyclic (N year month day &optional mark)
  4481. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4482. (org-no-warnings
  4483. (let ((calendar-date-style 'european) (european-calendar-style t))
  4484. (diary-cyclic N day month year mark))))
  4485. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4486. "Like `diary-block', but with fixed (ISO) order of arguments."
  4487. (org-no-warnings
  4488. (let ((calendar-date-style 'european) (european-calendar-style t))
  4489. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4490. (defun org-date (year month day &optional mark)
  4491. "Like `diary-date', but with fixed (ISO) order of arguments."
  4492. (org-no-warnings
  4493. (let ((calendar-date-style 'european) (european-calendar-style t))
  4494. (diary-date day month year mark))))
  4495. (defalias 'org-float 'diary-float)
  4496. ;; Define the` org-class' function
  4497. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4498. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4499. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4500. is any number of ISO weeks in the block period for which the item should
  4501. be skipped."
  4502. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4503. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4504. (d (calendar-absolute-from-gregorian date)))
  4505. (and
  4506. (<= date1 d)
  4507. (<= d date2)
  4508. (= (calendar-day-of-week date) dayname)
  4509. (or (not skip-weeks)
  4510. (progn
  4511. (require 'cal-iso)
  4512. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4513. entry)))
  4514. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4515. "Like `org-class', but honor `calendar-date-style'.
  4516. The order of the first 2 times 3 arguments depends on the variable
  4517. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4518. So for American calendars, give this as MONTH DAY YEAR, for European as
  4519. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4520. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4521. is any number of ISO weeks in the block period for which the item should
  4522. be skipped.
  4523. This function is here only for backward compatibility and it is deprecated,
  4524. please use `org-class' instead."
  4525. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4526. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4527. (org-class
  4528. (nth 2 date1) (car date1) (nth 1 date1)
  4529. (nth 2 date2) (car date2) (nth 1 date2)
  4530. dayname skip-weeks)))
  4531. (defalias 'org-get-closed 'org-agenda-get-progress)
  4532. (defun org-agenda-get-progress ()
  4533. "Return the logged TODO entries for agenda display."
  4534. (let* ((props (list 'mouse-face 'highlight
  4535. 'org-not-done-regexp org-not-done-regexp
  4536. 'org-todo-regexp org-todo-regexp
  4537. 'org-complex-heading-regexp org-complex-heading-regexp
  4538. 'help-echo
  4539. (format "mouse-2 or RET jump to org file %s"
  4540. (abbreviate-file-name buffer-file-name))))
  4541. (items (if (consp org-agenda-show-log)
  4542. org-agenda-show-log
  4543. (if (eq org-agenda-show-log 'clockcheck)
  4544. '(clock)
  4545. org-agenda-log-mode-items)))
  4546. (parts
  4547. (delq nil
  4548. (list
  4549. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4550. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4551. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4552. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4553. (error "`org-agenda-log-mode-items' is empty")))
  4554. (regexp (concat
  4555. "\\(" parts-re "\\)"
  4556. " *\\["
  4557. (regexp-quote
  4558. (substring
  4559. (format-time-string
  4560. (car org-time-stamp-formats)
  4561. (apply 'encode-time ; DATE bound by calendar
  4562. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4563. 1 11))))
  4564. (org-agenda-search-headline-for-time nil)
  4565. marker hdmarker priority category category-pos tags closedp
  4566. statep clockp state ee txt extra timestr rest clocked)
  4567. (goto-char (point-min))
  4568. (while (re-search-forward regexp nil t)
  4569. (catch :skip
  4570. (org-agenda-skip)
  4571. (setq marker (org-agenda-new-marker (match-beginning 0))
  4572. closedp (equal (match-string 1) org-closed-string)
  4573. statep (equal (string-to-char (match-string 1)) ?-)
  4574. clockp (not (or closedp statep))
  4575. state (and statep (match-string 2))
  4576. category (org-get-category (match-beginning 0))
  4577. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4578. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4579. (when (string-match "\\]" timestr)
  4580. ;; substring should only run to end of time stamp
  4581. (setq rest (substring timestr (match-end 0))
  4582. timestr (substring timestr 0 (match-end 0)))
  4583. (if (and (not closedp) (not statep)
  4584. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4585. rest))
  4586. (progn (setq timestr (concat (substring timestr 0 -1)
  4587. "-" (match-string 1 rest) "]"))
  4588. (setq clocked (match-string 2 rest)))
  4589. (setq clocked "-")))
  4590. (save-excursion
  4591. (setq extra
  4592. (cond
  4593. ((not org-agenda-log-mode-add-notes) nil)
  4594. (statep
  4595. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4596. (match-string 1)))
  4597. (clockp
  4598. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4599. (match-string 1)))))
  4600. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4601. (setq txt org-agenda-no-heading-message)
  4602. (goto-char (match-beginning 0))
  4603. (setq hdmarker (org-agenda-new-marker)
  4604. tags (org-get-tags-at))
  4605. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4606. (setq txt (match-string 1))
  4607. (when extra
  4608. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4609. (setq txt (concat (substring txt 0 (match-beginning 1))
  4610. " - " extra " " (match-string 2 txt)))
  4611. (setq txt (concat txt " - " extra))))
  4612. (setq txt (org-format-agenda-item
  4613. (cond
  4614. (closedp "Closed: ")
  4615. (statep (concat "State: (" state ")"))
  4616. (t (concat "Clocked: (" clocked ")")))
  4617. txt category tags timestr)))
  4618. (setq priority 100000)
  4619. (org-add-props txt props
  4620. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4621. 'priority priority 'org-category category
  4622. 'org-category-position category-pos
  4623. 'type "closed" 'date date
  4624. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4625. (push txt ee))
  4626. (goto-char (point-at-eol))))
  4627. (nreverse ee)))
  4628. (defun org-agenda-show-clocking-issues ()
  4629. "Add overlays, showing issues with clocking.
  4630. See also the user option `org-agenda-clock-consistency-checks'."
  4631. (interactive)
  4632. (let* ((pl org-agenda-clock-consistency-checks)
  4633. (re (concat "^[ \t]*"
  4634. org-clock-string
  4635. "[ \t]+"
  4636. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4637. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4638. (tlstart 0.)
  4639. (tlend 0.)
  4640. (maxtime (org-hh:mm-string-to-minutes
  4641. (or (plist-get pl :max-duration) "24:00")))
  4642. (mintime (org-hh:mm-string-to-minutes
  4643. (or (plist-get pl :min-duration) 0)))
  4644. (maxgap (org-hh:mm-string-to-minutes
  4645. ;; default 30:00 means never complain
  4646. (or (plist-get pl :max-gap) "30:00")))
  4647. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4648. (plist-get pl :gap-ok-around)))
  4649. (def-face (or (plist-get pl :default-face)
  4650. '((:background "DarkRed") (:foreground "white"))))
  4651. issue face m te ts dt ov)
  4652. (goto-char (point-min))
  4653. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4654. (setq issue nil face def-face)
  4655. (catch 'next
  4656. (setq m (org-get-at-bol 'org-marker)
  4657. te nil ts nil)
  4658. (unless (and m (markerp m))
  4659. (setq issue "No valid clock line") (throw 'next t))
  4660. (org-with-point-at m
  4661. (save-excursion
  4662. (goto-char (point-at-bol))
  4663. (unless (looking-at re)
  4664. (error "No valid Clock line")
  4665. (throw 'next t))
  4666. (unless (match-end 3)
  4667. (setq issue "No end time"
  4668. face (or (plist-get pl :no-end-time-face) face))
  4669. (throw 'next t))
  4670. (setq ts (match-string 1)
  4671. te (match-string 3)
  4672. ts (org-float-time
  4673. (apply 'encode-time (org-parse-time-string ts)))
  4674. te (org-float-time
  4675. (apply 'encode-time (org-parse-time-string te)))
  4676. dt (- te ts))))
  4677. (cond
  4678. ((> dt (* 60 maxtime))
  4679. ;; a very long clocking chunk
  4680. (setq issue (format "Clocking interval is very long: %s"
  4681. (org-minutes-to-hh:mm-string
  4682. (floor (/ (float dt) 60.))))
  4683. face (or (plist-get pl :long-face) face)))
  4684. ((< dt (* 60 mintime))
  4685. ;; a very short clocking chunk
  4686. (setq issue (format "Clocking interval is very short: %s"
  4687. (org-minutes-to-hh:mm-string
  4688. (floor (/ (float dt) 60.))))
  4689. face (or (plist-get pl :short-face) face)))
  4690. ((and (> tlend 0) (< ts tlend))
  4691. ;; Two clock entries are overlapping
  4692. (setq issue (format "Clocking overlap: %d minutes"
  4693. (/ (- tlend ts) 60))
  4694. face (or (plist-get pl :overlap-face) face)))
  4695. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4696. ;; There is a gap, lets see if we need to report it
  4697. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4698. (setq issue (format "Clocking gap: %d minutes"
  4699. (/ (- ts tlend) 60))
  4700. face (or (plist-get pl :gap-face) face))))
  4701. (t nil)))
  4702. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4703. (when issue
  4704. ;; OK, there was some issue, add an overlay to show the issue
  4705. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4706. (overlay-put ov 'before-string
  4707. (concat
  4708. (org-add-props
  4709. (format "%-43s" (concat " " issue))
  4710. nil
  4711. 'face face)
  4712. "\n"))
  4713. (overlay-put ov 'evaporate t)))))
  4714. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4715. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4716. (catch 'exit
  4717. (unless ok-list
  4718. ;; there are no OK times for gaps...
  4719. (throw 'exit nil))
  4720. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4721. ;; This is more than 24 hours, so it is OK.
  4722. ;; because we have at least one OK time, that must be in the
  4723. ;; 24 hour interval.
  4724. (throw 'exit t))
  4725. ;; We have a shorter gap.
  4726. ;; Now we have to get the minute of the day when these times are
  4727. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4728. (t2dec (decode-time (seconds-to-time t2)))
  4729. ;; compute the minute on the day
  4730. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4731. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4732. (when (< min2 min1)
  4733. ;; if min2 is smaller than min1, this means it is on the next day.
  4734. ;; Wrap it to after midnight.
  4735. (setq min2 (+ min2 1440)))
  4736. ;; Now check if any of the OK times is in the gap
  4737. (mapc (lambda (x)
  4738. ;; Wrap the time to after midnight if necessary
  4739. (if (< x min1) (setq x (+ x 1440)))
  4740. ;; Check if in interval
  4741. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4742. ok-list)
  4743. ;; Nope, this gap is not OK
  4744. nil)))
  4745. (defun org-agenda-get-deadlines ()
  4746. "Return the deadline information for agenda display."
  4747. (let* ((props (list 'mouse-face 'highlight
  4748. 'org-not-done-regexp org-not-done-regexp
  4749. 'org-todo-regexp org-todo-regexp
  4750. 'org-complex-heading-regexp org-complex-heading-regexp
  4751. 'help-echo
  4752. (format "mouse-2 or RET jump to org file %s"
  4753. (abbreviate-file-name buffer-file-name))))
  4754. (regexp org-deadline-time-regexp)
  4755. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4756. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4757. d2 diff dfrac wdays pos pos1 category category-pos
  4758. tags suppress-prewarning ee txt head face s todo-state
  4759. show-all upcomingp donep timestr)
  4760. (goto-char (point-min))
  4761. (while (re-search-forward regexp nil t)
  4762. (setq suppress-prewarning nil)
  4763. (catch :skip
  4764. (org-agenda-skip)
  4765. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4766. (save-match-data
  4767. (string-match org-scheduled-time-regexp
  4768. (buffer-substring (point-at-bol)
  4769. (point-at-eol)))))
  4770. (setq suppress-prewarning
  4771. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4772. org-agenda-skip-deadline-prewarning-if-scheduled
  4773. 0)))
  4774. (setq s (match-string 1)
  4775. txt nil
  4776. pos (1- (match-beginning 1))
  4777. todo-state (save-match-data (org-get-todo-state))
  4778. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4779. (member todo-state
  4780. org-agenda-repeating-timestamp-show-all))
  4781. d2 (org-time-string-to-absolute
  4782. (match-string 1) d1 'past show-all
  4783. (current-buffer) pos)
  4784. diff (- d2 d1)
  4785. wdays (if suppress-prewarning
  4786. (let ((org-deadline-warning-days suppress-prewarning))
  4787. (org-get-wdays s))
  4788. (org-get-wdays s))
  4789. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4790. upcomingp (and todayp (> diff 0)))
  4791. ;; When to show a deadline in the calendar:
  4792. ;; If the expiration is within wdays warning time.
  4793. ;; Past-due deadlines are only shown on the current date
  4794. (if (and (or (and (<= diff wdays)
  4795. (and todayp (not org-agenda-only-exact-dates)))
  4796. (= diff 0)))
  4797. (save-excursion
  4798. ;; (setq todo-state (org-get-todo-state))
  4799. (setq donep (member todo-state org-done-keywords))
  4800. (if (and donep
  4801. (or org-agenda-skip-deadline-if-done
  4802. (not (= diff 0))))
  4803. (setq txt nil)
  4804. (setq category (org-get-category)
  4805. category-pos (get-text-property (point) 'org-category-position))
  4806. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4807. (setq txt org-agenda-no-heading-message)
  4808. (goto-char (match-end 0))
  4809. (setq pos1 (match-beginning 0))
  4810. (setq tags (org-get-tags-at pos1))
  4811. (setq head (buffer-substring-no-properties
  4812. (point)
  4813. (progn (skip-chars-forward "^\r\n")
  4814. (point))))
  4815. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4816. (setq timestr
  4817. (concat (substring s (match-beginning 1)) " "))
  4818. (setq timestr 'time))
  4819. (setq txt (org-format-agenda-item
  4820. (if (= diff 0)
  4821. (car org-agenda-deadline-leaders)
  4822. (if (functionp
  4823. (nth 1 org-agenda-deadline-leaders))
  4824. (funcall
  4825. (nth 1 org-agenda-deadline-leaders)
  4826. diff date)
  4827. (format (nth 1 org-agenda-deadline-leaders)
  4828. diff)))
  4829. head category tags
  4830. (if (not (= diff 0)) nil timestr)))))
  4831. (when txt
  4832. (setq face (org-agenda-deadline-face dfrac))
  4833. (org-add-props txt props
  4834. 'org-marker (org-agenda-new-marker pos)
  4835. 'org-hd-marker (org-agenda-new-marker pos1)
  4836. 'priority (+ (- diff)
  4837. (org-get-priority txt))
  4838. 'org-category category
  4839. 'org-category-position category-pos
  4840. 'todo-state todo-state
  4841. 'type (if upcomingp "upcoming-deadline" "deadline")
  4842. 'date (if upcomingp date d2)
  4843. 'face (if donep 'org-agenda-done face)
  4844. 'undone-face face 'done-face 'org-agenda-done)
  4845. (push txt ee))))))
  4846. (nreverse ee)))
  4847. (defun org-agenda-deadline-face (fraction)
  4848. "Return the face to displaying a deadline item.
  4849. FRACTION is what fraction of the head-warning time has passed."
  4850. (let ((faces org-agenda-deadline-faces) f)
  4851. (catch 'exit
  4852. (while (setq f (pop faces))
  4853. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4854. (defun org-agenda-get-scheduled (&optional deadline-results)
  4855. "Return the scheduled information for agenda display."
  4856. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4857. 'org-todo-regexp org-todo-regexp
  4858. 'org-complex-heading-regexp org-complex-heading-regexp
  4859. 'done-face 'org-agenda-done
  4860. 'mouse-face 'highlight
  4861. 'help-echo
  4862. (format "mouse-2 or RET jump to org file %s"
  4863. (abbreviate-file-name buffer-file-name))))
  4864. (regexp org-scheduled-time-regexp)
  4865. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4866. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4867. mm
  4868. (deadline-position-alist
  4869. (mapcar (lambda (a) (and (setq mm (get-text-property
  4870. 0 'org-hd-marker a))
  4871. (cons (marker-position mm) a)))
  4872. deadline-results))
  4873. d2 diff pos pos1 category category-pos tags donep
  4874. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4875. (goto-char (point-min))
  4876. (while (re-search-forward regexp nil t)
  4877. (catch :skip
  4878. (org-agenda-skip)
  4879. (setq s (match-string 1)
  4880. txt nil
  4881. pos (1- (match-beginning 1))
  4882. todo-state (save-match-data (org-get-todo-state))
  4883. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4884. (member todo-state
  4885. org-agenda-repeating-timestamp-show-all))
  4886. d2 (org-time-string-to-absolute
  4887. (match-string 1) d1 'past show-all
  4888. (current-buffer) pos)
  4889. diff (- d2 d1))
  4890. (setq pastschedp (and todayp (< diff 0)))
  4891. ;; When to show a scheduled item in the calendar:
  4892. ;; If it is on or past the date.
  4893. (when (or (and (< diff 0)
  4894. (< (abs diff) org-scheduled-past-days)
  4895. (and todayp (not org-agenda-only-exact-dates)))
  4896. (= diff 0))
  4897. (save-excursion
  4898. (setq donep (member todo-state org-done-keywords))
  4899. (if (and donep
  4900. (or org-agenda-skip-scheduled-if-done
  4901. (not (= diff 0))
  4902. (and (functionp 'org-is-habit-p)
  4903. (org-is-habit-p))))
  4904. (setq txt nil)
  4905. (setq habitp (and (functionp 'org-is-habit-p)
  4906. (org-is-habit-p)))
  4907. (setq category (org-get-category)
  4908. category-pos (get-text-property (point) 'org-category-position))
  4909. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4910. (setq txt org-agenda-no-heading-message)
  4911. (goto-char (match-end 0))
  4912. (setq pos1 (match-beginning 0))
  4913. (if habitp
  4914. (if (or (not org-habit-show-habits)
  4915. (and (not todayp)
  4916. org-habit-show-habits-only-for-today))
  4917. (throw :skip nil))
  4918. (if (and
  4919. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4920. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4921. pastschedp))
  4922. (setq mm (assoc pos1 deadline-position-alist)))
  4923. (throw :skip nil)))
  4924. (setq tags (org-get-tags-at))
  4925. (setq head (buffer-substring-no-properties
  4926. (point)
  4927. (progn (skip-chars-forward "^\r\n") (point))))
  4928. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4929. (setq timestr
  4930. (concat (substring s (match-beginning 1)) " "))
  4931. (setq timestr 'time))
  4932. (setq txt (org-format-agenda-item
  4933. (if (= diff 0)
  4934. (car org-agenda-scheduled-leaders)
  4935. (format (nth 1 org-agenda-scheduled-leaders)
  4936. (- 1 diff)))
  4937. head category tags
  4938. (if (not (= diff 0)) nil timestr)
  4939. nil habitp))))
  4940. (when txt
  4941. (setq face
  4942. (cond
  4943. ((and (not habitp) pastschedp)
  4944. 'org-scheduled-previously)
  4945. (todayp 'org-scheduled-today)
  4946. (t 'org-scheduled))
  4947. habitp (and habitp (org-habit-parse-todo)))
  4948. (org-add-props txt props
  4949. 'undone-face face
  4950. 'face (if donep 'org-agenda-done face)
  4951. 'org-marker (org-agenda-new-marker pos)
  4952. 'org-hd-marker (org-agenda-new-marker pos1)
  4953. 'type (if pastschedp "past-scheduled" "scheduled")
  4954. 'date (if pastschedp d2 date)
  4955. 'priority (if habitp
  4956. (org-habit-get-priority habitp)
  4957. (+ 94 (- 5 diff) (org-get-priority txt)))
  4958. 'org-category category
  4959. 'org-category-position category-pos
  4960. 'org-habit-p habitp
  4961. 'todo-state todo-state)
  4962. (push txt ee))))))
  4963. (nreverse ee)))
  4964. (defun org-agenda-get-blocks ()
  4965. "Return the date-range information for agenda display."
  4966. (let* ((props (list 'face nil
  4967. 'org-not-done-regexp org-not-done-regexp
  4968. 'org-todo-regexp org-todo-regexp
  4969. 'org-complex-heading-regexp org-complex-heading-regexp
  4970. 'mouse-face 'highlight
  4971. 'help-echo
  4972. (format "mouse-2 or RET jump to org file %s"
  4973. (abbreviate-file-name buffer-file-name))))
  4974. (regexp org-tr-regexp)
  4975. (d0 (calendar-absolute-from-gregorian date))
  4976. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4977. head donep)
  4978. (goto-char (point-min))
  4979. (while (re-search-forward regexp nil t)
  4980. (catch :skip
  4981. (org-agenda-skip)
  4982. (setq pos (point))
  4983. (let ((start-time (match-string 1))
  4984. (end-time (match-string 2)))
  4985. (setq s1 (match-string 1)
  4986. s2 (match-string 2)
  4987. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  4988. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  4989. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4990. ;; Only allow days between the limits, because the normal
  4991. ;; date stamps will catch the limits.
  4992. (save-excursion
  4993. (setq todo-state (org-get-todo-state))
  4994. (setq donep (member todo-state org-done-keywords))
  4995. (if (and donep org-agenda-skip-timestamp-if-done)
  4996. (throw :skip t))
  4997. (setq marker (org-agenda-new-marker (point)))
  4998. (setq category (org-get-category)
  4999. category-pos (get-text-property (point) 'org-category-position))
  5000. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5001. (setq txt org-agenda-no-heading-message)
  5002. (goto-char (match-beginning 0))
  5003. (setq hdmarker (org-agenda-new-marker (point)))
  5004. (setq tags (org-get-tags-at))
  5005. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5006. (setq head (match-string 1))
  5007. (let ((remove-re
  5008. (if org-agenda-remove-timeranges-from-blocks
  5009. (concat
  5010. "<" (regexp-quote s1) ".*?>"
  5011. "--"
  5012. "<" (regexp-quote s2) ".*?>")
  5013. nil)))
  5014. (setq txt (org-format-agenda-item
  5015. (format
  5016. (nth (if (= d1 d2) 0 1)
  5017. org-agenda-timerange-leaders)
  5018. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5019. head category tags
  5020. (cond ((and (= d1 d0) (= d2 d0))
  5021. (concat "<" start-time ">--<" end-time ">"))
  5022. ((= d1 d0)
  5023. (concat "<" start-time ">"))
  5024. ((= d2 d0)
  5025. (concat "<" end-time ">"))
  5026. (t nil))
  5027. remove-re))))
  5028. (org-add-props txt props
  5029. 'org-marker marker 'org-hd-marker hdmarker
  5030. 'type "block" 'date date
  5031. 'todo-state todo-state
  5032. 'priority (org-get-priority txt) 'org-category category
  5033. 'org-category-position category-pos)
  5034. (push txt ee))))
  5035. (goto-char pos)))
  5036. ;; Sort the entries by expiration date.
  5037. (nreverse ee)))
  5038. ;;; Agenda presentation and sorting
  5039. (defvar org-prefix-has-time nil
  5040. "A flag, set by `org-compile-prefix-format'.
  5041. The flag is set if the currently compiled format contains a `%t'.")
  5042. (defvar org-prefix-has-tag nil
  5043. "A flag, set by `org-compile-prefix-format'.
  5044. The flag is set if the currently compiled format contains a `%T'.")
  5045. (defvar org-prefix-has-effort nil
  5046. "A flag, set by `org-compile-prefix-format'.
  5047. The flag is set if the currently compiled format contains a `%e'.")
  5048. (defvar org-prefix-category-length nil
  5049. "Used by `org-compile-prefix-format' to remember the category field width.")
  5050. (defvar org-prefix-category-max-length nil
  5051. "Used by `org-compile-prefix-format' to remember the category field width.")
  5052. (defun org-agenda-get-category-icon (category)
  5053. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5054. (dolist (entry org-agenda-category-icon-alist)
  5055. (when (org-string-match-p (car entry) category)
  5056. (if (listp (cadr entry))
  5057. (return (cadr entry))
  5058. (return (apply 'create-image (cdr entry)))))))
  5059. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5060. remove-re habitp)
  5061. "Format TXT to be inserted into the agenda buffer.
  5062. In particular, it adds the prefix and corresponding text properties. EXTRA
  5063. must be a string and replaces the `%s' specifier in the prefix format.
  5064. CATEGORY (string, symbol or nil) may be used to overrule the default
  5065. category taken from local variable or file name. It will replace the `%c'
  5066. specifier in the format. DOTIME, when non-nil, indicates that a
  5067. time-of-day should be extracted from TXT for sorting of this entry, and for
  5068. the `%t' specifier in the format. When DOTIME is a string, this string is
  5069. searched for a time before TXT is. TAGS can be the tags of the headline.
  5070. Any match of REMOVE-RE will be removed from TXT."
  5071. (save-match-data
  5072. ;; Diary entries sometimes have extra whitespace at the beginning
  5073. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5074. ;; Fix the tags part in txt
  5075. (setq txt (org-agenda-fix-displayed-tags
  5076. txt tags
  5077. org-agenda-show-inherited-tags
  5078. org-agenda-hide-tags-regexp))
  5079. (let* ((category (or category
  5080. (if (stringp org-category)
  5081. org-category
  5082. (and org-category (symbol-name org-category)))
  5083. (if buffer-file-name
  5084. (file-name-sans-extension
  5085. (file-name-nondirectory buffer-file-name))
  5086. "")))
  5087. (category-icon (org-agenda-get-category-icon category))
  5088. (category-icon (if category-icon
  5089. (propertize " " 'display category-icon)
  5090. ""))
  5091. ;; time, tag, effort are needed for the eval of the prefix format
  5092. (tag (if tags (nth (1- (length tags)) tags) ""))
  5093. time effort neffort
  5094. (ts (if dotime (concat
  5095. (if (stringp dotime) dotime "")
  5096. (and org-agenda-search-headline-for-time txt))))
  5097. (time-of-day (and dotime (org-get-time-of-day ts)))
  5098. stamp plain s0 s1 s2 rtn srp l
  5099. duration thecategory)
  5100. (and (org-mode-p) buffer-file-name
  5101. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5102. (when (and dotime time-of-day)
  5103. ;; Extract starting and ending time and move them to prefix
  5104. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5105. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5106. (setq s0 (match-string 0 ts)
  5107. srp (and stamp (match-end 3))
  5108. s1 (match-string (if plain 1 2) ts)
  5109. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5110. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5111. ;; them, we might want to remove them there to avoid duplication.
  5112. ;; The user can turn this off with a variable.
  5113. (if (and org-prefix-has-time
  5114. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5115. (string-match (concat (regexp-quote s0) " *") txt)
  5116. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5117. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5118. (= (match-beginning 0) 0)
  5119. t))
  5120. (setq txt (replace-match "" nil nil txt))))
  5121. ;; Normalize the time(s) to 24 hour
  5122. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5123. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5124. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5125. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5126. (setq s2
  5127. (org-minutes-to-hh:mm-string
  5128. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5129. ;; Compute the duration
  5130. (when s2
  5131. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5132. (org-hh:mm-string-to-minutes s1)))))
  5133. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5134. txt)
  5135. ;; Tags are in the string
  5136. (if (or (eq org-agenda-remove-tags t)
  5137. (and org-agenda-remove-tags
  5138. org-prefix-has-tag))
  5139. (setq txt (replace-match "" t t txt))
  5140. (setq txt (replace-match
  5141. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5142. (match-string 2 txt))
  5143. t t txt))))
  5144. (when (org-mode-p)
  5145. (setq effort
  5146. (condition-case nil
  5147. (org-get-effort
  5148. (or (get-text-property 0 'org-hd-marker txt)
  5149. (get-text-property 0 'org-marker txt)))
  5150. (error nil)))
  5151. (when effort
  5152. (setq neffort (org-duration-string-to-minutes effort)
  5153. effort (setq effort (concat "[" effort "]")))))
  5154. ;; prevent erroring out with %e format when there is no effort
  5155. (or effort (setq effort ""))
  5156. (when remove-re
  5157. (while (string-match remove-re txt)
  5158. (setq txt (replace-match "" t t txt))))
  5159. ;; Set org-heading property on `txt' to mark the start of the
  5160. ;; heading.
  5161. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5162. ;; Prepare the variables needed in the eval of the compiled format
  5163. (setq time (cond (s2 (concat
  5164. (org-agenda-time-of-day-to-ampm-maybe s1)
  5165. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5166. (if org-agenda-timegrid-use-ampm " ")))
  5167. (s1 (concat
  5168. (org-agenda-time-of-day-to-ampm-maybe s1)
  5169. (if org-agenda-timegrid-use-ampm
  5170. "........ "
  5171. "......")))
  5172. (t ""))
  5173. extra (or (and (not habitp) extra) "")
  5174. category (if (symbolp category) (symbol-name category) category)
  5175. thecategory (copy-sequence category))
  5176. (if (string-match org-bracket-link-regexp category)
  5177. (progn
  5178. (setq l (if (match-end 3)
  5179. (- (match-end 3) (match-beginning 3))
  5180. (- (match-end 1) (match-beginning 1))))
  5181. (when (< l (or org-prefix-category-length 0))
  5182. (setq category (copy-sequence category))
  5183. (org-add-props category nil
  5184. 'extra-space (make-string
  5185. (- org-prefix-category-length l 1) ?\ ))))
  5186. (if (and org-prefix-category-max-length
  5187. (>= (length category) org-prefix-category-max-length))
  5188. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5189. ;; Evaluate the compiled format
  5190. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5191. ;; And finally add the text properties
  5192. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5193. (org-add-props rtn nil
  5194. 'org-category (if thecategory (downcase thecategory) category)
  5195. 'tags (mapcar 'org-downcase-keep-props tags)
  5196. 'org-highest-priority org-highest-priority
  5197. 'org-lowest-priority org-lowest-priority
  5198. 'time-of-day time-of-day
  5199. 'duration duration
  5200. 'effort effort
  5201. 'effort-minutes neffort
  5202. 'txt txt
  5203. 'time time
  5204. 'extra extra
  5205. 'format org-prefix-format-compiled
  5206. 'dotime dotime))))
  5207. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5208. "Remove tags string from TXT, and add a modified list of tags.
  5209. The modified list may contain inherited tags, and tags matched by
  5210. `org-agenda-hide-tags-regexp' will be removed."
  5211. (when (or add-inherited hide-re)
  5212. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5213. (setq txt (substring txt 0 (match-beginning 0))))
  5214. (setq tags
  5215. (delq nil
  5216. (mapcar (lambda (tg)
  5217. (if (or (and hide-re (string-match hide-re tg))
  5218. (and (not add-inherited)
  5219. (get-text-property 0 'inherited tg)))
  5220. nil
  5221. tg))
  5222. tags)))
  5223. (when tags
  5224. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5225. i)
  5226. (setq txt (concat txt " :"
  5227. (mapconcat
  5228. (lambda (x)
  5229. (setq i (get-text-property 0 'inherited x))
  5230. (if (and have-i (not i))
  5231. (progn
  5232. (setq have-i nil)
  5233. (concat ":" x))
  5234. x))
  5235. tags ":")
  5236. (if have-i "::" ":"))))))
  5237. txt)
  5238. (defun org-downcase-keep-props (s)
  5239. (let ((props (text-properties-at 0 s)))
  5240. (setq s (downcase s))
  5241. (add-text-properties 0 (length s) props s)
  5242. s))
  5243. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5244. (defvar org-agenda-sorting-strategy-selected nil)
  5245. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5246. (catch 'exit
  5247. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5248. ((and todayp (member 'today (car org-agenda-time-grid))))
  5249. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5250. ((member 'weekly (car org-agenda-time-grid)))
  5251. (t (throw 'exit list)))
  5252. (let* ((have (delq nil (mapcar
  5253. (lambda (x) (get-text-property 1 'time-of-day x))
  5254. list)))
  5255. (string (nth 1 org-agenda-time-grid))
  5256. (gridtimes (nth 2 org-agenda-time-grid))
  5257. (req (car org-agenda-time-grid))
  5258. (remove (member 'remove-match req))
  5259. new time)
  5260. (if (and (member 'require-timed req) (not have))
  5261. ;; don't show empty grid
  5262. (throw 'exit list))
  5263. (while (setq time (pop gridtimes))
  5264. (unless (and remove (member time have))
  5265. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5266. (push (org-format-agenda-item
  5267. nil string "" nil
  5268. (concat (substring time 0 -2) ":" (substring time -2)))
  5269. new)
  5270. (put-text-property
  5271. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5272. (when (and todayp org-agenda-show-current-time-in-grid)
  5273. (push (org-format-agenda-item
  5274. nil
  5275. org-agenda-current-time-string
  5276. "" nil
  5277. (format-time-string "%H:%M "))
  5278. new)
  5279. (put-text-property
  5280. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5281. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5282. (append new list)
  5283. (append list new)))))
  5284. (defun org-compile-prefix-format (key)
  5285. "Compile the prefix format into a Lisp form that can be evaluated.
  5286. The resulting form is returned and stored in the variable
  5287. `org-prefix-format-compiled'."
  5288. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5289. org-prefix-category-length nil
  5290. org-prefix-has-effort nil)
  5291. (let ((s (cond
  5292. ((stringp org-agenda-prefix-format)
  5293. org-agenda-prefix-format)
  5294. ((assq key org-agenda-prefix-format)
  5295. (cdr (assq key org-agenda-prefix-format)))
  5296. (t " %-12:c%?-12t% s")))
  5297. (start 0)
  5298. varform vars var e c f opt)
  5299. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5300. s start)
  5301. (setq var (or (cdr (assoc (match-string 4 s)
  5302. '(("c" . category) ("t" . time) ("s" . extra)
  5303. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5304. 'eval)
  5305. c (or (match-string 3 s) "")
  5306. opt (match-beginning 1)
  5307. start (1+ (match-beginning 0)))
  5308. (if (equal var 'time) (setq org-prefix-has-time t))
  5309. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5310. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5311. (setq f (concat "%" (match-string 2 s) "s"))
  5312. (when (equal var 'category)
  5313. (setq org-prefix-category-length
  5314. (floor (abs (string-to-number (match-string 2 s)))))
  5315. (setq org-prefix-category-max-length
  5316. (let ((x (match-string 2 s)))
  5317. (save-match-data
  5318. (if (string-match "\\.[0-9]+" x)
  5319. (string-to-number (substring (match-string 0 x) 1)))))))
  5320. (if (eq var 'eval)
  5321. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5322. (if opt
  5323. (setq varform
  5324. `(if (equal "" ,var)
  5325. ""
  5326. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5327. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5328. (setq s (replace-match "%s" t nil s))
  5329. (push varform vars))
  5330. (setq vars (nreverse vars))
  5331. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5332. (defun org-set-sorting-strategy (key)
  5333. (if (symbolp (car org-agenda-sorting-strategy))
  5334. ;; the old format
  5335. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5336. (setq org-agenda-sorting-strategy-selected
  5337. (or (cdr (assq key org-agenda-sorting-strategy))
  5338. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5339. '(time-up category-keep priority-down)))))
  5340. (defun org-get-time-of-day (s &optional string mod24)
  5341. "Check string S for a time of day.
  5342. If found, return it as a military time number between 0 and 2400.
  5343. If not found, return nil.
  5344. The optional STRING argument forces conversion into a 5 character wide string
  5345. HH:MM."
  5346. (save-match-data
  5347. (when
  5348. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5349. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5350. (let* ((h (string-to-number (match-string 1 s)))
  5351. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5352. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5353. (am-p (equal ampm "am"))
  5354. (h1 (cond ((not ampm) h)
  5355. ((= h 12) (if am-p 0 12))
  5356. (t (+ h (if am-p 0 12)))))
  5357. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5358. (mod h1 24) h1))
  5359. (t0 (+ (* 100 h2) m))
  5360. (t1 (concat (if (>= h1 24) "+" " ")
  5361. (if (and org-agenda-time-leading-zero
  5362. (< t0 1000)) "0" "")
  5363. (if (< t0 100) "0" "")
  5364. (if (< t0 10) "0" "")
  5365. (int-to-string t0))))
  5366. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5367. (defvar org-agenda-before-sorting-filter-function nil
  5368. "Function to be applied to agenda items prior to sorting.
  5369. Prior to sorting also means just before they are inserted into the agenda.
  5370. To aid sorting, you may revisit the original entries and add more text
  5371. properties which will later be used by the sorting functions.
  5372. The function should take a string argument, an agenda line.
  5373. It has access to the text properties in that line, which contain among
  5374. other things, the property `org-hd-marker' that points to the entry
  5375. where the line comes from. Note that not all lines going into the agenda
  5376. have this property, only most.
  5377. The function should return the modified string. It is probably best
  5378. to ONLY change text properties.
  5379. You can also use this function as a filter, by returning nil for lines
  5380. you don't want to have in the agenda at all. For this application, you
  5381. could bind the variable in the options section of a custom command.")
  5382. (defun org-finalize-agenda-entries (list &optional nosort)
  5383. "Sort and concatenate the agenda items."
  5384. (setq list (mapcar 'org-agenda-highlight-todo list))
  5385. (if nosort
  5386. list
  5387. (when org-agenda-before-sorting-filter-function
  5388. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5389. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5390. (defun org-agenda-highlight-todo (x)
  5391. (let ((org-done-keywords org-done-keywords-for-agenda)
  5392. (case-fold-search nil)
  5393. re)
  5394. (if (eq x 'line)
  5395. (save-excursion
  5396. (beginning-of-line 1)
  5397. (setq re (org-get-at-bol 'org-todo-regexp))
  5398. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5399. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5400. (add-text-properties (match-beginning 0) (match-end 1)
  5401. (list 'face (org-get-todo-face 1)))
  5402. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5403. (delete-region (match-beginning 1) (1- (match-end 0)))
  5404. (goto-char (match-beginning 1))
  5405. (insert (format org-agenda-todo-keyword-format s)))))
  5406. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5407. (setq re (get-text-property 0 'org-todo-regexp x))
  5408. (when (and re
  5409. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5410. x (or pl 0)) pl))
  5411. (add-text-properties
  5412. (or (match-end 1) (match-end 0)) (match-end 0)
  5413. (list 'face (org-get-todo-face (match-string 2 x)))
  5414. x)
  5415. (when (match-end 1)
  5416. (setq x (concat (substring x 0 (match-end 1))
  5417. (format org-agenda-todo-keyword-format
  5418. (match-string 2 x))
  5419. (org-add-props " " (text-properties-at 0 x))
  5420. (substring x (match-end 3)))))))
  5421. x)))
  5422. (defsubst org-cmp-priority (a b)
  5423. "Compare the priorities of string A and B."
  5424. (let ((pa (or (get-text-property 1 'priority a) 0))
  5425. (pb (or (get-text-property 1 'priority b) 0)))
  5426. (cond ((> pa pb) +1)
  5427. ((< pa pb) -1)
  5428. (t nil))))
  5429. (defsubst org-cmp-effort (a b)
  5430. "Compare the effort values of string A and B."
  5431. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5432. (ea (or (get-text-property 1 'effort-minutes a) def))
  5433. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5434. (cond ((> ea eb) +1)
  5435. ((< ea eb) -1)
  5436. (t nil))))
  5437. (defsubst org-cmp-category (a b)
  5438. "Compare the string values of categories of strings A and B."
  5439. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5440. (cb (or (get-text-property 1 'org-category b) "")))
  5441. (cond ((string-lessp ca cb) -1)
  5442. ((string-lessp cb ca) +1)
  5443. (t nil))))
  5444. (defsubst org-cmp-todo-state (a b)
  5445. "Compare the todo states of strings A and B."
  5446. (let* ((ma (or (get-text-property 1 'org-marker a)
  5447. (get-text-property 1 'org-hd-marker a)))
  5448. (mb (or (get-text-property 1 'org-marker b)
  5449. (get-text-property 1 'org-hd-marker b)))
  5450. (fa (and ma (marker-buffer ma)))
  5451. (fb (and mb (marker-buffer mb)))
  5452. (todo-kwds
  5453. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5454. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5455. (ta (or (get-text-property 1 'todo-state a) ""))
  5456. (tb (or (get-text-property 1 'todo-state b) ""))
  5457. (la (- (length (member ta todo-kwds))))
  5458. (lb (- (length (member tb todo-kwds))))
  5459. (donepa (member ta org-done-keywords-for-agenda))
  5460. (donepb (member tb org-done-keywords-for-agenda)))
  5461. (cond ((and donepa (not donepb)) -1)
  5462. ((and (not donepa) donepb) +1)
  5463. ((< la lb) -1)
  5464. ((< lb la) +1)
  5465. (t nil))))
  5466. (defsubst org-cmp-alpha (a b)
  5467. "Compare the headlines, alphabetically."
  5468. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5469. (plb (text-property-any 0 (length b) 'org-heading t b))
  5470. (ta (and pla (substring a pla)))
  5471. (tb (and plb (substring b plb))))
  5472. (when pla
  5473. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5474. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5475. (setq ta (substring ta (match-end 0))))
  5476. (setq ta (downcase ta)))
  5477. (when plb
  5478. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5479. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5480. (setq tb (substring tb (match-end 0))))
  5481. (setq tb (downcase tb)))
  5482. (cond ((not ta) +1)
  5483. ((not tb) -1)
  5484. ((string-lessp ta tb) -1)
  5485. ((string-lessp tb ta) +1)
  5486. (t nil))))
  5487. (defsubst org-cmp-tag (a b)
  5488. "Compare the string values of the first tags of A and B."
  5489. (let ((ta (car (last (get-text-property 1 'tags a))))
  5490. (tb (car (last (get-text-property 1 'tags b)))))
  5491. (cond ((not ta) +1)
  5492. ((not tb) -1)
  5493. ((string-lessp ta tb) -1)
  5494. ((string-lessp tb ta) +1)
  5495. (t nil))))
  5496. (defsubst org-cmp-time (a b)
  5497. "Compare the time-of-day values of strings A and B."
  5498. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5499. (ta (or (get-text-property 1 'time-of-day a) def))
  5500. (tb (or (get-text-property 1 'time-of-day b) def)))
  5501. (cond ((< ta tb) -1)
  5502. ((< tb ta) +1)
  5503. (t nil))))
  5504. (defsubst org-cmp-habit-p (a b)
  5505. "Compare the todo states of strings A and B."
  5506. (let ((ha (get-text-property 1 'org-habit-p a))
  5507. (hb (get-text-property 1 'org-habit-p b)))
  5508. (cond ((and ha (not hb)) -1)
  5509. ((and (not ha) hb) +1)
  5510. (t nil))))
  5511. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5512. (defun org-entries-lessp (a b)
  5513. "Predicate for sorting agenda entries."
  5514. ;; The following variables will be used when the form is evaluated.
  5515. ;; So even though the compiler complains, keep them.
  5516. (let* ((ss org-agenda-sorting-strategy-selected)
  5517. (time-up (and (org-em 'time-up 'time-down ss)
  5518. (org-cmp-time a b)))
  5519. (time-down (if time-up (- time-up) nil))
  5520. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5521. (org-cmp-priority a b)))
  5522. (priority-down (if priority-up (- priority-up) nil))
  5523. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5524. (org-cmp-effort a b)))
  5525. (effort-down (if effort-up (- effort-up) nil))
  5526. (category-up (and (or (org-em 'category-up 'category-down ss)
  5527. (memq 'category-keep ss))
  5528. (org-cmp-category a b)))
  5529. (category-down (if category-up (- category-up) nil))
  5530. (category-keep (if category-up +1 nil))
  5531. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5532. (org-cmp-tag a b)))
  5533. (tag-down (if tag-up (- tag-up) nil))
  5534. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5535. (org-cmp-todo-state a b)))
  5536. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5537. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5538. (org-cmp-habit-p a b)))
  5539. (habit-down (if habit-up (- habit-up) nil))
  5540. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5541. (org-cmp-alpha a b)))
  5542. (alpha-down (if alpha-up (- alpha-up) nil))
  5543. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5544. user-defined-up user-defined-down)
  5545. (if (and need-user-cmp org-agenda-cmp-user-defined
  5546. (functionp org-agenda-cmp-user-defined))
  5547. (setq user-defined-up
  5548. (funcall org-agenda-cmp-user-defined a b)
  5549. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5550. (cdr (assoc
  5551. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5552. '((-1 . t) (1 . nil) (nil . nil))))))
  5553. ;;; Agenda restriction lock
  5554. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5555. "Overlay to mark the headline to which agenda commands are restricted.")
  5556. (overlay-put org-agenda-restriction-lock-overlay
  5557. 'face 'org-agenda-restriction-lock)
  5558. (overlay-put org-agenda-restriction-lock-overlay
  5559. 'help-echo "Agendas are currently limited to this subtree.")
  5560. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5561. (defun org-agenda-set-restriction-lock (&optional type)
  5562. "Set restriction lock for agenda, to current subtree or file.
  5563. Restriction will be the file if TYPE is `file', or if type is the
  5564. universal prefix '(4), or if the cursor is before the first headline
  5565. in the file. Otherwise, restriction will be to the current subtree."
  5566. (interactive "P")
  5567. (and (equal type '(4)) (setq type 'file))
  5568. (setq type (cond
  5569. (type type)
  5570. ((org-at-heading-p) 'subtree)
  5571. ((condition-case nil (org-back-to-heading t) (error nil))
  5572. 'subtree)
  5573. (t 'file)))
  5574. (if (eq type 'subtree)
  5575. (progn
  5576. (setq org-agenda-restrict t)
  5577. (setq org-agenda-overriding-restriction 'subtree)
  5578. (put 'org-agenda-files 'org-restrict
  5579. (list (buffer-file-name (buffer-base-buffer))))
  5580. (org-back-to-heading t)
  5581. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5582. (move-marker org-agenda-restrict-begin (point))
  5583. (move-marker org-agenda-restrict-end
  5584. (save-excursion (org-end-of-subtree t)))
  5585. (message "Locking agenda restriction to subtree"))
  5586. (put 'org-agenda-files 'org-restrict
  5587. (list (buffer-file-name (buffer-base-buffer))))
  5588. (setq org-agenda-restrict nil)
  5589. (setq org-agenda-overriding-restriction 'file)
  5590. (move-marker org-agenda-restrict-begin nil)
  5591. (move-marker org-agenda-restrict-end nil)
  5592. (message "Locking agenda restriction to file"))
  5593. (setq current-prefix-arg nil)
  5594. (org-agenda-maybe-redo))
  5595. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5596. "Remove the agenda restriction lock."
  5597. (interactive "P")
  5598. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5599. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5600. (setq org-agenda-overriding-restriction nil)
  5601. (setq org-agenda-restrict nil)
  5602. (put 'org-agenda-files 'org-restrict nil)
  5603. (move-marker org-agenda-restrict-begin nil)
  5604. (move-marker org-agenda-restrict-end nil)
  5605. (setq current-prefix-arg nil)
  5606. (message "Agenda restriction lock removed")
  5607. (or noupdate (org-agenda-maybe-redo)))
  5608. (defun org-agenda-maybe-redo ()
  5609. "If there is any window showing the agenda view, update it."
  5610. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5611. (w0 (selected-window)))
  5612. (when w
  5613. (select-window w)
  5614. (org-agenda-redo)
  5615. (select-window w0)
  5616. (if org-agenda-overriding-restriction
  5617. (message "Agenda view shifted to new %s restriction"
  5618. org-agenda-overriding-restriction)
  5619. (message "Agenda restriction lock removed")))))
  5620. ;;; Agenda commands
  5621. (defun org-agenda-check-type (error &rest types)
  5622. "Check if agenda buffer is of allowed type.
  5623. If ERROR is non-nil, throw an error, otherwise just return nil."
  5624. (if (memq org-agenda-type types)
  5625. t
  5626. (if error
  5627. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5628. nil)))
  5629. (defun org-agenda-quit ()
  5630. "Exit agenda by removing the window or the buffer."
  5631. (interactive)
  5632. (if org-agenda-columns-active
  5633. (org-columns-quit)
  5634. (let ((buf (current-buffer)))
  5635. (if (eq org-agenda-window-setup 'other-frame)
  5636. (progn
  5637. (kill-buffer buf)
  5638. (org-agenda-reset-markers)
  5639. (org-columns-remove-overlays)
  5640. (setq org-agenda-archives-mode nil)
  5641. (delete-frame))
  5642. (and (not (eq org-agenda-window-setup 'current-window))
  5643. (not (one-window-p))
  5644. (delete-window))
  5645. (kill-buffer buf)
  5646. (org-agenda-reset-markers)
  5647. (org-columns-remove-overlays)
  5648. (setq org-agenda-archives-mode nil)))
  5649. ;; Maybe restore the pre-agenda window configuration.
  5650. (and org-agenda-restore-windows-after-quit
  5651. (not (eq org-agenda-window-setup 'other-frame))
  5652. org-pre-agenda-window-conf
  5653. (set-window-configuration org-pre-agenda-window-conf))))
  5654. (defun org-agenda-exit ()
  5655. "Exit agenda by removing the window or the buffer.
  5656. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5657. Org-mode buffers visited directly by the user will not be touched."
  5658. (interactive)
  5659. (org-release-buffers org-agenda-new-buffers)
  5660. (setq org-agenda-new-buffers nil)
  5661. (org-agenda-quit))
  5662. (defun org-agenda-execute (arg)
  5663. "Execute another agenda command, keeping same window.
  5664. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5665. in the agenda."
  5666. (interactive "P")
  5667. (let ((org-agenda-window-setup 'current-window))
  5668. (org-agenda arg)))
  5669. (defun org-agenda-redo ()
  5670. "Rebuild Agenda.
  5671. When this is the global TODO list, a prefix argument will be interpreted."
  5672. (interactive)
  5673. (let* ((org-agenda-keep-modes t)
  5674. (filter org-agenda-filter)
  5675. (preset (get 'org-agenda-filter :preset-filter))
  5676. (org-agenda-filter-while-redo (or filter preset))
  5677. (cols org-agenda-columns-active)
  5678. (line (org-current-line))
  5679. (window-line (- line (org-current-line (window-start))))
  5680. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5681. (put 'org-agenda-filter :preset-filter nil)
  5682. (and cols (org-columns-quit))
  5683. (message "Rebuilding agenda buffer...")
  5684. (org-let lprops '(eval org-agenda-redo-command))
  5685. (setq org-agenda-undo-list nil
  5686. org-agenda-pending-undo-list nil)
  5687. (message "Rebuilding agenda buffer...done")
  5688. (put 'org-agenda-filter :preset-filter preset)
  5689. (and (or filter preset) (org-agenda-filter-apply filter))
  5690. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5691. (org-goto-line line)
  5692. (recenter window-line)))
  5693. (defvar org-global-tags-completion-table nil)
  5694. (defvar org-agenda-filter-form nil)
  5695. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5696. "Keep only those lines in the agenda buffer that have a specific tag.
  5697. The tag is selected with its fast selection letter, as configured.
  5698. With prefix argument STRIP, remove all lines that do have the tag.
  5699. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5700. used to narrow the search - the interactive user can also press `-' or `+'
  5701. to switch to narrowing."
  5702. (interactive "P")
  5703. (let* ((alist org-tag-alist-for-agenda)
  5704. (tag-chars (mapconcat
  5705. (lambda (x) (if (and (not (symbolp (car x)))
  5706. (cdr x))
  5707. (char-to-string (cdr x))
  5708. ""))
  5709. alist ""))
  5710. (efforts (org-split-string
  5711. (or (cdr (assoc (concat org-effort-property "_ALL")
  5712. org-global-properties))
  5713. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5714. "")))
  5715. (effort-op org-agenda-filter-effort-default-operator)
  5716. (effort-prompt "")
  5717. (inhibit-read-only t)
  5718. (current org-agenda-filter)
  5719. maybe-refresh a n tag)
  5720. (unless char
  5721. (message
  5722. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5723. (if narrow "Narrow" "Filter") tag-chars
  5724. (if org-agenda-auto-exclude-function "[RET], " ""))
  5725. (setq char (read-char)))
  5726. (when (member char '(?+ ?-))
  5727. ;; Narrowing down
  5728. (cond ((equal char ?-) (setq strip t narrow t))
  5729. ((equal char ?+) (setq strip nil narrow t)))
  5730. (message
  5731. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5732. (setq char (read-char)))
  5733. (when (member char '(?< ?> ?= ??))
  5734. ;; An effort operator
  5735. (setq effort-op (char-to-string char))
  5736. (setq alist nil) ; to make sure it will be interpreted as effort.
  5737. (unless (equal char ??)
  5738. (loop for i from 0 to 9 do
  5739. (setq effort-prompt
  5740. (concat
  5741. effort-prompt " ["
  5742. (if (= i 9) "0" (int-to-string (1+ i)))
  5743. "]" (nth i efforts))))
  5744. (message "Effort%s: %s " effort-op effort-prompt)
  5745. (setq char (read-char))
  5746. (when (or (< char ?0) (> char ?9))
  5747. (error "Need 1-9,0 to select effort" ))))
  5748. (when (equal char ?\t)
  5749. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5750. (org-set-local 'org-global-tags-completion-table
  5751. (org-global-tags-completion-table)))
  5752. (let ((completion-ignore-case t))
  5753. (setq tag (org-icompleting-read
  5754. "Tag: " org-global-tags-completion-table))))
  5755. (cond
  5756. ((equal char ?\r)
  5757. (org-agenda-filter-by-tag-show-all)
  5758. (when org-agenda-auto-exclude-function
  5759. (setq org-agenda-filter '())
  5760. (dolist (tag (org-agenda-get-represented-tags))
  5761. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5762. (if modifier
  5763. (push modifier org-agenda-filter))))
  5764. (if (not (null org-agenda-filter))
  5765. (org-agenda-filter-apply org-agenda-filter)))
  5766. (setq maybe-refresh t))
  5767. ((equal char ?/)
  5768. (org-agenda-filter-by-tag-show-all)
  5769. (when (get 'org-agenda-filter :preset-filter)
  5770. (org-agenda-filter-apply org-agenda-filter))
  5771. (setq maybe-refresh t))
  5772. ((or (equal char ?\ )
  5773. (setq a (rassoc char alist))
  5774. (and (>= char ?0) (<= char ?9)
  5775. (setq n (if (= char ?0) 9 (- char ?0 1))
  5776. tag (concat effort-op (nth n efforts))
  5777. a (cons tag nil)))
  5778. (and (= char ??)
  5779. (setq tag "?eff")
  5780. a (cons tag nil))
  5781. (and tag (setq a (cons tag nil))))
  5782. (org-agenda-filter-by-tag-show-all)
  5783. (setq tag (car a))
  5784. (setq org-agenda-filter
  5785. (cons (concat (if strip "-" "+") tag)
  5786. (if narrow current nil)))
  5787. (org-agenda-filter-apply org-agenda-filter)
  5788. (setq maybe-refresh t))
  5789. (t (error "Invalid tag selection character %c" char)))
  5790. (when (and maybe-refresh
  5791. (eq org-agenda-clockreport-mode 'with-filter))
  5792. (org-agenda-redo))))
  5793. (defun org-agenda-get-represented-tags ()
  5794. "Get a list of all tags currently represented in the agenda."
  5795. (let (p tags)
  5796. (save-excursion
  5797. (goto-char (point-min))
  5798. (while (setq p (next-single-property-change (point) 'tags))
  5799. (goto-char p)
  5800. (mapc (lambda (x) (add-to-list 'tags x))
  5801. (get-text-property (point) 'tags))))
  5802. tags))
  5803. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5804. "Refine the current filter. See `org-agenda-filter-by-tag'."
  5805. (interactive "P")
  5806. (org-agenda-filter-by-tag strip char 'refine))
  5807. (defun org-agenda-filter-make-matcher ()
  5808. "Create the form that tests a line for the agenda filter."
  5809. (let (f f1)
  5810. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5811. org-agenda-filter))
  5812. (if (member x '("-" "+"))
  5813. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5814. (if (string-match "[<=>?]" x)
  5815. (setq f1 (org-agenda-filter-effort-form x))
  5816. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5817. (if (equal (string-to-char x) ?-)
  5818. (setq f1 (list 'not f1))))
  5819. (push f1 f))
  5820. (cons 'and (nreverse f))))
  5821. (defun org-agenda-filter-effort-form (e)
  5822. "Return the form to compare the effort of the current line with what E says.
  5823. E looks like \"+<2:25\"."
  5824. (let (op)
  5825. (setq e (substring e 1))
  5826. (setq op (string-to-char e) e (substring e 1))
  5827. (setq op (cond ((equal op ?<) '<=)
  5828. ((equal op ?>) '>=)
  5829. ((equal op ??) op)
  5830. (t '=)))
  5831. (list 'org-agenda-compare-effort (list 'quote op)
  5832. (org-duration-string-to-minutes e))))
  5833. (defun org-agenda-compare-effort (op value)
  5834. "Compare the effort of the current line with VALUE, using OP.
  5835. If the line does not have an effort defined, return nil."
  5836. (let ((eff (org-get-at-bol 'effort-minutes)))
  5837. (if (equal op ??)
  5838. (not eff)
  5839. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5840. value))))
  5841. (defun org-agenda-filter-apply (filter)
  5842. "Set FILTER as the new agenda filter and apply it."
  5843. (let (tags)
  5844. (setq org-agenda-filter filter
  5845. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5846. (org-agenda-set-mode-name)
  5847. (save-excursion
  5848. (goto-char (point-min))
  5849. (while (not (eobp))
  5850. (if (org-get-at-bol 'org-marker)
  5851. (progn
  5852. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5853. (if (not (eval org-agenda-filter-form))
  5854. (org-agenda-filter-by-tag-hide-line))
  5855. (beginning-of-line 2))
  5856. (beginning-of-line 2))))
  5857. (if (get-char-property (point) 'invisible)
  5858. (org-agenda-previous-line))))
  5859. (defun org-agenda-filter-by-tag-hide-line ()
  5860. (let (ov)
  5861. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5862. (point-at-eol)))
  5863. (overlay-put ov 'invisible t)
  5864. (overlay-put ov 'type 'tags-filter)
  5865. (push ov org-agenda-filter-overlays)))
  5866. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5867. (setq pos (or pos (point)))
  5868. (save-excursion
  5869. (dolist (ov (overlays-at pos))
  5870. (when (and (overlay-get ov 'invisible)
  5871. (eq (overlay-get ov 'type) 'tags-filter))
  5872. (goto-char pos)
  5873. (if (< (overlay-start ov) (point-at-eol))
  5874. (move-overlay ov (point-at-eol)
  5875. (overlay-end ov)))))))
  5876. (defun org-agenda-filter-by-tag-show-all ()
  5877. (mapc 'delete-overlay org-agenda-filter-overlays)
  5878. (setq org-agenda-filter-overlays nil)
  5879. (setq org-agenda-filter nil)
  5880. (setq org-agenda-filter-form nil)
  5881. (org-agenda-set-mode-name))
  5882. (defun org-agenda-manipulate-query-add ()
  5883. "Manipulate the query by adding a search term with positive selection.
  5884. Positive selection means the term must be matched for selection of an entry."
  5885. (interactive)
  5886. (org-agenda-manipulate-query ?\[))
  5887. (defun org-agenda-manipulate-query-subtract ()
  5888. "Manipulate the query by adding a search term with negative selection.
  5889. Negative selection means term must not be matched for selection of an entry."
  5890. (interactive)
  5891. (org-agenda-manipulate-query ?\]))
  5892. (defun org-agenda-manipulate-query-add-re ()
  5893. "Manipulate the query by adding a search regexp with positive selection.
  5894. Positive selection means the regexp must match for selection of an entry."
  5895. (interactive)
  5896. (org-agenda-manipulate-query ?\{))
  5897. (defun org-agenda-manipulate-query-subtract-re ()
  5898. "Manipulate the query by adding a search regexp with negative selection.
  5899. Negative selection means regexp must not match for selection of an entry."
  5900. (interactive)
  5901. (org-agenda-manipulate-query ?\}))
  5902. (defun org-agenda-manipulate-query (char)
  5903. (cond
  5904. ((memq org-agenda-type '(timeline agenda))
  5905. (let ((org-agenda-include-inactive-timestamps t))
  5906. (org-agenda-redo))
  5907. (message "Display now includes inactive timestamps as well"))
  5908. ((eq org-agenda-type 'search)
  5909. (org-add-to-string
  5910. 'org-agenda-query-string
  5911. (if org-agenda-last-search-view-search-was-boolean
  5912. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5913. (?\{ . " +{}") (?\} . " -{}"))))
  5914. " "))
  5915. (setq org-agenda-redo-command
  5916. (list 'org-search-view
  5917. org-todo-only
  5918. org-agenda-query-string
  5919. (+ (length org-agenda-query-string)
  5920. (if (member char '(?\{ ?\})) 0 1))))
  5921. (set-register org-agenda-query-register org-agenda-query-string)
  5922. (org-agenda-redo))
  5923. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5924. org-agenda-type))))
  5925. (defun org-add-to-string (var string)
  5926. (set var (concat (symbol-value var) string)))
  5927. (defun org-agenda-goto-date (date)
  5928. "Jump to DATE in agenda."
  5929. (interactive (list (let ((org-read-date-prefer-future
  5930. (eval org-agenda-jump-prefer-future)))
  5931. (org-read-date))))
  5932. (org-agenda-list nil date))
  5933. (defun org-agenda-goto-today ()
  5934. "Go to today."
  5935. (interactive)
  5936. (org-agenda-check-type t 'timeline 'agenda)
  5937. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5938. (cond
  5939. (tdpos (goto-char tdpos))
  5940. ((eq org-agenda-type 'agenda)
  5941. (let* ((sd (org-agenda-compute-starting-span
  5942. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5943. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5944. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5945. (org-agenda-redo)
  5946. (org-agenda-find-same-or-today-or-agenda)))
  5947. (t (error "Cannot find today")))))
  5948. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5949. (goto-char
  5950. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5951. (text-property-any (point-min) (point-max) 'org-today t)
  5952. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5953. (point-min))))
  5954. (defun org-agenda-later (arg)
  5955. "Go forward in time by thee current span.
  5956. With prefix ARG, go forward that many times the current span."
  5957. (interactive "p")
  5958. (org-agenda-check-type t 'agenda)
  5959. (let* ((span org-agenda-current-span)
  5960. (sd org-starting-day)
  5961. (greg (calendar-gregorian-from-absolute sd))
  5962. (cnt (org-get-at-bol 'org-day-cnt))
  5963. greg2)
  5964. (cond
  5965. ((eq span 'day)
  5966. (setq sd (+ arg sd)))
  5967. ((eq span 'week)
  5968. (setq sd (+ (* 7 arg) sd)))
  5969. ((eq span 'month)
  5970. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5971. sd (calendar-absolute-from-gregorian greg2))
  5972. (setcar greg2 (1+ (car greg2))))
  5973. ((eq span 'year)
  5974. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5975. sd (calendar-absolute-from-gregorian greg2))
  5976. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5977. (t
  5978. (setq sd (+ (* span arg) sd))))
  5979. (let ((org-agenda-overriding-arguments
  5980. (list (car org-agenda-last-arguments) sd span t)))
  5981. (org-agenda-redo)
  5982. (org-agenda-find-same-or-today-or-agenda cnt))))
  5983. (defun org-agenda-earlier (arg)
  5984. "Go backward in time by the current span.
  5985. With prefix ARG, go backward that many times the current span."
  5986. (interactive "p")
  5987. (org-agenda-later (- arg)))
  5988. (defun org-agenda-view-mode-dispatch ()
  5989. "Call one of the view mode commands."
  5990. (interactive)
  5991. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5992. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5993. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5994. [E]ntryText")
  5995. (let ((a (read-char-exclusive)))
  5996. (case a
  5997. (?\ (call-interactively 'org-agenda-reset-view))
  5998. (?d (call-interactively 'org-agenda-day-view))
  5999. (?w (call-interactively 'org-agenda-week-view))
  6000. (?m (call-interactively 'org-agenda-month-view))
  6001. (?y (call-interactively 'org-agenda-year-view))
  6002. (?l (call-interactively 'org-agenda-log-mode))
  6003. (?L (org-agenda-log-mode '(4)))
  6004. (?c (org-agenda-log-mode 'clockcheck))
  6005. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6006. (?a (call-interactively 'org-agenda-archives-mode))
  6007. (?A (org-agenda-archives-mode 'files))
  6008. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6009. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6010. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6011. (?D (call-interactively 'org-agenda-toggle-diary))
  6012. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6013. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6014. (org-agenda-check-type t 'timeline 'agenda)
  6015. (org-agenda-redo))
  6016. (message "Display now includes inactive timestamps as well"))
  6017. (?q (message "Abort"))
  6018. (otherwise (error "Invalid key" )))))
  6019. (defun org-agenda-reset-view ()
  6020. "Switch to default view for agenda."
  6021. (interactive)
  6022. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6023. (defun org-agenda-day-view (&optional day-of-year)
  6024. "Switch to daily view for agenda.
  6025. With argument DAY-OF-YEAR, switch to that day of the year."
  6026. (interactive "P")
  6027. (org-agenda-change-time-span 'day day-of-year))
  6028. (defun org-agenda-week-view (&optional iso-week)
  6029. "Switch to daily view for agenda.
  6030. With argument ISO-WEEK, switch to the corresponding ISO week.
  6031. If ISO-WEEK has more then 2 digits, only the last two encode the
  6032. week. Any digits before this encode a year. So 200712 means
  6033. week 12 of year 2007. Years in the range 1938-2037 can also be
  6034. written as 2-digit years."
  6035. (interactive "P")
  6036. (org-agenda-change-time-span 'week iso-week))
  6037. (defun org-agenda-month-view (&optional month)
  6038. "Switch to monthly view for agenda.
  6039. With argument MONTH, switch to that month."
  6040. (interactive "P")
  6041. (org-agenda-change-time-span 'month month))
  6042. (defun org-agenda-year-view (&optional year)
  6043. "Switch to yearly view for agenda.
  6044. With argument YEAR, switch to that year.
  6045. If MONTH has more then 2 digits, only the last two encode the
  6046. month. Any digits before this encode a year. So 200712 means
  6047. December year 2007. Years in the range 1938-2037 can also be
  6048. written as 2-digit years."
  6049. (interactive "P")
  6050. (when year
  6051. (setq year (org-small-year-to-year year)))
  6052. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6053. (org-agenda-change-time-span 'year year)
  6054. (error "Abort")))
  6055. (defun org-agenda-change-time-span (span &optional n)
  6056. "Change the agenda view to SPAN.
  6057. SPAN may be `day', `week', `month', `year'."
  6058. (org-agenda-check-type t 'agenda)
  6059. (if (and (not n) (equal org-agenda-current-span span))
  6060. (error "Viewing span is already \"%s\"" span))
  6061. (let* ((sd (or (org-get-at-bol 'day)
  6062. org-starting-day))
  6063. (sd (org-agenda-compute-starting-span sd span n))
  6064. (org-agenda-overriding-arguments
  6065. (or org-agenda-overriding-arguments
  6066. (list (car org-agenda-last-arguments) sd span t))))
  6067. (org-agenda-redo)
  6068. (org-agenda-find-same-or-today-or-agenda))
  6069. (org-agenda-set-mode-name)
  6070. (message "Switched to %s view" span))
  6071. (defun org-agenda-compute-starting-span (sd span &optional n)
  6072. "Compute starting date for agenda.
  6073. SPAN may be `day', `week', `month', `year'. The return value
  6074. is a cons cell with the starting date and the number of days,
  6075. so that the date SD will be in that range."
  6076. (let* ((greg (calendar-gregorian-from-absolute sd))
  6077. (dg (nth 1 greg))
  6078. (mg (car greg))
  6079. (yg (nth 2 greg)))
  6080. (cond
  6081. ((eq span 'day)
  6082. (when n
  6083. (setq sd (+ (calendar-absolute-from-gregorian
  6084. (list mg 1 yg))
  6085. n -1))))
  6086. ((eq span 'week)
  6087. (let* ((nt (calendar-day-of-week
  6088. (calendar-gregorian-from-absolute sd)))
  6089. (d (if org-agenda-start-on-weekday
  6090. (- nt org-agenda-start-on-weekday)
  6091. 0))
  6092. y1)
  6093. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6094. (when n
  6095. (require 'cal-iso)
  6096. (when (> n 99)
  6097. (setq y1 (org-small-year-to-year (/ n 100))
  6098. n (mod n 100)))
  6099. (setq sd
  6100. (calendar-absolute-from-iso
  6101. (list n 1
  6102. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6103. ((eq span 'month)
  6104. (let (y1)
  6105. (when (and n (> n 99))
  6106. (setq y1 (org-small-year-to-year (/ n 100))
  6107. n (mod n 100)))
  6108. (setq sd (calendar-absolute-from-gregorian
  6109. (list (or n mg) 1 (or y1 yg))))))
  6110. ((eq span 'year)
  6111. (setq sd (calendar-absolute-from-gregorian
  6112. (list 1 1 (or n yg))))))
  6113. sd))
  6114. (defun org-agenda-next-date-line (&optional arg)
  6115. "Jump to the next line indicating a date in agenda buffer."
  6116. (interactive "p")
  6117. (org-agenda-check-type t 'agenda 'timeline)
  6118. (beginning-of-line 1)
  6119. ;; This does not work if user makes date format that starts with a blank
  6120. (if (looking-at "^\\S-") (forward-char 1))
  6121. (if (not (re-search-forward "^\\S-" nil t arg))
  6122. (progn
  6123. (backward-char 1)
  6124. (error "No next date after this line in this buffer")))
  6125. (goto-char (match-beginning 0)))
  6126. (defun org-agenda-previous-date-line (&optional arg)
  6127. "Jump to the previous line indicating a date in agenda buffer."
  6128. (interactive "p")
  6129. (org-agenda-check-type t 'agenda 'timeline)
  6130. (beginning-of-line 1)
  6131. (if (not (re-search-backward "^\\S-" nil t arg))
  6132. (error "No previous date before this line in this buffer")))
  6133. ;; Initialize the highlight
  6134. (defvar org-hl (make-overlay 1 1))
  6135. (overlay-put org-hl 'face 'highlight)
  6136. (defun org-highlight (begin end &optional buffer)
  6137. "Highlight a region with overlay."
  6138. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6139. (defun org-unhighlight ()
  6140. "Detach overlay INDEX."
  6141. (org-detach-overlay org-hl))
  6142. ;; FIXME this is currently not used.
  6143. (defun org-highlight-until-next-command (beg end &optional buffer)
  6144. "Move the highlight overlay to BEG/END, remove it before the next command."
  6145. (org-highlight beg end buffer)
  6146. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6147. (defun org-unhighlight-once ()
  6148. "Remove the highlight from its position, and this function from the hook."
  6149. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6150. (org-unhighlight))
  6151. (defun org-agenda-follow-mode ()
  6152. "Toggle follow mode in an agenda buffer."
  6153. (interactive)
  6154. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6155. (org-agenda-set-mode-name)
  6156. (org-agenda-do-context-action)
  6157. (message "Follow mode is %s"
  6158. (if org-agenda-follow-mode "on" "off")))
  6159. (defun org-agenda-entry-text-mode (&optional arg)
  6160. "Toggle entry text mode in an agenda buffer."
  6161. (interactive "P")
  6162. (setq org-agenda-entry-text-mode (or (integerp arg)
  6163. (not org-agenda-entry-text-mode)))
  6164. (org-agenda-entry-text-hide)
  6165. (and org-agenda-entry-text-mode
  6166. (let ((org-agenda-entry-text-maxlines
  6167. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6168. (org-agenda-entry-text-show)))
  6169. (org-agenda-set-mode-name)
  6170. (message "Entry text mode is %s. Maximum number of lines is %d"
  6171. (if org-agenda-entry-text-mode "on" "off")
  6172. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6173. (defun org-agenda-clockreport-mode (&optional with-filter)
  6174. "Toggle clocktable mode in an agenda buffer.
  6175. With prefix arg WITH-FILTER, make the clocktable respect the current
  6176. agenda filter."
  6177. (interactive "P")
  6178. (org-agenda-check-type t 'agenda)
  6179. (if with-filter
  6180. (setq org-agenda-clockreport-mode 'with-filter)
  6181. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6182. (org-agenda-set-mode-name)
  6183. (org-agenda-redo)
  6184. (message "Clocktable mode is %s"
  6185. (if org-agenda-clockreport-mode "on" "off")))
  6186. (defun org-agenda-log-mode (&optional special)
  6187. "Toggle log mode in an agenda buffer.
  6188. With argument SPECIAL, show all possible log items, not only the ones
  6189. configured in `org-agenda-log-mode-items'.
  6190. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6191. (interactive "P")
  6192. (org-agenda-check-type t 'agenda 'timeline)
  6193. (setq org-agenda-show-log
  6194. (cond
  6195. ((equal special '(16)) 'only)
  6196. ((eq special 'clockcheck)
  6197. (if (eq org-agenda-show-log 'clockcheck)
  6198. nil 'clockcheck))
  6199. (special '(closed clock state))
  6200. (t (not org-agenda-show-log))))
  6201. (org-agenda-set-mode-name)
  6202. (org-agenda-redo)
  6203. (message "Log mode is %s"
  6204. (if org-agenda-show-log "on" "off")))
  6205. (defun org-agenda-archives-mode (&optional with-files)
  6206. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6207. When called with a prefix argument, include all archive files as well."
  6208. (interactive "P")
  6209. (setq org-agenda-archives-mode
  6210. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6211. (org-agenda-set-mode-name)
  6212. (org-agenda-redo)
  6213. (message
  6214. "%s"
  6215. (cond
  6216. ((eq org-agenda-archives-mode nil)
  6217. "No archives are included")
  6218. ((eq org-agenda-archives-mode 'trees)
  6219. (format "Trees with :%s: tag are included" org-archive-tag))
  6220. ((eq org-agenda-archives-mode t)
  6221. (format "Trees with :%s: tag and all active archive files are included"
  6222. org-archive-tag)))))
  6223. (defun org-agenda-toggle-diary ()
  6224. "Toggle diary inclusion in an agenda buffer."
  6225. (interactive)
  6226. (org-agenda-check-type t 'agenda)
  6227. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6228. (org-agenda-redo)
  6229. (org-agenda-set-mode-name)
  6230. (message "Diary inclusion turned %s"
  6231. (if org-agenda-include-diary "on" "off")))
  6232. (defun org-agenda-toggle-deadlines ()
  6233. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6234. (interactive)
  6235. (org-agenda-check-type t 'agenda)
  6236. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6237. (org-agenda-redo)
  6238. (org-agenda-set-mode-name)
  6239. (message "Deadlines inclusion turned %s"
  6240. (if org-agenda-include-deadlines "on" "off")))
  6241. (defun org-agenda-toggle-time-grid ()
  6242. "Toggle time grid in an agenda buffer."
  6243. (interactive)
  6244. (org-agenda-check-type t 'agenda)
  6245. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6246. (org-agenda-redo)
  6247. (org-agenda-set-mode-name)
  6248. (message "Time-grid turned %s"
  6249. (if org-agenda-use-time-grid "on" "off")))
  6250. (defun org-agenda-set-mode-name ()
  6251. "Set the mode name to indicate all the small mode settings."
  6252. (setq mode-name
  6253. (list "Org-Agenda"
  6254. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6255. " "
  6256. '(:eval (org-agenda-span-name org-agenda-current-span))
  6257. (if org-agenda-follow-mode " Follow" "")
  6258. (if org-agenda-entry-text-mode " ETxt" "")
  6259. (if org-agenda-include-diary " Diary" "")
  6260. (if org-agenda-include-deadlines " Ddl" "")
  6261. (if org-agenda-use-time-grid " Grid" "")
  6262. (if (and (boundp 'org-habit-show-habits)
  6263. org-habit-show-habits) " Habit" "")
  6264. (cond
  6265. ((consp org-agenda-show-log) " LogAll")
  6266. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6267. (org-agenda-show-log " Log")
  6268. (t ""))
  6269. (if (or org-agenda-filter (get 'org-agenda-filter
  6270. :preset-filter))
  6271. (concat " {" (mapconcat
  6272. 'identity
  6273. (append (get 'org-agenda-filter
  6274. :preset-filter)
  6275. org-agenda-filter) "") "}")
  6276. "")
  6277. (if org-agenda-archives-mode
  6278. (if (eq org-agenda-archives-mode t)
  6279. " Archives"
  6280. (format " :%s:" org-archive-tag))
  6281. "")
  6282. (if org-agenda-clockreport-mode
  6283. (if (eq org-agenda-clockreport-mode 'with-filter)
  6284. " Clock{}" " Clock")
  6285. "")))
  6286. (force-mode-line-update))
  6287. (defun org-agenda-post-command-hook ()
  6288. (setq org-agenda-type
  6289. (or (get-text-property (point) 'org-agenda-type)
  6290. (get-text-property (max (point-min) (1- (point)))
  6291. 'org-agenda-type))))
  6292. (defun org-agenda-next-line ()
  6293. "Move cursor to the next line, and show if follow mode is active."
  6294. (interactive)
  6295. (call-interactively 'next-line)
  6296. (org-agenda-do-context-action))
  6297. (defun org-agenda-previous-line ()
  6298. "Move cursor to the previous line, and show if follow-mode is active."
  6299. (interactive)
  6300. (call-interactively 'previous-line)
  6301. (org-agenda-do-context-action))
  6302. (defun org-agenda-do-context-action ()
  6303. "Show outline path and, maybe, follow mode window."
  6304. (let ((m (org-get-at-bol 'org-marker)))
  6305. (if (and org-agenda-follow-mode m)
  6306. (if org-agenda-follow-indirect
  6307. (org-agenda-tree-to-indirect-buffer)
  6308. (org-agenda-show)))
  6309. (if (and m org-agenda-show-outline-path)
  6310. (org-with-point-at m
  6311. (org-display-outline-path t)))))
  6312. (defun org-agenda-show-priority ()
  6313. "Show the priority of the current item.
  6314. This priority is composed of the main priority given with the [#A] cookies,
  6315. and by additional input from the age of a schedules or deadline entry."
  6316. (interactive)
  6317. (let* ((pri (org-get-at-bol 'priority)))
  6318. (message "Priority is %d" (if pri pri -1000))))
  6319. (defun org-agenda-show-tags ()
  6320. "Show the tags applicable to the current item."
  6321. (interactive)
  6322. (let* ((tags (org-get-at-bol 'tags)))
  6323. (if tags
  6324. (message "Tags are :%s:"
  6325. (org-no-properties (mapconcat 'identity tags ":")))
  6326. (message "No tags associated with this line"))))
  6327. (defun org-agenda-goto (&optional highlight)
  6328. "Go to the Org-mode file which contains the item at point."
  6329. (interactive)
  6330. (let* ((marker (or (org-get-at-bol 'org-marker)
  6331. (org-agenda-error)))
  6332. (buffer (marker-buffer marker))
  6333. (pos (marker-position marker)))
  6334. (switch-to-buffer-other-window buffer)
  6335. (widen)
  6336. (push-mark)
  6337. (goto-char pos)
  6338. (when (org-mode-p)
  6339. (org-show-context 'agenda)
  6340. (save-excursion
  6341. (and (outline-next-heading)
  6342. (org-flag-heading nil)))) ; show the next heading
  6343. (when (outline-invisible-p)
  6344. (show-entry)) ; display invisible text
  6345. (recenter (/ (window-height) 2))
  6346. (run-hooks 'org-agenda-after-show-hook)
  6347. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6348. (defvar org-agenda-after-show-hook nil
  6349. "Normal hook run after an item has been shown from the agenda.
  6350. Point is in the buffer where the item originated.")
  6351. (defun org-agenda-kill ()
  6352. "Kill the entry or subtree belonging to the current agenda entry."
  6353. (interactive)
  6354. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6355. (let* ((marker (or (org-get-at-bol 'org-marker)
  6356. (org-agenda-error)))
  6357. (buffer (marker-buffer marker))
  6358. (pos (marker-position marker))
  6359. (type (org-get-at-bol 'type))
  6360. dbeg dend (n 0) conf)
  6361. (org-with-remote-undo buffer
  6362. (with-current-buffer buffer
  6363. (save-excursion
  6364. (goto-char pos)
  6365. (if (and (org-mode-p) (not (member type '("sexp"))))
  6366. (setq dbeg (progn (org-back-to-heading t) (point))
  6367. dend (org-end-of-subtree t t))
  6368. (setq dbeg (point-at-bol)
  6369. dend (min (point-max) (1+ (point-at-eol)))))
  6370. (goto-char dbeg)
  6371. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6372. (setq conf (or (eq t org-agenda-confirm-kill)
  6373. (and (numberp org-agenda-confirm-kill)
  6374. (> n org-agenda-confirm-kill))))
  6375. (and conf
  6376. (not (y-or-n-p
  6377. (format "Delete entry with %d lines in buffer \"%s\"? "
  6378. n (buffer-name buffer))))
  6379. (error "Abort"))
  6380. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6381. (with-current-buffer buffer (delete-region dbeg dend))
  6382. (message "Agenda item and source killed"))))
  6383. (defvar org-archive-default-command)
  6384. (defun org-agenda-archive-default ()
  6385. "Archive the entry or subtree belonging to the current agenda entry."
  6386. (interactive)
  6387. (require 'org-archive)
  6388. (org-agenda-archive-with org-archive-default-command))
  6389. (defun org-agenda-archive-default-with-confirmation ()
  6390. "Archive the entry or subtree belonging to the current agenda entry."
  6391. (interactive)
  6392. (require 'org-archive)
  6393. (org-agenda-archive-with org-archive-default-command 'confirm))
  6394. (defun org-agenda-archive ()
  6395. "Archive the entry or subtree belonging to the current agenda entry."
  6396. (interactive)
  6397. (org-agenda-archive-with 'org-archive-subtree))
  6398. (defun org-agenda-archive-to-archive-sibling ()
  6399. "Move the entry to the archive sibling."
  6400. (interactive)
  6401. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6402. (defun org-agenda-archive-with (cmd &optional confirm)
  6403. "Move the entry to the archive sibling."
  6404. (interactive)
  6405. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6406. (let* ((marker (or (org-get-at-bol 'org-marker)
  6407. (org-agenda-error)))
  6408. (buffer (marker-buffer marker))
  6409. (pos (marker-position marker)))
  6410. (org-with-remote-undo buffer
  6411. (with-current-buffer buffer
  6412. (if (org-mode-p)
  6413. (if (and confirm
  6414. (not (y-or-n-p "Archive this subtree or entry? ")))
  6415. (error "Abort")
  6416. (save-excursion
  6417. (goto-char pos)
  6418. (org-remove-subtree-entries-from-agenda)
  6419. (org-back-to-heading t)
  6420. (funcall cmd)))
  6421. (error "Archiving works only in Org-mode files"))))))
  6422. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6423. "Remove all lines in the agenda that correspond to a given subtree.
  6424. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6425. If this information is not given, the function uses the tree at point."
  6426. (let ((buf (or buf (current-buffer))) m p)
  6427. (save-excursion
  6428. (unless (and beg end)
  6429. (org-back-to-heading t)
  6430. (setq beg (point))
  6431. (org-end-of-subtree t)
  6432. (setq end (point)))
  6433. (set-buffer (get-buffer org-agenda-buffer-name))
  6434. (save-excursion
  6435. (goto-char (point-max))
  6436. (beginning-of-line 1)
  6437. (while (not (bobp))
  6438. (when (and (setq m (org-get-at-bol 'org-marker))
  6439. (equal buf (marker-buffer m))
  6440. (setq p (marker-position m))
  6441. (>= p beg)
  6442. (< p end))
  6443. (let ((inhibit-read-only t))
  6444. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6445. (beginning-of-line 0))))))
  6446. (defun org-agenda-refile (&optional goto rfloc no-update)
  6447. "Refile the item at point."
  6448. (interactive "P")
  6449. (if (equal goto '(16))
  6450. (org-refile-goto-last-stored)
  6451. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6452. (org-agenda-error)))
  6453. (buffer (marker-buffer marker))
  6454. (pos (marker-position marker))
  6455. (rfloc (or rfloc
  6456. (org-refile-get-location
  6457. (if goto "Goto" "Refile to") buffer
  6458. org-refile-allow-creating-parent-nodes))))
  6459. (with-current-buffer buffer
  6460. (save-excursion
  6461. (save-restriction
  6462. (widen)
  6463. (goto-char marker)
  6464. (org-remove-subtree-entries-from-agenda)
  6465. (org-refile goto buffer rfloc)))))
  6466. (unless no-update (org-agenda-redo))))
  6467. (defun org-agenda-open-link (&optional arg)
  6468. "Follow the link in the current line, if any.
  6469. This looks for a link in the displayed line in the agenda. It also looks
  6470. at the text of the entry itself."
  6471. (interactive "P")
  6472. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6473. (org-get-at-bol 'org-marker)))
  6474. (buffer (and marker (marker-buffer marker)))
  6475. (prefix (buffer-substring
  6476. (point-at-bol) (point-at-eol))))
  6477. (cond
  6478. (buffer
  6479. (with-current-buffer buffer
  6480. (save-excursion
  6481. (save-restriction
  6482. (widen)
  6483. (goto-char marker)
  6484. (org-offer-links-in-entry arg prefix)))))
  6485. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6486. (save-excursion
  6487. (beginning-of-line 1)
  6488. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6489. (org-open-link-from-string (match-string 1)))
  6490. (t (error "No link to open here")))))
  6491. (defun org-agenda-copy-local-variable (var)
  6492. "Get a variable from a referenced buffer and install it here."
  6493. (let ((m (org-get-at-bol 'org-marker)))
  6494. (when (and m (buffer-live-p (marker-buffer m)))
  6495. (org-set-local var (with-current-buffer (marker-buffer m)
  6496. (symbol-value var))))))
  6497. (defun org-agenda-switch-to (&optional delete-other-windows)
  6498. "Go to the Org-mode file which contains the item at point."
  6499. (interactive)
  6500. (if (and org-return-follows-link
  6501. (not (org-get-at-bol 'org-marker))
  6502. (org-in-regexp org-bracket-link-regexp))
  6503. (org-open-link-from-string (match-string 0))
  6504. (let* ((marker (or (org-get-at-bol 'org-marker)
  6505. (org-agenda-error)))
  6506. (buffer (marker-buffer marker))
  6507. (pos (marker-position marker)))
  6508. (org-pop-to-buffer-same-window buffer)
  6509. (and delete-other-windows (delete-other-windows))
  6510. (widen)
  6511. (goto-char pos)
  6512. (when (org-mode-p)
  6513. (org-show-context 'agenda)
  6514. (save-excursion
  6515. (and (outline-next-heading)
  6516. (org-flag-heading nil))) ; show the next heading
  6517. (when (outline-invisible-p)
  6518. (show-entry)))))) ; display invisible text
  6519. (defun org-agenda-goto-mouse (ev)
  6520. "Go to the Org-mode file which contains the item at the mouse click."
  6521. (interactive "e")
  6522. (mouse-set-point ev)
  6523. (org-agenda-goto))
  6524. (defun org-agenda-show (&optional full-entry)
  6525. "Display the Org-mode file which contains the item at point.
  6526. With prefix argument FULL-ENTRY, make the entire entry visible
  6527. if it was hidden in the outline."
  6528. (interactive "P")
  6529. (let ((win (selected-window)))
  6530. (if full-entry
  6531. (let ((org-show-entry-below t))
  6532. (org-agenda-goto t))
  6533. (org-agenda-goto t))
  6534. (select-window win)))
  6535. (defvar org-agenda-show-window nil)
  6536. (defun org-agenda-show-and-scroll-up ()
  6537. "Display the Org-mode file which contains the item at point.
  6538. When called repeatedly, scroll the window that is displaying the buffer."
  6539. (interactive)
  6540. (let ((win (selected-window)))
  6541. (if (and (window-live-p org-agenda-show-window)
  6542. (eq this-command last-command))
  6543. (progn
  6544. (select-window org-agenda-show-window)
  6545. (ignore-errors (scroll-up)))
  6546. (org-agenda-goto t)
  6547. (show-subtree)
  6548. (setq org-agenda-show-window (selected-window)))
  6549. (select-window win)))
  6550. (defun org-agenda-show-scroll-down ()
  6551. "Scroll down the window showing the agenda."
  6552. (interactive)
  6553. (let ((win (selected-window)))
  6554. (when (window-live-p org-agenda-show-window)
  6555. (select-window org-agenda-show-window)
  6556. (ignore-errors (scroll-down))
  6557. (select-window win))))
  6558. (defun org-agenda-show-1 (&optional more)
  6559. "Display the Org-mode file which contains the item at point.
  6560. The prefix arg selects the amount of information to display:
  6561. 0 hide the subtree
  6562. 1 just show the entry according to defaults.
  6563. 2 show the children view
  6564. 3 show the subtree view
  6565. 4 show the entire subtree and any LOGBOOK drawers
  6566. 5 show the entire subtree and any drawers
  6567. With prefix argument FULL-ENTRY, make the entire entry visible
  6568. if it was hidden in the outline."
  6569. (interactive "p")
  6570. (let ((win (selected-window)))
  6571. (org-agenda-goto t)
  6572. (org-recenter-heading 1)
  6573. (cond
  6574. ((= more 0)
  6575. (hide-subtree)
  6576. (save-excursion
  6577. (org-back-to-heading)
  6578. (run-hook-with-args 'org-cycle-hook 'folded))
  6579. (message "Remote: FOLDED"))
  6580. ((and (org-called-interactively-p 'any) (= more 1))
  6581. (message "Remote: show with default settings"))
  6582. ((= more 2)
  6583. (show-entry)
  6584. (show-children)
  6585. (save-excursion
  6586. (org-back-to-heading)
  6587. (run-hook-with-args 'org-cycle-hook 'children))
  6588. (message "Remote: CHILDREN"))
  6589. ((= more 3)
  6590. (show-subtree)
  6591. (save-excursion
  6592. (org-back-to-heading)
  6593. (run-hook-with-args 'org-cycle-hook 'subtree))
  6594. (message "Remote: SUBTREE"))
  6595. ((= more 4)
  6596. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6597. (org-drawer-regexp
  6598. (concat "^[ \t]*:\\("
  6599. (mapconcat 'regexp-quote org-drawers "\\|")
  6600. "\\):[ \t]*$")))
  6601. (show-subtree)
  6602. (save-excursion
  6603. (org-back-to-heading)
  6604. (org-cycle-hide-drawers 'subtree)))
  6605. (message "Remote: SUBTREE AND LOGBOOK"))
  6606. ((> more 4)
  6607. (show-subtree)
  6608. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6609. (select-window win)))
  6610. (defun org-recenter-heading (n)
  6611. (save-excursion
  6612. (org-back-to-heading)
  6613. (recenter n)))
  6614. (defvar org-agenda-cycle-counter nil)
  6615. (defun org-agenda-cycle-show (&optional n)
  6616. "Show the current entry in another window, with default settings.
  6617. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6618. When use repeatedly in immediate succession, the remote entry will cycle
  6619. through visibility
  6620. children -> subtree -> folded
  6621. When called with a numeric prefix arg, that arg will be passed through to
  6622. `org-agenda-show-1'. For the interpretation of that argument, see the
  6623. docstring of `org-agenda-show-1'."
  6624. (interactive "P")
  6625. (if (integerp n)
  6626. (setq org-agenda-cycle-counter n)
  6627. (if (not (eq last-command this-command))
  6628. (setq org-agenda-cycle-counter 1)
  6629. (if (equal org-agenda-cycle-counter 0)
  6630. (setq org-agenda-cycle-counter 2)
  6631. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6632. (if (> org-agenda-cycle-counter 3)
  6633. (setq org-agenda-cycle-counter 0)))))
  6634. (org-agenda-show-1 org-agenda-cycle-counter))
  6635. (defun org-agenda-recenter (arg)
  6636. "Display the Org-mode file which contains the item at point and recenter."
  6637. (interactive "P")
  6638. (let ((win (selected-window)))
  6639. (org-agenda-goto t)
  6640. (recenter arg)
  6641. (select-window win)))
  6642. (defun org-agenda-show-mouse (ev)
  6643. "Display the Org-mode file which contains the item at the mouse click."
  6644. (interactive "e")
  6645. (mouse-set-point ev)
  6646. (org-agenda-show))
  6647. (defun org-agenda-check-no-diary ()
  6648. "Check if the entry is a diary link and abort if yes."
  6649. (if (org-get-at-bol 'org-agenda-diary-link)
  6650. (org-agenda-error)))
  6651. (defun org-agenda-error ()
  6652. (error "Command not allowed in this line"))
  6653. (defun org-agenda-tree-to-indirect-buffer ()
  6654. "Show the subtree corresponding to the current entry in an indirect buffer.
  6655. This calls the command `org-tree-to-indirect-buffer' from the original
  6656. Org-mode buffer.
  6657. With numerical prefix arg ARG, go up to this level and then take that tree.
  6658. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6659. use the dedicated frame)."
  6660. (interactive)
  6661. (org-agenda-check-no-diary)
  6662. (let* ((marker (or (org-get-at-bol 'org-marker)
  6663. (org-agenda-error)))
  6664. (buffer (marker-buffer marker))
  6665. (pos (marker-position marker)))
  6666. (with-current-buffer buffer
  6667. (save-excursion
  6668. (goto-char pos)
  6669. (call-interactively 'org-tree-to-indirect-buffer)))))
  6670. (defvar org-last-heading-marker (make-marker)
  6671. "Marker pointing to the headline that last changed its TODO state
  6672. by a remote command from the agenda.")
  6673. (defun org-agenda-todo-nextset ()
  6674. "Switch TODO entry to next sequence."
  6675. (interactive)
  6676. (org-agenda-todo 'nextset))
  6677. (defun org-agenda-todo-previousset ()
  6678. "Switch TODO entry to previous sequence."
  6679. (interactive)
  6680. (org-agenda-todo 'previousset))
  6681. (defun org-agenda-todo (&optional arg)
  6682. "Cycle TODO state of line at point, also in Org-mode file.
  6683. This changes the line at point, all other lines in the agenda referring to
  6684. the same tree node, and the headline of the tree node in the Org-mode file."
  6685. (interactive "P")
  6686. (org-agenda-check-no-diary)
  6687. (let* ((col (current-column))
  6688. (marker (or (org-get-at-bol 'org-marker)
  6689. (org-agenda-error)))
  6690. (buffer (marker-buffer marker))
  6691. (pos (marker-position marker))
  6692. (hdmarker (org-get-at-bol 'org-hd-marker))
  6693. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6694. (inhibit-read-only t)
  6695. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6696. (org-with-remote-undo buffer
  6697. (with-current-buffer buffer
  6698. (widen)
  6699. (goto-char pos)
  6700. (org-show-context 'agenda)
  6701. (save-excursion
  6702. (and (outline-next-heading)
  6703. (org-flag-heading nil))) ; show the next heading
  6704. (let ((current-prefix-arg arg))
  6705. (call-interactively 'org-todo))
  6706. (and (bolp) (forward-char 1))
  6707. (setq newhead (org-get-heading))
  6708. (when (and (org-bound-and-true-p
  6709. org-agenda-headline-snapshot-before-repeat)
  6710. (not (equal org-agenda-headline-snapshot-before-repeat
  6711. newhead))
  6712. todayp)
  6713. (setq newhead org-agenda-headline-snapshot-before-repeat
  6714. just-one t))
  6715. (save-excursion
  6716. (org-back-to-heading)
  6717. (move-marker org-last-heading-marker (point))))
  6718. (beginning-of-line 1)
  6719. (save-excursion
  6720. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6721. (org-move-to-column col))))
  6722. (defun org-agenda-add-note (&optional arg)
  6723. "Add a time-stamped note to the entry at point."
  6724. (interactive "P")
  6725. (org-agenda-check-no-diary)
  6726. (let* ((marker (or (org-get-at-bol 'org-marker)
  6727. (org-agenda-error)))
  6728. (buffer (marker-buffer marker))
  6729. (pos (marker-position marker))
  6730. (hdmarker (org-get-at-bol 'org-hd-marker))
  6731. (inhibit-read-only t))
  6732. (with-current-buffer buffer
  6733. (widen)
  6734. (goto-char pos)
  6735. (org-show-context 'agenda)
  6736. (save-excursion
  6737. (and (outline-next-heading)
  6738. (org-flag-heading nil))) ; show the next heading
  6739. (org-add-note))))
  6740. (defun org-agenda-change-all-lines (newhead hdmarker
  6741. &optional fixface just-this)
  6742. "Change all lines in the agenda buffer which match HDMARKER.
  6743. The new content of the line will be NEWHEAD (as modified by
  6744. `org-format-agenda-item'). HDMARKER is checked with
  6745. `equal' against all `org-hd-marker' text properties in the file.
  6746. If FIXFACE is non-nil, the face of each item is modified according to
  6747. the new TODO state.
  6748. If JUST-THIS is non-nil, change just the current line, not all.
  6749. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6750. (let* ((inhibit-read-only t)
  6751. (line (org-current-line))
  6752. (thetags (with-current-buffer (marker-buffer hdmarker)
  6753. (save-excursion (save-restriction (widen)
  6754. (goto-char hdmarker)
  6755. (org-get-tags-at)))))
  6756. props m pl undone-face done-face finish new dotime cat tags)
  6757. (save-excursion
  6758. (goto-char (point-max))
  6759. (beginning-of-line 1)
  6760. (while (not finish)
  6761. (setq finish (bobp))
  6762. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6763. (or (not just-this) (= (org-current-line) line))
  6764. (equal m hdmarker))
  6765. (setq props (text-properties-at (point))
  6766. dotime (org-get-at-bol 'dotime)
  6767. cat (org-get-at-bol 'org-category)
  6768. tags thetags
  6769. new
  6770. (let ((org-prefix-format-compiled
  6771. (or (get-text-property (point) 'format)
  6772. org-prefix-format-compiled)))
  6773. (with-current-buffer (marker-buffer hdmarker)
  6774. (save-excursion
  6775. (save-restriction
  6776. (widen)
  6777. (org-format-agenda-item (org-get-at-bol 'extra)
  6778. newhead cat tags dotime)))))
  6779. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6780. undone-face (org-get-at-bol 'undone-face)
  6781. done-face (org-get-at-bol 'done-face))
  6782. (beginning-of-line 1)
  6783. (cond
  6784. ((equal new "")
  6785. (and (looking-at ".*\n?") (replace-match "")))
  6786. ((looking-at ".*")
  6787. (replace-match new t t)
  6788. (beginning-of-line 1)
  6789. (add-text-properties (point-at-bol) (point-at-eol) props)
  6790. (when fixface
  6791. (add-text-properties
  6792. (point-at-bol) (point-at-eol)
  6793. (list 'face
  6794. (if org-last-todo-state-is-todo
  6795. undone-face done-face))))
  6796. (org-agenda-highlight-todo 'line)
  6797. (beginning-of-line 1))
  6798. (t (error "Line update did not work"))))
  6799. (beginning-of-line 0)))
  6800. (org-finalize-agenda)))
  6801. (defun org-agenda-align-tags (&optional line)
  6802. "Align all tags in agenda items to `org-agenda-tags-column'."
  6803. (let ((inhibit-read-only t) l c)
  6804. (save-excursion
  6805. (goto-char (if line (point-at-bol) (point-min)))
  6806. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6807. (if line (point-at-eol) nil) t)
  6808. (add-text-properties
  6809. (match-beginning 2) (match-end 2)
  6810. (list 'face (delq nil (let ((prop (get-text-property
  6811. (match-beginning 2) 'face)))
  6812. (or (listp prop) (setq prop (list prop)))
  6813. (if (memq 'org-tag prop)
  6814. prop
  6815. (cons 'org-tag prop))))))
  6816. (setq l (- (match-end 2) (match-beginning 2))
  6817. c (if (< org-agenda-tags-column 0)
  6818. (- (abs org-agenda-tags-column) l)
  6819. org-agenda-tags-column))
  6820. (delete-region (match-beginning 1) (match-end 1))
  6821. (goto-char (match-beginning 1))
  6822. (insert (org-add-props
  6823. (make-string (max 1 (- c (current-column))) ?\ )
  6824. (plist-put (copy-sequence (text-properties-at (point)))
  6825. 'face nil))))
  6826. (goto-char (point-min))
  6827. (org-font-lock-add-tag-faces (point-max)))))
  6828. (defun org-agenda-priority-up ()
  6829. "Increase the priority of line at point, also in Org-mode file."
  6830. (interactive)
  6831. (org-agenda-priority 'up))
  6832. (defun org-agenda-priority-down ()
  6833. "Decrease the priority of line at point, also in Org-mode file."
  6834. (interactive)
  6835. (org-agenda-priority 'down))
  6836. (defun org-agenda-priority (&optional force-direction)
  6837. "Set the priority of line at point, also in Org-mode file.
  6838. This changes the line at point, all other lines in the agenda referring to
  6839. the same tree node, and the headline of the tree node in the Org-mode file."
  6840. (interactive)
  6841. (unless org-enable-priority-commands
  6842. (error "Priority commands are disabled"))
  6843. (org-agenda-check-no-diary)
  6844. (let* ((marker (or (org-get-at-bol 'org-marker)
  6845. (org-agenda-error)))
  6846. (hdmarker (org-get-at-bol 'org-hd-marker))
  6847. (buffer (marker-buffer hdmarker))
  6848. (pos (marker-position hdmarker))
  6849. (inhibit-read-only t)
  6850. newhead)
  6851. (org-with-remote-undo buffer
  6852. (with-current-buffer buffer
  6853. (widen)
  6854. (goto-char pos)
  6855. (org-show-context 'agenda)
  6856. (save-excursion
  6857. (and (outline-next-heading)
  6858. (org-flag-heading nil))) ; show the next heading
  6859. (funcall 'org-priority force-direction)
  6860. (end-of-line 1)
  6861. (setq newhead (org-get-heading)))
  6862. (org-agenda-change-all-lines newhead hdmarker)
  6863. (beginning-of-line 1))))
  6864. ;; FIXME: should fix the tags property of the agenda line.
  6865. (defun org-agenda-set-tags (&optional tag onoff)
  6866. "Set tags for the current headline."
  6867. (interactive)
  6868. (org-agenda-check-no-diary)
  6869. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6870. (call-interactively 'org-change-tag-in-region)
  6871. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6872. (org-agenda-error)))
  6873. (buffer (marker-buffer hdmarker))
  6874. (pos (marker-position hdmarker))
  6875. (inhibit-read-only t)
  6876. newhead)
  6877. (org-with-remote-undo buffer
  6878. (with-current-buffer buffer
  6879. (widen)
  6880. (goto-char pos)
  6881. (save-excursion
  6882. (org-show-context 'agenda))
  6883. (save-excursion
  6884. (and (outline-next-heading)
  6885. (org-flag-heading nil))) ; show the next heading
  6886. (goto-char pos)
  6887. (if tag
  6888. (org-toggle-tag tag onoff)
  6889. (call-interactively 'org-set-tags))
  6890. (end-of-line 1)
  6891. (setq newhead (org-get-heading)))
  6892. (org-agenda-change-all-lines newhead hdmarker)
  6893. (beginning-of-line 1)))))
  6894. (defun org-agenda-set-property ()
  6895. "Set a property for the current headline."
  6896. (interactive)
  6897. (org-agenda-check-no-diary)
  6898. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6899. (org-agenda-error)))
  6900. (buffer (marker-buffer hdmarker))
  6901. (pos (marker-position hdmarker))
  6902. (inhibit-read-only t)
  6903. newhead)
  6904. (org-with-remote-undo buffer
  6905. (with-current-buffer buffer
  6906. (widen)
  6907. (goto-char pos)
  6908. (save-excursion
  6909. (org-show-context 'agenda))
  6910. (save-excursion
  6911. (and (outline-next-heading)
  6912. (org-flag-heading nil))) ; show the next heading
  6913. (goto-char pos)
  6914. (call-interactively 'org-set-property)))))
  6915. (defun org-agenda-set-effort ()
  6916. "Set the effort property for the current headline."
  6917. (interactive)
  6918. (org-agenda-check-no-diary)
  6919. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6920. (org-agenda-error)))
  6921. (buffer (marker-buffer hdmarker))
  6922. (pos (marker-position hdmarker))
  6923. (inhibit-read-only t)
  6924. newhead)
  6925. (org-with-remote-undo buffer
  6926. (with-current-buffer buffer
  6927. (widen)
  6928. (goto-char pos)
  6929. (save-excursion
  6930. (org-show-context 'agenda))
  6931. (save-excursion
  6932. (and (outline-next-heading)
  6933. (org-flag-heading nil))) ; show the next heading
  6934. (goto-char pos)
  6935. (call-interactively 'org-set-effort)
  6936. (end-of-line 1)
  6937. (setq newhead (org-get-heading)))
  6938. (org-agenda-change-all-lines newhead hdmarker))))
  6939. (defun org-agenda-toggle-archive-tag ()
  6940. "Toggle the archive tag for the current entry."
  6941. (interactive)
  6942. (org-agenda-check-no-diary)
  6943. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6944. (org-agenda-error)))
  6945. (buffer (marker-buffer hdmarker))
  6946. (pos (marker-position hdmarker))
  6947. (inhibit-read-only t)
  6948. newhead)
  6949. (org-with-remote-undo buffer
  6950. (with-current-buffer buffer
  6951. (widen)
  6952. (goto-char pos)
  6953. (org-show-context 'agenda)
  6954. (save-excursion
  6955. (and (outline-next-heading)
  6956. (org-flag-heading nil))) ; show the next heading
  6957. (call-interactively 'org-toggle-archive-tag)
  6958. (end-of-line 1)
  6959. (setq newhead (org-get-heading)))
  6960. (org-agenda-change-all-lines newhead hdmarker)
  6961. (beginning-of-line 1))))
  6962. (defun org-agenda-do-date-later (arg)
  6963. (interactive "P")
  6964. (cond
  6965. ((or (equal arg '(16))
  6966. (memq last-command
  6967. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6968. (setq this-command 'org-agenda-date-later-minutes)
  6969. (org-agenda-date-later-minutes 1))
  6970. ((or (equal arg '(4))
  6971. (memq last-command
  6972. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6973. (setq this-command 'org-agenda-date-later-hours)
  6974. (org-agenda-date-later-hours 1))
  6975. (t
  6976. (org-agenda-date-later (prefix-numeric-value arg)))))
  6977. (defun org-agenda-do-date-earlier (arg)
  6978. (interactive "P")
  6979. (cond
  6980. ((or (equal arg '(16))
  6981. (memq last-command
  6982. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6983. (setq this-command 'org-agenda-date-earlier-minutes)
  6984. (org-agenda-date-earlier-minutes 1))
  6985. ((or (equal arg '(4))
  6986. (memq last-command
  6987. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6988. (setq this-command 'org-agenda-date-earlier-hours)
  6989. (org-agenda-date-earlier-hours 1))
  6990. (t
  6991. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6992. (defun org-agenda-date-later (arg &optional what)
  6993. "Change the date of this item to ARG day(s) later."
  6994. (interactive "p")
  6995. (org-agenda-check-type t 'agenda 'timeline)
  6996. (org-agenda-check-no-diary)
  6997. (let* ((marker (or (org-get-at-bol 'org-marker)
  6998. (org-agenda-error)))
  6999. (buffer (marker-buffer marker))
  7000. (pos (marker-position marker)))
  7001. (org-with-remote-undo buffer
  7002. (with-current-buffer buffer
  7003. (widen)
  7004. (goto-char pos)
  7005. (if (not (org-at-timestamp-p))
  7006. (error "Cannot find time stamp"))
  7007. (org-timestamp-change arg (or what 'day)))
  7008. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7009. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7010. (defun org-agenda-date-earlier (arg &optional what)
  7011. "Change the date of this item to ARG day(s) earlier."
  7012. (interactive "p")
  7013. (org-agenda-date-later (- arg) what))
  7014. (defun org-agenda-date-later-minutes (arg)
  7015. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7016. (interactive "p")
  7017. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7018. (org-agenda-date-later arg 'minute))
  7019. (defun org-agenda-date-earlier-minutes (arg)
  7020. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7021. (interactive "p")
  7022. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7023. (org-agenda-date-earlier arg 'minute))
  7024. (defun org-agenda-date-later-hours (arg)
  7025. "Change the time of this item, in hour steps."
  7026. (interactive "p")
  7027. (org-agenda-date-later arg 'hour))
  7028. (defun org-agenda-date-earlier-hours (arg)
  7029. "Change the time of this item, in hour steps."
  7030. (interactive "p")
  7031. (org-agenda-date-earlier arg 'hour))
  7032. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7033. "Show new date stamp via text properties."
  7034. ;; We use text properties to make this undoable
  7035. (let ((inhibit-read-only t)
  7036. (buffer-invisibility-spec))
  7037. (setq stamp (concat " " prefix " => " stamp))
  7038. (save-excursion
  7039. (goto-char (point-max))
  7040. (while (not (bobp))
  7041. (when (equal marker (org-get-at-bol 'org-marker))
  7042. (org-move-to-column (- (window-width) (length stamp)) t)
  7043. (org-agenda-fix-tags-filter-overlays-at (point))
  7044. (if (featurep 'xemacs)
  7045. ;; Use `duplicable' property to trigger undo recording
  7046. (let ((ex (make-extent nil nil))
  7047. (gl (make-glyph stamp)))
  7048. (set-glyph-face gl 'secondary-selection)
  7049. (set-extent-properties
  7050. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7051. (insert-extent ex (1- (point)) (point-at-eol)))
  7052. (add-text-properties
  7053. (1- (point)) (point-at-eol)
  7054. (list 'display (org-add-props stamp nil
  7055. 'face 'secondary-selection))))
  7056. (beginning-of-line 1))
  7057. (beginning-of-line 0)))))
  7058. (defun org-agenda-date-prompt (arg)
  7059. "Change the date of this item. Date is prompted for, with default today.
  7060. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7061. be used to request time specification in the time stamp."
  7062. (interactive "P")
  7063. (org-agenda-check-type t 'agenda 'timeline)
  7064. (org-agenda-check-no-diary)
  7065. (let* ((marker (or (org-get-at-bol 'org-marker)
  7066. (org-agenda-error)))
  7067. (buffer (marker-buffer marker))
  7068. (pos (marker-position marker)))
  7069. (org-with-remote-undo buffer
  7070. (with-current-buffer buffer
  7071. (widen)
  7072. (goto-char pos)
  7073. (if (not (org-at-timestamp-p t))
  7074. (error "Cannot find time stamp"))
  7075. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7076. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7077. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7078. (defun org-agenda-schedule (arg &optional time)
  7079. "Schedule the item at point.
  7080. ARG is passed through to `org-schedule'."
  7081. (interactive "P")
  7082. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7083. (org-agenda-check-no-diary)
  7084. (let* ((marker (or (org-get-at-bol 'org-marker)
  7085. (org-agenda-error)))
  7086. (type (marker-insertion-type marker))
  7087. (buffer (marker-buffer marker))
  7088. (pos (marker-position marker))
  7089. (org-insert-labeled-timestamps-at-point nil)
  7090. ts)
  7091. (set-marker-insertion-type marker t)
  7092. (org-with-remote-undo buffer
  7093. (with-current-buffer buffer
  7094. (widen)
  7095. (goto-char pos)
  7096. (setq ts (org-schedule arg time)))
  7097. (org-agenda-show-new-time marker ts "S"))
  7098. (message "Item scheduled for %s" ts)))
  7099. (defun org-agenda-deadline (arg &optional time)
  7100. "Schedule the item at point.
  7101. ARG is passed through to `org-deadline'."
  7102. (interactive "P")
  7103. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7104. (org-agenda-check-no-diary)
  7105. (let* ((marker (or (org-get-at-bol 'org-marker)
  7106. (org-agenda-error)))
  7107. (buffer (marker-buffer marker))
  7108. (pos (marker-position marker))
  7109. (org-insert-labeled-timestamps-at-point nil)
  7110. ts)
  7111. (org-with-remote-undo buffer
  7112. (with-current-buffer buffer
  7113. (widen)
  7114. (goto-char pos)
  7115. (setq ts (org-deadline arg time)))
  7116. (org-agenda-show-new-time marker ts "D"))
  7117. (message "Deadline for this item set to %s" ts)))
  7118. (defun org-agenda-action ()
  7119. "Select entry for agenda action, or execute an agenda action.
  7120. This command prompts for another letter. Valid inputs are:
  7121. m Mark the entry at point for an agenda action
  7122. s Schedule the marked entry to the date at the cursor
  7123. d Set the deadline of the marked entry to the date at the cursor
  7124. r Call `org-remember' with cursor date as the default date
  7125. c Call `org-capture' with cursor date as the default date
  7126. SPC Show marked entry in other window
  7127. TAB Visit marked entry in other window
  7128. The cursor may be at a date in the calendar, or in the Org agenda."
  7129. (interactive)
  7130. (let (ans)
  7131. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7132. (setq ans (read-char-exclusive))
  7133. (cond
  7134. ((equal ans ?m)
  7135. ;; Mark this entry
  7136. (if (eq major-mode 'org-agenda-mode)
  7137. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7138. (org-get-at-bol 'org-marker))))
  7139. (if m
  7140. (progn
  7141. (move-marker org-agenda-action-marker
  7142. (marker-position m) (marker-buffer m))
  7143. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7144. (error "Don't know which entry to mark")))
  7145. (error "This command works only in the agenda")))
  7146. ((equal ans ?s)
  7147. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7148. ((equal ans ?d)
  7149. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7150. ((equal ans ?r)
  7151. (org-agenda-do-action '(org-remember) t))
  7152. ((equal ans ?c)
  7153. (org-agenda-do-action '(org-capture) t))
  7154. ((equal ans ?\ )
  7155. (let ((cw (selected-window)))
  7156. (org-switch-to-buffer-other-window
  7157. (marker-buffer org-agenda-action-marker))
  7158. (goto-char org-agenda-action-marker)
  7159. (org-show-context 'agenda)
  7160. (select-window cw)))
  7161. ((equal ans ?\C-i)
  7162. (org-switch-to-buffer-other-window
  7163. (marker-buffer org-agenda-action-marker))
  7164. (goto-char org-agenda-action-marker)
  7165. (org-show-context 'agenda))
  7166. (t (error "Invalid agenda action %c" ans)))))
  7167. (defun org-agenda-do-action (form &optional current-buffer)
  7168. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7169. (let ((org-overriding-default-time (org-get-cursor-date)))
  7170. (if current-buffer
  7171. (eval form)
  7172. (if (not (marker-buffer org-agenda-action-marker))
  7173. (error "No entry has been selected for agenda action")
  7174. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7175. (save-excursion
  7176. (save-restriction
  7177. (widen)
  7178. (goto-char org-agenda-action-marker)
  7179. (eval form))))))))
  7180. (defun org-agenda-clock-in (&optional arg)
  7181. "Start the clock on the currently selected item."
  7182. (interactive "P")
  7183. (org-agenda-check-no-diary)
  7184. (if (equal arg '(4))
  7185. (org-clock-in arg)
  7186. (let* ((marker (or (org-get-at-bol 'org-marker)
  7187. (org-agenda-error)))
  7188. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7189. marker))
  7190. (pos (marker-position marker))
  7191. newhead)
  7192. (org-with-remote-undo (marker-buffer marker)
  7193. (with-current-buffer (marker-buffer marker)
  7194. (widen)
  7195. (goto-char pos)
  7196. (org-show-context 'agenda)
  7197. (org-show-entry)
  7198. (org-cycle-hide-drawers 'children)
  7199. (org-clock-in arg)
  7200. (setq newhead (org-get-heading)))
  7201. (org-agenda-change-all-lines newhead hdmarker)))))
  7202. (defun org-agenda-clock-out ()
  7203. "Stop the currently running clock."
  7204. (interactive)
  7205. (unless (marker-buffer org-clock-marker)
  7206. (error "No running clock"))
  7207. (let ((marker (make-marker)) newhead)
  7208. (org-with-remote-undo (marker-buffer org-clock-marker)
  7209. (with-current-buffer (marker-buffer org-clock-marker)
  7210. (save-excursion
  7211. (save-restriction
  7212. (widen)
  7213. (goto-char org-clock-marker)
  7214. (org-back-to-heading t)
  7215. (move-marker marker (point))
  7216. (org-clock-out)
  7217. (setq newhead (org-get-heading))))))
  7218. (org-agenda-change-all-lines newhead marker)
  7219. (move-marker marker nil)))
  7220. (defun org-agenda-clock-cancel (&optional arg)
  7221. "Cancel the currently running clock."
  7222. (interactive "P")
  7223. (unless (marker-buffer org-clock-marker)
  7224. (error "No running clock"))
  7225. (org-with-remote-undo (marker-buffer org-clock-marker)
  7226. (org-clock-cancel)))
  7227. (defun org-agenda-clock-goto ()
  7228. "Jump to the currently clocked in task within the agenda.
  7229. If the currently clocked in task is not listed in the agenda
  7230. buffer, display it in another window."
  7231. (interactive)
  7232. (let (pos)
  7233. (mapc (lambda (o)
  7234. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7235. (setq pos (overlay-start o))))
  7236. (overlays-in (point-min) (point-max)))
  7237. (cond (pos (goto-char pos))
  7238. ;; If the currently clocked entry is not in the agenda
  7239. ;; buffer, we visit it in another window:
  7240. (org-clock-current-task
  7241. (org-switch-to-buffer-other-window (org-clock-goto)))
  7242. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7243. (defun org-agenda-diary-entry-in-org-file ()
  7244. "Make a diary entry in the file `org-agenda-diary-file'."
  7245. (let (d1 d2 char (text "") dp1 dp2)
  7246. (if (equal (buffer-name) "*Calendar*")
  7247. (setq d1 (calendar-cursor-to-date t)
  7248. d2 (car calendar-mark-ring))
  7249. (setq dp1 (get-text-property (point-at-bol) 'day))
  7250. (unless dp1 (error "No date defined in current line"))
  7251. (setq d1 (calendar-gregorian-from-absolute dp1)
  7252. d2 (and (ignore-errors (mark))
  7253. (save-excursion
  7254. (goto-char (mark))
  7255. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7256. (calendar-gregorian-from-absolute dp2))))
  7257. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7258. (setq char (read-char-exclusive))
  7259. (cond
  7260. ((equal char ?d)
  7261. (setq text (read-string "Day entry: "))
  7262. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7263. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7264. ((equal char ?a)
  7265. (setq d1 (list (car d1) (nth 1 d1)
  7266. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7267. (nth 2 d1))))
  7268. (setq text (read-string "Anniversary (use %d to show years): "))
  7269. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7270. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7271. ((equal char ?b)
  7272. (setq text (read-string "Block entry: "))
  7273. (unless (and d1 d2 (not (equal d1 d2)))
  7274. (error "No block of days selected"))
  7275. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7276. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7277. ((equal char ?j)
  7278. (org-switch-to-buffer-other-window
  7279. (find-file-noselect org-agenda-diary-file))
  7280. (require 'org-datetree)
  7281. (org-datetree-find-date-create d1)
  7282. (org-reveal t))
  7283. (t (error "Invalid selection character `%c'" char)))))
  7284. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7285. "Where in `org-agenda-diary-file' should new entries be added?
  7286. Valid values:
  7287. date-tree in the date tree, as child of the date
  7288. top-level as top-level entries at the end of the file."
  7289. :group 'org-agenda
  7290. :type '(choice
  7291. (const :tag "in a date tree" date-tree)
  7292. (const :tag "as top level at end of file" top-level)))
  7293. (defcustom org-agenda-insert-diary-extract-time nil
  7294. "Non-nil means extract any time specification from the diary entry."
  7295. :group 'org-agenda
  7296. :type 'boolean)
  7297. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7298. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7299. If TEXT is not empty, it will become the headline of the new entry, and
  7300. the resulting entry will not be shown. When TEXT is empty, switch to
  7301. `org-agenda-diary-file' and let the user finish the entry there."
  7302. (let ((cw (current-window-configuration)))
  7303. (org-switch-to-buffer-other-window
  7304. (find-file-noselect org-agenda-diary-file))
  7305. (widen)
  7306. (goto-char (point-min))
  7307. (cond
  7308. ((eq type 'anniversary)
  7309. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7310. (progn
  7311. (or (org-on-heading-p t)
  7312. (progn
  7313. (outline-next-heading)
  7314. (insert "* Anniversaries\n\n")
  7315. (beginning-of-line -1)))))
  7316. (outline-next-heading)
  7317. (org-back-over-empty-lines)
  7318. (backward-char 1)
  7319. (insert "\n")
  7320. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7321. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7322. ((eq type 'day)
  7323. (let ((org-prefix-has-time t)
  7324. (org-agenda-time-leading-zero t)
  7325. fmt time time2)
  7326. (if org-agenda-insert-diary-extract-time
  7327. ;; Use org-format-agenda-item to parse text for a time-range and
  7328. ;; remove it. FIXME: This is a hack, we should refactor
  7329. ;; that function to make time extraction available separately
  7330. (setq fmt (org-format-agenda-item nil text nil nil t)
  7331. time (get-text-property 0 'time fmt)
  7332. time2 (if (> (length time) 0)
  7333. ;; split-string removes trailing ...... if
  7334. ;; no end time given. First space
  7335. ;; separates time from date.
  7336. (concat " " (car (split-string time "\\.")))
  7337. nil)
  7338. text (get-text-property 0 'txt fmt)))
  7339. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7340. (org-agenda-insert-diary-as-top-level text)
  7341. (require 'org-datetree)
  7342. (org-datetree-find-date-create d1)
  7343. (org-agenda-insert-diary-make-new-entry text))
  7344. (org-insert-time-stamp (org-time-from-absolute
  7345. (calendar-absolute-from-gregorian d1))
  7346. nil nil nil nil time2))
  7347. (end-of-line 0))
  7348. ((eq type 'block)
  7349. (if (> (calendar-absolute-from-gregorian d1)
  7350. (calendar-absolute-from-gregorian d2))
  7351. (setq d1 (prog1 d2 (setq d2 d1))))
  7352. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7353. (org-agenda-insert-diary-as-top-level text)
  7354. (require 'org-datetree)
  7355. (org-datetree-find-date-create d1)
  7356. (org-agenda-insert-diary-make-new-entry text))
  7357. (org-insert-time-stamp (org-time-from-absolute
  7358. (calendar-absolute-from-gregorian d1)))
  7359. (insert "--")
  7360. (org-insert-time-stamp (org-time-from-absolute
  7361. (calendar-absolute-from-gregorian d2)))
  7362. (end-of-line 0)))
  7363. (if (string-match "\\S-" text)
  7364. (progn
  7365. (set-window-configuration cw)
  7366. (message "%s entry added to %s"
  7367. (capitalize (symbol-name type))
  7368. (abbreviate-file-name org-agenda-diary-file)))
  7369. (org-reveal t)
  7370. (message "Please finish entry here"))))
  7371. (defun org-agenda-insert-diary-as-top-level (text)
  7372. "Make new entry as a top-level entry at the end of the file.
  7373. Add TEXT as headline, and position the cursor in the second line so that
  7374. a timestamp can be added there."
  7375. (widen)
  7376. (goto-char (point-max))
  7377. (or (bolp) (insert "\n"))
  7378. (insert "* " text "\n")
  7379. (if org-adapt-indentation (org-indent-to-column 2)))
  7380. (defun org-agenda-insert-diary-make-new-entry (text)
  7381. "Make new entry as last child of current entry.
  7382. Add TEXT as headline, and position the cursor in the second line so that
  7383. a timestamp can be added there."
  7384. (let ((org-show-following-heading t)
  7385. (org-show-siblings t)
  7386. (org-show-hierarchy-above t)
  7387. (org-show-entry-below t)
  7388. col)
  7389. (outline-next-heading)
  7390. (org-back-over-empty-lines)
  7391. (or (looking-at "[ \t]*$")
  7392. (progn (insert "\n") (backward-char 1)))
  7393. (org-insert-heading nil t)
  7394. (org-do-demote)
  7395. (setq col (current-column))
  7396. (insert text "\n")
  7397. (if org-adapt-indentation (org-indent-to-column col))
  7398. (let ((org-show-following-heading t)
  7399. (org-show-siblings t)
  7400. (org-show-hierarchy-above t)
  7401. (org-show-entry-below t))
  7402. (org-show-context))))
  7403. (defun org-agenda-diary-entry ()
  7404. "Make a diary entry, like the `i' command from the calendar.
  7405. All the standard commands work: block, weekly etc.
  7406. When `org-agenda-diary-file' points to a file,
  7407. `org-agenda-diary-entry-in-org-file' is called instead to create
  7408. entries in that Org-mode file."
  7409. (interactive)
  7410. (org-agenda-check-type t 'agenda 'timeline)
  7411. (if (not (eq org-agenda-diary-file 'diary-file))
  7412. (org-agenda-diary-entry-in-org-file)
  7413. (require 'diary-lib)
  7414. (let* ((char (progn
  7415. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7416. (read-char-exclusive)))
  7417. (cmd (cdr (assoc char
  7418. '((?d . insert-diary-entry)
  7419. (?w . insert-weekly-diary-entry)
  7420. (?m . insert-monthly-diary-entry)
  7421. (?y . insert-yearly-diary-entry)
  7422. (?a . insert-anniversary-diary-entry)
  7423. (?b . insert-block-diary-entry)
  7424. (?c . insert-cyclic-diary-entry)))))
  7425. (oldf (symbol-function 'calendar-cursor-to-date))
  7426. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7427. (point (point))
  7428. (mark (or (mark t) (point))))
  7429. (unless cmd
  7430. (error "No command associated with <%c>" char))
  7431. (unless (and (get-text-property point 'day)
  7432. (or (not (equal ?b char))
  7433. (get-text-property mark 'day)))
  7434. (error "Don't know which date to use for diary entry"))
  7435. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7436. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7437. (let ((calendar-mark-ring
  7438. (list (calendar-gregorian-from-absolute
  7439. (or (get-text-property mark 'day)
  7440. (get-text-property point 'day))))))
  7441. (unwind-protect
  7442. (progn
  7443. (fset 'calendar-cursor-to-date
  7444. (lambda (&optional error dummy)
  7445. (calendar-gregorian-from-absolute
  7446. (get-text-property point 'day))))
  7447. (call-interactively cmd))
  7448. (fset 'calendar-cursor-to-date oldf))))))
  7449. (defun org-agenda-execute-calendar-command (cmd)
  7450. "Execute a calendar command from the agenda, with the date associated to
  7451. the cursor position."
  7452. (org-agenda-check-type t 'agenda 'timeline)
  7453. (require 'diary-lib)
  7454. (unless (get-text-property (point) 'day)
  7455. (error "Don't know which date to use for calendar command"))
  7456. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7457. (point (point))
  7458. (date (calendar-gregorian-from-absolute
  7459. (get-text-property point 'day)))
  7460. ;; the following 2 vars are needed in the calendar
  7461. (displayed-month (car date))
  7462. (displayed-year (nth 2 date)))
  7463. (unwind-protect
  7464. (progn
  7465. (fset 'calendar-cursor-to-date
  7466. (lambda (&optional error dummy)
  7467. (calendar-gregorian-from-absolute
  7468. (get-text-property point 'day))))
  7469. (call-interactively cmd))
  7470. (fset 'calendar-cursor-to-date oldf))))
  7471. (defun org-agenda-phases-of-moon ()
  7472. "Display the phases of the moon for the 3 months around the cursor date."
  7473. (interactive)
  7474. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7475. (defun org-agenda-holidays ()
  7476. "Display the holidays for the 3 months around the cursor date."
  7477. (interactive)
  7478. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7479. (defvar calendar-longitude)
  7480. (defvar calendar-latitude)
  7481. (defvar calendar-location-name)
  7482. (defun org-agenda-sunrise-sunset (arg)
  7483. "Display sunrise and sunset for the cursor date.
  7484. Latitude and longitude can be specified with the variables
  7485. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7486. argument, latitude and longitude will be prompted for."
  7487. (interactive "P")
  7488. (require 'solar)
  7489. (let ((calendar-longitude (if arg nil calendar-longitude))
  7490. (calendar-latitude (if arg nil calendar-latitude))
  7491. (calendar-location-name
  7492. (if arg "the given coordinates" calendar-location-name)))
  7493. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7494. (defun org-agenda-goto-calendar ()
  7495. "Open the Emacs calendar with the date at the cursor."
  7496. (interactive)
  7497. (org-agenda-check-type t 'agenda 'timeline)
  7498. (let* ((day (or (get-text-property (point) 'day)
  7499. (error "Don't know which date to open in calendar")))
  7500. (date (calendar-gregorian-from-absolute day))
  7501. (calendar-move-hook nil)
  7502. (calendar-view-holidays-initially-flag nil)
  7503. (calendar-view-diary-initially-flag nil))
  7504. (calendar)
  7505. (calendar-goto-date date)))
  7506. ;;;###autoload
  7507. (defun org-calendar-goto-agenda ()
  7508. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7509. This is a command that has to be installed in `calendar-mode-map'."
  7510. (interactive)
  7511. (org-agenda-list nil (calendar-absolute-from-gregorian
  7512. (calendar-cursor-to-date))
  7513. nil))
  7514. (defun org-agenda-convert-date ()
  7515. (interactive)
  7516. (org-agenda-check-type t 'agenda 'timeline)
  7517. (let ((day (get-text-property (point) 'day))
  7518. date s)
  7519. (unless day
  7520. (error "Don't know which date to convert"))
  7521. (setq date (calendar-gregorian-from-absolute day))
  7522. (setq s (concat
  7523. "Gregorian: " (calendar-date-string date) "\n"
  7524. "ISO: " (calendar-iso-date-string date) "\n"
  7525. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7526. "Julian: " (calendar-julian-date-string date) "\n"
  7527. "Astron. JD: " (calendar-astro-date-string date)
  7528. " (Julian date number at noon UTC)\n"
  7529. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7530. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7531. "French: " (calendar-french-date-string date) "\n"
  7532. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7533. "Mayan: " (calendar-mayan-date-string date) "\n"
  7534. "Coptic: " (calendar-coptic-date-string date) "\n"
  7535. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7536. "Persian: " (calendar-persian-date-string date) "\n"
  7537. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7538. (with-output-to-temp-buffer "*Dates*"
  7539. (princ s))
  7540. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7541. ;;; Bulk commands
  7542. (defvar org-agenda-bulk-marked-entries nil
  7543. "List of markers that refer to marked entries in the agenda.")
  7544. (defun org-agenda-bulk-marked-p ()
  7545. (eq (get-char-property (point-at-bol) 'type)
  7546. 'org-marked-entry-overlay))
  7547. (defun org-agenda-bulk-mark (&optional arg)
  7548. "Mark the entry at point for future bulk action."
  7549. (interactive "p")
  7550. (dotimes (i (max arg 1))
  7551. (unless (org-get-at-bol 'org-agenda-diary-link)
  7552. (let* ((m (org-get-at-bol 'org-hd-marker))
  7553. ov)
  7554. (unless (org-agenda-bulk-marked-p)
  7555. (unless m (error "Nothing to mark at point"))
  7556. (push m org-agenda-bulk-marked-entries)
  7557. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7558. (org-overlay-display ov "> "
  7559. (org-get-todo-face "TODO")
  7560. 'evaporate)
  7561. (overlay-put ov 'type 'org-marked-entry-overlay))
  7562. (beginning-of-line 2)
  7563. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7564. (beginning-of-line 2))
  7565. (message "%d entries marked for bulk action"
  7566. (length org-agenda-bulk-marked-entries))))))
  7567. (defun org-agenda-bulk-mark-regexp (regexp)
  7568. "Mark entries match REGEXP."
  7569. (interactive "sMark entries matching regexp: ")
  7570. (let (entries-marked)
  7571. (save-excursion
  7572. (goto-char (point-min))
  7573. (goto-char (next-single-property-change (point) 'txt))
  7574. (while (re-search-forward regexp nil t)
  7575. (when (string-match regexp (get-text-property (point) 'txt))
  7576. (setq entries-marked (+ entries-marked 1))
  7577. (call-interactively 'org-agenda-bulk-mark))))
  7578. (if (not entries-marked)
  7579. (message "No entry matching this regexp."))))
  7580. (defun org-agenda-bulk-unmark ()
  7581. "Unmark the entry at point for future bulk action."
  7582. (interactive)
  7583. (when (org-agenda-bulk-marked-p)
  7584. (org-agenda-bulk-remove-overlays
  7585. (point-at-bol) (+ 2 (point-at-bol)))
  7586. (setq org-agenda-bulk-marked-entries
  7587. (delete (org-get-at-bol 'org-hd-marker)
  7588. org-agenda-bulk-marked-entries)))
  7589. (beginning-of-line 2)
  7590. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7591. (beginning-of-line 2))
  7592. (message "%d entries marked for bulk action"
  7593. (length org-agenda-bulk-marked-entries)))
  7594. (defun org-agenda-bulk-toggle ()
  7595. "Toggle marking the entry at point for bulk action."
  7596. (interactive)
  7597. (if (org-agenda-bulk-marked-p)
  7598. (org-agenda-bulk-unmark)
  7599. (org-agenda-bulk-mark)))
  7600. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7601. "Remove the mark overlays between BEG and END in the agenda buffer.
  7602. BEG and END default to the buffer limits.
  7603. This only removes the overlays, it does not remove the markers
  7604. from the list in `org-agenda-bulk-marked-entries'."
  7605. (interactive)
  7606. (mapc (lambda (ov)
  7607. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7608. (delete-overlay ov)))
  7609. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7610. (defun org-agenda-bulk-remove-all-marks ()
  7611. "Remove all marks in the agenda buffer.
  7612. This will remove the markers, and the overlays."
  7613. (interactive)
  7614. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7615. (setq org-agenda-bulk-marked-entries nil)
  7616. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7617. (defun org-agenda-bulk-action (&optional arg)
  7618. "Execute an remote-editing action on all marked entries.
  7619. The prefix arg is passed through to the command if possible."
  7620. (interactive "P")
  7621. ;; Make sure we have markers, and only valid ones
  7622. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7623. (mapc
  7624. (lambda (m)
  7625. (unless (and (markerp m)
  7626. (marker-buffer m)
  7627. (buffer-live-p (marker-buffer m))
  7628. (marker-position m))
  7629. (error "Marker %s for bulk command is invalid" m)))
  7630. org-agenda-bulk-marked-entries)
  7631. ;; Prompt for the bulk command
  7632. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7633. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7634. (when org-agenda-bulk-custom-functions
  7635. (concat " Custom: ["
  7636. (mapconcat (lambda(f) (char-to-string (car f)))
  7637. org-agenda-bulk-custom-functions "")
  7638. "]"))))
  7639. (let* ((action (read-char-exclusive))
  7640. (org-log-refile (if org-log-refile 'time nil))
  7641. (entries (reverse org-agenda-bulk-marked-entries))
  7642. redo-at-end
  7643. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7644. (cond
  7645. ((equal action ?$)
  7646. (setq cmd '(org-agenda-archive)))
  7647. ((equal action ?A)
  7648. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7649. ((member action '(?r ?w))
  7650. (setq rfloc (org-refile-get-location
  7651. "Refile to"
  7652. (marker-buffer (car org-agenda-bulk-marked-entries))
  7653. org-refile-allow-creating-parent-nodes))
  7654. (if (nth 3 rfloc)
  7655. (setcar (nthcdr 3 rfloc)
  7656. (move-marker (make-marker) (nth 3 rfloc)
  7657. (or (get-file-buffer (nth 1 rfloc))
  7658. (find-buffer-visiting (nth 1 rfloc))
  7659. (error "This should not happen")))))
  7660. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7661. redo-at-end t))
  7662. ((equal action ?t)
  7663. (setq state (org-icompleting-read
  7664. "Todo state: "
  7665. (with-current-buffer (marker-buffer (car entries))
  7666. (mapcar 'list org-todo-keywords-1))))
  7667. (setq cmd `(let ((org-inhibit-blocking t)
  7668. (org-inhibit-logging 'note))
  7669. (org-agenda-todo ,state))))
  7670. ((memq action '(?- ?+))
  7671. (setq tag (org-icompleting-read
  7672. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7673. (with-current-buffer (marker-buffer (car entries))
  7674. (delq nil
  7675. (mapcar (lambda (x)
  7676. (if (stringp (car x)) x)) org-tag-alist)))))
  7677. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7678. ((memq action '(?s ?d))
  7679. (let* ((date (unless arg
  7680. (org-read-date
  7681. nil nil nil
  7682. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7683. (ans (if arg nil org-read-date-final-answer))
  7684. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7685. (setq cmd `(let* ((bound (fboundp 'read-string))
  7686. (old (and bound (symbol-function 'read-string))))
  7687. (unwind-protect
  7688. (progn
  7689. (fset 'read-string (lambda (&rest ignore) ,ans))
  7690. (eval '(,c1 arg)))
  7691. (if bound
  7692. (fset 'read-string old)
  7693. (fmakunbound 'read-string)))))))
  7694. ((equal action ?S)
  7695. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7696. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7697. (let ((days (read-number
  7698. (format "Scatter tasks across how many %sdays: "
  7699. (if arg "week" "")) 7)))
  7700. (setq cmd
  7701. `(let ((distance (1+ (random ,days))))
  7702. (if arg
  7703. (let ((dist distance)
  7704. (day-of-week
  7705. (calendar-day-of-week
  7706. (calendar-gregorian-from-absolute (org-today)))))
  7707. (dotimes (i (1+ dist))
  7708. (while (member day-of-week org-agenda-weekend-days)
  7709. (incf distance)
  7710. (incf day-of-week)
  7711. (if (= day-of-week 7)
  7712. (setq day-of-week 0)))
  7713. (incf day-of-week)
  7714. (if (= day-of-week 7)
  7715. (setq day-of-week 0)))))
  7716. ;; silently fail when try to replan a sexp entry
  7717. (condition-case nil
  7718. (let* ((date (calendar-gregorian-from-absolute
  7719. (+ (org-today) distance)))
  7720. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7721. (nth 2 date))))
  7722. (org-agenda-schedule nil time))
  7723. (error nil)))))))
  7724. ((assoc action org-agenda-bulk-custom-functions)
  7725. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7726. redo-at-end t))
  7727. ((equal action ?f)
  7728. (setq cmd (list (intern
  7729. (org-icompleting-read "Function: "
  7730. obarray 'fboundp t nil nil)))))
  7731. (t (error "Invalid bulk action")))
  7732. ;; Sort the markers, to make sure that parents are handled before children
  7733. (setq entries (sort entries
  7734. (lambda (a b)
  7735. (cond
  7736. ((equal (marker-buffer a) (marker-buffer b))
  7737. (< (marker-position a) (marker-position b)))
  7738. (t
  7739. (string< (buffer-name (marker-buffer a))
  7740. (buffer-name (marker-buffer b))))))))
  7741. ;; Now loop over all markers and apply cmd
  7742. (while (setq e (pop entries))
  7743. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7744. (if (not pos)
  7745. (progn (message "Skipping removed entry at %s" e)
  7746. (setq cntskip (1+ cntskip)))
  7747. (goto-char pos)
  7748. (eval cmd)
  7749. (setq org-agenda-bulk-marked-entries
  7750. (delete e org-agenda-bulk-marked-entries))
  7751. (setq cnt (1+ cnt))))
  7752. (setq org-agenda-bulk-marked-entries nil)
  7753. (org-agenda-bulk-remove-all-marks)
  7754. (when redo-at-end (org-agenda-redo))
  7755. (message "Acted on %d entries%s"
  7756. cnt
  7757. (if (= cntskip 0)
  7758. ""
  7759. (format ", skipped %d (disappeared before their turn)"
  7760. cntskip)))))
  7761. ;;; Flagging notes
  7762. (defun org-agenda-show-the-flagging-note ()
  7763. "Display the flagging note in the other window.
  7764. When called a second time in direct sequence, offer to remove the FLAGGING
  7765. tag and (if present) the flagging note."
  7766. (interactive)
  7767. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7768. (win (selected-window))
  7769. note heading newhead)
  7770. (unless hdmarker
  7771. (error "No linked entry at point"))
  7772. (if (and (eq this-command last-command)
  7773. (y-or-n-p "Unflag and remove any flagging note? "))
  7774. (progn
  7775. (org-agenda-remove-flag hdmarker)
  7776. (let ((win (get-buffer-window "*Flagging Note*")))
  7777. (and win (delete-window win)))
  7778. (message "Entry unflaged"))
  7779. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7780. (unless note
  7781. (error "No flagging note"))
  7782. (org-kill-new note)
  7783. (org-switch-to-buffer-other-window "*Flagging Note*")
  7784. (erase-buffer)
  7785. (insert note)
  7786. (goto-char (point-min))
  7787. (while (re-search-forward "\\\\n" nil t)
  7788. (replace-match "\n" t t))
  7789. (goto-char (point-min))
  7790. (select-window win)
  7791. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7792. (defun org-agenda-remove-flag (marker)
  7793. "Remove the FLAGGED tag and any flagging note in the entry."
  7794. (let (newhead)
  7795. (org-with-point-at marker
  7796. (org-toggle-tag "FLAGGED" 'off)
  7797. (org-entry-delete nil "THEFLAGGINGNOTE")
  7798. (setq newhead (org-get-heading)))
  7799. (org-agenda-change-all-lines newhead marker)
  7800. (message "Entry unflaged")))
  7801. (defun org-agenda-get-any-marker (&optional pos)
  7802. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7803. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7804. ;;; Appointment reminders
  7805. (defvar appt-time-msg-list)
  7806. ;;;###autoload
  7807. (defun org-agenda-to-appt (&optional refresh filter)
  7808. "Activate appointments found in `org-agenda-files'.
  7809. With a \\[universal-argument] prefix, refresh the list of
  7810. appointments.
  7811. If FILTER is t, interactively prompt the user for a regular
  7812. expression, and filter out entries that don't match it.
  7813. If FILTER is a string, use this string as a regular expression
  7814. for filtering entries out.
  7815. FILTER can also be an alist with the car of each cell being
  7816. either 'headline or 'category. For example:
  7817. '((headline \"IMPORTANT\")
  7818. (category \"Work\"))
  7819. will only add headlines containing IMPORTANT or headlines
  7820. belonging to the \"Work\" category."
  7821. (interactive "P")
  7822. (if refresh (setq appt-time-msg-list nil))
  7823. (if (eq filter t)
  7824. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7825. (let* ((cnt 0) ; count added events
  7826. (org-agenda-new-buffers nil)
  7827. (org-deadline-warning-days 0)
  7828. ;; Do not use `org-today' here because appt only takes
  7829. ;; time and without date as argument, so it may pass wrong
  7830. ;; information otherwise
  7831. (today (org-date-to-gregorian
  7832. (time-to-days (current-time))))
  7833. (org-agenda-restrict nil)
  7834. (files (org-agenda-files 'unrestricted)) entries file)
  7835. ;; Get all entries which may contain an appt
  7836. (org-prepare-agenda-buffers files)
  7837. (while (setq file (pop files))
  7838. (setq entries
  7839. (append entries
  7840. (org-agenda-get-day-entries
  7841. file today :timestamp :scheduled :deadline))))
  7842. (setq entries (delq nil entries))
  7843. ;; Map thru entries and find if we should filter them out
  7844. (mapc
  7845. (lambda(x)
  7846. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7847. (cat (get-text-property 1 'org-category x))
  7848. (tod (get-text-property 1 'time-of-day x))
  7849. (ok (or (null filter)
  7850. (and (stringp filter) (string-match filter evt))
  7851. (and (listp filter)
  7852. (or (string-match
  7853. (cadr (assoc 'category filter)) cat)
  7854. (string-match
  7855. (cadr (assoc 'headline filter)) evt))))))
  7856. ;; FIXME: Shall we remove text-properties for the appt text?
  7857. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7858. (when (and ok tod)
  7859. (setq tod (concat "00" (number-to-string tod))
  7860. tod (when (string-match
  7861. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7862. (concat (match-string 1 tod) ":"
  7863. (match-string 2 tod))))
  7864. (appt-add tod evt)
  7865. (setq cnt (1+ cnt))))) entries)
  7866. (org-release-buffers org-agenda-new-buffers)
  7867. (if (eq cnt 0)
  7868. (message "No event to add")
  7869. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7870. (defun org-agenda-todayp (date)
  7871. "Does DATE mean today, when considering `org-extend-today-until'?"
  7872. (let ((today (org-today))
  7873. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7874. date)))
  7875. (eq date today)))
  7876. (defun org-agenda-todo-yesterday (&optional arg)
  7877. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  7878. (interactive "P")
  7879. (let* ((hour (third (decode-time
  7880. (org-current-time))))
  7881. (org-extend-today-until (1+ hour)))
  7882. (org-agenda-todo arg)))
  7883. (provide 'org-agenda)
  7884. ;;; org-agenda.el ends here