org-agenda.el 325 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a conveniant way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function org-datetree-find-date-create "org-datetree"
  62. (date &optional keep-restriction))
  63. (declare-function org-columns-quit "org-colview" ())
  64. (declare-function diary-date-display-form "diary-lib" (&optional type))
  65. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  66. (declare-function org-habit-insert-consistency-graphs
  67. "org-habit" (&optional line))
  68. (declare-function org-is-habit-p "org-habit" (&optional pom))
  69. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  70. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  71. (declare-function org-pop-to-buffer-same-window "org-compat"
  72. (&optional buffer-or-name norecord label))
  73. (defvar calendar-mode-map)
  74. (defvar org-clock-current-task) ; defined in org-clock.el
  75. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  76. (defvar org-habit-show-habits)
  77. (defvar org-habit-show-habits-only-for-today)
  78. ;; Defined somewhere in this file, but used before definition.
  79. (defvar org-agenda-buffer-name)
  80. (defvar org-agenda-overriding-header)
  81. (defvar org-agenda-title-append nil)
  82. (defvar entry)
  83. (defvar date)
  84. (defvar org-agenda-undo-list)
  85. (defvar org-agenda-pending-undo-list)
  86. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  87. (defcustom org-agenda-confirm-kill 1
  88. "When set, remote killing from the agenda buffer needs confirmation.
  89. When t, a confirmation is always needed. When a number N, confirmation is
  90. only needed when the text to be killed contains more than N non-white lines."
  91. :group 'org-agenda
  92. :type '(choice
  93. (const :tag "Never" nil)
  94. (const :tag "Always" t)
  95. (integer :tag "When more than N lines")))
  96. (defcustom org-agenda-compact-blocks nil
  97. "Non-nil means make the block agenda more compact.
  98. This is done globally by leaving out lines like the agenda span
  99. name and week number or the separator lines."
  100. :group 'org-agenda
  101. :type 'boolean)
  102. (defcustom org-agenda-block-separator ?=
  103. "The separator between blocks in the agenda.
  104. If this is a string, it will be used as the separator, with a newline added.
  105. If it is a character, it will be repeated to fill the window width.
  106. If nil the separator is disabled. In `org-agenda-custom-commands' this
  107. addresses the separator between the current and the previous block."
  108. :group 'org-agenda
  109. :type '(choice
  110. (const :tag "Disabled" nil)
  111. (character)
  112. (string)))
  113. (defgroup org-agenda-export nil
  114. "Options concerning exporting agenda views in Org-mode."
  115. :tag "Org Agenda Export"
  116. :group 'org-agenda)
  117. (defcustom org-agenda-with-colors t
  118. "Non-nil means use colors in agenda views."
  119. :group 'org-agenda-export
  120. :type 'boolean)
  121. (defcustom org-agenda-exporter-settings nil
  122. "Alist of variable/value pairs that should be active during agenda export.
  123. This is a good place to set options for ps-print and for htmlize.
  124. Note that the way this is implemented, the values will be evaluated
  125. before assigned to the variables. So make sure to quote values you do
  126. *not* want evaluated, for example
  127. (setq org-agenda-exporter-settings
  128. '((ps-print-color-p 'black-white)))"
  129. :group 'org-agenda-export
  130. :type '(repeat
  131. (list
  132. (variable)
  133. (sexp :tag "Value"))))
  134. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  135. "Hook run in temporary buffer before writing it to an export file.
  136. A useful function is `org-agenda-add-entry-text'."
  137. :group 'org-agenda-export
  138. :type 'hook
  139. :options '(org-agenda-add-entry-text))
  140. (defcustom org-agenda-add-entry-text-maxlines 0
  141. "Maximum number of entry text lines to be added to agenda.
  142. This is only relevant when `org-agenda-add-entry-text' is part of
  143. `org-agenda-before-write-hook', which it is by default.
  144. When this is 0, nothing will happen. When it is greater than 0, it
  145. specifies the maximum number of lines that will be added for each entry
  146. that is listed in the agenda view.
  147. Note that this variable is not used during display, only when exporting
  148. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  149. and `org-agenda-entry-text-maxlines'."
  150. :group 'org-agenda
  151. :type 'integer)
  152. (defcustom org-agenda-add-entry-text-descriptive-links t
  153. "Non-nil means export org-links as descriptive links in agenda added text.
  154. This variable applies to the text added to the agenda when
  155. `org-agenda-add-entry-text-maxlines' is larger than 0.
  156. When this variable nil, the URL will (also) be shown."
  157. :group 'org-agenda
  158. :type 'boolean)
  159. (defcustom org-agenda-export-html-style ""
  160. "The style specification for exported HTML Agenda files.
  161. If this variable contains a string, it will replace the default <style>
  162. section as produced by `htmlize'.
  163. Since there are different ways of setting style information, this variable
  164. needs to contain the full HTML structure to provide a style, including the
  165. surrounding HTML tags. The style specifications should include definitions
  166. the fonts used by the agenda, here is an example:
  167. <style type=\"text/css\">
  168. p { font-weight: normal; color: gray; }
  169. .org-agenda-structure {
  170. font-size: 110%;
  171. color: #003399;
  172. font-weight: 600;
  173. }
  174. .org-todo {
  175. color: #cc6666;
  176. font-weight: bold;
  177. }
  178. .org-agenda-done {
  179. color: #339933;
  180. }
  181. .org-done {
  182. color: #339933;
  183. }
  184. .title { text-align: center; }
  185. .todo, .deadline { color: red; }
  186. .done { color: green; }
  187. </style>
  188. or, if you want to keep the style in a file,
  189. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  190. As the value of this option simply gets inserted into the HTML <head> header,
  191. you can \"misuse\" it to also add other text to the header. However,
  192. <style>...</style> is required, if not present the variable will be ignored."
  193. :group 'org-agenda-export
  194. :group 'org-export-html
  195. :type 'string)
  196. (defcustom org-agenda-persistent-filter nil
  197. "When set, keep filters from one agenda view to the next."
  198. :group 'org-agenda
  199. :type 'boolean)
  200. (defgroup org-agenda-custom-commands nil
  201. "Options concerning agenda views in Org-mode."
  202. :tag "Org Agenda Custom Commands"
  203. :group 'org-agenda)
  204. (defconst org-sorting-choice
  205. '(choice
  206. (const time-up) (const time-down)
  207. (const category-keep) (const category-up) (const category-down)
  208. (const tag-down) (const tag-up)
  209. (const priority-up) (const priority-down)
  210. (const todo-state-up) (const todo-state-down)
  211. (const effort-up) (const effort-down)
  212. (const habit-up) (const habit-down)
  213. (const alpha-up) (const alpha-down)
  214. (const user-defined-up) (const user-defined-down))
  215. "Sorting choices.")
  216. (defconst org-agenda-custom-commands-local-options
  217. `(repeat :tag "Local settings for this command. Remember to quote values"
  218. (choice :tag "Setting"
  219. (list :tag "Heading for this block"
  220. (const org-agenda-overriding-header)
  221. (string :tag "Headline"))
  222. (list :tag "Files to be searched"
  223. (const org-agenda-files)
  224. (list
  225. (const :format "" quote)
  226. (repeat (file))))
  227. (list :tag "Sorting strategy"
  228. (const org-agenda-sorting-strategy)
  229. (list
  230. (const :format "" quote)
  231. (repeat
  232. ,org-sorting-choice)))
  233. (list :tag "Prefix format"
  234. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  235. (string))
  236. (list :tag "Number of days in agenda"
  237. (const org-agenda-span)
  238. (choice (const :tag "Day" 'day)
  239. (const :tag "Week" 'week)
  240. (const :tag "Month" 'month)
  241. (const :tag "Year" 'year)
  242. (integer :tag "Custom")))
  243. (list :tag "Fixed starting date"
  244. (const org-agenda-start-day)
  245. (string :value "2007-11-01"))
  246. (list :tag "Start on day of week"
  247. (const org-agenda-start-on-weekday)
  248. (choice :value 1
  249. (const :tag "Today" nil)
  250. (integer :tag "Weekday No.")))
  251. (list :tag "Include data from diary"
  252. (const org-agenda-include-diary)
  253. (boolean))
  254. (list :tag "Deadline Warning days"
  255. (const org-deadline-warning-days)
  256. (integer :value 1))
  257. (list :tag "Tags filter preset"
  258. (const org-agenda-filter-preset)
  259. (list
  260. (const :format "" quote)
  261. (repeat
  262. (string :tag "+tag or -tag"))))
  263. (list :tag "Set daily/weekly entry types"
  264. (const org-agenda-entry-types)
  265. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  266. (const :deadline)
  267. (const :scheduled)
  268. (const :timestamp)
  269. (const :sexp)))
  270. (list :tag "Standard skipping condition"
  271. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  272. (const org-agenda-skip-function)
  273. (list
  274. (const :format "" quote)
  275. (list
  276. (choice
  277. :tag "Skipping range"
  278. (const :tag "Skip entry" org-agenda-skip-entry-if)
  279. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  280. (repeat :inline t :tag "Conditions for skipping"
  281. (choice
  282. :tag "Condition type"
  283. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  284. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  285. (list :tag "TODO state is" :inline t
  286. (const 'todo)
  287. (choice
  288. (const :tag "any not-done state" 'todo)
  289. (const :tag "any done state" 'done)
  290. (const :tag "any state" 'any)
  291. (list :tag "Keyword list"
  292. (const :format "" quote)
  293. (repeat (string :tag "Keyword")))))
  294. (list :tag "TODO state is not" :inline t
  295. (const 'nottodo)
  296. (choice
  297. (const :tag "any not-done state" 'todo)
  298. (const :tag "any done state" 'done)
  299. (const :tag "any state" 'any)
  300. (list :tag "Keyword list"
  301. (const :format "" quote)
  302. (repeat (string :tag "Keyword")))))
  303. (const :tag "scheduled" 'scheduled)
  304. (const :tag "not scheduled" 'notscheduled)
  305. (const :tag "deadline" 'deadline)
  306. (const :tag "no deadline" 'notdeadline)
  307. (const :tag "timestamp" 'timestamp)
  308. (const :tag "no timestamp" 'nottimestamp))))))
  309. (list :tag "Non-standard skipping condition"
  310. :value (org-agenda-skip-function)
  311. (const org-agenda-skip-function)
  312. (sexp :tag "Function or form (quoted!)"))
  313. (list :tag "Any variable"
  314. (variable :tag "Variable")
  315. (sexp :tag "Value (sexp)"))))
  316. "Selection of examples for agenda command settings.
  317. This will be spliced into the custom type of
  318. `org-agenda-custom-commands'.")
  319. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  320. ((agenda "") (alltodo))))
  321. "Custom commands for the agenda.
  322. These commands will be offered on the splash screen displayed by the
  323. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  324. (key desc type match settings files)
  325. key The key (one or more characters as a string) to be associated
  326. with the command.
  327. desc A description of the command, when omitted or nil, a default
  328. description is built using MATCH.
  329. type The command type, any of the following symbols:
  330. agenda The daily/weekly agenda.
  331. todo Entries with a specific TODO keyword, in all agenda files.
  332. search Entries containing search words entry or headline.
  333. tags Tags/Property/TODO match in all agenda files.
  334. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  335. todo-tree Sparse tree of specific TODO keyword in *current* file.
  336. tags-tree Sparse tree with all tags matches in *current* file.
  337. occur-tree Occur sparse tree for *current* file.
  338. ... A user-defined function.
  339. match What to search for:
  340. - a single keyword for TODO keyword searches
  341. - a tags match expression for tags searches
  342. - a word search expression for text searches.
  343. - a regular expression for occur searches
  344. For all other commands, this should be the empty string.
  345. settings A list of option settings, similar to that in a let form, so like
  346. this: ((opt1 val1) (opt2 val2) ...). The values will be
  347. evaluated at the moment of execution, so quote them when needed.
  348. files A list of files file to write the produced agenda buffer to
  349. with the command `org-store-agenda-views'.
  350. If a file name ends in \".html\", an HTML version of the buffer
  351. is written out. If it ends in \".ps\", a postscript version is
  352. produced. Otherwise, only the plain text is written to the file.
  353. You can also define a set of commands, to create a composite agenda buffer.
  354. In this case, an entry looks like this:
  355. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  356. where
  357. desc A description string to be displayed in the dispatcher menu.
  358. cmd An agenda command, similar to the above. However, tree commands
  359. are no allowed, but instead you can get agenda and global todo list.
  360. So valid commands for a set are:
  361. (agenda \"\" settings)
  362. (alltodo \"\" settings)
  363. (stuck \"\" settings)
  364. (todo \"match\" settings files)
  365. (search \"match\" settings files)
  366. (tags \"match\" settings files)
  367. (tags-todo \"match\" settings files)
  368. Each command can carry a list of options, and another set of options can be
  369. given for the whole set of commands. Individual command options take
  370. precedence over the general options.
  371. When using several characters as key to a command, the first characters
  372. are prefix commands. For the dispatcher to display useful information, you
  373. should provide a description for the prefix, like
  374. (setq org-agenda-custom-commands
  375. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  376. (\"hl\" tags \"+HOME+Lisa\")
  377. (\"hp\" tags \"+HOME+Peter\")
  378. (\"hk\" tags \"+HOME+Kim\")))"
  379. :group 'org-agenda-custom-commands
  380. :type `(repeat
  381. (choice :value ("x" "Describe command here" tags "" nil)
  382. (list :tag "Single command"
  383. (string :tag "Access Key(s) ")
  384. (option (string :tag "Description"))
  385. (choice
  386. (const :tag "Agenda" agenda)
  387. (const :tag "TODO list" alltodo)
  388. (const :tag "Search words" search)
  389. (const :tag "Stuck projects" stuck)
  390. (const :tag "Tags/Property match (all agenda files)" tags)
  391. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  392. (const :tag "TODO keyword search (all agenda files)" todo)
  393. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  394. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  395. (const :tag "Occur tree (current buffer)" occur-tree)
  396. (sexp :tag "Other, user-defined function"))
  397. (string :tag "Match (only for some commands)")
  398. ,org-agenda-custom-commands-local-options
  399. (option (repeat :tag "Export" (file :tag "Export to"))))
  400. (list :tag "Command series, all agenda files"
  401. (string :tag "Access Key(s)")
  402. (string :tag "Description ")
  403. (repeat :tag "Component"
  404. (choice
  405. (list :tag "Agenda"
  406. (const :format "" agenda)
  407. (const :tag "" :format "" "")
  408. ,org-agenda-custom-commands-local-options)
  409. (list :tag "TODO list (all keywords)"
  410. (const :format "" alltodo)
  411. (const :tag "" :format "" "")
  412. ,org-agenda-custom-commands-local-options)
  413. (list :tag "Search words"
  414. (const :format "" search)
  415. (string :tag "Match")
  416. ,org-agenda-custom-commands-local-options)
  417. (list :tag "Stuck projects"
  418. (const :format "" stuck)
  419. (const :tag "" :format "" "")
  420. ,org-agenda-custom-commands-local-options)
  421. (list :tag "Tags search"
  422. (const :format "" tags)
  423. (string :tag "Match")
  424. ,org-agenda-custom-commands-local-options)
  425. (list :tag "Tags search, TODO entries only"
  426. (const :format "" tags-todo)
  427. (string :tag "Match")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO keyword search"
  430. (const :format "" todo)
  431. (string :tag "Match")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Other, user-defined function"
  434. (symbol :tag "function")
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)))
  437. (repeat :tag "Settings for entire command set"
  438. (list (variable :tag "Any variable")
  439. (sexp :tag "Value")))
  440. (option (repeat :tag "Export" (file :tag "Export to"))))
  441. (cons :tag "Prefix key documentation"
  442. (string :tag "Access Key(s)")
  443. (string :tag "Description ")))))
  444. (defcustom org-agenda-query-register ?o
  445. "The register holding the current query string.
  446. The purpose of this is that if you construct a query string interactively,
  447. you can then use it to define a custom command."
  448. :group 'org-agenda-custom-commands
  449. :type 'character)
  450. (defcustom org-stuck-projects
  451. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  452. "How to identify stuck projects.
  453. This is a list of four items:
  454. 1. A tags/todo/property matcher string that is used to identify a project.
  455. See the manual for a description of tag and property searches.
  456. The entire tree below a headline matched by this is considered one project.
  457. 2. A list of TODO keywords identifying non-stuck projects.
  458. If the project subtree contains any headline with one of these todo
  459. keywords, the project is considered to be not stuck. If you specify
  460. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  461. 3. A list of tags identifying non-stuck projects.
  462. If the project subtree contains any headline with one of these tags,
  463. the project is considered to be not stuck. If you specify \"*\" as
  464. a tag, any tag will mark the project unstuck. Note that this is about
  465. the explicit presence of a tag somewhere in the subtree, inherited
  466. tags to not count here. If inherited tags make a project not stuck,
  467. use \"-TAG\" in the tags part of the matcher under (1.) above.
  468. 4. An arbitrary regular expression matching non-stuck projects.
  469. If the project turns out to be not stuck, search continues also in the
  470. subtree to see if any of the subtasks have project status.
  471. See also the variable `org-tags-match-list-sublevels' which applies
  472. to projects matched by this search as well.
  473. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  474. or `C-c a #' to produce the list."
  475. :group 'org-agenda-custom-commands
  476. :type '(list
  477. (string :tag "Tags/TODO match to identify a project")
  478. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  479. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  480. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  481. (defcustom org-agenda-filter-effort-default-operator "<"
  482. "The default operator for effort estimate filtering.
  483. If you select an effort estimate limit without first pressing an operator,
  484. this one will be used."
  485. :group 'org-agenda-custom-commands
  486. :type '(choice (const :tag "less or equal" "<")
  487. (const :tag "greater or equal"">")
  488. (const :tag "equal" "=")))
  489. (defgroup org-agenda-skip nil
  490. "Options concerning skipping parts of agenda files."
  491. :tag "Org Agenda Skip"
  492. :group 'org-agenda)
  493. (defcustom org-agenda-skip-function-global nil
  494. "Function to be called at each match during agenda construction.
  495. If this function returns nil, the current match should not be skipped.
  496. If the function decided to skip an agenda match, is must return the
  497. buffer position from which the search should be continued.
  498. This may also be a Lisp form, which will be evaluated.
  499. This variable will be applied to every agenda match, including
  500. tags/property searches and TODO lists. So try to make the test function
  501. do its checking as efficiently as possible. To implement a skipping
  502. condition just for specific agenda commands, use the variable
  503. `org-agenda-skip-function' which can be set in the options section
  504. of custom agenda commands."
  505. :group 'org-agenda-skip
  506. :type 'sexp)
  507. (defgroup org-agenda-daily/weekly nil
  508. "Options concerning the daily/weekly agenda."
  509. :tag "Org Agenda Daily/Weekly"
  510. :group 'org-agenda)
  511. (defgroup org-agenda-todo-list nil
  512. "Options concerning the global todo list agenda view."
  513. :tag "Org Agenda Todo List"
  514. :group 'org-agenda)
  515. (defgroup org-agenda-match-view nil
  516. "Options concerning the general tags/property/todo match agenda view."
  517. :tag "Org Agenda Match View"
  518. :group 'org-agenda)
  519. (defgroup org-agenda-search-view nil
  520. "Options concerning the general tags/property/todo match agenda view."
  521. :tag "Org Agenda Match View"
  522. :group 'org-agenda)
  523. (defvar org-agenda-archives-mode nil
  524. "Non-nil means the agenda will include archived items.
  525. If this is the symbol `trees', trees in the selected agenda scope
  526. that are marked with the ARCHIVE tag will be included anyway. When this is
  527. t, also all archive files associated with the current selection of agenda
  528. files will be included.")
  529. (defcustom org-agenda-skip-comment-trees t
  530. "Non-nil means skip trees that start with the COMMENT keyword.
  531. When nil, these trees are also scanned by agenda commands."
  532. :group 'org-agenda-skip
  533. :type 'boolean)
  534. (defcustom org-agenda-todo-list-sublevels t
  535. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  536. When nil, the sublevels of a TODO entry are not checked, resulting in
  537. potentially much shorter TODO lists."
  538. :group 'org-agenda-skip
  539. :group 'org-agenda-todo-list
  540. :type 'boolean)
  541. (defcustom org-agenda-todo-ignore-with-date nil
  542. "Non-nil means don't show entries with a date in the global todo list.
  543. You can use this if you prefer to mark mere appointments with a TODO keyword,
  544. but don't want them to show up in the TODO list.
  545. When this is set, it also covers deadlines and scheduled items, the settings
  546. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  547. will be ignored.
  548. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  549. :group 'org-agenda-skip
  550. :group 'org-agenda-todo-list
  551. :type 'boolean)
  552. (defcustom org-agenda-todo-ignore-timestamp nil
  553. "Non-nil means don't show entries with a timestamp.
  554. This applies when creating the global todo list.
  555. Valid values are:
  556. past Don't show entries for today or in the past.
  557. future Don't show entries with a timestamp in the future.
  558. The idea behind this is that if it has a future
  559. timestamp, you don't want to think about it until the
  560. date.
  561. all Don't show any entries with a timestamp in the global todo list.
  562. The idea behind this is that by setting a timestamp, you
  563. have already \"taken care\" of this item.
  564. This variable can also have an integer as a value. If positive (N),
  565. todos with a timestamp N or more days in the future will be ignored. If
  566. negative (-N), todos with a timestamp N or more days in the past will be
  567. ignored. If 0, todos with a timestamp either today or in the future will
  568. be ignored. For example, a value of -1 will exclude todos with a
  569. timestamp in the past (yesterday or earlier), while a value of 7 will
  570. exclude todos with a timestamp a week or more in the future.
  571. See also `org-agenda-todo-ignore-with-date'.
  572. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  573. to make his option also apply to the tags-todo list."
  574. :group 'org-agenda-skip
  575. :group 'org-agenda-todo-list
  576. :type '(choice
  577. (const :tag "Ignore future timestamp todos" future)
  578. (const :tag "Ignore past or present timestamp todos" past)
  579. (const :tag "Ignore all timestamp todos" all)
  580. (const :tag "Show timestamp todos" nil)
  581. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  582. (defcustom org-agenda-todo-ignore-scheduled nil
  583. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  584. This applies when creating the global todo list.
  585. Valid values are:
  586. past Don't show entries scheduled today or in the past.
  587. future Don't show entries scheduled in the future.
  588. The idea behind this is that by scheduling it, you don't want to
  589. think about it until the scheduled date.
  590. all Don't show any scheduled entries in the global todo list.
  591. The idea behind this is that by scheduling it, you have already
  592. \"taken care\" of this item.
  593. t Same as `all', for backward compatibility.
  594. This variable can also have an integer as a value. See
  595. `org-agenda-todo-ignore-timestamp' for more details.
  596. See also `org-agenda-todo-ignore-with-date'.
  597. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  598. to make his option also apply to the tags-todo list."
  599. :group 'org-agenda-skip
  600. :group 'org-agenda-todo-list
  601. :type '(choice
  602. (const :tag "Ignore future-scheduled todos" future)
  603. (const :tag "Ignore past- or present-scheduled todos" past)
  604. (const :tag "Ignore all scheduled todos" all)
  605. (const :tag "Ignore all scheduled todos (compatibility)" t)
  606. (const :tag "Show scheduled todos" nil)
  607. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  608. (defcustom org-agenda-todo-ignore-deadlines nil
  609. "Non-nil means ignore some deadlined TODO items when making TODO list.
  610. There are different motivations for using different values, please think
  611. carefully when configuring this variable.
  612. This applies when creating the global todo list.
  613. Valid values are:
  614. near Don't show near deadline entries. A deadline is near when it is
  615. closer than `org-deadline-warning-days' days. The idea behind this
  616. is that such items will appear in the agenda anyway.
  617. far Don't show TODO entries where a deadline has been defined, but
  618. the deadline is not near. This is useful if you don't want to
  619. use the todo list to figure out what to do now.
  620. past Don't show entries with a deadline timestamp for today or in the past.
  621. future Don't show entries with a deadline timestamp in the future, not even
  622. when they become `near' ones. Use it with caution.
  623. all Ignore all TODO entries that do have a deadline.
  624. t Same as `near', for backward compatibility.
  625. This variable can also have an integer as a value. See
  626. `org-agenda-todo-ignore-timestamp' for more details.
  627. See also `org-agenda-todo-ignore-with-date'.
  628. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  629. to make his option also apply to the tags-todo list."
  630. :group 'org-agenda-skip
  631. :group 'org-agenda-todo-list
  632. :type '(choice
  633. (const :tag "Ignore near deadlines" near)
  634. (const :tag "Ignore near deadlines (compatibility)" t)
  635. (const :tag "Ignore far deadlines" far)
  636. (const :tag "Ignore all TODOs with a deadlines" all)
  637. (const :tag "Show all TODOs, even if they have a deadline" nil)
  638. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  639. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  640. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  641. The variables
  642. `org-agenda-todo-ignore-with-date',
  643. `org-agenda-todo-ignore-timestamp',
  644. `org-agenda-todo-ignore-scheduled',
  645. `org-agenda-todo-ignore-deadlines'
  646. make the global TODO list skip entries that have time stamps of certain
  647. kinds. If this option is set, the same options will also apply for the
  648. tags-todo search, which is the general tags/property matcher
  649. restricted to unfinished TODO entries only."
  650. :group 'org-agenda-skip
  651. :group 'org-agenda-todo-list
  652. :group 'org-agenda-match-view
  653. :type 'boolean)
  654. (defcustom org-agenda-skip-scheduled-if-done nil
  655. "Non-nil means don't show scheduled items in agenda when they are done.
  656. This is relevant for the daily/weekly agenda, not for the TODO list. And
  657. it applies only to the actual date of the scheduling. Warnings about
  658. an item with a past scheduling dates are always turned off when the item
  659. is DONE."
  660. :group 'org-agenda-skip
  661. :group 'org-agenda-daily/weekly
  662. :type 'boolean)
  663. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  664. "Non-nil means skip scheduling line if same entry shows because of deadline.
  665. In the agenda of today, an entry can show up multiple times because
  666. it is both scheduled and has a nearby deadline, and maybe a plain time
  667. stamp as well.
  668. When this variable is t, then only the deadline is shown and the fact that
  669. the entry is scheduled today or was scheduled previously is not shown.
  670. When this variable is nil, the entry will be shown several times. When
  671. the variable is the symbol `not-today', then skip scheduled previously,
  672. but not scheduled today."
  673. :group 'org-agenda-skip
  674. :group 'org-agenda-daily/weekly
  675. :type '(choice
  676. (const :tag "Never" nil)
  677. (const :tag "Always" t)
  678. (const :tag "Not when scheduled today" not-today)))
  679. (defcustom org-agenda-skip-deadline-if-done nil
  680. "Non-nil means don't show deadlines when the corresponding item is done.
  681. When nil, the deadline is still shown and should give you a happy feeling.
  682. This is relevant for the daily/weekly agenda. And it applied only to the
  683. actually date of the deadline. Warnings about approaching and past-due
  684. deadlines are always turned off when the item is DONE."
  685. :group 'org-agenda-skip
  686. :group 'org-agenda-daily/weekly
  687. :type 'boolean)
  688. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  689. "Non-nil means skip deadline prewarning when entry is also scheduled.
  690. This will apply on all days where a prewarning for the deadline would
  691. be shown, but not at the day when the entry is actually due. On that day,
  692. the deadline will be shown anyway.
  693. This variable may be set to nil, t, or a number which will then give
  694. the number of days before the actual deadline when the prewarnings
  695. should resume.
  696. This can be used in a workflow where the first showing of the deadline will
  697. trigger you to schedule it, and then you don't want to be reminded of it
  698. because you will take care of it on the day when scheduled."
  699. :group 'org-agenda-skip
  700. :group 'org-agenda-daily/weekly
  701. :type '(choice
  702. (const :tag "Alwas show prewarning" nil)
  703. (const :tag "Remove prewarning if entry is scheduled" t)
  704. (integer :tag "Restart prewarning N days before deadline")))
  705. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  706. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  707. When non-nil, after the search for timestamps has matched once in an
  708. entry, the rest of the entry will not be searched."
  709. :group 'org-agenda-skip
  710. :type 'boolean)
  711. (defcustom org-agenda-skip-timestamp-if-done nil
  712. "Non-nil means don't select item by timestamp or -range if it is DONE."
  713. :group 'org-agenda-skip
  714. :group 'org-agenda-daily/weekly
  715. :type 'boolean)
  716. (defcustom org-agenda-dim-blocked-tasks t
  717. "Non-nil means dim blocked tasks in the agenda display.
  718. This causes some overhead during agenda construction, but if you
  719. have turned on `org-enforce-todo-dependencies',
  720. `org-enforce-todo-checkbox-dependencies', or any other blocking
  721. mechanism, this will create useful feedback in the agenda.
  722. Instead of t, this variable can also have the value `invisible'.
  723. Then blocked tasks will be invisible and only become visible when
  724. they become unblocked. An exemption to this behavior is when a task is
  725. blocked because of unchecked checkboxes below it. Since checkboxes do
  726. not show up in the agenda views, making this task invisible you remove any
  727. trace from agenda views that there is something to do. Therefore, a task
  728. that is blocked because of checkboxes will never be made invisible, it
  729. will only be dimmed."
  730. :group 'org-agenda-daily/weekly
  731. :group 'org-agenda-todo-list
  732. :type '(choice
  733. (const :tag "Do not dim" nil)
  734. (const :tag "Dim to a grey face" t)
  735. (const :tag "Make invisible" invisible)))
  736. (defcustom org-timeline-show-empty-dates 3
  737. "Non-nil means `org-timeline' also shows dates without an entry.
  738. When nil, only the days which actually have entries are shown.
  739. When t, all days between the first and the last date are shown.
  740. When an integer, show also empty dates, but if there is a gap of more than
  741. N days, just insert a special line indicating the size of the gap."
  742. :group 'org-agenda-skip
  743. :type '(choice
  744. (const :tag "None" nil)
  745. (const :tag "All" t)
  746. (integer :tag "at most")))
  747. (defgroup org-agenda-startup nil
  748. "Options concerning initial settings in the Agenda in Org Mode."
  749. :tag "Org Agenda Startup"
  750. :group 'org-agenda)
  751. (defcustom org-agenda-menu-show-matcher t
  752. "Non-nil means show the match string in the agenda dispatcher menu.
  753. When nil, the matcher string is not shown, but is put into the help-echo
  754. property so than moving the mouse over the command shows it.
  755. Setting it to nil is good if matcher strings are very long and/or if
  756. you want to use two-column display (see `org-agenda-menu-two-column')."
  757. :group 'org-agenda
  758. :type 'boolean)
  759. (defcustom org-agenda-menu-two-column nil
  760. "Non-nil means, use two columns to show custom commands in the dispatcher.
  761. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  762. to nil."
  763. :group 'org-agenda
  764. :type 'boolean)
  765. (defcustom org-finalize-agenda-hook nil
  766. "Hook run just before displaying an agenda buffer."
  767. :group 'org-agenda-startup
  768. :type 'hook)
  769. (defcustom org-agenda-mouse-1-follows-link nil
  770. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  771. A longer mouse click will still set point. Does not work on XEmacs.
  772. Needs to be set before org.el is loaded."
  773. :group 'org-agenda-startup
  774. :type 'boolean)
  775. (defcustom org-agenda-start-with-follow-mode nil
  776. "The initial value of follow mode in a newly created agenda window."
  777. :group 'org-agenda-startup
  778. :type 'boolean)
  779. (defcustom org-agenda-follow-indirect nil
  780. "Non-nil means `org-agenda-follow-mode' displays only the
  781. current item's tree, in an indirect buffer."
  782. :group 'org-agenda
  783. :type 'boolean)
  784. (defcustom org-agenda-show-outline-path t
  785. "Non-nil means show outline path in echo area after line motion."
  786. :group 'org-agenda-startup
  787. :type 'boolean)
  788. (defcustom org-agenda-start-with-entry-text-mode nil
  789. "The initial value of entry-text-mode in a newly created agenda window."
  790. :group 'org-agenda-startup
  791. :type 'boolean)
  792. (defcustom org-agenda-entry-text-maxlines 5
  793. "Number of text lines to be added when `E' is pressed in the agenda.
  794. Note that this variable only used during agenda display. Add add entry text
  795. when exporting the agenda, configure the variable
  796. `org-agenda-add-entry-ext-maxlines'."
  797. :group 'org-agenda
  798. :type 'integer)
  799. (defcustom org-agenda-entry-text-exclude-regexps nil
  800. "List of regular expressions to clean up entry text.
  801. The complete matches of all regular expressions in this list will be
  802. removed from entry text before it is shown in the agenda."
  803. :group 'org-agenda
  804. :type '(repeat (regexp)))
  805. (defvar org-agenda-entry-text-cleanup-hook nil
  806. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  807. This cleanup is done in a temporary buffer, so the function may inspect and
  808. change the entire buffer.
  809. Some default stuff like drawers and scheduling/deadline dates will already
  810. have been removed when this is called, as will any matches for regular
  811. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  812. (defvar org-agenda-include-inactive-timestamps nil
  813. "Non-nil means include inactive time stamps in agenda and timeline.")
  814. (defgroup org-agenda-windows nil
  815. "Options concerning the windows used by the Agenda in Org Mode."
  816. :tag "Org Agenda Windows"
  817. :group 'org-agenda)
  818. (defcustom org-agenda-window-setup 'reorganize-frame
  819. "How the agenda buffer should be displayed.
  820. Possible values for this option are:
  821. current-window Show agenda in the current window, keeping all other windows.
  822. other-window Use `switch-to-buffer-other-window' to display agenda.
  823. reorganize-frame Show only two windows on the current frame, the current
  824. window and the agenda.
  825. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  826. Also, when exiting the agenda, kill that frame.
  827. See also the variable `org-agenda-restore-windows-after-quit'."
  828. :group 'org-agenda-windows
  829. :type '(choice
  830. (const current-window)
  831. (const other-frame)
  832. (const other-window)
  833. (const reorganize-frame)))
  834. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  835. "The min and max height of the agenda window as a fraction of frame height.
  836. The value of the variable is a cons cell with two numbers between 0 and 1.
  837. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  838. :group 'org-agenda-windows
  839. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  840. (defcustom org-agenda-restore-windows-after-quit nil
  841. "Non-nil means restore window configuration upon exiting agenda.
  842. Before the window configuration is changed for displaying the agenda,
  843. the current status is recorded. When the agenda is exited with
  844. `q' or `x' and this option is set, the old state is restored. If
  845. `org-agenda-window-setup' is `other-frame', the value of this
  846. option will be ignored."
  847. :group 'org-agenda-windows
  848. :type 'boolean)
  849. (defcustom org-agenda-ndays nil
  850. "Number of days to include in overview display.
  851. Should be 1 or 7.
  852. Obsolete, see `org-agenda-span'."
  853. :group 'org-agenda-daily/weekly
  854. :type 'integer)
  855. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  856. (defcustom org-agenda-span 'week
  857. "Number of days to include in overview display.
  858. Can be day, week, month, year, or any number of days.
  859. Custom commands can set this variable in the options section."
  860. :group 'org-agenda-daily/weekly
  861. :type '(choice (const :tag "Day" day)
  862. (const :tag "Week" week)
  863. (const :tag "Month" month)
  864. (const :tag "Year" year)
  865. (integer :tag "Custom")))
  866. (defcustom org-agenda-start-on-weekday 1
  867. "Non-nil means start the overview always on the specified weekday.
  868. 0 denotes Sunday, 1 denotes Monday etc.
  869. When nil, always start on the current day.
  870. Custom commands can set this variable in the options section."
  871. :group 'org-agenda-daily/weekly
  872. :type '(choice (const :tag "Today" nil)
  873. (integer :tag "Weekday No.")))
  874. (defcustom org-agenda-show-all-dates t
  875. "Non-nil means `org-agenda' shows every day in the selected range.
  876. When nil, only the days which actually have entries are shown."
  877. :group 'org-agenda-daily/weekly
  878. :type 'boolean)
  879. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  880. "Format string for displaying dates in the agenda.
  881. Used by the daily/weekly agenda and by the timeline. This should be
  882. a format string understood by `format-time-string', or a function returning
  883. the formatted date as a string. The function must take a single argument,
  884. a calendar-style date list like (month day year)."
  885. :group 'org-agenda-daily/weekly
  886. :type '(choice
  887. (string :tag "Format string")
  888. (function :tag "Function")))
  889. (defun org-agenda-format-date-aligned (date)
  890. "Format a date string for display in the daily/weekly agenda, or timeline.
  891. This function makes sure that dates are aligned for easy reading."
  892. (require 'cal-iso)
  893. (let* ((dayname (calendar-day-name date))
  894. (day (cadr date))
  895. (day-of-week (calendar-day-of-week date))
  896. (month (car date))
  897. (monthname (calendar-month-name month))
  898. (year (nth 2 date))
  899. (iso-week (org-days-to-iso-week
  900. (calendar-absolute-from-gregorian date)))
  901. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  902. (1- year))
  903. ((and (= month 12) (<= iso-week 1))
  904. (1+ year))
  905. (t year)))
  906. (weekstring (if (= day-of-week 1)
  907. (format " W%02d" iso-week)
  908. "")))
  909. (format "%-10s %2d %s %4d%s"
  910. dayname day monthname year weekstring)))
  911. (defcustom org-agenda-time-leading-zero nil
  912. "Non-nil means use leading zero for military times in agenda.
  913. For example, 9:30am would become 09:30 rather than 9:30."
  914. :group 'org-agenda-daily/weekly
  915. :type 'boolean)
  916. (defcustom org-agenda-timegrid-use-ampm nil
  917. "When set, show AM/PM style timestamps on the timegrid."
  918. :group 'org-agenda
  919. :type 'boolean)
  920. (defun org-agenda-time-of-day-to-ampm (time)
  921. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  922. (let* ((hour-number (string-to-number (substring time 0 -3)))
  923. (minute (substring time -2))
  924. (ampm "am"))
  925. (cond
  926. ((equal hour-number 12)
  927. (setq ampm "pm"))
  928. ((> hour-number 12)
  929. (setq ampm "pm")
  930. (setq hour-number (- hour-number 12))))
  931. (concat
  932. (if org-agenda-time-leading-zero
  933. (format "%02d" hour-number)
  934. (format "%02s" (number-to-string hour-number)))
  935. ":" minute ampm)))
  936. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  937. "Conditionally convert TIME to AM/PM format
  938. based on `org-agenda-timegrid-use-ampm'"
  939. (if org-agenda-timegrid-use-ampm
  940. (org-agenda-time-of-day-to-ampm time)
  941. time))
  942. (defcustom org-agenda-weekend-days '(6 0)
  943. "Which days are weekend?
  944. These days get the special face `org-agenda-date-weekend' in the agenda
  945. and timeline buffers."
  946. :group 'org-agenda-daily/weekly
  947. :type '(set :greedy t
  948. (const :tag "Monday" 1)
  949. (const :tag "Tuesday" 2)
  950. (const :tag "Wednesday" 3)
  951. (const :tag "Thursday" 4)
  952. (const :tag "Friday" 5)
  953. (const :tag "Saturday" 6)
  954. (const :tag "Sunday" 0)))
  955. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  956. "Non-nil means jumpt to today when moving a past date forward in time.
  957. When using S-right in the agenda to move a a date forward, and the date
  958. stamp currently points to the past, the first key press will move it
  959. to today. WHen nil, just move one day forward even if the date stays
  960. in the past."
  961. :group 'org-agenda-daily/weekly
  962. :type 'boolean)
  963. (defcustom org-agenda-include-diary nil
  964. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  965. Custom commands can set this variable in the options section."
  966. :group 'org-agenda-daily/weekly
  967. :type 'boolean)
  968. (defcustom org-agenda-include-deadlines t
  969. "If non-nil, include entries within their deadline warning period.
  970. Custom commands can set this variable in the options section."
  971. :group 'org-agenda-daily/weekly
  972. :type 'boolean)
  973. (defcustom org-agenda-repeating-timestamp-show-all t
  974. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  975. When set to a list of strings, only show occurrences of repeating
  976. stamps for these TODO keywords. When nil, only one occurrence is
  977. shown, either today or the nearest into the future."
  978. :group 'org-agenda-daily/weekly
  979. :type '(choice
  980. (const :tag "Show repeating stamps" t)
  981. (repeat :tag "Show repeating stamps for these TODO keywords"
  982. (string :tag "TODO Keyword"))
  983. (const :tag "Don't show repeating stamps" nil)))
  984. (defcustom org-scheduled-past-days 10000
  985. "No. of days to continue listing scheduled items that are not marked DONE.
  986. When an item is scheduled on a date, it shows up in the agenda on this
  987. day and will be listed until it is marked done for the number of days
  988. given here."
  989. :group 'org-agenda-daily/weekly
  990. :type 'integer)
  991. (defcustom org-agenda-log-mode-items '(closed clock)
  992. "List of items that should be shown in agenda log mode.
  993. This list may contain the following symbols:
  994. closed Show entries that have been closed on that day.
  995. clock Show entries that have received clocked time on that day.
  996. state Show all logged state changes.
  997. Note that instead of changing this variable, you can also press `C-u l' in
  998. the agenda to display all available LOG items temporarily."
  999. :group 'org-agenda-daily/weekly
  1000. :type '(set :greedy t (const closed) (const clock) (const state)))
  1001. (defcustom org-agenda-clock-consistency-checks
  1002. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1003. :gap-ok-around ("4:00")
  1004. :default-face ((:background "DarkRed") (:foreground "white"))
  1005. :overlap-face nil :gap-face nil :no-end-time-face nil
  1006. :long-face nil :short-face nil)
  1007. "This is a property list, with the following keys:
  1008. :max-duration Mark clocking chunks that are longer than this time.
  1009. This is a time string like \"HH:MM\", or the number
  1010. of minutes as an integer.
  1011. :min-duration Mark clocking chunks that are shorter that this.
  1012. This is a time string like \"HH:MM\", or the number
  1013. of minutes as an integer.
  1014. :max-gap Mark gaps between clocking chunks that are longer than
  1015. this duration. A number of minutes, or a string
  1016. like \"HH:MM\".
  1017. :gap-ok-around List of times during the day which are usually not working
  1018. times. When a gap is detected, but the gap contains any
  1019. of these times, the gap is *not* reported. For example,
  1020. if this is (\"4:00\" \"13:00\") then gaps that contain
  1021. 4:00 in the morning (i.e. the night) and 13:00
  1022. (i.e. a typical lunch time) do not cause a warning.
  1023. You should have at least one time during the night in this
  1024. list, or otherwise the first task each morning will trigger
  1025. a warning because it follows a long gap.
  1026. Furthermore, the following properties can be used to define faces for
  1027. issue display.
  1028. :default-face the default face, if the specific face is undefined
  1029. :overlap-face face for overlapping clocks
  1030. :gap-face face for gaps between clocks
  1031. :no-end-time-face face for incomplete clocks
  1032. :long-face face for clock intervals that are too long
  1033. :short-face face for clock intervals that are too short"
  1034. :group 'org-agenda-daily/weekly
  1035. :group 'org-clock
  1036. :type 'plist)
  1037. (defcustom org-agenda-log-mode-add-notes t
  1038. "Non-nil means add first line of notes to log entries in agenda views.
  1039. If a log item like a state change or a clock entry is associated with
  1040. notes, the first line of these notes will be added to the entry in the
  1041. agenda display."
  1042. :group 'org-agenda-daily/weekly
  1043. :type 'boolean)
  1044. (defcustom org-agenda-start-with-log-mode nil
  1045. "The initial value of log-mode in a newly created agenda window."
  1046. :group 'org-agenda-startup
  1047. :group 'org-agenda-daily/weekly
  1048. :type 'boolean)
  1049. (defcustom org-agenda-start-with-clockreport-mode nil
  1050. "The initial value of clockreport-mode in a newly created agenda window."
  1051. :group 'org-agenda-startup
  1052. :group 'org-agenda-daily/weekly
  1053. :type 'boolean)
  1054. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1055. "Property list with parameters for the clocktable in clockreport mode.
  1056. This is the display mode that shows a clock table in the daily/weekly
  1057. agenda, the properties for this dynamic block can be set here.
  1058. The usual clocktable parameters are allowed here, but you cannot set
  1059. the properties :name, :tstart, :tend, :block, and :scope - these will
  1060. be overwritten to make sure the content accurately reflects the
  1061. current display in the agenda."
  1062. :group 'org-agenda-daily/weekly
  1063. :type 'plist)
  1064. (defcustom org-agenda-search-view-always-boolean nil
  1065. "Non-nil means the search string is interpreted as individual parts.
  1066. The search string for search view can either be interpreted as a phrase,
  1067. or as a list of snippets that define a boolean search for a number of
  1068. strings.
  1069. When this is non-nil, the string will be split on whitespace, and each
  1070. snippet will be searched individually, and all must match in order to
  1071. select an entry. A snippet is then a single string of non-white
  1072. characters, or a string in double quotes, or a regexp in {} braces.
  1073. If a snippet is preceded by \"-\", the snippet must *not* match.
  1074. \"+\" is syntactic sugar for positive selection. Each snippet may
  1075. be found as a full word or a partial word, but see the variable
  1076. `org-agenda-search-view-force-full-words'.
  1077. When this is nil, search will look for the entire search phrase as one,
  1078. with each space character matching any amount of whitespace, including
  1079. line breaks.
  1080. Even when this is nil, you can still switch to Boolean search dynamically
  1081. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1082. is a regexp marked with braces like \"{abc}\", this will also switch to
  1083. boolean search."
  1084. :group 'org-agenda-search-view
  1085. :type 'boolean)
  1086. (if (fboundp 'defvaralias)
  1087. (defvaralias 'org-agenda-search-view-search-words-only
  1088. 'org-agenda-search-view-always-boolean))
  1089. (defcustom org-agenda-search-view-force-full-words nil
  1090. "Non-nil means, search words must be matches as complete words.
  1091. When nil, they may also match part of a word."
  1092. :group 'org-agenda-search-view
  1093. :type 'boolean)
  1094. (defgroup org-agenda-time-grid nil
  1095. "Options concerning the time grid in the Org-mode Agenda."
  1096. :tag "Org Agenda Time Grid"
  1097. :group 'org-agenda)
  1098. (defcustom org-agenda-search-headline-for-time t
  1099. "Non-nil means search headline for a time-of-day.
  1100. If the headline contains a time-of-day in one format or another, it will
  1101. be used to sort the entry into the time sequence of items for a day.
  1102. Some people have time stamps in the headline that refer to the creation
  1103. time or so, and then this produces an unwanted side effect. If this is
  1104. the case for your, use this variable to turn off searching the headline
  1105. for a time."
  1106. :group 'org-agenda-time-grid
  1107. :type 'boolean)
  1108. (defcustom org-agenda-use-time-grid t
  1109. "Non-nil means show a time grid in the agenda schedule.
  1110. A time grid is a set of lines for specific times (like every two hours between
  1111. 8:00 and 20:00). The items scheduled for a day at specific times are
  1112. sorted in between these lines.
  1113. For details about when the grid will be shown, and what it will look like, see
  1114. the variable `org-agenda-time-grid'."
  1115. :group 'org-agenda-time-grid
  1116. :type 'boolean)
  1117. (defcustom org-agenda-time-grid
  1118. '((daily today require-timed)
  1119. "----------------"
  1120. (800 1000 1200 1400 1600 1800 2000))
  1121. "The settings for time grid for agenda display.
  1122. This is a list of three items. The first item is again a list. It contains
  1123. symbols specifying conditions when the grid should be displayed:
  1124. daily if the agenda shows a single day
  1125. weekly if the agenda shows an entire week
  1126. today show grid on current date, independent of daily/weekly display
  1127. require-timed show grid only if at least one item has a time specification
  1128. The second item is a string which will be placed behind the grid time.
  1129. The third item is a list of integers, indicating the times that should have
  1130. a grid line."
  1131. :group 'org-agenda-time-grid
  1132. :type
  1133. '(list
  1134. (set :greedy t :tag "Grid Display Options"
  1135. (const :tag "Show grid in single day agenda display" daily)
  1136. (const :tag "Show grid in weekly agenda display" weekly)
  1137. (const :tag "Always show grid for today" today)
  1138. (const :tag "Show grid only if any timed entries are present"
  1139. require-timed)
  1140. (const :tag "Skip grid times already present in an entry"
  1141. remove-match))
  1142. (string :tag "Grid String")
  1143. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1144. (defcustom org-agenda-show-current-time-in-grid t
  1145. "Non-nil means show the current time in the time grid."
  1146. :group 'org-agenda-time-grid
  1147. :type 'boolean)
  1148. (defcustom org-agenda-current-time-string
  1149. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1150. "The string for the current time marker in the agenda."
  1151. :group 'org-agenda-time-grid
  1152. :type 'string)
  1153. (defgroup org-agenda-sorting nil
  1154. "Options concerning sorting in the Org-mode Agenda."
  1155. :tag "Org Agenda Sorting"
  1156. :group 'org-agenda)
  1157. (defcustom org-agenda-sorting-strategy
  1158. '((agenda habit-down time-up priority-down category-keep)
  1159. (todo priority-down category-keep)
  1160. (tags priority-down category-keep)
  1161. (search category-keep))
  1162. "Sorting structure for the agenda items of a single day.
  1163. This is a list of symbols which will be used in sequence to determine
  1164. if an entry should be listed before another entry. The following
  1165. symbols are recognized:
  1166. time-up Put entries with time-of-day indications first, early first
  1167. time-down Put entries with time-of-day indications first, late first
  1168. category-keep Keep the default order of categories, corresponding to the
  1169. sequence in `org-agenda-files'.
  1170. category-up Sort alphabetically by category, A-Z.
  1171. category-down Sort alphabetically by category, Z-A.
  1172. tag-up Sort alphabetically by last tag, A-Z.
  1173. tag-down Sort alphabetically by last tag, Z-A.
  1174. priority-up Sort numerically by priority, high priority last.
  1175. priority-down Sort numerically by priority, high priority first.
  1176. todo-state-up Sort by todo state, tasks that are done last.
  1177. todo-state-down Sort by todo state, tasks that are done first.
  1178. effort-up Sort numerically by estimated effort, high effort last.
  1179. effort-down Sort numerically by estimated effort, high effort first.
  1180. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1181. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1182. habit-up Put entries that are habits first
  1183. habit-down Put entries that are habits last
  1184. alpha-up Sort headlines alphabetically
  1185. alpha-down Sort headlines alphabetically, reversed
  1186. The different possibilities will be tried in sequence, and testing stops
  1187. if one comparison returns a \"not-equal\". For example, the default
  1188. '(time-up category-keep priority-down)
  1189. means: Pull out all entries having a specified time of day and sort them,
  1190. in order to make a time schedule for the current day the first thing in the
  1191. agenda listing for the day. Of the entries without a time indication, keep
  1192. the grouped in categories, don't sort the categories, but keep them in
  1193. the sequence given in `org-agenda-files'. Within each category sort by
  1194. priority.
  1195. Leaving out `category-keep' would mean that items will be sorted across
  1196. categories by priority.
  1197. Instead of a single list, this can also be a set of list for specific
  1198. contents, with a context symbol in the car of the list, any of
  1199. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1200. Custom commands can bind this variable in the options section."
  1201. :group 'org-agenda-sorting
  1202. :type `(choice
  1203. (repeat :tag "General" ,org-sorting-choice)
  1204. (list :tag "Individually"
  1205. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1206. (repeat ,org-sorting-choice))
  1207. (cons (const :tag "Strategy for TODO lists" todo)
  1208. (repeat ,org-sorting-choice))
  1209. (cons (const :tag "Strategy for Tags matches" tags)
  1210. (repeat ,org-sorting-choice))
  1211. (cons (const :tag "Strategy for search matches" search)
  1212. (repeat ,org-sorting-choice)))))
  1213. (defcustom org-agenda-cmp-user-defined nil
  1214. "A function to define the comparison `user-defined'.
  1215. This function must receive two arguments, agenda entry a and b.
  1216. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1217. the user comparison, return nil.
  1218. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1219. part of an agenda sorting strategy."
  1220. :group 'org-agenda-sorting
  1221. :type 'symbol)
  1222. (defcustom org-sort-agenda-notime-is-late t
  1223. "Non-nil means items without time are considered late.
  1224. This is only relevant for sorting. When t, items which have no explicit
  1225. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1226. do have a time. When nil, the default time is before 0:00. You can use this
  1227. option to decide if the schedule for today should come before or after timeless
  1228. agenda entries."
  1229. :group 'org-agenda-sorting
  1230. :type 'boolean)
  1231. (defcustom org-sort-agenda-noeffort-is-high t
  1232. "Non-nil means items without effort estimate are sorted as high effort.
  1233. This also applies when filtering an agenda view with respect to the
  1234. < or > effort operator. Then, tasks with no effort defined will be treated
  1235. as tasks with high effort.
  1236. When nil, such items are sorted as 0 minutes effort."
  1237. :group 'org-agenda-sorting
  1238. :type 'boolean)
  1239. (defgroup org-agenda-line-format nil
  1240. "Options concerning the entry prefix in the Org-mode agenda display."
  1241. :tag "Org Agenda Line Format"
  1242. :group 'org-agenda)
  1243. (defcustom org-agenda-prefix-format
  1244. '((agenda . " %i %-12:c%?-12t% s")
  1245. (timeline . " % s")
  1246. (todo . " %i %-12:c")
  1247. (tags . " %i %-12:c")
  1248. (search . " %i %-12:c"))
  1249. "Format specifications for the prefix of items in the agenda views.
  1250. An alist with five entries, each for the different agenda types. The
  1251. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1252. The values are format strings.
  1253. This format works similar to a printf format, with the following meaning:
  1254. %c the category of the item, \"Diary\" for entries from the diary,
  1255. or as given by the CATEGORY keyword or derived from the file name
  1256. %e the effort required by the item
  1257. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1258. %T the last tag of the item (ignore inherited tags, which come first)
  1259. %t the HH:MM time-of-day specification if one applies to the entry
  1260. %s Scheduling/Deadline information, a short string
  1261. %(expression) Eval EXPRESSION and replace the control string
  1262. by the result
  1263. All specifiers work basically like the standard `%s' of printf, but may
  1264. contain two additional characters: a question mark just after the `%'
  1265. and a whitespace/punctuation character just before the final letter.
  1266. If the first character after `%' is a question mark, the entire field
  1267. will only be included if the corresponding value applies to the current
  1268. entry. This is useful for fields which should have fixed width when
  1269. present, but zero width when absent. For example, \"%?-12t\" will
  1270. result in a 12 character time field if a time of the day is specified,
  1271. but will completely disappear in entries which do not contain a time.
  1272. If there is punctuation or whitespace character just before the final
  1273. format letter, this character will be appended to the field value if
  1274. the value is not empty. For example, the format \"%-12:c\" leads to
  1275. \"Diary: \" if the category is \"Diary\". If the category were be
  1276. empty, no additional colon would be inserted.
  1277. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1278. which means:
  1279. - Indent the line with two space characters
  1280. - Give the category a 12 chars wide field, padded with whitespace on
  1281. the right (because of `-'). Append a colon if there is a category
  1282. (because of `:').
  1283. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1284. time, don't put in an empty field, just skip it (because of '?').
  1285. - Finally, put the scheduling information.
  1286. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1287. `org-agenda-remove-tags'.
  1288. Custom commands can set this variable in the options section."
  1289. :type '(choice
  1290. (string :tag "General format")
  1291. (list :greedy t :tag "View dependent"
  1292. (cons (const agenda) (string :tag "Format"))
  1293. (cons (const timeline) (string :tag "Format"))
  1294. (cons (const todo) (string :tag "Format"))
  1295. (cons (const tags) (string :tag "Format"))
  1296. (cons (const search) (string :tag "Format"))))
  1297. :group 'org-agenda-line-format)
  1298. (defvar org-prefix-format-compiled nil
  1299. "The compiled version of the most recently used prefix format.
  1300. See the variable `org-agenda-prefix-format'.")
  1301. (defcustom org-agenda-todo-keyword-format "%-1s"
  1302. "Format for the TODO keyword in agenda lines.
  1303. Set this to something like \"%-12s\" if you want all TODO keywords
  1304. to occupy a fixed space in the agenda display."
  1305. :group 'org-agenda-line-format
  1306. :type 'string)
  1307. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1308. "Text preceding timerange entries in the agenda view.
  1309. This is a list with two strings. The first applies when the range
  1310. is entirely on one day. The second applies if the range spans several days.
  1311. The strings may have two \"%d\" format specifiers which will be filled
  1312. with the sequence number of the days, and the total number of days in the
  1313. range, respectively."
  1314. :group 'org-agenda-line-format
  1315. :type '(list
  1316. (string :tag "Deadline today ")
  1317. (choice :tag "Deadline relative"
  1318. (string :tag "Format string")
  1319. (function))))
  1320. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1321. "Text preceding scheduled items in the agenda view.
  1322. This is a list with two strings. The first applies when the item is
  1323. scheduled on the current day. The second applies when it has been scheduled
  1324. previously, it may contain a %d indicating that this is the nth time that
  1325. this item is scheduled, due to automatic rescheduling of unfinished items
  1326. for the following day. So this number is one larger than the number of days
  1327. that passed since this item was scheduled first."
  1328. :group 'org-agenda-line-format
  1329. :type '(list
  1330. (string :tag "Scheduled today ")
  1331. (string :tag "Scheduled previously")))
  1332. (defcustom org-agenda-inactive-leader "["
  1333. "Text preceding item pulled into the agenda by inactive time stamps.
  1334. These entries are added to the agenda when pressing \"[\"."
  1335. :group 'org-agenda-line-format
  1336. :type '(list
  1337. (string :tag "Scheduled today ")
  1338. (string :tag "Scheduled previously")))
  1339. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1340. "Text preceding deadline items in the agenda view.
  1341. This is a list with two strings. The first applies when the item has its
  1342. deadline on the current day. The second applies when it is in the past or
  1343. in the future, it may contain %d to capture how many days away the deadline
  1344. is (was)."
  1345. :group 'org-agenda-line-format
  1346. :type '(list
  1347. (string :tag "Deadline today ")
  1348. (choice :tag "Deadline relative"
  1349. (string :tag "Format string")
  1350. (function))))
  1351. (defcustom org-agenda-remove-times-when-in-prefix t
  1352. "Non-nil means remove duplicate time specifications in agenda items.
  1353. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1354. time-of-day specification in a headline or diary entry is extracted and
  1355. placed into the prefix. If this option is non-nil, the original specification
  1356. \(a timestamp or -range, or just a plain time(range) specification like
  1357. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1358. cluttered.
  1359. The option can be t or nil. It may also be the symbol `beg', indicating
  1360. that the time should only be removed when it is located at the beginning of
  1361. the headline/diary entry."
  1362. :group 'org-agenda-line-format
  1363. :type '(choice
  1364. (const :tag "Always" t)
  1365. (const :tag "Never" nil)
  1366. (const :tag "When at beginning of entry" beg)))
  1367. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1368. "Non-nil means remove time ranges specifications in agenda
  1369. items that span on several days."
  1370. :group 'org-agenda-line-format
  1371. :type 'boolean)
  1372. (defcustom org-agenda-default-appointment-duration nil
  1373. "Default duration for appointments that only have a starting time.
  1374. When nil, no duration is specified in such cases.
  1375. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1376. :group 'org-agenda-line-format
  1377. :type '(choice
  1378. (integer :tag "Minutes")
  1379. (const :tag "No default duration")))
  1380. (defcustom org-agenda-show-inherited-tags t
  1381. "Non-nil means show inherited tags in each agenda line."
  1382. :group 'org-agenda-line-format
  1383. :type 'boolean)
  1384. (defcustom org-agenda-hide-tags-regexp nil
  1385. "Regular expression used to filter away specific tags in agenda views.
  1386. This means that these tags will be present, but not be shown in the agenda
  1387. line. Secondary filtering will still work on the hidden tags.
  1388. Nil means don't hide any tags."
  1389. :group 'org-agenda-line-format
  1390. :type '(choice
  1391. (const :tag "Hide none" nil)
  1392. (string :tag "Regexp ")))
  1393. (defcustom org-agenda-remove-tags nil
  1394. "Non-nil means remove the tags from the headline copy in the agenda.
  1395. When this is the symbol `prefix', only remove tags when
  1396. `org-agenda-prefix-format' contains a `%T' specifier."
  1397. :group 'org-agenda-line-format
  1398. :type '(choice
  1399. (const :tag "Always" t)
  1400. (const :tag "Never" nil)
  1401. (const :tag "When prefix format contains %T" prefix)))
  1402. (if (fboundp 'defvaralias)
  1403. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1404. 'org-agenda-remove-tags))
  1405. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1406. "Shift tags in agenda items to this column.
  1407. If this number is positive, it specifies the column. If it is negative,
  1408. it means that the tags should be flushright to that column. For example,
  1409. -80 works well for a normal 80 character screen."
  1410. :group 'org-agenda-line-format
  1411. :type 'integer)
  1412. (if (fboundp 'defvaralias)
  1413. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1414. (defcustom org-agenda-fontify-priorities 'cookies
  1415. "Non-nil means highlight low and high priorities in agenda.
  1416. When t, the highest priority entries are bold, lowest priority italic.
  1417. However, settings in `org-priority-faces' will overrule these faces.
  1418. When this variable is the symbol `cookies', only fontify the
  1419. cookies, not the entire task.
  1420. This may also be an association list of priority faces, whose
  1421. keys are the character values of `org-highest-priority',
  1422. `org-default-priority', and `org-lowest-priority' (the default values
  1423. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1424. color as a string, or a list like `(:background \"Red\")'.
  1425. If it is a color, the variable `org-faces-easy-properties'
  1426. determines if it is a foreground or a background color."
  1427. :group 'org-agenda-line-format
  1428. :type '(choice
  1429. (const :tag "Never" nil)
  1430. (const :tag "Defaults" t)
  1431. (const :tag "Cookies only" cookies)
  1432. (repeat :tag "Specify"
  1433. (list (character :tag "Priority" :value ?A)
  1434. (choice :tag "Face "
  1435. (string :tag "Color")
  1436. (sexp :tag "Face"))))))
  1437. (defcustom org-agenda-day-face-function nil
  1438. "Function called to determine what face should be used to display a day.
  1439. The only argument passed to that function is the day. It should
  1440. returns a face, or nil if does not want to specify a face and let
  1441. the normal rules apply."
  1442. :group 'org-agenda-line-format
  1443. :type 'function)
  1444. (defcustom org-agenda-category-icon-alist nil
  1445. "Alist of category icon to be displayed in agenda views.
  1446. Each entry should have the following format:
  1447. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1448. Where CATEGORY-REGEXP is a regexp matching the categories where
  1449. the icon should be displayed.
  1450. FILE-OR-DATA either a file path or a string containing image data.
  1451. The other fields can be omited safely if not needed:
  1452. TYPE indicates the image type.
  1453. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1454. image data.
  1455. PROPS are additional image attributes to assign to the image,
  1456. like, e.g. `:ascent center'.
  1457. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1458. If you want to set the display properties yourself, just put a
  1459. list as second element:
  1460. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1461. For example, to display a 16px horizontal space for Emacs
  1462. category, you can use:
  1463. (\"Emacs\" '(space . (:width (16))))"
  1464. :group 'org-agenda-line-format
  1465. :type '(alist :key-type (string :tag "Regexp matching category")
  1466. :value-type (choice (list :tag "Icon"
  1467. (string :tag "File or data")
  1468. (symbol :tag "Type")
  1469. (boolean :tag "Data?")
  1470. (repeat :tag "Extra image properties" :inline t symbol))
  1471. (list :tag "Display properties" sexp))))
  1472. (defgroup org-agenda-column-view nil
  1473. "Options concerning column view in the agenda."
  1474. :tag "Org Agenda Column View"
  1475. :group 'org-agenda)
  1476. (defcustom org-agenda-columns-show-summaries t
  1477. "Non-nil means show summaries for columns displayed in the agenda view."
  1478. :group 'org-agenda-column-view
  1479. :type 'boolean)
  1480. (defcustom org-agenda-columns-compute-summary-properties t
  1481. "Non-nil means recompute all summary properties before column view.
  1482. When column view in the agenda is listing properties that have a summary
  1483. operator, it can go to all relevant buffers and recompute the summaries
  1484. there. This can mean overhead for the agenda column view, but is necessary
  1485. to have thing up to date.
  1486. As a special case, a CLOCKSUM property also makes sure that the clock
  1487. computations are current."
  1488. :group 'org-agenda-column-view
  1489. :type 'boolean)
  1490. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1491. "Non-nil means the duration of an appointment will add to day effort.
  1492. The property to which appointment durations will be added is the one given
  1493. in the option `org-effort-property'. If an appointment does not have
  1494. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1495. is not set, an appointment without end time will not contribute to the time
  1496. estimate."
  1497. :group 'org-agenda-column-view
  1498. :type 'boolean)
  1499. (defcustom org-agenda-auto-exclude-function nil
  1500. "A function called with a tag to decide if it is filtered on '/ RET'.
  1501. The sole argument to the function, which is called once for each
  1502. possible tag, is a string giving the name of the tag. The
  1503. function should return either nil if the tag should be included
  1504. as normal, or \"-<TAG>\" to exclude the tag.
  1505. Note that for the purpose of tag filtering, only the lower-case version of
  1506. all tags will be considered, so that this function will only ever see
  1507. the lower-case version of all tags."
  1508. :group 'org-agenda
  1509. :type 'function)
  1510. (defcustom org-agenda-bulk-custom-functions nil
  1511. "Alist of characters and custom functions for bulk actions.
  1512. For example, this value makes those two functions available:
  1513. '((?R set-category)
  1514. (?C bulk-cut))
  1515. With selected entries in an agenda buffer, `B R' will call
  1516. the custom function `set-category' on the selected entries.
  1517. Note that functions in this alist don't need to be quoted."
  1518. :type 'alist
  1519. :group 'org-agenda)
  1520. (eval-when-compile
  1521. (require 'cl))
  1522. (require 'org)
  1523. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1524. "Execute BODY with point at location given by `org-hd-marker' property.
  1525. If STRING is non-nil, the text property will be fetched from position 0
  1526. in that string. If STRING is nil, it will be fetched from the beginning
  1527. of the current line."
  1528. (org-with-gensyms (marker)
  1529. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1530. 'org-hd-marker string)))
  1531. (with-current-buffer (marker-buffer ,marker)
  1532. (save-excursion
  1533. (goto-char ,marker)
  1534. ,@body)))))
  1535. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1536. (defun org-add-agenda-custom-command (entry)
  1537. "Replace or add a command in `org-agenda-custom-commands'.
  1538. This is mostly for hacking and trying a new command - once the command
  1539. works you probably want to add it to `org-agenda-custom-commands' for good."
  1540. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1541. (if ass
  1542. (setcdr ass (cdr entry))
  1543. (push entry org-agenda-custom-commands))))
  1544. ;;; Define the Org-agenda-mode
  1545. (defvar org-agenda-mode-map (make-sparse-keymap)
  1546. "Keymap for `org-agenda-mode'.")
  1547. (if (fboundp 'defvaralias)
  1548. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1549. (defvar org-agenda-menu) ; defined later in this file.
  1550. (defvar org-agenda-restrict) ; defined later in this file.
  1551. (defvar org-agenda-follow-mode nil)
  1552. (defvar org-agenda-entry-text-mode nil)
  1553. (defvar org-agenda-clockreport-mode nil)
  1554. (defvar org-agenda-show-log nil)
  1555. (defvar org-agenda-redo-command nil)
  1556. (defvar org-agenda-query-string nil)
  1557. (defvar org-agenda-mode-hook nil
  1558. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1559. (defvar org-agenda-type nil)
  1560. (defvar org-agenda-force-single-file nil)
  1561. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1562. (defun org-agenda-mode ()
  1563. "Mode for time-sorted view on action items in Org-mode files.
  1564. The following commands are available:
  1565. \\{org-agenda-mode-map}"
  1566. (interactive)
  1567. (kill-all-local-variables)
  1568. (setq org-agenda-undo-list nil
  1569. org-agenda-pending-undo-list nil
  1570. org-agenda-bulk-marked-entries nil)
  1571. (setq major-mode 'org-agenda-mode)
  1572. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1573. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1574. (setq mode-name "Org-Agenda")
  1575. (use-local-map org-agenda-mode-map)
  1576. (easy-menu-add org-agenda-menu)
  1577. (if org-startup-truncated (setq truncate-lines t))
  1578. (org-set-local 'line-move-visual nil)
  1579. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1580. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1581. ;; Make sure properties are removed when copying text
  1582. (when (boundp 'buffer-substring-filters)
  1583. (org-set-local 'buffer-substring-filters
  1584. (cons (lambda (x)
  1585. (set-text-properties 0 (length x) nil x) x)
  1586. buffer-substring-filters)))
  1587. (unless org-agenda-keep-modes
  1588. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1589. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1590. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1591. org-agenda-show-log org-agenda-start-with-log-mode))
  1592. (easy-menu-change
  1593. '("Agenda") "Agenda Files"
  1594. (append
  1595. (list
  1596. (vector
  1597. (if (get 'org-agenda-files 'org-restrict)
  1598. "Restricted to single file"
  1599. "Edit File List")
  1600. '(org-edit-agenda-file-list)
  1601. (not (get 'org-agenda-files 'org-restrict)))
  1602. "--")
  1603. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1604. (org-agenda-set-mode-name)
  1605. (apply
  1606. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1607. (list 'org-agenda-mode-hook)))
  1608. (substitute-key-definition 'undo 'org-agenda-undo
  1609. org-agenda-mode-map global-map)
  1610. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1611. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1612. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1613. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1614. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1615. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1616. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1617. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1618. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1619. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1620. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1621. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1622. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1623. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1624. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1625. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1626. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1627. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1628. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1629. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1630. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1631. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1632. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1633. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1634. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1635. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1636. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1637. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1638. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1639. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1640. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1641. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1642. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1643. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1644. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1645. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1646. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1647. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1648. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1649. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1650. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1651. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1652. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1653. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1654. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1655. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1656. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1657. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1658. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1659. (while l (org-defkey org-agenda-mode-map
  1660. (int-to-string (pop l)) 'digit-argument)))
  1661. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1662. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1663. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1664. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1665. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1666. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1667. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1668. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1669. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1670. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1671. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1672. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1673. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1674. 'org-clock-modify-effort-estimate)
  1675. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1676. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1677. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1678. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1679. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1680. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1681. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1682. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1683. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1684. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1685. (substitute-key-definition 'next-line 'org-agenda-next-line
  1686. org-agenda-mode-map global-map)
  1687. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1688. org-agenda-mode-map global-map)
  1689. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1690. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1691. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1692. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1693. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1694. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1695. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1696. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1697. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1698. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1699. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1700. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1701. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1702. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1703. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1704. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1705. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1706. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1707. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1708. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1709. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1710. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1711. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1712. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1713. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1714. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1715. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1716. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1717. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1718. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1719. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1720. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1721. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1722. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1723. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1724. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1725. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1726. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1727. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1728. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1729. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1730. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1731. (when org-agenda-mouse-1-follows-link
  1732. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1733. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1734. '("Agenda"
  1735. ("Agenda Files")
  1736. "--"
  1737. ("Agenda Dates"
  1738. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1739. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1740. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1741. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1742. "--"
  1743. ("View"
  1744. ["Day View" org-agenda-day-view
  1745. :active (org-agenda-check-type nil 'agenda)
  1746. :style radio :selected (eq org-agenda-current-span 'day)
  1747. :keys "v d (or just d)"]
  1748. ["Week View" org-agenda-week-view
  1749. :active (org-agenda-check-type nil 'agenda)
  1750. :style radio :selected (eq org-agenda-current-span 'week)
  1751. :keys "v w (or just w)"]
  1752. ["Month View" org-agenda-month-view
  1753. :active (org-agenda-check-type nil 'agenda)
  1754. :style radio :selected (eq org-agenda-current-span 'month)
  1755. :keys "v m"]
  1756. ["Year View" org-agenda-year-view
  1757. :active (org-agenda-check-type nil 'agenda)
  1758. :style radio :selected (eq org-agenda-current-span 'year)
  1759. :keys "v y"]
  1760. "--"
  1761. ["Include Diary" org-agenda-toggle-diary
  1762. :style toggle :selected org-agenda-include-diary
  1763. :active (org-agenda-check-type nil 'agenda)]
  1764. ["Include Deadlines" org-agenda-toggle-deadlines
  1765. :style toggle :selected org-agenda-include-deadlines
  1766. :active (org-agenda-check-type nil 'agenda)]
  1767. ["Use Time Grid" org-agenda-toggle-time-grid
  1768. :style toggle :selected org-agenda-use-time-grid
  1769. :active (org-agenda-check-type nil 'agenda)]
  1770. "--"
  1771. ["Show clock report" org-agenda-clockreport-mode
  1772. :style toggle :selected org-agenda-clockreport-mode
  1773. :active (org-agenda-check-type nil 'agenda)]
  1774. ["Show some entry text" org-agenda-entry-text-mode
  1775. :style toggle :selected org-agenda-entry-text-mode
  1776. :active t]
  1777. "--"
  1778. ["Show Logbook entries" org-agenda-log-mode
  1779. :style toggle :selected org-agenda-show-log
  1780. :active (org-agenda-check-type nil 'agenda 'timeline)
  1781. :keys "v l (or just l)"]
  1782. ["Include archived trees" org-agenda-archives-mode
  1783. :style toggle :selected org-agenda-archives-mode :active t
  1784. :keys "v a"]
  1785. ["Include archive files" (org-agenda-archives-mode t)
  1786. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1787. :keys "v A"]
  1788. "--"
  1789. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1790. ["Write view to file" org-write-agenda t]
  1791. ["Rebuild buffer" org-agenda-redo t]
  1792. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1793. "--"
  1794. ["Show original entry" org-agenda-show t]
  1795. ["Go To (other window)" org-agenda-goto t]
  1796. ["Go To (this window)" org-agenda-switch-to t]
  1797. ["Follow Mode" org-agenda-follow-mode
  1798. :style toggle :selected org-agenda-follow-mode :active t]
  1799. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1800. "--"
  1801. ("TODO"
  1802. ["Cycle TODO" org-agenda-todo t]
  1803. ["Next TODO set" org-agenda-todo-nextset t]
  1804. ["Previous TODO set" org-agenda-todo-previousset t]
  1805. ["Add note" org-agenda-add-note t])
  1806. ("Archive/Refile/Delete"
  1807. ["Archive default" org-agenda-archive-default t]
  1808. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1809. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1810. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1811. ["Archive subtree" org-agenda-archive t]
  1812. "--"
  1813. ["Refile" org-agenda-refile t]
  1814. "--"
  1815. ["Delete subtree" org-agenda-kill t])
  1816. ("Bulk action"
  1817. ["Mark entry" org-agenda-bulk-mark t]
  1818. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1819. ["Unmark entry" org-agenda-bulk-unmark t]
  1820. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1821. ["Act on all marked" org-agenda-bulk-action t]
  1822. "--"
  1823. ("Tags and Properties"
  1824. ["Show all Tags" org-agenda-show-tags t]
  1825. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1826. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1827. "--"
  1828. ["Column View" org-columns t])
  1829. ("Deadline/Schedule"
  1830. ["Schedule" org-agenda-schedule t]
  1831. ["Set Deadline" org-agenda-deadline t]
  1832. "--"
  1833. ["Mark item" org-agenda-action :active t :keys "k m"]
  1834. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1835. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1836. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1837. "--"
  1838. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1839. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1840. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1841. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1842. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1843. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1844. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1845. ("Clock and Effort"
  1846. ["Clock in" org-agenda-clock-in t]
  1847. ["Clock out" org-agenda-clock-out t]
  1848. ["Clock cancel" org-agenda-clock-cancel t]
  1849. ["Goto running clock" org-clock-goto t]
  1850. "--"
  1851. ["Set Effort" org-agenda-set-effort t]
  1852. ["Change clocked effort" org-clock-modify-effort-estimate
  1853. (org-clock-is-active)])
  1854. ("Priority"
  1855. ["Set Priority" org-agenda-priority t]
  1856. ["Increase Priority" org-agenda-priority-up t]
  1857. ["Decrease Priority" org-agenda-priority-down t]
  1858. ["Show Priority" org-agenda-show-priority t])
  1859. ("Calendar/Diary"
  1860. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1861. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1862. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1863. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1864. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1865. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1866. "--"
  1867. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1868. "--"
  1869. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1870. "--"
  1871. ("MobileOrg"
  1872. ["Push Files and Views" org-mobile-push t]
  1873. ["Get Captured and Flagged" org-mobile-pull t]
  1874. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1875. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1876. "--"
  1877. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1878. "--"
  1879. ["Quit" org-agenda-quit t]
  1880. ["Exit and Release Buffers" org-agenda-exit t]
  1881. ))
  1882. ;;; Agenda undo
  1883. (defvar org-agenda-allow-remote-undo t
  1884. "Non-nil means allow remote undo from the agenda buffer.")
  1885. (defvar org-agenda-undo-list nil
  1886. "List of undoable operations in the agenda since last refresh.")
  1887. (defvar org-agenda-undo-has-started-in nil
  1888. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1889. (defvar org-agenda-pending-undo-list nil
  1890. "In a series of undo commands, this is the list of remaining undo items.")
  1891. (defun org-agenda-undo ()
  1892. "Undo a remote editing step in the agenda.
  1893. This undoes changes both in the agenda buffer and in the remote buffer
  1894. that have been changed along."
  1895. (interactive)
  1896. (or org-agenda-allow-remote-undo
  1897. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1898. (if (not (eq this-command last-command))
  1899. (setq org-agenda-undo-has-started-in nil
  1900. org-agenda-pending-undo-list org-agenda-undo-list))
  1901. (if (not org-agenda-pending-undo-list)
  1902. (error "No further undo information"))
  1903. (let* ((entry (pop org-agenda-pending-undo-list))
  1904. buf line cmd rembuf)
  1905. (setq cmd (pop entry) line (pop entry))
  1906. (setq rembuf (nth 2 entry))
  1907. (org-with-remote-undo rembuf
  1908. (while (bufferp (setq buf (pop entry)))
  1909. (if (pop entry)
  1910. (with-current-buffer buf
  1911. (let ((last-undo-buffer buf)
  1912. (inhibit-read-only t))
  1913. (unless (memq buf org-agenda-undo-has-started-in)
  1914. (push buf org-agenda-undo-has-started-in)
  1915. (make-local-variable 'pending-undo-list)
  1916. (undo-start))
  1917. (while (and pending-undo-list
  1918. (listp pending-undo-list)
  1919. (not (car pending-undo-list)))
  1920. (pop pending-undo-list))
  1921. (undo-more 1))))))
  1922. (org-goto-line line)
  1923. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1924. (defun org-verify-change-for-undo (l1 l2)
  1925. "Verify that a real change occurred between the undo lists L1 and L2."
  1926. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1927. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1928. (not (eq l1 l2)))
  1929. ;;; Agenda dispatch
  1930. (defvar org-agenda-restrict nil)
  1931. (defvar org-agenda-restrict-begin (make-marker))
  1932. (defvar org-agenda-restrict-end (make-marker))
  1933. (defvar org-agenda-last-dispatch-buffer nil)
  1934. (defvar org-agenda-overriding-restriction nil)
  1935. ;;;###autoload
  1936. (defun org-agenda (&optional arg keys restriction)
  1937. "Dispatch agenda commands to collect entries to the agenda buffer.
  1938. Prompts for a command to execute. Any prefix arg will be passed
  1939. on to the selected command. The default selections are:
  1940. a Call `org-agenda-list' to display the agenda for current day or week.
  1941. t Call `org-todo-list' to display the global todo list.
  1942. T Call `org-todo-list' to display the global todo list, select only
  1943. entries with a specific TODO keyword (the user gets a prompt).
  1944. m Call `org-tags-view' to display headlines with tags matching
  1945. a condition (the user is prompted for the condition).
  1946. M Like `m', but select only TODO entries, no ordinary headlines.
  1947. L Create a timeline for the current buffer.
  1948. e Export views to associated files.
  1949. s Search entries for keywords.
  1950. / Multi occur across all agenda files and also files listed
  1951. in `org-agenda-text-search-extra-files'.
  1952. < Restrict agenda commands to buffer, subtree, or region.
  1953. Press several times to get the desired effect.
  1954. > Remove a previous restriction.
  1955. # List \"stuck\" projects.
  1956. ! Configure what \"stuck\" means.
  1957. C Configure custom agenda commands.
  1958. More commands can be added by configuring the variable
  1959. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1960. searches can be pre-defined in this way.
  1961. If the current buffer is in Org-mode and visiting a file, you can also
  1962. first press `<' once to indicate that the agenda should be temporarily
  1963. \(until the next use of \\[org-agenda]) restricted to the current file.
  1964. Pressing `<' twice means to restrict to the current subtree or region
  1965. \(if active)."
  1966. (interactive "P")
  1967. (catch 'exit
  1968. (let* ((prefix-descriptions nil)
  1969. (org-agenda-window-setup (if (equal (buffer-name)
  1970. org-agenda-buffer-name)
  1971. 'current-window
  1972. org-agenda-window-setup))
  1973. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1974. (org-agenda-custom-commands
  1975. ;; normalize different versions
  1976. (delq nil
  1977. (mapcar
  1978. (lambda (x)
  1979. (cond ((stringp (cdr x))
  1980. (push x prefix-descriptions)
  1981. nil)
  1982. ((stringp (nth 1 x)) x)
  1983. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1984. (t (cons (car x) (cons "" (cdr x))))))
  1985. org-agenda-custom-commands)))
  1986. (buf (current-buffer))
  1987. (bfn (buffer-file-name (buffer-base-buffer)))
  1988. entry key type match lprops ans)
  1989. ;; Turn off restriction unless there is an overriding one,
  1990. (unless org-agenda-overriding-restriction
  1991. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1992. ;; There is a request to keep the file list in place
  1993. (put 'org-agenda-files 'org-restrict nil))
  1994. (setq org-agenda-restrict nil)
  1995. (move-marker org-agenda-restrict-begin nil)
  1996. (move-marker org-agenda-restrict-end nil))
  1997. ;; Delete old local properties
  1998. (put 'org-agenda-redo-command 'org-lprops nil)
  1999. ;; Delete previously set last-arguments
  2000. (put 'org-agenda-redo-command 'last-args nil)
  2001. ;; Remember where this call originated
  2002. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2003. (unless keys
  2004. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2005. keys (car ans)
  2006. restriction (cdr ans)))
  2007. ;; Establish the restriction, if any
  2008. (when (and (not org-agenda-overriding-restriction) restriction)
  2009. (put 'org-agenda-files 'org-restrict (list bfn))
  2010. (cond
  2011. ((eq restriction 'region)
  2012. (setq org-agenda-restrict t)
  2013. (move-marker org-agenda-restrict-begin (region-beginning))
  2014. (move-marker org-agenda-restrict-end (region-end)))
  2015. ((eq restriction 'subtree)
  2016. (save-excursion
  2017. (setq org-agenda-restrict t)
  2018. (org-back-to-heading t)
  2019. (move-marker org-agenda-restrict-begin (point))
  2020. (move-marker org-agenda-restrict-end
  2021. (progn (org-end-of-subtree t)))))))
  2022. ;; For example the todo list should not need it (but does...)
  2023. (cond
  2024. ((setq entry (assoc keys org-agenda-custom-commands))
  2025. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2026. (progn
  2027. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2028. lprops (nth 4 entry))
  2029. (put 'org-agenda-redo-command 'org-lprops lprops)
  2030. (cond
  2031. ((eq type 'agenda)
  2032. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2033. ((eq type 'alltodo)
  2034. (org-let lprops '(org-todo-list current-prefix-arg)))
  2035. ((eq type 'search)
  2036. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2037. ((eq type 'stuck)
  2038. (org-let lprops '(org-agenda-list-stuck-projects
  2039. current-prefix-arg)))
  2040. ((eq type 'tags)
  2041. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2042. ((eq type 'tags-todo)
  2043. (org-let lprops '(org-tags-view '(4) match)))
  2044. ((eq type 'todo)
  2045. (org-let lprops '(org-todo-list match)))
  2046. ((eq type 'tags-tree)
  2047. (org-check-for-org-mode)
  2048. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2049. ((eq type 'todo-tree)
  2050. (org-check-for-org-mode)
  2051. (org-let lprops
  2052. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2053. (regexp-quote match) "\\>"))))
  2054. ((eq type 'occur-tree)
  2055. (org-check-for-org-mode)
  2056. (org-let lprops '(org-occur match)))
  2057. ((functionp type)
  2058. (org-let lprops '(funcall type match)))
  2059. ((fboundp type)
  2060. (org-let lprops '(funcall type match)))
  2061. (t (error "Invalid custom agenda command type %s" type))))
  2062. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2063. ((equal keys "C")
  2064. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2065. (customize-variable 'org-agenda-custom-commands))
  2066. ((equal keys "a") (call-interactively 'org-agenda-list))
  2067. ((equal keys "s") (call-interactively 'org-search-view))
  2068. ((equal keys "t") (call-interactively 'org-todo-list))
  2069. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2070. ((equal keys "m") (call-interactively 'org-tags-view))
  2071. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2072. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2073. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2074. (org-add-hook
  2075. 'post-command-hook
  2076. (lambda ()
  2077. (unless (current-message)
  2078. (let* ((m (org-agenda-get-any-marker))
  2079. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2080. (when note
  2081. (message (concat
  2082. "FLAGGING-NOTE ([?] for more info): "
  2083. (org-add-props
  2084. (replace-regexp-in-string
  2085. "\\\\n" "//"
  2086. (copy-sequence note))
  2087. nil 'face 'org-warning)))))))
  2088. t t))
  2089. ((equal keys "L")
  2090. (unless (eq major-mode 'org-mode)
  2091. (error "This is not an Org-mode file"))
  2092. (unless restriction
  2093. (put 'org-agenda-files 'org-restrict (list bfn))
  2094. (org-call-with-arg 'org-timeline arg)))
  2095. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2096. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2097. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2098. (t (error "Invalid agenda key"))))))
  2099. (defun org-agenda-append-agenda ()
  2100. "Append another agenda view to the current one.
  2101. This function allows interactive building of block agendas.
  2102. Agenda views are separated by `org-agenda-block-separator'."
  2103. (interactive)
  2104. (unless (string= (buffer-name) org-agenda-buffer-name)
  2105. (error "Can only append from within agenda buffer"))
  2106. (let ((org-agenda-multi t))
  2107. (org-agenda)
  2108. (widen)))
  2109. (defun org-agenda-normalize-custom-commands (cmds)
  2110. (delq nil
  2111. (mapcar
  2112. (lambda (x)
  2113. (cond ((stringp (cdr x)) nil)
  2114. ((stringp (nth 1 x)) x)
  2115. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2116. (t (cons (car x) (cons "" (cdr x))))))
  2117. cmds)))
  2118. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2119. "The user interface for selecting an agenda command."
  2120. (catch 'exit
  2121. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2122. (restrict-ok (and bfn (eq major-mode 'org-mode)))
  2123. (region-p (org-region-active-p))
  2124. (custom org-agenda-custom-commands)
  2125. (selstring "")
  2126. restriction second-time
  2127. c entry key type match prefixes rmheader header-end custom1 desc
  2128. line lines left right n n1)
  2129. (save-window-excursion
  2130. (delete-other-windows)
  2131. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2132. (erase-buffer)
  2133. (insert (eval-when-compile
  2134. (let ((header
  2135. "
  2136. Press key for an agenda command: < Buffer, subtree/region restriction
  2137. -------------------------------- > Remove restriction
  2138. a Agenda for current week or day e Export agenda views
  2139. t List of all TODO entries T Entries with special TODO kwd
  2140. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2141. L Timeline for current buffer # List stuck projects (!=configure)
  2142. s Search for keywords C Configure custom agenda commands
  2143. / Multi-occur ? Find :FLAGGED: entries
  2144. ")
  2145. (start 0))
  2146. (while (string-match
  2147. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2148. header start)
  2149. (setq start (match-end 0))
  2150. (add-text-properties (match-beginning 2) (match-end 2)
  2151. '(face bold) header))
  2152. header)))
  2153. (setq header-end (move-marker (make-marker) (point)))
  2154. (while t
  2155. (setq custom1 custom)
  2156. (when (eq rmheader t)
  2157. (org-goto-line 1)
  2158. (re-search-forward ":" nil t)
  2159. (delete-region (match-end 0) (point-at-eol))
  2160. (forward-char 1)
  2161. (looking-at "-+")
  2162. (delete-region (match-end 0) (point-at-eol))
  2163. (move-marker header-end (match-end 0)))
  2164. (goto-char header-end)
  2165. (delete-region (point) (point-max))
  2166. ;; Produce all the lines that describe custom commands and prefixes
  2167. (setq lines nil)
  2168. (while (setq entry (pop custom1))
  2169. (setq key (car entry) desc (nth 1 entry)
  2170. type (nth 2 entry)
  2171. match (nth 3 entry))
  2172. (if (> (length key) 1)
  2173. (add-to-list 'prefixes (string-to-char key))
  2174. (setq line
  2175. (format
  2176. "%-4s%-14s"
  2177. (org-add-props (copy-sequence key)
  2178. '(face bold))
  2179. (cond
  2180. ((string-match "\\S-" desc) desc)
  2181. ((eq type 'agenda) "Agenda for current week or day")
  2182. ((eq type 'alltodo) "List of all TODO entries")
  2183. ((eq type 'search) "Word search")
  2184. ((eq type 'stuck) "List of stuck projects")
  2185. ((eq type 'todo) "TODO keyword")
  2186. ((eq type 'tags) "Tags query")
  2187. ((eq type 'tags-todo) "Tags (TODO)")
  2188. ((eq type 'tags-tree) "Tags tree")
  2189. ((eq type 'todo-tree) "TODO kwd tree")
  2190. ((eq type 'occur-tree) "Occur tree")
  2191. ((functionp type) (if (symbolp type)
  2192. (symbol-name type)
  2193. "Lambda expression"))
  2194. (t "???"))))
  2195. (if org-agenda-menu-show-matcher
  2196. (setq line
  2197. (concat line ": "
  2198. (cond
  2199. ((stringp match)
  2200. (setq match (copy-sequence match))
  2201. (org-add-props match nil 'face 'org-warning))
  2202. (match
  2203. (format "set of %d commands" (length match)))
  2204. (t ""))))
  2205. (if (org-string-nw-p match)
  2206. (add-text-properties
  2207. 0 (length line) (list 'help-echo
  2208. (concat "Matcher: "match)) line)))
  2209. (push line lines)))
  2210. (setq lines (nreverse lines))
  2211. (when prefixes
  2212. (mapc (lambda (x)
  2213. (push
  2214. (format "%s %s"
  2215. (org-add-props (char-to-string x)
  2216. nil 'face 'bold)
  2217. (or (cdr (assoc (concat selstring
  2218. (char-to-string x))
  2219. prefix-descriptions))
  2220. "Prefix key"))
  2221. lines))
  2222. prefixes))
  2223. ;; Check if we should display in two columns
  2224. (if org-agenda-menu-two-column
  2225. (progn
  2226. (setq n (length lines)
  2227. n1 (+ (/ n 2) (mod n 2))
  2228. right (nthcdr n1 lines)
  2229. left (copy-sequence lines))
  2230. (setcdr (nthcdr (1- n1) left) nil))
  2231. (setq left lines right nil))
  2232. (while left
  2233. (insert "\n" (pop left))
  2234. (when right
  2235. (if (< (current-column) 40)
  2236. (move-to-column 40 t)
  2237. (insert " "))
  2238. (insert (pop right))))
  2239. ;; Make the window the right size
  2240. (goto-char (point-min))
  2241. (if second-time
  2242. (if (not (pos-visible-in-window-p (point-max)))
  2243. (org-fit-window-to-buffer))
  2244. (setq second-time t)
  2245. (org-fit-window-to-buffer))
  2246. ;; Ask for selection
  2247. (message "Press key for agenda command%s:"
  2248. (if (or restrict-ok org-agenda-overriding-restriction)
  2249. (if org-agenda-overriding-restriction
  2250. " (restriction lock active)"
  2251. (if restriction
  2252. (format " (restricted to %s)" restriction)
  2253. " (unrestricted)"))
  2254. ""))
  2255. (setq c (read-char-exclusive))
  2256. (message "")
  2257. (cond
  2258. ((assoc (char-to-string c) custom)
  2259. (setq selstring (concat selstring (char-to-string c)))
  2260. (throw 'exit (cons selstring restriction)))
  2261. ((memq c prefixes)
  2262. (setq selstring (concat selstring (char-to-string c))
  2263. prefixes nil
  2264. rmheader (or rmheader t)
  2265. custom (delq nil (mapcar
  2266. (lambda (x)
  2267. (if (or (= (length (car x)) 1)
  2268. (/= (string-to-char (car x)) c))
  2269. nil
  2270. (cons (substring (car x) 1) (cdr x))))
  2271. custom))))
  2272. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2273. (message "Restriction is only possible in Org-mode buffers")
  2274. (ding) (sit-for 1))
  2275. ((eq c ?1)
  2276. (org-agenda-remove-restriction-lock 'noupdate)
  2277. (setq restriction 'buffer))
  2278. ((eq c ?0)
  2279. (org-agenda-remove-restriction-lock 'noupdate)
  2280. (setq restriction (if region-p 'region 'subtree)))
  2281. ((eq c ?<)
  2282. (org-agenda-remove-restriction-lock 'noupdate)
  2283. (setq restriction
  2284. (cond
  2285. ((eq restriction 'buffer)
  2286. (if region-p 'region 'subtree))
  2287. ((memq restriction '(subtree region))
  2288. nil)
  2289. (t 'buffer))))
  2290. ((eq c ?>)
  2291. (org-agenda-remove-restriction-lock 'noupdate)
  2292. (setq restriction nil))
  2293. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2294. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2295. ((and (> (length selstring) 0) (eq c ?\d))
  2296. (delete-window)
  2297. (org-agenda-get-restriction-and-command prefix-descriptions))
  2298. ((equal c ?q) (error "Abort"))
  2299. (t (error "Invalid key %c" c))))))))
  2300. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2301. (defvar org-agenda-last-arguments nil
  2302. "The arguments of the previous call to `org-agenda'.")
  2303. (defun org-agenda-run-series (name series)
  2304. (org-let (nth 1 series) '(org-prepare-agenda name))
  2305. (let* ((org-agenda-multi t)
  2306. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2307. (org-agenda-overriding-arguments
  2308. (or org-agenda-overriding-arguments
  2309. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2310. (get 'org-agenda-redo-command 'last-args))))
  2311. (cmds (car series))
  2312. (gprops (nth 1 series))
  2313. match ;; The byte compiler incorrectly complains about this. Keep it!
  2314. cmd type lprops)
  2315. (while (setq cmd (pop cmds))
  2316. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2317. (cond
  2318. ((eq type 'agenda)
  2319. (org-let2 gprops lprops
  2320. '(call-interactively 'org-agenda-list)))
  2321. ((eq type 'alltodo)
  2322. (org-let2 gprops lprops
  2323. '(call-interactively 'org-todo-list)))
  2324. ((eq type 'search)
  2325. (org-let2 gprops lprops
  2326. '(org-search-view current-prefix-arg match nil)))
  2327. ((eq type 'stuck)
  2328. (org-let2 gprops lprops
  2329. '(call-interactively 'org-agenda-list-stuck-projects)))
  2330. ((eq type 'tags)
  2331. (org-let2 gprops lprops
  2332. '(org-tags-view current-prefix-arg match)))
  2333. ((eq type 'tags-todo)
  2334. (org-let2 gprops lprops
  2335. '(org-tags-view '(4) match)))
  2336. ((eq type 'todo)
  2337. (org-let2 gprops lprops
  2338. '(org-todo-list match)))
  2339. ((fboundp type)
  2340. (org-let2 gprops lprops
  2341. '(funcall type match)))
  2342. (t (error "Invalid type in command series"))))
  2343. (widen)
  2344. (setq org-agenda-redo-command redo)
  2345. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2346. (goto-char (point-min)))
  2347. (org-fit-agenda-window)
  2348. (org-let (nth 1 series) '(org-finalize-agenda)))
  2349. ;;;###autoload
  2350. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2351. "Run an agenda command in batch mode and send the result to STDOUT.
  2352. If CMD-KEY is a string of length 1, it is used as a key in
  2353. `org-agenda-custom-commands' and triggers this command. If it is a
  2354. longer string it is used as a tags/todo match string.
  2355. Parameters are alternating variable names and values that will be bound
  2356. before running the agenda command."
  2357. (org-eval-in-environment (org-make-parameter-alist parameters)
  2358. (if (> (length cmd-key) 2)
  2359. (org-tags-view nil cmd-key)
  2360. (org-agenda nil cmd-key)))
  2361. (set-buffer org-agenda-buffer-name)
  2362. (princ (org-encode-for-stdout (buffer-string))))
  2363. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2364. ;(defun org-encode-for-stdout (string)
  2365. ; (if (fboundp 'encode-coding-string)
  2366. ; (encode-coding-string string buffer-file-coding-system)
  2367. ; string))
  2368. (defun org-encode-for-stdout (string)
  2369. string)
  2370. (defvar org-agenda-info nil)
  2371. ;;;###autoload
  2372. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2373. "Run an agenda command in batch mode and send the result to STDOUT.
  2374. If CMD-KEY is a string of length 1, it is used as a key in
  2375. `org-agenda-custom-commands' and triggers this command. If it is a
  2376. longer string it is used as a tags/todo match string.
  2377. Parameters are alternating variable names and values that will be bound
  2378. before running the agenda command.
  2379. The output gives a line for each selected agenda item. Each
  2380. item is a list of comma-separated values, like this:
  2381. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2382. category The category of the item
  2383. head The headline, without TODO kwd, TAGS and PRIORITY
  2384. type The type of the agenda entry, can be
  2385. todo selected in TODO match
  2386. tagsmatch selected in tags match
  2387. diary imported from diary
  2388. deadline a deadline on given date
  2389. scheduled scheduled on given date
  2390. timestamp entry has timestamp on given date
  2391. closed entry was closed on given date
  2392. upcoming-deadline warning about deadline
  2393. past-scheduled forwarded scheduled item
  2394. block entry has date block including g. date
  2395. todo The todo keyword, if any
  2396. tags All tags including inherited ones, separated by colons
  2397. date The relevant date, like 2007-2-14
  2398. time The time, like 15:00-16:50
  2399. extra Sting with extra planning info
  2400. priority-l The priority letter if any was given
  2401. priority-n The computed numerical priority
  2402. agenda-day The day in the agenda where this is listed"
  2403. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2404. (org-make-parameter-alist parameters))
  2405. (if (> (length cmd-key) 2)
  2406. (org-tags-view nil cmd-key)
  2407. (org-agenda nil cmd-key)))
  2408. (set-buffer org-agenda-buffer-name)
  2409. (let* ((lines (org-split-string (buffer-string) "\n"))
  2410. line)
  2411. (while (setq line (pop lines))
  2412. (catch 'next
  2413. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2414. (setq org-agenda-info
  2415. (org-fix-agenda-info (text-properties-at 0 line)))
  2416. (princ
  2417. (org-encode-for-stdout
  2418. (mapconcat 'org-agenda-export-csv-mapper
  2419. '(org-category txt type todo tags date time extra
  2420. priority-letter priority agenda-day)
  2421. ",")))
  2422. (princ "\n")))))
  2423. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2424. (defun org-fix-agenda-info (props)
  2425. "Make sure all properties on an agenda item have a canonical form.
  2426. This ensures the export commands can easily use it."
  2427. (let (tmp re)
  2428. (when (setq tmp (plist-get props 'tags))
  2429. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2430. (when (setq tmp (plist-get props 'date))
  2431. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2432. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2433. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2434. (setq tmp (calendar-date-string tmp)))
  2435. (setq props (plist-put props 'date tmp)))
  2436. (when (setq tmp (plist-get props 'day))
  2437. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2438. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2439. (setq tmp (calendar-date-string tmp)))
  2440. (setq props (plist-put props 'day tmp))
  2441. (setq props (plist-put props 'agenda-day tmp)))
  2442. (when (setq tmp (plist-get props 'txt))
  2443. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2444. (plist-put props 'priority-letter (match-string 1 tmp))
  2445. (setq tmp (replace-match "" t t tmp)))
  2446. (when (and (setq re (plist-get props 'org-todo-regexp))
  2447. (setq re (concat "\\`\\.*" re " ?"))
  2448. (string-match re tmp))
  2449. (plist-put props 'todo (match-string 1 tmp))
  2450. (setq tmp (replace-match "" t t tmp)))
  2451. (plist-put props 'txt tmp)))
  2452. props)
  2453. (defun org-agenda-export-csv-mapper (prop)
  2454. (let ((res (plist-get org-agenda-info prop)))
  2455. (setq res
  2456. (cond
  2457. ((not res) "")
  2458. ((stringp res) res)
  2459. (t (prin1-to-string res))))
  2460. (while (string-match "," res)
  2461. (setq res (replace-match ";" t t res)))
  2462. (org-trim res)))
  2463. ;;;###autoload
  2464. (defun org-store-agenda-views (&rest parameters)
  2465. (interactive)
  2466. (eval (list 'org-batch-store-agenda-views)))
  2467. ;;;###autoload
  2468. (defmacro org-batch-store-agenda-views (&rest parameters)
  2469. "Run all custom agenda commands that have a file argument."
  2470. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2471. (pop-up-frames nil)
  2472. (dir default-directory)
  2473. (pars (org-make-parameter-alist parameters))
  2474. cmd thiscmdkey files opts cmd-or-set)
  2475. (save-window-excursion
  2476. (while cmds
  2477. (setq cmd (pop cmds)
  2478. thiscmdkey (car cmd)
  2479. cmd-or-set (nth 2 cmd)
  2480. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2481. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2482. (if (stringp files) (setq files (list files)))
  2483. (when files
  2484. (org-eval-in-environment (append org-agenda-exporter-settings
  2485. opts pars)
  2486. (org-agenda nil thiscmdkey))
  2487. (set-buffer org-agenda-buffer-name)
  2488. (while files
  2489. (org-eval-in-environment (append org-agenda-exporter-settings
  2490. opts pars)
  2491. (org-write-agenda (expand-file-name (pop files) dir) nil t)))
  2492. (and (get-buffer org-agenda-buffer-name)
  2493. (kill-buffer org-agenda-buffer-name)))))))
  2494. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2495. (defun org-agenda-mark-header-line (pos)
  2496. "Mark the line at POS as an agenda structure header."
  2497. (save-excursion
  2498. (goto-char pos)
  2499. (put-text-property (point-at-bol) (point-at-eol)
  2500. 'org-agenda-structural-header t)
  2501. (when org-agenda-title-append
  2502. (put-text-property (point-at-bol) (point-at-eol)
  2503. 'org-agenda-title-append org-agenda-title-append))))
  2504. (defvar org-mobile-creating-agendas)
  2505. (defun org-write-agenda (file &optional open nosettings)
  2506. "Write the current buffer (an agenda view) as a file.
  2507. Depending on the extension of the file name, plain text (.txt),
  2508. HTML (.html or .htm) or Postscript (.ps) is produced.
  2509. If the extension is .ics, run icalendar export over all files used
  2510. to construct the agenda and limit the export to entries listed in the
  2511. agenda now.
  2512. With prefix argument OPEN, open the new file immediately.
  2513. If NOSETTINGS is given, do not scope the settings of
  2514. `org-agenda-exporter-settings' into the export commands. This is used when
  2515. the settings have already been scoped and we do not wish to overrule other,
  2516. higher priority settings."
  2517. (interactive "FWrite agenda to file: \nP")
  2518. (if (not (file-writable-p file))
  2519. (error "Cannot write agenda to file %s" file))
  2520. (org-let (if nosettings nil org-agenda-exporter-settings)
  2521. '(save-excursion
  2522. (save-window-excursion
  2523. (org-agenda-mark-filtered-text)
  2524. (let ((bs (copy-sequence (buffer-string))) beg)
  2525. (org-agenda-unmark-filtered-text)
  2526. (with-temp-buffer
  2527. (rename-buffer "Agenda View" t)
  2528. (set-buffer-modified-p nil)
  2529. (insert bs)
  2530. (org-agenda-remove-marked-text 'org-filtered)
  2531. (while (setq beg (text-property-any (point-min) (point-max)
  2532. 'org-filtered t))
  2533. (delete-region
  2534. beg (or (next-single-property-change beg 'org-filtered)
  2535. (point-max))))
  2536. (run-hooks 'org-agenda-before-write-hook)
  2537. (cond
  2538. ((org-bound-and-true-p org-mobile-creating-agendas)
  2539. (org-mobile-write-agenda-for-mobile file))
  2540. ((string-match "\\.html?\\'" file)
  2541. (require 'htmlize)
  2542. (set-buffer (htmlize-buffer (current-buffer)))
  2543. (when (and org-agenda-export-html-style
  2544. (string-match "<style>" org-agenda-export-html-style))
  2545. ;; replace <style> section with org-agenda-export-html-style
  2546. (goto-char (point-min))
  2547. (kill-region (- (search-forward "<style") 6)
  2548. (search-forward "</style>"))
  2549. (insert org-agenda-export-html-style))
  2550. (write-file file)
  2551. (kill-buffer (current-buffer))
  2552. (message "HTML written to %s" file))
  2553. ((string-match "\\.ps\\'" file)
  2554. (require 'ps-print)
  2555. (ps-print-buffer-with-faces file)
  2556. (message "Postscript written to %s" file))
  2557. ((string-match "\\.pdf\\'" file)
  2558. (require 'ps-print)
  2559. (ps-print-buffer-with-faces
  2560. (concat (file-name-sans-extension file) ".ps"))
  2561. (call-process "ps2pdf" nil nil nil
  2562. (expand-file-name
  2563. (concat (file-name-sans-extension file) ".ps"))
  2564. (expand-file-name file))
  2565. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2566. (message "PDF written to %s" file))
  2567. ((string-match "\\.ics\\'" file)
  2568. (require 'org-icalendar)
  2569. (let ((org-agenda-marker-table
  2570. (org-create-marker-find-array
  2571. (org-agenda-collect-markers)))
  2572. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2573. (org-combined-agenda-icalendar-file file))
  2574. (apply 'org-export-icalendar 'combine
  2575. (org-agenda-files nil 'ifmode))))
  2576. (t
  2577. (let ((bs (buffer-string)))
  2578. (find-file file)
  2579. (erase-buffer)
  2580. (insert bs)
  2581. (save-buffer 0)
  2582. (kill-buffer (current-buffer))
  2583. (message "Plain text written to %s" file))))))))
  2584. (set-buffer org-agenda-buffer-name))
  2585. (when open (org-open-file file)))
  2586. (defvar org-agenda-filter-overlays nil)
  2587. (defun org-agenda-mark-filtered-text ()
  2588. "Mark all text hidden by filtering with a text property."
  2589. (let ((inhibit-read-only t))
  2590. (mapc
  2591. (lambda (o)
  2592. (when (equal (overlay-buffer o) (current-buffer))
  2593. (put-text-property
  2594. (overlay-start o) (overlay-end o)
  2595. 'org-filtered t)))
  2596. org-agenda-filter-overlays)))
  2597. (defun org-agenda-unmark-filtered-text ()
  2598. "Remove the filtering text property."
  2599. (let ((inhibit-read-only t))
  2600. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2601. (defun org-agenda-remove-marked-text (property &optional value)
  2602. "Delete all text marked with VALUE of PROPERTY.
  2603. VALUE defaults to t."
  2604. (let (beg)
  2605. (setq value (or value t))
  2606. (while (setq beg (text-property-any (point-min) (point-max)
  2607. property value))
  2608. (delete-region
  2609. beg (or (next-single-property-change beg 'org-filtered)
  2610. (point-max))))))
  2611. (defun org-agenda-add-entry-text ()
  2612. "Add entry text to agenda lines.
  2613. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2614. entry text following headings shown in the agenda.
  2615. Drawers will be excluded, also the line with scheduling/deadline info."
  2616. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2617. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2618. (let (m txt)
  2619. (goto-char (point-min))
  2620. (while (not (eobp))
  2621. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2622. (beginning-of-line 2)
  2623. (setq txt (org-agenda-get-some-entry-text
  2624. m org-agenda-add-entry-text-maxlines " > "))
  2625. (end-of-line 1)
  2626. (if (string-match "\\S-" txt)
  2627. (insert "\n" txt)
  2628. (or (eobp) (forward-char 1))))))))
  2629. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2630. &rest keep)
  2631. "Extract entry text from MARKER, at most N-LINES lines.
  2632. This will ignore drawers etc, just get the text.
  2633. If INDENT is given, prefix every line with this string. If KEEP is
  2634. given, it is a list of symbols, defining stuff that should not be
  2635. removed from the entry content. Currently only `planning' is allowed here."
  2636. (let (txt drawer-re kwd-time-re ind)
  2637. (save-excursion
  2638. (with-current-buffer (marker-buffer marker)
  2639. (if (not (eq major-mode 'org-mode))
  2640. (setq txt "")
  2641. (save-excursion
  2642. (save-restriction
  2643. (widen)
  2644. (goto-char marker)
  2645. (end-of-line 1)
  2646. (setq txt (buffer-substring
  2647. (min (1+ (point)) (point-max))
  2648. (progn (outline-next-heading) (point)))
  2649. drawer-re org-drawer-regexp
  2650. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2651. ".*\n?"))
  2652. (with-temp-buffer
  2653. (insert txt)
  2654. (when org-agenda-add-entry-text-descriptive-links
  2655. (goto-char (point-min))
  2656. (while (org-activate-bracket-links (point-max))
  2657. (add-text-properties (match-beginning 0) (match-end 0)
  2658. '(face org-link))))
  2659. (goto-char (point-min))
  2660. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2661. (set-text-properties (match-beginning 0) (match-end 0)
  2662. nil))
  2663. (goto-char (point-min))
  2664. (while (re-search-forward drawer-re nil t)
  2665. (delete-region
  2666. (match-beginning 0)
  2667. (progn (re-search-forward
  2668. "^[ \t]*:END:.*\n?" nil 'move)
  2669. (point))))
  2670. (unless (member 'planning keep)
  2671. (goto-char (point-min))
  2672. (while (re-search-forward kwd-time-re nil t)
  2673. (replace-match "")))
  2674. (goto-char (point-min))
  2675. (when org-agenda-entry-text-exclude-regexps
  2676. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2677. (while (setq re (pop re-list))
  2678. (goto-char (point-min))
  2679. (while (re-search-forward re nil t)
  2680. (replace-match "")))))
  2681. (goto-char (point-max))
  2682. (skip-chars-backward " \t\n")
  2683. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2684. ;; find and remove min common indentation
  2685. (goto-char (point-min))
  2686. (untabify (point-min) (point-max))
  2687. (setq ind (org-get-indentation))
  2688. (while (not (eobp))
  2689. (unless (looking-at "[ \t]*$")
  2690. (setq ind (min ind (org-get-indentation))))
  2691. (beginning-of-line 2))
  2692. (goto-char (point-min))
  2693. (while (not (eobp))
  2694. (unless (looking-at "[ \t]*$")
  2695. (move-to-column ind)
  2696. (delete-region (point-at-bol) (point)))
  2697. (beginning-of-line 2))
  2698. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2699. (goto-char (point-min))
  2700. (when indent
  2701. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2702. (replace-match indent t t)))
  2703. (goto-char (point-min))
  2704. (while (looking-at "[ \t]*\n") (replace-match ""))
  2705. (goto-char (point-max))
  2706. (when (> (org-current-line)
  2707. n-lines)
  2708. (org-goto-line (1+ n-lines))
  2709. (backward-char 1))
  2710. (setq txt (buffer-substring (point-min) (point)))))))))
  2711. txt))
  2712. (defun org-agenda-collect-markers ()
  2713. "Collect the markers pointing to entries in the agenda buffer."
  2714. (let (m markers)
  2715. (save-excursion
  2716. (goto-char (point-min))
  2717. (while (not (eobp))
  2718. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2719. (org-get-at-bol 'org-marker)))
  2720. (push m markers))
  2721. (beginning-of-line 2)))
  2722. (nreverse markers)))
  2723. (defun org-create-marker-find-array (marker-list)
  2724. "Create a alist of files names with all marker positions in that file."
  2725. (let (f tbl m a p)
  2726. (while (setq m (pop marker-list))
  2727. (setq p (marker-position m)
  2728. f (buffer-file-name (or (buffer-base-buffer
  2729. (marker-buffer m))
  2730. (marker-buffer m))))
  2731. (if (setq a (assoc f tbl))
  2732. (push (marker-position m) (cdr a))
  2733. (push (list f p) tbl)))
  2734. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2735. tbl)))
  2736. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2737. (defun org-check-agenda-marker-table ()
  2738. "Check of the current entry is on the marker list."
  2739. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2740. a)
  2741. (and (setq a (assoc file org-agenda-marker-table))
  2742. (save-match-data
  2743. (save-excursion
  2744. (org-back-to-heading t)
  2745. (member (point) (cdr a)))))))
  2746. (defun org-check-for-org-mode ()
  2747. "Make sure current buffer is in org-mode. Error if not."
  2748. (or (eq major-mode 'org-mode)
  2749. (error "Cannot execute org-mode agenda command on buffer in %s"
  2750. major-mode)))
  2751. (defun org-fit-agenda-window ()
  2752. "Fit the window to the buffer size."
  2753. (and (memq org-agenda-window-setup '(reorganize-frame))
  2754. (fboundp 'fit-window-to-buffer)
  2755. (org-fit-window-to-buffer
  2756. nil
  2757. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2758. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2759. ;;; Agenda prepare and finalize
  2760. (defvar org-agenda-multi nil) ; dynamically scoped
  2761. (defvar org-agenda-buffer-name "*Org Agenda*")
  2762. (defvar org-pre-agenda-window-conf nil)
  2763. (defvar org-agenda-columns-active nil)
  2764. (defvar org-agenda-name nil)
  2765. (defvar org-agenda-filter nil)
  2766. (defvar org-agenda-filter-while-redo nil)
  2767. (defvar org-agenda-filter-preset nil
  2768. "A preset of the tags filter used for secondary agenda filtering.
  2769. This must be a list of strings, each string must be a single tag preceded
  2770. by \"+\" or \"-\".
  2771. This variable should not be set directly, but agenda custom commands can
  2772. bind it in the options section. The preset filter is a global property of
  2773. the entire agenda view. In a block agenda, it will not work reliably to
  2774. define a filter for one of the individual blocks. You need to set it in
  2775. the global options and expect it to be applied to the entire view.")
  2776. (defun org-prepare-agenda (&optional name)
  2777. (setq org-todo-keywords-for-agenda nil)
  2778. (setq org-done-keywords-for-agenda nil)
  2779. (setq org-drawers-for-agenda nil)
  2780. (unless org-agenda-persistent-filter
  2781. (setq org-agenda-filter nil))
  2782. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2783. (if org-agenda-multi
  2784. (progn
  2785. (setq buffer-read-only nil)
  2786. (goto-char (point-max))
  2787. (unless (or (bobp) org-agenda-compact-blocks
  2788. (not org-agenda-block-separator))
  2789. (insert "\n"
  2790. (if (stringp org-agenda-block-separator)
  2791. org-agenda-block-separator
  2792. (make-string (window-width) org-agenda-block-separator))
  2793. "\n"))
  2794. (narrow-to-region (point) (point-max)))
  2795. (org-agenda-reset-markers)
  2796. (setq org-agenda-contributing-files nil)
  2797. (setq org-agenda-columns-active nil)
  2798. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2799. (setq org-todo-keywords-for-agenda
  2800. (org-uniquify org-todo-keywords-for-agenda))
  2801. (setq org-done-keywords-for-agenda
  2802. (org-uniquify org-done-keywords-for-agenda))
  2803. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2804. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2805. (awin (get-buffer-window abuf)))
  2806. (cond
  2807. ((equal (current-buffer) abuf) nil)
  2808. (awin (select-window awin))
  2809. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2810. ((equal org-agenda-window-setup 'current-window)
  2811. (org-pop-to-buffer-same-window abuf))
  2812. ((equal org-agenda-window-setup 'other-window)
  2813. (org-switch-to-buffer-other-window abuf))
  2814. ((equal org-agenda-window-setup 'other-frame)
  2815. (switch-to-buffer-other-frame abuf))
  2816. ((equal org-agenda-window-setup 'reorganize-frame)
  2817. (delete-other-windows)
  2818. (org-switch-to-buffer-other-window abuf)))
  2819. ;; additional test in case agenda is invoked from within agenda
  2820. ;; buffer via elisp link
  2821. (unless (equal (current-buffer) abuf)
  2822. (org-pop-to-buffer-same-window abuf)))
  2823. (setq buffer-read-only nil)
  2824. (let ((inhibit-read-only t)) (erase-buffer))
  2825. (org-agenda-mode)
  2826. (and name (not org-agenda-name)
  2827. (org-set-local 'org-agenda-name name)))
  2828. (setq buffer-read-only nil))
  2829. (defun org-finalize-agenda ()
  2830. "Finishing touch for the agenda buffer, called just before displaying it."
  2831. (unless org-agenda-multi
  2832. (save-excursion
  2833. (let ((inhibit-read-only t))
  2834. (goto-char (point-min))
  2835. (while (org-activate-bracket-links (point-max))
  2836. (add-text-properties (match-beginning 0) (match-end 0)
  2837. '(face org-link)))
  2838. (org-agenda-align-tags)
  2839. (unless org-agenda-with-colors
  2840. (remove-text-properties (point-min) (point-max) '(face nil))))
  2841. (if (and (boundp 'org-agenda-overriding-columns-format)
  2842. org-agenda-overriding-columns-format)
  2843. (org-set-local 'org-agenda-overriding-columns-format
  2844. org-agenda-overriding-columns-format))
  2845. (if (and (boundp 'org-agenda-view-columns-initially)
  2846. org-agenda-view-columns-initially)
  2847. (org-agenda-columns))
  2848. (when org-agenda-fontify-priorities
  2849. (org-agenda-fontify-priorities))
  2850. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2851. (org-agenda-dim-blocked-tasks))
  2852. (org-agenda-mark-clocking-task)
  2853. (when org-agenda-entry-text-mode
  2854. (org-agenda-entry-text-hide)
  2855. (org-agenda-entry-text-show))
  2856. (if (functionp 'org-habit-insert-consistency-graphs)
  2857. (org-habit-insert-consistency-graphs))
  2858. (run-hooks 'org-finalize-agenda-hook)
  2859. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2860. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2861. (org-agenda-filter-apply org-agenda-filter))
  2862. )))
  2863. (defun org-agenda-mark-clocking-task ()
  2864. "Mark the current clock entry in the agenda if it is present."
  2865. (mapc (lambda (o)
  2866. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2867. (delete-overlay o)))
  2868. (overlays-in (point-min) (point-max)))
  2869. (when (marker-buffer org-clock-hd-marker)
  2870. (save-excursion
  2871. (goto-char (point-min))
  2872. (let (s ov)
  2873. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2874. (goto-char s)
  2875. (when (equal (org-get-at-bol 'org-hd-marker)
  2876. org-clock-hd-marker)
  2877. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2878. (overlay-put ov 'type 'org-agenda-clocking)
  2879. (overlay-put ov 'face 'org-agenda-clocking)
  2880. (overlay-put ov 'help-echo
  2881. "The clock is running in this item")))))))
  2882. (defun org-agenda-fontify-priorities ()
  2883. "Make highest priority lines bold, and lowest italic."
  2884. (interactive)
  2885. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2886. (delete-overlay o)))
  2887. (overlays-in (point-min) (point-max)))
  2888. (save-excursion
  2889. (let ((inhibit-read-only t)
  2890. b e p ov h l)
  2891. (goto-char (point-min))
  2892. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2893. (setq h (or (get-char-property (point) 'org-highest-priority)
  2894. org-highest-priority)
  2895. l (or (get-char-property (point) 'org-lowest-priority)
  2896. org-lowest-priority)
  2897. p (string-to-char (match-string 1))
  2898. b (match-beginning 0)
  2899. e (if (eq org-agenda-fontify-priorities 'cookies)
  2900. (match-end 0)
  2901. (point-at-eol))
  2902. ov (make-overlay b e))
  2903. (overlay-put
  2904. ov 'face
  2905. (cond ((org-face-from-face-or-color
  2906. 'priority nil
  2907. (cdr (assoc p org-priority-faces))))
  2908. ((and (listp org-agenda-fontify-priorities)
  2909. (org-face-from-face-or-color
  2910. 'priority nil
  2911. (cdr (assoc p org-agenda-fontify-priorities)))))
  2912. ((equal p l) 'italic)
  2913. ((equal p h) 'bold)))
  2914. (overlay-put ov 'org-type 'org-priority)))))
  2915. (defun org-agenda-dim-blocked-tasks ()
  2916. "Dim currently blocked TODO's in the agenda display."
  2917. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2918. (delete-overlay o)))
  2919. (overlays-in (point-min) (point-max)))
  2920. (save-excursion
  2921. (let ((inhibit-read-only t)
  2922. (org-depend-tag-blocked nil)
  2923. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2924. org-blocked-by-checkboxes
  2925. invis1 b e p ov h l)
  2926. (goto-char (point-min))
  2927. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2928. (and pos (goto-char (1+ pos))))
  2929. (setq org-blocked-by-checkboxes nil invis1 invis)
  2930. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2931. (when (and marker
  2932. (with-current-buffer (marker-buffer marker)
  2933. (save-excursion (goto-char marker)
  2934. (org-entry-blocked-p))))
  2935. (if org-blocked-by-checkboxes (setq invis1 nil))
  2936. (setq b (if invis1
  2937. (max (point-min) (1- (point-at-bol)))
  2938. (point-at-bol))
  2939. e (point-at-eol)
  2940. ov (make-overlay b e))
  2941. (if invis1
  2942. (overlay-put ov 'invisible t)
  2943. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2944. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2945. (defvar org-agenda-skip-function nil
  2946. "Function to be called at each match during agenda construction.
  2947. If this function returns nil, the current match should not be skipped.
  2948. Otherwise, the function must return a position from where the search
  2949. should be continued.
  2950. This may also be a Lisp form, it will be evaluated.
  2951. Never set this variable using `setq' or so, because then it will apply
  2952. to all future agenda commands. If you do want a global skipping condition,
  2953. use the option `org-agenda-skip-function-global' instead.
  2954. The correct usage for `org-agenda-skip-function' is to bind it with
  2955. `let' to scope it dynamically into the agenda-constructing command.
  2956. A good way to set it is through options in `org-agenda-custom-commands'.")
  2957. (defun org-agenda-skip ()
  2958. "Throw to `:skip' in places that should be skipped.
  2959. Also moves point to the end of the skipped region, so that search can
  2960. continue from there."
  2961. (let ((p (point-at-bol)) to)
  2962. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2963. (get-text-property p :org-archived)
  2964. (org-end-of-subtree t)
  2965. (throw :skip t))
  2966. (and org-agenda-skip-comment-trees
  2967. (get-text-property p :org-comment)
  2968. (org-end-of-subtree t)
  2969. (throw :skip t))
  2970. (if (equal (char-after p) ?#) (throw :skip t))
  2971. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2972. (org-agenda-skip-eval org-agenda-skip-function)))
  2973. (goto-char to)
  2974. (throw :skip t))))
  2975. (defun org-agenda-skip-eval (form)
  2976. "If FORM is a function or a list, call (or eval) is and return result.
  2977. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2978. and match data are returned to the previous state no matter what these
  2979. functions do."
  2980. (let (fp)
  2981. (and form
  2982. (or (setq fp (functionp form))
  2983. (consp form))
  2984. (save-excursion
  2985. (save-match-data
  2986. (if fp
  2987. (funcall form)
  2988. (eval form)))))))
  2989. (defvar org-agenda-markers nil
  2990. "List of all currently active markers created by `org-agenda'.")
  2991. (defvar org-agenda-last-marker-time (org-float-time)
  2992. "Creation time of the last agenda marker.")
  2993. (defun org-agenda-new-marker (&optional pos)
  2994. "Return a new agenda marker.
  2995. Org-mode keeps a list of these markers and resets them when they are
  2996. no longer in use."
  2997. (let ((m (copy-marker (or pos (point)))))
  2998. (setq org-agenda-last-marker-time (org-float-time))
  2999. (push m org-agenda-markers)
  3000. m))
  3001. (defun org-agenda-reset-markers ()
  3002. "Reset markers created by `org-agenda'."
  3003. (while org-agenda-markers
  3004. (move-marker (pop org-agenda-markers) nil)))
  3005. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3006. "Save relative positions of markers in region."
  3007. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3008. org-agenda-markers))
  3009. ;;; Entry text mode
  3010. (defun org-agenda-entry-text-show-here ()
  3011. "Add some text from the entry as context to the current line."
  3012. (let (m txt o)
  3013. (setq m (org-get-at-bol 'org-hd-marker))
  3014. (unless (marker-buffer m)
  3015. (error "No marker points to an entry here"))
  3016. (setq txt (concat "\n" (org-no-properties
  3017. (org-agenda-get-some-entry-text
  3018. m org-agenda-entry-text-maxlines " > "))))
  3019. (when (string-match "\\S-" txt)
  3020. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3021. (overlay-put o 'evaporate t)
  3022. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3023. (overlay-put o 'after-string txt))))
  3024. (defun org-agenda-entry-text-show ()
  3025. "Add entry context for all agenda lines."
  3026. (interactive)
  3027. (save-excursion
  3028. (goto-char (point-max))
  3029. (beginning-of-line 1)
  3030. (while (not (bobp))
  3031. (when (org-get-at-bol 'org-hd-marker)
  3032. (org-agenda-entry-text-show-here))
  3033. (beginning-of-line 0))))
  3034. (defun org-agenda-entry-text-hide ()
  3035. "Remove any shown entry context."
  3036. (delq nil
  3037. (mapcar (lambda (o)
  3038. (if (eq (overlay-get o 'org-overlay-type)
  3039. 'agenda-entry-content)
  3040. (progn (delete-overlay o) t)))
  3041. (overlays-in (point-min) (point-max)))))
  3042. (defun org-agenda-get-day-face (date)
  3043. "Return the face DATE should be displayed with."
  3044. (or (and (functionp org-agenda-day-face-function)
  3045. (funcall org-agenda-day-face-function date))
  3046. (cond ((org-agenda-todayp date)
  3047. 'org-agenda-date-today)
  3048. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3049. 'org-agenda-date-weekend)
  3050. (t 'org-agenda-date))))
  3051. ;;; Agenda timeline
  3052. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3053. (defun org-timeline (&optional dotodo)
  3054. "Show a time-sorted view of the entries in the current org file.
  3055. Only entries with a time stamp of today or later will be listed. With
  3056. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3057. under the current date.
  3058. If the buffer contains an active region, only check the region for
  3059. dates."
  3060. (interactive "P")
  3061. (org-compile-prefix-format 'timeline)
  3062. (org-set-sorting-strategy 'timeline)
  3063. (let* ((dopast t)
  3064. (doclosed org-agenda-show-log)
  3065. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3066. (current-buffer))))
  3067. (date (calendar-current-date))
  3068. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3069. (end (if (org-region-active-p) (region-end) (point-max)))
  3070. (day-numbers (org-get-all-dates beg end 'no-ranges
  3071. t doclosed ; always include today
  3072. org-timeline-show-empty-dates))
  3073. (org-deadline-warning-days 0)
  3074. (org-agenda-only-exact-dates t)
  3075. (today (org-today))
  3076. (past t)
  3077. args
  3078. s e rtn d emptyp)
  3079. (setq org-agenda-redo-command
  3080. (list 'progn
  3081. (list 'org-switch-to-buffer-other-window (current-buffer))
  3082. (list 'org-timeline (list 'quote dotodo))))
  3083. (if (not dopast)
  3084. ;; Remove past dates from the list of dates.
  3085. (setq day-numbers (delq nil (mapcar (lambda(x)
  3086. (if (>= x today) x nil))
  3087. day-numbers))))
  3088. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3089. (if doclosed (push :closed args))
  3090. (push :timestamp args)
  3091. (push :deadline args)
  3092. (push :scheduled args)
  3093. (push :sexp args)
  3094. (if dotodo (push :todo args))
  3095. (insert "Timeline of file " entry "\n")
  3096. (add-text-properties (point-min) (point)
  3097. (list 'face 'org-agenda-structure))
  3098. (org-agenda-mark-header-line (point-min))
  3099. (while (setq d (pop day-numbers))
  3100. (if (and (listp d) (eq (car d) :omitted))
  3101. (progn
  3102. (setq s (point))
  3103. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3104. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3105. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3106. (if (and (>= d today)
  3107. dopast
  3108. past)
  3109. (progn
  3110. (setq past nil)
  3111. (insert (make-string 79 ?-) "\n")))
  3112. (setq date (calendar-gregorian-from-absolute d))
  3113. (setq s (point))
  3114. (setq rtn (and (not emptyp)
  3115. (apply 'org-agenda-get-day-entries entry
  3116. date args)))
  3117. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3118. (progn
  3119. (insert
  3120. (if (stringp org-agenda-format-date)
  3121. (format-time-string org-agenda-format-date
  3122. (org-time-from-absolute date))
  3123. (funcall org-agenda-format-date date))
  3124. "\n")
  3125. (put-text-property s (1- (point)) 'face
  3126. (org-agenda-get-day-face date))
  3127. (put-text-property s (1- (point)) 'org-date-line t)
  3128. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3129. (if (equal d today)
  3130. (put-text-property s (1- (point)) 'org-today t))
  3131. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3132. (put-text-property s (1- (point)) 'day d)))))
  3133. (goto-char (point-min))
  3134. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3135. (point-min)))
  3136. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3137. (org-finalize-agenda)
  3138. (setq buffer-read-only t)))
  3139. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3140. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3141. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3142. not every single day in the range. If FORCE-TODAY is non-nil, make
  3143. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3144. inactive time stamps (those in square brackets) are included.
  3145. When EMPTY is non-nil, also include days without any entries."
  3146. (let ((re (concat
  3147. (if pre-re pre-re "")
  3148. (if inactive org-ts-regexp-both org-ts-regexp)))
  3149. dates dates1 date day day1 day2 ts1 ts2 pos)
  3150. (if force-today
  3151. (setq dates (list (org-today))))
  3152. (save-excursion
  3153. (goto-char beg)
  3154. (while (re-search-forward re end t)
  3155. (setq day (time-to-days (org-time-string-to-time
  3156. (substring (match-string 1) 0 10)
  3157. (current-buffer) (match-beginning 0))))
  3158. (or (memq day dates) (push day dates)))
  3159. (unless no-ranges
  3160. (goto-char beg)
  3161. (while (re-search-forward org-tr-regexp end t)
  3162. (setq pos (match-beginning 0))
  3163. (setq ts1 (substring (match-string 1) 0 10)
  3164. ts2 (substring (match-string 2) 0 10)
  3165. day1 (time-to-days (org-time-string-to-time
  3166. ts1 (current-buffer) pos))
  3167. day2 (time-to-days (org-time-string-to-time
  3168. ts2 (current-buffer) pos)))
  3169. (while (< (setq day1 (1+ day1)) day2)
  3170. (or (memq day1 dates) (push day1 dates)))))
  3171. (setq dates (sort dates '<))
  3172. (when empty
  3173. (while (setq day (pop dates))
  3174. (setq day2 (car dates))
  3175. (push day dates1)
  3176. (when (and day2 empty)
  3177. (if (or (eq empty t)
  3178. (and (numberp empty) (<= (- day2 day) empty)))
  3179. (while (< (setq day (1+ day)) day2)
  3180. (push (list day) dates1))
  3181. (push (cons :omitted (- day2 day)) dates1))))
  3182. (setq dates (nreverse dates1)))
  3183. dates)))
  3184. ;;; Agenda Daily/Weekly
  3185. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3186. "Start day for the agenda view.
  3187. Custom commands can set this variable in the options section.")
  3188. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3189. (defvar org-agenda-current-span nil
  3190. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3191. (defvar org-arg-loc nil) ; local variable
  3192. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3193. "List of types searched for when creating the daily/weekly agenda.
  3194. This variable is a list of symbols that controls the types of
  3195. items that appear in the daily/weekly agenda. Allowed symbols in this
  3196. list are are
  3197. :timestamp List items containing a date stamp or date range matching
  3198. the selected date. This includes sexp entries in
  3199. angular brackets.
  3200. :sexp List entries resulting from plain diary-like sexps.
  3201. :deadline List deadline due on that date. When the date is today,
  3202. also list any deadlines past due, or due within
  3203. `org-deadline-warning-days'. `:deadline' must appear before
  3204. `:scheduled' if the setting of
  3205. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3206. any effect.
  3207. :scheduled List all items which are scheduled for the given date.
  3208. The diary for *today* also contains items which were
  3209. scheduled earlier and are not yet marked DONE.
  3210. By default, all four types are turned on.
  3211. Never set this variable globally using `setq', because then it
  3212. will apply to all future agenda commands. Instead, bind it with
  3213. `let' to scope it dynamically into the agenda-constructing
  3214. command. A good way to set it is through options in
  3215. `org-agenda-custom-commands'. For a more flexible (though
  3216. somewhat less efficient) way of determining what is included in
  3217. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3218. ;;;###autoload
  3219. (defun org-agenda-list (&optional arg start-day span)
  3220. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3221. The view will be for the current day or week, but from the overview buffer
  3222. you will be able to go to other days/weeks.
  3223. With a numeric prefix argument in an interactive call, the agenda will
  3224. span ARG days. Lisp programs should instead specify SPAN to change
  3225. the number of days. SPAN defaults to `org-agenda-span'.
  3226. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3227. given in `org-agenda-start-on-weekday'."
  3228. (interactive "P")
  3229. (if (and (integerp arg) (> arg 0))
  3230. (setq span arg arg nil))
  3231. (setq start-day (or start-day org-agenda-start-day))
  3232. (if org-agenda-overriding-arguments
  3233. (setq arg (car org-agenda-overriding-arguments)
  3234. start-day (nth 1 org-agenda-overriding-arguments)
  3235. span (nth 2 org-agenda-overriding-arguments)))
  3236. (if (stringp start-day)
  3237. ;; Convert to an absolute day number
  3238. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3239. (setq org-agenda-last-arguments (list arg start-day span))
  3240. (org-compile-prefix-format 'agenda)
  3241. (org-set-sorting-strategy 'agenda)
  3242. (let* ((span (org-agenda-ndays-to-span
  3243. (or span org-agenda-ndays org-agenda-span)))
  3244. (today (org-today))
  3245. (sd (or start-day today))
  3246. (ndays (org-agenda-span-to-ndays span sd))
  3247. (org-agenda-start-on-weekday
  3248. (if (eq ndays 7)
  3249. org-agenda-start-on-weekday))
  3250. (thefiles (org-agenda-files nil 'ifmode))
  3251. (files thefiles)
  3252. (start (if (or (null org-agenda-start-on-weekday)
  3253. (< ndays 7))
  3254. sd
  3255. (let* ((nt (calendar-day-of-week
  3256. (calendar-gregorian-from-absolute sd)))
  3257. (n1 org-agenda-start-on-weekday)
  3258. (d (- nt n1)))
  3259. (- sd (+ (if (< d 0) 7 0) d)))))
  3260. (day-numbers (list start))
  3261. (day-cnt 0)
  3262. (inhibit-redisplay (not debug-on-error))
  3263. s e rtn rtnall file date d start-pos end-pos todayp
  3264. clocktable-start clocktable-end filter)
  3265. (setq org-agenda-redo-command
  3266. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3267. (dotimes (n (1- ndays))
  3268. (push (1+ (car day-numbers)) day-numbers))
  3269. (setq day-numbers (nreverse day-numbers))
  3270. (setq clocktable-start (car day-numbers)
  3271. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3272. (org-prepare-agenda "Day/Week")
  3273. (org-set-local 'org-starting-day (car day-numbers))
  3274. (org-set-local 'org-arg-loc arg)
  3275. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3276. (unless org-agenda-compact-blocks
  3277. (let* ((d1 (car day-numbers))
  3278. (d2 (org-last day-numbers))
  3279. (w1 (org-days-to-iso-week d1))
  3280. (w2 (org-days-to-iso-week d2)))
  3281. (setq s (point))
  3282. (if org-agenda-overriding-header
  3283. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3284. nil 'face 'org-agenda-structure) "\n")
  3285. (insert (org-agenda-span-name span)
  3286. "-agenda"
  3287. (if (< (- d2 d1) 350)
  3288. (if (= w1 w2)
  3289. (format " (W%02d)" w1)
  3290. (format " (W%02d-W%02d)" w1 w2))
  3291. "")
  3292. ":\n")))
  3293. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3294. 'org-date-line t))
  3295. (org-agenda-mark-header-line s))
  3296. (while (setq d (pop day-numbers))
  3297. (setq date (calendar-gregorian-from-absolute d)
  3298. s (point))
  3299. (if (or (setq todayp (= d today))
  3300. (and (not start-pos) (= d sd)))
  3301. (setq start-pos (point))
  3302. (if (and start-pos (not end-pos))
  3303. (setq end-pos (point))))
  3304. (setq files thefiles
  3305. rtnall nil)
  3306. (while (setq file (pop files))
  3307. (catch 'nextfile
  3308. (org-check-agenda-file file)
  3309. (let ((org-agenda-entry-types org-agenda-entry-types))
  3310. (unless org-agenda-include-deadlines
  3311. (setq org-agenda-entry-types
  3312. (delq :deadline org-agenda-entry-types)))
  3313. (cond
  3314. ((memq org-agenda-show-log '(only clockcheck))
  3315. (setq rtn (org-agenda-get-day-entries
  3316. file date :closed)))
  3317. (org-agenda-show-log
  3318. (setq rtn (apply 'org-agenda-get-day-entries
  3319. file date
  3320. (append '(:closed) org-agenda-entry-types))))
  3321. (t
  3322. (setq rtn (apply 'org-agenda-get-day-entries
  3323. file date
  3324. org-agenda-entry-types)))))
  3325. (setq rtnall (append rtnall rtn))))
  3326. (if org-agenda-include-diary
  3327. (let ((org-agenda-search-headline-for-time t))
  3328. (require 'diary-lib)
  3329. (setq rtn (org-get-entries-from-diary date))
  3330. (setq rtnall (append rtnall rtn))))
  3331. (if (or rtnall org-agenda-show-all-dates)
  3332. (progn
  3333. (setq day-cnt (1+ day-cnt))
  3334. (insert
  3335. (if (stringp org-agenda-format-date)
  3336. (format-time-string org-agenda-format-date
  3337. (org-time-from-absolute date))
  3338. (funcall org-agenda-format-date date))
  3339. "\n")
  3340. (put-text-property s (1- (point)) 'face
  3341. (org-agenda-get-day-face date))
  3342. (put-text-property s (1- (point)) 'org-date-line t)
  3343. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3344. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3345. (when todayp
  3346. (put-text-property s (1- (point)) 'org-today t))
  3347. (if rtnall (insert
  3348. (org-finalize-agenda-entries
  3349. (org-agenda-add-time-grid-maybe
  3350. rtnall ndays todayp))
  3351. "\n"))
  3352. (put-text-property s (1- (point)) 'day d)
  3353. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3354. (when (and org-agenda-clockreport-mode clocktable-start)
  3355. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3356. ;; the above line is to ensure the restricted range!
  3357. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3358. tbl)
  3359. (setq p (org-plist-delete p :block))
  3360. (setq p (plist-put p :tstart clocktable-start))
  3361. (setq p (plist-put p :tend clocktable-end))
  3362. (setq p (plist-put p :scope 'agenda))
  3363. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3364. (setq filter (or org-agenda-filter-while-redo
  3365. (get 'org-agenda-filter :preset-filter))))
  3366. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3367. (if (string-match "[<>=]" x)
  3368. ""
  3369. x))
  3370. filter ""))))
  3371. (setq tbl (apply 'org-get-clocktable p))
  3372. (insert tbl)))
  3373. (goto-char (point-min))
  3374. (or org-agenda-multi (org-fit-agenda-window))
  3375. (unless (and (pos-visible-in-window-p (point-min))
  3376. (pos-visible-in-window-p (point-max)))
  3377. (goto-char (1- (point-max)))
  3378. (recenter -1)
  3379. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3380. (progn
  3381. (goto-char (or start-pos 1))
  3382. (recenter 1))))
  3383. (goto-char (or start-pos 1))
  3384. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3385. (if (eq org-agenda-show-log 'clockcheck)
  3386. (org-agenda-show-clocking-issues))
  3387. (org-finalize-agenda)
  3388. (setq buffer-read-only t)
  3389. (message "")))
  3390. (defun org-agenda-ndays-to-span (n)
  3391. "Return a span symbol for a span of N days, or N if none matches."
  3392. (cond ((symbolp n) n)
  3393. ((= n 1) 'day)
  3394. ((= n 7) 'week)
  3395. (t n)))
  3396. (defun org-agenda-span-to-ndays (span start-day)
  3397. "Return ndays from SPAN starting at START-DAY."
  3398. (cond ((numberp span) span)
  3399. ((eq span 'day) 1)
  3400. ((eq span 'week) 7)
  3401. ((eq span 'month)
  3402. (let ((date (calendar-gregorian-from-absolute start-day)))
  3403. (calendar-last-day-of-month (car date) (caddr date))))
  3404. ((eq span 'year)
  3405. (let ((date (calendar-gregorian-from-absolute start-day)))
  3406. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3407. (defun org-agenda-span-name (span)
  3408. "Return a SPAN name."
  3409. (if (null span)
  3410. ""
  3411. (if (symbolp span)
  3412. (capitalize (symbol-name span))
  3413. (format "%d days" span))))
  3414. ;;; Agenda word search
  3415. (defvar org-agenda-search-history nil)
  3416. (defvar org-todo-only nil)
  3417. (defvar org-search-syntax-table nil
  3418. "Special syntax table for org-mode search.
  3419. In this table, we have single quotes not as word constituents, to
  3420. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3421. (defun org-search-syntax-table ()
  3422. (unless org-search-syntax-table
  3423. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3424. (modify-syntax-entry ?' "." org-search-syntax-table)
  3425. (modify-syntax-entry ?` "." org-search-syntax-table))
  3426. org-search-syntax-table)
  3427. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3428. ;;;###autoload
  3429. (defun org-search-view (&optional todo-only string edit-at)
  3430. "Show all entries that contain a phrase or words or regular expressions.
  3431. With optional prefix argument TODO-ONLY, only consider entries that are
  3432. TODO entries. The argument STRING can be used to pass a default search
  3433. string into this function. If EDIT-AT is non-nil, it means that the
  3434. user should get a chance to edit this string, with cursor at position
  3435. EDIT-AT.
  3436. The search string can be viewed either as a phrase that should be found as
  3437. is, or it can be broken into a number of snippets, each of which must match
  3438. in a Boolean way to select an entry. The default depends on the variable
  3439. `org-agenda-search-view-always-boolean'.
  3440. Even if this is turned off (the default) you can always switch to
  3441. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3442. The default is a direct search of the whole phrase, where each space in
  3443. the search string can expand to an arbitrary amount of whitespace,
  3444. including newlines.
  3445. If using a Boolean search, the search string is split on whitespace and
  3446. each snippet is searched separately, with logical AND to select an entry.
  3447. Words prefixed with a minus must *not* occur in the entry. Words without
  3448. a prefix or prefixed with a plus must occur in the entry. Matching is
  3449. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3450. match whole words, not parts of a word) if
  3451. `org-agenda-search-view-force-full-words' is set (default is nil).
  3452. Boolean search snippets enclosed by curly braces are interpreted as
  3453. regular expressions that must or (when preceded with \"-\") must not
  3454. match in the entry. Snippets enclosed into double quotes will be taken
  3455. as a whole, to include whitespace.
  3456. - If the search string starts with an asterisk, search only in headlines.
  3457. - If (possibly after the leading star) the search string starts with an
  3458. exclamation mark, this also means to look at TODO entries only, an effect
  3459. that can also be achieved with a prefix argument.
  3460. - If (possibly after star and exclamation mark) the search string starts
  3461. with a colon, this will mean that the (non-regexp) snippets of the
  3462. Boolean search must match as full words.
  3463. This command searches the agenda files, and in addition the files listed
  3464. in `org-agenda-text-search-extra-files'."
  3465. (interactive "P")
  3466. (org-compile-prefix-format 'search)
  3467. (org-set-sorting-strategy 'search)
  3468. (org-prepare-agenda "SEARCH")
  3469. (let* ((props (list 'face nil
  3470. 'done-face 'org-agenda-done
  3471. 'org-not-done-regexp org-not-done-regexp
  3472. 'org-todo-regexp org-todo-regexp
  3473. 'org-complex-heading-regexp org-complex-heading-regexp
  3474. 'mouse-face 'highlight
  3475. 'help-echo (format "mouse-2 or RET jump to location")))
  3476. (full-words org-agenda-search-view-force-full-words)
  3477. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3478. regexp rtn rtnall files file pos
  3479. marker category category-pos tags c neg re boolean
  3480. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3481. (unless (and (not edit-at)
  3482. (stringp string)
  3483. (string-match "\\S-" string))
  3484. (setq string (read-string
  3485. (if org-agenda-search-view-always-boolean
  3486. "[+-]Word/{Regexp} ...: "
  3487. "Phrase, or [+-]Word/{Regexp} ...: ")
  3488. (cond
  3489. ((integerp edit-at) (cons string edit-at))
  3490. (edit-at string))
  3491. 'org-agenda-search-history)))
  3492. (org-set-local 'org-todo-only todo-only)
  3493. (setq org-agenda-redo-command
  3494. (list 'org-search-view (if todo-only t nil) string
  3495. '(if current-prefix-arg 1 nil)))
  3496. (setq org-agenda-query-string string)
  3497. (if (equal (string-to-char string) ?*)
  3498. (setq hdl-only t
  3499. words (substring string 1))
  3500. (setq words string))
  3501. (when (equal (string-to-char words) ?!)
  3502. (setq todo-only t
  3503. words (substring words 1)))
  3504. (when (equal (string-to-char words) ?:)
  3505. (setq full-words t
  3506. words (substring words 1)))
  3507. (if (or org-agenda-search-view-always-boolean
  3508. (member (string-to-char words) '(?- ?+ ?\{)))
  3509. (setq boolean t))
  3510. (setq words (org-split-string words))
  3511. (let (www w)
  3512. (while (setq w (pop words))
  3513. (while (and (string-match "\\\\\\'" w) words)
  3514. (setq w (concat (substring w 0 -1) " " (pop words))))
  3515. (push w www))
  3516. (setq words (nreverse www) www nil)
  3517. (while (setq w (pop words))
  3518. (when (and (string-match "\\`[-+]?{" w)
  3519. (not (string-match "}\\'" w)))
  3520. (while (and words (not (string-match "}\\'" (car words))))
  3521. (setq w (concat w " " (pop words))))
  3522. (setq w (concat w " " (pop words))))
  3523. (push w www))
  3524. (setq words (nreverse www)))
  3525. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3526. (when boolean
  3527. (let (wds w)
  3528. (while (setq w (pop words))
  3529. (if (or (equal (substring w 0 1) "\"")
  3530. (and (> (length w) 1)
  3531. (member (substring w 0 1) '("+" "-"))
  3532. (equal (substring w 1 2) "\"")))
  3533. (while (and words (not (equal (substring w -1) "\"")))
  3534. (setq w (concat w " " (pop words)))))
  3535. (and (string-match "\\`\\([-+]?\\)\"" w)
  3536. (setq w (replace-match "\\1" nil nil w)))
  3537. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3538. (push w wds))
  3539. (setq words (nreverse wds))))
  3540. (if boolean
  3541. (mapc (lambda (w)
  3542. (setq c (string-to-char w))
  3543. (if (equal c ?-)
  3544. (setq neg t w (substring w 1))
  3545. (if (equal c ?+)
  3546. (setq neg nil w (substring w 1))
  3547. (setq neg nil)))
  3548. (if (string-match "\\`{.*}\\'" w)
  3549. (setq re (substring w 1 -1))
  3550. (if full-words
  3551. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3552. (setq re (regexp-quote (downcase w)))))
  3553. (if neg (push re regexps-) (push re regexps+)))
  3554. words)
  3555. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3556. regexps+))
  3557. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3558. (if (not regexps+)
  3559. (setq regexp org-outline-regexp-bol)
  3560. (setq regexp (pop regexps+))
  3561. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3562. regexp))))
  3563. (setq files (org-agenda-files nil 'ifmode))
  3564. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3565. (pop org-agenda-text-search-extra-files)
  3566. (setq files (org-add-archive-files files)))
  3567. (setq files (append files org-agenda-text-search-extra-files)
  3568. rtnall nil)
  3569. (while (setq file (pop files))
  3570. (setq ee nil)
  3571. (catch 'nextfile
  3572. (org-check-agenda-file file)
  3573. (setq buffer (if (file-exists-p file)
  3574. (org-get-agenda-file-buffer file)
  3575. (error "No such file %s" file)))
  3576. (if (not buffer)
  3577. ;; If file does not exist, make sure an error message is sent
  3578. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3579. file))))
  3580. (with-current-buffer buffer
  3581. (with-syntax-table (org-search-syntax-table)
  3582. (unless (eq major-mode 'org-mode)
  3583. (error "Agenda file %s is not in `org-mode'" file))
  3584. (let ((case-fold-search t))
  3585. (save-excursion
  3586. (save-restriction
  3587. (if org-agenda-restrict
  3588. (narrow-to-region org-agenda-restrict-begin
  3589. org-agenda-restrict-end)
  3590. (widen))
  3591. (goto-char (point-min))
  3592. (unless (or (org-on-heading-p)
  3593. (outline-next-heading))
  3594. (throw 'nextfile t))
  3595. (goto-char (max (point-min) (1- (point))))
  3596. (while (re-search-forward regexp nil t)
  3597. (org-back-to-heading t)
  3598. (skip-chars-forward "* ")
  3599. (setq beg (point-at-bol)
  3600. beg1 (point)
  3601. end (progn (outline-next-heading) (point)))
  3602. (catch :skip
  3603. (goto-char beg)
  3604. (org-agenda-skip)
  3605. (setq str (buffer-substring-no-properties
  3606. (point-at-bol)
  3607. (if hdl-only (point-at-eol) end)))
  3608. (mapc (lambda (wr) (when (string-match wr str)
  3609. (goto-char (1- end))
  3610. (throw :skip t)))
  3611. regexps-)
  3612. (mapc (lambda (wr) (unless (string-match wr str)
  3613. (goto-char (1- end))
  3614. (throw :skip t)))
  3615. (if todo-only
  3616. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3617. regexps+)
  3618. regexps+))
  3619. (goto-char beg)
  3620. (setq marker (org-agenda-new-marker (point))
  3621. category (org-get-category)
  3622. category-pos (get-text-property (point) 'org-category-position)
  3623. tags (org-get-tags-at (point))
  3624. txt (org-format-agenda-item
  3625. ""
  3626. (buffer-substring-no-properties
  3627. beg1 (point-at-eol))
  3628. category tags))
  3629. (org-add-props txt props
  3630. 'org-marker marker 'org-hd-marker marker
  3631. 'org-todo-regexp org-todo-regexp
  3632. 'org-complex-heading-regexp org-complex-heading-regexp
  3633. 'priority 1000 'org-category category
  3634. 'org-category-position category-pos
  3635. 'type "search")
  3636. (push txt ee)
  3637. (goto-char (1- end))))))))))
  3638. (setq rtn (nreverse ee))
  3639. (setq rtnall (append rtnall rtn)))
  3640. (if org-agenda-overriding-header
  3641. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3642. nil 'face 'org-agenda-structure) "\n")
  3643. (insert "Search words: ")
  3644. (add-text-properties (point-min) (1- (point))
  3645. (list 'face 'org-agenda-structure))
  3646. (setq pos (point))
  3647. (insert string "\n")
  3648. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3649. (setq pos (point))
  3650. (unless org-agenda-multi
  3651. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3652. (add-text-properties pos (1- (point))
  3653. (list 'face 'org-agenda-structure))))
  3654. (org-agenda-mark-header-line (point-min))
  3655. (when rtnall
  3656. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3657. (goto-char (point-min))
  3658. (or org-agenda-multi (org-fit-agenda-window))
  3659. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3660. (org-finalize-agenda)
  3661. (setq buffer-read-only t)))
  3662. ;;; Agenda TODO list
  3663. (defvar org-select-this-todo-keyword nil)
  3664. (defvar org-last-arg nil)
  3665. ;;;###autoload
  3666. (defun org-todo-list (arg)
  3667. "Show all (not done) TODO entries from all agenda file in a single list.
  3668. The prefix arg can be used to select a specific TODO keyword and limit
  3669. the list to these. When using \\[universal-argument], you will be prompted
  3670. for a keyword. A numeric prefix directly selects the Nth keyword in
  3671. `org-todo-keywords-1'."
  3672. (interactive "P")
  3673. (org-compile-prefix-format 'todo)
  3674. (org-set-sorting-strategy 'todo)
  3675. (org-prepare-agenda "TODO")
  3676. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3677. (let* ((today (org-today))
  3678. (date (calendar-gregorian-from-absolute today))
  3679. (kwds org-todo-keywords-for-agenda)
  3680. (completion-ignore-case t)
  3681. (org-select-this-todo-keyword
  3682. (if (stringp arg) arg
  3683. (and arg (integerp arg) (> arg 0)
  3684. (nth (1- arg) kwds))))
  3685. rtn rtnall files file pos)
  3686. (when (equal arg '(4))
  3687. (setq org-select-this-todo-keyword
  3688. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3689. (mapcar 'list kwds) nil nil)))
  3690. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3691. (org-set-local 'org-last-arg arg)
  3692. (setq org-agenda-redo-command
  3693. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3694. (setq files (org-agenda-files nil 'ifmode)
  3695. rtnall nil)
  3696. (while (setq file (pop files))
  3697. (catch 'nextfile
  3698. (org-check-agenda-file file)
  3699. (setq rtn (org-agenda-get-day-entries file date :todo))
  3700. (setq rtnall (append rtnall rtn))))
  3701. (if org-agenda-overriding-header
  3702. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3703. nil 'face 'org-agenda-structure) "\n")
  3704. (insert "Global list of TODO items of type: ")
  3705. (add-text-properties (point-min) (1- (point))
  3706. (list 'face 'org-agenda-structure
  3707. 'short-heading
  3708. (concat "ToDo: "
  3709. (or org-select-this-todo-keyword "ALL"))))
  3710. (org-agenda-mark-header-line (point-min))
  3711. (setq pos (point))
  3712. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3713. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3714. (setq pos (point))
  3715. (unless org-agenda-multi
  3716. (insert "Available with `N r': (0)ALL")
  3717. (let ((n 0) s)
  3718. (mapc (lambda (x)
  3719. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3720. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3721. (insert "\n "))
  3722. (insert " " s))
  3723. kwds))
  3724. (insert "\n"))
  3725. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3726. (org-agenda-mark-header-line (point-min))
  3727. (when rtnall
  3728. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3729. (goto-char (point-min))
  3730. (or org-agenda-multi (org-fit-agenda-window))
  3731. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3732. (org-finalize-agenda)
  3733. (setq buffer-read-only t)))
  3734. ;;; Agenda tags match
  3735. ;;;###autoload
  3736. (defun org-tags-view (&optional todo-only match)
  3737. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3738. The prefix arg TODO-ONLY limits the search to TODO entries."
  3739. (interactive "P")
  3740. (org-compile-prefix-format 'tags)
  3741. (org-set-sorting-strategy 'tags)
  3742. (let* ((org-tags-match-list-sublevels
  3743. org-tags-match-list-sublevels)
  3744. (completion-ignore-case t)
  3745. rtn rtnall files file pos matcher
  3746. buffer)
  3747. (when (and (stringp match) (not (string-match "\\S-" match)))
  3748. (setq match nil))
  3749. (setq matcher (org-make-tags-matcher match)
  3750. match (car matcher) matcher (cdr matcher))
  3751. (org-prepare-agenda (concat "TAGS " match))
  3752. (setq org-agenda-query-string match)
  3753. (setq org-agenda-redo-command
  3754. (list 'org-tags-view (list 'quote todo-only)
  3755. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3756. (setq files (org-agenda-files nil 'ifmode)
  3757. rtnall nil)
  3758. (while (setq file (pop files))
  3759. (catch 'nextfile
  3760. (org-check-agenda-file file)
  3761. (setq buffer (if (file-exists-p file)
  3762. (org-get-agenda-file-buffer file)
  3763. (error "No such file %s" file)))
  3764. (if (not buffer)
  3765. ;; If file does not exist, error message to agenda
  3766. (setq rtn (list
  3767. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3768. rtnall (append rtnall rtn))
  3769. (with-current-buffer buffer
  3770. (unless (eq major-mode 'org-mode)
  3771. (error "Agenda file %s is not in `org-mode'" file))
  3772. (save-excursion
  3773. (save-restriction
  3774. (if org-agenda-restrict
  3775. (narrow-to-region org-agenda-restrict-begin
  3776. org-agenda-restrict-end)
  3777. (widen))
  3778. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3779. (setq rtnall (append rtnall rtn))))))))
  3780. (if org-agenda-overriding-header
  3781. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3782. nil 'face 'org-agenda-structure) "\n")
  3783. (insert "Headlines with TAGS match: ")
  3784. (add-text-properties (point-min) (1- (point))
  3785. (list 'face 'org-agenda-structure
  3786. 'short-heading
  3787. (concat "Match: " match)))
  3788. (setq pos (point))
  3789. (insert match "\n")
  3790. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3791. (setq pos (point))
  3792. (unless org-agenda-multi
  3793. (insert "Press `C-u r' to search again with new search string\n"))
  3794. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3795. (org-agenda-mark-header-line (point-min))
  3796. (when rtnall
  3797. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3798. (goto-char (point-min))
  3799. (or org-agenda-multi (org-fit-agenda-window))
  3800. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3801. (org-finalize-agenda)
  3802. (setq buffer-read-only t)))
  3803. ;;; Agenda Finding stuck projects
  3804. (defvar org-agenda-skip-regexp nil
  3805. "Regular expression used in skipping subtrees for the agenda.
  3806. This is basically a temporary global variable that can be set and then
  3807. used by user-defined selections using `org-agenda-skip-function'.")
  3808. (defvar org-agenda-overriding-header nil
  3809. "When set during agenda, todo and tags searches it replaces the header.
  3810. This variable should not be set directly, but custom commands can bind it
  3811. in the options section.")
  3812. (defun org-agenda-skip-entry-when-regexp-matches ()
  3813. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3814. If yes, it returns the end position of this entry, causing agenda commands
  3815. to skip the entry but continuing the search in the subtree. This is a
  3816. function that can be put into `org-agenda-skip-function' for the duration
  3817. of a command."
  3818. (let ((end (save-excursion (org-end-of-subtree t)))
  3819. skip)
  3820. (save-excursion
  3821. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3822. (and skip end)))
  3823. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3824. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3825. If yes, it returns the end position of this tree, causing agenda commands
  3826. to skip this subtree. This is a function that can be put into
  3827. `org-agenda-skip-function' for the duration of a command."
  3828. (let ((end (save-excursion (org-end-of-subtree t)))
  3829. skip)
  3830. (save-excursion
  3831. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3832. (and skip end)))
  3833. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3834. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3835. If yes, it returns the end position of the current entry (NOT the tree),
  3836. causing agenda commands to skip the entry but continuing the search in
  3837. the subtree. This is a function that can be put into
  3838. `org-agenda-skip-function' for the duration of a command. An important
  3839. use of this function is for the stuck project list."
  3840. (let ((end (save-excursion (org-end-of-subtree t)))
  3841. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3842. skip)
  3843. (save-excursion
  3844. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3845. (and skip entry-end)))
  3846. (defun org-agenda-skip-entry-if (&rest conditions)
  3847. "Skip entry if any of CONDITIONS is true.
  3848. See `org-agenda-skip-if' for details."
  3849. (org-agenda-skip-if nil conditions))
  3850. (defun org-agenda-skip-subtree-if (&rest conditions)
  3851. "Skip entry if any of CONDITIONS is true.
  3852. See `org-agenda-skip-if' for details."
  3853. (org-agenda-skip-if t conditions))
  3854. (defun org-agenda-skip-if (subtree conditions)
  3855. "Checks current entity for CONDITIONS.
  3856. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3857. the entry, i.e. the text before the next heading is checked.
  3858. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3859. from different tests. Valid conditions are:
  3860. scheduled Check if there is a scheduled cookie
  3861. notscheduled Check if there is no scheduled cookie
  3862. deadline Check if there is a deadline
  3863. notdeadline Check if there is no deadline
  3864. timestamp Check if there is a timestamp (also deadline or scheduled)
  3865. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3866. regexp Check if regexp matches
  3867. notregexp Check if regexp does not match.
  3868. todo Check if TODO keyword matches
  3869. nottodo Check if TODO keyword does not match
  3870. The regexp is taken from the conditions list, it must come right after
  3871. the `regexp' or `notregexp' element.
  3872. `todo' and `nottodo' accept as an argument a list of todo
  3873. keywords, which may include \"*\" to match any todo keyword.
  3874. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3875. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3876. Instead of a list a keyword class may be given
  3877. (org-agenda-skip-entry-if 'nottodo 'done)
  3878. would skip entries that haven't been marked with any of \"DONE\"
  3879. keywords. Possible classes are: `todo', `done', `any'.
  3880. If any of these conditions is met, this function returns the end point of
  3881. the entity, causing the search to continue from there. This is a function
  3882. that can be put into `org-agenda-skip-function' for the duration of a command."
  3883. (let (beg end m)
  3884. (org-back-to-heading t)
  3885. (setq beg (point)
  3886. end (if subtree
  3887. (progn (org-end-of-subtree t) (point))
  3888. (progn (outline-next-heading) (1- (point)))))
  3889. (goto-char beg)
  3890. (and
  3891. (or
  3892. (and (memq 'scheduled conditions)
  3893. (re-search-forward org-scheduled-time-regexp end t))
  3894. (and (memq 'notscheduled conditions)
  3895. (not (re-search-forward org-scheduled-time-regexp end t)))
  3896. (and (memq 'deadline conditions)
  3897. (re-search-forward org-deadline-time-regexp end t))
  3898. (and (memq 'notdeadline conditions)
  3899. (not (re-search-forward org-deadline-time-regexp end t)))
  3900. (and (memq 'timestamp conditions)
  3901. (re-search-forward org-ts-regexp end t))
  3902. (and (memq 'nottimestamp conditions)
  3903. (not (re-search-forward org-ts-regexp end t)))
  3904. (and (setq m (memq 'regexp conditions))
  3905. (stringp (nth 1 m))
  3906. (re-search-forward (nth 1 m) end t))
  3907. (and (setq m (memq 'notregexp conditions))
  3908. (stringp (nth 1 m))
  3909. (not (re-search-forward (nth 1 m) end t)))
  3910. (and (or
  3911. (setq m (memq 'todo conditions))
  3912. (setq m (memq 'nottodo conditions)))
  3913. (org-agenda-skip-if-todo m end)))
  3914. end)))
  3915. (defun org-agenda-skip-if-todo (args end)
  3916. "Helper function for `org-agenda-skip-if', do not use it directly.
  3917. ARGS is a list with first element either `todo' or `nottodo'.
  3918. The remainder is either a list of TODO keywords, or a state symbol
  3919. `todo' or `done' or `any'."
  3920. (let ((kw (car args))
  3921. (arg (cadr args))
  3922. todo-wds todo-re)
  3923. (setq todo-wds
  3924. (org-uniquify
  3925. (cond
  3926. ((listp arg) ;; list of keywords
  3927. (if (member "*" arg)
  3928. (mapcar 'substring-no-properties org-todo-keywords-1)
  3929. arg))
  3930. ((symbolp arg) ;; keyword class name
  3931. (cond
  3932. ((eq arg 'todo)
  3933. (org-delete-all org-done-keywords
  3934. (mapcar 'substring-no-properties
  3935. org-todo-keywords-1)))
  3936. ((eq arg 'done) org-done-keywords)
  3937. ((eq arg 'any)
  3938. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3939. (setq todo-re
  3940. (concat "^\\*+[ \t]+\\<\\("
  3941. (mapconcat 'identity todo-wds "\\|")
  3942. "\\)\\>"))
  3943. (if (eq kw 'todo)
  3944. (re-search-forward todo-re end t)
  3945. (not (re-search-forward todo-re end t)))))
  3946. ;;;###autoload
  3947. (defun org-agenda-list-stuck-projects (&rest ignore)
  3948. "Create agenda view for projects that are stuck.
  3949. Stuck projects are project that have no next actions. For the definitions
  3950. of what a project is and how to check if it stuck, customize the variable
  3951. `org-stuck-projects'."
  3952. (interactive)
  3953. (let* ((org-agenda-skip-function
  3954. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3955. ;; We could have used org-agenda-skip-if here.
  3956. (org-agenda-overriding-header
  3957. (or org-agenda-overriding-header "List of stuck projects: "))
  3958. (matcher (nth 0 org-stuck-projects))
  3959. (todo (nth 1 org-stuck-projects))
  3960. (todo-wds (if (member "*" todo)
  3961. (progn
  3962. (org-prepare-agenda-buffers (org-agenda-files
  3963. nil 'ifmode))
  3964. (org-delete-all
  3965. org-done-keywords-for-agenda
  3966. (copy-sequence org-todo-keywords-for-agenda)))
  3967. todo))
  3968. (todo-re (concat "^\\*+[ \t]+\\("
  3969. (mapconcat 'identity todo-wds "\\|")
  3970. "\\)\\>"))
  3971. (tags (nth 2 org-stuck-projects))
  3972. (tags-re (if (member "*" tags)
  3973. (concat org-outline-regexp-bol
  3974. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3975. (if tags
  3976. (concat org-outline-regexp-bol
  3977. ".*:\\("
  3978. (mapconcat 'identity tags "\\|")
  3979. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3980. (gen-re (nth 3 org-stuck-projects))
  3981. (re-list
  3982. (delq nil
  3983. (list
  3984. (if todo todo-re)
  3985. (if tags tags-re)
  3986. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3987. gen-re)))))
  3988. (setq org-agenda-skip-regexp
  3989. (if re-list
  3990. (mapconcat 'identity re-list "\\|")
  3991. (error "No information how to identify unstuck projects")))
  3992. (org-tags-view nil matcher)
  3993. (with-current-buffer org-agenda-buffer-name
  3994. (setq org-agenda-redo-command
  3995. '(org-agenda-list-stuck-projects
  3996. (or current-prefix-arg org-last-arg))))))
  3997. ;;; Diary integration
  3998. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3999. (defvar list-diary-entries-hook)
  4000. (defvar diary-time-regexp)
  4001. (defun org-get-entries-from-diary (date)
  4002. "Get the (Emacs Calendar) diary entries for DATE."
  4003. (require 'diary-lib)
  4004. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4005. (diary-display-hook '(fancy-diary-display))
  4006. (diary-display-function 'fancy-diary-display)
  4007. (pop-up-frames nil)
  4008. (list-diary-entries-hook
  4009. (cons 'org-diary-default-entry list-diary-entries-hook))
  4010. (diary-file-name-prefix-function nil) ; turn this feature off
  4011. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4012. entries
  4013. (org-disable-agenda-to-diary t))
  4014. (save-excursion
  4015. (save-window-excursion
  4016. (funcall (if (fboundp 'diary-list-entries)
  4017. 'diary-list-entries 'list-diary-entries)
  4018. date 1)))
  4019. (if (not (get-buffer diary-fancy-buffer))
  4020. (setq entries nil)
  4021. (with-current-buffer diary-fancy-buffer
  4022. (setq buffer-read-only nil)
  4023. (if (zerop (buffer-size))
  4024. ;; No entries
  4025. (setq entries nil)
  4026. ;; Omit the date and other unnecessary stuff
  4027. (org-agenda-cleanup-fancy-diary)
  4028. ;; Add prefix to each line and extend the text properties
  4029. (if (zerop (buffer-size))
  4030. (setq entries nil)
  4031. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4032. (setq entries
  4033. (with-temp-buffer
  4034. (insert entries) (goto-char (point-min))
  4035. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4036. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4037. (replace-match (concat "; " (match-string 1)))))
  4038. (buffer-string)))))
  4039. (set-buffer-modified-p nil)
  4040. (kill-buffer diary-fancy-buffer)))
  4041. (when entries
  4042. (setq entries (org-split-string entries "\n"))
  4043. (setq entries
  4044. (mapcar
  4045. (lambda (x)
  4046. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4047. ;; Extend the text properties to the beginning of the line
  4048. (org-add-props x (text-properties-at (1- (length x)) x)
  4049. 'type "diary" 'date date 'face 'org-agenda-diary))
  4050. entries)))))
  4051. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4052. "Hook run when the fancy diary buffer is cleaned up.")
  4053. (defun org-agenda-cleanup-fancy-diary ()
  4054. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4055. This gets rid of the date, the underline under the date, and
  4056. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4057. date. It also removes lines that contain only whitespace."
  4058. (goto-char (point-min))
  4059. (if (looking-at ".*?:[ \t]*")
  4060. (progn
  4061. (replace-match "")
  4062. (re-search-forward "\n=+$" nil t)
  4063. (replace-match "")
  4064. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4065. (re-search-forward "\n=+$" nil t)
  4066. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4067. (goto-char (point-min))
  4068. (while (re-search-forward "^ +\n" nil t)
  4069. (replace-match ""))
  4070. (goto-char (point-min))
  4071. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4072. (replace-match ""))
  4073. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4074. ;; Make sure entries from the diary have the right text properties.
  4075. (eval-after-load "diary-lib"
  4076. '(if (boundp 'diary-modify-entry-list-string-function)
  4077. ;; We can rely on the hook, nothing to do
  4078. nil
  4079. ;; Hook not available, must use advice to make this work
  4080. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4081. "Make the position visible."
  4082. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4083. (stringp string)
  4084. buffer-file-name)
  4085. (setq string (org-modify-diary-entry-string string))))))
  4086. (defun org-modify-diary-entry-string (string)
  4087. "Add text properties to string, allowing org-mode to act on it."
  4088. (org-add-props string nil
  4089. 'mouse-face 'highlight
  4090. 'help-echo (if buffer-file-name
  4091. (format "mouse-2 or RET jump to diary file %s"
  4092. (abbreviate-file-name buffer-file-name))
  4093. "")
  4094. 'org-agenda-diary-link t
  4095. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4096. (defun org-diary-default-entry ()
  4097. "Add a dummy entry to the diary.
  4098. Needed to avoid empty dates which mess up holiday display."
  4099. ;; Catch the error if dealing with the new add-to-diary-alist
  4100. (when org-disable-agenda-to-diary
  4101. (condition-case nil
  4102. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4103. (error
  4104. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4105. (defun org-add-to-diary-list (&rest args)
  4106. (if (fboundp 'diary-add-to-list)
  4107. (apply 'diary-add-to-list args)
  4108. (apply 'add-to-diary-list args)))
  4109. (defvar org-diary-last-run-time nil)
  4110. ;;;###autoload
  4111. (defun org-diary (&rest args)
  4112. "Return diary information from org-files.
  4113. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4114. It accesses org files and extracts information from those files to be
  4115. listed in the diary. The function accepts arguments specifying what
  4116. items should be listed. For a list of arguments allowed here, see the
  4117. variable `org-agenda-entry-types'.
  4118. The call in the diary file should look like this:
  4119. &%%(org-diary) ~/path/to/some/orgfile.org
  4120. Use a separate line for each org file to check. Or, if you omit the file name,
  4121. all files listed in `org-agenda-files' will be checked automatically:
  4122. &%%(org-diary)
  4123. If you don't give any arguments (as in the example above), the default
  4124. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4125. So the example above may also be written as
  4126. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4127. The function expects the lisp variables `entry' and `date' to be provided
  4128. by the caller, because this is how the calendar works. Don't use this
  4129. function from a program - use `org-agenda-get-day-entries' instead."
  4130. (when (> (- (org-float-time)
  4131. org-agenda-last-marker-time)
  4132. 5)
  4133. (org-agenda-reset-markers))
  4134. (org-compile-prefix-format 'agenda)
  4135. (org-set-sorting-strategy 'agenda)
  4136. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4137. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4138. (list entry)
  4139. (org-agenda-files t)))
  4140. (time (org-float-time))
  4141. file rtn results)
  4142. (when (or (not org-diary-last-run-time)
  4143. (> (- time
  4144. org-diary-last-run-time)
  4145. 3))
  4146. (org-prepare-agenda-buffers files))
  4147. (setq org-diary-last-run-time time)
  4148. ;; If this is called during org-agenda, don't return any entries to
  4149. ;; the calendar. Org Agenda will list these entries itself.
  4150. (if org-disable-agenda-to-diary (setq files nil))
  4151. (while (setq file (pop files))
  4152. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4153. (setq results (append results rtn)))
  4154. (if results
  4155. (concat (org-finalize-agenda-entries results) "\n"))))
  4156. ;;; Agenda entry finders
  4157. (defun org-agenda-get-day-entries (file date &rest args)
  4158. "Does the work for `org-diary' and `org-agenda'.
  4159. FILE is the path to a file to be checked for entries. DATE is date like
  4160. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4161. which kind of entries should be extracted. For details about these, see
  4162. the documentation of `org-diary'."
  4163. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4164. (let* ((org-startup-folded nil)
  4165. (org-startup-align-all-tables nil)
  4166. (buffer (if (file-exists-p file)
  4167. (org-get-agenda-file-buffer file)
  4168. (error "No such file %s" file)))
  4169. arg results rtn deadline-results)
  4170. (if (not buffer)
  4171. ;; If file does not exist, make sure an error message ends up in diary
  4172. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4173. (with-current-buffer buffer
  4174. (unless (eq major-mode 'org-mode)
  4175. (error "Agenda file %s is not in `org-mode'" file))
  4176. (let ((case-fold-search nil))
  4177. (save-excursion
  4178. (save-restriction
  4179. (if org-agenda-restrict
  4180. (narrow-to-region org-agenda-restrict-begin
  4181. org-agenda-restrict-end)
  4182. (widen))
  4183. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4184. (while (setq arg (pop args))
  4185. (cond
  4186. ((and (eq arg :todo)
  4187. (equal date (calendar-gregorian-from-absolute
  4188. (org-today))))
  4189. (setq rtn (org-agenda-get-todos))
  4190. (setq results (append results rtn)))
  4191. ((eq arg :timestamp)
  4192. (setq rtn (org-agenda-get-blocks))
  4193. (setq results (append results rtn))
  4194. (setq rtn (org-agenda-get-timestamps))
  4195. (setq results (append results rtn)))
  4196. ((eq arg :sexp)
  4197. (setq rtn (org-agenda-get-sexps))
  4198. (setq results (append results rtn)))
  4199. ((eq arg :scheduled)
  4200. (setq rtn (org-agenda-get-scheduled deadline-results))
  4201. (setq results (append results rtn)))
  4202. ((eq arg :closed)
  4203. (setq rtn (org-agenda-get-progress))
  4204. (setq results (append results rtn)))
  4205. ((eq arg :deadline)
  4206. (setq rtn (org-agenda-get-deadlines))
  4207. (setq deadline-results (copy-sequence rtn))
  4208. (setq results (append results rtn))))))))
  4209. results))))
  4210. (defun org-agenda-get-todos ()
  4211. "Return the TODO information for agenda display."
  4212. (let* ((props (list 'face nil
  4213. 'done-face 'org-agenda-done
  4214. 'org-not-done-regexp org-not-done-regexp
  4215. 'org-todo-regexp org-todo-regexp
  4216. 'org-complex-heading-regexp org-complex-heading-regexp
  4217. 'mouse-face 'highlight
  4218. 'help-echo
  4219. (format "mouse-2 or RET jump to org file %s"
  4220. (abbreviate-file-name buffer-file-name))))
  4221. (regexp (concat "^\\*+[ \t]+\\("
  4222. (if org-select-this-todo-keyword
  4223. (if (equal org-select-this-todo-keyword "*")
  4224. org-todo-regexp
  4225. (concat "\\<\\("
  4226. (mapconcat 'identity
  4227. (org-split-string
  4228. org-select-this-todo-keyword "|") "\\|")
  4229. "\\)\\>"))
  4230. org-not-done-regexp)
  4231. "[^\n\r]*\\)"))
  4232. marker priority category category-pos tags todo-state ee txt beg end)
  4233. (goto-char (point-min))
  4234. (while (re-search-forward regexp nil t)
  4235. (catch :skip
  4236. (save-match-data
  4237. (beginning-of-line)
  4238. (org-agenda-skip)
  4239. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4240. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4241. (goto-char (1+ beg))
  4242. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4243. (throw :skip nil)))
  4244. (goto-char (match-beginning 1))
  4245. (setq marker (org-agenda-new-marker (match-beginning 0))
  4246. category (org-get-category)
  4247. category-pos (get-text-property (point) 'org-category-position)
  4248. txt (match-string 1)
  4249. tags (org-get-tags-at (point))
  4250. txt (org-format-agenda-item "" txt category tags)
  4251. priority (1+ (org-get-priority txt))
  4252. todo-state (org-get-todo-state))
  4253. (org-add-props txt props
  4254. 'org-marker marker 'org-hd-marker marker
  4255. 'priority priority 'org-category category
  4256. 'org-category-position category-pos
  4257. 'type "todo" 'todo-state todo-state)
  4258. (push txt ee)
  4259. (if org-agenda-todo-list-sublevels
  4260. (goto-char (match-end 1))
  4261. (org-end-of-subtree 'invisible))))
  4262. (nreverse ee)))
  4263. (defun org-agenda-todo-custom-ignore-p (time n)
  4264. "Check whether timestamp is farther away then n number of days.
  4265. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4266. `org-agenda-todo-ignore-scheduled' or
  4267. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4268. (let ((days (org-days-to-time time)))
  4269. (if (>= n 0)
  4270. (>= days n)
  4271. (<= days n))))
  4272. ;;;###autoload
  4273. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4274. (&optional end)
  4275. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4276. (when (or org-agenda-todo-ignore-with-date
  4277. org-agenda-todo-ignore-scheduled
  4278. org-agenda-todo-ignore-deadlines
  4279. org-agenda-todo-ignore-timestamp)
  4280. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4281. (save-excursion
  4282. (or (and org-agenda-todo-ignore-with-date
  4283. (re-search-forward org-ts-regexp end t))
  4284. (and org-agenda-todo-ignore-scheduled
  4285. (re-search-forward org-scheduled-time-regexp end t)
  4286. (cond
  4287. ((eq org-agenda-todo-ignore-scheduled 'future)
  4288. (> (org-days-to-time (match-string 1)) 0))
  4289. ((eq org-agenda-todo-ignore-scheduled 'past)
  4290. (<= (org-days-to-time (match-string 1)) 0))
  4291. ((numberp org-agenda-todo-ignore-scheduled)
  4292. (org-agenda-todo-custom-ignore-p
  4293. (match-string 1) org-agenda-todo-ignore-scheduled))
  4294. (t)))
  4295. (and org-agenda-todo-ignore-deadlines
  4296. (re-search-forward org-deadline-time-regexp end t)
  4297. (cond
  4298. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4299. ((eq org-agenda-todo-ignore-deadlines 'far)
  4300. (not (org-deadline-close (match-string 1))))
  4301. ((eq org-agenda-todo-ignore-deadlines 'future)
  4302. (> (org-days-to-time (match-string 1)) 0))
  4303. ((eq org-agenda-todo-ignore-deadlines 'past)
  4304. (<= (org-days-to-time (match-string 1)) 0))
  4305. ((numberp org-agenda-todo-ignore-deadlines)
  4306. (org-agenda-todo-custom-ignore-p
  4307. (match-string 1) org-agenda-todo-ignore-deadlines))
  4308. (t (org-deadline-close (match-string 1)))))
  4309. (and org-agenda-todo-ignore-timestamp
  4310. (let ((buffer (current-buffer))
  4311. (regexp
  4312. (concat
  4313. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4314. (start (point)))
  4315. ;; Copy current buffer into a temporary one
  4316. (with-temp-buffer
  4317. (insert-buffer-substring buffer start end)
  4318. (goto-char (point-min))
  4319. ;; Delete SCHEDULED and DEADLINE items
  4320. (while (re-search-forward regexp end t)
  4321. (delete-region (match-beginning 0) (match-end 0)))
  4322. (goto-char (point-min))
  4323. ;; No search for timestamp left
  4324. (when (re-search-forward org-ts-regexp nil t)
  4325. (cond
  4326. ((eq org-agenda-todo-ignore-timestamp 'future)
  4327. (> (org-days-to-time (match-string 1)) 0))
  4328. ((eq org-agenda-todo-ignore-timestamp 'past)
  4329. (<= (org-days-to-time (match-string 1)) 0))
  4330. ((numberp org-agenda-todo-ignore-timestamp)
  4331. (org-agenda-todo-custom-ignore-p
  4332. (match-string 1) org-agenda-todo-ignore-timestamp))
  4333. (t))))))))))
  4334. (defconst org-agenda-no-heading-message
  4335. "No heading for this item in buffer or region.")
  4336. (defun org-agenda-get-timestamps ()
  4337. "Return the date stamp information for agenda display."
  4338. (let* ((props (list 'face nil
  4339. 'org-not-done-regexp org-not-done-regexp
  4340. 'org-todo-regexp org-todo-regexp
  4341. 'org-complex-heading-regexp org-complex-heading-regexp
  4342. 'mouse-face 'highlight
  4343. 'help-echo
  4344. (format "mouse-2 or RET jump to org file %s"
  4345. (abbreviate-file-name buffer-file-name))))
  4346. (d1 (calendar-absolute-from-gregorian date))
  4347. (remove-re
  4348. (concat
  4349. (regexp-quote
  4350. (format-time-string
  4351. "<%Y-%m-%d"
  4352. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4353. ".*?>"))
  4354. (regexp
  4355. (concat
  4356. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4357. (regexp-quote
  4358. (substring
  4359. (format-time-string
  4360. (car org-time-stamp-formats)
  4361. (apply 'encode-time ; DATE bound by calendar
  4362. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4363. 1 11))
  4364. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4365. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4366. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4367. donep tmp priority category category-pos ee txt timestr tags
  4368. b0 b3 e3 head todo-state end-of-match show-all)
  4369. (goto-char (point-min))
  4370. (while (setq end-of-match (re-search-forward regexp nil t))
  4371. (setq b0 (match-beginning 0)
  4372. b3 (match-beginning 3) e3 (match-end 3)
  4373. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4374. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4375. (member todo-state
  4376. org-agenda-repeating-timestamp-show-all)))
  4377. (catch :skip
  4378. (and (org-at-date-range-p) (throw :skip nil))
  4379. (org-agenda-skip)
  4380. (if (and (match-end 1)
  4381. (not (= d1 (org-time-string-to-absolute
  4382. (match-string 1) d1 nil show-all
  4383. (current-buffer) b0))))
  4384. (throw :skip nil))
  4385. (if (and e3
  4386. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4387. (throw :skip nil))
  4388. (setq tmp (buffer-substring (max (point-min)
  4389. (- b0 org-ds-keyword-length))
  4390. b0)
  4391. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4392. inactivep (= (char-after b0) ?\[)
  4393. deadlinep (string-match org-deadline-regexp tmp)
  4394. scheduledp (string-match org-scheduled-regexp tmp)
  4395. closedp (and org-agenda-include-inactive-timestamps
  4396. (string-match org-closed-string tmp))
  4397. clockp (and org-agenda-include-inactive-timestamps
  4398. (or (string-match org-clock-string tmp)
  4399. (string-match "]-+\\'" tmp)))
  4400. donep (member todo-state org-done-keywords))
  4401. (if (or scheduledp deadlinep closedp clockp
  4402. (and donep org-agenda-skip-timestamp-if-done))
  4403. (throw :skip t))
  4404. (if (string-match ">" timestr)
  4405. ;; substring should only run to end of time stamp
  4406. (setq timestr (substring timestr 0 (match-end 0))))
  4407. (setq marker (org-agenda-new-marker b0)
  4408. category (org-get-category b0)
  4409. category-pos (get-text-property b0 'org-category-position))
  4410. (save-excursion
  4411. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4412. (setq txt org-agenda-no-heading-message)
  4413. (goto-char (match-beginning 0))
  4414. (setq hdmarker (org-agenda-new-marker)
  4415. tags (org-get-tags-at))
  4416. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4417. (setq head (or (match-string 1) ""))
  4418. (setq txt (org-format-agenda-item
  4419. (if inactivep org-agenda-inactive-leader nil)
  4420. head category tags timestr
  4421. remove-re)))
  4422. (setq priority (org-get-priority txt))
  4423. (org-add-props txt props
  4424. 'org-marker marker 'org-hd-marker hdmarker)
  4425. (org-add-props txt nil 'priority priority
  4426. 'org-category category 'date date
  4427. 'org-category-position category-pos
  4428. 'todo-state todo-state
  4429. 'type "timestamp")
  4430. (push txt ee))
  4431. (if org-agenda-skip-additional-timestamps-same-entry
  4432. (outline-next-heading)
  4433. (goto-char end-of-match))))
  4434. (nreverse ee)))
  4435. (defun org-agenda-get-sexps ()
  4436. "Return the sexp information for agenda display."
  4437. (require 'diary-lib)
  4438. (let* ((props (list 'mouse-face 'highlight
  4439. 'help-echo
  4440. (format "mouse-2 or RET jump to org file %s"
  4441. (abbreviate-file-name buffer-file-name))))
  4442. (regexp "^&?%%(")
  4443. marker category category-pos ee txt tags entry
  4444. result beg b sexp sexp-entry todo-state)
  4445. (goto-char (point-min))
  4446. (while (re-search-forward regexp nil t)
  4447. (catch :skip
  4448. (org-agenda-skip)
  4449. (setq beg (match-beginning 0))
  4450. (goto-char (1- (match-end 0)))
  4451. (setq b (point))
  4452. (forward-sexp 1)
  4453. (setq sexp (buffer-substring b (point)))
  4454. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4455. (org-trim (match-string 1))
  4456. ""))
  4457. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4458. (when result
  4459. (setq marker (org-agenda-new-marker beg)
  4460. category (org-get-category beg)
  4461. category-pos (get-text-property beg 'org-category-position)
  4462. todo-state (org-get-todo-state))
  4463. (dolist (r (if (stringp result)
  4464. (list result)
  4465. result)) ;; we expect a list here
  4466. (if (string-match "\\S-" r)
  4467. (setq txt r)
  4468. (setq txt "SEXP entry returned empty string"))
  4469. (setq txt (org-format-agenda-item
  4470. "" txt category tags 'time))
  4471. (org-add-props txt props 'org-marker marker)
  4472. (org-add-props txt nil
  4473. 'org-category category 'date date 'todo-state todo-state
  4474. 'org-category-position category-pos
  4475. 'type "sexp")
  4476. (push txt ee)))))
  4477. (nreverse ee)))
  4478. ;; Calendar sanity: define some functions that are independent of
  4479. ;; `calendar-date-style'.
  4480. ;; Normally I would like to use ISO format when calling the diary functions,
  4481. ;; but to make sure we still have Emacs 22 compatibility we bind
  4482. ;; also `european-calendar-style' and use european format
  4483. (defun org-anniversary (year month day &optional mark)
  4484. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4485. (org-no-warnings
  4486. (let ((calendar-date-style 'european) (european-calendar-style t))
  4487. (diary-anniversary day month year mark))))
  4488. (defun org-cyclic (N year month day &optional mark)
  4489. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4490. (org-no-warnings
  4491. (let ((calendar-date-style 'european) (european-calendar-style t))
  4492. (diary-cyclic N day month year mark))))
  4493. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4494. "Like `diary-block', but with fixed (ISO) order of arguments."
  4495. (org-no-warnings
  4496. (let ((calendar-date-style 'european) (european-calendar-style t))
  4497. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4498. (defun org-date (year month day &optional mark)
  4499. "Like `diary-date', but with fixed (ISO) order of arguments."
  4500. (org-no-warnings
  4501. (let ((calendar-date-style 'european) (european-calendar-style t))
  4502. (diary-date day month year mark))))
  4503. (defalias 'org-float 'diary-float)
  4504. ;; Define the` org-class' function
  4505. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4506. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4507. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4508. is any number of ISO weeks in the block period for which the item should
  4509. be skipped."
  4510. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4511. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4512. (d (calendar-absolute-from-gregorian date)))
  4513. (and
  4514. (<= date1 d)
  4515. (<= d date2)
  4516. (= (calendar-day-of-week date) dayname)
  4517. (or (not skip-weeks)
  4518. (progn
  4519. (require 'cal-iso)
  4520. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4521. entry)))
  4522. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4523. "Like `org-class', but honor `calendar-date-style'.
  4524. The order of the first 2 times 3 arguments depends on the variable
  4525. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4526. So for American calendars, give this as MONTH DAY YEAR, for European as
  4527. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4528. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4529. is any number of ISO weeks in the block period for which the item should
  4530. be skipped.
  4531. This function is here only for backward compatibility and it is deprecated,
  4532. please use `org-class' instead."
  4533. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4534. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4535. (org-class
  4536. (nth 2 date1) (car date1) (nth 1 date1)
  4537. (nth 2 date2) (car date2) (nth 1 date2)
  4538. dayname skip-weeks)))
  4539. (defalias 'org-get-closed 'org-agenda-get-progress)
  4540. (defun org-agenda-get-progress ()
  4541. "Return the logged TODO entries for agenda display."
  4542. (let* ((props (list 'mouse-face 'highlight
  4543. 'org-not-done-regexp org-not-done-regexp
  4544. 'org-todo-regexp org-todo-regexp
  4545. 'org-complex-heading-regexp org-complex-heading-regexp
  4546. 'help-echo
  4547. (format "mouse-2 or RET jump to org file %s"
  4548. (abbreviate-file-name buffer-file-name))))
  4549. (items (if (consp org-agenda-show-log)
  4550. org-agenda-show-log
  4551. (if (eq org-agenda-show-log 'clockcheck)
  4552. '(clock)
  4553. org-agenda-log-mode-items)))
  4554. (parts
  4555. (delq nil
  4556. (list
  4557. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4558. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4559. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4560. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4561. (error "`org-agenda-log-mode-items' is empty")))
  4562. (regexp (concat
  4563. "\\(" parts-re "\\)"
  4564. " *\\["
  4565. (regexp-quote
  4566. (substring
  4567. (format-time-string
  4568. (car org-time-stamp-formats)
  4569. (apply 'encode-time ; DATE bound by calendar
  4570. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4571. 1 11))))
  4572. (org-agenda-search-headline-for-time nil)
  4573. marker hdmarker priority category category-pos tags closedp
  4574. statep clockp state ee txt extra timestr rest clocked)
  4575. (goto-char (point-min))
  4576. (while (re-search-forward regexp nil t)
  4577. (catch :skip
  4578. (org-agenda-skip)
  4579. (setq marker (org-agenda-new-marker (match-beginning 0))
  4580. closedp (equal (match-string 1) org-closed-string)
  4581. statep (equal (string-to-char (match-string 1)) ?-)
  4582. clockp (not (or closedp statep))
  4583. state (and statep (match-string 2))
  4584. category (org-get-category (match-beginning 0))
  4585. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4586. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4587. (when (string-match "\\]" timestr)
  4588. ;; substring should only run to end of time stamp
  4589. (setq rest (substring timestr (match-end 0))
  4590. timestr (substring timestr 0 (match-end 0)))
  4591. (if (and (not closedp) (not statep)
  4592. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4593. rest))
  4594. (progn (setq timestr (concat (substring timestr 0 -1)
  4595. "-" (match-string 1 rest) "]"))
  4596. (setq clocked (match-string 2 rest)))
  4597. (setq clocked "-")))
  4598. (save-excursion
  4599. (setq extra
  4600. (cond
  4601. ((not org-agenda-log-mode-add-notes) nil)
  4602. (statep
  4603. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4604. (match-string 1)))
  4605. (clockp
  4606. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4607. (match-string 1)))))
  4608. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4609. (setq txt org-agenda-no-heading-message)
  4610. (goto-char (match-beginning 0))
  4611. (setq hdmarker (org-agenda-new-marker)
  4612. tags (org-get-tags-at))
  4613. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4614. (setq txt (match-string 1))
  4615. (when extra
  4616. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4617. (setq txt (concat (substring txt 0 (match-beginning 1))
  4618. " - " extra " " (match-string 2 txt)))
  4619. (setq txt (concat txt " - " extra))))
  4620. (setq txt (org-format-agenda-item
  4621. (cond
  4622. (closedp "Closed: ")
  4623. (statep (concat "State: (" state ")"))
  4624. (t (concat "Clocked: (" clocked ")")))
  4625. txt category tags timestr)))
  4626. (setq priority 100000)
  4627. (org-add-props txt props
  4628. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4629. 'priority priority 'org-category category
  4630. 'org-category-position category-pos
  4631. 'type "closed" 'date date
  4632. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4633. (push txt ee))
  4634. (goto-char (point-at-eol))))
  4635. (nreverse ee)))
  4636. (defun org-agenda-show-clocking-issues ()
  4637. "Add overlays, showing issues with clocking.
  4638. See also the user option `org-agenda-clock-consistency-checks'."
  4639. (interactive)
  4640. (let* ((pl org-agenda-clock-consistency-checks)
  4641. (re (concat "^[ \t]*"
  4642. org-clock-string
  4643. "[ \t]+"
  4644. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4645. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4646. (tlstart 0.)
  4647. (tlend 0.)
  4648. (maxtime (org-hh:mm-string-to-minutes
  4649. (or (plist-get pl :max-duration) "24:00")))
  4650. (mintime (org-hh:mm-string-to-minutes
  4651. (or (plist-get pl :min-duration) 0)))
  4652. (maxgap (org-hh:mm-string-to-minutes
  4653. ;; default 30:00 means never complain
  4654. (or (plist-get pl :max-gap) "30:00")))
  4655. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4656. (plist-get pl :gap-ok-around)))
  4657. (def-face (or (plist-get pl :default-face)
  4658. '((:background "DarkRed") (:foreground "white"))))
  4659. issue face m te ts dt ov)
  4660. (goto-char (point-min))
  4661. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4662. (setq issue nil face def-face)
  4663. (catch 'next
  4664. (setq m (org-get-at-bol 'org-marker)
  4665. te nil ts nil)
  4666. (unless (and m (markerp m))
  4667. (setq issue "No valid clock line") (throw 'next t))
  4668. (org-with-point-at m
  4669. (save-excursion
  4670. (goto-char (point-at-bol))
  4671. (unless (looking-at re)
  4672. (error "No valid Clock line")
  4673. (throw 'next t))
  4674. (unless (match-end 3)
  4675. (setq issue "No end time"
  4676. face (or (plist-get pl :no-end-time-face) face))
  4677. (throw 'next t))
  4678. (setq ts (match-string 1)
  4679. te (match-string 3)
  4680. ts (org-float-time
  4681. (apply 'encode-time (org-parse-time-string ts)))
  4682. te (org-float-time
  4683. (apply 'encode-time (org-parse-time-string te)))
  4684. dt (- te ts))))
  4685. (cond
  4686. ((> dt (* 60 maxtime))
  4687. ;; a very long clocking chunk
  4688. (setq issue (format "Clocking interval is very long: %s"
  4689. (org-minutes-to-hh:mm-string
  4690. (floor (/ (float dt) 60.))))
  4691. face (or (plist-get pl :long-face) face)))
  4692. ((< dt (* 60 mintime))
  4693. ;; a very short clocking chunk
  4694. (setq issue (format "Clocking interval is very short: %s"
  4695. (org-minutes-to-hh:mm-string
  4696. (floor (/ (float dt) 60.))))
  4697. face (or (plist-get pl :short-face) face)))
  4698. ((and (> tlend 0) (< ts tlend))
  4699. ;; Two clock entries are overlapping
  4700. (setq issue (format "Clocking overlap: %d minutes"
  4701. (/ (- tlend ts) 60))
  4702. face (or (plist-get pl :overlap-face) face)))
  4703. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4704. ;; There is a gap, lets see if we need to report it
  4705. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4706. (setq issue (format "Clocking gap: %d minutes"
  4707. (/ (- ts tlend) 60))
  4708. face (or (plist-get pl :gap-face) face))))
  4709. (t nil)))
  4710. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4711. (when issue
  4712. ;; OK, there was some issue, add an overlay to show the issue
  4713. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4714. (overlay-put ov 'before-string
  4715. (concat
  4716. (org-add-props
  4717. (format "%-43s" (concat " " issue))
  4718. nil
  4719. 'face face)
  4720. "\n"))
  4721. (overlay-put ov 'evaporate t)))))
  4722. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4723. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4724. (catch 'exit
  4725. (unless ok-list
  4726. ;; there are no OK times for gaps...
  4727. (throw 'exit nil))
  4728. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4729. ;; This is more than 24 hours, so it is OK.
  4730. ;; because we have at least one OK time, that must be in the
  4731. ;; 24 hour interval.
  4732. (throw 'exit t))
  4733. ;; We have a shorter gap.
  4734. ;; Now we have to get the minute of the day when these times are
  4735. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4736. (t2dec (decode-time (seconds-to-time t2)))
  4737. ;; compute the minute on the day
  4738. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4739. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4740. (when (< min2 min1)
  4741. ;; if min2 is smaller than min1, this means it is on the next day.
  4742. ;; Wrap it to after midnight.
  4743. (setq min2 (+ min2 1440)))
  4744. ;; Now check if any of the OK times is in the gap
  4745. (mapc (lambda (x)
  4746. ;; Wrap the time to after midnight if necessary
  4747. (if (< x min1) (setq x (+ x 1440)))
  4748. ;; Check if in interval
  4749. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4750. ok-list)
  4751. ;; Nope, this gap is not OK
  4752. nil)))
  4753. (defun org-agenda-get-deadlines ()
  4754. "Return the deadline information for agenda display."
  4755. (let* ((props (list 'mouse-face 'highlight
  4756. 'org-not-done-regexp org-not-done-regexp
  4757. 'org-todo-regexp org-todo-regexp
  4758. 'org-complex-heading-regexp org-complex-heading-regexp
  4759. 'help-echo
  4760. (format "mouse-2 or RET jump to org file %s"
  4761. (abbreviate-file-name buffer-file-name))))
  4762. (regexp org-deadline-time-regexp)
  4763. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4764. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4765. d2 diff dfrac wdays pos pos1 category category-pos
  4766. tags suppress-prewarning ee txt head face s todo-state
  4767. show-all upcomingp donep timestr)
  4768. (goto-char (point-min))
  4769. (while (re-search-forward regexp nil t)
  4770. (setq suppress-prewarning nil)
  4771. (catch :skip
  4772. (org-agenda-skip)
  4773. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4774. (save-match-data
  4775. (string-match org-scheduled-time-regexp
  4776. (buffer-substring (point-at-bol)
  4777. (point-at-eol)))))
  4778. (setq suppress-prewarning
  4779. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4780. org-agenda-skip-deadline-prewarning-if-scheduled
  4781. 0)))
  4782. (setq s (match-string 1)
  4783. txt nil
  4784. pos (1- (match-beginning 1))
  4785. todo-state (save-match-data (org-get-todo-state))
  4786. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4787. (member todo-state
  4788. org-agenda-repeating-timestamp-show-all))
  4789. d2 (org-time-string-to-absolute
  4790. (match-string 1) d1 'past show-all
  4791. (current-buffer) pos)
  4792. diff (- d2 d1)
  4793. wdays (if suppress-prewarning
  4794. (let ((org-deadline-warning-days suppress-prewarning))
  4795. (org-get-wdays s))
  4796. (org-get-wdays s))
  4797. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4798. upcomingp (and todayp (> diff 0)))
  4799. ;; When to show a deadline in the calendar:
  4800. ;; If the expiration is within wdays warning time.
  4801. ;; Past-due deadlines are only shown on the current date
  4802. (if (and (or (and (<= diff wdays)
  4803. (and todayp (not org-agenda-only-exact-dates)))
  4804. (= diff 0)))
  4805. (save-excursion
  4806. ;; (setq todo-state (org-get-todo-state))
  4807. (setq donep (member todo-state org-done-keywords))
  4808. (if (and donep
  4809. (or org-agenda-skip-deadline-if-done
  4810. (not (= diff 0))))
  4811. (setq txt nil)
  4812. (setq category (org-get-category)
  4813. category-pos (get-text-property (point) 'org-category-position))
  4814. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4815. (setq txt org-agenda-no-heading-message)
  4816. (goto-char (match-end 0))
  4817. (setq pos1 (match-beginning 0))
  4818. (setq tags (org-get-tags-at pos1))
  4819. (setq head (buffer-substring-no-properties
  4820. (point)
  4821. (progn (skip-chars-forward "^\r\n")
  4822. (point))))
  4823. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4824. (setq timestr
  4825. (concat (substring s (match-beginning 1)) " "))
  4826. (setq timestr 'time))
  4827. (setq txt (org-format-agenda-item
  4828. (if (= diff 0)
  4829. (car org-agenda-deadline-leaders)
  4830. (if (functionp
  4831. (nth 1 org-agenda-deadline-leaders))
  4832. (funcall
  4833. (nth 1 org-agenda-deadline-leaders)
  4834. diff date)
  4835. (format (nth 1 org-agenda-deadline-leaders)
  4836. diff)))
  4837. head category tags
  4838. (if (not (= diff 0)) nil timestr)))))
  4839. (when txt
  4840. (setq face (org-agenda-deadline-face dfrac))
  4841. (org-add-props txt props
  4842. 'org-marker (org-agenda-new-marker pos)
  4843. 'org-hd-marker (org-agenda-new-marker pos1)
  4844. 'priority (+ (- diff)
  4845. (org-get-priority txt))
  4846. 'org-category category
  4847. 'org-category-position category-pos
  4848. 'todo-state todo-state
  4849. 'type (if upcomingp "upcoming-deadline" "deadline")
  4850. 'date (if upcomingp date d2)
  4851. 'face (if donep 'org-agenda-done face)
  4852. 'undone-face face 'done-face 'org-agenda-done)
  4853. (push txt ee))))))
  4854. (nreverse ee)))
  4855. (defun org-agenda-deadline-face (fraction)
  4856. "Return the face to displaying a deadline item.
  4857. FRACTION is what fraction of the head-warning time has passed."
  4858. (let ((faces org-agenda-deadline-faces) f)
  4859. (catch 'exit
  4860. (while (setq f (pop faces))
  4861. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4862. (defun org-agenda-get-scheduled (&optional deadline-results)
  4863. "Return the scheduled information for agenda display."
  4864. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4865. 'org-todo-regexp org-todo-regexp
  4866. 'org-complex-heading-regexp org-complex-heading-regexp
  4867. 'done-face 'org-agenda-done
  4868. 'mouse-face 'highlight
  4869. 'help-echo
  4870. (format "mouse-2 or RET jump to org file %s"
  4871. (abbreviate-file-name buffer-file-name))))
  4872. (regexp org-scheduled-time-regexp)
  4873. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4874. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4875. mm
  4876. (deadline-position-alist
  4877. (mapcar (lambda (a) (and (setq mm (get-text-property
  4878. 0 'org-hd-marker a))
  4879. (cons (marker-position mm) a)))
  4880. deadline-results))
  4881. d2 diff pos pos1 category category-pos tags donep
  4882. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4883. (goto-char (point-min))
  4884. (while (re-search-forward regexp nil t)
  4885. (catch :skip
  4886. (org-agenda-skip)
  4887. (setq s (match-string 1)
  4888. txt nil
  4889. pos (1- (match-beginning 1))
  4890. todo-state (save-match-data (org-get-todo-state))
  4891. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4892. (member todo-state
  4893. org-agenda-repeating-timestamp-show-all))
  4894. d2 (org-time-string-to-absolute
  4895. (match-string 1) d1 'past show-all
  4896. (current-buffer) pos)
  4897. diff (- d2 d1))
  4898. (setq pastschedp (and todayp (< diff 0)))
  4899. ;; When to show a scheduled item in the calendar:
  4900. ;; If it is on or past the date.
  4901. (when (or (and (< diff 0)
  4902. (< (abs diff) org-scheduled-past-days)
  4903. (and todayp (not org-agenda-only-exact-dates)))
  4904. (= diff 0))
  4905. (save-excursion
  4906. (setq donep (member todo-state org-done-keywords))
  4907. (if (and donep
  4908. (or org-agenda-skip-scheduled-if-done
  4909. (not (= diff 0))
  4910. (and (functionp 'org-is-habit-p)
  4911. (org-is-habit-p))))
  4912. (setq txt nil)
  4913. (setq habitp (and (functionp 'org-is-habit-p)
  4914. (org-is-habit-p)))
  4915. (setq category (org-get-category)
  4916. category-pos (get-text-property (point) 'org-category-position))
  4917. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4918. (setq txt org-agenda-no-heading-message)
  4919. (goto-char (match-end 0))
  4920. (setq pos1 (match-beginning 0))
  4921. (if habitp
  4922. (if (or (not org-habit-show-habits)
  4923. (and (not todayp)
  4924. org-habit-show-habits-only-for-today))
  4925. (throw :skip nil))
  4926. (if (and
  4927. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4928. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4929. pastschedp))
  4930. (setq mm (assoc pos1 deadline-position-alist)))
  4931. (throw :skip nil)))
  4932. (setq tags (org-get-tags-at))
  4933. (setq head (buffer-substring-no-properties
  4934. (point)
  4935. (progn (skip-chars-forward "^\r\n") (point))))
  4936. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4937. (setq timestr
  4938. (concat (substring s (match-beginning 1)) " "))
  4939. (setq timestr 'time))
  4940. (setq txt (org-format-agenda-item
  4941. (if (= diff 0)
  4942. (car org-agenda-scheduled-leaders)
  4943. (format (nth 1 org-agenda-scheduled-leaders)
  4944. (- 1 diff)))
  4945. head category tags
  4946. (if (not (= diff 0)) nil timestr)
  4947. nil habitp))))
  4948. (when txt
  4949. (setq face
  4950. (cond
  4951. ((and (not habitp) pastschedp)
  4952. 'org-scheduled-previously)
  4953. (todayp 'org-scheduled-today)
  4954. (t 'org-scheduled))
  4955. habitp (and habitp (org-habit-parse-todo)))
  4956. (org-add-props txt props
  4957. 'undone-face face
  4958. 'face (if donep 'org-agenda-done face)
  4959. 'org-marker (org-agenda-new-marker pos)
  4960. 'org-hd-marker (org-agenda-new-marker pos1)
  4961. 'type (if pastschedp "past-scheduled" "scheduled")
  4962. 'date (if pastschedp d2 date)
  4963. 'priority (if habitp
  4964. (org-habit-get-priority habitp)
  4965. (+ 94 (- 5 diff) (org-get-priority txt)))
  4966. 'org-category category
  4967. 'org-category-position category-pos
  4968. 'org-habit-p habitp
  4969. 'todo-state todo-state)
  4970. (push txt ee))))))
  4971. (nreverse ee)))
  4972. (defun org-agenda-get-blocks ()
  4973. "Return the date-range information for agenda display."
  4974. (let* ((props (list 'face nil
  4975. 'org-not-done-regexp org-not-done-regexp
  4976. 'org-todo-regexp org-todo-regexp
  4977. 'org-complex-heading-regexp org-complex-heading-regexp
  4978. 'mouse-face 'highlight
  4979. 'help-echo
  4980. (format "mouse-2 or RET jump to org file %s"
  4981. (abbreviate-file-name buffer-file-name))))
  4982. (regexp org-tr-regexp)
  4983. (d0 (calendar-absolute-from-gregorian date))
  4984. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4985. head donep)
  4986. (goto-char (point-min))
  4987. (while (re-search-forward regexp nil t)
  4988. (catch :skip
  4989. (org-agenda-skip)
  4990. (setq pos (point))
  4991. (let ((start-time (match-string 1))
  4992. (end-time (match-string 2)))
  4993. (setq s1 (match-string 1)
  4994. s2 (match-string 2)
  4995. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  4996. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  4997. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4998. ;; Only allow days between the limits, because the normal
  4999. ;; date stamps will catch the limits.
  5000. (save-excursion
  5001. (setq todo-state (org-get-todo-state))
  5002. (setq donep (member todo-state org-done-keywords))
  5003. (if (and donep org-agenda-skip-timestamp-if-done)
  5004. (throw :skip t))
  5005. (setq marker (org-agenda-new-marker (point)))
  5006. (setq category (org-get-category)
  5007. category-pos (get-text-property (point) 'org-category-position))
  5008. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5009. (setq txt org-agenda-no-heading-message)
  5010. (goto-char (match-beginning 0))
  5011. (setq hdmarker (org-agenda-new-marker (point)))
  5012. (setq tags (org-get-tags-at))
  5013. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5014. (setq head (match-string 1))
  5015. (let ((remove-re
  5016. (if org-agenda-remove-timeranges-from-blocks
  5017. (concat
  5018. "<" (regexp-quote s1) ".*?>"
  5019. "--"
  5020. "<" (regexp-quote s2) ".*?>")
  5021. nil)))
  5022. (setq txt (org-format-agenda-item
  5023. (format
  5024. (nth (if (= d1 d2) 0 1)
  5025. org-agenda-timerange-leaders)
  5026. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5027. head category tags
  5028. (cond ((and (= d1 d0) (= d2 d0))
  5029. (concat "<" start-time ">--<" end-time ">"))
  5030. ((= d1 d0)
  5031. (concat "<" start-time ">"))
  5032. ((= d2 d0)
  5033. (concat "<" end-time ">"))
  5034. (t nil))
  5035. remove-re))))
  5036. (org-add-props txt props
  5037. 'org-marker marker 'org-hd-marker hdmarker
  5038. 'type "block" 'date date
  5039. 'todo-state todo-state
  5040. 'priority (org-get-priority txt) 'org-category category
  5041. 'org-category-position category-pos)
  5042. (push txt ee))))
  5043. (goto-char pos)))
  5044. ;; Sort the entries by expiration date.
  5045. (nreverse ee)))
  5046. ;;; Agenda presentation and sorting
  5047. (defvar org-prefix-has-time nil
  5048. "A flag, set by `org-compile-prefix-format'.
  5049. The flag is set if the currently compiled format contains a `%t'.")
  5050. (defvar org-prefix-has-tag nil
  5051. "A flag, set by `org-compile-prefix-format'.
  5052. The flag is set if the currently compiled format contains a `%T'.")
  5053. (defvar org-prefix-has-effort nil
  5054. "A flag, set by `org-compile-prefix-format'.
  5055. The flag is set if the currently compiled format contains a `%e'.")
  5056. (defvar org-prefix-category-length nil
  5057. "Used by `org-compile-prefix-format' to remember the category field width.")
  5058. (defvar org-prefix-category-max-length nil
  5059. "Used by `org-compile-prefix-format' to remember the category field width.")
  5060. (defun org-agenda-get-category-icon (category)
  5061. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5062. (dolist (entry org-agenda-category-icon-alist)
  5063. (when (org-string-match-p (car entry) category)
  5064. (if (listp (cadr entry))
  5065. (return (cadr entry))
  5066. (return (apply 'create-image (cdr entry)))))))
  5067. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5068. remove-re habitp)
  5069. "Format TXT to be inserted into the agenda buffer.
  5070. In particular, it adds the prefix and corresponding text properties. EXTRA
  5071. must be a string and replaces the `%s' specifier in the prefix format.
  5072. CATEGORY (string, symbol or nil) may be used to overrule the default
  5073. category taken from local variable or file name. It will replace the `%c'
  5074. specifier in the format. DOTIME, when non-nil, indicates that a
  5075. time-of-day should be extracted from TXT for sorting of this entry, and for
  5076. the `%t' specifier in the format. When DOTIME is a string, this string is
  5077. searched for a time before TXT is. TAGS can be the tags of the headline.
  5078. Any match of REMOVE-RE will be removed from TXT."
  5079. (save-match-data
  5080. ;; Diary entries sometimes have extra whitespace at the beginning
  5081. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5082. ;; Fix the tags part in txt
  5083. (setq txt (org-agenda-fix-displayed-tags
  5084. txt tags
  5085. org-agenda-show-inherited-tags
  5086. org-agenda-hide-tags-regexp))
  5087. (let* ((category (or category
  5088. (if (stringp org-category)
  5089. org-category
  5090. (and org-category (symbol-name org-category)))
  5091. (if buffer-file-name
  5092. (file-name-sans-extension
  5093. (file-name-nondirectory buffer-file-name))
  5094. "")))
  5095. (category-icon (org-agenda-get-category-icon category))
  5096. (category-icon (if category-icon
  5097. (propertize " " 'display category-icon)
  5098. ""))
  5099. ;; time, tag, effort are needed for the eval of the prefix format
  5100. (tag (if tags (nth (1- (length tags)) tags) ""))
  5101. time effort neffort
  5102. (ts (if dotime (concat
  5103. (if (stringp dotime) dotime "")
  5104. (and org-agenda-search-headline-for-time txt))))
  5105. (time-of-day (and dotime (org-get-time-of-day ts)))
  5106. stamp plain s0 s1 s2 rtn srp l
  5107. duration thecategory)
  5108. (and (eq major-mode 'org-mode) buffer-file-name
  5109. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5110. (when (and dotime time-of-day)
  5111. ;; Extract starting and ending time and move them to prefix
  5112. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5113. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5114. (setq s0 (match-string 0 ts)
  5115. srp (and stamp (match-end 3))
  5116. s1 (match-string (if plain 1 2) ts)
  5117. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5118. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5119. ;; them, we might want to remove them there to avoid duplication.
  5120. ;; The user can turn this off with a variable.
  5121. (if (and org-prefix-has-time
  5122. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5123. (string-match (concat (regexp-quote s0) " *") txt)
  5124. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5125. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5126. (= (match-beginning 0) 0)
  5127. t))
  5128. (setq txt (replace-match "" nil nil txt))))
  5129. ;; Normalize the time(s) to 24 hour
  5130. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5131. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5132. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5133. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5134. (setq s2
  5135. (org-minutes-to-hh:mm-string
  5136. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5137. ;; Compute the duration
  5138. (when s2
  5139. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5140. (org-hh:mm-string-to-minutes s1)))))
  5141. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5142. txt)
  5143. ;; Tags are in the string
  5144. (if (or (eq org-agenda-remove-tags t)
  5145. (and org-agenda-remove-tags
  5146. org-prefix-has-tag))
  5147. (setq txt (replace-match "" t t txt))
  5148. (setq txt (replace-match
  5149. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5150. (match-string 2 txt))
  5151. t t txt))))
  5152. (when (eq major-mode 'org-mode)
  5153. (setq effort
  5154. (condition-case nil
  5155. (org-get-effort
  5156. (or (get-text-property 0 'org-hd-marker txt)
  5157. (get-text-property 0 'org-marker txt)))
  5158. (error nil)))
  5159. (when effort
  5160. (setq neffort (org-duration-string-to-minutes effort)
  5161. effort (setq effort (concat "[" effort "]")))))
  5162. ;; prevent erroring out with %e format when there is no effort
  5163. (or effort (setq effort ""))
  5164. (when remove-re
  5165. (while (string-match remove-re txt)
  5166. (setq txt (replace-match "" t t txt))))
  5167. ;; Set org-heading property on `txt' to mark the start of the
  5168. ;; heading.
  5169. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5170. ;; Prepare the variables needed in the eval of the compiled format
  5171. (setq time (cond (s2 (concat
  5172. (org-agenda-time-of-day-to-ampm-maybe s1)
  5173. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5174. (if org-agenda-timegrid-use-ampm " ")))
  5175. (s1 (concat
  5176. (org-agenda-time-of-day-to-ampm-maybe s1)
  5177. (if org-agenda-timegrid-use-ampm
  5178. "........ "
  5179. "......")))
  5180. (t ""))
  5181. extra (or (and (not habitp) extra) "")
  5182. category (if (symbolp category) (symbol-name category) category)
  5183. thecategory (copy-sequence category))
  5184. (if (string-match org-bracket-link-regexp category)
  5185. (progn
  5186. (setq l (if (match-end 3)
  5187. (- (match-end 3) (match-beginning 3))
  5188. (- (match-end 1) (match-beginning 1))))
  5189. (when (< l (or org-prefix-category-length 0))
  5190. (setq category (copy-sequence category))
  5191. (org-add-props category nil
  5192. 'extra-space (make-string
  5193. (- org-prefix-category-length l 1) ?\ ))))
  5194. (if (and org-prefix-category-max-length
  5195. (>= (length category) org-prefix-category-max-length))
  5196. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5197. ;; Evaluate the compiled format
  5198. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5199. ;; And finally add the text properties
  5200. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5201. (org-add-props rtn nil
  5202. 'org-category (if thecategory (downcase thecategory) category)
  5203. 'tags (mapcar 'org-downcase-keep-props tags)
  5204. 'org-highest-priority org-highest-priority
  5205. 'org-lowest-priority org-lowest-priority
  5206. 'time-of-day time-of-day
  5207. 'duration duration
  5208. 'effort effort
  5209. 'effort-minutes neffort
  5210. 'txt txt
  5211. 'time time
  5212. 'extra extra
  5213. 'format org-prefix-format-compiled
  5214. 'dotime dotime))))
  5215. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5216. "Remove tags string from TXT, and add a modified list of tags.
  5217. The modified list may contain inherited tags, and tags matched by
  5218. `org-agenda-hide-tags-regexp' will be removed."
  5219. (when (or add-inherited hide-re)
  5220. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5221. (setq txt (substring txt 0 (match-beginning 0))))
  5222. (setq tags
  5223. (delq nil
  5224. (mapcar (lambda (tg)
  5225. (if (or (and hide-re (string-match hide-re tg))
  5226. (and (not add-inherited)
  5227. (get-text-property 0 'inherited tg)))
  5228. nil
  5229. tg))
  5230. tags)))
  5231. (when tags
  5232. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5233. i)
  5234. (setq txt (concat txt " :"
  5235. (mapconcat
  5236. (lambda (x)
  5237. (setq i (get-text-property 0 'inherited x))
  5238. (if (and have-i (not i))
  5239. (progn
  5240. (setq have-i nil)
  5241. (concat ":" x))
  5242. x))
  5243. tags ":")
  5244. (if have-i "::" ":"))))))
  5245. txt)
  5246. (defun org-downcase-keep-props (s)
  5247. (let ((props (text-properties-at 0 s)))
  5248. (setq s (downcase s))
  5249. (add-text-properties 0 (length s) props s)
  5250. s))
  5251. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5252. (defvar org-agenda-sorting-strategy-selected nil)
  5253. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5254. (catch 'exit
  5255. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5256. ((and todayp (member 'today (car org-agenda-time-grid))))
  5257. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5258. ((member 'weekly (car org-agenda-time-grid)))
  5259. (t (throw 'exit list)))
  5260. (let* ((have (delq nil (mapcar
  5261. (lambda (x) (get-text-property 1 'time-of-day x))
  5262. list)))
  5263. (string (nth 1 org-agenda-time-grid))
  5264. (gridtimes (nth 2 org-agenda-time-grid))
  5265. (req (car org-agenda-time-grid))
  5266. (remove (member 'remove-match req))
  5267. new time)
  5268. (if (and (member 'require-timed req) (not have))
  5269. ;; don't show empty grid
  5270. (throw 'exit list))
  5271. (while (setq time (pop gridtimes))
  5272. (unless (and remove (member time have))
  5273. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5274. (push (org-format-agenda-item
  5275. nil string "" nil
  5276. (concat (substring time 0 -2) ":" (substring time -2)))
  5277. new)
  5278. (put-text-property
  5279. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5280. (when (and todayp org-agenda-show-current-time-in-grid)
  5281. (push (org-format-agenda-item
  5282. nil
  5283. org-agenda-current-time-string
  5284. "" nil
  5285. (format-time-string "%H:%M "))
  5286. new)
  5287. (put-text-property
  5288. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5289. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5290. (append new list)
  5291. (append list new)))))
  5292. (defun org-compile-prefix-format (key)
  5293. "Compile the prefix format into a Lisp form that can be evaluated.
  5294. The resulting form is returned and stored in the variable
  5295. `org-prefix-format-compiled'."
  5296. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5297. org-prefix-category-length nil
  5298. org-prefix-has-effort nil)
  5299. (let ((s (cond
  5300. ((stringp org-agenda-prefix-format)
  5301. org-agenda-prefix-format)
  5302. ((assq key org-agenda-prefix-format)
  5303. (cdr (assq key org-agenda-prefix-format)))
  5304. (t " %-12:c%?-12t% s")))
  5305. (start 0)
  5306. varform vars var e c f opt)
  5307. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5308. s start)
  5309. (setq var (or (cdr (assoc (match-string 4 s)
  5310. '(("c" . category) ("t" . time) ("s" . extra)
  5311. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5312. 'eval)
  5313. c (or (match-string 3 s) "")
  5314. opt (match-beginning 1)
  5315. start (1+ (match-beginning 0)))
  5316. (if (equal var 'time) (setq org-prefix-has-time t))
  5317. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5318. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5319. (setq f (concat "%" (match-string 2 s) "s"))
  5320. (when (equal var 'category)
  5321. (setq org-prefix-category-length
  5322. (floor (abs (string-to-number (match-string 2 s)))))
  5323. (setq org-prefix-category-max-length
  5324. (let ((x (match-string 2 s)))
  5325. (save-match-data
  5326. (if (string-match "\\.[0-9]+" x)
  5327. (string-to-number (substring (match-string 0 x) 1)))))))
  5328. (if (eq var 'eval)
  5329. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5330. (if opt
  5331. (setq varform
  5332. `(if (equal "" ,var)
  5333. ""
  5334. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5335. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5336. (setq s (replace-match "%s" t nil s))
  5337. (push varform vars))
  5338. (setq vars (nreverse vars))
  5339. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5340. (defun org-set-sorting-strategy (key)
  5341. (if (symbolp (car org-agenda-sorting-strategy))
  5342. ;; the old format
  5343. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5344. (setq org-agenda-sorting-strategy-selected
  5345. (or (cdr (assq key org-agenda-sorting-strategy))
  5346. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5347. '(time-up category-keep priority-down)))))
  5348. (defun org-get-time-of-day (s &optional string mod24)
  5349. "Check string S for a time of day.
  5350. If found, return it as a military time number between 0 and 2400.
  5351. If not found, return nil.
  5352. The optional STRING argument forces conversion into a 5 character wide string
  5353. HH:MM."
  5354. (save-match-data
  5355. (when
  5356. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5357. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5358. (let* ((h (string-to-number (match-string 1 s)))
  5359. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5360. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5361. (am-p (equal ampm "am"))
  5362. (h1 (cond ((not ampm) h)
  5363. ((= h 12) (if am-p 0 12))
  5364. (t (+ h (if am-p 0 12)))))
  5365. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5366. (mod h1 24) h1))
  5367. (t0 (+ (* 100 h2) m))
  5368. (t1 (concat (if (>= h1 24) "+" " ")
  5369. (if (and org-agenda-time-leading-zero
  5370. (< t0 1000)) "0" "")
  5371. (if (< t0 100) "0" "")
  5372. (if (< t0 10) "0" "")
  5373. (int-to-string t0))))
  5374. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5375. (defvar org-agenda-before-sorting-filter-function nil
  5376. "Function to be applied to agenda items prior to sorting.
  5377. Prior to sorting also means just before they are inserted into the agenda.
  5378. To aid sorting, you may revisit the original entries and add more text
  5379. properties which will later be used by the sorting functions.
  5380. The function should take a string argument, an agenda line.
  5381. It has access to the text properties in that line, which contain among
  5382. other things, the property `org-hd-marker' that points to the entry
  5383. where the line comes from. Note that not all lines going into the agenda
  5384. have this property, only most.
  5385. The function should return the modified string. It is probably best
  5386. to ONLY change text properties.
  5387. You can also use this function as a filter, by returning nil for lines
  5388. you don't want to have in the agenda at all. For this application, you
  5389. could bind the variable in the options section of a custom command.")
  5390. (defun org-finalize-agenda-entries (list &optional nosort)
  5391. "Sort and concatenate the agenda items."
  5392. (setq list (mapcar 'org-agenda-highlight-todo list))
  5393. (if nosort
  5394. list
  5395. (when org-agenda-before-sorting-filter-function
  5396. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5397. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5398. (defun org-agenda-highlight-todo (x)
  5399. (let ((org-done-keywords org-done-keywords-for-agenda)
  5400. (case-fold-search nil)
  5401. re)
  5402. (if (eq x 'line)
  5403. (save-excursion
  5404. (beginning-of-line 1)
  5405. (setq re (org-get-at-bol 'org-todo-regexp))
  5406. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5407. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5408. (add-text-properties (match-beginning 0) (match-end 1)
  5409. (list 'face (org-get-todo-face 1)))
  5410. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5411. (delete-region (match-beginning 1) (1- (match-end 0)))
  5412. (goto-char (match-beginning 1))
  5413. (insert (format org-agenda-todo-keyword-format s)))))
  5414. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5415. (setq re (get-text-property 0 'org-todo-regexp x))
  5416. (when (and re
  5417. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5418. x (or pl 0)) pl))
  5419. (add-text-properties
  5420. (or (match-end 1) (match-end 0)) (match-end 0)
  5421. (list 'face (org-get-todo-face (match-string 2 x)))
  5422. x)
  5423. (when (match-end 1)
  5424. (setq x (concat (substring x 0 (match-end 1))
  5425. (format org-agenda-todo-keyword-format
  5426. (match-string 2 x))
  5427. (org-add-props " " (text-properties-at 0 x))
  5428. (substring x (match-end 3)))))))
  5429. x)))
  5430. (defsubst org-cmp-priority (a b)
  5431. "Compare the priorities of string A and B."
  5432. (let ((pa (or (get-text-property 1 'priority a) 0))
  5433. (pb (or (get-text-property 1 'priority b) 0)))
  5434. (cond ((> pa pb) +1)
  5435. ((< pa pb) -1)
  5436. (t nil))))
  5437. (defsubst org-cmp-effort (a b)
  5438. "Compare the effort values of string A and B."
  5439. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5440. (ea (or (get-text-property 1 'effort-minutes a) def))
  5441. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5442. (cond ((> ea eb) +1)
  5443. ((< ea eb) -1)
  5444. (t nil))))
  5445. (defsubst org-cmp-category (a b)
  5446. "Compare the string values of categories of strings A and B."
  5447. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5448. (cb (or (get-text-property 1 'org-category b) "")))
  5449. (cond ((string-lessp ca cb) -1)
  5450. ((string-lessp cb ca) +1)
  5451. (t nil))))
  5452. (defsubst org-cmp-todo-state (a b)
  5453. "Compare the todo states of strings A and B."
  5454. (let* ((ma (or (get-text-property 1 'org-marker a)
  5455. (get-text-property 1 'org-hd-marker a)))
  5456. (mb (or (get-text-property 1 'org-marker b)
  5457. (get-text-property 1 'org-hd-marker b)))
  5458. (fa (and ma (marker-buffer ma)))
  5459. (fb (and mb (marker-buffer mb)))
  5460. (todo-kwds
  5461. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5462. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5463. (ta (or (get-text-property 1 'todo-state a) ""))
  5464. (tb (or (get-text-property 1 'todo-state b) ""))
  5465. (la (- (length (member ta todo-kwds))))
  5466. (lb (- (length (member tb todo-kwds))))
  5467. (donepa (member ta org-done-keywords-for-agenda))
  5468. (donepb (member tb org-done-keywords-for-agenda)))
  5469. (cond ((and donepa (not donepb)) -1)
  5470. ((and (not donepa) donepb) +1)
  5471. ((< la lb) -1)
  5472. ((< lb la) +1)
  5473. (t nil))))
  5474. (defsubst org-cmp-alpha (a b)
  5475. "Compare the headlines, alphabetically."
  5476. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5477. (plb (text-property-any 0 (length b) 'org-heading t b))
  5478. (ta (and pla (substring a pla)))
  5479. (tb (and plb (substring b plb))))
  5480. (when pla
  5481. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5482. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5483. (setq ta (substring ta (match-end 0))))
  5484. (setq ta (downcase ta)))
  5485. (when plb
  5486. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5487. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5488. (setq tb (substring tb (match-end 0))))
  5489. (setq tb (downcase tb)))
  5490. (cond ((not ta) +1)
  5491. ((not tb) -1)
  5492. ((string-lessp ta tb) -1)
  5493. ((string-lessp tb ta) +1)
  5494. (t nil))))
  5495. (defsubst org-cmp-tag (a b)
  5496. "Compare the string values of the first tags of A and B."
  5497. (let ((ta (car (last (get-text-property 1 'tags a))))
  5498. (tb (car (last (get-text-property 1 'tags b)))))
  5499. (cond ((not ta) +1)
  5500. ((not tb) -1)
  5501. ((string-lessp ta tb) -1)
  5502. ((string-lessp tb ta) +1)
  5503. (t nil))))
  5504. (defsubst org-cmp-time (a b)
  5505. "Compare the time-of-day values of strings A and B."
  5506. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5507. (ta (or (get-text-property 1 'time-of-day a) def))
  5508. (tb (or (get-text-property 1 'time-of-day b) def)))
  5509. (cond ((< ta tb) -1)
  5510. ((< tb ta) +1)
  5511. (t nil))))
  5512. (defsubst org-cmp-habit-p (a b)
  5513. "Compare the todo states of strings A and B."
  5514. (let ((ha (get-text-property 1 'org-habit-p a))
  5515. (hb (get-text-property 1 'org-habit-p b)))
  5516. (cond ((and ha (not hb)) -1)
  5517. ((and (not ha) hb) +1)
  5518. (t nil))))
  5519. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5520. (defun org-entries-lessp (a b)
  5521. "Predicate for sorting agenda entries."
  5522. ;; The following variables will be used when the form is evaluated.
  5523. ;; So even though the compiler complains, keep them.
  5524. (let* ((ss org-agenda-sorting-strategy-selected)
  5525. (time-up (and (org-em 'time-up 'time-down ss)
  5526. (org-cmp-time a b)))
  5527. (time-down (if time-up (- time-up) nil))
  5528. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5529. (org-cmp-priority a b)))
  5530. (priority-down (if priority-up (- priority-up) nil))
  5531. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5532. (org-cmp-effort a b)))
  5533. (effort-down (if effort-up (- effort-up) nil))
  5534. (category-up (and (or (org-em 'category-up 'category-down ss)
  5535. (memq 'category-keep ss))
  5536. (org-cmp-category a b)))
  5537. (category-down (if category-up (- category-up) nil))
  5538. (category-keep (if category-up +1 nil))
  5539. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5540. (org-cmp-tag a b)))
  5541. (tag-down (if tag-up (- tag-up) nil))
  5542. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5543. (org-cmp-todo-state a b)))
  5544. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5545. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5546. (org-cmp-habit-p a b)))
  5547. (habit-down (if habit-up (- habit-up) nil))
  5548. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5549. (org-cmp-alpha a b)))
  5550. (alpha-down (if alpha-up (- alpha-up) nil))
  5551. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5552. user-defined-up user-defined-down)
  5553. (if (and need-user-cmp org-agenda-cmp-user-defined
  5554. (functionp org-agenda-cmp-user-defined))
  5555. (setq user-defined-up
  5556. (funcall org-agenda-cmp-user-defined a b)
  5557. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5558. (cdr (assoc
  5559. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5560. '((-1 . t) (1 . nil) (nil . nil))))))
  5561. ;;; Agenda restriction lock
  5562. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5563. "Overlay to mark the headline to which agenda commands are restricted.")
  5564. (overlay-put org-agenda-restriction-lock-overlay
  5565. 'face 'org-agenda-restriction-lock)
  5566. (overlay-put org-agenda-restriction-lock-overlay
  5567. 'help-echo "Agendas are currently limited to this subtree.")
  5568. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5569. (defun org-agenda-set-restriction-lock (&optional type)
  5570. "Set restriction lock for agenda, to current subtree or file.
  5571. Restriction will be the file if TYPE is `file', or if type is the
  5572. universal prefix '(4), or if the cursor is before the first headline
  5573. in the file. Otherwise, restriction will be to the current subtree."
  5574. (interactive "P")
  5575. (and (equal type '(4)) (setq type 'file))
  5576. (setq type (cond
  5577. (type type)
  5578. ((org-at-heading-p) 'subtree)
  5579. ((condition-case nil (org-back-to-heading t) (error nil))
  5580. 'subtree)
  5581. (t 'file)))
  5582. (if (eq type 'subtree)
  5583. (progn
  5584. (setq org-agenda-restrict t)
  5585. (setq org-agenda-overriding-restriction 'subtree)
  5586. (put 'org-agenda-files 'org-restrict
  5587. (list (buffer-file-name (buffer-base-buffer))))
  5588. (org-back-to-heading t)
  5589. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5590. (move-marker org-agenda-restrict-begin (point))
  5591. (move-marker org-agenda-restrict-end
  5592. (save-excursion (org-end-of-subtree t)))
  5593. (message "Locking agenda restriction to subtree"))
  5594. (put 'org-agenda-files 'org-restrict
  5595. (list (buffer-file-name (buffer-base-buffer))))
  5596. (setq org-agenda-restrict nil)
  5597. (setq org-agenda-overriding-restriction 'file)
  5598. (move-marker org-agenda-restrict-begin nil)
  5599. (move-marker org-agenda-restrict-end nil)
  5600. (message "Locking agenda restriction to file"))
  5601. (setq current-prefix-arg nil)
  5602. (org-agenda-maybe-redo))
  5603. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5604. "Remove the agenda restriction lock."
  5605. (interactive "P")
  5606. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5607. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5608. (setq org-agenda-overriding-restriction nil)
  5609. (setq org-agenda-restrict nil)
  5610. (put 'org-agenda-files 'org-restrict nil)
  5611. (move-marker org-agenda-restrict-begin nil)
  5612. (move-marker org-agenda-restrict-end nil)
  5613. (setq current-prefix-arg nil)
  5614. (message "Agenda restriction lock removed")
  5615. (or noupdate (org-agenda-maybe-redo)))
  5616. (defun org-agenda-maybe-redo ()
  5617. "If there is any window showing the agenda view, update it."
  5618. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5619. (w0 (selected-window)))
  5620. (when w
  5621. (select-window w)
  5622. (org-agenda-redo)
  5623. (select-window w0)
  5624. (if org-agenda-overriding-restriction
  5625. (message "Agenda view shifted to new %s restriction"
  5626. org-agenda-overriding-restriction)
  5627. (message "Agenda restriction lock removed")))))
  5628. ;;; Agenda commands
  5629. (defun org-agenda-check-type (error &rest types)
  5630. "Check if agenda buffer is of allowed type.
  5631. If ERROR is non-nil, throw an error, otherwise just return nil."
  5632. (if (memq org-agenda-type types)
  5633. t
  5634. (if error
  5635. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5636. nil)))
  5637. (defun org-agenda-quit ()
  5638. "Exit agenda by removing the window or the buffer."
  5639. (interactive)
  5640. (if org-agenda-columns-active
  5641. (org-columns-quit)
  5642. (let ((buf (current-buffer)))
  5643. (if (eq org-agenda-window-setup 'other-frame)
  5644. (progn
  5645. (kill-buffer buf)
  5646. (org-agenda-reset-markers)
  5647. (org-columns-remove-overlays)
  5648. (setq org-agenda-archives-mode nil)
  5649. (delete-frame))
  5650. (and (not (eq org-agenda-window-setup 'current-window))
  5651. (not (one-window-p))
  5652. (delete-window))
  5653. (kill-buffer buf)
  5654. (org-agenda-reset-markers)
  5655. (org-columns-remove-overlays)
  5656. (setq org-agenda-archives-mode nil)))
  5657. ;; Maybe restore the pre-agenda window configuration.
  5658. (and org-agenda-restore-windows-after-quit
  5659. (not (eq org-agenda-window-setup 'other-frame))
  5660. org-pre-agenda-window-conf
  5661. (set-window-configuration org-pre-agenda-window-conf))))
  5662. (defun org-agenda-exit ()
  5663. "Exit agenda by removing the window or the buffer.
  5664. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5665. Org-mode buffers visited directly by the user will not be touched."
  5666. (interactive)
  5667. (org-release-buffers org-agenda-new-buffers)
  5668. (setq org-agenda-new-buffers nil)
  5669. (org-agenda-quit))
  5670. (defun org-agenda-execute (arg)
  5671. "Execute another agenda command, keeping same window.
  5672. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5673. in the agenda."
  5674. (interactive "P")
  5675. (let ((org-agenda-window-setup 'current-window))
  5676. (org-agenda arg)))
  5677. (defun org-agenda-redo ()
  5678. "Rebuild Agenda.
  5679. When this is the global TODO list, a prefix argument will be interpreted."
  5680. (interactive)
  5681. (let* ((org-agenda-keep-modes t)
  5682. (filter org-agenda-filter)
  5683. (preset (get 'org-agenda-filter :preset-filter))
  5684. (org-agenda-filter-while-redo (or filter preset))
  5685. (cols org-agenda-columns-active)
  5686. (line (org-current-line))
  5687. (window-line (- line (org-current-line (window-start))))
  5688. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5689. (put 'org-agenda-filter :preset-filter nil)
  5690. (and cols (org-columns-quit))
  5691. (message "Rebuilding agenda buffer...")
  5692. (org-let lprops '(eval org-agenda-redo-command))
  5693. (setq org-agenda-undo-list nil
  5694. org-agenda-pending-undo-list nil)
  5695. (message "Rebuilding agenda buffer...done")
  5696. (put 'org-agenda-filter :preset-filter preset)
  5697. (and (or filter preset) (org-agenda-filter-apply filter))
  5698. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5699. (org-goto-line line)
  5700. (recenter window-line)))
  5701. (defvar org-global-tags-completion-table nil)
  5702. (defvar org-agenda-filter-form nil)
  5703. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5704. "Keep only those lines in the agenda buffer that have a specific tag.
  5705. The tag is selected with its fast selection letter, as configured.
  5706. With prefix argument STRIP, remove all lines that do have the tag.
  5707. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5708. used to narrow the search - the interactive user can also press `-' or `+'
  5709. to switch to narrowing."
  5710. (interactive "P")
  5711. (let* ((alist org-tag-alist-for-agenda)
  5712. (tag-chars (mapconcat
  5713. (lambda (x) (if (and (not (symbolp (car x)))
  5714. (cdr x))
  5715. (char-to-string (cdr x))
  5716. ""))
  5717. alist ""))
  5718. (efforts (org-split-string
  5719. (or (cdr (assoc (concat org-effort-property "_ALL")
  5720. org-global-properties))
  5721. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5722. "")))
  5723. (effort-op org-agenda-filter-effort-default-operator)
  5724. (effort-prompt "")
  5725. (inhibit-read-only t)
  5726. (current org-agenda-filter)
  5727. maybe-refresh a n tag)
  5728. (unless char
  5729. (message
  5730. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5731. (if narrow "Narrow" "Filter") tag-chars
  5732. (if org-agenda-auto-exclude-function "[RET], " ""))
  5733. (setq char (read-char)))
  5734. (when (member char '(?+ ?-))
  5735. ;; Narrowing down
  5736. (cond ((equal char ?-) (setq strip t narrow t))
  5737. ((equal char ?+) (setq strip nil narrow t)))
  5738. (message
  5739. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5740. (setq char (read-char)))
  5741. (when (member char '(?< ?> ?= ??))
  5742. ;; An effort operator
  5743. (setq effort-op (char-to-string char))
  5744. (setq alist nil) ; to make sure it will be interpreted as effort.
  5745. (unless (equal char ??)
  5746. (loop for i from 0 to 9 do
  5747. (setq effort-prompt
  5748. (concat
  5749. effort-prompt " ["
  5750. (if (= i 9) "0" (int-to-string (1+ i)))
  5751. "]" (nth i efforts))))
  5752. (message "Effort%s: %s " effort-op effort-prompt)
  5753. (setq char (read-char))
  5754. (when (or (< char ?0) (> char ?9))
  5755. (error "Need 1-9,0 to select effort" ))))
  5756. (when (equal char ?\t)
  5757. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5758. (org-set-local 'org-global-tags-completion-table
  5759. (org-global-tags-completion-table)))
  5760. (let ((completion-ignore-case t))
  5761. (setq tag (org-icompleting-read
  5762. "Tag: " org-global-tags-completion-table))))
  5763. (cond
  5764. ((equal char ?\r)
  5765. (org-agenda-filter-by-tag-show-all)
  5766. (when org-agenda-auto-exclude-function
  5767. (setq org-agenda-filter '())
  5768. (dolist (tag (org-agenda-get-represented-tags))
  5769. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5770. (if modifier
  5771. (push modifier org-agenda-filter))))
  5772. (if (not (null org-agenda-filter))
  5773. (org-agenda-filter-apply org-agenda-filter)))
  5774. (setq maybe-refresh t))
  5775. ((equal char ?/)
  5776. (org-agenda-filter-by-tag-show-all)
  5777. (when (get 'org-agenda-filter :preset-filter)
  5778. (org-agenda-filter-apply org-agenda-filter))
  5779. (setq maybe-refresh t))
  5780. ((or (equal char ?\ )
  5781. (setq a (rassoc char alist))
  5782. (and (>= char ?0) (<= char ?9)
  5783. (setq n (if (= char ?0) 9 (- char ?0 1))
  5784. tag (concat effort-op (nth n efforts))
  5785. a (cons tag nil)))
  5786. (and (= char ??)
  5787. (setq tag "?eff")
  5788. a (cons tag nil))
  5789. (and tag (setq a (cons tag nil))))
  5790. (org-agenda-filter-by-tag-show-all)
  5791. (setq tag (car a))
  5792. (setq org-agenda-filter
  5793. (cons (concat (if strip "-" "+") tag)
  5794. (if narrow current nil)))
  5795. (org-agenda-filter-apply org-agenda-filter)
  5796. (setq maybe-refresh t))
  5797. (t (error "Invalid tag selection character %c" char)))
  5798. (when (and maybe-refresh
  5799. (eq org-agenda-clockreport-mode 'with-filter))
  5800. (org-agenda-redo))))
  5801. (defun org-agenda-get-represented-tags ()
  5802. "Get a list of all tags currently represented in the agenda."
  5803. (let (p tags)
  5804. (save-excursion
  5805. (goto-char (point-min))
  5806. (while (setq p (next-single-property-change (point) 'tags))
  5807. (goto-char p)
  5808. (mapc (lambda (x) (add-to-list 'tags x))
  5809. (get-text-property (point) 'tags))))
  5810. tags))
  5811. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5812. "Refine the current filter. See `org-agenda-filter-by-tag'."
  5813. (interactive "P")
  5814. (org-agenda-filter-by-tag strip char 'refine))
  5815. (defun org-agenda-filter-make-matcher ()
  5816. "Create the form that tests a line for the agenda filter."
  5817. (let (f f1)
  5818. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5819. org-agenda-filter))
  5820. (if (member x '("-" "+"))
  5821. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5822. (if (string-match "[<=>?]" x)
  5823. (setq f1 (org-agenda-filter-effort-form x))
  5824. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5825. (if (equal (string-to-char x) ?-)
  5826. (setq f1 (list 'not f1))))
  5827. (push f1 f))
  5828. (cons 'and (nreverse f))))
  5829. (defun org-agenda-filter-effort-form (e)
  5830. "Return the form to compare the effort of the current line with what E says.
  5831. E looks like \"+<2:25\"."
  5832. (let (op)
  5833. (setq e (substring e 1))
  5834. (setq op (string-to-char e) e (substring e 1))
  5835. (setq op (cond ((equal op ?<) '<=)
  5836. ((equal op ?>) '>=)
  5837. ((equal op ??) op)
  5838. (t '=)))
  5839. (list 'org-agenda-compare-effort (list 'quote op)
  5840. (org-duration-string-to-minutes e))))
  5841. (defun org-agenda-compare-effort (op value)
  5842. "Compare the effort of the current line with VALUE, using OP.
  5843. If the line does not have an effort defined, return nil."
  5844. (let ((eff (org-get-at-bol 'effort-minutes)))
  5845. (if (equal op ??)
  5846. (not eff)
  5847. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5848. value))))
  5849. (defun org-agenda-filter-apply (filter)
  5850. "Set FILTER as the new agenda filter and apply it."
  5851. (let (tags)
  5852. (setq org-agenda-filter filter
  5853. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5854. (org-agenda-set-mode-name)
  5855. (save-excursion
  5856. (goto-char (point-min))
  5857. (while (not (eobp))
  5858. (if (org-get-at-bol 'org-marker)
  5859. (progn
  5860. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5861. (if (not (eval org-agenda-filter-form))
  5862. (org-agenda-filter-by-tag-hide-line))
  5863. (beginning-of-line 2))
  5864. (beginning-of-line 2))))
  5865. (if (get-char-property (point) 'invisible)
  5866. (org-agenda-previous-line))))
  5867. (defun org-agenda-filter-by-tag-hide-line ()
  5868. (let (ov)
  5869. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5870. (point-at-eol)))
  5871. (overlay-put ov 'invisible t)
  5872. (overlay-put ov 'type 'tags-filter)
  5873. (push ov org-agenda-filter-overlays)))
  5874. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5875. (setq pos (or pos (point)))
  5876. (save-excursion
  5877. (dolist (ov (overlays-at pos))
  5878. (when (and (overlay-get ov 'invisible)
  5879. (eq (overlay-get ov 'type) 'tags-filter))
  5880. (goto-char pos)
  5881. (if (< (overlay-start ov) (point-at-eol))
  5882. (move-overlay ov (point-at-eol)
  5883. (overlay-end ov)))))))
  5884. (defun org-agenda-filter-by-tag-show-all ()
  5885. (mapc 'delete-overlay org-agenda-filter-overlays)
  5886. (setq org-agenda-filter-overlays nil)
  5887. (setq org-agenda-filter nil)
  5888. (setq org-agenda-filter-form nil)
  5889. (org-agenda-set-mode-name))
  5890. (defun org-agenda-manipulate-query-add ()
  5891. "Manipulate the query by adding a search term with positive selection.
  5892. Positive selection means the term must be matched for selection of an entry."
  5893. (interactive)
  5894. (org-agenda-manipulate-query ?\[))
  5895. (defun org-agenda-manipulate-query-subtract ()
  5896. "Manipulate the query by adding a search term with negative selection.
  5897. Negative selection means term must not be matched for selection of an entry."
  5898. (interactive)
  5899. (org-agenda-manipulate-query ?\]))
  5900. (defun org-agenda-manipulate-query-add-re ()
  5901. "Manipulate the query by adding a search regexp with positive selection.
  5902. Positive selection means the regexp must match for selection of an entry."
  5903. (interactive)
  5904. (org-agenda-manipulate-query ?\{))
  5905. (defun org-agenda-manipulate-query-subtract-re ()
  5906. "Manipulate the query by adding a search regexp with negative selection.
  5907. Negative selection means regexp must not match for selection of an entry."
  5908. (interactive)
  5909. (org-agenda-manipulate-query ?\}))
  5910. (defun org-agenda-manipulate-query (char)
  5911. (cond
  5912. ((memq org-agenda-type '(timeline agenda))
  5913. (let ((org-agenda-include-inactive-timestamps t))
  5914. (org-agenda-redo))
  5915. (message "Display now includes inactive timestamps as well"))
  5916. ((eq org-agenda-type 'search)
  5917. (org-add-to-string
  5918. 'org-agenda-query-string
  5919. (if org-agenda-last-search-view-search-was-boolean
  5920. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5921. (?\{ . " +{}") (?\} . " -{}"))))
  5922. " "))
  5923. (setq org-agenda-redo-command
  5924. (list 'org-search-view
  5925. org-todo-only
  5926. org-agenda-query-string
  5927. (+ (length org-agenda-query-string)
  5928. (if (member char '(?\{ ?\})) 0 1))))
  5929. (set-register org-agenda-query-register org-agenda-query-string)
  5930. (org-agenda-redo))
  5931. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5932. org-agenda-type))))
  5933. (defun org-add-to-string (var string)
  5934. (set var (concat (symbol-value var) string)))
  5935. (defun org-agenda-goto-date (date)
  5936. "Jump to DATE in agenda."
  5937. (interactive (list (let ((org-read-date-prefer-future
  5938. (eval org-agenda-jump-prefer-future)))
  5939. (org-read-date))))
  5940. (org-agenda-list nil date))
  5941. (defun org-agenda-goto-today ()
  5942. "Go to today."
  5943. (interactive)
  5944. (org-agenda-check-type t 'timeline 'agenda)
  5945. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5946. (cond
  5947. (tdpos (goto-char tdpos))
  5948. ((eq org-agenda-type 'agenda)
  5949. (let* ((sd (org-agenda-compute-starting-span
  5950. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5951. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5952. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5953. (org-agenda-redo)
  5954. (org-agenda-find-same-or-today-or-agenda)))
  5955. (t (error "Cannot find today")))))
  5956. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5957. (goto-char
  5958. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5959. (text-property-any (point-min) (point-max) 'org-today t)
  5960. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5961. (point-min))))
  5962. (defun org-agenda-later (arg)
  5963. "Go forward in time by thee current span.
  5964. With prefix ARG, go forward that many times the current span."
  5965. (interactive "p")
  5966. (org-agenda-check-type t 'agenda)
  5967. (let* ((span org-agenda-current-span)
  5968. (sd org-starting-day)
  5969. (greg (calendar-gregorian-from-absolute sd))
  5970. (cnt (org-get-at-bol 'org-day-cnt))
  5971. greg2)
  5972. (cond
  5973. ((eq span 'day)
  5974. (setq sd (+ arg sd)))
  5975. ((eq span 'week)
  5976. (setq sd (+ (* 7 arg) sd)))
  5977. ((eq span 'month)
  5978. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5979. sd (calendar-absolute-from-gregorian greg2))
  5980. (setcar greg2 (1+ (car greg2))))
  5981. ((eq span 'year)
  5982. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5983. sd (calendar-absolute-from-gregorian greg2))
  5984. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5985. (t
  5986. (setq sd (+ (* span arg) sd))))
  5987. (let ((org-agenda-overriding-arguments
  5988. (list (car org-agenda-last-arguments) sd span t)))
  5989. (org-agenda-redo)
  5990. (org-agenda-find-same-or-today-or-agenda cnt))))
  5991. (defun org-agenda-earlier (arg)
  5992. "Go backward in time by the current span.
  5993. With prefix ARG, go backward that many times the current span."
  5994. (interactive "p")
  5995. (org-agenda-later (- arg)))
  5996. (defun org-agenda-view-mode-dispatch ()
  5997. "Call one of the view mode commands."
  5998. (interactive)
  5999. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6000. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6001. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6002. [E]ntryText")
  6003. (let ((a (read-char-exclusive)))
  6004. (case a
  6005. (?\ (call-interactively 'org-agenda-reset-view))
  6006. (?d (call-interactively 'org-agenda-day-view))
  6007. (?w (call-interactively 'org-agenda-week-view))
  6008. (?m (call-interactively 'org-agenda-month-view))
  6009. (?y (call-interactively 'org-agenda-year-view))
  6010. (?l (call-interactively 'org-agenda-log-mode))
  6011. (?L (org-agenda-log-mode '(4)))
  6012. (?c (org-agenda-log-mode 'clockcheck))
  6013. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6014. (?a (call-interactively 'org-agenda-archives-mode))
  6015. (?A (org-agenda-archives-mode 'files))
  6016. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6017. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6018. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6019. (?D (call-interactively 'org-agenda-toggle-diary))
  6020. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6021. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6022. (org-agenda-check-type t 'timeline 'agenda)
  6023. (org-agenda-redo))
  6024. (message "Display now includes inactive timestamps as well"))
  6025. (?q (message "Abort"))
  6026. (otherwise (error "Invalid key" )))))
  6027. (defun org-agenda-reset-view ()
  6028. "Switch to default view for agenda."
  6029. (interactive)
  6030. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6031. (defun org-agenda-day-view (&optional day-of-year)
  6032. "Switch to daily view for agenda.
  6033. With argument DAY-OF-YEAR, switch to that day of the year."
  6034. (interactive "P")
  6035. (org-agenda-change-time-span 'day day-of-year))
  6036. (defun org-agenda-week-view (&optional iso-week)
  6037. "Switch to daily view for agenda.
  6038. With argument ISO-WEEK, switch to the corresponding ISO week.
  6039. If ISO-WEEK has more then 2 digits, only the last two encode the
  6040. week. Any digits before this encode a year. So 200712 means
  6041. week 12 of year 2007. Years in the range 1938-2037 can also be
  6042. written as 2-digit years."
  6043. (interactive "P")
  6044. (org-agenda-change-time-span 'week iso-week))
  6045. (defun org-agenda-month-view (&optional month)
  6046. "Switch to monthly view for agenda.
  6047. With argument MONTH, switch to that month."
  6048. (interactive "P")
  6049. (org-agenda-change-time-span 'month month))
  6050. (defun org-agenda-year-view (&optional year)
  6051. "Switch to yearly view for agenda.
  6052. With argument YEAR, switch to that year.
  6053. If MONTH has more then 2 digits, only the last two encode the
  6054. month. Any digits before this encode a year. So 200712 means
  6055. December year 2007. Years in the range 1938-2037 can also be
  6056. written as 2-digit years."
  6057. (interactive "P")
  6058. (when year
  6059. (setq year (org-small-year-to-year year)))
  6060. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6061. (org-agenda-change-time-span 'year year)
  6062. (error "Abort")))
  6063. (defun org-agenda-change-time-span (span &optional n)
  6064. "Change the agenda view to SPAN.
  6065. SPAN may be `day', `week', `month', `year'."
  6066. (org-agenda-check-type t 'agenda)
  6067. (if (and (not n) (equal org-agenda-current-span span))
  6068. (error "Viewing span is already \"%s\"" span))
  6069. (let* ((sd (or (org-get-at-bol 'day)
  6070. org-starting-day))
  6071. (sd (org-agenda-compute-starting-span sd span n))
  6072. (org-agenda-overriding-arguments
  6073. (or org-agenda-overriding-arguments
  6074. (list (car org-agenda-last-arguments) sd span t))))
  6075. (org-agenda-redo)
  6076. (org-agenda-find-same-or-today-or-agenda))
  6077. (org-agenda-set-mode-name)
  6078. (message "Switched to %s view" span))
  6079. (defun org-agenda-compute-starting-span (sd span &optional n)
  6080. "Compute starting date for agenda.
  6081. SPAN may be `day', `week', `month', `year'. The return value
  6082. is a cons cell with the starting date and the number of days,
  6083. so that the date SD will be in that range."
  6084. (let* ((greg (calendar-gregorian-from-absolute sd))
  6085. (dg (nth 1 greg))
  6086. (mg (car greg))
  6087. (yg (nth 2 greg)))
  6088. (cond
  6089. ((eq span 'day)
  6090. (when n
  6091. (setq sd (+ (calendar-absolute-from-gregorian
  6092. (list mg 1 yg))
  6093. n -1))))
  6094. ((eq span 'week)
  6095. (let* ((nt (calendar-day-of-week
  6096. (calendar-gregorian-from-absolute sd)))
  6097. (d (if org-agenda-start-on-weekday
  6098. (- nt org-agenda-start-on-weekday)
  6099. 0))
  6100. y1)
  6101. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6102. (when n
  6103. (require 'cal-iso)
  6104. (when (> n 99)
  6105. (setq y1 (org-small-year-to-year (/ n 100))
  6106. n (mod n 100)))
  6107. (setq sd
  6108. (calendar-absolute-from-iso
  6109. (list n 1
  6110. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6111. ((eq span 'month)
  6112. (let (y1)
  6113. (when (and n (> n 99))
  6114. (setq y1 (org-small-year-to-year (/ n 100))
  6115. n (mod n 100)))
  6116. (setq sd (calendar-absolute-from-gregorian
  6117. (list (or n mg) 1 (or y1 yg))))))
  6118. ((eq span 'year)
  6119. (setq sd (calendar-absolute-from-gregorian
  6120. (list 1 1 (or n yg))))))
  6121. sd))
  6122. (defun org-agenda-next-date-line (&optional arg)
  6123. "Jump to the next line indicating a date in agenda buffer."
  6124. (interactive "p")
  6125. (org-agenda-check-type t 'agenda 'timeline)
  6126. (beginning-of-line 1)
  6127. ;; This does not work if user makes date format that starts with a blank
  6128. (if (looking-at "^\\S-") (forward-char 1))
  6129. (if (not (re-search-forward "^\\S-" nil t arg))
  6130. (progn
  6131. (backward-char 1)
  6132. (error "No next date after this line in this buffer")))
  6133. (goto-char (match-beginning 0)))
  6134. (defun org-agenda-previous-date-line (&optional arg)
  6135. "Jump to the previous line indicating a date in agenda buffer."
  6136. (interactive "p")
  6137. (org-agenda-check-type t 'agenda 'timeline)
  6138. (beginning-of-line 1)
  6139. (if (not (re-search-backward "^\\S-" nil t arg))
  6140. (error "No previous date before this line in this buffer")))
  6141. ;; Initialize the highlight
  6142. (defvar org-hl (make-overlay 1 1))
  6143. (overlay-put org-hl 'face 'highlight)
  6144. (defun org-highlight (begin end &optional buffer)
  6145. "Highlight a region with overlay."
  6146. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6147. (defun org-unhighlight ()
  6148. "Detach overlay INDEX."
  6149. (org-detach-overlay org-hl))
  6150. ;; FIXME this is currently not used.
  6151. (defun org-highlight-until-next-command (beg end &optional buffer)
  6152. "Move the highlight overlay to BEG/END, remove it before the next command."
  6153. (org-highlight beg end buffer)
  6154. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6155. (defun org-unhighlight-once ()
  6156. "Remove the highlight from its position, and this function from the hook."
  6157. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6158. (org-unhighlight))
  6159. (defun org-agenda-follow-mode ()
  6160. "Toggle follow mode in an agenda buffer."
  6161. (interactive)
  6162. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6163. (org-agenda-set-mode-name)
  6164. (org-agenda-do-context-action)
  6165. (message "Follow mode is %s"
  6166. (if org-agenda-follow-mode "on" "off")))
  6167. (defun org-agenda-entry-text-mode (&optional arg)
  6168. "Toggle entry text mode in an agenda buffer."
  6169. (interactive "P")
  6170. (setq org-agenda-entry-text-mode (or (integerp arg)
  6171. (not org-agenda-entry-text-mode)))
  6172. (org-agenda-entry-text-hide)
  6173. (and org-agenda-entry-text-mode
  6174. (let ((org-agenda-entry-text-maxlines
  6175. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6176. (org-agenda-entry-text-show)))
  6177. (org-agenda-set-mode-name)
  6178. (message "Entry text mode is %s. Maximum number of lines is %d"
  6179. (if org-agenda-entry-text-mode "on" "off")
  6180. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6181. (defun org-agenda-clockreport-mode (&optional with-filter)
  6182. "Toggle clocktable mode in an agenda buffer.
  6183. With prefix arg WITH-FILTER, make the clocktable respect the current
  6184. agenda filter."
  6185. (interactive "P")
  6186. (org-agenda-check-type t 'agenda)
  6187. (if with-filter
  6188. (setq org-agenda-clockreport-mode 'with-filter)
  6189. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6190. (org-agenda-set-mode-name)
  6191. (org-agenda-redo)
  6192. (message "Clocktable mode is %s"
  6193. (if org-agenda-clockreport-mode "on" "off")))
  6194. (defun org-agenda-log-mode (&optional special)
  6195. "Toggle log mode in an agenda buffer.
  6196. With argument SPECIAL, show all possible log items, not only the ones
  6197. configured in `org-agenda-log-mode-items'.
  6198. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6199. (interactive "P")
  6200. (org-agenda-check-type t 'agenda 'timeline)
  6201. (setq org-agenda-show-log
  6202. (cond
  6203. ((equal special '(16)) 'only)
  6204. ((eq special 'clockcheck)
  6205. (if (eq org-agenda-show-log 'clockcheck)
  6206. nil 'clockcheck))
  6207. (special '(closed clock state))
  6208. (t (not org-agenda-show-log))))
  6209. (org-agenda-set-mode-name)
  6210. (org-agenda-redo)
  6211. (message "Log mode is %s"
  6212. (if org-agenda-show-log "on" "off")))
  6213. (defun org-agenda-archives-mode (&optional with-files)
  6214. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6215. When called with a prefix argument, include all archive files as well."
  6216. (interactive "P")
  6217. (setq org-agenda-archives-mode
  6218. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6219. (org-agenda-set-mode-name)
  6220. (org-agenda-redo)
  6221. (message
  6222. "%s"
  6223. (cond
  6224. ((eq org-agenda-archives-mode nil)
  6225. "No archives are included")
  6226. ((eq org-agenda-archives-mode 'trees)
  6227. (format "Trees with :%s: tag are included" org-archive-tag))
  6228. ((eq org-agenda-archives-mode t)
  6229. (format "Trees with :%s: tag and all active archive files are included"
  6230. org-archive-tag)))))
  6231. (defun org-agenda-toggle-diary ()
  6232. "Toggle diary inclusion in an agenda buffer."
  6233. (interactive)
  6234. (org-agenda-check-type t 'agenda)
  6235. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6236. (org-agenda-redo)
  6237. (org-agenda-set-mode-name)
  6238. (message "Diary inclusion turned %s"
  6239. (if org-agenda-include-diary "on" "off")))
  6240. (defun org-agenda-toggle-deadlines ()
  6241. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6242. (interactive)
  6243. (org-agenda-check-type t 'agenda)
  6244. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6245. (org-agenda-redo)
  6246. (org-agenda-set-mode-name)
  6247. (message "Deadlines inclusion turned %s"
  6248. (if org-agenda-include-deadlines "on" "off")))
  6249. (defun org-agenda-toggle-time-grid ()
  6250. "Toggle time grid in an agenda buffer."
  6251. (interactive)
  6252. (org-agenda-check-type t 'agenda)
  6253. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6254. (org-agenda-redo)
  6255. (org-agenda-set-mode-name)
  6256. (message "Time-grid turned %s"
  6257. (if org-agenda-use-time-grid "on" "off")))
  6258. (defun org-agenda-set-mode-name ()
  6259. "Set the mode name to indicate all the small mode settings."
  6260. (setq mode-name
  6261. (list "Org-Agenda"
  6262. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6263. " "
  6264. '(:eval (org-agenda-span-name org-agenda-current-span))
  6265. (if org-agenda-follow-mode " Follow" "")
  6266. (if org-agenda-entry-text-mode " ETxt" "")
  6267. (if org-agenda-include-diary " Diary" "")
  6268. (if org-agenda-include-deadlines " Ddl" "")
  6269. (if org-agenda-use-time-grid " Grid" "")
  6270. (if (and (boundp 'org-habit-show-habits)
  6271. org-habit-show-habits) " Habit" "")
  6272. (cond
  6273. ((consp org-agenda-show-log) " LogAll")
  6274. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6275. (org-agenda-show-log " Log")
  6276. (t ""))
  6277. (if (or org-agenda-filter (get 'org-agenda-filter
  6278. :preset-filter))
  6279. (concat " {" (mapconcat
  6280. 'identity
  6281. (append (get 'org-agenda-filter
  6282. :preset-filter)
  6283. org-agenda-filter) "") "}")
  6284. "")
  6285. (if org-agenda-archives-mode
  6286. (if (eq org-agenda-archives-mode t)
  6287. " Archives"
  6288. (format " :%s:" org-archive-tag))
  6289. "")
  6290. (if org-agenda-clockreport-mode
  6291. (if (eq org-agenda-clockreport-mode 'with-filter)
  6292. " Clock{}" " Clock")
  6293. "")))
  6294. (force-mode-line-update))
  6295. (defun org-agenda-post-command-hook ()
  6296. (setq org-agenda-type
  6297. (or (get-text-property (point) 'org-agenda-type)
  6298. (get-text-property (max (point-min) (1- (point)))
  6299. 'org-agenda-type))))
  6300. (defun org-agenda-next-line ()
  6301. "Move cursor to the next line, and show if follow mode is active."
  6302. (interactive)
  6303. (call-interactively 'next-line)
  6304. (org-agenda-do-context-action))
  6305. (defun org-agenda-previous-line ()
  6306. "Move cursor to the previous line, and show if follow-mode is active."
  6307. (interactive)
  6308. (call-interactively 'previous-line)
  6309. (org-agenda-do-context-action))
  6310. (defun org-agenda-do-context-action ()
  6311. "Show outline path and, maybe, follow mode window."
  6312. (let ((m (org-get-at-bol 'org-marker)))
  6313. (when (and (markerp m) (marker-buffer m))
  6314. (and org-agenda-follow-mode
  6315. (if org-agenda-follow-indirect
  6316. (org-agenda-tree-to-indirect-buffer)
  6317. (org-agenda-show)))
  6318. (and org-agenda-show-outline-path
  6319. (org-with-point-at m (org-display-outline-path t))))))
  6320. (defun org-agenda-show-priority ()
  6321. "Show the priority of the current item.
  6322. This priority is composed of the main priority given with the [#A] cookies,
  6323. and by additional input from the age of a schedules or deadline entry."
  6324. (interactive)
  6325. (let* ((pri (org-get-at-bol 'priority)))
  6326. (message "Priority is %d" (if pri pri -1000))))
  6327. (defun org-agenda-show-tags ()
  6328. "Show the tags applicable to the current item."
  6329. (interactive)
  6330. (let* ((tags (org-get-at-bol 'tags)))
  6331. (if tags
  6332. (message "Tags are :%s:"
  6333. (org-no-properties (mapconcat 'identity tags ":")))
  6334. (message "No tags associated with this line"))))
  6335. (defun org-agenda-goto (&optional highlight)
  6336. "Go to the Org-mode file which contains the item at point."
  6337. (interactive)
  6338. (let* ((marker (or (org-get-at-bol 'org-marker)
  6339. (org-agenda-error)))
  6340. (buffer (marker-buffer marker))
  6341. (pos (marker-position marker)))
  6342. (switch-to-buffer-other-window buffer)
  6343. (widen)
  6344. (push-mark)
  6345. (goto-char pos)
  6346. (when (eq major-mode 'org-mode)
  6347. (org-show-context 'agenda)
  6348. (save-excursion
  6349. (and (outline-next-heading)
  6350. (org-flag-heading nil)))) ; show the next heading
  6351. (when (outline-invisible-p)
  6352. (show-entry)) ; display invisible text
  6353. (recenter (/ (window-height) 2))
  6354. (run-hooks 'org-agenda-after-show-hook)
  6355. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6356. (defvar org-agenda-after-show-hook nil
  6357. "Normal hook run after an item has been shown from the agenda.
  6358. Point is in the buffer where the item originated.")
  6359. (defun org-agenda-kill ()
  6360. "Kill the entry or subtree belonging to the current agenda entry."
  6361. (interactive)
  6362. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6363. (let* ((marker (or (org-get-at-bol 'org-marker)
  6364. (org-agenda-error)))
  6365. (buffer (marker-buffer marker))
  6366. (pos (marker-position marker))
  6367. (type (org-get-at-bol 'type))
  6368. dbeg dend (n 0) conf)
  6369. (org-with-remote-undo buffer
  6370. (with-current-buffer buffer
  6371. (save-excursion
  6372. (goto-char pos)
  6373. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6374. (setq dbeg (progn (org-back-to-heading t) (point))
  6375. dend (org-end-of-subtree t t))
  6376. (setq dbeg (point-at-bol)
  6377. dend (min (point-max) (1+ (point-at-eol)))))
  6378. (goto-char dbeg)
  6379. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6380. (setq conf (or (eq t org-agenda-confirm-kill)
  6381. (and (numberp org-agenda-confirm-kill)
  6382. (> n org-agenda-confirm-kill))))
  6383. (and conf
  6384. (not (y-or-n-p
  6385. (format "Delete entry with %d lines in buffer \"%s\"? "
  6386. n (buffer-name buffer))))
  6387. (error "Abort"))
  6388. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6389. (with-current-buffer buffer (delete-region dbeg dend))
  6390. (message "Agenda item and source killed"))))
  6391. (defvar org-archive-default-command)
  6392. (defun org-agenda-archive-default ()
  6393. "Archive the entry or subtree belonging to the current agenda entry."
  6394. (interactive)
  6395. (require 'org-archive)
  6396. (org-agenda-archive-with org-archive-default-command))
  6397. (defun org-agenda-archive-default-with-confirmation ()
  6398. "Archive the entry or subtree belonging to the current agenda entry."
  6399. (interactive)
  6400. (require 'org-archive)
  6401. (org-agenda-archive-with org-archive-default-command 'confirm))
  6402. (defun org-agenda-archive ()
  6403. "Archive the entry or subtree belonging to the current agenda entry."
  6404. (interactive)
  6405. (org-agenda-archive-with 'org-archive-subtree))
  6406. (defun org-agenda-archive-to-archive-sibling ()
  6407. "Move the entry to the archive sibling."
  6408. (interactive)
  6409. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6410. (defun org-agenda-archive-with (cmd &optional confirm)
  6411. "Move the entry to the archive sibling."
  6412. (interactive)
  6413. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6414. (let* ((marker (or (org-get-at-bol 'org-marker)
  6415. (org-agenda-error)))
  6416. (buffer (marker-buffer marker))
  6417. (pos (marker-position marker)))
  6418. (org-with-remote-undo buffer
  6419. (with-current-buffer buffer
  6420. (if (eq major-mode 'org-mode)
  6421. (if (and confirm
  6422. (not (y-or-n-p "Archive this subtree or entry? ")))
  6423. (error "Abort")
  6424. (save-excursion
  6425. (goto-char pos)
  6426. (org-remove-subtree-entries-from-agenda)
  6427. (org-back-to-heading t)
  6428. (funcall cmd)))
  6429. (error "Archiving works only in Org-mode files"))))))
  6430. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6431. "Remove all lines in the agenda that correspond to a given subtree.
  6432. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6433. If this information is not given, the function uses the tree at point."
  6434. (let ((buf (or buf (current-buffer))) m p)
  6435. (save-excursion
  6436. (unless (and beg end)
  6437. (org-back-to-heading t)
  6438. (setq beg (point))
  6439. (org-end-of-subtree t)
  6440. (setq end (point)))
  6441. (set-buffer (get-buffer org-agenda-buffer-name))
  6442. (save-excursion
  6443. (goto-char (point-max))
  6444. (beginning-of-line 1)
  6445. (while (not (bobp))
  6446. (when (and (setq m (org-get-at-bol 'org-marker))
  6447. (equal buf (marker-buffer m))
  6448. (setq p (marker-position m))
  6449. (>= p beg)
  6450. (< p end))
  6451. (let ((inhibit-read-only t))
  6452. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6453. (beginning-of-line 0))))))
  6454. (defun org-agenda-refile (&optional goto rfloc no-update)
  6455. "Refile the item at point."
  6456. (interactive "P")
  6457. (if (equal goto '(16))
  6458. (org-refile-goto-last-stored)
  6459. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6460. (org-agenda-error)))
  6461. (buffer (marker-buffer marker))
  6462. (pos (marker-position marker))
  6463. (rfloc (or rfloc
  6464. (org-refile-get-location
  6465. (if goto "Goto" "Refile to") buffer
  6466. org-refile-allow-creating-parent-nodes))))
  6467. (with-current-buffer buffer
  6468. (save-excursion
  6469. (save-restriction
  6470. (widen)
  6471. (goto-char marker)
  6472. (org-remove-subtree-entries-from-agenda)
  6473. (org-refile goto buffer rfloc)))))
  6474. (unless no-update (org-agenda-redo))))
  6475. (defun org-agenda-open-link (&optional arg)
  6476. "Follow the link in the current line, if any.
  6477. This looks for a link in the displayed line in the agenda. It also looks
  6478. at the text of the entry itself."
  6479. (interactive "P")
  6480. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6481. (org-get-at-bol 'org-marker)))
  6482. (buffer (and marker (marker-buffer marker)))
  6483. (prefix (buffer-substring
  6484. (point-at-bol) (point-at-eol))))
  6485. (cond
  6486. (buffer
  6487. (with-current-buffer buffer
  6488. (save-excursion
  6489. (save-restriction
  6490. (widen)
  6491. (goto-char marker)
  6492. (org-offer-links-in-entry arg prefix)))))
  6493. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6494. (save-excursion
  6495. (beginning-of-line 1)
  6496. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6497. (org-open-link-from-string (match-string 1)))
  6498. (t (error "No link to open here")))))
  6499. (defun org-agenda-copy-local-variable (var)
  6500. "Get a variable from a referenced buffer and install it here."
  6501. (let ((m (org-get-at-bol 'org-marker)))
  6502. (when (and m (buffer-live-p (marker-buffer m)))
  6503. (org-set-local var (with-current-buffer (marker-buffer m)
  6504. (symbol-value var))))))
  6505. (defun org-agenda-switch-to (&optional delete-other-windows)
  6506. "Go to the Org-mode file which contains the item at point."
  6507. (interactive)
  6508. (if (and org-return-follows-link
  6509. (not (org-get-at-bol 'org-marker))
  6510. (org-in-regexp org-bracket-link-regexp))
  6511. (org-open-link-from-string (match-string 0))
  6512. (let* ((marker (or (org-get-at-bol 'org-marker)
  6513. (org-agenda-error)))
  6514. (buffer (marker-buffer marker))
  6515. (pos (marker-position marker)))
  6516. (org-pop-to-buffer-same-window buffer)
  6517. (and delete-other-windows (delete-other-windows))
  6518. (widen)
  6519. (goto-char pos)
  6520. (when (eq major-mode 'org-mode)
  6521. (org-show-context 'agenda)
  6522. (save-excursion
  6523. (and (outline-next-heading)
  6524. (org-flag-heading nil))) ; show the next heading
  6525. (when (outline-invisible-p)
  6526. (show-entry)))))) ; display invisible text
  6527. (defun org-agenda-goto-mouse (ev)
  6528. "Go to the Org-mode file which contains the item at the mouse click."
  6529. (interactive "e")
  6530. (mouse-set-point ev)
  6531. (org-agenda-goto))
  6532. (defun org-agenda-show (&optional full-entry)
  6533. "Display the Org-mode file which contains the item at point.
  6534. With prefix argument FULL-ENTRY, make the entire entry visible
  6535. if it was hidden in the outline."
  6536. (interactive "P")
  6537. (let ((win (selected-window)))
  6538. (if full-entry
  6539. (let ((org-show-entry-below t))
  6540. (org-agenda-goto t))
  6541. (org-agenda-goto t))
  6542. (select-window win)))
  6543. (defvar org-agenda-show-window nil)
  6544. (defun org-agenda-show-and-scroll-up ()
  6545. "Display the Org-mode file which contains the item at point.
  6546. When called repeatedly, scroll the window that is displaying the buffer."
  6547. (interactive)
  6548. (let ((win (selected-window)))
  6549. (if (and (window-live-p org-agenda-show-window)
  6550. (eq this-command last-command))
  6551. (progn
  6552. (select-window org-agenda-show-window)
  6553. (ignore-errors (scroll-up)))
  6554. (org-agenda-goto t)
  6555. (show-subtree)
  6556. (setq org-agenda-show-window (selected-window)))
  6557. (select-window win)))
  6558. (defun org-agenda-show-scroll-down ()
  6559. "Scroll down the window showing the agenda."
  6560. (interactive)
  6561. (let ((win (selected-window)))
  6562. (when (window-live-p org-agenda-show-window)
  6563. (select-window org-agenda-show-window)
  6564. (ignore-errors (scroll-down))
  6565. (select-window win))))
  6566. (defun org-agenda-show-1 (&optional more)
  6567. "Display the Org-mode file which contains the item at point.
  6568. The prefix arg selects the amount of information to display:
  6569. 0 hide the subtree
  6570. 1 just show the entry according to defaults.
  6571. 2 show the children view
  6572. 3 show the subtree view
  6573. 4 show the entire subtree and any LOGBOOK drawers
  6574. 5 show the entire subtree and any drawers
  6575. With prefix argument FULL-ENTRY, make the entire entry visible
  6576. if it was hidden in the outline."
  6577. (interactive "p")
  6578. (let ((win (selected-window)))
  6579. (org-agenda-goto t)
  6580. (org-recenter-heading 1)
  6581. (cond
  6582. ((= more 0)
  6583. (hide-subtree)
  6584. (save-excursion
  6585. (org-back-to-heading)
  6586. (run-hook-with-args 'org-cycle-hook 'folded))
  6587. (message "Remote: FOLDED"))
  6588. ((and (org-called-interactively-p 'any) (= more 1))
  6589. (message "Remote: show with default settings"))
  6590. ((= more 2)
  6591. (show-entry)
  6592. (show-children)
  6593. (save-excursion
  6594. (org-back-to-heading)
  6595. (run-hook-with-args 'org-cycle-hook 'children))
  6596. (message "Remote: CHILDREN"))
  6597. ((= more 3)
  6598. (show-subtree)
  6599. (save-excursion
  6600. (org-back-to-heading)
  6601. (run-hook-with-args 'org-cycle-hook 'subtree))
  6602. (message "Remote: SUBTREE"))
  6603. ((= more 4)
  6604. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6605. (org-drawer-regexp
  6606. (concat "^[ \t]*:\\("
  6607. (mapconcat 'regexp-quote org-drawers "\\|")
  6608. "\\):[ \t]*$")))
  6609. (show-subtree)
  6610. (save-excursion
  6611. (org-back-to-heading)
  6612. (org-cycle-hide-drawers 'subtree)))
  6613. (message "Remote: SUBTREE AND LOGBOOK"))
  6614. ((> more 4)
  6615. (show-subtree)
  6616. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6617. (select-window win)))
  6618. (defun org-recenter-heading (n)
  6619. (save-excursion
  6620. (org-back-to-heading)
  6621. (recenter n)))
  6622. (defvar org-agenda-cycle-counter nil)
  6623. (defun org-agenda-cycle-show (&optional n)
  6624. "Show the current entry in another window, with default settings.
  6625. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6626. When use repeatedly in immediate succession, the remote entry will cycle
  6627. through visibility
  6628. children -> subtree -> folded
  6629. When called with a numeric prefix arg, that arg will be passed through to
  6630. `org-agenda-show-1'. For the interpretation of that argument, see the
  6631. docstring of `org-agenda-show-1'."
  6632. (interactive "P")
  6633. (if (integerp n)
  6634. (setq org-agenda-cycle-counter n)
  6635. (if (not (eq last-command this-command))
  6636. (setq org-agenda-cycle-counter 1)
  6637. (if (equal org-agenda-cycle-counter 0)
  6638. (setq org-agenda-cycle-counter 2)
  6639. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6640. (if (> org-agenda-cycle-counter 3)
  6641. (setq org-agenda-cycle-counter 0)))))
  6642. (org-agenda-show-1 org-agenda-cycle-counter))
  6643. (defun org-agenda-recenter (arg)
  6644. "Display the Org-mode file which contains the item at point and recenter."
  6645. (interactive "P")
  6646. (let ((win (selected-window)))
  6647. (org-agenda-goto t)
  6648. (recenter arg)
  6649. (select-window win)))
  6650. (defun org-agenda-show-mouse (ev)
  6651. "Display the Org-mode file which contains the item at the mouse click."
  6652. (interactive "e")
  6653. (mouse-set-point ev)
  6654. (org-agenda-show))
  6655. (defun org-agenda-check-no-diary ()
  6656. "Check if the entry is a diary link and abort if yes."
  6657. (if (org-get-at-bol 'org-agenda-diary-link)
  6658. (org-agenda-error)))
  6659. (defun org-agenda-error ()
  6660. (error "Command not allowed in this line"))
  6661. (defun org-agenda-tree-to-indirect-buffer ()
  6662. "Show the subtree corresponding to the current entry in an indirect buffer.
  6663. This calls the command `org-tree-to-indirect-buffer' from the original
  6664. Org-mode buffer.
  6665. With numerical prefix arg ARG, go up to this level and then take that tree.
  6666. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6667. use the dedicated frame)."
  6668. (interactive)
  6669. (org-agenda-check-no-diary)
  6670. (let* ((marker (or (org-get-at-bol 'org-marker)
  6671. (org-agenda-error)))
  6672. (buffer (marker-buffer marker))
  6673. (pos (marker-position marker)))
  6674. (with-current-buffer buffer
  6675. (save-excursion
  6676. (goto-char pos)
  6677. (call-interactively 'org-tree-to-indirect-buffer)))))
  6678. (defvar org-last-heading-marker (make-marker)
  6679. "Marker pointing to the headline that last changed its TODO state
  6680. by a remote command from the agenda.")
  6681. (defun org-agenda-todo-nextset ()
  6682. "Switch TODO entry to next sequence."
  6683. (interactive)
  6684. (org-agenda-todo 'nextset))
  6685. (defun org-agenda-todo-previousset ()
  6686. "Switch TODO entry to previous sequence."
  6687. (interactive)
  6688. (org-agenda-todo 'previousset))
  6689. (defun org-agenda-todo (&optional arg)
  6690. "Cycle TODO state of line at point, also in Org-mode file.
  6691. This changes the line at point, all other lines in the agenda referring to
  6692. the same tree node, and the headline of the tree node in the Org-mode file."
  6693. (interactive "P")
  6694. (org-agenda-check-no-diary)
  6695. (let* ((col (current-column))
  6696. (marker (or (org-get-at-bol 'org-marker)
  6697. (org-agenda-error)))
  6698. (buffer (marker-buffer marker))
  6699. (pos (marker-position marker))
  6700. (hdmarker (org-get-at-bol 'org-hd-marker))
  6701. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6702. (inhibit-read-only t)
  6703. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6704. (org-with-remote-undo buffer
  6705. (with-current-buffer buffer
  6706. (widen)
  6707. (goto-char pos)
  6708. (org-show-context 'agenda)
  6709. (save-excursion
  6710. (and (outline-next-heading)
  6711. (org-flag-heading nil))) ; show the next heading
  6712. (let ((current-prefix-arg arg))
  6713. (call-interactively 'org-todo))
  6714. (and (bolp) (forward-char 1))
  6715. (setq newhead (org-get-heading))
  6716. (when (and (org-bound-and-true-p
  6717. org-agenda-headline-snapshot-before-repeat)
  6718. (not (equal org-agenda-headline-snapshot-before-repeat
  6719. newhead))
  6720. todayp)
  6721. (setq newhead org-agenda-headline-snapshot-before-repeat
  6722. just-one t))
  6723. (save-excursion
  6724. (org-back-to-heading)
  6725. (move-marker org-last-heading-marker (point))))
  6726. (beginning-of-line 1)
  6727. (save-excursion
  6728. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6729. (org-move-to-column col))))
  6730. (defun org-agenda-add-note (&optional arg)
  6731. "Add a time-stamped note to the entry at point."
  6732. (interactive "P")
  6733. (org-agenda-check-no-diary)
  6734. (let* ((marker (or (org-get-at-bol 'org-marker)
  6735. (org-agenda-error)))
  6736. (buffer (marker-buffer marker))
  6737. (pos (marker-position marker))
  6738. (hdmarker (org-get-at-bol 'org-hd-marker))
  6739. (inhibit-read-only t))
  6740. (with-current-buffer buffer
  6741. (widen)
  6742. (goto-char pos)
  6743. (org-show-context 'agenda)
  6744. (save-excursion
  6745. (and (outline-next-heading)
  6746. (org-flag-heading nil))) ; show the next heading
  6747. (org-add-note))))
  6748. (defun org-agenda-change-all-lines (newhead hdmarker
  6749. &optional fixface just-this)
  6750. "Change all lines in the agenda buffer which match HDMARKER.
  6751. The new content of the line will be NEWHEAD (as modified by
  6752. `org-format-agenda-item'). HDMARKER is checked with
  6753. `equal' against all `org-hd-marker' text properties in the file.
  6754. If FIXFACE is non-nil, the face of each item is modified according to
  6755. the new TODO state.
  6756. If JUST-THIS is non-nil, change just the current line, not all.
  6757. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6758. (let* ((inhibit-read-only t)
  6759. (line (org-current-line))
  6760. (thetags (with-current-buffer (marker-buffer hdmarker)
  6761. (save-excursion (save-restriction (widen)
  6762. (goto-char hdmarker)
  6763. (org-get-tags-at)))))
  6764. props m pl undone-face done-face finish new dotime cat tags)
  6765. (save-excursion
  6766. (goto-char (point-max))
  6767. (beginning-of-line 1)
  6768. (while (not finish)
  6769. (setq finish (bobp))
  6770. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6771. (or (not just-this) (= (org-current-line) line))
  6772. (equal m hdmarker))
  6773. (setq props (text-properties-at (point))
  6774. dotime (org-get-at-bol 'dotime)
  6775. cat (org-get-at-bol 'org-category)
  6776. tags thetags
  6777. new
  6778. (let ((org-prefix-format-compiled
  6779. (or (get-text-property (point) 'format)
  6780. org-prefix-format-compiled)))
  6781. (with-current-buffer (marker-buffer hdmarker)
  6782. (save-excursion
  6783. (save-restriction
  6784. (widen)
  6785. (org-format-agenda-item (org-get-at-bol 'extra)
  6786. newhead cat tags dotime)))))
  6787. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6788. undone-face (org-get-at-bol 'undone-face)
  6789. done-face (org-get-at-bol 'done-face))
  6790. (beginning-of-line 1)
  6791. (cond
  6792. ((equal new "")
  6793. (and (looking-at ".*\n?") (replace-match "")))
  6794. ((looking-at ".*")
  6795. (replace-match new t t)
  6796. (beginning-of-line 1)
  6797. (add-text-properties (point-at-bol) (point-at-eol) props)
  6798. (when fixface
  6799. (add-text-properties
  6800. (point-at-bol) (point-at-eol)
  6801. (list 'face
  6802. (if org-last-todo-state-is-todo
  6803. undone-face done-face))))
  6804. (org-agenda-highlight-todo 'line)
  6805. (beginning-of-line 1))
  6806. (t (error "Line update did not work"))))
  6807. (beginning-of-line 0)))
  6808. (org-finalize-agenda)))
  6809. (defun org-agenda-align-tags (&optional line)
  6810. "Align all tags in agenda items to `org-agenda-tags-column'."
  6811. (let ((inhibit-read-only t) l c)
  6812. (save-excursion
  6813. (goto-char (if line (point-at-bol) (point-min)))
  6814. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6815. (if line (point-at-eol) nil) t)
  6816. (add-text-properties
  6817. (match-beginning 2) (match-end 2)
  6818. (list 'face (delq nil (let ((prop (get-text-property
  6819. (match-beginning 2) 'face)))
  6820. (or (listp prop) (setq prop (list prop)))
  6821. (if (memq 'org-tag prop)
  6822. prop
  6823. (cons 'org-tag prop))))))
  6824. (setq l (- (match-end 2) (match-beginning 2))
  6825. c (if (< org-agenda-tags-column 0)
  6826. (- (abs org-agenda-tags-column) l)
  6827. org-agenda-tags-column))
  6828. (delete-region (match-beginning 1) (match-end 1))
  6829. (goto-char (match-beginning 1))
  6830. (insert (org-add-props
  6831. (make-string (max 1 (- c (current-column))) ?\ )
  6832. (plist-put (copy-sequence (text-properties-at (point)))
  6833. 'face nil))))
  6834. (goto-char (point-min))
  6835. (org-font-lock-add-tag-faces (point-max)))))
  6836. (defun org-agenda-priority-up ()
  6837. "Increase the priority of line at point, also in Org-mode file."
  6838. (interactive)
  6839. (org-agenda-priority 'up))
  6840. (defun org-agenda-priority-down ()
  6841. "Decrease the priority of line at point, also in Org-mode file."
  6842. (interactive)
  6843. (org-agenda-priority 'down))
  6844. (defun org-agenda-priority (&optional force-direction)
  6845. "Set the priority of line at point, also in Org-mode file.
  6846. This changes the line at point, all other lines in the agenda referring to
  6847. the same tree node, and the headline of the tree node in the Org-mode file."
  6848. (interactive)
  6849. (unless org-enable-priority-commands
  6850. (error "Priority commands are disabled"))
  6851. (org-agenda-check-no-diary)
  6852. (let* ((marker (or (org-get-at-bol 'org-marker)
  6853. (org-agenda-error)))
  6854. (hdmarker (org-get-at-bol 'org-hd-marker))
  6855. (buffer (marker-buffer hdmarker))
  6856. (pos (marker-position hdmarker))
  6857. (inhibit-read-only t)
  6858. newhead)
  6859. (org-with-remote-undo buffer
  6860. (with-current-buffer buffer
  6861. (widen)
  6862. (goto-char pos)
  6863. (org-show-context 'agenda)
  6864. (save-excursion
  6865. (and (outline-next-heading)
  6866. (org-flag-heading nil))) ; show the next heading
  6867. (funcall 'org-priority force-direction)
  6868. (end-of-line 1)
  6869. (setq newhead (org-get-heading)))
  6870. (org-agenda-change-all-lines newhead hdmarker)
  6871. (beginning-of-line 1))))
  6872. ;; FIXME: should fix the tags property of the agenda line.
  6873. (defun org-agenda-set-tags (&optional tag onoff)
  6874. "Set tags for the current headline."
  6875. (interactive)
  6876. (org-agenda-check-no-diary)
  6877. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6878. (call-interactively 'org-change-tag-in-region)
  6879. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6880. (org-agenda-error)))
  6881. (buffer (marker-buffer hdmarker))
  6882. (pos (marker-position hdmarker))
  6883. (inhibit-read-only t)
  6884. newhead)
  6885. (org-with-remote-undo buffer
  6886. (with-current-buffer buffer
  6887. (widen)
  6888. (goto-char pos)
  6889. (save-excursion
  6890. (org-show-context 'agenda))
  6891. (save-excursion
  6892. (and (outline-next-heading)
  6893. (org-flag-heading nil))) ; show the next heading
  6894. (goto-char pos)
  6895. (if tag
  6896. (org-toggle-tag tag onoff)
  6897. (call-interactively 'org-set-tags))
  6898. (end-of-line 1)
  6899. (setq newhead (org-get-heading)))
  6900. (org-agenda-change-all-lines newhead hdmarker)
  6901. (beginning-of-line 1)))))
  6902. (defun org-agenda-set-property ()
  6903. "Set a property for the current headline."
  6904. (interactive)
  6905. (org-agenda-check-no-diary)
  6906. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6907. (org-agenda-error)))
  6908. (buffer (marker-buffer hdmarker))
  6909. (pos (marker-position hdmarker))
  6910. (inhibit-read-only t)
  6911. newhead)
  6912. (org-with-remote-undo buffer
  6913. (with-current-buffer buffer
  6914. (widen)
  6915. (goto-char pos)
  6916. (save-excursion
  6917. (org-show-context 'agenda))
  6918. (save-excursion
  6919. (and (outline-next-heading)
  6920. (org-flag-heading nil))) ; show the next heading
  6921. (goto-char pos)
  6922. (call-interactively 'org-set-property)))))
  6923. (defun org-agenda-set-effort ()
  6924. "Set the effort property for the current headline."
  6925. (interactive)
  6926. (org-agenda-check-no-diary)
  6927. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6928. (org-agenda-error)))
  6929. (buffer (marker-buffer hdmarker))
  6930. (pos (marker-position hdmarker))
  6931. (inhibit-read-only t)
  6932. newhead)
  6933. (org-with-remote-undo buffer
  6934. (with-current-buffer buffer
  6935. (widen)
  6936. (goto-char pos)
  6937. (save-excursion
  6938. (org-show-context 'agenda))
  6939. (save-excursion
  6940. (and (outline-next-heading)
  6941. (org-flag-heading nil))) ; show the next heading
  6942. (goto-char pos)
  6943. (call-interactively 'org-set-effort)
  6944. (end-of-line 1)
  6945. (setq newhead (org-get-heading)))
  6946. (org-agenda-change-all-lines newhead hdmarker))))
  6947. (defun org-agenda-toggle-archive-tag ()
  6948. "Toggle the archive tag for the current entry."
  6949. (interactive)
  6950. (org-agenda-check-no-diary)
  6951. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6952. (org-agenda-error)))
  6953. (buffer (marker-buffer hdmarker))
  6954. (pos (marker-position hdmarker))
  6955. (inhibit-read-only t)
  6956. newhead)
  6957. (org-with-remote-undo buffer
  6958. (with-current-buffer buffer
  6959. (widen)
  6960. (goto-char pos)
  6961. (org-show-context 'agenda)
  6962. (save-excursion
  6963. (and (outline-next-heading)
  6964. (org-flag-heading nil))) ; show the next heading
  6965. (call-interactively 'org-toggle-archive-tag)
  6966. (end-of-line 1)
  6967. (setq newhead (org-get-heading)))
  6968. (org-agenda-change-all-lines newhead hdmarker)
  6969. (beginning-of-line 1))))
  6970. (defun org-agenda-do-date-later (arg)
  6971. (interactive "P")
  6972. (cond
  6973. ((or (equal arg '(16))
  6974. (memq last-command
  6975. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6976. (setq this-command 'org-agenda-date-later-minutes)
  6977. (org-agenda-date-later-minutes 1))
  6978. ((or (equal arg '(4))
  6979. (memq last-command
  6980. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6981. (setq this-command 'org-agenda-date-later-hours)
  6982. (org-agenda-date-later-hours 1))
  6983. (t
  6984. (org-agenda-date-later (prefix-numeric-value arg)))))
  6985. (defun org-agenda-do-date-earlier (arg)
  6986. (interactive "P")
  6987. (cond
  6988. ((or (equal arg '(16))
  6989. (memq last-command
  6990. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6991. (setq this-command 'org-agenda-date-earlier-minutes)
  6992. (org-agenda-date-earlier-minutes 1))
  6993. ((or (equal arg '(4))
  6994. (memq last-command
  6995. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6996. (setq this-command 'org-agenda-date-earlier-hours)
  6997. (org-agenda-date-earlier-hours 1))
  6998. (t
  6999. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7000. (defun org-agenda-date-later (arg &optional what)
  7001. "Change the date of this item to ARG day(s) later."
  7002. (interactive "p")
  7003. (org-agenda-check-type t 'agenda 'timeline)
  7004. (org-agenda-check-no-diary)
  7005. (let* ((marker (or (org-get-at-bol 'org-marker)
  7006. (org-agenda-error)))
  7007. (buffer (marker-buffer marker))
  7008. (pos (marker-position marker))
  7009. cdate today)
  7010. (org-with-remote-undo buffer
  7011. (with-current-buffer buffer
  7012. (widen)
  7013. (goto-char pos)
  7014. (if (not (org-at-timestamp-p))
  7015. (error "Cannot find time stamp"))
  7016. (when (and org-agenda-move-date-from-past-immediately-to-today
  7017. (equal arg 1)
  7018. (or (not what) (eq what 'day))
  7019. (not (save-match-data (org-at-date-range-p))))
  7020. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7021. cdate (calendar-absolute-from-gregorian
  7022. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7023. today (org-today))
  7024. (if (> today cdate)
  7025. ;; immediately shift to today
  7026. (setq arg (- today cdate))))
  7027. (org-timestamp-change arg (or what 'day))
  7028. (when (and (org-at-date-range-p)
  7029. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7030. (let ((end org-last-changed-timestamp))
  7031. (org-timestamp-change arg (or what 'day))
  7032. (setq org-last-changed-timestamp
  7033. (concat org-last-changed-timestamp "--" end)))))
  7034. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7035. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7036. (defun org-agenda-date-earlier (arg &optional what)
  7037. "Change the date of this item to ARG day(s) earlier."
  7038. (interactive "p")
  7039. (org-agenda-date-later (- arg) what))
  7040. (defun org-agenda-date-later-minutes (arg)
  7041. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7042. (interactive "p")
  7043. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7044. (org-agenda-date-later arg 'minute))
  7045. (defun org-agenda-date-earlier-minutes (arg)
  7046. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7047. (interactive "p")
  7048. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7049. (org-agenda-date-earlier arg 'minute))
  7050. (defun org-agenda-date-later-hours (arg)
  7051. "Change the time of this item, in hour steps."
  7052. (interactive "p")
  7053. (org-agenda-date-later arg 'hour))
  7054. (defun org-agenda-date-earlier-hours (arg)
  7055. "Change the time of this item, in hour steps."
  7056. (interactive "p")
  7057. (org-agenda-date-earlier arg 'hour))
  7058. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7059. "Show new date stamp via text properties."
  7060. ;; We use text properties to make this undoable
  7061. (let ((inhibit-read-only t)
  7062. (buffer-invisibility-spec))
  7063. (setq stamp (concat " " prefix " => " stamp))
  7064. (save-excursion
  7065. (goto-char (point-max))
  7066. (while (not (bobp))
  7067. (when (equal marker (org-get-at-bol 'org-marker))
  7068. (org-move-to-column (- (window-width) (length stamp)) t)
  7069. (org-agenda-fix-tags-filter-overlays-at (point))
  7070. (if (featurep 'xemacs)
  7071. ;; Use `duplicable' property to trigger undo recording
  7072. (let ((ex (make-extent nil nil))
  7073. (gl (make-glyph stamp)))
  7074. (set-glyph-face gl 'secondary-selection)
  7075. (set-extent-properties
  7076. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7077. (insert-extent ex (1- (point)) (point-at-eol)))
  7078. (add-text-properties
  7079. (1- (point)) (point-at-eol)
  7080. (list 'display (org-add-props stamp nil
  7081. 'face 'secondary-selection))))
  7082. (beginning-of-line 1))
  7083. (beginning-of-line 0)))))
  7084. (defun org-agenda-date-prompt (arg)
  7085. "Change the date of this item. Date is prompted for, with default today.
  7086. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7087. be used to request time specification in the time stamp."
  7088. (interactive "P")
  7089. (org-agenda-check-type t 'agenda 'timeline)
  7090. (org-agenda-check-no-diary)
  7091. (let* ((marker (or (org-get-at-bol 'org-marker)
  7092. (org-agenda-error)))
  7093. (buffer (marker-buffer marker))
  7094. (pos (marker-position marker)))
  7095. (org-with-remote-undo buffer
  7096. (with-current-buffer buffer
  7097. (widen)
  7098. (goto-char pos)
  7099. (if (not (org-at-timestamp-p t))
  7100. (error "Cannot find time stamp"))
  7101. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7102. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7103. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7104. (defun org-agenda-schedule (arg &optional time)
  7105. "Schedule the item at point.
  7106. ARG is passed through to `org-schedule'."
  7107. (interactive "P")
  7108. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7109. (org-agenda-check-no-diary)
  7110. (let* ((marker (or (org-get-at-bol 'org-marker)
  7111. (org-agenda-error)))
  7112. (type (marker-insertion-type marker))
  7113. (buffer (marker-buffer marker))
  7114. (pos (marker-position marker))
  7115. (org-insert-labeled-timestamps-at-point nil)
  7116. ts)
  7117. (set-marker-insertion-type marker t)
  7118. (org-with-remote-undo buffer
  7119. (with-current-buffer buffer
  7120. (widen)
  7121. (goto-char pos)
  7122. (setq ts (org-schedule arg time)))
  7123. (org-agenda-show-new-time marker ts "S"))
  7124. (message "Item scheduled for %s" ts)))
  7125. (defun org-agenda-deadline (arg &optional time)
  7126. "Schedule the item at point.
  7127. ARG is passed through to `org-deadline'."
  7128. (interactive "P")
  7129. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7130. (org-agenda-check-no-diary)
  7131. (let* ((marker (or (org-get-at-bol 'org-marker)
  7132. (org-agenda-error)))
  7133. (buffer (marker-buffer marker))
  7134. (pos (marker-position marker))
  7135. (org-insert-labeled-timestamps-at-point nil)
  7136. ts)
  7137. (org-with-remote-undo buffer
  7138. (with-current-buffer buffer
  7139. (widen)
  7140. (goto-char pos)
  7141. (setq ts (org-deadline arg time)))
  7142. (org-agenda-show-new-time marker ts "D"))
  7143. (message "Deadline for this item set to %s" ts)))
  7144. (defun org-agenda-action ()
  7145. "Select entry for agenda action, or execute an agenda action.
  7146. This command prompts for another letter. Valid inputs are:
  7147. m Mark the entry at point for an agenda action
  7148. s Schedule the marked entry to the date at the cursor
  7149. d Set the deadline of the marked entry to the date at the cursor
  7150. r Call `org-remember' with cursor date as the default date
  7151. c Call `org-capture' with cursor date as the default date
  7152. SPC Show marked entry in other window
  7153. TAB Visit marked entry in other window
  7154. The cursor may be at a date in the calendar, or in the Org agenda."
  7155. (interactive)
  7156. (let (ans)
  7157. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7158. (setq ans (read-char-exclusive))
  7159. (cond
  7160. ((equal ans ?m)
  7161. ;; Mark this entry
  7162. (if (eq major-mode 'org-agenda-mode)
  7163. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7164. (org-get-at-bol 'org-marker))))
  7165. (if m
  7166. (progn
  7167. (move-marker org-agenda-action-marker
  7168. (marker-position m) (marker-buffer m))
  7169. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7170. (error "Don't know which entry to mark")))
  7171. (error "This command works only in the agenda")))
  7172. ((equal ans ?s)
  7173. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7174. ((equal ans ?d)
  7175. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7176. ((equal ans ?r)
  7177. (org-agenda-do-action '(org-remember) t))
  7178. ((equal ans ?c)
  7179. (org-agenda-do-action '(org-capture) t))
  7180. ((equal ans ?\ )
  7181. (let ((cw (selected-window)))
  7182. (org-switch-to-buffer-other-window
  7183. (marker-buffer org-agenda-action-marker))
  7184. (goto-char org-agenda-action-marker)
  7185. (org-show-context 'agenda)
  7186. (select-window cw)))
  7187. ((equal ans ?\C-i)
  7188. (org-switch-to-buffer-other-window
  7189. (marker-buffer org-agenda-action-marker))
  7190. (goto-char org-agenda-action-marker)
  7191. (org-show-context 'agenda))
  7192. (t (error "Invalid agenda action %c" ans)))))
  7193. (defun org-agenda-do-action (form &optional current-buffer)
  7194. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7195. (let ((org-overriding-default-time (org-get-cursor-date)))
  7196. (if current-buffer
  7197. (eval form)
  7198. (if (not (marker-buffer org-agenda-action-marker))
  7199. (error "No entry has been selected for agenda action")
  7200. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7201. (save-excursion
  7202. (save-restriction
  7203. (widen)
  7204. (goto-char org-agenda-action-marker)
  7205. (eval form))))))))
  7206. (defun org-agenda-clock-in (&optional arg)
  7207. "Start the clock on the currently selected item."
  7208. (interactive "P")
  7209. (org-agenda-check-no-diary)
  7210. (if (equal arg '(4))
  7211. (org-clock-in arg)
  7212. (let* ((marker (or (org-get-at-bol 'org-marker)
  7213. (org-agenda-error)))
  7214. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7215. marker))
  7216. (pos (marker-position marker))
  7217. newhead)
  7218. (org-with-remote-undo (marker-buffer marker)
  7219. (with-current-buffer (marker-buffer marker)
  7220. (widen)
  7221. (goto-char pos)
  7222. (org-show-context 'agenda)
  7223. (org-show-entry)
  7224. (org-cycle-hide-drawers 'children)
  7225. (org-clock-in arg)
  7226. (setq newhead (org-get-heading)))
  7227. (org-agenda-change-all-lines newhead hdmarker)))))
  7228. (defun org-agenda-clock-out ()
  7229. "Stop the currently running clock."
  7230. (interactive)
  7231. (unless (marker-buffer org-clock-marker)
  7232. (error "No running clock"))
  7233. (let ((marker (make-marker)) newhead)
  7234. (org-with-remote-undo (marker-buffer org-clock-marker)
  7235. (with-current-buffer (marker-buffer org-clock-marker)
  7236. (save-excursion
  7237. (save-restriction
  7238. (widen)
  7239. (goto-char org-clock-marker)
  7240. (org-back-to-heading t)
  7241. (move-marker marker (point))
  7242. (org-clock-out)
  7243. (setq newhead (org-get-heading))))))
  7244. (org-agenda-change-all-lines newhead marker)
  7245. (move-marker marker nil)))
  7246. (defun org-agenda-clock-cancel (&optional arg)
  7247. "Cancel the currently running clock."
  7248. (interactive "P")
  7249. (unless (marker-buffer org-clock-marker)
  7250. (error "No running clock"))
  7251. (org-with-remote-undo (marker-buffer org-clock-marker)
  7252. (org-clock-cancel)))
  7253. (defun org-agenda-clock-goto ()
  7254. "Jump to the currently clocked in task within the agenda.
  7255. If the currently clocked in task is not listed in the agenda
  7256. buffer, display it in another window."
  7257. (interactive)
  7258. (let (pos)
  7259. (mapc (lambda (o)
  7260. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7261. (setq pos (overlay-start o))))
  7262. (overlays-in (point-min) (point-max)))
  7263. (cond (pos (goto-char pos))
  7264. ;; If the currently clocked entry is not in the agenda
  7265. ;; buffer, we visit it in another window:
  7266. (org-clock-current-task
  7267. (org-switch-to-buffer-other-window (org-clock-goto)))
  7268. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7269. (defun org-agenda-diary-entry-in-org-file ()
  7270. "Make a diary entry in the file `org-agenda-diary-file'."
  7271. (let (d1 d2 char (text "") dp1 dp2)
  7272. (if (equal (buffer-name) "*Calendar*")
  7273. (setq d1 (calendar-cursor-to-date t)
  7274. d2 (car calendar-mark-ring))
  7275. (setq dp1 (get-text-property (point-at-bol) 'day))
  7276. (unless dp1 (error "No date defined in current line"))
  7277. (setq d1 (calendar-gregorian-from-absolute dp1)
  7278. d2 (and (ignore-errors (mark))
  7279. (save-excursion
  7280. (goto-char (mark))
  7281. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7282. (calendar-gregorian-from-absolute dp2))))
  7283. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7284. (setq char (read-char-exclusive))
  7285. (cond
  7286. ((equal char ?d)
  7287. (setq text (read-string "Day entry: "))
  7288. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7289. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7290. ((equal char ?a)
  7291. (setq d1 (list (car d1) (nth 1 d1)
  7292. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7293. (nth 2 d1))))
  7294. (setq text (read-string "Anniversary (use %d to show years): "))
  7295. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7296. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7297. ((equal char ?b)
  7298. (setq text (read-string "Block entry: "))
  7299. (unless (and d1 d2 (not (equal d1 d2)))
  7300. (error "No block of days selected"))
  7301. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7302. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7303. ((equal char ?j)
  7304. (org-switch-to-buffer-other-window
  7305. (find-file-noselect org-agenda-diary-file))
  7306. (require 'org-datetree)
  7307. (org-datetree-find-date-create d1)
  7308. (org-reveal t))
  7309. (t (error "Invalid selection character `%c'" char)))))
  7310. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7311. "Where in `org-agenda-diary-file' should new entries be added?
  7312. Valid values:
  7313. date-tree in the date tree, as child of the date
  7314. top-level as top-level entries at the end of the file."
  7315. :group 'org-agenda
  7316. :type '(choice
  7317. (const :tag "in a date tree" date-tree)
  7318. (const :tag "as top level at end of file" top-level)))
  7319. (defcustom org-agenda-insert-diary-extract-time nil
  7320. "Non-nil means extract any time specification from the diary entry."
  7321. :group 'org-agenda
  7322. :type 'boolean)
  7323. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7324. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7325. If TEXT is not empty, it will become the headline of the new entry, and
  7326. the resulting entry will not be shown. When TEXT is empty, switch to
  7327. `org-agenda-diary-file' and let the user finish the entry there."
  7328. (let ((cw (current-window-configuration)))
  7329. (org-switch-to-buffer-other-window
  7330. (find-file-noselect org-agenda-diary-file))
  7331. (widen)
  7332. (goto-char (point-min))
  7333. (cond
  7334. ((eq type 'anniversary)
  7335. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7336. (progn
  7337. (or (org-on-heading-p t)
  7338. (progn
  7339. (outline-next-heading)
  7340. (insert "* Anniversaries\n\n")
  7341. (beginning-of-line -1)))))
  7342. (outline-next-heading)
  7343. (org-back-over-empty-lines)
  7344. (backward-char 1)
  7345. (insert "\n")
  7346. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7347. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7348. ((eq type 'day)
  7349. (let ((org-prefix-has-time t)
  7350. (org-agenda-time-leading-zero t)
  7351. fmt time time2)
  7352. (if org-agenda-insert-diary-extract-time
  7353. ;; Use org-format-agenda-item to parse text for a time-range and
  7354. ;; remove it. FIXME: This is a hack, we should refactor
  7355. ;; that function to make time extraction available separately
  7356. (setq fmt (org-format-agenda-item nil text nil nil t)
  7357. time (get-text-property 0 'time fmt)
  7358. time2 (if (> (length time) 0)
  7359. ;; split-string removes trailing ...... if
  7360. ;; no end time given. First space
  7361. ;; separates time from date.
  7362. (concat " " (car (split-string time "\\.")))
  7363. nil)
  7364. text (get-text-property 0 'txt fmt)))
  7365. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7366. (org-agenda-insert-diary-as-top-level text)
  7367. (require 'org-datetree)
  7368. (org-datetree-find-date-create d1)
  7369. (org-agenda-insert-diary-make-new-entry text))
  7370. (org-insert-time-stamp (org-time-from-absolute
  7371. (calendar-absolute-from-gregorian d1))
  7372. nil nil nil nil time2))
  7373. (end-of-line 0))
  7374. ((eq type 'block)
  7375. (if (> (calendar-absolute-from-gregorian d1)
  7376. (calendar-absolute-from-gregorian d2))
  7377. (setq d1 (prog1 d2 (setq d2 d1))))
  7378. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7379. (org-agenda-insert-diary-as-top-level text)
  7380. (require 'org-datetree)
  7381. (org-datetree-find-date-create d1)
  7382. (org-agenda-insert-diary-make-new-entry text))
  7383. (org-insert-time-stamp (org-time-from-absolute
  7384. (calendar-absolute-from-gregorian d1)))
  7385. (insert "--")
  7386. (org-insert-time-stamp (org-time-from-absolute
  7387. (calendar-absolute-from-gregorian d2)))
  7388. (end-of-line 0)))
  7389. (if (string-match "\\S-" text)
  7390. (progn
  7391. (set-window-configuration cw)
  7392. (message "%s entry added to %s"
  7393. (capitalize (symbol-name type))
  7394. (abbreviate-file-name org-agenda-diary-file)))
  7395. (org-reveal t)
  7396. (message "Please finish entry here"))))
  7397. (defun org-agenda-insert-diary-as-top-level (text)
  7398. "Make new entry as a top-level entry at the end of the file.
  7399. Add TEXT as headline, and position the cursor in the second line so that
  7400. a timestamp can be added there."
  7401. (widen)
  7402. (goto-char (point-max))
  7403. (or (bolp) (insert "\n"))
  7404. (insert "* " text "\n")
  7405. (if org-adapt-indentation (org-indent-to-column 2)))
  7406. (defun org-agenda-insert-diary-make-new-entry (text)
  7407. "Make new entry as last child of current entry.
  7408. Add TEXT as headline, and position the cursor in the second line so that
  7409. a timestamp can be added there."
  7410. (let ((org-show-following-heading t)
  7411. (org-show-siblings t)
  7412. (org-show-hierarchy-above t)
  7413. (org-show-entry-below t)
  7414. col)
  7415. (outline-next-heading)
  7416. (org-back-over-empty-lines)
  7417. (or (looking-at "[ \t]*$")
  7418. (progn (insert "\n") (backward-char 1)))
  7419. (org-insert-heading nil t)
  7420. (org-do-demote)
  7421. (setq col (current-column))
  7422. (insert text "\n")
  7423. (if org-adapt-indentation (org-indent-to-column col))
  7424. (let ((org-show-following-heading t)
  7425. (org-show-siblings t)
  7426. (org-show-hierarchy-above t)
  7427. (org-show-entry-below t))
  7428. (org-show-context))))
  7429. (defun org-agenda-diary-entry ()
  7430. "Make a diary entry, like the `i' command from the calendar.
  7431. All the standard commands work: block, weekly etc.
  7432. When `org-agenda-diary-file' points to a file,
  7433. `org-agenda-diary-entry-in-org-file' is called instead to create
  7434. entries in that Org-mode file."
  7435. (interactive)
  7436. (org-agenda-check-type t 'agenda 'timeline)
  7437. (if (not (eq org-agenda-diary-file 'diary-file))
  7438. (org-agenda-diary-entry-in-org-file)
  7439. (require 'diary-lib)
  7440. (let* ((char (progn
  7441. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7442. (read-char-exclusive)))
  7443. (cmd (cdr (assoc char
  7444. '((?d . insert-diary-entry)
  7445. (?w . insert-weekly-diary-entry)
  7446. (?m . insert-monthly-diary-entry)
  7447. (?y . insert-yearly-diary-entry)
  7448. (?a . insert-anniversary-diary-entry)
  7449. (?b . insert-block-diary-entry)
  7450. (?c . insert-cyclic-diary-entry)))))
  7451. (oldf (symbol-function 'calendar-cursor-to-date))
  7452. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7453. (point (point))
  7454. (mark (or (mark t) (point))))
  7455. (unless cmd
  7456. (error "No command associated with <%c>" char))
  7457. (unless (and (get-text-property point 'day)
  7458. (or (not (equal ?b char))
  7459. (get-text-property mark 'day)))
  7460. (error "Don't know which date to use for diary entry"))
  7461. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7462. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7463. (let ((calendar-mark-ring
  7464. (list (calendar-gregorian-from-absolute
  7465. (or (get-text-property mark 'day)
  7466. (get-text-property point 'day))))))
  7467. (unwind-protect
  7468. (progn
  7469. (fset 'calendar-cursor-to-date
  7470. (lambda (&optional error dummy)
  7471. (calendar-gregorian-from-absolute
  7472. (get-text-property point 'day))))
  7473. (call-interactively cmd))
  7474. (fset 'calendar-cursor-to-date oldf))))))
  7475. (defun org-agenda-execute-calendar-command (cmd)
  7476. "Execute a calendar command from the agenda, with the date associated to
  7477. the cursor position."
  7478. (org-agenda-check-type t 'agenda 'timeline)
  7479. (require 'diary-lib)
  7480. (unless (get-text-property (point) 'day)
  7481. (error "Don't know which date to use for calendar command"))
  7482. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7483. (point (point))
  7484. (date (calendar-gregorian-from-absolute
  7485. (get-text-property point 'day)))
  7486. ;; the following 2 vars are needed in the calendar
  7487. (displayed-month (car date))
  7488. (displayed-year (nth 2 date)))
  7489. (unwind-protect
  7490. (progn
  7491. (fset 'calendar-cursor-to-date
  7492. (lambda (&optional error dummy)
  7493. (calendar-gregorian-from-absolute
  7494. (get-text-property point 'day))))
  7495. (call-interactively cmd))
  7496. (fset 'calendar-cursor-to-date oldf))))
  7497. (defun org-agenda-phases-of-moon ()
  7498. "Display the phases of the moon for the 3 months around the cursor date."
  7499. (interactive)
  7500. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7501. (defun org-agenda-holidays ()
  7502. "Display the holidays for the 3 months around the cursor date."
  7503. (interactive)
  7504. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7505. (defvar calendar-longitude)
  7506. (defvar calendar-latitude)
  7507. (defvar calendar-location-name)
  7508. (defun org-agenda-sunrise-sunset (arg)
  7509. "Display sunrise and sunset for the cursor date.
  7510. Latitude and longitude can be specified with the variables
  7511. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7512. argument, latitude and longitude will be prompted for."
  7513. (interactive "P")
  7514. (require 'solar)
  7515. (let ((calendar-longitude (if arg nil calendar-longitude))
  7516. (calendar-latitude (if arg nil calendar-latitude))
  7517. (calendar-location-name
  7518. (if arg "the given coordinates" calendar-location-name)))
  7519. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7520. (defun org-agenda-goto-calendar ()
  7521. "Open the Emacs calendar with the date at the cursor."
  7522. (interactive)
  7523. (org-agenda-check-type t 'agenda 'timeline)
  7524. (let* ((day (or (get-text-property (point) 'day)
  7525. (error "Don't know which date to open in calendar")))
  7526. (date (calendar-gregorian-from-absolute day))
  7527. (calendar-move-hook nil)
  7528. (calendar-view-holidays-initially-flag nil)
  7529. (calendar-view-diary-initially-flag nil))
  7530. (calendar)
  7531. (calendar-goto-date date)))
  7532. ;;;###autoload
  7533. (defun org-calendar-goto-agenda ()
  7534. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7535. This is a command that has to be installed in `calendar-mode-map'."
  7536. (interactive)
  7537. (org-agenda-list nil (calendar-absolute-from-gregorian
  7538. (calendar-cursor-to-date))
  7539. nil))
  7540. (defun org-agenda-convert-date ()
  7541. (interactive)
  7542. (org-agenda-check-type t 'agenda 'timeline)
  7543. (let ((day (get-text-property (point) 'day))
  7544. date s)
  7545. (unless day
  7546. (error "Don't know which date to convert"))
  7547. (setq date (calendar-gregorian-from-absolute day))
  7548. (setq s (concat
  7549. "Gregorian: " (calendar-date-string date) "\n"
  7550. "ISO: " (calendar-iso-date-string date) "\n"
  7551. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7552. "Julian: " (calendar-julian-date-string date) "\n"
  7553. "Astron. JD: " (calendar-astro-date-string date)
  7554. " (Julian date number at noon UTC)\n"
  7555. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7556. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7557. "French: " (calendar-french-date-string date) "\n"
  7558. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7559. "Mayan: " (calendar-mayan-date-string date) "\n"
  7560. "Coptic: " (calendar-coptic-date-string date) "\n"
  7561. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7562. "Persian: " (calendar-persian-date-string date) "\n"
  7563. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7564. (with-output-to-temp-buffer "*Dates*"
  7565. (princ s))
  7566. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7567. ;;; Bulk commands
  7568. (defvar org-agenda-bulk-marked-entries nil
  7569. "List of markers that refer to marked entries in the agenda.")
  7570. (defun org-agenda-bulk-marked-p ()
  7571. (eq (get-char-property (point-at-bol) 'type)
  7572. 'org-marked-entry-overlay))
  7573. (defun org-agenda-bulk-mark (&optional arg)
  7574. "Mark the entry at point for future bulk action."
  7575. (interactive "p")
  7576. (dotimes (i (max arg 1))
  7577. (unless (org-get-at-bol 'org-agenda-diary-link)
  7578. (let* ((m (org-get-at-bol 'org-hd-marker))
  7579. ov)
  7580. (unless (org-agenda-bulk-marked-p)
  7581. (unless m (error "Nothing to mark at point"))
  7582. (push m org-agenda-bulk-marked-entries)
  7583. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7584. (org-overlay-display ov "> "
  7585. (org-get-todo-face "TODO")
  7586. 'evaporate)
  7587. (overlay-put ov 'type 'org-marked-entry-overlay))
  7588. (beginning-of-line 2)
  7589. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7590. (beginning-of-line 2))
  7591. (message "%d entries marked for bulk action"
  7592. (length org-agenda-bulk-marked-entries))))))
  7593. (defun org-agenda-bulk-mark-regexp (regexp)
  7594. "Mark entries match REGEXP."
  7595. (interactive "sMark entries matching regexp: ")
  7596. (let (entries-marked)
  7597. (save-excursion
  7598. (goto-char (point-min))
  7599. (goto-char (next-single-property-change (point) 'txt))
  7600. (while (re-search-forward regexp nil t)
  7601. (when (string-match regexp (get-text-property (point) 'txt))
  7602. (setq entries-marked (+ entries-marked 1))
  7603. (call-interactively 'org-agenda-bulk-mark))))
  7604. (if (not entries-marked)
  7605. (message "No entry matching this regexp."))))
  7606. (defun org-agenda-bulk-unmark ()
  7607. "Unmark the entry at point for future bulk action."
  7608. (interactive)
  7609. (when (org-agenda-bulk-marked-p)
  7610. (org-agenda-bulk-remove-overlays
  7611. (point-at-bol) (+ 2 (point-at-bol)))
  7612. (setq org-agenda-bulk-marked-entries
  7613. (delete (org-get-at-bol 'org-hd-marker)
  7614. org-agenda-bulk-marked-entries)))
  7615. (beginning-of-line 2)
  7616. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7617. (beginning-of-line 2))
  7618. (message "%d entries marked for bulk action"
  7619. (length org-agenda-bulk-marked-entries)))
  7620. (defun org-agenda-bulk-toggle ()
  7621. "Toggle marking the entry at point for bulk action."
  7622. (interactive)
  7623. (if (org-agenda-bulk-marked-p)
  7624. (org-agenda-bulk-unmark)
  7625. (org-agenda-bulk-mark)))
  7626. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7627. "Remove the mark overlays between BEG and END in the agenda buffer.
  7628. BEG and END default to the buffer limits.
  7629. This only removes the overlays, it does not remove the markers
  7630. from the list in `org-agenda-bulk-marked-entries'."
  7631. (interactive)
  7632. (mapc (lambda (ov)
  7633. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7634. (delete-overlay ov)))
  7635. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7636. (defun org-agenda-bulk-remove-all-marks ()
  7637. "Remove all marks in the agenda buffer.
  7638. This will remove the markers, and the overlays."
  7639. (interactive)
  7640. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7641. (setq org-agenda-bulk-marked-entries nil)
  7642. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7643. (defun org-agenda-bulk-action (&optional arg)
  7644. "Execute an remote-editing action on all marked entries.
  7645. The prefix arg is passed through to the command if possible."
  7646. (interactive "P")
  7647. ;; Make sure we have markers, and only valid ones
  7648. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7649. (mapc
  7650. (lambda (m)
  7651. (unless (and (markerp m)
  7652. (marker-buffer m)
  7653. (buffer-live-p (marker-buffer m))
  7654. (marker-position m))
  7655. (error "Marker %s for bulk command is invalid" m)))
  7656. org-agenda-bulk-marked-entries)
  7657. ;; Prompt for the bulk command
  7658. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7659. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7660. (when org-agenda-bulk-custom-functions
  7661. (concat " Custom: ["
  7662. (mapconcat (lambda(f) (char-to-string (car f)))
  7663. org-agenda-bulk-custom-functions "")
  7664. "]"))))
  7665. (let* ((action (read-char-exclusive))
  7666. (org-log-refile (if org-log-refile 'time nil))
  7667. (entries (reverse org-agenda-bulk-marked-entries))
  7668. redo-at-end
  7669. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7670. (cond
  7671. ((equal action ?$)
  7672. (setq cmd '(org-agenda-archive)))
  7673. ((equal action ?A)
  7674. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7675. ((member action '(?r ?w))
  7676. (setq rfloc (org-refile-get-location
  7677. "Refile to"
  7678. (marker-buffer (car org-agenda-bulk-marked-entries))
  7679. org-refile-allow-creating-parent-nodes))
  7680. (if (nth 3 rfloc)
  7681. (setcar (nthcdr 3 rfloc)
  7682. (move-marker (make-marker) (nth 3 rfloc)
  7683. (or (get-file-buffer (nth 1 rfloc))
  7684. (find-buffer-visiting (nth 1 rfloc))
  7685. (error "This should not happen")))))
  7686. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7687. redo-at-end t))
  7688. ((equal action ?t)
  7689. (setq state (org-icompleting-read
  7690. "Todo state: "
  7691. (with-current-buffer (marker-buffer (car entries))
  7692. (mapcar 'list org-todo-keywords-1))))
  7693. (setq cmd `(let ((org-inhibit-blocking t)
  7694. (org-inhibit-logging 'note))
  7695. (org-agenda-todo ,state))))
  7696. ((memq action '(?- ?+))
  7697. (setq tag (org-icompleting-read
  7698. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7699. (with-current-buffer (marker-buffer (car entries))
  7700. (delq nil
  7701. (mapcar (lambda (x)
  7702. (if (stringp (car x)) x)) org-tag-alist)))))
  7703. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7704. ((memq action '(?s ?d))
  7705. (let* ((date (unless arg
  7706. (org-read-date
  7707. nil nil nil
  7708. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7709. (ans (if arg nil org-read-date-final-answer))
  7710. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7711. (setq cmd `(let* ((bound (fboundp 'read-string))
  7712. (old (and bound (symbol-function 'read-string))))
  7713. (unwind-protect
  7714. (progn
  7715. (fset 'read-string (lambda (&rest ignore) ,ans))
  7716. (eval '(,c1 arg)))
  7717. (if bound
  7718. (fset 'read-string old)
  7719. (fmakunbound 'read-string)))))))
  7720. ((equal action ?S)
  7721. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7722. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7723. (let ((days (read-number
  7724. (format "Scatter tasks across how many %sdays: "
  7725. (if arg "week" "")) 7)))
  7726. (setq cmd
  7727. `(let ((distance (1+ (random ,days))))
  7728. (if arg
  7729. (let ((dist distance)
  7730. (day-of-week
  7731. (calendar-day-of-week
  7732. (calendar-gregorian-from-absolute (org-today)))))
  7733. (dotimes (i (1+ dist))
  7734. (while (member day-of-week org-agenda-weekend-days)
  7735. (incf distance)
  7736. (incf day-of-week)
  7737. (if (= day-of-week 7)
  7738. (setq day-of-week 0)))
  7739. (incf day-of-week)
  7740. (if (= day-of-week 7)
  7741. (setq day-of-week 0)))))
  7742. ;; silently fail when try to replan a sexp entry
  7743. (condition-case nil
  7744. (let* ((date (calendar-gregorian-from-absolute
  7745. (+ (org-today) distance)))
  7746. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7747. (nth 2 date))))
  7748. (org-agenda-schedule nil time))
  7749. (error nil)))))))
  7750. ((assoc action org-agenda-bulk-custom-functions)
  7751. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7752. redo-at-end t))
  7753. ((equal action ?f)
  7754. (setq cmd (list (intern
  7755. (org-icompleting-read "Function: "
  7756. obarray 'fboundp t nil nil)))))
  7757. (t (error "Invalid bulk action")))
  7758. ;; Sort the markers, to make sure that parents are handled before children
  7759. (setq entries (sort entries
  7760. (lambda (a b)
  7761. (cond
  7762. ((equal (marker-buffer a) (marker-buffer b))
  7763. (< (marker-position a) (marker-position b)))
  7764. (t
  7765. (string< (buffer-name (marker-buffer a))
  7766. (buffer-name (marker-buffer b))))))))
  7767. ;; Now loop over all markers and apply cmd
  7768. (while (setq e (pop entries))
  7769. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7770. (if (not pos)
  7771. (progn (message "Skipping removed entry at %s" e)
  7772. (setq cntskip (1+ cntskip)))
  7773. (goto-char pos)
  7774. (eval cmd)
  7775. (setq org-agenda-bulk-marked-entries
  7776. (delete e org-agenda-bulk-marked-entries))
  7777. (setq cnt (1+ cnt))))
  7778. (setq org-agenda-bulk-marked-entries nil)
  7779. (org-agenda-bulk-remove-all-marks)
  7780. (when redo-at-end (org-agenda-redo))
  7781. (message "Acted on %d entries%s"
  7782. cnt
  7783. (if (= cntskip 0)
  7784. ""
  7785. (format ", skipped %d (disappeared before their turn)"
  7786. cntskip)))))
  7787. ;;; Flagging notes
  7788. (defun org-agenda-show-the-flagging-note ()
  7789. "Display the flagging note in the other window.
  7790. When called a second time in direct sequence, offer to remove the FLAGGING
  7791. tag and (if present) the flagging note."
  7792. (interactive)
  7793. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7794. (win (selected-window))
  7795. note heading newhead)
  7796. (unless hdmarker
  7797. (error "No linked entry at point"))
  7798. (if (and (eq this-command last-command)
  7799. (y-or-n-p "Unflag and remove any flagging note? "))
  7800. (progn
  7801. (org-agenda-remove-flag hdmarker)
  7802. (let ((win (get-buffer-window "*Flagging Note*")))
  7803. (and win (delete-window win)))
  7804. (message "Entry unflaged"))
  7805. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7806. (unless note
  7807. (error "No flagging note"))
  7808. (org-kill-new note)
  7809. (org-switch-to-buffer-other-window "*Flagging Note*")
  7810. (erase-buffer)
  7811. (insert note)
  7812. (goto-char (point-min))
  7813. (while (re-search-forward "\\\\n" nil t)
  7814. (replace-match "\n" t t))
  7815. (goto-char (point-min))
  7816. (select-window win)
  7817. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7818. (defun org-agenda-remove-flag (marker)
  7819. "Remove the FLAGGED tag and any flagging note in the entry."
  7820. (let (newhead)
  7821. (org-with-point-at marker
  7822. (org-toggle-tag "FLAGGED" 'off)
  7823. (org-entry-delete nil "THEFLAGGINGNOTE")
  7824. (setq newhead (org-get-heading)))
  7825. (org-agenda-change-all-lines newhead marker)
  7826. (message "Entry unflaged")))
  7827. (defun org-agenda-get-any-marker (&optional pos)
  7828. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7829. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7830. ;;; Appointment reminders
  7831. (defvar appt-time-msg-list)
  7832. ;;;###autoload
  7833. (defun org-agenda-to-appt (&optional refresh filter)
  7834. "Activate appointments found in `org-agenda-files'.
  7835. With a \\[universal-argument] prefix, refresh the list of
  7836. appointments.
  7837. If FILTER is t, interactively prompt the user for a regular
  7838. expression, and filter out entries that don't match it.
  7839. If FILTER is a string, use this string as a regular expression
  7840. for filtering entries out.
  7841. FILTER can also be an alist with the car of each cell being
  7842. either 'headline or 'category. For example:
  7843. '((headline \"IMPORTANT\")
  7844. (category \"Work\"))
  7845. will only add headlines containing IMPORTANT or headlines
  7846. belonging to the \"Work\" category."
  7847. (interactive "P")
  7848. (if refresh (setq appt-time-msg-list nil))
  7849. (if (eq filter t)
  7850. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7851. (let* ((cnt 0) ; count added events
  7852. (org-agenda-new-buffers nil)
  7853. (org-deadline-warning-days 0)
  7854. ;; Do not use `org-today' here because appt only takes
  7855. ;; time and without date as argument, so it may pass wrong
  7856. ;; information otherwise
  7857. (today (org-date-to-gregorian
  7858. (time-to-days (current-time))))
  7859. (org-agenda-restrict nil)
  7860. (files (org-agenda-files 'unrestricted)) entries file)
  7861. ;; Get all entries which may contain an appt
  7862. (org-prepare-agenda-buffers files)
  7863. (while (setq file (pop files))
  7864. (setq entries
  7865. (append entries
  7866. (org-agenda-get-day-entries
  7867. file today :timestamp :scheduled :deadline))))
  7868. (setq entries (delq nil entries))
  7869. ;; Map thru entries and find if we should filter them out
  7870. (mapc
  7871. (lambda(x)
  7872. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7873. (cat (get-text-property 1 'org-category x))
  7874. (tod (get-text-property 1 'time-of-day x))
  7875. (ok (or (null filter)
  7876. (and (stringp filter) (string-match filter evt))
  7877. (and (listp filter)
  7878. (or (string-match
  7879. (cadr (assoc 'category filter)) cat)
  7880. (string-match
  7881. (cadr (assoc 'headline filter)) evt))))))
  7882. ;; FIXME: Shall we remove text-properties for the appt text?
  7883. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7884. (when (and ok tod)
  7885. (setq tod (concat "00" (number-to-string tod))
  7886. tod (when (string-match
  7887. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7888. (concat (match-string 1 tod) ":"
  7889. (match-string 2 tod))))
  7890. (appt-add tod evt)
  7891. (setq cnt (1+ cnt))))) entries)
  7892. (org-release-buffers org-agenda-new-buffers)
  7893. (if (eq cnt 0)
  7894. (message "No event to add")
  7895. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7896. (defun org-agenda-todayp (date)
  7897. "Does DATE mean today, when considering `org-extend-today-until'?"
  7898. (let ((today (org-today))
  7899. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7900. date)))
  7901. (eq date today)))
  7902. (defun org-agenda-todo-yesterday (&optional arg)
  7903. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  7904. (interactive "P")
  7905. (let* ((hour (third (decode-time
  7906. (org-current-time))))
  7907. (org-extend-today-until (1+ hour)))
  7908. (org-agenda-todo arg)))
  7909. (provide 'org-agenda)
  7910. ;;; org-agenda.el ends here