org-agenda.el 323 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462
  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. (declare-function org-duration-string-to-minutes "org-clock" (s))
  74. (declare-function org-hh:mm-string-to-minutes "org-clock" (s))
  75. (declare-function org-minutes-to-hh:mm-string "org-clock" (m))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task) ; defined in org-clock.el
  78. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  79. (defvar org-habit-show-habits)
  80. (defvar org-habit-show-habits-only-for-today)
  81. ;; Defined somewhere in this file, but used before definition.
  82. (defvar org-agenda-buffer-name)
  83. (defvar org-agenda-overriding-header)
  84. (defvar org-agenda-title-append nil)
  85. (defvar entry)
  86. (defvar date)
  87. (defvar org-agenda-undo-list)
  88. (defvar org-agenda-pending-undo-list)
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defcustom org-agenda-confirm-kill 1
  91. "When set, remote killing from the agenda buffer needs confirmation.
  92. When t, a confirmation is always needed. When a number N, confirmation is
  93. only needed when the text to be killed contains more than N non-white lines."
  94. :group 'org-agenda
  95. :type '(choice
  96. (const :tag "Never" nil)
  97. (const :tag "Always" t)
  98. (integer :tag "When more than N lines")))
  99. (defcustom org-agenda-compact-blocks nil
  100. "Non-nil means make the block agenda more compact.
  101. This is done globally by leaving out lines like the agenda span
  102. name and week number or the separator lines."
  103. :group 'org-agenda
  104. :type 'boolean)
  105. (defcustom org-agenda-block-separator ?=
  106. "The separator between blocks in the agenda.
  107. If this is a string, it will be used as the separator, with a newline added.
  108. If it is a character, it will be repeated to fill the window width.
  109. If nil the separator is disabled. In `org-agenda-custom-commands' this
  110. addresses the separator between the current and the previous block."
  111. :group 'org-agenda
  112. :type '(choice
  113. (const :tag "Disabled" nil)
  114. (character)
  115. (string)))
  116. (defgroup org-agenda-export nil
  117. "Options concerning exporting agenda views in Org-mode."
  118. :tag "Org Agenda Export"
  119. :group 'org-agenda)
  120. (defcustom org-agenda-with-colors t
  121. "Non-nil means use colors in agenda views."
  122. :group 'org-agenda-export
  123. :type 'boolean)
  124. (defcustom org-agenda-exporter-settings nil
  125. "Alist of variable/value pairs that should be active during agenda export.
  126. This is a good place to set options for ps-print and for htmlize.
  127. Note that the way this is implemented, the values will be evaluated
  128. before assigned to the variables. So make sure to quote values you do
  129. *not* want evaluated, for example
  130. (setq org-agenda-exporter-settings
  131. '((ps-print-color-p 'black-white)))"
  132. :group 'org-agenda-export
  133. :type '(repeat
  134. (list
  135. (variable)
  136. (sexp :tag "Value"))))
  137. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  138. "Hook run in temporary buffer before writing it to an export file.
  139. A useful function is `org-agenda-add-entry-text'."
  140. :group 'org-agenda-export
  141. :type 'hook
  142. :options '(org-agenda-add-entry-text))
  143. (defcustom org-agenda-add-entry-text-maxlines 0
  144. "Maximum number of entry text lines to be added to agenda.
  145. This is only relevant when `org-agenda-add-entry-text' is part of
  146. `org-agenda-before-write-hook', which it is by default.
  147. When this is 0, nothing will happen. When it is greater than 0, it
  148. specifies the maximum number of lines that will be added for each entry
  149. that is listed in the agenda view.
  150. Note that this variable is not used during display, only when exporting
  151. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  152. and `org-agenda-entry-text-maxlines'."
  153. :group 'org-agenda
  154. :type 'integer)
  155. (defcustom org-agenda-add-entry-text-descriptive-links t
  156. "Non-nil means export org-links as descriptive links in agenda added text.
  157. This variable applies to the text added to the agenda when
  158. `org-agenda-add-entry-text-maxlines' is larger than 0.
  159. When this variable nil, the URL will (also) be shown."
  160. :group 'org-agenda
  161. :type 'boolean)
  162. (defcustom org-agenda-export-html-style ""
  163. "The style specification for exported HTML Agenda files.
  164. If this variable contains a string, it will replace the default <style>
  165. section as produced by `htmlize'.
  166. Since there are different ways of setting style information, this variable
  167. needs to contain the full HTML structure to provide a style, including the
  168. surrounding HTML tags. The style specifications should include definitions
  169. the fonts used by the agenda, here is an example:
  170. <style type=\"text/css\">
  171. p { font-weight: normal; color: gray; }
  172. .org-agenda-structure {
  173. font-size: 110%;
  174. color: #003399;
  175. font-weight: 600;
  176. }
  177. .org-todo {
  178. color: #cc6666;
  179. font-weight: bold;
  180. }
  181. .org-agenda-done {
  182. color: #339933;
  183. }
  184. .org-done {
  185. color: #339933;
  186. }
  187. .title { text-align: center; }
  188. .todo, .deadline { color: red; }
  189. .done { color: green; }
  190. </style>
  191. or, if you want to keep the style in a file,
  192. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  193. As the value of this option simply gets inserted into the HTML <head> header,
  194. you can \"misuse\" it to also add other text to the header. However,
  195. <style>...</style> is required, if not present the variable will be ignored."
  196. :group 'org-agenda-export
  197. :group 'org-export-html
  198. :type 'string)
  199. (defcustom org-agenda-persistent-filter nil
  200. "When set, keep filters from one agenda view to the next."
  201. :group 'org-agenda
  202. :type 'boolean)
  203. (defgroup org-agenda-custom-commands nil
  204. "Options concerning agenda views in Org-mode."
  205. :tag "Org Agenda Custom Commands"
  206. :group 'org-agenda)
  207. (defconst org-sorting-choice
  208. '(choice
  209. (const time-up) (const time-down)
  210. (const category-keep) (const category-up) (const category-down)
  211. (const tag-down) (const tag-up)
  212. (const priority-up) (const priority-down)
  213. (const todo-state-up) (const todo-state-down)
  214. (const effort-up) (const effort-down)
  215. (const habit-up) (const habit-down)
  216. (const alpha-up) (const alpha-down)
  217. (const user-defined-up) (const user-defined-down))
  218. "Sorting choices.")
  219. (defconst org-agenda-custom-commands-local-options
  220. `(repeat :tag "Local settings for this command. Remember to quote values"
  221. (choice :tag "Setting"
  222. (list :tag "Heading for this block"
  223. (const org-agenda-overriding-header)
  224. (string :tag "Headline"))
  225. (list :tag "Files to be searched"
  226. (const org-agenda-files)
  227. (list
  228. (const :format "" quote)
  229. (repeat (file))))
  230. (list :tag "Sorting strategy"
  231. (const org-agenda-sorting-strategy)
  232. (list
  233. (const :format "" quote)
  234. (repeat
  235. ,org-sorting-choice)))
  236. (list :tag "Prefix format"
  237. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  238. (string))
  239. (list :tag "Number of days in agenda"
  240. (const org-agenda-span)
  241. (choice (const :tag "Day" 'day)
  242. (const :tag "Week" 'week)
  243. (const :tag "Month" 'month)
  244. (const :tag "Year" 'year)
  245. (integer :tag "Custom")))
  246. (list :tag "Fixed starting date"
  247. (const org-agenda-start-day)
  248. (string :value "2007-11-01"))
  249. (list :tag "Start on day of week"
  250. (const org-agenda-start-on-weekday)
  251. (choice :value 1
  252. (const :tag "Today" nil)
  253. (integer :tag "Weekday No.")))
  254. (list :tag "Include data from diary"
  255. (const org-agenda-include-diary)
  256. (boolean))
  257. (list :tag "Deadline Warning days"
  258. (const org-deadline-warning-days)
  259. (integer :value 1))
  260. (list :tag "Tags filter preset"
  261. (const org-agenda-filter-preset)
  262. (list
  263. (const :format "" quote)
  264. (repeat
  265. (string :tag "+tag or -tag"))))
  266. (list :tag "Set daily/weekly entry types"
  267. (const org-agenda-entry-types)
  268. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  269. (const :deadline)
  270. (const :scheduled)
  271. (const :timestamp)
  272. (const :sexp)))
  273. (list :tag "Standard skipping condition"
  274. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  275. (const org-agenda-skip-function)
  276. (list
  277. (const :format "" quote)
  278. (list
  279. (choice
  280. :tag "Skipping range"
  281. (const :tag "Skip entry" org-agenda-skip-entry-if)
  282. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  283. (repeat :inline t :tag "Conditions for skipping"
  284. (choice
  285. :tag "Condition type"
  286. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  287. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  288. (list :tag "TODO state is" :inline t
  289. (const 'todo)
  290. (choice
  291. (const :tag "any not-done state" 'todo)
  292. (const :tag "any done state" 'done)
  293. (const :tag "any state" 'any)
  294. (list :tag "Keyword list"
  295. (const :format "" quote)
  296. (repeat (string :tag "Keyword")))))
  297. (list :tag "TODO state is not" :inline t
  298. (const 'nottodo)
  299. (choice
  300. (const :tag "any not-done state" 'todo)
  301. (const :tag "any done state" 'done)
  302. (const :tag "any state" 'any)
  303. (list :tag "Keyword list"
  304. (const :format "" quote)
  305. (repeat (string :tag "Keyword")))))
  306. (const :tag "scheduled" 'scheduled)
  307. (const :tag "not scheduled" 'notscheduled)
  308. (const :tag "deadline" 'deadline)
  309. (const :tag "no deadline" 'notdeadline)
  310. (const :tag "timestamp" 'timestamp)
  311. (const :tag "no timestamp" 'nottimestamp))))))
  312. (list :tag "Non-standard skipping condition"
  313. :value (org-agenda-skip-function)
  314. (const org-agenda-skip-function)
  315. (sexp :tag "Function or form (quoted!)"))
  316. (list :tag "Any variable"
  317. (variable :tag "Variable")
  318. (sexp :tag "Value (sexp)"))))
  319. "Selection of examples for agenda command settings.
  320. This will be spliced into the custom type of
  321. `org-agenda-custom-commands'.")
  322. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  323. ((agenda "") (alltodo))))
  324. "Custom commands for the agenda.
  325. These commands will be offered on the splash screen displayed by the
  326. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  327. (key desc type match settings files)
  328. key The key (one or more characters as a string) to be associated
  329. with the command.
  330. desc A description of the command, when omitted or nil, a default
  331. description is built using MATCH.
  332. type The command type, any of the following symbols:
  333. agenda The daily/weekly agenda.
  334. todo Entries with a specific TODO keyword, in all agenda files.
  335. search Entries containing search words entry or headline.
  336. tags Tags/Property/TODO match in all agenda files.
  337. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  338. todo-tree Sparse tree of specific TODO keyword in *current* file.
  339. tags-tree Sparse tree with all tags matches in *current* file.
  340. occur-tree Occur sparse tree for *current* file.
  341. ... A user-defined function.
  342. match What to search for:
  343. - a single keyword for TODO keyword searches
  344. - a tags match expression for tags searches
  345. - a word search expression for text searches.
  346. - a regular expression for occur searches
  347. For all other commands, this should be the empty string.
  348. settings A list of option settings, similar to that in a let form, so like
  349. this: ((opt1 val1) (opt2 val2) ...). The values will be
  350. evaluated at the moment of execution, so quote them when needed.
  351. files A list of files file to write the produced agenda buffer to
  352. with the command `org-store-agenda-views'.
  353. If a file name ends in \".html\", an HTML version of the buffer
  354. is written out. If it ends in \".ps\", a postscript version is
  355. produced. Otherwise, only the plain text is written to the file.
  356. You can also define a set of commands, to create a composite agenda buffer.
  357. In this case, an entry looks like this:
  358. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  359. where
  360. desc A description string to be displayed in the dispatcher menu.
  361. cmd An agenda command, similar to the above. However, tree commands
  362. are no allowed, but instead you can get agenda and global todo list.
  363. So valid commands for a set are:
  364. (agenda \"\" settings)
  365. (alltodo \"\" settings)
  366. (stuck \"\" settings)
  367. (todo \"match\" settings files)
  368. (search \"match\" settings files)
  369. (tags \"match\" settings files)
  370. (tags-todo \"match\" settings files)
  371. Each command can carry a list of options, and another set of options can be
  372. given for the whole set of commands. Individual command options take
  373. precedence over the general options.
  374. When using several characters as key to a command, the first characters
  375. are prefix commands. For the dispatcher to display useful information, you
  376. should provide a description for the prefix, like
  377. (setq org-agenda-custom-commands
  378. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  379. (\"hl\" tags \"+HOME+Lisa\")
  380. (\"hp\" tags \"+HOME+Peter\")
  381. (\"hk\" tags \"+HOME+Kim\")))"
  382. :group 'org-agenda-custom-commands
  383. :type `(repeat
  384. (choice :value ("x" "Describe command here" tags "" nil)
  385. (list :tag "Single command"
  386. (string :tag "Access Key(s) ")
  387. (option (string :tag "Description"))
  388. (choice
  389. (const :tag "Agenda" agenda)
  390. (const :tag "TODO list" alltodo)
  391. (const :tag "Search words" search)
  392. (const :tag "Stuck projects" stuck)
  393. (const :tag "Tags/Property match (all agenda files)" tags)
  394. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  395. (const :tag "TODO keyword search (all agenda files)" todo)
  396. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  397. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  398. (const :tag "Occur tree (current buffer)" occur-tree)
  399. (sexp :tag "Other, user-defined function"))
  400. (string :tag "Match (only for some commands)")
  401. ,org-agenda-custom-commands-local-options
  402. (option (repeat :tag "Export" (file :tag "Export to"))))
  403. (list :tag "Command series, all agenda files"
  404. (string :tag "Access Key(s)")
  405. (string :tag "Description ")
  406. (repeat :tag "Component"
  407. (choice
  408. (list :tag "Agenda"
  409. (const :format "" agenda)
  410. (const :tag "" :format "" "")
  411. ,org-agenda-custom-commands-local-options)
  412. (list :tag "TODO list (all keywords)"
  413. (const :format "" alltodo)
  414. (const :tag "" :format "" "")
  415. ,org-agenda-custom-commands-local-options)
  416. (list :tag "Search words"
  417. (const :format "" search)
  418. (string :tag "Match")
  419. ,org-agenda-custom-commands-local-options)
  420. (list :tag "Stuck projects"
  421. (const :format "" stuck)
  422. (const :tag "" :format "" "")
  423. ,org-agenda-custom-commands-local-options)
  424. (list :tag "Tags search"
  425. (const :format "" tags)
  426. (string :tag "Match")
  427. ,org-agenda-custom-commands-local-options)
  428. (list :tag "Tags search, TODO entries only"
  429. (const :format "" tags-todo)
  430. (string :tag "Match")
  431. ,org-agenda-custom-commands-local-options)
  432. (list :tag "TODO keyword search"
  433. (const :format "" todo)
  434. (string :tag "Match")
  435. ,org-agenda-custom-commands-local-options)
  436. (list :tag "Other, user-defined function"
  437. (symbol :tag "function")
  438. (string :tag "Match")
  439. ,org-agenda-custom-commands-local-options)))
  440. (repeat :tag "Settings for entire command set"
  441. (list (variable :tag "Any variable")
  442. (sexp :tag "Value")))
  443. (option (repeat :tag "Export" (file :tag "Export to"))))
  444. (cons :tag "Prefix key documentation"
  445. (string :tag "Access Key(s)")
  446. (string :tag "Description ")))))
  447. (defcustom org-agenda-query-register ?o
  448. "The register holding the current query string.
  449. The purpose of this is that if you construct a query string interactively,
  450. you can then use it to define a custom command."
  451. :group 'org-agenda-custom-commands
  452. :type 'character)
  453. (defcustom org-stuck-projects
  454. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  455. "How to identify stuck projects.
  456. This is a list of four items:
  457. 1. A tags/todo/property matcher string that is used to identify a project.
  458. See the manual for a description of tag and property searches.
  459. The entire tree below a headline matched by this is considered one project.
  460. 2. A list of TODO keywords identifying non-stuck projects.
  461. If the project subtree contains any headline with one of these todo
  462. keywords, the project is considered to be not stuck. If you specify
  463. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  464. 3. A list of tags identifying non-stuck projects.
  465. If the project subtree contains any headline with one of these tags,
  466. the project is considered to be not stuck. If you specify \"*\" as
  467. a tag, any tag will mark the project unstuck. Note that this is about
  468. the explicit presence of a tag somewhere in the subtree, inherited
  469. tags to not count here. If inherited tags make a project not stuck,
  470. use \"-TAG\" in the tags part of the matcher under (1.) above.
  471. 4. An arbitrary regular expression matching non-stuck projects.
  472. If the project turns out to be not stuck, search continues also in the
  473. subtree to see if any of the subtasks have project status.
  474. See also the variable `org-tags-match-list-sublevels' which applies
  475. to projects matched by this search as well.
  476. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  477. or `C-c a #' to produce the list."
  478. :group 'org-agenda-custom-commands
  479. :type '(list
  480. (string :tag "Tags/TODO match to identify a project")
  481. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  482. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  483. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  484. (defcustom org-agenda-filter-effort-default-operator "<"
  485. "The default operator for effort estimate filtering.
  486. If you select an effort estimate limit without first pressing an operator,
  487. this one will be used."
  488. :group 'org-agenda-custom-commands
  489. :type '(choice (const :tag "less or equal" "<")
  490. (const :tag "greater or equal"">")
  491. (const :tag "equal" "=")))
  492. (defgroup org-agenda-skip nil
  493. "Options concerning skipping parts of agenda files."
  494. :tag "Org Agenda Skip"
  495. :group 'org-agenda)
  496. (defcustom org-agenda-skip-function-global nil
  497. "Function to be called at each match during agenda construction.
  498. If this function returns nil, the current match should not be skipped.
  499. If the function decided to skip an agenda match, is must return the
  500. buffer position from which the search should be continued.
  501. This may also be a Lisp form, which will be evaluated.
  502. This variable will be applied to every agenda match, including
  503. tags/property searches and TODO lists. So try to make the test function
  504. do its checking as efficiently as possible. To implement a skipping
  505. condition just for specific agenda commands, use the variable
  506. `org-agenda-skip-function' which can be set in the options section
  507. of custom agenda commands."
  508. :group 'org-agenda-skip
  509. :type 'sexp)
  510. (defgroup org-agenda-daily/weekly nil
  511. "Options concerning the daily/weekly agenda."
  512. :tag "Org Agenda Daily/Weekly"
  513. :group 'org-agenda)
  514. (defgroup org-agenda-todo-list nil
  515. "Options concerning the global todo list agenda view."
  516. :tag "Org Agenda Todo List"
  517. :group 'org-agenda)
  518. (defgroup org-agenda-match-view nil
  519. "Options concerning the general tags/property/todo match agenda view."
  520. :tag "Org Agenda Match View"
  521. :group 'org-agenda)
  522. (defgroup org-agenda-search-view nil
  523. "Options concerning the general tags/property/todo match agenda view."
  524. :tag "Org Agenda Match View"
  525. :group 'org-agenda)
  526. (defvar org-agenda-archives-mode nil
  527. "Non-nil means the agenda will include archived items.
  528. If this is the symbol `trees', trees in the selected agenda scope
  529. that are marked with the ARCHIVE tag will be included anyway. When this is
  530. t, also all archive files associated with the current selection of agenda
  531. files will be included.")
  532. (defcustom org-agenda-skip-comment-trees t
  533. "Non-nil means skip trees that start with the COMMENT keyword.
  534. When nil, these trees are also scanned by agenda commands."
  535. :group 'org-agenda-skip
  536. :type 'boolean)
  537. (defcustom org-agenda-todo-list-sublevels t
  538. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  539. When nil, the sublevels of a TODO entry are not checked, resulting in
  540. potentially much shorter TODO lists."
  541. :group 'org-agenda-skip
  542. :group 'org-agenda-todo-list
  543. :type 'boolean)
  544. (defcustom org-agenda-todo-ignore-with-date nil
  545. "Non-nil means don't show entries with a date in the global todo list.
  546. You can use this if you prefer to mark mere appointments with a TODO keyword,
  547. but don't want them to show up in the TODO list.
  548. When this is set, it also covers deadlines and scheduled items, the settings
  549. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  550. will be ignored.
  551. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type 'boolean)
  555. (defcustom org-agenda-todo-ignore-timestamp nil
  556. "Non-nil means don't show entries with a timestamp.
  557. This applies when creating the global todo list.
  558. Valid values are:
  559. past Don't show entries for today or in the past.
  560. future Don't show entries with a timestamp in the future.
  561. The idea behind this is that if it has a future
  562. timestamp, you don't want to think about it until the
  563. date.
  564. all Don't show any entries with a timestamp in the global todo list.
  565. The idea behind this is that by setting a timestamp, you
  566. have already \"taken care\" of this item.
  567. This variable can also have an integer as a value. If positive (N),
  568. todos with a timestamp N or more days in the future will be ignored. If
  569. negative (-N), todos with a timestamp N or more days in the past will be
  570. ignored. If 0, todos with a timestamp either today or in the future will
  571. be ignored. For example, a value of -1 will exclude todos with a
  572. timestamp in the past (yesterday or earlier), while a value of 7 will
  573. exclude todos with a timestamp a week or more in the future.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore future timestamp todos" future)
  581. (const :tag "Ignore past or present timestamp todos" past)
  582. (const :tag "Ignore all timestamp todos" all)
  583. (const :tag "Show timestamp todos" nil)
  584. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  585. (defcustom org-agenda-todo-ignore-scheduled nil
  586. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  587. This applies when creating the global todo list.
  588. Valid values are:
  589. past Don't show entries scheduled today or in the past.
  590. future Don't show entries scheduled in the future.
  591. The idea behind this is that by scheduling it, you don't want to
  592. think about it until the scheduled date.
  593. all Don't show any scheduled entries in the global todo list.
  594. The idea behind this is that by scheduling it, you have already
  595. \"taken care\" of this item.
  596. t Same as `all', for backward compatibility.
  597. This variable can also have an integer as a value. See
  598. `org-agenda-todo-ignore-timestamp' for more details.
  599. See also `org-agenda-todo-ignore-with-date'.
  600. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  601. to make his option also apply to the tags-todo list."
  602. :group 'org-agenda-skip
  603. :group 'org-agenda-todo-list
  604. :type '(choice
  605. (const :tag "Ignore future-scheduled todos" future)
  606. (const :tag "Ignore past- or present-scheduled todos" past)
  607. (const :tag "Ignore all scheduled todos" all)
  608. (const :tag "Ignore all scheduled todos (compatibility)" t)
  609. (const :tag "Show scheduled todos" nil)
  610. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  611. (defcustom org-agenda-todo-ignore-deadlines nil
  612. "Non-nil means ignore some deadlined TODO items when making TODO list.
  613. There are different motivations for using different values, please think
  614. carefully when configuring this variable.
  615. This applies when creating the global todo list.
  616. Valid values are:
  617. near Don't show near deadline entries. A deadline is near when it is
  618. closer than `org-deadline-warning-days' days. The idea behind this
  619. is that such items will appear in the agenda anyway.
  620. far Don't show TODO entries where a deadline has been defined, but
  621. the deadline is not near. This is useful if you don't want to
  622. use the todo list to figure out what to do now.
  623. past Don't show entries with a deadline timestamp for today or in the past.
  624. future Don't show entries with a deadline timestamp in the future, not even
  625. when they become `near' ones. Use it with caution.
  626. all Ignore all TODO entries that do have a deadline.
  627. t Same as `near', for backward compatibility.
  628. This variable can also have an integer as a value. See
  629. `org-agenda-todo-ignore-timestamp' for more details.
  630. See also `org-agenda-todo-ignore-with-date'.
  631. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  632. to make his option also apply to the tags-todo list."
  633. :group 'org-agenda-skip
  634. :group 'org-agenda-todo-list
  635. :type '(choice
  636. (const :tag "Ignore near deadlines" near)
  637. (const :tag "Ignore near deadlines (compatibility)" t)
  638. (const :tag "Ignore far deadlines" far)
  639. (const :tag "Ignore all TODOs with a deadlines" all)
  640. (const :tag "Show all TODOs, even if they have a deadline" nil)
  641. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  642. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  643. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  644. The variables
  645. `org-agenda-todo-ignore-with-date',
  646. `org-agenda-todo-ignore-timestamp',
  647. `org-agenda-todo-ignore-scheduled',
  648. `org-agenda-todo-ignore-deadlines'
  649. make the global TODO list skip entries that have time stamps of certain
  650. kinds. If this option is set, the same options will also apply for the
  651. tags-todo search, which is the general tags/property matcher
  652. restricted to unfinished TODO entries only."
  653. :group 'org-agenda-skip
  654. :group 'org-agenda-todo-list
  655. :group 'org-agenda-match-view
  656. :type 'boolean)
  657. (defcustom org-agenda-skip-scheduled-if-done nil
  658. "Non-nil means don't show scheduled items in agenda when they are done.
  659. This is relevant for the daily/weekly agenda, not for the TODO list. And
  660. it applies only to the actual date of the scheduling. Warnings about
  661. an item with a past scheduling dates are always turned off when the item
  662. is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  667. "Non-nil means skip scheduling line if same entry shows because of deadline.
  668. In the agenda of today, an entry can show up multiple times because
  669. it is both scheduled and has a nearby deadline, and maybe a plain time
  670. stamp as well.
  671. When this variable is t, then only the deadline is shown and the fact that
  672. the entry is scheduled today or was scheduled previously is not shown.
  673. When this variable is nil, the entry will be shown several times. When
  674. the variable is the symbol `not-today', then skip scheduled previously,
  675. but not scheduled today."
  676. :group 'org-agenda-skip
  677. :group 'org-agenda-daily/weekly
  678. :type '(choice
  679. (const :tag "Never" nil)
  680. (const :tag "Always" t)
  681. (const :tag "Not when scheduled today" not-today)))
  682. (defcustom org-agenda-skip-deadline-if-done nil
  683. "Non-nil means don't show deadlines when the corresponding item is done.
  684. When nil, the deadline is still shown and should give you a happy feeling.
  685. This is relevant for the daily/weekly agenda. And it applied only to the
  686. actually date of the deadline. Warnings about approaching and past-due
  687. deadlines are always turned off when the item is DONE."
  688. :group 'org-agenda-skip
  689. :group 'org-agenda-daily/weekly
  690. :type 'boolean)
  691. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  692. "Non-nil means skip deadline prewarning when entry is also scheduled.
  693. This will apply on all days where a prewarning for the deadline would
  694. be shown, but not at the day when the entry is actually due. On that day,
  695. the deadline will be shown anyway.
  696. This variable may be set to nil, t, or a number which will then give
  697. the number of days before the actual deadline when the prewarnings
  698. should resume.
  699. This can be used in a workflow where the first showing of the deadline will
  700. trigger you to schedule it, and then you don't want to be reminded of it
  701. because you will take care of it on the day when scheduled."
  702. :group 'org-agenda-skip
  703. :group 'org-agenda-daily/weekly
  704. :type '(choice
  705. (const :tag "Alwas show prewarning" nil)
  706. (const :tag "Remove prewarning if entry is scheduled" t)
  707. (integer :tag "Restart prewarning N days before deadline")))
  708. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  709. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  710. When non-nil, after the search for timestamps has matched once in an
  711. entry, the rest of the entry will not be searched."
  712. :group 'org-agenda-skip
  713. :type 'boolean)
  714. (defcustom org-agenda-skip-timestamp-if-done nil
  715. "Non-nil means don't select item by timestamp or -range if it is DONE."
  716. :group 'org-agenda-skip
  717. :group 'org-agenda-daily/weekly
  718. :type 'boolean)
  719. (defcustom org-agenda-dim-blocked-tasks t
  720. "Non-nil means dim blocked tasks in the agenda display.
  721. This causes some overhead during agenda construction, but if you
  722. have turned on `org-enforce-todo-dependencies',
  723. `org-enforce-todo-checkbox-dependencies', or any other blocking
  724. mechanism, this will create useful feedback in the agenda.
  725. Instead of t, this variable can also have the value `invisible'.
  726. Then blocked tasks will be invisible and only become visible when
  727. they become unblocked. An exemption to this behavior is when a task is
  728. blocked because of unchecked checkboxes below it. Since checkboxes do
  729. not show up in the agenda views, making this task invisible you remove any
  730. trace from agenda views that there is something to do. Therefore, a task
  731. that is blocked because of checkboxes will never be made invisible, it
  732. will only be dimmed."
  733. :group 'org-agenda-daily/weekly
  734. :group 'org-agenda-todo-list
  735. :type '(choice
  736. (const :tag "Do not dim" nil)
  737. (const :tag "Dim to a grey face" t)
  738. (const :tag "Make invisible" invisible)))
  739. (defcustom org-timeline-show-empty-dates 3
  740. "Non-nil means `org-timeline' also shows dates without an entry.
  741. When nil, only the days which actually have entries are shown.
  742. When t, all days between the first and the last date are shown.
  743. When an integer, show also empty dates, but if there is a gap of more than
  744. N days, just insert a special line indicating the size of the gap."
  745. :group 'org-agenda-skip
  746. :type '(choice
  747. (const :tag "None" nil)
  748. (const :tag "All" t)
  749. (integer :tag "at most")))
  750. (defgroup org-agenda-startup nil
  751. "Options concerning initial settings in the Agenda in Org Mode."
  752. :tag "Org Agenda Startup"
  753. :group 'org-agenda)
  754. (defcustom org-agenda-menu-show-matcher t
  755. "Non-nil means show the match string in the agenda dispatcher menu.
  756. When nil, the matcher string is not shown, but is put into the help-echo
  757. property so than moving the mouse over the command shows it.
  758. Setting it to nil is good if matcher strings are very long and/or if
  759. you want to use two-column display (see `org-agenda-menu-two-column')."
  760. :group 'org-agenda
  761. :type 'boolean)
  762. (defcustom org-agenda-menu-two-column nil
  763. "Non-nil means, use two columns to show custom commands in the dispatcher.
  764. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  765. to nil."
  766. :group 'org-agenda
  767. :type 'boolean)
  768. (defcustom org-finalize-agenda-hook nil
  769. "Hook run just before displaying an agenda buffer."
  770. :group 'org-agenda-startup
  771. :type 'hook)
  772. (defcustom org-agenda-mouse-1-follows-link nil
  773. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  774. A longer mouse click will still set point. Does not work on XEmacs.
  775. Needs to be set before org.el is loaded."
  776. :group 'org-agenda-startup
  777. :type 'boolean)
  778. (defcustom org-agenda-start-with-follow-mode nil
  779. "The initial value of follow mode in a newly created agenda window."
  780. :group 'org-agenda-startup
  781. :type 'boolean)
  782. (defcustom org-agenda-show-outline-path t
  783. "Non-nil means show outline path in echo area after line motion."
  784. :group 'org-agenda-startup
  785. :type 'boolean)
  786. (defcustom org-agenda-start-with-entry-text-mode nil
  787. "The initial value of entry-text-mode in a newly created agenda window."
  788. :group 'org-agenda-startup
  789. :type 'boolean)
  790. (defcustom org-agenda-entry-text-maxlines 5
  791. "Number of text lines to be added when `E' is pressed in the agenda.
  792. Note that this variable only used during agenda display. Add add entry text
  793. when exporting the agenda, configure the variable
  794. `org-agenda-add-entry-ext-maxlines'."
  795. :group 'org-agenda
  796. :type 'integer)
  797. (defcustom org-agenda-entry-text-exclude-regexps nil
  798. "List of regular expressions to clean up entry text.
  799. The complete matches of all regular expressions in this list will be
  800. removed from entry text before it is shown in the agenda."
  801. :group 'org-agenda
  802. :type '(repeat (regexp)))
  803. (defvar org-agenda-entry-text-cleanup-hook nil
  804. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  805. This cleanup is done in a temporary buffer, so the function may inspect and
  806. change the entire buffer.
  807. Some default stuff like drawers and scheduling/deadline dates will already
  808. have been removed when this is called, as will any matches for regular
  809. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  810. (defvar org-agenda-include-inactive-timestamps nil
  811. "Non-nil means include inactive time stamps in agenda and timeline.")
  812. (defgroup org-agenda-windows nil
  813. "Options concerning the windows used by the Agenda in Org Mode."
  814. :tag "Org Agenda Windows"
  815. :group 'org-agenda)
  816. (defcustom org-agenda-window-setup 'reorganize-frame
  817. "How the agenda buffer should be displayed.
  818. Possible values for this option are:
  819. current-window Show agenda in the current window, keeping all other windows.
  820. other-window Use `switch-to-buffer-other-window' to display agenda.
  821. reorganize-frame Show only two windows on the current frame, the current
  822. window and the agenda.
  823. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  824. Also, when exiting the agenda, kill that frame.
  825. See also the variable `org-agenda-restore-windows-after-quit'."
  826. :group 'org-agenda-windows
  827. :type '(choice
  828. (const current-window)
  829. (const other-frame)
  830. (const other-window)
  831. (const reorganize-frame)))
  832. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  833. "The min and max height of the agenda window as a fraction of frame height.
  834. The value of the variable is a cons cell with two numbers between 0 and 1.
  835. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  836. :group 'org-agenda-windows
  837. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  838. (defcustom org-agenda-restore-windows-after-quit nil
  839. "Non-nil means restore window configuration upon exiting agenda.
  840. Before the window configuration is changed for displaying the agenda,
  841. the current status is recorded. When the agenda is exited with
  842. `q' or `x' and this option is set, the old state is restored. If
  843. `org-agenda-window-setup' is `other-frame', the value of this
  844. option will be ignored."
  845. :group 'org-agenda-windows
  846. :type 'boolean)
  847. (defcustom org-agenda-ndays nil
  848. "Number of days to include in overview display.
  849. Should be 1 or 7.
  850. Obsolete, see `org-agenda-span'."
  851. :group 'org-agenda-daily/weekly
  852. :type 'integer)
  853. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  854. (defcustom org-agenda-span 'week
  855. "Number of days to include in overview display.
  856. Can be day, week, month, year, or any number of days.
  857. Custom commands can set this variable in the options section."
  858. :group 'org-agenda-daily/weekly
  859. :type '(choice (const :tag "Day" day)
  860. (const :tag "Week" week)
  861. (const :tag "Month" month)
  862. (const :tag "Year" year)
  863. (integer :tag "Custom")))
  864. (defcustom org-agenda-start-on-weekday 1
  865. "Non-nil means start the overview always on the specified weekday.
  866. 0 denotes Sunday, 1 denotes Monday etc.
  867. When nil, always start on the current day.
  868. Custom commands can set this variable in the options section."
  869. :group 'org-agenda-daily/weekly
  870. :type '(choice (const :tag "Today" nil)
  871. (integer :tag "Weekday No.")))
  872. (defcustom org-agenda-show-all-dates t
  873. "Non-nil means `org-agenda' shows every day in the selected range.
  874. When nil, only the days which actually have entries are shown."
  875. :group 'org-agenda-daily/weekly
  876. :type 'boolean)
  877. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  878. "Format string for displaying dates in the agenda.
  879. Used by the daily/weekly agenda and by the timeline. This should be
  880. a format string understood by `format-time-string', or a function returning
  881. the formatted date as a string. The function must take a single argument,
  882. a calendar-style date list like (month day year)."
  883. :group 'org-agenda-daily/weekly
  884. :type '(choice
  885. (string :tag "Format string")
  886. (function :tag "Function")))
  887. (defun org-agenda-format-date-aligned (date)
  888. "Format a date string for display in the daily/weekly agenda, or timeline.
  889. This function makes sure that dates are aligned for easy reading."
  890. (require 'cal-iso)
  891. (let* ((dayname (calendar-day-name date))
  892. (day (cadr date))
  893. (day-of-week (calendar-day-of-week date))
  894. (month (car date))
  895. (monthname (calendar-month-name month))
  896. (year (nth 2 date))
  897. (iso-week (org-days-to-iso-week
  898. (calendar-absolute-from-gregorian date)))
  899. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  900. (1- year))
  901. ((and (= month 12) (<= iso-week 1))
  902. (1+ year))
  903. (t year)))
  904. (weekstring (if (= day-of-week 1)
  905. (format " W%02d" iso-week)
  906. "")))
  907. (format "%-10s %2d %s %4d%s"
  908. dayname day monthname year weekstring)))
  909. (defcustom org-agenda-time-leading-zero nil
  910. "Non-nil means use leading zero for military times in agenda.
  911. For example, 9:30am would become 09:30 rather than 9:30."
  912. :group 'org-agenda-daily/weekly
  913. :type 'boolean)
  914. (defcustom org-agenda-timegrid-use-ampm nil
  915. "When set, show AM/PM style timestamps on the timegrid."
  916. :group 'org-agenda
  917. :type 'boolean)
  918. (defun org-agenda-time-of-day-to-ampm (time)
  919. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  920. (let* ((hour-number (string-to-number (substring time 0 -3)))
  921. (minute (substring time -2))
  922. (ampm "am"))
  923. (cond
  924. ((equal hour-number 12)
  925. (setq ampm "pm"))
  926. ((> hour-number 12)
  927. (setq ampm "pm")
  928. (setq hour-number (- hour-number 12))))
  929. (concat
  930. (if org-agenda-time-leading-zero
  931. (format "%02d" hour-number)
  932. (format "%02s" (number-to-string hour-number)))
  933. ":" minute ampm)))
  934. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  935. "Conditionally convert TIME to AM/PM format
  936. based on `org-agenda-timegrid-use-ampm'"
  937. (if org-agenda-timegrid-use-ampm
  938. (org-agenda-time-of-day-to-ampm time)
  939. time))
  940. (defcustom org-agenda-weekend-days '(6 0)
  941. "Which days are weekend?
  942. These days get the special face `org-agenda-date-weekend' in the agenda
  943. and timeline buffers."
  944. :group 'org-agenda-daily/weekly
  945. :type '(set :greedy t
  946. (const :tag "Monday" 1)
  947. (const :tag "Tuesday" 2)
  948. (const :tag "Wednesday" 3)
  949. (const :tag "Thursday" 4)
  950. (const :tag "Friday" 5)
  951. (const :tag "Saturday" 6)
  952. (const :tag "Sunday" 0)))
  953. (defcustom org-agenda-include-diary nil
  954. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  955. Custom commands can set this variable in the options section."
  956. :group 'org-agenda-daily/weekly
  957. :type 'boolean)
  958. (defcustom org-agenda-include-deadlines t
  959. "If non-nil, include entries within their deadline warning period.
  960. Custom commands can set this variable in the options section."
  961. :group 'org-agenda-daily/weekly
  962. :type 'boolean)
  963. (defcustom org-agenda-repeating-timestamp-show-all t
  964. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  965. When set to a list of strings, only show occurrences of repeating
  966. stamps for these TODO keywords. When nil, only one occurrence is
  967. shown, either today or the nearest into the future."
  968. :group 'org-agenda-daily/weekly
  969. :type '(choice
  970. (const :tag "Show repeating stamps" t)
  971. (repeat :tag "Show repeating stamps for these TODO keywords"
  972. (string :tag "TODO Keyword"))
  973. (const :tag "Don't show repeating stamps" nil)))
  974. (defcustom org-scheduled-past-days 10000
  975. "No. of days to continue listing scheduled items that are not marked DONE.
  976. When an item is scheduled on a date, it shows up in the agenda on this
  977. day and will be listed until it is marked done for the number of days
  978. given here."
  979. :group 'org-agenda-daily/weekly
  980. :type 'integer)
  981. (defcustom org-agenda-log-mode-items '(closed clock)
  982. "List of items that should be shown in agenda log mode.
  983. This list may contain the following symbols:
  984. closed Show entries that have been closed on that day.
  985. clock Show entries that have received clocked time on that day.
  986. state Show all logged state changes.
  987. Note that instead of changing this variable, you can also press `C-u l' in
  988. the agenda to display all available LOG items temporarily."
  989. :group 'org-agenda-daily/weekly
  990. :type '(set :greedy t (const closed) (const clock) (const state)))
  991. (defcustom org-agenda-clock-consistency-checks
  992. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  993. :gap-ok-around ("4:00")
  994. :default-face ((:background "DarkRed") (:foreground "white"))
  995. :overlap-face nil :gap-face nil :no-end-time-face nil
  996. :long-face nil :short-face nil)
  997. "This is a property list, with the following keys:
  998. :max-duration Mark clocking chunks that are longer than this time.
  999. This is a time string like \"HH:MM\", or the number
  1000. of minutes as an integer.
  1001. :min-duration Mark clocking chunks that are shorter that this.
  1002. This is a time string like \"HH:MM\", or the number
  1003. of minutes as an integer.
  1004. :max-gap Mark gaps between clocking chunks that are longer than
  1005. this duration. A number of minutes, or a string
  1006. like \"HH:MM\".
  1007. :gap-ok-around List of times during the day which are usually not working
  1008. times. When a gap is detected, but the gap contains any
  1009. of these times, the gap is *not* reported. For example,
  1010. if this is (\"4:00\" \"13:00\") then gaps that contain
  1011. 4:00 in the morning (i.e. the night) and 13:00
  1012. (i.e. a typical lunch time) do not cause a warning.
  1013. You should have at least one time during the night in this
  1014. list, or otherwise the first task each morning will trigger
  1015. a warning because it follows a long gap.
  1016. Furthermore, the following properties can be used to define faces for
  1017. issue display.
  1018. :default-face the default face, if the specific face is undefined
  1019. :overlap-face face for overlapping clocks
  1020. :gap-face face for gaps between clocks
  1021. :no-end-time-face face for incomplete clocks
  1022. :long-face face for clock intervals that are too long
  1023. :short-face face for clock intervals that are too short"
  1024. :group 'org-agenda-daily/weekly
  1025. :group 'org-clock
  1026. :type 'plist)
  1027. (defcustom org-agenda-log-mode-add-notes t
  1028. "Non-nil means add first line of notes to log entries in agenda views.
  1029. If a log item like a state change or a clock entry is associated with
  1030. notes, the first line of these notes will be added to the entry in the
  1031. agenda display."
  1032. :group 'org-agenda-daily/weekly
  1033. :type 'boolean)
  1034. (defcustom org-agenda-start-with-log-mode nil
  1035. "The initial value of log-mode in a newly created agenda window."
  1036. :group 'org-agenda-startup
  1037. :group 'org-agenda-daily/weekly
  1038. :type 'boolean)
  1039. (defcustom org-agenda-start-with-clockreport-mode nil
  1040. "The initial value of clockreport-mode in a newly created agenda window."
  1041. :group 'org-agenda-startup
  1042. :group 'org-agenda-daily/weekly
  1043. :type 'boolean)
  1044. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1045. "Property list with parameters for the clocktable in clockreport mode.
  1046. This is the display mode that shows a clock table in the daily/weekly
  1047. agenda, the properties for this dynamic block can be set here.
  1048. The usual clocktable parameters are allowed here, but you cannot set
  1049. the properties :name, :tstart, :tend, :block, and :scope - these will
  1050. be overwritten to make sure the content accurately reflects the
  1051. current display in the agenda."
  1052. :group 'org-agenda-daily/weekly
  1053. :type 'plist)
  1054. (defcustom org-agenda-search-view-always-boolean nil
  1055. "Non-nil means the search string is interpreted as individual parts.
  1056. The search string for search view can either be interpreted as a phrase,
  1057. or as a list of snippets that define a boolean search for a number of
  1058. strings.
  1059. When this is non-nil, the string will be split on whitespace, and each
  1060. snippet will be searched individually, and all must match in order to
  1061. select an entry. A snippet is then a single string of non-white
  1062. characters, or a string in double quotes, or a regexp in {} braces.
  1063. If a snippet is preceded by \"-\", the snippet must *not* match.
  1064. \"+\" is syntactic sugar for positive selection. Each snippet may
  1065. be found as a full word or a partial word, but see the variable
  1066. `org-agenda-search-view-force-full-words'.
  1067. When this is nil, search will look for the entire search phrase as one,
  1068. with each space character matching any amount of whitespace, including
  1069. line breaks.
  1070. Even when this is nil, you can still switch to Boolean search dynamically
  1071. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1072. is a regexp marked with braces like \"{abc}\", this will also switch to
  1073. boolean search."
  1074. :group 'org-agenda-search-view
  1075. :type 'boolean)
  1076. (if (fboundp 'defvaralias)
  1077. (defvaralias 'org-agenda-search-view-search-words-only
  1078. 'org-agenda-search-view-always-boolean))
  1079. (defcustom org-agenda-search-view-force-full-words nil
  1080. "Non-nil means, search words must be matches as complete words.
  1081. When nil, they may also match part of a word."
  1082. :group 'org-agenda-search-view
  1083. :type 'boolean)
  1084. (defgroup org-agenda-time-grid nil
  1085. "Options concerning the time grid in the Org-mode Agenda."
  1086. :tag "Org Agenda Time Grid"
  1087. :group 'org-agenda)
  1088. (defcustom org-agenda-search-headline-for-time t
  1089. "Non-nil means search headline for a time-of-day.
  1090. If the headline contains a time-of-day in one format or another, it will
  1091. be used to sort the entry into the time sequence of items for a day.
  1092. Some people have time stamps in the headline that refer to the creation
  1093. time or so, and then this produces an unwanted side effect. If this is
  1094. the case for your, use this variable to turn off searching the headline
  1095. for a time."
  1096. :group 'org-agenda-time-grid
  1097. :type 'boolean)
  1098. (defcustom org-agenda-use-time-grid t
  1099. "Non-nil means show a time grid in the agenda schedule.
  1100. A time grid is a set of lines for specific times (like every two hours between
  1101. 8:00 and 20:00). The items scheduled for a day at specific times are
  1102. sorted in between these lines.
  1103. For details about when the grid will be shown, and what it will look like, see
  1104. the variable `org-agenda-time-grid'."
  1105. :group 'org-agenda-time-grid
  1106. :type 'boolean)
  1107. (defcustom org-agenda-time-grid
  1108. '((daily today require-timed)
  1109. "----------------"
  1110. (800 1000 1200 1400 1600 1800 2000))
  1111. "The settings for time grid for agenda display.
  1112. This is a list of three items. The first item is again a list. It contains
  1113. symbols specifying conditions when the grid should be displayed:
  1114. daily if the agenda shows a single day
  1115. weekly if the agenda shows an entire week
  1116. today show grid on current date, independent of daily/weekly display
  1117. require-timed show grid only if at least one item has a time specification
  1118. The second item is a string which will be placed behind the grid time.
  1119. The third item is a list of integers, indicating the times that should have
  1120. a grid line."
  1121. :group 'org-agenda-time-grid
  1122. :type
  1123. '(list
  1124. (set :greedy t :tag "Grid Display Options"
  1125. (const :tag "Show grid in single day agenda display" daily)
  1126. (const :tag "Show grid in weekly agenda display" weekly)
  1127. (const :tag "Always show grid for today" today)
  1128. (const :tag "Show grid only if any timed entries are present"
  1129. require-timed)
  1130. (const :tag "Skip grid times already present in an entry"
  1131. remove-match))
  1132. (string :tag "Grid String")
  1133. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1134. (defcustom org-agenda-show-current-time-in-grid t
  1135. "Non-nil means show the current time in the time grid."
  1136. :group 'org-agenda-time-grid
  1137. :type 'boolean)
  1138. (defcustom org-agenda-current-time-string
  1139. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1140. "The string for the current time marker in the agenda."
  1141. :group 'org-agenda-time-grid
  1142. :type 'string)
  1143. (defgroup org-agenda-sorting nil
  1144. "Options concerning sorting in the Org-mode Agenda."
  1145. :tag "Org Agenda Sorting"
  1146. :group 'org-agenda)
  1147. (defcustom org-agenda-sorting-strategy
  1148. '((agenda habit-down time-up priority-down category-keep)
  1149. (todo priority-down category-keep)
  1150. (tags priority-down category-keep)
  1151. (search category-keep))
  1152. "Sorting structure for the agenda items of a single day.
  1153. This is a list of symbols which will be used in sequence to determine
  1154. if an entry should be listed before another entry. The following
  1155. symbols are recognized:
  1156. time-up Put entries with time-of-day indications first, early first
  1157. time-down Put entries with time-of-day indications first, late first
  1158. category-keep Keep the default order of categories, corresponding to the
  1159. sequence in `org-agenda-files'.
  1160. category-up Sort alphabetically by category, A-Z.
  1161. category-down Sort alphabetically by category, Z-A.
  1162. tag-up Sort alphabetically by last tag, A-Z.
  1163. tag-down Sort alphabetically by last tag, Z-A.
  1164. priority-up Sort numerically by priority, high priority last.
  1165. priority-down Sort numerically by priority, high priority first.
  1166. todo-state-up Sort by todo state, tasks that are done last.
  1167. todo-state-down Sort by todo state, tasks that are done first.
  1168. effort-up Sort numerically by estimated effort, high effort last.
  1169. effort-down Sort numerically by estimated effort, high effort first.
  1170. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1171. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1172. habit-up Put entries that are habits first
  1173. habit-down Put entries that are habits last
  1174. alpha-up Sort headlines alphabetically
  1175. alpha-down Sort headlines alphabetically, reversed
  1176. The different possibilities will be tried in sequence, and testing stops
  1177. if one comparison returns a \"not-equal\". For example, the default
  1178. '(time-up category-keep priority-down)
  1179. means: Pull out all entries having a specified time of day and sort them,
  1180. in order to make a time schedule for the current day the first thing in the
  1181. agenda listing for the day. Of the entries without a time indication, keep
  1182. the grouped in categories, don't sort the categories, but keep them in
  1183. the sequence given in `org-agenda-files'. Within each category sort by
  1184. priority.
  1185. Leaving out `category-keep' would mean that items will be sorted across
  1186. categories by priority.
  1187. Instead of a single list, this can also be a set of list for specific
  1188. contents, with a context symbol in the car of the list, any of
  1189. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1190. Custom commands can bind this variable in the options section."
  1191. :group 'org-agenda-sorting
  1192. :type `(choice
  1193. (repeat :tag "General" ,org-sorting-choice)
  1194. (list :tag "Individually"
  1195. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1196. (repeat ,org-sorting-choice))
  1197. (cons (const :tag "Strategy for TODO lists" todo)
  1198. (repeat ,org-sorting-choice))
  1199. (cons (const :tag "Strategy for Tags matches" tags)
  1200. (repeat ,org-sorting-choice))
  1201. (cons (const :tag "Strategy for search matches" search)
  1202. (repeat ,org-sorting-choice)))))
  1203. (defcustom org-agenda-cmp-user-defined nil
  1204. "A function to define the comparison `user-defined'.
  1205. This function must receive two arguments, agenda entry a and b.
  1206. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1207. the user comparison, return nil.
  1208. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1209. part of an agenda sorting strategy."
  1210. :group 'org-agenda-sorting
  1211. :type 'symbol)
  1212. (defcustom org-sort-agenda-notime-is-late t
  1213. "Non-nil means items without time are considered late.
  1214. This is only relevant for sorting. When t, items which have no explicit
  1215. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1216. do have a time. When nil, the default time is before 0:00. You can use this
  1217. option to decide if the schedule for today should come before or after timeless
  1218. agenda entries."
  1219. :group 'org-agenda-sorting
  1220. :type 'boolean)
  1221. (defcustom org-sort-agenda-noeffort-is-high t
  1222. "Non-nil means items without effort estimate are sorted as high effort.
  1223. This also applies when filtering an agenda view with respect to the
  1224. < or > effort operator. Then, tasks with no effort defined will be treated
  1225. as tasks with high effort.
  1226. When nil, such items are sorted as 0 minutes effort."
  1227. :group 'org-agenda-sorting
  1228. :type 'boolean)
  1229. (defgroup org-agenda-line-format nil
  1230. "Options concerning the entry prefix in the Org-mode agenda display."
  1231. :tag "Org Agenda Line Format"
  1232. :group 'org-agenda)
  1233. (defcustom org-agenda-prefix-format
  1234. '((agenda . " %i %-12:c%?-12t% s")
  1235. (timeline . " % s")
  1236. (todo . " %i %-12:c")
  1237. (tags . " %i %-12:c")
  1238. (search . " %i %-12:c"))
  1239. "Format specifications for the prefix of items in the agenda views.
  1240. An alist with five entries, each for the different agenda types. The
  1241. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1242. The values are format strings.
  1243. This format works similar to a printf format, with the following meaning:
  1244. %c the category of the item, \"Diary\" for entries from the diary,
  1245. or as given by the CATEGORY keyword or derived from the file name
  1246. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1247. %T the last tag of the item (ignore inherited tags, which come first)
  1248. %t the HH:MM time-of-day specification if one applies to the entry
  1249. %s Scheduling/Deadline information, a short string
  1250. %(expression) Eval EXPRESSION and replace the control string
  1251. by the result
  1252. All specifiers work basically like the standard `%s' of printf, but may
  1253. contain two additional characters: a question mark just after the `%'
  1254. and a whitespace/punctuation character just before the final letter.
  1255. If the first character after `%' is a question mark, the entire field
  1256. will only be included if the corresponding value applies to the current
  1257. entry. This is useful for fields which should have fixed width when
  1258. present, but zero width when absent. For example, \"%?-12t\" will
  1259. result in a 12 character time field if a time of the day is specified,
  1260. but will completely disappear in entries which do not contain a time.
  1261. If there is punctuation or whitespace character just before the final
  1262. format letter, this character will be appended to the field value if
  1263. the value is not empty. For example, the format \"%-12:c\" leads to
  1264. \"Diary: \" if the category is \"Diary\". If the category were be
  1265. empty, no additional colon would be inserted.
  1266. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1267. which means:
  1268. - Indent the line with two space characters
  1269. - Give the category a 12 chars wide field, padded with whitespace on
  1270. the right (because of `-'). Append a colon if there is a category
  1271. (because of `:').
  1272. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1273. time, don't put in an empty field, just skip it (because of '?').
  1274. - Finally, put the scheduling information.
  1275. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1276. `org-agenda-remove-tags'.
  1277. Custom commands can set this variable in the options section."
  1278. :type '(choice
  1279. (string :tag "General format")
  1280. (list :greedy t :tag "View dependent"
  1281. (cons (const agenda) (string :tag "Format"))
  1282. (cons (const timeline) (string :tag "Format"))
  1283. (cons (const todo) (string :tag "Format"))
  1284. (cons (const tags) (string :tag "Format"))
  1285. (cons (const search) (string :tag "Format"))))
  1286. :group 'org-agenda-line-format)
  1287. (defvar org-prefix-format-compiled nil
  1288. "The compiled version of the most recently used prefix format.
  1289. See the variable `org-agenda-prefix-format'.")
  1290. (defcustom org-agenda-todo-keyword-format "%-1s"
  1291. "Format for the TODO keyword in agenda lines.
  1292. Set this to something like \"%-12s\" if you want all TODO keywords
  1293. to occupy a fixed space in the agenda display."
  1294. :group 'org-agenda-line-format
  1295. :type 'string)
  1296. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1297. "Text preceding timerange entries in the agenda view.
  1298. This is a list with two strings. The first applies when the range
  1299. is entirely on one day. The second applies if the range spans several days.
  1300. The strings may have two \"%d\" format specifiers which will be filled
  1301. with the sequence number of the days, and the total number of days in the
  1302. range, respectively."
  1303. :group 'org-agenda-line-format
  1304. :type '(list
  1305. (string :tag "Deadline today ")
  1306. (choice :tag "Deadline relative"
  1307. (string :tag "Format string")
  1308. (function))))
  1309. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1310. "Text preceding scheduled items in the agenda view.
  1311. This is a list with two strings. The first applies when the item is
  1312. scheduled on the current day. The second applies when it has been scheduled
  1313. previously, it may contain a %d indicating that this is the nth time that
  1314. this item is scheduled, due to automatic rescheduling of unfinished items
  1315. for the following day. So this number is one larger than the number of days
  1316. that passed since this item was scheduled first."
  1317. :group 'org-agenda-line-format
  1318. :type '(list
  1319. (string :tag "Scheduled today ")
  1320. (string :tag "Scheduled previously")))
  1321. (defcustom org-agenda-inactive-leader "["
  1322. "Text preceding item pulled into the agenda by inactive time stamps.
  1323. These entries are added to the agenda when pressing \"[\"."
  1324. :group 'org-agenda-line-format
  1325. :type '(list
  1326. (string :tag "Scheduled today ")
  1327. (string :tag "Scheduled previously")))
  1328. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1329. "Text preceding deadline items in the agenda view.
  1330. This is a list with two strings. The first applies when the item has its
  1331. deadline on the current day. The second applies when it is in the past or
  1332. in the future, it may contain %d to capture how many days away the deadline
  1333. is (was)."
  1334. :group 'org-agenda-line-format
  1335. :type '(list
  1336. (string :tag "Deadline today ")
  1337. (choice :tag "Deadline relative"
  1338. (string :tag "Format string")
  1339. (function))))
  1340. (defcustom org-agenda-remove-times-when-in-prefix t
  1341. "Non-nil means remove duplicate time specifications in agenda items.
  1342. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1343. time-of-day specification in a headline or diary entry is extracted and
  1344. placed into the prefix. If this option is non-nil, the original specification
  1345. \(a timestamp or -range, or just a plain time(range) specification like
  1346. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1347. cluttered.
  1348. The option can be t or nil. It may also be the symbol `beg', indicating
  1349. that the time should only be removed when it is located at the beginning of
  1350. the headline/diary entry."
  1351. :group 'org-agenda-line-format
  1352. :type '(choice
  1353. (const :tag "Always" t)
  1354. (const :tag "Never" nil)
  1355. (const :tag "When at beginning of entry" beg)))
  1356. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1357. "Non-nil means remove time ranges specifications in agenda
  1358. items that span on several days."
  1359. :group 'org-agenda-line-format
  1360. :type 'boolean)
  1361. (defcustom org-agenda-default-appointment-duration nil
  1362. "Default duration for appointments that only have a starting time.
  1363. When nil, no duration is specified in such cases.
  1364. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1365. :group 'org-agenda-line-format
  1366. :type '(choice
  1367. (integer :tag "Minutes")
  1368. (const :tag "No default duration")))
  1369. (defcustom org-agenda-show-inherited-tags t
  1370. "Non-nil means show inherited tags in each agenda line."
  1371. :group 'org-agenda-line-format
  1372. :type 'boolean)
  1373. (defcustom org-agenda-hide-tags-regexp nil
  1374. "Regular expression used to filter away specific tags in agenda views.
  1375. This means that these tags will be present, but not be shown in the agenda
  1376. line. Secondary filtering will still work on the hidden tags.
  1377. Nil means don't hide any tags."
  1378. :group 'org-agenda-line-format
  1379. :type '(choice
  1380. (const :tag "Hide none" nil)
  1381. (string :tag "Regexp ")))
  1382. (defcustom org-agenda-remove-tags nil
  1383. "Non-nil means remove the tags from the headline copy in the agenda.
  1384. When this is the symbol `prefix', only remove tags when
  1385. `org-agenda-prefix-format' contains a `%T' specifier."
  1386. :group 'org-agenda-line-format
  1387. :type '(choice
  1388. (const :tag "Always" t)
  1389. (const :tag "Never" nil)
  1390. (const :tag "When prefix format contains %T" prefix)))
  1391. (if (fboundp 'defvaralias)
  1392. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1393. 'org-agenda-remove-tags))
  1394. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1395. "Shift tags in agenda items to this column.
  1396. If this number is positive, it specifies the column. If it is negative,
  1397. it means that the tags should be flushright to that column. For example,
  1398. -80 works well for a normal 80 character screen."
  1399. :group 'org-agenda-line-format
  1400. :type 'integer)
  1401. (if (fboundp 'defvaralias)
  1402. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1403. (defcustom org-agenda-fontify-priorities 'cookies
  1404. "Non-nil means highlight low and high priorities in agenda.
  1405. When t, the highest priority entries are bold, lowest priority italic.
  1406. However, settings in `org-priority-faces' will overrule these faces.
  1407. When this variable is the symbol `cookies', only fontify the
  1408. cookies, not the entire task.
  1409. This may also be an association list of priority faces, whose
  1410. keys are the character values of `org-highest-priority',
  1411. `org-default-priority', and `org-lowest-priority' (the default values
  1412. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1413. color as a string, or a list like `(:background \"Red\")'.
  1414. If it is a color, the variable `org-faces-easy-properties'
  1415. determines if it is a foreground or a background color."
  1416. :group 'org-agenda-line-format
  1417. :type '(choice
  1418. (const :tag "Never" nil)
  1419. (const :tag "Defaults" t)
  1420. (const :tag "Cookies only" cookies)
  1421. (repeat :tag "Specify"
  1422. (list (character :tag "Priority" :value ?A)
  1423. (choice :tag "Face "
  1424. (string :tag "Color")
  1425. (sexp :tag "Face"))))))
  1426. (defcustom org-agenda-day-face-function nil
  1427. "Function called to determine what face should be used to display a day.
  1428. The only argument passed to that function is the day. It should
  1429. returns a face, or nil if does not want to specify a face and let
  1430. the normal rules apply."
  1431. :group 'org-agenda-line-format
  1432. :type 'function)
  1433. (defcustom org-agenda-category-icon-alist nil
  1434. "Alist of category icon to be displayed in agenda views.
  1435. Each entry should have the following format:
  1436. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1437. Where CATEGORY-REGEXP is a regexp matching the categories where
  1438. the icon should be displayed.
  1439. FILE-OR-DATA either a file path or a string containing image data.
  1440. The other fields can be omited safely if not needed:
  1441. TYPE indicates the image type.
  1442. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1443. image data.
  1444. PROPS are additional image attributes to assign to the image,
  1445. like, e.g. `:ascent center'.
  1446. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1447. If you want to set the display properties yourself, just put a
  1448. list as second element:
  1449. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1450. For example, to display a 16px horizontal space for Emacs
  1451. category, you can use:
  1452. (\"Emacs\" '(space . (:width (16))))"
  1453. :group 'org-agenda-line-format
  1454. :type '(alist :key-type (string :tag "Regexp matching category")
  1455. :value-type (choice (list :tag "Icon"
  1456. (string :tag "File or data")
  1457. (symbol :tag "Type")
  1458. (boolean :tag "Data?")
  1459. (repeat :tag "Extra image properties" :inline t symbol))
  1460. (list :tag "Display properties" sexp))))
  1461. (defgroup org-agenda-column-view nil
  1462. "Options concerning column view in the agenda."
  1463. :tag "Org Agenda Column View"
  1464. :group 'org-agenda)
  1465. (defcustom org-agenda-columns-show-summaries t
  1466. "Non-nil means show summaries for columns displayed in the agenda view."
  1467. :group 'org-agenda-column-view
  1468. :type 'boolean)
  1469. (defcustom org-agenda-columns-compute-summary-properties t
  1470. "Non-nil means recompute all summary properties before column view.
  1471. When column view in the agenda is listing properties that have a summary
  1472. operator, it can go to all relevant buffers and recompute the summaries
  1473. there. This can mean overhead for the agenda column view, but is necessary
  1474. to have thing up to date.
  1475. As a special case, a CLOCKSUM property also makes sure that the clock
  1476. computations are current."
  1477. :group 'org-agenda-column-view
  1478. :type 'boolean)
  1479. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1480. "Non-nil means the duration of an appointment will add to day effort.
  1481. The property to which appointment durations will be added is the one given
  1482. in the option `org-effort-property'. If an appointment does not have
  1483. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1484. is not set, an appointment without end time will not contribute to the time
  1485. estimate."
  1486. :group 'org-agenda-column-view
  1487. :type 'boolean)
  1488. (defcustom org-agenda-auto-exclude-function nil
  1489. "A function called with a tag to decide if it is filtered on '/ RET'.
  1490. The sole argument to the function, which is called once for each
  1491. possible tag, is a string giving the name of the tag. The
  1492. function should return either nil if the tag should be included
  1493. as normal, or \"-<TAG>\" to exclude the tag.
  1494. Note that for the purpose of tag filtering, only the lower-case version of
  1495. all tags will be considered, so that this function will only ever see
  1496. the lower-case version of all tags."
  1497. :group 'org-agenda
  1498. :type 'function)
  1499. (defcustom org-agenda-bulk-custom-functions nil
  1500. "Alist of characters and custom functions for bulk actions.
  1501. For example, this value makes those two functions available:
  1502. '((?R set-category)
  1503. (?C bulk-cut))
  1504. With selected entries in an agenda buffer, `B R' will call
  1505. the custom function `set-category' on the selected entries.
  1506. Note that functions in this alist don't need to be quoted."
  1507. :type 'alist
  1508. :group 'org-agenda)
  1509. (eval-when-compile
  1510. (require 'cl))
  1511. (require 'org)
  1512. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1513. "Execute BODY with point at location given by `org-hd-marker' property.
  1514. If STRING is non-nil, the text property will be fetched from position 0
  1515. in that string. If STRING is nil, it will be fetched from the beginning
  1516. of the current line."
  1517. (org-with-gensyms (marker)
  1518. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1519. 'org-hd-marker string)))
  1520. (with-current-buffer (marker-buffer ,marker)
  1521. (save-excursion
  1522. (goto-char ,marker)
  1523. ,@body)))))
  1524. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1525. (defun org-add-agenda-custom-command (entry)
  1526. "Replace or add a command in `org-agenda-custom-commands'.
  1527. This is mostly for hacking and trying a new command - once the command
  1528. works you probably want to add it to `org-agenda-custom-commands' for good."
  1529. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1530. (if ass
  1531. (setcdr ass (cdr entry))
  1532. (push entry org-agenda-custom-commands))))
  1533. ;;; Define the Org-agenda-mode
  1534. (defvar org-agenda-mode-map (make-sparse-keymap)
  1535. "Keymap for `org-agenda-mode'.")
  1536. (if (fboundp 'defvaralias)
  1537. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1538. (defvar org-agenda-menu) ; defined later in this file.
  1539. (defvar org-agenda-restrict) ; defined later in this file.
  1540. (defvar org-agenda-follow-mode nil)
  1541. (defvar org-agenda-entry-text-mode nil)
  1542. (defvar org-agenda-clockreport-mode nil)
  1543. (defvar org-agenda-show-log nil)
  1544. (defvar org-agenda-redo-command nil)
  1545. (defvar org-agenda-query-string nil)
  1546. (defvar org-agenda-mode-hook nil
  1547. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1548. (defvar org-agenda-type nil)
  1549. (defvar org-agenda-force-single-file nil)
  1550. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1551. (defun org-agenda-mode ()
  1552. "Mode for time-sorted view on action items in Org-mode files.
  1553. The following commands are available:
  1554. \\{org-agenda-mode-map}"
  1555. (interactive)
  1556. (kill-all-local-variables)
  1557. (setq org-agenda-undo-list nil
  1558. org-agenda-pending-undo-list nil
  1559. org-agenda-bulk-marked-entries nil)
  1560. (setq major-mode 'org-agenda-mode)
  1561. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1562. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1563. (setq mode-name "Org-Agenda")
  1564. (use-local-map org-agenda-mode-map)
  1565. (easy-menu-add org-agenda-menu)
  1566. (if org-startup-truncated (setq truncate-lines t))
  1567. (org-set-local 'line-move-visual nil)
  1568. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1569. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1570. ;; Make sure properties are removed when copying text
  1571. (when (boundp 'buffer-substring-filters)
  1572. (org-set-local 'buffer-substring-filters
  1573. (cons (lambda (x)
  1574. (set-text-properties 0 (length x) nil x) x)
  1575. buffer-substring-filters)))
  1576. (unless org-agenda-keep-modes
  1577. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1578. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1579. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1580. org-agenda-show-log org-agenda-start-with-log-mode))
  1581. (easy-menu-change
  1582. '("Agenda") "Agenda Files"
  1583. (append
  1584. (list
  1585. (vector
  1586. (if (get 'org-agenda-files 'org-restrict)
  1587. "Restricted to single file"
  1588. "Edit File List")
  1589. '(org-edit-agenda-file-list)
  1590. (not (get 'org-agenda-files 'org-restrict)))
  1591. "--")
  1592. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1593. (org-agenda-set-mode-name)
  1594. (apply
  1595. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1596. (list 'org-agenda-mode-hook)))
  1597. (substitute-key-definition 'undo 'org-agenda-undo
  1598. org-agenda-mode-map global-map)
  1599. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1600. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1601. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1602. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1603. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1604. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1605. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1606. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1607. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1608. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1609. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1610. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1611. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1612. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1613. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1614. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1615. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1616. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1617. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1618. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1619. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1620. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1621. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1622. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1623. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1624. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1625. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1627. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1628. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1629. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1630. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1631. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1632. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1633. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1634. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1635. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1636. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1637. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1638. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1639. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1640. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1641. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1642. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1643. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1644. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1645. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1646. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1647. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1648. (while l (org-defkey org-agenda-mode-map
  1649. (int-to-string (pop l)) 'digit-argument)))
  1650. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1651. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1652. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1653. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1654. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1655. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1656. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1657. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1658. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1659. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1660. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1661. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1662. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1663. 'org-clock-modify-effort-estimate)
  1664. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1665. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1666. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1667. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1668. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1669. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1670. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1671. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1672. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1673. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1674. (substitute-key-definition 'next-line 'org-agenda-next-line
  1675. org-agenda-mode-map global-map)
  1676. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1677. org-agenda-mode-map global-map)
  1678. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1679. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1680. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1681. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1682. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1683. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1684. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1685. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1686. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1687. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1688. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1689. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1690. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1691. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1692. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1693. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1694. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1695. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1696. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1697. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1698. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1699. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1700. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1701. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1702. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1703. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1704. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1705. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1706. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1707. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1708. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1709. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1710. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1711. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1712. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1713. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1714. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1715. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1716. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1717. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1718. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1719. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1720. (when org-agenda-mouse-1-follows-link
  1721. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1722. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1723. '("Agenda"
  1724. ("Agenda Files")
  1725. "--"
  1726. ("Agenda Dates"
  1727. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1728. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1729. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1730. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1731. "--"
  1732. ("View"
  1733. ["Day View" org-agenda-day-view
  1734. :active (org-agenda-check-type nil 'agenda)
  1735. :style radio :selected (eq org-agenda-current-span 'day)
  1736. :keys "v d (or just d)"]
  1737. ["Week View" org-agenda-week-view
  1738. :active (org-agenda-check-type nil 'agenda)
  1739. :style radio :selected (eq org-agenda-current-span 'week)
  1740. :keys "v w (or just w)"]
  1741. ["Month View" org-agenda-month-view
  1742. :active (org-agenda-check-type nil 'agenda)
  1743. :style radio :selected (eq org-agenda-current-span 'month)
  1744. :keys "v m"]
  1745. ["Year View" org-agenda-year-view
  1746. :active (org-agenda-check-type nil 'agenda)
  1747. :style radio :selected (eq org-agenda-current-span 'year)
  1748. :keys "v y"]
  1749. "--"
  1750. ["Include Diary" org-agenda-toggle-diary
  1751. :style toggle :selected org-agenda-include-diary
  1752. :active (org-agenda-check-type nil 'agenda)]
  1753. ["Include Deadlines" org-agenda-toggle-deadlines
  1754. :style toggle :selected org-agenda-include-deadlines
  1755. :active (org-agenda-check-type nil 'agenda)]
  1756. ["Use Time Grid" org-agenda-toggle-time-grid
  1757. :style toggle :selected org-agenda-use-time-grid
  1758. :active (org-agenda-check-type nil 'agenda)]
  1759. "--"
  1760. ["Show clock report" org-agenda-clockreport-mode
  1761. :style toggle :selected org-agenda-clockreport-mode
  1762. :active (org-agenda-check-type nil 'agenda)]
  1763. ["Show some entry text" org-agenda-entry-text-mode
  1764. :style toggle :selected org-agenda-entry-text-mode
  1765. :active t]
  1766. "--"
  1767. ["Show Logbook entries" org-agenda-log-mode
  1768. :style toggle :selected org-agenda-show-log
  1769. :active (org-agenda-check-type nil 'agenda 'timeline)
  1770. :keys "v l (or just l)"]
  1771. ["Include archived trees" org-agenda-archives-mode
  1772. :style toggle :selected org-agenda-archives-mode :active t
  1773. :keys "v a"]
  1774. ["Include archive files" (org-agenda-archives-mode t)
  1775. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1776. :keys "v A"]
  1777. "--"
  1778. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1779. ["Write view to file" org-write-agenda t]
  1780. ["Rebuild buffer" org-agenda-redo t]
  1781. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1782. "--"
  1783. ["Show original entry" org-agenda-show t]
  1784. ["Go To (other window)" org-agenda-goto t]
  1785. ["Go To (this window)" org-agenda-switch-to t]
  1786. ["Follow Mode" org-agenda-follow-mode
  1787. :style toggle :selected org-agenda-follow-mode :active t]
  1788. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1789. "--"
  1790. ("TODO"
  1791. ["Cycle TODO" org-agenda-todo t]
  1792. ["Next TODO set" org-agenda-todo-nextset t]
  1793. ["Previous TODO set" org-agenda-todo-previousset t]
  1794. ["Add note" org-agenda-add-note t])
  1795. ("Archive/Refile/Delete"
  1796. ["Archive default" org-agenda-archive-default t]
  1797. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1798. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1799. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1800. ["Archive subtree" org-agenda-archive t]
  1801. "--"
  1802. ["Refile" org-agenda-refile t]
  1803. "--"
  1804. ["Delete subtree" org-agenda-kill t])
  1805. ("Bulk action"
  1806. ["Mark entry" org-agenda-bulk-mark t]
  1807. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1808. ["Unmark entry" org-agenda-bulk-unmark t]
  1809. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1810. ["Act on all marked" org-agenda-bulk-action t]
  1811. "--"
  1812. ("Tags and Properties"
  1813. ["Show all Tags" org-agenda-show-tags t]
  1814. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1815. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1816. "--"
  1817. ["Column View" org-columns t])
  1818. ("Deadline/Schedule"
  1819. ["Schedule" org-agenda-schedule t]
  1820. ["Set Deadline" org-agenda-deadline t]
  1821. "--"
  1822. ["Mark item" org-agenda-action :active t :keys "k m"]
  1823. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1824. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1825. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1826. "--"
  1827. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1828. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1829. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1830. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1831. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1832. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1833. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1834. ("Clock and Effort"
  1835. ["Clock in" org-agenda-clock-in t]
  1836. ["Clock out" org-agenda-clock-out t]
  1837. ["Clock cancel" org-agenda-clock-cancel t]
  1838. ["Goto running clock" org-clock-goto t]
  1839. "--"
  1840. ["Set Effort" org-agenda-set-effort t]
  1841. ["Change clocked effort" org-clock-modify-effort-estimate
  1842. (org-clock-is-active)])
  1843. ("Priority"
  1844. ["Set Priority" org-agenda-priority t]
  1845. ["Increase Priority" org-agenda-priority-up t]
  1846. ["Decrease Priority" org-agenda-priority-down t]
  1847. ["Show Priority" org-agenda-show-priority t])
  1848. ("Calendar/Diary"
  1849. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1850. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1851. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1852. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1853. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1854. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1855. "--"
  1856. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1857. "--"
  1858. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1859. "--"
  1860. ("MobileOrg"
  1861. ["Push Files and Views" org-mobile-push t]
  1862. ["Get Captured and Flagged" org-mobile-pull t]
  1863. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1864. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1865. "--"
  1866. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1867. "--"
  1868. ["Quit" org-agenda-quit t]
  1869. ["Exit and Release Buffers" org-agenda-exit t]
  1870. ))
  1871. ;;; Agenda undo
  1872. (defvar org-agenda-allow-remote-undo t
  1873. "Non-nil means allow remote undo from the agenda buffer.")
  1874. (defvar org-agenda-undo-list nil
  1875. "List of undoable operations in the agenda since last refresh.")
  1876. (defvar org-agenda-undo-has-started-in nil
  1877. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1878. (defvar org-agenda-pending-undo-list nil
  1879. "In a series of undo commands, this is the list of remaining undo items.")
  1880. (defun org-agenda-undo ()
  1881. "Undo a remote editing step in the agenda.
  1882. This undoes changes both in the agenda buffer and in the remote buffer
  1883. that have been changed along."
  1884. (interactive)
  1885. (or org-agenda-allow-remote-undo
  1886. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1887. (if (not (eq this-command last-command))
  1888. (setq org-agenda-undo-has-started-in nil
  1889. org-agenda-pending-undo-list org-agenda-undo-list))
  1890. (if (not org-agenda-pending-undo-list)
  1891. (error "No further undo information"))
  1892. (let* ((entry (pop org-agenda-pending-undo-list))
  1893. buf line cmd rembuf)
  1894. (setq cmd (pop entry) line (pop entry))
  1895. (setq rembuf (nth 2 entry))
  1896. (org-with-remote-undo rembuf
  1897. (while (bufferp (setq buf (pop entry)))
  1898. (if (pop entry)
  1899. (with-current-buffer buf
  1900. (let ((last-undo-buffer buf)
  1901. (inhibit-read-only t))
  1902. (unless (memq buf org-agenda-undo-has-started-in)
  1903. (push buf org-agenda-undo-has-started-in)
  1904. (make-local-variable 'pending-undo-list)
  1905. (undo-start))
  1906. (while (and pending-undo-list
  1907. (listp pending-undo-list)
  1908. (not (car pending-undo-list)))
  1909. (pop pending-undo-list))
  1910. (undo-more 1))))))
  1911. (org-goto-line line)
  1912. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1913. (defun org-verify-change-for-undo (l1 l2)
  1914. "Verify that a real change occurred between the undo lists L1 and L2."
  1915. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1916. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1917. (not (eq l1 l2)))
  1918. ;;; Agenda dispatch
  1919. (defvar org-agenda-restrict nil)
  1920. (defvar org-agenda-restrict-begin (make-marker))
  1921. (defvar org-agenda-restrict-end (make-marker))
  1922. (defvar org-agenda-last-dispatch-buffer nil)
  1923. (defvar org-agenda-overriding-restriction nil)
  1924. ;;;###autoload
  1925. (defun org-agenda (&optional arg keys restriction)
  1926. "Dispatch agenda commands to collect entries to the agenda buffer.
  1927. Prompts for a command to execute. Any prefix arg will be passed
  1928. on to the selected command. The default selections are:
  1929. a Call `org-agenda-list' to display the agenda for current day or week.
  1930. t Call `org-todo-list' to display the global todo list.
  1931. T Call `org-todo-list' to display the global todo list, select only
  1932. entries with a specific TODO keyword (the user gets a prompt).
  1933. m Call `org-tags-view' to display headlines with tags matching
  1934. a condition (the user is prompted for the condition).
  1935. M Like `m', but select only TODO entries, no ordinary headlines.
  1936. L Create a timeline for the current buffer.
  1937. e Export views to associated files.
  1938. s Search entries for keywords.
  1939. / Multi occur across all agenda files and also files listed
  1940. in `org-agenda-text-search-extra-files'.
  1941. < Restrict agenda commands to buffer, subtree, or region.
  1942. Press several times to get the desired effect.
  1943. > Remove a previous restriction.
  1944. # List \"stuck\" projects.
  1945. ! Configure what \"stuck\" means.
  1946. C Configure custom agenda commands.
  1947. More commands can be added by configuring the variable
  1948. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1949. searches can be pre-defined in this way.
  1950. If the current buffer is in Org-mode and visiting a file, you can also
  1951. first press `<' once to indicate that the agenda should be temporarily
  1952. \(until the next use of \\[org-agenda]) restricted to the current file.
  1953. Pressing `<' twice means to restrict to the current subtree or region
  1954. \(if active)."
  1955. (interactive "P")
  1956. (catch 'exit
  1957. (let* ((prefix-descriptions nil)
  1958. (org-agenda-window-setup (if (equal (buffer-name)
  1959. org-agenda-buffer-name)
  1960. 'current-window
  1961. org-agenda-window-setup))
  1962. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1963. (org-agenda-custom-commands
  1964. ;; normalize different versions
  1965. (delq nil
  1966. (mapcar
  1967. (lambda (x)
  1968. (cond ((stringp (cdr x))
  1969. (push x prefix-descriptions)
  1970. nil)
  1971. ((stringp (nth 1 x)) x)
  1972. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1973. (t (cons (car x) (cons "" (cdr x))))))
  1974. org-agenda-custom-commands)))
  1975. (buf (current-buffer))
  1976. (bfn (buffer-file-name (buffer-base-buffer)))
  1977. entry key type match lprops ans)
  1978. ;; Turn off restriction unless there is an overriding one,
  1979. (unless org-agenda-overriding-restriction
  1980. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1981. ;; There is a request to keep the file list in place
  1982. (put 'org-agenda-files 'org-restrict nil))
  1983. (setq org-agenda-restrict nil)
  1984. (move-marker org-agenda-restrict-begin nil)
  1985. (move-marker org-agenda-restrict-end nil))
  1986. ;; Delete old local properties
  1987. (put 'org-agenda-redo-command 'org-lprops nil)
  1988. ;; Delete previously set last-arguments
  1989. (put 'org-agenda-redo-command 'last-args nil)
  1990. ;; Remember where this call originated
  1991. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1992. (unless keys
  1993. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1994. keys (car ans)
  1995. restriction (cdr ans)))
  1996. ;; Establish the restriction, if any
  1997. (when (and (not org-agenda-overriding-restriction) restriction)
  1998. (put 'org-agenda-files 'org-restrict (list bfn))
  1999. (cond
  2000. ((eq restriction 'region)
  2001. (setq org-agenda-restrict t)
  2002. (move-marker org-agenda-restrict-begin (region-beginning))
  2003. (move-marker org-agenda-restrict-end (region-end)))
  2004. ((eq restriction 'subtree)
  2005. (save-excursion
  2006. (setq org-agenda-restrict t)
  2007. (org-back-to-heading t)
  2008. (move-marker org-agenda-restrict-begin (point))
  2009. (move-marker org-agenda-restrict-end
  2010. (progn (org-end-of-subtree t)))))))
  2011. ;; For example the todo list should not need it (but does...)
  2012. (cond
  2013. ((setq entry (assoc keys org-agenda-custom-commands))
  2014. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2015. (progn
  2016. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2017. lprops (nth 4 entry))
  2018. (put 'org-agenda-redo-command 'org-lprops lprops)
  2019. (cond
  2020. ((eq type 'agenda)
  2021. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2022. ((eq type 'alltodo)
  2023. (org-let lprops '(org-todo-list current-prefix-arg)))
  2024. ((eq type 'search)
  2025. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2026. ((eq type 'stuck)
  2027. (org-let lprops '(org-agenda-list-stuck-projects
  2028. current-prefix-arg)))
  2029. ((eq type 'tags)
  2030. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2031. ((eq type 'tags-todo)
  2032. (org-let lprops '(org-tags-view '(4) match)))
  2033. ((eq type 'todo)
  2034. (org-let lprops '(org-todo-list match)))
  2035. ((eq type 'tags-tree)
  2036. (org-check-for-org-mode)
  2037. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2038. ((eq type 'todo-tree)
  2039. (org-check-for-org-mode)
  2040. (org-let lprops
  2041. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2042. (regexp-quote match) "\\>"))))
  2043. ((eq type 'occur-tree)
  2044. (org-check-for-org-mode)
  2045. (org-let lprops '(org-occur match)))
  2046. ((functionp type)
  2047. (org-let lprops '(funcall type match)))
  2048. ((fboundp type)
  2049. (org-let lprops '(funcall type match)))
  2050. (t (error "Invalid custom agenda command type %s" type))))
  2051. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2052. ((equal keys "C")
  2053. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2054. (customize-variable 'org-agenda-custom-commands))
  2055. ((equal keys "a") (call-interactively 'org-agenda-list))
  2056. ((equal keys "s") (call-interactively 'org-search-view))
  2057. ((equal keys "t") (call-interactively 'org-todo-list))
  2058. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2059. ((equal keys "m") (call-interactively 'org-tags-view))
  2060. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2061. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2062. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2063. (org-add-hook
  2064. 'post-command-hook
  2065. (lambda ()
  2066. (unless (current-message)
  2067. (let* ((m (org-agenda-get-any-marker))
  2068. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2069. (when note
  2070. (message (concat
  2071. "FLAGGING-NOTE ([?] for more info): "
  2072. (org-add-props
  2073. (replace-regexp-in-string
  2074. "\\\\n" "//"
  2075. (copy-sequence note))
  2076. nil 'face 'org-warning)))))))
  2077. t t))
  2078. ((equal keys "L")
  2079. (unless (org-mode-p)
  2080. (error "This is not an Org-mode file"))
  2081. (unless restriction
  2082. (put 'org-agenda-files 'org-restrict (list bfn))
  2083. (org-call-with-arg 'org-timeline arg)))
  2084. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2085. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2086. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2087. (t (error "Invalid agenda key"))))))
  2088. (defun org-agenda-append-agenda ()
  2089. "Append another agenda view to the current one.
  2090. This function allows interactive building of block agendas.
  2091. Agenda views are separated by `org-agenda-block-separator'."
  2092. (interactive)
  2093. (unless (string= (buffer-name) org-agenda-buffer-name)
  2094. (error "Can only append from within agenda buffer"))
  2095. (let ((org-agenda-multi t))
  2096. (org-agenda)
  2097. (widen)))
  2098. (defun org-agenda-normalize-custom-commands (cmds)
  2099. (delq nil
  2100. (mapcar
  2101. (lambda (x)
  2102. (cond ((stringp (cdr x)) nil)
  2103. ((stringp (nth 1 x)) x)
  2104. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2105. (t (cons (car x) (cons "" (cdr x))))))
  2106. cmds)))
  2107. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2108. "The user interface for selecting an agenda command."
  2109. (catch 'exit
  2110. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2111. (restrict-ok (and bfn (org-mode-p)))
  2112. (region-p (org-region-active-p))
  2113. (custom org-agenda-custom-commands)
  2114. (selstring "")
  2115. restriction second-time
  2116. c entry key type match prefixes rmheader header-end custom1 desc
  2117. line lines left right n n1)
  2118. (save-window-excursion
  2119. (delete-other-windows)
  2120. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2121. (erase-buffer)
  2122. (insert (eval-when-compile
  2123. (let ((header
  2124. "
  2125. Press key for an agenda command: < Buffer, subtree/region restriction
  2126. -------------------------------- > Remove restriction
  2127. a Agenda for current week or day e Export agenda views
  2128. t List of all TODO entries T Entries with special TODO kwd
  2129. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2130. L Timeline for current buffer # List stuck projects (!=configure)
  2131. s Search for keywords C Configure custom agenda commands
  2132. / Multi-occur ? Find :FLAGGED: entries
  2133. ")
  2134. (start 0))
  2135. (while (string-match
  2136. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2137. header start)
  2138. (setq start (match-end 0))
  2139. (add-text-properties (match-beginning 2) (match-end 2)
  2140. '(face bold) header))
  2141. header)))
  2142. (setq header-end (move-marker (make-marker) (point)))
  2143. (while t
  2144. (setq custom1 custom)
  2145. (when (eq rmheader t)
  2146. (org-goto-line 1)
  2147. (re-search-forward ":" nil t)
  2148. (delete-region (match-end 0) (point-at-eol))
  2149. (forward-char 1)
  2150. (looking-at "-+")
  2151. (delete-region (match-end 0) (point-at-eol))
  2152. (move-marker header-end (match-end 0)))
  2153. (goto-char header-end)
  2154. (delete-region (point) (point-max))
  2155. ;; Produce all the lines that describe custom commands and prefixes
  2156. (setq lines nil)
  2157. (while (setq entry (pop custom1))
  2158. (setq key (car entry) desc (nth 1 entry)
  2159. type (nth 2 entry)
  2160. match (nth 3 entry))
  2161. (if (> (length key) 1)
  2162. (add-to-list 'prefixes (string-to-char key))
  2163. (setq line
  2164. (format
  2165. "%-4s%-14s"
  2166. (org-add-props (copy-sequence key)
  2167. '(face bold))
  2168. (cond
  2169. ((string-match "\\S-" desc) desc)
  2170. ((eq type 'agenda) "Agenda for current week or day")
  2171. ((eq type 'alltodo) "List of all TODO entries")
  2172. ((eq type 'search) "Word search")
  2173. ((eq type 'stuck) "List of stuck projects")
  2174. ((eq type 'todo) "TODO keyword")
  2175. ((eq type 'tags) "Tags query")
  2176. ((eq type 'tags-todo) "Tags (TODO)")
  2177. ((eq type 'tags-tree) "Tags tree")
  2178. ((eq type 'todo-tree) "TODO kwd tree")
  2179. ((eq type 'occur-tree) "Occur tree")
  2180. ((functionp type) (if (symbolp type)
  2181. (symbol-name type)
  2182. "Lambda expression"))
  2183. (t "???"))))
  2184. (if org-agenda-menu-show-matcher
  2185. (setq line
  2186. (concat line ": "
  2187. (cond
  2188. ((stringp match)
  2189. (setq match (copy-sequence match))
  2190. (org-add-props match nil 'face 'org-warning))
  2191. (match
  2192. (format "set of %d commands" (length match)))
  2193. (t ""))))
  2194. (if (org-string-nw-p match)
  2195. (add-text-properties
  2196. 0 (length line) (list 'help-echo
  2197. (concat "Matcher: "match)) line)))
  2198. (push line lines)))
  2199. (setq lines (nreverse lines))
  2200. (when prefixes
  2201. (mapc (lambda (x)
  2202. (push
  2203. (format "%s %s"
  2204. (org-add-props (char-to-string x)
  2205. nil 'face 'bold)
  2206. (or (cdr (assoc (concat selstring
  2207. (char-to-string x))
  2208. prefix-descriptions))
  2209. "Prefix key"))
  2210. lines))
  2211. prefixes))
  2212. ;; Check if we should display in two columns
  2213. (if org-agenda-menu-two-column
  2214. (progn
  2215. (setq n (length lines)
  2216. n1 (+ (/ n 2) (mod n 2))
  2217. right (nthcdr n1 lines)
  2218. left (copy-sequence lines))
  2219. (setcdr (nthcdr (1- n1) left) nil))
  2220. (setq left lines right nil))
  2221. (while left
  2222. (insert "\n" (pop left))
  2223. (when right
  2224. (if (< (current-column) 40)
  2225. (move-to-column 40 t)
  2226. (insert " "))
  2227. (insert (pop right))))
  2228. ;; Make the window the right size
  2229. (goto-char (point-min))
  2230. (if second-time
  2231. (if (not (pos-visible-in-window-p (point-max)))
  2232. (org-fit-window-to-buffer))
  2233. (setq second-time t)
  2234. (org-fit-window-to-buffer))
  2235. ;; Ask for selection
  2236. (message "Press key for agenda command%s:"
  2237. (if (or restrict-ok org-agenda-overriding-restriction)
  2238. (if org-agenda-overriding-restriction
  2239. " (restriction lock active)"
  2240. (if restriction
  2241. (format " (restricted to %s)" restriction)
  2242. " (unrestricted)"))
  2243. ""))
  2244. (setq c (read-char-exclusive))
  2245. (message "")
  2246. (cond
  2247. ((assoc (char-to-string c) custom)
  2248. (setq selstring (concat selstring (char-to-string c)))
  2249. (throw 'exit (cons selstring restriction)))
  2250. ((memq c prefixes)
  2251. (setq selstring (concat selstring (char-to-string c))
  2252. prefixes nil
  2253. rmheader (or rmheader t)
  2254. custom (delq nil (mapcar
  2255. (lambda (x)
  2256. (if (or (= (length (car x)) 1)
  2257. (/= (string-to-char (car x)) c))
  2258. nil
  2259. (cons (substring (car x) 1) (cdr x))))
  2260. custom))))
  2261. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2262. (message "Restriction is only possible in Org-mode buffers")
  2263. (ding) (sit-for 1))
  2264. ((eq c ?1)
  2265. (org-agenda-remove-restriction-lock 'noupdate)
  2266. (setq restriction 'buffer))
  2267. ((eq c ?0)
  2268. (org-agenda-remove-restriction-lock 'noupdate)
  2269. (setq restriction (if region-p 'region 'subtree)))
  2270. ((eq c ?<)
  2271. (org-agenda-remove-restriction-lock 'noupdate)
  2272. (setq restriction
  2273. (cond
  2274. ((eq restriction 'buffer)
  2275. (if region-p 'region 'subtree))
  2276. ((memq restriction '(subtree region))
  2277. nil)
  2278. (t 'buffer))))
  2279. ((eq c ?>)
  2280. (org-agenda-remove-restriction-lock 'noupdate)
  2281. (setq restriction nil))
  2282. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2283. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2284. ((and (> (length selstring) 0) (eq c ?\d))
  2285. (delete-window)
  2286. (org-agenda-get-restriction-and-command prefix-descriptions))
  2287. ((equal c ?q) (error "Abort"))
  2288. (t (error "Invalid key %c" c))))))))
  2289. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2290. (defvar org-agenda-last-arguments nil
  2291. "The arguments of the previous call to `org-agenda'.")
  2292. (defun org-agenda-run-series (name series)
  2293. (org-let (nth 1 series) '(org-prepare-agenda name))
  2294. (let* ((org-agenda-multi t)
  2295. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2296. (org-agenda-overriding-arguments
  2297. (or org-agenda-overriding-arguments
  2298. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2299. (get 'org-agenda-redo-command 'last-args))))
  2300. (cmds (car series))
  2301. (gprops (nth 1 series))
  2302. match ;; The byte compiler incorrectly complains about this. Keep it!
  2303. cmd type lprops)
  2304. (while (setq cmd (pop cmds))
  2305. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2306. (cond
  2307. ((eq type 'agenda)
  2308. (org-let2 gprops lprops
  2309. '(call-interactively 'org-agenda-list)))
  2310. ((eq type 'alltodo)
  2311. (org-let2 gprops lprops
  2312. '(call-interactively 'org-todo-list)))
  2313. ((eq type 'search)
  2314. (org-let2 gprops lprops
  2315. '(org-search-view current-prefix-arg match nil)))
  2316. ((eq type 'stuck)
  2317. (org-let2 gprops lprops
  2318. '(call-interactively 'org-agenda-list-stuck-projects)))
  2319. ((eq type 'tags)
  2320. (org-let2 gprops lprops
  2321. '(org-tags-view current-prefix-arg match)))
  2322. ((eq type 'tags-todo)
  2323. (org-let2 gprops lprops
  2324. '(org-tags-view '(4) match)))
  2325. ((eq type 'todo)
  2326. (org-let2 gprops lprops
  2327. '(org-todo-list match)))
  2328. ((fboundp type)
  2329. (org-let2 gprops lprops
  2330. '(funcall type match)))
  2331. (t (error "Invalid type in command series"))))
  2332. (widen)
  2333. (setq org-agenda-redo-command redo)
  2334. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2335. (goto-char (point-min)))
  2336. (org-fit-agenda-window)
  2337. (org-let (nth 1 series) '(org-finalize-agenda)))
  2338. ;;;###autoload
  2339. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2340. "Run an agenda command in batch mode and send the result to STDOUT.
  2341. If CMD-KEY is a string of length 1, it is used as a key in
  2342. `org-agenda-custom-commands' and triggers this command. If it is a
  2343. longer string it is used as a tags/todo match string.
  2344. Parameters are alternating variable names and values that will be bound
  2345. before running the agenda command."
  2346. (org-eval-in-environment (org-make-parameter-alist parameters)
  2347. (if (> (length cmd-key) 2)
  2348. (org-tags-view nil cmd-key)
  2349. (org-agenda nil cmd-key)))
  2350. (set-buffer org-agenda-buffer-name)
  2351. (princ (org-encode-for-stdout (buffer-string))))
  2352. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2353. ;(defun org-encode-for-stdout (string)
  2354. ; (if (fboundp 'encode-coding-string)
  2355. ; (encode-coding-string string buffer-file-coding-system)
  2356. ; string))
  2357. (defun org-encode-for-stdout (string)
  2358. string)
  2359. (defvar org-agenda-info nil)
  2360. ;;;###autoload
  2361. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2362. "Run an agenda command in batch mode and send the result to STDOUT.
  2363. If CMD-KEY is a string of length 1, it is used as a key in
  2364. `org-agenda-custom-commands' and triggers this command. If it is a
  2365. longer string it is used as a tags/todo match string.
  2366. Parameters are alternating variable names and values that will be bound
  2367. before running the agenda command.
  2368. The output gives a line for each selected agenda item. Each
  2369. item is a list of comma-separated values, like this:
  2370. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2371. category The category of the item
  2372. head The headline, without TODO kwd, TAGS and PRIORITY
  2373. type The type of the agenda entry, can be
  2374. todo selected in TODO match
  2375. tagsmatch selected in tags match
  2376. diary imported from diary
  2377. deadline a deadline on given date
  2378. scheduled scheduled on given date
  2379. timestamp entry has timestamp on given date
  2380. closed entry was closed on given date
  2381. upcoming-deadline warning about deadline
  2382. past-scheduled forwarded scheduled item
  2383. block entry has date block including g. date
  2384. todo The todo keyword, if any
  2385. tags All tags including inherited ones, separated by colons
  2386. date The relevant date, like 2007-2-14
  2387. time The time, like 15:00-16:50
  2388. extra Sting with extra planning info
  2389. priority-l The priority letter if any was given
  2390. priority-n The computed numerical priority
  2391. agenda-day The day in the agenda where this is listed"
  2392. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2393. (org-make-parameter-alist parameters))
  2394. (if (> (length cmd-key) 2)
  2395. (org-tags-view nil cmd-key)
  2396. (org-agenda nil cmd-key)))
  2397. (set-buffer org-agenda-buffer-name)
  2398. (let* ((lines (org-split-string (buffer-string) "\n"))
  2399. line)
  2400. (while (setq line (pop lines))
  2401. (catch 'next
  2402. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2403. (setq org-agenda-info
  2404. (org-fix-agenda-info (text-properties-at 0 line)))
  2405. (princ
  2406. (org-encode-for-stdout
  2407. (mapconcat 'org-agenda-export-csv-mapper
  2408. '(org-category txt type todo tags date time extra
  2409. priority-letter priority agenda-day)
  2410. ",")))
  2411. (princ "\n")))))
  2412. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2413. (defun org-fix-agenda-info (props)
  2414. "Make sure all properties on an agenda item have a canonical form.
  2415. This ensures the export commands can easily use it."
  2416. (let (tmp re)
  2417. (when (setq tmp (plist-get props 'tags))
  2418. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2419. (when (setq tmp (plist-get props 'date))
  2420. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2421. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2422. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2423. (setq tmp (calendar-date-string tmp)))
  2424. (setq props (plist-put props 'date tmp)))
  2425. (when (setq tmp (plist-get props 'day))
  2426. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2427. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2428. (setq tmp (calendar-date-string tmp)))
  2429. (setq props (plist-put props 'day tmp))
  2430. (setq props (plist-put props 'agenda-day tmp)))
  2431. (when (setq tmp (plist-get props 'txt))
  2432. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2433. (plist-put props 'priority-letter (match-string 1 tmp))
  2434. (setq tmp (replace-match "" t t tmp)))
  2435. (when (and (setq re (plist-get props 'org-todo-regexp))
  2436. (setq re (concat "\\`\\.*" re " ?"))
  2437. (string-match re tmp))
  2438. (plist-put props 'todo (match-string 1 tmp))
  2439. (setq tmp (replace-match "" t t tmp)))
  2440. (plist-put props 'txt tmp)))
  2441. props)
  2442. (defun org-agenda-export-csv-mapper (prop)
  2443. (let ((res (plist-get org-agenda-info prop)))
  2444. (setq res
  2445. (cond
  2446. ((not res) "")
  2447. ((stringp res) res)
  2448. (t (prin1-to-string res))))
  2449. (while (string-match "," res)
  2450. (setq res (replace-match ";" t t res)))
  2451. (org-trim res)))
  2452. ;;;###autoload
  2453. (defun org-store-agenda-views (&rest parameters)
  2454. (interactive)
  2455. (eval (list 'org-batch-store-agenda-views)))
  2456. ;;;###autoload
  2457. (defmacro org-batch-store-agenda-views (&rest parameters)
  2458. "Run all custom agenda commands that have a file argument."
  2459. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2460. (pop-up-frames nil)
  2461. (dir default-directory)
  2462. (pars (org-make-parameter-alist parameters))
  2463. cmd thiscmdkey files opts cmd-or-set)
  2464. (save-window-excursion
  2465. (while cmds
  2466. (setq cmd (pop cmds)
  2467. thiscmdkey (car cmd)
  2468. cmd-or-set (nth 2 cmd)
  2469. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2470. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2471. (if (stringp files) (setq files (list files)))
  2472. (when files
  2473. (org-eval-in-environment (append org-agenda-exporter-settings
  2474. opts pars)
  2475. (org-agenda nil thiscmdkey))
  2476. (set-buffer org-agenda-buffer-name)
  2477. (while files
  2478. (org-eval-in-environment (append org-agenda-exporter-settings
  2479. opts pars)
  2480. (org-write-agenda (expand-file-name (pop files) dir) nil t)))
  2481. (and (get-buffer org-agenda-buffer-name)
  2482. (kill-buffer org-agenda-buffer-name)))))))
  2483. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2484. (defun org-agenda-mark-header-line (pos)
  2485. "Mark the line at POS as an agenda structure header."
  2486. (save-excursion
  2487. (goto-char pos)
  2488. (put-text-property (point-at-bol) (point-at-eol)
  2489. 'org-agenda-structural-header t)
  2490. (when org-agenda-title-append
  2491. (put-text-property (point-at-bol) (point-at-eol)
  2492. 'org-agenda-title-append org-agenda-title-append))))
  2493. (defvar org-mobile-creating-agendas)
  2494. (defun org-write-agenda (file &optional open nosettings)
  2495. "Write the current buffer (an agenda view) as a file.
  2496. Depending on the extension of the file name, plain text (.txt),
  2497. HTML (.html or .htm) or Postscript (.ps) is produced.
  2498. If the extension is .ics, run icalendar export over all files used
  2499. to construct the agenda and limit the export to entries listed in the
  2500. agenda now.
  2501. With prefix argument OPEN, open the new file immediately.
  2502. If NOSETTINGS is given, do not scope the settings of
  2503. `org-agenda-exporter-settings' into the export commands. This is used when
  2504. the settings have already been scoped and we do not wish to overrule other,
  2505. higher priority settings."
  2506. (interactive "FWrite agenda to file: \nP")
  2507. (if (not (file-writable-p file))
  2508. (error "Cannot write agenda to file %s" file))
  2509. (org-let (if nosettings nil org-agenda-exporter-settings)
  2510. '(save-excursion
  2511. (save-window-excursion
  2512. (org-agenda-mark-filtered-text)
  2513. (let ((bs (copy-sequence (buffer-string))) beg)
  2514. (org-agenda-unmark-filtered-text)
  2515. (with-temp-buffer
  2516. (rename-buffer "Agenda View" t)
  2517. (set-buffer-modified-p nil)
  2518. (insert bs)
  2519. (org-agenda-remove-marked-text 'org-filtered)
  2520. (while (setq beg (text-property-any (point-min) (point-max)
  2521. 'org-filtered t))
  2522. (delete-region
  2523. beg (or (next-single-property-change beg 'org-filtered)
  2524. (point-max))))
  2525. (run-hooks 'org-agenda-before-write-hook)
  2526. (cond
  2527. ((org-bound-and-true-p org-mobile-creating-agendas)
  2528. (org-mobile-write-agenda-for-mobile file))
  2529. ((string-match "\\.html?\\'" file)
  2530. (require 'htmlize)
  2531. (set-buffer (htmlize-buffer (current-buffer)))
  2532. (when (and org-agenda-export-html-style
  2533. (string-match "<style>" org-agenda-export-html-style))
  2534. ;; replace <style> section with org-agenda-export-html-style
  2535. (goto-char (point-min))
  2536. (kill-region (- (search-forward "<style") 6)
  2537. (search-forward "</style>"))
  2538. (insert org-agenda-export-html-style))
  2539. (write-file file)
  2540. (kill-buffer (current-buffer))
  2541. (message "HTML written to %s" file))
  2542. ((string-match "\\.ps\\'" file)
  2543. (require 'ps-print)
  2544. (ps-print-buffer-with-faces file)
  2545. (message "Postscript written to %s" file))
  2546. ((string-match "\\.pdf\\'" file)
  2547. (require 'ps-print)
  2548. (ps-print-buffer-with-faces
  2549. (concat (file-name-sans-extension file) ".ps"))
  2550. (call-process "ps2pdf" nil nil nil
  2551. (expand-file-name
  2552. (concat (file-name-sans-extension file) ".ps"))
  2553. (expand-file-name file))
  2554. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2555. (message "PDF written to %s" file))
  2556. ((string-match "\\.ics\\'" file)
  2557. (require 'org-icalendar)
  2558. (let ((org-agenda-marker-table
  2559. (org-create-marker-find-array
  2560. (org-agenda-collect-markers)))
  2561. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2562. (org-combined-agenda-icalendar-file file))
  2563. (apply 'org-export-icalendar 'combine
  2564. (org-agenda-files nil 'ifmode))))
  2565. (t
  2566. (let ((bs (buffer-string)))
  2567. (find-file file)
  2568. (erase-buffer)
  2569. (insert bs)
  2570. (save-buffer 0)
  2571. (kill-buffer (current-buffer))
  2572. (message "Plain text written to %s" file))))))))
  2573. (set-buffer org-agenda-buffer-name))
  2574. (when open (org-open-file file)))
  2575. (defvar org-agenda-filter-overlays nil)
  2576. (defun org-agenda-mark-filtered-text ()
  2577. "Mark all text hidden by filtering with a text property."
  2578. (let ((inhibit-read-only t))
  2579. (mapc
  2580. (lambda (o)
  2581. (when (equal (overlay-buffer o) (current-buffer))
  2582. (put-text-property
  2583. (overlay-start o) (overlay-end o)
  2584. 'org-filtered t)))
  2585. org-agenda-filter-overlays)))
  2586. (defun org-agenda-unmark-filtered-text ()
  2587. "Remove the filtering text property."
  2588. (let ((inhibit-read-only t))
  2589. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2590. (defun org-agenda-remove-marked-text (property &optional value)
  2591. "Delete all text marked with VALUE of PROPERTY.
  2592. VALUE defaults to t."
  2593. (let (beg)
  2594. (setq value (or value t))
  2595. (while (setq beg (text-property-any (point-min) (point-max)
  2596. property value))
  2597. (delete-region
  2598. beg (or (next-single-property-change beg 'org-filtered)
  2599. (point-max))))))
  2600. (defun org-agenda-add-entry-text ()
  2601. "Add entry text to agenda lines.
  2602. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2603. entry text following headings shown in the agenda.
  2604. Drawers will be excluded, also the line with scheduling/deadline info."
  2605. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2606. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2607. (let (m txt)
  2608. (goto-char (point-min))
  2609. (while (not (eobp))
  2610. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2611. (beginning-of-line 2)
  2612. (setq txt (org-agenda-get-some-entry-text
  2613. m org-agenda-add-entry-text-maxlines " > "))
  2614. (end-of-line 1)
  2615. (if (string-match "\\S-" txt)
  2616. (insert "\n" txt)
  2617. (or (eobp) (forward-char 1))))))))
  2618. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2619. &rest keep)
  2620. "Extract entry text from MARKER, at most N-LINES lines.
  2621. This will ignore drawers etc, just get the text.
  2622. If INDENT is given, prefix every line with this string. If KEEP is
  2623. given, it is a list of symbols, defining stuff that should not be
  2624. removed from the entry content. Currently only `planning' is allowed here."
  2625. (let (txt drawer-re kwd-time-re ind)
  2626. (save-excursion
  2627. (with-current-buffer (marker-buffer marker)
  2628. (if (not (org-mode-p))
  2629. (setq txt "")
  2630. (save-excursion
  2631. (save-restriction
  2632. (widen)
  2633. (goto-char marker)
  2634. (end-of-line 1)
  2635. (setq txt (buffer-substring
  2636. (min (1+ (point)) (point-max))
  2637. (progn (outline-next-heading) (point)))
  2638. drawer-re org-drawer-regexp
  2639. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2640. ".*\n?"))
  2641. (with-temp-buffer
  2642. (insert txt)
  2643. (when org-agenda-add-entry-text-descriptive-links
  2644. (goto-char (point-min))
  2645. (while (org-activate-bracket-links (point-max))
  2646. (add-text-properties (match-beginning 0) (match-end 0)
  2647. '(face org-link))))
  2648. (goto-char (point-min))
  2649. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2650. (set-text-properties (match-beginning 0) (match-end 0)
  2651. nil))
  2652. (goto-char (point-min))
  2653. (while (re-search-forward drawer-re nil t)
  2654. (delete-region
  2655. (match-beginning 0)
  2656. (progn (re-search-forward
  2657. "^[ \t]*:END:.*\n?" nil 'move)
  2658. (point))))
  2659. (unless (member 'planning keep)
  2660. (goto-char (point-min))
  2661. (while (re-search-forward kwd-time-re nil t)
  2662. (replace-match "")))
  2663. (goto-char (point-min))
  2664. (when org-agenda-entry-text-exclude-regexps
  2665. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2666. (while (setq re (pop re-list))
  2667. (goto-char (point-min))
  2668. (while (re-search-forward re nil t)
  2669. (replace-match "")))))
  2670. (goto-char (point-max))
  2671. (skip-chars-backward " \t\n")
  2672. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2673. ;; find and remove min common indentation
  2674. (goto-char (point-min))
  2675. (untabify (point-min) (point-max))
  2676. (setq ind (org-get-indentation))
  2677. (while (not (eobp))
  2678. (unless (looking-at "[ \t]*$")
  2679. (setq ind (min ind (org-get-indentation))))
  2680. (beginning-of-line 2))
  2681. (goto-char (point-min))
  2682. (while (not (eobp))
  2683. (unless (looking-at "[ \t]*$")
  2684. (move-to-column ind)
  2685. (delete-region (point-at-bol) (point)))
  2686. (beginning-of-line 2))
  2687. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2688. (goto-char (point-min))
  2689. (when indent
  2690. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2691. (replace-match indent t t)))
  2692. (goto-char (point-min))
  2693. (while (looking-at "[ \t]*\n") (replace-match ""))
  2694. (goto-char (point-max))
  2695. (when (> (org-current-line)
  2696. n-lines)
  2697. (org-goto-line (1+ n-lines))
  2698. (backward-char 1))
  2699. (setq txt (buffer-substring (point-min) (point)))))))))
  2700. txt))
  2701. (defun org-agenda-collect-markers ()
  2702. "Collect the markers pointing to entries in the agenda buffer."
  2703. (let (m markers)
  2704. (save-excursion
  2705. (goto-char (point-min))
  2706. (while (not (eobp))
  2707. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2708. (org-get-at-bol 'org-marker)))
  2709. (push m markers))
  2710. (beginning-of-line 2)))
  2711. (nreverse markers)))
  2712. (defun org-create-marker-find-array (marker-list)
  2713. "Create a alist of files names with all marker positions in that file."
  2714. (let (f tbl m a p)
  2715. (while (setq m (pop marker-list))
  2716. (setq p (marker-position m)
  2717. f (buffer-file-name (or (buffer-base-buffer
  2718. (marker-buffer m))
  2719. (marker-buffer m))))
  2720. (if (setq a (assoc f tbl))
  2721. (push (marker-position m) (cdr a))
  2722. (push (list f p) tbl)))
  2723. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2724. tbl)))
  2725. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2726. (defun org-check-agenda-marker-table ()
  2727. "Check of the current entry is on the marker list."
  2728. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2729. a)
  2730. (and (setq a (assoc file org-agenda-marker-table))
  2731. (save-match-data
  2732. (save-excursion
  2733. (org-back-to-heading t)
  2734. (member (point) (cdr a)))))))
  2735. (defun org-check-for-org-mode ()
  2736. "Make sure current buffer is in org-mode. Error if not."
  2737. (or (org-mode-p)
  2738. (error "Cannot execute org-mode agenda command on buffer in %s"
  2739. major-mode)))
  2740. (defun org-fit-agenda-window ()
  2741. "Fit the window to the buffer size."
  2742. (and (memq org-agenda-window-setup '(reorganize-frame))
  2743. (fboundp 'fit-window-to-buffer)
  2744. (org-fit-window-to-buffer
  2745. nil
  2746. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2747. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2748. ;;; Agenda prepare and finalize
  2749. (defvar org-agenda-multi nil) ; dynamically scoped
  2750. (defvar org-agenda-buffer-name "*Org Agenda*")
  2751. (defvar org-pre-agenda-window-conf nil)
  2752. (defvar org-agenda-columns-active nil)
  2753. (defvar org-agenda-name nil)
  2754. (defvar org-agenda-filter nil)
  2755. (defvar org-agenda-filter-while-redo nil)
  2756. (defvar org-agenda-filter-preset nil
  2757. "A preset of the tags filter used for secondary agenda filtering.
  2758. This must be a list of strings, each string must be a single tag preceded
  2759. by \"+\" or \"-\".
  2760. This variable should not be set directly, but agenda custom commands can
  2761. bind it in the options section. The preset filter is a global property of
  2762. the entire agenda view. In a block agenda, it will not work reliably to
  2763. define a filter for one of the individual blocks. You need to set it in
  2764. the global options and expect it to be applied to the entire view.")
  2765. (defun org-prepare-agenda (&optional name)
  2766. (setq org-todo-keywords-for-agenda nil)
  2767. (setq org-done-keywords-for-agenda nil)
  2768. (setq org-drawers-for-agenda nil)
  2769. (unless org-agenda-persistent-filter
  2770. (setq org-agenda-filter nil))
  2771. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2772. (if org-agenda-multi
  2773. (progn
  2774. (setq buffer-read-only nil)
  2775. (goto-char (point-max))
  2776. (unless (or (bobp) org-agenda-compact-blocks
  2777. (not org-agenda-block-separator))
  2778. (insert "\n"
  2779. (if (stringp org-agenda-block-separator)
  2780. org-agenda-block-separator
  2781. (make-string (window-width) org-agenda-block-separator))
  2782. "\n"))
  2783. (narrow-to-region (point) (point-max)))
  2784. (org-agenda-reset-markers)
  2785. (setq org-agenda-contributing-files nil)
  2786. (setq org-agenda-columns-active nil)
  2787. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2788. (setq org-todo-keywords-for-agenda
  2789. (org-uniquify org-todo-keywords-for-agenda))
  2790. (setq org-done-keywords-for-agenda
  2791. (org-uniquify org-done-keywords-for-agenda))
  2792. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2793. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2794. (awin (get-buffer-window abuf)))
  2795. (cond
  2796. ((equal (current-buffer) abuf) nil)
  2797. (awin (select-window awin))
  2798. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2799. ((equal org-agenda-window-setup 'current-window)
  2800. (org-pop-to-buffer-same-window abuf))
  2801. ((equal org-agenda-window-setup 'other-window)
  2802. (org-switch-to-buffer-other-window abuf))
  2803. ((equal org-agenda-window-setup 'other-frame)
  2804. (switch-to-buffer-other-frame abuf))
  2805. ((equal org-agenda-window-setup 'reorganize-frame)
  2806. (delete-other-windows)
  2807. (org-switch-to-buffer-other-window abuf)))
  2808. ;; additional test in case agenda is invoked from within agenda
  2809. ;; buffer via elisp link
  2810. (unless (equal (current-buffer) abuf)
  2811. (org-pop-to-buffer-same-window abuf)))
  2812. (setq buffer-read-only nil)
  2813. (let ((inhibit-read-only t)) (erase-buffer))
  2814. (org-agenda-mode)
  2815. (and name (not org-agenda-name)
  2816. (org-set-local 'org-agenda-name name)))
  2817. (setq buffer-read-only nil))
  2818. (defun org-finalize-agenda ()
  2819. "Finishing touch for the agenda buffer, called just before displaying it."
  2820. (unless org-agenda-multi
  2821. (save-excursion
  2822. (let ((inhibit-read-only t))
  2823. (goto-char (point-min))
  2824. (while (org-activate-bracket-links (point-max))
  2825. (add-text-properties (match-beginning 0) (match-end 0)
  2826. '(face org-link)))
  2827. (org-agenda-align-tags)
  2828. (unless org-agenda-with-colors
  2829. (remove-text-properties (point-min) (point-max) '(face nil))))
  2830. (if (and (boundp 'org-agenda-overriding-columns-format)
  2831. org-agenda-overriding-columns-format)
  2832. (org-set-local 'org-agenda-overriding-columns-format
  2833. org-agenda-overriding-columns-format))
  2834. (if (and (boundp 'org-agenda-view-columns-initially)
  2835. org-agenda-view-columns-initially)
  2836. (org-agenda-columns))
  2837. (when org-agenda-fontify-priorities
  2838. (org-agenda-fontify-priorities))
  2839. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2840. (org-agenda-dim-blocked-tasks))
  2841. (org-agenda-mark-clocking-task)
  2842. (when org-agenda-entry-text-mode
  2843. (org-agenda-entry-text-hide)
  2844. (org-agenda-entry-text-show))
  2845. (if (functionp 'org-habit-insert-consistency-graphs)
  2846. (org-habit-insert-consistency-graphs))
  2847. (run-hooks 'org-finalize-agenda-hook)
  2848. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2849. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2850. (org-agenda-filter-apply org-agenda-filter))
  2851. )))
  2852. (defun org-agenda-mark-clocking-task ()
  2853. "Mark the current clock entry in the agenda if it is present."
  2854. (mapc (lambda (o)
  2855. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2856. (delete-overlay o)))
  2857. (overlays-in (point-min) (point-max)))
  2858. (when (marker-buffer org-clock-hd-marker)
  2859. (save-excursion
  2860. (goto-char (point-min))
  2861. (let (s ov)
  2862. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2863. (goto-char s)
  2864. (when (equal (org-get-at-bol 'org-hd-marker)
  2865. org-clock-hd-marker)
  2866. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2867. (overlay-put ov 'type 'org-agenda-clocking)
  2868. (overlay-put ov 'face 'org-agenda-clocking)
  2869. (overlay-put ov 'help-echo
  2870. "The clock is running in this item")))))))
  2871. (defun org-agenda-fontify-priorities ()
  2872. "Make highest priority lines bold, and lowest italic."
  2873. (interactive)
  2874. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2875. (delete-overlay o)))
  2876. (overlays-in (point-min) (point-max)))
  2877. (save-excursion
  2878. (let ((inhibit-read-only t)
  2879. b e p ov h l)
  2880. (goto-char (point-min))
  2881. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2882. (setq h (or (get-char-property (point) 'org-highest-priority)
  2883. org-highest-priority)
  2884. l (or (get-char-property (point) 'org-lowest-priority)
  2885. org-lowest-priority)
  2886. p (string-to-char (match-string 1))
  2887. b (match-beginning 0)
  2888. e (if (eq org-agenda-fontify-priorities 'cookies)
  2889. (match-end 0)
  2890. (point-at-eol))
  2891. ov (make-overlay b e))
  2892. (overlay-put
  2893. ov 'face
  2894. (cond ((org-face-from-face-or-color
  2895. 'priority nil
  2896. (cdr (assoc p org-priority-faces))))
  2897. ((and (listp org-agenda-fontify-priorities)
  2898. (org-face-from-face-or-color
  2899. 'priority nil
  2900. (cdr (assoc p org-agenda-fontify-priorities)))))
  2901. ((equal p l) 'italic)
  2902. ((equal p h) 'bold)))
  2903. (overlay-put ov 'org-type 'org-priority)))))
  2904. (defun org-agenda-dim-blocked-tasks ()
  2905. "Dim currently blocked TODO's in the agenda display."
  2906. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2907. (delete-overlay o)))
  2908. (overlays-in (point-min) (point-max)))
  2909. (save-excursion
  2910. (let ((inhibit-read-only t)
  2911. (org-depend-tag-blocked nil)
  2912. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2913. org-blocked-by-checkboxes
  2914. invis1 b e p ov h l)
  2915. (goto-char (point-min))
  2916. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2917. (and pos (goto-char (1+ pos))))
  2918. (setq org-blocked-by-checkboxes nil invis1 invis)
  2919. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2920. (when (and marker
  2921. (not (with-current-buffer (marker-buffer marker)
  2922. (save-excursion
  2923. (goto-char marker)
  2924. (if (org-entry-get nil "NOBLOCKING")
  2925. t ;; Never block this entry
  2926. (run-hook-with-args-until-failure
  2927. 'org-blocker-hook
  2928. (list :type 'todo-state-change
  2929. :position marker
  2930. :from 'todo
  2931. :to 'done)))))))
  2932. (if org-blocked-by-checkboxes (setq invis1 nil))
  2933. (setq b (if invis1
  2934. (max (point-min) (1- (point-at-bol)))
  2935. (point-at-bol))
  2936. e (point-at-eol)
  2937. ov (make-overlay b e))
  2938. (if invis1
  2939. (overlay-put ov 'invisible t)
  2940. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2941. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2942. (defvar org-agenda-skip-function nil
  2943. "Function to be called at each match during agenda construction.
  2944. If this function returns nil, the current match should not be skipped.
  2945. Otherwise, the function must return a position from where the search
  2946. should be continued.
  2947. This may also be a Lisp form, it will be evaluated.
  2948. Never set this variable using `setq' or so, because then it will apply
  2949. to all future agenda commands. If you do want a global skipping condition,
  2950. use the option `org-agenda-skip-function-global' instead.
  2951. The correct usage for `org-agenda-skip-function' is to bind it with
  2952. `let' to scope it dynamically into the agenda-constructing command.
  2953. A good way to set it is through options in `org-agenda-custom-commands'.")
  2954. (defun org-agenda-skip ()
  2955. "Throw to `:skip' in places that should be skipped.
  2956. Also moves point to the end of the skipped region, so that search can
  2957. continue from there."
  2958. (let ((p (point-at-bol)) to)
  2959. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2960. (get-text-property p :org-archived)
  2961. (org-end-of-subtree t)
  2962. (throw :skip t))
  2963. (and org-agenda-skip-comment-trees
  2964. (get-text-property p :org-comment)
  2965. (org-end-of-subtree t)
  2966. (throw :skip t))
  2967. (if (equal (char-after p) ?#) (throw :skip t))
  2968. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2969. (org-agenda-skip-eval org-agenda-skip-function)))
  2970. (goto-char to)
  2971. (throw :skip t))))
  2972. (defun org-agenda-skip-eval (form)
  2973. "If FORM is a function or a list, call (or eval) is and return result.
  2974. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2975. and match data are returned to the previous state no matter what these
  2976. functions do."
  2977. (let (fp)
  2978. (and form
  2979. (or (setq fp (functionp form))
  2980. (consp form))
  2981. (save-excursion
  2982. (save-match-data
  2983. (if fp
  2984. (funcall form)
  2985. (eval form)))))))
  2986. (defvar org-agenda-markers nil
  2987. "List of all currently active markers created by `org-agenda'.")
  2988. (defvar org-agenda-last-marker-time (org-float-time)
  2989. "Creation time of the last agenda marker.")
  2990. (defun org-agenda-new-marker (&optional pos)
  2991. "Return a new agenda marker.
  2992. Org-mode keeps a list of these markers and resets them when they are
  2993. no longer in use."
  2994. (let ((m (copy-marker (or pos (point)))))
  2995. (setq org-agenda-last-marker-time (org-float-time))
  2996. (push m org-agenda-markers)
  2997. m))
  2998. (defun org-agenda-reset-markers ()
  2999. "Reset markers created by `org-agenda'."
  3000. (while org-agenda-markers
  3001. (move-marker (pop org-agenda-markers) nil)))
  3002. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3003. "Save relative positions of markers in region."
  3004. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3005. org-agenda-markers))
  3006. ;;; Entry text mode
  3007. (defun org-agenda-entry-text-show-here ()
  3008. "Add some text from the entry as context to the current line."
  3009. (let (m txt o)
  3010. (setq m (org-get-at-bol 'org-hd-marker))
  3011. (unless (marker-buffer m)
  3012. (error "No marker points to an entry here"))
  3013. (setq txt (concat "\n" (org-no-properties
  3014. (org-agenda-get-some-entry-text
  3015. m org-agenda-entry-text-maxlines " > "))))
  3016. (when (string-match "\\S-" txt)
  3017. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3018. (overlay-put o 'evaporate t)
  3019. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3020. (overlay-put o 'after-string txt))))
  3021. (defun org-agenda-entry-text-show ()
  3022. "Add entry context for all agenda lines."
  3023. (interactive)
  3024. (save-excursion
  3025. (goto-char (point-max))
  3026. (beginning-of-line 1)
  3027. (while (not (bobp))
  3028. (when (org-get-at-bol 'org-hd-marker)
  3029. (org-agenda-entry-text-show-here))
  3030. (beginning-of-line 0))))
  3031. (defun org-agenda-entry-text-hide ()
  3032. "Remove any shown entry context."
  3033. (delq nil
  3034. (mapcar (lambda (o)
  3035. (if (eq (overlay-get o 'org-overlay-type)
  3036. 'agenda-entry-content)
  3037. (progn (delete-overlay o) t)))
  3038. (overlays-in (point-min) (point-max)))))
  3039. (defun org-agenda-get-day-face (date)
  3040. "Return the face DATE should be displayed with."
  3041. (or (and (functionp org-agenda-day-face-function)
  3042. (funcall org-agenda-day-face-function date))
  3043. (cond ((org-agenda-todayp date)
  3044. 'org-agenda-date-today)
  3045. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3046. 'org-agenda-date-weekend)
  3047. (t 'org-agenda-date))))
  3048. ;;; Agenda timeline
  3049. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3050. (defun org-timeline (&optional dotodo)
  3051. "Show a time-sorted view of the entries in the current org file.
  3052. Only entries with a time stamp of today or later will be listed. With
  3053. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3054. under the current date.
  3055. If the buffer contains an active region, only check the region for
  3056. dates."
  3057. (interactive "P")
  3058. (org-compile-prefix-format 'timeline)
  3059. (org-set-sorting-strategy 'timeline)
  3060. (let* ((dopast t)
  3061. (doclosed org-agenda-show-log)
  3062. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3063. (current-buffer))))
  3064. (date (calendar-current-date))
  3065. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3066. (end (if (org-region-active-p) (region-end) (point-max)))
  3067. (day-numbers (org-get-all-dates beg end 'no-ranges
  3068. t doclosed ; always include today
  3069. org-timeline-show-empty-dates))
  3070. (org-deadline-warning-days 0)
  3071. (org-agenda-only-exact-dates t)
  3072. (today (org-today))
  3073. (past t)
  3074. args
  3075. s e rtn d emptyp)
  3076. (setq org-agenda-redo-command
  3077. (list 'progn
  3078. (list 'org-switch-to-buffer-other-window (current-buffer))
  3079. (list 'org-timeline (list 'quote dotodo))))
  3080. (if (not dopast)
  3081. ;; Remove past dates from the list of dates.
  3082. (setq day-numbers (delq nil (mapcar (lambda(x)
  3083. (if (>= x today) x nil))
  3084. day-numbers))))
  3085. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3086. (if doclosed (push :closed args))
  3087. (push :timestamp args)
  3088. (push :deadline args)
  3089. (push :scheduled args)
  3090. (push :sexp args)
  3091. (if dotodo (push :todo args))
  3092. (insert "Timeline of file " entry "\n")
  3093. (add-text-properties (point-min) (point)
  3094. (list 'face 'org-agenda-structure))
  3095. (org-agenda-mark-header-line (point-min))
  3096. (while (setq d (pop day-numbers))
  3097. (if (and (listp d) (eq (car d) :omitted))
  3098. (progn
  3099. (setq s (point))
  3100. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3101. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3102. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3103. (if (and (>= d today)
  3104. dopast
  3105. past)
  3106. (progn
  3107. (setq past nil)
  3108. (insert (make-string 79 ?-) "\n")))
  3109. (setq date (calendar-gregorian-from-absolute d))
  3110. (setq s (point))
  3111. (setq rtn (and (not emptyp)
  3112. (apply 'org-agenda-get-day-entries entry
  3113. date args)))
  3114. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3115. (progn
  3116. (insert
  3117. (if (stringp org-agenda-format-date)
  3118. (format-time-string org-agenda-format-date
  3119. (org-time-from-absolute date))
  3120. (funcall org-agenda-format-date date))
  3121. "\n")
  3122. (put-text-property s (1- (point)) 'face
  3123. (org-agenda-get-day-face date))
  3124. (put-text-property s (1- (point)) 'org-date-line t)
  3125. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3126. (if (equal d today)
  3127. (put-text-property s (1- (point)) 'org-today t))
  3128. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3129. (put-text-property s (1- (point)) 'day d)))))
  3130. (goto-char (point-min))
  3131. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3132. (point-min)))
  3133. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3134. (org-finalize-agenda)
  3135. (setq buffer-read-only t)))
  3136. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3137. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3138. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3139. not every single day in the range. If FORCE-TODAY is non-nil, make
  3140. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3141. inactive time stamps (those in square brackets) are included.
  3142. When EMPTY is non-nil, also include days without any entries."
  3143. (let ((re (concat
  3144. (if pre-re pre-re "")
  3145. (if inactive org-ts-regexp-both org-ts-regexp)))
  3146. dates dates1 date day day1 day2 ts1 ts2)
  3147. (if force-today
  3148. (setq dates (list (org-today))))
  3149. (save-excursion
  3150. (goto-char beg)
  3151. (while (re-search-forward re end t)
  3152. (setq day (time-to-days (org-time-string-to-time
  3153. (substring (match-string 1) 0 10))))
  3154. (or (memq day dates) (push day dates)))
  3155. (unless no-ranges
  3156. (goto-char beg)
  3157. (while (re-search-forward org-tr-regexp end t)
  3158. (setq ts1 (substring (match-string 1) 0 10)
  3159. ts2 (substring (match-string 2) 0 10)
  3160. day1 (time-to-days (org-time-string-to-time ts1))
  3161. day2 (time-to-days (org-time-string-to-time ts2)))
  3162. (while (< (setq day1 (1+ day1)) day2)
  3163. (or (memq day1 dates) (push day1 dates)))))
  3164. (setq dates (sort dates '<))
  3165. (when empty
  3166. (while (setq day (pop dates))
  3167. (setq day2 (car dates))
  3168. (push day dates1)
  3169. (when (and day2 empty)
  3170. (if (or (eq empty t)
  3171. (and (numberp empty) (<= (- day2 day) empty)))
  3172. (while (< (setq day (1+ day)) day2)
  3173. (push (list day) dates1))
  3174. (push (cons :omitted (- day2 day)) dates1))))
  3175. (setq dates (nreverse dates1)))
  3176. dates)))
  3177. ;;; Agenda Daily/Weekly
  3178. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3179. "Start day for the agenda view.
  3180. Custom commands can set this variable in the options section.")
  3181. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3182. (defvar org-agenda-current-span nil
  3183. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3184. (defvar org-arg-loc nil) ; local variable
  3185. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3186. "List of types searched for when creating the daily/weekly agenda.
  3187. This variable is a list of symbols that controls the types of
  3188. items that appear in the daily/weekly agenda. Allowed symbols in this
  3189. list are are
  3190. :timestamp List items containing a date stamp or date range matching
  3191. the selected date. This includes sexp entries in
  3192. angular brackets.
  3193. :sexp List entries resulting from plain diary-like sexps.
  3194. :deadline List deadline due on that date. When the date is today,
  3195. also list any deadlines past due, or due within
  3196. `org-deadline-warning-days'. `:deadline' must appear before
  3197. `:scheduled' if the setting of
  3198. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3199. any effect.
  3200. :scheduled List all items which are scheduled for the given date.
  3201. The diary for *today* also contains items which were
  3202. scheduled earlier and are not yet marked DONE.
  3203. By default, all four types are turned on.
  3204. Never set this variable globally using `setq', because then it
  3205. will apply to all future agenda commands. Instead, bind it with
  3206. `let' to scope it dynamically into the agenda-constructing
  3207. command. A good way to set it is through options in
  3208. `org-agenda-custom-commands'. For a more flexible (though
  3209. somewhat less efficient) way of determining what is included in
  3210. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3211. ;;;###autoload
  3212. (defun org-agenda-list (&optional arg start-day span)
  3213. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3214. The view will be for the current day or week, but from the overview buffer
  3215. you will be able to go to other days/weeks.
  3216. With a numeric prefix argument in an interactive call, the agenda will
  3217. span ARG days. Lisp programs should instead specify SPAN to change
  3218. the number of days. SPAN defaults to `org-agenda-span'.
  3219. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3220. given in `org-agenda-start-on-weekday'."
  3221. (interactive "P")
  3222. (if (and (integerp arg) (> arg 0))
  3223. (setq span arg arg nil))
  3224. (setq start-day (or start-day org-agenda-start-day))
  3225. (if org-agenda-overriding-arguments
  3226. (setq arg (car org-agenda-overriding-arguments)
  3227. start-day (nth 1 org-agenda-overriding-arguments)
  3228. span (nth 2 org-agenda-overriding-arguments)))
  3229. (if (stringp start-day)
  3230. ;; Convert to an absolute day number
  3231. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3232. (setq org-agenda-last-arguments (list arg start-day span))
  3233. (org-compile-prefix-format 'agenda)
  3234. (org-set-sorting-strategy 'agenda)
  3235. (let* ((span (org-agenda-ndays-to-span
  3236. (or span org-agenda-ndays org-agenda-span)))
  3237. (today (org-today))
  3238. (sd (or start-day today))
  3239. (ndays (org-agenda-span-to-ndays span sd))
  3240. (org-agenda-start-on-weekday
  3241. (if (eq ndays 7)
  3242. org-agenda-start-on-weekday))
  3243. (thefiles (org-agenda-files nil 'ifmode))
  3244. (files thefiles)
  3245. (start (if (or (null org-agenda-start-on-weekday)
  3246. (< ndays 7))
  3247. sd
  3248. (let* ((nt (calendar-day-of-week
  3249. (calendar-gregorian-from-absolute sd)))
  3250. (n1 org-agenda-start-on-weekday)
  3251. (d (- nt n1)))
  3252. (- sd (+ (if (< d 0) 7 0) d)))))
  3253. (day-numbers (list start))
  3254. (day-cnt 0)
  3255. (inhibit-redisplay (not debug-on-error))
  3256. s e rtn rtnall file date d start-pos end-pos todayp
  3257. clocktable-start clocktable-end filter)
  3258. (setq org-agenda-redo-command
  3259. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3260. (dotimes (n (1- ndays))
  3261. (push (1+ (car day-numbers)) day-numbers))
  3262. (setq day-numbers (nreverse day-numbers))
  3263. (setq clocktable-start (car day-numbers)
  3264. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3265. (org-prepare-agenda "Day/Week")
  3266. (org-set-local 'org-starting-day (car day-numbers))
  3267. (org-set-local 'org-arg-loc arg)
  3268. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3269. (unless org-agenda-compact-blocks
  3270. (let* ((d1 (car day-numbers))
  3271. (d2 (org-last day-numbers))
  3272. (w1 (org-days-to-iso-week d1))
  3273. (w2 (org-days-to-iso-week d2)))
  3274. (setq s (point))
  3275. (if org-agenda-overriding-header
  3276. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3277. nil 'face 'org-agenda-structure) "\n")
  3278. (insert (org-agenda-span-name span)
  3279. "-agenda"
  3280. (if (< (- d2 d1) 350)
  3281. (if (= w1 w2)
  3282. (format " (W%02d)" w1)
  3283. (format " (W%02d-W%02d)" w1 w2))
  3284. "")
  3285. ":\n")))
  3286. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3287. 'org-date-line t))
  3288. (org-agenda-mark-header-line s))
  3289. (while (setq d (pop day-numbers))
  3290. (setq date (calendar-gregorian-from-absolute d)
  3291. s (point))
  3292. (if (or (setq todayp (= d today))
  3293. (and (not start-pos) (= d sd)))
  3294. (setq start-pos (point))
  3295. (if (and start-pos (not end-pos))
  3296. (setq end-pos (point))))
  3297. (setq files thefiles
  3298. rtnall nil)
  3299. (while (setq file (pop files))
  3300. (catch 'nextfile
  3301. (org-check-agenda-file file)
  3302. (let ((org-agenda-entry-types org-agenda-entry-types))
  3303. (unless org-agenda-include-deadlines
  3304. (setq org-agenda-entry-types
  3305. (delq :deadline org-agenda-entry-types)))
  3306. (cond
  3307. ((memq org-agenda-show-log '(only clockcheck))
  3308. (setq rtn (org-agenda-get-day-entries
  3309. file date :closed)))
  3310. (org-agenda-show-log
  3311. (setq rtn (apply 'org-agenda-get-day-entries
  3312. file date
  3313. (append '(:closed) org-agenda-entry-types))))
  3314. (t
  3315. (setq rtn (apply 'org-agenda-get-day-entries
  3316. file date
  3317. org-agenda-entry-types)))))
  3318. (setq rtnall (append rtnall rtn))))
  3319. (if org-agenda-include-diary
  3320. (let ((org-agenda-search-headline-for-time t))
  3321. (require 'diary-lib)
  3322. (setq rtn (org-get-entries-from-diary date))
  3323. (setq rtnall (append rtnall rtn))))
  3324. (if (or rtnall org-agenda-show-all-dates)
  3325. (progn
  3326. (setq day-cnt (1+ day-cnt))
  3327. (insert
  3328. (if (stringp org-agenda-format-date)
  3329. (format-time-string org-agenda-format-date
  3330. (org-time-from-absolute date))
  3331. (funcall org-agenda-format-date date))
  3332. "\n")
  3333. (put-text-property s (1- (point)) 'face
  3334. (org-agenda-get-day-face date))
  3335. (put-text-property s (1- (point)) 'org-date-line t)
  3336. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3337. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3338. (when todayp
  3339. (put-text-property s (1- (point)) 'org-today t))
  3340. (if rtnall (insert
  3341. (org-finalize-agenda-entries
  3342. (org-agenda-add-time-grid-maybe
  3343. rtnall ndays todayp))
  3344. "\n"))
  3345. (put-text-property s (1- (point)) 'day d)
  3346. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3347. (when (and org-agenda-clockreport-mode clocktable-start)
  3348. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3349. ;; the above line is to ensure the restricted range!
  3350. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3351. tbl)
  3352. (setq p (org-plist-delete p :block))
  3353. (setq p (plist-put p :tstart clocktable-start))
  3354. (setq p (plist-put p :tend clocktable-end))
  3355. (setq p (plist-put p :scope 'agenda))
  3356. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3357. (setq filter (or org-agenda-filter-while-redo
  3358. (get 'org-agenda-filter :preset-filter))))
  3359. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3360. (if (string-match "[<>=]" x)
  3361. ""
  3362. x))
  3363. filter ""))))
  3364. (setq tbl (apply 'org-get-clocktable p))
  3365. (insert tbl)))
  3366. (goto-char (point-min))
  3367. (or org-agenda-multi (org-fit-agenda-window))
  3368. (unless (and (pos-visible-in-window-p (point-min))
  3369. (pos-visible-in-window-p (point-max)))
  3370. (goto-char (1- (point-max)))
  3371. (recenter -1)
  3372. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3373. (progn
  3374. (goto-char (or start-pos 1))
  3375. (recenter 1))))
  3376. (goto-char (or start-pos 1))
  3377. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3378. (if (eq org-agenda-show-log 'clockcheck)
  3379. (org-agenda-show-clocking-issues))
  3380. (org-finalize-agenda)
  3381. (setq buffer-read-only t)
  3382. (message "")))
  3383. (defun org-agenda-ndays-to-span (n)
  3384. "Return a span symbol for a span of N days, or N if none matches."
  3385. (cond ((symbolp n) n)
  3386. ((= n 1) 'day)
  3387. ((= n 7) 'week)
  3388. (t n)))
  3389. (defun org-agenda-span-to-ndays (span start-day)
  3390. "Return ndays from SPAN starting at START-DAY."
  3391. (cond ((numberp span) span)
  3392. ((eq span 'day) 1)
  3393. ((eq span 'week) 7)
  3394. ((eq span 'month)
  3395. (let ((date (calendar-gregorian-from-absolute start-day)))
  3396. (calendar-last-day-of-month (car date) (caddr date))))
  3397. ((eq span 'year)
  3398. (let ((date (calendar-gregorian-from-absolute start-day)))
  3399. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3400. (defun org-agenda-span-name (span)
  3401. "Return a SPAN name."
  3402. (if (null span)
  3403. ""
  3404. (if (symbolp span)
  3405. (capitalize (symbol-name span))
  3406. (format "%d days" span))))
  3407. ;;; Agenda word search
  3408. (defvar org-agenda-search-history nil)
  3409. (defvar org-todo-only nil)
  3410. (defvar org-search-syntax-table nil
  3411. "Special syntax table for org-mode search.
  3412. In this table, we have single quotes not as word constituents, to
  3413. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3414. (defun org-search-syntax-table ()
  3415. (unless org-search-syntax-table
  3416. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3417. (modify-syntax-entry ?' "." org-search-syntax-table)
  3418. (modify-syntax-entry ?` "." org-search-syntax-table))
  3419. org-search-syntax-table)
  3420. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3421. ;;;###autoload
  3422. (defun org-search-view (&optional todo-only string edit-at)
  3423. "Show all entries that contain a phrase or words or regular expressions.
  3424. With optional prefix argument TODO-ONLY, only consider entries that are
  3425. TODO entries. The argument STRING can be used to pass a default search
  3426. string into this function. If EDIT-AT is non-nil, it means that the
  3427. user should get a chance to edit this string, with cursor at position
  3428. EDIT-AT.
  3429. The search string can be viewed either as a phrase that should be found as
  3430. is, or it can be broken into a number of snippets, each of which must match
  3431. in a Boolean way to select an entry. The default depends on the variable
  3432. `org-agenda-search-view-always-boolean'.
  3433. Even if this is turned off (the default) you can always switch to
  3434. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3435. The default is a direct search of the whole phrase, where each space in
  3436. the search string can expand to an arbitrary amount of whitespace,
  3437. including newlines.
  3438. If using a Boolean search, the search string is split on whitespace and
  3439. each snippet is searched separately, with logical AND to select an entry.
  3440. Words prefixed with a minus must *not* occur in the entry. Words without
  3441. a prefix or prefixed with a plus must occur in the entry. Matching is
  3442. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3443. match whole words, not parts of a word) if
  3444. `org-agenda-search-view-force-full-words' is set (default is nil).
  3445. Boolean search snippets enclosed by curly braces are interpreted as
  3446. regular expressions that must or (when preceded with \"-\") must not
  3447. match in the entry. Snippets enclosed into double quotes will be taken
  3448. as a whole, to include whitespace.
  3449. - If the search string starts with an asterisk, search only in headlines.
  3450. - If (possibly after the leading star) the search string starts with an
  3451. exclamation mark, this also means to look at TODO entries only, an effect
  3452. that can also be achieved with a prefix argument.
  3453. - If (possibly after star and exclamation mark) the search string starts
  3454. with a colon, this will mean that the (non-regexp) snippets of the
  3455. Boolean search must match as full words.
  3456. This command searches the agenda files, and in addition the files listed
  3457. in `org-agenda-text-search-extra-files'."
  3458. (interactive "P")
  3459. (org-compile-prefix-format 'search)
  3460. (org-set-sorting-strategy 'search)
  3461. (org-prepare-agenda "SEARCH")
  3462. (let* ((props (list 'face nil
  3463. 'done-face 'org-agenda-done
  3464. 'org-not-done-regexp org-not-done-regexp
  3465. 'org-todo-regexp org-todo-regexp
  3466. 'org-complex-heading-regexp org-complex-heading-regexp
  3467. 'mouse-face 'highlight
  3468. 'help-echo (format "mouse-2 or RET jump to location")))
  3469. (full-words org-agenda-search-view-force-full-words)
  3470. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3471. regexp rtn rtnall files file pos
  3472. marker category tags c neg re boolean
  3473. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3474. (unless (and (not edit-at)
  3475. (stringp string)
  3476. (string-match "\\S-" string))
  3477. (setq string (read-string
  3478. (if org-agenda-search-view-always-boolean
  3479. "[+-]Word/{Regexp} ...: "
  3480. "Phrase, or [+-]Word/{Regexp} ...: ")
  3481. (cond
  3482. ((integerp edit-at) (cons string edit-at))
  3483. (edit-at string))
  3484. 'org-agenda-search-history)))
  3485. (org-set-local 'org-todo-only todo-only)
  3486. (setq org-agenda-redo-command
  3487. (list 'org-search-view (if todo-only t nil) string
  3488. '(if current-prefix-arg 1 nil)))
  3489. (setq org-agenda-query-string string)
  3490. (if (equal (string-to-char string) ?*)
  3491. (setq hdl-only t
  3492. words (substring string 1))
  3493. (setq words string))
  3494. (when (equal (string-to-char words) ?!)
  3495. (setq todo-only t
  3496. words (substring words 1)))
  3497. (when (equal (string-to-char words) ?:)
  3498. (setq full-words t
  3499. words (substring words 1)))
  3500. (if (or org-agenda-search-view-always-boolean
  3501. (member (string-to-char words) '(?- ?+ ?\{)))
  3502. (setq boolean t))
  3503. (setq words (org-split-string words))
  3504. (let (www w)
  3505. (while (setq w (pop words))
  3506. (while (and (string-match "\\\\\\'" w) words)
  3507. (setq w (concat (substring w 0 -1) " " (pop words))))
  3508. (push w www))
  3509. (setq words (nreverse www) www nil)
  3510. (while (setq w (pop words))
  3511. (when (and (string-match "\\`[-+]?{" w)
  3512. (not (string-match "}\\'" w)))
  3513. (while (and words (not (string-match "}\\'" (car words))))
  3514. (setq w (concat w " " (pop words))))
  3515. (setq w (concat w " " (pop words))))
  3516. (push w www))
  3517. (setq words (nreverse www)))
  3518. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3519. (when boolean
  3520. (let (wds w)
  3521. (while (setq w (pop words))
  3522. (if (or (equal (substring w 0 1) "\"")
  3523. (and (> (length w) 1)
  3524. (member (substring w 0 1) '("+" "-"))
  3525. (equal (substring w 1 2) "\"")))
  3526. (while (and words (not (equal (substring w -1) "\"")))
  3527. (setq w (concat w " " (pop words)))))
  3528. (and (string-match "\\`\\([-+]?\\)\"" w)
  3529. (setq w (replace-match "\\1" nil nil w)))
  3530. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3531. (push w wds))
  3532. (setq words (nreverse wds))))
  3533. (if boolean
  3534. (mapc (lambda (w)
  3535. (setq c (string-to-char w))
  3536. (if (equal c ?-)
  3537. (setq neg t w (substring w 1))
  3538. (if (equal c ?+)
  3539. (setq neg nil w (substring w 1))
  3540. (setq neg nil)))
  3541. (if (string-match "\\`{.*}\\'" w)
  3542. (setq re (substring w 1 -1))
  3543. (if full-words
  3544. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3545. (setq re (regexp-quote (downcase w)))))
  3546. (if neg (push re regexps-) (push re regexps+)))
  3547. words)
  3548. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3549. regexps+))
  3550. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3551. (if (not regexps+)
  3552. (setq regexp org-outline-regexp-bol)
  3553. (setq regexp (pop regexps+))
  3554. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3555. regexp))))
  3556. (setq files (org-agenda-files nil 'ifmode))
  3557. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3558. (pop org-agenda-text-search-extra-files)
  3559. (setq files (org-add-archive-files files)))
  3560. (setq files (append files org-agenda-text-search-extra-files)
  3561. rtnall nil)
  3562. (while (setq file (pop files))
  3563. (setq ee nil)
  3564. (catch 'nextfile
  3565. (org-check-agenda-file file)
  3566. (setq buffer (if (file-exists-p file)
  3567. (org-get-agenda-file-buffer file)
  3568. (error "No such file %s" file)))
  3569. (if (not buffer)
  3570. ;; If file does not exist, make sure an error message is sent
  3571. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3572. file))))
  3573. (with-current-buffer buffer
  3574. (with-syntax-table (org-search-syntax-table)
  3575. (unless (org-mode-p)
  3576. (error "Agenda file %s is not in `org-mode'" file))
  3577. (let ((case-fold-search t))
  3578. (save-excursion
  3579. (save-restriction
  3580. (if org-agenda-restrict
  3581. (narrow-to-region org-agenda-restrict-begin
  3582. org-agenda-restrict-end)
  3583. (widen))
  3584. (goto-char (point-min))
  3585. (unless (or (org-on-heading-p)
  3586. (outline-next-heading))
  3587. (throw 'nextfile t))
  3588. (goto-char (max (point-min) (1- (point))))
  3589. (while (re-search-forward regexp nil t)
  3590. (org-back-to-heading t)
  3591. (skip-chars-forward "* ")
  3592. (setq beg (point-at-bol)
  3593. beg1 (point)
  3594. end (progn (outline-next-heading) (point)))
  3595. (catch :skip
  3596. (goto-char beg)
  3597. (org-agenda-skip)
  3598. (setq str (buffer-substring-no-properties
  3599. (point-at-bol)
  3600. (if hdl-only (point-at-eol) end)))
  3601. (mapc (lambda (wr) (when (string-match wr str)
  3602. (goto-char (1- end))
  3603. (throw :skip t)))
  3604. regexps-)
  3605. (mapc (lambda (wr) (unless (string-match wr str)
  3606. (goto-char (1- end))
  3607. (throw :skip t)))
  3608. (if todo-only
  3609. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3610. regexps+)
  3611. regexps+))
  3612. (goto-char beg)
  3613. (setq marker (org-agenda-new-marker (point))
  3614. category (org-get-category)
  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. 'type "search")
  3627. (push txt ee)
  3628. (goto-char (1- end))))))))))
  3629. (setq rtn (nreverse ee))
  3630. (setq rtnall (append rtnall rtn)))
  3631. (if org-agenda-overriding-header
  3632. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3633. nil 'face 'org-agenda-structure) "\n")
  3634. (insert "Search words: ")
  3635. (add-text-properties (point-min) (1- (point))
  3636. (list 'face 'org-agenda-structure))
  3637. (setq pos (point))
  3638. (insert string "\n")
  3639. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3640. (setq pos (point))
  3641. (unless org-agenda-multi
  3642. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3643. (add-text-properties pos (1- (point))
  3644. (list 'face 'org-agenda-structure))))
  3645. (org-agenda-mark-header-line (point-min))
  3646. (when rtnall
  3647. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3648. (goto-char (point-min))
  3649. (or org-agenda-multi (org-fit-agenda-window))
  3650. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3651. (org-finalize-agenda)
  3652. (setq buffer-read-only t)))
  3653. ;;; Agenda TODO list
  3654. (defvar org-select-this-todo-keyword nil)
  3655. (defvar org-last-arg nil)
  3656. ;;;###autoload
  3657. (defun org-todo-list (arg)
  3658. "Show all (not done) TODO entries from all agenda file in a single list.
  3659. The prefix arg can be used to select a specific TODO keyword and limit
  3660. the list to these. When using \\[universal-argument], you will be prompted
  3661. for a keyword. A numeric prefix directly selects the Nth keyword in
  3662. `org-todo-keywords-1'."
  3663. (interactive "P")
  3664. (org-compile-prefix-format 'todo)
  3665. (org-set-sorting-strategy 'todo)
  3666. (org-prepare-agenda "TODO")
  3667. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3668. (let* ((today (org-today))
  3669. (date (calendar-gregorian-from-absolute today))
  3670. (kwds org-todo-keywords-for-agenda)
  3671. (completion-ignore-case t)
  3672. (org-select-this-todo-keyword
  3673. (if (stringp arg) arg
  3674. (and arg (integerp arg) (> arg 0)
  3675. (nth (1- arg) kwds))))
  3676. rtn rtnall files file pos)
  3677. (when (equal arg '(4))
  3678. (setq org-select-this-todo-keyword
  3679. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3680. (mapcar 'list kwds) nil nil)))
  3681. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3682. (org-set-local 'org-last-arg arg)
  3683. (setq org-agenda-redo-command
  3684. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3685. (setq files (org-agenda-files nil 'ifmode)
  3686. rtnall nil)
  3687. (while (setq file (pop files))
  3688. (catch 'nextfile
  3689. (org-check-agenda-file file)
  3690. (setq rtn (org-agenda-get-day-entries file date :todo))
  3691. (setq rtnall (append rtnall rtn))))
  3692. (if org-agenda-overriding-header
  3693. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3694. nil 'face 'org-agenda-structure) "\n")
  3695. (insert "Global list of TODO items of type: ")
  3696. (add-text-properties (point-min) (1- (point))
  3697. (list 'face 'org-agenda-structure
  3698. 'short-heading
  3699. (concat "ToDo: "
  3700. (or org-select-this-todo-keyword "ALL"))))
  3701. (org-agenda-mark-header-line (point-min))
  3702. (setq pos (point))
  3703. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3704. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3705. (setq pos (point))
  3706. (unless org-agenda-multi
  3707. (insert "Available with `N r': (0)ALL")
  3708. (let ((n 0) s)
  3709. (mapc (lambda (x)
  3710. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3711. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3712. (insert "\n "))
  3713. (insert " " s))
  3714. kwds))
  3715. (insert "\n"))
  3716. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3717. (org-agenda-mark-header-line (point-min))
  3718. (when rtnall
  3719. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3720. (goto-char (point-min))
  3721. (or org-agenda-multi (org-fit-agenda-window))
  3722. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3723. (org-finalize-agenda)
  3724. (setq buffer-read-only t)))
  3725. ;;; Agenda tags match
  3726. ;;;###autoload
  3727. (defun org-tags-view (&optional todo-only match)
  3728. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3729. The prefix arg TODO-ONLY limits the search to TODO entries."
  3730. (interactive "P")
  3731. (org-compile-prefix-format 'tags)
  3732. (org-set-sorting-strategy 'tags)
  3733. (let* ((org-tags-match-list-sublevels
  3734. org-tags-match-list-sublevels)
  3735. (completion-ignore-case t)
  3736. rtn rtnall files file pos matcher
  3737. buffer)
  3738. (when (and (stringp match) (not (string-match "\\S-" match)))
  3739. (setq match nil))
  3740. (setq matcher (org-make-tags-matcher match)
  3741. match (car matcher) matcher (cdr matcher))
  3742. (org-prepare-agenda (concat "TAGS " match))
  3743. (setq org-agenda-query-string match)
  3744. (setq org-agenda-redo-command
  3745. (list 'org-tags-view (list 'quote todo-only)
  3746. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3747. (setq files (org-agenda-files nil 'ifmode)
  3748. rtnall nil)
  3749. (while (setq file (pop files))
  3750. (catch 'nextfile
  3751. (org-check-agenda-file file)
  3752. (setq buffer (if (file-exists-p file)
  3753. (org-get-agenda-file-buffer file)
  3754. (error "No such file %s" file)))
  3755. (if (not buffer)
  3756. ;; If file does not exist, error message to agenda
  3757. (setq rtn (list
  3758. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3759. rtnall (append rtnall rtn))
  3760. (with-current-buffer buffer
  3761. (unless (org-mode-p)
  3762. (error "Agenda file %s is not in `org-mode'" file))
  3763. (save-excursion
  3764. (save-restriction
  3765. (if org-agenda-restrict
  3766. (narrow-to-region org-agenda-restrict-begin
  3767. org-agenda-restrict-end)
  3768. (widen))
  3769. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3770. (setq rtnall (append rtnall rtn))))))))
  3771. (if org-agenda-overriding-header
  3772. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3773. nil 'face 'org-agenda-structure) "\n")
  3774. (insert "Headlines with TAGS match: ")
  3775. (add-text-properties (point-min) (1- (point))
  3776. (list 'face 'org-agenda-structure
  3777. 'short-heading
  3778. (concat "Match: " match)))
  3779. (setq pos (point))
  3780. (insert match "\n")
  3781. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3782. (setq pos (point))
  3783. (unless org-agenda-multi
  3784. (insert "Press `C-u r' to search again with new search string\n"))
  3785. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3786. (org-agenda-mark-header-line (point-min))
  3787. (when rtnall
  3788. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3789. (goto-char (point-min))
  3790. (or org-agenda-multi (org-fit-agenda-window))
  3791. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3792. (org-finalize-agenda)
  3793. (setq buffer-read-only t)))
  3794. ;;; Agenda Finding stuck projects
  3795. (defvar org-agenda-skip-regexp nil
  3796. "Regular expression used in skipping subtrees for the agenda.
  3797. This is basically a temporary global variable that can be set and then
  3798. used by user-defined selections using `org-agenda-skip-function'.")
  3799. (defvar org-agenda-overriding-header nil
  3800. "When set during agenda, todo and tags searches it replaces the header.
  3801. This variable should not be set directly, but custom commands can bind it
  3802. in the options section.")
  3803. (defun org-agenda-skip-entry-when-regexp-matches ()
  3804. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3805. If yes, it returns the end position of this entry, causing agenda commands
  3806. to skip the entry but continuing the search in the subtree. This is a
  3807. function that can be put into `org-agenda-skip-function' for the duration
  3808. of a command."
  3809. (let ((end (save-excursion (org-end-of-subtree t)))
  3810. skip)
  3811. (save-excursion
  3812. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3813. (and skip end)))
  3814. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3815. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3816. If yes, it returns the end position of this tree, causing agenda commands
  3817. to skip this subtree. This is a function that can be put into
  3818. `org-agenda-skip-function' for the duration of a command."
  3819. (let ((end (save-excursion (org-end-of-subtree t)))
  3820. skip)
  3821. (save-excursion
  3822. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3823. (and skip end)))
  3824. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3825. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3826. If yes, it returns the end position of the current entry (NOT the tree),
  3827. causing agenda commands to skip the entry but continuing the search in
  3828. the subtree. This is a function that can be put into
  3829. `org-agenda-skip-function' for the duration of a command. An important
  3830. use of this function is for the stuck project list."
  3831. (let ((end (save-excursion (org-end-of-subtree t)))
  3832. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3833. skip)
  3834. (save-excursion
  3835. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3836. (and skip entry-end)))
  3837. (defun org-agenda-skip-entry-if (&rest conditions)
  3838. "Skip entry if any of CONDITIONS is true.
  3839. See `org-agenda-skip-if' for details."
  3840. (org-agenda-skip-if nil conditions))
  3841. (defun org-agenda-skip-subtree-if (&rest conditions)
  3842. "Skip entry if any of CONDITIONS is true.
  3843. See `org-agenda-skip-if' for details."
  3844. (org-agenda-skip-if t conditions))
  3845. (defun org-agenda-skip-if (subtree conditions)
  3846. "Checks current entity for CONDITIONS.
  3847. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3848. the entry, i.e. the text before the next heading is checked.
  3849. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3850. from different tests. Valid conditions are:
  3851. scheduled Check if there is a scheduled cookie
  3852. notscheduled Check if there is no scheduled cookie
  3853. deadline Check if there is a deadline
  3854. notdeadline Check if there is no deadline
  3855. timestamp Check if there is a timestamp (also deadline or scheduled)
  3856. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3857. regexp Check if regexp matches
  3858. notregexp Check if regexp does not match.
  3859. todo Check if TODO keyword matches
  3860. nottodo Check if TODO keyword does not match
  3861. The regexp is taken from the conditions list, it must come right after
  3862. the `regexp' or `notregexp' element.
  3863. `todo' and `nottodo' accept as an argument a list of todo
  3864. keywords, which may include \"*\" to match any todo keyword.
  3865. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3866. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3867. Instead of a list a keyword class may be given
  3868. (org-agenda-skip-entry-if 'nottodo 'done)
  3869. would skip entries that haven't been marked with any of \"DONE\"
  3870. keywords. Possible classes are: `todo', `done', `any'.
  3871. If any of these conditions is met, this function returns the end point of
  3872. the entity, causing the search to continue from there. This is a function
  3873. that can be put into `org-agenda-skip-function' for the duration of a command."
  3874. (let (beg end m)
  3875. (org-back-to-heading t)
  3876. (setq beg (point)
  3877. end (if subtree
  3878. (progn (org-end-of-subtree t) (point))
  3879. (progn (outline-next-heading) (1- (point)))))
  3880. (goto-char beg)
  3881. (and
  3882. (or
  3883. (and (memq 'scheduled conditions)
  3884. (re-search-forward org-scheduled-time-regexp end t))
  3885. (and (memq 'notscheduled conditions)
  3886. (not (re-search-forward org-scheduled-time-regexp end t)))
  3887. (and (memq 'deadline conditions)
  3888. (re-search-forward org-deadline-time-regexp end t))
  3889. (and (memq 'notdeadline conditions)
  3890. (not (re-search-forward org-deadline-time-regexp end t)))
  3891. (and (memq 'timestamp conditions)
  3892. (re-search-forward org-ts-regexp end t))
  3893. (and (memq 'nottimestamp conditions)
  3894. (not (re-search-forward org-ts-regexp end t)))
  3895. (and (setq m (memq 'regexp conditions))
  3896. (stringp (nth 1 m))
  3897. (re-search-forward (nth 1 m) end t))
  3898. (and (setq m (memq 'notregexp conditions))
  3899. (stringp (nth 1 m))
  3900. (not (re-search-forward (nth 1 m) end t)))
  3901. (and (or
  3902. (setq m (memq 'todo conditions))
  3903. (setq m (memq 'nottodo conditions)))
  3904. (org-agenda-skip-if-todo m end)))
  3905. end)))
  3906. (defun org-agenda-skip-if-todo (args end)
  3907. "Helper function for `org-agenda-skip-if', do not use it directly.
  3908. ARGS is a list with first element either `todo' or `nottodo'.
  3909. The remainder is either a list of TODO keywords, or a state symbol
  3910. `todo' or `done' or `any'."
  3911. (let ((kw (car args))
  3912. (arg (cadr args))
  3913. todo-wds todo-re)
  3914. (setq todo-wds
  3915. (org-uniquify
  3916. (cond
  3917. ((listp arg) ;; list of keywords
  3918. (if (member "*" arg)
  3919. (mapcar 'substring-no-properties org-todo-keywords-1)
  3920. arg))
  3921. ((symbolp arg) ;; keyword class name
  3922. (cond
  3923. ((eq arg 'todo)
  3924. (org-delete-all org-done-keywords
  3925. (mapcar 'substring-no-properties
  3926. org-todo-keywords-1)))
  3927. ((eq arg 'done) org-done-keywords)
  3928. ((eq arg 'any)
  3929. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3930. (setq todo-re
  3931. (concat "^\\*+[ \t]+\\<\\("
  3932. (mapconcat 'identity todo-wds "\\|")
  3933. "\\)\\>"))
  3934. (if (eq kw 'todo)
  3935. (re-search-forward todo-re end t)
  3936. (not (re-search-forward todo-re end t)))))
  3937. ;;;###autoload
  3938. (defun org-agenda-list-stuck-projects (&rest ignore)
  3939. "Create agenda view for projects that are stuck.
  3940. Stuck projects are project that have no next actions. For the definitions
  3941. of what a project is and how to check if it stuck, customize the variable
  3942. `org-stuck-projects'."
  3943. (interactive)
  3944. (let* ((org-agenda-skip-function
  3945. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3946. ;; We could have used org-agenda-skip-if here.
  3947. (org-agenda-overriding-header
  3948. (or org-agenda-overriding-header "List of stuck projects: "))
  3949. (matcher (nth 0 org-stuck-projects))
  3950. (todo (nth 1 org-stuck-projects))
  3951. (todo-wds (if (member "*" todo)
  3952. (progn
  3953. (org-prepare-agenda-buffers (org-agenda-files
  3954. nil 'ifmode))
  3955. (org-delete-all
  3956. org-done-keywords-for-agenda
  3957. (copy-sequence org-todo-keywords-for-agenda)))
  3958. todo))
  3959. (todo-re (concat "^\\*+[ \t]+\\("
  3960. (mapconcat 'identity todo-wds "\\|")
  3961. "\\)\\>"))
  3962. (tags (nth 2 org-stuck-projects))
  3963. (tags-re (if (member "*" tags)
  3964. (org-re (concat org-outline-regexp-bol
  3965. ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3966. (if tags
  3967. (concat org-outline-regexp-bol
  3968. ".*:\\("
  3969. (mapconcat 'identity tags "\\|")
  3970. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3971. (gen-re (nth 3 org-stuck-projects))
  3972. (re-list
  3973. (delq nil
  3974. (list
  3975. (if todo todo-re)
  3976. (if tags tags-re)
  3977. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3978. gen-re)))))
  3979. (setq org-agenda-skip-regexp
  3980. (if re-list
  3981. (mapconcat 'identity re-list "\\|")
  3982. (error "No information how to identify unstuck projects")))
  3983. (org-tags-view nil matcher)
  3984. (with-current-buffer org-agenda-buffer-name
  3985. (setq org-agenda-redo-command
  3986. '(org-agenda-list-stuck-projects
  3987. (or current-prefix-arg org-last-arg))))))
  3988. ;;; Diary integration
  3989. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3990. (defvar list-diary-entries-hook)
  3991. (defvar diary-time-regexp)
  3992. (defun org-get-entries-from-diary (date)
  3993. "Get the (Emacs Calendar) diary entries for DATE."
  3994. (require 'diary-lib)
  3995. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3996. (diary-display-hook '(fancy-diary-display))
  3997. (diary-display-function 'fancy-diary-display)
  3998. (pop-up-frames nil)
  3999. (list-diary-entries-hook
  4000. (cons 'org-diary-default-entry list-diary-entries-hook))
  4001. (diary-file-name-prefix-function nil) ; turn this feature off
  4002. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4003. entries
  4004. (org-disable-agenda-to-diary t))
  4005. (save-excursion
  4006. (save-window-excursion
  4007. (funcall (if (fboundp 'diary-list-entries)
  4008. 'diary-list-entries 'list-diary-entries)
  4009. date 1)))
  4010. (if (not (get-buffer diary-fancy-buffer))
  4011. (setq entries nil)
  4012. (with-current-buffer diary-fancy-buffer
  4013. (setq buffer-read-only nil)
  4014. (if (zerop (buffer-size))
  4015. ;; No entries
  4016. (setq entries nil)
  4017. ;; Omit the date and other unnecessary stuff
  4018. (org-agenda-cleanup-fancy-diary)
  4019. ;; Add prefix to each line and extend the text properties
  4020. (if (zerop (buffer-size))
  4021. (setq entries nil)
  4022. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4023. (setq entries
  4024. (with-temp-buffer
  4025. (insert entries) (goto-char (point-min))
  4026. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4027. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4028. (replace-match (concat "; " (match-string 1)))))
  4029. (buffer-string)))))
  4030. (set-buffer-modified-p nil)
  4031. (kill-buffer diary-fancy-buffer)))
  4032. (when entries
  4033. (setq entries (org-split-string entries "\n"))
  4034. (setq entries
  4035. (mapcar
  4036. (lambda (x)
  4037. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4038. ;; Extend the text properties to the beginning of the line
  4039. (org-add-props x (text-properties-at (1- (length x)) x)
  4040. 'type "diary" 'date date 'face 'org-agenda-diary))
  4041. entries)))))
  4042. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4043. "Hook run when the fancy diary buffer is cleaned up.")
  4044. (defun org-agenda-cleanup-fancy-diary ()
  4045. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4046. This gets rid of the date, the underline under the date, and
  4047. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4048. date. It also removes lines that contain only whitespace."
  4049. (goto-char (point-min))
  4050. (if (looking-at ".*?:[ \t]*")
  4051. (progn
  4052. (replace-match "")
  4053. (re-search-forward "\n=+$" nil t)
  4054. (replace-match "")
  4055. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4056. (re-search-forward "\n=+$" nil t)
  4057. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4058. (goto-char (point-min))
  4059. (while (re-search-forward "^ +\n" nil t)
  4060. (replace-match ""))
  4061. (goto-char (point-min))
  4062. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4063. (replace-match ""))
  4064. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4065. ;; Make sure entries from the diary have the right text properties.
  4066. (eval-after-load "diary-lib"
  4067. '(if (boundp 'diary-modify-entry-list-string-function)
  4068. ;; We can rely on the hook, nothing to do
  4069. nil
  4070. ;; Hook not available, must use advice to make this work
  4071. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4072. "Make the position visible."
  4073. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4074. (stringp string)
  4075. buffer-file-name)
  4076. (setq string (org-modify-diary-entry-string string))))))
  4077. (defun org-modify-diary-entry-string (string)
  4078. "Add text properties to string, allowing org-mode to act on it."
  4079. (org-add-props string nil
  4080. 'mouse-face 'highlight
  4081. 'help-echo (if buffer-file-name
  4082. (format "mouse-2 or RET jump to diary file %s"
  4083. (abbreviate-file-name buffer-file-name))
  4084. "")
  4085. 'org-agenda-diary-link t
  4086. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4087. (defun org-diary-default-entry ()
  4088. "Add a dummy entry to the diary.
  4089. Needed to avoid empty dates which mess up holiday display."
  4090. ;; Catch the error if dealing with the new add-to-diary-alist
  4091. (when org-disable-agenda-to-diary
  4092. (condition-case nil
  4093. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4094. (error
  4095. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4096. (defun org-add-to-diary-list (&rest args)
  4097. (if (fboundp 'diary-add-to-list)
  4098. (apply 'diary-add-to-list args)
  4099. (apply 'add-to-diary-list args)))
  4100. (defvar org-diary-last-run-time nil)
  4101. ;;;###autoload
  4102. (defun org-diary (&rest args)
  4103. "Return diary information from org-files.
  4104. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4105. It accesses org files and extracts information from those files to be
  4106. listed in the diary. The function accepts arguments specifying what
  4107. items should be listed. For a list of arguments allowed here, see the
  4108. variable `org-agenda-entry-types'.
  4109. The call in the diary file should look like this:
  4110. &%%(org-diary) ~/path/to/some/orgfile.org
  4111. Use a separate line for each org file to check. Or, if you omit the file name,
  4112. all files listed in `org-agenda-files' will be checked automatically:
  4113. &%%(org-diary)
  4114. If you don't give any arguments (as in the example above), the default
  4115. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4116. So the example above may also be written as
  4117. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4118. The function expects the lisp variables `entry' and `date' to be provided
  4119. by the caller, because this is how the calendar works. Don't use this
  4120. function from a program - use `org-agenda-get-day-entries' instead."
  4121. (when (> (- (org-float-time)
  4122. org-agenda-last-marker-time)
  4123. 5)
  4124. (org-agenda-reset-markers))
  4125. (org-compile-prefix-format 'agenda)
  4126. (org-set-sorting-strategy 'agenda)
  4127. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4128. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4129. (list entry)
  4130. (org-agenda-files t)))
  4131. (time (org-float-time))
  4132. file rtn results)
  4133. (when (or (not org-diary-last-run-time)
  4134. (> (- time
  4135. org-diary-last-run-time)
  4136. 3))
  4137. (org-prepare-agenda-buffers files))
  4138. (setq org-diary-last-run-time time)
  4139. ;; If this is called during org-agenda, don't return any entries to
  4140. ;; the calendar. Org Agenda will list these entries itself.
  4141. (if org-disable-agenda-to-diary (setq files nil))
  4142. (while (setq file (pop files))
  4143. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4144. (setq results (append results rtn)))
  4145. (if results
  4146. (concat (org-finalize-agenda-entries results) "\n"))))
  4147. ;;; Agenda entry finders
  4148. (defun org-agenda-get-day-entries (file date &rest args)
  4149. "Does the work for `org-diary' and `org-agenda'.
  4150. FILE is the path to a file to be checked for entries. DATE is date like
  4151. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4152. which kind of entries should be extracted. For details about these, see
  4153. the documentation of `org-diary'."
  4154. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4155. (let* ((org-startup-folded nil)
  4156. (org-startup-align-all-tables nil)
  4157. (buffer (if (file-exists-p file)
  4158. (org-get-agenda-file-buffer file)
  4159. (error "No such file %s" file)))
  4160. arg results rtn deadline-results)
  4161. (if (not buffer)
  4162. ;; If file does not exist, make sure an error message ends up in diary
  4163. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4164. (with-current-buffer buffer
  4165. (unless (org-mode-p)
  4166. (error "Agenda file %s is not in `org-mode'" file))
  4167. (let ((case-fold-search nil))
  4168. (save-excursion
  4169. (save-restriction
  4170. (if org-agenda-restrict
  4171. (narrow-to-region org-agenda-restrict-begin
  4172. org-agenda-restrict-end)
  4173. (widen))
  4174. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4175. (while (setq arg (pop args))
  4176. (cond
  4177. ((and (eq arg :todo)
  4178. (equal date (calendar-gregorian-from-absolute
  4179. (org-today))))
  4180. (setq rtn (org-agenda-get-todos))
  4181. (setq results (append results rtn)))
  4182. ((eq arg :timestamp)
  4183. (setq rtn (org-agenda-get-blocks))
  4184. (setq results (append results rtn))
  4185. (setq rtn (org-agenda-get-timestamps))
  4186. (setq results (append results rtn)))
  4187. ((eq arg :sexp)
  4188. (setq rtn (org-agenda-get-sexps))
  4189. (setq results (append results rtn)))
  4190. ((eq arg :scheduled)
  4191. (setq rtn (org-agenda-get-scheduled deadline-results))
  4192. (setq results (append results rtn)))
  4193. ((eq arg :closed)
  4194. (setq rtn (org-agenda-get-progress))
  4195. (setq results (append results rtn)))
  4196. ((eq arg :deadline)
  4197. (setq rtn (org-agenda-get-deadlines))
  4198. (setq deadline-results (copy-sequence rtn))
  4199. (setq results (append results rtn))))))))
  4200. results))))
  4201. (defun org-agenda-get-todos ()
  4202. "Return the TODO information for agenda display."
  4203. (let* ((props (list 'face nil
  4204. 'done-face 'org-agenda-done
  4205. 'org-not-done-regexp org-not-done-regexp
  4206. 'org-todo-regexp org-todo-regexp
  4207. 'org-complex-heading-regexp org-complex-heading-regexp
  4208. 'mouse-face 'highlight
  4209. 'help-echo
  4210. (format "mouse-2 or RET jump to org file %s"
  4211. (abbreviate-file-name buffer-file-name))))
  4212. (regexp (concat "^\\*+[ \t]+\\("
  4213. (if org-select-this-todo-keyword
  4214. (if (equal org-select-this-todo-keyword "*")
  4215. org-todo-regexp
  4216. (concat "\\<\\("
  4217. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4218. "\\)\\>"))
  4219. org-not-done-regexp)
  4220. "[^\n\r]*\\)"))
  4221. marker priority category tags todo-state
  4222. ee txt beg end)
  4223. (goto-char (point-min))
  4224. (while (re-search-forward regexp nil t)
  4225. (catch :skip
  4226. (save-match-data
  4227. (beginning-of-line)
  4228. (org-agenda-skip)
  4229. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4230. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4231. (goto-char (1+ beg))
  4232. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4233. (throw :skip nil)))
  4234. (goto-char (match-beginning 1))
  4235. (setq marker (org-agenda-new-marker (match-beginning 0))
  4236. category (org-get-category)
  4237. txt (match-string 1)
  4238. tags (org-get-tags-at (point))
  4239. txt (org-format-agenda-item "" txt category tags)
  4240. priority (1+ (org-get-priority txt))
  4241. todo-state (org-get-todo-state))
  4242. (org-add-props txt props
  4243. 'org-marker marker 'org-hd-marker marker
  4244. 'priority priority 'org-category category
  4245. 'type "todo" 'todo-state todo-state)
  4246. (push txt ee)
  4247. (if org-agenda-todo-list-sublevels
  4248. (goto-char (match-end 1))
  4249. (org-end-of-subtree 'invisible))))
  4250. (nreverse ee)))
  4251. (defun org-agenda-todo-custom-ignore-p (time n)
  4252. "Check whether timestamp is farther away then n number of days.
  4253. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4254. `org-agenda-todo-ignore-scheduled' or
  4255. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4256. (let ((days (org-days-to-time time)))
  4257. (if (>= n 0)
  4258. (>= days n)
  4259. (<= days n))))
  4260. ;;;###autoload
  4261. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4262. (&optional end)
  4263. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4264. (when (or org-agenda-todo-ignore-with-date
  4265. org-agenda-todo-ignore-scheduled
  4266. org-agenda-todo-ignore-deadlines
  4267. org-agenda-todo-ignore-timestamp)
  4268. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4269. (save-excursion
  4270. (or (and org-agenda-todo-ignore-with-date
  4271. (re-search-forward org-ts-regexp end t))
  4272. (and org-agenda-todo-ignore-scheduled
  4273. (re-search-forward org-scheduled-time-regexp end t)
  4274. (cond
  4275. ((eq org-agenda-todo-ignore-scheduled 'future)
  4276. (> (org-days-to-time (match-string 1)) 0))
  4277. ((eq org-agenda-todo-ignore-scheduled 'past)
  4278. (<= (org-days-to-time (match-string 1)) 0))
  4279. ((numberp org-agenda-todo-ignore-scheduled)
  4280. (org-agenda-todo-custom-ignore-p
  4281. (match-string 1) org-agenda-todo-ignore-scheduled))
  4282. (t)))
  4283. (and org-agenda-todo-ignore-deadlines
  4284. (re-search-forward org-deadline-time-regexp end t)
  4285. (cond
  4286. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4287. ((eq org-agenda-todo-ignore-deadlines 'far)
  4288. (not (org-deadline-close (match-string 1))))
  4289. ((eq org-agenda-todo-ignore-deadlines 'future)
  4290. (> (org-days-to-time (match-string 1)) 0))
  4291. ((eq org-agenda-todo-ignore-deadlines 'past)
  4292. (<= (org-days-to-time (match-string 1)) 0))
  4293. ((numberp org-agenda-todo-ignore-deadlines)
  4294. (org-agenda-todo-custom-ignore-p
  4295. (match-string 1) org-agenda-todo-ignore-deadlines))
  4296. (t (org-deadline-close (match-string 1)))))
  4297. (and org-agenda-todo-ignore-timestamp
  4298. (let ((buffer (current-buffer))
  4299. (regexp
  4300. (concat
  4301. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4302. (start (point)))
  4303. ;; Copy current buffer into a temporary one
  4304. (with-temp-buffer
  4305. (insert-buffer-substring buffer start end)
  4306. (goto-char (point-min))
  4307. ;; Delete SCHEDULED and DEADLINE items
  4308. (while (re-search-forward regexp end t)
  4309. (delete-region (match-beginning 0) (match-end 0)))
  4310. (goto-char (point-min))
  4311. ;; No search for timestamp left
  4312. (when (re-search-forward org-ts-regexp nil t)
  4313. (cond
  4314. ((eq org-agenda-todo-ignore-timestamp 'future)
  4315. (> (org-days-to-time (match-string 1)) 0))
  4316. ((eq org-agenda-todo-ignore-timestamp 'past)
  4317. (<= (org-days-to-time (match-string 1)) 0))
  4318. ((numberp org-agenda-todo-ignore-timestamp)
  4319. (org-agenda-todo-custom-ignore-p
  4320. (match-string 1) org-agenda-todo-ignore-timestamp))
  4321. (t))))))))))
  4322. (defconst org-agenda-no-heading-message
  4323. "No heading for this item in buffer or region.")
  4324. (defun org-agenda-get-timestamps ()
  4325. "Return the date stamp information for agenda display."
  4326. (let* ((props (list 'face nil
  4327. 'org-not-done-regexp org-not-done-regexp
  4328. 'org-todo-regexp org-todo-regexp
  4329. 'org-complex-heading-regexp org-complex-heading-regexp
  4330. 'mouse-face 'highlight
  4331. 'help-echo
  4332. (format "mouse-2 or RET jump to org file %s"
  4333. (abbreviate-file-name buffer-file-name))))
  4334. (d1 (calendar-absolute-from-gregorian date))
  4335. (remove-re
  4336. (concat
  4337. (regexp-quote
  4338. (format-time-string
  4339. "<%Y-%m-%d"
  4340. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4341. ".*?>"))
  4342. (regexp
  4343. (concat
  4344. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4345. (regexp-quote
  4346. (substring
  4347. (format-time-string
  4348. (car org-time-stamp-formats)
  4349. (apply 'encode-time ; DATE bound by calendar
  4350. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4351. 1 11))
  4352. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4353. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4354. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4355. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4356. todo-state end-of-match show-all)
  4357. (goto-char (point-min))
  4358. (while (setq end-of-match (re-search-forward regexp nil t))
  4359. (setq b0 (match-beginning 0)
  4360. b3 (match-beginning 3) e3 (match-end 3)
  4361. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4362. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4363. (member todo-state
  4364. org-agenda-repeating-timestamp-show-all)))
  4365. (catch :skip
  4366. (and (org-at-date-range-p) (throw :skip nil))
  4367. (org-agenda-skip)
  4368. (if (and (match-end 1)
  4369. (not (= d1 (org-time-string-to-absolute
  4370. (match-string 1) d1 nil show-all))))
  4371. (throw :skip nil))
  4372. (if (and e3
  4373. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4374. (throw :skip nil))
  4375. (setq tmp (buffer-substring (max (point-min)
  4376. (- b0 org-ds-keyword-length))
  4377. b0)
  4378. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4379. inactivep (= (char-after b0) ?\[)
  4380. deadlinep (string-match org-deadline-regexp tmp)
  4381. scheduledp (string-match org-scheduled-regexp tmp)
  4382. closedp (and org-agenda-include-inactive-timestamps
  4383. (string-match org-closed-string tmp))
  4384. clockp (and org-agenda-include-inactive-timestamps
  4385. (or (string-match org-clock-string tmp)
  4386. (string-match "]-+\\'" tmp)))
  4387. donep (member todo-state org-done-keywords))
  4388. (if (or scheduledp deadlinep closedp clockp
  4389. (and donep org-agenda-skip-timestamp-if-done))
  4390. (throw :skip t))
  4391. (if (string-match ">" timestr)
  4392. ;; substring should only run to end of time stamp
  4393. (setq timestr (substring timestr 0 (match-end 0))))
  4394. (setq marker (org-agenda-new-marker b0)
  4395. category (org-get-category b0))
  4396. (save-excursion
  4397. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4398. (setq txt org-agenda-no-heading-message)
  4399. (goto-char (match-beginning 0))
  4400. (setq hdmarker (org-agenda-new-marker)
  4401. tags (org-get-tags-at))
  4402. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4403. (setq head (or (match-string 1) ""))
  4404. (setq txt (org-format-agenda-item
  4405. (if inactivep org-agenda-inactive-leader nil)
  4406. head category tags timestr
  4407. remove-re)))
  4408. (setq priority (org-get-priority txt))
  4409. (org-add-props txt props
  4410. 'org-marker marker 'org-hd-marker hdmarker)
  4411. (org-add-props txt nil 'priority priority
  4412. 'org-category category 'date date
  4413. 'todo-state todo-state
  4414. 'type "timestamp")
  4415. (push txt ee))
  4416. (if org-agenda-skip-additional-timestamps-same-entry
  4417. (outline-next-heading)
  4418. (goto-char end-of-match))))
  4419. (nreverse ee)))
  4420. (defun org-agenda-get-sexps ()
  4421. "Return the sexp information for agenda display."
  4422. (require 'diary-lib)
  4423. (let* ((props (list 'mouse-face 'highlight
  4424. 'help-echo
  4425. (format "mouse-2 or RET jump to org file %s"
  4426. (abbreviate-file-name buffer-file-name))))
  4427. (regexp "^&?%%(")
  4428. marker category ee txt tags entry result beg b sexp sexp-entry
  4429. todo-state)
  4430. (goto-char (point-min))
  4431. (while (re-search-forward regexp nil t)
  4432. (catch :skip
  4433. (org-agenda-skip)
  4434. (setq beg (match-beginning 0))
  4435. (goto-char (1- (match-end 0)))
  4436. (setq b (point))
  4437. (forward-sexp 1)
  4438. (setq sexp (buffer-substring b (point)))
  4439. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4440. (org-trim (match-string 1))
  4441. ""))
  4442. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4443. (when result
  4444. (setq marker (org-agenda-new-marker beg)
  4445. category (org-get-category beg)
  4446. todo-state (org-get-todo-state))
  4447. (dolist (r (if (stringp result)
  4448. (list result)
  4449. result)) ;; we expect a list here
  4450. (if (string-match "\\S-" r)
  4451. (setq txt r)
  4452. (setq txt "SEXP entry returned empty string"))
  4453. (setq txt (org-format-agenda-item
  4454. "" txt category tags 'time))
  4455. (org-add-props txt props 'org-marker marker)
  4456. (org-add-props txt nil
  4457. 'org-category category 'date date 'todo-state todo-state
  4458. 'type "sexp")
  4459. (push txt ee)))))
  4460. (nreverse ee)))
  4461. ;; Calendar sanity: define some functions that are independent of
  4462. ;; `calendar-date-style'.
  4463. ;; Normally I would like to use ISO format when calling the diary functions,
  4464. ;; but to make sure we still have Emacs 22 compatibility we bind
  4465. ;; also `european-calendar-style' and use european format
  4466. (defun org-anniversary (year month day &optional mark)
  4467. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4468. (org-no-warnings
  4469. (let ((calendar-date-style 'european) (european-calendar-style t))
  4470. (diary-anniversary day month year mark))))
  4471. (defun org-cyclic (N year month day &optional mark)
  4472. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4473. (org-no-warnings
  4474. (let ((calendar-date-style 'european) (european-calendar-style t))
  4475. (diary-cyclic N day month year mark))))
  4476. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4477. "Like `diary-block', but with fixed (ISO) order of arguments."
  4478. (org-no-warnings
  4479. (let ((calendar-date-style 'european) (european-calendar-style t))
  4480. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4481. (defun org-date (year month day &optional mark)
  4482. "Like `diary-date', but with fixed (ISO) order of arguments."
  4483. (org-no-warnings
  4484. (let ((calendar-date-style 'european) (european-calendar-style t))
  4485. (diary-date day month year mark))))
  4486. (defalias 'org-float 'diary-float)
  4487. ;; Define the` org-class' function
  4488. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4489. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4490. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4491. is any number of ISO weeks in the block period for which the item should
  4492. be skipped."
  4493. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4494. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4495. (d (calendar-absolute-from-gregorian date)))
  4496. (and
  4497. (<= date1 d)
  4498. (<= d date2)
  4499. (= (calendar-day-of-week date) dayname)
  4500. (or (not skip-weeks)
  4501. (progn
  4502. (require 'cal-iso)
  4503. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4504. entry)))
  4505. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4506. "Like `org-class', but honor `calendar-date-style'.
  4507. The order of the first 2 times 3 arguments depends on the variable
  4508. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4509. So for American calendars, give this as MONTH DAY YEAR, for European as
  4510. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4511. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4512. is any number of ISO weeks in the block period for which the item should
  4513. be skipped.
  4514. This function is here only for backward compatibility and it is deprecated,
  4515. please use `org-class' instead."
  4516. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4517. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4518. (org-class
  4519. (nth 2 date1) (car date1) (nth 1 date1)
  4520. (nth 2 date2) (car date2) (nth 1 date2)
  4521. dayname skip-weeks)))
  4522. (defalias 'org-get-closed 'org-agenda-get-progress)
  4523. (defun org-agenda-get-progress ()
  4524. "Return the logged TODO entries for agenda display."
  4525. (let* ((props (list 'mouse-face 'highlight
  4526. 'org-not-done-regexp org-not-done-regexp
  4527. 'org-todo-regexp org-todo-regexp
  4528. 'org-complex-heading-regexp org-complex-heading-regexp
  4529. 'help-echo
  4530. (format "mouse-2 or RET jump to org file %s"
  4531. (abbreviate-file-name buffer-file-name))))
  4532. (items (if (consp org-agenda-show-log)
  4533. org-agenda-show-log
  4534. (if (eq org-agenda-show-log 'clockcheck)
  4535. '(clock)
  4536. org-agenda-log-mode-items)))
  4537. (parts
  4538. (delq nil
  4539. (list
  4540. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4541. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4542. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4543. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4544. (error "`org-agenda-log-mode-items' is empty")))
  4545. (regexp (concat
  4546. "\\(" parts-re "\\)"
  4547. " *\\["
  4548. (regexp-quote
  4549. (substring
  4550. (format-time-string
  4551. (car org-time-stamp-formats)
  4552. (apply 'encode-time ; DATE bound by calendar
  4553. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4554. 1 11))))
  4555. (org-agenda-search-headline-for-time nil)
  4556. marker hdmarker priority category tags closedp statep clockp state
  4557. ee txt extra timestr rest clocked)
  4558. (goto-char (point-min))
  4559. (while (re-search-forward regexp nil t)
  4560. (catch :skip
  4561. (org-agenda-skip)
  4562. (setq marker (org-agenda-new-marker (match-beginning 0))
  4563. closedp (equal (match-string 1) org-closed-string)
  4564. statep (equal (string-to-char (match-string 1)) ?-)
  4565. clockp (not (or closedp statep))
  4566. state (and statep (match-string 2))
  4567. category (org-get-category (match-beginning 0))
  4568. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4569. )
  4570. (when (string-match "\\]" timestr)
  4571. ;; substring should only run to end of time stamp
  4572. (setq rest (substring timestr (match-end 0))
  4573. timestr (substring timestr 0 (match-end 0)))
  4574. (if (and (not closedp) (not statep)
  4575. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4576. (progn (setq timestr (concat (substring timestr 0 -1)
  4577. "-" (match-string 1 rest) "]"))
  4578. (setq clocked (match-string 2 rest)))
  4579. (setq clocked "-")))
  4580. (save-excursion
  4581. (setq extra
  4582. (cond
  4583. ((not org-agenda-log-mode-add-notes) nil)
  4584. (statep
  4585. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4586. (match-string 1)))
  4587. (clockp
  4588. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4589. (match-string 1)))))
  4590. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4591. (setq txt org-agenda-no-heading-message)
  4592. (goto-char (match-beginning 0))
  4593. (setq hdmarker (org-agenda-new-marker)
  4594. tags (org-get-tags-at))
  4595. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4596. (setq txt (match-string 1))
  4597. (when extra
  4598. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4599. (setq txt (concat (substring txt 0 (match-beginning 1))
  4600. " - " extra " " (match-string 2 txt)))
  4601. (setq txt (concat txt " - " extra))))
  4602. (setq txt (org-format-agenda-item
  4603. (cond
  4604. (closedp "Closed: ")
  4605. (statep (concat "State: (" state ")"))
  4606. (t (concat "Clocked: (" clocked ")")))
  4607. txt category tags timestr)))
  4608. (setq priority 100000)
  4609. (org-add-props txt props
  4610. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4611. 'priority priority 'org-category category
  4612. 'type "closed" 'date date
  4613. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4614. (push txt ee))
  4615. (goto-char (point-at-eol))))
  4616. (nreverse ee)))
  4617. (defun org-agenda-show-clocking-issues ()
  4618. "Add overlays, showing issues with clocking.
  4619. See also the user option `org-agenda-clock-consistency-checks'."
  4620. (interactive)
  4621. (let* ((pl org-agenda-clock-consistency-checks)
  4622. (re (concat "^[ \t]*"
  4623. org-clock-string
  4624. "[ \t]+"
  4625. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4626. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4627. (tlstart 0.)
  4628. (tlend 0.)
  4629. (maxtime (org-hh:mm-string-to-minutes
  4630. (or (plist-get pl :max-duration) "24:00")))
  4631. (mintime (org-hh:mm-string-to-minutes
  4632. (or (plist-get pl :min-duration) 0)))
  4633. (maxgap (org-hh:mm-string-to-minutes
  4634. ;; default 30:00 means never complain
  4635. (or (plist-get pl :max-gap) "30:00")))
  4636. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4637. (plist-get pl :gap-ok-around)))
  4638. (def-face (or (plist-get pl :default-face)
  4639. '((:background "DarkRed") (:foreground "white"))))
  4640. issue face m te ts dt ov)
  4641. (goto-char (point-min))
  4642. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4643. (setq issue nil face def-face)
  4644. (catch 'next
  4645. (setq m (org-get-at-bol 'org-marker)
  4646. te nil ts nil)
  4647. (unless (and m (markerp m))
  4648. (setq issue "No valid clock line") (throw 'next t))
  4649. (org-with-point-at m
  4650. (save-excursion
  4651. (goto-char (point-at-bol))
  4652. (unless (looking-at re)
  4653. (error "No valid Clock line")
  4654. (throw 'next t))
  4655. (unless (match-end 3)
  4656. (setq issue "No end time"
  4657. face (or (plist-get pl :no-end-time-face) face))
  4658. (throw 'next t))
  4659. (setq ts (match-string 1)
  4660. te (match-string 3)
  4661. ts (org-float-time
  4662. (apply 'encode-time (org-parse-time-string ts)))
  4663. te (org-float-time
  4664. (apply 'encode-time (org-parse-time-string te)))
  4665. dt (- te ts))))
  4666. (cond
  4667. ((> dt (* 60 maxtime))
  4668. ;; a very long clocking chunk
  4669. (setq issue (format "Clocking interval is very long: %s"
  4670. (org-minutes-to-hh:mm-string
  4671. (floor (/ (float dt) 60.))))
  4672. face (or (plist-get pl :long-face) face)))
  4673. ((< dt (* 60 mintime))
  4674. ;; a very short clocking chunk
  4675. (setq issue (format "Clocking interval is very short: %s"
  4676. (org-minutes-to-hh:mm-string
  4677. (floor (/ (float dt) 60.))))
  4678. face (or (plist-get pl :short-face) face)))
  4679. ((and (> tlend 0) (< ts tlend))
  4680. ;; Two clock entries are overlapping
  4681. (setq issue (format "Clocking overlap: %d minutes"
  4682. (/ (- tlend ts) 60))
  4683. face (or (plist-get pl :overlap-face) face)))
  4684. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4685. ;; There is a gap, lets see if we need to report it
  4686. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4687. (setq issue (format "Clocking gap: %d minutes"
  4688. (/ (- ts tlend) 60))
  4689. face (or (plist-get pl :gap-face) face))))
  4690. (t nil)))
  4691. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4692. (when issue
  4693. ;; OK, there was some issue, add an overlay to show the issue
  4694. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4695. (overlay-put ov 'before-string
  4696. (concat
  4697. (org-add-props
  4698. (format "%-43s" (concat " " issue))
  4699. nil
  4700. 'face face)
  4701. "\n"))
  4702. (overlay-put ov 'evaporate t)))))
  4703. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4704. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4705. (catch 'exit
  4706. (unless ok-list
  4707. ;; there are no OK times for gaps...
  4708. (throw 'exit nil))
  4709. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4710. ;; This is more than 24 hours, so it is OK.
  4711. ;; because we have at least one OK time, that must be in the
  4712. ;; 24 hour interval.
  4713. (throw 'exit t))
  4714. ;; We have a shorter gap.
  4715. ;; Now we have to get the minute of the day when these times are
  4716. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4717. (t2dec (decode-time (seconds-to-time t2)))
  4718. ;; compute the minute on the day
  4719. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4720. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4721. (when (< min2 min1)
  4722. ;; if min2 is smaller than min1, this means it is on the next day.
  4723. ;; Wrap it to after midnight.
  4724. (setq min2 (+ min2 1440)))
  4725. ;; Now check if any of the OK times is in the gap
  4726. (mapc (lambda (x)
  4727. ;; Wrap the time to after midnight if necessary
  4728. (if (< x min1) (setq x (+ x 1440)))
  4729. ;; Check if in interval
  4730. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4731. ok-list)
  4732. ;; Nope, this gap is not OK
  4733. nil)))
  4734. (defun org-agenda-get-deadlines ()
  4735. "Return the deadline information for agenda display."
  4736. (let* ((props (list 'mouse-face 'highlight
  4737. 'org-not-done-regexp org-not-done-regexp
  4738. 'org-todo-regexp org-todo-regexp
  4739. 'org-complex-heading-regexp org-complex-heading-regexp
  4740. 'help-echo
  4741. (format "mouse-2 or RET jump to org file %s"
  4742. (abbreviate-file-name buffer-file-name))))
  4743. (regexp org-deadline-time-regexp)
  4744. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4745. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4746. d2 diff dfrac wdays pos pos1 category tags
  4747. suppress-prewarning
  4748. ee txt head face s todo-state show-all upcomingp donep timestr)
  4749. (goto-char (point-min))
  4750. (while (re-search-forward regexp nil t)
  4751. (setq suppress-prewarning nil)
  4752. (catch :skip
  4753. (org-agenda-skip)
  4754. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4755. (save-match-data
  4756. (string-match org-scheduled-time-regexp
  4757. (buffer-substring (point-at-bol)
  4758. (point-at-eol)))))
  4759. (setq suppress-prewarning
  4760. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4761. org-agenda-skip-deadline-prewarning-if-scheduled
  4762. 0)))
  4763. (setq s (match-string 1)
  4764. txt nil
  4765. pos (1- (match-beginning 1))
  4766. todo-state (save-match-data (org-get-todo-state))
  4767. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4768. (member todo-state
  4769. org-agenda-repeating-timestamp-show-all))
  4770. d2 (org-time-string-to-absolute
  4771. (match-string 1) d1 'past show-all)
  4772. diff (- d2 d1)
  4773. wdays (if suppress-prewarning
  4774. (let ((org-deadline-warning-days suppress-prewarning))
  4775. (org-get-wdays s))
  4776. (org-get-wdays s))
  4777. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4778. upcomingp (and todayp (> diff 0)))
  4779. ;; When to show a deadline in the calendar:
  4780. ;; If the expiration is within wdays warning time.
  4781. ;; Past-due deadlines are only shown on the current date
  4782. (if (and (or (and (<= diff wdays)
  4783. (and todayp (not org-agenda-only-exact-dates)))
  4784. (= diff 0)))
  4785. (save-excursion
  4786. ;; (setq todo-state (org-get-todo-state))
  4787. (setq donep (member todo-state org-done-keywords))
  4788. (if (and donep
  4789. (or org-agenda-skip-deadline-if-done
  4790. (not (= diff 0))))
  4791. (setq txt nil)
  4792. (setq category (org-get-category))
  4793. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4794. (setq txt org-agenda-no-heading-message)
  4795. (goto-char (match-end 0))
  4796. (setq pos1 (match-beginning 0))
  4797. (setq tags (org-get-tags-at pos1))
  4798. (setq head (buffer-substring-no-properties
  4799. (point)
  4800. (progn (skip-chars-forward "^\r\n")
  4801. (point))))
  4802. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4803. (setq timestr
  4804. (concat (substring s (match-beginning 1)) " "))
  4805. (setq timestr 'time))
  4806. (setq txt (org-format-agenda-item
  4807. (if (= diff 0)
  4808. (car org-agenda-deadline-leaders)
  4809. (if (functionp
  4810. (nth 1 org-agenda-deadline-leaders))
  4811. (funcall
  4812. (nth 1 org-agenda-deadline-leaders)
  4813. diff date)
  4814. (format (nth 1 org-agenda-deadline-leaders)
  4815. diff)))
  4816. head category tags
  4817. (if (not (= diff 0)) nil timestr)))))
  4818. (when txt
  4819. (setq face (org-agenda-deadline-face dfrac))
  4820. (org-add-props txt props
  4821. 'org-marker (org-agenda-new-marker pos)
  4822. 'org-hd-marker (org-agenda-new-marker pos1)
  4823. 'priority (+ (- diff)
  4824. (org-get-priority txt))
  4825. 'org-category category
  4826. 'todo-state todo-state
  4827. 'type (if upcomingp "upcoming-deadline" "deadline")
  4828. 'date (if upcomingp date d2)
  4829. 'face (if donep 'org-agenda-done face)
  4830. 'undone-face face 'done-face 'org-agenda-done)
  4831. (push txt ee))))))
  4832. (nreverse ee)))
  4833. (defun org-agenda-deadline-face (fraction)
  4834. "Return the face to displaying a deadline item.
  4835. FRACTION is what fraction of the head-warning time has passed."
  4836. (let ((faces org-agenda-deadline-faces) f)
  4837. (catch 'exit
  4838. (while (setq f (pop faces))
  4839. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4840. (defun org-agenda-get-scheduled (&optional deadline-results)
  4841. "Return the scheduled information for agenda display."
  4842. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4843. 'org-todo-regexp org-todo-regexp
  4844. 'org-complex-heading-regexp org-complex-heading-regexp
  4845. 'done-face 'org-agenda-done
  4846. 'mouse-face 'highlight
  4847. 'help-echo
  4848. (format "mouse-2 or RET jump to org file %s"
  4849. (abbreviate-file-name buffer-file-name))))
  4850. (regexp org-scheduled-time-regexp)
  4851. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4852. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4853. mm
  4854. (deadline-position-alist
  4855. (mapcar (lambda (a) (and (setq mm (get-text-property
  4856. 0 'org-hd-marker a))
  4857. (cons (marker-position mm) a)))
  4858. deadline-results))
  4859. d2 diff pos pos1 category tags donep
  4860. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4861. (goto-char (point-min))
  4862. (while (re-search-forward regexp nil t)
  4863. (catch :skip
  4864. (org-agenda-skip)
  4865. (setq s (match-string 1)
  4866. txt nil
  4867. pos (1- (match-beginning 1))
  4868. todo-state (save-match-data (org-get-todo-state))
  4869. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4870. (member todo-state
  4871. org-agenda-repeating-timestamp-show-all))
  4872. d2 (org-time-string-to-absolute
  4873. (match-string 1) d1 'past show-all)
  4874. diff (- d2 d1))
  4875. (setq pastschedp (and todayp (< diff 0)))
  4876. ;; When to show a scheduled item in the calendar:
  4877. ;; If it is on or past the date.
  4878. (when (or (and (< diff 0)
  4879. (< (abs diff) org-scheduled-past-days)
  4880. (and todayp (not org-agenda-only-exact-dates)))
  4881. (= diff 0))
  4882. (save-excursion
  4883. (setq donep (member todo-state org-done-keywords))
  4884. (if (and donep
  4885. (or org-agenda-skip-scheduled-if-done
  4886. (not (= diff 0))
  4887. (and (functionp 'org-is-habit-p)
  4888. (org-is-habit-p))))
  4889. (setq txt nil)
  4890. (setq habitp (and (functionp 'org-is-habit-p)
  4891. (org-is-habit-p)))
  4892. (setq category (org-get-category))
  4893. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4894. (setq txt org-agenda-no-heading-message)
  4895. (goto-char (match-end 0))
  4896. (setq pos1 (match-beginning 0))
  4897. (if habitp
  4898. (if (or (not org-habit-show-habits)
  4899. (and (not todayp)
  4900. org-habit-show-habits-only-for-today))
  4901. (throw :skip nil))
  4902. (if (and
  4903. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4904. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4905. pastschedp))
  4906. (setq mm (assoc pos1 deadline-position-alist)))
  4907. (throw :skip nil)))
  4908. (setq tags (org-get-tags-at))
  4909. (setq head (buffer-substring-no-properties
  4910. (point)
  4911. (progn (skip-chars-forward "^\r\n") (point))))
  4912. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4913. (setq timestr
  4914. (concat (substring s (match-beginning 1)) " "))
  4915. (setq timestr 'time))
  4916. (setq txt (org-format-agenda-item
  4917. (if (= diff 0)
  4918. (car org-agenda-scheduled-leaders)
  4919. (format (nth 1 org-agenda-scheduled-leaders)
  4920. (- 1 diff)))
  4921. head category tags
  4922. (if (not (= diff 0)) nil timestr)
  4923. nil habitp))))
  4924. (when txt
  4925. (setq face
  4926. (cond
  4927. ((and (not habitp) pastschedp)
  4928. 'org-scheduled-previously)
  4929. (todayp 'org-scheduled-today)
  4930. (t 'org-scheduled))
  4931. habitp (and habitp (org-habit-parse-todo)))
  4932. (org-add-props txt props
  4933. 'undone-face face
  4934. 'face (if donep 'org-agenda-done face)
  4935. 'org-marker (org-agenda-new-marker pos)
  4936. 'org-hd-marker (org-agenda-new-marker pos1)
  4937. 'type (if pastschedp "past-scheduled" "scheduled")
  4938. 'date (if pastschedp d2 date)
  4939. 'priority (if habitp
  4940. (org-habit-get-priority habitp)
  4941. (+ 94 (- 5 diff) (org-get-priority txt)))
  4942. 'org-category category
  4943. 'org-habit-p habitp
  4944. 'todo-state todo-state)
  4945. (push txt ee))))))
  4946. (nreverse ee)))
  4947. (defun org-agenda-get-blocks ()
  4948. "Return the date-range information for agenda display."
  4949. (let* ((props (list 'face nil
  4950. 'org-not-done-regexp org-not-done-regexp
  4951. 'org-todo-regexp org-todo-regexp
  4952. 'org-complex-heading-regexp org-complex-heading-regexp
  4953. 'mouse-face 'highlight
  4954. 'help-echo
  4955. (format "mouse-2 or RET jump to org file %s"
  4956. (abbreviate-file-name buffer-file-name))))
  4957. (regexp org-tr-regexp)
  4958. (d0 (calendar-absolute-from-gregorian date))
  4959. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4960. head donep)
  4961. (goto-char (point-min))
  4962. (while (re-search-forward regexp nil t)
  4963. (catch :skip
  4964. (org-agenda-skip)
  4965. (setq pos (point))
  4966. (let ((start-time (match-string 1))
  4967. (end-time (match-string 2)))
  4968. (setq s1 (match-string 1)
  4969. s2 (match-string 2)
  4970. d1 (time-to-days (org-time-string-to-time s1))
  4971. d2 (time-to-days (org-time-string-to-time s2)))
  4972. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4973. ;; Only allow days between the limits, because the normal
  4974. ;; date stamps will catch the limits.
  4975. (save-excursion
  4976. (setq todo-state (org-get-todo-state))
  4977. (setq donep (member todo-state org-done-keywords))
  4978. (if (and donep org-agenda-skip-timestamp-if-done)
  4979. (throw :skip t))
  4980. (setq marker (org-agenda-new-marker (point)))
  4981. (setq category (org-get-category))
  4982. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4983. (setq txt org-agenda-no-heading-message)
  4984. (goto-char (match-beginning 0))
  4985. (setq hdmarker (org-agenda-new-marker (point)))
  4986. (setq tags (org-get-tags-at))
  4987. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4988. (setq head (match-string 1))
  4989. (let ((remove-re
  4990. (if org-agenda-remove-timeranges-from-blocks
  4991. (concat
  4992. "<" (regexp-quote s1) ".*?>"
  4993. "--"
  4994. "<" (regexp-quote s2) ".*?>")
  4995. nil)))
  4996. (setq txt (org-format-agenda-item
  4997. (format
  4998. (nth (if (= d1 d2) 0 1)
  4999. org-agenda-timerange-leaders)
  5000. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5001. head category tags
  5002. (cond ((= d1 d0)
  5003. (concat "<" start-time ">"))
  5004. ((= d2 d0)
  5005. (concat "<" end-time ">"))
  5006. (t nil))
  5007. remove-re))))
  5008. (org-add-props txt props
  5009. 'org-marker marker 'org-hd-marker hdmarker
  5010. 'type "block" 'date date
  5011. 'todo-state todo-state
  5012. 'priority (org-get-priority txt) 'org-category category)
  5013. (push txt ee))))
  5014. (goto-char pos)))
  5015. ;; Sort the entries by expiration date.
  5016. (nreverse ee)))
  5017. ;;; Agenda presentation and sorting
  5018. (defvar org-prefix-has-time nil
  5019. "A flag, set by `org-compile-prefix-format'.
  5020. The flag is set if the currently compiled format contains a `%t'.")
  5021. (defvar org-prefix-has-tag nil
  5022. "A flag, set by `org-compile-prefix-format'.
  5023. The flag is set if the currently compiled format contains a `%T'.")
  5024. (defvar org-prefix-has-effort nil
  5025. "A flag, set by `org-compile-prefix-format'.
  5026. The flag is set if the currently compiled format contains a `%e'.")
  5027. (defvar org-prefix-category-length nil
  5028. "Used by `org-compile-prefix-format' to remember the category field width.")
  5029. (defvar org-prefix-category-max-length nil
  5030. "Used by `org-compile-prefix-format' to remember the category field width.")
  5031. (defun org-agenda-get-category-icon (category)
  5032. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5033. (dolist (entry org-agenda-category-icon-alist)
  5034. (when (org-string-match-p (car entry) category)
  5035. (if (listp (cadr entry))
  5036. (return (cadr entry))
  5037. (return (apply 'create-image (cdr entry)))))))
  5038. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5039. remove-re habitp)
  5040. "Format TXT to be inserted into the agenda buffer.
  5041. In particular, it adds the prefix and corresponding text properties. EXTRA
  5042. must be a string and replaces the `%s' specifier in the prefix format.
  5043. CATEGORY (string, symbol or nil) may be used to overrule the default
  5044. category taken from local variable or file name. It will replace the `%c'
  5045. specifier in the format. DOTIME, when non-nil, indicates that a
  5046. time-of-day should be extracted from TXT for sorting of this entry, and for
  5047. the `%t' specifier in the format. When DOTIME is a string, this string is
  5048. searched for a time before TXT is. TAGS can be the tags of the headline.
  5049. Any match of REMOVE-RE will be removed from TXT."
  5050. (save-match-data
  5051. ;; Diary entries sometimes have extra whitespace at the beginning
  5052. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5053. ;; Fix the tags part in txt
  5054. (setq txt (org-agenda-fix-displayed-tags
  5055. txt tags
  5056. org-agenda-show-inherited-tags
  5057. org-agenda-hide-tags-regexp))
  5058. (let* ((category (or category
  5059. (if (stringp org-category)
  5060. org-category
  5061. (and org-category (symbol-name org-category)))
  5062. (if buffer-file-name
  5063. (file-name-sans-extension
  5064. (file-name-nondirectory buffer-file-name))
  5065. "")))
  5066. (category-icon (org-agenda-get-category-icon category))
  5067. (category-icon (if category-icon
  5068. (propertize " " 'display category-icon)
  5069. ""))
  5070. ;; time, tag, effort are needed for the eval of the prefix format
  5071. (tag (if tags (nth (1- (length tags)) tags) ""))
  5072. time effort neffort
  5073. (ts (if dotime (concat
  5074. (if (stringp dotime) dotime "")
  5075. (and org-agenda-search-headline-for-time txt))))
  5076. (time-of-day (and dotime (org-get-time-of-day ts)))
  5077. stamp plain s0 s1 s2 rtn srp l
  5078. duration thecategory)
  5079. (and (org-mode-p) buffer-file-name
  5080. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5081. (when (and dotime time-of-day)
  5082. ;; Extract starting and ending time and move them to prefix
  5083. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5084. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5085. (setq s0 (match-string 0 ts)
  5086. srp (and stamp (match-end 3))
  5087. s1 (match-string (if plain 1 2) ts)
  5088. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5089. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5090. ;; them, we might want to remove them there to avoid duplication.
  5091. ;; The user can turn this off with a variable.
  5092. (if (and org-prefix-has-time
  5093. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5094. (string-match (concat (regexp-quote s0) " *") txt)
  5095. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5096. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5097. (= (match-beginning 0) 0)
  5098. t))
  5099. (setq txt (replace-match "" nil nil txt))))
  5100. ;; Normalize the time(s) to 24 hour
  5101. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5102. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5103. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5104. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5105. (setq s2
  5106. (org-minutes-to-hh:mm-string
  5107. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5108. ;; Compute the duration
  5109. (when s2
  5110. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5111. (org-hh:mm-string-to-minutes s1)))))
  5112. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5113. txt)
  5114. ;; Tags are in the string
  5115. (if (or (eq org-agenda-remove-tags t)
  5116. (and org-agenda-remove-tags
  5117. org-prefix-has-tag))
  5118. (setq txt (replace-match "" t t txt))
  5119. (setq txt (replace-match
  5120. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5121. (match-string 2 txt))
  5122. t t txt))))
  5123. (when (org-mode-p)
  5124. (setq effort
  5125. (condition-case nil
  5126. (org-get-effort
  5127. (or (get-text-property 0 'org-hd-marker txt)
  5128. (get-text-property 0 'org-marker txt)))
  5129. (error nil)))
  5130. (when effort
  5131. (setq neffort (org-duration-string-to-minutes effort)
  5132. effort (setq effort (concat "[" effort "]")))))
  5133. ;; prevent erroring out with %e format when there is no effort
  5134. (or effort (setq effort ""))
  5135. (when remove-re
  5136. (while (string-match remove-re txt)
  5137. (setq txt (replace-match "" t t txt))))
  5138. ;; Set org-heading property on `txt' to mark the start of the
  5139. ;; heading.
  5140. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5141. ;; Prepare the variables needed in the eval of the compiled format
  5142. (setq time (cond (s2 (concat
  5143. (org-agenda-time-of-day-to-ampm-maybe s1)
  5144. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5145. (if org-agenda-timegrid-use-ampm " ")))
  5146. (s1 (concat
  5147. (org-agenda-time-of-day-to-ampm-maybe s1)
  5148. (if org-agenda-timegrid-use-ampm
  5149. "........ "
  5150. "......")))
  5151. (t ""))
  5152. extra (or (and (not habitp) extra) "")
  5153. category (if (symbolp category) (symbol-name category) category)
  5154. thecategory (copy-sequence category))
  5155. (if (string-match org-bracket-link-regexp category)
  5156. (progn
  5157. (setq l (if (match-end 3)
  5158. (- (match-end 3) (match-beginning 3))
  5159. (- (match-end 1) (match-beginning 1))))
  5160. (when (< l (or org-prefix-category-length 0))
  5161. (setq category (copy-sequence category))
  5162. (org-add-props category nil
  5163. 'extra-space (make-string
  5164. (- org-prefix-category-length l 1) ?\ ))))
  5165. (if (and org-prefix-category-max-length
  5166. (>= (length category) org-prefix-category-max-length))
  5167. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5168. ;; Evaluate the compiled format
  5169. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5170. ;; And finally add the text properties
  5171. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5172. (org-add-props rtn nil
  5173. 'org-category (if thecategory (downcase thecategory) category)
  5174. 'tags (mapcar 'org-downcase-keep-props tags)
  5175. 'org-highest-priority org-highest-priority
  5176. 'org-lowest-priority org-lowest-priority
  5177. 'time-of-day time-of-day
  5178. 'duration duration
  5179. 'effort effort
  5180. 'effort-minutes neffort
  5181. 'txt txt
  5182. 'time time
  5183. 'extra extra
  5184. 'format org-prefix-format-compiled
  5185. 'dotime dotime))))
  5186. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5187. "Remove tags string from TXT, and add a modified list of tags.
  5188. The modified list may contain inherited tags, and tags matched by
  5189. `org-agenda-hide-tags-regexp' will be removed."
  5190. (when (or add-inherited hide-re)
  5191. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5192. (setq txt (substring txt 0 (match-beginning 0))))
  5193. (setq tags
  5194. (delq nil
  5195. (mapcar (lambda (tg)
  5196. (if (or (and hide-re (string-match hide-re tg))
  5197. (and (not add-inherited)
  5198. (get-text-property 0 'inherited tg)))
  5199. nil
  5200. tg))
  5201. tags)))
  5202. (when tags
  5203. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5204. i)
  5205. (setq txt (concat txt " :"
  5206. (mapconcat
  5207. (lambda (x)
  5208. (setq i (get-text-property 0 'inherited x))
  5209. (if (and have-i (not i))
  5210. (progn
  5211. (setq have-i nil)
  5212. (concat ":" x))
  5213. x))
  5214. tags ":")
  5215. (if have-i "::" ":"))))))
  5216. txt)
  5217. (defun org-downcase-keep-props (s)
  5218. (let ((props (text-properties-at 0 s)))
  5219. (setq s (downcase s))
  5220. (add-text-properties 0 (length s) props s)
  5221. s))
  5222. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5223. (defvar org-agenda-sorting-strategy-selected nil)
  5224. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5225. (catch 'exit
  5226. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5227. ((and todayp (member 'today (car org-agenda-time-grid))))
  5228. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5229. ((member 'weekly (car org-agenda-time-grid)))
  5230. (t (throw 'exit list)))
  5231. (let* ((have (delq nil (mapcar
  5232. (lambda (x) (get-text-property 1 'time-of-day x))
  5233. list)))
  5234. (string (nth 1 org-agenda-time-grid))
  5235. (gridtimes (nth 2 org-agenda-time-grid))
  5236. (req (car org-agenda-time-grid))
  5237. (remove (member 'remove-match req))
  5238. new time)
  5239. (if (and (member 'require-timed req) (not have))
  5240. ;; don't show empty grid
  5241. (throw 'exit list))
  5242. (while (setq time (pop gridtimes))
  5243. (unless (and remove (member time have))
  5244. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5245. (push (org-format-agenda-item
  5246. nil string "" nil
  5247. (concat (substring time 0 -2) ":" (substring time -2)))
  5248. new)
  5249. (put-text-property
  5250. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5251. (when (and todayp org-agenda-show-current-time-in-grid)
  5252. (push (org-format-agenda-item
  5253. nil
  5254. org-agenda-current-time-string
  5255. "" nil
  5256. (format-time-string "%H:%M "))
  5257. new)
  5258. (put-text-property
  5259. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5260. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5261. (append new list)
  5262. (append list new)))))
  5263. (defun org-compile-prefix-format (key)
  5264. "Compile the prefix format into a Lisp form that can be evaluated.
  5265. The resulting form is returned and stored in the variable
  5266. `org-prefix-format-compiled'."
  5267. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5268. org-prefix-category-length nil org-prefix-has-effort nil)
  5269. (let ((s (cond
  5270. ((stringp org-agenda-prefix-format)
  5271. org-agenda-prefix-format)
  5272. ((assq key org-agenda-prefix-format)
  5273. (cdr (assq key org-agenda-prefix-format)))
  5274. (t " %-12:c%?-12t% s")))
  5275. (start 0)
  5276. varform vars var e c f opt)
  5277. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5278. s start)
  5279. (setq var (or (cdr (assoc (match-string 4 s)
  5280. '(("c" . category) ("t" . time) ("s" . extra)
  5281. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5282. 'eval)
  5283. c (or (match-string 3 s) "")
  5284. opt (match-beginning 1)
  5285. start (1+ (match-beginning 0)))
  5286. (if (equal var 'time) (setq org-prefix-has-time t))
  5287. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5288. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5289. (setq f (concat "%" (match-string 2 s) "s"))
  5290. (when (equal var 'category)
  5291. (setq org-prefix-category-length
  5292. (floor (abs (string-to-number (match-string 2 s)))))
  5293. (setq org-prefix-category-max-length
  5294. (let ((x (match-string 2 s)))
  5295. (save-match-data
  5296. (if (string-match "\\.[0-9]+" x)
  5297. (string-to-number (substring (match-string 0 x) 1)))))))
  5298. (if (eq var 'eval)
  5299. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5300. (if opt
  5301. (setq varform
  5302. `(if (equal "" ,var)
  5303. ""
  5304. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5305. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5306. (setq s (replace-match "%s" t nil s))
  5307. (push varform vars))
  5308. (setq vars (nreverse vars))
  5309. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5310. (defun org-set-sorting-strategy (key)
  5311. (if (symbolp (car org-agenda-sorting-strategy))
  5312. ;; the old format
  5313. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5314. (setq org-agenda-sorting-strategy-selected
  5315. (or (cdr (assq key org-agenda-sorting-strategy))
  5316. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5317. '(time-up category-keep priority-down)))))
  5318. (defun org-get-time-of-day (s &optional string mod24)
  5319. "Check string S for a time of day.
  5320. If found, return it as a military time number between 0 and 2400.
  5321. If not found, return nil.
  5322. The optional STRING argument forces conversion into a 5 character wide string
  5323. HH:MM."
  5324. (save-match-data
  5325. (when
  5326. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5327. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5328. (let* ((h (string-to-number (match-string 1 s)))
  5329. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5330. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5331. (am-p (equal ampm "am"))
  5332. (h1 (cond ((not ampm) h)
  5333. ((= h 12) (if am-p 0 12))
  5334. (t (+ h (if am-p 0 12)))))
  5335. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5336. (mod h1 24) h1))
  5337. (t0 (+ (* 100 h2) m))
  5338. (t1 (concat (if (>= h1 24) "+" " ")
  5339. (if (and org-agenda-time-leading-zero
  5340. (< t0 1000)) "0" "")
  5341. (if (< t0 100) "0" "")
  5342. (if (< t0 10) "0" "")
  5343. (int-to-string t0))))
  5344. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5345. (defvar org-agenda-before-sorting-filter-function nil
  5346. "Function to be applied to agenda items prior to sorting.
  5347. Prior to sorting also means just before they are inserted into the agenda.
  5348. To aid sorting, you may revisit the original entries and add more text
  5349. properties which will later be used by the sorting functions.
  5350. The function should take a string argument, an agenda line.
  5351. It has access to the text properties in that line, which contain among
  5352. other things, the property `org-hd-marker' that points to the entry
  5353. where the line comes from. Note that not all lines going into the agenda
  5354. have this property, only most.
  5355. The function should return the modified string. It is probably best
  5356. to ONLY change text properties.
  5357. You can also use this function as a filter, by returning nil for lines
  5358. you don't want to have in the agenda at all. For this application, you
  5359. could bind the variable in the options section of a custom command.")
  5360. (defun org-finalize-agenda-entries (list &optional nosort)
  5361. "Sort and concatenate the agenda items."
  5362. (setq list (mapcar 'org-agenda-highlight-todo list))
  5363. (if nosort
  5364. list
  5365. (when org-agenda-before-sorting-filter-function
  5366. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5367. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5368. (defun org-agenda-highlight-todo (x)
  5369. (let ((org-done-keywords org-done-keywords-for-agenda)
  5370. (case-fold-search nil)
  5371. re)
  5372. (if (eq x 'line)
  5373. (save-excursion
  5374. (beginning-of-line 1)
  5375. (setq re (org-get-at-bol 'org-todo-regexp))
  5376. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5377. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5378. (add-text-properties (match-beginning 0) (match-end 1)
  5379. (list 'face (org-get-todo-face 1)))
  5380. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5381. (delete-region (match-beginning 1) (1- (match-end 0)))
  5382. (goto-char (match-beginning 1))
  5383. (insert (format org-agenda-todo-keyword-format s)))))
  5384. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5385. (setq re (get-text-property 0 'org-todo-regexp x))
  5386. (when (and re
  5387. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5388. x (or pl 0)) pl))
  5389. (add-text-properties
  5390. (or (match-end 1) (match-end 0)) (match-end 0)
  5391. (list 'face (org-get-todo-face (match-string 2 x)))
  5392. x)
  5393. (when (match-end 1)
  5394. (setq x (concat (substring x 0 (match-end 1))
  5395. (format org-agenda-todo-keyword-format
  5396. (match-string 2 x))
  5397. (org-add-props " " (text-properties-at 0 x))
  5398. (substring x (match-end 3)))))))
  5399. x)))
  5400. (defsubst org-cmp-priority (a b)
  5401. "Compare the priorities of string A and B."
  5402. (let ((pa (or (get-text-property 1 'priority a) 0))
  5403. (pb (or (get-text-property 1 'priority b) 0)))
  5404. (cond ((> pa pb) +1)
  5405. ((< pa pb) -1)
  5406. (t nil))))
  5407. (defsubst org-cmp-effort (a b)
  5408. "Compare the effort values of string A and B."
  5409. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5410. (ea (or (get-text-property 1 'effort-minutes a) def))
  5411. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5412. (cond ((> ea eb) +1)
  5413. ((< ea eb) -1)
  5414. (t nil))))
  5415. (defsubst org-cmp-category (a b)
  5416. "Compare the string values of categories of strings A and B."
  5417. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5418. (cb (or (get-text-property 1 'org-category b) "")))
  5419. (cond ((string-lessp ca cb) -1)
  5420. ((string-lessp cb ca) +1)
  5421. (t nil))))
  5422. (defsubst org-cmp-todo-state (a b)
  5423. "Compare the todo states of strings A and B."
  5424. (let* ((ma (or (get-text-property 1 'org-marker a)
  5425. (get-text-property 1 'org-hd-marker a)))
  5426. (mb (or (get-text-property 1 'org-marker b)
  5427. (get-text-property 1 'org-hd-marker b)))
  5428. (fa (and ma (marker-buffer ma)))
  5429. (fb (and mb (marker-buffer mb)))
  5430. (todo-kwds
  5431. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5432. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5433. (ta (or (get-text-property 1 'todo-state a) ""))
  5434. (tb (or (get-text-property 1 'todo-state b) ""))
  5435. (la (- (length (member ta todo-kwds))))
  5436. (lb (- (length (member tb todo-kwds))))
  5437. (donepa (member ta org-done-keywords-for-agenda))
  5438. (donepb (member tb org-done-keywords-for-agenda)))
  5439. (cond ((and donepa (not donepb)) -1)
  5440. ((and (not donepa) donepb) +1)
  5441. ((< la lb) -1)
  5442. ((< lb la) +1)
  5443. (t nil))))
  5444. (defsubst org-cmp-alpha (a b)
  5445. "Compare the headlines, alphabetically."
  5446. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5447. (plb (text-property-any 0 (length b) 'org-heading t b))
  5448. (ta (and pla (substring a pla)))
  5449. (tb (and plb (substring b plb))))
  5450. (when pla
  5451. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5452. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5453. (setq ta (substring ta (match-end 0))))
  5454. (setq ta (downcase ta)))
  5455. (when plb
  5456. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5457. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5458. (setq tb (substring tb (match-end 0))))
  5459. (setq tb (downcase tb)))
  5460. (cond ((not ta) +1)
  5461. ((not tb) -1)
  5462. ((string-lessp ta tb) -1)
  5463. ((string-lessp tb ta) +1)
  5464. (t nil))))
  5465. (defsubst org-cmp-tag (a b)
  5466. "Compare the string values of the first tags of A and B."
  5467. (let ((ta (car (last (get-text-property 1 'tags a))))
  5468. (tb (car (last (get-text-property 1 'tags b)))))
  5469. (cond ((not ta) +1)
  5470. ((not tb) -1)
  5471. ((string-lessp ta tb) -1)
  5472. ((string-lessp tb ta) +1)
  5473. (t nil))))
  5474. (defsubst org-cmp-time (a b)
  5475. "Compare the time-of-day values of strings A and B."
  5476. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5477. (ta (or (get-text-property 1 'time-of-day a) def))
  5478. (tb (or (get-text-property 1 'time-of-day b) def)))
  5479. (cond ((< ta tb) -1)
  5480. ((< tb ta) +1)
  5481. (t nil))))
  5482. (defsubst org-cmp-habit-p (a b)
  5483. "Compare the todo states of strings A and B."
  5484. (let ((ha (get-text-property 1 'org-habit-p a))
  5485. (hb (get-text-property 1 'org-habit-p b)))
  5486. (cond ((and ha (not hb)) -1)
  5487. ((and (not ha) hb) +1)
  5488. (t nil))))
  5489. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5490. (defun org-entries-lessp (a b)
  5491. "Predicate for sorting agenda entries."
  5492. ;; The following variables will be used when the form is evaluated.
  5493. ;; So even though the compiler complains, keep them.
  5494. (let* ((ss org-agenda-sorting-strategy-selected)
  5495. (time-up (and (org-em 'time-up 'time-down ss)
  5496. (org-cmp-time a b)))
  5497. (time-down (if time-up (- time-up) nil))
  5498. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5499. (org-cmp-priority a b)))
  5500. (priority-down (if priority-up (- priority-up) nil))
  5501. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5502. (org-cmp-effort a b)))
  5503. (effort-down (if effort-up (- effort-up) nil))
  5504. (category-up (and (or (org-em 'category-up 'category-down ss)
  5505. (memq 'category-keep ss))
  5506. (org-cmp-category a b)))
  5507. (category-down (if category-up (- category-up) nil))
  5508. (category-keep (if category-up +1 nil))
  5509. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5510. (org-cmp-tag a b)))
  5511. (tag-down (if tag-up (- tag-up) nil))
  5512. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5513. (org-cmp-todo-state a b)))
  5514. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5515. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5516. (org-cmp-habit-p a b)))
  5517. (habit-down (if habit-up (- habit-up) nil))
  5518. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5519. (org-cmp-alpha a b)))
  5520. (alpha-down (if alpha-up (- alpha-up) nil))
  5521. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5522. user-defined-up user-defined-down)
  5523. (if (and need-user-cmp org-agenda-cmp-user-defined
  5524. (functionp org-agenda-cmp-user-defined))
  5525. (setq user-defined-up
  5526. (funcall org-agenda-cmp-user-defined a b)
  5527. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5528. (cdr (assoc
  5529. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5530. '((-1 . t) (1 . nil) (nil . nil))))))
  5531. ;;; Agenda restriction lock
  5532. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5533. "Overlay to mark the headline to which agenda commands are restricted.")
  5534. (overlay-put org-agenda-restriction-lock-overlay
  5535. 'face 'org-agenda-restriction-lock)
  5536. (overlay-put org-agenda-restriction-lock-overlay
  5537. 'help-echo "Agendas are currently limited to this subtree.")
  5538. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5539. (defun org-agenda-set-restriction-lock (&optional type)
  5540. "Set restriction lock for agenda, to current subtree or file.
  5541. Restriction will be the file if TYPE is `file', or if type is the
  5542. universal prefix '(4), or if the cursor is before the first headline
  5543. in the file. Otherwise, restriction will be to the current subtree."
  5544. (interactive "P")
  5545. (and (equal type '(4)) (setq type 'file))
  5546. (setq type (cond
  5547. (type type)
  5548. ((org-at-heading-p) 'subtree)
  5549. ((condition-case nil (org-back-to-heading t) (error nil))
  5550. 'subtree)
  5551. (t 'file)))
  5552. (if (eq type 'subtree)
  5553. (progn
  5554. (setq org-agenda-restrict t)
  5555. (setq org-agenda-overriding-restriction 'subtree)
  5556. (put 'org-agenda-files 'org-restrict
  5557. (list (buffer-file-name (buffer-base-buffer))))
  5558. (org-back-to-heading t)
  5559. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5560. (move-marker org-agenda-restrict-begin (point))
  5561. (move-marker org-agenda-restrict-end
  5562. (save-excursion (org-end-of-subtree t)))
  5563. (message "Locking agenda restriction to subtree"))
  5564. (put 'org-agenda-files 'org-restrict
  5565. (list (buffer-file-name (buffer-base-buffer))))
  5566. (setq org-agenda-restrict nil)
  5567. (setq org-agenda-overriding-restriction 'file)
  5568. (move-marker org-agenda-restrict-begin nil)
  5569. (move-marker org-agenda-restrict-end nil)
  5570. (message "Locking agenda restriction to file"))
  5571. (setq current-prefix-arg nil)
  5572. (org-agenda-maybe-redo))
  5573. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5574. "Remove the agenda restriction lock."
  5575. (interactive "P")
  5576. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5577. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5578. (setq org-agenda-overriding-restriction nil)
  5579. (setq org-agenda-restrict nil)
  5580. (put 'org-agenda-files 'org-restrict nil)
  5581. (move-marker org-agenda-restrict-begin nil)
  5582. (move-marker org-agenda-restrict-end nil)
  5583. (setq current-prefix-arg nil)
  5584. (message "Agenda restriction lock removed")
  5585. (or noupdate (org-agenda-maybe-redo)))
  5586. (defun org-agenda-maybe-redo ()
  5587. "If there is any window showing the agenda view, update it."
  5588. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5589. (w0 (selected-window)))
  5590. (when w
  5591. (select-window w)
  5592. (org-agenda-redo)
  5593. (select-window w0)
  5594. (if org-agenda-overriding-restriction
  5595. (message "Agenda view shifted to new %s restriction"
  5596. org-agenda-overriding-restriction)
  5597. (message "Agenda restriction lock removed")))))
  5598. ;;; Agenda commands
  5599. (defun org-agenda-check-type (error &rest types)
  5600. "Check if agenda buffer is of allowed type.
  5601. If ERROR is non-nil, throw an error, otherwise just return nil."
  5602. (if (memq org-agenda-type types)
  5603. t
  5604. (if error
  5605. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5606. nil)))
  5607. (defun org-agenda-quit ()
  5608. "Exit agenda by removing the window or the buffer."
  5609. (interactive)
  5610. (if org-agenda-columns-active
  5611. (org-columns-quit)
  5612. (let ((buf (current-buffer)))
  5613. (if (eq org-agenda-window-setup 'other-frame)
  5614. (progn
  5615. (kill-buffer buf)
  5616. (org-agenda-reset-markers)
  5617. (org-columns-remove-overlays)
  5618. (setq org-agenda-archives-mode nil)
  5619. (delete-frame))
  5620. (and (not (eq org-agenda-window-setup 'current-window))
  5621. (not (one-window-p))
  5622. (delete-window))
  5623. (kill-buffer buf)
  5624. (org-agenda-reset-markers)
  5625. (org-columns-remove-overlays)
  5626. (setq org-agenda-archives-mode nil)))
  5627. ;; Maybe restore the pre-agenda window configuration.
  5628. (and org-agenda-restore-windows-after-quit
  5629. (not (eq org-agenda-window-setup 'other-frame))
  5630. org-pre-agenda-window-conf
  5631. (set-window-configuration org-pre-agenda-window-conf))))
  5632. (defun org-agenda-exit ()
  5633. "Exit agenda by removing the window or the buffer.
  5634. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5635. Org-mode buffers visited directly by the user will not be touched."
  5636. (interactive)
  5637. (org-release-buffers org-agenda-new-buffers)
  5638. (setq org-agenda-new-buffers nil)
  5639. (org-agenda-quit))
  5640. (defun org-agenda-execute (arg)
  5641. "Execute another agenda command, keeping same window.
  5642. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5643. in the agenda."
  5644. (interactive "P")
  5645. (let ((org-agenda-window-setup 'current-window))
  5646. (org-agenda arg)))
  5647. (defun org-agenda-redo ()
  5648. "Rebuild Agenda.
  5649. When this is the global TODO list, a prefix argument will be interpreted."
  5650. (interactive)
  5651. (let* ((org-agenda-keep-modes t)
  5652. (filter org-agenda-filter)
  5653. (preset (get 'org-agenda-filter :preset-filter))
  5654. (org-agenda-filter-while-redo (or filter preset))
  5655. (cols org-agenda-columns-active)
  5656. (line (org-current-line))
  5657. (window-line (- line (org-current-line (window-start))))
  5658. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5659. (put 'org-agenda-filter :preset-filter nil)
  5660. (and cols (org-columns-quit))
  5661. (message "Rebuilding agenda buffer...")
  5662. (org-let lprops '(eval org-agenda-redo-command))
  5663. (setq org-agenda-undo-list nil
  5664. org-agenda-pending-undo-list nil)
  5665. (message "Rebuilding agenda buffer...done")
  5666. (put 'org-agenda-filter :preset-filter preset)
  5667. (and (or filter preset) (org-agenda-filter-apply filter))
  5668. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5669. (org-goto-line line)
  5670. (recenter window-line)))
  5671. (defvar org-global-tags-completion-table nil)
  5672. (defvar org-agenda-filter-form nil)
  5673. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5674. "Keep only those lines in the agenda buffer that have a specific tag.
  5675. The tag is selected with its fast selection letter, as configured.
  5676. With prefix argument STRIP, remove all lines that do have the tag.
  5677. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5678. used to narrow the search - the interactive user can also press `-' or `+'
  5679. to switch to narrowing."
  5680. (interactive "P")
  5681. (let* ((alist org-tag-alist-for-agenda)
  5682. (tag-chars (mapconcat
  5683. (lambda (x) (if (and (not (symbolp (car x)))
  5684. (cdr x))
  5685. (char-to-string (cdr x))
  5686. ""))
  5687. alist ""))
  5688. (efforts (org-split-string
  5689. (or (cdr (assoc (concat org-effort-property "_ALL")
  5690. org-global-properties))
  5691. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5692. "")))
  5693. (effort-op org-agenda-filter-effort-default-operator)
  5694. (effort-prompt "")
  5695. (inhibit-read-only t)
  5696. (current org-agenda-filter)
  5697. maybe-refresh a n tag)
  5698. (unless char
  5699. (message
  5700. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5701. (if narrow "Narrow" "Filter") tag-chars
  5702. (if org-agenda-auto-exclude-function "[RET], " ""))
  5703. (setq char (read-char)))
  5704. (when (member char '(?+ ?-))
  5705. ;; Narrowing down
  5706. (cond ((equal char ?-) (setq strip t narrow t))
  5707. ((equal char ?+) (setq strip nil narrow t)))
  5708. (message
  5709. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5710. (setq char (read-char)))
  5711. (when (member char '(?< ?> ?= ??))
  5712. ;; An effort operator
  5713. (setq effort-op (char-to-string char))
  5714. (setq alist nil) ; to make sure it will be interpreted as effort.
  5715. (unless (equal char ??)
  5716. (loop for i from 0 to 9 do
  5717. (setq effort-prompt
  5718. (concat
  5719. effort-prompt " ["
  5720. (if (= i 9) "0" (int-to-string (1+ i)))
  5721. "]" (nth i efforts))))
  5722. (message "Effort%s: %s " effort-op effort-prompt)
  5723. (setq char (read-char))
  5724. (when (or (< char ?0) (> char ?9))
  5725. (error "Need 1-9,0 to select effort" ))))
  5726. (when (equal char ?\t)
  5727. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5728. (org-set-local 'org-global-tags-completion-table
  5729. (org-global-tags-completion-table)))
  5730. (let ((completion-ignore-case t))
  5731. (setq tag (org-icompleting-read
  5732. "Tag: " org-global-tags-completion-table))))
  5733. (cond
  5734. ((equal char ?\r)
  5735. (org-agenda-filter-by-tag-show-all)
  5736. (when org-agenda-auto-exclude-function
  5737. (setq org-agenda-filter '())
  5738. (dolist (tag (org-agenda-get-represented-tags))
  5739. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5740. (if modifier
  5741. (push modifier org-agenda-filter))))
  5742. (if (not (null org-agenda-filter))
  5743. (org-agenda-filter-apply org-agenda-filter)))
  5744. (setq maybe-refresh t))
  5745. ((equal char ?/)
  5746. (org-agenda-filter-by-tag-show-all)
  5747. (when (get 'org-agenda-filter :preset-filter)
  5748. (org-agenda-filter-apply org-agenda-filter))
  5749. (setq maybe-refresh t))
  5750. ((or (equal char ?\ )
  5751. (setq a (rassoc char alist))
  5752. (and (>= char ?0) (<= char ?9)
  5753. (setq n (if (= char ?0) 9 (- char ?0 1))
  5754. tag (concat effort-op (nth n efforts))
  5755. a (cons tag nil)))
  5756. (and (= char ??)
  5757. (setq tag "?eff")
  5758. a (cons tag nil))
  5759. (and tag (setq a (cons tag nil))))
  5760. (org-agenda-filter-by-tag-show-all)
  5761. (setq tag (car a))
  5762. (setq org-agenda-filter
  5763. (cons (concat (if strip "-" "+") tag)
  5764. (if narrow current nil)))
  5765. (org-agenda-filter-apply org-agenda-filter)
  5766. (setq maybe-refresh t))
  5767. (t (error "Invalid tag selection character %c" char)))
  5768. (when (and maybe-refresh
  5769. (eq org-agenda-clockreport-mode 'with-filter))
  5770. (org-agenda-redo))))
  5771. (defun org-agenda-get-represented-tags ()
  5772. "Get a list of all tags currently represented in the agenda."
  5773. (let (p tags)
  5774. (save-excursion
  5775. (goto-char (point-min))
  5776. (while (setq p (next-single-property-change (point) 'tags))
  5777. (goto-char p)
  5778. (mapc (lambda (x) (add-to-list 'tags x))
  5779. (get-text-property (point) 'tags))))
  5780. tags))
  5781. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5782. "Refine the current filter. See `org-agenda-filter-by-tag."
  5783. (interactive "P")
  5784. (org-agenda-filter-by-tag strip char 'refine))
  5785. (defun org-agenda-filter-make-matcher ()
  5786. "Create the form that tests a line for the agenda filter."
  5787. (let (f f1)
  5788. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5789. org-agenda-filter))
  5790. (if (member x '("-" "+"))
  5791. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5792. (if (string-match "[<=>?]" x)
  5793. (setq f1 (org-agenda-filter-effort-form x))
  5794. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5795. (if (equal (string-to-char x) ?-)
  5796. (setq f1 (list 'not f1))))
  5797. (push f1 f))
  5798. (cons 'and (nreverse f))))
  5799. (defun org-agenda-filter-effort-form (e)
  5800. "Return the form to compare the effort of the current line with what E says.
  5801. E looks like \"+<2:25\"."
  5802. (let (op)
  5803. (setq e (substring e 1))
  5804. (setq op (string-to-char e) e (substring e 1))
  5805. (setq op (cond ((equal op ?<) '<=)
  5806. ((equal op ?>) '>=)
  5807. ((equal op ??) op)
  5808. (t '=)))
  5809. (list 'org-agenda-compare-effort (list 'quote op)
  5810. (org-duration-string-to-minutes e))))
  5811. (defun org-agenda-compare-effort (op value)
  5812. "Compare the effort of the current line with VALUE, using OP.
  5813. If the line does not have an effort defined, return nil."
  5814. (let ((eff (org-get-at-bol 'effort-minutes)))
  5815. (if (equal op ??)
  5816. (not eff)
  5817. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5818. value))))
  5819. (defun org-agenda-filter-apply (filter)
  5820. "Set FILTER as the new agenda filter and apply it."
  5821. (let (tags)
  5822. (setq org-agenda-filter filter
  5823. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5824. (org-agenda-set-mode-name)
  5825. (save-excursion
  5826. (goto-char (point-min))
  5827. (while (not (eobp))
  5828. (if (org-get-at-bol 'org-marker)
  5829. (progn
  5830. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5831. (if (not (eval org-agenda-filter-form))
  5832. (org-agenda-filter-by-tag-hide-line))
  5833. (beginning-of-line 2))
  5834. (beginning-of-line 2))))
  5835. (if (get-char-property (point) 'invisible)
  5836. (org-agenda-previous-line))))
  5837. (defun org-agenda-filter-by-tag-hide-line ()
  5838. (let (ov)
  5839. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5840. (point-at-eol)))
  5841. (overlay-put ov 'invisible t)
  5842. (overlay-put ov 'type 'tags-filter)
  5843. (push ov org-agenda-filter-overlays)))
  5844. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5845. (setq pos (or pos (point)))
  5846. (save-excursion
  5847. (dolist (ov (overlays-at pos))
  5848. (when (and (overlay-get ov 'invisible)
  5849. (eq (overlay-get ov 'type) 'tags-filter))
  5850. (goto-char pos)
  5851. (if (< (overlay-start ov) (point-at-eol))
  5852. (move-overlay ov (point-at-eol)
  5853. (overlay-end ov)))))))
  5854. (defun org-agenda-filter-by-tag-show-all ()
  5855. (mapc 'delete-overlay org-agenda-filter-overlays)
  5856. (setq org-agenda-filter-overlays nil)
  5857. (setq org-agenda-filter nil)
  5858. (setq org-agenda-filter-form nil)
  5859. (org-agenda-set-mode-name))
  5860. (defun org-agenda-manipulate-query-add ()
  5861. "Manipulate the query by adding a search term with positive selection.
  5862. Positive selection means the term must be matched for selection of an entry."
  5863. (interactive)
  5864. (org-agenda-manipulate-query ?\[))
  5865. (defun org-agenda-manipulate-query-subtract ()
  5866. "Manipulate the query by adding a search term with negative selection.
  5867. Negative selection means term must not be matched for selection of an entry."
  5868. (interactive)
  5869. (org-agenda-manipulate-query ?\]))
  5870. (defun org-agenda-manipulate-query-add-re ()
  5871. "Manipulate the query by adding a search regexp with positive selection.
  5872. Positive selection means the regexp must match for selection of an entry."
  5873. (interactive)
  5874. (org-agenda-manipulate-query ?\{))
  5875. (defun org-agenda-manipulate-query-subtract-re ()
  5876. "Manipulate the query by adding a search regexp with negative selection.
  5877. Negative selection means regexp must not match for selection of an entry."
  5878. (interactive)
  5879. (org-agenda-manipulate-query ?\}))
  5880. (defun org-agenda-manipulate-query (char)
  5881. (cond
  5882. ((memq org-agenda-type '(timeline agenda))
  5883. (let ((org-agenda-include-inactive-timestamps t))
  5884. (org-agenda-redo))
  5885. (message "Display now includes inactive timestamps as well"))
  5886. ((eq org-agenda-type 'search)
  5887. (org-add-to-string
  5888. 'org-agenda-query-string
  5889. (if org-agenda-last-search-view-search-was-boolean
  5890. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5891. (?\{ . " +{}") (?\} . " -{}"))))
  5892. " "))
  5893. (setq org-agenda-redo-command
  5894. (list 'org-search-view
  5895. org-todo-only
  5896. org-agenda-query-string
  5897. (+ (length org-agenda-query-string)
  5898. (if (member char '(?\{ ?\})) 0 1))))
  5899. (set-register org-agenda-query-register org-agenda-query-string)
  5900. (org-agenda-redo))
  5901. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5902. org-agenda-type))))
  5903. (defun org-add-to-string (var string)
  5904. (set var (concat (symbol-value var) string)))
  5905. (defun org-agenda-goto-date (date)
  5906. "Jump to DATE in agenda."
  5907. (interactive (list (let ((org-read-date-prefer-future
  5908. (eval org-agenda-jump-prefer-future)))
  5909. (org-read-date))))
  5910. (org-agenda-list nil date))
  5911. (defun org-agenda-goto-today ()
  5912. "Go to today."
  5913. (interactive)
  5914. (org-agenda-check-type t 'timeline 'agenda)
  5915. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5916. (cond
  5917. (tdpos (goto-char tdpos))
  5918. ((eq org-agenda-type 'agenda)
  5919. (let* ((sd (org-agenda-compute-starting-span
  5920. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5921. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5922. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5923. (org-agenda-redo)
  5924. (org-agenda-find-same-or-today-or-agenda)))
  5925. (t (error "Cannot find today")))))
  5926. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5927. (goto-char
  5928. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5929. (text-property-any (point-min) (point-max) 'org-today t)
  5930. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5931. (point-min))))
  5932. (defun org-agenda-later (arg)
  5933. "Go forward in time by thee current span.
  5934. With prefix ARG, go forward that many times the current span."
  5935. (interactive "p")
  5936. (org-agenda-check-type t 'agenda)
  5937. (let* ((span org-agenda-current-span)
  5938. (sd org-starting-day)
  5939. (greg (calendar-gregorian-from-absolute sd))
  5940. (cnt (org-get-at-bol 'org-day-cnt))
  5941. greg2)
  5942. (cond
  5943. ((eq span 'day)
  5944. (setq sd (+ arg sd)))
  5945. ((eq span 'week)
  5946. (setq sd (+ (* 7 arg) sd)))
  5947. ((eq span 'month)
  5948. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5949. sd (calendar-absolute-from-gregorian greg2))
  5950. (setcar greg2 (1+ (car greg2))))
  5951. ((eq span 'year)
  5952. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5953. sd (calendar-absolute-from-gregorian greg2))
  5954. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5955. (t
  5956. (setq sd (+ (* span arg) sd))))
  5957. (let ((org-agenda-overriding-arguments
  5958. (list (car org-agenda-last-arguments) sd span t)))
  5959. (org-agenda-redo)
  5960. (org-agenda-find-same-or-today-or-agenda cnt))))
  5961. (defun org-agenda-earlier (arg)
  5962. "Go backward in time by the current span.
  5963. With prefix ARG, go backward that many times the current span."
  5964. (interactive "p")
  5965. (org-agenda-later (- arg)))
  5966. (defun org-agenda-view-mode-dispatch ()
  5967. "Call one of the view mode commands."
  5968. (interactive)
  5969. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5970. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5971. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5972. [E]ntryText")
  5973. (let ((a (read-char-exclusive)))
  5974. (case a
  5975. (?\ (call-interactively 'org-agenda-reset-view))
  5976. (?d (call-interactively 'org-agenda-day-view))
  5977. (?w (call-interactively 'org-agenda-week-view))
  5978. (?m (call-interactively 'org-agenda-month-view))
  5979. (?y (call-interactively 'org-agenda-year-view))
  5980. (?l (call-interactively 'org-agenda-log-mode))
  5981. (?L (org-agenda-log-mode '(4)))
  5982. (?c (org-agenda-log-mode 'clockcheck))
  5983. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5984. (?a (call-interactively 'org-agenda-archives-mode))
  5985. (?A (org-agenda-archives-mode 'files))
  5986. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5987. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5988. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5989. (?D (call-interactively 'org-agenda-toggle-diary))
  5990. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5991. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5992. (org-agenda-check-type t 'timeline 'agenda)
  5993. (org-agenda-redo))
  5994. (message "Display now includes inactive timestamps as well"))
  5995. (?q (message "Abort"))
  5996. (otherwise (error "Invalid key" )))))
  5997. (defun org-agenda-reset-view ()
  5998. "Switch to default view for agenda."
  5999. (interactive)
  6000. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6001. (defun org-agenda-day-view (&optional day-of-year)
  6002. "Switch to daily view for agenda.
  6003. With argument DAY-OF-YEAR, switch to that day of the year."
  6004. (interactive "P")
  6005. (org-agenda-change-time-span 'day day-of-year))
  6006. (defun org-agenda-week-view (&optional iso-week)
  6007. "Switch to daily view for agenda.
  6008. With argument ISO-WEEK, switch to the corresponding ISO week.
  6009. If ISO-WEEK has more then 2 digits, only the last two encode the
  6010. week. Any digits before this encode a year. So 200712 means
  6011. week 12 of year 2007. Years in the range 1938-2037 can also be
  6012. written as 2-digit years."
  6013. (interactive "P")
  6014. (org-agenda-change-time-span 'week iso-week))
  6015. (defun org-agenda-month-view (&optional month)
  6016. "Switch to monthly view for agenda.
  6017. With argument MONTH, switch to that month."
  6018. (interactive "P")
  6019. (org-agenda-change-time-span 'month month))
  6020. (defun org-agenda-year-view (&optional year)
  6021. "Switch to yearly view for agenda.
  6022. With argument YEAR, switch to that year.
  6023. If MONTH has more then 2 digits, only the last two encode the
  6024. month. Any digits before this encode a year. So 200712 means
  6025. December year 2007. Years in the range 1938-2037 can also be
  6026. written as 2-digit years."
  6027. (interactive "P")
  6028. (when year
  6029. (setq year (org-small-year-to-year year)))
  6030. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6031. (org-agenda-change-time-span 'year year)
  6032. (error "Abort")))
  6033. (defun org-agenda-change-time-span (span &optional n)
  6034. "Change the agenda view to SPAN.
  6035. SPAN may be `day', `week', `month', `year'."
  6036. (org-agenda-check-type t 'agenda)
  6037. (if (and (not n) (equal org-agenda-current-span span))
  6038. (error "Viewing span is already \"%s\"" span))
  6039. (let* ((sd (or (org-get-at-bol 'day)
  6040. org-starting-day))
  6041. (sd (org-agenda-compute-starting-span sd span n))
  6042. (org-agenda-overriding-arguments
  6043. (or org-agenda-overriding-arguments
  6044. (list (car org-agenda-last-arguments) sd span t))))
  6045. (org-agenda-redo)
  6046. (org-agenda-find-same-or-today-or-agenda))
  6047. (org-agenda-set-mode-name)
  6048. (message "Switched to %s view" span))
  6049. (defun org-agenda-compute-starting-span (sd span &optional n)
  6050. "Compute starting date for agenda.
  6051. SPAN may be `day', `week', `month', `year'. The return value
  6052. is a cons cell with the starting date and the number of days,
  6053. so that the date SD will be in that range."
  6054. (let* ((greg (calendar-gregorian-from-absolute sd))
  6055. (dg (nth 1 greg))
  6056. (mg (car greg))
  6057. (yg (nth 2 greg)))
  6058. (cond
  6059. ((eq span 'day)
  6060. (when n
  6061. (setq sd (+ (calendar-absolute-from-gregorian
  6062. (list mg 1 yg))
  6063. n -1))))
  6064. ((eq span 'week)
  6065. (let* ((nt (calendar-day-of-week
  6066. (calendar-gregorian-from-absolute sd)))
  6067. (d (if org-agenda-start-on-weekday
  6068. (- nt org-agenda-start-on-weekday)
  6069. 0))
  6070. y1)
  6071. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6072. (when n
  6073. (require 'cal-iso)
  6074. (when (> n 99)
  6075. (setq y1 (org-small-year-to-year (/ n 100))
  6076. n (mod n 100)))
  6077. (setq sd
  6078. (calendar-absolute-from-iso
  6079. (list n 1
  6080. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6081. ((eq span 'month)
  6082. (let (y1)
  6083. (when (and n (> n 99))
  6084. (setq y1 (org-small-year-to-year (/ n 100))
  6085. n (mod n 100)))
  6086. (setq sd (calendar-absolute-from-gregorian
  6087. (list (or n mg) 1 (or y1 yg))))))
  6088. ((eq span 'year)
  6089. (setq sd (calendar-absolute-from-gregorian
  6090. (list 1 1 (or n yg))))))
  6091. sd))
  6092. (defun org-agenda-next-date-line (&optional arg)
  6093. "Jump to the next line indicating a date in agenda buffer."
  6094. (interactive "p")
  6095. (org-agenda-check-type t 'agenda 'timeline)
  6096. (beginning-of-line 1)
  6097. ;; This does not work if user makes date format that starts with a blank
  6098. (if (looking-at "^\\S-") (forward-char 1))
  6099. (if (not (re-search-forward "^\\S-" nil t arg))
  6100. (progn
  6101. (backward-char 1)
  6102. (error "No next date after this line in this buffer")))
  6103. (goto-char (match-beginning 0)))
  6104. (defun org-agenda-previous-date-line (&optional arg)
  6105. "Jump to the previous line indicating a date in agenda buffer."
  6106. (interactive "p")
  6107. (org-agenda-check-type t 'agenda 'timeline)
  6108. (beginning-of-line 1)
  6109. (if (not (re-search-backward "^\\S-" nil t arg))
  6110. (error "No previous date before this line in this buffer")))
  6111. ;; Initialize the highlight
  6112. (defvar org-hl (make-overlay 1 1))
  6113. (overlay-put org-hl 'face 'highlight)
  6114. (defun org-highlight (begin end &optional buffer)
  6115. "Highlight a region with overlay."
  6116. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6117. (defun org-unhighlight ()
  6118. "Detach overlay INDEX."
  6119. (org-detach-overlay org-hl))
  6120. ;; FIXME this is currently not used.
  6121. (defun org-highlight-until-next-command (beg end &optional buffer)
  6122. "Move the highlight overlay to BEG/END, remove it before the next command."
  6123. (org-highlight beg end buffer)
  6124. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6125. (defun org-unhighlight-once ()
  6126. "Remove the highlight from its position, and this function from the hook."
  6127. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6128. (org-unhighlight))
  6129. (defun org-agenda-follow-mode ()
  6130. "Toggle follow mode in an agenda buffer."
  6131. (interactive)
  6132. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6133. (org-agenda-set-mode-name)
  6134. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6135. (org-agenda-show))
  6136. (message "Follow mode is %s"
  6137. (if org-agenda-follow-mode "on" "off")))
  6138. (defun org-agenda-entry-text-mode (&optional arg)
  6139. "Toggle entry text mode in an agenda buffer."
  6140. (interactive "P")
  6141. (setq org-agenda-entry-text-mode (or (integerp arg)
  6142. (not org-agenda-entry-text-mode)))
  6143. (org-agenda-entry-text-hide)
  6144. (and org-agenda-entry-text-mode
  6145. (let ((org-agenda-entry-text-maxlines
  6146. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6147. (org-agenda-entry-text-show)))
  6148. (org-agenda-set-mode-name)
  6149. (message "Entry text mode is %s. Maximum number of lines is %d"
  6150. (if org-agenda-entry-text-mode "on" "off")
  6151. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6152. (defun org-agenda-clockreport-mode (&optional with-filter)
  6153. "Toggle clocktable mode in an agenda buffer.
  6154. With prefix arg WITH-FILTER, make the clocktable respect the current
  6155. agenda filter."
  6156. (interactive "P")
  6157. (org-agenda-check-type t 'agenda)
  6158. (if with-filter
  6159. (setq org-agenda-clockreport-mode 'with-filter)
  6160. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6161. (org-agenda-set-mode-name)
  6162. (org-agenda-redo)
  6163. (message "Clocktable mode is %s"
  6164. (if org-agenda-clockreport-mode "on" "off")))
  6165. (defun org-agenda-log-mode (&optional special)
  6166. "Toggle log mode in an agenda buffer.
  6167. With argument SPECIAL, show all possible log items, not only the ones
  6168. configured in `org-agenda-log-mode-items'.
  6169. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6170. (interactive "P")
  6171. (org-agenda-check-type t 'agenda 'timeline)
  6172. (setq org-agenda-show-log
  6173. (cond
  6174. ((equal special '(16)) 'only)
  6175. ((eq special 'clockcheck)
  6176. (if (eq org-agenda-show-log 'clockcheck)
  6177. nil 'clockcheck))
  6178. (special '(closed clock state))
  6179. (t (not org-agenda-show-log))))
  6180. (org-agenda-set-mode-name)
  6181. (org-agenda-redo)
  6182. (message "Log mode is %s"
  6183. (if org-agenda-show-log "on" "off")))
  6184. (defun org-agenda-archives-mode (&optional with-files)
  6185. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6186. When called with a prefix argument, include all archive files as well."
  6187. (interactive "P")
  6188. (setq org-agenda-archives-mode
  6189. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6190. (org-agenda-set-mode-name)
  6191. (org-agenda-redo)
  6192. (message
  6193. "%s"
  6194. (cond
  6195. ((eq org-agenda-archives-mode nil)
  6196. "No archives are included")
  6197. ((eq org-agenda-archives-mode 'trees)
  6198. (format "Trees with :%s: tag are included" org-archive-tag))
  6199. ((eq org-agenda-archives-mode t)
  6200. (format "Trees with :%s: tag and all active archive files are included"
  6201. org-archive-tag)))))
  6202. (defun org-agenda-toggle-diary ()
  6203. "Toggle diary inclusion in an agenda buffer."
  6204. (interactive)
  6205. (org-agenda-check-type t 'agenda)
  6206. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6207. (org-agenda-redo)
  6208. (org-agenda-set-mode-name)
  6209. (message "Diary inclusion turned %s"
  6210. (if org-agenda-include-diary "on" "off")))
  6211. (defun org-agenda-toggle-deadlines ()
  6212. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6213. (interactive)
  6214. (org-agenda-check-type t 'agenda)
  6215. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6216. (org-agenda-redo)
  6217. (org-agenda-set-mode-name)
  6218. (message "Deadlines inclusion turned %s"
  6219. (if org-agenda-include-deadlines "on" "off")))
  6220. (defun org-agenda-toggle-time-grid ()
  6221. "Toggle time grid in an agenda buffer."
  6222. (interactive)
  6223. (org-agenda-check-type t 'agenda)
  6224. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6225. (org-agenda-redo)
  6226. (org-agenda-set-mode-name)
  6227. (message "Time-grid turned %s"
  6228. (if org-agenda-use-time-grid "on" "off")))
  6229. (defun org-agenda-set-mode-name ()
  6230. "Set the mode name to indicate all the small mode settings."
  6231. (setq mode-name
  6232. (list "Org-Agenda"
  6233. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6234. " "
  6235. '(:eval (org-agenda-span-name org-agenda-current-span))
  6236. (if org-agenda-follow-mode " Follow" "")
  6237. (if org-agenda-entry-text-mode " ETxt" "")
  6238. (if org-agenda-include-diary " Diary" "")
  6239. (if org-agenda-include-deadlines " Ddl" "")
  6240. (if org-agenda-use-time-grid " Grid" "")
  6241. (if (and (boundp 'org-habit-show-habits)
  6242. org-habit-show-habits) " Habit" "")
  6243. (cond
  6244. ((consp org-agenda-show-log) " LogAll")
  6245. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6246. (org-agenda-show-log " Log")
  6247. (t ""))
  6248. (if (or org-agenda-filter (get 'org-agenda-filter
  6249. :preset-filter))
  6250. (concat " {" (mapconcat
  6251. 'identity
  6252. (append (get 'org-agenda-filter
  6253. :preset-filter)
  6254. org-agenda-filter) "") "}")
  6255. "")
  6256. (if org-agenda-archives-mode
  6257. (if (eq org-agenda-archives-mode t)
  6258. " Archives"
  6259. (format " :%s:" org-archive-tag))
  6260. "")
  6261. (if org-agenda-clockreport-mode
  6262. (if (eq org-agenda-clockreport-mode 'with-filter)
  6263. " Clock{}" " Clock")
  6264. "")))
  6265. (force-mode-line-update))
  6266. (defun org-agenda-post-command-hook ()
  6267. (setq org-agenda-type
  6268. (or (get-text-property (point) 'org-agenda-type)
  6269. (get-text-property (max (point-min) (1- (point)))
  6270. 'org-agenda-type))))
  6271. (defun org-agenda-next-line ()
  6272. "Move cursor to the next line, and show if follow mode is active."
  6273. (interactive)
  6274. (call-interactively 'next-line)
  6275. (org-agenda-do-context-action))
  6276. (defun org-agenda-previous-line ()
  6277. "Move cursor to the previous line, and show if follow-mode is active."
  6278. (interactive)
  6279. (call-interactively 'previous-line)
  6280. (org-agenda-do-context-action))
  6281. (defun org-agenda-do-context-action ()
  6282. "Show outline path and, maybe, follow mode window."
  6283. (let ((m (org-get-at-bol 'org-marker)))
  6284. (if (and org-agenda-follow-mode m)
  6285. (org-agenda-show))
  6286. (if (and m org-agenda-show-outline-path)
  6287. (org-with-point-at m
  6288. (org-display-outline-path t)))))
  6289. (defun org-agenda-show-priority ()
  6290. "Show the priority of the current item.
  6291. This priority is composed of the main priority given with the [#A] cookies,
  6292. and by additional input from the age of a schedules or deadline entry."
  6293. (interactive)
  6294. (let* ((pri (org-get-at-bol 'priority)))
  6295. (message "Priority is %d" (if pri pri -1000))))
  6296. (defun org-agenda-show-tags ()
  6297. "Show the tags applicable to the current item."
  6298. (interactive)
  6299. (let* ((tags (org-get-at-bol 'tags)))
  6300. (if tags
  6301. (message "Tags are :%s:"
  6302. (org-no-properties (mapconcat 'identity tags ":")))
  6303. (message "No tags associated with this line"))))
  6304. (defun org-agenda-goto (&optional highlight)
  6305. "Go to the Org-mode file which contains the item at point."
  6306. (interactive)
  6307. (let* ((marker (or (org-get-at-bol 'org-marker)
  6308. (org-agenda-error)))
  6309. (buffer (marker-buffer marker))
  6310. (pos (marker-position marker)))
  6311. (switch-to-buffer-other-window buffer)
  6312. (widen)
  6313. (push-mark)
  6314. (goto-char pos)
  6315. (when (org-mode-p)
  6316. (org-show-context 'agenda)
  6317. (save-excursion
  6318. (and (outline-next-heading)
  6319. (org-flag-heading nil)))) ; show the next heading
  6320. (when (outline-invisible-p)
  6321. (show-entry)) ; display invisible text
  6322. (recenter (/ (window-height) 2))
  6323. (run-hooks 'org-agenda-after-show-hook)
  6324. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6325. (defvar org-agenda-after-show-hook nil
  6326. "Normal hook run after an item has been shown from the agenda.
  6327. Point is in the buffer where the item originated.")
  6328. (defun org-agenda-kill ()
  6329. "Kill the entry or subtree belonging to the current agenda entry."
  6330. (interactive)
  6331. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6332. (let* ((marker (or (org-get-at-bol 'org-marker)
  6333. (org-agenda-error)))
  6334. (buffer (marker-buffer marker))
  6335. (pos (marker-position marker))
  6336. (type (org-get-at-bol 'type))
  6337. dbeg dend (n 0) conf)
  6338. (org-with-remote-undo buffer
  6339. (with-current-buffer buffer
  6340. (save-excursion
  6341. (goto-char pos)
  6342. (if (and (org-mode-p) (not (member type '("sexp"))))
  6343. (setq dbeg (progn (org-back-to-heading t) (point))
  6344. dend (org-end-of-subtree t t))
  6345. (setq dbeg (point-at-bol)
  6346. dend (min (point-max) (1+ (point-at-eol)))))
  6347. (goto-char dbeg)
  6348. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6349. (setq conf (or (eq t org-agenda-confirm-kill)
  6350. (and (numberp org-agenda-confirm-kill)
  6351. (> n org-agenda-confirm-kill))))
  6352. (and conf
  6353. (not (y-or-n-p
  6354. (format "Delete entry with %d lines in buffer \"%s\"? "
  6355. n (buffer-name buffer))))
  6356. (error "Abort"))
  6357. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6358. (with-current-buffer buffer (delete-region dbeg dend))
  6359. (message "Agenda item and source killed"))))
  6360. (defvar org-archive-default-command)
  6361. (defun org-agenda-archive-default ()
  6362. "Archive the entry or subtree belonging to the current agenda entry."
  6363. (interactive)
  6364. (require 'org-archive)
  6365. (org-agenda-archive-with org-archive-default-command))
  6366. (defun org-agenda-archive-default-with-confirmation ()
  6367. "Archive the entry or subtree belonging to the current agenda entry."
  6368. (interactive)
  6369. (require 'org-archive)
  6370. (org-agenda-archive-with org-archive-default-command 'confirm))
  6371. (defun org-agenda-archive ()
  6372. "Archive the entry or subtree belonging to the current agenda entry."
  6373. (interactive)
  6374. (org-agenda-archive-with 'org-archive-subtree))
  6375. (defun org-agenda-archive-to-archive-sibling ()
  6376. "Move the entry to the archive sibling."
  6377. (interactive)
  6378. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6379. (defun org-agenda-archive-with (cmd &optional confirm)
  6380. "Move the entry to the archive sibling."
  6381. (interactive)
  6382. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6383. (let* ((marker (or (org-get-at-bol 'org-marker)
  6384. (org-agenda-error)))
  6385. (buffer (marker-buffer marker))
  6386. (pos (marker-position marker)))
  6387. (org-with-remote-undo buffer
  6388. (with-current-buffer buffer
  6389. (if (org-mode-p)
  6390. (if (and confirm
  6391. (not (y-or-n-p "Archive this subtree or entry? ")))
  6392. (error "Abort")
  6393. (save-excursion
  6394. (goto-char pos)
  6395. (org-remove-subtree-entries-from-agenda)
  6396. (org-back-to-heading t)
  6397. (funcall cmd)))
  6398. (error "Archiving works only in Org-mode files"))))))
  6399. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6400. "Remove all lines in the agenda that correspond to a given subtree.
  6401. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6402. If this information is not given, the function uses the tree at point."
  6403. (let ((buf (or buf (current-buffer))) m p)
  6404. (save-excursion
  6405. (unless (and beg end)
  6406. (org-back-to-heading t)
  6407. (setq beg (point))
  6408. (org-end-of-subtree t)
  6409. (setq end (point)))
  6410. (set-buffer (get-buffer org-agenda-buffer-name))
  6411. (save-excursion
  6412. (goto-char (point-max))
  6413. (beginning-of-line 1)
  6414. (while (not (bobp))
  6415. (when (and (setq m (org-get-at-bol 'org-marker))
  6416. (equal buf (marker-buffer m))
  6417. (setq p (marker-position m))
  6418. (>= p beg)
  6419. (< p end))
  6420. (let ((inhibit-read-only t))
  6421. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6422. (beginning-of-line 0))))))
  6423. (defun org-agenda-refile (&optional goto rfloc no-update)
  6424. "Refile the item at point."
  6425. (interactive "P")
  6426. (if (equal goto '(16))
  6427. (org-refile-goto-last-stored)
  6428. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6429. (org-agenda-error)))
  6430. (buffer (marker-buffer marker))
  6431. (pos (marker-position marker))
  6432. (rfloc (or rfloc
  6433. (org-refile-get-location
  6434. (if goto "Goto" "Refile to") buffer
  6435. org-refile-allow-creating-parent-nodes))))
  6436. (with-current-buffer buffer
  6437. (save-excursion
  6438. (save-restriction
  6439. (widen)
  6440. (goto-char marker)
  6441. (org-remove-subtree-entries-from-agenda)
  6442. (org-refile goto buffer rfloc)))))
  6443. (unless no-update (org-agenda-redo))))
  6444. (defun org-agenda-open-link (&optional arg)
  6445. "Follow the link in the current line, if any.
  6446. This looks for a link in the displayed line in the agenda. It also looks
  6447. at the text of the entry itself."
  6448. (interactive "P")
  6449. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6450. (org-get-at-bol 'org-marker)))
  6451. (buffer (and marker (marker-buffer marker)))
  6452. (prefix (buffer-substring
  6453. (point-at-bol) (point-at-eol))))
  6454. (cond
  6455. (buffer
  6456. (with-current-buffer buffer
  6457. (save-excursion
  6458. (save-restriction
  6459. (widen)
  6460. (goto-char marker)
  6461. (org-offer-links-in-entry arg prefix)))))
  6462. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6463. (save-excursion
  6464. (beginning-of-line 1)
  6465. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6466. (org-open-link-from-string (match-string 1)))
  6467. (t (error "No link to open here")))))
  6468. (defun org-agenda-copy-local-variable (var)
  6469. "Get a variable from a referenced buffer and install it here."
  6470. (let ((m (org-get-at-bol 'org-marker)))
  6471. (when (and m (buffer-live-p (marker-buffer m)))
  6472. (org-set-local var (with-current-buffer (marker-buffer m)
  6473. (symbol-value var))))))
  6474. (defun org-agenda-switch-to (&optional delete-other-windows)
  6475. "Go to the Org-mode file which contains the item at point."
  6476. (interactive)
  6477. (if (and org-return-follows-link
  6478. (not (org-get-at-bol 'org-marker))
  6479. (org-in-regexp org-bracket-link-regexp))
  6480. (org-open-link-from-string (match-string 0))
  6481. (let* ((marker (or (org-get-at-bol 'org-marker)
  6482. (org-agenda-error)))
  6483. (buffer (marker-buffer marker))
  6484. (pos (marker-position marker)))
  6485. (org-pop-to-buffer-same-window buffer)
  6486. (and delete-other-windows (delete-other-windows))
  6487. (widen)
  6488. (goto-char pos)
  6489. (when (org-mode-p)
  6490. (org-show-context 'agenda)
  6491. (save-excursion
  6492. (and (outline-next-heading)
  6493. (org-flag-heading nil))) ; show the next heading
  6494. (when (outline-invisible-p)
  6495. (show-entry)))))) ; display invisible text
  6496. (defun org-agenda-goto-mouse (ev)
  6497. "Go to the Org-mode file which contains the item at the mouse click."
  6498. (interactive "e")
  6499. (mouse-set-point ev)
  6500. (org-agenda-goto))
  6501. (defun org-agenda-show (&optional full-entry)
  6502. "Display the Org-mode file which contains the item at point.
  6503. With prefix argument FULL-ENTRY, make the entire entry visible
  6504. if it was hidden in the outline."
  6505. (interactive "P")
  6506. (let ((win (selected-window)))
  6507. (if full-entry
  6508. (let ((org-show-entry-below t))
  6509. (org-agenda-goto t))
  6510. (org-agenda-goto t))
  6511. (select-window win)))
  6512. (defvar org-agenda-show-window nil)
  6513. (defun org-agenda-show-and-scroll-up ()
  6514. "Display the Org-mode file which contains the item at point.
  6515. When called repeatedly, scroll the window that is displaying the buffer."
  6516. (interactive)
  6517. (let ((win (selected-window)))
  6518. (if (and (window-live-p org-agenda-show-window)
  6519. (eq this-command last-command))
  6520. (progn
  6521. (select-window org-agenda-show-window)
  6522. (ignore-errors (scroll-up)))
  6523. (org-agenda-goto t)
  6524. (show-subtree)
  6525. (setq org-agenda-show-window (selected-window)))
  6526. (select-window win)))
  6527. (defun org-agenda-show-scroll-down ()
  6528. "Scroll down the window showing the agenda."
  6529. (interactive)
  6530. (let ((win (selected-window)))
  6531. (when (window-live-p org-agenda-show-window)
  6532. (select-window org-agenda-show-window)
  6533. (ignore-errors (scroll-down))
  6534. (select-window win))))
  6535. (defun org-agenda-show-1 (&optional more)
  6536. "Display the Org-mode file which contains the item at point.
  6537. The prefix arg selects the amount of information to display:
  6538. 0 hide the subtree
  6539. 1 just show the entry according to defaults.
  6540. 2 show the children view
  6541. 3 show the subtree view
  6542. 4 show the entire subtree and any LOGBOOK drawers
  6543. 5 show the entire subtree and any drawers
  6544. With prefix argument FULL-ENTRY, make the entire entry visible
  6545. if it was hidden in the outline."
  6546. (interactive "p")
  6547. (let ((win (selected-window)))
  6548. (org-agenda-goto t)
  6549. (org-recenter-heading 1)
  6550. (cond
  6551. ((= more 0)
  6552. (hide-subtree)
  6553. (save-excursion
  6554. (org-back-to-heading)
  6555. (run-hook-with-args 'org-cycle-hook 'folded))
  6556. (message "Remote: FOLDED"))
  6557. ((and (org-called-interactively-p 'any) (= more 1))
  6558. (message "Remote: show with default settings"))
  6559. ((= more 2)
  6560. (show-entry)
  6561. (show-children)
  6562. (save-excursion
  6563. (org-back-to-heading)
  6564. (run-hook-with-args 'org-cycle-hook 'children))
  6565. (message "Remote: CHILDREN"))
  6566. ((= more 3)
  6567. (show-subtree)
  6568. (save-excursion
  6569. (org-back-to-heading)
  6570. (run-hook-with-args 'org-cycle-hook 'subtree))
  6571. (message "Remote: SUBTREE"))
  6572. ((= more 4)
  6573. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6574. (org-drawer-regexp
  6575. (concat "^[ \t]*:\\("
  6576. (mapconcat 'regexp-quote org-drawers "\\|")
  6577. "\\):[ \t]*$")))
  6578. (show-subtree)
  6579. (save-excursion
  6580. (org-back-to-heading)
  6581. (org-cycle-hide-drawers 'subtree)))
  6582. (message "Remote: SUBTREE AND LOGBOOK"))
  6583. ((> more 4)
  6584. (show-subtree)
  6585. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6586. (select-window win)))
  6587. (defun org-recenter-heading (n)
  6588. (save-excursion
  6589. (org-back-to-heading)
  6590. (recenter n)))
  6591. (defvar org-agenda-cycle-counter nil)
  6592. (defun org-agenda-cycle-show (&optional n)
  6593. "Show the current entry in another window, with default settings.
  6594. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6595. When use repeatedly in immediate succession, the remote entry will cycle
  6596. through visibility
  6597. children -> subtree -> folded
  6598. When called with a numeric prefix arg, that arg will be passed through to
  6599. `org-agenda-show-1'. For the interpretation of that argument, see the
  6600. docstring of `org-agenda-show-1'."
  6601. (interactive "P")
  6602. (if (integerp n)
  6603. (setq org-agenda-cycle-counter n)
  6604. (if (not (eq last-command this-command))
  6605. (setq org-agenda-cycle-counter 1)
  6606. (if (equal org-agenda-cycle-counter 0)
  6607. (setq org-agenda-cycle-counter 2)
  6608. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6609. (if (> org-agenda-cycle-counter 3)
  6610. (setq org-agenda-cycle-counter 0)))))
  6611. (org-agenda-show-1 org-agenda-cycle-counter))
  6612. (defun org-agenda-recenter (arg)
  6613. "Display the Org-mode file which contains the item at point and recenter."
  6614. (interactive "P")
  6615. (let ((win (selected-window)))
  6616. (org-agenda-goto t)
  6617. (recenter arg)
  6618. (select-window win)))
  6619. (defun org-agenda-show-mouse (ev)
  6620. "Display the Org-mode file which contains the item at the mouse click."
  6621. (interactive "e")
  6622. (mouse-set-point ev)
  6623. (org-agenda-show))
  6624. (defun org-agenda-check-no-diary ()
  6625. "Check if the entry is a diary link and abort if yes."
  6626. (if (org-get-at-bol 'org-agenda-diary-link)
  6627. (org-agenda-error)))
  6628. (defun org-agenda-error ()
  6629. (error "Command not allowed in this line"))
  6630. (defun org-agenda-tree-to-indirect-buffer ()
  6631. "Show the subtree corresponding to the current entry in an indirect buffer.
  6632. This calls the command `org-tree-to-indirect-buffer' from the original
  6633. Org-mode buffer.
  6634. With numerical prefix arg ARG, go up to this level and then take that tree.
  6635. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6636. use the dedicated frame)."
  6637. (interactive)
  6638. (org-agenda-check-no-diary)
  6639. (let* ((marker (or (org-get-at-bol 'org-marker)
  6640. (org-agenda-error)))
  6641. (buffer (marker-buffer marker))
  6642. (pos (marker-position marker)))
  6643. (with-current-buffer buffer
  6644. (save-excursion
  6645. (goto-char pos)
  6646. (call-interactively 'org-tree-to-indirect-buffer)))))
  6647. (defvar org-last-heading-marker (make-marker)
  6648. "Marker pointing to the headline that last changed its TODO state
  6649. by a remote command from the agenda.")
  6650. (defun org-agenda-todo-nextset ()
  6651. "Switch TODO entry to next sequence."
  6652. (interactive)
  6653. (org-agenda-todo 'nextset))
  6654. (defun org-agenda-todo-previousset ()
  6655. "Switch TODO entry to previous sequence."
  6656. (interactive)
  6657. (org-agenda-todo 'previousset))
  6658. (defun org-agenda-todo (&optional arg)
  6659. "Cycle TODO state of line at point, also in Org-mode file.
  6660. This changes the line at point, all other lines in the agenda referring to
  6661. the same tree node, and the headline of the tree node in the Org-mode file."
  6662. (interactive "P")
  6663. (org-agenda-check-no-diary)
  6664. (let* ((col (current-column))
  6665. (marker (or (org-get-at-bol 'org-marker)
  6666. (org-agenda-error)))
  6667. (buffer (marker-buffer marker))
  6668. (pos (marker-position marker))
  6669. (hdmarker (org-get-at-bol 'org-hd-marker))
  6670. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6671. (inhibit-read-only t)
  6672. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6673. (org-with-remote-undo buffer
  6674. (with-current-buffer buffer
  6675. (widen)
  6676. (goto-char pos)
  6677. (org-show-context 'agenda)
  6678. (save-excursion
  6679. (and (outline-next-heading)
  6680. (org-flag-heading nil))) ; show the next heading
  6681. (let ((current-prefix-arg arg))
  6682. (call-interactively 'org-todo))
  6683. (and (bolp) (forward-char 1))
  6684. (setq newhead (org-get-heading))
  6685. (when (and (org-bound-and-true-p
  6686. org-agenda-headline-snapshot-before-repeat)
  6687. (not (equal org-agenda-headline-snapshot-before-repeat
  6688. newhead))
  6689. todayp)
  6690. (setq newhead org-agenda-headline-snapshot-before-repeat
  6691. just-one t))
  6692. (save-excursion
  6693. (org-back-to-heading)
  6694. (move-marker org-last-heading-marker (point))))
  6695. (beginning-of-line 1)
  6696. (save-excursion
  6697. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6698. (org-move-to-column col))))
  6699. (defun org-agenda-add-note (&optional arg)
  6700. "Add a time-stamped note to the entry at point."
  6701. (interactive "P")
  6702. (org-agenda-check-no-diary)
  6703. (let* ((marker (or (org-get-at-bol 'org-marker)
  6704. (org-agenda-error)))
  6705. (buffer (marker-buffer marker))
  6706. (pos (marker-position marker))
  6707. (hdmarker (org-get-at-bol 'org-hd-marker))
  6708. (inhibit-read-only t))
  6709. (with-current-buffer buffer
  6710. (widen)
  6711. (goto-char pos)
  6712. (org-show-context 'agenda)
  6713. (save-excursion
  6714. (and (outline-next-heading)
  6715. (org-flag-heading nil))) ; show the next heading
  6716. (org-add-note))))
  6717. (defun org-agenda-change-all-lines (newhead hdmarker
  6718. &optional fixface just-this)
  6719. "Change all lines in the agenda buffer which match HDMARKER.
  6720. The new content of the line will be NEWHEAD (as modified by
  6721. `org-format-agenda-item'). HDMARKER is checked with
  6722. `equal' against all `org-hd-marker' text properties in the file.
  6723. If FIXFACE is non-nil, the face of each item is modified according to
  6724. the new TODO state.
  6725. If JUST-THIS is non-nil, change just the current line, not all.
  6726. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6727. (let* ((inhibit-read-only t)
  6728. (line (org-current-line))
  6729. (thetags (with-current-buffer (marker-buffer hdmarker)
  6730. (save-excursion (save-restriction (widen)
  6731. (goto-char hdmarker)
  6732. (org-get-tags-at)))))
  6733. props m pl undone-face done-face finish new dotime cat tags)
  6734. (save-excursion
  6735. (goto-char (point-max))
  6736. (beginning-of-line 1)
  6737. (while (not finish)
  6738. (setq finish (bobp))
  6739. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6740. (or (not just-this) (= (org-current-line) line))
  6741. (equal m hdmarker))
  6742. (setq props (text-properties-at (point))
  6743. dotime (org-get-at-bol 'dotime)
  6744. cat (org-get-at-bol 'org-category)
  6745. tags thetags
  6746. new
  6747. (let ((org-prefix-format-compiled
  6748. (or (get-text-property (point) 'format)
  6749. org-prefix-format-compiled)))
  6750. (with-current-buffer (marker-buffer hdmarker)
  6751. (save-excursion
  6752. (save-restriction
  6753. (widen)
  6754. (org-format-agenda-item (org-get-at-bol 'extra)
  6755. newhead cat tags dotime)))))
  6756. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6757. undone-face (org-get-at-bol 'undone-face)
  6758. done-face (org-get-at-bol 'done-face))
  6759. (beginning-of-line 1)
  6760. (cond
  6761. ((equal new "")
  6762. (and (looking-at ".*\n?") (replace-match "")))
  6763. ((looking-at ".*")
  6764. (replace-match new t t)
  6765. (beginning-of-line 1)
  6766. (add-text-properties (point-at-bol) (point-at-eol) props)
  6767. (when fixface
  6768. (add-text-properties
  6769. (point-at-bol) (point-at-eol)
  6770. (list 'face
  6771. (if org-last-todo-state-is-todo
  6772. undone-face done-face))))
  6773. (org-agenda-highlight-todo 'line)
  6774. (beginning-of-line 1))
  6775. (t (error "Line update did not work"))))
  6776. (beginning-of-line 0)))
  6777. (org-finalize-agenda)))
  6778. (defun org-agenda-align-tags (&optional line)
  6779. "Align all tags in agenda items to `org-agenda-tags-column'."
  6780. (let ((inhibit-read-only t) l c)
  6781. (save-excursion
  6782. (goto-char (if line (point-at-bol) (point-min)))
  6783. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6784. (if line (point-at-eol) nil) t)
  6785. (add-text-properties
  6786. (match-beginning 2) (match-end 2)
  6787. (list 'face (delq nil (let ((prop (get-text-property
  6788. (match-beginning 2) 'face)))
  6789. (or (listp prop) (setq prop (list prop)))
  6790. (if (memq 'org-tag prop)
  6791. prop
  6792. (cons 'org-tag prop))))))
  6793. (setq l (- (match-end 2) (match-beginning 2))
  6794. c (if (< org-agenda-tags-column 0)
  6795. (- (abs org-agenda-tags-column) l)
  6796. org-agenda-tags-column))
  6797. (delete-region (match-beginning 1) (match-end 1))
  6798. (goto-char (match-beginning 1))
  6799. (insert (org-add-props
  6800. (make-string (max 1 (- c (current-column))) ?\ )
  6801. (plist-put (copy-sequence (text-properties-at (point)))
  6802. 'face nil))))
  6803. (goto-char (point-min))
  6804. (org-font-lock-add-tag-faces (point-max)))))
  6805. (defun org-agenda-priority-up ()
  6806. "Increase the priority of line at point, also in Org-mode file."
  6807. (interactive)
  6808. (org-agenda-priority 'up))
  6809. (defun org-agenda-priority-down ()
  6810. "Decrease the priority of line at point, also in Org-mode file."
  6811. (interactive)
  6812. (org-agenda-priority 'down))
  6813. (defun org-agenda-priority (&optional force-direction)
  6814. "Set the priority of line at point, also in Org-mode file.
  6815. This changes the line at point, all other lines in the agenda referring to
  6816. the same tree node, and the headline of the tree node in the Org-mode file."
  6817. (interactive)
  6818. (unless org-enable-priority-commands
  6819. (error "Priority commands are disabled"))
  6820. (org-agenda-check-no-diary)
  6821. (let* ((marker (or (org-get-at-bol 'org-marker)
  6822. (org-agenda-error)))
  6823. (hdmarker (org-get-at-bol 'org-hd-marker))
  6824. (buffer (marker-buffer hdmarker))
  6825. (pos (marker-position hdmarker))
  6826. (inhibit-read-only t)
  6827. newhead)
  6828. (org-with-remote-undo buffer
  6829. (with-current-buffer buffer
  6830. (widen)
  6831. (goto-char pos)
  6832. (org-show-context 'agenda)
  6833. (save-excursion
  6834. (and (outline-next-heading)
  6835. (org-flag-heading nil))) ; show the next heading
  6836. (funcall 'org-priority force-direction)
  6837. (end-of-line 1)
  6838. (setq newhead (org-get-heading)))
  6839. (org-agenda-change-all-lines newhead hdmarker)
  6840. (beginning-of-line 1))))
  6841. ;; FIXME: should fix the tags property of the agenda line.
  6842. (defun org-agenda-set-tags (&optional tag onoff)
  6843. "Set tags for the current headline."
  6844. (interactive)
  6845. (org-agenda-check-no-diary)
  6846. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6847. (call-interactively 'org-change-tag-in-region)
  6848. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6849. (org-agenda-error)))
  6850. (buffer (marker-buffer hdmarker))
  6851. (pos (marker-position hdmarker))
  6852. (inhibit-read-only t)
  6853. newhead)
  6854. (org-with-remote-undo buffer
  6855. (with-current-buffer buffer
  6856. (widen)
  6857. (goto-char pos)
  6858. (save-excursion
  6859. (org-show-context 'agenda))
  6860. (save-excursion
  6861. (and (outline-next-heading)
  6862. (org-flag-heading nil))) ; show the next heading
  6863. (goto-char pos)
  6864. (if tag
  6865. (org-toggle-tag tag onoff)
  6866. (call-interactively 'org-set-tags))
  6867. (end-of-line 1)
  6868. (setq newhead (org-get-heading)))
  6869. (org-agenda-change-all-lines newhead hdmarker)
  6870. (beginning-of-line 1)))))
  6871. (defun org-agenda-set-property ()
  6872. "Set a property for the current headline."
  6873. (interactive)
  6874. (org-agenda-check-no-diary)
  6875. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6876. (org-agenda-error)))
  6877. (buffer (marker-buffer hdmarker))
  6878. (pos (marker-position hdmarker))
  6879. (inhibit-read-only t)
  6880. newhead)
  6881. (org-with-remote-undo buffer
  6882. (with-current-buffer buffer
  6883. (widen)
  6884. (goto-char pos)
  6885. (save-excursion
  6886. (org-show-context 'agenda))
  6887. (save-excursion
  6888. (and (outline-next-heading)
  6889. (org-flag-heading nil))) ; show the next heading
  6890. (goto-char pos)
  6891. (call-interactively 'org-set-property)))))
  6892. (defun org-agenda-set-effort ()
  6893. "Set the effort property for the current headline."
  6894. (interactive)
  6895. (org-agenda-check-no-diary)
  6896. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6897. (org-agenda-error)))
  6898. (buffer (marker-buffer hdmarker))
  6899. (pos (marker-position hdmarker))
  6900. (inhibit-read-only t)
  6901. newhead)
  6902. (org-with-remote-undo buffer
  6903. (with-current-buffer buffer
  6904. (widen)
  6905. (goto-char pos)
  6906. (save-excursion
  6907. (org-show-context 'agenda))
  6908. (save-excursion
  6909. (and (outline-next-heading)
  6910. (org-flag-heading nil))) ; show the next heading
  6911. (goto-char pos)
  6912. (call-interactively 'org-set-effort)
  6913. (end-of-line 1)
  6914. (setq newhead (org-get-heading)))
  6915. (org-agenda-change-all-lines newhead hdmarker))))
  6916. (defun org-agenda-toggle-archive-tag ()
  6917. "Toggle the archive tag for the current entry."
  6918. (interactive)
  6919. (org-agenda-check-no-diary)
  6920. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6921. (org-agenda-error)))
  6922. (buffer (marker-buffer hdmarker))
  6923. (pos (marker-position hdmarker))
  6924. (inhibit-read-only t)
  6925. newhead)
  6926. (org-with-remote-undo buffer
  6927. (with-current-buffer buffer
  6928. (widen)
  6929. (goto-char pos)
  6930. (org-show-context 'agenda)
  6931. (save-excursion
  6932. (and (outline-next-heading)
  6933. (org-flag-heading nil))) ; show the next heading
  6934. (call-interactively 'org-toggle-archive-tag)
  6935. (end-of-line 1)
  6936. (setq newhead (org-get-heading)))
  6937. (org-agenda-change-all-lines newhead hdmarker)
  6938. (beginning-of-line 1))))
  6939. (defun org-agenda-do-date-later (arg)
  6940. (interactive "P")
  6941. (cond
  6942. ((or (equal arg '(16))
  6943. (memq last-command
  6944. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6945. (setq this-command 'org-agenda-date-later-minutes)
  6946. (org-agenda-date-later-minutes 1))
  6947. ((or (equal arg '(4))
  6948. (memq last-command
  6949. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6950. (setq this-command 'org-agenda-date-later-hours)
  6951. (org-agenda-date-later-hours 1))
  6952. (t
  6953. (org-agenda-date-later (prefix-numeric-value arg)))))
  6954. (defun org-agenda-do-date-earlier (arg)
  6955. (interactive "P")
  6956. (cond
  6957. ((or (equal arg '(16))
  6958. (memq last-command
  6959. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6960. (setq this-command 'org-agenda-date-earlier-minutes)
  6961. (org-agenda-date-earlier-minutes 1))
  6962. ((or (equal arg '(4))
  6963. (memq last-command
  6964. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6965. (setq this-command 'org-agenda-date-earlier-hours)
  6966. (org-agenda-date-earlier-hours 1))
  6967. (t
  6968. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6969. (defun org-agenda-date-later (arg &optional what)
  6970. "Change the date of this item to ARG day(s) later."
  6971. (interactive "p")
  6972. (org-agenda-check-type t 'agenda 'timeline)
  6973. (org-agenda-check-no-diary)
  6974. (let* ((marker (or (org-get-at-bol 'org-marker)
  6975. (org-agenda-error)))
  6976. (buffer (marker-buffer marker))
  6977. (pos (marker-position marker)))
  6978. (org-with-remote-undo buffer
  6979. (with-current-buffer buffer
  6980. (widen)
  6981. (goto-char pos)
  6982. (if (not (org-at-timestamp-p))
  6983. (error "Cannot find time stamp"))
  6984. (org-timestamp-change arg (or what 'day)))
  6985. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6986. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6987. (defun org-agenda-date-earlier (arg &optional what)
  6988. "Change the date of this item to ARG day(s) earlier."
  6989. (interactive "p")
  6990. (org-agenda-date-later (- arg) what))
  6991. (defun org-agenda-date-later-minutes (arg)
  6992. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6993. (interactive "p")
  6994. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6995. (org-agenda-date-later arg 'minute))
  6996. (defun org-agenda-date-earlier-minutes (arg)
  6997. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6998. (interactive "p")
  6999. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7000. (org-agenda-date-earlier arg 'minute))
  7001. (defun org-agenda-date-later-hours (arg)
  7002. "Change the time of this item, in hour steps."
  7003. (interactive "p")
  7004. (org-agenda-date-later arg 'hour))
  7005. (defun org-agenda-date-earlier-hours (arg)
  7006. "Change the time of this item, in hour steps."
  7007. (interactive "p")
  7008. (org-agenda-date-earlier arg 'hour))
  7009. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7010. "Show new date stamp via text properties."
  7011. ;; We use text properties to make this undoable
  7012. (let ((inhibit-read-only t)
  7013. (buffer-invisibility-spec))
  7014. (setq stamp (concat " " prefix " => " stamp))
  7015. (save-excursion
  7016. (goto-char (point-max))
  7017. (while (not (bobp))
  7018. (when (equal marker (org-get-at-bol 'org-marker))
  7019. (org-move-to-column (- (window-width) (length stamp)) t)
  7020. (org-agenda-fix-tags-filter-overlays-at (point))
  7021. (if (featurep 'xemacs)
  7022. ;; Use `duplicable' property to trigger undo recording
  7023. (let ((ex (make-extent nil nil))
  7024. (gl (make-glyph stamp)))
  7025. (set-glyph-face gl 'secondary-selection)
  7026. (set-extent-properties
  7027. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7028. (insert-extent ex (1- (point)) (point-at-eol)))
  7029. (add-text-properties
  7030. (1- (point)) (point-at-eol)
  7031. (list 'display (org-add-props stamp nil
  7032. 'face 'secondary-selection))))
  7033. (beginning-of-line 1))
  7034. (beginning-of-line 0)))))
  7035. (defun org-agenda-date-prompt (arg)
  7036. "Change the date of this item. Date is prompted for, with default today.
  7037. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7038. be used to request time specification in the time stamp."
  7039. (interactive "P")
  7040. (org-agenda-check-type t 'agenda 'timeline)
  7041. (org-agenda-check-no-diary)
  7042. (let* ((marker (or (org-get-at-bol 'org-marker)
  7043. (org-agenda-error)))
  7044. (buffer (marker-buffer marker))
  7045. (pos (marker-position marker)))
  7046. (org-with-remote-undo buffer
  7047. (with-current-buffer buffer
  7048. (widen)
  7049. (goto-char pos)
  7050. (if (not (org-at-timestamp-p t))
  7051. (error "Cannot find time stamp"))
  7052. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7053. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7054. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7055. (defun org-agenda-schedule (arg &optional time)
  7056. "Schedule the item at point.
  7057. ARG is passed through to `org-schedule'."
  7058. (interactive "P")
  7059. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7060. (org-agenda-check-no-diary)
  7061. (let* ((marker (or (org-get-at-bol 'org-marker)
  7062. (org-agenda-error)))
  7063. (type (marker-insertion-type marker))
  7064. (buffer (marker-buffer marker))
  7065. (pos (marker-position marker))
  7066. (org-insert-labeled-timestamps-at-point nil)
  7067. ts)
  7068. (set-marker-insertion-type marker t)
  7069. (org-with-remote-undo buffer
  7070. (with-current-buffer buffer
  7071. (widen)
  7072. (goto-char pos)
  7073. (setq ts (org-schedule arg time)))
  7074. (org-agenda-show-new-time marker ts "S"))
  7075. (message "Item scheduled for %s" ts)))
  7076. (defun org-agenda-deadline (arg &optional time)
  7077. "Schedule the item at point.
  7078. ARG is passed through to `org-deadline'."
  7079. (interactive "P")
  7080. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7081. (org-agenda-check-no-diary)
  7082. (let* ((marker (or (org-get-at-bol 'org-marker)
  7083. (org-agenda-error)))
  7084. (buffer (marker-buffer marker))
  7085. (pos (marker-position marker))
  7086. (org-insert-labeled-timestamps-at-point nil)
  7087. ts)
  7088. (org-with-remote-undo buffer
  7089. (with-current-buffer buffer
  7090. (widen)
  7091. (goto-char pos)
  7092. (setq ts (org-deadline arg time)))
  7093. (org-agenda-show-new-time marker ts "D"))
  7094. (message "Deadline for this item set to %s" ts)))
  7095. (defun org-agenda-action ()
  7096. "Select entry for agenda action, or execute an agenda action.
  7097. This command prompts for another letter. Valid inputs are:
  7098. m Mark the entry at point for an agenda action
  7099. s Schedule the marked entry to the date at the cursor
  7100. d Set the deadline of the marked entry to the date at the cursor
  7101. r Call `org-remember' with cursor date as the default date
  7102. c Call `org-capture' with cursor date as the default date
  7103. SPC Show marked entry in other window
  7104. TAB Visit marked entry in other window
  7105. The cursor may be at a date in the calendar, or in the Org agenda."
  7106. (interactive)
  7107. (let (ans)
  7108. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7109. (setq ans (read-char-exclusive))
  7110. (cond
  7111. ((equal ans ?m)
  7112. ;; Mark this entry
  7113. (if (eq major-mode 'org-agenda-mode)
  7114. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7115. (org-get-at-bol 'org-marker))))
  7116. (if m
  7117. (progn
  7118. (move-marker org-agenda-action-marker
  7119. (marker-position m) (marker-buffer m))
  7120. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7121. (error "Don't know which entry to mark")))
  7122. (error "This command works only in the agenda")))
  7123. ((equal ans ?s)
  7124. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7125. ((equal ans ?d)
  7126. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7127. ((equal ans ?r)
  7128. (org-agenda-do-action '(org-remember) t))
  7129. ((equal ans ?c)
  7130. (org-agenda-do-action '(org-capture) t))
  7131. ((equal ans ?\ )
  7132. (let ((cw (selected-window)))
  7133. (org-switch-to-buffer-other-window
  7134. (marker-buffer org-agenda-action-marker))
  7135. (goto-char org-agenda-action-marker)
  7136. (org-show-context 'agenda)
  7137. (select-window cw)))
  7138. ((equal ans ?\C-i)
  7139. (org-switch-to-buffer-other-window
  7140. (marker-buffer org-agenda-action-marker))
  7141. (goto-char org-agenda-action-marker)
  7142. (org-show-context 'agenda))
  7143. (t (error "Invalid agenda action %c" ans)))))
  7144. (defun org-agenda-do-action (form &optional current-buffer)
  7145. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7146. (let ((org-overriding-default-time (org-get-cursor-date)))
  7147. (if current-buffer
  7148. (eval form)
  7149. (if (not (marker-buffer org-agenda-action-marker))
  7150. (error "No entry has been selected for agenda action")
  7151. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7152. (save-excursion
  7153. (save-restriction
  7154. (widen)
  7155. (goto-char org-agenda-action-marker)
  7156. (eval form))))))))
  7157. (defun org-agenda-clock-in (&optional arg)
  7158. "Start the clock on the currently selected item."
  7159. (interactive "P")
  7160. (org-agenda-check-no-diary)
  7161. (if (equal arg '(4))
  7162. (org-clock-in arg)
  7163. (let* ((marker (or (org-get-at-bol 'org-marker)
  7164. (org-agenda-error)))
  7165. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7166. marker))
  7167. (pos (marker-position marker))
  7168. newhead)
  7169. (org-with-remote-undo (marker-buffer marker)
  7170. (with-current-buffer (marker-buffer marker)
  7171. (widen)
  7172. (goto-char pos)
  7173. (org-show-context 'agenda)
  7174. (org-show-entry)
  7175. (org-cycle-hide-drawers 'children)
  7176. (org-clock-in arg)
  7177. (setq newhead (org-get-heading)))
  7178. (org-agenda-change-all-lines newhead hdmarker)))))
  7179. (defun org-agenda-clock-out ()
  7180. "Stop the currently running clock."
  7181. (interactive)
  7182. (unless (marker-buffer org-clock-marker)
  7183. (error "No running clock"))
  7184. (let ((marker (make-marker)) newhead)
  7185. (org-with-remote-undo (marker-buffer org-clock-marker)
  7186. (with-current-buffer (marker-buffer org-clock-marker)
  7187. (save-excursion
  7188. (save-restriction
  7189. (widen)
  7190. (goto-char org-clock-marker)
  7191. (org-back-to-heading t)
  7192. (move-marker marker (point))
  7193. (org-clock-out)
  7194. (setq newhead (org-get-heading))))))
  7195. (org-agenda-change-all-lines newhead marker)
  7196. (move-marker marker nil)))
  7197. (defun org-agenda-clock-cancel (&optional arg)
  7198. "Cancel the currently running clock."
  7199. (interactive "P")
  7200. (unless (marker-buffer org-clock-marker)
  7201. (error "No running clock"))
  7202. (org-with-remote-undo (marker-buffer org-clock-marker)
  7203. (org-clock-cancel)))
  7204. (defun org-agenda-clock-goto ()
  7205. "Jump to the currently clocked in task within the agenda.
  7206. If the currently clocked in task is not listed in the agenda
  7207. buffer, display it in another window."
  7208. (interactive)
  7209. (let (pos)
  7210. (mapc (lambda (o)
  7211. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7212. (setq pos (overlay-start o))))
  7213. (overlays-in (point-min) (point-max)))
  7214. (cond (pos (goto-char pos))
  7215. ;; If the currently clocked entry is not in the agenda
  7216. ;; buffer, we visit it in another window:
  7217. (org-clock-current-task
  7218. (org-switch-to-buffer-other-window (org-clock-goto)))
  7219. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7220. (defun org-agenda-diary-entry-in-org-file ()
  7221. "Make a diary entry in the file `org-agenda-diary-file'."
  7222. (let (d1 d2 char (text "") dp1 dp2)
  7223. (if (equal (buffer-name) "*Calendar*")
  7224. (setq d1 (calendar-cursor-to-date t)
  7225. d2 (car calendar-mark-ring))
  7226. (setq dp1 (get-text-property (point-at-bol) 'day))
  7227. (unless dp1 (error "No date defined in current line"))
  7228. (setq d1 (calendar-gregorian-from-absolute dp1)
  7229. d2 (and (ignore-errors (mark))
  7230. (save-excursion
  7231. (goto-char (mark))
  7232. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7233. (calendar-gregorian-from-absolute dp2))))
  7234. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7235. (setq char (read-char-exclusive))
  7236. (cond
  7237. ((equal char ?d)
  7238. (setq text (read-string "Day entry: "))
  7239. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7240. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7241. ((equal char ?a)
  7242. (setq d1 (list (car d1) (nth 1 d1)
  7243. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7244. (nth 2 d1))))
  7245. (setq text (read-string "Anniversary (use %d to show years): "))
  7246. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7247. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7248. ((equal char ?b)
  7249. (setq text (read-string "Block entry: "))
  7250. (unless (and d1 d2 (not (equal d1 d2)))
  7251. (error "No block of days selected"))
  7252. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7253. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7254. ((equal char ?j)
  7255. (org-switch-to-buffer-other-window
  7256. (find-file-noselect org-agenda-diary-file))
  7257. (require 'org-datetree)
  7258. (org-datetree-find-date-create d1)
  7259. (org-reveal t))
  7260. (t (error "Invalid selection character `%c'" char)))))
  7261. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7262. "Where in `org-agenda-diary-file' should new entries be added?
  7263. Valid values:
  7264. date-tree in the date tree, as child of the date
  7265. top-level as top-level entries at the end of the file."
  7266. :group 'org-agenda
  7267. :type '(choice
  7268. (const :tag "in a date tree" date-tree)
  7269. (const :tag "as top level at end of file" top-level)))
  7270. (defcustom org-agenda-insert-diary-extract-time nil
  7271. "Non-nil means extract any time specification from the diary entry."
  7272. :group 'org-agenda
  7273. :type 'boolean)
  7274. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7275. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7276. If TEXT is not empty, it will become the headline of the new entry, and
  7277. the resulting entry will not be shown. When TEXT is empty, switch to
  7278. `org-agenda-diary-file' and let the user finish the entry there."
  7279. (let ((cw (current-window-configuration)))
  7280. (org-switch-to-buffer-other-window
  7281. (find-file-noselect org-agenda-diary-file))
  7282. (widen)
  7283. (goto-char (point-min))
  7284. (cond
  7285. ((eq type 'anniversary)
  7286. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7287. (progn
  7288. (or (org-on-heading-p t)
  7289. (progn
  7290. (outline-next-heading)
  7291. (insert "* Anniversaries\n\n")
  7292. (beginning-of-line -1)))))
  7293. (outline-next-heading)
  7294. (org-back-over-empty-lines)
  7295. (backward-char 1)
  7296. (insert "\n")
  7297. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7298. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7299. ((eq type 'day)
  7300. (let ((org-prefix-has-time t)
  7301. (org-agenda-time-leading-zero t)
  7302. fmt time time2)
  7303. (if org-agenda-insert-diary-extract-time
  7304. ;; Use org-format-agenda-item to parse text for a time-range and
  7305. ;; remove it. FIXME: This is a hack, we should refactor
  7306. ;; that function to make time extraction available separately
  7307. (setq fmt (org-format-agenda-item nil text nil nil t)
  7308. time (get-text-property 0 'time fmt)
  7309. time2 (if (> (length time) 0)
  7310. ;; split-string removes trailing ...... if
  7311. ;; no end time given. First space
  7312. ;; separates time from date.
  7313. (concat " " (car (split-string time "\\.")))
  7314. nil)
  7315. text (get-text-property 0 'txt fmt)))
  7316. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7317. (org-agenda-insert-diary-as-top-level text)
  7318. (require 'org-datetree)
  7319. (org-datetree-find-date-create d1)
  7320. (org-agenda-insert-diary-make-new-entry text))
  7321. (org-insert-time-stamp (org-time-from-absolute
  7322. (calendar-absolute-from-gregorian d1))
  7323. nil nil nil nil time2))
  7324. (end-of-line 0))
  7325. ((eq type 'block)
  7326. (if (> (calendar-absolute-from-gregorian d1)
  7327. (calendar-absolute-from-gregorian d2))
  7328. (setq d1 (prog1 d2 (setq d2 d1))))
  7329. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7330. (org-agenda-insert-diary-as-top-level text)
  7331. (require 'org-datetree)
  7332. (org-datetree-find-date-create d1)
  7333. (org-agenda-insert-diary-make-new-entry text))
  7334. (org-insert-time-stamp (org-time-from-absolute
  7335. (calendar-absolute-from-gregorian d1)))
  7336. (insert "--")
  7337. (org-insert-time-stamp (org-time-from-absolute
  7338. (calendar-absolute-from-gregorian d2)))
  7339. (end-of-line 0)))
  7340. (if (string-match "\\S-" text)
  7341. (progn
  7342. (set-window-configuration cw)
  7343. (message "%s entry added to %s"
  7344. (capitalize (symbol-name type))
  7345. (abbreviate-file-name org-agenda-diary-file)))
  7346. (org-reveal t)
  7347. (message "Please finish entry here"))))
  7348. (defun org-agenda-insert-diary-as-top-level (text)
  7349. "Make new entry as a top-level entry at the end of the file.
  7350. Add TEXT as headline, and position the cursor in the second line so that
  7351. a timestamp can be added there."
  7352. (widen)
  7353. (goto-char (point-max))
  7354. (or (bolp) (insert "\n"))
  7355. (insert "* " text "\n")
  7356. (if org-adapt-indentation (org-indent-to-column 2)))
  7357. (defun org-agenda-insert-diary-make-new-entry (text)
  7358. "Make new entry as last child of current entry.
  7359. Add TEXT as headline, and position the cursor in the second line so that
  7360. a timestamp can be added there."
  7361. (let ((org-show-following-heading t)
  7362. (org-show-siblings t)
  7363. (org-show-hierarchy-above t)
  7364. (org-show-entry-below t)
  7365. col)
  7366. (outline-next-heading)
  7367. (org-back-over-empty-lines)
  7368. (or (looking-at "[ \t]*$")
  7369. (progn (insert "\n") (backward-char 1)))
  7370. (org-insert-heading nil t)
  7371. (org-do-demote)
  7372. (setq col (current-column))
  7373. (insert text "\n")
  7374. (if org-adapt-indentation (org-indent-to-column col))
  7375. (let ((org-show-following-heading t)
  7376. (org-show-siblings t)
  7377. (org-show-hierarchy-above t)
  7378. (org-show-entry-below t))
  7379. (org-show-context))))
  7380. (defun org-agenda-diary-entry ()
  7381. "Make a diary entry, like the `i' command from the calendar.
  7382. All the standard commands work: block, weekly etc.
  7383. When `org-agenda-diary-file' points to a file,
  7384. `org-agenda-diary-entry-in-org-file' is called instead to create
  7385. entries in that Org-mode file."
  7386. (interactive)
  7387. (org-agenda-check-type t 'agenda 'timeline)
  7388. (if (not (eq org-agenda-diary-file 'diary-file))
  7389. (org-agenda-diary-entry-in-org-file)
  7390. (require 'diary-lib)
  7391. (let* ((char (progn
  7392. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7393. (read-char-exclusive)))
  7394. (cmd (cdr (assoc char
  7395. '((?d . insert-diary-entry)
  7396. (?w . insert-weekly-diary-entry)
  7397. (?m . insert-monthly-diary-entry)
  7398. (?y . insert-yearly-diary-entry)
  7399. (?a . insert-anniversary-diary-entry)
  7400. (?b . insert-block-diary-entry)
  7401. (?c . insert-cyclic-diary-entry)))))
  7402. (oldf (symbol-function 'calendar-cursor-to-date))
  7403. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7404. (point (point))
  7405. (mark (or (mark t) (point))))
  7406. (unless cmd
  7407. (error "No command associated with <%c>" char))
  7408. (unless (and (get-text-property point 'day)
  7409. (or (not (equal ?b char))
  7410. (get-text-property mark 'day)))
  7411. (error "Don't know which date to use for diary entry"))
  7412. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7413. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7414. (let ((calendar-mark-ring
  7415. (list (calendar-gregorian-from-absolute
  7416. (or (get-text-property mark 'day)
  7417. (get-text-property point 'day))))))
  7418. (unwind-protect
  7419. (progn
  7420. (fset 'calendar-cursor-to-date
  7421. (lambda (&optional error dummy)
  7422. (calendar-gregorian-from-absolute
  7423. (get-text-property point 'day))))
  7424. (call-interactively cmd))
  7425. (fset 'calendar-cursor-to-date oldf))))))
  7426. (defun org-agenda-execute-calendar-command (cmd)
  7427. "Execute a calendar command from the agenda, with the date associated to
  7428. the cursor position."
  7429. (org-agenda-check-type t 'agenda 'timeline)
  7430. (require 'diary-lib)
  7431. (unless (get-text-property (point) 'day)
  7432. (error "Don't know which date to use for calendar command"))
  7433. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7434. (point (point))
  7435. (date (calendar-gregorian-from-absolute
  7436. (get-text-property point 'day)))
  7437. ;; the following 2 vars are needed in the calendar
  7438. (displayed-month (car date))
  7439. (displayed-year (nth 2 date)))
  7440. (unwind-protect
  7441. (progn
  7442. (fset 'calendar-cursor-to-date
  7443. (lambda (&optional error dummy)
  7444. (calendar-gregorian-from-absolute
  7445. (get-text-property point 'day))))
  7446. (call-interactively cmd))
  7447. (fset 'calendar-cursor-to-date oldf))))
  7448. (defun org-agenda-phases-of-moon ()
  7449. "Display the phases of the moon for the 3 months around the cursor date."
  7450. (interactive)
  7451. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7452. (defun org-agenda-holidays ()
  7453. "Display the holidays for the 3 months around the cursor date."
  7454. (interactive)
  7455. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7456. (defvar calendar-longitude)
  7457. (defvar calendar-latitude)
  7458. (defvar calendar-location-name)
  7459. (defun org-agenda-sunrise-sunset (arg)
  7460. "Display sunrise and sunset for the cursor date.
  7461. Latitude and longitude can be specified with the variables
  7462. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7463. argument, latitude and longitude will be prompted for."
  7464. (interactive "P")
  7465. (require 'solar)
  7466. (let ((calendar-longitude (if arg nil calendar-longitude))
  7467. (calendar-latitude (if arg nil calendar-latitude))
  7468. (calendar-location-name
  7469. (if arg "the given coordinates" calendar-location-name)))
  7470. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7471. (defun org-agenda-goto-calendar ()
  7472. "Open the Emacs calendar with the date at the cursor."
  7473. (interactive)
  7474. (org-agenda-check-type t 'agenda 'timeline)
  7475. (let* ((day (or (get-text-property (point) 'day)
  7476. (error "Don't know which date to open in calendar")))
  7477. (date (calendar-gregorian-from-absolute day))
  7478. (calendar-move-hook nil)
  7479. (calendar-view-holidays-initially-flag nil)
  7480. (calendar-view-diary-initially-flag nil))
  7481. (calendar)
  7482. (calendar-goto-date date)))
  7483. ;;;###autoload
  7484. (defun org-calendar-goto-agenda ()
  7485. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7486. This is a command that has to be installed in `calendar-mode-map'."
  7487. (interactive)
  7488. (org-agenda-list nil (calendar-absolute-from-gregorian
  7489. (calendar-cursor-to-date))
  7490. nil))
  7491. (defun org-agenda-convert-date ()
  7492. (interactive)
  7493. (org-agenda-check-type t 'agenda 'timeline)
  7494. (let ((day (get-text-property (point) 'day))
  7495. date s)
  7496. (unless day
  7497. (error "Don't know which date to convert"))
  7498. (setq date (calendar-gregorian-from-absolute day))
  7499. (setq s (concat
  7500. "Gregorian: " (calendar-date-string date) "\n"
  7501. "ISO: " (calendar-iso-date-string date) "\n"
  7502. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7503. "Julian: " (calendar-julian-date-string date) "\n"
  7504. "Astron. JD: " (calendar-astro-date-string date)
  7505. " (Julian date number at noon UTC)\n"
  7506. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7507. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7508. "French: " (calendar-french-date-string date) "\n"
  7509. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7510. "Mayan: " (calendar-mayan-date-string date) "\n"
  7511. "Coptic: " (calendar-coptic-date-string date) "\n"
  7512. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7513. "Persian: " (calendar-persian-date-string date) "\n"
  7514. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7515. (with-output-to-temp-buffer "*Dates*"
  7516. (princ s))
  7517. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7518. ;;; Bulk commands
  7519. (defvar org-agenda-bulk-marked-entries nil
  7520. "List of markers that refer to marked entries in the agenda.")
  7521. (defun org-agenda-bulk-marked-p ()
  7522. (eq (get-char-property (point-at-bol) 'type)
  7523. 'org-marked-entry-overlay))
  7524. (defun org-agenda-bulk-mark (&optional arg)
  7525. "Mark the entry at point for future bulk action."
  7526. (interactive "p")
  7527. (dotimes (i (max arg 1))
  7528. (unless (org-get-at-bol 'org-agenda-diary-link)
  7529. (let* ((m (org-get-at-bol 'org-hd-marker))
  7530. ov)
  7531. (unless (org-agenda-bulk-marked-p)
  7532. (unless m (error "Nothing to mark at point"))
  7533. (push m org-agenda-bulk-marked-entries)
  7534. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7535. (org-overlay-display ov "> "
  7536. (org-get-todo-face "TODO")
  7537. 'evaporate)
  7538. (overlay-put ov 'type 'org-marked-entry-overlay))
  7539. (beginning-of-line 2)
  7540. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7541. (beginning-of-line 2))
  7542. (message "%d entries marked for bulk action"
  7543. (length org-agenda-bulk-marked-entries))))))
  7544. (defun org-agenda-bulk-mark-regexp (regexp)
  7545. "Mark entries match REGEXP."
  7546. (interactive "sMark entries matching regexp: ")
  7547. (let (entries-marked)
  7548. (save-excursion
  7549. (goto-char (point-min))
  7550. (goto-char (next-single-property-change (point) 'txt))
  7551. (while (re-search-forward regexp nil t)
  7552. (when (string-match regexp (get-text-property (point) 'txt))
  7553. (setq entries-marked (+ entries-marked 1))
  7554. (call-interactively 'org-agenda-bulk-mark))))
  7555. (if (not entries-marked)
  7556. (message "No entry matching this regexp."))))
  7557. (defun org-agenda-bulk-unmark ()
  7558. "Unmark the entry at point for future bulk action."
  7559. (interactive)
  7560. (when (org-agenda-bulk-marked-p)
  7561. (org-agenda-bulk-remove-overlays
  7562. (point-at-bol) (+ 2 (point-at-bol)))
  7563. (setq org-agenda-bulk-marked-entries
  7564. (delete (org-get-at-bol 'org-hd-marker)
  7565. org-agenda-bulk-marked-entries)))
  7566. (beginning-of-line 2)
  7567. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7568. (beginning-of-line 2))
  7569. (message "%d entries marked for bulk action"
  7570. (length org-agenda-bulk-marked-entries)))
  7571. (defun org-agenda-bulk-toggle ()
  7572. "Toggle marking the entry at point for bulk action."
  7573. (interactive)
  7574. (if (org-agenda-bulk-marked-p)
  7575. (org-agenda-bulk-unmark)
  7576. (org-agenda-bulk-mark)))
  7577. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7578. "Remove the mark overlays between BEG and END in the agenda buffer.
  7579. BEG and END default to the buffer limits.
  7580. This only removes the overlays, it does not remove the markers
  7581. from the list in `org-agenda-bulk-marked-entries'."
  7582. (interactive)
  7583. (mapc (lambda (ov)
  7584. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7585. (delete-overlay ov)))
  7586. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7587. (defun org-agenda-bulk-remove-all-marks ()
  7588. "Remove all marks in the agenda buffer.
  7589. This will remove the markers, and the overlays."
  7590. (interactive)
  7591. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7592. (setq org-agenda-bulk-marked-entries nil)
  7593. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7594. (defun org-agenda-bulk-action (&optional arg)
  7595. "Execute an remote-editing action on all marked entries.
  7596. The prefix arg is passed through to the command if possible."
  7597. (interactive "P")
  7598. ;; Make sure we have markers, and only valid ones
  7599. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7600. (mapc
  7601. (lambda (m)
  7602. (unless (and (markerp m)
  7603. (marker-buffer m)
  7604. (buffer-live-p (marker-buffer m))
  7605. (marker-position m))
  7606. (error "Marker %s for bulk command is invalid" m)))
  7607. org-agenda-bulk-marked-entries)
  7608. ;; Prompt for the bulk command
  7609. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7610. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7611. (when org-agenda-bulk-custom-functions
  7612. (concat " Custom: ["
  7613. (mapconcat (lambda(f) (char-to-string (car f)))
  7614. org-agenda-bulk-custom-functions "")
  7615. "]"))))
  7616. (let* ((action (read-char-exclusive))
  7617. (org-log-refile (if org-log-refile 'time nil))
  7618. (entries (reverse org-agenda-bulk-marked-entries))
  7619. redo-at-end
  7620. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7621. (cond
  7622. ((equal action ?$)
  7623. (setq cmd '(org-agenda-archive)))
  7624. ((equal action ?A)
  7625. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7626. ((member action '(?r ?w))
  7627. (setq rfloc (org-refile-get-location
  7628. "Refile to"
  7629. (marker-buffer (car org-agenda-bulk-marked-entries))
  7630. org-refile-allow-creating-parent-nodes))
  7631. (if (nth 3 rfloc)
  7632. (setcar (nthcdr 3 rfloc)
  7633. (move-marker (make-marker) (nth 3 rfloc)
  7634. (or (get-file-buffer (nth 1 rfloc))
  7635. (find-buffer-visiting (nth 1 rfloc))
  7636. (error "This should not happen")))))
  7637. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7638. redo-at-end t))
  7639. ((equal action ?t)
  7640. (setq state (org-icompleting-read
  7641. "Todo state: "
  7642. (with-current-buffer (marker-buffer (car entries))
  7643. (mapcar 'list org-todo-keywords-1))))
  7644. (setq cmd `(let ((org-inhibit-blocking t)
  7645. (org-inhibit-logging 'note))
  7646. (org-agenda-todo ,state))))
  7647. ((memq action '(?- ?+))
  7648. (setq tag (org-icompleting-read
  7649. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7650. (with-current-buffer (marker-buffer (car entries))
  7651. (delq nil
  7652. (mapcar (lambda (x)
  7653. (if (stringp (car x)) x)) org-tag-alist)))))
  7654. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7655. ((memq action '(?s ?d))
  7656. (let* ((date (unless arg
  7657. (org-read-date
  7658. nil nil nil
  7659. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7660. (ans (if arg nil org-read-date-final-answer))
  7661. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7662. (setq cmd `(let* ((bound (fboundp 'read-string))
  7663. (old (and bound (symbol-function 'read-string))))
  7664. (unwind-protect
  7665. (progn
  7666. (fset 'read-string (lambda (&rest ignore) ,ans))
  7667. (eval '(,c1 arg)))
  7668. (if bound
  7669. (fset 'read-string old)
  7670. (fmakunbound 'read-string)))))))
  7671. ((equal action ?S)
  7672. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7673. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7674. (let ((days (read-number
  7675. (format "Scatter tasks across how many %sdays: "
  7676. (if arg "week" "")) 7)))
  7677. (setq cmd
  7678. `(let ((distance (1+ (random ,days))))
  7679. (if arg
  7680. (let ((dist distance)
  7681. (day-of-week
  7682. (calendar-day-of-week
  7683. (calendar-gregorian-from-absolute (org-today)))))
  7684. (dotimes (i (1+ dist))
  7685. (while (member day-of-week org-agenda-weekend-days)
  7686. (incf distance)
  7687. (incf day-of-week)
  7688. (if (= day-of-week 7)
  7689. (setq day-of-week 0)))
  7690. (incf day-of-week)
  7691. (if (= day-of-week 7)
  7692. (setq day-of-week 0)))))
  7693. ;; silently fail when try to replan a sexp entry
  7694. (condition-case nil
  7695. (let* ((date (calendar-gregorian-from-absolute
  7696. (+ (org-today) distance)))
  7697. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7698. (nth 2 date))))
  7699. (org-agenda-schedule nil time))
  7700. (error nil)))))))
  7701. ((assoc action org-agenda-bulk-custom-functions)
  7702. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7703. redo-at-end t))
  7704. ((equal action ?f)
  7705. (setq cmd (list (intern
  7706. (org-icompleting-read "Function: "
  7707. obarray 'fboundp t nil nil)))))
  7708. (t (error "Invalid bulk action")))
  7709. ;; Sort the markers, to make sure that parents are handled before children
  7710. (setq entries (sort entries
  7711. (lambda (a b)
  7712. (cond
  7713. ((equal (marker-buffer a) (marker-buffer b))
  7714. (< (marker-position a) (marker-position b)))
  7715. (t
  7716. (string< (buffer-name (marker-buffer a))
  7717. (buffer-name (marker-buffer b))))))))
  7718. ;; Now loop over all markers and apply cmd
  7719. (while (setq e (pop entries))
  7720. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7721. (if (not pos)
  7722. (progn (message "Skipping removed entry at %s" e)
  7723. (setq cntskip (1+ cntskip)))
  7724. (goto-char pos)
  7725. (eval cmd)
  7726. (setq org-agenda-bulk-marked-entries
  7727. (delete e org-agenda-bulk-marked-entries))
  7728. (setq cnt (1+ cnt))))
  7729. (setq org-agenda-bulk-marked-entries nil)
  7730. (org-agenda-bulk-remove-all-marks)
  7731. (when redo-at-end (org-agenda-redo))
  7732. (message "Acted on %d entries%s"
  7733. cnt
  7734. (if (= cntskip 0)
  7735. ""
  7736. (format ", skipped %d (disappeared before their turn)"
  7737. cntskip)))))
  7738. ;;; Flagging notes
  7739. (defun org-agenda-show-the-flagging-note ()
  7740. "Display the flagging note in the other window.
  7741. When called a second time in direct sequence, offer to remove the FLAGGING
  7742. tag and (if present) the flagging note."
  7743. (interactive)
  7744. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7745. (win (selected-window))
  7746. note heading newhead)
  7747. (unless hdmarker
  7748. (error "No linked entry at point"))
  7749. (if (and (eq this-command last-command)
  7750. (y-or-n-p "Unflag and remove any flagging note? "))
  7751. (progn
  7752. (org-agenda-remove-flag hdmarker)
  7753. (let ((win (get-buffer-window "*Flagging Note*")))
  7754. (and win (delete-window win)))
  7755. (message "Entry unflaged"))
  7756. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7757. (unless note
  7758. (error "No flagging note"))
  7759. (org-kill-new note)
  7760. (org-switch-to-buffer-other-window "*Flagging Note*")
  7761. (erase-buffer)
  7762. (insert note)
  7763. (goto-char (point-min))
  7764. (while (re-search-forward "\\\\n" nil t)
  7765. (replace-match "\n" t t))
  7766. (goto-char (point-min))
  7767. (select-window win)
  7768. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7769. (defun org-agenda-remove-flag (marker)
  7770. "Remove the FLAGGED tag and any flagging note in the entry."
  7771. (let (newhead)
  7772. (org-with-point-at marker
  7773. (org-toggle-tag "FLAGGED" 'off)
  7774. (org-entry-delete nil "THEFLAGGINGNOTE")
  7775. (setq newhead (org-get-heading)))
  7776. (org-agenda-change-all-lines newhead marker)
  7777. (message "Entry unflaged")))
  7778. (defun org-agenda-get-any-marker (&optional pos)
  7779. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7780. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7781. ;;; Appointment reminders
  7782. (defvar appt-time-msg-list)
  7783. ;;;###autoload
  7784. (defun org-agenda-to-appt (&optional refresh filter)
  7785. "Activate appointments found in `org-agenda-files'.
  7786. With a \\[universal-argument] prefix, refresh the list of
  7787. appointments.
  7788. If FILTER is t, interactively prompt the user for a regular
  7789. expression, and filter out entries that don't match it.
  7790. If FILTER is a string, use this string as a regular expression
  7791. for filtering entries out.
  7792. FILTER can also be an alist with the car of each cell being
  7793. either 'headline or 'category. For example:
  7794. '((headline \"IMPORTANT\")
  7795. (category \"Work\"))
  7796. will only add headlines containing IMPORTANT or headlines
  7797. belonging to the \"Work\" category."
  7798. (interactive "P")
  7799. (if refresh (setq appt-time-msg-list nil))
  7800. (if (eq filter t)
  7801. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7802. (let* ((cnt 0) ; count added events
  7803. (org-agenda-new-buffers nil)
  7804. (org-deadline-warning-days 0)
  7805. ;; Do not use `org-today' here because appt only takes
  7806. ;; time and without date as argument, so it may pass wrong
  7807. ;; information otherwise
  7808. (today (org-date-to-gregorian
  7809. (time-to-days (current-time))))
  7810. (org-agenda-restrict nil)
  7811. (files (org-agenda-files 'unrestricted)) entries file)
  7812. ;; Get all entries which may contain an appt
  7813. (org-prepare-agenda-buffers files)
  7814. (while (setq file (pop files))
  7815. (setq entries
  7816. (append entries
  7817. (org-agenda-get-day-entries
  7818. file today :timestamp :scheduled :deadline))))
  7819. (setq entries (delq nil entries))
  7820. ;; Map thru entries and find if we should filter them out
  7821. (mapc
  7822. (lambda(x)
  7823. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7824. (cat (get-text-property 1 'org-category x))
  7825. (tod (get-text-property 1 'time-of-day x))
  7826. (ok (or (null filter)
  7827. (and (stringp filter) (string-match filter evt))
  7828. (and (listp filter)
  7829. (or (string-match
  7830. (cadr (assoc 'category filter)) cat)
  7831. (string-match
  7832. (cadr (assoc 'headline filter)) evt))))))
  7833. ;; FIXME: Shall we remove text-properties for the appt text?
  7834. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7835. (when (and ok tod)
  7836. (setq tod (concat "00" (number-to-string tod))
  7837. tod (when (string-match
  7838. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7839. (concat (match-string 1 tod) ":"
  7840. (match-string 2 tod))))
  7841. (appt-add tod evt)
  7842. (setq cnt (1+ cnt))))) entries)
  7843. (org-release-buffers org-agenda-new-buffers)
  7844. (if (eq cnt 0)
  7845. (message "No event to add")
  7846. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7847. (defun org-agenda-todayp (date)
  7848. "Does DATE mean today, when considering `org-extend-today-until'?"
  7849. (let ((today (org-today))
  7850. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7851. date)))
  7852. (eq date today)))
  7853. (defun org-agenda-todo-yesterday (&optional arg)
  7854. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  7855. (interactive "P")
  7856. (let* ((hour (third (decode-time
  7857. (org-current-time))))
  7858. (org-extend-today-until (1+ hour)))
  7859. (org-agenda-todo arg)))
  7860. (provide 'org-agenda)
  7861. ;;; org-agenda.el ends here